pixi.js 1.6MB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901259022590325904259052590625907259082590925910259112591225913259142591525916259172591825919259202592125922259232592425925259262592725928259292593025931259322593325934259352593625937259382593925940259412594225943259442594525946259472594825949259502595125952259532595425955259562595725958259592596025961259622596325964259652596625967259682596925970259712597225973259742597525976259772597825979259802598125982259832598425985259862598725988259892599025991259922599325994259952599625997259982599926000260012600226003260042600526006260072600826009260102601126012260132601426015260162601726018260192602026021260222602326024260252602626027260282602926030260312603226033260342603526036260372603826039260402604126042260432604426045260462604726048260492605026051260522605326054260552605626057260582605926060260612606226063260642606526066260672606826069260702607126072260732607426075260762607726078260792608026081260822608326084260852608626087260882608926090260912609226093260942609526096260972609826099261002610126102261032610426105261062610726108261092611026111261122611326114261152611626117261182611926120261212612226123261242612526126261272612826129261302613126132261332613426135261362613726138261392614026141261422614326144261452614626147261482614926150261512615226153261542615526156261572615826159261602616126162261632616426165261662616726168261692617026171261722617326174261752617626177261782617926180261812618226183261842618526186261872618826189261902619126192261932619426195261962619726198261992620026201262022620326204262052620626207262082620926210262112621226213262142621526216262172621826219262202622126222262232622426225262262622726228262292623026231262322623326234262352623626237262382623926240262412624226243262442624526246262472624826249262502625126252262532625426255262562625726258262592626026261262622626326264262652626626267262682626926270262712627226273262742627526276262772627826279262802628126282262832628426285262862628726288262892629026291262922629326294262952629626297262982629926300263012630226303263042630526306263072630826309263102631126312263132631426315263162631726318263192632026321263222632326324263252632626327263282632926330263312633226333263342633526336263372633826339263402634126342263432634426345263462634726348263492635026351263522635326354263552635626357263582635926360263612636226363263642636526366263672636826369263702637126372263732637426375263762637726378263792638026381263822638326384263852638626387263882638926390263912639226393263942639526396263972639826399264002640126402264032640426405264062640726408264092641026411264122641326414264152641626417264182641926420264212642226423264242642526426264272642826429264302643126432264332643426435264362643726438264392644026441264422644326444264452644626447264482644926450264512645226453264542645526456264572645826459264602646126462264632646426465264662646726468264692647026471264722647326474264752647626477264782647926480264812648226483264842648526486264872648826489264902649126492264932649426495264962649726498264992650026501265022650326504265052650626507265082650926510265112651226513265142651526516265172651826519265202652126522265232652426525265262652726528265292653026531265322653326534265352653626537265382653926540265412654226543265442654526546265472654826549265502655126552265532655426555265562655726558265592656026561265622656326564265652656626567265682656926570265712657226573265742657526576265772657826579265802658126582265832658426585265862658726588265892659026591265922659326594265952659626597265982659926600266012660226603266042660526606266072660826609266102661126612266132661426615266162661726618266192662026621266222662326624266252662626627266282662926630266312663226633266342663526636266372663826639266402664126642266432664426645266462664726648266492665026651266522665326654266552665626657266582665926660266612666226663266642666526666266672666826669266702667126672266732667426675266762667726678266792668026681266822668326684266852668626687266882668926690266912669226693266942669526696266972669826699267002670126702267032670426705267062670726708267092671026711267122671326714267152671626717267182671926720267212672226723267242672526726267272672826729267302673126732267332673426735267362673726738267392674026741267422674326744267452674626747267482674926750267512675226753267542675526756267572675826759267602676126762267632676426765267662676726768267692677026771267722677326774267752677626777267782677926780267812678226783267842678526786267872678826789267902679126792267932679426795267962679726798267992680026801268022680326804268052680626807268082680926810268112681226813268142681526816268172681826819268202682126822268232682426825268262682726828268292683026831268322683326834268352683626837268382683926840268412684226843268442684526846268472684826849268502685126852268532685426855268562685726858268592686026861268622686326864268652686626867268682686926870268712687226873268742687526876268772687826879268802688126882268832688426885268862688726888268892689026891268922689326894268952689626897268982689926900269012690226903269042690526906269072690826909269102691126912269132691426915269162691726918269192692026921269222692326924269252692626927269282692926930269312693226933269342693526936269372693826939269402694126942269432694426945269462694726948269492695026951269522695326954269552695626957269582695926960269612696226963269642696526966269672696826969269702697126972269732697426975269762697726978269792698026981269822698326984269852698626987269882698926990269912699226993269942699526996269972699826999270002700127002270032700427005270062700727008270092701027011270122701327014270152701627017270182701927020270212702227023270242702527026270272702827029270302703127032270332703427035270362703727038270392704027041270422704327044270452704627047270482704927050270512705227053270542705527056270572705827059270602706127062270632706427065270662706727068270692707027071270722707327074270752707627077270782707927080270812708227083270842708527086270872708827089270902709127092270932709427095270962709727098270992710027101271022710327104271052710627107271082710927110271112711227113271142711527116271172711827119271202712127122271232712427125271262712727128271292713027131271322713327134271352713627137271382713927140271412714227143271442714527146271472714827149271502715127152271532715427155271562715727158271592716027161271622716327164271652716627167271682716927170271712717227173271742717527176271772717827179271802718127182271832718427185271862718727188271892719027191271922719327194271952719627197271982719927200272012720227203272042720527206272072720827209272102721127212272132721427215272162721727218272192722027221272222722327224272252722627227272282722927230272312723227233272342723527236272372723827239272402724127242272432724427245272462724727248272492725027251272522725327254272552725627257272582725927260272612726227263272642726527266272672726827269272702727127272272732727427275272762727727278272792728027281272822728327284272852728627287272882728927290272912729227293272942729527296272972729827299273002730127302273032730427305273062730727308273092731027311273122731327314273152731627317273182731927320273212732227323273242732527326273272732827329273302733127332273332733427335273362733727338273392734027341273422734327344273452734627347273482734927350273512735227353273542735527356273572735827359273602736127362273632736427365273662736727368273692737027371273722737327374273752737627377273782737927380273812738227383273842738527386273872738827389273902739127392273932739427395273962739727398273992740027401274022740327404274052740627407274082740927410274112741227413274142741527416274172741827419274202742127422274232742427425274262742727428274292743027431274322743327434274352743627437274382743927440274412744227443274442744527446274472744827449274502745127452274532745427455274562745727458274592746027461274622746327464274652746627467274682746927470274712747227473274742747527476274772747827479274802748127482274832748427485274862748727488274892749027491274922749327494274952749627497274982749927500275012750227503275042750527506275072750827509275102751127512275132751427515275162751727518275192752027521275222752327524275252752627527275282752927530275312753227533275342753527536275372753827539275402754127542275432754427545275462754727548275492755027551275522755327554275552755627557275582755927560275612756227563275642756527566275672756827569275702757127572275732757427575275762757727578275792758027581275822758327584275852758627587275882758927590275912759227593275942759527596275972759827599276002760127602276032760427605276062760727608276092761027611276122761327614276152761627617276182761927620276212762227623276242762527626276272762827629276302763127632276332763427635276362763727638276392764027641276422764327644276452764627647276482764927650276512765227653276542765527656276572765827659276602766127662276632766427665276662766727668276692767027671276722767327674276752767627677276782767927680276812768227683276842768527686276872768827689276902769127692276932769427695276962769727698276992770027701277022770327704277052770627707277082770927710277112771227713277142771527716277172771827719277202772127722277232772427725277262772727728277292773027731277322773327734277352773627737277382773927740277412774227743277442774527746277472774827749277502775127752277532775427755277562775727758277592776027761277622776327764277652776627767277682776927770277712777227773277742777527776277772777827779277802778127782277832778427785277862778727788277892779027791277922779327794277952779627797277982779927800278012780227803278042780527806278072780827809278102781127812278132781427815278162781727818278192782027821278222782327824278252782627827278282782927830278312783227833278342783527836278372783827839278402784127842278432784427845278462784727848278492785027851278522785327854278552785627857278582785927860278612786227863278642786527866278672786827869278702787127872278732787427875278762787727878278792788027881278822788327884278852788627887278882788927890278912789227893278942789527896278972789827899279002790127902279032790427905279062790727908279092791027911279122791327914279152791627917279182791927920279212792227923279242792527926279272792827929279302793127932279332793427935279362793727938279392794027941279422794327944279452794627947279482794927950279512795227953279542795527956279572795827959279602796127962279632796427965279662796727968279692797027971279722797327974279752797627977279782797927980279812798227983279842798527986279872798827989279902799127992279932799427995279962799727998279992800028001280022800328004280052800628007280082800928010280112801228013280142801528016280172801828019280202802128022280232802428025280262802728028280292803028031280322803328034280352803628037280382803928040280412804228043280442804528046280472804828049280502805128052280532805428055280562805728058280592806028061280622806328064280652806628067280682806928070280712807228073280742807528076280772807828079280802808128082280832808428085280862808728088280892809028091280922809328094280952809628097280982809928100281012810228103281042810528106281072810828109281102811128112281132811428115281162811728118281192812028121281222812328124281252812628127281282812928130281312813228133281342813528136281372813828139281402814128142281432814428145281462814728148281492815028151281522815328154281552815628157281582815928160281612816228163281642816528166281672816828169281702817128172281732817428175281762817728178281792818028181281822818328184281852818628187281882818928190281912819228193281942819528196281972819828199282002820128202282032820428205282062820728208282092821028211282122821328214282152821628217282182821928220282212822228223282242822528226282272822828229282302823128232282332823428235282362823728238282392824028241282422824328244282452824628247282482824928250282512825228253282542825528256282572825828259282602826128262282632826428265282662826728268282692827028271282722827328274282752827628277282782827928280282812828228283282842828528286282872828828289282902829128292282932829428295282962829728298282992830028301283022830328304283052830628307283082830928310283112831228313283142831528316283172831828319283202832128322283232832428325283262832728328283292833028331283322833328334283352833628337283382833928340283412834228343283442834528346283472834828349283502835128352283532835428355283562835728358283592836028361283622836328364283652836628367283682836928370283712837228373283742837528376283772837828379283802838128382283832838428385283862838728388283892839028391283922839328394283952839628397283982839928400284012840228403284042840528406284072840828409284102841128412284132841428415284162841728418284192842028421284222842328424284252842628427284282842928430284312843228433284342843528436284372843828439284402844128442284432844428445284462844728448284492845028451284522845328454284552845628457284582845928460284612846228463284642846528466284672846828469284702847128472284732847428475284762847728478284792848028481284822848328484284852848628487284882848928490284912849228493284942849528496284972849828499285002850128502285032850428505285062850728508285092851028511285122851328514285152851628517285182851928520285212852228523285242852528526285272852828529285302853128532285332853428535285362853728538285392854028541285422854328544285452854628547285482854928550285512855228553285542855528556285572855828559285602856128562285632856428565285662856728568285692857028571285722857328574285752857628577285782857928580285812858228583285842858528586285872858828589285902859128592285932859428595285962859728598285992860028601286022860328604286052860628607286082860928610286112861228613286142861528616286172861828619286202862128622286232862428625286262862728628286292863028631286322863328634286352863628637286382863928640286412864228643286442864528646286472864828649286502865128652286532865428655286562865728658286592866028661286622866328664286652866628667286682866928670286712867228673286742867528676286772867828679286802868128682286832868428685286862868728688286892869028691286922869328694286952869628697286982869928700287012870228703287042870528706287072870828709287102871128712287132871428715287162871728718287192872028721287222872328724287252872628727287282872928730287312873228733287342873528736287372873828739287402874128742287432874428745287462874728748287492875028751287522875328754287552875628757287582875928760287612876228763287642876528766287672876828769287702877128772287732877428775287762877728778287792878028781287822878328784287852878628787287882878928790287912879228793287942879528796287972879828799288002880128802288032880428805288062880728808288092881028811288122881328814288152881628817288182881928820288212882228823288242882528826288272882828829288302883128832288332883428835288362883728838288392884028841288422884328844288452884628847288482884928850288512885228853288542885528856288572885828859288602886128862288632886428865288662886728868288692887028871288722887328874288752887628877288782887928880288812888228883288842888528886288872888828889288902889128892288932889428895288962889728898288992890028901289022890328904289052890628907289082890928910289112891228913289142891528916289172891828919289202892128922289232892428925289262892728928289292893028931289322893328934289352893628937289382893928940289412894228943289442894528946289472894828949289502895128952289532895428955289562895728958289592896028961289622896328964289652896628967289682896928970289712897228973289742897528976289772897828979289802898128982289832898428985289862898728988289892899028991289922899328994289952899628997289982899929000290012900229003290042900529006290072900829009290102901129012290132901429015290162901729018290192902029021290222902329024290252902629027290282902929030290312903229033290342903529036290372903829039290402904129042290432904429045290462904729048290492905029051290522905329054290552905629057290582905929060290612906229063290642906529066290672906829069290702907129072290732907429075290762907729078290792908029081290822908329084290852908629087290882908929090290912909229093290942909529096290972909829099291002910129102291032910429105291062910729108291092911029111291122911329114291152911629117291182911929120291212912229123291242912529126291272912829129291302913129132291332913429135291362913729138291392914029141291422914329144291452914629147291482914929150291512915229153291542915529156291572915829159291602916129162291632916429165291662916729168291692917029171291722917329174291752917629177291782917929180291812918229183291842918529186291872918829189291902919129192291932919429195291962919729198291992920029201292022920329204292052920629207292082920929210292112921229213292142921529216292172921829219292202922129222292232922429225292262922729228292292923029231292322923329234292352923629237292382923929240292412924229243292442924529246292472924829249292502925129252292532925429255292562925729258292592926029261292622926329264292652926629267292682926929270292712927229273292742927529276292772927829279292802928129282292832928429285292862928729288292892929029291292922929329294292952929629297292982929929300293012930229303293042930529306293072930829309293102931129312293132931429315293162931729318293192932029321293222932329324293252932629327293282932929330293312933229333293342933529336293372933829339293402934129342293432934429345293462934729348293492935029351293522935329354293552935629357293582935929360293612936229363293642936529366293672936829369293702937129372293732937429375293762937729378293792938029381293822938329384293852938629387293882938929390293912939229393293942939529396293972939829399294002940129402294032940429405294062940729408294092941029411294122941329414294152941629417294182941929420294212942229423294242942529426294272942829429294302943129432294332943429435294362943729438294392944029441294422944329444294452944629447294482944929450294512945229453294542945529456294572945829459294602946129462294632946429465294662946729468294692947029471294722947329474294752947629477294782947929480294812948229483294842948529486294872948829489294902949129492294932949429495294962949729498294992950029501295022950329504295052950629507295082950929510295112951229513295142951529516295172951829519295202952129522295232952429525295262952729528295292953029531295322953329534295352953629537295382953929540295412954229543295442954529546295472954829549295502955129552295532955429555295562955729558295592956029561295622956329564295652956629567295682956929570295712957229573295742957529576295772957829579295802958129582295832958429585295862958729588295892959029591295922959329594295952959629597295982959929600296012960229603296042960529606296072960829609296102961129612296132961429615296162961729618296192962029621296222962329624296252962629627296282962929630296312963229633296342963529636296372963829639296402964129642296432964429645296462964729648296492965029651296522965329654296552965629657296582965929660296612966229663296642966529666296672966829669296702967129672296732967429675296762967729678296792968029681296822968329684296852968629687296882968929690296912969229693296942969529696296972969829699297002970129702297032970429705297062970729708297092971029711297122971329714297152971629717297182971929720297212972229723297242972529726297272972829729297302973129732297332973429735297362973729738297392974029741297422974329744297452974629747297482974929750297512975229753297542975529756297572975829759297602976129762297632976429765297662976729768297692977029771297722977329774297752977629777297782977929780297812978229783297842978529786297872978829789297902979129792297932979429795297962979729798297992980029801298022980329804298052980629807298082980929810298112981229813298142981529816298172981829819298202982129822298232982429825298262982729828298292983029831298322983329834298352983629837298382983929840298412984229843298442984529846298472984829849298502985129852298532985429855298562985729858298592986029861298622986329864298652986629867298682986929870298712987229873298742987529876298772987829879298802988129882298832988429885298862988729888298892989029891298922989329894298952989629897298982989929900299012990229903299042990529906299072990829909299102991129912299132991429915299162991729918299192992029921299222992329924299252992629927299282992929930299312993229933299342993529936299372993829939299402994129942299432994429945299462994729948299492995029951299522995329954299552995629957299582995929960299612996229963299642996529966299672996829969299702997129972299732997429975299762997729978299792998029981299822998329984299852998629987299882998929990299912999229993299942999529996299972999829999300003000130002300033000430005300063000730008300093001030011300123001330014300153001630017300183001930020300213002230023300243002530026300273002830029300303003130032300333003430035300363003730038300393004030041300423004330044300453004630047300483004930050300513005230053300543005530056300573005830059300603006130062300633006430065300663006730068300693007030071300723007330074300753007630077300783007930080300813008230083300843008530086300873008830089300903009130092300933009430095300963009730098300993010030101301023010330104301053010630107301083010930110301113011230113301143011530116301173011830119301203012130122301233012430125301263012730128301293013030131301323013330134301353013630137301383013930140301413014230143301443014530146301473014830149301503015130152301533015430155301563015730158301593016030161301623016330164301653016630167301683016930170301713017230173301743017530176301773017830179301803018130182301833018430185301863018730188301893019030191301923019330194301953019630197301983019930200302013020230203302043020530206302073020830209302103021130212302133021430215302163021730218302193022030221302223022330224302253022630227302283022930230302313023230233302343023530236302373023830239302403024130242302433024430245302463024730248302493025030251302523025330254302553025630257302583025930260302613026230263302643026530266302673026830269302703027130272302733027430275302763027730278302793028030281302823028330284302853028630287302883028930290302913029230293302943029530296302973029830299303003030130302303033030430305303063030730308303093031030311303123031330314303153031630317303183031930320303213032230323303243032530326303273032830329303303033130332303333033430335303363033730338303393034030341303423034330344303453034630347303483034930350303513035230353303543035530356303573035830359303603036130362303633036430365303663036730368303693037030371303723037330374303753037630377303783037930380303813038230383303843038530386303873038830389303903039130392303933039430395303963039730398303993040030401304023040330404304053040630407304083040930410304113041230413304143041530416304173041830419304203042130422304233042430425304263042730428304293043030431304323043330434304353043630437304383043930440304413044230443304443044530446304473044830449304503045130452304533045430455304563045730458304593046030461304623046330464304653046630467304683046930470304713047230473304743047530476304773047830479304803048130482304833048430485304863048730488304893049030491304923049330494304953049630497304983049930500305013050230503305043050530506305073050830509305103051130512305133051430515305163051730518305193052030521305223052330524305253052630527305283052930530305313053230533305343053530536305373053830539305403054130542305433054430545305463054730548305493055030551305523055330554305553055630557305583055930560305613056230563305643056530566305673056830569305703057130572305733057430575305763057730578305793058030581305823058330584305853058630587305883058930590305913059230593305943059530596305973059830599306003060130602306033060430605306063060730608306093061030611306123061330614306153061630617306183061930620306213062230623306243062530626306273062830629306303063130632306333063430635306363063730638306393064030641306423064330644306453064630647306483064930650306513065230653306543065530656306573065830659306603066130662306633066430665306663066730668306693067030671306723067330674306753067630677306783067930680306813068230683306843068530686306873068830689306903069130692306933069430695306963069730698306993070030701307023070330704307053070630707307083070930710307113071230713307143071530716307173071830719307203072130722307233072430725307263072730728307293073030731307323073330734307353073630737307383073930740307413074230743307443074530746307473074830749307503075130752307533075430755307563075730758307593076030761307623076330764307653076630767307683076930770307713077230773307743077530776307773077830779307803078130782307833078430785307863078730788307893079030791307923079330794307953079630797307983079930800308013080230803308043080530806308073080830809308103081130812308133081430815308163081730818308193082030821308223082330824308253082630827308283082930830308313083230833308343083530836308373083830839308403084130842308433084430845308463084730848308493085030851308523085330854308553085630857308583085930860308613086230863308643086530866308673086830869308703087130872308733087430875308763087730878308793088030881308823088330884308853088630887308883088930890308913089230893308943089530896308973089830899309003090130902309033090430905309063090730908309093091030911309123091330914309153091630917309183091930920309213092230923309243092530926309273092830929309303093130932309333093430935309363093730938309393094030941309423094330944309453094630947309483094930950309513095230953309543095530956309573095830959309603096130962309633096430965309663096730968309693097030971309723097330974309753097630977309783097930980309813098230983309843098530986309873098830989309903099130992309933099430995309963099730998309993100031001310023100331004310053100631007310083100931010310113101231013310143101531016310173101831019310203102131022310233102431025310263102731028310293103031031310323103331034310353103631037310383103931040310413104231043310443104531046310473104831049310503105131052310533105431055310563105731058310593106031061310623106331064310653106631067310683106931070310713107231073310743107531076310773107831079310803108131082310833108431085310863108731088310893109031091310923109331094310953109631097310983109931100311013110231103311043110531106311073110831109311103111131112311133111431115311163111731118311193112031121311223112331124311253112631127311283112931130311313113231133311343113531136311373113831139311403114131142311433114431145311463114731148311493115031151311523115331154311553115631157311583115931160311613116231163311643116531166311673116831169311703117131172311733117431175311763117731178311793118031181311823118331184311853118631187311883118931190311913119231193311943119531196311973119831199312003120131202312033120431205312063120731208312093121031211312123121331214312153121631217312183121931220312213122231223312243122531226312273122831229312303123131232312333123431235312363123731238312393124031241312423124331244312453124631247312483124931250312513125231253312543125531256312573125831259312603126131262312633126431265312663126731268312693127031271312723127331274312753127631277312783127931280312813128231283312843128531286312873128831289312903129131292312933129431295312963129731298312993130031301313023130331304313053130631307313083130931310313113131231313313143131531316313173131831319313203132131322313233132431325313263132731328313293133031331313323133331334313353133631337313383133931340313413134231343313443134531346313473134831349313503135131352313533135431355313563135731358313593136031361313623136331364313653136631367313683136931370313713137231373313743137531376313773137831379313803138131382313833138431385313863138731388313893139031391313923139331394313953139631397313983139931400314013140231403314043140531406314073140831409314103141131412314133141431415314163141731418314193142031421314223142331424314253142631427314283142931430314313143231433314343143531436314373143831439314403144131442314433144431445314463144731448314493145031451314523145331454314553145631457314583145931460314613146231463314643146531466314673146831469314703147131472314733147431475314763147731478314793148031481314823148331484314853148631487314883148931490314913149231493314943149531496314973149831499315003150131502315033150431505315063150731508315093151031511315123151331514315153151631517315183151931520315213152231523315243152531526315273152831529315303153131532315333153431535315363153731538315393154031541315423154331544315453154631547315483154931550315513155231553315543155531556315573155831559315603156131562315633156431565315663156731568315693157031571315723157331574315753157631577315783157931580315813158231583315843158531586315873158831589315903159131592315933159431595315963159731598315993160031601316023160331604316053160631607316083160931610316113161231613316143161531616316173161831619316203162131622316233162431625316263162731628316293163031631316323163331634316353163631637316383163931640316413164231643316443164531646316473164831649316503165131652316533165431655316563165731658316593166031661316623166331664316653166631667316683166931670316713167231673316743167531676316773167831679316803168131682316833168431685316863168731688316893169031691316923169331694316953169631697316983169931700317013170231703317043170531706317073170831709317103171131712317133171431715317163171731718317193172031721317223172331724317253172631727317283172931730317313173231733317343173531736317373173831739317403174131742317433174431745317463174731748317493175031751317523175331754317553175631757317583175931760317613176231763317643176531766317673176831769317703177131772317733177431775317763177731778317793178031781317823178331784317853178631787317883178931790317913179231793317943179531796317973179831799318003180131802318033180431805318063180731808318093181031811318123181331814318153181631817318183181931820318213182231823318243182531826318273182831829318303183131832318333183431835318363183731838318393184031841318423184331844318453184631847318483184931850318513185231853318543185531856318573185831859318603186131862318633186431865318663186731868318693187031871318723187331874318753187631877318783187931880318813188231883318843188531886318873188831889318903189131892318933189431895318963189731898318993190031901319023190331904319053190631907319083190931910319113191231913319143191531916319173191831919319203192131922319233192431925319263192731928319293193031931319323193331934319353193631937319383193931940319413194231943319443194531946319473194831949319503195131952319533195431955319563195731958319593196031961319623196331964319653196631967319683196931970319713197231973319743197531976319773197831979319803198131982319833198431985319863198731988319893199031991319923199331994319953199631997319983199932000320013200232003320043200532006320073200832009320103201132012320133201432015320163201732018320193202032021320223202332024320253202632027320283202932030320313203232033320343203532036320373203832039320403204132042320433204432045320463204732048320493205032051320523205332054320553205632057320583205932060320613206232063320643206532066320673206832069320703207132072320733207432075320763207732078320793208032081320823208332084320853208632087320883208932090320913209232093320943209532096320973209832099321003210132102321033210432105321063210732108321093211032111321123211332114321153211632117321183211932120321213212232123321243212532126321273212832129321303213132132321333213432135321363213732138321393214032141321423214332144321453214632147321483214932150321513215232153321543215532156321573215832159321603216132162321633216432165321663216732168321693217032171321723217332174321753217632177321783217932180321813218232183321843218532186321873218832189321903219132192321933219432195321963219732198321993220032201322023220332204322053220632207322083220932210322113221232213322143221532216322173221832219322203222132222322233222432225322263222732228322293223032231322323223332234322353223632237322383223932240322413224232243322443224532246322473224832249322503225132252322533225432255322563225732258322593226032261322623226332264322653226632267322683226932270322713227232273322743227532276322773227832279322803228132282322833228432285322863228732288322893229032291322923229332294322953229632297322983229932300323013230232303323043230532306323073230832309323103231132312323133231432315323163231732318323193232032321323223232332324323253232632327323283232932330323313233232333323343233532336323373233832339323403234132342323433234432345323463234732348323493235032351323523235332354323553235632357323583235932360323613236232363323643236532366323673236832369323703237132372323733237432375323763237732378323793238032381323823238332384323853238632387323883238932390323913239232393323943239532396323973239832399324003240132402324033240432405324063240732408324093241032411324123241332414324153241632417324183241932420324213242232423324243242532426324273242832429324303243132432324333243432435324363243732438324393244032441324423244332444324453244632447324483244932450324513245232453324543245532456324573245832459324603246132462324633246432465324663246732468324693247032471324723247332474324753247632477324783247932480324813248232483324843248532486324873248832489324903249132492324933249432495324963249732498324993250032501325023250332504325053250632507325083250932510325113251232513325143251532516325173251832519325203252132522325233252432525325263252732528325293253032531325323253332534325353253632537325383253932540325413254232543325443254532546325473254832549325503255132552325533255432555325563255732558325593256032561325623256332564325653256632567325683256932570325713257232573325743257532576325773257832579325803258132582325833258432585325863258732588325893259032591325923259332594325953259632597325983259932600326013260232603326043260532606326073260832609326103261132612326133261432615326163261732618326193262032621326223262332624326253262632627326283262932630326313263232633326343263532636326373263832639326403264132642326433264432645326463264732648326493265032651326523265332654326553265632657326583265932660326613266232663326643266532666326673266832669326703267132672326733267432675326763267732678326793268032681326823268332684326853268632687326883268932690326913269232693326943269532696326973269832699327003270132702327033270432705327063270732708327093271032711327123271332714327153271632717327183271932720327213272232723327243272532726327273272832729327303273132732327333273432735327363273732738327393274032741327423274332744327453274632747327483274932750327513275232753327543275532756327573275832759327603276132762327633276432765327663276732768327693277032771327723277332774327753277632777327783277932780327813278232783327843278532786327873278832789327903279132792327933279432795327963279732798327993280032801328023280332804328053280632807328083280932810328113281232813328143281532816328173281832819328203282132822328233282432825328263282732828328293283032831328323283332834328353283632837328383283932840328413284232843328443284532846328473284832849328503285132852328533285432855328563285732858328593286032861328623286332864328653286632867328683286932870328713287232873328743287532876328773287832879328803288132882328833288432885328863288732888328893289032891328923289332894328953289632897328983289932900329013290232903329043290532906329073290832909329103291132912329133291432915329163291732918329193292032921329223292332924329253292632927329283292932930329313293232933329343293532936329373293832939329403294132942329433294432945329463294732948329493295032951329523295332954329553295632957329583295932960329613296232963329643296532966329673296832969329703297132972329733297432975329763297732978329793298032981329823298332984329853298632987329883298932990329913299232993329943299532996329973299832999330003300133002330033300433005330063300733008330093301033011330123301333014330153301633017330183301933020330213302233023330243302533026330273302833029330303303133032330333303433035330363303733038330393304033041330423304333044330453304633047330483304933050330513305233053330543305533056330573305833059330603306133062330633306433065330663306733068330693307033071330723307333074330753307633077330783307933080330813308233083330843308533086330873308833089330903309133092330933309433095330963309733098330993310033101331023310333104331053310633107331083310933110331113311233113331143311533116331173311833119331203312133122331233312433125331263312733128331293313033131331323313333134331353313633137331383313933140331413314233143331443314533146331473314833149331503315133152331533315433155331563315733158331593316033161331623316333164331653316633167331683316933170331713317233173331743317533176331773317833179331803318133182331833318433185331863318733188331893319033191331923319333194331953319633197331983319933200332013320233203332043320533206332073320833209332103321133212332133321433215332163321733218332193322033221332223322333224332253322633227332283322933230332313323233233332343323533236332373323833239332403324133242332433324433245332463324733248332493325033251332523325333254332553325633257332583325933260332613326233263332643326533266332673326833269332703327133272332733327433275332763327733278332793328033281332823328333284332853328633287332883328933290332913329233293332943329533296332973329833299333003330133302333033330433305333063330733308333093331033311333123331333314333153331633317333183331933320333213332233323333243332533326333273332833329333303333133332333333333433335333363333733338333393334033341333423334333344333453334633347333483334933350333513335233353333543335533356333573335833359333603336133362333633336433365333663336733368333693337033371333723337333374333753337633377333783337933380333813338233383333843338533386333873338833389333903339133392333933339433395333963339733398333993340033401334023340333404334053340633407334083340933410334113341233413334143341533416334173341833419334203342133422334233342433425334263342733428334293343033431334323343333434334353343633437334383343933440334413344233443334443344533446334473344833449334503345133452334533345433455334563345733458334593346033461334623346333464334653346633467334683346933470334713347233473334743347533476334773347833479334803348133482334833348433485334863348733488334893349033491334923349333494334953349633497334983349933500335013350233503335043350533506335073350833509335103351133512335133351433515335163351733518335193352033521335223352333524335253352633527335283352933530335313353233533335343353533536335373353833539335403354133542335433354433545335463354733548335493355033551335523355333554335553355633557335583355933560335613356233563335643356533566335673356833569335703357133572335733357433575335763357733578335793358033581335823358333584335853358633587335883358933590335913359233593335943359533596335973359833599336003360133602336033360433605336063360733608336093361033611336123361333614336153361633617336183361933620336213362233623336243362533626336273362833629336303363133632336333363433635336363363733638336393364033641336423364333644336453364633647336483364933650336513365233653336543365533656336573365833659336603366133662336633366433665336663366733668336693367033671336723367333674336753367633677336783367933680336813368233683336843368533686336873368833689336903369133692336933369433695336963369733698336993370033701337023370333704337053370633707337083370933710337113371233713337143371533716337173371833719337203372133722337233372433725337263372733728337293373033731337323373333734337353373633737337383373933740337413374233743337443374533746337473374833749337503375133752337533375433755337563375733758337593376033761337623376333764337653376633767337683376933770337713377233773337743377533776337773377833779337803378133782337833378433785337863378733788337893379033791337923379333794337953379633797337983379933800338013380233803338043380533806338073380833809338103381133812338133381433815338163381733818338193382033821338223382333824338253382633827338283382933830338313383233833338343383533836338373383833839338403384133842338433384433845338463384733848338493385033851338523385333854338553385633857338583385933860338613386233863338643386533866338673386833869338703387133872338733387433875338763387733878338793388033881338823388333884338853388633887338883388933890338913389233893338943389533896338973389833899339003390133902339033390433905339063390733908339093391033911339123391333914339153391633917339183391933920339213392233923339243392533926339273392833929339303393133932339333393433935339363393733938339393394033941339423394333944339453394633947339483394933950339513395233953339543395533956339573395833959339603396133962339633396433965339663396733968339693397033971339723397333974339753397633977339783397933980339813398233983339843398533986339873398833989339903399133992339933399433995339963399733998339993400034001340023400334004340053400634007340083400934010340113401234013340143401534016340173401834019340203402134022340233402434025340263402734028340293403034031340323403334034340353403634037340383403934040340413404234043340443404534046340473404834049340503405134052340533405434055340563405734058340593406034061340623406334064340653406634067340683406934070340713407234073340743407534076340773407834079340803408134082340833408434085340863408734088340893409034091340923409334094340953409634097340983409934100341013410234103341043410534106341073410834109341103411134112341133411434115341163411734118341193412034121341223412334124341253412634127341283412934130341313413234133341343413534136341373413834139341403414134142341433414434145341463414734148341493415034151341523415334154341553415634157341583415934160341613416234163341643416534166341673416834169341703417134172341733417434175341763417734178341793418034181341823418334184341853418634187341883418934190341913419234193341943419534196341973419834199342003420134202342033420434205342063420734208342093421034211342123421334214342153421634217342183421934220342213422234223342243422534226342273422834229342303423134232342333423434235342363423734238342393424034241342423424334244342453424634247342483424934250342513425234253342543425534256342573425834259342603426134262342633426434265342663426734268342693427034271342723427334274342753427634277342783427934280342813428234283342843428534286342873428834289342903429134292342933429434295342963429734298342993430034301343023430334304343053430634307343083430934310343113431234313343143431534316343173431834319343203432134322343233432434325343263432734328343293433034331343323433334334343353433634337343383433934340343413434234343343443434534346343473434834349343503435134352343533435434355343563435734358343593436034361343623436334364343653436634367343683436934370343713437234373343743437534376343773437834379343803438134382343833438434385343863438734388343893439034391343923439334394343953439634397343983439934400344013440234403344043440534406344073440834409344103441134412344133441434415344163441734418344193442034421344223442334424344253442634427344283442934430344313443234433344343443534436344373443834439344403444134442344433444434445344463444734448344493445034451344523445334454344553445634457344583445934460344613446234463344643446534466344673446834469344703447134472344733447434475344763447734478344793448034481344823448334484344853448634487344883448934490344913449234493344943449534496344973449834499345003450134502345033450434505345063450734508345093451034511345123451334514345153451634517345183451934520345213452234523345243452534526345273452834529345303453134532345333453434535345363453734538345393454034541345423454334544345453454634547345483454934550345513455234553345543455534556345573455834559345603456134562345633456434565345663456734568345693457034571345723457334574345753457634577345783457934580345813458234583345843458534586345873458834589345903459134592345933459434595345963459734598345993460034601346023460334604346053460634607346083460934610346113461234613346143461534616346173461834619346203462134622346233462434625346263462734628346293463034631346323463334634346353463634637346383463934640346413464234643346443464534646346473464834649346503465134652346533465434655346563465734658346593466034661346623466334664346653466634667346683466934670346713467234673346743467534676346773467834679346803468134682346833468434685346863468734688346893469034691346923469334694346953469634697346983469934700347013470234703347043470534706347073470834709347103471134712347133471434715347163471734718347193472034721347223472334724347253472634727347283472934730347313473234733347343473534736347373473834739347403474134742347433474434745347463474734748347493475034751347523475334754347553475634757347583475934760347613476234763347643476534766347673476834769347703477134772347733477434775347763477734778347793478034781347823478334784347853478634787347883478934790347913479234793347943479534796347973479834799348003480134802348033480434805348063480734808348093481034811348123481334814348153481634817348183481934820348213482234823348243482534826348273482834829348303483134832348333483434835348363483734838348393484034841348423484334844348453484634847348483484934850348513485234853348543485534856348573485834859348603486134862348633486434865348663486734868348693487034871348723487334874348753487634877348783487934880348813488234883348843488534886348873488834889348903489134892348933489434895348963489734898348993490034901349023490334904349053490634907349083490934910349113491234913349143491534916349173491834919349203492134922349233492434925349263492734928349293493034931349323493334934349353493634937349383493934940349413494234943349443494534946349473494834949349503495134952349533495434955349563495734958349593496034961349623496334964349653496634967349683496934970349713497234973349743497534976349773497834979349803498134982349833498434985349863498734988349893499034991349923499334994349953499634997349983499935000350013500235003350043500535006350073500835009350103501135012350133501435015350163501735018350193502035021350223502335024350253502635027350283502935030350313503235033350343503535036350373503835039350403504135042350433504435045350463504735048350493505035051350523505335054350553505635057350583505935060350613506235063350643506535066350673506835069350703507135072350733507435075350763507735078350793508035081350823508335084350853508635087350883508935090350913509235093350943509535096350973509835099351003510135102351033510435105351063510735108351093511035111351123511335114351153511635117351183511935120351213512235123351243512535126351273512835129351303513135132351333513435135351363513735138351393514035141351423514335144351453514635147351483514935150351513515235153351543515535156351573515835159351603516135162351633516435165351663516735168351693517035171351723517335174351753517635177351783517935180351813518235183351843518535186351873518835189351903519135192351933519435195351963519735198351993520035201352023520335204352053520635207352083520935210352113521235213352143521535216352173521835219352203522135222352233522435225352263522735228352293523035231352323523335234352353523635237352383523935240352413524235243352443524535246352473524835249352503525135252352533525435255352563525735258352593526035261352623526335264352653526635267352683526935270352713527235273352743527535276352773527835279352803528135282352833528435285352863528735288352893529035291352923529335294352953529635297352983529935300353013530235303353043530535306353073530835309353103531135312353133531435315353163531735318353193532035321353223532335324353253532635327353283532935330353313533235333353343533535336353373533835339353403534135342353433534435345353463534735348353493535035351353523535335354353553535635357353583535935360353613536235363353643536535366353673536835369353703537135372353733537435375353763537735378353793538035381353823538335384353853538635387353883538935390353913539235393353943539535396353973539835399354003540135402354033540435405354063540735408354093541035411354123541335414354153541635417354183541935420354213542235423354243542535426354273542835429354303543135432354333543435435354363543735438354393544035441354423544335444354453544635447354483544935450354513545235453354543545535456354573545835459354603546135462354633546435465354663546735468354693547035471354723547335474354753547635477354783547935480354813548235483354843548535486354873548835489354903549135492354933549435495354963549735498354993550035501355023550335504355053550635507355083550935510355113551235513355143551535516355173551835519355203552135522355233552435525355263552735528355293553035531355323553335534355353553635537355383553935540355413554235543355443554535546355473554835549355503555135552355533555435555355563555735558355593556035561355623556335564355653556635567355683556935570355713557235573355743557535576355773557835579355803558135582355833558435585355863558735588355893559035591355923559335594355953559635597355983559935600356013560235603356043560535606356073560835609356103561135612356133561435615356163561735618356193562035621356223562335624356253562635627356283562935630356313563235633356343563535636356373563835639356403564135642356433564435645356463564735648356493565035651356523565335654356553565635657356583565935660356613566235663356643566535666356673566835669356703567135672356733567435675356763567735678356793568035681356823568335684356853568635687356883568935690356913569235693356943569535696356973569835699357003570135702357033570435705357063570735708357093571035711357123571335714357153571635717357183571935720357213572235723357243572535726357273572835729357303573135732357333573435735357363573735738357393574035741357423574335744357453574635747357483574935750357513575235753357543575535756357573575835759357603576135762357633576435765357663576735768357693577035771357723577335774357753577635777357783577935780357813578235783357843578535786357873578835789357903579135792357933579435795357963579735798357993580035801358023580335804358053580635807358083580935810358113581235813358143581535816358173581835819358203582135822358233582435825358263582735828358293583035831358323583335834358353583635837358383583935840358413584235843358443584535846358473584835849358503585135852358533585435855358563585735858358593586035861358623586335864358653586635867358683586935870358713587235873358743587535876358773587835879358803588135882358833588435885358863588735888358893589035891358923589335894358953589635897358983589935900359013590235903359043590535906359073590835909359103591135912359133591435915359163591735918359193592035921359223592335924359253592635927359283592935930359313593235933359343593535936359373593835939359403594135942359433594435945359463594735948359493595035951359523595335954359553595635957359583595935960359613596235963359643596535966359673596835969359703597135972359733597435975359763597735978359793598035981359823598335984359853598635987359883598935990359913599235993359943599535996359973599835999360003600136002360033600436005360063600736008360093601036011360123601336014360153601636017360183601936020360213602236023360243602536026360273602836029360303603136032360333603436035360363603736038360393604036041360423604336044360453604636047360483604936050360513605236053360543605536056360573605836059360603606136062360633606436065360663606736068360693607036071360723607336074360753607636077360783607936080360813608236083360843608536086360873608836089360903609136092360933609436095360963609736098360993610036101361023610336104361053610636107361083610936110361113611236113361143611536116361173611836119361203612136122361233612436125361263612736128361293613036131361323613336134361353613636137361383613936140361413614236143361443614536146361473614836149361503615136152361533615436155361563615736158361593616036161361623616336164361653616636167361683616936170361713617236173361743617536176361773617836179361803618136182361833618436185361863618736188361893619036191361923619336194361953619636197361983619936200362013620236203362043620536206362073620836209362103621136212362133621436215362163621736218362193622036221362223622336224362253622636227362283622936230362313623236233362343623536236362373623836239362403624136242362433624436245362463624736248362493625036251362523625336254362553625636257362583625936260362613626236263362643626536266362673626836269362703627136272362733627436275362763627736278362793628036281362823628336284362853628636287362883628936290362913629236293362943629536296362973629836299363003630136302363033630436305363063630736308363093631036311363123631336314363153631636317363183631936320363213632236323363243632536326363273632836329363303633136332363333633436335363363633736338363393634036341363423634336344363453634636347363483634936350363513635236353363543635536356363573635836359363603636136362363633636436365363663636736368363693637036371363723637336374363753637636377363783637936380363813638236383363843638536386363873638836389363903639136392363933639436395363963639736398363993640036401364023640336404364053640636407364083640936410364113641236413364143641536416364173641836419364203642136422364233642436425364263642736428364293643036431364323643336434364353643636437364383643936440364413644236443364443644536446364473644836449364503645136452364533645436455364563645736458364593646036461364623646336464364653646636467364683646936470364713647236473364743647536476364773647836479364803648136482364833648436485364863648736488364893649036491364923649336494364953649636497364983649936500365013650236503365043650536506365073650836509365103651136512365133651436515365163651736518365193652036521365223652336524365253652636527365283652936530365313653236533365343653536536365373653836539365403654136542365433654436545365463654736548365493655036551365523655336554365553655636557365583655936560365613656236563365643656536566365673656836569365703657136572365733657436575365763657736578365793658036581365823658336584365853658636587365883658936590365913659236593365943659536596365973659836599366003660136602366033660436605366063660736608366093661036611366123661336614366153661636617366183661936620366213662236623366243662536626366273662836629366303663136632366333663436635366363663736638366393664036641366423664336644366453664636647366483664936650366513665236653366543665536656366573665836659366603666136662366633666436665366663666736668366693667036671366723667336674366753667636677366783667936680366813668236683366843668536686366873668836689366903669136692366933669436695366963669736698366993670036701367023670336704367053670636707367083670936710367113671236713367143671536716367173671836719367203672136722367233672436725367263672736728367293673036731367323673336734367353673636737367383673936740367413674236743367443674536746367473674836749367503675136752367533675436755367563675736758367593676036761367623676336764367653676636767367683676936770367713677236773367743677536776367773677836779367803678136782367833678436785367863678736788367893679036791367923679336794367953679636797367983679936800368013680236803368043680536806368073680836809368103681136812368133681436815368163681736818368193682036821368223682336824368253682636827368283682936830368313683236833368343683536836368373683836839368403684136842368433684436845368463684736848368493685036851368523685336854368553685636857368583685936860368613686236863368643686536866368673686836869368703687136872368733687436875368763687736878368793688036881368823688336884368853688636887368883688936890368913689236893368943689536896368973689836899369003690136902369033690436905369063690736908369093691036911369123691336914369153691636917369183691936920369213692236923369243692536926369273692836929369303693136932369333693436935369363693736938369393694036941369423694336944369453694636947369483694936950369513695236953369543695536956369573695836959369603696136962369633696436965369663696736968369693697036971369723697336974369753697636977369783697936980369813698236983369843698536986369873698836989369903699136992369933699436995369963699736998369993700037001370023700337004370053700637007370083700937010370113701237013370143701537016370173701837019370203702137022370233702437025370263702737028370293703037031370323703337034370353703637037370383703937040370413704237043370443704537046370473704837049370503705137052370533705437055370563705737058370593706037061370623706337064370653706637067370683706937070370713707237073370743707537076370773707837079370803708137082370833708437085370863708737088370893709037091370923709337094370953709637097370983709937100371013710237103371043710537106371073710837109371103711137112371133711437115371163711737118371193712037121371223712337124371253712637127371283712937130371313713237133371343713537136371373713837139371403714137142371433714437145371463714737148371493715037151371523715337154371553715637157371583715937160371613716237163371643716537166371673716837169371703717137172371733717437175371763717737178371793718037181371823718337184371853718637187371883718937190371913719237193371943719537196371973719837199372003720137202372033720437205372063720737208372093721037211372123721337214372153721637217372183721937220372213722237223372243722537226372273722837229372303723137232372333723437235372363723737238372393724037241372423724337244372453724637247372483724937250372513725237253372543725537256372573725837259372603726137262372633726437265372663726737268372693727037271372723727337274372753727637277372783727937280372813728237283372843728537286372873728837289372903729137292372933729437295372963729737298372993730037301373023730337304373053730637307373083730937310373113731237313373143731537316373173731837319373203732137322373233732437325373263732737328373293733037331373323733337334373353733637337373383733937340373413734237343373443734537346373473734837349373503735137352373533735437355373563735737358373593736037361373623736337364373653736637367373683736937370373713737237373373743737537376373773737837379373803738137382373833738437385373863738737388373893739037391373923739337394373953739637397373983739937400374013740237403374043740537406374073740837409374103741137412374133741437415374163741737418374193742037421374223742337424374253742637427374283742937430374313743237433374343743537436374373743837439374403744137442374433744437445374463744737448374493745037451374523745337454374553745637457374583745937460374613746237463374643746537466374673746837469374703747137472374733747437475374763747737478374793748037481374823748337484374853748637487374883748937490374913749237493374943749537496374973749837499375003750137502375033750437505375063750737508375093751037511375123751337514375153751637517375183751937520375213752237523375243752537526375273752837529375303753137532375333753437535375363753737538375393754037541375423754337544375453754637547375483754937550375513755237553375543755537556375573755837559375603756137562375633756437565375663756737568375693757037571375723757337574375753757637577375783757937580375813758237583375843758537586375873758837589375903759137592375933759437595375963759737598375993760037601376023760337604376053760637607376083760937610376113761237613376143761537616376173761837619376203762137622376233762437625376263762737628376293763037631376323763337634376353763637637376383763937640376413764237643376443764537646376473764837649376503765137652376533765437655376563765737658376593766037661376623766337664376653766637667376683766937670376713767237673376743767537676376773767837679376803768137682376833768437685376863768737688376893769037691376923769337694376953769637697376983769937700377013770237703377043770537706377073770837709377103771137712377133771437715377163771737718377193772037721377223772337724377253772637727377283772937730377313773237733377343773537736377373773837739377403774137742377433774437745377463774737748377493775037751377523775337754377553775637757377583775937760377613776237763377643776537766377673776837769377703777137772377733777437775377763777737778377793778037781377823778337784377853778637787377883778937790377913779237793377943779537796377973779837799378003780137802378033780437805378063780737808378093781037811378123781337814378153781637817378183781937820378213782237823378243782537826378273782837829378303783137832378333783437835378363783737838378393784037841378423784337844378453784637847378483784937850378513785237853378543785537856378573785837859378603786137862378633786437865378663786737868378693787037871378723787337874378753787637877378783787937880378813788237883378843788537886378873788837889378903789137892378933789437895378963789737898378993790037901379023790337904379053790637907379083790937910379113791237913379143791537916379173791837919379203792137922379233792437925379263792737928379293793037931379323793337934379353793637937379383793937940379413794237943379443794537946379473794837949379503795137952379533795437955379563795737958379593796037961379623796337964379653796637967379683796937970379713797237973379743797537976379773797837979379803798137982379833798437985379863798737988379893799037991379923799337994379953799637997379983799938000380013800238003380043800538006380073800838009380103801138012380133801438015380163801738018380193802038021380223802338024380253802638027380283802938030380313803238033380343803538036380373803838039380403804138042380433804438045380463804738048380493805038051380523805338054380553805638057380583805938060380613806238063380643806538066380673806838069380703807138072380733807438075380763807738078380793808038081380823808338084380853808638087380883808938090380913809238093380943809538096380973809838099381003810138102381033810438105381063810738108381093811038111381123811338114381153811638117381183811938120381213812238123381243812538126381273812838129381303813138132381333813438135381363813738138381393814038141381423814338144381453814638147381483814938150381513815238153381543815538156381573815838159381603816138162381633816438165381663816738168381693817038171381723817338174381753817638177381783817938180381813818238183381843818538186381873818838189381903819138192381933819438195381963819738198381993820038201382023820338204382053820638207382083820938210382113821238213382143821538216382173821838219382203822138222382233822438225382263822738228382293823038231382323823338234382353823638237382383823938240382413824238243382443824538246382473824838249382503825138252382533825438255382563825738258382593826038261382623826338264382653826638267382683826938270382713827238273382743827538276382773827838279382803828138282382833828438285382863828738288382893829038291382923829338294382953829638297382983829938300383013830238303383043830538306383073830838309383103831138312383133831438315383163831738318383193832038321383223832338324383253832638327383283832938330383313833238333383343833538336383373833838339383403834138342383433834438345383463834738348383493835038351383523835338354383553835638357383583835938360383613836238363383643836538366383673836838369383703837138372383733837438375383763837738378383793838038381383823838338384383853838638387383883838938390383913839238393383943839538396383973839838399384003840138402384033840438405384063840738408384093841038411384123841338414384153841638417384183841938420384213842238423384243842538426384273842838429384303843138432384333843438435384363843738438384393844038441384423844338444384453844638447384483844938450384513845238453384543845538456384573845838459384603846138462384633846438465384663846738468384693847038471384723847338474384753847638477384783847938480384813848238483384843848538486384873848838489384903849138492384933849438495384963849738498384993850038501385023850338504385053850638507385083850938510385113851238513385143851538516385173851838519385203852138522385233852438525385263852738528385293853038531385323853338534385353853638537385383853938540385413854238543385443854538546385473854838549385503855138552385533855438555385563855738558385593856038561385623856338564385653856638567385683856938570385713857238573385743857538576385773857838579385803858138582385833858438585385863858738588385893859038591385923859338594385953859638597385983859938600386013860238603386043860538606386073860838609386103861138612386133861438615386163861738618386193862038621386223862338624386253862638627386283862938630386313863238633386343863538636386373863838639386403864138642386433864438645386463864738648386493865038651386523865338654386553865638657386583865938660386613866238663386643866538666386673866838669386703867138672386733867438675386763867738678386793868038681386823868338684386853868638687386883868938690386913869238693386943869538696386973869838699387003870138702387033870438705387063870738708387093871038711387123871338714387153871638717387183871938720387213872238723387243872538726387273872838729387303873138732387333873438735387363873738738387393874038741387423874338744387453874638747387483874938750387513875238753387543875538756387573875838759387603876138762387633876438765387663876738768387693877038771387723877338774387753877638777387783877938780387813878238783387843878538786387873878838789387903879138792387933879438795387963879738798387993880038801388023880338804388053880638807388083880938810388113881238813388143881538816388173881838819388203882138822388233882438825388263882738828388293883038831388323883338834388353883638837388383883938840388413884238843388443884538846388473884838849388503885138852388533885438855388563885738858388593886038861388623886338864388653886638867388683886938870388713887238873388743887538876388773887838879388803888138882388833888438885388863888738888388893889038891388923889338894388953889638897388983889938900389013890238903389043890538906389073890838909389103891138912389133891438915389163891738918389193892038921389223892338924389253892638927389283892938930389313893238933389343893538936389373893838939389403894138942389433894438945389463894738948389493895038951389523895338954389553895638957389583895938960389613896238963389643896538966389673896838969389703897138972389733897438975389763897738978389793898038981389823898338984389853898638987389883898938990389913899238993389943899538996389973899838999390003900139002390033900439005390063900739008390093901039011390123901339014390153901639017390183901939020390213902239023390243902539026390273902839029390303903139032390333903439035390363903739038390393904039041390423904339044390453904639047390483904939050390513905239053390543905539056390573905839059390603906139062390633906439065390663906739068390693907039071390723907339074390753907639077390783907939080390813908239083390843908539086390873908839089390903909139092390933909439095390963909739098390993910039101391023910339104391053910639107391083910939110391113911239113391143911539116391173911839119391203912139122391233912439125391263912739128391293913039131391323913339134391353913639137391383913939140391413914239143391443914539146391473914839149391503915139152391533915439155391563915739158391593916039161391623916339164391653916639167391683916939170391713917239173391743917539176391773917839179391803918139182391833918439185391863918739188391893919039191391923919339194391953919639197391983919939200392013920239203392043920539206392073920839209392103921139212392133921439215392163921739218392193922039221392223922339224392253922639227392283922939230392313923239233392343923539236392373923839239392403924139242392433924439245392463924739248392493925039251392523925339254392553925639257392583925939260392613926239263392643926539266392673926839269392703927139272392733927439275392763927739278392793928039281392823928339284392853928639287392883928939290392913929239293392943929539296392973929839299393003930139302393033930439305393063930739308393093931039311393123931339314393153931639317393183931939320393213932239323393243932539326393273932839329393303933139332393333933439335393363933739338393393934039341393423934339344393453934639347393483934939350393513935239353393543935539356393573935839359393603936139362393633936439365393663936739368393693937039371393723937339374393753937639377393783937939380393813938239383393843938539386393873938839389393903939139392393933939439395393963939739398393993940039401394023940339404394053940639407394083940939410394113941239413394143941539416394173941839419394203942139422394233942439425394263942739428394293943039431394323943339434394353943639437394383943939440394413944239443394443944539446394473944839449394503945139452394533945439455394563945739458394593946039461394623946339464394653946639467394683946939470394713947239473394743947539476394773947839479394803948139482394833948439485394863948739488394893949039491394923949339494394953949639497394983949939500395013950239503395043950539506395073950839509395103951139512395133951439515395163951739518395193952039521395223952339524395253952639527395283952939530395313953239533395343953539536395373953839539395403954139542395433954439545395463954739548395493955039551395523955339554395553955639557395583955939560395613956239563395643956539566395673956839569395703957139572395733957439575395763957739578395793958039581395823958339584395853958639587395883958939590395913959239593395943959539596395973959839599396003960139602396033960439605396063960739608396093961039611396123961339614396153961639617396183961939620396213962239623396243962539626396273962839629396303963139632396333963439635396363963739638396393964039641396423964339644396453964639647396483964939650396513965239653396543965539656396573965839659396603966139662396633966439665396663966739668396693967039671396723967339674396753967639677396783967939680396813968239683396843968539686396873968839689396903969139692396933969439695396963969739698396993970039701397023970339704397053970639707397083970939710397113971239713397143971539716397173971839719397203972139722397233972439725397263972739728397293973039731397323973339734397353973639737397383973939740397413974239743397443974539746397473974839749397503975139752397533975439755397563975739758397593976039761397623976339764397653976639767397683976939770397713977239773397743977539776397773977839779397803978139782397833978439785397863978739788397893979039791397923979339794397953979639797397983979939800398013980239803398043980539806398073980839809398103981139812398133981439815398163981739818398193982039821398223982339824398253982639827398283982939830398313983239833398343983539836398373983839839398403984139842398433984439845398463984739848398493985039851398523985339854398553985639857398583985939860398613986239863398643986539866398673986839869398703987139872398733987439875398763987739878398793988039881398823988339884398853988639887398883988939890398913989239893398943989539896398973989839899399003990139902399033990439905399063990739908399093991039911399123991339914399153991639917399183991939920399213992239923399243992539926399273992839929399303993139932399333993439935399363993739938399393994039941399423994339944399453994639947399483994939950399513995239953399543995539956399573995839959399603996139962399633996439965399663996739968399693997039971399723997339974399753997639977399783997939980399813998239983399843998539986399873998839989399903999139992399933999439995399963999739998399994000040001400024000340004400054000640007400084000940010400114001240013400144001540016400174001840019400204002140022400234002440025400264002740028400294003040031400324003340034400354003640037400384003940040400414004240043400444004540046400474004840049400504005140052400534005440055400564005740058400594006040061400624006340064400654006640067400684006940070400714007240073400744007540076400774007840079400804008140082400834008440085400864008740088400894009040091400924009340094400954009640097400984009940100401014010240103401044010540106401074010840109401104011140112401134011440115401164011740118401194012040121401224012340124401254012640127401284012940130401314013240133401344013540136401374013840139401404014140142401434014440145401464014740148401494015040151401524015340154401554015640157401584015940160401614016240163401644016540166401674016840169401704017140172401734017440175401764017740178401794018040181401824018340184401854018640187401884018940190401914019240193401944019540196401974019840199402004020140202402034020440205402064020740208402094021040211402124021340214402154021640217402184021940220402214022240223402244022540226402274022840229402304023140232402334023440235402364023740238402394024040241402424024340244402454024640247402484024940250402514025240253402544025540256402574025840259402604026140262402634026440265402664026740268402694027040271402724027340274402754027640277402784027940280402814028240283402844028540286402874028840289402904029140292402934029440295402964029740298402994030040301403024030340304403054030640307403084030940310403114031240313403144031540316403174031840319403204032140322403234032440325403264032740328403294033040331403324033340334403354033640337403384033940340403414034240343403444034540346403474034840349403504035140352403534035440355403564035740358403594036040361403624036340364403654036640367403684036940370403714037240373403744037540376403774037840379403804038140382403834038440385403864038740388403894039040391403924039340394403954039640397403984039940400404014040240403404044040540406404074040840409404104041140412404134041440415404164041740418404194042040421404224042340424404254042640427404284042940430404314043240433404344043540436404374043840439404404044140442404434044440445404464044740448404494045040451404524045340454404554045640457404584045940460404614046240463404644046540466404674046840469404704047140472404734047440475404764047740478404794048040481404824048340484404854048640487404884048940490404914049240493404944049540496404974049840499405004050140502405034050440505405064050740508405094051040511405124051340514405154051640517405184051940520405214052240523405244052540526405274052840529405304053140532405334053440535405364053740538405394054040541405424054340544405454054640547405484054940550405514055240553405544055540556405574055840559405604056140562405634056440565405664056740568405694057040571405724057340574405754057640577405784057940580405814058240583405844058540586405874058840589405904059140592405934059440595405964059740598405994060040601406024060340604406054060640607406084060940610406114061240613406144061540616406174061840619406204062140622406234062440625406264062740628406294063040631406324063340634406354063640637406384063940640406414064240643406444064540646406474064840649406504065140652406534065440655406564065740658406594066040661406624066340664406654066640667406684066940670406714067240673406744067540676406774067840679406804068140682406834068440685406864068740688406894069040691406924069340694406954069640697406984069940700407014070240703407044070540706407074070840709407104071140712407134071440715407164071740718407194072040721407224072340724407254072640727407284072940730407314073240733407344073540736407374073840739407404074140742407434074440745407464074740748407494075040751407524075340754407554075640757407584075940760407614076240763407644076540766407674076840769407704077140772407734077440775407764077740778407794078040781407824078340784407854078640787407884078940790407914079240793407944079540796407974079840799408004080140802408034080440805408064080740808408094081040811408124081340814408154081640817408184081940820408214082240823408244082540826408274082840829408304083140832408334083440835408364083740838408394084040841408424084340844408454084640847408484084940850408514085240853408544085540856408574085840859408604086140862408634086440865408664086740868408694087040871408724087340874408754087640877408784087940880408814088240883408844088540886408874088840889408904089140892408934089440895408964089740898408994090040901409024090340904409054090640907409084090940910409114091240913409144091540916409174091840919409204092140922409234092440925409264092740928409294093040931409324093340934409354093640937409384093940940409414094240943409444094540946409474094840949409504095140952409534095440955409564095740958409594096040961409624096340964409654096640967409684096940970409714097240973409744097540976409774097840979409804098140982409834098440985409864098740988409894099040991409924099340994409954099640997409984099941000410014100241003410044100541006410074100841009410104101141012410134101441015410164101741018410194102041021410224102341024410254102641027410284102941030410314103241033410344103541036410374103841039410404104141042410434104441045410464104741048410494105041051410524105341054410554105641057410584105941060410614106241063410644106541066410674106841069410704107141072410734107441075410764107741078410794108041081410824108341084410854108641087410884108941090410914109241093410944109541096410974109841099411004110141102411034110441105411064110741108411094111041111411124111341114411154111641117411184111941120411214112241123411244112541126411274112841129411304113141132411334113441135411364113741138411394114041141411424114341144411454114641147411484114941150411514115241153411544115541156411574115841159411604116141162411634116441165411664116741168411694117041171411724117341174411754117641177411784117941180411814118241183411844118541186411874118841189411904119141192411934119441195411964119741198411994120041201412024120341204412054120641207412084120941210412114121241213412144121541216412174121841219412204122141222412234122441225412264122741228412294123041231412324123341234412354123641237412384123941240412414124241243412444124541246412474124841249412504125141252412534125441255412564125741258412594126041261412624126341264412654126641267412684126941270412714127241273412744127541276412774127841279412804128141282412834128441285412864128741288412894129041291412924129341294412954129641297412984129941300413014130241303413044130541306413074130841309413104131141312413134131441315413164131741318413194132041321413224132341324413254132641327413284132941330413314133241333413344133541336413374133841339413404134141342413434134441345413464134741348413494135041351413524135341354413554135641357413584135941360413614136241363413644136541366413674136841369413704137141372413734137441375413764137741378413794138041381413824138341384413854138641387413884138941390413914139241393413944139541396413974139841399414004140141402414034140441405414064140741408414094141041411414124141341414414154141641417414184141941420414214142241423414244142541426414274142841429414304143141432414334143441435414364143741438414394144041441414424144341444414454144641447414484144941450414514145241453414544145541456414574145841459414604146141462414634146441465414664146741468414694147041471414724147341474414754147641477414784147941480414814148241483414844148541486414874148841489414904149141492414934149441495414964149741498414994150041501415024150341504415054150641507415084150941510415114151241513415144151541516415174151841519415204152141522415234152441525415264152741528415294153041531415324153341534415354153641537415384153941540415414154241543415444154541546415474154841549415504155141552415534155441555415564155741558415594156041561415624156341564415654156641567415684156941570415714157241573415744157541576415774157841579415804158141582415834158441585415864158741588415894159041591415924159341594415954159641597415984159941600416014160241603416044160541606416074160841609416104161141612416134161441615416164161741618416194162041621416224162341624416254162641627416284162941630416314163241633416344163541636416374163841639416404164141642416434164441645416464164741648416494165041651416524165341654416554165641657416584165941660416614166241663416644166541666416674166841669416704167141672416734167441675416764167741678416794168041681416824168341684416854168641687416884168941690416914169241693416944169541696416974169841699417004170141702417034170441705417064170741708417094171041711417124171341714417154171641717417184171941720417214172241723417244172541726417274172841729417304173141732417334173441735417364173741738417394174041741417424174341744417454174641747417484174941750417514175241753417544175541756417574175841759417604176141762417634176441765417664176741768417694177041771417724177341774417754177641777417784177941780417814178241783417844178541786417874178841789417904179141792417934179441795417964179741798417994180041801418024180341804418054180641807418084180941810418114181241813418144181541816418174181841819418204182141822418234182441825418264182741828418294183041831418324183341834418354183641837418384183941840418414184241843418444184541846418474184841849418504185141852418534185441855418564185741858418594186041861418624186341864418654186641867418684186941870418714187241873418744187541876418774187841879418804188141882418834188441885418864188741888418894189041891418924189341894418954189641897418984189941900419014190241903419044190541906419074190841909419104191141912419134191441915419164191741918419194192041921419224192341924419254192641927419284192941930419314193241933419344193541936419374193841939419404194141942419434194441945419464194741948419494195041951419524195341954419554195641957419584195941960419614196241963419644196541966419674196841969419704197141972419734197441975419764197741978419794198041981419824198341984419854198641987419884198941990419914199241993419944199541996419974199841999420004200142002420034200442005420064200742008420094201042011420124201342014420154201642017420184201942020420214202242023420244202542026420274202842029420304203142032420334203442035420364203742038420394204042041420424204342044420454204642047420484204942050420514205242053420544205542056420574205842059420604206142062420634206442065420664206742068420694207042071420724207342074420754207642077420784207942080420814208242083420844208542086420874208842089420904209142092420934209442095420964209742098420994210042101421024210342104421054210642107421084210942110421114211242113421144211542116421174211842119421204212142122421234212442125421264212742128421294213042131421324213342134421354213642137421384213942140421414214242143421444214542146421474214842149421504215142152421534215442155421564215742158421594216042161421624216342164421654216642167421684216942170421714217242173421744217542176421774217842179421804218142182421834218442185421864218742188421894219042191421924219342194421954219642197421984219942200422014220242203422044220542206422074220842209422104221142212422134221442215422164221742218422194222042221422224222342224422254222642227422284222942230422314223242233422344223542236422374223842239422404224142242422434224442245422464224742248422494225042251422524225342254422554225642257422584225942260422614226242263422644226542266422674226842269422704227142272422734227442275422764227742278422794228042281422824228342284422854228642287422884228942290422914229242293422944229542296422974229842299423004230142302423034230442305423064230742308423094231042311423124231342314423154231642317423184231942320423214232242323423244232542326423274232842329423304233142332423334233442335423364233742338423394234042341423424234342344423454234642347423484234942350423514235242353423544235542356423574235842359423604236142362423634236442365423664236742368423694237042371423724237342374423754237642377423784237942380423814238242383423844238542386423874238842389423904239142392423934239442395423964239742398423994240042401424024240342404424054240642407424084240942410424114241242413424144241542416424174241842419424204242142422424234242442425424264242742428424294243042431424324243342434424354243642437424384243942440424414244242443424444244542446424474244842449424504245142452424534245442455424564245742458424594246042461424624246342464424654246642467424684246942470424714247242473424744247542476424774247842479424804248142482424834248442485424864248742488424894249042491424924249342494424954249642497424984249942500425014250242503425044250542506425074250842509425104251142512425134251442515425164251742518425194252042521425224252342524425254252642527425284252942530425314253242533425344253542536425374253842539425404254142542425434254442545425464254742548425494255042551425524255342554425554255642557425584255942560425614256242563425644256542566425674256842569425704257142572425734257442575425764257742578425794258042581425824258342584425854258642587425884258942590425914259242593425944259542596425974259842599426004260142602426034260442605426064260742608426094261042611426124261342614426154261642617426184261942620426214262242623426244262542626426274262842629426304263142632426334263442635426364263742638426394264042641426424264342644426454264642647426484264942650426514265242653426544265542656426574265842659426604266142662426634266442665426664266742668426694267042671426724267342674426754267642677426784267942680426814268242683426844268542686426874268842689426904269142692426934269442695426964269742698426994270042701427024270342704427054270642707427084270942710427114271242713427144271542716427174271842719427204272142722427234272442725427264272742728427294273042731427324273342734427354273642737427384273942740427414274242743427444274542746427474274842749427504275142752427534275442755427564275742758427594276042761427624276342764427654276642767427684276942770427714277242773427744277542776427774277842779427804278142782427834278442785427864278742788427894279042791427924279342794427954279642797427984279942800428014280242803428044280542806428074280842809428104281142812428134281442815428164281742818428194282042821428224282342824428254282642827428284282942830428314283242833428344283542836428374283842839428404284142842428434284442845428464284742848428494285042851428524285342854428554285642857428584285942860428614286242863428644286542866428674286842869428704287142872428734287442875428764287742878428794288042881428824288342884428854288642887428884288942890428914289242893428944289542896428974289842899429004290142902429034290442905429064290742908429094291042911429124291342914429154291642917429184291942920429214292242923429244292542926429274292842929429304293142932429334293442935429364293742938429394294042941429424294342944429454294642947429484294942950429514295242953429544295542956429574295842959429604296142962429634296442965429664296742968429694297042971429724297342974429754297642977429784297942980429814298242983429844298542986429874298842989429904299142992429934299442995429964299742998429994300043001430024300343004430054300643007430084300943010430114301243013430144301543016430174301843019430204302143022430234302443025430264302743028430294303043031430324303343034430354303643037430384303943040430414304243043430444304543046430474304843049430504305143052430534305443055430564305743058430594306043061430624306343064430654306643067430684306943070430714307243073430744307543076430774307843079430804308143082430834308443085430864308743088430894309043091430924309343094430954309643097430984309943100431014310243103431044310543106431074310843109431104311143112431134311443115431164311743118431194312043121431224312343124431254312643127431284312943130431314313243133431344313543136431374313843139431404314143142431434314443145431464314743148431494315043151431524315343154431554315643157431584315943160431614316243163431644316543166431674316843169431704317143172431734317443175431764317743178431794318043181431824318343184431854318643187431884318943190431914319243193431944319543196431974319843199432004320143202432034320443205432064320743208432094321043211432124321343214432154321643217432184321943220432214322243223432244322543226432274322843229432304323143232432334323443235432364323743238432394324043241432424324343244432454324643247432484324943250432514325243253432544325543256432574325843259432604326143262432634326443265432664326743268432694327043271432724327343274432754327643277432784327943280432814328243283432844328543286432874328843289432904329143292432934329443295432964329743298432994330043301433024330343304433054330643307433084330943310433114331243313433144331543316433174331843319433204332143322433234332443325433264332743328433294333043331433324333343334433354333643337433384333943340433414334243343433444334543346433474334843349433504335143352433534335443355433564335743358433594336043361433624336343364433654336643367433684336943370433714337243373433744337543376433774337843379433804338143382433834338443385433864338743388433894339043391433924339343394433954339643397433984339943400434014340243403434044340543406434074340843409434104341143412434134341443415434164341743418434194342043421434224342343424434254342643427434284342943430434314343243433434344343543436434374343843439434404344143442434434344443445434464344743448434494345043451434524345343454434554345643457434584345943460434614346243463434644346543466434674346843469434704347143472434734347443475434764347743478434794348043481434824348343484434854348643487434884348943490434914349243493434944349543496434974349843499435004350143502435034350443505435064350743508435094351043511435124351343514435154351643517435184351943520435214352243523435244352543526435274352843529435304353143532435334353443535435364353743538435394354043541435424354343544435454354643547435484354943550435514355243553435544355543556435574355843559435604356143562435634356443565435664356743568435694357043571435724357343574435754357643577435784357943580435814358243583435844358543586435874358843589435904359143592435934359443595435964359743598435994360043601436024360343604436054360643607436084360943610436114361243613436144361543616436174361843619436204362143622436234362443625436264362743628436294363043631436324363343634436354363643637436384363943640436414364243643436444364543646436474364843649436504365143652436534365443655436564365743658436594366043661436624366343664436654366643667436684366943670436714367243673436744367543676436774367843679436804368143682436834368443685436864368743688436894369043691436924369343694436954369643697436984369943700437014370243703437044370543706437074370843709437104371143712437134371443715437164371743718437194372043721437224372343724437254372643727437284372943730437314373243733437344373543736437374373843739437404374143742437434374443745437464374743748437494375043751437524375343754437554375643757437584375943760437614376243763437644376543766437674376843769437704377143772437734377443775437764377743778437794378043781437824378343784437854378643787437884378943790437914379243793437944379543796437974379843799438004380143802
  1. /*!
  2. * pixi.js - v6.1.2
  3. * Compiled Thu, 12 Aug 2021 17:11:19 UTC
  4. *
  5. * pixi.js is licensed under the MIT License.
  6. * http://www.opensource.org/licenses/mit-license
  7. */
  8. var PIXI = (function (exports) {
  9. 'use strict';
  10. /**
  11. * @this {Promise}
  12. */
  13. function finallyConstructor(callback) {
  14. var constructor = this.constructor;
  15. return this.then(
  16. function(value) {
  17. // @ts-ignore
  18. return constructor.resolve(callback()).then(function() {
  19. return value;
  20. });
  21. },
  22. function(reason) {
  23. // @ts-ignore
  24. return constructor.resolve(callback()).then(function() {
  25. // @ts-ignore
  26. return constructor.reject(reason);
  27. });
  28. }
  29. );
  30. }
  31. function allSettled(arr) {
  32. var P = this;
  33. return new P(function(resolve, reject) {
  34. if (!(arr && typeof arr.length !== 'undefined')) {
  35. return reject(
  36. new TypeError(
  37. typeof arr +
  38. ' ' +
  39. arr +
  40. ' is not iterable(cannot read property Symbol(Symbol.iterator))'
  41. )
  42. );
  43. }
  44. var args = Array.prototype.slice.call(arr);
  45. if (args.length === 0) { return resolve([]); }
  46. var remaining = args.length;
  47. function res(i, val) {
  48. if (val && (typeof val === 'object' || typeof val === 'function')) {
  49. var then = val.then;
  50. if (typeof then === 'function') {
  51. then.call(
  52. val,
  53. function(val) {
  54. res(i, val);
  55. },
  56. function(e) {
  57. args[i] = { status: 'rejected', reason: e };
  58. if (--remaining === 0) {
  59. resolve(args);
  60. }
  61. }
  62. );
  63. return;
  64. }
  65. }
  66. args[i] = { status: 'fulfilled', value: val };
  67. if (--remaining === 0) {
  68. resolve(args);
  69. }
  70. }
  71. for (var i = 0; i < args.length; i++) {
  72. res(i, args[i]);
  73. }
  74. });
  75. }
  76. // Store setTimeout reference so promise-polyfill will be unaffected by
  77. // other code modifying setTimeout (like sinon.useFakeTimers())
  78. var setTimeoutFunc = setTimeout;
  79. function isArray(x) {
  80. return Boolean(x && typeof x.length !== 'undefined');
  81. }
  82. function noop() {}
  83. // Polyfill for Function.prototype.bind
  84. function bind(fn, thisArg) {
  85. return function() {
  86. fn.apply(thisArg, arguments);
  87. };
  88. }
  89. /**
  90. * @constructor
  91. * @param {Function} fn
  92. */
  93. function Promise$1(fn) {
  94. if (!(this instanceof Promise$1))
  95. { throw new TypeError('Promises must be constructed via new'); }
  96. if (typeof fn !== 'function') { throw new TypeError('not a function'); }
  97. /** @type {!number} */
  98. this._state = 0;
  99. /** @type {!boolean} */
  100. this._handled = false;
  101. /** @type {Promise|undefined} */
  102. this._value = undefined;
  103. /** @type {!Array<!Function>} */
  104. this._deferreds = [];
  105. doResolve(fn, this);
  106. }
  107. function handle(self, deferred) {
  108. while (self._state === 3) {
  109. self = self._value;
  110. }
  111. if (self._state === 0) {
  112. self._deferreds.push(deferred);
  113. return;
  114. }
  115. self._handled = true;
  116. Promise$1._immediateFn(function() {
  117. var cb = self._state === 1 ? deferred.onFulfilled : deferred.onRejected;
  118. if (cb === null) {
  119. (self._state === 1 ? resolve : reject)(deferred.promise, self._value);
  120. return;
  121. }
  122. var ret;
  123. try {
  124. ret = cb(self._value);
  125. } catch (e) {
  126. reject(deferred.promise, e);
  127. return;
  128. }
  129. resolve(deferred.promise, ret);
  130. });
  131. }
  132. function resolve(self, newValue) {
  133. try {
  134. // Promise Resolution Procedure: https://github.com/promises-aplus/promises-spec#the-promise-resolution-procedure
  135. if (newValue === self)
  136. { throw new TypeError('A promise cannot be resolved with itself.'); }
  137. if (
  138. newValue &&
  139. (typeof newValue === 'object' || typeof newValue === 'function')
  140. ) {
  141. var then = newValue.then;
  142. if (newValue instanceof Promise$1) {
  143. self._state = 3;
  144. self._value = newValue;
  145. finale(self);
  146. return;
  147. } else if (typeof then === 'function') {
  148. doResolve(bind(then, newValue), self);
  149. return;
  150. }
  151. }
  152. self._state = 1;
  153. self._value = newValue;
  154. finale(self);
  155. } catch (e) {
  156. reject(self, e);
  157. }
  158. }
  159. function reject(self, newValue) {
  160. self._state = 2;
  161. self._value = newValue;
  162. finale(self);
  163. }
  164. function finale(self) {
  165. if (self._state === 2 && self._deferreds.length === 0) {
  166. Promise$1._immediateFn(function() {
  167. if (!self._handled) {
  168. Promise$1._unhandledRejectionFn(self._value);
  169. }
  170. });
  171. }
  172. for (var i = 0, len = self._deferreds.length; i < len; i++) {
  173. handle(self, self._deferreds[i]);
  174. }
  175. self._deferreds = null;
  176. }
  177. /**
  178. * @constructor
  179. */
  180. function Handler(onFulfilled, onRejected, promise) {
  181. this.onFulfilled = typeof onFulfilled === 'function' ? onFulfilled : null;
  182. this.onRejected = typeof onRejected === 'function' ? onRejected : null;
  183. this.promise = promise;
  184. }
  185. /**
  186. * Take a potentially misbehaving resolver function and make sure
  187. * onFulfilled and onRejected are only called once.
  188. *
  189. * Makes no guarantees about asynchrony.
  190. */
  191. function doResolve(fn, self) {
  192. var done = false;
  193. try {
  194. fn(
  195. function(value) {
  196. if (done) { return; }
  197. done = true;
  198. resolve(self, value);
  199. },
  200. function(reason) {
  201. if (done) { return; }
  202. done = true;
  203. reject(self, reason);
  204. }
  205. );
  206. } catch (ex) {
  207. if (done) { return; }
  208. done = true;
  209. reject(self, ex);
  210. }
  211. }
  212. Promise$1.prototype['catch'] = function(onRejected) {
  213. return this.then(null, onRejected);
  214. };
  215. Promise$1.prototype.then = function(onFulfilled, onRejected) {
  216. // @ts-ignore
  217. var prom = new this.constructor(noop);
  218. handle(this, new Handler(onFulfilled, onRejected, prom));
  219. return prom;
  220. };
  221. Promise$1.prototype['finally'] = finallyConstructor;
  222. Promise$1.all = function(arr) {
  223. return new Promise$1(function(resolve, reject) {
  224. if (!isArray(arr)) {
  225. return reject(new TypeError('Promise.all accepts an array'));
  226. }
  227. var args = Array.prototype.slice.call(arr);
  228. if (args.length === 0) { return resolve([]); }
  229. var remaining = args.length;
  230. function res(i, val) {
  231. try {
  232. if (val && (typeof val === 'object' || typeof val === 'function')) {
  233. var then = val.then;
  234. if (typeof then === 'function') {
  235. then.call(
  236. val,
  237. function(val) {
  238. res(i, val);
  239. },
  240. reject
  241. );
  242. return;
  243. }
  244. }
  245. args[i] = val;
  246. if (--remaining === 0) {
  247. resolve(args);
  248. }
  249. } catch (ex) {
  250. reject(ex);
  251. }
  252. }
  253. for (var i = 0; i < args.length; i++) {
  254. res(i, args[i]);
  255. }
  256. });
  257. };
  258. Promise$1.allSettled = allSettled;
  259. Promise$1.resolve = function(value) {
  260. if (value && typeof value === 'object' && value.constructor === Promise$1) {
  261. return value;
  262. }
  263. return new Promise$1(function(resolve) {
  264. resolve(value);
  265. });
  266. };
  267. Promise$1.reject = function(value) {
  268. return new Promise$1(function(resolve, reject) {
  269. reject(value);
  270. });
  271. };
  272. Promise$1.race = function(arr) {
  273. return new Promise$1(function(resolve, reject) {
  274. if (!isArray(arr)) {
  275. return reject(new TypeError('Promise.race accepts an array'));
  276. }
  277. for (var i = 0, len = arr.length; i < len; i++) {
  278. Promise$1.resolve(arr[i]).then(resolve, reject);
  279. }
  280. });
  281. };
  282. // Use polyfill for setImmediate for performance gains
  283. Promise$1._immediateFn =
  284. // @ts-ignore
  285. (typeof setImmediate === 'function' &&
  286. function(fn) {
  287. // @ts-ignore
  288. setImmediate(fn);
  289. }) ||
  290. function(fn) {
  291. setTimeoutFunc(fn, 0);
  292. };
  293. Promise$1._unhandledRejectionFn = function _unhandledRejectionFn(err) {
  294. if (typeof console !== 'undefined' && console) {
  295. console.warn('Possible Unhandled Promise Rejection:', err); // eslint-disable-line no-console
  296. }
  297. };
  298. /*
  299. object-assign
  300. (c) Sindre Sorhus
  301. @license MIT
  302. */
  303. 'use strict';
  304. /* eslint-disable no-unused-vars */
  305. var getOwnPropertySymbols = Object.getOwnPropertySymbols;
  306. var hasOwnProperty = Object.prototype.hasOwnProperty;
  307. var propIsEnumerable = Object.prototype.propertyIsEnumerable;
  308. function toObject(val) {
  309. if (val === null || val === undefined) {
  310. throw new TypeError('Object.assign cannot be called with null or undefined');
  311. }
  312. return Object(val);
  313. }
  314. function shouldUseNative() {
  315. try {
  316. if (!Object.assign) {
  317. return false;
  318. }
  319. // Detect buggy property enumeration order in older V8 versions.
  320. // https://bugs.chromium.org/p/v8/issues/detail?id=4118
  321. var test1 = new String('abc'); // eslint-disable-line no-new-wrappers
  322. test1[5] = 'de';
  323. if (Object.getOwnPropertyNames(test1)[0] === '5') {
  324. return false;
  325. }
  326. // https://bugs.chromium.org/p/v8/issues/detail?id=3056
  327. var test2 = {};
  328. for (var i = 0; i < 10; i++) {
  329. test2['_' + String.fromCharCode(i)] = i;
  330. }
  331. var order2 = Object.getOwnPropertyNames(test2).map(function (n) {
  332. return test2[n];
  333. });
  334. if (order2.join('') !== '0123456789') {
  335. return false;
  336. }
  337. // https://bugs.chromium.org/p/v8/issues/detail?id=3056
  338. var test3 = {};
  339. 'abcdefghijklmnopqrst'.split('').forEach(function (letter) {
  340. test3[letter] = letter;
  341. });
  342. if (Object.keys(Object.assign({}, test3)).join('') !==
  343. 'abcdefghijklmnopqrst') {
  344. return false;
  345. }
  346. return true;
  347. } catch (err) {
  348. // We don't expect any of the above to throw, but better to be safe.
  349. return false;
  350. }
  351. }
  352. var objectAssign = shouldUseNative() ? Object.assign : function (target, source) {
  353. var arguments$1 = arguments;
  354. var from;
  355. var to = toObject(target);
  356. var symbols;
  357. for (var s = 1; s < arguments.length; s++) {
  358. from = Object(arguments$1[s]);
  359. for (var key in from) {
  360. if (hasOwnProperty.call(from, key)) {
  361. to[key] = from[key];
  362. }
  363. }
  364. if (getOwnPropertySymbols) {
  365. symbols = getOwnPropertySymbols(from);
  366. for (var i = 0; i < symbols.length; i++) {
  367. if (propIsEnumerable.call(from, symbols[i])) {
  368. to[symbols[i]] = from[symbols[i]];
  369. }
  370. }
  371. }
  372. }
  373. return to;
  374. };
  375. /*!
  376. * @pixi/polyfill - v6.1.2
  377. * Compiled Thu, 12 Aug 2021 17:11:19 UTC
  378. *
  379. * @pixi/polyfill is licensed under the MIT License.
  380. * http://www.opensource.org/licenses/mit-license
  381. */
  382. // Support for IE 9 - 11 which does not include Promises
  383. if (!self.Promise) {
  384. self.Promise = Promise$1;
  385. }
  386. // References:
  387. if (!Object.assign) {
  388. Object.assign = objectAssign;
  389. }
  390. // References:
  391. // http://paulirish.com/2011/requestanimationframe-for-smart-animating/
  392. // https://gist.github.com/1579671
  393. // http://updates.html5rocks.com/2012/05/requestAnimationFrame-API-now-with-sub-millisecond-precision
  394. // https://gist.github.com/timhall/4078614
  395. // https://github.com/Financial-Times/polyfill-service/tree/master/polyfills/requestAnimationFrame
  396. // Expected to be used with Browserfiy
  397. // Browserify automatically detects the use of `global` and passes the
  398. // correct reference of `global`, `self`, and finally `window`
  399. var ONE_FRAME_TIME = 16;
  400. // Date.now
  401. if (!(Date.now && Date.prototype.getTime)) {
  402. Date.now = function now() {
  403. return new Date().getTime();
  404. };
  405. }
  406. // performance.now
  407. if (!(self.performance && self.performance.now)) {
  408. var startTime_1 = Date.now();
  409. if (!self.performance) {
  410. self.performance = {};
  411. }
  412. self.performance.now = function () { return Date.now() - startTime_1; };
  413. }
  414. // requestAnimationFrame
  415. var lastTime = Date.now();
  416. var vendors = ['ms', 'moz', 'webkit', 'o'];
  417. for (var x = 0; x < vendors.length && !self.requestAnimationFrame; ++x) {
  418. var p = vendors[x];
  419. self.requestAnimationFrame = self[p + "RequestAnimationFrame"];
  420. self.cancelAnimationFrame = self[p + "CancelAnimationFrame"]
  421. || self[p + "CancelRequestAnimationFrame"];
  422. }
  423. if (!self.requestAnimationFrame) {
  424. self.requestAnimationFrame = function (callback) {
  425. if (typeof callback !== 'function') {
  426. throw new TypeError(callback + "is not a function");
  427. }
  428. var currentTime = Date.now();
  429. var delay = ONE_FRAME_TIME + lastTime - currentTime;
  430. if (delay < 0) {
  431. delay = 0;
  432. }
  433. lastTime = currentTime;
  434. return self.setTimeout(function () {
  435. lastTime = Date.now();
  436. callback(performance.now());
  437. }, delay);
  438. };
  439. }
  440. if (!self.cancelAnimationFrame) {
  441. self.cancelAnimationFrame = function (id) { return clearTimeout(id); };
  442. }
  443. // References:
  444. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sign
  445. if (!Math.sign) {
  446. Math.sign = function mathSign(x) {
  447. x = Number(x);
  448. if (x === 0 || isNaN(x)) {
  449. return x;
  450. }
  451. return x > 0 ? 1 : -1;
  452. };
  453. }
  454. // References:
  455. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isInteger
  456. if (!Number.isInteger) {
  457. Number.isInteger = function numberIsInteger(value) {
  458. return typeof value === 'number' && isFinite(value) && Math.floor(value) === value;
  459. };
  460. }
  461. if (!self.ArrayBuffer) {
  462. self.ArrayBuffer = Array;
  463. }
  464. if (!self.Float32Array) {
  465. self.Float32Array = Array;
  466. }
  467. if (!self.Uint32Array) {
  468. self.Uint32Array = Array;
  469. }
  470. if (!self.Uint16Array) {
  471. self.Uint16Array = Array;
  472. }
  473. if (!self.Uint8Array) {
  474. self.Uint8Array = Array;
  475. }
  476. if (!self.Int32Array) {
  477. self.Int32Array = Array;
  478. }
  479. var appleIphone = /iPhone/i;
  480. var appleIpod = /iPod/i;
  481. var appleTablet = /iPad/i;
  482. var appleUniversal = /\biOS-universal(?:.+)Mac\b/i;
  483. var androidPhone = /\bAndroid(?:.+)Mobile\b/i;
  484. var androidTablet = /Android/i;
  485. var amazonPhone = /(?:SD4930UR|\bSilk(?:.+)Mobile\b)/i;
  486. var amazonTablet = /Silk/i;
  487. var windowsPhone = /Windows Phone/i;
  488. var windowsTablet = /\bWindows(?:.+)ARM\b/i;
  489. var otherBlackBerry = /BlackBerry/i;
  490. var otherBlackBerry10 = /BB10/i;
  491. var otherOpera = /Opera Mini/i;
  492. var otherChrome = /\b(CriOS|Chrome)(?:.+)Mobile/i;
  493. var otherFirefox = /Mobile(?:.+)Firefox\b/i;
  494. var isAppleTabletOnIos13 = function (navigator) {
  495. return (typeof navigator !== 'undefined' &&
  496. navigator.platform === 'MacIntel' &&
  497. typeof navigator.maxTouchPoints === 'number' &&
  498. navigator.maxTouchPoints > 1 &&
  499. typeof MSStream === 'undefined');
  500. };
  501. function createMatch(userAgent) {
  502. return function (regex) { return regex.test(userAgent); };
  503. }
  504. function isMobile(param) {
  505. var nav = {
  506. userAgent: '',
  507. platform: '',
  508. maxTouchPoints: 0
  509. };
  510. if (!param && typeof navigator !== 'undefined') {
  511. nav = {
  512. userAgent: navigator.userAgent,
  513. platform: navigator.platform,
  514. maxTouchPoints: navigator.maxTouchPoints || 0
  515. };
  516. }
  517. else if (typeof param === 'string') {
  518. nav.userAgent = param;
  519. }
  520. else if (param && param.userAgent) {
  521. nav = {
  522. userAgent: param.userAgent,
  523. platform: param.platform,
  524. maxTouchPoints: param.maxTouchPoints || 0
  525. };
  526. }
  527. var userAgent = nav.userAgent;
  528. var tmp = userAgent.split('[FBAN');
  529. if (typeof tmp[1] !== 'undefined') {
  530. userAgent = tmp[0];
  531. }
  532. tmp = userAgent.split('Twitter');
  533. if (typeof tmp[1] !== 'undefined') {
  534. userAgent = tmp[0];
  535. }
  536. var match = createMatch(userAgent);
  537. var result = {
  538. apple: {
  539. phone: match(appleIphone) && !match(windowsPhone),
  540. ipod: match(appleIpod),
  541. tablet: !match(appleIphone) &&
  542. (match(appleTablet) || isAppleTabletOnIos13(nav)) &&
  543. !match(windowsPhone),
  544. universal: match(appleUniversal),
  545. device: (match(appleIphone) ||
  546. match(appleIpod) ||
  547. match(appleTablet) ||
  548. match(appleUniversal) ||
  549. isAppleTabletOnIos13(nav)) &&
  550. !match(windowsPhone)
  551. },
  552. amazon: {
  553. phone: match(amazonPhone),
  554. tablet: !match(amazonPhone) && match(amazonTablet),
  555. device: match(amazonPhone) || match(amazonTablet)
  556. },
  557. android: {
  558. phone: (!match(windowsPhone) && match(amazonPhone)) ||
  559. (!match(windowsPhone) && match(androidPhone)),
  560. tablet: !match(windowsPhone) &&
  561. !match(amazonPhone) &&
  562. !match(androidPhone) &&
  563. (match(amazonTablet) || match(androidTablet)),
  564. device: (!match(windowsPhone) &&
  565. (match(amazonPhone) ||
  566. match(amazonTablet) ||
  567. match(androidPhone) ||
  568. match(androidTablet))) ||
  569. match(/\bokhttp\b/i)
  570. },
  571. windows: {
  572. phone: match(windowsPhone),
  573. tablet: match(windowsTablet),
  574. device: match(windowsPhone) || match(windowsTablet)
  575. },
  576. other: {
  577. blackberry: match(otherBlackBerry),
  578. blackberry10: match(otherBlackBerry10),
  579. opera: match(otherOpera),
  580. firefox: match(otherFirefox),
  581. chrome: match(otherChrome),
  582. device: match(otherBlackBerry) ||
  583. match(otherBlackBerry10) ||
  584. match(otherOpera) ||
  585. match(otherFirefox) ||
  586. match(otherChrome)
  587. },
  588. any: false,
  589. phone: false,
  590. tablet: false
  591. };
  592. result.any =
  593. result.apple.device ||
  594. result.android.device ||
  595. result.windows.device ||
  596. result.other.device;
  597. result.phone =
  598. result.apple.phone || result.android.phone || result.windows.phone;
  599. result.tablet =
  600. result.apple.tablet || result.android.tablet || result.windows.tablet;
  601. return result;
  602. }
  603. /*!
  604. * @pixi/settings - v6.1.2
  605. * Compiled Thu, 12 Aug 2021 17:11:19 UTC
  606. *
  607. * @pixi/settings is licensed under the MIT License.
  608. * http://www.opensource.org/licenses/mit-license
  609. */
  610. // The ESM/CJS versions of ismobilejs only
  611. var isMobile$1 = isMobile(self.navigator);
  612. /**
  613. * The maximum recommended texture units to use.
  614. * In theory the bigger the better, and for desktop we'll use as many as we can.
  615. * But some mobile devices slow down if there is to many branches in the shader.
  616. * So in practice there seems to be a sweet spot size that varies depending on the device.
  617. *
  618. * In v4, all mobile devices were limited to 4 texture units because for this.
  619. * In v5, we allow all texture units to be used on modern Apple or Android devices.
  620. *
  621. * @private
  622. * @param {number} max
  623. * @returns {number}
  624. */
  625. function maxRecommendedTextures(max) {
  626. var allowMax = true;
  627. if (isMobile$1.tablet || isMobile$1.phone) {
  628. if (isMobile$1.apple.device) {
  629. var match = (navigator.userAgent).match(/OS (\d+)_(\d+)?/);
  630. if (match) {
  631. var majorVersion = parseInt(match[1], 10);
  632. // Limit texture units on devices below iOS 11, which will be older hardware
  633. if (majorVersion < 11) {
  634. allowMax = false;
  635. }
  636. }
  637. }
  638. if (isMobile$1.android.device) {
  639. var match = (navigator.userAgent).match(/Android\s([0-9.]*)/);
  640. if (match) {
  641. var majorVersion = parseInt(match[1], 10);
  642. // Limit texture units on devices below Android 7 (Nougat), which will be older hardware
  643. if (majorVersion < 7) {
  644. allowMax = false;
  645. }
  646. }
  647. }
  648. }
  649. return allowMax ? max : 4;
  650. }
  651. /**
  652. * Uploading the same buffer multiple times in a single frame can cause performance issues.
  653. * Apparent on iOS so only check for that at the moment
  654. * This check may become more complex if this issue pops up elsewhere.
  655. *
  656. * @private
  657. * @returns {boolean}
  658. */
  659. function canUploadSameBuffer() {
  660. return !isMobile$1.apple.device;
  661. }
  662. /*!
  663. * @pixi/constants - v6.1.2
  664. * Compiled Thu, 12 Aug 2021 17:11:19 UTC
  665. *
  666. * @pixi/constants is licensed under the MIT License.
  667. * http://www.opensource.org/licenses/mit-license
  668. */
  669. /**
  670. * Different types of environments for WebGL.
  671. *
  672. * @static
  673. * @memberof PIXI
  674. * @name ENV
  675. * @enum {number}
  676. * @property {number} WEBGL_LEGACY - Used for older v1 WebGL devices. PixiJS will aim to ensure compatibility
  677. * with older / less advanced devices. If you experience unexplained flickering prefer this environment.
  678. * @property {number} WEBGL - Version 1 of WebGL
  679. * @property {number} WEBGL2 - Version 2 of WebGL
  680. */
  681. var ENV;
  682. (function (ENV) {
  683. ENV[ENV["WEBGL_LEGACY"] = 0] = "WEBGL_LEGACY";
  684. ENV[ENV["WEBGL"] = 1] = "WEBGL";
  685. ENV[ENV["WEBGL2"] = 2] = "WEBGL2";
  686. })(ENV || (ENV = {}));
  687. /**
  688. * Constant to identify the Renderer Type.
  689. *
  690. * @static
  691. * @memberof PIXI
  692. * @name RENDERER_TYPE
  693. * @enum {number}
  694. * @property {number} UNKNOWN - Unknown render type.
  695. * @property {number} WEBGL - WebGL render type.
  696. * @property {number} CANVAS - Canvas render type.
  697. */
  698. var RENDERER_TYPE;
  699. (function (RENDERER_TYPE) {
  700. RENDERER_TYPE[RENDERER_TYPE["UNKNOWN"] = 0] = "UNKNOWN";
  701. RENDERER_TYPE[RENDERER_TYPE["WEBGL"] = 1] = "WEBGL";
  702. RENDERER_TYPE[RENDERER_TYPE["CANVAS"] = 2] = "CANVAS";
  703. })(RENDERER_TYPE || (RENDERER_TYPE = {}));
  704. /**
  705. * Bitwise OR of masks that indicate the buffers to be cleared.
  706. *
  707. * @static
  708. * @memberof PIXI
  709. * @name BUFFER_BITS
  710. * @enum {number}
  711. * @property {number} COLOR - Indicates the buffers currently enabled for color writing.
  712. * @property {number} DEPTH - Indicates the depth buffer.
  713. * @property {number} STENCIL - Indicates the stencil buffer.
  714. */
  715. var BUFFER_BITS;
  716. (function (BUFFER_BITS) {
  717. BUFFER_BITS[BUFFER_BITS["COLOR"] = 16384] = "COLOR";
  718. BUFFER_BITS[BUFFER_BITS["DEPTH"] = 256] = "DEPTH";
  719. BUFFER_BITS[BUFFER_BITS["STENCIL"] = 1024] = "STENCIL";
  720. })(BUFFER_BITS || (BUFFER_BITS = {}));
  721. /**
  722. * Various blend modes supported by PIXI.
  723. *
  724. * IMPORTANT - The WebGL renderer only supports the NORMAL, ADD, MULTIPLY and SCREEN blend modes.
  725. * Anything else will silently act like NORMAL.
  726. *
  727. * @memberof PIXI
  728. * @name BLEND_MODES
  729. * @enum {number}
  730. * @property {number} NORMAL
  731. * @property {number} ADD
  732. * @property {number} MULTIPLY
  733. * @property {number} SCREEN
  734. * @property {number} OVERLAY
  735. * @property {number} DARKEN
  736. * @property {number} LIGHTEN
  737. * @property {number} COLOR_DODGE
  738. * @property {number} COLOR_BURN
  739. * @property {number} HARD_LIGHT
  740. * @property {number} SOFT_LIGHT
  741. * @property {number} DIFFERENCE
  742. * @property {number} EXCLUSION
  743. * @property {number} HUE
  744. * @property {number} SATURATION
  745. * @property {number} COLOR
  746. * @property {number} LUMINOSITY
  747. * @property {number} NORMAL_NPM
  748. * @property {number} ADD_NPM
  749. * @property {number} SCREEN_NPM
  750. * @property {number} NONE
  751. * @property {number} SRC_IN
  752. * @property {number} SRC_OUT
  753. * @property {number} SRC_ATOP
  754. * @property {number} DST_OVER
  755. * @property {number} DST_IN
  756. * @property {number} DST_OUT
  757. * @property {number} DST_ATOP
  758. * @property {number} SUBTRACT
  759. * @property {number} SRC_OVER
  760. * @property {number} ERASE
  761. * @property {number} XOR
  762. */
  763. var BLEND_MODES;
  764. (function (BLEND_MODES) {
  765. BLEND_MODES[BLEND_MODES["NORMAL"] = 0] = "NORMAL";
  766. BLEND_MODES[BLEND_MODES["ADD"] = 1] = "ADD";
  767. BLEND_MODES[BLEND_MODES["MULTIPLY"] = 2] = "MULTIPLY";
  768. BLEND_MODES[BLEND_MODES["SCREEN"] = 3] = "SCREEN";
  769. BLEND_MODES[BLEND_MODES["OVERLAY"] = 4] = "OVERLAY";
  770. BLEND_MODES[BLEND_MODES["DARKEN"] = 5] = "DARKEN";
  771. BLEND_MODES[BLEND_MODES["LIGHTEN"] = 6] = "LIGHTEN";
  772. BLEND_MODES[BLEND_MODES["COLOR_DODGE"] = 7] = "COLOR_DODGE";
  773. BLEND_MODES[BLEND_MODES["COLOR_BURN"] = 8] = "COLOR_BURN";
  774. BLEND_MODES[BLEND_MODES["HARD_LIGHT"] = 9] = "HARD_LIGHT";
  775. BLEND_MODES[BLEND_MODES["SOFT_LIGHT"] = 10] = "SOFT_LIGHT";
  776. BLEND_MODES[BLEND_MODES["DIFFERENCE"] = 11] = "DIFFERENCE";
  777. BLEND_MODES[BLEND_MODES["EXCLUSION"] = 12] = "EXCLUSION";
  778. BLEND_MODES[BLEND_MODES["HUE"] = 13] = "HUE";
  779. BLEND_MODES[BLEND_MODES["SATURATION"] = 14] = "SATURATION";
  780. BLEND_MODES[BLEND_MODES["COLOR"] = 15] = "COLOR";
  781. BLEND_MODES[BLEND_MODES["LUMINOSITY"] = 16] = "LUMINOSITY";
  782. BLEND_MODES[BLEND_MODES["NORMAL_NPM"] = 17] = "NORMAL_NPM";
  783. BLEND_MODES[BLEND_MODES["ADD_NPM"] = 18] = "ADD_NPM";
  784. BLEND_MODES[BLEND_MODES["SCREEN_NPM"] = 19] = "SCREEN_NPM";
  785. BLEND_MODES[BLEND_MODES["NONE"] = 20] = "NONE";
  786. BLEND_MODES[BLEND_MODES["SRC_OVER"] = 0] = "SRC_OVER";
  787. BLEND_MODES[BLEND_MODES["SRC_IN"] = 21] = "SRC_IN";
  788. BLEND_MODES[BLEND_MODES["SRC_OUT"] = 22] = "SRC_OUT";
  789. BLEND_MODES[BLEND_MODES["SRC_ATOP"] = 23] = "SRC_ATOP";
  790. BLEND_MODES[BLEND_MODES["DST_OVER"] = 24] = "DST_OVER";
  791. BLEND_MODES[BLEND_MODES["DST_IN"] = 25] = "DST_IN";
  792. BLEND_MODES[BLEND_MODES["DST_OUT"] = 26] = "DST_OUT";
  793. BLEND_MODES[BLEND_MODES["DST_ATOP"] = 27] = "DST_ATOP";
  794. BLEND_MODES[BLEND_MODES["ERASE"] = 26] = "ERASE";
  795. BLEND_MODES[BLEND_MODES["SUBTRACT"] = 28] = "SUBTRACT";
  796. BLEND_MODES[BLEND_MODES["XOR"] = 29] = "XOR";
  797. })(BLEND_MODES || (BLEND_MODES = {}));
  798. /**
  799. * Various webgl draw modes. These can be used to specify which GL drawMode to use
  800. * under certain situations and renderers.
  801. *
  802. * @memberof PIXI
  803. * @static
  804. * @name DRAW_MODES
  805. * @enum {number}
  806. * @property {number} POINTS
  807. * @property {number} LINES
  808. * @property {number} LINE_LOOP
  809. * @property {number} LINE_STRIP
  810. * @property {number} TRIANGLES
  811. * @property {number} TRIANGLE_STRIP
  812. * @property {number} TRIANGLE_FAN
  813. */
  814. var DRAW_MODES;
  815. (function (DRAW_MODES) {
  816. DRAW_MODES[DRAW_MODES["POINTS"] = 0] = "POINTS";
  817. DRAW_MODES[DRAW_MODES["LINES"] = 1] = "LINES";
  818. DRAW_MODES[DRAW_MODES["LINE_LOOP"] = 2] = "LINE_LOOP";
  819. DRAW_MODES[DRAW_MODES["LINE_STRIP"] = 3] = "LINE_STRIP";
  820. DRAW_MODES[DRAW_MODES["TRIANGLES"] = 4] = "TRIANGLES";
  821. DRAW_MODES[DRAW_MODES["TRIANGLE_STRIP"] = 5] = "TRIANGLE_STRIP";
  822. DRAW_MODES[DRAW_MODES["TRIANGLE_FAN"] = 6] = "TRIANGLE_FAN";
  823. })(DRAW_MODES || (DRAW_MODES = {}));
  824. /**
  825. * Various GL texture/resources formats.
  826. *
  827. * @memberof PIXI
  828. * @static
  829. * @name FORMATS
  830. * @enum {number}
  831. * @property {number} RGBA=6408
  832. * @property {number} RGB=6407
  833. * @property {number} RG=33319
  834. * @property {number} RED=6403
  835. * @property {number} RGBA_INTEGER=36249
  836. * @property {number} RGB_INTEGER=36248
  837. * @property {number} RG_INTEGER=33320
  838. * @property {number} RED_INTEGER=36244
  839. * @property {number} ALPHA=6406
  840. * @property {number} LUMINANCE=6409
  841. * @property {number} LUMINANCE_ALPHA=6410
  842. * @property {number} DEPTH_COMPONENT=6402
  843. * @property {number} DEPTH_STENCIL=34041
  844. */
  845. var FORMATS;
  846. (function (FORMATS) {
  847. FORMATS[FORMATS["RGBA"] = 6408] = "RGBA";
  848. FORMATS[FORMATS["RGB"] = 6407] = "RGB";
  849. FORMATS[FORMATS["RG"] = 33319] = "RG";
  850. FORMATS[FORMATS["RED"] = 6403] = "RED";
  851. FORMATS[FORMATS["RGBA_INTEGER"] = 36249] = "RGBA_INTEGER";
  852. FORMATS[FORMATS["RGB_INTEGER"] = 36248] = "RGB_INTEGER";
  853. FORMATS[FORMATS["RG_INTEGER"] = 33320] = "RG_INTEGER";
  854. FORMATS[FORMATS["RED_INTEGER"] = 36244] = "RED_INTEGER";
  855. FORMATS[FORMATS["ALPHA"] = 6406] = "ALPHA";
  856. FORMATS[FORMATS["LUMINANCE"] = 6409] = "LUMINANCE";
  857. FORMATS[FORMATS["LUMINANCE_ALPHA"] = 6410] = "LUMINANCE_ALPHA";
  858. FORMATS[FORMATS["DEPTH_COMPONENT"] = 6402] = "DEPTH_COMPONENT";
  859. FORMATS[FORMATS["DEPTH_STENCIL"] = 34041] = "DEPTH_STENCIL";
  860. })(FORMATS || (FORMATS = {}));
  861. /**
  862. * Various GL target types.
  863. *
  864. * @memberof PIXI
  865. * @static
  866. * @name TARGETS
  867. * @enum {number}
  868. * @property {number} TEXTURE_2D=3553
  869. * @property {number} TEXTURE_CUBE_MAP=34067
  870. * @property {number} TEXTURE_2D_ARRAY=35866
  871. * @property {number} TEXTURE_CUBE_MAP_POSITIVE_X=34069
  872. * @property {number} TEXTURE_CUBE_MAP_NEGATIVE_X=34070
  873. * @property {number} TEXTURE_CUBE_MAP_POSITIVE_Y=34071
  874. * @property {number} TEXTURE_CUBE_MAP_NEGATIVE_Y=34072
  875. * @property {number} TEXTURE_CUBE_MAP_POSITIVE_Z=34073
  876. * @property {number} TEXTURE_CUBE_MAP_NEGATIVE_Z=34074
  877. */
  878. var TARGETS;
  879. (function (TARGETS) {
  880. TARGETS[TARGETS["TEXTURE_2D"] = 3553] = "TEXTURE_2D";
  881. TARGETS[TARGETS["TEXTURE_CUBE_MAP"] = 34067] = "TEXTURE_CUBE_MAP";
  882. TARGETS[TARGETS["TEXTURE_2D_ARRAY"] = 35866] = "TEXTURE_2D_ARRAY";
  883. TARGETS[TARGETS["TEXTURE_CUBE_MAP_POSITIVE_X"] = 34069] = "TEXTURE_CUBE_MAP_POSITIVE_X";
  884. TARGETS[TARGETS["TEXTURE_CUBE_MAP_NEGATIVE_X"] = 34070] = "TEXTURE_CUBE_MAP_NEGATIVE_X";
  885. TARGETS[TARGETS["TEXTURE_CUBE_MAP_POSITIVE_Y"] = 34071] = "TEXTURE_CUBE_MAP_POSITIVE_Y";
  886. TARGETS[TARGETS["TEXTURE_CUBE_MAP_NEGATIVE_Y"] = 34072] = "TEXTURE_CUBE_MAP_NEGATIVE_Y";
  887. TARGETS[TARGETS["TEXTURE_CUBE_MAP_POSITIVE_Z"] = 34073] = "TEXTURE_CUBE_MAP_POSITIVE_Z";
  888. TARGETS[TARGETS["TEXTURE_CUBE_MAP_NEGATIVE_Z"] = 34074] = "TEXTURE_CUBE_MAP_NEGATIVE_Z";
  889. })(TARGETS || (TARGETS = {}));
  890. /**
  891. * Various GL data format types.
  892. *
  893. * @memberof PIXI
  894. * @static
  895. * @name TYPES
  896. * @enum {number}
  897. * @property {number} UNSIGNED_BYTE=5121
  898. * @property {number} UNSIGNED_SHORT=5123
  899. * @property {number} UNSIGNED_SHORT_5_6_5=33635
  900. * @property {number} UNSIGNED_SHORT_4_4_4_4=32819
  901. * @property {number} UNSIGNED_SHORT_5_5_5_1=32820
  902. * @property {number} UNSIGNED_INT=5125
  903. * @property {number} UNSIGNED_INT_10F_11F_11F_REV=35899
  904. * @property {number} UNSIGNED_INT_2_10_10_10_REV=33640
  905. * @property {number} UNSIGNED_INT_24_8=34042
  906. * @property {number} UNSIGNED_INT_5_9_9_9_REV=35902
  907. * @property {number} BYTE=5120
  908. * @property {number} SHORT=5122
  909. * @property {number} INT=5124
  910. * @property {number} FLOAT=5126
  911. * @property {number} FLOAT_32_UNSIGNED_INT_24_8_REV=36269
  912. * @property {number} HALF_FLOAT=36193
  913. */
  914. var TYPES;
  915. (function (TYPES) {
  916. TYPES[TYPES["UNSIGNED_BYTE"] = 5121] = "UNSIGNED_BYTE";
  917. TYPES[TYPES["UNSIGNED_SHORT"] = 5123] = "UNSIGNED_SHORT";
  918. TYPES[TYPES["UNSIGNED_SHORT_5_6_5"] = 33635] = "UNSIGNED_SHORT_5_6_5";
  919. TYPES[TYPES["UNSIGNED_SHORT_4_4_4_4"] = 32819] = "UNSIGNED_SHORT_4_4_4_4";
  920. TYPES[TYPES["UNSIGNED_SHORT_5_5_5_1"] = 32820] = "UNSIGNED_SHORT_5_5_5_1";
  921. TYPES[TYPES["UNSIGNED_INT"] = 5125] = "UNSIGNED_INT";
  922. TYPES[TYPES["UNSIGNED_INT_10F_11F_11F_REV"] = 35899] = "UNSIGNED_INT_10F_11F_11F_REV";
  923. TYPES[TYPES["UNSIGNED_INT_2_10_10_10_REV"] = 33640] = "UNSIGNED_INT_2_10_10_10_REV";
  924. TYPES[TYPES["UNSIGNED_INT_24_8"] = 34042] = "UNSIGNED_INT_24_8";
  925. TYPES[TYPES["UNSIGNED_INT_5_9_9_9_REV"] = 35902] = "UNSIGNED_INT_5_9_9_9_REV";
  926. TYPES[TYPES["BYTE"] = 5120] = "BYTE";
  927. TYPES[TYPES["SHORT"] = 5122] = "SHORT";
  928. TYPES[TYPES["INT"] = 5124] = "INT";
  929. TYPES[TYPES["FLOAT"] = 5126] = "FLOAT";
  930. TYPES[TYPES["FLOAT_32_UNSIGNED_INT_24_8_REV"] = 36269] = "FLOAT_32_UNSIGNED_INT_24_8_REV";
  931. TYPES[TYPES["HALF_FLOAT"] = 36193] = "HALF_FLOAT";
  932. })(TYPES || (TYPES = {}));
  933. /**
  934. * Various sampler types. Correspond to `sampler`, `isampler`, `usampler` GLSL types respectively.
  935. * WebGL1 works only with FLOAT.
  936. *
  937. * @memberof PIXI
  938. * @static
  939. * @name SAMPLER_TYPES
  940. * @enum {number}
  941. * @property {number} FLOAT=0
  942. * @property {number} INT=1
  943. * @property {number} UINT=2
  944. */
  945. var SAMPLER_TYPES;
  946. (function (SAMPLER_TYPES) {
  947. SAMPLER_TYPES[SAMPLER_TYPES["FLOAT"] = 0] = "FLOAT";
  948. SAMPLER_TYPES[SAMPLER_TYPES["INT"] = 1] = "INT";
  949. SAMPLER_TYPES[SAMPLER_TYPES["UINT"] = 2] = "UINT";
  950. })(SAMPLER_TYPES || (SAMPLER_TYPES = {}));
  951. /**
  952. * The scale modes that are supported by pixi.
  953. *
  954. * The {@link PIXI.settings.SCALE_MODE} scale mode affects the default scaling mode of future operations.
  955. * It can be re-assigned to either LINEAR or NEAREST, depending upon suitability.
  956. *
  957. * @memberof PIXI
  958. * @static
  959. * @name SCALE_MODES
  960. * @enum {number}
  961. * @property {number} LINEAR Smooth scaling
  962. * @property {number} NEAREST Pixelating scaling
  963. */
  964. var SCALE_MODES;
  965. (function (SCALE_MODES) {
  966. SCALE_MODES[SCALE_MODES["NEAREST"] = 0] = "NEAREST";
  967. SCALE_MODES[SCALE_MODES["LINEAR"] = 1] = "LINEAR";
  968. })(SCALE_MODES || (SCALE_MODES = {}));
  969. /**
  970. * The wrap modes that are supported by pixi.
  971. *
  972. * The {@link PIXI.settings.WRAP_MODE} wrap mode affects the default wrapping mode of future operations.
  973. * It can be re-assigned to either CLAMP or REPEAT, depending upon suitability.
  974. * If the texture is non power of two then clamp will be used regardless as WebGL can
  975. * only use REPEAT if the texture is po2.
  976. *
  977. * This property only affects WebGL.
  978. *
  979. * @name WRAP_MODES
  980. * @memberof PIXI
  981. * @static
  982. * @enum {number}
  983. * @property {number} CLAMP - The textures uvs are clamped
  984. * @property {number} REPEAT - The texture uvs tile and repeat
  985. * @property {number} MIRRORED_REPEAT - The texture uvs tile and repeat with mirroring
  986. */
  987. var WRAP_MODES;
  988. (function (WRAP_MODES) {
  989. WRAP_MODES[WRAP_MODES["CLAMP"] = 33071] = "CLAMP";
  990. WRAP_MODES[WRAP_MODES["REPEAT"] = 10497] = "REPEAT";
  991. WRAP_MODES[WRAP_MODES["MIRRORED_REPEAT"] = 33648] = "MIRRORED_REPEAT";
  992. })(WRAP_MODES || (WRAP_MODES = {}));
  993. /**
  994. * Mipmap filtering modes that are supported by pixi.
  995. *
  996. * The {@link PIXI.settings.MIPMAP_TEXTURES} affects default texture filtering.
  997. * Mipmaps are generated for a baseTexture if its `mipmap` field is `ON`,
  998. * or its `POW2` and texture dimensions are powers of 2.
  999. * Due to platform restriction, `ON` option will work like `POW2` for webgl-1.
  1000. *
  1001. * This property only affects WebGL.
  1002. *
  1003. * @name MIPMAP_MODES
  1004. * @memberof PIXI
  1005. * @static
  1006. * @enum {number}
  1007. * @property {number} OFF - No mipmaps
  1008. * @property {number} POW2 - Generate mipmaps if texture dimensions are pow2
  1009. * @property {number} ON - Always generate mipmaps
  1010. * @property {number} ON_MANUAL - Use mipmaps, but do not auto-generate them; this is used with a resource
  1011. * that supports buffering each level-of-detail.
  1012. */
  1013. var MIPMAP_MODES;
  1014. (function (MIPMAP_MODES) {
  1015. MIPMAP_MODES[MIPMAP_MODES["OFF"] = 0] = "OFF";
  1016. MIPMAP_MODES[MIPMAP_MODES["POW2"] = 1] = "POW2";
  1017. MIPMAP_MODES[MIPMAP_MODES["ON"] = 2] = "ON";
  1018. MIPMAP_MODES[MIPMAP_MODES["ON_MANUAL"] = 3] = "ON_MANUAL";
  1019. })(MIPMAP_MODES || (MIPMAP_MODES = {}));
  1020. /**
  1021. * How to treat textures with premultiplied alpha
  1022. *
  1023. * @name ALPHA_MODES
  1024. * @memberof PIXI
  1025. * @static
  1026. * @enum {number}
  1027. * @property {number} NO_PREMULTIPLIED_ALPHA - Source is not premultiplied, leave it like that.
  1028. * Option for compressed and data textures that are created from typed arrays.
  1029. * @property {number} PREMULTIPLY_ON_UPLOAD - Source is not premultiplied, premultiply on upload.
  1030. * Default option, used for all loaded images.
  1031. * @property {number} PREMULTIPLIED_ALPHA - Source is already premultiplied
  1032. * Example: spine atlases with `_pma` suffix.
  1033. * @property {number} NPM - Alias for NO_PREMULTIPLIED_ALPHA.
  1034. * @property {number} UNPACK - Default option, alias for PREMULTIPLY_ON_UPLOAD.
  1035. * @property {number} PMA - Alias for PREMULTIPLIED_ALPHA.
  1036. */
  1037. var ALPHA_MODES;
  1038. (function (ALPHA_MODES) {
  1039. ALPHA_MODES[ALPHA_MODES["NPM"] = 0] = "NPM";
  1040. ALPHA_MODES[ALPHA_MODES["UNPACK"] = 1] = "UNPACK";
  1041. ALPHA_MODES[ALPHA_MODES["PMA"] = 2] = "PMA";
  1042. ALPHA_MODES[ALPHA_MODES["NO_PREMULTIPLIED_ALPHA"] = 0] = "NO_PREMULTIPLIED_ALPHA";
  1043. ALPHA_MODES[ALPHA_MODES["PREMULTIPLY_ON_UPLOAD"] = 1] = "PREMULTIPLY_ON_UPLOAD";
  1044. ALPHA_MODES[ALPHA_MODES["PREMULTIPLY_ALPHA"] = 2] = "PREMULTIPLY_ALPHA";
  1045. })(ALPHA_MODES || (ALPHA_MODES = {}));
  1046. /**
  1047. * Configure whether filter textures are cleared after binding.
  1048. *
  1049. * Filter textures need not be cleared if the filter does not use pixel blending. {@link CLEAR_MODES.BLIT} will detect
  1050. * this and skip clearing as an optimization.
  1051. *
  1052. * @name CLEAR_MODES
  1053. * @memberof PIXI
  1054. * @static
  1055. * @enum {number}
  1056. * @property {number} BLEND - Do not clear the filter texture. The filter's output will blend on top of the output texture.
  1057. * @property {number} CLEAR - Always clear the filter texture.
  1058. * @property {number} BLIT - Clear only if {@link FilterSystem.forceClear} is set or if the filter uses pixel blending.
  1059. * @property {number} NO - Alias for BLEND, same as `false` in earlier versions
  1060. * @property {number} YES - Alias for CLEAR, same as `true` in earlier versions
  1061. * @property {number} AUTO - Alias for BLIT
  1062. */
  1063. var CLEAR_MODES;
  1064. (function (CLEAR_MODES) {
  1065. CLEAR_MODES[CLEAR_MODES["NO"] = 0] = "NO";
  1066. CLEAR_MODES[CLEAR_MODES["YES"] = 1] = "YES";
  1067. CLEAR_MODES[CLEAR_MODES["AUTO"] = 2] = "AUTO";
  1068. CLEAR_MODES[CLEAR_MODES["BLEND"] = 0] = "BLEND";
  1069. CLEAR_MODES[CLEAR_MODES["CLEAR"] = 1] = "CLEAR";
  1070. CLEAR_MODES[CLEAR_MODES["BLIT"] = 2] = "BLIT";
  1071. })(CLEAR_MODES || (CLEAR_MODES = {}));
  1072. /**
  1073. * The gc modes that are supported by pixi.
  1074. *
  1075. * The {@link PIXI.settings.GC_MODE} Garbage Collection mode for PixiJS textures is AUTO
  1076. * If set to GC_MODE, the renderer will occasionally check textures usage. If they are not
  1077. * used for a specified period of time they will be removed from the GPU. They will of course
  1078. * be uploaded again when they are required. This is a silent behind the scenes process that
  1079. * should ensure that the GPU does not get filled up.
  1080. *
  1081. * Handy for mobile devices!
  1082. * This property only affects WebGL.
  1083. *
  1084. * @name GC_MODES
  1085. * @enum {number}
  1086. * @static
  1087. * @memberof PIXI
  1088. * @property {number} AUTO - Garbage collection will happen periodically automatically
  1089. * @property {number} MANUAL - Garbage collection will need to be called manually
  1090. */
  1091. var GC_MODES;
  1092. (function (GC_MODES) {
  1093. GC_MODES[GC_MODES["AUTO"] = 0] = "AUTO";
  1094. GC_MODES[GC_MODES["MANUAL"] = 1] = "MANUAL";
  1095. })(GC_MODES || (GC_MODES = {}));
  1096. /**
  1097. * Constants that specify float precision in shaders.
  1098. *
  1099. * @name PRECISION
  1100. * @memberof PIXI
  1101. * @constant
  1102. * @static
  1103. * @enum {string}
  1104. * @property {string} LOW='lowp'
  1105. * @property {string} MEDIUM='mediump'
  1106. * @property {string} HIGH='highp'
  1107. */
  1108. var PRECISION;
  1109. (function (PRECISION) {
  1110. PRECISION["LOW"] = "lowp";
  1111. PRECISION["MEDIUM"] = "mediump";
  1112. PRECISION["HIGH"] = "highp";
  1113. })(PRECISION || (PRECISION = {}));
  1114. /**
  1115. * Constants for mask implementations.
  1116. * We use `type` suffix because it leads to very different behaviours
  1117. *
  1118. * @name MASK_TYPES
  1119. * @memberof PIXI
  1120. * @static
  1121. * @enum {number}
  1122. * @property {number} NONE - Mask is ignored
  1123. * @property {number} SCISSOR - Scissor mask, rectangle on screen, cheap
  1124. * @property {number} STENCIL - Stencil mask, 1-bit, medium, works only if renderer supports stencil
  1125. * @property {number} SPRITE - Mask that uses SpriteMaskFilter, uses temporary RenderTexture
  1126. */
  1127. var MASK_TYPES;
  1128. (function (MASK_TYPES) {
  1129. MASK_TYPES[MASK_TYPES["NONE"] = 0] = "NONE";
  1130. MASK_TYPES[MASK_TYPES["SCISSOR"] = 1] = "SCISSOR";
  1131. MASK_TYPES[MASK_TYPES["STENCIL"] = 2] = "STENCIL";
  1132. MASK_TYPES[MASK_TYPES["SPRITE"] = 3] = "SPRITE";
  1133. })(MASK_TYPES || (MASK_TYPES = {}));
  1134. /**
  1135. * Constants for multi-sampling antialiasing.
  1136. *
  1137. * @see PIXI.Framebuffer#multisample
  1138. *
  1139. * @name MSAA_QUALITY
  1140. * @memberof PIXI
  1141. * @static
  1142. * @enum {number}
  1143. * @property {number} NONE - No multisampling for this renderTexture
  1144. * @property {number} LOW - Try 2 samples
  1145. * @property {number} MEDIUM - Try 4 samples
  1146. * @property {number} HIGH - Try 8 samples
  1147. */
  1148. var MSAA_QUALITY;
  1149. (function (MSAA_QUALITY) {
  1150. MSAA_QUALITY[MSAA_QUALITY["NONE"] = 0] = "NONE";
  1151. MSAA_QUALITY[MSAA_QUALITY["LOW"] = 2] = "LOW";
  1152. MSAA_QUALITY[MSAA_QUALITY["MEDIUM"] = 4] = "MEDIUM";
  1153. MSAA_QUALITY[MSAA_QUALITY["HIGH"] = 8] = "HIGH";
  1154. })(MSAA_QUALITY || (MSAA_QUALITY = {}));
  1155. /**
  1156. * Constants for various buffer types in Pixi
  1157. *
  1158. * @see PIXI.BUFFER_TYPE
  1159. *
  1160. * @name BUFFER_TYPE
  1161. * @memberof PIXI
  1162. * @static
  1163. * @enum {number}
  1164. * @property {number} ELEMENT_ARRAY_BUFFER - buffer type for using as an index buffer
  1165. * @property {number} ARRAY_BUFFER - buffer type for using attribute data
  1166. * @property {number} UNIFORM_BUFFER - the buffer type is for uniform buffer objects
  1167. */
  1168. var BUFFER_TYPE;
  1169. (function (BUFFER_TYPE) {
  1170. BUFFER_TYPE[BUFFER_TYPE["ELEMENT_ARRAY_BUFFER"] = 34963] = "ELEMENT_ARRAY_BUFFER";
  1171. BUFFER_TYPE[BUFFER_TYPE["ARRAY_BUFFER"] = 34962] = "ARRAY_BUFFER";
  1172. // NOT YET SUPPORTED
  1173. BUFFER_TYPE[BUFFER_TYPE["UNIFORM_BUFFER"] = 35345] = "UNIFORM_BUFFER";
  1174. })(BUFFER_TYPE || (BUFFER_TYPE = {}));
  1175. /**
  1176. * User's customizable globals for overriding the default PIXI settings, such
  1177. * as a renderer's default resolution, framerate, float precision, etc.
  1178. * @example
  1179. * // Use the native window resolution as the default resolution
  1180. * // will support high-density displays when rendering
  1181. * PIXI.settings.RESOLUTION = window.devicePixelRatio;
  1182. *
  1183. * // Disable interpolation when scaling, will make texture be pixelated
  1184. * PIXI.settings.SCALE_MODE = PIXI.SCALE_MODES.NEAREST;
  1185. * @namespace PIXI.settings
  1186. */
  1187. var settings = {
  1188. /**
  1189. * If set to true WebGL will attempt make textures mimpaped by default.
  1190. * Mipmapping will only succeed if the base texture uploaded has power of two dimensions.
  1191. *
  1192. * @static
  1193. * @name MIPMAP_TEXTURES
  1194. * @memberof PIXI.settings
  1195. * @type {PIXI.MIPMAP_MODES}
  1196. * @default PIXI.MIPMAP_MODES.POW2
  1197. */
  1198. MIPMAP_TEXTURES: MIPMAP_MODES.POW2,
  1199. /**
  1200. * Default anisotropic filtering level of textures.
  1201. * Usually from 0 to 16
  1202. *
  1203. * @static
  1204. * @name ANISOTROPIC_LEVEL
  1205. * @memberof PIXI.settings
  1206. * @type {number}
  1207. * @default 0
  1208. */
  1209. ANISOTROPIC_LEVEL: 0,
  1210. /**
  1211. * Default resolution / device pixel ratio of the renderer.
  1212. *
  1213. * @static
  1214. * @name RESOLUTION
  1215. * @memberof PIXI.settings
  1216. * @type {number}
  1217. * @default 1
  1218. */
  1219. RESOLUTION: 1,
  1220. /**
  1221. * Default filter resolution.
  1222. *
  1223. * @static
  1224. * @name FILTER_RESOLUTION
  1225. * @memberof PIXI.settings
  1226. * @type {number}
  1227. * @default 1
  1228. */
  1229. FILTER_RESOLUTION: 1,
  1230. /**
  1231. * Default filter samples.
  1232. *
  1233. * @static
  1234. * @name FILTER_MULTISAMPLE
  1235. * @memberof PIXI.settings
  1236. * @type {PIXI.MSAA_QUALITY}
  1237. * @default PIXI.MSAA_QUALITY.NONE
  1238. */
  1239. FILTER_MULTISAMPLE: MSAA_QUALITY.NONE,
  1240. /**
  1241. * The maximum textures that this device supports.
  1242. *
  1243. * @static
  1244. * @name SPRITE_MAX_TEXTURES
  1245. * @memberof PIXI.settings
  1246. * @type {number}
  1247. * @default 32
  1248. */
  1249. SPRITE_MAX_TEXTURES: maxRecommendedTextures(32),
  1250. // TODO: maybe change to SPRITE.BATCH_SIZE: 2000
  1251. // TODO: maybe add PARTICLE.BATCH_SIZE: 15000
  1252. /**
  1253. * The default sprite batch size.
  1254. *
  1255. * The default aims to balance desktop and mobile devices.
  1256. *
  1257. * @static
  1258. * @name SPRITE_BATCH_SIZE
  1259. * @memberof PIXI.settings
  1260. * @type {number}
  1261. * @default 4096
  1262. */
  1263. SPRITE_BATCH_SIZE: 4096,
  1264. /**
  1265. * The default render options if none are supplied to {@link PIXI.Renderer}
  1266. * or {@link PIXI.CanvasRenderer}.
  1267. *
  1268. * @static
  1269. * @name RENDER_OPTIONS
  1270. * @memberof PIXI.settings
  1271. * @type {object}
  1272. * @property {HTMLCanvasElement} view=null
  1273. * @property {boolean} antialias=false
  1274. * @property {boolean} autoDensity=false
  1275. * @property {boolean} useContextAlpha=true
  1276. * @property {number} backgroundColor=0x000000
  1277. * @property {number} backgroundAlpha=1
  1278. * @property {boolean} clearBeforeRender=true
  1279. * @property {boolean} preserveDrawingBuffer=false
  1280. * @property {number} width=800
  1281. * @property {number} height=600
  1282. * @property {boolean} legacy=false
  1283. */
  1284. RENDER_OPTIONS: {
  1285. view: null,
  1286. antialias: false,
  1287. autoDensity: false,
  1288. backgroundColor: 0x000000,
  1289. backgroundAlpha: 1,
  1290. useContextAlpha: true,
  1291. clearBeforeRender: true,
  1292. preserveDrawingBuffer: false,
  1293. width: 800,
  1294. height: 600,
  1295. legacy: false,
  1296. },
  1297. /**
  1298. * Default Garbage Collection mode.
  1299. *
  1300. * @static
  1301. * @name GC_MODE
  1302. * @memberof PIXI.settings
  1303. * @type {PIXI.GC_MODES}
  1304. * @default PIXI.GC_MODES.AUTO
  1305. */
  1306. GC_MODE: GC_MODES.AUTO,
  1307. /**
  1308. * Default Garbage Collection max idle.
  1309. *
  1310. * @static
  1311. * @name GC_MAX_IDLE
  1312. * @memberof PIXI.settings
  1313. * @type {number}
  1314. * @default 3600
  1315. */
  1316. GC_MAX_IDLE: 60 * 60,
  1317. /**
  1318. * Default Garbage Collection maximum check count.
  1319. *
  1320. * @static
  1321. * @name GC_MAX_CHECK_COUNT
  1322. * @memberof PIXI.settings
  1323. * @type {number}
  1324. * @default 600
  1325. */
  1326. GC_MAX_CHECK_COUNT: 60 * 10,
  1327. /**
  1328. * Default wrap modes that are supported by pixi.
  1329. *
  1330. * @static
  1331. * @name WRAP_MODE
  1332. * @memberof PIXI.settings
  1333. * @type {PIXI.WRAP_MODES}
  1334. * @default PIXI.WRAP_MODES.CLAMP
  1335. */
  1336. WRAP_MODE: WRAP_MODES.CLAMP,
  1337. /**
  1338. * Default scale mode for textures.
  1339. *
  1340. * @static
  1341. * @name SCALE_MODE
  1342. * @memberof PIXI.settings
  1343. * @type {PIXI.SCALE_MODES}
  1344. * @default PIXI.SCALE_MODES.LINEAR
  1345. */
  1346. SCALE_MODE: SCALE_MODES.LINEAR,
  1347. /**
  1348. * Default specify float precision in vertex shader.
  1349. *
  1350. * @static
  1351. * @name PRECISION_VERTEX
  1352. * @memberof PIXI.settings
  1353. * @type {PIXI.PRECISION}
  1354. * @default PIXI.PRECISION.HIGH
  1355. */
  1356. PRECISION_VERTEX: PRECISION.HIGH,
  1357. /**
  1358. * Default specify float precision in fragment shader.
  1359. * iOS is best set at highp due to https://github.com/pixijs/pixi.js/issues/3742
  1360. *
  1361. * @static
  1362. * @name PRECISION_FRAGMENT
  1363. * @memberof PIXI.settings
  1364. * @type {PIXI.PRECISION}
  1365. * @default PIXI.PRECISION.MEDIUM
  1366. */
  1367. PRECISION_FRAGMENT: isMobile$1.apple.device ? PRECISION.HIGH : PRECISION.MEDIUM,
  1368. /**
  1369. * Can we upload the same buffer in a single frame?
  1370. *
  1371. * @static
  1372. * @name CAN_UPLOAD_SAME_BUFFER
  1373. * @memberof PIXI.settings
  1374. * @type {boolean}
  1375. */
  1376. CAN_UPLOAD_SAME_BUFFER: canUploadSameBuffer(),
  1377. /**
  1378. * Enables bitmap creation before image load. This feature is experimental.
  1379. *
  1380. * @static
  1381. * @name CREATE_IMAGE_BITMAP
  1382. * @memberof PIXI.settings
  1383. * @type {boolean}
  1384. * @default false
  1385. */
  1386. CREATE_IMAGE_BITMAP: false,
  1387. /**
  1388. * If true PixiJS will Math.floor() x/y values when rendering, stopping pixel interpolation.
  1389. * Advantages can include sharper image quality (like text) and faster rendering on canvas.
  1390. * The main disadvantage is movement of objects may appear less smooth.
  1391. *
  1392. * @static
  1393. * @constant
  1394. * @memberof PIXI.settings
  1395. * @type {boolean}
  1396. * @default false
  1397. */
  1398. ROUND_PIXELS: false,
  1399. };
  1400. var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
  1401. function getDefaultExportFromCjs (x) {
  1402. return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
  1403. }
  1404. function createCommonjsModule(fn, basedir, module) {
  1405. return module = {
  1406. path: basedir,
  1407. exports: {},
  1408. require: function (path, base) {
  1409. return commonjsRequire(path, (base === undefined || base === null) ? module.path : base);
  1410. }
  1411. }, fn(module, module.exports), module.exports;
  1412. }
  1413. function getDefaultExportFromNamespaceIfPresent (n) {
  1414. return n && Object.prototype.hasOwnProperty.call(n, 'default') ? n['default'] : n;
  1415. }
  1416. function getDefaultExportFromNamespaceIfNotNamed (n) {
  1417. return n && Object.prototype.hasOwnProperty.call(n, 'default') && Object.keys(n).length === 1 ? n['default'] : n;
  1418. }
  1419. function getAugmentedNamespace(n) {
  1420. if (n.__esModule) return n;
  1421. var a = Object.defineProperty({}, '__esModule', {value: true});
  1422. Object.keys(n).forEach(function (k) {
  1423. var d = Object.getOwnPropertyDescriptor(n, k);
  1424. Object.defineProperty(a, k, d.get ? d : {
  1425. enumerable: true,
  1426. get: function () {
  1427. return n[k];
  1428. }
  1429. });
  1430. });
  1431. return a;
  1432. }
  1433. function commonjsRequire () {
  1434. throw new Error('Dynamic requires are not currently supported by @rollup/plugin-commonjs');
  1435. }
  1436. var eventemitter3 = createCommonjsModule(function (module) {
  1437. 'use strict';
  1438. var has = Object.prototype.hasOwnProperty
  1439. , prefix = '~';
  1440. /**
  1441. * Constructor to create a storage for our `EE` objects.
  1442. * An `Events` instance is a plain object whose properties are event names.
  1443. *
  1444. * @constructor
  1445. * @private
  1446. */
  1447. function Events() {}
  1448. //
  1449. // We try to not inherit from `Object.prototype`. In some engines creating an
  1450. // instance in this way is faster than calling `Object.create(null)` directly.
  1451. // If `Object.create(null)` is not supported we prefix the event names with a
  1452. // character to make sure that the built-in object properties are not
  1453. // overridden or used as an attack vector.
  1454. //
  1455. if (Object.create) {
  1456. Events.prototype = Object.create(null);
  1457. //
  1458. // This hack is needed because the `__proto__` property is still inherited in
  1459. // some old browsers like Android 4, iPhone 5.1, Opera 11 and Safari 5.
  1460. //
  1461. if (!new Events().__proto__) { prefix = false; }
  1462. }
  1463. /**
  1464. * Representation of a single event listener.
  1465. *
  1466. * @param {Function} fn The listener function.
  1467. * @param {*} context The context to invoke the listener with.
  1468. * @param {Boolean} [once=false] Specify if the listener is a one-time listener.
  1469. * @constructor
  1470. * @private
  1471. */
  1472. function EE(fn, context, once) {
  1473. this.fn = fn;
  1474. this.context = context;
  1475. this.once = once || false;
  1476. }
  1477. /**
  1478. * Add a listener for a given event.
  1479. *
  1480. * @param {EventEmitter} emitter Reference to the `EventEmitter` instance.
  1481. * @param {(String|Symbol)} event The event name.
  1482. * @param {Function} fn The listener function.
  1483. * @param {*} context The context to invoke the listener with.
  1484. * @param {Boolean} once Specify if the listener is a one-time listener.
  1485. * @returns {EventEmitter}
  1486. * @private
  1487. */
  1488. function addListener(emitter, event, fn, context, once) {
  1489. if (typeof fn !== 'function') {
  1490. throw new TypeError('The listener must be a function');
  1491. }
  1492. var listener = new EE(fn, context || emitter, once)
  1493. , evt = prefix ? prefix + event : event;
  1494. if (!emitter._events[evt]) { emitter._events[evt] = listener, emitter._eventsCount++; }
  1495. else if (!emitter._events[evt].fn) { emitter._events[evt].push(listener); }
  1496. else { emitter._events[evt] = [emitter._events[evt], listener]; }
  1497. return emitter;
  1498. }
  1499. /**
  1500. * Clear event by name.
  1501. *
  1502. * @param {EventEmitter} emitter Reference to the `EventEmitter` instance.
  1503. * @param {(String|Symbol)} evt The Event name.
  1504. * @private
  1505. */
  1506. function clearEvent(emitter, evt) {
  1507. if (--emitter._eventsCount === 0) { emitter._events = new Events(); }
  1508. else { delete emitter._events[evt]; }
  1509. }
  1510. /**
  1511. * Minimal `EventEmitter` interface that is molded against the Node.js
  1512. * `EventEmitter` interface.
  1513. *
  1514. * @constructor
  1515. * @public
  1516. */
  1517. function EventEmitter() {
  1518. this._events = new Events();
  1519. this._eventsCount = 0;
  1520. }
  1521. /**
  1522. * Return an array listing the events for which the emitter has registered
  1523. * listeners.
  1524. *
  1525. * @returns {Array}
  1526. * @public
  1527. */
  1528. EventEmitter.prototype.eventNames = function eventNames() {
  1529. var names = []
  1530. , events
  1531. , name;
  1532. if (this._eventsCount === 0) { return names; }
  1533. for (name in (events = this._events)) {
  1534. if (has.call(events, name)) { names.push(prefix ? name.slice(1) : name); }
  1535. }
  1536. if (Object.getOwnPropertySymbols) {
  1537. return names.concat(Object.getOwnPropertySymbols(events));
  1538. }
  1539. return names;
  1540. };
  1541. /**
  1542. * Return the listeners registered for a given event.
  1543. *
  1544. * @param {(String|Symbol)} event The event name.
  1545. * @returns {Array} The registered listeners.
  1546. * @public
  1547. */
  1548. EventEmitter.prototype.listeners = function listeners(event) {
  1549. var evt = prefix ? prefix + event : event
  1550. , handlers = this._events[evt];
  1551. if (!handlers) { return []; }
  1552. if (handlers.fn) { return [handlers.fn]; }
  1553. for (var i = 0, l = handlers.length, ee = new Array(l); i < l; i++) {
  1554. ee[i] = handlers[i].fn;
  1555. }
  1556. return ee;
  1557. };
  1558. /**
  1559. * Return the number of listeners listening to a given event.
  1560. *
  1561. * @param {(String|Symbol)} event The event name.
  1562. * @returns {Number} The number of listeners.
  1563. * @public
  1564. */
  1565. EventEmitter.prototype.listenerCount = function listenerCount(event) {
  1566. var evt = prefix ? prefix + event : event
  1567. , listeners = this._events[evt];
  1568. if (!listeners) { return 0; }
  1569. if (listeners.fn) { return 1; }
  1570. return listeners.length;
  1571. };
  1572. /**
  1573. * Calls each of the listeners registered for a given event.
  1574. *
  1575. * @param {(String|Symbol)} event The event name.
  1576. * @returns {Boolean} `true` if the event had listeners, else `false`.
  1577. * @public
  1578. */
  1579. EventEmitter.prototype.emit = function emit(event, a1, a2, a3, a4, a5) {
  1580. var arguments$1 = arguments;
  1581. var evt = prefix ? prefix + event : event;
  1582. if (!this._events[evt]) { return false; }
  1583. var listeners = this._events[evt]
  1584. , len = arguments.length
  1585. , args
  1586. , i;
  1587. if (listeners.fn) {
  1588. if (listeners.once) { this.removeListener(event, listeners.fn, undefined, true); }
  1589. switch (len) {
  1590. case 1: return listeners.fn.call(listeners.context), true;
  1591. case 2: return listeners.fn.call(listeners.context, a1), true;
  1592. case 3: return listeners.fn.call(listeners.context, a1, a2), true;
  1593. case 4: return listeners.fn.call(listeners.context, a1, a2, a3), true;
  1594. case 5: return listeners.fn.call(listeners.context, a1, a2, a3, a4), true;
  1595. case 6: return listeners.fn.call(listeners.context, a1, a2, a3, a4, a5), true;
  1596. }
  1597. for (i = 1, args = new Array(len -1); i < len; i++) {
  1598. args[i - 1] = arguments$1[i];
  1599. }
  1600. listeners.fn.apply(listeners.context, args);
  1601. } else {
  1602. var length = listeners.length
  1603. , j;
  1604. for (i = 0; i < length; i++) {
  1605. if (listeners[i].once) { this.removeListener(event, listeners[i].fn, undefined, true); }
  1606. switch (len) {
  1607. case 1: listeners[i].fn.call(listeners[i].context); break;
  1608. case 2: listeners[i].fn.call(listeners[i].context, a1); break;
  1609. case 3: listeners[i].fn.call(listeners[i].context, a1, a2); break;
  1610. case 4: listeners[i].fn.call(listeners[i].context, a1, a2, a3); break;
  1611. default:
  1612. if (!args) { for (j = 1, args = new Array(len -1); j < len; j++) {
  1613. args[j - 1] = arguments$1[j];
  1614. } }
  1615. listeners[i].fn.apply(listeners[i].context, args);
  1616. }
  1617. }
  1618. }
  1619. return true;
  1620. };
  1621. /**
  1622. * Add a listener for a given event.
  1623. *
  1624. * @param {(String|Symbol)} event The event name.
  1625. * @param {Function} fn The listener function.
  1626. * @param {*} [context=this] The context to invoke the listener with.
  1627. * @returns {EventEmitter} `this`.
  1628. * @public
  1629. */
  1630. EventEmitter.prototype.on = function on(event, fn, context) {
  1631. return addListener(this, event, fn, context, false);
  1632. };
  1633. /**
  1634. * Add a one-time listener for a given event.
  1635. *
  1636. * @param {(String|Symbol)} event The event name.
  1637. * @param {Function} fn The listener function.
  1638. * @param {*} [context=this] The context to invoke the listener with.
  1639. * @returns {EventEmitter} `this`.
  1640. * @public
  1641. */
  1642. EventEmitter.prototype.once = function once(event, fn, context) {
  1643. return addListener(this, event, fn, context, true);
  1644. };
  1645. /**
  1646. * Remove the listeners of a given event.
  1647. *
  1648. * @param {(String|Symbol)} event The event name.
  1649. * @param {Function} fn Only remove the listeners that match this function.
  1650. * @param {*} context Only remove the listeners that have this context.
  1651. * @param {Boolean} once Only remove one-time listeners.
  1652. * @returns {EventEmitter} `this`.
  1653. * @public
  1654. */
  1655. EventEmitter.prototype.removeListener = function removeListener(event, fn, context, once) {
  1656. var evt = prefix ? prefix + event : event;
  1657. if (!this._events[evt]) { return this; }
  1658. if (!fn) {
  1659. clearEvent(this, evt);
  1660. return this;
  1661. }
  1662. var listeners = this._events[evt];
  1663. if (listeners.fn) {
  1664. if (
  1665. listeners.fn === fn &&
  1666. (!once || listeners.once) &&
  1667. (!context || listeners.context === context)
  1668. ) {
  1669. clearEvent(this, evt);
  1670. }
  1671. } else {
  1672. for (var i = 0, events = [], length = listeners.length; i < length; i++) {
  1673. if (
  1674. listeners[i].fn !== fn ||
  1675. (once && !listeners[i].once) ||
  1676. (context && listeners[i].context !== context)
  1677. ) {
  1678. events.push(listeners[i]);
  1679. }
  1680. }
  1681. //
  1682. // Reset the array, or remove it completely if we have no more listeners.
  1683. //
  1684. if (events.length) { this._events[evt] = events.length === 1 ? events[0] : events; }
  1685. else { clearEvent(this, evt); }
  1686. }
  1687. return this;
  1688. };
  1689. /**
  1690. * Remove all listeners, or those of the specified event.
  1691. *
  1692. * @param {(String|Symbol)} [event] The event name.
  1693. * @returns {EventEmitter} `this`.
  1694. * @public
  1695. */
  1696. EventEmitter.prototype.removeAllListeners = function removeAllListeners(event) {
  1697. var evt;
  1698. if (event) {
  1699. evt = prefix ? prefix + event : event;
  1700. if (this._events[evt]) { clearEvent(this, evt); }
  1701. } else {
  1702. this._events = new Events();
  1703. this._eventsCount = 0;
  1704. }
  1705. return this;
  1706. };
  1707. //
  1708. // Alias methods names because people roll like that.
  1709. //
  1710. EventEmitter.prototype.off = EventEmitter.prototype.removeListener;
  1711. EventEmitter.prototype.addListener = EventEmitter.prototype.on;
  1712. //
  1713. // Expose the prefix.
  1714. //
  1715. EventEmitter.prefixed = prefix;
  1716. //
  1717. // Allow `EventEmitter` to be imported as module namespace.
  1718. //
  1719. EventEmitter.EventEmitter = EventEmitter;
  1720. //
  1721. // Expose the module.
  1722. //
  1723. if ('undefined' !== 'object') {
  1724. module.exports = EventEmitter;
  1725. }
  1726. });
  1727. 'use strict';
  1728. var earcut_1 = earcut;
  1729. var _default = earcut;
  1730. function earcut(data, holeIndices, dim) {
  1731. dim = dim || 2;
  1732. var hasHoles = holeIndices && holeIndices.length,
  1733. outerLen = hasHoles ? holeIndices[0] * dim : data.length,
  1734. outerNode = linkedList(data, 0, outerLen, dim, true),
  1735. triangles = [];
  1736. if (!outerNode || outerNode.next === outerNode.prev) { return triangles; }
  1737. var minX, minY, maxX, maxY, x, y, invSize;
  1738. if (hasHoles) { outerNode = eliminateHoles(data, holeIndices, outerNode, dim); }
  1739. // if the shape is not too simple, we'll use z-order curve hash later; calculate polygon bbox
  1740. if (data.length > 80 * dim) {
  1741. minX = maxX = data[0];
  1742. minY = maxY = data[1];
  1743. for (var i = dim; i < outerLen; i += dim) {
  1744. x = data[i];
  1745. y = data[i + 1];
  1746. if (x < minX) { minX = x; }
  1747. if (y < minY) { minY = y; }
  1748. if (x > maxX) { maxX = x; }
  1749. if (y > maxY) { maxY = y; }
  1750. }
  1751. // minX, minY and invSize are later used to transform coords into integers for z-order calculation
  1752. invSize = Math.max(maxX - minX, maxY - minY);
  1753. invSize = invSize !== 0 ? 1 / invSize : 0;
  1754. }
  1755. earcutLinked(outerNode, triangles, dim, minX, minY, invSize);
  1756. return triangles;
  1757. }
  1758. // create a circular doubly linked list from polygon points in the specified winding order
  1759. function linkedList(data, start, end, dim, clockwise) {
  1760. var i, last;
  1761. if (clockwise === (signedArea(data, start, end, dim) > 0)) {
  1762. for (i = start; i < end; i += dim) { last = insertNode(i, data[i], data[i + 1], last); }
  1763. } else {
  1764. for (i = end - dim; i >= start; i -= dim) { last = insertNode(i, data[i], data[i + 1], last); }
  1765. }
  1766. if (last && equals(last, last.next)) {
  1767. removeNode(last);
  1768. last = last.next;
  1769. }
  1770. return last;
  1771. }
  1772. // eliminate colinear or duplicate points
  1773. function filterPoints(start, end) {
  1774. if (!start) { return start; }
  1775. if (!end) { end = start; }
  1776. var p = start,
  1777. again;
  1778. do {
  1779. again = false;
  1780. if (!p.steiner && (equals(p, p.next) || area(p.prev, p, p.next) === 0)) {
  1781. removeNode(p);
  1782. p = end = p.prev;
  1783. if (p === p.next) { break; }
  1784. again = true;
  1785. } else {
  1786. p = p.next;
  1787. }
  1788. } while (again || p !== end);
  1789. return end;
  1790. }
  1791. // main ear slicing loop which triangulates a polygon (given as a linked list)
  1792. function earcutLinked(ear, triangles, dim, minX, minY, invSize, pass) {
  1793. if (!ear) { return; }
  1794. // interlink polygon nodes in z-order
  1795. if (!pass && invSize) { indexCurve(ear, minX, minY, invSize); }
  1796. var stop = ear,
  1797. prev, next;
  1798. // iterate through ears, slicing them one by one
  1799. while (ear.prev !== ear.next) {
  1800. prev = ear.prev;
  1801. next = ear.next;
  1802. if (invSize ? isEarHashed(ear, minX, minY, invSize) : isEar(ear)) {
  1803. // cut off the triangle
  1804. triangles.push(prev.i / dim);
  1805. triangles.push(ear.i / dim);
  1806. triangles.push(next.i / dim);
  1807. removeNode(ear);
  1808. // skipping the next vertex leads to less sliver triangles
  1809. ear = next.next;
  1810. stop = next.next;
  1811. continue;
  1812. }
  1813. ear = next;
  1814. // if we looped through the whole remaining polygon and can't find any more ears
  1815. if (ear === stop) {
  1816. // try filtering points and slicing again
  1817. if (!pass) {
  1818. earcutLinked(filterPoints(ear), triangles, dim, minX, minY, invSize, 1);
  1819. // if this didn't work, try curing all small self-intersections locally
  1820. } else if (pass === 1) {
  1821. ear = cureLocalIntersections(filterPoints(ear), triangles, dim);
  1822. earcutLinked(ear, triangles, dim, minX, minY, invSize, 2);
  1823. // as a last resort, try splitting the remaining polygon into two
  1824. } else if (pass === 2) {
  1825. splitEarcut(ear, triangles, dim, minX, minY, invSize);
  1826. }
  1827. break;
  1828. }
  1829. }
  1830. }
  1831. // check whether a polygon node forms a valid ear with adjacent nodes
  1832. function isEar(ear) {
  1833. var a = ear.prev,
  1834. b = ear,
  1835. c = ear.next;
  1836. if (area(a, b, c) >= 0) { return false; } // reflex, can't be an ear
  1837. // now make sure we don't have other points inside the potential ear
  1838. var p = ear.next.next;
  1839. while (p !== ear.prev) {
  1840. if (pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y) &&
  1841. area(p.prev, p, p.next) >= 0) { return false; }
  1842. p = p.next;
  1843. }
  1844. return true;
  1845. }
  1846. function isEarHashed(ear, minX, minY, invSize) {
  1847. var a = ear.prev,
  1848. b = ear,
  1849. c = ear.next;
  1850. if (area(a, b, c) >= 0) { return false; } // reflex, can't be an ear
  1851. // triangle bbox; min & max are calculated like this for speed
  1852. var minTX = a.x < b.x ? (a.x < c.x ? a.x : c.x) : (b.x < c.x ? b.x : c.x),
  1853. minTY = a.y < b.y ? (a.y < c.y ? a.y : c.y) : (b.y < c.y ? b.y : c.y),
  1854. maxTX = a.x > b.x ? (a.x > c.x ? a.x : c.x) : (b.x > c.x ? b.x : c.x),
  1855. maxTY = a.y > b.y ? (a.y > c.y ? a.y : c.y) : (b.y > c.y ? b.y : c.y);
  1856. // z-order range for the current triangle bbox;
  1857. var minZ = zOrder(minTX, minTY, minX, minY, invSize),
  1858. maxZ = zOrder(maxTX, maxTY, minX, minY, invSize);
  1859. var p = ear.prevZ,
  1860. n = ear.nextZ;
  1861. // look for points inside the triangle in both directions
  1862. while (p && p.z >= minZ && n && n.z <= maxZ) {
  1863. if (p !== ear.prev && p !== ear.next &&
  1864. pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y) &&
  1865. area(p.prev, p, p.next) >= 0) { return false; }
  1866. p = p.prevZ;
  1867. if (n !== ear.prev && n !== ear.next &&
  1868. pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, n.x, n.y) &&
  1869. area(n.prev, n, n.next) >= 0) { return false; }
  1870. n = n.nextZ;
  1871. }
  1872. // look for remaining points in decreasing z-order
  1873. while (p && p.z >= minZ) {
  1874. if (p !== ear.prev && p !== ear.next &&
  1875. pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y) &&
  1876. area(p.prev, p, p.next) >= 0) { return false; }
  1877. p = p.prevZ;
  1878. }
  1879. // look for remaining points in increasing z-order
  1880. while (n && n.z <= maxZ) {
  1881. if (n !== ear.prev && n !== ear.next &&
  1882. pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, n.x, n.y) &&
  1883. area(n.prev, n, n.next) >= 0) { return false; }
  1884. n = n.nextZ;
  1885. }
  1886. return true;
  1887. }
  1888. // go through all polygon nodes and cure small local self-intersections
  1889. function cureLocalIntersections(start, triangles, dim) {
  1890. var p = start;
  1891. do {
  1892. var a = p.prev,
  1893. b = p.next.next;
  1894. if (!equals(a, b) && intersects(a, p, p.next, b) && locallyInside(a, b) && locallyInside(b, a)) {
  1895. triangles.push(a.i / dim);
  1896. triangles.push(p.i / dim);
  1897. triangles.push(b.i / dim);
  1898. // remove two nodes involved
  1899. removeNode(p);
  1900. removeNode(p.next);
  1901. p = start = b;
  1902. }
  1903. p = p.next;
  1904. } while (p !== start);
  1905. return filterPoints(p);
  1906. }
  1907. // try splitting polygon into two and triangulate them independently
  1908. function splitEarcut(start, triangles, dim, minX, minY, invSize) {
  1909. // look for a valid diagonal that divides the polygon into two
  1910. var a = start;
  1911. do {
  1912. var b = a.next.next;
  1913. while (b !== a.prev) {
  1914. if (a.i !== b.i && isValidDiagonal(a, b)) {
  1915. // split the polygon in two by the diagonal
  1916. var c = splitPolygon(a, b);
  1917. // filter colinear points around the cuts
  1918. a = filterPoints(a, a.next);
  1919. c = filterPoints(c, c.next);
  1920. // run earcut on each half
  1921. earcutLinked(a, triangles, dim, minX, minY, invSize);
  1922. earcutLinked(c, triangles, dim, minX, minY, invSize);
  1923. return;
  1924. }
  1925. b = b.next;
  1926. }
  1927. a = a.next;
  1928. } while (a !== start);
  1929. }
  1930. // link every hole into the outer loop, producing a single-ring polygon without holes
  1931. function eliminateHoles(data, holeIndices, outerNode, dim) {
  1932. var queue = [],
  1933. i, len, start, end, list;
  1934. for (i = 0, len = holeIndices.length; i < len; i++) {
  1935. start = holeIndices[i] * dim;
  1936. end = i < len - 1 ? holeIndices[i + 1] * dim : data.length;
  1937. list = linkedList(data, start, end, dim, false);
  1938. if (list === list.next) { list.steiner = true; }
  1939. queue.push(getLeftmost(list));
  1940. }
  1941. queue.sort(compareX);
  1942. // process holes from left to right
  1943. for (i = 0; i < queue.length; i++) {
  1944. eliminateHole(queue[i], outerNode);
  1945. outerNode = filterPoints(outerNode, outerNode.next);
  1946. }
  1947. return outerNode;
  1948. }
  1949. function compareX(a, b) {
  1950. return a.x - b.x;
  1951. }
  1952. // find a bridge between vertices that connects hole with an outer ring and and link it
  1953. function eliminateHole(hole, outerNode) {
  1954. outerNode = findHoleBridge(hole, outerNode);
  1955. if (outerNode) {
  1956. var b = splitPolygon(outerNode, hole);
  1957. // filter collinear points around the cuts
  1958. filterPoints(outerNode, outerNode.next);
  1959. filterPoints(b, b.next);
  1960. }
  1961. }
  1962. // David Eberly's algorithm for finding a bridge between hole and outer polygon
  1963. function findHoleBridge(hole, outerNode) {
  1964. var p = outerNode,
  1965. hx = hole.x,
  1966. hy = hole.y,
  1967. qx = -Infinity,
  1968. m;
  1969. // find a segment intersected by a ray from the hole's leftmost point to the left;
  1970. // segment's endpoint with lesser x will be potential connection point
  1971. do {
  1972. if (hy <= p.y && hy >= p.next.y && p.next.y !== p.y) {
  1973. var x = p.x + (hy - p.y) * (p.next.x - p.x) / (p.next.y - p.y);
  1974. if (x <= hx && x > qx) {
  1975. qx = x;
  1976. if (x === hx) {
  1977. if (hy === p.y) { return p; }
  1978. if (hy === p.next.y) { return p.next; }
  1979. }
  1980. m = p.x < p.next.x ? p : p.next;
  1981. }
  1982. }
  1983. p = p.next;
  1984. } while (p !== outerNode);
  1985. if (!m) { return null; }
  1986. if (hx === qx) { return m; } // hole touches outer segment; pick leftmost endpoint
  1987. // look for points inside the triangle of hole point, segment intersection and endpoint;
  1988. // if there are no points found, we have a valid connection;
  1989. // otherwise choose the point of the minimum angle with the ray as connection point
  1990. var stop = m,
  1991. mx = m.x,
  1992. my = m.y,
  1993. tanMin = Infinity,
  1994. tan;
  1995. p = m;
  1996. do {
  1997. if (hx >= p.x && p.x >= mx && hx !== p.x &&
  1998. pointInTriangle(hy < my ? hx : qx, hy, mx, my, hy < my ? qx : hx, hy, p.x, p.y)) {
  1999. tan = Math.abs(hy - p.y) / (hx - p.x); // tangential
  2000. if (locallyInside(p, hole) &&
  2001. (tan < tanMin || (tan === tanMin && (p.x > m.x || (p.x === m.x && sectorContainsSector(m, p)))))) {
  2002. m = p;
  2003. tanMin = tan;
  2004. }
  2005. }
  2006. p = p.next;
  2007. } while (p !== stop);
  2008. return m;
  2009. }
  2010. // whether sector in vertex m contains sector in vertex p in the same coordinates
  2011. function sectorContainsSector(m, p) {
  2012. return area(m.prev, m, p.prev) < 0 && area(p.next, m, m.next) < 0;
  2013. }
  2014. // interlink polygon nodes in z-order
  2015. function indexCurve(start, minX, minY, invSize) {
  2016. var p = start;
  2017. do {
  2018. if (p.z === null) { p.z = zOrder(p.x, p.y, minX, minY, invSize); }
  2019. p.prevZ = p.prev;
  2020. p.nextZ = p.next;
  2021. p = p.next;
  2022. } while (p !== start);
  2023. p.prevZ.nextZ = null;
  2024. p.prevZ = null;
  2025. sortLinked(p);
  2026. }
  2027. // Simon Tatham's linked list merge sort algorithm
  2028. // http://www.chiark.greenend.org.uk/~sgtatham/algorithms/listsort.html
  2029. function sortLinked(list) {
  2030. var i, p, q, e, tail, numMerges, pSize, qSize,
  2031. inSize = 1;
  2032. do {
  2033. p = list;
  2034. list = null;
  2035. tail = null;
  2036. numMerges = 0;
  2037. while (p) {
  2038. numMerges++;
  2039. q = p;
  2040. pSize = 0;
  2041. for (i = 0; i < inSize; i++) {
  2042. pSize++;
  2043. q = q.nextZ;
  2044. if (!q) { break; }
  2045. }
  2046. qSize = inSize;
  2047. while (pSize > 0 || (qSize > 0 && q)) {
  2048. if (pSize !== 0 && (qSize === 0 || !q || p.z <= q.z)) {
  2049. e = p;
  2050. p = p.nextZ;
  2051. pSize--;
  2052. } else {
  2053. e = q;
  2054. q = q.nextZ;
  2055. qSize--;
  2056. }
  2057. if (tail) { tail.nextZ = e; }
  2058. else { list = e; }
  2059. e.prevZ = tail;
  2060. tail = e;
  2061. }
  2062. p = q;
  2063. }
  2064. tail.nextZ = null;
  2065. inSize *= 2;
  2066. } while (numMerges > 1);
  2067. return list;
  2068. }
  2069. // z-order of a point given coords and inverse of the longer side of data bbox
  2070. function zOrder(x, y, minX, minY, invSize) {
  2071. // coords are transformed into non-negative 15-bit integer range
  2072. x = 32767 * (x - minX) * invSize;
  2073. y = 32767 * (y - minY) * invSize;
  2074. x = (x | (x << 8)) & 0x00FF00FF;
  2075. x = (x | (x << 4)) & 0x0F0F0F0F;
  2076. x = (x | (x << 2)) & 0x33333333;
  2077. x = (x | (x << 1)) & 0x55555555;
  2078. y = (y | (y << 8)) & 0x00FF00FF;
  2079. y = (y | (y << 4)) & 0x0F0F0F0F;
  2080. y = (y | (y << 2)) & 0x33333333;
  2081. y = (y | (y << 1)) & 0x55555555;
  2082. return x | (y << 1);
  2083. }
  2084. // find the leftmost node of a polygon ring
  2085. function getLeftmost(start) {
  2086. var p = start,
  2087. leftmost = start;
  2088. do {
  2089. if (p.x < leftmost.x || (p.x === leftmost.x && p.y < leftmost.y)) { leftmost = p; }
  2090. p = p.next;
  2091. } while (p !== start);
  2092. return leftmost;
  2093. }
  2094. // check if a point lies within a convex triangle
  2095. function pointInTriangle(ax, ay, bx, by, cx, cy, px, py) {
  2096. return (cx - px) * (ay - py) - (ax - px) * (cy - py) >= 0 &&
  2097. (ax - px) * (by - py) - (bx - px) * (ay - py) >= 0 &&
  2098. (bx - px) * (cy - py) - (cx - px) * (by - py) >= 0;
  2099. }
  2100. // check if a diagonal between two polygon nodes is valid (lies in polygon interior)
  2101. function isValidDiagonal(a, b) {
  2102. return a.next.i !== b.i && a.prev.i !== b.i && !intersectsPolygon(a, b) && // dones't intersect other edges
  2103. (locallyInside(a, b) && locallyInside(b, a) && middleInside(a, b) && // locally visible
  2104. (area(a.prev, a, b.prev) || area(a, b.prev, b)) || // does not create opposite-facing sectors
  2105. equals(a, b) && area(a.prev, a, a.next) > 0 && area(b.prev, b, b.next) > 0); // special zero-length case
  2106. }
  2107. // signed area of a triangle
  2108. function area(p, q, r) {
  2109. return (q.y - p.y) * (r.x - q.x) - (q.x - p.x) * (r.y - q.y);
  2110. }
  2111. // check if two points are equal
  2112. function equals(p1, p2) {
  2113. return p1.x === p2.x && p1.y === p2.y;
  2114. }
  2115. // check if two segments intersect
  2116. function intersects(p1, q1, p2, q2) {
  2117. var o1 = sign(area(p1, q1, p2));
  2118. var o2 = sign(area(p1, q1, q2));
  2119. var o3 = sign(area(p2, q2, p1));
  2120. var o4 = sign(area(p2, q2, q1));
  2121. if (o1 !== o2 && o3 !== o4) { return true; } // general case
  2122. if (o1 === 0 && onSegment(p1, p2, q1)) { return true; } // p1, q1 and p2 are collinear and p2 lies on p1q1
  2123. if (o2 === 0 && onSegment(p1, q2, q1)) { return true; } // p1, q1 and q2 are collinear and q2 lies on p1q1
  2124. if (o3 === 0 && onSegment(p2, p1, q2)) { return true; } // p2, q2 and p1 are collinear and p1 lies on p2q2
  2125. if (o4 === 0 && onSegment(p2, q1, q2)) { return true; } // p2, q2 and q1 are collinear and q1 lies on p2q2
  2126. return false;
  2127. }
  2128. // for collinear points p, q, r, check if point q lies on segment pr
  2129. function onSegment(p, q, r) {
  2130. return q.x <= Math.max(p.x, r.x) && q.x >= Math.min(p.x, r.x) && q.y <= Math.max(p.y, r.y) && q.y >= Math.min(p.y, r.y);
  2131. }
  2132. function sign(num) {
  2133. return num > 0 ? 1 : num < 0 ? -1 : 0;
  2134. }
  2135. // check if a polygon diagonal intersects any polygon segments
  2136. function intersectsPolygon(a, b) {
  2137. var p = a;
  2138. do {
  2139. if (p.i !== a.i && p.next.i !== a.i && p.i !== b.i && p.next.i !== b.i &&
  2140. intersects(p, p.next, a, b)) { return true; }
  2141. p = p.next;
  2142. } while (p !== a);
  2143. return false;
  2144. }
  2145. // check if a polygon diagonal is locally inside the polygon
  2146. function locallyInside(a, b) {
  2147. return area(a.prev, a, a.next) < 0 ?
  2148. area(a, b, a.next) >= 0 && area(a, a.prev, b) >= 0 :
  2149. area(a, b, a.prev) < 0 || area(a, a.next, b) < 0;
  2150. }
  2151. // check if the middle point of a polygon diagonal is inside the polygon
  2152. function middleInside(a, b) {
  2153. var p = a,
  2154. inside = false,
  2155. px = (a.x + b.x) / 2,
  2156. py = (a.y + b.y) / 2;
  2157. do {
  2158. if (((p.y > py) !== (p.next.y > py)) && p.next.y !== p.y &&
  2159. (px < (p.next.x - p.x) * (py - p.y) / (p.next.y - p.y) + p.x))
  2160. { inside = !inside; }
  2161. p = p.next;
  2162. } while (p !== a);
  2163. return inside;
  2164. }
  2165. // link two polygon vertices with a bridge; if the vertices belong to the same ring, it splits polygon into two;
  2166. // if one belongs to the outer ring and another to a hole, it merges it into a single ring
  2167. function splitPolygon(a, b) {
  2168. var a2 = new Node(a.i, a.x, a.y),
  2169. b2 = new Node(b.i, b.x, b.y),
  2170. an = a.next,
  2171. bp = b.prev;
  2172. a.next = b;
  2173. b.prev = a;
  2174. a2.next = an;
  2175. an.prev = a2;
  2176. b2.next = a2;
  2177. a2.prev = b2;
  2178. bp.next = b2;
  2179. b2.prev = bp;
  2180. return b2;
  2181. }
  2182. // create a node and optionally link it with previous one (in a circular doubly linked list)
  2183. function insertNode(i, x, y, last) {
  2184. var p = new Node(i, x, y);
  2185. if (!last) {
  2186. p.prev = p;
  2187. p.next = p;
  2188. } else {
  2189. p.next = last.next;
  2190. p.prev = last;
  2191. last.next.prev = p;
  2192. last.next = p;
  2193. }
  2194. return p;
  2195. }
  2196. function removeNode(p) {
  2197. p.next.prev = p.prev;
  2198. p.prev.next = p.next;
  2199. if (p.prevZ) { p.prevZ.nextZ = p.nextZ; }
  2200. if (p.nextZ) { p.nextZ.prevZ = p.prevZ; }
  2201. }
  2202. function Node(i, x, y) {
  2203. // vertex index in coordinates array
  2204. this.i = i;
  2205. // vertex coordinates
  2206. this.x = x;
  2207. this.y = y;
  2208. // previous and next vertex nodes in a polygon ring
  2209. this.prev = null;
  2210. this.next = null;
  2211. // z-order curve value
  2212. this.z = null;
  2213. // previous and next nodes in z-order
  2214. this.prevZ = null;
  2215. this.nextZ = null;
  2216. // indicates whether this is a steiner point
  2217. this.steiner = false;
  2218. }
  2219. // return a percentage difference between the polygon area and its triangulation area;
  2220. // used to verify correctness of triangulation
  2221. earcut.deviation = function (data, holeIndices, dim, triangles) {
  2222. var hasHoles = holeIndices && holeIndices.length;
  2223. var outerLen = hasHoles ? holeIndices[0] * dim : data.length;
  2224. var polygonArea = Math.abs(signedArea(data, 0, outerLen, dim));
  2225. if (hasHoles) {
  2226. for (var i = 0, len = holeIndices.length; i < len; i++) {
  2227. var start = holeIndices[i] * dim;
  2228. var end = i < len - 1 ? holeIndices[i + 1] * dim : data.length;
  2229. polygonArea -= Math.abs(signedArea(data, start, end, dim));
  2230. }
  2231. }
  2232. var trianglesArea = 0;
  2233. for (i = 0; i < triangles.length; i += 3) {
  2234. var a = triangles[i] * dim;
  2235. var b = triangles[i + 1] * dim;
  2236. var c = triangles[i + 2] * dim;
  2237. trianglesArea += Math.abs(
  2238. (data[a] - data[c]) * (data[b + 1] - data[a + 1]) -
  2239. (data[a] - data[b]) * (data[c + 1] - data[a + 1]));
  2240. }
  2241. return polygonArea === 0 && trianglesArea === 0 ? 0 :
  2242. Math.abs((trianglesArea - polygonArea) / polygonArea);
  2243. };
  2244. function signedArea(data, start, end, dim) {
  2245. var sum = 0;
  2246. for (var i = start, j = end - dim; i < end; i += dim) {
  2247. sum += (data[j] - data[i]) * (data[i + 1] + data[j + 1]);
  2248. j = i;
  2249. }
  2250. return sum;
  2251. }
  2252. // turn a polygon in a multi-dimensional array form (e.g. as in GeoJSON) into a form Earcut accepts
  2253. earcut.flatten = function (data) {
  2254. var dim = data[0][0].length,
  2255. result = {vertices: [], holes: [], dimensions: dim},
  2256. holeIndex = 0;
  2257. for (var i = 0; i < data.length; i++) {
  2258. for (var j = 0; j < data[i].length; j++) {
  2259. for (var d = 0; d < dim; d++) { result.vertices.push(data[i][j][d]); }
  2260. }
  2261. if (i > 0) {
  2262. holeIndex += data[i - 1].length;
  2263. result.holes.push(holeIndex);
  2264. }
  2265. }
  2266. return result;
  2267. };
  2268. earcut_1.default = _default;
  2269. var punycode = createCommonjsModule(function (module, exports) {
  2270. /*! https://mths.be/punycode v1.3.2 by @mathias */
  2271. ;(function(root) {
  2272. /** Detect free variables */
  2273. var freeExports = 'object' == 'object' && exports &&
  2274. !exports.nodeType && exports;
  2275. var freeModule = 'object' == 'object' && module &&
  2276. !module.nodeType && module;
  2277. var freeGlobal = typeof commonjsGlobal == 'object' && commonjsGlobal;
  2278. if (
  2279. freeGlobal.global === freeGlobal ||
  2280. freeGlobal.window === freeGlobal ||
  2281. freeGlobal.self === freeGlobal
  2282. ) {
  2283. root = freeGlobal;
  2284. }
  2285. /**
  2286. * The `punycode` object.
  2287. * @name punycode
  2288. * @type Object
  2289. */
  2290. var punycode,
  2291. /** Highest positive signed 32-bit float value */
  2292. maxInt = 2147483647, // aka. 0x7FFFFFFF or 2^31-1
  2293. /** Bootstring parameters */
  2294. base = 36,
  2295. tMin = 1,
  2296. tMax = 26,
  2297. skew = 38,
  2298. damp = 700,
  2299. initialBias = 72,
  2300. initialN = 128, // 0x80
  2301. delimiter = '-', // '\x2D'
  2302. /** Regular expressions */
  2303. regexPunycode = /^xn--/,
  2304. regexNonASCII = /[^\x20-\x7E]/, // unprintable ASCII chars + non-ASCII chars
  2305. regexSeparators = /[\x2E\u3002\uFF0E\uFF61]/g, // RFC 3490 separators
  2306. /** Error messages */
  2307. errors = {
  2308. 'overflow': 'Overflow: input needs wider integers to process',
  2309. 'not-basic': 'Illegal input >= 0x80 (not a basic code point)',
  2310. 'invalid-input': 'Invalid input'
  2311. },
  2312. /** Convenience shortcuts */
  2313. baseMinusTMin = base - tMin,
  2314. floor = Math.floor,
  2315. stringFromCharCode = String.fromCharCode,
  2316. /** Temporary variable */
  2317. key;
  2318. /*--------------------------------------------------------------------------*/
  2319. /**
  2320. * A generic error utility function.
  2321. * @private
  2322. * @param {String} type The error type.
  2323. * @returns {Error} Throws a `RangeError` with the applicable error message.
  2324. */
  2325. function error(type) {
  2326. throw RangeError(errors[type]);
  2327. }
  2328. /**
  2329. * A generic `Array#map` utility function.
  2330. * @private
  2331. * @param {Array} array The array to iterate over.
  2332. * @param {Function} callback The function that gets called for every array
  2333. * item.
  2334. * @returns {Array} A new array of values returned by the callback function.
  2335. */
  2336. function map(array, fn) {
  2337. var length = array.length;
  2338. var result = [];
  2339. while (length--) {
  2340. result[length] = fn(array[length]);
  2341. }
  2342. return result;
  2343. }
  2344. /**
  2345. * A simple `Array#map`-like wrapper to work with domain name strings or email
  2346. * addresses.
  2347. * @private
  2348. * @param {String} domain The domain name or email address.
  2349. * @param {Function} callback The function that gets called for every
  2350. * character.
  2351. * @returns {Array} A new string of characters returned by the callback
  2352. * function.
  2353. */
  2354. function mapDomain(string, fn) {
  2355. var parts = string.split('@');
  2356. var result = '';
  2357. if (parts.length > 1) {
  2358. // In email addresses, only the domain name should be punycoded. Leave
  2359. // the local part (i.e. everything up to `@`) intact.
  2360. result = parts[0] + '@';
  2361. string = parts[1];
  2362. }
  2363. // Avoid `split(regex)` for IE8 compatibility. See #17.
  2364. string = string.replace(regexSeparators, '\x2E');
  2365. var labels = string.split('.');
  2366. var encoded = map(labels, fn).join('.');
  2367. return result + encoded;
  2368. }
  2369. /**
  2370. * Creates an array containing the numeric code points of each Unicode
  2371. * character in the string. While JavaScript uses UCS-2 internally,
  2372. * this function will convert a pair of surrogate halves (each of which
  2373. * UCS-2 exposes as separate characters) into a single code point,
  2374. * matching UTF-16.
  2375. * @see `punycode.ucs2.encode`
  2376. * @see <https://mathiasbynens.be/notes/javascript-encoding>
  2377. * @memberOf punycode.ucs2
  2378. * @name decode
  2379. * @param {String} string The Unicode input string (UCS-2).
  2380. * @returns {Array} The new array of code points.
  2381. */
  2382. function ucs2decode(string) {
  2383. var output = [],
  2384. counter = 0,
  2385. length = string.length,
  2386. value,
  2387. extra;
  2388. while (counter < length) {
  2389. value = string.charCodeAt(counter++);
  2390. if (value >= 0xD800 && value <= 0xDBFF && counter < length) {
  2391. // high surrogate, and there is a next character
  2392. extra = string.charCodeAt(counter++);
  2393. if ((extra & 0xFC00) == 0xDC00) { // low surrogate
  2394. output.push(((value & 0x3FF) << 10) + (extra & 0x3FF) + 0x10000);
  2395. } else {
  2396. // unmatched surrogate; only append this code unit, in case the next
  2397. // code unit is the high surrogate of a surrogate pair
  2398. output.push(value);
  2399. counter--;
  2400. }
  2401. } else {
  2402. output.push(value);
  2403. }
  2404. }
  2405. return output;
  2406. }
  2407. /**
  2408. * Creates a string based on an array of numeric code points.
  2409. * @see `punycode.ucs2.decode`
  2410. * @memberOf punycode.ucs2
  2411. * @name encode
  2412. * @param {Array} codePoints The array of numeric code points.
  2413. * @returns {String} The new Unicode string (UCS-2).
  2414. */
  2415. function ucs2encode(array) {
  2416. return map(array, function(value) {
  2417. var output = '';
  2418. if (value > 0xFFFF) {
  2419. value -= 0x10000;
  2420. output += stringFromCharCode(value >>> 10 & 0x3FF | 0xD800);
  2421. value = 0xDC00 | value & 0x3FF;
  2422. }
  2423. output += stringFromCharCode(value);
  2424. return output;
  2425. }).join('');
  2426. }
  2427. /**
  2428. * Converts a basic code point into a digit/integer.
  2429. * @see `digitToBasic()`
  2430. * @private
  2431. * @param {Number} codePoint The basic numeric code point value.
  2432. * @returns {Number} The numeric value of a basic code point (for use in
  2433. * representing integers) in the range `0` to `base - 1`, or `base` if
  2434. * the code point does not represent a value.
  2435. */
  2436. function basicToDigit(codePoint) {
  2437. if (codePoint - 48 < 10) {
  2438. return codePoint - 22;
  2439. }
  2440. if (codePoint - 65 < 26) {
  2441. return codePoint - 65;
  2442. }
  2443. if (codePoint - 97 < 26) {
  2444. return codePoint - 97;
  2445. }
  2446. return base;
  2447. }
  2448. /**
  2449. * Converts a digit/integer into a basic code point.
  2450. * @see `basicToDigit()`
  2451. * @private
  2452. * @param {Number} digit The numeric value of a basic code point.
  2453. * @returns {Number} The basic code point whose value (when used for
  2454. * representing integers) is `digit`, which needs to be in the range
  2455. * `0` to `base - 1`. If `flag` is non-zero, the uppercase form is
  2456. * used; else, the lowercase form is used. The behavior is undefined
  2457. * if `flag` is non-zero and `digit` has no uppercase form.
  2458. */
  2459. function digitToBasic(digit, flag) {
  2460. // 0..25 map to ASCII a..z or A..Z
  2461. // 26..35 map to ASCII 0..9
  2462. return digit + 22 + 75 * (digit < 26) - ((flag != 0) << 5);
  2463. }
  2464. /**
  2465. * Bias adaptation function as per section 3.4 of RFC 3492.
  2466. * http://tools.ietf.org/html/rfc3492#section-3.4
  2467. * @private
  2468. */
  2469. function adapt(delta, numPoints, firstTime) {
  2470. var k = 0;
  2471. delta = firstTime ? floor(delta / damp) : delta >> 1;
  2472. delta += floor(delta / numPoints);
  2473. for (/* no initialization */; delta > baseMinusTMin * tMax >> 1; k += base) {
  2474. delta = floor(delta / baseMinusTMin);
  2475. }
  2476. return floor(k + (baseMinusTMin + 1) * delta / (delta + skew));
  2477. }
  2478. /**
  2479. * Converts a Punycode string of ASCII-only symbols to a string of Unicode
  2480. * symbols.
  2481. * @memberOf punycode
  2482. * @param {String} input The Punycode string of ASCII-only symbols.
  2483. * @returns {String} The resulting string of Unicode symbols.
  2484. */
  2485. function decode(input) {
  2486. // Don't use UCS-2
  2487. var output = [],
  2488. inputLength = input.length,
  2489. out,
  2490. i = 0,
  2491. n = initialN,
  2492. bias = initialBias,
  2493. basic,
  2494. j,
  2495. index,
  2496. oldi,
  2497. w,
  2498. k,
  2499. digit,
  2500. t,
  2501. /** Cached calculation results */
  2502. baseMinusT;
  2503. // Handle the basic code points: let `basic` be the number of input code
  2504. // points before the last delimiter, or `0` if there is none, then copy
  2505. // the first basic code points to the output.
  2506. basic = input.lastIndexOf(delimiter);
  2507. if (basic < 0) {
  2508. basic = 0;
  2509. }
  2510. for (j = 0; j < basic; ++j) {
  2511. // if it's not a basic code point
  2512. if (input.charCodeAt(j) >= 0x80) {
  2513. error('not-basic');
  2514. }
  2515. output.push(input.charCodeAt(j));
  2516. }
  2517. // Main decoding loop: start just after the last delimiter if any basic code
  2518. // points were copied; start at the beginning otherwise.
  2519. for (index = basic > 0 ? basic + 1 : 0; index < inputLength; /* no final expression */) {
  2520. // `index` is the index of the next character to be consumed.
  2521. // Decode a generalized variable-length integer into `delta`,
  2522. // which gets added to `i`. The overflow checking is easier
  2523. // if we increase `i` as we go, then subtract off its starting
  2524. // value at the end to obtain `delta`.
  2525. for (oldi = i, w = 1, k = base; /* no condition */; k += base) {
  2526. if (index >= inputLength) {
  2527. error('invalid-input');
  2528. }
  2529. digit = basicToDigit(input.charCodeAt(index++));
  2530. if (digit >= base || digit > floor((maxInt - i) / w)) {
  2531. error('overflow');
  2532. }
  2533. i += digit * w;
  2534. t = k <= bias ? tMin : (k >= bias + tMax ? tMax : k - bias);
  2535. if (digit < t) {
  2536. break;
  2537. }
  2538. baseMinusT = base - t;
  2539. if (w > floor(maxInt / baseMinusT)) {
  2540. error('overflow');
  2541. }
  2542. w *= baseMinusT;
  2543. }
  2544. out = output.length + 1;
  2545. bias = adapt(i - oldi, out, oldi == 0);
  2546. // `i` was supposed to wrap around from `out` to `0`,
  2547. // incrementing `n` each time, so we'll fix that now:
  2548. if (floor(i / out) > maxInt - n) {
  2549. error('overflow');
  2550. }
  2551. n += floor(i / out);
  2552. i %= out;
  2553. // Insert `n` at position `i` of the output
  2554. output.splice(i++, 0, n);
  2555. }
  2556. return ucs2encode(output);
  2557. }
  2558. /**
  2559. * Converts a string of Unicode symbols (e.g. a domain name label) to a
  2560. * Punycode string of ASCII-only symbols.
  2561. * @memberOf punycode
  2562. * @param {String} input The string of Unicode symbols.
  2563. * @returns {String} The resulting Punycode string of ASCII-only symbols.
  2564. */
  2565. function encode(input) {
  2566. var n,
  2567. delta,
  2568. handledCPCount,
  2569. basicLength,
  2570. bias,
  2571. j,
  2572. m,
  2573. q,
  2574. k,
  2575. t,
  2576. currentValue,
  2577. output = [],
  2578. /** `inputLength` will hold the number of code points in `input`. */
  2579. inputLength,
  2580. /** Cached calculation results */
  2581. handledCPCountPlusOne,
  2582. baseMinusT,
  2583. qMinusT;
  2584. // Convert the input in UCS-2 to Unicode
  2585. input = ucs2decode(input);
  2586. // Cache the length
  2587. inputLength = input.length;
  2588. // Initialize the state
  2589. n = initialN;
  2590. delta = 0;
  2591. bias = initialBias;
  2592. // Handle the basic code points
  2593. for (j = 0; j < inputLength; ++j) {
  2594. currentValue = input[j];
  2595. if (currentValue < 0x80) {
  2596. output.push(stringFromCharCode(currentValue));
  2597. }
  2598. }
  2599. handledCPCount = basicLength = output.length;
  2600. // `handledCPCount` is the number of code points that have been handled;
  2601. // `basicLength` is the number of basic code points.
  2602. // Finish the basic string - if it is not empty - with a delimiter
  2603. if (basicLength) {
  2604. output.push(delimiter);
  2605. }
  2606. // Main encoding loop:
  2607. while (handledCPCount < inputLength) {
  2608. // All non-basic code points < n have been handled already. Find the next
  2609. // larger one:
  2610. for (m = maxInt, j = 0; j < inputLength; ++j) {
  2611. currentValue = input[j];
  2612. if (currentValue >= n && currentValue < m) {
  2613. m = currentValue;
  2614. }
  2615. }
  2616. // Increase `delta` enough to advance the decoder's <n,i> state to <m,0>,
  2617. // but guard against overflow
  2618. handledCPCountPlusOne = handledCPCount + 1;
  2619. if (m - n > floor((maxInt - delta) / handledCPCountPlusOne)) {
  2620. error('overflow');
  2621. }
  2622. delta += (m - n) * handledCPCountPlusOne;
  2623. n = m;
  2624. for (j = 0; j < inputLength; ++j) {
  2625. currentValue = input[j];
  2626. if (currentValue < n && ++delta > maxInt) {
  2627. error('overflow');
  2628. }
  2629. if (currentValue == n) {
  2630. // Represent delta as a generalized variable-length integer
  2631. for (q = delta, k = base; /* no condition */; k += base) {
  2632. t = k <= bias ? tMin : (k >= bias + tMax ? tMax : k - bias);
  2633. if (q < t) {
  2634. break;
  2635. }
  2636. qMinusT = q - t;
  2637. baseMinusT = base - t;
  2638. output.push(
  2639. stringFromCharCode(digitToBasic(t + qMinusT % baseMinusT, 0))
  2640. );
  2641. q = floor(qMinusT / baseMinusT);
  2642. }
  2643. output.push(stringFromCharCode(digitToBasic(q, 0)));
  2644. bias = adapt(delta, handledCPCountPlusOne, handledCPCount == basicLength);
  2645. delta = 0;
  2646. ++handledCPCount;
  2647. }
  2648. }
  2649. ++delta;
  2650. ++n;
  2651. }
  2652. return output.join('');
  2653. }
  2654. /**
  2655. * Converts a Punycode string representing a domain name or an email address
  2656. * to Unicode. Only the Punycoded parts of the input will be converted, i.e.
  2657. * it doesn't matter if you call it on a string that has already been
  2658. * converted to Unicode.
  2659. * @memberOf punycode
  2660. * @param {String} input The Punycoded domain name or email address to
  2661. * convert to Unicode.
  2662. * @returns {String} The Unicode representation of the given Punycode
  2663. * string.
  2664. */
  2665. function toUnicode(input) {
  2666. return mapDomain(input, function(string) {
  2667. return regexPunycode.test(string)
  2668. ? decode(string.slice(4).toLowerCase())
  2669. : string;
  2670. });
  2671. }
  2672. /**
  2673. * Converts a Unicode string representing a domain name or an email address to
  2674. * Punycode. Only the non-ASCII parts of the domain name will be converted,
  2675. * i.e. it doesn't matter if you call it with a domain that's already in
  2676. * ASCII.
  2677. * @memberOf punycode
  2678. * @param {String} input The domain name or email address to convert, as a
  2679. * Unicode string.
  2680. * @returns {String} The Punycode representation of the given domain name or
  2681. * email address.
  2682. */
  2683. function toASCII(input) {
  2684. return mapDomain(input, function(string) {
  2685. return regexNonASCII.test(string)
  2686. ? 'xn--' + encode(string)
  2687. : string;
  2688. });
  2689. }
  2690. /*--------------------------------------------------------------------------*/
  2691. /** Define the public API */
  2692. punycode = {
  2693. /**
  2694. * A string representing the current Punycode.js version number.
  2695. * @memberOf punycode
  2696. * @type String
  2697. */
  2698. 'version': '1.3.2',
  2699. /**
  2700. * An object of methods to convert from JavaScript's internal character
  2701. * representation (UCS-2) to Unicode code points, and back.
  2702. * @see <https://mathiasbynens.be/notes/javascript-encoding>
  2703. * @memberOf punycode
  2704. * @type Object
  2705. */
  2706. 'ucs2': {
  2707. 'decode': ucs2decode,
  2708. 'encode': ucs2encode
  2709. },
  2710. 'decode': decode,
  2711. 'encode': encode,
  2712. 'toASCII': toASCII,
  2713. 'toUnicode': toUnicode
  2714. };
  2715. /** Expose `punycode` */
  2716. // Some AMD build optimizers, like r.js, check for specific condition patterns
  2717. // like the following:
  2718. if (
  2719. typeof undefined == 'function' &&
  2720. typeof undefined.amd == 'object' &&
  2721. undefined.amd
  2722. ) {
  2723. undefined('punycode', function() {
  2724. return punycode;
  2725. });
  2726. } else if (freeExports && freeModule) {
  2727. if (module.exports == freeExports) { // in Node.js or RingoJS v0.8.0+
  2728. freeModule.exports = punycode;
  2729. } else { // in Narwhal or RingoJS v0.7.0-
  2730. for (key in punycode) {
  2731. punycode.hasOwnProperty(key) && (freeExports[key] = punycode[key]);
  2732. }
  2733. }
  2734. } else { // in Rhino or a web browser
  2735. root.punycode = punycode;
  2736. }
  2737. }(commonjsGlobal));
  2738. });
  2739. 'use strict';
  2740. var util = {
  2741. isString: function(arg) {
  2742. return typeof(arg) === 'string';
  2743. },
  2744. isObject: function(arg) {
  2745. return typeof(arg) === 'object' && arg !== null;
  2746. },
  2747. isNull: function(arg) {
  2748. return arg === null;
  2749. },
  2750. isNullOrUndefined: function(arg) {
  2751. return arg == null;
  2752. }
  2753. };
  2754. // Copyright Joyent, Inc. and other Node contributors.
  2755. //
  2756. // Permission is hereby granted, free of charge, to any person obtaining a
  2757. // copy of this software and associated documentation files (the
  2758. // "Software"), to deal in the Software without restriction, including
  2759. // without limitation the rights to use, copy, modify, merge, publish,
  2760. // distribute, sublicense, and/or sell copies of the Software, and to permit
  2761. // persons to whom the Software is furnished to do so, subject to the
  2762. // following conditions:
  2763. //
  2764. // The above copyright notice and this permission notice shall be included
  2765. // in all copies or substantial portions of the Software.
  2766. //
  2767. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  2768. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  2769. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  2770. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  2771. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  2772. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  2773. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  2774. 'use strict';
  2775. // If obj.hasOwnProperty has been overridden, then calling
  2776. // obj.hasOwnProperty(prop) will break.
  2777. // See: https://github.com/joyent/node/issues/1707
  2778. function hasOwnProperty$1(obj, prop) {
  2779. return Object.prototype.hasOwnProperty.call(obj, prop);
  2780. }
  2781. var decode = function(qs, sep, eq, options) {
  2782. sep = sep || '&';
  2783. eq = eq || '=';
  2784. var obj = {};
  2785. if (typeof qs !== 'string' || qs.length === 0) {
  2786. return obj;
  2787. }
  2788. var regexp = /\+/g;
  2789. qs = qs.split(sep);
  2790. var maxKeys = 1000;
  2791. if (options && typeof options.maxKeys === 'number') {
  2792. maxKeys = options.maxKeys;
  2793. }
  2794. var len = qs.length;
  2795. // maxKeys <= 0 means that we should not limit keys count
  2796. if (maxKeys > 0 && len > maxKeys) {
  2797. len = maxKeys;
  2798. }
  2799. for (var i = 0; i < len; ++i) {
  2800. var x = qs[i].replace(regexp, '%20'),
  2801. idx = x.indexOf(eq),
  2802. kstr, vstr, k, v;
  2803. if (idx >= 0) {
  2804. kstr = x.substr(0, idx);
  2805. vstr = x.substr(idx + 1);
  2806. } else {
  2807. kstr = x;
  2808. vstr = '';
  2809. }
  2810. k = decodeURIComponent(kstr);
  2811. v = decodeURIComponent(vstr);
  2812. if (!hasOwnProperty$1(obj, k)) {
  2813. obj[k] = v;
  2814. } else if (Array.isArray(obj[k])) {
  2815. obj[k].push(v);
  2816. } else {
  2817. obj[k] = [obj[k], v];
  2818. }
  2819. }
  2820. return obj;
  2821. };
  2822. // Copyright Joyent, Inc. and other Node contributors.
  2823. //
  2824. // Permission is hereby granted, free of charge, to any person obtaining a
  2825. // copy of this software and associated documentation files (the
  2826. // "Software"), to deal in the Software without restriction, including
  2827. // without limitation the rights to use, copy, modify, merge, publish,
  2828. // distribute, sublicense, and/or sell copies of the Software, and to permit
  2829. // persons to whom the Software is furnished to do so, subject to the
  2830. // following conditions:
  2831. //
  2832. // The above copyright notice and this permission notice shall be included
  2833. // in all copies or substantial portions of the Software.
  2834. //
  2835. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  2836. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  2837. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  2838. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  2839. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  2840. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  2841. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  2842. 'use strict';
  2843. var stringifyPrimitive = function(v) {
  2844. switch (typeof v) {
  2845. case 'string':
  2846. return v;
  2847. case 'boolean':
  2848. return v ? 'true' : 'false';
  2849. case 'number':
  2850. return isFinite(v) ? v : '';
  2851. default:
  2852. return '';
  2853. }
  2854. };
  2855. var encode = function(obj, sep, eq, name) {
  2856. sep = sep || '&';
  2857. eq = eq || '=';
  2858. if (obj === null) {
  2859. obj = undefined;
  2860. }
  2861. if (typeof obj === 'object') {
  2862. return Object.keys(obj).map(function(k) {
  2863. var ks = encodeURIComponent(stringifyPrimitive(k)) + eq;
  2864. if (Array.isArray(obj[k])) {
  2865. return obj[k].map(function(v) {
  2866. return ks + encodeURIComponent(stringifyPrimitive(v));
  2867. }).join(sep);
  2868. } else {
  2869. return ks + encodeURIComponent(stringifyPrimitive(obj[k]));
  2870. }
  2871. }).join(sep);
  2872. }
  2873. if (!name) { return ''; }
  2874. return encodeURIComponent(stringifyPrimitive(name)) + eq +
  2875. encodeURIComponent(stringifyPrimitive(obj));
  2876. };
  2877. var querystring = createCommonjsModule(function (module, exports) {
  2878. 'use strict';
  2879. exports.decode = exports.parse = decode;
  2880. exports.encode = exports.stringify = encode;
  2881. });
  2882. // Copyright Joyent, Inc. and other Node contributors.
  2883. //
  2884. // Permission is hereby granted, free of charge, to any person obtaining a
  2885. // copy of this software and associated documentation files (the
  2886. // "Software"), to deal in the Software without restriction, including
  2887. // without limitation the rights to use, copy, modify, merge, publish,
  2888. // distribute, sublicense, and/or sell copies of the Software, and to permit
  2889. // persons to whom the Software is furnished to do so, subject to the
  2890. // following conditions:
  2891. //
  2892. // The above copyright notice and this permission notice shall be included
  2893. // in all copies or substantial portions of the Software.
  2894. //
  2895. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  2896. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  2897. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  2898. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  2899. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  2900. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  2901. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  2902. 'use strict';
  2903. var parse = urlParse;
  2904. var resolve$1 = urlResolve;
  2905. var resolveObject = urlResolveObject;
  2906. var format = urlFormat;
  2907. var Url_1 = Url;
  2908. function Url() {
  2909. this.protocol = null;
  2910. this.slashes = null;
  2911. this.auth = null;
  2912. this.host = null;
  2913. this.port = null;
  2914. this.hostname = null;
  2915. this.hash = null;
  2916. this.search = null;
  2917. this.query = null;
  2918. this.pathname = null;
  2919. this.path = null;
  2920. this.href = null;
  2921. }
  2922. // Reference: RFC 3986, RFC 1808, RFC 2396
  2923. // define these here so at least they only have to be
  2924. // compiled once on the first module load.
  2925. var protocolPattern = /^([a-z0-9.+-]+:)/i,
  2926. portPattern = /:[0-9]*$/,
  2927. // Special case for a simple path URL
  2928. simplePathPattern = /^(\/\/?(?!\/)[^\?\s]*)(\?[^\s]*)?$/,
  2929. // RFC 2396: characters reserved for delimiting URLs.
  2930. // We actually just auto-escape these.
  2931. delims = ['<', '>', '"', '`', ' ', '\r', '\n', '\t'],
  2932. // RFC 2396: characters not allowed for various reasons.
  2933. unwise = ['{', '}', '|', '\\', '^', '`'].concat(delims),
  2934. // Allowed by RFCs, but cause of XSS attacks. Always escape these.
  2935. autoEscape = ['\''].concat(unwise),
  2936. // Characters that are never ever allowed in a hostname.
  2937. // Note that any invalid chars are also handled, but these
  2938. // are the ones that are *expected* to be seen, so we fast-path
  2939. // them.
  2940. nonHostChars = ['%', '/', '?', ';', '#'].concat(autoEscape),
  2941. hostEndingChars = ['/', '?', '#'],
  2942. hostnameMaxLen = 255,
  2943. hostnamePartPattern = /^[+a-z0-9A-Z_-]{0,63}$/,
  2944. hostnamePartStart = /^([+a-z0-9A-Z_-]{0,63})(.*)$/,
  2945. // protocols that can allow "unsafe" and "unwise" chars.
  2946. unsafeProtocol = {
  2947. 'javascript': true,
  2948. 'javascript:': true
  2949. },
  2950. // protocols that never have a hostname.
  2951. hostlessProtocol = {
  2952. 'javascript': true,
  2953. 'javascript:': true
  2954. },
  2955. // protocols that always contain a // bit.
  2956. slashedProtocol = {
  2957. 'http': true,
  2958. 'https': true,
  2959. 'ftp': true,
  2960. 'gopher': true,
  2961. 'file': true,
  2962. 'http:': true,
  2963. 'https:': true,
  2964. 'ftp:': true,
  2965. 'gopher:': true,
  2966. 'file:': true
  2967. };
  2968. function urlParse(url, parseQueryString, slashesDenoteHost) {
  2969. if (url && util.isObject(url) && url instanceof Url) { return url; }
  2970. var u = new Url;
  2971. u.parse(url, parseQueryString, slashesDenoteHost);
  2972. return u;
  2973. }
  2974. Url.prototype.parse = function(url, parseQueryString, slashesDenoteHost) {
  2975. if (!util.isString(url)) {
  2976. throw new TypeError("Parameter 'url' must be a string, not " + typeof url);
  2977. }
  2978. // Copy chrome, IE, opera backslash-handling behavior.
  2979. // Back slashes before the query string get converted to forward slashes
  2980. // See: https://code.google.com/p/chromium/issues/detail?id=25916
  2981. var queryIndex = url.indexOf('?'),
  2982. splitter =
  2983. (queryIndex !== -1 && queryIndex < url.indexOf('#')) ? '?' : '#',
  2984. uSplit = url.split(splitter),
  2985. slashRegex = /\\/g;
  2986. uSplit[0] = uSplit[0].replace(slashRegex, '/');
  2987. url = uSplit.join(splitter);
  2988. var rest = url;
  2989. // trim before proceeding.
  2990. // This is to support parse stuff like " http://foo.com \n"
  2991. rest = rest.trim();
  2992. if (!slashesDenoteHost && url.split('#').length === 1) {
  2993. // Try fast path regexp
  2994. var simplePath = simplePathPattern.exec(rest);
  2995. if (simplePath) {
  2996. this.path = rest;
  2997. this.href = rest;
  2998. this.pathname = simplePath[1];
  2999. if (simplePath[2]) {
  3000. this.search = simplePath[2];
  3001. if (parseQueryString) {
  3002. this.query = querystring.parse(this.search.substr(1));
  3003. } else {
  3004. this.query = this.search.substr(1);
  3005. }
  3006. } else if (parseQueryString) {
  3007. this.search = '';
  3008. this.query = {};
  3009. }
  3010. return this;
  3011. }
  3012. }
  3013. var proto = protocolPattern.exec(rest);
  3014. if (proto) {
  3015. proto = proto[0];
  3016. var lowerProto = proto.toLowerCase();
  3017. this.protocol = lowerProto;
  3018. rest = rest.substr(proto.length);
  3019. }
  3020. // figure out if it's got a host
  3021. // user@server is *always* interpreted as a hostname, and url
  3022. // resolution will treat //foo/bar as host=foo,path=bar because that's
  3023. // how the browser resolves relative URLs.
  3024. if (slashesDenoteHost || proto || rest.match(/^\/\/[^@\/]+@[^@\/]+/)) {
  3025. var slashes = rest.substr(0, 2) === '//';
  3026. if (slashes && !(proto && hostlessProtocol[proto])) {
  3027. rest = rest.substr(2);
  3028. this.slashes = true;
  3029. }
  3030. }
  3031. if (!hostlessProtocol[proto] &&
  3032. (slashes || (proto && !slashedProtocol[proto]))) {
  3033. // there's a hostname.
  3034. // the first instance of /, ?, ;, or # ends the host.
  3035. //
  3036. // If there is an @ in the hostname, then non-host chars *are* allowed
  3037. // to the left of the last @ sign, unless some host-ending character
  3038. // comes *before* the @-sign.
  3039. // URLs are obnoxious.
  3040. //
  3041. // ex:
  3042. // http://a@b@c/ => user:a@b host:c
  3043. // http://a@b?@c => user:a host:c path:/?@c
  3044. // v0.12 TODO(isaacs): This is not quite how Chrome does things.
  3045. // Review our test case against browsers more comprehensively.
  3046. // find the first instance of any hostEndingChars
  3047. var hostEnd = -1;
  3048. for (var i = 0; i < hostEndingChars.length; i++) {
  3049. var hec = rest.indexOf(hostEndingChars[i]);
  3050. if (hec !== -1 && (hostEnd === -1 || hec < hostEnd))
  3051. { hostEnd = hec; }
  3052. }
  3053. // at this point, either we have an explicit point where the
  3054. // auth portion cannot go past, or the last @ char is the decider.
  3055. var auth, atSign;
  3056. if (hostEnd === -1) {
  3057. // atSign can be anywhere.
  3058. atSign = rest.lastIndexOf('@');
  3059. } else {
  3060. // atSign must be in auth portion.
  3061. // http://a@b/c@d => host:b auth:a path:/c@d
  3062. atSign = rest.lastIndexOf('@', hostEnd);
  3063. }
  3064. // Now we have a portion which is definitely the auth.
  3065. // Pull that off.
  3066. if (atSign !== -1) {
  3067. auth = rest.slice(0, atSign);
  3068. rest = rest.slice(atSign + 1);
  3069. this.auth = decodeURIComponent(auth);
  3070. }
  3071. // the host is the remaining to the left of the first non-host char
  3072. hostEnd = -1;
  3073. for (var i = 0; i < nonHostChars.length; i++) {
  3074. var hec = rest.indexOf(nonHostChars[i]);
  3075. if (hec !== -1 && (hostEnd === -1 || hec < hostEnd))
  3076. { hostEnd = hec; }
  3077. }
  3078. // if we still have not hit it, then the entire thing is a host.
  3079. if (hostEnd === -1)
  3080. { hostEnd = rest.length; }
  3081. this.host = rest.slice(0, hostEnd);
  3082. rest = rest.slice(hostEnd);
  3083. // pull out port.
  3084. this.parseHost();
  3085. // we've indicated that there is a hostname,
  3086. // so even if it's empty, it has to be present.
  3087. this.hostname = this.hostname || '';
  3088. // if hostname begins with [ and ends with ]
  3089. // assume that it's an IPv6 address.
  3090. var ipv6Hostname = this.hostname[0] === '[' &&
  3091. this.hostname[this.hostname.length - 1] === ']';
  3092. // validate a little.
  3093. if (!ipv6Hostname) {
  3094. var hostparts = this.hostname.split(/\./);
  3095. for (var i = 0, l = hostparts.length; i < l; i++) {
  3096. var part = hostparts[i];
  3097. if (!part) { continue; }
  3098. if (!part.match(hostnamePartPattern)) {
  3099. var newpart = '';
  3100. for (var j = 0, k = part.length; j < k; j++) {
  3101. if (part.charCodeAt(j) > 127) {
  3102. // we replace non-ASCII char with a temporary placeholder
  3103. // we need this to make sure size of hostname is not
  3104. // broken by replacing non-ASCII by nothing
  3105. newpart += 'x';
  3106. } else {
  3107. newpart += part[j];
  3108. }
  3109. }
  3110. // we test again with ASCII char only
  3111. if (!newpart.match(hostnamePartPattern)) {
  3112. var validParts = hostparts.slice(0, i);
  3113. var notHost = hostparts.slice(i + 1);
  3114. var bit = part.match(hostnamePartStart);
  3115. if (bit) {
  3116. validParts.push(bit[1]);
  3117. notHost.unshift(bit[2]);
  3118. }
  3119. if (notHost.length) {
  3120. rest = '/' + notHost.join('.') + rest;
  3121. }
  3122. this.hostname = validParts.join('.');
  3123. break;
  3124. }
  3125. }
  3126. }
  3127. }
  3128. if (this.hostname.length > hostnameMaxLen) {
  3129. this.hostname = '';
  3130. } else {
  3131. // hostnames are always lower case.
  3132. this.hostname = this.hostname.toLowerCase();
  3133. }
  3134. if (!ipv6Hostname) {
  3135. // IDNA Support: Returns a punycoded representation of "domain".
  3136. // It only converts parts of the domain name that
  3137. // have non-ASCII characters, i.e. it doesn't matter if
  3138. // you call it with a domain that already is ASCII-only.
  3139. this.hostname = punycode.toASCII(this.hostname);
  3140. }
  3141. var p = this.port ? ':' + this.port : '';
  3142. var h = this.hostname || '';
  3143. this.host = h + p;
  3144. this.href += this.host;
  3145. // strip [ and ] from the hostname
  3146. // the host field still retains them, though
  3147. if (ipv6Hostname) {
  3148. this.hostname = this.hostname.substr(1, this.hostname.length - 2);
  3149. if (rest[0] !== '/') {
  3150. rest = '/' + rest;
  3151. }
  3152. }
  3153. }
  3154. // now rest is set to the post-host stuff.
  3155. // chop off any delim chars.
  3156. if (!unsafeProtocol[lowerProto]) {
  3157. // First, make 100% sure that any "autoEscape" chars get
  3158. // escaped, even if encodeURIComponent doesn't think they
  3159. // need to be.
  3160. for (var i = 0, l = autoEscape.length; i < l; i++) {
  3161. var ae = autoEscape[i];
  3162. if (rest.indexOf(ae) === -1)
  3163. { continue; }
  3164. var esc = encodeURIComponent(ae);
  3165. if (esc === ae) {
  3166. esc = escape(ae);
  3167. }
  3168. rest = rest.split(ae).join(esc);
  3169. }
  3170. }
  3171. // chop off from the tail first.
  3172. var hash = rest.indexOf('#');
  3173. if (hash !== -1) {
  3174. // got a fragment string.
  3175. this.hash = rest.substr(hash);
  3176. rest = rest.slice(0, hash);
  3177. }
  3178. var qm = rest.indexOf('?');
  3179. if (qm !== -1) {
  3180. this.search = rest.substr(qm);
  3181. this.query = rest.substr(qm + 1);
  3182. if (parseQueryString) {
  3183. this.query = querystring.parse(this.query);
  3184. }
  3185. rest = rest.slice(0, qm);
  3186. } else if (parseQueryString) {
  3187. // no query string, but parseQueryString still requested
  3188. this.search = '';
  3189. this.query = {};
  3190. }
  3191. if (rest) { this.pathname = rest; }
  3192. if (slashedProtocol[lowerProto] &&
  3193. this.hostname && !this.pathname) {
  3194. this.pathname = '/';
  3195. }
  3196. //to support http.request
  3197. if (this.pathname || this.search) {
  3198. var p = this.pathname || '';
  3199. var s = this.search || '';
  3200. this.path = p + s;
  3201. }
  3202. // finally, reconstruct the href based on what has been validated.
  3203. this.href = this.format();
  3204. return this;
  3205. };
  3206. // format a parsed object into a url string
  3207. function urlFormat(obj) {
  3208. // ensure it's an object, and not a string url.
  3209. // If it's an obj, this is a no-op.
  3210. // this way, you can call url_format() on strings
  3211. // to clean up potentially wonky urls.
  3212. if (util.isString(obj)) { obj = urlParse(obj); }
  3213. if (!(obj instanceof Url)) { return Url.prototype.format.call(obj); }
  3214. return obj.format();
  3215. }
  3216. Url.prototype.format = function() {
  3217. var auth = this.auth || '';
  3218. if (auth) {
  3219. auth = encodeURIComponent(auth);
  3220. auth = auth.replace(/%3A/i, ':');
  3221. auth += '@';
  3222. }
  3223. var protocol = this.protocol || '',
  3224. pathname = this.pathname || '',
  3225. hash = this.hash || '',
  3226. host = false,
  3227. query = '';
  3228. if (this.host) {
  3229. host = auth + this.host;
  3230. } else if (this.hostname) {
  3231. host = auth + (this.hostname.indexOf(':') === -1 ?
  3232. this.hostname :
  3233. '[' + this.hostname + ']');
  3234. if (this.port) {
  3235. host += ':' + this.port;
  3236. }
  3237. }
  3238. if (this.query &&
  3239. util.isObject(this.query) &&
  3240. Object.keys(this.query).length) {
  3241. query = querystring.stringify(this.query);
  3242. }
  3243. var search = this.search || (query && ('?' + query)) || '';
  3244. if (protocol && protocol.substr(-1) !== ':') { protocol += ':'; }
  3245. // only the slashedProtocols get the //. Not mailto:, xmpp:, etc.
  3246. // unless they had them to begin with.
  3247. if (this.slashes ||
  3248. (!protocol || slashedProtocol[protocol]) && host !== false) {
  3249. host = '//' + (host || '');
  3250. if (pathname && pathname.charAt(0) !== '/') { pathname = '/' + pathname; }
  3251. } else if (!host) {
  3252. host = '';
  3253. }
  3254. if (hash && hash.charAt(0) !== '#') { hash = '#' + hash; }
  3255. if (search && search.charAt(0) !== '?') { search = '?' + search; }
  3256. pathname = pathname.replace(/[?#]/g, function(match) {
  3257. return encodeURIComponent(match);
  3258. });
  3259. search = search.replace('#', '%23');
  3260. return protocol + host + pathname + search + hash;
  3261. };
  3262. function urlResolve(source, relative) {
  3263. return urlParse(source, false, true).resolve(relative);
  3264. }
  3265. Url.prototype.resolve = function(relative) {
  3266. return this.resolveObject(urlParse(relative, false, true)).format();
  3267. };
  3268. function urlResolveObject(source, relative) {
  3269. if (!source) { return relative; }
  3270. return urlParse(source, false, true).resolveObject(relative);
  3271. }
  3272. Url.prototype.resolveObject = function(relative) {
  3273. if (util.isString(relative)) {
  3274. var rel = new Url();
  3275. rel.parse(relative, false, true);
  3276. relative = rel;
  3277. }
  3278. var result = new Url();
  3279. var tkeys = Object.keys(this);
  3280. for (var tk = 0; tk < tkeys.length; tk++) {
  3281. var tkey = tkeys[tk];
  3282. result[tkey] = this[tkey];
  3283. }
  3284. // hash is always overridden, no matter what.
  3285. // even href="" will remove it.
  3286. result.hash = relative.hash;
  3287. // if the relative url is empty, then there's nothing left to do here.
  3288. if (relative.href === '') {
  3289. result.href = result.format();
  3290. return result;
  3291. }
  3292. // hrefs like //foo/bar always cut to the protocol.
  3293. if (relative.slashes && !relative.protocol) {
  3294. // take everything except the protocol from relative
  3295. var rkeys = Object.keys(relative);
  3296. for (var rk = 0; rk < rkeys.length; rk++) {
  3297. var rkey = rkeys[rk];
  3298. if (rkey !== 'protocol')
  3299. { result[rkey] = relative[rkey]; }
  3300. }
  3301. //urlParse appends trailing / to urls like http://www.example.com
  3302. if (slashedProtocol[result.protocol] &&
  3303. result.hostname && !result.pathname) {
  3304. result.path = result.pathname = '/';
  3305. }
  3306. result.href = result.format();
  3307. return result;
  3308. }
  3309. if (relative.protocol && relative.protocol !== result.protocol) {
  3310. // if it's a known url protocol, then changing
  3311. // the protocol does weird things
  3312. // first, if it's not file:, then we MUST have a host,
  3313. // and if there was a path
  3314. // to begin with, then we MUST have a path.
  3315. // if it is file:, then the host is dropped,
  3316. // because that's known to be hostless.
  3317. // anything else is assumed to be absolute.
  3318. if (!slashedProtocol[relative.protocol]) {
  3319. var keys = Object.keys(relative);
  3320. for (var v = 0; v < keys.length; v++) {
  3321. var k = keys[v];
  3322. result[k] = relative[k];
  3323. }
  3324. result.href = result.format();
  3325. return result;
  3326. }
  3327. result.protocol = relative.protocol;
  3328. if (!relative.host && !hostlessProtocol[relative.protocol]) {
  3329. var relPath = (relative.pathname || '').split('/');
  3330. while (relPath.length && !(relative.host = relPath.shift())){ ; }
  3331. if (!relative.host) { relative.host = ''; }
  3332. if (!relative.hostname) { relative.hostname = ''; }
  3333. if (relPath[0] !== '') { relPath.unshift(''); }
  3334. if (relPath.length < 2) { relPath.unshift(''); }
  3335. result.pathname = relPath.join('/');
  3336. } else {
  3337. result.pathname = relative.pathname;
  3338. }
  3339. result.search = relative.search;
  3340. result.query = relative.query;
  3341. result.host = relative.host || '';
  3342. result.auth = relative.auth;
  3343. result.hostname = relative.hostname || relative.host;
  3344. result.port = relative.port;
  3345. // to support http.request
  3346. if (result.pathname || result.search) {
  3347. var p = result.pathname || '';
  3348. var s = result.search || '';
  3349. result.path = p + s;
  3350. }
  3351. result.slashes = result.slashes || relative.slashes;
  3352. result.href = result.format();
  3353. return result;
  3354. }
  3355. var isSourceAbs = (result.pathname && result.pathname.charAt(0) === '/'),
  3356. isRelAbs = (
  3357. relative.host ||
  3358. relative.pathname && relative.pathname.charAt(0) === '/'
  3359. ),
  3360. mustEndAbs = (isRelAbs || isSourceAbs ||
  3361. (result.host && relative.pathname)),
  3362. removeAllDots = mustEndAbs,
  3363. srcPath = result.pathname && result.pathname.split('/') || [],
  3364. relPath = relative.pathname && relative.pathname.split('/') || [],
  3365. psychotic = result.protocol && !slashedProtocol[result.protocol];
  3366. // if the url is a non-slashed url, then relative
  3367. // links like ../.. should be able
  3368. // to crawl up to the hostname, as well. This is strange.
  3369. // result.protocol has already been set by now.
  3370. // Later on, put the first path part into the host field.
  3371. if (psychotic) {
  3372. result.hostname = '';
  3373. result.port = null;
  3374. if (result.host) {
  3375. if (srcPath[0] === '') { srcPath[0] = result.host; }
  3376. else { srcPath.unshift(result.host); }
  3377. }
  3378. result.host = '';
  3379. if (relative.protocol) {
  3380. relative.hostname = null;
  3381. relative.port = null;
  3382. if (relative.host) {
  3383. if (relPath[0] === '') { relPath[0] = relative.host; }
  3384. else { relPath.unshift(relative.host); }
  3385. }
  3386. relative.host = null;
  3387. }
  3388. mustEndAbs = mustEndAbs && (relPath[0] === '' || srcPath[0] === '');
  3389. }
  3390. if (isRelAbs) {
  3391. // it's absolute.
  3392. result.host = (relative.host || relative.host === '') ?
  3393. relative.host : result.host;
  3394. result.hostname = (relative.hostname || relative.hostname === '') ?
  3395. relative.hostname : result.hostname;
  3396. result.search = relative.search;
  3397. result.query = relative.query;
  3398. srcPath = relPath;
  3399. // fall through to the dot-handling below.
  3400. } else if (relPath.length) {
  3401. // it's relative
  3402. // throw away the existing file, and take the new path instead.
  3403. if (!srcPath) { srcPath = []; }
  3404. srcPath.pop();
  3405. srcPath = srcPath.concat(relPath);
  3406. result.search = relative.search;
  3407. result.query = relative.query;
  3408. } else if (!util.isNullOrUndefined(relative.search)) {
  3409. // just pull out the search.
  3410. // like href='?foo'.
  3411. // Put this after the other two cases because it simplifies the booleans
  3412. if (psychotic) {
  3413. result.hostname = result.host = srcPath.shift();
  3414. //occationaly the auth can get stuck only in host
  3415. //this especially happens in cases like
  3416. //url.resolveObject('mailto:local1@domain1', 'local2@domain2')
  3417. var authInHost = result.host && result.host.indexOf('@') > 0 ?
  3418. result.host.split('@') : false;
  3419. if (authInHost) {
  3420. result.auth = authInHost.shift();
  3421. result.host = result.hostname = authInHost.shift();
  3422. }
  3423. }
  3424. result.search = relative.search;
  3425. result.query = relative.query;
  3426. //to support http.request
  3427. if (!util.isNull(result.pathname) || !util.isNull(result.search)) {
  3428. result.path = (result.pathname ? result.pathname : '') +
  3429. (result.search ? result.search : '');
  3430. }
  3431. result.href = result.format();
  3432. return result;
  3433. }
  3434. if (!srcPath.length) {
  3435. // no path at all. easy.
  3436. // we've already handled the other stuff above.
  3437. result.pathname = null;
  3438. //to support http.request
  3439. if (result.search) {
  3440. result.path = '/' + result.search;
  3441. } else {
  3442. result.path = null;
  3443. }
  3444. result.href = result.format();
  3445. return result;
  3446. }
  3447. // if a url ENDs in . or .., then it must get a trailing slash.
  3448. // however, if it ends in anything else non-slashy,
  3449. // then it must NOT get a trailing slash.
  3450. var last = srcPath.slice(-1)[0];
  3451. var hasTrailingSlash = (
  3452. (result.host || relative.host || srcPath.length > 1) &&
  3453. (last === '.' || last === '..') || last === '');
  3454. // strip single dots, resolve double dots to parent dir
  3455. // if the path tries to go above the root, `up` ends up > 0
  3456. var up = 0;
  3457. for (var i = srcPath.length; i >= 0; i--) {
  3458. last = srcPath[i];
  3459. if (last === '.') {
  3460. srcPath.splice(i, 1);
  3461. } else if (last === '..') {
  3462. srcPath.splice(i, 1);
  3463. up++;
  3464. } else if (up) {
  3465. srcPath.splice(i, 1);
  3466. up--;
  3467. }
  3468. }
  3469. // if the path is allowed to go above the root, restore leading ..s
  3470. if (!mustEndAbs && !removeAllDots) {
  3471. for (; up--; up) {
  3472. srcPath.unshift('..');
  3473. }
  3474. }
  3475. if (mustEndAbs && srcPath[0] !== '' &&
  3476. (!srcPath[0] || srcPath[0].charAt(0) !== '/')) {
  3477. srcPath.unshift('');
  3478. }
  3479. if (hasTrailingSlash && (srcPath.join('/').substr(-1) !== '/')) {
  3480. srcPath.push('');
  3481. }
  3482. var isAbsolute = srcPath[0] === '' ||
  3483. (srcPath[0] && srcPath[0].charAt(0) === '/');
  3484. // put the host back
  3485. if (psychotic) {
  3486. result.hostname = result.host = isAbsolute ? '' :
  3487. srcPath.length ? srcPath.shift() : '';
  3488. //occationaly the auth can get stuck only in host
  3489. //this especially happens in cases like
  3490. //url.resolveObject('mailto:local1@domain1', 'local2@domain2')
  3491. var authInHost = result.host && result.host.indexOf('@') > 0 ?
  3492. result.host.split('@') : false;
  3493. if (authInHost) {
  3494. result.auth = authInHost.shift();
  3495. result.host = result.hostname = authInHost.shift();
  3496. }
  3497. }
  3498. mustEndAbs = mustEndAbs || (result.host && srcPath.length);
  3499. if (mustEndAbs && !isAbsolute) {
  3500. srcPath.unshift('');
  3501. }
  3502. if (!srcPath.length) {
  3503. result.pathname = null;
  3504. result.path = null;
  3505. } else {
  3506. result.pathname = srcPath.join('/');
  3507. }
  3508. //to support request.http
  3509. if (!util.isNull(result.pathname) || !util.isNull(result.search)) {
  3510. result.path = (result.pathname ? result.pathname : '') +
  3511. (result.search ? result.search : '');
  3512. }
  3513. result.auth = relative.auth || result.auth;
  3514. result.slashes = result.slashes || relative.slashes;
  3515. result.href = result.format();
  3516. return result;
  3517. };
  3518. Url.prototype.parseHost = function() {
  3519. var host = this.host;
  3520. var port = portPattern.exec(host);
  3521. if (port) {
  3522. port = port[0];
  3523. if (port !== ':') {
  3524. this.port = port.substr(1);
  3525. }
  3526. host = host.substr(0, host.length - port.length);
  3527. }
  3528. if (host) { this.hostname = host; }
  3529. };
  3530. var url = {
  3531. parse: parse,
  3532. resolve: resolve$1,
  3533. resolveObject: resolveObject,
  3534. format: format,
  3535. Url: Url_1
  3536. };
  3537. /*!
  3538. * @pixi/constants - v6.1.2
  3539. * Compiled Thu, 12 Aug 2021 17:11:19 UTC
  3540. *
  3541. * @pixi/constants is licensed under the MIT License.
  3542. * http://www.opensource.org/licenses/mit-license
  3543. */
  3544. /**
  3545. * Different types of environments for WebGL.
  3546. *
  3547. * @static
  3548. * @memberof PIXI
  3549. * @name ENV
  3550. * @enum {number}
  3551. * @property {number} WEBGL_LEGACY - Used for older v1 WebGL devices. PixiJS will aim to ensure compatibility
  3552. * with older / less advanced devices. If you experience unexplained flickering prefer this environment.
  3553. * @property {number} WEBGL - Version 1 of WebGL
  3554. * @property {number} WEBGL2 - Version 2 of WebGL
  3555. */
  3556. (function (ENV) {
  3557. ENV[ENV["WEBGL_LEGACY"] = 0] = "WEBGL_LEGACY";
  3558. ENV[ENV["WEBGL"] = 1] = "WEBGL";
  3559. ENV[ENV["WEBGL2"] = 2] = "WEBGL2";
  3560. })(exports.ENV || (exports.ENV = {}));
  3561. /**
  3562. * Constant to identify the Renderer Type.
  3563. *
  3564. * @static
  3565. * @memberof PIXI
  3566. * @name RENDERER_TYPE
  3567. * @enum {number}
  3568. * @property {number} UNKNOWN - Unknown render type.
  3569. * @property {number} WEBGL - WebGL render type.
  3570. * @property {number} CANVAS - Canvas render type.
  3571. */
  3572. (function (RENDERER_TYPE) {
  3573. RENDERER_TYPE[RENDERER_TYPE["UNKNOWN"] = 0] = "UNKNOWN";
  3574. RENDERER_TYPE[RENDERER_TYPE["WEBGL"] = 1] = "WEBGL";
  3575. RENDERER_TYPE[RENDERER_TYPE["CANVAS"] = 2] = "CANVAS";
  3576. })(exports.RENDERER_TYPE || (exports.RENDERER_TYPE = {}));
  3577. /**
  3578. * Bitwise OR of masks that indicate the buffers to be cleared.
  3579. *
  3580. * @static
  3581. * @memberof PIXI
  3582. * @name BUFFER_BITS
  3583. * @enum {number}
  3584. * @property {number} COLOR - Indicates the buffers currently enabled for color writing.
  3585. * @property {number} DEPTH - Indicates the depth buffer.
  3586. * @property {number} STENCIL - Indicates the stencil buffer.
  3587. */
  3588. (function (BUFFER_BITS) {
  3589. BUFFER_BITS[BUFFER_BITS["COLOR"] = 16384] = "COLOR";
  3590. BUFFER_BITS[BUFFER_BITS["DEPTH"] = 256] = "DEPTH";
  3591. BUFFER_BITS[BUFFER_BITS["STENCIL"] = 1024] = "STENCIL";
  3592. })(exports.BUFFER_BITS || (exports.BUFFER_BITS = {}));
  3593. /**
  3594. * Various blend modes supported by PIXI.
  3595. *
  3596. * IMPORTANT - The WebGL renderer only supports the NORMAL, ADD, MULTIPLY and SCREEN blend modes.
  3597. * Anything else will silently act like NORMAL.
  3598. *
  3599. * @memberof PIXI
  3600. * @name BLEND_MODES
  3601. * @enum {number}
  3602. * @property {number} NORMAL
  3603. * @property {number} ADD
  3604. * @property {number} MULTIPLY
  3605. * @property {number} SCREEN
  3606. * @property {number} OVERLAY
  3607. * @property {number} DARKEN
  3608. * @property {number} LIGHTEN
  3609. * @property {number} COLOR_DODGE
  3610. * @property {number} COLOR_BURN
  3611. * @property {number} HARD_LIGHT
  3612. * @property {number} SOFT_LIGHT
  3613. * @property {number} DIFFERENCE
  3614. * @property {number} EXCLUSION
  3615. * @property {number} HUE
  3616. * @property {number} SATURATION
  3617. * @property {number} COLOR
  3618. * @property {number} LUMINOSITY
  3619. * @property {number} NORMAL_NPM
  3620. * @property {number} ADD_NPM
  3621. * @property {number} SCREEN_NPM
  3622. * @property {number} NONE
  3623. * @property {number} SRC_IN
  3624. * @property {number} SRC_OUT
  3625. * @property {number} SRC_ATOP
  3626. * @property {number} DST_OVER
  3627. * @property {number} DST_IN
  3628. * @property {number} DST_OUT
  3629. * @property {number} DST_ATOP
  3630. * @property {number} SUBTRACT
  3631. * @property {number} SRC_OVER
  3632. * @property {number} ERASE
  3633. * @property {number} XOR
  3634. */
  3635. (function (BLEND_MODES) {
  3636. BLEND_MODES[BLEND_MODES["NORMAL"] = 0] = "NORMAL";
  3637. BLEND_MODES[BLEND_MODES["ADD"] = 1] = "ADD";
  3638. BLEND_MODES[BLEND_MODES["MULTIPLY"] = 2] = "MULTIPLY";
  3639. BLEND_MODES[BLEND_MODES["SCREEN"] = 3] = "SCREEN";
  3640. BLEND_MODES[BLEND_MODES["OVERLAY"] = 4] = "OVERLAY";
  3641. BLEND_MODES[BLEND_MODES["DARKEN"] = 5] = "DARKEN";
  3642. BLEND_MODES[BLEND_MODES["LIGHTEN"] = 6] = "LIGHTEN";
  3643. BLEND_MODES[BLEND_MODES["COLOR_DODGE"] = 7] = "COLOR_DODGE";
  3644. BLEND_MODES[BLEND_MODES["COLOR_BURN"] = 8] = "COLOR_BURN";
  3645. BLEND_MODES[BLEND_MODES["HARD_LIGHT"] = 9] = "HARD_LIGHT";
  3646. BLEND_MODES[BLEND_MODES["SOFT_LIGHT"] = 10] = "SOFT_LIGHT";
  3647. BLEND_MODES[BLEND_MODES["DIFFERENCE"] = 11] = "DIFFERENCE";
  3648. BLEND_MODES[BLEND_MODES["EXCLUSION"] = 12] = "EXCLUSION";
  3649. BLEND_MODES[BLEND_MODES["HUE"] = 13] = "HUE";
  3650. BLEND_MODES[BLEND_MODES["SATURATION"] = 14] = "SATURATION";
  3651. BLEND_MODES[BLEND_MODES["COLOR"] = 15] = "COLOR";
  3652. BLEND_MODES[BLEND_MODES["LUMINOSITY"] = 16] = "LUMINOSITY";
  3653. BLEND_MODES[BLEND_MODES["NORMAL_NPM"] = 17] = "NORMAL_NPM";
  3654. BLEND_MODES[BLEND_MODES["ADD_NPM"] = 18] = "ADD_NPM";
  3655. BLEND_MODES[BLEND_MODES["SCREEN_NPM"] = 19] = "SCREEN_NPM";
  3656. BLEND_MODES[BLEND_MODES["NONE"] = 20] = "NONE";
  3657. BLEND_MODES[BLEND_MODES["SRC_OVER"] = 0] = "SRC_OVER";
  3658. BLEND_MODES[BLEND_MODES["SRC_IN"] = 21] = "SRC_IN";
  3659. BLEND_MODES[BLEND_MODES["SRC_OUT"] = 22] = "SRC_OUT";
  3660. BLEND_MODES[BLEND_MODES["SRC_ATOP"] = 23] = "SRC_ATOP";
  3661. BLEND_MODES[BLEND_MODES["DST_OVER"] = 24] = "DST_OVER";
  3662. BLEND_MODES[BLEND_MODES["DST_IN"] = 25] = "DST_IN";
  3663. BLEND_MODES[BLEND_MODES["DST_OUT"] = 26] = "DST_OUT";
  3664. BLEND_MODES[BLEND_MODES["DST_ATOP"] = 27] = "DST_ATOP";
  3665. BLEND_MODES[BLEND_MODES["ERASE"] = 26] = "ERASE";
  3666. BLEND_MODES[BLEND_MODES["SUBTRACT"] = 28] = "SUBTRACT";
  3667. BLEND_MODES[BLEND_MODES["XOR"] = 29] = "XOR";
  3668. })(exports.BLEND_MODES || (exports.BLEND_MODES = {}));
  3669. /**
  3670. * Various webgl draw modes. These can be used to specify which GL drawMode to use
  3671. * under certain situations and renderers.
  3672. *
  3673. * @memberof PIXI
  3674. * @static
  3675. * @name DRAW_MODES
  3676. * @enum {number}
  3677. * @property {number} POINTS
  3678. * @property {number} LINES
  3679. * @property {number} LINE_LOOP
  3680. * @property {number} LINE_STRIP
  3681. * @property {number} TRIANGLES
  3682. * @property {number} TRIANGLE_STRIP
  3683. * @property {number} TRIANGLE_FAN
  3684. */
  3685. (function (DRAW_MODES) {
  3686. DRAW_MODES[DRAW_MODES["POINTS"] = 0] = "POINTS";
  3687. DRAW_MODES[DRAW_MODES["LINES"] = 1] = "LINES";
  3688. DRAW_MODES[DRAW_MODES["LINE_LOOP"] = 2] = "LINE_LOOP";
  3689. DRAW_MODES[DRAW_MODES["LINE_STRIP"] = 3] = "LINE_STRIP";
  3690. DRAW_MODES[DRAW_MODES["TRIANGLES"] = 4] = "TRIANGLES";
  3691. DRAW_MODES[DRAW_MODES["TRIANGLE_STRIP"] = 5] = "TRIANGLE_STRIP";
  3692. DRAW_MODES[DRAW_MODES["TRIANGLE_FAN"] = 6] = "TRIANGLE_FAN";
  3693. })(exports.DRAW_MODES || (exports.DRAW_MODES = {}));
  3694. /**
  3695. * Various GL texture/resources formats.
  3696. *
  3697. * @memberof PIXI
  3698. * @static
  3699. * @name FORMATS
  3700. * @enum {number}
  3701. * @property {number} RGBA=6408
  3702. * @property {number} RGB=6407
  3703. * @property {number} RG=33319
  3704. * @property {number} RED=6403
  3705. * @property {number} RGBA_INTEGER=36249
  3706. * @property {number} RGB_INTEGER=36248
  3707. * @property {number} RG_INTEGER=33320
  3708. * @property {number} RED_INTEGER=36244
  3709. * @property {number} ALPHA=6406
  3710. * @property {number} LUMINANCE=6409
  3711. * @property {number} LUMINANCE_ALPHA=6410
  3712. * @property {number} DEPTH_COMPONENT=6402
  3713. * @property {number} DEPTH_STENCIL=34041
  3714. */
  3715. (function (FORMATS) {
  3716. FORMATS[FORMATS["RGBA"] = 6408] = "RGBA";
  3717. FORMATS[FORMATS["RGB"] = 6407] = "RGB";
  3718. FORMATS[FORMATS["RG"] = 33319] = "RG";
  3719. FORMATS[FORMATS["RED"] = 6403] = "RED";
  3720. FORMATS[FORMATS["RGBA_INTEGER"] = 36249] = "RGBA_INTEGER";
  3721. FORMATS[FORMATS["RGB_INTEGER"] = 36248] = "RGB_INTEGER";
  3722. FORMATS[FORMATS["RG_INTEGER"] = 33320] = "RG_INTEGER";
  3723. FORMATS[FORMATS["RED_INTEGER"] = 36244] = "RED_INTEGER";
  3724. FORMATS[FORMATS["ALPHA"] = 6406] = "ALPHA";
  3725. FORMATS[FORMATS["LUMINANCE"] = 6409] = "LUMINANCE";
  3726. FORMATS[FORMATS["LUMINANCE_ALPHA"] = 6410] = "LUMINANCE_ALPHA";
  3727. FORMATS[FORMATS["DEPTH_COMPONENT"] = 6402] = "DEPTH_COMPONENT";
  3728. FORMATS[FORMATS["DEPTH_STENCIL"] = 34041] = "DEPTH_STENCIL";
  3729. })(exports.FORMATS || (exports.FORMATS = {}));
  3730. /**
  3731. * Various GL target types.
  3732. *
  3733. * @memberof PIXI
  3734. * @static
  3735. * @name TARGETS
  3736. * @enum {number}
  3737. * @property {number} TEXTURE_2D=3553
  3738. * @property {number} TEXTURE_CUBE_MAP=34067
  3739. * @property {number} TEXTURE_2D_ARRAY=35866
  3740. * @property {number} TEXTURE_CUBE_MAP_POSITIVE_X=34069
  3741. * @property {number} TEXTURE_CUBE_MAP_NEGATIVE_X=34070
  3742. * @property {number} TEXTURE_CUBE_MAP_POSITIVE_Y=34071
  3743. * @property {number} TEXTURE_CUBE_MAP_NEGATIVE_Y=34072
  3744. * @property {number} TEXTURE_CUBE_MAP_POSITIVE_Z=34073
  3745. * @property {number} TEXTURE_CUBE_MAP_NEGATIVE_Z=34074
  3746. */
  3747. (function (TARGETS) {
  3748. TARGETS[TARGETS["TEXTURE_2D"] = 3553] = "TEXTURE_2D";
  3749. TARGETS[TARGETS["TEXTURE_CUBE_MAP"] = 34067] = "TEXTURE_CUBE_MAP";
  3750. TARGETS[TARGETS["TEXTURE_2D_ARRAY"] = 35866] = "TEXTURE_2D_ARRAY";
  3751. TARGETS[TARGETS["TEXTURE_CUBE_MAP_POSITIVE_X"] = 34069] = "TEXTURE_CUBE_MAP_POSITIVE_X";
  3752. TARGETS[TARGETS["TEXTURE_CUBE_MAP_NEGATIVE_X"] = 34070] = "TEXTURE_CUBE_MAP_NEGATIVE_X";
  3753. TARGETS[TARGETS["TEXTURE_CUBE_MAP_POSITIVE_Y"] = 34071] = "TEXTURE_CUBE_MAP_POSITIVE_Y";
  3754. TARGETS[TARGETS["TEXTURE_CUBE_MAP_NEGATIVE_Y"] = 34072] = "TEXTURE_CUBE_MAP_NEGATIVE_Y";
  3755. TARGETS[TARGETS["TEXTURE_CUBE_MAP_POSITIVE_Z"] = 34073] = "TEXTURE_CUBE_MAP_POSITIVE_Z";
  3756. TARGETS[TARGETS["TEXTURE_CUBE_MAP_NEGATIVE_Z"] = 34074] = "TEXTURE_CUBE_MAP_NEGATIVE_Z";
  3757. })(exports.TARGETS || (exports.TARGETS = {}));
  3758. /**
  3759. * Various GL data format types.
  3760. *
  3761. * @memberof PIXI
  3762. * @static
  3763. * @name TYPES
  3764. * @enum {number}
  3765. * @property {number} UNSIGNED_BYTE=5121
  3766. * @property {number} UNSIGNED_SHORT=5123
  3767. * @property {number} UNSIGNED_SHORT_5_6_5=33635
  3768. * @property {number} UNSIGNED_SHORT_4_4_4_4=32819
  3769. * @property {number} UNSIGNED_SHORT_5_5_5_1=32820
  3770. * @property {number} UNSIGNED_INT=5125
  3771. * @property {number} UNSIGNED_INT_10F_11F_11F_REV=35899
  3772. * @property {number} UNSIGNED_INT_2_10_10_10_REV=33640
  3773. * @property {number} UNSIGNED_INT_24_8=34042
  3774. * @property {number} UNSIGNED_INT_5_9_9_9_REV=35902
  3775. * @property {number} BYTE=5120
  3776. * @property {number} SHORT=5122
  3777. * @property {number} INT=5124
  3778. * @property {number} FLOAT=5126
  3779. * @property {number} FLOAT_32_UNSIGNED_INT_24_8_REV=36269
  3780. * @property {number} HALF_FLOAT=36193
  3781. */
  3782. (function (TYPES) {
  3783. TYPES[TYPES["UNSIGNED_BYTE"] = 5121] = "UNSIGNED_BYTE";
  3784. TYPES[TYPES["UNSIGNED_SHORT"] = 5123] = "UNSIGNED_SHORT";
  3785. TYPES[TYPES["UNSIGNED_SHORT_5_6_5"] = 33635] = "UNSIGNED_SHORT_5_6_5";
  3786. TYPES[TYPES["UNSIGNED_SHORT_4_4_4_4"] = 32819] = "UNSIGNED_SHORT_4_4_4_4";
  3787. TYPES[TYPES["UNSIGNED_SHORT_5_5_5_1"] = 32820] = "UNSIGNED_SHORT_5_5_5_1";
  3788. TYPES[TYPES["UNSIGNED_INT"] = 5125] = "UNSIGNED_INT";
  3789. TYPES[TYPES["UNSIGNED_INT_10F_11F_11F_REV"] = 35899] = "UNSIGNED_INT_10F_11F_11F_REV";
  3790. TYPES[TYPES["UNSIGNED_INT_2_10_10_10_REV"] = 33640] = "UNSIGNED_INT_2_10_10_10_REV";
  3791. TYPES[TYPES["UNSIGNED_INT_24_8"] = 34042] = "UNSIGNED_INT_24_8";
  3792. TYPES[TYPES["UNSIGNED_INT_5_9_9_9_REV"] = 35902] = "UNSIGNED_INT_5_9_9_9_REV";
  3793. TYPES[TYPES["BYTE"] = 5120] = "BYTE";
  3794. TYPES[TYPES["SHORT"] = 5122] = "SHORT";
  3795. TYPES[TYPES["INT"] = 5124] = "INT";
  3796. TYPES[TYPES["FLOAT"] = 5126] = "FLOAT";
  3797. TYPES[TYPES["FLOAT_32_UNSIGNED_INT_24_8_REV"] = 36269] = "FLOAT_32_UNSIGNED_INT_24_8_REV";
  3798. TYPES[TYPES["HALF_FLOAT"] = 36193] = "HALF_FLOAT";
  3799. })(exports.TYPES || (exports.TYPES = {}));
  3800. /**
  3801. * Various sampler types. Correspond to `sampler`, `isampler`, `usampler` GLSL types respectively.
  3802. * WebGL1 works only with FLOAT.
  3803. *
  3804. * @memberof PIXI
  3805. * @static
  3806. * @name SAMPLER_TYPES
  3807. * @enum {number}
  3808. * @property {number} FLOAT=0
  3809. * @property {number} INT=1
  3810. * @property {number} UINT=2
  3811. */
  3812. (function (SAMPLER_TYPES) {
  3813. SAMPLER_TYPES[SAMPLER_TYPES["FLOAT"] = 0] = "FLOAT";
  3814. SAMPLER_TYPES[SAMPLER_TYPES["INT"] = 1] = "INT";
  3815. SAMPLER_TYPES[SAMPLER_TYPES["UINT"] = 2] = "UINT";
  3816. })(exports.SAMPLER_TYPES || (exports.SAMPLER_TYPES = {}));
  3817. /**
  3818. * The scale modes that are supported by pixi.
  3819. *
  3820. * The {@link PIXI.settings.SCALE_MODE} scale mode affects the default scaling mode of future operations.
  3821. * It can be re-assigned to either LINEAR or NEAREST, depending upon suitability.
  3822. *
  3823. * @memberof PIXI
  3824. * @static
  3825. * @name SCALE_MODES
  3826. * @enum {number}
  3827. * @property {number} LINEAR Smooth scaling
  3828. * @property {number} NEAREST Pixelating scaling
  3829. */
  3830. (function (SCALE_MODES) {
  3831. SCALE_MODES[SCALE_MODES["NEAREST"] = 0] = "NEAREST";
  3832. SCALE_MODES[SCALE_MODES["LINEAR"] = 1] = "LINEAR";
  3833. })(exports.SCALE_MODES || (exports.SCALE_MODES = {}));
  3834. /**
  3835. * The wrap modes that are supported by pixi.
  3836. *
  3837. * The {@link PIXI.settings.WRAP_MODE} wrap mode affects the default wrapping mode of future operations.
  3838. * It can be re-assigned to either CLAMP or REPEAT, depending upon suitability.
  3839. * If the texture is non power of two then clamp will be used regardless as WebGL can
  3840. * only use REPEAT if the texture is po2.
  3841. *
  3842. * This property only affects WebGL.
  3843. *
  3844. * @name WRAP_MODES
  3845. * @memberof PIXI
  3846. * @static
  3847. * @enum {number}
  3848. * @property {number} CLAMP - The textures uvs are clamped
  3849. * @property {number} REPEAT - The texture uvs tile and repeat
  3850. * @property {number} MIRRORED_REPEAT - The texture uvs tile and repeat with mirroring
  3851. */
  3852. (function (WRAP_MODES) {
  3853. WRAP_MODES[WRAP_MODES["CLAMP"] = 33071] = "CLAMP";
  3854. WRAP_MODES[WRAP_MODES["REPEAT"] = 10497] = "REPEAT";
  3855. WRAP_MODES[WRAP_MODES["MIRRORED_REPEAT"] = 33648] = "MIRRORED_REPEAT";
  3856. })(exports.WRAP_MODES || (exports.WRAP_MODES = {}));
  3857. /**
  3858. * Mipmap filtering modes that are supported by pixi.
  3859. *
  3860. * The {@link PIXI.settings.MIPMAP_TEXTURES} affects default texture filtering.
  3861. * Mipmaps are generated for a baseTexture if its `mipmap` field is `ON`,
  3862. * or its `POW2` and texture dimensions are powers of 2.
  3863. * Due to platform restriction, `ON` option will work like `POW2` for webgl-1.
  3864. *
  3865. * This property only affects WebGL.
  3866. *
  3867. * @name MIPMAP_MODES
  3868. * @memberof PIXI
  3869. * @static
  3870. * @enum {number}
  3871. * @property {number} OFF - No mipmaps
  3872. * @property {number} POW2 - Generate mipmaps if texture dimensions are pow2
  3873. * @property {number} ON - Always generate mipmaps
  3874. * @property {number} ON_MANUAL - Use mipmaps, but do not auto-generate them; this is used with a resource
  3875. * that supports buffering each level-of-detail.
  3876. */
  3877. (function (MIPMAP_MODES) {
  3878. MIPMAP_MODES[MIPMAP_MODES["OFF"] = 0] = "OFF";
  3879. MIPMAP_MODES[MIPMAP_MODES["POW2"] = 1] = "POW2";
  3880. MIPMAP_MODES[MIPMAP_MODES["ON"] = 2] = "ON";
  3881. MIPMAP_MODES[MIPMAP_MODES["ON_MANUAL"] = 3] = "ON_MANUAL";
  3882. })(exports.MIPMAP_MODES || (exports.MIPMAP_MODES = {}));
  3883. /**
  3884. * How to treat textures with premultiplied alpha
  3885. *
  3886. * @name ALPHA_MODES
  3887. * @memberof PIXI
  3888. * @static
  3889. * @enum {number}
  3890. * @property {number} NO_PREMULTIPLIED_ALPHA - Source is not premultiplied, leave it like that.
  3891. * Option for compressed and data textures that are created from typed arrays.
  3892. * @property {number} PREMULTIPLY_ON_UPLOAD - Source is not premultiplied, premultiply on upload.
  3893. * Default option, used for all loaded images.
  3894. * @property {number} PREMULTIPLIED_ALPHA - Source is already premultiplied
  3895. * Example: spine atlases with `_pma` suffix.
  3896. * @property {number} NPM - Alias for NO_PREMULTIPLIED_ALPHA.
  3897. * @property {number} UNPACK - Default option, alias for PREMULTIPLY_ON_UPLOAD.
  3898. * @property {number} PMA - Alias for PREMULTIPLIED_ALPHA.
  3899. */
  3900. (function (ALPHA_MODES) {
  3901. ALPHA_MODES[ALPHA_MODES["NPM"] = 0] = "NPM";
  3902. ALPHA_MODES[ALPHA_MODES["UNPACK"] = 1] = "UNPACK";
  3903. ALPHA_MODES[ALPHA_MODES["PMA"] = 2] = "PMA";
  3904. ALPHA_MODES[ALPHA_MODES["NO_PREMULTIPLIED_ALPHA"] = 0] = "NO_PREMULTIPLIED_ALPHA";
  3905. ALPHA_MODES[ALPHA_MODES["PREMULTIPLY_ON_UPLOAD"] = 1] = "PREMULTIPLY_ON_UPLOAD";
  3906. ALPHA_MODES[ALPHA_MODES["PREMULTIPLY_ALPHA"] = 2] = "PREMULTIPLY_ALPHA";
  3907. })(exports.ALPHA_MODES || (exports.ALPHA_MODES = {}));
  3908. /**
  3909. * Configure whether filter textures are cleared after binding.
  3910. *
  3911. * Filter textures need not be cleared if the filter does not use pixel blending. {@link CLEAR_MODES.BLIT} will detect
  3912. * this and skip clearing as an optimization.
  3913. *
  3914. * @name CLEAR_MODES
  3915. * @memberof PIXI
  3916. * @static
  3917. * @enum {number}
  3918. * @property {number} BLEND - Do not clear the filter texture. The filter's output will blend on top of the output texture.
  3919. * @property {number} CLEAR - Always clear the filter texture.
  3920. * @property {number} BLIT - Clear only if {@link FilterSystem.forceClear} is set or if the filter uses pixel blending.
  3921. * @property {number} NO - Alias for BLEND, same as `false` in earlier versions
  3922. * @property {number} YES - Alias for CLEAR, same as `true` in earlier versions
  3923. * @property {number} AUTO - Alias for BLIT
  3924. */
  3925. (function (CLEAR_MODES) {
  3926. CLEAR_MODES[CLEAR_MODES["NO"] = 0] = "NO";
  3927. CLEAR_MODES[CLEAR_MODES["YES"] = 1] = "YES";
  3928. CLEAR_MODES[CLEAR_MODES["AUTO"] = 2] = "AUTO";
  3929. CLEAR_MODES[CLEAR_MODES["BLEND"] = 0] = "BLEND";
  3930. CLEAR_MODES[CLEAR_MODES["CLEAR"] = 1] = "CLEAR";
  3931. CLEAR_MODES[CLEAR_MODES["BLIT"] = 2] = "BLIT";
  3932. })(exports.CLEAR_MODES || (exports.CLEAR_MODES = {}));
  3933. /**
  3934. * The gc modes that are supported by pixi.
  3935. *
  3936. * The {@link PIXI.settings.GC_MODE} Garbage Collection mode for PixiJS textures is AUTO
  3937. * If set to GC_MODE, the renderer will occasionally check textures usage. If they are not
  3938. * used for a specified period of time they will be removed from the GPU. They will of course
  3939. * be uploaded again when they are required. This is a silent behind the scenes process that
  3940. * should ensure that the GPU does not get filled up.
  3941. *
  3942. * Handy for mobile devices!
  3943. * This property only affects WebGL.
  3944. *
  3945. * @name GC_MODES
  3946. * @enum {number}
  3947. * @static
  3948. * @memberof PIXI
  3949. * @property {number} AUTO - Garbage collection will happen periodically automatically
  3950. * @property {number} MANUAL - Garbage collection will need to be called manually
  3951. */
  3952. (function (GC_MODES) {
  3953. GC_MODES[GC_MODES["AUTO"] = 0] = "AUTO";
  3954. GC_MODES[GC_MODES["MANUAL"] = 1] = "MANUAL";
  3955. })(exports.GC_MODES || (exports.GC_MODES = {}));
  3956. /**
  3957. * Constants that specify float precision in shaders.
  3958. *
  3959. * @name PRECISION
  3960. * @memberof PIXI
  3961. * @constant
  3962. * @static
  3963. * @enum {string}
  3964. * @property {string} LOW='lowp'
  3965. * @property {string} MEDIUM='mediump'
  3966. * @property {string} HIGH='highp'
  3967. */
  3968. (function (PRECISION) {
  3969. PRECISION["LOW"] = "lowp";
  3970. PRECISION["MEDIUM"] = "mediump";
  3971. PRECISION["HIGH"] = "highp";
  3972. })(exports.PRECISION || (exports.PRECISION = {}));
  3973. /**
  3974. * Constants for mask implementations.
  3975. * We use `type` suffix because it leads to very different behaviours
  3976. *
  3977. * @name MASK_TYPES
  3978. * @memberof PIXI
  3979. * @static
  3980. * @enum {number}
  3981. * @property {number} NONE - Mask is ignored
  3982. * @property {number} SCISSOR - Scissor mask, rectangle on screen, cheap
  3983. * @property {number} STENCIL - Stencil mask, 1-bit, medium, works only if renderer supports stencil
  3984. * @property {number} SPRITE - Mask that uses SpriteMaskFilter, uses temporary RenderTexture
  3985. */
  3986. (function (MASK_TYPES) {
  3987. MASK_TYPES[MASK_TYPES["NONE"] = 0] = "NONE";
  3988. MASK_TYPES[MASK_TYPES["SCISSOR"] = 1] = "SCISSOR";
  3989. MASK_TYPES[MASK_TYPES["STENCIL"] = 2] = "STENCIL";
  3990. MASK_TYPES[MASK_TYPES["SPRITE"] = 3] = "SPRITE";
  3991. })(exports.MASK_TYPES || (exports.MASK_TYPES = {}));
  3992. /**
  3993. * Constants for multi-sampling antialiasing.
  3994. *
  3995. * @see PIXI.Framebuffer#multisample
  3996. *
  3997. * @name MSAA_QUALITY
  3998. * @memberof PIXI
  3999. * @static
  4000. * @enum {number}
  4001. * @property {number} NONE - No multisampling for this renderTexture
  4002. * @property {number} LOW - Try 2 samples
  4003. * @property {number} MEDIUM - Try 4 samples
  4004. * @property {number} HIGH - Try 8 samples
  4005. */
  4006. (function (MSAA_QUALITY) {
  4007. MSAA_QUALITY[MSAA_QUALITY["NONE"] = 0] = "NONE";
  4008. MSAA_QUALITY[MSAA_QUALITY["LOW"] = 2] = "LOW";
  4009. MSAA_QUALITY[MSAA_QUALITY["MEDIUM"] = 4] = "MEDIUM";
  4010. MSAA_QUALITY[MSAA_QUALITY["HIGH"] = 8] = "HIGH";
  4011. })(exports.MSAA_QUALITY || (exports.MSAA_QUALITY = {}));
  4012. /**
  4013. * Constants for various buffer types in Pixi
  4014. *
  4015. * @see PIXI.BUFFER_TYPE
  4016. *
  4017. * @name BUFFER_TYPE
  4018. * @memberof PIXI
  4019. * @static
  4020. * @enum {number}
  4021. * @property {number} ELEMENT_ARRAY_BUFFER - buffer type for using as an index buffer
  4022. * @property {number} ARRAY_BUFFER - buffer type for using attribute data
  4023. * @property {number} UNIFORM_BUFFER - the buffer type is for uniform buffer objects
  4024. */
  4025. (function (BUFFER_TYPE) {
  4026. BUFFER_TYPE[BUFFER_TYPE["ELEMENT_ARRAY_BUFFER"] = 34963] = "ELEMENT_ARRAY_BUFFER";
  4027. BUFFER_TYPE[BUFFER_TYPE["ARRAY_BUFFER"] = 34962] = "ARRAY_BUFFER";
  4028. // NOT YET SUPPORTED
  4029. BUFFER_TYPE[BUFFER_TYPE["UNIFORM_BUFFER"] = 35345] = "UNIFORM_BUFFER";
  4030. })(exports.BUFFER_TYPE || (exports.BUFFER_TYPE = {}));
  4031. /*!
  4032. * @pixi/utils - v6.1.2
  4033. * Compiled Thu, 12 Aug 2021 17:11:19 UTC
  4034. *
  4035. * @pixi/utils is licensed under the MIT License.
  4036. * http://www.opensource.org/licenses/mit-license
  4037. */
  4038. /**
  4039. * This file contains redeclared types for Node `url` and `querystring` modules. These modules
  4040. * don't provide their own typings but instead are a part of the full Node typings. The purpose of
  4041. * this file is to redeclare the required types to avoid having the whole Node types as a
  4042. * dependency.
  4043. */
  4044. var url$1 = {
  4045. parse: parse,
  4046. format: format,
  4047. resolve: resolve$1,
  4048. };
  4049. /**
  4050. * The prefix that denotes a URL is for a retina asset.
  4051. *
  4052. * @static
  4053. * @name RETINA_PREFIX
  4054. * @memberof PIXI.settings
  4055. * @type {RegExp}
  4056. * @default /@([0-9\.]+)x/
  4057. * @example `@2x`
  4058. */
  4059. settings.RETINA_PREFIX = /@([0-9\.]+)x/;
  4060. /**
  4061. * Should the `failIfMajorPerformanceCaveat` flag be enabled as a context option used in the `isWebGLSupported` function.
  4062. * If set to true, a WebGL renderer can fail to be created if the browser thinks there could be performance issues when
  4063. * using WebGL.
  4064. *
  4065. * In PixiJS v6 this has changed from true to false by default, to allow WebGL to work in as many scenarios as possible.
  4066. * However, some users may have a poor experience, for example, if a user has a gpu or driver version blacklisted by the
  4067. * browser.
  4068. *
  4069. * If your application requires high performance rendering, you may wish to set this to false.
  4070. * We recommend one of two options if you decide to set this flag to false:
  4071. *
  4072. * 1: Use the `pixi.js-legacy` package, which includes a Canvas renderer as a fallback in case high performance WebGL is
  4073. * not supported.
  4074. *
  4075. * 2: Call `isWebGLSupported` (which if found in the PIXI.utils package) in your code before attempting to create a PixiJS
  4076. * renderer, and show an error message to the user if the function returns false, explaining that their device & browser
  4077. * combination does not support high performance WebGL.
  4078. * This is a much better strategy than trying to create a PixiJS renderer and finding it then fails.
  4079. *
  4080. * @static
  4081. * @name FAIL_IF_MAJOR_PERFORMANCE_CAVEAT
  4082. * @memberof PIXI.settings
  4083. * @type {boolean}
  4084. * @default false
  4085. */
  4086. settings.FAIL_IF_MAJOR_PERFORMANCE_CAVEAT = false;
  4087. var saidHello = false;
  4088. var VERSION = '6.1.2';
  4089. /**
  4090. * Skips the hello message of renderers that are created after this is run.
  4091. *
  4092. * @function skipHello
  4093. * @memberof PIXI.utils
  4094. */
  4095. function skipHello() {
  4096. saidHello = true;
  4097. }
  4098. /**
  4099. * Logs out the version and renderer information for this running instance of PIXI.
  4100. * If you don't want to see this message you can run `PIXI.utils.skipHello()` before
  4101. * creating your renderer. Keep in mind that doing that will forever make you a jerk face.
  4102. *
  4103. * @static
  4104. * @function sayHello
  4105. * @memberof PIXI.utils
  4106. * @param {string} type - The string renderer type to log.
  4107. */
  4108. function sayHello(type) {
  4109. var _a;
  4110. if (saidHello) {
  4111. return;
  4112. }
  4113. if (navigator.userAgent.toLowerCase().indexOf('chrome') > -1) {
  4114. var args = [
  4115. "\n %c %c %c PixiJS " + VERSION + " - \u2730 " + type + " \u2730 %c %c http://www.pixijs.com/ %c %c \u2665%c\u2665%c\u2665 \n\n",
  4116. 'background: #ff66a5; padding:5px 0;',
  4117. 'background: #ff66a5; padding:5px 0;',
  4118. 'color: #ff66a5; background: #030307; padding:5px 0;',
  4119. 'background: #ff66a5; padding:5px 0;',
  4120. 'background: #ffc3dc; padding:5px 0;',
  4121. 'background: #ff66a5; padding:5px 0;',
  4122. 'color: #ff2424; background: #fff; padding:5px 0;',
  4123. 'color: #ff2424; background: #fff; padding:5px 0;',
  4124. 'color: #ff2424; background: #fff; padding:5px 0;' ];
  4125. (_a = self.console).log.apply(_a, args);
  4126. }
  4127. else if (self.console) {
  4128. self.console.log("PixiJS " + VERSION + " - " + type + " - http://www.pixijs.com/");
  4129. }
  4130. saidHello = true;
  4131. }
  4132. var supported;
  4133. /**
  4134. * Helper for checking for WebGL support.
  4135. *
  4136. * @memberof PIXI.utils
  4137. * @function isWebGLSupported
  4138. * @return {boolean} Is WebGL supported.
  4139. */
  4140. function isWebGLSupported() {
  4141. if (typeof supported === 'undefined') {
  4142. supported = (function supported() {
  4143. var contextOptions = {
  4144. stencil: true,
  4145. failIfMajorPerformanceCaveat: settings.FAIL_IF_MAJOR_PERFORMANCE_CAVEAT,
  4146. };
  4147. try {
  4148. if (!self.WebGLRenderingContext) {
  4149. return false;
  4150. }
  4151. var canvas = document.createElement('canvas');
  4152. var gl = (canvas.getContext('webgl', contextOptions)
  4153. || canvas.getContext('experimental-webgl', contextOptions));
  4154. var success = !!(gl && gl.getContextAttributes().stencil);
  4155. if (gl) {
  4156. var loseContext = gl.getExtension('WEBGL_lose_context');
  4157. if (loseContext) {
  4158. loseContext.loseContext();
  4159. }
  4160. }
  4161. gl = null;
  4162. return success;
  4163. }
  4164. catch (e) {
  4165. return false;
  4166. }
  4167. })();
  4168. }
  4169. return supported;
  4170. }
  4171. var aliceblue = "#f0f8ff";
  4172. var antiquewhite = "#faebd7";
  4173. var aqua = "#00ffff";
  4174. var aquamarine = "#7fffd4";
  4175. var azure = "#f0ffff";
  4176. var beige = "#f5f5dc";
  4177. var bisque = "#ffe4c4";
  4178. var black = "#000000";
  4179. var blanchedalmond = "#ffebcd";
  4180. var blue = "#0000ff";
  4181. var blueviolet = "#8a2be2";
  4182. var brown = "#a52a2a";
  4183. var burlywood = "#deb887";
  4184. var cadetblue = "#5f9ea0";
  4185. var chartreuse = "#7fff00";
  4186. var chocolate = "#d2691e";
  4187. var coral = "#ff7f50";
  4188. var cornflowerblue = "#6495ed";
  4189. var cornsilk = "#fff8dc";
  4190. var crimson = "#dc143c";
  4191. var cyan = "#00ffff";
  4192. var darkblue = "#00008b";
  4193. var darkcyan = "#008b8b";
  4194. var darkgoldenrod = "#b8860b";
  4195. var darkgray = "#a9a9a9";
  4196. var darkgreen = "#006400";
  4197. var darkgrey = "#a9a9a9";
  4198. var darkkhaki = "#bdb76b";
  4199. var darkmagenta = "#8b008b";
  4200. var darkolivegreen = "#556b2f";
  4201. var darkorange = "#ff8c00";
  4202. var darkorchid = "#9932cc";
  4203. var darkred = "#8b0000";
  4204. var darksalmon = "#e9967a";
  4205. var darkseagreen = "#8fbc8f";
  4206. var darkslateblue = "#483d8b";
  4207. var darkslategray = "#2f4f4f";
  4208. var darkslategrey = "#2f4f4f";
  4209. var darkturquoise = "#00ced1";
  4210. var darkviolet = "#9400d3";
  4211. var deeppink = "#ff1493";
  4212. var deepskyblue = "#00bfff";
  4213. var dimgray = "#696969";
  4214. var dimgrey = "#696969";
  4215. var dodgerblue = "#1e90ff";
  4216. var firebrick = "#b22222";
  4217. var floralwhite = "#fffaf0";
  4218. var forestgreen = "#228b22";
  4219. var fuchsia = "#ff00ff";
  4220. var gainsboro = "#dcdcdc";
  4221. var ghostwhite = "#f8f8ff";
  4222. var goldenrod = "#daa520";
  4223. var gold = "#ffd700";
  4224. var gray = "#808080";
  4225. var green = "#008000";
  4226. var greenyellow = "#adff2f";
  4227. var grey = "#808080";
  4228. var honeydew = "#f0fff0";
  4229. var hotpink = "#ff69b4";
  4230. var indianred = "#cd5c5c";
  4231. var indigo = "#4b0082";
  4232. var ivory = "#fffff0";
  4233. var khaki = "#f0e68c";
  4234. var lavenderblush = "#fff0f5";
  4235. var lavender = "#e6e6fa";
  4236. var lawngreen = "#7cfc00";
  4237. var lemonchiffon = "#fffacd";
  4238. var lightblue = "#add8e6";
  4239. var lightcoral = "#f08080";
  4240. var lightcyan = "#e0ffff";
  4241. var lightgoldenrodyellow = "#fafad2";
  4242. var lightgray = "#d3d3d3";
  4243. var lightgreen = "#90ee90";
  4244. var lightgrey = "#d3d3d3";
  4245. var lightpink = "#ffb6c1";
  4246. var lightsalmon = "#ffa07a";
  4247. var lightseagreen = "#20b2aa";
  4248. var lightskyblue = "#87cefa";
  4249. var lightslategray = "#778899";
  4250. var lightslategrey = "#778899";
  4251. var lightsteelblue = "#b0c4de";
  4252. var lightyellow = "#ffffe0";
  4253. var lime = "#00ff00";
  4254. var limegreen = "#32cd32";
  4255. var linen = "#faf0e6";
  4256. var magenta = "#ff00ff";
  4257. var maroon = "#800000";
  4258. var mediumaquamarine = "#66cdaa";
  4259. var mediumblue = "#0000cd";
  4260. var mediumorchid = "#ba55d3";
  4261. var mediumpurple = "#9370db";
  4262. var mediumseagreen = "#3cb371";
  4263. var mediumslateblue = "#7b68ee";
  4264. var mediumspringgreen = "#00fa9a";
  4265. var mediumturquoise = "#48d1cc";
  4266. var mediumvioletred = "#c71585";
  4267. var midnightblue = "#191970";
  4268. var mintcream = "#f5fffa";
  4269. var mistyrose = "#ffe4e1";
  4270. var moccasin = "#ffe4b5";
  4271. var navajowhite = "#ffdead";
  4272. var navy = "#000080";
  4273. var oldlace = "#fdf5e6";
  4274. var olive = "#808000";
  4275. var olivedrab = "#6b8e23";
  4276. var orange = "#ffa500";
  4277. var orangered = "#ff4500";
  4278. var orchid = "#da70d6";
  4279. var palegoldenrod = "#eee8aa";
  4280. var palegreen = "#98fb98";
  4281. var paleturquoise = "#afeeee";
  4282. var palevioletred = "#db7093";
  4283. var papayawhip = "#ffefd5";
  4284. var peachpuff = "#ffdab9";
  4285. var peru = "#cd853f";
  4286. var pink = "#ffc0cb";
  4287. var plum = "#dda0dd";
  4288. var powderblue = "#b0e0e6";
  4289. var purple = "#800080";
  4290. var rebeccapurple = "#663399";
  4291. var red = "#ff0000";
  4292. var rosybrown = "#bc8f8f";
  4293. var royalblue = "#4169e1";
  4294. var saddlebrown = "#8b4513";
  4295. var salmon = "#fa8072";
  4296. var sandybrown = "#f4a460";
  4297. var seagreen = "#2e8b57";
  4298. var seashell = "#fff5ee";
  4299. var sienna = "#a0522d";
  4300. var silver = "#c0c0c0";
  4301. var skyblue = "#87ceeb";
  4302. var slateblue = "#6a5acd";
  4303. var slategray = "#708090";
  4304. var slategrey = "#708090";
  4305. var snow = "#fffafa";
  4306. var springgreen = "#00ff7f";
  4307. var steelblue = "#4682b4";
  4308. var tan = "#d2b48c";
  4309. var teal = "#008080";
  4310. var thistle = "#d8bfd8";
  4311. var tomato = "#ff6347";
  4312. var turquoise = "#40e0d0";
  4313. var violet = "#ee82ee";
  4314. var wheat = "#f5deb3";
  4315. var white = "#ffffff";
  4316. var whitesmoke = "#f5f5f5";
  4317. var yellow = "#ffff00";
  4318. var yellowgreen = "#9acd32";
  4319. var cssColorNames = {
  4320. aliceblue: aliceblue,
  4321. antiquewhite: antiquewhite,
  4322. aqua: aqua,
  4323. aquamarine: aquamarine,
  4324. azure: azure,
  4325. beige: beige,
  4326. bisque: bisque,
  4327. black: black,
  4328. blanchedalmond: blanchedalmond,
  4329. blue: blue,
  4330. blueviolet: blueviolet,
  4331. brown: brown,
  4332. burlywood: burlywood,
  4333. cadetblue: cadetblue,
  4334. chartreuse: chartreuse,
  4335. chocolate: chocolate,
  4336. coral: coral,
  4337. cornflowerblue: cornflowerblue,
  4338. cornsilk: cornsilk,
  4339. crimson: crimson,
  4340. cyan: cyan,
  4341. darkblue: darkblue,
  4342. darkcyan: darkcyan,
  4343. darkgoldenrod: darkgoldenrod,
  4344. darkgray: darkgray,
  4345. darkgreen: darkgreen,
  4346. darkgrey: darkgrey,
  4347. darkkhaki: darkkhaki,
  4348. darkmagenta: darkmagenta,
  4349. darkolivegreen: darkolivegreen,
  4350. darkorange: darkorange,
  4351. darkorchid: darkorchid,
  4352. darkred: darkred,
  4353. darksalmon: darksalmon,
  4354. darkseagreen: darkseagreen,
  4355. darkslateblue: darkslateblue,
  4356. darkslategray: darkslategray,
  4357. darkslategrey: darkslategrey,
  4358. darkturquoise: darkturquoise,
  4359. darkviolet: darkviolet,
  4360. deeppink: deeppink,
  4361. deepskyblue: deepskyblue,
  4362. dimgray: dimgray,
  4363. dimgrey: dimgrey,
  4364. dodgerblue: dodgerblue,
  4365. firebrick: firebrick,
  4366. floralwhite: floralwhite,
  4367. forestgreen: forestgreen,
  4368. fuchsia: fuchsia,
  4369. gainsboro: gainsboro,
  4370. ghostwhite: ghostwhite,
  4371. goldenrod: goldenrod,
  4372. gold: gold,
  4373. gray: gray,
  4374. green: green,
  4375. greenyellow: greenyellow,
  4376. grey: grey,
  4377. honeydew: honeydew,
  4378. hotpink: hotpink,
  4379. indianred: indianred,
  4380. indigo: indigo,
  4381. ivory: ivory,
  4382. khaki: khaki,
  4383. lavenderblush: lavenderblush,
  4384. lavender: lavender,
  4385. lawngreen: lawngreen,
  4386. lemonchiffon: lemonchiffon,
  4387. lightblue: lightblue,
  4388. lightcoral: lightcoral,
  4389. lightcyan: lightcyan,
  4390. lightgoldenrodyellow: lightgoldenrodyellow,
  4391. lightgray: lightgray,
  4392. lightgreen: lightgreen,
  4393. lightgrey: lightgrey,
  4394. lightpink: lightpink,
  4395. lightsalmon: lightsalmon,
  4396. lightseagreen: lightseagreen,
  4397. lightskyblue: lightskyblue,
  4398. lightslategray: lightslategray,
  4399. lightslategrey: lightslategrey,
  4400. lightsteelblue: lightsteelblue,
  4401. lightyellow: lightyellow,
  4402. lime: lime,
  4403. limegreen: limegreen,
  4404. linen: linen,
  4405. magenta: magenta,
  4406. maroon: maroon,
  4407. mediumaquamarine: mediumaquamarine,
  4408. mediumblue: mediumblue,
  4409. mediumorchid: mediumorchid,
  4410. mediumpurple: mediumpurple,
  4411. mediumseagreen: mediumseagreen,
  4412. mediumslateblue: mediumslateblue,
  4413. mediumspringgreen: mediumspringgreen,
  4414. mediumturquoise: mediumturquoise,
  4415. mediumvioletred: mediumvioletred,
  4416. midnightblue: midnightblue,
  4417. mintcream: mintcream,
  4418. mistyrose: mistyrose,
  4419. moccasin: moccasin,
  4420. navajowhite: navajowhite,
  4421. navy: navy,
  4422. oldlace: oldlace,
  4423. olive: olive,
  4424. olivedrab: olivedrab,
  4425. orange: orange,
  4426. orangered: orangered,
  4427. orchid: orchid,
  4428. palegoldenrod: palegoldenrod,
  4429. palegreen: palegreen,
  4430. paleturquoise: paleturquoise,
  4431. palevioletred: palevioletred,
  4432. papayawhip: papayawhip,
  4433. peachpuff: peachpuff,
  4434. peru: peru,
  4435. pink: pink,
  4436. plum: plum,
  4437. powderblue: powderblue,
  4438. purple: purple,
  4439. rebeccapurple: rebeccapurple,
  4440. red: red,
  4441. rosybrown: rosybrown,
  4442. royalblue: royalblue,
  4443. saddlebrown: saddlebrown,
  4444. salmon: salmon,
  4445. sandybrown: sandybrown,
  4446. seagreen: seagreen,
  4447. seashell: seashell,
  4448. sienna: sienna,
  4449. silver: silver,
  4450. skyblue: skyblue,
  4451. slateblue: slateblue,
  4452. slategray: slategray,
  4453. slategrey: slategrey,
  4454. snow: snow,
  4455. springgreen: springgreen,
  4456. steelblue: steelblue,
  4457. tan: tan,
  4458. teal: teal,
  4459. thistle: thistle,
  4460. tomato: tomato,
  4461. turquoise: turquoise,
  4462. violet: violet,
  4463. wheat: wheat,
  4464. white: white,
  4465. whitesmoke: whitesmoke,
  4466. yellow: yellow,
  4467. yellowgreen: yellowgreen
  4468. };
  4469. /**
  4470. * Converts a hexadecimal color number to an [R, G, B] array of normalized floats (numbers from 0.0 to 1.0).
  4471. *
  4472. * @example
  4473. * PIXI.utils.hex2rgb(0xffffff); // returns [1, 1, 1]
  4474. * @memberof PIXI.utils
  4475. * @function hex2rgb
  4476. * @param {number} hex - The hexadecimal number to convert
  4477. * @param {number[]} [out=[]] - If supplied, this array will be used rather than returning a new one
  4478. * @return {number[]} An array representing the [R, G, B] of the color where all values are floats.
  4479. */
  4480. function hex2rgb(hex, out) {
  4481. if (out === void 0) { out = []; }
  4482. out[0] = ((hex >> 16) & 0xFF) / 255;
  4483. out[1] = ((hex >> 8) & 0xFF) / 255;
  4484. out[2] = (hex & 0xFF) / 255;
  4485. return out;
  4486. }
  4487. /**
  4488. * Converts a hexadecimal color number to a string.
  4489. *
  4490. * @example
  4491. * PIXI.utils.hex2string(0xffffff); // returns "#ffffff"
  4492. * @memberof PIXI.utils
  4493. * @function hex2string
  4494. * @param {number} hex - Number in hex (e.g., `0xffffff`)
  4495. * @return {string} The string color (e.g., `"#ffffff"`).
  4496. */
  4497. function hex2string(hex) {
  4498. var hexString = hex.toString(16);
  4499. hexString = '000000'.substr(0, 6 - hexString.length) + hexString;
  4500. return "#" + hexString;
  4501. }
  4502. /**
  4503. * Converts a string to a hexadecimal color number.
  4504. * It can handle:
  4505. * hex strings starting with #: "#ffffff"
  4506. * hex strings starting with 0x: "0xffffff"
  4507. * hex strings without prefix: "ffffff"
  4508. * css colors: "black"
  4509. *
  4510. * @example
  4511. * PIXI.utils.string2hex("#ffffff"); // returns 0xffffff
  4512. * @memberof PIXI.utils
  4513. * @function string2hex
  4514. * @param {string} string - The string color (e.g., `"#ffffff"`)
  4515. * @return {number} Number in hexadecimal.
  4516. */
  4517. function string2hex(string) {
  4518. if (typeof string === 'string') {
  4519. string = cssColorNames[string.toLowerCase()] || string;
  4520. if (string[0] === '#') {
  4521. string = string.substr(1);
  4522. }
  4523. }
  4524. return parseInt(string, 16);
  4525. }
  4526. /**
  4527. * Converts a color as an [R, G, B] array of normalized floats to a hexadecimal number.
  4528. *
  4529. * @example
  4530. * PIXI.utils.rgb2hex([1, 1, 1]); // returns 0xffffff
  4531. * @memberof PIXI.utils
  4532. * @function rgb2hex
  4533. * @param {number[]} rgb - Array of numbers where all values are normalized floats from 0.0 to 1.0.
  4534. * @return {number} Number in hexadecimal.
  4535. */
  4536. function rgb2hex(rgb) {
  4537. return (((rgb[0] * 255) << 16) + ((rgb[1] * 255) << 8) + (rgb[2] * 255 | 0));
  4538. }
  4539. /**
  4540. * Corrects PixiJS blend, takes premultiplied alpha into account
  4541. *
  4542. * @memberof PIXI.utils
  4543. * @function mapPremultipliedBlendModes
  4544. * @private
  4545. * @return {Array<number[]>} Mapped modes.
  4546. */
  4547. function mapPremultipliedBlendModes() {
  4548. var pm = [];
  4549. var npm = [];
  4550. for (var i = 0; i < 32; i++) {
  4551. pm[i] = i;
  4552. npm[i] = i;
  4553. }
  4554. pm[exports.BLEND_MODES.NORMAL_NPM] = exports.BLEND_MODES.NORMAL;
  4555. pm[exports.BLEND_MODES.ADD_NPM] = exports.BLEND_MODES.ADD;
  4556. pm[exports.BLEND_MODES.SCREEN_NPM] = exports.BLEND_MODES.SCREEN;
  4557. npm[exports.BLEND_MODES.NORMAL] = exports.BLEND_MODES.NORMAL_NPM;
  4558. npm[exports.BLEND_MODES.ADD] = exports.BLEND_MODES.ADD_NPM;
  4559. npm[exports.BLEND_MODES.SCREEN] = exports.BLEND_MODES.SCREEN_NPM;
  4560. var array = [];
  4561. array.push(npm);
  4562. array.push(pm);
  4563. return array;
  4564. }
  4565. /**
  4566. * maps premultiply flag and blendMode to adjusted blendMode
  4567. * @memberof PIXI.utils
  4568. * @const premultiplyBlendMode
  4569. * @type {Array<number[]>}
  4570. */
  4571. var premultiplyBlendMode = mapPremultipliedBlendModes();
  4572. /**
  4573. * changes blendMode according to texture format
  4574. *
  4575. * @memberof PIXI.utils
  4576. * @function correctBlendMode
  4577. * @param {number} blendMode - supposed blend mode
  4578. * @param {boolean} premultiplied - whether source is premultiplied
  4579. * @returns {number} true blend mode for this texture
  4580. */
  4581. function correctBlendMode(blendMode, premultiplied) {
  4582. return premultiplyBlendMode[premultiplied ? 1 : 0][blendMode];
  4583. }
  4584. /**
  4585. * combines rgb and alpha to out array
  4586. *
  4587. * @memberof PIXI.utils
  4588. * @function premultiplyRgba
  4589. * @param {Float32Array|number[]} rgb - input rgb
  4590. * @param {number} alpha - alpha param
  4591. * @param {Float32Array} [out] - output
  4592. * @param {boolean} [premultiply=true] - do premultiply it
  4593. * @returns {Float32Array} vec4 rgba
  4594. */
  4595. function premultiplyRgba(rgb, alpha, out, premultiply) {
  4596. out = out || new Float32Array(4);
  4597. if (premultiply || premultiply === undefined) {
  4598. out[0] = rgb[0] * alpha;
  4599. out[1] = rgb[1] * alpha;
  4600. out[2] = rgb[2] * alpha;
  4601. }
  4602. else {
  4603. out[0] = rgb[0];
  4604. out[1] = rgb[1];
  4605. out[2] = rgb[2];
  4606. }
  4607. out[3] = alpha;
  4608. return out;
  4609. }
  4610. /**
  4611. * premultiplies tint
  4612. *
  4613. * @memberof PIXI.utils
  4614. * @function premultiplyTint
  4615. * @param {number} tint - integer RGB
  4616. * @param {number} alpha - floating point alpha (0.0-1.0)
  4617. * @returns {number} tint multiplied by alpha
  4618. */
  4619. function premultiplyTint(tint, alpha) {
  4620. if (alpha === 1.0) {
  4621. return (alpha * 255 << 24) + tint;
  4622. }
  4623. if (alpha === 0.0) {
  4624. return 0;
  4625. }
  4626. var R = ((tint >> 16) & 0xFF);
  4627. var G = ((tint >> 8) & 0xFF);
  4628. var B = (tint & 0xFF);
  4629. R = ((R * alpha) + 0.5) | 0;
  4630. G = ((G * alpha) + 0.5) | 0;
  4631. B = ((B * alpha) + 0.5) | 0;
  4632. return (alpha * 255 << 24) + (R << 16) + (G << 8) + B;
  4633. }
  4634. /**
  4635. * converts integer tint and float alpha to vec4 form, premultiplies by default
  4636. *
  4637. * @memberof PIXI.utils
  4638. * @function premultiplyTintToRgba
  4639. * @param {number} tint - input tint
  4640. * @param {number} alpha - alpha param
  4641. * @param {Float32Array} [out] - output
  4642. * @param {boolean} [premultiply=true] - do premultiply it
  4643. * @returns {Float32Array} vec4 rgba
  4644. */
  4645. function premultiplyTintToRgba(tint, alpha, out, premultiply) {
  4646. out = out || new Float32Array(4);
  4647. out[0] = ((tint >> 16) & 0xFF) / 255.0;
  4648. out[1] = ((tint >> 8) & 0xFF) / 255.0;
  4649. out[2] = (tint & 0xFF) / 255.0;
  4650. if (premultiply || premultiply === undefined) {
  4651. out[0] *= alpha;
  4652. out[1] *= alpha;
  4653. out[2] *= alpha;
  4654. }
  4655. out[3] = alpha;
  4656. return out;
  4657. }
  4658. /**
  4659. * Generic Mask Stack data structure
  4660. *
  4661. * @memberof PIXI.utils
  4662. * @function createIndicesForQuads
  4663. * @param {number} size - Number of quads
  4664. * @param {Uint16Array|Uint32Array} [outBuffer] - Buffer for output, length has to be `6 * size`
  4665. * @return {Uint16Array|Uint32Array} - Resulting index buffer
  4666. */
  4667. function createIndicesForQuads(size, outBuffer) {
  4668. if (outBuffer === void 0) { outBuffer = null; }
  4669. // the total number of indices in our array, there are 6 points per quad.
  4670. var totalIndices = size * 6;
  4671. outBuffer = outBuffer || new Uint16Array(totalIndices);
  4672. if (outBuffer.length !== totalIndices) {
  4673. throw new Error("Out buffer length is incorrect, got " + outBuffer.length + " and expected " + totalIndices);
  4674. }
  4675. // fill the indices with the quads to draw
  4676. for (var i = 0, j = 0; i < totalIndices; i += 6, j += 4) {
  4677. outBuffer[i + 0] = j + 0;
  4678. outBuffer[i + 1] = j + 1;
  4679. outBuffer[i + 2] = j + 2;
  4680. outBuffer[i + 3] = j + 0;
  4681. outBuffer[i + 4] = j + 2;
  4682. outBuffer[i + 5] = j + 3;
  4683. }
  4684. return outBuffer;
  4685. }
  4686. function getBufferType(array) {
  4687. if (array.BYTES_PER_ELEMENT === 4) {
  4688. if (array instanceof Float32Array) {
  4689. return 'Float32Array';
  4690. }
  4691. else if (array instanceof Uint32Array) {
  4692. return 'Uint32Array';
  4693. }
  4694. return 'Int32Array';
  4695. }
  4696. else if (array.BYTES_PER_ELEMENT === 2) {
  4697. if (array instanceof Uint16Array) {
  4698. return 'Uint16Array';
  4699. }
  4700. }
  4701. else if (array.BYTES_PER_ELEMENT === 1) {
  4702. if (array instanceof Uint8Array) {
  4703. return 'Uint8Array';
  4704. }
  4705. }
  4706. // TODO map out the rest of the array elements!
  4707. return null;
  4708. }
  4709. /* eslint-disable object-shorthand */
  4710. var map = { Float32Array: Float32Array, Uint32Array: Uint32Array, Int32Array: Int32Array, Uint8Array: Uint8Array };
  4711. function interleaveTypedArrays(arrays, sizes) {
  4712. var outSize = 0;
  4713. var stride = 0;
  4714. var views = {};
  4715. for (var i = 0; i < arrays.length; i++) {
  4716. stride += sizes[i];
  4717. outSize += arrays[i].length;
  4718. }
  4719. var buffer = new ArrayBuffer(outSize * 4);
  4720. var out = null;
  4721. var littleOffset = 0;
  4722. for (var i = 0; i < arrays.length; i++) {
  4723. var size = sizes[i];
  4724. var array = arrays[i];
  4725. /*
  4726. @todo This is unsafe casting but consistent with how the code worked previously. Should it stay this way
  4727. or should and `getBufferTypeUnsafe` function be exposed that throws an Error if unsupported type is passed?
  4728. */
  4729. var type = getBufferType(array);
  4730. if (!views[type]) {
  4731. views[type] = new map[type](buffer);
  4732. }
  4733. out = views[type];
  4734. for (var j = 0; j < array.length; j++) {
  4735. var indexStart = ((j / size | 0) * stride) + littleOffset;
  4736. var index = j % size;
  4737. out[indexStart + index] = array[j];
  4738. }
  4739. littleOffset += size;
  4740. }
  4741. return new Float32Array(buffer);
  4742. }
  4743. // Taken from the bit-twiddle package
  4744. /**
  4745. * Rounds to next power of two.
  4746. *
  4747. * @function nextPow2
  4748. * @memberof PIXI.utils
  4749. * @param {number} v - input value
  4750. * @return {number}
  4751. */
  4752. function nextPow2(v) {
  4753. v += v === 0 ? 1 : 0;
  4754. --v;
  4755. v |= v >>> 1;
  4756. v |= v >>> 2;
  4757. v |= v >>> 4;
  4758. v |= v >>> 8;
  4759. v |= v >>> 16;
  4760. return v + 1;
  4761. }
  4762. /**
  4763. * Checks if a number is a power of two.
  4764. *
  4765. * @function isPow2
  4766. * @memberof PIXI.utils
  4767. * @param {number} v - input value
  4768. * @return {boolean} `true` if value is power of two
  4769. */
  4770. function isPow2(v) {
  4771. return !(v & (v - 1)) && (!!v);
  4772. }
  4773. /**
  4774. * Computes ceil of log base 2
  4775. *
  4776. * @function log2
  4777. * @memberof PIXI.utils
  4778. * @param {number} v - input value
  4779. * @return {number} logarithm base 2
  4780. */
  4781. function log2(v) {
  4782. var r = (v > 0xFFFF ? 1 : 0) << 4;
  4783. v >>>= r;
  4784. var shift = (v > 0xFF ? 1 : 0) << 3;
  4785. v >>>= shift;
  4786. r |= shift;
  4787. shift = (v > 0xF ? 1 : 0) << 2;
  4788. v >>>= shift;
  4789. r |= shift;
  4790. shift = (v > 0x3 ? 1 : 0) << 1;
  4791. v >>>= shift;
  4792. r |= shift;
  4793. return r | (v >> 1);
  4794. }
  4795. /**
  4796. * Remove items from a javascript array without generating garbage
  4797. *
  4798. * @function removeItems
  4799. * @memberof PIXI.utils
  4800. * @param {Array<any>} arr - Array to remove elements from
  4801. * @param {number} startIdx - starting index
  4802. * @param {number} removeCount - how many to remove
  4803. */
  4804. function removeItems(arr, startIdx, removeCount) {
  4805. var length = arr.length;
  4806. var i;
  4807. if (startIdx >= length || removeCount === 0) {
  4808. return;
  4809. }
  4810. removeCount = (startIdx + removeCount > length ? length - startIdx : removeCount);
  4811. var len = length - removeCount;
  4812. for (i = startIdx; i < len; ++i) {
  4813. arr[i] = arr[i + removeCount];
  4814. }
  4815. arr.length = len;
  4816. }
  4817. /**
  4818. * Returns sign of number
  4819. *
  4820. * @memberof PIXI.utils
  4821. * @function sign
  4822. * @param {number} n - the number to check the sign of
  4823. * @returns {number} 0 if `n` is 0, -1 if `n` is negative, 1 if `n` is positive
  4824. */
  4825. function sign$1(n) {
  4826. if (n === 0)
  4827. { return 0; }
  4828. return n < 0 ? -1 : 1;
  4829. }
  4830. var nextUid = 0;
  4831. /**
  4832. * Gets the next unique identifier
  4833. *
  4834. * @memberof PIXI.utils
  4835. * @function uid
  4836. * @return {number} The next unique identifier to use.
  4837. */
  4838. function uid() {
  4839. return ++nextUid;
  4840. }
  4841. // A map of warning messages already fired
  4842. var warnings = {};
  4843. /**
  4844. * Helper for warning developers about deprecated features & settings.
  4845. * A stack track for warnings is given; useful for tracking-down where
  4846. * deprecated methods/properties/classes are being used within the code.
  4847. *
  4848. * @memberof PIXI.utils
  4849. * @function deprecation
  4850. * @param {string} version - The version where the feature became deprecated
  4851. * @param {string} message - Message should include what is deprecated, where, and the new solution
  4852. * @param {number} [ignoreDepth=3] - The number of steps to ignore at the top of the error stack
  4853. * this is mostly to ignore internal deprecation calls.
  4854. */
  4855. function deprecation(version, message, ignoreDepth) {
  4856. if (ignoreDepth === void 0) { ignoreDepth = 3; }
  4857. // Ignore duplicat
  4858. if (warnings[message]) {
  4859. return;
  4860. }
  4861. /* eslint-disable no-console */
  4862. var stack = new Error().stack;
  4863. // Handle IE < 10 and Safari < 6
  4864. if (typeof stack === 'undefined') {
  4865. console.warn('PixiJS Deprecation Warning: ', message + "\nDeprecated since v" + version);
  4866. }
  4867. else {
  4868. // chop off the stack trace which includes PixiJS internal calls
  4869. stack = stack.split('\n').splice(ignoreDepth).join('\n');
  4870. if (console.groupCollapsed) {
  4871. console.groupCollapsed('%cPixiJS Deprecation Warning: %c%s', 'color:#614108;background:#fffbe6', 'font-weight:normal;color:#614108;background:#fffbe6', message + "\nDeprecated since v" + version);
  4872. console.warn(stack);
  4873. console.groupEnd();
  4874. }
  4875. else {
  4876. console.warn('PixiJS Deprecation Warning: ', message + "\nDeprecated since v" + version);
  4877. console.warn(stack);
  4878. }
  4879. }
  4880. /* eslint-enable no-console */
  4881. warnings[message] = true;
  4882. }
  4883. /**
  4884. * @todo Describe property usage
  4885. *
  4886. * @static
  4887. * @name ProgramCache
  4888. * @memberof PIXI.utils
  4889. * @type {Object}
  4890. */
  4891. var ProgramCache = {};
  4892. /**
  4893. * @todo Describe property usage
  4894. *
  4895. * @static
  4896. * @name TextureCache
  4897. * @memberof PIXI.utils
  4898. * @type {Object}
  4899. */
  4900. var TextureCache = Object.create(null);
  4901. /**
  4902. * @todo Describe property usage
  4903. *
  4904. * @static
  4905. * @name BaseTextureCache
  4906. * @memberof PIXI.utils
  4907. * @type {Object}
  4908. */
  4909. var BaseTextureCache = Object.create(null);
  4910. /**
  4911. * Destroys all texture in the cache
  4912. *
  4913. * @memberof PIXI.utils
  4914. * @function destroyTextureCache
  4915. */
  4916. function destroyTextureCache() {
  4917. var key;
  4918. for (key in TextureCache) {
  4919. TextureCache[key].destroy();
  4920. }
  4921. for (key in BaseTextureCache) {
  4922. BaseTextureCache[key].destroy();
  4923. }
  4924. }
  4925. /**
  4926. * Removes all textures from cache, but does not destroy them
  4927. *
  4928. * @memberof PIXI.utils
  4929. * @function clearTextureCache
  4930. */
  4931. function clearTextureCache() {
  4932. var key;
  4933. for (key in TextureCache) {
  4934. delete TextureCache[key];
  4935. }
  4936. for (key in BaseTextureCache) {
  4937. delete BaseTextureCache[key];
  4938. }
  4939. }
  4940. /**
  4941. * Creates a Canvas element of the given size to be used as a target for rendering to.
  4942. *
  4943. * @class
  4944. * @memberof PIXI.utils
  4945. */
  4946. var CanvasRenderTarget = /** @class */ (function () {
  4947. /**
  4948. * @param width - the width for the newly created canvas
  4949. * @param height - the height for the newly created canvas
  4950. * @param {number} [resolution=PIXI.settings.RESOLUTION] - The resolution / device pixel ratio of the canvas
  4951. */
  4952. function CanvasRenderTarget(width, height, resolution) {
  4953. this.canvas = document.createElement('canvas');
  4954. this.context = this.canvas.getContext('2d');
  4955. this.resolution = resolution || settings.RESOLUTION;
  4956. this.resize(width, height);
  4957. }
  4958. /**
  4959. * Clears the canvas that was created by the CanvasRenderTarget class.
  4960. *
  4961. * @private
  4962. */
  4963. CanvasRenderTarget.prototype.clear = function () {
  4964. this.context.setTransform(1, 0, 0, 1, 0, 0);
  4965. this.context.clearRect(0, 0, this.canvas.width, this.canvas.height);
  4966. };
  4967. /**
  4968. * Resizes the canvas to the specified width and height.
  4969. *
  4970. * @param desiredWidth - the desired width of the canvas
  4971. * @param desiredHeight - the desired height of the canvas
  4972. */
  4973. CanvasRenderTarget.prototype.resize = function (desiredWidth, desiredHeight) {
  4974. this.canvas.width = Math.round(desiredWidth * this.resolution);
  4975. this.canvas.height = Math.round(desiredHeight * this.resolution);
  4976. };
  4977. /** Destroys this canvas. */
  4978. CanvasRenderTarget.prototype.destroy = function () {
  4979. this.context = null;
  4980. this.canvas = null;
  4981. };
  4982. Object.defineProperty(CanvasRenderTarget.prototype, "width", {
  4983. /**
  4984. * The width of the canvas buffer in pixels.
  4985. *
  4986. * @member {number}
  4987. */
  4988. get: function () {
  4989. return this.canvas.width;
  4990. },
  4991. set: function (val) {
  4992. this.canvas.width = Math.round(val);
  4993. },
  4994. enumerable: false,
  4995. configurable: true
  4996. });
  4997. Object.defineProperty(CanvasRenderTarget.prototype, "height", {
  4998. /**
  4999. * The height of the canvas buffer in pixels.
  5000. *
  5001. * @member {number}
  5002. */
  5003. get: function () {
  5004. return this.canvas.height;
  5005. },
  5006. set: function (val) {
  5007. this.canvas.height = Math.round(val);
  5008. },
  5009. enumerable: false,
  5010. configurable: true
  5011. });
  5012. return CanvasRenderTarget;
  5013. }());
  5014. /**
  5015. * Trim transparent borders from a canvas
  5016. *
  5017. * @memberof PIXI.utils
  5018. * @function trimCanvas
  5019. * @param {HTMLCanvasElement} canvas - the canvas to trim
  5020. * @returns {object} Trim data
  5021. */
  5022. function trimCanvas(canvas) {
  5023. // https://gist.github.com/remy/784508
  5024. var width = canvas.width;
  5025. var height = canvas.height;
  5026. var context = canvas.getContext('2d');
  5027. var imageData = context.getImageData(0, 0, width, height);
  5028. var pixels = imageData.data;
  5029. var len = pixels.length;
  5030. var bound = {
  5031. top: null,
  5032. left: null,
  5033. right: null,
  5034. bottom: null,
  5035. };
  5036. var data = null;
  5037. var i;
  5038. var x;
  5039. var y;
  5040. for (i = 0; i < len; i += 4) {
  5041. if (pixels[i + 3] !== 0) {
  5042. x = (i / 4) % width;
  5043. y = ~~((i / 4) / width);
  5044. if (bound.top === null) {
  5045. bound.top = y;
  5046. }
  5047. if (bound.left === null) {
  5048. bound.left = x;
  5049. }
  5050. else if (x < bound.left) {
  5051. bound.left = x;
  5052. }
  5053. if (bound.right === null) {
  5054. bound.right = x + 1;
  5055. }
  5056. else if (bound.right < x) {
  5057. bound.right = x + 1;
  5058. }
  5059. if (bound.bottom === null) {
  5060. bound.bottom = y;
  5061. }
  5062. else if (bound.bottom < y) {
  5063. bound.bottom = y;
  5064. }
  5065. }
  5066. }
  5067. if (bound.top !== null) {
  5068. width = bound.right - bound.left;
  5069. height = bound.bottom - bound.top + 1;
  5070. data = context.getImageData(bound.left, bound.top, width, height);
  5071. }
  5072. return {
  5073. height: height,
  5074. width: width,
  5075. data: data,
  5076. };
  5077. }
  5078. /**
  5079. * Regexp for data URI.
  5080. * Based on: {@link https://github.com/ragingwind/data-uri-regex}
  5081. *
  5082. * @static
  5083. * @constant {RegExp|string} DATA_URI
  5084. * @memberof PIXI
  5085. * @example data:image/png;base64
  5086. */
  5087. var DATA_URI = /^\s*data:(?:([\w-]+)\/([\w+.-]+))?(?:;charset=([\w-]+))?(?:;(base64))?,(.*)/i;
  5088. /**
  5089. * @memberof PIXI.utils
  5090. * @interface DecomposedDataUri
  5091. */
  5092. /**
  5093. * type, eg. `image`
  5094. * @memberof PIXI.utils.DecomposedDataUri#
  5095. * @member {string} mediaType
  5096. */
  5097. /**
  5098. * Sub type, eg. `png`
  5099. * @memberof PIXI.utils.DecomposedDataUri#
  5100. * @member {string} subType
  5101. */
  5102. /**
  5103. * @memberof PIXI.utils.DecomposedDataUri#
  5104. * @member {string} charset
  5105. */
  5106. /**
  5107. * Data encoding, eg. `base64`
  5108. * @memberof PIXI.utils.DecomposedDataUri#
  5109. * @member {string} encoding
  5110. */
  5111. /**
  5112. * The actual data
  5113. * @memberof PIXI.utils.DecomposedDataUri#
  5114. * @member {string} data
  5115. */
  5116. /**
  5117. * Split a data URI into components. Returns undefined if
  5118. * parameter `dataUri` is not a valid data URI.
  5119. *
  5120. * @memberof PIXI.utils
  5121. * @function decomposeDataUri
  5122. * @param {string} dataUri - the data URI to check
  5123. * @return {PIXI.utils.DecomposedDataUri|undefined} The decomposed data uri or undefined
  5124. */
  5125. function decomposeDataUri(dataUri) {
  5126. var dataUriMatch = DATA_URI.exec(dataUri);
  5127. if (dataUriMatch) {
  5128. return {
  5129. mediaType: dataUriMatch[1] ? dataUriMatch[1].toLowerCase() : undefined,
  5130. subType: dataUriMatch[2] ? dataUriMatch[2].toLowerCase() : undefined,
  5131. charset: dataUriMatch[3] ? dataUriMatch[3].toLowerCase() : undefined,
  5132. encoding: dataUriMatch[4] ? dataUriMatch[4].toLowerCase() : undefined,
  5133. data: dataUriMatch[5],
  5134. };
  5135. }
  5136. return undefined;
  5137. }
  5138. var tempAnchor;
  5139. /**
  5140. * Sets the `crossOrigin` property for this resource based on if the url
  5141. * for this resource is cross-origin. If crossOrigin was manually set, this
  5142. * function does nothing.
  5143. * Nipped from the resource loader!
  5144. *
  5145. * @ignore
  5146. * @param {string} url - The url to test.
  5147. * @param {object} [loc=window.location] - The location object to test against.
  5148. * @return {string} The crossOrigin value to use (or empty string for none).
  5149. */
  5150. function determineCrossOrigin(url$1$1, loc) {
  5151. if (loc === void 0) { loc = self.location; }
  5152. // data: and javascript: urls are considered same-origin
  5153. if (url$1$1.indexOf('data:') === 0) {
  5154. return '';
  5155. }
  5156. // default is window.location
  5157. loc = loc || self.location;
  5158. if (!tempAnchor) {
  5159. tempAnchor = document.createElement('a');
  5160. }
  5161. // let the browser determine the full href for the url of this resource and then
  5162. // parse with the node url lib, we can't use the properties of the anchor element
  5163. // because they don't work in IE9 :(
  5164. tempAnchor.href = url$1$1;
  5165. var parsedUrl = url$1.parse(tempAnchor.href);
  5166. var samePort = (!parsedUrl.port && loc.port === '') || (parsedUrl.port === loc.port);
  5167. // if cross origin
  5168. if (parsedUrl.hostname !== loc.hostname || !samePort || parsedUrl.protocol !== loc.protocol) {
  5169. return 'anonymous';
  5170. }
  5171. return '';
  5172. }
  5173. /**
  5174. * get the resolution / device pixel ratio of an asset by looking for the prefix
  5175. * used by spritesheets and image urls
  5176. *
  5177. * @memberof PIXI.utils
  5178. * @function getResolutionOfUrl
  5179. * @param {string} url - the image path
  5180. * @param {number} [defaultValue=1] - the defaultValue if no filename prefix is set.
  5181. * @return {number} resolution / device pixel ratio of an asset
  5182. */
  5183. function getResolutionOfUrl(url, defaultValue) {
  5184. var resolution = settings.RETINA_PREFIX.exec(url);
  5185. if (resolution) {
  5186. return parseFloat(resolution[1]);
  5187. }
  5188. return defaultValue !== undefined ? defaultValue : 1;
  5189. }
  5190. var utils = {
  5191. __proto__: null,
  5192. BaseTextureCache: BaseTextureCache,
  5193. CanvasRenderTarget: CanvasRenderTarget,
  5194. DATA_URI: DATA_URI,
  5195. ProgramCache: ProgramCache,
  5196. TextureCache: TextureCache,
  5197. clearTextureCache: clearTextureCache,
  5198. correctBlendMode: correctBlendMode,
  5199. createIndicesForQuads: createIndicesForQuads,
  5200. decomposeDataUri: decomposeDataUri,
  5201. deprecation: deprecation,
  5202. destroyTextureCache: destroyTextureCache,
  5203. determineCrossOrigin: determineCrossOrigin,
  5204. getBufferType: getBufferType,
  5205. getResolutionOfUrl: getResolutionOfUrl,
  5206. hex2rgb: hex2rgb,
  5207. hex2string: hex2string,
  5208. interleaveTypedArrays: interleaveTypedArrays,
  5209. isPow2: isPow2,
  5210. isWebGLSupported: isWebGLSupported,
  5211. log2: log2,
  5212. nextPow2: nextPow2,
  5213. premultiplyBlendMode: premultiplyBlendMode,
  5214. premultiplyRgba: premultiplyRgba,
  5215. premultiplyTint: premultiplyTint,
  5216. premultiplyTintToRgba: premultiplyTintToRgba,
  5217. removeItems: removeItems,
  5218. rgb2hex: rgb2hex,
  5219. sayHello: sayHello,
  5220. sign: sign$1,
  5221. skipHello: skipHello,
  5222. string2hex: string2hex,
  5223. trimCanvas: trimCanvas,
  5224. uid: uid,
  5225. url: url$1,
  5226. isMobile: isMobile$1,
  5227. EventEmitter: eventemitter3,
  5228. earcut: earcut_1
  5229. };
  5230. /*!
  5231. * @pixi/math - v6.1.2
  5232. * Compiled Thu, 12 Aug 2021 17:11:19 UTC
  5233. *
  5234. * @pixi/math is licensed under the MIT License.
  5235. * http://www.opensource.org/licenses/mit-license
  5236. */
  5237. /**
  5238. * Two Pi.
  5239. *
  5240. * @static
  5241. * @member {number}
  5242. * @memberof PIXI
  5243. */
  5244. var PI_2 = Math.PI * 2;
  5245. /**
  5246. * Conversion factor for converting radians to degrees.
  5247. *
  5248. * @static
  5249. * @member {number} RAD_TO_DEG
  5250. * @memberof PIXI
  5251. */
  5252. var RAD_TO_DEG = 180 / Math.PI;
  5253. /**
  5254. * Conversion factor for converting degrees to radians.
  5255. *
  5256. * @static
  5257. * @member {number}
  5258. * @memberof PIXI
  5259. */
  5260. var DEG_TO_RAD = Math.PI / 180;
  5261. /**
  5262. * Constants that identify shapes, mainly to prevent `instanceof` calls.
  5263. *
  5264. * @static
  5265. * @memberof PIXI
  5266. * @enum {number}
  5267. * @property {number} POLY Polygon
  5268. * @property {number} RECT Rectangle
  5269. * @property {number} CIRC Circle
  5270. * @property {number} ELIP Ellipse
  5271. * @property {number} RREC Rounded Rectangle
  5272. */
  5273. (function (SHAPES) {
  5274. SHAPES[SHAPES["POLY"] = 0] = "POLY";
  5275. SHAPES[SHAPES["RECT"] = 1] = "RECT";
  5276. SHAPES[SHAPES["CIRC"] = 2] = "CIRC";
  5277. SHAPES[SHAPES["ELIP"] = 3] = "ELIP";
  5278. SHAPES[SHAPES["RREC"] = 4] = "RREC";
  5279. })(exports.SHAPES || (exports.SHAPES = {}));
  5280. /**
  5281. * Size object, contains width and height
  5282. *
  5283. * @memberof PIXI
  5284. * @typedef {object} ISize
  5285. * @property {number} width - Width component
  5286. * @property {number} height - Height component
  5287. */
  5288. /**
  5289. * Rectangle object is an area defined by its position, as indicated by its top-left corner
  5290. * point (x, y) and by its width and its height.
  5291. *
  5292. * @class
  5293. * @memberof PIXI
  5294. */
  5295. var Rectangle = /** @class */ (function () {
  5296. /**
  5297. * @param {number} [x=0] - The X coordinate of the upper-left corner of the rectangle
  5298. * @param {number} [y=0] - The Y coordinate of the upper-left corner of the rectangle
  5299. * @param {number} [width=0] - The overall width of this rectangle
  5300. * @param {number} [height=0] - The overall height of this rectangle
  5301. */
  5302. function Rectangle(x, y, width, height) {
  5303. if (x === void 0) { x = 0; }
  5304. if (y === void 0) { y = 0; }
  5305. if (width === void 0) { width = 0; }
  5306. if (height === void 0) { height = 0; }
  5307. /**
  5308. * @member {number}
  5309. * @default 0
  5310. */
  5311. this.x = Number(x);
  5312. /**
  5313. * @member {number}
  5314. * @default 0
  5315. */
  5316. this.y = Number(y);
  5317. /**
  5318. * @member {number}
  5319. * @default 0
  5320. */
  5321. this.width = Number(width);
  5322. /**
  5323. * @member {number}
  5324. * @default 0
  5325. */
  5326. this.height = Number(height);
  5327. /**
  5328. * The type of the object, mainly used to avoid `instanceof` checks
  5329. *
  5330. * @member {number}
  5331. * @readOnly
  5332. * @default PIXI.SHAPES.RECT
  5333. * @see PIXI.SHAPES
  5334. */
  5335. this.type = exports.SHAPES.RECT;
  5336. }
  5337. Object.defineProperty(Rectangle.prototype, "left", {
  5338. /**
  5339. * returns the left edge of the rectangle
  5340. *
  5341. * @member {number}
  5342. */
  5343. get: function () {
  5344. return this.x;
  5345. },
  5346. enumerable: false,
  5347. configurable: true
  5348. });
  5349. Object.defineProperty(Rectangle.prototype, "right", {
  5350. /**
  5351. * returns the right edge of the rectangle
  5352. *
  5353. * @member {number}
  5354. */
  5355. get: function () {
  5356. return this.x + this.width;
  5357. },
  5358. enumerable: false,
  5359. configurable: true
  5360. });
  5361. Object.defineProperty(Rectangle.prototype, "top", {
  5362. /**
  5363. * returns the top edge of the rectangle
  5364. *
  5365. * @member {number}
  5366. */
  5367. get: function () {
  5368. return this.y;
  5369. },
  5370. enumerable: false,
  5371. configurable: true
  5372. });
  5373. Object.defineProperty(Rectangle.prototype, "bottom", {
  5374. /**
  5375. * returns the bottom edge of the rectangle
  5376. *
  5377. * @member {number}
  5378. */
  5379. get: function () {
  5380. return this.y + this.height;
  5381. },
  5382. enumerable: false,
  5383. configurable: true
  5384. });
  5385. Object.defineProperty(Rectangle, "EMPTY", {
  5386. /**
  5387. * A constant empty rectangle.
  5388. *
  5389. * @static
  5390. * @constant
  5391. * @member {PIXI.Rectangle}
  5392. * @return {PIXI.Rectangle} An empty rectangle
  5393. */
  5394. get: function () {
  5395. return new Rectangle(0, 0, 0, 0);
  5396. },
  5397. enumerable: false,
  5398. configurable: true
  5399. });
  5400. /**
  5401. * Creates a clone of this Rectangle
  5402. *
  5403. * @return {PIXI.Rectangle} a copy of the rectangle
  5404. */
  5405. Rectangle.prototype.clone = function () {
  5406. return new Rectangle(this.x, this.y, this.width, this.height);
  5407. };
  5408. /**
  5409. * Copies another rectangle to this one.
  5410. *
  5411. * @param {PIXI.Rectangle} rectangle - The rectangle to copy from.
  5412. * @return {PIXI.Rectangle} Returns itself.
  5413. */
  5414. Rectangle.prototype.copyFrom = function (rectangle) {
  5415. this.x = rectangle.x;
  5416. this.y = rectangle.y;
  5417. this.width = rectangle.width;
  5418. this.height = rectangle.height;
  5419. return this;
  5420. };
  5421. /**
  5422. * Copies this rectangle to another one.
  5423. *
  5424. * @param {PIXI.Rectangle} rectangle - The rectangle to copy to.
  5425. * @return {PIXI.Rectangle} Returns given parameter.
  5426. */
  5427. Rectangle.prototype.copyTo = function (rectangle) {
  5428. rectangle.x = this.x;
  5429. rectangle.y = this.y;
  5430. rectangle.width = this.width;
  5431. rectangle.height = this.height;
  5432. return rectangle;
  5433. };
  5434. /**
  5435. * Checks whether the x and y coordinates given are contained within this Rectangle
  5436. *
  5437. * @param {number} x - The X coordinate of the point to test
  5438. * @param {number} y - The Y coordinate of the point to test
  5439. * @return {boolean} Whether the x/y coordinates are within this Rectangle
  5440. */
  5441. Rectangle.prototype.contains = function (x, y) {
  5442. if (this.width <= 0 || this.height <= 0) {
  5443. return false;
  5444. }
  5445. if (x >= this.x && x < this.x + this.width) {
  5446. if (y >= this.y && y < this.y + this.height) {
  5447. return true;
  5448. }
  5449. }
  5450. return false;
  5451. };
  5452. /**
  5453. * Pads the rectangle making it grow in all directions.
  5454. * If paddingY is omitted, both paddingX and paddingY will be set to paddingX.
  5455. *
  5456. * @param {number} [paddingX=0] - The horizontal padding amount.
  5457. * @param {number} [paddingY=0] - The vertical padding amount.
  5458. * @return {PIXI.Rectangle} Returns itself.
  5459. */
  5460. Rectangle.prototype.pad = function (paddingX, paddingY) {
  5461. if (paddingX === void 0) { paddingX = 0; }
  5462. if (paddingY === void 0) { paddingY = paddingX; }
  5463. this.x -= paddingX;
  5464. this.y -= paddingY;
  5465. this.width += paddingX * 2;
  5466. this.height += paddingY * 2;
  5467. return this;
  5468. };
  5469. /**
  5470. * Fits this rectangle around the passed one.
  5471. *
  5472. * @param {PIXI.Rectangle} rectangle - The rectangle to fit.
  5473. * @return {PIXI.Rectangle} Returns itself.
  5474. */
  5475. Rectangle.prototype.fit = function (rectangle) {
  5476. var x1 = Math.max(this.x, rectangle.x);
  5477. var x2 = Math.min(this.x + this.width, rectangle.x + rectangle.width);
  5478. var y1 = Math.max(this.y, rectangle.y);
  5479. var y2 = Math.min(this.y + this.height, rectangle.y + rectangle.height);
  5480. this.x = x1;
  5481. this.width = Math.max(x2 - x1, 0);
  5482. this.y = y1;
  5483. this.height = Math.max(y2 - y1, 0);
  5484. return this;
  5485. };
  5486. /**
  5487. * Enlarges rectangle that way its corners lie on grid
  5488. *
  5489. * @param {number} [resolution=1] - resolution
  5490. * @param {number} [eps=0.001] - precision
  5491. * @return {PIXI.Rectangle} Returns itself.
  5492. */
  5493. Rectangle.prototype.ceil = function (resolution, eps) {
  5494. if (resolution === void 0) { resolution = 1; }
  5495. if (eps === void 0) { eps = 0.001; }
  5496. var x2 = Math.ceil((this.x + this.width - eps) * resolution) / resolution;
  5497. var y2 = Math.ceil((this.y + this.height - eps) * resolution) / resolution;
  5498. this.x = Math.floor((this.x + eps) * resolution) / resolution;
  5499. this.y = Math.floor((this.y + eps) * resolution) / resolution;
  5500. this.width = x2 - this.x;
  5501. this.height = y2 - this.y;
  5502. return this;
  5503. };
  5504. /**
  5505. * Enlarges this rectangle to include the passed rectangle.
  5506. *
  5507. * @param {PIXI.Rectangle} rectangle - The rectangle to include.
  5508. * @return {PIXI.Rectangle} Returns itself.
  5509. */
  5510. Rectangle.prototype.enlarge = function (rectangle) {
  5511. var x1 = Math.min(this.x, rectangle.x);
  5512. var x2 = Math.max(this.x + this.width, rectangle.x + rectangle.width);
  5513. var y1 = Math.min(this.y, rectangle.y);
  5514. var y2 = Math.max(this.y + this.height, rectangle.y + rectangle.height);
  5515. this.x = x1;
  5516. this.width = x2 - x1;
  5517. this.y = y1;
  5518. this.height = y2 - y1;
  5519. return this;
  5520. };
  5521. Rectangle.prototype.toString = function () {
  5522. return "[@pixi/math:Rectangle x=" + this.x + " y=" + this.y + " width=" + this.width + " height=" + this.height + "]";
  5523. };
  5524. return Rectangle;
  5525. }());
  5526. /**
  5527. * The Circle object is used to help draw graphics and can also be used to specify a hit area for displayObjects.
  5528. *
  5529. * @class
  5530. * @memberof PIXI
  5531. */
  5532. var Circle = /** @class */ (function () {
  5533. /**
  5534. * @param {number} [x=0] - The X coordinate of the center of this circle
  5535. * @param {number} [y=0] - The Y coordinate of the center of this circle
  5536. * @param {number} [radius=0] - The radius of the circle
  5537. */
  5538. function Circle(x, y, radius) {
  5539. if (x === void 0) { x = 0; }
  5540. if (y === void 0) { y = 0; }
  5541. if (radius === void 0) { radius = 0; }
  5542. /**
  5543. * @member {number}
  5544. * @default 0
  5545. */
  5546. this.x = x;
  5547. /**
  5548. * @member {number}
  5549. * @default 0
  5550. */
  5551. this.y = y;
  5552. /**
  5553. * @member {number}
  5554. * @default 0
  5555. */
  5556. this.radius = radius;
  5557. /**
  5558. * The type of the object, mainly used to avoid `instanceof` checks
  5559. *
  5560. * @member {number}
  5561. * @readOnly
  5562. * @default PIXI.SHAPES.CIRC
  5563. * @see PIXI.SHAPES
  5564. */
  5565. this.type = exports.SHAPES.CIRC;
  5566. }
  5567. /**
  5568. * Creates a clone of this Circle instance
  5569. *
  5570. * @return {PIXI.Circle} a copy of the Circle
  5571. */
  5572. Circle.prototype.clone = function () {
  5573. return new Circle(this.x, this.y, this.radius);
  5574. };
  5575. /**
  5576. * Checks whether the x and y coordinates given are contained within this circle
  5577. *
  5578. * @param {number} x - The X coordinate of the point to test
  5579. * @param {number} y - The Y coordinate of the point to test
  5580. * @return {boolean} Whether the x/y coordinates are within this Circle
  5581. */
  5582. Circle.prototype.contains = function (x, y) {
  5583. if (this.radius <= 0) {
  5584. return false;
  5585. }
  5586. var r2 = this.radius * this.radius;
  5587. var dx = (this.x - x);
  5588. var dy = (this.y - y);
  5589. dx *= dx;
  5590. dy *= dy;
  5591. return (dx + dy <= r2);
  5592. };
  5593. /**
  5594. * Returns the framing rectangle of the circle as a Rectangle object
  5595. *
  5596. * @return {PIXI.Rectangle} the framing rectangle
  5597. */
  5598. Circle.prototype.getBounds = function () {
  5599. return new Rectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2);
  5600. };
  5601. Circle.prototype.toString = function () {
  5602. return "[@pixi/math:Circle x=" + this.x + " y=" + this.y + " radius=" + this.radius + "]";
  5603. };
  5604. return Circle;
  5605. }());
  5606. /**
  5607. * The Ellipse object is used to help draw graphics and can also be used to specify a hit area for displayObjects.
  5608. *
  5609. * @class
  5610. * @memberof PIXI
  5611. */
  5612. var Ellipse = /** @class */ (function () {
  5613. /**
  5614. * @param {number} [x=0] - The X coordinate of the center of this ellipse
  5615. * @param {number} [y=0] - The Y coordinate of the center of this ellipse
  5616. * @param {number} [halfWidth=0] - The half width of this ellipse
  5617. * @param {number} [halfHeight=0] - The half height of this ellipse
  5618. */
  5619. function Ellipse(x, y, halfWidth, halfHeight) {
  5620. if (x === void 0) { x = 0; }
  5621. if (y === void 0) { y = 0; }
  5622. if (halfWidth === void 0) { halfWidth = 0; }
  5623. if (halfHeight === void 0) { halfHeight = 0; }
  5624. /**
  5625. * @member {number}
  5626. * @default 0
  5627. */
  5628. this.x = x;
  5629. /**
  5630. * @member {number}
  5631. * @default 0
  5632. */
  5633. this.y = y;
  5634. /**
  5635. * @member {number}
  5636. * @default 0
  5637. */
  5638. this.width = halfWidth;
  5639. /**
  5640. * @member {number}
  5641. * @default 0
  5642. */
  5643. this.height = halfHeight;
  5644. /**
  5645. * The type of the object, mainly used to avoid `instanceof` checks
  5646. *
  5647. * @member {number}
  5648. * @readOnly
  5649. * @default PIXI.SHAPES.ELIP
  5650. * @see PIXI.SHAPES
  5651. */
  5652. this.type = exports.SHAPES.ELIP;
  5653. }
  5654. /**
  5655. * Creates a clone of this Ellipse instance
  5656. *
  5657. * @return {PIXI.Ellipse} a copy of the ellipse
  5658. */
  5659. Ellipse.prototype.clone = function () {
  5660. return new Ellipse(this.x, this.y, this.width, this.height);
  5661. };
  5662. /**
  5663. * Checks whether the x and y coordinates given are contained within this ellipse
  5664. *
  5665. * @param {number} x - The X coordinate of the point to test
  5666. * @param {number} y - The Y coordinate of the point to test
  5667. * @return {boolean} Whether the x/y coords are within this ellipse
  5668. */
  5669. Ellipse.prototype.contains = function (x, y) {
  5670. if (this.width <= 0 || this.height <= 0) {
  5671. return false;
  5672. }
  5673. // normalize the coords to an ellipse with center 0,0
  5674. var normx = ((x - this.x) / this.width);
  5675. var normy = ((y - this.y) / this.height);
  5676. normx *= normx;
  5677. normy *= normy;
  5678. return (normx + normy <= 1);
  5679. };
  5680. /**
  5681. * Returns the framing rectangle of the ellipse as a Rectangle object
  5682. *
  5683. * @return {PIXI.Rectangle} the framing rectangle
  5684. */
  5685. Ellipse.prototype.getBounds = function () {
  5686. return new Rectangle(this.x - this.width, this.y - this.height, this.width, this.height);
  5687. };
  5688. Ellipse.prototype.toString = function () {
  5689. return "[@pixi/math:Ellipse x=" + this.x + " y=" + this.y + " width=" + this.width + " height=" + this.height + "]";
  5690. };
  5691. return Ellipse;
  5692. }());
  5693. /**
  5694. * A class to define a shape via user defined coordinates.
  5695. *
  5696. * @class
  5697. * @memberof PIXI
  5698. */
  5699. var Polygon = /** @class */ (function () {
  5700. /**
  5701. * @param {PIXI.IPointData[]|number[]} points - This can be an array of Points
  5702. * that form the polygon, a flat array of numbers that will be interpreted as [x,y, x,y, ...], or
  5703. * the arguments passed can be all the points of the polygon e.g.
  5704. * `new PIXI.Polygon(new PIXI.Point(), new PIXI.Point(), ...)`, or the arguments passed can be flat
  5705. * x,y values e.g. `new Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are Numbers.
  5706. */
  5707. function Polygon() {
  5708. var arguments$1 = arguments;
  5709. var points = [];
  5710. for (var _i = 0; _i < arguments.length; _i++) {
  5711. points[_i] = arguments$1[_i];
  5712. }
  5713. var flat = Array.isArray(points[0]) ? points[0] : points;
  5714. // if this is an array of points, convert it to a flat array of numbers
  5715. if (typeof flat[0] !== 'number') {
  5716. var p = [];
  5717. for (var i = 0, il = flat.length; i < il; i++) {
  5718. p.push(flat[i].x, flat[i].y);
  5719. }
  5720. flat = p;
  5721. }
  5722. /**
  5723. * An array of the points of this polygon
  5724. *
  5725. * @member {number[]}
  5726. */
  5727. this.points = flat;
  5728. /**
  5729. * The type of the object, mainly used to avoid `instanceof` checks
  5730. *
  5731. * @member {number}
  5732. * @readOnly
  5733. * @default PIXI.SHAPES.POLY
  5734. * @see PIXI.SHAPES
  5735. */
  5736. this.type = exports.SHAPES.POLY;
  5737. /**
  5738. * `false` after moveTo, `true` after `closePath`. In all other cases it is `true`.
  5739. * @member {boolean}
  5740. * @default true
  5741. */
  5742. this.closeStroke = true;
  5743. }
  5744. /**
  5745. * Creates a clone of this polygon
  5746. *
  5747. * @return {PIXI.Polygon} a copy of the polygon
  5748. */
  5749. Polygon.prototype.clone = function () {
  5750. var points = this.points.slice();
  5751. var polygon = new Polygon(points);
  5752. polygon.closeStroke = this.closeStroke;
  5753. return polygon;
  5754. };
  5755. /**
  5756. * Checks whether the x and y coordinates passed to this function are contained within this polygon
  5757. *
  5758. * @param {number} x - The X coordinate of the point to test
  5759. * @param {number} y - The Y coordinate of the point to test
  5760. * @return {boolean} Whether the x/y coordinates are within this polygon
  5761. */
  5762. Polygon.prototype.contains = function (x, y) {
  5763. var inside = false;
  5764. // use some raycasting to test hits
  5765. // https://github.com/substack/point-in-polygon/blob/master/index.js
  5766. var length = this.points.length / 2;
  5767. for (var i = 0, j = length - 1; i < length; j = i++) {
  5768. var xi = this.points[i * 2];
  5769. var yi = this.points[(i * 2) + 1];
  5770. var xj = this.points[j * 2];
  5771. var yj = this.points[(j * 2) + 1];
  5772. var intersect = ((yi > y) !== (yj > y)) && (x < ((xj - xi) * ((y - yi) / (yj - yi))) + xi);
  5773. if (intersect) {
  5774. inside = !inside;
  5775. }
  5776. }
  5777. return inside;
  5778. };
  5779. Polygon.prototype.toString = function () {
  5780. return "[@pixi/math:Polygon"
  5781. + ("closeStroke=" + this.closeStroke)
  5782. + ("points=" + this.points.reduce(function (pointsDesc, currentPoint) { return pointsDesc + ", " + currentPoint; }, '') + "]");
  5783. };
  5784. return Polygon;
  5785. }());
  5786. /**
  5787. * The Rounded Rectangle object is an area that has nice rounded corners, as indicated by its
  5788. * top-left corner point (x, y) and by its width and its height and its radius.
  5789. *
  5790. * @class
  5791. * @memberof PIXI
  5792. */
  5793. var RoundedRectangle = /** @class */ (function () {
  5794. /**
  5795. * @param {number} [x=0] - The X coordinate of the upper-left corner of the rounded rectangle
  5796. * @param {number} [y=0] - The Y coordinate of the upper-left corner of the rounded rectangle
  5797. * @param {number} [width=0] - The overall width of this rounded rectangle
  5798. * @param {number} [height=0] - The overall height of this rounded rectangle
  5799. * @param {number} [radius=20] - Controls the radius of the rounded corners
  5800. */
  5801. function RoundedRectangle(x, y, width, height, radius) {
  5802. if (x === void 0) { x = 0; }
  5803. if (y === void 0) { y = 0; }
  5804. if (width === void 0) { width = 0; }
  5805. if (height === void 0) { height = 0; }
  5806. if (radius === void 0) { radius = 20; }
  5807. /**
  5808. * @member {number}
  5809. * @default 0
  5810. */
  5811. this.x = x;
  5812. /**
  5813. * @member {number}
  5814. * @default 0
  5815. */
  5816. this.y = y;
  5817. /**
  5818. * @member {number}
  5819. * @default 0
  5820. */
  5821. this.width = width;
  5822. /**
  5823. * @member {number}
  5824. * @default 0
  5825. */
  5826. this.height = height;
  5827. /**
  5828. * @member {number}
  5829. * @default 20
  5830. */
  5831. this.radius = radius;
  5832. /**
  5833. * The type of the object, mainly used to avoid `instanceof` checks
  5834. *
  5835. * @member {number}
  5836. * @readonly
  5837. * @default PIXI.SHAPES.RREC
  5838. * @see PIXI.SHAPES
  5839. */
  5840. this.type = exports.SHAPES.RREC;
  5841. }
  5842. /**
  5843. * Creates a clone of this Rounded Rectangle
  5844. *
  5845. * @return {PIXI.RoundedRectangle} a copy of the rounded rectangle
  5846. */
  5847. RoundedRectangle.prototype.clone = function () {
  5848. return new RoundedRectangle(this.x, this.y, this.width, this.height, this.radius);
  5849. };
  5850. /**
  5851. * Checks whether the x and y coordinates given are contained within this Rounded Rectangle
  5852. *
  5853. * @param {number} x - The X coordinate of the point to test
  5854. * @param {number} y - The Y coordinate of the point to test
  5855. * @return {boolean} Whether the x/y coordinates are within this Rounded Rectangle
  5856. */
  5857. RoundedRectangle.prototype.contains = function (x, y) {
  5858. if (this.width <= 0 || this.height <= 0) {
  5859. return false;
  5860. }
  5861. if (x >= this.x && x <= this.x + this.width) {
  5862. if (y >= this.y && y <= this.y + this.height) {
  5863. if ((y >= this.y + this.radius && y <= this.y + this.height - this.radius)
  5864. || (x >= this.x + this.radius && x <= this.x + this.width - this.radius)) {
  5865. return true;
  5866. }
  5867. var dx = x - (this.x + this.radius);
  5868. var dy = y - (this.y + this.radius);
  5869. var radius2 = this.radius * this.radius;
  5870. if ((dx * dx) + (dy * dy) <= radius2) {
  5871. return true;
  5872. }
  5873. dx = x - (this.x + this.width - this.radius);
  5874. if ((dx * dx) + (dy * dy) <= radius2) {
  5875. return true;
  5876. }
  5877. dy = y - (this.y + this.height - this.radius);
  5878. if ((dx * dx) + (dy * dy) <= radius2) {
  5879. return true;
  5880. }
  5881. dx = x - (this.x + this.radius);
  5882. if ((dx * dx) + (dy * dy) <= radius2) {
  5883. return true;
  5884. }
  5885. }
  5886. }
  5887. return false;
  5888. };
  5889. RoundedRectangle.prototype.toString = function () {
  5890. return "[@pixi/math:RoundedRectangle x=" + this.x + " y=" + this.y
  5891. + ("width=" + this.width + " height=" + this.height + " radius=" + this.radius + "]");
  5892. };
  5893. return RoundedRectangle;
  5894. }());
  5895. /**
  5896. * The Point object represents a location in a two-dimensional coordinate system, where `x` represents
  5897. * the position on the horizontal axis and `y` represents the position on the vertical axis
  5898. *
  5899. * @class
  5900. * @memberof PIXI
  5901. * @implements IPoint
  5902. */
  5903. var Point = /** @class */ (function () {
  5904. /** Creates a new `Point`
  5905. * @param {number} [x=0] - position of the point on the x axis
  5906. * @param {number} [y=0] - position of the point on the y axis
  5907. */
  5908. function Point(x, y) {
  5909. if (x === void 0) { x = 0; }
  5910. if (y === void 0) { y = 0; }
  5911. /** Position of the point on the x axis */
  5912. this.x = 0;
  5913. /** Position of the point on the y axis */
  5914. this.y = 0;
  5915. this.x = x;
  5916. this.y = y;
  5917. }
  5918. /** Creates a clone of this point
  5919. * @returns A clone of this point
  5920. */
  5921. Point.prototype.clone = function () {
  5922. return new Point(this.x, this.y);
  5923. };
  5924. /**
  5925. * Copies `x` and `y` from the given point into this point
  5926. *
  5927. * @param p - The point to copy from
  5928. * @returns The point instance itself
  5929. */
  5930. Point.prototype.copyFrom = function (p) {
  5931. this.set(p.x, p.y);
  5932. return this;
  5933. };
  5934. /**
  5935. * Copies this point's x and y into the given point (`p`).
  5936. *
  5937. * @param p - The point to copy to. Can be any of type that is or extends `IPointData`
  5938. * @returns The point (`p`) with values updated
  5939. */
  5940. Point.prototype.copyTo = function (p) {
  5941. p.set(this.x, this.y);
  5942. return p;
  5943. };
  5944. /**
  5945. * Accepts another point (`p`) and returns `true` if the given point is equal to this point
  5946. *
  5947. * @param p - The point to check
  5948. * @returns Returns `true` if both `x` and `y` are equal
  5949. */
  5950. Point.prototype.equals = function (p) {
  5951. return (p.x === this.x) && (p.y === this.y);
  5952. };
  5953. /**
  5954. * Sets the point to a new `x` and `y` position.
  5955. * If `y` is omitted, both `x` and `y` will be set to `x`.
  5956. *
  5957. * @param {number} [x=0] - position of the point on the `x` axis
  5958. * @param {number} [y=x] - position of the point on the `y` axis
  5959. * @returns The point instance itself
  5960. */
  5961. Point.prototype.set = function (x, y) {
  5962. if (x === void 0) { x = 0; }
  5963. if (y === void 0) { y = x; }
  5964. this.x = x;
  5965. this.y = y;
  5966. return this;
  5967. };
  5968. Point.prototype.toString = function () {
  5969. return "[@pixi/math:Point x=" + this.x + " y=" + this.y + "]";
  5970. };
  5971. return Point;
  5972. }());
  5973. /**
  5974. * The ObservablePoint object represents a location in a two-dimensional coordinate system, where `x` represents
  5975. * the position on the horizontal axis and `y` represents the position on the vertical axis.
  5976. *
  5977. * An `ObservablePoint` is a point that triggers a callback when the point's position is changed.
  5978. *
  5979. * @class
  5980. * @memberof PIXI
  5981. * @implements IPoint
  5982. */
  5983. var ObservablePoint = /** @class */ (function () {
  5984. /**
  5985. * Creates a new `ObservablePoint`
  5986. *
  5987. * @param cb - callback function triggered when `x` and/or `y` are changed
  5988. * @param scope - owner of callback
  5989. * @param {number} [x=0] - position of the point on the x axis
  5990. * @param {number} [y=0] - position of the point on the y axis
  5991. */
  5992. function ObservablePoint(cb, scope, x, y) {
  5993. if (x === void 0) { x = 0; }
  5994. if (y === void 0) { y = 0; }
  5995. this._x = x;
  5996. this._y = y;
  5997. this.cb = cb;
  5998. this.scope = scope;
  5999. }
  6000. /**
  6001. * Creates a clone of this point.
  6002. * The callback and scope params can be overridden otherwise they will default
  6003. * to the clone object's values.
  6004. *
  6005. * @override
  6006. * @param cb - The callback function triggered when `x` and/or `y` are changed
  6007. * @param scope - The owner of the callback
  6008. * @return a copy of this observable point
  6009. */
  6010. ObservablePoint.prototype.clone = function (cb, scope) {
  6011. if (cb === void 0) { cb = this.cb; }
  6012. if (scope === void 0) { scope = this.scope; }
  6013. return new ObservablePoint(cb, scope, this._x, this._y);
  6014. };
  6015. /**
  6016. * Sets the point to a new `x` and `y` position.
  6017. * If `y` is omitted, both `x` and `y` will be set to `x`.
  6018. *
  6019. * @param {number} [x=0] - position of the point on the x axis
  6020. * @param {number} [y=x] - position of the point on the y axis
  6021. * @returns The observable point instance itself
  6022. */
  6023. ObservablePoint.prototype.set = function (x, y) {
  6024. if (x === void 0) { x = 0; }
  6025. if (y === void 0) { y = x; }
  6026. if (this._x !== x || this._y !== y) {
  6027. this._x = x;
  6028. this._y = y;
  6029. this.cb.call(this.scope);
  6030. }
  6031. return this;
  6032. };
  6033. /**
  6034. * Copies x and y from the given point (`p`)
  6035. *
  6036. * @param p - The point to copy from. Can be any of type that is or extends `IPointData`
  6037. * @returns The observable point instance itself
  6038. */
  6039. ObservablePoint.prototype.copyFrom = function (p) {
  6040. if (this._x !== p.x || this._y !== p.y) {
  6041. this._x = p.x;
  6042. this._y = p.y;
  6043. this.cb.call(this.scope);
  6044. }
  6045. return this;
  6046. };
  6047. /**
  6048. * Copies this point's x and y into that of the given point (`p`)
  6049. *
  6050. * @param p - The point to copy to. Can be any of type that is or extends `IPointData`
  6051. * @returns The point (`p`) with values updated
  6052. */
  6053. ObservablePoint.prototype.copyTo = function (p) {
  6054. p.set(this._x, this._y);
  6055. return p;
  6056. };
  6057. /**
  6058. * Accepts another point (`p`) and returns `true` if the given point is equal to this point
  6059. *
  6060. * @param p - The point to check
  6061. * @returns Returns `true` if both `x` and `y` are equal
  6062. */
  6063. ObservablePoint.prototype.equals = function (p) {
  6064. return (p.x === this._x) && (p.y === this._y);
  6065. };
  6066. ObservablePoint.prototype.toString = function () {
  6067. return "[@pixi/math:ObservablePoint x=" + 0 + " y=" + 0 + " scope=" + this.scope + "]";
  6068. };
  6069. Object.defineProperty(ObservablePoint.prototype, "x", {
  6070. /** Position of the observable point on the x axis
  6071. * @type {number}
  6072. */
  6073. get: function () {
  6074. return this._x;
  6075. },
  6076. set: function (value) {
  6077. if (this._x !== value) {
  6078. this._x = value;
  6079. this.cb.call(this.scope);
  6080. }
  6081. },
  6082. enumerable: false,
  6083. configurable: true
  6084. });
  6085. Object.defineProperty(ObservablePoint.prototype, "y", {
  6086. /** Position of the observable point on the y axis
  6087. * @type {number}
  6088. */
  6089. get: function () {
  6090. return this._y;
  6091. },
  6092. set: function (value) {
  6093. if (this._y !== value) {
  6094. this._y = value;
  6095. this.cb.call(this.scope);
  6096. }
  6097. },
  6098. enumerable: false,
  6099. configurable: true
  6100. });
  6101. return ObservablePoint;
  6102. }());
  6103. /**
  6104. * The PixiJS Matrix as a class makes it a lot faster.
  6105. *
  6106. * Here is a representation of it:
  6107. * ```js
  6108. * | a | c | tx|
  6109. * | b | d | ty|
  6110. * | 0 | 0 | 1 |
  6111. * ```
  6112. * @class
  6113. * @memberof PIXI
  6114. */
  6115. var Matrix = /** @class */ (function () {
  6116. /**
  6117. * @param {number} [a=1] - x scale
  6118. * @param {number} [b=0] - y skew
  6119. * @param {number} [c=0] - x skew
  6120. * @param {number} [d=1] - y scale
  6121. * @param {number} [tx=0] - x translation
  6122. * @param {number} [ty=0] - y translation
  6123. */
  6124. function Matrix(a, b, c, d, tx, ty) {
  6125. if (a === void 0) { a = 1; }
  6126. if (b === void 0) { b = 0; }
  6127. if (c === void 0) { c = 0; }
  6128. if (d === void 0) { d = 1; }
  6129. if (tx === void 0) { tx = 0; }
  6130. if (ty === void 0) { ty = 0; }
  6131. this.array = null;
  6132. /**
  6133. * @member {number}
  6134. * @default 1
  6135. */
  6136. this.a = a;
  6137. /**
  6138. * @member {number}
  6139. * @default 0
  6140. */
  6141. this.b = b;
  6142. /**
  6143. * @member {number}
  6144. * @default 0
  6145. */
  6146. this.c = c;
  6147. /**
  6148. * @member {number}
  6149. * @default 1
  6150. */
  6151. this.d = d;
  6152. /**
  6153. * @member {number}
  6154. * @default 0
  6155. */
  6156. this.tx = tx;
  6157. /**
  6158. * @member {number}
  6159. * @default 0
  6160. */
  6161. this.ty = ty;
  6162. }
  6163. /**
  6164. * Creates a Matrix object based on the given array. The Element to Matrix mapping order is as follows:
  6165. *
  6166. * a = array[0]
  6167. * b = array[1]
  6168. * c = array[3]
  6169. * d = array[4]
  6170. * tx = array[2]
  6171. * ty = array[5]
  6172. *
  6173. * @param {number[]} array - The array that the matrix will be populated from.
  6174. */
  6175. Matrix.prototype.fromArray = function (array) {
  6176. this.a = array[0];
  6177. this.b = array[1];
  6178. this.c = array[3];
  6179. this.d = array[4];
  6180. this.tx = array[2];
  6181. this.ty = array[5];
  6182. };
  6183. /**
  6184. * sets the matrix properties
  6185. *
  6186. * @param {number} a - Matrix component
  6187. * @param {number} b - Matrix component
  6188. * @param {number} c - Matrix component
  6189. * @param {number} d - Matrix component
  6190. * @param {number} tx - Matrix component
  6191. * @param {number} ty - Matrix component
  6192. *
  6193. * @return {PIXI.Matrix} This matrix. Good for chaining method calls.
  6194. */
  6195. Matrix.prototype.set = function (a, b, c, d, tx, ty) {
  6196. this.a = a;
  6197. this.b = b;
  6198. this.c = c;
  6199. this.d = d;
  6200. this.tx = tx;
  6201. this.ty = ty;
  6202. return this;
  6203. };
  6204. /**
  6205. * Creates an array from the current Matrix object.
  6206. *
  6207. * @param {boolean} transpose - Whether we need to transpose the matrix or not
  6208. * @param {Float32Array} [out=new Float32Array(9)] - If provided the array will be assigned to out
  6209. * @return {number[]} the newly created array which contains the matrix
  6210. */
  6211. Matrix.prototype.toArray = function (transpose, out) {
  6212. if (!this.array) {
  6213. this.array = new Float32Array(9);
  6214. }
  6215. var array = out || this.array;
  6216. if (transpose) {
  6217. array[0] = this.a;
  6218. array[1] = this.b;
  6219. array[2] = 0;
  6220. array[3] = this.c;
  6221. array[4] = this.d;
  6222. array[5] = 0;
  6223. array[6] = this.tx;
  6224. array[7] = this.ty;
  6225. array[8] = 1;
  6226. }
  6227. else {
  6228. array[0] = this.a;
  6229. array[1] = this.c;
  6230. array[2] = this.tx;
  6231. array[3] = this.b;
  6232. array[4] = this.d;
  6233. array[5] = this.ty;
  6234. array[6] = 0;
  6235. array[7] = 0;
  6236. array[8] = 1;
  6237. }
  6238. return array;
  6239. };
  6240. /**
  6241. * Get a new position with the current transformation applied.
  6242. * Can be used to go from a child's coordinate space to the world coordinate space. (e.g. rendering)
  6243. *
  6244. * @param {PIXI.IPointData} pos - The origin
  6245. * @param {PIXI.Point} [newPos] - The point that the new position is assigned to (allowed to be same as input)
  6246. * @return {PIXI.Point} The new point, transformed through this matrix
  6247. */
  6248. Matrix.prototype.apply = function (pos, newPos) {
  6249. newPos = (newPos || new Point());
  6250. var x = pos.x;
  6251. var y = pos.y;
  6252. newPos.x = (this.a * x) + (this.c * y) + this.tx;
  6253. newPos.y = (this.b * x) + (this.d * y) + this.ty;
  6254. return newPos;
  6255. };
  6256. /**
  6257. * Get a new position with the inverse of the current transformation applied.
  6258. * Can be used to go from the world coordinate space to a child's coordinate space. (e.g. input)
  6259. *
  6260. * @param {PIXI.IPointData} pos - The origin
  6261. * @param {PIXI.Point} [newPos] - The point that the new position is assigned to (allowed to be same as input)
  6262. * @return {PIXI.Point} The new point, inverse-transformed through this matrix
  6263. */
  6264. Matrix.prototype.applyInverse = function (pos, newPos) {
  6265. newPos = (newPos || new Point());
  6266. var id = 1 / ((this.a * this.d) + (this.c * -this.b));
  6267. var x = pos.x;
  6268. var y = pos.y;
  6269. newPos.x = (this.d * id * x) + (-this.c * id * y) + (((this.ty * this.c) - (this.tx * this.d)) * id);
  6270. newPos.y = (this.a * id * y) + (-this.b * id * x) + (((-this.ty * this.a) + (this.tx * this.b)) * id);
  6271. return newPos;
  6272. };
  6273. /**
  6274. * Translates the matrix on the x and y.
  6275. *
  6276. * @param {number} x - How much to translate x by
  6277. * @param {number} y - How much to translate y by
  6278. * @return {PIXI.Matrix} This matrix. Good for chaining method calls.
  6279. */
  6280. Matrix.prototype.translate = function (x, y) {
  6281. this.tx += x;
  6282. this.ty += y;
  6283. return this;
  6284. };
  6285. /**
  6286. * Applies a scale transformation to the matrix.
  6287. *
  6288. * @param {number} x - The amount to scale horizontally
  6289. * @param {number} y - The amount to scale vertically
  6290. * @return {PIXI.Matrix} This matrix. Good for chaining method calls.
  6291. */
  6292. Matrix.prototype.scale = function (x, y) {
  6293. this.a *= x;
  6294. this.d *= y;
  6295. this.c *= x;
  6296. this.b *= y;
  6297. this.tx *= x;
  6298. this.ty *= y;
  6299. return this;
  6300. };
  6301. /**
  6302. * Applies a rotation transformation to the matrix.
  6303. *
  6304. * @param {number} angle - The angle in radians.
  6305. * @return {PIXI.Matrix} This matrix. Good for chaining method calls.
  6306. */
  6307. Matrix.prototype.rotate = function (angle) {
  6308. var cos = Math.cos(angle);
  6309. var sin = Math.sin(angle);
  6310. var a1 = this.a;
  6311. var c1 = this.c;
  6312. var tx1 = this.tx;
  6313. this.a = (a1 * cos) - (this.b * sin);
  6314. this.b = (a1 * sin) + (this.b * cos);
  6315. this.c = (c1 * cos) - (this.d * sin);
  6316. this.d = (c1 * sin) + (this.d * cos);
  6317. this.tx = (tx1 * cos) - (this.ty * sin);
  6318. this.ty = (tx1 * sin) + (this.ty * cos);
  6319. return this;
  6320. };
  6321. /**
  6322. * Appends the given Matrix to this Matrix.
  6323. *
  6324. * @param {PIXI.Matrix} matrix - The matrix to append.
  6325. * @return {PIXI.Matrix} This matrix. Good for chaining method calls.
  6326. */
  6327. Matrix.prototype.append = function (matrix) {
  6328. var a1 = this.a;
  6329. var b1 = this.b;
  6330. var c1 = this.c;
  6331. var d1 = this.d;
  6332. this.a = (matrix.a * a1) + (matrix.b * c1);
  6333. this.b = (matrix.a * b1) + (matrix.b * d1);
  6334. this.c = (matrix.c * a1) + (matrix.d * c1);
  6335. this.d = (matrix.c * b1) + (matrix.d * d1);
  6336. this.tx = (matrix.tx * a1) + (matrix.ty * c1) + this.tx;
  6337. this.ty = (matrix.tx * b1) + (matrix.ty * d1) + this.ty;
  6338. return this;
  6339. };
  6340. /**
  6341. * Sets the matrix based on all the available properties
  6342. *
  6343. * @param {number} x - Position on the x axis
  6344. * @param {number} y - Position on the y axis
  6345. * @param {number} pivotX - Pivot on the x axis
  6346. * @param {number} pivotY - Pivot on the y axis
  6347. * @param {number} scaleX - Scale on the x axis
  6348. * @param {number} scaleY - Scale on the y axis
  6349. * @param {number} rotation - Rotation in radians
  6350. * @param {number} skewX - Skew on the x axis
  6351. * @param {number} skewY - Skew on the y axis
  6352. * @return {PIXI.Matrix} This matrix. Good for chaining method calls.
  6353. */
  6354. Matrix.prototype.setTransform = function (x, y, pivotX, pivotY, scaleX, scaleY, rotation, skewX, skewY) {
  6355. this.a = Math.cos(rotation + skewY) * scaleX;
  6356. this.b = Math.sin(rotation + skewY) * scaleX;
  6357. this.c = -Math.sin(rotation - skewX) * scaleY;
  6358. this.d = Math.cos(rotation - skewX) * scaleY;
  6359. this.tx = x - ((pivotX * this.a) + (pivotY * this.c));
  6360. this.ty = y - ((pivotX * this.b) + (pivotY * this.d));
  6361. return this;
  6362. };
  6363. /**
  6364. * Prepends the given Matrix to this Matrix.
  6365. *
  6366. * @param {PIXI.Matrix} matrix - The matrix to prepend
  6367. * @return {PIXI.Matrix} This matrix. Good for chaining method calls.
  6368. */
  6369. Matrix.prototype.prepend = function (matrix) {
  6370. var tx1 = this.tx;
  6371. if (matrix.a !== 1 || matrix.b !== 0 || matrix.c !== 0 || matrix.d !== 1) {
  6372. var a1 = this.a;
  6373. var c1 = this.c;
  6374. this.a = (a1 * matrix.a) + (this.b * matrix.c);
  6375. this.b = (a1 * matrix.b) + (this.b * matrix.d);
  6376. this.c = (c1 * matrix.a) + (this.d * matrix.c);
  6377. this.d = (c1 * matrix.b) + (this.d * matrix.d);
  6378. }
  6379. this.tx = (tx1 * matrix.a) + (this.ty * matrix.c) + matrix.tx;
  6380. this.ty = (tx1 * matrix.b) + (this.ty * matrix.d) + matrix.ty;
  6381. return this;
  6382. };
  6383. /**
  6384. * Decomposes the matrix (x, y, scaleX, scaleY, and rotation) and sets the properties on to a transform.
  6385. *
  6386. * @param {PIXI.Transform} transform - The transform to apply the properties to.
  6387. * @return {PIXI.Transform} The transform with the newly applied properties
  6388. */
  6389. Matrix.prototype.decompose = function (transform) {
  6390. // sort out rotation / skew..
  6391. var a = this.a;
  6392. var b = this.b;
  6393. var c = this.c;
  6394. var d = this.d;
  6395. var pivot = transform.pivot;
  6396. var skewX = -Math.atan2(-c, d);
  6397. var skewY = Math.atan2(b, a);
  6398. var delta = Math.abs(skewX + skewY);
  6399. if (delta < 0.00001 || Math.abs(PI_2 - delta) < 0.00001) {
  6400. transform.rotation = skewY;
  6401. transform.skew.x = transform.skew.y = 0;
  6402. }
  6403. else {
  6404. transform.rotation = 0;
  6405. transform.skew.x = skewX;
  6406. transform.skew.y = skewY;
  6407. }
  6408. // next set scale
  6409. transform.scale.x = Math.sqrt((a * a) + (b * b));
  6410. transform.scale.y = Math.sqrt((c * c) + (d * d));
  6411. // next set position
  6412. transform.position.x = this.tx + ((pivot.x * a) + (pivot.y * c));
  6413. transform.position.y = this.ty + ((pivot.x * b) + (pivot.y * d));
  6414. return transform;
  6415. };
  6416. /**
  6417. * Inverts this matrix
  6418. *
  6419. * @return {PIXI.Matrix} This matrix. Good for chaining method calls.
  6420. */
  6421. Matrix.prototype.invert = function () {
  6422. var a1 = this.a;
  6423. var b1 = this.b;
  6424. var c1 = this.c;
  6425. var d1 = this.d;
  6426. var tx1 = this.tx;
  6427. var n = (a1 * d1) - (b1 * c1);
  6428. this.a = d1 / n;
  6429. this.b = -b1 / n;
  6430. this.c = -c1 / n;
  6431. this.d = a1 / n;
  6432. this.tx = ((c1 * this.ty) - (d1 * tx1)) / n;
  6433. this.ty = -((a1 * this.ty) - (b1 * tx1)) / n;
  6434. return this;
  6435. };
  6436. /**
  6437. * Resets this Matrix to an identity (default) matrix.
  6438. *
  6439. * @return {PIXI.Matrix} This matrix. Good for chaining method calls.
  6440. */
  6441. Matrix.prototype.identity = function () {
  6442. this.a = 1;
  6443. this.b = 0;
  6444. this.c = 0;
  6445. this.d = 1;
  6446. this.tx = 0;
  6447. this.ty = 0;
  6448. return this;
  6449. };
  6450. /**
  6451. * Creates a new Matrix object with the same values as this one.
  6452. *
  6453. * @return {PIXI.Matrix} A copy of this matrix. Good for chaining method calls.
  6454. */
  6455. Matrix.prototype.clone = function () {
  6456. var matrix = new Matrix();
  6457. matrix.a = this.a;
  6458. matrix.b = this.b;
  6459. matrix.c = this.c;
  6460. matrix.d = this.d;
  6461. matrix.tx = this.tx;
  6462. matrix.ty = this.ty;
  6463. return matrix;
  6464. };
  6465. /**
  6466. * Changes the values of the given matrix to be the same as the ones in this matrix
  6467. *
  6468. * @param {PIXI.Matrix} matrix - The matrix to copy to.
  6469. * @return {PIXI.Matrix} The matrix given in parameter with its values updated.
  6470. */
  6471. Matrix.prototype.copyTo = function (matrix) {
  6472. matrix.a = this.a;
  6473. matrix.b = this.b;
  6474. matrix.c = this.c;
  6475. matrix.d = this.d;
  6476. matrix.tx = this.tx;
  6477. matrix.ty = this.ty;
  6478. return matrix;
  6479. };
  6480. /**
  6481. * Changes the values of the matrix to be the same as the ones in given matrix
  6482. *
  6483. * @param {PIXI.Matrix} matrix - The matrix to copy from.
  6484. * @return {PIXI.Matrix} this
  6485. */
  6486. Matrix.prototype.copyFrom = function (matrix) {
  6487. this.a = matrix.a;
  6488. this.b = matrix.b;
  6489. this.c = matrix.c;
  6490. this.d = matrix.d;
  6491. this.tx = matrix.tx;
  6492. this.ty = matrix.ty;
  6493. return this;
  6494. };
  6495. Matrix.prototype.toString = function () {
  6496. return "[@pixi/math:Matrix a=" + this.a + " b=" + this.b + " c=" + this.c + " d=" + this.d + " tx=" + this.tx + " ty=" + this.ty + "]";
  6497. };
  6498. Object.defineProperty(Matrix, "IDENTITY", {
  6499. /**
  6500. * A default (identity) matrix
  6501. *
  6502. * @static
  6503. * @const
  6504. * @member {PIXI.Matrix}
  6505. */
  6506. get: function () {
  6507. return new Matrix();
  6508. },
  6509. enumerable: false,
  6510. configurable: true
  6511. });
  6512. Object.defineProperty(Matrix, "TEMP_MATRIX", {
  6513. /**
  6514. * A temp matrix
  6515. *
  6516. * @static
  6517. * @const
  6518. * @member {PIXI.Matrix}
  6519. */
  6520. get: function () {
  6521. return new Matrix();
  6522. },
  6523. enumerable: false,
  6524. configurable: true
  6525. });
  6526. return Matrix;
  6527. }());
  6528. // Your friendly neighbour https://en.wikipedia.org/wiki/Dihedral_group
  6529. /*
  6530. * Transform matrix for operation n is:
  6531. * | ux | vx |
  6532. * | uy | vy |
  6533. */
  6534. var ux = [1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1];
  6535. var uy = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1];
  6536. var vx = [0, -1, -1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 0, -1, -1, -1];
  6537. var vy = [1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 0, 1, 1, 1, 0, -1];
  6538. /**
  6539. * [Cayley Table]{@link https://en.wikipedia.org/wiki/Cayley_table}
  6540. * for the composition of each rotation in the dihederal group D8.
  6541. *
  6542. * @type number[][]
  6543. * @private
  6544. */
  6545. var rotationCayley = [];
  6546. /**
  6547. * Matrices for each `GD8Symmetry` rotation.
  6548. *
  6549. * @type Matrix[]
  6550. * @private
  6551. */
  6552. var rotationMatrices = [];
  6553. /*
  6554. * Alias for {@code Math.sign}.
  6555. */
  6556. var signum = Math.sign;
  6557. /*
  6558. * Initializes `rotationCayley` and `rotationMatrices`. It is called
  6559. * only once below.
  6560. */
  6561. function init() {
  6562. for (var i = 0; i < 16; i++) {
  6563. var row = [];
  6564. rotationCayley.push(row);
  6565. for (var j = 0; j < 16; j++) {
  6566. /* Multiplies rotation matrices i and j. */
  6567. var _ux = signum((ux[i] * ux[j]) + (vx[i] * uy[j]));
  6568. var _uy = signum((uy[i] * ux[j]) + (vy[i] * uy[j]));
  6569. var _vx = signum((ux[i] * vx[j]) + (vx[i] * vy[j]));
  6570. var _vy = signum((uy[i] * vx[j]) + (vy[i] * vy[j]));
  6571. /* Finds rotation matrix matching the product and pushes it. */
  6572. for (var k = 0; k < 16; k++) {
  6573. if (ux[k] === _ux && uy[k] === _uy
  6574. && vx[k] === _vx && vy[k] === _vy) {
  6575. row.push(k);
  6576. break;
  6577. }
  6578. }
  6579. }
  6580. }
  6581. for (var i = 0; i < 16; i++) {
  6582. var mat = new Matrix();
  6583. mat.set(ux[i], uy[i], vx[i], vy[i], 0, 0);
  6584. rotationMatrices.push(mat);
  6585. }
  6586. }
  6587. init();
  6588. /**
  6589. * @memberof PIXI
  6590. * @typedef {number} GD8Symmetry
  6591. * @see PIXI.groupD8
  6592. */
  6593. /**
  6594. * Implements the dihedral group D8, which is similar to
  6595. * [group D4]{@link http://mathworld.wolfram.com/DihedralGroupD4.html};
  6596. * D8 is the same but with diagonals, and it is used for texture
  6597. * rotations.
  6598. *
  6599. * The directions the U- and V- axes after rotation
  6600. * of an angle of `a: GD8Constant` are the vectors `(uX(a), uY(a))`
  6601. * and `(vX(a), vY(a))`. These aren't necessarily unit vectors.
  6602. *
  6603. * **Origin:**<br>
  6604. * This is the small part of gameofbombs.com portal system. It works.
  6605. *
  6606. * @see PIXI.groupD8.E
  6607. * @see PIXI.groupD8.SE
  6608. * @see PIXI.groupD8.S
  6609. * @see PIXI.groupD8.SW
  6610. * @see PIXI.groupD8.W
  6611. * @see PIXI.groupD8.NW
  6612. * @see PIXI.groupD8.N
  6613. * @see PIXI.groupD8.NE
  6614. * @author Ivan @ivanpopelyshev
  6615. * @namespace PIXI.groupD8
  6616. * @memberof PIXI
  6617. */
  6618. var groupD8 = {
  6619. /**
  6620. * | Rotation | Direction |
  6621. * |----------|-----------|
  6622. * | 0° | East |
  6623. *
  6624. * @memberof PIXI.groupD8
  6625. * @constant {PIXI.GD8Symmetry}
  6626. */
  6627. E: 0,
  6628. /**
  6629. * | Rotation | Direction |
  6630. * |----------|-----------|
  6631. * | 45°↻ | Southeast |
  6632. *
  6633. * @memberof PIXI.groupD8
  6634. * @constant {PIXI.GD8Symmetry}
  6635. */
  6636. SE: 1,
  6637. /**
  6638. * | Rotation | Direction |
  6639. * |----------|-----------|
  6640. * | 90°↻ | South |
  6641. *
  6642. * @memberof PIXI.groupD8
  6643. * @constant {PIXI.GD8Symmetry}
  6644. */
  6645. S: 2,
  6646. /**
  6647. * | Rotation | Direction |
  6648. * |----------|-----------|
  6649. * | 135°↻ | Southwest |
  6650. *
  6651. * @memberof PIXI.groupD8
  6652. * @constant {PIXI.GD8Symmetry}
  6653. */
  6654. SW: 3,
  6655. /**
  6656. * | Rotation | Direction |
  6657. * |----------|-----------|
  6658. * | 180° | West |
  6659. *
  6660. * @memberof PIXI.groupD8
  6661. * @constant {PIXI.GD8Symmetry}
  6662. */
  6663. W: 4,
  6664. /**
  6665. * | Rotation | Direction |
  6666. * |-------------|--------------|
  6667. * | -135°/225°↻ | Northwest |
  6668. *
  6669. * @memberof PIXI.groupD8
  6670. * @constant {PIXI.GD8Symmetry}
  6671. */
  6672. NW: 5,
  6673. /**
  6674. * | Rotation | Direction |
  6675. * |-------------|--------------|
  6676. * | -90°/270°↻ | North |
  6677. *
  6678. * @memberof PIXI.groupD8
  6679. * @constant {PIXI.GD8Symmetry}
  6680. */
  6681. N: 6,
  6682. /**
  6683. * | Rotation | Direction |
  6684. * |-------------|--------------|
  6685. * | -45°/315°↻ | Northeast |
  6686. *
  6687. * @memberof PIXI.groupD8
  6688. * @constant {PIXI.GD8Symmetry}
  6689. */
  6690. NE: 7,
  6691. /**
  6692. * Reflection about Y-axis.
  6693. *
  6694. * @memberof PIXI.groupD8
  6695. * @constant {PIXI.GD8Symmetry}
  6696. */
  6697. MIRROR_VERTICAL: 8,
  6698. /**
  6699. * Reflection about the main diagonal.
  6700. *
  6701. * @memberof PIXI.groupD8
  6702. * @constant {PIXI.GD8Symmetry}
  6703. */
  6704. MAIN_DIAGONAL: 10,
  6705. /**
  6706. * Reflection about X-axis.
  6707. *
  6708. * @memberof PIXI.groupD8
  6709. * @constant {PIXI.GD8Symmetry}
  6710. */
  6711. MIRROR_HORIZONTAL: 12,
  6712. /**
  6713. * Reflection about reverse diagonal.
  6714. *
  6715. * @memberof PIXI.groupD8
  6716. * @constant {PIXI.GD8Symmetry}
  6717. */
  6718. REVERSE_DIAGONAL: 14,
  6719. /**
  6720. * @memberof PIXI.groupD8
  6721. * @param {PIXI.GD8Symmetry} ind - sprite rotation angle.
  6722. * @return {PIXI.GD8Symmetry} The X-component of the U-axis
  6723. * after rotating the axes.
  6724. */
  6725. uX: function (ind) { return ux[ind]; },
  6726. /**
  6727. * @memberof PIXI.groupD8
  6728. * @param {PIXI.GD8Symmetry} ind - sprite rotation angle.
  6729. * @return {PIXI.GD8Symmetry} The Y-component of the U-axis
  6730. * after rotating the axes.
  6731. */
  6732. uY: function (ind) { return uy[ind]; },
  6733. /**
  6734. * @memberof PIXI.groupD8
  6735. * @param {PIXI.GD8Symmetry} ind - sprite rotation angle.
  6736. * @return {PIXI.GD8Symmetry} The X-component of the V-axis
  6737. * after rotating the axes.
  6738. */
  6739. vX: function (ind) { return vx[ind]; },
  6740. /**
  6741. * @memberof PIXI.groupD8
  6742. * @param {PIXI.GD8Symmetry} ind - sprite rotation angle.
  6743. * @return {PIXI.GD8Symmetry} The Y-component of the V-axis
  6744. * after rotating the axes.
  6745. */
  6746. vY: function (ind) { return vy[ind]; },
  6747. /**
  6748. * @memberof PIXI.groupD8
  6749. * @param {PIXI.GD8Symmetry} rotation - symmetry whose opposite
  6750. * is needed. Only rotations have opposite symmetries while
  6751. * reflections don't.
  6752. * @return {PIXI.GD8Symmetry} The opposite symmetry of `rotation`
  6753. */
  6754. inv: function (rotation) {
  6755. if (rotation & 8) // true only if between 8 & 15 (reflections)
  6756. {
  6757. return rotation & 15; // or rotation % 16
  6758. }
  6759. return (-rotation) & 7; // or (8 - rotation) % 8
  6760. },
  6761. /**
  6762. * Composes the two D8 operations.
  6763. *
  6764. * Taking `^` as reflection:
  6765. *
  6766. * | | E=0 | S=2 | W=4 | N=6 | E^=8 | S^=10 | W^=12 | N^=14 |
  6767. * |-------|-----|-----|-----|-----|------|-------|-------|-------|
  6768. * | E=0 | E | S | W | N | E^ | S^ | W^ | N^ |
  6769. * | S=2 | S | W | N | E | S^ | W^ | N^ | E^ |
  6770. * | W=4 | W | N | E | S | W^ | N^ | E^ | S^ |
  6771. * | N=6 | N | E | S | W | N^ | E^ | S^ | W^ |
  6772. * | E^=8 | E^ | N^ | W^ | S^ | E | N | W | S |
  6773. * | S^=10 | S^ | E^ | N^ | W^ | S | E | N | W |
  6774. * | W^=12 | W^ | S^ | E^ | N^ | W | S | E | N |
  6775. * | N^=14 | N^ | W^ | S^ | E^ | N | W | S | E |
  6776. *
  6777. * [This is a Cayley table]{@link https://en.wikipedia.org/wiki/Cayley_table}
  6778. * @memberof PIXI.groupD8
  6779. * @param {PIXI.GD8Symmetry} rotationSecond - Second operation, which
  6780. * is the row in the above cayley table.
  6781. * @param {PIXI.GD8Symmetry} rotationFirst - First operation, which
  6782. * is the column in the above cayley table.
  6783. * @return {PIXI.GD8Symmetry} Composed operation
  6784. */
  6785. add: function (rotationSecond, rotationFirst) { return (rotationCayley[rotationSecond][rotationFirst]); },
  6786. /**
  6787. * Reverse of `add`.
  6788. *
  6789. * @memberof PIXI.groupD8
  6790. * @param {PIXI.GD8Symmetry} rotationSecond - Second operation
  6791. * @param {PIXI.GD8Symmetry} rotationFirst - First operation
  6792. * @return {PIXI.GD8Symmetry} Result
  6793. */
  6794. sub: function (rotationSecond, rotationFirst) { return (rotationCayley[rotationSecond][groupD8.inv(rotationFirst)]); },
  6795. /**
  6796. * Adds 180 degrees to rotation, which is a commutative
  6797. * operation.
  6798. *
  6799. * @memberof PIXI.groupD8
  6800. * @param {number} rotation - The number to rotate.
  6801. * @returns {number} Rotated number
  6802. */
  6803. rotate180: function (rotation) { return rotation ^ 4; },
  6804. /**
  6805. * Checks if the rotation angle is vertical, i.e. south
  6806. * or north. It doesn't work for reflections.
  6807. *
  6808. * @memberof PIXI.groupD8
  6809. * @param {PIXI.GD8Symmetry} rotation - The number to check.
  6810. * @returns {boolean} Whether or not the direction is vertical
  6811. */
  6812. isVertical: function (rotation) { return (rotation & 3) === 2; },
  6813. /**
  6814. * Approximates the vector `V(dx,dy)` into one of the
  6815. * eight directions provided by `groupD8`.
  6816. *
  6817. * @memberof PIXI.groupD8
  6818. * @param {number} dx - X-component of the vector
  6819. * @param {number} dy - Y-component of the vector
  6820. * @return {PIXI.GD8Symmetry} Approximation of the vector into
  6821. * one of the eight symmetries.
  6822. */
  6823. byDirection: function (dx, dy) {
  6824. if (Math.abs(dx) * 2 <= Math.abs(dy)) {
  6825. if (dy >= 0) {
  6826. return groupD8.S;
  6827. }
  6828. return groupD8.N;
  6829. }
  6830. else if (Math.abs(dy) * 2 <= Math.abs(dx)) {
  6831. if (dx > 0) {
  6832. return groupD8.E;
  6833. }
  6834. return groupD8.W;
  6835. }
  6836. else if (dy > 0) {
  6837. if (dx > 0) {
  6838. return groupD8.SE;
  6839. }
  6840. return groupD8.SW;
  6841. }
  6842. else if (dx > 0) {
  6843. return groupD8.NE;
  6844. }
  6845. return groupD8.NW;
  6846. },
  6847. /**
  6848. * Helps sprite to compensate texture packer rotation.
  6849. *
  6850. * @memberof PIXI.groupD8
  6851. * @param {PIXI.Matrix} matrix - sprite world matrix
  6852. * @param {PIXI.GD8Symmetry} rotation - The rotation factor to use.
  6853. * @param {number} tx - sprite anchoring
  6854. * @param {number} ty - sprite anchoring
  6855. */
  6856. matrixAppendRotationInv: function (matrix, rotation, tx, ty) {
  6857. if (tx === void 0) { tx = 0; }
  6858. if (ty === void 0) { ty = 0; }
  6859. // Packer used "rotation", we use "inv(rotation)"
  6860. var mat = rotationMatrices[groupD8.inv(rotation)];
  6861. mat.tx = tx;
  6862. mat.ty = ty;
  6863. matrix.append(mat);
  6864. },
  6865. };
  6866. /**
  6867. * Transform that takes care about its versions
  6868. *
  6869. * @class
  6870. * @memberof PIXI
  6871. */
  6872. var Transform = /** @class */ (function () {
  6873. function Transform() {
  6874. /**
  6875. * The world transformation matrix.
  6876. *
  6877. * @member {PIXI.Matrix}
  6878. */
  6879. this.worldTransform = new Matrix();
  6880. /**
  6881. * The local transformation matrix.
  6882. *
  6883. * @member {PIXI.Matrix}
  6884. */
  6885. this.localTransform = new Matrix();
  6886. /**
  6887. * The coordinate of the object relative to the local coordinates of the parent.
  6888. *
  6889. * @member {PIXI.ObservablePoint}
  6890. */
  6891. this.position = new ObservablePoint(this.onChange, this, 0, 0);
  6892. /**
  6893. * The scale factor of the object.
  6894. *
  6895. * @member {PIXI.ObservablePoint}
  6896. */
  6897. this.scale = new ObservablePoint(this.onChange, this, 1, 1);
  6898. /**
  6899. * The pivot point of the displayObject that it rotates around.
  6900. *
  6901. * @member {PIXI.ObservablePoint}
  6902. */
  6903. this.pivot = new ObservablePoint(this.onChange, this, 0, 0);
  6904. /**
  6905. * The skew amount, on the x and y axis.
  6906. *
  6907. * @member {PIXI.ObservablePoint}
  6908. */
  6909. this.skew = new ObservablePoint(this.updateSkew, this, 0, 0);
  6910. /**
  6911. * The rotation amount.
  6912. *
  6913. * @protected
  6914. * @member {number}
  6915. */
  6916. this._rotation = 0;
  6917. /**
  6918. * The X-coordinate value of the normalized local X axis,
  6919. * the first column of the local transformation matrix without a scale.
  6920. *
  6921. * @protected
  6922. * @member {number}
  6923. */
  6924. this._cx = 1;
  6925. /**
  6926. * The Y-coordinate value of the normalized local X axis,
  6927. * the first column of the local transformation matrix without a scale.
  6928. *
  6929. * @protected
  6930. * @member {number}
  6931. */
  6932. this._sx = 0;
  6933. /**
  6934. * The X-coordinate value of the normalized local Y axis,
  6935. * the second column of the local transformation matrix without a scale.
  6936. *
  6937. * @protected
  6938. * @member {number}
  6939. */
  6940. this._cy = 0;
  6941. /**
  6942. * The Y-coordinate value of the normalized local Y axis,
  6943. * the second column of the local transformation matrix without a scale.
  6944. *
  6945. * @protected
  6946. * @member {number}
  6947. */
  6948. this._sy = 1;
  6949. /**
  6950. * The locally unique ID of the local transform.
  6951. *
  6952. * @protected
  6953. * @member {number}
  6954. */
  6955. this._localID = 0;
  6956. /**
  6957. * The locally unique ID of the local transform
  6958. * used to calculate the current local transformation matrix.
  6959. *
  6960. * @protected
  6961. * @member {number}
  6962. */
  6963. this._currentLocalID = 0;
  6964. /**
  6965. * The locally unique ID of the world transform.
  6966. *
  6967. * @protected
  6968. * @member {number}
  6969. */
  6970. this._worldID = 0;
  6971. /**
  6972. * The locally unique ID of the parent's world transform
  6973. * used to calculate the current world transformation matrix.
  6974. *
  6975. * @protected
  6976. * @member {number}
  6977. */
  6978. this._parentID = 0;
  6979. }
  6980. /**
  6981. * Called when a value changes.
  6982. *
  6983. * @protected
  6984. */
  6985. Transform.prototype.onChange = function () {
  6986. this._localID++;
  6987. };
  6988. /**
  6989. * Called when the skew or the rotation changes.
  6990. *
  6991. * @protected
  6992. */
  6993. Transform.prototype.updateSkew = function () {
  6994. this._cx = Math.cos(this._rotation + this.skew.y);
  6995. this._sx = Math.sin(this._rotation + this.skew.y);
  6996. this._cy = -Math.sin(this._rotation - this.skew.x); // cos, added PI/2
  6997. this._sy = Math.cos(this._rotation - this.skew.x); // sin, added PI/2
  6998. this._localID++;
  6999. };
  7000. Transform.prototype.toString = function () {
  7001. return "[@pixi/math:Transform "
  7002. + ("position=(" + this.position.x + ", " + this.position.y + ") ")
  7003. + ("rotation=" + this.rotation + " ")
  7004. + ("scale=(" + this.scale.x + ", " + this.scale.y + ") ")
  7005. + ("skew=(" + this.skew.x + ", " + this.skew.y + ") ")
  7006. + "]";
  7007. };
  7008. /**
  7009. * Updates the local transformation matrix.
  7010. */
  7011. Transform.prototype.updateLocalTransform = function () {
  7012. var lt = this.localTransform;
  7013. if (this._localID !== this._currentLocalID) {
  7014. // get the matrix values of the displayobject based on its transform properties..
  7015. lt.a = this._cx * this.scale.x;
  7016. lt.b = this._sx * this.scale.x;
  7017. lt.c = this._cy * this.scale.y;
  7018. lt.d = this._sy * this.scale.y;
  7019. lt.tx = this.position.x - ((this.pivot.x * lt.a) + (this.pivot.y * lt.c));
  7020. lt.ty = this.position.y - ((this.pivot.x * lt.b) + (this.pivot.y * lt.d));
  7021. this._currentLocalID = this._localID;
  7022. // force an update..
  7023. this._parentID = -1;
  7024. }
  7025. };
  7026. /**
  7027. * Updates the local and the world transformation matrices.
  7028. *
  7029. * @param {PIXI.Transform} parentTransform - The parent transform
  7030. */
  7031. Transform.prototype.updateTransform = function (parentTransform) {
  7032. var lt = this.localTransform;
  7033. if (this._localID !== this._currentLocalID) {
  7034. // get the matrix values of the displayobject based on its transform properties..
  7035. lt.a = this._cx * this.scale.x;
  7036. lt.b = this._sx * this.scale.x;
  7037. lt.c = this._cy * this.scale.y;
  7038. lt.d = this._sy * this.scale.y;
  7039. lt.tx = this.position.x - ((this.pivot.x * lt.a) + (this.pivot.y * lt.c));
  7040. lt.ty = this.position.y - ((this.pivot.x * lt.b) + (this.pivot.y * lt.d));
  7041. this._currentLocalID = this._localID;
  7042. // force an update..
  7043. this._parentID = -1;
  7044. }
  7045. if (this._parentID !== parentTransform._worldID) {
  7046. // concat the parent matrix with the objects transform.
  7047. var pt = parentTransform.worldTransform;
  7048. var wt = this.worldTransform;
  7049. wt.a = (lt.a * pt.a) + (lt.b * pt.c);
  7050. wt.b = (lt.a * pt.b) + (lt.b * pt.d);
  7051. wt.c = (lt.c * pt.a) + (lt.d * pt.c);
  7052. wt.d = (lt.c * pt.b) + (lt.d * pt.d);
  7053. wt.tx = (lt.tx * pt.a) + (lt.ty * pt.c) + pt.tx;
  7054. wt.ty = (lt.tx * pt.b) + (lt.ty * pt.d) + pt.ty;
  7055. this._parentID = parentTransform._worldID;
  7056. // update the id of the transform..
  7057. this._worldID++;
  7058. }
  7059. };
  7060. /**
  7061. * Decomposes a matrix and sets the transforms properties based on it.
  7062. *
  7063. * @param {PIXI.Matrix} matrix - The matrix to decompose
  7064. */
  7065. Transform.prototype.setFromMatrix = function (matrix) {
  7066. matrix.decompose(this);
  7067. this._localID++;
  7068. };
  7069. Object.defineProperty(Transform.prototype, "rotation", {
  7070. /**
  7071. * The rotation of the object in radians.
  7072. *
  7073. * @member {number}
  7074. */
  7075. get: function () {
  7076. return this._rotation;
  7077. },
  7078. set: function (value) {
  7079. if (this._rotation !== value) {
  7080. this._rotation = value;
  7081. this.updateSkew();
  7082. }
  7083. },
  7084. enumerable: false,
  7085. configurable: true
  7086. });
  7087. /**
  7088. * A default (identity) transform
  7089. *
  7090. * @static
  7091. * @constant
  7092. * @member {PIXI.Transform}
  7093. */
  7094. Transform.IDENTITY = new Transform();
  7095. return Transform;
  7096. }());
  7097. /*!
  7098. * @pixi/display - v6.1.2
  7099. * Compiled Thu, 12 Aug 2021 17:11:19 UTC
  7100. *
  7101. * @pixi/display is licensed under the MIT License.
  7102. * http://www.opensource.org/licenses/mit-license
  7103. */
  7104. /**
  7105. * Sets the default value for the container property 'sortableChildren'.
  7106. * If set to true, the container will sort its children by zIndex value
  7107. * when updateTransform() is called, or manually if sortChildren() is called.
  7108. *
  7109. * This actually changes the order of elements in the array, so should be treated
  7110. * as a basic solution that is not performant compared to other solutions,
  7111. * such as @link https://github.com/pixijs/pixi-display
  7112. *
  7113. * Also be aware of that this may not work nicely with the addChildAt() function,
  7114. * as the zIndex sorting may cause the child to automatically sorted to another position.
  7115. *
  7116. * @static
  7117. * @constant
  7118. * @name SORTABLE_CHILDREN
  7119. * @memberof PIXI.settings
  7120. * @type {boolean}
  7121. * @default false
  7122. */
  7123. settings.SORTABLE_CHILDREN = false;
  7124. /**
  7125. * 'Builder' pattern for bounds rectangles.
  7126. *
  7127. * This could be called an Axis-Aligned Bounding Box.
  7128. * It is not an actual shape. It is a mutable thing; no 'EMPTY' or those kind of problems.
  7129. *
  7130. * @class
  7131. * @memberof PIXI
  7132. */
  7133. var Bounds = /** @class */ (function () {
  7134. function Bounds() {
  7135. /**
  7136. * @member {number}
  7137. * @default 0
  7138. */
  7139. this.minX = Infinity;
  7140. /**
  7141. * @member {number}
  7142. * @default 0
  7143. */
  7144. this.minY = Infinity;
  7145. /**
  7146. * @member {number}
  7147. * @default 0
  7148. */
  7149. this.maxX = -Infinity;
  7150. /**
  7151. * @member {number}
  7152. * @default 0
  7153. */
  7154. this.maxY = -Infinity;
  7155. this.rect = null;
  7156. /**
  7157. * It is updated to _boundsID of corresponding object to keep bounds in sync with content.
  7158. * Updated from outside, thus public modifier.
  7159. *
  7160. * @member {number}
  7161. * @public
  7162. */
  7163. this.updateID = -1;
  7164. }
  7165. /**
  7166. * Checks if bounds are empty.
  7167. *
  7168. * @return {boolean} True if empty.
  7169. */
  7170. Bounds.prototype.isEmpty = function () {
  7171. return this.minX > this.maxX || this.minY > this.maxY;
  7172. };
  7173. /**
  7174. * Clears the bounds and resets.
  7175. *
  7176. */
  7177. Bounds.prototype.clear = function () {
  7178. this.minX = Infinity;
  7179. this.minY = Infinity;
  7180. this.maxX = -Infinity;
  7181. this.maxY = -Infinity;
  7182. };
  7183. /**
  7184. * Can return Rectangle.EMPTY constant, either construct new rectangle, either use your rectangle
  7185. * It is not guaranteed that it will return tempRect
  7186. *
  7187. * @param {PIXI.Rectangle} rect - temporary object will be used if AABB is not empty
  7188. * @returns {PIXI.Rectangle} A rectangle of the bounds
  7189. */
  7190. Bounds.prototype.getRectangle = function (rect) {
  7191. if (this.minX > this.maxX || this.minY > this.maxY) {
  7192. return Rectangle.EMPTY;
  7193. }
  7194. rect = rect || new Rectangle(0, 0, 1, 1);
  7195. rect.x = this.minX;
  7196. rect.y = this.minY;
  7197. rect.width = this.maxX - this.minX;
  7198. rect.height = this.maxY - this.minY;
  7199. return rect;
  7200. };
  7201. /**
  7202. * This function should be inlined when its possible.
  7203. *
  7204. * @param {PIXI.IPointData} point - The point to add.
  7205. */
  7206. Bounds.prototype.addPoint = function (point) {
  7207. this.minX = Math.min(this.minX, point.x);
  7208. this.maxX = Math.max(this.maxX, point.x);
  7209. this.minY = Math.min(this.minY, point.y);
  7210. this.maxY = Math.max(this.maxY, point.y);
  7211. };
  7212. /**
  7213. * Adds a point, after transformed. This should be inlined when its possible.
  7214. *
  7215. * @param matrix
  7216. * @param point
  7217. */
  7218. Bounds.prototype.addPointMatrix = function (matrix, point) {
  7219. var a = matrix.a, b = matrix.b, c = matrix.c, d = matrix.d, tx = matrix.tx, ty = matrix.ty;
  7220. var x = (a * point.x) + (c * point.y) + tx;
  7221. var y = (b * point.x) + (d * point.y) + ty;
  7222. this.minX = Math.min(this.minX, x);
  7223. this.maxX = Math.max(this.maxX, x);
  7224. this.minY = Math.min(this.minY, y);
  7225. this.maxY = Math.max(this.maxY, y);
  7226. };
  7227. /**
  7228. * Adds a quad, not transformed
  7229. *
  7230. * @param {Float32Array} vertices - The verts to add.
  7231. */
  7232. Bounds.prototype.addQuad = function (vertices) {
  7233. var minX = this.minX;
  7234. var minY = this.minY;
  7235. var maxX = this.maxX;
  7236. var maxY = this.maxY;
  7237. var x = vertices[0];
  7238. var y = vertices[1];
  7239. minX = x < minX ? x : minX;
  7240. minY = y < minY ? y : minY;
  7241. maxX = x > maxX ? x : maxX;
  7242. maxY = y > maxY ? y : maxY;
  7243. x = vertices[2];
  7244. y = vertices[3];
  7245. minX = x < minX ? x : minX;
  7246. minY = y < minY ? y : minY;
  7247. maxX = x > maxX ? x : maxX;
  7248. maxY = y > maxY ? y : maxY;
  7249. x = vertices[4];
  7250. y = vertices[5];
  7251. minX = x < minX ? x : minX;
  7252. minY = y < minY ? y : minY;
  7253. maxX = x > maxX ? x : maxX;
  7254. maxY = y > maxY ? y : maxY;
  7255. x = vertices[6];
  7256. y = vertices[7];
  7257. minX = x < minX ? x : minX;
  7258. minY = y < minY ? y : minY;
  7259. maxX = x > maxX ? x : maxX;
  7260. maxY = y > maxY ? y : maxY;
  7261. this.minX = minX;
  7262. this.minY = minY;
  7263. this.maxX = maxX;
  7264. this.maxY = maxY;
  7265. };
  7266. /**
  7267. * Adds sprite frame, transformed.
  7268. *
  7269. * @param {PIXI.Transform} transform - transform to apply
  7270. * @param {number} x0 - left X of frame
  7271. * @param {number} y0 - top Y of frame
  7272. * @param {number} x1 - right X of frame
  7273. * @param {number} y1 - bottom Y of frame
  7274. */
  7275. Bounds.prototype.addFrame = function (transform, x0, y0, x1, y1) {
  7276. this.addFrameMatrix(transform.worldTransform, x0, y0, x1, y1);
  7277. };
  7278. /**
  7279. * Adds sprite frame, multiplied by matrix
  7280. *
  7281. * @param {PIXI.Matrix} matrix - matrix to apply
  7282. * @param {number} x0 - left X of frame
  7283. * @param {number} y0 - top Y of frame
  7284. * @param {number} x1 - right X of frame
  7285. * @param {number} y1 - bottom Y of frame
  7286. */
  7287. Bounds.prototype.addFrameMatrix = function (matrix, x0, y0, x1, y1) {
  7288. var a = matrix.a;
  7289. var b = matrix.b;
  7290. var c = matrix.c;
  7291. var d = matrix.d;
  7292. var tx = matrix.tx;
  7293. var ty = matrix.ty;
  7294. var minX = this.minX;
  7295. var minY = this.minY;
  7296. var maxX = this.maxX;
  7297. var maxY = this.maxY;
  7298. var x = (a * x0) + (c * y0) + tx;
  7299. var y = (b * x0) + (d * y0) + ty;
  7300. minX = x < minX ? x : minX;
  7301. minY = y < minY ? y : minY;
  7302. maxX = x > maxX ? x : maxX;
  7303. maxY = y > maxY ? y : maxY;
  7304. x = (a * x1) + (c * y0) + tx;
  7305. y = (b * x1) + (d * y0) + ty;
  7306. minX = x < minX ? x : minX;
  7307. minY = y < minY ? y : minY;
  7308. maxX = x > maxX ? x : maxX;
  7309. maxY = y > maxY ? y : maxY;
  7310. x = (a * x0) + (c * y1) + tx;
  7311. y = (b * x0) + (d * y1) + ty;
  7312. minX = x < minX ? x : minX;
  7313. minY = y < minY ? y : minY;
  7314. maxX = x > maxX ? x : maxX;
  7315. maxY = y > maxY ? y : maxY;
  7316. x = (a * x1) + (c * y1) + tx;
  7317. y = (b * x1) + (d * y1) + ty;
  7318. minX = x < minX ? x : minX;
  7319. minY = y < minY ? y : minY;
  7320. maxX = x > maxX ? x : maxX;
  7321. maxY = y > maxY ? y : maxY;
  7322. this.minX = minX;
  7323. this.minY = minY;
  7324. this.maxX = maxX;
  7325. this.maxY = maxY;
  7326. };
  7327. /**
  7328. * Adds screen vertices from array
  7329. *
  7330. * @param {Float32Array} vertexData - calculated vertices
  7331. * @param {number} beginOffset - begin offset
  7332. * @param {number} endOffset - end offset, excluded
  7333. */
  7334. Bounds.prototype.addVertexData = function (vertexData, beginOffset, endOffset) {
  7335. var minX = this.minX;
  7336. var minY = this.minY;
  7337. var maxX = this.maxX;
  7338. var maxY = this.maxY;
  7339. for (var i = beginOffset; i < endOffset; i += 2) {
  7340. var x = vertexData[i];
  7341. var y = vertexData[i + 1];
  7342. minX = x < minX ? x : minX;
  7343. minY = y < minY ? y : minY;
  7344. maxX = x > maxX ? x : maxX;
  7345. maxY = y > maxY ? y : maxY;
  7346. }
  7347. this.minX = minX;
  7348. this.minY = minY;
  7349. this.maxX = maxX;
  7350. this.maxY = maxY;
  7351. };
  7352. /**
  7353. * Add an array of mesh vertices
  7354. *
  7355. * @param {PIXI.Transform} transform - mesh transform
  7356. * @param {Float32Array} vertices - mesh coordinates in array
  7357. * @param {number} beginOffset - begin offset
  7358. * @param {number} endOffset - end offset, excluded
  7359. */
  7360. Bounds.prototype.addVertices = function (transform, vertices, beginOffset, endOffset) {
  7361. this.addVerticesMatrix(transform.worldTransform, vertices, beginOffset, endOffset);
  7362. };
  7363. /**
  7364. * Add an array of mesh vertices.
  7365. *
  7366. * @param {PIXI.Matrix} matrix - mesh matrix
  7367. * @param {Float32Array} vertices - mesh coordinates in array
  7368. * @param {number} beginOffset - begin offset
  7369. * @param {number} endOffset - end offset, excluded
  7370. * @param {number} [padX=0] - x padding
  7371. * @param {number} [padY=0] - y padding
  7372. */
  7373. Bounds.prototype.addVerticesMatrix = function (matrix, vertices, beginOffset, endOffset, padX, padY) {
  7374. if (padX === void 0) { padX = 0; }
  7375. if (padY === void 0) { padY = padX; }
  7376. var a = matrix.a;
  7377. var b = matrix.b;
  7378. var c = matrix.c;
  7379. var d = matrix.d;
  7380. var tx = matrix.tx;
  7381. var ty = matrix.ty;
  7382. var minX = this.minX;
  7383. var minY = this.minY;
  7384. var maxX = this.maxX;
  7385. var maxY = this.maxY;
  7386. for (var i = beginOffset; i < endOffset; i += 2) {
  7387. var rawX = vertices[i];
  7388. var rawY = vertices[i + 1];
  7389. var x = (a * rawX) + (c * rawY) + tx;
  7390. var y = (d * rawY) + (b * rawX) + ty;
  7391. minX = Math.min(minX, x - padX);
  7392. maxX = Math.max(maxX, x + padX);
  7393. minY = Math.min(minY, y - padY);
  7394. maxY = Math.max(maxY, y + padY);
  7395. }
  7396. this.minX = minX;
  7397. this.minY = minY;
  7398. this.maxX = maxX;
  7399. this.maxY = maxY;
  7400. };
  7401. /**
  7402. * Adds other Bounds.
  7403. *
  7404. * @param {PIXI.Bounds} bounds - The Bounds to be added
  7405. */
  7406. Bounds.prototype.addBounds = function (bounds) {
  7407. var minX = this.minX;
  7408. var minY = this.minY;
  7409. var maxX = this.maxX;
  7410. var maxY = this.maxY;
  7411. this.minX = bounds.minX < minX ? bounds.minX : minX;
  7412. this.minY = bounds.minY < minY ? bounds.minY : minY;
  7413. this.maxX = bounds.maxX > maxX ? bounds.maxX : maxX;
  7414. this.maxY = bounds.maxY > maxY ? bounds.maxY : maxY;
  7415. };
  7416. /**
  7417. * Adds other Bounds, masked with Bounds.
  7418. *
  7419. * @param {PIXI.Bounds} bounds - The Bounds to be added.
  7420. * @param {PIXI.Bounds} mask - TODO
  7421. */
  7422. Bounds.prototype.addBoundsMask = function (bounds, mask) {
  7423. var _minX = bounds.minX > mask.minX ? bounds.minX : mask.minX;
  7424. var _minY = bounds.minY > mask.minY ? bounds.minY : mask.minY;
  7425. var _maxX = bounds.maxX < mask.maxX ? bounds.maxX : mask.maxX;
  7426. var _maxY = bounds.maxY < mask.maxY ? bounds.maxY : mask.maxY;
  7427. if (_minX <= _maxX && _minY <= _maxY) {
  7428. var minX = this.minX;
  7429. var minY = this.minY;
  7430. var maxX = this.maxX;
  7431. var maxY = this.maxY;
  7432. this.minX = _minX < minX ? _minX : minX;
  7433. this.minY = _minY < minY ? _minY : minY;
  7434. this.maxX = _maxX > maxX ? _maxX : maxX;
  7435. this.maxY = _maxY > maxY ? _maxY : maxY;
  7436. }
  7437. };
  7438. /**
  7439. * Adds other Bounds, multiplied by matrix. Bounds shouldn't be empty.
  7440. *
  7441. * @param {PIXI.Bounds} bounds - other bounds
  7442. * @param {PIXI.Matrix} matrix - multiplicator
  7443. */
  7444. Bounds.prototype.addBoundsMatrix = function (bounds, matrix) {
  7445. this.addFrameMatrix(matrix, bounds.minX, bounds.minY, bounds.maxX, bounds.maxY);
  7446. };
  7447. /**
  7448. * Adds other Bounds, masked with Rectangle.
  7449. *
  7450. * @param {PIXI.Bounds} bounds - TODO
  7451. * @param {PIXI.Rectangle} area - TODO
  7452. */
  7453. Bounds.prototype.addBoundsArea = function (bounds, area) {
  7454. var _minX = bounds.minX > area.x ? bounds.minX : area.x;
  7455. var _minY = bounds.minY > area.y ? bounds.minY : area.y;
  7456. var _maxX = bounds.maxX < area.x + area.width ? bounds.maxX : (area.x + area.width);
  7457. var _maxY = bounds.maxY < area.y + area.height ? bounds.maxY : (area.y + area.height);
  7458. if (_minX <= _maxX && _minY <= _maxY) {
  7459. var minX = this.minX;
  7460. var minY = this.minY;
  7461. var maxX = this.maxX;
  7462. var maxY = this.maxY;
  7463. this.minX = _minX < minX ? _minX : minX;
  7464. this.minY = _minY < minY ? _minY : minY;
  7465. this.maxX = _maxX > maxX ? _maxX : maxX;
  7466. this.maxY = _maxY > maxY ? _maxY : maxY;
  7467. }
  7468. };
  7469. /**
  7470. * Pads bounds object, making it grow in all directions.
  7471. * If paddingY is omitted, both paddingX and paddingY will be set to paddingX.
  7472. *
  7473. * @param {number} [paddingX=0] - The horizontal padding amount.
  7474. * @param {number} [paddingY=0] - The vertical padding amount.
  7475. */
  7476. Bounds.prototype.pad = function (paddingX, paddingY) {
  7477. if (paddingX === void 0) { paddingX = 0; }
  7478. if (paddingY === void 0) { paddingY = paddingX; }
  7479. if (!this.isEmpty()) {
  7480. this.minX -= paddingX;
  7481. this.maxX += paddingX;
  7482. this.minY -= paddingY;
  7483. this.maxY += paddingY;
  7484. }
  7485. };
  7486. /**
  7487. * Adds padded frame. (x0, y0) should be strictly less than (x1, y1)
  7488. *
  7489. * @param {number} x0 - left X of frame
  7490. * @param {number} y0 - top Y of frame
  7491. * @param {number} x1 - right X of frame
  7492. * @param {number} y1 - bottom Y of frame
  7493. * @param {number} padX - padding X
  7494. * @param {number} padY - padding Y
  7495. */
  7496. Bounds.prototype.addFramePad = function (x0, y0, x1, y1, padX, padY) {
  7497. x0 -= padX;
  7498. y0 -= padY;
  7499. x1 += padX;
  7500. y1 += padY;
  7501. this.minX = this.minX < x0 ? this.minX : x0;
  7502. this.maxX = this.maxX > x1 ? this.maxX : x1;
  7503. this.minY = this.minY < y0 ? this.minY : y0;
  7504. this.maxY = this.maxY > y1 ? this.maxY : y1;
  7505. };
  7506. return Bounds;
  7507. }());
  7508. /*! *****************************************************************************
  7509. Copyright (c) Microsoft Corporation. All rights reserved.
  7510. Licensed under the Apache License, Version 2.0 (the "License"); you may not use
  7511. this file except in compliance with the License. You may obtain a copy of the
  7512. License at http://www.apache.org/licenses/LICENSE-2.0
  7513. THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  7514. KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
  7515. WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
  7516. MERCHANTABLITY OR NON-INFRINGEMENT.
  7517. See the Apache Version 2.0 License for specific language governing permissions
  7518. and limitations under the License.
  7519. ***************************************************************************** */
  7520. /* global Reflect, Promise */
  7521. var extendStatics = function(d, b) {
  7522. extendStatics = Object.setPrototypeOf ||
  7523. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  7524. function (d, b) { for (var p in b) { if (b.hasOwnProperty(p)) { d[p] = b[p]; } } };
  7525. return extendStatics(d, b);
  7526. };
  7527. function __extends(d, b) {
  7528. extendStatics(d, b);
  7529. function __() { this.constructor = d; }
  7530. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  7531. }
  7532. /**
  7533. * The base class for all objects that are rendered on the screen.
  7534. *
  7535. * This is an abstract class and can not be used on its own; rather it should be extended.
  7536. *
  7537. * ## Display objects implemented in PixiJS
  7538. *
  7539. * | Display Object | Description |
  7540. * | ------------------------------- | --------------------------------------------------------------------- |
  7541. * | {@link PIXI.Container} | Adds support for `children` to DisplayObject |
  7542. * | {@link PIXI.Graphics} | Shape-drawing display object similar to the Canvas API |
  7543. * | {@link PIXI.Sprite} | Draws textures (i.e. images) |
  7544. * | {@link PIXI.Text} | Draws text using the Canvas API internally |
  7545. * | {@link PIXI.BitmapText} | More scaleable solution for text rendering, reusing glyph textures |
  7546. * | {@link PIXI.TilingSprite} | Draws textures/images in a tiled fashion |
  7547. * | {@link PIXI.AnimatedSprite} | Draws an animation of multiple images |
  7548. * | {@link PIXI.Mesh} | Provides a lower-level API for drawing meshes with custom data |
  7549. * | {@link PIXI.NineSlicePlane} | Mesh-related |
  7550. * | {@link PIXI.SimpleMesh} | v4-compatibile mesh |
  7551. * | {@link PIXI.SimplePlane} | Mesh-related |
  7552. * | {@link PIXI.SimpleRope} | Mesh-related |
  7553. *
  7554. * ## Transforms
  7555. *
  7556. * The [transform]{@link DisplayObject#transform} of a display object describes the projection from its
  7557. * local coordinate space to its parent's local coordinate space. The following properties are derived
  7558. * from the transform:
  7559. *
  7560. * <table>
  7561. * <thead>
  7562. * <tr>
  7563. * <th>Property</th>
  7564. * <th>Description</th>
  7565. * </tr>
  7566. * </thead>
  7567. * <tbody>
  7568. * <tr>
  7569. * <td>[pivot]{@link PIXI.DisplayObject#pivot}</td>
  7570. * <td>
  7571. * Invariant under rotation, scaling, and skewing. The projection of into the parent's space of the pivot
  7572. * is equal to position, regardless of the other three transformations. In other words, It is the center of
  7573. * rotation, scaling, and skewing.
  7574. * </td>
  7575. * </tr>
  7576. * <tr>
  7577. * <td>[position]{@link PIXI.DisplayObject#position}</td>
  7578. * <td>
  7579. * Translation. This is the position of the [pivot]{@link PIXI.DisplayObject#pivot} in the parent's local
  7580. * space. The default value of the pivot is the origin (0,0). If the top-left corner of your display object
  7581. * is (0,0) in its local space, then the position will be its top-left corner in the parent's local space.
  7582. * </td>
  7583. * </tr>
  7584. * <tr>
  7585. * <td>[scale]{@link PIXI.DisplayObject#scale}</td>
  7586. * <td>
  7587. * Scaling. This will stretch (or compress) the display object's projection. The scale factors are along the
  7588. * local coordinate axes. In other words, the display object is scaled before rotated or skewed. The center
  7589. * of scaling is the [pivot]{@link PIXI.DisplayObject#pivot}.
  7590. * </td>
  7591. * </tr>
  7592. * <tr>
  7593. * <td>[rotation]{@link PIXI.DisplayObject#rotation}</td>
  7594. * <td>
  7595. * Rotation. This will rotate the display object's projection by this angle (in radians).
  7596. * </td>
  7597. * </tr>
  7598. * <tr>
  7599. * <td>[skew]{@link PIXI.DisplayObject#skew}</td>
  7600. * <td>
  7601. * <p>Skewing. This can be used to deform a rectangular display object into a parallelogram.</p>
  7602. * <p>
  7603. * In PixiJS, skew has a slightly different behaviour than the conventional meaning. It can be
  7604. * thought of the net rotation applied to the coordinate axes (separately). For example, if "skew.x" is
  7605. * ⍺ and "skew.y" is β, then the line x = 0 will be rotated by ⍺ (y = -x*cot⍺) and the line y = 0 will be
  7606. * rotated by β (y = x*tanβ). A line y = x*tanϴ (i.e. a line at angle ϴ to the x-axis in local-space) will
  7607. * be rotated by an angle between ⍺ and β.
  7608. * </p>
  7609. * <p>
  7610. * It can be observed that if skew is applied equally to both axes, then it will be equivalent to applying
  7611. * a rotation. Indeed, if "skew.x" = -ϴ and "skew.y" = ϴ, it will produce an equivalent of "rotation" = ϴ.
  7612. * </p>
  7613. * <p>
  7614. * Another quite interesting observation is that "skew.x", "skew.y", rotation are communtative operations. Indeed,
  7615. * because rotation is essentially a careful combination of the two.
  7616. * </p>
  7617. * </td>
  7618. * </tr>
  7619. * <tr>
  7620. * <td>angle</td>
  7621. * <td>Rotation. This is an alias for [rotation]{@link PIXI.DisplayObject#rotation}, but in degrees.</td>
  7622. * </tr>
  7623. * <tr>
  7624. * <td>x</td>
  7625. * <td>Translation. This is an alias for position.x!</td>
  7626. * </tr>
  7627. * <tr>
  7628. * <td>y</td>
  7629. * <td>Translation. This is an alias for position.y!</td>
  7630. * </tr>
  7631. * <tr>
  7632. * <td>width</td>
  7633. * <td>
  7634. * Implemented in [Container]{@link PIXI.Container}. Scaling. The width property calculates scale.x by dividing
  7635. * the "requested" width by the local bounding box width. It is indirectly an abstraction over scale.x, and there
  7636. * is no concept of user-defined width.
  7637. * </td>
  7638. * </tr>
  7639. * <tr>
  7640. * <td>height</td>
  7641. * <td>
  7642. * Implemented in [Container]{@link PIXI.Container}. Scaling. The height property calculates scale.y by dividing
  7643. * the "requested" height by the local bounding box height. It is indirectly an abstraction over scale.y, and there
  7644. * is no concept of user-defined height.
  7645. * </td>
  7646. * </tr>
  7647. * </tbody>
  7648. * </table>
  7649. *
  7650. * ## Bounds
  7651. *
  7652. * The bounds of a display object is defined by the minimum axis-aligned rectangle in world space that can fit
  7653. * around it. The abstract `calculateBounds` method is responsible for providing it (and it should use the
  7654. * `worldTransform` to calculate in world space).
  7655. *
  7656. * There are a few additional types of bounding boxes:
  7657. *
  7658. * | Bounds | Description |
  7659. * | --------------------- | ---------------------------------------------------------------------------------------- |
  7660. * | World Bounds | This is synonymous is the regular bounds described above. See `getBounds()`. |
  7661. * | Local Bounds | This the axis-aligned bounding box in the parent's local space. See `getLocalBounds()`. |
  7662. * | Render Bounds | The bounds, but including extra rendering effects like filter padding. |
  7663. * | Projected Bounds | The bounds of the projected display object onto the screen. Usually equals world bounds. |
  7664. * | Relative Bounds | The bounds of a display object when projected onto a ancestor's (or parent's) space. |
  7665. * | Natural Bounds | The bounds of an object in its own local space (not parent's space, like in local bounds)|
  7666. * | Content Bounds | The natural bounds when excluding all children of a `Container`. |
  7667. *
  7668. * ### calculateBounds
  7669. *
  7670. * [Container]{@link Container} already implements `calculateBounds` in a manner that includes children.
  7671. *
  7672. * But for a non-Container display object, the `calculateBounds` method must be overridden in order for `getBounds` and
  7673. * `getLocalBounds` to work. This method must write the bounds into `this._bounds`.
  7674. *
  7675. * Generally, the following technique works for most simple cases: take the list of points
  7676. * forming the "hull" of the object (i.e. outline of the object's shape), and then add them
  7677. * using {@link PIXI.Bounds#addPointMatrix}.
  7678. *
  7679. * ```js
  7680. * calculateBounds(): void
  7681. * {
  7682. * const points = [...];
  7683. *
  7684. * for (let i = 0, j = points.length; i < j; i++)
  7685. * {
  7686. * this._bounds.addPointMatrix(this.worldTransform, points[i]);
  7687. * }
  7688. * }
  7689. * ```
  7690. *
  7691. * You can optimize this for a large number of points by using {@link PIXI.Bounds#addVerticesMatrix} to pass them
  7692. * in one array together.
  7693. *
  7694. * ## Alpha
  7695. *
  7696. * This alpha sets a display object's **relative opacity** w.r.t its parent. For example, if the alpha of a display
  7697. * object is 0.5 and its parent's alpha is 0.5, then it will be rendered with 25% opacity (assuming alpha is not
  7698. * applied on any ancestor further up the chain).
  7699. *
  7700. * The alpha with which the display object will be rendered is called the [worldAlpha]{@link PIXI.DisplayObject#worldAlpha}.
  7701. *
  7702. * ## Renderable vs Visible
  7703. *
  7704. * The `renderable` and `visible` properties can be used to prevent a display object from being rendered to the
  7705. * screen. However, there is a subtle difference between the two. When using `renderable`, the transforms of the display
  7706. * object (and its children subtree) will continue to be calculated. When using `visible`, the transforms will not
  7707. * be calculated.
  7708. *
  7709. * It is recommended that applications use the `renderable` property for culling. See
  7710. * [@pixi-essentials/cull]{@link https://www.npmjs.com/package/@pixi-essentials/cull} or
  7711. * [pixi-cull]{@link https://www.npmjs.com/package/pixi-cull} for more details.
  7712. *
  7713. * Otherwise, to prevent an object from rendering in the general-purpose sense - `visible` is the property to use. This
  7714. * one is also better in terms of performance.
  7715. *
  7716. * @class
  7717. * @extends PIXI.utils.EventEmitter
  7718. * @memberof PIXI
  7719. */
  7720. var DisplayObject = /** @class */ (function (_super) {
  7721. __extends(DisplayObject, _super);
  7722. function DisplayObject() {
  7723. var _this = _super.call(this) || this;
  7724. _this.tempDisplayObjectParent = null;
  7725. // TODO: need to create Transform from factory
  7726. /**
  7727. * World transform and local transform of this object.
  7728. * This will become read-only later, please do not assign anything there unless you know what are you doing.
  7729. *
  7730. * @member {PIXI.Transform}
  7731. */
  7732. _this.transform = new Transform();
  7733. /**
  7734. * The opacity of the object.
  7735. *
  7736. * @member {number}
  7737. */
  7738. _this.alpha = 1;
  7739. /**
  7740. * The visibility of the object. If false the object will not be drawn, and
  7741. * the updateTransform function will not be called.
  7742. *
  7743. * Only affects recursive calls from parent. You can ask for bounds or call updateTransform manually.
  7744. *
  7745. * @member {boolean}
  7746. */
  7747. _this.visible = true;
  7748. /**
  7749. * Can this object be rendered, if false the object will not be drawn but the updateTransform
  7750. * methods will still be called.
  7751. *
  7752. * Only affects recursive calls from parent. You can ask for bounds manually.
  7753. *
  7754. * @member {boolean}
  7755. */
  7756. _this.renderable = true;
  7757. /**
  7758. * The display object container that contains this display object.
  7759. *
  7760. * @member {PIXI.Container}
  7761. */
  7762. _this.parent = null;
  7763. /**
  7764. * The multiplied alpha of the displayObject.
  7765. *
  7766. * @member {number}
  7767. * @readonly
  7768. */
  7769. _this.worldAlpha = 1;
  7770. /**
  7771. * Which index in the children array the display component was before the previous zIndex sort.
  7772. * Used by containers to help sort objects with the same zIndex, by using previous array index as the decider.
  7773. *
  7774. * @member {number}
  7775. * @protected
  7776. */
  7777. _this._lastSortedIndex = 0;
  7778. /**
  7779. * The zIndex of the displayObject.
  7780. * A higher value will mean it will be rendered on top of other displayObjects within the same container.
  7781. *
  7782. * @member {number}
  7783. * @protected
  7784. */
  7785. _this._zIndex = 0;
  7786. /**
  7787. * The area the filter is applied to. This is used as more of an optimization
  7788. * rather than figuring out the dimensions of the displayObject each frame you can set this rectangle.
  7789. *
  7790. * Also works as an interaction mask.
  7791. *
  7792. * @member {?PIXI.Rectangle}
  7793. */
  7794. _this.filterArea = null;
  7795. /**
  7796. * Sets the filters for the displayObject.
  7797. * * IMPORTANT: This is a WebGL only feature and will be ignored by the canvas renderer.
  7798. * To remove filters simply set this property to `'null'`.
  7799. *
  7800. * @member {?PIXI.Filter[]}
  7801. */
  7802. _this.filters = null;
  7803. /**
  7804. * Currently enabled filters
  7805. * @member {PIXI.Filter[]}
  7806. * @protected
  7807. */
  7808. _this._enabledFilters = null;
  7809. /**
  7810. * The bounds object, this is used to calculate and store the bounds of the displayObject.
  7811. *
  7812. * @member {PIXI.Bounds}
  7813. */
  7814. _this._bounds = new Bounds();
  7815. /**
  7816. * Local bounds object, swapped with `_bounds` when using `getLocalBounds()`.
  7817. *
  7818. * @member {PIXI.Bounds}
  7819. */
  7820. _this._localBounds = null;
  7821. /**
  7822. * Flags the cached bounds as dirty.
  7823. *
  7824. * @member {number}
  7825. * @protected
  7826. */
  7827. _this._boundsID = 0;
  7828. /**
  7829. * Cache of this display-object's bounds-rectangle.
  7830. *
  7831. * @member {PIXI.Bounds}
  7832. * @protected
  7833. */
  7834. _this._boundsRect = null;
  7835. /**
  7836. * Cache of this display-object's local-bounds rectangle.
  7837. *
  7838. * @member {PIXI.Bounds}
  7839. * @protected
  7840. */
  7841. _this._localBoundsRect = null;
  7842. /**
  7843. * The original, cached mask of the object.
  7844. *
  7845. * @member {PIXI.Container|PIXI.MaskData|null}
  7846. * @protected
  7847. */
  7848. _this._mask = null;
  7849. /**
  7850. * If the object has been destroyed via destroy(). If true, it should not be used.
  7851. *
  7852. * @member {boolean}
  7853. * @protected
  7854. */
  7855. _this._destroyed = false;
  7856. /**
  7857. * used to fast check if a sprite is.. a sprite!
  7858. * @member {boolean}
  7859. */
  7860. _this.isSprite = false;
  7861. /**
  7862. * Does any other displayObject use this object as a mask?
  7863. * @member {boolean}
  7864. */
  7865. _this.isMask = false;
  7866. return _this;
  7867. }
  7868. /**
  7869. * Mixes all enumerable properties and methods from a source object to DisplayObject.
  7870. *
  7871. * @param {object} source - The source of properties and methods to mix in.
  7872. */
  7873. DisplayObject.mixin = function (source) {
  7874. // in ES8/ES2017, this would be really easy:
  7875. // Object.defineProperties(DisplayObject.prototype, Object.getOwnPropertyDescriptors(source));
  7876. // get all the enumerable property keys
  7877. var keys = Object.keys(source);
  7878. // loop through properties
  7879. for (var i = 0; i < keys.length; ++i) {
  7880. var propertyName = keys[i];
  7881. // Set the property using the property descriptor - this works for accessors and normal value properties
  7882. Object.defineProperty(DisplayObject.prototype, propertyName, Object.getOwnPropertyDescriptor(source, propertyName));
  7883. }
  7884. };
  7885. Object.defineProperty(DisplayObject.prototype, "destroyed", {
  7886. /**
  7887. * Fired when this DisplayObject is added to a Container.
  7888. *
  7889. * @instance
  7890. * @event added
  7891. * @param {PIXI.Container} container - The container added to.
  7892. */
  7893. /**
  7894. * Fired when this DisplayObject is removed from a Container.
  7895. *
  7896. * @instance
  7897. * @event removed
  7898. * @param {PIXI.Container} container - The container removed from.
  7899. */
  7900. /**
  7901. * Fired when this DisplayObject is destroyed.
  7902. *
  7903. * @instance
  7904. * @event destroyed
  7905. */
  7906. /**
  7907. * Readonly flag for destroyed display objects.
  7908. */
  7909. get: function () {
  7910. return this._destroyed;
  7911. },
  7912. enumerable: false,
  7913. configurable: true
  7914. });
  7915. /**
  7916. * Recursively updates transform of all objects from the root to this one
  7917. * internal function for toLocal()
  7918. */
  7919. DisplayObject.prototype._recursivePostUpdateTransform = function () {
  7920. if (this.parent) {
  7921. this.parent._recursivePostUpdateTransform();
  7922. this.transform.updateTransform(this.parent.transform);
  7923. }
  7924. else {
  7925. this.transform.updateTransform(this._tempDisplayObjectParent.transform);
  7926. }
  7927. };
  7928. /**
  7929. * Updates the object transform for rendering.
  7930. *
  7931. * TODO - Optimization pass!
  7932. */
  7933. DisplayObject.prototype.updateTransform = function () {
  7934. this._boundsID++;
  7935. this.transform.updateTransform(this.parent.transform);
  7936. // multiply the alphas..
  7937. this.worldAlpha = this.alpha * this.parent.worldAlpha;
  7938. };
  7939. /**
  7940. * Calculates and returns the (world) bounds of the display object as a [Rectangle]{@link PIXI.Rectangle}.
  7941. *
  7942. * This method is expensive on containers with a large subtree (like the stage). This is because the bounds
  7943. * of a container depend on its children's bounds, which recursively causes all bounds in the subtree to
  7944. * be recalculated. The upside, however, is that calling `getBounds` once on a container will indeed update
  7945. * the bounds of all children (the whole subtree, in fact). This side effect should be exploited by using
  7946. * `displayObject._bounds.getRectangle()` when traversing through all the bounds in a scene graph. Otherwise,
  7947. * calling `getBounds` on each object in a subtree will cause the total cost to increase quadratically as
  7948. * its height increases.
  7949. *
  7950. * * The transforms of all objects in a container's **subtree** and of all **ancestors** are updated.
  7951. * * The world bounds of all display objects in a container's **subtree** will also be recalculated.
  7952. *
  7953. * The `_bounds` object stores the last calculation of the bounds. You can use to entirely skip bounds
  7954. * calculation if needed.
  7955. *
  7956. * ```js
  7957. * const lastCalculatedBounds = displayObject._bounds.getRectangle(optionalRect);
  7958. * ```
  7959. *
  7960. * Do know that usage of `getLocalBounds` can corrupt the `_bounds` of children (the whole subtree, actually). This
  7961. * is a known issue that has not been solved. See [getLocalBounds]{@link PIXI.DisplayObject#getLocalBounds} for more
  7962. * details.
  7963. *
  7964. * `getBounds` should be called with `skipUpdate` equal to `true` in a render() call. This is because the transforms
  7965. * are guaranteed to be update-to-date. In fact, recalculating inside a render() call may cause corruption in certain
  7966. * cases.
  7967. *
  7968. * @param {boolean} [skipUpdate] - Setting to `true` will stop the transforms of the scene graph from
  7969. * being updated. This means the calculation returned MAY be out of date BUT will give you a
  7970. * nice performance boost.
  7971. * @param {PIXI.Rectangle} [rect] - Optional rectangle to store the result of the bounds calculation.
  7972. * @return {PIXI.Rectangle} The minimum axis-aligned rectangle in world space that fits around this object.
  7973. */
  7974. DisplayObject.prototype.getBounds = function (skipUpdate, rect) {
  7975. if (!skipUpdate) {
  7976. if (!this.parent) {
  7977. this.parent = this._tempDisplayObjectParent;
  7978. this.updateTransform();
  7979. this.parent = null;
  7980. }
  7981. else {
  7982. this._recursivePostUpdateTransform();
  7983. this.updateTransform();
  7984. }
  7985. }
  7986. if (this._bounds.updateID !== this._boundsID) {
  7987. this.calculateBounds();
  7988. this._bounds.updateID = this._boundsID;
  7989. }
  7990. if (!rect) {
  7991. if (!this._boundsRect) {
  7992. this._boundsRect = new Rectangle();
  7993. }
  7994. rect = this._boundsRect;
  7995. }
  7996. return this._bounds.getRectangle(rect);
  7997. };
  7998. /**
  7999. * Retrieves the local bounds of the displayObject as a rectangle object.
  8000. *
  8001. * @param {PIXI.Rectangle} [rect] - Optional rectangle to store the result of the bounds calculation.
  8002. * @return {PIXI.Rectangle} The rectangular bounding area.
  8003. */
  8004. DisplayObject.prototype.getLocalBounds = function (rect) {
  8005. if (!rect) {
  8006. if (!this._localBoundsRect) {
  8007. this._localBoundsRect = new Rectangle();
  8008. }
  8009. rect = this._localBoundsRect;
  8010. }
  8011. if (!this._localBounds) {
  8012. this._localBounds = new Bounds();
  8013. }
  8014. var transformRef = this.transform;
  8015. var parentRef = this.parent;
  8016. this.parent = null;
  8017. this.transform = this._tempDisplayObjectParent.transform;
  8018. var worldBounds = this._bounds;
  8019. var worldBoundsID = this._boundsID;
  8020. this._bounds = this._localBounds;
  8021. var bounds = this.getBounds(false, rect);
  8022. this.parent = parentRef;
  8023. this.transform = transformRef;
  8024. this._bounds = worldBounds;
  8025. this._bounds.updateID += this._boundsID - worldBoundsID; // reflect side-effects
  8026. return bounds;
  8027. };
  8028. /**
  8029. * Calculates the global position of the display object.
  8030. *
  8031. * @param {PIXI.IPointData} position - The world origin to calculate from.
  8032. * @param {PIXI.Point} [point] - A Point object in which to store the value, optional
  8033. * (otherwise will create a new Point).
  8034. * @param {boolean} [skipUpdate=false] - Should we skip the update transform.
  8035. * @return {PIXI.Point} A point object representing the position of this object.
  8036. */
  8037. DisplayObject.prototype.toGlobal = function (position, point, skipUpdate) {
  8038. if (skipUpdate === void 0) { skipUpdate = false; }
  8039. if (!skipUpdate) {
  8040. this._recursivePostUpdateTransform();
  8041. // this parent check is for just in case the item is a root object.
  8042. // If it is we need to give it a temporary parent so that displayObjectUpdateTransform works correctly
  8043. // this is mainly to avoid a parent check in the main loop. Every little helps for performance :)
  8044. if (!this.parent) {
  8045. this.parent = this._tempDisplayObjectParent;
  8046. this.displayObjectUpdateTransform();
  8047. this.parent = null;
  8048. }
  8049. else {
  8050. this.displayObjectUpdateTransform();
  8051. }
  8052. }
  8053. // don't need to update the lot
  8054. return this.worldTransform.apply(position, point);
  8055. };
  8056. /**
  8057. * Calculates the local position of the display object relative to another point.
  8058. *
  8059. * @param {PIXI.IPointData} position - The world origin to calculate from.
  8060. * @param {PIXI.DisplayObject} [from] - The DisplayObject to calculate the global position from.
  8061. * @param {PIXI.Point} [point] - A Point object in which to store the value, optional
  8062. * (otherwise will create a new Point).
  8063. * @param {boolean} [skipUpdate=false] - Should we skip the update transform
  8064. * @return {PIXI.Point} A point object representing the position of this object
  8065. */
  8066. DisplayObject.prototype.toLocal = function (position, from, point, skipUpdate) {
  8067. if (from) {
  8068. position = from.toGlobal(position, point, skipUpdate);
  8069. }
  8070. if (!skipUpdate) {
  8071. this._recursivePostUpdateTransform();
  8072. // this parent check is for just in case the item is a root object.
  8073. // If it is we need to give it a temporary parent so that displayObjectUpdateTransform works correctly
  8074. // this is mainly to avoid a parent check in the main loop. Every little helps for performance :)
  8075. if (!this.parent) {
  8076. this.parent = this._tempDisplayObjectParent;
  8077. this.displayObjectUpdateTransform();
  8078. this.parent = null;
  8079. }
  8080. else {
  8081. this.displayObjectUpdateTransform();
  8082. }
  8083. }
  8084. // simply apply the matrix..
  8085. return this.worldTransform.applyInverse(position, point);
  8086. };
  8087. /**
  8088. * Set the parent Container of this DisplayObject.
  8089. *
  8090. * @param {PIXI.Container} container - The Container to add this DisplayObject to.
  8091. * @return {PIXI.Container} The Container that this DisplayObject was added to.
  8092. */
  8093. DisplayObject.prototype.setParent = function (container) {
  8094. if (!container || !container.addChild) {
  8095. throw new Error('setParent: Argument must be a Container');
  8096. }
  8097. container.addChild(this);
  8098. return container;
  8099. };
  8100. /**
  8101. * Convenience function to set the position, scale, skew and pivot at once.
  8102. *
  8103. * @param {number} [x=0] - The X position
  8104. * @param {number} [y=0] - The Y position
  8105. * @param {number} [scaleX=1] - The X scale value
  8106. * @param {number} [scaleY=1] - The Y scale value
  8107. * @param {number} [rotation=0] - The rotation
  8108. * @param {number} [skewX=0] - The X skew value
  8109. * @param {number} [skewY=0] - The Y skew value
  8110. * @param {number} [pivotX=0] - The X pivot value
  8111. * @param {number} [pivotY=0] - The Y pivot value
  8112. * @return {PIXI.DisplayObject} The DisplayObject instance
  8113. */
  8114. DisplayObject.prototype.setTransform = function (x, y, scaleX, scaleY, rotation, skewX, skewY, pivotX, pivotY) {
  8115. if (x === void 0) { x = 0; }
  8116. if (y === void 0) { y = 0; }
  8117. if (scaleX === void 0) { scaleX = 1; }
  8118. if (scaleY === void 0) { scaleY = 1; }
  8119. if (rotation === void 0) { rotation = 0; }
  8120. if (skewX === void 0) { skewX = 0; }
  8121. if (skewY === void 0) { skewY = 0; }
  8122. if (pivotX === void 0) { pivotX = 0; }
  8123. if (pivotY === void 0) { pivotY = 0; }
  8124. this.position.x = x;
  8125. this.position.y = y;
  8126. this.scale.x = !scaleX ? 1 : scaleX;
  8127. this.scale.y = !scaleY ? 1 : scaleY;
  8128. this.rotation = rotation;
  8129. this.skew.x = skewX;
  8130. this.skew.y = skewY;
  8131. this.pivot.x = pivotX;
  8132. this.pivot.y = pivotY;
  8133. return this;
  8134. };
  8135. /**
  8136. * Base destroy method for generic display objects. This will automatically
  8137. * remove the display object from its parent Container as well as remove
  8138. * all current event listeners and internal references. Do not use a DisplayObject
  8139. * after calling `destroy()`.
  8140. *
  8141. */
  8142. DisplayObject.prototype.destroy = function (_options) {
  8143. if (this.parent) {
  8144. this.parent.removeChild(this);
  8145. }
  8146. this.emit('destroyed');
  8147. this.removeAllListeners();
  8148. this.transform = null;
  8149. this.parent = null;
  8150. this._bounds = null;
  8151. this._mask = null;
  8152. this.filters = null;
  8153. this.filterArea = null;
  8154. this.hitArea = null;
  8155. this.interactive = false;
  8156. this.interactiveChildren = false;
  8157. this._destroyed = true;
  8158. };
  8159. Object.defineProperty(DisplayObject.prototype, "_tempDisplayObjectParent", {
  8160. /**
  8161. * @protected
  8162. * @member {PIXI.Container}
  8163. */
  8164. get: function () {
  8165. if (this.tempDisplayObjectParent === null) {
  8166. // eslint-disable-next-line @typescript-eslint/no-use-before-define
  8167. this.tempDisplayObjectParent = new TemporaryDisplayObject();
  8168. }
  8169. return this.tempDisplayObjectParent;
  8170. },
  8171. enumerable: false,
  8172. configurable: true
  8173. });
  8174. /**
  8175. * Used in Renderer, cacheAsBitmap and other places where you call an `updateTransform` on root
  8176. *
  8177. * ```
  8178. * const cacheParent = elem.enableTempParent();
  8179. * elem.updateTransform();
  8180. * elem.disableTempParent(cacheParent);
  8181. * ```
  8182. *
  8183. * @returns {PIXI.Container} current parent
  8184. */
  8185. DisplayObject.prototype.enableTempParent = function () {
  8186. var myParent = this.parent;
  8187. this.parent = this._tempDisplayObjectParent;
  8188. return myParent;
  8189. };
  8190. /**
  8191. * Pair method for `enableTempParent`
  8192. *
  8193. * @param {PIXI.Container} cacheParent - Actual parent of element
  8194. */
  8195. DisplayObject.prototype.disableTempParent = function (cacheParent) {
  8196. this.parent = cacheParent;
  8197. };
  8198. Object.defineProperty(DisplayObject.prototype, "x", {
  8199. /**
  8200. * The position of the displayObject on the x axis relative to the local coordinates of the parent.
  8201. * An alias to position.x
  8202. *
  8203. * @member {number}
  8204. */
  8205. get: function () {
  8206. return this.position.x;
  8207. },
  8208. set: function (value) {
  8209. this.transform.position.x = value;
  8210. },
  8211. enumerable: false,
  8212. configurable: true
  8213. });
  8214. Object.defineProperty(DisplayObject.prototype, "y", {
  8215. /**
  8216. * The position of the displayObject on the y axis relative to the local coordinates of the parent.
  8217. * An alias to position.y
  8218. *
  8219. * @member {number}
  8220. */
  8221. get: function () {
  8222. return this.position.y;
  8223. },
  8224. set: function (value) {
  8225. this.transform.position.y = value;
  8226. },
  8227. enumerable: false,
  8228. configurable: true
  8229. });
  8230. Object.defineProperty(DisplayObject.prototype, "worldTransform", {
  8231. /**
  8232. * Current transform of the object based on world (parent) factors.
  8233. *
  8234. * @member {PIXI.Matrix}
  8235. * @readonly
  8236. */
  8237. get: function () {
  8238. return this.transform.worldTransform;
  8239. },
  8240. enumerable: false,
  8241. configurable: true
  8242. });
  8243. Object.defineProperty(DisplayObject.prototype, "localTransform", {
  8244. /**
  8245. * Current transform of the object based on local factors: position, scale, other stuff.
  8246. *
  8247. * @member {PIXI.Matrix}
  8248. * @readonly
  8249. */
  8250. get: function () {
  8251. return this.transform.localTransform;
  8252. },
  8253. enumerable: false,
  8254. configurable: true
  8255. });
  8256. Object.defineProperty(DisplayObject.prototype, "position", {
  8257. /**
  8258. * The coordinate of the object relative to the local coordinates of the parent.
  8259. *
  8260. * @since PixiJS 4
  8261. * @member {PIXI.ObservablePoint}
  8262. */
  8263. get: function () {
  8264. return this.transform.position;
  8265. },
  8266. set: function (value) {
  8267. this.transform.position.copyFrom(value);
  8268. },
  8269. enumerable: false,
  8270. configurable: true
  8271. });
  8272. Object.defineProperty(DisplayObject.prototype, "scale", {
  8273. /**
  8274. * The scale factors of this object along the local coordinate axes.
  8275. *
  8276. * The default scale is (1, 1).
  8277. *
  8278. * @since PixiJS 4
  8279. * @member {PIXI.ObservablePoint}
  8280. */
  8281. get: function () {
  8282. return this.transform.scale;
  8283. },
  8284. set: function (value) {
  8285. this.transform.scale.copyFrom(value);
  8286. },
  8287. enumerable: false,
  8288. configurable: true
  8289. });
  8290. Object.defineProperty(DisplayObject.prototype, "pivot", {
  8291. /**
  8292. * The center of rotation, scaling, and skewing for this display object in its local space. The `position`
  8293. * is the projection of `pivot` in the parent's local space.
  8294. *
  8295. * By default, the pivot is the origin (0, 0).
  8296. *
  8297. * @since PixiJS 4
  8298. * @member {PIXI.ObservablePoint}
  8299. */
  8300. get: function () {
  8301. return this.transform.pivot;
  8302. },
  8303. set: function (value) {
  8304. this.transform.pivot.copyFrom(value);
  8305. },
  8306. enumerable: false,
  8307. configurable: true
  8308. });
  8309. Object.defineProperty(DisplayObject.prototype, "skew", {
  8310. /**
  8311. * The skew factor for the object in radians.
  8312. *
  8313. * @since PixiJS 4
  8314. * @member {PIXI.ObservablePoint}
  8315. */
  8316. get: function () {
  8317. return this.transform.skew;
  8318. },
  8319. set: function (value) {
  8320. this.transform.skew.copyFrom(value);
  8321. },
  8322. enumerable: false,
  8323. configurable: true
  8324. });
  8325. Object.defineProperty(DisplayObject.prototype, "rotation", {
  8326. /**
  8327. * The rotation of the object in radians.
  8328. * 'rotation' and 'angle' have the same effect on a display object; rotation is in radians, angle is in degrees.
  8329. *
  8330. * @member {number}
  8331. */
  8332. get: function () {
  8333. return this.transform.rotation;
  8334. },
  8335. set: function (value) {
  8336. this.transform.rotation = value;
  8337. },
  8338. enumerable: false,
  8339. configurable: true
  8340. });
  8341. Object.defineProperty(DisplayObject.prototype, "angle", {
  8342. /**
  8343. * The angle of the object in degrees.
  8344. * 'rotation' and 'angle' have the same effect on a display object; rotation is in radians, angle is in degrees.
  8345. *
  8346. * @member {number}
  8347. */
  8348. get: function () {
  8349. return this.transform.rotation * RAD_TO_DEG;
  8350. },
  8351. set: function (value) {
  8352. this.transform.rotation = value * DEG_TO_RAD;
  8353. },
  8354. enumerable: false,
  8355. configurable: true
  8356. });
  8357. Object.defineProperty(DisplayObject.prototype, "zIndex", {
  8358. /**
  8359. * The zIndex of the displayObject.
  8360. *
  8361. * If a container has the sortableChildren property set to true, children will be automatically
  8362. * sorted by zIndex value; a higher value will mean it will be moved towards the end of the array,
  8363. * and thus rendered on top of other display objects within the same container.
  8364. *
  8365. * @member {number}
  8366. * @see PIXI.Container#sortableChildren
  8367. */
  8368. get: function () {
  8369. return this._zIndex;
  8370. },
  8371. set: function (value) {
  8372. this._zIndex = value;
  8373. if (this.parent) {
  8374. this.parent.sortDirty = true;
  8375. }
  8376. },
  8377. enumerable: false,
  8378. configurable: true
  8379. });
  8380. Object.defineProperty(DisplayObject.prototype, "worldVisible", {
  8381. /**
  8382. * Indicates if the object is globally visible.
  8383. *
  8384. * @member {boolean}
  8385. * @readonly
  8386. */
  8387. get: function () {
  8388. var item = this;
  8389. do {
  8390. if (!item.visible) {
  8391. return false;
  8392. }
  8393. item = item.parent;
  8394. } while (item);
  8395. return true;
  8396. },
  8397. enumerable: false,
  8398. configurable: true
  8399. });
  8400. Object.defineProperty(DisplayObject.prototype, "mask", {
  8401. /**
  8402. * Sets a mask for the displayObject. A mask is an object that limits the visibility of an
  8403. * object to the shape of the mask applied to it. In PixiJS a regular mask must be a
  8404. * {@link PIXI.Graphics} or a {@link PIXI.Sprite} object. This allows for much faster masking in canvas as it
  8405. * utilities shape clipping. To remove a mask, set this property to `null`.
  8406. *
  8407. * For sprite mask both alpha and red channel are used. Black mask is the same as transparent mask.
  8408. *
  8409. * @example
  8410. * const graphics = new PIXI.Graphics();
  8411. * graphics.beginFill(0xFF3300);
  8412. * graphics.drawRect(50, 250, 100, 100);
  8413. * graphics.endFill();
  8414. *
  8415. * const sprite = new PIXI.Sprite(texture);
  8416. * sprite.mask = graphics;
  8417. *
  8418. * @todo At the moment, PIXI.CanvasRenderer doesn't support PIXI.Sprite as mask.
  8419. * @member {PIXI.Container|PIXI.MaskData|null}
  8420. */
  8421. get: function () {
  8422. return this._mask;
  8423. },
  8424. set: function (value) {
  8425. if (this._mask) {
  8426. var maskObject = (this._mask.maskObject || this._mask);
  8427. maskObject.renderable = true;
  8428. maskObject.isMask = false;
  8429. }
  8430. this._mask = value;
  8431. if (this._mask) {
  8432. var maskObject = (this._mask.maskObject || this._mask);
  8433. maskObject.renderable = false;
  8434. maskObject.isMask = true;
  8435. }
  8436. },
  8437. enumerable: false,
  8438. configurable: true
  8439. });
  8440. return DisplayObject;
  8441. }(eventemitter3));
  8442. /**
  8443. * @private
  8444. */
  8445. var TemporaryDisplayObject = /** @class */ (function (_super) {
  8446. __extends(TemporaryDisplayObject, _super);
  8447. function TemporaryDisplayObject() {
  8448. var _this = _super !== null && _super.apply(this, arguments) || this;
  8449. _this.sortDirty = null;
  8450. return _this;
  8451. }
  8452. return TemporaryDisplayObject;
  8453. }(DisplayObject));
  8454. /**
  8455. * DisplayObject default updateTransform, does not update children of container.
  8456. * Will crash if there's no parent element.
  8457. *
  8458. * @memberof PIXI.DisplayObject#
  8459. * @method displayObjectUpdateTransform
  8460. */
  8461. DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform;
  8462. function sortChildren(a, b) {
  8463. if (a.zIndex === b.zIndex) {
  8464. return a._lastSortedIndex - b._lastSortedIndex;
  8465. }
  8466. return a.zIndex - b.zIndex;
  8467. }
  8468. /**
  8469. * Container is a general-purpose display object that holds children. It also adds built-in support for advanced
  8470. * rendering features like masking and filtering.
  8471. *
  8472. * It is the base class of all display objects that act as a container for other objects, including Graphics
  8473. * and Sprite.
  8474. *
  8475. * ```js
  8476. * import { BlurFilter } from '@pixi/filter-blur';
  8477. * import { Container } from '@pixi/display';
  8478. * import { Graphics } from '@pixi/graphics';
  8479. * import { Sprite } from '@pixi/sprite';
  8480. *
  8481. * let container = new Container();
  8482. * let sprite = Sprite.from("https://s3-us-west-2.amazonaws.com/s.cdpn.io/693612/IaUrttj.png");
  8483. *
  8484. * sprite.width = 512;
  8485. * sprite.height = 512;
  8486. *
  8487. * // Adds a sprite as a child to this container. As a result, the sprite will be rendered whenever the container
  8488. * // is rendered.
  8489. * container.addChild(sprite);
  8490. *
  8491. * // Blurs whatever is rendered by the container
  8492. * container.filters = [new BlurFilter()];
  8493. *
  8494. * // Only the contents within a circle at the center should be rendered onto the screen.
  8495. * container.mask = new Graphics()
  8496. * .beginFill(0xffffff)
  8497. * .drawCircle(sprite.width / 2, sprite.height / 2, Math.min(sprite.width, sprite.height) / 2)
  8498. * .endFill();
  8499. * ```
  8500. *
  8501. * @class
  8502. * @extends PIXI.DisplayObject
  8503. * @memberof PIXI
  8504. */
  8505. var Container = /** @class */ (function (_super) {
  8506. __extends(Container, _super);
  8507. function Container() {
  8508. var _this = _super.call(this) || this;
  8509. /**
  8510. * The array of children of this container.
  8511. *
  8512. * @member {PIXI.DisplayObject[]}
  8513. * @readonly
  8514. */
  8515. _this.children = [];
  8516. /**
  8517. * If set to true, the container will sort its children by zIndex value
  8518. * when updateTransform() is called, or manually if sortChildren() is called.
  8519. *
  8520. * This actually changes the order of elements in the array, so should be treated
  8521. * as a basic solution that is not performant compared to other solutions,
  8522. * such as @link https://github.com/pixijs/pixi-display
  8523. *
  8524. * Also be aware of that this may not work nicely with the addChildAt() function,
  8525. * as the zIndex sorting may cause the child to automatically sorted to another position.
  8526. *
  8527. * @see PIXI.settings.SORTABLE_CHILDREN
  8528. *
  8529. * @member {boolean}
  8530. */
  8531. _this.sortableChildren = settings.SORTABLE_CHILDREN;
  8532. /**
  8533. * Should children be sorted by zIndex at the next updateTransform call.
  8534. *
  8535. * Will get automatically set to true if a new child is added, or if a child's zIndex changes.
  8536. *
  8537. * @member {boolean}
  8538. */
  8539. _this.sortDirty = false;
  8540. return _this;
  8541. /**
  8542. * Fired when a DisplayObject is added to this Container.
  8543. *
  8544. * @event PIXI.Container#childAdded
  8545. * @param {PIXI.DisplayObject} child - The child added to the Container.
  8546. * @param {PIXI.Container} container - The container that added the child.
  8547. * @param {number} index - The children's index of the added child.
  8548. */
  8549. /**
  8550. * Fired when a DisplayObject is removed from this Container.
  8551. *
  8552. * @event PIXI.DisplayObject#removedFrom
  8553. * @param {PIXI.DisplayObject} child - The child removed from the Container.
  8554. * @param {PIXI.Container} container - The container that removed removed the child.
  8555. * @param {number} index - The former children's index of the removed child
  8556. */
  8557. }
  8558. /**
  8559. * Overridable method that can be used by Container subclasses whenever the children array is modified
  8560. *
  8561. * @protected
  8562. */
  8563. Container.prototype.onChildrenChange = function (_length) {
  8564. /* empty */
  8565. };
  8566. /**
  8567. * Adds one or more children to the container.
  8568. *
  8569. * Multiple items can be added like so: `myContainer.addChild(thingOne, thingTwo, thingThree)`
  8570. *
  8571. * @param {...PIXI.DisplayObject} children - The DisplayObject(s) to add to the container
  8572. * @return {PIXI.DisplayObject} The first child that was added.
  8573. */
  8574. Container.prototype.addChild = function () {
  8575. var arguments$1 = arguments;
  8576. var children = [];
  8577. for (var _i = 0; _i < arguments.length; _i++) {
  8578. children[_i] = arguments$1[_i];
  8579. }
  8580. // if there is only one argument we can bypass looping through the them
  8581. if (children.length > 1) {
  8582. // loop through the array and add all children
  8583. for (var i = 0; i < children.length; i++) {
  8584. // eslint-disable-next-line prefer-rest-params
  8585. this.addChild(children[i]);
  8586. }
  8587. }
  8588. else {
  8589. var child = children[0];
  8590. // if the child has a parent then lets remove it as PixiJS objects can only exist in one place
  8591. if (child.parent) {
  8592. child.parent.removeChild(child);
  8593. }
  8594. child.parent = this;
  8595. this.sortDirty = true;
  8596. // ensure child transform will be recalculated
  8597. child.transform._parentID = -1;
  8598. this.children.push(child);
  8599. // ensure bounds will be recalculated
  8600. this._boundsID++;
  8601. // TODO - lets either do all callbacks or all events.. not both!
  8602. this.onChildrenChange(this.children.length - 1);
  8603. this.emit('childAdded', child, this, this.children.length - 1);
  8604. child.emit('added', this);
  8605. }
  8606. return children[0];
  8607. };
  8608. /**
  8609. * Adds a child to the container at a specified index. If the index is out of bounds an error will be thrown
  8610. *
  8611. * @param {PIXI.DisplayObject} child - The child to add
  8612. * @param {number} index - The index to place the child in
  8613. * @return {PIXI.DisplayObject} The child that was added.
  8614. */
  8615. Container.prototype.addChildAt = function (child, index) {
  8616. if (index < 0 || index > this.children.length) {
  8617. throw new Error(child + "addChildAt: The index " + index + " supplied is out of bounds " + this.children.length);
  8618. }
  8619. if (child.parent) {
  8620. child.parent.removeChild(child);
  8621. }
  8622. child.parent = this;
  8623. this.sortDirty = true;
  8624. // ensure child transform will be recalculated
  8625. child.transform._parentID = -1;
  8626. this.children.splice(index, 0, child);
  8627. // ensure bounds will be recalculated
  8628. this._boundsID++;
  8629. // TODO - lets either do all callbacks or all events.. not both!
  8630. this.onChildrenChange(index);
  8631. child.emit('added', this);
  8632. this.emit('childAdded', child, this, index);
  8633. return child;
  8634. };
  8635. /**
  8636. * Swaps the position of 2 Display Objects within this container.
  8637. *
  8638. * @param {PIXI.DisplayObject} child - First display object to swap
  8639. * @param {PIXI.DisplayObject} child2 - Second display object to swap
  8640. */
  8641. Container.prototype.swapChildren = function (child, child2) {
  8642. if (child === child2) {
  8643. return;
  8644. }
  8645. var index1 = this.getChildIndex(child);
  8646. var index2 = this.getChildIndex(child2);
  8647. this.children[index1] = child2;
  8648. this.children[index2] = child;
  8649. this.onChildrenChange(index1 < index2 ? index1 : index2);
  8650. };
  8651. /**
  8652. * Returns the index position of a child DisplayObject instance
  8653. *
  8654. * @param {PIXI.DisplayObject} child - The DisplayObject instance to identify
  8655. * @return {number} The index position of the child display object to identify
  8656. */
  8657. Container.prototype.getChildIndex = function (child) {
  8658. var index = this.children.indexOf(child);
  8659. if (index === -1) {
  8660. throw new Error('The supplied DisplayObject must be a child of the caller');
  8661. }
  8662. return index;
  8663. };
  8664. /**
  8665. * Changes the position of an existing child in the display object container
  8666. *
  8667. * @param {PIXI.DisplayObject} child - The child DisplayObject instance for which you want to change the index number
  8668. * @param {number} index - The resulting index number for the child display object
  8669. */
  8670. Container.prototype.setChildIndex = function (child, index) {
  8671. if (index < 0 || index >= this.children.length) {
  8672. throw new Error("The index " + index + " supplied is out of bounds " + this.children.length);
  8673. }
  8674. var currentIndex = this.getChildIndex(child);
  8675. removeItems(this.children, currentIndex, 1); // remove from old position
  8676. this.children.splice(index, 0, child); // add at new position
  8677. this.onChildrenChange(index);
  8678. };
  8679. /**
  8680. * Returns the child at the specified index
  8681. *
  8682. * @param {number} index - The index to get the child at
  8683. * @return {PIXI.DisplayObject} The child at the given index, if any.
  8684. */
  8685. Container.prototype.getChildAt = function (index) {
  8686. if (index < 0 || index >= this.children.length) {
  8687. throw new Error("getChildAt: Index (" + index + ") does not exist.");
  8688. }
  8689. return this.children[index];
  8690. };
  8691. /**
  8692. * Removes one or more children from the container.
  8693. *
  8694. * @param {...PIXI.DisplayObject} children - The DisplayObject(s) to remove
  8695. * @return {PIXI.DisplayObject} The first child that was removed.
  8696. */
  8697. Container.prototype.removeChild = function () {
  8698. var arguments$1 = arguments;
  8699. var children = [];
  8700. for (var _i = 0; _i < arguments.length; _i++) {
  8701. children[_i] = arguments$1[_i];
  8702. }
  8703. // if there is only one argument we can bypass looping through the them
  8704. if (children.length > 1) {
  8705. // loop through the arguments property and remove all children
  8706. for (var i = 0; i < children.length; i++) {
  8707. this.removeChild(children[i]);
  8708. }
  8709. }
  8710. else {
  8711. var child = children[0];
  8712. var index = this.children.indexOf(child);
  8713. if (index === -1)
  8714. { return null; }
  8715. child.parent = null;
  8716. // ensure child transform will be recalculated
  8717. child.transform._parentID = -1;
  8718. removeItems(this.children, index, 1);
  8719. // ensure bounds will be recalculated
  8720. this._boundsID++;
  8721. // TODO - lets either do all callbacks or all events.. not both!
  8722. this.onChildrenChange(index);
  8723. child.emit('removed', this);
  8724. this.emit('childRemoved', child, this, index);
  8725. }
  8726. return children[0];
  8727. };
  8728. /**
  8729. * Removes a child from the specified index position.
  8730. *
  8731. * @param {number} index - The index to get the child from
  8732. * @return {PIXI.DisplayObject} The child that was removed.
  8733. */
  8734. Container.prototype.removeChildAt = function (index) {
  8735. var child = this.getChildAt(index);
  8736. // ensure child transform will be recalculated..
  8737. child.parent = null;
  8738. child.transform._parentID = -1;
  8739. removeItems(this.children, index, 1);
  8740. // ensure bounds will be recalculated
  8741. this._boundsID++;
  8742. // TODO - lets either do all callbacks or all events.. not both!
  8743. this.onChildrenChange(index);
  8744. child.emit('removed', this);
  8745. this.emit('childRemoved', child, this, index);
  8746. return child;
  8747. };
  8748. /**
  8749. * Removes all children from this container that are within the begin and end indexes.
  8750. *
  8751. * @param {number} [beginIndex=0] - The beginning position.
  8752. * @param {number} [endIndex=this.children.length] - The ending position. Default value is size of the container.
  8753. * @returns {PIXI.DisplayObject[]} List of removed children
  8754. */
  8755. Container.prototype.removeChildren = function (beginIndex, endIndex) {
  8756. if (beginIndex === void 0) { beginIndex = 0; }
  8757. if (endIndex === void 0) { endIndex = this.children.length; }
  8758. var begin = beginIndex;
  8759. var end = endIndex;
  8760. var range = end - begin;
  8761. var removed;
  8762. if (range > 0 && range <= end) {
  8763. removed = this.children.splice(begin, range);
  8764. for (var i = 0; i < removed.length; ++i) {
  8765. removed[i].parent = null;
  8766. if (removed[i].transform) {
  8767. removed[i].transform._parentID = -1;
  8768. }
  8769. }
  8770. this._boundsID++;
  8771. this.onChildrenChange(beginIndex);
  8772. for (var i = 0; i < removed.length; ++i) {
  8773. removed[i].emit('removed', this);
  8774. this.emit('childRemoved', removed[i], this, i);
  8775. }
  8776. return removed;
  8777. }
  8778. else if (range === 0 && this.children.length === 0) {
  8779. return [];
  8780. }
  8781. throw new RangeError('removeChildren: numeric values are outside the acceptable range.');
  8782. };
  8783. /**
  8784. * Sorts children by zIndex. Previous order is maintained for 2 children with the same zIndex.
  8785. */
  8786. Container.prototype.sortChildren = function () {
  8787. var sortRequired = false;
  8788. for (var i = 0, j = this.children.length; i < j; ++i) {
  8789. var child = this.children[i];
  8790. child._lastSortedIndex = i;
  8791. if (!sortRequired && child.zIndex !== 0) {
  8792. sortRequired = true;
  8793. }
  8794. }
  8795. if (sortRequired && this.children.length > 1) {
  8796. this.children.sort(sortChildren);
  8797. }
  8798. this.sortDirty = false;
  8799. };
  8800. /**
  8801. * Updates the transform on all children of this container for rendering
  8802. */
  8803. Container.prototype.updateTransform = function () {
  8804. if (this.sortableChildren && this.sortDirty) {
  8805. this.sortChildren();
  8806. }
  8807. this._boundsID++;
  8808. this.transform.updateTransform(this.parent.transform);
  8809. // TODO: check render flags, how to process stuff here
  8810. this.worldAlpha = this.alpha * this.parent.worldAlpha;
  8811. for (var i = 0, j = this.children.length; i < j; ++i) {
  8812. var child = this.children[i];
  8813. if (child.visible) {
  8814. child.updateTransform();
  8815. }
  8816. }
  8817. };
  8818. /**
  8819. * Recalculates the bounds of the container.
  8820. *
  8821. * This implementation will automatically fit the children's bounds into the calculation. Each child's bounds
  8822. * is limited to its mask's bounds or filterArea, if any is applied.
  8823. */
  8824. Container.prototype.calculateBounds = function () {
  8825. this._bounds.clear();
  8826. this._calculateBounds();
  8827. for (var i = 0; i < this.children.length; i++) {
  8828. var child = this.children[i];
  8829. if (!child.visible || !child.renderable) {
  8830. continue;
  8831. }
  8832. child.calculateBounds();
  8833. // TODO: filter+mask, need to mask both somehow
  8834. if (child._mask) {
  8835. var maskObject = (child._mask.maskObject || child._mask);
  8836. maskObject.calculateBounds();
  8837. this._bounds.addBoundsMask(child._bounds, maskObject._bounds);
  8838. }
  8839. else if (child.filterArea) {
  8840. this._bounds.addBoundsArea(child._bounds, child.filterArea);
  8841. }
  8842. else {
  8843. this._bounds.addBounds(child._bounds);
  8844. }
  8845. }
  8846. this._bounds.updateID = this._boundsID;
  8847. };
  8848. /**
  8849. * Retrieves the local bounds of the displayObject as a rectangle object.
  8850. *
  8851. * Calling `getLocalBounds` may invalidate the `_bounds` of the whole subtree below. If using it inside a render()
  8852. * call, it is advised to call `getBounds()` immediately after to recalculate the world bounds of the subtree.
  8853. *
  8854. * @param {PIXI.Rectangle} [rect] - Optional rectangle to store the result of the bounds calculation.
  8855. * @param {boolean} [skipChildrenUpdate=false] - Setting to `true` will stop re-calculation of children transforms,
  8856. * it was default behaviour of pixi 4.0-5.2 and caused many problems to users.
  8857. * @return {PIXI.Rectangle} The rectangular bounding area.
  8858. */
  8859. Container.prototype.getLocalBounds = function (rect, skipChildrenUpdate) {
  8860. if (skipChildrenUpdate === void 0) { skipChildrenUpdate = false; }
  8861. var result = _super.prototype.getLocalBounds.call(this, rect);
  8862. if (!skipChildrenUpdate) {
  8863. for (var i = 0, j = this.children.length; i < j; ++i) {
  8864. var child = this.children[i];
  8865. if (child.visible) {
  8866. child.updateTransform();
  8867. }
  8868. }
  8869. }
  8870. return result;
  8871. };
  8872. /**
  8873. * Recalculates the content bounds of this object. This should be overriden to
  8874. * calculate the bounds of this specific object (not including children).
  8875. *
  8876. * @protected
  8877. */
  8878. Container.prototype._calculateBounds = function () {
  8879. // FILL IN//
  8880. };
  8881. /**
  8882. * Renders the object using the WebGL renderer.
  8883. *
  8884. * The [_render]{@link PIXI.Container#_render} method is be overriden for rendering the contents of the
  8885. * container itself. This `render` method will invoke it, and also invoke the `render` methods of all
  8886. * children afterward.
  8887. *
  8888. * If `renderable` or `visible` is false or if `worldAlpha` is not positive, this implementation will entirely
  8889. * skip rendering. See {@link PIXI.DisplayObject} for choosing between `renderable` or `visible`. Generally,
  8890. * setting alpha to zero is not recommended for purely skipping rendering.
  8891. *
  8892. * When your scene becomes large (especially when it is larger than can be viewed in a single screen), it is
  8893. * advised to employ **culling** to automatically skip rendering objects outside of the current screen. The
  8894. * [@pixi-essentials/cull]{@link https://www.npmjs.com/package/@pixi-essentials/cull} and
  8895. * [pixi-cull]{@link https://www.npmjs.com/package/pixi-cull} packages do this out of the box.
  8896. *
  8897. * The [renderAdvanced]{@link PIXI.Container#renderAdvanced} method is internally used when when masking or
  8898. * filtering is applied on a container. This does, however, break batching and can affect performance when
  8899. * masking and filtering is applied extensively throughout the scene graph.
  8900. *
  8901. * @param {PIXI.Renderer} renderer - The renderer
  8902. */
  8903. Container.prototype.render = function (renderer) {
  8904. // if the object is not visible or the alpha is 0 then no need to render this element
  8905. if (!this.visible || this.worldAlpha <= 0 || !this.renderable) {
  8906. return;
  8907. }
  8908. // do a quick check to see if this element has a mask or a filter.
  8909. if (this._mask || (this.filters && this.filters.length)) {
  8910. this.renderAdvanced(renderer);
  8911. }
  8912. else {
  8913. this._render(renderer);
  8914. // simple render children!
  8915. for (var i = 0, j = this.children.length; i < j; ++i) {
  8916. this.children[i].render(renderer);
  8917. }
  8918. }
  8919. };
  8920. /**
  8921. * Render the object using the WebGL renderer and advanced features.
  8922. *
  8923. * @protected
  8924. * @param {PIXI.Renderer} renderer - The renderer
  8925. */
  8926. Container.prototype.renderAdvanced = function (renderer) {
  8927. renderer.batch.flush();
  8928. var filters = this.filters;
  8929. var mask = this._mask;
  8930. // push filter first as we need to ensure the stencil buffer is correct for any masking
  8931. if (filters) {
  8932. if (!this._enabledFilters) {
  8933. this._enabledFilters = [];
  8934. }
  8935. this._enabledFilters.length = 0;
  8936. for (var i = 0; i < filters.length; i++) {
  8937. if (filters[i].enabled) {
  8938. this._enabledFilters.push(filters[i]);
  8939. }
  8940. }
  8941. if (this._enabledFilters.length) {
  8942. renderer.filter.push(this, this._enabledFilters);
  8943. }
  8944. }
  8945. if (mask) {
  8946. renderer.mask.push(this, this._mask);
  8947. }
  8948. // add this object to the batch, only rendered if it has a texture.
  8949. this._render(renderer);
  8950. // now loop through the children and make sure they get rendered
  8951. for (var i = 0, j = this.children.length; i < j; i++) {
  8952. this.children[i].render(renderer);
  8953. }
  8954. renderer.batch.flush();
  8955. if (mask) {
  8956. renderer.mask.pop(this);
  8957. }
  8958. if (filters && this._enabledFilters && this._enabledFilters.length) {
  8959. renderer.filter.pop();
  8960. }
  8961. };
  8962. /**
  8963. * To be overridden by the subclasses.
  8964. *
  8965. * @protected
  8966. * @param {PIXI.Renderer} renderer - The renderer
  8967. */
  8968. Container.prototype._render = function (_renderer) {
  8969. // this is where content itself gets rendered...
  8970. };
  8971. /**
  8972. * Removes all internal references and listeners as well as removes children from the display list.
  8973. * Do not use a Container after calling `destroy`.
  8974. *
  8975. * @param {object|boolean} [options] - Options parameter. A boolean will act as if all options
  8976. * have been set to that value
  8977. * @param {boolean} [options.children=false] - if set to true, all the children will have their destroy
  8978. * method called as well. 'options' will be passed on to those calls.
  8979. * @param {boolean} [options.texture=false] - Only used for child Sprites if options.children is set to true
  8980. * Should it destroy the texture of the child sprite
  8981. * @param {boolean} [options.baseTexture=false] - Only used for child Sprites if options.children is set to true
  8982. * Should it destroy the base texture of the child sprite
  8983. */
  8984. Container.prototype.destroy = function (options) {
  8985. _super.prototype.destroy.call(this);
  8986. this.sortDirty = false;
  8987. var destroyChildren = typeof options === 'boolean' ? options : options && options.children;
  8988. var oldChildren = this.removeChildren(0, this.children.length);
  8989. if (destroyChildren) {
  8990. for (var i = 0; i < oldChildren.length; ++i) {
  8991. oldChildren[i].destroy(options);
  8992. }
  8993. }
  8994. };
  8995. Object.defineProperty(Container.prototype, "width", {
  8996. /**
  8997. * The width of the Container, setting this will actually modify the scale to achieve the value set
  8998. *
  8999. * @member {number}
  9000. */
  9001. get: function () {
  9002. return this.scale.x * this.getLocalBounds().width;
  9003. },
  9004. set: function (value) {
  9005. var width = this.getLocalBounds().width;
  9006. if (width !== 0) {
  9007. this.scale.x = value / width;
  9008. }
  9009. else {
  9010. this.scale.x = 1;
  9011. }
  9012. this._width = value;
  9013. },
  9014. enumerable: false,
  9015. configurable: true
  9016. });
  9017. Object.defineProperty(Container.prototype, "height", {
  9018. /**
  9019. * The height of the Container, setting this will actually modify the scale to achieve the value set
  9020. *
  9021. * @member {number}
  9022. */
  9023. get: function () {
  9024. return this.scale.y * this.getLocalBounds().height;
  9025. },
  9026. set: function (value) {
  9027. var height = this.getLocalBounds().height;
  9028. if (height !== 0) {
  9029. this.scale.y = value / height;
  9030. }
  9031. else {
  9032. this.scale.y = 1;
  9033. }
  9034. this._height = value;
  9035. },
  9036. enumerable: false,
  9037. configurable: true
  9038. });
  9039. return Container;
  9040. }(DisplayObject));
  9041. /**
  9042. * Container default updateTransform, does update children of container.
  9043. * Will crash if there's no parent element.
  9044. *
  9045. * @memberof PIXI.Container#
  9046. * @method containerUpdateTransform
  9047. */
  9048. Container.prototype.containerUpdateTransform = Container.prototype.updateTransform;
  9049. /*!
  9050. * @pixi/accessibility - v6.1.2
  9051. * Compiled Thu, 12 Aug 2021 17:11:19 UTC
  9052. *
  9053. * @pixi/accessibility is licensed under the MIT License.
  9054. * http://www.opensource.org/licenses/mit-license
  9055. */
  9056. /**
  9057. * Default property values of accessible objects
  9058. * used by {@link PIXI.AccessibilityManager}.
  9059. *
  9060. * @private
  9061. * @function accessibleTarget
  9062. * @memberof PIXI
  9063. * @type {Object}
  9064. * @example
  9065. * function MyObject() {}
  9066. *
  9067. * Object.assign(
  9068. * MyObject.prototype,
  9069. * PIXI.accessibleTarget
  9070. * );
  9071. */
  9072. var accessibleTarget = {
  9073. /**
  9074. * Flag for if the object is accessible. If true AccessibilityManager will overlay a
  9075. * shadow div with attributes set
  9076. *
  9077. * @member {boolean}
  9078. * @memberof PIXI.DisplayObject#
  9079. */
  9080. accessible: false,
  9081. /**
  9082. * Sets the title attribute of the shadow div
  9083. * If accessibleTitle AND accessibleHint has not been this will default to 'displayObject [tabIndex]'
  9084. *
  9085. * @member {?string}
  9086. * @memberof PIXI.DisplayObject#
  9087. */
  9088. accessibleTitle: null,
  9089. /**
  9090. * Sets the aria-label attribute of the shadow div
  9091. *
  9092. * @member {string}
  9093. * @memberof PIXI.DisplayObject#
  9094. */
  9095. accessibleHint: null,
  9096. /**
  9097. * @member {number}
  9098. * @memberof PIXI.DisplayObject#
  9099. * @private
  9100. * @todo Needs docs.
  9101. */
  9102. tabIndex: 0,
  9103. /**
  9104. * @member {boolean}
  9105. * @memberof PIXI.DisplayObject#
  9106. * @todo Needs docs.
  9107. */
  9108. _accessibleActive: false,
  9109. /**
  9110. * @member {boolean}
  9111. * @memberof PIXI.DisplayObject#
  9112. * @todo Needs docs.
  9113. */
  9114. _accessibleDiv: null,
  9115. /**
  9116. * Specify the type of div the accessible layer is. Screen readers treat the element differently
  9117. * depending on this type. Defaults to button.
  9118. *
  9119. * @member {string}
  9120. * @memberof PIXI.DisplayObject#
  9121. * @default 'button'
  9122. */
  9123. accessibleType: 'button',
  9124. /**
  9125. * Specify the pointer-events the accessible div will use
  9126. * Defaults to auto.
  9127. *
  9128. * @member {string}
  9129. * @memberof PIXI.DisplayObject#
  9130. * @default 'auto'
  9131. */
  9132. accessiblePointerEvents: 'auto',
  9133. /**
  9134. * Setting to false will prevent any children inside this container to
  9135. * be accessible. Defaults to true.
  9136. *
  9137. * @member {boolean}
  9138. * @memberof PIXI.DisplayObject#
  9139. * @default true
  9140. */
  9141. accessibleChildren: true,
  9142. renderId: -1,
  9143. };
  9144. // add some extra variables to the container..
  9145. DisplayObject.mixin(accessibleTarget);
  9146. var KEY_CODE_TAB = 9;
  9147. var DIV_TOUCH_SIZE = 100;
  9148. var DIV_TOUCH_POS_X = 0;
  9149. var DIV_TOUCH_POS_Y = 0;
  9150. var DIV_TOUCH_ZINDEX = 2;
  9151. var DIV_HOOK_SIZE = 1;
  9152. var DIV_HOOK_POS_X = -1000;
  9153. var DIV_HOOK_POS_Y = -1000;
  9154. var DIV_HOOK_ZINDEX = 2;
  9155. /**
  9156. * The Accessibility manager recreates the ability to tab and have content read by screen readers.
  9157. * This is very important as it can possibly help people with disabilities access PixiJS content.
  9158. *
  9159. * A DisplayObject can be made accessible just like it can be made interactive. This manager will map the
  9160. * events as if the mouse was being used, minimizing the effort required to implement.
  9161. *
  9162. * An instance of this class is automatically created by default, and can be found at `renderer.plugins.accessibility`
  9163. *
  9164. * @class
  9165. * @memberof PIXI
  9166. */
  9167. var AccessibilityManager = /** @class */ (function () {
  9168. /**
  9169. * @param {PIXI.CanvasRenderer|PIXI.Renderer} renderer - A reference to the current renderer
  9170. */
  9171. function AccessibilityManager(renderer) {
  9172. /** Setting this to true will visually show the divs. */
  9173. this.debug = false;
  9174. /** Internal variable, see isActive getter. */
  9175. this._isActive = false;
  9176. /** Internal variable, see isMobileAccessibility getter. */
  9177. this._isMobileAccessibility = false;
  9178. /** A simple pool for storing divs. */
  9179. this.pool = [];
  9180. /** This is a tick used to check if an object is no longer being rendered. */
  9181. this.renderId = 0;
  9182. /** The array of currently active accessible items. */
  9183. this.children = [];
  9184. /** Count to throttle div updates on android devices. */
  9185. this.androidUpdateCount = 0;
  9186. /** The frequency to update the div elements. */
  9187. this.androidUpdateFrequency = 500; // 2fps
  9188. this._hookDiv = null;
  9189. if (isMobile$1.tablet || isMobile$1.phone) {
  9190. this.createTouchHook();
  9191. }
  9192. // first we create a div that will sit over the PixiJS element. This is where the div overlays will go.
  9193. var div = document.createElement('div');
  9194. div.style.width = DIV_TOUCH_SIZE + "px";
  9195. div.style.height = DIV_TOUCH_SIZE + "px";
  9196. div.style.position = 'absolute';
  9197. div.style.top = DIV_TOUCH_POS_X + "px";
  9198. div.style.left = DIV_TOUCH_POS_Y + "px";
  9199. div.style.zIndex = DIV_TOUCH_ZINDEX.toString();
  9200. this.div = div;
  9201. this.renderer = renderer;
  9202. /**
  9203. * pre-bind the functions
  9204. *
  9205. * @type {Function}
  9206. * @private
  9207. */
  9208. this._onKeyDown = this._onKeyDown.bind(this);
  9209. /**
  9210. * pre-bind the functions
  9211. *
  9212. * @type {Function}
  9213. * @private
  9214. */
  9215. this._onMouseMove = this._onMouseMove.bind(this);
  9216. // let listen for tab.. once pressed we can fire up and show the accessibility layer
  9217. self.addEventListener('keydown', this._onKeyDown, false);
  9218. }
  9219. Object.defineProperty(AccessibilityManager.prototype, "isActive", {
  9220. /**
  9221. * Value of `true` if accessibility is currently active and accessibility layers are showing.
  9222. * @member {boolean}
  9223. * @readonly
  9224. */
  9225. get: function () {
  9226. return this._isActive;
  9227. },
  9228. enumerable: false,
  9229. configurable: true
  9230. });
  9231. Object.defineProperty(AccessibilityManager.prototype, "isMobileAccessibility", {
  9232. /**
  9233. * Value of `true` if accessibility is enabled for touch devices.
  9234. * @member {boolean}
  9235. * @readonly
  9236. */
  9237. get: function () {
  9238. return this._isMobileAccessibility;
  9239. },
  9240. enumerable: false,
  9241. configurable: true
  9242. });
  9243. /**
  9244. * Creates the touch hooks.
  9245. *
  9246. * @private
  9247. */
  9248. AccessibilityManager.prototype.createTouchHook = function () {
  9249. var _this = this;
  9250. var hookDiv = document.createElement('button');
  9251. hookDiv.style.width = DIV_HOOK_SIZE + "px";
  9252. hookDiv.style.height = DIV_HOOK_SIZE + "px";
  9253. hookDiv.style.position = 'absolute';
  9254. hookDiv.style.top = DIV_HOOK_POS_X + "px";
  9255. hookDiv.style.left = DIV_HOOK_POS_Y + "px";
  9256. hookDiv.style.zIndex = DIV_HOOK_ZINDEX.toString();
  9257. hookDiv.style.backgroundColor = '#FF0000';
  9258. hookDiv.title = 'select to enable accessibility for this content';
  9259. hookDiv.addEventListener('focus', function () {
  9260. _this._isMobileAccessibility = true;
  9261. _this.activate();
  9262. _this.destroyTouchHook();
  9263. });
  9264. document.body.appendChild(hookDiv);
  9265. this._hookDiv = hookDiv;
  9266. };
  9267. /**
  9268. * Destroys the touch hooks.
  9269. *
  9270. * @private
  9271. */
  9272. AccessibilityManager.prototype.destroyTouchHook = function () {
  9273. if (!this._hookDiv) {
  9274. return;
  9275. }
  9276. document.body.removeChild(this._hookDiv);
  9277. this._hookDiv = null;
  9278. };
  9279. /**
  9280. * Activating will cause the Accessibility layer to be shown.
  9281. * This is called when a user presses the tab key.
  9282. *
  9283. * @private
  9284. */
  9285. AccessibilityManager.prototype.activate = function () {
  9286. var _a;
  9287. if (this._isActive) {
  9288. return;
  9289. }
  9290. this._isActive = true;
  9291. self.document.addEventListener('mousemove', this._onMouseMove, true);
  9292. self.removeEventListener('keydown', this._onKeyDown, false);
  9293. this.renderer.on('postrender', this.update, this);
  9294. (_a = this.renderer.view.parentNode) === null || _a === void 0 ? void 0 : _a.appendChild(this.div);
  9295. };
  9296. /**
  9297. * Deactivating will cause the Accessibility layer to be hidden.
  9298. * This is called when a user moves the mouse.
  9299. *
  9300. * @private
  9301. */
  9302. AccessibilityManager.prototype.deactivate = function () {
  9303. var _a;
  9304. if (!this._isActive || this._isMobileAccessibility) {
  9305. return;
  9306. }
  9307. this._isActive = false;
  9308. self.document.removeEventListener('mousemove', this._onMouseMove, true);
  9309. self.addEventListener('keydown', this._onKeyDown, false);
  9310. this.renderer.off('postrender', this.update);
  9311. (_a = this.div.parentNode) === null || _a === void 0 ? void 0 : _a.removeChild(this.div);
  9312. };
  9313. /**
  9314. * This recursive function will run through the scene graph and add any new accessible objects to the DOM layer.
  9315. *
  9316. * @private
  9317. * @param {PIXI.Container} displayObject - The DisplayObject to check.
  9318. */
  9319. AccessibilityManager.prototype.updateAccessibleObjects = function (displayObject) {
  9320. if (!displayObject.visible || !displayObject.accessibleChildren) {
  9321. return;
  9322. }
  9323. if (displayObject.accessible && displayObject.interactive) {
  9324. if (!displayObject._accessibleActive) {
  9325. this.addChild(displayObject);
  9326. }
  9327. displayObject.renderId = this.renderId;
  9328. }
  9329. var children = displayObject.children;
  9330. for (var i = 0; i < children.length; i++) {
  9331. this.updateAccessibleObjects(children[i]);
  9332. }
  9333. };
  9334. /**
  9335. * Before each render this function will ensure that all divs are mapped correctly to their DisplayObjects.
  9336. *
  9337. * @private
  9338. */
  9339. AccessibilityManager.prototype.update = function () {
  9340. /* On Android default web browser, tab order seems to be calculated by position rather than tabIndex,
  9341. * moving buttons can cause focus to flicker between two buttons making it hard/impossible to navigate,
  9342. * so I am just running update every half a second, seems to fix it.
  9343. */
  9344. var now = performance.now();
  9345. if (isMobile$1.android.device && now < this.androidUpdateCount) {
  9346. return;
  9347. }
  9348. this.androidUpdateCount = now + this.androidUpdateFrequency;
  9349. if (!this.renderer.renderingToScreen) {
  9350. return;
  9351. }
  9352. // update children...
  9353. if (this.renderer._lastObjectRendered) {
  9354. this.updateAccessibleObjects(this.renderer._lastObjectRendered);
  9355. }
  9356. var _a = this.renderer.view.getBoundingClientRect(), left = _a.left, top = _a.top, width = _a.width, height = _a.height;
  9357. var _b = this.renderer, viewWidth = _b.width, viewHeight = _b.height, resolution = _b.resolution;
  9358. var sx = (width / viewWidth) * resolution;
  9359. var sy = (height / viewHeight) * resolution;
  9360. var div = this.div;
  9361. div.style.left = left + "px";
  9362. div.style.top = top + "px";
  9363. div.style.width = viewWidth + "px";
  9364. div.style.height = viewHeight + "px";
  9365. for (var i = 0; i < this.children.length; i++) {
  9366. var child = this.children[i];
  9367. if (child.renderId !== this.renderId) {
  9368. child._accessibleActive = false;
  9369. removeItems(this.children, i, 1);
  9370. this.div.removeChild(child._accessibleDiv);
  9371. this.pool.push(child._accessibleDiv);
  9372. child._accessibleDiv = null;
  9373. i--;
  9374. }
  9375. else {
  9376. // map div to display..
  9377. div = child._accessibleDiv;
  9378. var hitArea = child.hitArea;
  9379. var wt = child.worldTransform;
  9380. if (child.hitArea) {
  9381. div.style.left = (wt.tx + (hitArea.x * wt.a)) * sx + "px";
  9382. div.style.top = (wt.ty + (hitArea.y * wt.d)) * sy + "px";
  9383. div.style.width = hitArea.width * wt.a * sx + "px";
  9384. div.style.height = hitArea.height * wt.d * sy + "px";
  9385. }
  9386. else {
  9387. hitArea = child.getBounds();
  9388. this.capHitArea(hitArea);
  9389. div.style.left = hitArea.x * sx + "px";
  9390. div.style.top = hitArea.y * sy + "px";
  9391. div.style.width = hitArea.width * sx + "px";
  9392. div.style.height = hitArea.height * sy + "px";
  9393. // update button titles and hints if they exist and they've changed
  9394. if (div.title !== child.accessibleTitle && child.accessibleTitle !== null) {
  9395. div.title = child.accessibleTitle;
  9396. }
  9397. if (div.getAttribute('aria-label') !== child.accessibleHint
  9398. && child.accessibleHint !== null) {
  9399. div.setAttribute('aria-label', child.accessibleHint);
  9400. }
  9401. }
  9402. // the title or index may have changed, if so lets update it!
  9403. if (child.accessibleTitle !== div.title || child.tabIndex !== div.tabIndex) {
  9404. div.title = child.accessibleTitle;
  9405. div.tabIndex = child.tabIndex;
  9406. if (this.debug)
  9407. { this.updateDebugHTML(div); }
  9408. }
  9409. }
  9410. }
  9411. // increment the render id..
  9412. this.renderId++;
  9413. };
  9414. /**
  9415. * private function that will visually add the information to the
  9416. * accessability div
  9417. *
  9418. * @param {HTMLElement} div
  9419. */
  9420. AccessibilityManager.prototype.updateDebugHTML = function (div) {
  9421. div.innerHTML = "type: " + div.type + "</br> title : " + div.title + "</br> tabIndex: " + div.tabIndex;
  9422. };
  9423. /**
  9424. * Adjust the hit area based on the bounds of a display object
  9425. *
  9426. * @param {PIXI.Rectangle} hitArea - Bounds of the child
  9427. */
  9428. AccessibilityManager.prototype.capHitArea = function (hitArea) {
  9429. if (hitArea.x < 0) {
  9430. hitArea.width += hitArea.x;
  9431. hitArea.x = 0;
  9432. }
  9433. if (hitArea.y < 0) {
  9434. hitArea.height += hitArea.y;
  9435. hitArea.y = 0;
  9436. }
  9437. var _a = this.renderer, viewWidth = _a.width, viewHeight = _a.height;
  9438. if (hitArea.x + hitArea.width > viewWidth) {
  9439. hitArea.width = viewWidth - hitArea.x;
  9440. }
  9441. if (hitArea.y + hitArea.height > viewHeight) {
  9442. hitArea.height = viewHeight - hitArea.y;
  9443. }
  9444. };
  9445. /**
  9446. * Adds a DisplayObject to the accessibility manager
  9447. *
  9448. * @private
  9449. * @param {PIXI.DisplayObject} displayObject - The child to make accessible.
  9450. */
  9451. AccessibilityManager.prototype.addChild = function (displayObject) {
  9452. // this.activate();
  9453. var div = this.pool.pop();
  9454. if (!div) {
  9455. div = document.createElement('button');
  9456. div.style.width = DIV_TOUCH_SIZE + "px";
  9457. div.style.height = DIV_TOUCH_SIZE + "px";
  9458. div.style.backgroundColor = this.debug ? 'rgba(255,255,255,0.5)' : 'transparent';
  9459. div.style.position = 'absolute';
  9460. div.style.zIndex = DIV_TOUCH_ZINDEX.toString();
  9461. div.style.borderStyle = 'none';
  9462. // ARIA attributes ensure that button title and hint updates are announced properly
  9463. if (navigator.userAgent.toLowerCase().indexOf('chrome') > -1) {
  9464. // Chrome doesn't need aria-live to work as intended; in fact it just gets more confused.
  9465. div.setAttribute('aria-live', 'off');
  9466. }
  9467. else {
  9468. div.setAttribute('aria-live', 'polite');
  9469. }
  9470. if (navigator.userAgent.match(/rv:.*Gecko\//)) {
  9471. // FireFox needs this to announce only the new button name
  9472. div.setAttribute('aria-relevant', 'additions');
  9473. }
  9474. else {
  9475. // required by IE, other browsers don't much care
  9476. div.setAttribute('aria-relevant', 'text');
  9477. }
  9478. div.addEventListener('click', this._onClick.bind(this));
  9479. div.addEventListener('focus', this._onFocus.bind(this));
  9480. div.addEventListener('focusout', this._onFocusOut.bind(this));
  9481. }
  9482. // set pointer events
  9483. div.style.pointerEvents = displayObject.accessiblePointerEvents;
  9484. // set the type, this defaults to button!
  9485. div.type = displayObject.accessibleType;
  9486. if (displayObject.accessibleTitle && displayObject.accessibleTitle !== null) {
  9487. div.title = displayObject.accessibleTitle;
  9488. }
  9489. else if (!displayObject.accessibleHint
  9490. || displayObject.accessibleHint === null) {
  9491. div.title = "displayObject " + displayObject.tabIndex;
  9492. }
  9493. if (displayObject.accessibleHint
  9494. && displayObject.accessibleHint !== null) {
  9495. div.setAttribute('aria-label', displayObject.accessibleHint);
  9496. }
  9497. if (this.debug)
  9498. { this.updateDebugHTML(div); }
  9499. displayObject._accessibleActive = true;
  9500. displayObject._accessibleDiv = div;
  9501. div.displayObject = displayObject;
  9502. this.children.push(displayObject);
  9503. this.div.appendChild(displayObject._accessibleDiv);
  9504. displayObject._accessibleDiv.tabIndex = displayObject.tabIndex;
  9505. };
  9506. /**
  9507. * Maps the div button press to pixi's InteractionManager (click)
  9508. *
  9509. * @private
  9510. * @param {MouseEvent} e - The click event.
  9511. */
  9512. AccessibilityManager.prototype._onClick = function (e) {
  9513. var interactionManager = this.renderer.plugins.interaction;
  9514. var displayObject = e.target.displayObject;
  9515. var eventData = interactionManager.eventData;
  9516. interactionManager.dispatchEvent(displayObject, 'click', eventData);
  9517. interactionManager.dispatchEvent(displayObject, 'pointertap', eventData);
  9518. interactionManager.dispatchEvent(displayObject, 'tap', eventData);
  9519. };
  9520. /**
  9521. * Maps the div focus events to pixi's InteractionManager (mouseover)
  9522. *
  9523. * @private
  9524. * @param {FocusEvent} e - The focus event.
  9525. */
  9526. AccessibilityManager.prototype._onFocus = function (e) {
  9527. if (!e.target.getAttribute('aria-live')) {
  9528. e.target.setAttribute('aria-live', 'assertive');
  9529. }
  9530. var interactionManager = this.renderer.plugins.interaction;
  9531. var displayObject = e.target.displayObject;
  9532. var eventData = interactionManager.eventData;
  9533. interactionManager.dispatchEvent(displayObject, 'mouseover', eventData);
  9534. };
  9535. /**
  9536. * Maps the div focus events to pixi's InteractionManager (mouseout)
  9537. *
  9538. * @private
  9539. * @param {FocusEvent} e - The focusout event.
  9540. */
  9541. AccessibilityManager.prototype._onFocusOut = function (e) {
  9542. if (!e.target.getAttribute('aria-live')) {
  9543. e.target.setAttribute('aria-live', 'polite');
  9544. }
  9545. var interactionManager = this.renderer.plugins.interaction;
  9546. var displayObject = e.target.displayObject;
  9547. var eventData = interactionManager.eventData;
  9548. interactionManager.dispatchEvent(displayObject, 'mouseout', eventData);
  9549. };
  9550. /**
  9551. * Is called when a key is pressed
  9552. *
  9553. * @private
  9554. * @param {KeyboardEvent} e - The keydown event.
  9555. */
  9556. AccessibilityManager.prototype._onKeyDown = function (e) {
  9557. if (e.keyCode !== KEY_CODE_TAB) {
  9558. return;
  9559. }
  9560. this.activate();
  9561. };
  9562. /**
  9563. * Is called when the mouse moves across the renderer element
  9564. *
  9565. * @private
  9566. * @param {MouseEvent} e - The mouse event.
  9567. */
  9568. AccessibilityManager.prototype._onMouseMove = function (e) {
  9569. if (e.movementX === 0 && e.movementY === 0) {
  9570. return;
  9571. }
  9572. this.deactivate();
  9573. };
  9574. /**
  9575. * Destroys the accessibility manager
  9576. *
  9577. */
  9578. AccessibilityManager.prototype.destroy = function () {
  9579. this.destroyTouchHook();
  9580. this.div = null;
  9581. self.document.removeEventListener('mousemove', this._onMouseMove, true);
  9582. self.removeEventListener('keydown', this._onKeyDown);
  9583. this.pool = null;
  9584. this.children = null;
  9585. this.renderer = null;
  9586. };
  9587. return AccessibilityManager;
  9588. }());
  9589. /*!
  9590. * @pixi/ticker - v6.1.2
  9591. * Compiled Thu, 12 Aug 2021 17:11:19 UTC
  9592. *
  9593. * @pixi/ticker is licensed under the MIT License.
  9594. * http://www.opensource.org/licenses/mit-license
  9595. */
  9596. /**
  9597. * Target frames per millisecond.
  9598. *
  9599. * @static
  9600. * @name TARGET_FPMS
  9601. * @memberof PIXI.settings
  9602. * @type {number}
  9603. * @default 0.06
  9604. */
  9605. settings.TARGET_FPMS = 0.06;
  9606. /**
  9607. * Represents the update priorities used by internal PIXI classes when registered with
  9608. * the {@link PIXI.Ticker} object. Higher priority items are updated first and lower
  9609. * priority items, such as render, should go later.
  9610. *
  9611. * @static
  9612. * @constant
  9613. * @name UPDATE_PRIORITY
  9614. * @memberof PIXI
  9615. * @enum {number}
  9616. * @property {number} INTERACTION=50 Highest priority, used for {@link PIXI.InteractionManager}
  9617. * @property {number} HIGH=25 High priority updating, {@link PIXI.VideoBaseTexture} and {@link PIXI.AnimatedSprite}
  9618. * @property {number} NORMAL=0 Default priority for ticker events, see {@link PIXI.Ticker#add}.
  9619. * @property {number} LOW=-25 Low priority used for {@link PIXI.Application} rendering.
  9620. * @property {number} UTILITY=-50 Lowest priority used for {@link PIXI.BasePrepare} utility.
  9621. */
  9622. (function (UPDATE_PRIORITY) {
  9623. UPDATE_PRIORITY[UPDATE_PRIORITY["INTERACTION"] = 50] = "INTERACTION";
  9624. UPDATE_PRIORITY[UPDATE_PRIORITY["HIGH"] = 25] = "HIGH";
  9625. UPDATE_PRIORITY[UPDATE_PRIORITY["NORMAL"] = 0] = "NORMAL";
  9626. UPDATE_PRIORITY[UPDATE_PRIORITY["LOW"] = -25] = "LOW";
  9627. UPDATE_PRIORITY[UPDATE_PRIORITY["UTILITY"] = -50] = "UTILITY";
  9628. })(exports.UPDATE_PRIORITY || (exports.UPDATE_PRIORITY = {}));
  9629. /**
  9630. * Internal class for handling the priority sorting of ticker handlers.
  9631. *
  9632. * @private
  9633. * @class
  9634. * @memberof PIXI
  9635. */
  9636. var TickerListener = /** @class */ (function () {
  9637. /**
  9638. * Constructor
  9639. * @private
  9640. * @param fn - The listener function to be added for one update
  9641. * @param context - The listener context
  9642. * @param priority - The priority for emitting
  9643. * @param once - If the handler should fire once
  9644. */
  9645. function TickerListener(fn, context, priority, once) {
  9646. if (context === void 0) { context = null; }
  9647. if (priority === void 0) { priority = 0; }
  9648. if (once === void 0) { once = false; }
  9649. /** The next item in chain. */
  9650. this.next = null;
  9651. /** The previous item in chain. */
  9652. this.previous = null;
  9653. /** `true` if this listener has been destroyed already. */
  9654. this._destroyed = false;
  9655. this.fn = fn;
  9656. this.context = context;
  9657. this.priority = priority;
  9658. this.once = once;
  9659. }
  9660. /**
  9661. * Simple compare function to figure out if a function and context match.
  9662. * @private
  9663. * @param fn - The listener function to be added for one update
  9664. * @param context - The listener context
  9665. * @return `true` if the listener match the arguments
  9666. */
  9667. TickerListener.prototype.match = function (fn, context) {
  9668. if (context === void 0) { context = null; }
  9669. return this.fn === fn && this.context === context;
  9670. };
  9671. /**
  9672. * Emit by calling the current function.
  9673. * @private
  9674. * @param deltaTime - time since the last emit.
  9675. * @return Next ticker
  9676. */
  9677. TickerListener.prototype.emit = function (deltaTime) {
  9678. if (this.fn) {
  9679. if (this.context) {
  9680. this.fn.call(this.context, deltaTime);
  9681. }
  9682. else {
  9683. this.fn(deltaTime);
  9684. }
  9685. }
  9686. var redirect = this.next;
  9687. if (this.once) {
  9688. this.destroy(true);
  9689. }
  9690. // Soft-destroying should remove
  9691. // the next reference
  9692. if (this._destroyed) {
  9693. this.next = null;
  9694. }
  9695. return redirect;
  9696. };
  9697. /**
  9698. * Connect to the list.
  9699. * @private
  9700. * @param previous - Input node, previous listener
  9701. */
  9702. TickerListener.prototype.connect = function (previous) {
  9703. this.previous = previous;
  9704. if (previous.next) {
  9705. previous.next.previous = this;
  9706. }
  9707. this.next = previous.next;
  9708. previous.next = this;
  9709. };
  9710. /**
  9711. * Destroy and don't use after this.
  9712. * @private
  9713. * @param hard - `true` to remove the `next` reference, this
  9714. * is considered a hard destroy. Soft destroy maintains the next reference.
  9715. * @return The listener to redirect while emitting or removing.
  9716. */
  9717. TickerListener.prototype.destroy = function (hard) {
  9718. if (hard === void 0) { hard = false; }
  9719. this._destroyed = true;
  9720. this.fn = null;
  9721. this.context = null;
  9722. // Disconnect, hook up next and previous
  9723. if (this.previous) {
  9724. this.previous.next = this.next;
  9725. }
  9726. if (this.next) {
  9727. this.next.previous = this.previous;
  9728. }
  9729. // Redirect to the next item
  9730. var redirect = this.next;
  9731. // Remove references
  9732. this.next = hard ? null : redirect;
  9733. this.previous = null;
  9734. return redirect;
  9735. };
  9736. return TickerListener;
  9737. }());
  9738. /**
  9739. * A Ticker class that runs an update loop that other objects listen to.
  9740. *
  9741. * This class is composed around listeners meant for execution on the next requested animation frame.
  9742. * Animation frames are requested only when necessary, e.g. When the ticker is started and the emitter has listeners.
  9743. *
  9744. * @class
  9745. * @memberof PIXI
  9746. */
  9747. var Ticker = /** @class */ (function () {
  9748. function Ticker() {
  9749. var _this = this;
  9750. /**
  9751. * Whether or not this ticker should invoke the method
  9752. * {@link PIXI.Ticker#start} automatically
  9753. * when a listener is added.
  9754. */
  9755. this.autoStart = false;
  9756. /**
  9757. * Scalar time value from last frame to this frame.
  9758. * This value is capped by setting {@link PIXI.Ticker#minFPS}
  9759. * and is scaled with {@link PIXI.Ticker#speed}.
  9760. * **Note:** The cap may be exceeded by scaling.
  9761. */
  9762. this.deltaTime = 1;
  9763. /**
  9764. * The last time {@link PIXI.Ticker#update} was invoked.
  9765. * This value is also reset internally outside of invoking
  9766. * update, but only when a new animation frame is requested.
  9767. * If the platform supports DOMHighResTimeStamp,
  9768. * this value will have a precision of 1 µs.
  9769. */
  9770. this.lastTime = -1;
  9771. /**
  9772. * Factor of current {@link PIXI.Ticker#deltaTime}.
  9773. * @example
  9774. * // Scales ticker.deltaTime to what would be
  9775. * // the equivalent of approximately 120 FPS
  9776. * ticker.speed = 2;
  9777. */
  9778. this.speed = 1;
  9779. /**
  9780. * Whether or not this ticker has been started.
  9781. * `true` if {@link PIXI.Ticker#start} has been called.
  9782. * `false` if {@link PIXI.Ticker#stop} has been called.
  9783. * While `false`, this value may change to `true` in the
  9784. * event of {@link PIXI.Ticker#autoStart} being `true`
  9785. * and a listener is added.
  9786. */
  9787. this.started = false;
  9788. /** Internal current frame request ID */
  9789. this._requestId = null;
  9790. /**
  9791. * Internal value managed by minFPS property setter and getter.
  9792. * This is the maximum allowed milliseconds between updates.
  9793. */
  9794. this._maxElapsedMS = 100;
  9795. /**
  9796. * Internal value managed by minFPS property setter and getter.
  9797. * This is the maximum allowed milliseconds between updates.
  9798. */
  9799. this._minElapsedMS = 0;
  9800. /** If enabled, deleting is disabled.*/
  9801. this._protected = false;
  9802. /**
  9803. * The last time keyframe was executed.
  9804. * Maintains a relatively fixed interval with the previous value.
  9805. */
  9806. this._lastFrame = -1;
  9807. this._head = new TickerListener(null, null, Infinity);
  9808. this.deltaMS = 1 / settings.TARGET_FPMS;
  9809. this.elapsedMS = 1 / settings.TARGET_FPMS;
  9810. this._tick = function (time) {
  9811. _this._requestId = null;
  9812. if (_this.started) {
  9813. // Invoke listeners now
  9814. _this.update(time);
  9815. // Listener side effects may have modified ticker state.
  9816. if (_this.started && _this._requestId === null && _this._head.next) {
  9817. _this._requestId = requestAnimationFrame(_this._tick);
  9818. }
  9819. }
  9820. };
  9821. }
  9822. /**
  9823. * Conditionally requests a new animation frame.
  9824. * If a frame has not already been requested, and if the internal
  9825. * emitter has listeners, a new frame is requested.
  9826. *
  9827. * @private
  9828. */
  9829. Ticker.prototype._requestIfNeeded = function () {
  9830. if (this._requestId === null && this._head.next) {
  9831. // ensure callbacks get correct delta
  9832. this.lastTime = performance.now();
  9833. this._lastFrame = this.lastTime;
  9834. this._requestId = requestAnimationFrame(this._tick);
  9835. }
  9836. };
  9837. /**
  9838. * Conditionally cancels a pending animation frame.
  9839. * @private
  9840. */
  9841. Ticker.prototype._cancelIfNeeded = function () {
  9842. if (this._requestId !== null) {
  9843. cancelAnimationFrame(this._requestId);
  9844. this._requestId = null;
  9845. }
  9846. };
  9847. /**
  9848. * Conditionally requests a new animation frame.
  9849. * If the ticker has been started it checks if a frame has not already
  9850. * been requested, and if the internal emitter has listeners. If these
  9851. * conditions are met, a new frame is requested. If the ticker has not
  9852. * been started, but autoStart is `true`, then the ticker starts now,
  9853. * and continues with the previous conditions to request a new frame.
  9854. *
  9855. * @private
  9856. */
  9857. Ticker.prototype._startIfPossible = function () {
  9858. if (this.started) {
  9859. this._requestIfNeeded();
  9860. }
  9861. else if (this.autoStart) {
  9862. this.start();
  9863. }
  9864. };
  9865. /**
  9866. * Register a handler for tick events. Calls continuously unless
  9867. * it is removed or the ticker is stopped.
  9868. *
  9869. * @param fn - The listener function to be added for updates
  9870. * @param context - The listener context
  9871. * @param {number} [priority=PIXI.UPDATE_PRIORITY.NORMAL] - The priority for emitting
  9872. * @returns This instance of a ticker
  9873. */
  9874. Ticker.prototype.add = function (fn, context, priority) {
  9875. if (priority === void 0) { priority = exports.UPDATE_PRIORITY.NORMAL; }
  9876. return this._addListener(new TickerListener(fn, context, priority));
  9877. };
  9878. /**
  9879. * Add a handler for the tick event which is only execute once.
  9880. *
  9881. * @param fn - The listener function to be added for one update
  9882. * @param context - The listener context
  9883. * @param {number} [priority=PIXI.UPDATE_PRIORITY.NORMAL] - The priority for emitting
  9884. * @returns This instance of a ticker
  9885. */
  9886. Ticker.prototype.addOnce = function (fn, context, priority) {
  9887. if (priority === void 0) { priority = exports.UPDATE_PRIORITY.NORMAL; }
  9888. return this._addListener(new TickerListener(fn, context, priority, true));
  9889. };
  9890. /**
  9891. * Internally adds the event handler so that it can be sorted by priority.
  9892. * Priority allows certain handler (user, AnimatedSprite, Interaction) to be run
  9893. * before the rendering.
  9894. *
  9895. * @private
  9896. * @param listener - Current listener being added.
  9897. * @returns This instance of a ticker
  9898. */
  9899. Ticker.prototype._addListener = function (listener) {
  9900. // For attaching to head
  9901. var current = this._head.next;
  9902. var previous = this._head;
  9903. // Add the first item
  9904. if (!current) {
  9905. listener.connect(previous);
  9906. }
  9907. else {
  9908. // Go from highest to lowest priority
  9909. while (current) {
  9910. if (listener.priority > current.priority) {
  9911. listener.connect(previous);
  9912. break;
  9913. }
  9914. previous = current;
  9915. current = current.next;
  9916. }
  9917. // Not yet connected
  9918. if (!listener.previous) {
  9919. listener.connect(previous);
  9920. }
  9921. }
  9922. this._startIfPossible();
  9923. return this;
  9924. };
  9925. /**
  9926. * Removes any handlers matching the function and context parameters.
  9927. * If no handlers are left after removing, then it cancels the animation frame.
  9928. *
  9929. * @param fn - The listener function to be removed
  9930. * @param context - The listener context to be removed
  9931. * @returns This instance of a ticker
  9932. */
  9933. Ticker.prototype.remove = function (fn, context) {
  9934. var listener = this._head.next;
  9935. while (listener) {
  9936. // We found a match, lets remove it
  9937. // no break to delete all possible matches
  9938. // incase a listener was added 2+ times
  9939. if (listener.match(fn, context)) {
  9940. listener = listener.destroy();
  9941. }
  9942. else {
  9943. listener = listener.next;
  9944. }
  9945. }
  9946. if (!this._head.next) {
  9947. this._cancelIfNeeded();
  9948. }
  9949. return this;
  9950. };
  9951. Object.defineProperty(Ticker.prototype, "count", {
  9952. /**
  9953. * The number of listeners on this ticker, calculated by walking through linked list
  9954. *
  9955. * @readonly
  9956. * @member {number}
  9957. */
  9958. get: function () {
  9959. if (!this._head) {
  9960. return 0;
  9961. }
  9962. var count = 0;
  9963. var current = this._head;
  9964. while ((current = current.next)) {
  9965. count++;
  9966. }
  9967. return count;
  9968. },
  9969. enumerable: false,
  9970. configurable: true
  9971. });
  9972. /**
  9973. * Starts the ticker. If the ticker has listeners
  9974. * a new animation frame is requested at this point.
  9975. */
  9976. Ticker.prototype.start = function () {
  9977. if (!this.started) {
  9978. this.started = true;
  9979. this._requestIfNeeded();
  9980. }
  9981. };
  9982. /**
  9983. * Stops the ticker. If the ticker has requested
  9984. * an animation frame it is canceled at this point.
  9985. */
  9986. Ticker.prototype.stop = function () {
  9987. if (this.started) {
  9988. this.started = false;
  9989. this._cancelIfNeeded();
  9990. }
  9991. };
  9992. /**
  9993. * Destroy the ticker and don't use after this. Calling
  9994. * this method removes all references to internal events.
  9995. */
  9996. Ticker.prototype.destroy = function () {
  9997. if (!this._protected) {
  9998. this.stop();
  9999. var listener = this._head.next;
  10000. while (listener) {
  10001. listener = listener.destroy(true);
  10002. }
  10003. this._head.destroy();
  10004. this._head = null;
  10005. }
  10006. };
  10007. /**
  10008. * Triggers an update. An update entails setting the
  10009. * current {@link PIXI.Ticker#elapsedMS},
  10010. * the current {@link PIXI.Ticker#deltaTime},
  10011. * invoking all listeners with current deltaTime,
  10012. * and then finally setting {@link PIXI.Ticker#lastTime}
  10013. * with the value of currentTime that was provided.
  10014. * This method will be called automatically by animation
  10015. * frame callbacks if the ticker instance has been started
  10016. * and listeners are added.
  10017. *
  10018. * @param {number} [currentTime=performance.now()] - the current time of execution
  10019. */
  10020. Ticker.prototype.update = function (currentTime) {
  10021. if (currentTime === void 0) { currentTime = performance.now(); }
  10022. var elapsedMS;
  10023. // If the difference in time is zero or negative, we ignore most of the work done here.
  10024. // If there is no valid difference, then should be no reason to let anyone know about it.
  10025. // A zero delta, is exactly that, nothing should update.
  10026. //
  10027. // The difference in time can be negative, and no this does not mean time traveling.
  10028. // This can be the result of a race condition between when an animation frame is requested
  10029. // on the current JavaScript engine event loop, and when the ticker's start method is invoked
  10030. // (which invokes the internal _requestIfNeeded method). If a frame is requested before
  10031. // _requestIfNeeded is invoked, then the callback for the animation frame the ticker requests,
  10032. // can receive a time argument that can be less than the lastTime value that was set within
  10033. // _requestIfNeeded. This difference is in microseconds, but this is enough to cause problems.
  10034. //
  10035. // This check covers this browser engine timing issue, as well as if consumers pass an invalid
  10036. // currentTime value. This may happen if consumers opt-out of the autoStart, and update themselves.
  10037. if (currentTime > this.lastTime) {
  10038. // Save uncapped elapsedMS for measurement
  10039. elapsedMS = this.elapsedMS = currentTime - this.lastTime;
  10040. // cap the milliseconds elapsed used for deltaTime
  10041. if (elapsedMS > this._maxElapsedMS) {
  10042. elapsedMS = this._maxElapsedMS;
  10043. }
  10044. elapsedMS *= this.speed;
  10045. // If not enough time has passed, exit the function.
  10046. // Get ready for next frame by setting _lastFrame, but based on _minElapsedMS
  10047. // adjustment to ensure a relatively stable interval.
  10048. if (this._minElapsedMS) {
  10049. var delta = currentTime - this._lastFrame | 0;
  10050. if (delta < this._minElapsedMS) {
  10051. return;
  10052. }
  10053. this._lastFrame = currentTime - (delta % this._minElapsedMS);
  10054. }
  10055. this.deltaMS = elapsedMS;
  10056. this.deltaTime = this.deltaMS * settings.TARGET_FPMS;
  10057. // Cache a local reference, in-case ticker is destroyed
  10058. // during the emit, we can still check for head.next
  10059. var head = this._head;
  10060. // Invoke listeners added to internal emitter
  10061. var listener = head.next;
  10062. while (listener) {
  10063. listener = listener.emit(this.deltaTime);
  10064. }
  10065. if (!head.next) {
  10066. this._cancelIfNeeded();
  10067. }
  10068. }
  10069. else {
  10070. this.deltaTime = this.deltaMS = this.elapsedMS = 0;
  10071. }
  10072. this.lastTime = currentTime;
  10073. };
  10074. Object.defineProperty(Ticker.prototype, "FPS", {
  10075. /**
  10076. * The frames per second at which this ticker is running.
  10077. * The default is approximately 60 in most modern browsers.
  10078. * **Note:** This does not factor in the value of
  10079. * {@link PIXI.Ticker#speed}, which is specific
  10080. * to scaling {@link PIXI.Ticker#deltaTime}.
  10081. *
  10082. * @member {number}
  10083. * @readonly
  10084. */
  10085. get: function () {
  10086. return 1000 / this.elapsedMS;
  10087. },
  10088. enumerable: false,
  10089. configurable: true
  10090. });
  10091. Object.defineProperty(Ticker.prototype, "minFPS", {
  10092. /**
  10093. * Manages the maximum amount of milliseconds allowed to
  10094. * elapse between invoking {@link PIXI.Ticker#update}.
  10095. * This value is used to cap {@link PIXI.Ticker#deltaTime},
  10096. * but does not effect the measured value of {@link PIXI.Ticker#FPS}.
  10097. * When setting this property it is clamped to a value between
  10098. * `0` and `PIXI.settings.TARGET_FPMS * 1000`.
  10099. *
  10100. * @member {number}
  10101. * @default 10
  10102. */
  10103. get: function () {
  10104. return 1000 / this._maxElapsedMS;
  10105. },
  10106. set: function (fps) {
  10107. // Minimum must be below the maxFPS
  10108. var minFPS = Math.min(this.maxFPS, fps);
  10109. // Must be at least 0, but below 1 / settings.TARGET_FPMS
  10110. var minFPMS = Math.min(Math.max(0, minFPS) / 1000, settings.TARGET_FPMS);
  10111. this._maxElapsedMS = 1 / minFPMS;
  10112. },
  10113. enumerable: false,
  10114. configurable: true
  10115. });
  10116. Object.defineProperty(Ticker.prototype, "maxFPS", {
  10117. /**
  10118. * Manages the minimum amount of milliseconds required to
  10119. * elapse between invoking {@link PIXI.Ticker#update}.
  10120. * This will effect the measured value of {@link PIXI.Ticker#FPS}.
  10121. * If it is set to `0`, then there is no limit; PixiJS will render as many frames as it can.
  10122. * Otherwise it will be at least `minFPS`
  10123. *
  10124. * @member {number}
  10125. * @default 0
  10126. */
  10127. get: function () {
  10128. if (this._minElapsedMS) {
  10129. return Math.round(1000 / this._minElapsedMS);
  10130. }
  10131. return 0;
  10132. },
  10133. set: function (fps) {
  10134. if (fps === 0) {
  10135. this._minElapsedMS = 0;
  10136. }
  10137. else {
  10138. // Max must be at least the minFPS
  10139. var maxFPS = Math.max(this.minFPS, fps);
  10140. this._minElapsedMS = 1 / (maxFPS / 1000);
  10141. }
  10142. },
  10143. enumerable: false,
  10144. configurable: true
  10145. });
  10146. Object.defineProperty(Ticker, "shared", {
  10147. /**
  10148. * The shared ticker instance used by {@link PIXI.AnimatedSprite} and by
  10149. * {@link PIXI.VideoResource} to update animation frames / video textures.
  10150. *
  10151. * It may also be used by {@link PIXI.Application} if created with the `sharedTicker` option property set to true.
  10152. *
  10153. * The property {@link PIXI.Ticker#autoStart} is set to `true` for this instance.
  10154. * Please follow the examples for usage, including how to opt-out of auto-starting the shared ticker.
  10155. *
  10156. * @example
  10157. * let ticker = PIXI.Ticker.shared;
  10158. * // Set this to prevent starting this ticker when listeners are added.
  10159. * // By default this is true only for the PIXI.Ticker.shared instance.
  10160. * ticker.autoStart = false;
  10161. * // FYI, call this to ensure the ticker is stopped. It should be stopped
  10162. * // if you have not attempted to render anything yet.
  10163. * ticker.stop();
  10164. * // Call this when you are ready for a running shared ticker.
  10165. * ticker.start();
  10166. *
  10167. * @example
  10168. * // You may use the shared ticker to render...
  10169. * let renderer = PIXI.autoDetectRenderer();
  10170. * let stage = new PIXI.Container();
  10171. * document.body.appendChild(renderer.view);
  10172. * ticker.add(function (time) {
  10173. * renderer.render(stage);
  10174. * });
  10175. *
  10176. * @example
  10177. * // Or you can just update it manually.
  10178. * ticker.autoStart = false;
  10179. * ticker.stop();
  10180. * function animate(time) {
  10181. * ticker.update(time);
  10182. * renderer.render(stage);
  10183. * requestAnimationFrame(animate);
  10184. * }
  10185. * animate(performance.now());
  10186. *
  10187. * @member {PIXI.Ticker}
  10188. * @static
  10189. */
  10190. get: function () {
  10191. if (!Ticker._shared) {
  10192. var shared = Ticker._shared = new Ticker();
  10193. shared.autoStart = true;
  10194. shared._protected = true;
  10195. }
  10196. return Ticker._shared;
  10197. },
  10198. enumerable: false,
  10199. configurable: true
  10200. });
  10201. Object.defineProperty(Ticker, "system", {
  10202. /**
  10203. * The system ticker instance used by {@link PIXI.InteractionManager} and by
  10204. * {@link PIXI.BasePrepare} for core timing functionality that shouldn't usually need to be paused,
  10205. * unlike the `shared` ticker which drives visual animations and rendering which may want to be paused.
  10206. *
  10207. * The property {@link PIXI.Ticker#autoStart} is set to `true` for this instance.
  10208. *
  10209. * @member {PIXI.Ticker}
  10210. * @static
  10211. */
  10212. get: function () {
  10213. if (!Ticker._system) {
  10214. var system = Ticker._system = new Ticker();
  10215. system.autoStart = true;
  10216. system._protected = true;
  10217. }
  10218. return Ticker._system;
  10219. },
  10220. enumerable: false,
  10221. configurable: true
  10222. });
  10223. return Ticker;
  10224. }());
  10225. /**
  10226. * Middleware for for Application Ticker.
  10227. *
  10228. * @example
  10229. * import {TickerPlugin} from '@pixi/ticker';
  10230. * import {Application} from '@pixi/app';
  10231. * Application.registerPlugin(TickerPlugin);
  10232. *
  10233. * @class
  10234. * @memberof PIXI
  10235. */
  10236. var TickerPlugin = /** @class */ (function () {
  10237. function TickerPlugin() {
  10238. }
  10239. /**
  10240. * Initialize the plugin with scope of application instance
  10241. *
  10242. * @static
  10243. * @private
  10244. * @param {object} [options] - See application options
  10245. */
  10246. TickerPlugin.init = function (options) {
  10247. var _this = this;
  10248. // Set default
  10249. options = Object.assign({
  10250. autoStart: true,
  10251. sharedTicker: false,
  10252. }, options);
  10253. // Create ticker setter
  10254. Object.defineProperty(this, 'ticker', {
  10255. set: function (ticker) {
  10256. if (this._ticker) {
  10257. this._ticker.remove(this.render, this);
  10258. }
  10259. this._ticker = ticker;
  10260. if (ticker) {
  10261. ticker.add(this.render, this, exports.UPDATE_PRIORITY.LOW);
  10262. }
  10263. },
  10264. get: function () {
  10265. return this._ticker;
  10266. },
  10267. });
  10268. /**
  10269. * Convenience method for stopping the render.
  10270. *
  10271. * @method
  10272. * @memberof PIXI.Application
  10273. * @instance
  10274. */
  10275. this.stop = function () {
  10276. _this._ticker.stop();
  10277. };
  10278. /**
  10279. * Convenience method for starting the render.
  10280. *
  10281. * @method
  10282. * @memberof PIXI.Application
  10283. * @instance
  10284. */
  10285. this.start = function () {
  10286. _this._ticker.start();
  10287. };
  10288. /**
  10289. * Internal reference to the ticker.
  10290. *
  10291. * @type {PIXI.Ticker}
  10292. * @name _ticker
  10293. * @memberof PIXI.Application#
  10294. * @private
  10295. */
  10296. this._ticker = null;
  10297. /**
  10298. * Ticker for doing render updates.
  10299. *
  10300. * @type {PIXI.Ticker}
  10301. * @name ticker
  10302. * @memberof PIXI.Application#
  10303. * @default PIXI.Ticker.shared
  10304. */
  10305. this.ticker = options.sharedTicker ? Ticker.shared : new Ticker();
  10306. // Start the rendering
  10307. if (options.autoStart) {
  10308. this.start();
  10309. }
  10310. };
  10311. /**
  10312. * Clean up the ticker, scoped to application.
  10313. *
  10314. * @static
  10315. * @private
  10316. */
  10317. TickerPlugin.destroy = function () {
  10318. if (this._ticker) {
  10319. var oldTicker = this._ticker;
  10320. this.ticker = null;
  10321. oldTicker.destroy();
  10322. }
  10323. };
  10324. return TickerPlugin;
  10325. }());
  10326. /*!
  10327. * @pixi/interaction - v6.1.2
  10328. * Compiled Thu, 12 Aug 2021 17:11:19 UTC
  10329. *
  10330. * @pixi/interaction is licensed under the MIT License.
  10331. * http://www.opensource.org/licenses/mit-license
  10332. */
  10333. /**
  10334. * Holds all information related to an Interaction event
  10335. *
  10336. * @class
  10337. * @memberof PIXI
  10338. */
  10339. var InteractionData = /** @class */ (function () {
  10340. function InteractionData() {
  10341. this.pressure = 0;
  10342. this.rotationAngle = 0;
  10343. this.twist = 0;
  10344. this.tangentialPressure = 0;
  10345. /**
  10346. * This point stores the global coords of where the touch/mouse event happened
  10347. *
  10348. * @member {PIXI.Point}
  10349. */
  10350. this.global = new Point();
  10351. /**
  10352. * The target Sprite that was interacted with
  10353. *
  10354. * @member {PIXI.Sprite}
  10355. */
  10356. this.target = null;
  10357. /**
  10358. * When passed to an event handler, this will be the original DOM Event that was captured
  10359. *
  10360. * @see https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent
  10361. * @see https://developer.mozilla.org/en-US/docs/Web/API/TouchEvent
  10362. * @see https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent
  10363. * @member {MouseEvent|TouchEvent|PointerEvent}
  10364. */
  10365. this.originalEvent = null;
  10366. /**
  10367. * Unique identifier for this interaction
  10368. *
  10369. * @member {number}
  10370. */
  10371. this.identifier = null;
  10372. /**
  10373. * Indicates whether or not the pointer device that created the event is the primary pointer.
  10374. * @see https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/isPrimary
  10375. * @type {Boolean}
  10376. */
  10377. this.isPrimary = false;
  10378. /**
  10379. * Indicates which button was pressed on the mouse or pointer device to trigger the event.
  10380. * @see https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/button
  10381. * @type {number}
  10382. */
  10383. this.button = 0;
  10384. /**
  10385. * Indicates which buttons are pressed on the mouse or pointer device when the event is triggered.
  10386. * @see https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/buttons
  10387. * @type {number}
  10388. */
  10389. this.buttons = 0;
  10390. /**
  10391. * The width of the pointer's contact along the x-axis, measured in CSS pixels.
  10392. * radiusX of TouchEvents will be represented by this value.
  10393. * @see https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/width
  10394. * @type {number}
  10395. */
  10396. this.width = 0;
  10397. /**
  10398. * The height of the pointer's contact along the y-axis, measured in CSS pixels.
  10399. * radiusY of TouchEvents will be represented by this value.
  10400. * @see https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/height
  10401. * @type {number}
  10402. */
  10403. this.height = 0;
  10404. /**
  10405. * The angle, in degrees, between the pointer device and the screen.
  10406. * @see https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/tiltX
  10407. * @type {number}
  10408. */
  10409. this.tiltX = 0;
  10410. /**
  10411. * The angle, in degrees, between the pointer device and the screen.
  10412. * @see https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/tiltY
  10413. * @type {number}
  10414. */
  10415. this.tiltY = 0;
  10416. /**
  10417. * The type of pointer that triggered the event.
  10418. * @see https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/pointerType
  10419. * @type {string}
  10420. */
  10421. this.pointerType = null;
  10422. /**
  10423. * Pressure applied by the pointing device during the event. A Touch's force property
  10424. * will be represented by this value.
  10425. * @see https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/pressure
  10426. * @type {number}
  10427. */
  10428. this.pressure = 0;
  10429. /**
  10430. * From TouchEvents (not PointerEvents triggered by touches), the rotationAngle of the Touch.
  10431. * @see https://developer.mozilla.org/en-US/docs/Web/API/Touch/rotationAngle
  10432. * @type {number}
  10433. */
  10434. this.rotationAngle = 0;
  10435. /**
  10436. * Twist of a stylus pointer.
  10437. * @see https://w3c.github.io/pointerevents/#pointerevent-interface
  10438. * @type {number}
  10439. */
  10440. this.twist = 0;
  10441. /**
  10442. * Barrel pressure on a stylus pointer.
  10443. * @see https://w3c.github.io/pointerevents/#pointerevent-interface
  10444. * @type {number}
  10445. */
  10446. this.tangentialPressure = 0;
  10447. }
  10448. Object.defineProperty(InteractionData.prototype, "pointerId", {
  10449. /**
  10450. * The unique identifier of the pointer. It will be the same as `identifier`.
  10451. * @readonly
  10452. * @member {number}
  10453. * @see https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/pointerId
  10454. */
  10455. get: function () {
  10456. return this.identifier;
  10457. },
  10458. enumerable: false,
  10459. configurable: true
  10460. });
  10461. /**
  10462. * This will return the local coordinates of the specified displayObject for this InteractionData
  10463. *
  10464. * @param {PIXI.DisplayObject} displayObject - The DisplayObject that you would like the local
  10465. * coords off
  10466. * @param {PIXI.Point} [point] - A Point object in which to store the value, optional (otherwise
  10467. * will create a new point)
  10468. * @param {PIXI.Point} [globalPos] - A Point object containing your custom global coords, optional
  10469. * (otherwise will use the current global coords)
  10470. * @return {PIXI.Point} A point containing the coordinates of the InteractionData position relative
  10471. * to the DisplayObject
  10472. */
  10473. InteractionData.prototype.getLocalPosition = function (displayObject, point, globalPos) {
  10474. return displayObject.worldTransform.applyInverse(globalPos || this.global, point);
  10475. };
  10476. /**
  10477. * Copies properties from normalized event data.
  10478. *
  10479. * @param {Touch|MouseEvent|PointerEvent} event - The normalized event data
  10480. */
  10481. InteractionData.prototype.copyEvent = function (event) {
  10482. // isPrimary should only change on touchstart/pointerdown, so we don't want to overwrite
  10483. // it with "false" on later events when our shim for it on touch events might not be
  10484. // accurate
  10485. if ('isPrimary' in event && event.isPrimary) {
  10486. this.isPrimary = true;
  10487. }
  10488. this.button = 'button' in event && event.button;
  10489. // event.buttons is not available in all browsers (ie. Safari), but it does have a non-standard
  10490. // event.which property instead, which conveys the same information.
  10491. var buttons = 'buttons' in event && event.buttons;
  10492. this.buttons = Number.isInteger(buttons) ? buttons : 'which' in event && event.which;
  10493. this.width = 'width' in event && event.width;
  10494. this.height = 'height' in event && event.height;
  10495. this.tiltX = 'tiltX' in event && event.tiltX;
  10496. this.tiltY = 'tiltY' in event && event.tiltY;
  10497. this.pointerType = 'pointerType' in event && event.pointerType;
  10498. this.pressure = 'pressure' in event && event.pressure;
  10499. this.rotationAngle = 'rotationAngle' in event && event.rotationAngle;
  10500. this.twist = ('twist' in event && event.twist) || 0;
  10501. this.tangentialPressure = ('tangentialPressure' in event && event.tangentialPressure) || 0;
  10502. };
  10503. /**
  10504. * Resets the data for pooling.
  10505. */
  10506. InteractionData.prototype.reset = function () {
  10507. // isPrimary is the only property that we really need to reset - everything else is
  10508. // guaranteed to be overwritten
  10509. this.isPrimary = false;
  10510. };
  10511. return InteractionData;
  10512. }());
  10513. /*! *****************************************************************************
  10514. Copyright (c) Microsoft Corporation. All rights reserved.
  10515. Licensed under the Apache License, Version 2.0 (the "License"); you may not use
  10516. this file except in compliance with the License. You may obtain a copy of the
  10517. License at http://www.apache.org/licenses/LICENSE-2.0
  10518. THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  10519. KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
  10520. WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
  10521. MERCHANTABLITY OR NON-INFRINGEMENT.
  10522. See the Apache Version 2.0 License for specific language governing permissions
  10523. and limitations under the License.
  10524. ***************************************************************************** */
  10525. /* global Reflect, Promise */
  10526. var extendStatics$1 = function(d, b) {
  10527. extendStatics$1 = Object.setPrototypeOf ||
  10528. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  10529. function (d, b) { for (var p in b) { if (b.hasOwnProperty(p)) { d[p] = b[p]; } } };
  10530. return extendStatics$1(d, b);
  10531. };
  10532. function __extends$1(d, b) {
  10533. extendStatics$1(d, b);
  10534. function __() { this.constructor = d; }
  10535. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  10536. }
  10537. /**
  10538. * Event class that mimics native DOM events.
  10539. *
  10540. * @class
  10541. * @memberof PIXI
  10542. */
  10543. var InteractionEvent = /** @class */ (function () {
  10544. function InteractionEvent() {
  10545. /**
  10546. * Whether this event will continue propagating in the tree.
  10547. *
  10548. * Remaining events for the {@link stopsPropagatingAt} object
  10549. * will still be dispatched.
  10550. *
  10551. * @member {boolean}
  10552. */
  10553. this.stopped = false;
  10554. /**
  10555. * At which object this event stops propagating.
  10556. *
  10557. * @private
  10558. * @member {PIXI.DisplayObject}
  10559. */
  10560. this.stopsPropagatingAt = null;
  10561. /**
  10562. * Whether we already reached the element we want to
  10563. * stop propagating at. This is important for delayed events,
  10564. * where we start over deeper in the tree again.
  10565. *
  10566. * @private
  10567. * @member {boolean}
  10568. */
  10569. this.stopPropagationHint = false;
  10570. /**
  10571. * The object which caused this event to be dispatched.
  10572. * For listener callback see {@link PIXI.InteractionEvent.currentTarget}.
  10573. *
  10574. * @member {PIXI.DisplayObject}
  10575. */
  10576. this.target = null;
  10577. /**
  10578. * The object whose event listener’s callback is currently being invoked.
  10579. *
  10580. * @member {PIXI.DisplayObject}
  10581. */
  10582. this.currentTarget = null;
  10583. /**
  10584. * Type of the event
  10585. *
  10586. * @member {string}
  10587. */
  10588. this.type = null;
  10589. /**
  10590. * InteractionData related to this event
  10591. *
  10592. * @member {PIXI.InteractionData}
  10593. */
  10594. this.data = null;
  10595. }
  10596. /**
  10597. * Prevents event from reaching any objects other than the current object.
  10598. *
  10599. */
  10600. InteractionEvent.prototype.stopPropagation = function () {
  10601. this.stopped = true;
  10602. this.stopPropagationHint = true;
  10603. this.stopsPropagatingAt = this.currentTarget;
  10604. };
  10605. /**
  10606. * Resets the event.
  10607. */
  10608. InteractionEvent.prototype.reset = function () {
  10609. this.stopped = false;
  10610. this.stopsPropagatingAt = null;
  10611. this.stopPropagationHint = false;
  10612. this.currentTarget = null;
  10613. this.target = null;
  10614. };
  10615. return InteractionEvent;
  10616. }());
  10617. /**
  10618. * DisplayObjects with the {@link PIXI.interactiveTarget} mixin use this class to track interactions
  10619. *
  10620. * @class
  10621. * @private
  10622. * @memberof PIXI
  10623. */
  10624. var InteractionTrackingData = /** @class */ (function () {
  10625. /**
  10626. * @param {number} pointerId - Unique pointer id of the event
  10627. * @private
  10628. */
  10629. function InteractionTrackingData(pointerId) {
  10630. this._pointerId = pointerId;
  10631. this._flags = InteractionTrackingData.FLAGS.NONE;
  10632. }
  10633. /**
  10634. *
  10635. * @private
  10636. * @param {number} flag - The interaction flag to set
  10637. * @param {boolean} yn - Should the flag be set or unset
  10638. */
  10639. InteractionTrackingData.prototype._doSet = function (flag, yn) {
  10640. if (yn) {
  10641. this._flags = this._flags | flag;
  10642. }
  10643. else {
  10644. this._flags = this._flags & (~flag);
  10645. }
  10646. };
  10647. Object.defineProperty(InteractionTrackingData.prototype, "pointerId", {
  10648. /**
  10649. * Unique pointer id of the event
  10650. *
  10651. * @readonly
  10652. * @private
  10653. * @member {number}
  10654. */
  10655. get: function () {
  10656. return this._pointerId;
  10657. },
  10658. enumerable: false,
  10659. configurable: true
  10660. });
  10661. Object.defineProperty(InteractionTrackingData.prototype, "flags", {
  10662. /**
  10663. * State of the tracking data, expressed as bit flags
  10664. *
  10665. * @private
  10666. * @member {number}
  10667. */
  10668. get: function () {
  10669. return this._flags;
  10670. },
  10671. set: function (flags) {
  10672. this._flags = flags;
  10673. },
  10674. enumerable: false,
  10675. configurable: true
  10676. });
  10677. Object.defineProperty(InteractionTrackingData.prototype, "none", {
  10678. /**
  10679. * Is the tracked event inactive (not over or down)?
  10680. *
  10681. * @private
  10682. * @member {number}
  10683. */
  10684. get: function () {
  10685. return this._flags === InteractionTrackingData.FLAGS.NONE;
  10686. },
  10687. enumerable: false,
  10688. configurable: true
  10689. });
  10690. Object.defineProperty(InteractionTrackingData.prototype, "over", {
  10691. /**
  10692. * Is the tracked event over the DisplayObject?
  10693. *
  10694. * @private
  10695. * @member {boolean}
  10696. */
  10697. get: function () {
  10698. return (this._flags & InteractionTrackingData.FLAGS.OVER) !== 0;
  10699. },
  10700. set: function (yn) {
  10701. this._doSet(InteractionTrackingData.FLAGS.OVER, yn);
  10702. },
  10703. enumerable: false,
  10704. configurable: true
  10705. });
  10706. Object.defineProperty(InteractionTrackingData.prototype, "rightDown", {
  10707. /**
  10708. * Did the right mouse button come down in the DisplayObject?
  10709. *
  10710. * @private
  10711. * @member {boolean}
  10712. */
  10713. get: function () {
  10714. return (this._flags & InteractionTrackingData.FLAGS.RIGHT_DOWN) !== 0;
  10715. },
  10716. set: function (yn) {
  10717. this._doSet(InteractionTrackingData.FLAGS.RIGHT_DOWN, yn);
  10718. },
  10719. enumerable: false,
  10720. configurable: true
  10721. });
  10722. Object.defineProperty(InteractionTrackingData.prototype, "leftDown", {
  10723. /**
  10724. * Did the left mouse button come down in the DisplayObject?
  10725. *
  10726. * @private
  10727. * @member {boolean}
  10728. */
  10729. get: function () {
  10730. return (this._flags & InteractionTrackingData.FLAGS.LEFT_DOWN) !== 0;
  10731. },
  10732. set: function (yn) {
  10733. this._doSet(InteractionTrackingData.FLAGS.LEFT_DOWN, yn);
  10734. },
  10735. enumerable: false,
  10736. configurable: true
  10737. });
  10738. InteractionTrackingData.FLAGS = Object.freeze({
  10739. NONE: 0,
  10740. OVER: 1 << 0,
  10741. LEFT_DOWN: 1 << 1,
  10742. RIGHT_DOWN: 1 << 2,
  10743. });
  10744. return InteractionTrackingData;
  10745. }());
  10746. /**
  10747. * Strategy how to search through stage tree for interactive objects
  10748. *
  10749. * @private
  10750. * @class
  10751. * @memberof PIXI
  10752. */
  10753. var TreeSearch = /** @class */ (function () {
  10754. function TreeSearch() {
  10755. this._tempPoint = new Point();
  10756. }
  10757. /**
  10758. * Recursive implementation for findHit
  10759. *
  10760. * @private
  10761. * @param {PIXI.InteractionEvent} interactionEvent - event containing the point that
  10762. * is tested for collision
  10763. * @param {PIXI.Container|PIXI.Sprite|PIXI.TilingSprite} displayObject - the displayObject
  10764. * that will be hit test (recursively crawls its children)
  10765. * @param {Function} [func] - the function that will be called on each interactive object. The
  10766. * interactionEvent, displayObject and hit will be passed to the function
  10767. * @param {boolean} [hitTest] - this indicates if the objects inside should be hit test against the point
  10768. * @param {boolean} [interactive] - Whether the displayObject is interactive
  10769. * @return {boolean} returns true if the displayObject hit the point
  10770. */
  10771. TreeSearch.prototype.recursiveFindHit = function (interactionEvent, displayObject, func, hitTest, interactive) {
  10772. if (!displayObject || !displayObject.visible) {
  10773. return false;
  10774. }
  10775. var point = interactionEvent.data.global;
  10776. // Took a little while to rework this function correctly! But now it is done and nice and optimized! ^_^
  10777. //
  10778. // This function will now loop through all objects and then only hit test the objects it HAS
  10779. // to, not all of them. MUCH faster..
  10780. // An object will be hit test if the following is true:
  10781. //
  10782. // 1: It is interactive.
  10783. // 2: It belongs to a parent that is interactive AND one of the parents children have not already been hit.
  10784. //
  10785. // As another little optimization once an interactive object has been hit we can carry on
  10786. // through the scenegraph, but we know that there will be no more hits! So we can avoid extra hit tests
  10787. // A final optimization is that an object is not hit test directly if a child has already been hit.
  10788. interactive = displayObject.interactive || interactive;
  10789. var hit = false;
  10790. var interactiveParent = interactive;
  10791. // Flag here can set to false if the event is outside the parents hitArea or mask
  10792. var hitTestChildren = true;
  10793. // If there is a hitArea, no need to test against anything else if the pointer is not within the hitArea
  10794. // There is also no longer a need to hitTest children.
  10795. if (displayObject.hitArea) {
  10796. if (hitTest) {
  10797. displayObject.worldTransform.applyInverse(point, this._tempPoint);
  10798. if (!displayObject.hitArea.contains(this._tempPoint.x, this._tempPoint.y)) {
  10799. hitTest = false;
  10800. hitTestChildren = false;
  10801. }
  10802. else {
  10803. hit = true;
  10804. }
  10805. }
  10806. interactiveParent = false;
  10807. }
  10808. // If there is a mask, no need to hitTest against anything else if the pointer is not within the mask.
  10809. // We still want to hitTestChildren, however, to ensure a mouseout can still be generated.
  10810. // https://github.com/pixijs/pixi.js/issues/5135
  10811. else if (displayObject._mask) {
  10812. if (hitTest) {
  10813. if (!(displayObject._mask.containsPoint && displayObject._mask.containsPoint(point))) {
  10814. hitTest = false;
  10815. }
  10816. }
  10817. }
  10818. // ** FREE TIP **! If an object is not interactive or has no buttons in it
  10819. // (such as a game scene!) set interactiveChildren to false for that displayObject.
  10820. // This will allow PixiJS to completely ignore and bypass checking the displayObjects children.
  10821. if (hitTestChildren && displayObject.interactiveChildren && displayObject.children) {
  10822. var children = displayObject.children;
  10823. for (var i = children.length - 1; i >= 0; i--) {
  10824. var child = children[i];
  10825. // time to get recursive.. if this function will return if something is hit..
  10826. var childHit = this.recursiveFindHit(interactionEvent, child, func, hitTest, interactiveParent);
  10827. if (childHit) {
  10828. // its a good idea to check if a child has lost its parent.
  10829. // this means it has been removed whilst looping so its best
  10830. if (!child.parent) {
  10831. continue;
  10832. }
  10833. // we no longer need to hit test any more objects in this container as we we
  10834. // now know the parent has been hit
  10835. interactiveParent = false;
  10836. // If the child is interactive , that means that the object hit was actually
  10837. // interactive and not just the child of an interactive object.
  10838. // This means we no longer need to hit test anything else. We still need to run
  10839. // through all objects, but we don't need to perform any hit tests.
  10840. if (childHit) {
  10841. if (interactionEvent.target) {
  10842. hitTest = false;
  10843. }
  10844. hit = true;
  10845. }
  10846. }
  10847. }
  10848. }
  10849. // no point running this if the item is not interactive or does not have an interactive parent.
  10850. if (interactive) {
  10851. // if we are hit testing (as in we have no hit any objects yet)
  10852. // We also don't need to worry about hit testing if once of the displayObjects children
  10853. // has already been hit - but only if it was interactive, otherwise we need to keep
  10854. // looking for an interactive child, just in case we hit one
  10855. if (hitTest && !interactionEvent.target) {
  10856. // already tested against hitArea if it is defined
  10857. if (!displayObject.hitArea && displayObject.containsPoint) {
  10858. if (displayObject.containsPoint(point)) {
  10859. hit = true;
  10860. }
  10861. }
  10862. }
  10863. if (displayObject.interactive) {
  10864. if (hit && !interactionEvent.target) {
  10865. interactionEvent.target = displayObject;
  10866. }
  10867. if (func) {
  10868. func(interactionEvent, displayObject, !!hit);
  10869. }
  10870. }
  10871. }
  10872. return hit;
  10873. };
  10874. /**
  10875. * This function is provides a neat way of crawling through the scene graph and running a
  10876. * specified function on all interactive objects it finds. It will also take care of hit
  10877. * testing the interactive objects and passes the hit across in the function.
  10878. *
  10879. * @private
  10880. * @param {PIXI.InteractionEvent} interactionEvent - event containing the point that
  10881. * is tested for collision
  10882. * @param {PIXI.Container|PIXI.Sprite|PIXI.TilingSprite} displayObject - the displayObject
  10883. * that will be hit test (recursively crawls its children)
  10884. * @param {Function} [func] - the function that will be called on each interactive object. The
  10885. * interactionEvent, displayObject and hit will be passed to the function
  10886. * @param {boolean} [hitTest] - this indicates if the objects inside should be hit test against the point
  10887. * @return {boolean} returns true if the displayObject hit the point
  10888. */
  10889. TreeSearch.prototype.findHit = function (interactionEvent, displayObject, func, hitTest) {
  10890. this.recursiveFindHit(interactionEvent, displayObject, func, hitTest, false);
  10891. };
  10892. return TreeSearch;
  10893. }());
  10894. /**
  10895. * Interface for classes that represent a hit area.
  10896. *
  10897. * It is implemented by the following classes:
  10898. * - {@link PIXI.Circle}
  10899. * - {@link PIXI.Ellipse}
  10900. * - {@link PIXI.Polygon}
  10901. * - {@link PIXI.RoundedRectangle}
  10902. *
  10903. * @interface IHitArea
  10904. * @memberof PIXI
  10905. */
  10906. /**
  10907. * Checks whether the x and y coordinates given are contained within this area
  10908. *
  10909. * @method
  10910. * @name contains
  10911. * @memberof PIXI.IHitArea#
  10912. * @param {number} x - The X coordinate of the point to test
  10913. * @param {number} y - The Y coordinate of the point to test
  10914. * @return {boolean} Whether the x/y coordinates are within this area
  10915. */
  10916. /**
  10917. * Default property values of interactive objects
  10918. * Used by {@link PIXI.InteractionManager} to automatically give all DisplayObjects these properties
  10919. *
  10920. * @private
  10921. * @name interactiveTarget
  10922. * @type {Object}
  10923. * @memberof PIXI
  10924. * @example
  10925. * function MyObject() {}
  10926. *
  10927. * Object.assign(
  10928. * DisplayObject.prototype,
  10929. * PIXI.interactiveTarget
  10930. * );
  10931. */
  10932. var interactiveTarget = {
  10933. interactive: false,
  10934. interactiveChildren: true,
  10935. hitArea: null,
  10936. /**
  10937. * If enabled, the mouse cursor use the pointer behavior when hovered over the displayObject if it is interactive
  10938. * Setting this changes the 'cursor' property to `'pointer'`.
  10939. *
  10940. * @example
  10941. * const sprite = new PIXI.Sprite(texture);
  10942. * sprite.interactive = true;
  10943. * sprite.buttonMode = true;
  10944. * @member {boolean}
  10945. * @memberof PIXI.DisplayObject#
  10946. */
  10947. get buttonMode() {
  10948. return this.cursor === 'pointer';
  10949. },
  10950. set buttonMode(value) {
  10951. if (value) {
  10952. this.cursor = 'pointer';
  10953. }
  10954. else if (this.cursor === 'pointer') {
  10955. this.cursor = null;
  10956. }
  10957. },
  10958. /**
  10959. * This defines what cursor mode is used when the mouse cursor
  10960. * is hovered over the displayObject.
  10961. *
  10962. * @example
  10963. * const sprite = new PIXI.Sprite(texture);
  10964. * sprite.interactive = true;
  10965. * sprite.cursor = 'wait';
  10966. * @see https://developer.mozilla.org/en/docs/Web/CSS/cursor
  10967. *
  10968. * @member {string}
  10969. * @memberof PIXI.DisplayObject#
  10970. */
  10971. cursor: null,
  10972. /**
  10973. * Internal set of all active pointers, by identifier
  10974. *
  10975. * @member {Map<number, InteractionTrackingData>}
  10976. * @memberof PIXI.DisplayObject#
  10977. * @private
  10978. */
  10979. get trackedPointers() {
  10980. if (this._trackedPointers === undefined)
  10981. { this._trackedPointers = {}; }
  10982. return this._trackedPointers;
  10983. },
  10984. /**
  10985. * Map of all tracked pointers, by identifier. Use trackedPointers to access.
  10986. *
  10987. * @private
  10988. * @type {Map<number, InteractionTrackingData>}
  10989. */
  10990. _trackedPointers: undefined,
  10991. };
  10992. // Mix interactiveTarget into DisplayObject.prototype
  10993. DisplayObject.mixin(interactiveTarget);
  10994. var MOUSE_POINTER_ID = 1;
  10995. // helpers for hitTest() - only used inside hitTest()
  10996. var hitTestEvent = {
  10997. target: null,
  10998. data: {
  10999. global: null,
  11000. },
  11001. };
  11002. /**
  11003. * The interaction manager deals with mouse, touch and pointer events.
  11004. *
  11005. * Any DisplayObject can be interactive if its `interactive` property is set to true.
  11006. *
  11007. * This manager also supports multitouch.
  11008. *
  11009. * An instance of this class is automatically created by default, and can be found at `renderer.plugins.interaction`
  11010. *
  11011. * @class
  11012. * @extends PIXI.utils.EventEmitter
  11013. * @memberof PIXI
  11014. */
  11015. var InteractionManager = /** @class */ (function (_super) {
  11016. __extends$1(InteractionManager, _super);
  11017. /**
  11018. * @param {PIXI.CanvasRenderer|PIXI.Renderer} renderer - A reference to the current renderer
  11019. * @param {object} [options] - The options for the manager.
  11020. * @param {boolean} [options.autoPreventDefault=true] - Should the manager automatically prevent default browser actions.
  11021. * @param {number} [options.interactionFrequency=10] - Maximum frequency (ms) at pointer over/out states will be checked.
  11022. * @param {number} [options.useSystemTicker=true] - Whether to add {@link tickerUpdate} to {@link PIXI.Ticker.system}.
  11023. */
  11024. function InteractionManager(renderer, options) {
  11025. var _this = _super.call(this) || this;
  11026. options = options || {};
  11027. /**
  11028. * The renderer this interaction manager works for.
  11029. *
  11030. * @member {PIXI.AbstractRenderer}
  11031. */
  11032. _this.renderer = renderer;
  11033. /**
  11034. * Should default browser actions automatically be prevented.
  11035. * Does not apply to pointer events for backwards compatibility
  11036. * preventDefault on pointer events stops mouse events from firing
  11037. * Thus, for every pointer event, there will always be either a mouse of touch event alongside it.
  11038. *
  11039. * @member {boolean}
  11040. * @default true
  11041. */
  11042. _this.autoPreventDefault = options.autoPreventDefault !== undefined ? options.autoPreventDefault : true;
  11043. /**
  11044. * Maximum frequency in milliseconds at which pointer over/out states will be checked by {@link tickerUpdate}.
  11045. *
  11046. * @member {number}
  11047. * @default 10
  11048. */
  11049. _this.interactionFrequency = options.interactionFrequency || 10;
  11050. /**
  11051. * The mouse data
  11052. *
  11053. * @member {PIXI.InteractionData}
  11054. */
  11055. _this.mouse = new InteractionData();
  11056. _this.mouse.identifier = MOUSE_POINTER_ID;
  11057. // setting the mouse to start off far off screen will mean that mouse over does
  11058. // not get called before we even move the mouse.
  11059. _this.mouse.global.set(-999999);
  11060. /**
  11061. * Actively tracked InteractionData
  11062. *
  11063. * @private
  11064. * @member {Object.<number,PIXI.InteractionData>}
  11065. */
  11066. _this.activeInteractionData = {};
  11067. _this.activeInteractionData[MOUSE_POINTER_ID] = _this.mouse;
  11068. /**
  11069. * Pool of unused InteractionData
  11070. *
  11071. * @private
  11072. * @member {PIXI.InteractionData[]}
  11073. */
  11074. _this.interactionDataPool = [];
  11075. /**
  11076. * An event data object to handle all the event tracking/dispatching
  11077. *
  11078. * @member {object}
  11079. */
  11080. _this.eventData = new InteractionEvent();
  11081. /**
  11082. * The DOM element to bind to.
  11083. *
  11084. * @protected
  11085. * @member {HTMLElement}
  11086. */
  11087. _this.interactionDOMElement = null;
  11088. /**
  11089. * This property determines if mousemove and touchmove events are fired only when the cursor
  11090. * is over the object.
  11091. * Setting to true will make things work more in line with how the DOM version works.
  11092. * Setting to false can make things easier for things like dragging
  11093. * It is currently set to false as this is how PixiJS used to work. This will be set to true in
  11094. * future versions of pixi.
  11095. *
  11096. * @member {boolean}
  11097. * @default false
  11098. */
  11099. _this.moveWhenInside = false;
  11100. /**
  11101. * Have events been attached to the dom element?
  11102. *
  11103. * @protected
  11104. * @member {boolean}
  11105. */
  11106. _this.eventsAdded = false;
  11107. /**
  11108. * Has the system ticker been added?
  11109. *
  11110. * @protected
  11111. * @member {boolean}
  11112. */
  11113. _this.tickerAdded = false;
  11114. /**
  11115. * Is the mouse hovering over the renderer? If working in worker mouse considered to be over renderer by default.
  11116. *
  11117. * @protected
  11118. * @member {boolean}
  11119. */
  11120. _this.mouseOverRenderer = !('PointerEvent' in self);
  11121. /**
  11122. * Does the device support touch events
  11123. * https://www.w3.org/TR/touch-events/
  11124. *
  11125. * @readonly
  11126. * @member {boolean}
  11127. */
  11128. _this.supportsTouchEvents = 'ontouchstart' in self;
  11129. /**
  11130. * Does the device support pointer events
  11131. * https://www.w3.org/Submission/pointer-events/
  11132. *
  11133. * @readonly
  11134. * @member {boolean}
  11135. */
  11136. _this.supportsPointerEvents = !!self.PointerEvent;
  11137. // this will make it so that you don't have to call bind all the time
  11138. /**
  11139. * @private
  11140. * @member {Function}
  11141. */
  11142. _this.onPointerUp = _this.onPointerUp.bind(_this);
  11143. _this.processPointerUp = _this.processPointerUp.bind(_this);
  11144. /**
  11145. * @private
  11146. * @member {Function}
  11147. */
  11148. _this.onPointerCancel = _this.onPointerCancel.bind(_this);
  11149. _this.processPointerCancel = _this.processPointerCancel.bind(_this);
  11150. /**
  11151. * @private
  11152. * @member {Function}
  11153. */
  11154. _this.onPointerDown = _this.onPointerDown.bind(_this);
  11155. _this.processPointerDown = _this.processPointerDown.bind(_this);
  11156. /**
  11157. * @private
  11158. * @member {Function}
  11159. */
  11160. _this.onPointerMove = _this.onPointerMove.bind(_this);
  11161. _this.processPointerMove = _this.processPointerMove.bind(_this);
  11162. /**
  11163. * @private
  11164. * @member {Function}
  11165. */
  11166. _this.onPointerOut = _this.onPointerOut.bind(_this);
  11167. _this.processPointerOverOut = _this.processPointerOverOut.bind(_this);
  11168. /**
  11169. * @private
  11170. * @member {Function}
  11171. */
  11172. _this.onPointerOver = _this.onPointerOver.bind(_this);
  11173. /**
  11174. * Dictionary of how different cursor modes are handled. Strings are handled as CSS cursor
  11175. * values, objects are handled as dictionaries of CSS values for interactionDOMElement,
  11176. * and functions are called instead of changing the CSS.
  11177. * Default CSS cursor values are provided for 'default' and 'pointer' modes.
  11178. * @member {Object.<string, Object>}
  11179. */
  11180. _this.cursorStyles = {
  11181. default: 'inherit',
  11182. pointer: 'pointer',
  11183. };
  11184. /**
  11185. * The mode of the cursor that is being used.
  11186. * The value of this is a key from the cursorStyles dictionary.
  11187. *
  11188. * @member {string}
  11189. */
  11190. _this.currentCursorMode = null;
  11191. /**
  11192. * Internal cached let.
  11193. *
  11194. * @private
  11195. * @member {string}
  11196. */
  11197. _this.cursor = null;
  11198. /**
  11199. * The current resolution / device pixel ratio.
  11200. *
  11201. * @member {number}
  11202. * @default 1
  11203. */
  11204. _this.resolution = 1;
  11205. /**
  11206. * Delayed pointer events. Used to guarantee correct ordering of over/out events.
  11207. *
  11208. * @private
  11209. * @member {Array}
  11210. */
  11211. _this.delayedEvents = [];
  11212. /**
  11213. * TreeSearch component that is used to hitTest stage tree
  11214. *
  11215. * @private
  11216. * @member {PIXI.TreeSearch}
  11217. */
  11218. _this.search = new TreeSearch();
  11219. /**
  11220. * Used as a last rendered object in case renderer doesnt have _lastObjectRendered
  11221. * @member {DisplayObject}
  11222. * @private
  11223. */
  11224. _this._tempDisplayObject = new TemporaryDisplayObject();
  11225. /**
  11226. * An options object specifies characteristics about the event listener.
  11227. * @private
  11228. * @readonly
  11229. * @member {Object.<string, boolean>}
  11230. */
  11231. _this._eventListenerOptions = { capture: true, passive: false };
  11232. /**
  11233. * Fired when a pointer device button (usually a mouse left-button) is pressed on the display
  11234. * object.
  11235. *
  11236. * @event PIXI.InteractionManager#mousedown
  11237. * @param {PIXI.InteractionEvent} event - Interaction event
  11238. */
  11239. /**
  11240. * Fired when a pointer device secondary button (usually a mouse right-button) is pressed
  11241. * on the display object.
  11242. *
  11243. * @event PIXI.InteractionManager#rightdown
  11244. * @param {PIXI.InteractionEvent} event - Interaction event
  11245. */
  11246. /**
  11247. * Fired when a pointer device button (usually a mouse left-button) is released over the display
  11248. * object.
  11249. *
  11250. * @event PIXI.InteractionManager#mouseup
  11251. * @param {PIXI.InteractionEvent} event - Interaction event
  11252. */
  11253. /**
  11254. * Fired when a pointer device secondary button (usually a mouse right-button) is released
  11255. * over the display object.
  11256. *
  11257. * @event PIXI.InteractionManager#rightup
  11258. * @param {PIXI.InteractionEvent} event - Interaction event
  11259. */
  11260. /**
  11261. * Fired when a pointer device button (usually a mouse left-button) is pressed and released on
  11262. * the display object.
  11263. *
  11264. * @event PIXI.InteractionManager#click
  11265. * @param {PIXI.InteractionEvent} event - Interaction event
  11266. */
  11267. /**
  11268. * Fired when a pointer device secondary button (usually a mouse right-button) is pressed
  11269. * and released on the display object.
  11270. *
  11271. * @event PIXI.InteractionManager#rightclick
  11272. * @param {PIXI.InteractionEvent} event - Interaction event
  11273. */
  11274. /**
  11275. * Fired when a pointer device button (usually a mouse left-button) is released outside the
  11276. * display object that initially registered a
  11277. * [mousedown]{@link PIXI.InteractionManager#event:mousedown}.
  11278. *
  11279. * @event PIXI.InteractionManager#mouseupoutside
  11280. * @param {PIXI.InteractionEvent} event - Interaction event
  11281. */
  11282. /**
  11283. * Fired when a pointer device secondary button (usually a mouse right-button) is released
  11284. * outside the display object that initially registered a
  11285. * [rightdown]{@link PIXI.InteractionManager#event:rightdown}.
  11286. *
  11287. * @event PIXI.InteractionManager#rightupoutside
  11288. * @param {PIXI.InteractionEvent} event - Interaction event
  11289. */
  11290. /**
  11291. * Fired when a pointer device (usually a mouse) is moved while over the display object
  11292. *
  11293. * @event PIXI.InteractionManager#mousemove
  11294. * @param {PIXI.InteractionEvent} event - Interaction event
  11295. */
  11296. /**
  11297. * Fired when a pointer device (usually a mouse) is moved onto the display object
  11298. *
  11299. * @event PIXI.InteractionManager#mouseover
  11300. * @param {PIXI.InteractionEvent} event - Interaction event
  11301. */
  11302. /**
  11303. * Fired when a pointer device (usually a mouse) is moved off the display object
  11304. *
  11305. * @event PIXI.InteractionManager#mouseout
  11306. * @param {PIXI.InteractionEvent} event - Interaction event
  11307. */
  11308. /**
  11309. * Fired when a pointer device button is pressed on the display object.
  11310. *
  11311. * @event PIXI.InteractionManager#pointerdown
  11312. * @param {PIXI.InteractionEvent} event - Interaction event
  11313. */
  11314. /**
  11315. * Fired when a pointer device button is released over the display object.
  11316. * Not always fired when some buttons are held down while others are released. In those cases,
  11317. * use [mousedown]{@link PIXI.InteractionManager#event:mousedown} and
  11318. * [mouseup]{@link PIXI.InteractionManager#event:mouseup} instead.
  11319. *
  11320. * @event PIXI.InteractionManager#pointerup
  11321. * @param {PIXI.InteractionEvent} event - Interaction event
  11322. */
  11323. /**
  11324. * Fired when the operating system cancels a pointer event
  11325. *
  11326. * @event PIXI.InteractionManager#pointercancel
  11327. * @param {PIXI.InteractionEvent} event - Interaction event
  11328. */
  11329. /**
  11330. * Fired when a pointer device button is pressed and released on the display object.
  11331. *
  11332. * @event PIXI.InteractionManager#pointertap
  11333. * @param {PIXI.InteractionEvent} event - Interaction event
  11334. */
  11335. /**
  11336. * Fired when a pointer device button is released outside the display object that initially
  11337. * registered a [pointerdown]{@link PIXI.InteractionManager#event:pointerdown}.
  11338. *
  11339. * @event PIXI.InteractionManager#pointerupoutside
  11340. * @param {PIXI.InteractionEvent} event - Interaction event
  11341. */
  11342. /**
  11343. * Fired when a pointer device is moved while over the display object
  11344. *
  11345. * @event PIXI.InteractionManager#pointermove
  11346. * @param {PIXI.InteractionEvent} event - Interaction event
  11347. */
  11348. /**
  11349. * Fired when a pointer device is moved onto the display object
  11350. *
  11351. * @event PIXI.InteractionManager#pointerover
  11352. * @param {PIXI.InteractionEvent} event - Interaction event
  11353. */
  11354. /**
  11355. * Fired when a pointer device is moved off the display object
  11356. *
  11357. * @event PIXI.InteractionManager#pointerout
  11358. * @param {PIXI.InteractionEvent} event - Interaction event
  11359. */
  11360. /**
  11361. * Fired when a touch point is placed on the display object.
  11362. *
  11363. * @event PIXI.InteractionManager#touchstart
  11364. * @param {PIXI.InteractionEvent} event - Interaction event
  11365. */
  11366. /**
  11367. * Fired when a touch point is removed from the display object.
  11368. *
  11369. * @event PIXI.InteractionManager#touchend
  11370. * @param {PIXI.InteractionEvent} event - Interaction event
  11371. */
  11372. /**
  11373. * Fired when the operating system cancels a touch
  11374. *
  11375. * @event PIXI.InteractionManager#touchcancel
  11376. * @param {PIXI.InteractionEvent} event - Interaction event
  11377. */
  11378. /**
  11379. * Fired when a touch point is placed and removed from the display object.
  11380. *
  11381. * @event PIXI.InteractionManager#tap
  11382. * @param {PIXI.InteractionEvent} event - Interaction event
  11383. */
  11384. /**
  11385. * Fired when a touch point is removed outside of the display object that initially
  11386. * registered a [touchstart]{@link PIXI.InteractionManager#event:touchstart}.
  11387. *
  11388. * @event PIXI.InteractionManager#touchendoutside
  11389. * @param {PIXI.InteractionEvent} event - Interaction event
  11390. */
  11391. /**
  11392. * Fired when a touch point is moved along the display object.
  11393. *
  11394. * @event PIXI.InteractionManager#touchmove
  11395. * @param {PIXI.InteractionEvent} event - Interaction event
  11396. */
  11397. /**
  11398. * Fired when a pointer device button (usually a mouse left-button) is pressed on the display.
  11399. * object. DisplayObject's `interactive` property must be set to `true` to fire event.
  11400. *
  11401. * This comes from the @pixi/interaction package.
  11402. *
  11403. * @event PIXI.DisplayObject#mousedown
  11404. * @param {PIXI.InteractionEvent} event - Interaction event
  11405. */
  11406. /**
  11407. * Fired when a pointer device secondary button (usually a mouse right-button) is pressed
  11408. * on the display object. DisplayObject's `interactive` property must be set to `true` to fire event.
  11409. *
  11410. * This comes from the @pixi/interaction package.
  11411. *
  11412. * @event PIXI.DisplayObject#rightdown
  11413. * @param {PIXI.InteractionEvent} event - Interaction event
  11414. */
  11415. /**
  11416. * Fired when a pointer device button (usually a mouse left-button) is released over the display
  11417. * object. DisplayObject's `interactive` property must be set to `true` to fire event.
  11418. *
  11419. * This comes from the @pixi/interaction package.
  11420. *
  11421. * @event PIXI.DisplayObject#mouseup
  11422. * @param {PIXI.InteractionEvent} event - Interaction event
  11423. */
  11424. /**
  11425. * Fired when a pointer device secondary button (usually a mouse right-button) is released
  11426. * over the display object. DisplayObject's `interactive` property must be set to `true` to fire event.
  11427. *
  11428. * This comes from the @pixi/interaction package.
  11429. *
  11430. * @event PIXI.DisplayObject#rightup
  11431. * @param {PIXI.InteractionEvent} event - Interaction event
  11432. */
  11433. /**
  11434. * Fired when a pointer device button (usually a mouse left-button) is pressed and released on
  11435. * the display object. DisplayObject's `interactive` property must be set to `true` to fire event.
  11436. *
  11437. * This comes from the @pixi/interaction package.
  11438. *
  11439. * @event PIXI.DisplayObject#click
  11440. * @param {PIXI.InteractionEvent} event - Interaction event
  11441. */
  11442. /**
  11443. * Fired when a pointer device secondary button (usually a mouse right-button) is pressed
  11444. * and released on the display object. DisplayObject's `interactive` property must be set to `true` to fire event.
  11445. *
  11446. * This comes from the @pixi/interaction package.
  11447. *
  11448. * @event PIXI.DisplayObject#rightclick
  11449. * @param {PIXI.InteractionEvent} event - Interaction event
  11450. */
  11451. /**
  11452. * Fired when a pointer device button (usually a mouse left-button) is released outside the
  11453. * display object that initially registered a
  11454. * [mousedown]{@link PIXI.DisplayObject#event:mousedown}.
  11455. * DisplayObject's `interactive` property must be set to `true` to fire event.
  11456. *
  11457. * This comes from the @pixi/interaction package.
  11458. *
  11459. * @event PIXI.DisplayObject#mouseupoutside
  11460. * @param {PIXI.InteractionEvent} event - Interaction event
  11461. */
  11462. /**
  11463. * Fired when a pointer device secondary button (usually a mouse right-button) is released
  11464. * outside the display object that initially registered a
  11465. * [rightdown]{@link PIXI.DisplayObject#event:rightdown}.
  11466. * DisplayObject's `interactive` property must be set to `true` to fire event.
  11467. *
  11468. * This comes from the @pixi/interaction package.
  11469. *
  11470. * @event PIXI.DisplayObject#rightupoutside
  11471. * @param {PIXI.InteractionEvent} event - Interaction event
  11472. */
  11473. /**
  11474. * Fired when a pointer device (usually a mouse) is moved while over the display object.
  11475. * DisplayObject's `interactive` property must be set to `true` to fire event.
  11476. *
  11477. * This comes from the @pixi/interaction package.
  11478. *
  11479. * @event PIXI.DisplayObject#mousemove
  11480. * @param {PIXI.InteractionEvent} event - Interaction event
  11481. */
  11482. /**
  11483. * Fired when a pointer device (usually a mouse) is moved onto the display object.
  11484. * DisplayObject's `interactive` property must be set to `true` to fire event.
  11485. *
  11486. * This comes from the @pixi/interaction package.
  11487. *
  11488. * @event PIXI.DisplayObject#mouseover
  11489. * @param {PIXI.InteractionEvent} event - Interaction event
  11490. */
  11491. /**
  11492. * Fired when a pointer device (usually a mouse) is moved off the display object.
  11493. * DisplayObject's `interactive` property must be set to `true` to fire event.
  11494. *
  11495. * This comes from the @pixi/interaction package.
  11496. *
  11497. * @event PIXI.DisplayObject#mouseout
  11498. * @param {PIXI.InteractionEvent} event - Interaction event
  11499. */
  11500. /**
  11501. * Fired when a pointer device button is pressed on the display object.
  11502. * DisplayObject's `interactive` property must be set to `true` to fire event.
  11503. *
  11504. * This comes from the @pixi/interaction package.
  11505. *
  11506. * @event PIXI.DisplayObject#pointerdown
  11507. * @param {PIXI.InteractionEvent} event - Interaction event
  11508. */
  11509. /**
  11510. * Fired when a pointer device button is released over the display object.
  11511. * DisplayObject's `interactive` property must be set to `true` to fire event.
  11512. *
  11513. * This comes from the @pixi/interaction package.
  11514. *
  11515. * @event PIXI.DisplayObject#pointerup
  11516. * @param {PIXI.InteractionEvent} event - Interaction event
  11517. */
  11518. /**
  11519. * Fired when the operating system cancels a pointer event.
  11520. * DisplayObject's `interactive` property must be set to `true` to fire event.
  11521. *
  11522. * This comes from the @pixi/interaction package.
  11523. *
  11524. * @event PIXI.DisplayObject#pointercancel
  11525. * @param {PIXI.InteractionEvent} event - Interaction event
  11526. */
  11527. /**
  11528. * Fired when a pointer device button is pressed and released on the display object.
  11529. * DisplayObject's `interactive` property must be set to `true` to fire event.
  11530. *
  11531. * This comes from the @pixi/interaction package.
  11532. *
  11533. * @event PIXI.DisplayObject#pointertap
  11534. * @param {PIXI.InteractionEvent} event - Interaction event
  11535. */
  11536. /**
  11537. * Fired when a pointer device button is released outside the display object that initially
  11538. * registered a [pointerdown]{@link PIXI.DisplayObject#event:pointerdown}.
  11539. * DisplayObject's `interactive` property must be set to `true` to fire event.
  11540. *
  11541. * This comes from the @pixi/interaction package.
  11542. *
  11543. * @event PIXI.DisplayObject#pointerupoutside
  11544. * @param {PIXI.InteractionEvent} event - Interaction event
  11545. */
  11546. /**
  11547. * Fired when a pointer device is moved while over the display object.
  11548. * DisplayObject's `interactive` property must be set to `true` to fire event.
  11549. *
  11550. * This comes from the @pixi/interaction package.
  11551. *
  11552. * @event PIXI.DisplayObject#pointermove
  11553. * @param {PIXI.InteractionEvent} event - Interaction event
  11554. */
  11555. /**
  11556. * Fired when a pointer device is moved onto the display object.
  11557. * DisplayObject's `interactive` property must be set to `true` to fire event.
  11558. *
  11559. * This comes from the @pixi/interaction package.
  11560. *
  11561. * @event PIXI.DisplayObject#pointerover
  11562. * @param {PIXI.InteractionEvent} event - Interaction event
  11563. */
  11564. /**
  11565. * Fired when a pointer device is moved off the display object.
  11566. * DisplayObject's `interactive` property must be set to `true` to fire event.
  11567. *
  11568. * This comes from the @pixi/interaction package.
  11569. *
  11570. * @event PIXI.DisplayObject#pointerout
  11571. * @param {PIXI.InteractionEvent} event - Interaction event
  11572. */
  11573. /**
  11574. * Fired when a touch point is placed on the display object.
  11575. * DisplayObject's `interactive` property must be set to `true` to fire event.
  11576. *
  11577. * This comes from the @pixi/interaction package.
  11578. *
  11579. * @event PIXI.DisplayObject#touchstart
  11580. * @param {PIXI.InteractionEvent} event - Interaction event
  11581. */
  11582. /**
  11583. * Fired when a touch point is removed from the display object.
  11584. * DisplayObject's `interactive` property must be set to `true` to fire event.
  11585. *
  11586. * This comes from the @pixi/interaction package.
  11587. *
  11588. * @event PIXI.DisplayObject#touchend
  11589. * @param {PIXI.InteractionEvent} event - Interaction event
  11590. */
  11591. /**
  11592. * Fired when the operating system cancels a touch.
  11593. * DisplayObject's `interactive` property must be set to `true` to fire event.
  11594. *
  11595. * This comes from the @pixi/interaction package.
  11596. *
  11597. * @event PIXI.DisplayObject#touchcancel
  11598. * @param {PIXI.InteractionEvent} event - Interaction event
  11599. */
  11600. /**
  11601. * Fired when a touch point is placed and removed from the display object.
  11602. * DisplayObject's `interactive` property must be set to `true` to fire event.
  11603. *
  11604. * This comes from the @pixi/interaction package.
  11605. *
  11606. * @event PIXI.DisplayObject#tap
  11607. * @param {PIXI.InteractionEvent} event - Interaction event
  11608. */
  11609. /**
  11610. * Fired when a touch point is removed outside of the display object that initially
  11611. * registered a [touchstart]{@link PIXI.DisplayObject#event:touchstart}.
  11612. * DisplayObject's `interactive` property must be set to `true` to fire event.
  11613. *
  11614. * This comes from the @pixi/interaction package.
  11615. *
  11616. * @event PIXI.DisplayObject#touchendoutside
  11617. * @param {PIXI.InteractionEvent} event - Interaction event
  11618. */
  11619. /**
  11620. * Fired when a touch point is moved along the display object.
  11621. * DisplayObject's `interactive` property must be set to `true` to fire event.
  11622. *
  11623. * This comes from the @pixi/interaction package.
  11624. *
  11625. * @event PIXI.DisplayObject#touchmove
  11626. * @param {PIXI.InteractionEvent} event - Interaction event
  11627. */
  11628. _this._useSystemTicker = options.useSystemTicker !== undefined ? options.useSystemTicker : true;
  11629. _this.setTargetElement(_this.renderer.view, _this.renderer.resolution);
  11630. return _this;
  11631. }
  11632. Object.defineProperty(InteractionManager.prototype, "useSystemTicker", {
  11633. /**
  11634. * Should the InteractionManager automatically add {@link tickerUpdate} to {@link PIXI.Ticker.system}.
  11635. *
  11636. * @member {boolean}
  11637. * @default true
  11638. */
  11639. get: function () {
  11640. return this._useSystemTicker;
  11641. },
  11642. set: function (useSystemTicker) {
  11643. this._useSystemTicker = useSystemTicker;
  11644. if (useSystemTicker) {
  11645. this.addTickerListener();
  11646. }
  11647. else {
  11648. this.removeTickerListener();
  11649. }
  11650. },
  11651. enumerable: false,
  11652. configurable: true
  11653. });
  11654. Object.defineProperty(InteractionManager.prototype, "lastObjectRendered", {
  11655. /**
  11656. * Last rendered object or temp object
  11657. * @readonly
  11658. * @protected
  11659. * @member {PIXI.DisplayObject}
  11660. */
  11661. get: function () {
  11662. return this.renderer._lastObjectRendered || this._tempDisplayObject;
  11663. },
  11664. enumerable: false,
  11665. configurable: true
  11666. });
  11667. /**
  11668. * Hit tests a point against the display tree, returning the first interactive object that is hit.
  11669. *
  11670. * @param {PIXI.Point} globalPoint - A point to hit test with, in global space.
  11671. * @param {PIXI.Container} [root] - The root display object to start from. If omitted, defaults
  11672. * to the last rendered root of the associated renderer.
  11673. * @return {PIXI.DisplayObject} The hit display object, if any.
  11674. */
  11675. InteractionManager.prototype.hitTest = function (globalPoint, root) {
  11676. // clear the target for our hit test
  11677. hitTestEvent.target = null;
  11678. // assign the global point
  11679. hitTestEvent.data.global = globalPoint;
  11680. // ensure safety of the root
  11681. if (!root) {
  11682. root = this.lastObjectRendered;
  11683. }
  11684. // run the hit test
  11685. this.processInteractive(hitTestEvent, root, null, true);
  11686. // return our found object - it'll be null if we didn't hit anything
  11687. return hitTestEvent.target;
  11688. };
  11689. /**
  11690. * Sets the DOM element which will receive mouse/touch events. This is useful for when you have
  11691. * other DOM elements on top of the renderers Canvas element. With this you'll be bale to delegate
  11692. * another DOM element to receive those events.
  11693. *
  11694. * @param {HTMLElement} element - the DOM element which will receive mouse and touch events.
  11695. * @param {number} [resolution=1] - The resolution / device pixel ratio of the new element (relative to the canvas).
  11696. */
  11697. InteractionManager.prototype.setTargetElement = function (element, resolution) {
  11698. if (resolution === void 0) { resolution = 1; }
  11699. this.removeTickerListener();
  11700. this.removeEvents();
  11701. this.interactionDOMElement = element;
  11702. this.resolution = resolution;
  11703. this.addEvents();
  11704. this.addTickerListener();
  11705. };
  11706. /**
  11707. * Add the ticker listener
  11708. *
  11709. * @private
  11710. */
  11711. InteractionManager.prototype.addTickerListener = function () {
  11712. if (this.tickerAdded || !this.interactionDOMElement || !this._useSystemTicker) {
  11713. return;
  11714. }
  11715. Ticker.system.add(this.tickerUpdate, this, exports.UPDATE_PRIORITY.INTERACTION);
  11716. this.tickerAdded = true;
  11717. };
  11718. /**
  11719. * Remove the ticker listener
  11720. *
  11721. * @private
  11722. */
  11723. InteractionManager.prototype.removeTickerListener = function () {
  11724. if (!this.tickerAdded) {
  11725. return;
  11726. }
  11727. Ticker.system.remove(this.tickerUpdate, this);
  11728. this.tickerAdded = false;
  11729. };
  11730. /**
  11731. * Registers all the DOM events
  11732. *
  11733. * @private
  11734. */
  11735. InteractionManager.prototype.addEvents = function () {
  11736. if (this.eventsAdded || !this.interactionDOMElement) {
  11737. return;
  11738. }
  11739. var style = this.interactionDOMElement.style;
  11740. if (self.navigator.msPointerEnabled) {
  11741. style.msContentZooming = 'none';
  11742. style.msTouchAction = 'none';
  11743. }
  11744. else if (this.supportsPointerEvents) {
  11745. style.touchAction = 'none';
  11746. }
  11747. /*
  11748. * These events are added first, so that if pointer events are normalized, they are fired
  11749. * in the same order as non-normalized events. ie. pointer event 1st, mouse / touch 2nd
  11750. */
  11751. if (this.supportsPointerEvents) {
  11752. self.document.addEventListener('pointermove', this.onPointerMove, this._eventListenerOptions);
  11753. this.interactionDOMElement.addEventListener('pointerdown', this.onPointerDown, this._eventListenerOptions);
  11754. // pointerout is fired in addition to pointerup (for touch events) and pointercancel
  11755. // we already handle those, so for the purposes of what we do in onPointerOut, we only
  11756. // care about the pointerleave event
  11757. this.interactionDOMElement.addEventListener('pointerleave', this.onPointerOut, this._eventListenerOptions);
  11758. this.interactionDOMElement.addEventListener('pointerover', this.onPointerOver, this._eventListenerOptions);
  11759. self.addEventListener('pointercancel', this.onPointerCancel, this._eventListenerOptions);
  11760. self.addEventListener('pointerup', this.onPointerUp, this._eventListenerOptions);
  11761. }
  11762. else {
  11763. self.document.addEventListener('mousemove', this.onPointerMove, this._eventListenerOptions);
  11764. this.interactionDOMElement.addEventListener('mousedown', this.onPointerDown, this._eventListenerOptions);
  11765. this.interactionDOMElement.addEventListener('mouseout', this.onPointerOut, this._eventListenerOptions);
  11766. this.interactionDOMElement.addEventListener('mouseover', this.onPointerOver, this._eventListenerOptions);
  11767. self.addEventListener('mouseup', this.onPointerUp, this._eventListenerOptions);
  11768. }
  11769. // always look directly for touch events so that we can provide original data
  11770. // In a future version we should change this to being just a fallback and rely solely on
  11771. // PointerEvents whenever available
  11772. if (this.supportsTouchEvents) {
  11773. this.interactionDOMElement.addEventListener('touchstart', this.onPointerDown, this._eventListenerOptions);
  11774. this.interactionDOMElement.addEventListener('touchcancel', this.onPointerCancel, this._eventListenerOptions);
  11775. this.interactionDOMElement.addEventListener('touchend', this.onPointerUp, this._eventListenerOptions);
  11776. this.interactionDOMElement.addEventListener('touchmove', this.onPointerMove, this._eventListenerOptions);
  11777. }
  11778. this.eventsAdded = true;
  11779. };
  11780. /**
  11781. * Removes all the DOM events that were previously registered
  11782. *
  11783. * @private
  11784. */
  11785. InteractionManager.prototype.removeEvents = function () {
  11786. if (!this.eventsAdded || !this.interactionDOMElement) {
  11787. return;
  11788. }
  11789. var style = this.interactionDOMElement.style;
  11790. if (self.navigator.msPointerEnabled) {
  11791. style.msContentZooming = '';
  11792. style.msTouchAction = '';
  11793. }
  11794. else if (this.supportsPointerEvents) {
  11795. style.touchAction = '';
  11796. }
  11797. if (this.supportsPointerEvents) {
  11798. self.document.removeEventListener('pointermove', this.onPointerMove, this._eventListenerOptions);
  11799. this.interactionDOMElement.removeEventListener('pointerdown', this.onPointerDown, this._eventListenerOptions);
  11800. this.interactionDOMElement.removeEventListener('pointerleave', this.onPointerOut, this._eventListenerOptions);
  11801. this.interactionDOMElement.removeEventListener('pointerover', this.onPointerOver, this._eventListenerOptions);
  11802. self.removeEventListener('pointercancel', this.onPointerCancel, this._eventListenerOptions);
  11803. self.removeEventListener('pointerup', this.onPointerUp, this._eventListenerOptions);
  11804. }
  11805. else {
  11806. self.document.removeEventListener('mousemove', this.onPointerMove, this._eventListenerOptions);
  11807. this.interactionDOMElement.removeEventListener('mousedown', this.onPointerDown, this._eventListenerOptions);
  11808. this.interactionDOMElement.removeEventListener('mouseout', this.onPointerOut, this._eventListenerOptions);
  11809. this.interactionDOMElement.removeEventListener('mouseover', this.onPointerOver, this._eventListenerOptions);
  11810. self.removeEventListener('mouseup', this.onPointerUp, this._eventListenerOptions);
  11811. }
  11812. if (this.supportsTouchEvents) {
  11813. this.interactionDOMElement.removeEventListener('touchstart', this.onPointerDown, this._eventListenerOptions);
  11814. this.interactionDOMElement.removeEventListener('touchcancel', this.onPointerCancel, this._eventListenerOptions);
  11815. this.interactionDOMElement.removeEventListener('touchend', this.onPointerUp, this._eventListenerOptions);
  11816. this.interactionDOMElement.removeEventListener('touchmove', this.onPointerMove, this._eventListenerOptions);
  11817. }
  11818. this.interactionDOMElement = null;
  11819. this.eventsAdded = false;
  11820. };
  11821. /**
  11822. * Updates the state of interactive objects if at least {@link interactionFrequency}
  11823. * milliseconds have passed since the last invocation.
  11824. *
  11825. * Invoked by a throttled ticker update from {@link PIXI.Ticker.system}.
  11826. *
  11827. * @param {number} deltaTime - time delta since the last call
  11828. */
  11829. InteractionManager.prototype.tickerUpdate = function (deltaTime) {
  11830. this._deltaTime += deltaTime;
  11831. if (this._deltaTime < this.interactionFrequency) {
  11832. return;
  11833. }
  11834. this._deltaTime = 0;
  11835. this.update();
  11836. };
  11837. /**
  11838. * Updates the state of interactive objects.
  11839. */
  11840. InteractionManager.prototype.update = function () {
  11841. if (!this.interactionDOMElement) {
  11842. return;
  11843. }
  11844. // if the user move the mouse this check has already been done using the mouse move!
  11845. if (this._didMove) {
  11846. this._didMove = false;
  11847. return;
  11848. }
  11849. this.cursor = null;
  11850. // Resets the flag as set by a stopPropagation call. This flag is usually reset by a user interaction of any kind,
  11851. // but there was a scenario of a display object moving under a static mouse cursor.
  11852. // In this case, mouseover and mouseevents would not pass the flag test in dispatchEvent function
  11853. for (var k in this.activeInteractionData) {
  11854. // eslint-disable-next-line no-prototype-builtins
  11855. if (this.activeInteractionData.hasOwnProperty(k)) {
  11856. var interactionData = this.activeInteractionData[k];
  11857. if (interactionData.originalEvent && interactionData.pointerType !== 'touch') {
  11858. var interactionEvent = this.configureInteractionEventForDOMEvent(this.eventData, interactionData.originalEvent, interactionData);
  11859. this.processInteractive(interactionEvent, this.lastObjectRendered, this.processPointerOverOut, true);
  11860. }
  11861. }
  11862. }
  11863. this.setCursorMode(this.cursor);
  11864. };
  11865. /**
  11866. * Sets the current cursor mode, handling any callbacks or CSS style changes.
  11867. *
  11868. * @param {string} mode - cursor mode, a key from the cursorStyles dictionary
  11869. */
  11870. InteractionManager.prototype.setCursorMode = function (mode) {
  11871. mode = mode || 'default';
  11872. var applyStyles = true;
  11873. // offscreen canvas does not support setting styles, but cursor modes can be functions,
  11874. // in order to handle pixi rendered cursors, so we can't bail
  11875. if (self.OffscreenCanvas && this.interactionDOMElement instanceof OffscreenCanvas) {
  11876. applyStyles = false;
  11877. }
  11878. // if the mode didn't actually change, bail early
  11879. if (this.currentCursorMode === mode) {
  11880. return;
  11881. }
  11882. this.currentCursorMode = mode;
  11883. var style = this.cursorStyles[mode];
  11884. // only do things if there is a cursor style for it
  11885. if (style) {
  11886. switch (typeof style) {
  11887. case 'string':
  11888. // string styles are handled as cursor CSS
  11889. if (applyStyles) {
  11890. this.interactionDOMElement.style.cursor = style;
  11891. }
  11892. break;
  11893. case 'function':
  11894. // functions are just called, and passed the cursor mode
  11895. style(mode);
  11896. break;
  11897. case 'object':
  11898. // if it is an object, assume that it is a dictionary of CSS styles,
  11899. // apply it to the interactionDOMElement
  11900. if (applyStyles) {
  11901. Object.assign(this.interactionDOMElement.style, style);
  11902. }
  11903. break;
  11904. }
  11905. }
  11906. else if (applyStyles && typeof mode === 'string' && !Object.prototype.hasOwnProperty.call(this.cursorStyles, mode)) {
  11907. // if it mode is a string (not a Symbol) and cursorStyles doesn't have any entry
  11908. // for the mode, then assume that the dev wants it to be CSS for the cursor.
  11909. this.interactionDOMElement.style.cursor = mode;
  11910. }
  11911. };
  11912. /**
  11913. * Dispatches an event on the display object that was interacted with
  11914. *
  11915. * @param {PIXI.Container|PIXI.Sprite|PIXI.TilingSprite} displayObject - the display object in question
  11916. * @param {string} eventString - the name of the event (e.g, mousedown)
  11917. * @param {PIXI.InteractionEvent} eventData - the event data object
  11918. * @private
  11919. */
  11920. InteractionManager.prototype.dispatchEvent = function (displayObject, eventString, eventData) {
  11921. // Even if the event was stopped, at least dispatch any remaining events
  11922. // for the same display object.
  11923. if (!eventData.stopPropagationHint || displayObject === eventData.stopsPropagatingAt) {
  11924. eventData.currentTarget = displayObject;
  11925. eventData.type = eventString;
  11926. displayObject.emit(eventString, eventData);
  11927. if (displayObject[eventString]) {
  11928. displayObject[eventString](eventData);
  11929. }
  11930. }
  11931. };
  11932. /**
  11933. * Puts a event on a queue to be dispatched later. This is used to guarantee correct
  11934. * ordering of over/out events.
  11935. *
  11936. * @param {PIXI.Container|PIXI.Sprite|PIXI.TilingSprite} displayObject - the display object in question
  11937. * @param {string} eventString - the name of the event (e.g, mousedown)
  11938. * @param {object} eventData - the event data object
  11939. * @private
  11940. */
  11941. InteractionManager.prototype.delayDispatchEvent = function (displayObject, eventString, eventData) {
  11942. this.delayedEvents.push({ displayObject: displayObject, eventString: eventString, eventData: eventData });
  11943. };
  11944. /**
  11945. * Maps x and y coords from a DOM object and maps them correctly to the PixiJS view. The
  11946. * resulting value is stored in the point. This takes into account the fact that the DOM
  11947. * element could be scaled and positioned anywhere on the screen.
  11948. *
  11949. * @param {PIXI.IPointData} point - the point that the result will be stored in
  11950. * @param {number} x - the x coord of the position to map
  11951. * @param {number} y - the y coord of the position to map
  11952. */
  11953. InteractionManager.prototype.mapPositionToPoint = function (point, x, y) {
  11954. var rect;
  11955. // IE 11 fix
  11956. if (!this.interactionDOMElement.parentElement) {
  11957. rect = {
  11958. x: 0,
  11959. y: 0,
  11960. width: this.interactionDOMElement.width,
  11961. height: this.interactionDOMElement.height,
  11962. left: 0,
  11963. top: 0
  11964. };
  11965. }
  11966. else {
  11967. rect = this.interactionDOMElement.getBoundingClientRect();
  11968. }
  11969. var resolutionMultiplier = 1.0 / this.resolution;
  11970. point.x = ((x - rect.left) * (this.interactionDOMElement.width / rect.width)) * resolutionMultiplier;
  11971. point.y = ((y - rect.top) * (this.interactionDOMElement.height / rect.height)) * resolutionMultiplier;
  11972. };
  11973. /**
  11974. * This function is provides a neat way of crawling through the scene graph and running a
  11975. * specified function on all interactive objects it finds. It will also take care of hit
  11976. * testing the interactive objects and passes the hit across in the function.
  11977. *
  11978. * @protected
  11979. * @param {PIXI.InteractionEvent} interactionEvent - event containing the point that
  11980. * is tested for collision
  11981. * @param {PIXI.Container|PIXI.Sprite|PIXI.TilingSprite} displayObject - the displayObject
  11982. * that will be hit test (recursively crawls its children)
  11983. * @param {Function} [func] - the function that will be called on each interactive object. The
  11984. * interactionEvent, displayObject and hit will be passed to the function
  11985. * @param {boolean} [hitTest] - indicates whether we want to calculate hits
  11986. * or just iterate through all interactive objects
  11987. */
  11988. InteractionManager.prototype.processInteractive = function (interactionEvent, displayObject, func, hitTest) {
  11989. var hit = this.search.findHit(interactionEvent, displayObject, func, hitTest);
  11990. var delayedEvents = this.delayedEvents;
  11991. if (!delayedEvents.length) {
  11992. return hit;
  11993. }
  11994. // Reset the propagation hint, because we start deeper in the tree again.
  11995. interactionEvent.stopPropagationHint = false;
  11996. var delayedLen = delayedEvents.length;
  11997. this.delayedEvents = [];
  11998. for (var i = 0; i < delayedLen; i++) {
  11999. var _a = delayedEvents[i], displayObject_1 = _a.displayObject, eventString = _a.eventString, eventData = _a.eventData;
  12000. // When we reach the object we wanted to stop propagating at,
  12001. // set the propagation hint.
  12002. if (eventData.stopsPropagatingAt === displayObject_1) {
  12003. eventData.stopPropagationHint = true;
  12004. }
  12005. this.dispatchEvent(displayObject_1, eventString, eventData);
  12006. }
  12007. return hit;
  12008. };
  12009. /**
  12010. * Is called when the pointer button is pressed down on the renderer element
  12011. *
  12012. * @private
  12013. * @param {PointerEvent} originalEvent - The DOM event of a pointer button being pressed down
  12014. */
  12015. InteractionManager.prototype.onPointerDown = function (originalEvent) {
  12016. // if we support touch events, then only use those for touch events, not pointer events
  12017. if (this.supportsTouchEvents && originalEvent.pointerType === 'touch')
  12018. { return; }
  12019. var events = this.normalizeToPointerData(originalEvent);
  12020. /*
  12021. * No need to prevent default on natural pointer events, as there are no side effects
  12022. * Normalized events, however, may have the double mousedown/touchstart issue on the native android browser,
  12023. * so still need to be prevented.
  12024. */
  12025. // Guaranteed that there will be at least one event in events, and all events must have the same pointer type
  12026. if (this.autoPreventDefault && events[0].isNormalized) {
  12027. var cancelable = originalEvent.cancelable || !('cancelable' in originalEvent);
  12028. if (cancelable) {
  12029. originalEvent.preventDefault();
  12030. }
  12031. }
  12032. var eventLen = events.length;
  12033. for (var i = 0; i < eventLen; i++) {
  12034. var event = events[i];
  12035. var interactionData = this.getInteractionDataForPointerId(event);
  12036. var interactionEvent = this.configureInteractionEventForDOMEvent(this.eventData, event, interactionData);
  12037. interactionEvent.data.originalEvent = originalEvent;
  12038. this.processInteractive(interactionEvent, this.lastObjectRendered, this.processPointerDown, true);
  12039. this.emit('pointerdown', interactionEvent);
  12040. if (event.pointerType === 'touch') {
  12041. this.emit('touchstart', interactionEvent);
  12042. }
  12043. // emit a mouse event for "pen" pointers, the way a browser would emit a fallback event
  12044. else if (event.pointerType === 'mouse' || event.pointerType === 'pen') {
  12045. var isRightButton = event.button === 2;
  12046. this.emit(isRightButton ? 'rightdown' : 'mousedown', this.eventData);
  12047. }
  12048. }
  12049. };
  12050. /**
  12051. * Processes the result of the pointer down check and dispatches the event if need be
  12052. *
  12053. * @private
  12054. * @param {PIXI.InteractionEvent} interactionEvent - The interaction event wrapping the DOM event
  12055. * @param {PIXI.Container|PIXI.Sprite|PIXI.TilingSprite} displayObject - The display object that was tested
  12056. * @param {boolean} hit - the result of the hit test on the display object
  12057. */
  12058. InteractionManager.prototype.processPointerDown = function (interactionEvent, displayObject, hit) {
  12059. var data = interactionEvent.data;
  12060. var id = interactionEvent.data.identifier;
  12061. if (hit) {
  12062. if (!displayObject.trackedPointers[id]) {
  12063. displayObject.trackedPointers[id] = new InteractionTrackingData(id);
  12064. }
  12065. this.dispatchEvent(displayObject, 'pointerdown', interactionEvent);
  12066. if (data.pointerType === 'touch') {
  12067. this.dispatchEvent(displayObject, 'touchstart', interactionEvent);
  12068. }
  12069. else if (data.pointerType === 'mouse' || data.pointerType === 'pen') {
  12070. var isRightButton = data.button === 2;
  12071. if (isRightButton) {
  12072. displayObject.trackedPointers[id].rightDown = true;
  12073. }
  12074. else {
  12075. displayObject.trackedPointers[id].leftDown = true;
  12076. }
  12077. this.dispatchEvent(displayObject, isRightButton ? 'rightdown' : 'mousedown', interactionEvent);
  12078. }
  12079. }
  12080. };
  12081. /**
  12082. * Is called when the pointer button is released on the renderer element
  12083. *
  12084. * @private
  12085. * @param {PointerEvent} originalEvent - The DOM event of a pointer button being released
  12086. * @param {boolean} cancelled - true if the pointer is cancelled
  12087. * @param {Function} func - Function passed to {@link processInteractive}
  12088. */
  12089. InteractionManager.prototype.onPointerComplete = function (originalEvent, cancelled, func) {
  12090. var events = this.normalizeToPointerData(originalEvent);
  12091. var eventLen = events.length;
  12092. // if the event wasn't targeting our canvas, then consider it to be pointerupoutside
  12093. // in all cases (unless it was a pointercancel)
  12094. var eventAppend = originalEvent.target !== this.interactionDOMElement ? 'outside' : '';
  12095. for (var i = 0; i < eventLen; i++) {
  12096. var event = events[i];
  12097. var interactionData = this.getInteractionDataForPointerId(event);
  12098. var interactionEvent = this.configureInteractionEventForDOMEvent(this.eventData, event, interactionData);
  12099. interactionEvent.data.originalEvent = originalEvent;
  12100. // perform hit testing for events targeting our canvas or cancel events
  12101. this.processInteractive(interactionEvent, this.lastObjectRendered, func, cancelled || !eventAppend);
  12102. this.emit(cancelled ? 'pointercancel' : "pointerup" + eventAppend, interactionEvent);
  12103. if (event.pointerType === 'mouse' || event.pointerType === 'pen') {
  12104. var isRightButton = event.button === 2;
  12105. this.emit(isRightButton ? "rightup" + eventAppend : "mouseup" + eventAppend, interactionEvent);
  12106. }
  12107. else if (event.pointerType === 'touch') {
  12108. this.emit(cancelled ? 'touchcancel' : "touchend" + eventAppend, interactionEvent);
  12109. this.releaseInteractionDataForPointerId(event.pointerId);
  12110. }
  12111. }
  12112. };
  12113. /**
  12114. * Is called when the pointer button is cancelled
  12115. *
  12116. * @private
  12117. * @param {PointerEvent} event - The DOM event of a pointer button being released
  12118. */
  12119. InteractionManager.prototype.onPointerCancel = function (event) {
  12120. // if we support touch events, then only use those for touch events, not pointer events
  12121. if (this.supportsTouchEvents && event.pointerType === 'touch')
  12122. { return; }
  12123. this.onPointerComplete(event, true, this.processPointerCancel);
  12124. };
  12125. /**
  12126. * Processes the result of the pointer cancel check and dispatches the event if need be
  12127. *
  12128. * @private
  12129. * @param {PIXI.InteractionEvent} interactionEvent - The interaction event wrapping the DOM event
  12130. * @param {PIXI.Container|PIXI.Sprite|PIXI.TilingSprite} displayObject - The display object that was tested
  12131. */
  12132. InteractionManager.prototype.processPointerCancel = function (interactionEvent, displayObject) {
  12133. var data = interactionEvent.data;
  12134. var id = interactionEvent.data.identifier;
  12135. if (displayObject.trackedPointers[id] !== undefined) {
  12136. delete displayObject.trackedPointers[id];
  12137. this.dispatchEvent(displayObject, 'pointercancel', interactionEvent);
  12138. if (data.pointerType === 'touch') {
  12139. this.dispatchEvent(displayObject, 'touchcancel', interactionEvent);
  12140. }
  12141. }
  12142. };
  12143. /**
  12144. * Is called when the pointer button is released on the renderer element
  12145. *
  12146. * @private
  12147. * @param {PointerEvent} event - The DOM event of a pointer button being released
  12148. */
  12149. InteractionManager.prototype.onPointerUp = function (event) {
  12150. // if we support touch events, then only use those for touch events, not pointer events
  12151. if (this.supportsTouchEvents && event.pointerType === 'touch')
  12152. { return; }
  12153. this.onPointerComplete(event, false, this.processPointerUp);
  12154. };
  12155. /**
  12156. * Processes the result of the pointer up check and dispatches the event if need be
  12157. *
  12158. * @private
  12159. * @param {PIXI.InteractionEvent} interactionEvent - The interaction event wrapping the DOM event
  12160. * @param {PIXI.Container|PIXI.Sprite|PIXI.TilingSprite} displayObject - The display object that was tested
  12161. * @param {boolean} hit - the result of the hit test on the display object
  12162. */
  12163. InteractionManager.prototype.processPointerUp = function (interactionEvent, displayObject, hit) {
  12164. var data = interactionEvent.data;
  12165. var id = interactionEvent.data.identifier;
  12166. var trackingData = displayObject.trackedPointers[id];
  12167. var isTouch = data.pointerType === 'touch';
  12168. var isMouse = (data.pointerType === 'mouse' || data.pointerType === 'pen');
  12169. // need to track mouse down status in the mouse block so that we can emit
  12170. // event in a later block
  12171. var isMouseTap = false;
  12172. // Mouse only
  12173. if (isMouse) {
  12174. var isRightButton = data.button === 2;
  12175. var flags = InteractionTrackingData.FLAGS;
  12176. var test = isRightButton ? flags.RIGHT_DOWN : flags.LEFT_DOWN;
  12177. var isDown = trackingData !== undefined && (trackingData.flags & test);
  12178. if (hit) {
  12179. this.dispatchEvent(displayObject, isRightButton ? 'rightup' : 'mouseup', interactionEvent);
  12180. if (isDown) {
  12181. this.dispatchEvent(displayObject, isRightButton ? 'rightclick' : 'click', interactionEvent);
  12182. // because we can confirm that the mousedown happened on this object, flag for later emit of pointertap
  12183. isMouseTap = true;
  12184. }
  12185. }
  12186. else if (isDown) {
  12187. this.dispatchEvent(displayObject, isRightButton ? 'rightupoutside' : 'mouseupoutside', interactionEvent);
  12188. }
  12189. // update the down state of the tracking data
  12190. if (trackingData) {
  12191. if (isRightButton) {
  12192. trackingData.rightDown = false;
  12193. }
  12194. else {
  12195. trackingData.leftDown = false;
  12196. }
  12197. }
  12198. }
  12199. // Pointers and Touches, and Mouse
  12200. if (hit) {
  12201. this.dispatchEvent(displayObject, 'pointerup', interactionEvent);
  12202. if (isTouch)
  12203. { this.dispatchEvent(displayObject, 'touchend', interactionEvent); }
  12204. if (trackingData) {
  12205. // emit pointertap if not a mouse, or if the mouse block decided it was a tap
  12206. if (!isMouse || isMouseTap) {
  12207. this.dispatchEvent(displayObject, 'pointertap', interactionEvent);
  12208. }
  12209. if (isTouch) {
  12210. this.dispatchEvent(displayObject, 'tap', interactionEvent);
  12211. // touches are no longer over (if they ever were) when we get the touchend
  12212. // so we should ensure that we don't keep pretending that they are
  12213. trackingData.over = false;
  12214. }
  12215. }
  12216. }
  12217. else if (trackingData) {
  12218. this.dispatchEvent(displayObject, 'pointerupoutside', interactionEvent);
  12219. if (isTouch)
  12220. { this.dispatchEvent(displayObject, 'touchendoutside', interactionEvent); }
  12221. }
  12222. // Only remove the tracking data if there is no over/down state still associated with it
  12223. if (trackingData && trackingData.none) {
  12224. delete displayObject.trackedPointers[id];
  12225. }
  12226. };
  12227. /**
  12228. * Is called when the pointer moves across the renderer element
  12229. *
  12230. * @private
  12231. * @param {PointerEvent} originalEvent - The DOM event of a pointer moving
  12232. */
  12233. InteractionManager.prototype.onPointerMove = function (originalEvent) {
  12234. // if we support touch events, then only use those for touch events, not pointer events
  12235. if (this.supportsTouchEvents && originalEvent.pointerType === 'touch')
  12236. { return; }
  12237. var events = this.normalizeToPointerData(originalEvent);
  12238. if (events[0].pointerType === 'mouse' || events[0].pointerType === 'pen') {
  12239. this._didMove = true;
  12240. this.cursor = null;
  12241. }
  12242. var eventLen = events.length;
  12243. for (var i = 0; i < eventLen; i++) {
  12244. var event = events[i];
  12245. var interactionData = this.getInteractionDataForPointerId(event);
  12246. var interactionEvent = this.configureInteractionEventForDOMEvent(this.eventData, event, interactionData);
  12247. interactionEvent.data.originalEvent = originalEvent;
  12248. this.processInteractive(interactionEvent, this.lastObjectRendered, this.processPointerMove, true);
  12249. this.emit('pointermove', interactionEvent);
  12250. if (event.pointerType === 'touch')
  12251. { this.emit('touchmove', interactionEvent); }
  12252. if (event.pointerType === 'mouse' || event.pointerType === 'pen')
  12253. { this.emit('mousemove', interactionEvent); }
  12254. }
  12255. if (events[0].pointerType === 'mouse') {
  12256. this.setCursorMode(this.cursor);
  12257. // TODO BUG for parents interactive object (border order issue)
  12258. }
  12259. };
  12260. /**
  12261. * Processes the result of the pointer move check and dispatches the event if need be
  12262. *
  12263. * @private
  12264. * @param {PIXI.InteractionEvent} interactionEvent - The interaction event wrapping the DOM event
  12265. * @param {PIXI.Container|PIXI.Sprite|PIXI.TilingSprite} displayObject - The display object that was tested
  12266. * @param {boolean} hit - the result of the hit test on the display object
  12267. */
  12268. InteractionManager.prototype.processPointerMove = function (interactionEvent, displayObject, hit) {
  12269. var data = interactionEvent.data;
  12270. var isTouch = data.pointerType === 'touch';
  12271. var isMouse = (data.pointerType === 'mouse' || data.pointerType === 'pen');
  12272. if (isMouse) {
  12273. this.processPointerOverOut(interactionEvent, displayObject, hit);
  12274. }
  12275. if (!this.moveWhenInside || hit) {
  12276. this.dispatchEvent(displayObject, 'pointermove', interactionEvent);
  12277. if (isTouch)
  12278. { this.dispatchEvent(displayObject, 'touchmove', interactionEvent); }
  12279. if (isMouse)
  12280. { this.dispatchEvent(displayObject, 'mousemove', interactionEvent); }
  12281. }
  12282. };
  12283. /**
  12284. * Is called when the pointer is moved out of the renderer element
  12285. *
  12286. * @private
  12287. * @param {PointerEvent} originalEvent - The DOM event of a pointer being moved out
  12288. */
  12289. InteractionManager.prototype.onPointerOut = function (originalEvent) {
  12290. // if we support touch events, then only use those for touch events, not pointer events
  12291. if (this.supportsTouchEvents && originalEvent.pointerType === 'touch')
  12292. { return; }
  12293. var events = this.normalizeToPointerData(originalEvent);
  12294. // Only mouse and pointer can call onPointerOut, so events will always be length 1
  12295. var event = events[0];
  12296. if (event.pointerType === 'mouse') {
  12297. this.mouseOverRenderer = false;
  12298. this.setCursorMode(null);
  12299. }
  12300. var interactionData = this.getInteractionDataForPointerId(event);
  12301. var interactionEvent = this.configureInteractionEventForDOMEvent(this.eventData, event, interactionData);
  12302. interactionEvent.data.originalEvent = event;
  12303. this.processInteractive(interactionEvent, this.lastObjectRendered, this.processPointerOverOut, false);
  12304. this.emit('pointerout', interactionEvent);
  12305. if (event.pointerType === 'mouse' || event.pointerType === 'pen') {
  12306. this.emit('mouseout', interactionEvent);
  12307. }
  12308. else {
  12309. // we can get touchleave events after touchend, so we want to make sure we don't
  12310. // introduce memory leaks
  12311. this.releaseInteractionDataForPointerId(interactionData.identifier);
  12312. }
  12313. };
  12314. /**
  12315. * Processes the result of the pointer over/out check and dispatches the event if need be
  12316. *
  12317. * @private
  12318. * @param {PIXI.InteractionEvent} interactionEvent - The interaction event wrapping the DOM event
  12319. * @param {PIXI.Container|PIXI.Sprite|PIXI.TilingSprite} displayObject - The display object that was tested
  12320. * @param {boolean} hit - the result of the hit test on the display object
  12321. */
  12322. InteractionManager.prototype.processPointerOverOut = function (interactionEvent, displayObject, hit) {
  12323. var data = interactionEvent.data;
  12324. var id = interactionEvent.data.identifier;
  12325. var isMouse = (data.pointerType === 'mouse' || data.pointerType === 'pen');
  12326. var trackingData = displayObject.trackedPointers[id];
  12327. // if we just moused over the display object, then we need to track that state
  12328. if (hit && !trackingData) {
  12329. trackingData = displayObject.trackedPointers[id] = new InteractionTrackingData(id);
  12330. }
  12331. if (trackingData === undefined)
  12332. { return; }
  12333. if (hit && this.mouseOverRenderer) {
  12334. if (!trackingData.over) {
  12335. trackingData.over = true;
  12336. this.delayDispatchEvent(displayObject, 'pointerover', interactionEvent);
  12337. if (isMouse) {
  12338. this.delayDispatchEvent(displayObject, 'mouseover', interactionEvent);
  12339. }
  12340. }
  12341. // only change the cursor if it has not already been changed (by something deeper in the
  12342. // display tree)
  12343. if (isMouse && this.cursor === null) {
  12344. this.cursor = displayObject.cursor;
  12345. }
  12346. }
  12347. else if (trackingData.over) {
  12348. trackingData.over = false;
  12349. this.dispatchEvent(displayObject, 'pointerout', this.eventData);
  12350. if (isMouse) {
  12351. this.dispatchEvent(displayObject, 'mouseout', interactionEvent);
  12352. }
  12353. // if there is no mouse down information for the pointer, then it is safe to delete
  12354. if (trackingData.none) {
  12355. delete displayObject.trackedPointers[id];
  12356. }
  12357. }
  12358. };
  12359. /**
  12360. * Is called when the pointer is moved into the renderer element
  12361. *
  12362. * @private
  12363. * @param {PointerEvent} originalEvent - The DOM event of a pointer button being moved into the renderer view
  12364. */
  12365. InteractionManager.prototype.onPointerOver = function (originalEvent) {
  12366. var events = this.normalizeToPointerData(originalEvent);
  12367. // Only mouse and pointer can call onPointerOver, so events will always be length 1
  12368. var event = events[0];
  12369. var interactionData = this.getInteractionDataForPointerId(event);
  12370. var interactionEvent = this.configureInteractionEventForDOMEvent(this.eventData, event, interactionData);
  12371. interactionEvent.data.originalEvent = event;
  12372. if (event.pointerType === 'mouse') {
  12373. this.mouseOverRenderer = true;
  12374. }
  12375. this.emit('pointerover', interactionEvent);
  12376. if (event.pointerType === 'mouse' || event.pointerType === 'pen') {
  12377. this.emit('mouseover', interactionEvent);
  12378. }
  12379. };
  12380. /**
  12381. * Get InteractionData for a given pointerId. Store that data as well
  12382. *
  12383. * @private
  12384. * @param {PointerEvent} event - Normalized pointer event, output from normalizeToPointerData
  12385. * @return {PIXI.InteractionData} - Interaction data for the given pointer identifier
  12386. */
  12387. InteractionManager.prototype.getInteractionDataForPointerId = function (event) {
  12388. var pointerId = event.pointerId;
  12389. var interactionData;
  12390. if (pointerId === MOUSE_POINTER_ID || event.pointerType === 'mouse') {
  12391. interactionData = this.mouse;
  12392. }
  12393. else if (this.activeInteractionData[pointerId]) {
  12394. interactionData = this.activeInteractionData[pointerId];
  12395. }
  12396. else {
  12397. interactionData = this.interactionDataPool.pop() || new InteractionData();
  12398. interactionData.identifier = pointerId;
  12399. this.activeInteractionData[pointerId] = interactionData;
  12400. }
  12401. // copy properties from the event, so that we can make sure that touch/pointer specific
  12402. // data is available
  12403. interactionData.copyEvent(event);
  12404. return interactionData;
  12405. };
  12406. /**
  12407. * Return unused InteractionData to the pool, for a given pointerId
  12408. *
  12409. * @private
  12410. * @param {number} pointerId - Identifier from a pointer event
  12411. */
  12412. InteractionManager.prototype.releaseInteractionDataForPointerId = function (pointerId) {
  12413. var interactionData = this.activeInteractionData[pointerId];
  12414. if (interactionData) {
  12415. delete this.activeInteractionData[pointerId];
  12416. interactionData.reset();
  12417. this.interactionDataPool.push(interactionData);
  12418. }
  12419. };
  12420. /**
  12421. * Configure an InteractionEvent to wrap a DOM PointerEvent and InteractionData
  12422. *
  12423. * @private
  12424. * @param {PIXI.InteractionEvent} interactionEvent - The event to be configured
  12425. * @param {PointerEvent} pointerEvent - The DOM event that will be paired with the InteractionEvent
  12426. * @param {PIXI.InteractionData} interactionData - The InteractionData that will be paired
  12427. * with the InteractionEvent
  12428. * @return {PIXI.InteractionEvent} the interaction event that was passed in
  12429. */
  12430. InteractionManager.prototype.configureInteractionEventForDOMEvent = function (interactionEvent, pointerEvent, interactionData) {
  12431. interactionEvent.data = interactionData;
  12432. this.mapPositionToPoint(interactionData.global, pointerEvent.clientX, pointerEvent.clientY);
  12433. // Not really sure why this is happening, but it's how a previous version handled things
  12434. if (pointerEvent.pointerType === 'touch') {
  12435. pointerEvent.globalX = interactionData.global.x;
  12436. pointerEvent.globalY = interactionData.global.y;
  12437. }
  12438. interactionData.originalEvent = pointerEvent;
  12439. interactionEvent.reset();
  12440. return interactionEvent;
  12441. };
  12442. /**
  12443. * Ensures that the original event object contains all data that a regular pointer event would have
  12444. *
  12445. * @private
  12446. * @param {TouchEvent|MouseEvent|PointerEvent} event - The original event data from a touch or mouse event
  12447. * @return {PointerEvent[]} An array containing a single normalized pointer event, in the case of a pointer
  12448. * or mouse event, or a multiple normalized pointer events if there are multiple changed touches
  12449. */
  12450. InteractionManager.prototype.normalizeToPointerData = function (event) {
  12451. var normalizedEvents = [];
  12452. if (this.supportsTouchEvents && event instanceof TouchEvent) {
  12453. for (var i = 0, li = event.changedTouches.length; i < li; i++) {
  12454. var touch = event.changedTouches[i];
  12455. if (typeof touch.button === 'undefined')
  12456. { touch.button = event.touches.length ? 1 : 0; }
  12457. if (typeof touch.buttons === 'undefined')
  12458. { touch.buttons = event.touches.length ? 1 : 0; }
  12459. if (typeof touch.isPrimary === 'undefined') {
  12460. touch.isPrimary = event.touches.length === 1 && event.type === 'touchstart';
  12461. }
  12462. if (typeof touch.width === 'undefined')
  12463. { touch.width = touch.radiusX || 1; }
  12464. if (typeof touch.height === 'undefined')
  12465. { touch.height = touch.radiusY || 1; }
  12466. if (typeof touch.tiltX === 'undefined')
  12467. { touch.tiltX = 0; }
  12468. if (typeof touch.tiltY === 'undefined')
  12469. { touch.tiltY = 0; }
  12470. if (typeof touch.pointerType === 'undefined')
  12471. { touch.pointerType = 'touch'; }
  12472. if (typeof touch.pointerId === 'undefined')
  12473. { touch.pointerId = touch.identifier || 0; }
  12474. if (typeof touch.pressure === 'undefined')
  12475. { touch.pressure = touch.force || 0.5; }
  12476. if (typeof touch.twist === 'undefined')
  12477. { touch.twist = 0; }
  12478. if (typeof touch.tangentialPressure === 'undefined')
  12479. { touch.tangentialPressure = 0; }
  12480. // TODO: Remove these, as layerX/Y is not a standard, is deprecated, has uneven
  12481. // support, and the fill ins are not quite the same
  12482. // offsetX/Y might be okay, but is not the same as clientX/Y when the canvas's top
  12483. // left is not 0,0 on the page
  12484. if (typeof touch.layerX === 'undefined')
  12485. { touch.layerX = touch.offsetX = touch.clientX; }
  12486. if (typeof touch.layerY === 'undefined')
  12487. { touch.layerY = touch.offsetY = touch.clientY; }
  12488. // mark the touch as normalized, just so that we know we did it
  12489. touch.isNormalized = true;
  12490. normalizedEvents.push(touch);
  12491. }
  12492. }
  12493. // apparently PointerEvent subclasses MouseEvent, so yay
  12494. else if (!self.MouseEvent
  12495. || (event instanceof MouseEvent && (!this.supportsPointerEvents || !(event instanceof self.PointerEvent)))) {
  12496. var tempEvent = event;
  12497. if (typeof tempEvent.isPrimary === 'undefined')
  12498. { tempEvent.isPrimary = true; }
  12499. if (typeof tempEvent.width === 'undefined')
  12500. { tempEvent.width = 1; }
  12501. if (typeof tempEvent.height === 'undefined')
  12502. { tempEvent.height = 1; }
  12503. if (typeof tempEvent.tiltX === 'undefined')
  12504. { tempEvent.tiltX = 0; }
  12505. if (typeof tempEvent.tiltY === 'undefined')
  12506. { tempEvent.tiltY = 0; }
  12507. if (typeof tempEvent.pointerType === 'undefined')
  12508. { tempEvent.pointerType = 'mouse'; }
  12509. if (typeof tempEvent.pointerId === 'undefined')
  12510. { tempEvent.pointerId = MOUSE_POINTER_ID; }
  12511. if (typeof tempEvent.pressure === 'undefined')
  12512. { tempEvent.pressure = 0.5; }
  12513. if (typeof tempEvent.twist === 'undefined')
  12514. { tempEvent.twist = 0; }
  12515. if (typeof tempEvent.tangentialPressure === 'undefined')
  12516. { tempEvent.tangentialPressure = 0; }
  12517. // mark the mouse event as normalized, just so that we know we did it
  12518. tempEvent.isNormalized = true;
  12519. normalizedEvents.push(tempEvent);
  12520. }
  12521. else {
  12522. normalizedEvents.push(event);
  12523. }
  12524. return normalizedEvents;
  12525. };
  12526. /**
  12527. * Destroys the interaction manager
  12528. *
  12529. */
  12530. InteractionManager.prototype.destroy = function () {
  12531. this.removeEvents();
  12532. this.removeTickerListener();
  12533. this.removeAllListeners();
  12534. this.renderer = null;
  12535. this.mouse = null;
  12536. this.eventData = null;
  12537. this.interactionDOMElement = null;
  12538. this.onPointerDown = null;
  12539. this.processPointerDown = null;
  12540. this.onPointerUp = null;
  12541. this.processPointerUp = null;
  12542. this.onPointerCancel = null;
  12543. this.processPointerCancel = null;
  12544. this.onPointerMove = null;
  12545. this.processPointerMove = null;
  12546. this.onPointerOut = null;
  12547. this.processPointerOverOut = null;
  12548. this.onPointerOver = null;
  12549. this.search = null;
  12550. };
  12551. return InteractionManager;
  12552. }(eventemitter3));
  12553. /*!
  12554. * @pixi/runner - v6.1.2
  12555. * Compiled Thu, 12 Aug 2021 17:11:19 UTC
  12556. *
  12557. * @pixi/runner is licensed under the MIT License.
  12558. * http://www.opensource.org/licenses/mit-license
  12559. */
  12560. /**
  12561. * A Runner is a highly performant and simple alternative to signals. Best used in situations
  12562. * where events are dispatched to many objects at high frequency (say every frame!)
  12563. *
  12564. *
  12565. * like a signal..
  12566. * ```
  12567. * import { Runner } from '@pixi/runner';
  12568. *
  12569. * const myObject = {
  12570. * loaded: new Runner('loaded')
  12571. * }
  12572. *
  12573. * const listener = {
  12574. * loaded: function(){
  12575. * // thin
  12576. * }
  12577. * }
  12578. *
  12579. * myObject.loaded.add(listener);
  12580. *
  12581. * myObject.loaded.emit();
  12582. * ```
  12583. *
  12584. * Or for handling calling the same function on many items
  12585. * ```
  12586. * import { Runner } from '@pixi/runner';
  12587. *
  12588. * const myGame = {
  12589. * update: new Runner('update')
  12590. * }
  12591. *
  12592. * const gameObject = {
  12593. * update: function(time){
  12594. * // update my gamey state
  12595. * }
  12596. * }
  12597. *
  12598. * myGame.update.add(gameObject);
  12599. *
  12600. * myGame.update.emit(time);
  12601. * ```
  12602. * @class
  12603. * @memberof PIXI
  12604. */
  12605. var Runner = /** @class */ (function () {
  12606. /**
  12607. * @param {string} name - the function name that will be executed on the listeners added to this Runner.
  12608. */
  12609. function Runner(name) {
  12610. this.items = [];
  12611. this._name = name;
  12612. this._aliasCount = 0;
  12613. }
  12614. /**
  12615. * Dispatch/Broadcast Runner to all listeners added to the queue.
  12616. * @param {...any} params - optional parameters to pass to each listener
  12617. * @return {PIXI.Runner}
  12618. */
  12619. Runner.prototype.emit = function (a0, a1, a2, a3, a4, a5, a6, a7) {
  12620. if (arguments.length > 8) {
  12621. throw new Error('max arguments reached');
  12622. }
  12623. var _a = this, name = _a.name, items = _a.items;
  12624. this._aliasCount++;
  12625. for (var i = 0, len = items.length; i < len; i++) {
  12626. items[i][name](a0, a1, a2, a3, a4, a5, a6, a7);
  12627. }
  12628. if (items === this.items) {
  12629. this._aliasCount--;
  12630. }
  12631. return this;
  12632. };
  12633. Runner.prototype.ensureNonAliasedItems = function () {
  12634. if (this._aliasCount > 0 && this.items.length > 1) {
  12635. this._aliasCount = 0;
  12636. this.items = this.items.slice(0);
  12637. }
  12638. };
  12639. /**
  12640. * Add a listener to the Runner
  12641. *
  12642. * Runners do not need to have scope or functions passed to them.
  12643. * All that is required is to pass the listening object and ensure that it has contains a function that has the same name
  12644. * as the name provided to the Runner when it was created.
  12645. *
  12646. * Eg A listener passed to this Runner will require a 'complete' function.
  12647. *
  12648. * ```
  12649. * import { Runner } from '@pixi/runner';
  12650. *
  12651. * const complete = new Runner('complete');
  12652. * ```
  12653. *
  12654. * The scope used will be the object itself.
  12655. *
  12656. * @param {any} item - The object that will be listening.
  12657. * @return {PIXI.Runner}
  12658. */
  12659. Runner.prototype.add = function (item) {
  12660. if (item[this._name]) {
  12661. this.ensureNonAliasedItems();
  12662. this.remove(item);
  12663. this.items.push(item);
  12664. }
  12665. return this;
  12666. };
  12667. /**
  12668. * Remove a single listener from the dispatch queue.
  12669. * @param {any} item - The listener that you would like to remove.
  12670. * @return {PIXI.Runner}
  12671. */
  12672. Runner.prototype.remove = function (item) {
  12673. var index = this.items.indexOf(item);
  12674. if (index !== -1) {
  12675. this.ensureNonAliasedItems();
  12676. this.items.splice(index, 1);
  12677. }
  12678. return this;
  12679. };
  12680. /**
  12681. * Check to see if the listener is already in the Runner
  12682. * @param {any} item - The listener that you would like to check.
  12683. */
  12684. Runner.prototype.contains = function (item) {
  12685. return this.items.indexOf(item) !== -1;
  12686. };
  12687. /**
  12688. * Remove all listeners from the Runner
  12689. * @return {PIXI.Runner}
  12690. */
  12691. Runner.prototype.removeAll = function () {
  12692. this.ensureNonAliasedItems();
  12693. this.items.length = 0;
  12694. return this;
  12695. };
  12696. /**
  12697. * Remove all references, don't use after this.
  12698. */
  12699. Runner.prototype.destroy = function () {
  12700. this.removeAll();
  12701. this.items = null;
  12702. this._name = null;
  12703. };
  12704. Object.defineProperty(Runner.prototype, "empty", {
  12705. /**
  12706. * `true` if there are no this Runner contains no listeners
  12707. *
  12708. * @member {boolean}
  12709. * @readonly
  12710. */
  12711. get: function () {
  12712. return this.items.length === 0;
  12713. },
  12714. enumerable: false,
  12715. configurable: true
  12716. });
  12717. Object.defineProperty(Runner.prototype, "name", {
  12718. /**
  12719. * The name of the runner.
  12720. *
  12721. * @member {string}
  12722. * @readonly
  12723. */
  12724. get: function () {
  12725. return this._name;
  12726. },
  12727. enumerable: false,
  12728. configurable: true
  12729. });
  12730. return Runner;
  12731. }());
  12732. Object.defineProperties(Runner.prototype, {
  12733. /**
  12734. * Alias for `emit`
  12735. * @memberof PIXI.Runner#
  12736. * @method dispatch
  12737. * @see PIXI.Runner#emit
  12738. */
  12739. dispatch: { value: Runner.prototype.emit },
  12740. /**
  12741. * Alias for `emit`
  12742. * @memberof PIXI.Runner#
  12743. * @method run
  12744. * @see PIXI.Runner#emit
  12745. */
  12746. run: { value: Runner.prototype.emit },
  12747. });
  12748. /*!
  12749. * @pixi/core - v6.1.2
  12750. * Compiled Thu, 12 Aug 2021 17:11:19 UTC
  12751. *
  12752. * @pixi/core is licensed under the MIT License.
  12753. * http://www.opensource.org/licenses/mit-license
  12754. */
  12755. /**
  12756. * The maximum support for using WebGL. If a device does not
  12757. * support WebGL version, for instance WebGL 2, it will still
  12758. * attempt to fallback support to WebGL 1. If you want to
  12759. * explicitly remove feature support to target a more stable
  12760. * baseline, prefer a lower environment.
  12761. *
  12762. * Due to {@link https://bugs.chromium.org/p/chromium/issues/detail?id=934823|bug in chromium}
  12763. * we disable webgl2 by default for all non-apple mobile devices.
  12764. *
  12765. * @static
  12766. * @name PREFER_ENV
  12767. * @memberof PIXI.settings
  12768. * @type {number}
  12769. * @default PIXI.ENV.WEBGL2
  12770. */
  12771. settings.PREFER_ENV = isMobile$1.any ? exports.ENV.WEBGL : exports.ENV.WEBGL2;
  12772. /**
  12773. * If set to `true`, *only* Textures and BaseTexture objects stored
  12774. * in the caches ({@link PIXI.utils.TextureCache TextureCache} and
  12775. * {@link PIXI.utils.BaseTextureCache BaseTextureCache}) can be
  12776. * used when calling {@link PIXI.Texture.from Texture.from} or
  12777. * {@link PIXI.BaseTexture.from BaseTexture.from}.
  12778. * Otherwise, these `from` calls throw an exception. Using this property
  12779. * can be useful if you want to enforce preloading all assets with
  12780. * {@link PIXI.Loader Loader}.
  12781. *
  12782. * @static
  12783. * @name STRICT_TEXTURE_CACHE
  12784. * @memberof PIXI.settings
  12785. * @type {boolean}
  12786. * @default false
  12787. */
  12788. settings.STRICT_TEXTURE_CACHE = false;
  12789. /**
  12790. * Collection of installed resource types, class must extend {@link PIXI.Resource}.
  12791. * @example
  12792. * class CustomResource extends PIXI.Resource {
  12793. * // MUST have source, options constructor signature
  12794. * // for auto-detected resources to be created.
  12795. * constructor(source, options) {
  12796. * super();
  12797. * }
  12798. * upload(renderer, baseTexture, glTexture) {
  12799. * // upload with GL
  12800. * return true;
  12801. * }
  12802. * // used to auto-detect resource
  12803. * static test(source, extension) {
  12804. * return extension === 'xyz'|| source instanceof SomeClass;
  12805. * }
  12806. * }
  12807. * // Install the new resource type
  12808. * PIXI.INSTALLED.push(CustomResource);
  12809. *
  12810. * @memberof PIXI
  12811. * @type {Array<PIXI.IResourcePlugin>}
  12812. * @static
  12813. * @readonly
  12814. */
  12815. var INSTALLED = [];
  12816. /**
  12817. * Create a resource element from a single source element. This
  12818. * auto-detects which type of resource to create. All resources that
  12819. * are auto-detectable must have a static `test` method and a constructor
  12820. * with the arguments `(source, options?)`. Currently, the supported
  12821. * resources for auto-detection include:
  12822. * - {@link PIXI.ImageResource}
  12823. * - {@link PIXI.CanvasResource}
  12824. * - {@link PIXI.VideoResource}
  12825. * - {@link PIXI.SVGResource}
  12826. * - {@link PIXI.BufferResource}
  12827. * @static
  12828. * @memberof PIXI
  12829. * @function autoDetectResource
  12830. * @param {string|*} source - Resource source, this can be the URL to the resource,
  12831. * a typed-array (for BufferResource), HTMLVideoElement, SVG data-uri
  12832. * or any other resource that can be auto-detected. If not resource is
  12833. * detected, it's assumed to be an ImageResource.
  12834. * @param {object} [options] - Pass-through options to use for Resource
  12835. * @param {number} [options.width] - Width of BufferResource or SVG rasterization
  12836. * @param {number} [options.height] - Height of BufferResource or SVG rasterization
  12837. * @param {boolean} [options.autoLoad=true] - Image, SVG and Video flag to start loading
  12838. * @param {number} [options.scale=1] - SVG source scale. Overridden by width, height
  12839. * @param {boolean} [options.createBitmap=PIXI.settings.CREATE_IMAGE_BITMAP] - Image option to create Bitmap object
  12840. * @param {boolean} [options.crossorigin=true] - Image and Video option to set crossOrigin
  12841. * @param {boolean} [options.autoPlay=true] - Video option to start playing video immediately
  12842. * @param {number} [options.updateFPS=0] - Video option to update how many times a second the
  12843. * texture should be updated from the video. Leave at 0 to update at every render
  12844. * @return {PIXI.Resource} The created resource.
  12845. */
  12846. function autoDetectResource(source, options) {
  12847. if (!source) {
  12848. return null;
  12849. }
  12850. var extension = '';
  12851. if (typeof source === 'string') {
  12852. // search for file extension: period, 3-4 chars, then ?, # or EOL
  12853. var result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source);
  12854. if (result) {
  12855. extension = result[1].toLowerCase();
  12856. }
  12857. }
  12858. for (var i = INSTALLED.length - 1; i >= 0; --i) {
  12859. var ResourcePlugin = INSTALLED[i];
  12860. if (ResourcePlugin.test && ResourcePlugin.test(source, extension)) {
  12861. return new ResourcePlugin(source, options);
  12862. }
  12863. }
  12864. throw new Error('Unrecognized source type to auto-detect Resource');
  12865. }
  12866. /*! *****************************************************************************
  12867. Copyright (c) Microsoft Corporation. All rights reserved.
  12868. Licensed under the Apache License, Version 2.0 (the "License"); you may not use
  12869. this file except in compliance with the License. You may obtain a copy of the
  12870. License at http://www.apache.org/licenses/LICENSE-2.0
  12871. THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  12872. KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
  12873. WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
  12874. MERCHANTABLITY OR NON-INFRINGEMENT.
  12875. See the Apache Version 2.0 License for specific language governing permissions
  12876. and limitations under the License.
  12877. ***************************************************************************** */
  12878. /* global Reflect, Promise */
  12879. var extendStatics$2 = function(d, b) {
  12880. extendStatics$2 = Object.setPrototypeOf ||
  12881. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  12882. function (d, b) { for (var p in b) { if (b.hasOwnProperty(p)) { d[p] = b[p]; } } };
  12883. return extendStatics$2(d, b);
  12884. };
  12885. function __extends$2(d, b) {
  12886. extendStatics$2(d, b);
  12887. function __() { this.constructor = d; }
  12888. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  12889. }
  12890. var __assign = function() {
  12891. __assign = Object.assign || function __assign(t) {
  12892. var arguments$1 = arguments;
  12893. for (var s, i = 1, n = arguments.length; i < n; i++) {
  12894. s = arguments$1[i];
  12895. for (var p in s) { if (Object.prototype.hasOwnProperty.call(s, p)) { t[p] = s[p]; } }
  12896. }
  12897. return t;
  12898. };
  12899. return __assign.apply(this, arguments);
  12900. };
  12901. function __rest(s, e) {
  12902. var t = {};
  12903. for (var p in s) { if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
  12904. { t[p] = s[p]; } }
  12905. if (s != null && typeof Object.getOwnPropertySymbols === "function")
  12906. { for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0)
  12907. { t[p[i]] = s[p[i]]; } } }
  12908. return t;
  12909. }
  12910. /**
  12911. * Base resource class for textures that manages validation and uploading, depending on its type.
  12912. *
  12913. * Uploading of a base texture to the GPU is required.
  12914. *
  12915. * @class
  12916. * @memberof PIXI
  12917. */
  12918. var Resource = /** @class */ (function () {
  12919. /**
  12920. * @param {number} [width=0] - Width of the resource
  12921. * @param {number} [height=0] - Height of the resource
  12922. */
  12923. function Resource(width, height) {
  12924. if (width === void 0) { width = 0; }
  12925. if (height === void 0) { height = 0; }
  12926. /**
  12927. * Internal width of the resource
  12928. * @member {number}
  12929. * @protected
  12930. */
  12931. this._width = width;
  12932. /**
  12933. * Internal height of the resource
  12934. * @member {number}
  12935. * @protected
  12936. */
  12937. this._height = height;
  12938. /**
  12939. * If resource has been destroyed
  12940. * @member {boolean}
  12941. * @readonly
  12942. * @default false
  12943. */
  12944. this.destroyed = false;
  12945. /**
  12946. * `true` if resource is created by BaseTexture
  12947. * useful for doing cleanup with BaseTexture destroy
  12948. * and not cleaning up resources that were created
  12949. * externally.
  12950. * @member {boolean}
  12951. * @protected
  12952. */
  12953. this.internal = false;
  12954. /**
  12955. * Mini-runner for handling resize events
  12956. * accepts 2 parameters: width, height
  12957. *
  12958. * @member {Runner}
  12959. * @private
  12960. */
  12961. this.onResize = new Runner('setRealSize');
  12962. /**
  12963. * Mini-runner for handling update events
  12964. *
  12965. * @member {Runner}
  12966. * @private
  12967. */
  12968. this.onUpdate = new Runner('update');
  12969. /**
  12970. * Handle internal errors, such as loading errors
  12971. * accepts 1 param: error
  12972. *
  12973. * @member {Runner}
  12974. * @private
  12975. */
  12976. this.onError = new Runner('onError');
  12977. }
  12978. /**
  12979. * Bind to a parent BaseTexture
  12980. *
  12981. * @param {PIXI.BaseTexture} baseTexture - Parent texture
  12982. */
  12983. Resource.prototype.bind = function (baseTexture) {
  12984. this.onResize.add(baseTexture);
  12985. this.onUpdate.add(baseTexture);
  12986. this.onError.add(baseTexture);
  12987. // Call a resize immediate if we already
  12988. // have the width and height of the resource
  12989. if (this._width || this._height) {
  12990. this.onResize.emit(this._width, this._height);
  12991. }
  12992. };
  12993. /**
  12994. * Unbind to a parent BaseTexture
  12995. *
  12996. * @param {PIXI.BaseTexture} baseTexture - Parent texture
  12997. */
  12998. Resource.prototype.unbind = function (baseTexture) {
  12999. this.onResize.remove(baseTexture);
  13000. this.onUpdate.remove(baseTexture);
  13001. this.onError.remove(baseTexture);
  13002. };
  13003. /**
  13004. * Trigger a resize event
  13005. * @param {number} width - X dimension
  13006. * @param {number} height - Y dimension
  13007. */
  13008. Resource.prototype.resize = function (width, height) {
  13009. if (width !== this._width || height !== this._height) {
  13010. this._width = width;
  13011. this._height = height;
  13012. this.onResize.emit(width, height);
  13013. }
  13014. };
  13015. Object.defineProperty(Resource.prototype, "valid", {
  13016. /**
  13017. * Has been validated
  13018. * @readonly
  13019. * @member {boolean}
  13020. */
  13021. get: function () {
  13022. return !!this._width && !!this._height;
  13023. },
  13024. enumerable: false,
  13025. configurable: true
  13026. });
  13027. /**
  13028. * Has been updated trigger event
  13029. */
  13030. Resource.prototype.update = function () {
  13031. if (!this.destroyed) {
  13032. this.onUpdate.emit();
  13033. }
  13034. };
  13035. /**
  13036. * This can be overridden to start preloading a resource
  13037. * or do any other prepare step.
  13038. * @protected
  13039. * @return {Promise<void>} Handle the validate event
  13040. */
  13041. Resource.prototype.load = function () {
  13042. return Promise.resolve(this);
  13043. };
  13044. Object.defineProperty(Resource.prototype, "width", {
  13045. /**
  13046. * The width of the resource.
  13047. *
  13048. * @member {number}
  13049. * @readonly
  13050. */
  13051. get: function () {
  13052. return this._width;
  13053. },
  13054. enumerable: false,
  13055. configurable: true
  13056. });
  13057. Object.defineProperty(Resource.prototype, "height", {
  13058. /**
  13059. * The height of the resource.
  13060. *
  13061. * @member {number}
  13062. * @readonly
  13063. */
  13064. get: function () {
  13065. return this._height;
  13066. },
  13067. enumerable: false,
  13068. configurable: true
  13069. });
  13070. /**
  13071. * Set the style, optional to override
  13072. *
  13073. * @param {PIXI.Renderer} renderer - yeah, renderer!
  13074. * @param {PIXI.BaseTexture} baseTexture - the texture
  13075. * @param {PIXI.GLTexture} glTexture - texture instance for this webgl context
  13076. * @returns {boolean} `true` is success
  13077. */
  13078. Resource.prototype.style = function (_renderer, _baseTexture, _glTexture) {
  13079. return false;
  13080. };
  13081. /**
  13082. * Clean up anything, this happens when destroying is ready.
  13083. *
  13084. * @protected
  13085. */
  13086. Resource.prototype.dispose = function () {
  13087. // override
  13088. };
  13089. /**
  13090. * Call when destroying resource, unbind any BaseTexture object
  13091. * before calling this method, as reference counts are maintained
  13092. * internally.
  13093. */
  13094. Resource.prototype.destroy = function () {
  13095. if (!this.destroyed) {
  13096. this.destroyed = true;
  13097. this.dispose();
  13098. this.onError.removeAll();
  13099. this.onError = null;
  13100. this.onResize.removeAll();
  13101. this.onResize = null;
  13102. this.onUpdate.removeAll();
  13103. this.onUpdate = null;
  13104. }
  13105. };
  13106. /**
  13107. * Abstract, used to auto-detect resource type
  13108. *
  13109. * @static
  13110. * @param {*} source - The source object
  13111. * @param {string} extension - The extension of source, if set
  13112. */
  13113. Resource.test = function (_source, _extension) {
  13114. return false;
  13115. };
  13116. return Resource;
  13117. }());
  13118. /**
  13119. * @interface SharedArrayBuffer
  13120. */
  13121. /**
  13122. * Buffer resource with data of typed array.
  13123. * @class
  13124. * @extends PIXI.Resource
  13125. * @memberof PIXI
  13126. */
  13127. var BufferResource = /** @class */ (function (_super) {
  13128. __extends$2(BufferResource, _super);
  13129. /**
  13130. * @param {Float32Array|Uint8Array|Uint32Array} source - Source buffer
  13131. * @param {object} options - Options
  13132. * @param {number} options.width - Width of the texture
  13133. * @param {number} options.height - Height of the texture
  13134. */
  13135. function BufferResource(source, options) {
  13136. var _this = this;
  13137. var _a = options || {}, width = _a.width, height = _a.height;
  13138. if (!width || !height) {
  13139. throw new Error('BufferResource width or height invalid');
  13140. }
  13141. _this = _super.call(this, width, height) || this;
  13142. /**
  13143. * Source array
  13144. * Cannot be ClampedUint8Array because it cant be uploaded to WebGL
  13145. *
  13146. * @member {Float32Array|Uint8Array|Uint32Array}
  13147. */
  13148. _this.data = source;
  13149. return _this;
  13150. }
  13151. /**
  13152. * Upload the texture to the GPU.
  13153. * @param {PIXI.Renderer} renderer - Upload to the renderer
  13154. * @param {PIXI.BaseTexture} baseTexture - Reference to parent texture
  13155. * @param {PIXI.GLTexture} glTexture - glTexture
  13156. * @returns {boolean} true is success
  13157. */
  13158. BufferResource.prototype.upload = function (renderer, baseTexture, glTexture) {
  13159. var gl = renderer.gl;
  13160. gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, baseTexture.alphaMode === exports.ALPHA_MODES.UNPACK);
  13161. var width = baseTexture.realWidth;
  13162. var height = baseTexture.realHeight;
  13163. if (glTexture.width === width && glTexture.height === height) {
  13164. gl.texSubImage2D(baseTexture.target, 0, 0, 0, width, height, baseTexture.format, glTexture.type, this.data);
  13165. }
  13166. else {
  13167. glTexture.width = width;
  13168. glTexture.height = height;
  13169. gl.texImage2D(baseTexture.target, 0, glTexture.internalFormat, width, height, 0, baseTexture.format, glTexture.type, this.data);
  13170. }
  13171. return true;
  13172. };
  13173. /**
  13174. * Destroy and don't use after this
  13175. * @override
  13176. */
  13177. BufferResource.prototype.dispose = function () {
  13178. this.data = null;
  13179. };
  13180. /**
  13181. * Used to auto-detect the type of resource.
  13182. *
  13183. * @static
  13184. * @param {*} source - The source object
  13185. * @return {boolean} `true` if <canvas>
  13186. */
  13187. BufferResource.test = function (source) {
  13188. return source instanceof Float32Array
  13189. || source instanceof Uint8Array
  13190. || source instanceof Uint32Array;
  13191. };
  13192. return BufferResource;
  13193. }(Resource));
  13194. var defaultBufferOptions = {
  13195. scaleMode: exports.SCALE_MODES.NEAREST,
  13196. format: exports.FORMATS.RGBA,
  13197. alphaMode: exports.ALPHA_MODES.NPM,
  13198. };
  13199. /**
  13200. * A Texture stores the information that represents an image.
  13201. * All textures have a base texture, which contains information about the source.
  13202. * Therefore you can have many textures all using a single BaseTexture
  13203. *
  13204. * @class
  13205. * @extends PIXI.utils.EventEmitter
  13206. * @memberof PIXI
  13207. * @typeParam R - The BaseTexture's Resource type.
  13208. * @typeParam RO - The options for constructing resource.
  13209. */
  13210. var BaseTexture = /** @class */ (function (_super) {
  13211. __extends$2(BaseTexture, _super);
  13212. /**
  13213. * @param {PIXI.Resource|string|HTMLImageElement|HTMLCanvasElement|HTMLVideoElement} [resource=null] -
  13214. * The current resource to use, for things that aren't Resource objects, will be converted
  13215. * into a Resource.
  13216. * @param {Object} [options] - Collection of options
  13217. * @param {PIXI.MIPMAP_MODES} [options.mipmap=PIXI.settings.MIPMAP_TEXTURES] - If mipmapping is enabled for texture
  13218. * @param {number} [options.anisotropicLevel=PIXI.settings.ANISOTROPIC_LEVEL] - Anisotropic filtering level of texture
  13219. * @param {PIXI.WRAP_MODES} [options.wrapMode=PIXI.settings.WRAP_MODE] - Wrap mode for textures
  13220. * @param {PIXI.SCALE_MODES} [options.scaleMode=PIXI.settings.SCALE_MODE] - Default scale mode, linear, nearest
  13221. * @param {PIXI.FORMATS} [options.format=PIXI.FORMATS.RGBA] - GL format type
  13222. * @param {PIXI.TYPES} [options.type=PIXI.TYPES.UNSIGNED_BYTE] - GL data type
  13223. * @param {PIXI.TARGETS} [options.target=PIXI.TARGETS.TEXTURE_2D] - GL texture target
  13224. * @param {PIXI.ALPHA_MODES} [options.alphaMode=PIXI.ALPHA_MODES.UNPACK] - Pre multiply the image alpha
  13225. * @param {number} [options.width=0] - Width of the texture
  13226. * @param {number} [options.height=0] - Height of the texture
  13227. * @param {number} [options.resolution=PIXI.settings.RESOLUTION] - Resolution of the base texture
  13228. * @param {object} [options.resourceOptions] - Optional resource options,
  13229. * see {@link PIXI.autoDetectResource autoDetectResource}
  13230. */
  13231. function BaseTexture(resource, options) {
  13232. if (resource === void 0) { resource = null; }
  13233. if (options === void 0) { options = null; }
  13234. var _this = _super.call(this) || this;
  13235. options = options || {};
  13236. var alphaMode = options.alphaMode, mipmap = options.mipmap, anisotropicLevel = options.anisotropicLevel, scaleMode = options.scaleMode, width = options.width, height = options.height, wrapMode = options.wrapMode, format = options.format, type = options.type, target = options.target, resolution = options.resolution, resourceOptions = options.resourceOptions;
  13237. // Convert the resource to a Resource object
  13238. if (resource && !(resource instanceof Resource)) {
  13239. resource = autoDetectResource(resource, resourceOptions);
  13240. resource.internal = true;
  13241. }
  13242. _this.resolution = resolution || settings.RESOLUTION;
  13243. _this.width = Math.round((width || 0) * _this.resolution) / _this.resolution;
  13244. _this.height = Math.round((height || 0) * _this.resolution) / _this.resolution;
  13245. _this._mipmap = mipmap !== undefined ? mipmap : settings.MIPMAP_TEXTURES;
  13246. _this.anisotropicLevel = anisotropicLevel !== undefined ? anisotropicLevel : settings.ANISOTROPIC_LEVEL;
  13247. _this._wrapMode = wrapMode || settings.WRAP_MODE;
  13248. _this._scaleMode = scaleMode !== undefined ? scaleMode : settings.SCALE_MODE;
  13249. _this.format = format || exports.FORMATS.RGBA;
  13250. _this.type = type || exports.TYPES.UNSIGNED_BYTE;
  13251. _this.target = target || exports.TARGETS.TEXTURE_2D;
  13252. _this.alphaMode = alphaMode !== undefined ? alphaMode : exports.ALPHA_MODES.UNPACK;
  13253. _this.uid = uid();
  13254. _this.touched = 0;
  13255. _this.isPowerOfTwo = false;
  13256. _this._refreshPOT();
  13257. _this._glTextures = {};
  13258. _this.dirtyId = 0;
  13259. _this.dirtyStyleId = 0;
  13260. _this.cacheId = null;
  13261. _this.valid = width > 0 && height > 0;
  13262. _this.textureCacheIds = [];
  13263. _this.destroyed = false;
  13264. _this.resource = null;
  13265. _this._batchEnabled = 0;
  13266. _this._batchLocation = 0;
  13267. _this.parentTextureArray = null;
  13268. /**
  13269. * Fired when a not-immediately-available source finishes loading.
  13270. *
  13271. * @protected
  13272. * @event PIXI.BaseTexture#loaded
  13273. * @param {PIXI.BaseTexture} baseTexture - Resource loaded.
  13274. */
  13275. /**
  13276. * Fired when a not-immediately-available source fails to load.
  13277. *
  13278. * @protected
  13279. * @event PIXI.BaseTexture#error
  13280. * @param {PIXI.BaseTexture} baseTexture - Resource errored.
  13281. * @param {ErrorEvent} event - Load error event.
  13282. */
  13283. /**
  13284. * Fired when BaseTexture is updated.
  13285. *
  13286. * @protected
  13287. * @event PIXI.BaseTexture#loaded
  13288. * @param {PIXI.BaseTexture} baseTexture - Resource loaded.
  13289. */
  13290. /**
  13291. * Fired when BaseTexture is updated.
  13292. *
  13293. * @protected
  13294. * @event PIXI.BaseTexture#update
  13295. * @param {PIXI.BaseTexture} baseTexture - Instance of texture being updated.
  13296. */
  13297. /**
  13298. * Fired when BaseTexture is destroyed.
  13299. *
  13300. * @protected
  13301. * @event PIXI.BaseTexture#dispose
  13302. * @param {PIXI.BaseTexture} baseTexture - Instance of texture being destroyed.
  13303. */
  13304. // Set the resource
  13305. _this.setResource(resource);
  13306. return _this;
  13307. }
  13308. Object.defineProperty(BaseTexture.prototype, "realWidth", {
  13309. /**
  13310. * Pixel width of the source of this texture
  13311. *
  13312. * @readonly
  13313. * @member {number}
  13314. */
  13315. get: function () {
  13316. return Math.round(this.width * this.resolution);
  13317. },
  13318. enumerable: false,
  13319. configurable: true
  13320. });
  13321. Object.defineProperty(BaseTexture.prototype, "realHeight", {
  13322. /**
  13323. * Pixel height of the source of this texture
  13324. *
  13325. * @readonly
  13326. * @member {number}
  13327. */
  13328. get: function () {
  13329. return Math.round(this.height * this.resolution);
  13330. },
  13331. enumerable: false,
  13332. configurable: true
  13333. });
  13334. Object.defineProperty(BaseTexture.prototype, "mipmap", {
  13335. /**
  13336. * Mipmap mode of the texture, affects downscaled images
  13337. *
  13338. * @member {PIXI.MIPMAP_MODES}
  13339. * @default PIXI.settings.MIPMAP_TEXTURES
  13340. */
  13341. get: function () {
  13342. return this._mipmap;
  13343. },
  13344. set: function (value) {
  13345. if (this._mipmap !== value) {
  13346. this._mipmap = value;
  13347. this.dirtyStyleId++;
  13348. }
  13349. },
  13350. enumerable: false,
  13351. configurable: true
  13352. });
  13353. Object.defineProperty(BaseTexture.prototype, "scaleMode", {
  13354. /**
  13355. * The scale mode to apply when scaling this texture
  13356. *
  13357. * @member {PIXI.SCALE_MODES}
  13358. * @default PIXI.settings.SCALE_MODE
  13359. */
  13360. get: function () {
  13361. return this._scaleMode;
  13362. },
  13363. set: function (value) {
  13364. if (this._scaleMode !== value) {
  13365. this._scaleMode = value;
  13366. this.dirtyStyleId++;
  13367. }
  13368. },
  13369. enumerable: false,
  13370. configurable: true
  13371. });
  13372. Object.defineProperty(BaseTexture.prototype, "wrapMode", {
  13373. /**
  13374. * How the texture wraps
  13375. * @member {PIXI.WRAP_MODES}
  13376. * @default PIXI.settings.WRAP_MODE
  13377. */
  13378. get: function () {
  13379. return this._wrapMode;
  13380. },
  13381. set: function (value) {
  13382. if (this._wrapMode !== value) {
  13383. this._wrapMode = value;
  13384. this.dirtyStyleId++;
  13385. }
  13386. },
  13387. enumerable: false,
  13388. configurable: true
  13389. });
  13390. /**
  13391. * Changes style options of BaseTexture
  13392. *
  13393. * @param {PIXI.SCALE_MODES} [scaleMode] - Pixi scalemode
  13394. * @param {PIXI.MIPMAP_MODES} [mipmap] - enable mipmaps
  13395. * @returns {PIXI.BaseTexture} this
  13396. */
  13397. BaseTexture.prototype.setStyle = function (scaleMode, mipmap) {
  13398. var dirty;
  13399. if (scaleMode !== undefined && scaleMode !== this.scaleMode) {
  13400. this.scaleMode = scaleMode;
  13401. dirty = true;
  13402. }
  13403. if (mipmap !== undefined && mipmap !== this.mipmap) {
  13404. this.mipmap = mipmap;
  13405. dirty = true;
  13406. }
  13407. if (dirty) {
  13408. this.dirtyStyleId++;
  13409. }
  13410. return this;
  13411. };
  13412. /**
  13413. * Changes w/h/resolution. Texture becomes valid if width and height are greater than zero.
  13414. *
  13415. * @param {number} desiredWidth - Desired visual width
  13416. * @param {number} desiredHeight - Desired visual height
  13417. * @param {number} [resolution] - Optionally set resolution
  13418. * @returns {PIXI.BaseTexture} this
  13419. */
  13420. BaseTexture.prototype.setSize = function (desiredWidth, desiredHeight, resolution) {
  13421. resolution = resolution || this.resolution;
  13422. return this.setRealSize(desiredWidth * resolution, desiredHeight * resolution, resolution);
  13423. };
  13424. /**
  13425. * Sets real size of baseTexture, preserves current resolution.
  13426. *
  13427. * @param {number} realWidth - Full rendered width
  13428. * @param {number} realHeight - Full rendered height
  13429. * @param {number} [resolution] - Optionally set resolution
  13430. * @returns {PIXI.BaseTexture} this
  13431. */
  13432. BaseTexture.prototype.setRealSize = function (realWidth, realHeight, resolution) {
  13433. this.resolution = resolution || this.resolution;
  13434. this.width = Math.round(realWidth) / this.resolution;
  13435. this.height = Math.round(realHeight) / this.resolution;
  13436. this._refreshPOT();
  13437. this.update();
  13438. return this;
  13439. };
  13440. /**
  13441. * Refresh check for isPowerOfTwo texture based on size
  13442. *
  13443. * @private
  13444. */
  13445. BaseTexture.prototype._refreshPOT = function () {
  13446. this.isPowerOfTwo = isPow2(this.realWidth) && isPow2(this.realHeight);
  13447. };
  13448. /**
  13449. * Changes resolution
  13450. *
  13451. * @param {number} resolution - res
  13452. * @returns {PIXI.BaseTexture} this
  13453. */
  13454. BaseTexture.prototype.setResolution = function (resolution) {
  13455. var oldResolution = this.resolution;
  13456. if (oldResolution === resolution) {
  13457. return this;
  13458. }
  13459. this.resolution = resolution;
  13460. if (this.valid) {
  13461. this.width = Math.round(this.width * oldResolution) / resolution;
  13462. this.height = Math.round(this.height * oldResolution) / resolution;
  13463. this.emit('update', this);
  13464. }
  13465. this._refreshPOT();
  13466. return this;
  13467. };
  13468. /**
  13469. * Sets the resource if it wasn't set. Throws error if resource already present
  13470. *
  13471. * @param {PIXI.Resource} resource - that is managing this BaseTexture
  13472. * @returns {PIXI.BaseTexture} this
  13473. */
  13474. BaseTexture.prototype.setResource = function (resource) {
  13475. if (this.resource === resource) {
  13476. return this;
  13477. }
  13478. if (this.resource) {
  13479. throw new Error('Resource can be set only once');
  13480. }
  13481. resource.bind(this);
  13482. this.resource = resource;
  13483. return this;
  13484. };
  13485. /**
  13486. * Invalidates the object. Texture becomes valid if width and height are greater than zero.
  13487. */
  13488. BaseTexture.prototype.update = function () {
  13489. if (!this.valid) {
  13490. if (this.width > 0 && this.height > 0) {
  13491. this.valid = true;
  13492. this.emit('loaded', this);
  13493. this.emit('update', this);
  13494. }
  13495. }
  13496. else {
  13497. this.dirtyId++;
  13498. this.dirtyStyleId++;
  13499. this.emit('update', this);
  13500. }
  13501. };
  13502. /**
  13503. * Handle errors with resources.
  13504. * @private
  13505. * @param {ErrorEvent} event - Error event emitted.
  13506. */
  13507. BaseTexture.prototype.onError = function (event) {
  13508. this.emit('error', this, event);
  13509. };
  13510. /**
  13511. * Destroys this base texture.
  13512. * The method stops if resource doesn't want this texture to be destroyed.
  13513. * Removes texture from all caches.
  13514. */
  13515. BaseTexture.prototype.destroy = function () {
  13516. // remove and destroy the resource
  13517. if (this.resource) {
  13518. this.resource.unbind(this);
  13519. // only destroy resourced created internally
  13520. if (this.resource.internal) {
  13521. this.resource.destroy();
  13522. }
  13523. this.resource = null;
  13524. }
  13525. if (this.cacheId) {
  13526. delete BaseTextureCache[this.cacheId];
  13527. delete TextureCache[this.cacheId];
  13528. this.cacheId = null;
  13529. }
  13530. // finally let the WebGL renderer know..
  13531. this.dispose();
  13532. BaseTexture.removeFromCache(this);
  13533. this.textureCacheIds = null;
  13534. this.destroyed = true;
  13535. };
  13536. /**
  13537. * Frees the texture from WebGL memory without destroying this texture object.
  13538. * This means you can still use the texture later which will upload it to GPU
  13539. * memory again.
  13540. *
  13541. * @fires PIXI.BaseTexture#dispose
  13542. */
  13543. BaseTexture.prototype.dispose = function () {
  13544. this.emit('dispose', this);
  13545. };
  13546. /**
  13547. * Utility function for BaseTexture|Texture cast
  13548. */
  13549. BaseTexture.prototype.castToBaseTexture = function () {
  13550. return this;
  13551. };
  13552. /**
  13553. * Helper function that creates a base texture based on the source you provide.
  13554. * The source can be - image url, image element, canvas element. If the
  13555. * source is an image url or an image element and not in the base texture
  13556. * cache, it will be created and loaded.
  13557. *
  13558. * @static
  13559. * @param {string|HTMLImageElement|HTMLCanvasElement|SVGElement|HTMLVideoElement} source - The
  13560. * source to create base texture from.
  13561. * @param {object} [options] - See {@link PIXI.BaseTexture}'s constructor for options.
  13562. * @param {string} [options.pixiIdPrefix=pixiid] - If a source has no id, this is the prefix of the generated id
  13563. * @param {boolean} [strict] - Enforce strict-mode, see {@link PIXI.settings.STRICT_TEXTURE_CACHE}.
  13564. * @returns {PIXI.BaseTexture} The new base texture.
  13565. */
  13566. BaseTexture.from = function (source, options, strict) {
  13567. if (strict === void 0) { strict = settings.STRICT_TEXTURE_CACHE; }
  13568. var isFrame = typeof source === 'string';
  13569. var cacheId = null;
  13570. if (isFrame) {
  13571. cacheId = source;
  13572. }
  13573. else {
  13574. if (!source._pixiId) {
  13575. var prefix = (options && options.pixiIdPrefix) || 'pixiid';
  13576. source._pixiId = prefix + "_" + uid();
  13577. }
  13578. cacheId = source._pixiId;
  13579. }
  13580. var baseTexture = BaseTextureCache[cacheId];
  13581. // Strict-mode rejects invalid cacheIds
  13582. if (isFrame && strict && !baseTexture) {
  13583. throw new Error("The cacheId \"" + cacheId + "\" does not exist in BaseTextureCache.");
  13584. }
  13585. if (!baseTexture) {
  13586. baseTexture = new BaseTexture(source, options);
  13587. baseTexture.cacheId = cacheId;
  13588. BaseTexture.addToCache(baseTexture, cacheId);
  13589. }
  13590. return baseTexture;
  13591. };
  13592. /**
  13593. * Create a new BaseTexture with a BufferResource from a Float32Array.
  13594. * RGBA values are floats from 0 to 1.
  13595. * @static
  13596. * @param {Float32Array|Uint8Array} buffer - The optional array to use, if no data
  13597. * is provided, a new Float32Array is created.
  13598. * @param {number} width - Width of the resource
  13599. * @param {number} height - Height of the resource
  13600. * @param {object} [options] - See {@link PIXI.BaseTexture}'s constructor for options.
  13601. * @return {PIXI.BaseTexture} The resulting new BaseTexture
  13602. */
  13603. BaseTexture.fromBuffer = function (buffer, width, height, options) {
  13604. buffer = buffer || new Float32Array(width * height * 4);
  13605. var resource = new BufferResource(buffer, { width: width, height: height });
  13606. var type = buffer instanceof Float32Array ? exports.TYPES.FLOAT : exports.TYPES.UNSIGNED_BYTE;
  13607. return new BaseTexture(resource, Object.assign(defaultBufferOptions, options || { width: width, height: height, type: type }));
  13608. };
  13609. /**
  13610. * Adds a BaseTexture to the global BaseTextureCache. This cache is shared across the whole PIXI object.
  13611. *
  13612. * @static
  13613. * @param {PIXI.BaseTexture} baseTexture - The BaseTexture to add to the cache.
  13614. * @param {string} id - The id that the BaseTexture will be stored against.
  13615. */
  13616. BaseTexture.addToCache = function (baseTexture, id) {
  13617. if (id) {
  13618. if (baseTexture.textureCacheIds.indexOf(id) === -1) {
  13619. baseTexture.textureCacheIds.push(id);
  13620. }
  13621. if (BaseTextureCache[id]) {
  13622. // eslint-disable-next-line no-console
  13623. console.warn("BaseTexture added to the cache with an id [" + id + "] that already had an entry");
  13624. }
  13625. BaseTextureCache[id] = baseTexture;
  13626. }
  13627. };
  13628. /**
  13629. * Remove a BaseTexture from the global BaseTextureCache.
  13630. *
  13631. * @static
  13632. * @param {string|PIXI.BaseTexture} baseTexture - id of a BaseTexture to be removed, or a BaseTexture instance itself.
  13633. * @return {PIXI.BaseTexture|null} The BaseTexture that was removed.
  13634. */
  13635. BaseTexture.removeFromCache = function (baseTexture) {
  13636. if (typeof baseTexture === 'string') {
  13637. var baseTextureFromCache = BaseTextureCache[baseTexture];
  13638. if (baseTextureFromCache) {
  13639. var index = baseTextureFromCache.textureCacheIds.indexOf(baseTexture);
  13640. if (index > -1) {
  13641. baseTextureFromCache.textureCacheIds.splice(index, 1);
  13642. }
  13643. delete BaseTextureCache[baseTexture];
  13644. return baseTextureFromCache;
  13645. }
  13646. }
  13647. else if (baseTexture && baseTexture.textureCacheIds) {
  13648. for (var i = 0; i < baseTexture.textureCacheIds.length; ++i) {
  13649. delete BaseTextureCache[baseTexture.textureCacheIds[i]];
  13650. }
  13651. baseTexture.textureCacheIds.length = 0;
  13652. return baseTexture;
  13653. }
  13654. return null;
  13655. };
  13656. /**
  13657. * Global number of the texture batch, used by multi-texture renderers
  13658. *
  13659. * @static
  13660. * @member {number}
  13661. */
  13662. BaseTexture._globalBatch = 0;
  13663. return BaseTexture;
  13664. }(eventemitter3));
  13665. /**
  13666. * Resource that can manage several resource (items) inside.
  13667. * All resources need to have the same pixel size.
  13668. * Parent class for CubeResource and ArrayResource
  13669. *
  13670. * @class
  13671. * @extends PIXI.Resource
  13672. * @memberof PIXI
  13673. */
  13674. var AbstractMultiResource = /** @class */ (function (_super) {
  13675. __extends$2(AbstractMultiResource, _super);
  13676. /**
  13677. * @param {number} length
  13678. * @param {object} [options] - Options to for Resource constructor
  13679. * @param {number} [options.width] - Width of the resource
  13680. * @param {number} [options.height] - Height of the resource
  13681. */
  13682. function AbstractMultiResource(length, options) {
  13683. var _this = this;
  13684. var _a = options || {}, width = _a.width, height = _a.height;
  13685. _this = _super.call(this, width, height) || this;
  13686. /**
  13687. * Collection of partial baseTextures that correspond to resources
  13688. * @member {Array<PIXI.BaseTexture>}
  13689. * @readonly
  13690. */
  13691. _this.items = [];
  13692. /**
  13693. * Dirty IDs for each part
  13694. * @member {Array<number>}
  13695. * @readonly
  13696. */
  13697. _this.itemDirtyIds = [];
  13698. for (var i = 0; i < length; i++) {
  13699. var partTexture = new BaseTexture();
  13700. _this.items.push(partTexture);
  13701. // -2 - first run of texture array upload
  13702. // -1 - texture item was allocated
  13703. // >=0 - texture item uploaded , in sync with items[i].dirtyId
  13704. _this.itemDirtyIds.push(-2);
  13705. }
  13706. /**
  13707. * Number of elements in array
  13708. *
  13709. * @member {number}
  13710. * @readonly
  13711. */
  13712. _this.length = length;
  13713. /**
  13714. * Promise when loading
  13715. * @member {Promise}
  13716. * @private
  13717. * @default null
  13718. */
  13719. _this._load = null;
  13720. /**
  13721. * Bound baseTexture, there can only be one
  13722. * @member {PIXI.BaseTexture}
  13723. */
  13724. _this.baseTexture = null;
  13725. return _this;
  13726. }
  13727. /**
  13728. * used from ArrayResource and CubeResource constructors
  13729. * @param {Array<*>} resources - Can be resources, image elements, canvas, etc. ,
  13730. * length should be same as constructor length
  13731. * @param {object} [options] - detect options for resources
  13732. * @protected
  13733. */
  13734. AbstractMultiResource.prototype.initFromArray = function (resources, options) {
  13735. for (var i = 0; i < this.length; i++) {
  13736. if (!resources[i]) {
  13737. continue;
  13738. }
  13739. if (resources[i].castToBaseTexture) {
  13740. this.addBaseTextureAt(resources[i].castToBaseTexture(), i);
  13741. }
  13742. else if (resources[i] instanceof Resource) {
  13743. this.addResourceAt(resources[i], i);
  13744. }
  13745. else {
  13746. this.addResourceAt(autoDetectResource(resources[i], options), i);
  13747. }
  13748. }
  13749. };
  13750. /**
  13751. * Destroy this BaseImageResource
  13752. * @override
  13753. */
  13754. AbstractMultiResource.prototype.dispose = function () {
  13755. for (var i = 0, len = this.length; i < len; i++) {
  13756. this.items[i].destroy();
  13757. }
  13758. this.items = null;
  13759. this.itemDirtyIds = null;
  13760. this._load = null;
  13761. };
  13762. /**
  13763. * Set a resource by ID
  13764. *
  13765. * @param {PIXI.Resource} resource
  13766. * @param {number} index - Zero-based index of resource to set
  13767. * @return {PIXI.ArrayResource} Instance for chaining
  13768. */
  13769. AbstractMultiResource.prototype.addResourceAt = function (resource, index) {
  13770. if (!this.items[index]) {
  13771. throw new Error("Index " + index + " is out of bounds");
  13772. }
  13773. // Inherit the first resource dimensions
  13774. if (resource.valid && !this.valid) {
  13775. this.resize(resource.width, resource.height);
  13776. }
  13777. this.items[index].setResource(resource);
  13778. return this;
  13779. };
  13780. /**
  13781. * Set the parent base texture
  13782. * @member {PIXI.BaseTexture}
  13783. * @override
  13784. */
  13785. AbstractMultiResource.prototype.bind = function (baseTexture) {
  13786. if (this.baseTexture !== null) {
  13787. throw new Error('Only one base texture per TextureArray is allowed');
  13788. }
  13789. _super.prototype.bind.call(this, baseTexture);
  13790. for (var i = 0; i < this.length; i++) {
  13791. this.items[i].parentTextureArray = baseTexture;
  13792. this.items[i].on('update', baseTexture.update, baseTexture);
  13793. }
  13794. };
  13795. /**
  13796. * Unset the parent base texture
  13797. * @member {PIXI.BaseTexture}
  13798. * @override
  13799. */
  13800. AbstractMultiResource.prototype.unbind = function (baseTexture) {
  13801. _super.prototype.unbind.call(this, baseTexture);
  13802. for (var i = 0; i < this.length; i++) {
  13803. this.items[i].parentTextureArray = null;
  13804. this.items[i].off('update', baseTexture.update, baseTexture);
  13805. }
  13806. };
  13807. /**
  13808. * Load all the resources simultaneously
  13809. * @override
  13810. * @return {Promise<void>} When load is resolved
  13811. */
  13812. AbstractMultiResource.prototype.load = function () {
  13813. var _this = this;
  13814. if (this._load) {
  13815. return this._load;
  13816. }
  13817. var resources = this.items.map(function (item) { return item.resource; }).filter(function (item) { return item; });
  13818. // TODO: also implement load part-by-part strategy
  13819. var promises = resources.map(function (item) { return item.load(); });
  13820. this._load = Promise.all(promises)
  13821. .then(function () {
  13822. var _a = _this.items[0], realWidth = _a.realWidth, realHeight = _a.realHeight;
  13823. _this.resize(realWidth, realHeight);
  13824. return Promise.resolve(_this);
  13825. });
  13826. return this._load;
  13827. };
  13828. return AbstractMultiResource;
  13829. }(Resource));
  13830. /**
  13831. * A resource that contains a number of sources.
  13832. *
  13833. * @class
  13834. * @extends PIXI.Resource
  13835. * @memberof PIXI
  13836. */
  13837. var ArrayResource = /** @class */ (function (_super) {
  13838. __extends$2(ArrayResource, _super);
  13839. /**
  13840. * @param {number|Array<*>} source - Number of items in array or the collection
  13841. * of image URLs to use. Can also be resources, image elements, canvas, etc.
  13842. * @param {object} [options] - Options to apply to {@link PIXI.autoDetectResource}
  13843. * @param {number} [options.width] - Width of the resource
  13844. * @param {number} [options.height] - Height of the resource
  13845. */
  13846. function ArrayResource(source, options) {
  13847. var _this = this;
  13848. var _a = options || {}, width = _a.width, height = _a.height;
  13849. var urls;
  13850. var length;
  13851. if (Array.isArray(source)) {
  13852. urls = source;
  13853. length = source.length;
  13854. }
  13855. else {
  13856. length = source;
  13857. }
  13858. _this = _super.call(this, length, { width: width, height: height }) || this;
  13859. if (urls) {
  13860. _this.initFromArray(urls, options);
  13861. }
  13862. return _this;
  13863. }
  13864. /**
  13865. * Set a baseTexture by ID,
  13866. * ArrayResource just takes resource from it, nothing more
  13867. *
  13868. * @param {PIXI.BaseTexture} baseTexture
  13869. * @param {number} index - Zero-based index of resource to set
  13870. * @return {PIXI.ArrayResource} Instance for chaining
  13871. */
  13872. ArrayResource.prototype.addBaseTextureAt = function (baseTexture, index) {
  13873. if (baseTexture.resource) {
  13874. this.addResourceAt(baseTexture.resource, index);
  13875. }
  13876. else {
  13877. throw new Error('ArrayResource does not support RenderTexture');
  13878. }
  13879. return this;
  13880. };
  13881. /**
  13882. * Add binding
  13883. * @member {PIXI.BaseTexture}
  13884. * @override
  13885. */
  13886. ArrayResource.prototype.bind = function (baseTexture) {
  13887. _super.prototype.bind.call(this, baseTexture);
  13888. baseTexture.target = exports.TARGETS.TEXTURE_2D_ARRAY;
  13889. };
  13890. /**
  13891. * Upload the resources to the GPU.
  13892. * @param {PIXI.Renderer} renderer
  13893. * @param {PIXI.BaseTexture} texture
  13894. * @param {PIXI.GLTexture} glTexture
  13895. * @returns {boolean} whether texture was uploaded
  13896. */
  13897. ArrayResource.prototype.upload = function (renderer, texture, glTexture) {
  13898. var _a = this, length = _a.length, itemDirtyIds = _a.itemDirtyIds, items = _a.items;
  13899. var gl = renderer.gl;
  13900. if (glTexture.dirtyId < 0) {
  13901. gl.texImage3D(gl.TEXTURE_2D_ARRAY, 0, glTexture.internalFormat, this._width, this._height, length, 0, texture.format, glTexture.type, null);
  13902. }
  13903. for (var i = 0; i < length; i++) {
  13904. var item = items[i];
  13905. if (itemDirtyIds[i] < item.dirtyId) {
  13906. itemDirtyIds[i] = item.dirtyId;
  13907. if (item.valid) {
  13908. gl.texSubImage3D(gl.TEXTURE_2D_ARRAY, 0, 0, // xoffset
  13909. 0, // yoffset
  13910. i, // zoffset
  13911. item.resource.width, item.resource.height, 1, texture.format, glTexture.type, item.resource.source);
  13912. }
  13913. }
  13914. }
  13915. return true;
  13916. };
  13917. return ArrayResource;
  13918. }(AbstractMultiResource));
  13919. /**
  13920. * Base for all the image/canvas resources
  13921. * @class
  13922. * @extends PIXI.Resource
  13923. * @memberof PIXI
  13924. */
  13925. var BaseImageResource = /** @class */ (function (_super) {
  13926. __extends$2(BaseImageResource, _super);
  13927. /**
  13928. * @param {HTMLImageElement|HTMLCanvasElement|HTMLVideoElement|SVGElement} source
  13929. */
  13930. function BaseImageResource(source) {
  13931. var _this = this;
  13932. var sourceAny = source;
  13933. var width = sourceAny.naturalWidth || sourceAny.videoWidth || sourceAny.width;
  13934. var height = sourceAny.naturalHeight || sourceAny.videoHeight || sourceAny.height;
  13935. _this = _super.call(this, width, height) || this;
  13936. /**
  13937. * The source element
  13938. * @member {HTMLImageElement|HTMLCanvasElement|HTMLVideoElement|SVGElement}
  13939. * @readonly
  13940. */
  13941. _this.source = source;
  13942. /**
  13943. * If set to `true`, will force `texImage2D` over `texSubImage2D` for uploading.
  13944. * Certain types of media (e.g. video) using `texImage2D` is more performant.
  13945. * @member {boolean}
  13946. * @default false
  13947. * @private
  13948. */
  13949. _this.noSubImage = false;
  13950. return _this;
  13951. }
  13952. /**
  13953. * Set cross origin based detecting the url and the crossorigin
  13954. * @protected
  13955. * @param {HTMLElement} element - Element to apply crossOrigin
  13956. * @param {string} url - URL to check
  13957. * @param {boolean|string} [crossorigin=true] - Cross origin value to use
  13958. */
  13959. BaseImageResource.crossOrigin = function (element, url, crossorigin) {
  13960. if (crossorigin === undefined && url.indexOf('data:') !== 0) {
  13961. element.crossOrigin = determineCrossOrigin(url);
  13962. }
  13963. else if (crossorigin !== false) {
  13964. element.crossOrigin = typeof crossorigin === 'string' ? crossorigin : 'anonymous';
  13965. }
  13966. };
  13967. /**
  13968. * Upload the texture to the GPU.
  13969. * @param {PIXI.Renderer} renderer - Upload to the renderer
  13970. * @param {PIXI.BaseTexture} baseTexture - Reference to parent texture
  13971. * @param {PIXI.GLTexture} glTexture
  13972. * @param {HTMLImageElement|HTMLCanvasElement|HTMLVideoElement|SVGElement} [source] - (optional)
  13973. * @returns {boolean} true is success
  13974. */
  13975. BaseImageResource.prototype.upload = function (renderer, baseTexture, glTexture, source) {
  13976. var gl = renderer.gl;
  13977. var width = baseTexture.realWidth;
  13978. var height = baseTexture.realHeight;
  13979. source = source || this.source;
  13980. gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, baseTexture.alphaMode === exports.ALPHA_MODES.UNPACK);
  13981. if (!this.noSubImage
  13982. && baseTexture.target === gl.TEXTURE_2D
  13983. && glTexture.width === width
  13984. && glTexture.height === height) {
  13985. gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, baseTexture.format, glTexture.type, source);
  13986. }
  13987. else {
  13988. glTexture.width = width;
  13989. glTexture.height = height;
  13990. gl.texImage2D(baseTexture.target, 0, glTexture.internalFormat, baseTexture.format, glTexture.type, source);
  13991. }
  13992. return true;
  13993. };
  13994. /**
  13995. * Checks if source width/height was changed, resize can cause extra baseTexture update.
  13996. * Triggers one update in any case.
  13997. */
  13998. BaseImageResource.prototype.update = function () {
  13999. if (this.destroyed) {
  14000. return;
  14001. }
  14002. var source = this.source;
  14003. var width = source.naturalWidth || source.videoWidth || source.width;
  14004. var height = source.naturalHeight || source.videoHeight || source.height;
  14005. this.resize(width, height);
  14006. _super.prototype.update.call(this);
  14007. };
  14008. /**
  14009. * Destroy this BaseImageResource
  14010. * @override
  14011. */
  14012. BaseImageResource.prototype.dispose = function () {
  14013. this.source = null;
  14014. };
  14015. return BaseImageResource;
  14016. }(Resource));
  14017. /**
  14018. * @interface OffscreenCanvas
  14019. */
  14020. /**
  14021. * Resource type for HTMLCanvasElement.
  14022. * @class
  14023. * @extends PIXI.BaseImageResource
  14024. * @memberof PIXI
  14025. */
  14026. var CanvasResource = /** @class */ (function (_super) {
  14027. __extends$2(CanvasResource, _super);
  14028. /**
  14029. * @param {HTMLCanvasElement} source - Canvas element to use
  14030. */
  14031. // eslint-disable-next-line @typescript-eslint/no-useless-constructor
  14032. function CanvasResource(source) {
  14033. return _super.call(this, source) || this;
  14034. }
  14035. /**
  14036. * Used to auto-detect the type of resource.
  14037. *
  14038. * @static
  14039. * @param {HTMLCanvasElement|OffscreenCanvas} source - The source object
  14040. * @return {boolean} `true` if source is HTMLCanvasElement or OffscreenCanvas
  14041. */
  14042. CanvasResource.test = function (source) {
  14043. var OffscreenCanvas = self.OffscreenCanvas;
  14044. // Check for browsers that don't yet support OffscreenCanvas
  14045. if (OffscreenCanvas && source instanceof OffscreenCanvas) {
  14046. return true;
  14047. }
  14048. return self.HTMLCanvasElement && source instanceof HTMLCanvasElement;
  14049. };
  14050. return CanvasResource;
  14051. }(BaseImageResource));
  14052. /**
  14053. * Resource for a CubeTexture which contains six resources.
  14054. *
  14055. * @class
  14056. * @extends PIXI.ArrayResource
  14057. * @memberof PIXI
  14058. */
  14059. var CubeResource = /** @class */ (function (_super) {
  14060. __extends$2(CubeResource, _super);
  14061. /**
  14062. * @param {Array<string|PIXI.Resource>} [source] - Collection of URLs or resources
  14063. * to use as the sides of the cube.
  14064. * @param {object} [options] - ImageResource options
  14065. * @param {number} [options.width] - Width of resource
  14066. * @param {number} [options.height] - Height of resource
  14067. * @param {number} [options.autoLoad=true] - Whether to auto-load resources
  14068. * @param {number} [options.linkBaseTexture=true] - In case BaseTextures are supplied,
  14069. * whether to copy them or use
  14070. */
  14071. function CubeResource(source, options) {
  14072. var _this = this;
  14073. var _a = options || {}, width = _a.width, height = _a.height, autoLoad = _a.autoLoad, linkBaseTexture = _a.linkBaseTexture;
  14074. if (source && source.length !== CubeResource.SIDES) {
  14075. throw new Error("Invalid length. Got " + source.length + ", expected 6");
  14076. }
  14077. _this = _super.call(this, 6, { width: width, height: height }) || this;
  14078. for (var i = 0; i < CubeResource.SIDES; i++) {
  14079. _this.items[i].target = exports.TARGETS.TEXTURE_CUBE_MAP_POSITIVE_X + i;
  14080. }
  14081. /**
  14082. * In case BaseTextures are supplied, whether to use same resource or bind baseTexture itself
  14083. * @member {boolean}
  14084. * @protected
  14085. */
  14086. _this.linkBaseTexture = linkBaseTexture !== false;
  14087. if (source) {
  14088. _this.initFromArray(source, options);
  14089. }
  14090. if (autoLoad !== false) {
  14091. _this.load();
  14092. }
  14093. return _this;
  14094. }
  14095. /**
  14096. * Add binding
  14097. *
  14098. * @override
  14099. * @param {PIXI.BaseTexture} baseTexture - parent base texture
  14100. */
  14101. CubeResource.prototype.bind = function (baseTexture) {
  14102. _super.prototype.bind.call(this, baseTexture);
  14103. baseTexture.target = exports.TARGETS.TEXTURE_CUBE_MAP;
  14104. };
  14105. CubeResource.prototype.addBaseTextureAt = function (baseTexture, index, linkBaseTexture) {
  14106. if (linkBaseTexture === undefined) {
  14107. linkBaseTexture = this.linkBaseTexture;
  14108. }
  14109. if (!this.items[index]) {
  14110. throw new Error("Index " + index + " is out of bounds");
  14111. }
  14112. if (!this.linkBaseTexture
  14113. || baseTexture.parentTextureArray
  14114. || Object.keys(baseTexture._glTextures).length > 0) {
  14115. // copy mode
  14116. if (baseTexture.resource) {
  14117. this.addResourceAt(baseTexture.resource, index);
  14118. }
  14119. else {
  14120. throw new Error("CubeResource does not support copying of renderTexture.");
  14121. }
  14122. }
  14123. else {
  14124. // link mode, the difficult one!
  14125. baseTexture.target = exports.TARGETS.TEXTURE_CUBE_MAP_POSITIVE_X + index;
  14126. baseTexture.parentTextureArray = this.baseTexture;
  14127. this.items[index] = baseTexture;
  14128. }
  14129. if (baseTexture.valid && !this.valid) {
  14130. this.resize(baseTexture.realWidth, baseTexture.realHeight);
  14131. }
  14132. this.items[index] = baseTexture;
  14133. return this;
  14134. };
  14135. /**
  14136. * Upload the resource
  14137. *
  14138. * @returns {boolean} true is success
  14139. */
  14140. CubeResource.prototype.upload = function (renderer, _baseTexture, glTexture) {
  14141. var dirty = this.itemDirtyIds;
  14142. for (var i = 0; i < CubeResource.SIDES; i++) {
  14143. var side = this.items[i];
  14144. if (dirty[i] < side.dirtyId) {
  14145. if (side.valid && side.resource) {
  14146. side.resource.upload(renderer, side, glTexture);
  14147. dirty[i] = side.dirtyId;
  14148. }
  14149. else if (dirty[i] < -1) {
  14150. // either item is not valid yet, either its a renderTexture
  14151. // allocate the memory
  14152. renderer.gl.texImage2D(side.target, 0, glTexture.internalFormat, _baseTexture.realWidth, _baseTexture.realHeight, 0, _baseTexture.format, glTexture.type, null);
  14153. dirty[i] = -1;
  14154. }
  14155. }
  14156. }
  14157. return true;
  14158. };
  14159. /**
  14160. * Used to auto-detect the type of resource.
  14161. *
  14162. * @static
  14163. * @param {object} source - The source object
  14164. * @return {boolean} `true` if source is an array of 6 elements
  14165. */
  14166. CubeResource.test = function (source) {
  14167. return Array.isArray(source) && source.length === CubeResource.SIDES;
  14168. };
  14169. /**
  14170. * Number of texture sides to store for CubeResources
  14171. *
  14172. * @name PIXI.CubeResource.SIDES
  14173. * @static
  14174. * @member {number}
  14175. * @default 6
  14176. */
  14177. CubeResource.SIDES = 6;
  14178. return CubeResource;
  14179. }(AbstractMultiResource));
  14180. /**
  14181. * Resource type for HTMLImageElement.
  14182. * @class
  14183. * @extends PIXI.BaseImageResource
  14184. * @memberof PIXI
  14185. */
  14186. var ImageResource = /** @class */ (function (_super) {
  14187. __extends$2(ImageResource, _super);
  14188. /**
  14189. * @param {HTMLImageElement|string} source - image source or URL
  14190. * @param {object} [options]
  14191. * @param {boolean} [options.autoLoad=true] - start loading process
  14192. * @param {boolean} [options.createBitmap=PIXI.settings.CREATE_IMAGE_BITMAP] - whether its required to create
  14193. * a bitmap before upload
  14194. * @param {boolean} [options.crossorigin=true] - Load image using cross origin
  14195. * @param {PIXI.ALPHA_MODES} [options.alphaMode=PIXI.ALPHA_MODES.UNPACK] - Premultiply image alpha in bitmap
  14196. */
  14197. function ImageResource(source, options) {
  14198. var _this = this;
  14199. options = options || {};
  14200. if (!(source instanceof HTMLImageElement)) {
  14201. var imageElement = new Image();
  14202. BaseImageResource.crossOrigin(imageElement, source, options.crossorigin);
  14203. imageElement.src = source;
  14204. source = imageElement;
  14205. }
  14206. _this = _super.call(this, source) || this;
  14207. // FireFox 68, and possibly other versions, seems like setting the HTMLImageElement#width and #height
  14208. // to non-zero values before its loading completes if images are in a cache.
  14209. // Because of this, need to set the `_width` and the `_height` to zero to avoid uploading incomplete images.
  14210. // Please refer to the issue #5968 (https://github.com/pixijs/pixi.js/issues/5968).
  14211. if (!source.complete && !!_this._width && !!_this._height) {
  14212. _this._width = 0;
  14213. _this._height = 0;
  14214. }
  14215. /**
  14216. * URL of the image source
  14217. * @member {string}
  14218. */
  14219. _this.url = source.src;
  14220. /**
  14221. * When process is completed
  14222. * @member {Promise<void>}
  14223. * @private
  14224. */
  14225. _this._process = null;
  14226. /**
  14227. * If the image should be disposed after upload
  14228. * @member {boolean}
  14229. * @default false
  14230. */
  14231. _this.preserveBitmap = false;
  14232. /**
  14233. * If capable, convert the image using createImageBitmap API
  14234. * @member {boolean}
  14235. * @default PIXI.settings.CREATE_IMAGE_BITMAP
  14236. */
  14237. _this.createBitmap = (options.createBitmap !== undefined
  14238. ? options.createBitmap : settings.CREATE_IMAGE_BITMAP) && !!self.createImageBitmap;
  14239. /**
  14240. * Controls texture alphaMode field
  14241. * Copies from options
  14242. * Default is `null`, copies option from baseTexture
  14243. *
  14244. * @member {PIXI.ALPHA_MODES|null}
  14245. * @readonly
  14246. */
  14247. _this.alphaMode = typeof options.alphaMode === 'number' ? options.alphaMode : null;
  14248. /**
  14249. * The ImageBitmap element created for HTMLImageElement
  14250. * @member {ImageBitmap}
  14251. * @default null
  14252. */
  14253. _this.bitmap = null;
  14254. /**
  14255. * Promise when loading
  14256. * @member {Promise<void>}
  14257. * @private
  14258. * @default null
  14259. */
  14260. _this._load = null;
  14261. if (options.autoLoad !== false) {
  14262. _this.load();
  14263. }
  14264. return _this;
  14265. }
  14266. /**
  14267. * returns a promise when image will be loaded and processed
  14268. *
  14269. * @param {boolean} [createBitmap] - whether process image into bitmap
  14270. * @returns {Promise<void>}
  14271. */
  14272. ImageResource.prototype.load = function (createBitmap) {
  14273. var _this = this;
  14274. if (this._load) {
  14275. return this._load;
  14276. }
  14277. if (createBitmap !== undefined) {
  14278. this.createBitmap = createBitmap;
  14279. }
  14280. this._load = new Promise(function (resolve, reject) {
  14281. var source = _this.source;
  14282. _this.url = source.src;
  14283. var completed = function () {
  14284. if (_this.destroyed) {
  14285. return;
  14286. }
  14287. source.onload = null;
  14288. source.onerror = null;
  14289. _this.resize(source.width, source.height);
  14290. _this._load = null;
  14291. if (_this.createBitmap) {
  14292. resolve(_this.process());
  14293. }
  14294. else {
  14295. resolve(_this);
  14296. }
  14297. };
  14298. if (source.complete && source.src) {
  14299. completed();
  14300. }
  14301. else {
  14302. source.onload = completed;
  14303. source.onerror = function (event) {
  14304. // Avoids Promise freezing when resource broken
  14305. reject(event);
  14306. _this.onError.emit(event);
  14307. };
  14308. }
  14309. });
  14310. return this._load;
  14311. };
  14312. /**
  14313. * Called when we need to convert image into BitmapImage.
  14314. * Can be called multiple times, real promise is cached inside.
  14315. *
  14316. * @returns {Promise<void>} cached promise to fill that bitmap
  14317. */
  14318. ImageResource.prototype.process = function () {
  14319. var _this = this;
  14320. var source = this.source;
  14321. if (this._process !== null) {
  14322. return this._process;
  14323. }
  14324. if (this.bitmap !== null || !self.createImageBitmap) {
  14325. return Promise.resolve(this);
  14326. }
  14327. var createImageBitmap = self.createImageBitmap;
  14328. var cors = !source.crossOrigin || source.crossOrigin === 'anonymous';
  14329. this._process = fetch(source.src, {
  14330. mode: cors ? 'cors' : 'no-cors'
  14331. })
  14332. .then(function (r) { return r.blob(); })
  14333. .then(function (blob) { return createImageBitmap(blob, 0, 0, source.width, source.height, {
  14334. premultiplyAlpha: _this.alphaMode === exports.ALPHA_MODES.UNPACK ? 'premultiply' : 'none',
  14335. }); })
  14336. .then(function (bitmap) {
  14337. if (_this.destroyed) {
  14338. return Promise.reject();
  14339. }
  14340. _this.bitmap = bitmap;
  14341. _this.update();
  14342. _this._process = null;
  14343. return Promise.resolve(_this);
  14344. });
  14345. return this._process;
  14346. };
  14347. /**
  14348. * Upload the image resource to GPU.
  14349. *
  14350. * @param {PIXI.Renderer} renderer - Renderer to upload to
  14351. * @param {PIXI.BaseTexture} baseTexture - BaseTexture for this resource
  14352. * @param {PIXI.GLTexture} glTexture - GLTexture to use
  14353. * @returns {boolean} true is success
  14354. */
  14355. ImageResource.prototype.upload = function (renderer, baseTexture, glTexture) {
  14356. if (typeof this.alphaMode === 'number') {
  14357. // bitmap stores unpack premultiply flag, we dont have to notify texImage2D about it
  14358. baseTexture.alphaMode = this.alphaMode;
  14359. }
  14360. if (!this.createBitmap) {
  14361. return _super.prototype.upload.call(this, renderer, baseTexture, glTexture);
  14362. }
  14363. if (!this.bitmap) {
  14364. // yeah, ignore the output
  14365. this.process();
  14366. if (!this.bitmap) {
  14367. return false;
  14368. }
  14369. }
  14370. _super.prototype.upload.call(this, renderer, baseTexture, glTexture, this.bitmap);
  14371. if (!this.preserveBitmap) {
  14372. // checks if there are other renderers that possibly need this bitmap
  14373. var flag = true;
  14374. var glTextures = baseTexture._glTextures;
  14375. for (var key in glTextures) {
  14376. var otherTex = glTextures[key];
  14377. if (otherTex !== glTexture && otherTex.dirtyId !== baseTexture.dirtyId) {
  14378. flag = false;
  14379. break;
  14380. }
  14381. }
  14382. if (flag) {
  14383. if (this.bitmap.close) {
  14384. this.bitmap.close();
  14385. }
  14386. this.bitmap = null;
  14387. }
  14388. }
  14389. return true;
  14390. };
  14391. /**
  14392. * Destroys this texture
  14393. * @override
  14394. */
  14395. ImageResource.prototype.dispose = function () {
  14396. this.source.onload = null;
  14397. this.source.onerror = null;
  14398. _super.prototype.dispose.call(this);
  14399. if (this.bitmap) {
  14400. this.bitmap.close();
  14401. this.bitmap = null;
  14402. }
  14403. this._process = null;
  14404. this._load = null;
  14405. };
  14406. /**
  14407. * Used to auto-detect the type of resource.
  14408. *
  14409. * @static
  14410. * @param {string|HTMLImageElement} source - The source object
  14411. * @return {boolean} `true` if source is string or HTMLImageElement
  14412. */
  14413. ImageResource.test = function (source) {
  14414. return typeof source === 'string' || source instanceof HTMLImageElement;
  14415. };
  14416. return ImageResource;
  14417. }(BaseImageResource));
  14418. /**
  14419. * Resource type for SVG elements and graphics.
  14420. * @class
  14421. * @extends PIXI.BaseImageResource
  14422. * @memberof PIXI
  14423. */
  14424. var SVGResource = /** @class */ (function (_super) {
  14425. __extends$2(SVGResource, _super);
  14426. /**
  14427. * @param {string} source - Base64 encoded SVG element or URL for SVG file.
  14428. * @param {object} [options] - Options to use
  14429. * @param {number} [options.scale=1] - Scale to apply to SVG. Overridden by...
  14430. * @param {number} [options.width] - Rasterize SVG this wide. Aspect ratio preserved if height not specified.
  14431. * @param {number} [options.height] - Rasterize SVG this high. Aspect ratio preserved if width not specified.
  14432. * @param {boolean} [options.autoLoad=true] - Start loading right away.
  14433. */
  14434. function SVGResource(sourceBase64, options) {
  14435. var _this = this;
  14436. options = options || {};
  14437. _this = _super.call(this, document.createElement('canvas')) || this;
  14438. _this._width = 0;
  14439. _this._height = 0;
  14440. /**
  14441. * Base64 encoded SVG element or URL for SVG file
  14442. * @readonly
  14443. * @member {string}
  14444. */
  14445. _this.svg = sourceBase64;
  14446. /**
  14447. * The source scale to apply when rasterizing on load
  14448. * @readonly
  14449. * @member {number}
  14450. */
  14451. _this.scale = options.scale || 1;
  14452. /**
  14453. * A width override for rasterization on load
  14454. * @readonly
  14455. * @member {number}
  14456. */
  14457. _this._overrideWidth = options.width;
  14458. /**
  14459. * A height override for rasterization on load
  14460. * @readonly
  14461. * @member {number}
  14462. */
  14463. _this._overrideHeight = options.height;
  14464. /**
  14465. * Call when completely loaded
  14466. * @private
  14467. * @member {function}
  14468. */
  14469. _this._resolve = null;
  14470. /**
  14471. * Cross origin value to use
  14472. * @private
  14473. * @member {boolean|string}
  14474. */
  14475. _this._crossorigin = options.crossorigin;
  14476. /**
  14477. * Promise when loading
  14478. * @member {Promise<void>}
  14479. * @private
  14480. * @default null
  14481. */
  14482. _this._load = null;
  14483. if (options.autoLoad !== false) {
  14484. _this.load();
  14485. }
  14486. return _this;
  14487. }
  14488. SVGResource.prototype.load = function () {
  14489. var _this = this;
  14490. if (this._load) {
  14491. return this._load;
  14492. }
  14493. this._load = new Promise(function (resolve) {
  14494. // Save this until after load is finished
  14495. _this._resolve = function () {
  14496. _this.resize(_this.source.width, _this.source.height);
  14497. resolve(_this);
  14498. };
  14499. // Convert SVG inline string to data-uri
  14500. if ((/^\<svg/).test(_this.svg.trim())) {
  14501. if (!btoa) {
  14502. throw new Error('Your browser doesn\'t support base64 conversions.');
  14503. }
  14504. _this.svg = "data:image/svg+xml;base64," + btoa(unescape(encodeURIComponent(_this.svg)));
  14505. }
  14506. _this._loadSvg();
  14507. });
  14508. return this._load;
  14509. };
  14510. /**
  14511. * Loads an SVG image from `imageUrl` or `data URL`.
  14512. *
  14513. * @private
  14514. */
  14515. SVGResource.prototype._loadSvg = function () {
  14516. var _this = this;
  14517. var tempImage = new Image();
  14518. BaseImageResource.crossOrigin(tempImage, this.svg, this._crossorigin);
  14519. tempImage.src = this.svg;
  14520. tempImage.onerror = function (event) {
  14521. if (!_this._resolve) {
  14522. return;
  14523. }
  14524. tempImage.onerror = null;
  14525. _this.onError.emit(event);
  14526. };
  14527. tempImage.onload = function () {
  14528. if (!_this._resolve) {
  14529. return;
  14530. }
  14531. var svgWidth = tempImage.width;
  14532. var svgHeight = tempImage.height;
  14533. if (!svgWidth || !svgHeight) {
  14534. throw new Error('The SVG image must have width and height defined (in pixels), canvas API needs them.');
  14535. }
  14536. // Set render size
  14537. var width = svgWidth * _this.scale;
  14538. var height = svgHeight * _this.scale;
  14539. if (_this._overrideWidth || _this._overrideHeight) {
  14540. width = _this._overrideWidth || _this._overrideHeight / svgHeight * svgWidth;
  14541. height = _this._overrideHeight || _this._overrideWidth / svgWidth * svgHeight;
  14542. }
  14543. width = Math.round(width);
  14544. height = Math.round(height);
  14545. // Create a canvas element
  14546. var canvas = _this.source;
  14547. canvas.width = width;
  14548. canvas.height = height;
  14549. canvas._pixiId = "canvas_" + uid();
  14550. // Draw the Svg to the canvas
  14551. canvas
  14552. .getContext('2d')
  14553. .drawImage(tempImage, 0, 0, svgWidth, svgHeight, 0, 0, width, height);
  14554. _this._resolve();
  14555. _this._resolve = null;
  14556. };
  14557. };
  14558. /**
  14559. * Get size from an svg string using regexp.
  14560. *
  14561. * @method
  14562. * @param {string} svgString - a serialized svg element
  14563. * @return {PIXI.ISize} image extension
  14564. */
  14565. SVGResource.getSize = function (svgString) {
  14566. var sizeMatch = SVGResource.SVG_SIZE.exec(svgString);
  14567. var size = {};
  14568. if (sizeMatch) {
  14569. size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3]));
  14570. size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7]));
  14571. }
  14572. return size;
  14573. };
  14574. /**
  14575. * Destroys this texture
  14576. * @override
  14577. */
  14578. SVGResource.prototype.dispose = function () {
  14579. _super.prototype.dispose.call(this);
  14580. this._resolve = null;
  14581. this._crossorigin = null;
  14582. };
  14583. /**
  14584. * Used to auto-detect the type of resource.
  14585. *
  14586. * @static
  14587. * @param {*} source - The source object
  14588. * @param {string} extension - The extension of source, if set
  14589. */
  14590. SVGResource.test = function (source, extension) {
  14591. // url file extension is SVG
  14592. return extension === 'svg'
  14593. // source is SVG data-uri
  14594. || (typeof source === 'string' && (/^data:image\/svg\+xml(;(charset=utf8|utf8))?;base64/).test(source))
  14595. // source is SVG inline
  14596. || (typeof source === 'string' && SVGResource.SVG_XML.test(source));
  14597. };
  14598. /**
  14599. * RegExp for SVG XML document.
  14600. *
  14601. * @example &lt;?xml version="1.0" encoding="utf-8" ?&gt;&lt;!-- image/svg --&gt;&lt;svg
  14602. */
  14603. SVGResource.SVG_XML = /^(<\?xml[^?]+\?>)?\s*(<!--[^(-->)]*-->)?\s*\<svg/m;
  14604. /**
  14605. * RegExp for SVG size.
  14606. *
  14607. * @static
  14608. * @constant {RegExp|string} SVG_SIZE
  14609. * @memberof PIXI.SVGResource
  14610. * @example &lt;svg width="100" height="100"&gt;&lt;/svg&gt;
  14611. */
  14612. SVGResource.SVG_SIZE = /<svg[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len
  14613. return SVGResource;
  14614. }(BaseImageResource));
  14615. /**
  14616. * Resource type for HTMLVideoElement.
  14617. * @class
  14618. * @extends PIXI.BaseImageResource
  14619. * @memberof PIXI
  14620. */
  14621. var VideoResource = /** @class */ (function (_super) {
  14622. __extends$2(VideoResource, _super);
  14623. /**
  14624. * @param {HTMLVideoElement|object|string|Array<string|object>} source - Video element to use.
  14625. * @param {object} [options] - Options to use
  14626. * @param {boolean} [options.autoLoad=true] - Start loading the video immediately
  14627. * @param {boolean} [options.autoPlay=true] - Start playing video immediately
  14628. * @param {number} [options.updateFPS=0] - How many times a second to update the texture from the video.
  14629. * Leave at 0 to update at every render.
  14630. * @param {boolean} [options.crossorigin=true] - Load image using cross origin
  14631. */
  14632. function VideoResource(source, options) {
  14633. var _this = this;
  14634. options = options || {};
  14635. if (!(source instanceof HTMLVideoElement)) {
  14636. var videoElement = document.createElement('video');
  14637. // workaround for https://github.com/pixijs/pixi.js/issues/5996
  14638. videoElement.setAttribute('preload', 'auto');
  14639. videoElement.setAttribute('webkit-playsinline', '');
  14640. videoElement.setAttribute('playsinline', '');
  14641. if (typeof source === 'string') {
  14642. source = [source];
  14643. }
  14644. var firstSrc = source[0].src || source[0];
  14645. BaseImageResource.crossOrigin(videoElement, firstSrc, options.crossorigin);
  14646. // array of objects or strings
  14647. for (var i = 0; i < source.length; ++i) {
  14648. var sourceElement = document.createElement('source');
  14649. var _a = source[i], src = _a.src, mime = _a.mime;
  14650. src = src || source[i];
  14651. var baseSrc = src.split('?').shift().toLowerCase();
  14652. var ext = baseSrc.substr(baseSrc.lastIndexOf('.') + 1);
  14653. mime = mime || VideoResource.MIME_TYPES[ext] || "video/" + ext;
  14654. sourceElement.src = src;
  14655. sourceElement.type = mime;
  14656. videoElement.appendChild(sourceElement);
  14657. }
  14658. // Override the source
  14659. source = videoElement;
  14660. }
  14661. _this = _super.call(this, source) || this;
  14662. _this.noSubImage = true;
  14663. /**
  14664. * `true` to use PIXI.Ticker.shared to auto update the base texture.
  14665. *
  14666. * @type {boolean}
  14667. * @default true
  14668. * @private
  14669. */
  14670. _this._autoUpdate = true;
  14671. /**
  14672. * `true` if the instance is currently connected to PIXI.Ticker.shared to auto update the base texture.
  14673. *
  14674. * @type {boolean}
  14675. * @default false
  14676. * @private
  14677. */
  14678. _this._isConnectedToTicker = false;
  14679. _this._updateFPS = options.updateFPS || 0;
  14680. _this._msToNextUpdate = 0;
  14681. /**
  14682. * When set to true will automatically play videos used by this texture once
  14683. * they are loaded. If false, it will not modify the playing state.
  14684. *
  14685. * @member {boolean}
  14686. * @default true
  14687. */
  14688. _this.autoPlay = options.autoPlay !== false;
  14689. /**
  14690. * Promise when loading
  14691. * @member {Promise<void>}
  14692. * @private
  14693. * @default null
  14694. */
  14695. _this._load = null;
  14696. /**
  14697. * Callback when completed with load.
  14698. * @member {function}
  14699. * @private
  14700. */
  14701. _this._resolve = null;
  14702. // Bind for listeners
  14703. _this._onCanPlay = _this._onCanPlay.bind(_this);
  14704. _this._onError = _this._onError.bind(_this);
  14705. if (options.autoLoad !== false) {
  14706. _this.load();
  14707. }
  14708. return _this;
  14709. }
  14710. /**
  14711. * Trigger updating of the texture
  14712. *
  14713. * @param {number} [deltaTime=0] - time delta since last tick
  14714. */
  14715. VideoResource.prototype.update = function (_deltaTime) {
  14716. if (!this.destroyed) {
  14717. // account for if video has had its playbackRate changed
  14718. var elapsedMS = Ticker.shared.elapsedMS * this.source.playbackRate;
  14719. this._msToNextUpdate = Math.floor(this._msToNextUpdate - elapsedMS);
  14720. if (!this._updateFPS || this._msToNextUpdate <= 0) {
  14721. _super.prototype.update.call(this);
  14722. this._msToNextUpdate = this._updateFPS ? Math.floor(1000 / this._updateFPS) : 0;
  14723. }
  14724. }
  14725. };
  14726. /**
  14727. * Start preloading the video resource.
  14728. *
  14729. * @protected
  14730. * @return {Promise<void>} Handle the validate event
  14731. */
  14732. VideoResource.prototype.load = function () {
  14733. var _this = this;
  14734. if (this._load) {
  14735. return this._load;
  14736. }
  14737. var source = this.source;
  14738. if ((source.readyState === source.HAVE_ENOUGH_DATA || source.readyState === source.HAVE_FUTURE_DATA)
  14739. && source.width && source.height) {
  14740. source.complete = true;
  14741. }
  14742. source.addEventListener('play', this._onPlayStart.bind(this));
  14743. source.addEventListener('pause', this._onPlayStop.bind(this));
  14744. if (!this._isSourceReady()) {
  14745. source.addEventListener('canplay', this._onCanPlay);
  14746. source.addEventListener('canplaythrough', this._onCanPlay);
  14747. source.addEventListener('error', this._onError, true);
  14748. }
  14749. else {
  14750. this._onCanPlay();
  14751. }
  14752. this._load = new Promise(function (resolve) {
  14753. if (_this.valid) {
  14754. resolve(_this);
  14755. }
  14756. else {
  14757. _this._resolve = resolve;
  14758. source.load();
  14759. }
  14760. });
  14761. return this._load;
  14762. };
  14763. /**
  14764. * Handle video error events.
  14765. *
  14766. * @private
  14767. */
  14768. VideoResource.prototype._onError = function (event) {
  14769. this.source.removeEventListener('error', this._onError, true);
  14770. this.onError.emit(event);
  14771. };
  14772. /**
  14773. * Returns true if the underlying source is playing.
  14774. *
  14775. * @private
  14776. * @return {boolean} True if playing.
  14777. */
  14778. VideoResource.prototype._isSourcePlaying = function () {
  14779. var source = this.source;
  14780. return (source.currentTime > 0 && source.paused === false && source.ended === false && source.readyState > 2);
  14781. };
  14782. /**
  14783. * Returns true if the underlying source is ready for playing.
  14784. *
  14785. * @private
  14786. * @return {boolean} True if ready.
  14787. */
  14788. VideoResource.prototype._isSourceReady = function () {
  14789. var source = this.source;
  14790. return source.readyState === 3 || source.readyState === 4;
  14791. };
  14792. /**
  14793. * Runs the update loop when the video is ready to play
  14794. *
  14795. * @private
  14796. */
  14797. VideoResource.prototype._onPlayStart = function () {
  14798. // Just in case the video has not received its can play even yet..
  14799. if (!this.valid) {
  14800. this._onCanPlay();
  14801. }
  14802. if (this.autoUpdate && !this._isConnectedToTicker) {
  14803. Ticker.shared.add(this.update, this);
  14804. this._isConnectedToTicker = true;
  14805. }
  14806. };
  14807. /**
  14808. * Fired when a pause event is triggered, stops the update loop
  14809. *
  14810. * @private
  14811. */
  14812. VideoResource.prototype._onPlayStop = function () {
  14813. if (this._isConnectedToTicker) {
  14814. Ticker.shared.remove(this.update, this);
  14815. this._isConnectedToTicker = false;
  14816. }
  14817. };
  14818. /**
  14819. * Fired when the video is loaded and ready to play
  14820. *
  14821. * @private
  14822. */
  14823. VideoResource.prototype._onCanPlay = function () {
  14824. var source = this.source;
  14825. source.removeEventListener('canplay', this._onCanPlay);
  14826. source.removeEventListener('canplaythrough', this._onCanPlay);
  14827. var valid = this.valid;
  14828. this.resize(source.videoWidth, source.videoHeight);
  14829. // prevent multiple loaded dispatches..
  14830. if (!valid && this._resolve) {
  14831. this._resolve(this);
  14832. this._resolve = null;
  14833. }
  14834. if (this._isSourcePlaying()) {
  14835. this._onPlayStart();
  14836. }
  14837. else if (this.autoPlay) {
  14838. source.play();
  14839. }
  14840. };
  14841. /**
  14842. * Destroys this texture
  14843. * @override
  14844. */
  14845. VideoResource.prototype.dispose = function () {
  14846. if (this._isConnectedToTicker) {
  14847. Ticker.shared.remove(this.update, this);
  14848. this._isConnectedToTicker = false;
  14849. }
  14850. var source = this.source;
  14851. if (source) {
  14852. source.removeEventListener('error', this._onError, true);
  14853. source.pause();
  14854. source.src = '';
  14855. source.load();
  14856. }
  14857. _super.prototype.dispose.call(this);
  14858. };
  14859. Object.defineProperty(VideoResource.prototype, "autoUpdate", {
  14860. /**
  14861. * Should the base texture automatically update itself, set to true by default
  14862. *
  14863. * @member {boolean}
  14864. */
  14865. get: function () {
  14866. return this._autoUpdate;
  14867. },
  14868. set: function (value) {
  14869. if (value !== this._autoUpdate) {
  14870. this._autoUpdate = value;
  14871. if (!this._autoUpdate && this._isConnectedToTicker) {
  14872. Ticker.shared.remove(this.update, this);
  14873. this._isConnectedToTicker = false;
  14874. }
  14875. else if (this._autoUpdate && !this._isConnectedToTicker && this._isSourcePlaying()) {
  14876. Ticker.shared.add(this.update, this);
  14877. this._isConnectedToTicker = true;
  14878. }
  14879. }
  14880. },
  14881. enumerable: false,
  14882. configurable: true
  14883. });
  14884. Object.defineProperty(VideoResource.prototype, "updateFPS", {
  14885. /**
  14886. * How many times a second to update the texture from the video. Leave at 0 to update at every render.
  14887. * A lower fps can help performance, as updating the texture at 60fps on a 30ps video may not be efficient.
  14888. *
  14889. * @member {number}
  14890. */
  14891. get: function () {
  14892. return this._updateFPS;
  14893. },
  14894. set: function (value) {
  14895. if (value !== this._updateFPS) {
  14896. this._updateFPS = value;
  14897. }
  14898. },
  14899. enumerable: false,
  14900. configurable: true
  14901. });
  14902. /**
  14903. * Used to auto-detect the type of resource.
  14904. *
  14905. * @static
  14906. * @param {*} source - The source object
  14907. * @param {string} extension - The extension of source, if set
  14908. * @return {boolean} `true` if video source
  14909. */
  14910. VideoResource.test = function (source, extension) {
  14911. return (self.HTMLVideoElement && source instanceof HTMLVideoElement)
  14912. || VideoResource.TYPES.indexOf(extension) > -1;
  14913. };
  14914. /**
  14915. * List of common video file extensions supported by VideoResource.
  14916. * @constant
  14917. * @member {Array<string>}
  14918. * @static
  14919. * @readonly
  14920. */
  14921. VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov'];
  14922. /**
  14923. * Map of video MIME types that can't be directly derived from file extensions.
  14924. * @constant
  14925. * @member {object}
  14926. * @static
  14927. * @readonly
  14928. */
  14929. VideoResource.MIME_TYPES = {
  14930. ogv: 'video/ogg',
  14931. mov: 'video/quicktime',
  14932. m4v: 'video/mp4',
  14933. };
  14934. return VideoResource;
  14935. }(BaseImageResource));
  14936. /**
  14937. * Resource type for ImageBitmap.
  14938. * @class
  14939. * @extends PIXI.BaseImageResource
  14940. * @memberof PIXI
  14941. */
  14942. var ImageBitmapResource = /** @class */ (function (_super) {
  14943. __extends$2(ImageBitmapResource, _super);
  14944. /**
  14945. * @param {ImageBitmap} source - Image element to use
  14946. */
  14947. // eslint-disable-next-line @typescript-eslint/no-useless-constructor
  14948. function ImageBitmapResource(source) {
  14949. return _super.call(this, source) || this;
  14950. }
  14951. /**
  14952. * Used to auto-detect the type of resource.
  14953. *
  14954. * @static
  14955. * @param {ImageBitmap} source - The source object
  14956. * @return {boolean} `true` if source is an ImageBitmap
  14957. */
  14958. ImageBitmapResource.test = function (source) {
  14959. return !!self.createImageBitmap && source instanceof ImageBitmap;
  14960. };
  14961. return ImageBitmapResource;
  14962. }(BaseImageResource));
  14963. INSTALLED.push(ImageResource, ImageBitmapResource, CanvasResource, VideoResource, SVGResource, BufferResource, CubeResource, ArrayResource);
  14964. var _resources = {
  14965. __proto__: null,
  14966. Resource: Resource,
  14967. BaseImageResource: BaseImageResource,
  14968. INSTALLED: INSTALLED,
  14969. autoDetectResource: autoDetectResource,
  14970. AbstractMultiResource: AbstractMultiResource,
  14971. ArrayResource: ArrayResource,
  14972. BufferResource: BufferResource,
  14973. CanvasResource: CanvasResource,
  14974. CubeResource: CubeResource,
  14975. ImageResource: ImageResource,
  14976. SVGResource: SVGResource,
  14977. VideoResource: VideoResource,
  14978. ImageBitmapResource: ImageBitmapResource
  14979. };
  14980. /**
  14981. * Resource type for DepthTexture.
  14982. * @class
  14983. * @extends PIXI.BufferResource
  14984. * @memberof PIXI
  14985. */
  14986. var DepthResource = /** @class */ (function (_super) {
  14987. __extends$2(DepthResource, _super);
  14988. function DepthResource() {
  14989. return _super !== null && _super.apply(this, arguments) || this;
  14990. }
  14991. /**
  14992. * Upload the texture to the GPU.
  14993. * @param {PIXI.Renderer} renderer - Upload to the renderer
  14994. * @param {PIXI.BaseTexture} baseTexture - Reference to parent texture
  14995. * @param {PIXI.GLTexture} glTexture - glTexture
  14996. * @returns {boolean} true is success
  14997. */
  14998. DepthResource.prototype.upload = function (renderer, baseTexture, glTexture) {
  14999. var gl = renderer.gl;
  15000. gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, baseTexture.alphaMode === exports.ALPHA_MODES.UNPACK);
  15001. var width = baseTexture.realWidth;
  15002. var height = baseTexture.realHeight;
  15003. if (glTexture.width === width && glTexture.height === height) {
  15004. gl.texSubImage2D(baseTexture.target, 0, 0, 0, width, height, baseTexture.format, glTexture.type, this.data);
  15005. }
  15006. else {
  15007. glTexture.width = width;
  15008. glTexture.height = height;
  15009. gl.texImage2D(baseTexture.target, 0, glTexture.internalFormat, width, height, 0, baseTexture.format, glTexture.type, this.data);
  15010. }
  15011. return true;
  15012. };
  15013. return DepthResource;
  15014. }(BufferResource));
  15015. /**
  15016. * A framebuffer can be used to render contents off of the screen. {@link PIXI.BaseRenderTexture} uses
  15017. * one internally to render into itself. You can attach a depth or stencil buffer to a framebuffer.
  15018. *
  15019. * On WebGL 2 machines, shaders can output to multiple textures simultaneously with GLSL 300 ES.
  15020. *
  15021. * @class
  15022. * @memberof PIXI
  15023. */
  15024. var Framebuffer = /** @class */ (function () {
  15025. /**
  15026. * @param {number} width - Width of the frame buffer
  15027. * @param {number} height - Height of the frame buffer
  15028. */
  15029. function Framebuffer(width, height) {
  15030. /**
  15031. * Width of framebuffer in pixels
  15032. * @member {number}
  15033. */
  15034. this.width = Math.round(width || 100);
  15035. /**
  15036. * Height of framebuffer in pixels
  15037. * @member {number}
  15038. */
  15039. this.height = Math.round(height || 100);
  15040. this.stencil = false;
  15041. this.depth = false;
  15042. this.dirtyId = 0;
  15043. this.dirtyFormat = 0;
  15044. this.dirtySize = 0;
  15045. this.depthTexture = null;
  15046. this.colorTextures = [];
  15047. this.glFramebuffers = {};
  15048. this.disposeRunner = new Runner('disposeFramebuffer');
  15049. /**
  15050. * Desired number of samples for antialiasing. 0 means AA should not be used.
  15051. *
  15052. * Experimental WebGL2 feature, allows to use antialiasing in individual renderTextures.
  15053. * Antialiasing is the same as for main buffer with renderer `antialias:true` options.
  15054. * Seriously affects GPU memory consumption and GPU performance.
  15055. *
  15056. *```js
  15057. * renderTexture.framebuffer.multisample = PIXI.MSAA_QUALITY.HIGH;
  15058. * //...
  15059. * renderer.render(myContainer, {renderTexture});
  15060. * renderer.framebuffer.blit(); // copies data from MSAA framebuffer to texture
  15061. * ```
  15062. *
  15063. * @member {PIXI.MSAA_QUALITY}
  15064. * @default PIXI.MSAA_QUALITY.NONE
  15065. */
  15066. this.multisample = exports.MSAA_QUALITY.NONE;
  15067. }
  15068. Object.defineProperty(Framebuffer.prototype, "colorTexture", {
  15069. /**
  15070. * Reference to the colorTexture.
  15071. *
  15072. * @member {PIXI.BaseTexture[]}
  15073. * @readonly
  15074. */
  15075. get: function () {
  15076. return this.colorTextures[0];
  15077. },
  15078. enumerable: false,
  15079. configurable: true
  15080. });
  15081. /**
  15082. * Add texture to the colorTexture array
  15083. *
  15084. * @param {number} [index=0] - Index of the array to add the texture to
  15085. * @param {PIXI.BaseTexture} [texture] - Texture to add to the array
  15086. */
  15087. Framebuffer.prototype.addColorTexture = function (index, texture) {
  15088. if (index === void 0) { index = 0; }
  15089. // TODO add some validation to the texture - same width / height etc?
  15090. this.colorTextures[index] = texture || new BaseTexture(null, {
  15091. scaleMode: exports.SCALE_MODES.NEAREST,
  15092. resolution: 1,
  15093. mipmap: exports.MIPMAP_MODES.OFF,
  15094. width: this.width,
  15095. height: this.height,
  15096. });
  15097. this.dirtyId++;
  15098. this.dirtyFormat++;
  15099. return this;
  15100. };
  15101. /**
  15102. * Add a depth texture to the frame buffer
  15103. *
  15104. * @param {PIXI.BaseTexture} [texture] - Texture to add
  15105. */
  15106. Framebuffer.prototype.addDepthTexture = function (texture) {
  15107. /* eslint-disable max-len */
  15108. this.depthTexture = texture || new BaseTexture(new DepthResource(null, { width: this.width, height: this.height }), {
  15109. scaleMode: exports.SCALE_MODES.NEAREST,
  15110. resolution: 1,
  15111. width: this.width,
  15112. height: this.height,
  15113. mipmap: exports.MIPMAP_MODES.OFF,
  15114. format: exports.FORMATS.DEPTH_COMPONENT,
  15115. type: exports.TYPES.UNSIGNED_SHORT,
  15116. });
  15117. this.dirtyId++;
  15118. this.dirtyFormat++;
  15119. return this;
  15120. };
  15121. /**
  15122. * Enable depth on the frame buffer
  15123. */
  15124. Framebuffer.prototype.enableDepth = function () {
  15125. this.depth = true;
  15126. this.dirtyId++;
  15127. this.dirtyFormat++;
  15128. return this;
  15129. };
  15130. /**
  15131. * Enable stencil on the frame buffer
  15132. */
  15133. Framebuffer.prototype.enableStencil = function () {
  15134. this.stencil = true;
  15135. this.dirtyId++;
  15136. this.dirtyFormat++;
  15137. return this;
  15138. };
  15139. /**
  15140. * Resize the frame buffer
  15141. *
  15142. * @param {number} width - Width of the frame buffer to resize to
  15143. * @param {number} height - Height of the frame buffer to resize to
  15144. */
  15145. Framebuffer.prototype.resize = function (width, height) {
  15146. width = Math.round(width);
  15147. height = Math.round(height);
  15148. if (width === this.width && height === this.height)
  15149. { return; }
  15150. this.width = width;
  15151. this.height = height;
  15152. this.dirtyId++;
  15153. this.dirtySize++;
  15154. for (var i = 0; i < this.colorTextures.length; i++) {
  15155. var texture = this.colorTextures[i];
  15156. var resolution = texture.resolution;
  15157. // take into account the fact the texture may have a different resolution..
  15158. texture.setSize(width / resolution, height / resolution);
  15159. }
  15160. if (this.depthTexture) {
  15161. var resolution = this.depthTexture.resolution;
  15162. this.depthTexture.setSize(width / resolution, height / resolution);
  15163. }
  15164. };
  15165. /**
  15166. * Disposes WebGL resources that are connected to this geometry
  15167. */
  15168. Framebuffer.prototype.dispose = function () {
  15169. this.disposeRunner.emit(this, false);
  15170. };
  15171. /**
  15172. * Destroys and removes the depth texture added to this framebuffer.
  15173. */
  15174. Framebuffer.prototype.destroyDepthTexture = function () {
  15175. if (this.depthTexture) {
  15176. this.depthTexture.destroy();
  15177. this.depthTexture = null;
  15178. ++this.dirtyId;
  15179. ++this.dirtyFormat;
  15180. }
  15181. };
  15182. return Framebuffer;
  15183. }());
  15184. /**
  15185. * A BaseRenderTexture is a special texture that allows any PixiJS display object to be rendered to it.
  15186. *
  15187. * __Hint__: All DisplayObjects (i.e. Sprites) that render to a BaseRenderTexture should be preloaded
  15188. * otherwise black rectangles will be drawn instead.
  15189. *
  15190. * A BaseRenderTexture takes a snapshot of any Display Object given to its render method. The position
  15191. * and rotation of the given Display Objects is ignored. For example:
  15192. *
  15193. * ```js
  15194. * let renderer = PIXI.autoDetectRenderer();
  15195. * let baseRenderTexture = new PIXI.BaseRenderTexture({ width: 800, height: 600 });
  15196. * let renderTexture = new PIXI.RenderTexture(baseRenderTexture);
  15197. * let sprite = PIXI.Sprite.from("spinObj_01.png");
  15198. *
  15199. * sprite.position.x = 800/2;
  15200. * sprite.position.y = 600/2;
  15201. * sprite.anchor.x = 0.5;
  15202. * sprite.anchor.y = 0.5;
  15203. *
  15204. * renderer.render(sprite, {renderTexture});
  15205. * ```
  15206. *
  15207. * The Sprite in this case will be rendered using its local transform. To render this sprite at 0,0
  15208. * you can clear the transform
  15209. *
  15210. * ```js
  15211. *
  15212. * sprite.setTransform()
  15213. *
  15214. * let baseRenderTexture = new PIXI.BaseRenderTexture({ width: 100, height: 100 });
  15215. * let renderTexture = new PIXI.RenderTexture(baseRenderTexture);
  15216. *
  15217. * renderer.render(sprite, {renderTexture}); // Renders to center of RenderTexture
  15218. * ```
  15219. *
  15220. * @class
  15221. * @extends PIXI.BaseTexture
  15222. * @memberof PIXI
  15223. */
  15224. var BaseRenderTexture = /** @class */ (function (_super) {
  15225. __extends$2(BaseRenderTexture, _super);
  15226. /**
  15227. * @param {object} [options]
  15228. * @param {number} [options.width=100] - The width of the base render texture.
  15229. * @param {number} [options.height=100] - The height of the base render texture.
  15230. * @param {PIXI.SCALE_MODES} [options.scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES}
  15231. * for possible values.
  15232. * @param {number} [options.resolution=PIXI.settings.RESOLUTION] - The resolution / device pixel ratio
  15233. * of the texture being generated.
  15234. * @param {PIXI.MSAA_QUALITY} [options.multisample=PIXI.MSAA_QUALITY.NONE] - The number of samples of the frame buffer.
  15235. */
  15236. function BaseRenderTexture(options) {
  15237. var _this = this;
  15238. if (typeof options === 'number') {
  15239. /* eslint-disable prefer-rest-params */
  15240. // Backward compatibility of signature
  15241. var width = arguments[0];
  15242. var height = arguments[1];
  15243. var scaleMode = arguments[2];
  15244. var resolution = arguments[3];
  15245. options = { width: width, height: height, scaleMode: scaleMode, resolution: resolution };
  15246. /* eslint-enable prefer-rest-params */
  15247. }
  15248. options.width = options.width || 100;
  15249. options.height = options.height || 100;
  15250. options.multisample = options.multisample !== undefined ? options.multisample : exports.MSAA_QUALITY.NONE;
  15251. _this = _super.call(this, null, options) || this;
  15252. // Set defaults
  15253. _this.mipmap = exports.MIPMAP_MODES.OFF;
  15254. _this.valid = true;
  15255. _this.clearColor = [0, 0, 0, 0];
  15256. _this.framebuffer = new Framebuffer(_this.realWidth, _this.realHeight)
  15257. .addColorTexture(0, _this);
  15258. _this.framebuffer.multisample = options.multisample;
  15259. // TODO - could this be added the systems?
  15260. /**
  15261. * The data structure for the stencil masks.
  15262. *
  15263. * @member {PIXI.MaskData[]}
  15264. */
  15265. _this.maskStack = [];
  15266. /**
  15267. * The data structure for the filters.
  15268. *
  15269. * @member {Object[]}
  15270. */
  15271. _this.filterStack = [{}];
  15272. return _this;
  15273. }
  15274. /**
  15275. * Resizes the BaseRenderTexture.
  15276. *
  15277. * @param {number} desiredWidth - The desired width to resize to.
  15278. * @param {number} desiredHeight - The desired height to resize to.
  15279. */
  15280. BaseRenderTexture.prototype.resize = function (desiredWidth, desiredHeight) {
  15281. this.framebuffer.resize(desiredWidth * this.resolution, desiredHeight * this.resolution);
  15282. this.setRealSize(this.framebuffer.width, this.framebuffer.height);
  15283. };
  15284. /**
  15285. * Frees the texture and framebuffer from WebGL memory without destroying this texture object.
  15286. * This means you can still use the texture later which will upload it to GPU
  15287. * memory again.
  15288. *
  15289. * @fires PIXI.BaseTexture#dispose
  15290. */
  15291. BaseRenderTexture.prototype.dispose = function () {
  15292. this.framebuffer.dispose();
  15293. _super.prototype.dispose.call(this);
  15294. };
  15295. /**
  15296. * Destroys this texture.
  15297. */
  15298. BaseRenderTexture.prototype.destroy = function () {
  15299. _super.prototype.destroy.call(this);
  15300. this.framebuffer.destroyDepthTexture();
  15301. this.framebuffer = null;
  15302. };
  15303. return BaseRenderTexture;
  15304. }(BaseTexture));
  15305. /**
  15306. * Stores a texture's frame in UV coordinates, in
  15307. * which everything lies in the rectangle `[(0,0), (1,0),
  15308. * (1,1), (0,1)]`.
  15309. *
  15310. * | Corner | Coordinates |
  15311. * |--------------|-------------|
  15312. * | Top-Left | `(x0,y0)` |
  15313. * | Top-Right | `(x1,y1)` |
  15314. * | Bottom-Right | `(x2,y2)` |
  15315. * | Bottom-Left | `(x3,y3)` |
  15316. *
  15317. * @class
  15318. * @protected
  15319. * @memberof PIXI
  15320. */
  15321. var TextureUvs = /** @class */ (function () {
  15322. function TextureUvs() {
  15323. /**
  15324. * X-component of top-left corner `(x0,y0)`.
  15325. *
  15326. * @member {number}
  15327. */
  15328. this.x0 = 0;
  15329. /**
  15330. * Y-component of top-left corner `(x0,y0)`.
  15331. *
  15332. * @member {number}
  15333. */
  15334. this.y0 = 0;
  15335. /**
  15336. * X-component of top-right corner `(x1,y1)`.
  15337. *
  15338. * @member {number}
  15339. */
  15340. this.x1 = 1;
  15341. /**
  15342. * Y-component of top-right corner `(x1,y1)`.
  15343. *
  15344. * @member {number}
  15345. */
  15346. this.y1 = 0;
  15347. /**
  15348. * X-component of bottom-right corner `(x2,y2)`.
  15349. *
  15350. * @member {number}
  15351. */
  15352. this.x2 = 1;
  15353. /**
  15354. * Y-component of bottom-right corner `(x2,y2)`.
  15355. *
  15356. * @member {number}
  15357. */
  15358. this.y2 = 1;
  15359. /**
  15360. * X-component of bottom-left corner `(x3,y3)`.
  15361. *
  15362. * @member {number}
  15363. */
  15364. this.x3 = 0;
  15365. /**
  15366. * Y-component of bottom-right corner `(x3,y3)`.
  15367. *
  15368. * @member {number}
  15369. */
  15370. this.y3 = 1;
  15371. this.uvsFloat32 = new Float32Array(8);
  15372. }
  15373. /**
  15374. * Sets the texture Uvs based on the given frame information.
  15375. *
  15376. * @protected
  15377. * @param {PIXI.Rectangle} frame - The frame of the texture
  15378. * @param {PIXI.Rectangle} baseFrame - The base frame of the texture
  15379. * @param {number} rotate - Rotation of frame, see {@link PIXI.groupD8}
  15380. */
  15381. TextureUvs.prototype.set = function (frame, baseFrame, rotate) {
  15382. var tw = baseFrame.width;
  15383. var th = baseFrame.height;
  15384. if (rotate) {
  15385. // width and height div 2 div baseFrame size
  15386. var w2 = frame.width / 2 / tw;
  15387. var h2 = frame.height / 2 / th;
  15388. // coordinates of center
  15389. var cX = (frame.x / tw) + w2;
  15390. var cY = (frame.y / th) + h2;
  15391. rotate = groupD8.add(rotate, groupD8.NW); // NW is top-left corner
  15392. this.x0 = cX + (w2 * groupD8.uX(rotate));
  15393. this.y0 = cY + (h2 * groupD8.uY(rotate));
  15394. rotate = groupD8.add(rotate, 2); // rotate 90 degrees clockwise
  15395. this.x1 = cX + (w2 * groupD8.uX(rotate));
  15396. this.y1 = cY + (h2 * groupD8.uY(rotate));
  15397. rotate = groupD8.add(rotate, 2);
  15398. this.x2 = cX + (w2 * groupD8.uX(rotate));
  15399. this.y2 = cY + (h2 * groupD8.uY(rotate));
  15400. rotate = groupD8.add(rotate, 2);
  15401. this.x3 = cX + (w2 * groupD8.uX(rotate));
  15402. this.y3 = cY + (h2 * groupD8.uY(rotate));
  15403. }
  15404. else {
  15405. this.x0 = frame.x / tw;
  15406. this.y0 = frame.y / th;
  15407. this.x1 = (frame.x + frame.width) / tw;
  15408. this.y1 = frame.y / th;
  15409. this.x2 = (frame.x + frame.width) / tw;
  15410. this.y2 = (frame.y + frame.height) / th;
  15411. this.x3 = frame.x / tw;
  15412. this.y3 = (frame.y + frame.height) / th;
  15413. }
  15414. this.uvsFloat32[0] = this.x0;
  15415. this.uvsFloat32[1] = this.y0;
  15416. this.uvsFloat32[2] = this.x1;
  15417. this.uvsFloat32[3] = this.y1;
  15418. this.uvsFloat32[4] = this.x2;
  15419. this.uvsFloat32[5] = this.y2;
  15420. this.uvsFloat32[6] = this.x3;
  15421. this.uvsFloat32[7] = this.y3;
  15422. };
  15423. TextureUvs.prototype.toString = function () {
  15424. return "[@pixi/core:TextureUvs "
  15425. + ("x0=" + this.x0 + " y0=" + this.y0 + " ")
  15426. + ("x1=" + this.x1 + " y1=" + this.y1 + " x2=" + this.x2 + " ")
  15427. + ("y2=" + this.y2 + " x3=" + this.x3 + " y3=" + this.y3)
  15428. + "]";
  15429. };
  15430. return TextureUvs;
  15431. }());
  15432. var DEFAULT_UVS = new TextureUvs();
  15433. /**
  15434. * A texture stores the information that represents an image or part of an image.
  15435. *
  15436. * It cannot be added to the display list directly; instead use it as the texture for a Sprite.
  15437. * If no frame is provided for a texture, then the whole image is used.
  15438. *
  15439. * You can directly create a texture from an image and then reuse it multiple times like this :
  15440. *
  15441. * ```js
  15442. * let texture = PIXI.Texture.from('assets/image.png');
  15443. * let sprite1 = new PIXI.Sprite(texture);
  15444. * let sprite2 = new PIXI.Sprite(texture);
  15445. * ```
  15446. *
  15447. * If you didnt pass the texture frame to constructor, it enables `noFrame` mode:
  15448. * it subscribes on baseTexture events, it automatically resizes at the same time as baseTexture.
  15449. *
  15450. * Textures made from SVGs, loaded or not, cannot be used before the file finishes processing.
  15451. * You can check for this by checking the sprite's _textureID property.
  15452. * ```js
  15453. * var texture = PIXI.Texture.from('assets/image.svg');
  15454. * var sprite1 = new PIXI.Sprite(texture);
  15455. * //sprite1._textureID should not be undefined if the texture has finished processing the SVG file
  15456. * ```
  15457. * You can use a ticker or rAF to ensure your sprites load the finished textures after processing. See issue #3068.
  15458. *
  15459. * @class
  15460. * @extends PIXI.utils.EventEmitter
  15461. * @memberof PIXI
  15462. * @typeParam R - The BaseTexture's Resource type.
  15463. */
  15464. var Texture = /** @class */ (function (_super) {
  15465. __extends$2(Texture, _super);
  15466. /**
  15467. * @param {PIXI.BaseTexture} baseTexture - The base texture source to create the texture from
  15468. * @param {PIXI.Rectangle} [frame] - The rectangle frame of the texture to show
  15469. * @param {PIXI.Rectangle} [orig] - The area of original texture
  15470. * @param {PIXI.Rectangle} [trim] - Trimmed rectangle of original texture
  15471. * @param {number} [rotate] - indicates how the texture was rotated by texture packer. See {@link PIXI.groupD8}
  15472. * @param {PIXI.IPointData} [anchor] - Default anchor point used for sprite placement / rotation
  15473. */
  15474. function Texture(baseTexture, frame, orig, trim, rotate, anchor) {
  15475. var _this = _super.call(this) || this;
  15476. /**
  15477. * Does this Texture have any frame data assigned to it?
  15478. *
  15479. * This mode is enabled automatically if no frame was passed inside constructor.
  15480. *
  15481. * In this mode texture is subscribed to baseTexture events, and fires `update` on any change.
  15482. *
  15483. * Beware, after loading or resize of baseTexture event can fired two times!
  15484. * If you want more control, subscribe on baseTexture itself.
  15485. *
  15486. * ```js
  15487. * texture.on('update', () => {});
  15488. * ```
  15489. *
  15490. * Any assignment of `frame` switches off `noFrame` mode.
  15491. *
  15492. * @member {boolean}
  15493. */
  15494. _this.noFrame = false;
  15495. if (!frame) {
  15496. _this.noFrame = true;
  15497. frame = new Rectangle(0, 0, 1, 1);
  15498. }
  15499. if (baseTexture instanceof Texture) {
  15500. baseTexture = baseTexture.baseTexture;
  15501. }
  15502. /**
  15503. * The base texture that this texture uses.
  15504. *
  15505. * @member {PIXI.BaseTexture}
  15506. */
  15507. _this.baseTexture = baseTexture;
  15508. /**
  15509. * This is the area of the BaseTexture image to actually copy to the Canvas / WebGL when rendering,
  15510. * irrespective of the actual frame size or placement (which can be influenced by trimmed texture atlases)
  15511. *
  15512. * @member {PIXI.Rectangle}
  15513. */
  15514. _this._frame = frame;
  15515. /**
  15516. * This is the trimmed area of original texture, before it was put in atlas
  15517. * Please call `updateUvs()` after you change coordinates of `trim` manually.
  15518. *
  15519. * @member {PIXI.Rectangle}
  15520. */
  15521. _this.trim = trim;
  15522. /**
  15523. * This will let the renderer know if the texture is valid. If it's not then it cannot be rendered.
  15524. *
  15525. * @member {boolean}
  15526. */
  15527. _this.valid = false;
  15528. /**
  15529. * The WebGL UV data cache. Can be used as quad UV
  15530. *
  15531. * @member {PIXI.TextureUvs}
  15532. * @protected
  15533. */
  15534. _this._uvs = DEFAULT_UVS;
  15535. /**
  15536. * Default TextureMatrix instance for this texture
  15537. * By default that object is not created because its heavy
  15538. *
  15539. * @member {PIXI.TextureMatrix}
  15540. */
  15541. _this.uvMatrix = null;
  15542. /**
  15543. * This is the area of original texture, before it was put in atlas
  15544. *
  15545. * @member {PIXI.Rectangle}
  15546. */
  15547. _this.orig = orig || frame; // new Rectangle(0, 0, 1, 1);
  15548. _this._rotate = Number(rotate || 0);
  15549. if (rotate === true) {
  15550. // this is old texturepacker legacy, some games/libraries are passing "true" for rotated textures
  15551. _this._rotate = 2;
  15552. }
  15553. else if (_this._rotate % 2 !== 0) {
  15554. throw new Error('attempt to use diamond-shaped UVs. If you are sure, set rotation manually');
  15555. }
  15556. /**
  15557. * Anchor point that is used as default if sprite is created with this texture.
  15558. * Changing the `defaultAnchor` at a later point of time will not update Sprite's anchor point.
  15559. * @member {PIXI.Point}
  15560. * @default {0,0}
  15561. */
  15562. _this.defaultAnchor = anchor ? new Point(anchor.x, anchor.y) : new Point(0, 0);
  15563. /**
  15564. * Update ID is observed by sprites and TextureMatrix instances.
  15565. * Call updateUvs() to increment it.
  15566. *
  15567. * @member {number}
  15568. * @protected
  15569. */
  15570. _this._updateID = 0;
  15571. /**
  15572. * The ids under which this Texture has been added to the texture cache. This is
  15573. * automatically set as long as Texture.addToCache is used, but may not be set if a
  15574. * Texture is added directly to the TextureCache array.
  15575. *
  15576. * @member {string[]}
  15577. */
  15578. _this.textureCacheIds = [];
  15579. if (!baseTexture.valid) {
  15580. baseTexture.once('loaded', _this.onBaseTextureUpdated, _this);
  15581. }
  15582. else if (_this.noFrame) {
  15583. // if there is no frame we should monitor for any base texture changes..
  15584. if (baseTexture.valid) {
  15585. _this.onBaseTextureUpdated(baseTexture);
  15586. }
  15587. }
  15588. else {
  15589. _this.frame = frame;
  15590. }
  15591. if (_this.noFrame) {
  15592. baseTexture.on('update', _this.onBaseTextureUpdated, _this);
  15593. }
  15594. return _this;
  15595. }
  15596. /**
  15597. * Updates this texture on the gpu.
  15598. *
  15599. * Calls the TextureResource update.
  15600. *
  15601. * If you adjusted `frame` manually, please call `updateUvs()` instead.
  15602. *
  15603. */
  15604. Texture.prototype.update = function () {
  15605. if (this.baseTexture.resource) {
  15606. this.baseTexture.resource.update();
  15607. }
  15608. };
  15609. /**
  15610. * Called when the base texture is updated
  15611. *
  15612. * @protected
  15613. * @param {PIXI.BaseTexture} baseTexture - The base texture.
  15614. */
  15615. Texture.prototype.onBaseTextureUpdated = function (baseTexture) {
  15616. if (this.noFrame) {
  15617. if (!this.baseTexture.valid) {
  15618. return;
  15619. }
  15620. this._frame.width = baseTexture.width;
  15621. this._frame.height = baseTexture.height;
  15622. this.valid = true;
  15623. this.updateUvs();
  15624. }
  15625. else {
  15626. // TODO this code looks confusing.. boo to abusing getters and setters!
  15627. // if user gave us frame that has bigger size than resized texture it can be a problem
  15628. this.frame = this._frame;
  15629. }
  15630. this.emit('update', this);
  15631. };
  15632. /**
  15633. * Destroys this texture
  15634. *
  15635. * @param {boolean} [destroyBase=false] - Whether to destroy the base texture as well
  15636. */
  15637. Texture.prototype.destroy = function (destroyBase) {
  15638. if (this.baseTexture) {
  15639. if (destroyBase) {
  15640. var resource = this.baseTexture.resource;
  15641. // delete the texture if it exists in the texture cache..
  15642. // this only needs to be removed if the base texture is actually destroyed too..
  15643. if (resource && resource.url && TextureCache[resource.url]) {
  15644. Texture.removeFromCache(resource.url);
  15645. }
  15646. this.baseTexture.destroy();
  15647. }
  15648. this.baseTexture.off('loaded', this.onBaseTextureUpdated, this);
  15649. this.baseTexture.off('update', this.onBaseTextureUpdated, this);
  15650. this.baseTexture = null;
  15651. }
  15652. this._frame = null;
  15653. this._uvs = null;
  15654. this.trim = null;
  15655. this.orig = null;
  15656. this.valid = false;
  15657. Texture.removeFromCache(this);
  15658. this.textureCacheIds = null;
  15659. };
  15660. /**
  15661. * Creates a new texture object that acts the same as this one.
  15662. *
  15663. * @return {PIXI.Texture} The new texture
  15664. */
  15665. Texture.prototype.clone = function () {
  15666. var clonedFrame = this._frame.clone();
  15667. var clonedOrig = this._frame === this.orig ? clonedFrame : this.orig.clone();
  15668. var clonedTexture = new Texture(this.baseTexture, !this.noFrame && clonedFrame, clonedOrig, this.trim && this.trim.clone(), this.rotate, this.defaultAnchor);
  15669. if (this.noFrame) {
  15670. clonedTexture._frame = clonedFrame;
  15671. }
  15672. return clonedTexture;
  15673. };
  15674. /**
  15675. * Updates the internal WebGL UV cache. Use it after you change `frame` or `trim` of the texture.
  15676. * Call it after changing the frame
  15677. */
  15678. Texture.prototype.updateUvs = function () {
  15679. if (this._uvs === DEFAULT_UVS) {
  15680. this._uvs = new TextureUvs();
  15681. }
  15682. this._uvs.set(this._frame, this.baseTexture, this.rotate);
  15683. this._updateID++;
  15684. };
  15685. /**
  15686. * Helper function that creates a new Texture based on the source you provide.
  15687. * The source can be - frame id, image url, video url, canvas element, video element, base texture
  15688. *
  15689. * @static
  15690. * @param {string|HTMLImageElement|HTMLCanvasElement|HTMLVideoElement|PIXI.BaseTexture} source -
  15691. * Source to create texture from
  15692. * @param {object} [options] - See {@link PIXI.BaseTexture}'s constructor for options.
  15693. * @param {string} [options.pixiIdPrefix=pixiid] - If a source has no id, this is the prefix of the generated id
  15694. * @param {boolean} [strict] - Enforce strict-mode, see {@link PIXI.settings.STRICT_TEXTURE_CACHE}.
  15695. * @return {PIXI.Texture} The newly created texture
  15696. */
  15697. Texture.from = function (source, options, strict) {
  15698. if (options === void 0) { options = {}; }
  15699. if (strict === void 0) { strict = settings.STRICT_TEXTURE_CACHE; }
  15700. var isFrame = typeof source === 'string';
  15701. var cacheId = null;
  15702. if (isFrame) {
  15703. cacheId = source;
  15704. }
  15705. else {
  15706. if (!source._pixiId) {
  15707. var prefix = (options && options.pixiIdPrefix) || 'pixiid';
  15708. source._pixiId = prefix + "_" + uid();
  15709. }
  15710. cacheId = source._pixiId;
  15711. }
  15712. var texture = TextureCache[cacheId];
  15713. // Strict-mode rejects invalid cacheIds
  15714. if (isFrame && strict && !texture) {
  15715. throw new Error("The cacheId \"" + cacheId + "\" does not exist in TextureCache.");
  15716. }
  15717. if (!texture) {
  15718. if (!options.resolution) {
  15719. options.resolution = getResolutionOfUrl(source);
  15720. }
  15721. texture = new Texture(new BaseTexture(source, options));
  15722. texture.baseTexture.cacheId = cacheId;
  15723. BaseTexture.addToCache(texture.baseTexture, cacheId);
  15724. Texture.addToCache(texture, cacheId);
  15725. }
  15726. // lets assume its a base texture!
  15727. return texture;
  15728. };
  15729. /**
  15730. * Useful for loading textures via URLs. Use instead of `Texture.from` because
  15731. * it does a better job of handling failed URLs more effectively. This also ignores
  15732. * `PIXI.settings.STRICT_TEXTURE_CACHE`. Works for Videos, SVGs, Images.
  15733. * @param {string} url - The remote URL to load.
  15734. * @param {object} [options] - Optional options to include
  15735. * @return {Promise<PIXI.Texture>} A Promise that resolves to a Texture.
  15736. */
  15737. Texture.fromURL = function (url, options) {
  15738. var resourceOptions = Object.assign({ autoLoad: false }, options === null || options === void 0 ? void 0 : options.resourceOptions);
  15739. var texture = Texture.from(url, Object.assign({ resourceOptions: resourceOptions }, options), false);
  15740. var resource = texture.baseTexture.resource;
  15741. // The texture was already loaded
  15742. if (texture.baseTexture.valid) {
  15743. return Promise.resolve(texture);
  15744. }
  15745. // Manually load the texture, this should allow users to handle load errors
  15746. return resource.load().then(function () { return Promise.resolve(texture); });
  15747. };
  15748. /**
  15749. * Create a new Texture with a BufferResource from a Float32Array.
  15750. * RGBA values are floats from 0 to 1.
  15751. * @static
  15752. * @param {Float32Array|Uint8Array} buffer - The optional array to use, if no data
  15753. * is provided, a new Float32Array is created.
  15754. * @param {number} width - Width of the resource
  15755. * @param {number} height - Height of the resource
  15756. * @param {object} [options] - See {@link PIXI.BaseTexture}'s constructor for options.
  15757. * @return {PIXI.Texture} The resulting new BaseTexture
  15758. */
  15759. Texture.fromBuffer = function (buffer, width, height, options) {
  15760. return new Texture(BaseTexture.fromBuffer(buffer, width, height, options));
  15761. };
  15762. /**
  15763. * Create a texture from a source and add to the cache.
  15764. *
  15765. * @static
  15766. * @param {HTMLImageElement|HTMLCanvasElement|string} source - The input source.
  15767. * @param {String} imageUrl - File name of texture, for cache and resolving resolution.
  15768. * @param {String} [name] - Human readable name for the texture cache. If no name is
  15769. * specified, only `imageUrl` will be used as the cache ID.
  15770. * @return {PIXI.Texture} Output texture
  15771. */
  15772. Texture.fromLoader = function (source, imageUrl, name, options) {
  15773. var baseTexture = new BaseTexture(source, Object.assign({
  15774. scaleMode: settings.SCALE_MODE,
  15775. resolution: getResolutionOfUrl(imageUrl),
  15776. }, options));
  15777. var resource = baseTexture.resource;
  15778. if (resource instanceof ImageResource) {
  15779. resource.url = imageUrl;
  15780. }
  15781. var texture = new Texture(baseTexture);
  15782. // No name, use imageUrl instead
  15783. if (!name) {
  15784. name = imageUrl;
  15785. }
  15786. // lets also add the frame to pixi's global cache for 'fromLoader' function
  15787. BaseTexture.addToCache(texture.baseTexture, name);
  15788. Texture.addToCache(texture, name);
  15789. // also add references by url if they are different.
  15790. if (name !== imageUrl) {
  15791. BaseTexture.addToCache(texture.baseTexture, imageUrl);
  15792. Texture.addToCache(texture, imageUrl);
  15793. }
  15794. // Generally images are valid right away
  15795. if (texture.baseTexture.valid) {
  15796. return Promise.resolve(texture);
  15797. }
  15798. // SVG assets need to be parsed async, let's wait
  15799. return new Promise(function (resolve) {
  15800. texture.baseTexture.once('loaded', function () { return resolve(texture); });
  15801. });
  15802. };
  15803. /**
  15804. * Adds a Texture to the global TextureCache. This cache is shared across the whole PIXI object.
  15805. *
  15806. * @static
  15807. * @param {PIXI.Texture} texture - The Texture to add to the cache.
  15808. * @param {string} id - The id that the Texture will be stored against.
  15809. */
  15810. Texture.addToCache = function (texture, id) {
  15811. if (id) {
  15812. if (texture.textureCacheIds.indexOf(id) === -1) {
  15813. texture.textureCacheIds.push(id);
  15814. }
  15815. if (TextureCache[id]) {
  15816. // eslint-disable-next-line no-console
  15817. console.warn("Texture added to the cache with an id [" + id + "] that already had an entry");
  15818. }
  15819. TextureCache[id] = texture;
  15820. }
  15821. };
  15822. /**
  15823. * Remove a Texture from the global TextureCache.
  15824. *
  15825. * @static
  15826. * @param {string|PIXI.Texture} texture - id of a Texture to be removed, or a Texture instance itself
  15827. * @return {PIXI.Texture|null} The Texture that was removed
  15828. */
  15829. Texture.removeFromCache = function (texture) {
  15830. if (typeof texture === 'string') {
  15831. var textureFromCache = TextureCache[texture];
  15832. if (textureFromCache) {
  15833. var index = textureFromCache.textureCacheIds.indexOf(texture);
  15834. if (index > -1) {
  15835. textureFromCache.textureCacheIds.splice(index, 1);
  15836. }
  15837. delete TextureCache[texture];
  15838. return textureFromCache;
  15839. }
  15840. }
  15841. else if (texture && texture.textureCacheIds) {
  15842. for (var i = 0; i < texture.textureCacheIds.length; ++i) {
  15843. // Check that texture matches the one being passed in before deleting it from the cache.
  15844. if (TextureCache[texture.textureCacheIds[i]] === texture) {
  15845. delete TextureCache[texture.textureCacheIds[i]];
  15846. }
  15847. }
  15848. texture.textureCacheIds.length = 0;
  15849. return texture;
  15850. }
  15851. return null;
  15852. };
  15853. Object.defineProperty(Texture.prototype, "resolution", {
  15854. /**
  15855. * Returns resolution of baseTexture
  15856. *
  15857. * @member {number}
  15858. * @readonly
  15859. */
  15860. get: function () {
  15861. return this.baseTexture.resolution;
  15862. },
  15863. enumerable: false,
  15864. configurable: true
  15865. });
  15866. Object.defineProperty(Texture.prototype, "frame", {
  15867. /**
  15868. * The frame specifies the region of the base texture that this texture uses.
  15869. * Please call `updateUvs()` after you change coordinates of `frame` manually.
  15870. *
  15871. * @member {PIXI.Rectangle}
  15872. */
  15873. get: function () {
  15874. return this._frame;
  15875. },
  15876. set: function (frame) {
  15877. this._frame = frame;
  15878. this.noFrame = false;
  15879. var x = frame.x, y = frame.y, width = frame.width, height = frame.height;
  15880. var xNotFit = x + width > this.baseTexture.width;
  15881. var yNotFit = y + height > this.baseTexture.height;
  15882. if (xNotFit || yNotFit) {
  15883. var relationship = xNotFit && yNotFit ? 'and' : 'or';
  15884. var errorX = "X: " + x + " + " + width + " = " + (x + width) + " > " + this.baseTexture.width;
  15885. var errorY = "Y: " + y + " + " + height + " = " + (y + height) + " > " + this.baseTexture.height;
  15886. throw new Error('Texture Error: frame does not fit inside the base Texture dimensions: '
  15887. + (errorX + " " + relationship + " " + errorY));
  15888. }
  15889. this.valid = width && height && this.baseTexture.valid;
  15890. if (!this.trim && !this.rotate) {
  15891. this.orig = frame;
  15892. }
  15893. if (this.valid) {
  15894. this.updateUvs();
  15895. }
  15896. },
  15897. enumerable: false,
  15898. configurable: true
  15899. });
  15900. Object.defineProperty(Texture.prototype, "rotate", {
  15901. /**
  15902. * Indicates whether the texture is rotated inside the atlas
  15903. * set to 2 to compensate for texture packer rotation
  15904. * set to 6 to compensate for spine packer rotation
  15905. * can be used to rotate or mirror sprites
  15906. * See {@link PIXI.groupD8} for explanation
  15907. *
  15908. * @member {number}
  15909. */
  15910. get: function () {
  15911. return this._rotate;
  15912. },
  15913. set: function (rotate) {
  15914. this._rotate = rotate;
  15915. if (this.valid) {
  15916. this.updateUvs();
  15917. }
  15918. },
  15919. enumerable: false,
  15920. configurable: true
  15921. });
  15922. Object.defineProperty(Texture.prototype, "width", {
  15923. /**
  15924. * The width of the Texture in pixels.
  15925. *
  15926. * @member {number}
  15927. */
  15928. get: function () {
  15929. return this.orig.width;
  15930. },
  15931. enumerable: false,
  15932. configurable: true
  15933. });
  15934. Object.defineProperty(Texture.prototype, "height", {
  15935. /**
  15936. * The height of the Texture in pixels.
  15937. *
  15938. * @member {number}
  15939. */
  15940. get: function () {
  15941. return this.orig.height;
  15942. },
  15943. enumerable: false,
  15944. configurable: true
  15945. });
  15946. /**
  15947. * Utility function for BaseTexture|Texture cast
  15948. */
  15949. Texture.prototype.castToBaseTexture = function () {
  15950. return this.baseTexture;
  15951. };
  15952. return Texture;
  15953. }(eventemitter3));
  15954. function createWhiteTexture() {
  15955. var canvas = document.createElement('canvas');
  15956. canvas.width = 16;
  15957. canvas.height = 16;
  15958. var context = canvas.getContext('2d');
  15959. context.fillStyle = 'white';
  15960. context.fillRect(0, 0, 16, 16);
  15961. return new Texture(new BaseTexture(new CanvasResource(canvas)));
  15962. }
  15963. function removeAllHandlers(tex) {
  15964. tex.destroy = function _emptyDestroy() { };
  15965. tex.on = function _emptyOn() { };
  15966. tex.once = function _emptyOnce() { };
  15967. tex.emit = function _emptyEmit() { };
  15968. }
  15969. /**
  15970. * An empty texture, used often to not have to create multiple empty textures.
  15971. * Can not be destroyed.
  15972. *
  15973. * @static
  15974. * @constant
  15975. * @member {PIXI.Texture}
  15976. */
  15977. Texture.EMPTY = new Texture(new BaseTexture());
  15978. removeAllHandlers(Texture.EMPTY);
  15979. removeAllHandlers(Texture.EMPTY.baseTexture);
  15980. /**
  15981. * A white texture of 16x16 size, used for graphics and other things
  15982. * Can not be destroyed.
  15983. *
  15984. * @static
  15985. * @constant
  15986. * @member {PIXI.Texture}
  15987. */
  15988. Texture.WHITE = createWhiteTexture();
  15989. removeAllHandlers(Texture.WHITE);
  15990. removeAllHandlers(Texture.WHITE.baseTexture);
  15991. /**
  15992. * A RenderTexture is a special texture that allows any PixiJS display object to be rendered to it.
  15993. *
  15994. * __Hint__: All DisplayObjects (i.e. Sprites) that render to a RenderTexture should be preloaded
  15995. * otherwise black rectangles will be drawn instead.
  15996. *
  15997. * __Hint-2__: The actual memory allocation will happen on first render.
  15998. * You shouldn't create renderTextures each frame just to delete them after, try to reuse them.
  15999. *
  16000. * A RenderTexture takes a snapshot of any Display Object given to its render method. For example:
  16001. *
  16002. * ```js
  16003. * let renderer = PIXI.autoDetectRenderer();
  16004. * let renderTexture = PIXI.RenderTexture.create({ width: 800, height: 600 });
  16005. * let sprite = PIXI.Sprite.from("spinObj_01.png");
  16006. *
  16007. * sprite.position.x = 800/2;
  16008. * sprite.position.y = 600/2;
  16009. * sprite.anchor.x = 0.5;
  16010. * sprite.anchor.y = 0.5;
  16011. *
  16012. * renderer.render(sprite, {renderTexture});
  16013. * ```
  16014. * Note that you should not create a new renderer, but reuse the same one as the rest of the application.
  16015. *
  16016. * The Sprite in this case will be rendered using its local transform. To render this sprite at 0,0
  16017. * you can clear the transform
  16018. *
  16019. * ```js
  16020. *
  16021. * sprite.setTransform()
  16022. *
  16023. * let renderTexture = new PIXI.RenderTexture.create({ width: 100, height: 100 });
  16024. *
  16025. * renderer.render(sprite, {renderTexture}); // Renders to center of RenderTexture
  16026. * ```
  16027. *
  16028. * @class
  16029. * @extends PIXI.Texture
  16030. * @memberof PIXI
  16031. */
  16032. var RenderTexture = /** @class */ (function (_super) {
  16033. __extends$2(RenderTexture, _super);
  16034. /**
  16035. * @param {PIXI.BaseRenderTexture} baseRenderTexture - The base texture object that this texture uses
  16036. * @param {PIXI.Rectangle} [frame] - The rectangle frame of the texture to show
  16037. */
  16038. function RenderTexture(baseRenderTexture, frame) {
  16039. var _this = _super.call(this, baseRenderTexture, frame) || this;
  16040. /**
  16041. * This will let the renderer know if the texture is valid. If it's not then it cannot be rendered.
  16042. *
  16043. * @member {boolean}
  16044. */
  16045. _this.valid = true;
  16046. /**
  16047. * Stores `sourceFrame` when this texture is inside current filter stack.
  16048. * You can read it inside filters.
  16049. *
  16050. * @readonly
  16051. * @member {PIXI.Rectangle}
  16052. */
  16053. _this.filterFrame = null;
  16054. /**
  16055. * The key for pooled texture of FilterSystem
  16056. * @protected
  16057. * @member {string}
  16058. */
  16059. _this.filterPoolKey = null;
  16060. _this.updateUvs();
  16061. return _this;
  16062. }
  16063. Object.defineProperty(RenderTexture.prototype, "framebuffer", {
  16064. /**
  16065. * Shortcut to `this.baseTexture.framebuffer`, saves baseTexture cast.
  16066. * @member {PIXI.Framebuffer}
  16067. * @readonly
  16068. */
  16069. get: function () {
  16070. return this.baseTexture.framebuffer;
  16071. },
  16072. enumerable: false,
  16073. configurable: true
  16074. });
  16075. Object.defineProperty(RenderTexture.prototype, "multisample", {
  16076. /**
  16077. * Shortcut to `this.framebuffer.multisample`.
  16078. *
  16079. * @member {PIXI.MSAA_QUALITY}
  16080. * @default PIXI.MSAA_QUALITY.NONE
  16081. */
  16082. get: function () {
  16083. return this.framebuffer.multisample;
  16084. },
  16085. set: function (value) {
  16086. this.framebuffer.multisample = value;
  16087. },
  16088. enumerable: false,
  16089. configurable: true
  16090. });
  16091. /**
  16092. * Resizes the RenderTexture.
  16093. *
  16094. * @param {number} desiredWidth - The desired width to resize to.
  16095. * @param {number} desiredHeight - The desired height to resize to.
  16096. * @param {boolean} [resizeBaseTexture=true] - Should the baseTexture.width and height values be resized as well?
  16097. */
  16098. RenderTexture.prototype.resize = function (desiredWidth, desiredHeight, resizeBaseTexture) {
  16099. if (resizeBaseTexture === void 0) { resizeBaseTexture = true; }
  16100. var resolution = this.baseTexture.resolution;
  16101. var width = Math.round(desiredWidth * resolution) / resolution;
  16102. var height = Math.round(desiredHeight * resolution) / resolution;
  16103. // TODO - could be not required..
  16104. this.valid = (width > 0 && height > 0);
  16105. this._frame.width = this.orig.width = width;
  16106. this._frame.height = this.orig.height = height;
  16107. if (resizeBaseTexture) {
  16108. this.baseTexture.resize(width, height);
  16109. }
  16110. this.updateUvs();
  16111. };
  16112. /**
  16113. * Changes the resolution of baseTexture, but does not change framebuffer size.
  16114. *
  16115. * @param {number} resolution - The new resolution to apply to RenderTexture
  16116. */
  16117. RenderTexture.prototype.setResolution = function (resolution) {
  16118. var baseTexture = this.baseTexture;
  16119. if (baseTexture.resolution === resolution) {
  16120. return;
  16121. }
  16122. baseTexture.setResolution(resolution);
  16123. this.resize(baseTexture.width, baseTexture.height, false);
  16124. };
  16125. RenderTexture.create = function (options) {
  16126. var arguments$1 = arguments;
  16127. var rest = [];
  16128. for (var _i = 1; _i < arguments.length; _i++) {
  16129. rest[_i - 1] = arguments$1[_i];
  16130. }
  16131. // @deprecated fallback, old-style: create(width, height, scaleMode, resolution)
  16132. if (typeof options === 'number') {
  16133. deprecation('6.0.0', 'Arguments (width, height, scaleMode, resolution) have been deprecated.');
  16134. /* eslint-disable prefer-rest-params */
  16135. options = {
  16136. width: options,
  16137. height: rest[0],
  16138. scaleMode: rest[1],
  16139. resolution: rest[2],
  16140. };
  16141. /* eslint-enable prefer-rest-params */
  16142. }
  16143. return new RenderTexture(new BaseRenderTexture(options));
  16144. };
  16145. return RenderTexture;
  16146. }(Texture));
  16147. /**
  16148. * Experimental!
  16149. *
  16150. * Texture pool, used by FilterSystem and plugins
  16151. * Stores collection of temporary pow2 or screen-sized renderTextures
  16152. *
  16153. * If you use custom RenderTexturePool for your filters, you can use methods
  16154. * `getFilterTexture` and `returnFilterTexture` same as in
  16155. *
  16156. * @class
  16157. * @memberof PIXI
  16158. */
  16159. var RenderTexturePool = /** @class */ (function () {
  16160. /**
  16161. * @param {object} [textureOptions] - options that will be passed to BaseRenderTexture constructor
  16162. * @param {PIXI.SCALE_MODES} [textureOptions.scaleMode] - See {@link PIXI.SCALE_MODES} for possible values.
  16163. */
  16164. function RenderTexturePool(textureOptions) {
  16165. this.texturePool = {};
  16166. this.textureOptions = textureOptions || {};
  16167. /**
  16168. * Allow renderTextures of the same size as screen, not just pow2
  16169. *
  16170. * Automatically sets to true after `setScreenSize`
  16171. *
  16172. * @member {boolean}
  16173. * @default false
  16174. */
  16175. this.enableFullScreen = false;
  16176. this._pixelsWidth = 0;
  16177. this._pixelsHeight = 0;
  16178. }
  16179. /**
  16180. * creates of texture with params that were specified in pool constructor
  16181. *
  16182. * @param {number} realWidth - width of texture in pixels
  16183. * @param {number} realHeight - height of texture in pixels
  16184. * @param {PIXI.MSAA_QUALITY} [multisample=PIXI.MSAA_QUALITY.NONE] - number of samples of the framebuffer
  16185. * @returns {RenderTexture}
  16186. */
  16187. RenderTexturePool.prototype.createTexture = function (realWidth, realHeight, multisample) {
  16188. if (multisample === void 0) { multisample = exports.MSAA_QUALITY.NONE; }
  16189. var baseRenderTexture = new BaseRenderTexture(Object.assign({
  16190. width: realWidth,
  16191. height: realHeight,
  16192. resolution: 1,
  16193. multisample: multisample,
  16194. }, this.textureOptions));
  16195. return new RenderTexture(baseRenderTexture);
  16196. };
  16197. /**
  16198. * Gets a Power-of-Two render texture or fullScreen texture
  16199. *
  16200. * @protected
  16201. * @param {number} minWidth - The minimum width of the render texture.
  16202. * @param {number} minHeight - The minimum height of the render texture.
  16203. * @param {number} [resolution=1] - The resolution of the render texture.
  16204. * @param {PIXI.MSAA_QUALITY} [multisample=PIXI.MSAA_QUALITY.NONE] - Number of samples of the render texture.
  16205. * @return {PIXI.RenderTexture} The new render texture.
  16206. */
  16207. RenderTexturePool.prototype.getOptimalTexture = function (minWidth, minHeight, resolution, multisample) {
  16208. if (resolution === void 0) { resolution = 1; }
  16209. if (multisample === void 0) { multisample = exports.MSAA_QUALITY.NONE; }
  16210. var key;
  16211. minWidth = Math.ceil(minWidth * resolution);
  16212. minHeight = Math.ceil(minHeight * resolution);
  16213. if (!this.enableFullScreen || minWidth !== this._pixelsWidth || minHeight !== this._pixelsHeight) {
  16214. minWidth = nextPow2(minWidth);
  16215. minHeight = nextPow2(minHeight);
  16216. key = (((minWidth & 0xFFFF) << 16) | (minHeight & 0xFFFF)) >>> 0;
  16217. if (multisample > 1) {
  16218. key += multisample * 0x100000000;
  16219. }
  16220. }
  16221. else {
  16222. key = multisample > 1 ? -multisample : -1;
  16223. }
  16224. if (!this.texturePool[key]) {
  16225. this.texturePool[key] = [];
  16226. }
  16227. var renderTexture = this.texturePool[key].pop();
  16228. if (!renderTexture) {
  16229. renderTexture = this.createTexture(minWidth, minHeight, multisample);
  16230. }
  16231. renderTexture.filterPoolKey = key;
  16232. renderTexture.setResolution(resolution);
  16233. return renderTexture;
  16234. };
  16235. /**
  16236. * Gets extra texture of the same size as input renderTexture
  16237. *
  16238. * `getFilterTexture(input, 0.5)` or `getFilterTexture(0.5, input)`
  16239. *
  16240. * @param {PIXI.RenderTexture} input - renderTexture from which size and resolution will be copied
  16241. * @param {number} [resolution] - override resolution of the renderTexture
  16242. * It overrides, it does not multiply
  16243. * @param {PIXI.MSAA_QUALITY} [multisample=PIXI.MSAA_QUALITY.NONE] - number of samples of the renderTexture
  16244. * @returns {PIXI.RenderTexture}
  16245. */
  16246. RenderTexturePool.prototype.getFilterTexture = function (input, resolution, multisample) {
  16247. var filterTexture = this.getOptimalTexture(input.width, input.height, resolution || input.resolution, multisample || exports.MSAA_QUALITY.NONE);
  16248. filterTexture.filterFrame = input.filterFrame;
  16249. return filterTexture;
  16250. };
  16251. /**
  16252. * Place a render texture back into the pool.
  16253. * @param {PIXI.RenderTexture} renderTexture - The renderTexture to free
  16254. */
  16255. RenderTexturePool.prototype.returnTexture = function (renderTexture) {
  16256. var key = renderTexture.filterPoolKey;
  16257. renderTexture.filterFrame = null;
  16258. this.texturePool[key].push(renderTexture);
  16259. };
  16260. /**
  16261. * Alias for returnTexture, to be compliant with FilterSystem interface
  16262. * @param {PIXI.RenderTexture} renderTexture - The renderTexture to free
  16263. */
  16264. RenderTexturePool.prototype.returnFilterTexture = function (renderTexture) {
  16265. this.returnTexture(renderTexture);
  16266. };
  16267. /**
  16268. * Clears the pool
  16269. *
  16270. * @param {boolean} [destroyTextures=true] - destroy all stored textures
  16271. */
  16272. RenderTexturePool.prototype.clear = function (destroyTextures) {
  16273. destroyTextures = destroyTextures !== false;
  16274. if (destroyTextures) {
  16275. for (var i in this.texturePool) {
  16276. var textures = this.texturePool[i];
  16277. if (textures) {
  16278. for (var j = 0; j < textures.length; j++) {
  16279. textures[j].destroy(true);
  16280. }
  16281. }
  16282. }
  16283. }
  16284. this.texturePool = {};
  16285. };
  16286. /**
  16287. * If screen size was changed, drops all screen-sized textures,
  16288. * sets new screen size, sets `enableFullScreen` to true
  16289. *
  16290. * Size is measured in pixels, `renderer.view` can be passed here, not `renderer.screen`
  16291. *
  16292. * @param {PIXI.ISize} size - Initial size of screen
  16293. */
  16294. RenderTexturePool.prototype.setScreenSize = function (size) {
  16295. if (size.width === this._pixelsWidth
  16296. && size.height === this._pixelsHeight) {
  16297. return;
  16298. }
  16299. this.enableFullScreen = size.width > 0 && size.height > 0;
  16300. for (var i in this.texturePool) {
  16301. if (!(Number(i) < 0)) {
  16302. continue;
  16303. }
  16304. var textures = this.texturePool[i];
  16305. if (textures) {
  16306. for (var j = 0; j < textures.length; j++) {
  16307. textures[j].destroy(true);
  16308. }
  16309. }
  16310. this.texturePool[i] = [];
  16311. }
  16312. this._pixelsWidth = size.width;
  16313. this._pixelsHeight = size.height;
  16314. };
  16315. /**
  16316. * Key that is used to store fullscreen renderTextures in a pool
  16317. *
  16318. * @static
  16319. * @const {number}
  16320. */
  16321. RenderTexturePool.SCREEN_KEY = -1;
  16322. return RenderTexturePool;
  16323. }());
  16324. /* eslint-disable max-len */
  16325. /**
  16326. * Holds the information for a single attribute structure required to render geometry.
  16327. *
  16328. * This does not contain the actual data, but instead has a buffer id that maps to a {@link PIXI.Buffer}
  16329. * This can include anything from positions, uvs, normals, colors etc.
  16330. *
  16331. * @class
  16332. * @memberof PIXI
  16333. */
  16334. var Attribute = /** @class */ (function () {
  16335. /**
  16336. * @param {string} buffer - the id of the buffer that this attribute will look for
  16337. * @param {Number} [size=0] - the size of the attribute. If you have 2 floats per vertex (eg position x and y) this would be 2.
  16338. * @param {Boolean} [normalized=false] - should the data be normalized.
  16339. * @param {PIXI.TYPES} [type=PIXI.TYPES.FLOAT] - what type of number is the attribute. Check {@link PIXI.TYPES} to see the ones available
  16340. * @param {Number} [stride=0] - How far apart (in floats) the start of each value is. (used for interleaving data)
  16341. * @param {Number} [start=0] - How far into the array to start reading values (used for interleaving data)
  16342. */
  16343. function Attribute(buffer, size, normalized, type, stride, start, instance) {
  16344. if (size === void 0) { size = 0; }
  16345. if (normalized === void 0) { normalized = false; }
  16346. if (type === void 0) { type = exports.TYPES.FLOAT; }
  16347. this.buffer = buffer;
  16348. this.size = size;
  16349. this.normalized = normalized;
  16350. this.type = type;
  16351. this.stride = stride;
  16352. this.start = start;
  16353. this.instance = instance;
  16354. }
  16355. /**
  16356. * Destroys the Attribute.
  16357. */
  16358. Attribute.prototype.destroy = function () {
  16359. this.buffer = null;
  16360. };
  16361. /**
  16362. * Helper function that creates an Attribute based on the information provided
  16363. *
  16364. * @static
  16365. * @param {string} buffer - the id of the buffer that this attribute will look for
  16366. * @param {Number} [size=0] - the size of the attribute. If you have 2 floats per vertex (eg position x and y) this would be 2
  16367. * @param {Boolean} [normalized=false] - should the data be normalized.
  16368. * @param {PIXI.TYPES} [type=PIXI.TYPES.FLOAT] - what type of number is the attribute. Check {@link PIXI.TYPES} to see the ones available
  16369. * @param {Number} [stride=0] - How far apart (in floats) the start of each value is. (used for interleaving data)
  16370. *
  16371. * @returns {PIXI.Attribute} A new {@link PIXI.Attribute} based on the information provided
  16372. */
  16373. Attribute.from = function (buffer, size, normalized, type, stride) {
  16374. return new Attribute(buffer, size, normalized, type, stride);
  16375. };
  16376. return Attribute;
  16377. }());
  16378. var UID = 0;
  16379. /**
  16380. * A wrapper for data so that it can be used and uploaded by WebGL
  16381. *
  16382. * @class
  16383. * @memberof PIXI
  16384. */
  16385. var Buffer = /** @class */ (function () {
  16386. /**
  16387. * @param {ArrayBuffer| SharedArrayBuffer|ArrayBufferView} data - the data to store in the buffer.
  16388. * @param {boolean} [_static=true] - `true` for static buffer
  16389. * @param {boolean} [index=false] - `true` for index buffer
  16390. */
  16391. function Buffer(data, _static, index) {
  16392. if (_static === void 0) { _static = true; }
  16393. if (index === void 0) { index = false; }
  16394. /**
  16395. * The data in the buffer, as a typed array
  16396. *
  16397. * @member {ArrayBuffer| SharedArrayBuffer | ArrayBufferView}
  16398. */
  16399. this.data = (data || new Float32Array(1));
  16400. /**
  16401. * A map of renderer IDs to webgl buffer
  16402. *
  16403. * @private
  16404. * @member {object<number, GLBuffer>}
  16405. */
  16406. this._glBuffers = {};
  16407. this._updateID = 0;
  16408. this.index = index;
  16409. this.static = _static;
  16410. this.id = UID++;
  16411. this.disposeRunner = new Runner('disposeBuffer');
  16412. }
  16413. // TODO could explore flagging only a partial upload?
  16414. /**
  16415. * flags this buffer as requiring an upload to the GPU
  16416. * @param {ArrayBuffer|SharedArrayBuffer|ArrayBufferView|number[]} [data] - the data to update in the buffer.
  16417. */
  16418. Buffer.prototype.update = function (data) {
  16419. if (data instanceof Array) {
  16420. data = new Float32Array(data);
  16421. }
  16422. this.data = data || this.data;
  16423. this._updateID++;
  16424. };
  16425. /**
  16426. * disposes WebGL resources that are connected to this geometry
  16427. */
  16428. Buffer.prototype.dispose = function () {
  16429. this.disposeRunner.emit(this, false);
  16430. };
  16431. /**
  16432. * Destroys the buffer
  16433. */
  16434. Buffer.prototype.destroy = function () {
  16435. this.dispose();
  16436. this.data = null;
  16437. };
  16438. Object.defineProperty(Buffer.prototype, "index", {
  16439. get: function () {
  16440. return this.type === exports.BUFFER_TYPE.ELEMENT_ARRAY_BUFFER;
  16441. },
  16442. /**
  16443. * Flags whether this is an index buffer.
  16444. *
  16445. * Index buffers are of type `ELEMENT_ARRAY_BUFFER`. Note that setting this property to false will make
  16446. * the buffer of type `ARRAY_BUFFER`.
  16447. *
  16448. * For backwards compatibility.
  16449. */
  16450. set: function (value) {
  16451. this.type = value ? exports.BUFFER_TYPE.ELEMENT_ARRAY_BUFFER : exports.BUFFER_TYPE.ARRAY_BUFFER;
  16452. },
  16453. enumerable: false,
  16454. configurable: true
  16455. });
  16456. /**
  16457. * Helper function that creates a buffer based on an array or TypedArray
  16458. *
  16459. * @static
  16460. * @param {ArrayBufferView | number[]} data - the TypedArray that the buffer will store. If this is a regular Array it will be converted to a Float32Array.
  16461. * @return {PIXI.Buffer} A new Buffer based on the data provided.
  16462. */
  16463. Buffer.from = function (data) {
  16464. if (data instanceof Array) {
  16465. data = new Float32Array(data);
  16466. }
  16467. return new Buffer(data);
  16468. };
  16469. return Buffer;
  16470. }());
  16471. /* eslint-disable object-shorthand */
  16472. var map$1 = {
  16473. Float32Array: Float32Array,
  16474. Uint32Array: Uint32Array,
  16475. Int32Array: Int32Array,
  16476. Uint8Array: Uint8Array,
  16477. };
  16478. function interleaveTypedArrays$1(arrays, sizes) {
  16479. var outSize = 0;
  16480. var stride = 0;
  16481. var views = {};
  16482. for (var i = 0; i < arrays.length; i++) {
  16483. stride += sizes[i];
  16484. outSize += arrays[i].length;
  16485. }
  16486. var buffer = new ArrayBuffer(outSize * 4);
  16487. var out = null;
  16488. var littleOffset = 0;
  16489. for (var i = 0; i < arrays.length; i++) {
  16490. var size = sizes[i];
  16491. var array = arrays[i];
  16492. var type = getBufferType(array);
  16493. if (!views[type]) {
  16494. views[type] = new map$1[type](buffer);
  16495. }
  16496. out = views[type];
  16497. for (var j = 0; j < array.length; j++) {
  16498. var indexStart = ((j / size | 0) * stride) + littleOffset;
  16499. var index = j % size;
  16500. out[indexStart + index] = array[j];
  16501. }
  16502. littleOffset += size;
  16503. }
  16504. return new Float32Array(buffer);
  16505. }
  16506. var byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 };
  16507. var UID$1 = 0;
  16508. /* eslint-disable object-shorthand */
  16509. var map$1$1 = {
  16510. Float32Array: Float32Array,
  16511. Uint32Array: Uint32Array,
  16512. Int32Array: Int32Array,
  16513. Uint8Array: Uint8Array,
  16514. Uint16Array: Uint16Array,
  16515. };
  16516. /* eslint-disable max-len */
  16517. /**
  16518. * The Geometry represents a model. It consists of two components:
  16519. * - GeometryStyle - The structure of the model such as the attributes layout
  16520. * - GeometryData - the data of the model - this consists of buffers.
  16521. * This can include anything from positions, uvs, normals, colors etc.
  16522. *
  16523. * Geometry can be defined without passing in a style or data if required (thats how I prefer!)
  16524. *
  16525. * ```js
  16526. * let geometry = new PIXI.Geometry();
  16527. *
  16528. * geometry.addAttribute('positions', [0, 0, 100, 0, 100, 100, 0, 100], 2);
  16529. * geometry.addAttribute('uvs', [0,0,1,0,1,1,0,1],2)
  16530. * geometry.addIndex([0,1,2,1,3,2])
  16531. *
  16532. * ```
  16533. * @class
  16534. * @memberof PIXI
  16535. */
  16536. var Geometry = /** @class */ (function () {
  16537. /**
  16538. * @param {PIXI.Buffer[]} [buffers] - an array of buffers. optional.
  16539. * @param {object} [attributes] - of the geometry, optional structure of the attributes layout
  16540. */
  16541. function Geometry(buffers, attributes) {
  16542. if (buffers === void 0) { buffers = []; }
  16543. if (attributes === void 0) { attributes = {}; }
  16544. this.buffers = buffers;
  16545. this.indexBuffer = null;
  16546. this.attributes = attributes;
  16547. /**
  16548. * A map of renderer IDs to webgl VAOs
  16549. *
  16550. * @protected
  16551. * @type {object}
  16552. */
  16553. this.glVertexArrayObjects = {};
  16554. this.id = UID$1++;
  16555. this.instanced = false;
  16556. /**
  16557. * Number of instances in this geometry, pass it to `GeometrySystem.draw()`
  16558. * @member {number}
  16559. * @default 1
  16560. */
  16561. this.instanceCount = 1;
  16562. this.disposeRunner = new Runner('disposeGeometry');
  16563. /**
  16564. * Count of existing (not destroyed) meshes that reference this geometry
  16565. * @member {number}
  16566. */
  16567. this.refCount = 0;
  16568. }
  16569. /**
  16570. *
  16571. * Adds an attribute to the geometry
  16572. * Note: `stride` and `start` should be `undefined` if you dont know them, not 0!
  16573. *
  16574. * @param {String} id - the name of the attribute (matching up to a shader)
  16575. * @param {PIXI.Buffer|number[]} buffer - the buffer that holds the data of the attribute . You can also provide an Array and a buffer will be created from it.
  16576. * @param {Number} [size=0] - the size of the attribute. If you have 2 floats per vertex (eg position x and y) this would be 2
  16577. * @param {Boolean} [normalized=false] - should the data be normalized.
  16578. * @param {PIXI.TYPES} [type=PIXI.TYPES.FLOAT] - what type of number is the attribute. Check {PIXI.TYPES} to see the ones available
  16579. * @param {Number} [stride] - How far apart (in floats) the start of each value is. (used for interleaving data)
  16580. * @param {Number} [start] - How far into the array to start reading values (used for interleaving data)
  16581. * @param {boolean} [instance=false] - Instancing flag
  16582. *
  16583. * @return {PIXI.Geometry} returns self, useful for chaining.
  16584. */
  16585. Geometry.prototype.addAttribute = function (id, buffer, size, normalized, type, stride, start, instance) {
  16586. if (size === void 0) { size = 0; }
  16587. if (normalized === void 0) { normalized = false; }
  16588. if (instance === void 0) { instance = false; }
  16589. if (!buffer) {
  16590. throw new Error('You must pass a buffer when creating an attribute');
  16591. }
  16592. // check if this is a buffer!
  16593. if (!(buffer instanceof Buffer)) {
  16594. // its an array!
  16595. if (buffer instanceof Array) {
  16596. buffer = new Float32Array(buffer);
  16597. }
  16598. buffer = new Buffer(buffer);
  16599. }
  16600. var ids = id.split('|');
  16601. if (ids.length > 1) {
  16602. for (var i = 0; i < ids.length; i++) {
  16603. this.addAttribute(ids[i], buffer, size, normalized, type);
  16604. }
  16605. return this;
  16606. }
  16607. var bufferIndex = this.buffers.indexOf(buffer);
  16608. if (bufferIndex === -1) {
  16609. this.buffers.push(buffer);
  16610. bufferIndex = this.buffers.length - 1;
  16611. }
  16612. this.attributes[id] = new Attribute(bufferIndex, size, normalized, type, stride, start, instance);
  16613. // assuming that if there is instanced data then this will be drawn with instancing!
  16614. this.instanced = this.instanced || instance;
  16615. return this;
  16616. };
  16617. /**
  16618. * returns the requested attribute
  16619. *
  16620. * @param {String} id - the name of the attribute required
  16621. * @return {PIXI.Attribute} the attribute requested.
  16622. */
  16623. Geometry.prototype.getAttribute = function (id) {
  16624. return this.attributes[id];
  16625. };
  16626. /**
  16627. * returns the requested buffer
  16628. *
  16629. * @param {String} id - the name of the buffer required
  16630. * @return {PIXI.Buffer} the buffer requested.
  16631. */
  16632. Geometry.prototype.getBuffer = function (id) {
  16633. return this.buffers[this.getAttribute(id).buffer];
  16634. };
  16635. /**
  16636. *
  16637. * Adds an index buffer to the geometry
  16638. * The index buffer contains integers, three for each triangle in the geometry, which reference the various attribute buffers (position, colour, UV coordinates, other UV coordinates, normal, …). There is only ONE index buffer.
  16639. *
  16640. * @param {PIXI.Buffer|number[]} [buffer] - the buffer that holds the data of the index buffer. You can also provide an Array and a buffer will be created from it.
  16641. * @return {PIXI.Geometry} returns self, useful for chaining.
  16642. */
  16643. Geometry.prototype.addIndex = function (buffer) {
  16644. if (!(buffer instanceof Buffer)) {
  16645. // its an array!
  16646. if (buffer instanceof Array) {
  16647. buffer = new Uint16Array(buffer);
  16648. }
  16649. buffer = new Buffer(buffer);
  16650. }
  16651. buffer.type = exports.BUFFER_TYPE.ELEMENT_ARRAY_BUFFER;
  16652. this.indexBuffer = buffer;
  16653. if (this.buffers.indexOf(buffer) === -1) {
  16654. this.buffers.push(buffer);
  16655. }
  16656. return this;
  16657. };
  16658. /**
  16659. * returns the index buffer
  16660. *
  16661. * @return {PIXI.Buffer} the index buffer.
  16662. */
  16663. Geometry.prototype.getIndex = function () {
  16664. return this.indexBuffer;
  16665. };
  16666. /**
  16667. * this function modifies the structure so that all current attributes become interleaved into a single buffer
  16668. * This can be useful if your model remains static as it offers a little performance boost
  16669. *
  16670. * @return {PIXI.Geometry} returns self, useful for chaining.
  16671. */
  16672. Geometry.prototype.interleave = function () {
  16673. // a simple check to see if buffers are already interleaved..
  16674. if (this.buffers.length === 1 || (this.buffers.length === 2 && this.indexBuffer))
  16675. { return this; }
  16676. // assume already that no buffers are interleaved
  16677. var arrays = [];
  16678. var sizes = [];
  16679. var interleavedBuffer = new Buffer();
  16680. var i;
  16681. for (i in this.attributes) {
  16682. var attribute = this.attributes[i];
  16683. var buffer = this.buffers[attribute.buffer];
  16684. arrays.push(buffer.data);
  16685. sizes.push((attribute.size * byteSizeMap[attribute.type]) / 4);
  16686. attribute.buffer = 0;
  16687. }
  16688. interleavedBuffer.data = interleaveTypedArrays$1(arrays, sizes);
  16689. for (i = 0; i < this.buffers.length; i++) {
  16690. if (this.buffers[i] !== this.indexBuffer) {
  16691. this.buffers[i].destroy();
  16692. }
  16693. }
  16694. this.buffers = [interleavedBuffer];
  16695. if (this.indexBuffer) {
  16696. this.buffers.push(this.indexBuffer);
  16697. }
  16698. return this;
  16699. };
  16700. Geometry.prototype.getSize = function () {
  16701. for (var i in this.attributes) {
  16702. var attribute = this.attributes[i];
  16703. var buffer = this.buffers[attribute.buffer];
  16704. return buffer.data.length / ((attribute.stride / 4) || attribute.size);
  16705. }
  16706. return 0;
  16707. };
  16708. /**
  16709. * disposes WebGL resources that are connected to this geometry
  16710. */
  16711. Geometry.prototype.dispose = function () {
  16712. this.disposeRunner.emit(this, false);
  16713. };
  16714. /**
  16715. * Destroys the geometry.
  16716. */
  16717. Geometry.prototype.destroy = function () {
  16718. this.dispose();
  16719. this.buffers = null;
  16720. this.indexBuffer = null;
  16721. this.attributes = null;
  16722. };
  16723. /**
  16724. * returns a clone of the geometry
  16725. *
  16726. * @returns {PIXI.Geometry} a new clone of this geometry
  16727. */
  16728. Geometry.prototype.clone = function () {
  16729. var geometry = new Geometry();
  16730. for (var i = 0; i < this.buffers.length; i++) {
  16731. geometry.buffers[i] = new Buffer(this.buffers[i].data.slice(0));
  16732. }
  16733. for (var i in this.attributes) {
  16734. var attrib = this.attributes[i];
  16735. geometry.attributes[i] = new Attribute(attrib.buffer, attrib.size, attrib.normalized, attrib.type, attrib.stride, attrib.start, attrib.instance);
  16736. }
  16737. if (this.indexBuffer) {
  16738. geometry.indexBuffer = geometry.buffers[this.buffers.indexOf(this.indexBuffer)];
  16739. geometry.indexBuffer.type = exports.BUFFER_TYPE.ELEMENT_ARRAY_BUFFER;
  16740. }
  16741. return geometry;
  16742. };
  16743. /**
  16744. * merges an array of geometries into a new single one
  16745. * geometry attribute styles must match for this operation to work
  16746. *
  16747. * @param {PIXI.Geometry[]} geometries - array of geometries to merge
  16748. * @returns {PIXI.Geometry} shiny new geometry!
  16749. */
  16750. Geometry.merge = function (geometries) {
  16751. // todo add a geometry check!
  16752. // also a size check.. cant be too big!]
  16753. var geometryOut = new Geometry();
  16754. var arrays = [];
  16755. var sizes = [];
  16756. var offsets = [];
  16757. var geometry;
  16758. // pass one.. get sizes..
  16759. for (var i = 0; i < geometries.length; i++) {
  16760. geometry = geometries[i];
  16761. for (var j = 0; j < geometry.buffers.length; j++) {
  16762. sizes[j] = sizes[j] || 0;
  16763. sizes[j] += geometry.buffers[j].data.length;
  16764. offsets[j] = 0;
  16765. }
  16766. }
  16767. // build the correct size arrays..
  16768. for (var i = 0; i < geometry.buffers.length; i++) {
  16769. // TODO types!
  16770. arrays[i] = new map$1$1[getBufferType(geometry.buffers[i].data)](sizes[i]);
  16771. geometryOut.buffers[i] = new Buffer(arrays[i]);
  16772. }
  16773. // pass to set data..
  16774. for (var i = 0; i < geometries.length; i++) {
  16775. geometry = geometries[i];
  16776. for (var j = 0; j < geometry.buffers.length; j++) {
  16777. arrays[j].set(geometry.buffers[j].data, offsets[j]);
  16778. offsets[j] += geometry.buffers[j].data.length;
  16779. }
  16780. }
  16781. geometryOut.attributes = geometry.attributes;
  16782. if (geometry.indexBuffer) {
  16783. geometryOut.indexBuffer = geometryOut.buffers[geometry.buffers.indexOf(geometry.indexBuffer)];
  16784. geometryOut.indexBuffer.type = exports.BUFFER_TYPE.ELEMENT_ARRAY_BUFFER;
  16785. var offset = 0;
  16786. var stride = 0;
  16787. var offset2 = 0;
  16788. var bufferIndexToCount = 0;
  16789. // get a buffer
  16790. for (var i = 0; i < geometry.buffers.length; i++) {
  16791. if (geometry.buffers[i] !== geometry.indexBuffer) {
  16792. bufferIndexToCount = i;
  16793. break;
  16794. }
  16795. }
  16796. // figure out the stride of one buffer..
  16797. for (var i in geometry.attributes) {
  16798. var attribute = geometry.attributes[i];
  16799. if ((attribute.buffer | 0) === bufferIndexToCount) {
  16800. stride += ((attribute.size * byteSizeMap[attribute.type]) / 4);
  16801. }
  16802. }
  16803. // time to off set all indexes..
  16804. for (var i = 0; i < geometries.length; i++) {
  16805. var indexBufferData = geometries[i].indexBuffer.data;
  16806. for (var j = 0; j < indexBufferData.length; j++) {
  16807. geometryOut.indexBuffer.data[j + offset2] += offset;
  16808. }
  16809. offset += geometries[i].buffers[bufferIndexToCount].data.length / (stride);
  16810. offset2 += indexBufferData.length;
  16811. }
  16812. }
  16813. return geometryOut;
  16814. };
  16815. return Geometry;
  16816. }());
  16817. /**
  16818. * Helper class to create a quad
  16819. *
  16820. * @class
  16821. * @memberof PIXI
  16822. */
  16823. var Quad = /** @class */ (function (_super) {
  16824. __extends$2(Quad, _super);
  16825. function Quad() {
  16826. var _this = _super.call(this) || this;
  16827. _this.addAttribute('aVertexPosition', new Float32Array([
  16828. 0, 0,
  16829. 1, 0,
  16830. 1, 1,
  16831. 0, 1 ]))
  16832. .addIndex([0, 1, 3, 2]);
  16833. return _this;
  16834. }
  16835. return Quad;
  16836. }(Geometry));
  16837. /**
  16838. * Helper class to create a quad with uvs like in v4
  16839. *
  16840. * @class
  16841. * @memberof PIXI
  16842. * @extends PIXI.Geometry
  16843. */
  16844. var QuadUv = /** @class */ (function (_super) {
  16845. __extends$2(QuadUv, _super);
  16846. function QuadUv() {
  16847. var _this = _super.call(this) || this;
  16848. /**
  16849. * An array of vertices
  16850. *
  16851. * @member {Float32Array}
  16852. */
  16853. _this.vertices = new Float32Array([
  16854. -1, -1,
  16855. 1, -1,
  16856. 1, 1,
  16857. -1, 1 ]);
  16858. /**
  16859. * The Uvs of the quad
  16860. *
  16861. * @member {Float32Array}
  16862. */
  16863. _this.uvs = new Float32Array([
  16864. 0, 0,
  16865. 1, 0,
  16866. 1, 1,
  16867. 0, 1 ]);
  16868. _this.vertexBuffer = new Buffer(_this.vertices);
  16869. _this.uvBuffer = new Buffer(_this.uvs);
  16870. _this.addAttribute('aVertexPosition', _this.vertexBuffer)
  16871. .addAttribute('aTextureCoord', _this.uvBuffer)
  16872. .addIndex([0, 1, 2, 0, 2, 3]);
  16873. return _this;
  16874. }
  16875. /**
  16876. * Maps two Rectangle to the quad.
  16877. *
  16878. * @param {PIXI.Rectangle} targetTextureFrame - the first rectangle
  16879. * @param {PIXI.Rectangle} destinationFrame - the second rectangle
  16880. * @return {PIXI.Quad} Returns itself.
  16881. */
  16882. QuadUv.prototype.map = function (targetTextureFrame, destinationFrame) {
  16883. var x = 0; // destinationFrame.x / targetTextureFrame.width;
  16884. var y = 0; // destinationFrame.y / targetTextureFrame.height;
  16885. this.uvs[0] = x;
  16886. this.uvs[1] = y;
  16887. this.uvs[2] = x + (destinationFrame.width / targetTextureFrame.width);
  16888. this.uvs[3] = y;
  16889. this.uvs[4] = x + (destinationFrame.width / targetTextureFrame.width);
  16890. this.uvs[5] = y + (destinationFrame.height / targetTextureFrame.height);
  16891. this.uvs[6] = x;
  16892. this.uvs[7] = y + (destinationFrame.height / targetTextureFrame.height);
  16893. x = destinationFrame.x;
  16894. y = destinationFrame.y;
  16895. this.vertices[0] = x;
  16896. this.vertices[1] = y;
  16897. this.vertices[2] = x + destinationFrame.width;
  16898. this.vertices[3] = y;
  16899. this.vertices[4] = x + destinationFrame.width;
  16900. this.vertices[5] = y + destinationFrame.height;
  16901. this.vertices[6] = x;
  16902. this.vertices[7] = y + destinationFrame.height;
  16903. this.invalidate();
  16904. return this;
  16905. };
  16906. /**
  16907. * legacy upload method, just marks buffers dirty
  16908. * @returns {PIXI.QuadUv} Returns itself.
  16909. */
  16910. QuadUv.prototype.invalidate = function () {
  16911. this.vertexBuffer._updateID++;
  16912. this.uvBuffer._updateID++;
  16913. return this;
  16914. };
  16915. return QuadUv;
  16916. }(Geometry));
  16917. var UID$2 = 0;
  16918. /**
  16919. * Uniform group holds uniform map and some ID's for work
  16920. *
  16921. * `UniformGroup` has two modes:
  16922. *
  16923. * 1: Normal mode
  16924. * Normal mode will upload the uniforms with individual function calls as required
  16925. *
  16926. * 2: Uniform buffer mode
  16927. * This mode will treat the uniforms as a uniform buffer. You can pass in either a buffer that you manually handle, or
  16928. * or a generic object that PixiJS will automatically map to a buffer for you.
  16929. * For maximum benefits, make Ubo UniformGroups static, and only update them each frame.
  16930. *
  16931. * Rules of UBOs:
  16932. * - UBOs only work with WebGL2, so make sure you have a fallback!
  16933. * - Only floats are supported (including vec[2,3,4], mat[2,3,4])
  16934. * - Samplers cannot be used in ubo's (a GPU limitation)
  16935. * - You must ensure that the object you pass in exactly matches in the shader ubo structure.
  16936. * Otherwise, weirdness will ensue!
  16937. * - The name of the ubo object added to the group must match exactly the name of the ubo in the shader.
  16938. *
  16939. * ```
  16940. * // ubo in shader:
  16941. * uniform myCoolData { // declaring a ubo..
  16942. * mat4 uCoolMatrix;
  16943. * float uFloatyMcFloatFace
  16944. *
  16945. *
  16946. * // a new uniform buffer object..
  16947. * const myCoolData = new UniformBufferGroup({
  16948. * uCoolMatrix: new Matrix(),
  16949. * uFloatyMcFloatFace: 23,
  16950. * }}
  16951. *
  16952. * // build a shader...
  16953. * const shader = Shader.from(srcVert, srcFrag, {
  16954. * myCoolData // name matches the ubo name in the shader. will be processed accordingly.
  16955. * })
  16956. *
  16957. * ```
  16958. *
  16959. * @class
  16960. * @memberof PIXI
  16961. */
  16962. var UniformGroup = /** @class */ (function () {
  16963. /**
  16964. * @param {object | Buffer} [uniforms] - Custom uniforms to use to augment the built-in ones. Or a pixi buffer
  16965. * @param {boolean} [isStatic] - Uniforms wont be changed after creation
  16966. * @param {boolean} [isUbo] - if true, will treat this uniform group as a uniform buffer object
  16967. */
  16968. function UniformGroup(uniforms, isStatic, isUbo) {
  16969. /**
  16970. * Its a group and not a single uniforms
  16971. * @member {boolean}
  16972. * @readonly
  16973. * @default true
  16974. */
  16975. this.group = true;
  16976. // lets generate this when the shader ?
  16977. this.syncUniforms = {};
  16978. /**
  16979. * dirty version
  16980. * @protected
  16981. * @member {number}
  16982. */
  16983. this.dirtyId = 0;
  16984. /**
  16985. * unique id
  16986. * @protected
  16987. * @member {number}
  16988. */
  16989. this.id = UID$2++;
  16990. /**
  16991. * Uniforms wont be changed after creation
  16992. * @member {boolean}
  16993. */
  16994. this.static = !!isStatic;
  16995. /**
  16996. * Flags whether this group is treated like a uniform buffer object.
  16997. * @member {boolean}
  16998. */
  16999. this.ubo = !!isUbo;
  17000. if (uniforms instanceof Buffer) {
  17001. this.buffer = uniforms;
  17002. this.buffer.type = exports.BUFFER_TYPE.UNIFORM_BUFFER;
  17003. this.autoManage = false;
  17004. this.ubo = true;
  17005. }
  17006. else {
  17007. /**
  17008. * uniform values
  17009. * @member {object}
  17010. * @readonly
  17011. */
  17012. this.uniforms = uniforms;
  17013. if (this.ubo) {
  17014. this.buffer = new Buffer(new Float32Array(1));
  17015. this.buffer.type = exports.BUFFER_TYPE.UNIFORM_BUFFER;
  17016. this.autoManage = true;
  17017. }
  17018. }
  17019. }
  17020. UniformGroup.prototype.update = function () {
  17021. this.dirtyId++;
  17022. if (!this.autoManage && this.buffer) {
  17023. this.buffer.update();
  17024. }
  17025. };
  17026. UniformGroup.prototype.add = function (name, uniforms, _static) {
  17027. if (!this.ubo) {
  17028. this.uniforms[name] = new UniformGroup(uniforms, _static);
  17029. }
  17030. else {
  17031. // eslint-disable-next-line max-len
  17032. throw new Error('[UniformGroup] uniform groups in ubo mode cannot be modified, or have uniform groups nested in them');
  17033. }
  17034. };
  17035. UniformGroup.from = function (uniforms, _static, _ubo) {
  17036. return new UniformGroup(uniforms, _static, _ubo);
  17037. };
  17038. /**
  17039. * A short hand function for creating a static UBO UniformGroup.
  17040. *
  17041. * @param uniforms - the ubo item
  17042. * @param _static - should this be updated each time it is used? defaults to true here!
  17043. */
  17044. UniformGroup.uboFrom = function (uniforms, _static) {
  17045. return new UniformGroup(uniforms, _static !== null && _static !== void 0 ? _static : true, true);
  17046. };
  17047. return UniformGroup;
  17048. }());
  17049. /**
  17050. * System plugin to the renderer to manage filter states.
  17051. *
  17052. * @class
  17053. * @private
  17054. */
  17055. var FilterState = /** @class */ (function () {
  17056. function FilterState() {
  17057. this.renderTexture = null;
  17058. /**
  17059. * Target of the filters
  17060. * We store for case when custom filter wants to know the element it was applied on
  17061. * @member {PIXI.DisplayObject}
  17062. * @private
  17063. */
  17064. this.target = null;
  17065. /**
  17066. * Compatibility with PixiJS v4 filters
  17067. * @member {boolean}
  17068. * @default false
  17069. * @private
  17070. */
  17071. this.legacy = false;
  17072. /**
  17073. * Resolution of filters
  17074. * @member {number}
  17075. * @default 1
  17076. * @private
  17077. */
  17078. this.resolution = 1;
  17079. /**
  17080. * Number of samples
  17081. * @member {PIXI.MSAA_QUALITY}
  17082. * @default MSAA_QUALITY.NONE
  17083. * @private
  17084. */
  17085. this.multisample = exports.MSAA_QUALITY.NONE;
  17086. // next three fields are created only for root
  17087. // re-assigned for everything else
  17088. /**
  17089. * Source frame
  17090. * @member {PIXI.Rectangle}
  17091. * @private
  17092. */
  17093. this.sourceFrame = new Rectangle();
  17094. /**
  17095. * Destination frame
  17096. * @member {PIXI.Rectangle}
  17097. * @private
  17098. */
  17099. this.destinationFrame = new Rectangle();
  17100. /**
  17101. * Original render-target source frame
  17102. * @private
  17103. */
  17104. this.bindingSourceFrame = new Rectangle();
  17105. /**
  17106. * Original render-target destination frame
  17107. * @private
  17108. */
  17109. this.bindingDestinationFrame = new Rectangle();
  17110. /**
  17111. * Collection of filters
  17112. * @member {PIXI.Filter[]}
  17113. * @private
  17114. */
  17115. this.filters = [];
  17116. /**
  17117. * Projection system transform saved by link.
  17118. * @member {PIXI.Matrix}
  17119. * @private
  17120. */
  17121. this.transform = null;
  17122. }
  17123. /**
  17124. * clears the state
  17125. * @private
  17126. */
  17127. FilterState.prototype.clear = function () {
  17128. this.target = null;
  17129. this.filters = null;
  17130. this.renderTexture = null;
  17131. };
  17132. return FilterState;
  17133. }());
  17134. var tempPoints = [new Point(), new Point(), new Point(), new Point()];
  17135. var tempMatrix = new Matrix();
  17136. /**
  17137. * System plugin to the renderer to manage filters.
  17138. *
  17139. * ## Pipeline
  17140. *
  17141. * The FilterSystem executes the filtering pipeline by rendering the display-object into a texture, applying its
  17142. * [filters]{@link PIXI.Filter} in series, and the last filter outputs into the final render-target.
  17143. *
  17144. * The filter-frame is the rectangle in world space being filtered, and those contents are mapped into
  17145. * `(0, 0, filterFrame.width, filterFrame.height)` into the filter render-texture. The filter-frame is also called
  17146. * the source-frame, as it is used to bind the filter render-textures. The last filter outputs to the `filterFrame`
  17147. * in the final render-target.
  17148. *
  17149. * ## Usage
  17150. *
  17151. * {@link PIXI.Container#renderAdvanced} is an example of how to use the filter system. It is a 3 step process:
  17152. *
  17153. * * **push**: Use {@link PIXI.FilterSystem#push} to push the set of filters to be applied on a filter-target.
  17154. * * **render**: Render the contents to be filtered using the renderer. The filter-system will only capture the contents
  17155. * inside the bounds of the filter-target. NOTE: Using {@link PIXI.Renderer#render} is
  17156. * illegal during an existing render cycle, and it may reset the filter system.
  17157. * * **pop**: Use {@link PIXI.FilterSystem#pop} to pop & execute the filters you initially pushed. It will apply them
  17158. * serially and output to the bounds of the filter-target.
  17159. *
  17160. * @class
  17161. * @memberof PIXI
  17162. * @extends PIXI.System
  17163. */
  17164. var FilterSystem = /** @class */ (function () {
  17165. /**
  17166. * @param {PIXI.Renderer} renderer - The renderer this System works for.
  17167. */
  17168. function FilterSystem(renderer) {
  17169. this.renderer = renderer;
  17170. /**
  17171. * List of filters for the FilterSystem
  17172. * @member {Object[]}
  17173. * @readonly
  17174. */
  17175. this.defaultFilterStack = [{}];
  17176. /**
  17177. * stores a bunch of PO2 textures used for filtering
  17178. * @member {Object}
  17179. */
  17180. this.texturePool = new RenderTexturePool();
  17181. this.texturePool.setScreenSize(renderer.view);
  17182. /**
  17183. * a pool for storing filter states, save us creating new ones each tick
  17184. * @member {Object[]}
  17185. */
  17186. this.statePool = [];
  17187. /**
  17188. * A very simple geometry used when drawing a filter effect to the screen
  17189. * @member {PIXI.Quad}
  17190. */
  17191. this.quad = new Quad();
  17192. /**
  17193. * Quad UVs
  17194. * @member {PIXI.QuadUv}
  17195. */
  17196. this.quadUv = new QuadUv();
  17197. /**
  17198. * Temporary rect for maths
  17199. * @type {PIXI.Rectangle}
  17200. */
  17201. this.tempRect = new Rectangle();
  17202. /**
  17203. * Active state
  17204. * @member {object}
  17205. */
  17206. this.activeState = {};
  17207. /**
  17208. * This uniform group is attached to filter uniforms when used
  17209. * @member {PIXI.UniformGroup}
  17210. * @property {PIXI.Rectangle} outputFrame
  17211. * @property {Float32Array} inputSize
  17212. * @property {Float32Array} inputPixel
  17213. * @property {Float32Array} inputClamp
  17214. * @property {Number} resolution
  17215. * @property {Float32Array} filterArea
  17216. * @property {Float32Array} filterClamp
  17217. */
  17218. this.globalUniforms = new UniformGroup({
  17219. outputFrame: new Rectangle(),
  17220. inputSize: new Float32Array(4),
  17221. inputPixel: new Float32Array(4),
  17222. inputClamp: new Float32Array(4),
  17223. resolution: 1,
  17224. // legacy variables
  17225. filterArea: new Float32Array(4),
  17226. filterClamp: new Float32Array(4),
  17227. }, true);
  17228. /**
  17229. * Whether to clear output renderTexture in AUTO/BLIT mode. See {@link PIXI.CLEAR_MODES}
  17230. * @member {boolean}
  17231. */
  17232. this.forceClear = false;
  17233. /**
  17234. * Old padding behavior is to use the max amount instead of sum padding.
  17235. * Use this flag if you need the old behavior.
  17236. * @member {boolean}
  17237. * @default false
  17238. */
  17239. this.useMaxPadding = false;
  17240. }
  17241. /**
  17242. * Pushes a set of filters to be applied later to the system. This will redirect further rendering into an
  17243. * input render-texture for the rest of the filtering pipeline.
  17244. *
  17245. * @param {PIXI.DisplayObject} target - The target of the filter to render.
  17246. * @param {PIXI.Filter[]} filters - The filters to apply.
  17247. */
  17248. FilterSystem.prototype.push = function (target, filters) {
  17249. var renderer = this.renderer;
  17250. var filterStack = this.defaultFilterStack;
  17251. var state = this.statePool.pop() || new FilterState();
  17252. var renderTextureSystem = this.renderer.renderTexture;
  17253. var resolution = filters[0].resolution;
  17254. var multisample = filters[0].multisample;
  17255. var padding = filters[0].padding;
  17256. var autoFit = filters[0].autoFit;
  17257. var legacy = filters[0].legacy;
  17258. for (var i = 1; i < filters.length; i++) {
  17259. var filter = filters[i];
  17260. // let's use the lowest resolution
  17261. resolution = Math.min(resolution, filter.resolution);
  17262. // let's use the lowest number of samples
  17263. multisample = Math.min(multisample, filter.multisample);
  17264. // figure out the padding required for filters
  17265. padding = this.useMaxPadding
  17266. // old behavior: use largest amount of padding!
  17267. ? Math.max(padding, filter.padding)
  17268. // new behavior: sum the padding
  17269. : padding + filter.padding;
  17270. // only auto fit if all filters are autofit
  17271. autoFit = autoFit && filter.autoFit;
  17272. legacy = legacy || filter.legacy;
  17273. }
  17274. if (filterStack.length === 1) {
  17275. this.defaultFilterStack[0].renderTexture = renderTextureSystem.current;
  17276. }
  17277. filterStack.push(state);
  17278. state.resolution = resolution;
  17279. state.multisample = multisample;
  17280. state.legacy = legacy;
  17281. state.target = target;
  17282. state.sourceFrame.copyFrom(target.filterArea || target.getBounds(true));
  17283. state.sourceFrame.pad(padding);
  17284. if (autoFit) {
  17285. var sourceFrameProjected = this.tempRect.copyFrom(renderTextureSystem.sourceFrame);
  17286. // Project source frame into world space (if projection is applied)
  17287. if (renderer.projection.transform) {
  17288. this.transformAABB(tempMatrix.copyFrom(renderer.projection.transform).invert(), sourceFrameProjected);
  17289. }
  17290. state.sourceFrame.fit(sourceFrameProjected);
  17291. }
  17292. // Round sourceFrame in screen space based on render-texture.
  17293. this.roundFrame(state.sourceFrame, renderTextureSystem.current ? renderTextureSystem.current.resolution : renderer.resolution, renderTextureSystem.sourceFrame, renderTextureSystem.destinationFrame, renderer.projection.transform);
  17294. state.renderTexture = this.getOptimalFilterTexture(state.sourceFrame.width, state.sourceFrame.height, resolution, multisample);
  17295. state.filters = filters;
  17296. state.destinationFrame.width = state.renderTexture.width;
  17297. state.destinationFrame.height = state.renderTexture.height;
  17298. var destinationFrame = this.tempRect;
  17299. destinationFrame.x = 0;
  17300. destinationFrame.y = 0;
  17301. destinationFrame.width = state.sourceFrame.width;
  17302. destinationFrame.height = state.sourceFrame.height;
  17303. state.renderTexture.filterFrame = state.sourceFrame;
  17304. state.bindingSourceFrame.copyFrom(renderTextureSystem.sourceFrame);
  17305. state.bindingDestinationFrame.copyFrom(renderTextureSystem.destinationFrame);
  17306. state.transform = renderer.projection.transform;
  17307. renderer.projection.transform = null;
  17308. renderTextureSystem.bind(state.renderTexture, state.sourceFrame, destinationFrame);
  17309. renderer.framebuffer.clear(0, 0, 0, 0);
  17310. };
  17311. /**
  17312. * Pops off the filter and applies it.
  17313. */
  17314. FilterSystem.prototype.pop = function () {
  17315. var filterStack = this.defaultFilterStack;
  17316. var state = filterStack.pop();
  17317. var filters = state.filters;
  17318. this.activeState = state;
  17319. var globalUniforms = this.globalUniforms.uniforms;
  17320. globalUniforms.outputFrame = state.sourceFrame;
  17321. globalUniforms.resolution = state.resolution;
  17322. var inputSize = globalUniforms.inputSize;
  17323. var inputPixel = globalUniforms.inputPixel;
  17324. var inputClamp = globalUniforms.inputClamp;
  17325. inputSize[0] = state.destinationFrame.width;
  17326. inputSize[1] = state.destinationFrame.height;
  17327. inputSize[2] = 1.0 / inputSize[0];
  17328. inputSize[3] = 1.0 / inputSize[1];
  17329. inputPixel[0] = Math.round(inputSize[0] * state.resolution);
  17330. inputPixel[1] = Math.round(inputSize[1] * state.resolution);
  17331. inputPixel[2] = 1.0 / inputPixel[0];
  17332. inputPixel[3] = 1.0 / inputPixel[1];
  17333. inputClamp[0] = 0.5 * inputPixel[2];
  17334. inputClamp[1] = 0.5 * inputPixel[3];
  17335. inputClamp[2] = (state.sourceFrame.width * inputSize[2]) - (0.5 * inputPixel[2]);
  17336. inputClamp[3] = (state.sourceFrame.height * inputSize[3]) - (0.5 * inputPixel[3]);
  17337. // only update the rect if its legacy..
  17338. if (state.legacy) {
  17339. var filterArea = globalUniforms.filterArea;
  17340. filterArea[0] = state.destinationFrame.width;
  17341. filterArea[1] = state.destinationFrame.height;
  17342. filterArea[2] = state.sourceFrame.x;
  17343. filterArea[3] = state.sourceFrame.y;
  17344. globalUniforms.filterClamp = globalUniforms.inputClamp;
  17345. }
  17346. this.globalUniforms.update();
  17347. var lastState = filterStack[filterStack.length - 1];
  17348. this.renderer.framebuffer.blit();
  17349. if (filters.length === 1) {
  17350. filters[0].apply(this, state.renderTexture, lastState.renderTexture, exports.CLEAR_MODES.BLEND, state);
  17351. this.returnFilterTexture(state.renderTexture);
  17352. }
  17353. else {
  17354. var flip = state.renderTexture;
  17355. var flop = this.getOptimalFilterTexture(flip.width, flip.height, state.resolution);
  17356. flop.filterFrame = flip.filterFrame;
  17357. var i = 0;
  17358. for (i = 0; i < filters.length - 1; ++i) {
  17359. if (i === 1 && state.multisample > 1) {
  17360. flop = this.getOptimalFilterTexture(flip.width, flip.height, state.resolution);
  17361. flop.filterFrame = flip.filterFrame;
  17362. }
  17363. filters[i].apply(this, flip, flop, exports.CLEAR_MODES.CLEAR, state);
  17364. var t = flip;
  17365. flip = flop;
  17366. flop = t;
  17367. }
  17368. filters[i].apply(this, flip, lastState.renderTexture, exports.CLEAR_MODES.BLEND, state);
  17369. if (i > 1 && state.multisample > 1) {
  17370. this.returnFilterTexture(state.renderTexture);
  17371. }
  17372. this.returnFilterTexture(flip);
  17373. this.returnFilterTexture(flop);
  17374. }
  17375. // lastState.renderTexture is blitted when lastState is popped
  17376. state.clear();
  17377. this.statePool.push(state);
  17378. };
  17379. /**
  17380. * Binds a renderTexture with corresponding `filterFrame`, clears it if mode corresponds.
  17381. *
  17382. * @param {PIXI.RenderTexture} filterTexture - renderTexture to bind, should belong to filter pool or filter stack
  17383. * @param {PIXI.CLEAR_MODES} [clearMode] - clearMode, by default its CLEAR/YES. See {@link PIXI.CLEAR_MODES}
  17384. */
  17385. FilterSystem.prototype.bindAndClear = function (filterTexture, clearMode) {
  17386. if (clearMode === void 0) { clearMode = exports.CLEAR_MODES.CLEAR; }
  17387. var _a = this.renderer, renderTextureSystem = _a.renderTexture, stateSystem = _a.state;
  17388. if (filterTexture === this.defaultFilterStack[this.defaultFilterStack.length - 1].renderTexture) {
  17389. // Restore projection transform if rendering into the output render-target.
  17390. this.renderer.projection.transform = this.activeState.transform;
  17391. }
  17392. else {
  17393. // Prevent projection within filtering pipeline.
  17394. this.renderer.projection.transform = null;
  17395. }
  17396. if (filterTexture && filterTexture.filterFrame) {
  17397. var destinationFrame = this.tempRect;
  17398. destinationFrame.x = 0;
  17399. destinationFrame.y = 0;
  17400. destinationFrame.width = filterTexture.filterFrame.width;
  17401. destinationFrame.height = filterTexture.filterFrame.height;
  17402. renderTextureSystem.bind(filterTexture, filterTexture.filterFrame, destinationFrame);
  17403. }
  17404. else if (filterTexture !== this.defaultFilterStack[this.defaultFilterStack.length - 1].renderTexture) {
  17405. renderTextureSystem.bind(filterTexture);
  17406. }
  17407. else {
  17408. // Restore binding for output render-target.
  17409. this.renderer.renderTexture.bind(filterTexture, this.activeState.bindingSourceFrame, this.activeState.bindingDestinationFrame);
  17410. }
  17411. // Clear the texture in BLIT mode if blending is disabled or the forceClear flag is set. The blending
  17412. // is stored in the 0th bit of the state.
  17413. var autoClear = (stateSystem.stateId & 1) || this.forceClear;
  17414. if (clearMode === exports.CLEAR_MODES.CLEAR
  17415. || (clearMode === exports.CLEAR_MODES.BLIT && autoClear)) {
  17416. // Use framebuffer.clear because we want to clear the whole filter texture, not just the filtering
  17417. // area over which the shaders are run. This is because filters may sampling outside of it (e.g. blur)
  17418. // instead of clamping their arithmetic.
  17419. this.renderer.framebuffer.clear(0, 0, 0, 0);
  17420. }
  17421. };
  17422. /**
  17423. * Draws a filter.
  17424. *
  17425. * @param {PIXI.Filter} filter - The filter to draw.
  17426. * @param {PIXI.RenderTexture} input - The input render target.
  17427. * @param {PIXI.RenderTexture} output - The target to output to.
  17428. * @param {PIXI.CLEAR_MODES} [clearMode] - Should the output be cleared before rendering to it
  17429. */
  17430. FilterSystem.prototype.applyFilter = function (filter, input, output, clearMode) {
  17431. var renderer = this.renderer;
  17432. // Set state before binding, so bindAndClear gets the blend mode.
  17433. renderer.state.set(filter.state);
  17434. this.bindAndClear(output, clearMode);
  17435. // set the uniforms..
  17436. filter.uniforms.uSampler = input;
  17437. filter.uniforms.filterGlobals = this.globalUniforms;
  17438. // TODO make it so that the order of this does not matter..
  17439. // because it does at the moment cos of global uniforms.
  17440. // they need to get resynced
  17441. renderer.shader.bind(filter);
  17442. // check to see if the filter is a legacy one..
  17443. filter.legacy = !!filter.program.attributeData.aTextureCoord;
  17444. if (filter.legacy) {
  17445. this.quadUv.map(input._frame, input.filterFrame);
  17446. renderer.geometry.bind(this.quadUv);
  17447. renderer.geometry.draw(exports.DRAW_MODES.TRIANGLES);
  17448. }
  17449. else {
  17450. renderer.geometry.bind(this.quad);
  17451. renderer.geometry.draw(exports.DRAW_MODES.TRIANGLE_STRIP);
  17452. }
  17453. };
  17454. /**
  17455. * Multiply _input normalized coordinates_ to this matrix to get _sprite texture normalized coordinates_.
  17456. *
  17457. * Use `outputMatrix * vTextureCoord` in the shader.
  17458. *
  17459. * @param {PIXI.Matrix} outputMatrix - The matrix to output to.
  17460. * @param {PIXI.Sprite} sprite - The sprite to map to.
  17461. * @return {PIXI.Matrix} The mapped matrix.
  17462. */
  17463. FilterSystem.prototype.calculateSpriteMatrix = function (outputMatrix, sprite) {
  17464. var _a = this.activeState, sourceFrame = _a.sourceFrame, destinationFrame = _a.destinationFrame;
  17465. var orig = sprite._texture.orig;
  17466. var mappedMatrix = outputMatrix.set(destinationFrame.width, 0, 0, destinationFrame.height, sourceFrame.x, sourceFrame.y);
  17467. var worldTransform = sprite.worldTransform.copyTo(Matrix.TEMP_MATRIX);
  17468. worldTransform.invert();
  17469. mappedMatrix.prepend(worldTransform);
  17470. mappedMatrix.scale(1.0 / orig.width, 1.0 / orig.height);
  17471. mappedMatrix.translate(sprite.anchor.x, sprite.anchor.y);
  17472. return mappedMatrix;
  17473. };
  17474. /**
  17475. * Destroys this Filter System.
  17476. */
  17477. FilterSystem.prototype.destroy = function () {
  17478. this.renderer = null;
  17479. // Those textures has to be destroyed by RenderTextureSystem or FramebufferSystem
  17480. this.texturePool.clear(false);
  17481. };
  17482. /**
  17483. * Gets a Power-of-Two render texture or fullScreen texture
  17484. *
  17485. * @protected
  17486. * @param {number} minWidth - The minimum width of the render texture in real pixels.
  17487. * @param {number} minHeight - The minimum height of the render texture in real pixels.
  17488. * @param {number} [resolution=1] - The resolution of the render texture.
  17489. * @param {PIXI.MSAA_QUALITY} [multisample=PIXI.MSAA_QUALITY.NONE] - Number of samples of the render texture.
  17490. * @return {PIXI.RenderTexture} The new render texture.
  17491. */
  17492. FilterSystem.prototype.getOptimalFilterTexture = function (minWidth, minHeight, resolution, multisample) {
  17493. if (resolution === void 0) { resolution = 1; }
  17494. if (multisample === void 0) { multisample = exports.MSAA_QUALITY.NONE; }
  17495. return this.texturePool.getOptimalTexture(minWidth, minHeight, resolution, multisample);
  17496. };
  17497. /**
  17498. * Gets extra render texture to use inside current filter
  17499. * To be compliant with older filters, you can use params in any order
  17500. *
  17501. * @param {PIXI.RenderTexture} [input] - renderTexture from which size and resolution will be copied
  17502. * @param {number} [resolution] - override resolution of the renderTexture
  17503. * @param {PIXI.MSAA_QUALITY} [multisample=PIXI.MSAA_QUALITY.NONE] - number of samples of the renderTexture
  17504. * @returns {PIXI.RenderTexture}
  17505. */
  17506. FilterSystem.prototype.getFilterTexture = function (input, resolution, multisample) {
  17507. if (typeof input === 'number') {
  17508. var swap = input;
  17509. input = resolution;
  17510. resolution = swap;
  17511. }
  17512. input = input || this.activeState.renderTexture;
  17513. var filterTexture = this.texturePool.getOptimalTexture(input.width, input.height, resolution || input.resolution, multisample || exports.MSAA_QUALITY.NONE);
  17514. filterTexture.filterFrame = input.filterFrame;
  17515. return filterTexture;
  17516. };
  17517. /**
  17518. * Frees a render texture back into the pool.
  17519. *
  17520. * @param {PIXI.RenderTexture} renderTexture - The renderTarget to free
  17521. */
  17522. FilterSystem.prototype.returnFilterTexture = function (renderTexture) {
  17523. this.texturePool.returnTexture(renderTexture);
  17524. };
  17525. /**
  17526. * Empties the texture pool.
  17527. */
  17528. FilterSystem.prototype.emptyPool = function () {
  17529. this.texturePool.clear(true);
  17530. };
  17531. /**
  17532. * calls `texturePool.resize()`, affects fullScreen renderTextures
  17533. */
  17534. FilterSystem.prototype.resize = function () {
  17535. this.texturePool.setScreenSize(this.renderer.view);
  17536. };
  17537. /**
  17538. * @param {PIXI.Matrix} matrix - first param
  17539. * @param {PIXI.Rectangle} rect - second param
  17540. */
  17541. FilterSystem.prototype.transformAABB = function (matrix, rect) {
  17542. var lt = tempPoints[0];
  17543. var lb = tempPoints[1];
  17544. var rt = tempPoints[2];
  17545. var rb = tempPoints[3];
  17546. lt.set(rect.left, rect.top);
  17547. lb.set(rect.left, rect.bottom);
  17548. rt.set(rect.right, rect.top);
  17549. rb.set(rect.right, rect.bottom);
  17550. matrix.apply(lt, lt);
  17551. matrix.apply(lb, lb);
  17552. matrix.apply(rt, rt);
  17553. matrix.apply(rb, rb);
  17554. var x0 = Math.min(lt.x, lb.x, rt.x, rb.x);
  17555. var y0 = Math.min(lt.y, lb.y, rt.y, rb.y);
  17556. var x1 = Math.max(lt.x, lb.x, rt.x, rb.x);
  17557. var y1 = Math.max(lt.y, lb.y, rt.y, rb.y);
  17558. rect.x = x0;
  17559. rect.y = y0;
  17560. rect.width = x1 - x0;
  17561. rect.height = y1 - y0;
  17562. };
  17563. FilterSystem.prototype.roundFrame = function (frame, resolution, bindingSourceFrame, bindingDestinationFrame, transform) {
  17564. if (transform) {
  17565. var a = transform.a, b = transform.b, c = transform.c, d = transform.d;
  17566. // Skip if skew/rotation present in matrix, except for multiple of 90° rotation. If rotation
  17567. // is a multiple of 90°, then either pair of (b,c) or (a,d) will be (0,0).
  17568. if ((Math.abs(b) > 1e-4 || Math.abs(c) > 1e-4)
  17569. && (Math.abs(a) > 1e-4 || Math.abs(d) > 1e-4)) {
  17570. return;
  17571. }
  17572. }
  17573. transform = transform ? tempMatrix.copyFrom(transform) : tempMatrix.identity();
  17574. // Get forward transform from world space to screen space
  17575. transform
  17576. .translate(-bindingSourceFrame.x, -bindingSourceFrame.y)
  17577. .scale(bindingDestinationFrame.width / bindingSourceFrame.width, bindingDestinationFrame.height / bindingSourceFrame.height)
  17578. .translate(bindingDestinationFrame.x, bindingDestinationFrame.y);
  17579. // Convert frame to screen space
  17580. this.transformAABB(transform, frame);
  17581. // Round frame in screen space
  17582. frame.ceil(resolution);
  17583. // Project back into world space.
  17584. this.transformAABB(transform.invert(), frame);
  17585. };
  17586. return FilterSystem;
  17587. }());
  17588. /**
  17589. * Base for a common object renderer that can be used as a
  17590. * system renderer plugin.
  17591. *
  17592. * @class
  17593. * @extends PIXI.System
  17594. * @memberof PIXI
  17595. */
  17596. var ObjectRenderer = /** @class */ (function () {
  17597. /**
  17598. * @param {PIXI.Renderer} renderer - The renderer this manager works for.
  17599. */
  17600. function ObjectRenderer(renderer) {
  17601. /**
  17602. * The renderer this manager works for.
  17603. *
  17604. * @member {PIXI.Renderer}
  17605. */
  17606. this.renderer = renderer;
  17607. }
  17608. /**
  17609. * Stub method that should be used to empty the current
  17610. * batch by rendering objects now.
  17611. */
  17612. ObjectRenderer.prototype.flush = function () {
  17613. // flush!
  17614. };
  17615. /**
  17616. * Generic destruction method that frees all resources. This
  17617. * should be called by subclasses.
  17618. */
  17619. ObjectRenderer.prototype.destroy = function () {
  17620. this.renderer = null;
  17621. };
  17622. /**
  17623. * Stub method that initializes any state required before
  17624. * rendering starts. It is different from the `prerender`
  17625. * signal, which occurs every frame, in that it is called
  17626. * whenever an object requests _this_ renderer specifically.
  17627. */
  17628. ObjectRenderer.prototype.start = function () {
  17629. // set the shader..
  17630. };
  17631. /**
  17632. * Stops the renderer. It should free up any state and
  17633. * become dormant.
  17634. */
  17635. ObjectRenderer.prototype.stop = function () {
  17636. this.flush();
  17637. };
  17638. /**
  17639. * Keeps the object to render. It doesn't have to be
  17640. * rendered immediately.
  17641. *
  17642. * @param {PIXI.DisplayObject} object - The object to render.
  17643. */
  17644. ObjectRenderer.prototype.render = function (_object) {
  17645. // render the object
  17646. };
  17647. return ObjectRenderer;
  17648. }());
  17649. /**
  17650. * System plugin to the renderer to manage batching.
  17651. *
  17652. * @class
  17653. * @extends PIXI.System
  17654. * @memberof PIXI
  17655. */
  17656. var BatchSystem = /** @class */ (function () {
  17657. /**
  17658. * @param {PIXI.Renderer} renderer - The renderer this System works for.
  17659. */
  17660. function BatchSystem(renderer) {
  17661. this.renderer = renderer;
  17662. /**
  17663. * An empty renderer.
  17664. *
  17665. * @member {PIXI.ObjectRenderer}
  17666. */
  17667. this.emptyRenderer = new ObjectRenderer(renderer);
  17668. /**
  17669. * The currently active ObjectRenderer.
  17670. *
  17671. * @member {PIXI.ObjectRenderer}
  17672. */
  17673. this.currentRenderer = this.emptyRenderer;
  17674. }
  17675. /**
  17676. * Changes the current renderer to the one given in parameter
  17677. *
  17678. * @param {PIXI.ObjectRenderer} objectRenderer - The object renderer to use.
  17679. */
  17680. BatchSystem.prototype.setObjectRenderer = function (objectRenderer) {
  17681. if (this.currentRenderer === objectRenderer) {
  17682. return;
  17683. }
  17684. this.currentRenderer.stop();
  17685. this.currentRenderer = objectRenderer;
  17686. this.currentRenderer.start();
  17687. };
  17688. /**
  17689. * This should be called if you wish to do some custom rendering
  17690. * It will basically render anything that may be batched up such as sprites
  17691. */
  17692. BatchSystem.prototype.flush = function () {
  17693. this.setObjectRenderer(this.emptyRenderer);
  17694. };
  17695. /**
  17696. * Reset the system to an empty renderer
  17697. */
  17698. BatchSystem.prototype.reset = function () {
  17699. this.setObjectRenderer(this.emptyRenderer);
  17700. };
  17701. /**
  17702. * Handy function for batch renderers: copies bound textures in first maxTextures locations to array
  17703. * sets actual _batchLocation for them
  17704. *
  17705. * @param {PIXI.BaseTexture[]} arr - arr copy destination
  17706. * @param {number} maxTextures - number of copied elements
  17707. */
  17708. BatchSystem.prototype.copyBoundTextures = function (arr, maxTextures) {
  17709. var boundTextures = this.renderer.texture.boundTextures;
  17710. for (var i = maxTextures - 1; i >= 0; --i) {
  17711. arr[i] = boundTextures[i] || null;
  17712. if (arr[i]) {
  17713. arr[i]._batchLocation = i;
  17714. }
  17715. }
  17716. };
  17717. /**
  17718. * Assigns batch locations to textures in array based on boundTextures state.
  17719. * All textures in texArray should have `_batchEnabled = _batchId`,
  17720. * and their count should be less than `maxTextures`.
  17721. *
  17722. * @param {PIXI.BatchTextureArray} texArray - textures to bound
  17723. * @param {PIXI.BaseTexture[]} boundTextures - current state of bound textures
  17724. * @param {number} batchId - marker for _batchEnabled param of textures in texArray
  17725. * @param {number} maxTextures - number of texture locations to manipulate
  17726. */
  17727. BatchSystem.prototype.boundArray = function (texArray, boundTextures, batchId, maxTextures) {
  17728. var elements = texArray.elements, ids = texArray.ids, count = texArray.count;
  17729. var j = 0;
  17730. for (var i = 0; i < count; i++) {
  17731. var tex = elements[i];
  17732. var loc = tex._batchLocation;
  17733. if (loc >= 0 && loc < maxTextures
  17734. && boundTextures[loc] === tex) {
  17735. ids[i] = loc;
  17736. continue;
  17737. }
  17738. while (j < maxTextures) {
  17739. var bound = boundTextures[j];
  17740. if (bound && bound._batchEnabled === batchId
  17741. && bound._batchLocation === j) {
  17742. j++;
  17743. continue;
  17744. }
  17745. ids[i] = j;
  17746. tex._batchLocation = j;
  17747. boundTextures[j] = tex;
  17748. break;
  17749. }
  17750. }
  17751. };
  17752. /**
  17753. * @ignore
  17754. */
  17755. BatchSystem.prototype.destroy = function () {
  17756. this.renderer = null;
  17757. };
  17758. return BatchSystem;
  17759. }());
  17760. var CONTEXT_UID_COUNTER = 0;
  17761. /**
  17762. * System plugin to the renderer to manage the context.
  17763. *
  17764. * @class
  17765. * @extends PIXI.System
  17766. * @memberof PIXI
  17767. */
  17768. var ContextSystem = /** @class */ (function () {
  17769. /**
  17770. * @param {PIXI.Renderer} renderer - The renderer this System works for.
  17771. */
  17772. function ContextSystem(renderer) {
  17773. this.renderer = renderer;
  17774. /**
  17775. * Either 1 or 2 to reflect the WebGL version being used
  17776. * @member {number}
  17777. * @readonly
  17778. */
  17779. this.webGLVersion = 1;
  17780. /**
  17781. * Extensions being used
  17782. * @member {object}
  17783. * @readonly
  17784. * @property {WEBGL_draw_buffers} drawBuffers - WebGL v1 extension
  17785. * @property {WEBGL_depth_texture} depthTexture - WebGL v1 extension
  17786. * @property {OES_texture_float} floatTexture - WebGL v1 extension
  17787. * @property {WEBGL_lose_context} loseContext - WebGL v1 extension
  17788. * @property {OES_vertex_array_object} vertexArrayObject - WebGL v1 extension
  17789. * @property {EXT_texture_filter_anisotropic} anisotropicFiltering - WebGL v1 and v2 extension
  17790. */
  17791. this.extensions = {};
  17792. /**
  17793. * Features supported by current context
  17794. * @member {object}
  17795. * @private
  17796. * @readonly
  17797. * @property {boolean} uint32Indices - Supports of 32-bit indices buffer
  17798. */
  17799. this.supports = {
  17800. uint32Indices: false,
  17801. };
  17802. // Bind functions
  17803. this.handleContextLost = this.handleContextLost.bind(this);
  17804. this.handleContextRestored = this.handleContextRestored.bind(this);
  17805. renderer.view.addEventListener('webglcontextlost', this.handleContextLost, false);
  17806. renderer.view.addEventListener('webglcontextrestored', this.handleContextRestored, false);
  17807. }
  17808. Object.defineProperty(ContextSystem.prototype, "isLost", {
  17809. /**
  17810. * `true` if the context is lost
  17811. * @member {boolean}
  17812. * @readonly
  17813. */
  17814. get: function () {
  17815. return (!this.gl || this.gl.isContextLost());
  17816. },
  17817. enumerable: false,
  17818. configurable: true
  17819. });
  17820. /**
  17821. * Handle the context change event
  17822. * @param {WebGLRenderingContext} gl - new webgl context
  17823. */
  17824. ContextSystem.prototype.contextChange = function (gl) {
  17825. this.gl = gl;
  17826. this.renderer.gl = gl;
  17827. this.renderer.CONTEXT_UID = CONTEXT_UID_COUNTER++;
  17828. // restore a context if it was previously lost
  17829. if (gl.isContextLost() && gl.getExtension('WEBGL_lose_context')) {
  17830. gl.getExtension('WEBGL_lose_context').restoreContext();
  17831. }
  17832. };
  17833. /**
  17834. * Initialize the context
  17835. *
  17836. * @protected
  17837. * @param {WebGLRenderingContext} gl - WebGL context
  17838. */
  17839. ContextSystem.prototype.initFromContext = function (gl) {
  17840. this.gl = gl;
  17841. this.validateContext(gl);
  17842. this.renderer.gl = gl;
  17843. this.renderer.CONTEXT_UID = CONTEXT_UID_COUNTER++;
  17844. this.renderer.runners.contextChange.emit(gl);
  17845. };
  17846. /**
  17847. * Initialize from context options
  17848. *
  17849. * @protected
  17850. * @see https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/getContext
  17851. * @param {object} options - context attributes
  17852. */
  17853. ContextSystem.prototype.initFromOptions = function (options) {
  17854. var gl = this.createContext(this.renderer.view, options);
  17855. this.initFromContext(gl);
  17856. };
  17857. /**
  17858. * Helper class to create a WebGL Context
  17859. *
  17860. * @param {HTMLCanvasElement} canvas - the canvas element that we will get the context from
  17861. * @param {object} options - An options object that gets passed in to the canvas element containing the
  17862. * context attributes
  17863. * @see https://developer.mozilla.org/en/docs/Web/API/HTMLCanvasElement/getContext
  17864. * @return {WebGLRenderingContext} the WebGL context
  17865. */
  17866. ContextSystem.prototype.createContext = function (canvas, options) {
  17867. var gl;
  17868. if (settings.PREFER_ENV >= exports.ENV.WEBGL2) {
  17869. gl = canvas.getContext('webgl2', options);
  17870. }
  17871. if (gl) {
  17872. this.webGLVersion = 2;
  17873. }
  17874. else {
  17875. this.webGLVersion = 1;
  17876. gl = canvas.getContext('webgl', options)
  17877. || canvas.getContext('experimental-webgl', options);
  17878. if (!gl) {
  17879. // fail, not able to get a context
  17880. throw new Error('This browser does not support WebGL. Try using the canvas renderer');
  17881. }
  17882. }
  17883. this.gl = gl;
  17884. this.getExtensions();
  17885. return this.gl;
  17886. };
  17887. /**
  17888. * Auto-populate the extensions
  17889. *
  17890. * @protected
  17891. */
  17892. ContextSystem.prototype.getExtensions = function () {
  17893. // time to set up default extensions that Pixi uses.
  17894. var gl = this.gl;
  17895. var common = {
  17896. anisotropicFiltering: gl.getExtension('EXT_texture_filter_anisotropic'),
  17897. floatTextureLinear: gl.getExtension('OES_texture_float_linear'),
  17898. s3tc: gl.getExtension('WEBGL_compressed_texture_s3tc'),
  17899. s3tc_sRGB: gl.getExtension('WEBGL_compressed_texture_s3tc_srgb'),
  17900. etc: gl.getExtension('WEBGL_compressed_texture_etc'),
  17901. etc1: gl.getExtension('WEBGL_compressed_texture_etc1'),
  17902. pvrtc: gl.getExtension('WEBGL_compressed_texture_pvrtc')
  17903. || gl.getExtension('WEBKIT_WEBGL_compressed_texture_pvrtc'),
  17904. atc: gl.getExtension('WEBGL_compressed_texture_atc'),
  17905. astc: gl.getExtension('WEBGL_compressed_texture_astc')
  17906. };
  17907. if (this.webGLVersion === 1) {
  17908. Object.assign(this.extensions, common, {
  17909. drawBuffers: gl.getExtension('WEBGL_draw_buffers'),
  17910. depthTexture: gl.getExtension('WEBGL_depth_texture'),
  17911. loseContext: gl.getExtension('WEBGL_lose_context'),
  17912. vertexArrayObject: gl.getExtension('OES_vertex_array_object')
  17913. || gl.getExtension('MOZ_OES_vertex_array_object')
  17914. || gl.getExtension('WEBKIT_OES_vertex_array_object'),
  17915. uint32ElementIndex: gl.getExtension('OES_element_index_uint'),
  17916. // Floats and half-floats
  17917. floatTexture: gl.getExtension('OES_texture_float'),
  17918. floatTextureLinear: gl.getExtension('OES_texture_float_linear'),
  17919. textureHalfFloat: gl.getExtension('OES_texture_half_float'),
  17920. textureHalfFloatLinear: gl.getExtension('OES_texture_half_float_linear'),
  17921. });
  17922. }
  17923. else if (this.webGLVersion === 2) {
  17924. Object.assign(this.extensions, common, {
  17925. // Floats and half-floats
  17926. colorBufferFloat: gl.getExtension('EXT_color_buffer_float')
  17927. });
  17928. }
  17929. };
  17930. /**
  17931. * Handles a lost webgl context
  17932. *
  17933. * @protected
  17934. * @param {WebGLContextEvent} event - The context lost event.
  17935. */
  17936. ContextSystem.prototype.handleContextLost = function (event) {
  17937. event.preventDefault();
  17938. };
  17939. /**
  17940. * Handles a restored webgl context
  17941. *
  17942. * @protected
  17943. */
  17944. ContextSystem.prototype.handleContextRestored = function () {
  17945. this.renderer.runners.contextChange.emit(this.gl);
  17946. };
  17947. ContextSystem.prototype.destroy = function () {
  17948. var view = this.renderer.view;
  17949. this.renderer = null;
  17950. // remove listeners
  17951. view.removeEventListener('webglcontextlost', this.handleContextLost);
  17952. view.removeEventListener('webglcontextrestored', this.handleContextRestored);
  17953. this.gl.useProgram(null);
  17954. if (this.extensions.loseContext) {
  17955. this.extensions.loseContext.loseContext();
  17956. }
  17957. };
  17958. /**
  17959. * Handle the post-render runner event
  17960. *
  17961. * @protected
  17962. */
  17963. ContextSystem.prototype.postrender = function () {
  17964. if (this.renderer.renderingToScreen) {
  17965. this.gl.flush();
  17966. }
  17967. };
  17968. /**
  17969. * Validate context
  17970. *
  17971. * @protected
  17972. * @param {WebGLRenderingContext} gl - Render context
  17973. */
  17974. ContextSystem.prototype.validateContext = function (gl) {
  17975. var attributes = gl.getContextAttributes();
  17976. var isWebGl2 = 'WebGL2RenderingContext' in self && gl instanceof self.WebGL2RenderingContext;
  17977. if (isWebGl2) {
  17978. this.webGLVersion = 2;
  17979. }
  17980. // this is going to be fairly simple for now.. but at least we have room to grow!
  17981. if (!attributes.stencil) {
  17982. /* eslint-disable max-len, no-console */
  17983. console.warn('Provided WebGL context does not have a stencil buffer, masks may not render correctly');
  17984. /* eslint-enable max-len, no-console */
  17985. }
  17986. var hasuint32 = isWebGl2 || !!gl.getExtension('OES_element_index_uint');
  17987. this.supports.uint32Indices = hasuint32;
  17988. if (!hasuint32) {
  17989. /* eslint-disable max-len, no-console */
  17990. console.warn('Provided WebGL context does not support 32 index buffer, complex graphics may not render correctly');
  17991. /* eslint-enable max-len, no-console */
  17992. }
  17993. };
  17994. return ContextSystem;
  17995. }());
  17996. /**
  17997. * Internal framebuffer for WebGL context
  17998. * @class
  17999. * @memberof PIXI
  18000. */
  18001. var GLFramebuffer = /** @class */ (function () {
  18002. function GLFramebuffer(framebuffer) {
  18003. /**
  18004. * The WebGL framebuffer
  18005. * @member {WebGLFramebuffer}
  18006. */
  18007. this.framebuffer = framebuffer;
  18008. /**
  18009. * stencil+depth , usually costs 32bits per pixel
  18010. * @member {WebGLRenderbuffer}
  18011. */
  18012. this.stencil = null;
  18013. /**
  18014. * latest known version of framebuffer
  18015. * @member {number}
  18016. * @protected
  18017. */
  18018. this.dirtyId = -1;
  18019. /**
  18020. * latest known version of framebuffer format
  18021. * @member {number}
  18022. * @protected
  18023. */
  18024. this.dirtyFormat = -1;
  18025. /**
  18026. * latest known version of framebuffer size
  18027. * @member {number}
  18028. * @protected
  18029. */
  18030. this.dirtySize = -1;
  18031. /**
  18032. * Detected AA samples number
  18033. * @member {PIXI.MSAA_QUALITY}
  18034. */
  18035. this.multisample = exports.MSAA_QUALITY.NONE;
  18036. /**
  18037. * In case MSAA, we use this Renderbuffer instead of colorTextures[0] when we write info
  18038. * @member {WebGLRenderbuffer}
  18039. */
  18040. this.msaaBuffer = null;
  18041. /**
  18042. * In case we use MSAA, this is actual framebuffer that has colorTextures[0]
  18043. * The contents of that framebuffer are read when we use that renderTexture in sprites
  18044. * @member {PIXI.Framebuffer}
  18045. */
  18046. this.blitFramebuffer = null;
  18047. /**
  18048. * store the current mipmap of the textures the framebuffer will write too.
  18049. */
  18050. this.mipLevel = 0;
  18051. }
  18052. return GLFramebuffer;
  18053. }());
  18054. var tempRectangle = new Rectangle();
  18055. /**
  18056. * System plugin to the renderer to manage framebuffers.
  18057. *
  18058. * @class
  18059. * @extends PIXI.System
  18060. * @memberof PIXI
  18061. */
  18062. var FramebufferSystem = /** @class */ (function () {
  18063. /**
  18064. * @param {PIXI.Renderer} renderer - The renderer this System works for.
  18065. */
  18066. function FramebufferSystem(renderer) {
  18067. this.renderer = renderer;
  18068. /**
  18069. * A list of managed framebuffers
  18070. * @member {PIXI.Framebuffer[]}
  18071. * @readonly
  18072. */
  18073. this.managedFramebuffers = [];
  18074. /**
  18075. * Framebuffer value that shows that we don't know what is bound
  18076. * @member {Framebuffer}
  18077. * @readonly
  18078. */
  18079. this.unknownFramebuffer = new Framebuffer(10, 10);
  18080. this.msaaSamples = null;
  18081. }
  18082. /**
  18083. * Sets up the renderer context and necessary buffers.
  18084. */
  18085. FramebufferSystem.prototype.contextChange = function () {
  18086. var gl = this.gl = this.renderer.gl;
  18087. this.CONTEXT_UID = this.renderer.CONTEXT_UID;
  18088. this.current = this.unknownFramebuffer;
  18089. this.viewport = new Rectangle();
  18090. this.hasMRT = true;
  18091. this.writeDepthTexture = true;
  18092. this.disposeAll(true);
  18093. // webgl2
  18094. if (this.renderer.context.webGLVersion === 1) {
  18095. // webgl 1!
  18096. var nativeDrawBuffersExtension_1 = this.renderer.context.extensions.drawBuffers;
  18097. var nativeDepthTextureExtension = this.renderer.context.extensions.depthTexture;
  18098. if (settings.PREFER_ENV === exports.ENV.WEBGL_LEGACY) {
  18099. nativeDrawBuffersExtension_1 = null;
  18100. nativeDepthTextureExtension = null;
  18101. }
  18102. if (nativeDrawBuffersExtension_1) {
  18103. gl.drawBuffers = function (activeTextures) {
  18104. return nativeDrawBuffersExtension_1.drawBuffersWEBGL(activeTextures);
  18105. };
  18106. }
  18107. else {
  18108. this.hasMRT = false;
  18109. gl.drawBuffers = function () {
  18110. // empty
  18111. };
  18112. }
  18113. if (!nativeDepthTextureExtension) {
  18114. this.writeDepthTexture = false;
  18115. }
  18116. }
  18117. else {
  18118. // WebGL2
  18119. // cache possible MSAA samples
  18120. this.msaaSamples = gl.getInternalformatParameter(gl.RENDERBUFFER, gl.RGBA8, gl.SAMPLES);
  18121. }
  18122. };
  18123. /**
  18124. * Bind a framebuffer
  18125. *
  18126. * @param {PIXI.Framebuffer} [framebuffer]
  18127. * @param {PIXI.Rectangle} [frame] - frame, default is framebuffer size
  18128. * @param {number} [mipLevel] - optional mip level to set on the framebuffer - defaults to 0
  18129. */
  18130. FramebufferSystem.prototype.bind = function (framebuffer, frame, mipLevel) {
  18131. if (mipLevel === void 0) { mipLevel = 0; }
  18132. var gl = this.gl;
  18133. if (framebuffer) {
  18134. // TODO caching layer!
  18135. var fbo = framebuffer.glFramebuffers[this.CONTEXT_UID] || this.initFramebuffer(framebuffer);
  18136. if (this.current !== framebuffer) {
  18137. this.current = framebuffer;
  18138. gl.bindFramebuffer(gl.FRAMEBUFFER, fbo.framebuffer);
  18139. }
  18140. // make sure all textures are unbound..
  18141. if (fbo.mipLevel !== mipLevel) {
  18142. framebuffer.dirtyId++;
  18143. framebuffer.dirtyFormat++;
  18144. fbo.mipLevel = mipLevel;
  18145. }
  18146. // now check for updates...
  18147. if (fbo.dirtyId !== framebuffer.dirtyId) {
  18148. fbo.dirtyId = framebuffer.dirtyId;
  18149. if (fbo.dirtyFormat !== framebuffer.dirtyFormat) {
  18150. fbo.dirtyFormat = framebuffer.dirtyFormat;
  18151. fbo.dirtySize = framebuffer.dirtySize;
  18152. this.updateFramebuffer(framebuffer, mipLevel);
  18153. }
  18154. else if (fbo.dirtySize !== framebuffer.dirtySize) {
  18155. fbo.dirtySize = framebuffer.dirtySize;
  18156. this.resizeFramebuffer(framebuffer);
  18157. }
  18158. }
  18159. for (var i = 0; i < framebuffer.colorTextures.length; i++) {
  18160. var tex = framebuffer.colorTextures[i];
  18161. this.renderer.texture.unbind(tex.parentTextureArray || tex);
  18162. }
  18163. if (framebuffer.depthTexture) {
  18164. this.renderer.texture.unbind(framebuffer.depthTexture);
  18165. }
  18166. if (frame) {
  18167. var mipWidth = (frame.width >> mipLevel);
  18168. var mipHeight = (frame.height >> mipLevel);
  18169. var scale = mipWidth / frame.width;
  18170. this.setViewport(frame.x * scale, frame.y * scale, mipWidth, mipHeight);
  18171. }
  18172. else {
  18173. var mipWidth = (framebuffer.width >> mipLevel);
  18174. var mipHeight = (framebuffer.height >> mipLevel);
  18175. this.setViewport(0, 0, mipWidth, mipHeight);
  18176. }
  18177. }
  18178. else {
  18179. if (this.current) {
  18180. this.current = null;
  18181. gl.bindFramebuffer(gl.FRAMEBUFFER, null);
  18182. }
  18183. if (frame) {
  18184. this.setViewport(frame.x, frame.y, frame.width, frame.height);
  18185. }
  18186. else {
  18187. this.setViewport(0, 0, this.renderer.width, this.renderer.height);
  18188. }
  18189. }
  18190. };
  18191. /**
  18192. * Set the WebGLRenderingContext's viewport.
  18193. *
  18194. * @param {Number} x - X position of viewport
  18195. * @param {Number} y - Y position of viewport
  18196. * @param {Number} width - Width of viewport
  18197. * @param {Number} height - Height of viewport
  18198. */
  18199. FramebufferSystem.prototype.setViewport = function (x, y, width, height) {
  18200. var v = this.viewport;
  18201. x = Math.round(x);
  18202. y = Math.round(y);
  18203. width = Math.round(width);
  18204. height = Math.round(height);
  18205. if (v.width !== width || v.height !== height || v.x !== x || v.y !== y) {
  18206. v.x = x;
  18207. v.y = y;
  18208. v.width = width;
  18209. v.height = height;
  18210. this.gl.viewport(x, y, width, height);
  18211. }
  18212. };
  18213. Object.defineProperty(FramebufferSystem.prototype, "size", {
  18214. /**
  18215. * Get the size of the current width and height. Returns object with `width` and `height` values.
  18216. *
  18217. * @member {object}
  18218. * @readonly
  18219. */
  18220. get: function () {
  18221. if (this.current) {
  18222. // TODO store temp
  18223. return { x: 0, y: 0, width: this.current.width, height: this.current.height };
  18224. }
  18225. return { x: 0, y: 0, width: this.renderer.width, height: this.renderer.height };
  18226. },
  18227. enumerable: false,
  18228. configurable: true
  18229. });
  18230. /**
  18231. * Clear the color of the context
  18232. *
  18233. * @param {Number} r - Red value from 0 to 1
  18234. * @param {Number} g - Green value from 0 to 1
  18235. * @param {Number} b - Blue value from 0 to 1
  18236. * @param {Number} a - Alpha value from 0 to 1
  18237. * @param {PIXI.BUFFER_BITS} [mask=BUFFER_BITS.COLOR | BUFFER_BITS.DEPTH] - Bitwise OR of masks
  18238. * that indicate the buffers to be cleared, by default COLOR and DEPTH buffers.
  18239. */
  18240. FramebufferSystem.prototype.clear = function (r, g, b, a, mask) {
  18241. if (mask === void 0) { mask = exports.BUFFER_BITS.COLOR | exports.BUFFER_BITS.DEPTH; }
  18242. var gl = this.gl;
  18243. // TODO clear color can be set only one right?
  18244. gl.clearColor(r, g, b, a);
  18245. gl.clear(mask);
  18246. };
  18247. /**
  18248. * Initialize framebuffer for this context
  18249. *
  18250. * @protected
  18251. * @param {PIXI.Framebuffer} framebuffer
  18252. * @returns {PIXI.GLFramebuffer} created GLFramebuffer
  18253. */
  18254. FramebufferSystem.prototype.initFramebuffer = function (framebuffer) {
  18255. var gl = this.gl;
  18256. var fbo = new GLFramebuffer(gl.createFramebuffer());
  18257. fbo.multisample = this.detectSamples(framebuffer.multisample);
  18258. framebuffer.glFramebuffers[this.CONTEXT_UID] = fbo;
  18259. this.managedFramebuffers.push(framebuffer);
  18260. framebuffer.disposeRunner.add(this);
  18261. return fbo;
  18262. };
  18263. /**
  18264. * Resize the framebuffer
  18265. *
  18266. * @protected
  18267. * @param {PIXI.Framebuffer} framebuffer
  18268. */
  18269. FramebufferSystem.prototype.resizeFramebuffer = function (framebuffer) {
  18270. var gl = this.gl;
  18271. var fbo = framebuffer.glFramebuffers[this.CONTEXT_UID];
  18272. if (fbo.msaaBuffer) {
  18273. gl.bindRenderbuffer(gl.RENDERBUFFER, fbo.msaaBuffer);
  18274. gl.renderbufferStorageMultisample(gl.RENDERBUFFER, fbo.multisample, gl.RGBA8, framebuffer.width, framebuffer.height);
  18275. }
  18276. if (fbo.stencil) {
  18277. gl.bindRenderbuffer(gl.RENDERBUFFER, fbo.stencil);
  18278. if (fbo.msaaBuffer) {
  18279. gl.renderbufferStorageMultisample(gl.RENDERBUFFER, fbo.multisample, gl.DEPTH24_STENCIL8, framebuffer.width, framebuffer.height);
  18280. }
  18281. else {
  18282. gl.renderbufferStorage(gl.RENDERBUFFER, gl.DEPTH_STENCIL, framebuffer.width, framebuffer.height);
  18283. }
  18284. }
  18285. var colorTextures = framebuffer.colorTextures;
  18286. var count = colorTextures.length;
  18287. if (!gl.drawBuffers) {
  18288. count = Math.min(count, 1);
  18289. }
  18290. for (var i = 0; i < count; i++) {
  18291. var texture = colorTextures[i];
  18292. var parentTexture = texture.parentTextureArray || texture;
  18293. this.renderer.texture.bind(parentTexture, 0);
  18294. }
  18295. if (framebuffer.depthTexture && this.writeDepthTexture) {
  18296. this.renderer.texture.bind(framebuffer.depthTexture, 0);
  18297. }
  18298. };
  18299. /**
  18300. * Update the framebuffer
  18301. *
  18302. * @protected
  18303. * @param {PIXI.Framebuffer} framebuffer
  18304. * @param {number} mipLevel
  18305. */
  18306. FramebufferSystem.prototype.updateFramebuffer = function (framebuffer, mipLevel) {
  18307. var gl = this.gl;
  18308. var fbo = framebuffer.glFramebuffers[this.CONTEXT_UID];
  18309. // bind the color texture
  18310. var colorTextures = framebuffer.colorTextures;
  18311. var count = colorTextures.length;
  18312. if (!gl.drawBuffers) {
  18313. count = Math.min(count, 1);
  18314. }
  18315. if (fbo.multisample > 1 && this.canMultisampleFramebuffer(framebuffer)) {
  18316. fbo.msaaBuffer = fbo.msaaBuffer || gl.createRenderbuffer();
  18317. gl.bindRenderbuffer(gl.RENDERBUFFER, fbo.msaaBuffer);
  18318. gl.renderbufferStorageMultisample(gl.RENDERBUFFER, fbo.multisample, gl.RGBA8, framebuffer.width, framebuffer.height);
  18319. gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.RENDERBUFFER, fbo.msaaBuffer);
  18320. }
  18321. else if (fbo.msaaBuffer) {
  18322. gl.deleteRenderbuffer(fbo.msaaBuffer);
  18323. fbo.msaaBuffer = null;
  18324. }
  18325. var activeTextures = [];
  18326. for (var i = 0; i < count; i++) {
  18327. var texture = colorTextures[i];
  18328. var parentTexture = texture.parentTextureArray || texture;
  18329. this.renderer.texture.bind(parentTexture, 0);
  18330. if (i === 0 && fbo.msaaBuffer) {
  18331. continue;
  18332. }
  18333. gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0 + i, texture.target, parentTexture._glTextures[this.CONTEXT_UID].texture, mipLevel);
  18334. activeTextures.push(gl.COLOR_ATTACHMENT0 + i);
  18335. }
  18336. if (activeTextures.length > 1) {
  18337. gl.drawBuffers(activeTextures);
  18338. }
  18339. if (framebuffer.depthTexture) {
  18340. var writeDepthTexture = this.writeDepthTexture;
  18341. if (writeDepthTexture) {
  18342. var depthTexture = framebuffer.depthTexture;
  18343. this.renderer.texture.bind(depthTexture, 0);
  18344. gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.TEXTURE_2D, depthTexture._glTextures[this.CONTEXT_UID].texture, mipLevel);
  18345. }
  18346. }
  18347. if ((framebuffer.stencil || framebuffer.depth) && !(framebuffer.depthTexture && this.writeDepthTexture)) {
  18348. fbo.stencil = fbo.stencil || gl.createRenderbuffer();
  18349. gl.bindRenderbuffer(gl.RENDERBUFFER, fbo.stencil);
  18350. if (fbo.msaaBuffer) {
  18351. gl.renderbufferStorageMultisample(gl.RENDERBUFFER, fbo.multisample, gl.DEPTH24_STENCIL8, framebuffer.width, framebuffer.height);
  18352. }
  18353. else {
  18354. gl.renderbufferStorage(gl.RENDERBUFFER, gl.DEPTH_STENCIL, framebuffer.width, framebuffer.height);
  18355. }
  18356. gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_STENCIL_ATTACHMENT, gl.RENDERBUFFER, fbo.stencil);
  18357. }
  18358. else if (fbo.stencil) {
  18359. gl.deleteRenderbuffer(fbo.stencil);
  18360. fbo.stencil = null;
  18361. }
  18362. };
  18363. /**
  18364. * Returns true if the frame buffer can be multisampled
  18365. *
  18366. * @protected
  18367. * @param {PIXI.Framebuffer} framebuffer
  18368. */
  18369. FramebufferSystem.prototype.canMultisampleFramebuffer = function (framebuffer) {
  18370. return this.renderer.context.webGLVersion !== 1
  18371. && framebuffer.colorTextures.length <= 1 && !framebuffer.depthTexture;
  18372. };
  18373. /**
  18374. * Detects number of samples that is not more than a param but as close to it as possible
  18375. *
  18376. * @param {PIXI.MSAA_QUALITY} samples - number of samples
  18377. * @returns {PIXI.MSAA_QUALITY} - recommended number of samples
  18378. */
  18379. FramebufferSystem.prototype.detectSamples = function (samples) {
  18380. var msaaSamples = this.msaaSamples;
  18381. var res = exports.MSAA_QUALITY.NONE;
  18382. if (samples <= 1 || msaaSamples === null) {
  18383. return res;
  18384. }
  18385. for (var i = 0; i < msaaSamples.length; i++) {
  18386. if (msaaSamples[i] <= samples) {
  18387. res = msaaSamples[i];
  18388. break;
  18389. }
  18390. }
  18391. if (res === 1) {
  18392. res = exports.MSAA_QUALITY.NONE;
  18393. }
  18394. return res;
  18395. };
  18396. /**
  18397. * Only works with WebGL2
  18398. *
  18399. * blits framebuffer to another of the same or bigger size
  18400. * after that target framebuffer is bound
  18401. *
  18402. * Fails with WebGL warning if blits multisample framebuffer to different size
  18403. *
  18404. * @param {PIXI.Framebuffer} [framebuffer] - by default it blits "into itself", from renderBuffer to texture.
  18405. * @param {PIXI.Rectangle} [sourcePixels] - source rectangle in pixels
  18406. * @param {PIXI.Rectangle} [destPixels] - dest rectangle in pixels, assumed to be the same as sourcePixels
  18407. */
  18408. FramebufferSystem.prototype.blit = function (framebuffer, sourcePixels, destPixels) {
  18409. var _a = this, current = _a.current, renderer = _a.renderer, gl = _a.gl, CONTEXT_UID = _a.CONTEXT_UID;
  18410. if (renderer.context.webGLVersion !== 2) {
  18411. return;
  18412. }
  18413. if (!current) {
  18414. return;
  18415. }
  18416. var fbo = current.glFramebuffers[CONTEXT_UID];
  18417. if (!fbo) {
  18418. return;
  18419. }
  18420. if (!framebuffer) {
  18421. if (!fbo.msaaBuffer) {
  18422. return;
  18423. }
  18424. if (!fbo.blitFramebuffer) {
  18425. fbo.blitFramebuffer = new Framebuffer(current.width, current.height);
  18426. fbo.blitFramebuffer.addColorTexture(0, current.colorTextures[0]);
  18427. }
  18428. framebuffer = fbo.blitFramebuffer;
  18429. framebuffer.width = current.width;
  18430. framebuffer.height = current.height;
  18431. }
  18432. if (!sourcePixels) {
  18433. sourcePixels = tempRectangle;
  18434. sourcePixels.width = current.width;
  18435. sourcePixels.height = current.height;
  18436. }
  18437. if (!destPixels) {
  18438. destPixels = sourcePixels;
  18439. }
  18440. var sameSize = sourcePixels.width === destPixels.width && sourcePixels.height === destPixels.height;
  18441. this.bind(framebuffer);
  18442. gl.bindFramebuffer(gl.READ_FRAMEBUFFER, fbo.framebuffer);
  18443. gl.blitFramebuffer(sourcePixels.x, sourcePixels.y, sourcePixels.width, sourcePixels.height, destPixels.x, destPixels.y, destPixels.width, destPixels.height, gl.COLOR_BUFFER_BIT, sameSize ? gl.NEAREST : gl.LINEAR);
  18444. };
  18445. /**
  18446. * Disposes framebuffer
  18447. * @param {PIXI.Framebuffer} framebuffer - framebuffer that has to be disposed of
  18448. * @param {boolean} [contextLost=false] - If context was lost, we suppress all delete function calls
  18449. */
  18450. FramebufferSystem.prototype.disposeFramebuffer = function (framebuffer, contextLost) {
  18451. var fbo = framebuffer.glFramebuffers[this.CONTEXT_UID];
  18452. var gl = this.gl;
  18453. if (!fbo) {
  18454. return;
  18455. }
  18456. delete framebuffer.glFramebuffers[this.CONTEXT_UID];
  18457. var index = this.managedFramebuffers.indexOf(framebuffer);
  18458. if (index >= 0) {
  18459. this.managedFramebuffers.splice(index, 1);
  18460. }
  18461. framebuffer.disposeRunner.remove(this);
  18462. if (!contextLost) {
  18463. gl.deleteFramebuffer(fbo.framebuffer);
  18464. if (fbo.msaaBuffer) {
  18465. gl.deleteRenderbuffer(fbo.msaaBuffer);
  18466. }
  18467. if (fbo.stencil) {
  18468. gl.deleteRenderbuffer(fbo.stencil);
  18469. }
  18470. }
  18471. };
  18472. /**
  18473. * Disposes all framebuffers, but not textures bound to them
  18474. * @param {boolean} [contextLost=false] - If context was lost, we suppress all delete function calls
  18475. */
  18476. FramebufferSystem.prototype.disposeAll = function (contextLost) {
  18477. var list = this.managedFramebuffers;
  18478. this.managedFramebuffers = [];
  18479. for (var i = 0; i < list.length; i++) {
  18480. this.disposeFramebuffer(list[i], contextLost);
  18481. }
  18482. };
  18483. /**
  18484. * Forcing creation of stencil buffer for current framebuffer, if it wasn't done before.
  18485. * Used by MaskSystem, when its time to use stencil mask for Graphics element.
  18486. *
  18487. * Its an alternative for public lazy `framebuffer.enableStencil`, in case we need stencil without rebind.
  18488. *
  18489. * @private
  18490. */
  18491. FramebufferSystem.prototype.forceStencil = function () {
  18492. var framebuffer = this.current;
  18493. if (!framebuffer) {
  18494. return;
  18495. }
  18496. var fbo = framebuffer.glFramebuffers[this.CONTEXT_UID];
  18497. if (!fbo || fbo.stencil) {
  18498. return;
  18499. }
  18500. framebuffer.stencil = true;
  18501. var w = framebuffer.width;
  18502. var h = framebuffer.height;
  18503. var gl = this.gl;
  18504. var stencil = gl.createRenderbuffer();
  18505. gl.bindRenderbuffer(gl.RENDERBUFFER, stencil);
  18506. if (fbo.msaaBuffer) {
  18507. gl.renderbufferStorageMultisample(gl.RENDERBUFFER, fbo.multisample, gl.DEPTH24_STENCIL8, w, h);
  18508. }
  18509. else {
  18510. gl.renderbufferStorage(gl.RENDERBUFFER, gl.DEPTH_STENCIL, w, h);
  18511. }
  18512. fbo.stencil = stencil;
  18513. gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_STENCIL_ATTACHMENT, gl.RENDERBUFFER, stencil);
  18514. };
  18515. /**
  18516. * resets framebuffer stored state, binds screen framebuffer
  18517. *
  18518. * should be called before renderTexture reset()
  18519. */
  18520. FramebufferSystem.prototype.reset = function () {
  18521. this.current = this.unknownFramebuffer;
  18522. this.viewport = new Rectangle();
  18523. };
  18524. /**
  18525. * @ignore
  18526. */
  18527. FramebufferSystem.prototype.destroy = function () {
  18528. this.renderer = null;
  18529. };
  18530. return FramebufferSystem;
  18531. }());
  18532. var byteSizeMap$1 = { 5126: 4, 5123: 2, 5121: 1 };
  18533. /**
  18534. * System plugin to the renderer to manage geometry.
  18535. *
  18536. * @class
  18537. * @extends PIXI.System
  18538. * @memberof PIXI
  18539. */
  18540. var GeometrySystem = /** @class */ (function () {
  18541. /**
  18542. * @param {PIXI.Renderer} renderer - The renderer this System works for.
  18543. */
  18544. function GeometrySystem(renderer) {
  18545. this.renderer = renderer;
  18546. this._activeGeometry = null;
  18547. this._activeVao = null;
  18548. /**
  18549. * `true` if we has `*_vertex_array_object` extension
  18550. * @member {boolean}
  18551. * @readonly
  18552. */
  18553. this.hasVao = true;
  18554. /**
  18555. * `true` if has `ANGLE_instanced_arrays` extension
  18556. * @member {boolean}
  18557. * @readonly
  18558. */
  18559. this.hasInstance = true;
  18560. /**
  18561. * `true` if support `gl.UNSIGNED_INT` in `gl.drawElements` or `gl.drawElementsInstanced`
  18562. * @member {boolean}
  18563. * @readonly
  18564. */
  18565. this.canUseUInt32ElementIndex = false;
  18566. /**
  18567. * Cache for all geometries by id, used in case renderer gets destroyed or for profiling
  18568. * @member {object}
  18569. * @readonly
  18570. */
  18571. this.managedGeometries = {};
  18572. }
  18573. /**
  18574. * Sets up the renderer context and necessary buffers.
  18575. */
  18576. GeometrySystem.prototype.contextChange = function () {
  18577. this.disposeAll(true);
  18578. var gl = this.gl = this.renderer.gl;
  18579. var context = this.renderer.context;
  18580. this.CONTEXT_UID = this.renderer.CONTEXT_UID;
  18581. // webgl2
  18582. if (context.webGLVersion !== 2) {
  18583. // webgl 1!
  18584. var nativeVaoExtension_1 = this.renderer.context.extensions.vertexArrayObject;
  18585. if (settings.PREFER_ENV === exports.ENV.WEBGL_LEGACY) {
  18586. nativeVaoExtension_1 = null;
  18587. }
  18588. if (nativeVaoExtension_1) {
  18589. gl.createVertexArray = function () {
  18590. return nativeVaoExtension_1.createVertexArrayOES();
  18591. };
  18592. gl.bindVertexArray = function (vao) {
  18593. return nativeVaoExtension_1.bindVertexArrayOES(vao);
  18594. };
  18595. gl.deleteVertexArray = function (vao) {
  18596. return nativeVaoExtension_1.deleteVertexArrayOES(vao);
  18597. };
  18598. }
  18599. else {
  18600. this.hasVao = false;
  18601. gl.createVertexArray = function () {
  18602. return null;
  18603. };
  18604. gl.bindVertexArray = function () {
  18605. return null;
  18606. };
  18607. gl.deleteVertexArray = function () {
  18608. return null;
  18609. };
  18610. }
  18611. }
  18612. if (context.webGLVersion !== 2) {
  18613. var instanceExt_1 = gl.getExtension('ANGLE_instanced_arrays');
  18614. if (instanceExt_1) {
  18615. gl.vertexAttribDivisor = function (a, b) {
  18616. return instanceExt_1.vertexAttribDivisorANGLE(a, b);
  18617. };
  18618. gl.drawElementsInstanced = function (a, b, c, d, e) {
  18619. return instanceExt_1.drawElementsInstancedANGLE(a, b, c, d, e);
  18620. };
  18621. gl.drawArraysInstanced = function (a, b, c, d) {
  18622. return instanceExt_1.drawArraysInstancedANGLE(a, b, c, d);
  18623. };
  18624. }
  18625. else {
  18626. this.hasInstance = false;
  18627. }
  18628. }
  18629. this.canUseUInt32ElementIndex = context.webGLVersion === 2 || !!context.extensions.uint32ElementIndex;
  18630. };
  18631. /**
  18632. * Binds geometry so that is can be drawn. Creating a Vao if required
  18633. *
  18634. * @param {PIXI.Geometry} geometry - instance of geometry to bind
  18635. * @param {PIXI.Shader} [shader] - instance of shader to use vao for
  18636. */
  18637. GeometrySystem.prototype.bind = function (geometry, shader) {
  18638. shader = shader || this.renderer.shader.shader;
  18639. var gl = this.gl;
  18640. // not sure the best way to address this..
  18641. // currently different shaders require different VAOs for the same geometry
  18642. // Still mulling over the best way to solve this one..
  18643. // will likely need to modify the shader attribute locations at run time!
  18644. var vaos = geometry.glVertexArrayObjects[this.CONTEXT_UID];
  18645. var incRefCount = false;
  18646. if (!vaos) {
  18647. this.managedGeometries[geometry.id] = geometry;
  18648. geometry.disposeRunner.add(this);
  18649. geometry.glVertexArrayObjects[this.CONTEXT_UID] = vaos = {};
  18650. incRefCount = true;
  18651. }
  18652. var vao = vaos[shader.program.id] || this.initGeometryVao(geometry, shader, incRefCount);
  18653. this._activeGeometry = geometry;
  18654. if (this._activeVao !== vao) {
  18655. this._activeVao = vao;
  18656. if (this.hasVao) {
  18657. gl.bindVertexArray(vao);
  18658. }
  18659. else {
  18660. this.activateVao(geometry, shader.program);
  18661. }
  18662. }
  18663. // TODO - optimise later!
  18664. // don't need to loop through if nothing changed!
  18665. // maybe look to add an 'autoupdate' to geometry?
  18666. this.updateBuffers();
  18667. };
  18668. /**
  18669. * Reset and unbind any active VAO and geometry
  18670. */
  18671. GeometrySystem.prototype.reset = function () {
  18672. this.unbind();
  18673. };
  18674. /**
  18675. * Update buffers
  18676. * @protected
  18677. */
  18678. GeometrySystem.prototype.updateBuffers = function () {
  18679. var geometry = this._activeGeometry;
  18680. var bufferSystem = this.renderer.buffer;
  18681. for (var i = 0; i < geometry.buffers.length; i++) {
  18682. var buffer = geometry.buffers[i];
  18683. bufferSystem.update(buffer);
  18684. }
  18685. };
  18686. /**
  18687. * Check compatibility between a geometry and a program
  18688. * @protected
  18689. * @param {PIXI.Geometry} geometry - Geometry instance
  18690. * @param {PIXI.Program} program - Program instance
  18691. */
  18692. GeometrySystem.prototype.checkCompatibility = function (geometry, program) {
  18693. // geometry must have at least all the attributes that the shader requires.
  18694. var geometryAttributes = geometry.attributes;
  18695. var shaderAttributes = program.attributeData;
  18696. for (var j in shaderAttributes) {
  18697. if (!geometryAttributes[j]) {
  18698. throw new Error("shader and geometry incompatible, geometry missing the \"" + j + "\" attribute");
  18699. }
  18700. }
  18701. };
  18702. /**
  18703. * Takes a geometry and program and generates a unique signature for them.
  18704. *
  18705. * @param {PIXI.Geometry} geometry - to get signature from
  18706. * @param {PIXI.Program} program - to test geometry against
  18707. * @returns {String} Unique signature of the geometry and program
  18708. * @protected
  18709. */
  18710. GeometrySystem.prototype.getSignature = function (geometry, program) {
  18711. var attribs = geometry.attributes;
  18712. var shaderAttributes = program.attributeData;
  18713. var strings = ['g', geometry.id];
  18714. for (var i in attribs) {
  18715. if (shaderAttributes[i]) {
  18716. strings.push(i);
  18717. }
  18718. }
  18719. return strings.join('-');
  18720. };
  18721. /**
  18722. * Creates or gets Vao with the same structure as the geometry and stores it on the geometry.
  18723. * If vao is created, it is bound automatically. We use a shader to infer what and how to set up the
  18724. * attribute locations.
  18725. *
  18726. * @protected
  18727. * @param {PIXI.Geometry} geometry - Instance of geometry to to generate Vao for
  18728. * @param {PIXI.Shader} shader - Instance of the shader
  18729. * @param {boolean} [incRefCount=false] - Increment refCount of all geometry buffers
  18730. */
  18731. GeometrySystem.prototype.initGeometryVao = function (geometry, shader, incRefCount) {
  18732. if (incRefCount === void 0) { incRefCount = true; }
  18733. var gl = this.gl;
  18734. var CONTEXT_UID = this.CONTEXT_UID;
  18735. var bufferSystem = this.renderer.buffer;
  18736. var program = shader.program;
  18737. if (!program.glPrograms[CONTEXT_UID]) {
  18738. this.renderer.shader.generateProgram(shader);
  18739. }
  18740. this.checkCompatibility(geometry, program);
  18741. var signature = this.getSignature(geometry, program);
  18742. var vaoObjectHash = geometry.glVertexArrayObjects[this.CONTEXT_UID];
  18743. var vao = vaoObjectHash[signature];
  18744. if (vao) {
  18745. // this will give us easy access to the vao
  18746. vaoObjectHash[program.id] = vao;
  18747. return vao;
  18748. }
  18749. var buffers = geometry.buffers;
  18750. var attributes = geometry.attributes;
  18751. var tempStride = {};
  18752. var tempStart = {};
  18753. for (var j in buffers) {
  18754. tempStride[j] = 0;
  18755. tempStart[j] = 0;
  18756. }
  18757. for (var j in attributes) {
  18758. if (!attributes[j].size && program.attributeData[j]) {
  18759. attributes[j].size = program.attributeData[j].size;
  18760. }
  18761. else if (!attributes[j].size) {
  18762. console.warn("PIXI Geometry attribute '" + j + "' size cannot be determined (likely the bound shader does not have the attribute)"); // eslint-disable-line
  18763. }
  18764. tempStride[attributes[j].buffer] += attributes[j].size * byteSizeMap$1[attributes[j].type];
  18765. }
  18766. for (var j in attributes) {
  18767. var attribute = attributes[j];
  18768. var attribSize = attribute.size;
  18769. if (attribute.stride === undefined) {
  18770. if (tempStride[attribute.buffer] === attribSize * byteSizeMap$1[attribute.type]) {
  18771. attribute.stride = 0;
  18772. }
  18773. else {
  18774. attribute.stride = tempStride[attribute.buffer];
  18775. }
  18776. }
  18777. if (attribute.start === undefined) {
  18778. attribute.start = tempStart[attribute.buffer];
  18779. tempStart[attribute.buffer] += attribSize * byteSizeMap$1[attribute.type];
  18780. }
  18781. }
  18782. vao = gl.createVertexArray();
  18783. gl.bindVertexArray(vao);
  18784. // first update - and create the buffers!
  18785. // only create a gl buffer if it actually gets
  18786. for (var i = 0; i < buffers.length; i++) {
  18787. var buffer = buffers[i];
  18788. bufferSystem.bind(buffer);
  18789. if (incRefCount) {
  18790. buffer._glBuffers[CONTEXT_UID].refCount++;
  18791. }
  18792. }
  18793. // TODO - maybe make this a data object?
  18794. // lets wait to see if we need to first!
  18795. this.activateVao(geometry, program);
  18796. this._activeVao = vao;
  18797. // add it to the cache!
  18798. vaoObjectHash[program.id] = vao;
  18799. vaoObjectHash[signature] = vao;
  18800. return vao;
  18801. };
  18802. /**
  18803. * Disposes geometry
  18804. * @param {PIXI.Geometry} geometry - Geometry with buffers. Only VAO will be disposed
  18805. * @param {boolean} [contextLost=false] - If context was lost, we suppress deleteVertexArray
  18806. */
  18807. GeometrySystem.prototype.disposeGeometry = function (geometry, contextLost) {
  18808. var _a;
  18809. if (!this.managedGeometries[geometry.id]) {
  18810. return;
  18811. }
  18812. delete this.managedGeometries[geometry.id];
  18813. var vaos = geometry.glVertexArrayObjects[this.CONTEXT_UID];
  18814. var gl = this.gl;
  18815. var buffers = geometry.buffers;
  18816. var bufferSystem = (_a = this.renderer) === null || _a === void 0 ? void 0 : _a.buffer;
  18817. geometry.disposeRunner.remove(this);
  18818. if (!vaos) {
  18819. return;
  18820. }
  18821. // bufferSystem may have already been destroyed..
  18822. // if this is the case, there is no need to destroy the geometry buffers...
  18823. // they already have been!
  18824. if (bufferSystem) {
  18825. for (var i = 0; i < buffers.length; i++) {
  18826. var buf = buffers[i]._glBuffers[this.CONTEXT_UID];
  18827. // my be null as context may have changed right before the dispose is called
  18828. if (buf) {
  18829. buf.refCount--;
  18830. if (buf.refCount === 0 && !contextLost) {
  18831. bufferSystem.dispose(buffers[i], contextLost);
  18832. }
  18833. }
  18834. }
  18835. }
  18836. if (!contextLost) {
  18837. for (var vaoId in vaos) {
  18838. // delete only signatures, everything else are copies
  18839. if (vaoId[0] === 'g') {
  18840. var vao = vaos[vaoId];
  18841. if (this._activeVao === vao) {
  18842. this.unbind();
  18843. }
  18844. gl.deleteVertexArray(vao);
  18845. }
  18846. }
  18847. }
  18848. delete geometry.glVertexArrayObjects[this.CONTEXT_UID];
  18849. };
  18850. /**
  18851. * dispose all WebGL resources of all managed geometries
  18852. * @param {boolean} [contextLost=false] - If context was lost, we suppress `gl.delete` calls
  18853. */
  18854. GeometrySystem.prototype.disposeAll = function (contextLost) {
  18855. var all = Object.keys(this.managedGeometries);
  18856. for (var i = 0; i < all.length; i++) {
  18857. this.disposeGeometry(this.managedGeometries[all[i]], contextLost);
  18858. }
  18859. };
  18860. /**
  18861. * Activate vertex array object
  18862. *
  18863. * @protected
  18864. * @param {PIXI.Geometry} geometry - Geometry instance
  18865. * @param {PIXI.Program} program - Shader program instance
  18866. */
  18867. GeometrySystem.prototype.activateVao = function (geometry, program) {
  18868. var gl = this.gl;
  18869. var CONTEXT_UID = this.CONTEXT_UID;
  18870. var bufferSystem = this.renderer.buffer;
  18871. var buffers = geometry.buffers;
  18872. var attributes = geometry.attributes;
  18873. if (geometry.indexBuffer) {
  18874. // first update the index buffer if we have one..
  18875. bufferSystem.bind(geometry.indexBuffer);
  18876. }
  18877. var lastBuffer = null;
  18878. // add a new one!
  18879. for (var j in attributes) {
  18880. var attribute = attributes[j];
  18881. var buffer = buffers[attribute.buffer];
  18882. var glBuffer = buffer._glBuffers[CONTEXT_UID];
  18883. if (program.attributeData[j]) {
  18884. if (lastBuffer !== glBuffer) {
  18885. bufferSystem.bind(buffer);
  18886. lastBuffer = glBuffer;
  18887. }
  18888. var location = program.attributeData[j].location;
  18889. // TODO introduce state again
  18890. // we can optimise this for older devices that have no VAOs
  18891. gl.enableVertexAttribArray(location);
  18892. gl.vertexAttribPointer(location, attribute.size, attribute.type || gl.FLOAT, attribute.normalized, attribute.stride, attribute.start);
  18893. if (attribute.instance) {
  18894. // TODO calculate instance count based of this...
  18895. if (this.hasInstance) {
  18896. gl.vertexAttribDivisor(location, 1);
  18897. }
  18898. else {
  18899. throw new Error('geometry error, GPU Instancing is not supported on this device');
  18900. }
  18901. }
  18902. }
  18903. }
  18904. };
  18905. /**
  18906. * Draw the geometry
  18907. *
  18908. * @param {Number} type - the type primitive to render
  18909. * @param {Number} [size] - the number of elements to be rendered
  18910. * @param {Number} [start] - Starting index
  18911. * @param {Number} [instanceCount] - the number of instances of the set of elements to execute
  18912. */
  18913. GeometrySystem.prototype.draw = function (type, size, start, instanceCount) {
  18914. var gl = this.gl;
  18915. var geometry = this._activeGeometry;
  18916. // TODO.. this should not change so maybe cache the function?
  18917. if (geometry.indexBuffer) {
  18918. var byteSize = geometry.indexBuffer.data.BYTES_PER_ELEMENT;
  18919. var glType = byteSize === 2 ? gl.UNSIGNED_SHORT : gl.UNSIGNED_INT;
  18920. if (byteSize === 2 || (byteSize === 4 && this.canUseUInt32ElementIndex)) {
  18921. if (geometry.instanced) {
  18922. /* eslint-disable max-len */
  18923. gl.drawElementsInstanced(type, size || geometry.indexBuffer.data.length, glType, (start || 0) * byteSize, instanceCount || 1);
  18924. /* eslint-enable max-len */
  18925. }
  18926. else {
  18927. /* eslint-disable max-len */
  18928. gl.drawElements(type, size || geometry.indexBuffer.data.length, glType, (start || 0) * byteSize);
  18929. /* eslint-enable max-len */
  18930. }
  18931. }
  18932. else {
  18933. console.warn('unsupported index buffer type: uint32');
  18934. }
  18935. }
  18936. else if (geometry.instanced) {
  18937. // TODO need a better way to calculate size..
  18938. gl.drawArraysInstanced(type, start, size || geometry.getSize(), instanceCount || 1);
  18939. }
  18940. else {
  18941. gl.drawArrays(type, start, size || geometry.getSize());
  18942. }
  18943. return this;
  18944. };
  18945. /**
  18946. * Unbind/reset everything
  18947. * @protected
  18948. */
  18949. GeometrySystem.prototype.unbind = function () {
  18950. this.gl.bindVertexArray(null);
  18951. this._activeVao = null;
  18952. this._activeGeometry = null;
  18953. };
  18954. /**
  18955. * @ignore
  18956. */
  18957. GeometrySystem.prototype.destroy = function () {
  18958. this.renderer = null;
  18959. };
  18960. return GeometrySystem;
  18961. }());
  18962. /**
  18963. * Component for masked elements
  18964. *
  18965. * Holds mask mode and temporary data about current mask
  18966. *
  18967. * @class
  18968. * @memberof PIXI
  18969. */
  18970. var MaskData = /** @class */ (function () {
  18971. /**
  18972. * Create MaskData
  18973. *
  18974. * @param {PIXI.DisplayObject} [maskObject=null] - object that describes the mask
  18975. */
  18976. function MaskData(maskObject) {
  18977. if (maskObject === void 0) { maskObject = null; }
  18978. /**
  18979. * Mask type
  18980. * @member {PIXI.MASK_TYPES}
  18981. */
  18982. this.type = exports.MASK_TYPES.NONE;
  18983. /**
  18984. * Whether we know the mask type beforehand
  18985. * @member {boolean}
  18986. * @default true
  18987. */
  18988. this.autoDetect = true;
  18989. /**
  18990. * Which element we use to mask
  18991. * @member {PIXI.DisplayObject}
  18992. */
  18993. this.maskObject = maskObject || null;
  18994. /**
  18995. * Whether it belongs to MaskSystem pool
  18996. * @member {boolean}
  18997. */
  18998. this.pooled = false;
  18999. /**
  19000. * Indicator of the type
  19001. * @member {boolean}
  19002. */
  19003. this.isMaskData = true;
  19004. /**
  19005. * Resolution of the sprite mask filter.
  19006. * If set to `null` or `0`, the resolution of the current render target is used.
  19007. * @member {number}
  19008. */
  19009. this.resolution = null;
  19010. /**
  19011. * Number of samples of the sprite mask filter.
  19012. * If set to `null`, the sample count of the current render target is used.
  19013. * @member {PIXI.MSAA_QUALITY}
  19014. * @default {PIXI.settings.FILTER_MULTISAMPLE}
  19015. */
  19016. this.multisample = settings.FILTER_MULTISAMPLE;
  19017. /**
  19018. * Stencil counter above the mask in stack
  19019. * @member {number}
  19020. * @private
  19021. */
  19022. this._stencilCounter = 0;
  19023. /**
  19024. * Scissor counter above the mask in stack
  19025. * @member {number}
  19026. * @private
  19027. */
  19028. this._scissorCounter = 0;
  19029. /**
  19030. * Scissor operation above the mask in stack.
  19031. * Null if _scissorCounter is zero, rectangle instance if positive.
  19032. * @member {PIXI.Rectangle}
  19033. */
  19034. this._scissorRect = null;
  19035. /**
  19036. * Targeted element. Temporary variable set by MaskSystem
  19037. * @member {PIXI.DisplayObject}
  19038. * @private
  19039. */
  19040. this._target = null;
  19041. }
  19042. /**
  19043. * resets the mask data after popMask()
  19044. */
  19045. MaskData.prototype.reset = function () {
  19046. if (this.pooled) {
  19047. this.maskObject = null;
  19048. this.type = exports.MASK_TYPES.NONE;
  19049. this.autoDetect = true;
  19050. }
  19051. this._target = null;
  19052. };
  19053. /**
  19054. * copies counters from maskData above, called from pushMask()
  19055. * @param {PIXI.MaskData|null} maskAbove
  19056. */
  19057. MaskData.prototype.copyCountersOrReset = function (maskAbove) {
  19058. if (maskAbove) {
  19059. this._stencilCounter = maskAbove._stencilCounter;
  19060. this._scissorCounter = maskAbove._scissorCounter;
  19061. this._scissorRect = maskAbove._scissorRect;
  19062. }
  19063. else {
  19064. this._stencilCounter = 0;
  19065. this._scissorCounter = 0;
  19066. this._scissorRect = null;
  19067. }
  19068. };
  19069. return MaskData;
  19070. }());
  19071. /**
  19072. * @private
  19073. * @param {WebGLRenderingContext} gl - The current WebGL context {WebGLProgram}
  19074. * @param {Number} type - the type, can be either VERTEX_SHADER or FRAGMENT_SHADER
  19075. * @param {string} src - The vertex shader source as an array of strings.
  19076. * @return {WebGLShader} the shader
  19077. */
  19078. function compileShader(gl, type, src) {
  19079. var shader = gl.createShader(type);
  19080. gl.shaderSource(shader, src);
  19081. gl.compileShader(shader);
  19082. return shader;
  19083. }
  19084. /**
  19085. * will log a shader error highlighting the lines with the error
  19086. * also will add numbers along the side.
  19087. *
  19088. * @param gl - the WebGLContext
  19089. * @param shader - the shader to log errors for
  19090. */
  19091. function logPrettyShaderError(gl, shader) {
  19092. var shaderSrc = gl.getShaderSource(shader)
  19093. .split('\n')
  19094. .map(function (line, index) { return index + ": " + line; });
  19095. var shaderLog = gl.getShaderInfoLog(shader);
  19096. var splitShader = shaderLog.split('\n');
  19097. var dedupe = {};
  19098. var lineNumbers = splitShader.map(function (line) { return parseFloat(line.replace(/^ERROR\: 0\:([\d]+)\:.*$/, '$1')); })
  19099. .filter(function (n) {
  19100. if (n && !dedupe[n]) {
  19101. dedupe[n] = true;
  19102. return true;
  19103. }
  19104. return false;
  19105. });
  19106. var logArgs = [''];
  19107. lineNumbers.forEach(function (number) {
  19108. shaderSrc[number - 1] = "%c" + shaderSrc[number - 1] + "%c";
  19109. logArgs.push('background: #FF0000; color:#FFFFFF; font-size: 10px', 'font-size: 10px');
  19110. });
  19111. var fragmentSourceToLog = shaderSrc
  19112. .join('\n');
  19113. logArgs[0] = fragmentSourceToLog;
  19114. console.error(shaderLog);
  19115. // eslint-disable-next-line no-console
  19116. console.groupCollapsed('click to view full shader code');
  19117. console.warn.apply(console, logArgs);
  19118. // eslint-disable-next-line no-console
  19119. console.groupEnd();
  19120. }
  19121. /**
  19122. *
  19123. * logs out any program errors
  19124. *
  19125. * @param gl - The current WebGL context
  19126. * @param program - the WebGL program to display errors for
  19127. * @param vertexShader - the fragment WebGL shader program
  19128. * @param fragmentShader - the vertex WebGL shader program
  19129. */
  19130. function logProgramError(gl, program, vertexShader, fragmentShader) {
  19131. // if linking fails, then log and cleanup
  19132. if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
  19133. if (!gl.getShaderParameter(vertexShader, gl.COMPILE_STATUS)) {
  19134. logPrettyShaderError(gl, vertexShader);
  19135. }
  19136. if (!gl.getShaderParameter(fragmentShader, gl.COMPILE_STATUS)) {
  19137. logPrettyShaderError(gl, fragmentShader);
  19138. }
  19139. console.error('PixiJS Error: Could not initialize shader.');
  19140. // if there is a program info log, log it
  19141. if (gl.getProgramInfoLog(program) !== '') {
  19142. console.warn('PixiJS Warning: gl.getProgramInfoLog()', gl.getProgramInfoLog(program));
  19143. }
  19144. }
  19145. }
  19146. function booleanArray(size) {
  19147. var array = new Array(size);
  19148. for (var i = 0; i < array.length; i++) {
  19149. array[i] = false;
  19150. }
  19151. return array;
  19152. }
  19153. /**
  19154. * @method defaultValue
  19155. * @memberof PIXI.glCore.shader
  19156. * @param {string} type - Type of value
  19157. * @param {number} size
  19158. * @private
  19159. */
  19160. function defaultValue(type, size) {
  19161. switch (type) {
  19162. case 'float':
  19163. return 0;
  19164. case 'vec2':
  19165. return new Float32Array(2 * size);
  19166. case 'vec3':
  19167. return new Float32Array(3 * size);
  19168. case 'vec4':
  19169. return new Float32Array(4 * size);
  19170. case 'int':
  19171. case 'uint':
  19172. case 'sampler2D':
  19173. case 'sampler2DArray':
  19174. return 0;
  19175. case 'ivec2':
  19176. return new Int32Array(2 * size);
  19177. case 'ivec3':
  19178. return new Int32Array(3 * size);
  19179. case 'ivec4':
  19180. return new Int32Array(4 * size);
  19181. case 'uvec2':
  19182. return new Uint32Array(2 * size);
  19183. case 'uvec3':
  19184. return new Uint32Array(3 * size);
  19185. case 'uvec4':
  19186. return new Uint32Array(4 * size);
  19187. case 'bool':
  19188. return false;
  19189. case 'bvec2':
  19190. return booleanArray(2 * size);
  19191. case 'bvec3':
  19192. return booleanArray(3 * size);
  19193. case 'bvec4':
  19194. return booleanArray(4 * size);
  19195. case 'mat2':
  19196. return new Float32Array([1, 0,
  19197. 0, 1]);
  19198. case 'mat3':
  19199. return new Float32Array([1, 0, 0,
  19200. 0, 1, 0,
  19201. 0, 0, 1]);
  19202. case 'mat4':
  19203. return new Float32Array([1, 0, 0, 0,
  19204. 0, 1, 0, 0,
  19205. 0, 0, 1, 0,
  19206. 0, 0, 0, 1]);
  19207. }
  19208. return null;
  19209. }
  19210. var unknownContext = {};
  19211. var context = unknownContext;
  19212. /**
  19213. * returns a little WebGL context to use for program inspection.
  19214. *
  19215. * @static
  19216. * @private
  19217. * @returns {WebGLRenderingContext} a gl context to test with
  19218. */
  19219. function getTestContext() {
  19220. if (context === unknownContext || (context && context.isContextLost())) {
  19221. var canvas = document.createElement('canvas');
  19222. var gl = void 0;
  19223. if (settings.PREFER_ENV >= exports.ENV.WEBGL2) {
  19224. gl = canvas.getContext('webgl2', {});
  19225. }
  19226. if (!gl) {
  19227. gl = canvas.getContext('webgl', {})
  19228. || canvas.getContext('experimental-webgl', {});
  19229. if (!gl) {
  19230. // fail, not able to get a context
  19231. gl = null;
  19232. }
  19233. else {
  19234. // for shader testing..
  19235. gl.getExtension('WEBGL_draw_buffers');
  19236. }
  19237. }
  19238. context = gl;
  19239. }
  19240. return context;
  19241. }
  19242. var maxFragmentPrecision;
  19243. function getMaxFragmentPrecision() {
  19244. if (!maxFragmentPrecision) {
  19245. maxFragmentPrecision = exports.PRECISION.MEDIUM;
  19246. var gl = getTestContext();
  19247. if (gl) {
  19248. if (gl.getShaderPrecisionFormat) {
  19249. var shaderFragment = gl.getShaderPrecisionFormat(gl.FRAGMENT_SHADER, gl.HIGH_FLOAT);
  19250. maxFragmentPrecision = shaderFragment.precision ? exports.PRECISION.HIGH : exports.PRECISION.MEDIUM;
  19251. }
  19252. }
  19253. }
  19254. return maxFragmentPrecision;
  19255. }
  19256. /**
  19257. * Sets the float precision on the shader, ensuring the device supports the request precision.
  19258. * If the precision is already present, it just ensures that the device is able to handle it.
  19259. *
  19260. * @private
  19261. * @param {string} src - The shader source
  19262. * @param {PIXI.PRECISION} requestedPrecision - The request float precision of the shader.
  19263. * @param {PIXI.PRECISION} maxSupportedPrecision - The maximum precision the shader supports.
  19264. *
  19265. * @return {string} modified shader source
  19266. */
  19267. function setPrecision(src, requestedPrecision, maxSupportedPrecision) {
  19268. if (src.substring(0, 9) !== 'precision') {
  19269. // no precision supplied, so PixiJS will add the requested level.
  19270. var precision = requestedPrecision;
  19271. // If highp is requested but not supported, downgrade precision to a level all devices support.
  19272. if (requestedPrecision === exports.PRECISION.HIGH && maxSupportedPrecision !== exports.PRECISION.HIGH) {
  19273. precision = exports.PRECISION.MEDIUM;
  19274. }
  19275. return "precision " + precision + " float;\n" + src;
  19276. }
  19277. else if (maxSupportedPrecision !== exports.PRECISION.HIGH && src.substring(0, 15) === 'precision highp') {
  19278. // precision was supplied, but at a level this device does not support, so downgrading to mediump.
  19279. return src.replace('precision highp', 'precision mediump');
  19280. }
  19281. return src;
  19282. }
  19283. var GLSL_TO_SIZE = {
  19284. float: 1,
  19285. vec2: 2,
  19286. vec3: 3,
  19287. vec4: 4,
  19288. int: 1,
  19289. ivec2: 2,
  19290. ivec3: 3,
  19291. ivec4: 4,
  19292. uint: 1,
  19293. uvec2: 2,
  19294. uvec3: 3,
  19295. uvec4: 4,
  19296. bool: 1,
  19297. bvec2: 2,
  19298. bvec3: 3,
  19299. bvec4: 4,
  19300. mat2: 4,
  19301. mat3: 9,
  19302. mat4: 16,
  19303. sampler2D: 1,
  19304. };
  19305. /**
  19306. * @private
  19307. * @method mapSize
  19308. * @memberof PIXI.glCore.shader
  19309. * @param {String} type
  19310. * @return {Number}
  19311. */
  19312. function mapSize(type) {
  19313. return GLSL_TO_SIZE[type];
  19314. }
  19315. var GL_TABLE = null;
  19316. var GL_TO_GLSL_TYPES = {
  19317. FLOAT: 'float',
  19318. FLOAT_VEC2: 'vec2',
  19319. FLOAT_VEC3: 'vec3',
  19320. FLOAT_VEC4: 'vec4',
  19321. INT: 'int',
  19322. INT_VEC2: 'ivec2',
  19323. INT_VEC3: 'ivec3',
  19324. INT_VEC4: 'ivec4',
  19325. UNSIGNED_INT: 'uint',
  19326. UNSIGNED_INT_VEC2: 'uvec2',
  19327. UNSIGNED_INT_VEC3: 'uvec3',
  19328. UNSIGNED_INT_VEC4: 'uvec4',
  19329. BOOL: 'bool',
  19330. BOOL_VEC2: 'bvec2',
  19331. BOOL_VEC3: 'bvec3',
  19332. BOOL_VEC4: 'bvec4',
  19333. FLOAT_MAT2: 'mat2',
  19334. FLOAT_MAT3: 'mat3',
  19335. FLOAT_MAT4: 'mat4',
  19336. SAMPLER_2D: 'sampler2D',
  19337. INT_SAMPLER_2D: 'sampler2D',
  19338. UNSIGNED_INT_SAMPLER_2D: 'sampler2D',
  19339. SAMPLER_CUBE: 'samplerCube',
  19340. INT_SAMPLER_CUBE: 'samplerCube',
  19341. UNSIGNED_INT_SAMPLER_CUBE: 'samplerCube',
  19342. SAMPLER_2D_ARRAY: 'sampler2DArray',
  19343. INT_SAMPLER_2D_ARRAY: 'sampler2DArray',
  19344. UNSIGNED_INT_SAMPLER_2D_ARRAY: 'sampler2DArray',
  19345. };
  19346. // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
  19347. function mapType(gl, type) {
  19348. if (!GL_TABLE) {
  19349. var typeNames = Object.keys(GL_TO_GLSL_TYPES);
  19350. GL_TABLE = {};
  19351. for (var i = 0; i < typeNames.length; ++i) {
  19352. var tn = typeNames[i];
  19353. GL_TABLE[gl[tn]] = GL_TO_GLSL_TYPES[tn];
  19354. }
  19355. }
  19356. return GL_TABLE[type];
  19357. }
  19358. /* eslint-disable @typescript-eslint/explicit-module-boundary-types */
  19359. // Parsers, each one of these will take a look at the type of shader property and uniform.
  19360. // if they pass the test function then the code function is called that returns a the shader upload code for that uniform.
  19361. // Shader upload code is automagically generated with these parsers.
  19362. // If no parser is valid then the default upload functions are used.
  19363. // exposing Parsers means that custom upload logic can be added to pixi's shaders.
  19364. // A good example would be a pixi rectangle can be directly set on a uniform.
  19365. // If the shader sees it it knows how to upload the rectangle structure as a vec4
  19366. // format is as follows:
  19367. //
  19368. // {
  19369. // test: (data, uniform) => {} <--- test is this code should be used for this uniform
  19370. // code: (name, uniform) => {} <--- returns the string of the piece of code that uploads the uniform
  19371. // codeUbo: (name, uniform) => {} <--- returns the string of the piece of code that uploads the
  19372. // uniform to a uniform buffer
  19373. // }
  19374. var uniformParsers = [
  19375. // a float cache layer
  19376. {
  19377. test: function (data) {
  19378. return data.type === 'float' && data.size === 1;
  19379. },
  19380. code: function (name) {
  19381. return "\n if(uv[\"" + name + "\"] !== ud[\"" + name + "\"].value)\n {\n ud[\"" + name + "\"].value = uv[\"" + name + "\"]\n gl.uniform1f(ud[\"" + name + "\"].location, uv[\"" + name + "\"])\n }\n ";
  19382. },
  19383. },
  19384. // handling samplers
  19385. {
  19386. test: function (data) {
  19387. // eslint-disable-next-line max-len
  19388. return (data.type === 'sampler2D' || data.type === 'samplerCube' || data.type === 'sampler2DArray') && data.size === 1 && !data.isArray;
  19389. },
  19390. code: function (name) { return "t = syncData.textureCount++;\n\n renderer.texture.bind(uv[\"" + name + "\"], t);\n\n if(ud[\"" + name + "\"].value !== t)\n {\n ud[\"" + name + "\"].value = t;\n gl.uniform1i(ud[\"" + name + "\"].location, t);\n; // eslint-disable-line max-len\n }"; },
  19391. },
  19392. // uploading pixi matrix object to mat3
  19393. {
  19394. test: function (data, uniform) {
  19395. return data.type === 'mat3' && data.size === 1 && uniform.a !== undefined;
  19396. },
  19397. code: function (name) {
  19398. // TODO and some smart caching dirty ids here!
  19399. return "\n gl.uniformMatrix3fv(ud[\"" + name + "\"].location, false, uv[\"" + name + "\"].toArray(true));\n ";
  19400. },
  19401. codeUbo: function (name) {
  19402. return "\n var " + name + "_matrix = uv." + name + ".toArray(true);\n\n data[offset] = " + name + "_matrix[0];\n data[offset+1] = " + name + "_matrix[1];\n data[offset+2] = " + name + "_matrix[2];\n \n data[offset + 4] = " + name + "_matrix[3];\n data[offset + 5] = " + name + "_matrix[4];\n data[offset + 6] = " + name + "_matrix[5];\n \n data[offset + 8] = " + name + "_matrix[6];\n data[offset + 9] = " + name + "_matrix[7];\n data[offset + 10] = " + name + "_matrix[8];\n ";
  19403. },
  19404. },
  19405. // uploading a pixi point as a vec2 with caching layer
  19406. {
  19407. test: function (data, uniform) {
  19408. return data.type === 'vec2' && data.size === 1 && uniform.x !== undefined;
  19409. },
  19410. code: function (name) {
  19411. return "\n cv = ud[\"" + name + "\"].value;\n v = uv[\"" + name + "\"];\n\n if(cv[0] !== v.x || cv[1] !== v.y)\n {\n cv[0] = v.x;\n cv[1] = v.y;\n gl.uniform2f(ud[\"" + name + "\"].location, v.x, v.y);\n }";
  19412. },
  19413. codeUbo: function (name) {
  19414. return "\n v = uv." + name + ";\n\n data[offset] = v.x;\n data[offset+1] = v.y;\n ";
  19415. }
  19416. },
  19417. // caching layer for a vec2
  19418. {
  19419. test: function (data) {
  19420. return data.type === 'vec2' && data.size === 1;
  19421. },
  19422. code: function (name) {
  19423. return "\n cv = ud[\"" + name + "\"].value;\n v = uv[\"" + name + "\"];\n\n if(cv[0] !== v[0] || cv[1] !== v[1])\n {\n cv[0] = v[0];\n cv[1] = v[1];\n gl.uniform2f(ud[\"" + name + "\"].location, v[0], v[1]);\n }\n ";
  19424. },
  19425. },
  19426. // upload a pixi rectangle as a vec4 with caching layer
  19427. {
  19428. test: function (data, uniform) {
  19429. return data.type === 'vec4' && data.size === 1 && uniform.width !== undefined;
  19430. },
  19431. code: function (name) {
  19432. return "\n cv = ud[\"" + name + "\"].value;\n v = uv[\"" + name + "\"];\n\n if(cv[0] !== v.x || cv[1] !== v.y || cv[2] !== v.width || cv[3] !== v.height)\n {\n cv[0] = v.x;\n cv[1] = v.y;\n cv[2] = v.width;\n cv[3] = v.height;\n gl.uniform4f(ud[\"" + name + "\"].location, v.x, v.y, v.width, v.height)\n }";
  19433. },
  19434. codeUbo: function (name) {
  19435. return "\n v = uv." + name + ";\n\n data[offset] = v.x;\n data[offset+1] = v.y;\n data[offset+2] = v.width;\n data[offset+3] = v.height;\n ";
  19436. }
  19437. },
  19438. // a caching layer for vec4 uploading
  19439. {
  19440. test: function (data) {
  19441. return data.type === 'vec4' && data.size === 1;
  19442. },
  19443. code: function (name) {
  19444. return "\n cv = ud[\"" + name + "\"].value;\n v = uv[\"" + name + "\"];\n\n if(cv[0] !== v[0] || cv[1] !== v[1] || cv[2] !== v[2] || cv[3] !== v[3])\n {\n cv[0] = v[0];\n cv[1] = v[1];\n cv[2] = v[2];\n cv[3] = v[3];\n\n gl.uniform4f(ud[\"" + name + "\"].location, v[0], v[1], v[2], v[3])\n }";
  19445. },
  19446. } ];
  19447. // cv = CachedValue
  19448. // v = value
  19449. // ud = uniformData
  19450. // uv = uniformValue
  19451. // l = location
  19452. var GLSL_TO_SINGLE_SETTERS_CACHED = {
  19453. float: "\n if(cv !== v)\n {\n cv.v = v;\n gl.uniform1f(location, v)\n }",
  19454. vec2: "\n if(cv[0] !== v[0] || cv[1] !== v[1])\n {\n cv[0] = v[0];\n cv[1] = v[1];\n gl.uniform2f(location, v[0], v[1])\n }",
  19455. vec3: "\n if(cv[0] !== v[0] || cv[1] !== v[1] || cv[2] !== v[2])\n {\n cv[0] = v[0];\n cv[1] = v[1];\n cv[2] = v[2];\n\n gl.uniform3f(location, v[0], v[1], v[2])\n }",
  19456. vec4: 'gl.uniform4f(location, v[0], v[1], v[2], v[3])',
  19457. int: 'gl.uniform1i(location, v)',
  19458. ivec2: 'gl.uniform2i(location, v[0], v[1])',
  19459. ivec3: 'gl.uniform3i(location, v[0], v[1], v[2])',
  19460. ivec4: 'gl.uniform4i(location, v[0], v[1], v[2], v[3])',
  19461. uint: 'gl.uniform1ui(location, v)',
  19462. uvec2: 'gl.uniform2ui(location, v[0], v[1])',
  19463. uvec3: 'gl.uniform3ui(location, v[0], v[1], v[2])',
  19464. uvec4: 'gl.uniform4ui(location, v[0], v[1], v[2], v[3])',
  19465. bool: 'gl.uniform1i(location, v)',
  19466. bvec2: 'gl.uniform2i(location, v[0], v[1])',
  19467. bvec3: 'gl.uniform3i(location, v[0], v[1], v[2])',
  19468. bvec4: 'gl.uniform4i(location, v[0], v[1], v[2], v[3])',
  19469. mat2: 'gl.uniformMatrix2fv(location, false, v)',
  19470. mat3: 'gl.uniformMatrix3fv(location, false, v)',
  19471. mat4: 'gl.uniformMatrix4fv(location, false, v)',
  19472. sampler2D: 'gl.uniform1i(location, v)',
  19473. samplerCube: 'gl.uniform1i(location, v)',
  19474. sampler2DArray: 'gl.uniform1i(location, v)',
  19475. };
  19476. var GLSL_TO_ARRAY_SETTERS = {
  19477. float: "gl.uniform1fv(location, v)",
  19478. vec2: "gl.uniform2fv(location, v)",
  19479. vec3: "gl.uniform3fv(location, v)",
  19480. vec4: 'gl.uniform4fv(location, v)',
  19481. mat4: 'gl.uniformMatrix4fv(location, false, v)',
  19482. mat3: 'gl.uniformMatrix3fv(location, false, v)',
  19483. mat2: 'gl.uniformMatrix2fv(location, false, v)',
  19484. int: 'gl.uniform1iv(location, v)',
  19485. ivec2: 'gl.uniform2iv(location, v)',
  19486. ivec3: 'gl.uniform3iv(location, v)',
  19487. ivec4: 'gl.uniform4iv(location, v)',
  19488. uint: 'gl.uniform1uiv(location, v)',
  19489. uvec2: 'gl.uniform2uiv(location, v)',
  19490. uvec3: 'gl.uniform3uiv(location, v)',
  19491. uvec4: 'gl.uniform4uiv(location, v)',
  19492. bool: 'gl.uniform1iv(location, v)',
  19493. bvec2: 'gl.uniform2iv(location, v)',
  19494. bvec3: 'gl.uniform3iv(location, v)',
  19495. bvec4: 'gl.uniform4iv(location, v)',
  19496. sampler2D: 'gl.uniform1iv(location, v)',
  19497. samplerCube: 'gl.uniform1iv(location, v)',
  19498. sampler2DArray: 'gl.uniform1iv(location, v)',
  19499. };
  19500. function generateUniformsSync(group, uniformData) {
  19501. var funcFragments = ["\n var v = null;\n var cv = null\n var t = 0;\n var gl = renderer.gl\n "];
  19502. for (var i in group.uniforms) {
  19503. var data = uniformData[i];
  19504. if (!data) {
  19505. if (group.uniforms[i].group) {
  19506. if (group.uniforms[i].ubo) {
  19507. funcFragments.push("\n renderer.shader.syncUniformBufferGroup(uv." + i + ", '" + i + "');\n ");
  19508. }
  19509. else {
  19510. funcFragments.push("\n renderer.shader.syncUniformGroup(uv." + i + ", syncData);\n ");
  19511. }
  19512. }
  19513. continue;
  19514. }
  19515. var uniform = group.uniforms[i];
  19516. var parsed = false;
  19517. for (var j = 0; j < uniformParsers.length; j++) {
  19518. if (uniformParsers[j].test(data, uniform)) {
  19519. funcFragments.push(uniformParsers[j].code(i, uniform));
  19520. parsed = true;
  19521. break;
  19522. }
  19523. }
  19524. if (!parsed) {
  19525. var templateType = (data.size === 1) ? GLSL_TO_SINGLE_SETTERS_CACHED : GLSL_TO_ARRAY_SETTERS;
  19526. var template = templateType[data.type].replace('location', "ud[\"" + i + "\"].location");
  19527. funcFragments.push("\n cv = ud[\"" + i + "\"].value;\n v = uv[\"" + i + "\"];\n " + template + ";");
  19528. }
  19529. }
  19530. /*
  19531. * the introduction of syncData is to solve an issue where textures in uniform groups are not set correctly
  19532. * the texture count was always starting from 0 in each group. This needs to increment each time a texture is used
  19533. * no matter which group is being used
  19534. *
  19535. */
  19536. // eslint-disable-next-line no-new-func
  19537. return new Function('ud', 'uv', 'renderer', 'syncData', funcFragments.join('\n'));
  19538. }
  19539. var fragTemplate = [
  19540. 'precision mediump float;',
  19541. 'void main(void){',
  19542. 'float test = 0.1;',
  19543. '%forloop%',
  19544. 'gl_FragColor = vec4(0.0);',
  19545. '}' ].join('\n');
  19546. function generateIfTestSrc(maxIfs) {
  19547. var src = '';
  19548. for (var i = 0; i < maxIfs; ++i) {
  19549. if (i > 0) {
  19550. src += '\nelse ';
  19551. }
  19552. if (i < maxIfs - 1) {
  19553. src += "if(test == " + i + ".0){}";
  19554. }
  19555. }
  19556. return src;
  19557. }
  19558. function checkMaxIfStatementsInShader(maxIfs, gl) {
  19559. if (maxIfs === 0) {
  19560. throw new Error('Invalid value of `0` passed to `checkMaxIfStatementsInShader`');
  19561. }
  19562. var shader = gl.createShader(gl.FRAGMENT_SHADER);
  19563. while (true) // eslint-disable-line no-constant-condition
  19564. {
  19565. var fragmentSrc = fragTemplate.replace(/%forloop%/gi, generateIfTestSrc(maxIfs));
  19566. gl.shaderSource(shader, fragmentSrc);
  19567. gl.compileShader(shader);
  19568. if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
  19569. maxIfs = (maxIfs / 2) | 0;
  19570. }
  19571. else {
  19572. // valid!
  19573. break;
  19574. }
  19575. }
  19576. return maxIfs;
  19577. }
  19578. // Cache the result to prevent running this over and over
  19579. var unsafeEval;
  19580. /**
  19581. * Not all platforms allow to generate function code (e.g., `new Function`).
  19582. * this provides the platform-level detection.
  19583. *
  19584. * @private
  19585. * @returns {boolean}
  19586. */
  19587. function unsafeEvalSupported() {
  19588. if (typeof unsafeEval === 'boolean') {
  19589. return unsafeEval;
  19590. }
  19591. try {
  19592. /* eslint-disable no-new-func */
  19593. var func = new Function('param1', 'param2', 'param3', 'return param1[param2] === param3;');
  19594. /* eslint-enable no-new-func */
  19595. unsafeEval = func({ a: 'b' }, 'a', 'b') === true;
  19596. }
  19597. catch (e) {
  19598. unsafeEval = false;
  19599. }
  19600. return unsafeEval;
  19601. }
  19602. var defaultFragment = "varying vec2 vTextureCoord;\n\nuniform sampler2D uSampler;\n\nvoid main(void){\n gl_FragColor *= texture2D(uSampler, vTextureCoord);\n}";
  19603. var defaultVertex = "attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\n\nuniform mat3 projectionMatrix;\n\nvarying vec2 vTextureCoord;\n\nvoid main(void){\n gl_Position = vec4((projectionMatrix * vec3(aVertexPosition, 1.0)).xy, 0.0, 1.0);\n vTextureCoord = aTextureCoord;\n}\n";
  19604. var UID$3 = 0;
  19605. var nameCache = {};
  19606. /**
  19607. * Helper class to create a shader program.
  19608. *
  19609. * @class
  19610. * @memberof PIXI
  19611. */
  19612. var Program = /** @class */ (function () {
  19613. /**
  19614. * @param {string} [vertexSrc] - The source of the vertex shader.
  19615. * @param {string} [fragmentSrc] - The source of the fragment shader.
  19616. * @param {string} [name] - Name for shader
  19617. */
  19618. function Program(vertexSrc, fragmentSrc, name) {
  19619. if (name === void 0) { name = 'pixi-shader'; }
  19620. this.id = UID$3++;
  19621. /**
  19622. * The vertex shader.
  19623. *
  19624. * @member {string}
  19625. */
  19626. this.vertexSrc = vertexSrc || Program.defaultVertexSrc;
  19627. /**
  19628. * The fragment shader.
  19629. *
  19630. * @member {string}
  19631. */
  19632. this.fragmentSrc = fragmentSrc || Program.defaultFragmentSrc;
  19633. this.vertexSrc = this.vertexSrc.trim();
  19634. this.fragmentSrc = this.fragmentSrc.trim();
  19635. if (this.vertexSrc.substring(0, 8) !== '#version') {
  19636. name = name.replace(/\s+/g, '-');
  19637. if (nameCache[name]) {
  19638. nameCache[name]++;
  19639. name += "-" + nameCache[name];
  19640. }
  19641. else {
  19642. nameCache[name] = 1;
  19643. }
  19644. this.vertexSrc = "#define SHADER_NAME " + name + "\n" + this.vertexSrc;
  19645. this.fragmentSrc = "#define SHADER_NAME " + name + "\n" + this.fragmentSrc;
  19646. this.vertexSrc = setPrecision(this.vertexSrc, settings.PRECISION_VERTEX, exports.PRECISION.HIGH);
  19647. this.fragmentSrc = setPrecision(this.fragmentSrc, settings.PRECISION_FRAGMENT, getMaxFragmentPrecision());
  19648. }
  19649. // currently this does not extract structs only default types
  19650. // this is where we store shader references..
  19651. this.glPrograms = {};
  19652. this.syncUniforms = null;
  19653. }
  19654. Object.defineProperty(Program, "defaultVertexSrc", {
  19655. /**
  19656. * The default vertex shader source
  19657. *
  19658. * @static
  19659. * @constant
  19660. * @member {string}
  19661. */
  19662. get: function () {
  19663. return defaultVertex;
  19664. },
  19665. enumerable: false,
  19666. configurable: true
  19667. });
  19668. Object.defineProperty(Program, "defaultFragmentSrc", {
  19669. /**
  19670. * The default fragment shader source
  19671. *
  19672. * @static
  19673. * @constant
  19674. * @member {string}
  19675. */
  19676. get: function () {
  19677. return defaultFragment;
  19678. },
  19679. enumerable: false,
  19680. configurable: true
  19681. });
  19682. /**
  19683. * A short hand function to create a program based of a vertex and fragment shader
  19684. * this method will also check to see if there is a cached program.
  19685. *
  19686. * @param {string} [vertexSrc] - The source of the vertex shader.
  19687. * @param {string} [fragmentSrc] - The source of the fragment shader.
  19688. * @param {string} [name=pixi-shader] - Name for shader
  19689. *
  19690. * @returns {PIXI.Program} an shiny new Pixi shader!
  19691. */
  19692. Program.from = function (vertexSrc, fragmentSrc, name) {
  19693. var key = vertexSrc + fragmentSrc;
  19694. var program = ProgramCache[key];
  19695. if (!program) {
  19696. ProgramCache[key] = program = new Program(vertexSrc, fragmentSrc, name);
  19697. }
  19698. return program;
  19699. };
  19700. return Program;
  19701. }());
  19702. /**
  19703. * A helper class for shaders
  19704. *
  19705. * @class
  19706. * @memberof PIXI
  19707. */
  19708. var Shader = /** @class */ (function () {
  19709. /**
  19710. * @param {PIXI.Program} [program] - The program the shader will use.
  19711. * @param {object} [uniforms] - Custom uniforms to use to augment the built-in ones.
  19712. */
  19713. function Shader(program, uniforms) {
  19714. /**
  19715. * used internally to bind uniform buffer objects
  19716. * @ignore
  19717. */
  19718. this.uniformBindCount = 0;
  19719. /**
  19720. * Program that the shader uses
  19721. *
  19722. * @member {PIXI.Program}
  19723. */
  19724. this.program = program;
  19725. // lets see whats been passed in
  19726. // uniforms should be converted to a uniform group
  19727. if (uniforms) {
  19728. if (uniforms instanceof UniformGroup) {
  19729. this.uniformGroup = uniforms;
  19730. }
  19731. else {
  19732. this.uniformGroup = new UniformGroup(uniforms);
  19733. }
  19734. }
  19735. else {
  19736. this.uniformGroup = new UniformGroup({});
  19737. }
  19738. }
  19739. // TODO move to shader system..
  19740. Shader.prototype.checkUniformExists = function (name, group) {
  19741. if (group.uniforms[name]) {
  19742. return true;
  19743. }
  19744. for (var i in group.uniforms) {
  19745. var uniform = group.uniforms[i];
  19746. if (uniform.group) {
  19747. if (this.checkUniformExists(name, uniform)) {
  19748. return true;
  19749. }
  19750. }
  19751. }
  19752. return false;
  19753. };
  19754. Shader.prototype.destroy = function () {
  19755. // usage count on programs?
  19756. // remove if not used!
  19757. this.uniformGroup = null;
  19758. };
  19759. Object.defineProperty(Shader.prototype, "uniforms", {
  19760. /**
  19761. * Shader uniform values, shortcut for `uniformGroup.uniforms`
  19762. * @readonly
  19763. * @member {object}
  19764. */
  19765. get: function () {
  19766. return this.uniformGroup.uniforms;
  19767. },
  19768. enumerable: false,
  19769. configurable: true
  19770. });
  19771. /**
  19772. * A short hand function to create a shader based of a vertex and fragment shader
  19773. *
  19774. * @param {string} [vertexSrc] - The source of the vertex shader.
  19775. * @param {string} [fragmentSrc] - The source of the fragment shader.
  19776. * @param {object} [uniforms] - Custom uniforms to use to augment the built-in ones.
  19777. *
  19778. * @returns {PIXI.Shader} an shiny new Pixi shader!
  19779. */
  19780. Shader.from = function (vertexSrc, fragmentSrc, uniforms) {
  19781. var program = Program.from(vertexSrc, fragmentSrc);
  19782. return new Shader(program, uniforms);
  19783. };
  19784. return Shader;
  19785. }());
  19786. /* eslint-disable max-len */
  19787. var BLEND = 0;
  19788. var OFFSET = 1;
  19789. var CULLING = 2;
  19790. var DEPTH_TEST = 3;
  19791. var WINDING = 4;
  19792. var DEPTH_MASK = 5;
  19793. /**
  19794. * This is a WebGL state, and is is passed The WebGL StateManager.
  19795. *
  19796. * Each mesh rendered may require WebGL to be in a different state.
  19797. * For example you may want different blend mode or to enable polygon offsets
  19798. *
  19799. * @class
  19800. * @memberof PIXI
  19801. */
  19802. var State = /** @class */ (function () {
  19803. function State() {
  19804. this.data = 0;
  19805. this.blendMode = exports.BLEND_MODES.NORMAL;
  19806. this.polygonOffset = 0;
  19807. this.blend = true;
  19808. this.depthMask = true;
  19809. // this.depthTest = true;
  19810. }
  19811. Object.defineProperty(State.prototype, "blend", {
  19812. /**
  19813. * Activates blending of the computed fragment color values
  19814. *
  19815. * @member {boolean}
  19816. */
  19817. get: function () {
  19818. return !!(this.data & (1 << BLEND));
  19819. },
  19820. set: function (value) {
  19821. if (!!(this.data & (1 << BLEND)) !== value) {
  19822. this.data ^= (1 << BLEND);
  19823. }
  19824. },
  19825. enumerable: false,
  19826. configurable: true
  19827. });
  19828. Object.defineProperty(State.prototype, "offsets", {
  19829. /**
  19830. * Activates adding an offset to depth values of polygon's fragments
  19831. *
  19832. * @member {boolean}
  19833. * @default false
  19834. */
  19835. get: function () {
  19836. return !!(this.data & (1 << OFFSET));
  19837. },
  19838. set: function (value) {
  19839. if (!!(this.data & (1 << OFFSET)) !== value) {
  19840. this.data ^= (1 << OFFSET);
  19841. }
  19842. },
  19843. enumerable: false,
  19844. configurable: true
  19845. });
  19846. Object.defineProperty(State.prototype, "culling", {
  19847. /**
  19848. * Activates culling of polygons.
  19849. *
  19850. * @member {boolean}
  19851. * @default false
  19852. */
  19853. get: function () {
  19854. return !!(this.data & (1 << CULLING));
  19855. },
  19856. set: function (value) {
  19857. if (!!(this.data & (1 << CULLING)) !== value) {
  19858. this.data ^= (1 << CULLING);
  19859. }
  19860. },
  19861. enumerable: false,
  19862. configurable: true
  19863. });
  19864. Object.defineProperty(State.prototype, "depthTest", {
  19865. /**
  19866. * Activates depth comparisons and updates to the depth buffer.
  19867. *
  19868. * @member {boolean}
  19869. * @default false
  19870. */
  19871. get: function () {
  19872. return !!(this.data & (1 << DEPTH_TEST));
  19873. },
  19874. set: function (value) {
  19875. if (!!(this.data & (1 << DEPTH_TEST)) !== value) {
  19876. this.data ^= (1 << DEPTH_TEST);
  19877. }
  19878. },
  19879. enumerable: false,
  19880. configurable: true
  19881. });
  19882. Object.defineProperty(State.prototype, "depthMask", {
  19883. /**
  19884. * Enables or disables writing to the depth buffer.
  19885. *
  19886. * @member {boolean}
  19887. * @default true
  19888. */
  19889. get: function () {
  19890. return !!(this.data & (1 << DEPTH_MASK));
  19891. },
  19892. set: function (value) {
  19893. if (!!(this.data & (1 << DEPTH_MASK)) !== value) {
  19894. this.data ^= (1 << DEPTH_MASK);
  19895. }
  19896. },
  19897. enumerable: false,
  19898. configurable: true
  19899. });
  19900. Object.defineProperty(State.prototype, "clockwiseFrontFace", {
  19901. /**
  19902. * Specifies whether or not front or back-facing polygons can be culled.
  19903. * @member {boolean}
  19904. * @default false
  19905. */
  19906. get: function () {
  19907. return !!(this.data & (1 << WINDING));
  19908. },
  19909. set: function (value) {
  19910. if (!!(this.data & (1 << WINDING)) !== value) {
  19911. this.data ^= (1 << WINDING);
  19912. }
  19913. },
  19914. enumerable: false,
  19915. configurable: true
  19916. });
  19917. Object.defineProperty(State.prototype, "blendMode", {
  19918. /**
  19919. * The blend mode to be applied when this state is set. Apply a value of `PIXI.BLEND_MODES.NORMAL` to reset the blend mode.
  19920. * Setting this mode to anything other than NO_BLEND will automatically switch blending on.
  19921. *
  19922. * @member {number}
  19923. * @default PIXI.BLEND_MODES.NORMAL
  19924. * @see PIXI.BLEND_MODES
  19925. */
  19926. get: function () {
  19927. return this._blendMode;
  19928. },
  19929. set: function (value) {
  19930. this.blend = (value !== exports.BLEND_MODES.NONE);
  19931. this._blendMode = value;
  19932. },
  19933. enumerable: false,
  19934. configurable: true
  19935. });
  19936. Object.defineProperty(State.prototype, "polygonOffset", {
  19937. /**
  19938. * The polygon offset. Setting this property to anything other than 0 will automatically enable polygon offset fill.
  19939. *
  19940. * @member {number}
  19941. * @default 0
  19942. */
  19943. get: function () {
  19944. return this._polygonOffset;
  19945. },
  19946. set: function (value) {
  19947. this.offsets = !!value;
  19948. this._polygonOffset = value;
  19949. },
  19950. enumerable: false,
  19951. configurable: true
  19952. });
  19953. State.prototype.toString = function () {
  19954. return "[@pixi/core:State "
  19955. + ("blendMode=" + this.blendMode + " ")
  19956. + ("clockwiseFrontFace=" + this.clockwiseFrontFace + " ")
  19957. + ("culling=" + this.culling + " ")
  19958. + ("depthMask=" + this.depthMask + " ")
  19959. + ("polygonOffset=" + this.polygonOffset)
  19960. + "]";
  19961. };
  19962. State.for2d = function () {
  19963. var state = new State();
  19964. state.depthTest = false;
  19965. state.blend = true;
  19966. return state;
  19967. };
  19968. return State;
  19969. }());
  19970. var defaultVertex$1 = "attribute vec2 aVertexPosition;\n\nuniform mat3 projectionMatrix;\n\nvarying vec2 vTextureCoord;\n\nuniform vec4 inputSize;\nuniform vec4 outputFrame;\n\nvec4 filterVertexPosition( void )\n{\n vec2 position = aVertexPosition * max(outputFrame.zw, vec2(0.)) + outputFrame.xy;\n\n return vec4((projectionMatrix * vec3(position, 1.0)).xy, 0.0, 1.0);\n}\n\nvec2 filterTextureCoord( void )\n{\n return aVertexPosition * (outputFrame.zw * inputSize.zw);\n}\n\nvoid main(void)\n{\n gl_Position = filterVertexPosition();\n vTextureCoord = filterTextureCoord();\n}\n";
  19971. var defaultFragment$1 = "varying vec2 vTextureCoord;\n\nuniform sampler2D uSampler;\n\nvoid main(void){\n gl_FragColor = texture2D(uSampler, vTextureCoord);\n}\n";
  19972. /**
  19973. * A filter is a special shader that applies post-processing effects to an input texture and writes into an output
  19974. * render-target.
  19975. *
  19976. * {@link http://pixijs.io/examples/#/filters/blur-filter.js Example} of the
  19977. * {@link PIXI.filters.BlurFilter BlurFilter}.
  19978. *
  19979. * ### Usage
  19980. * Filters can be applied to any DisplayObject or Container.
  19981. * PixiJS' `FilterSystem` renders the container into temporary Framebuffer,
  19982. * then filter renders it to the screen.
  19983. * Multiple filters can be added to the `filters` array property and stacked on each other.
  19984. *
  19985. * ```
  19986. * const filter = new PIXI.Filter(myShaderVert, myShaderFrag, { myUniform: 0.5 });
  19987. * const container = new PIXI.Container();
  19988. * container.filters = [filter];
  19989. * ```
  19990. *
  19991. * ### Previous Version Differences
  19992. *
  19993. * In PixiJS **v3**, a filter was always applied to _whole screen_.
  19994. *
  19995. * In PixiJS **v4**, a filter can be applied _only part of the screen_.
  19996. * Developers had to create a set of uniforms to deal with coordinates.
  19997. *
  19998. * In PixiJS **v5** combines _both approaches_.
  19999. * Developers can use normal coordinates of v3 and then allow filter to use partial Framebuffers,
  20000. * bringing those extra uniforms into account.
  20001. *
  20002. * Also be aware that we have changed default vertex shader, please consult
  20003. * {@link https://github.com/pixijs/pixi.js/wiki/v5-Creating-filters Wiki}.
  20004. *
  20005. * ### Frames
  20006. *
  20007. * The following table summarizes the coordinate spaces used in the filtering pipeline:
  20008. *
  20009. * <table>
  20010. * <thead>
  20011. * <tr>
  20012. * <th>Coordinate Space</th>
  20013. * <th>Description</th>
  20014. * </tr>
  20015. * </thead>
  20016. * <tbody>
  20017. * <tr>
  20018. * <td>Texture Coordinates</td>
  20019. * <td>
  20020. * The texture (or UV) coordinates in the input base-texture's space. These are normalized into the (0,1) range along
  20021. * both axes.
  20022. * </td>
  20023. * </tr>
  20024. * <tr>
  20025. * <td>World Space</td>
  20026. * <td>
  20027. * A point in the same space as the world bounds of any display-object (i.e. in the scene graph's space).
  20028. * </td>
  20029. * </tr>
  20030. * <tr>
  20031. * <td>Physical Pixels</td>
  20032. * <td>
  20033. * This is base-texture's space with the origin on the top-left. You can calculate these by multiplying the texture
  20034. * coordinates by the dimensions of the texture.
  20035. * </td>
  20036. * </tr>
  20037. * </tbody>
  20038. * </table>
  20039. *
  20040. * ### Built-in Uniforms
  20041. *
  20042. * PixiJS viewport uses screen (CSS) coordinates, `(0, 0, renderer.screen.width, renderer.screen.height)`,
  20043. * and `projectionMatrix` uniform maps it to the gl viewport.
  20044. *
  20045. * **uSampler**
  20046. *
  20047. * The most important uniform is the input texture that container was rendered into.
  20048. * _Important note: as with all Framebuffers in PixiJS, both input and output are
  20049. * premultiplied by alpha._
  20050. *
  20051. * By default, input normalized coordinates are passed to fragment shader with `vTextureCoord`.
  20052. * Use it to sample the input.
  20053. *
  20054. * ```
  20055. * const fragment = `
  20056. * varying vec2 vTextureCoord;
  20057. * uniform sampler2D uSampler;
  20058. * void main(void)
  20059. * {
  20060. * gl_FragColor = texture2D(uSampler, vTextureCoord);
  20061. * }
  20062. * `;
  20063. *
  20064. * const myFilter = new PIXI.Filter(null, fragment);
  20065. * ```
  20066. *
  20067. * This filter is just one uniform less than {@link PIXI.filters.AlphaFilter AlphaFilter}.
  20068. *
  20069. * **outputFrame**
  20070. *
  20071. * The `outputFrame` holds the rectangle where filter is applied in screen (CSS) coordinates.
  20072. * It's the same as `renderer.screen` for a fullscreen filter.
  20073. * Only a part of `outputFrame.zw` size of temporary Framebuffer is used,
  20074. * `(0, 0, outputFrame.width, outputFrame.height)`,
  20075. *
  20076. * Filters uses this quad to normalized (0-1) space, its passed into `aVertexPosition` attribute.
  20077. * To calculate vertex position in screen space using normalized (0-1) space:
  20078. *
  20079. * ```
  20080. * vec4 filterVertexPosition( void )
  20081. * {
  20082. * vec2 position = aVertexPosition * max(outputFrame.zw, vec2(0.)) + outputFrame.xy;
  20083. * return vec4((projectionMatrix * vec3(position, 1.0)).xy, 0.0, 1.0);
  20084. * }
  20085. * ```
  20086. *
  20087. * **inputSize**
  20088. *
  20089. * Temporary framebuffer is different, it can be either the size of screen, either power-of-two.
  20090. * The `inputSize.xy` are size of temporary framebuffer that holds input.
  20091. * The `inputSize.zw` is inverted, it's a shortcut to evade division inside the shader.
  20092. *
  20093. * Set `inputSize.xy = outputFrame.zw` for a fullscreen filter.
  20094. *
  20095. * To calculate input normalized coordinate, you have to map it to filter normalized space.
  20096. * Multiply by `outputFrame.zw` to get input coordinate.
  20097. * Divide by `inputSize.xy` to get input normalized coordinate.
  20098. *
  20099. * ```
  20100. * vec2 filterTextureCoord( void )
  20101. * {
  20102. * return aVertexPosition * (outputFrame.zw * inputSize.zw); // same as /inputSize.xy
  20103. * }
  20104. * ```
  20105. * **resolution**
  20106. *
  20107. * The `resolution` is the ratio of screen (CSS) pixels to real pixels.
  20108. *
  20109. * **inputPixel**
  20110. *
  20111. * `inputPixel.xy` is the size of framebuffer in real pixels, same as `inputSize.xy * resolution`
  20112. * `inputPixel.zw` is inverted `inputPixel.xy`.
  20113. *
  20114. * It's handy for filters that use neighbour pixels, like {@link PIXI.filters.FXAAFilter FXAAFilter}.
  20115. *
  20116. * **inputClamp**
  20117. *
  20118. * If you try to get info from outside of used part of Framebuffer - you'll get undefined behaviour.
  20119. * For displacements, coordinates has to be clamped.
  20120. *
  20121. * The `inputClamp.xy` is left-top pixel center, you may ignore it, because we use left-top part of Framebuffer
  20122. * `inputClamp.zw` is bottom-right pixel center.
  20123. *
  20124. * ```
  20125. * vec4 color = texture2D(uSampler, clamp(modifiedTextureCoord, inputClamp.xy, inputClamp.zw))
  20126. * ```
  20127. * OR
  20128. * ```
  20129. * vec4 color = texture2D(uSampler, min(modifigedTextureCoord, inputClamp.zw))
  20130. * ```
  20131. *
  20132. * ### Additional Information
  20133. *
  20134. * Complete documentation on Filter usage is located in the
  20135. * {@link https://github.com/pixijs/pixi.js/wiki/v5-Creating-filters Wiki}.
  20136. *
  20137. * Since PixiJS only had a handful of built-in filters, additional filters can be downloaded
  20138. * {@link https://github.com/pixijs/pixi-filters here} from the PixiJS Filters repository.
  20139. *
  20140. * @class
  20141. * @memberof PIXI
  20142. * @extends PIXI.Shader
  20143. */
  20144. var Filter = /** @class */ (function (_super) {
  20145. __extends$2(Filter, _super);
  20146. /**
  20147. * @param {string} [vertexSrc] - The source of the vertex shader.
  20148. * @param {string} [fragmentSrc] - The source of the fragment shader.
  20149. * @param {object} [uniforms] - Custom uniforms to use to augment the built-in ones.
  20150. */
  20151. function Filter(vertexSrc, fragmentSrc, uniforms) {
  20152. var _this = this;
  20153. var program = Program.from(vertexSrc || Filter.defaultVertexSrc, fragmentSrc || Filter.defaultFragmentSrc);
  20154. _this = _super.call(this, program, uniforms) || this;
  20155. /**
  20156. * The padding of the filter. Some filters require extra space to breath such as a blur.
  20157. * Increasing this will add extra width and height to the bounds of the object that the
  20158. * filter is applied to.
  20159. *
  20160. * @member {number}
  20161. */
  20162. _this.padding = 0;
  20163. /**
  20164. * The resolution of the filter. Setting this to be lower will lower the quality but
  20165. * increase the performance of the filter.
  20166. *
  20167. * @member {number}
  20168. */
  20169. _this.resolution = settings.FILTER_RESOLUTION;
  20170. /**
  20171. * The samples of the filter.
  20172. *
  20173. * @member {PIXI.MSAA_QUALITY}
  20174. */
  20175. _this.multisample = settings.FILTER_MULTISAMPLE;
  20176. /**
  20177. * If enabled is true the filter is applied, if false it will not.
  20178. *
  20179. * @member {boolean}
  20180. */
  20181. _this.enabled = true;
  20182. /**
  20183. * If enabled, PixiJS will fit the filter area into boundaries for better performance.
  20184. * Switch it off if it does not work for specific shader.
  20185. *
  20186. * @member {boolean}
  20187. */
  20188. _this.autoFit = true;
  20189. /**
  20190. * The WebGL state the filter requires to render
  20191. * @member {PIXI.State}
  20192. */
  20193. _this.state = new State();
  20194. return _this;
  20195. }
  20196. /**
  20197. * Applies the filter
  20198. *
  20199. * @param {PIXI.FilterSystem} filterManager - The renderer to retrieve the filter from
  20200. * @param {PIXI.RenderTexture} input - The input render target.
  20201. * @param {PIXI.RenderTexture} output - The target to output to.
  20202. * @param {PIXI.CLEAR_MODES} [clearMode] - Should the output be cleared before rendering to it.
  20203. * @param {object} [currentState] - It's current state of filter.
  20204. * There are some useful properties in the currentState :
  20205. * target, filters, sourceFrame, destinationFrame, renderTarget, resolution
  20206. */
  20207. Filter.prototype.apply = function (filterManager, input, output, clearMode, _currentState) {
  20208. // do as you please!
  20209. filterManager.applyFilter(this, input, output, clearMode);
  20210. // or just do a regular render..
  20211. };
  20212. Object.defineProperty(Filter.prototype, "blendMode", {
  20213. /**
  20214. * Sets the blendmode of the filter
  20215. *
  20216. * @member {number}
  20217. * @default PIXI.BLEND_MODES.NORMAL
  20218. */
  20219. get: function () {
  20220. return this.state.blendMode;
  20221. },
  20222. set: function (value) {
  20223. this.state.blendMode = value;
  20224. },
  20225. enumerable: false,
  20226. configurable: true
  20227. });
  20228. Object.defineProperty(Filter, "defaultVertexSrc", {
  20229. /**
  20230. * The default vertex shader source
  20231. *
  20232. * @static
  20233. * @type {string}
  20234. * @constant
  20235. */
  20236. get: function () {
  20237. return defaultVertex$1;
  20238. },
  20239. enumerable: false,
  20240. configurable: true
  20241. });
  20242. Object.defineProperty(Filter, "defaultFragmentSrc", {
  20243. /**
  20244. * The default fragment shader source
  20245. *
  20246. * @static
  20247. * @type {string}
  20248. * @constant
  20249. */
  20250. get: function () {
  20251. return defaultFragment$1;
  20252. },
  20253. enumerable: false,
  20254. configurable: true
  20255. });
  20256. return Filter;
  20257. }(Shader));
  20258. var vertex = "attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\n\nuniform mat3 projectionMatrix;\nuniform mat3 otherMatrix;\n\nvarying vec2 vMaskCoord;\nvarying vec2 vTextureCoord;\n\nvoid main(void)\n{\n gl_Position = vec4((projectionMatrix * vec3(aVertexPosition, 1.0)).xy, 0.0, 1.0);\n\n vTextureCoord = aTextureCoord;\n vMaskCoord = ( otherMatrix * vec3( aTextureCoord, 1.0) ).xy;\n}\n";
  20259. var fragment = "varying vec2 vMaskCoord;\nvarying vec2 vTextureCoord;\n\nuniform sampler2D uSampler;\nuniform sampler2D mask;\nuniform float alpha;\nuniform float npmAlpha;\nuniform vec4 maskClamp;\n\nvoid main(void)\n{\n float clip = step(3.5,\n step(maskClamp.x, vMaskCoord.x) +\n step(maskClamp.y, vMaskCoord.y) +\n step(vMaskCoord.x, maskClamp.z) +\n step(vMaskCoord.y, maskClamp.w));\n\n vec4 original = texture2D(uSampler, vTextureCoord);\n vec4 masky = texture2D(mask, vMaskCoord);\n float alphaMul = 1.0 - npmAlpha * (1.0 - masky.a);\n\n original *= (alphaMul * masky.r * alpha * clip);\n\n gl_FragColor = original;\n}\n";
  20260. var tempMat = new Matrix();
  20261. /**
  20262. * Class controls uv mapping from Texture normal space to BaseTexture normal space.
  20263. *
  20264. * Takes `trim` and `rotate` into account. May contain clamp settings for Meshes and TilingSprite.
  20265. *
  20266. * Can be used in Texture `uvMatrix` field, or separately, you can use different clamp settings on the same texture.
  20267. * If you want to add support for texture region of certain feature or filter, that's what you're looking for.
  20268. *
  20269. * Takes track of Texture changes through `_lastTextureID` private field.
  20270. * Use `update()` method call to track it from outside.
  20271. *
  20272. * @see PIXI.Texture
  20273. * @see PIXI.Mesh
  20274. * @see PIXI.TilingSprite
  20275. * @class
  20276. * @memberof PIXI
  20277. */
  20278. var TextureMatrix = /** @class */ (function () {
  20279. /**
  20280. *
  20281. * @param {PIXI.Texture} texture - observed texture
  20282. * @param {number} [clampMargin] - Changes frame clamping, 0.5 by default. Use -0.5 for extra border.
  20283. * @constructor
  20284. */
  20285. function TextureMatrix(texture, clampMargin) {
  20286. this._texture = texture;
  20287. /**
  20288. * Matrix operation that converts texture region coords to texture coords
  20289. * @member {PIXI.Matrix}
  20290. * @readonly
  20291. */
  20292. this.mapCoord = new Matrix();
  20293. /**
  20294. * Clamp region for normalized coords, left-top pixel center in xy , bottom-right in zw.
  20295. * Calculated based on clampOffset.
  20296. * @member {Float32Array}
  20297. * @readonly
  20298. */
  20299. this.uClampFrame = new Float32Array(4);
  20300. /**
  20301. * Normalized clamp offset.
  20302. * Calculated based on clampOffset.
  20303. * @member {Float32Array}
  20304. * @readonly
  20305. */
  20306. this.uClampOffset = new Float32Array(2);
  20307. /**
  20308. * Tracks Texture frame changes
  20309. * @member {number}
  20310. * @protected
  20311. */
  20312. this._textureID = -1;
  20313. /**
  20314. * Tracks Texture frame changes
  20315. * @member {number}
  20316. * @protected
  20317. */
  20318. this._updateID = 0;
  20319. /**
  20320. * Changes frame clamping
  20321. * Works with TilingSprite and Mesh
  20322. * Change to 1.5 if you texture has repeated right and bottom lines, that leads to smoother borders
  20323. *
  20324. * @default 0
  20325. * @member {number}
  20326. */
  20327. this.clampOffset = 0;
  20328. /**
  20329. * Changes frame clamping
  20330. * Works with TilingSprite and Mesh
  20331. * Change to -0.5 to add a pixel to the edge, recommended for transparent trimmed textures in atlas
  20332. *
  20333. * @default 0.5
  20334. * @member {number}
  20335. */
  20336. this.clampMargin = (typeof clampMargin === 'undefined') ? 0.5 : clampMargin;
  20337. /**
  20338. * If texture size is the same as baseTexture
  20339. * @member {boolean}
  20340. * @default false
  20341. * @readonly
  20342. */
  20343. this.isSimple = false;
  20344. }
  20345. Object.defineProperty(TextureMatrix.prototype, "texture", {
  20346. /**
  20347. * texture property
  20348. * @member {PIXI.Texture}
  20349. */
  20350. get: function () {
  20351. return this._texture;
  20352. },
  20353. set: function (value) {
  20354. this._texture = value;
  20355. this._textureID = -1;
  20356. },
  20357. enumerable: false,
  20358. configurable: true
  20359. });
  20360. /**
  20361. * Multiplies uvs array to transform
  20362. * @param {Float32Array} uvs - mesh uvs
  20363. * @param {Float32Array} [out=uvs] - output
  20364. * @returns {Float32Array} output
  20365. */
  20366. TextureMatrix.prototype.multiplyUvs = function (uvs, out) {
  20367. if (out === undefined) {
  20368. out = uvs;
  20369. }
  20370. var mat = this.mapCoord;
  20371. for (var i = 0; i < uvs.length; i += 2) {
  20372. var x = uvs[i];
  20373. var y = uvs[i + 1];
  20374. out[i] = (x * mat.a) + (y * mat.c) + mat.tx;
  20375. out[i + 1] = (x * mat.b) + (y * mat.d) + mat.ty;
  20376. }
  20377. return out;
  20378. };
  20379. /**
  20380. * updates matrices if texture was changed
  20381. * @param {boolean} [forceUpdate=false] - if true, matrices will be updated any case
  20382. * @returns {boolean} whether or not it was updated
  20383. */
  20384. TextureMatrix.prototype.update = function (forceUpdate) {
  20385. var tex = this._texture;
  20386. if (!tex || !tex.valid) {
  20387. return false;
  20388. }
  20389. if (!forceUpdate
  20390. && this._textureID === tex._updateID) {
  20391. return false;
  20392. }
  20393. this._textureID = tex._updateID;
  20394. this._updateID++;
  20395. var uvs = tex._uvs;
  20396. this.mapCoord.set(uvs.x1 - uvs.x0, uvs.y1 - uvs.y0, uvs.x3 - uvs.x0, uvs.y3 - uvs.y0, uvs.x0, uvs.y0);
  20397. var orig = tex.orig;
  20398. var trim = tex.trim;
  20399. if (trim) {
  20400. tempMat.set(orig.width / trim.width, 0, 0, orig.height / trim.height, -trim.x / trim.width, -trim.y / trim.height);
  20401. this.mapCoord.append(tempMat);
  20402. }
  20403. var texBase = tex.baseTexture;
  20404. var frame = this.uClampFrame;
  20405. var margin = this.clampMargin / texBase.resolution;
  20406. var offset = this.clampOffset;
  20407. frame[0] = (tex._frame.x + margin + offset) / texBase.width;
  20408. frame[1] = (tex._frame.y + margin + offset) / texBase.height;
  20409. frame[2] = (tex._frame.x + tex._frame.width - margin + offset) / texBase.width;
  20410. frame[3] = (tex._frame.y + tex._frame.height - margin + offset) / texBase.height;
  20411. this.uClampOffset[0] = offset / texBase.realWidth;
  20412. this.uClampOffset[1] = offset / texBase.realHeight;
  20413. this.isSimple = tex._frame.width === texBase.width
  20414. && tex._frame.height === texBase.height
  20415. && tex.rotate === 0;
  20416. return true;
  20417. };
  20418. return TextureMatrix;
  20419. }());
  20420. /**
  20421. * This handles a Sprite acting as a mask, as opposed to a Graphic.
  20422. *
  20423. * WebGL only.
  20424. *
  20425. * @class
  20426. * @extends PIXI.Filter
  20427. * @memberof PIXI
  20428. */
  20429. var SpriteMaskFilter = /** @class */ (function (_super) {
  20430. __extends$2(SpriteMaskFilter, _super);
  20431. /**
  20432. * @param {PIXI.Sprite} sprite - the target sprite
  20433. */
  20434. function SpriteMaskFilter(sprite) {
  20435. var _this = this;
  20436. var maskMatrix = new Matrix();
  20437. _this = _super.call(this, vertex, fragment) || this;
  20438. sprite.renderable = false;
  20439. /**
  20440. * Sprite mask
  20441. * @member {PIXI.Sprite}
  20442. */
  20443. _this.maskSprite = sprite;
  20444. /**
  20445. * Mask matrix
  20446. * @member {PIXI.Matrix}
  20447. */
  20448. _this.maskMatrix = maskMatrix;
  20449. return _this;
  20450. }
  20451. /**
  20452. * Applies the filter
  20453. *
  20454. * @param {PIXI.FilterSystem} filterManager - The renderer to retrieve the filter from
  20455. * @param {PIXI.RenderTexture} input - The input render target.
  20456. * @param {PIXI.RenderTexture} output - The target to output to.
  20457. * @param {PIXI.CLEAR_MODES} clearMode - Should the output be cleared before rendering to it.
  20458. */
  20459. SpriteMaskFilter.prototype.apply = function (filterManager, input, output, clearMode) {
  20460. var maskSprite = this.maskSprite;
  20461. var tex = maskSprite._texture;
  20462. if (!tex.valid) {
  20463. return;
  20464. }
  20465. if (!tex.uvMatrix) {
  20466. // margin = 0.0, let it bleed a bit, shader code becomes easier
  20467. // assuming that atlas textures were made with 1-pixel padding
  20468. tex.uvMatrix = new TextureMatrix(tex, 0.0);
  20469. }
  20470. tex.uvMatrix.update();
  20471. this.uniforms.npmAlpha = tex.baseTexture.alphaMode ? 0.0 : 1.0;
  20472. this.uniforms.mask = tex;
  20473. // get _normalized sprite texture coords_ and convert them to _normalized atlas texture coords_ with `prepend`
  20474. this.uniforms.otherMatrix = filterManager.calculateSpriteMatrix(this.maskMatrix, maskSprite)
  20475. .prepend(tex.uvMatrix.mapCoord);
  20476. this.uniforms.alpha = maskSprite.worldAlpha;
  20477. this.uniforms.maskClamp = tex.uvMatrix.uClampFrame;
  20478. filterManager.applyFilter(this, input, output, clearMode);
  20479. };
  20480. return SpriteMaskFilter;
  20481. }(Filter));
  20482. /**
  20483. * System plugin to the renderer to manage masks.
  20484. *
  20485. * There are three built-in types of masking:
  20486. * * **Scissor Masking**: Scissor masking discards pixels that are outside of a rectangle called the scissor box. It is
  20487. * the most performant as the scissor test is inexpensive. However, it can only be used when the mask is rectangular.
  20488. * * **Stencil Masking**: Stencil masking discards pixels that don't overlap with the pixels rendered into the stencil
  20489. * buffer. It is the next fastest option as it does not require rendering into a separate framebuffer. However, it does
  20490. * cause the mask to be rendered **twice** for each masking operation; hence, minimize the rendering cost of your masks.
  20491. * * **Sprite Mask Filtering**: Sprite mask filtering discards pixels based on the red channel of the sprite-mask's
  20492. * texture. (Generally, the masking texture is grayscale). Using advanced techniques, you might be able to embed this
  20493. * type of masking in a custom shader - and hence, bypassing the masking system fully for performance wins.
  20494. *
  20495. * The best type of masking is auto-detected when you `push` one. To use scissor masking, you must pass in a `Graphics`
  20496. * object with just a rectangle drawn.
  20497. *
  20498. * ## Mask Stacks
  20499. *
  20500. * In the scene graph, masks can be applied recursively, i.e. a mask can be applied during a masking operation. The mask
  20501. * stack stores the currently applied masks in order. Each {@link PIXI.BaseRenderTexture} holds its own mask stack, i.e.
  20502. * when you switch render-textures, the old masks only applied when you switch back to rendering to the old render-target.
  20503. *
  20504. * @class
  20505. * @extends PIXI.System
  20506. * @memberof PIXI
  20507. */
  20508. var MaskSystem = /** @class */ (function () {
  20509. /**
  20510. * @param {PIXI.Renderer} renderer - The renderer this System works for.
  20511. */
  20512. function MaskSystem(renderer) {
  20513. this.renderer = renderer;
  20514. /**
  20515. * Enable scissor masking.
  20516. *
  20517. * @member {boolean}
  20518. * @readonly
  20519. */
  20520. this.enableScissor = true;
  20521. /**
  20522. * Pool of used sprite mask filters
  20523. * @member {PIXI.SpriteMaskFilter[]}
  20524. * @readonly
  20525. */
  20526. this.alphaMaskPool = [];
  20527. /**
  20528. * Pool of mask data
  20529. * @member {PIXI.MaskData[]}
  20530. * @readonly
  20531. */
  20532. this.maskDataPool = [];
  20533. this.maskStack = [];
  20534. /**
  20535. * Current index of alpha mask pool
  20536. * @member {number}
  20537. * @default 0
  20538. * @readonly
  20539. */
  20540. this.alphaMaskIndex = 0;
  20541. }
  20542. /**
  20543. * Changes the mask stack that is used by this System.
  20544. *
  20545. * @param {PIXI.MaskData[]} maskStack - The mask stack
  20546. */
  20547. MaskSystem.prototype.setMaskStack = function (maskStack) {
  20548. this.maskStack = maskStack;
  20549. this.renderer.scissor.setMaskStack(maskStack);
  20550. this.renderer.stencil.setMaskStack(maskStack);
  20551. };
  20552. /**
  20553. * Enables the mask and appends it to the current mask stack.
  20554. *
  20555. * NOTE: The batch renderer should be flushed beforehand to prevent pending renders from being masked.
  20556. *
  20557. * @param {PIXI.DisplayObject} target - Display Object to push the mask to
  20558. * @param {PIXI.MaskData|PIXI.Sprite|PIXI.Graphics|PIXI.DisplayObject} maskData - The masking data.
  20559. */
  20560. MaskSystem.prototype.push = function (target, maskDataOrTarget) {
  20561. var maskData = maskDataOrTarget;
  20562. if (!maskData.isMaskData) {
  20563. var d = this.maskDataPool.pop() || new MaskData();
  20564. d.pooled = true;
  20565. d.maskObject = maskDataOrTarget;
  20566. maskData = d;
  20567. }
  20568. if (maskData.autoDetect) {
  20569. this.detect(maskData);
  20570. }
  20571. maskData.copyCountersOrReset(this.maskStack[this.maskStack.length - 1]);
  20572. maskData._target = target;
  20573. switch (maskData.type) {
  20574. case exports.MASK_TYPES.SCISSOR:
  20575. this.maskStack.push(maskData);
  20576. this.renderer.scissor.push(maskData);
  20577. break;
  20578. case exports.MASK_TYPES.STENCIL:
  20579. this.maskStack.push(maskData);
  20580. this.renderer.stencil.push(maskData);
  20581. break;
  20582. case exports.MASK_TYPES.SPRITE:
  20583. maskData.copyCountersOrReset(null);
  20584. this.pushSpriteMask(maskData);
  20585. this.maskStack.push(maskData);
  20586. break;
  20587. }
  20588. };
  20589. /**
  20590. * Removes the last mask from the mask stack and doesn't return it.
  20591. *
  20592. * NOTE: The batch renderer should be flushed beforehand to render the masked contents before the mask is removed.
  20593. *
  20594. * @param {PIXI.DisplayObject} target - Display Object to pop the mask from
  20595. */
  20596. MaskSystem.prototype.pop = function (target) {
  20597. var maskData = this.maskStack.pop();
  20598. if (!maskData || maskData._target !== target) {
  20599. // TODO: add an assert when we have it
  20600. return;
  20601. }
  20602. switch (maskData.type) {
  20603. case exports.MASK_TYPES.SCISSOR:
  20604. this.renderer.scissor.pop();
  20605. break;
  20606. case exports.MASK_TYPES.STENCIL:
  20607. this.renderer.stencil.pop(maskData.maskObject);
  20608. break;
  20609. case exports.MASK_TYPES.SPRITE:
  20610. this.popSpriteMask();
  20611. break;
  20612. }
  20613. maskData.reset();
  20614. if (maskData.pooled) {
  20615. this.maskDataPool.push(maskData);
  20616. }
  20617. };
  20618. /**
  20619. * Sets type of MaskData based on its maskObject
  20620. * @param {PIXI.MaskData} maskData
  20621. */
  20622. MaskSystem.prototype.detect = function (maskData) {
  20623. var maskObject = maskData.maskObject;
  20624. if (maskObject.isSprite) {
  20625. maskData.type = exports.MASK_TYPES.SPRITE;
  20626. return;
  20627. }
  20628. maskData.type = exports.MASK_TYPES.STENCIL;
  20629. // detect scissor in graphics
  20630. if (this.enableScissor
  20631. && maskObject.isFastRect
  20632. && maskObject.isFastRect()) {
  20633. var matrix = maskObject.worldTransform;
  20634. // TODO: move the check to the matrix itself
  20635. // we are checking that its orthogonal and x rotation is 0 90 180 or 270
  20636. var rotX = Math.atan2(matrix.b, matrix.a);
  20637. var rotXY = Math.atan2(matrix.d, matrix.c);
  20638. // use the nearest degree to 0.01
  20639. rotX = Math.round(rotX * (180 / Math.PI) * 100);
  20640. rotXY = Math.round(rotXY * (180 / Math.PI) * 100) - rotX;
  20641. rotX = ((rotX % 9000) + 9000) % 9000;
  20642. rotXY = ((rotXY % 18000) + 18000) % 18000;
  20643. if (rotX === 0 && rotXY === 9000) {
  20644. maskData.type = exports.MASK_TYPES.SCISSOR;
  20645. }
  20646. }
  20647. };
  20648. /**
  20649. * Applies the Mask and adds it to the current filter stack.
  20650. *
  20651. * @param {PIXI.MaskData} maskData - Sprite to be used as the mask
  20652. */
  20653. MaskSystem.prototype.pushSpriteMask = function (maskData) {
  20654. var _a, _b;
  20655. var maskObject = maskData.maskObject;
  20656. var target = maskData._target;
  20657. var alphaMaskFilter = this.alphaMaskPool[this.alphaMaskIndex];
  20658. if (!alphaMaskFilter) {
  20659. alphaMaskFilter = this.alphaMaskPool[this.alphaMaskIndex] = [new SpriteMaskFilter(maskObject)];
  20660. }
  20661. var renderer = this.renderer;
  20662. var renderTextureSystem = renderer.renderTexture;
  20663. var resolution;
  20664. var multisample;
  20665. if (renderTextureSystem.current) {
  20666. var renderTexture = renderTextureSystem.current;
  20667. resolution = maskData.resolution || renderTexture.resolution;
  20668. multisample = (_a = maskData.multisample) !== null && _a !== void 0 ? _a : renderTexture.multisample;
  20669. }
  20670. else {
  20671. resolution = maskData.resolution || renderer.resolution;
  20672. multisample = (_b = maskData.multisample) !== null && _b !== void 0 ? _b : renderer.multisample;
  20673. }
  20674. alphaMaskFilter[0].resolution = resolution;
  20675. alphaMaskFilter[0].multisample = multisample;
  20676. alphaMaskFilter[0].maskSprite = maskObject;
  20677. var stashFilterArea = target.filterArea;
  20678. target.filterArea = maskObject.getBounds(true);
  20679. renderer.filter.push(target, alphaMaskFilter);
  20680. target.filterArea = stashFilterArea;
  20681. this.alphaMaskIndex++;
  20682. };
  20683. /**
  20684. * Removes the last filter from the filter stack and doesn't return it.
  20685. */
  20686. MaskSystem.prototype.popSpriteMask = function () {
  20687. this.renderer.filter.pop();
  20688. this.alphaMaskIndex--;
  20689. };
  20690. /**
  20691. * @ignore
  20692. */
  20693. MaskSystem.prototype.destroy = function () {
  20694. this.renderer = null;
  20695. };
  20696. return MaskSystem;
  20697. }());
  20698. /**
  20699. * System plugin to the renderer to manage specific types of masking operations.
  20700. *
  20701. * @class
  20702. * @extends PIXI.System
  20703. * @memberof PIXI
  20704. */
  20705. var AbstractMaskSystem = /** @class */ (function () {
  20706. /**
  20707. * @param {PIXI.Renderer} renderer - The renderer this System works for.
  20708. */
  20709. function AbstractMaskSystem(renderer) {
  20710. this.renderer = renderer;
  20711. /**
  20712. * The mask stack
  20713. * @member {PIXI.MaskData[]}
  20714. */
  20715. this.maskStack = [];
  20716. /**
  20717. * Constant for gl.enable
  20718. * @member {number}
  20719. * @private
  20720. */
  20721. this.glConst = 0;
  20722. }
  20723. /**
  20724. * gets count of masks of certain type
  20725. * @returns {number}
  20726. */
  20727. AbstractMaskSystem.prototype.getStackLength = function () {
  20728. return this.maskStack.length;
  20729. };
  20730. /**
  20731. * Changes the mask stack that is used by this System.
  20732. *
  20733. * @param {PIXI.MaskData[]} maskStack - The mask stack
  20734. */
  20735. AbstractMaskSystem.prototype.setMaskStack = function (maskStack) {
  20736. var gl = this.renderer.gl;
  20737. var curStackLen = this.getStackLength();
  20738. this.maskStack = maskStack;
  20739. var newStackLen = this.getStackLength();
  20740. if (newStackLen !== curStackLen) {
  20741. if (newStackLen === 0) {
  20742. gl.disable(this.glConst);
  20743. }
  20744. else {
  20745. gl.enable(this.glConst);
  20746. this._useCurrent();
  20747. }
  20748. }
  20749. };
  20750. /**
  20751. * Setup renderer to use the current mask data.
  20752. * @private
  20753. */
  20754. AbstractMaskSystem.prototype._useCurrent = function () {
  20755. // OVERWRITE;
  20756. };
  20757. /**
  20758. * Destroys the mask stack.
  20759. *
  20760. */
  20761. AbstractMaskSystem.prototype.destroy = function () {
  20762. this.renderer = null;
  20763. this.maskStack = null;
  20764. };
  20765. return AbstractMaskSystem;
  20766. }());
  20767. /**
  20768. * System plugin to the renderer to manage scissor masking.
  20769. *
  20770. * Scissor masking discards pixels outside of a rectangle called the scissor box. The scissor box is in the framebuffer
  20771. * viewport's space; however, the mask's rectangle is projected from world-space to viewport space automatically
  20772. * by this system.
  20773. *
  20774. * @class
  20775. * @extends PIXI.System
  20776. * @memberof PIXI
  20777. */
  20778. var ScissorSystem = /** @class */ (function (_super) {
  20779. __extends$2(ScissorSystem, _super);
  20780. /**
  20781. * @param {PIXI.Renderer} renderer - The renderer this System works for.
  20782. */
  20783. function ScissorSystem(renderer) {
  20784. var _this = _super.call(this, renderer) || this;
  20785. _this.glConst = WebGLRenderingContext.SCISSOR_TEST;
  20786. return _this;
  20787. }
  20788. ScissorSystem.prototype.getStackLength = function () {
  20789. var maskData = this.maskStack[this.maskStack.length - 1];
  20790. if (maskData) {
  20791. return maskData._scissorCounter;
  20792. }
  20793. return 0;
  20794. };
  20795. /**
  20796. * Applies the Mask and adds it to the current stencil stack.
  20797. *
  20798. * @author alvin
  20799. * @param {PIXI.MaskData} maskData - The mask data
  20800. */
  20801. ScissorSystem.prototype.push = function (maskData) {
  20802. var maskObject = maskData.maskObject;
  20803. maskObject.renderable = true;
  20804. var prevData = maskData._scissorRect;
  20805. var bounds = maskObject.getBounds(true);
  20806. var gl = this.renderer.gl;
  20807. maskObject.renderable = false;
  20808. if (prevData) {
  20809. bounds.fit(prevData);
  20810. }
  20811. else {
  20812. gl.enable(gl.SCISSOR_TEST);
  20813. }
  20814. maskData._scissorCounter++;
  20815. maskData._scissorRect = bounds;
  20816. this._useCurrent();
  20817. };
  20818. /**
  20819. * This should be called after a mask is popped off the mask stack. It will rebind the scissor box to be latest with the
  20820. * last mask in the stack.
  20821. *
  20822. * This can also be called when you directly modify the scissor box and want to restore PixiJS state.
  20823. */
  20824. ScissorSystem.prototype.pop = function () {
  20825. var gl = this.renderer.gl;
  20826. if (this.getStackLength() > 0) {
  20827. this._useCurrent();
  20828. }
  20829. else {
  20830. gl.disable(gl.SCISSOR_TEST);
  20831. }
  20832. };
  20833. /**
  20834. * Setup renderer to use the current scissor data.
  20835. * @private
  20836. */
  20837. ScissorSystem.prototype._useCurrent = function () {
  20838. var rect = this.maskStack[this.maskStack.length - 1]._scissorRect;
  20839. var rt = this.renderer.renderTexture.current;
  20840. var _a = this.renderer.projection, transform = _a.transform, sourceFrame = _a.sourceFrame, destinationFrame = _a.destinationFrame;
  20841. var resolution = rt ? rt.resolution : this.renderer.resolution;
  20842. var sx = destinationFrame.width / sourceFrame.width;
  20843. var sy = destinationFrame.height / sourceFrame.height;
  20844. var x = (((rect.x - sourceFrame.x) * sx) + destinationFrame.x) * resolution;
  20845. var y = (((rect.y - sourceFrame.y) * sy) + destinationFrame.y) * resolution;
  20846. var width = rect.width * sx * resolution;
  20847. var height = rect.height * sy * resolution;
  20848. if (transform) {
  20849. x += transform.tx * resolution;
  20850. y += transform.ty * resolution;
  20851. }
  20852. if (!rt) {
  20853. // flipY. In future we'll have it over renderTextures as an option
  20854. y = this.renderer.height - height - y;
  20855. }
  20856. x = Math.round(x);
  20857. y = Math.round(y);
  20858. width = Math.round(width);
  20859. height = Math.round(height);
  20860. this.renderer.gl.scissor(x, y, width, height);
  20861. };
  20862. return ScissorSystem;
  20863. }(AbstractMaskSystem));
  20864. /**
  20865. * System plugin to the renderer to manage stencils (used for masks).
  20866. *
  20867. * @class
  20868. * @extends PIXI.System
  20869. * @memberof PIXI
  20870. */
  20871. var StencilSystem = /** @class */ (function (_super) {
  20872. __extends$2(StencilSystem, _super);
  20873. /**
  20874. * @param {PIXI.Renderer} renderer - The renderer this System works for.
  20875. */
  20876. function StencilSystem(renderer) {
  20877. var _this = _super.call(this, renderer) || this;
  20878. _this.glConst = WebGLRenderingContext.STENCIL_TEST;
  20879. return _this;
  20880. }
  20881. StencilSystem.prototype.getStackLength = function () {
  20882. var maskData = this.maskStack[this.maskStack.length - 1];
  20883. if (maskData) {
  20884. return maskData._stencilCounter;
  20885. }
  20886. return 0;
  20887. };
  20888. /**
  20889. * Applies the Mask and adds it to the current stencil stack.
  20890. *
  20891. * @param {PIXI.MaskData} maskData - The mask data
  20892. */
  20893. StencilSystem.prototype.push = function (maskData) {
  20894. var maskObject = maskData.maskObject;
  20895. var gl = this.renderer.gl;
  20896. var prevMaskCount = maskData._stencilCounter;
  20897. if (prevMaskCount === 0) {
  20898. // force use stencil texture in current framebuffer
  20899. this.renderer.framebuffer.forceStencil();
  20900. gl.enable(gl.STENCIL_TEST);
  20901. }
  20902. maskData._stencilCounter++;
  20903. // Increment the reference stencil value where the new mask overlaps with the old ones.
  20904. gl.colorMask(false, false, false, false);
  20905. gl.stencilFunc(gl.EQUAL, prevMaskCount, this._getBitwiseMask());
  20906. gl.stencilOp(gl.KEEP, gl.KEEP, gl.INCR);
  20907. maskObject.renderable = true;
  20908. maskObject.render(this.renderer);
  20909. this.renderer.batch.flush();
  20910. maskObject.renderable = false;
  20911. this._useCurrent();
  20912. };
  20913. /**
  20914. * Pops stencil mask. MaskData is already removed from stack
  20915. *
  20916. * @param {PIXI.DisplayObject} maskObject - object of popped mask data
  20917. */
  20918. StencilSystem.prototype.pop = function (maskObject) {
  20919. var gl = this.renderer.gl;
  20920. if (this.getStackLength() === 0) {
  20921. // the stack is empty!
  20922. gl.disable(gl.STENCIL_TEST);
  20923. gl.clear(gl.STENCIL_BUFFER_BIT);
  20924. gl.clearStencil(0);
  20925. }
  20926. else {
  20927. // Decrement the reference stencil value where the popped mask overlaps with the other ones
  20928. gl.colorMask(false, false, false, false);
  20929. gl.stencilOp(gl.KEEP, gl.KEEP, gl.DECR);
  20930. maskObject.renderable = true;
  20931. maskObject.render(this.renderer);
  20932. this.renderer.batch.flush();
  20933. maskObject.renderable = false;
  20934. this._useCurrent();
  20935. }
  20936. };
  20937. /**
  20938. * Setup renderer to use the current stencil data.
  20939. * @private
  20940. */
  20941. StencilSystem.prototype._useCurrent = function () {
  20942. var gl = this.renderer.gl;
  20943. gl.colorMask(true, true, true, true);
  20944. gl.stencilFunc(gl.EQUAL, this.getStackLength(), this._getBitwiseMask());
  20945. gl.stencilOp(gl.KEEP, gl.KEEP, gl.KEEP);
  20946. };
  20947. /**
  20948. * Fill 1s equal to the number of acitve stencil masks.
  20949. * @private
  20950. * @return {number} The bitwise mask.
  20951. */
  20952. StencilSystem.prototype._getBitwiseMask = function () {
  20953. return (1 << this.getStackLength()) - 1;
  20954. };
  20955. return StencilSystem;
  20956. }(AbstractMaskSystem));
  20957. /**
  20958. * System plugin to the renderer to manage the projection matrix.
  20959. *
  20960. * The `projectionMatrix` is a global uniform provided to all shaders. It is used to transform points in world space to
  20961. * normalized device coordinates.
  20962. *
  20963. * @class
  20964. * @extends PIXI.System
  20965. * @memberof PIXI
  20966. */
  20967. var ProjectionSystem = /** @class */ (function () {
  20968. /**
  20969. * @param {PIXI.Renderer} renderer - The renderer this System works for.
  20970. */
  20971. function ProjectionSystem(renderer) {
  20972. this.renderer = renderer;
  20973. /**
  20974. * The destination frame used to calculate the current projection matrix.
  20975. *
  20976. * The destination frame is the rectangle in the render-target into which contents are rendered. If rendering
  20977. * to the screen, the origin is on the top-left. If rendering to a framebuffer, the origin is on the
  20978. * bottom-left. This "flipping" phenomenon is because of WebGL convention for (shader) texture coordinates, where
  20979. * the bottom-left corner is (0,0). It allows display-objects to map their (0,0) position in local-space (top-left)
  20980. * to (0,0) in texture space (bottom-left). In other words, a sprite's top-left corner actually renders the
  20981. * texture's bottom-left corner. You will also notice this when using a tool like SpectorJS to view your textures
  20982. * at runtime.
  20983. *
  20984. * The destination frame's dimensions (width,height) should be equal to the source frame. This is because,
  20985. * otherwise, the contents will be scaled to fill the destination frame. Similarly, the destination frame's (x,y)
  20986. * coordinates are (0,0) unless you know what you're doing.
  20987. *
  20988. *
  20989. * @member {PIXI.Rectangle}
  20990. * @readonly
  20991. */
  20992. this.destinationFrame = null;
  20993. /**
  20994. * The source frame used to calculate the current projection matrix.
  20995. *
  20996. * The source frame is the rectangle in world space containing the contents to be rendered.
  20997. *
  20998. * @member {PIXI.Rectangle}
  20999. * @readonly
  21000. */
  21001. this.sourceFrame = null;
  21002. /**
  21003. * Default destination frame
  21004. *
  21005. * This is not used internally. It is not advised to use this feature specifically unless you know what
  21006. * you're doing. The `update` method will default to this frame if you do not pass the destination frame.
  21007. *
  21008. * @member {PIXI.Rectangle}
  21009. * @readonly
  21010. */
  21011. this.defaultFrame = null;
  21012. /**
  21013. * Projection matrix
  21014. *
  21015. * This matrix can be used to transform points from world space to normalized device coordinates, and is calculated
  21016. * from the sourceFrame → destinationFrame mapping provided.
  21017. *
  21018. * The renderer's `globalUniforms` keeps a reference to this, and so it is available for all shaders to use as a
  21019. * uniform.
  21020. *
  21021. * @member {PIXI.Matrix}
  21022. * @readonly
  21023. */
  21024. this.projectionMatrix = new Matrix();
  21025. /**
  21026. * A transform to be appended to the projection matrix.
  21027. *
  21028. * This can be used to transform points in world-space one last time before they are outputted by the shader. You can
  21029. * use to rotate the whole scene, for example. Remember to clear it once you've rendered everything.
  21030. *
  21031. * @member {PIXI.Matrix}
  21032. */
  21033. this.transform = null;
  21034. }
  21035. /**
  21036. * Updates the projection-matrix based on the sourceFrame → destinationFrame mapping provided.
  21037. *
  21038. * NOTE: It is expected you call `renderer.framebuffer.setViewport(destinationFrame)` after this. This is because
  21039. * the framebuffer viewport converts shader vertex output in normalized device coordinates to window coordinates.
  21040. *
  21041. * NOTE-2: {@link RenderTextureSystem#bind} updates the projection-matrix when you bind a render-texture. It is expected
  21042. * that you dirty the current bindings when calling this manually.
  21043. *
  21044. * @param {PIXI.Rectangle} destinationFrame - The rectangle in the render-target to render the contents
  21045. * into. If rendering to the canvas, the origin is on the top-left; if rendering to a render-texture, the origin
  21046. * is on the bottom-left.
  21047. * @param {PIXI.Rectangle} sourceFrame - The rectangle in world space that contains the contents being rendered.
  21048. * @param {Number} resolution - The resolution of the render-target, which is the ratio of world-space (or CSS) pixels
  21049. * to physical pixels.
  21050. * @param {boolean} root - Whether the render-target is the screen. This is required because rendering to textures
  21051. * is y-flipped (i.e. upside down relative to the screen).
  21052. */
  21053. ProjectionSystem.prototype.update = function (destinationFrame, sourceFrame, resolution, root) {
  21054. this.destinationFrame = destinationFrame || this.destinationFrame || this.defaultFrame;
  21055. this.sourceFrame = sourceFrame || this.sourceFrame || destinationFrame;
  21056. // Calculate object-space to clip-space projection
  21057. this.calculateProjection(this.destinationFrame, this.sourceFrame, resolution, root);
  21058. if (this.transform) {
  21059. this.projectionMatrix.append(this.transform);
  21060. }
  21061. var renderer = this.renderer;
  21062. renderer.globalUniforms.uniforms.projectionMatrix = this.projectionMatrix;
  21063. renderer.globalUniforms.update();
  21064. // this will work for now
  21065. // but would be sweet to stick and even on the global uniforms..
  21066. if (renderer.shader.shader) {
  21067. renderer.shader.syncUniformGroup(renderer.shader.shader.uniforms.globals);
  21068. }
  21069. };
  21070. /**
  21071. * Calculates the `projectionMatrix` to map points inside `sourceFrame` to inside `destinationFrame`.
  21072. *
  21073. * @param {PIXI.Rectangle} destinationFrame - The destination frame in the render-target.
  21074. * @param {PIXI.Rectangle} sourceFrame - The source frame in world space.
  21075. * @param {Number} resolution - The render-target's resolution, i.e. ratio of CSS to physical pixels.
  21076. * @param {boolean} root - Whether rendering into the screen. Otherwise, if rendering to a framebuffer, the projection
  21077. * is y-flipped.
  21078. */
  21079. ProjectionSystem.prototype.calculateProjection = function (_destinationFrame, sourceFrame, _resolution, root) {
  21080. var pm = this.projectionMatrix;
  21081. var sign = !root ? 1 : -1;
  21082. pm.identity();
  21083. pm.a = (1 / sourceFrame.width * 2);
  21084. pm.d = sign * (1 / sourceFrame.height * 2);
  21085. pm.tx = -1 - (sourceFrame.x * pm.a);
  21086. pm.ty = -sign - (sourceFrame.y * pm.d);
  21087. };
  21088. /**
  21089. * Sets the transform of the active render target to the given matrix
  21090. *
  21091. * @param {PIXI.Matrix} matrix - The transformation matrix
  21092. */
  21093. ProjectionSystem.prototype.setTransform = function (_matrix) {
  21094. // this._activeRenderTarget.transform = matrix;
  21095. };
  21096. /**
  21097. * @ignore
  21098. */
  21099. ProjectionSystem.prototype.destroy = function () {
  21100. this.renderer = null;
  21101. };
  21102. return ProjectionSystem;
  21103. }());
  21104. // Temporary rectangle for assigned sourceFrame or destinationFrame
  21105. var tempRect = new Rectangle();
  21106. // Temporary rectangle for renderTexture destinationFrame
  21107. var tempRect2 = new Rectangle();
  21108. /* eslint-disable max-len */
  21109. /**
  21110. * System plugin to the renderer to manage render textures.
  21111. *
  21112. * Should be added after FramebufferSystem
  21113. *
  21114. * ### Frames
  21115. *
  21116. * The `RenderTextureSystem` holds a sourceFrame → destinationFrame projection. The following table explains the different
  21117. * coordinate spaces used:
  21118. *
  21119. * | Frame | Description | Coordinate System |
  21120. * | ---------------------- | ---------------------------------------------------------------- | ------------------------------------------------------- |
  21121. * | sourceFrame | The rectangle inside of which display-objects are being rendered | **World Space**: The origin on the top-left |
  21122. * | destinationFrame | The rectangle in the render-target (canvas or texture) into which contents should be rendered | If rendering to the canvas, this is in screen space and the origin is on the top-left. If rendering to a render-texture, this is in its base-texture's space with the origin on the bottom-left. |
  21123. * | viewportFrame | The framebuffer viewport corresponding to the destination-frame | **Window Coordinates**: The origin is always on the bottom-left. |
  21124. *
  21125. * @class
  21126. * @extends PIXI.System
  21127. * @memberof PIXI
  21128. */
  21129. var RenderTextureSystem = /** @class */ (function () {
  21130. /**
  21131. * @param {PIXI.Renderer} renderer - The renderer this System works for.
  21132. */
  21133. function RenderTextureSystem(renderer) {
  21134. this.renderer = renderer;
  21135. /**
  21136. * The clear background color as rgba
  21137. * @member {number[]}
  21138. */
  21139. this.clearColor = renderer._backgroundColorRgba;
  21140. // TODO move this property somewhere else!
  21141. /**
  21142. * List of masks for the StencilSystem
  21143. * @member {PIXI.Graphics[]}
  21144. * @readonly
  21145. */
  21146. this.defaultMaskStack = [];
  21147. // empty render texture?
  21148. /**
  21149. * Render texture
  21150. * @member {PIXI.RenderTexture}
  21151. * @readonly
  21152. */
  21153. this.current = null;
  21154. /**
  21155. * The source frame for the render-target's projection mapping.
  21156. *
  21157. * See {@link PIXI.ProjectionSystem#sourceFrame} for more details.
  21158. *
  21159. * @member {PIXI.Rectangle}
  21160. * @readonly
  21161. */
  21162. this.sourceFrame = new Rectangle();
  21163. /**
  21164. * The destination frame for the render-target's projection mapping.
  21165. *
  21166. * See {@link PIXI.Projection#destinationFrame} for more details.
  21167. *
  21168. * @member {PIXI.Rectangle}
  21169. * @readonly
  21170. */
  21171. this.destinationFrame = new Rectangle();
  21172. /**
  21173. * The viewport frame for the render-target's viewport binding. This is equal to the destination-frame
  21174. * for render-textures, while it is y-flipped when rendering to the screen (i.e. its origin is always on
  21175. * the bottom-left).
  21176. *
  21177. * @member {PIXI.Rectangle}
  21178. * @readonly
  21179. */
  21180. this.viewportFrame = new Rectangle();
  21181. }
  21182. /**
  21183. * Bind the current render texture
  21184. *
  21185. * @param {PIXI.RenderTexture} [renderTexture] - RenderTexture to bind, by default its `null`, the screen
  21186. * @param {PIXI.Rectangle} [sourceFrame] - part of screen that is mapped to the renderTexture
  21187. * @param {PIXI.Rectangle} [destinationFrame] - part of renderTexture, by default it has the same size as sourceFrame
  21188. */
  21189. RenderTextureSystem.prototype.bind = function (renderTexture, sourceFrame, destinationFrame) {
  21190. if (renderTexture === void 0) { renderTexture = null; }
  21191. var renderer = this.renderer;
  21192. this.current = renderTexture;
  21193. var baseTexture;
  21194. var framebuffer;
  21195. var resolution;
  21196. if (renderTexture) {
  21197. baseTexture = renderTexture.baseTexture;
  21198. resolution = baseTexture.resolution;
  21199. if (!sourceFrame) {
  21200. tempRect.width = renderTexture.frame.width;
  21201. tempRect.height = renderTexture.frame.height;
  21202. sourceFrame = tempRect;
  21203. }
  21204. if (!destinationFrame) {
  21205. tempRect2.x = renderTexture.frame.x;
  21206. tempRect2.y = renderTexture.frame.y;
  21207. tempRect2.width = sourceFrame.width;
  21208. tempRect2.height = sourceFrame.height;
  21209. destinationFrame = tempRect2;
  21210. }
  21211. framebuffer = baseTexture.framebuffer;
  21212. }
  21213. else {
  21214. resolution = renderer.resolution;
  21215. if (!sourceFrame) {
  21216. tempRect.width = renderer.screen.width;
  21217. tempRect.height = renderer.screen.height;
  21218. sourceFrame = tempRect;
  21219. }
  21220. if (!destinationFrame) {
  21221. destinationFrame = tempRect;
  21222. destinationFrame.width = sourceFrame.width;
  21223. destinationFrame.height = sourceFrame.height;
  21224. }
  21225. }
  21226. var viewportFrame = this.viewportFrame;
  21227. viewportFrame.x = destinationFrame.x * resolution;
  21228. viewportFrame.y = destinationFrame.y * resolution;
  21229. viewportFrame.width = destinationFrame.width * resolution;
  21230. viewportFrame.height = destinationFrame.height * resolution;
  21231. if (!renderTexture) {
  21232. viewportFrame.y = renderer.view.height - (viewportFrame.y + viewportFrame.height);
  21233. }
  21234. viewportFrame.ceil();
  21235. this.renderer.framebuffer.bind(framebuffer, viewportFrame);
  21236. this.renderer.projection.update(destinationFrame, sourceFrame, resolution, !framebuffer);
  21237. if (renderTexture) {
  21238. this.renderer.mask.setMaskStack(baseTexture.maskStack);
  21239. }
  21240. else {
  21241. this.renderer.mask.setMaskStack(this.defaultMaskStack);
  21242. }
  21243. this.sourceFrame.copyFrom(sourceFrame);
  21244. this.destinationFrame.copyFrom(destinationFrame);
  21245. };
  21246. /**
  21247. * Erases the render texture and fills the drawing area with a colour
  21248. *
  21249. * @param {number[]} [clearColor] - The color as rgba, default to use the renderer backgroundColor
  21250. * @param {PIXI.BUFFER_BITS} [mask=BUFFER_BITS.COLOR | BUFFER_BITS.DEPTH] - Bitwise OR of masks
  21251. * that indicate the buffers to be cleared, by default COLOR and DEPTH buffers.
  21252. * @return {PIXI.Renderer} Returns itself.
  21253. */
  21254. RenderTextureSystem.prototype.clear = function (clearColor, mask) {
  21255. if (this.current) {
  21256. clearColor = clearColor || this.current.baseTexture.clearColor;
  21257. }
  21258. else {
  21259. clearColor = clearColor || this.clearColor;
  21260. }
  21261. var destinationFrame = this.destinationFrame;
  21262. var baseFrame = this.current ? this.current.baseTexture : this.renderer.screen;
  21263. var clearMask = destinationFrame.width !== baseFrame.width || destinationFrame.height !== baseFrame.height;
  21264. if (clearMask) {
  21265. var _a = this.viewportFrame, x = _a.x, y = _a.y, width = _a.width, height = _a.height;
  21266. x = Math.round(x);
  21267. y = Math.round(y);
  21268. width = Math.round(width);
  21269. height = Math.round(height);
  21270. // TODO: ScissorSystem should cache whether the scissor test is enabled or not.
  21271. this.renderer.gl.enable(this.renderer.gl.SCISSOR_TEST);
  21272. this.renderer.gl.scissor(x, y, width, height);
  21273. }
  21274. this.renderer.framebuffer.clear(clearColor[0], clearColor[1], clearColor[2], clearColor[3], mask);
  21275. if (clearMask) {
  21276. // Restore the scissor box
  21277. this.renderer.scissor.pop();
  21278. }
  21279. };
  21280. RenderTextureSystem.prototype.resize = function () {
  21281. // resize the root only!
  21282. this.bind(null);
  21283. };
  21284. /**
  21285. * Resets renderTexture state
  21286. */
  21287. RenderTextureSystem.prototype.reset = function () {
  21288. this.bind(null);
  21289. };
  21290. /**
  21291. * @ignore
  21292. */
  21293. RenderTextureSystem.prototype.destroy = function () {
  21294. this.renderer = null;
  21295. };
  21296. return RenderTextureSystem;
  21297. }());
  21298. function uboUpdate(_ud, _uv, _renderer, _syncData, buffer) {
  21299. _renderer.buffer.update(buffer);
  21300. }
  21301. // cv = CachedValue
  21302. // v = value
  21303. // ud = uniformData
  21304. // uv = uniformValue
  21305. // l = location
  21306. var UBO_TO_SINGLE_SETTERS = {
  21307. float: "\n data[offset] = v;\n ",
  21308. vec2: "\n data[offset] = v[0];\n data[offset+1] = v[1];\n ",
  21309. vec3: "\n data[offset] = v[0];\n data[offset+1] = v[1];\n data[offset+2] = v[2];\n\n ",
  21310. vec4: "\n data[offset] = v[0];\n data[offset+1] = v[1];\n data[offset+2] = v[2];\n data[offset+3] = v[3];\n ",
  21311. mat2: "\n data[offset] = v[0];\n data[offset+1] = v[1];\n\n data[offset+4] = v[2];\n data[offset+5] = v[3];\n ",
  21312. mat3: "\n data[offset] = v[0];\n data[offset+1] = v[1];\n data[offset+2] = v[2];\n\n data[offset + 4] = v[3];\n data[offset + 5] = v[4];\n data[offset + 6] = v[5];\n\n data[offset + 8] = v[6];\n data[offset + 9] = v[7];\n data[offset + 10] = v[8];\n ",
  21313. mat4: "\n for(var i = 0; i < 16; i++)\n {\n data[offset + i] = v[i];\n }\n "
  21314. };
  21315. var GLSL_TO_STD40_SIZE = {
  21316. float: 4,
  21317. vec2: 8,
  21318. vec3: 12,
  21319. vec4: 16,
  21320. int: 4,
  21321. ivec2: 8,
  21322. ivec3: 12,
  21323. ivec4: 16,
  21324. uint: 4,
  21325. uvec2: 8,
  21326. uvec3: 12,
  21327. uvec4: 16,
  21328. bool: 4,
  21329. bvec2: 8,
  21330. bvec3: 12,
  21331. bvec4: 16,
  21332. mat2: 16 * 2,
  21333. mat3: 16 * 3,
  21334. mat4: 16 * 4,
  21335. };
  21336. /**
  21337. * @ignore
  21338. *
  21339. * logic originally from here: https://github.com/sketchpunk/FunWithWebGL2/blob/master/lesson_022/Shaders.js
  21340. * rewrote it, but this was a great starting point to get a solid understanding of whats going on :)
  21341. *
  21342. * @param uniformData
  21343. */
  21344. function createUBOElements(uniformData) {
  21345. var uboElements = uniformData.map(function (data) {
  21346. return ({
  21347. data: data,
  21348. offset: 0,
  21349. dataLen: 0,
  21350. dirty: 0
  21351. });
  21352. });
  21353. var size = 0;
  21354. var chunkSize = 0;
  21355. var offset = 0;
  21356. for (var i = 0; i < uboElements.length; i++) {
  21357. var uboElement = uboElements[i];
  21358. size = GLSL_TO_STD40_SIZE[uboElement.data.type];
  21359. if (uboElement.data.size > 1) {
  21360. size = Math.max(size, 16) * uboElement.data.size;
  21361. }
  21362. uboElement.dataLen = size;
  21363. // add some size offset..
  21364. // must align to the nearest 16 bytes or internally nearest round size
  21365. if (chunkSize % size !== 0 && chunkSize < 16) {
  21366. // diff required to line up..
  21367. var lineUpValue = (chunkSize % size) % 16;
  21368. chunkSize += lineUpValue;
  21369. offset += lineUpValue;
  21370. }
  21371. if ((chunkSize + size) > 16) {
  21372. offset = Math.ceil(offset / 16) * 16;
  21373. uboElement.offset = offset;
  21374. offset += size;
  21375. chunkSize = size;
  21376. }
  21377. else {
  21378. uboElement.offset = offset;
  21379. chunkSize += size;
  21380. offset += size;
  21381. }
  21382. }
  21383. offset = Math.ceil(offset / 16) * 16;
  21384. return { uboElements: uboElements, size: offset };
  21385. }
  21386. function getUBOData(uniforms, uniformData) {
  21387. var usedUniformDatas = [];
  21388. // build..
  21389. for (var i in uniforms) {
  21390. if (uniformData[i]) {
  21391. usedUniformDatas.push(uniformData[i]);
  21392. }
  21393. }
  21394. // sort them out by index!
  21395. usedUniformDatas.sort(function (a, b) { return a.index - b.index; });
  21396. return usedUniformDatas;
  21397. }
  21398. function generateUniformBufferSync(group, uniformData) {
  21399. if (!group.autoManage) {
  21400. // if the group is nott automatically managed, we don't need to generate a special function for it...
  21401. return { size: 0, syncFunc: uboUpdate };
  21402. }
  21403. var usedUniformDatas = getUBOData(group.uniforms, uniformData);
  21404. var _a = createUBOElements(usedUniformDatas), uboElements = _a.uboElements, size = _a.size;
  21405. var funcFragments = ["\n var v = null;\n var v2 = null;\n var cv = null;\n var t = 0;\n var gl = renderer.gl\n var index = 0;\n var data = buffer.data;\n "];
  21406. for (var i = 0; i < uboElements.length; i++) {
  21407. var uboElement = uboElements[i];
  21408. var uniform = group.uniforms[uboElement.data.name];
  21409. var name = uboElement.data.name;
  21410. var parsed = false;
  21411. for (var j = 0; j < uniformParsers.length; j++) {
  21412. var uniformParser = uniformParsers[j];
  21413. if (uniformParser.codeUbo && uniformParser.test(uboElement.data, uniform)) {
  21414. funcFragments.push("offset = " + uboElement.offset / 4 + ";", uniformParsers[j].codeUbo(uboElement.data.name, uniform));
  21415. parsed = true;
  21416. break;
  21417. }
  21418. }
  21419. if (!parsed) {
  21420. if (uboElement.data.size > 1) {
  21421. var size_1 = mapSize(uboElement.data.type);
  21422. var rowSize = Math.max(GLSL_TO_STD40_SIZE[uboElement.data.type] / 16, 1);
  21423. var elementSize = size_1 / rowSize;
  21424. var remainder = (4 - (elementSize % 4)) % 4;
  21425. funcFragments.push("\n cv = ud." + name + ".value;\n v = uv." + name + ";\n offset = " + uboElement.offset / 4 + ";\n\n t = 0;\n\n for(var i=0; i < " + uboElement.data.size * rowSize + "; i++)\n {\n for(var j = 0; j < " + elementSize + "; j++)\n {\n data[offset++] = v[t++];\n }\n offset += " + remainder + ";\n }\n\n ");
  21426. }
  21427. else {
  21428. var template = UBO_TO_SINGLE_SETTERS[uboElement.data.type];
  21429. funcFragments.push("\n cv = ud." + name + ".value;\n v = uv." + name + ";\n offset = " + uboElement.offset / 4 + ";\n " + template + ";\n ");
  21430. }
  21431. }
  21432. }
  21433. funcFragments.push("\n renderer.buffer.update(buffer);\n ");
  21434. return {
  21435. size: size,
  21436. // eslint-disable-next-line no-new-func
  21437. syncFunc: new Function('ud', 'uv', 'renderer', 'syncData', 'buffer', funcFragments.join('\n'))
  21438. };
  21439. }
  21440. /**
  21441. * @private
  21442. */
  21443. var IGLUniformData = /** @class */ (function () {
  21444. function IGLUniformData() {
  21445. }
  21446. return IGLUniformData;
  21447. }());
  21448. /**
  21449. * Helper class to create a WebGL Program
  21450. *
  21451. * @class
  21452. * @memberof PIXI
  21453. */
  21454. var GLProgram = /** @class */ (function () {
  21455. /**
  21456. * Makes a new Pixi program
  21457. *
  21458. * @param {WebGLProgram} program - webgl program
  21459. * @param {Object} uniformData - uniforms
  21460. */
  21461. function GLProgram(program, uniformData) {
  21462. /**
  21463. * The shader program
  21464. *
  21465. * @member {WebGLProgram}
  21466. */
  21467. this.program = program;
  21468. /**
  21469. * holds the uniform data which contains uniform locations
  21470. * and current uniform values used for caching and preventing unneeded GPU commands
  21471. * @member {Object}
  21472. */
  21473. this.uniformData = uniformData;
  21474. /**
  21475. * uniformGroups holds the various upload functions for the shader. Each uniform group
  21476. * and program have a unique upload function generated.
  21477. * @member {Object}
  21478. */
  21479. this.uniformGroups = {};
  21480. this.uniformDirtyGroups = {};
  21481. this.uniformBufferBindings = {};
  21482. }
  21483. /**
  21484. * Destroys this program
  21485. */
  21486. GLProgram.prototype.destroy = function () {
  21487. this.uniformData = null;
  21488. this.uniformGroups = null;
  21489. this.uniformDirtyGroups = null;
  21490. this.uniformBufferBindings = null;
  21491. this.program = null;
  21492. };
  21493. return GLProgram;
  21494. }());
  21495. /**
  21496. * returns the attribute data from the program
  21497. * @private
  21498. *
  21499. * @param {WebGLProgram} [program] - the WebGL program
  21500. * @param {WebGLRenderingContext} [gl] - the WebGL context
  21501. *
  21502. * @returns {object} the attribute data for this program
  21503. */
  21504. function getAttributeData(program, gl) {
  21505. var attributes = {};
  21506. var totalAttributes = gl.getProgramParameter(program, gl.ACTIVE_ATTRIBUTES);
  21507. for (var i = 0; i < totalAttributes; i++) {
  21508. var attribData = gl.getActiveAttrib(program, i);
  21509. if (attribData.name.startsWith('gl_')) {
  21510. continue;
  21511. }
  21512. var type = mapType(gl, attribData.type);
  21513. var data = {
  21514. type: type,
  21515. name: attribData.name,
  21516. size: mapSize(type),
  21517. location: i,
  21518. };
  21519. attributes[attribData.name] = data;
  21520. }
  21521. return attributes;
  21522. }
  21523. /**
  21524. * returns the uniform data from the program
  21525. * @private
  21526. *
  21527. * @param program - the webgl program
  21528. * @param gl - the WebGL context
  21529. *
  21530. * @returns {object} the uniform data for this program
  21531. */
  21532. function getUniformData(program, gl) {
  21533. var uniforms = {};
  21534. var totalUniforms = gl.getProgramParameter(program, gl.ACTIVE_UNIFORMS);
  21535. for (var i = 0; i < totalUniforms; i++) {
  21536. var uniformData = gl.getActiveUniform(program, i);
  21537. var name = uniformData.name.replace(/\[.*?\]$/, '');
  21538. var isArray = !!(uniformData.name.match(/\[.*?\]$/));
  21539. var type = mapType(gl, uniformData.type);
  21540. uniforms[name] = {
  21541. name: name,
  21542. index: i,
  21543. type: type,
  21544. size: uniformData.size,
  21545. isArray: isArray,
  21546. value: defaultValue(type, uniformData.size),
  21547. };
  21548. }
  21549. return uniforms;
  21550. }
  21551. /**
  21552. * generates a WebGL Program object from a high level Pixi Program.
  21553. *
  21554. * @param gl - a rendering context on which to generate the program
  21555. * @param program - the high level Pixi Program.
  21556. */
  21557. function generateProgram(gl, program) {
  21558. var glVertShader = compileShader(gl, gl.VERTEX_SHADER, program.vertexSrc);
  21559. var glFragShader = compileShader(gl, gl.FRAGMENT_SHADER, program.fragmentSrc);
  21560. var webGLProgram = gl.createProgram();
  21561. gl.attachShader(webGLProgram, glVertShader);
  21562. gl.attachShader(webGLProgram, glFragShader);
  21563. gl.linkProgram(webGLProgram);
  21564. if (!gl.getProgramParameter(webGLProgram, gl.LINK_STATUS)) {
  21565. logProgramError(gl, webGLProgram, glVertShader, glFragShader);
  21566. }
  21567. program.attributeData = getAttributeData(webGLProgram, gl);
  21568. program.uniformData = getUniformData(webGLProgram, gl);
  21569. var keys = Object.keys(program.attributeData);
  21570. keys.sort(function (a, b) { return (a > b) ? 1 : -1; }); // eslint-disable-line no-confusing-arrow
  21571. for (var i = 0; i < keys.length; i++) {
  21572. program.attributeData[keys[i]].location = i;
  21573. gl.bindAttribLocation(webGLProgram, i, keys[i]);
  21574. }
  21575. gl.linkProgram(webGLProgram);
  21576. gl.deleteShader(glVertShader);
  21577. gl.deleteShader(glFragShader);
  21578. var uniformData = {};
  21579. for (var i in program.uniformData) {
  21580. var data = program.uniformData[i];
  21581. uniformData[i] = {
  21582. location: gl.getUniformLocation(webGLProgram, i),
  21583. value: defaultValue(data.type, data.size),
  21584. };
  21585. }
  21586. var glProgram = new GLProgram(webGLProgram, uniformData);
  21587. return glProgram;
  21588. }
  21589. var UID$4 = 0;
  21590. // default sync data so we don't create a new one each time!
  21591. var defaultSyncData = { textureCount: 0, uboCount: 0 };
  21592. /**
  21593. * System plugin to the renderer to manage shaders.
  21594. *
  21595. * @class
  21596. * @memberof PIXI
  21597. * @extends PIXI.System
  21598. */
  21599. var ShaderSystem = /** @class */ (function () {
  21600. /**
  21601. * @param {PIXI.Renderer} renderer - The renderer this System works for.
  21602. */
  21603. function ShaderSystem(renderer) {
  21604. this.destroyed = false;
  21605. this.renderer = renderer;
  21606. // Validation check that this environment support `new Function`
  21607. this.systemCheck();
  21608. /**
  21609. * The current WebGL rendering context
  21610. *
  21611. * @member {WebGLRenderingContext}
  21612. */
  21613. this.gl = null;
  21614. this.shader = null;
  21615. this.program = null;
  21616. /**
  21617. * Cache to holds the generated functions. Stored against UniformObjects unique signature
  21618. * @type {Object}
  21619. * @private
  21620. */
  21621. this.cache = {};
  21622. this._uboCache = {};
  21623. this.id = UID$4++;
  21624. }
  21625. /**
  21626. * Overrideable function by `@pixi/unsafe-eval` to silence
  21627. * throwing an error if platform doesn't support unsafe-evals.
  21628. *
  21629. * @private
  21630. */
  21631. ShaderSystem.prototype.systemCheck = function () {
  21632. if (!unsafeEvalSupported()) {
  21633. throw new Error('Current environment does not allow unsafe-eval, '
  21634. + 'please use @pixi/unsafe-eval module to enable support.');
  21635. }
  21636. };
  21637. ShaderSystem.prototype.contextChange = function (gl) {
  21638. this.gl = gl;
  21639. this.reset();
  21640. };
  21641. /**
  21642. * Changes the current shader to the one given in parameter
  21643. *
  21644. * @param {PIXI.Shader} shader - the new shader
  21645. * @param {boolean} [dontSync] - false if the shader should automatically sync its uniforms.
  21646. * @returns {PIXI.GLProgram} the glProgram that belongs to the shader.
  21647. */
  21648. ShaderSystem.prototype.bind = function (shader, dontSync) {
  21649. shader.uniforms.globals = this.renderer.globalUniforms;
  21650. var program = shader.program;
  21651. var glProgram = program.glPrograms[this.renderer.CONTEXT_UID] || this.generateProgram(shader);
  21652. this.shader = shader;
  21653. // TODO - some current Pixi plugins bypass this.. so it not safe to use yet..
  21654. if (this.program !== program) {
  21655. this.program = program;
  21656. this.gl.useProgram(glProgram.program);
  21657. }
  21658. if (!dontSync) {
  21659. defaultSyncData.textureCount = 0;
  21660. defaultSyncData.uboCount = 0;
  21661. this.syncUniformGroup(shader.uniformGroup, defaultSyncData);
  21662. }
  21663. return glProgram;
  21664. };
  21665. /**
  21666. * Uploads the uniforms values to the currently bound shader.
  21667. *
  21668. * @param {object} uniforms - the uniforms values that be applied to the current shader
  21669. */
  21670. ShaderSystem.prototype.setUniforms = function (uniforms) {
  21671. var shader = this.shader.program;
  21672. var glProgram = shader.glPrograms[this.renderer.CONTEXT_UID];
  21673. shader.syncUniforms(glProgram.uniformData, uniforms, this.renderer);
  21674. };
  21675. /* eslint-disable @typescript-eslint/explicit-module-boundary-types */
  21676. /**
  21677. *
  21678. * syncs uniforms on the group
  21679. * @param group - the uniform group to sync
  21680. * @param syncData - this is data that is passed to the sync function and any nested sync functions
  21681. */
  21682. ShaderSystem.prototype.syncUniformGroup = function (group, syncData) {
  21683. var glProgram = this.getGlProgram();
  21684. if (!group.static || group.dirtyId !== glProgram.uniformDirtyGroups[group.id]) {
  21685. glProgram.uniformDirtyGroups[group.id] = group.dirtyId;
  21686. this.syncUniforms(group, glProgram, syncData);
  21687. }
  21688. };
  21689. /**
  21690. * Overrideable by the @pixi/unsafe-eval package to use static
  21691. * syncUniforms instead.
  21692. *
  21693. * @private
  21694. */
  21695. ShaderSystem.prototype.syncUniforms = function (group, glProgram, syncData) {
  21696. var syncFunc = group.syncUniforms[this.shader.program.id] || this.createSyncGroups(group);
  21697. syncFunc(glProgram.uniformData, group.uniforms, this.renderer, syncData);
  21698. };
  21699. ShaderSystem.prototype.createSyncGroups = function (group) {
  21700. var id = this.getSignature(group, this.shader.program.uniformData, 'u');
  21701. if (!this.cache[id]) {
  21702. this.cache[id] = generateUniformsSync(group, this.shader.program.uniformData);
  21703. }
  21704. group.syncUniforms[this.shader.program.id] = this.cache[id];
  21705. return group.syncUniforms[this.shader.program.id];
  21706. };
  21707. /**
  21708. * Syncs uniform buffers
  21709. *
  21710. * @param group - the uniform buffer group to sync
  21711. * @param name - the name of the uniform buffer
  21712. */
  21713. ShaderSystem.prototype.syncUniformBufferGroup = function (group, name) {
  21714. var glProgram = this.getGlProgram();
  21715. if (!group.static || group.dirtyId !== 0 || !glProgram.uniformGroups[group.id]) {
  21716. group.dirtyId = 0;
  21717. var syncFunc = glProgram.uniformGroups[group.id]
  21718. || this.createSyncBufferGroup(group, glProgram, name);
  21719. // TODO wrap update in a cache??
  21720. group.buffer.update();
  21721. syncFunc(glProgram.uniformData, group.uniforms, this.renderer, defaultSyncData, group.buffer);
  21722. }
  21723. this.renderer.buffer.bindBufferBase(group.buffer, glProgram.uniformBufferBindings[name]);
  21724. };
  21725. /**
  21726. * Will create a function that uploads a uniform buffer using the STD140 standard.
  21727. * The upload function will then be cached for future calls
  21728. * If a group is manually managed, then a simple upload function is generated
  21729. *
  21730. * @param group - the uniform buffer group to sync
  21731. * @param glProgram - the gl program to attach the uniform bindings to
  21732. * @param name - the name of the uniform buffer (must exist on the shader)
  21733. */
  21734. ShaderSystem.prototype.createSyncBufferGroup = function (group, glProgram, name) {
  21735. var gl = this.renderer.gl;
  21736. this.renderer.buffer.bind(group.buffer);
  21737. // bind them...
  21738. var uniformBlockIndex = this.gl.getUniformBlockIndex(glProgram.program, name);
  21739. glProgram.uniformBufferBindings[name] = this.shader.uniformBindCount;
  21740. gl.uniformBlockBinding(glProgram.program, uniformBlockIndex, this.shader.uniformBindCount);
  21741. this.shader.uniformBindCount++;
  21742. var id = this.getSignature(group, this.shader.program.uniformData, 'ubo');
  21743. var uboData = this._uboCache[id];
  21744. if (!uboData) {
  21745. uboData = this._uboCache[id] = generateUniformBufferSync(group, this.shader.program.uniformData);
  21746. }
  21747. if (group.autoManage) {
  21748. var data = new Float32Array(uboData.size / 4);
  21749. group.buffer.update(data);
  21750. }
  21751. glProgram.uniformGroups[group.id] = uboData.syncFunc;
  21752. return glProgram.uniformGroups[group.id];
  21753. };
  21754. /**
  21755. * Takes a uniform group and data and generates a unique signature for them.
  21756. *
  21757. * @param {PIXI.UniformGroup} group - the uniform group to get signature of
  21758. * @param {Object} uniformData - uniform information generated by the shader
  21759. * @returns {String} Unique signature of the uniform group
  21760. * @private
  21761. */
  21762. ShaderSystem.prototype.getSignature = function (group, uniformData, preFix) {
  21763. var uniforms = group.uniforms;
  21764. var strings = [preFix + "-"];
  21765. for (var i in uniforms) {
  21766. strings.push(i);
  21767. if (uniformData[i]) {
  21768. strings.push(uniformData[i].type);
  21769. }
  21770. }
  21771. return strings.join('-');
  21772. };
  21773. /**
  21774. * Returns the underlying GLShade rof the currently bound shader.
  21775. * This can be handy for when you to have a little more control over the setting of your uniforms.
  21776. *
  21777. * @return {PIXI.GLProgram} the glProgram for the currently bound Shader for this context
  21778. */
  21779. ShaderSystem.prototype.getGlProgram = function () {
  21780. if (this.shader) {
  21781. return this.shader.program.glPrograms[this.renderer.CONTEXT_UID];
  21782. }
  21783. return null;
  21784. };
  21785. /**
  21786. * Generates a glProgram version of the Shader provided.
  21787. *
  21788. * @private
  21789. * @param {PIXI.Shader} shader - the shader that the glProgram will be based on.
  21790. * @return {PIXI.GLProgram} A shiny new glProgram!
  21791. */
  21792. ShaderSystem.prototype.generateProgram = function (shader) {
  21793. var gl = this.gl;
  21794. var program = shader.program;
  21795. var glProgram = generateProgram(gl, program);
  21796. program.glPrograms[this.renderer.CONTEXT_UID] = glProgram;
  21797. return glProgram;
  21798. };
  21799. /**
  21800. * Resets ShaderSystem state, does not affect WebGL state
  21801. */
  21802. ShaderSystem.prototype.reset = function () {
  21803. this.program = null;
  21804. this.shader = null;
  21805. };
  21806. /**
  21807. * Destroys this System and removes all its textures
  21808. */
  21809. ShaderSystem.prototype.destroy = function () {
  21810. this.renderer = null;
  21811. // TODO implement destroy method for ShaderSystem
  21812. this.destroyed = true;
  21813. };
  21814. return ShaderSystem;
  21815. }());
  21816. /**
  21817. * Maps gl blend combinations to WebGL.
  21818. *
  21819. * @memberof PIXI
  21820. * @function mapWebGLBlendModesToPixi
  21821. * @private
  21822. * @param {WebGLRenderingContext} gl - The rendering context.
  21823. * @param {number[][]} [array=[]] - The array to output into.
  21824. * @return {number[][]} Mapped modes.
  21825. */
  21826. function mapWebGLBlendModesToPixi(gl, array) {
  21827. if (array === void 0) { array = []; }
  21828. // TODO - premultiply alpha would be different.
  21829. // add a boolean for that!
  21830. array[exports.BLEND_MODES.NORMAL] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA];
  21831. array[exports.BLEND_MODES.ADD] = [gl.ONE, gl.ONE];
  21832. array[exports.BLEND_MODES.MULTIPLY] = [gl.DST_COLOR, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA];
  21833. array[exports.BLEND_MODES.SCREEN] = [gl.ONE, gl.ONE_MINUS_SRC_COLOR, gl.ONE, gl.ONE_MINUS_SRC_ALPHA];
  21834. array[exports.BLEND_MODES.OVERLAY] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA];
  21835. array[exports.BLEND_MODES.DARKEN] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA];
  21836. array[exports.BLEND_MODES.LIGHTEN] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA];
  21837. array[exports.BLEND_MODES.COLOR_DODGE] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA];
  21838. array[exports.BLEND_MODES.COLOR_BURN] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA];
  21839. array[exports.BLEND_MODES.HARD_LIGHT] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA];
  21840. array[exports.BLEND_MODES.SOFT_LIGHT] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA];
  21841. array[exports.BLEND_MODES.DIFFERENCE] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA];
  21842. array[exports.BLEND_MODES.EXCLUSION] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA];
  21843. array[exports.BLEND_MODES.HUE] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA];
  21844. array[exports.BLEND_MODES.SATURATION] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA];
  21845. array[exports.BLEND_MODES.COLOR] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA];
  21846. array[exports.BLEND_MODES.LUMINOSITY] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA];
  21847. array[exports.BLEND_MODES.NONE] = [0, 0];
  21848. // not-premultiplied blend modes
  21849. array[exports.BLEND_MODES.NORMAL_NPM] = [gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA];
  21850. array[exports.BLEND_MODES.ADD_NPM] = [gl.SRC_ALPHA, gl.ONE, gl.ONE, gl.ONE];
  21851. array[exports.BLEND_MODES.SCREEN_NPM] = [gl.SRC_ALPHA, gl.ONE_MINUS_SRC_COLOR, gl.ONE, gl.ONE_MINUS_SRC_ALPHA];
  21852. // composite operations
  21853. array[exports.BLEND_MODES.SRC_IN] = [gl.DST_ALPHA, gl.ZERO];
  21854. array[exports.BLEND_MODES.SRC_OUT] = [gl.ONE_MINUS_DST_ALPHA, gl.ZERO];
  21855. array[exports.BLEND_MODES.SRC_ATOP] = [gl.DST_ALPHA, gl.ONE_MINUS_SRC_ALPHA];
  21856. array[exports.BLEND_MODES.DST_OVER] = [gl.ONE_MINUS_DST_ALPHA, gl.ONE];
  21857. array[exports.BLEND_MODES.DST_IN] = [gl.ZERO, gl.SRC_ALPHA];
  21858. array[exports.BLEND_MODES.DST_OUT] = [gl.ZERO, gl.ONE_MINUS_SRC_ALPHA];
  21859. array[exports.BLEND_MODES.DST_ATOP] = [gl.ONE_MINUS_DST_ALPHA, gl.SRC_ALPHA];
  21860. array[exports.BLEND_MODES.XOR] = [gl.ONE_MINUS_DST_ALPHA, gl.ONE_MINUS_SRC_ALPHA];
  21861. // SUBTRACT from flash
  21862. array[exports.BLEND_MODES.SUBTRACT] = [gl.ONE, gl.ONE, gl.ONE, gl.ONE, gl.FUNC_REVERSE_SUBTRACT, gl.FUNC_ADD];
  21863. return array;
  21864. }
  21865. var BLEND$1 = 0;
  21866. var OFFSET$1 = 1;
  21867. var CULLING$1 = 2;
  21868. var DEPTH_TEST$1 = 3;
  21869. var WINDING$1 = 4;
  21870. var DEPTH_MASK$1 = 5;
  21871. /**
  21872. * System plugin to the renderer to manage WebGL state machines.
  21873. *
  21874. * @class
  21875. * @extends PIXI.System
  21876. * @memberof PIXI
  21877. */
  21878. var StateSystem = /** @class */ (function () {
  21879. function StateSystem() {
  21880. /**
  21881. * GL context
  21882. * @member {WebGLRenderingContext}
  21883. * @readonly
  21884. */
  21885. this.gl = null;
  21886. /**
  21887. * State ID
  21888. * @member {number}
  21889. * @readonly
  21890. */
  21891. this.stateId = 0;
  21892. /**
  21893. * Polygon offset
  21894. * @member {number}
  21895. * @readonly
  21896. */
  21897. this.polygonOffset = 0;
  21898. /**
  21899. * Blend mode
  21900. * @member {number}
  21901. * @default PIXI.BLEND_MODES.NONE
  21902. * @readonly
  21903. */
  21904. this.blendMode = exports.BLEND_MODES.NONE;
  21905. /**
  21906. * Whether current blend equation is different
  21907. * @member {boolean}
  21908. * @protected
  21909. */
  21910. this._blendEq = false;
  21911. /**
  21912. * Collection of calls
  21913. * @member {function[]}
  21914. * @readonly
  21915. */
  21916. this.map = [];
  21917. // map functions for when we set state..
  21918. this.map[BLEND$1] = this.setBlend;
  21919. this.map[OFFSET$1] = this.setOffset;
  21920. this.map[CULLING$1] = this.setCullFace;
  21921. this.map[DEPTH_TEST$1] = this.setDepthTest;
  21922. this.map[WINDING$1] = this.setFrontFace;
  21923. this.map[DEPTH_MASK$1] = this.setDepthMask;
  21924. /**
  21925. * Collection of check calls
  21926. * @member {function[]}
  21927. * @readonly
  21928. */
  21929. this.checks = [];
  21930. /**
  21931. * Default WebGL State
  21932. * @member {PIXI.State}
  21933. * @readonly
  21934. */
  21935. this.defaultState = new State();
  21936. this.defaultState.blend = true;
  21937. }
  21938. StateSystem.prototype.contextChange = function (gl) {
  21939. this.gl = gl;
  21940. this.blendModes = mapWebGLBlendModesToPixi(gl);
  21941. this.set(this.defaultState);
  21942. this.reset();
  21943. };
  21944. /**
  21945. * Sets the current state
  21946. *
  21947. * @param {*} state - The state to set.
  21948. */
  21949. StateSystem.prototype.set = function (state) {
  21950. state = state || this.defaultState;
  21951. // TODO maybe to an object check? ( this.state === state )?
  21952. if (this.stateId !== state.data) {
  21953. var diff = this.stateId ^ state.data;
  21954. var i = 0;
  21955. // order from least to most common
  21956. while (diff) {
  21957. if (diff & 1) {
  21958. // state change!
  21959. this.map[i].call(this, !!(state.data & (1 << i)));
  21960. }
  21961. diff = diff >> 1;
  21962. i++;
  21963. }
  21964. this.stateId = state.data;
  21965. }
  21966. // based on the above settings we check for specific modes..
  21967. // for example if blend is active we check and set the blend modes
  21968. // or of polygon offset is active we check the poly depth.
  21969. for (var i = 0; i < this.checks.length; i++) {
  21970. this.checks[i](this, state);
  21971. }
  21972. };
  21973. /**
  21974. * Sets the state, when previous state is unknown
  21975. *
  21976. * @param {*} state - The state to set
  21977. */
  21978. StateSystem.prototype.forceState = function (state) {
  21979. state = state || this.defaultState;
  21980. for (var i = 0; i < this.map.length; i++) {
  21981. this.map[i].call(this, !!(state.data & (1 << i)));
  21982. }
  21983. for (var i = 0; i < this.checks.length; i++) {
  21984. this.checks[i](this, state);
  21985. }
  21986. this.stateId = state.data;
  21987. };
  21988. /**
  21989. * Enables or disabled blending.
  21990. *
  21991. * @param {boolean} value - Turn on or off webgl blending.
  21992. */
  21993. StateSystem.prototype.setBlend = function (value) {
  21994. this.updateCheck(StateSystem.checkBlendMode, value);
  21995. this.gl[value ? 'enable' : 'disable'](this.gl.BLEND);
  21996. };
  21997. /**
  21998. * Enables or disable polygon offset fill
  21999. *
  22000. * @param {boolean} value - Turn on or off webgl polygon offset testing.
  22001. */
  22002. StateSystem.prototype.setOffset = function (value) {
  22003. this.updateCheck(StateSystem.checkPolygonOffset, value);
  22004. this.gl[value ? 'enable' : 'disable'](this.gl.POLYGON_OFFSET_FILL);
  22005. };
  22006. /**
  22007. * Sets whether to enable or disable depth test.
  22008. *
  22009. * @param {boolean} value - Turn on or off webgl depth testing.
  22010. */
  22011. StateSystem.prototype.setDepthTest = function (value) {
  22012. this.gl[value ? 'enable' : 'disable'](this.gl.DEPTH_TEST);
  22013. };
  22014. /**
  22015. * Sets whether to enable or disable depth mask.
  22016. *
  22017. * @param {boolean} value - Turn on or off webgl depth mask.
  22018. */
  22019. StateSystem.prototype.setDepthMask = function (value) {
  22020. this.gl.depthMask(value);
  22021. };
  22022. /**
  22023. * Sets whether to enable or disable cull face.
  22024. *
  22025. * @param {boolean} value - Turn on or off webgl cull face.
  22026. */
  22027. StateSystem.prototype.setCullFace = function (value) {
  22028. this.gl[value ? 'enable' : 'disable'](this.gl.CULL_FACE);
  22029. };
  22030. /**
  22031. * Sets the gl front face.
  22032. *
  22033. * @param {boolean} value - true is clockwise and false is counter-clockwise
  22034. */
  22035. StateSystem.prototype.setFrontFace = function (value) {
  22036. this.gl.frontFace(this.gl[value ? 'CW' : 'CCW']);
  22037. };
  22038. /**
  22039. * Sets the blend mode.
  22040. *
  22041. * @param {number} value - The blend mode to set to.
  22042. */
  22043. StateSystem.prototype.setBlendMode = function (value) {
  22044. if (value === this.blendMode) {
  22045. return;
  22046. }
  22047. this.blendMode = value;
  22048. var mode = this.blendModes[value];
  22049. var gl = this.gl;
  22050. if (mode.length === 2) {
  22051. gl.blendFunc(mode[0], mode[1]);
  22052. }
  22053. else {
  22054. gl.blendFuncSeparate(mode[0], mode[1], mode[2], mode[3]);
  22055. }
  22056. if (mode.length === 6) {
  22057. this._blendEq = true;
  22058. gl.blendEquationSeparate(mode[4], mode[5]);
  22059. }
  22060. else if (this._blendEq) {
  22061. this._blendEq = false;
  22062. gl.blendEquationSeparate(gl.FUNC_ADD, gl.FUNC_ADD);
  22063. }
  22064. };
  22065. /**
  22066. * Sets the polygon offset.
  22067. *
  22068. * @param {number} value - the polygon offset
  22069. * @param {number} scale - the polygon offset scale
  22070. */
  22071. StateSystem.prototype.setPolygonOffset = function (value, scale) {
  22072. this.gl.polygonOffset(value, scale);
  22073. };
  22074. // used
  22075. /**
  22076. * Resets all the logic and disables the vaos
  22077. */
  22078. StateSystem.prototype.reset = function () {
  22079. this.gl.pixelStorei(this.gl.UNPACK_FLIP_Y_WEBGL, false);
  22080. this.forceState(this.defaultState);
  22081. this._blendEq = true;
  22082. this.blendMode = -1;
  22083. this.setBlendMode(0);
  22084. };
  22085. /**
  22086. * checks to see which updates should be checked based on which settings have been activated.
  22087. * For example, if blend is enabled then we should check the blend modes each time the state is changed
  22088. * or if polygon fill is activated then we need to check if the polygon offset changes.
  22089. * The idea is that we only check what we have too.
  22090. *
  22091. * @param {Function} func - the checking function to add or remove
  22092. * @param {boolean} value - should the check function be added or removed.
  22093. */
  22094. StateSystem.prototype.updateCheck = function (func, value) {
  22095. var index = this.checks.indexOf(func);
  22096. if (value && index === -1) {
  22097. this.checks.push(func);
  22098. }
  22099. else if (!value && index !== -1) {
  22100. this.checks.splice(index, 1);
  22101. }
  22102. };
  22103. /**
  22104. * A private little wrapper function that we call to check the blend mode.
  22105. *
  22106. * @static
  22107. * @private
  22108. * @param {PIXI.StateSystem} System - the System to perform the state check on
  22109. * @param {PIXI.State} state - the state that the blendMode will pulled from
  22110. */
  22111. StateSystem.checkBlendMode = function (system, state) {
  22112. system.setBlendMode(state.blendMode);
  22113. };
  22114. /**
  22115. * A private little wrapper function that we call to check the polygon offset.
  22116. *
  22117. * @static
  22118. * @private
  22119. * @param {PIXI.StateSystem} System - the System to perform the state check on
  22120. * @param {PIXI.State} state - the state that the blendMode will pulled from
  22121. */
  22122. StateSystem.checkPolygonOffset = function (system, state) {
  22123. system.setPolygonOffset(1, state.polygonOffset);
  22124. };
  22125. /**
  22126. * @ignore
  22127. */
  22128. StateSystem.prototype.destroy = function () {
  22129. this.gl = null;
  22130. };
  22131. return StateSystem;
  22132. }());
  22133. /**
  22134. * System plugin to the renderer to manage texture garbage collection on the GPU,
  22135. * ensuring that it does not get clogged up with textures that are no longer being used.
  22136. *
  22137. * @class
  22138. * @memberof PIXI
  22139. * @extends PIXI.System
  22140. */
  22141. var TextureGCSystem = /** @class */ (function () {
  22142. /**
  22143. * @param {PIXI.Renderer} renderer - The renderer this System works for.
  22144. */
  22145. function TextureGCSystem(renderer) {
  22146. this.renderer = renderer;
  22147. /**
  22148. * Count
  22149. * @member {number}
  22150. * @readonly
  22151. */
  22152. this.count = 0;
  22153. /**
  22154. * Check count
  22155. * @member {number}
  22156. * @readonly
  22157. */
  22158. this.checkCount = 0;
  22159. /**
  22160. * Maximum idle time, in seconds
  22161. * @member {number}
  22162. * @see PIXI.settings.GC_MAX_IDLE
  22163. */
  22164. this.maxIdle = settings.GC_MAX_IDLE;
  22165. /**
  22166. * Maximum number of item to check
  22167. * @member {number}
  22168. * @see PIXI.settings.GC_MAX_CHECK_COUNT
  22169. */
  22170. this.checkCountMax = settings.GC_MAX_CHECK_COUNT;
  22171. /**
  22172. * Current garbage collection mode
  22173. * @member {PIXI.GC_MODES}
  22174. * @see PIXI.settings.GC_MODE
  22175. */
  22176. this.mode = settings.GC_MODE;
  22177. }
  22178. /**
  22179. * Checks to see when the last time a texture was used
  22180. * if the texture has not been used for a specified amount of time it will be removed from the GPU
  22181. */
  22182. TextureGCSystem.prototype.postrender = function () {
  22183. if (!this.renderer.renderingToScreen) {
  22184. return;
  22185. }
  22186. this.count++;
  22187. if (this.mode === exports.GC_MODES.MANUAL) {
  22188. return;
  22189. }
  22190. this.checkCount++;
  22191. if (this.checkCount > this.checkCountMax) {
  22192. this.checkCount = 0;
  22193. this.run();
  22194. }
  22195. };
  22196. /**
  22197. * Checks to see when the last time a texture was used
  22198. * if the texture has not been used for a specified amount of time it will be removed from the GPU
  22199. */
  22200. TextureGCSystem.prototype.run = function () {
  22201. var tm = this.renderer.texture;
  22202. var managedTextures = tm.managedTextures;
  22203. var wasRemoved = false;
  22204. for (var i = 0; i < managedTextures.length; i++) {
  22205. var texture = managedTextures[i];
  22206. // only supports non generated textures at the moment!
  22207. if (!texture.framebuffer && this.count - texture.touched > this.maxIdle) {
  22208. tm.destroyTexture(texture, true);
  22209. managedTextures[i] = null;
  22210. wasRemoved = true;
  22211. }
  22212. }
  22213. if (wasRemoved) {
  22214. var j = 0;
  22215. for (var i = 0; i < managedTextures.length; i++) {
  22216. if (managedTextures[i] !== null) {
  22217. managedTextures[j++] = managedTextures[i];
  22218. }
  22219. }
  22220. managedTextures.length = j;
  22221. }
  22222. };
  22223. /**
  22224. * Removes all the textures within the specified displayObject and its children from the GPU
  22225. *
  22226. * @param {PIXI.DisplayObject} displayObject - the displayObject to remove the textures from.
  22227. */
  22228. TextureGCSystem.prototype.unload = function (displayObject) {
  22229. var tm = this.renderer.texture;
  22230. var texture = displayObject._texture;
  22231. // only destroy non generated textures
  22232. if (texture && !texture.framebuffer) {
  22233. tm.destroyTexture(texture);
  22234. }
  22235. for (var i = displayObject.children.length - 1; i >= 0; i--) {
  22236. this.unload(displayObject.children[i]);
  22237. }
  22238. };
  22239. /**
  22240. * @ignore
  22241. */
  22242. TextureGCSystem.prototype.destroy = function () {
  22243. this.renderer = null;
  22244. };
  22245. return TextureGCSystem;
  22246. }());
  22247. /**
  22248. * Returns a lookup table that maps each type-format pair to a compatible internal format.
  22249. *
  22250. * @memberof PIXI
  22251. * @function mapTypeAndFormatToInternalFormat
  22252. * @private
  22253. * @param {WebGLRenderingContext} gl - The rendering context.
  22254. * @return {{ [type: number]: { [format: number]: number } }} Lookup table.
  22255. */
  22256. function mapTypeAndFormatToInternalFormat(gl) {
  22257. var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x;
  22258. var table;
  22259. if ('WebGL2RenderingContext' in self && gl instanceof self.WebGL2RenderingContext) {
  22260. table = (_a = {},
  22261. _a[exports.TYPES.UNSIGNED_BYTE] = (_b = {},
  22262. _b[exports.FORMATS.RGBA] = gl.RGBA8,
  22263. _b[exports.FORMATS.RGB] = gl.RGB8,
  22264. _b[exports.FORMATS.RG] = gl.RG8,
  22265. _b[exports.FORMATS.RED] = gl.R8,
  22266. _b[exports.FORMATS.RGBA_INTEGER] = gl.RGBA8UI,
  22267. _b[exports.FORMATS.RGB_INTEGER] = gl.RGB8UI,
  22268. _b[exports.FORMATS.RG_INTEGER] = gl.RG8UI,
  22269. _b[exports.FORMATS.RED_INTEGER] = gl.R8UI,
  22270. _b[exports.FORMATS.ALPHA] = gl.ALPHA,
  22271. _b[exports.FORMATS.LUMINANCE] = gl.LUMINANCE,
  22272. _b[exports.FORMATS.LUMINANCE_ALPHA] = gl.LUMINANCE_ALPHA,
  22273. _b),
  22274. _a[exports.TYPES.BYTE] = (_c = {},
  22275. _c[exports.FORMATS.RGBA] = gl.RGBA8_SNORM,
  22276. _c[exports.FORMATS.RGB] = gl.RGB8_SNORM,
  22277. _c[exports.FORMATS.RG] = gl.RG8_SNORM,
  22278. _c[exports.FORMATS.RED] = gl.R8_SNORM,
  22279. _c[exports.FORMATS.RGBA_INTEGER] = gl.RGBA8I,
  22280. _c[exports.FORMATS.RGB_INTEGER] = gl.RGB8I,
  22281. _c[exports.FORMATS.RG_INTEGER] = gl.RG8I,
  22282. _c[exports.FORMATS.RED_INTEGER] = gl.R8I,
  22283. _c),
  22284. _a[exports.TYPES.UNSIGNED_SHORT] = (_d = {},
  22285. _d[exports.FORMATS.RGBA_INTEGER] = gl.RGBA16UI,
  22286. _d[exports.FORMATS.RGB_INTEGER] = gl.RGB16UI,
  22287. _d[exports.FORMATS.RG_INTEGER] = gl.RG16UI,
  22288. _d[exports.FORMATS.RED_INTEGER] = gl.R16UI,
  22289. _d[exports.FORMATS.DEPTH_COMPONENT] = gl.DEPTH_COMPONENT16,
  22290. _d),
  22291. _a[exports.TYPES.SHORT] = (_e = {},
  22292. _e[exports.FORMATS.RGBA_INTEGER] = gl.RGBA16I,
  22293. _e[exports.FORMATS.RGB_INTEGER] = gl.RGB16I,
  22294. _e[exports.FORMATS.RG_INTEGER] = gl.RG16I,
  22295. _e[exports.FORMATS.RED_INTEGER] = gl.R16I,
  22296. _e),
  22297. _a[exports.TYPES.UNSIGNED_INT] = (_f = {},
  22298. _f[exports.FORMATS.RGBA_INTEGER] = gl.RGBA32UI,
  22299. _f[exports.FORMATS.RGB_INTEGER] = gl.RGB32UI,
  22300. _f[exports.FORMATS.RG_INTEGER] = gl.RG32UI,
  22301. _f[exports.FORMATS.RED_INTEGER] = gl.R32UI,
  22302. _f[exports.FORMATS.DEPTH_COMPONENT] = gl.DEPTH_COMPONENT24,
  22303. _f),
  22304. _a[exports.TYPES.INT] = (_g = {},
  22305. _g[exports.FORMATS.RGBA_INTEGER] = gl.RGBA32I,
  22306. _g[exports.FORMATS.RGB_INTEGER] = gl.RGB32I,
  22307. _g[exports.FORMATS.RG_INTEGER] = gl.RG32I,
  22308. _g[exports.FORMATS.RED_INTEGER] = gl.R32I,
  22309. _g),
  22310. _a[exports.TYPES.FLOAT] = (_h = {},
  22311. _h[exports.FORMATS.RGBA] = gl.RGBA32F,
  22312. _h[exports.FORMATS.RGB] = gl.RGB32F,
  22313. _h[exports.FORMATS.RG] = gl.RG32F,
  22314. _h[exports.FORMATS.RED] = gl.R32F,
  22315. _h[exports.FORMATS.DEPTH_COMPONENT] = gl.DEPTH_COMPONENT32F,
  22316. _h),
  22317. _a[exports.TYPES.HALF_FLOAT] = (_j = {},
  22318. _j[exports.FORMATS.RGBA] = gl.RGBA16F,
  22319. _j[exports.FORMATS.RGB] = gl.RGB16F,
  22320. _j[exports.FORMATS.RG] = gl.RG16F,
  22321. _j[exports.FORMATS.RED] = gl.R16F,
  22322. _j),
  22323. _a[exports.TYPES.UNSIGNED_SHORT_5_6_5] = (_k = {},
  22324. _k[exports.FORMATS.RGB] = gl.RGB565,
  22325. _k),
  22326. _a[exports.TYPES.UNSIGNED_SHORT_4_4_4_4] = (_l = {},
  22327. _l[exports.FORMATS.RGBA] = gl.RGBA4,
  22328. _l),
  22329. _a[exports.TYPES.UNSIGNED_SHORT_5_5_5_1] = (_m = {},
  22330. _m[exports.FORMATS.RGBA] = gl.RGB5_A1,
  22331. _m),
  22332. _a[exports.TYPES.UNSIGNED_INT_2_10_10_10_REV] = (_o = {},
  22333. _o[exports.FORMATS.RGBA] = gl.RGB10_A2,
  22334. _o[exports.FORMATS.RGBA_INTEGER] = gl.RGB10_A2UI,
  22335. _o),
  22336. _a[exports.TYPES.UNSIGNED_INT_10F_11F_11F_REV] = (_p = {},
  22337. _p[exports.FORMATS.RGB] = gl.R11F_G11F_B10F,
  22338. _p),
  22339. _a[exports.TYPES.UNSIGNED_INT_5_9_9_9_REV] = (_q = {},
  22340. _q[exports.FORMATS.RGB] = gl.RGB9_E5,
  22341. _q),
  22342. _a[exports.TYPES.UNSIGNED_INT_24_8] = (_r = {},
  22343. _r[exports.FORMATS.DEPTH_STENCIL] = gl.DEPTH24_STENCIL8,
  22344. _r),
  22345. _a[exports.TYPES.FLOAT_32_UNSIGNED_INT_24_8_REV] = (_s = {},
  22346. _s[exports.FORMATS.DEPTH_STENCIL] = gl.DEPTH32F_STENCIL8,
  22347. _s),
  22348. _a);
  22349. }
  22350. else {
  22351. table = (_t = {},
  22352. _t[exports.TYPES.UNSIGNED_BYTE] = (_u = {},
  22353. _u[exports.FORMATS.RGBA] = gl.RGBA,
  22354. _u[exports.FORMATS.RGB] = gl.RGB,
  22355. _u[exports.FORMATS.ALPHA] = gl.ALPHA,
  22356. _u[exports.FORMATS.LUMINANCE] = gl.LUMINANCE,
  22357. _u[exports.FORMATS.LUMINANCE_ALPHA] = gl.LUMINANCE_ALPHA,
  22358. _u),
  22359. _t[exports.TYPES.UNSIGNED_SHORT_5_6_5] = (_v = {},
  22360. _v[exports.FORMATS.RGB] = gl.RGB,
  22361. _v),
  22362. _t[exports.TYPES.UNSIGNED_SHORT_4_4_4_4] = (_w = {},
  22363. _w[exports.FORMATS.RGBA] = gl.RGBA,
  22364. _w),
  22365. _t[exports.TYPES.UNSIGNED_SHORT_5_5_5_1] = (_x = {},
  22366. _x[exports.FORMATS.RGBA] = gl.RGBA,
  22367. _x),
  22368. _t);
  22369. }
  22370. return table;
  22371. }
  22372. /**
  22373. * Internal texture for WebGL context
  22374. * @class
  22375. * @memberof PIXI
  22376. */
  22377. var GLTexture = /** @class */ (function () {
  22378. function GLTexture(texture) {
  22379. /**
  22380. * The WebGL texture
  22381. * @member {WebGLTexture}
  22382. */
  22383. this.texture = texture;
  22384. /**
  22385. * Width of texture that was used in texImage2D
  22386. * @member {number}
  22387. */
  22388. this.width = -1;
  22389. /**
  22390. * Height of texture that was used in texImage2D
  22391. * @member {number}
  22392. */
  22393. this.height = -1;
  22394. /**
  22395. * Texture contents dirty flag
  22396. * @member {number}
  22397. */
  22398. this.dirtyId = -1;
  22399. /**
  22400. * Texture style dirty flag
  22401. * @member {number}
  22402. */
  22403. this.dirtyStyleId = -1;
  22404. /**
  22405. * Whether mip levels has to be generated
  22406. * @member {boolean}
  22407. */
  22408. this.mipmap = false;
  22409. /**
  22410. * WrapMode copied from baseTexture
  22411. * @member {number}
  22412. */
  22413. this.wrapMode = 33071;
  22414. /**
  22415. * Type copied from baseTexture
  22416. * @member {number}
  22417. */
  22418. this.type = exports.TYPES.UNSIGNED_BYTE;
  22419. /**
  22420. * Type copied from baseTexture
  22421. * @member {number}
  22422. */
  22423. this.internalFormat = exports.FORMATS.RGBA;
  22424. this.samplerType = 0;
  22425. }
  22426. return GLTexture;
  22427. }());
  22428. /**
  22429. * System plugin to the renderer to manage textures.
  22430. *
  22431. * @class
  22432. * @extends PIXI.System
  22433. * @memberof PIXI
  22434. */
  22435. var TextureSystem = /** @class */ (function () {
  22436. /**
  22437. * @param {PIXI.Renderer} renderer - The renderer this System works for.
  22438. */
  22439. function TextureSystem(renderer) {
  22440. this.renderer = renderer;
  22441. // TODO set to max textures...
  22442. /**
  22443. * Bound textures
  22444. * @member {PIXI.BaseTexture[]}
  22445. * @readonly
  22446. */
  22447. this.boundTextures = [];
  22448. /**
  22449. * Current location
  22450. * @member {number}
  22451. * @readonly
  22452. */
  22453. this.currentLocation = -1;
  22454. /**
  22455. * List of managed textures
  22456. * @member {PIXI.BaseTexture[]}
  22457. * @readonly
  22458. */
  22459. this.managedTextures = [];
  22460. /**
  22461. * Did someone temper with textures state? We'll overwrite them when we need to unbind something.
  22462. * @member {boolean}
  22463. * @private
  22464. */
  22465. this._unknownBoundTextures = false;
  22466. /**
  22467. * BaseTexture value that shows that we don't know what is bound
  22468. * @member {PIXI.BaseTexture}
  22469. * @readonly
  22470. */
  22471. this.unknownTexture = new BaseTexture();
  22472. this.hasIntegerTextures = false;
  22473. }
  22474. /**
  22475. * Sets up the renderer context and necessary buffers.
  22476. */
  22477. TextureSystem.prototype.contextChange = function () {
  22478. var gl = this.gl = this.renderer.gl;
  22479. this.CONTEXT_UID = this.renderer.CONTEXT_UID;
  22480. this.webGLVersion = this.renderer.context.webGLVersion;
  22481. this.internalFormats = mapTypeAndFormatToInternalFormat(gl);
  22482. var maxTextures = gl.getParameter(gl.MAX_TEXTURE_IMAGE_UNITS);
  22483. this.boundTextures.length = maxTextures;
  22484. for (var i = 0; i < maxTextures; i++) {
  22485. this.boundTextures[i] = null;
  22486. }
  22487. // TODO move this.. to a nice make empty textures class..
  22488. this.emptyTextures = {};
  22489. var emptyTexture2D = new GLTexture(gl.createTexture());
  22490. gl.bindTexture(gl.TEXTURE_2D, emptyTexture2D.texture);
  22491. gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 1, 1, 0, gl.RGBA, gl.UNSIGNED_BYTE, new Uint8Array(4));
  22492. this.emptyTextures[gl.TEXTURE_2D] = emptyTexture2D;
  22493. this.emptyTextures[gl.TEXTURE_CUBE_MAP] = new GLTexture(gl.createTexture());
  22494. gl.bindTexture(gl.TEXTURE_CUBE_MAP, this.emptyTextures[gl.TEXTURE_CUBE_MAP].texture);
  22495. for (var i = 0; i < 6; i++) {
  22496. gl.texImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, gl.RGBA, 1, 1, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
  22497. }
  22498. gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
  22499. gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
  22500. for (var i = 0; i < this.boundTextures.length; i++) {
  22501. this.bind(null, i);
  22502. }
  22503. };
  22504. /**
  22505. * Bind a texture to a specific location
  22506. *
  22507. * If you want to unbind something, please use `unbind(texture)` instead of `bind(null, textureLocation)`
  22508. *
  22509. * @param {PIXI.Texture|PIXI.BaseTexture} texture_ - Texture to bind
  22510. * @param {number} [location=0] - Location to bind at
  22511. */
  22512. TextureSystem.prototype.bind = function (texture, location) {
  22513. if (location === void 0) { location = 0; }
  22514. var gl = this.gl;
  22515. texture = texture === null || texture === void 0 ? void 0 : texture.castToBaseTexture();
  22516. // cannot bind partial texture
  22517. // TODO: report a warning
  22518. if (texture && texture.valid && !texture.parentTextureArray) {
  22519. texture.touched = this.renderer.textureGC.count;
  22520. var glTexture = texture._glTextures[this.CONTEXT_UID] || this.initTexture(texture);
  22521. if (this.boundTextures[location] !== texture) {
  22522. if (this.currentLocation !== location) {
  22523. this.currentLocation = location;
  22524. gl.activeTexture(gl.TEXTURE0 + location);
  22525. }
  22526. gl.bindTexture(texture.target, glTexture.texture);
  22527. }
  22528. if (glTexture.dirtyId !== texture.dirtyId) {
  22529. if (this.currentLocation !== location) {
  22530. this.currentLocation = location;
  22531. gl.activeTexture(gl.TEXTURE0 + location);
  22532. }
  22533. this.updateTexture(texture);
  22534. }
  22535. this.boundTextures[location] = texture;
  22536. }
  22537. else {
  22538. if (this.currentLocation !== location) {
  22539. this.currentLocation = location;
  22540. gl.activeTexture(gl.TEXTURE0 + location);
  22541. }
  22542. gl.bindTexture(gl.TEXTURE_2D, this.emptyTextures[gl.TEXTURE_2D].texture);
  22543. this.boundTextures[location] = null;
  22544. }
  22545. };
  22546. /**
  22547. * Resets texture location and bound textures
  22548. *
  22549. * Actual `bind(null, i)` calls will be performed at next `unbind()` call
  22550. */
  22551. TextureSystem.prototype.reset = function () {
  22552. this._unknownBoundTextures = true;
  22553. this.hasIntegerTextures = false;
  22554. this.currentLocation = -1;
  22555. for (var i = 0; i < this.boundTextures.length; i++) {
  22556. this.boundTextures[i] = this.unknownTexture;
  22557. }
  22558. };
  22559. /**
  22560. * Unbind a texture
  22561. * @param {PIXI.BaseTexture} texture - Texture to bind
  22562. */
  22563. TextureSystem.prototype.unbind = function (texture) {
  22564. var _a = this, gl = _a.gl, boundTextures = _a.boundTextures;
  22565. if (this._unknownBoundTextures) {
  22566. this._unknownBoundTextures = false;
  22567. // someone changed webGL state,
  22568. // we have to be sure that our texture does not appear in multi-texture renderer samplers
  22569. for (var i = 0; i < boundTextures.length; i++) {
  22570. if (boundTextures[i] === this.unknownTexture) {
  22571. this.bind(null, i);
  22572. }
  22573. }
  22574. }
  22575. for (var i = 0; i < boundTextures.length; i++) {
  22576. if (boundTextures[i] === texture) {
  22577. if (this.currentLocation !== i) {
  22578. gl.activeTexture(gl.TEXTURE0 + i);
  22579. this.currentLocation = i;
  22580. }
  22581. gl.bindTexture(texture.target, this.emptyTextures[texture.target].texture);
  22582. boundTextures[i] = null;
  22583. }
  22584. }
  22585. };
  22586. /**
  22587. * Ensures that current boundTextures all have FLOAT sampler type,
  22588. * see {@link PIXI.SAMPLER_TYPES} for explanation.
  22589. *
  22590. * @param maxTextures - number of locations to check
  22591. */
  22592. TextureSystem.prototype.ensureSamplerType = function (maxTextures) {
  22593. var _a = this, boundTextures = _a.boundTextures, hasIntegerTextures = _a.hasIntegerTextures, CONTEXT_UID = _a.CONTEXT_UID;
  22594. if (!hasIntegerTextures) {
  22595. return;
  22596. }
  22597. for (var i = maxTextures - 1; i >= 0; --i) {
  22598. var tex = boundTextures[i];
  22599. if (tex) {
  22600. var glTexture = tex._glTextures[CONTEXT_UID];
  22601. if (glTexture.samplerType !== exports.SAMPLER_TYPES.FLOAT) {
  22602. this.renderer.texture.unbind(tex);
  22603. }
  22604. }
  22605. }
  22606. };
  22607. /**
  22608. * Initialize a texture
  22609. *
  22610. * @private
  22611. * @param {PIXI.BaseTexture} texture - Texture to initialize
  22612. */
  22613. TextureSystem.prototype.initTexture = function (texture) {
  22614. var glTexture = new GLTexture(this.gl.createTexture());
  22615. // guarantee an update..
  22616. glTexture.dirtyId = -1;
  22617. texture._glTextures[this.CONTEXT_UID] = glTexture;
  22618. this.managedTextures.push(texture);
  22619. texture.on('dispose', this.destroyTexture, this);
  22620. return glTexture;
  22621. };
  22622. TextureSystem.prototype.initTextureType = function (texture, glTexture) {
  22623. var _a, _b;
  22624. glTexture.internalFormat = (_b = (_a = this.internalFormats[texture.type]) === null || _a === void 0 ? void 0 : _a[texture.format]) !== null && _b !== void 0 ? _b : texture.format;
  22625. if (this.webGLVersion === 2 && texture.type === exports.TYPES.HALF_FLOAT) {
  22626. // TYPES.HALF_FLOAT is WebGL1 HALF_FLOAT_OES
  22627. // we have to convert it to WebGL HALF_FLOAT
  22628. glTexture.type = this.gl.HALF_FLOAT;
  22629. }
  22630. else {
  22631. glTexture.type = texture.type;
  22632. }
  22633. };
  22634. /**
  22635. * Update a texture
  22636. *
  22637. * @private
  22638. * @param {PIXI.BaseTexture} texture - Texture to initialize
  22639. */
  22640. TextureSystem.prototype.updateTexture = function (texture) {
  22641. var glTexture = texture._glTextures[this.CONTEXT_UID];
  22642. if (!glTexture) {
  22643. return;
  22644. }
  22645. var renderer = this.renderer;
  22646. this.initTextureType(texture, glTexture);
  22647. if (texture.resource && texture.resource.upload(renderer, texture, glTexture)) {
  22648. // texture is uploaded, dont do anything!
  22649. if (glTexture.samplerType !== exports.SAMPLER_TYPES.FLOAT) {
  22650. this.hasIntegerTextures = true;
  22651. }
  22652. }
  22653. else {
  22654. // default, renderTexture-like logic
  22655. var width = texture.realWidth;
  22656. var height = texture.realHeight;
  22657. var gl = renderer.gl;
  22658. if (glTexture.width !== width
  22659. || glTexture.height !== height
  22660. || glTexture.dirtyId < 0) {
  22661. glTexture.width = width;
  22662. glTexture.height = height;
  22663. gl.texImage2D(texture.target, 0, glTexture.internalFormat, width, height, 0, texture.format, glTexture.type, null);
  22664. }
  22665. }
  22666. // lets only update what changes..
  22667. if (texture.dirtyStyleId !== glTexture.dirtyStyleId) {
  22668. this.updateTextureStyle(texture);
  22669. }
  22670. glTexture.dirtyId = texture.dirtyId;
  22671. };
  22672. /**
  22673. * Deletes the texture from WebGL
  22674. *
  22675. * @private
  22676. * @param {PIXI.BaseTexture|PIXI.Texture} texture_ - the texture to destroy
  22677. * @param {boolean} [skipRemove=false] - Whether to skip removing the texture from the TextureManager.
  22678. */
  22679. TextureSystem.prototype.destroyTexture = function (texture, skipRemove) {
  22680. var gl = this.gl;
  22681. texture = texture.castToBaseTexture();
  22682. if (texture._glTextures[this.CONTEXT_UID]) {
  22683. this.unbind(texture);
  22684. gl.deleteTexture(texture._glTextures[this.CONTEXT_UID].texture);
  22685. texture.off('dispose', this.destroyTexture, this);
  22686. delete texture._glTextures[this.CONTEXT_UID];
  22687. if (!skipRemove) {
  22688. var i = this.managedTextures.indexOf(texture);
  22689. if (i !== -1) {
  22690. removeItems(this.managedTextures, i, 1);
  22691. }
  22692. }
  22693. }
  22694. };
  22695. /**
  22696. * Update texture style such as mipmap flag
  22697. *
  22698. * @private
  22699. * @param {PIXI.BaseTexture} texture - Texture to update
  22700. */
  22701. TextureSystem.prototype.updateTextureStyle = function (texture) {
  22702. var glTexture = texture._glTextures[this.CONTEXT_UID];
  22703. if (!glTexture) {
  22704. return;
  22705. }
  22706. if ((texture.mipmap === exports.MIPMAP_MODES.POW2 || this.webGLVersion !== 2) && !texture.isPowerOfTwo) {
  22707. glTexture.mipmap = false;
  22708. }
  22709. else {
  22710. glTexture.mipmap = texture.mipmap >= 1;
  22711. }
  22712. if (this.webGLVersion !== 2 && !texture.isPowerOfTwo) {
  22713. glTexture.wrapMode = exports.WRAP_MODES.CLAMP;
  22714. }
  22715. else {
  22716. glTexture.wrapMode = texture.wrapMode;
  22717. }
  22718. if (texture.resource && texture.resource.style(this.renderer, texture, glTexture)) { ; }
  22719. else {
  22720. this.setStyle(texture, glTexture);
  22721. }
  22722. glTexture.dirtyStyleId = texture.dirtyStyleId;
  22723. };
  22724. /**
  22725. * Set style for texture
  22726. *
  22727. * @private
  22728. * @param {PIXI.BaseTexture} texture - Texture to update
  22729. * @param {PIXI.GLTexture} glTexture
  22730. */
  22731. TextureSystem.prototype.setStyle = function (texture, glTexture) {
  22732. var gl = this.gl;
  22733. if (glTexture.mipmap && texture.mipmap !== exports.MIPMAP_MODES.ON_MANUAL) {
  22734. gl.generateMipmap(texture.target);
  22735. }
  22736. gl.texParameteri(texture.target, gl.TEXTURE_WRAP_S, glTexture.wrapMode);
  22737. gl.texParameteri(texture.target, gl.TEXTURE_WRAP_T, glTexture.wrapMode);
  22738. if (glTexture.mipmap) {
  22739. /* eslint-disable max-len */
  22740. gl.texParameteri(texture.target, gl.TEXTURE_MIN_FILTER, texture.scaleMode === exports.SCALE_MODES.LINEAR ? gl.LINEAR_MIPMAP_LINEAR : gl.NEAREST_MIPMAP_NEAREST);
  22741. /* eslint-disable max-len */
  22742. var anisotropicExt = this.renderer.context.extensions.anisotropicFiltering;
  22743. if (anisotropicExt && texture.anisotropicLevel > 0 && texture.scaleMode === exports.SCALE_MODES.LINEAR) {
  22744. var level = Math.min(texture.anisotropicLevel, gl.getParameter(anisotropicExt.MAX_TEXTURE_MAX_ANISOTROPY_EXT));
  22745. gl.texParameterf(texture.target, anisotropicExt.TEXTURE_MAX_ANISOTROPY_EXT, level);
  22746. }
  22747. }
  22748. else {
  22749. gl.texParameteri(texture.target, gl.TEXTURE_MIN_FILTER, texture.scaleMode === exports.SCALE_MODES.LINEAR ? gl.LINEAR : gl.NEAREST);
  22750. }
  22751. gl.texParameteri(texture.target, gl.TEXTURE_MAG_FILTER, texture.scaleMode === exports.SCALE_MODES.LINEAR ? gl.LINEAR : gl.NEAREST);
  22752. };
  22753. /**
  22754. * @ignore
  22755. */
  22756. TextureSystem.prototype.destroy = function () {
  22757. this.renderer = null;
  22758. };
  22759. return TextureSystem;
  22760. }());
  22761. var _systems = {
  22762. __proto__: null,
  22763. FilterSystem: FilterSystem,
  22764. BatchSystem: BatchSystem,
  22765. ContextSystem: ContextSystem,
  22766. FramebufferSystem: FramebufferSystem,
  22767. GeometrySystem: GeometrySystem,
  22768. MaskSystem: MaskSystem,
  22769. ScissorSystem: ScissorSystem,
  22770. StencilSystem: StencilSystem,
  22771. ProjectionSystem: ProjectionSystem,
  22772. RenderTextureSystem: RenderTextureSystem,
  22773. ShaderSystem: ShaderSystem,
  22774. StateSystem: StateSystem,
  22775. TextureGCSystem: TextureGCSystem,
  22776. TextureSystem: TextureSystem
  22777. };
  22778. var tempMatrix$1 = new Matrix();
  22779. /**
  22780. * The AbstractRenderer is the base for a PixiJS Renderer. It is extended by the {@link PIXI.CanvasRenderer}
  22781. * and {@link PIXI.Renderer} which can be used for rendering a PixiJS scene.
  22782. *
  22783. * @abstract
  22784. * @class
  22785. * @extends PIXI.utils.EventEmitter
  22786. * @memberof PIXI
  22787. */
  22788. var AbstractRenderer = /** @class */ (function (_super) {
  22789. __extends$2(AbstractRenderer, _super);
  22790. /**
  22791. * @param system - The name of the system this renderer is for.
  22792. * @param [options] - The optional renderer parameters.
  22793. * @param {number} [options.width=800] - The width of the screen.
  22794. * @param {number} [options.height=600] - The height of the screen.
  22795. * @param {HTMLCanvasElement} [options.view] - The canvas to use as a view, optional.
  22796. * @param {boolean} [options.useContextAlpha=true] - Pass-through value for canvas' context `alpha` property.
  22797. * If you want to set transparency, please use `backgroundAlpha`. This option is for cases where the
  22798. * canvas needs to be opaque, possibly for performance reasons on some older devices.
  22799. * @param {boolean} [options.autoDensity=false] - Resizes renderer view in CSS pixels to allow for
  22800. * resolutions other than 1.
  22801. * @param {boolean} [options.antialias=false] - Sets antialias
  22802. * @param {number} [options.resolution=PIXI.settings.RESOLUTION] - The resolution / device pixel ratio of the renderer.
  22803. * @param {boolean} [options.preserveDrawingBuffer=false] - Enables drawing buffer preservation,
  22804. * enable this if you need to call toDataUrl on the WebGL context.
  22805. * @param {boolean} [options.clearBeforeRender=true] - This sets if the renderer will clear the canvas or
  22806. * not before the new render pass.
  22807. * @param {number} [options.backgroundColor=0x000000] - The background color of the rendered area
  22808. * (shown if not transparent).
  22809. * @param {number} [options.backgroundAlpha=1] - Value from 0 (fully transparent) to 1 (fully opaque).
  22810. */
  22811. function AbstractRenderer(type, options) {
  22812. if (type === void 0) { type = exports.RENDERER_TYPE.UNKNOWN; }
  22813. var _this = _super.call(this) || this;
  22814. // Add the default render options
  22815. options = Object.assign({}, settings.RENDER_OPTIONS, options);
  22816. /**
  22817. * The supplied constructor options.
  22818. *
  22819. * @member {Object}
  22820. * @readOnly
  22821. */
  22822. _this.options = options;
  22823. /**
  22824. * The type of the renderer.
  22825. *
  22826. * @member {number}
  22827. * @default PIXI.RENDERER_TYPE.UNKNOWN
  22828. * @see PIXI.RENDERER_TYPE
  22829. */
  22830. _this.type = type;
  22831. /**
  22832. * Measurements of the screen. (0, 0, screenWidth, screenHeight).
  22833. *
  22834. * Its safe to use as filterArea or hitArea for the whole stage.
  22835. *
  22836. * @member {PIXI.Rectangle}
  22837. */
  22838. _this.screen = new Rectangle(0, 0, options.width, options.height);
  22839. /**
  22840. * The canvas element that everything is drawn to.
  22841. *
  22842. * @member {HTMLCanvasElement}
  22843. */
  22844. _this.view = options.view || document.createElement('canvas');
  22845. /**
  22846. * The resolution / device pixel ratio of the renderer.
  22847. *
  22848. * @member {number}
  22849. * @default PIXI.settings.RESOLUTION
  22850. */
  22851. _this.resolution = options.resolution || settings.RESOLUTION;
  22852. /**
  22853. * Pass-thru setting for the the canvas' context `alpha` property. This is typically
  22854. * not something you need to fiddle with. If you want transparency, use `backgroundAlpha`.
  22855. *
  22856. * @member {boolean}
  22857. */
  22858. _this.useContextAlpha = options.useContextAlpha;
  22859. /**
  22860. * Whether CSS dimensions of canvas view should be resized to screen dimensions automatically.
  22861. *
  22862. * @member {boolean}
  22863. */
  22864. _this.autoDensity = !!options.autoDensity;
  22865. /**
  22866. * The value of the preserveDrawingBuffer flag affects whether or not the contents of
  22867. * the stencil buffer is retained after rendering.
  22868. *
  22869. * @member {boolean}
  22870. */
  22871. _this.preserveDrawingBuffer = options.preserveDrawingBuffer;
  22872. /**
  22873. * This sets if the CanvasRenderer will clear the canvas or not before the new render pass.
  22874. * If the scene is NOT transparent PixiJS will use a canvas sized fillRect operation every
  22875. * frame to set the canvas background color. If the scene is transparent PixiJS will use clearRect
  22876. * to clear the canvas every frame. Disable this by setting this to false. For example, if
  22877. * your game has a canvas filling background image you often don't need this set.
  22878. *
  22879. * @member {boolean}
  22880. * @default
  22881. */
  22882. _this.clearBeforeRender = options.clearBeforeRender;
  22883. /**
  22884. * The background color as a number.
  22885. *
  22886. * @member {number}
  22887. * @protected
  22888. */
  22889. _this._backgroundColor = 0x000000;
  22890. /**
  22891. * The background color as an [R, G, B, A] array.
  22892. *
  22893. * @member {number[]}
  22894. * @protected
  22895. */
  22896. _this._backgroundColorRgba = [0, 0, 0, 1];
  22897. /**
  22898. * The background color as a string.
  22899. *
  22900. * @member {string}
  22901. * @protected
  22902. */
  22903. _this._backgroundColorString = '#000000';
  22904. _this.backgroundColor = options.backgroundColor || _this._backgroundColor; // run bg color setter
  22905. _this.backgroundAlpha = options.backgroundAlpha;
  22906. // @deprecated
  22907. if (options.transparent !== undefined) {
  22908. deprecation('6.0.0', 'Option transparent is deprecated, please use backgroundAlpha instead.');
  22909. _this.useContextAlpha = options.transparent;
  22910. _this.backgroundAlpha = options.transparent ? 0 : 1;
  22911. }
  22912. /**
  22913. * The last root object that the renderer tried to render.
  22914. *
  22915. * @member {PIXI.DisplayObject}
  22916. * @protected
  22917. */
  22918. _this._lastObjectRendered = null;
  22919. /**
  22920. * Collection of plugins.
  22921. * @readonly
  22922. * @member {object}
  22923. */
  22924. _this.plugins = {};
  22925. return _this;
  22926. }
  22927. /**
  22928. * Initialize the plugins.
  22929. *
  22930. * @protected
  22931. * @param {object} staticMap - The dictionary of statically saved plugins.
  22932. */
  22933. AbstractRenderer.prototype.initPlugins = function (staticMap) {
  22934. for (var o in staticMap) {
  22935. this.plugins[o] = new (staticMap[o])(this);
  22936. }
  22937. };
  22938. Object.defineProperty(AbstractRenderer.prototype, "width", {
  22939. /**
  22940. * Same as view.width, actual number of pixels in the canvas by horizontal.
  22941. *
  22942. * @member {number}
  22943. * @readonly
  22944. * @default 800
  22945. */
  22946. get: function () {
  22947. return this.view.width;
  22948. },
  22949. enumerable: false,
  22950. configurable: true
  22951. });
  22952. Object.defineProperty(AbstractRenderer.prototype, "height", {
  22953. /**
  22954. * Same as view.height, actual number of pixels in the canvas by vertical.
  22955. *
  22956. * @member {number}
  22957. * @readonly
  22958. * @default 600
  22959. */
  22960. get: function () {
  22961. return this.view.height;
  22962. },
  22963. enumerable: false,
  22964. configurable: true
  22965. });
  22966. /**
  22967. * Resizes the screen and canvas as close as possible to the specified width and height.
  22968. * Canvas dimensions are multiplied by resolution and rounded to the nearest integers.
  22969. * The new canvas dimensions divided by the resolution become the new screen dimensions.
  22970. *
  22971. * @param desiredScreenWidth - The desired width of the screen.
  22972. * @param desiredScreenHeight - The desired height of the screen.
  22973. */
  22974. AbstractRenderer.prototype.resize = function (desiredScreenWidth, desiredScreenHeight) {
  22975. this.view.width = Math.round(desiredScreenWidth * this.resolution);
  22976. this.view.height = Math.round(desiredScreenHeight * this.resolution);
  22977. var screenWidth = this.view.width / this.resolution;
  22978. var screenHeight = this.view.height / this.resolution;
  22979. this.screen.width = screenWidth;
  22980. this.screen.height = screenHeight;
  22981. if (this.autoDensity) {
  22982. this.view.style.width = screenWidth + "px";
  22983. this.view.style.height = screenHeight + "px";
  22984. }
  22985. /**
  22986. * Fired after view has been resized.
  22987. *
  22988. * @event PIXI.Renderer#resize
  22989. * @param {number} screenWidth - The new width of the screen.
  22990. * @param {number} screenHeight - The new height of the screen.
  22991. */
  22992. this.emit('resize', screenWidth, screenHeight);
  22993. };
  22994. /**
  22995. * @ignore
  22996. */
  22997. AbstractRenderer.prototype.generateTexture = function (displayObject, options, resolution, region) {
  22998. if (options === void 0) { options = {}; }
  22999. // @deprecated parameters spread, use options instead
  23000. if (typeof options === 'number') {
  23001. deprecation('6.1.0', 'generateTexture options (scaleMode, resolution, region) are now object options.');
  23002. options = { scaleMode: options, resolution: resolution, region: region };
  23003. }
  23004. var manualRegion = options.region, textureOptions = __rest(options, ["region"]);
  23005. region = manualRegion || displayObject.getLocalBounds(null, true);
  23006. // minimum texture size is 1x1, 0x0 will throw an error
  23007. if (region.width === 0)
  23008. { region.width = 1; }
  23009. if (region.height === 0)
  23010. { region.height = 1; }
  23011. var renderTexture = RenderTexture.create(__assign({ width: region.width, height: region.height }, textureOptions));
  23012. tempMatrix$1.tx = -region.x;
  23013. tempMatrix$1.ty = -region.y;
  23014. this.render(displayObject, {
  23015. renderTexture: renderTexture,
  23016. clear: false,
  23017. transform: tempMatrix$1,
  23018. skipUpdateTransform: !!displayObject.parent
  23019. });
  23020. return renderTexture;
  23021. };
  23022. /**
  23023. * Removes everything from the renderer and optionally removes the Canvas DOM element.
  23024. *
  23025. * @param [removeView=false] - Removes the Canvas element from the DOM.
  23026. */
  23027. AbstractRenderer.prototype.destroy = function (removeView) {
  23028. for (var o in this.plugins) {
  23029. this.plugins[o].destroy();
  23030. this.plugins[o] = null;
  23031. }
  23032. if (removeView && this.view.parentNode) {
  23033. this.view.parentNode.removeChild(this.view);
  23034. }
  23035. var thisAny = this;
  23036. // null-ing all objects, that's a tradition!
  23037. thisAny.plugins = null;
  23038. thisAny.type = exports.RENDERER_TYPE.UNKNOWN;
  23039. thisAny.view = null;
  23040. thisAny.screen = null;
  23041. thisAny._tempDisplayObjectParent = null;
  23042. thisAny.options = null;
  23043. this._backgroundColorRgba = null;
  23044. this._backgroundColorString = null;
  23045. this._lastObjectRendered = null;
  23046. };
  23047. Object.defineProperty(AbstractRenderer.prototype, "backgroundColor", {
  23048. /**
  23049. * The background color to fill if not transparent
  23050. *
  23051. * @member {number}
  23052. */
  23053. get: function () {
  23054. return this._backgroundColor;
  23055. },
  23056. set: function (value) {
  23057. this._backgroundColor = value;
  23058. this._backgroundColorString = hex2string(value);
  23059. hex2rgb(value, this._backgroundColorRgba);
  23060. },
  23061. enumerable: false,
  23062. configurable: true
  23063. });
  23064. Object.defineProperty(AbstractRenderer.prototype, "backgroundAlpha", {
  23065. /**
  23066. * The background color alpha. Setting this to 0 will make the canvas transparent.
  23067. *
  23068. * @member {number}
  23069. */
  23070. get: function () {
  23071. return this._backgroundColorRgba[3];
  23072. },
  23073. set: function (value) {
  23074. this._backgroundColorRgba[3] = value;
  23075. },
  23076. enumerable: false,
  23077. configurable: true
  23078. });
  23079. return AbstractRenderer;
  23080. }(eventemitter3));
  23081. var GLBuffer = /** @class */ (function () {
  23082. function GLBuffer(buffer) {
  23083. this.buffer = buffer || null;
  23084. this.updateID = -1;
  23085. this.byteLength = -1;
  23086. this.refCount = 0;
  23087. }
  23088. return GLBuffer;
  23089. }());
  23090. /**
  23091. * System plugin to the renderer to manage buffers.
  23092. *
  23093. * WebGL uses Buffers as a way to store objects to the GPU.
  23094. * This system makes working with them a lot easier.
  23095. *
  23096. * Buffers are used in three main places in WebGL
  23097. * - geometry information
  23098. * - Uniform information (via uniform buffer objects - a WebGL 2 only feature)
  23099. * - Transform feedback information. (WebGL 2 only feature)
  23100. *
  23101. * This system will handle the binding of buffers to the GPU as well as uploading
  23102. * them. With this system, you never need to work directly with GPU buffers, but instead work with
  23103. * the PIXI.Buffer class.
  23104. *
  23105. *
  23106. * @class
  23107. * @memberof PIXI
  23108. */
  23109. var BufferSystem = /** @class */ (function () {
  23110. /**
  23111. * @param {PIXI.Renderer} renderer - The renderer this System works for.
  23112. */
  23113. function BufferSystem(renderer) {
  23114. this.renderer = renderer;
  23115. this.managedBuffers = {};
  23116. this.boundBufferBases = {};
  23117. }
  23118. /**
  23119. * @ignore
  23120. */
  23121. BufferSystem.prototype.destroy = function () {
  23122. this.renderer = null;
  23123. };
  23124. /**
  23125. * Sets up the renderer context and necessary buffers.
  23126. */
  23127. BufferSystem.prototype.contextChange = function () {
  23128. this.disposeAll(true);
  23129. this.gl = this.renderer.gl;
  23130. // TODO fill out...
  23131. this.CONTEXT_UID = this.renderer.CONTEXT_UID;
  23132. };
  23133. /**
  23134. * This binds specified buffer. On first run, it will create the webGL buffers for the context too
  23135. *
  23136. * @param buffer - the buffer to bind to the renderer
  23137. */
  23138. BufferSystem.prototype.bind = function (buffer) {
  23139. var _a = this, gl = _a.gl, CONTEXT_UID = _a.CONTEXT_UID;
  23140. var glBuffer = buffer._glBuffers[CONTEXT_UID] || this.createGLBuffer(buffer);
  23141. gl.bindBuffer(buffer.type, glBuffer.buffer);
  23142. };
  23143. /**
  23144. * Binds an uniform buffer to at the given index.
  23145. *
  23146. * A cache is used so a buffer will not be bound again if already bound.
  23147. *
  23148. * @param buffer - the buffer to bind
  23149. * @param index - the base index to bind it to.
  23150. */
  23151. BufferSystem.prototype.bindBufferBase = function (buffer, index) {
  23152. var _a = this, gl = _a.gl, CONTEXT_UID = _a.CONTEXT_UID;
  23153. if (this.boundBufferBases[index] !== buffer) {
  23154. var glBuffer = buffer._glBuffers[CONTEXT_UID] || this.createGLBuffer(buffer);
  23155. this.boundBufferBases[index] = buffer;
  23156. gl.bindBufferBase(gl.UNIFORM_BUFFER, index, glBuffer.buffer);
  23157. }
  23158. };
  23159. /**
  23160. * Binds a buffer whilst also binding its range.
  23161. * This will make the buffer start from the offset supplied rather than 0 when it is read.
  23162. *
  23163. * @param buffer - the buffer to bind
  23164. * @param index - the base index to bind at, defaults to 0
  23165. * @param offset - the offset to bind at (this is blocks of 256). 0 = 0, 1 = 256, 2 = 512 etc
  23166. */
  23167. BufferSystem.prototype.bindBufferRange = function (buffer, index, offset) {
  23168. var _a = this, gl = _a.gl, CONTEXT_UID = _a.CONTEXT_UID;
  23169. offset = offset || 0;
  23170. var glBuffer = buffer._glBuffers[CONTEXT_UID] || this.createGLBuffer(buffer);
  23171. gl.bindBufferRange(gl.UNIFORM_BUFFER, index || 0, glBuffer.buffer, offset * 256, 256);
  23172. };
  23173. /**
  23174. * Will ensure sure the the data in the buffer is uploaded to the GPU.
  23175. *
  23176. * @param {PIXI.Buffer} buffer - the buffer to update
  23177. */
  23178. BufferSystem.prototype.update = function (buffer) {
  23179. var _a = this, gl = _a.gl, CONTEXT_UID = _a.CONTEXT_UID;
  23180. var glBuffer = buffer._glBuffers[CONTEXT_UID];
  23181. if (buffer._updateID === glBuffer.updateID) {
  23182. return;
  23183. }
  23184. glBuffer.updateID = buffer._updateID;
  23185. gl.bindBuffer(buffer.type, glBuffer.buffer);
  23186. if (glBuffer.byteLength >= buffer.data.byteLength) {
  23187. // offset is always zero for now!
  23188. gl.bufferSubData(buffer.type, 0, buffer.data);
  23189. }
  23190. else {
  23191. var drawType = buffer.static ? gl.STATIC_DRAW : gl.DYNAMIC_DRAW;
  23192. glBuffer.byteLength = buffer.data.byteLength;
  23193. gl.bufferData(buffer.type, buffer.data, drawType);
  23194. }
  23195. };
  23196. /**
  23197. * Disposes buffer
  23198. * @param {PIXI.Buffer} buffer - buffer with data
  23199. * @param {boolean} [contextLost=false] - If context was lost, we suppress deleteVertexArray
  23200. */
  23201. BufferSystem.prototype.dispose = function (buffer, contextLost) {
  23202. if (!this.managedBuffers[buffer.id]) {
  23203. return;
  23204. }
  23205. delete this.managedBuffers[buffer.id];
  23206. var glBuffer = buffer._glBuffers[this.CONTEXT_UID];
  23207. var gl = this.gl;
  23208. buffer.disposeRunner.remove(this);
  23209. if (!glBuffer) {
  23210. return;
  23211. }
  23212. if (!contextLost) {
  23213. gl.deleteBuffer(glBuffer.buffer);
  23214. }
  23215. delete buffer._glBuffers[this.CONTEXT_UID];
  23216. };
  23217. /**
  23218. * dispose all WebGL resources of all managed buffers
  23219. * @param {boolean} [contextLost=false] - If context was lost, we suppress `gl.delete` calls
  23220. */
  23221. BufferSystem.prototype.disposeAll = function (contextLost) {
  23222. var all = Object.keys(this.managedBuffers);
  23223. for (var i = 0; i < all.length; i++) {
  23224. this.dispose(this.managedBuffers[all[i]], contextLost);
  23225. }
  23226. };
  23227. /**
  23228. * creates and attaches a GLBuffer object tied to the current context.
  23229. * @protected
  23230. */
  23231. BufferSystem.prototype.createGLBuffer = function (buffer) {
  23232. var _a = this, CONTEXT_UID = _a.CONTEXT_UID, gl = _a.gl;
  23233. buffer._glBuffers[CONTEXT_UID] = new GLBuffer(gl.createBuffer());
  23234. this.managedBuffers[buffer.id] = buffer;
  23235. buffer.disposeRunner.add(this);
  23236. return buffer._glBuffers[CONTEXT_UID];
  23237. };
  23238. return BufferSystem;
  23239. }());
  23240. /**
  23241. * The Renderer draws the scene and all its content onto a WebGL enabled canvas.
  23242. *
  23243. * This renderer should be used for browsers that support WebGL.
  23244. *
  23245. * This renderer works by automatically managing WebGLBatchesm, so no need for Sprite Batches or Sprite Clouds.
  23246. * Don't forget to add the view to your DOM or you will not see anything!
  23247. *
  23248. * Renderer is composed of systems that manage specific tasks. The following systems are added by default
  23249. * whenever you create a renderer:
  23250. *
  23251. * | System | Description |
  23252. * | ------------------------------------ | ----------------------------------------------------------------------------- |
  23253. * | {@link PIXI.BatchSystem} | This manages object renderers that defer rendering until a flush. |
  23254. * | {@link PIXI.ContextSystem} | This manages the WebGL context and extensions. |
  23255. * | {@link PIXI.EventSystem} | This manages UI events. |
  23256. * | {@link PIXI.FilterSystem} | This manages the filtering pipeline for post-processing effects. |
  23257. * | {@link PIXI.FramebufferSystem} | This manages framebuffers, which are used for offscreen rendering. |
  23258. * | {@link PIXI.GeometrySystem} | This manages geometries & buffers, which are used to draw object meshes. |
  23259. * | {@link PIXI.MaskSystem} | This manages masking operations. |
  23260. * | {@link PIXI.ProjectionSystem} | This manages the `projectionMatrix`, used by shaders to get NDC coordinates. |
  23261. * | {@link PIXI.RenderTextureSystem} | This manages render-textures, which are an abstraction over framebuffers. |
  23262. * | {@link PIXI.ScissorSystem} | This handles scissor masking, and is used internally by {@link MaskSystem} |
  23263. * | {@link PIXI.ShaderSystem} | This manages shaders, programs that run on the GPU to calculate 'em pixels. |
  23264. * | {@link PIXI.StateSystem} | This manages the WebGL state variables like blend mode, depth testing, etc. |
  23265. * | {@link PIXI.StencilSystem} | This handles stencil masking, and is used internally by {@link MaskSystem} |
  23266. * | {@link PIXI.TextureSystem} | This manages textures and their resources on the GPU. |
  23267. * | {@link PIXI.TextureGCSystem} | This will automatically remove textures from the GPU if they are not used. |
  23268. *
  23269. * The breadth of the API surface provided by the renderer is contained within these systems.
  23270. *
  23271. * @class
  23272. * @memberof PIXI
  23273. * @extends PIXI.AbstractRenderer
  23274. */
  23275. var Renderer = /** @class */ (function (_super) {
  23276. __extends$2(Renderer, _super);
  23277. /**
  23278. * @param [options] - The optional renderer parameters.
  23279. * @param {number} [options.width=800] - The width of the screen.
  23280. * @param {number} [options.height=600] - The height of the screen.
  23281. * @param {HTMLCanvasElement} [options.view] - The canvas to use as a view, optional.
  23282. * @param {boolean} [options.useContextAlpha=true] - Pass-through value for canvas' context `alpha` property.
  23283. * If you want to set transparency, please use `backgroundAlpha`. This option is for cases where the
  23284. * canvas needs to be opaque, possibly for performance reasons on some older devices.
  23285. * @param {boolean} [options.autoDensity=false] - Resizes renderer view in CSS pixels to allow for
  23286. * resolutions other than 1.
  23287. * @param {boolean} [options.antialias=false] - Sets antialias. If not available natively then FXAA
  23288. * antialiasing is used.
  23289. * @param {number} [options.resolution=PIXI.settings.RESOLUTION] - The resolution / device pixel ratio of the renderer.
  23290. * @param {boolean} [options.clearBeforeRender=true] - This sets if the renderer will clear
  23291. * the canvas or not before the new render pass. If you wish to set this to false, you *must* set
  23292. * preserveDrawingBuffer to `true`.
  23293. * @param {boolean} [options.preserveDrawingBuffer=false] - Enables drawing buffer preservation,
  23294. * enable this if you need to call toDataUrl on the WebGL context.
  23295. * @param {number} [options.backgroundColor=0x000000] - The background color of the rendered area
  23296. * (shown if not transparent).
  23297. * @param {number} [options.backgroundAlpha=1] - Value from 0 (fully transparent) to 1 (fully opaque).
  23298. * @param {string} [options.powerPreference] - Parameter passed to WebGL context, set to "high-performance"
  23299. * for devices with dual graphics card.
  23300. * @param {object} [options.context] - If WebGL context already exists, all parameters must be taken from it.
  23301. * @public
  23302. */
  23303. function Renderer(options) {
  23304. var _this = _super.call(this, exports.RENDERER_TYPE.WEBGL, options) || this;
  23305. // the options will have been modified here in the super constructor with pixi's default settings..
  23306. options = _this.options;
  23307. /**
  23308. * WebGL context, set by the contextSystem (this.context)
  23309. *
  23310. * @readonly
  23311. * @member {WebGLRenderingContext}
  23312. */
  23313. _this.gl = null;
  23314. _this.CONTEXT_UID = 0;
  23315. /**
  23316. * Internal signal instances of **runner**, these
  23317. * are assigned to each system created.
  23318. * @see PIXI.Runner
  23319. * @name runners
  23320. * @private
  23321. * @type {object}
  23322. * @readonly
  23323. * @property {PIXI.Runner} destroy - Destroy runner
  23324. * @property {PIXI.Runner} contextChange - Context change runner
  23325. * @property {PIXI.Runner} reset - Reset runner
  23326. * @property {PIXI.Runner} update - Update runner
  23327. * @property {PIXI.Runner} postrender - Post-render runner
  23328. * @property {PIXI.Runner} prerender - Pre-render runner
  23329. * @property {PIXI.Runner} resize - Resize runner
  23330. */
  23331. _this.runners = {
  23332. destroy: new Runner('destroy'),
  23333. contextChange: new Runner('contextChange'),
  23334. reset: new Runner('reset'),
  23335. update: new Runner('update'),
  23336. postrender: new Runner('postrender'),
  23337. prerender: new Runner('prerender'),
  23338. resize: new Runner('resize'),
  23339. };
  23340. _this.runners.contextChange.add(_this);
  23341. /**
  23342. * Global uniforms
  23343. * @member {PIXI.UniformGroup}
  23344. */
  23345. _this.globalUniforms = new UniformGroup({
  23346. projectionMatrix: new Matrix(),
  23347. }, true);
  23348. /**
  23349. * Mask system instance
  23350. * @member {PIXI.MaskSystem} mask
  23351. * @memberof PIXI.Renderer#
  23352. * @readonly
  23353. */
  23354. _this.addSystem(MaskSystem, 'mask')
  23355. /**
  23356. * Context system instance
  23357. * @member {PIXI.ContextSystem} context
  23358. * @memberof PIXI.Renderer#
  23359. * @readonly
  23360. */
  23361. .addSystem(ContextSystem, 'context')
  23362. /**
  23363. * State system instance
  23364. * @member {PIXI.StateSystem} state
  23365. * @memberof PIXI.Renderer#
  23366. * @readonly
  23367. */
  23368. .addSystem(StateSystem, 'state')
  23369. /**
  23370. * Shader system instance
  23371. * @member {PIXI.ShaderSystem} shader
  23372. * @memberof PIXI.Renderer#
  23373. * @readonly
  23374. */
  23375. .addSystem(ShaderSystem, 'shader')
  23376. /**
  23377. * Texture system instance
  23378. * @member {PIXI.TextureSystem} texture
  23379. * @memberof PIXI.Renderer#
  23380. * @readonly
  23381. */
  23382. .addSystem(TextureSystem, 'texture')
  23383. /**
  23384. * Geometry system instance
  23385. * @member {PIXI.systems.BufferSystem} buffer
  23386. * @memberof PIXI.Renderer#
  23387. * @readonly
  23388. */
  23389. .addSystem(BufferSystem, 'buffer')
  23390. /**
  23391. * Geometry system instance
  23392. * @member {PIXI.systems.GeometrySystem} geometry
  23393. * @memberof PIXI.Renderer#
  23394. * @readonly
  23395. */
  23396. .addSystem(GeometrySystem, 'geometry')
  23397. /**
  23398. * Framebuffer system instance
  23399. * @member {PIXI.FramebufferSystem} framebuffer
  23400. * @memberof PIXI.Renderer#
  23401. * @readonly
  23402. */
  23403. .addSystem(FramebufferSystem, 'framebuffer')
  23404. /**
  23405. * Scissor system instance
  23406. * @member {PIXI.ScissorSystem} scissor
  23407. * @memberof PIXI.Renderer#
  23408. * @readonly
  23409. */
  23410. .addSystem(ScissorSystem, 'scissor')
  23411. /**
  23412. * Stencil system instance
  23413. * @member {PIXI.StencilSystem} stencil
  23414. * @memberof PIXI.Renderer#
  23415. * @readonly
  23416. */
  23417. .addSystem(StencilSystem, 'stencil')
  23418. /**
  23419. * Projection system instance
  23420. * @member {PIXI.ProjectionSystem} projection
  23421. * @memberof PIXI.Renderer#
  23422. * @readonly
  23423. */
  23424. .addSystem(ProjectionSystem, 'projection')
  23425. /**
  23426. * Texture garbage collector system instance
  23427. * @member {PIXI.TextureGCSystem} textureGC
  23428. * @memberof PIXI.Renderer#
  23429. * @readonly
  23430. */
  23431. .addSystem(TextureGCSystem, 'textureGC')
  23432. /**
  23433. * Filter system instance
  23434. * @member {PIXI.FilterSystem} filter
  23435. * @memberof PIXI.Renderer#
  23436. * @readonly
  23437. */
  23438. .addSystem(FilterSystem, 'filter')
  23439. /**
  23440. * RenderTexture system instance
  23441. * @member {PIXI.RenderTextureSystem} renderTexture
  23442. * @memberof PIXI.Renderer#
  23443. * @readonly
  23444. */
  23445. .addSystem(RenderTextureSystem, 'renderTexture')
  23446. /**
  23447. * Batch system instance
  23448. * @member {PIXI.BatchSystem} batch
  23449. * @memberof PIXI.Renderer#
  23450. * @readonly
  23451. */
  23452. .addSystem(BatchSystem, 'batch');
  23453. _this.initPlugins(Renderer.__plugins);
  23454. /**
  23455. * The number of msaa samples of the canvas.
  23456. * @member {PIXI.MSAA_QUALITY}
  23457. * @readonly
  23458. */
  23459. _this.multisample = undefined;
  23460. /*
  23461. * The options passed in to create a new WebGL context.
  23462. */
  23463. if (options.context) {
  23464. _this.context.initFromContext(options.context);
  23465. }
  23466. else {
  23467. _this.context.initFromOptions({
  23468. alpha: !!_this.useContextAlpha,
  23469. antialias: options.antialias,
  23470. premultipliedAlpha: _this.useContextAlpha && _this.useContextAlpha !== 'notMultiplied',
  23471. stencil: true,
  23472. preserveDrawingBuffer: options.preserveDrawingBuffer,
  23473. powerPreference: _this.options.powerPreference,
  23474. });
  23475. }
  23476. /**
  23477. * Flag if we are rendering to the screen vs renderTexture
  23478. * @member {boolean}
  23479. * @readonly
  23480. * @default true
  23481. */
  23482. _this.renderingToScreen = true;
  23483. sayHello(_this.context.webGLVersion === 2 ? 'WebGL 2' : 'WebGL 1');
  23484. _this.resize(_this.options.width, _this.options.height);
  23485. return _this;
  23486. }
  23487. /**
  23488. * Create renderer if WebGL is available. Overrideable
  23489. * by the **@pixi/canvas-renderer** package to allow fallback.
  23490. * throws error if WebGL is not available.
  23491. * @static
  23492. * @private
  23493. */
  23494. Renderer.create = function (options) {
  23495. if (isWebGLSupported()) {
  23496. return new Renderer(options);
  23497. }
  23498. throw new Error('WebGL unsupported in this browser, use "pixi.js-legacy" for fallback canvas2d support.');
  23499. };
  23500. Renderer.prototype.contextChange = function () {
  23501. var gl = this.gl;
  23502. var samples;
  23503. if (this.context.webGLVersion === 1) {
  23504. var framebuffer = gl.getParameter(gl.FRAMEBUFFER_BINDING);
  23505. gl.bindFramebuffer(gl.FRAMEBUFFER, null);
  23506. samples = gl.getParameter(gl.SAMPLES);
  23507. gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);
  23508. }
  23509. else {
  23510. var framebuffer = gl.getParameter(gl.DRAW_FRAMEBUFFER_BINDING);
  23511. gl.bindFramebuffer(gl.DRAW_FRAMEBUFFER, null);
  23512. samples = gl.getParameter(gl.SAMPLES);
  23513. gl.bindFramebuffer(gl.DRAW_FRAMEBUFFER, framebuffer);
  23514. }
  23515. if (samples >= exports.MSAA_QUALITY.HIGH) {
  23516. this.multisample = exports.MSAA_QUALITY.HIGH;
  23517. }
  23518. else if (samples >= exports.MSAA_QUALITY.MEDIUM) {
  23519. this.multisample = exports.MSAA_QUALITY.MEDIUM;
  23520. }
  23521. else if (samples >= exports.MSAA_QUALITY.LOW) {
  23522. this.multisample = exports.MSAA_QUALITY.LOW;
  23523. }
  23524. else {
  23525. this.multisample = exports.MSAA_QUALITY.NONE;
  23526. }
  23527. };
  23528. /**
  23529. * Add a new system to the renderer.
  23530. * @param ClassRef - Class reference
  23531. * @param [name] - Property name for system, if not specified
  23532. * will use a static `name` property on the class itself. This
  23533. * name will be assigned as s property on the Renderer so make
  23534. * sure it doesn't collide with properties on Renderer.
  23535. * @return {PIXI.Renderer} Return instance of renderer
  23536. */
  23537. Renderer.prototype.addSystem = function (ClassRef, name) {
  23538. var system = new ClassRef(this);
  23539. if (this[name]) {
  23540. throw new Error("Whoops! The name \"" + name + "\" is already in use");
  23541. }
  23542. this[name] = system;
  23543. for (var i in this.runners) {
  23544. this.runners[i].add(system);
  23545. }
  23546. /**
  23547. * Fired after rendering finishes.
  23548. *
  23549. * @event PIXI.Renderer#postrender
  23550. */
  23551. /**
  23552. * Fired before rendering starts.
  23553. *
  23554. * @event PIXI.Renderer#prerender
  23555. */
  23556. /**
  23557. * Fired when the WebGL context is set.
  23558. *
  23559. * @event PIXI.Renderer#context
  23560. * @param {WebGLRenderingContext} gl - WebGL context.
  23561. */
  23562. return this;
  23563. };
  23564. /**
  23565. * @ignore
  23566. */
  23567. Renderer.prototype.render = function (displayObject, options) {
  23568. var renderTexture;
  23569. var clear;
  23570. var transform;
  23571. var skipUpdateTransform;
  23572. if (options) {
  23573. if (options instanceof RenderTexture) {
  23574. deprecation('6.0.0', 'Renderer#render arguments changed, use options instead.');
  23575. /* eslint-disable prefer-rest-params */
  23576. renderTexture = options;
  23577. clear = arguments[2];
  23578. transform = arguments[3];
  23579. skipUpdateTransform = arguments[4];
  23580. /* eslint-enable prefer-rest-params */
  23581. }
  23582. else {
  23583. renderTexture = options.renderTexture;
  23584. clear = options.clear;
  23585. transform = options.transform;
  23586. skipUpdateTransform = options.skipUpdateTransform;
  23587. }
  23588. }
  23589. // can be handy to know!
  23590. this.renderingToScreen = !renderTexture;
  23591. this.runners.prerender.emit();
  23592. this.emit('prerender');
  23593. // apply a transform at a GPU level
  23594. this.projection.transform = transform;
  23595. // no point rendering if our context has been blown up!
  23596. if (this.context.isLost) {
  23597. return;
  23598. }
  23599. if (!renderTexture) {
  23600. this._lastObjectRendered = displayObject;
  23601. }
  23602. if (!skipUpdateTransform) {
  23603. // update the scene graph
  23604. var cacheParent = displayObject.enableTempParent();
  23605. displayObject.updateTransform();
  23606. displayObject.disableTempParent(cacheParent);
  23607. // displayObject.hitArea = //TODO add a temp hit area
  23608. }
  23609. this.renderTexture.bind(renderTexture);
  23610. this.batch.currentRenderer.start();
  23611. if (clear !== undefined ? clear : this.clearBeforeRender) {
  23612. this.renderTexture.clear();
  23613. }
  23614. displayObject.render(this);
  23615. // apply transform..
  23616. this.batch.currentRenderer.flush();
  23617. if (renderTexture) {
  23618. renderTexture.baseTexture.update();
  23619. }
  23620. this.runners.postrender.emit();
  23621. // reset transform after render
  23622. this.projection.transform = null;
  23623. this.emit('postrender');
  23624. };
  23625. /**
  23626. * @override
  23627. * @ignore
  23628. */
  23629. Renderer.prototype.generateTexture = function (displayObject, options, resolution, region) {
  23630. if (options === void 0) { options = {}; }
  23631. var renderTexture = _super.prototype.generateTexture.call(this, displayObject, options, resolution, region);
  23632. this.framebuffer.blit();
  23633. return renderTexture;
  23634. };
  23635. /**
  23636. * Resizes the WebGL view to the specified width and height.
  23637. *
  23638. * @param desiredScreenWidth - The desired width of the screen.
  23639. * @param desiredScreenHeight - The desired height of the screen.
  23640. */
  23641. Renderer.prototype.resize = function (desiredScreenWidth, desiredScreenHeight) {
  23642. _super.prototype.resize.call(this, desiredScreenWidth, desiredScreenHeight);
  23643. this.runners.resize.emit(this.screen.height, this.screen.width);
  23644. };
  23645. /**
  23646. * Resets the WebGL state so you can render things however you fancy!
  23647. *
  23648. * @return {PIXI.Renderer} Returns itself.
  23649. */
  23650. Renderer.prototype.reset = function () {
  23651. this.runners.reset.emit();
  23652. return this;
  23653. };
  23654. /**
  23655. * Clear the frame buffer
  23656. */
  23657. Renderer.prototype.clear = function () {
  23658. this.renderTexture.bind();
  23659. this.renderTexture.clear();
  23660. };
  23661. /**
  23662. * Removes everything from the renderer (event listeners, spritebatch, etc...)
  23663. *
  23664. * @param [removeView=false] - Removes the Canvas element from the DOM.
  23665. * See: https://github.com/pixijs/pixi.js/issues/2233
  23666. */
  23667. Renderer.prototype.destroy = function (removeView) {
  23668. this.runners.destroy.emit();
  23669. for (var r in this.runners) {
  23670. this.runners[r].destroy();
  23671. }
  23672. // call base destroy
  23673. _super.prototype.destroy.call(this, removeView);
  23674. // TODO nullify all the managers..
  23675. this.gl = null;
  23676. };
  23677. Object.defineProperty(Renderer.prototype, "extract", {
  23678. /**
  23679. * Please use `plugins.extract` instead.
  23680. * @member {PIXI.Extract} extract
  23681. * @deprecated since 6.0.0
  23682. * @readonly
  23683. */
  23684. get: function () {
  23685. deprecation('6.0.0', 'Renderer#extract has been deprecated, please use Renderer#plugins.extract instead.');
  23686. return this.plugins.extract;
  23687. },
  23688. enumerable: false,
  23689. configurable: true
  23690. });
  23691. /**
  23692. * Adds a plugin to the renderer.
  23693. *
  23694. * @method
  23695. * @param pluginName - The name of the plugin.
  23696. * @param ctor - The constructor function or class for the plugin.
  23697. */
  23698. Renderer.registerPlugin = function (pluginName, ctor) {
  23699. Renderer.__plugins = Renderer.__plugins || {};
  23700. Renderer.__plugins[pluginName] = ctor;
  23701. };
  23702. return Renderer;
  23703. }(AbstractRenderer));
  23704. /**
  23705. * This helper function will automatically detect which renderer you should be using.
  23706. * WebGL is the preferred renderer as it is a lot faster. If WebGL is not supported by
  23707. * the browser then this function will return a canvas renderer
  23708. *
  23709. * @memberof PIXI
  23710. * @function autoDetectRenderer
  23711. * @param {object} [options] - The optional renderer parameters
  23712. * @param {number} [options.width=800] - the width of the renderers view
  23713. * @param {number} [options.height=600] - the height of the renderers view
  23714. * @param {HTMLCanvasElement} [options.view] - the canvas to use as a view, optional
  23715. * @param {boolean} [options.useContextAlpha=true] - Pass-through value for canvas' context `alpha` property.
  23716. * If you want to set transparency, please use `backgroundAlpha`. This option is for cases where the
  23717. * canvas needs to be opaque, possibly for performance reasons on some older devices.
  23718. * @param {boolean} [options.autoDensity=false] - Resizes renderer view in CSS pixels to allow for
  23719. * resolutions other than 1
  23720. * @param {boolean} [options.antialias=false] - sets antialias
  23721. * @param {boolean} [options.preserveDrawingBuffer=false] - enables drawing buffer preservation, enable this if you
  23722. * need to call toDataUrl on the webgl context
  23723. * @param {number} [options.backgroundColor=0x000000] - The background color of the rendered area
  23724. * (shown if not transparent).
  23725. * @param {number} [options.backgroundAlpha=1] - Value from 0 (fully transparent) to 1 (fully opaque).
  23726. * @param {boolean} [options.clearBeforeRender=true] - This sets if the renderer will clear the canvas or
  23727. * not before the new render pass.
  23728. * @param {number} [options.resolution=PIXI.settings.RESOLUTION] - The resolution / device pixel ratio of the renderer.
  23729. * @param {boolean} [options.forceCanvas=false] - prevents selection of WebGL renderer, even if such is present, this
  23730. * option only is available when using **pixi.js-legacy** or **@pixi/canvas-renderer** modules, otherwise
  23731. * it is ignored.
  23732. * @param {string} [options.powerPreference] - Parameter passed to webgl context, set to "high-performance"
  23733. * for devices with dual graphics card **webgl only**
  23734. * @return {PIXI.Renderer|PIXI.CanvasRenderer} Returns WebGL renderer if available, otherwise CanvasRenderer
  23735. */
  23736. function autoDetectRenderer(options) {
  23737. return Renderer.create(options);
  23738. }
  23739. var $defaultVertex = "attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\n\nuniform mat3 projectionMatrix;\n\nvarying vec2 vTextureCoord;\n\nvoid main(void)\n{\n gl_Position = vec4((projectionMatrix * vec3(aVertexPosition, 1.0)).xy, 0.0, 1.0);\n vTextureCoord = aTextureCoord;\n}";
  23740. var $defaultFilterVertex = "attribute vec2 aVertexPosition;\n\nuniform mat3 projectionMatrix;\n\nvarying vec2 vTextureCoord;\n\nuniform vec4 inputSize;\nuniform vec4 outputFrame;\n\nvec4 filterVertexPosition( void )\n{\n vec2 position = aVertexPosition * max(outputFrame.zw, vec2(0.)) + outputFrame.xy;\n\n return vec4((projectionMatrix * vec3(position, 1.0)).xy, 0.0, 1.0);\n}\n\nvec2 filterTextureCoord( void )\n{\n return aVertexPosition * (outputFrame.zw * inputSize.zw);\n}\n\nvoid main(void)\n{\n gl_Position = filterVertexPosition();\n vTextureCoord = filterTextureCoord();\n}\n";
  23741. /**
  23742. * Default vertex shader
  23743. * @memberof PIXI
  23744. * @member {string} defaultVertex
  23745. */
  23746. /**
  23747. * Default filter vertex shader
  23748. * @memberof PIXI
  23749. * @member {string} defaultFilterVertex
  23750. */
  23751. // NOTE: This black magic is so that @microsoft/api-extractor does not complain! This explicitly specifies the types
  23752. // of defaultVertex, defaultFilterVertex.
  23753. var defaultVertex$2 = $defaultVertex;
  23754. var defaultFilterVertex = $defaultFilterVertex;
  23755. /**
  23756. * Use the ISystem interface instead.
  23757. * @deprecated since 6.1.0
  23758. * @memberof PIXI
  23759. */
  23760. var System = /** @class */ (function () {
  23761. /**
  23762. * @param renderer - Reference to Renderer
  23763. */
  23764. function System(renderer) {
  23765. deprecation('6.1.0', 'System class is deprecated, implemement ISystem interface instead.');
  23766. this.renderer = renderer;
  23767. }
  23768. /** Destroy and don't use after this. */
  23769. System.prototype.destroy = function () {
  23770. this.renderer = null;
  23771. };
  23772. return System;
  23773. }());
  23774. /**
  23775. * Used by the batcher to draw batches.
  23776. * Each one of these contains all information required to draw a bound geometry.
  23777. *
  23778. * @class
  23779. * @memberof PIXI
  23780. */
  23781. var BatchDrawCall = /** @class */ (function () {
  23782. function BatchDrawCall() {
  23783. this.texArray = null;
  23784. this.blend = 0;
  23785. this.type = exports.DRAW_MODES.TRIANGLES;
  23786. this.start = 0;
  23787. this.size = 0;
  23788. /**
  23789. * data for uniforms or custom webgl state
  23790. * @member {object}
  23791. */
  23792. this.data = null;
  23793. }
  23794. return BatchDrawCall;
  23795. }());
  23796. /**
  23797. * Used by the batcher to build texture batches.
  23798. * Holds list of textures and their respective locations.
  23799. *
  23800. * @class
  23801. * @memberof PIXI
  23802. */
  23803. var BatchTextureArray = /** @class */ (function () {
  23804. function BatchTextureArray() {
  23805. /**
  23806. * inside textures array
  23807. * @member {PIXI.BaseTexture[]}
  23808. */
  23809. this.elements = [];
  23810. /**
  23811. * Respective locations for textures
  23812. * @member {number[]}
  23813. */
  23814. this.ids = [];
  23815. /**
  23816. * number of filled elements
  23817. * @member {number}
  23818. */
  23819. this.count = 0;
  23820. }
  23821. BatchTextureArray.prototype.clear = function () {
  23822. for (var i = 0; i < this.count; i++) {
  23823. this.elements[i] = null;
  23824. }
  23825. this.count = 0;
  23826. };
  23827. return BatchTextureArray;
  23828. }());
  23829. /**
  23830. * Flexible wrapper around `ArrayBuffer` that also provides typed array views on demand.
  23831. *
  23832. * @class
  23833. * @memberof PIXI
  23834. */
  23835. var ViewableBuffer = /** @class */ (function () {
  23836. function ViewableBuffer(sizeOrBuffer) {
  23837. if (typeof sizeOrBuffer === 'number') {
  23838. /**
  23839. * Underlying `ArrayBuffer` that holds all the data and is of capacity `this.size`.
  23840. *
  23841. * @member {ArrayBuffer}
  23842. */
  23843. this.rawBinaryData = new ArrayBuffer(sizeOrBuffer);
  23844. }
  23845. else if (sizeOrBuffer instanceof Uint8Array) {
  23846. this.rawBinaryData = sizeOrBuffer.buffer;
  23847. }
  23848. else {
  23849. this.rawBinaryData = sizeOrBuffer;
  23850. }
  23851. /**
  23852. * View on the raw binary data as a `Uint32Array`.
  23853. *
  23854. * @member {Uint32Array}
  23855. */
  23856. this.uint32View = new Uint32Array(this.rawBinaryData);
  23857. /**
  23858. * View on the raw binary data as a `Float32Array`.
  23859. *
  23860. * @member {Float32Array}
  23861. */
  23862. this.float32View = new Float32Array(this.rawBinaryData);
  23863. }
  23864. Object.defineProperty(ViewableBuffer.prototype, "int8View", {
  23865. /**
  23866. * View on the raw binary data as a `Int8Array`.
  23867. *
  23868. * @member {Int8Array}
  23869. */
  23870. get: function () {
  23871. if (!this._int8View) {
  23872. this._int8View = new Int8Array(this.rawBinaryData);
  23873. }
  23874. return this._int8View;
  23875. },
  23876. enumerable: false,
  23877. configurable: true
  23878. });
  23879. Object.defineProperty(ViewableBuffer.prototype, "uint8View", {
  23880. /**
  23881. * View on the raw binary data as a `Uint8Array`.
  23882. *
  23883. * @member {Uint8Array}
  23884. */
  23885. get: function () {
  23886. if (!this._uint8View) {
  23887. this._uint8View = new Uint8Array(this.rawBinaryData);
  23888. }
  23889. return this._uint8View;
  23890. },
  23891. enumerable: false,
  23892. configurable: true
  23893. });
  23894. Object.defineProperty(ViewableBuffer.prototype, "int16View", {
  23895. /**
  23896. * View on the raw binary data as a `Int16Array`.
  23897. *
  23898. * @member {Int16Array}
  23899. */
  23900. get: function () {
  23901. if (!this._int16View) {
  23902. this._int16View = new Int16Array(this.rawBinaryData);
  23903. }
  23904. return this._int16View;
  23905. },
  23906. enumerable: false,
  23907. configurable: true
  23908. });
  23909. Object.defineProperty(ViewableBuffer.prototype, "uint16View", {
  23910. /**
  23911. * View on the raw binary data as a `Uint16Array`.
  23912. *
  23913. * @member {Uint16Array}
  23914. */
  23915. get: function () {
  23916. if (!this._uint16View) {
  23917. this._uint16View = new Uint16Array(this.rawBinaryData);
  23918. }
  23919. return this._uint16View;
  23920. },
  23921. enumerable: false,
  23922. configurable: true
  23923. });
  23924. Object.defineProperty(ViewableBuffer.prototype, "int32View", {
  23925. /**
  23926. * View on the raw binary data as a `Int32Array`.
  23927. *
  23928. * @member {Int32Array}
  23929. */
  23930. get: function () {
  23931. if (!this._int32View) {
  23932. this._int32View = new Int32Array(this.rawBinaryData);
  23933. }
  23934. return this._int32View;
  23935. },
  23936. enumerable: false,
  23937. configurable: true
  23938. });
  23939. /**
  23940. * Returns the view of the given type.
  23941. *
  23942. * @param {string} type - One of `int8`, `uint8`, `int16`,
  23943. * `uint16`, `int32`, `uint32`, and `float32`.
  23944. * @return {object} typed array of given type
  23945. */
  23946. ViewableBuffer.prototype.view = function (type) {
  23947. return this[type + "View"];
  23948. };
  23949. /**
  23950. * Destroys all buffer references. Do not use after calling
  23951. * this.
  23952. */
  23953. ViewableBuffer.prototype.destroy = function () {
  23954. this.rawBinaryData = null;
  23955. this._int8View = null;
  23956. this._uint8View = null;
  23957. this._int16View = null;
  23958. this._uint16View = null;
  23959. this._int32View = null;
  23960. this.uint32View = null;
  23961. this.float32View = null;
  23962. };
  23963. ViewableBuffer.sizeOf = function (type) {
  23964. switch (type) {
  23965. case 'int8':
  23966. case 'uint8':
  23967. return 1;
  23968. case 'int16':
  23969. case 'uint16':
  23970. return 2;
  23971. case 'int32':
  23972. case 'uint32':
  23973. case 'float32':
  23974. return 4;
  23975. default:
  23976. throw new Error(type + " isn't a valid view type");
  23977. }
  23978. };
  23979. return ViewableBuffer;
  23980. }());
  23981. /**
  23982. * Renderer dedicated to drawing and batching sprites.
  23983. *
  23984. * This is the default batch renderer. It buffers objects
  23985. * with texture-based geometries and renders them in
  23986. * batches. It uploads multiple textures to the GPU to
  23987. * reduce to the number of draw calls.
  23988. *
  23989. * @class
  23990. * @protected
  23991. * @memberof PIXI
  23992. * @extends PIXI.ObjectRenderer
  23993. */
  23994. var AbstractBatchRenderer = /** @class */ (function (_super) {
  23995. __extends$2(AbstractBatchRenderer, _super);
  23996. /**
  23997. * This will hook onto the renderer's `contextChange`
  23998. * and `prerender` signals.
  23999. *
  24000. * @param {PIXI.Renderer} renderer - The renderer this works for.
  24001. */
  24002. function AbstractBatchRenderer(renderer) {
  24003. var _this = _super.call(this, renderer) || this;
  24004. /**
  24005. * This is used to generate a shader that can
  24006. * color each vertex based on a `aTextureId`
  24007. * attribute that points to an texture in `uSampler`.
  24008. *
  24009. * This enables the objects with different textures
  24010. * to be drawn in the same draw call.
  24011. *
  24012. * You can customize your shader by creating your
  24013. * custom shader generator.
  24014. *
  24015. * @member {PIXI.BatchShaderGenerator}
  24016. * @protected
  24017. */
  24018. _this.shaderGenerator = null;
  24019. /**
  24020. * The class that represents the geometry of objects
  24021. * that are going to be batched with this.
  24022. *
  24023. * @member {object}
  24024. * @default PIXI.BatchGeometry
  24025. * @protected
  24026. */
  24027. _this.geometryClass = null;
  24028. /**
  24029. * Size of data being buffered per vertex in the
  24030. * attribute buffers (in floats). By default, the
  24031. * batch-renderer plugin uses 6:
  24032. *
  24033. * | aVertexPosition | 2 |
  24034. * |-----------------|---|
  24035. * | aTextureCoords | 2 |
  24036. * | aColor | 1 |
  24037. * | aTextureId | 1 |
  24038. *
  24039. * @member {number}
  24040. * @readonly
  24041. */
  24042. _this.vertexSize = null;
  24043. /**
  24044. * The WebGL state in which this renderer will work.
  24045. *
  24046. * @member {PIXI.State}
  24047. * @readonly
  24048. */
  24049. _this.state = State.for2d();
  24050. /**
  24051. * The number of bufferable objects before a flush
  24052. * occurs automatically.
  24053. *
  24054. * @member {number}
  24055. * @default settings.SPRITE_BATCH_SIZE * 4
  24056. */
  24057. _this.size = settings.SPRITE_BATCH_SIZE * 4;
  24058. /**
  24059. * Total count of all vertices used by the currently
  24060. * buffered objects.
  24061. *
  24062. * @member {number}
  24063. * @private
  24064. */
  24065. _this._vertexCount = 0;
  24066. /**
  24067. * Total count of all indices used by the currently
  24068. * buffered objects.
  24069. *
  24070. * @member {number}
  24071. * @private
  24072. */
  24073. _this._indexCount = 0;
  24074. /**
  24075. * Buffer of objects that are yet to be rendered.
  24076. *
  24077. * @member {PIXI.DisplayObject[]}
  24078. * @private
  24079. */
  24080. _this._bufferedElements = [];
  24081. /**
  24082. * Data for texture batch builder, helps to save a bit of CPU on a pass.
  24083. * @type {PIXI.BaseTexture[]}
  24084. * @private
  24085. */
  24086. _this._bufferedTextures = [];
  24087. /**
  24088. * Number of elements that are buffered and are
  24089. * waiting to be flushed.
  24090. *
  24091. * @member {number}
  24092. * @private
  24093. */
  24094. _this._bufferSize = 0;
  24095. /**
  24096. * This shader is generated by `this.shaderGenerator`.
  24097. *
  24098. * It is generated specifically to handle the required
  24099. * number of textures being batched together.
  24100. *
  24101. * @member {PIXI.Shader}
  24102. * @protected
  24103. */
  24104. _this._shader = null;
  24105. /**
  24106. * Pool of `this.geometryClass` geometry objects
  24107. * that store buffers. They are used to pass data
  24108. * to the shader on each draw call.
  24109. *
  24110. * These are never re-allocated again, unless a
  24111. * context change occurs; however, the pool may
  24112. * be expanded if required.
  24113. *
  24114. * @member {PIXI.Geometry[]}
  24115. * @private
  24116. * @see PIXI.AbstractBatchRenderer.contextChange
  24117. */
  24118. _this._packedGeometries = [];
  24119. /**
  24120. * Size of `this._packedGeometries`. It can be expanded
  24121. * if more than `this._packedGeometryPoolSize` flushes
  24122. * occur in a single frame.
  24123. *
  24124. * @member {number}
  24125. * @private
  24126. */
  24127. _this._packedGeometryPoolSize = 2;
  24128. /**
  24129. * A flush may occur multiple times in a single
  24130. * frame. On iOS devices or when
  24131. * `settings.CAN_UPLOAD_SAME_BUFFER` is false, the
  24132. * batch renderer does not upload data to the same
  24133. * `WebGLBuffer` for performance reasons.
  24134. *
  24135. * This is the index into `packedGeometries` that points to
  24136. * geometry holding the most recent buffers.
  24137. *
  24138. * @member {number}
  24139. * @private
  24140. */
  24141. _this._flushId = 0;
  24142. /**
  24143. * Pool of `ViewableBuffer` objects that are sorted in
  24144. * order of increasing size. The flush method uses
  24145. * the buffer with the least size above the amount
  24146. * it requires. These are used for passing attributes.
  24147. *
  24148. * The first buffer has a size of 8; each subsequent
  24149. * buffer has double capacity of its previous.
  24150. *
  24151. * @member {PIXI.ViewableBuffer[]}
  24152. * @private
  24153. * @see PIXI.AbstractBatchRenderer#getAttributeBuffer
  24154. */
  24155. _this._aBuffers = {};
  24156. /**
  24157. * Pool of `Uint16Array` objects that are sorted in
  24158. * order of increasing size. The flush method uses
  24159. * the buffer with the least size above the amount
  24160. * it requires. These are used for passing indices.
  24161. *
  24162. * The first buffer has a size of 12; each subsequent
  24163. * buffer has double capacity of its previous.
  24164. *
  24165. * @member {Uint16Array[]}
  24166. * @private
  24167. * @see PIXI.AbstractBatchRenderer#getIndexBuffer
  24168. */
  24169. _this._iBuffers = {};
  24170. /**
  24171. * Maximum number of textures that can be uploaded to
  24172. * the GPU under the current context. It is initialized
  24173. * properly in `this.contextChange`.
  24174. *
  24175. * @member {number}
  24176. * @see PIXI.AbstractBatchRenderer#contextChange
  24177. * @readonly
  24178. */
  24179. _this.MAX_TEXTURES = 1;
  24180. _this.renderer.on('prerender', _this.onPrerender, _this);
  24181. renderer.runners.contextChange.add(_this);
  24182. _this._dcIndex = 0;
  24183. _this._aIndex = 0;
  24184. _this._iIndex = 0;
  24185. _this._attributeBuffer = null;
  24186. _this._indexBuffer = null;
  24187. _this._tempBoundTextures = [];
  24188. return _this;
  24189. }
  24190. /**
  24191. * Handles the `contextChange` signal.
  24192. *
  24193. * It calculates `this.MAX_TEXTURES` and allocating the
  24194. * packed-geometry object pool.
  24195. */
  24196. AbstractBatchRenderer.prototype.contextChange = function () {
  24197. var gl = this.renderer.gl;
  24198. if (settings.PREFER_ENV === exports.ENV.WEBGL_LEGACY) {
  24199. this.MAX_TEXTURES = 1;
  24200. }
  24201. else {
  24202. // step 1: first check max textures the GPU can handle.
  24203. this.MAX_TEXTURES = Math.min(gl.getParameter(gl.MAX_TEXTURE_IMAGE_UNITS), settings.SPRITE_MAX_TEXTURES);
  24204. // step 2: check the maximum number of if statements the shader can have too..
  24205. this.MAX_TEXTURES = checkMaxIfStatementsInShader(this.MAX_TEXTURES, gl);
  24206. }
  24207. this._shader = this.shaderGenerator.generateShader(this.MAX_TEXTURES);
  24208. // we use the second shader as the first one depending on your browser
  24209. // may omit aTextureId as it is not used by the shader so is optimized out.
  24210. for (var i = 0; i < this._packedGeometryPoolSize; i++) {
  24211. /* eslint-disable max-len */
  24212. this._packedGeometries[i] = new (this.geometryClass)();
  24213. }
  24214. this.initFlushBuffers();
  24215. };
  24216. /**
  24217. * Makes sure that static and dynamic flush pooled objects have correct dimensions
  24218. */
  24219. AbstractBatchRenderer.prototype.initFlushBuffers = function () {
  24220. var _drawCallPool = AbstractBatchRenderer._drawCallPool, _textureArrayPool = AbstractBatchRenderer._textureArrayPool;
  24221. // max draw calls
  24222. var MAX_SPRITES = this.size / 4;
  24223. // max texture arrays
  24224. var MAX_TA = Math.floor(MAX_SPRITES / this.MAX_TEXTURES) + 1;
  24225. while (_drawCallPool.length < MAX_SPRITES) {
  24226. _drawCallPool.push(new BatchDrawCall());
  24227. }
  24228. while (_textureArrayPool.length < MAX_TA) {
  24229. _textureArrayPool.push(new BatchTextureArray());
  24230. }
  24231. for (var i = 0; i < this.MAX_TEXTURES; i++) {
  24232. this._tempBoundTextures[i] = null;
  24233. }
  24234. };
  24235. /**
  24236. * Handles the `prerender` signal.
  24237. *
  24238. * It ensures that flushes start from the first geometry
  24239. * object again.
  24240. */
  24241. AbstractBatchRenderer.prototype.onPrerender = function () {
  24242. this._flushId = 0;
  24243. };
  24244. /**
  24245. * Buffers the "batchable" object. It need not be rendered
  24246. * immediately.
  24247. *
  24248. * @param {PIXI.DisplayObject} element - the element to render when
  24249. * using this renderer
  24250. */
  24251. AbstractBatchRenderer.prototype.render = function (element) {
  24252. if (!element._texture.valid) {
  24253. return;
  24254. }
  24255. if (this._vertexCount + (element.vertexData.length / 2) > this.size) {
  24256. this.flush();
  24257. }
  24258. this._vertexCount += element.vertexData.length / 2;
  24259. this._indexCount += element.indices.length;
  24260. this._bufferedTextures[this._bufferSize] = element._texture.baseTexture;
  24261. this._bufferedElements[this._bufferSize++] = element;
  24262. };
  24263. AbstractBatchRenderer.prototype.buildTexturesAndDrawCalls = function () {
  24264. var _a = this, textures = _a._bufferedTextures, MAX_TEXTURES = _a.MAX_TEXTURES;
  24265. var textureArrays = AbstractBatchRenderer._textureArrayPool;
  24266. var batch = this.renderer.batch;
  24267. var boundTextures = this._tempBoundTextures;
  24268. var touch = this.renderer.textureGC.count;
  24269. var TICK = ++BaseTexture._globalBatch;
  24270. var countTexArrays = 0;
  24271. var texArray = textureArrays[0];
  24272. var start = 0;
  24273. batch.copyBoundTextures(boundTextures, MAX_TEXTURES);
  24274. for (var i = 0; i < this._bufferSize; ++i) {
  24275. var tex = textures[i];
  24276. textures[i] = null;
  24277. if (tex._batchEnabled === TICK) {
  24278. continue;
  24279. }
  24280. if (texArray.count >= MAX_TEXTURES) {
  24281. batch.boundArray(texArray, boundTextures, TICK, MAX_TEXTURES);
  24282. this.buildDrawCalls(texArray, start, i);
  24283. start = i;
  24284. texArray = textureArrays[++countTexArrays];
  24285. ++TICK;
  24286. }
  24287. tex._batchEnabled = TICK;
  24288. tex.touched = touch;
  24289. texArray.elements[texArray.count++] = tex;
  24290. }
  24291. if (texArray.count > 0) {
  24292. batch.boundArray(texArray, boundTextures, TICK, MAX_TEXTURES);
  24293. this.buildDrawCalls(texArray, start, this._bufferSize);
  24294. ++countTexArrays;
  24295. ++TICK;
  24296. }
  24297. // Clean-up
  24298. for (var i = 0; i < boundTextures.length; i++) {
  24299. boundTextures[i] = null;
  24300. }
  24301. BaseTexture._globalBatch = TICK;
  24302. };
  24303. /**
  24304. * Populating drawcalls for rendering
  24305. *
  24306. * @param {PIXI.BatchTextureArray} texArray
  24307. * @param {number} start
  24308. * @param {number} finish
  24309. */
  24310. AbstractBatchRenderer.prototype.buildDrawCalls = function (texArray, start, finish) {
  24311. var _a = this, elements = _a._bufferedElements, _attributeBuffer = _a._attributeBuffer, _indexBuffer = _a._indexBuffer, vertexSize = _a.vertexSize;
  24312. var drawCalls = AbstractBatchRenderer._drawCallPool;
  24313. var dcIndex = this._dcIndex;
  24314. var aIndex = this._aIndex;
  24315. var iIndex = this._iIndex;
  24316. var drawCall = drawCalls[dcIndex];
  24317. drawCall.start = this._iIndex;
  24318. drawCall.texArray = texArray;
  24319. for (var i = start; i < finish; ++i) {
  24320. var sprite = elements[i];
  24321. var tex = sprite._texture.baseTexture;
  24322. var spriteBlendMode = premultiplyBlendMode[tex.alphaMode ? 1 : 0][sprite.blendMode];
  24323. elements[i] = null;
  24324. if (start < i && drawCall.blend !== spriteBlendMode) {
  24325. drawCall.size = iIndex - drawCall.start;
  24326. start = i;
  24327. drawCall = drawCalls[++dcIndex];
  24328. drawCall.texArray = texArray;
  24329. drawCall.start = iIndex;
  24330. }
  24331. this.packInterleavedGeometry(sprite, _attributeBuffer, _indexBuffer, aIndex, iIndex);
  24332. aIndex += sprite.vertexData.length / 2 * vertexSize;
  24333. iIndex += sprite.indices.length;
  24334. drawCall.blend = spriteBlendMode;
  24335. }
  24336. if (start < finish) {
  24337. drawCall.size = iIndex - drawCall.start;
  24338. ++dcIndex;
  24339. }
  24340. this._dcIndex = dcIndex;
  24341. this._aIndex = aIndex;
  24342. this._iIndex = iIndex;
  24343. };
  24344. /**
  24345. * Bind textures for current rendering
  24346. *
  24347. * @param {PIXI.BatchTextureArray} texArray
  24348. */
  24349. AbstractBatchRenderer.prototype.bindAndClearTexArray = function (texArray) {
  24350. var textureSystem = this.renderer.texture;
  24351. for (var j = 0; j < texArray.count; j++) {
  24352. textureSystem.bind(texArray.elements[j], texArray.ids[j]);
  24353. texArray.elements[j] = null;
  24354. }
  24355. texArray.count = 0;
  24356. };
  24357. AbstractBatchRenderer.prototype.updateGeometry = function () {
  24358. var _a = this, packedGeometries = _a._packedGeometries, attributeBuffer = _a._attributeBuffer, indexBuffer = _a._indexBuffer;
  24359. if (!settings.CAN_UPLOAD_SAME_BUFFER) { /* Usually on iOS devices, where the browser doesn't
  24360. like uploads to the same buffer in a single frame. */
  24361. if (this._packedGeometryPoolSize <= this._flushId) {
  24362. this._packedGeometryPoolSize++;
  24363. packedGeometries[this._flushId] = new (this.geometryClass)();
  24364. }
  24365. packedGeometries[this._flushId]._buffer.update(attributeBuffer.rawBinaryData);
  24366. packedGeometries[this._flushId]._indexBuffer.update(indexBuffer);
  24367. this.renderer.geometry.bind(packedGeometries[this._flushId]);
  24368. this.renderer.geometry.updateBuffers();
  24369. this._flushId++;
  24370. }
  24371. else {
  24372. // lets use the faster option, always use buffer number 0
  24373. packedGeometries[this._flushId]._buffer.update(attributeBuffer.rawBinaryData);
  24374. packedGeometries[this._flushId]._indexBuffer.update(indexBuffer);
  24375. this.renderer.geometry.updateBuffers();
  24376. }
  24377. };
  24378. AbstractBatchRenderer.prototype.drawBatches = function () {
  24379. var dcCount = this._dcIndex;
  24380. var _a = this.renderer, gl = _a.gl, stateSystem = _a.state;
  24381. var drawCalls = AbstractBatchRenderer._drawCallPool;
  24382. var curTexArray = null;
  24383. // Upload textures and do the draw calls
  24384. for (var i = 0; i < dcCount; i++) {
  24385. var _b = drawCalls[i], texArray = _b.texArray, type = _b.type, size = _b.size, start = _b.start, blend = _b.blend;
  24386. if (curTexArray !== texArray) {
  24387. curTexArray = texArray;
  24388. this.bindAndClearTexArray(texArray);
  24389. }
  24390. this.state.blendMode = blend;
  24391. stateSystem.set(this.state);
  24392. gl.drawElements(type, size, gl.UNSIGNED_SHORT, start * 2);
  24393. }
  24394. };
  24395. /**
  24396. * Renders the content _now_ and empties the current batch.
  24397. */
  24398. AbstractBatchRenderer.prototype.flush = function () {
  24399. if (this._vertexCount === 0) {
  24400. return;
  24401. }
  24402. this._attributeBuffer = this.getAttributeBuffer(this._vertexCount);
  24403. this._indexBuffer = this.getIndexBuffer(this._indexCount);
  24404. this._aIndex = 0;
  24405. this._iIndex = 0;
  24406. this._dcIndex = 0;
  24407. this.buildTexturesAndDrawCalls();
  24408. this.updateGeometry();
  24409. this.drawBatches();
  24410. // reset elements buffer for the next flush
  24411. this._bufferSize = 0;
  24412. this._vertexCount = 0;
  24413. this._indexCount = 0;
  24414. };
  24415. /**
  24416. * Starts a new sprite batch.
  24417. */
  24418. AbstractBatchRenderer.prototype.start = function () {
  24419. this.renderer.state.set(this.state);
  24420. this.renderer.texture.ensureSamplerType(this.MAX_TEXTURES);
  24421. this.renderer.shader.bind(this._shader);
  24422. if (settings.CAN_UPLOAD_SAME_BUFFER) {
  24423. // bind buffer #0, we don't need others
  24424. this.renderer.geometry.bind(this._packedGeometries[this._flushId]);
  24425. }
  24426. };
  24427. /**
  24428. * Stops and flushes the current batch.
  24429. */
  24430. AbstractBatchRenderer.prototype.stop = function () {
  24431. this.flush();
  24432. };
  24433. /**
  24434. * Destroys this `AbstractBatchRenderer`. It cannot be used again.
  24435. */
  24436. AbstractBatchRenderer.prototype.destroy = function () {
  24437. for (var i = 0; i < this._packedGeometryPoolSize; i++) {
  24438. if (this._packedGeometries[i]) {
  24439. this._packedGeometries[i].destroy();
  24440. }
  24441. }
  24442. this.renderer.off('prerender', this.onPrerender, this);
  24443. this._aBuffers = null;
  24444. this._iBuffers = null;
  24445. this._packedGeometries = null;
  24446. this._attributeBuffer = null;
  24447. this._indexBuffer = null;
  24448. if (this._shader) {
  24449. this._shader.destroy();
  24450. this._shader = null;
  24451. }
  24452. _super.prototype.destroy.call(this);
  24453. };
  24454. /**
  24455. * Fetches an attribute buffer from `this._aBuffers` that
  24456. * can hold atleast `size` floats.
  24457. *
  24458. * @param {number} size - minimum capacity required
  24459. * @return {ViewableBuffer} - buffer than can hold atleast `size` floats
  24460. * @private
  24461. */
  24462. AbstractBatchRenderer.prototype.getAttributeBuffer = function (size) {
  24463. // 8 vertices is enough for 2 quads
  24464. var roundedP2 = nextPow2(Math.ceil(size / 8));
  24465. var roundedSizeIndex = log2(roundedP2);
  24466. var roundedSize = roundedP2 * 8;
  24467. if (this._aBuffers.length <= roundedSizeIndex) {
  24468. this._iBuffers.length = roundedSizeIndex + 1;
  24469. }
  24470. var buffer = this._aBuffers[roundedSize];
  24471. if (!buffer) {
  24472. this._aBuffers[roundedSize] = buffer = new ViewableBuffer(roundedSize * this.vertexSize * 4);
  24473. }
  24474. return buffer;
  24475. };
  24476. /**
  24477. * Fetches an index buffer from `this._iBuffers` that can
  24478. * have at least `size` capacity.
  24479. *
  24480. * @param {number} size - minimum required capacity
  24481. * @return {Uint16Array} - buffer that can fit `size`
  24482. * indices.
  24483. * @private
  24484. */
  24485. AbstractBatchRenderer.prototype.getIndexBuffer = function (size) {
  24486. // 12 indices is enough for 2 quads
  24487. var roundedP2 = nextPow2(Math.ceil(size / 12));
  24488. var roundedSizeIndex = log2(roundedP2);
  24489. var roundedSize = roundedP2 * 12;
  24490. if (this._iBuffers.length <= roundedSizeIndex) {
  24491. this._iBuffers.length = roundedSizeIndex + 1;
  24492. }
  24493. var buffer = this._iBuffers[roundedSizeIndex];
  24494. if (!buffer) {
  24495. this._iBuffers[roundedSizeIndex] = buffer = new Uint16Array(roundedSize);
  24496. }
  24497. return buffer;
  24498. };
  24499. /**
  24500. * Takes the four batching parameters of `element`, interleaves
  24501. * and pushes them into the batching attribute/index buffers given.
  24502. *
  24503. * It uses these properties: `vertexData` `uvs`, `textureId` and
  24504. * `indicies`. It also uses the "tint" of the base-texture, if
  24505. * present.
  24506. *
  24507. * @param {PIXI.Sprite} element - element being rendered
  24508. * @param {PIXI.ViewableBuffer} attributeBuffer - attribute buffer.
  24509. * @param {Uint16Array} indexBuffer - index buffer
  24510. * @param {number} aIndex - number of floats already in the attribute buffer
  24511. * @param {number} iIndex - number of indices already in `indexBuffer`
  24512. */
  24513. AbstractBatchRenderer.prototype.packInterleavedGeometry = function (element, attributeBuffer, indexBuffer, aIndex, iIndex) {
  24514. var uint32View = attributeBuffer.uint32View, float32View = attributeBuffer.float32View;
  24515. var packedVertices = aIndex / this.vertexSize;
  24516. var uvs = element.uvs;
  24517. var indicies = element.indices;
  24518. var vertexData = element.vertexData;
  24519. var textureId = element._texture.baseTexture._batchLocation;
  24520. var alpha = Math.min(element.worldAlpha, 1.0);
  24521. var argb = (alpha < 1.0
  24522. && element._texture.baseTexture.alphaMode)
  24523. ? premultiplyTint(element._tintRGB, alpha)
  24524. : element._tintRGB + (alpha * 255 << 24);
  24525. // lets not worry about tint! for now..
  24526. for (var i = 0; i < vertexData.length; i += 2) {
  24527. float32View[aIndex++] = vertexData[i];
  24528. float32View[aIndex++] = vertexData[i + 1];
  24529. float32View[aIndex++] = uvs[i];
  24530. float32View[aIndex++] = uvs[i + 1];
  24531. uint32View[aIndex++] = argb;
  24532. float32View[aIndex++] = textureId;
  24533. }
  24534. for (var i = 0; i < indicies.length; i++) {
  24535. indexBuffer[iIndex++] = packedVertices + indicies[i];
  24536. }
  24537. };
  24538. /**
  24539. * Pool of `BatchDrawCall` objects that `flush` used
  24540. * to create "batches" of the objects being rendered.
  24541. *
  24542. * These are never re-allocated again.
  24543. * Shared between all batch renderers because it can be only one "flush" working at the moment.
  24544. *
  24545. * @static
  24546. * @member {PIXI.BatchDrawCall[]}
  24547. */
  24548. AbstractBatchRenderer._drawCallPool = [];
  24549. /**
  24550. * Pool of `BatchDrawCall` objects that `flush` used
  24551. * to create "batches" of the objects being rendered.
  24552. *
  24553. * These are never re-allocated again.
  24554. * Shared between all batch renderers because it can be only one "flush" working at the moment.
  24555. *
  24556. * @static
  24557. * @member {PIXI.BatchTextureArray[]}
  24558. */
  24559. AbstractBatchRenderer._textureArrayPool = [];
  24560. return AbstractBatchRenderer;
  24561. }(ObjectRenderer));
  24562. /**
  24563. * Helper that generates batching multi-texture shader. Use it with your new BatchRenderer
  24564. *
  24565. * @class
  24566. * @memberof PIXI
  24567. */
  24568. var BatchShaderGenerator = /** @class */ (function () {
  24569. /**
  24570. * @param {string} vertexSrc - Vertex shader
  24571. * @param {string} fragTemplate - Fragment shader template
  24572. */
  24573. function BatchShaderGenerator(vertexSrc, fragTemplate) {
  24574. /**
  24575. * Reference to the vertex shader source.
  24576. *
  24577. * @member {string}
  24578. */
  24579. this.vertexSrc = vertexSrc;
  24580. /**
  24581. * Reference to the fragment shader template. Must contain "%count%" and "%forloop%".
  24582. *
  24583. * @member {string}
  24584. */
  24585. this.fragTemplate = fragTemplate;
  24586. this.programCache = {};
  24587. this.defaultGroupCache = {};
  24588. if (fragTemplate.indexOf('%count%') < 0) {
  24589. throw new Error('Fragment template must contain "%count%".');
  24590. }
  24591. if (fragTemplate.indexOf('%forloop%') < 0) {
  24592. throw new Error('Fragment template must contain "%forloop%".');
  24593. }
  24594. }
  24595. BatchShaderGenerator.prototype.generateShader = function (maxTextures) {
  24596. if (!this.programCache[maxTextures]) {
  24597. var sampleValues = new Int32Array(maxTextures);
  24598. for (var i = 0; i < maxTextures; i++) {
  24599. sampleValues[i] = i;
  24600. }
  24601. this.defaultGroupCache[maxTextures] = UniformGroup.from({ uSamplers: sampleValues }, true);
  24602. var fragmentSrc = this.fragTemplate;
  24603. fragmentSrc = fragmentSrc.replace(/%count%/gi, "" + maxTextures);
  24604. fragmentSrc = fragmentSrc.replace(/%forloop%/gi, this.generateSampleSrc(maxTextures));
  24605. this.programCache[maxTextures] = new Program(this.vertexSrc, fragmentSrc);
  24606. }
  24607. var uniforms = {
  24608. tint: new Float32Array([1, 1, 1, 1]),
  24609. translationMatrix: new Matrix(),
  24610. default: this.defaultGroupCache[maxTextures],
  24611. };
  24612. return new Shader(this.programCache[maxTextures], uniforms);
  24613. };
  24614. BatchShaderGenerator.prototype.generateSampleSrc = function (maxTextures) {
  24615. var src = '';
  24616. src += '\n';
  24617. src += '\n';
  24618. for (var i = 0; i < maxTextures; i++) {
  24619. if (i > 0) {
  24620. src += '\nelse ';
  24621. }
  24622. if (i < maxTextures - 1) {
  24623. src += "if(vTextureId < " + i + ".5)";
  24624. }
  24625. src += '\n{';
  24626. src += "\n\tcolor = texture2D(uSamplers[" + i + "], vTextureCoord);";
  24627. src += '\n}';
  24628. }
  24629. src += '\n';
  24630. src += '\n';
  24631. return src;
  24632. };
  24633. return BatchShaderGenerator;
  24634. }());
  24635. /**
  24636. * Geometry used to batch standard PIXI content (e.g. Mesh, Sprite, Graphics objects).
  24637. *
  24638. * @class
  24639. * @memberof PIXI
  24640. */
  24641. var BatchGeometry = /** @class */ (function (_super) {
  24642. __extends$2(BatchGeometry, _super);
  24643. /**
  24644. * @param {boolean} [_static=false] - Optimization flag, where `false`
  24645. * is updated every frame, `true` doesn't change frame-to-frame.
  24646. */
  24647. function BatchGeometry(_static) {
  24648. if (_static === void 0) { _static = false; }
  24649. var _this = _super.call(this) || this;
  24650. /**
  24651. * Buffer used for position, color, texture IDs
  24652. *
  24653. * @member {PIXI.Buffer}
  24654. * @protected
  24655. */
  24656. _this._buffer = new Buffer(null, _static, false);
  24657. /**
  24658. * Index buffer data
  24659. *
  24660. * @member {PIXI.Buffer}
  24661. * @protected
  24662. */
  24663. _this._indexBuffer = new Buffer(null, _static, true);
  24664. _this.addAttribute('aVertexPosition', _this._buffer, 2, false, exports.TYPES.FLOAT)
  24665. .addAttribute('aTextureCoord', _this._buffer, 2, false, exports.TYPES.FLOAT)
  24666. .addAttribute('aColor', _this._buffer, 4, true, exports.TYPES.UNSIGNED_BYTE)
  24667. .addAttribute('aTextureId', _this._buffer, 1, true, exports.TYPES.FLOAT)
  24668. .addIndex(_this._indexBuffer);
  24669. return _this;
  24670. }
  24671. return BatchGeometry;
  24672. }(Geometry));
  24673. var defaultVertex$3 = "precision highp float;\nattribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nattribute vec4 aColor;\nattribute float aTextureId;\n\nuniform mat3 projectionMatrix;\nuniform mat3 translationMatrix;\nuniform vec4 tint;\n\nvarying vec2 vTextureCoord;\nvarying vec4 vColor;\nvarying float vTextureId;\n\nvoid main(void){\n gl_Position = vec4((projectionMatrix * translationMatrix * vec3(aVertexPosition, 1.0)).xy, 0.0, 1.0);\n\n vTextureCoord = aTextureCoord;\n vTextureId = aTextureId;\n vColor = aColor * tint;\n}\n";
  24674. var defaultFragment$2 = "varying vec2 vTextureCoord;\nvarying vec4 vColor;\nvarying float vTextureId;\nuniform sampler2D uSamplers[%count%];\n\nvoid main(void){\n vec4 color;\n %forloop%\n gl_FragColor = color * vColor;\n}\n";
  24675. /**
  24676. * @class
  24677. * @memberof PIXI
  24678. * @hideconstructor
  24679. */
  24680. var BatchPluginFactory = /** @class */ (function () {
  24681. function BatchPluginFactory() {
  24682. }
  24683. /**
  24684. * Create a new BatchRenderer plugin for Renderer. this convenience can provide an easy way
  24685. * to extend BatchRenderer with all the necessary pieces.
  24686. * @example
  24687. * const fragment = `
  24688. * varying vec2 vTextureCoord;
  24689. * varying vec4 vColor;
  24690. * varying float vTextureId;
  24691. * uniform sampler2D uSamplers[%count%];
  24692. *
  24693. * void main(void){
  24694. * vec4 color;
  24695. * %forloop%
  24696. * gl_FragColor = vColor * vec4(color.a - color.rgb, color.a);
  24697. * }
  24698. * `;
  24699. * const InvertBatchRenderer = PIXI.BatchPluginFactory.create({ fragment });
  24700. * PIXI.Renderer.registerPlugin('invert', InvertBatchRenderer);
  24701. * const sprite = new PIXI.Sprite();
  24702. * sprite.pluginName = 'invert';
  24703. *
  24704. * @static
  24705. * @param {object} [options]
  24706. * @param {string} [options.vertex=PIXI.BatchPluginFactory.defaultVertexSrc] - Vertex shader source
  24707. * @param {string} [options.fragment=PIXI.BatchPluginFactory.defaultFragmentTemplate] - Fragment shader template
  24708. * @param {number} [options.vertexSize=6] - Vertex size
  24709. * @param {object} [options.geometryClass=PIXI.BatchGeometry]
  24710. * @return {*} New batch renderer plugin
  24711. */
  24712. BatchPluginFactory.create = function (options) {
  24713. var _a = Object.assign({
  24714. vertex: defaultVertex$3,
  24715. fragment: defaultFragment$2,
  24716. geometryClass: BatchGeometry,
  24717. vertexSize: 6,
  24718. }, options), vertex = _a.vertex, fragment = _a.fragment, vertexSize = _a.vertexSize, geometryClass = _a.geometryClass;
  24719. return /** @class */ (function (_super) {
  24720. __extends$2(BatchPlugin, _super);
  24721. function BatchPlugin(renderer) {
  24722. var _this = _super.call(this, renderer) || this;
  24723. _this.shaderGenerator = new BatchShaderGenerator(vertex, fragment);
  24724. _this.geometryClass = geometryClass;
  24725. _this.vertexSize = vertexSize;
  24726. return _this;
  24727. }
  24728. return BatchPlugin;
  24729. }(AbstractBatchRenderer));
  24730. };
  24731. Object.defineProperty(BatchPluginFactory, "defaultVertexSrc", {
  24732. /**
  24733. * The default vertex shader source
  24734. *
  24735. * @static
  24736. * @type {string}
  24737. * @constant
  24738. */
  24739. get: function () {
  24740. return defaultVertex$3;
  24741. },
  24742. enumerable: false,
  24743. configurable: true
  24744. });
  24745. Object.defineProperty(BatchPluginFactory, "defaultFragmentTemplate", {
  24746. /**
  24747. * The default fragment shader source
  24748. *
  24749. * @static
  24750. * @type {string}
  24751. * @constant
  24752. */
  24753. get: function () {
  24754. return defaultFragment$2;
  24755. },
  24756. enumerable: false,
  24757. configurable: true
  24758. });
  24759. return BatchPluginFactory;
  24760. }());
  24761. // Setup the default BatchRenderer plugin, this is what
  24762. // we'll actually export at the root level
  24763. var BatchRenderer = BatchPluginFactory.create();
  24764. /**
  24765. * @memberof PIXI
  24766. * @namespace resources
  24767. * @see PIXI
  24768. * @deprecated since 6.0.0
  24769. */
  24770. var resources = {};
  24771. var _loop_1 = function (name) {
  24772. Object.defineProperty(resources, name, {
  24773. get: function () {
  24774. deprecation('6.0.0', "PIXI.systems." + name + " has moved to PIXI." + name);
  24775. return _resources[name];
  24776. },
  24777. });
  24778. };
  24779. for (var name in _resources) {
  24780. _loop_1(name);
  24781. }
  24782. /**
  24783. * @memberof PIXI
  24784. * @namespace systems
  24785. * @see PIXI
  24786. * @deprecated since 6.0.0
  24787. */
  24788. var systems = {};
  24789. var _loop_2 = function (name) {
  24790. Object.defineProperty(systems, name, {
  24791. get: function () {
  24792. deprecation('6.0.0', "PIXI.resources." + name + " has moved to PIXI." + name);
  24793. return _systems[name];
  24794. },
  24795. });
  24796. };
  24797. for (var name in _systems) {
  24798. _loop_2(name);
  24799. }
  24800. /*!
  24801. * @pixi/app - v6.1.2
  24802. * Compiled Thu, 12 Aug 2021 17:11:19 UTC
  24803. *
  24804. * @pixi/app is licensed under the MIT License.
  24805. * http://www.opensource.org/licenses/mit-license
  24806. */
  24807. /**
  24808. * Convenience class to create a new PIXI application.
  24809. *
  24810. * This class automatically creates the renderer, ticker and root container.
  24811. *
  24812. * @example
  24813. * // Create the application
  24814. * const app = new PIXI.Application();
  24815. *
  24816. * // Add the view to the DOM
  24817. * document.body.appendChild(app.view);
  24818. *
  24819. * // ex, add display objects
  24820. * app.stage.addChild(PIXI.Sprite.from('something.png'));
  24821. *
  24822. * @class
  24823. * @memberof PIXI
  24824. */
  24825. var Application = /** @class */ (function () {
  24826. /**
  24827. * @param {object} [options] - The optional renderer parameters.
  24828. * @param {boolean} [options.autoStart=true] - Automatically starts the rendering after the construction.
  24829. * **Note**: Setting this parameter to false does NOT stop the shared ticker even if you set
  24830. * options.sharedTicker to true in case that it is already started. Stop it by your own.
  24831. * @param {number} [options.width=800] - The width of the renderers view.
  24832. * @param {number} [options.height=600] - The height of the renderers view.
  24833. * @param {HTMLCanvasElement} [options.view] - The canvas to use as a view, optional.
  24834. * @param {boolean} [options.useContextAlpha=true] - Pass-through value for canvas' context `alpha` property.
  24835. * If you want to set transparency, please use `backgroundAlpha`. This option is for cases where the
  24836. * canvas needs to be opaque, possibly for performance reasons on some older devices.
  24837. * @param {boolean} [options.autoDensity=false] - Resizes renderer view in CSS pixels to allow for
  24838. * resolutions other than 1.
  24839. * @param {boolean} [options.antialias=false] - Sets antialias
  24840. * @param {boolean} [options.preserveDrawingBuffer=false] - Enables drawing buffer preservation, enable this if you
  24841. * need to call toDataUrl on the WebGL context.
  24842. * @param {number} [options.resolution=PIXI.settings.RESOLUTION] - The resolution / device pixel ratio of the renderer.
  24843. * @param {boolean} [options.forceCanvas=false] - prevents selection of WebGL renderer, even if such is present, this
  24844. * option only is available when using **pixi.js-legacy** or **@pixi/canvas-renderer** modules, otherwise
  24845. * it is ignored.
  24846. * @param {number} [options.backgroundColor=0x000000] - The background color of the rendered area
  24847. * (shown if not transparent).
  24848. * @param {number} [options.backgroundAlpha=1] - Value from 0 (fully transparent) to 1 (fully opaque).
  24849. * @param {boolean} [options.clearBeforeRender=true] - This sets if the renderer will clear the canvas or
  24850. * not before the new render pass.
  24851. * @param {string} [options.powerPreference] - Parameter passed to webgl context, set to "high-performance"
  24852. * for devices with dual graphics card. **(WebGL only)**.
  24853. * @param {boolean} [options.sharedTicker=false] - `true` to use PIXI.Ticker.shared, `false` to create new ticker.
  24854. * If set to false, you cannot register a handler to occur before anything that runs on the shared ticker.
  24855. * The system ticker will always run before both the shared ticker and the app ticker.
  24856. * @param {boolean} [options.sharedLoader=false] - `true` to use PIXI.Loader.shared, `false` to create new Loader.
  24857. * @param {Window|HTMLElement} [options.resizeTo] - Element to automatically resize stage to.
  24858. */
  24859. function Application(options) {
  24860. var _this = this;
  24861. /**
  24862. * The root display container that's rendered.
  24863. * @member {PIXI.Container}
  24864. */
  24865. this.stage = new Container();
  24866. // The default options
  24867. options = Object.assign({
  24868. forceCanvas: false,
  24869. }, options);
  24870. this.renderer = autoDetectRenderer(options);
  24871. // install plugins here
  24872. Application._plugins.forEach(function (plugin) {
  24873. plugin.init.call(_this, options);
  24874. });
  24875. }
  24876. /**
  24877. * Register a middleware plugin for the application
  24878. * @static
  24879. * @param {PIXI.IApplicationPlugin} plugin - Plugin being installed
  24880. */
  24881. Application.registerPlugin = function (plugin) {
  24882. Application._plugins.push(plugin);
  24883. };
  24884. /**
  24885. * Render the current stage.
  24886. */
  24887. Application.prototype.render = function () {
  24888. this.renderer.render(this.stage);
  24889. };
  24890. Object.defineProperty(Application.prototype, "view", {
  24891. /**
  24892. * Reference to the renderer's canvas element.
  24893. * @member {HTMLCanvasElement}
  24894. * @readonly
  24895. */
  24896. get: function () {
  24897. return this.renderer.view;
  24898. },
  24899. enumerable: false,
  24900. configurable: true
  24901. });
  24902. Object.defineProperty(Application.prototype, "screen", {
  24903. /**
  24904. * Reference to the renderer's screen rectangle. Its safe to use as `filterArea` or `hitArea` for the whole screen.
  24905. * @member {PIXI.Rectangle}
  24906. * @readonly
  24907. */
  24908. get: function () {
  24909. return this.renderer.screen;
  24910. },
  24911. enumerable: false,
  24912. configurable: true
  24913. });
  24914. /**
  24915. * Destroy and don't use after this.
  24916. * @param {Boolean} [removeView=false] - Automatically remove canvas from DOM.
  24917. * @param {object|boolean} [stageOptions] - Options parameter. A boolean will act as if all options
  24918. * have been set to that value
  24919. * @param {boolean} [stageOptions.children=false] - if set to true, all the children will have their destroy
  24920. * method called as well. 'stageOptions' will be passed on to those calls.
  24921. * @param {boolean} [stageOptions.texture=false] - Only used for child Sprites if stageOptions.children is set
  24922. * to true. Should it destroy the texture of the child sprite
  24923. * @param {boolean} [stageOptions.baseTexture=false] - Only used for child Sprites if stageOptions.children is set
  24924. * to true. Should it destroy the base texture of the child sprite
  24925. */
  24926. Application.prototype.destroy = function (removeView, stageOptions) {
  24927. var _this = this;
  24928. // Destroy plugins in the opposite order
  24929. // which they were constructed
  24930. var plugins = Application._plugins.slice(0);
  24931. plugins.reverse();
  24932. plugins.forEach(function (plugin) {
  24933. plugin.destroy.call(_this);
  24934. });
  24935. this.stage.destroy(stageOptions);
  24936. this.stage = null;
  24937. this.renderer.destroy(removeView);
  24938. this.renderer = null;
  24939. };
  24940. /** Collection of installed plugins. */
  24941. Application._plugins = [];
  24942. return Application;
  24943. }());
  24944. /**
  24945. * Middleware for for Application's resize functionality
  24946. * @private
  24947. * @class
  24948. */
  24949. var ResizePlugin = /** @class */ (function () {
  24950. function ResizePlugin() {
  24951. }
  24952. /**
  24953. * Initialize the plugin with scope of application instance
  24954. * @static
  24955. * @private
  24956. * @param {object} [options] - See application options
  24957. */
  24958. ResizePlugin.init = function (options) {
  24959. var _this = this;
  24960. Object.defineProperty(this, 'resizeTo',
  24961. /**
  24962. * The HTML element or window to automatically resize the
  24963. * renderer's view element to match width and height.
  24964. * @member {Window|HTMLElement}
  24965. * @name resizeTo
  24966. * @memberof PIXI.Application#
  24967. */
  24968. {
  24969. set: function (dom) {
  24970. self.removeEventListener('resize', this.queueResize);
  24971. this._resizeTo = dom;
  24972. if (dom) {
  24973. self.addEventListener('resize', this.queueResize);
  24974. this.resize();
  24975. }
  24976. },
  24977. get: function () {
  24978. return this._resizeTo;
  24979. },
  24980. });
  24981. /**
  24982. * Resize is throttled, so it's safe to call this multiple times per frame and it'll
  24983. * only be called once.
  24984. *
  24985. * @memberof PIXI.Application#
  24986. * @method queueResize
  24987. * @private
  24988. */
  24989. this.queueResize = function () {
  24990. if (!_this._resizeTo) {
  24991. return;
  24992. }
  24993. _this.cancelResize();
  24994. // // Throttle resize events per raf
  24995. _this._resizeId = requestAnimationFrame(function () { return _this.resize(); });
  24996. };
  24997. /**
  24998. * Cancel the resize queue.
  24999. *
  25000. * @memberof PIXI.Application#
  25001. * @method cancelResize
  25002. * @private
  25003. */
  25004. this.cancelResize = function () {
  25005. if (_this._resizeId) {
  25006. cancelAnimationFrame(_this._resizeId);
  25007. _this._resizeId = null;
  25008. }
  25009. };
  25010. /**
  25011. * Execute an immediate resize on the renderer, this is not
  25012. * throttled and can be expensive to call many times in a row.
  25013. * Will resize only if `resizeTo` property is set.
  25014. *
  25015. * @memberof PIXI.Application#
  25016. * @method resize
  25017. */
  25018. this.resize = function () {
  25019. if (!_this._resizeTo) {
  25020. return;
  25021. }
  25022. // clear queue resize
  25023. _this.cancelResize();
  25024. var width;
  25025. var height;
  25026. // Resize to the window
  25027. if (_this._resizeTo === self) {
  25028. width = self.innerWidth;
  25029. height = self.innerHeight;
  25030. }
  25031. // Resize to other HTML entities
  25032. else {
  25033. var _a = _this._resizeTo, clientWidth = _a.clientWidth, clientHeight = _a.clientHeight;
  25034. width = clientWidth;
  25035. height = clientHeight;
  25036. }
  25037. _this.renderer.resize(width, height);
  25038. };
  25039. // On resize
  25040. this._resizeId = null;
  25041. this._resizeTo = null;
  25042. this.resizeTo = options.resizeTo || null;
  25043. };
  25044. /**
  25045. * Clean up the ticker, scoped to application
  25046. *
  25047. * @static
  25048. * @private
  25049. */
  25050. ResizePlugin.destroy = function () {
  25051. self.removeEventListener('resize', this.queueResize);
  25052. this.cancelResize();
  25053. this.cancelResize = null;
  25054. this.queueResize = null;
  25055. this.resizeTo = null;
  25056. this.resize = null;
  25057. };
  25058. return ResizePlugin;
  25059. }());
  25060. Application.registerPlugin(ResizePlugin);
  25061. /*!
  25062. * @pixi/extract - v6.1.2
  25063. * Compiled Thu, 12 Aug 2021 17:11:19 UTC
  25064. *
  25065. * @pixi/extract is licensed under the MIT License.
  25066. * http://www.opensource.org/licenses/mit-license
  25067. */
  25068. var TEMP_RECT = new Rectangle();
  25069. var BYTES_PER_PIXEL = 4;
  25070. /**
  25071. * This class provides renderer-specific plugins for exporting content from a renderer.
  25072. * For instance, these plugins can be used for saving an Image, Canvas element or for exporting the raw image data (pixels).
  25073. *
  25074. * Do not instantiate these plugins directly. It is available from the `renderer.plugins` property.
  25075. * See {@link PIXI.CanvasRenderer#plugins} or {@link PIXI.Renderer#plugins}.
  25076. * @example
  25077. * // Create a new app (will auto-add extract plugin to renderer)
  25078. * const app = new PIXI.Application();
  25079. *
  25080. * // Draw a red circle
  25081. * const graphics = new PIXI.Graphics()
  25082. * .beginFill(0xFF0000)
  25083. * .drawCircle(0, 0, 50);
  25084. *
  25085. * // Render the graphics as an HTMLImageElement
  25086. * const image = app.renderer.plugins.extract.image(graphics);
  25087. * document.body.appendChild(image);
  25088. * @class
  25089. * @memberof PIXI
  25090. */
  25091. var Extract = /** @class */ (function () {
  25092. /**
  25093. * @param {PIXI.Renderer} renderer - A reference to the current renderer
  25094. */
  25095. function Extract(renderer) {
  25096. this.renderer = renderer;
  25097. }
  25098. /**
  25099. * Will return a HTML Image of the target
  25100. *
  25101. * @param {PIXI.DisplayObject|PIXI.RenderTexture} target - A displayObject or renderTexture
  25102. * to convert. If left empty will use the main renderer
  25103. * @param {string} [format] - Image format, e.g. "image/jpeg" or "image/webp".
  25104. * @param {number} [quality] - JPEG or Webp compression from 0 to 1. Default is 0.92.
  25105. * @return {HTMLImageElement} HTML Image of the target
  25106. */
  25107. Extract.prototype.image = function (target, format, quality) {
  25108. var image = new Image();
  25109. image.src = this.base64(target, format, quality);
  25110. return image;
  25111. };
  25112. /**
  25113. * Will return a a base64 encoded string of this target. It works by calling
  25114. * `Extract.getCanvas` and then running toDataURL on that.
  25115. *
  25116. * @param {PIXI.DisplayObject|PIXI.RenderTexture} target - A displayObject or renderTexture
  25117. * to convert. If left empty will use the main renderer
  25118. * @param {string} [format] - Image format, e.g. "image/jpeg" or "image/webp".
  25119. * @param {number} [quality] - JPEG or Webp compression from 0 to 1. Default is 0.92.
  25120. * @return {string} A base64 encoded string of the texture.
  25121. */
  25122. Extract.prototype.base64 = function (target, format, quality) {
  25123. return this.canvas(target).toDataURL(format, quality);
  25124. };
  25125. /**
  25126. * Creates a Canvas element, renders this target to it and then returns it.
  25127. *
  25128. * @param {PIXI.DisplayObject|PIXI.RenderTexture} target - A displayObject or renderTexture
  25129. * to convert. If left empty will use the main renderer
  25130. * @return {HTMLCanvasElement} A Canvas element with the texture rendered on.
  25131. */
  25132. Extract.prototype.canvas = function (target) {
  25133. var renderer = this.renderer;
  25134. var resolution;
  25135. var frame;
  25136. var flipY = false;
  25137. var renderTexture;
  25138. var generated = false;
  25139. if (target) {
  25140. if (target instanceof RenderTexture) {
  25141. renderTexture = target;
  25142. }
  25143. else {
  25144. renderTexture = this.renderer.generateTexture(target);
  25145. generated = true;
  25146. }
  25147. }
  25148. if (renderTexture) {
  25149. resolution = renderTexture.baseTexture.resolution;
  25150. frame = renderTexture.frame;
  25151. flipY = false;
  25152. renderer.renderTexture.bind(renderTexture);
  25153. }
  25154. else {
  25155. resolution = this.renderer.resolution;
  25156. flipY = true;
  25157. frame = TEMP_RECT;
  25158. frame.width = this.renderer.width;
  25159. frame.height = this.renderer.height;
  25160. renderer.renderTexture.bind(null);
  25161. }
  25162. var width = Math.floor((frame.width * resolution) + 1e-4);
  25163. var height = Math.floor((frame.height * resolution) + 1e-4);
  25164. var canvasBuffer = new CanvasRenderTarget(width, height, 1);
  25165. var webglPixels = new Uint8Array(BYTES_PER_PIXEL * width * height);
  25166. // read pixels to the array
  25167. var gl = renderer.gl;
  25168. gl.readPixels(frame.x * resolution, frame.y * resolution, width, height, gl.RGBA, gl.UNSIGNED_BYTE, webglPixels);
  25169. // add the pixels to the canvas
  25170. var canvasData = canvasBuffer.context.getImageData(0, 0, width, height);
  25171. Extract.arrayPostDivide(webglPixels, canvasData.data);
  25172. canvasBuffer.context.putImageData(canvasData, 0, 0);
  25173. // pulling pixels
  25174. if (flipY) {
  25175. var target_1 = new CanvasRenderTarget(canvasBuffer.width, canvasBuffer.height, 1);
  25176. target_1.context.scale(1, -1);
  25177. // we can't render to itself because we should be empty before render.
  25178. target_1.context.drawImage(canvasBuffer.canvas, 0, -height);
  25179. canvasBuffer.destroy();
  25180. canvasBuffer = target_1;
  25181. }
  25182. if (generated) {
  25183. renderTexture.destroy(true);
  25184. }
  25185. // send the canvas back..
  25186. return canvasBuffer.canvas;
  25187. };
  25188. /**
  25189. * Will return a one-dimensional array containing the pixel data of the entire texture in RGBA
  25190. * order, with integer values between 0 and 255 (included).
  25191. *
  25192. * @param {PIXI.DisplayObject|PIXI.RenderTexture} target - A displayObject or renderTexture
  25193. * to convert. If left empty will use the main renderer
  25194. * @return {Uint8Array} One-dimensional array containing the pixel data of the entire texture
  25195. */
  25196. Extract.prototype.pixels = function (target) {
  25197. var renderer = this.renderer;
  25198. var resolution;
  25199. var frame;
  25200. var renderTexture;
  25201. var generated = false;
  25202. if (target) {
  25203. if (target instanceof RenderTexture) {
  25204. renderTexture = target;
  25205. }
  25206. else {
  25207. renderTexture = this.renderer.generateTexture(target);
  25208. generated = true;
  25209. }
  25210. }
  25211. if (renderTexture) {
  25212. resolution = renderTexture.baseTexture.resolution;
  25213. frame = renderTexture.frame;
  25214. // bind the buffer
  25215. renderer.renderTexture.bind(renderTexture);
  25216. }
  25217. else {
  25218. resolution = renderer.resolution;
  25219. frame = TEMP_RECT;
  25220. frame.width = renderer.width;
  25221. frame.height = renderer.height;
  25222. renderer.renderTexture.bind(null);
  25223. }
  25224. var width = frame.width * resolution;
  25225. var height = frame.height * resolution;
  25226. var webglPixels = new Uint8Array(BYTES_PER_PIXEL * width * height);
  25227. // read pixels to the array
  25228. var gl = renderer.gl;
  25229. gl.readPixels(frame.x * resolution, frame.y * resolution, width, height, gl.RGBA, gl.UNSIGNED_BYTE, webglPixels);
  25230. if (generated) {
  25231. renderTexture.destroy(true);
  25232. }
  25233. Extract.arrayPostDivide(webglPixels, webglPixels);
  25234. return webglPixels;
  25235. };
  25236. /**
  25237. * Destroys the extract
  25238. *
  25239. */
  25240. Extract.prototype.destroy = function () {
  25241. this.renderer = null;
  25242. };
  25243. /**
  25244. * Takes premultiplied pixel data and produces regular pixel data
  25245. *
  25246. * @private
  25247. * @param {number[] | Uint8Array | Uint8ClampedArray} pixels - array of pixel data
  25248. * @param {number[] | Uint8Array | Uint8ClampedArray} out - output array
  25249. */
  25250. Extract.arrayPostDivide = function (pixels, out) {
  25251. for (var i = 0; i < pixels.length; i += 4) {
  25252. var alpha = out[i + 3] = pixels[i + 3];
  25253. if (alpha !== 0) {
  25254. out[i] = Math.round(Math.min(pixels[i] * 255.0 / alpha, 255.0));
  25255. out[i + 1] = Math.round(Math.min(pixels[i + 1] * 255.0 / alpha, 255.0));
  25256. out[i + 2] = Math.round(Math.min(pixels[i + 2] * 255.0 / alpha, 255.0));
  25257. }
  25258. else {
  25259. out[i] = pixels[i];
  25260. out[i + 1] = pixels[i + 1];
  25261. out[i + 2] = pixels[i + 2];
  25262. }
  25263. }
  25264. };
  25265. return Extract;
  25266. }());
  25267. /*!
  25268. * @pixi/loaders - v6.1.2
  25269. * Compiled Thu, 12 Aug 2021 17:11:19 UTC
  25270. *
  25271. * @pixi/loaders is licensed under the MIT License.
  25272. * http://www.opensource.org/licenses/mit-license
  25273. */
  25274. /* jshint -W097 */
  25275. /**
  25276. * @memberof PIXI
  25277. */
  25278. var SignalBinding = /** @class */ (function () {
  25279. /**
  25280. * SignalBinding constructor.
  25281. * @constructs SignalBinding
  25282. * @param {Function} fn - Event handler to be called.
  25283. * @param {Boolean} [once=false] - Should this listener be removed after dispatch
  25284. * @param {object} [thisArg] - The context of the callback function.
  25285. * @api private
  25286. */
  25287. // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
  25288. function SignalBinding(fn, once, thisArg) {
  25289. if (once === void 0) { once = false; }
  25290. this._fn = fn;
  25291. this._once = once;
  25292. this._thisArg = thisArg;
  25293. this._next = this._prev = this._owner = null;
  25294. }
  25295. SignalBinding.prototype.detach = function () {
  25296. if (this._owner === null)
  25297. { return false; }
  25298. this._owner.detach(this);
  25299. return true;
  25300. };
  25301. return SignalBinding;
  25302. }());
  25303. /**
  25304. * @private
  25305. */
  25306. function _addSignalBinding(self, node) {
  25307. if (!self._head) {
  25308. self._head = node;
  25309. self._tail = node;
  25310. }
  25311. else {
  25312. self._tail._next = node;
  25313. node._prev = self._tail;
  25314. self._tail = node;
  25315. }
  25316. node._owner = self;
  25317. return node;
  25318. }
  25319. /**
  25320. * @memberof PIXI
  25321. */
  25322. var Signal = /** @class */ (function () {
  25323. /**
  25324. * MiniSignal constructor.
  25325. * @example
  25326. * let mySignal = new Signal();
  25327. * let binding = mySignal.add(onSignal);
  25328. * mySignal.dispatch('foo', 'bar');
  25329. * mySignal.detach(binding);
  25330. */
  25331. function Signal() {
  25332. this._head = this._tail = undefined;
  25333. }
  25334. /**
  25335. * Return an array of attached SignalBinding.
  25336. *
  25337. * @param {Boolean} [exists=false] - We only need to know if there are handlers.
  25338. * @returns {PIXI.SignalBinding[]|Boolean} Array of attached SignalBinding or Boolean if called with exists = true
  25339. * @api public
  25340. */
  25341. Signal.prototype.handlers = function (exists) {
  25342. if (exists === void 0) { exists = false; }
  25343. var node = this._head;
  25344. if (exists)
  25345. { return !!node; }
  25346. var ee = [];
  25347. while (node) {
  25348. ee.push(node);
  25349. node = node._next;
  25350. }
  25351. return ee;
  25352. };
  25353. /**
  25354. * Return true if node is a SignalBinding attached to this MiniSignal
  25355. *
  25356. * @param {PIXI.SignalBinding} node - Node to check.
  25357. * @returns {Boolean} True if node is attache to mini-signal
  25358. */
  25359. Signal.prototype.has = function (node) {
  25360. if (!(node instanceof SignalBinding)) {
  25361. throw new Error('MiniSignal#has(): First arg must be a SignalBinding object.');
  25362. }
  25363. return node._owner === this;
  25364. };
  25365. /**
  25366. * Dispaches a signal to all registered listeners.
  25367. *
  25368. * @returns {Boolean} Indication if we've emitted an event.
  25369. */
  25370. Signal.prototype.dispatch = function () {
  25371. var arguments$1 = arguments;
  25372. var args = [];
  25373. for (var _i = 0; _i < arguments.length; _i++) {
  25374. args[_i] = arguments$1[_i];
  25375. }
  25376. var node = this._head;
  25377. if (!node)
  25378. { return false; }
  25379. while (node) {
  25380. if (node._once)
  25381. { this.detach(node); }
  25382. node._fn.apply(node._thisArg, args);
  25383. node = node._next;
  25384. }
  25385. return true;
  25386. };
  25387. /**
  25388. * Register a new listener.
  25389. *
  25390. * @param {Function} fn - Callback function.
  25391. * @param {object} [thisArg] - The context of the callback function.
  25392. * @returns {PIXI.SignalBinding} The SignalBinding node that was added.
  25393. */
  25394. Signal.prototype.add = function (fn, thisArg) {
  25395. if (thisArg === void 0) { thisArg = null; }
  25396. if (typeof fn !== 'function') {
  25397. throw new Error('MiniSignal#add(): First arg must be a Function.');
  25398. }
  25399. return _addSignalBinding(this, new SignalBinding(fn, false, thisArg));
  25400. };
  25401. /**
  25402. * Register a new listener that will be executed only once.
  25403. *
  25404. * @param {Function} fn - Callback function.
  25405. * @param {object} [thisArg] - The context of the callback function.
  25406. * @returns {PIXI.SignalBinding} The SignalBinding node that was added.
  25407. */
  25408. Signal.prototype.once = function (fn, thisArg) {
  25409. if (thisArg === void 0) { thisArg = null; }
  25410. if (typeof fn !== 'function') {
  25411. throw new Error('MiniSignal#once(): First arg must be a Function.');
  25412. }
  25413. return _addSignalBinding(this, new SignalBinding(fn, true, thisArg));
  25414. };
  25415. /**
  25416. * Remove binding object.
  25417. *
  25418. * @param {PIXI.SignalBinding} node - The binding node that will be removed.
  25419. * @returns {Signal} The instance on which this method was called.
  25420. * @api public */
  25421. Signal.prototype.detach = function (node) {
  25422. if (!(node instanceof SignalBinding)) {
  25423. throw new Error('MiniSignal#detach(): First arg must be a SignalBinding object.');
  25424. }
  25425. if (node._owner !== this)
  25426. { return this; } // todo: or error?
  25427. if (node._prev)
  25428. { node._prev._next = node._next; }
  25429. if (node._next)
  25430. { node._next._prev = node._prev; }
  25431. if (node === this._head) { // first node
  25432. this._head = node._next;
  25433. if (node._next === null) {
  25434. this._tail = null;
  25435. }
  25436. }
  25437. else if (node === this._tail) { // last node
  25438. this._tail = node._prev;
  25439. this._tail._next = null;
  25440. }
  25441. node._owner = null;
  25442. return this;
  25443. };
  25444. /**
  25445. * Detach all listeners.
  25446. *
  25447. * @returns {Signal} The instance on which this method was called.
  25448. */
  25449. Signal.prototype.detachAll = function () {
  25450. var node = this._head;
  25451. if (!node)
  25452. { return this; }
  25453. this._head = this._tail = null;
  25454. while (node) {
  25455. node._owner = null;
  25456. node = node._next;
  25457. }
  25458. return this;
  25459. };
  25460. return Signal;
  25461. }());
  25462. /**
  25463. * function from npm package `parseUri`, converted to TS to avoid leftpad incident
  25464. * @param {string} str
  25465. * @param [opts] - options
  25466. * @param {boolean} [opts.strictMode] - type of parser
  25467. */
  25468. function parseUri(str, opts) {
  25469. opts = opts || {};
  25470. var o = {
  25471. // eslint-disable-next-line max-len
  25472. key: ['source', 'protocol', 'authority', 'userInfo', 'user', 'password', 'host', 'port', 'relative', 'path', 'directory', 'file', 'query', 'anchor'],
  25473. q: {
  25474. name: 'queryKey',
  25475. parser: /(?:^|&)([^&=]*)=?([^&]*)/g
  25476. },
  25477. parser: {
  25478. // eslint-disable-next-line max-len
  25479. strict: /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,
  25480. // eslint-disable-next-line max-len
  25481. loose: /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/
  25482. }
  25483. };
  25484. var m = o.parser[opts.strictMode ? 'strict' : 'loose'].exec(str);
  25485. var uri = {};
  25486. var i = 14;
  25487. while (i--)
  25488. { uri[o.key[i]] = m[i] || ''; }
  25489. uri[o.q.name] = {};
  25490. uri[o.key[12]].replace(o.q.parser, function (_t0, t1, t2) {
  25491. if (t1)
  25492. { uri[o.q.name][t1] = t2; }
  25493. });
  25494. return uri;
  25495. }
  25496. // tests if CORS is supported in XHR, if not we need to use XDR
  25497. var useXdr = !!(self.XDomainRequest && !('withCredentials' in (new XMLHttpRequest())));
  25498. var tempAnchor$1 = null;
  25499. // some status constants
  25500. var STATUS_NONE = 0;
  25501. var STATUS_OK = 200;
  25502. var STATUS_EMPTY = 204;
  25503. var STATUS_IE_BUG_EMPTY = 1223;
  25504. var STATUS_TYPE_OK = 2;
  25505. // noop
  25506. function _noop() { }
  25507. /**
  25508. * Quick helper to set a value on one of the extension maps. Ensures there is no
  25509. * dot at the start of the extension.
  25510. *
  25511. * @ignore
  25512. * @param map - The map to set on.
  25513. * @param extname - The extension (or key) to set.
  25514. * @param val - The value to set.
  25515. */
  25516. function setExtMap(map, extname, val) {
  25517. if (extname && extname.indexOf('.') === 0) {
  25518. extname = extname.substring(1);
  25519. }
  25520. if (!extname) {
  25521. return;
  25522. }
  25523. map[extname] = val;
  25524. }
  25525. /**
  25526. * Quick helper to get string xhr type.
  25527. *
  25528. * @ignore
  25529. * @param xhr - The request to check.
  25530. * @return The type.
  25531. */
  25532. function reqType(xhr) {
  25533. return xhr.toString().replace('object ', '');
  25534. }
  25535. /**
  25536. * Manages the state and loading of a resource and all child resources.
  25537. *
  25538. * Can be extended in `GlobalMixins.LoaderResource`.
  25539. *
  25540. * @memberof PIXI
  25541. */
  25542. exports.LoaderResource = /** @class */ (function () {
  25543. /**
  25544. * @param {string} name - The name of the resource to load.
  25545. * @param {string|string[]} url - The url for this resource, for audio/video loads you can pass
  25546. * an array of sources.
  25547. * @param {object} [options] - The options for the load.
  25548. * @param {string|boolean} [options.crossOrigin] - Is this request cross-origin? Default is to
  25549. * determine automatically.
  25550. * @param {number} [options.timeout=0] - A timeout in milliseconds for the load. If the load takes
  25551. * longer than this time it is cancelled and the load is considered a failure. If this value is
  25552. * set to `0` then there is no explicit timeout.
  25553. * @param {PIXI.LoaderResource.LOAD_TYPE} [options.loadType=LOAD_TYPE.XHR] - How should this resource
  25554. * be loaded?
  25555. * @param {PIXI.LoaderResource.XHR_RESPONSE_TYPE} [options.xhrType=XHR_RESPONSE_TYPE.DEFAULT] - How
  25556. * should the data being loaded be interpreted when using XHR?
  25557. * @param {PIXI.LoaderResource.IMetadata} [options.metadata] - Extra configuration for middleware
  25558. * and the Resource object.
  25559. */
  25560. function LoaderResource(name, url, options) {
  25561. /**
  25562. * The `dequeue` method that will be used a storage place for the async queue dequeue method
  25563. * used privately by the loader.
  25564. *
  25565. * @private
  25566. * @member {function}
  25567. */
  25568. this._dequeue = _noop;
  25569. /**
  25570. * Used a storage place for the on load binding used privately by the loader.
  25571. *
  25572. * @private
  25573. * @member {function}
  25574. */
  25575. this._onLoadBinding = null;
  25576. /**
  25577. * The timer for element loads to check if they timeout.
  25578. *
  25579. * @private
  25580. */
  25581. this._elementTimer = 0;
  25582. /**
  25583. * The `complete` function bound to this resource's context.
  25584. *
  25585. * @private
  25586. * @type {function}
  25587. */
  25588. this._boundComplete = null;
  25589. /**
  25590. * The `_onError` function bound to this resource's context.
  25591. *
  25592. * @private
  25593. * @type {function}
  25594. */
  25595. this._boundOnError = null;
  25596. /**
  25597. * The `_onProgress` function bound to this resource's context.
  25598. *
  25599. * @private
  25600. * @type {function}
  25601. */
  25602. this._boundOnProgress = null;
  25603. /**
  25604. * The `_onTimeout` function bound to this resource's context.
  25605. *
  25606. * @private
  25607. * @type {function}
  25608. */
  25609. this._boundOnTimeout = null;
  25610. this._boundXhrOnError = null;
  25611. this._boundXhrOnTimeout = null;
  25612. this._boundXhrOnAbort = null;
  25613. this._boundXhrOnLoad = null;
  25614. if (typeof name !== 'string' || typeof url !== 'string') {
  25615. throw new Error('Both name and url are required for constructing a resource.');
  25616. }
  25617. options = options || {};
  25618. this._flags = 0;
  25619. // set data url flag, needs to be set early for some _determineX checks to work.
  25620. this._setFlag(LoaderResource.STATUS_FLAGS.DATA_URL, url.indexOf('data:') === 0);
  25621. this.name = name;
  25622. this.url = url;
  25623. this.extension = this._getExtension();
  25624. this.data = null;
  25625. this.crossOrigin = options.crossOrigin === true ? 'anonymous' : options.crossOrigin;
  25626. this.timeout = options.timeout || 0;
  25627. this.loadType = options.loadType || this._determineLoadType();
  25628. // The type used to load the resource via XHR. If unset, determined automatically.
  25629. this.xhrType = options.xhrType;
  25630. // Extra info for middleware, and controlling specifics about how the resource loads.
  25631. // Note that if you pass in a `loadElement`, the Resource class takes ownership of it.
  25632. // Meaning it will modify it as it sees fit.
  25633. this.metadata = options.metadata || {};
  25634. // The error that occurred while loading (if any).
  25635. this.error = null;
  25636. // The XHR object that was used to load this resource. This is only set
  25637. // when `loadType` is `LoaderResource.LOAD_TYPE.XHR`.
  25638. this.xhr = null;
  25639. // The child resources this resource owns.
  25640. this.children = [];
  25641. // The resource type.
  25642. this.type = LoaderResource.TYPE.UNKNOWN;
  25643. // The progress chunk owned by this resource.
  25644. this.progressChunk = 0;
  25645. // The `dequeue` method that will be used a storage place for the async queue dequeue method
  25646. // used privately by the loader.
  25647. this._dequeue = _noop;
  25648. // Used a storage place for the on load binding used privately by the loader.
  25649. this._onLoadBinding = null;
  25650. // The timer for element loads to check if they timeout.
  25651. this._elementTimer = 0;
  25652. this._boundComplete = this.complete.bind(this);
  25653. this._boundOnError = this._onError.bind(this);
  25654. this._boundOnProgress = this._onProgress.bind(this);
  25655. this._boundOnTimeout = this._onTimeout.bind(this);
  25656. // xhr callbacks
  25657. this._boundXhrOnError = this._xhrOnError.bind(this);
  25658. this._boundXhrOnTimeout = this._xhrOnTimeout.bind(this);
  25659. this._boundXhrOnAbort = this._xhrOnAbort.bind(this);
  25660. this._boundXhrOnLoad = this._xhrOnLoad.bind(this);
  25661. // Dispatched when the resource beings to load.
  25662. this.onStart = new Signal();
  25663. // Dispatched each time progress of this resource load updates.
  25664. // Not all resources types and loader systems can support this event
  25665. // so sometimes it may not be available. If the resource
  25666. // is being loaded on a modern browser, using XHR, and the remote server
  25667. // properly sets Content-Length headers, then this will be available.
  25668. this.onProgress = new Signal();
  25669. // Dispatched once this resource has loaded, if there was an error it will
  25670. // be in the `error` property.
  25671. this.onComplete = new Signal();
  25672. // Dispatched after this resource has had all the *after* middleware run on it.
  25673. this.onAfterMiddleware = new Signal();
  25674. }
  25675. /**
  25676. * Sets the load type to be used for a specific extension.
  25677. *
  25678. * @static
  25679. * @param {string} extname - The extension to set the type for, e.g. "png" or "fnt"
  25680. * @param {PIXI.LoaderResource.LOAD_TYPE} loadType - The load type to set it to.
  25681. */
  25682. LoaderResource.setExtensionLoadType = function (extname, loadType) {
  25683. setExtMap(LoaderResource._loadTypeMap, extname, loadType);
  25684. };
  25685. /**
  25686. * Sets the load type to be used for a specific extension.
  25687. *
  25688. * @static
  25689. * @param {string} extname - The extension to set the type for, e.g. "png" or "fnt"
  25690. * @param {PIXI.LoaderResource.XHR_RESPONSE_TYPE} xhrType - The xhr type to set it to.
  25691. */
  25692. LoaderResource.setExtensionXhrType = function (extname, xhrType) {
  25693. setExtMap(LoaderResource._xhrTypeMap, extname, xhrType);
  25694. };
  25695. Object.defineProperty(LoaderResource.prototype, "isDataUrl", {
  25696. /**
  25697. * When the resource starts to load.
  25698. *
  25699. * @memberof PIXI.LoaderResource
  25700. * @callback OnStartSignal
  25701. * @param {Resource} resource - The resource that the event happened on.
  25702. */
  25703. /**
  25704. * When the resource reports loading progress.
  25705. *
  25706. * @memberof PIXI.LoaderResource
  25707. * @callback OnProgressSignal
  25708. * @param {Resource} resource - The resource that the event happened on.
  25709. * @param {number} percentage - The progress of the load in the range [0, 1].
  25710. */
  25711. /**
  25712. * When the resource finishes loading.
  25713. *
  25714. * @memberof PIXI.LoaderResource
  25715. * @callback OnCompleteSignal
  25716. * @param {Resource} resource - The resource that the event happened on.
  25717. */
  25718. /**
  25719. * @memberof PIXI.LoaderResource
  25720. * @typedef {object} IMetadata
  25721. * @property {HTMLImageElement|HTMLAudioElement|HTMLVideoElement} [loadElement=null] - The
  25722. * element to use for loading, instead of creating one.
  25723. * @property {boolean} [skipSource=false] - Skips adding source(s) to the load element. This
  25724. * is useful if you want to pass in a `loadElement` that you already added load sources to.
  25725. * @property {string|string[]} [mimeType] - The mime type to use for the source element
  25726. * of a video/audio elment. If the urls are an array, you can pass this as an array as well
  25727. * where each index is the mime type to use for the corresponding url index.
  25728. */
  25729. /**
  25730. * Stores whether or not this url is a data url.
  25731. *
  25732. * @readonly
  25733. * @member {boolean}
  25734. */
  25735. get: function () {
  25736. return this._hasFlag(LoaderResource.STATUS_FLAGS.DATA_URL);
  25737. },
  25738. enumerable: false,
  25739. configurable: true
  25740. });
  25741. Object.defineProperty(LoaderResource.prototype, "isComplete", {
  25742. /**
  25743. * Describes if this resource has finished loading. Is true when the resource has completely
  25744. * loaded.
  25745. *
  25746. * @readonly
  25747. * @member {boolean}
  25748. */
  25749. get: function () {
  25750. return this._hasFlag(LoaderResource.STATUS_FLAGS.COMPLETE);
  25751. },
  25752. enumerable: false,
  25753. configurable: true
  25754. });
  25755. Object.defineProperty(LoaderResource.prototype, "isLoading", {
  25756. /**
  25757. * Describes if this resource is currently loading. Is true when the resource starts loading,
  25758. * and is false again when complete.
  25759. *
  25760. * @readonly
  25761. * @member {boolean}
  25762. */
  25763. get: function () {
  25764. return this._hasFlag(LoaderResource.STATUS_FLAGS.LOADING);
  25765. },
  25766. enumerable: false,
  25767. configurable: true
  25768. });
  25769. /**
  25770. * Marks the resource as complete.
  25771. *
  25772. */
  25773. LoaderResource.prototype.complete = function () {
  25774. this._clearEvents();
  25775. this._finish();
  25776. };
  25777. /**
  25778. * Aborts the loading of this resource, with an optional message.
  25779. *
  25780. * @param {string} message - The message to use for the error
  25781. */
  25782. LoaderResource.prototype.abort = function (message) {
  25783. // abort can be called multiple times, ignore subsequent calls.
  25784. if (this.error) {
  25785. return;
  25786. }
  25787. // store error
  25788. this.error = new Error(message);
  25789. // clear events before calling aborts
  25790. this._clearEvents();
  25791. // abort the actual loading
  25792. if (this.xhr) {
  25793. this.xhr.abort();
  25794. }
  25795. else if (this.xdr) {
  25796. this.xdr.abort();
  25797. }
  25798. else if (this.data) {
  25799. // single source
  25800. if (this.data.src) {
  25801. this.data.src = LoaderResource.EMPTY_GIF;
  25802. }
  25803. // multi-source
  25804. else {
  25805. while (this.data.firstChild) {
  25806. this.data.removeChild(this.data.firstChild);
  25807. }
  25808. }
  25809. }
  25810. // done now.
  25811. this._finish();
  25812. };
  25813. /**
  25814. * Kicks off loading of this resource. This method is asynchronous.
  25815. *
  25816. * @param {PIXI.LoaderResource.OnCompleteSignal} [cb] - Optional callback to call once the resource is loaded.
  25817. */
  25818. LoaderResource.prototype.load = function (cb) {
  25819. var _this = this;
  25820. if (this.isLoading) {
  25821. return;
  25822. }
  25823. if (this.isComplete) {
  25824. if (cb) {
  25825. setTimeout(function () { return cb(_this); }, 1);
  25826. }
  25827. return;
  25828. }
  25829. else if (cb) {
  25830. this.onComplete.once(cb);
  25831. }
  25832. this._setFlag(LoaderResource.STATUS_FLAGS.LOADING, true);
  25833. this.onStart.dispatch(this);
  25834. // if unset, determine the value
  25835. if (this.crossOrigin === false || typeof this.crossOrigin !== 'string') {
  25836. this.crossOrigin = this._determineCrossOrigin(this.url);
  25837. }
  25838. switch (this.loadType) {
  25839. case LoaderResource.LOAD_TYPE.IMAGE:
  25840. this.type = LoaderResource.TYPE.IMAGE;
  25841. this._loadElement('image');
  25842. break;
  25843. case LoaderResource.LOAD_TYPE.AUDIO:
  25844. this.type = LoaderResource.TYPE.AUDIO;
  25845. this._loadSourceElement('audio');
  25846. break;
  25847. case LoaderResource.LOAD_TYPE.VIDEO:
  25848. this.type = LoaderResource.TYPE.VIDEO;
  25849. this._loadSourceElement('video');
  25850. break;
  25851. case LoaderResource.LOAD_TYPE.XHR:
  25852. /* falls through */
  25853. default:
  25854. if (useXdr && this.crossOrigin) {
  25855. this._loadXdr();
  25856. }
  25857. else {
  25858. this._loadXhr();
  25859. }
  25860. break;
  25861. }
  25862. };
  25863. /**
  25864. * Checks if the flag is set.
  25865. *
  25866. * @param flag - The flag to check.
  25867. * @return True if the flag is set.
  25868. */
  25869. LoaderResource.prototype._hasFlag = function (flag) {
  25870. return (this._flags & flag) !== 0;
  25871. };
  25872. /**
  25873. * (Un)Sets the flag.
  25874. *
  25875. * @param flag - The flag to (un)set.
  25876. * @param value - Whether to set or (un)set the flag.
  25877. */
  25878. LoaderResource.prototype._setFlag = function (flag, value) {
  25879. this._flags = value ? (this._flags | flag) : (this._flags & ~flag);
  25880. };
  25881. /**
  25882. * Clears all the events from the underlying loading source.
  25883. */
  25884. LoaderResource.prototype._clearEvents = function () {
  25885. clearTimeout(this._elementTimer);
  25886. if (this.data && this.data.removeEventListener) {
  25887. this.data.removeEventListener('error', this._boundOnError, false);
  25888. this.data.removeEventListener('load', this._boundComplete, false);
  25889. this.data.removeEventListener('progress', this._boundOnProgress, false);
  25890. this.data.removeEventListener('canplaythrough', this._boundComplete, false);
  25891. }
  25892. if (this.xhr) {
  25893. if (this.xhr.removeEventListener) {
  25894. this.xhr.removeEventListener('error', this._boundXhrOnError, false);
  25895. this.xhr.removeEventListener('timeout', this._boundXhrOnTimeout, false);
  25896. this.xhr.removeEventListener('abort', this._boundXhrOnAbort, false);
  25897. this.xhr.removeEventListener('progress', this._boundOnProgress, false);
  25898. this.xhr.removeEventListener('load', this._boundXhrOnLoad, false);
  25899. }
  25900. else {
  25901. this.xhr.onerror = null;
  25902. this.xhr.ontimeout = null;
  25903. this.xhr.onprogress = null;
  25904. this.xhr.onload = null;
  25905. }
  25906. }
  25907. };
  25908. /**
  25909. * Finalizes the load.
  25910. */
  25911. LoaderResource.prototype._finish = function () {
  25912. if (this.isComplete) {
  25913. throw new Error('Complete called again for an already completed resource.');
  25914. }
  25915. this._setFlag(LoaderResource.STATUS_FLAGS.COMPLETE, true);
  25916. this._setFlag(LoaderResource.STATUS_FLAGS.LOADING, false);
  25917. this.onComplete.dispatch(this);
  25918. };
  25919. /**
  25920. * Loads this resources using an element that has a single source,
  25921. * like an HTMLImageElement.
  25922. * @private
  25923. * @param type - The type of element to use.
  25924. */
  25925. LoaderResource.prototype._loadElement = function (type) {
  25926. if (this.metadata.loadElement) {
  25927. this.data = this.metadata.loadElement;
  25928. }
  25929. else if (type === 'image' && typeof self.Image !== 'undefined') {
  25930. this.data = new Image();
  25931. }
  25932. else {
  25933. this.data = document.createElement(type);
  25934. }
  25935. if (this.crossOrigin) {
  25936. this.data.crossOrigin = this.crossOrigin;
  25937. }
  25938. if (!this.metadata.skipSource) {
  25939. this.data.src = this.url;
  25940. }
  25941. this.data.addEventListener('error', this._boundOnError, false);
  25942. this.data.addEventListener('load', this._boundComplete, false);
  25943. this.data.addEventListener('progress', this._boundOnProgress, false);
  25944. if (this.timeout) {
  25945. this._elementTimer = setTimeout(this._boundOnTimeout, this.timeout);
  25946. }
  25947. };
  25948. /**
  25949. * Loads this resources using an element that has multiple sources,
  25950. * like an HTMLAudioElement or HTMLVideoElement.
  25951. * @param type - The type of element to use.
  25952. */
  25953. LoaderResource.prototype._loadSourceElement = function (type) {
  25954. if (this.metadata.loadElement) {
  25955. this.data = this.metadata.loadElement;
  25956. }
  25957. else if (type === 'audio' && typeof self.Audio !== 'undefined') {
  25958. this.data = new Audio();
  25959. }
  25960. else {
  25961. this.data = document.createElement(type);
  25962. }
  25963. if (this.data === null) {
  25964. this.abort("Unsupported element: " + type);
  25965. return;
  25966. }
  25967. if (this.crossOrigin) {
  25968. this.data.crossOrigin = this.crossOrigin;
  25969. }
  25970. if (!this.metadata.skipSource) {
  25971. // support for CocoonJS Canvas+ runtime, lacks document.createElement('source')
  25972. if (navigator.isCocoonJS) {
  25973. this.data.src = Array.isArray(this.url) ? this.url[0] : this.url;
  25974. }
  25975. else if (Array.isArray(this.url)) {
  25976. var mimeTypes = this.metadata.mimeType;
  25977. for (var i = 0; i < this.url.length; ++i) {
  25978. this.data.appendChild(this._createSource(type, this.url[i], Array.isArray(mimeTypes) ? mimeTypes[i] : mimeTypes));
  25979. }
  25980. }
  25981. else {
  25982. var mimeTypes = this.metadata.mimeType;
  25983. this.data.appendChild(this._createSource(type, this.url, Array.isArray(mimeTypes) ? mimeTypes[0] : mimeTypes));
  25984. }
  25985. }
  25986. this.data.addEventListener('error', this._boundOnError, false);
  25987. this.data.addEventListener('load', this._boundComplete, false);
  25988. this.data.addEventListener('progress', this._boundOnProgress, false);
  25989. this.data.addEventListener('canplaythrough', this._boundComplete, false);
  25990. this.data.load();
  25991. if (this.timeout) {
  25992. this._elementTimer = setTimeout(this._boundOnTimeout, this.timeout);
  25993. }
  25994. };
  25995. /**
  25996. * Loads this resources using an XMLHttpRequest.
  25997. */
  25998. LoaderResource.prototype._loadXhr = function () {
  25999. // if unset, determine the value
  26000. if (typeof this.xhrType !== 'string') {
  26001. this.xhrType = this._determineXhrType();
  26002. }
  26003. var xhr = this.xhr = new XMLHttpRequest();
  26004. // set the request type and url
  26005. xhr.open('GET', this.url, true);
  26006. xhr.timeout = this.timeout;
  26007. // load json as text and parse it ourselves. We do this because some browsers
  26008. // *cough* safari *cough* can't deal with it.
  26009. if (this.xhrType === LoaderResource.XHR_RESPONSE_TYPE.JSON
  26010. || this.xhrType === LoaderResource.XHR_RESPONSE_TYPE.DOCUMENT) {
  26011. xhr.responseType = LoaderResource.XHR_RESPONSE_TYPE.TEXT;
  26012. }
  26013. else {
  26014. xhr.responseType = this.xhrType;
  26015. }
  26016. xhr.addEventListener('error', this._boundXhrOnError, false);
  26017. xhr.addEventListener('timeout', this._boundXhrOnTimeout, false);
  26018. xhr.addEventListener('abort', this._boundXhrOnAbort, false);
  26019. xhr.addEventListener('progress', this._boundOnProgress, false);
  26020. xhr.addEventListener('load', this._boundXhrOnLoad, false);
  26021. xhr.send();
  26022. };
  26023. /**
  26024. * Loads this resources using an XDomainRequest. This is here because we need to support IE9 (gross).
  26025. */
  26026. LoaderResource.prototype._loadXdr = function () {
  26027. // if unset, determine the value
  26028. if (typeof this.xhrType !== 'string') {
  26029. this.xhrType = this._determineXhrType();
  26030. }
  26031. var xdr = this.xhr = new self.XDomainRequest(); // eslint-disable-line no-undef
  26032. // XDomainRequest has a few quirks. Occasionally it will abort requests
  26033. // A way to avoid this is to make sure ALL callbacks are set even if not used
  26034. // More info here: http://stackoverflow.com/questions/15786966/xdomainrequest-aborts-post-on-ie-9
  26035. xdr.timeout = this.timeout || 5000; // XDR needs a timeout value or it breaks in IE9
  26036. xdr.onerror = this._boundXhrOnError;
  26037. xdr.ontimeout = this._boundXhrOnTimeout;
  26038. xdr.onprogress = this._boundOnProgress;
  26039. xdr.onload = this._boundXhrOnLoad;
  26040. xdr.open('GET', this.url, true);
  26041. // Note: The xdr.send() call is wrapped in a timeout to prevent an
  26042. // issue with the interface where some requests are lost if multiple
  26043. // XDomainRequests are being sent at the same time.
  26044. // Some info here: https://github.com/photonstorm/phaser/issues/1248
  26045. setTimeout(function () { return xdr.send(); }, 1);
  26046. };
  26047. /**
  26048. * Creates a source used in loading via an element.
  26049. * @param type - The element type (video or audio).
  26050. * @param url - The source URL to load from.
  26051. * @param [mime] - The mime type of the video
  26052. * @return The source element.
  26053. */
  26054. LoaderResource.prototype._createSource = function (type, url, mime) {
  26055. if (!mime) {
  26056. mime = type + "/" + this._getExtension(url);
  26057. }
  26058. var source = document.createElement('source');
  26059. source.src = url;
  26060. source.type = mime;
  26061. return source;
  26062. };
  26063. /**
  26064. * Called if a load errors out.
  26065. *
  26066. * @param event - The error event from the element that emits it.
  26067. */
  26068. LoaderResource.prototype._onError = function (event) {
  26069. this.abort("Failed to load element using: " + event.target.nodeName);
  26070. };
  26071. /**
  26072. * Called if a load progress event fires for an element or xhr/xdr.
  26073. * @param event - Progress event.
  26074. */
  26075. LoaderResource.prototype._onProgress = function (event) {
  26076. if (event && event.lengthComputable) {
  26077. this.onProgress.dispatch(this, event.loaded / event.total);
  26078. }
  26079. };
  26080. /**
  26081. * Called if a timeout event fires for an element.
  26082. */
  26083. LoaderResource.prototype._onTimeout = function () {
  26084. this.abort("Load timed out.");
  26085. };
  26086. /**
  26087. * Called if an error event fires for xhr/xdr.
  26088. */
  26089. LoaderResource.prototype._xhrOnError = function () {
  26090. var xhr = this.xhr;
  26091. this.abort(reqType(xhr) + " Request failed. Status: " + xhr.status + ", text: \"" + xhr.statusText + "\"");
  26092. };
  26093. /**
  26094. * Called if an error event fires for xhr/xdr.
  26095. */
  26096. LoaderResource.prototype._xhrOnTimeout = function () {
  26097. var xhr = this.xhr;
  26098. this.abort(reqType(xhr) + " Request timed out.");
  26099. };
  26100. /**
  26101. * Called if an abort event fires for xhr/xdr.
  26102. */
  26103. LoaderResource.prototype._xhrOnAbort = function () {
  26104. var xhr = this.xhr;
  26105. this.abort(reqType(xhr) + " Request was aborted by the user.");
  26106. };
  26107. /**
  26108. * Called when data successfully loads from an xhr/xdr request.
  26109. */
  26110. LoaderResource.prototype._xhrOnLoad = function () {
  26111. var xhr = this.xhr;
  26112. var text = '';
  26113. var status = typeof xhr.status === 'undefined' ? STATUS_OK : xhr.status; // XDR has no `.status`, assume 200.
  26114. // responseText is accessible only if responseType is '' or 'text' and on older browsers
  26115. if (xhr.responseType === '' || xhr.responseType === 'text' || typeof xhr.responseType === 'undefined') {
  26116. text = xhr.responseText;
  26117. }
  26118. // status can be 0 when using the `file://` protocol so we also check if a response is set.
  26119. // If it has a response, we assume 200; otherwise a 0 status code with no contents is an aborted request.
  26120. if (status === STATUS_NONE && (text.length > 0 || xhr.responseType === LoaderResource.XHR_RESPONSE_TYPE.BUFFER)) {
  26121. status = STATUS_OK;
  26122. }
  26123. // handle IE9 bug: http://stackoverflow.com/questions/10046972/msie-returns-status-code-of-1223-for-ajax-request
  26124. else if (status === STATUS_IE_BUG_EMPTY) {
  26125. status = STATUS_EMPTY;
  26126. }
  26127. var statusType = (status / 100) | 0;
  26128. if (statusType === STATUS_TYPE_OK) {
  26129. // if text, just return it
  26130. if (this.xhrType === LoaderResource.XHR_RESPONSE_TYPE.TEXT) {
  26131. this.data = text;
  26132. this.type = LoaderResource.TYPE.TEXT;
  26133. }
  26134. // if json, parse into json object
  26135. else if (this.xhrType === LoaderResource.XHR_RESPONSE_TYPE.JSON) {
  26136. try {
  26137. this.data = JSON.parse(text);
  26138. this.type = LoaderResource.TYPE.JSON;
  26139. }
  26140. catch (e) {
  26141. this.abort("Error trying to parse loaded json: " + e);
  26142. return;
  26143. }
  26144. }
  26145. // if xml, parse into an xml document or div element
  26146. else if (this.xhrType === LoaderResource.XHR_RESPONSE_TYPE.DOCUMENT) {
  26147. try {
  26148. if (self.DOMParser) {
  26149. var domparser = new DOMParser();
  26150. this.data = domparser.parseFromString(text, 'text/xml');
  26151. }
  26152. else {
  26153. var div = document.createElement('div');
  26154. div.innerHTML = text;
  26155. this.data = div;
  26156. }
  26157. this.type = LoaderResource.TYPE.XML;
  26158. }
  26159. catch (e$1) {
  26160. this.abort("Error trying to parse loaded xml: " + e$1);
  26161. return;
  26162. }
  26163. }
  26164. // other types just return the response
  26165. else {
  26166. this.data = xhr.response || text;
  26167. }
  26168. }
  26169. else {
  26170. this.abort("[" + xhr.status + "] " + xhr.statusText + ": " + xhr.responseURL);
  26171. return;
  26172. }
  26173. this.complete();
  26174. };
  26175. /**
  26176. * Sets the `crossOrigin` property for this resource based on if the url
  26177. * for this resource is cross-origin. If crossOrigin was manually set, this
  26178. * function does nothing.
  26179. * @private
  26180. * @param url - The url to test.
  26181. * @param [loc=self.location] - The location object to test against.
  26182. * @return The crossOrigin value to use (or empty string for none).
  26183. */
  26184. // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
  26185. LoaderResource.prototype._determineCrossOrigin = function (url, loc) {
  26186. // data: and javascript: urls are considered same-origin
  26187. if (url.indexOf('data:') === 0) {
  26188. return '';
  26189. }
  26190. // A sandboxed iframe without the 'allow-same-origin' attribute will have a special
  26191. // origin designed not to match self.location.origin, and will always require
  26192. // crossOrigin requests regardless of whether the location matches.
  26193. if (self.origin !== self.location.origin) {
  26194. return 'anonymous';
  26195. }
  26196. // default is self.location
  26197. loc = loc || self.location;
  26198. if (!tempAnchor$1) {
  26199. tempAnchor$1 = document.createElement('a');
  26200. }
  26201. // let the browser determine the full href for the url of this resource and then
  26202. // parse with the node url lib, we can't use the properties of the anchor element
  26203. // because they don't work in IE9 :(
  26204. tempAnchor$1.href = url;
  26205. var parsedUrl = parseUri(tempAnchor$1.href, { strictMode: true });
  26206. var samePort = (!parsedUrl.port && loc.port === '') || (parsedUrl.port === loc.port);
  26207. var protocol = parsedUrl.protocol ? parsedUrl.protocol + ":" : '';
  26208. // if cross origin
  26209. if (parsedUrl.host !== loc.hostname || !samePort || protocol !== loc.protocol) {
  26210. return 'anonymous';
  26211. }
  26212. return '';
  26213. };
  26214. /**
  26215. * Determines the responseType of an XHR request based on the extension of the
  26216. * resource being loaded.
  26217. *
  26218. * @private
  26219. * @return {PIXI.LoaderResource.XHR_RESPONSE_TYPE} The responseType to use.
  26220. */
  26221. LoaderResource.prototype._determineXhrType = function () {
  26222. return LoaderResource._xhrTypeMap[this.extension] || LoaderResource.XHR_RESPONSE_TYPE.TEXT;
  26223. };
  26224. /**
  26225. * Determines the loadType of a resource based on the extension of the
  26226. * resource being loaded.
  26227. *
  26228. * @private
  26229. * @return {PIXI.LoaderResource.LOAD_TYPE} The loadType to use.
  26230. */
  26231. LoaderResource.prototype._determineLoadType = function () {
  26232. return LoaderResource._loadTypeMap[this.extension] || LoaderResource.LOAD_TYPE.XHR;
  26233. };
  26234. /**
  26235. * Extracts the extension (sans '.') of the file being loaded by the resource.
  26236. *
  26237. * @param [url] - url to parse, `this.url` by default.
  26238. * @return The extension.
  26239. */
  26240. LoaderResource.prototype._getExtension = function (url) {
  26241. if (url === void 0) { url = this.url; }
  26242. var ext = '';
  26243. if (this.isDataUrl) {
  26244. var slashIndex = url.indexOf('/');
  26245. ext = url.substring(slashIndex + 1, url.indexOf(';', slashIndex));
  26246. }
  26247. else {
  26248. var queryStart = url.indexOf('?');
  26249. var hashStart = url.indexOf('#');
  26250. var index = Math.min(queryStart > -1 ? queryStart : url.length, hashStart > -1 ? hashStart : url.length);
  26251. url = url.substring(0, index);
  26252. ext = url.substring(url.lastIndexOf('.') + 1);
  26253. }
  26254. return ext.toLowerCase();
  26255. };
  26256. /**
  26257. * Determines the mime type of an XHR request based on the responseType of
  26258. * resource being loaded.
  26259. *
  26260. * @param type - The type to get a mime type for.
  26261. * @private
  26262. * @return The mime type to use.
  26263. */
  26264. LoaderResource.prototype._getMimeFromXhrType = function (type) {
  26265. switch (type) {
  26266. case LoaderResource.XHR_RESPONSE_TYPE.BUFFER:
  26267. return 'application/octet-binary';
  26268. case LoaderResource.XHR_RESPONSE_TYPE.BLOB:
  26269. return 'application/blob';
  26270. case LoaderResource.XHR_RESPONSE_TYPE.DOCUMENT:
  26271. return 'application/xml';
  26272. case LoaderResource.XHR_RESPONSE_TYPE.JSON:
  26273. return 'application/json';
  26274. case LoaderResource.XHR_RESPONSE_TYPE.DEFAULT:
  26275. case LoaderResource.XHR_RESPONSE_TYPE.TEXT:
  26276. /* falls through */
  26277. default:
  26278. return 'text/plain';
  26279. }
  26280. };
  26281. return LoaderResource;
  26282. }());
  26283. // eslint-disable-next-line @typescript-eslint/no-namespace
  26284. (function (LoaderResource) {
  26285. /**
  26286. * The types of resources a resource could represent.
  26287. *
  26288. * @static
  26289. * @readonly
  26290. * @enum {number}
  26291. * @memberof PIXI.LoaderResource
  26292. */
  26293. var STATUS_FLAGS;
  26294. (function (STATUS_FLAGS) {
  26295. /** None */
  26296. STATUS_FLAGS[STATUS_FLAGS["NONE"] = 0] = "NONE";
  26297. /** Data URL */
  26298. STATUS_FLAGS[STATUS_FLAGS["DATA_URL"] = 1] = "DATA_URL";
  26299. /** Complete */
  26300. STATUS_FLAGS[STATUS_FLAGS["COMPLETE"] = 2] = "COMPLETE";
  26301. /** Loading */
  26302. STATUS_FLAGS[STATUS_FLAGS["LOADING"] = 4] = "LOADING";
  26303. })(STATUS_FLAGS = LoaderResource.STATUS_FLAGS || (LoaderResource.STATUS_FLAGS = {}));
  26304. /**
  26305. * The types of resources a resource could represent.
  26306. *
  26307. * @static
  26308. * @readonly
  26309. * @enum {number}
  26310. * @memberof PIXI.LoaderResource
  26311. */
  26312. var TYPE;
  26313. (function (TYPE) {
  26314. /** Unknown */
  26315. TYPE[TYPE["UNKNOWN"] = 0] = "UNKNOWN";
  26316. /** JSON */
  26317. TYPE[TYPE["JSON"] = 1] = "JSON";
  26318. /** XML */
  26319. TYPE[TYPE["XML"] = 2] = "XML";
  26320. /** Image */
  26321. TYPE[TYPE["IMAGE"] = 3] = "IMAGE";
  26322. /** Audio */
  26323. TYPE[TYPE["AUDIO"] = 4] = "AUDIO";
  26324. /** Video */
  26325. TYPE[TYPE["VIDEO"] = 5] = "VIDEO";
  26326. /** Plain text */
  26327. TYPE[TYPE["TEXT"] = 6] = "TEXT";
  26328. })(TYPE = LoaderResource.TYPE || (LoaderResource.TYPE = {}));
  26329. /**
  26330. * The types of loading a resource can use.
  26331. *
  26332. * @static
  26333. * @readonly
  26334. * @enum {number}
  26335. * @memberof PIXI.LoaderResource
  26336. */
  26337. var LOAD_TYPE;
  26338. (function (LOAD_TYPE) {
  26339. /** Uses XMLHttpRequest to load the resource. */
  26340. LOAD_TYPE[LOAD_TYPE["XHR"] = 1] = "XHR";
  26341. /** Uses an `Image` object to load the resource. */
  26342. LOAD_TYPE[LOAD_TYPE["IMAGE"] = 2] = "IMAGE";
  26343. /** Uses an `Audio` object to load the resource. */
  26344. LOAD_TYPE[LOAD_TYPE["AUDIO"] = 3] = "AUDIO";
  26345. /** Uses a `Video` object to load the resource. */
  26346. LOAD_TYPE[LOAD_TYPE["VIDEO"] = 4] = "VIDEO";
  26347. })(LOAD_TYPE = LoaderResource.LOAD_TYPE || (LoaderResource.LOAD_TYPE = {}));
  26348. /**
  26349. * The XHR ready states, used internally.
  26350. *
  26351. * @static
  26352. * @readonly
  26353. * @enum {string}
  26354. * @memberof PIXI.LoaderResource
  26355. */
  26356. var XHR_RESPONSE_TYPE;
  26357. (function (XHR_RESPONSE_TYPE) {
  26358. /** string */
  26359. XHR_RESPONSE_TYPE["DEFAULT"] = "text";
  26360. /** ArrayBuffer */
  26361. XHR_RESPONSE_TYPE["BUFFER"] = "arraybuffer";
  26362. /** Blob */
  26363. XHR_RESPONSE_TYPE["BLOB"] = "blob";
  26364. /** Document */
  26365. XHR_RESPONSE_TYPE["DOCUMENT"] = "document";
  26366. /** Object */
  26367. XHR_RESPONSE_TYPE["JSON"] = "json";
  26368. /** String */
  26369. XHR_RESPONSE_TYPE["TEXT"] = "text";
  26370. })(XHR_RESPONSE_TYPE = LoaderResource.XHR_RESPONSE_TYPE || (LoaderResource.XHR_RESPONSE_TYPE = {}));
  26371. LoaderResource._loadTypeMap = {
  26372. // images
  26373. gif: LoaderResource.LOAD_TYPE.IMAGE,
  26374. png: LoaderResource.LOAD_TYPE.IMAGE,
  26375. bmp: LoaderResource.LOAD_TYPE.IMAGE,
  26376. jpg: LoaderResource.LOAD_TYPE.IMAGE,
  26377. jpeg: LoaderResource.LOAD_TYPE.IMAGE,
  26378. tif: LoaderResource.LOAD_TYPE.IMAGE,
  26379. tiff: LoaderResource.LOAD_TYPE.IMAGE,
  26380. webp: LoaderResource.LOAD_TYPE.IMAGE,
  26381. tga: LoaderResource.LOAD_TYPE.IMAGE,
  26382. svg: LoaderResource.LOAD_TYPE.IMAGE,
  26383. 'svg+xml': LoaderResource.LOAD_TYPE.IMAGE,
  26384. // audio
  26385. mp3: LoaderResource.LOAD_TYPE.AUDIO,
  26386. ogg: LoaderResource.LOAD_TYPE.AUDIO,
  26387. wav: LoaderResource.LOAD_TYPE.AUDIO,
  26388. // videos
  26389. mp4: LoaderResource.LOAD_TYPE.VIDEO,
  26390. webm: LoaderResource.LOAD_TYPE.VIDEO,
  26391. };
  26392. LoaderResource._xhrTypeMap = {
  26393. // xml
  26394. xhtml: LoaderResource.XHR_RESPONSE_TYPE.DOCUMENT,
  26395. html: LoaderResource.XHR_RESPONSE_TYPE.DOCUMENT,
  26396. htm: LoaderResource.XHR_RESPONSE_TYPE.DOCUMENT,
  26397. xml: LoaderResource.XHR_RESPONSE_TYPE.DOCUMENT,
  26398. tmx: LoaderResource.XHR_RESPONSE_TYPE.DOCUMENT,
  26399. svg: LoaderResource.XHR_RESPONSE_TYPE.DOCUMENT,
  26400. // This was added to handle Tiled Tileset XML, but .tsx is also a TypeScript React Component.
  26401. // Since it is way less likely for people to be loading TypeScript files instead of Tiled files,
  26402. // this should probably be fine.
  26403. tsx: LoaderResource.XHR_RESPONSE_TYPE.DOCUMENT,
  26404. // images
  26405. gif: LoaderResource.XHR_RESPONSE_TYPE.BLOB,
  26406. png: LoaderResource.XHR_RESPONSE_TYPE.BLOB,
  26407. bmp: LoaderResource.XHR_RESPONSE_TYPE.BLOB,
  26408. jpg: LoaderResource.XHR_RESPONSE_TYPE.BLOB,
  26409. jpeg: LoaderResource.XHR_RESPONSE_TYPE.BLOB,
  26410. tif: LoaderResource.XHR_RESPONSE_TYPE.BLOB,
  26411. tiff: LoaderResource.XHR_RESPONSE_TYPE.BLOB,
  26412. webp: LoaderResource.XHR_RESPONSE_TYPE.BLOB,
  26413. tga: LoaderResource.XHR_RESPONSE_TYPE.BLOB,
  26414. // json
  26415. json: LoaderResource.XHR_RESPONSE_TYPE.JSON,
  26416. // text
  26417. text: LoaderResource.XHR_RESPONSE_TYPE.TEXT,
  26418. txt: LoaderResource.XHR_RESPONSE_TYPE.TEXT,
  26419. // fonts
  26420. ttf: LoaderResource.XHR_RESPONSE_TYPE.BUFFER,
  26421. otf: LoaderResource.XHR_RESPONSE_TYPE.BUFFER,
  26422. };
  26423. // We can't set the `src` attribute to empty string, so on abort we set it to this 1px transparent gif
  26424. LoaderResource.EMPTY_GIF = 'data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==';
  26425. })(exports.LoaderResource || (exports.LoaderResource = {}));
  26426. /**
  26427. * Smaller version of the async library constructs.
  26428. * @ignore
  26429. */
  26430. function _noop$1() {
  26431. }
  26432. /**
  26433. * Ensures a function is only called once.
  26434. * @ignore
  26435. * @param {function} fn - The function to wrap.
  26436. * @return {function} The wrapping function.
  26437. */
  26438. function onlyOnce(fn) {
  26439. return function onceWrapper() {
  26440. var arguments$1 = arguments;
  26441. var args = [];
  26442. for (var _i = 0; _i < arguments.length; _i++) {
  26443. args[_i] = arguments$1[_i];
  26444. }
  26445. if (fn === null) {
  26446. throw new Error('Callback was already called.');
  26447. }
  26448. var callFn = fn;
  26449. fn = null;
  26450. callFn.apply(this, args);
  26451. };
  26452. }
  26453. /**
  26454. * @private
  26455. * @memberof PIXI
  26456. */
  26457. var AsyncQueueItem = /** @class */ (function () {
  26458. /**
  26459. * @private
  26460. */
  26461. function AsyncQueueItem(data, callback) {
  26462. this.data = data;
  26463. this.callback = callback;
  26464. }
  26465. return AsyncQueueItem;
  26466. }());
  26467. /**
  26468. * @private
  26469. * @memberof PIXI
  26470. */
  26471. var AsyncQueue = /** @class */ (function () {
  26472. /**
  26473. * @private
  26474. */
  26475. function AsyncQueue(worker, concurrency) {
  26476. var _this = this;
  26477. if (concurrency === void 0) { concurrency = 1; }
  26478. this.workers = 0;
  26479. this.saturated = _noop$1;
  26480. this.unsaturated = _noop$1;
  26481. this.empty = _noop$1;
  26482. this.drain = _noop$1;
  26483. this.error = _noop$1;
  26484. this.started = false;
  26485. this.paused = false;
  26486. this._tasks = [];
  26487. this._insert = function (data, insertAtFront, callback) {
  26488. if (callback && typeof callback !== 'function') {
  26489. throw new Error('task callback must be a function');
  26490. }
  26491. _this.started = true;
  26492. // eslint-disable-next-line no-eq-null,eqeqeq
  26493. if (data == null && _this.idle()) {
  26494. // call drain immediately if there are no tasks
  26495. setTimeout(function () { return _this.drain(); }, 1);
  26496. return;
  26497. }
  26498. var item = new AsyncQueueItem(data, typeof callback === 'function' ? callback : _noop$1);
  26499. if (insertAtFront) {
  26500. _this._tasks.unshift(item);
  26501. }
  26502. else {
  26503. _this._tasks.push(item);
  26504. }
  26505. setTimeout(_this.process, 1);
  26506. };
  26507. this.process = function () {
  26508. while (!_this.paused && _this.workers < _this.concurrency && _this._tasks.length) {
  26509. var task = _this._tasks.shift();
  26510. if (_this._tasks.length === 0) {
  26511. _this.empty();
  26512. }
  26513. _this.workers += 1;
  26514. if (_this.workers === _this.concurrency) {
  26515. _this.saturated();
  26516. }
  26517. _this._worker(task.data, onlyOnce(_this._next(task)));
  26518. }
  26519. };
  26520. this._worker = worker;
  26521. if (concurrency === 0) {
  26522. throw new Error('Concurrency must not be zero');
  26523. }
  26524. this.concurrency = concurrency;
  26525. this.buffer = concurrency / 4.0;
  26526. }
  26527. /**
  26528. * @private
  26529. */
  26530. AsyncQueue.prototype._next = function (task) {
  26531. var _this = this;
  26532. return function () {
  26533. var arguments$1 = arguments;
  26534. var args = [];
  26535. for (var _i = 0; _i < arguments.length; _i++) {
  26536. args[_i] = arguments$1[_i];
  26537. }
  26538. _this.workers -= 1;
  26539. task.callback.apply(task, args);
  26540. // eslint-disable-next-line no-eq-null,eqeqeq
  26541. if (args[0] != null) {
  26542. _this.error(args[0], task.data);
  26543. }
  26544. if (_this.workers <= (_this.concurrency - _this.buffer)) {
  26545. _this.unsaturated();
  26546. }
  26547. if (_this.idle()) {
  26548. _this.drain();
  26549. }
  26550. _this.process();
  26551. };
  26552. };
  26553. // That was in object
  26554. // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
  26555. AsyncQueue.prototype.push = function (data, callback) {
  26556. this._insert(data, false, callback);
  26557. };
  26558. AsyncQueue.prototype.kill = function () {
  26559. this.workers = 0;
  26560. this.drain = _noop$1;
  26561. this.started = false;
  26562. this._tasks = [];
  26563. };
  26564. // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
  26565. AsyncQueue.prototype.unshift = function (data, callback) {
  26566. this._insert(data, true, callback);
  26567. };
  26568. AsyncQueue.prototype.length = function () {
  26569. return this._tasks.length;
  26570. };
  26571. AsyncQueue.prototype.running = function () {
  26572. return this.workers;
  26573. };
  26574. AsyncQueue.prototype.idle = function () {
  26575. return this._tasks.length + this.workers === 0;
  26576. };
  26577. AsyncQueue.prototype.pause = function () {
  26578. if (this.paused === true) {
  26579. return;
  26580. }
  26581. this.paused = true;
  26582. };
  26583. AsyncQueue.prototype.resume = function () {
  26584. if (this.paused === false) {
  26585. return;
  26586. }
  26587. this.paused = false;
  26588. // Need to call this.process once per concurrent
  26589. // worker to preserve full concurrency after pause
  26590. for (var w = 1; w <= this.concurrency; w++) {
  26591. this.process();
  26592. }
  26593. };
  26594. /**
  26595. * Iterates an array in series.
  26596. *
  26597. * @param {Array.<*>} array - Array to iterate.
  26598. * @param {function} iterator - Function to call for each element.
  26599. * @param {function} callback - Function to call when done, or on error.
  26600. * @param {boolean} [deferNext=false] - Break synchronous each loop by calling next with a setTimeout of 1.
  26601. */
  26602. AsyncQueue.eachSeries = function (array, iterator, callback, deferNext) {
  26603. var i = 0;
  26604. var len = array.length;
  26605. function next(err) {
  26606. if (err || i === len) {
  26607. if (callback) {
  26608. callback(err);
  26609. }
  26610. return;
  26611. }
  26612. if (deferNext) {
  26613. setTimeout(function () {
  26614. iterator(array[i++], next);
  26615. }, 1);
  26616. }
  26617. else {
  26618. iterator(array[i++], next);
  26619. }
  26620. }
  26621. next();
  26622. };
  26623. /**
  26624. * Async queue implementation,
  26625. *
  26626. * @param {function} worker - The worker function to call for each task.
  26627. * @param {number} concurrency - How many workers to run in parrallel.
  26628. * @return {*} The async queue object.
  26629. */
  26630. AsyncQueue.queue = function (worker, concurrency) {
  26631. return new AsyncQueue(worker, concurrency);
  26632. };
  26633. return AsyncQueue;
  26634. }());
  26635. // some constants
  26636. var MAX_PROGRESS = 100;
  26637. var rgxExtractUrlHash = /(#[\w-]+)?$/;
  26638. /**
  26639. * The new loader, forked from Resource Loader by Chad Engler: https://github.com/englercj/resource-loader
  26640. *
  26641. * ```js
  26642. * const loader = PIXI.Loader.shared; // PixiJS exposes a premade instance for you to use.
  26643. * //or
  26644. * const loader = new PIXI.Loader(); // you can also create your own if you want
  26645. *
  26646. * const sprites = {};
  26647. *
  26648. * // Chainable `add` to enqueue a resource
  26649. * loader.add('bunny', 'data/bunny.png')
  26650. * .add('spaceship', 'assets/spritesheet.json');
  26651. * loader.add('scoreFont', 'assets/score.fnt');
  26652. *
  26653. * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource.
  26654. * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc).
  26655. * loader.pre(cachingMiddleware);
  26656. *
  26657. * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource.
  26658. * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc).
  26659. * loader.use(parsingMiddleware);
  26660. *
  26661. * // The `load` method loads the queue of resources, and calls the passed in callback called once all
  26662. * // resources have loaded.
  26663. * loader.load((loader, resources) => {
  26664. * // resources is an object where the key is the name of the resource loaded and the value is the resource object.
  26665. * // They have a couple default properties:
  26666. * // - `url`: The URL that the resource was loaded from
  26667. * // - `error`: The error that happened when trying to load (if any)
  26668. * // - `data`: The raw data that was loaded
  26669. * // also may contain other properties based on the middleware that runs.
  26670. * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture);
  26671. * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture);
  26672. * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture);
  26673. * });
  26674. *
  26675. * // throughout the process multiple signals can be dispatched.
  26676. * loader.onProgress.add(() => {}); // called once per loaded/errored file
  26677. * loader.onError.add(() => {}); // called once per errored file
  26678. * loader.onLoad.add(() => {}); // called once per loaded file
  26679. * loader.onComplete.add(() => {}); // called once when the queued resources all load.
  26680. * ```
  26681. *
  26682. * @class Loader
  26683. * @memberof PIXI
  26684. */
  26685. var Loader = /** @class */ (function () {
  26686. /**
  26687. * @param baseUrl - The base url for all resources loaded by this loader.
  26688. * @param concurrency - The number of resources to load concurrently.
  26689. */
  26690. function Loader(baseUrl, concurrency) {
  26691. var _this = this;
  26692. if (baseUrl === void 0) { baseUrl = ''; }
  26693. if (concurrency === void 0) { concurrency = 10; }
  26694. /**
  26695. * The middleware to run before loading each resource.
  26696. */
  26697. this._beforeMiddleware = [];
  26698. /**
  26699. * The middleware to run after loading each resource.
  26700. */
  26701. this._afterMiddleware = [];
  26702. /**
  26703. * The tracks the resources we are currently completing parsing for.
  26704. */
  26705. this._resourcesParsing = [];
  26706. /**
  26707. * The `_loadResource` function bound with this object context.
  26708. *
  26709. * @private
  26710. * @member {function}
  26711. * @param {PIXI.LoaderResource} r - The resource to load
  26712. * @param {Function} d - The dequeue function
  26713. * @return {undefined}
  26714. */
  26715. this._boundLoadResource = function (r, d) { return _this._loadResource(r, d); };
  26716. /**
  26717. * All the resources for this loader keyed by name.
  26718. *
  26719. * @member {object<string, PIXI.LoaderResource>}
  26720. */
  26721. this.resources = {};
  26722. this.baseUrl = baseUrl;
  26723. this.progress = 0;
  26724. this.loading = false;
  26725. this.defaultQueryString = '';
  26726. this._beforeMiddleware = [];
  26727. this._afterMiddleware = [];
  26728. this._resourcesParsing = [];
  26729. this._boundLoadResource = function (r, d) { return _this._loadResource(r, d); };
  26730. this._queue = AsyncQueue.queue(this._boundLoadResource, concurrency);
  26731. this._queue.pause();
  26732. this.resources = {};
  26733. this.onProgress = new Signal();
  26734. this.onError = new Signal();
  26735. this.onLoad = new Signal();
  26736. this.onStart = new Signal();
  26737. this.onComplete = new Signal();
  26738. for (var i = 0; i < Loader._plugins.length; ++i) {
  26739. var plugin = Loader._plugins[i];
  26740. var pre = plugin.pre, use = plugin.use;
  26741. if (pre) {
  26742. this.pre(pre);
  26743. }
  26744. if (use) {
  26745. this.use(use);
  26746. }
  26747. }
  26748. this._protected = false;
  26749. }
  26750. /**
  26751. * Same as add, params have strict order
  26752. * @private
  26753. * @param name - The name of the resource to load.
  26754. * @param url - The url for this resource, relative to the baseUrl of this loader.
  26755. * @param options - The options for the load.
  26756. * @param callback - Function to call when this specific resource completes loading.
  26757. * @return {this} Returns itself.
  26758. */
  26759. Loader.prototype._add = function (name, url, options, callback) {
  26760. // if loading already you can only add resources that have a parent.
  26761. if (this.loading && (!options || !options.parentResource)) {
  26762. throw new Error('Cannot add resources while the loader is running.');
  26763. }
  26764. // check if resource already exists.
  26765. if (this.resources[name]) {
  26766. throw new Error("Resource named \"" + name + "\" already exists.");
  26767. }
  26768. // add base url if this isn't an absolute url
  26769. url = this._prepareUrl(url);
  26770. // create the store the resource
  26771. this.resources[name] = new exports.LoaderResource(name, url, options);
  26772. if (typeof callback === 'function') {
  26773. this.resources[name].onAfterMiddleware.once(callback);
  26774. }
  26775. // if actively loading, make sure to adjust progress chunks for that parent and its children
  26776. if (this.loading) {
  26777. var parent = options.parentResource;
  26778. var incompleteChildren = [];
  26779. for (var i = 0; i < parent.children.length; ++i) {
  26780. if (!parent.children[i].isComplete) {
  26781. incompleteChildren.push(parent.children[i]);
  26782. }
  26783. }
  26784. var fullChunk = parent.progressChunk * (incompleteChildren.length + 1); // +1 for parent
  26785. var eachChunk = fullChunk / (incompleteChildren.length + 2); // +2 for parent & new child
  26786. parent.children.push(this.resources[name]);
  26787. parent.progressChunk = eachChunk;
  26788. for (var i = 0; i < incompleteChildren.length; ++i) {
  26789. incompleteChildren[i].progressChunk = eachChunk;
  26790. }
  26791. this.resources[name].progressChunk = eachChunk;
  26792. }
  26793. // add the resource to the queue
  26794. this._queue.push(this.resources[name]);
  26795. return this;
  26796. };
  26797. /* eslint-enable require-jsdoc,valid-jsdoc */
  26798. /**
  26799. * Sets up a middleware function that will run *before* the
  26800. * resource is loaded.
  26801. *
  26802. * @param fn - The middleware function to register.
  26803. * @return Returns itself.
  26804. */
  26805. Loader.prototype.pre = function (fn) {
  26806. this._beforeMiddleware.push(fn);
  26807. return this;
  26808. };
  26809. /**
  26810. * Sets up a middleware function that will run *after* the
  26811. * resource is loaded.
  26812. *
  26813. * @param fn - The middleware function to register.
  26814. * @return Returns itself.
  26815. */
  26816. Loader.prototype.use = function (fn) {
  26817. this._afterMiddleware.push(fn);
  26818. return this;
  26819. };
  26820. /**
  26821. * Resets the queue of the loader to prepare for a new load.
  26822. *
  26823. * @return Returns itself.
  26824. */
  26825. Loader.prototype.reset = function () {
  26826. this.progress = 0;
  26827. this.loading = false;
  26828. this._queue.kill();
  26829. this._queue.pause();
  26830. // abort all resource loads
  26831. for (var k in this.resources) {
  26832. var res = this.resources[k];
  26833. if (res._onLoadBinding) {
  26834. res._onLoadBinding.detach();
  26835. }
  26836. if (res.isLoading) {
  26837. res.abort('loader reset');
  26838. }
  26839. }
  26840. this.resources = {};
  26841. return this;
  26842. };
  26843. /**
  26844. * Starts loading the queued resources.
  26845. * @param [cb] - Optional callback that will be bound to the `complete` event.
  26846. * @return Returns itself.
  26847. */
  26848. Loader.prototype.load = function (cb) {
  26849. // register complete callback if they pass one
  26850. if (typeof cb === 'function') {
  26851. this.onComplete.once(cb);
  26852. }
  26853. // if the queue has already started we are done here
  26854. if (this.loading) {
  26855. return this;
  26856. }
  26857. if (this._queue.idle()) {
  26858. this._onStart();
  26859. this._onComplete();
  26860. }
  26861. else {
  26862. // distribute progress chunks
  26863. var numTasks = this._queue._tasks.length;
  26864. var chunk = MAX_PROGRESS / numTasks;
  26865. for (var i = 0; i < this._queue._tasks.length; ++i) {
  26866. this._queue._tasks[i].data.progressChunk = chunk;
  26867. }
  26868. // notify we are starting
  26869. this._onStart();
  26870. // start loading
  26871. this._queue.resume();
  26872. }
  26873. return this;
  26874. };
  26875. Object.defineProperty(Loader.prototype, "concurrency", {
  26876. /**
  26877. * The number of resources to load concurrently.
  26878. *
  26879. * @member {number}
  26880. * @default 10
  26881. */
  26882. get: function () {
  26883. return this._queue.concurrency;
  26884. },
  26885. // eslint-disable-next-line require-jsdoc
  26886. set: function (concurrency) {
  26887. this._queue.concurrency = concurrency;
  26888. },
  26889. enumerable: false,
  26890. configurable: true
  26891. });
  26892. /**
  26893. * Prepares a url for usage based on the configuration of this object
  26894. * @param url - The url to prepare.
  26895. * @return The prepared url.
  26896. */
  26897. Loader.prototype._prepareUrl = function (url) {
  26898. var parsedUrl = parseUri(url, { strictMode: true });
  26899. var result;
  26900. // absolute url, just use it as is.
  26901. if (parsedUrl.protocol || !parsedUrl.path || url.indexOf('//') === 0) {
  26902. result = url;
  26903. }
  26904. // if baseUrl doesn't end in slash and url doesn't start with slash, then add a slash inbetween
  26905. else if (this.baseUrl.length
  26906. && this.baseUrl.lastIndexOf('/') !== this.baseUrl.length - 1
  26907. && url.charAt(0) !== '/') {
  26908. result = this.baseUrl + "/" + url;
  26909. }
  26910. else {
  26911. result = this.baseUrl + url;
  26912. }
  26913. // if we need to add a default querystring, there is a bit more work
  26914. if (this.defaultQueryString) {
  26915. var hash = rgxExtractUrlHash.exec(result)[0];
  26916. result = result.substr(0, result.length - hash.length);
  26917. if (result.indexOf('?') !== -1) {
  26918. result += "&" + this.defaultQueryString;
  26919. }
  26920. else {
  26921. result += "?" + this.defaultQueryString;
  26922. }
  26923. result += hash;
  26924. }
  26925. return result;
  26926. };
  26927. /**
  26928. * Loads a single resource.
  26929. *
  26930. * @private
  26931. * @param {PIXI.LoaderResource} resource - The resource to load.
  26932. * @param {function} dequeue - The function to call when we need to dequeue this item.
  26933. */
  26934. Loader.prototype._loadResource = function (resource, dequeue) {
  26935. var _this = this;
  26936. resource._dequeue = dequeue;
  26937. // run before middleware
  26938. AsyncQueue.eachSeries(this._beforeMiddleware, function (fn, next) {
  26939. fn.call(_this, resource, function () {
  26940. // if the before middleware marks the resource as complete,
  26941. // break and don't process any more before middleware
  26942. next(resource.isComplete ? {} : null);
  26943. });
  26944. }, function () {
  26945. if (resource.isComplete) {
  26946. _this._onLoad(resource);
  26947. }
  26948. else {
  26949. resource._onLoadBinding = resource.onComplete.once(_this._onLoad, _this);
  26950. resource.load();
  26951. }
  26952. }, true);
  26953. };
  26954. /**
  26955. * Called once loading has started.
  26956. */
  26957. Loader.prototype._onStart = function () {
  26958. this.progress = 0;
  26959. this.loading = true;
  26960. this.onStart.dispatch(this);
  26961. };
  26962. /**
  26963. * Called once each resource has loaded.
  26964. */
  26965. Loader.prototype._onComplete = function () {
  26966. this.progress = MAX_PROGRESS;
  26967. this.loading = false;
  26968. this.onComplete.dispatch(this, this.resources);
  26969. };
  26970. /**
  26971. * Called each time a resources is loaded.
  26972. * @param resource - The resource that was loaded
  26973. */
  26974. Loader.prototype._onLoad = function (resource) {
  26975. var _this = this;
  26976. resource._onLoadBinding = null;
  26977. // remove this resource from the async queue, and add it to our list of resources that are being parsed
  26978. this._resourcesParsing.push(resource);
  26979. resource._dequeue();
  26980. // run all the after middleware for this resource
  26981. AsyncQueue.eachSeries(this._afterMiddleware, function (fn, next) {
  26982. fn.call(_this, resource, next);
  26983. }, function () {
  26984. resource.onAfterMiddleware.dispatch(resource);
  26985. _this.progress = Math.min(MAX_PROGRESS, _this.progress + resource.progressChunk);
  26986. _this.onProgress.dispatch(_this, resource);
  26987. if (resource.error) {
  26988. _this.onError.dispatch(resource.error, _this, resource);
  26989. }
  26990. else {
  26991. _this.onLoad.dispatch(_this, resource);
  26992. }
  26993. _this._resourcesParsing.splice(_this._resourcesParsing.indexOf(resource), 1);
  26994. // do completion check
  26995. if (_this._queue.idle() && _this._resourcesParsing.length === 0) {
  26996. _this._onComplete();
  26997. }
  26998. }, true);
  26999. };
  27000. /**
  27001. * Destroy the loader, removes references.
  27002. */
  27003. Loader.prototype.destroy = function () {
  27004. if (!this._protected) {
  27005. this.reset();
  27006. }
  27007. };
  27008. Object.defineProperty(Loader, "shared", {
  27009. /**
  27010. * A premade instance of the loader that can be used to load resources.
  27011. */
  27012. get: function () {
  27013. var shared = Loader._shared;
  27014. if (!shared) {
  27015. shared = new Loader();
  27016. shared._protected = true;
  27017. Loader._shared = shared;
  27018. }
  27019. return shared;
  27020. },
  27021. enumerable: false,
  27022. configurable: true
  27023. });
  27024. /**
  27025. * Adds a Loader plugin for the global shared loader and all
  27026. * new Loader instances created.
  27027. *
  27028. * @param plugin - The plugin to add
  27029. * @return Reference to PIXI.Loader for chaining
  27030. */
  27031. Loader.registerPlugin = function (plugin) {
  27032. Loader._plugins.push(plugin);
  27033. if (plugin.add) {
  27034. plugin.add();
  27035. }
  27036. return Loader;
  27037. };
  27038. Loader._plugins = [];
  27039. return Loader;
  27040. }());
  27041. Loader.prototype.add = function add(name, url, options, callback) {
  27042. // special case of an array of objects or urls
  27043. if (Array.isArray(name)) {
  27044. for (var i = 0; i < name.length; ++i) {
  27045. this.add(name[i]);
  27046. }
  27047. return this;
  27048. }
  27049. // if an object is passed instead of params
  27050. if (typeof name === 'object') {
  27051. options = name;
  27052. callback = url || options.callback || options.onComplete;
  27053. url = options.url;
  27054. name = options.name || options.key || options.url;
  27055. }
  27056. // case where no name is passed shift all args over by one.
  27057. if (typeof url !== 'string') {
  27058. callback = options;
  27059. options = url;
  27060. url = name;
  27061. }
  27062. // now that we shifted make sure we have a proper url.
  27063. if (typeof url !== 'string') {
  27064. throw new Error('No url passed to add resource to loader.');
  27065. }
  27066. // options are optional so people might pass a function and no options
  27067. if (typeof options === 'function') {
  27068. callback = options;
  27069. options = null;
  27070. }
  27071. return this._add(name, url, options, callback);
  27072. };
  27073. /**
  27074. * Application plugin for supporting loader option. Installing the LoaderPlugin
  27075. * is not necessary if using **pixi.js** or **pixi.js-legacy**.
  27076. * @example
  27077. * import {AppLoaderPlugin} from '@pixi/loaders';
  27078. * import {Application} from '@pixi/app';
  27079. * Application.registerPlugin(AppLoaderPlugin);
  27080. * @class
  27081. * @memberof PIXI
  27082. */
  27083. var AppLoaderPlugin = /** @class */ (function () {
  27084. function AppLoaderPlugin() {
  27085. }
  27086. /**
  27087. * Called on application constructor
  27088. * @param {object} options
  27089. * @private
  27090. */
  27091. AppLoaderPlugin.init = function (options) {
  27092. options = Object.assign({
  27093. sharedLoader: false,
  27094. }, options);
  27095. /**
  27096. * Loader instance to help with asset loading.
  27097. * @memberof PIXI.Application#
  27098. * @type {PIXI.Loader}
  27099. * @readonly
  27100. */
  27101. this.loader = options.sharedLoader ? Loader.shared : new Loader();
  27102. };
  27103. /**
  27104. * Called when application destroyed
  27105. *
  27106. * @private
  27107. */
  27108. AppLoaderPlugin.destroy = function () {
  27109. if (this.loader) {
  27110. this.loader.destroy();
  27111. this.loader = null;
  27112. }
  27113. };
  27114. return AppLoaderPlugin;
  27115. }());
  27116. /**
  27117. * Loader plugin for handling Texture resources.
  27118. *
  27119. * @memberof PIXI
  27120. */
  27121. var TextureLoader = /** @class */ (function () {
  27122. function TextureLoader() {
  27123. }
  27124. /**
  27125. * Handle SVG elements a text, render with SVGResource.
  27126. */
  27127. TextureLoader.add = function () {
  27128. exports.LoaderResource.setExtensionLoadType('svg', exports.LoaderResource.LOAD_TYPE.XHR);
  27129. exports.LoaderResource.setExtensionXhrType('svg', exports.LoaderResource.XHR_RESPONSE_TYPE.TEXT);
  27130. };
  27131. /**
  27132. * Called after a resource is loaded.
  27133. * @see PIXI.Loader.loaderMiddleware
  27134. * @param resource
  27135. * @param {function} next
  27136. */
  27137. TextureLoader.use = function (resource, next) {
  27138. // create a new texture if the data is an Image object
  27139. if (resource.data && (resource.type === exports.LoaderResource.TYPE.IMAGE || resource.extension === 'svg')) {
  27140. var data = resource.data, url = resource.url, name = resource.name, metadata = resource.metadata;
  27141. Texture.fromLoader(data, url, name, metadata).then(function (texture) {
  27142. resource.texture = texture;
  27143. next();
  27144. })
  27145. // TODO: handle errors in Texture.fromLoader
  27146. // so we can pass them to the Loader
  27147. .catch(next);
  27148. }
  27149. else {
  27150. next();
  27151. }
  27152. };
  27153. return TextureLoader;
  27154. }());
  27155. var _keyStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
  27156. /**
  27157. * Encodes binary into base64.
  27158. *
  27159. * @function encodeBinary
  27160. * @param {string} input - The input data to encode.
  27161. * @returns {string} The encoded base64 string
  27162. */
  27163. function encodeBinary(input) {
  27164. var output = '';
  27165. var inx = 0;
  27166. while (inx < input.length) {
  27167. // Fill byte buffer array
  27168. var bytebuffer = [0, 0, 0];
  27169. var encodedCharIndexes = [0, 0, 0, 0];
  27170. for (var jnx = 0; jnx < bytebuffer.length; ++jnx) {
  27171. if (inx < input.length) {
  27172. // throw away high-order byte, as documented at:
  27173. // https://developer.mozilla.org/En/Using_XMLHttpRequest#Handling_binary_data
  27174. bytebuffer[jnx] = input.charCodeAt(inx++) & 0xff;
  27175. }
  27176. else {
  27177. bytebuffer[jnx] = 0;
  27178. }
  27179. }
  27180. // Get each encoded character, 6 bits at a time
  27181. // index 1: first 6 bits
  27182. encodedCharIndexes[0] = bytebuffer[0] >> 2;
  27183. // index 2: second 6 bits (2 least significant bits from input byte 1 + 4 most significant bits from byte 2)
  27184. encodedCharIndexes[1] = ((bytebuffer[0] & 0x3) << 4) | (bytebuffer[1] >> 4);
  27185. // index 3: third 6 bits (4 least significant bits from input byte 2 + 2 most significant bits from byte 3)
  27186. encodedCharIndexes[2] = ((bytebuffer[1] & 0x0f) << 2) | (bytebuffer[2] >> 6);
  27187. // index 3: forth 6 bits (6 least significant bits from input byte 3)
  27188. encodedCharIndexes[3] = bytebuffer[2] & 0x3f;
  27189. // Determine whether padding happened, and adjust accordingly
  27190. var paddingBytes = inx - (input.length - 1);
  27191. switch (paddingBytes) {
  27192. case 2:
  27193. // Set last 2 characters to padding char
  27194. encodedCharIndexes[3] = 64;
  27195. encodedCharIndexes[2] = 64;
  27196. break;
  27197. case 1:
  27198. // Set last character to padding char
  27199. encodedCharIndexes[3] = 64;
  27200. break;
  27201. }
  27202. // Now we will grab each appropriate character out of our keystring
  27203. // based on our index array and append it to the output string
  27204. for (var jnx = 0; jnx < encodedCharIndexes.length; ++jnx) {
  27205. output += _keyStr.charAt(encodedCharIndexes[jnx]);
  27206. }
  27207. }
  27208. return output;
  27209. }
  27210. var Url$1 = self.URL || self.webkitURL;
  27211. /**
  27212. * A middleware for transforming XHR loaded Blobs into more useful objects
  27213. *
  27214. * @ignore
  27215. * @function parsing
  27216. * @example
  27217. * import { Loader, middleware } from 'resource-loader';
  27218. * const loader = new Loader();
  27219. * loader.use(middleware.parsing);
  27220. * @param resource - Current Resource
  27221. * @param next - Callback when complete
  27222. */
  27223. function parsing(resource, next) {
  27224. if (!resource.data) {
  27225. next();
  27226. return;
  27227. }
  27228. // if this was an XHR load of a blob
  27229. if (resource.xhr && resource.xhrType === exports.LoaderResource.XHR_RESPONSE_TYPE.BLOB) {
  27230. // if there is no blob support we probably got a binary string back
  27231. if (!self.Blob || typeof resource.data === 'string') {
  27232. var type = resource.xhr.getResponseHeader('content-type');
  27233. // this is an image, convert the binary string into a data url
  27234. if (type && type.indexOf('image') === 0) {
  27235. resource.data = new Image();
  27236. resource.data.src = "data:" + type + ";base64," + encodeBinary(resource.xhr.responseText);
  27237. resource.type = exports.LoaderResource.TYPE.IMAGE;
  27238. // wait until the image loads and then callback
  27239. resource.data.onload = function () {
  27240. resource.data.onload = null;
  27241. next();
  27242. };
  27243. // next will be called on load
  27244. return;
  27245. }
  27246. }
  27247. // if content type says this is an image, then we should transform the blob into an Image object
  27248. else if (resource.data.type.indexOf('image') === 0) {
  27249. var src_1 = Url$1.createObjectURL(resource.data);
  27250. resource.blob = resource.data;
  27251. resource.data = new Image();
  27252. resource.data.src = src_1;
  27253. resource.type = exports.LoaderResource.TYPE.IMAGE;
  27254. // cleanup the no longer used blob after the image loads
  27255. // TODO: Is this correct? Will the image be invalid after revoking?
  27256. resource.data.onload = function () {
  27257. Url$1.revokeObjectURL(src_1);
  27258. resource.data.onload = null;
  27259. next();
  27260. };
  27261. // next will be called on load.
  27262. return;
  27263. }
  27264. }
  27265. next();
  27266. }
  27267. // parse any blob into more usable objects (e.g. Image)
  27268. Loader.registerPlugin({ use: parsing });
  27269. // parse any Image objects into textures
  27270. Loader.registerPlugin(TextureLoader);
  27271. /*!
  27272. * @pixi/compressed-textures - v6.1.2
  27273. * Compiled Thu, 12 Aug 2021 17:11:19 UTC
  27274. *
  27275. * @pixi/compressed-textures is licensed under the MIT License.
  27276. * http://www.opensource.org/licenses/mit-license
  27277. */
  27278. var _a;
  27279. /**
  27280. * WebGL internal formats, including compressed texture formats provided by extensions
  27281. *
  27282. * @memberof PIXI
  27283. * @static
  27284. * @name INTERNAL_FORMATS
  27285. * @enum {number}
  27286. * @property {number} COMPRESSED_RGB_S3TC_DXT1_EXT=0x83F0
  27287. * @property {number} COMPRESSED_RGBA_S3TC_DXT1_EXT=0x83F1
  27288. * @property {number} COMPRESSED_RGBA_S3TC_DXT3_EXT=0x83F2
  27289. * @property {number} COMPRESSED_RGBA_S3TC_DXT5_EXT=0x83F3
  27290. * @property {number} COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT=35917
  27291. * @property {number} COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT=35918
  27292. * @property {number} COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT=35919
  27293. * @property {number} COMPRESSED_SRGB_S3TC_DXT1_EXT=35916
  27294. * @property {number} COMPRESSED_R11_EAC=0x9270
  27295. * @property {number} COMPRESSED_SIGNED_R11_EAC=0x9271
  27296. * @property {number} COMPRESSED_RG11_EAC=0x9272
  27297. * @property {number} COMPRESSED_SIGNED_RG11_EAC=0x9273
  27298. * @property {number} COMPRESSED_RGB8_ETC2=0x9274
  27299. * @property {number} COMPRESSED_RGBA8_ETC2_EAC=0x9278
  27300. * @property {number} COMPRESSED_SRGB8_ETC2=0x9275
  27301. * @property {number} COMPRESSED_SRGB8_ALPHA8_ETC2_EAC=0x9279
  27302. * @property {number} COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2=0x9276
  27303. * @property {number} COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2=0x9277
  27304. * @property {number} COMPRESSED_RGB_PVRTC_4BPPV1_IMG=0x8C00
  27305. * @property {number} COMPRESSED_RGBA_PVRTC_4BPPV1_IMG=0x8C02
  27306. * @property {number} COMPRESSED_RGB_PVRTC_2BPPV1_IMG=0x8C01
  27307. * @property {number} COMPRESSED_RGBA_PVRTC_2BPPV1_IMG=0x8C03
  27308. * @property {number} COMPRESSED_RGB_ETC1_WEBGL=0x8D64
  27309. * @property {number} COMPRESSED_RGB_ATC_WEBGL=0x8C92
  27310. * @property {number} COMPRESSED_RGBA_ATC_EXPLICIT_ALPHA_WEBGL=0x8C92
  27311. * @property {number} COMPRESSED_RGBA_ATC_INTERPOLATED_ALPHA_WEBGL=0x87EE
  27312. */
  27313. (function (INTERNAL_FORMATS) {
  27314. // WEBGL_compressed_texture_s3tc
  27315. INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_RGB_S3TC_DXT1_EXT"] = 33776] = "COMPRESSED_RGB_S3TC_DXT1_EXT";
  27316. INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_RGBA_S3TC_DXT1_EXT"] = 33777] = "COMPRESSED_RGBA_S3TC_DXT1_EXT";
  27317. INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_RGBA_S3TC_DXT3_EXT"] = 33778] = "COMPRESSED_RGBA_S3TC_DXT3_EXT";
  27318. INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_RGBA_S3TC_DXT5_EXT"] = 33779] = "COMPRESSED_RGBA_S3TC_DXT5_EXT";
  27319. // WEBGL_compressed_texture_s3tc_srgb
  27320. INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT"] = 35917] = "COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT";
  27321. INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT"] = 35918] = "COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT";
  27322. INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT"] = 35919] = "COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT";
  27323. INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_SRGB_S3TC_DXT1_EXT"] = 35916] = "COMPRESSED_SRGB_S3TC_DXT1_EXT";
  27324. // WEBGL_compressed_texture_etc
  27325. INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_R11_EAC"] = 37488] = "COMPRESSED_R11_EAC";
  27326. INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_SIGNED_R11_EAC"] = 37489] = "COMPRESSED_SIGNED_R11_EAC";
  27327. INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_RG11_EAC"] = 37490] = "COMPRESSED_RG11_EAC";
  27328. INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_SIGNED_RG11_EAC"] = 37491] = "COMPRESSED_SIGNED_RG11_EAC";
  27329. INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_RGB8_ETC2"] = 37492] = "COMPRESSED_RGB8_ETC2";
  27330. INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_RGBA8_ETC2_EAC"] = 37496] = "COMPRESSED_RGBA8_ETC2_EAC";
  27331. INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_SRGB8_ETC2"] = 37493] = "COMPRESSED_SRGB8_ETC2";
  27332. INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_SRGB8_ALPHA8_ETC2_EAC"] = 37497] = "COMPRESSED_SRGB8_ALPHA8_ETC2_EAC";
  27333. INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2"] = 37494] = "COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2";
  27334. INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2"] = 37495] = "COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2";
  27335. // WEBGL_compressed_texture_pvrtc
  27336. INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_RGB_PVRTC_4BPPV1_IMG"] = 35840] = "COMPRESSED_RGB_PVRTC_4BPPV1_IMG";
  27337. INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_RGBA_PVRTC_4BPPV1_IMG"] = 35842] = "COMPRESSED_RGBA_PVRTC_4BPPV1_IMG";
  27338. INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_RGB_PVRTC_2BPPV1_IMG"] = 35841] = "COMPRESSED_RGB_PVRTC_2BPPV1_IMG";
  27339. INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_RGBA_PVRTC_2BPPV1_IMG"] = 35843] = "COMPRESSED_RGBA_PVRTC_2BPPV1_IMG";
  27340. // WEBGL_compressed_texture_etc1
  27341. INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_RGB_ETC1_WEBGL"] = 36196] = "COMPRESSED_RGB_ETC1_WEBGL";
  27342. // WEBGL_compressed_texture_atc
  27343. INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_RGB_ATC_WEBGL"] = 35986] = "COMPRESSED_RGB_ATC_WEBGL";
  27344. INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_RGBA_ATC_EXPLICIT_ALPHA_WEBGL"] = 35986] = "COMPRESSED_RGBA_ATC_EXPLICIT_ALPHA_WEBGL";
  27345. INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_RGBA_ATC_INTERPOLATED_ALPHA_WEBGL"] = 34798] = "COMPRESSED_RGBA_ATC_INTERPOLATED_ALPHA_WEBGL";
  27346. })(exports.INTERNAL_FORMATS || (exports.INTERNAL_FORMATS = {}));
  27347. /**
  27348. * Maps the compressed texture formats in {@link PIXI.INTERNAL_FORMATS} to the number of bytes taken by
  27349. * each texel.
  27350. *
  27351. * @memberof PIXI
  27352. * @static
  27353. * @ignore
  27354. */
  27355. var INTERNAL_FORMAT_TO_BYTES_PER_PIXEL = (_a = {},
  27356. // WEBGL_compressed_texture_s3tc
  27357. _a[exports.INTERNAL_FORMATS.COMPRESSED_RGB_S3TC_DXT1_EXT] = 0.5,
  27358. _a[exports.INTERNAL_FORMATS.COMPRESSED_RGBA_S3TC_DXT1_EXT] = 0.5,
  27359. _a[exports.INTERNAL_FORMATS.COMPRESSED_RGBA_S3TC_DXT3_EXT] = 1,
  27360. _a[exports.INTERNAL_FORMATS.COMPRESSED_RGBA_S3TC_DXT5_EXT] = 1,
  27361. // WEBGL_compressed_texture_s3tc
  27362. _a[exports.INTERNAL_FORMATS.COMPRESSED_SRGB_S3TC_DXT1_EXT] = 0.5,
  27363. _a[exports.INTERNAL_FORMATS.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT] = 0.5,
  27364. _a[exports.INTERNAL_FORMATS.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT] = 1,
  27365. _a[exports.INTERNAL_FORMATS.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT] = 1,
  27366. // WEBGL_compressed_texture_etc
  27367. _a[exports.INTERNAL_FORMATS.COMPRESSED_R11_EAC] = 0.5,
  27368. _a[exports.INTERNAL_FORMATS.COMPRESSED_SIGNED_R11_EAC] = 0.5,
  27369. _a[exports.INTERNAL_FORMATS.COMPRESSED_RG11_EAC] = 1,
  27370. _a[exports.INTERNAL_FORMATS.COMPRESSED_SIGNED_RG11_EAC] = 1,
  27371. _a[exports.INTERNAL_FORMATS.COMPRESSED_RGB8_ETC2] = 0.5,
  27372. _a[exports.INTERNAL_FORMATS.COMPRESSED_RGBA8_ETC2_EAC] = 1,
  27373. _a[exports.INTERNAL_FORMATS.COMPRESSED_SRGB8_ETC2] = 0.5,
  27374. _a[exports.INTERNAL_FORMATS.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC] = 1,
  27375. _a[exports.INTERNAL_FORMATS.COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2] = 0.5,
  27376. _a[exports.INTERNAL_FORMATS.COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2] = 0.5,
  27377. // WEBGL_compressed_texture_pvrtc
  27378. _a[exports.INTERNAL_FORMATS.COMPRESSED_RGB_PVRTC_4BPPV1_IMG] = 0.5,
  27379. _a[exports.INTERNAL_FORMATS.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG] = 0.5,
  27380. _a[exports.INTERNAL_FORMATS.COMPRESSED_RGB_PVRTC_2BPPV1_IMG] = 0.25,
  27381. _a[exports.INTERNAL_FORMATS.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG] = 0.25,
  27382. // WEBGL_compressed_texture_etc1
  27383. _a[exports.INTERNAL_FORMATS.COMPRESSED_RGB_ETC1_WEBGL] = 0.5,
  27384. // @see https://www.khronos.org/registry/OpenGL/extensions/AMD/AMD_compressed_ATC_texture.txt
  27385. // WEBGL_compressed_texture_atc
  27386. _a[exports.INTERNAL_FORMATS.COMPRESSED_RGB_ATC_WEBGL] = 0.5,
  27387. _a[exports.INTERNAL_FORMATS.COMPRESSED_RGBA_ATC_EXPLICIT_ALPHA_WEBGL] = 1,
  27388. _a[exports.INTERNAL_FORMATS.COMPRESSED_RGBA_ATC_INTERPOLATED_ALPHA_WEBGL] = 1,
  27389. _a);
  27390. /*! *****************************************************************************
  27391. Copyright (c) Microsoft Corporation. All rights reserved.
  27392. Licensed under the Apache License, Version 2.0 (the "License"); you may not use
  27393. this file except in compliance with the License. You may obtain a copy of the
  27394. License at http://www.apache.org/licenses/LICENSE-2.0
  27395. THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  27396. KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
  27397. WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
  27398. MERCHANTABLITY OR NON-INFRINGEMENT.
  27399. See the Apache Version 2.0 License for specific language governing permissions
  27400. and limitations under the License.
  27401. ***************************************************************************** */
  27402. /* global Reflect, Promise */
  27403. var extendStatics$3 = function(d, b) {
  27404. extendStatics$3 = Object.setPrototypeOf ||
  27405. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  27406. function (d, b) { for (var p in b) { if (b.hasOwnProperty(p)) { d[p] = b[p]; } } };
  27407. return extendStatics$3(d, b);
  27408. };
  27409. function __extends$3(d, b) {
  27410. extendStatics$3(d, b);
  27411. function __() { this.constructor = d; }
  27412. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  27413. }
  27414. function __awaiter(thisArg, _arguments, P, generator) {
  27415. return new (P || (P = Promise))(function (resolve, reject) {
  27416. function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
  27417. function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
  27418. function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
  27419. step((generator = generator.apply(thisArg, _arguments || [])).next());
  27420. });
  27421. }
  27422. function __generator(thisArg, body) {
  27423. var _ = { label: 0, sent: function() { if (t[0] & 1) { throw t[1]; } return t[1]; }, trys: [], ops: [] }, f, y, t, g;
  27424. return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
  27425. function verb(n) { return function (v) { return step([n, v]); }; }
  27426. function step(op) {
  27427. if (f) { throw new TypeError("Generator is already executing."); }
  27428. while (_) { try {
  27429. if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) { return t; }
  27430. if (y = 0, t) { op = [op[0] & 2, t.value]; }
  27431. switch (op[0]) {
  27432. case 0: case 1: t = op; break;
  27433. case 4: _.label++; return { value: op[1], done: false };
  27434. case 5: _.label++; y = op[1]; op = [0]; continue;
  27435. case 7: op = _.ops.pop(); _.trys.pop(); continue;
  27436. default:
  27437. if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
  27438. if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
  27439. if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
  27440. if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
  27441. if (t[2]) { _.ops.pop(); }
  27442. _.trys.pop(); continue;
  27443. }
  27444. op = body.call(thisArg, _);
  27445. } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } }
  27446. if (op[0] & 5) { throw op[1]; } return { value: op[0] ? op[1] : void 0, done: true };
  27447. }
  27448. }
  27449. /**
  27450. * Resource that fetches texture data over the network and stores it in a buffer.
  27451. *
  27452. * @class
  27453. * @extends PIXI.Resource
  27454. * @memberof PIXI
  27455. */
  27456. var BlobResource = /** @class */ (function (_super) {
  27457. __extends$3(BlobResource, _super);
  27458. /**
  27459. * @param {string} url - the URL of the texture file
  27460. * @param {boolean}[autoLoad] - whether to fetch the data immediately;
  27461. * you can fetch it later via {@link BlobResource#load}
  27462. */
  27463. function BlobResource(source, options) {
  27464. if (options === void 0) { options = { width: 1, height: 1, autoLoad: true }; }
  27465. var _this = this;
  27466. var origin;
  27467. var data;
  27468. if (typeof source === 'string') {
  27469. origin = source;
  27470. data = new Uint8Array();
  27471. }
  27472. else {
  27473. origin = null;
  27474. data = source;
  27475. }
  27476. _this = _super.call(this, data, options) || this;
  27477. /**
  27478. * The URL of the texture file
  27479. * @member {string}
  27480. */
  27481. _this.origin = origin;
  27482. /**
  27483. * The viewable buffer on the data
  27484. * @member {ViewableBuffer}
  27485. */
  27486. // HINT: BlobResource allows "null" sources, assuming the child class provides an alternative
  27487. _this.buffer = data ? new ViewableBuffer(data) : null;
  27488. // Allow autoLoad = "undefined" still load the resource by default
  27489. if (_this.origin && options.autoLoad !== false) {
  27490. _this.load();
  27491. }
  27492. if (data && data.length) {
  27493. _this.loaded = true;
  27494. _this.onBlobLoaded(_this.buffer.rawBinaryData);
  27495. }
  27496. return _this;
  27497. }
  27498. BlobResource.prototype.onBlobLoaded = function (_data) {
  27499. // TODO: Override this method
  27500. };
  27501. /**
  27502. * Loads the blob
  27503. */
  27504. BlobResource.prototype.load = function () {
  27505. return __awaiter(this, void 0, Promise, function () {
  27506. var response, blob, arrayBuffer;
  27507. return __generator(this, function (_a) {
  27508. switch (_a.label) {
  27509. case 0: return [4 /*yield*/, fetch(this.origin)];
  27510. case 1:
  27511. response = _a.sent();
  27512. return [4 /*yield*/, response.blob()];
  27513. case 2:
  27514. blob = _a.sent();
  27515. return [4 /*yield*/, blob.arrayBuffer()];
  27516. case 3:
  27517. arrayBuffer = _a.sent();
  27518. this.data = new Uint32Array(arrayBuffer);
  27519. this.buffer = new ViewableBuffer(arrayBuffer);
  27520. this.loaded = true;
  27521. this.onBlobLoaded(arrayBuffer);
  27522. this.update();
  27523. return [2 /*return*/, this];
  27524. }
  27525. });
  27526. });
  27527. };
  27528. return BlobResource;
  27529. }(BufferResource));
  27530. /**
  27531. * Resource for compressed texture formats, as follows: S3TC/DXTn (& their sRGB formats), ATC, ASTC, ETC 1/2, PVRTC.
  27532. *
  27533. * Compressed textures improve performance when rendering is texture-bound. The texture data stays compressed in
  27534. * graphics memory, increasing memory locality and speeding up texture fetches. These formats can also be used to store
  27535. * more detail in the same amount of memory.
  27536. *
  27537. * For most developers, container file formats are a better abstraction instead of directly handling raw texture
  27538. * data. PixiJS provides native support for the following texture file formats (via {@link PIXI.Loader}):
  27539. *
  27540. * * **.dds** - the DirectDraw Surface file format stores DXTn (DXT-1,3,5) data. See {@link PIXI.DDSLoader}
  27541. * * **.ktx** - the Khronos Texture Container file format supports storing all the supported WebGL compression formats.
  27542. * See {@link PIXI.KTXLoader}.
  27543. * * **.basis** - the BASIS supercompressed file format stores texture data in an internal format that is transcoded
  27544. * to the compression format supported on the device at _runtime_. It also supports transcoding into a uncompressed
  27545. * format as a fallback; you must install the `@pixi/basis-loader`, `@pixi/basis-transcoder` packages separately to
  27546. * use these files. See {@link PIXI.BasisLoader}.
  27547. *
  27548. * The loaders for the aforementioned formats use `CompressedTextureResource` internally. It is strongly suggested that
  27549. * they be used instead.
  27550. *
  27551. * ## Working directly with CompressedTextureResource
  27552. *
  27553. * Since `CompressedTextureResource` inherits `BlobResource`, you can provide it a URL pointing to a file containing
  27554. * the raw texture data (with no file headers!):
  27555. *
  27556. * ```js
  27557. * // The resource backing the texture data for your textures.
  27558. * // NOTE: You can also provide a ArrayBufferView instead of a URL. This is used when loading data from a container file
  27559. * // format such as KTX, DDS, or BASIS.
  27560. * const compressedResource = new PIXI.CompressedTextureResource("bunny.dxt5", {
  27561. * format: PIXI.INTERNAL_FORMATS.COMPRESSED_RGBA_S3TC_DXT5_EXT,
  27562. * width: 256,
  27563. * height: 256
  27564. * });
  27565. *
  27566. * // You can create a base-texture to the cache, so that future `Texture`s can be created using the `Texture.from` API.
  27567. * const baseTexture = new PIXI.BaseTexture(compressedResource, { pmaMode: PIXI.ALPHA_MODES.NPM });
  27568. *
  27569. * // Create a Texture to add to the TextureCache
  27570. * const texture = new PIXI.Texture(baseTexture);
  27571. *
  27572. * // Add baseTexture & texture to the global texture cache
  27573. * PIXI.BaseTexture.addToCache(baseTexture, "bunny.dxt5");
  27574. * PIXI.Texture.addToCache(texture, "bunny.dxt5");
  27575. * ```
  27576. *
  27577. * @memberof PIXI
  27578. */
  27579. var CompressedTextureResource = /** @class */ (function (_super) {
  27580. __extends$3(CompressedTextureResource, _super);
  27581. /**
  27582. * @param source - the buffer/URL holding the compressed texture data
  27583. * @param options
  27584. * @param {PIXI.INTERNAL_FORMATS} options.format - the compression format
  27585. * @param {number} options.width - the image width in pixels.
  27586. * @param {number} options.height - the image height in pixels.
  27587. * @param {number} [options.level=1] - the mipmap levels stored in the compressed texture, including level 0.
  27588. * @param {number} [options.levelBuffers] - the buffers for each mipmap level. `CompressedTextureResource` can allows you
  27589. * to pass `null` for `source`, for cases where each level is stored in non-contiguous memory.
  27590. */
  27591. function CompressedTextureResource(source, options) {
  27592. var _this = _super.call(this, source, options) || this;
  27593. _this.format = options.format;
  27594. _this.levels = options.levels || 1;
  27595. _this._width = options.width;
  27596. _this._height = options.height;
  27597. _this._extension = CompressedTextureResource._formatToExtension(_this.format);
  27598. if (options.levelBuffers || _this.buffer) {
  27599. // ViewableBuffer doesn't support byteOffset :-( so allow source to be Uint8Array
  27600. _this._levelBuffers = options.levelBuffers
  27601. || CompressedTextureResource._createLevelBuffers(source instanceof Uint8Array ? source : _this.buffer.uint8View, _this.format, _this.levels, 4, 4, // PVRTC has 8x4 blocks in 2bpp mode
  27602. _this.width, _this.height);
  27603. }
  27604. return _this;
  27605. }
  27606. /**
  27607. * @override
  27608. * @param renderer - A reference to the current renderer
  27609. * @param _texture - the texture
  27610. * @param _glTexture - texture instance for this webgl context
  27611. */
  27612. CompressedTextureResource.prototype.upload = function (renderer, _texture, _glTexture) {
  27613. var gl = renderer.gl;
  27614. var extension = renderer.context.extensions[this._extension];
  27615. if (!extension) {
  27616. throw new Error(this._extension + " textures are not supported on the current machine");
  27617. }
  27618. if (!this._levelBuffers) {
  27619. // Do not try to upload data before BlobResource loads, unless the levelBuffers were provided directly!
  27620. return false;
  27621. }
  27622. for (var i = 0, j = this.levels; i < j; i++) {
  27623. var _a = this._levelBuffers[i], levelID = _a.levelID, levelWidth = _a.levelWidth, levelHeight = _a.levelHeight, levelBuffer = _a.levelBuffer;
  27624. gl.compressedTexImage2D(gl.TEXTURE_2D, levelID, this.format, levelWidth, levelHeight, 0, levelBuffer);
  27625. }
  27626. return true;
  27627. };
  27628. /** @protected */
  27629. CompressedTextureResource.prototype.onBlobLoaded = function () {
  27630. this._levelBuffers = CompressedTextureResource._createLevelBuffers(this.buffer.uint8View, this.format, this.levels, 4, 4, // PVRTC has 8x4 blocks in 2bpp mode
  27631. this.width, this.height);
  27632. };
  27633. /**
  27634. * Returns the key (to ContextSystem#extensions) for the WebGL extension supporting the compression format
  27635. *
  27636. * @private
  27637. * @param format - the compression format to get the extension for.
  27638. */
  27639. CompressedTextureResource._formatToExtension = function (format) {
  27640. if (format >= 0x83F0 && format <= 0x83F3) {
  27641. return 's3tc';
  27642. }
  27643. else if (format >= 0x9270 && format <= 0x9279) {
  27644. return 'etc';
  27645. }
  27646. else if (format >= 0x8C00 && format <= 0x8C03) {
  27647. return 'pvrtc';
  27648. }
  27649. else if (format >= 0x8D64) {
  27650. return 'etc1';
  27651. }
  27652. else if (format >= 0x8C92 && format <= 0x87EE) {
  27653. return 'atc';
  27654. }
  27655. throw new Error('Invalid (compressed) texture format given!');
  27656. };
  27657. /**
  27658. * Pre-creates buffer views for each mipmap level
  27659. *
  27660. * @private
  27661. * @param buffer -
  27662. * @param format - compression formats
  27663. * @param levels - mipmap levels
  27664. * @param blockWidth -
  27665. * @param blockHeight -
  27666. * @param imageWidth - width of the image in pixels
  27667. * @param imageHeight - height of the image in pixels
  27668. */
  27669. CompressedTextureResource._createLevelBuffers = function (buffer, format, levels, blockWidth, blockHeight, imageWidth, imageHeight) {
  27670. // The byte-size of the first level buffer
  27671. var buffers = new Array(levels);
  27672. var offset = buffer.byteOffset;
  27673. var levelWidth = imageWidth;
  27674. var levelHeight = imageHeight;
  27675. var alignedLevelWidth = (levelWidth + blockWidth - 1) & ~(blockWidth - 1);
  27676. var alignedLevelHeight = (levelHeight + blockHeight - 1) & ~(blockHeight - 1);
  27677. var levelSize = alignedLevelWidth * alignedLevelHeight * INTERNAL_FORMAT_TO_BYTES_PER_PIXEL[format];
  27678. for (var i = 0; i < levels; i++) {
  27679. buffers[i] = {
  27680. levelID: i,
  27681. levelWidth: levels > 1 ? levelWidth : alignedLevelWidth,
  27682. levelHeight: levels > 1 ? levelHeight : alignedLevelHeight,
  27683. levelBuffer: new Uint8Array(buffer.buffer, offset, levelSize)
  27684. };
  27685. offset += levelSize;
  27686. // Calculate levelBuffer dimensions for next iteration
  27687. levelWidth = (levelWidth >> 1) || 1;
  27688. levelHeight = (levelHeight >> 1) || 1;
  27689. alignedLevelWidth = (levelWidth + blockWidth - 1) & ~(blockWidth - 1);
  27690. alignedLevelHeight = (levelHeight + blockHeight - 1) & ~(blockHeight - 1);
  27691. levelSize = alignedLevelWidth * alignedLevelHeight * INTERNAL_FORMAT_TO_BYTES_PER_PIXEL[format];
  27692. }
  27693. return buffers;
  27694. };
  27695. return CompressedTextureResource;
  27696. }(BlobResource));
  27697. /* eslint-enable camelcase */
  27698. /**
  27699. * Loader plugin for handling compressed textures for all platforms.
  27700. *
  27701. * @class
  27702. * @memberof PIXI
  27703. * @implements PIXI.ILoaderPlugin
  27704. */
  27705. var CompressedTextureLoader = /** @class */ (function () {
  27706. function CompressedTextureLoader() {
  27707. }
  27708. /**
  27709. * Called after a compressed-textures manifest is loaded.
  27710. *
  27711. * This will then load the correct compression format for the device. Your manifest should adhere
  27712. * to the following schema:
  27713. *
  27714. * ```js
  27715. * import { INTERNAL_FORMATS } from '@pixi/constants';
  27716. *
  27717. * type CompressedTextureManifest = {
  27718. * textures: Array<{ src: string, format?: keyof INTERNAL_FORMATS}>,
  27719. * cacheID: string;
  27720. * };
  27721. * ```
  27722. *
  27723. * This is an example of a .json manifest file
  27724. *
  27725. * ```json
  27726. * {
  27727. * "cacheID":"asset",
  27728. * "textures":[
  27729. * { "src":"asset.fallback.png" },
  27730. * { "format":"COMPRESSED_RGBA_S3TC_DXT5_EXT", "src":"asset.s3tc.ktx" },
  27731. * { "format":"COMPRESSED_RGBA8_ETC2_EAC", "src":"asset.etc.ktx" },
  27732. * { "format":"RGBA_PVRTC_4BPPV1_IMG", "src":"asset.pvrtc.ktx" }
  27733. * ]
  27734. * }
  27735. * ```
  27736. */
  27737. CompressedTextureLoader.use = function (resource, next) {
  27738. var data = resource.data;
  27739. var loader = this;
  27740. if (resource.type === exports.LoaderResource.TYPE.JSON
  27741. && data
  27742. && data.cacheID
  27743. && data.textures) {
  27744. var textures = data.textures;
  27745. var textureURL = void 0;
  27746. var fallbackURL = void 0;
  27747. // Search for an extension that holds one the formats
  27748. for (var i = 0, j = textures.length; i < j; i++) {
  27749. var texture = textures[i];
  27750. var url_1 = texture.src;
  27751. var format = texture.format;
  27752. if (!format) {
  27753. fallbackURL = url_1;
  27754. }
  27755. if (CompressedTextureLoader.textureFormats[format]) {
  27756. textureURL = url_1;
  27757. break;
  27758. }
  27759. }
  27760. textureURL = textureURL || fallbackURL;
  27761. // Make sure we have a URL
  27762. if (!textureURL) {
  27763. next(new Error("Cannot load compressed-textures in " + resource.url + ", make sure you provide a fallback"));
  27764. return;
  27765. }
  27766. if (textureURL === resource.url) {
  27767. // Prevent infinite loops
  27768. next(new Error('URL of compressed texture cannot be the same as the manifest\'s URL'));
  27769. return;
  27770. }
  27771. var loadOptions = {
  27772. crossOrigin: resource.crossOrigin,
  27773. metadata: resource.metadata.imageMetadata,
  27774. parentResource: resource
  27775. };
  27776. var resourcePath = url$1.resolve(resource.url.replace(loader.baseUrl, ''), textureURL);
  27777. var resourceName = data.cacheID;
  27778. // The appropriate loader should register the texture
  27779. loader.add(resourceName, resourcePath, loadOptions, function (res) {
  27780. if (res.error) {
  27781. next(res.error);
  27782. return;
  27783. }
  27784. var _a = res.texture, texture = _a === void 0 ? null : _a, _b = res.textures, textures = _b === void 0 ? {} : _b;
  27785. // Make sure texture/textures is assigned to parent resource
  27786. Object.assign(resource, { texture: texture, textures: textures });
  27787. // Pass along any error
  27788. next();
  27789. });
  27790. }
  27791. else {
  27792. next();
  27793. }
  27794. };
  27795. /**
  27796. * Detects the available compressed texture extensions on the device.
  27797. * @ignore
  27798. */
  27799. CompressedTextureLoader.add = function () {
  27800. // Auto-detect WebGL compressed-texture extensions
  27801. var canvas = document.createElement('canvas');
  27802. var gl = canvas.getContext('webgl');
  27803. if (!gl) {
  27804. console.warn('WebGL not available for compressed textures. Silently failing.');
  27805. return;
  27806. }
  27807. var extensions = {
  27808. s3tc: gl.getExtension('WEBGL_compressed_texture_s3tc'),
  27809. s3tc_sRGB: gl.getExtension('WEBGL_compressed_texture_s3tc_srgb'),
  27810. etc: gl.getExtension('WEBGL_compressed_texture_etc'),
  27811. etc1: gl.getExtension('WEBGL_compressed_texture_etc1'),
  27812. pvrtc: gl.getExtension('WEBGL_compressed_texture_pvrtc')
  27813. || gl.getExtension('WEBKIT_WEBGL_compressed_texture_pvrtc'),
  27814. atc: gl.getExtension('WEBGL_compressed_texture_atc'),
  27815. astc: gl.getExtension('WEBGL_compressed_texture_astc')
  27816. };
  27817. CompressedTextureLoader.textureExtensions = extensions;
  27818. CompressedTextureLoader.textureFormats = {};
  27819. // Assign all available compressed-texture formats
  27820. for (var extensionName in extensions) {
  27821. var extension = extensions[extensionName];
  27822. if (!extension) {
  27823. continue;
  27824. }
  27825. Object.assign(CompressedTextureLoader.textureFormats, Object.getPrototypeOf(extension));
  27826. }
  27827. };
  27828. return CompressedTextureLoader;
  27829. }());
  27830. /**
  27831. * Creates base-textures and textures for each compressed-texture resource and adds them into the global
  27832. * texture cache. The first texture has two IDs - `${url}`, `${url}-1`; while the rest have an ID of the
  27833. * form `${url}-i`.
  27834. *
  27835. * @param url - the original address of the resources
  27836. * @param resources - the resources backing texture data
  27837. * @ignore
  27838. */
  27839. function registerCompressedTextures(url, resources, metadata) {
  27840. var result = {
  27841. textures: {},
  27842. texture: null,
  27843. };
  27844. if (!resources) {
  27845. return result;
  27846. }
  27847. var textures = resources.map(function (resource) {
  27848. return (new Texture(new BaseTexture(resource, Object.assign({
  27849. mipmap: exports.MIPMAP_MODES.OFF,
  27850. alphaMode: exports.ALPHA_MODES.NO_PREMULTIPLIED_ALPHA
  27851. }, metadata))));
  27852. });
  27853. textures.forEach(function (texture, i) {
  27854. var baseTexture = texture.baseTexture;
  27855. var cacheID = url + "-" + (i + 1);
  27856. BaseTexture.addToCache(baseTexture, cacheID);
  27857. Texture.addToCache(texture, cacheID);
  27858. if (i === 0) {
  27859. BaseTexture.addToCache(baseTexture, url);
  27860. Texture.addToCache(texture, url);
  27861. result.texture = texture;
  27862. }
  27863. result.textures[cacheID] = texture;
  27864. });
  27865. return result;
  27866. }
  27867. var _a$1, _b;
  27868. // Set DDS files to be loaded as an ArrayBuffer
  27869. exports.LoaderResource.setExtensionXhrType('dds', exports.LoaderResource.XHR_RESPONSE_TYPE.BUFFER);
  27870. var DDS_MAGIC_SIZE = 4;
  27871. var DDS_HEADER_SIZE = 124;
  27872. var DDS_HEADER_PF_SIZE = 32;
  27873. var DDS_HEADER_DX10_SIZE = 20;
  27874. // DDS file format magic word
  27875. var DDS_MAGIC = 0x20534444;
  27876. /**
  27877. * DWORD offsets of the DDS file header fields (relative to file start).
  27878. *
  27879. * @ignore
  27880. */
  27881. var DDS_FIELDS = {
  27882. SIZE: 1,
  27883. FLAGS: 2,
  27884. HEIGHT: 3,
  27885. WIDTH: 4,
  27886. MIPMAP_COUNT: 7,
  27887. PIXEL_FORMAT: 19,
  27888. };
  27889. /**
  27890. * DWORD offsets of the DDS PIXEL_FORMAT fields.
  27891. *
  27892. * @ignore
  27893. */
  27894. var DDS_PF_FIELDS = {
  27895. SIZE: 0,
  27896. FLAGS: 1,
  27897. FOURCC: 2,
  27898. RGB_BITCOUNT: 3,
  27899. R_BIT_MASK: 4,
  27900. G_BIT_MASK: 5,
  27901. B_BIT_MASK: 6,
  27902. A_BIT_MASK: 7
  27903. };
  27904. /**
  27905. * DWORD offsets of the DDS_HEADER_DX10 fields.
  27906. *
  27907. * @ignore
  27908. */
  27909. var DDS_DX10_FIELDS = {
  27910. DXGI_FORMAT: 0,
  27911. RESOURCE_DIMENSION: 1,
  27912. MISC_FLAG: 2,
  27913. ARRAY_SIZE: 3,
  27914. MISC_FLAGS2: 4
  27915. };
  27916. /**
  27917. * @see https://docs.microsoft.com/en-us/windows/win32/api/dxgiformat/ne-dxgiformat-dxgi_format
  27918. * @ignore
  27919. */
  27920. // This is way over-blown for us! Lend us a hand, and remove the ones that aren't used (but set the remaining
  27921. // ones to their correct value)
  27922. var DXGI_FORMAT;
  27923. (function (DXGI_FORMAT) {
  27924. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_UNKNOWN"] = 0] = "DXGI_FORMAT_UNKNOWN";
  27925. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_R32G32B32A32_TYPELESS"] = 1] = "DXGI_FORMAT_R32G32B32A32_TYPELESS";
  27926. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_R32G32B32A32_FLOAT"] = 2] = "DXGI_FORMAT_R32G32B32A32_FLOAT";
  27927. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_R32G32B32A32_UINT"] = 3] = "DXGI_FORMAT_R32G32B32A32_UINT";
  27928. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_R32G32B32A32_SINT"] = 4] = "DXGI_FORMAT_R32G32B32A32_SINT";
  27929. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_R32G32B32_TYPELESS"] = 5] = "DXGI_FORMAT_R32G32B32_TYPELESS";
  27930. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_R32G32B32_FLOAT"] = 6] = "DXGI_FORMAT_R32G32B32_FLOAT";
  27931. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_R32G32B32_UINT"] = 7] = "DXGI_FORMAT_R32G32B32_UINT";
  27932. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_R32G32B32_SINT"] = 8] = "DXGI_FORMAT_R32G32B32_SINT";
  27933. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_R16G16B16A16_TYPELESS"] = 9] = "DXGI_FORMAT_R16G16B16A16_TYPELESS";
  27934. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_R16G16B16A16_FLOAT"] = 10] = "DXGI_FORMAT_R16G16B16A16_FLOAT";
  27935. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_R16G16B16A16_UNORM"] = 11] = "DXGI_FORMAT_R16G16B16A16_UNORM";
  27936. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_R16G16B16A16_UINT"] = 12] = "DXGI_FORMAT_R16G16B16A16_UINT";
  27937. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_R16G16B16A16_SNORM"] = 13] = "DXGI_FORMAT_R16G16B16A16_SNORM";
  27938. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_R16G16B16A16_SINT"] = 14] = "DXGI_FORMAT_R16G16B16A16_SINT";
  27939. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_R32G32_TYPELESS"] = 15] = "DXGI_FORMAT_R32G32_TYPELESS";
  27940. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_R32G32_FLOAT"] = 16] = "DXGI_FORMAT_R32G32_FLOAT";
  27941. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_R32G32_UINT"] = 17] = "DXGI_FORMAT_R32G32_UINT";
  27942. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_R32G32_SINT"] = 18] = "DXGI_FORMAT_R32G32_SINT";
  27943. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_R32G8X24_TYPELESS"] = 19] = "DXGI_FORMAT_R32G8X24_TYPELESS";
  27944. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_D32_FLOAT_S8X24_UINT"] = 20] = "DXGI_FORMAT_D32_FLOAT_S8X24_UINT";
  27945. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS"] = 21] = "DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS";
  27946. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_X32_TYPELESS_G8X24_UINT"] = 22] = "DXGI_FORMAT_X32_TYPELESS_G8X24_UINT";
  27947. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_R10G10B10A2_TYPELESS"] = 23] = "DXGI_FORMAT_R10G10B10A2_TYPELESS";
  27948. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_R10G10B10A2_UNORM"] = 24] = "DXGI_FORMAT_R10G10B10A2_UNORM";
  27949. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_R10G10B10A2_UINT"] = 25] = "DXGI_FORMAT_R10G10B10A2_UINT";
  27950. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_R11G11B10_FLOAT"] = 26] = "DXGI_FORMAT_R11G11B10_FLOAT";
  27951. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_R8G8B8A8_TYPELESS"] = 27] = "DXGI_FORMAT_R8G8B8A8_TYPELESS";
  27952. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_R8G8B8A8_UNORM"] = 28] = "DXGI_FORMAT_R8G8B8A8_UNORM";
  27953. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_R8G8B8A8_UNORM_SRGB"] = 29] = "DXGI_FORMAT_R8G8B8A8_UNORM_SRGB";
  27954. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_R8G8B8A8_UINT"] = 30] = "DXGI_FORMAT_R8G8B8A8_UINT";
  27955. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_R8G8B8A8_SNORM"] = 31] = "DXGI_FORMAT_R8G8B8A8_SNORM";
  27956. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_R8G8B8A8_SINT"] = 32] = "DXGI_FORMAT_R8G8B8A8_SINT";
  27957. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_R16G16_TYPELESS"] = 33] = "DXGI_FORMAT_R16G16_TYPELESS";
  27958. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_R16G16_FLOAT"] = 34] = "DXGI_FORMAT_R16G16_FLOAT";
  27959. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_R16G16_UNORM"] = 35] = "DXGI_FORMAT_R16G16_UNORM";
  27960. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_R16G16_UINT"] = 36] = "DXGI_FORMAT_R16G16_UINT";
  27961. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_R16G16_SNORM"] = 37] = "DXGI_FORMAT_R16G16_SNORM";
  27962. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_R16G16_SINT"] = 38] = "DXGI_FORMAT_R16G16_SINT";
  27963. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_R32_TYPELESS"] = 39] = "DXGI_FORMAT_R32_TYPELESS";
  27964. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_D32_FLOAT"] = 40] = "DXGI_FORMAT_D32_FLOAT";
  27965. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_R32_FLOAT"] = 41] = "DXGI_FORMAT_R32_FLOAT";
  27966. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_R32_UINT"] = 42] = "DXGI_FORMAT_R32_UINT";
  27967. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_R32_SINT"] = 43] = "DXGI_FORMAT_R32_SINT";
  27968. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_R24G8_TYPELESS"] = 44] = "DXGI_FORMAT_R24G8_TYPELESS";
  27969. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_D24_UNORM_S8_UINT"] = 45] = "DXGI_FORMAT_D24_UNORM_S8_UINT";
  27970. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_R24_UNORM_X8_TYPELESS"] = 46] = "DXGI_FORMAT_R24_UNORM_X8_TYPELESS";
  27971. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_X24_TYPELESS_G8_UINT"] = 47] = "DXGI_FORMAT_X24_TYPELESS_G8_UINT";
  27972. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_R8G8_TYPELESS"] = 48] = "DXGI_FORMAT_R8G8_TYPELESS";
  27973. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_R8G8_UNORM"] = 49] = "DXGI_FORMAT_R8G8_UNORM";
  27974. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_R8G8_UINT"] = 50] = "DXGI_FORMAT_R8G8_UINT";
  27975. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_R8G8_SNORM"] = 51] = "DXGI_FORMAT_R8G8_SNORM";
  27976. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_R8G8_SINT"] = 52] = "DXGI_FORMAT_R8G8_SINT";
  27977. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_R16_TYPELESS"] = 53] = "DXGI_FORMAT_R16_TYPELESS";
  27978. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_R16_FLOAT"] = 54] = "DXGI_FORMAT_R16_FLOAT";
  27979. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_D16_UNORM"] = 55] = "DXGI_FORMAT_D16_UNORM";
  27980. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_R16_UNORM"] = 56] = "DXGI_FORMAT_R16_UNORM";
  27981. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_R16_UINT"] = 57] = "DXGI_FORMAT_R16_UINT";
  27982. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_R16_SNORM"] = 58] = "DXGI_FORMAT_R16_SNORM";
  27983. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_R16_SINT"] = 59] = "DXGI_FORMAT_R16_SINT";
  27984. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_R8_TYPELESS"] = 60] = "DXGI_FORMAT_R8_TYPELESS";
  27985. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_R8_UNORM"] = 61] = "DXGI_FORMAT_R8_UNORM";
  27986. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_R8_UINT"] = 62] = "DXGI_FORMAT_R8_UINT";
  27987. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_R8_SNORM"] = 63] = "DXGI_FORMAT_R8_SNORM";
  27988. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_R8_SINT"] = 64] = "DXGI_FORMAT_R8_SINT";
  27989. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_A8_UNORM"] = 65] = "DXGI_FORMAT_A8_UNORM";
  27990. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_R1_UNORM"] = 66] = "DXGI_FORMAT_R1_UNORM";
  27991. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_R9G9B9E5_SHAREDEXP"] = 67] = "DXGI_FORMAT_R9G9B9E5_SHAREDEXP";
  27992. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_R8G8_B8G8_UNORM"] = 68] = "DXGI_FORMAT_R8G8_B8G8_UNORM";
  27993. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_G8R8_G8B8_UNORM"] = 69] = "DXGI_FORMAT_G8R8_G8B8_UNORM";
  27994. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_BC1_TYPELESS"] = 70] = "DXGI_FORMAT_BC1_TYPELESS";
  27995. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_BC1_UNORM"] = 71] = "DXGI_FORMAT_BC1_UNORM";
  27996. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_BC1_UNORM_SRGB"] = 72] = "DXGI_FORMAT_BC1_UNORM_SRGB";
  27997. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_BC2_TYPELESS"] = 73] = "DXGI_FORMAT_BC2_TYPELESS";
  27998. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_BC2_UNORM"] = 74] = "DXGI_FORMAT_BC2_UNORM";
  27999. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_BC2_UNORM_SRGB"] = 75] = "DXGI_FORMAT_BC2_UNORM_SRGB";
  28000. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_BC3_TYPELESS"] = 76] = "DXGI_FORMAT_BC3_TYPELESS";
  28001. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_BC3_UNORM"] = 77] = "DXGI_FORMAT_BC3_UNORM";
  28002. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_BC3_UNORM_SRGB"] = 78] = "DXGI_FORMAT_BC3_UNORM_SRGB";
  28003. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_BC4_TYPELESS"] = 79] = "DXGI_FORMAT_BC4_TYPELESS";
  28004. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_BC4_UNORM"] = 80] = "DXGI_FORMAT_BC4_UNORM";
  28005. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_BC4_SNORM"] = 81] = "DXGI_FORMAT_BC4_SNORM";
  28006. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_BC5_TYPELESS"] = 82] = "DXGI_FORMAT_BC5_TYPELESS";
  28007. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_BC5_UNORM"] = 83] = "DXGI_FORMAT_BC5_UNORM";
  28008. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_BC5_SNORM"] = 84] = "DXGI_FORMAT_BC5_SNORM";
  28009. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_B5G6R5_UNORM"] = 85] = "DXGI_FORMAT_B5G6R5_UNORM";
  28010. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_B5G5R5A1_UNORM"] = 86] = "DXGI_FORMAT_B5G5R5A1_UNORM";
  28011. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_B8G8R8A8_UNORM"] = 87] = "DXGI_FORMAT_B8G8R8A8_UNORM";
  28012. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_B8G8R8X8_UNORM"] = 88] = "DXGI_FORMAT_B8G8R8X8_UNORM";
  28013. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM"] = 89] = "DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM";
  28014. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_B8G8R8A8_TYPELESS"] = 90] = "DXGI_FORMAT_B8G8R8A8_TYPELESS";
  28015. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_B8G8R8A8_UNORM_SRGB"] = 91] = "DXGI_FORMAT_B8G8R8A8_UNORM_SRGB";
  28016. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_B8G8R8X8_TYPELESS"] = 92] = "DXGI_FORMAT_B8G8R8X8_TYPELESS";
  28017. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_B8G8R8X8_UNORM_SRGB"] = 93] = "DXGI_FORMAT_B8G8R8X8_UNORM_SRGB";
  28018. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_BC6H_TYPELESS"] = 94] = "DXGI_FORMAT_BC6H_TYPELESS";
  28019. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_BC6H_UF16"] = 95] = "DXGI_FORMAT_BC6H_UF16";
  28020. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_BC6H_SF16"] = 96] = "DXGI_FORMAT_BC6H_SF16";
  28021. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_BC7_TYPELESS"] = 97] = "DXGI_FORMAT_BC7_TYPELESS";
  28022. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_BC7_UNORM"] = 98] = "DXGI_FORMAT_BC7_UNORM";
  28023. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_BC7_UNORM_SRGB"] = 99] = "DXGI_FORMAT_BC7_UNORM_SRGB";
  28024. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_AYUV"] = 100] = "DXGI_FORMAT_AYUV";
  28025. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_Y410"] = 101] = "DXGI_FORMAT_Y410";
  28026. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_Y416"] = 102] = "DXGI_FORMAT_Y416";
  28027. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_NV12"] = 103] = "DXGI_FORMAT_NV12";
  28028. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_P010"] = 104] = "DXGI_FORMAT_P010";
  28029. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_P016"] = 105] = "DXGI_FORMAT_P016";
  28030. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_420_OPAQUE"] = 106] = "DXGI_FORMAT_420_OPAQUE";
  28031. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_YUY2"] = 107] = "DXGI_FORMAT_YUY2";
  28032. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_Y210"] = 108] = "DXGI_FORMAT_Y210";
  28033. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_Y216"] = 109] = "DXGI_FORMAT_Y216";
  28034. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_NV11"] = 110] = "DXGI_FORMAT_NV11";
  28035. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_AI44"] = 111] = "DXGI_FORMAT_AI44";
  28036. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_IA44"] = 112] = "DXGI_FORMAT_IA44";
  28037. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_P8"] = 113] = "DXGI_FORMAT_P8";
  28038. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_A8P8"] = 114] = "DXGI_FORMAT_A8P8";
  28039. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_B4G4R4A4_UNORM"] = 115] = "DXGI_FORMAT_B4G4R4A4_UNORM";
  28040. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_P208"] = 116] = "DXGI_FORMAT_P208";
  28041. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_V208"] = 117] = "DXGI_FORMAT_V208";
  28042. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_V408"] = 118] = "DXGI_FORMAT_V408";
  28043. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_SAMPLER_FEEDBACK_MIN_MIP_OPAQUE"] = 119] = "DXGI_FORMAT_SAMPLER_FEEDBACK_MIN_MIP_OPAQUE";
  28044. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_SAMPLER_FEEDBACK_MIP_REGION_USED_OPAQUE"] = 120] = "DXGI_FORMAT_SAMPLER_FEEDBACK_MIP_REGION_USED_OPAQUE";
  28045. DXGI_FORMAT[DXGI_FORMAT["DXGI_FORMAT_FORCE_UINT"] = 121] = "DXGI_FORMAT_FORCE_UINT";
  28046. })(DXGI_FORMAT || (DXGI_FORMAT = {}));
  28047. /**
  28048. * Possible values of the field {@link DDS_DX10_FIELDS.RESOURCE_DIMENSION}
  28049. *
  28050. * @ignore
  28051. */
  28052. var D3D10_RESOURCE_DIMENSION;
  28053. (function (D3D10_RESOURCE_DIMENSION) {
  28054. D3D10_RESOURCE_DIMENSION[D3D10_RESOURCE_DIMENSION["DDS_DIMENSION_TEXTURE1D"] = 2] = "DDS_DIMENSION_TEXTURE1D";
  28055. D3D10_RESOURCE_DIMENSION[D3D10_RESOURCE_DIMENSION["DDS_DIMENSION_TEXTURE2D"] = 3] = "DDS_DIMENSION_TEXTURE2D";
  28056. D3D10_RESOURCE_DIMENSION[D3D10_RESOURCE_DIMENSION["DDS_DIMENSION_TEXTURE3D"] = 6] = "DDS_DIMENSION_TEXTURE3D";
  28057. })(D3D10_RESOURCE_DIMENSION || (D3D10_RESOURCE_DIMENSION = {}));
  28058. var PF_FLAGS = 1;
  28059. // PIXEL_FORMAT flags
  28060. var DDPF_ALPHA = 0x2;
  28061. var DDPF_FOURCC = 0x4;
  28062. var DDPF_RGB = 0x40;
  28063. var DDPF_YUV = 0x200;
  28064. var DDPF_LUMINANCE = 0x20000;
  28065. // Four character codes for DXTn formats
  28066. var FOURCC_DXT1 = 0x31545844;
  28067. var FOURCC_DXT3 = 0x33545844;
  28068. var FOURCC_DXT5 = 0x35545844;
  28069. var FOURCC_DX10 = 0x30315844;
  28070. // Cubemap texture flag (for DDS_DX10_FIELDS.MISC_FLAG)
  28071. var DDS_RESOURCE_MISC_TEXTURECUBE = 0x4;
  28072. /**
  28073. * Maps `FOURCC_*` formats to internal formats (see {@link PIXI.INTERNAL_FORMATS}).
  28074. *
  28075. * @ignore
  28076. */
  28077. var FOURCC_TO_FORMAT = (_a$1 = {},
  28078. _a$1[FOURCC_DXT1] = exports.INTERNAL_FORMATS.COMPRESSED_RGBA_S3TC_DXT1_EXT,
  28079. _a$1[FOURCC_DXT3] = exports.INTERNAL_FORMATS.COMPRESSED_RGBA_S3TC_DXT3_EXT,
  28080. _a$1[FOURCC_DXT5] = exports.INTERNAL_FORMATS.COMPRESSED_RGBA_S3TC_DXT5_EXT,
  28081. _a$1);
  28082. /**
  28083. * Maps {@link DXGI_FORMAT} to types/internal-formats (see {@link PIXI.TYPES}, {@link PIXI.INTERNAL_FORMATS})
  28084. *
  28085. * @ignore
  28086. */
  28087. var DXGI_TO_FORMAT = (_b = {},
  28088. // WEBGL_compressed_texture_s3tc
  28089. _b[DXGI_FORMAT.DXGI_FORMAT_BC1_TYPELESS] = exports.INTERNAL_FORMATS.COMPRESSED_RGBA_S3TC_DXT1_EXT,
  28090. _b[DXGI_FORMAT.DXGI_FORMAT_BC1_UNORM] = exports.INTERNAL_FORMATS.COMPRESSED_RGBA_S3TC_DXT1_EXT,
  28091. _b[DXGI_FORMAT.DXGI_FORMAT_BC2_TYPELESS] = exports.INTERNAL_FORMATS.COMPRESSED_RGBA_S3TC_DXT3_EXT,
  28092. _b[DXGI_FORMAT.DXGI_FORMAT_BC2_UNORM] = exports.INTERNAL_FORMATS.COMPRESSED_RGBA_S3TC_DXT3_EXT,
  28093. _b[DXGI_FORMAT.DXGI_FORMAT_BC3_TYPELESS] = exports.INTERNAL_FORMATS.COMPRESSED_RGBA_S3TC_DXT5_EXT,
  28094. _b[DXGI_FORMAT.DXGI_FORMAT_BC3_UNORM] = exports.INTERNAL_FORMATS.COMPRESSED_RGBA_S3TC_DXT5_EXT,
  28095. // WEBGL_compressed_texture_s3tc_srgb
  28096. _b[DXGI_FORMAT.DXGI_FORMAT_BC1_UNORM_SRGB] = exports.INTERNAL_FORMATS.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT,
  28097. _b[DXGI_FORMAT.DXGI_FORMAT_BC2_UNORM_SRGB] = exports.INTERNAL_FORMATS.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT,
  28098. _b[DXGI_FORMAT.DXGI_FORMAT_BC3_UNORM_SRGB] = exports.INTERNAL_FORMATS.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT,
  28099. _b);
  28100. /**
  28101. * @class
  28102. * @memberof PIXI
  28103. * @implements PIXI.ILoaderPlugin
  28104. * @see https://docs.microsoft.com/en-us/windows/win32/direct3ddds/dx-graphics-dds-pguide
  28105. */
  28106. var DDSLoader = /** @class */ (function () {
  28107. function DDSLoader() {
  28108. }
  28109. /**
  28110. * Registers a DDS compressed texture
  28111. * @see PIXI.Loader.loaderMiddleware
  28112. * @param resource - loader resource that is checked to see if it is a DDS file
  28113. * @param next - callback Function to call when done
  28114. */
  28115. DDSLoader.use = function (resource, next) {
  28116. if (resource.extension === 'dds' && resource.data) {
  28117. try {
  28118. Object.assign(resource, registerCompressedTextures(resource.name || resource.url, DDSLoader.parse(resource.data), resource.metadata));
  28119. }
  28120. catch (err) {
  28121. next(err);
  28122. return;
  28123. }
  28124. }
  28125. next();
  28126. };
  28127. /** Parses the DDS file header, generates base-textures, and puts them into the texture cache. */
  28128. DDSLoader.parse = function (arrayBuffer) {
  28129. var data = new Uint32Array(arrayBuffer);
  28130. var magicWord = data[0];
  28131. if (magicWord !== DDS_MAGIC) {
  28132. throw new Error('Invalid DDS file magic word');
  28133. }
  28134. var header = new Uint32Array(arrayBuffer, 0, DDS_HEADER_SIZE / Uint32Array.BYTES_PER_ELEMENT);
  28135. // DDS header fields
  28136. var height = header[DDS_FIELDS.HEIGHT];
  28137. var width = header[DDS_FIELDS.WIDTH];
  28138. var mipmapCount = header[DDS_FIELDS.MIPMAP_COUNT];
  28139. // PIXEL_FORMAT fields
  28140. var pixelFormat = new Uint32Array(arrayBuffer, DDS_FIELDS.PIXEL_FORMAT * Uint32Array.BYTES_PER_ELEMENT, DDS_HEADER_PF_SIZE / Uint32Array.BYTES_PER_ELEMENT);
  28141. var formatFlags = pixelFormat[PF_FLAGS];
  28142. // File contains compressed texture(s)
  28143. if (formatFlags & DDPF_FOURCC) {
  28144. var fourCC = pixelFormat[DDS_PF_FIELDS.FOURCC];
  28145. // File contains one DXTn compressed texture
  28146. if (fourCC !== FOURCC_DX10) {
  28147. var internalFormat_1 = FOURCC_TO_FORMAT[fourCC];
  28148. var dataOffset_1 = DDS_MAGIC_SIZE + DDS_HEADER_SIZE;
  28149. var texData = new Uint8Array(arrayBuffer, dataOffset_1);
  28150. var resource = new CompressedTextureResource(texData, {
  28151. format: internalFormat_1,
  28152. width: width,
  28153. height: height,
  28154. levels: mipmapCount // CompressedTextureResource will separate the levelBuffers for us!
  28155. });
  28156. return [resource];
  28157. }
  28158. // FOURCC_DX10 indicates there is a 20-byte DDS_HEADER_DX10 after DDS_HEADER
  28159. var dx10Offset = DDS_MAGIC_SIZE + DDS_HEADER_SIZE;
  28160. var dx10Header = new Uint32Array(data.buffer, dx10Offset, DDS_HEADER_DX10_SIZE / Uint32Array.BYTES_PER_ELEMENT);
  28161. var dxgiFormat = dx10Header[DDS_DX10_FIELDS.DXGI_FORMAT];
  28162. var resourceDimension = dx10Header[DDS_DX10_FIELDS.RESOURCE_DIMENSION];
  28163. var miscFlag = dx10Header[DDS_DX10_FIELDS.MISC_FLAG];
  28164. var arraySize = dx10Header[DDS_DX10_FIELDS.ARRAY_SIZE];
  28165. // Map dxgiFormat to PIXI.INTERNAL_FORMATS
  28166. var internalFormat_2 = DXGI_TO_FORMAT[dxgiFormat];
  28167. if (internalFormat_2 === undefined) {
  28168. throw new Error("DDSLoader cannot parse texture data with DXGI format " + dxgiFormat);
  28169. }
  28170. if (miscFlag === DDS_RESOURCE_MISC_TEXTURECUBE) {
  28171. // FIXME: Anybody excited about cubemap compressed textures?
  28172. throw new Error('DDSLoader does not support cubemap textures');
  28173. }
  28174. if (resourceDimension === D3D10_RESOURCE_DIMENSION.DDS_DIMENSION_TEXTURE3D) {
  28175. // FIXME: Anybody excited about 3D compressed textures?
  28176. throw new Error('DDSLoader does not supported 3D texture data');
  28177. }
  28178. // Uint8Array buffers of image data, including all mipmap levels in each image
  28179. var imageBuffers = new Array();
  28180. var dataOffset = DDS_MAGIC_SIZE
  28181. + DDS_HEADER_SIZE
  28182. + DDS_HEADER_DX10_SIZE;
  28183. if (arraySize === 1) {
  28184. // No need bothering with the imageSize calculation!
  28185. imageBuffers.push(new Uint8Array(arrayBuffer, dataOffset));
  28186. }
  28187. else {
  28188. // Calculate imageSize for each texture, and then locate each image's texture data
  28189. var pixelSize = INTERNAL_FORMAT_TO_BYTES_PER_PIXEL[internalFormat_2];
  28190. var imageSize = 0;
  28191. var levelWidth = width;
  28192. var levelHeight = height;
  28193. for (var i = 0; i < mipmapCount; i++) {
  28194. var alignedLevelWidth = Math.max(1, (levelWidth + 3) & ~3);
  28195. var alignedLevelHeight = Math.max(1, (levelHeight + 3) & ~3);
  28196. var levelSize = alignedLevelWidth * alignedLevelHeight * pixelSize;
  28197. imageSize += levelSize;
  28198. levelWidth = levelWidth >>> 1;
  28199. levelHeight = levelHeight >>> 1;
  28200. }
  28201. var imageOffset = dataOffset;
  28202. // NOTE: Cubemaps have 6-images per texture (but they aren't supported so ^_^)
  28203. for (var i = 0; i < arraySize; i++) {
  28204. imageBuffers.push(new Uint8Array(arrayBuffer, imageOffset, imageSize));
  28205. imageOffset += imageSize;
  28206. }
  28207. }
  28208. // Uint8Array -> CompressedTextureResource, and we're done!
  28209. return imageBuffers.map(function (buffer) { return new CompressedTextureResource(buffer, {
  28210. format: internalFormat_2,
  28211. width: width,
  28212. height: height,
  28213. levels: mipmapCount
  28214. }); });
  28215. }
  28216. if (formatFlags & DDPF_RGB) {
  28217. // FIXME: We might want to allow uncompressed *.dds files?
  28218. throw new Error('DDSLoader does not support uncompressed texture data.');
  28219. }
  28220. if (formatFlags & DDPF_YUV) {
  28221. // FIXME: Does anybody need this feature?
  28222. throw new Error('DDSLoader does not supported YUV uncompressed texture data.');
  28223. }
  28224. if (formatFlags & DDPF_LUMINANCE) {
  28225. // FIXME: Microsoft says older DDS filers use this feature! Probably not worth the effort!
  28226. throw new Error('DDSLoader does not support single-channel (lumninance) texture data!');
  28227. }
  28228. if (formatFlags & DDPF_ALPHA) {
  28229. // FIXME: I'm tired! See above =)
  28230. throw new Error('DDSLoader does not support single-channel (alpha) texture data!');
  28231. }
  28232. throw new Error('DDSLoader failed to load a texture file due to an unknown reason!');
  28233. };
  28234. return DDSLoader;
  28235. }());
  28236. var _a$2, _b$1, _c;
  28237. // Set KTX files to be loaded as an ArrayBuffer
  28238. exports.LoaderResource.setExtensionXhrType('ktx', exports.LoaderResource.XHR_RESPONSE_TYPE.BUFFER);
  28239. /**
  28240. * The 12-byte KTX file identifier
  28241. *
  28242. * @see https://www.khronos.org/opengles/sdk/tools/KTX/file_format_spec/#2.1
  28243. * @ignore
  28244. */
  28245. var FILE_IDENTIFIER = [0xAB, 0x4B, 0x54, 0x58, 0x20, 0x31, 0x31, 0xBB, 0x0D, 0x0A, 0x1A, 0x0A];
  28246. /**
  28247. * The value stored in the "endianness" field.
  28248. *
  28249. * @see https://www.khronos.org/opengles/sdk/tools/KTX/file_format_spec/#2.2
  28250. * @ignore
  28251. */
  28252. var ENDIANNESS = 0x04030201;
  28253. /**
  28254. * Byte offsets of the KTX file header fields
  28255. *
  28256. * @ignore
  28257. */
  28258. var KTX_FIELDS = {
  28259. FILE_IDENTIFIER: 0,
  28260. ENDIANNESS: 12,
  28261. GL_TYPE: 16,
  28262. GL_TYPE_SIZE: 20,
  28263. GL_FORMAT: 24,
  28264. GL_INTERNAL_FORMAT: 28,
  28265. GL_BASE_INTERNAL_FORMAT: 32,
  28266. PIXEL_WIDTH: 36,
  28267. PIXEL_HEIGHT: 40,
  28268. PIXEL_DEPTH: 44,
  28269. NUMBER_OF_ARRAY_ELEMENTS: 48,
  28270. NUMBER_OF_FACES: 52,
  28271. NUMBER_OF_MIPMAP_LEVELS: 56,
  28272. BYTES_OF_KEY_VALUE_DATA: 60
  28273. };
  28274. /**
  28275. * Byte size of the file header fields in {@code KTX_FIELDS}
  28276. *
  28277. * @ignore
  28278. */
  28279. var FILE_HEADER_SIZE = 64;
  28280. /**
  28281. * Maps {@link PIXI.TYPES} to the bytes taken per component, excluding those ones that are bit-fields.
  28282. *
  28283. * @ignore
  28284. */
  28285. var TYPES_TO_BYTES_PER_COMPONENT = (_a$2 = {},
  28286. _a$2[exports.TYPES.UNSIGNED_BYTE] = 1,
  28287. _a$2[exports.TYPES.UNSIGNED_SHORT] = 2,
  28288. _a$2[exports.TYPES.FLOAT] = 4,
  28289. _a$2[exports.TYPES.HALF_FLOAT] = 8,
  28290. _a$2);
  28291. /**
  28292. * Number of components in each {@link PIXI.FORMATS}
  28293. *
  28294. * @ignore
  28295. */
  28296. var FORMATS_TO_COMPONENTS = (_b$1 = {},
  28297. _b$1[exports.FORMATS.RGBA] = 4,
  28298. _b$1[exports.FORMATS.RGB] = 3,
  28299. _b$1[exports.FORMATS.LUMINANCE] = 1,
  28300. _b$1[exports.FORMATS.LUMINANCE_ALPHA] = 2,
  28301. _b$1[exports.FORMATS.ALPHA] = 1,
  28302. _b$1);
  28303. /**
  28304. * Number of bytes per pixel in bit-field types in {@link PIXI.TYPES}
  28305. *
  28306. * @ignore
  28307. */
  28308. var TYPES_TO_BYTES_PER_PIXEL = (_c = {},
  28309. _c[exports.TYPES.UNSIGNED_SHORT_4_4_4_4] = 2,
  28310. _c[exports.TYPES.UNSIGNED_SHORT_5_5_5_1] = 2,
  28311. _c[exports.TYPES.UNSIGNED_SHORT_5_6_5] = 2,
  28312. _c);
  28313. /**
  28314. * Loader plugin for handling KTX texture container files.
  28315. *
  28316. * This KTX loader does not currently support the following features:
  28317. * * cube textures
  28318. * * 3D textures
  28319. * * vendor-specific key/value data parsing
  28320. * * endianness conversion for big-endian machines
  28321. * * embedded *.basis files
  28322. *
  28323. * It does supports the following features:
  28324. * * multiple textures per file
  28325. * * mipmapping
  28326. *
  28327. * @class
  28328. * @memberof PIXI
  28329. * @implements PIXI.ILoaderPlugin
  28330. */
  28331. var KTXLoader = /** @class */ (function () {
  28332. function KTXLoader() {
  28333. }
  28334. /**
  28335. * Called after a KTX file is loaded.
  28336. *
  28337. * This will parse the KTX file header and add a {@code BaseTexture} to the texture
  28338. * cache.
  28339. *
  28340. * @see PIXI.Loader.loaderMiddleware
  28341. * @param resource - loader resource that is checked to see if it is a KTX file
  28342. * @param next - callback Function to call when done
  28343. */
  28344. KTXLoader.use = function (resource, next) {
  28345. if (resource.extension === 'ktx' && resource.data) {
  28346. try {
  28347. var url = resource.name || resource.url;
  28348. Object.assign(resource, registerCompressedTextures(url, KTXLoader.parse(url, resource.data), resource.metadata));
  28349. }
  28350. catch (err) {
  28351. next(err);
  28352. return;
  28353. }
  28354. }
  28355. next();
  28356. };
  28357. /** Parses the KTX file header, generates base-textures, and puts them into the texture cache. */
  28358. KTXLoader.parse = function (url, arrayBuffer) {
  28359. var dataView = new DataView(arrayBuffer);
  28360. if (!KTXLoader.validate(url, dataView)) {
  28361. return null;
  28362. }
  28363. var littleEndian = dataView.getUint32(KTX_FIELDS.ENDIANNESS, true) === ENDIANNESS;
  28364. var glType = dataView.getUint32(KTX_FIELDS.GL_TYPE, littleEndian);
  28365. // const glTypeSize = dataView.getUint32(KTX_FIELDS.GL_TYPE_SIZE, littleEndian);
  28366. var glFormat = dataView.getUint32(KTX_FIELDS.GL_FORMAT, littleEndian);
  28367. var glInternalFormat = dataView.getUint32(KTX_FIELDS.GL_INTERNAL_FORMAT, littleEndian);
  28368. var pixelWidth = dataView.getUint32(KTX_FIELDS.PIXEL_WIDTH, littleEndian);
  28369. var pixelHeight = dataView.getUint32(KTX_FIELDS.PIXEL_HEIGHT, littleEndian) || 1; // "pixelHeight = 0" -> "1"
  28370. var pixelDepth = dataView.getUint32(KTX_FIELDS.PIXEL_DEPTH, littleEndian) || 1; // ^^
  28371. var numberOfArrayElements = dataView.getUint32(KTX_FIELDS.NUMBER_OF_ARRAY_ELEMENTS, littleEndian) || 1; // ^^
  28372. var numberOfFaces = dataView.getUint32(KTX_FIELDS.NUMBER_OF_FACES, littleEndian);
  28373. var numberOfMipmapLevels = dataView.getUint32(KTX_FIELDS.NUMBER_OF_MIPMAP_LEVELS, littleEndian);
  28374. var bytesOfKeyValueData = dataView.getUint32(KTX_FIELDS.BYTES_OF_KEY_VALUE_DATA, littleEndian);
  28375. // Whether the platform architecture is little endian. If littleEndian !== platformLittleEndian, then the
  28376. // file contents must be endian-converted!
  28377. // TODO: Endianness conversion
  28378. // const platformLittleEndian = new Uint8Array((new Uint32Array([ENDIANNESS])).buffer)[0] === 0x01;
  28379. if (pixelHeight === 0 || pixelDepth !== 1) {
  28380. throw new Error('Only 2D textures are supported');
  28381. }
  28382. if (numberOfFaces !== 1) {
  28383. throw new Error('CubeTextures are not supported by KTXLoader yet!');
  28384. }
  28385. if (numberOfArrayElements !== 1) {
  28386. // TODO: Support splitting array-textures into multiple BaseTextures
  28387. throw new Error('WebGL does not support array textures');
  28388. }
  28389. // TODO: 8x4 blocks for 2bpp pvrtc
  28390. var blockWidth = 4;
  28391. var blockHeight = 4;
  28392. var alignedWidth = (pixelWidth + 3) & ~3;
  28393. var alignedHeight = (pixelHeight + 3) & ~3;
  28394. var imageBuffers = new Array(numberOfArrayElements);
  28395. var imagePixels = pixelWidth * pixelHeight;
  28396. if (glType === 0) {
  28397. // Align to 16 pixels (4x4 blocks)
  28398. imagePixels = alignedWidth * alignedHeight;
  28399. }
  28400. var imagePixelByteSize;
  28401. if (glType !== 0) {
  28402. // Uncompressed texture format
  28403. if (TYPES_TO_BYTES_PER_COMPONENT[glType]) {
  28404. imagePixelByteSize = TYPES_TO_BYTES_PER_COMPONENT[glType] * FORMATS_TO_COMPONENTS[glFormat];
  28405. }
  28406. else {
  28407. imagePixelByteSize = TYPES_TO_BYTES_PER_PIXEL[glType];
  28408. }
  28409. }
  28410. else {
  28411. imagePixelByteSize = INTERNAL_FORMAT_TO_BYTES_PER_PIXEL[glInternalFormat];
  28412. }
  28413. if (imagePixelByteSize === undefined) {
  28414. throw new Error('Unable to resolve the pixel format stored in the *.ktx file!');
  28415. }
  28416. var imageByteSize = imagePixels * imagePixelByteSize;
  28417. var mipByteSize = imageByteSize;
  28418. var mipWidth = pixelWidth;
  28419. var mipHeight = pixelHeight;
  28420. var alignedMipWidth = alignedWidth;
  28421. var alignedMipHeight = alignedHeight;
  28422. var imageOffset = FILE_HEADER_SIZE + bytesOfKeyValueData;
  28423. for (var mipmapLevel = 0; mipmapLevel < numberOfMipmapLevels; mipmapLevel++) {
  28424. var imageSize = dataView.getUint32(imageOffset, littleEndian);
  28425. var elementOffset = imageOffset + 4;
  28426. for (var arrayElement = 0; arrayElement < numberOfArrayElements; arrayElement++) {
  28427. // TODO: Maybe support 3D textures? :-)
  28428. // for (let zSlice = 0; zSlice < pixelDepth; zSlice)
  28429. var mips = imageBuffers[arrayElement];
  28430. if (!mips) {
  28431. mips = imageBuffers[arrayElement] = new Array(numberOfMipmapLevels);
  28432. }
  28433. mips[mipmapLevel] = {
  28434. levelID: mipmapLevel,
  28435. levelWidth: numberOfMipmapLevels > 1 ? mipWidth : alignedMipWidth,
  28436. levelHeight: numberOfMipmapLevels > 1 ? mipHeight : alignedMipHeight,
  28437. levelBuffer: new Uint8Array(arrayBuffer, elementOffset, mipByteSize)
  28438. };
  28439. elementOffset += mipByteSize;
  28440. }
  28441. // HINT: Aligns to 4-byte boundary after jumping imageSize (in lieu of mipPadding)
  28442. imageOffset += imageSize + 4; // (+4 to jump the imageSize field itself)
  28443. imageOffset = imageOffset % 4 !== 0 ? imageOffset + 4 - (imageOffset % 4) : imageOffset;
  28444. // Calculate mipWidth, mipHeight for _next_ iteration
  28445. mipWidth = (mipWidth >> 1) || 1;
  28446. mipHeight = (mipHeight >> 1) || 1;
  28447. alignedMipWidth = (mipWidth + blockWidth - 1) & ~(blockWidth - 1);
  28448. alignedMipHeight = (mipHeight + blockHeight - 1) & ~(blockHeight - 1);
  28449. // Each mipmap level is 4-times smaller?
  28450. mipByteSize = alignedMipWidth * alignedMipHeight * imagePixelByteSize;
  28451. }
  28452. // We use the levelBuffers feature of CompressedTextureResource b/c texture data is image-major, not level-major.
  28453. if (glType !== 0) {
  28454. throw new Error('TODO: Uncompressed');
  28455. }
  28456. return imageBuffers.map(function (levelBuffers) { return new CompressedTextureResource(null, {
  28457. format: glInternalFormat,
  28458. width: pixelWidth,
  28459. height: pixelHeight,
  28460. levels: numberOfMipmapLevels,
  28461. levelBuffers: levelBuffers,
  28462. }); });
  28463. };
  28464. /** Checks whether the arrayBuffer contains a valid *.ktx file. */
  28465. KTXLoader.validate = function (url, dataView) {
  28466. // NOTE: Do not optimize this into 3 32-bit integer comparison because the endianness
  28467. // of the data is not specified.
  28468. for (var i = 0; i < FILE_IDENTIFIER.length; i++) {
  28469. if (dataView.getUint8(i) !== FILE_IDENTIFIER[i]) {
  28470. console.error(url + " is not a valid *.ktx file!");
  28471. return false;
  28472. }
  28473. }
  28474. return true;
  28475. };
  28476. return KTXLoader;
  28477. }());
  28478. /*!
  28479. * @pixi/particle-container - v6.1.2
  28480. * Compiled Thu, 12 Aug 2021 17:11:19 UTC
  28481. *
  28482. * @pixi/particle-container is licensed under the MIT License.
  28483. * http://www.opensource.org/licenses/mit-license
  28484. */
  28485. /*! *****************************************************************************
  28486. Copyright (c) Microsoft Corporation. All rights reserved.
  28487. Licensed under the Apache License, Version 2.0 (the "License"); you may not use
  28488. this file except in compliance with the License. You may obtain a copy of the
  28489. License at http://www.apache.org/licenses/LICENSE-2.0
  28490. THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  28491. KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
  28492. WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
  28493. MERCHANTABLITY OR NON-INFRINGEMENT.
  28494. See the Apache Version 2.0 License for specific language governing permissions
  28495. and limitations under the License.
  28496. ***************************************************************************** */
  28497. /* global Reflect, Promise */
  28498. var extendStatics$4 = function(d, b) {
  28499. extendStatics$4 = Object.setPrototypeOf ||
  28500. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  28501. function (d, b) { for (var p in b) { if (b.hasOwnProperty(p)) { d[p] = b[p]; } } };
  28502. return extendStatics$4(d, b);
  28503. };
  28504. function __extends$4(d, b) {
  28505. extendStatics$4(d, b);
  28506. function __() { this.constructor = d; }
  28507. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  28508. }
  28509. /**
  28510. * The ParticleContainer class is a really fast version of the Container built solely for speed,
  28511. * so use when you need a lot of sprites or particles.
  28512. *
  28513. * The tradeoff of the ParticleContainer is that most advanced functionality will not work.
  28514. * ParticleContainer implements the basic object transform (position, scale, rotation)
  28515. * and some advanced functionality like tint (as of v4.5.6).
  28516. *
  28517. * Other more advanced functionality like masking, children, filters, etc will not work on sprites in this batch.
  28518. *
  28519. * It's extremely easy to use:
  28520. * ```js
  28521. * let container = new ParticleContainer();
  28522. *
  28523. * for (let i = 0; i < 100; ++i)
  28524. * {
  28525. * let sprite = PIXI.Sprite.from("myImage.png");
  28526. * container.addChild(sprite);
  28527. * }
  28528. * ```
  28529. *
  28530. * And here you have a hundred sprites that will be rendered at the speed of light.
  28531. *
  28532. * @class
  28533. * @extends PIXI.Container
  28534. * @memberof PIXI
  28535. */
  28536. var ParticleContainer = /** @class */ (function (_super) {
  28537. __extends$4(ParticleContainer, _super);
  28538. /**
  28539. * @param {number} [maxSize=1500] - The maximum number of particles that can be rendered by the container.
  28540. * Affects size of allocated buffers.
  28541. * @param {object} [properties] - The properties of children that should be uploaded to the gpu and applied.
  28542. * @param {boolean} [properties.vertices=false] - When true, vertices be uploaded and applied.
  28543. * if sprite's ` scale/anchor/trim/frame/orig` is dynamic, please set `true`.
  28544. * @param {boolean} [properties.position=true] - When true, position be uploaded and applied.
  28545. * @param {boolean} [properties.rotation=false] - When true, rotation be uploaded and applied.
  28546. * @param {boolean} [properties.uvs=false] - When true, uvs be uploaded and applied.
  28547. * @param {boolean} [properties.tint=false] - When true, alpha and tint be uploaded and applied.
  28548. * @param {number} [batchSize=16384] - Number of particles per batch. If less than maxSize, it uses maxSize instead.
  28549. * @param {boolean} [autoResize=false] - If true, container allocates more batches in case
  28550. * there are more than `maxSize` particles.
  28551. */
  28552. function ParticleContainer(maxSize, properties, batchSize, autoResize) {
  28553. if (maxSize === void 0) { maxSize = 1500; }
  28554. if (batchSize === void 0) { batchSize = 16384; }
  28555. if (autoResize === void 0) { autoResize = false; }
  28556. var _this = _super.call(this) || this;
  28557. // Making sure the batch size is valid
  28558. // 65535 is max vertex index in the index buffer (see ParticleRenderer)
  28559. // so max number of particles is 65536 / 4 = 16384
  28560. var maxBatchSize = 16384;
  28561. if (batchSize > maxBatchSize) {
  28562. batchSize = maxBatchSize;
  28563. }
  28564. /**
  28565. * Set properties to be dynamic (true) / static (false)
  28566. *
  28567. * @member {boolean[]}
  28568. * @private
  28569. */
  28570. _this._properties = [false, true, false, false, false];
  28571. /**
  28572. * @member {number}
  28573. * @private
  28574. */
  28575. _this._maxSize = maxSize;
  28576. /**
  28577. * @member {number}
  28578. * @private
  28579. */
  28580. _this._batchSize = batchSize;
  28581. /**
  28582. * @member {Array<PIXI.Buffer>}
  28583. * @private
  28584. */
  28585. _this._buffers = null;
  28586. /**
  28587. * for every batch stores _updateID corresponding to the last change in that batch
  28588. * @member {number[]}
  28589. * @private
  28590. */
  28591. _this._bufferUpdateIDs = [];
  28592. /**
  28593. * when child inserted, removed or changes position this number goes up
  28594. * @member {number[]}
  28595. * @private
  28596. */
  28597. _this._updateID = 0;
  28598. /**
  28599. * @member {boolean}
  28600. *
  28601. */
  28602. _this.interactiveChildren = false;
  28603. /**
  28604. * The blend mode to be applied to the sprite. Apply a value of `PIXI.BLEND_MODES.NORMAL`
  28605. * to reset the blend mode.
  28606. *
  28607. * @member {number}
  28608. * @default PIXI.BLEND_MODES.NORMAL
  28609. * @see PIXI.BLEND_MODES
  28610. */
  28611. _this.blendMode = exports.BLEND_MODES.NORMAL;
  28612. /**
  28613. * If true, container allocates more batches in case there are more than `maxSize` particles.
  28614. * @member {boolean}
  28615. * @default false
  28616. */
  28617. _this.autoResize = autoResize;
  28618. /**
  28619. * If true PixiJS will Math.floor() x/y values when rendering, stopping pixel interpolation.
  28620. * Advantages can include sharper image quality (like text) and faster rendering on canvas.
  28621. * The main disadvantage is movement of objects may appear less smooth.
  28622. * Default to true here as performance is usually the priority for particles.
  28623. *
  28624. * @member {boolean}
  28625. * @default true
  28626. */
  28627. _this.roundPixels = true;
  28628. /**
  28629. * The texture used to render the children.
  28630. *
  28631. * @readonly
  28632. * @member {PIXI.BaseTexture}
  28633. */
  28634. _this.baseTexture = null;
  28635. _this.setProperties(properties);
  28636. /**
  28637. * The tint applied to the container.
  28638. * This is a hex value. A value of 0xFFFFFF will remove any tint effect.
  28639. *
  28640. * @private
  28641. * @member {number}
  28642. * @default 0xFFFFFF
  28643. */
  28644. _this._tint = 0;
  28645. _this.tintRgb = new Float32Array(4);
  28646. _this.tint = 0xFFFFFF;
  28647. return _this;
  28648. }
  28649. /**
  28650. * Sets the private properties array to dynamic / static based on the passed properties object
  28651. *
  28652. * @param {object} properties - The properties to be uploaded
  28653. */
  28654. ParticleContainer.prototype.setProperties = function (properties) {
  28655. if (properties) {
  28656. this._properties[0] = 'vertices' in properties || 'scale' in properties
  28657. ? !!properties.vertices || !!properties.scale : this._properties[0];
  28658. this._properties[1] = 'position' in properties ? !!properties.position : this._properties[1];
  28659. this._properties[2] = 'rotation' in properties ? !!properties.rotation : this._properties[2];
  28660. this._properties[3] = 'uvs' in properties ? !!properties.uvs : this._properties[3];
  28661. this._properties[4] = 'tint' in properties || 'alpha' in properties
  28662. ? !!properties.tint || !!properties.alpha : this._properties[4];
  28663. }
  28664. };
  28665. /**
  28666. * Updates the object transform for rendering
  28667. *
  28668. * @private
  28669. */
  28670. ParticleContainer.prototype.updateTransform = function () {
  28671. // TODO don't need to!
  28672. this.displayObjectUpdateTransform();
  28673. };
  28674. Object.defineProperty(ParticleContainer.prototype, "tint", {
  28675. /**
  28676. * The tint applied to the container. This is a hex value.
  28677. * A value of 0xFFFFFF will remove any tint effect.
  28678. ** IMPORTANT: This is a WebGL only feature and will be ignored by the canvas renderer.
  28679. * @member {number}
  28680. * @default 0xFFFFFF
  28681. */
  28682. get: function () {
  28683. return this._tint;
  28684. },
  28685. set: function (value) {
  28686. this._tint = value;
  28687. hex2rgb(value, this.tintRgb);
  28688. },
  28689. enumerable: false,
  28690. configurable: true
  28691. });
  28692. /**
  28693. * Renders the container using the WebGL renderer
  28694. *
  28695. * @private
  28696. * @param {PIXI.Renderer} renderer - The webgl renderer
  28697. */
  28698. ParticleContainer.prototype.render = function (renderer) {
  28699. var _this = this;
  28700. if (!this.visible || this.worldAlpha <= 0 || !this.children.length || !this.renderable) {
  28701. return;
  28702. }
  28703. if (!this.baseTexture) {
  28704. this.baseTexture = this.children[0]._texture.baseTexture;
  28705. if (!this.baseTexture.valid) {
  28706. this.baseTexture.once('update', function () { return _this.onChildrenChange(0); });
  28707. }
  28708. }
  28709. renderer.batch.setObjectRenderer(renderer.plugins.particle);
  28710. renderer.plugins.particle.render(this);
  28711. };
  28712. /**
  28713. * Set the flag that static data should be updated to true
  28714. *
  28715. * @private
  28716. * @param {number} smallestChildIndex - The smallest child index
  28717. */
  28718. ParticleContainer.prototype.onChildrenChange = function (smallestChildIndex) {
  28719. var bufferIndex = Math.floor(smallestChildIndex / this._batchSize);
  28720. while (this._bufferUpdateIDs.length < bufferIndex) {
  28721. this._bufferUpdateIDs.push(0);
  28722. }
  28723. this._bufferUpdateIDs[bufferIndex] = ++this._updateID;
  28724. };
  28725. ParticleContainer.prototype.dispose = function () {
  28726. if (this._buffers) {
  28727. for (var i = 0; i < this._buffers.length; ++i) {
  28728. this._buffers[i].destroy();
  28729. }
  28730. this._buffers = null;
  28731. }
  28732. };
  28733. /**
  28734. * Destroys the container
  28735. *
  28736. * @param {object|boolean} [options] - Options parameter. A boolean will act as if all options
  28737. * have been set to that value
  28738. * @param {boolean} [options.children=false] - if set to true, all the children will have their
  28739. * destroy method called as well. 'options' will be passed on to those calls.
  28740. * @param {boolean} [options.texture=false] - Only used for child Sprites if options.children is set to true
  28741. * Should it destroy the texture of the child sprite
  28742. * @param {boolean} [options.baseTexture=false] - Only used for child Sprites if options.children is set to true
  28743. * Should it destroy the base texture of the child sprite
  28744. */
  28745. ParticleContainer.prototype.destroy = function (options) {
  28746. _super.prototype.destroy.call(this, options);
  28747. this.dispose();
  28748. this._properties = null;
  28749. this._buffers = null;
  28750. this._bufferUpdateIDs = null;
  28751. };
  28752. return ParticleContainer;
  28753. }(Container));
  28754. /*
  28755. * @author Mat Groves
  28756. *
  28757. * Big thanks to the very clever Matt DesLauriers <mattdesl> https://github.com/mattdesl/
  28758. * for creating the original PixiJS version!
  28759. * Also a thanks to https://github.com/bchevalier for tweaking the tint and alpha so that
  28760. * they now share 4 bytes on the vertex buffer
  28761. *
  28762. * Heavily inspired by LibGDX's ParticleBuffer:
  28763. * https://github.com/libgdx/libgdx/blob/master/gdx/src/com/badlogic/gdx/graphics/g2d/ParticleBuffer.java
  28764. */
  28765. /**
  28766. * The particle buffer manages the static and dynamic buffers for a particle container.
  28767. *
  28768. * @class
  28769. * @private
  28770. * @memberof PIXI
  28771. */
  28772. var ParticleBuffer = /** @class */ (function () {
  28773. /**
  28774. * @private
  28775. * @param {object} properties - The properties to upload.
  28776. * @param {boolean[]} dynamicPropertyFlags - Flags for which properties are dynamic.
  28777. * @param {number} size - The size of the batch.
  28778. */
  28779. function ParticleBuffer(properties, dynamicPropertyFlags, size) {
  28780. this.geometry = new Geometry();
  28781. this.indexBuffer = null;
  28782. /**
  28783. * The number of particles the buffer can hold
  28784. *
  28785. * @private
  28786. * @member {number}
  28787. */
  28788. this.size = size;
  28789. /**
  28790. * A list of the properties that are dynamic.
  28791. *
  28792. * @private
  28793. * @member {object[]}
  28794. */
  28795. this.dynamicProperties = [];
  28796. /**
  28797. * A list of the properties that are static.
  28798. *
  28799. * @private
  28800. * @member {object[]}
  28801. */
  28802. this.staticProperties = [];
  28803. for (var i = 0; i < properties.length; ++i) {
  28804. var property = properties[i];
  28805. // Make copy of properties object so that when we edit the offset it doesn't
  28806. // change all other instances of the object literal
  28807. property = {
  28808. attributeName: property.attributeName,
  28809. size: property.size,
  28810. uploadFunction: property.uploadFunction,
  28811. type: property.type || exports.TYPES.FLOAT,
  28812. offset: property.offset,
  28813. };
  28814. if (dynamicPropertyFlags[i]) {
  28815. this.dynamicProperties.push(property);
  28816. }
  28817. else {
  28818. this.staticProperties.push(property);
  28819. }
  28820. }
  28821. this.staticStride = 0;
  28822. this.staticBuffer = null;
  28823. this.staticData = null;
  28824. this.staticDataUint32 = null;
  28825. this.dynamicStride = 0;
  28826. this.dynamicBuffer = null;
  28827. this.dynamicData = null;
  28828. this.dynamicDataUint32 = null;
  28829. this._updateID = 0;
  28830. this.initBuffers();
  28831. }
  28832. /**
  28833. * Sets up the renderer context and necessary buffers.
  28834. *
  28835. * @private
  28836. */
  28837. ParticleBuffer.prototype.initBuffers = function () {
  28838. var geometry = this.geometry;
  28839. var dynamicOffset = 0;
  28840. /**
  28841. * Holds the indices of the geometry (quads) to draw
  28842. *
  28843. * @member {Uint16Array}
  28844. * @private
  28845. */
  28846. this.indexBuffer = new Buffer(createIndicesForQuads(this.size), true, true);
  28847. geometry.addIndex(this.indexBuffer);
  28848. this.dynamicStride = 0;
  28849. for (var i = 0; i < this.dynamicProperties.length; ++i) {
  28850. var property = this.dynamicProperties[i];
  28851. property.offset = dynamicOffset;
  28852. dynamicOffset += property.size;
  28853. this.dynamicStride += property.size;
  28854. }
  28855. var dynBuffer = new ArrayBuffer(this.size * this.dynamicStride * 4 * 4);
  28856. this.dynamicData = new Float32Array(dynBuffer);
  28857. this.dynamicDataUint32 = new Uint32Array(dynBuffer);
  28858. this.dynamicBuffer = new Buffer(this.dynamicData, false, false);
  28859. // static //
  28860. var staticOffset = 0;
  28861. this.staticStride = 0;
  28862. for (var i = 0; i < this.staticProperties.length; ++i) {
  28863. var property = this.staticProperties[i];
  28864. property.offset = staticOffset;
  28865. staticOffset += property.size;
  28866. this.staticStride += property.size;
  28867. }
  28868. var statBuffer = new ArrayBuffer(this.size * this.staticStride * 4 * 4);
  28869. this.staticData = new Float32Array(statBuffer);
  28870. this.staticDataUint32 = new Uint32Array(statBuffer);
  28871. this.staticBuffer = new Buffer(this.staticData, true, false);
  28872. for (var i = 0; i < this.dynamicProperties.length; ++i) {
  28873. var property = this.dynamicProperties[i];
  28874. geometry.addAttribute(property.attributeName, this.dynamicBuffer, 0, property.type === exports.TYPES.UNSIGNED_BYTE, property.type, this.dynamicStride * 4, property.offset * 4);
  28875. }
  28876. for (var i = 0; i < this.staticProperties.length; ++i) {
  28877. var property = this.staticProperties[i];
  28878. geometry.addAttribute(property.attributeName, this.staticBuffer, 0, property.type === exports.TYPES.UNSIGNED_BYTE, property.type, this.staticStride * 4, property.offset * 4);
  28879. }
  28880. };
  28881. /**
  28882. * Uploads the dynamic properties.
  28883. *
  28884. * @private
  28885. * @param {PIXI.DisplayObject[]} children - The children to upload.
  28886. * @param {number} startIndex - The index to start at.
  28887. * @param {number} amount - The number to upload.
  28888. */
  28889. ParticleBuffer.prototype.uploadDynamic = function (children, startIndex, amount) {
  28890. for (var i = 0; i < this.dynamicProperties.length; i++) {
  28891. var property = this.dynamicProperties[i];
  28892. property.uploadFunction(children, startIndex, amount, property.type === exports.TYPES.UNSIGNED_BYTE ? this.dynamicDataUint32 : this.dynamicData, this.dynamicStride, property.offset);
  28893. }
  28894. this.dynamicBuffer._updateID++;
  28895. };
  28896. /**
  28897. * Uploads the static properties.
  28898. *
  28899. * @private
  28900. * @param {PIXI.DisplayObject[]} children - The children to upload.
  28901. * @param {number} startIndex - The index to start at.
  28902. * @param {number} amount - The number to upload.
  28903. */
  28904. ParticleBuffer.prototype.uploadStatic = function (children, startIndex, amount) {
  28905. for (var i = 0; i < this.staticProperties.length; i++) {
  28906. var property = this.staticProperties[i];
  28907. property.uploadFunction(children, startIndex, amount, property.type === exports.TYPES.UNSIGNED_BYTE ? this.staticDataUint32 : this.staticData, this.staticStride, property.offset);
  28908. }
  28909. this.staticBuffer._updateID++;
  28910. };
  28911. /**
  28912. * Destroys the ParticleBuffer.
  28913. *
  28914. * @private
  28915. */
  28916. ParticleBuffer.prototype.destroy = function () {
  28917. this.indexBuffer = null;
  28918. this.dynamicProperties = null;
  28919. this.dynamicBuffer = null;
  28920. this.dynamicData = null;
  28921. this.dynamicDataUint32 = null;
  28922. this.staticProperties = null;
  28923. this.staticBuffer = null;
  28924. this.staticData = null;
  28925. this.staticDataUint32 = null;
  28926. // all buffers are destroyed inside geometry
  28927. this.geometry.destroy();
  28928. };
  28929. return ParticleBuffer;
  28930. }());
  28931. var fragment$1 = "varying vec2 vTextureCoord;\nvarying vec4 vColor;\n\nuniform sampler2D uSampler;\n\nvoid main(void){\n vec4 color = texture2D(uSampler, vTextureCoord) * vColor;\n gl_FragColor = color;\n}";
  28932. var vertex$1 = "attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nattribute vec4 aColor;\n\nattribute vec2 aPositionCoord;\nattribute float aRotation;\n\nuniform mat3 translationMatrix;\nuniform vec4 uColor;\n\nvarying vec2 vTextureCoord;\nvarying vec4 vColor;\n\nvoid main(void){\n float x = (aVertexPosition.x) * cos(aRotation) - (aVertexPosition.y) * sin(aRotation);\n float y = (aVertexPosition.x) * sin(aRotation) + (aVertexPosition.y) * cos(aRotation);\n\n vec2 v = vec2(x, y);\n v = v + aPositionCoord;\n\n gl_Position = vec4((translationMatrix * vec3(v, 1.0)).xy, 0.0, 1.0);\n\n vTextureCoord = aTextureCoord;\n vColor = aColor * uColor;\n}\n";
  28933. /*
  28934. * @author Mat Groves
  28935. *
  28936. * Big thanks to the very clever Matt DesLauriers <mattdesl> https://github.com/mattdesl/
  28937. * for creating the original PixiJS version!
  28938. * Also a thanks to https://github.com/bchevalier for tweaking the tint and alpha so that they now
  28939. * share 4 bytes on the vertex buffer
  28940. *
  28941. * Heavily inspired by LibGDX's ParticleRenderer:
  28942. * https://github.com/libgdx/libgdx/blob/master/gdx/src/com/badlogic/gdx/graphics/g2d/ParticleRenderer.java
  28943. */
  28944. /**
  28945. * Renderer for Particles that is designer for speed over feature set.
  28946. *
  28947. * @class
  28948. * @memberof PIXI
  28949. */
  28950. var ParticleRenderer = /** @class */ (function (_super) {
  28951. __extends$4(ParticleRenderer, _super);
  28952. /**
  28953. * @param {PIXI.Renderer} renderer - The renderer this sprite batch works for.
  28954. */
  28955. function ParticleRenderer(renderer) {
  28956. var _this = _super.call(this, renderer) || this;
  28957. // 65535 is max vertex index in the index buffer (see ParticleRenderer)
  28958. // so max number of particles is 65536 / 4 = 16384
  28959. // and max number of element in the index buffer is 16384 * 6 = 98304
  28960. // Creating a full index buffer, overhead is 98304 * 2 = 196Ko
  28961. // let numIndices = 98304;
  28962. /**
  28963. * The default shader that is used if a sprite doesn't have a more specific one.
  28964. *
  28965. * @member {PIXI.Shader}
  28966. */
  28967. _this.shader = null;
  28968. _this.properties = null;
  28969. _this.tempMatrix = new Matrix();
  28970. _this.properties = [
  28971. // verticesData
  28972. {
  28973. attributeName: 'aVertexPosition',
  28974. size: 2,
  28975. uploadFunction: _this.uploadVertices,
  28976. offset: 0,
  28977. },
  28978. // positionData
  28979. {
  28980. attributeName: 'aPositionCoord',
  28981. size: 2,
  28982. uploadFunction: _this.uploadPosition,
  28983. offset: 0,
  28984. },
  28985. // rotationData
  28986. {
  28987. attributeName: 'aRotation',
  28988. size: 1,
  28989. uploadFunction: _this.uploadRotation,
  28990. offset: 0,
  28991. },
  28992. // uvsData
  28993. {
  28994. attributeName: 'aTextureCoord',
  28995. size: 2,
  28996. uploadFunction: _this.uploadUvs,
  28997. offset: 0,
  28998. },
  28999. // tintData
  29000. {
  29001. attributeName: 'aColor',
  29002. size: 1,
  29003. type: exports.TYPES.UNSIGNED_BYTE,
  29004. uploadFunction: _this.uploadTint,
  29005. offset: 0,
  29006. } ];
  29007. _this.shader = Shader.from(vertex$1, fragment$1, {});
  29008. /**
  29009. * The WebGL state in which this renderer will work.
  29010. *
  29011. * @member {PIXI.State}
  29012. * @readonly
  29013. */
  29014. _this.state = State.for2d();
  29015. return _this;
  29016. }
  29017. /**
  29018. * Renders the particle container object.
  29019. *
  29020. * @param {PIXI.ParticleContainer} container - The container to render using this ParticleRenderer
  29021. */
  29022. ParticleRenderer.prototype.render = function (container) {
  29023. var children = container.children;
  29024. var maxSize = container._maxSize;
  29025. var batchSize = container._batchSize;
  29026. var renderer = this.renderer;
  29027. var totalChildren = children.length;
  29028. if (totalChildren === 0) {
  29029. return;
  29030. }
  29031. else if (totalChildren > maxSize && !container.autoResize) {
  29032. totalChildren = maxSize;
  29033. }
  29034. var buffers = container._buffers;
  29035. if (!buffers) {
  29036. buffers = container._buffers = this.generateBuffers(container);
  29037. }
  29038. var baseTexture = children[0]._texture.baseTexture;
  29039. // if the uvs have not updated then no point rendering just yet!
  29040. this.state.blendMode = correctBlendMode(container.blendMode, baseTexture.alphaMode);
  29041. renderer.state.set(this.state);
  29042. var gl = renderer.gl;
  29043. var m = container.worldTransform.copyTo(this.tempMatrix);
  29044. m.prepend(renderer.globalUniforms.uniforms.projectionMatrix);
  29045. this.shader.uniforms.translationMatrix = m.toArray(true);
  29046. this.shader.uniforms.uColor = premultiplyRgba(container.tintRgb, container.worldAlpha, this.shader.uniforms.uColor, baseTexture.alphaMode);
  29047. this.shader.uniforms.uSampler = baseTexture;
  29048. this.renderer.shader.bind(this.shader);
  29049. var updateStatic = false;
  29050. // now lets upload and render the buffers..
  29051. for (var i = 0, j = 0; i < totalChildren; i += batchSize, j += 1) {
  29052. var amount = (totalChildren - i);
  29053. if (amount > batchSize) {
  29054. amount = batchSize;
  29055. }
  29056. if (j >= buffers.length) {
  29057. buffers.push(this._generateOneMoreBuffer(container));
  29058. }
  29059. var buffer = buffers[j];
  29060. // we always upload the dynamic
  29061. buffer.uploadDynamic(children, i, amount);
  29062. var bid = container._bufferUpdateIDs[j] || 0;
  29063. updateStatic = updateStatic || (buffer._updateID < bid);
  29064. // we only upload the static content when we have to!
  29065. if (updateStatic) {
  29066. buffer._updateID = container._updateID;
  29067. buffer.uploadStatic(children, i, amount);
  29068. }
  29069. // bind the buffer
  29070. renderer.geometry.bind(buffer.geometry);
  29071. gl.drawElements(gl.TRIANGLES, amount * 6, gl.UNSIGNED_SHORT, 0);
  29072. }
  29073. };
  29074. /**
  29075. * Creates one particle buffer for each child in the container we want to render and updates internal properties
  29076. *
  29077. * @param {PIXI.ParticleContainer} container - The container to render using this ParticleRenderer
  29078. * @return {PIXI.ParticleBuffer[]} The buffers
  29079. * @private
  29080. */
  29081. ParticleRenderer.prototype.generateBuffers = function (container) {
  29082. var buffers = [];
  29083. var size = container._maxSize;
  29084. var batchSize = container._batchSize;
  29085. var dynamicPropertyFlags = container._properties;
  29086. for (var i = 0; i < size; i += batchSize) {
  29087. buffers.push(new ParticleBuffer(this.properties, dynamicPropertyFlags, batchSize));
  29088. }
  29089. return buffers;
  29090. };
  29091. /**
  29092. * Creates one more particle buffer, because container has autoResize feature
  29093. *
  29094. * @param {PIXI.ParticleContainer} container - The container to render using this ParticleRenderer
  29095. * @return {PIXI.ParticleBuffer} generated buffer
  29096. * @private
  29097. */
  29098. ParticleRenderer.prototype._generateOneMoreBuffer = function (container) {
  29099. var batchSize = container._batchSize;
  29100. var dynamicPropertyFlags = container._properties;
  29101. return new ParticleBuffer(this.properties, dynamicPropertyFlags, batchSize);
  29102. };
  29103. /**
  29104. * Uploads the vertices.
  29105. *
  29106. * @param {PIXI.DisplayObject[]} children - the array of display objects to render
  29107. * @param {number} startIndex - the index to start from in the children array
  29108. * @param {number} amount - the amount of children that will have their vertices uploaded
  29109. * @param {number[]} array - The vertices to upload.
  29110. * @param {number} stride - Stride to use for iteration.
  29111. * @param {number} offset - Offset to start at.
  29112. */
  29113. ParticleRenderer.prototype.uploadVertices = function (children, startIndex, amount, array, stride, offset) {
  29114. var w0 = 0;
  29115. var w1 = 0;
  29116. var h0 = 0;
  29117. var h1 = 0;
  29118. for (var i = 0; i < amount; ++i) {
  29119. var sprite = children[startIndex + i];
  29120. var texture = sprite._texture;
  29121. var sx = sprite.scale.x;
  29122. var sy = sprite.scale.y;
  29123. var trim = texture.trim;
  29124. var orig = texture.orig;
  29125. if (trim) {
  29126. // if the sprite is trimmed and is not a tilingsprite then we need to add the
  29127. // extra space before transforming the sprite coords..
  29128. w1 = trim.x - (sprite.anchor.x * orig.width);
  29129. w0 = w1 + trim.width;
  29130. h1 = trim.y - (sprite.anchor.y * orig.height);
  29131. h0 = h1 + trim.height;
  29132. }
  29133. else {
  29134. w0 = (orig.width) * (1 - sprite.anchor.x);
  29135. w1 = (orig.width) * -sprite.anchor.x;
  29136. h0 = orig.height * (1 - sprite.anchor.y);
  29137. h1 = orig.height * -sprite.anchor.y;
  29138. }
  29139. array[offset] = w1 * sx;
  29140. array[offset + 1] = h1 * sy;
  29141. array[offset + stride] = w0 * sx;
  29142. array[offset + stride + 1] = h1 * sy;
  29143. array[offset + (stride * 2)] = w0 * sx;
  29144. array[offset + (stride * 2) + 1] = h0 * sy;
  29145. array[offset + (stride * 3)] = w1 * sx;
  29146. array[offset + (stride * 3) + 1] = h0 * sy;
  29147. offset += stride * 4;
  29148. }
  29149. };
  29150. /**
  29151. * Uploads the position.
  29152. *
  29153. * @param {PIXI.DisplayObject[]} children - the array of display objects to render
  29154. * @param {number} startIndex - the index to start from in the children array
  29155. * @param {number} amount - the amount of children that will have their positions uploaded
  29156. * @param {number[]} array - The vertices to upload.
  29157. * @param {number} stride - Stride to use for iteration.
  29158. * @param {number} offset - Offset to start at.
  29159. */
  29160. ParticleRenderer.prototype.uploadPosition = function (children, startIndex, amount, array, stride, offset) {
  29161. for (var i = 0; i < amount; i++) {
  29162. var spritePosition = children[startIndex + i].position;
  29163. array[offset] = spritePosition.x;
  29164. array[offset + 1] = spritePosition.y;
  29165. array[offset + stride] = spritePosition.x;
  29166. array[offset + stride + 1] = spritePosition.y;
  29167. array[offset + (stride * 2)] = spritePosition.x;
  29168. array[offset + (stride * 2) + 1] = spritePosition.y;
  29169. array[offset + (stride * 3)] = spritePosition.x;
  29170. array[offset + (stride * 3) + 1] = spritePosition.y;
  29171. offset += stride * 4;
  29172. }
  29173. };
  29174. /**
  29175. * Uploads the rotation.
  29176. *
  29177. * @param {PIXI.DisplayObject[]} children - the array of display objects to render
  29178. * @param {number} startIndex - the index to start from in the children array
  29179. * @param {number} amount - the amount of children that will have their rotation uploaded
  29180. * @param {number[]} array - The vertices to upload.
  29181. * @param {number} stride - Stride to use for iteration.
  29182. * @param {number} offset - Offset to start at.
  29183. */
  29184. ParticleRenderer.prototype.uploadRotation = function (children, startIndex, amount, array, stride, offset) {
  29185. for (var i = 0; i < amount; i++) {
  29186. var spriteRotation = children[startIndex + i].rotation;
  29187. array[offset] = spriteRotation;
  29188. array[offset + stride] = spriteRotation;
  29189. array[offset + (stride * 2)] = spriteRotation;
  29190. array[offset + (stride * 3)] = spriteRotation;
  29191. offset += stride * 4;
  29192. }
  29193. };
  29194. /**
  29195. * Uploads the Uvs
  29196. *
  29197. * @param {PIXI.DisplayObject[]} children - the array of display objects to render
  29198. * @param {number} startIndex - the index to start from in the children array
  29199. * @param {number} amount - the amount of children that will have their rotation uploaded
  29200. * @param {number[]} array - The vertices to upload.
  29201. * @param {number} stride - Stride to use for iteration.
  29202. * @param {number} offset - Offset to start at.
  29203. */
  29204. ParticleRenderer.prototype.uploadUvs = function (children, startIndex, amount, array, stride, offset) {
  29205. for (var i = 0; i < amount; ++i) {
  29206. var textureUvs = children[startIndex + i]._texture._uvs;
  29207. if (textureUvs) {
  29208. array[offset] = textureUvs.x0;
  29209. array[offset + 1] = textureUvs.y0;
  29210. array[offset + stride] = textureUvs.x1;
  29211. array[offset + stride + 1] = textureUvs.y1;
  29212. array[offset + (stride * 2)] = textureUvs.x2;
  29213. array[offset + (stride * 2) + 1] = textureUvs.y2;
  29214. array[offset + (stride * 3)] = textureUvs.x3;
  29215. array[offset + (stride * 3) + 1] = textureUvs.y3;
  29216. offset += stride * 4;
  29217. }
  29218. else {
  29219. // TODO you know this can be easier!
  29220. array[offset] = 0;
  29221. array[offset + 1] = 0;
  29222. array[offset + stride] = 0;
  29223. array[offset + stride + 1] = 0;
  29224. array[offset + (stride * 2)] = 0;
  29225. array[offset + (stride * 2) + 1] = 0;
  29226. array[offset + (stride * 3)] = 0;
  29227. array[offset + (stride * 3) + 1] = 0;
  29228. offset += stride * 4;
  29229. }
  29230. }
  29231. };
  29232. /**
  29233. * Uploads the tint.
  29234. *
  29235. * @param {PIXI.DisplayObject[]} children - the array of display objects to render
  29236. * @param {number} startIndex - the index to start from in the children array
  29237. * @param {number} amount - the amount of children that will have their rotation uploaded
  29238. * @param {number[]} array - The vertices to upload.
  29239. * @param {number} stride - Stride to use for iteration.
  29240. * @param {number} offset - Offset to start at.
  29241. */
  29242. ParticleRenderer.prototype.uploadTint = function (children, startIndex, amount, array, stride, offset) {
  29243. for (var i = 0; i < amount; ++i) {
  29244. var sprite = children[startIndex + i];
  29245. var premultiplied = sprite._texture.baseTexture.alphaMode > 0;
  29246. var alpha = sprite.alpha;
  29247. // we dont call extra function if alpha is 1.0, that's faster
  29248. var argb = alpha < 1.0 && premultiplied
  29249. ? premultiplyTint(sprite._tintRGB, alpha) : sprite._tintRGB + (alpha * 255 << 24);
  29250. array[offset] = argb;
  29251. array[offset + stride] = argb;
  29252. array[offset + (stride * 2)] = argb;
  29253. array[offset + (stride * 3)] = argb;
  29254. offset += stride * 4;
  29255. }
  29256. };
  29257. /**
  29258. * Destroys the ParticleRenderer.
  29259. */
  29260. ParticleRenderer.prototype.destroy = function () {
  29261. _super.prototype.destroy.call(this);
  29262. if (this.shader) {
  29263. this.shader.destroy();
  29264. this.shader = null;
  29265. }
  29266. this.tempMatrix = null;
  29267. };
  29268. return ParticleRenderer;
  29269. }(ObjectRenderer));
  29270. /*!
  29271. * @pixi/graphics - v6.1.2
  29272. * Compiled Thu, 12 Aug 2021 17:11:19 UTC
  29273. *
  29274. * @pixi/graphics is licensed under the MIT License.
  29275. * http://www.opensource.org/licenses/mit-license
  29276. */
  29277. /**
  29278. * Supported line joints in `PIXI.LineStyle` for graphics.
  29279. *
  29280. * @see PIXI.Graphics#lineStyle
  29281. * @see https://graphicdesign.stackexchange.com/questions/59018/what-is-a-bevel-join-of-two-lines-exactly-illustrator
  29282. *
  29283. * @name LINE_JOIN
  29284. * @memberof PIXI
  29285. * @static
  29286. * @enum {string}
  29287. * @property {string} MITER - 'miter': make a sharp corner where outer part of lines meet
  29288. * @property {string} BEVEL - 'bevel': add a square butt at each end of line segment and fill the triangle at turn
  29289. * @property {string} ROUND - 'round': add an arc at the joint
  29290. */
  29291. (function (LINE_JOIN) {
  29292. LINE_JOIN["MITER"] = "miter";
  29293. LINE_JOIN["BEVEL"] = "bevel";
  29294. LINE_JOIN["ROUND"] = "round";
  29295. })(exports.LINE_JOIN || (exports.LINE_JOIN = {}));
  29296. /**
  29297. * Support line caps in `PIXI.LineStyle` for graphics.
  29298. *
  29299. * @see PIXI.Graphics#lineStyle
  29300. *
  29301. * @name LINE_CAP
  29302. * @memberof PIXI
  29303. * @static
  29304. * @enum {string}
  29305. * @property {string} BUTT - 'butt': don't add any cap at line ends (leaves orthogonal edges)
  29306. * @property {string} ROUND - 'round': add semicircle at ends
  29307. * @property {string} SQUARE - 'square': add square at end (like `BUTT` except more length at end)
  29308. */
  29309. (function (LINE_CAP) {
  29310. LINE_CAP["BUTT"] = "butt";
  29311. LINE_CAP["ROUND"] = "round";
  29312. LINE_CAP["SQUARE"] = "square";
  29313. })(exports.LINE_CAP || (exports.LINE_CAP = {}));
  29314. /**
  29315. * Graphics curves resolution settings. If `adaptive` flag is set to `true`,
  29316. * the resolution is calculated based on the curve's length to ensure better visual quality.
  29317. * Adaptive draw works with `bezierCurveTo` and `quadraticCurveTo`.
  29318. *
  29319. * @static
  29320. * @constant
  29321. * @memberof PIXI
  29322. * @name GRAPHICS_CURVES
  29323. * @type {object}
  29324. * @property {boolean} adaptive=true - flag indicating if the resolution should be adaptive
  29325. * @property {number} maxLength=10 - maximal length of a single segment of the curve (if adaptive = false, ignored)
  29326. * @property {number} minSegments=8 - minimal number of segments in the curve (if adaptive = false, ignored)
  29327. * @property {number} maxSegments=2048 - maximal number of segments in the curve (if adaptive = false, ignored)
  29328. */
  29329. var GRAPHICS_CURVES = {
  29330. adaptive: true,
  29331. maxLength: 10,
  29332. minSegments: 8,
  29333. maxSegments: 2048,
  29334. epsilon: 0.0001,
  29335. _segmentsCount: function (length, defaultSegments) {
  29336. if (defaultSegments === void 0) { defaultSegments = 20; }
  29337. if (!this.adaptive || !length || isNaN(length)) {
  29338. return defaultSegments;
  29339. }
  29340. var result = Math.ceil(length / this.maxLength);
  29341. if (result < this.minSegments) {
  29342. result = this.minSegments;
  29343. }
  29344. else if (result > this.maxSegments) {
  29345. result = this.maxSegments;
  29346. }
  29347. return result;
  29348. },
  29349. };
  29350. /**
  29351. * Fill style object for Graphics.
  29352. *
  29353. * @class
  29354. * @memberof PIXI
  29355. */
  29356. var FillStyle = /** @class */ (function () {
  29357. function FillStyle() {
  29358. /**
  29359. * The hex color value used when coloring the Graphics object.
  29360. *
  29361. * @default 0xFFFFFF
  29362. */
  29363. this.color = 0xFFFFFF;
  29364. /** The alpha value used when filling the Graphics object. */
  29365. this.alpha = 1.0;
  29366. /**
  29367. * The texture to be used for the fill.
  29368. *
  29369. * @member {PIXI.Texture}
  29370. * @default 0
  29371. */
  29372. this.texture = Texture.WHITE;
  29373. /**
  29374. * The transform applied to the texture.
  29375. *
  29376. * @member {PIXI.Matrix}
  29377. * @default null
  29378. */
  29379. this.matrix = null;
  29380. /** If the current fill is visible. */
  29381. this.visible = false;
  29382. this.reset();
  29383. }
  29384. /**
  29385. * Clones the object
  29386. *
  29387. * @return {PIXI.FillStyle}
  29388. */
  29389. FillStyle.prototype.clone = function () {
  29390. var obj = new FillStyle();
  29391. obj.color = this.color;
  29392. obj.alpha = this.alpha;
  29393. obj.texture = this.texture;
  29394. obj.matrix = this.matrix;
  29395. obj.visible = this.visible;
  29396. return obj;
  29397. };
  29398. /**
  29399. * Reset
  29400. */
  29401. FillStyle.prototype.reset = function () {
  29402. this.color = 0xFFFFFF;
  29403. this.alpha = 1;
  29404. this.texture = Texture.WHITE;
  29405. this.matrix = null;
  29406. this.visible = false;
  29407. };
  29408. /**
  29409. * Destroy and don't use after this
  29410. */
  29411. FillStyle.prototype.destroy = function () {
  29412. this.texture = null;
  29413. this.matrix = null;
  29414. };
  29415. return FillStyle;
  29416. }());
  29417. /*! *****************************************************************************
  29418. Copyright (c) Microsoft Corporation. All rights reserved.
  29419. Licensed under the Apache License, Version 2.0 (the "License"); you may not use
  29420. this file except in compliance with the License. You may obtain a copy of the
  29421. License at http://www.apache.org/licenses/LICENSE-2.0
  29422. THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  29423. KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
  29424. WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
  29425. MERCHANTABLITY OR NON-INFRINGEMENT.
  29426. See the Apache Version 2.0 License for specific language governing permissions
  29427. and limitations under the License.
  29428. ***************************************************************************** */
  29429. /* global Reflect, Promise */
  29430. var extendStatics$5 = function(d, b) {
  29431. extendStatics$5 = Object.setPrototypeOf ||
  29432. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  29433. function (d, b) { for (var p in b) { if (b.hasOwnProperty(p)) { d[p] = b[p]; } } };
  29434. return extendStatics$5(d, b);
  29435. };
  29436. function __extends$5(d, b) {
  29437. extendStatics$5(d, b);
  29438. function __() { this.constructor = d; }
  29439. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  29440. }
  29441. /**
  29442. * Builds a polygon to draw
  29443. *
  29444. * Ignored from docs since it is not directly exposed.
  29445. *
  29446. * @ignore
  29447. * @private
  29448. * @param {PIXI.WebGLGraphicsData} graphicsData - The graphics object containing all the necessary properties
  29449. * @param {object} webGLData - an object containing all the WebGL-specific information to create this shape
  29450. * @param {object} webGLDataNativeLines - an object containing all the WebGL-specific information to create nativeLines
  29451. */
  29452. var buildPoly = {
  29453. build: function (graphicsData) {
  29454. graphicsData.points = graphicsData.shape.points.slice();
  29455. },
  29456. triangulate: function (graphicsData, graphicsGeometry) {
  29457. var points = graphicsData.points;
  29458. var holes = graphicsData.holes;
  29459. var verts = graphicsGeometry.points;
  29460. var indices = graphicsGeometry.indices;
  29461. if (points.length >= 6) {
  29462. var holeArray = [];
  29463. // Process holes..
  29464. for (var i = 0; i < holes.length; i++) {
  29465. var hole = holes[i];
  29466. holeArray.push(points.length / 2);
  29467. points = points.concat(hole.points);
  29468. }
  29469. // sort color
  29470. var triangles = earcut_1(points, holeArray, 2);
  29471. if (!triangles) {
  29472. return;
  29473. }
  29474. var vertPos = verts.length / 2;
  29475. for (var i = 0; i < triangles.length; i += 3) {
  29476. indices.push(triangles[i] + vertPos);
  29477. indices.push(triangles[i + 1] + vertPos);
  29478. indices.push(triangles[i + 2] + vertPos);
  29479. }
  29480. for (var i = 0; i < points.length; i++) {
  29481. verts.push(points[i]);
  29482. }
  29483. }
  29484. },
  29485. };
  29486. // for type only
  29487. /**
  29488. * Builds a circle to draw
  29489. *
  29490. * Ignored from docs since it is not directly exposed.
  29491. *
  29492. * @ignore
  29493. * @private
  29494. * @param {PIXI.WebGLGraphicsData} graphicsData - The graphics object to draw
  29495. * @param {object} webGLData - an object containing all the WebGL-specific information to create this shape
  29496. * @param {object} webGLDataNativeLines - an object containing all the WebGL-specific information to create nativeLines
  29497. */
  29498. var buildCircle = {
  29499. build: function (graphicsData) {
  29500. // need to convert points to a nice regular data
  29501. var circleData = graphicsData.shape;
  29502. var points = graphicsData.points;
  29503. var x = circleData.x;
  29504. var y = circleData.y;
  29505. var width;
  29506. var height;
  29507. points.length = 0;
  29508. // TODO - bit hacky??
  29509. if (graphicsData.type === exports.SHAPES.CIRC) {
  29510. width = circleData.radius;
  29511. height = circleData.radius;
  29512. }
  29513. else {
  29514. var ellipseData = graphicsData.shape;
  29515. width = ellipseData.width;
  29516. height = ellipseData.height;
  29517. }
  29518. if (width === 0 || height === 0) {
  29519. return;
  29520. }
  29521. var totalSegs = Math.floor(30 * Math.sqrt(circleData.radius))
  29522. || Math.floor(15 * Math.sqrt(width + height));
  29523. totalSegs /= 2.3;
  29524. var seg = (Math.PI * 2) / totalSegs;
  29525. for (var i = 0; i < totalSegs - 0.5; i++) {
  29526. points.push(x + (Math.sin(-seg * i) * width), y + (Math.cos(-seg * i) * height));
  29527. }
  29528. points.push(points[0], points[1]);
  29529. },
  29530. triangulate: function (graphicsData, graphicsGeometry) {
  29531. var points = graphicsData.points;
  29532. var verts = graphicsGeometry.points;
  29533. var indices = graphicsGeometry.indices;
  29534. var vertPos = verts.length / 2;
  29535. var center = vertPos;
  29536. var circle = (graphicsData.shape);
  29537. var matrix = graphicsData.matrix;
  29538. var x = circle.x;
  29539. var y = circle.y;
  29540. // Push center (special point)
  29541. verts.push(graphicsData.matrix ? (matrix.a * x) + (matrix.c * y) + matrix.tx : x, graphicsData.matrix ? (matrix.b * x) + (matrix.d * y) + matrix.ty : y);
  29542. for (var i = 0; i < points.length; i += 2) {
  29543. verts.push(points[i], points[i + 1]);
  29544. // add some uvs
  29545. indices.push(vertPos++, center, vertPos);
  29546. }
  29547. },
  29548. };
  29549. /**
  29550. * Builds a rectangle to draw
  29551. *
  29552. * Ignored from docs since it is not directly exposed.
  29553. *
  29554. * @ignore
  29555. * @private
  29556. * @param {PIXI.WebGLGraphicsData} graphicsData - The graphics object containing all the necessary properties
  29557. * @param {object} webGLData - an object containing all the WebGL-specific information to create this shape
  29558. * @param {object} webGLDataNativeLines - an object containing all the WebGL-specific information to create nativeLines
  29559. */
  29560. var buildRectangle = {
  29561. build: function (graphicsData) {
  29562. // --- //
  29563. // need to convert points to a nice regular data
  29564. //
  29565. var rectData = graphicsData.shape;
  29566. var x = rectData.x;
  29567. var y = rectData.y;
  29568. var width = rectData.width;
  29569. var height = rectData.height;
  29570. var points = graphicsData.points;
  29571. points.length = 0;
  29572. points.push(x, y, x + width, y, x + width, y + height, x, y + height);
  29573. },
  29574. triangulate: function (graphicsData, graphicsGeometry) {
  29575. var points = graphicsData.points;
  29576. var verts = graphicsGeometry.points;
  29577. var vertPos = verts.length / 2;
  29578. verts.push(points[0], points[1], points[2], points[3], points[6], points[7], points[4], points[5]);
  29579. graphicsGeometry.indices.push(vertPos, vertPos + 1, vertPos + 2, vertPos + 1, vertPos + 2, vertPos + 3);
  29580. },
  29581. };
  29582. /**
  29583. * Calculate a single point for a quadratic bezier curve.
  29584. * Utility function used by quadraticBezierCurve.
  29585. * Ignored from docs since it is not directly exposed.
  29586. *
  29587. * @ignore
  29588. * @private
  29589. * @param {number} n1 - first number
  29590. * @param {number} n2 - second number
  29591. * @param {number} perc - percentage
  29592. * @return {number} the result
  29593. *
  29594. */
  29595. function getPt(n1, n2, perc) {
  29596. var diff = n2 - n1;
  29597. return n1 + (diff * perc);
  29598. }
  29599. /**
  29600. * Calculate the points for a quadratic bezier curve. (helper function..)
  29601. * Based on: https://stackoverflow.com/questions/785097/how-do-i-implement-a-bezier-curve-in-c
  29602. *
  29603. * Ignored from docs since it is not directly exposed.
  29604. *
  29605. * @ignore
  29606. * @private
  29607. * @param {number} fromX - Origin point x
  29608. * @param {number} fromY - Origin point x
  29609. * @param {number} cpX - Control point x
  29610. * @param {number} cpY - Control point y
  29611. * @param {number} toX - Destination point x
  29612. * @param {number} toY - Destination point y
  29613. * @param {number[]} [out=[]] - The output array to add points into. If not passed, a new array is created.
  29614. * @return {number[]} an array of points
  29615. */
  29616. function quadraticBezierCurve(fromX, fromY, cpX, cpY, toX, toY, out) {
  29617. if (out === void 0) { out = []; }
  29618. var n = 20;
  29619. var points = out;
  29620. var xa = 0;
  29621. var ya = 0;
  29622. var xb = 0;
  29623. var yb = 0;
  29624. var x = 0;
  29625. var y = 0;
  29626. for (var i = 0, j = 0; i <= n; ++i) {
  29627. j = i / n;
  29628. // The Green Line
  29629. xa = getPt(fromX, cpX, j);
  29630. ya = getPt(fromY, cpY, j);
  29631. xb = getPt(cpX, toX, j);
  29632. yb = getPt(cpY, toY, j);
  29633. // The Black Dot
  29634. x = getPt(xa, xb, j);
  29635. y = getPt(ya, yb, j);
  29636. // Handle case when first curve points overlaps and earcut fails to triangulate
  29637. if (i === 0 && points[points.length - 2] === x && points[points.length - 1] === y) {
  29638. continue;
  29639. }
  29640. points.push(x, y);
  29641. }
  29642. return points;
  29643. }
  29644. /**
  29645. * Builds a rounded rectangle to draw
  29646. *
  29647. * Ignored from docs since it is not directly exposed.
  29648. *
  29649. * @ignore
  29650. * @private
  29651. * @param {PIXI.WebGLGraphicsData} graphicsData - The graphics object containing all the necessary properties
  29652. * @param {object} webGLData - an object containing all the WebGL-specific information to create this shape
  29653. * @param {object} webGLDataNativeLines - an object containing all the WebGL-specific information to create nativeLines
  29654. */
  29655. var buildRoundedRectangle = {
  29656. build: function (graphicsData) {
  29657. var rrectData = graphicsData.shape;
  29658. var points = graphicsData.points;
  29659. var x = rrectData.x;
  29660. var y = rrectData.y;
  29661. var width = rrectData.width;
  29662. var height = rrectData.height;
  29663. // Don't allow negative radius or greater than half the smallest width
  29664. var radius = Math.max(0, Math.min(rrectData.radius, Math.min(width, height) / 2));
  29665. points.length = 0;
  29666. // No radius, do a simple rectangle
  29667. if (!radius) {
  29668. points.push(x, y, x + width, y, x + width, y + height, x, y + height);
  29669. }
  29670. else {
  29671. quadraticBezierCurve(x, y + radius, x, y, x + radius, y, points);
  29672. quadraticBezierCurve(x + width - radius, y, x + width, y, x + width, y + radius, points);
  29673. quadraticBezierCurve(x + width, y + height - radius, x + width, y + height, x + width - radius, y + height, points);
  29674. quadraticBezierCurve(x + radius, y + height, x, y + height, x, y + height - radius, points);
  29675. }
  29676. },
  29677. triangulate: function (graphicsData, graphicsGeometry) {
  29678. var points = graphicsData.points;
  29679. var verts = graphicsGeometry.points;
  29680. var indices = graphicsGeometry.indices;
  29681. var vecPos = verts.length / 2;
  29682. var triangles = earcut_1(points, null, 2);
  29683. for (var i = 0, j = triangles.length; i < j; i += 3) {
  29684. indices.push(triangles[i] + vecPos);
  29685. // indices.push(triangles[i] + vecPos);
  29686. indices.push(triangles[i + 1] + vecPos);
  29687. // indices.push(triangles[i + 2] + vecPos);
  29688. indices.push(triangles[i + 2] + vecPos);
  29689. }
  29690. for (var i = 0, j = points.length; i < j; i++) {
  29691. verts.push(points[i], points[++i]);
  29692. }
  29693. },
  29694. };
  29695. /**
  29696. * Buffers vertices to draw a square cap.
  29697. *
  29698. * Ignored from docs since it is not directly exposed.
  29699. *
  29700. * @ignore
  29701. * @private
  29702. * @param {number} x - X-coord of end point
  29703. * @param {number} y - Y-coord of end point
  29704. * @param {number} nx - X-coord of line normal pointing inside
  29705. * @param {number} ny - Y-coord of line normal pointing inside
  29706. * @param {Array<number>} verts - vertex buffer
  29707. * @returns {}
  29708. */
  29709. function square(x, y, nx, ny, innerWeight, outerWeight, clockwise, /* rotation for square (true at left end, false at right end) */ verts) {
  29710. var ix = x - (nx * innerWeight);
  29711. var iy = y - (ny * innerWeight);
  29712. var ox = x + (nx * outerWeight);
  29713. var oy = y + (ny * outerWeight);
  29714. /* Rotate nx,ny for extension vector */
  29715. var exx;
  29716. var eyy;
  29717. if (clockwise) {
  29718. exx = ny;
  29719. eyy = -nx;
  29720. }
  29721. else {
  29722. exx = -ny;
  29723. eyy = nx;
  29724. }
  29725. /* [i|0]x,y extended at cap */
  29726. var eix = ix + exx;
  29727. var eiy = iy + eyy;
  29728. var eox = ox + exx;
  29729. var eoy = oy + eyy;
  29730. /* Square itself must be inserted clockwise*/
  29731. verts.push(eix, eiy);
  29732. verts.push(eox, eoy);
  29733. return 2;
  29734. }
  29735. /**
  29736. * Buffers vertices to draw an arc at the line joint or cap.
  29737. *
  29738. * Ignored from docs since it is not directly exposed.
  29739. *
  29740. * @ignore
  29741. * @private
  29742. * @param {number} cx - X-coord of center
  29743. * @param {number} cy - Y-coord of center
  29744. * @param {number} sx - X-coord of arc start
  29745. * @param {number} sy - Y-coord of arc start
  29746. * @param {number} ex - X-coord of arc end
  29747. * @param {number} ey - Y-coord of arc end
  29748. * @param {Array<number>} verts - buffer of vertices
  29749. * @param {boolean} clockwise - orientation of vertices
  29750. * @returns {number} - no. of vertices pushed
  29751. */
  29752. function round(cx, cy, sx, sy, ex, ey, verts, clockwise) {
  29753. var cx2p0x = sx - cx;
  29754. var cy2p0y = sy - cy;
  29755. var angle0 = Math.atan2(cx2p0x, cy2p0y);
  29756. var angle1 = Math.atan2(ex - cx, ey - cy);
  29757. if (clockwise && angle0 < angle1) {
  29758. angle0 += Math.PI * 2;
  29759. }
  29760. else if (!clockwise && angle0 > angle1) {
  29761. angle1 += Math.PI * 2;
  29762. }
  29763. var startAngle = angle0;
  29764. var angleDiff = angle1 - angle0;
  29765. var absAngleDiff = Math.abs(angleDiff);
  29766. /* if (absAngleDiff >= PI_LBOUND && absAngleDiff <= PI_UBOUND)
  29767. {
  29768. const r1x = cx - nxtPx;
  29769. const r1y = cy - nxtPy;
  29770. if (r1x === 0)
  29771. {
  29772. if (r1y > 0)
  29773. {
  29774. angleDiff = -angleDiff;
  29775. }
  29776. }
  29777. else if (r1x >= -GRAPHICS_CURVES.epsilon)
  29778. {
  29779. angleDiff = -angleDiff;
  29780. }
  29781. }*/
  29782. var radius = Math.sqrt((cx2p0x * cx2p0x) + (cy2p0y * cy2p0y));
  29783. var segCount = ((15 * absAngleDiff * Math.sqrt(radius) / Math.PI) >> 0) + 1;
  29784. var angleInc = angleDiff / segCount;
  29785. startAngle += angleInc;
  29786. if (clockwise) {
  29787. verts.push(cx, cy);
  29788. verts.push(sx, sy);
  29789. for (var i = 1, angle = startAngle; i < segCount; i++, angle += angleInc) {
  29790. verts.push(cx, cy);
  29791. verts.push(cx + ((Math.sin(angle) * radius)), cy + ((Math.cos(angle) * radius)));
  29792. }
  29793. verts.push(cx, cy);
  29794. verts.push(ex, ey);
  29795. }
  29796. else {
  29797. verts.push(sx, sy);
  29798. verts.push(cx, cy);
  29799. for (var i = 1, angle = startAngle; i < segCount; i++, angle += angleInc) {
  29800. verts.push(cx + ((Math.sin(angle) * radius)), cy + ((Math.cos(angle) * radius)));
  29801. verts.push(cx, cy);
  29802. }
  29803. verts.push(ex, ey);
  29804. verts.push(cx, cy);
  29805. }
  29806. return segCount * 2;
  29807. }
  29808. /**
  29809. * Builds a line to draw using the polygon method.
  29810. *
  29811. * Ignored from docs since it is not directly exposed.
  29812. *
  29813. * @ignore
  29814. * @private
  29815. * @param {PIXI.GraphicsData} graphicsData - The graphics object containing all the necessary properties
  29816. * @param {PIXI.GraphicsGeometry} graphicsGeometry - Geometry where to append output
  29817. */
  29818. function buildNonNativeLine(graphicsData, graphicsGeometry) {
  29819. var shape = graphicsData.shape;
  29820. var points = graphicsData.points || shape.points.slice();
  29821. var eps = graphicsGeometry.closePointEps;
  29822. if (points.length === 0) {
  29823. return;
  29824. }
  29825. // if the line width is an odd number add 0.5 to align to a whole pixel
  29826. // commenting this out fixes #711 and #1620
  29827. // if (graphicsData.lineWidth%2)
  29828. // {
  29829. // for (i = 0; i < points.length; i++)
  29830. // {
  29831. // points[i] += 0.5;
  29832. // }
  29833. // }
  29834. var style = graphicsData.lineStyle;
  29835. // get first and last point.. figure out the middle!
  29836. var firstPoint = new Point(points[0], points[1]);
  29837. var lastPoint = new Point(points[points.length - 2], points[points.length - 1]);
  29838. var closedShape = shape.type !== exports.SHAPES.POLY || shape.closeStroke;
  29839. var closedPath = Math.abs(firstPoint.x - lastPoint.x) < eps
  29840. && Math.abs(firstPoint.y - lastPoint.y) < eps;
  29841. // if the first point is the last point - gonna have issues :)
  29842. if (closedShape) {
  29843. // need to clone as we are going to slightly modify the shape..
  29844. points = points.slice();
  29845. if (closedPath) {
  29846. points.pop();
  29847. points.pop();
  29848. lastPoint.set(points[points.length - 2], points[points.length - 1]);
  29849. }
  29850. var midPointX = (firstPoint.x + lastPoint.x) * 0.5;
  29851. var midPointY = (lastPoint.y + firstPoint.y) * 0.5;
  29852. points.unshift(midPointX, midPointY);
  29853. points.push(midPointX, midPointY);
  29854. }
  29855. var verts = graphicsGeometry.points;
  29856. var length = points.length / 2;
  29857. var indexCount = points.length;
  29858. var indexStart = verts.length / 2;
  29859. // Max. inner and outer width
  29860. var width = style.width / 2;
  29861. var widthSquared = width * width;
  29862. var miterLimitSquared = style.miterLimit * style.miterLimit;
  29863. /* Line segments of interest where (x1,y1) forms the corner. */
  29864. var x0 = points[0];
  29865. var y0 = points[1];
  29866. var x1 = points[2];
  29867. var y1 = points[3];
  29868. var x2 = 0;
  29869. var y2 = 0;
  29870. /* perp[?](x|y) = the line normal with magnitude lineWidth. */
  29871. var perpx = -(y0 - y1);
  29872. var perpy = x0 - x1;
  29873. var perp1x = 0;
  29874. var perp1y = 0;
  29875. var dist = Math.sqrt((perpx * perpx) + (perpy * perpy));
  29876. perpx /= dist;
  29877. perpy /= dist;
  29878. perpx *= width;
  29879. perpy *= width;
  29880. var ratio = style.alignment; // 0.5;
  29881. var innerWeight = (1 - ratio) * 2;
  29882. var outerWeight = ratio * 2;
  29883. if (!closedShape) {
  29884. if (style.cap === exports.LINE_CAP.ROUND) {
  29885. indexCount += round(x0 - (perpx * (innerWeight - outerWeight) * 0.5), y0 - (perpy * (innerWeight - outerWeight) * 0.5), x0 - (perpx * innerWeight), y0 - (perpy * innerWeight), x0 + (perpx * outerWeight), y0 + (perpy * outerWeight), verts, true) + 2;
  29886. }
  29887. else if (style.cap === exports.LINE_CAP.SQUARE) {
  29888. indexCount += square(x0, y0, perpx, perpy, innerWeight, outerWeight, true, verts);
  29889. }
  29890. }
  29891. // Push first point (below & above vertices)
  29892. verts.push(x0 - (perpx * innerWeight), y0 - (perpy * innerWeight));
  29893. verts.push(x0 + (perpx * outerWeight), y0 + (perpy * outerWeight));
  29894. for (var i = 1; i < length - 1; ++i) {
  29895. x0 = points[(i - 1) * 2];
  29896. y0 = points[((i - 1) * 2) + 1];
  29897. x1 = points[i * 2];
  29898. y1 = points[(i * 2) + 1];
  29899. x2 = points[(i + 1) * 2];
  29900. y2 = points[((i + 1) * 2) + 1];
  29901. perpx = -(y0 - y1);
  29902. perpy = x0 - x1;
  29903. dist = Math.sqrt((perpx * perpx) + (perpy * perpy));
  29904. perpx /= dist;
  29905. perpy /= dist;
  29906. perpx *= width;
  29907. perpy *= width;
  29908. perp1x = -(y1 - y2);
  29909. perp1y = x1 - x2;
  29910. dist = Math.sqrt((perp1x * perp1x) + (perp1y * perp1y));
  29911. perp1x /= dist;
  29912. perp1y /= dist;
  29913. perp1x *= width;
  29914. perp1y *= width;
  29915. /* d[x|y](0|1) = the component displacement between points p(0,1|1,2) */
  29916. var dx0 = x1 - x0;
  29917. var dy0 = y0 - y1;
  29918. var dx1 = x1 - x2;
  29919. var dy1 = y2 - y1;
  29920. /* +ve if internal angle counterclockwise, -ve if internal angle clockwise. */
  29921. var cross = (dy0 * dx1) - (dy1 * dx0);
  29922. var clockwise = (cross < 0);
  29923. /* Going nearly straight? */
  29924. if (Math.abs(cross) < 0.1) {
  29925. verts.push(x1 - (perpx * innerWeight), y1 - (perpy * innerWeight));
  29926. verts.push(x1 + (perpx * outerWeight), y1 + (perpy * outerWeight));
  29927. continue;
  29928. }
  29929. /* p[x|y] is the miter point. pdist is the distance between miter point and p1. */
  29930. var c1 = ((-perpx + x0) * (-perpy + y1)) - ((-perpx + x1) * (-perpy + y0));
  29931. var c2 = ((-perp1x + x2) * (-perp1y + y1)) - ((-perp1x + x1) * (-perp1y + y2));
  29932. var px = ((dx0 * c2) - (dx1 * c1)) / cross;
  29933. var py = ((dy1 * c1) - (dy0 * c2)) / cross;
  29934. var pdist = ((px - x1) * (px - x1)) + ((py - y1) * (py - y1));
  29935. /* Inner miter point */
  29936. var imx = x1 + ((px - x1) * innerWeight);
  29937. var imy = y1 + ((py - y1) * innerWeight);
  29938. /* Outer miter point */
  29939. var omx = x1 - ((px - x1) * outerWeight);
  29940. var omy = y1 - ((py - y1) * outerWeight);
  29941. /* Is the inside miter point too far away, creating a spike? */
  29942. var smallerInsideSegmentSq = Math.min((dx0 * dx0) + (dy0 * dy0), (dx1 * dx1) + (dy1 * dy1));
  29943. var insideWeight = clockwise ? innerWeight : outerWeight;
  29944. var smallerInsideDiagonalSq = smallerInsideSegmentSq + (insideWeight * insideWeight * widthSquared);
  29945. var insideMiterOk = pdist <= smallerInsideDiagonalSq;
  29946. if (insideMiterOk) {
  29947. if (style.join === exports.LINE_JOIN.BEVEL || pdist / widthSquared > miterLimitSquared) {
  29948. if (clockwise) /* rotating at inner angle */ {
  29949. verts.push(imx, imy); // inner miter point
  29950. verts.push(x1 + (perpx * outerWeight), y1 + (perpy * outerWeight)); // first segment's outer vertex
  29951. verts.push(imx, imy); // inner miter point
  29952. verts.push(x1 + (perp1x * outerWeight), y1 + (perp1y * outerWeight)); // second segment's outer vertex
  29953. }
  29954. else /* rotating at outer angle */ {
  29955. verts.push(x1 - (perpx * innerWeight), y1 - (perpy * innerWeight)); // first segment's inner vertex
  29956. verts.push(omx, omy); // outer miter point
  29957. verts.push(x1 - (perp1x * innerWeight), y1 - (perp1y * innerWeight)); // second segment's outer vertex
  29958. verts.push(omx, omy); // outer miter point
  29959. }
  29960. indexCount += 2;
  29961. }
  29962. else if (style.join === exports.LINE_JOIN.ROUND) {
  29963. if (clockwise) /* arc is outside */ {
  29964. verts.push(imx, imy);
  29965. verts.push(x1 + (perpx * outerWeight), y1 + (perpy * outerWeight));
  29966. indexCount += round(x1, y1, x1 + (perpx * outerWeight), y1 + (perpy * outerWeight), x1 + (perp1x * outerWeight), y1 + (perp1y * outerWeight), verts, true) + 4;
  29967. verts.push(imx, imy);
  29968. verts.push(x1 + (perp1x * outerWeight), y1 + (perp1y * outerWeight));
  29969. }
  29970. else /* arc is inside */ {
  29971. verts.push(x1 - (perpx * innerWeight), y1 - (perpy * innerWeight));
  29972. verts.push(omx, omy);
  29973. indexCount += round(x1, y1, x1 - (perpx * innerWeight), y1 - (perpy * innerWeight), x1 - (perp1x * innerWeight), y1 - (perp1y * innerWeight), verts, false) + 4;
  29974. verts.push(x1 - (perp1x * innerWeight), y1 - (perp1y * innerWeight));
  29975. verts.push(omx, omy);
  29976. }
  29977. }
  29978. else {
  29979. verts.push(imx, imy);
  29980. verts.push(omx, omy);
  29981. }
  29982. }
  29983. else // inside miter is NOT ok
  29984. {
  29985. verts.push(x1 - (perpx * innerWeight), y1 - (perpy * innerWeight)); // first segment's inner vertex
  29986. verts.push(x1 + (perpx * outerWeight), y1 + (perpy * outerWeight)); // first segment's outer vertex
  29987. if (style.join === exports.LINE_JOIN.BEVEL || pdist / widthSquared > miterLimitSquared) { ; }
  29988. else if (style.join === exports.LINE_JOIN.ROUND) {
  29989. if (clockwise) /* arc is outside */ {
  29990. indexCount += round(x1, y1, x1 + (perpx * outerWeight), y1 + (perpy * outerWeight), x1 + (perp1x * outerWeight), y1 + (perp1y * outerWeight), verts, true) + 2;
  29991. }
  29992. else /* arc is inside */ {
  29993. indexCount += round(x1, y1, x1 - (perpx * innerWeight), y1 - (perpy * innerWeight), x1 - (perp1x * innerWeight), y1 - (perp1y * innerWeight), verts, false) + 2;
  29994. }
  29995. }
  29996. else {
  29997. if (clockwise) {
  29998. verts.push(omx, omy); // inner miter point
  29999. verts.push(omx, omy); // inner miter point
  30000. }
  30001. else {
  30002. verts.push(imx, imy); // outer miter point
  30003. verts.push(imx, imy); // outer miter point
  30004. }
  30005. indexCount += 2;
  30006. }
  30007. verts.push(x1 - (perp1x * innerWeight), y1 - (perp1y * innerWeight)); // second segment's inner vertex
  30008. verts.push(x1 + (perp1x * outerWeight), y1 + (perp1y * outerWeight)); // second segment's outer vertex
  30009. indexCount += 2;
  30010. }
  30011. }
  30012. x0 = points[(length - 2) * 2];
  30013. y0 = points[((length - 2) * 2) + 1];
  30014. x1 = points[(length - 1) * 2];
  30015. y1 = points[((length - 1) * 2) + 1];
  30016. perpx = -(y0 - y1);
  30017. perpy = x0 - x1;
  30018. dist = Math.sqrt((perpx * perpx) + (perpy * perpy));
  30019. perpx /= dist;
  30020. perpy /= dist;
  30021. perpx *= width;
  30022. perpy *= width;
  30023. verts.push(x1 - (perpx * innerWeight), y1 - (perpy * innerWeight));
  30024. verts.push(x1 + (perpx * outerWeight), y1 + (perpy * outerWeight));
  30025. if (!closedShape) {
  30026. if (style.cap === exports.LINE_CAP.ROUND) {
  30027. indexCount += round(x1 - (perpx * (innerWeight - outerWeight) * 0.5), y1 - (perpy * (innerWeight - outerWeight) * 0.5), x1 - (perpx * innerWeight), y1 - (perpy * innerWeight), x1 + (perpx * outerWeight), y1 + (perpy * outerWeight), verts, false) + 2;
  30028. }
  30029. else if (style.cap === exports.LINE_CAP.SQUARE) {
  30030. indexCount += square(x1, y1, perpx, perpy, innerWeight, outerWeight, false, verts);
  30031. }
  30032. }
  30033. var indices = graphicsGeometry.indices;
  30034. var eps2 = GRAPHICS_CURVES.epsilon * GRAPHICS_CURVES.epsilon;
  30035. // indices.push(indexStart);
  30036. for (var i = indexStart; i < indexCount + indexStart - 2; ++i) {
  30037. x0 = verts[(i * 2)];
  30038. y0 = verts[(i * 2) + 1];
  30039. x1 = verts[(i + 1) * 2];
  30040. y1 = verts[((i + 1) * 2) + 1];
  30041. x2 = verts[(i + 2) * 2];
  30042. y2 = verts[((i + 2) * 2) + 1];
  30043. /* Skip zero area triangles */
  30044. if (Math.abs((x0 * (y1 - y2)) + (x1 * (y2 - y0)) + (x2 * (y0 - y1))) < eps2) {
  30045. continue;
  30046. }
  30047. indices.push(i, i + 1, i + 2);
  30048. }
  30049. }
  30050. /**
  30051. * Builds a line to draw using the gl.drawArrays(gl.LINES) method
  30052. *
  30053. * Ignored from docs since it is not directly exposed.
  30054. *
  30055. * @ignore
  30056. * @private
  30057. * @param {PIXI.GraphicsData} graphicsData - The graphics object containing all the necessary properties
  30058. * @param {PIXI.GraphicsGeometry} graphicsGeometry - Geometry where to append output
  30059. */
  30060. function buildNativeLine(graphicsData, graphicsGeometry) {
  30061. var i = 0;
  30062. var shape = graphicsData.shape;
  30063. var points = graphicsData.points || shape.points;
  30064. var closedShape = shape.type !== exports.SHAPES.POLY || shape.closeStroke;
  30065. if (points.length === 0)
  30066. { return; }
  30067. var verts = graphicsGeometry.points;
  30068. var indices = graphicsGeometry.indices;
  30069. var length = points.length / 2;
  30070. var startIndex = verts.length / 2;
  30071. var currentIndex = startIndex;
  30072. verts.push(points[0], points[1]);
  30073. for (i = 1; i < length; i++) {
  30074. verts.push(points[i * 2], points[(i * 2) + 1]);
  30075. indices.push(currentIndex, currentIndex + 1);
  30076. currentIndex++;
  30077. }
  30078. if (closedShape) {
  30079. indices.push(currentIndex, startIndex);
  30080. }
  30081. }
  30082. /**
  30083. * Builds a line to draw
  30084. *
  30085. * Ignored from docs since it is not directly exposed.
  30086. *
  30087. * @ignore
  30088. * @private
  30089. * @param {PIXI.GraphicsData} graphicsData - The graphics object containing all the necessary properties
  30090. * @param {PIXI.GraphicsGeometry} graphicsGeometry - Geometry where to append output
  30091. */
  30092. function buildLine(graphicsData, graphicsGeometry) {
  30093. if (graphicsData.lineStyle.native) {
  30094. buildNativeLine(graphicsData, graphicsGeometry);
  30095. }
  30096. else {
  30097. buildNonNativeLine(graphicsData, graphicsGeometry);
  30098. }
  30099. }
  30100. /**
  30101. * Utilities for arc curves
  30102. * @class
  30103. * @private
  30104. */
  30105. var ArcUtils = /** @class */ (function () {
  30106. function ArcUtils() {
  30107. }
  30108. /**
  30109. * The arcTo() method creates an arc/curve between two tangents on the canvas.
  30110. *
  30111. * "borrowed" from https://code.google.com/p/fxcanvas/ - thanks google!
  30112. *
  30113. * @private
  30114. * @param {number} x1 - The x-coordinate of the beginning of the arc
  30115. * @param {number} y1 - The y-coordinate of the beginning of the arc
  30116. * @param {number} x2 - The x-coordinate of the end of the arc
  30117. * @param {number} y2 - The y-coordinate of the end of the arc
  30118. * @param {number} radius - The radius of the arc
  30119. * @return {object} If the arc length is valid, return center of circle, radius and other info otherwise `null`.
  30120. */
  30121. ArcUtils.curveTo = function (x1, y1, x2, y2, radius, points) {
  30122. var fromX = points[points.length - 2];
  30123. var fromY = points[points.length - 1];
  30124. var a1 = fromY - y1;
  30125. var b1 = fromX - x1;
  30126. var a2 = y2 - y1;
  30127. var b2 = x2 - x1;
  30128. var mm = Math.abs((a1 * b2) - (b1 * a2));
  30129. if (mm < 1.0e-8 || radius === 0) {
  30130. if (points[points.length - 2] !== x1 || points[points.length - 1] !== y1) {
  30131. points.push(x1, y1);
  30132. }
  30133. return null;
  30134. }
  30135. var dd = (a1 * a1) + (b1 * b1);
  30136. var cc = (a2 * a2) + (b2 * b2);
  30137. var tt = (a1 * a2) + (b1 * b2);
  30138. var k1 = radius * Math.sqrt(dd) / mm;
  30139. var k2 = radius * Math.sqrt(cc) / mm;
  30140. var j1 = k1 * tt / dd;
  30141. var j2 = k2 * tt / cc;
  30142. var cx = (k1 * b2) + (k2 * b1);
  30143. var cy = (k1 * a2) + (k2 * a1);
  30144. var px = b1 * (k2 + j1);
  30145. var py = a1 * (k2 + j1);
  30146. var qx = b2 * (k1 + j2);
  30147. var qy = a2 * (k1 + j2);
  30148. var startAngle = Math.atan2(py - cy, px - cx);
  30149. var endAngle = Math.atan2(qy - cy, qx - cx);
  30150. return {
  30151. cx: (cx + x1),
  30152. cy: (cy + y1),
  30153. radius: radius,
  30154. startAngle: startAngle,
  30155. endAngle: endAngle,
  30156. anticlockwise: (b1 * a2 > b2 * a1),
  30157. };
  30158. };
  30159. /* eslint-disable max-len */
  30160. /**
  30161. * The arc method creates an arc/curve (used to create circles, or parts of circles).
  30162. *
  30163. * @private
  30164. * @param {number} startX - Start x location of arc
  30165. * @param {number} startY - Start y location of arc
  30166. * @param {number} cx - The x-coordinate of the center of the circle
  30167. * @param {number} cy - The y-coordinate of the center of the circle
  30168. * @param {number} radius - The radius of the circle
  30169. * @param {number} startAngle - The starting angle, in radians (0 is at the 3 o'clock position
  30170. * of the arc's circle)
  30171. * @param {number} endAngle - The ending angle, in radians
  30172. * @param {boolean} anticlockwise - Specifies whether the drawing should be
  30173. * counter-clockwise or clockwise. False is default, and indicates clockwise, while true
  30174. * indicates counter-clockwise.
  30175. * @param {number[]} points - Collection of points to add to
  30176. */
  30177. ArcUtils.arc = function (_startX, _startY, cx, cy, radius, startAngle, endAngle, _anticlockwise, points) {
  30178. var sweep = endAngle - startAngle;
  30179. var n = GRAPHICS_CURVES._segmentsCount(Math.abs(sweep) * radius, Math.ceil(Math.abs(sweep) / PI_2) * 40);
  30180. var theta = (sweep) / (n * 2);
  30181. var theta2 = theta * 2;
  30182. var cTheta = Math.cos(theta);
  30183. var sTheta = Math.sin(theta);
  30184. var segMinus = n - 1;
  30185. var remainder = (segMinus % 1) / segMinus;
  30186. for (var i = 0; i <= segMinus; ++i) {
  30187. var real = i + (remainder * i);
  30188. var angle = ((theta) + startAngle + (theta2 * real));
  30189. var c = Math.cos(angle);
  30190. var s = -Math.sin(angle);
  30191. points.push((((cTheta * c) + (sTheta * s)) * radius) + cx, (((cTheta * -s) + (sTheta * c)) * radius) + cy);
  30192. }
  30193. };
  30194. return ArcUtils;
  30195. }());
  30196. /**
  30197. * Utilities for bezier curves
  30198. * @class
  30199. * @private
  30200. */
  30201. var BezierUtils = /** @class */ (function () {
  30202. function BezierUtils() {
  30203. }
  30204. /**
  30205. * Calculate length of bezier curve.
  30206. * Analytical solution is impossible, since it involves an integral that does not integrate in general.
  30207. * Therefore numerical solution is used.
  30208. *
  30209. * @private
  30210. * @param {number} fromX - Starting point x
  30211. * @param {number} fromY - Starting point y
  30212. * @param {number} cpX - Control point x
  30213. * @param {number} cpY - Control point y
  30214. * @param {number} cpX2 - Second Control point x
  30215. * @param {number} cpY2 - Second Control point y
  30216. * @param {number} toX - Destination point x
  30217. * @param {number} toY - Destination point y
  30218. * @return {number} Length of bezier curve
  30219. */
  30220. BezierUtils.curveLength = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY) {
  30221. var n = 10;
  30222. var result = 0.0;
  30223. var t = 0.0;
  30224. var t2 = 0.0;
  30225. var t3 = 0.0;
  30226. var nt = 0.0;
  30227. var nt2 = 0.0;
  30228. var nt3 = 0.0;
  30229. var x = 0.0;
  30230. var y = 0.0;
  30231. var dx = 0.0;
  30232. var dy = 0.0;
  30233. var prevX = fromX;
  30234. var prevY = fromY;
  30235. for (var i = 1; i <= n; ++i) {
  30236. t = i / n;
  30237. t2 = t * t;
  30238. t3 = t2 * t;
  30239. nt = (1.0 - t);
  30240. nt2 = nt * nt;
  30241. nt3 = nt2 * nt;
  30242. x = (nt3 * fromX) + (3.0 * nt2 * t * cpX) + (3.0 * nt * t2 * cpX2) + (t3 * toX);
  30243. y = (nt3 * fromY) + (3.0 * nt2 * t * cpY) + (3 * nt * t2 * cpY2) + (t3 * toY);
  30244. dx = prevX - x;
  30245. dy = prevY - y;
  30246. prevX = x;
  30247. prevY = y;
  30248. result += Math.sqrt((dx * dx) + (dy * dy));
  30249. }
  30250. return result;
  30251. };
  30252. /**
  30253. * Calculate the points for a bezier curve and then draws it.
  30254. *
  30255. * Ignored from docs since it is not directly exposed.
  30256. *
  30257. * @ignore
  30258. * @param {number} cpX - Control point x
  30259. * @param {number} cpY - Control point y
  30260. * @param {number} cpX2 - Second Control point x
  30261. * @param {number} cpY2 - Second Control point y
  30262. * @param {number} toX - Destination point x
  30263. * @param {number} toY - Destination point y
  30264. * @param {number[]} points - Path array to push points into
  30265. */
  30266. BezierUtils.curveTo = function (cpX, cpY, cpX2, cpY2, toX, toY, points) {
  30267. var fromX = points[points.length - 2];
  30268. var fromY = points[points.length - 1];
  30269. points.length -= 2;
  30270. var n = GRAPHICS_CURVES._segmentsCount(BezierUtils.curveLength(fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY));
  30271. var dt = 0;
  30272. var dt2 = 0;
  30273. var dt3 = 0;
  30274. var t2 = 0;
  30275. var t3 = 0;
  30276. points.push(fromX, fromY);
  30277. for (var i = 1, j = 0; i <= n; ++i) {
  30278. j = i / n;
  30279. dt = (1 - j);
  30280. dt2 = dt * dt;
  30281. dt3 = dt2 * dt;
  30282. t2 = j * j;
  30283. t3 = t2 * j;
  30284. points.push((dt3 * fromX) + (3 * dt2 * j * cpX) + (3 * dt * t2 * cpX2) + (t3 * toX), (dt3 * fromY) + (3 * dt2 * j * cpY) + (3 * dt * t2 * cpY2) + (t3 * toY));
  30285. }
  30286. };
  30287. return BezierUtils;
  30288. }());
  30289. /**
  30290. * Utilities for quadratic curves
  30291. * @class
  30292. * @private
  30293. */
  30294. var QuadraticUtils = /** @class */ (function () {
  30295. function QuadraticUtils() {
  30296. }
  30297. /**
  30298. * Calculate length of quadratic curve
  30299. * @see {@link http://www.malczak.linuxpl.com/blog/quadratic-bezier-curve-length/}
  30300. * for the detailed explanation of math behind this.
  30301. *
  30302. * @private
  30303. * @param {number} fromX - x-coordinate of curve start point
  30304. * @param {number} fromY - y-coordinate of curve start point
  30305. * @param {number} cpX - x-coordinate of curve control point
  30306. * @param {number} cpY - y-coordinate of curve control point
  30307. * @param {number} toX - x-coordinate of curve end point
  30308. * @param {number} toY - y-coordinate of curve end point
  30309. * @return {number} Length of quadratic curve
  30310. */
  30311. QuadraticUtils.curveLength = function (fromX, fromY, cpX, cpY, toX, toY) {
  30312. var ax = fromX - (2.0 * cpX) + toX;
  30313. var ay = fromY - (2.0 * cpY) + toY;
  30314. var bx = (2.0 * cpX) - (2.0 * fromX);
  30315. var by = (2.0 * cpY) - (2.0 * fromY);
  30316. var a = 4.0 * ((ax * ax) + (ay * ay));
  30317. var b = 4.0 * ((ax * bx) + (ay * by));
  30318. var c = (bx * bx) + (by * by);
  30319. var s = 2.0 * Math.sqrt(a + b + c);
  30320. var a2 = Math.sqrt(a);
  30321. var a32 = 2.0 * a * a2;
  30322. var c2 = 2.0 * Math.sqrt(c);
  30323. var ba = b / a2;
  30324. return ((a32 * s)
  30325. + (a2 * b * (s - c2))
  30326. + (((4.0 * c * a) - (b * b))
  30327. * Math.log(((2.0 * a2) + ba + s) / (ba + c2)))) / (4.0 * a32);
  30328. };
  30329. /**
  30330. * Calculate the points for a quadratic bezier curve and then draws it.
  30331. * Based on: https://stackoverflow.com/questions/785097/how-do-i-implement-a-bezier-curve-in-c
  30332. *
  30333. * @private
  30334. * @param {number} cpX - Control point x
  30335. * @param {number} cpY - Control point y
  30336. * @param {number} toX - Destination point x
  30337. * @param {number} toY - Destination point y
  30338. * @param {number[]} points - Points to add segments to.
  30339. */
  30340. QuadraticUtils.curveTo = function (cpX, cpY, toX, toY, points) {
  30341. var fromX = points[points.length - 2];
  30342. var fromY = points[points.length - 1];
  30343. var n = GRAPHICS_CURVES._segmentsCount(QuadraticUtils.curveLength(fromX, fromY, cpX, cpY, toX, toY));
  30344. var xa = 0;
  30345. var ya = 0;
  30346. for (var i = 1; i <= n; ++i) {
  30347. var j = i / n;
  30348. xa = fromX + ((cpX - fromX) * j);
  30349. ya = fromY + ((cpY - fromY) * j);
  30350. points.push(xa + (((cpX + ((toX - cpX) * j)) - xa) * j), ya + (((cpY + ((toY - cpY) * j)) - ya) * j));
  30351. }
  30352. };
  30353. return QuadraticUtils;
  30354. }());
  30355. /**
  30356. * A structure to hold interim batch objects for Graphics.
  30357. * @class
  30358. * @memberof PIXI.graphicsUtils
  30359. */
  30360. var BatchPart = /** @class */ (function () {
  30361. function BatchPart() {
  30362. this.reset();
  30363. }
  30364. /**
  30365. * Begin batch part
  30366. *
  30367. * @param {PIXI.FillStyle | PIXI.LineStyle} style
  30368. * @param {number} startIndex
  30369. * @param {number} attribStart
  30370. */
  30371. BatchPart.prototype.begin = function (style, startIndex, attribStart) {
  30372. this.reset();
  30373. this.style = style;
  30374. this.start = startIndex;
  30375. this.attribStart = attribStart;
  30376. };
  30377. /**
  30378. * End batch part
  30379. *
  30380. * @param {number} endIndex
  30381. * @param {number} endAttrib
  30382. */
  30383. BatchPart.prototype.end = function (endIndex, endAttrib) {
  30384. this.attribSize = endAttrib - this.attribStart;
  30385. this.size = endIndex - this.start;
  30386. };
  30387. BatchPart.prototype.reset = function () {
  30388. this.style = null;
  30389. this.size = 0;
  30390. this.start = 0;
  30391. this.attribStart = 0;
  30392. this.attribSize = 0;
  30393. };
  30394. return BatchPart;
  30395. }());
  30396. /**
  30397. * Generalized convenience utilities for Graphics.
  30398. *
  30399. * @namespace graphicsUtils
  30400. * @memberof PIXI
  30401. */
  30402. var _a$3;
  30403. /**
  30404. * Map of fill commands for each shape type.
  30405. *
  30406. * @memberof PIXI.graphicsUtils
  30407. * @member {Object} FILL_COMMANDS
  30408. */
  30409. var FILL_COMMANDS = (_a$3 = {},
  30410. _a$3[exports.SHAPES.POLY] = buildPoly,
  30411. _a$3[exports.SHAPES.CIRC] = buildCircle,
  30412. _a$3[exports.SHAPES.ELIP] = buildCircle,
  30413. _a$3[exports.SHAPES.RECT] = buildRectangle,
  30414. _a$3[exports.SHAPES.RREC] = buildRoundedRectangle,
  30415. _a$3);
  30416. /**
  30417. * Batch pool, stores unused batches for preventing allocations.
  30418. *
  30419. * @memberof PIXI.graphicsUtils
  30420. * @member {Array<PIXI.graphicsUtils.BatchPart>} BATCH_POOL
  30421. */
  30422. var BATCH_POOL = [];
  30423. /**
  30424. * Draw call pool, stores unused draw calls for preventing allocations.
  30425. *
  30426. * @memberof PIXI.graphicsUtils
  30427. * @member {Array<PIXI.BatchDrawCall>} DRAW_CALL_POOL
  30428. */
  30429. var DRAW_CALL_POOL = [];
  30430. /**
  30431. * Determine if polygon is clockwise or counterclockwise.
  30432. * @see {@link https://stackoverflow.com/questions/1165647}
  30433. *
  30434. * Ignored from docs since it is not directly exposed.
  30435. *
  30436. * @ignore
  30437. * @private
  30438. * @param {Polygon} polygon
  30439. * @return {boolean}
  30440. */
  30441. function isPolygonClockwise(polygon) {
  30442. var points = polygon.points;
  30443. var sum = 0;
  30444. for (var i = 0; i < points.length - 2; i += 2) {
  30445. sum += (points[i + 2] - points[i]) * (points[i + 3] + points[i + 1]);
  30446. }
  30447. return sum > 0;
  30448. }
  30449. /**
  30450. * A class to contain data useful for Graphics objects
  30451. *
  30452. * @class
  30453. * @memberof PIXI
  30454. */
  30455. var GraphicsData = /** @class */ (function () {
  30456. /**
  30457. *
  30458. * @param {PIXI.Circle|PIXI.Ellipse|PIXI.Polygon|PIXI.Rectangle|PIXI.RoundedRectangle} shape - The shape object to draw.
  30459. * @param {PIXI.FillStyle} [fillStyle] - the width of the line to draw
  30460. * @param {PIXI.LineStyle} [lineStyle] - the color of the line to draw
  30461. * @param {PIXI.Matrix} [matrix] - Transform matrix
  30462. */
  30463. function GraphicsData(shape, fillStyle, lineStyle, matrix) {
  30464. if (fillStyle === void 0) { fillStyle = null; }
  30465. if (lineStyle === void 0) { lineStyle = null; }
  30466. if (matrix === void 0) { matrix = null; }
  30467. /** The collection of points. */
  30468. this.points = [];
  30469. /**
  30470. * The collection of holes.
  30471. *
  30472. * @member {PIXI.GraphicsData[]}
  30473. */
  30474. this.holes = [];
  30475. /**
  30476. * The shape object to draw.
  30477. * @member {PIXI.Circle|PIXI.Ellipse|PIXI.Polygon|PIXI.Rectangle|PIXI.RoundedRectangle}
  30478. */
  30479. this.shape = shape;
  30480. /**
  30481. * The style of the line.
  30482. * @member {PIXI.LineStyle}
  30483. */
  30484. this.lineStyle = lineStyle;
  30485. /**
  30486. * The style of the fill.
  30487. * @member {PIXI.FillStyle}
  30488. */
  30489. this.fillStyle = fillStyle;
  30490. /**
  30491. * The transform matrix.
  30492. * @member {PIXI.Matrix}
  30493. */
  30494. this.matrix = matrix;
  30495. /**
  30496. * The type of the shape, see the Const.Shapes file for all the existing types,
  30497. * @member {number}
  30498. */
  30499. this.type = shape.type;
  30500. }
  30501. /**
  30502. * Creates a new GraphicsData object with the same values as this one.
  30503. *
  30504. * @return {PIXI.GraphicsData} Cloned GraphicsData object
  30505. */
  30506. GraphicsData.prototype.clone = function () {
  30507. return new GraphicsData(this.shape, this.fillStyle, this.lineStyle, this.matrix);
  30508. };
  30509. /**
  30510. * Destroys the Graphics data.
  30511. *
  30512. */
  30513. GraphicsData.prototype.destroy = function () {
  30514. this.shape = null;
  30515. this.holes.length = 0;
  30516. this.holes = null;
  30517. this.points.length = 0;
  30518. this.points = null;
  30519. this.lineStyle = null;
  30520. this.fillStyle = null;
  30521. };
  30522. return GraphicsData;
  30523. }());
  30524. var tmpPoint = new Point();
  30525. var tmpBounds = new Bounds();
  30526. /**
  30527. * The Graphics class contains methods used to draw primitive shapes such as lines, circles and
  30528. * rectangles to the display, and to color and fill them.
  30529. *
  30530. * GraphicsGeometry is designed to not be continually updating the geometry since it's expensive
  30531. * to re-tesselate using **earcut**. Consider using {@link PIXI.Mesh} for this use-case, it's much faster.
  30532. *
  30533. * @class
  30534. * @extends PIXI.BatchGeometry
  30535. * @memberof PIXI
  30536. */
  30537. var GraphicsGeometry = /** @class */ (function (_super) {
  30538. __extends$5(GraphicsGeometry, _super);
  30539. // eslint-disable-next-line @typescript-eslint/no-useless-constructor
  30540. function GraphicsGeometry() {
  30541. var _this = _super.call(this) || this;
  30542. /**
  30543. * Minimal distance between points that are considered different.
  30544. * Affects line tesselation.
  30545. */
  30546. _this.closePointEps = 1e-4;
  30547. /** Padding to add to the bounds. */
  30548. _this.boundsPadding = 0;
  30549. _this.uvsFloat32 = null;
  30550. _this.indicesUint16 = null;
  30551. _this.batchable = false;
  30552. /** An array of points to draw, 2 numbers per point */
  30553. _this.points = [];
  30554. /** The collection of colors */
  30555. _this.colors = [];
  30556. /** The UVs collection */
  30557. _this.uvs = [];
  30558. /** The indices of the vertices */
  30559. _this.indices = [];
  30560. /** Reference to the texture IDs. */
  30561. _this.textureIds = [];
  30562. /**
  30563. * The collection of drawn shapes.
  30564. *
  30565. * @member {PIXI.GraphicsData[]}
  30566. */
  30567. _this.graphicsData = [];
  30568. /**
  30569. * List of current draw calls drived from the batches.
  30570. *
  30571. * @member {PIXI.BatchDrawCall[]}
  30572. */
  30573. _this.drawCalls = [];
  30574. /** Batches need to regenerated if the geometry is updated. */
  30575. _this.batchDirty = -1;
  30576. /**
  30577. * Intermediate abstract format sent to batch system.
  30578. * Can be converted to drawCalls or to batchable objects.
  30579. *
  30580. * @member {PIXI.graphicsUtils.BatchPart[]}
  30581. */
  30582. _this.batches = [];
  30583. /** Used to detect if the graphics object has changed. */
  30584. _this.dirty = 0;
  30585. /** Used to check if the cache is dirty. */
  30586. _this.cacheDirty = -1;
  30587. /** Used to detect if we cleared the graphicsData. */
  30588. _this.clearDirty = 0;
  30589. /** Index of the last batched shape in the stack of calls. */
  30590. _this.shapeIndex = 0;
  30591. /**
  30592. * Cached bounds.
  30593. *
  30594. * @member {PIXI.Bounds}
  30595. */
  30596. _this._bounds = new Bounds();
  30597. /** The bounds dirty flag. */
  30598. _this.boundsDirty = -1;
  30599. return _this;
  30600. }
  30601. Object.defineProperty(GraphicsGeometry.prototype, "bounds", {
  30602. /**
  30603. * Get the current bounds of the graphic geometry.
  30604. *
  30605. * @member {PIXI.Bounds}
  30606. * @readonly
  30607. */
  30608. get: function () {
  30609. if (this.boundsDirty !== this.dirty) {
  30610. this.boundsDirty = this.dirty;
  30611. this.calculateBounds();
  30612. }
  30613. return this._bounds;
  30614. },
  30615. enumerable: false,
  30616. configurable: true
  30617. });
  30618. /**
  30619. * Call if you changed graphicsData manually.
  30620. * Empties all batch buffers.
  30621. */
  30622. GraphicsGeometry.prototype.invalidate = function () {
  30623. this.boundsDirty = -1;
  30624. this.dirty++;
  30625. this.batchDirty++;
  30626. this.shapeIndex = 0;
  30627. this.points.length = 0;
  30628. this.colors.length = 0;
  30629. this.uvs.length = 0;
  30630. this.indices.length = 0;
  30631. this.textureIds.length = 0;
  30632. for (var i = 0; i < this.drawCalls.length; i++) {
  30633. this.drawCalls[i].texArray.clear();
  30634. DRAW_CALL_POOL.push(this.drawCalls[i]);
  30635. }
  30636. this.drawCalls.length = 0;
  30637. for (var i = 0; i < this.batches.length; i++) {
  30638. var batchPart = this.batches[i];
  30639. batchPart.reset();
  30640. BATCH_POOL.push(batchPart);
  30641. }
  30642. this.batches.length = 0;
  30643. };
  30644. /**
  30645. * Clears the graphics that were drawn to this Graphics object, and resets fill and line style settings.
  30646. *
  30647. * @return {PIXI.GraphicsGeometry} This GraphicsGeometry object. Good for chaining method calls
  30648. */
  30649. GraphicsGeometry.prototype.clear = function () {
  30650. if (this.graphicsData.length > 0) {
  30651. this.invalidate();
  30652. this.clearDirty++;
  30653. this.graphicsData.length = 0;
  30654. }
  30655. return this;
  30656. };
  30657. /**
  30658. * Draws the given shape to this Graphics object. Can be any of Circle, Rectangle, Ellipse, Line or Polygon.
  30659. *
  30660. * @param {PIXI.Circle|PIXI.Ellipse|PIXI.Polygon|PIXI.Rectangle|PIXI.RoundedRectangle} shape - The shape object to draw.
  30661. * @param {PIXI.FillStyle} fillStyle - Defines style of the fill.
  30662. * @param {PIXI.LineStyle} lineStyle - Defines style of the lines.
  30663. * @param {PIXI.Matrix} matrix - Transform applied to the points of the shape.
  30664. * @return {PIXI.GraphicsGeometry} Returns geometry for chaining.
  30665. */
  30666. GraphicsGeometry.prototype.drawShape = function (shape, fillStyle, lineStyle, matrix) {
  30667. if (fillStyle === void 0) { fillStyle = null; }
  30668. if (lineStyle === void 0) { lineStyle = null; }
  30669. if (matrix === void 0) { matrix = null; }
  30670. var data = new GraphicsData(shape, fillStyle, lineStyle, matrix);
  30671. this.graphicsData.push(data);
  30672. this.dirty++;
  30673. return this;
  30674. };
  30675. /**
  30676. * Draws the given shape to this Graphics object. Can be any of Circle, Rectangle, Ellipse, Line or Polygon.
  30677. *
  30678. * @param {PIXI.Circle|PIXI.Ellipse|PIXI.Polygon|PIXI.Rectangle|PIXI.RoundedRectangle} shape - The shape object to draw.
  30679. * @param {PIXI.Matrix} matrix - Transform applied to the points of the shape.
  30680. * @return {PIXI.GraphicsGeometry} Returns geometry for chaining.
  30681. */
  30682. GraphicsGeometry.prototype.drawHole = function (shape, matrix) {
  30683. if (matrix === void 0) { matrix = null; }
  30684. if (!this.graphicsData.length) {
  30685. return null;
  30686. }
  30687. var data = new GraphicsData(shape, null, null, matrix);
  30688. var lastShape = this.graphicsData[this.graphicsData.length - 1];
  30689. data.lineStyle = lastShape.lineStyle;
  30690. lastShape.holes.push(data);
  30691. this.dirty++;
  30692. return this;
  30693. };
  30694. /**
  30695. * Destroys the GraphicsGeometry object.
  30696. *
  30697. */
  30698. GraphicsGeometry.prototype.destroy = function () {
  30699. _super.prototype.destroy.call(this);
  30700. // destroy each of the GraphicsData objects
  30701. for (var i = 0; i < this.graphicsData.length; ++i) {
  30702. this.graphicsData[i].destroy();
  30703. }
  30704. this.points.length = 0;
  30705. this.points = null;
  30706. this.colors.length = 0;
  30707. this.colors = null;
  30708. this.uvs.length = 0;
  30709. this.uvs = null;
  30710. this.indices.length = 0;
  30711. this.indices = null;
  30712. this.indexBuffer.destroy();
  30713. this.indexBuffer = null;
  30714. this.graphicsData.length = 0;
  30715. this.graphicsData = null;
  30716. this.drawCalls.length = 0;
  30717. this.drawCalls = null;
  30718. this.batches.length = 0;
  30719. this.batches = null;
  30720. this._bounds = null;
  30721. };
  30722. /**
  30723. * Check to see if a point is contained within this geometry.
  30724. *
  30725. * @param {PIXI.IPointData} point - Point to check if it's contained.
  30726. * @return {Boolean} `true` if the point is contained within geometry.
  30727. */
  30728. GraphicsGeometry.prototype.containsPoint = function (point) {
  30729. var graphicsData = this.graphicsData;
  30730. for (var i = 0; i < graphicsData.length; ++i) {
  30731. var data = graphicsData[i];
  30732. if (!data.fillStyle.visible) {
  30733. continue;
  30734. }
  30735. // only deal with fills..
  30736. if (data.shape) {
  30737. if (data.matrix) {
  30738. data.matrix.applyInverse(point, tmpPoint);
  30739. }
  30740. else {
  30741. tmpPoint.copyFrom(point);
  30742. }
  30743. if (data.shape.contains(tmpPoint.x, tmpPoint.y)) {
  30744. var hitHole = false;
  30745. if (data.holes) {
  30746. for (var i_1 = 0; i_1 < data.holes.length; i_1++) {
  30747. var hole = data.holes[i_1];
  30748. if (hole.shape.contains(tmpPoint.x, tmpPoint.y)) {
  30749. hitHole = true;
  30750. break;
  30751. }
  30752. }
  30753. }
  30754. if (!hitHole) {
  30755. return true;
  30756. }
  30757. }
  30758. }
  30759. }
  30760. return false;
  30761. };
  30762. /**
  30763. * Generates intermediate batch data. Either gets converted to drawCalls
  30764. * or used to convert to batch objects directly by the Graphics object.
  30765. *
  30766. * @param {boolean} [allow32Indices] - Allow using 32-bit indices for preventing artifacts when more that 65535 vertices
  30767. */
  30768. GraphicsGeometry.prototype.updateBatches = function (allow32Indices) {
  30769. if (!this.graphicsData.length) {
  30770. this.batchable = true;
  30771. return;
  30772. }
  30773. if (!this.validateBatching()) {
  30774. return;
  30775. }
  30776. this.cacheDirty = this.dirty;
  30777. var uvs = this.uvs;
  30778. var graphicsData = this.graphicsData;
  30779. var batchPart = null;
  30780. var currentStyle = null;
  30781. if (this.batches.length > 0) {
  30782. batchPart = this.batches[this.batches.length - 1];
  30783. currentStyle = batchPart.style;
  30784. }
  30785. for (var i = this.shapeIndex; i < graphicsData.length; i++) {
  30786. this.shapeIndex++;
  30787. var data = graphicsData[i];
  30788. var fillStyle = data.fillStyle;
  30789. var lineStyle = data.lineStyle;
  30790. var command = FILL_COMMANDS[data.type];
  30791. // build out the shapes points..
  30792. command.build(data);
  30793. if (data.matrix) {
  30794. this.transformPoints(data.points, data.matrix);
  30795. }
  30796. for (var j = 0; j < 2; j++) {
  30797. var style = (j === 0) ? fillStyle : lineStyle;
  30798. if (!style.visible)
  30799. { continue; }
  30800. var nextTexture = style.texture.baseTexture;
  30801. var index_1 = this.indices.length;
  30802. var attribIndex = this.points.length / 2;
  30803. nextTexture.wrapMode = exports.WRAP_MODES.REPEAT;
  30804. if (j === 0) {
  30805. this.processFill(data);
  30806. }
  30807. else {
  30808. this.processLine(data);
  30809. }
  30810. var size = (this.points.length / 2) - attribIndex;
  30811. if (size === 0)
  30812. { continue; }
  30813. // close batch if style is different
  30814. if (batchPart && !this._compareStyles(currentStyle, style)) {
  30815. batchPart.end(index_1, attribIndex);
  30816. batchPart = null;
  30817. }
  30818. // spawn new batch if its first batch or previous was closed
  30819. if (!batchPart) {
  30820. batchPart = BATCH_POOL.pop() || new BatchPart();
  30821. batchPart.begin(style, index_1, attribIndex);
  30822. this.batches.push(batchPart);
  30823. currentStyle = style;
  30824. }
  30825. this.addUvs(this.points, uvs, style.texture, attribIndex, size, style.matrix);
  30826. }
  30827. }
  30828. var index = this.indices.length;
  30829. var attrib = this.points.length / 2;
  30830. if (batchPart) {
  30831. batchPart.end(index, attrib);
  30832. }
  30833. if (this.batches.length === 0) {
  30834. // there are no visible styles in GraphicsData
  30835. // its possible that someone wants Graphics just for the bounds
  30836. this.batchable = true;
  30837. return;
  30838. }
  30839. // prevent allocation when length is same as buffer
  30840. if (this.indicesUint16 && this.indices.length === this.indicesUint16.length) {
  30841. this.indicesUint16.set(this.indices);
  30842. }
  30843. else {
  30844. var need32 = attrib > 0xffff && allow32Indices;
  30845. this.indicesUint16 = need32 ? new Uint32Array(this.indices) : new Uint16Array(this.indices);
  30846. }
  30847. // TODO make this a const..
  30848. this.batchable = this.isBatchable();
  30849. if (this.batchable) {
  30850. this.packBatches();
  30851. }
  30852. else {
  30853. this.buildDrawCalls();
  30854. }
  30855. };
  30856. /**
  30857. * Affinity check
  30858. *
  30859. * @param {PIXI.FillStyle | PIXI.LineStyle} styleA
  30860. * @param {PIXI.FillStyle | PIXI.LineStyle} styleB
  30861. */
  30862. GraphicsGeometry.prototype._compareStyles = function (styleA, styleB) {
  30863. if (!styleA || !styleB) {
  30864. return false;
  30865. }
  30866. if (styleA.texture.baseTexture !== styleB.texture.baseTexture) {
  30867. return false;
  30868. }
  30869. if (styleA.color + styleA.alpha !== styleB.color + styleB.alpha) {
  30870. return false;
  30871. }
  30872. if (!!styleA.native !== !!styleB.native) {
  30873. return false;
  30874. }
  30875. return true;
  30876. };
  30877. /**
  30878. * Test geometry for batching process.
  30879. *
  30880. * @protected
  30881. */
  30882. GraphicsGeometry.prototype.validateBatching = function () {
  30883. if (this.dirty === this.cacheDirty || !this.graphicsData.length) {
  30884. return false;
  30885. }
  30886. for (var i = 0, l = this.graphicsData.length; i < l; i++) {
  30887. var data = this.graphicsData[i];
  30888. var fill = data.fillStyle;
  30889. var line = data.lineStyle;
  30890. if (fill && !fill.texture.baseTexture.valid)
  30891. { return false; }
  30892. if (line && !line.texture.baseTexture.valid)
  30893. { return false; }
  30894. }
  30895. return true;
  30896. };
  30897. /**
  30898. * Offset the indices so that it works with the batcher.
  30899. *
  30900. * @protected
  30901. */
  30902. GraphicsGeometry.prototype.packBatches = function () {
  30903. this.batchDirty++;
  30904. this.uvsFloat32 = new Float32Array(this.uvs);
  30905. var batches = this.batches;
  30906. for (var i = 0, l = batches.length; i < l; i++) {
  30907. var batch = batches[i];
  30908. for (var j = 0; j < batch.size; j++) {
  30909. var index = batch.start + j;
  30910. this.indicesUint16[index] = this.indicesUint16[index] - batch.attribStart;
  30911. }
  30912. }
  30913. };
  30914. /**
  30915. * Checks to see if this graphics geometry can be batched.
  30916. * Currently it needs to be small enough and not contain any native lines.
  30917. *
  30918. * @protected
  30919. */
  30920. GraphicsGeometry.prototype.isBatchable = function () {
  30921. // prevent heavy mesh batching
  30922. if (this.points.length > 0xffff * 2) {
  30923. return false;
  30924. }
  30925. var batches = this.batches;
  30926. for (var i = 0; i < batches.length; i++) {
  30927. if (batches[i].style.native) {
  30928. return false;
  30929. }
  30930. }
  30931. return (this.points.length < GraphicsGeometry.BATCHABLE_SIZE * 2);
  30932. };
  30933. /**
  30934. * Converts intermediate batches data to drawCalls.
  30935. *
  30936. * @protected
  30937. */
  30938. GraphicsGeometry.prototype.buildDrawCalls = function () {
  30939. var TICK = ++BaseTexture._globalBatch;
  30940. for (var i = 0; i < this.drawCalls.length; i++) {
  30941. this.drawCalls[i].texArray.clear();
  30942. DRAW_CALL_POOL.push(this.drawCalls[i]);
  30943. }
  30944. this.drawCalls.length = 0;
  30945. var colors = this.colors;
  30946. var textureIds = this.textureIds;
  30947. var currentGroup = DRAW_CALL_POOL.pop();
  30948. if (!currentGroup) {
  30949. currentGroup = new BatchDrawCall();
  30950. currentGroup.texArray = new BatchTextureArray();
  30951. }
  30952. currentGroup.texArray.count = 0;
  30953. currentGroup.start = 0;
  30954. currentGroup.size = 0;
  30955. currentGroup.type = exports.DRAW_MODES.TRIANGLES;
  30956. var textureCount = 0;
  30957. var currentTexture = null;
  30958. var textureId = 0;
  30959. var native = false;
  30960. var drawMode = exports.DRAW_MODES.TRIANGLES;
  30961. var index = 0;
  30962. this.drawCalls.push(currentGroup);
  30963. // TODO - this can be simplified
  30964. for (var i = 0; i < this.batches.length; i++) {
  30965. var data = this.batches[i];
  30966. // TODO add some full on MAX_TEXTURE CODE..
  30967. var MAX_TEXTURES = 8;
  30968. // Forced cast for checking `native` without errors
  30969. var style = data.style;
  30970. var nextTexture = style.texture.baseTexture;
  30971. if (native !== !!style.native) {
  30972. native = !!style.native;
  30973. drawMode = native ? exports.DRAW_MODES.LINES : exports.DRAW_MODES.TRIANGLES;
  30974. // force the batch to break!
  30975. currentTexture = null;
  30976. textureCount = MAX_TEXTURES;
  30977. TICK++;
  30978. }
  30979. if (currentTexture !== nextTexture) {
  30980. currentTexture = nextTexture;
  30981. if (nextTexture._batchEnabled !== TICK) {
  30982. if (textureCount === MAX_TEXTURES) {
  30983. TICK++;
  30984. textureCount = 0;
  30985. if (currentGroup.size > 0) {
  30986. currentGroup = DRAW_CALL_POOL.pop();
  30987. if (!currentGroup) {
  30988. currentGroup = new BatchDrawCall();
  30989. currentGroup.texArray = new BatchTextureArray();
  30990. }
  30991. this.drawCalls.push(currentGroup);
  30992. }
  30993. currentGroup.start = index;
  30994. currentGroup.size = 0;
  30995. currentGroup.texArray.count = 0;
  30996. currentGroup.type = drawMode;
  30997. }
  30998. // TODO add this to the render part..
  30999. // Hack! Because texture has protected `touched`
  31000. nextTexture.touched = 1; // touch;
  31001. nextTexture._batchEnabled = TICK;
  31002. nextTexture._batchLocation = textureCount;
  31003. nextTexture.wrapMode = exports.WRAP_MODES.REPEAT;
  31004. currentGroup.texArray.elements[currentGroup.texArray.count++] = nextTexture;
  31005. textureCount++;
  31006. }
  31007. }
  31008. currentGroup.size += data.size;
  31009. index += data.size;
  31010. textureId = nextTexture._batchLocation;
  31011. this.addColors(colors, style.color, style.alpha, data.attribSize, data.attribStart);
  31012. this.addTextureIds(textureIds, textureId, data.attribSize, data.attribStart);
  31013. }
  31014. BaseTexture._globalBatch = TICK;
  31015. // upload..
  31016. // merge for now!
  31017. this.packAttributes();
  31018. };
  31019. /**
  31020. * Packs attributes to single buffer.
  31021. *
  31022. * @protected
  31023. */
  31024. GraphicsGeometry.prototype.packAttributes = function () {
  31025. var verts = this.points;
  31026. var uvs = this.uvs;
  31027. var colors = this.colors;
  31028. var textureIds = this.textureIds;
  31029. // verts are 2 positions.. so we * by 3 as there are 6 properties.. then 4 cos its bytes
  31030. var glPoints = new ArrayBuffer(verts.length * 3 * 4);
  31031. var f32 = new Float32Array(glPoints);
  31032. var u32 = new Uint32Array(glPoints);
  31033. var p = 0;
  31034. for (var i = 0; i < verts.length / 2; i++) {
  31035. f32[p++] = verts[i * 2];
  31036. f32[p++] = verts[(i * 2) + 1];
  31037. f32[p++] = uvs[i * 2];
  31038. f32[p++] = uvs[(i * 2) + 1];
  31039. u32[p++] = colors[i];
  31040. f32[p++] = textureIds[i];
  31041. }
  31042. this._buffer.update(glPoints);
  31043. this._indexBuffer.update(this.indicesUint16);
  31044. };
  31045. /**
  31046. * Process fill part of Graphics.
  31047. *
  31048. * @param {PIXI.GraphicsData} data
  31049. * @protected
  31050. */
  31051. GraphicsGeometry.prototype.processFill = function (data) {
  31052. if (data.holes.length) {
  31053. this.processHoles(data.holes);
  31054. buildPoly.triangulate(data, this);
  31055. }
  31056. else {
  31057. var command = FILL_COMMANDS[data.type];
  31058. command.triangulate(data, this);
  31059. }
  31060. };
  31061. /**
  31062. * Process line part of Graphics.
  31063. *
  31064. * @param {PIXI.GraphicsData} data
  31065. * @protected
  31066. */
  31067. GraphicsGeometry.prototype.processLine = function (data) {
  31068. buildLine(data, this);
  31069. for (var i = 0; i < data.holes.length; i++) {
  31070. buildLine(data.holes[i], this);
  31071. }
  31072. };
  31073. /**
  31074. * Process the holes data.
  31075. *
  31076. * @param {PIXI.GraphicsData[]} holes - Holes to render
  31077. * @protected
  31078. */
  31079. GraphicsGeometry.prototype.processHoles = function (holes) {
  31080. for (var i = 0; i < holes.length; i++) {
  31081. var hole = holes[i];
  31082. var command = FILL_COMMANDS[hole.type];
  31083. command.build(hole);
  31084. if (hole.matrix) {
  31085. this.transformPoints(hole.points, hole.matrix);
  31086. }
  31087. }
  31088. };
  31089. /**
  31090. * Update the local bounds of the object. Expensive to use performance-wise.
  31091. *
  31092. * @protected
  31093. */
  31094. GraphicsGeometry.prototype.calculateBounds = function () {
  31095. var bounds = this._bounds;
  31096. var sequenceBounds = tmpBounds;
  31097. var curMatrix = Matrix.IDENTITY;
  31098. this._bounds.clear();
  31099. sequenceBounds.clear();
  31100. for (var i = 0; i < this.graphicsData.length; i++) {
  31101. var data = this.graphicsData[i];
  31102. var shape = data.shape;
  31103. var type = data.type;
  31104. var lineStyle = data.lineStyle;
  31105. var nextMatrix = data.matrix || Matrix.IDENTITY;
  31106. var lineWidth = 0.0;
  31107. if (lineStyle && lineStyle.visible) {
  31108. var alignment = lineStyle.alignment;
  31109. lineWidth = lineStyle.width;
  31110. if (type === exports.SHAPES.POLY) {
  31111. if (isPolygonClockwise(shape)) {
  31112. lineWidth = lineWidth * (1 - alignment);
  31113. }
  31114. else {
  31115. lineWidth = lineWidth * alignment;
  31116. }
  31117. }
  31118. else {
  31119. lineWidth = lineWidth * Math.max(0, alignment);
  31120. }
  31121. }
  31122. if (curMatrix !== nextMatrix) {
  31123. if (!sequenceBounds.isEmpty()) {
  31124. bounds.addBoundsMatrix(sequenceBounds, curMatrix);
  31125. sequenceBounds.clear();
  31126. }
  31127. curMatrix = nextMatrix;
  31128. }
  31129. if (type === exports.SHAPES.RECT || type === exports.SHAPES.RREC) {
  31130. var rect = shape;
  31131. sequenceBounds.addFramePad(rect.x, rect.y, rect.x + rect.width, rect.y + rect.height, lineWidth, lineWidth);
  31132. }
  31133. else if (type === exports.SHAPES.CIRC) {
  31134. var circle = shape;
  31135. sequenceBounds.addFramePad(circle.x, circle.y, circle.x, circle.y, circle.radius + lineWidth, circle.radius + lineWidth);
  31136. }
  31137. else if (type === exports.SHAPES.ELIP) {
  31138. var ellipse = shape;
  31139. sequenceBounds.addFramePad(ellipse.x, ellipse.y, ellipse.x, ellipse.y, ellipse.width + lineWidth, ellipse.height + lineWidth);
  31140. }
  31141. else {
  31142. var poly = shape;
  31143. // adding directly to the bounds
  31144. bounds.addVerticesMatrix(curMatrix, poly.points, 0, poly.points.length, lineWidth, lineWidth);
  31145. }
  31146. }
  31147. if (!sequenceBounds.isEmpty()) {
  31148. bounds.addBoundsMatrix(sequenceBounds, curMatrix);
  31149. }
  31150. bounds.pad(this.boundsPadding, this.boundsPadding);
  31151. };
  31152. /**
  31153. * Transform points using matrix.
  31154. *
  31155. * @protected
  31156. * @param {number[]} points - Points to transform
  31157. * @param {PIXI.Matrix} matrix - Transform matrix
  31158. */
  31159. GraphicsGeometry.prototype.transformPoints = function (points, matrix) {
  31160. for (var i = 0; i < points.length / 2; i++) {
  31161. var x = points[(i * 2)];
  31162. var y = points[(i * 2) + 1];
  31163. points[(i * 2)] = (matrix.a * x) + (matrix.c * y) + matrix.tx;
  31164. points[(i * 2) + 1] = (matrix.b * x) + (matrix.d * y) + matrix.ty;
  31165. }
  31166. };
  31167. /**
  31168. * Add colors.
  31169. *
  31170. * @protected
  31171. * @param {number[]} colors - List of colors to add to
  31172. * @param {number} color - Color to add
  31173. * @param {number} alpha - Alpha to use
  31174. * @param {number} size - Number of colors to add
  31175. * @param {number} offset
  31176. */
  31177. GraphicsGeometry.prototype.addColors = function (colors, color, alpha, size, offset) {
  31178. if (offset === void 0) { offset = 0; }
  31179. // TODO use the premultiply bits Ivan added
  31180. var rgb = (color >> 16) + (color & 0xff00) + ((color & 0xff) << 16);
  31181. var rgba = premultiplyTint(rgb, alpha);
  31182. colors.length = Math.max(colors.length, offset + size);
  31183. for (var i = 0; i < size; i++) {
  31184. colors[offset + i] = rgba;
  31185. }
  31186. };
  31187. /**
  31188. * Add texture id that the shader/fragment wants to use.
  31189. *
  31190. * @protected
  31191. * @param {number[]} textureIds
  31192. * @param {number} id
  31193. * @param {number} size
  31194. * @param {number} offset
  31195. */
  31196. GraphicsGeometry.prototype.addTextureIds = function (textureIds, id, size, offset) {
  31197. if (offset === void 0) { offset = 0; }
  31198. textureIds.length = Math.max(textureIds.length, offset + size);
  31199. for (var i = 0; i < size; i++) {
  31200. textureIds[offset + i] = id;
  31201. }
  31202. };
  31203. /**
  31204. * Generates the UVs for a shape.
  31205. *
  31206. * @protected
  31207. * @param {number[]} verts - Vertices
  31208. * @param {number[]} uvs - UVs
  31209. * @param {PIXI.Texture} texture - Reference to Texture
  31210. * @param {number} start - Index buffer start index.
  31211. * @param {number} size - The size/length for index buffer.
  31212. * @param {PIXI.Matrix} [matrix] - Optional transform for all points.
  31213. */
  31214. GraphicsGeometry.prototype.addUvs = function (verts, uvs, texture, start, size, matrix) {
  31215. if (matrix === void 0) { matrix = null; }
  31216. var index = 0;
  31217. var uvsStart = uvs.length;
  31218. var frame = texture.frame;
  31219. while (index < size) {
  31220. var x = verts[(start + index) * 2];
  31221. var y = verts[((start + index) * 2) + 1];
  31222. if (matrix) {
  31223. var nx = (matrix.a * x) + (matrix.c * y) + matrix.tx;
  31224. y = (matrix.b * x) + (matrix.d * y) + matrix.ty;
  31225. x = nx;
  31226. }
  31227. index++;
  31228. uvs.push(x / frame.width, y / frame.height);
  31229. }
  31230. var baseTexture = texture.baseTexture;
  31231. if (frame.width < baseTexture.width
  31232. || frame.height < baseTexture.height) {
  31233. this.adjustUvs(uvs, texture, uvsStart, size);
  31234. }
  31235. };
  31236. /**
  31237. * Modify uvs array according to position of texture region
  31238. * Does not work with rotated or trimmed textures
  31239. *
  31240. * @param {number[]} uvs - array
  31241. * @param {PIXI.Texture} texture - region
  31242. * @param {number} start - starting index for uvs
  31243. * @param {number} size - how many points to adjust
  31244. */
  31245. GraphicsGeometry.prototype.adjustUvs = function (uvs, texture, start, size) {
  31246. var baseTexture = texture.baseTexture;
  31247. var eps = 1e-6;
  31248. var finish = start + (size * 2);
  31249. var frame = texture.frame;
  31250. var scaleX = frame.width / baseTexture.width;
  31251. var scaleY = frame.height / baseTexture.height;
  31252. var offsetX = frame.x / frame.width;
  31253. var offsetY = frame.y / frame.height;
  31254. var minX = Math.floor(uvs[start] + eps);
  31255. var minY = Math.floor(uvs[start + 1] + eps);
  31256. for (var i = start + 2; i < finish; i += 2) {
  31257. minX = Math.min(minX, Math.floor(uvs[i] + eps));
  31258. minY = Math.min(minY, Math.floor(uvs[i + 1] + eps));
  31259. }
  31260. offsetX -= minX;
  31261. offsetY -= minY;
  31262. for (var i = start; i < finish; i += 2) {
  31263. uvs[i] = (uvs[i] + offsetX) * scaleX;
  31264. uvs[i + 1] = (uvs[i + 1] + offsetY) * scaleY;
  31265. }
  31266. };
  31267. /**
  31268. * The maximum number of points to consider an object "batchable",
  31269. * able to be batched by the renderer's batch system.
  31270. \ */
  31271. GraphicsGeometry.BATCHABLE_SIZE = 100;
  31272. return GraphicsGeometry;
  31273. }(BatchGeometry));
  31274. /**
  31275. * Represents the line style for Graphics.
  31276. * @memberof PIXI
  31277. * @class
  31278. * @extends PIXI.FillStyle
  31279. */
  31280. var LineStyle = /** @class */ (function (_super) {
  31281. __extends$5(LineStyle, _super);
  31282. function LineStyle() {
  31283. var _this = _super !== null && _super.apply(this, arguments) || this;
  31284. /** The width (thickness) of any lines drawn. */
  31285. _this.width = 0;
  31286. /** The alignment of any lines drawn (0.5 = middle, 1 = outer, 0 = inner). WebGL only. */
  31287. _this.alignment = 0.5;
  31288. /** If true the lines will be draw using LINES instead of TRIANGLE_STRIP */
  31289. _this.native = false;
  31290. /**
  31291. * Line cap style.
  31292. *
  31293. * @member {PIXI.LINE_CAP}
  31294. * @default PIXI.LINE_CAP.BUTT
  31295. */
  31296. _this.cap = exports.LINE_CAP.BUTT;
  31297. /**
  31298. * Line join style.
  31299. *
  31300. * @member {PIXI.LINE_JOIN}
  31301. * @default PIXI.LINE_JOIN.MITER
  31302. */
  31303. _this.join = exports.LINE_JOIN.MITER;
  31304. /** Miter limit. */
  31305. _this.miterLimit = 10;
  31306. return _this;
  31307. }
  31308. /**
  31309. * Clones the object
  31310. *
  31311. * @return {PIXI.LineStyle}
  31312. */
  31313. LineStyle.prototype.clone = function () {
  31314. var obj = new LineStyle();
  31315. obj.color = this.color;
  31316. obj.alpha = this.alpha;
  31317. obj.texture = this.texture;
  31318. obj.matrix = this.matrix;
  31319. obj.visible = this.visible;
  31320. obj.width = this.width;
  31321. obj.alignment = this.alignment;
  31322. obj.native = this.native;
  31323. obj.cap = this.cap;
  31324. obj.join = this.join;
  31325. obj.miterLimit = this.miterLimit;
  31326. return obj;
  31327. };
  31328. /**
  31329. * Reset the line style to default.
  31330. */
  31331. LineStyle.prototype.reset = function () {
  31332. _super.prototype.reset.call(this);
  31333. // Override default line style color
  31334. this.color = 0x0;
  31335. this.alignment = 0.5;
  31336. this.width = 0;
  31337. this.native = false;
  31338. };
  31339. return LineStyle;
  31340. }(FillStyle));
  31341. var temp = new Float32Array(3);
  31342. // a default shaders map used by graphics..
  31343. var DEFAULT_SHADERS = {};
  31344. /**
  31345. * The Graphics class is primarily used to render primitive shapes such as lines, circles and
  31346. * rectangles to the display, and to color and fill them. However, you can also use a Graphics
  31347. * object to build a list of primitives to use as a mask, or as a complex hitArea.
  31348. *
  31349. * Please note that due to legacy naming conventions, the behavior of some functions in this class
  31350. * can be confusing. Each call to `drawRect()`, `drawPolygon()`, etc. actually stores that primitive
  31351. * in the Geometry class's GraphicsGeometry object for later use in rendering or hit testing - the
  31352. * functions do not directly draw anything to the screen. Similarly, the `clear()` function doesn't
  31353. * change the screen, it simply resets the list of primitives, which can be useful if you want to
  31354. * rebuild the contents of an existing Graphics object.
  31355. *
  31356. * Once a GraphicsGeometry list is built, you can re-use it in other Geometry objects as
  31357. * an optimization, by passing it into a new Geometry object's constructor. Because of this
  31358. * ability, it's important to call `destroy()` on Geometry objects once you are done with them, to
  31359. * properly dereference each GraphicsGeometry and prevent memory leaks.
  31360. *
  31361. * @class
  31362. * @extends PIXI.Container
  31363. * @memberof PIXI
  31364. */
  31365. var Graphics = /** @class */ (function (_super) {
  31366. __extends$5(Graphics, _super);
  31367. /**
  31368. * @param {PIXI.GraphicsGeometry} [geometry=null] - Geometry to use, if omitted
  31369. * will create a new GraphicsGeometry instance.
  31370. */
  31371. function Graphics(geometry) {
  31372. if (geometry === void 0) { geometry = null; }
  31373. var _this = _super.call(this) || this;
  31374. /**
  31375. * Represents the vertex and fragment shaders that processes the geometry and runs on the GPU.
  31376. * Can be shared between multiple Graphics objects.
  31377. *
  31378. * @member {PIXI.Shader}
  31379. */
  31380. _this.shader = null;
  31381. /** Renderer plugin for batching */
  31382. _this.pluginName = 'batch';
  31383. /**
  31384. * Current path
  31385. *
  31386. * @member {PIXI.Polygon}
  31387. * @readonly
  31388. */
  31389. _this.currentPath = null;
  31390. /**
  31391. * A collections of batches! These can be drawn by the renderer batch system.
  31392. *
  31393. * @member {PIXI.IGraphicsBatchElement[]}
  31394. */
  31395. _this.batches = [];
  31396. /** Update dirty for limiting calculating tints for batches. */
  31397. _this.batchTint = -1;
  31398. /** Update dirty for limiting calculating batches.*/
  31399. _this.batchDirty = -1;
  31400. /** Copy of the object vertex data. */
  31401. _this.vertexData = null;
  31402. /**
  31403. * Current fill style
  31404. *
  31405. * @member {PIXI.FillStyle}
  31406. */
  31407. _this._fillStyle = new FillStyle();
  31408. /**
  31409. * Current line style
  31410. *
  31411. * @member {PIXI.LineStyle}
  31412. */
  31413. _this._lineStyle = new LineStyle();
  31414. /**
  31415. * Current shape transform matrix.
  31416. *
  31417. * @member {PIXI.Matrix}
  31418. */
  31419. _this._matrix = null;
  31420. /** Current hole mode is enabled. */
  31421. _this._holeMode = false;
  31422. /**
  31423. * Represents the WebGL state the Graphics required to render, excludes shader and geometry. E.g.,
  31424. * blend mode, culling, depth testing, direction of rendering triangles, backface, etc.
  31425. *
  31426. * @member {PIXI.State}
  31427. */
  31428. _this.state = State.for2d();
  31429. _this._geometry = geometry || new GraphicsGeometry();
  31430. _this._geometry.refCount++;
  31431. /**
  31432. * When cacheAsBitmap is set to true the graphics object will be rendered as if it was a sprite.
  31433. * This is useful if your graphics element does not change often, as it will speed up the rendering
  31434. * of the object in exchange for taking up texture memory. It is also useful if you need the graphics
  31435. * object to be anti-aliased, because it will be rendered using canvas. This is not recommended if
  31436. * you are constantly redrawing the graphics element.
  31437. *
  31438. * @name cacheAsBitmap
  31439. * @member {boolean}
  31440. * @memberof PIXI.Graphics#
  31441. * @default false
  31442. */
  31443. _this._transformID = -1;
  31444. // Set default
  31445. _this.tint = 0xFFFFFF;
  31446. _this.blendMode = exports.BLEND_MODES.NORMAL;
  31447. return _this;
  31448. }
  31449. Object.defineProperty(Graphics.prototype, "geometry", {
  31450. /**
  31451. * Includes vertex positions, face indices, normals, colors, UVs, and
  31452. * custom attributes within buffers, reducing the cost of passing all
  31453. * this data to the GPU. Can be shared between multiple Mesh or Graphics objects.
  31454. *
  31455. * @member {PIXI.GraphicsGeometry}
  31456. * @readonly
  31457. */
  31458. get: function () {
  31459. return this._geometry;
  31460. },
  31461. enumerable: false,
  31462. configurable: true
  31463. });
  31464. /**
  31465. * Creates a new Graphics object with the same values as this one.
  31466. * Note that only the geometry of the object is cloned, not its transform (position,scale,etc)
  31467. *
  31468. * @return {PIXI.Graphics} A clone of the graphics object
  31469. */
  31470. Graphics.prototype.clone = function () {
  31471. this.finishPoly();
  31472. return new Graphics(this._geometry);
  31473. };
  31474. Object.defineProperty(Graphics.prototype, "blendMode", {
  31475. get: function () {
  31476. return this.state.blendMode;
  31477. },
  31478. /**
  31479. * The blend mode to be applied to the graphic shape. Apply a value of
  31480. * `PIXI.BLEND_MODES.NORMAL` to reset the blend mode. Note that, since each
  31481. * primitive in the GraphicsGeometry list is rendered sequentially, modes
  31482. * such as `PIXI.BLEND_MODES.ADD` and `PIXI.BLEND_MODES.MULTIPLY` will
  31483. * be applied per-primitive.
  31484. *
  31485. * @member {number}
  31486. * @default PIXI.BLEND_MODES.NORMAL;
  31487. * @see PIXI.BLEND_MODES
  31488. */
  31489. set: function (value) {
  31490. this.state.blendMode = value;
  31491. },
  31492. enumerable: false,
  31493. configurable: true
  31494. });
  31495. Object.defineProperty(Graphics.prototype, "tint", {
  31496. /**
  31497. * The tint applied to each graphic shape. This is a hex value. A value of
  31498. * 0xFFFFFF will remove any tint effect.
  31499. *
  31500. * @member {number}
  31501. * @default 0xFFFFFF
  31502. */
  31503. get: function () {
  31504. return this._tint;
  31505. },
  31506. set: function (value) {
  31507. this._tint = value;
  31508. },
  31509. enumerable: false,
  31510. configurable: true
  31511. });
  31512. Object.defineProperty(Graphics.prototype, "fill", {
  31513. /**
  31514. * The current fill style.
  31515. *
  31516. * @member {PIXI.FillStyle}
  31517. * @readonly
  31518. */
  31519. get: function () {
  31520. return this._fillStyle;
  31521. },
  31522. enumerable: false,
  31523. configurable: true
  31524. });
  31525. Object.defineProperty(Graphics.prototype, "line", {
  31526. /**
  31527. * The current line style.
  31528. *
  31529. * @member {PIXI.LineStyle}
  31530. * @readonly
  31531. */
  31532. get: function () {
  31533. return this._lineStyle;
  31534. },
  31535. enumerable: false,
  31536. configurable: true
  31537. });
  31538. Graphics.prototype.lineStyle = function (options, color, alpha, alignment, native) {
  31539. if (options === void 0) { options = null; }
  31540. if (color === void 0) { color = 0x0; }
  31541. if (alpha === void 0) { alpha = 1; }
  31542. if (alignment === void 0) { alignment = 0.5; }
  31543. if (native === void 0) { native = false; }
  31544. // Support non-object params: (width, color, alpha, alignment, native)
  31545. if (typeof options === 'number') {
  31546. options = { width: options, color: color, alpha: alpha, alignment: alignment, native: native };
  31547. }
  31548. return this.lineTextureStyle(options);
  31549. };
  31550. /**
  31551. * Like line style but support texture for line fill.
  31552. *
  31553. * @param {object} [options] - Collection of options for setting line style.
  31554. * @param {number} [options.width=0] - width of the line to draw, will update the objects stored style
  31555. * @param {PIXI.Texture} [options.texture=PIXI.Texture.WHITE] - Texture to use
  31556. * @param {number} [options.color=0x0] - color of the line to draw, will update the objects stored style.
  31557. * Default 0xFFFFFF if texture present.
  31558. * @param {number} [options.alpha=1] - alpha of the line to draw, will update the objects stored style
  31559. * @param {PIXI.Matrix} [options.matrix=null] - Texture matrix to transform texture
  31560. * @param {number} [options.alignment=0.5] - alignment of the line to draw, (0 = inner, 0.5 = middle, 1 = outer).
  31561. * WebGL only.
  31562. * @param {boolean} [options.native=false] - If true the lines will be draw using LINES instead of TRIANGLE_STRIP
  31563. * @param {PIXI.LINE_CAP}[options.cap=PIXI.LINE_CAP.BUTT] - line cap style
  31564. * @param {PIXI.LINE_JOIN}[options.join=PIXI.LINE_JOIN.MITER] - line join style
  31565. * @param {number}[options.miterLimit=10] - miter limit ratio
  31566. * @return {PIXI.Graphics} This Graphics object. Good for chaining method calls
  31567. */
  31568. Graphics.prototype.lineTextureStyle = function (options) {
  31569. // Apply defaults
  31570. options = Object.assign({
  31571. width: 0,
  31572. texture: Texture.WHITE,
  31573. color: (options && options.texture) ? 0xFFFFFF : 0x0,
  31574. alpha: 1,
  31575. matrix: null,
  31576. alignment: 0.5,
  31577. native: false,
  31578. cap: exports.LINE_CAP.BUTT,
  31579. join: exports.LINE_JOIN.MITER,
  31580. miterLimit: 10,
  31581. }, options);
  31582. if (this.currentPath) {
  31583. this.startPoly();
  31584. }
  31585. var visible = options.width > 0 && options.alpha > 0;
  31586. if (!visible) {
  31587. this._lineStyle.reset();
  31588. }
  31589. else {
  31590. if (options.matrix) {
  31591. options.matrix = options.matrix.clone();
  31592. options.matrix.invert();
  31593. }
  31594. Object.assign(this._lineStyle, { visible: visible }, options);
  31595. }
  31596. return this;
  31597. };
  31598. /**
  31599. * Start a polygon object internally
  31600. * @protected
  31601. */
  31602. Graphics.prototype.startPoly = function () {
  31603. if (this.currentPath) {
  31604. var points = this.currentPath.points;
  31605. var len = this.currentPath.points.length;
  31606. if (len > 2) {
  31607. this.drawShape(this.currentPath);
  31608. this.currentPath = new Polygon();
  31609. this.currentPath.closeStroke = false;
  31610. this.currentPath.points.push(points[len - 2], points[len - 1]);
  31611. }
  31612. }
  31613. else {
  31614. this.currentPath = new Polygon();
  31615. this.currentPath.closeStroke = false;
  31616. }
  31617. };
  31618. /**
  31619. * Finish the polygon object.
  31620. * @protected
  31621. */
  31622. Graphics.prototype.finishPoly = function () {
  31623. if (this.currentPath) {
  31624. if (this.currentPath.points.length > 2) {
  31625. this.drawShape(this.currentPath);
  31626. this.currentPath = null;
  31627. }
  31628. else {
  31629. this.currentPath.points.length = 0;
  31630. }
  31631. }
  31632. };
  31633. /**
  31634. * Moves the current drawing position to x, y.
  31635. *
  31636. * @param {number} x - the X coordinate to move to
  31637. * @param {number} y - the Y coordinate to move to
  31638. * @return {PIXI.Graphics} This Graphics object. Good for chaining method calls
  31639. */
  31640. Graphics.prototype.moveTo = function (x, y) {
  31641. this.startPoly();
  31642. this.currentPath.points[0] = x;
  31643. this.currentPath.points[1] = y;
  31644. return this;
  31645. };
  31646. /**
  31647. * Draws a line using the current line style from the current drawing position to (x, y);
  31648. * The current drawing position is then set to (x, y).
  31649. *
  31650. * @param {number} x - the X coordinate to draw to
  31651. * @param {number} y - the Y coordinate to draw to
  31652. * @return {PIXI.Graphics} This Graphics object. Good for chaining method calls
  31653. */
  31654. Graphics.prototype.lineTo = function (x, y) {
  31655. if (!this.currentPath) {
  31656. this.moveTo(0, 0);
  31657. }
  31658. // remove duplicates..
  31659. var points = this.currentPath.points;
  31660. var fromX = points[points.length - 2];
  31661. var fromY = points[points.length - 1];
  31662. if (fromX !== x || fromY !== y) {
  31663. points.push(x, y);
  31664. }
  31665. return this;
  31666. };
  31667. /**
  31668. * Initialize the curve
  31669. *
  31670. * @param {number} [x=0]
  31671. * @param {number} [y=0]
  31672. */
  31673. Graphics.prototype._initCurve = function (x, y) {
  31674. if (x === void 0) { x = 0; }
  31675. if (y === void 0) { y = 0; }
  31676. if (this.currentPath) {
  31677. if (this.currentPath.points.length === 0) {
  31678. this.currentPath.points = [x, y];
  31679. }
  31680. }
  31681. else {
  31682. this.moveTo(x, y);
  31683. }
  31684. };
  31685. /**
  31686. * Calculate the points for a quadratic bezier curve and then draws it.
  31687. * Based on: https://stackoverflow.com/questions/785097/how-do-i-implement-a-bezier-curve-in-c
  31688. *
  31689. * @param {number} cpX - Control point x
  31690. * @param {number} cpY - Control point y
  31691. * @param {number} toX - Destination point x
  31692. * @param {number} toY - Destination point y
  31693. * @return {PIXI.Graphics} This Graphics object. Good for chaining method calls
  31694. */
  31695. Graphics.prototype.quadraticCurveTo = function (cpX, cpY, toX, toY) {
  31696. this._initCurve();
  31697. var points = this.currentPath.points;
  31698. if (points.length === 0) {
  31699. this.moveTo(0, 0);
  31700. }
  31701. QuadraticUtils.curveTo(cpX, cpY, toX, toY, points);
  31702. return this;
  31703. };
  31704. /**
  31705. * Calculate the points for a bezier curve and then draws it.
  31706. *
  31707. * @param {number} cpX - Control point x
  31708. * @param {number} cpY - Control point y
  31709. * @param {number} cpX2 - Second Control point x
  31710. * @param {number} cpY2 - Second Control point y
  31711. * @param {number} toX - Destination point x
  31712. * @param {number} toY - Destination point y
  31713. * @return {PIXI.Graphics} This Graphics object. Good for chaining method calls
  31714. */
  31715. Graphics.prototype.bezierCurveTo = function (cpX, cpY, cpX2, cpY2, toX, toY) {
  31716. this._initCurve();
  31717. BezierUtils.curveTo(cpX, cpY, cpX2, cpY2, toX, toY, this.currentPath.points);
  31718. return this;
  31719. };
  31720. /**
  31721. * The arcTo() method creates an arc/curve between two tangents on the canvas.
  31722. *
  31723. * "borrowed" from https://code.google.com/p/fxcanvas/ - thanks google!
  31724. *
  31725. * @param {number} x1 - The x-coordinate of the first tangent point of the arc
  31726. * @param {number} y1 - The y-coordinate of the first tangent point of the arc
  31727. * @param {number} x2 - The x-coordinate of the end of the arc
  31728. * @param {number} y2 - The y-coordinate of the end of the arc
  31729. * @param {number} radius - The radius of the arc
  31730. * @return {PIXI.Graphics} This Graphics object. Good for chaining method calls
  31731. */
  31732. Graphics.prototype.arcTo = function (x1, y1, x2, y2, radius) {
  31733. this._initCurve(x1, y1);
  31734. var points = this.currentPath.points;
  31735. var result = ArcUtils.curveTo(x1, y1, x2, y2, radius, points);
  31736. if (result) {
  31737. var cx = result.cx, cy = result.cy, radius_1 = result.radius, startAngle = result.startAngle, endAngle = result.endAngle, anticlockwise = result.anticlockwise;
  31738. this.arc(cx, cy, radius_1, startAngle, endAngle, anticlockwise);
  31739. }
  31740. return this;
  31741. };
  31742. /**
  31743. * The arc method creates an arc/curve (used to create circles, or parts of circles).
  31744. *
  31745. * @param {number} cx - The x-coordinate of the center of the circle
  31746. * @param {number} cy - The y-coordinate of the center of the circle
  31747. * @param {number} radius - The radius of the circle
  31748. * @param {number} startAngle - The starting angle, in radians (0 is at the 3 o'clock position
  31749. * of the arc's circle)
  31750. * @param {number} endAngle - The ending angle, in radians
  31751. * @param {boolean} [anticlockwise=false] - Specifies whether the drawing should be
  31752. * counter-clockwise or clockwise. False is default, and indicates clockwise, while true
  31753. * indicates counter-clockwise.
  31754. * @return {PIXI.Graphics} This Graphics object. Good for chaining method calls
  31755. */
  31756. Graphics.prototype.arc = function (cx, cy, radius, startAngle, endAngle, anticlockwise) {
  31757. if (anticlockwise === void 0) { anticlockwise = false; }
  31758. if (startAngle === endAngle) {
  31759. return this;
  31760. }
  31761. if (!anticlockwise && endAngle <= startAngle) {
  31762. endAngle += PI_2;
  31763. }
  31764. else if (anticlockwise && startAngle <= endAngle) {
  31765. startAngle += PI_2;
  31766. }
  31767. var sweep = endAngle - startAngle;
  31768. if (sweep === 0) {
  31769. return this;
  31770. }
  31771. var startX = cx + (Math.cos(startAngle) * radius);
  31772. var startY = cy + (Math.sin(startAngle) * radius);
  31773. var eps = this._geometry.closePointEps;
  31774. // If the currentPath exists, take its points. Otherwise call `moveTo` to start a path.
  31775. var points = this.currentPath ? this.currentPath.points : null;
  31776. if (points) {
  31777. // TODO: make a better fix.
  31778. // We check how far our start is from the last existing point
  31779. var xDiff = Math.abs(points[points.length - 2] - startX);
  31780. var yDiff = Math.abs(points[points.length - 1] - startY);
  31781. if (xDiff < eps && yDiff < eps) { ; }
  31782. else {
  31783. points.push(startX, startY);
  31784. }
  31785. }
  31786. else {
  31787. this.moveTo(startX, startY);
  31788. points = this.currentPath.points;
  31789. }
  31790. ArcUtils.arc(startX, startY, cx, cy, radius, startAngle, endAngle, anticlockwise, points);
  31791. return this;
  31792. };
  31793. /**
  31794. * Specifies a simple one-color fill that subsequent calls to other Graphics methods
  31795. * (such as lineTo() or drawCircle()) use when drawing.
  31796. *
  31797. * @param {number} [color=0] - the color of the fill
  31798. * @param {number} [alpha=1] - the alpha of the fill
  31799. * @return {PIXI.Graphics} This Graphics object. Good for chaining method calls
  31800. */
  31801. Graphics.prototype.beginFill = function (color, alpha) {
  31802. if (color === void 0) { color = 0; }
  31803. if (alpha === void 0) { alpha = 1; }
  31804. return this.beginTextureFill({ texture: Texture.WHITE, color: color, alpha: alpha });
  31805. };
  31806. /**
  31807. * Begin the texture fill
  31808. *
  31809. * @param {object} [options] - Object object.
  31810. * @param {PIXI.Texture} [options.texture=PIXI.Texture.WHITE] - Texture to fill
  31811. * @param {number} [options.color=0xffffff] - Background to fill behind texture
  31812. * @param {number} [options.alpha=1] - Alpha of fill
  31813. * @param {PIXI.Matrix} [options.matrix=null] - Transform matrix
  31814. * @return {PIXI.Graphics} This Graphics object. Good for chaining method calls
  31815. */
  31816. Graphics.prototype.beginTextureFill = function (options) {
  31817. // Apply defaults
  31818. options = Object.assign({
  31819. texture: Texture.WHITE,
  31820. color: 0xFFFFFF,
  31821. alpha: 1,
  31822. matrix: null,
  31823. }, options);
  31824. if (this.currentPath) {
  31825. this.startPoly();
  31826. }
  31827. var visible = options.alpha > 0;
  31828. if (!visible) {
  31829. this._fillStyle.reset();
  31830. }
  31831. else {
  31832. if (options.matrix) {
  31833. options.matrix = options.matrix.clone();
  31834. options.matrix.invert();
  31835. }
  31836. Object.assign(this._fillStyle, { visible: visible }, options);
  31837. }
  31838. return this;
  31839. };
  31840. /**
  31841. * Applies a fill to the lines and shapes that were added since the last call to the beginFill() method.
  31842. *
  31843. * @return {PIXI.Graphics} This Graphics object. Good for chaining method calls
  31844. */
  31845. Graphics.prototype.endFill = function () {
  31846. this.finishPoly();
  31847. this._fillStyle.reset();
  31848. return this;
  31849. };
  31850. /**
  31851. * Draws a rectangle shape.
  31852. *
  31853. * @param {number} x - The X coord of the top-left of the rectangle
  31854. * @param {number} y - The Y coord of the top-left of the rectangle
  31855. * @param {number} width - The width of the rectangle
  31856. * @param {number} height - The height of the rectangle
  31857. * @return {PIXI.Graphics} This Graphics object. Good for chaining method calls
  31858. */
  31859. Graphics.prototype.drawRect = function (x, y, width, height) {
  31860. return this.drawShape(new Rectangle(x, y, width, height));
  31861. };
  31862. /**
  31863. * Draw a rectangle shape with rounded/beveled corners.
  31864. *
  31865. * @param {number} x - The X coord of the top-left of the rectangle
  31866. * @param {number} y - The Y coord of the top-left of the rectangle
  31867. * @param {number} width - The width of the rectangle
  31868. * @param {number} height - The height of the rectangle
  31869. * @param {number} radius - Radius of the rectangle corners
  31870. * @return {PIXI.Graphics} This Graphics object. Good for chaining method calls
  31871. */
  31872. Graphics.prototype.drawRoundedRect = function (x, y, width, height, radius) {
  31873. return this.drawShape(new RoundedRectangle(x, y, width, height, radius));
  31874. };
  31875. /**
  31876. * Draws a circle.
  31877. *
  31878. * @param {number} x - The X coordinate of the center of the circle
  31879. * @param {number} y - The Y coordinate of the center of the circle
  31880. * @param {number} radius - The radius of the circle
  31881. * @return {PIXI.Graphics} This Graphics object. Good for chaining method calls
  31882. */
  31883. Graphics.prototype.drawCircle = function (x, y, radius) {
  31884. return this.drawShape(new Circle(x, y, radius));
  31885. };
  31886. /**
  31887. * Draws an ellipse.
  31888. *
  31889. * @param {number} x - The X coordinate of the center of the ellipse
  31890. * @param {number} y - The Y coordinate of the center of the ellipse
  31891. * @param {number} width - The half width of the ellipse
  31892. * @param {number} height - The half height of the ellipse
  31893. * @return {PIXI.Graphics} This Graphics object. Good for chaining method calls
  31894. */
  31895. Graphics.prototype.drawEllipse = function (x, y, width, height) {
  31896. return this.drawShape(new Ellipse(x, y, width, height));
  31897. };
  31898. /**
  31899. * Draws a polygon using the given path.
  31900. *
  31901. * @param {number[]|PIXI.Point[]|PIXI.Polygon} path - The path data used to construct the polygon.
  31902. * @return {PIXI.Graphics} This Graphics object. Good for chaining method calls
  31903. */
  31904. Graphics.prototype.drawPolygon = function () {
  31905. var arguments$1 = arguments;
  31906. var path = [];
  31907. for (var _i = 0; _i < arguments.length; _i++) {
  31908. path[_i] = arguments$1[_i];
  31909. }
  31910. var points;
  31911. var closeStroke = true; // !!this._fillStyle;
  31912. var poly = path[0];
  31913. // check if data has points..
  31914. if (poly.points) {
  31915. closeStroke = poly.closeStroke;
  31916. points = poly.points;
  31917. }
  31918. else if (Array.isArray(path[0])) {
  31919. points = path[0];
  31920. }
  31921. else {
  31922. points = path;
  31923. }
  31924. var shape = new Polygon(points);
  31925. shape.closeStroke = closeStroke;
  31926. this.drawShape(shape);
  31927. return this;
  31928. };
  31929. /**
  31930. * Draw any shape.
  31931. *
  31932. * @param {PIXI.Circle|PIXI.Ellipse|PIXI.Polygon|PIXI.Rectangle|PIXI.RoundedRectangle} shape - Shape to draw
  31933. * @return {PIXI.Graphics} This Graphics object. Good for chaining method calls
  31934. */
  31935. Graphics.prototype.drawShape = function (shape) {
  31936. if (!this._holeMode) {
  31937. this._geometry.drawShape(shape, this._fillStyle.clone(), this._lineStyle.clone(), this._matrix);
  31938. }
  31939. else {
  31940. this._geometry.drawHole(shape, this._matrix);
  31941. }
  31942. return this;
  31943. };
  31944. /**
  31945. * Clears the graphics that were drawn to this Graphics object, and resets fill and line style settings.
  31946. *
  31947. * @return {PIXI.Graphics} This Graphics object. Good for chaining method calls
  31948. */
  31949. Graphics.prototype.clear = function () {
  31950. this._geometry.clear();
  31951. this._lineStyle.reset();
  31952. this._fillStyle.reset();
  31953. this._boundsID++;
  31954. this._matrix = null;
  31955. this._holeMode = false;
  31956. this.currentPath = null;
  31957. return this;
  31958. };
  31959. /**
  31960. * True if graphics consists of one rectangle, and thus, can be drawn like a Sprite and
  31961. * masked with gl.scissor.
  31962. *
  31963. * @returns {boolean} True if only 1 rect.
  31964. */
  31965. Graphics.prototype.isFastRect = function () {
  31966. var data = this._geometry.graphicsData;
  31967. return data.length === 1
  31968. && data[0].shape.type === exports.SHAPES.RECT
  31969. && !data[0].holes.length
  31970. && !(data[0].lineStyle.visible && data[0].lineStyle.width);
  31971. };
  31972. /**
  31973. * Renders the object using the WebGL renderer
  31974. *
  31975. * @param {PIXI.Renderer} renderer - The renderer
  31976. */
  31977. Graphics.prototype._render = function (renderer) {
  31978. this.finishPoly();
  31979. var geometry = this._geometry;
  31980. var hasuint32 = renderer.context.supports.uint32Indices;
  31981. // batch part..
  31982. // batch it!
  31983. geometry.updateBatches(hasuint32);
  31984. if (geometry.batchable) {
  31985. if (this.batchDirty !== geometry.batchDirty) {
  31986. this._populateBatches();
  31987. }
  31988. this._renderBatched(renderer);
  31989. }
  31990. else {
  31991. // no batching...
  31992. renderer.batch.flush();
  31993. this._renderDirect(renderer);
  31994. }
  31995. };
  31996. /** Populating batches for rendering. */
  31997. Graphics.prototype._populateBatches = function () {
  31998. var geometry = this._geometry;
  31999. var blendMode = this.blendMode;
  32000. var len = geometry.batches.length;
  32001. this.batchTint = -1;
  32002. this._transformID = -1;
  32003. this.batchDirty = geometry.batchDirty;
  32004. this.batches.length = len;
  32005. this.vertexData = new Float32Array(geometry.points);
  32006. for (var i = 0; i < len; i++) {
  32007. var gI = geometry.batches[i];
  32008. var color = gI.style.color;
  32009. var vertexData = new Float32Array(this.vertexData.buffer, gI.attribStart * 4 * 2, gI.attribSize * 2);
  32010. var uvs = new Float32Array(geometry.uvsFloat32.buffer, gI.attribStart * 4 * 2, gI.attribSize * 2);
  32011. var indices = new Uint16Array(geometry.indicesUint16.buffer, gI.start * 2, gI.size);
  32012. var batch = {
  32013. vertexData: vertexData,
  32014. blendMode: blendMode,
  32015. indices: indices,
  32016. uvs: uvs,
  32017. _batchRGB: hex2rgb(color),
  32018. _tintRGB: color,
  32019. _texture: gI.style.texture,
  32020. alpha: gI.style.alpha,
  32021. worldAlpha: 1
  32022. };
  32023. this.batches[i] = batch;
  32024. }
  32025. };
  32026. /**
  32027. * Renders the batches using the BathedRenderer plugin
  32028. *
  32029. * @param {PIXI.Renderer} renderer - The renderer
  32030. */
  32031. Graphics.prototype._renderBatched = function (renderer) {
  32032. if (!this.batches.length) {
  32033. return;
  32034. }
  32035. renderer.batch.setObjectRenderer(renderer.plugins[this.pluginName]);
  32036. this.calculateVertices();
  32037. this.calculateTints();
  32038. for (var i = 0, l = this.batches.length; i < l; i++) {
  32039. var batch = this.batches[i];
  32040. batch.worldAlpha = this.worldAlpha * batch.alpha;
  32041. renderer.plugins[this.pluginName].render(batch);
  32042. }
  32043. };
  32044. /**
  32045. * Renders the graphics direct
  32046. *
  32047. * @param {PIXI.Renderer} renderer - The renderer
  32048. */
  32049. Graphics.prototype._renderDirect = function (renderer) {
  32050. var shader = this._resolveDirectShader(renderer);
  32051. var geometry = this._geometry;
  32052. var tint = this.tint;
  32053. var worldAlpha = this.worldAlpha;
  32054. var uniforms = shader.uniforms;
  32055. var drawCalls = geometry.drawCalls;
  32056. // lets set the transfomr
  32057. uniforms.translationMatrix = this.transform.worldTransform;
  32058. // and then lets set the tint..
  32059. uniforms.tint[0] = (((tint >> 16) & 0xFF) / 255) * worldAlpha;
  32060. uniforms.tint[1] = (((tint >> 8) & 0xFF) / 255) * worldAlpha;
  32061. uniforms.tint[2] = ((tint & 0xFF) / 255) * worldAlpha;
  32062. uniforms.tint[3] = worldAlpha;
  32063. // the first draw call, we can set the uniforms of the shader directly here.
  32064. // this means that we can tack advantage of the sync function of pixi!
  32065. // bind and sync uniforms..
  32066. // there is a way to optimise this..
  32067. renderer.shader.bind(shader);
  32068. renderer.geometry.bind(geometry, shader);
  32069. // set state..
  32070. renderer.state.set(this.state);
  32071. // then render the rest of them...
  32072. for (var i = 0, l = drawCalls.length; i < l; i++) {
  32073. this._renderDrawCallDirect(renderer, geometry.drawCalls[i]);
  32074. }
  32075. };
  32076. /**
  32077. * Renders specific DrawCall
  32078. *
  32079. * @param {PIXI.Renderer} renderer
  32080. * @param {PIXI.BatchDrawCall} drawCall
  32081. */
  32082. Graphics.prototype._renderDrawCallDirect = function (renderer, drawCall) {
  32083. var texArray = drawCall.texArray, type = drawCall.type, size = drawCall.size, start = drawCall.start;
  32084. var groupTextureCount = texArray.count;
  32085. for (var j = 0; j < groupTextureCount; j++) {
  32086. renderer.texture.bind(texArray.elements[j], j);
  32087. }
  32088. renderer.geometry.draw(type, size, start);
  32089. };
  32090. /**
  32091. * Resolves shader for direct rendering
  32092. *
  32093. * @param {PIXI.Renderer} renderer - The renderer
  32094. */
  32095. Graphics.prototype._resolveDirectShader = function (renderer) {
  32096. var shader = this.shader;
  32097. var pluginName = this.pluginName;
  32098. if (!shader) {
  32099. // if there is no shader here, we can use the default shader.
  32100. // and that only gets created if we actually need it..
  32101. // but may be more than one plugins for graphics
  32102. if (!DEFAULT_SHADERS[pluginName]) {
  32103. var MAX_TEXTURES = renderer.plugins.batch.MAX_TEXTURES;
  32104. var sampleValues = new Int32Array(MAX_TEXTURES);
  32105. for (var i = 0; i < MAX_TEXTURES; i++) {
  32106. sampleValues[i] = i;
  32107. }
  32108. var uniforms = {
  32109. tint: new Float32Array([1, 1, 1, 1]),
  32110. translationMatrix: new Matrix(),
  32111. default: UniformGroup.from({ uSamplers: sampleValues }, true),
  32112. };
  32113. var program = renderer.plugins[pluginName]._shader.program;
  32114. DEFAULT_SHADERS[pluginName] = new Shader(program, uniforms);
  32115. }
  32116. shader = DEFAULT_SHADERS[pluginName];
  32117. }
  32118. return shader;
  32119. };
  32120. /** Retrieves the bounds of the graphic shape as a rectangle object. */
  32121. Graphics.prototype._calculateBounds = function () {
  32122. this.finishPoly();
  32123. var geometry = this._geometry;
  32124. // skipping when graphics is empty, like a container
  32125. if (!geometry.graphicsData.length) {
  32126. return;
  32127. }
  32128. var _a = geometry.bounds, minX = _a.minX, minY = _a.minY, maxX = _a.maxX, maxY = _a.maxY;
  32129. this._bounds.addFrame(this.transform, minX, minY, maxX, maxY);
  32130. };
  32131. /**
  32132. * Tests if a point is inside this graphics object
  32133. *
  32134. * @param {PIXI.IPointData} point - the point to test
  32135. * @return {boolean} the result of the test
  32136. */
  32137. Graphics.prototype.containsPoint = function (point) {
  32138. this.worldTransform.applyInverse(point, Graphics._TEMP_POINT);
  32139. return this._geometry.containsPoint(Graphics._TEMP_POINT);
  32140. };
  32141. /** Recalculate the tint by applying tint to batches using Graphics tint. */
  32142. Graphics.prototype.calculateTints = function () {
  32143. if (this.batchTint !== this.tint) {
  32144. this.batchTint = this.tint;
  32145. var tintRGB = hex2rgb(this.tint, temp);
  32146. for (var i = 0; i < this.batches.length; i++) {
  32147. var batch = this.batches[i];
  32148. var batchTint = batch._batchRGB;
  32149. var r = (tintRGB[0] * batchTint[0]) * 255;
  32150. var g = (tintRGB[1] * batchTint[1]) * 255;
  32151. var b = (tintRGB[2] * batchTint[2]) * 255;
  32152. // TODO Ivan, can this be done in one go?
  32153. var color = (r << 16) + (g << 8) + (b | 0);
  32154. batch._tintRGB = (color >> 16)
  32155. + (color & 0xff00)
  32156. + ((color & 0xff) << 16);
  32157. }
  32158. }
  32159. };
  32160. /**
  32161. * If there's a transform update or a change to the shape of the
  32162. * geometry, recalculate the vertices.
  32163. */
  32164. Graphics.prototype.calculateVertices = function () {
  32165. var wtID = this.transform._worldID;
  32166. if (this._transformID === wtID) {
  32167. return;
  32168. }
  32169. this._transformID = wtID;
  32170. var wt = this.transform.worldTransform;
  32171. var a = wt.a;
  32172. var b = wt.b;
  32173. var c = wt.c;
  32174. var d = wt.d;
  32175. var tx = wt.tx;
  32176. var ty = wt.ty;
  32177. var data = this._geometry.points; // batch.vertexDataOriginal;
  32178. var vertexData = this.vertexData;
  32179. var count = 0;
  32180. for (var i = 0; i < data.length; i += 2) {
  32181. var x = data[i];
  32182. var y = data[i + 1];
  32183. vertexData[count++] = (a * x) + (c * y) + tx;
  32184. vertexData[count++] = (d * y) + (b * x) + ty;
  32185. }
  32186. };
  32187. /**
  32188. * Closes the current path.
  32189. *
  32190. * @return {PIXI.Graphics} Returns itself.
  32191. */
  32192. Graphics.prototype.closePath = function () {
  32193. var currentPath = this.currentPath;
  32194. if (currentPath) {
  32195. // we don't need to add extra point in the end because buildLine will take care of that
  32196. currentPath.closeStroke = true;
  32197. // ensure that the polygon is completed, and is available for hit detection
  32198. // (even if the graphics is not rendered yet)
  32199. this.finishPoly();
  32200. }
  32201. return this;
  32202. };
  32203. /**
  32204. * Apply a matrix to the positional data.
  32205. *
  32206. * @param {PIXI.Matrix} matrix - Matrix to use for transform current shape.
  32207. * @return {PIXI.Graphics} Returns itself.
  32208. */
  32209. Graphics.prototype.setMatrix = function (matrix) {
  32210. this._matrix = matrix;
  32211. return this;
  32212. };
  32213. /**
  32214. * Begin adding holes to the last draw shape
  32215. * IMPORTANT: holes must be fully inside a shape to work
  32216. * Also weirdness ensues if holes overlap!
  32217. * Ellipses, Circles, Rectangles and Rounded Rectangles cannot be holes or host for holes in CanvasRenderer,
  32218. * please use `moveTo` `lineTo`, `quadraticCurveTo` if you rely on pixi-legacy bundle.
  32219. * @return {PIXI.Graphics} Returns itself.
  32220. */
  32221. Graphics.prototype.beginHole = function () {
  32222. this.finishPoly();
  32223. this._holeMode = true;
  32224. return this;
  32225. };
  32226. /**
  32227. * End adding holes to the last draw shape
  32228. * @return {PIXI.Graphics} Returns itself.
  32229. */
  32230. Graphics.prototype.endHole = function () {
  32231. this.finishPoly();
  32232. this._holeMode = false;
  32233. return this;
  32234. };
  32235. /**
  32236. * Destroys the Graphics object.
  32237. *
  32238. * @param {object|boolean} [options] - Options parameter. A boolean will act as if all
  32239. * options have been set to that value
  32240. * @param {boolean} [options.children=false] - if set to true, all the children will have
  32241. * their destroy method called as well. 'options' will be passed on to those calls.
  32242. * @param {boolean} [options.texture=false] - Only used for child Sprites if options.children is set to true
  32243. * Should it destroy the texture of the child sprite
  32244. * @param {boolean} [options.baseTexture=false] - Only used for child Sprites if options.children is set to true
  32245. * Should it destroy the base texture of the child sprite
  32246. */
  32247. Graphics.prototype.destroy = function (options) {
  32248. this._geometry.refCount--;
  32249. if (this._geometry.refCount === 0) {
  32250. this._geometry.dispose();
  32251. }
  32252. this._matrix = null;
  32253. this.currentPath = null;
  32254. this._lineStyle.destroy();
  32255. this._lineStyle = null;
  32256. this._fillStyle.destroy();
  32257. this._fillStyle = null;
  32258. this._geometry = null;
  32259. this.shader = null;
  32260. this.vertexData = null;
  32261. this.batches.length = 0;
  32262. this.batches = null;
  32263. _super.prototype.destroy.call(this, options);
  32264. };
  32265. /**
  32266. * Temporary point to use for containsPoint
  32267. *
  32268. * @static
  32269. * @private
  32270. * @member {PIXI.Point}
  32271. */
  32272. Graphics._TEMP_POINT = new Point();
  32273. return Graphics;
  32274. }(Container));
  32275. var graphicsUtils = {
  32276. buildPoly: buildPoly,
  32277. buildCircle: buildCircle,
  32278. buildRectangle: buildRectangle,
  32279. buildRoundedRectangle: buildRoundedRectangle,
  32280. buildLine: buildLine,
  32281. ArcUtils: ArcUtils,
  32282. BezierUtils: BezierUtils,
  32283. QuadraticUtils: QuadraticUtils,
  32284. BatchPart: BatchPart,
  32285. FILL_COMMANDS: FILL_COMMANDS,
  32286. BATCH_POOL: BATCH_POOL,
  32287. DRAW_CALL_POOL: DRAW_CALL_POOL
  32288. };
  32289. /*!
  32290. * @pixi/sprite - v6.1.2
  32291. * Compiled Thu, 12 Aug 2021 17:11:19 UTC
  32292. *
  32293. * @pixi/sprite is licensed under the MIT License.
  32294. * http://www.opensource.org/licenses/mit-license
  32295. */
  32296. /*! *****************************************************************************
  32297. Copyright (c) Microsoft Corporation. All rights reserved.
  32298. Licensed under the Apache License, Version 2.0 (the "License"); you may not use
  32299. this file except in compliance with the License. You may obtain a copy of the
  32300. License at http://www.apache.org/licenses/LICENSE-2.0
  32301. THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  32302. KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
  32303. WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
  32304. MERCHANTABLITY OR NON-INFRINGEMENT.
  32305. See the Apache Version 2.0 License for specific language governing permissions
  32306. and limitations under the License.
  32307. ***************************************************************************** */
  32308. /* global Reflect, Promise */
  32309. var extendStatics$6 = function(d, b) {
  32310. extendStatics$6 = Object.setPrototypeOf ||
  32311. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  32312. function (d, b) { for (var p in b) { if (b.hasOwnProperty(p)) { d[p] = b[p]; } } };
  32313. return extendStatics$6(d, b);
  32314. };
  32315. function __extends$6(d, b) {
  32316. extendStatics$6(d, b);
  32317. function __() { this.constructor = d; }
  32318. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  32319. }
  32320. var tempPoint = new Point();
  32321. var indices = new Uint16Array([0, 1, 2, 0, 2, 3]);
  32322. /**
  32323. * The Sprite object is the base for all textured objects that are rendered to the screen
  32324. *
  32325. * A sprite can be created directly from an image like this:
  32326. *
  32327. * ```js
  32328. * let sprite = PIXI.Sprite.from('assets/image.png');
  32329. * ```
  32330. *
  32331. * The more efficient way to create sprites is using a {@link PIXI.Spritesheet},
  32332. * as swapping base textures when rendering to the screen is inefficient.
  32333. *
  32334. * ```js
  32335. * PIXI.Loader.shared.add("assets/spritesheet.json").load(setup);
  32336. *
  32337. * function setup() {
  32338. * let sheet = PIXI.Loader.shared.resources["assets/spritesheet.json"].spritesheet;
  32339. * let sprite = new PIXI.Sprite(sheet.textures["image.png"]);
  32340. * ...
  32341. * }
  32342. * ```
  32343. *
  32344. * @class
  32345. * @extends PIXI.Container
  32346. * @memberof PIXI
  32347. */
  32348. var Sprite = /** @class */ (function (_super) {
  32349. __extends$6(Sprite, _super);
  32350. /**
  32351. * @param {PIXI.Texture} [texture] - The texture for this sprite.
  32352. */
  32353. function Sprite(texture) {
  32354. var _this = _super.call(this) || this;
  32355. /**
  32356. * The anchor point defines the normalized coordinates
  32357. * in the texture that map to the position of this
  32358. * sprite.
  32359. *
  32360. * By default, this is `(0,0)` (or `texture.defaultAnchor`
  32361. * if you have modified that), which means the position
  32362. * `(x,y)` of this `Sprite` will be the top-left corner.
  32363. *
  32364. * Note: Updating `texture.defaultAnchor` after
  32365. * constructing a `Sprite` does _not_ update its anchor.
  32366. *
  32367. * {@link https://docs.cocos2d-x.org/cocos2d-x/en/sprites/manipulation.html}
  32368. *
  32369. * @default `texture.defaultAnchor`
  32370. * @member {PIXI.ObservablePoint}
  32371. * @private
  32372. */
  32373. _this._anchor = new ObservablePoint(_this._onAnchorUpdate, _this, (texture ? texture.defaultAnchor.x : 0), (texture ? texture.defaultAnchor.y : 0));
  32374. /**
  32375. * The texture that the sprite is using
  32376. *
  32377. * @private
  32378. * @member {PIXI.Texture}
  32379. */
  32380. _this._texture = null;
  32381. /**
  32382. * The width of the sprite (this is initially set by the texture)
  32383. *
  32384. * @protected
  32385. * @member {number}
  32386. */
  32387. _this._width = 0;
  32388. /**
  32389. * The height of the sprite (this is initially set by the texture)
  32390. *
  32391. * @protected
  32392. * @member {number}
  32393. */
  32394. _this._height = 0;
  32395. /**
  32396. * The tint applied to the sprite. This is a hex value. A value of 0xFFFFFF will remove any tint effect.
  32397. *
  32398. * @private
  32399. * @member {number}
  32400. * @default 0xFFFFFF
  32401. */
  32402. _this._tint = null;
  32403. /**
  32404. * The tint applied to the sprite. This is a RGB value. A value of 0xFFFFFF will remove any tint effect.
  32405. *
  32406. * @private
  32407. * @member {number}
  32408. * @default 16777215
  32409. */
  32410. _this._tintRGB = null;
  32411. _this.tint = 0xFFFFFF;
  32412. /**
  32413. * The blend mode to be applied to the sprite. Apply a value of `PIXI.BLEND_MODES.NORMAL` to reset the blend mode.
  32414. *
  32415. * @member {number}
  32416. * @default PIXI.BLEND_MODES.NORMAL
  32417. * @see PIXI.BLEND_MODES
  32418. */
  32419. _this.blendMode = exports.BLEND_MODES.NORMAL;
  32420. /**
  32421. * Cached tint value so we can tell when the tint is changed.
  32422. * Value is used for 2d CanvasRenderer.
  32423. *
  32424. * @protected
  32425. * @member {number}
  32426. * @default 0xFFFFFF
  32427. */
  32428. _this._cachedTint = 0xFFFFFF;
  32429. /**
  32430. * this is used to store the uvs data of the sprite, assigned at the same time
  32431. * as the vertexData in calculateVertices()
  32432. *
  32433. * @private
  32434. * @member {Float32Array}
  32435. */
  32436. _this.uvs = null;
  32437. // call texture setter
  32438. _this.texture = texture || Texture.EMPTY;
  32439. /**
  32440. * this is used to store the vertex data of the sprite (basically a quad)
  32441. *
  32442. * @private
  32443. * @member {Float32Array}
  32444. */
  32445. _this.vertexData = new Float32Array(8);
  32446. /**
  32447. * This is used to calculate the bounds of the object IF it is a trimmed sprite
  32448. *
  32449. * @private
  32450. * @member {Float32Array}
  32451. */
  32452. _this.vertexTrimmedData = null;
  32453. _this._transformID = -1;
  32454. _this._textureID = -1;
  32455. _this._transformTrimmedID = -1;
  32456. _this._textureTrimmedID = -1;
  32457. // Batchable stuff..
  32458. // TODO could make this a mixin?
  32459. _this.indices = indices;
  32460. /**
  32461. * Plugin that is responsible for rendering this element.
  32462. * Allows to customize the rendering process without overriding '_render' & '_renderCanvas' methods.
  32463. *
  32464. * @member {string}
  32465. * @default 'batch'
  32466. */
  32467. _this.pluginName = 'batch';
  32468. /**
  32469. * used to fast check if a sprite is.. a sprite!
  32470. * @member {boolean}
  32471. */
  32472. _this.isSprite = true;
  32473. /**
  32474. * Internal roundPixels field
  32475. *
  32476. * @member {boolean}
  32477. * @private
  32478. */
  32479. _this._roundPixels = settings.ROUND_PIXELS;
  32480. return _this;
  32481. }
  32482. /**
  32483. * When the texture is updated, this event will fire to update the scale and frame
  32484. *
  32485. * @protected
  32486. */
  32487. Sprite.prototype._onTextureUpdate = function () {
  32488. this._textureID = -1;
  32489. this._textureTrimmedID = -1;
  32490. this._cachedTint = 0xFFFFFF;
  32491. // so if _width is 0 then width was not set..
  32492. if (this._width) {
  32493. this.scale.x = sign$1(this.scale.x) * this._width / this._texture.orig.width;
  32494. }
  32495. if (this._height) {
  32496. this.scale.y = sign$1(this.scale.y) * this._height / this._texture.orig.height;
  32497. }
  32498. };
  32499. /**
  32500. * Called when the anchor position updates.
  32501. *
  32502. * @private
  32503. */
  32504. Sprite.prototype._onAnchorUpdate = function () {
  32505. this._transformID = -1;
  32506. this._transformTrimmedID = -1;
  32507. };
  32508. /**
  32509. * calculates worldTransform * vertices, store it in vertexData
  32510. */
  32511. Sprite.prototype.calculateVertices = function () {
  32512. var texture = this._texture;
  32513. if (this._transformID === this.transform._worldID && this._textureID === texture._updateID) {
  32514. return;
  32515. }
  32516. // update texture UV here, because base texture can be changed without calling `_onTextureUpdate`
  32517. if (this._textureID !== texture._updateID) {
  32518. this.uvs = this._texture._uvs.uvsFloat32;
  32519. }
  32520. this._transformID = this.transform._worldID;
  32521. this._textureID = texture._updateID;
  32522. // set the vertex data
  32523. var wt = this.transform.worldTransform;
  32524. var a = wt.a;
  32525. var b = wt.b;
  32526. var c = wt.c;
  32527. var d = wt.d;
  32528. var tx = wt.tx;
  32529. var ty = wt.ty;
  32530. var vertexData = this.vertexData;
  32531. var trim = texture.trim;
  32532. var orig = texture.orig;
  32533. var anchor = this._anchor;
  32534. var w0 = 0;
  32535. var w1 = 0;
  32536. var h0 = 0;
  32537. var h1 = 0;
  32538. if (trim) {
  32539. // if the sprite is trimmed and is not a tilingsprite then we need to add the extra
  32540. // space before transforming the sprite coords.
  32541. w1 = trim.x - (anchor._x * orig.width);
  32542. w0 = w1 + trim.width;
  32543. h1 = trim.y - (anchor._y * orig.height);
  32544. h0 = h1 + trim.height;
  32545. }
  32546. else {
  32547. w1 = -anchor._x * orig.width;
  32548. w0 = w1 + orig.width;
  32549. h1 = -anchor._y * orig.height;
  32550. h0 = h1 + orig.height;
  32551. }
  32552. // xy
  32553. vertexData[0] = (a * w1) + (c * h1) + tx;
  32554. vertexData[1] = (d * h1) + (b * w1) + ty;
  32555. // xy
  32556. vertexData[2] = (a * w0) + (c * h1) + tx;
  32557. vertexData[3] = (d * h1) + (b * w0) + ty;
  32558. // xy
  32559. vertexData[4] = (a * w0) + (c * h0) + tx;
  32560. vertexData[5] = (d * h0) + (b * w0) + ty;
  32561. // xy
  32562. vertexData[6] = (a * w1) + (c * h0) + tx;
  32563. vertexData[7] = (d * h0) + (b * w1) + ty;
  32564. if (this._roundPixels) {
  32565. var resolution = settings.RESOLUTION;
  32566. for (var i = 0; i < vertexData.length; ++i) {
  32567. vertexData[i] = Math.round((vertexData[i] * resolution | 0) / resolution);
  32568. }
  32569. }
  32570. };
  32571. /**
  32572. * calculates worldTransform * vertices for a non texture with a trim. store it in vertexTrimmedData
  32573. * This is used to ensure that the true width and height of a trimmed texture is respected
  32574. */
  32575. Sprite.prototype.calculateTrimmedVertices = function () {
  32576. if (!this.vertexTrimmedData) {
  32577. this.vertexTrimmedData = new Float32Array(8);
  32578. }
  32579. else if (this._transformTrimmedID === this.transform._worldID && this._textureTrimmedID === this._texture._updateID) {
  32580. return;
  32581. }
  32582. this._transformTrimmedID = this.transform._worldID;
  32583. this._textureTrimmedID = this._texture._updateID;
  32584. // lets do some special trim code!
  32585. var texture = this._texture;
  32586. var vertexData = this.vertexTrimmedData;
  32587. var orig = texture.orig;
  32588. var anchor = this._anchor;
  32589. // lets calculate the new untrimmed bounds..
  32590. var wt = this.transform.worldTransform;
  32591. var a = wt.a;
  32592. var b = wt.b;
  32593. var c = wt.c;
  32594. var d = wt.d;
  32595. var tx = wt.tx;
  32596. var ty = wt.ty;
  32597. var w1 = -anchor._x * orig.width;
  32598. var w0 = w1 + orig.width;
  32599. var h1 = -anchor._y * orig.height;
  32600. var h0 = h1 + orig.height;
  32601. // xy
  32602. vertexData[0] = (a * w1) + (c * h1) + tx;
  32603. vertexData[1] = (d * h1) + (b * w1) + ty;
  32604. // xy
  32605. vertexData[2] = (a * w0) + (c * h1) + tx;
  32606. vertexData[3] = (d * h1) + (b * w0) + ty;
  32607. // xy
  32608. vertexData[4] = (a * w0) + (c * h0) + tx;
  32609. vertexData[5] = (d * h0) + (b * w0) + ty;
  32610. // xy
  32611. vertexData[6] = (a * w1) + (c * h0) + tx;
  32612. vertexData[7] = (d * h0) + (b * w1) + ty;
  32613. };
  32614. /**
  32615. *
  32616. * Renders the object using the WebGL renderer
  32617. *
  32618. * @protected
  32619. * @param {PIXI.Renderer} renderer - The webgl renderer to use.
  32620. */
  32621. Sprite.prototype._render = function (renderer) {
  32622. this.calculateVertices();
  32623. renderer.batch.setObjectRenderer(renderer.plugins[this.pluginName]);
  32624. renderer.plugins[this.pluginName].render(this);
  32625. };
  32626. /**
  32627. * Updates the bounds of the sprite.
  32628. *
  32629. * @protected
  32630. */
  32631. Sprite.prototype._calculateBounds = function () {
  32632. var trim = this._texture.trim;
  32633. var orig = this._texture.orig;
  32634. // First lets check to see if the current texture has a trim..
  32635. if (!trim || (trim.width === orig.width && trim.height === orig.height)) {
  32636. // no trim! lets use the usual calculations..
  32637. this.calculateVertices();
  32638. this._bounds.addQuad(this.vertexData);
  32639. }
  32640. else {
  32641. // lets calculate a special trimmed bounds...
  32642. this.calculateTrimmedVertices();
  32643. this._bounds.addQuad(this.vertexTrimmedData);
  32644. }
  32645. };
  32646. /**
  32647. * Gets the local bounds of the sprite object.
  32648. *
  32649. * @param {PIXI.Rectangle} [rect] - Optional output rectangle.
  32650. * @return {PIXI.Rectangle} The bounds.
  32651. */
  32652. Sprite.prototype.getLocalBounds = function (rect) {
  32653. // we can do a fast local bounds if the sprite has no children!
  32654. if (this.children.length === 0) {
  32655. this._bounds.minX = this._texture.orig.width * -this._anchor._x;
  32656. this._bounds.minY = this._texture.orig.height * -this._anchor._y;
  32657. this._bounds.maxX = this._texture.orig.width * (1 - this._anchor._x);
  32658. this._bounds.maxY = this._texture.orig.height * (1 - this._anchor._y);
  32659. if (!rect) {
  32660. if (!this._localBoundsRect) {
  32661. this._localBoundsRect = new Rectangle();
  32662. }
  32663. rect = this._localBoundsRect;
  32664. }
  32665. return this._bounds.getRectangle(rect);
  32666. }
  32667. return _super.prototype.getLocalBounds.call(this, rect);
  32668. };
  32669. /**
  32670. * Tests if a point is inside this sprite
  32671. *
  32672. * @param {PIXI.IPointData} point - the point to test
  32673. * @return {boolean} the result of the test
  32674. */
  32675. Sprite.prototype.containsPoint = function (point) {
  32676. this.worldTransform.applyInverse(point, tempPoint);
  32677. var width = this._texture.orig.width;
  32678. var height = this._texture.orig.height;
  32679. var x1 = -width * this.anchor.x;
  32680. var y1 = 0;
  32681. if (tempPoint.x >= x1 && tempPoint.x < x1 + width) {
  32682. y1 = -height * this.anchor.y;
  32683. if (tempPoint.y >= y1 && tempPoint.y < y1 + height) {
  32684. return true;
  32685. }
  32686. }
  32687. return false;
  32688. };
  32689. /**
  32690. * Destroys this sprite and optionally its texture and children
  32691. *
  32692. * @param {object|boolean} [options] - Options parameter. A boolean will act as if all options
  32693. * have been set to that value
  32694. * @param {boolean} [options.children=false] - if set to true, all the children will have their destroy
  32695. * method called as well. 'options' will be passed on to those calls.
  32696. * @param {boolean} [options.texture=false] - Should it destroy the current texture of the sprite as well
  32697. * @param {boolean} [options.baseTexture=false] - Should it destroy the base texture of the sprite as well
  32698. */
  32699. Sprite.prototype.destroy = function (options) {
  32700. _super.prototype.destroy.call(this, options);
  32701. this._texture.off('update', this._onTextureUpdate, this);
  32702. this._anchor = null;
  32703. var destroyTexture = typeof options === 'boolean' ? options : options && options.texture;
  32704. if (destroyTexture) {
  32705. var destroyBaseTexture = typeof options === 'boolean' ? options : options && options.baseTexture;
  32706. this._texture.destroy(!!destroyBaseTexture);
  32707. }
  32708. this._texture = null;
  32709. };
  32710. // some helper functions..
  32711. /**
  32712. * Helper function that creates a new sprite based on the source you provide.
  32713. * The source can be - frame id, image url, video url, canvas element, video element, base texture
  32714. *
  32715. * @static
  32716. * @param {string|PIXI.Texture|HTMLCanvasElement|HTMLVideoElement} source - Source to create texture from
  32717. * @param {object} [options] - See {@link PIXI.BaseTexture}'s constructor for options.
  32718. * @return {PIXI.Sprite} The newly created sprite
  32719. */
  32720. Sprite.from = function (source, options) {
  32721. var texture = (source instanceof Texture)
  32722. ? source
  32723. : Texture.from(source, options);
  32724. return new Sprite(texture);
  32725. };
  32726. Object.defineProperty(Sprite.prototype, "roundPixels", {
  32727. get: function () {
  32728. return this._roundPixels;
  32729. },
  32730. /**
  32731. * If true PixiJS will Math.floor() x/y values when rendering, stopping pixel interpolation.
  32732. * Advantages can include sharper image quality (like text) and faster rendering on canvas.
  32733. * The main disadvantage is movement of objects may appear less smooth.
  32734. * To set the global default, change {@link PIXI.settings.ROUND_PIXELS}
  32735. *
  32736. * @member {boolean}
  32737. * @default false
  32738. */
  32739. set: function (value) {
  32740. if (this._roundPixels !== value) {
  32741. this._transformID = -1;
  32742. }
  32743. this._roundPixels = value;
  32744. },
  32745. enumerable: false,
  32746. configurable: true
  32747. });
  32748. Object.defineProperty(Sprite.prototype, "width", {
  32749. /**
  32750. * The width of the sprite, setting this will actually modify the scale to achieve the value set
  32751. *
  32752. * @member {number}
  32753. */
  32754. get: function () {
  32755. return Math.abs(this.scale.x) * this._texture.orig.width;
  32756. },
  32757. set: function (value) {
  32758. var s = sign$1(this.scale.x) || 1;
  32759. this.scale.x = s * value / this._texture.orig.width;
  32760. this._width = value;
  32761. },
  32762. enumerable: false,
  32763. configurable: true
  32764. });
  32765. Object.defineProperty(Sprite.prototype, "height", {
  32766. /**
  32767. * The height of the sprite, setting this will actually modify the scale to achieve the value set
  32768. *
  32769. * @member {number}
  32770. */
  32771. get: function () {
  32772. return Math.abs(this.scale.y) * this._texture.orig.height;
  32773. },
  32774. set: function (value) {
  32775. var s = sign$1(this.scale.y) || 1;
  32776. this.scale.y = s * value / this._texture.orig.height;
  32777. this._height = value;
  32778. },
  32779. enumerable: false,
  32780. configurable: true
  32781. });
  32782. Object.defineProperty(Sprite.prototype, "anchor", {
  32783. /**
  32784. * The anchor sets the origin point of the sprite. The default value is taken from the {@link PIXI.Texture|Texture}
  32785. * and passed to the constructor.
  32786. *
  32787. * The default is `(0,0)`, this means the sprite's origin is the top left.
  32788. *
  32789. * Setting the anchor to `(0.5,0.5)` means the sprite's origin is centered.
  32790. *
  32791. * Setting the anchor to `(1,1)` would mean the sprite's origin point will be the bottom right corner.
  32792. *
  32793. * If you pass only single parameter, it will set both x and y to the same value as shown in the example below.
  32794. *
  32795. * @example
  32796. * const sprite = new PIXI.Sprite(texture);
  32797. * sprite.anchor.set(0.5); // This will set the origin to center. (0.5) is same as (0.5, 0.5).
  32798. *
  32799. * @member {PIXI.ObservablePoint}
  32800. */
  32801. get: function () {
  32802. return this._anchor;
  32803. },
  32804. set: function (value) {
  32805. this._anchor.copyFrom(value);
  32806. },
  32807. enumerable: false,
  32808. configurable: true
  32809. });
  32810. Object.defineProperty(Sprite.prototype, "tint", {
  32811. /**
  32812. * The tint applied to the sprite. This is a hex value.
  32813. * A value of 0xFFFFFF will remove any tint effect.
  32814. *
  32815. * @member {number}
  32816. * @default 0xFFFFFF
  32817. */
  32818. get: function () {
  32819. return this._tint;
  32820. },
  32821. set: function (value) {
  32822. this._tint = value;
  32823. this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16);
  32824. },
  32825. enumerable: false,
  32826. configurable: true
  32827. });
  32828. Object.defineProperty(Sprite.prototype, "texture", {
  32829. /**
  32830. * The texture that the sprite is using
  32831. *
  32832. * @member {PIXI.Texture}
  32833. */
  32834. get: function () {
  32835. return this._texture;
  32836. },
  32837. set: function (value) {
  32838. if (this._texture === value) {
  32839. return;
  32840. }
  32841. if (this._texture) {
  32842. this._texture.off('update', this._onTextureUpdate, this);
  32843. }
  32844. this._texture = value || Texture.EMPTY;
  32845. this._cachedTint = 0xFFFFFF;
  32846. this._textureID = -1;
  32847. this._textureTrimmedID = -1;
  32848. if (value) {
  32849. // wait for the texture to load
  32850. if (value.baseTexture.valid) {
  32851. this._onTextureUpdate();
  32852. }
  32853. else {
  32854. value.once('update', this._onTextureUpdate, this);
  32855. }
  32856. }
  32857. },
  32858. enumerable: false,
  32859. configurable: true
  32860. });
  32861. return Sprite;
  32862. }(Container));
  32863. /*!
  32864. * @pixi/text - v6.1.2
  32865. * Compiled Thu, 12 Aug 2021 17:11:19 UTC
  32866. *
  32867. * @pixi/text is licensed under the MIT License.
  32868. * http://www.opensource.org/licenses/mit-license
  32869. */
  32870. /*! *****************************************************************************
  32871. Copyright (c) Microsoft Corporation. All rights reserved.
  32872. Licensed under the Apache License, Version 2.0 (the "License"); you may not use
  32873. this file except in compliance with the License. You may obtain a copy of the
  32874. License at http://www.apache.org/licenses/LICENSE-2.0
  32875. THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  32876. KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
  32877. WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
  32878. MERCHANTABLITY OR NON-INFRINGEMENT.
  32879. See the Apache Version 2.0 License for specific language governing permissions
  32880. and limitations under the License.
  32881. ***************************************************************************** */
  32882. /* global Reflect, Promise */
  32883. var extendStatics$7 = function(d, b) {
  32884. extendStatics$7 = Object.setPrototypeOf ||
  32885. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  32886. function (d, b) { for (var p in b) { if (b.hasOwnProperty(p)) { d[p] = b[p]; } } };
  32887. return extendStatics$7(d, b);
  32888. };
  32889. function __extends$7(d, b) {
  32890. extendStatics$7(d, b);
  32891. function __() { this.constructor = d; }
  32892. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  32893. }
  32894. /**
  32895. * Constants that define the type of gradient on text.
  32896. *
  32897. * @static
  32898. * @constant
  32899. * @name TEXT_GRADIENT
  32900. * @memberof PIXI
  32901. * @type {object}
  32902. * @property {number} LINEAR_VERTICAL Vertical gradient
  32903. * @property {number} LINEAR_HORIZONTAL Linear gradient
  32904. */
  32905. (function (TEXT_GRADIENT) {
  32906. TEXT_GRADIENT[TEXT_GRADIENT["LINEAR_VERTICAL"] = 0] = "LINEAR_VERTICAL";
  32907. TEXT_GRADIENT[TEXT_GRADIENT["LINEAR_HORIZONTAL"] = 1] = "LINEAR_HORIZONTAL";
  32908. })(exports.TEXT_GRADIENT || (exports.TEXT_GRADIENT = {}));
  32909. // disabling eslint for now, going to rewrite this in v5
  32910. var defaultStyle = {
  32911. align: 'left',
  32912. breakWords: false,
  32913. dropShadow: false,
  32914. dropShadowAlpha: 1,
  32915. dropShadowAngle: Math.PI / 6,
  32916. dropShadowBlur: 0,
  32917. dropShadowColor: 'black',
  32918. dropShadowDistance: 5,
  32919. fill: 'black',
  32920. fillGradientType: exports.TEXT_GRADIENT.LINEAR_VERTICAL,
  32921. fillGradientStops: [],
  32922. fontFamily: 'Arial',
  32923. fontSize: 26,
  32924. fontStyle: 'normal',
  32925. fontVariant: 'normal',
  32926. fontWeight: 'normal',
  32927. letterSpacing: 0,
  32928. lineHeight: 0,
  32929. lineJoin: 'miter',
  32930. miterLimit: 10,
  32931. padding: 0,
  32932. stroke: 'black',
  32933. strokeThickness: 0,
  32934. textBaseline: 'alphabetic',
  32935. trim: false,
  32936. whiteSpace: 'pre',
  32937. wordWrap: false,
  32938. wordWrapWidth: 100,
  32939. leading: 0,
  32940. };
  32941. var genericFontFamilies = [
  32942. 'serif',
  32943. 'sans-serif',
  32944. 'monospace',
  32945. 'cursive',
  32946. 'fantasy',
  32947. 'system-ui' ];
  32948. /**
  32949. * A TextStyle Object contains information to decorate a Text objects.
  32950. *
  32951. * An instance can be shared between multiple Text objects; then changing the style will update all text objects using it.
  32952. *
  32953. * A tool can be used to generate a text style [here](https://pixijs.io/pixi-text-style).
  32954. *
  32955. * @class
  32956. * @memberof PIXI
  32957. */
  32958. var TextStyle = /** @class */ (function () {
  32959. /**
  32960. * @param {object} [style] - The style parameters
  32961. * @param {string} [style.align='left'] - Alignment for multiline text ('left', 'center' or 'right'),
  32962. * does not affect single line text
  32963. * @param {boolean} [style.breakWords=false] - Indicates if lines can be wrapped within words, it
  32964. * needs wordWrap to be set to true
  32965. * @param {boolean} [style.dropShadow=false] - Set a drop shadow for the text
  32966. * @param {number} [style.dropShadowAlpha=1] - Set alpha for the drop shadow
  32967. * @param {number} [style.dropShadowAngle=Math.PI/6] - Set a angle of the drop shadow
  32968. * @param {number} [style.dropShadowBlur=0] - Set a shadow blur radius
  32969. * @param {string|number} [style.dropShadowColor='black'] - A fill style to be used on the dropshadow e.g 'red', '#00FF00'
  32970. * @param {number} [style.dropShadowDistance=5] - Set a distance of the drop shadow
  32971. * @param {string|string[]|number|number[]|CanvasGradient|CanvasPattern} [style.fill='black'] - A canvas
  32972. * fillstyle that will be used on the text e.g 'red', '#00FF00'. Can be an array to create a gradient
  32973. * eg ['#000000','#FFFFFF']
  32974. * {@link https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/fillStyle|MDN}
  32975. * @param {number} [style.fillGradientType=PIXI.TEXT_GRADIENT.LINEAR_VERTICAL] - If fill is an array of colours
  32976. * to create a gradient, this can change the type/direction of the gradient. See {@link PIXI.TEXT_GRADIENT}
  32977. * @param {number[]} [style.fillGradientStops] - If fill is an array of colours to create a gradient, this array can set
  32978. * the stop points (numbers between 0 and 1) for the color, overriding the default behaviour of evenly spacing them.
  32979. * @param {string|string[]} [style.fontFamily='Arial'] - The font family
  32980. * @param {number|string} [style.fontSize=26] - The font size (as a number it converts to px, but as a string,
  32981. * equivalents are '26px','20pt','160%' or '1.6em')
  32982. * @param {string} [style.fontStyle='normal'] - The font style ('normal', 'italic' or 'oblique')
  32983. * @param {string} [style.fontVariant='normal'] - The font variant ('normal' or 'small-caps')
  32984. * @param {string} [style.fontWeight='normal'] - The font weight ('normal', 'bold', 'bolder', 'lighter' and '100',
  32985. * '200', '300', '400', '500', '600', '700', '800' or '900')
  32986. * @param {number} [style.leading=0] - The space between lines
  32987. * @param {number} [style.letterSpacing=0] - The amount of spacing between letters, default is 0
  32988. * @param {number} [style.lineHeight] - The line height, a number that represents the vertical space that a letter uses
  32989. * @param {string} [style.lineJoin='miter'] - The lineJoin property sets the type of corner created, it can resolve
  32990. * spiked text issues. Possible values "miter" (creates a sharp corner), "round" (creates a round corner) or "bevel"
  32991. * (creates a squared corner).
  32992. * @param {number} [style.miterLimit=10] - The miter limit to use when using the 'miter' lineJoin mode. This can reduce
  32993. * or increase the spikiness of rendered text.
  32994. * @param {number} [style.padding=0] - Occasionally some fonts are cropped. Adding some padding will prevent this from
  32995. * happening by adding padding to all sides of the text.
  32996. * @param {string|number} [style.stroke='black'] - A canvas fillstyle that will be used on the text stroke
  32997. * e.g 'blue', '#FCFF00'
  32998. * @param {number} [style.strokeThickness=0] - A number that represents the thickness of the stroke.
  32999. * Default is 0 (no stroke)
  33000. * @param {boolean} [style.trim=false] - Trim transparent borders
  33001. * @param {string} [style.textBaseline='alphabetic'] - The baseline of the text that is rendered.
  33002. * @param {string} [style.whiteSpace='pre'] - Determines whether newlines & spaces are collapsed or preserved "normal"
  33003. * (collapse, collapse), "pre" (preserve, preserve) | "pre-line" (preserve, collapse). It needs wordWrap to be set to true
  33004. * @param {boolean} [style.wordWrap=false] - Indicates if word wrap should be used
  33005. * @param {number} [style.wordWrapWidth=100] - The width at which text will wrap, it needs wordWrap to be set to true
  33006. */
  33007. function TextStyle(style) {
  33008. this.styleID = 0;
  33009. this.reset();
  33010. deepCopyProperties(this, style, style);
  33011. }
  33012. /**
  33013. * Creates a new TextStyle object with the same values as this one.
  33014. * Note that the only the properties of the object are cloned.
  33015. *
  33016. * @return {PIXI.TextStyle} New cloned TextStyle object
  33017. */
  33018. TextStyle.prototype.clone = function () {
  33019. var clonedProperties = {};
  33020. deepCopyProperties(clonedProperties, this, defaultStyle);
  33021. return new TextStyle(clonedProperties);
  33022. };
  33023. /**
  33024. * Resets all properties to the defaults specified in TextStyle.prototype._default
  33025. */
  33026. TextStyle.prototype.reset = function () {
  33027. deepCopyProperties(this, defaultStyle, defaultStyle);
  33028. };
  33029. Object.defineProperty(TextStyle.prototype, "align", {
  33030. /**
  33031. * Alignment for multiline text ('left', 'center' or 'right'), does not affect single line text
  33032. *
  33033. * @member {string}
  33034. */
  33035. get: function () {
  33036. return this._align;
  33037. },
  33038. set: function (align) {
  33039. if (this._align !== align) {
  33040. this._align = align;
  33041. this.styleID++;
  33042. }
  33043. },
  33044. enumerable: false,
  33045. configurable: true
  33046. });
  33047. Object.defineProperty(TextStyle.prototype, "breakWords", {
  33048. /**
  33049. * Indicates if lines can be wrapped within words, it needs wordWrap to be set to true
  33050. *
  33051. * @member {boolean}
  33052. */
  33053. get: function () {
  33054. return this._breakWords;
  33055. },
  33056. set: function (breakWords) {
  33057. if (this._breakWords !== breakWords) {
  33058. this._breakWords = breakWords;
  33059. this.styleID++;
  33060. }
  33061. },
  33062. enumerable: false,
  33063. configurable: true
  33064. });
  33065. Object.defineProperty(TextStyle.prototype, "dropShadow", {
  33066. /**
  33067. * Set a drop shadow for the text
  33068. *
  33069. * @member {boolean}
  33070. */
  33071. get: function () {
  33072. return this._dropShadow;
  33073. },
  33074. set: function (dropShadow) {
  33075. if (this._dropShadow !== dropShadow) {
  33076. this._dropShadow = dropShadow;
  33077. this.styleID++;
  33078. }
  33079. },
  33080. enumerable: false,
  33081. configurable: true
  33082. });
  33083. Object.defineProperty(TextStyle.prototype, "dropShadowAlpha", {
  33084. /**
  33085. * Set alpha for the drop shadow
  33086. *
  33087. * @member {number}
  33088. */
  33089. get: function () {
  33090. return this._dropShadowAlpha;
  33091. },
  33092. set: function (dropShadowAlpha) {
  33093. if (this._dropShadowAlpha !== dropShadowAlpha) {
  33094. this._dropShadowAlpha = dropShadowAlpha;
  33095. this.styleID++;
  33096. }
  33097. },
  33098. enumerable: false,
  33099. configurable: true
  33100. });
  33101. Object.defineProperty(TextStyle.prototype, "dropShadowAngle", {
  33102. /**
  33103. * Set a angle of the drop shadow
  33104. *
  33105. * @member {number}
  33106. */
  33107. get: function () {
  33108. return this._dropShadowAngle;
  33109. },
  33110. set: function (dropShadowAngle) {
  33111. if (this._dropShadowAngle !== dropShadowAngle) {
  33112. this._dropShadowAngle = dropShadowAngle;
  33113. this.styleID++;
  33114. }
  33115. },
  33116. enumerable: false,
  33117. configurable: true
  33118. });
  33119. Object.defineProperty(TextStyle.prototype, "dropShadowBlur", {
  33120. /**
  33121. * Set a shadow blur radius
  33122. *
  33123. * @member {number}
  33124. */
  33125. get: function () {
  33126. return this._dropShadowBlur;
  33127. },
  33128. set: function (dropShadowBlur) {
  33129. if (this._dropShadowBlur !== dropShadowBlur) {
  33130. this._dropShadowBlur = dropShadowBlur;
  33131. this.styleID++;
  33132. }
  33133. },
  33134. enumerable: false,
  33135. configurable: true
  33136. });
  33137. Object.defineProperty(TextStyle.prototype, "dropShadowColor", {
  33138. /**
  33139. * A fill style to be used on the dropshadow e.g 'red', '#00FF00'
  33140. *
  33141. * @member {string|number}
  33142. */
  33143. get: function () {
  33144. return this._dropShadowColor;
  33145. },
  33146. set: function (dropShadowColor) {
  33147. var outputColor = getColor(dropShadowColor);
  33148. if (this._dropShadowColor !== outputColor) {
  33149. this._dropShadowColor = outputColor;
  33150. this.styleID++;
  33151. }
  33152. },
  33153. enumerable: false,
  33154. configurable: true
  33155. });
  33156. Object.defineProperty(TextStyle.prototype, "dropShadowDistance", {
  33157. /**
  33158. * Set a distance of the drop shadow
  33159. *
  33160. * @member {number}
  33161. */
  33162. get: function () {
  33163. return this._dropShadowDistance;
  33164. },
  33165. set: function (dropShadowDistance) {
  33166. if (this._dropShadowDistance !== dropShadowDistance) {
  33167. this._dropShadowDistance = dropShadowDistance;
  33168. this.styleID++;
  33169. }
  33170. },
  33171. enumerable: false,
  33172. configurable: true
  33173. });
  33174. Object.defineProperty(TextStyle.prototype, "fill", {
  33175. /**
  33176. * A canvas fillstyle that will be used on the text e.g 'red', '#00FF00'.
  33177. * Can be an array to create a gradient eg ['#000000','#FFFFFF']
  33178. * {@link https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/fillStyle|MDN}
  33179. *
  33180. * @member {string|string[]|number|number[]|CanvasGradient|CanvasPattern}
  33181. */
  33182. get: function () {
  33183. return this._fill;
  33184. },
  33185. set: function (fill) {
  33186. // TODO: Can't have different types for getter and setter. The getter shouldn't have the number type as
  33187. // the setter converts to string. See this thread for more details:
  33188. // https://github.com/microsoft/TypeScript/issues/2521
  33189. // TODO: Not sure if getColor works properly with CanvasGradient and/or CanvasPattern, can't pass in
  33190. // without casting here.
  33191. var outputColor = getColor(fill);
  33192. if (this._fill !== outputColor) {
  33193. this._fill = outputColor;
  33194. this.styleID++;
  33195. }
  33196. },
  33197. enumerable: false,
  33198. configurable: true
  33199. });
  33200. Object.defineProperty(TextStyle.prototype, "fillGradientType", {
  33201. /**
  33202. * If fill is an array of colours to create a gradient, this can change the type/direction of the gradient.
  33203. * See {@link PIXI.TEXT_GRADIENT}
  33204. *
  33205. * @member {number}
  33206. */
  33207. get: function () {
  33208. return this._fillGradientType;
  33209. },
  33210. set: function (fillGradientType) {
  33211. if (this._fillGradientType !== fillGradientType) {
  33212. this._fillGradientType = fillGradientType;
  33213. this.styleID++;
  33214. }
  33215. },
  33216. enumerable: false,
  33217. configurable: true
  33218. });
  33219. Object.defineProperty(TextStyle.prototype, "fillGradientStops", {
  33220. /**
  33221. * If fill is an array of colours to create a gradient, this array can set the stop points
  33222. * (numbers between 0 and 1) for the color, overriding the default behaviour of evenly spacing them.
  33223. *
  33224. * @member {number[]}
  33225. */
  33226. get: function () {
  33227. return this._fillGradientStops;
  33228. },
  33229. set: function (fillGradientStops) {
  33230. if (!areArraysEqual(this._fillGradientStops, fillGradientStops)) {
  33231. this._fillGradientStops = fillGradientStops;
  33232. this.styleID++;
  33233. }
  33234. },
  33235. enumerable: false,
  33236. configurable: true
  33237. });
  33238. Object.defineProperty(TextStyle.prototype, "fontFamily", {
  33239. /**
  33240. * The font family
  33241. *
  33242. * @member {string|string[]}
  33243. */
  33244. get: function () {
  33245. return this._fontFamily;
  33246. },
  33247. set: function (fontFamily) {
  33248. if (this.fontFamily !== fontFamily) {
  33249. this._fontFamily = fontFamily;
  33250. this.styleID++;
  33251. }
  33252. },
  33253. enumerable: false,
  33254. configurable: true
  33255. });
  33256. Object.defineProperty(TextStyle.prototype, "fontSize", {
  33257. /**
  33258. * The font size
  33259. * (as a number it converts to px, but as a string, equivalents are '26px','20pt','160%' or '1.6em')
  33260. *
  33261. * @member {number|string}
  33262. */
  33263. get: function () {
  33264. return this._fontSize;
  33265. },
  33266. set: function (fontSize) {
  33267. if (this._fontSize !== fontSize) {
  33268. this._fontSize = fontSize;
  33269. this.styleID++;
  33270. }
  33271. },
  33272. enumerable: false,
  33273. configurable: true
  33274. });
  33275. Object.defineProperty(TextStyle.prototype, "fontStyle", {
  33276. /**
  33277. * The font style
  33278. * ('normal', 'italic' or 'oblique')
  33279. *
  33280. * @member {string}
  33281. */
  33282. get: function () {
  33283. return this._fontStyle;
  33284. },
  33285. set: function (fontStyle) {
  33286. if (this._fontStyle !== fontStyle) {
  33287. this._fontStyle = fontStyle;
  33288. this.styleID++;
  33289. }
  33290. },
  33291. enumerable: false,
  33292. configurable: true
  33293. });
  33294. Object.defineProperty(TextStyle.prototype, "fontVariant", {
  33295. /**
  33296. * The font variant
  33297. * ('normal' or 'small-caps')
  33298. *
  33299. * @member {string}
  33300. */
  33301. get: function () {
  33302. return this._fontVariant;
  33303. },
  33304. set: function (fontVariant) {
  33305. if (this._fontVariant !== fontVariant) {
  33306. this._fontVariant = fontVariant;
  33307. this.styleID++;
  33308. }
  33309. },
  33310. enumerable: false,
  33311. configurable: true
  33312. });
  33313. Object.defineProperty(TextStyle.prototype, "fontWeight", {
  33314. /**
  33315. * The font weight
  33316. * ('normal', 'bold', 'bolder', 'lighter' and '100', '200', '300', '400', '500', '600', '700', 800' or '900')
  33317. *
  33318. * @member {string}
  33319. */
  33320. get: function () {
  33321. return this._fontWeight;
  33322. },
  33323. set: function (fontWeight) {
  33324. if (this._fontWeight !== fontWeight) {
  33325. this._fontWeight = fontWeight;
  33326. this.styleID++;
  33327. }
  33328. },
  33329. enumerable: false,
  33330. configurable: true
  33331. });
  33332. Object.defineProperty(TextStyle.prototype, "letterSpacing", {
  33333. /**
  33334. * The amount of spacing between letters, default is 0
  33335. *
  33336. * @member {number}
  33337. */
  33338. get: function () {
  33339. return this._letterSpacing;
  33340. },
  33341. set: function (letterSpacing) {
  33342. if (this._letterSpacing !== letterSpacing) {
  33343. this._letterSpacing = letterSpacing;
  33344. this.styleID++;
  33345. }
  33346. },
  33347. enumerable: false,
  33348. configurable: true
  33349. });
  33350. Object.defineProperty(TextStyle.prototype, "lineHeight", {
  33351. /**
  33352. * The line height, a number that represents the vertical space that a letter uses
  33353. *
  33354. * @member {number}
  33355. */
  33356. get: function () {
  33357. return this._lineHeight;
  33358. },
  33359. set: function (lineHeight) {
  33360. if (this._lineHeight !== lineHeight) {
  33361. this._lineHeight = lineHeight;
  33362. this.styleID++;
  33363. }
  33364. },
  33365. enumerable: false,
  33366. configurable: true
  33367. });
  33368. Object.defineProperty(TextStyle.prototype, "leading", {
  33369. /**
  33370. * The space between lines
  33371. *
  33372. * @member {number}
  33373. */
  33374. get: function () {
  33375. return this._leading;
  33376. },
  33377. set: function (leading) {
  33378. if (this._leading !== leading) {
  33379. this._leading = leading;
  33380. this.styleID++;
  33381. }
  33382. },
  33383. enumerable: false,
  33384. configurable: true
  33385. });
  33386. Object.defineProperty(TextStyle.prototype, "lineJoin", {
  33387. /**
  33388. * The lineJoin property sets the type of corner created, it can resolve spiked text issues.
  33389. * Default is 'miter' (creates a sharp corner).
  33390. *
  33391. * @member {string}
  33392. */
  33393. get: function () {
  33394. return this._lineJoin;
  33395. },
  33396. set: function (lineJoin) {
  33397. if (this._lineJoin !== lineJoin) {
  33398. this._lineJoin = lineJoin;
  33399. this.styleID++;
  33400. }
  33401. },
  33402. enumerable: false,
  33403. configurable: true
  33404. });
  33405. Object.defineProperty(TextStyle.prototype, "miterLimit", {
  33406. /**
  33407. * The miter limit to use when using the 'miter' lineJoin mode
  33408. * This can reduce or increase the spikiness of rendered text.
  33409. *
  33410. * @member {number}
  33411. */
  33412. get: function () {
  33413. return this._miterLimit;
  33414. },
  33415. set: function (miterLimit) {
  33416. if (this._miterLimit !== miterLimit) {
  33417. this._miterLimit = miterLimit;
  33418. this.styleID++;
  33419. }
  33420. },
  33421. enumerable: false,
  33422. configurable: true
  33423. });
  33424. Object.defineProperty(TextStyle.prototype, "padding", {
  33425. /**
  33426. * Occasionally some fonts are cropped. Adding some padding will prevent this from happening
  33427. * by adding padding to all sides of the text.
  33428. *
  33429. * @member {number}
  33430. */
  33431. get: function () {
  33432. return this._padding;
  33433. },
  33434. set: function (padding) {
  33435. if (this._padding !== padding) {
  33436. this._padding = padding;
  33437. this.styleID++;
  33438. }
  33439. },
  33440. enumerable: false,
  33441. configurable: true
  33442. });
  33443. Object.defineProperty(TextStyle.prototype, "stroke", {
  33444. /**
  33445. * A canvas fillstyle that will be used on the text stroke
  33446. * e.g 'blue', '#FCFF00'
  33447. *
  33448. * @member {string|number}
  33449. */
  33450. get: function () {
  33451. return this._stroke;
  33452. },
  33453. set: function (stroke) {
  33454. // TODO: Can't have different types for getter and setter. The getter shouldn't have the number type as
  33455. // the setter converts to string. See this thread for more details:
  33456. // https://github.com/microsoft/TypeScript/issues/2521
  33457. var outputColor = getColor(stroke);
  33458. if (this._stroke !== outputColor) {
  33459. this._stroke = outputColor;
  33460. this.styleID++;
  33461. }
  33462. },
  33463. enumerable: false,
  33464. configurable: true
  33465. });
  33466. Object.defineProperty(TextStyle.prototype, "strokeThickness", {
  33467. /**
  33468. * A number that represents the thickness of the stroke.
  33469. * Default is 0 (no stroke)
  33470. *
  33471. * @member {number}
  33472. */
  33473. get: function () {
  33474. return this._strokeThickness;
  33475. },
  33476. set: function (strokeThickness) {
  33477. if (this._strokeThickness !== strokeThickness) {
  33478. this._strokeThickness = strokeThickness;
  33479. this.styleID++;
  33480. }
  33481. },
  33482. enumerable: false,
  33483. configurable: true
  33484. });
  33485. Object.defineProperty(TextStyle.prototype, "textBaseline", {
  33486. /**
  33487. * The baseline of the text that is rendered.
  33488. *
  33489. * @member {string}
  33490. */
  33491. get: function () {
  33492. return this._textBaseline;
  33493. },
  33494. set: function (textBaseline) {
  33495. if (this._textBaseline !== textBaseline) {
  33496. this._textBaseline = textBaseline;
  33497. this.styleID++;
  33498. }
  33499. },
  33500. enumerable: false,
  33501. configurable: true
  33502. });
  33503. Object.defineProperty(TextStyle.prototype, "trim", {
  33504. /**
  33505. * Trim transparent borders
  33506. *
  33507. * @member {boolean}
  33508. */
  33509. get: function () {
  33510. return this._trim;
  33511. },
  33512. set: function (trim) {
  33513. if (this._trim !== trim) {
  33514. this._trim = trim;
  33515. this.styleID++;
  33516. }
  33517. },
  33518. enumerable: false,
  33519. configurable: true
  33520. });
  33521. Object.defineProperty(TextStyle.prototype, "whiteSpace", {
  33522. /**
  33523. * How newlines and spaces should be handled.
  33524. * Default is 'pre' (preserve, preserve).
  33525. *
  33526. * value | New lines | Spaces
  33527. * --- | --- | ---
  33528. * 'normal' | Collapse | Collapse
  33529. * 'pre' | Preserve | Preserve
  33530. * 'pre-line' | Preserve | Collapse
  33531. *
  33532. * @member {string}
  33533. */
  33534. get: function () {
  33535. return this._whiteSpace;
  33536. },
  33537. set: function (whiteSpace) {
  33538. if (this._whiteSpace !== whiteSpace) {
  33539. this._whiteSpace = whiteSpace;
  33540. this.styleID++;
  33541. }
  33542. },
  33543. enumerable: false,
  33544. configurable: true
  33545. });
  33546. Object.defineProperty(TextStyle.prototype, "wordWrap", {
  33547. /**
  33548. * Indicates if word wrap should be used
  33549. *
  33550. * @member {boolean}
  33551. */
  33552. get: function () {
  33553. return this._wordWrap;
  33554. },
  33555. set: function (wordWrap) {
  33556. if (this._wordWrap !== wordWrap) {
  33557. this._wordWrap = wordWrap;
  33558. this.styleID++;
  33559. }
  33560. },
  33561. enumerable: false,
  33562. configurable: true
  33563. });
  33564. Object.defineProperty(TextStyle.prototype, "wordWrapWidth", {
  33565. /**
  33566. * The width at which text will wrap, it needs wordWrap to be set to true
  33567. *
  33568. * @member {number}
  33569. */
  33570. get: function () {
  33571. return this._wordWrapWidth;
  33572. },
  33573. set: function (wordWrapWidth) {
  33574. if (this._wordWrapWidth !== wordWrapWidth) {
  33575. this._wordWrapWidth = wordWrapWidth;
  33576. this.styleID++;
  33577. }
  33578. },
  33579. enumerable: false,
  33580. configurable: true
  33581. });
  33582. /**
  33583. * Generates a font style string to use for `TextMetrics.measureFont()`.
  33584. *
  33585. * @return {string} Font style string, for passing to `TextMetrics.measureFont()`
  33586. */
  33587. TextStyle.prototype.toFontString = function () {
  33588. // build canvas api font setting from individual components. Convert a numeric this.fontSize to px
  33589. var fontSizeString = (typeof this.fontSize === 'number') ? this.fontSize + "px" : this.fontSize;
  33590. // Clean-up fontFamily property by quoting each font name
  33591. // this will support font names with spaces
  33592. var fontFamilies = this.fontFamily;
  33593. if (!Array.isArray(this.fontFamily)) {
  33594. fontFamilies = this.fontFamily.split(',');
  33595. }
  33596. for (var i = fontFamilies.length - 1; i >= 0; i--) {
  33597. // Trim any extra white-space
  33598. var fontFamily = fontFamilies[i].trim();
  33599. // Check if font already contains strings
  33600. if (!(/([\"\'])[^\'\"]+\1/).test(fontFamily) && genericFontFamilies.indexOf(fontFamily) < 0) {
  33601. fontFamily = "\"" + fontFamily + "\"";
  33602. }
  33603. fontFamilies[i] = fontFamily;
  33604. }
  33605. return this.fontStyle + " " + this.fontVariant + " " + this.fontWeight + " " + fontSizeString + " " + fontFamilies.join(',');
  33606. };
  33607. return TextStyle;
  33608. }());
  33609. /**
  33610. * Utility function to convert hexadecimal colors to strings, and simply return the color if it's a string.
  33611. * @private
  33612. * @param {string|number} color
  33613. * @return {string} The color as a string.
  33614. */
  33615. function getSingleColor(color) {
  33616. if (typeof color === 'number') {
  33617. return hex2string(color);
  33618. }
  33619. else if (typeof color === 'string') {
  33620. if (color.indexOf('0x') === 0) {
  33621. color = color.replace('0x', '#');
  33622. }
  33623. }
  33624. return color;
  33625. }
  33626. function getColor(color) {
  33627. if (!Array.isArray(color)) {
  33628. return getSingleColor(color);
  33629. }
  33630. else {
  33631. for (var i = 0; i < color.length; ++i) {
  33632. color[i] = getSingleColor(color[i]);
  33633. }
  33634. return color;
  33635. }
  33636. }
  33637. /**
  33638. * Utility function to convert hexadecimal colors to strings, and simply return the color if it's a string.
  33639. * This version can also convert array of colors
  33640. * @private
  33641. * @param {Array} array1 - First array to compare
  33642. * @param {Array} array2 - Second array to compare
  33643. * @return {boolean} Do the arrays contain the same values in the same order
  33644. */
  33645. function areArraysEqual(array1, array2) {
  33646. if (!Array.isArray(array1) || !Array.isArray(array2)) {
  33647. return false;
  33648. }
  33649. if (array1.length !== array2.length) {
  33650. return false;
  33651. }
  33652. for (var i = 0; i < array1.length; ++i) {
  33653. if (array1[i] !== array2[i]) {
  33654. return false;
  33655. }
  33656. }
  33657. return true;
  33658. }
  33659. /**
  33660. * Utility function to ensure that object properties are copied by value, and not by reference
  33661. * @private
  33662. * @param {Object} target - Target object to copy properties into
  33663. * @param {Object} source - Source object for the properties to copy
  33664. * @param {string} propertyObj - Object containing properties names we want to loop over
  33665. */
  33666. function deepCopyProperties(target, source, propertyObj) {
  33667. for (var prop in propertyObj) {
  33668. if (Array.isArray(source[prop])) {
  33669. target[prop] = source[prop].slice();
  33670. }
  33671. else {
  33672. target[prop] = source[prop];
  33673. }
  33674. }
  33675. }
  33676. /**
  33677. * The TextMetrics object represents the measurement of a block of text with a specified style.
  33678. *
  33679. * ```js
  33680. * let style = new PIXI.TextStyle({fontFamily : 'Arial', fontSize: 24, fill : 0xff1010, align : 'center'})
  33681. * let textMetrics = PIXI.TextMetrics.measureText('Your text', style)
  33682. * ```
  33683. *
  33684. * @class
  33685. * @memberof PIXI
  33686. */
  33687. var TextMetrics = /** @class */ (function () {
  33688. /**
  33689. * @param {string} text - the text that was measured
  33690. * @param {PIXI.TextStyle} style - the style that was measured
  33691. * @param {number} width - the measured width of the text
  33692. * @param {number} height - the measured height of the text
  33693. * @param {string[]} lines - an array of the lines of text broken by new lines and wrapping if specified in style
  33694. * @param {number[]} lineWidths - an array of the line widths for each line matched to `lines`
  33695. * @param {number} lineHeight - the measured line height for this style
  33696. * @param {number} maxLineWidth - the maximum line width for all measured lines
  33697. * @param {Object} fontProperties - the font properties object from TextMetrics.measureFont
  33698. */
  33699. function TextMetrics(text, style, width, height, lines, lineWidths, lineHeight, maxLineWidth, fontProperties) {
  33700. /**
  33701. * The text that was measured
  33702. *
  33703. * @member {string}
  33704. */
  33705. this.text = text;
  33706. /**
  33707. * The style that was measured
  33708. *
  33709. * @member {PIXI.TextStyle}
  33710. */
  33711. this.style = style;
  33712. /**
  33713. * The measured width of the text
  33714. *
  33715. * @member {number}
  33716. */
  33717. this.width = width;
  33718. /**
  33719. * The measured height of the text
  33720. *
  33721. * @member {number}
  33722. */
  33723. this.height = height;
  33724. /**
  33725. * An array of lines of the text broken by new lines and wrapping is specified in style
  33726. *
  33727. * @member {string[]}
  33728. */
  33729. this.lines = lines;
  33730. /**
  33731. * An array of the line widths for each line matched to `lines`
  33732. *
  33733. * @member {number[]}
  33734. */
  33735. this.lineWidths = lineWidths;
  33736. /**
  33737. * The measured line height for this style
  33738. *
  33739. * @member {number}
  33740. */
  33741. this.lineHeight = lineHeight;
  33742. /**
  33743. * The maximum line width for all measured lines
  33744. *
  33745. * @member {number}
  33746. */
  33747. this.maxLineWidth = maxLineWidth;
  33748. /**
  33749. * The font properties object from TextMetrics.measureFont
  33750. *
  33751. * @member {PIXI.IFontMetrics}
  33752. */
  33753. this.fontProperties = fontProperties;
  33754. }
  33755. /**
  33756. * Measures the supplied string of text and returns a Rectangle.
  33757. *
  33758. * @param {string} text - the text to measure.
  33759. * @param {PIXI.TextStyle} style - the text style to use for measuring
  33760. * @param {boolean} [wordWrap] - optional override for if word-wrap should be applied to the text.
  33761. * @param {HTMLCanvasElement} [canvas] - optional specification of the canvas to use for measuring.
  33762. * @return {PIXI.TextMetrics} measured width and height of the text.
  33763. */
  33764. TextMetrics.measureText = function (text, style, wordWrap, canvas) {
  33765. if (canvas === void 0) { canvas = TextMetrics._canvas; }
  33766. wordWrap = (wordWrap === undefined || wordWrap === null) ? style.wordWrap : wordWrap;
  33767. var font = style.toFontString();
  33768. var fontProperties = TextMetrics.measureFont(font);
  33769. // fallback in case UA disallow canvas data extraction
  33770. // (toDataURI, getImageData functions)
  33771. if (fontProperties.fontSize === 0) {
  33772. fontProperties.fontSize = style.fontSize;
  33773. fontProperties.ascent = style.fontSize;
  33774. }
  33775. var context = canvas.getContext('2d');
  33776. context.font = font;
  33777. var outputText = wordWrap ? TextMetrics.wordWrap(text, style, canvas) : text;
  33778. var lines = outputText.split(/(?:\r\n|\r|\n)/);
  33779. var lineWidths = new Array(lines.length);
  33780. var maxLineWidth = 0;
  33781. for (var i = 0; i < lines.length; i++) {
  33782. var lineWidth = context.measureText(lines[i]).width + ((lines[i].length - 1) * style.letterSpacing);
  33783. lineWidths[i] = lineWidth;
  33784. maxLineWidth = Math.max(maxLineWidth, lineWidth);
  33785. }
  33786. var width = maxLineWidth + style.strokeThickness;
  33787. if (style.dropShadow) {
  33788. width += style.dropShadowDistance;
  33789. }
  33790. var lineHeight = style.lineHeight || fontProperties.fontSize + style.strokeThickness;
  33791. var height = Math.max(lineHeight, fontProperties.fontSize + style.strokeThickness)
  33792. + ((lines.length - 1) * (lineHeight + style.leading));
  33793. if (style.dropShadow) {
  33794. height += style.dropShadowDistance;
  33795. }
  33796. return new TextMetrics(text, style, width, height, lines, lineWidths, lineHeight + style.leading, maxLineWidth, fontProperties);
  33797. };
  33798. /**
  33799. * Applies newlines to a string to have it optimally fit into the horizontal
  33800. * bounds set by the Text object's wordWrapWidth property.
  33801. *
  33802. * @private
  33803. * @param {string} text - String to apply word wrapping to
  33804. * @param {PIXI.TextStyle} style - the style to use when wrapping
  33805. * @param {HTMLCanvasElement} [canvas] - optional specification of the canvas to use for measuring.
  33806. * @return {string} New string with new lines applied where required
  33807. */
  33808. TextMetrics.wordWrap = function (text, style, canvas) {
  33809. if (canvas === void 0) { canvas = TextMetrics._canvas; }
  33810. var context = canvas.getContext('2d');
  33811. var width = 0;
  33812. var line = '';
  33813. var lines = '';
  33814. var cache = Object.create(null);
  33815. var letterSpacing = style.letterSpacing, whiteSpace = style.whiteSpace;
  33816. // How to handle whitespaces
  33817. var collapseSpaces = TextMetrics.collapseSpaces(whiteSpace);
  33818. var collapseNewlines = TextMetrics.collapseNewlines(whiteSpace);
  33819. // whether or not spaces may be added to the beginning of lines
  33820. var canPrependSpaces = !collapseSpaces;
  33821. // There is letterSpacing after every char except the last one
  33822. // t_h_i_s_' '_i_s_' '_a_n_' '_e_x_a_m_p_l_e_' '_!
  33823. // so for convenience the above needs to be compared to width + 1 extra letterSpace
  33824. // t_h_i_s_' '_i_s_' '_a_n_' '_e_x_a_m_p_l_e_' '_!_
  33825. // ________________________________________________
  33826. // And then the final space is simply no appended to each line
  33827. var wordWrapWidth = style.wordWrapWidth + letterSpacing;
  33828. // break text into words, spaces and newline chars
  33829. var tokens = TextMetrics.tokenize(text);
  33830. for (var i = 0; i < tokens.length; i++) {
  33831. // get the word, space or newlineChar
  33832. var token = tokens[i];
  33833. // if word is a new line
  33834. if (TextMetrics.isNewline(token)) {
  33835. // keep the new line
  33836. if (!collapseNewlines) {
  33837. lines += TextMetrics.addLine(line);
  33838. canPrependSpaces = !collapseSpaces;
  33839. line = '';
  33840. width = 0;
  33841. continue;
  33842. }
  33843. // if we should collapse new lines
  33844. // we simply convert it into a space
  33845. token = ' ';
  33846. }
  33847. // if we should collapse repeated whitespaces
  33848. if (collapseSpaces) {
  33849. // check both this and the last tokens for spaces
  33850. var currIsBreakingSpace = TextMetrics.isBreakingSpace(token);
  33851. var lastIsBreakingSpace = TextMetrics.isBreakingSpace(line[line.length - 1]);
  33852. if (currIsBreakingSpace && lastIsBreakingSpace) {
  33853. continue;
  33854. }
  33855. }
  33856. // get word width from cache if possible
  33857. var tokenWidth = TextMetrics.getFromCache(token, letterSpacing, cache, context);
  33858. // word is longer than desired bounds
  33859. if (tokenWidth > wordWrapWidth) {
  33860. // if we are not already at the beginning of a line
  33861. if (line !== '') {
  33862. // start newlines for overflow words
  33863. lines += TextMetrics.addLine(line);
  33864. line = '';
  33865. width = 0;
  33866. }
  33867. // break large word over multiple lines
  33868. if (TextMetrics.canBreakWords(token, style.breakWords)) {
  33869. // break word into characters
  33870. var characters = TextMetrics.wordWrapSplit(token);
  33871. // loop the characters
  33872. for (var j = 0; j < characters.length; j++) {
  33873. var char = characters[j];
  33874. var k = 1;
  33875. // we are not at the end of the token
  33876. while (characters[j + k]) {
  33877. var nextChar = characters[j + k];
  33878. var lastChar = char[char.length - 1];
  33879. // should not split chars
  33880. if (!TextMetrics.canBreakChars(lastChar, nextChar, token, j, style.breakWords)) {
  33881. // combine chars & move forward one
  33882. char += nextChar;
  33883. }
  33884. else {
  33885. break;
  33886. }
  33887. k++;
  33888. }
  33889. j += char.length - 1;
  33890. var characterWidth = TextMetrics.getFromCache(char, letterSpacing, cache, context);
  33891. if (characterWidth + width > wordWrapWidth) {
  33892. lines += TextMetrics.addLine(line);
  33893. canPrependSpaces = false;
  33894. line = '';
  33895. width = 0;
  33896. }
  33897. line += char;
  33898. width += characterWidth;
  33899. }
  33900. }
  33901. // run word out of the bounds
  33902. else {
  33903. // if there are words in this line already
  33904. // finish that line and start a new one
  33905. if (line.length > 0) {
  33906. lines += TextMetrics.addLine(line);
  33907. line = '';
  33908. width = 0;
  33909. }
  33910. var isLastToken = i === tokens.length - 1;
  33911. // give it its own line if it's not the end
  33912. lines += TextMetrics.addLine(token, !isLastToken);
  33913. canPrependSpaces = false;
  33914. line = '';
  33915. width = 0;
  33916. }
  33917. }
  33918. // word could fit
  33919. else {
  33920. // word won't fit because of existing words
  33921. // start a new line
  33922. if (tokenWidth + width > wordWrapWidth) {
  33923. // if its a space we don't want it
  33924. canPrependSpaces = false;
  33925. // add a new line
  33926. lines += TextMetrics.addLine(line);
  33927. // start a new line
  33928. line = '';
  33929. width = 0;
  33930. }
  33931. // don't add spaces to the beginning of lines
  33932. if (line.length > 0 || !TextMetrics.isBreakingSpace(token) || canPrependSpaces) {
  33933. // add the word to the current line
  33934. line += token;
  33935. // update width counter
  33936. width += tokenWidth;
  33937. }
  33938. }
  33939. }
  33940. lines += TextMetrics.addLine(line, false);
  33941. return lines;
  33942. };
  33943. /**
  33944. * Convienience function for logging each line added during the wordWrap
  33945. * method
  33946. *
  33947. * @private
  33948. * @param {string} line - The line of text to add
  33949. * @param {boolean} newLine - Add new line character to end
  33950. * @return {string} A formatted line
  33951. */
  33952. TextMetrics.addLine = function (line, newLine) {
  33953. if (newLine === void 0) { newLine = true; }
  33954. line = TextMetrics.trimRight(line);
  33955. line = (newLine) ? line + "\n" : line;
  33956. return line;
  33957. };
  33958. /**
  33959. * Gets & sets the widths of calculated characters in a cache object
  33960. *
  33961. * @private
  33962. * @param {string} key - The key
  33963. * @param {number} letterSpacing - The letter spacing
  33964. * @param {object} cache - The cache
  33965. * @param {CanvasRenderingContext2D} context - The canvas context
  33966. * @return {number} The from cache.
  33967. */
  33968. TextMetrics.getFromCache = function (key, letterSpacing, cache, context) {
  33969. var width = cache[key];
  33970. if (typeof width !== 'number') {
  33971. var spacing = ((key.length) * letterSpacing);
  33972. width = context.measureText(key).width + spacing;
  33973. cache[key] = width;
  33974. }
  33975. return width;
  33976. };
  33977. /**
  33978. * Determines whether we should collapse breaking spaces
  33979. *
  33980. * @private
  33981. * @param {string} whiteSpace - The TextStyle property whiteSpace
  33982. * @return {boolean} should collapse
  33983. */
  33984. TextMetrics.collapseSpaces = function (whiteSpace) {
  33985. return (whiteSpace === 'normal' || whiteSpace === 'pre-line');
  33986. };
  33987. /**
  33988. * Determines whether we should collapse newLine chars
  33989. *
  33990. * @private
  33991. * @param {string} whiteSpace - The white space
  33992. * @return {boolean} should collapse
  33993. */
  33994. TextMetrics.collapseNewlines = function (whiteSpace) {
  33995. return (whiteSpace === 'normal');
  33996. };
  33997. /**
  33998. * trims breaking whitespaces from string
  33999. *
  34000. * @private
  34001. * @param {string} text - The text
  34002. * @return {string} trimmed string
  34003. */
  34004. TextMetrics.trimRight = function (text) {
  34005. if (typeof text !== 'string') {
  34006. return '';
  34007. }
  34008. for (var i = text.length - 1; i >= 0; i--) {
  34009. var char = text[i];
  34010. if (!TextMetrics.isBreakingSpace(char)) {
  34011. break;
  34012. }
  34013. text = text.slice(0, -1);
  34014. }
  34015. return text;
  34016. };
  34017. /**
  34018. * Determines if char is a newline.
  34019. *
  34020. * @private
  34021. * @param {string} char - The character
  34022. * @return {boolean} True if newline, False otherwise.
  34023. */
  34024. TextMetrics.isNewline = function (char) {
  34025. if (typeof char !== 'string') {
  34026. return false;
  34027. }
  34028. return (TextMetrics._newlines.indexOf(char.charCodeAt(0)) >= 0);
  34029. };
  34030. /**
  34031. * Determines if char is a breaking whitespace.
  34032. *
  34033. * It allows one to determine whether char should be a breaking whitespace
  34034. * For example certain characters in CJK langs or numbers.
  34035. * It must return a boolean.
  34036. *
  34037. * @param {string} char - The character
  34038. * @param {string} [nextChar] - The next character
  34039. * @return {boolean} True if whitespace, False otherwise.
  34040. */
  34041. TextMetrics.isBreakingSpace = function (char, _nextChar) {
  34042. if (typeof char !== 'string') {
  34043. return false;
  34044. }
  34045. return (TextMetrics._breakingSpaces.indexOf(char.charCodeAt(0)) >= 0);
  34046. };
  34047. /**
  34048. * Splits a string into words, breaking-spaces and newLine characters
  34049. *
  34050. * @private
  34051. * @param {string} text - The text
  34052. * @return {string[]} A tokenized array
  34053. */
  34054. TextMetrics.tokenize = function (text) {
  34055. var tokens = [];
  34056. var token = '';
  34057. if (typeof text !== 'string') {
  34058. return tokens;
  34059. }
  34060. for (var i = 0; i < text.length; i++) {
  34061. var char = text[i];
  34062. var nextChar = text[i + 1];
  34063. if (TextMetrics.isBreakingSpace(char, nextChar) || TextMetrics.isNewline(char)) {
  34064. if (token !== '') {
  34065. tokens.push(token);
  34066. token = '';
  34067. }
  34068. tokens.push(char);
  34069. continue;
  34070. }
  34071. token += char;
  34072. }
  34073. if (token !== '') {
  34074. tokens.push(token);
  34075. }
  34076. return tokens;
  34077. };
  34078. /**
  34079. * Overridable helper method used internally by TextMetrics, exposed to allow customizing the class's behavior.
  34080. *
  34081. * It allows one to customise which words should break
  34082. * Examples are if the token is CJK or numbers.
  34083. * It must return a boolean.
  34084. *
  34085. * @param {string} token - The token
  34086. * @param {boolean} breakWords - The style attr break words
  34087. * @return {boolean} whether to break word or not
  34088. */
  34089. TextMetrics.canBreakWords = function (_token, breakWords) {
  34090. return breakWords;
  34091. };
  34092. /**
  34093. * Overridable helper method used internally by TextMetrics, exposed to allow customizing the class's behavior.
  34094. *
  34095. * It allows one to determine whether a pair of characters
  34096. * should be broken by newlines
  34097. * For example certain characters in CJK langs or numbers.
  34098. * It must return a boolean.
  34099. *
  34100. * @param {string} char - The character
  34101. * @param {string} nextChar - The next character
  34102. * @param {string} token - The token/word the characters are from
  34103. * @param {number} index - The index in the token of the char
  34104. * @param {boolean} breakWords - The style attr break words
  34105. * @return {boolean} whether to break word or not
  34106. */
  34107. TextMetrics.canBreakChars = function (_char, _nextChar, _token, _index, _breakWords) {
  34108. return true;
  34109. };
  34110. /**
  34111. * Overridable helper method used internally by TextMetrics, exposed to allow customizing the class's behavior.
  34112. *
  34113. * It is called when a token (usually a word) has to be split into separate pieces
  34114. * in order to determine the point to break a word.
  34115. * It must return an array of characters.
  34116. *
  34117. * @example
  34118. * // Correctly splits emojis, eg "🤪🤪" will result in two element array, each with one emoji.
  34119. * TextMetrics.wordWrapSplit = (token) => [...token];
  34120. *
  34121. * @param {string} token - The token to split
  34122. * @return {string[]} The characters of the token
  34123. */
  34124. TextMetrics.wordWrapSplit = function (token) {
  34125. return token.split('');
  34126. };
  34127. /**
  34128. * Calculates the ascent, descent and fontSize of a given font-style
  34129. *
  34130. * @static
  34131. * @param {string} font - String representing the style of the font
  34132. * @return {PIXI.IFontMetrics} Font properties object
  34133. */
  34134. TextMetrics.measureFont = function (font) {
  34135. // as this method is used for preparing assets, don't recalculate things if we don't need to
  34136. if (TextMetrics._fonts[font]) {
  34137. return TextMetrics._fonts[font];
  34138. }
  34139. var properties = {
  34140. ascent: 0,
  34141. descent: 0,
  34142. fontSize: 0,
  34143. };
  34144. var canvas = TextMetrics._canvas;
  34145. var context = TextMetrics._context;
  34146. context.font = font;
  34147. var metricsString = TextMetrics.METRICS_STRING + TextMetrics.BASELINE_SYMBOL;
  34148. var width = Math.ceil(context.measureText(metricsString).width);
  34149. var baseline = Math.ceil(context.measureText(TextMetrics.BASELINE_SYMBOL).width);
  34150. var height = Math.ceil(TextMetrics.HEIGHT_MULTIPLIER * baseline);
  34151. baseline = baseline * TextMetrics.BASELINE_MULTIPLIER | 0;
  34152. canvas.width = width;
  34153. canvas.height = height;
  34154. context.fillStyle = '#f00';
  34155. context.fillRect(0, 0, width, height);
  34156. context.font = font;
  34157. context.textBaseline = 'alphabetic';
  34158. context.fillStyle = '#000';
  34159. context.fillText(metricsString, 0, baseline);
  34160. var imagedata = context.getImageData(0, 0, width, height).data;
  34161. var pixels = imagedata.length;
  34162. var line = width * 4;
  34163. var i = 0;
  34164. var idx = 0;
  34165. var stop = false;
  34166. // ascent. scan from top to bottom until we find a non red pixel
  34167. for (i = 0; i < baseline; ++i) {
  34168. for (var j = 0; j < line; j += 4) {
  34169. if (imagedata[idx + j] !== 255) {
  34170. stop = true;
  34171. break;
  34172. }
  34173. }
  34174. if (!stop) {
  34175. idx += line;
  34176. }
  34177. else {
  34178. break;
  34179. }
  34180. }
  34181. properties.ascent = baseline - i;
  34182. idx = pixels - line;
  34183. stop = false;
  34184. // descent. scan from bottom to top until we find a non red pixel
  34185. for (i = height; i > baseline; --i) {
  34186. for (var j = 0; j < line; j += 4) {
  34187. if (imagedata[idx + j] !== 255) {
  34188. stop = true;
  34189. break;
  34190. }
  34191. }
  34192. if (!stop) {
  34193. idx -= line;
  34194. }
  34195. else {
  34196. break;
  34197. }
  34198. }
  34199. properties.descent = i - baseline;
  34200. properties.fontSize = properties.ascent + properties.descent;
  34201. TextMetrics._fonts[font] = properties;
  34202. return properties;
  34203. };
  34204. /**
  34205. * Clear font metrics in metrics cache.
  34206. *
  34207. * @static
  34208. * @param {string} [font] - font name. If font name not set then clear cache for all fonts.
  34209. */
  34210. TextMetrics.clearMetrics = function (font) {
  34211. if (font === void 0) { font = ''; }
  34212. if (font) {
  34213. delete TextMetrics._fonts[font];
  34214. }
  34215. else {
  34216. TextMetrics._fonts = {};
  34217. }
  34218. };
  34219. return TextMetrics;
  34220. }());
  34221. /**
  34222. * Internal return object for {@link PIXI.TextMetrics.measureFont `TextMetrics.measureFont`}.
  34223. *
  34224. * @typedef {object} FontMetrics
  34225. * @property {number} ascent - The ascent distance
  34226. * @property {number} descent - The descent distance
  34227. * @property {number} fontSize - Font size from ascent to descent
  34228. * @memberof PIXI.TextMetrics
  34229. * @private
  34230. */
  34231. var canvas = (function () {
  34232. try {
  34233. // OffscreenCanvas2D measureText can be up to 40% faster.
  34234. var c = new OffscreenCanvas(0, 0);
  34235. var context = c.getContext('2d');
  34236. if (context && context.measureText) {
  34237. return c;
  34238. }
  34239. return document.createElement('canvas');
  34240. }
  34241. catch (ex) {
  34242. return document.createElement('canvas');
  34243. }
  34244. })();
  34245. canvas.width = canvas.height = 10;
  34246. /**
  34247. * Cached canvas element for measuring text
  34248. *
  34249. * @memberof PIXI.TextMetrics
  34250. * @type {HTMLCanvasElement}
  34251. * @private
  34252. */
  34253. TextMetrics._canvas = canvas;
  34254. /**
  34255. * Cache for context to use.
  34256. *
  34257. * @memberof PIXI.TextMetrics
  34258. * @type {CanvasRenderingContext2D}
  34259. * @private
  34260. */
  34261. TextMetrics._context = canvas.getContext('2d');
  34262. /**
  34263. * Cache of {@see PIXI.TextMetrics.FontMetrics} objects.
  34264. *
  34265. * @memberof PIXI.TextMetrics
  34266. * @type {Object}
  34267. * @private
  34268. */
  34269. TextMetrics._fonts = {};
  34270. /**
  34271. * String used for calculate font metrics.
  34272. * These characters are all tall to help calculate the height required for text.
  34273. *
  34274. * @static
  34275. * @memberof PIXI.TextMetrics
  34276. * @name METRICS_STRING
  34277. * @type {string}
  34278. * @default |ÉqÅ
  34279. */
  34280. TextMetrics.METRICS_STRING = '|ÉqÅ';
  34281. /**
  34282. * Baseline symbol for calculate font metrics.
  34283. *
  34284. * @static
  34285. * @memberof PIXI.TextMetrics
  34286. * @name BASELINE_SYMBOL
  34287. * @type {string}
  34288. * @default M
  34289. */
  34290. TextMetrics.BASELINE_SYMBOL = 'M';
  34291. /**
  34292. * Baseline multiplier for calculate font metrics.
  34293. *
  34294. * @static
  34295. * @memberof PIXI.TextMetrics
  34296. * @name BASELINE_MULTIPLIER
  34297. * @type {number}
  34298. * @default 1.4
  34299. */
  34300. TextMetrics.BASELINE_MULTIPLIER = 1.4;
  34301. /**
  34302. * Height multiplier for setting height of canvas to calculate font metrics.
  34303. *
  34304. * @static
  34305. * @memberof PIXI.TextMetrics
  34306. * @name HEIGHT_MULTIPLIER
  34307. * @type {number}
  34308. * @default 2.00
  34309. */
  34310. TextMetrics.HEIGHT_MULTIPLIER = 2.0;
  34311. /**
  34312. * Cache of new line chars.
  34313. *
  34314. * @memberof PIXI.TextMetrics
  34315. * @type {number[]}
  34316. * @private
  34317. */
  34318. TextMetrics._newlines = [
  34319. 0x000A,
  34320. 0x000D ];
  34321. /**
  34322. * Cache of breaking spaces.
  34323. *
  34324. * @memberof PIXI.TextMetrics
  34325. * @type {number[]}
  34326. * @private
  34327. */
  34328. TextMetrics._breakingSpaces = [
  34329. 0x0009,
  34330. 0x0020,
  34331. 0x2000,
  34332. 0x2001,
  34333. 0x2002,
  34334. 0x2003,
  34335. 0x2004,
  34336. 0x2005,
  34337. 0x2006,
  34338. 0x2008,
  34339. 0x2009,
  34340. 0x200A,
  34341. 0x205F,
  34342. 0x3000 ];
  34343. /**
  34344. * A number, or a string containing a number.
  34345. *
  34346. * @memberof PIXI
  34347. * @typedef {object} IFontMetrics
  34348. * @property {number} ascent - Font ascent
  34349. * @property {number} descent - Font descent
  34350. * @property {number} fontSize - Font size
  34351. */
  34352. var defaultDestroyOptions = {
  34353. texture: true,
  34354. children: false,
  34355. baseTexture: true,
  34356. };
  34357. /**
  34358. * A Text Object will create a line or multiple lines of text.
  34359. *
  34360. * The text is created using the [Canvas API](https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API).
  34361. *
  34362. * The primary advantage of this class over BitmapText is that you have great control over the style of the text,
  34363. * which you can change at runtime.
  34364. *
  34365. * The primary disadvantages is that each piece of text has it's own texture, which can use more memory.
  34366. * When text changes, this texture has to be re-generated and re-uploaded to the GPU, taking up time.
  34367. *
  34368. * To split a line you can use '\n' in your text string, or, on the `style` object,
  34369. * change its `wordWrap` property to true and and give the `wordWrapWidth` property a value.
  34370. *
  34371. * A Text can be created directly from a string and a style object,
  34372. * which can be generated [here](https://pixijs.io/pixi-text-style).
  34373. *
  34374. * ```js
  34375. * let text = new PIXI.Text('This is a PixiJS text',{fontFamily : 'Arial', fontSize: 24, fill : 0xff1010, align : 'center'});
  34376. * ```
  34377. *
  34378. * @class
  34379. * @extends PIXI.Sprite
  34380. * @memberof PIXI
  34381. */
  34382. var Text = /** @class */ (function (_super) {
  34383. __extends$7(Text, _super);
  34384. /**
  34385. * @param {string} text - The string that you would like the text to display
  34386. * @param {object|PIXI.TextStyle} [style] - The style parameters
  34387. * @param {HTMLCanvasElement} [canvas] - The canvas element for drawing text
  34388. */
  34389. function Text(text, style, canvas) {
  34390. var _this = this;
  34391. var ownCanvas = false;
  34392. if (!canvas) {
  34393. canvas = document.createElement('canvas');
  34394. ownCanvas = true;
  34395. }
  34396. canvas.width = 3;
  34397. canvas.height = 3;
  34398. var texture = Texture.from(canvas);
  34399. texture.orig = new Rectangle();
  34400. texture.trim = new Rectangle();
  34401. _this = _super.call(this, texture) || this;
  34402. /**
  34403. * Keep track if this Text object created it's own canvas
  34404. * element (`true`) or uses the constructor argument (`false`).
  34405. * Used to workaround a GC issues with Safari < 13 when
  34406. * destroying Text. See `destroy` for more info.
  34407. *
  34408. * @member {boolean}
  34409. * @private
  34410. */
  34411. _this._ownCanvas = ownCanvas;
  34412. /**
  34413. * The canvas element that everything is drawn to
  34414. *
  34415. * @member {HTMLCanvasElement}
  34416. */
  34417. _this.canvas = canvas;
  34418. /**
  34419. * The canvas 2d context that everything is drawn with
  34420. * @member {CanvasRenderingContext2D}
  34421. */
  34422. _this.context = _this.canvas.getContext('2d');
  34423. /**
  34424. * The resolution / device pixel ratio of the canvas.
  34425. * This is set to automatically match the renderer resolution by default, but can be overridden by setting manually.
  34426. * @member {number}
  34427. * @default PIXI.settings.RESOLUTION
  34428. */
  34429. _this._resolution = settings.RESOLUTION;
  34430. _this._autoResolution = true;
  34431. /**
  34432. * Private tracker for the current text.
  34433. *
  34434. * @member {string}
  34435. * @private
  34436. */
  34437. _this._text = null;
  34438. /**
  34439. * Private tracker for the current style.
  34440. *
  34441. * @member {object}
  34442. * @private
  34443. */
  34444. _this._style = null;
  34445. /**
  34446. * Private listener to track style changes.
  34447. *
  34448. * @member {Function}
  34449. * @private
  34450. */
  34451. _this._styleListener = null;
  34452. /**
  34453. * Private tracker for the current font.
  34454. *
  34455. * @member {string}
  34456. * @private
  34457. */
  34458. _this._font = '';
  34459. _this.text = text;
  34460. _this.style = style;
  34461. _this.localStyleID = -1;
  34462. return _this;
  34463. }
  34464. /**
  34465. * Renders text to its canvas, and updates its texture.
  34466. * By default this is used internally to ensure the texture is correct before rendering,
  34467. * but it can be used called externally, for example from this class to 'pre-generate' the texture from a piece of text,
  34468. * and then shared across multiple Sprites.
  34469. *
  34470. * @param {boolean} respectDirty - Whether to abort updating the text if the Text isn't dirty and the function is called.
  34471. */
  34472. Text.prototype.updateText = function (respectDirty) {
  34473. var style = this._style;
  34474. // check if style has changed..
  34475. if (this.localStyleID !== style.styleID) {
  34476. this.dirty = true;
  34477. this.localStyleID = style.styleID;
  34478. }
  34479. if (!this.dirty && respectDirty) {
  34480. return;
  34481. }
  34482. this._font = this._style.toFontString();
  34483. var context = this.context;
  34484. var measured = TextMetrics.measureText(this._text || ' ', this._style, this._style.wordWrap, this.canvas);
  34485. var width = measured.width;
  34486. var height = measured.height;
  34487. var lines = measured.lines;
  34488. var lineHeight = measured.lineHeight;
  34489. var lineWidths = measured.lineWidths;
  34490. var maxLineWidth = measured.maxLineWidth;
  34491. var fontProperties = measured.fontProperties;
  34492. this.canvas.width = Math.ceil(Math.ceil((Math.max(1, width) + (style.padding * 2))) * this._resolution);
  34493. this.canvas.height = Math.ceil(Math.ceil((Math.max(1, height) + (style.padding * 2))) * this._resolution);
  34494. context.scale(this._resolution, this._resolution);
  34495. context.clearRect(0, 0, this.canvas.width, this.canvas.height);
  34496. context.font = this._font;
  34497. context.lineWidth = style.strokeThickness;
  34498. context.textBaseline = style.textBaseline;
  34499. context.lineJoin = style.lineJoin;
  34500. context.miterLimit = style.miterLimit;
  34501. var linePositionX;
  34502. var linePositionY;
  34503. // require 2 passes if a shadow; the first to draw the drop shadow, the second to draw the text
  34504. var passesCount = style.dropShadow ? 2 : 1;
  34505. // For v4, we drew text at the colours of the drop shadow underneath the normal text. This gave the correct zIndex,
  34506. // but features such as alpha and shadowblur did not look right at all, since we were using actual text as a shadow.
  34507. //
  34508. // For v5.0.0, we moved over to just use the canvas API for drop shadows, which made them look much nicer and more
  34509. // visually please, but now because the stroke is drawn and then the fill, drop shadows would appear on both the fill
  34510. // and the stroke; and fill drop shadows would appear over the top of the stroke.
  34511. //
  34512. // For v5.1.1, the new route is to revert to v4 style of drawing text first to get the drop shadows underneath normal
  34513. // text, but instead drawing text in the correct location, we'll draw it off screen (-paddingY), and then adjust the
  34514. // drop shadow so only that appears on screen (+paddingY). Now we'll have the correct draw order of the shadow
  34515. // beneath the text, whilst also having the proper text shadow styling.
  34516. for (var i = 0; i < passesCount; ++i) {
  34517. var isShadowPass = style.dropShadow && i === 0;
  34518. // we only want the drop shadow, so put text way off-screen
  34519. var dsOffsetText = isShadowPass ? Math.ceil(Math.max(1, height) + (style.padding * 2)) : 0;
  34520. var dsOffsetShadow = dsOffsetText * this._resolution;
  34521. if (isShadowPass) {
  34522. // On Safari, text with gradient and drop shadows together do not position correctly
  34523. // if the scale of the canvas is not 1: https://bugs.webkit.org/show_bug.cgi?id=197689
  34524. // Therefore we'll set the styles to be a plain black whilst generating this drop shadow
  34525. context.fillStyle = 'black';
  34526. context.strokeStyle = 'black';
  34527. var dropShadowColor = style.dropShadowColor;
  34528. var rgb = hex2rgb(typeof dropShadowColor === 'number' ? dropShadowColor : string2hex(dropShadowColor));
  34529. context.shadowColor = "rgba(" + rgb[0] * 255 + "," + rgb[1] * 255 + "," + rgb[2] * 255 + "," + style.dropShadowAlpha + ")";
  34530. context.shadowBlur = style.dropShadowBlur;
  34531. context.shadowOffsetX = Math.cos(style.dropShadowAngle) * style.dropShadowDistance;
  34532. context.shadowOffsetY = (Math.sin(style.dropShadowAngle) * style.dropShadowDistance) + dsOffsetShadow;
  34533. }
  34534. else {
  34535. // set canvas text styles
  34536. context.fillStyle = this._generateFillStyle(style, lines, measured);
  34537. // TODO: Can't have different types for getter and setter. The getter shouldn't have the number type as
  34538. // the setter converts to string. See this thread for more details:
  34539. // https://github.com/microsoft/TypeScript/issues/2521
  34540. context.strokeStyle = style.stroke;
  34541. context.shadowColor = 'black';
  34542. context.shadowBlur = 0;
  34543. context.shadowOffsetX = 0;
  34544. context.shadowOffsetY = 0;
  34545. }
  34546. var linePositionYShift = (lineHeight - fontProperties.fontSize) / 2;
  34547. if (!Text.nextLineHeightBehavior || lineHeight - fontProperties.fontSize < 0) {
  34548. linePositionYShift = 0;
  34549. }
  34550. // draw lines line by line
  34551. for (var i_1 = 0; i_1 < lines.length; i_1++) {
  34552. linePositionX = style.strokeThickness / 2;
  34553. linePositionY = ((style.strokeThickness / 2) + (i_1 * lineHeight)) + fontProperties.ascent
  34554. + linePositionYShift;
  34555. if (style.align === 'right') {
  34556. linePositionX += maxLineWidth - lineWidths[i_1];
  34557. }
  34558. else if (style.align === 'center') {
  34559. linePositionX += (maxLineWidth - lineWidths[i_1]) / 2;
  34560. }
  34561. if (style.stroke && style.strokeThickness) {
  34562. this.drawLetterSpacing(lines[i_1], linePositionX + style.padding, linePositionY + style.padding - dsOffsetText, true);
  34563. }
  34564. if (style.fill) {
  34565. this.drawLetterSpacing(lines[i_1], linePositionX + style.padding, linePositionY + style.padding - dsOffsetText);
  34566. }
  34567. }
  34568. }
  34569. this.updateTexture();
  34570. };
  34571. /**
  34572. * Render the text with letter-spacing.
  34573. * @param {string} text - The text to draw
  34574. * @param {number} x - Horizontal position to draw the text
  34575. * @param {number} y - Vertical position to draw the text
  34576. * @param {boolean} [isStroke=false] - Is this drawing for the outside stroke of the
  34577. * text? If not, it's for the inside fill
  34578. * @private
  34579. */
  34580. Text.prototype.drawLetterSpacing = function (text, x, y, isStroke) {
  34581. if (isStroke === void 0) { isStroke = false; }
  34582. var style = this._style;
  34583. // letterSpacing of 0 means normal
  34584. var letterSpacing = style.letterSpacing;
  34585. if (letterSpacing === 0) {
  34586. if (isStroke) {
  34587. this.context.strokeText(text, x, y);
  34588. }
  34589. else {
  34590. this.context.fillText(text, x, y);
  34591. }
  34592. return;
  34593. }
  34594. var currentPosition = x;
  34595. // Using Array.from correctly splits characters whilst keeping emoji together.
  34596. // This is not supported on IE as it requires ES6, so regular text splitting occurs.
  34597. // This also doesn't account for emoji that are multiple emoji put together to make something else.
  34598. // Handling all of this would require a big library itself.
  34599. // https://medium.com/@giltayar/iterating-over-emoji-characters-the-es6-way-f06e4589516
  34600. // https://github.com/orling/grapheme-splitter
  34601. var stringArray = Array.from ? Array.from(text) : text.split('');
  34602. var previousWidth = this.context.measureText(text).width;
  34603. var currentWidth = 0;
  34604. for (var i = 0; i < stringArray.length; ++i) {
  34605. var currentChar = stringArray[i];
  34606. if (isStroke) {
  34607. this.context.strokeText(currentChar, currentPosition, y);
  34608. }
  34609. else {
  34610. this.context.fillText(currentChar, currentPosition, y);
  34611. }
  34612. currentWidth = this.context.measureText(text.substring(i + 1)).width;
  34613. currentPosition += previousWidth - currentWidth + letterSpacing;
  34614. previousWidth = currentWidth;
  34615. }
  34616. };
  34617. /**
  34618. * Updates texture size based on canvas size
  34619. *
  34620. * @private
  34621. */
  34622. Text.prototype.updateTexture = function () {
  34623. var canvas = this.canvas;
  34624. if (this._style.trim) {
  34625. var trimmed = trimCanvas(canvas);
  34626. if (trimmed.data) {
  34627. canvas.width = trimmed.width;
  34628. canvas.height = trimmed.height;
  34629. this.context.putImageData(trimmed.data, 0, 0);
  34630. }
  34631. }
  34632. var texture = this._texture;
  34633. var style = this._style;
  34634. var padding = style.trim ? 0 : style.padding;
  34635. var baseTexture = texture.baseTexture;
  34636. texture.trim.width = texture._frame.width = canvas.width / this._resolution;
  34637. texture.trim.height = texture._frame.height = canvas.height / this._resolution;
  34638. texture.trim.x = -padding;
  34639. texture.trim.y = -padding;
  34640. texture.orig.width = texture._frame.width - (padding * 2);
  34641. texture.orig.height = texture._frame.height - (padding * 2);
  34642. // call sprite onTextureUpdate to update scale if _width or _height were set
  34643. this._onTextureUpdate();
  34644. baseTexture.setRealSize(canvas.width, canvas.height, this._resolution);
  34645. texture.updateUvs();
  34646. // Recursively updates transform of all objects from the root to this one
  34647. this._recursivePostUpdateTransform();
  34648. this.dirty = false;
  34649. };
  34650. /**
  34651. * Renders the object using the WebGL renderer
  34652. *
  34653. * @protected
  34654. * @param {PIXI.Renderer} renderer - The renderer
  34655. */
  34656. Text.prototype._render = function (renderer) {
  34657. if (this._autoResolution && this._resolution !== renderer.resolution) {
  34658. this._resolution = renderer.resolution;
  34659. this.dirty = true;
  34660. }
  34661. this.updateText(true);
  34662. _super.prototype._render.call(this, renderer);
  34663. };
  34664. /**
  34665. * Gets the local bounds of the text object.
  34666. *
  34667. * @param {PIXI.Rectangle} rect - The output rectangle.
  34668. * @return {PIXI.Rectangle} The bounds.
  34669. */
  34670. Text.prototype.getLocalBounds = function (rect) {
  34671. this.updateText(true);
  34672. return _super.prototype.getLocalBounds.call(this, rect);
  34673. };
  34674. /**
  34675. * calculates the bounds of the Text as a rectangle. The bounds calculation takes the worldTransform into account.
  34676. * @protected
  34677. */
  34678. Text.prototype._calculateBounds = function () {
  34679. this.updateText(true);
  34680. this.calculateVertices();
  34681. // if we have already done this on THIS frame.
  34682. this._bounds.addQuad(this.vertexData);
  34683. };
  34684. /**
  34685. * Generates the fill style. Can automatically generate a gradient based on the fill style being an array
  34686. *
  34687. * @private
  34688. * @param {object} style - The style.
  34689. * @param {string[]} lines - The lines of text.
  34690. * @return {string|number|CanvasGradient} The fill style
  34691. */
  34692. Text.prototype._generateFillStyle = function (style, lines, metrics) {
  34693. // TODO: Can't have different types for getter and setter. The getter shouldn't have the number type as
  34694. // the setter converts to string. See this thread for more details:
  34695. // https://github.com/microsoft/TypeScript/issues/2521
  34696. var fillStyle = style.fill;
  34697. if (!Array.isArray(fillStyle)) {
  34698. return fillStyle;
  34699. }
  34700. else if (fillStyle.length === 1) {
  34701. return fillStyle[0];
  34702. }
  34703. // the gradient will be evenly spaced out according to how large the array is.
  34704. // ['#FF0000', '#00FF00', '#0000FF'] would created stops at 0.25, 0.5 and 0.75
  34705. var gradient;
  34706. // a dropshadow will enlarge the canvas and result in the gradient being
  34707. // generated with the incorrect dimensions
  34708. var dropShadowCorrection = (style.dropShadow) ? style.dropShadowDistance : 0;
  34709. // should also take padding into account, padding can offset the gradient
  34710. var padding = style.padding || 0;
  34711. var width = (this.canvas.width / this._resolution) - dropShadowCorrection - (padding * 2);
  34712. var height = (this.canvas.height / this._resolution) - dropShadowCorrection - (padding * 2);
  34713. // make a copy of the style settings, so we can manipulate them later
  34714. var fill = fillStyle.slice();
  34715. var fillGradientStops = style.fillGradientStops.slice();
  34716. // wanting to evenly distribute the fills. So an array of 4 colours should give fills of 0.25, 0.5 and 0.75
  34717. if (!fillGradientStops.length) {
  34718. var lengthPlus1 = fill.length + 1;
  34719. for (var i = 1; i < lengthPlus1; ++i) {
  34720. fillGradientStops.push(i / lengthPlus1);
  34721. }
  34722. }
  34723. // stop the bleeding of the last gradient on the line above to the top gradient of the this line
  34724. // by hard defining the first gradient colour at point 0, and last gradient colour at point 1
  34725. fill.unshift(fillStyle[0]);
  34726. fillGradientStops.unshift(0);
  34727. fill.push(fillStyle[fillStyle.length - 1]);
  34728. fillGradientStops.push(1);
  34729. if (style.fillGradientType === exports.TEXT_GRADIENT.LINEAR_VERTICAL) {
  34730. // start the gradient at the top center of the canvas, and end at the bottom middle of the canvas
  34731. gradient = this.context.createLinearGradient(width / 2, padding, width / 2, height + padding);
  34732. // we need to repeat the gradient so that each individual line of text has the same vertical gradient effect
  34733. // ['#FF0000', '#00FF00', '#0000FF'] over 2 lines would create stops at 0.125, 0.25, 0.375, 0.625, 0.75, 0.875
  34734. // Actual height of the text itself, not counting spacing for lineHeight/leading/dropShadow etc
  34735. var textHeight = metrics.fontProperties.fontSize + style.strokeThickness;
  34736. for (var i = 0; i < lines.length; i++) {
  34737. var lastLineBottom = (metrics.lineHeight * (i - 1)) + textHeight;
  34738. var thisLineTop = metrics.lineHeight * i;
  34739. var thisLineGradientStart = thisLineTop;
  34740. // Handle case where last & this line overlap
  34741. if (i > 0 && lastLineBottom > thisLineTop) {
  34742. thisLineGradientStart = (thisLineTop + lastLineBottom) / 2;
  34743. }
  34744. var thisLineBottom = thisLineTop + textHeight;
  34745. var nextLineTop = metrics.lineHeight * (i + 1);
  34746. var thisLineGradientEnd = thisLineBottom;
  34747. // Handle case where this & next line overlap
  34748. if (i + 1 < lines.length && nextLineTop < thisLineBottom) {
  34749. thisLineGradientEnd = (thisLineBottom + nextLineTop) / 2;
  34750. }
  34751. // textHeight, but as a 0-1 size in global gradient stop space
  34752. var gradStopLineHeight = (thisLineGradientEnd - thisLineGradientStart) / height;
  34753. for (var j = 0; j < fill.length; j++) {
  34754. // 0-1 stop point for the current line, multiplied to global space afterwards
  34755. var lineStop = 0;
  34756. if (typeof fillGradientStops[j] === 'number') {
  34757. lineStop = fillGradientStops[j];
  34758. }
  34759. else {
  34760. lineStop = j / fill.length;
  34761. }
  34762. var globalStop = Math.min(1, Math.max(0, (thisLineGradientStart / height) + (lineStop * gradStopLineHeight)));
  34763. // There's potential for floating point precision issues at the seams between gradient repeats.
  34764. globalStop = Number(globalStop.toFixed(5));
  34765. gradient.addColorStop(globalStop, fill[j]);
  34766. }
  34767. }
  34768. }
  34769. else {
  34770. // start the gradient at the center left of the canvas, and end at the center right of the canvas
  34771. gradient = this.context.createLinearGradient(padding, height / 2, width + padding, height / 2);
  34772. // can just evenly space out the gradients in this case, as multiple lines makes no difference
  34773. // to an even left to right gradient
  34774. var totalIterations = fill.length + 1;
  34775. var currentIteration = 1;
  34776. for (var i = 0; i < fill.length; i++) {
  34777. var stop = void 0;
  34778. if (typeof fillGradientStops[i] === 'number') {
  34779. stop = fillGradientStops[i];
  34780. }
  34781. else {
  34782. stop = currentIteration / totalIterations;
  34783. }
  34784. gradient.addColorStop(stop, fill[i]);
  34785. currentIteration++;
  34786. }
  34787. }
  34788. return gradient;
  34789. };
  34790. /**
  34791. * Destroys this text object.
  34792. * Note* Unlike a Sprite, a Text object will automatically destroy its baseTexture and texture as
  34793. * the majority of the time the texture will not be shared with any other Sprites.
  34794. *
  34795. * @param {object|boolean} [options] - Options parameter. A boolean will act as if all options
  34796. * have been set to that value
  34797. * @param {boolean} [options.children=false] - if set to true, all the children will have their
  34798. * destroy method called as well. 'options' will be passed on to those calls.
  34799. * @param {boolean} [options.texture=true] - Should it destroy the current texture of the sprite as well
  34800. * @param {boolean} [options.baseTexture=true] - Should it destroy the base texture of the sprite as well
  34801. */
  34802. Text.prototype.destroy = function (options) {
  34803. if (typeof options === 'boolean') {
  34804. options = { children: options };
  34805. }
  34806. options = Object.assign({}, defaultDestroyOptions, options);
  34807. _super.prototype.destroy.call(this, options);
  34808. // set canvas width and height to 0 to workaround memory leak in Safari < 13
  34809. // https://stackoverflow.com/questions/52532614/total-canvas-memory-use-exceeds-the-maximum-limit-safari-12
  34810. if (this._ownCanvas) {
  34811. this.canvas.height = this.canvas.width = 0;
  34812. }
  34813. // make sure to reset the the context and canvas.. dont want this hanging around in memory!
  34814. this.context = null;
  34815. this.canvas = null;
  34816. this._style = null;
  34817. };
  34818. Object.defineProperty(Text.prototype, "width", {
  34819. /**
  34820. * The width of the Text, setting this will actually modify the scale to achieve the value set
  34821. *
  34822. * @member {number}
  34823. */
  34824. get: function () {
  34825. this.updateText(true);
  34826. return Math.abs(this.scale.x) * this._texture.orig.width;
  34827. },
  34828. set: function (value) {
  34829. this.updateText(true);
  34830. var s = sign$1(this.scale.x) || 1;
  34831. this.scale.x = s * value / this._texture.orig.width;
  34832. this._width = value;
  34833. },
  34834. enumerable: false,
  34835. configurable: true
  34836. });
  34837. Object.defineProperty(Text.prototype, "height", {
  34838. /**
  34839. * The height of the Text, setting this will actually modify the scale to achieve the value set
  34840. *
  34841. * @member {number}
  34842. */
  34843. get: function () {
  34844. this.updateText(true);
  34845. return Math.abs(this.scale.y) * this._texture.orig.height;
  34846. },
  34847. set: function (value) {
  34848. this.updateText(true);
  34849. var s = sign$1(this.scale.y) || 1;
  34850. this.scale.y = s * value / this._texture.orig.height;
  34851. this._height = value;
  34852. },
  34853. enumerable: false,
  34854. configurable: true
  34855. });
  34856. Object.defineProperty(Text.prototype, "style", {
  34857. /**
  34858. * Set the style of the text. Set up an event listener to listen for changes on the style
  34859. * object and mark the text as dirty.
  34860. *
  34861. * @member {object|PIXI.TextStyle}
  34862. */
  34863. get: function () {
  34864. // TODO: Can't have different types for getter and setter. The getter shouldn't have the ITextStyle
  34865. // since the setter creates the TextStyle. See this thread for more details:
  34866. // https://github.com/microsoft/TypeScript/issues/2521
  34867. return this._style;
  34868. },
  34869. set: function (style) {
  34870. style = style || {};
  34871. if (style instanceof TextStyle) {
  34872. this._style = style;
  34873. }
  34874. else {
  34875. this._style = new TextStyle(style);
  34876. }
  34877. this.localStyleID = -1;
  34878. this.dirty = true;
  34879. },
  34880. enumerable: false,
  34881. configurable: true
  34882. });
  34883. Object.defineProperty(Text.prototype, "text", {
  34884. /**
  34885. * Set the copy for the text object. To split a line you can use '\n'.
  34886. *
  34887. * @member {string}
  34888. */
  34889. get: function () {
  34890. return this._text;
  34891. },
  34892. set: function (text) {
  34893. text = String(text === null || text === undefined ? '' : text);
  34894. if (this._text === text) {
  34895. return;
  34896. }
  34897. this._text = text;
  34898. this.dirty = true;
  34899. },
  34900. enumerable: false,
  34901. configurable: true
  34902. });
  34903. Object.defineProperty(Text.prototype, "resolution", {
  34904. /**
  34905. * The resolution / device pixel ratio of the canvas.
  34906. * This is set to automatically match the renderer resolution by default, but can be overridden by setting manually.
  34907. * @member {number}
  34908. * @default 1
  34909. */
  34910. get: function () {
  34911. return this._resolution;
  34912. },
  34913. set: function (value) {
  34914. this._autoResolution = false;
  34915. if (this._resolution === value) {
  34916. return;
  34917. }
  34918. this._resolution = value;
  34919. this.dirty = true;
  34920. },
  34921. enumerable: false,
  34922. configurable: true
  34923. });
  34924. /**
  34925. * New behavior for `lineHeight` that's meant to mimic HTML text. A value of `true` will
  34926. * make sure the first baseline is offset by the `lineHeight` value if it is greater than `fontSize`.
  34927. * A value of `false` will use the legacy behavior and not change the baseline of the first line.
  34928. * In the next major release, we'll enable this by default.
  34929. *
  34930. * @static
  34931. * @memberof PIXI.Text
  34932. * @member {boolean} nextLineHeightBehavior
  34933. * @default false
  34934. */
  34935. Text.nextLineHeightBehavior = false;
  34936. return Text;
  34937. }(Sprite));
  34938. /*!
  34939. * @pixi/prepare - v6.1.2
  34940. * Compiled Thu, 12 Aug 2021 17:11:19 UTC
  34941. *
  34942. * @pixi/prepare is licensed under the MIT License.
  34943. * http://www.opensource.org/licenses/mit-license
  34944. */
  34945. /**
  34946. * Default number of uploads per frame using prepare plugin.
  34947. *
  34948. * @static
  34949. * @memberof PIXI.settings
  34950. * @name UPLOADS_PER_FRAME
  34951. * @type {number}
  34952. * @default 4
  34953. */
  34954. settings.UPLOADS_PER_FRAME = 4;
  34955. /*! *****************************************************************************
  34956. Copyright (c) Microsoft Corporation. All rights reserved.
  34957. Licensed under the Apache License, Version 2.0 (the "License"); you may not use
  34958. this file except in compliance with the License. You may obtain a copy of the
  34959. License at http://www.apache.org/licenses/LICENSE-2.0
  34960. THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  34961. KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
  34962. WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
  34963. MERCHANTABLITY OR NON-INFRINGEMENT.
  34964. See the Apache Version 2.0 License for specific language governing permissions
  34965. and limitations under the License.
  34966. ***************************************************************************** */
  34967. /* global Reflect, Promise */
  34968. var extendStatics$8 = function(d, b) {
  34969. extendStatics$8 = Object.setPrototypeOf ||
  34970. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  34971. function (d, b) { for (var p in b) { if (b.hasOwnProperty(p)) { d[p] = b[p]; } } };
  34972. return extendStatics$8(d, b);
  34973. };
  34974. function __extends$8(d, b) {
  34975. extendStatics$8(d, b);
  34976. function __() { this.constructor = d; }
  34977. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  34978. }
  34979. /**
  34980. * CountLimiter limits the number of items handled by a {@link PIXI.BasePrepare} to a specified
  34981. * number of items per frame.
  34982. *
  34983. * @class
  34984. * @memberof PIXI
  34985. */
  34986. var CountLimiter = /** @class */ (function () {
  34987. /**
  34988. * @param {number} maxItemsPerFrame - The maximum number of items that can be prepared each frame.
  34989. */
  34990. function CountLimiter(maxItemsPerFrame) {
  34991. /**
  34992. * The maximum number of items that can be prepared each frame.
  34993. * @type {number}
  34994. * @private
  34995. */
  34996. this.maxItemsPerFrame = maxItemsPerFrame;
  34997. /**
  34998. * The number of items that can be prepared in the current frame.
  34999. * @type {number}
  35000. * @private
  35001. */
  35002. this.itemsLeft = 0;
  35003. }
  35004. /**
  35005. * Resets any counting properties to start fresh on a new frame.
  35006. */
  35007. CountLimiter.prototype.beginFrame = function () {
  35008. this.itemsLeft = this.maxItemsPerFrame;
  35009. };
  35010. /**
  35011. * Checks to see if another item can be uploaded. This should only be called once per item.
  35012. * @return {boolean} If the item is allowed to be uploaded.
  35013. */
  35014. CountLimiter.prototype.allowedToUpload = function () {
  35015. return this.itemsLeft-- > 0;
  35016. };
  35017. return CountLimiter;
  35018. }());
  35019. /**
  35020. * Built-in hook to find multiple textures from objects like AnimatedSprites.
  35021. *
  35022. * @private
  35023. * @param {PIXI.DisplayObject} item - Display object to check
  35024. * @param {Array<*>} queue - Collection of items to upload
  35025. * @return {boolean} if a PIXI.Texture object was found.
  35026. */
  35027. function findMultipleBaseTextures(item, queue) {
  35028. var result = false;
  35029. // Objects with multiple textures
  35030. if (item && item._textures && item._textures.length) {
  35031. for (var i = 0; i < item._textures.length; i++) {
  35032. if (item._textures[i] instanceof Texture) {
  35033. var baseTexture = item._textures[i].baseTexture;
  35034. if (queue.indexOf(baseTexture) === -1) {
  35035. queue.push(baseTexture);
  35036. result = true;
  35037. }
  35038. }
  35039. }
  35040. }
  35041. return result;
  35042. }
  35043. /**
  35044. * Built-in hook to find BaseTextures from Texture.
  35045. *
  35046. * @private
  35047. * @param {PIXI.Texture} item - Display object to check
  35048. * @param {Array<*>} queue - Collection of items to upload
  35049. * @return {boolean} if a PIXI.Texture object was found.
  35050. */
  35051. function findBaseTexture(item, queue) {
  35052. if (item.baseTexture instanceof BaseTexture) {
  35053. var texture = item.baseTexture;
  35054. if (queue.indexOf(texture) === -1) {
  35055. queue.push(texture);
  35056. }
  35057. return true;
  35058. }
  35059. return false;
  35060. }
  35061. /**
  35062. * Built-in hook to find textures from objects.
  35063. *
  35064. * @private
  35065. * @param {PIXI.DisplayObject} item - Display object to check
  35066. * @param {Array<*>} queue - Collection of items to upload
  35067. * @return {boolean} if a PIXI.Texture object was found.
  35068. */
  35069. function findTexture(item, queue) {
  35070. if (item._texture && item._texture instanceof Texture) {
  35071. var texture = item._texture.baseTexture;
  35072. if (queue.indexOf(texture) === -1) {
  35073. queue.push(texture);
  35074. }
  35075. return true;
  35076. }
  35077. return false;
  35078. }
  35079. /**
  35080. * Built-in hook to draw PIXI.Text to its texture.
  35081. *
  35082. * @private
  35083. * @param {PIXI.AbstractRenderer|PIXI.BasePrepare} helper - Not used by this upload handler
  35084. * @param {PIXI.DisplayObject} item - Item to check
  35085. * @return {boolean} If item was uploaded.
  35086. */
  35087. function drawText(_helper, item) {
  35088. if (item instanceof Text) {
  35089. // updating text will return early if it is not dirty
  35090. item.updateText(true);
  35091. return true;
  35092. }
  35093. return false;
  35094. }
  35095. /**
  35096. * Built-in hook to calculate a text style for a PIXI.Text object.
  35097. *
  35098. * @private
  35099. * @param {PIXI.AbstractRenderer|PIXI.BasePrepare} helper - Not used by this upload handler
  35100. * @param {PIXI.DisplayObject} item - Item to check
  35101. * @return {boolean} If item was uploaded.
  35102. */
  35103. function calculateTextStyle(_helper, item) {
  35104. if (item instanceof TextStyle) {
  35105. var font = item.toFontString();
  35106. TextMetrics.measureFont(font);
  35107. return true;
  35108. }
  35109. return false;
  35110. }
  35111. /**
  35112. * Built-in hook to find Text objects.
  35113. *
  35114. * @private
  35115. * @param {PIXI.DisplayObject} item - Display object to check
  35116. * @param {Array<*>} queue - Collection of items to upload
  35117. * @return {boolean} if a PIXI.Text object was found.
  35118. */
  35119. function findText(item, queue) {
  35120. if (item instanceof Text) {
  35121. // push the text style to prepare it - this can be really expensive
  35122. if (queue.indexOf(item.style) === -1) {
  35123. queue.push(item.style);
  35124. }
  35125. // also push the text object so that we can render it (to canvas/texture) if needed
  35126. if (queue.indexOf(item) === -1) {
  35127. queue.push(item);
  35128. }
  35129. // also push the Text's texture for upload to GPU
  35130. var texture = item._texture.baseTexture;
  35131. if (queue.indexOf(texture) === -1) {
  35132. queue.push(texture);
  35133. }
  35134. return true;
  35135. }
  35136. return false;
  35137. }
  35138. /**
  35139. * Built-in hook to find TextStyle objects.
  35140. *
  35141. * @private
  35142. * @param {PIXI.TextStyle} item - Display object to check
  35143. * @param {Array<*>} queue - Collection of items to upload
  35144. * @return {boolean} if a PIXI.TextStyle object was found.
  35145. */
  35146. function findTextStyle(item, queue) {
  35147. if (item instanceof TextStyle) {
  35148. if (queue.indexOf(item) === -1) {
  35149. queue.push(item);
  35150. }
  35151. return true;
  35152. }
  35153. return false;
  35154. }
  35155. /**
  35156. * The prepare manager provides functionality to upload content to the GPU.
  35157. *
  35158. * BasePrepare handles basic queuing functionality and is extended by
  35159. * {@link PIXI.Prepare} and {@link PIXI.CanvasPrepare}
  35160. * to provide preparation capabilities specific to their respective renderers.
  35161. *
  35162. * @example
  35163. * // Create a sprite
  35164. * const sprite = PIXI.Sprite.from('something.png');
  35165. *
  35166. * // Load object into GPU
  35167. * app.renderer.plugins.prepare.upload(sprite, () => {
  35168. *
  35169. * //Texture(s) has been uploaded to GPU
  35170. * app.stage.addChild(sprite);
  35171. *
  35172. * })
  35173. *
  35174. * @abstract
  35175. * @class
  35176. * @memberof PIXI
  35177. */
  35178. var BasePrepare = /** @class */ (function () {
  35179. /**
  35180. * @param {PIXI.AbstractRenderer} renderer - A reference to the current renderer
  35181. */
  35182. function BasePrepare(renderer) {
  35183. var _this = this;
  35184. /**
  35185. * The limiter to be used to control how quickly items are prepared.
  35186. * @type {PIXI.CountLimiter|PIXI.TimeLimiter}
  35187. */
  35188. this.limiter = new CountLimiter(settings.UPLOADS_PER_FRAME);
  35189. /**
  35190. * Reference to the renderer.
  35191. * @type {PIXI.AbstractRenderer}
  35192. * @protected
  35193. */
  35194. this.renderer = renderer;
  35195. /**
  35196. * The only real difference between CanvasPrepare and Prepare is what they pass
  35197. * to upload hooks. That different parameter is stored here.
  35198. * @type {object}
  35199. * @protected
  35200. */
  35201. this.uploadHookHelper = null;
  35202. /**
  35203. * Collection of items to uploads at once.
  35204. * @type {Array<*>}
  35205. * @private
  35206. */
  35207. this.queue = [];
  35208. /**
  35209. * Collection of additional hooks for finding assets.
  35210. * @type {Array<Function>}
  35211. * @private
  35212. */
  35213. this.addHooks = [];
  35214. /**
  35215. * Collection of additional hooks for processing assets.
  35216. * @type {Array<Function>}
  35217. * @private
  35218. */
  35219. this.uploadHooks = [];
  35220. /**
  35221. * Callback to call after completed.
  35222. * @type {Array<Function>}
  35223. * @private
  35224. */
  35225. this.completes = [];
  35226. /**
  35227. * If prepare is ticking (running).
  35228. * @type {boolean}
  35229. * @private
  35230. */
  35231. this.ticking = false;
  35232. /**
  35233. * 'bound' call for prepareItems().
  35234. * @type {Function}
  35235. * @private
  35236. */
  35237. this.delayedTick = function () {
  35238. // unlikely, but in case we were destroyed between tick() and delayedTick()
  35239. if (!_this.queue) {
  35240. return;
  35241. }
  35242. _this.prepareItems();
  35243. };
  35244. // hooks to find the correct texture
  35245. this.registerFindHook(findText);
  35246. this.registerFindHook(findTextStyle);
  35247. this.registerFindHook(findMultipleBaseTextures);
  35248. this.registerFindHook(findBaseTexture);
  35249. this.registerFindHook(findTexture);
  35250. // upload hooks
  35251. this.registerUploadHook(drawText);
  35252. this.registerUploadHook(calculateTextStyle);
  35253. }
  35254. /**
  35255. * Upload all the textures and graphics to the GPU.
  35256. *
  35257. * @param {Function|PIXI.DisplayObject|PIXI.Container|PIXI.BaseTexture|PIXI.Texture|PIXI.Graphics|PIXI.Text} item -
  35258. * Either the container or display object to search for items to upload, the items to upload themselves,
  35259. * or the callback function, if items have been added using `prepare.add`.
  35260. * @param {Function} [done] - Optional callback when all queued uploads have completed
  35261. */
  35262. BasePrepare.prototype.upload = function (item, done) {
  35263. if (typeof item === 'function') {
  35264. done = item;
  35265. item = null;
  35266. }
  35267. // If a display object, search for items
  35268. // that we could upload
  35269. if (item) {
  35270. this.add(item);
  35271. }
  35272. // Get the items for upload from the display
  35273. if (this.queue.length) {
  35274. if (done) {
  35275. this.completes.push(done);
  35276. }
  35277. if (!this.ticking) {
  35278. this.ticking = true;
  35279. Ticker.system.addOnce(this.tick, this, exports.UPDATE_PRIORITY.UTILITY);
  35280. }
  35281. }
  35282. else if (done) {
  35283. done();
  35284. }
  35285. };
  35286. /**
  35287. * Handle tick update
  35288. *
  35289. * @private
  35290. */
  35291. BasePrepare.prototype.tick = function () {
  35292. setTimeout(this.delayedTick, 0);
  35293. };
  35294. /**
  35295. * Actually prepare items. This is handled outside of the tick because it will take a while
  35296. * and we do NOT want to block the current animation frame from rendering.
  35297. *
  35298. * @private
  35299. */
  35300. BasePrepare.prototype.prepareItems = function () {
  35301. this.limiter.beginFrame();
  35302. // Upload the graphics
  35303. while (this.queue.length && this.limiter.allowedToUpload()) {
  35304. var item = this.queue[0];
  35305. var uploaded = false;
  35306. if (item && !item._destroyed) {
  35307. for (var i = 0, len = this.uploadHooks.length; i < len; i++) {
  35308. if (this.uploadHooks[i](this.uploadHookHelper, item)) {
  35309. this.queue.shift();
  35310. uploaded = true;
  35311. break;
  35312. }
  35313. }
  35314. }
  35315. if (!uploaded) {
  35316. this.queue.shift();
  35317. }
  35318. }
  35319. // We're finished
  35320. if (!this.queue.length) {
  35321. this.ticking = false;
  35322. var completes = this.completes.slice(0);
  35323. this.completes.length = 0;
  35324. for (var i = 0, len = completes.length; i < len; i++) {
  35325. completes[i]();
  35326. }
  35327. }
  35328. else {
  35329. // if we are not finished, on the next rAF do this again
  35330. Ticker.system.addOnce(this.tick, this, exports.UPDATE_PRIORITY.UTILITY);
  35331. }
  35332. };
  35333. /**
  35334. * Adds hooks for finding items.
  35335. *
  35336. * @param {Function} addHook - Function call that takes two parameters: `item:*, queue:Array`
  35337. * function must return `true` if it was able to add item to the queue.
  35338. * @return {this} Instance of plugin for chaining.
  35339. */
  35340. BasePrepare.prototype.registerFindHook = function (addHook) {
  35341. if (addHook) {
  35342. this.addHooks.push(addHook);
  35343. }
  35344. return this;
  35345. };
  35346. /**
  35347. * Adds hooks for uploading items.
  35348. *
  35349. * @param {Function} uploadHook - Function call that takes two parameters: `prepare:CanvasPrepare, item:*` and
  35350. * function must return `true` if it was able to handle upload of item.
  35351. * @return {this} Instance of plugin for chaining.
  35352. */
  35353. BasePrepare.prototype.registerUploadHook = function (uploadHook) {
  35354. if (uploadHook) {
  35355. this.uploadHooks.push(uploadHook);
  35356. }
  35357. return this;
  35358. };
  35359. /**
  35360. * Manually add an item to the uploading queue.
  35361. *
  35362. * @param {PIXI.DisplayObject|PIXI.Container|PIXI.BaseTexture|PIXI.Texture|PIXI.Graphics|PIXI.Text|*} item - Object to
  35363. * add to the queue
  35364. * @return {this} Instance of plugin for chaining.
  35365. */
  35366. BasePrepare.prototype.add = function (item) {
  35367. // Add additional hooks for finding elements on special
  35368. // types of objects that
  35369. for (var i = 0, len = this.addHooks.length; i < len; i++) {
  35370. if (this.addHooks[i](item, this.queue)) {
  35371. break;
  35372. }
  35373. }
  35374. // Get children recursively
  35375. if (item instanceof Container) {
  35376. for (var i = item.children.length - 1; i >= 0; i--) {
  35377. this.add(item.children[i]);
  35378. }
  35379. }
  35380. return this;
  35381. };
  35382. /**
  35383. * Destroys the plugin, don't use after this.
  35384. *
  35385. */
  35386. BasePrepare.prototype.destroy = function () {
  35387. if (this.ticking) {
  35388. Ticker.system.remove(this.tick, this);
  35389. }
  35390. this.ticking = false;
  35391. this.addHooks = null;
  35392. this.uploadHooks = null;
  35393. this.renderer = null;
  35394. this.completes = null;
  35395. this.queue = null;
  35396. this.limiter = null;
  35397. this.uploadHookHelper = null;
  35398. };
  35399. return BasePrepare;
  35400. }());
  35401. /**
  35402. * Built-in hook to upload PIXI.Texture objects to the GPU.
  35403. *
  35404. * @private
  35405. * @param {PIXI.Renderer} renderer - instance of the webgl renderer
  35406. * @param {PIXI.BaseTexture} item - Item to check
  35407. * @return {boolean} If item was uploaded.
  35408. */
  35409. function uploadBaseTextures(renderer, item) {
  35410. if (item instanceof BaseTexture) {
  35411. // if the texture already has a GL texture, then the texture has been prepared or rendered
  35412. // before now. If the texture changed, then the changer should be calling texture.update() which
  35413. // reuploads the texture without need for preparing it again
  35414. if (!item._glTextures[renderer.CONTEXT_UID]) {
  35415. renderer.texture.bind(item);
  35416. }
  35417. return true;
  35418. }
  35419. return false;
  35420. }
  35421. /**
  35422. * Built-in hook to upload PIXI.Graphics to the GPU.
  35423. *
  35424. * @private
  35425. * @param {PIXI.Renderer} renderer - instance of the webgl renderer
  35426. * @param {PIXI.DisplayObject} item - Item to check
  35427. * @return {boolean} If item was uploaded.
  35428. */
  35429. function uploadGraphics(renderer, item) {
  35430. if (!(item instanceof Graphics)) {
  35431. return false;
  35432. }
  35433. var geometry = item.geometry;
  35434. // update dirty graphics to get batches
  35435. item.finishPoly();
  35436. geometry.updateBatches();
  35437. var batches = geometry.batches;
  35438. // upload all textures found in styles
  35439. for (var i = 0; i < batches.length; i++) {
  35440. var texture = batches[i].style.texture;
  35441. if (texture) {
  35442. uploadBaseTextures(renderer, texture.baseTexture);
  35443. }
  35444. }
  35445. // if its not batchable - update vao for particular shader
  35446. if (!geometry.batchable) {
  35447. renderer.geometry.bind(geometry, item._resolveDirectShader(renderer));
  35448. }
  35449. return true;
  35450. }
  35451. /**
  35452. * Built-in hook to find graphics.
  35453. *
  35454. * @private
  35455. * @param {PIXI.DisplayObject} item - Display object to check
  35456. * @param {Array<*>} queue - Collection of items to upload
  35457. * @return {boolean} if a PIXI.Graphics object was found.
  35458. */
  35459. function findGraphics(item, queue) {
  35460. if (item instanceof Graphics) {
  35461. queue.push(item);
  35462. return true;
  35463. }
  35464. return false;
  35465. }
  35466. /**
  35467. * The prepare plugin provides renderer-specific plugins for pre-rendering DisplayObjects. These plugins are useful for
  35468. * asynchronously preparing and uploading to the GPU assets, textures, graphics waiting to be displayed.
  35469. *
  35470. * Do not instantiate this plugin directly. It is available from the `renderer.plugins` property.
  35471. * See {@link PIXI.CanvasRenderer#plugins} or {@link PIXI.Renderer#plugins}.
  35472. * @example
  35473. * // Create a new application
  35474. * const app = new PIXI.Application();
  35475. * document.body.appendChild(app.view);
  35476. *
  35477. * // Don't start rendering right away
  35478. * app.stop();
  35479. *
  35480. * // create a display object
  35481. * const rect = new PIXI.Graphics()
  35482. * .beginFill(0x00ff00)
  35483. * .drawRect(40, 40, 200, 200);
  35484. *
  35485. * // Add to the stage
  35486. * app.stage.addChild(rect);
  35487. *
  35488. * // Don't start rendering until the graphic is uploaded to the GPU
  35489. * app.renderer.plugins.prepare.upload(app.stage, () => {
  35490. * app.start();
  35491. * });
  35492. *
  35493. * @class
  35494. * @extends PIXI.BasePrepare
  35495. * @memberof PIXI
  35496. */
  35497. var Prepare = /** @class */ (function (_super) {
  35498. __extends$8(Prepare, _super);
  35499. /**
  35500. * @param {PIXI.Renderer} renderer - A reference to the current renderer
  35501. */
  35502. function Prepare(renderer) {
  35503. var _this = _super.call(this, renderer) || this;
  35504. _this.uploadHookHelper = _this.renderer;
  35505. // Add textures and graphics to upload
  35506. _this.registerFindHook(findGraphics);
  35507. _this.registerUploadHook(uploadBaseTextures);
  35508. _this.registerUploadHook(uploadGraphics);
  35509. return _this;
  35510. }
  35511. return Prepare;
  35512. }(BasePrepare));
  35513. /**
  35514. * TimeLimiter limits the number of items handled by a {@link PIXI.BasePrepare} to a specified
  35515. * number of milliseconds per frame.
  35516. *
  35517. * @class
  35518. * @memberof PIXI
  35519. */
  35520. var TimeLimiter = /** @class */ (function () {
  35521. /**
  35522. * @param {number} maxMilliseconds - The maximum milliseconds that can be spent preparing items each frame.
  35523. */
  35524. function TimeLimiter(maxMilliseconds) {
  35525. /**
  35526. * The maximum milliseconds that can be spent preparing items each frame.
  35527. * @type {number}
  35528. * @private
  35529. */
  35530. this.maxMilliseconds = maxMilliseconds;
  35531. /**
  35532. * The start time of the current frame.
  35533. * @type {number}
  35534. * @private
  35535. */
  35536. this.frameStart = 0;
  35537. }
  35538. /**
  35539. * Resets any counting properties to start fresh on a new frame.
  35540. */
  35541. TimeLimiter.prototype.beginFrame = function () {
  35542. this.frameStart = Date.now();
  35543. };
  35544. /**
  35545. * Checks to see if another item can be uploaded. This should only be called once per item.
  35546. * @return {boolean} If the item is allowed to be uploaded.
  35547. */
  35548. TimeLimiter.prototype.allowedToUpload = function () {
  35549. return Date.now() - this.frameStart < this.maxMilliseconds;
  35550. };
  35551. return TimeLimiter;
  35552. }());
  35553. /*!
  35554. * @pixi/spritesheet - v6.1.2
  35555. * Compiled Thu, 12 Aug 2021 17:11:19 UTC
  35556. *
  35557. * @pixi/spritesheet is licensed under the MIT License.
  35558. * http://www.opensource.org/licenses/mit-license
  35559. */
  35560. /**
  35561. * Utility class for maintaining reference to a collection
  35562. * of Textures on a single Spritesheet.
  35563. *
  35564. * To access a sprite sheet from your code pass its JSON data file to Pixi's loader:
  35565. *
  35566. * ```js
  35567. * PIXI.Loader.shared.add("images/spritesheet.json").load(setup);
  35568. *
  35569. * function setup() {
  35570. * let sheet = PIXI.Loader.shared.resources["images/spritesheet.json"].spritesheet;
  35571. * ...
  35572. * }
  35573. * ```
  35574. * With the `sheet.textures` you can create Sprite objects,`sheet.animations` can be used to create an AnimatedSprite.
  35575. *
  35576. * Sprite sheets can be packed using tools like {@link https://codeandweb.com/texturepacker|TexturePacker},
  35577. * {@link https://renderhjs.net/shoebox/|Shoebox} or {@link https://github.com/krzysztof-o/spritesheet.js|Spritesheet.js}.
  35578. * Default anchor points (see {@link PIXI.Texture#defaultAnchor}) and grouping of animation sprites are currently only
  35579. * supported by TexturePacker.
  35580. *
  35581. * @class
  35582. * @memberof PIXI
  35583. */
  35584. var Spritesheet = /** @class */ (function () {
  35585. /**
  35586. * @param {PIXI.BaseTexture|PIXI.Texture} baseTexture - Reference to the source BaseTexture object.
  35587. * @param {Object} data - Spritesheet image data.
  35588. * @param {string} [resolutionFilename] - The filename to consider when determining
  35589. * the resolution of the spritesheet. If not provided, the imageUrl will
  35590. * be used on the BaseTexture.
  35591. */
  35592. function Spritesheet(texture, data, resolutionFilename) {
  35593. if (resolutionFilename === void 0) { resolutionFilename = null; }
  35594. /**
  35595. * Reference to original source image from the Loader. This reference is retained so we
  35596. * can destroy the Texture later on. It is never used internally.
  35597. * @type {PIXI.Texture}
  35598. * @private
  35599. */
  35600. this._texture = texture instanceof Texture ? texture : null;
  35601. /**
  35602. * Reference to ths source texture.
  35603. * @type {PIXI.BaseTexture}
  35604. */
  35605. this.baseTexture = texture instanceof BaseTexture ? texture : this._texture.baseTexture;
  35606. /**
  35607. * A map containing all textures of the sprite sheet.
  35608. * Can be used to create a {@link PIXI.Sprite|Sprite}:
  35609. * ```js
  35610. * new PIXI.Sprite(sheet.textures["image.png"]);
  35611. * ```
  35612. * @member {Object}
  35613. */
  35614. this.textures = {};
  35615. /**
  35616. * A map containing the textures for each animation.
  35617. * Can be used to create an {@link PIXI.AnimatedSprite|AnimatedSprite}:
  35618. * ```js
  35619. * new PIXI.AnimatedSprite(sheet.animations["anim_name"])
  35620. * ```
  35621. * @member {Object}
  35622. */
  35623. this.animations = {};
  35624. /**
  35625. * Reference to the original JSON data.
  35626. * @type {Object}
  35627. */
  35628. this.data = data;
  35629. var resource = this.baseTexture.resource;
  35630. /**
  35631. * The resolution of the spritesheet.
  35632. * @type {number}
  35633. */
  35634. this.resolution = this._updateResolution(resolutionFilename || (resource ? resource.url : null));
  35635. /**
  35636. * Map of spritesheet frames.
  35637. * @type {Object}
  35638. * @private
  35639. */
  35640. this._frames = this.data.frames;
  35641. /**
  35642. * Collection of frame names.
  35643. * @type {string[]}
  35644. * @private
  35645. */
  35646. this._frameKeys = Object.keys(this._frames);
  35647. /**
  35648. * Current batch index being processed.
  35649. * @type {number}
  35650. * @private
  35651. */
  35652. this._batchIndex = 0;
  35653. /**
  35654. * Callback when parse is completed.
  35655. * @type {Function}
  35656. * @private
  35657. */
  35658. this._callback = null;
  35659. }
  35660. /**
  35661. * Generate the resolution from the filename or fallback
  35662. * to the meta.scale field of the JSON data.
  35663. *
  35664. * @private
  35665. * @param {string} resolutionFilename - The filename to use for resolving
  35666. * the default resolution.
  35667. * @return {number} Resolution to use for spritesheet.
  35668. */
  35669. Spritesheet.prototype._updateResolution = function (resolutionFilename) {
  35670. if (resolutionFilename === void 0) { resolutionFilename = null; }
  35671. var scale = this.data.meta.scale;
  35672. // Use a defaultValue of `null` to check if a url-based resolution is set
  35673. var resolution = getResolutionOfUrl(resolutionFilename, null);
  35674. // No resolution found via URL
  35675. if (resolution === null) {
  35676. // Use the scale value or default to 1
  35677. resolution = scale !== undefined ? parseFloat(scale) : 1;
  35678. }
  35679. // For non-1 resolutions, update baseTexture
  35680. if (resolution !== 1) {
  35681. this.baseTexture.setResolution(resolution);
  35682. }
  35683. return resolution;
  35684. };
  35685. /**
  35686. * Parser spritesheet from loaded data. This is done asynchronously
  35687. * to prevent creating too many Texture within a single process.
  35688. *
  35689. * @param {Function} callback - Callback when complete returns
  35690. * a map of the Textures for this spritesheet.
  35691. */
  35692. Spritesheet.prototype.parse = function (callback) {
  35693. this._batchIndex = 0;
  35694. this._callback = callback;
  35695. if (this._frameKeys.length <= Spritesheet.BATCH_SIZE) {
  35696. this._processFrames(0);
  35697. this._processAnimations();
  35698. this._parseComplete();
  35699. }
  35700. else {
  35701. this._nextBatch();
  35702. }
  35703. };
  35704. /**
  35705. * Process a batch of frames
  35706. *
  35707. * @private
  35708. * @param {number} initialFrameIndex - The index of frame to start.
  35709. */
  35710. Spritesheet.prototype._processFrames = function (initialFrameIndex) {
  35711. var frameIndex = initialFrameIndex;
  35712. var maxFrames = Spritesheet.BATCH_SIZE;
  35713. while (frameIndex - initialFrameIndex < maxFrames && frameIndex < this._frameKeys.length) {
  35714. var i = this._frameKeys[frameIndex];
  35715. var data = this._frames[i];
  35716. var rect = data.frame;
  35717. if (rect) {
  35718. var frame = null;
  35719. var trim = null;
  35720. var sourceSize = data.trimmed !== false && data.sourceSize
  35721. ? data.sourceSize : data.frame;
  35722. var orig = new Rectangle(0, 0, Math.floor(sourceSize.w) / this.resolution, Math.floor(sourceSize.h) / this.resolution);
  35723. if (data.rotated) {
  35724. frame = new Rectangle(Math.floor(rect.x) / this.resolution, Math.floor(rect.y) / this.resolution, Math.floor(rect.h) / this.resolution, Math.floor(rect.w) / this.resolution);
  35725. }
  35726. else {
  35727. frame = new Rectangle(Math.floor(rect.x) / this.resolution, Math.floor(rect.y) / this.resolution, Math.floor(rect.w) / this.resolution, Math.floor(rect.h) / this.resolution);
  35728. }
  35729. // Check to see if the sprite is trimmed
  35730. if (data.trimmed !== false && data.spriteSourceSize) {
  35731. trim = new Rectangle(Math.floor(data.spriteSourceSize.x) / this.resolution, Math.floor(data.spriteSourceSize.y) / this.resolution, Math.floor(rect.w) / this.resolution, Math.floor(rect.h) / this.resolution);
  35732. }
  35733. this.textures[i] = new Texture(this.baseTexture, frame, orig, trim, data.rotated ? 2 : 0, data.anchor);
  35734. // lets also add the frame to pixi's global cache for 'from' and 'fromLoader' functions
  35735. Texture.addToCache(this.textures[i], i);
  35736. }
  35737. frameIndex++;
  35738. }
  35739. };
  35740. /**
  35741. * Parse animations config
  35742. *
  35743. * @private
  35744. */
  35745. Spritesheet.prototype._processAnimations = function () {
  35746. var animations = this.data.animations || {};
  35747. for (var animName in animations) {
  35748. this.animations[animName] = [];
  35749. for (var i = 0; i < animations[animName].length; i++) {
  35750. var frameName = animations[animName][i];
  35751. this.animations[animName].push(this.textures[frameName]);
  35752. }
  35753. }
  35754. };
  35755. /**
  35756. * The parse has completed.
  35757. *
  35758. * @private
  35759. */
  35760. Spritesheet.prototype._parseComplete = function () {
  35761. var callback = this._callback;
  35762. this._callback = null;
  35763. this._batchIndex = 0;
  35764. callback.call(this, this.textures);
  35765. };
  35766. /**
  35767. * Begin the next batch of textures.
  35768. *
  35769. * @private
  35770. */
  35771. Spritesheet.prototype._nextBatch = function () {
  35772. var _this = this;
  35773. this._processFrames(this._batchIndex * Spritesheet.BATCH_SIZE);
  35774. this._batchIndex++;
  35775. setTimeout(function () {
  35776. if (_this._batchIndex * Spritesheet.BATCH_SIZE < _this._frameKeys.length) {
  35777. _this._nextBatch();
  35778. }
  35779. else {
  35780. _this._processAnimations();
  35781. _this._parseComplete();
  35782. }
  35783. }, 0);
  35784. };
  35785. /**
  35786. * Destroy Spritesheet and don't use after this.
  35787. *
  35788. * @param {boolean} [destroyBase=false] - Whether to destroy the base texture as well
  35789. */
  35790. Spritesheet.prototype.destroy = function (destroyBase) {
  35791. var _a;
  35792. if (destroyBase === void 0) { destroyBase = false; }
  35793. for (var i in this.textures) {
  35794. this.textures[i].destroy();
  35795. }
  35796. this._frames = null;
  35797. this._frameKeys = null;
  35798. this.data = null;
  35799. this.textures = null;
  35800. if (destroyBase) {
  35801. (_a = this._texture) === null || _a === void 0 ? void 0 : _a.destroy();
  35802. this.baseTexture.destroy();
  35803. }
  35804. this._texture = null;
  35805. this.baseTexture = null;
  35806. };
  35807. /**
  35808. * The maximum number of Textures to build per process.
  35809. *
  35810. * @type {number}
  35811. * @default 1000
  35812. */
  35813. Spritesheet.BATCH_SIZE = 1000;
  35814. return Spritesheet;
  35815. }());
  35816. /**
  35817. * Reference to Spritesheet object created.
  35818. * @member {PIXI.Spritesheet} spritesheet
  35819. * @memberof PIXI.LoaderResource
  35820. * @instance
  35821. */
  35822. /**
  35823. * Dictionary of textures from Spritesheet.
  35824. * @member {object<string, PIXI.Texture>} textures
  35825. * @memberof PIXI.LoaderResource
  35826. * @instance
  35827. */
  35828. /**
  35829. * {@link PIXI.Loader} middleware for loading texture atlases that have been created with
  35830. * TexturePacker or similar JSON-based spritesheet.
  35831. *
  35832. * This middleware automatically generates Texture resources.
  35833. *
  35834. * If you're using Webpack or other bundlers and plan on bundling the atlas' JSON,
  35835. * use the {@link PIXI.Spritesheet} class to directly parse the JSON.
  35836. *
  35837. * The Loader's image Resource name is automatically appended with `"_image"`.
  35838. * If a Resource with this name is already loaded, the Loader will skip parsing the
  35839. * Spritesheet. The code below will generate an internal Loader Resource called `"myatlas_image"`.
  35840. *
  35841. * @example
  35842. * loader.add('myatlas', 'path/to/myatlas.json');
  35843. * loader.load(() => {
  35844. * loader.resources.myatlas; // atlas JSON resource
  35845. * loader.resources.myatlas_image; // atlas Image resource
  35846. * });
  35847. *
  35848. * @class
  35849. * @memberof PIXI
  35850. * @implements PIXI.ILoaderPlugin
  35851. */
  35852. var SpritesheetLoader = /** @class */ (function () {
  35853. function SpritesheetLoader() {
  35854. }
  35855. /**
  35856. * Called after a resource is loaded.
  35857. * @see PIXI.Loader.loaderMiddleware
  35858. * @param {PIXI.LoaderResource} resource
  35859. * @param {function} next
  35860. */
  35861. SpritesheetLoader.use = function (resource, next) {
  35862. var _a, _b;
  35863. // because this is middleware, it execute in loader context. `this` = loader
  35864. var loader = this;
  35865. var imageResourceName = resource.name + "_image";
  35866. // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists
  35867. if (!resource.data
  35868. || resource.type !== exports.LoaderResource.TYPE.JSON
  35869. || !resource.data.frames
  35870. || loader.resources[imageResourceName]) {
  35871. next();
  35872. return;
  35873. }
  35874. // Check and add the multi atlas
  35875. // Heavily influenced and based on https://github.com/rocket-ua/pixi-tps-loader/blob/master/src/ResourceLoader.js
  35876. // eslint-disable-next-line camelcase
  35877. var multiPacks = (_b = (_a = resource.data) === null || _a === void 0 ? void 0 : _a.meta) === null || _b === void 0 ? void 0 : _b.related_multi_packs;
  35878. if (Array.isArray(multiPacks)) {
  35879. var _loop_1 = function (item) {
  35880. if (typeof item !== 'string') {
  35881. return "continue";
  35882. }
  35883. var itemName = item.replace('.json', '');
  35884. var itemUrl = url$1.resolve(resource.url.replace(loader.baseUrl, ''), item);
  35885. // Check if the file wasn't already added as multipacks are redundant
  35886. if (loader.resources[itemName]
  35887. || Object.values(loader.resources).some(function (r) { return url$1.format(url$1.parse(r.url)) === itemUrl; })) {
  35888. return "continue";
  35889. }
  35890. var options = {
  35891. crossOrigin: resource.crossOrigin,
  35892. loadType: exports.LoaderResource.LOAD_TYPE.XHR,
  35893. xhrType: exports.LoaderResource.XHR_RESPONSE_TYPE.JSON,
  35894. parentResource: resource,
  35895. };
  35896. loader.add(itemName, itemUrl, options);
  35897. };
  35898. for (var _i = 0, multiPacks_1 = multiPacks; _i < multiPacks_1.length; _i++) {
  35899. var item = multiPacks_1[_i];
  35900. _loop_1(item);
  35901. }
  35902. }
  35903. var loadOptions = {
  35904. crossOrigin: resource.crossOrigin,
  35905. metadata: resource.metadata.imageMetadata,
  35906. parentResource: resource,
  35907. };
  35908. var resourcePath = SpritesheetLoader.getResourcePath(resource, loader.baseUrl);
  35909. // load the image for this sheet
  35910. loader.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) {
  35911. if (res.error) {
  35912. next(res.error);
  35913. return;
  35914. }
  35915. var spritesheet = new Spritesheet(res.texture, resource.data, resource.url);
  35916. spritesheet.parse(function () {
  35917. resource.spritesheet = spritesheet;
  35918. resource.textures = spritesheet.textures;
  35919. next();
  35920. });
  35921. });
  35922. };
  35923. /**
  35924. * Get the spritesheets root path
  35925. * @param {PIXI.LoaderResource} resource - Resource to check path
  35926. * @param {string} baseUrl - Base root url
  35927. */
  35928. SpritesheetLoader.getResourcePath = function (resource, baseUrl) {
  35929. // Prepend url path unless the resource image is a data url
  35930. if (resource.isDataUrl) {
  35931. return resource.data.meta.image;
  35932. }
  35933. return url$1.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image);
  35934. };
  35935. return SpritesheetLoader;
  35936. }());
  35937. /*!
  35938. * @pixi/sprite-tiling - v6.1.2
  35939. * Compiled Thu, 12 Aug 2021 17:11:19 UTC
  35940. *
  35941. * @pixi/sprite-tiling is licensed under the MIT License.
  35942. * http://www.opensource.org/licenses/mit-license
  35943. */
  35944. /*! *****************************************************************************
  35945. Copyright (c) Microsoft Corporation. All rights reserved.
  35946. Licensed under the Apache License, Version 2.0 (the "License"); you may not use
  35947. this file except in compliance with the License. You may obtain a copy of the
  35948. License at http://www.apache.org/licenses/LICENSE-2.0
  35949. THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  35950. KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
  35951. WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
  35952. MERCHANTABLITY OR NON-INFRINGEMENT.
  35953. See the Apache Version 2.0 License for specific language governing permissions
  35954. and limitations under the License.
  35955. ***************************************************************************** */
  35956. /* global Reflect, Promise */
  35957. var extendStatics$9 = function(d, b) {
  35958. extendStatics$9 = Object.setPrototypeOf ||
  35959. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  35960. function (d, b) { for (var p in b) { if (b.hasOwnProperty(p)) { d[p] = b[p]; } } };
  35961. return extendStatics$9(d, b);
  35962. };
  35963. function __extends$9(d, b) {
  35964. extendStatics$9(d, b);
  35965. function __() { this.constructor = d; }
  35966. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  35967. }
  35968. var tempPoint$1 = new Point();
  35969. /**
  35970. * A tiling sprite is a fast way of rendering a tiling image.
  35971. *
  35972. * @class
  35973. * @extends PIXI.Sprite
  35974. * @memberof PIXI
  35975. */
  35976. var TilingSprite = /** @class */ (function (_super) {
  35977. __extends$9(TilingSprite, _super);
  35978. /**
  35979. * @param {PIXI.Texture} texture - the texture of the tiling sprite
  35980. * @param {number} [width=100] - the width of the tiling sprite
  35981. * @param {number} [height=100] - the height of the tiling sprite
  35982. */
  35983. function TilingSprite(texture, width, height) {
  35984. if (width === void 0) { width = 100; }
  35985. if (height === void 0) { height = 100; }
  35986. var _this = _super.call(this, texture) || this;
  35987. /**
  35988. * Tile transform
  35989. *
  35990. * @member {PIXI.Transform}
  35991. */
  35992. _this.tileTransform = new Transform();
  35993. /**
  35994. * The with of the tiling sprite
  35995. *
  35996. * @member {number}
  35997. * @private
  35998. */
  35999. _this._width = width;
  36000. /**
  36001. * The height of the tiling sprite
  36002. *
  36003. * @member {number}
  36004. * @private
  36005. */
  36006. _this._height = height;
  36007. /**
  36008. * matrix that is applied to UV to get the coords in Texture normalized space to coords in BaseTexture space
  36009. *
  36010. * @member {PIXI.TextureMatrix}
  36011. */
  36012. _this.uvMatrix = _this.texture.uvMatrix || new TextureMatrix(texture);
  36013. /**
  36014. * Plugin that is responsible for rendering this element.
  36015. * Allows to customize the rendering process without overriding '_render' method.
  36016. *
  36017. * @member {string}
  36018. * @default 'tilingSprite'
  36019. */
  36020. _this.pluginName = 'tilingSprite';
  36021. /**
  36022. * Flags whether the tiling pattern should originate from the origin instead of the top-left corner in
  36023. * local space.
  36024. *
  36025. * This will make the texture coordinates assigned to each vertex dependent on the value of the anchor. Without
  36026. * this, the top-left corner always gets the (0, 0) texture coordinate.
  36027. *
  36028. * @member {boolean}
  36029. * @default false
  36030. */
  36031. _this.uvRespectAnchor = false;
  36032. return _this;
  36033. }
  36034. Object.defineProperty(TilingSprite.prototype, "clampMargin", {
  36035. /**
  36036. * Changes frame clamping in corresponding textureTransform, shortcut
  36037. * Change to -0.5 to add a pixel to the edge, recommended for transparent trimmed textures in atlas
  36038. *
  36039. * @default 0.5
  36040. * @member {number}
  36041. */
  36042. get: function () {
  36043. return this.uvMatrix.clampMargin;
  36044. },
  36045. set: function (value) {
  36046. this.uvMatrix.clampMargin = value;
  36047. this.uvMatrix.update(true);
  36048. },
  36049. enumerable: false,
  36050. configurable: true
  36051. });
  36052. Object.defineProperty(TilingSprite.prototype, "tileScale", {
  36053. /**
  36054. * The scaling of the image that is being tiled
  36055. *
  36056. * @member {PIXI.ObservablePoint}
  36057. */
  36058. get: function () {
  36059. return this.tileTransform.scale;
  36060. },
  36061. set: function (value) {
  36062. this.tileTransform.scale.copyFrom(value);
  36063. },
  36064. enumerable: false,
  36065. configurable: true
  36066. });
  36067. Object.defineProperty(TilingSprite.prototype, "tilePosition", {
  36068. /**
  36069. * The offset of the image that is being tiled
  36070. *
  36071. * @member {PIXI.ObservablePoint}
  36072. */
  36073. get: function () {
  36074. return this.tileTransform.position;
  36075. },
  36076. set: function (value) {
  36077. this.tileTransform.position.copyFrom(value);
  36078. },
  36079. enumerable: false,
  36080. configurable: true
  36081. });
  36082. /**
  36083. * @protected
  36084. */
  36085. TilingSprite.prototype._onTextureUpdate = function () {
  36086. if (this.uvMatrix) {
  36087. this.uvMatrix.texture = this._texture;
  36088. }
  36089. this._cachedTint = 0xFFFFFF;
  36090. };
  36091. /**
  36092. * Renders the object using the WebGL renderer
  36093. *
  36094. * @protected
  36095. * @param {PIXI.Renderer} renderer - The renderer
  36096. */
  36097. TilingSprite.prototype._render = function (renderer) {
  36098. // tweak our texture temporarily..
  36099. var texture = this._texture;
  36100. if (!texture || !texture.valid) {
  36101. return;
  36102. }
  36103. this.tileTransform.updateLocalTransform();
  36104. this.uvMatrix.update();
  36105. renderer.batch.setObjectRenderer(renderer.plugins[this.pluginName]);
  36106. renderer.plugins[this.pluginName].render(this);
  36107. };
  36108. /**
  36109. * Updates the bounds of the tiling sprite.
  36110. *
  36111. * @protected
  36112. */
  36113. TilingSprite.prototype._calculateBounds = function () {
  36114. var minX = this._width * -this._anchor._x;
  36115. var minY = this._height * -this._anchor._y;
  36116. var maxX = this._width * (1 - this._anchor._x);
  36117. var maxY = this._height * (1 - this._anchor._y);
  36118. this._bounds.addFrame(this.transform, minX, minY, maxX, maxY);
  36119. };
  36120. /**
  36121. * Gets the local bounds of the sprite object.
  36122. *
  36123. * @param {PIXI.Rectangle} [rect] - Optional output rectangle.
  36124. * @return {PIXI.Rectangle} The bounds.
  36125. */
  36126. TilingSprite.prototype.getLocalBounds = function (rect) {
  36127. // we can do a fast local bounds if the sprite has no children!
  36128. if (this.children.length === 0) {
  36129. this._bounds.minX = this._width * -this._anchor._x;
  36130. this._bounds.minY = this._height * -this._anchor._y;
  36131. this._bounds.maxX = this._width * (1 - this._anchor._x);
  36132. this._bounds.maxY = this._height * (1 - this._anchor._y);
  36133. if (!rect) {
  36134. if (!this._localBoundsRect) {
  36135. this._localBoundsRect = new Rectangle();
  36136. }
  36137. rect = this._localBoundsRect;
  36138. }
  36139. return this._bounds.getRectangle(rect);
  36140. }
  36141. return _super.prototype.getLocalBounds.call(this, rect);
  36142. };
  36143. /**
  36144. * Checks if a point is inside this tiling sprite.
  36145. *
  36146. * @param {PIXI.IPointData} point - the point to check
  36147. * @return {boolean} Whether or not the sprite contains the point.
  36148. */
  36149. TilingSprite.prototype.containsPoint = function (point) {
  36150. this.worldTransform.applyInverse(point, tempPoint$1);
  36151. var width = this._width;
  36152. var height = this._height;
  36153. var x1 = -width * this.anchor._x;
  36154. if (tempPoint$1.x >= x1 && tempPoint$1.x < x1 + width) {
  36155. var y1 = -height * this.anchor._y;
  36156. if (tempPoint$1.y >= y1 && tempPoint$1.y < y1 + height) {
  36157. return true;
  36158. }
  36159. }
  36160. return false;
  36161. };
  36162. /**
  36163. * Destroys this sprite and optionally its texture and children
  36164. *
  36165. * @param {object|boolean} [options] - Options parameter. A boolean will act as if all options
  36166. * have been set to that value
  36167. * @param {boolean} [options.children=false] - if set to true, all the children will have their destroy
  36168. * method called as well. 'options' will be passed on to those calls.
  36169. * @param {boolean} [options.texture=false] - Should it destroy the current texture of the sprite as well
  36170. * @param {boolean} [options.baseTexture=false] - Should it destroy the base texture of the sprite as well
  36171. */
  36172. TilingSprite.prototype.destroy = function (options) {
  36173. _super.prototype.destroy.call(this, options);
  36174. this.tileTransform = null;
  36175. this.uvMatrix = null;
  36176. };
  36177. /**
  36178. * Helper function that creates a new tiling sprite based on the source you provide.
  36179. * The source can be - frame id, image url, video url, canvas element, video element, base texture
  36180. *
  36181. * @static
  36182. * @param {string|PIXI.Texture|HTMLCanvasElement|HTMLVideoElement} source - Source to create texture from
  36183. * @param {Object} options - See {@link PIXI.BaseTexture}'s constructor for options.
  36184. * @param {number} options.width - required width of the tiling sprite
  36185. * @param {number} options.height - required height of the tiling sprite
  36186. * @return {PIXI.TilingSprite} The newly created texture
  36187. */
  36188. TilingSprite.from = function (source, options) {
  36189. var texture = (source instanceof Texture)
  36190. ? source
  36191. : Texture.from(source, options);
  36192. return new TilingSprite(texture, options.width, options.height);
  36193. };
  36194. Object.defineProperty(TilingSprite.prototype, "width", {
  36195. /**
  36196. * The width of the sprite, setting this will actually modify the scale to achieve the value set
  36197. *
  36198. * @member {number}
  36199. */
  36200. get: function () {
  36201. return this._width;
  36202. },
  36203. set: function (value) {
  36204. this._width = value;
  36205. },
  36206. enumerable: false,
  36207. configurable: true
  36208. });
  36209. Object.defineProperty(TilingSprite.prototype, "height", {
  36210. /**
  36211. * The height of the TilingSprite, setting this will actually modify the scale to achieve the value set
  36212. *
  36213. * @member {number}
  36214. */
  36215. get: function () {
  36216. return this._height;
  36217. },
  36218. set: function (value) {
  36219. this._height = value;
  36220. },
  36221. enumerable: false,
  36222. configurable: true
  36223. });
  36224. return TilingSprite;
  36225. }(Sprite));
  36226. var vertex$2 = "attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\n\nuniform mat3 projectionMatrix;\nuniform mat3 translationMatrix;\nuniform mat3 uTransform;\n\nvarying vec2 vTextureCoord;\n\nvoid main(void)\n{\n gl_Position = vec4((projectionMatrix * translationMatrix * vec3(aVertexPosition, 1.0)).xy, 0.0, 1.0);\n\n vTextureCoord = (uTransform * vec3(aTextureCoord, 1.0)).xy;\n}\n";
  36227. var fragment$2 = "varying vec2 vTextureCoord;\n\nuniform sampler2D uSampler;\nuniform vec4 uColor;\nuniform mat3 uMapCoord;\nuniform vec4 uClampFrame;\nuniform vec2 uClampOffset;\n\nvoid main(void)\n{\n vec2 coord = vTextureCoord + ceil(uClampOffset - vTextureCoord);\n coord = (uMapCoord * vec3(coord, 1.0)).xy;\n coord = clamp(coord, uClampFrame.xy, uClampFrame.zw);\n\n vec4 texSample = texture2D(uSampler, coord);\n gl_FragColor = texSample * uColor;\n}\n";
  36228. var fragmentSimple = "varying vec2 vTextureCoord;\n\nuniform sampler2D uSampler;\nuniform vec4 uColor;\n\nvoid main(void)\n{\n vec4 sample = texture2D(uSampler, vTextureCoord);\n gl_FragColor = sample * uColor;\n}\n";
  36229. var tempMat$1 = new Matrix();
  36230. /**
  36231. * WebGL renderer plugin for tiling sprites
  36232. *
  36233. * @class
  36234. * @memberof PIXI
  36235. * @extends PIXI.ObjectRenderer
  36236. */
  36237. var TilingSpriteRenderer = /** @class */ (function (_super) {
  36238. __extends$9(TilingSpriteRenderer, _super);
  36239. /**
  36240. * constructor for renderer
  36241. *
  36242. * @param {PIXI.Renderer} renderer - The renderer this tiling awesomeness works for.
  36243. */
  36244. function TilingSpriteRenderer(renderer) {
  36245. var _this = _super.call(this, renderer) || this;
  36246. var uniforms = { globals: _this.renderer.globalUniforms };
  36247. _this.shader = Shader.from(vertex$2, fragment$2, uniforms);
  36248. _this.simpleShader = Shader.from(vertex$2, fragmentSimple, uniforms);
  36249. _this.quad = new QuadUv();
  36250. /**
  36251. * The WebGL state in which this renderer will work.
  36252. *
  36253. * @member {PIXI.State}
  36254. * @readonly
  36255. */
  36256. _this.state = State.for2d();
  36257. return _this;
  36258. }
  36259. /**
  36260. *
  36261. * @param {PIXI.TilingSprite} ts - tilingSprite to be rendered
  36262. */
  36263. TilingSpriteRenderer.prototype.render = function (ts) {
  36264. var renderer = this.renderer;
  36265. var quad = this.quad;
  36266. var vertices = quad.vertices;
  36267. vertices[0] = vertices[6] = (ts._width) * -ts.anchor.x;
  36268. vertices[1] = vertices[3] = ts._height * -ts.anchor.y;
  36269. vertices[2] = vertices[4] = (ts._width) * (1.0 - ts.anchor.x);
  36270. vertices[5] = vertices[7] = ts._height * (1.0 - ts.anchor.y);
  36271. var anchorX = ts.uvRespectAnchor ? ts.anchor.x : 0;
  36272. var anchorY = ts.uvRespectAnchor ? ts.anchor.y : 0;
  36273. vertices = quad.uvs;
  36274. vertices[0] = vertices[6] = -anchorX;
  36275. vertices[1] = vertices[3] = -anchorY;
  36276. vertices[2] = vertices[4] = 1.0 - anchorX;
  36277. vertices[5] = vertices[7] = 1.0 - anchorY;
  36278. quad.invalidate();
  36279. var tex = ts._texture;
  36280. var baseTex = tex.baseTexture;
  36281. var lt = ts.tileTransform.localTransform;
  36282. var uv = ts.uvMatrix;
  36283. var isSimple = baseTex.isPowerOfTwo
  36284. && tex.frame.width === baseTex.width && tex.frame.height === baseTex.height;
  36285. // auto, force repeat wrapMode for big tiling textures
  36286. if (isSimple) {
  36287. if (!baseTex._glTextures[renderer.CONTEXT_UID]) {
  36288. if (baseTex.wrapMode === exports.WRAP_MODES.CLAMP) {
  36289. baseTex.wrapMode = exports.WRAP_MODES.REPEAT;
  36290. }
  36291. }
  36292. else {
  36293. isSimple = baseTex.wrapMode !== exports.WRAP_MODES.CLAMP;
  36294. }
  36295. }
  36296. var shader = isSimple ? this.simpleShader : this.shader;
  36297. var w = tex.width;
  36298. var h = tex.height;
  36299. var W = ts._width;
  36300. var H = ts._height;
  36301. tempMat$1.set(lt.a * w / W, lt.b * w / H, lt.c * h / W, lt.d * h / H, lt.tx / W, lt.ty / H);
  36302. // that part is the same as above:
  36303. // tempMat.identity();
  36304. // tempMat.scale(tex.width, tex.height);
  36305. // tempMat.prepend(lt);
  36306. // tempMat.scale(1.0 / ts._width, 1.0 / ts._height);
  36307. tempMat$1.invert();
  36308. if (isSimple) {
  36309. tempMat$1.prepend(uv.mapCoord);
  36310. }
  36311. else {
  36312. shader.uniforms.uMapCoord = uv.mapCoord.toArray(true);
  36313. shader.uniforms.uClampFrame = uv.uClampFrame;
  36314. shader.uniforms.uClampOffset = uv.uClampOffset;
  36315. }
  36316. shader.uniforms.uTransform = tempMat$1.toArray(true);
  36317. shader.uniforms.uColor = premultiplyTintToRgba(ts.tint, ts.worldAlpha, shader.uniforms.uColor, baseTex.alphaMode);
  36318. shader.uniforms.translationMatrix = ts.transform.worldTransform.toArray(true);
  36319. shader.uniforms.uSampler = tex;
  36320. renderer.shader.bind(shader);
  36321. renderer.geometry.bind(quad);
  36322. this.state.blendMode = correctBlendMode(ts.blendMode, baseTex.alphaMode);
  36323. renderer.state.set(this.state);
  36324. renderer.geometry.draw(this.renderer.gl.TRIANGLES, 6, 0);
  36325. };
  36326. return TilingSpriteRenderer;
  36327. }(ObjectRenderer));
  36328. /*!
  36329. * @pixi/mesh - v6.1.2
  36330. * Compiled Thu, 12 Aug 2021 17:11:19 UTC
  36331. *
  36332. * @pixi/mesh is licensed under the MIT License.
  36333. * http://www.opensource.org/licenses/mit-license
  36334. */
  36335. /*! *****************************************************************************
  36336. Copyright (c) Microsoft Corporation. All rights reserved.
  36337. Licensed under the Apache License, Version 2.0 (the "License"); you may not use
  36338. this file except in compliance with the License. You may obtain a copy of the
  36339. License at http://www.apache.org/licenses/LICENSE-2.0
  36340. THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  36341. KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
  36342. WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
  36343. MERCHANTABLITY OR NON-INFRINGEMENT.
  36344. See the Apache Version 2.0 License for specific language governing permissions
  36345. and limitations under the License.
  36346. ***************************************************************************** */
  36347. /* global Reflect, Promise */
  36348. var extendStatics$a = function(d, b) {
  36349. extendStatics$a = Object.setPrototypeOf ||
  36350. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  36351. function (d, b) { for (var p in b) { if (b.hasOwnProperty(p)) { d[p] = b[p]; } } };
  36352. return extendStatics$a(d, b);
  36353. };
  36354. function __extends$a(d, b) {
  36355. extendStatics$a(d, b);
  36356. function __() { this.constructor = d; }
  36357. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  36358. }
  36359. /**
  36360. * Class controls cache for UV mapping from Texture normal space to BaseTexture normal space.
  36361. *
  36362. * @class
  36363. * @memberof PIXI
  36364. */
  36365. var MeshBatchUvs = /** @class */ (function () {
  36366. /**
  36367. * @param {PIXI.Buffer} uvBuffer - Buffer with normalized uv's
  36368. * @param {PIXI.TextureMatrix} uvMatrix - Material UV matrix
  36369. */
  36370. function MeshBatchUvs(uvBuffer, uvMatrix) {
  36371. /**
  36372. * Buffer with normalized UV's
  36373. * @member {PIXI.Buffer}
  36374. */
  36375. this.uvBuffer = uvBuffer;
  36376. /**
  36377. * Material UV matrix
  36378. * @member {PIXI.TextureMatrix}
  36379. */
  36380. this.uvMatrix = uvMatrix;
  36381. /**
  36382. * UV Buffer data
  36383. * @member {Float32Array}
  36384. * @readonly
  36385. */
  36386. this.data = null;
  36387. this._bufferUpdateId = -1;
  36388. this._textureUpdateId = -1;
  36389. this._updateID = 0;
  36390. }
  36391. /**
  36392. * updates
  36393. *
  36394. * @param {boolean} [forceUpdate] - force the update
  36395. */
  36396. MeshBatchUvs.prototype.update = function (forceUpdate) {
  36397. if (!forceUpdate
  36398. && this._bufferUpdateId === this.uvBuffer._updateID
  36399. && this._textureUpdateId === this.uvMatrix._updateID) {
  36400. return;
  36401. }
  36402. this._bufferUpdateId = this.uvBuffer._updateID;
  36403. this._textureUpdateId = this.uvMatrix._updateID;
  36404. var data = this.uvBuffer.data;
  36405. if (!this.data || this.data.length !== data.length) {
  36406. this.data = new Float32Array(data.length);
  36407. }
  36408. this.uvMatrix.multiplyUvs(data, this.data);
  36409. this._updateID++;
  36410. };
  36411. return MeshBatchUvs;
  36412. }());
  36413. var tempPoint$2 = new Point();
  36414. var tempPolygon = new Polygon();
  36415. /**
  36416. * Base mesh class.
  36417. *
  36418. * This class empowers you to have maximum flexibility to render any kind of WebGL visuals you can think of.
  36419. * This class assumes a certain level of WebGL knowledge.
  36420. * If you know a bit this should abstract enough away to make you life easier!
  36421. *
  36422. * Pretty much ALL WebGL can be broken down into the following:
  36423. * - Geometry - The structure and data for the mesh. This can include anything from positions, uvs, normals, colors etc..
  36424. * - Shader - This is the shader that PixiJS will render the geometry with (attributes in the shader must match the geometry)
  36425. * - State - This is the state of WebGL required to render the mesh.
  36426. *
  36427. * Through a combination of the above elements you can render anything you want, 2D or 3D!
  36428. *
  36429. * @class
  36430. * @extends PIXI.Container
  36431. * @memberof PIXI
  36432. */
  36433. var Mesh = /** @class */ (function (_super) {
  36434. __extends$a(Mesh, _super);
  36435. /**
  36436. * @param {PIXI.Geometry} geometry - the geometry the mesh will use
  36437. * @param {PIXI.MeshMaterial} shader - the shader the mesh will use
  36438. * @param {PIXI.State} [state] - the state that the WebGL context is required to be in to render the mesh
  36439. * if no state is provided, uses {@link PIXI.State.for2d} to create a 2D state for PixiJS.
  36440. * @param {number} [drawMode=PIXI.DRAW_MODES.TRIANGLES] - the drawMode, can be any of the PIXI.DRAW_MODES consts
  36441. */
  36442. function Mesh(geometry, shader, state, drawMode) {
  36443. if (drawMode === void 0) { drawMode = exports.DRAW_MODES.TRIANGLES; }
  36444. var _this = _super.call(this) || this;
  36445. /**
  36446. * Includes vertex positions, face indices, normals, colors, UVs, and
  36447. * custom attributes within buffers, reducing the cost of passing all
  36448. * this data to the GPU. Can be shared between multiple Mesh objects.
  36449. * @member {PIXI.Geometry}
  36450. * @readonly
  36451. */
  36452. _this.geometry = geometry;
  36453. geometry.refCount++;
  36454. /**
  36455. * Represents the vertex and fragment shaders that processes the geometry and runs on the GPU.
  36456. * Can be shared between multiple Mesh objects.
  36457. * @member {PIXI.Shader|PIXI.MeshMaterial}
  36458. */
  36459. _this.shader = shader;
  36460. /**
  36461. * Represents the WebGL state the Mesh required to render, excludes shader and geometry. E.g.,
  36462. * blend mode, culling, depth testing, direction of rendering triangles, backface, etc.
  36463. * @member {PIXI.State}
  36464. */
  36465. _this.state = state || State.for2d();
  36466. /**
  36467. * The way the Mesh should be drawn, can be any of the {@link PIXI.DRAW_MODES} constants.
  36468. *
  36469. * @member {number}
  36470. * @see PIXI.DRAW_MODES
  36471. */
  36472. _this.drawMode = drawMode;
  36473. /**
  36474. * Typically the index of the IndexBuffer where to start drawing.
  36475. * @member {number}
  36476. * @default 0
  36477. */
  36478. _this.start = 0;
  36479. /**
  36480. * How much of the geometry to draw, by default `0` renders everything.
  36481. * @member {number}
  36482. * @default 0
  36483. */
  36484. _this.size = 0;
  36485. /**
  36486. * these are used as easy access for batching
  36487. * @member {Float32Array}
  36488. * @private
  36489. */
  36490. _this.uvs = null;
  36491. /**
  36492. * these are used as easy access for batching
  36493. * @member {Uint16Array}
  36494. * @private
  36495. */
  36496. _this.indices = null;
  36497. /**
  36498. * this is the caching layer used by the batcher
  36499. * @member {Float32Array}
  36500. * @private
  36501. */
  36502. _this.vertexData = new Float32Array(1);
  36503. /**
  36504. * If geometry is changed used to decide to re-transform
  36505. * the vertexData.
  36506. * @member {number}
  36507. * @private
  36508. */
  36509. _this.vertexDirty = -1;
  36510. _this._transformID = -1;
  36511. /**
  36512. * Internal roundPixels field
  36513. *
  36514. * @member {boolean}
  36515. * @private
  36516. */
  36517. _this._roundPixels = settings.ROUND_PIXELS;
  36518. /**
  36519. * Batched UV's are cached for atlas textures
  36520. * @member {PIXI.MeshBatchUvs}
  36521. * @private
  36522. */
  36523. _this.batchUvs = null;
  36524. return _this;
  36525. }
  36526. Object.defineProperty(Mesh.prototype, "uvBuffer", {
  36527. /**
  36528. * To change mesh uv's, change its uvBuffer data and increment its _updateID.
  36529. * @member {PIXI.Buffer}
  36530. * @readonly
  36531. */
  36532. get: function () {
  36533. return this.geometry.buffers[1];
  36534. },
  36535. enumerable: false,
  36536. configurable: true
  36537. });
  36538. Object.defineProperty(Mesh.prototype, "verticesBuffer", {
  36539. /**
  36540. * To change mesh vertices, change its uvBuffer data and increment its _updateID.
  36541. * Incrementing _updateID is optional because most of Mesh objects do it anyway.
  36542. * @member {PIXI.Buffer}
  36543. * @readonly
  36544. */
  36545. get: function () {
  36546. return this.geometry.buffers[0];
  36547. },
  36548. enumerable: false,
  36549. configurable: true
  36550. });
  36551. Object.defineProperty(Mesh.prototype, "material", {
  36552. get: function () {
  36553. return this.shader;
  36554. },
  36555. /**
  36556. * Alias for {@link PIXI.Mesh#shader}.
  36557. * @member {PIXI.MeshMaterial}
  36558. */
  36559. set: function (value) {
  36560. this.shader = value;
  36561. },
  36562. enumerable: false,
  36563. configurable: true
  36564. });
  36565. Object.defineProperty(Mesh.prototype, "blendMode", {
  36566. get: function () {
  36567. return this.state.blendMode;
  36568. },
  36569. /**
  36570. * The blend mode to be applied to the Mesh. Apply a value of
  36571. * `PIXI.BLEND_MODES.NORMAL` to reset the blend mode.
  36572. *
  36573. * @member {number}
  36574. * @default PIXI.BLEND_MODES.NORMAL;
  36575. * @see PIXI.BLEND_MODES
  36576. */
  36577. set: function (value) {
  36578. this.state.blendMode = value;
  36579. },
  36580. enumerable: false,
  36581. configurable: true
  36582. });
  36583. Object.defineProperty(Mesh.prototype, "roundPixels", {
  36584. get: function () {
  36585. return this._roundPixels;
  36586. },
  36587. /**
  36588. * If true PixiJS will Math.floor() x/y values when rendering, stopping pixel interpolation.
  36589. * Advantages can include sharper image quality (like text) and faster rendering on canvas.
  36590. * The main disadvantage is movement of objects may appear less smooth.
  36591. * To set the global default, change {@link PIXI.settings.ROUND_PIXELS}
  36592. *
  36593. * @member {boolean}
  36594. * @default false
  36595. */
  36596. set: function (value) {
  36597. if (this._roundPixels !== value) {
  36598. this._transformID = -1;
  36599. }
  36600. this._roundPixels = value;
  36601. },
  36602. enumerable: false,
  36603. configurable: true
  36604. });
  36605. Object.defineProperty(Mesh.prototype, "tint", {
  36606. /**
  36607. * The multiply tint applied to the Mesh. This is a hex value. A value of
  36608. * `0xFFFFFF` will remove any tint effect.
  36609. *
  36610. * Null for non-MeshMaterial shaders
  36611. * @member {number}
  36612. * @default 0xFFFFFF
  36613. */
  36614. get: function () {
  36615. return 'tint' in this.shader ? this.shader.tint : null;
  36616. },
  36617. set: function (value) {
  36618. this.shader.tint = value;
  36619. },
  36620. enumerable: false,
  36621. configurable: true
  36622. });
  36623. Object.defineProperty(Mesh.prototype, "texture", {
  36624. /**
  36625. * The texture that the Mesh uses.
  36626. *
  36627. * Null for non-MeshMaterial shaders
  36628. * @member {PIXI.Texture}
  36629. */
  36630. get: function () {
  36631. return 'texture' in this.shader ? this.shader.texture : null;
  36632. },
  36633. set: function (value) {
  36634. this.shader.texture = value;
  36635. },
  36636. enumerable: false,
  36637. configurable: true
  36638. });
  36639. /**
  36640. * Standard renderer draw.
  36641. * @protected
  36642. * @param {PIXI.Renderer} renderer - Instance to renderer.
  36643. */
  36644. Mesh.prototype._render = function (renderer) {
  36645. // set properties for batching..
  36646. // TODO could use a different way to grab verts?
  36647. var vertices = this.geometry.buffers[0].data;
  36648. var shader = this.shader;
  36649. // TODO benchmark check for attribute size..
  36650. if (shader.batchable
  36651. && this.drawMode === exports.DRAW_MODES.TRIANGLES
  36652. && vertices.length < Mesh.BATCHABLE_SIZE * 2) {
  36653. this._renderToBatch(renderer);
  36654. }
  36655. else {
  36656. this._renderDefault(renderer);
  36657. }
  36658. };
  36659. /**
  36660. * Standard non-batching way of rendering.
  36661. * @protected
  36662. * @param {PIXI.Renderer} renderer - Instance to renderer.
  36663. */
  36664. Mesh.prototype._renderDefault = function (renderer) {
  36665. var shader = this.shader;
  36666. shader.alpha = this.worldAlpha;
  36667. if (shader.update) {
  36668. shader.update();
  36669. }
  36670. renderer.batch.flush();
  36671. // bind and sync uniforms..
  36672. shader.uniforms.translationMatrix = this.transform.worldTransform.toArray(true);
  36673. renderer.shader.bind(shader);
  36674. // set state..
  36675. renderer.state.set(this.state);
  36676. // bind the geometry...
  36677. renderer.geometry.bind(this.geometry, shader);
  36678. // then render it
  36679. renderer.geometry.draw(this.drawMode, this.size, this.start, this.geometry.instanceCount);
  36680. };
  36681. /**
  36682. * Rendering by using the Batch system.
  36683. * @protected
  36684. * @param {PIXI.Renderer} renderer - Instance to renderer.
  36685. */
  36686. Mesh.prototype._renderToBatch = function (renderer) {
  36687. var geometry = this.geometry;
  36688. var shader = this.shader;
  36689. if (shader.uvMatrix) {
  36690. shader.uvMatrix.update();
  36691. this.calculateUvs();
  36692. }
  36693. // set properties for batching..
  36694. this.calculateVertices();
  36695. this.indices = geometry.indexBuffer.data;
  36696. this._tintRGB = shader._tintRGB;
  36697. this._texture = shader.texture;
  36698. var pluginName = this.material.pluginName;
  36699. renderer.batch.setObjectRenderer(renderer.plugins[pluginName]);
  36700. renderer.plugins[pluginName].render(this);
  36701. };
  36702. /**
  36703. * Updates vertexData field based on transform and vertices
  36704. */
  36705. Mesh.prototype.calculateVertices = function () {
  36706. var geometry = this.geometry;
  36707. var verticesBuffer = geometry.buffers[0];
  36708. var vertices = verticesBuffer.data;
  36709. var vertexDirtyId = verticesBuffer._updateID;
  36710. if (vertexDirtyId === this.vertexDirty && this._transformID === this.transform._worldID) {
  36711. return;
  36712. }
  36713. this._transformID = this.transform._worldID;
  36714. if (this.vertexData.length !== vertices.length) {
  36715. this.vertexData = new Float32Array(vertices.length);
  36716. }
  36717. var wt = this.transform.worldTransform;
  36718. var a = wt.a;
  36719. var b = wt.b;
  36720. var c = wt.c;
  36721. var d = wt.d;
  36722. var tx = wt.tx;
  36723. var ty = wt.ty;
  36724. var vertexData = this.vertexData;
  36725. for (var i = 0; i < vertexData.length / 2; i++) {
  36726. var x = vertices[(i * 2)];
  36727. var y = vertices[(i * 2) + 1];
  36728. vertexData[(i * 2)] = (a * x) + (c * y) + tx;
  36729. vertexData[(i * 2) + 1] = (b * x) + (d * y) + ty;
  36730. }
  36731. if (this._roundPixels) {
  36732. var resolution = settings.RESOLUTION;
  36733. for (var i = 0; i < vertexData.length; ++i) {
  36734. vertexData[i] = Math.round((vertexData[i] * resolution | 0) / resolution);
  36735. }
  36736. }
  36737. this.vertexDirty = vertexDirtyId;
  36738. };
  36739. /**
  36740. * Updates uv field based on from geometry uv's or batchUvs
  36741. */
  36742. Mesh.prototype.calculateUvs = function () {
  36743. var geomUvs = this.geometry.buffers[1];
  36744. var shader = this.shader;
  36745. if (!shader.uvMatrix.isSimple) {
  36746. if (!this.batchUvs) {
  36747. this.batchUvs = new MeshBatchUvs(geomUvs, shader.uvMatrix);
  36748. }
  36749. this.batchUvs.update();
  36750. this.uvs = this.batchUvs.data;
  36751. }
  36752. else {
  36753. this.uvs = geomUvs.data;
  36754. }
  36755. };
  36756. /**
  36757. * Updates the bounds of the mesh as a rectangle. The bounds calculation takes the worldTransform into account.
  36758. * there must be a aVertexPosition attribute present in the geometry for bounds to be calculated correctly.
  36759. *
  36760. * @protected
  36761. */
  36762. Mesh.prototype._calculateBounds = function () {
  36763. this.calculateVertices();
  36764. this._bounds.addVertexData(this.vertexData, 0, this.vertexData.length);
  36765. };
  36766. /**
  36767. * Tests if a point is inside this mesh. Works only for PIXI.DRAW_MODES.TRIANGLES.
  36768. *
  36769. * @param {PIXI.IPointData} point - the point to test
  36770. * @return {boolean} the result of the test
  36771. */
  36772. Mesh.prototype.containsPoint = function (point) {
  36773. if (!this.getBounds().contains(point.x, point.y)) {
  36774. return false;
  36775. }
  36776. this.worldTransform.applyInverse(point, tempPoint$2);
  36777. var vertices = this.geometry.getBuffer('aVertexPosition').data;
  36778. var points = tempPolygon.points;
  36779. var indices = this.geometry.getIndex().data;
  36780. var len = indices.length;
  36781. var step = this.drawMode === 4 ? 3 : 1;
  36782. for (var i = 0; i + 2 < len; i += step) {
  36783. var ind0 = indices[i] * 2;
  36784. var ind1 = indices[i + 1] * 2;
  36785. var ind2 = indices[i + 2] * 2;
  36786. points[0] = vertices[ind0];
  36787. points[1] = vertices[ind0 + 1];
  36788. points[2] = vertices[ind1];
  36789. points[3] = vertices[ind1 + 1];
  36790. points[4] = vertices[ind2];
  36791. points[5] = vertices[ind2 + 1];
  36792. if (tempPolygon.contains(tempPoint$2.x, tempPoint$2.y)) {
  36793. return true;
  36794. }
  36795. }
  36796. return false;
  36797. };
  36798. /**
  36799. * Destroys the Mesh object.
  36800. *
  36801. * @param {object|boolean} [options] - Options parameter. A boolean will act as if all
  36802. * options have been set to that value
  36803. * @param {boolean} [options.children=false] - if set to true, all the children will have
  36804. * their destroy method called as well. 'options' will be passed on to those calls.
  36805. */
  36806. Mesh.prototype.destroy = function (options) {
  36807. _super.prototype.destroy.call(this, options);
  36808. this.geometry.refCount--;
  36809. if (this.geometry.refCount === 0) {
  36810. this.geometry.dispose();
  36811. }
  36812. if (this._cachedTexture) {
  36813. this._cachedTexture.destroy();
  36814. this._cachedTexture = null;
  36815. }
  36816. this.geometry = null;
  36817. this.shader = null;
  36818. this.state = null;
  36819. this.uvs = null;
  36820. this.indices = null;
  36821. this.vertexData = null;
  36822. };
  36823. /**
  36824. * The maximum number of vertices to consider batchable. Generally, the complexity
  36825. * of the geometry.
  36826. * @memberof PIXI.Mesh
  36827. * @static
  36828. * @member {number} BATCHABLE_SIZE
  36829. */
  36830. Mesh.BATCHABLE_SIZE = 100;
  36831. return Mesh;
  36832. }(Container));
  36833. var fragment$3 = "varying vec2 vTextureCoord;\nuniform vec4 uColor;\n\nuniform sampler2D uSampler;\n\nvoid main(void)\n{\n gl_FragColor = texture2D(uSampler, vTextureCoord) * uColor;\n}\n";
  36834. var vertex$3 = "attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\n\nuniform mat3 projectionMatrix;\nuniform mat3 translationMatrix;\nuniform mat3 uTextureMatrix;\n\nvarying vec2 vTextureCoord;\n\nvoid main(void)\n{\n gl_Position = vec4((projectionMatrix * translationMatrix * vec3(aVertexPosition, 1.0)).xy, 0.0, 1.0);\n\n vTextureCoord = (uTextureMatrix * vec3(aTextureCoord, 1.0)).xy;\n}\n";
  36835. /**
  36836. * Slightly opinionated default shader for PixiJS 2D objects.
  36837. * @class
  36838. * @memberof PIXI
  36839. * @extends PIXI.Shader
  36840. */
  36841. var MeshMaterial = /** @class */ (function (_super) {
  36842. __extends$a(MeshMaterial, _super);
  36843. /**
  36844. * @param {PIXI.Texture} uSampler - Texture that material uses to render.
  36845. * @param {object} [options] - Additional options
  36846. * @param {number} [options.alpha=1] - Default alpha.
  36847. * @param {number} [options.tint=0xFFFFFF] - Default tint.
  36848. * @param {string} [options.pluginName='batch'] - Renderer plugin for batching.
  36849. * @param {PIXI.Program} [options.program=0xFFFFFF] - Custom program.
  36850. * @param {object} [options.uniforms] - Custom uniforms.
  36851. */
  36852. function MeshMaterial(uSampler, options) {
  36853. var _this = this;
  36854. var uniforms = {
  36855. uSampler: uSampler,
  36856. alpha: 1,
  36857. uTextureMatrix: Matrix.IDENTITY,
  36858. uColor: new Float32Array([1, 1, 1, 1]),
  36859. };
  36860. // Set defaults
  36861. options = Object.assign({
  36862. tint: 0xFFFFFF,
  36863. alpha: 1,
  36864. pluginName: 'batch',
  36865. }, options);
  36866. if (options.uniforms) {
  36867. Object.assign(uniforms, options.uniforms);
  36868. }
  36869. _this = _super.call(this, options.program || Program.from(vertex$3, fragment$3), uniforms) || this;
  36870. /**
  36871. * Only do update if tint or alpha changes.
  36872. * @member {boolean}
  36873. * @private
  36874. * @default false
  36875. */
  36876. _this._colorDirty = false;
  36877. /**
  36878. * TextureMatrix instance for this Mesh, used to track Texture changes
  36879. *
  36880. * @member {PIXI.TextureMatrix}
  36881. * @readonly
  36882. */
  36883. _this.uvMatrix = new TextureMatrix(uSampler);
  36884. /**
  36885. * `true` if shader can be batch with the renderer's batch system.
  36886. * @member {boolean}
  36887. * @default true
  36888. */
  36889. _this.batchable = options.program === undefined;
  36890. /**
  36891. * Renderer plugin for batching
  36892. *
  36893. * @member {string}
  36894. * @default 'batch'
  36895. */
  36896. _this.pluginName = options.pluginName;
  36897. _this.tint = options.tint;
  36898. _this.alpha = options.alpha;
  36899. return _this;
  36900. }
  36901. Object.defineProperty(MeshMaterial.prototype, "texture", {
  36902. /**
  36903. * Reference to the texture being rendered.
  36904. * @member {PIXI.Texture}
  36905. */
  36906. get: function () {
  36907. return this.uniforms.uSampler;
  36908. },
  36909. set: function (value) {
  36910. if (this.uniforms.uSampler !== value) {
  36911. this.uniforms.uSampler = value;
  36912. this.uvMatrix.texture = value;
  36913. }
  36914. },
  36915. enumerable: false,
  36916. configurable: true
  36917. });
  36918. Object.defineProperty(MeshMaterial.prototype, "alpha", {
  36919. get: function () {
  36920. return this._alpha;
  36921. },
  36922. /**
  36923. * This gets automatically set by the object using this.
  36924. *
  36925. * @default 1
  36926. * @member {number}
  36927. */
  36928. set: function (value) {
  36929. if (value === this._alpha)
  36930. { return; }
  36931. this._alpha = value;
  36932. this._colorDirty = true;
  36933. },
  36934. enumerable: false,
  36935. configurable: true
  36936. });
  36937. Object.defineProperty(MeshMaterial.prototype, "tint", {
  36938. get: function () {
  36939. return this._tint;
  36940. },
  36941. /**
  36942. * Multiply tint for the material.
  36943. * @member {number}
  36944. * @default 0xFFFFFF
  36945. */
  36946. set: function (value) {
  36947. if (value === this._tint)
  36948. { return; }
  36949. this._tint = value;
  36950. this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16);
  36951. this._colorDirty = true;
  36952. },
  36953. enumerable: false,
  36954. configurable: true
  36955. });
  36956. /**
  36957. * Gets called automatically by the Mesh. Intended to be overridden for custom
  36958. * MeshMaterial objects.
  36959. */
  36960. MeshMaterial.prototype.update = function () {
  36961. if (this._colorDirty) {
  36962. this._colorDirty = false;
  36963. var baseTexture = this.texture.baseTexture;
  36964. premultiplyTintToRgba(this._tint, this._alpha, this.uniforms.uColor, baseTexture.alphaMode);
  36965. }
  36966. if (this.uvMatrix.update()) {
  36967. this.uniforms.uTextureMatrix = this.uvMatrix.mapCoord;
  36968. }
  36969. };
  36970. return MeshMaterial;
  36971. }(Shader));
  36972. /**
  36973. * Standard 2D geometry used in PixiJS.
  36974. *
  36975. * Geometry can be defined without passing in a style or data if required.
  36976. *
  36977. * ```js
  36978. * const geometry = new PIXI.Geometry();
  36979. *
  36980. * geometry.addAttribute('positions', [0, 0, 100, 0, 100, 100, 0, 100], 2);
  36981. * geometry.addAttribute('uvs', [0,0,1,0,1,1,0,1], 2);
  36982. * geometry.addIndex([0,1,2,1,3,2]);
  36983. *
  36984. * ```
  36985. * @class
  36986. * @memberof PIXI
  36987. * @extends PIXI.Geometry
  36988. */
  36989. var MeshGeometry = /** @class */ (function (_super) {
  36990. __extends$a(MeshGeometry, _super);
  36991. /**
  36992. * @param {Float32Array|number[]} [vertices] - Positional data on geometry.
  36993. * @param {Float32Array|number[]} [uvs] - Texture UVs.
  36994. * @param {Uint16Array|number[]} [index] - IndexBuffer
  36995. */
  36996. function MeshGeometry(vertices, uvs, index) {
  36997. var _this = _super.call(this) || this;
  36998. var verticesBuffer = new Buffer(vertices);
  36999. var uvsBuffer = new Buffer(uvs, true);
  37000. var indexBuffer = new Buffer(index, true, true);
  37001. _this.addAttribute('aVertexPosition', verticesBuffer, 2, false, exports.TYPES.FLOAT)
  37002. .addAttribute('aTextureCoord', uvsBuffer, 2, false, exports.TYPES.FLOAT)
  37003. .addIndex(indexBuffer);
  37004. /**
  37005. * Dirty flag to limit update calls on Mesh. For example,
  37006. * limiting updates on a single Mesh instance with a shared Geometry
  37007. * within the render loop.
  37008. * @private
  37009. * @member {number}
  37010. * @default -1
  37011. */
  37012. _this._updateId = -1;
  37013. return _this;
  37014. }
  37015. Object.defineProperty(MeshGeometry.prototype, "vertexDirtyId", {
  37016. /**
  37017. * If the vertex position is updated.
  37018. * @member {number}
  37019. * @readonly
  37020. * @private
  37021. */
  37022. get: function () {
  37023. return this.buffers[0]._updateID;
  37024. },
  37025. enumerable: false,
  37026. configurable: true
  37027. });
  37028. return MeshGeometry;
  37029. }(Geometry));
  37030. /*!
  37031. * @pixi/text-bitmap - v6.1.2
  37032. * Compiled Thu, 12 Aug 2021 17:11:19 UTC
  37033. *
  37034. * @pixi/text-bitmap is licensed under the MIT License.
  37035. * http://www.opensource.org/licenses/mit-license
  37036. */
  37037. /*! *****************************************************************************
  37038. Copyright (c) Microsoft Corporation. All rights reserved.
  37039. Licensed under the Apache License, Version 2.0 (the "License"); you may not use
  37040. this file except in compliance with the License. You may obtain a copy of the
  37041. License at http://www.apache.org/licenses/LICENSE-2.0
  37042. THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  37043. KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
  37044. WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
  37045. MERCHANTABLITY OR NON-INFRINGEMENT.
  37046. See the Apache Version 2.0 License for specific language governing permissions
  37047. and limitations under the License.
  37048. ***************************************************************************** */
  37049. /* global Reflect, Promise */
  37050. var extendStatics$b = function(d, b) {
  37051. extendStatics$b = Object.setPrototypeOf ||
  37052. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  37053. function (d, b) { for (var p in b) { if (b.hasOwnProperty(p)) { d[p] = b[p]; } } };
  37054. return extendStatics$b(d, b);
  37055. };
  37056. function __extends$b(d, b) {
  37057. extendStatics$b(d, b);
  37058. function __() { this.constructor = d; }
  37059. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  37060. }
  37061. /* eslint-disable max-len */
  37062. /**
  37063. * Normalized parsed data from .fnt files.
  37064. *
  37065. * @class
  37066. * @memberof PIXI
  37067. */
  37068. var BitmapFontData = /** @class */ (function () {
  37069. function BitmapFontData() {
  37070. /**
  37071. * @member {PIXI.IBitmapFontDataInfo[]}
  37072. * @readOnly
  37073. */
  37074. this.info = [];
  37075. /**
  37076. * @member {PIXI.IBitmapFontDataCommon[]}
  37077. * @readOnly
  37078. */
  37079. this.common = [];
  37080. /**
  37081. * @member {PIXI.IBitmapFontDataPage[]}
  37082. * @readOnly
  37083. */
  37084. this.page = [];
  37085. /**
  37086. * @member {PIXI.IBitmapFontDataChar[]}
  37087. * @readOnly
  37088. */
  37089. this.char = [];
  37090. /**
  37091. * @member {PIXI.IBitmapFontDataKerning[]}
  37092. * @readOnly
  37093. */
  37094. this.kerning = [];
  37095. }
  37096. return BitmapFontData;
  37097. }());
  37098. /**
  37099. * @memberof PIXI
  37100. * @typedef {object} IBitmapFontDataInfo
  37101. * @property {string} face
  37102. * @property {number} size
  37103. */
  37104. /**
  37105. * @memberof PIXI
  37106. * @typedef {object} IBitmapFontDataCommon
  37107. * @property {number} lineHeight
  37108. */
  37109. /**
  37110. * @memberof PIXI
  37111. * @typedef {object} IBitmapFontDataPage
  37112. * @property {number} id
  37113. * @property {string} file
  37114. */
  37115. /**
  37116. * @memberof PIXI
  37117. * @typedef {object} IBitmapFontDataChar
  37118. * @property {string} id
  37119. * @property {number} page
  37120. * @property {number} x
  37121. * @property {number} y
  37122. * @property {number} width
  37123. * @property {number} height
  37124. * @property {number} xoffset
  37125. * @property {number} yoffset
  37126. * @property {number} xadvance
  37127. */
  37128. /**
  37129. * @memberof PIXI
  37130. * @typedef {object} IBitmapFontDataKerning
  37131. * @property {number} first
  37132. * @property {number} second
  37133. * @property {number} amount
  37134. */
  37135. /**
  37136. * BitmapFont format that's Text-based.
  37137. *
  37138. * @class
  37139. * @private
  37140. */
  37141. var TextFormat = /** @class */ (function () {
  37142. function TextFormat() {
  37143. }
  37144. /**
  37145. * Check if resource refers to txt font data.
  37146. *
  37147. * @static
  37148. * @private
  37149. * @param {any} data
  37150. * @return {boolean} True if resource could be treated as font data, false otherwise.
  37151. */
  37152. TextFormat.test = function (data) {
  37153. return typeof data === 'string' && data.indexOf('info face=') === 0;
  37154. };
  37155. /**
  37156. * Convert text font data to a javascript object.
  37157. *
  37158. * @static
  37159. * @private
  37160. * @param {string} txt - Raw string data to be converted
  37161. * @return {PIXI.BitmapFontData} Parsed font data
  37162. */
  37163. TextFormat.parse = function (txt) {
  37164. // Retrieve data item
  37165. var items = txt.match(/^[a-z]+\s+.+$/gm);
  37166. var rawData = {
  37167. info: [],
  37168. common: [],
  37169. page: [],
  37170. char: [],
  37171. chars: [],
  37172. kerning: [],
  37173. kernings: [],
  37174. };
  37175. for (var i in items) {
  37176. // Extract item name
  37177. var name = items[i].match(/^[a-z]+/gm)[0];
  37178. // Extract item attribute list as string ex.: "width=10"
  37179. var attributeList = items[i].match(/[a-zA-Z]+=([^\s"']+|"([^"]*)")/gm);
  37180. // Convert attribute list into an object
  37181. var itemData = {};
  37182. for (var i_1 in attributeList) {
  37183. // Split key-value pairs
  37184. var split = attributeList[i_1].split('=');
  37185. var key = split[0];
  37186. // Remove eventual quotes from value
  37187. var strValue = split[1].replace(/"/gm, '');
  37188. // Try to convert value into float
  37189. var floatValue = parseFloat(strValue);
  37190. // Use string value case float value is NaN
  37191. var value = isNaN(floatValue) ? strValue : floatValue;
  37192. itemData[key] = value;
  37193. }
  37194. // Push current item to the resulting data
  37195. rawData[name].push(itemData);
  37196. }
  37197. var font = new BitmapFontData();
  37198. rawData.info.forEach(function (info) { return font.info.push({
  37199. face: info.face,
  37200. size: parseInt(info.size, 10),
  37201. }); });
  37202. rawData.common.forEach(function (common) { return font.common.push({
  37203. lineHeight: parseInt(common.lineHeight, 10),
  37204. }); });
  37205. rawData.page.forEach(function (page) { return font.page.push({
  37206. id: parseInt(page.id, 10),
  37207. file: page.file,
  37208. }); });
  37209. rawData.char.forEach(function (char) { return font.char.push({
  37210. id: parseInt(char.id, 10),
  37211. page: parseInt(char.page, 10),
  37212. x: parseInt(char.x, 10),
  37213. y: parseInt(char.y, 10),
  37214. width: parseInt(char.width, 10),
  37215. height: parseInt(char.height, 10),
  37216. xoffset: parseInt(char.xoffset, 10),
  37217. yoffset: parseInt(char.yoffset, 10),
  37218. xadvance: parseInt(char.xadvance, 10),
  37219. }); });
  37220. rawData.kerning.forEach(function (kerning) { return font.kerning.push({
  37221. first: parseInt(kerning.first, 10),
  37222. second: parseInt(kerning.second, 10),
  37223. amount: parseInt(kerning.amount, 10),
  37224. }); });
  37225. return font;
  37226. };
  37227. return TextFormat;
  37228. }());
  37229. /**
  37230. * BitmapFont format that's XML-based.
  37231. *
  37232. * @class
  37233. * @private
  37234. */
  37235. var XMLFormat = /** @class */ (function () {
  37236. function XMLFormat() {
  37237. }
  37238. /**
  37239. * Check if resource refers to xml font data.
  37240. *
  37241. * @static
  37242. * @private
  37243. * @param {any} data
  37244. * @return {boolean} True if resource could be treated as font data, false otherwise.
  37245. */
  37246. XMLFormat.test = function (data) {
  37247. return data instanceof XMLDocument
  37248. && data.getElementsByTagName('page').length
  37249. && data.getElementsByTagName('info')[0].getAttribute('face') !== null;
  37250. };
  37251. /**
  37252. * Convert the XML into BitmapFontData that we can use.
  37253. *
  37254. * @static
  37255. * @private
  37256. * @param {XMLDocument} xml
  37257. * @return {BitmapFontData} Data to use for BitmapFont
  37258. */
  37259. XMLFormat.parse = function (xml) {
  37260. var data = new BitmapFontData();
  37261. var info = xml.getElementsByTagName('info');
  37262. var common = xml.getElementsByTagName('common');
  37263. var page = xml.getElementsByTagName('page');
  37264. var char = xml.getElementsByTagName('char');
  37265. var kerning = xml.getElementsByTagName('kerning');
  37266. for (var i = 0; i < info.length; i++) {
  37267. data.info.push({
  37268. face: info[i].getAttribute('face'),
  37269. size: parseInt(info[i].getAttribute('size'), 10),
  37270. });
  37271. }
  37272. for (var i = 0; i < common.length; i++) {
  37273. data.common.push({
  37274. lineHeight: parseInt(common[i].getAttribute('lineHeight'), 10),
  37275. });
  37276. }
  37277. for (var i = 0; i < page.length; i++) {
  37278. data.page.push({
  37279. id: parseInt(page[i].getAttribute('id'), 10) || 0,
  37280. file: page[i].getAttribute('file'),
  37281. });
  37282. }
  37283. for (var i = 0; i < char.length; i++) {
  37284. var letter = char[i];
  37285. data.char.push({
  37286. id: parseInt(letter.getAttribute('id'), 10),
  37287. page: parseInt(letter.getAttribute('page'), 10) || 0,
  37288. x: parseInt(letter.getAttribute('x'), 10),
  37289. y: parseInt(letter.getAttribute('y'), 10),
  37290. width: parseInt(letter.getAttribute('width'), 10),
  37291. height: parseInt(letter.getAttribute('height'), 10),
  37292. xoffset: parseInt(letter.getAttribute('xoffset'), 10),
  37293. yoffset: parseInt(letter.getAttribute('yoffset'), 10),
  37294. xadvance: parseInt(letter.getAttribute('xadvance'), 10),
  37295. });
  37296. }
  37297. for (var i = 0; i < kerning.length; i++) {
  37298. data.kerning.push({
  37299. first: parseInt(kerning[i].getAttribute('first'), 10),
  37300. second: parseInt(kerning[i].getAttribute('second'), 10),
  37301. amount: parseInt(kerning[i].getAttribute('amount'), 10),
  37302. });
  37303. }
  37304. return data;
  37305. };
  37306. return XMLFormat;
  37307. }());
  37308. /**
  37309. * BitmapFont format that's XML-based.
  37310. *
  37311. * @class
  37312. * @private
  37313. */
  37314. var XMLStringFormat = /** @class */ (function () {
  37315. function XMLStringFormat() {
  37316. }
  37317. /**
  37318. * Check if resource refers to text xml font data.
  37319. *
  37320. * @static
  37321. * @private
  37322. * @param {any} data
  37323. * @return {boolean} True if resource could be treated as font data, false otherwise.
  37324. */
  37325. XMLStringFormat.test = function (data) {
  37326. if (typeof data === 'string' && data.indexOf('<font>') > -1) {
  37327. var xml = new self.DOMParser().parseFromString(data, 'text/xml');
  37328. return XMLFormat.test(xml);
  37329. }
  37330. return false;
  37331. };
  37332. /**
  37333. * Convert the text XML into BitmapFontData that we can use.
  37334. *
  37335. * @static
  37336. * @private
  37337. * @param {string} xmlTxt
  37338. * @return {BitmapFontData} Data to use for BitmapFont
  37339. */
  37340. XMLStringFormat.parse = function (xmlTxt) {
  37341. var xml = new self.DOMParser().parseFromString(xmlTxt, 'text/xml');
  37342. return XMLFormat.parse(xml);
  37343. };
  37344. return XMLStringFormat;
  37345. }());
  37346. // Registered formats, maybe make this extensible in the future?
  37347. var formats = [
  37348. TextFormat,
  37349. XMLFormat,
  37350. XMLStringFormat ];
  37351. /**
  37352. * Auto-detect BitmapFont parsing format based on data.
  37353. * @private
  37354. * @param {any} data - Data to detect format
  37355. * @return {any} Format or null
  37356. */
  37357. function autoDetectFormat(data) {
  37358. for (var i = 0; i < formats.length; i++) {
  37359. if (formats[i].test(data)) {
  37360. return formats[i];
  37361. }
  37362. }
  37363. return null;
  37364. }
  37365. // TODO: Prevent code duplication b/w generateFillStyle & Text#generateFillStyle
  37366. /**
  37367. * Generates the fill style. Can automatically generate a gradient based on the fill style being an array
  37368. *
  37369. * @private
  37370. * @param {object} style - The style.
  37371. * @param {string[]} lines - The lines of text.
  37372. * @return {string|number|CanvasGradient} The fill style
  37373. */
  37374. function generateFillStyle(canvas, context, style, resolution, lines, metrics) {
  37375. // TODO: Can't have different types for getter and setter. The getter shouldn't have the number type as
  37376. // the setter converts to string. See this thread for more details:
  37377. // https://github.com/microsoft/TypeScript/issues/2521
  37378. var fillStyle = style.fill;
  37379. if (!Array.isArray(fillStyle)) {
  37380. return fillStyle;
  37381. }
  37382. else if (fillStyle.length === 1) {
  37383. return fillStyle[0];
  37384. }
  37385. // the gradient will be evenly spaced out according to how large the array is.
  37386. // ['#FF0000', '#00FF00', '#0000FF'] would created stops at 0.25, 0.5 and 0.75
  37387. var gradient;
  37388. // a dropshadow will enlarge the canvas and result in the gradient being
  37389. // generated with the incorrect dimensions
  37390. var dropShadowCorrection = (style.dropShadow) ? style.dropShadowDistance : 0;
  37391. // should also take padding into account, padding can offset the gradient
  37392. var padding = style.padding || 0;
  37393. var width = (canvas.width / resolution) - dropShadowCorrection - (padding * 2);
  37394. var height = (canvas.height / resolution) - dropShadowCorrection - (padding * 2);
  37395. // make a copy of the style settings, so we can manipulate them later
  37396. var fill = fillStyle.slice();
  37397. var fillGradientStops = style.fillGradientStops.slice();
  37398. // wanting to evenly distribute the fills. So an array of 4 colours should give fills of 0.25, 0.5 and 0.75
  37399. if (!fillGradientStops.length) {
  37400. var lengthPlus1 = fill.length + 1;
  37401. for (var i = 1; i < lengthPlus1; ++i) {
  37402. fillGradientStops.push(i / lengthPlus1);
  37403. }
  37404. }
  37405. // stop the bleeding of the last gradient on the line above to the top gradient of the this line
  37406. // by hard defining the first gradient colour at point 0, and last gradient colour at point 1
  37407. fill.unshift(fillStyle[0]);
  37408. fillGradientStops.unshift(0);
  37409. fill.push(fillStyle[fillStyle.length - 1]);
  37410. fillGradientStops.push(1);
  37411. if (style.fillGradientType === exports.TEXT_GRADIENT.LINEAR_VERTICAL) {
  37412. // start the gradient at the top center of the canvas, and end at the bottom middle of the canvas
  37413. gradient = context.createLinearGradient(width / 2, padding, width / 2, height + padding);
  37414. // we need to repeat the gradient so that each individual line of text has the same vertical gradient effect
  37415. // ['#FF0000', '#00FF00', '#0000FF'] over 2 lines would create stops at 0.125, 0.25, 0.375, 0.625, 0.75, 0.875
  37416. // There's potential for floating point precision issues at the seams between gradient repeats.
  37417. // The loop below generates the stops in order, so track the last generated one to prevent
  37418. // floating point precision from making us go the teeniest bit backwards, resulting in
  37419. // the first and last colors getting swapped.
  37420. var lastIterationStop = 0;
  37421. // Actual height of the text itself, not counting spacing for lineHeight/leading/dropShadow etc
  37422. var textHeight = metrics.fontProperties.fontSize + style.strokeThickness;
  37423. // textHeight, but as a 0-1 size in global gradient stop space
  37424. var gradStopLineHeight = textHeight / height;
  37425. for (var i = 0; i < lines.length; i++) {
  37426. var thisLineTop = metrics.lineHeight * i;
  37427. for (var j = 0; j < fill.length; j++) {
  37428. // 0-1 stop point for the current line, multiplied to global space afterwards
  37429. var lineStop = 0;
  37430. if (typeof fillGradientStops[j] === 'number') {
  37431. lineStop = fillGradientStops[j];
  37432. }
  37433. else {
  37434. lineStop = j / fill.length;
  37435. }
  37436. var globalStop = (thisLineTop / height) + (lineStop * gradStopLineHeight);
  37437. // Prevent color stop generation going backwards from floating point imprecision
  37438. var clampedStop = Math.max(lastIterationStop, globalStop);
  37439. clampedStop = Math.min(clampedStop, 1); // Cap at 1 as well for safety's sake to avoid a possible throw.
  37440. gradient.addColorStop(clampedStop, fill[j]);
  37441. lastIterationStop = clampedStop;
  37442. }
  37443. }
  37444. }
  37445. else {
  37446. // start the gradient at the center left of the canvas, and end at the center right of the canvas
  37447. gradient = context.createLinearGradient(padding, height / 2, width + padding, height / 2);
  37448. // can just evenly space out the gradients in this case, as multiple lines makes no difference
  37449. // to an even left to right gradient
  37450. var totalIterations = fill.length + 1;
  37451. var currentIteration = 1;
  37452. for (var i = 0; i < fill.length; i++) {
  37453. var stop = void 0;
  37454. if (typeof fillGradientStops[i] === 'number') {
  37455. stop = fillGradientStops[i];
  37456. }
  37457. else {
  37458. stop = currentIteration / totalIterations;
  37459. }
  37460. gradient.addColorStop(stop, fill[i]);
  37461. currentIteration++;
  37462. }
  37463. }
  37464. return gradient;
  37465. }
  37466. // TODO: Prevent code duplication b/w drawGlyph & Text#updateText
  37467. /**
  37468. * Draws the glyph `metrics.text` on the given canvas.
  37469. *
  37470. * Ignored because not directly exposed.
  37471. *
  37472. * @ignore
  37473. * @param {HTMLCanvasElement} canvas
  37474. * @param {CanvasRenderingContext2D} context
  37475. * @param {TextMetrics} metrics
  37476. * @param {number} x
  37477. * @param {number} y
  37478. * @param {number} resolution
  37479. * @param {TextStyle} style
  37480. */
  37481. function drawGlyph(canvas, context, metrics, x, y, resolution, style) {
  37482. var char = metrics.text;
  37483. var fontProperties = metrics.fontProperties;
  37484. context.translate(x, y);
  37485. context.scale(resolution, resolution);
  37486. var tx = style.strokeThickness / 2;
  37487. var ty = -(style.strokeThickness / 2);
  37488. context.font = style.toFontString();
  37489. context.lineWidth = style.strokeThickness;
  37490. context.textBaseline = style.textBaseline;
  37491. context.lineJoin = style.lineJoin;
  37492. context.miterLimit = style.miterLimit;
  37493. // set canvas text styles
  37494. context.fillStyle = generateFillStyle(canvas, context, style, resolution, [char], metrics);
  37495. context.strokeStyle = style.stroke;
  37496. var dropShadowColor = style.dropShadowColor;
  37497. var rgb = hex2rgb(typeof dropShadowColor === 'number' ? dropShadowColor : string2hex(dropShadowColor));
  37498. if (style.dropShadow) {
  37499. context.shadowColor = "rgba(" + rgb[0] * 255 + "," + rgb[1] * 255 + "," + rgb[2] * 255 + "," + style.dropShadowAlpha + ")";
  37500. context.shadowBlur = style.dropShadowBlur;
  37501. context.shadowOffsetX = Math.cos(style.dropShadowAngle) * style.dropShadowDistance;
  37502. context.shadowOffsetY = Math.sin(style.dropShadowAngle) * style.dropShadowDistance;
  37503. }
  37504. else {
  37505. context.shadowColor = 'black';
  37506. context.shadowBlur = 0;
  37507. context.shadowOffsetX = 0;
  37508. context.shadowOffsetY = 0;
  37509. }
  37510. if (style.stroke && style.strokeThickness) {
  37511. context.strokeText(char, tx, ty + metrics.lineHeight - fontProperties.descent);
  37512. }
  37513. if (style.fill) {
  37514. context.fillText(char, tx, ty + metrics.lineHeight - fontProperties.descent);
  37515. }
  37516. context.setTransform(1, 0, 0, 1, 0, 0); // defaults needed for older browsers (e.g. Opera 29)
  37517. context.fillStyle = 'rgba(0, 0, 0, 0)';
  37518. }
  37519. /**
  37520. * Processes the passed character set data and returns a flattened array of all the characters.
  37521. *
  37522. * Ignored because not directly exposed.
  37523. *
  37524. * @ignore
  37525. * @param {string | string[] | string[][] } chars
  37526. * @returns {string[]}
  37527. */
  37528. function resolveCharacters(chars) {
  37529. // Split the chars string into individual characters
  37530. if (typeof chars === 'string') {
  37531. chars = [chars];
  37532. }
  37533. // Handle an array of characters+ranges
  37534. var result = [];
  37535. for (var i = 0, j = chars.length; i < j; i++) {
  37536. var item = chars[i];
  37537. // Handle range delimited by start/end chars
  37538. if (Array.isArray(item)) {
  37539. if (item.length !== 2) {
  37540. throw new Error("[BitmapFont]: Invalid character range length, expecting 2 got " + item.length + ".");
  37541. }
  37542. var startCode = item[0].charCodeAt(0);
  37543. var endCode = item[1].charCodeAt(0);
  37544. if (endCode < startCode) {
  37545. throw new Error('[BitmapFont]: Invalid character range.');
  37546. }
  37547. for (var i_1 = startCode, j_1 = endCode; i_1 <= j_1; i_1++) {
  37548. result.push(String.fromCharCode(i_1));
  37549. }
  37550. }
  37551. // Handle a character set string
  37552. else {
  37553. result.push.apply(result, item.split(''));
  37554. }
  37555. }
  37556. if (result.length === 0) {
  37557. throw new Error('[BitmapFont]: Empty set when resolving characters.');
  37558. }
  37559. return result;
  37560. }
  37561. /**
  37562. * BitmapFont represents a typeface available for use with the BitmapText class. Use the `install`
  37563. * method for adding a font to be used.
  37564. *
  37565. * @class
  37566. * @memberof PIXI
  37567. */
  37568. var BitmapFont = /** @class */ (function () {
  37569. /**
  37570. * @param {PIXI.BitmapFontData} data
  37571. * @param {PIXI.Texture[]|Object.<string, PIXI.Texture>} textures
  37572. * @param {boolean} ownsTextures - Setting to `true` will destroy page textures
  37573. * when the font is uninstalled.
  37574. */
  37575. function BitmapFont(data, textures, ownsTextures) {
  37576. var info = data.info[0];
  37577. var common = data.common[0];
  37578. var page = data.page[0];
  37579. var res = getResolutionOfUrl(page.file);
  37580. var pageTextures = {};
  37581. this._ownsTextures = ownsTextures;
  37582. /**
  37583. * The name of the font face.
  37584. *
  37585. * @member {string}
  37586. * @readonly
  37587. */
  37588. this.font = info.face;
  37589. /**
  37590. * The size of the font face in pixels.
  37591. *
  37592. * @member {number}
  37593. * @readonly
  37594. */
  37595. this.size = info.size;
  37596. /**
  37597. * The line-height of the font face in pixels.
  37598. *
  37599. * @member {number}
  37600. * @readonly
  37601. */
  37602. this.lineHeight = common.lineHeight / res;
  37603. /**
  37604. * The map of characters by character code.
  37605. *
  37606. * @member {object}
  37607. * @readonly
  37608. */
  37609. this.chars = {};
  37610. /**
  37611. * The map of base page textures (i.e., sheets of glyphs).
  37612. *
  37613. * @member {object}
  37614. * @readonly
  37615. * @private
  37616. */
  37617. this.pageTextures = pageTextures;
  37618. // Convert the input Texture, Textures or object
  37619. // into a page Texture lookup by "id"
  37620. for (var i = 0; i < data.page.length; i++) {
  37621. var _a = data.page[i], id = _a.id, file = _a.file;
  37622. pageTextures[id] = textures instanceof Array
  37623. ? textures[i] : textures[file];
  37624. }
  37625. // parse letters
  37626. for (var i = 0; i < data.char.length; i++) {
  37627. var _b = data.char[i], id = _b.id, page_1 = _b.page;
  37628. var _c = data.char[i], x = _c.x, y = _c.y, width = _c.width, height = _c.height, xoffset = _c.xoffset, yoffset = _c.yoffset, xadvance = _c.xadvance;
  37629. x /= res;
  37630. y /= res;
  37631. width /= res;
  37632. height /= res;
  37633. xoffset /= res;
  37634. yoffset /= res;
  37635. xadvance /= res;
  37636. var rect = new Rectangle(x + (pageTextures[page_1].frame.x / res), y + (pageTextures[page_1].frame.y / res), width, height);
  37637. this.chars[id] = {
  37638. xOffset: xoffset,
  37639. yOffset: yoffset,
  37640. xAdvance: xadvance,
  37641. kerning: {},
  37642. texture: new Texture(pageTextures[page_1].baseTexture, rect),
  37643. page: page_1,
  37644. };
  37645. }
  37646. // parse kernings
  37647. for (var i = 0; i < data.kerning.length; i++) {
  37648. var _d = data.kerning[i], first = _d.first, second = _d.second, amount = _d.amount;
  37649. first /= res;
  37650. second /= res;
  37651. amount /= res;
  37652. if (this.chars[second]) {
  37653. this.chars[second].kerning[first] = amount;
  37654. }
  37655. }
  37656. }
  37657. /**
  37658. * Remove references to created glyph textures.
  37659. */
  37660. BitmapFont.prototype.destroy = function () {
  37661. for (var id in this.chars) {
  37662. this.chars[id].texture.destroy();
  37663. this.chars[id].texture = null;
  37664. }
  37665. for (var id in this.pageTextures) {
  37666. if (this._ownsTextures) {
  37667. this.pageTextures[id].destroy(true);
  37668. }
  37669. this.pageTextures[id] = null;
  37670. }
  37671. // Set readonly null.
  37672. this.chars = null;
  37673. this.pageTextures = null;
  37674. };
  37675. /**
  37676. * Register a new bitmap font.
  37677. *
  37678. * @static
  37679. * @param {XMLDocument|string|PIXI.BitmapFontData} data - The
  37680. * characters map that could be provided as xml or raw string.
  37681. * @param {Object.<string, PIXI.Texture>|PIXI.Texture|PIXI.Texture[]}
  37682. * textures - List of textures for each page.
  37683. * @param managedTexture - Set to `true` to destroy page textures
  37684. * when the font is uninstalled. By default fonts created with
  37685. * `BitmapFont.from` or from the `BitmapFontLoader` are `true`.
  37686. * @return {PIXI.BitmapFont} Result font object with font, size, lineHeight
  37687. * and char fields.
  37688. */
  37689. BitmapFont.install = function (data, textures, ownsTextures) {
  37690. var fontData;
  37691. if (data instanceof BitmapFontData) {
  37692. fontData = data;
  37693. }
  37694. else {
  37695. var format = autoDetectFormat(data);
  37696. if (!format) {
  37697. throw new Error('Unrecognized data format for font.');
  37698. }
  37699. fontData = format.parse(data);
  37700. }
  37701. // Single texture, convert to list
  37702. if (textures instanceof Texture) {
  37703. textures = [textures];
  37704. }
  37705. var font = new BitmapFont(fontData, textures, ownsTextures);
  37706. BitmapFont.available[font.font] = font;
  37707. return font;
  37708. };
  37709. /**
  37710. * Remove bitmap font by name.
  37711. *
  37712. * @static
  37713. * @param name - Name of the font to uninstall.
  37714. */
  37715. BitmapFont.uninstall = function (name) {
  37716. var font = BitmapFont.available[name];
  37717. if (!font) {
  37718. throw new Error("No font found named '" + name + "'");
  37719. }
  37720. font.destroy();
  37721. delete BitmapFont.available[name];
  37722. };
  37723. /**
  37724. * Generates a bitmap-font for the given style and character set. This does not support
  37725. * kernings yet. With `style` properties, only the following non-layout properties are used:
  37726. *
  37727. * - {@link PIXI.TextStyle#dropShadow|dropShadow}
  37728. * - {@link PIXI.TextStyle#dropShadowDistance|dropShadowDistance}
  37729. * - {@link PIXI.TextStyle#dropShadowColor|dropShadowColor}
  37730. * - {@link PIXI.TextStyle#dropShadowBlur|dropShadowBlur}
  37731. * - {@link PIXI.TextStyle#dropShadowAngle|dropShadowAngle}
  37732. * - {@link PIXI.TextStyle#fill|fill}
  37733. * - {@link PIXI.TextStyle#fillGradientStops|fillGradientStops}
  37734. * - {@link PIXI.TextStyle#fillGradientType|fillGradientType}
  37735. * - {@link PIXI.TextStyle#fontFamily|fontFamily}
  37736. * - {@link PIXI.TextStyle#fontSize|fontSize}
  37737. * - {@link PIXI.TextStyle#fontVariant|fontVariant}
  37738. * - {@link PIXI.TextStyle#fontWeight|fontWeight}
  37739. * - {@link PIXI.TextStyle#lineJoin|lineJoin}
  37740. * - {@link PIXI.TextStyle#miterLimit|miterLimit}
  37741. * - {@link PIXI.TextStyle#stroke|stroke}
  37742. * - {@link PIXI.TextStyle#strokeThickness|strokeThickness}
  37743. * - {@link PIXI.TextStyle#textBaseline|textBaseline}
  37744. *
  37745. * @param {string} name - The name of the custom font to use with BitmapText.
  37746. * @param {object|PIXI.TextStyle} [style] - Style options to render with BitmapFont.
  37747. * @param {PIXI.IBitmapFontOptions} [options] - Setup options for font or name of the font.
  37748. * @param {string|string[]|string[][]} [options.chars=PIXI.BitmapFont.ALPHANUMERIC] - characters included
  37749. * in the font set. You can also use ranges. For example, `[['a', 'z'], ['A', 'Z'], "!@#$%^&*()~{}[] "]`.
  37750. * Don't forget to include spaces ' ' in your character set!
  37751. * @param {number} [options.resolution=1] - Render resolution for glyphs.
  37752. * @param {number} [options.textureWidth=512] - Optional width of atlas, smaller values to reduce memory.
  37753. * @param {number} [options.textureHeight=512] - Optional height of atlas, smaller values to reduce memory.
  37754. * @param {number} [options.padding=4] - Padding between glyphs on texture atlas.
  37755. * @return {PIXI.BitmapFont} Font generated by style options.
  37756. * @static
  37757. * @example
  37758. * PIXI.BitmapFont.from("TitleFont", {
  37759. * fontFamily: "Arial",
  37760. * fontSize: 12,
  37761. * strokeThickness: 2,
  37762. * fill: "purple"
  37763. * });
  37764. *
  37765. * const title = new PIXI.BitmapText("This is the title", { fontName: "TitleFont" });
  37766. */
  37767. BitmapFont.from = function (name, textStyle, options) {
  37768. if (!name) {
  37769. throw new Error('[BitmapFont] Property `name` is required.');
  37770. }
  37771. var _a = Object.assign({}, BitmapFont.defaultOptions, options), chars = _a.chars, padding = _a.padding, resolution = _a.resolution, textureWidth = _a.textureWidth, textureHeight = _a.textureHeight;
  37772. var charsList = resolveCharacters(chars);
  37773. var style = textStyle instanceof TextStyle ? textStyle : new TextStyle(textStyle);
  37774. var lineWidth = textureWidth;
  37775. var fontData = new BitmapFontData();
  37776. fontData.info[0] = {
  37777. face: style.fontFamily,
  37778. size: style.fontSize,
  37779. };
  37780. fontData.common[0] = {
  37781. lineHeight: style.fontSize,
  37782. };
  37783. var positionX = 0;
  37784. var positionY = 0;
  37785. var canvas;
  37786. var context;
  37787. var baseTexture;
  37788. var maxCharHeight = 0;
  37789. var textures = [];
  37790. for (var i = 0; i < charsList.length; i++) {
  37791. if (!canvas) {
  37792. canvas = document.createElement('canvas');
  37793. canvas.width = textureWidth;
  37794. canvas.height = textureHeight;
  37795. context = canvas.getContext('2d');
  37796. baseTexture = new BaseTexture(canvas, { resolution: resolution });
  37797. textures.push(new Texture(baseTexture));
  37798. fontData.page.push({
  37799. id: textures.length - 1,
  37800. file: '',
  37801. });
  37802. }
  37803. // Measure glyph dimensions
  37804. var metrics = TextMetrics.measureText(charsList[i], style, false, canvas);
  37805. var width = metrics.width;
  37806. var height = Math.ceil(metrics.height);
  37807. // This is ugly - but italics are given more space so they don't overlap
  37808. var textureGlyphWidth = Math.ceil((style.fontStyle === 'italic' ? 2 : 1) * width);
  37809. // Can't fit char anymore: next canvas please!
  37810. if (positionY >= textureHeight - (height * resolution)) {
  37811. if (positionY === 0) {
  37812. // We don't want user debugging an infinite loop (or do we? :)
  37813. throw new Error("[BitmapFont] textureHeight " + textureHeight + "px is "
  37814. + ("too small for " + style.fontSize + "px fonts"));
  37815. }
  37816. --i;
  37817. // Create new atlas once current has filled up
  37818. canvas = null;
  37819. context = null;
  37820. baseTexture = null;
  37821. positionY = 0;
  37822. positionX = 0;
  37823. maxCharHeight = 0;
  37824. continue;
  37825. }
  37826. maxCharHeight = Math.max(height + metrics.fontProperties.descent, maxCharHeight);
  37827. // Wrap line once full row has been rendered
  37828. if ((textureGlyphWidth * resolution) + positionX >= lineWidth) {
  37829. --i;
  37830. positionY += maxCharHeight * resolution;
  37831. positionY = Math.ceil(positionY);
  37832. positionX = 0;
  37833. maxCharHeight = 0;
  37834. continue;
  37835. }
  37836. drawGlyph(canvas, context, metrics, positionX, positionY, resolution, style);
  37837. // Unique (numeric) ID mapping to this glyph
  37838. var id = metrics.text.charCodeAt(0);
  37839. // Create a texture holding just the glyph
  37840. fontData.char.push({
  37841. id: id,
  37842. page: textures.length - 1,
  37843. x: positionX / resolution,
  37844. y: positionY / resolution,
  37845. width: textureGlyphWidth,
  37846. height: height,
  37847. xoffset: 0,
  37848. yoffset: 0,
  37849. xadvance: Math.ceil(width
  37850. - (style.dropShadow ? style.dropShadowDistance : 0)
  37851. - (style.stroke ? style.strokeThickness : 0)),
  37852. });
  37853. positionX += (textureGlyphWidth + (2 * padding)) * resolution;
  37854. positionX = Math.ceil(positionX);
  37855. }
  37856. // Brute-force kerning info, this can be expensive b/c it's an O(n²),
  37857. // but we're using measureText which is native and fast.
  37858. for (var i = 0, len = charsList.length; i < len; i++) {
  37859. var first = charsList[i];
  37860. for (var j = 0; j < len; j++) {
  37861. var second = charsList[j];
  37862. var c1 = context.measureText(first).width;
  37863. var c2 = context.measureText(second).width;
  37864. var total = context.measureText(first + second).width;
  37865. var amount = total - (c1 + c2);
  37866. if (amount) {
  37867. fontData.kerning.push({
  37868. first: first.charCodeAt(0),
  37869. second: second.charCodeAt(0),
  37870. amount: amount,
  37871. });
  37872. }
  37873. }
  37874. }
  37875. var font = new BitmapFont(fontData, textures, true);
  37876. // Make it easier to replace a font
  37877. if (BitmapFont.available[name] !== undefined) {
  37878. BitmapFont.uninstall(name);
  37879. }
  37880. BitmapFont.available[name] = font;
  37881. return font;
  37882. };
  37883. /**
  37884. * This character set includes all the letters in the alphabet (both lower- and upper- case).
  37885. * @readonly
  37886. * @static
  37887. * @member {string[][]}
  37888. * @example
  37889. * BitmapFont.from("ExampleFont", style, { chars: BitmapFont.ALPHA })
  37890. */
  37891. BitmapFont.ALPHA = [['a', 'z'], ['A', 'Z'], ' '];
  37892. /**
  37893. * This character set includes all decimal digits (from 0 to 9).
  37894. * @readonly
  37895. * @static
  37896. * @member {string[][]}
  37897. * @example
  37898. * BitmapFont.from("ExampleFont", style, { chars: BitmapFont.NUMERIC })
  37899. */
  37900. BitmapFont.NUMERIC = [['0', '9']];
  37901. /**
  37902. * This character set is the union of `BitmapFont.ALPHA` and `BitmapFont.NUMERIC`.
  37903. * @readonly
  37904. * @static
  37905. * @member {string[][]}
  37906. */
  37907. BitmapFont.ALPHANUMERIC = [['a', 'z'], ['A', 'Z'], ['0', '9'], ' '];
  37908. /**
  37909. * This character set consists of all the ASCII table.
  37910. * @readonly
  37911. * @static
  37912. * @member {string[][]}
  37913. * @see http://www.asciitable.com/
  37914. */
  37915. BitmapFont.ASCII = [[' ', '~']];
  37916. /**
  37917. * Collection of default options when using `BitmapFont.from`.
  37918. *
  37919. * @readonly
  37920. * @static
  37921. * @member {PIXI.IBitmapFontOptions}
  37922. * @property {number} resolution=1
  37923. * @property {number} textureWidth=512
  37924. * @property {number} textureHeight=512
  37925. * @property {number} padding=4
  37926. * @property {string|string[]|string[][]} chars = PIXI.BitmapFont.ALPHANUMERIC
  37927. */
  37928. BitmapFont.defaultOptions = {
  37929. resolution: 1,
  37930. textureWidth: 512,
  37931. textureHeight: 512,
  37932. padding: 4,
  37933. chars: BitmapFont.ALPHANUMERIC,
  37934. };
  37935. /**
  37936. * Collection of available/installed fonts.
  37937. *
  37938. * @readonly
  37939. * @static
  37940. * @member {Object.<string, PIXI.BitmapFont>}
  37941. */
  37942. BitmapFont.available = {};
  37943. return BitmapFont;
  37944. }());
  37945. /**
  37946. * @memberof PIXI
  37947. * @interface IBitmapFontOptions
  37948. * @property {string | string[] | string[][]} [chars=PIXI.BitmapFont.ALPHANUMERIC] - the character set to generate
  37949. * @property {number} [resolution=1] - the resolution for rendering
  37950. * @property {number} [padding=4] - the padding between glyphs in the atlas
  37951. * @property {number} [textureWidth=512] - the width of the texture atlas
  37952. * @property {number} [textureHeight=512] - the height of the texture atlas
  37953. */
  37954. var pageMeshDataPool = [];
  37955. var charRenderDataPool = [];
  37956. /**
  37957. * A BitmapText object will create a line or multiple lines of text using bitmap font.
  37958. *
  37959. * The primary advantage of this class over Text is that all of your textures are pre-generated and loading,
  37960. * meaning that rendering is fast, and changing text has no performance implications.
  37961. *
  37962. * Supporting character sets other than latin, such as CJK languages, may be impractical due to the number of characters.
  37963. *
  37964. * To split a line you can use '\n', '\r' or '\r\n' in your string.
  37965. *
  37966. * PixiJS can auto-generate fonts on-the-fly using BitmapFont or use fnt files provided by:
  37967. * http://www.angelcode.com/products/bmfont/ for Windows or
  37968. * http://www.bmglyph.com/ for Mac.
  37969. *
  37970. * A BitmapText can only be created when the font is loaded.
  37971. *
  37972. * ```js
  37973. * // in this case the font is in a file called 'desyrel.fnt'
  37974. * let bitmapText = new PIXI.BitmapText("text using a fancy font!", {
  37975. * fontName: "Desyrel",
  37976. * fontSize: 35,
  37977. * align: "right"
  37978. * });
  37979. * ```
  37980. *
  37981. * @class
  37982. * @extends PIXI.Container
  37983. * @memberof PIXI
  37984. */
  37985. var BitmapText = /** @class */ (function (_super) {
  37986. __extends$b(BitmapText, _super);
  37987. /**
  37988. * @param {string} text - A string that you would like the text to display.
  37989. * @param {object} style - The style parameters.
  37990. * @param {string} style.fontName - The installed BitmapFont name.
  37991. * @param {number} [style.fontSize] - The size of the font in pixels, e.g. 24. If undefined,
  37992. *. this will default to the BitmapFont size.
  37993. * @param {string} [style.align='left'] - Alignment for multiline text ('left', 'center', 'right' or 'justify'),
  37994. * does not affect single line text.
  37995. * @param {number} [style.tint=0xFFFFFF] - The tint color.
  37996. * @param {number} [style.letterSpacing=0] - The amount of spacing between letters.
  37997. * @param {number} [style.maxWidth=0] - The max width of the text before line wrapping.
  37998. */
  37999. function BitmapText(text, style) {
  38000. if (style === void 0) { style = {}; }
  38001. var _this = _super.call(this) || this;
  38002. _this._tint = 0xFFFFFF;
  38003. // Apply the defaults
  38004. var _a = Object.assign({}, BitmapText.styleDefaults, style), align = _a.align, tint = _a.tint, maxWidth = _a.maxWidth, letterSpacing = _a.letterSpacing, fontName = _a.fontName, fontSize = _a.fontSize;
  38005. if (!BitmapFont.available[fontName]) {
  38006. throw new Error("Missing BitmapFont \"" + fontName + "\"");
  38007. }
  38008. /**
  38009. * Collection of page mesh data.
  38010. *
  38011. * @member {object}
  38012. * @private
  38013. */
  38014. _this._activePagesMeshData = [];
  38015. /**
  38016. * Private tracker for the width of the overall text
  38017. *
  38018. * @member {number}
  38019. * @private
  38020. */
  38021. _this._textWidth = 0;
  38022. /**
  38023. * Private tracker for the height of the overall text
  38024. *
  38025. * @member {number}
  38026. * @private
  38027. */
  38028. _this._textHeight = 0;
  38029. /**
  38030. * Private tracker for the current text align.
  38031. *
  38032. * @member {string}
  38033. * @private
  38034. */
  38035. _this._align = align;
  38036. /**
  38037. * Private tracker for the current tint.
  38038. *
  38039. * @member {number}
  38040. * @private
  38041. */
  38042. _this._tint = tint;
  38043. /**
  38044. * Private tracker for the current font name.
  38045. *
  38046. * @member {string}
  38047. * @private
  38048. */
  38049. _this._fontName = fontName;
  38050. /**
  38051. * Private tracker for the current font size.
  38052. *
  38053. * @member {number}
  38054. * @private
  38055. */
  38056. _this._fontSize = fontSize || BitmapFont.available[fontName].size;
  38057. /**
  38058. * Private tracker for the current text.
  38059. *
  38060. * @member {string}
  38061. * @private
  38062. */
  38063. _this._text = text;
  38064. /**
  38065. * The max width of this bitmap text in pixels. If the text provided is longer than the
  38066. * value provided, line breaks will be automatically inserted in the last whitespace.
  38067. * Disable by setting value to 0
  38068. *
  38069. * @member {number}
  38070. * @private
  38071. */
  38072. _this._maxWidth = maxWidth;
  38073. /**
  38074. * The max line height. This is useful when trying to use the total height of the Text,
  38075. * ie: when trying to vertically align. (Internally used)
  38076. *
  38077. * @member {number}
  38078. * @private
  38079. */
  38080. _this._maxLineHeight = 0;
  38081. /**
  38082. * Letter spacing. This is useful for setting the space between characters.
  38083. * @member {number}
  38084. * @private
  38085. */
  38086. _this._letterSpacing = letterSpacing;
  38087. /**
  38088. * Text anchor. read-only
  38089. *
  38090. * @member {PIXI.ObservablePoint}
  38091. * @private
  38092. */
  38093. _this._anchor = new ObservablePoint(function () { _this.dirty = true; }, _this, 0, 0);
  38094. /**
  38095. * If true PixiJS will Math.floor() x/y values when rendering
  38096. *
  38097. * @member {boolean}
  38098. * @default PIXI.settings.ROUND_PIXELS
  38099. */
  38100. _this._roundPixels = settings.ROUND_PIXELS;
  38101. /**
  38102. * Set to `true` if the BitmapText needs to be redrawn.
  38103. *
  38104. * @member {boolean}
  38105. */
  38106. _this.dirty = true;
  38107. /**
  38108. * Cached char texture is destroyed when BitmapText is destroyed
  38109. * @member {Record<number, Texture>}
  38110. * @private
  38111. */
  38112. _this._textureCache = {};
  38113. return _this;
  38114. }
  38115. /**
  38116. * Renders text and updates it when needed. This should only be called
  38117. * if the BitmapFont is regenerated.
  38118. */
  38119. BitmapText.prototype.updateText = function () {
  38120. var _a;
  38121. var data = BitmapFont.available[this._fontName];
  38122. var scale = this._fontSize / data.size;
  38123. var pos = new Point();
  38124. var chars = [];
  38125. var lineWidths = [];
  38126. var lineSpaces = [];
  38127. var text = this._text.replace(/(?:\r\n|\r)/g, '\n') || ' ';
  38128. var textLength = text.length;
  38129. var maxWidth = this._maxWidth * data.size / this._fontSize;
  38130. var prevCharCode = null;
  38131. var lastLineWidth = 0;
  38132. var maxLineWidth = 0;
  38133. var line = 0;
  38134. var lastBreakPos = -1;
  38135. var lastBreakWidth = 0;
  38136. var spacesRemoved = 0;
  38137. var maxLineHeight = 0;
  38138. var spaceCount = 0;
  38139. for (var i = 0; i < textLength; i++) {
  38140. var charCode = text.charCodeAt(i);
  38141. var char = text.charAt(i);
  38142. if ((/(?:\s)/).test(char)) {
  38143. lastBreakPos = i;
  38144. lastBreakWidth = lastLineWidth;
  38145. spaceCount++;
  38146. }
  38147. if (char === '\r' || char === '\n') {
  38148. lineWidths.push(lastLineWidth);
  38149. lineSpaces.push(-1);
  38150. maxLineWidth = Math.max(maxLineWidth, lastLineWidth);
  38151. ++line;
  38152. ++spacesRemoved;
  38153. pos.x = 0;
  38154. pos.y += data.lineHeight;
  38155. prevCharCode = null;
  38156. spaceCount = 0;
  38157. continue;
  38158. }
  38159. var charData = data.chars[charCode];
  38160. if (!charData) {
  38161. continue;
  38162. }
  38163. if (prevCharCode && charData.kerning[prevCharCode]) {
  38164. pos.x += charData.kerning[prevCharCode];
  38165. }
  38166. var charRenderData = charRenderDataPool.pop() || {
  38167. texture: Texture.EMPTY,
  38168. line: 0,
  38169. charCode: 0,
  38170. prevSpaces: 0,
  38171. position: new Point(),
  38172. };
  38173. charRenderData.texture = charData.texture;
  38174. charRenderData.line = line;
  38175. charRenderData.charCode = charCode;
  38176. charRenderData.position.x = pos.x + charData.xOffset + (this._letterSpacing / 2);
  38177. charRenderData.position.y = pos.y + charData.yOffset;
  38178. charRenderData.prevSpaces = spaceCount;
  38179. chars.push(charRenderData);
  38180. lastLineWidth = charRenderData.position.x + charData.texture.orig.width; // Use charRenderData position!
  38181. pos.x += charData.xAdvance + this._letterSpacing;
  38182. maxLineHeight = Math.max(maxLineHeight, (charData.yOffset + charData.texture.height));
  38183. prevCharCode = charCode;
  38184. if (lastBreakPos !== -1 && maxWidth > 0 && pos.x > maxWidth) {
  38185. ++spacesRemoved;
  38186. removeItems(chars, 1 + lastBreakPos - spacesRemoved, 1 + i - lastBreakPos);
  38187. i = lastBreakPos;
  38188. lastBreakPos = -1;
  38189. lineWidths.push(lastBreakWidth);
  38190. lineSpaces.push(chars.length > 0 ? chars[chars.length - 1].prevSpaces : 0);
  38191. maxLineWidth = Math.max(maxLineWidth, lastBreakWidth);
  38192. line++;
  38193. pos.x = 0;
  38194. pos.y += data.lineHeight;
  38195. prevCharCode = null;
  38196. spaceCount = 0;
  38197. }
  38198. }
  38199. var lastChar = text.charAt(text.length - 1);
  38200. if (lastChar !== '\r' && lastChar !== '\n') {
  38201. if ((/(?:\s)/).test(lastChar)) {
  38202. lastLineWidth = lastBreakWidth;
  38203. }
  38204. lineWidths.push(lastLineWidth);
  38205. maxLineWidth = Math.max(maxLineWidth, lastLineWidth);
  38206. lineSpaces.push(-1);
  38207. }
  38208. var lineAlignOffsets = [];
  38209. for (var i = 0; i <= line; i++) {
  38210. var alignOffset = 0;
  38211. if (this._align === 'right') {
  38212. alignOffset = maxLineWidth - lineWidths[i];
  38213. }
  38214. else if (this._align === 'center') {
  38215. alignOffset = (maxLineWidth - lineWidths[i]) / 2;
  38216. }
  38217. else if (this._align === 'justify') {
  38218. alignOffset = lineSpaces[i] < 0 ? 0 : (maxLineWidth - lineWidths[i]) / lineSpaces[i];
  38219. }
  38220. lineAlignOffsets.push(alignOffset);
  38221. }
  38222. var lenChars = chars.length;
  38223. var pagesMeshData = {};
  38224. var newPagesMeshData = [];
  38225. var activePagesMeshData = this._activePagesMeshData;
  38226. for (var i = 0; i < activePagesMeshData.length; i++) {
  38227. pageMeshDataPool.push(activePagesMeshData[i]);
  38228. }
  38229. for (var i = 0; i < lenChars; i++) {
  38230. var texture = chars[i].texture;
  38231. var baseTextureUid = texture.baseTexture.uid;
  38232. if (!pagesMeshData[baseTextureUid]) {
  38233. var pageMeshData = pageMeshDataPool.pop();
  38234. if (!pageMeshData) {
  38235. var geometry = new MeshGeometry();
  38236. var material = new MeshMaterial(Texture.EMPTY);
  38237. var mesh = new Mesh(geometry, material);
  38238. pageMeshData = {
  38239. index: 0,
  38240. indexCount: 0,
  38241. vertexCount: 0,
  38242. uvsCount: 0,
  38243. total: 0,
  38244. mesh: mesh,
  38245. vertices: null,
  38246. uvs: null,
  38247. indices: null,
  38248. };
  38249. }
  38250. // reset data..
  38251. pageMeshData.index = 0;
  38252. pageMeshData.indexCount = 0;
  38253. pageMeshData.vertexCount = 0;
  38254. pageMeshData.uvsCount = 0;
  38255. pageMeshData.total = 0;
  38256. // TODO need to get page texture here somehow..
  38257. var _textureCache = this._textureCache;
  38258. _textureCache[baseTextureUid] = _textureCache[baseTextureUid] || new Texture(texture.baseTexture);
  38259. pageMeshData.mesh.texture = _textureCache[baseTextureUid];
  38260. pageMeshData.mesh.tint = this._tint;
  38261. newPagesMeshData.push(pageMeshData);
  38262. pagesMeshData[baseTextureUid] = pageMeshData;
  38263. }
  38264. pagesMeshData[baseTextureUid].total++;
  38265. }
  38266. // lets find any previously active pageMeshDatas that are no longer required for
  38267. // the updated text (if any), removed and return them to the pool.
  38268. for (var i = 0; i < activePagesMeshData.length; i++) {
  38269. if (newPagesMeshData.indexOf(activePagesMeshData[i]) === -1) {
  38270. this.removeChild(activePagesMeshData[i].mesh);
  38271. }
  38272. }
  38273. // next lets add any new meshes, that have not yet been added to this BitmapText
  38274. // we only add if its not already a child of this BitmapObject
  38275. for (var i = 0; i < newPagesMeshData.length; i++) {
  38276. if (newPagesMeshData[i].mesh.parent !== this) {
  38277. this.addChild(newPagesMeshData[i].mesh);
  38278. }
  38279. }
  38280. // active page mesh datas are set to be the new pages added.
  38281. this._activePagesMeshData = newPagesMeshData;
  38282. for (var i in pagesMeshData) {
  38283. var pageMeshData = pagesMeshData[i];
  38284. var total = pageMeshData.total;
  38285. // lets only allocate new buffers if we can fit the new text in the current ones..
  38286. // unless that is, we will be batching. Currently batching dose not respect the size property of mesh
  38287. if (!(((_a = pageMeshData.indices) === null || _a === void 0 ? void 0 : _a.length) > 6 * total) || pageMeshData.vertices.length < Mesh.BATCHABLE_SIZE * 2) {
  38288. pageMeshData.vertices = new Float32Array(4 * 2 * total);
  38289. pageMeshData.uvs = new Float32Array(4 * 2 * total);
  38290. pageMeshData.indices = new Uint16Array(6 * total);
  38291. }
  38292. else {
  38293. var total_1 = pageMeshData.total;
  38294. var vertices = pageMeshData.vertices;
  38295. // Clear the garbage at the end of the vertices buffer. This will prevent the bounds miscalculation.
  38296. for (var i_1 = total_1 * 4 * 2; i_1 < vertices.length; i_1++) {
  38297. vertices[i_1] = 0;
  38298. }
  38299. }
  38300. // as a buffer maybe bigger than the current word, we set the size of the meshMaterial
  38301. // to match the number of letters needed
  38302. pageMeshData.mesh.size = 6 * total;
  38303. }
  38304. for (var i = 0; i < lenChars; i++) {
  38305. var char = chars[i];
  38306. var offset = char.position.x + (lineAlignOffsets[char.line] * (this._align === 'justify' ? char.prevSpaces : 1));
  38307. if (this._roundPixels) {
  38308. offset = Math.round(offset);
  38309. }
  38310. var xPos = offset * scale;
  38311. var yPos = char.position.y * scale;
  38312. var texture = char.texture;
  38313. var pageMesh = pagesMeshData[texture.baseTexture.uid];
  38314. var textureFrame = texture.frame;
  38315. var textureUvs = texture._uvs;
  38316. var index = pageMesh.index++;
  38317. pageMesh.indices[(index * 6) + 0] = 0 + (index * 4);
  38318. pageMesh.indices[(index * 6) + 1] = 1 + (index * 4);
  38319. pageMesh.indices[(index * 6) + 2] = 2 + (index * 4);
  38320. pageMesh.indices[(index * 6) + 3] = 0 + (index * 4);
  38321. pageMesh.indices[(index * 6) + 4] = 2 + (index * 4);
  38322. pageMesh.indices[(index * 6) + 5] = 3 + (index * 4);
  38323. pageMesh.vertices[(index * 8) + 0] = xPos;
  38324. pageMesh.vertices[(index * 8) + 1] = yPos;
  38325. pageMesh.vertices[(index * 8) + 2] = xPos + (textureFrame.width * scale);
  38326. pageMesh.vertices[(index * 8) + 3] = yPos;
  38327. pageMesh.vertices[(index * 8) + 4] = xPos + (textureFrame.width * scale);
  38328. pageMesh.vertices[(index * 8) + 5] = yPos + (textureFrame.height * scale);
  38329. pageMesh.vertices[(index * 8) + 6] = xPos;
  38330. pageMesh.vertices[(index * 8) + 7] = yPos + (textureFrame.height * scale);
  38331. pageMesh.uvs[(index * 8) + 0] = textureUvs.x0;
  38332. pageMesh.uvs[(index * 8) + 1] = textureUvs.y0;
  38333. pageMesh.uvs[(index * 8) + 2] = textureUvs.x1;
  38334. pageMesh.uvs[(index * 8) + 3] = textureUvs.y1;
  38335. pageMesh.uvs[(index * 8) + 4] = textureUvs.x2;
  38336. pageMesh.uvs[(index * 8) + 5] = textureUvs.y2;
  38337. pageMesh.uvs[(index * 8) + 6] = textureUvs.x3;
  38338. pageMesh.uvs[(index * 8) + 7] = textureUvs.y3;
  38339. }
  38340. this._textWidth = maxLineWidth * scale;
  38341. this._textHeight = (pos.y + data.lineHeight) * scale;
  38342. for (var i in pagesMeshData) {
  38343. var pageMeshData = pagesMeshData[i];
  38344. // apply anchor
  38345. if (this.anchor.x !== 0 || this.anchor.y !== 0) {
  38346. var vertexCount = 0;
  38347. var anchorOffsetX = this._textWidth * this.anchor.x;
  38348. var anchorOffsetY = this._textHeight * this.anchor.y;
  38349. for (var i_2 = 0; i_2 < pageMeshData.total; i_2++) {
  38350. pageMeshData.vertices[vertexCount++] -= anchorOffsetX;
  38351. pageMeshData.vertices[vertexCount++] -= anchorOffsetY;
  38352. pageMeshData.vertices[vertexCount++] -= anchorOffsetX;
  38353. pageMeshData.vertices[vertexCount++] -= anchorOffsetY;
  38354. pageMeshData.vertices[vertexCount++] -= anchorOffsetX;
  38355. pageMeshData.vertices[vertexCount++] -= anchorOffsetY;
  38356. pageMeshData.vertices[vertexCount++] -= anchorOffsetX;
  38357. pageMeshData.vertices[vertexCount++] -= anchorOffsetY;
  38358. }
  38359. }
  38360. this._maxLineHeight = maxLineHeight * scale;
  38361. var vertexBuffer = pageMeshData.mesh.geometry.getBuffer('aVertexPosition');
  38362. var textureBuffer = pageMeshData.mesh.geometry.getBuffer('aTextureCoord');
  38363. var indexBuffer = pageMeshData.mesh.geometry.getIndex();
  38364. vertexBuffer.data = pageMeshData.vertices;
  38365. textureBuffer.data = pageMeshData.uvs;
  38366. indexBuffer.data = pageMeshData.indices;
  38367. vertexBuffer.update();
  38368. textureBuffer.update();
  38369. indexBuffer.update();
  38370. }
  38371. for (var i = 0; i < chars.length; i++) {
  38372. charRenderDataPool.push(chars[i]);
  38373. }
  38374. };
  38375. /**
  38376. * Updates the transform of this object
  38377. *
  38378. * @private
  38379. */
  38380. BitmapText.prototype.updateTransform = function () {
  38381. this.validate();
  38382. this.containerUpdateTransform();
  38383. };
  38384. /**
  38385. * Validates text before calling parent's getLocalBounds
  38386. *
  38387. * @return {PIXI.Rectangle} The rectangular bounding area
  38388. */
  38389. BitmapText.prototype.getLocalBounds = function () {
  38390. this.validate();
  38391. return _super.prototype.getLocalBounds.call(this);
  38392. };
  38393. /**
  38394. * Updates text when needed
  38395. *
  38396. * @private
  38397. */
  38398. BitmapText.prototype.validate = function () {
  38399. if (this.dirty) {
  38400. this.updateText();
  38401. this.dirty = false;
  38402. }
  38403. };
  38404. Object.defineProperty(BitmapText.prototype, "tint", {
  38405. /**
  38406. * The tint of the BitmapText object.
  38407. *
  38408. * @member {number}
  38409. * @default 0xffffff
  38410. */
  38411. get: function () {
  38412. return this._tint;
  38413. },
  38414. set: function (value) {
  38415. if (this._tint === value)
  38416. { return; }
  38417. this._tint = value;
  38418. for (var i = 0; i < this._activePagesMeshData.length; i++) {
  38419. this._activePagesMeshData[i].mesh.tint = value;
  38420. }
  38421. },
  38422. enumerable: false,
  38423. configurable: true
  38424. });
  38425. Object.defineProperty(BitmapText.prototype, "align", {
  38426. /**
  38427. * The alignment of the BitmapText object.
  38428. *
  38429. * @member {string}
  38430. * @default 'left'
  38431. */
  38432. get: function () {
  38433. return this._align;
  38434. },
  38435. set: function (value) {
  38436. if (this._align !== value) {
  38437. this._align = value;
  38438. this.dirty = true;
  38439. }
  38440. },
  38441. enumerable: false,
  38442. configurable: true
  38443. });
  38444. Object.defineProperty(BitmapText.prototype, "fontName", {
  38445. /**
  38446. * The name of the BitmapFont.
  38447. *
  38448. * @member {string}
  38449. */
  38450. get: function () {
  38451. return this._fontName;
  38452. },
  38453. set: function (value) {
  38454. if (!BitmapFont.available[value]) {
  38455. throw new Error("Missing BitmapFont \"" + value + "\"");
  38456. }
  38457. if (this._fontName !== value) {
  38458. this._fontName = value;
  38459. this.dirty = true;
  38460. }
  38461. },
  38462. enumerable: false,
  38463. configurable: true
  38464. });
  38465. Object.defineProperty(BitmapText.prototype, "fontSize", {
  38466. /**
  38467. * The size of the font to display.
  38468. *
  38469. * @member {number}
  38470. */
  38471. get: function () {
  38472. return this._fontSize;
  38473. },
  38474. set: function (value) {
  38475. if (this._fontSize !== value) {
  38476. this._fontSize = value;
  38477. this.dirty = true;
  38478. }
  38479. },
  38480. enumerable: false,
  38481. configurable: true
  38482. });
  38483. Object.defineProperty(BitmapText.prototype, "anchor", {
  38484. /**
  38485. * The anchor sets the origin point of the text.
  38486. *
  38487. * The default is `(0,0)`, this means the text's origin is the top left.
  38488. *
  38489. * Setting the anchor to `(0.5,0.5)` means the text's origin is centered.
  38490. *
  38491. * Setting the anchor to `(1,1)` would mean the text's origin point will be the bottom right corner.
  38492. *
  38493. * @member {PIXI.Point | number}
  38494. */
  38495. get: function () {
  38496. return this._anchor;
  38497. },
  38498. set: function (value) {
  38499. if (typeof value === 'number') {
  38500. this._anchor.set(value);
  38501. }
  38502. else {
  38503. this._anchor.copyFrom(value);
  38504. }
  38505. },
  38506. enumerable: false,
  38507. configurable: true
  38508. });
  38509. Object.defineProperty(BitmapText.prototype, "text", {
  38510. /**
  38511. * The text of the BitmapText object.
  38512. *
  38513. * @member {string}
  38514. */
  38515. get: function () {
  38516. return this._text;
  38517. },
  38518. set: function (text) {
  38519. text = String(text === null || text === undefined ? '' : text);
  38520. if (this._text === text) {
  38521. return;
  38522. }
  38523. this._text = text;
  38524. this.dirty = true;
  38525. },
  38526. enumerable: false,
  38527. configurable: true
  38528. });
  38529. Object.defineProperty(BitmapText.prototype, "maxWidth", {
  38530. /**
  38531. * The max width of this bitmap text in pixels. If the text provided is longer than the
  38532. * value provided, line breaks will be automatically inserted in the last whitespace.
  38533. * Disable by setting the value to 0.
  38534. *
  38535. * @member {number}
  38536. */
  38537. get: function () {
  38538. return this._maxWidth;
  38539. },
  38540. set: function (value) {
  38541. if (this._maxWidth === value) {
  38542. return;
  38543. }
  38544. this._maxWidth = value;
  38545. this.dirty = true;
  38546. },
  38547. enumerable: false,
  38548. configurable: true
  38549. });
  38550. Object.defineProperty(BitmapText.prototype, "maxLineHeight", {
  38551. /**
  38552. * The max line height. This is useful when trying to use the total height of the Text,
  38553. * i.e. when trying to vertically align.
  38554. *
  38555. * @member {number}
  38556. * @readonly
  38557. */
  38558. get: function () {
  38559. this.validate();
  38560. return this._maxLineHeight;
  38561. },
  38562. enumerable: false,
  38563. configurable: true
  38564. });
  38565. Object.defineProperty(BitmapText.prototype, "textWidth", {
  38566. /**
  38567. * The width of the overall text, different from fontSize,
  38568. * which is defined in the style object.
  38569. *
  38570. * @member {number}
  38571. * @readonly
  38572. */
  38573. get: function () {
  38574. this.validate();
  38575. return this._textWidth;
  38576. },
  38577. enumerable: false,
  38578. configurable: true
  38579. });
  38580. Object.defineProperty(BitmapText.prototype, "letterSpacing", {
  38581. /**
  38582. * Additional space between characters.
  38583. *
  38584. * @member {number}
  38585. */
  38586. get: function () {
  38587. return this._letterSpacing;
  38588. },
  38589. set: function (value) {
  38590. if (this._letterSpacing !== value) {
  38591. this._letterSpacing = value;
  38592. this.dirty = true;
  38593. }
  38594. },
  38595. enumerable: false,
  38596. configurable: true
  38597. });
  38598. Object.defineProperty(BitmapText.prototype, "roundPixels", {
  38599. /**
  38600. * If true PixiJS will Math.floor() x/y values when rendering, stopping pixel interpolation.
  38601. * Advantages can include sharper image quality (like text) and faster rendering on canvas.
  38602. * The main disadvantage is movement of objects may appear less smooth.
  38603. * To set the global default, change {@link PIXI.settings.ROUND_PIXELS}
  38604. *
  38605. * @member {boolean}
  38606. * @default PIXI.settings.ROUND_PIXELS
  38607. */
  38608. get: function () {
  38609. return this._roundPixels;
  38610. },
  38611. set: function (value) {
  38612. if (value !== this._roundPixels) {
  38613. this._roundPixels = value;
  38614. this.dirty = true;
  38615. }
  38616. },
  38617. enumerable: false,
  38618. configurable: true
  38619. });
  38620. Object.defineProperty(BitmapText.prototype, "textHeight", {
  38621. /**
  38622. * The height of the overall text, different from fontSize,
  38623. * which is defined in the style object.
  38624. *
  38625. * @member {number}
  38626. * @readonly
  38627. */
  38628. get: function () {
  38629. this.validate();
  38630. return this._textHeight;
  38631. },
  38632. enumerable: false,
  38633. configurable: true
  38634. });
  38635. BitmapText.prototype.destroy = function (options) {
  38636. var _textureCache = this._textureCache;
  38637. for (var id in _textureCache) {
  38638. var texture = _textureCache[id];
  38639. texture.destroy();
  38640. delete _textureCache[id];
  38641. }
  38642. this._textureCache = null;
  38643. _super.prototype.destroy.call(this, options);
  38644. };
  38645. BitmapText.styleDefaults = {
  38646. align: 'left',
  38647. tint: 0xFFFFFF,
  38648. maxWidth: 0,
  38649. letterSpacing: 0,
  38650. };
  38651. return BitmapText;
  38652. }(Container));
  38653. /**
  38654. * {@link PIXI.Loader Loader} middleware for loading
  38655. * bitmap-based fonts suitable for using with {@link PIXI.BitmapText}.
  38656. * @class
  38657. * @memberof PIXI
  38658. * @implements PIXI.ILoaderPlugin
  38659. */
  38660. var BitmapFontLoader = /** @class */ (function () {
  38661. function BitmapFontLoader() {
  38662. }
  38663. /**
  38664. * Called when the plugin is installed.
  38665. *
  38666. * @see PIXI.Loader.registerPlugin
  38667. */
  38668. BitmapFontLoader.add = function () {
  38669. exports.LoaderResource.setExtensionXhrType('fnt', exports.LoaderResource.XHR_RESPONSE_TYPE.TEXT);
  38670. };
  38671. /**
  38672. * Called after a resource is loaded.
  38673. * @see PIXI.Loader.loaderMiddleware
  38674. * @param {PIXI.LoaderResource} resource
  38675. * @param {function} next
  38676. */
  38677. BitmapFontLoader.use = function (resource, next) {
  38678. var format = autoDetectFormat(resource.data);
  38679. // Resource was not recognised as any of the expected font data format
  38680. if (!format) {
  38681. next();
  38682. return;
  38683. }
  38684. var baseUrl = BitmapFontLoader.getBaseUrl(this, resource);
  38685. var data = format.parse(resource.data);
  38686. var textures = {};
  38687. // Handle completed, when the number of textures
  38688. // load is the same number as references in the fnt file
  38689. var completed = function (page) {
  38690. textures[page.metadata.pageFile] = page.texture;
  38691. if (Object.keys(textures).length === data.page.length) {
  38692. resource.bitmapFont = BitmapFont.install(data, textures, true);
  38693. next();
  38694. }
  38695. };
  38696. for (var i = 0; i < data.page.length; ++i) {
  38697. var pageFile = data.page[i].file;
  38698. var url = baseUrl + pageFile;
  38699. var exists = false;
  38700. // incase the image is loaded outside
  38701. // using the same loader, resource will be available
  38702. for (var name in this.resources) {
  38703. var bitmapResource = this.resources[name];
  38704. if (bitmapResource.url === url) {
  38705. bitmapResource.metadata.pageFile = pageFile;
  38706. if (bitmapResource.texture) {
  38707. completed(bitmapResource);
  38708. }
  38709. else {
  38710. bitmapResource.onAfterMiddleware.add(completed);
  38711. }
  38712. exists = true;
  38713. break;
  38714. }
  38715. }
  38716. // texture is not loaded, we'll attempt to add
  38717. // it to the load and add the texture to the list
  38718. if (!exists) {
  38719. // Standard loading options for images
  38720. var options = {
  38721. crossOrigin: resource.crossOrigin,
  38722. loadType: exports.LoaderResource.LOAD_TYPE.IMAGE,
  38723. metadata: Object.assign({ pageFile: pageFile }, resource.metadata.imageMetadata),
  38724. parentResource: resource,
  38725. };
  38726. this.add(url, options, completed);
  38727. }
  38728. }
  38729. };
  38730. /**
  38731. * Get folder path from a resource
  38732. * @private
  38733. * @param {PIXI.Loader} loader
  38734. * @param {PIXI.LoaderResource} resource
  38735. * @return {string}
  38736. */
  38737. BitmapFontLoader.getBaseUrl = function (loader, resource) {
  38738. var resUrl = !resource.isDataUrl ? BitmapFontLoader.dirname(resource.url) : '';
  38739. if (resource.isDataUrl) {
  38740. if (resUrl === '.') {
  38741. resUrl = '';
  38742. }
  38743. if (loader.baseUrl && resUrl) {
  38744. // if baseurl has a trailing slash then add one to resUrl so the replace works below
  38745. if (loader.baseUrl.charAt(loader.baseUrl.length - 1) === '/') {
  38746. resUrl += '/';
  38747. }
  38748. }
  38749. }
  38750. // remove baseUrl from resUrl
  38751. resUrl = resUrl.replace(loader.baseUrl, '');
  38752. // if there is an resUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty.
  38753. if (resUrl && resUrl.charAt(resUrl.length - 1) !== '/') {
  38754. resUrl += '/';
  38755. }
  38756. return resUrl;
  38757. };
  38758. /**
  38759. * Replacement for NodeJS's path.dirname
  38760. * @private
  38761. * @param {string} url - Path to get directory for
  38762. */
  38763. BitmapFontLoader.dirname = function (url) {
  38764. var dir = url
  38765. .replace(/\\/g, '/') // convert windows notation to UNIX notation, URL-safe because it's a forbidden character
  38766. .replace(/\/$/, '') // replace trailing slash
  38767. .replace(/\/[^\/]*$/, ''); // remove everything after the last
  38768. // File request is relative, use current directory
  38769. if (dir === url) {
  38770. return '.';
  38771. }
  38772. // Started with a slash
  38773. else if (dir === '') {
  38774. return '/';
  38775. }
  38776. return dir;
  38777. };
  38778. return BitmapFontLoader;
  38779. }());
  38780. /*!
  38781. * @pixi/filter-alpha - v6.1.2
  38782. * Compiled Thu, 12 Aug 2021 17:11:19 UTC
  38783. *
  38784. * @pixi/filter-alpha is licensed under the MIT License.
  38785. * http://www.opensource.org/licenses/mit-license
  38786. */
  38787. /*! *****************************************************************************
  38788. Copyright (c) Microsoft Corporation. All rights reserved.
  38789. Licensed under the Apache License, Version 2.0 (the "License"); you may not use
  38790. this file except in compliance with the License. You may obtain a copy of the
  38791. License at http://www.apache.org/licenses/LICENSE-2.0
  38792. THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  38793. KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
  38794. WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
  38795. MERCHANTABLITY OR NON-INFRINGEMENT.
  38796. See the Apache Version 2.0 License for specific language governing permissions
  38797. and limitations under the License.
  38798. ***************************************************************************** */
  38799. /* global Reflect, Promise */
  38800. var extendStatics$c = function(d, b) {
  38801. extendStatics$c = Object.setPrototypeOf ||
  38802. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  38803. function (d, b) { for (var p in b) { if (b.hasOwnProperty(p)) { d[p] = b[p]; } } };
  38804. return extendStatics$c(d, b);
  38805. };
  38806. function __extends$c(d, b) {
  38807. extendStatics$c(d, b);
  38808. function __() { this.constructor = d; }
  38809. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  38810. }
  38811. var fragment$4 = "varying vec2 vTextureCoord;\n\nuniform sampler2D uSampler;\nuniform float uAlpha;\n\nvoid main(void)\n{\n gl_FragColor = texture2D(uSampler, vTextureCoord) * uAlpha;\n}\n";
  38812. /**
  38813. * Simplest filter - applies alpha.
  38814. *
  38815. * Use this instead of Container's alpha property to avoid visual layering of individual elements.
  38816. * AlphaFilter applies alpha evenly across the entire display object and any opaque elements it contains.
  38817. * If elements are not opaque, they will blend with each other anyway.
  38818. *
  38819. * Very handy if you want to use common features of all filters:
  38820. *
  38821. * 1. Assign a blendMode to this filter, blend all elements inside display object with background.
  38822. *
  38823. * 2. To use clipping in display coordinates, assign a filterArea to the same container that has this filter.
  38824. *
  38825. * @class
  38826. * @extends PIXI.Filter
  38827. * @memberof PIXI.filters
  38828. */
  38829. var AlphaFilter = /** @class */ (function (_super) {
  38830. __extends$c(AlphaFilter, _super);
  38831. /**
  38832. * @param {number} [alpha=1] - Amount of alpha from 0 to 1, where 0 is transparent
  38833. */
  38834. function AlphaFilter(alpha) {
  38835. if (alpha === void 0) { alpha = 1.0; }
  38836. var _this = _super.call(this, defaultVertex$2, fragment$4, { uAlpha: 1 }) || this;
  38837. _this.alpha = alpha;
  38838. return _this;
  38839. }
  38840. Object.defineProperty(AlphaFilter.prototype, "alpha", {
  38841. /**
  38842. * Coefficient for alpha multiplication
  38843. *
  38844. * @member {number}
  38845. * @default 1
  38846. */
  38847. get: function () {
  38848. return this.uniforms.uAlpha;
  38849. },
  38850. set: function (value) {
  38851. this.uniforms.uAlpha = value;
  38852. },
  38853. enumerable: false,
  38854. configurable: true
  38855. });
  38856. return AlphaFilter;
  38857. }(Filter));
  38858. /*!
  38859. * @pixi/filter-blur - v6.1.2
  38860. * Compiled Thu, 12 Aug 2021 17:11:19 UTC
  38861. *
  38862. * @pixi/filter-blur is licensed under the MIT License.
  38863. * http://www.opensource.org/licenses/mit-license
  38864. */
  38865. /*! *****************************************************************************
  38866. Copyright (c) Microsoft Corporation. All rights reserved.
  38867. Licensed under the Apache License, Version 2.0 (the "License"); you may not use
  38868. this file except in compliance with the License. You may obtain a copy of the
  38869. License at http://www.apache.org/licenses/LICENSE-2.0
  38870. THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  38871. KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
  38872. WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
  38873. MERCHANTABLITY OR NON-INFRINGEMENT.
  38874. See the Apache Version 2.0 License for specific language governing permissions
  38875. and limitations under the License.
  38876. ***************************************************************************** */
  38877. /* global Reflect, Promise */
  38878. var extendStatics$d = function(d, b) {
  38879. extendStatics$d = Object.setPrototypeOf ||
  38880. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  38881. function (d, b) { for (var p in b) { if (b.hasOwnProperty(p)) { d[p] = b[p]; } } };
  38882. return extendStatics$d(d, b);
  38883. };
  38884. function __extends$d(d, b) {
  38885. extendStatics$d(d, b);
  38886. function __() { this.constructor = d; }
  38887. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  38888. }
  38889. var vertTemplate = "\n attribute vec2 aVertexPosition;\n\n uniform mat3 projectionMatrix;\n\n uniform float strength;\n\n varying vec2 vBlurTexCoords[%size%];\n\n uniform vec4 inputSize;\n uniform vec4 outputFrame;\n\n vec4 filterVertexPosition( void )\n {\n vec2 position = aVertexPosition * max(outputFrame.zw, vec2(0.)) + outputFrame.xy;\n\n return vec4((projectionMatrix * vec3(position, 1.0)).xy, 0.0, 1.0);\n }\n\n vec2 filterTextureCoord( void )\n {\n return aVertexPosition * (outputFrame.zw * inputSize.zw);\n }\n\n void main(void)\n {\n gl_Position = filterVertexPosition();\n\n vec2 textureCoord = filterTextureCoord();\n %blur%\n }";
  38890. function generateBlurVertSource(kernelSize, x) {
  38891. var halfLength = Math.ceil(kernelSize / 2);
  38892. var vertSource = vertTemplate;
  38893. var blurLoop = '';
  38894. var template;
  38895. if (x) {
  38896. template = 'vBlurTexCoords[%index%] = textureCoord + vec2(%sampleIndex% * strength, 0.0);';
  38897. }
  38898. else {
  38899. template = 'vBlurTexCoords[%index%] = textureCoord + vec2(0.0, %sampleIndex% * strength);';
  38900. }
  38901. for (var i = 0; i < kernelSize; i++) {
  38902. var blur = template.replace('%index%', i.toString());
  38903. blur = blur.replace('%sampleIndex%', i - (halfLength - 1) + ".0");
  38904. blurLoop += blur;
  38905. blurLoop += '\n';
  38906. }
  38907. vertSource = vertSource.replace('%blur%', blurLoop);
  38908. vertSource = vertSource.replace('%size%', kernelSize.toString());
  38909. return vertSource;
  38910. }
  38911. var GAUSSIAN_VALUES = {
  38912. 5: [0.153388, 0.221461, 0.250301],
  38913. 7: [0.071303, 0.131514, 0.189879, 0.214607],
  38914. 9: [0.028532, 0.067234, 0.124009, 0.179044, 0.20236],
  38915. 11: [0.0093, 0.028002, 0.065984, 0.121703, 0.175713, 0.198596],
  38916. 13: [0.002406, 0.009255, 0.027867, 0.065666, 0.121117, 0.174868, 0.197641],
  38917. 15: [0.000489, 0.002403, 0.009246, 0.02784, 0.065602, 0.120999, 0.174697, 0.197448],
  38918. };
  38919. var fragTemplate$1 = [
  38920. 'varying vec2 vBlurTexCoords[%size%];',
  38921. 'uniform sampler2D uSampler;',
  38922. 'void main(void)',
  38923. '{',
  38924. ' gl_FragColor = vec4(0.0);',
  38925. ' %blur%',
  38926. '}' ].join('\n');
  38927. function generateBlurFragSource(kernelSize) {
  38928. var kernel = GAUSSIAN_VALUES[kernelSize];
  38929. var halfLength = kernel.length;
  38930. var fragSource = fragTemplate$1;
  38931. var blurLoop = '';
  38932. var template = 'gl_FragColor += texture2D(uSampler, vBlurTexCoords[%index%]) * %value%;';
  38933. var value;
  38934. for (var i = 0; i < kernelSize; i++) {
  38935. var blur = template.replace('%index%', i.toString());
  38936. value = i;
  38937. if (i >= halfLength) {
  38938. value = kernelSize - i - 1;
  38939. }
  38940. blur = blur.replace('%value%', kernel[value].toString());
  38941. blurLoop += blur;
  38942. blurLoop += '\n';
  38943. }
  38944. fragSource = fragSource.replace('%blur%', blurLoop);
  38945. fragSource = fragSource.replace('%size%', kernelSize.toString());
  38946. return fragSource;
  38947. }
  38948. /*!
  38949. * @pixi/constants - v6.1.2
  38950. * Compiled Thu, 12 Aug 2021 17:11:19 UTC
  38951. *
  38952. * @pixi/constants is licensed under the MIT License.
  38953. * http://www.opensource.org/licenses/mit-license
  38954. */
  38955. /**
  38956. * Different types of environments for WebGL.
  38957. *
  38958. * @static
  38959. * @memberof PIXI
  38960. * @name ENV
  38961. * @enum {number}
  38962. * @property {number} WEBGL_LEGACY - Used for older v1 WebGL devices. PixiJS will aim to ensure compatibility
  38963. * with older / less advanced devices. If you experience unexplained flickering prefer this environment.
  38964. * @property {number} WEBGL - Version 1 of WebGL
  38965. * @property {number} WEBGL2 - Version 2 of WebGL
  38966. */
  38967. var ENV$1;
  38968. (function (ENV) {
  38969. ENV[ENV["WEBGL_LEGACY"] = 0] = "WEBGL_LEGACY";
  38970. ENV[ENV["WEBGL"] = 1] = "WEBGL";
  38971. ENV[ENV["WEBGL2"] = 2] = "WEBGL2";
  38972. })(ENV$1 || (ENV$1 = {}));
  38973. /**
  38974. * Constant to identify the Renderer Type.
  38975. *
  38976. * @static
  38977. * @memberof PIXI
  38978. * @name RENDERER_TYPE
  38979. * @enum {number}
  38980. * @property {number} UNKNOWN - Unknown render type.
  38981. * @property {number} WEBGL - WebGL render type.
  38982. * @property {number} CANVAS - Canvas render type.
  38983. */
  38984. var RENDERER_TYPE$1;
  38985. (function (RENDERER_TYPE) {
  38986. RENDERER_TYPE[RENDERER_TYPE["UNKNOWN"] = 0] = "UNKNOWN";
  38987. RENDERER_TYPE[RENDERER_TYPE["WEBGL"] = 1] = "WEBGL";
  38988. RENDERER_TYPE[RENDERER_TYPE["CANVAS"] = 2] = "CANVAS";
  38989. })(RENDERER_TYPE$1 || (RENDERER_TYPE$1 = {}));
  38990. /**
  38991. * Bitwise OR of masks that indicate the buffers to be cleared.
  38992. *
  38993. * @static
  38994. * @memberof PIXI
  38995. * @name BUFFER_BITS
  38996. * @enum {number}
  38997. * @property {number} COLOR - Indicates the buffers currently enabled for color writing.
  38998. * @property {number} DEPTH - Indicates the depth buffer.
  38999. * @property {number} STENCIL - Indicates the stencil buffer.
  39000. */
  39001. var BUFFER_BITS$1;
  39002. (function (BUFFER_BITS) {
  39003. BUFFER_BITS[BUFFER_BITS["COLOR"] = 16384] = "COLOR";
  39004. BUFFER_BITS[BUFFER_BITS["DEPTH"] = 256] = "DEPTH";
  39005. BUFFER_BITS[BUFFER_BITS["STENCIL"] = 1024] = "STENCIL";
  39006. })(BUFFER_BITS$1 || (BUFFER_BITS$1 = {}));
  39007. /**
  39008. * Various blend modes supported by PIXI.
  39009. *
  39010. * IMPORTANT - The WebGL renderer only supports the NORMAL, ADD, MULTIPLY and SCREEN blend modes.
  39011. * Anything else will silently act like NORMAL.
  39012. *
  39013. * @memberof PIXI
  39014. * @name BLEND_MODES
  39015. * @enum {number}
  39016. * @property {number} NORMAL
  39017. * @property {number} ADD
  39018. * @property {number} MULTIPLY
  39019. * @property {number} SCREEN
  39020. * @property {number} OVERLAY
  39021. * @property {number} DARKEN
  39022. * @property {number} LIGHTEN
  39023. * @property {number} COLOR_DODGE
  39024. * @property {number} COLOR_BURN
  39025. * @property {number} HARD_LIGHT
  39026. * @property {number} SOFT_LIGHT
  39027. * @property {number} DIFFERENCE
  39028. * @property {number} EXCLUSION
  39029. * @property {number} HUE
  39030. * @property {number} SATURATION
  39031. * @property {number} COLOR
  39032. * @property {number} LUMINOSITY
  39033. * @property {number} NORMAL_NPM
  39034. * @property {number} ADD_NPM
  39035. * @property {number} SCREEN_NPM
  39036. * @property {number} NONE
  39037. * @property {number} SRC_IN
  39038. * @property {number} SRC_OUT
  39039. * @property {number} SRC_ATOP
  39040. * @property {number} DST_OVER
  39041. * @property {number} DST_IN
  39042. * @property {number} DST_OUT
  39043. * @property {number} DST_ATOP
  39044. * @property {number} SUBTRACT
  39045. * @property {number} SRC_OVER
  39046. * @property {number} ERASE
  39047. * @property {number} XOR
  39048. */
  39049. var BLEND_MODES$1;
  39050. (function (BLEND_MODES) {
  39051. BLEND_MODES[BLEND_MODES["NORMAL"] = 0] = "NORMAL";
  39052. BLEND_MODES[BLEND_MODES["ADD"] = 1] = "ADD";
  39053. BLEND_MODES[BLEND_MODES["MULTIPLY"] = 2] = "MULTIPLY";
  39054. BLEND_MODES[BLEND_MODES["SCREEN"] = 3] = "SCREEN";
  39055. BLEND_MODES[BLEND_MODES["OVERLAY"] = 4] = "OVERLAY";
  39056. BLEND_MODES[BLEND_MODES["DARKEN"] = 5] = "DARKEN";
  39057. BLEND_MODES[BLEND_MODES["LIGHTEN"] = 6] = "LIGHTEN";
  39058. BLEND_MODES[BLEND_MODES["COLOR_DODGE"] = 7] = "COLOR_DODGE";
  39059. BLEND_MODES[BLEND_MODES["COLOR_BURN"] = 8] = "COLOR_BURN";
  39060. BLEND_MODES[BLEND_MODES["HARD_LIGHT"] = 9] = "HARD_LIGHT";
  39061. BLEND_MODES[BLEND_MODES["SOFT_LIGHT"] = 10] = "SOFT_LIGHT";
  39062. BLEND_MODES[BLEND_MODES["DIFFERENCE"] = 11] = "DIFFERENCE";
  39063. BLEND_MODES[BLEND_MODES["EXCLUSION"] = 12] = "EXCLUSION";
  39064. BLEND_MODES[BLEND_MODES["HUE"] = 13] = "HUE";
  39065. BLEND_MODES[BLEND_MODES["SATURATION"] = 14] = "SATURATION";
  39066. BLEND_MODES[BLEND_MODES["COLOR"] = 15] = "COLOR";
  39067. BLEND_MODES[BLEND_MODES["LUMINOSITY"] = 16] = "LUMINOSITY";
  39068. BLEND_MODES[BLEND_MODES["NORMAL_NPM"] = 17] = "NORMAL_NPM";
  39069. BLEND_MODES[BLEND_MODES["ADD_NPM"] = 18] = "ADD_NPM";
  39070. BLEND_MODES[BLEND_MODES["SCREEN_NPM"] = 19] = "SCREEN_NPM";
  39071. BLEND_MODES[BLEND_MODES["NONE"] = 20] = "NONE";
  39072. BLEND_MODES[BLEND_MODES["SRC_OVER"] = 0] = "SRC_OVER";
  39073. BLEND_MODES[BLEND_MODES["SRC_IN"] = 21] = "SRC_IN";
  39074. BLEND_MODES[BLEND_MODES["SRC_OUT"] = 22] = "SRC_OUT";
  39075. BLEND_MODES[BLEND_MODES["SRC_ATOP"] = 23] = "SRC_ATOP";
  39076. BLEND_MODES[BLEND_MODES["DST_OVER"] = 24] = "DST_OVER";
  39077. BLEND_MODES[BLEND_MODES["DST_IN"] = 25] = "DST_IN";
  39078. BLEND_MODES[BLEND_MODES["DST_OUT"] = 26] = "DST_OUT";
  39079. BLEND_MODES[BLEND_MODES["DST_ATOP"] = 27] = "DST_ATOP";
  39080. BLEND_MODES[BLEND_MODES["ERASE"] = 26] = "ERASE";
  39081. BLEND_MODES[BLEND_MODES["SUBTRACT"] = 28] = "SUBTRACT";
  39082. BLEND_MODES[BLEND_MODES["XOR"] = 29] = "XOR";
  39083. })(BLEND_MODES$1 || (BLEND_MODES$1 = {}));
  39084. /**
  39085. * Various webgl draw modes. These can be used to specify which GL drawMode to use
  39086. * under certain situations and renderers.
  39087. *
  39088. * @memberof PIXI
  39089. * @static
  39090. * @name DRAW_MODES
  39091. * @enum {number}
  39092. * @property {number} POINTS
  39093. * @property {number} LINES
  39094. * @property {number} LINE_LOOP
  39095. * @property {number} LINE_STRIP
  39096. * @property {number} TRIANGLES
  39097. * @property {number} TRIANGLE_STRIP
  39098. * @property {number} TRIANGLE_FAN
  39099. */
  39100. var DRAW_MODES$1;
  39101. (function (DRAW_MODES) {
  39102. DRAW_MODES[DRAW_MODES["POINTS"] = 0] = "POINTS";
  39103. DRAW_MODES[DRAW_MODES["LINES"] = 1] = "LINES";
  39104. DRAW_MODES[DRAW_MODES["LINE_LOOP"] = 2] = "LINE_LOOP";
  39105. DRAW_MODES[DRAW_MODES["LINE_STRIP"] = 3] = "LINE_STRIP";
  39106. DRAW_MODES[DRAW_MODES["TRIANGLES"] = 4] = "TRIANGLES";
  39107. DRAW_MODES[DRAW_MODES["TRIANGLE_STRIP"] = 5] = "TRIANGLE_STRIP";
  39108. DRAW_MODES[DRAW_MODES["TRIANGLE_FAN"] = 6] = "TRIANGLE_FAN";
  39109. })(DRAW_MODES$1 || (DRAW_MODES$1 = {}));
  39110. /**
  39111. * Various GL texture/resources formats.
  39112. *
  39113. * @memberof PIXI
  39114. * @static
  39115. * @name FORMATS
  39116. * @enum {number}
  39117. * @property {number} RGBA=6408
  39118. * @property {number} RGB=6407
  39119. * @property {number} RG=33319
  39120. * @property {number} RED=6403
  39121. * @property {number} RGBA_INTEGER=36249
  39122. * @property {number} RGB_INTEGER=36248
  39123. * @property {number} RG_INTEGER=33320
  39124. * @property {number} RED_INTEGER=36244
  39125. * @property {number} ALPHA=6406
  39126. * @property {number} LUMINANCE=6409
  39127. * @property {number} LUMINANCE_ALPHA=6410
  39128. * @property {number} DEPTH_COMPONENT=6402
  39129. * @property {number} DEPTH_STENCIL=34041
  39130. */
  39131. var FORMATS$1;
  39132. (function (FORMATS) {
  39133. FORMATS[FORMATS["RGBA"] = 6408] = "RGBA";
  39134. FORMATS[FORMATS["RGB"] = 6407] = "RGB";
  39135. FORMATS[FORMATS["RG"] = 33319] = "RG";
  39136. FORMATS[FORMATS["RED"] = 6403] = "RED";
  39137. FORMATS[FORMATS["RGBA_INTEGER"] = 36249] = "RGBA_INTEGER";
  39138. FORMATS[FORMATS["RGB_INTEGER"] = 36248] = "RGB_INTEGER";
  39139. FORMATS[FORMATS["RG_INTEGER"] = 33320] = "RG_INTEGER";
  39140. FORMATS[FORMATS["RED_INTEGER"] = 36244] = "RED_INTEGER";
  39141. FORMATS[FORMATS["ALPHA"] = 6406] = "ALPHA";
  39142. FORMATS[FORMATS["LUMINANCE"] = 6409] = "LUMINANCE";
  39143. FORMATS[FORMATS["LUMINANCE_ALPHA"] = 6410] = "LUMINANCE_ALPHA";
  39144. FORMATS[FORMATS["DEPTH_COMPONENT"] = 6402] = "DEPTH_COMPONENT";
  39145. FORMATS[FORMATS["DEPTH_STENCIL"] = 34041] = "DEPTH_STENCIL";
  39146. })(FORMATS$1 || (FORMATS$1 = {}));
  39147. /**
  39148. * Various GL target types.
  39149. *
  39150. * @memberof PIXI
  39151. * @static
  39152. * @name TARGETS
  39153. * @enum {number}
  39154. * @property {number} TEXTURE_2D=3553
  39155. * @property {number} TEXTURE_CUBE_MAP=34067
  39156. * @property {number} TEXTURE_2D_ARRAY=35866
  39157. * @property {number} TEXTURE_CUBE_MAP_POSITIVE_X=34069
  39158. * @property {number} TEXTURE_CUBE_MAP_NEGATIVE_X=34070
  39159. * @property {number} TEXTURE_CUBE_MAP_POSITIVE_Y=34071
  39160. * @property {number} TEXTURE_CUBE_MAP_NEGATIVE_Y=34072
  39161. * @property {number} TEXTURE_CUBE_MAP_POSITIVE_Z=34073
  39162. * @property {number} TEXTURE_CUBE_MAP_NEGATIVE_Z=34074
  39163. */
  39164. var TARGETS$1;
  39165. (function (TARGETS) {
  39166. TARGETS[TARGETS["TEXTURE_2D"] = 3553] = "TEXTURE_2D";
  39167. TARGETS[TARGETS["TEXTURE_CUBE_MAP"] = 34067] = "TEXTURE_CUBE_MAP";
  39168. TARGETS[TARGETS["TEXTURE_2D_ARRAY"] = 35866] = "TEXTURE_2D_ARRAY";
  39169. TARGETS[TARGETS["TEXTURE_CUBE_MAP_POSITIVE_X"] = 34069] = "TEXTURE_CUBE_MAP_POSITIVE_X";
  39170. TARGETS[TARGETS["TEXTURE_CUBE_MAP_NEGATIVE_X"] = 34070] = "TEXTURE_CUBE_MAP_NEGATIVE_X";
  39171. TARGETS[TARGETS["TEXTURE_CUBE_MAP_POSITIVE_Y"] = 34071] = "TEXTURE_CUBE_MAP_POSITIVE_Y";
  39172. TARGETS[TARGETS["TEXTURE_CUBE_MAP_NEGATIVE_Y"] = 34072] = "TEXTURE_CUBE_MAP_NEGATIVE_Y";
  39173. TARGETS[TARGETS["TEXTURE_CUBE_MAP_POSITIVE_Z"] = 34073] = "TEXTURE_CUBE_MAP_POSITIVE_Z";
  39174. TARGETS[TARGETS["TEXTURE_CUBE_MAP_NEGATIVE_Z"] = 34074] = "TEXTURE_CUBE_MAP_NEGATIVE_Z";
  39175. })(TARGETS$1 || (TARGETS$1 = {}));
  39176. /**
  39177. * Various GL data format types.
  39178. *
  39179. * @memberof PIXI
  39180. * @static
  39181. * @name TYPES
  39182. * @enum {number}
  39183. * @property {number} UNSIGNED_BYTE=5121
  39184. * @property {number} UNSIGNED_SHORT=5123
  39185. * @property {number} UNSIGNED_SHORT_5_6_5=33635
  39186. * @property {number} UNSIGNED_SHORT_4_4_4_4=32819
  39187. * @property {number} UNSIGNED_SHORT_5_5_5_1=32820
  39188. * @property {number} UNSIGNED_INT=5125
  39189. * @property {number} UNSIGNED_INT_10F_11F_11F_REV=35899
  39190. * @property {number} UNSIGNED_INT_2_10_10_10_REV=33640
  39191. * @property {number} UNSIGNED_INT_24_8=34042
  39192. * @property {number} UNSIGNED_INT_5_9_9_9_REV=35902
  39193. * @property {number} BYTE=5120
  39194. * @property {number} SHORT=5122
  39195. * @property {number} INT=5124
  39196. * @property {number} FLOAT=5126
  39197. * @property {number} FLOAT_32_UNSIGNED_INT_24_8_REV=36269
  39198. * @property {number} HALF_FLOAT=36193
  39199. */
  39200. var TYPES$1;
  39201. (function (TYPES) {
  39202. TYPES[TYPES["UNSIGNED_BYTE"] = 5121] = "UNSIGNED_BYTE";
  39203. TYPES[TYPES["UNSIGNED_SHORT"] = 5123] = "UNSIGNED_SHORT";
  39204. TYPES[TYPES["UNSIGNED_SHORT_5_6_5"] = 33635] = "UNSIGNED_SHORT_5_6_5";
  39205. TYPES[TYPES["UNSIGNED_SHORT_4_4_4_4"] = 32819] = "UNSIGNED_SHORT_4_4_4_4";
  39206. TYPES[TYPES["UNSIGNED_SHORT_5_5_5_1"] = 32820] = "UNSIGNED_SHORT_5_5_5_1";
  39207. TYPES[TYPES["UNSIGNED_INT"] = 5125] = "UNSIGNED_INT";
  39208. TYPES[TYPES["UNSIGNED_INT_10F_11F_11F_REV"] = 35899] = "UNSIGNED_INT_10F_11F_11F_REV";
  39209. TYPES[TYPES["UNSIGNED_INT_2_10_10_10_REV"] = 33640] = "UNSIGNED_INT_2_10_10_10_REV";
  39210. TYPES[TYPES["UNSIGNED_INT_24_8"] = 34042] = "UNSIGNED_INT_24_8";
  39211. TYPES[TYPES["UNSIGNED_INT_5_9_9_9_REV"] = 35902] = "UNSIGNED_INT_5_9_9_9_REV";
  39212. TYPES[TYPES["BYTE"] = 5120] = "BYTE";
  39213. TYPES[TYPES["SHORT"] = 5122] = "SHORT";
  39214. TYPES[TYPES["INT"] = 5124] = "INT";
  39215. TYPES[TYPES["FLOAT"] = 5126] = "FLOAT";
  39216. TYPES[TYPES["FLOAT_32_UNSIGNED_INT_24_8_REV"] = 36269] = "FLOAT_32_UNSIGNED_INT_24_8_REV";
  39217. TYPES[TYPES["HALF_FLOAT"] = 36193] = "HALF_FLOAT";
  39218. })(TYPES$1 || (TYPES$1 = {}));
  39219. /**
  39220. * Various sampler types. Correspond to `sampler`, `isampler`, `usampler` GLSL types respectively.
  39221. * WebGL1 works only with FLOAT.
  39222. *
  39223. * @memberof PIXI
  39224. * @static
  39225. * @name SAMPLER_TYPES
  39226. * @enum {number}
  39227. * @property {number} FLOAT=0
  39228. * @property {number} INT=1
  39229. * @property {number} UINT=2
  39230. */
  39231. var SAMPLER_TYPES$1;
  39232. (function (SAMPLER_TYPES) {
  39233. SAMPLER_TYPES[SAMPLER_TYPES["FLOAT"] = 0] = "FLOAT";
  39234. SAMPLER_TYPES[SAMPLER_TYPES["INT"] = 1] = "INT";
  39235. SAMPLER_TYPES[SAMPLER_TYPES["UINT"] = 2] = "UINT";
  39236. })(SAMPLER_TYPES$1 || (SAMPLER_TYPES$1 = {}));
  39237. /**
  39238. * The scale modes that are supported by pixi.
  39239. *
  39240. * The {@link PIXI.settings.SCALE_MODE} scale mode affects the default scaling mode of future operations.
  39241. * It can be re-assigned to either LINEAR or NEAREST, depending upon suitability.
  39242. *
  39243. * @memberof PIXI
  39244. * @static
  39245. * @name SCALE_MODES
  39246. * @enum {number}
  39247. * @property {number} LINEAR Smooth scaling
  39248. * @property {number} NEAREST Pixelating scaling
  39249. */
  39250. var SCALE_MODES$1;
  39251. (function (SCALE_MODES) {
  39252. SCALE_MODES[SCALE_MODES["NEAREST"] = 0] = "NEAREST";
  39253. SCALE_MODES[SCALE_MODES["LINEAR"] = 1] = "LINEAR";
  39254. })(SCALE_MODES$1 || (SCALE_MODES$1 = {}));
  39255. /**
  39256. * The wrap modes that are supported by pixi.
  39257. *
  39258. * The {@link PIXI.settings.WRAP_MODE} wrap mode affects the default wrapping mode of future operations.
  39259. * It can be re-assigned to either CLAMP or REPEAT, depending upon suitability.
  39260. * If the texture is non power of two then clamp will be used regardless as WebGL can
  39261. * only use REPEAT if the texture is po2.
  39262. *
  39263. * This property only affects WebGL.
  39264. *
  39265. * @name WRAP_MODES
  39266. * @memberof PIXI
  39267. * @static
  39268. * @enum {number}
  39269. * @property {number} CLAMP - The textures uvs are clamped
  39270. * @property {number} REPEAT - The texture uvs tile and repeat
  39271. * @property {number} MIRRORED_REPEAT - The texture uvs tile and repeat with mirroring
  39272. */
  39273. var WRAP_MODES$1;
  39274. (function (WRAP_MODES) {
  39275. WRAP_MODES[WRAP_MODES["CLAMP"] = 33071] = "CLAMP";
  39276. WRAP_MODES[WRAP_MODES["REPEAT"] = 10497] = "REPEAT";
  39277. WRAP_MODES[WRAP_MODES["MIRRORED_REPEAT"] = 33648] = "MIRRORED_REPEAT";
  39278. })(WRAP_MODES$1 || (WRAP_MODES$1 = {}));
  39279. /**
  39280. * Mipmap filtering modes that are supported by pixi.
  39281. *
  39282. * The {@link PIXI.settings.MIPMAP_TEXTURES} affects default texture filtering.
  39283. * Mipmaps are generated for a baseTexture if its `mipmap` field is `ON`,
  39284. * or its `POW2` and texture dimensions are powers of 2.
  39285. * Due to platform restriction, `ON` option will work like `POW2` for webgl-1.
  39286. *
  39287. * This property only affects WebGL.
  39288. *
  39289. * @name MIPMAP_MODES
  39290. * @memberof PIXI
  39291. * @static
  39292. * @enum {number}
  39293. * @property {number} OFF - No mipmaps
  39294. * @property {number} POW2 - Generate mipmaps if texture dimensions are pow2
  39295. * @property {number} ON - Always generate mipmaps
  39296. * @property {number} ON_MANUAL - Use mipmaps, but do not auto-generate them; this is used with a resource
  39297. * that supports buffering each level-of-detail.
  39298. */
  39299. var MIPMAP_MODES$1;
  39300. (function (MIPMAP_MODES) {
  39301. MIPMAP_MODES[MIPMAP_MODES["OFF"] = 0] = "OFF";
  39302. MIPMAP_MODES[MIPMAP_MODES["POW2"] = 1] = "POW2";
  39303. MIPMAP_MODES[MIPMAP_MODES["ON"] = 2] = "ON";
  39304. MIPMAP_MODES[MIPMAP_MODES["ON_MANUAL"] = 3] = "ON_MANUAL";
  39305. })(MIPMAP_MODES$1 || (MIPMAP_MODES$1 = {}));
  39306. /**
  39307. * How to treat textures with premultiplied alpha
  39308. *
  39309. * @name ALPHA_MODES
  39310. * @memberof PIXI
  39311. * @static
  39312. * @enum {number}
  39313. * @property {number} NO_PREMULTIPLIED_ALPHA - Source is not premultiplied, leave it like that.
  39314. * Option for compressed and data textures that are created from typed arrays.
  39315. * @property {number} PREMULTIPLY_ON_UPLOAD - Source is not premultiplied, premultiply on upload.
  39316. * Default option, used for all loaded images.
  39317. * @property {number} PREMULTIPLIED_ALPHA - Source is already premultiplied
  39318. * Example: spine atlases with `_pma` suffix.
  39319. * @property {number} NPM - Alias for NO_PREMULTIPLIED_ALPHA.
  39320. * @property {number} UNPACK - Default option, alias for PREMULTIPLY_ON_UPLOAD.
  39321. * @property {number} PMA - Alias for PREMULTIPLIED_ALPHA.
  39322. */
  39323. var ALPHA_MODES$1;
  39324. (function (ALPHA_MODES) {
  39325. ALPHA_MODES[ALPHA_MODES["NPM"] = 0] = "NPM";
  39326. ALPHA_MODES[ALPHA_MODES["UNPACK"] = 1] = "UNPACK";
  39327. ALPHA_MODES[ALPHA_MODES["PMA"] = 2] = "PMA";
  39328. ALPHA_MODES[ALPHA_MODES["NO_PREMULTIPLIED_ALPHA"] = 0] = "NO_PREMULTIPLIED_ALPHA";
  39329. ALPHA_MODES[ALPHA_MODES["PREMULTIPLY_ON_UPLOAD"] = 1] = "PREMULTIPLY_ON_UPLOAD";
  39330. ALPHA_MODES[ALPHA_MODES["PREMULTIPLY_ALPHA"] = 2] = "PREMULTIPLY_ALPHA";
  39331. })(ALPHA_MODES$1 || (ALPHA_MODES$1 = {}));
  39332. /**
  39333. * Configure whether filter textures are cleared after binding.
  39334. *
  39335. * Filter textures need not be cleared if the filter does not use pixel blending. {@link CLEAR_MODES.BLIT} will detect
  39336. * this and skip clearing as an optimization.
  39337. *
  39338. * @name CLEAR_MODES
  39339. * @memberof PIXI
  39340. * @static
  39341. * @enum {number}
  39342. * @property {number} BLEND - Do not clear the filter texture. The filter's output will blend on top of the output texture.
  39343. * @property {number} CLEAR - Always clear the filter texture.
  39344. * @property {number} BLIT - Clear only if {@link FilterSystem.forceClear} is set or if the filter uses pixel blending.
  39345. * @property {number} NO - Alias for BLEND, same as `false` in earlier versions
  39346. * @property {number} YES - Alias for CLEAR, same as `true` in earlier versions
  39347. * @property {number} AUTO - Alias for BLIT
  39348. */
  39349. var CLEAR_MODES$1;
  39350. (function (CLEAR_MODES) {
  39351. CLEAR_MODES[CLEAR_MODES["NO"] = 0] = "NO";
  39352. CLEAR_MODES[CLEAR_MODES["YES"] = 1] = "YES";
  39353. CLEAR_MODES[CLEAR_MODES["AUTO"] = 2] = "AUTO";
  39354. CLEAR_MODES[CLEAR_MODES["BLEND"] = 0] = "BLEND";
  39355. CLEAR_MODES[CLEAR_MODES["CLEAR"] = 1] = "CLEAR";
  39356. CLEAR_MODES[CLEAR_MODES["BLIT"] = 2] = "BLIT";
  39357. })(CLEAR_MODES$1 || (CLEAR_MODES$1 = {}));
  39358. /**
  39359. * The gc modes that are supported by pixi.
  39360. *
  39361. * The {@link PIXI.settings.GC_MODE} Garbage Collection mode for PixiJS textures is AUTO
  39362. * If set to GC_MODE, the renderer will occasionally check textures usage. If they are not
  39363. * used for a specified period of time they will be removed from the GPU. They will of course
  39364. * be uploaded again when they are required. This is a silent behind the scenes process that
  39365. * should ensure that the GPU does not get filled up.
  39366. *
  39367. * Handy for mobile devices!
  39368. * This property only affects WebGL.
  39369. *
  39370. * @name GC_MODES
  39371. * @enum {number}
  39372. * @static
  39373. * @memberof PIXI
  39374. * @property {number} AUTO - Garbage collection will happen periodically automatically
  39375. * @property {number} MANUAL - Garbage collection will need to be called manually
  39376. */
  39377. var GC_MODES$1;
  39378. (function (GC_MODES) {
  39379. GC_MODES[GC_MODES["AUTO"] = 0] = "AUTO";
  39380. GC_MODES[GC_MODES["MANUAL"] = 1] = "MANUAL";
  39381. })(GC_MODES$1 || (GC_MODES$1 = {}));
  39382. /**
  39383. * Constants that specify float precision in shaders.
  39384. *
  39385. * @name PRECISION
  39386. * @memberof PIXI
  39387. * @constant
  39388. * @static
  39389. * @enum {string}
  39390. * @property {string} LOW='lowp'
  39391. * @property {string} MEDIUM='mediump'
  39392. * @property {string} HIGH='highp'
  39393. */
  39394. var PRECISION$1;
  39395. (function (PRECISION) {
  39396. PRECISION["LOW"] = "lowp";
  39397. PRECISION["MEDIUM"] = "mediump";
  39398. PRECISION["HIGH"] = "highp";
  39399. })(PRECISION$1 || (PRECISION$1 = {}));
  39400. /**
  39401. * Constants for mask implementations.
  39402. * We use `type` suffix because it leads to very different behaviours
  39403. *
  39404. * @name MASK_TYPES
  39405. * @memberof PIXI
  39406. * @static
  39407. * @enum {number}
  39408. * @property {number} NONE - Mask is ignored
  39409. * @property {number} SCISSOR - Scissor mask, rectangle on screen, cheap
  39410. * @property {number} STENCIL - Stencil mask, 1-bit, medium, works only if renderer supports stencil
  39411. * @property {number} SPRITE - Mask that uses SpriteMaskFilter, uses temporary RenderTexture
  39412. */
  39413. var MASK_TYPES$1;
  39414. (function (MASK_TYPES) {
  39415. MASK_TYPES[MASK_TYPES["NONE"] = 0] = "NONE";
  39416. MASK_TYPES[MASK_TYPES["SCISSOR"] = 1] = "SCISSOR";
  39417. MASK_TYPES[MASK_TYPES["STENCIL"] = 2] = "STENCIL";
  39418. MASK_TYPES[MASK_TYPES["SPRITE"] = 3] = "SPRITE";
  39419. })(MASK_TYPES$1 || (MASK_TYPES$1 = {}));
  39420. /**
  39421. * Constants for multi-sampling antialiasing.
  39422. *
  39423. * @see PIXI.Framebuffer#multisample
  39424. *
  39425. * @name MSAA_QUALITY
  39426. * @memberof PIXI
  39427. * @static
  39428. * @enum {number}
  39429. * @property {number} NONE - No multisampling for this renderTexture
  39430. * @property {number} LOW - Try 2 samples
  39431. * @property {number} MEDIUM - Try 4 samples
  39432. * @property {number} HIGH - Try 8 samples
  39433. */
  39434. var MSAA_QUALITY$1;
  39435. (function (MSAA_QUALITY) {
  39436. MSAA_QUALITY[MSAA_QUALITY["NONE"] = 0] = "NONE";
  39437. MSAA_QUALITY[MSAA_QUALITY["LOW"] = 2] = "LOW";
  39438. MSAA_QUALITY[MSAA_QUALITY["MEDIUM"] = 4] = "MEDIUM";
  39439. MSAA_QUALITY[MSAA_QUALITY["HIGH"] = 8] = "HIGH";
  39440. })(MSAA_QUALITY$1 || (MSAA_QUALITY$1 = {}));
  39441. /**
  39442. * Constants for various buffer types in Pixi
  39443. *
  39444. * @see PIXI.BUFFER_TYPE
  39445. *
  39446. * @name BUFFER_TYPE
  39447. * @memberof PIXI
  39448. * @static
  39449. * @enum {number}
  39450. * @property {number} ELEMENT_ARRAY_BUFFER - buffer type for using as an index buffer
  39451. * @property {number} ARRAY_BUFFER - buffer type for using attribute data
  39452. * @property {number} UNIFORM_BUFFER - the buffer type is for uniform buffer objects
  39453. */
  39454. var BUFFER_TYPE$1;
  39455. (function (BUFFER_TYPE) {
  39456. BUFFER_TYPE[BUFFER_TYPE["ELEMENT_ARRAY_BUFFER"] = 34963] = "ELEMENT_ARRAY_BUFFER";
  39457. BUFFER_TYPE[BUFFER_TYPE["ARRAY_BUFFER"] = 34962] = "ARRAY_BUFFER";
  39458. // NOT YET SUPPORTED
  39459. BUFFER_TYPE[BUFFER_TYPE["UNIFORM_BUFFER"] = 35345] = "UNIFORM_BUFFER";
  39460. })(BUFFER_TYPE$1 || (BUFFER_TYPE$1 = {}));
  39461. /**
  39462. * The BlurFilterPass applies a horizontal or vertical Gaussian blur to an object.
  39463. *
  39464. * @class
  39465. * @extends PIXI.Filter
  39466. * @memberof PIXI.filters
  39467. */
  39468. var BlurFilterPass = /** @class */ (function (_super) {
  39469. __extends$d(BlurFilterPass, _super);
  39470. /**
  39471. * @param {boolean} horizontal - Do pass along the x-axis (`true`) or y-axis (`false`).
  39472. * @param {number} [strength=8] - The strength of the blur filter.
  39473. * @param {number} [quality=4] - The quality of the blur filter.
  39474. * @param {number} [resolution=PIXI.settings.FILTER_RESOLUTION] - The resolution of the blur filter.
  39475. * @param {number} [kernelSize=5] - The kernelSize of the blur filter.Options: 5, 7, 9, 11, 13, 15.
  39476. */
  39477. function BlurFilterPass(horizontal, strength, quality, resolution, kernelSize) {
  39478. if (strength === void 0) { strength = 8; }
  39479. if (quality === void 0) { quality = 4; }
  39480. if (resolution === void 0) { resolution = settings.FILTER_RESOLUTION; }
  39481. if (kernelSize === void 0) { kernelSize = 5; }
  39482. var _this = this;
  39483. var vertSrc = generateBlurVertSource(kernelSize, horizontal);
  39484. var fragSrc = generateBlurFragSource(kernelSize);
  39485. _this = _super.call(this,
  39486. // vertex shader
  39487. vertSrc,
  39488. // fragment shader
  39489. fragSrc) || this;
  39490. _this.horizontal = horizontal;
  39491. _this.resolution = resolution;
  39492. _this._quality = 0;
  39493. _this.quality = quality;
  39494. _this.blur = strength;
  39495. return _this;
  39496. }
  39497. /**
  39498. * Applies the filter.
  39499. *
  39500. * @param {PIXI.FilterSystem} filterManager - The manager.
  39501. * @param {PIXI.RenderTexture} input - The input target.
  39502. * @param {PIXI.RenderTexture} output - The output target.
  39503. * @param {PIXI.CLEAR_MODES} clearMode - How to clear
  39504. */
  39505. BlurFilterPass.prototype.apply = function (filterManager, input, output, clearMode) {
  39506. if (output) {
  39507. if (this.horizontal) {
  39508. this.uniforms.strength = (1 / output.width) * (output.width / input.width);
  39509. }
  39510. else {
  39511. this.uniforms.strength = (1 / output.height) * (output.height / input.height);
  39512. }
  39513. }
  39514. else {
  39515. if (this.horizontal) // eslint-disable-line
  39516. {
  39517. this.uniforms.strength = (1 / filterManager.renderer.width) * (filterManager.renderer.width / input.width);
  39518. }
  39519. else {
  39520. this.uniforms.strength = (1 / filterManager.renderer.height) * (filterManager.renderer.height / input.height); // eslint-disable-line
  39521. }
  39522. }
  39523. // screen space!
  39524. this.uniforms.strength *= this.strength;
  39525. this.uniforms.strength /= this.passes;
  39526. if (this.passes === 1) {
  39527. filterManager.applyFilter(this, input, output, clearMode);
  39528. }
  39529. else {
  39530. var renderTarget = filterManager.getFilterTexture();
  39531. var renderer = filterManager.renderer;
  39532. var flip = input;
  39533. var flop = renderTarget;
  39534. this.state.blend = false;
  39535. filterManager.applyFilter(this, flip, flop, CLEAR_MODES$1.CLEAR);
  39536. for (var i = 1; i < this.passes - 1; i++) {
  39537. filterManager.bindAndClear(flip, CLEAR_MODES$1.BLIT);
  39538. this.uniforms.uSampler = flop;
  39539. var temp = flop;
  39540. flop = flip;
  39541. flip = temp;
  39542. renderer.shader.bind(this);
  39543. renderer.geometry.draw(5);
  39544. }
  39545. this.state.blend = true;
  39546. filterManager.applyFilter(this, flop, output, clearMode);
  39547. filterManager.returnFilterTexture(renderTarget);
  39548. }
  39549. };
  39550. Object.defineProperty(BlurFilterPass.prototype, "blur", {
  39551. /**
  39552. * Sets the strength of both the blur.
  39553. *
  39554. * @member {number}
  39555. * @default 16
  39556. */
  39557. get: function () {
  39558. return this.strength;
  39559. },
  39560. set: function (value) {
  39561. this.padding = 1 + (Math.abs(value) * 2);
  39562. this.strength = value;
  39563. },
  39564. enumerable: false,
  39565. configurable: true
  39566. });
  39567. Object.defineProperty(BlurFilterPass.prototype, "quality", {
  39568. /**
  39569. * Sets the quality of the blur by modifying the number of passes. More passes means higher
  39570. * quality bluring but the lower the performance.
  39571. *
  39572. * @member {number}
  39573. * @default 4
  39574. */
  39575. get: function () {
  39576. return this._quality;
  39577. },
  39578. set: function (value) {
  39579. this._quality = value;
  39580. this.passes = value;
  39581. },
  39582. enumerable: false,
  39583. configurable: true
  39584. });
  39585. return BlurFilterPass;
  39586. }(Filter));
  39587. /**
  39588. * The BlurFilter applies a Gaussian blur to an object.
  39589. *
  39590. * The strength of the blur can be set for the x-axis and y-axis separately.
  39591. *
  39592. * @class
  39593. * @extends PIXI.Filter
  39594. * @memberof PIXI.filters
  39595. */
  39596. var BlurFilter = /** @class */ (function (_super) {
  39597. __extends$d(BlurFilter, _super);
  39598. /**
  39599. * @param {number} [strength=8] - The strength of the blur filter.
  39600. * @param {number} [quality=4] - The quality of the blur filter.
  39601. * @param {number} [resolution=PIXI.settings.FILTER_RESOLUTION] - The resolution of the blur filter.
  39602. * @param {number} [kernelSize=5] - The kernelSize of the blur filter.Options: 5, 7, 9, 11, 13, 15.
  39603. */
  39604. function BlurFilter(strength, quality, resolution, kernelSize) {
  39605. if (strength === void 0) { strength = 8; }
  39606. if (quality === void 0) { quality = 4; }
  39607. if (resolution === void 0) { resolution = settings.FILTER_RESOLUTION; }
  39608. if (kernelSize === void 0) { kernelSize = 5; }
  39609. var _this = _super.call(this) || this;
  39610. _this.blurXFilter = new BlurFilterPass(true, strength, quality, resolution, kernelSize);
  39611. _this.blurYFilter = new BlurFilterPass(false, strength, quality, resolution, kernelSize);
  39612. _this.resolution = resolution;
  39613. _this.quality = quality;
  39614. _this.blur = strength;
  39615. _this.repeatEdgePixels = false;
  39616. return _this;
  39617. }
  39618. /**
  39619. * Applies the filter.
  39620. *
  39621. * @param {PIXI.FilterSystem} filterManager - The manager.
  39622. * @param {PIXI.RenderTexture} input - The input target.
  39623. * @param {PIXI.RenderTexture} output - The output target.
  39624. * @param {PIXI.CLEAR_MODES} clearMode - How to clear
  39625. */
  39626. BlurFilter.prototype.apply = function (filterManager, input, output, clearMode) {
  39627. var xStrength = Math.abs(this.blurXFilter.strength);
  39628. var yStrength = Math.abs(this.blurYFilter.strength);
  39629. if (xStrength && yStrength) {
  39630. var renderTarget = filterManager.getFilterTexture();
  39631. this.blurXFilter.apply(filterManager, input, renderTarget, CLEAR_MODES$1.CLEAR);
  39632. this.blurYFilter.apply(filterManager, renderTarget, output, clearMode);
  39633. filterManager.returnFilterTexture(renderTarget);
  39634. }
  39635. else if (yStrength) {
  39636. this.blurYFilter.apply(filterManager, input, output, clearMode);
  39637. }
  39638. else {
  39639. this.blurXFilter.apply(filterManager, input, output, clearMode);
  39640. }
  39641. };
  39642. BlurFilter.prototype.updatePadding = function () {
  39643. if (this._repeatEdgePixels) {
  39644. this.padding = 0;
  39645. }
  39646. else {
  39647. this.padding = Math.max(Math.abs(this.blurXFilter.strength), Math.abs(this.blurYFilter.strength)) * 2;
  39648. }
  39649. };
  39650. Object.defineProperty(BlurFilter.prototype, "blur", {
  39651. /**
  39652. * Sets the strength of both the blurX and blurY properties simultaneously
  39653. *
  39654. * @member {number}
  39655. * @default 2
  39656. */
  39657. get: function () {
  39658. return this.blurXFilter.blur;
  39659. },
  39660. set: function (value) {
  39661. this.blurXFilter.blur = this.blurYFilter.blur = value;
  39662. this.updatePadding();
  39663. },
  39664. enumerable: false,
  39665. configurable: true
  39666. });
  39667. Object.defineProperty(BlurFilter.prototype, "quality", {
  39668. /**
  39669. * Sets the number of passes for blur. More passes means higher quality bluring.
  39670. *
  39671. * @member {number}
  39672. * @default 1
  39673. */
  39674. get: function () {
  39675. return this.blurXFilter.quality;
  39676. },
  39677. set: function (value) {
  39678. this.blurXFilter.quality = this.blurYFilter.quality = value;
  39679. },
  39680. enumerable: false,
  39681. configurable: true
  39682. });
  39683. Object.defineProperty(BlurFilter.prototype, "blurX", {
  39684. /**
  39685. * Sets the strength of the blurX property
  39686. *
  39687. * @member {number}
  39688. * @default 2
  39689. */
  39690. get: function () {
  39691. return this.blurXFilter.blur;
  39692. },
  39693. set: function (value) {
  39694. this.blurXFilter.blur = value;
  39695. this.updatePadding();
  39696. },
  39697. enumerable: false,
  39698. configurable: true
  39699. });
  39700. Object.defineProperty(BlurFilter.prototype, "blurY", {
  39701. /**
  39702. * Sets the strength of the blurY property
  39703. *
  39704. * @member {number}
  39705. * @default 2
  39706. */
  39707. get: function () {
  39708. return this.blurYFilter.blur;
  39709. },
  39710. set: function (value) {
  39711. this.blurYFilter.blur = value;
  39712. this.updatePadding();
  39713. },
  39714. enumerable: false,
  39715. configurable: true
  39716. });
  39717. Object.defineProperty(BlurFilter.prototype, "blendMode", {
  39718. /**
  39719. * Sets the blendmode of the filter
  39720. *
  39721. * @member {number}
  39722. * @default PIXI.BLEND_MODES.NORMAL
  39723. */
  39724. get: function () {
  39725. return this.blurYFilter.blendMode;
  39726. },
  39727. set: function (value) {
  39728. this.blurYFilter.blendMode = value;
  39729. },
  39730. enumerable: false,
  39731. configurable: true
  39732. });
  39733. Object.defineProperty(BlurFilter.prototype, "repeatEdgePixels", {
  39734. /**
  39735. * If set to true the edge of the target will be clamped
  39736. *
  39737. * @member {boolean}
  39738. * @default false
  39739. */
  39740. get: function () {
  39741. return this._repeatEdgePixels;
  39742. },
  39743. set: function (value) {
  39744. this._repeatEdgePixels = value;
  39745. this.updatePadding();
  39746. },
  39747. enumerable: false,
  39748. configurable: true
  39749. });
  39750. return BlurFilter;
  39751. }(Filter));
  39752. /*!
  39753. * @pixi/filter-color-matrix - v6.1.2
  39754. * Compiled Thu, 12 Aug 2021 17:11:19 UTC
  39755. *
  39756. * @pixi/filter-color-matrix is licensed under the MIT License.
  39757. * http://www.opensource.org/licenses/mit-license
  39758. */
  39759. /*! *****************************************************************************
  39760. Copyright (c) Microsoft Corporation. All rights reserved.
  39761. Licensed under the Apache License, Version 2.0 (the "License"); you may not use
  39762. this file except in compliance with the License. You may obtain a copy of the
  39763. License at http://www.apache.org/licenses/LICENSE-2.0
  39764. THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  39765. KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
  39766. WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
  39767. MERCHANTABLITY OR NON-INFRINGEMENT.
  39768. See the Apache Version 2.0 License for specific language governing permissions
  39769. and limitations under the License.
  39770. ***************************************************************************** */
  39771. /* global Reflect, Promise */
  39772. var extendStatics$e = function(d, b) {
  39773. extendStatics$e = Object.setPrototypeOf ||
  39774. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  39775. function (d, b) { for (var p in b) { if (b.hasOwnProperty(p)) { d[p] = b[p]; } } };
  39776. return extendStatics$e(d, b);
  39777. };
  39778. function __extends$e(d, b) {
  39779. extendStatics$e(d, b);
  39780. function __() { this.constructor = d; }
  39781. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  39782. }
  39783. var fragment$5 = "varying vec2 vTextureCoord;\nuniform sampler2D uSampler;\nuniform float m[20];\nuniform float uAlpha;\n\nvoid main(void)\n{\n vec4 c = texture2D(uSampler, vTextureCoord);\n\n if (uAlpha == 0.0) {\n gl_FragColor = c;\n return;\n }\n\n // Un-premultiply alpha before applying the color matrix. See issue #3539.\n if (c.a > 0.0) {\n c.rgb /= c.a;\n }\n\n vec4 result;\n\n result.r = (m[0] * c.r);\n result.r += (m[1] * c.g);\n result.r += (m[2] * c.b);\n result.r += (m[3] * c.a);\n result.r += m[4];\n\n result.g = (m[5] * c.r);\n result.g += (m[6] * c.g);\n result.g += (m[7] * c.b);\n result.g += (m[8] * c.a);\n result.g += m[9];\n\n result.b = (m[10] * c.r);\n result.b += (m[11] * c.g);\n result.b += (m[12] * c.b);\n result.b += (m[13] * c.a);\n result.b += m[14];\n\n result.a = (m[15] * c.r);\n result.a += (m[16] * c.g);\n result.a += (m[17] * c.b);\n result.a += (m[18] * c.a);\n result.a += m[19];\n\n vec3 rgb = mix(c.rgb, result.rgb, uAlpha);\n\n // Premultiply alpha again.\n rgb *= result.a;\n\n gl_FragColor = vec4(rgb, result.a);\n}\n";
  39784. /**
  39785. * The ColorMatrixFilter class lets you apply a 5x4 matrix transformation on the RGBA
  39786. * color and alpha values of every pixel on your displayObject to produce a result
  39787. * with a new set of RGBA color and alpha values. It's pretty powerful!
  39788. *
  39789. * ```js
  39790. * let colorMatrix = new PIXI.filters.ColorMatrixFilter();
  39791. * container.filters = [colorMatrix];
  39792. * colorMatrix.contrast(2);
  39793. * ```
  39794. * @author Clément Chenebault <clement@goodboydigital.com>
  39795. * @class
  39796. * @extends PIXI.Filter
  39797. * @memberof PIXI.filters
  39798. */
  39799. var ColorMatrixFilter = /** @class */ (function (_super) {
  39800. __extends$e(ColorMatrixFilter, _super);
  39801. function ColorMatrixFilter() {
  39802. var _this = this;
  39803. var uniforms = {
  39804. m: new Float32Array([1, 0, 0, 0, 0,
  39805. 0, 1, 0, 0, 0,
  39806. 0, 0, 1, 0, 0,
  39807. 0, 0, 0, 1, 0]),
  39808. uAlpha: 1,
  39809. };
  39810. _this = _super.call(this, defaultFilterVertex, fragment$5, uniforms) || this;
  39811. _this.alpha = 1;
  39812. return _this;
  39813. }
  39814. /**
  39815. * Transforms current matrix and set the new one
  39816. *
  39817. * @param {number[]} matrix - 5x4 matrix
  39818. * @param {boolean} multiply - if true, current matrix and matrix are multiplied. If false,
  39819. * just set the current matrix with @param matrix
  39820. */
  39821. ColorMatrixFilter.prototype._loadMatrix = function (matrix, multiply) {
  39822. if (multiply === void 0) { multiply = false; }
  39823. var newMatrix = matrix;
  39824. if (multiply) {
  39825. this._multiply(newMatrix, this.uniforms.m, matrix);
  39826. newMatrix = this._colorMatrix(newMatrix);
  39827. }
  39828. // set the new matrix
  39829. this.uniforms.m = newMatrix;
  39830. };
  39831. /**
  39832. * Multiplies two mat5's
  39833. *
  39834. * @private
  39835. * @param {number[]} out - 5x4 matrix the receiving matrix
  39836. * @param {number[]} a - 5x4 matrix the first operand
  39837. * @param {number[]} b - 5x4 matrix the second operand
  39838. * @returns {number[]} 5x4 matrix
  39839. */
  39840. ColorMatrixFilter.prototype._multiply = function (out, a, b) {
  39841. // Red Channel
  39842. out[0] = (a[0] * b[0]) + (a[1] * b[5]) + (a[2] * b[10]) + (a[3] * b[15]);
  39843. out[1] = (a[0] * b[1]) + (a[1] * b[6]) + (a[2] * b[11]) + (a[3] * b[16]);
  39844. out[2] = (a[0] * b[2]) + (a[1] * b[7]) + (a[2] * b[12]) + (a[3] * b[17]);
  39845. out[3] = (a[0] * b[3]) + (a[1] * b[8]) + (a[2] * b[13]) + (a[3] * b[18]);
  39846. out[4] = (a[0] * b[4]) + (a[1] * b[9]) + (a[2] * b[14]) + (a[3] * b[19]) + a[4];
  39847. // Green Channel
  39848. out[5] = (a[5] * b[0]) + (a[6] * b[5]) + (a[7] * b[10]) + (a[8] * b[15]);
  39849. out[6] = (a[5] * b[1]) + (a[6] * b[6]) + (a[7] * b[11]) + (a[8] * b[16]);
  39850. out[7] = (a[5] * b[2]) + (a[6] * b[7]) + (a[7] * b[12]) + (a[8] * b[17]);
  39851. out[8] = (a[5] * b[3]) + (a[6] * b[8]) + (a[7] * b[13]) + (a[8] * b[18]);
  39852. out[9] = (a[5] * b[4]) + (a[6] * b[9]) + (a[7] * b[14]) + (a[8] * b[19]) + a[9];
  39853. // Blue Channel
  39854. out[10] = (a[10] * b[0]) + (a[11] * b[5]) + (a[12] * b[10]) + (a[13] * b[15]);
  39855. out[11] = (a[10] * b[1]) + (a[11] * b[6]) + (a[12] * b[11]) + (a[13] * b[16]);
  39856. out[12] = (a[10] * b[2]) + (a[11] * b[7]) + (a[12] * b[12]) + (a[13] * b[17]);
  39857. out[13] = (a[10] * b[3]) + (a[11] * b[8]) + (a[12] * b[13]) + (a[13] * b[18]);
  39858. out[14] = (a[10] * b[4]) + (a[11] * b[9]) + (a[12] * b[14]) + (a[13] * b[19]) + a[14];
  39859. // Alpha Channel
  39860. out[15] = (a[15] * b[0]) + (a[16] * b[5]) + (a[17] * b[10]) + (a[18] * b[15]);
  39861. out[16] = (a[15] * b[1]) + (a[16] * b[6]) + (a[17] * b[11]) + (a[18] * b[16]);
  39862. out[17] = (a[15] * b[2]) + (a[16] * b[7]) + (a[17] * b[12]) + (a[18] * b[17]);
  39863. out[18] = (a[15] * b[3]) + (a[16] * b[8]) + (a[17] * b[13]) + (a[18] * b[18]);
  39864. out[19] = (a[15] * b[4]) + (a[16] * b[9]) + (a[17] * b[14]) + (a[18] * b[19]) + a[19];
  39865. return out;
  39866. };
  39867. /**
  39868. * Create a Float32 Array and normalize the offset component to 0-1
  39869. *
  39870. * @private
  39871. * @param {number[]} matrix - 5x4 matrix
  39872. * @return {number[]} 5x4 matrix with all values between 0-1
  39873. */
  39874. ColorMatrixFilter.prototype._colorMatrix = function (matrix) {
  39875. // Create a Float32 Array and normalize the offset component to 0-1
  39876. var m = new Float32Array(matrix);
  39877. m[4] /= 255;
  39878. m[9] /= 255;
  39879. m[14] /= 255;
  39880. m[19] /= 255;
  39881. return m;
  39882. };
  39883. /**
  39884. * Adjusts brightness
  39885. *
  39886. * @param {number} b - value of the brigthness (0-1, where 0 is black)
  39887. * @param {boolean} multiply - if true, current matrix and matrix are multiplied. If false,
  39888. * just set the current matrix with @param matrix
  39889. */
  39890. ColorMatrixFilter.prototype.brightness = function (b, multiply) {
  39891. var matrix = [
  39892. b, 0, 0, 0, 0,
  39893. 0, b, 0, 0, 0,
  39894. 0, 0, b, 0, 0,
  39895. 0, 0, 0, 1, 0 ];
  39896. this._loadMatrix(matrix, multiply);
  39897. };
  39898. /**
  39899. * Sets each channel on the diagonal of the color matrix.
  39900. * This can be used to achieve a tinting effect on Containers similar to the tint field of some
  39901. * display objects like Sprite, Text, Graphics, and Mesh.
  39902. *
  39903. * @param {number} color - Color of the tint. This is a hex value.
  39904. * @param {boolean} multiply - if true, current matrix and matrix are multiplied. If false,
  39905. * just set the current matrix with @param matrix
  39906. */
  39907. ColorMatrixFilter.prototype.tint = function (color, multiply) {
  39908. var r = (color >> 16) & 0xff;
  39909. var g = (color >> 8) & 0xff;
  39910. var b = color & 0xff;
  39911. var matrix = [
  39912. r / 255, 0, 0, 0, 0,
  39913. 0, g / 255, 0, 0, 0,
  39914. 0, 0, b / 255, 0, 0,
  39915. 0, 0, 0, 1, 0 ];
  39916. this._loadMatrix(matrix, multiply);
  39917. };
  39918. /**
  39919. * Set the matrices in grey scales
  39920. *
  39921. * @param {number} scale - value of the grey (0-1, where 0 is black)
  39922. * @param {boolean} multiply - if true, current matrix and matrix are multiplied. If false,
  39923. * just set the current matrix with @param matrix
  39924. */
  39925. ColorMatrixFilter.prototype.greyscale = function (scale, multiply) {
  39926. var matrix = [
  39927. scale, scale, scale, 0, 0,
  39928. scale, scale, scale, 0, 0,
  39929. scale, scale, scale, 0, 0,
  39930. 0, 0, 0, 1, 0 ];
  39931. this._loadMatrix(matrix, multiply);
  39932. };
  39933. /**
  39934. * Set the black and white matrice.
  39935. *
  39936. * @param {boolean} multiply - if true, current matrix and matrix are multiplied. If false,
  39937. * just set the current matrix with @param matrix
  39938. */
  39939. ColorMatrixFilter.prototype.blackAndWhite = function (multiply) {
  39940. var matrix = [
  39941. 0.3, 0.6, 0.1, 0, 0,
  39942. 0.3, 0.6, 0.1, 0, 0,
  39943. 0.3, 0.6, 0.1, 0, 0,
  39944. 0, 0, 0, 1, 0 ];
  39945. this._loadMatrix(matrix, multiply);
  39946. };
  39947. /**
  39948. * Set the hue property of the color
  39949. *
  39950. * @param {number} rotation - in degrees
  39951. * @param {boolean} multiply - if true, current matrix and matrix are multiplied. If false,
  39952. * just set the current matrix with @param matrix
  39953. */
  39954. ColorMatrixFilter.prototype.hue = function (rotation, multiply) {
  39955. rotation = (rotation || 0) / 180 * Math.PI;
  39956. var cosR = Math.cos(rotation);
  39957. var sinR = Math.sin(rotation);
  39958. var sqrt = Math.sqrt;
  39959. /* a good approximation for hue rotation
  39960. This matrix is far better than the versions with magic luminance constants
  39961. formerly used here, but also used in the starling framework (flash) and known from this
  39962. old part of the internet: quasimondo.com/archives/000565.php
  39963. This new matrix is based on rgb cube rotation in space. Look here for a more descriptive
  39964. implementation as a shader not a general matrix:
  39965. https://github.com/evanw/glfx.js/blob/58841c23919bd59787effc0333a4897b43835412/src/filters/adjust/huesaturation.js
  39966. This is the source for the code:
  39967. see http://stackoverflow.com/questions/8507885/shift-hue-of-an-rgb-color/8510751#8510751
  39968. */
  39969. var w = 1 / 3;
  39970. var sqrW = sqrt(w); // weight is
  39971. var a00 = cosR + ((1.0 - cosR) * w);
  39972. var a01 = (w * (1.0 - cosR)) - (sqrW * sinR);
  39973. var a02 = (w * (1.0 - cosR)) + (sqrW * sinR);
  39974. var a10 = (w * (1.0 - cosR)) + (sqrW * sinR);
  39975. var a11 = cosR + (w * (1.0 - cosR));
  39976. var a12 = (w * (1.0 - cosR)) - (sqrW * sinR);
  39977. var a20 = (w * (1.0 - cosR)) - (sqrW * sinR);
  39978. var a21 = (w * (1.0 - cosR)) + (sqrW * sinR);
  39979. var a22 = cosR + (w * (1.0 - cosR));
  39980. var matrix = [
  39981. a00, a01, a02, 0, 0,
  39982. a10, a11, a12, 0, 0,
  39983. a20, a21, a22, 0, 0,
  39984. 0, 0, 0, 1, 0 ];
  39985. this._loadMatrix(matrix, multiply);
  39986. };
  39987. /**
  39988. * Set the contrast matrix, increase the separation between dark and bright
  39989. * Increase contrast : shadows darker and highlights brighter
  39990. * Decrease contrast : bring the shadows up and the highlights down
  39991. *
  39992. * @param {number} amount - value of the contrast (0-1)
  39993. * @param {boolean} multiply - if true, current matrix and matrix are multiplied. If false,
  39994. * just set the current matrix with @param matrix
  39995. */
  39996. ColorMatrixFilter.prototype.contrast = function (amount, multiply) {
  39997. var v = (amount || 0) + 1;
  39998. var o = -0.5 * (v - 1);
  39999. var matrix = [
  40000. v, 0, 0, 0, o,
  40001. 0, v, 0, 0, o,
  40002. 0, 0, v, 0, o,
  40003. 0, 0, 0, 1, 0 ];
  40004. this._loadMatrix(matrix, multiply);
  40005. };
  40006. /**
  40007. * Set the saturation matrix, increase the separation between colors
  40008. * Increase saturation : increase contrast, brightness, and sharpness
  40009. *
  40010. * @param {number} amount - The saturation amount (0-1)
  40011. * @param {boolean} [multiply] - if true, current matrix and matrix are multiplied. If false,
  40012. * just set the current matrix with @param matrix
  40013. */
  40014. ColorMatrixFilter.prototype.saturate = function (amount, multiply) {
  40015. if (amount === void 0) { amount = 0; }
  40016. var x = (amount * 2 / 3) + 1;
  40017. var y = ((x - 1) * -0.5);
  40018. var matrix = [
  40019. x, y, y, 0, 0,
  40020. y, x, y, 0, 0,
  40021. y, y, x, 0, 0,
  40022. 0, 0, 0, 1, 0 ];
  40023. this._loadMatrix(matrix, multiply);
  40024. };
  40025. /**
  40026. * Desaturate image (remove color)
  40027. *
  40028. * Call the saturate function
  40029. *
  40030. */
  40031. ColorMatrixFilter.prototype.desaturate = function () {
  40032. this.saturate(-1);
  40033. };
  40034. /**
  40035. * Negative image (inverse of classic rgb matrix)
  40036. *
  40037. * @param {boolean} multiply - if true, current matrix and matrix are multiplied. If false,
  40038. * just set the current matrix with @param matrix
  40039. */
  40040. ColorMatrixFilter.prototype.negative = function (multiply) {
  40041. var matrix = [
  40042. -1, 0, 0, 1, 0,
  40043. 0, -1, 0, 1, 0,
  40044. 0, 0, -1, 1, 0,
  40045. 0, 0, 0, 1, 0 ];
  40046. this._loadMatrix(matrix, multiply);
  40047. };
  40048. /**
  40049. * Sepia image
  40050. *
  40051. * @param {boolean} multiply - if true, current matrix and matrix are multiplied. If false,
  40052. * just set the current matrix with @param matrix
  40053. */
  40054. ColorMatrixFilter.prototype.sepia = function (multiply) {
  40055. var matrix = [
  40056. 0.393, 0.7689999, 0.18899999, 0, 0,
  40057. 0.349, 0.6859999, 0.16799999, 0, 0,
  40058. 0.272, 0.5339999, 0.13099999, 0, 0,
  40059. 0, 0, 0, 1, 0 ];
  40060. this._loadMatrix(matrix, multiply);
  40061. };
  40062. /**
  40063. * Color motion picture process invented in 1916 (thanks Dominic Szablewski)
  40064. *
  40065. * @param {boolean} multiply - if true, current matrix and matrix are multiplied. If false,
  40066. * just set the current matrix with @param matrix
  40067. */
  40068. ColorMatrixFilter.prototype.technicolor = function (multiply) {
  40069. var matrix = [
  40070. 1.9125277891456083, -0.8545344976951645, -0.09155508482755585, 0, 11.793603434377337,
  40071. -0.3087833385928097, 1.7658908555458428, -0.10601743074722245, 0, -70.35205161461398,
  40072. -0.231103377548616, -0.7501899197440212, 1.847597816108189, 0, 30.950940869491138,
  40073. 0, 0, 0, 1, 0 ];
  40074. this._loadMatrix(matrix, multiply);
  40075. };
  40076. /**
  40077. * Polaroid filter
  40078. *
  40079. * @param {boolean} multiply - if true, current matrix and matrix are multiplied. If false,
  40080. * just set the current matrix with @param matrix
  40081. */
  40082. ColorMatrixFilter.prototype.polaroid = function (multiply) {
  40083. var matrix = [
  40084. 1.438, -0.062, -0.062, 0, 0,
  40085. -0.122, 1.378, -0.122, 0, 0,
  40086. -0.016, -0.016, 1.483, 0, 0,
  40087. 0, 0, 0, 1, 0 ];
  40088. this._loadMatrix(matrix, multiply);
  40089. };
  40090. /**
  40091. * Filter who transforms : Red -> Blue and Blue -> Red
  40092. *
  40093. * @param {boolean} multiply - if true, current matrix and matrix are multiplied. If false,
  40094. * just set the current matrix with @param matrix
  40095. */
  40096. ColorMatrixFilter.prototype.toBGR = function (multiply) {
  40097. var matrix = [
  40098. 0, 0, 1, 0, 0,
  40099. 0, 1, 0, 0, 0,
  40100. 1, 0, 0, 0, 0,
  40101. 0, 0, 0, 1, 0 ];
  40102. this._loadMatrix(matrix, multiply);
  40103. };
  40104. /**
  40105. * Color reversal film introduced by Eastman Kodak in 1935. (thanks Dominic Szablewski)
  40106. *
  40107. * @param {boolean} multiply - if true, current matrix and matrix are multiplied. If false,
  40108. * just set the current matrix with @param matrix
  40109. */
  40110. ColorMatrixFilter.prototype.kodachrome = function (multiply) {
  40111. var matrix = [
  40112. 1.1285582396593525, -0.3967382283601348, -0.03992559172921793, 0, 63.72958762196502,
  40113. -0.16404339962244616, 1.0835251566291304, -0.05498805115633132, 0, 24.732407896706203,
  40114. -0.16786010706155763, -0.5603416277695248, 1.6014850761964943, 0, 35.62982807460946,
  40115. 0, 0, 0, 1, 0 ];
  40116. this._loadMatrix(matrix, multiply);
  40117. };
  40118. /**
  40119. * Brown delicious browni filter (thanks Dominic Szablewski)
  40120. *
  40121. * @param {boolean} multiply - if true, current matrix and matrix are multiplied. If false,
  40122. * just set the current matrix with @param matrix
  40123. */
  40124. ColorMatrixFilter.prototype.browni = function (multiply) {
  40125. var matrix = [
  40126. 0.5997023498159715, 0.34553243048391263, -0.2708298674538042, 0, 47.43192855600873,
  40127. -0.037703249837783157, 0.8609577587992641, 0.15059552388459913, 0, -36.96841498319127,
  40128. 0.24113635128153335, -0.07441037908422492, 0.44972182064877153, 0, -7.562075277591283,
  40129. 0, 0, 0, 1, 0 ];
  40130. this._loadMatrix(matrix, multiply);
  40131. };
  40132. /**
  40133. * Vintage filter (thanks Dominic Szablewski)
  40134. *
  40135. * @param {boolean} multiply - if true, current matrix and matrix are multiplied. If false,
  40136. * just set the current matrix with @param matrix
  40137. */
  40138. ColorMatrixFilter.prototype.vintage = function (multiply) {
  40139. var matrix = [
  40140. 0.6279345635605994, 0.3202183420819367, -0.03965408211312453, 0, 9.651285835294123,
  40141. 0.02578397704808868, 0.6441188644374771, 0.03259127616149294, 0, 7.462829176470591,
  40142. 0.0466055556782719, -0.0851232987247891, 0.5241648018700465, 0, 5.159190588235296,
  40143. 0, 0, 0, 1, 0 ];
  40144. this._loadMatrix(matrix, multiply);
  40145. };
  40146. /**
  40147. * We don't know exactly what it does, kind of gradient map, but funny to play with!
  40148. *
  40149. * @param {number} desaturation - Tone values.
  40150. * @param {number} toned - Tone values.
  40151. * @param {number} lightColor - Tone values, example: `0xFFE580`
  40152. * @param {number} darkColor - Tone values, example: `0xFFE580`
  40153. * @param {boolean} multiply - if true, current matrix and matrix are multiplied. If false,
  40154. * just set the current matrix with @param matrix
  40155. */
  40156. ColorMatrixFilter.prototype.colorTone = function (desaturation, toned, lightColor, darkColor, multiply) {
  40157. desaturation = desaturation || 0.2;
  40158. toned = toned || 0.15;
  40159. lightColor = lightColor || 0xFFE580;
  40160. darkColor = darkColor || 0x338000;
  40161. var lR = ((lightColor >> 16) & 0xFF) / 255;
  40162. var lG = ((lightColor >> 8) & 0xFF) / 255;
  40163. var lB = (lightColor & 0xFF) / 255;
  40164. var dR = ((darkColor >> 16) & 0xFF) / 255;
  40165. var dG = ((darkColor >> 8) & 0xFF) / 255;
  40166. var dB = (darkColor & 0xFF) / 255;
  40167. var matrix = [
  40168. 0.3, 0.59, 0.11, 0, 0,
  40169. lR, lG, lB, desaturation, 0,
  40170. dR, dG, dB, toned, 0,
  40171. lR - dR, lG - dG, lB - dB, 0, 0 ];
  40172. this._loadMatrix(matrix, multiply);
  40173. };
  40174. /**
  40175. * Night effect
  40176. *
  40177. * @param {number} intensity - The intensity of the night effect.
  40178. * @param {boolean} multiply - if true, current matrix and matrix are multiplied. If false,
  40179. * just set the current matrix with @param matrix
  40180. */
  40181. ColorMatrixFilter.prototype.night = function (intensity, multiply) {
  40182. intensity = intensity || 0.1;
  40183. var matrix = [
  40184. intensity * (-2.0), -intensity, 0, 0, 0,
  40185. -intensity, 0, intensity, 0, 0,
  40186. 0, intensity, intensity * 2.0, 0, 0,
  40187. 0, 0, 0, 1, 0 ];
  40188. this._loadMatrix(matrix, multiply);
  40189. };
  40190. /**
  40191. * Predator effect
  40192. *
  40193. * Erase the current matrix by setting a new indepent one
  40194. *
  40195. * @param {number} amount - how much the predator feels his future victim
  40196. * @param {boolean} multiply - if true, current matrix and matrix are multiplied. If false,
  40197. * just set the current matrix with @param matrix
  40198. */
  40199. ColorMatrixFilter.prototype.predator = function (amount, multiply) {
  40200. var matrix = [
  40201. // row 1
  40202. 11.224130630493164 * amount,
  40203. -4.794486999511719 * amount,
  40204. -2.8746118545532227 * amount,
  40205. 0 * amount,
  40206. 0.40342438220977783 * amount,
  40207. // row 2
  40208. -3.6330697536468506 * amount,
  40209. 9.193157196044922 * amount,
  40210. -2.951810836791992 * amount,
  40211. 0 * amount,
  40212. -1.316135048866272 * amount,
  40213. // row 3
  40214. -3.2184197902679443 * amount,
  40215. -4.2375030517578125 * amount,
  40216. 7.476448059082031 * amount,
  40217. 0 * amount,
  40218. 0.8044459223747253 * amount,
  40219. // row 4
  40220. 0, 0, 0, 1, 0 ];
  40221. this._loadMatrix(matrix, multiply);
  40222. };
  40223. /**
  40224. * LSD effect
  40225. *
  40226. * Multiply the current matrix
  40227. *
  40228. * @param {boolean} multiply - if true, current matrix and matrix are multiplied. If false,
  40229. * just set the current matrix with @param matrix
  40230. */
  40231. ColorMatrixFilter.prototype.lsd = function (multiply) {
  40232. var matrix = [
  40233. 2, -0.4, 0.5, 0, 0,
  40234. -0.5, 2, -0.4, 0, 0,
  40235. -0.4, -0.5, 3, 0, 0,
  40236. 0, 0, 0, 1, 0 ];
  40237. this._loadMatrix(matrix, multiply);
  40238. };
  40239. /**
  40240. * Erase the current matrix by setting the default one
  40241. *
  40242. */
  40243. ColorMatrixFilter.prototype.reset = function () {
  40244. var matrix = [
  40245. 1, 0, 0, 0, 0,
  40246. 0, 1, 0, 0, 0,
  40247. 0, 0, 1, 0, 0,
  40248. 0, 0, 0, 1, 0 ];
  40249. this._loadMatrix(matrix, false);
  40250. };
  40251. Object.defineProperty(ColorMatrixFilter.prototype, "matrix", {
  40252. /**
  40253. * The matrix of the color matrix filter
  40254. *
  40255. * @member {number[]}
  40256. * @default [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0]
  40257. */
  40258. get: function () {
  40259. return this.uniforms.m;
  40260. },
  40261. set: function (value) {
  40262. this.uniforms.m = value;
  40263. },
  40264. enumerable: false,
  40265. configurable: true
  40266. });
  40267. Object.defineProperty(ColorMatrixFilter.prototype, "alpha", {
  40268. /**
  40269. * The opacity value to use when mixing the original and resultant colors.
  40270. *
  40271. * When the value is 0, the original color is used without modification.
  40272. * When the value is 1, the result color is used.
  40273. * When in the range (0, 1) the color is interpolated between the original and result by this amount.
  40274. *
  40275. * @member {number}
  40276. * @default 1
  40277. */
  40278. get: function () {
  40279. return this.uniforms.uAlpha;
  40280. },
  40281. set: function (value) {
  40282. this.uniforms.uAlpha = value;
  40283. },
  40284. enumerable: false,
  40285. configurable: true
  40286. });
  40287. return ColorMatrixFilter;
  40288. }(Filter));
  40289. // Americanized alias
  40290. ColorMatrixFilter.prototype.grayscale = ColorMatrixFilter.prototype.greyscale;
  40291. /*!
  40292. * @pixi/filter-displacement - v6.1.2
  40293. * Compiled Thu, 12 Aug 2021 17:11:19 UTC
  40294. *
  40295. * @pixi/filter-displacement is licensed under the MIT License.
  40296. * http://www.opensource.org/licenses/mit-license
  40297. */
  40298. /*! *****************************************************************************
  40299. Copyright (c) Microsoft Corporation. All rights reserved.
  40300. Licensed under the Apache License, Version 2.0 (the "License"); you may not use
  40301. this file except in compliance with the License. You may obtain a copy of the
  40302. License at http://www.apache.org/licenses/LICENSE-2.0
  40303. THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  40304. KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
  40305. WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
  40306. MERCHANTABLITY OR NON-INFRINGEMENT.
  40307. See the Apache Version 2.0 License for specific language governing permissions
  40308. and limitations under the License.
  40309. ***************************************************************************** */
  40310. /* global Reflect, Promise */
  40311. var extendStatics$f = function(d, b) {
  40312. extendStatics$f = Object.setPrototypeOf ||
  40313. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  40314. function (d, b) { for (var p in b) { if (b.hasOwnProperty(p)) { d[p] = b[p]; } } };
  40315. return extendStatics$f(d, b);
  40316. };
  40317. function __extends$f(d, b) {
  40318. extendStatics$f(d, b);
  40319. function __() { this.constructor = d; }
  40320. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  40321. }
  40322. var fragment$6 = "varying vec2 vFilterCoord;\nvarying vec2 vTextureCoord;\n\nuniform vec2 scale;\nuniform mat2 rotation;\nuniform sampler2D uSampler;\nuniform sampler2D mapSampler;\n\nuniform highp vec4 inputSize;\nuniform vec4 inputClamp;\n\nvoid main(void)\n{\n vec4 map = texture2D(mapSampler, vFilterCoord);\n\n map -= 0.5;\n map.xy = scale * inputSize.zw * (rotation * map.xy);\n\n gl_FragColor = texture2D(uSampler, clamp(vec2(vTextureCoord.x + map.x, vTextureCoord.y + map.y), inputClamp.xy, inputClamp.zw));\n}\n";
  40323. var vertex$4 = "attribute vec2 aVertexPosition;\n\nuniform mat3 projectionMatrix;\nuniform mat3 filterMatrix;\n\nvarying vec2 vTextureCoord;\nvarying vec2 vFilterCoord;\n\nuniform vec4 inputSize;\nuniform vec4 outputFrame;\n\nvec4 filterVertexPosition( void )\n{\n vec2 position = aVertexPosition * max(outputFrame.zw, vec2(0.)) + outputFrame.xy;\n\n return vec4((projectionMatrix * vec3(position, 1.0)).xy, 0.0, 1.0);\n}\n\nvec2 filterTextureCoord( void )\n{\n return aVertexPosition * (outputFrame.zw * inputSize.zw);\n}\n\nvoid main(void)\n{\n\tgl_Position = filterVertexPosition();\n\tvTextureCoord = filterTextureCoord();\n\tvFilterCoord = ( filterMatrix * vec3( vTextureCoord, 1.0) ).xy;\n}\n";
  40324. /**
  40325. * The DisplacementFilter class uses the pixel values from the specified texture
  40326. * (called the displacement map) to perform a displacement of an object.
  40327. *
  40328. * You can use this filter to apply all manor of crazy warping effects.
  40329. * Currently the `r` property of the texture is used to offset the `x`
  40330. * and the `g` property of the texture is used to offset the `y`.
  40331. *
  40332. * The way it works is it uses the values of the displacement map to look up the
  40333. * correct pixels to output. This means it's not technically moving the original.
  40334. * Instead, it's starting at the output and asking "which pixel from the original goes here".
  40335. * For example, if a displacement map pixel has `red = 1` and the filter scale is `20`,
  40336. * this filter will output the pixel approximately 20 pixels to the right of the original.
  40337. *
  40338. * @class
  40339. * @extends PIXI.Filter
  40340. * @memberof PIXI.filters
  40341. */
  40342. var DisplacementFilter = /** @class */ (function (_super) {
  40343. __extends$f(DisplacementFilter, _super);
  40344. /**
  40345. * @param {PIXI.Sprite} sprite - The sprite used for the displacement map. (make sure its added to the scene!)
  40346. * @param {number} [scale] - The scale of the displacement
  40347. */
  40348. function DisplacementFilter(sprite, scale) {
  40349. var _this = this;
  40350. var maskMatrix = new Matrix();
  40351. sprite.renderable = false;
  40352. _this = _super.call(this, vertex$4, fragment$6, {
  40353. mapSampler: sprite._texture,
  40354. filterMatrix: maskMatrix,
  40355. scale: { x: 1, y: 1 },
  40356. rotation: new Float32Array([1, 0, 0, 1]),
  40357. }) || this;
  40358. _this.maskSprite = sprite;
  40359. _this.maskMatrix = maskMatrix;
  40360. if (scale === null || scale === undefined) {
  40361. scale = 20;
  40362. }
  40363. /**
  40364. * scaleX, scaleY for displacements
  40365. * @member {PIXI.Point}
  40366. */
  40367. _this.scale = new Point(scale, scale);
  40368. return _this;
  40369. }
  40370. /**
  40371. * Applies the filter.
  40372. *
  40373. * @param {PIXI.FilterSystem} filterManager - The manager.
  40374. * @param {PIXI.RenderTexture} input - The input target.
  40375. * @param {PIXI.RenderTexture} output - The output target.
  40376. * @param {PIXI.CLEAR_MODES} clearMode - clearMode.
  40377. */
  40378. DisplacementFilter.prototype.apply = function (filterManager, input, output, clearMode) {
  40379. // fill maskMatrix with _normalized sprite texture coords_
  40380. this.uniforms.filterMatrix = filterManager.calculateSpriteMatrix(this.maskMatrix, this.maskSprite);
  40381. this.uniforms.scale.x = this.scale.x;
  40382. this.uniforms.scale.y = this.scale.y;
  40383. // Extract rotation from world transform
  40384. var wt = this.maskSprite.worldTransform;
  40385. var lenX = Math.sqrt((wt.a * wt.a) + (wt.b * wt.b));
  40386. var lenY = Math.sqrt((wt.c * wt.c) + (wt.d * wt.d));
  40387. if (lenX !== 0 && lenY !== 0) {
  40388. this.uniforms.rotation[0] = wt.a / lenX;
  40389. this.uniforms.rotation[1] = wt.b / lenX;
  40390. this.uniforms.rotation[2] = wt.c / lenY;
  40391. this.uniforms.rotation[3] = wt.d / lenY;
  40392. }
  40393. // draw the filter...
  40394. filterManager.applyFilter(this, input, output, clearMode);
  40395. };
  40396. Object.defineProperty(DisplacementFilter.prototype, "map", {
  40397. /**
  40398. * The texture used for the displacement map. Must be power of 2 sized texture.
  40399. *
  40400. * @member {PIXI.Texture}
  40401. */
  40402. get: function () {
  40403. return this.uniforms.mapSampler;
  40404. },
  40405. set: function (value) {
  40406. this.uniforms.mapSampler = value;
  40407. },
  40408. enumerable: false,
  40409. configurable: true
  40410. });
  40411. return DisplacementFilter;
  40412. }(Filter));
  40413. /*!
  40414. * @pixi/filter-fxaa - v6.1.2
  40415. * Compiled Thu, 12 Aug 2021 17:11:19 UTC
  40416. *
  40417. * @pixi/filter-fxaa is licensed under the MIT License.
  40418. * http://www.opensource.org/licenses/mit-license
  40419. */
  40420. /*! *****************************************************************************
  40421. Copyright (c) Microsoft Corporation. All rights reserved.
  40422. Licensed under the Apache License, Version 2.0 (the "License"); you may not use
  40423. this file except in compliance with the License. You may obtain a copy of the
  40424. License at http://www.apache.org/licenses/LICENSE-2.0
  40425. THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  40426. KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
  40427. WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
  40428. MERCHANTABLITY OR NON-INFRINGEMENT.
  40429. See the Apache Version 2.0 License for specific language governing permissions
  40430. and limitations under the License.
  40431. ***************************************************************************** */
  40432. /* global Reflect, Promise */
  40433. var extendStatics$g = function(d, b) {
  40434. extendStatics$g = Object.setPrototypeOf ||
  40435. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  40436. function (d, b) { for (var p in b) { if (b.hasOwnProperty(p)) { d[p] = b[p]; } } };
  40437. return extendStatics$g(d, b);
  40438. };
  40439. function __extends$g(d, b) {
  40440. extendStatics$g(d, b);
  40441. function __() { this.constructor = d; }
  40442. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  40443. }
  40444. var vertex$5 = "\nattribute vec2 aVertexPosition;\n\nuniform mat3 projectionMatrix;\n\nvarying vec2 v_rgbNW;\nvarying vec2 v_rgbNE;\nvarying vec2 v_rgbSW;\nvarying vec2 v_rgbSE;\nvarying vec2 v_rgbM;\n\nvarying vec2 vFragCoord;\n\nuniform vec4 inputSize;\nuniform vec4 outputFrame;\n\nvec4 filterVertexPosition( void )\n{\n vec2 position = aVertexPosition * max(outputFrame.zw, vec2(0.)) + outputFrame.xy;\n\n return vec4((projectionMatrix * vec3(position, 1.0)).xy, 0.0, 1.0);\n}\n\nvoid texcoords(vec2 fragCoord, vec2 inverseVP,\n out vec2 v_rgbNW, out vec2 v_rgbNE,\n out vec2 v_rgbSW, out vec2 v_rgbSE,\n out vec2 v_rgbM) {\n v_rgbNW = (fragCoord + vec2(-1.0, -1.0)) * inverseVP;\n v_rgbNE = (fragCoord + vec2(1.0, -1.0)) * inverseVP;\n v_rgbSW = (fragCoord + vec2(-1.0, 1.0)) * inverseVP;\n v_rgbSE = (fragCoord + vec2(1.0, 1.0)) * inverseVP;\n v_rgbM = vec2(fragCoord * inverseVP);\n}\n\nvoid main(void) {\n\n gl_Position = filterVertexPosition();\n\n vFragCoord = aVertexPosition * outputFrame.zw;\n\n texcoords(vFragCoord, inputSize.zw, v_rgbNW, v_rgbNE, v_rgbSW, v_rgbSE, v_rgbM);\n}\n";
  40445. var fragment$7 = "varying vec2 v_rgbNW;\nvarying vec2 v_rgbNE;\nvarying vec2 v_rgbSW;\nvarying vec2 v_rgbSE;\nvarying vec2 v_rgbM;\n\nvarying vec2 vFragCoord;\nuniform sampler2D uSampler;\nuniform highp vec4 inputSize;\n\n\n/**\n Basic FXAA implementation based on the code on geeks3d.com with the\n modification that the texture2DLod stuff was removed since it's\n unsupported by WebGL.\n\n --\n\n From:\n https://github.com/mitsuhiko/webgl-meincraft\n\n Copyright (c) 2011 by Armin Ronacher.\n\n Some rights reserved.\n\n Redistribution and use in source and binary forms, with or without\n modification, are permitted provided that the following conditions are\n met:\n\n * Redistributions of source code must retain the above copyright\n notice, this list of conditions and the following disclaimer.\n\n * Redistributions in binary form must reproduce the above\n copyright notice, this list of conditions and the following\n disclaimer in the documentation and/or other materials provided\n with the distribution.\n\n * The names of the contributors may not be used to endorse or\n promote products derived from this software without specific\n prior written permission.\n\n THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n */\n\n#ifndef FXAA_REDUCE_MIN\n#define FXAA_REDUCE_MIN (1.0/ 128.0)\n#endif\n#ifndef FXAA_REDUCE_MUL\n#define FXAA_REDUCE_MUL (1.0 / 8.0)\n#endif\n#ifndef FXAA_SPAN_MAX\n#define FXAA_SPAN_MAX 8.0\n#endif\n\n//optimized version for mobile, where dependent\n//texture reads can be a bottleneck\nvec4 fxaa(sampler2D tex, vec2 fragCoord, vec2 inverseVP,\n vec2 v_rgbNW, vec2 v_rgbNE,\n vec2 v_rgbSW, vec2 v_rgbSE,\n vec2 v_rgbM) {\n vec4 color;\n vec3 rgbNW = texture2D(tex, v_rgbNW).xyz;\n vec3 rgbNE = texture2D(tex, v_rgbNE).xyz;\n vec3 rgbSW = texture2D(tex, v_rgbSW).xyz;\n vec3 rgbSE = texture2D(tex, v_rgbSE).xyz;\n vec4 texColor = texture2D(tex, v_rgbM);\n vec3 rgbM = texColor.xyz;\n vec3 luma = vec3(0.299, 0.587, 0.114);\n float lumaNW = dot(rgbNW, luma);\n float lumaNE = dot(rgbNE, luma);\n float lumaSW = dot(rgbSW, luma);\n float lumaSE = dot(rgbSE, luma);\n float lumaM = dot(rgbM, luma);\n float lumaMin = min(lumaM, min(min(lumaNW, lumaNE), min(lumaSW, lumaSE)));\n float lumaMax = max(lumaM, max(max(lumaNW, lumaNE), max(lumaSW, lumaSE)));\n\n mediump vec2 dir;\n dir.x = -((lumaNW + lumaNE) - (lumaSW + lumaSE));\n dir.y = ((lumaNW + lumaSW) - (lumaNE + lumaSE));\n\n float dirReduce = max((lumaNW + lumaNE + lumaSW + lumaSE) *\n (0.25 * FXAA_REDUCE_MUL), FXAA_REDUCE_MIN);\n\n float rcpDirMin = 1.0 / (min(abs(dir.x), abs(dir.y)) + dirReduce);\n dir = min(vec2(FXAA_SPAN_MAX, FXAA_SPAN_MAX),\n max(vec2(-FXAA_SPAN_MAX, -FXAA_SPAN_MAX),\n dir * rcpDirMin)) * inverseVP;\n\n vec3 rgbA = 0.5 * (\n texture2D(tex, fragCoord * inverseVP + dir * (1.0 / 3.0 - 0.5)).xyz +\n texture2D(tex, fragCoord * inverseVP + dir * (2.0 / 3.0 - 0.5)).xyz);\n vec3 rgbB = rgbA * 0.5 + 0.25 * (\n texture2D(tex, fragCoord * inverseVP + dir * -0.5).xyz +\n texture2D(tex, fragCoord * inverseVP + dir * 0.5).xyz);\n\n float lumaB = dot(rgbB, luma);\n if ((lumaB < lumaMin) || (lumaB > lumaMax))\n color = vec4(rgbA, texColor.a);\n else\n color = vec4(rgbB, texColor.a);\n return color;\n}\n\nvoid main() {\n\n vec4 color;\n\n color = fxaa(uSampler, vFragCoord, inputSize.zw, v_rgbNW, v_rgbNE, v_rgbSW, v_rgbSE, v_rgbM);\n\n gl_FragColor = color;\n}\n";
  40446. /**
  40447. * Basic FXAA (Fast Approximate Anti-Aliasing) implementation based on the code on geeks3d.com
  40448. * with the modification that the texture2DLod stuff was removed since it is unsupported by WebGL.
  40449. *
  40450. * @see https://github.com/mitsuhiko/webgl-meincraft
  40451. *
  40452. * @class
  40453. * @extends PIXI.Filter
  40454. * @memberof PIXI.filters
  40455. *
  40456. */
  40457. var FXAAFilter = /** @class */ (function (_super) {
  40458. __extends$g(FXAAFilter, _super);
  40459. function FXAAFilter() {
  40460. // TODO - needs work
  40461. return _super.call(this, vertex$5, fragment$7) || this;
  40462. }
  40463. return FXAAFilter;
  40464. }(Filter));
  40465. /*!
  40466. * @pixi/filter-noise - v6.1.2
  40467. * Compiled Thu, 12 Aug 2021 17:11:19 UTC
  40468. *
  40469. * @pixi/filter-noise is licensed under the MIT License.
  40470. * http://www.opensource.org/licenses/mit-license
  40471. */
  40472. /*! *****************************************************************************
  40473. Copyright (c) Microsoft Corporation. All rights reserved.
  40474. Licensed under the Apache License, Version 2.0 (the "License"); you may not use
  40475. this file except in compliance with the License. You may obtain a copy of the
  40476. License at http://www.apache.org/licenses/LICENSE-2.0
  40477. THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  40478. KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
  40479. WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
  40480. MERCHANTABLITY OR NON-INFRINGEMENT.
  40481. See the Apache Version 2.0 License for specific language governing permissions
  40482. and limitations under the License.
  40483. ***************************************************************************** */
  40484. /* global Reflect, Promise */
  40485. var extendStatics$h = function(d, b) {
  40486. extendStatics$h = Object.setPrototypeOf ||
  40487. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  40488. function (d, b) { for (var p in b) { if (b.hasOwnProperty(p)) { d[p] = b[p]; } } };
  40489. return extendStatics$h(d, b);
  40490. };
  40491. function __extends$h(d, b) {
  40492. extendStatics$h(d, b);
  40493. function __() { this.constructor = d; }
  40494. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  40495. }
  40496. var fragment$8 = "precision highp float;\n\nvarying vec2 vTextureCoord;\nvarying vec4 vColor;\n\nuniform float uNoise;\nuniform float uSeed;\nuniform sampler2D uSampler;\n\nfloat rand(vec2 co)\n{\n return fract(sin(dot(co.xy, vec2(12.9898, 78.233))) * 43758.5453);\n}\n\nvoid main()\n{\n vec4 color = texture2D(uSampler, vTextureCoord);\n float randomValue = rand(gl_FragCoord.xy * uSeed);\n float diff = (randomValue - 0.5) * uNoise;\n\n // Un-premultiply alpha before applying the color matrix. See issue #3539.\n if (color.a > 0.0) {\n color.rgb /= color.a;\n }\n\n color.r += diff;\n color.g += diff;\n color.b += diff;\n\n // Premultiply alpha again.\n color.rgb *= color.a;\n\n gl_FragColor = color;\n}\n";
  40497. /**
  40498. * A Noise effect filter.
  40499. *
  40500. * original filter: https://github.com/evanw/glfx.js/blob/master/src/filters/adjust/noise.js
  40501. *
  40502. * @class
  40503. * @extends PIXI.Filter
  40504. * @memberof PIXI.filters
  40505. * @author Vico @vicocotea
  40506. */
  40507. var NoiseFilter = /** @class */ (function (_super) {
  40508. __extends$h(NoiseFilter, _super);
  40509. /**
  40510. * @param {number} [noise=0.5] - The noise intensity, should be a normalized value in the range [0, 1].
  40511. * @param {number} [seed] - A random seed for the noise generation. Default is `Math.random()`.
  40512. */
  40513. function NoiseFilter(noise, seed) {
  40514. if (noise === void 0) { noise = 0.5; }
  40515. if (seed === void 0) { seed = Math.random(); }
  40516. var _this = _super.call(this, defaultFilterVertex, fragment$8, {
  40517. uNoise: 0,
  40518. uSeed: 0,
  40519. }) || this;
  40520. _this.noise = noise;
  40521. _this.seed = seed;
  40522. return _this;
  40523. }
  40524. Object.defineProperty(NoiseFilter.prototype, "noise", {
  40525. /**
  40526. * The amount of noise to apply, this value should be in the range (0, 1].
  40527. *
  40528. * @member {number}
  40529. * @default 0.5
  40530. */
  40531. get: function () {
  40532. return this.uniforms.uNoise;
  40533. },
  40534. set: function (value) {
  40535. this.uniforms.uNoise = value;
  40536. },
  40537. enumerable: false,
  40538. configurable: true
  40539. });
  40540. Object.defineProperty(NoiseFilter.prototype, "seed", {
  40541. /**
  40542. * A seed value to apply to the random noise generation. `Math.random()` is a good value to use.
  40543. *
  40544. * @member {number}
  40545. */
  40546. get: function () {
  40547. return this.uniforms.uSeed;
  40548. },
  40549. set: function (value) {
  40550. this.uniforms.uSeed = value;
  40551. },
  40552. enumerable: false,
  40553. configurable: true
  40554. });
  40555. return NoiseFilter;
  40556. }(Filter));
  40557. /*!
  40558. * @pixi/mixin-cache-as-bitmap - v6.1.2
  40559. * Compiled Thu, 12 Aug 2021 17:11:19 UTC
  40560. *
  40561. * @pixi/mixin-cache-as-bitmap is licensed under the MIT License.
  40562. * http://www.opensource.org/licenses/mit-license
  40563. */
  40564. /*!
  40565. * @pixi/constants - v6.1.2
  40566. * Compiled Thu, 12 Aug 2021 17:11:19 UTC
  40567. *
  40568. * @pixi/constants is licensed under the MIT License.
  40569. * http://www.opensource.org/licenses/mit-license
  40570. */
  40571. /**
  40572. * Different types of environments for WebGL.
  40573. *
  40574. * @static
  40575. * @memberof PIXI
  40576. * @name ENV
  40577. * @enum {number}
  40578. * @property {number} WEBGL_LEGACY - Used for older v1 WebGL devices. PixiJS will aim to ensure compatibility
  40579. * with older / less advanced devices. If you experience unexplained flickering prefer this environment.
  40580. * @property {number} WEBGL - Version 1 of WebGL
  40581. * @property {number} WEBGL2 - Version 2 of WebGL
  40582. */
  40583. var ENV$2;
  40584. (function (ENV) {
  40585. ENV[ENV["WEBGL_LEGACY"] = 0] = "WEBGL_LEGACY";
  40586. ENV[ENV["WEBGL"] = 1] = "WEBGL";
  40587. ENV[ENV["WEBGL2"] = 2] = "WEBGL2";
  40588. })(ENV$2 || (ENV$2 = {}));
  40589. /**
  40590. * Constant to identify the Renderer Type.
  40591. *
  40592. * @static
  40593. * @memberof PIXI
  40594. * @name RENDERER_TYPE
  40595. * @enum {number}
  40596. * @property {number} UNKNOWN - Unknown render type.
  40597. * @property {number} WEBGL - WebGL render type.
  40598. * @property {number} CANVAS - Canvas render type.
  40599. */
  40600. var RENDERER_TYPE$2;
  40601. (function (RENDERER_TYPE) {
  40602. RENDERER_TYPE[RENDERER_TYPE["UNKNOWN"] = 0] = "UNKNOWN";
  40603. RENDERER_TYPE[RENDERER_TYPE["WEBGL"] = 1] = "WEBGL";
  40604. RENDERER_TYPE[RENDERER_TYPE["CANVAS"] = 2] = "CANVAS";
  40605. })(RENDERER_TYPE$2 || (RENDERER_TYPE$2 = {}));
  40606. /**
  40607. * Bitwise OR of masks that indicate the buffers to be cleared.
  40608. *
  40609. * @static
  40610. * @memberof PIXI
  40611. * @name BUFFER_BITS
  40612. * @enum {number}
  40613. * @property {number} COLOR - Indicates the buffers currently enabled for color writing.
  40614. * @property {number} DEPTH - Indicates the depth buffer.
  40615. * @property {number} STENCIL - Indicates the stencil buffer.
  40616. */
  40617. var BUFFER_BITS$2;
  40618. (function (BUFFER_BITS) {
  40619. BUFFER_BITS[BUFFER_BITS["COLOR"] = 16384] = "COLOR";
  40620. BUFFER_BITS[BUFFER_BITS["DEPTH"] = 256] = "DEPTH";
  40621. BUFFER_BITS[BUFFER_BITS["STENCIL"] = 1024] = "STENCIL";
  40622. })(BUFFER_BITS$2 || (BUFFER_BITS$2 = {}));
  40623. /**
  40624. * Various blend modes supported by PIXI.
  40625. *
  40626. * IMPORTANT - The WebGL renderer only supports the NORMAL, ADD, MULTIPLY and SCREEN blend modes.
  40627. * Anything else will silently act like NORMAL.
  40628. *
  40629. * @memberof PIXI
  40630. * @name BLEND_MODES
  40631. * @enum {number}
  40632. * @property {number} NORMAL
  40633. * @property {number} ADD
  40634. * @property {number} MULTIPLY
  40635. * @property {number} SCREEN
  40636. * @property {number} OVERLAY
  40637. * @property {number} DARKEN
  40638. * @property {number} LIGHTEN
  40639. * @property {number} COLOR_DODGE
  40640. * @property {number} COLOR_BURN
  40641. * @property {number} HARD_LIGHT
  40642. * @property {number} SOFT_LIGHT
  40643. * @property {number} DIFFERENCE
  40644. * @property {number} EXCLUSION
  40645. * @property {number} HUE
  40646. * @property {number} SATURATION
  40647. * @property {number} COLOR
  40648. * @property {number} LUMINOSITY
  40649. * @property {number} NORMAL_NPM
  40650. * @property {number} ADD_NPM
  40651. * @property {number} SCREEN_NPM
  40652. * @property {number} NONE
  40653. * @property {number} SRC_IN
  40654. * @property {number} SRC_OUT
  40655. * @property {number} SRC_ATOP
  40656. * @property {number} DST_OVER
  40657. * @property {number} DST_IN
  40658. * @property {number} DST_OUT
  40659. * @property {number} DST_ATOP
  40660. * @property {number} SUBTRACT
  40661. * @property {number} SRC_OVER
  40662. * @property {number} ERASE
  40663. * @property {number} XOR
  40664. */
  40665. var BLEND_MODES$2;
  40666. (function (BLEND_MODES) {
  40667. BLEND_MODES[BLEND_MODES["NORMAL"] = 0] = "NORMAL";
  40668. BLEND_MODES[BLEND_MODES["ADD"] = 1] = "ADD";
  40669. BLEND_MODES[BLEND_MODES["MULTIPLY"] = 2] = "MULTIPLY";
  40670. BLEND_MODES[BLEND_MODES["SCREEN"] = 3] = "SCREEN";
  40671. BLEND_MODES[BLEND_MODES["OVERLAY"] = 4] = "OVERLAY";
  40672. BLEND_MODES[BLEND_MODES["DARKEN"] = 5] = "DARKEN";
  40673. BLEND_MODES[BLEND_MODES["LIGHTEN"] = 6] = "LIGHTEN";
  40674. BLEND_MODES[BLEND_MODES["COLOR_DODGE"] = 7] = "COLOR_DODGE";
  40675. BLEND_MODES[BLEND_MODES["COLOR_BURN"] = 8] = "COLOR_BURN";
  40676. BLEND_MODES[BLEND_MODES["HARD_LIGHT"] = 9] = "HARD_LIGHT";
  40677. BLEND_MODES[BLEND_MODES["SOFT_LIGHT"] = 10] = "SOFT_LIGHT";
  40678. BLEND_MODES[BLEND_MODES["DIFFERENCE"] = 11] = "DIFFERENCE";
  40679. BLEND_MODES[BLEND_MODES["EXCLUSION"] = 12] = "EXCLUSION";
  40680. BLEND_MODES[BLEND_MODES["HUE"] = 13] = "HUE";
  40681. BLEND_MODES[BLEND_MODES["SATURATION"] = 14] = "SATURATION";
  40682. BLEND_MODES[BLEND_MODES["COLOR"] = 15] = "COLOR";
  40683. BLEND_MODES[BLEND_MODES["LUMINOSITY"] = 16] = "LUMINOSITY";
  40684. BLEND_MODES[BLEND_MODES["NORMAL_NPM"] = 17] = "NORMAL_NPM";
  40685. BLEND_MODES[BLEND_MODES["ADD_NPM"] = 18] = "ADD_NPM";
  40686. BLEND_MODES[BLEND_MODES["SCREEN_NPM"] = 19] = "SCREEN_NPM";
  40687. BLEND_MODES[BLEND_MODES["NONE"] = 20] = "NONE";
  40688. BLEND_MODES[BLEND_MODES["SRC_OVER"] = 0] = "SRC_OVER";
  40689. BLEND_MODES[BLEND_MODES["SRC_IN"] = 21] = "SRC_IN";
  40690. BLEND_MODES[BLEND_MODES["SRC_OUT"] = 22] = "SRC_OUT";
  40691. BLEND_MODES[BLEND_MODES["SRC_ATOP"] = 23] = "SRC_ATOP";
  40692. BLEND_MODES[BLEND_MODES["DST_OVER"] = 24] = "DST_OVER";
  40693. BLEND_MODES[BLEND_MODES["DST_IN"] = 25] = "DST_IN";
  40694. BLEND_MODES[BLEND_MODES["DST_OUT"] = 26] = "DST_OUT";
  40695. BLEND_MODES[BLEND_MODES["DST_ATOP"] = 27] = "DST_ATOP";
  40696. BLEND_MODES[BLEND_MODES["ERASE"] = 26] = "ERASE";
  40697. BLEND_MODES[BLEND_MODES["SUBTRACT"] = 28] = "SUBTRACT";
  40698. BLEND_MODES[BLEND_MODES["XOR"] = 29] = "XOR";
  40699. })(BLEND_MODES$2 || (BLEND_MODES$2 = {}));
  40700. /**
  40701. * Various webgl draw modes. These can be used to specify which GL drawMode to use
  40702. * under certain situations and renderers.
  40703. *
  40704. * @memberof PIXI
  40705. * @static
  40706. * @name DRAW_MODES
  40707. * @enum {number}
  40708. * @property {number} POINTS
  40709. * @property {number} LINES
  40710. * @property {number} LINE_LOOP
  40711. * @property {number} LINE_STRIP
  40712. * @property {number} TRIANGLES
  40713. * @property {number} TRIANGLE_STRIP
  40714. * @property {number} TRIANGLE_FAN
  40715. */
  40716. var DRAW_MODES$2;
  40717. (function (DRAW_MODES) {
  40718. DRAW_MODES[DRAW_MODES["POINTS"] = 0] = "POINTS";
  40719. DRAW_MODES[DRAW_MODES["LINES"] = 1] = "LINES";
  40720. DRAW_MODES[DRAW_MODES["LINE_LOOP"] = 2] = "LINE_LOOP";
  40721. DRAW_MODES[DRAW_MODES["LINE_STRIP"] = 3] = "LINE_STRIP";
  40722. DRAW_MODES[DRAW_MODES["TRIANGLES"] = 4] = "TRIANGLES";
  40723. DRAW_MODES[DRAW_MODES["TRIANGLE_STRIP"] = 5] = "TRIANGLE_STRIP";
  40724. DRAW_MODES[DRAW_MODES["TRIANGLE_FAN"] = 6] = "TRIANGLE_FAN";
  40725. })(DRAW_MODES$2 || (DRAW_MODES$2 = {}));
  40726. /**
  40727. * Various GL texture/resources formats.
  40728. *
  40729. * @memberof PIXI
  40730. * @static
  40731. * @name FORMATS
  40732. * @enum {number}
  40733. * @property {number} RGBA=6408
  40734. * @property {number} RGB=6407
  40735. * @property {number} RG=33319
  40736. * @property {number} RED=6403
  40737. * @property {number} RGBA_INTEGER=36249
  40738. * @property {number} RGB_INTEGER=36248
  40739. * @property {number} RG_INTEGER=33320
  40740. * @property {number} RED_INTEGER=36244
  40741. * @property {number} ALPHA=6406
  40742. * @property {number} LUMINANCE=6409
  40743. * @property {number} LUMINANCE_ALPHA=6410
  40744. * @property {number} DEPTH_COMPONENT=6402
  40745. * @property {number} DEPTH_STENCIL=34041
  40746. */
  40747. var FORMATS$2;
  40748. (function (FORMATS) {
  40749. FORMATS[FORMATS["RGBA"] = 6408] = "RGBA";
  40750. FORMATS[FORMATS["RGB"] = 6407] = "RGB";
  40751. FORMATS[FORMATS["RG"] = 33319] = "RG";
  40752. FORMATS[FORMATS["RED"] = 6403] = "RED";
  40753. FORMATS[FORMATS["RGBA_INTEGER"] = 36249] = "RGBA_INTEGER";
  40754. FORMATS[FORMATS["RGB_INTEGER"] = 36248] = "RGB_INTEGER";
  40755. FORMATS[FORMATS["RG_INTEGER"] = 33320] = "RG_INTEGER";
  40756. FORMATS[FORMATS["RED_INTEGER"] = 36244] = "RED_INTEGER";
  40757. FORMATS[FORMATS["ALPHA"] = 6406] = "ALPHA";
  40758. FORMATS[FORMATS["LUMINANCE"] = 6409] = "LUMINANCE";
  40759. FORMATS[FORMATS["LUMINANCE_ALPHA"] = 6410] = "LUMINANCE_ALPHA";
  40760. FORMATS[FORMATS["DEPTH_COMPONENT"] = 6402] = "DEPTH_COMPONENT";
  40761. FORMATS[FORMATS["DEPTH_STENCIL"] = 34041] = "DEPTH_STENCIL";
  40762. })(FORMATS$2 || (FORMATS$2 = {}));
  40763. /**
  40764. * Various GL target types.
  40765. *
  40766. * @memberof PIXI
  40767. * @static
  40768. * @name TARGETS
  40769. * @enum {number}
  40770. * @property {number} TEXTURE_2D=3553
  40771. * @property {number} TEXTURE_CUBE_MAP=34067
  40772. * @property {number} TEXTURE_2D_ARRAY=35866
  40773. * @property {number} TEXTURE_CUBE_MAP_POSITIVE_X=34069
  40774. * @property {number} TEXTURE_CUBE_MAP_NEGATIVE_X=34070
  40775. * @property {number} TEXTURE_CUBE_MAP_POSITIVE_Y=34071
  40776. * @property {number} TEXTURE_CUBE_MAP_NEGATIVE_Y=34072
  40777. * @property {number} TEXTURE_CUBE_MAP_POSITIVE_Z=34073
  40778. * @property {number} TEXTURE_CUBE_MAP_NEGATIVE_Z=34074
  40779. */
  40780. var TARGETS$2;
  40781. (function (TARGETS) {
  40782. TARGETS[TARGETS["TEXTURE_2D"] = 3553] = "TEXTURE_2D";
  40783. TARGETS[TARGETS["TEXTURE_CUBE_MAP"] = 34067] = "TEXTURE_CUBE_MAP";
  40784. TARGETS[TARGETS["TEXTURE_2D_ARRAY"] = 35866] = "TEXTURE_2D_ARRAY";
  40785. TARGETS[TARGETS["TEXTURE_CUBE_MAP_POSITIVE_X"] = 34069] = "TEXTURE_CUBE_MAP_POSITIVE_X";
  40786. TARGETS[TARGETS["TEXTURE_CUBE_MAP_NEGATIVE_X"] = 34070] = "TEXTURE_CUBE_MAP_NEGATIVE_X";
  40787. TARGETS[TARGETS["TEXTURE_CUBE_MAP_POSITIVE_Y"] = 34071] = "TEXTURE_CUBE_MAP_POSITIVE_Y";
  40788. TARGETS[TARGETS["TEXTURE_CUBE_MAP_NEGATIVE_Y"] = 34072] = "TEXTURE_CUBE_MAP_NEGATIVE_Y";
  40789. TARGETS[TARGETS["TEXTURE_CUBE_MAP_POSITIVE_Z"] = 34073] = "TEXTURE_CUBE_MAP_POSITIVE_Z";
  40790. TARGETS[TARGETS["TEXTURE_CUBE_MAP_NEGATIVE_Z"] = 34074] = "TEXTURE_CUBE_MAP_NEGATIVE_Z";
  40791. })(TARGETS$2 || (TARGETS$2 = {}));
  40792. /**
  40793. * Various GL data format types.
  40794. *
  40795. * @memberof PIXI
  40796. * @static
  40797. * @name TYPES
  40798. * @enum {number}
  40799. * @property {number} UNSIGNED_BYTE=5121
  40800. * @property {number} UNSIGNED_SHORT=5123
  40801. * @property {number} UNSIGNED_SHORT_5_6_5=33635
  40802. * @property {number} UNSIGNED_SHORT_4_4_4_4=32819
  40803. * @property {number} UNSIGNED_SHORT_5_5_5_1=32820
  40804. * @property {number} UNSIGNED_INT=5125
  40805. * @property {number} UNSIGNED_INT_10F_11F_11F_REV=35899
  40806. * @property {number} UNSIGNED_INT_2_10_10_10_REV=33640
  40807. * @property {number} UNSIGNED_INT_24_8=34042
  40808. * @property {number} UNSIGNED_INT_5_9_9_9_REV=35902
  40809. * @property {number} BYTE=5120
  40810. * @property {number} SHORT=5122
  40811. * @property {number} INT=5124
  40812. * @property {number} FLOAT=5126
  40813. * @property {number} FLOAT_32_UNSIGNED_INT_24_8_REV=36269
  40814. * @property {number} HALF_FLOAT=36193
  40815. */
  40816. var TYPES$2;
  40817. (function (TYPES) {
  40818. TYPES[TYPES["UNSIGNED_BYTE"] = 5121] = "UNSIGNED_BYTE";
  40819. TYPES[TYPES["UNSIGNED_SHORT"] = 5123] = "UNSIGNED_SHORT";
  40820. TYPES[TYPES["UNSIGNED_SHORT_5_6_5"] = 33635] = "UNSIGNED_SHORT_5_6_5";
  40821. TYPES[TYPES["UNSIGNED_SHORT_4_4_4_4"] = 32819] = "UNSIGNED_SHORT_4_4_4_4";
  40822. TYPES[TYPES["UNSIGNED_SHORT_5_5_5_1"] = 32820] = "UNSIGNED_SHORT_5_5_5_1";
  40823. TYPES[TYPES["UNSIGNED_INT"] = 5125] = "UNSIGNED_INT";
  40824. TYPES[TYPES["UNSIGNED_INT_10F_11F_11F_REV"] = 35899] = "UNSIGNED_INT_10F_11F_11F_REV";
  40825. TYPES[TYPES["UNSIGNED_INT_2_10_10_10_REV"] = 33640] = "UNSIGNED_INT_2_10_10_10_REV";
  40826. TYPES[TYPES["UNSIGNED_INT_24_8"] = 34042] = "UNSIGNED_INT_24_8";
  40827. TYPES[TYPES["UNSIGNED_INT_5_9_9_9_REV"] = 35902] = "UNSIGNED_INT_5_9_9_9_REV";
  40828. TYPES[TYPES["BYTE"] = 5120] = "BYTE";
  40829. TYPES[TYPES["SHORT"] = 5122] = "SHORT";
  40830. TYPES[TYPES["INT"] = 5124] = "INT";
  40831. TYPES[TYPES["FLOAT"] = 5126] = "FLOAT";
  40832. TYPES[TYPES["FLOAT_32_UNSIGNED_INT_24_8_REV"] = 36269] = "FLOAT_32_UNSIGNED_INT_24_8_REV";
  40833. TYPES[TYPES["HALF_FLOAT"] = 36193] = "HALF_FLOAT";
  40834. })(TYPES$2 || (TYPES$2 = {}));
  40835. /**
  40836. * Various sampler types. Correspond to `sampler`, `isampler`, `usampler` GLSL types respectively.
  40837. * WebGL1 works only with FLOAT.
  40838. *
  40839. * @memberof PIXI
  40840. * @static
  40841. * @name SAMPLER_TYPES
  40842. * @enum {number}
  40843. * @property {number} FLOAT=0
  40844. * @property {number} INT=1
  40845. * @property {number} UINT=2
  40846. */
  40847. var SAMPLER_TYPES$2;
  40848. (function (SAMPLER_TYPES) {
  40849. SAMPLER_TYPES[SAMPLER_TYPES["FLOAT"] = 0] = "FLOAT";
  40850. SAMPLER_TYPES[SAMPLER_TYPES["INT"] = 1] = "INT";
  40851. SAMPLER_TYPES[SAMPLER_TYPES["UINT"] = 2] = "UINT";
  40852. })(SAMPLER_TYPES$2 || (SAMPLER_TYPES$2 = {}));
  40853. /**
  40854. * The scale modes that are supported by pixi.
  40855. *
  40856. * The {@link PIXI.settings.SCALE_MODE} scale mode affects the default scaling mode of future operations.
  40857. * It can be re-assigned to either LINEAR or NEAREST, depending upon suitability.
  40858. *
  40859. * @memberof PIXI
  40860. * @static
  40861. * @name SCALE_MODES
  40862. * @enum {number}
  40863. * @property {number} LINEAR Smooth scaling
  40864. * @property {number} NEAREST Pixelating scaling
  40865. */
  40866. var SCALE_MODES$2;
  40867. (function (SCALE_MODES) {
  40868. SCALE_MODES[SCALE_MODES["NEAREST"] = 0] = "NEAREST";
  40869. SCALE_MODES[SCALE_MODES["LINEAR"] = 1] = "LINEAR";
  40870. })(SCALE_MODES$2 || (SCALE_MODES$2 = {}));
  40871. /**
  40872. * The wrap modes that are supported by pixi.
  40873. *
  40874. * The {@link PIXI.settings.WRAP_MODE} wrap mode affects the default wrapping mode of future operations.
  40875. * It can be re-assigned to either CLAMP or REPEAT, depending upon suitability.
  40876. * If the texture is non power of two then clamp will be used regardless as WebGL can
  40877. * only use REPEAT if the texture is po2.
  40878. *
  40879. * This property only affects WebGL.
  40880. *
  40881. * @name WRAP_MODES
  40882. * @memberof PIXI
  40883. * @static
  40884. * @enum {number}
  40885. * @property {number} CLAMP - The textures uvs are clamped
  40886. * @property {number} REPEAT - The texture uvs tile and repeat
  40887. * @property {number} MIRRORED_REPEAT - The texture uvs tile and repeat with mirroring
  40888. */
  40889. var WRAP_MODES$2;
  40890. (function (WRAP_MODES) {
  40891. WRAP_MODES[WRAP_MODES["CLAMP"] = 33071] = "CLAMP";
  40892. WRAP_MODES[WRAP_MODES["REPEAT"] = 10497] = "REPEAT";
  40893. WRAP_MODES[WRAP_MODES["MIRRORED_REPEAT"] = 33648] = "MIRRORED_REPEAT";
  40894. })(WRAP_MODES$2 || (WRAP_MODES$2 = {}));
  40895. /**
  40896. * Mipmap filtering modes that are supported by pixi.
  40897. *
  40898. * The {@link PIXI.settings.MIPMAP_TEXTURES} affects default texture filtering.
  40899. * Mipmaps are generated for a baseTexture if its `mipmap` field is `ON`,
  40900. * or its `POW2` and texture dimensions are powers of 2.
  40901. * Due to platform restriction, `ON` option will work like `POW2` for webgl-1.
  40902. *
  40903. * This property only affects WebGL.
  40904. *
  40905. * @name MIPMAP_MODES
  40906. * @memberof PIXI
  40907. * @static
  40908. * @enum {number}
  40909. * @property {number} OFF - No mipmaps
  40910. * @property {number} POW2 - Generate mipmaps if texture dimensions are pow2
  40911. * @property {number} ON - Always generate mipmaps
  40912. * @property {number} ON_MANUAL - Use mipmaps, but do not auto-generate them; this is used with a resource
  40913. * that supports buffering each level-of-detail.
  40914. */
  40915. var MIPMAP_MODES$2;
  40916. (function (MIPMAP_MODES) {
  40917. MIPMAP_MODES[MIPMAP_MODES["OFF"] = 0] = "OFF";
  40918. MIPMAP_MODES[MIPMAP_MODES["POW2"] = 1] = "POW2";
  40919. MIPMAP_MODES[MIPMAP_MODES["ON"] = 2] = "ON";
  40920. MIPMAP_MODES[MIPMAP_MODES["ON_MANUAL"] = 3] = "ON_MANUAL";
  40921. })(MIPMAP_MODES$2 || (MIPMAP_MODES$2 = {}));
  40922. /**
  40923. * How to treat textures with premultiplied alpha
  40924. *
  40925. * @name ALPHA_MODES
  40926. * @memberof PIXI
  40927. * @static
  40928. * @enum {number}
  40929. * @property {number} NO_PREMULTIPLIED_ALPHA - Source is not premultiplied, leave it like that.
  40930. * Option for compressed and data textures that are created from typed arrays.
  40931. * @property {number} PREMULTIPLY_ON_UPLOAD - Source is not premultiplied, premultiply on upload.
  40932. * Default option, used for all loaded images.
  40933. * @property {number} PREMULTIPLIED_ALPHA - Source is already premultiplied
  40934. * Example: spine atlases with `_pma` suffix.
  40935. * @property {number} NPM - Alias for NO_PREMULTIPLIED_ALPHA.
  40936. * @property {number} UNPACK - Default option, alias for PREMULTIPLY_ON_UPLOAD.
  40937. * @property {number} PMA - Alias for PREMULTIPLIED_ALPHA.
  40938. */
  40939. var ALPHA_MODES$2;
  40940. (function (ALPHA_MODES) {
  40941. ALPHA_MODES[ALPHA_MODES["NPM"] = 0] = "NPM";
  40942. ALPHA_MODES[ALPHA_MODES["UNPACK"] = 1] = "UNPACK";
  40943. ALPHA_MODES[ALPHA_MODES["PMA"] = 2] = "PMA";
  40944. ALPHA_MODES[ALPHA_MODES["NO_PREMULTIPLIED_ALPHA"] = 0] = "NO_PREMULTIPLIED_ALPHA";
  40945. ALPHA_MODES[ALPHA_MODES["PREMULTIPLY_ON_UPLOAD"] = 1] = "PREMULTIPLY_ON_UPLOAD";
  40946. ALPHA_MODES[ALPHA_MODES["PREMULTIPLY_ALPHA"] = 2] = "PREMULTIPLY_ALPHA";
  40947. })(ALPHA_MODES$2 || (ALPHA_MODES$2 = {}));
  40948. /**
  40949. * Configure whether filter textures are cleared after binding.
  40950. *
  40951. * Filter textures need not be cleared if the filter does not use pixel blending. {@link CLEAR_MODES.BLIT} will detect
  40952. * this and skip clearing as an optimization.
  40953. *
  40954. * @name CLEAR_MODES
  40955. * @memberof PIXI
  40956. * @static
  40957. * @enum {number}
  40958. * @property {number} BLEND - Do not clear the filter texture. The filter's output will blend on top of the output texture.
  40959. * @property {number} CLEAR - Always clear the filter texture.
  40960. * @property {number} BLIT - Clear only if {@link FilterSystem.forceClear} is set or if the filter uses pixel blending.
  40961. * @property {number} NO - Alias for BLEND, same as `false` in earlier versions
  40962. * @property {number} YES - Alias for CLEAR, same as `true` in earlier versions
  40963. * @property {number} AUTO - Alias for BLIT
  40964. */
  40965. var CLEAR_MODES$2;
  40966. (function (CLEAR_MODES) {
  40967. CLEAR_MODES[CLEAR_MODES["NO"] = 0] = "NO";
  40968. CLEAR_MODES[CLEAR_MODES["YES"] = 1] = "YES";
  40969. CLEAR_MODES[CLEAR_MODES["AUTO"] = 2] = "AUTO";
  40970. CLEAR_MODES[CLEAR_MODES["BLEND"] = 0] = "BLEND";
  40971. CLEAR_MODES[CLEAR_MODES["CLEAR"] = 1] = "CLEAR";
  40972. CLEAR_MODES[CLEAR_MODES["BLIT"] = 2] = "BLIT";
  40973. })(CLEAR_MODES$2 || (CLEAR_MODES$2 = {}));
  40974. /**
  40975. * The gc modes that are supported by pixi.
  40976. *
  40977. * The {@link PIXI.settings.GC_MODE} Garbage Collection mode for PixiJS textures is AUTO
  40978. * If set to GC_MODE, the renderer will occasionally check textures usage. If they are not
  40979. * used for a specified period of time they will be removed from the GPU. They will of course
  40980. * be uploaded again when they are required. This is a silent behind the scenes process that
  40981. * should ensure that the GPU does not get filled up.
  40982. *
  40983. * Handy for mobile devices!
  40984. * This property only affects WebGL.
  40985. *
  40986. * @name GC_MODES
  40987. * @enum {number}
  40988. * @static
  40989. * @memberof PIXI
  40990. * @property {number} AUTO - Garbage collection will happen periodically automatically
  40991. * @property {number} MANUAL - Garbage collection will need to be called manually
  40992. */
  40993. var GC_MODES$2;
  40994. (function (GC_MODES) {
  40995. GC_MODES[GC_MODES["AUTO"] = 0] = "AUTO";
  40996. GC_MODES[GC_MODES["MANUAL"] = 1] = "MANUAL";
  40997. })(GC_MODES$2 || (GC_MODES$2 = {}));
  40998. /**
  40999. * Constants that specify float precision in shaders.
  41000. *
  41001. * @name PRECISION
  41002. * @memberof PIXI
  41003. * @constant
  41004. * @static
  41005. * @enum {string}
  41006. * @property {string} LOW='lowp'
  41007. * @property {string} MEDIUM='mediump'
  41008. * @property {string} HIGH='highp'
  41009. */
  41010. var PRECISION$2;
  41011. (function (PRECISION) {
  41012. PRECISION["LOW"] = "lowp";
  41013. PRECISION["MEDIUM"] = "mediump";
  41014. PRECISION["HIGH"] = "highp";
  41015. })(PRECISION$2 || (PRECISION$2 = {}));
  41016. /**
  41017. * Constants for mask implementations.
  41018. * We use `type` suffix because it leads to very different behaviours
  41019. *
  41020. * @name MASK_TYPES
  41021. * @memberof PIXI
  41022. * @static
  41023. * @enum {number}
  41024. * @property {number} NONE - Mask is ignored
  41025. * @property {number} SCISSOR - Scissor mask, rectangle on screen, cheap
  41026. * @property {number} STENCIL - Stencil mask, 1-bit, medium, works only if renderer supports stencil
  41027. * @property {number} SPRITE - Mask that uses SpriteMaskFilter, uses temporary RenderTexture
  41028. */
  41029. var MASK_TYPES$2;
  41030. (function (MASK_TYPES) {
  41031. MASK_TYPES[MASK_TYPES["NONE"] = 0] = "NONE";
  41032. MASK_TYPES[MASK_TYPES["SCISSOR"] = 1] = "SCISSOR";
  41033. MASK_TYPES[MASK_TYPES["STENCIL"] = 2] = "STENCIL";
  41034. MASK_TYPES[MASK_TYPES["SPRITE"] = 3] = "SPRITE";
  41035. })(MASK_TYPES$2 || (MASK_TYPES$2 = {}));
  41036. /**
  41037. * Constants for multi-sampling antialiasing.
  41038. *
  41039. * @see PIXI.Framebuffer#multisample
  41040. *
  41041. * @name MSAA_QUALITY
  41042. * @memberof PIXI
  41043. * @static
  41044. * @enum {number}
  41045. * @property {number} NONE - No multisampling for this renderTexture
  41046. * @property {number} LOW - Try 2 samples
  41047. * @property {number} MEDIUM - Try 4 samples
  41048. * @property {number} HIGH - Try 8 samples
  41049. */
  41050. var MSAA_QUALITY$2;
  41051. (function (MSAA_QUALITY) {
  41052. MSAA_QUALITY[MSAA_QUALITY["NONE"] = 0] = "NONE";
  41053. MSAA_QUALITY[MSAA_QUALITY["LOW"] = 2] = "LOW";
  41054. MSAA_QUALITY[MSAA_QUALITY["MEDIUM"] = 4] = "MEDIUM";
  41055. MSAA_QUALITY[MSAA_QUALITY["HIGH"] = 8] = "HIGH";
  41056. })(MSAA_QUALITY$2 || (MSAA_QUALITY$2 = {}));
  41057. /**
  41058. * Constants for various buffer types in Pixi
  41059. *
  41060. * @see PIXI.BUFFER_TYPE
  41061. *
  41062. * @name BUFFER_TYPE
  41063. * @memberof PIXI
  41064. * @static
  41065. * @enum {number}
  41066. * @property {number} ELEMENT_ARRAY_BUFFER - buffer type for using as an index buffer
  41067. * @property {number} ARRAY_BUFFER - buffer type for using attribute data
  41068. * @property {number} UNIFORM_BUFFER - the buffer type is for uniform buffer objects
  41069. */
  41070. var BUFFER_TYPE$2;
  41071. (function (BUFFER_TYPE) {
  41072. BUFFER_TYPE[BUFFER_TYPE["ELEMENT_ARRAY_BUFFER"] = 34963] = "ELEMENT_ARRAY_BUFFER";
  41073. BUFFER_TYPE[BUFFER_TYPE["ARRAY_BUFFER"] = 34962] = "ARRAY_BUFFER";
  41074. // NOT YET SUPPORTED
  41075. BUFFER_TYPE[BUFFER_TYPE["UNIFORM_BUFFER"] = 35345] = "UNIFORM_BUFFER";
  41076. })(BUFFER_TYPE$2 || (BUFFER_TYPE$2 = {}));
  41077. var _tempMatrix = new Matrix();
  41078. DisplayObject.prototype._cacheAsBitmap = false;
  41079. DisplayObject.prototype._cacheData = null;
  41080. DisplayObject.prototype._cacheAsBitmapResolution = null;
  41081. DisplayObject.prototype._cacheAsBitmapMultisample = MSAA_QUALITY$2.NONE;
  41082. // figured there's no point adding ALL the extra variables to prototype.
  41083. // this model can hold the information needed. This can also be generated on demand as
  41084. // most objects are not cached as bitmaps.
  41085. /**
  41086. * @class
  41087. * @ignore
  41088. * @private
  41089. */
  41090. var CacheData = /** @class */ (function () {
  41091. function CacheData() {
  41092. this.textureCacheId = null;
  41093. this.originalRender = null;
  41094. this.originalRenderCanvas = null;
  41095. this.originalCalculateBounds = null;
  41096. this.originalGetLocalBounds = null;
  41097. this.originalUpdateTransform = null;
  41098. this.originalDestroy = null;
  41099. this.originalMask = null;
  41100. this.originalFilterArea = null;
  41101. this.originalContainsPoint = null;
  41102. this.sprite = null;
  41103. }
  41104. return CacheData;
  41105. }());
  41106. Object.defineProperties(DisplayObject.prototype, {
  41107. /**
  41108. * The resolution to use for cacheAsBitmap. By default this will use the renderer's resolution
  41109. * but can be overriden for performance. Lower values will reduce memory usage at the expense
  41110. * of render quality. A falsey value of `null` or `0` will default to the renderer's resolution.
  41111. * If `cacheAsBitmap` is set to `true`, this will re-render with the new resolution.
  41112. *
  41113. * @member {number} cacheAsBitmapResolution
  41114. * @memberof PIXI.DisplayObject#
  41115. * @default null
  41116. */
  41117. cacheAsBitmapResolution: {
  41118. get: function () {
  41119. return this._cacheAsBitmapResolution;
  41120. },
  41121. set: function (resolution) {
  41122. if (resolution === this._cacheAsBitmapResolution) {
  41123. return;
  41124. }
  41125. this._cacheAsBitmapResolution = resolution;
  41126. if (this.cacheAsBitmap) {
  41127. // Toggle to re-render at the new resolution
  41128. this.cacheAsBitmap = false;
  41129. this.cacheAsBitmap = true;
  41130. }
  41131. },
  41132. },
  41133. /**
  41134. * The number of samples to use for cacheAsBitmap. If set to `null`, the renderer's
  41135. * sample count is used.
  41136. * If `cacheAsBitmap` is set to `true`, this will re-render with the new number of samples.
  41137. *
  41138. * @member {number} cacheAsBitmapMultisample
  41139. * @memberof PIXI.DisplayObject#
  41140. * @default PIXI.MSAA_QUALITY.NONE
  41141. */
  41142. cacheAsBitmapMultisample: {
  41143. get: function () {
  41144. return this._cacheAsBitmapMultisample;
  41145. },
  41146. set: function (multisample) {
  41147. if (multisample === this._cacheAsBitmapMultisample) {
  41148. return;
  41149. }
  41150. this._cacheAsBitmapMultisample = multisample;
  41151. if (this.cacheAsBitmap) {
  41152. // Toggle to re-render with new multisample
  41153. this.cacheAsBitmap = false;
  41154. this.cacheAsBitmap = true;
  41155. }
  41156. },
  41157. },
  41158. /**
  41159. * Set this to true if you want this display object to be cached as a bitmap.
  41160. * This basically takes a snap shot of the display object as it is at that moment. It can
  41161. * provide a performance benefit for complex static displayObjects.
  41162. * To remove simply set this property to `false`
  41163. *
  41164. * IMPORTANT GOTCHA - Make sure that all your textures are preloaded BEFORE setting this property to true
  41165. * as it will take a snapshot of what is currently there. If the textures have not loaded then they will not appear.
  41166. *
  41167. * @member {boolean}
  41168. * @memberof PIXI.DisplayObject#
  41169. */
  41170. cacheAsBitmap: {
  41171. get: function () {
  41172. return this._cacheAsBitmap;
  41173. },
  41174. set: function (value) {
  41175. if (this._cacheAsBitmap === value) {
  41176. return;
  41177. }
  41178. this._cacheAsBitmap = value;
  41179. var data;
  41180. if (value) {
  41181. if (!this._cacheData) {
  41182. this._cacheData = new CacheData();
  41183. }
  41184. data = this._cacheData;
  41185. data.originalRender = this.render;
  41186. data.originalRenderCanvas = this.renderCanvas;
  41187. data.originalUpdateTransform = this.updateTransform;
  41188. data.originalCalculateBounds = this.calculateBounds;
  41189. data.originalGetLocalBounds = this.getLocalBounds;
  41190. data.originalDestroy = this.destroy;
  41191. data.originalContainsPoint = this.containsPoint;
  41192. data.originalMask = this._mask;
  41193. data.originalFilterArea = this.filterArea;
  41194. this.render = this._renderCached;
  41195. this.renderCanvas = this._renderCachedCanvas;
  41196. this.destroy = this._cacheAsBitmapDestroy;
  41197. }
  41198. else {
  41199. data = this._cacheData;
  41200. if (data.sprite) {
  41201. this._destroyCachedDisplayObject();
  41202. }
  41203. this.render = data.originalRender;
  41204. this.renderCanvas = data.originalRenderCanvas;
  41205. this.calculateBounds = data.originalCalculateBounds;
  41206. this.getLocalBounds = data.originalGetLocalBounds;
  41207. this.destroy = data.originalDestroy;
  41208. this.updateTransform = data.originalUpdateTransform;
  41209. this.containsPoint = data.originalContainsPoint;
  41210. this._mask = data.originalMask;
  41211. this.filterArea = data.originalFilterArea;
  41212. }
  41213. },
  41214. },
  41215. });
  41216. /**
  41217. * Renders a cached version of the sprite with WebGL
  41218. *
  41219. * @private
  41220. * @method _renderCached
  41221. * @memberof PIXI.DisplayObject#
  41222. * @param {PIXI.Renderer} renderer - the WebGL renderer
  41223. */
  41224. DisplayObject.prototype._renderCached = function _renderCached(renderer) {
  41225. if (!this.visible || this.worldAlpha <= 0 || !this.renderable) {
  41226. return;
  41227. }
  41228. this._initCachedDisplayObject(renderer);
  41229. this._cacheData.sprite.transform._worldID = this.transform._worldID;
  41230. this._cacheData.sprite.worldAlpha = this.worldAlpha;
  41231. this._cacheData.sprite._render(renderer);
  41232. };
  41233. /**
  41234. * Prepares the WebGL renderer to cache the sprite
  41235. *
  41236. * @private
  41237. * @method _initCachedDisplayObject
  41238. * @memberof PIXI.DisplayObject#
  41239. * @param {PIXI.Renderer} renderer - the WebGL renderer
  41240. */
  41241. DisplayObject.prototype._initCachedDisplayObject = function _initCachedDisplayObject(renderer) {
  41242. var _a;
  41243. if (this._cacheData && this._cacheData.sprite) {
  41244. return;
  41245. }
  41246. // make sure alpha is set to 1 otherwise it will get rendered as invisible!
  41247. var cacheAlpha = this.alpha;
  41248. this.alpha = 1;
  41249. // first we flush anything left in the renderer (otherwise it would get rendered to the cached texture)
  41250. renderer.batch.flush();
  41251. // this.filters= [];
  41252. // next we find the dimensions of the untransformed object
  41253. // this function also calls updatetransform on all its children as part of the measuring.
  41254. // This means we don't need to update the transform again in this function
  41255. // TODO pass an object to clone too? saves having to create a new one each time!
  41256. var bounds = this.getLocalBounds(null, true).clone();
  41257. // add some padding!
  41258. if (this.filters) {
  41259. var padding = this.filters[0].padding;
  41260. bounds.pad(padding);
  41261. }
  41262. bounds.ceil(settings.RESOLUTION);
  41263. // for now we cache the current renderTarget that the WebGL renderer is currently using.
  41264. // this could be more elegant..
  41265. var cachedRenderTexture = renderer.renderTexture.current;
  41266. var cachedSourceFrame = renderer.renderTexture.sourceFrame.clone();
  41267. var cachedDestinationFrame = renderer.renderTexture.destinationFrame.clone();
  41268. var cachedProjectionTransform = renderer.projection.transform;
  41269. // We also store the filter stack - I will definitely look to change how this works a little later down the line.
  41270. // const stack = renderer.filterManager.filterStack;
  41271. // this renderTexture will be used to store the cached DisplayObject
  41272. var renderTexture = RenderTexture.create({
  41273. width: bounds.width,
  41274. height: bounds.height,
  41275. resolution: this.cacheAsBitmapResolution || renderer.resolution,
  41276. multisample: (_a = this.cacheAsBitmapMultisample) !== null && _a !== void 0 ? _a : renderer.multisample,
  41277. });
  41278. var textureCacheId = "cacheAsBitmap_" + uid();
  41279. this._cacheData.textureCacheId = textureCacheId;
  41280. BaseTexture.addToCache(renderTexture.baseTexture, textureCacheId);
  41281. Texture.addToCache(renderTexture, textureCacheId);
  41282. // need to set //
  41283. var m = this.transform.localTransform.copyTo(_tempMatrix).invert().translate(-bounds.x, -bounds.y);
  41284. // set all properties to there original so we can render to a texture
  41285. this.render = this._cacheData.originalRender;
  41286. renderer.render(this, { renderTexture: renderTexture, clear: true, transform: m, skipUpdateTransform: false });
  41287. renderer.framebuffer.blit();
  41288. // now restore the state be setting the new properties
  41289. renderer.projection.transform = cachedProjectionTransform;
  41290. renderer.renderTexture.bind(cachedRenderTexture, cachedSourceFrame, cachedDestinationFrame);
  41291. // renderer.filterManager.filterStack = stack;
  41292. this.render = this._renderCached;
  41293. // the rest is the same as for Canvas
  41294. this.updateTransform = this.displayObjectUpdateTransform;
  41295. this.calculateBounds = this._calculateCachedBounds;
  41296. this.getLocalBounds = this._getCachedLocalBounds;
  41297. this._mask = null;
  41298. this.filterArea = null;
  41299. this.alpha = cacheAlpha;
  41300. // create our cached sprite
  41301. var cachedSprite = new Sprite(renderTexture);
  41302. cachedSprite.transform.worldTransform = this.transform.worldTransform;
  41303. cachedSprite.anchor.x = -(bounds.x / bounds.width);
  41304. cachedSprite.anchor.y = -(bounds.y / bounds.height);
  41305. cachedSprite.alpha = cacheAlpha;
  41306. cachedSprite._bounds = this._bounds;
  41307. this._cacheData.sprite = cachedSprite;
  41308. this.transform._parentID = -1;
  41309. // restore the transform of the cached sprite to avoid the nasty flicker..
  41310. if (!this.parent) {
  41311. this.enableTempParent();
  41312. this.updateTransform();
  41313. this.disableTempParent(null);
  41314. }
  41315. else {
  41316. this.updateTransform();
  41317. }
  41318. // map the hit test..
  41319. this.containsPoint = cachedSprite.containsPoint.bind(cachedSprite);
  41320. };
  41321. /**
  41322. * Renders a cached version of the sprite with canvas
  41323. *
  41324. * @private
  41325. * @method _renderCachedCanvas
  41326. * @memberof PIXI.DisplayObject#
  41327. * @param {PIXI.CanvasRenderer} renderer - The canvas renderer
  41328. */
  41329. DisplayObject.prototype._renderCachedCanvas = function _renderCachedCanvas(renderer) {
  41330. if (!this.visible || this.worldAlpha <= 0 || !this.renderable) {
  41331. return;
  41332. }
  41333. this._initCachedDisplayObjectCanvas(renderer);
  41334. this._cacheData.sprite.worldAlpha = this.worldAlpha;
  41335. this._cacheData.sprite._renderCanvas(renderer);
  41336. };
  41337. // TODO this can be the same as the WebGL version.. will need to do a little tweaking first though..
  41338. /**
  41339. * Prepares the Canvas renderer to cache the sprite
  41340. *
  41341. * @private
  41342. * @method _initCachedDisplayObjectCanvas
  41343. * @memberof PIXI.DisplayObject#
  41344. * @param {PIXI.CanvasRenderer} renderer - The canvas renderer
  41345. */
  41346. DisplayObject.prototype._initCachedDisplayObjectCanvas = function _initCachedDisplayObjectCanvas(renderer) {
  41347. if (this._cacheData && this._cacheData.sprite) {
  41348. return;
  41349. }
  41350. // get bounds actually transforms the object for us already!
  41351. var bounds = this.getLocalBounds(null, true);
  41352. var cacheAlpha = this.alpha;
  41353. this.alpha = 1;
  41354. var cachedRenderTarget = renderer.context;
  41355. var cachedProjectionTransform = renderer._projTransform;
  41356. bounds.ceil(settings.RESOLUTION);
  41357. var renderTexture = RenderTexture.create({ width: bounds.width, height: bounds.height });
  41358. var textureCacheId = "cacheAsBitmap_" + uid();
  41359. this._cacheData.textureCacheId = textureCacheId;
  41360. BaseTexture.addToCache(renderTexture.baseTexture, textureCacheId);
  41361. Texture.addToCache(renderTexture, textureCacheId);
  41362. // need to set //
  41363. var m = _tempMatrix;
  41364. this.transform.localTransform.copyTo(m);
  41365. m.invert();
  41366. m.tx -= bounds.x;
  41367. m.ty -= bounds.y;
  41368. // m.append(this.transform.worldTransform.)
  41369. // set all properties to there original so we can render to a texture
  41370. this.renderCanvas = this._cacheData.originalRenderCanvas;
  41371. renderer.render(this, { renderTexture: renderTexture, clear: true, transform: m, skipUpdateTransform: false });
  41372. // now restore the state be setting the new properties
  41373. renderer.context = cachedRenderTarget;
  41374. renderer._projTransform = cachedProjectionTransform;
  41375. this.renderCanvas = this._renderCachedCanvas;
  41376. // the rest is the same as for WebGL
  41377. this.updateTransform = this.displayObjectUpdateTransform;
  41378. this.calculateBounds = this._calculateCachedBounds;
  41379. this.getLocalBounds = this._getCachedLocalBounds;
  41380. this._mask = null;
  41381. this.filterArea = null;
  41382. this.alpha = cacheAlpha;
  41383. // create our cached sprite
  41384. var cachedSprite = new Sprite(renderTexture);
  41385. cachedSprite.transform.worldTransform = this.transform.worldTransform;
  41386. cachedSprite.anchor.x = -(bounds.x / bounds.width);
  41387. cachedSprite.anchor.y = -(bounds.y / bounds.height);
  41388. cachedSprite.alpha = cacheAlpha;
  41389. cachedSprite._bounds = this._bounds;
  41390. this._cacheData.sprite = cachedSprite;
  41391. this.transform._parentID = -1;
  41392. // restore the transform of the cached sprite to avoid the nasty flicker..
  41393. if (!this.parent) {
  41394. this.parent = renderer._tempDisplayObjectParent;
  41395. this.updateTransform();
  41396. this.parent = null;
  41397. }
  41398. else {
  41399. this.updateTransform();
  41400. }
  41401. // map the hit test..
  41402. this.containsPoint = cachedSprite.containsPoint.bind(cachedSprite);
  41403. };
  41404. /**
  41405. * Calculates the bounds of the cached sprite
  41406. *
  41407. * @private
  41408. * @method
  41409. */
  41410. DisplayObject.prototype._calculateCachedBounds = function _calculateCachedBounds() {
  41411. this._bounds.clear();
  41412. this._cacheData.sprite.transform._worldID = this.transform._worldID;
  41413. this._cacheData.sprite._calculateBounds();
  41414. this._bounds.updateID = this._boundsID;
  41415. };
  41416. /**
  41417. * Gets the bounds of the cached sprite.
  41418. *
  41419. * @private
  41420. * @method
  41421. * @return {Rectangle} The local bounds.
  41422. */
  41423. DisplayObject.prototype._getCachedLocalBounds = function _getCachedLocalBounds() {
  41424. return this._cacheData.sprite.getLocalBounds(null);
  41425. };
  41426. /**
  41427. * Destroys the cached sprite.
  41428. *
  41429. * @private
  41430. * @method
  41431. */
  41432. DisplayObject.prototype._destroyCachedDisplayObject = function _destroyCachedDisplayObject() {
  41433. this._cacheData.sprite._texture.destroy(true);
  41434. this._cacheData.sprite = null;
  41435. BaseTexture.removeFromCache(this._cacheData.textureCacheId);
  41436. Texture.removeFromCache(this._cacheData.textureCacheId);
  41437. this._cacheData.textureCacheId = null;
  41438. };
  41439. /**
  41440. * Destroys the cached object.
  41441. *
  41442. * @private
  41443. * @method
  41444. * @param {object|boolean} [options] - Options parameter. A boolean will act as if all options
  41445. * have been set to that value.
  41446. * Used when destroying containers, see the Container.destroy method.
  41447. */
  41448. DisplayObject.prototype._cacheAsBitmapDestroy = function _cacheAsBitmapDestroy(options) {
  41449. this.cacheAsBitmap = false;
  41450. this.destroy(options);
  41451. };
  41452. /*!
  41453. * @pixi/mixin-get-child-by-name - v6.1.2
  41454. * Compiled Thu, 12 Aug 2021 17:11:19 UTC
  41455. *
  41456. * @pixi/mixin-get-child-by-name is licensed under the MIT License.
  41457. * http://www.opensource.org/licenses/mit-license
  41458. */
  41459. /**
  41460. * The instance name of the object.
  41461. *
  41462. * @memberof PIXI.DisplayObject#
  41463. * @member {string} name
  41464. */
  41465. DisplayObject.prototype.name = null;
  41466. /**
  41467. * Returns the display object in the container.
  41468. *
  41469. * Recursive searches are done in a preorder traversal.
  41470. *
  41471. * @method getChildByName
  41472. * @memberof PIXI.Container#
  41473. * @param {string} name - Instance name.
  41474. * @param {boolean}[deep=false] - Whether to search recursively
  41475. * @return {PIXI.DisplayObject} The child with the specified name.
  41476. */
  41477. Container.prototype.getChildByName = function getChildByName(name, deep) {
  41478. for (var i = 0, j = this.children.length; i < j; i++) {
  41479. if (this.children[i].name === name) {
  41480. return this.children[i];
  41481. }
  41482. }
  41483. if (deep) {
  41484. for (var i = 0, j = this.children.length; i < j; i++) {
  41485. var child = this.children[i];
  41486. if (!child.getChildByName) {
  41487. continue;
  41488. }
  41489. var target = this.children[i].getChildByName(name, true);
  41490. if (target) {
  41491. return target;
  41492. }
  41493. }
  41494. }
  41495. return null;
  41496. };
  41497. /*!
  41498. * @pixi/mixin-get-global-position - v6.1.2
  41499. * Compiled Thu, 12 Aug 2021 17:11:19 UTC
  41500. *
  41501. * @pixi/mixin-get-global-position is licensed under the MIT License.
  41502. * http://www.opensource.org/licenses/mit-license
  41503. */
  41504. /**
  41505. * Returns the global position of the displayObject. Does not depend on object scale, rotation and pivot.
  41506. *
  41507. * @method getGlobalPosition
  41508. * @memberof PIXI.DisplayObject#
  41509. * @param {PIXI.Point} [point=new PIXI.Point()] - The point to write the global value to.
  41510. * @param {boolean} [skipUpdate=false] - Setting to true will stop the transforms of the scene graph from
  41511. * being updated. This means the calculation returned MAY be out of date BUT will give you a
  41512. * nice performance boost.
  41513. * @return {PIXI.Point} The updated point.
  41514. */
  41515. DisplayObject.prototype.getGlobalPosition = function getGlobalPosition(point, skipUpdate) {
  41516. if (point === void 0) { point = new Point(); }
  41517. if (skipUpdate === void 0) { skipUpdate = false; }
  41518. if (this.parent) {
  41519. this.parent.toGlobal(this.position, point, skipUpdate);
  41520. }
  41521. else {
  41522. point.x = this.position.x;
  41523. point.y = this.position.y;
  41524. }
  41525. return point;
  41526. };
  41527. /*!
  41528. * @pixi/mesh-extras - v6.1.2
  41529. * Compiled Thu, 12 Aug 2021 17:11:19 UTC
  41530. *
  41531. * @pixi/mesh-extras is licensed under the MIT License.
  41532. * http://www.opensource.org/licenses/mit-license
  41533. */
  41534. /*! *****************************************************************************
  41535. Copyright (c) Microsoft Corporation. All rights reserved.
  41536. Licensed under the Apache License, Version 2.0 (the "License"); you may not use
  41537. this file except in compliance with the License. You may obtain a copy of the
  41538. License at http://www.apache.org/licenses/LICENSE-2.0
  41539. THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  41540. KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
  41541. WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
  41542. MERCHANTABLITY OR NON-INFRINGEMENT.
  41543. See the Apache Version 2.0 License for specific language governing permissions
  41544. and limitations under the License.
  41545. ***************************************************************************** */
  41546. /* global Reflect, Promise */
  41547. var extendStatics$i = function(d, b) {
  41548. extendStatics$i = Object.setPrototypeOf ||
  41549. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  41550. function (d, b) { for (var p in b) { if (b.hasOwnProperty(p)) { d[p] = b[p]; } } };
  41551. return extendStatics$i(d, b);
  41552. };
  41553. function __extends$i(d, b) {
  41554. extendStatics$i(d, b);
  41555. function __() { this.constructor = d; }
  41556. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  41557. }
  41558. /**
  41559. * @memberof PIXI
  41560. */
  41561. var PlaneGeometry = /** @class */ (function (_super) {
  41562. __extends$i(PlaneGeometry, _super);
  41563. /**
  41564. * @param width - The width of the plane.
  41565. * @param height - The height of the plane.
  41566. * @param segWidth - Number of horizontal segments.
  41567. * @param segHeight - Number of vertical segments.
  41568. */
  41569. function PlaneGeometry(width, height, segWidth, segHeight) {
  41570. if (width === void 0) { width = 100; }
  41571. if (height === void 0) { height = 100; }
  41572. if (segWidth === void 0) { segWidth = 10; }
  41573. if (segHeight === void 0) { segHeight = 10; }
  41574. var _this = _super.call(this) || this;
  41575. _this.segWidth = segWidth;
  41576. _this.segHeight = segHeight;
  41577. _this.width = width;
  41578. _this.height = height;
  41579. _this.build();
  41580. return _this;
  41581. }
  41582. /**
  41583. * Refreshes plane coordinates
  41584. * @private
  41585. */
  41586. PlaneGeometry.prototype.build = function () {
  41587. var total = this.segWidth * this.segHeight;
  41588. var verts = [];
  41589. var uvs = [];
  41590. var indices = [];
  41591. var segmentsX = this.segWidth - 1;
  41592. var segmentsY = this.segHeight - 1;
  41593. var sizeX = (this.width) / segmentsX;
  41594. var sizeY = (this.height) / segmentsY;
  41595. for (var i = 0; i < total; i++) {
  41596. var x = (i % this.segWidth);
  41597. var y = ((i / this.segWidth) | 0);
  41598. verts.push(x * sizeX, y * sizeY);
  41599. uvs.push(x / segmentsX, y / segmentsY);
  41600. }
  41601. var totalSub = segmentsX * segmentsY;
  41602. for (var i = 0; i < totalSub; i++) {
  41603. var xpos = i % segmentsX;
  41604. var ypos = (i / segmentsX) | 0;
  41605. var value = (ypos * this.segWidth) + xpos;
  41606. var value2 = (ypos * this.segWidth) + xpos + 1;
  41607. var value3 = ((ypos + 1) * this.segWidth) + xpos;
  41608. var value4 = ((ypos + 1) * this.segWidth) + xpos + 1;
  41609. indices.push(value, value2, value3, value2, value4, value3);
  41610. }
  41611. this.buffers[0].data = new Float32Array(verts);
  41612. this.buffers[1].data = new Float32Array(uvs);
  41613. this.indexBuffer.data = new Uint16Array(indices);
  41614. // ensure that the changes are uploaded
  41615. this.buffers[0].update();
  41616. this.buffers[1].update();
  41617. this.indexBuffer.update();
  41618. };
  41619. return PlaneGeometry;
  41620. }(MeshGeometry));
  41621. /**
  41622. * RopeGeometry allows you to draw a geometry across several points and then manipulate these points.
  41623. *
  41624. * ```js
  41625. * for (let i = 0; i < 20; i++) {
  41626. * points.push(new PIXI.Point(i * 50, 0));
  41627. * };
  41628. * const rope = new PIXI.RopeGeometry(100, points);
  41629. * ```
  41630. *
  41631. * @class
  41632. * @extends PIXI.MeshGeometry
  41633. * @memberof PIXI
  41634. *
  41635. */
  41636. var RopeGeometry = /** @class */ (function (_super) {
  41637. __extends$i(RopeGeometry, _super);
  41638. /**
  41639. * @param {number} [width=200] - The width (i.e., thickness) of the rope.
  41640. * @param {PIXI.Point[]} [points] - An array of {@link PIXI.Point} objects to construct this rope.
  41641. * @param {number} [textureScale=0] - By default the rope texture will be stretched to match
  41642. * rope length. If textureScale is positive this value will be treated as a scaling
  41643. * factor and the texture will preserve its aspect ratio instead. To create a tiling rope
  41644. * set baseTexture.wrapMode to {@link PIXI.WRAP_MODES.REPEAT} and use a power of two texture,
  41645. * then set textureScale=1 to keep the original texture pixel size.
  41646. * In order to reduce alpha channel artifacts provide a larger texture and downsample -
  41647. * i.e. set textureScale=0.5 to scale it down twice.
  41648. */
  41649. function RopeGeometry(width, points, textureScale) {
  41650. if (width === void 0) { width = 200; }
  41651. if (textureScale === void 0) { textureScale = 0; }
  41652. var _this = _super.call(this, new Float32Array(points.length * 4), new Float32Array(points.length * 4), new Uint16Array((points.length - 1) * 6)) || this;
  41653. /**
  41654. * An array of points that determine the rope
  41655. * @member {PIXI.Point[]}
  41656. */
  41657. _this.points = points;
  41658. /**
  41659. * The width (i.e., thickness) of the rope.
  41660. * @member {number}
  41661. * @readOnly
  41662. */
  41663. _this._width = width;
  41664. /**
  41665. * Rope texture scale, if zero then the rope texture is stretched.
  41666. * @member {number}
  41667. * @readOnly
  41668. */
  41669. _this.textureScale = textureScale;
  41670. _this.build();
  41671. return _this;
  41672. }
  41673. Object.defineProperty(RopeGeometry.prototype, "width", {
  41674. /**
  41675. * The width (i.e., thickness) of the rope.
  41676. * @member {number}
  41677. * @readOnly
  41678. */
  41679. get: function () {
  41680. return this._width;
  41681. },
  41682. enumerable: false,
  41683. configurable: true
  41684. });
  41685. /**
  41686. * Refreshes Rope indices and uvs
  41687. * @private
  41688. */
  41689. RopeGeometry.prototype.build = function () {
  41690. var points = this.points;
  41691. if (!points)
  41692. { return; }
  41693. var vertexBuffer = this.getBuffer('aVertexPosition');
  41694. var uvBuffer = this.getBuffer('aTextureCoord');
  41695. var indexBuffer = this.getIndex();
  41696. // if too little points, or texture hasn't got UVs set yet just move on.
  41697. if (points.length < 1) {
  41698. return;
  41699. }
  41700. // if the number of points has changed we will need to recreate the arraybuffers
  41701. if (vertexBuffer.data.length / 4 !== points.length) {
  41702. vertexBuffer.data = new Float32Array(points.length * 4);
  41703. uvBuffer.data = new Float32Array(points.length * 4);
  41704. indexBuffer.data = new Uint16Array((points.length - 1) * 6);
  41705. }
  41706. var uvs = uvBuffer.data;
  41707. var indices = indexBuffer.data;
  41708. uvs[0] = 0;
  41709. uvs[1] = 0;
  41710. uvs[2] = 0;
  41711. uvs[3] = 1;
  41712. var amount = 0;
  41713. var prev = points[0];
  41714. var textureWidth = this._width * this.textureScale;
  41715. var total = points.length; // - 1;
  41716. for (var i = 0; i < total; i++) {
  41717. // time to do some smart drawing!
  41718. var index = i * 4;
  41719. if (this.textureScale > 0) {
  41720. // calculate pixel distance from previous point
  41721. var dx = prev.x - points[i].x;
  41722. var dy = prev.y - points[i].y;
  41723. var distance = Math.sqrt((dx * dx) + (dy * dy));
  41724. prev = points[i];
  41725. amount += distance / textureWidth;
  41726. }
  41727. else {
  41728. // stretch texture
  41729. amount = i / (total - 1);
  41730. }
  41731. uvs[index] = amount;
  41732. uvs[index + 1] = 0;
  41733. uvs[index + 2] = amount;
  41734. uvs[index + 3] = 1;
  41735. }
  41736. var indexCount = 0;
  41737. for (var i = 0; i < total - 1; i++) {
  41738. var index = i * 2;
  41739. indices[indexCount++] = index;
  41740. indices[indexCount++] = index + 1;
  41741. indices[indexCount++] = index + 2;
  41742. indices[indexCount++] = index + 2;
  41743. indices[indexCount++] = index + 1;
  41744. indices[indexCount++] = index + 3;
  41745. }
  41746. // ensure that the changes are uploaded
  41747. uvBuffer.update();
  41748. indexBuffer.update();
  41749. this.updateVertices();
  41750. };
  41751. /**
  41752. * refreshes vertices of Rope mesh
  41753. */
  41754. RopeGeometry.prototype.updateVertices = function () {
  41755. var points = this.points;
  41756. if (points.length < 1) {
  41757. return;
  41758. }
  41759. var lastPoint = points[0];
  41760. var nextPoint;
  41761. var perpX = 0;
  41762. var perpY = 0;
  41763. var vertices = this.buffers[0].data;
  41764. var total = points.length;
  41765. for (var i = 0; i < total; i++) {
  41766. var point = points[i];
  41767. var index = i * 4;
  41768. if (i < points.length - 1) {
  41769. nextPoint = points[i + 1];
  41770. }
  41771. else {
  41772. nextPoint = point;
  41773. }
  41774. perpY = -(nextPoint.x - lastPoint.x);
  41775. perpX = nextPoint.y - lastPoint.y;
  41776. var perpLength = Math.sqrt((perpX * perpX) + (perpY * perpY));
  41777. var num = this.textureScale > 0 ? this.textureScale * this._width / 2 : this._width / 2;
  41778. perpX /= perpLength;
  41779. perpY /= perpLength;
  41780. perpX *= num;
  41781. perpY *= num;
  41782. vertices[index] = point.x + perpX;
  41783. vertices[index + 1] = point.y + perpY;
  41784. vertices[index + 2] = point.x - perpX;
  41785. vertices[index + 3] = point.y - perpY;
  41786. lastPoint = point;
  41787. }
  41788. this.buffers[0].update();
  41789. };
  41790. RopeGeometry.prototype.update = function () {
  41791. if (this.textureScale > 0) {
  41792. this.build(); // we need to update UVs
  41793. }
  41794. else {
  41795. this.updateVertices();
  41796. }
  41797. };
  41798. return RopeGeometry;
  41799. }(MeshGeometry));
  41800. /**
  41801. * The rope allows you to draw a texture across several points and then manipulate these points
  41802. *
  41803. *```js
  41804. * for (let i = 0; i < 20; i++) {
  41805. * points.push(new PIXI.Point(i * 50, 0));
  41806. * };
  41807. * let rope = new PIXI.SimpleRope(PIXI.Texture.from("snake.png"), points);
  41808. * ```
  41809. *
  41810. * @class
  41811. * @extends PIXI.Mesh
  41812. * @memberof PIXI
  41813. *
  41814. */
  41815. var SimpleRope = /** @class */ (function (_super) {
  41816. __extends$i(SimpleRope, _super);
  41817. /**
  41818. * @param {PIXI.Texture} texture - The texture to use on the rope.
  41819. * @param {PIXI.Point[]} points - An array of {@link PIXI.Point} objects to construct this rope.
  41820. * @param {number} [textureScale=0] - Optional. Positive values scale rope texture
  41821. * keeping its aspect ratio. You can reduce alpha channel artifacts by providing a larger texture
  41822. * and downsampling here. If set to zero, texture will be stretched instead.
  41823. */
  41824. function SimpleRope(texture, points, textureScale) {
  41825. if (textureScale === void 0) { textureScale = 0; }
  41826. var _this = this;
  41827. var ropeGeometry = new RopeGeometry(texture.height, points, textureScale);
  41828. var meshMaterial = new MeshMaterial(texture);
  41829. if (textureScale > 0) {
  41830. // attempt to set UV wrapping, will fail on non-power of two textures
  41831. texture.baseTexture.wrapMode = exports.WRAP_MODES.REPEAT;
  41832. }
  41833. _this = _super.call(this, ropeGeometry, meshMaterial) || this;
  41834. /**
  41835. * re-calculate vertices by rope points each frame
  41836. *
  41837. * @member {boolean}
  41838. */
  41839. _this.autoUpdate = true;
  41840. return _this;
  41841. }
  41842. SimpleRope.prototype._render = function (renderer) {
  41843. var geometry = this.geometry;
  41844. if (this.autoUpdate || geometry._width !== this.shader.texture.height) {
  41845. geometry._width = this.shader.texture.height;
  41846. geometry.update();
  41847. }
  41848. _super.prototype._render.call(this, renderer);
  41849. };
  41850. return SimpleRope;
  41851. }(Mesh));
  41852. /**
  41853. * The SimplePlane allows you to draw a texture across several points and then manipulate these points
  41854. *
  41855. *```js
  41856. * for (let i = 0; i < 20; i++) {
  41857. * points.push(new PIXI.Point(i * 50, 0));
  41858. * };
  41859. * let SimplePlane = new PIXI.SimplePlane(PIXI.Texture.from("snake.png"), points);
  41860. * ```
  41861. *
  41862. * @class
  41863. * @extends PIXI.Mesh
  41864. * @memberof PIXI
  41865. *
  41866. */
  41867. var SimplePlane = /** @class */ (function (_super) {
  41868. __extends$i(SimplePlane, _super);
  41869. /**
  41870. * @param {PIXI.Texture} texture - The texture to use on the SimplePlane.
  41871. * @param {number} verticesX - The number of vertices in the x-axis
  41872. * @param {number} verticesY - The number of vertices in the y-axis
  41873. */
  41874. function SimplePlane(texture, verticesX, verticesY) {
  41875. var _this = this;
  41876. var planeGeometry = new PlaneGeometry(texture.width, texture.height, verticesX, verticesY);
  41877. var meshMaterial = new MeshMaterial(Texture.WHITE);
  41878. _this = _super.call(this, planeGeometry, meshMaterial) || this;
  41879. // lets call the setter to ensure all necessary updates are performed
  41880. _this.texture = texture;
  41881. _this.autoResize = true;
  41882. return _this;
  41883. }
  41884. /**
  41885. * Method used for overrides, to do something in case texture frame was changed.
  41886. * Meshes based on plane can override it and change more details based on texture.
  41887. */
  41888. SimplePlane.prototype.textureUpdated = function () {
  41889. this._textureID = this.shader.texture._updateID;
  41890. var geometry = this.geometry;
  41891. var _a = this.shader.texture, width = _a.width, height = _a.height;
  41892. if (this.autoResize && (geometry.width !== width || geometry.height !== height)) {
  41893. geometry.width = this.shader.texture.width;
  41894. geometry.height = this.shader.texture.height;
  41895. geometry.build();
  41896. }
  41897. };
  41898. Object.defineProperty(SimplePlane.prototype, "texture", {
  41899. get: function () {
  41900. return this.shader.texture;
  41901. },
  41902. set: function (value) {
  41903. // Track texture same way sprite does.
  41904. // For generated meshes like NineSlicePlane it can change the geometry.
  41905. // Unfortunately, this method might not work if you directly change texture in material.
  41906. if (this.shader.texture === value) {
  41907. return;
  41908. }
  41909. this.shader.texture = value;
  41910. this._textureID = -1;
  41911. if (value.baseTexture.valid) {
  41912. this.textureUpdated();
  41913. }
  41914. else {
  41915. value.once('update', this.textureUpdated, this);
  41916. }
  41917. },
  41918. enumerable: false,
  41919. configurable: true
  41920. });
  41921. SimplePlane.prototype._render = function (renderer) {
  41922. if (this._textureID !== this.shader.texture._updateID) {
  41923. this.textureUpdated();
  41924. }
  41925. _super.prototype._render.call(this, renderer);
  41926. };
  41927. SimplePlane.prototype.destroy = function (options) {
  41928. this.shader.texture.off('update', this.textureUpdated, this);
  41929. _super.prototype.destroy.call(this, options);
  41930. };
  41931. return SimplePlane;
  41932. }(Mesh));
  41933. /**
  41934. * The Simple Mesh class mimics Mesh in PixiJS v4, providing easy-to-use constructor arguments.
  41935. * For more robust customization, use {@link PIXI.Mesh}.
  41936. *
  41937. * @class
  41938. * @extends PIXI.Mesh
  41939. * @memberof PIXI
  41940. */
  41941. var SimpleMesh = /** @class */ (function (_super) {
  41942. __extends$i(SimpleMesh, _super);
  41943. /**
  41944. * @param {PIXI.Texture} [texture=Texture.EMPTY] - The texture to use
  41945. * @param {Float32Array} [vertices] - if you want to specify the vertices
  41946. * @param {Float32Array} [uvs] - if you want to specify the uvs
  41947. * @param {Uint16Array} [indices] - if you want to specify the indices
  41948. * @param {number} [drawMode] - the drawMode, can be any of the Mesh.DRAW_MODES consts
  41949. */
  41950. function SimpleMesh(texture, vertices, uvs, indices, drawMode) {
  41951. if (texture === void 0) { texture = Texture.EMPTY; }
  41952. var _this = this;
  41953. var geometry = new MeshGeometry(vertices, uvs, indices);
  41954. geometry.getBuffer('aVertexPosition').static = false;
  41955. var meshMaterial = new MeshMaterial(texture);
  41956. _this = _super.call(this, geometry, meshMaterial, null, drawMode) || this;
  41957. /**
  41958. * upload vertices buffer each frame
  41959. * @member {boolean}
  41960. */
  41961. _this.autoUpdate = true;
  41962. return _this;
  41963. }
  41964. Object.defineProperty(SimpleMesh.prototype, "vertices", {
  41965. /**
  41966. * Collection of vertices data.
  41967. * @member {Float32Array}
  41968. */
  41969. get: function () {
  41970. return this.geometry.getBuffer('aVertexPosition').data;
  41971. },
  41972. set: function (value) {
  41973. this.geometry.getBuffer('aVertexPosition').data = value;
  41974. },
  41975. enumerable: false,
  41976. configurable: true
  41977. });
  41978. SimpleMesh.prototype._render = function (renderer) {
  41979. if (this.autoUpdate) {
  41980. this.geometry.getBuffer('aVertexPosition').update();
  41981. }
  41982. _super.prototype._render.call(this, renderer);
  41983. };
  41984. return SimpleMesh;
  41985. }(Mesh));
  41986. var DEFAULT_BORDER_SIZE = 10;
  41987. /**
  41988. * The NineSlicePlane allows you to stretch a texture using 9-slice scaling. The corners will remain unscaled (useful
  41989. * for buttons with rounded corners for example) and the other areas will be scaled horizontally and or vertically
  41990. *
  41991. *```js
  41992. * let Plane9 = new PIXI.NineSlicePlane(PIXI.Texture.from('BoxWithRoundedCorners.png'), 15, 15, 15, 15);
  41993. * ```
  41994. * <pre>
  41995. * A B
  41996. * +---+----------------------+---+
  41997. * C | 1 | 2 | 3 |
  41998. * +---+----------------------+---+
  41999. * | | | |
  42000. * | 4 | 5 | 6 |
  42001. * | | | |
  42002. * +---+----------------------+---+
  42003. * D | 7 | 8 | 9 |
  42004. * +---+----------------------+---+
  42005. * When changing this objects width and/or height:
  42006. * areas 1 3 7 and 9 will remain unscaled.
  42007. * areas 2 and 8 will be stretched horizontally
  42008. * areas 4 and 6 will be stretched vertically
  42009. * area 5 will be stretched both horizontally and vertically
  42010. * </pre>
  42011. *
  42012. * @class
  42013. * @extends PIXI.SimplePlane
  42014. * @memberof PIXI
  42015. *
  42016. */
  42017. var NineSlicePlane = /** @class */ (function (_super) {
  42018. __extends$i(NineSlicePlane, _super);
  42019. /**
  42020. * @param {PIXI.Texture} texture - The texture to use on the NineSlicePlane.
  42021. * @param {number} [leftWidth=10] - size of the left vertical bar (A)
  42022. * @param {number} [topHeight=10] - size of the top horizontal bar (C)
  42023. * @param {number} [rightWidth=10] - size of the right vertical bar (B)
  42024. * @param {number} [bottomHeight=10] - size of the bottom horizontal bar (D)
  42025. */
  42026. function NineSlicePlane(texture, leftWidth, topHeight, rightWidth, bottomHeight) {
  42027. if (leftWidth === void 0) { leftWidth = DEFAULT_BORDER_SIZE; }
  42028. if (topHeight === void 0) { topHeight = DEFAULT_BORDER_SIZE; }
  42029. if (rightWidth === void 0) { rightWidth = DEFAULT_BORDER_SIZE; }
  42030. if (bottomHeight === void 0) { bottomHeight = DEFAULT_BORDER_SIZE; }
  42031. var _this = _super.call(this, Texture.WHITE, 4, 4) || this;
  42032. _this._origWidth = texture.orig.width;
  42033. _this._origHeight = texture.orig.height;
  42034. /**
  42035. * The width of the NineSlicePlane, setting this will actually modify the vertices and UV's of this plane
  42036. *
  42037. * @member {number}
  42038. * @override
  42039. */
  42040. _this._width = _this._origWidth;
  42041. /**
  42042. * The height of the NineSlicePlane, setting this will actually modify the vertices and UV's of this plane
  42043. *
  42044. * @member {number}
  42045. * @override
  42046. */
  42047. _this._height = _this._origHeight;
  42048. /**
  42049. * The width of the left column (a)
  42050. *
  42051. * @member {number}
  42052. * @private
  42053. */
  42054. _this._leftWidth = leftWidth;
  42055. /**
  42056. * The width of the right column (b)
  42057. *
  42058. * @member {number}
  42059. * @private
  42060. */
  42061. _this._rightWidth = rightWidth;
  42062. /**
  42063. * The height of the top row (c)
  42064. *
  42065. * @member {number}
  42066. * @private
  42067. */
  42068. _this._topHeight = topHeight;
  42069. /**
  42070. * The height of the bottom row (d)
  42071. *
  42072. * @member {number}
  42073. * @private
  42074. */
  42075. _this._bottomHeight = bottomHeight;
  42076. // lets call the setter to ensure all necessary updates are performed
  42077. _this.texture = texture;
  42078. return _this;
  42079. }
  42080. NineSlicePlane.prototype.textureUpdated = function () {
  42081. this._textureID = this.shader.texture._updateID;
  42082. this._refresh();
  42083. };
  42084. Object.defineProperty(NineSlicePlane.prototype, "vertices", {
  42085. get: function () {
  42086. return this.geometry.getBuffer('aVertexPosition').data;
  42087. },
  42088. set: function (value) {
  42089. this.geometry.getBuffer('aVertexPosition').data = value;
  42090. },
  42091. enumerable: false,
  42092. configurable: true
  42093. });
  42094. /**
  42095. * Updates the horizontal vertices.
  42096. *
  42097. */
  42098. NineSlicePlane.prototype.updateHorizontalVertices = function () {
  42099. var vertices = this.vertices;
  42100. var scale = this._getMinScale();
  42101. vertices[9] = vertices[11] = vertices[13] = vertices[15] = this._topHeight * scale;
  42102. vertices[17] = vertices[19] = vertices[21] = vertices[23] = this._height - (this._bottomHeight * scale);
  42103. vertices[25] = vertices[27] = vertices[29] = vertices[31] = this._height;
  42104. };
  42105. /**
  42106. * Updates the vertical vertices.
  42107. *
  42108. */
  42109. NineSlicePlane.prototype.updateVerticalVertices = function () {
  42110. var vertices = this.vertices;
  42111. var scale = this._getMinScale();
  42112. vertices[2] = vertices[10] = vertices[18] = vertices[26] = this._leftWidth * scale;
  42113. vertices[4] = vertices[12] = vertices[20] = vertices[28] = this._width - (this._rightWidth * scale);
  42114. vertices[6] = vertices[14] = vertices[22] = vertices[30] = this._width;
  42115. };
  42116. /**
  42117. * Returns the smaller of a set of vertical and horizontal scale of nine slice corners.
  42118. *
  42119. * @return {number} Smaller number of vertical and horizontal scale.
  42120. * @private
  42121. */
  42122. NineSlicePlane.prototype._getMinScale = function () {
  42123. var w = this._leftWidth + this._rightWidth;
  42124. var scaleW = this._width > w ? 1.0 : this._width / w;
  42125. var h = this._topHeight + this._bottomHeight;
  42126. var scaleH = this._height > h ? 1.0 : this._height / h;
  42127. var scale = Math.min(scaleW, scaleH);
  42128. return scale;
  42129. };
  42130. Object.defineProperty(NineSlicePlane.prototype, "width", {
  42131. /**
  42132. * The width of the NineSlicePlane, setting this will actually modify the vertices and UV's of this plane
  42133. *
  42134. * @member {number}
  42135. */
  42136. get: function () {
  42137. return this._width;
  42138. },
  42139. set: function (value) {
  42140. this._width = value;
  42141. this._refresh();
  42142. },
  42143. enumerable: false,
  42144. configurable: true
  42145. });
  42146. Object.defineProperty(NineSlicePlane.prototype, "height", {
  42147. /**
  42148. * The height of the NineSlicePlane, setting this will actually modify the vertices and UV's of this plane
  42149. *
  42150. * @member {number}
  42151. */
  42152. get: function () {
  42153. return this._height;
  42154. },
  42155. set: function (value) {
  42156. this._height = value;
  42157. this._refresh();
  42158. },
  42159. enumerable: false,
  42160. configurable: true
  42161. });
  42162. Object.defineProperty(NineSlicePlane.prototype, "leftWidth", {
  42163. /**
  42164. * The width of the left column
  42165. *
  42166. * @member {number}
  42167. */
  42168. get: function () {
  42169. return this._leftWidth;
  42170. },
  42171. set: function (value) {
  42172. this._leftWidth = value;
  42173. this._refresh();
  42174. },
  42175. enumerable: false,
  42176. configurable: true
  42177. });
  42178. Object.defineProperty(NineSlicePlane.prototype, "rightWidth", {
  42179. /**
  42180. * The width of the right column
  42181. *
  42182. * @member {number}
  42183. */
  42184. get: function () {
  42185. return this._rightWidth;
  42186. },
  42187. set: function (value) {
  42188. this._rightWidth = value;
  42189. this._refresh();
  42190. },
  42191. enumerable: false,
  42192. configurable: true
  42193. });
  42194. Object.defineProperty(NineSlicePlane.prototype, "topHeight", {
  42195. /**
  42196. * The height of the top row
  42197. *
  42198. * @member {number}
  42199. */
  42200. get: function () {
  42201. return this._topHeight;
  42202. },
  42203. set: function (value) {
  42204. this._topHeight = value;
  42205. this._refresh();
  42206. },
  42207. enumerable: false,
  42208. configurable: true
  42209. });
  42210. Object.defineProperty(NineSlicePlane.prototype, "bottomHeight", {
  42211. /**
  42212. * The height of the bottom row
  42213. *
  42214. * @member {number}
  42215. */
  42216. get: function () {
  42217. return this._bottomHeight;
  42218. },
  42219. set: function (value) {
  42220. this._bottomHeight = value;
  42221. this._refresh();
  42222. },
  42223. enumerable: false,
  42224. configurable: true
  42225. });
  42226. /**
  42227. * Refreshes NineSlicePlane coords. All of them.
  42228. */
  42229. NineSlicePlane.prototype._refresh = function () {
  42230. var texture = this.texture;
  42231. var uvs = this.geometry.buffers[1].data;
  42232. this._origWidth = texture.orig.width;
  42233. this._origHeight = texture.orig.height;
  42234. var _uvw = 1.0 / this._origWidth;
  42235. var _uvh = 1.0 / this._origHeight;
  42236. uvs[0] = uvs[8] = uvs[16] = uvs[24] = 0;
  42237. uvs[1] = uvs[3] = uvs[5] = uvs[7] = 0;
  42238. uvs[6] = uvs[14] = uvs[22] = uvs[30] = 1;
  42239. uvs[25] = uvs[27] = uvs[29] = uvs[31] = 1;
  42240. uvs[2] = uvs[10] = uvs[18] = uvs[26] = _uvw * this._leftWidth;
  42241. uvs[4] = uvs[12] = uvs[20] = uvs[28] = 1 - (_uvw * this._rightWidth);
  42242. uvs[9] = uvs[11] = uvs[13] = uvs[15] = _uvh * this._topHeight;
  42243. uvs[17] = uvs[19] = uvs[21] = uvs[23] = 1 - (_uvh * this._bottomHeight);
  42244. this.updateHorizontalVertices();
  42245. this.updateVerticalVertices();
  42246. this.geometry.buffers[0].update();
  42247. this.geometry.buffers[1].update();
  42248. };
  42249. return NineSlicePlane;
  42250. }(SimplePlane));
  42251. /*!
  42252. * @pixi/sprite-animated - v6.1.2
  42253. * Compiled Thu, 12 Aug 2021 17:11:19 UTC
  42254. *
  42255. * @pixi/sprite-animated is licensed under the MIT License.
  42256. * http://www.opensource.org/licenses/mit-license
  42257. */
  42258. /*! *****************************************************************************
  42259. Copyright (c) Microsoft Corporation. All rights reserved.
  42260. Licensed under the Apache License, Version 2.0 (the "License"); you may not use
  42261. this file except in compliance with the License. You may obtain a copy of the
  42262. License at http://www.apache.org/licenses/LICENSE-2.0
  42263. THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  42264. KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
  42265. WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
  42266. MERCHANTABLITY OR NON-INFRINGEMENT.
  42267. See the Apache Version 2.0 License for specific language governing permissions
  42268. and limitations under the License.
  42269. ***************************************************************************** */
  42270. /* global Reflect, Promise */
  42271. var extendStatics$j = function(d, b) {
  42272. extendStatics$j = Object.setPrototypeOf ||
  42273. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  42274. function (d, b) { for (var p in b) { if (b.hasOwnProperty(p)) { d[p] = b[p]; } } };
  42275. return extendStatics$j(d, b);
  42276. };
  42277. function __extends$j(d, b) {
  42278. extendStatics$j(d, b);
  42279. function __() { this.constructor = d; }
  42280. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  42281. }
  42282. /**
  42283. * An AnimatedSprite is a simple way to display an animation depicted by a list of textures.
  42284. *
  42285. * ```js
  42286. * let alienImages = ["image_sequence_01.png","image_sequence_02.png","image_sequence_03.png","image_sequence_04.png"];
  42287. * let textureArray = [];
  42288. *
  42289. * for (let i=0; i < 4; i++)
  42290. * {
  42291. * let texture = PIXI.Texture.from(alienImages[i]);
  42292. * textureArray.push(texture);
  42293. * };
  42294. *
  42295. * let animatedSprite = new PIXI.AnimatedSprite(textureArray);
  42296. * ```
  42297. *
  42298. * The more efficient and simpler way to create an animated sprite is using a {@link PIXI.Spritesheet}
  42299. * containing the animation definitions:
  42300. *
  42301. * ```js
  42302. * PIXI.Loader.shared.add("assets/spritesheet.json").load(setup);
  42303. *
  42304. * function setup() {
  42305. * let sheet = PIXI.Loader.shared.resources["assets/spritesheet.json"].spritesheet;
  42306. * animatedSprite = new PIXI.AnimatedSprite(sheet.animations["image_sequence"]);
  42307. * ...
  42308. * }
  42309. * ```
  42310. *
  42311. * @class
  42312. * @extends PIXI.Sprite
  42313. * @memberof PIXI
  42314. */
  42315. var AnimatedSprite = /** @class */ (function (_super) {
  42316. __extends$j(AnimatedSprite, _super);
  42317. /**
  42318. * @param {PIXI.Texture[]|PIXI.AnimatedSprite.FrameObject[]} textures - An array of {@link PIXI.Texture} or frame
  42319. * objects that make up the animation.
  42320. * @param {boolean} [autoUpdate=true] - Whether to use PIXI.Ticker.shared to auto update animation time.
  42321. */
  42322. function AnimatedSprite(textures, autoUpdate) {
  42323. if (autoUpdate === void 0) { autoUpdate = true; }
  42324. var _this = _super.call(this, textures[0] instanceof Texture ? textures[0] : textures[0].texture) || this;
  42325. /**
  42326. * @type {PIXI.Texture[]}
  42327. * @private
  42328. */
  42329. _this._textures = null;
  42330. /**
  42331. * @type {number[]}
  42332. * @private
  42333. */
  42334. _this._durations = null;
  42335. /**
  42336. * `true` uses PIXI.Ticker.shared to auto update animation time.
  42337. *
  42338. * @type {boolean}
  42339. * @default true
  42340. * @private
  42341. */
  42342. _this._autoUpdate = autoUpdate;
  42343. /**
  42344. * `true` if the instance is currently connected to PIXI.Ticker.shared to auto update animation time.
  42345. *
  42346. * @type {boolean}
  42347. * @default false
  42348. * @private
  42349. */
  42350. _this._isConnectedToTicker = false;
  42351. /**
  42352. * The speed that the AnimatedSprite will play at. Higher is faster, lower is slower.
  42353. *
  42354. * @member {number}
  42355. * @default 1
  42356. */
  42357. _this.animationSpeed = 1;
  42358. /**
  42359. * Whether or not the animate sprite repeats after playing.
  42360. *
  42361. * @member {boolean}
  42362. * @default true
  42363. */
  42364. _this.loop = true;
  42365. /**
  42366. * Update anchor to [Texture's defaultAnchor]{@link PIXI.Texture#defaultAnchor} when frame changes.
  42367. *
  42368. * Useful with [sprite sheet animations]{@link PIXI.Spritesheet#animations} created with tools.
  42369. * Changing anchor for each frame allows to pin sprite origin to certain moving feature
  42370. * of the frame (e.g. left foot).
  42371. *
  42372. * Note: Enabling this will override any previously set `anchor` on each frame change.
  42373. *
  42374. * @member {boolean}
  42375. * @default false
  42376. */
  42377. _this.updateAnchor = false;
  42378. /**
  42379. * User-assigned function to call when an AnimatedSprite finishes playing.
  42380. *
  42381. * @example
  42382. * animation.onComplete = function () {
  42383. * // finished!
  42384. * };
  42385. * @member {Function}
  42386. */
  42387. _this.onComplete = null;
  42388. /**
  42389. * User-assigned function to call when an AnimatedSprite changes which texture is being rendered.
  42390. *
  42391. * @example
  42392. * animation.onFrameChange = function () {
  42393. * // updated!
  42394. * };
  42395. * @member {Function}
  42396. */
  42397. _this.onFrameChange = null;
  42398. /**
  42399. * User-assigned function to call when `loop` is true, and an AnimatedSprite is played and
  42400. * loops around to start again.
  42401. *
  42402. * @example
  42403. * animation.onLoop = function () {
  42404. * // looped!
  42405. * };
  42406. * @member {Function}
  42407. */
  42408. _this.onLoop = null;
  42409. /**
  42410. * Elapsed time since animation has been started, used internally to display current texture.
  42411. *
  42412. * @member {number}
  42413. * @private
  42414. */
  42415. _this._currentTime = 0;
  42416. _this._playing = false;
  42417. /**
  42418. * The texture index that was displayed last time
  42419. *
  42420. * @member {number}
  42421. * @private
  42422. */
  42423. _this._previousFrame = null;
  42424. _this.textures = textures;
  42425. return _this;
  42426. }
  42427. /**
  42428. * Stops the AnimatedSprite.
  42429. *
  42430. */
  42431. AnimatedSprite.prototype.stop = function () {
  42432. if (!this._playing) {
  42433. return;
  42434. }
  42435. this._playing = false;
  42436. if (this._autoUpdate && this._isConnectedToTicker) {
  42437. Ticker.shared.remove(this.update, this);
  42438. this._isConnectedToTicker = false;
  42439. }
  42440. };
  42441. /**
  42442. * Plays the AnimatedSprite.
  42443. *
  42444. */
  42445. AnimatedSprite.prototype.play = function () {
  42446. if (this._playing) {
  42447. return;
  42448. }
  42449. this._playing = true;
  42450. if (this._autoUpdate && !this._isConnectedToTicker) {
  42451. Ticker.shared.add(this.update, this, exports.UPDATE_PRIORITY.HIGH);
  42452. this._isConnectedToTicker = true;
  42453. }
  42454. };
  42455. /**
  42456. * Stops the AnimatedSprite and goes to a specific frame.
  42457. *
  42458. * @param {number} frameNumber - Frame index to stop at.
  42459. */
  42460. AnimatedSprite.prototype.gotoAndStop = function (frameNumber) {
  42461. this.stop();
  42462. var previousFrame = this.currentFrame;
  42463. this._currentTime = frameNumber;
  42464. if (previousFrame !== this.currentFrame) {
  42465. this.updateTexture();
  42466. }
  42467. };
  42468. /**
  42469. * Goes to a specific frame and begins playing the AnimatedSprite.
  42470. *
  42471. * @param {number} frameNumber - Frame index to start at.
  42472. */
  42473. AnimatedSprite.prototype.gotoAndPlay = function (frameNumber) {
  42474. var previousFrame = this.currentFrame;
  42475. this._currentTime = frameNumber;
  42476. if (previousFrame !== this.currentFrame) {
  42477. this.updateTexture();
  42478. }
  42479. this.play();
  42480. };
  42481. /**
  42482. * Updates the object transform for rendering.
  42483. *
  42484. * @param {number} deltaTime - Time since last tick.
  42485. */
  42486. AnimatedSprite.prototype.update = function (deltaTime) {
  42487. if (!this._playing) {
  42488. return;
  42489. }
  42490. var elapsed = this.animationSpeed * deltaTime;
  42491. var previousFrame = this.currentFrame;
  42492. if (this._durations !== null) {
  42493. var lag = this._currentTime % 1 * this._durations[this.currentFrame];
  42494. lag += elapsed / 60 * 1000;
  42495. while (lag < 0) {
  42496. this._currentTime--;
  42497. lag += this._durations[this.currentFrame];
  42498. }
  42499. var sign = Math.sign(this.animationSpeed * deltaTime);
  42500. this._currentTime = Math.floor(this._currentTime);
  42501. while (lag >= this._durations[this.currentFrame]) {
  42502. lag -= this._durations[this.currentFrame] * sign;
  42503. this._currentTime += sign;
  42504. }
  42505. this._currentTime += lag / this._durations[this.currentFrame];
  42506. }
  42507. else {
  42508. this._currentTime += elapsed;
  42509. }
  42510. if (this._currentTime < 0 && !this.loop) {
  42511. this.gotoAndStop(0);
  42512. if (this.onComplete) {
  42513. this.onComplete();
  42514. }
  42515. }
  42516. else if (this._currentTime >= this._textures.length && !this.loop) {
  42517. this.gotoAndStop(this._textures.length - 1);
  42518. if (this.onComplete) {
  42519. this.onComplete();
  42520. }
  42521. }
  42522. else if (previousFrame !== this.currentFrame) {
  42523. if (this.loop && this.onLoop) {
  42524. if (this.animationSpeed > 0 && this.currentFrame < previousFrame) {
  42525. this.onLoop();
  42526. }
  42527. else if (this.animationSpeed < 0 && this.currentFrame > previousFrame) {
  42528. this.onLoop();
  42529. }
  42530. }
  42531. this.updateTexture();
  42532. }
  42533. };
  42534. /**
  42535. * Updates the displayed texture to match the current frame index.
  42536. *
  42537. * @private
  42538. */
  42539. AnimatedSprite.prototype.updateTexture = function () {
  42540. var currentFrame = this.currentFrame;
  42541. if (this._previousFrame === currentFrame) {
  42542. return;
  42543. }
  42544. this._previousFrame = currentFrame;
  42545. this._texture = this._textures[currentFrame];
  42546. this._textureID = -1;
  42547. this._textureTrimmedID = -1;
  42548. this._cachedTint = 0xFFFFFF;
  42549. this.uvs = this._texture._uvs.uvsFloat32;
  42550. if (this.updateAnchor) {
  42551. this._anchor.copyFrom(this._texture.defaultAnchor);
  42552. }
  42553. if (this.onFrameChange) {
  42554. this.onFrameChange(this.currentFrame);
  42555. }
  42556. };
  42557. /**
  42558. * Stops the AnimatedSprite and destroys it.
  42559. *
  42560. * @param {object|boolean} [options] - Options parameter. A boolean will act as if all options
  42561. * have been set to that value.
  42562. * @param {boolean} [options.children=false] - If set to true, all the children will have their destroy
  42563. * method called as well. 'options' will be passed on to those calls.
  42564. * @param {boolean} [options.texture=false] - Should it destroy the current texture of the sprite as well.
  42565. * @param {boolean} [options.baseTexture=false] - Should it destroy the base texture of the sprite as well.
  42566. */
  42567. AnimatedSprite.prototype.destroy = function (options) {
  42568. this.stop();
  42569. _super.prototype.destroy.call(this, options);
  42570. this.onComplete = null;
  42571. this.onFrameChange = null;
  42572. this.onLoop = null;
  42573. };
  42574. /**
  42575. * A short hand way of creating an AnimatedSprite from an array of frame ids.
  42576. *
  42577. * @static
  42578. * @param {string[]} frames - The array of frames ids the AnimatedSprite will use as its texture frames.
  42579. * @return {PIXI.AnimatedSprite} The new animated sprite with the specified frames.
  42580. */
  42581. AnimatedSprite.fromFrames = function (frames) {
  42582. var textures = [];
  42583. for (var i = 0; i < frames.length; ++i) {
  42584. textures.push(Texture.from(frames[i]));
  42585. }
  42586. return new AnimatedSprite(textures);
  42587. };
  42588. /**
  42589. * A short hand way of creating an AnimatedSprite from an array of image ids.
  42590. *
  42591. * @static
  42592. * @param {string[]} images - The array of image urls the AnimatedSprite will use as its texture frames.
  42593. * @return {PIXI.AnimatedSprite} The new animate sprite with the specified images as frames.
  42594. */
  42595. AnimatedSprite.fromImages = function (images) {
  42596. var textures = [];
  42597. for (var i = 0; i < images.length; ++i) {
  42598. textures.push(Texture.from(images[i]));
  42599. }
  42600. return new AnimatedSprite(textures);
  42601. };
  42602. Object.defineProperty(AnimatedSprite.prototype, "totalFrames", {
  42603. /**
  42604. * The total number of frames in the AnimatedSprite. This is the same as number of textures
  42605. * assigned to the AnimatedSprite.
  42606. *
  42607. * @readonly
  42608. * @member {number}
  42609. * @default 0
  42610. */
  42611. get: function () {
  42612. return this._textures.length;
  42613. },
  42614. enumerable: false,
  42615. configurable: true
  42616. });
  42617. Object.defineProperty(AnimatedSprite.prototype, "textures", {
  42618. /**
  42619. * The array of textures used for this AnimatedSprite.
  42620. *
  42621. * @member {PIXI.Texture[]}
  42622. */
  42623. get: function () {
  42624. return this._textures;
  42625. },
  42626. set: function (value) {
  42627. if (value[0] instanceof Texture) {
  42628. this._textures = value;
  42629. this._durations = null;
  42630. }
  42631. else {
  42632. this._textures = [];
  42633. this._durations = [];
  42634. for (var i = 0; i < value.length; i++) {
  42635. this._textures.push(value[i].texture);
  42636. this._durations.push(value[i].time);
  42637. }
  42638. }
  42639. this._previousFrame = null;
  42640. this.gotoAndStop(0);
  42641. this.updateTexture();
  42642. },
  42643. enumerable: false,
  42644. configurable: true
  42645. });
  42646. Object.defineProperty(AnimatedSprite.prototype, "currentFrame", {
  42647. /**
  42648. * The AnimatedSprites current frame index.
  42649. *
  42650. * @member {number}
  42651. * @readonly
  42652. */
  42653. get: function () {
  42654. var currentFrame = Math.floor(this._currentTime) % this._textures.length;
  42655. if (currentFrame < 0) {
  42656. currentFrame += this._textures.length;
  42657. }
  42658. return currentFrame;
  42659. },
  42660. enumerable: false,
  42661. configurable: true
  42662. });
  42663. Object.defineProperty(AnimatedSprite.prototype, "playing", {
  42664. /**
  42665. * Indicates if the AnimatedSprite is currently playing.
  42666. *
  42667. * @member {boolean}
  42668. * @readonly
  42669. */
  42670. get: function () {
  42671. return this._playing;
  42672. },
  42673. enumerable: false,
  42674. configurable: true
  42675. });
  42676. Object.defineProperty(AnimatedSprite.prototype, "autoUpdate", {
  42677. /**
  42678. * Whether to use PIXI.Ticker.shared to auto update animation time
  42679. *
  42680. * @member {boolean}
  42681. */
  42682. get: function () {
  42683. return this._autoUpdate;
  42684. },
  42685. set: function (value) {
  42686. if (value !== this._autoUpdate) {
  42687. this._autoUpdate = value;
  42688. if (!this._autoUpdate && this._isConnectedToTicker) {
  42689. Ticker.shared.remove(this.update, this);
  42690. this._isConnectedToTicker = false;
  42691. }
  42692. else if (this._autoUpdate && !this._isConnectedToTicker && this._playing) {
  42693. Ticker.shared.add(this.update, this);
  42694. this._isConnectedToTicker = true;
  42695. }
  42696. }
  42697. },
  42698. enumerable: false,
  42699. configurable: true
  42700. });
  42701. return AnimatedSprite;
  42702. }(Sprite));
  42703. // Install renderer plugins
  42704. Renderer.registerPlugin('accessibility', AccessibilityManager);
  42705. Renderer.registerPlugin('extract', Extract);
  42706. Renderer.registerPlugin('interaction', InteractionManager);
  42707. Renderer.registerPlugin('particle', ParticleRenderer);
  42708. Renderer.registerPlugin('prepare', Prepare);
  42709. Renderer.registerPlugin('batch', BatchRenderer);
  42710. Renderer.registerPlugin('tilingSprite', TilingSpriteRenderer);
  42711. // Install loader plugins
  42712. Loader.registerPlugin(BitmapFontLoader);
  42713. Loader.registerPlugin(CompressedTextureLoader);
  42714. Loader.registerPlugin(DDSLoader);
  42715. Loader.registerPlugin(KTXLoader);
  42716. Loader.registerPlugin(SpritesheetLoader);
  42717. // Install application plugins
  42718. Application.registerPlugin(TickerPlugin);
  42719. Application.registerPlugin(AppLoaderPlugin);
  42720. /**
  42721. * String of the current PIXI version.
  42722. *
  42723. * @static
  42724. * @constant
  42725. * @memberof PIXI
  42726. * @name VERSION
  42727. * @type {string}
  42728. */
  42729. var VERSION$1 = '6.1.2';
  42730. /**
  42731. * @namespace PIXI
  42732. */
  42733. /**
  42734. * This namespace contains WebGL-only display filters that can be applied
  42735. * to DisplayObjects using the {@link PIXI.DisplayObject#filters filters} property.
  42736. *
  42737. * Since PixiJS only had a handful of built-in filters, additional filters
  42738. * can be downloaded {@link https://github.com/pixijs/pixi-filters here} from the
  42739. * PixiJS Filters repository.
  42740. *
  42741. * All filters must extend {@link PIXI.Filter}.
  42742. *
  42743. * @example
  42744. * // Create a new application
  42745. * const app = new PIXI.Application();
  42746. *
  42747. * // Draw a green rectangle
  42748. * const rect = new PIXI.Graphics()
  42749. * .beginFill(0x00ff00)
  42750. * .drawRect(40, 40, 200, 200);
  42751. *
  42752. * // Add a blur filter
  42753. * rect.filters = [new PIXI.filters.BlurFilter()];
  42754. *
  42755. * // Display rectangle
  42756. * app.stage.addChild(rect);
  42757. * document.body.appendChild(app.view);
  42758. * @namespace PIXI.filters
  42759. */
  42760. var filters = {
  42761. AlphaFilter: AlphaFilter,
  42762. BlurFilter: BlurFilter,
  42763. BlurFilterPass: BlurFilterPass,
  42764. ColorMatrixFilter: ColorMatrixFilter,
  42765. DisplacementFilter: DisplacementFilter,
  42766. FXAAFilter: FXAAFilter,
  42767. NoiseFilter: NoiseFilter,
  42768. };
  42769. exports.AbstractBatchRenderer = AbstractBatchRenderer;
  42770. exports.AbstractMultiResource = AbstractMultiResource;
  42771. exports.AbstractRenderer = AbstractRenderer;
  42772. exports.AccessibilityManager = AccessibilityManager;
  42773. exports.AnimatedSprite = AnimatedSprite;
  42774. exports.AppLoaderPlugin = AppLoaderPlugin;
  42775. exports.Application = Application;
  42776. exports.ArrayResource = ArrayResource;
  42777. exports.Attribute = Attribute;
  42778. exports.BaseImageResource = BaseImageResource;
  42779. exports.BasePrepare = BasePrepare;
  42780. exports.BaseRenderTexture = BaseRenderTexture;
  42781. exports.BaseTexture = BaseTexture;
  42782. exports.BatchDrawCall = BatchDrawCall;
  42783. exports.BatchGeometry = BatchGeometry;
  42784. exports.BatchPluginFactory = BatchPluginFactory;
  42785. exports.BatchRenderer = BatchRenderer;
  42786. exports.BatchShaderGenerator = BatchShaderGenerator;
  42787. exports.BatchSystem = BatchSystem;
  42788. exports.BatchTextureArray = BatchTextureArray;
  42789. exports.BitmapFont = BitmapFont;
  42790. exports.BitmapFontData = BitmapFontData;
  42791. exports.BitmapFontLoader = BitmapFontLoader;
  42792. exports.BitmapText = BitmapText;
  42793. exports.BlobResource = BlobResource;
  42794. exports.Bounds = Bounds;
  42795. exports.Buffer = Buffer;
  42796. exports.BufferResource = BufferResource;
  42797. exports.CanvasResource = CanvasResource;
  42798. exports.Circle = Circle;
  42799. exports.CompressedTextureLoader = CompressedTextureLoader;
  42800. exports.CompressedTextureResource = CompressedTextureResource;
  42801. exports.Container = Container;
  42802. exports.ContextSystem = ContextSystem;
  42803. exports.CountLimiter = CountLimiter;
  42804. exports.CubeResource = CubeResource;
  42805. exports.DDSLoader = DDSLoader;
  42806. exports.DEG_TO_RAD = DEG_TO_RAD;
  42807. exports.DisplayObject = DisplayObject;
  42808. exports.Ellipse = Ellipse;
  42809. exports.Extract = Extract;
  42810. exports.FORMATS_TO_COMPONENTS = FORMATS_TO_COMPONENTS;
  42811. exports.FillStyle = FillStyle;
  42812. exports.Filter = Filter;
  42813. exports.FilterState = FilterState;
  42814. exports.FilterSystem = FilterSystem;
  42815. exports.Framebuffer = Framebuffer;
  42816. exports.FramebufferSystem = FramebufferSystem;
  42817. exports.GLFramebuffer = GLFramebuffer;
  42818. exports.GLProgram = GLProgram;
  42819. exports.GLTexture = GLTexture;
  42820. exports.GRAPHICS_CURVES = GRAPHICS_CURVES;
  42821. exports.Geometry = Geometry;
  42822. exports.GeometrySystem = GeometrySystem;
  42823. exports.Graphics = Graphics;
  42824. exports.GraphicsData = GraphicsData;
  42825. exports.GraphicsGeometry = GraphicsGeometry;
  42826. exports.IGLUniformData = IGLUniformData;
  42827. exports.INSTALLED = INSTALLED;
  42828. exports.INTERNAL_FORMAT_TO_BYTES_PER_PIXEL = INTERNAL_FORMAT_TO_BYTES_PER_PIXEL;
  42829. exports.ImageBitmapResource = ImageBitmapResource;
  42830. exports.ImageResource = ImageResource;
  42831. exports.InteractionData = InteractionData;
  42832. exports.InteractionEvent = InteractionEvent;
  42833. exports.InteractionManager = InteractionManager;
  42834. exports.InteractionTrackingData = InteractionTrackingData;
  42835. exports.KTXLoader = KTXLoader;
  42836. exports.LineStyle = LineStyle;
  42837. exports.Loader = Loader;
  42838. exports.MaskData = MaskData;
  42839. exports.MaskSystem = MaskSystem;
  42840. exports.Matrix = Matrix;
  42841. exports.Mesh = Mesh;
  42842. exports.MeshBatchUvs = MeshBatchUvs;
  42843. exports.MeshGeometry = MeshGeometry;
  42844. exports.MeshMaterial = MeshMaterial;
  42845. exports.NineSlicePlane = NineSlicePlane;
  42846. exports.ObjectRenderer = ObjectRenderer;
  42847. exports.ObservablePoint = ObservablePoint;
  42848. exports.PI_2 = PI_2;
  42849. exports.ParticleContainer = ParticleContainer;
  42850. exports.ParticleRenderer = ParticleRenderer;
  42851. exports.PlaneGeometry = PlaneGeometry;
  42852. exports.Point = Point;
  42853. exports.Polygon = Polygon;
  42854. exports.Prepare = Prepare;
  42855. exports.Program = Program;
  42856. exports.ProjectionSystem = ProjectionSystem;
  42857. exports.Quad = Quad;
  42858. exports.QuadUv = QuadUv;
  42859. exports.RAD_TO_DEG = RAD_TO_DEG;
  42860. exports.Rectangle = Rectangle;
  42861. exports.RenderTexture = RenderTexture;
  42862. exports.RenderTexturePool = RenderTexturePool;
  42863. exports.RenderTextureSystem = RenderTextureSystem;
  42864. exports.Renderer = Renderer;
  42865. exports.Resource = Resource;
  42866. exports.RopeGeometry = RopeGeometry;
  42867. exports.RoundedRectangle = RoundedRectangle;
  42868. exports.Runner = Runner;
  42869. exports.SVGResource = SVGResource;
  42870. exports.ScissorSystem = ScissorSystem;
  42871. exports.Shader = Shader;
  42872. exports.ShaderSystem = ShaderSystem;
  42873. exports.SimpleMesh = SimpleMesh;
  42874. exports.SimplePlane = SimplePlane;
  42875. exports.SimpleRope = SimpleRope;
  42876. exports.Sprite = Sprite;
  42877. exports.SpriteMaskFilter = SpriteMaskFilter;
  42878. exports.Spritesheet = Spritesheet;
  42879. exports.SpritesheetLoader = SpritesheetLoader;
  42880. exports.State = State;
  42881. exports.StateSystem = StateSystem;
  42882. exports.StencilSystem = StencilSystem;
  42883. exports.System = System;
  42884. exports.TYPES_TO_BYTES_PER_COMPONENT = TYPES_TO_BYTES_PER_COMPONENT;
  42885. exports.TYPES_TO_BYTES_PER_PIXEL = TYPES_TO_BYTES_PER_PIXEL;
  42886. exports.TemporaryDisplayObject = TemporaryDisplayObject;
  42887. exports.Text = Text;
  42888. exports.TextMetrics = TextMetrics;
  42889. exports.TextStyle = TextStyle;
  42890. exports.Texture = Texture;
  42891. exports.TextureGCSystem = TextureGCSystem;
  42892. exports.TextureLoader = TextureLoader;
  42893. exports.TextureMatrix = TextureMatrix;
  42894. exports.TextureSystem = TextureSystem;
  42895. exports.TextureUvs = TextureUvs;
  42896. exports.Ticker = Ticker;
  42897. exports.TickerPlugin = TickerPlugin;
  42898. exports.TilingSprite = TilingSprite;
  42899. exports.TilingSpriteRenderer = TilingSpriteRenderer;
  42900. exports.TimeLimiter = TimeLimiter;
  42901. exports.Transform = Transform;
  42902. exports.UniformGroup = UniformGroup;
  42903. exports.VERSION = VERSION$1;
  42904. exports.VideoResource = VideoResource;
  42905. exports.ViewableBuffer = ViewableBuffer;
  42906. exports.accessibleTarget = accessibleTarget;
  42907. exports.autoDetectRenderer = autoDetectRenderer;
  42908. exports.autoDetectResource = autoDetectResource;
  42909. exports.checkMaxIfStatementsInShader = checkMaxIfStatementsInShader;
  42910. exports.createUBOElements = createUBOElements;
  42911. exports.defaultFilterVertex = defaultFilterVertex;
  42912. exports.defaultVertex = defaultVertex$2;
  42913. exports.filters = filters;
  42914. exports.generateProgram = generateProgram;
  42915. exports.generateUniformBufferSync = generateUniformBufferSync;
  42916. exports.getTestContext = getTestContext;
  42917. exports.getUBOData = getUBOData;
  42918. exports.graphicsUtils = graphicsUtils;
  42919. exports.groupD8 = groupD8;
  42920. exports.interactiveTarget = interactiveTarget;
  42921. exports.isMobile = isMobile$1;
  42922. exports.resources = resources;
  42923. exports.settings = settings;
  42924. exports.systems = systems;
  42925. exports.uniformParsers = uniformParsers;
  42926. exports.utils = utils;
  42927. return exports;
  42928. }({}));
  42929. //# sourceMappingURL=pixi.js.map