pixi.js 1.6 MB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901259022590325904259052590625907259082590925910259112591225913259142591525916259172591825919259202592125922259232592425925259262592725928259292593025931259322593325934259352593625937259382593925940259412594225943259442594525946259472594825949259502595125952259532595425955259562595725958259592596025961259622596325964259652596625967259682596925970259712597225973259742597525976259772597825979259802598125982259832598425985259862598725988259892599025991259922599325994259952599625997259982599926000260012600226003260042600526006260072600826009260102601126012260132601426015260162601726018260192602026021260222602326024260252602626027260282602926030260312603226033260342603526036260372603826039260402604126042260432604426045260462604726048260492605026051260522605326054260552605626057260582605926060260612606226063260642606526066260672606826069260702607126072260732607426075260762607726078260792608026081260822608326084260852608626087260882608926090260912609226093260942609526096260972609826099261002610126102261032610426105261062610726108261092611026111261122611326114261152611626117261182611926120261212612226123261242612526126261272612826129261302613126132261332613426135261362613726138261392614026141261422614326144261452614626147261482614926150261512615226153261542615526156261572615826159261602616126162261632616426165261662616726168261692617026171261722617326174261752617626177261782617926180261812618226183261842618526186261872618826189261902619126192261932619426195261962619726198261992620026201262022620326204262052620626207262082620926210262112621226213262142621526216262172621826219262202622126222262232622426225262262622726228262292623026231262322623326234262352623626237262382623926240262412624226243262442624526246262472624826249262502625126252262532625426255262562625726258262592626026261262622626326264262652626626267262682626926270262712627226273262742627526276262772627826279262802628126282262832628426285262862628726288262892629026291262922629326294262952629626297262982629926300263012630226303263042630526306263072630826309263102631126312263132631426315263162631726318263192632026321263222632326324263252632626327263282632926330263312633226333263342633526336263372633826339263402634126342263432634426345263462634726348263492635026351263522635326354263552635626357263582635926360263612636226363263642636526366263672636826369263702637126372263732637426375263762637726378263792638026381263822638326384263852638626387263882638926390263912639226393263942639526396263972639826399264002640126402264032640426405264062640726408264092641026411264122641326414264152641626417264182641926420264212642226423264242642526426264272642826429264302643126432264332643426435264362643726438264392644026441264422644326444264452644626447264482644926450264512645226453264542645526456264572645826459264602646126462264632646426465264662646726468264692647026471264722647326474264752647626477264782647926480264812648226483264842648526486264872648826489264902649126492264932649426495264962649726498264992650026501265022650326504265052650626507265082650926510265112651226513265142651526516265172651826519265202652126522265232652426525265262652726528265292653026531265322653326534265352653626537265382653926540265412654226543265442654526546265472654826549265502655126552265532655426555265562655726558265592656026561265622656326564265652656626567265682656926570265712657226573265742657526576265772657826579265802658126582265832658426585265862658726588265892659026591265922659326594265952659626597265982659926600266012660226603266042660526606266072660826609266102661126612266132661426615266162661726618266192662026621266222662326624266252662626627266282662926630266312663226633266342663526636266372663826639266402664126642266432664426645266462664726648266492665026651266522665326654266552665626657266582665926660266612666226663266642666526666266672666826669266702667126672266732667426675266762667726678266792668026681266822668326684266852668626687266882668926690266912669226693266942669526696266972669826699267002670126702267032670426705267062670726708267092671026711267122671326714267152671626717267182671926720267212672226723267242672526726267272672826729267302673126732267332673426735267362673726738267392674026741267422674326744267452674626747267482674926750267512675226753267542675526756267572675826759267602676126762267632676426765267662676726768267692677026771267722677326774267752677626777267782677926780267812678226783267842678526786267872678826789267902679126792267932679426795267962679726798267992680026801268022680326804268052680626807268082680926810268112681226813268142681526816268172681826819268202682126822268232682426825268262682726828268292683026831268322683326834268352683626837268382683926840268412684226843268442684526846268472684826849268502685126852268532685426855268562685726858268592686026861268622686326864268652686626867268682686926870268712687226873268742687526876268772687826879268802688126882268832688426885268862688726888268892689026891268922689326894268952689626897268982689926900269012690226903269042690526906269072690826909269102691126912269132691426915269162691726918269192692026921269222692326924269252692626927269282692926930269312693226933269342693526936269372693826939269402694126942269432694426945269462694726948269492695026951269522695326954269552695626957269582695926960269612696226963269642696526966269672696826969269702697126972269732697426975269762697726978269792698026981269822698326984269852698626987269882698926990269912699226993269942699526996269972699826999270002700127002270032700427005270062700727008270092701027011270122701327014270152701627017270182701927020270212702227023270242702527026270272702827029270302703127032270332703427035270362703727038270392704027041270422704327044270452704627047270482704927050270512705227053270542705527056270572705827059270602706127062270632706427065270662706727068270692707027071270722707327074270752707627077270782707927080270812708227083270842708527086270872708827089270902709127092270932709427095270962709727098270992710027101271022710327104271052710627107271082710927110271112711227113271142711527116271172711827119271202712127122271232712427125271262712727128271292713027131271322713327134271352713627137271382713927140271412714227143271442714527146271472714827149271502715127152271532715427155271562715727158271592716027161271622716327164271652716627167271682716927170271712717227173271742717527176271772717827179271802718127182271832718427185271862718727188271892719027191271922719327194271952719627197271982719927200272012720227203272042720527206272072720827209272102721127212272132721427215272162721727218272192722027221272222722327224272252722627227272282722927230272312723227233272342723527236272372723827239272402724127242272432724427245272462724727248272492725027251272522725327254272552725627257272582725927260272612726227263272642726527266272672726827269272702727127272272732727427275272762727727278272792728027281272822728327284272852728627287272882728927290272912729227293272942729527296272972729827299273002730127302273032730427305273062730727308273092731027311273122731327314273152731627317273182731927320273212732227323273242732527326273272732827329273302733127332273332733427335273362733727338273392734027341273422734327344273452734627347273482734927350273512735227353273542735527356273572735827359273602736127362273632736427365273662736727368273692737027371273722737327374273752737627377273782737927380273812738227383273842738527386273872738827389273902739127392273932739427395273962739727398273992740027401274022740327404274052740627407274082740927410274112741227413274142741527416274172741827419274202742127422274232742427425274262742727428274292743027431274322743327434274352743627437274382743927440274412744227443274442744527446274472744827449274502745127452274532745427455274562745727458274592746027461274622746327464274652746627467274682746927470274712747227473274742747527476274772747827479274802748127482274832748427485274862748727488274892749027491274922749327494274952749627497274982749927500275012750227503275042750527506275072750827509275102751127512275132751427515275162751727518275192752027521275222752327524275252752627527275282752927530275312753227533275342753527536275372753827539275402754127542275432754427545275462754727548275492755027551275522755327554275552755627557275582755927560275612756227563275642756527566275672756827569275702757127572275732757427575275762757727578275792758027581275822758327584275852758627587275882758927590275912759227593275942759527596275972759827599276002760127602276032760427605276062760727608276092761027611276122761327614276152761627617276182761927620276212762227623276242762527626276272762827629276302763127632276332763427635276362763727638276392764027641276422764327644276452764627647276482764927650276512765227653276542765527656276572765827659276602766127662276632766427665276662766727668276692767027671276722767327674276752767627677276782767927680276812768227683276842768527686276872768827689276902769127692276932769427695276962769727698276992770027701277022770327704277052770627707277082770927710277112771227713277142771527716277172771827719277202772127722277232772427725277262772727728277292773027731277322773327734277352773627737277382773927740277412774227743277442774527746277472774827749277502775127752277532775427755277562775727758277592776027761277622776327764277652776627767277682776927770277712777227773277742777527776277772777827779277802778127782277832778427785277862778727788277892779027791277922779327794277952779627797277982779927800278012780227803278042780527806278072780827809278102781127812278132781427815278162781727818278192782027821278222782327824278252782627827278282782927830278312783227833278342783527836278372783827839278402784127842278432784427845278462784727848278492785027851278522785327854278552785627857278582785927860278612786227863278642786527866278672786827869278702787127872278732787427875278762787727878278792788027881278822788327884278852788627887278882788927890278912789227893278942789527896278972789827899279002790127902279032790427905279062790727908279092791027911279122791327914279152791627917279182791927920279212792227923279242792527926279272792827929279302793127932279332793427935279362793727938279392794027941279422794327944279452794627947279482794927950279512795227953279542795527956279572795827959279602796127962279632796427965279662796727968279692797027971279722797327974279752797627977279782797927980279812798227983279842798527986279872798827989279902799127992279932799427995279962799727998279992800028001280022800328004280052800628007280082800928010280112801228013280142801528016280172801828019280202802128022280232802428025280262802728028280292803028031280322803328034280352803628037280382803928040280412804228043280442804528046280472804828049280502805128052280532805428055280562805728058280592806028061280622806328064280652806628067280682806928070280712807228073280742807528076280772807828079280802808128082280832808428085280862808728088280892809028091280922809328094280952809628097280982809928100281012810228103281042810528106281072810828109281102811128112281132811428115281162811728118281192812028121281222812328124281252812628127281282812928130281312813228133281342813528136281372813828139281402814128142281432814428145281462814728148281492815028151281522815328154281552815628157281582815928160281612816228163281642816528166281672816828169281702817128172281732817428175281762817728178281792818028181281822818328184281852818628187281882818928190281912819228193281942819528196281972819828199282002820128202282032820428205282062820728208282092821028211282122821328214282152821628217282182821928220282212822228223282242822528226282272822828229282302823128232282332823428235282362823728238282392824028241282422824328244282452824628247282482824928250282512825228253282542825528256282572825828259282602826128262282632826428265282662826728268282692827028271282722827328274282752827628277282782827928280282812828228283282842828528286282872828828289282902829128292282932829428295282962829728298282992830028301283022830328304283052830628307283082830928310283112831228313283142831528316283172831828319283202832128322283232832428325283262832728328283292833028331283322833328334283352833628337283382833928340283412834228343283442834528346283472834828349283502835128352283532835428355283562835728358283592836028361283622836328364283652836628367283682836928370283712837228373283742837528376283772837828379283802838128382283832838428385283862838728388283892839028391283922839328394283952839628397283982839928400284012840228403284042840528406284072840828409284102841128412284132841428415284162841728418284192842028421284222842328424284252842628427284282842928430284312843228433284342843528436284372843828439284402844128442284432844428445284462844728448284492845028451284522845328454284552845628457284582845928460284612846228463284642846528466284672846828469284702847128472284732847428475284762847728478284792848028481284822848328484284852848628487284882848928490284912849228493284942849528496284972849828499285002850128502285032850428505285062850728508285092851028511285122851328514285152851628517285182851928520285212852228523285242852528526285272852828529285302853128532285332853428535285362853728538285392854028541285422854328544285452854628547285482854928550285512855228553285542855528556285572855828559285602856128562285632856428565285662856728568285692857028571285722857328574285752857628577285782857928580285812858228583285842858528586285872858828589285902859128592285932859428595285962859728598285992860028601286022860328604286052860628607286082860928610286112861228613286142861528616286172861828619286202862128622286232862428625286262862728628286292863028631286322863328634286352863628637286382863928640286412864228643286442864528646286472864828649286502865128652286532865428655286562865728658286592866028661286622866328664286652866628667286682866928670286712867228673286742867528676286772867828679286802868128682286832868428685286862868728688286892869028691286922869328694286952869628697286982869928700287012870228703287042870528706287072870828709287102871128712287132871428715287162871728718287192872028721287222872328724287252872628727287282872928730287312873228733287342873528736287372873828739287402874128742287432874428745287462874728748287492875028751287522875328754287552875628757287582875928760287612876228763287642876528766287672876828769287702877128772287732877428775287762877728778287792878028781287822878328784287852878628787287882878928790287912879228793287942879528796287972879828799288002880128802288032880428805288062880728808288092881028811288122881328814288152881628817288182881928820288212882228823288242882528826288272882828829288302883128832288332883428835288362883728838288392884028841288422884328844288452884628847288482884928850288512885228853288542885528856288572885828859288602886128862288632886428865288662886728868288692887028871288722887328874288752887628877288782887928880288812888228883288842888528886288872888828889288902889128892288932889428895288962889728898288992890028901289022890328904289052890628907289082890928910289112891228913289142891528916289172891828919289202892128922289232892428925289262892728928289292893028931289322893328934289352893628937289382893928940289412894228943289442894528946289472894828949289502895128952289532895428955289562895728958289592896028961289622896328964289652896628967289682896928970289712897228973289742897528976289772897828979289802898128982289832898428985289862898728988289892899028991289922899328994289952899628997289982899929000290012900229003290042900529006290072900829009290102901129012290132901429015290162901729018290192902029021290222902329024290252902629027290282902929030290312903229033290342903529036290372903829039290402904129042290432904429045290462904729048290492905029051290522905329054290552905629057290582905929060290612906229063290642906529066290672906829069290702907129072290732907429075290762907729078290792908029081290822908329084290852908629087290882908929090290912909229093290942909529096290972909829099291002910129102291032910429105291062910729108291092911029111291122911329114291152911629117291182911929120291212912229123291242912529126291272912829129291302913129132291332913429135291362913729138291392914029141291422914329144291452914629147291482914929150291512915229153291542915529156291572915829159291602916129162291632916429165291662916729168291692917029171291722917329174291752917629177291782917929180291812918229183291842918529186291872918829189291902919129192291932919429195291962919729198291992920029201292022920329204292052920629207292082920929210292112921229213292142921529216292172921829219292202922129222292232922429225292262922729228292292923029231292322923329234292352923629237292382923929240292412924229243292442924529246292472924829249292502925129252292532925429255292562925729258292592926029261292622926329264292652926629267292682926929270292712927229273292742927529276292772927829279292802928129282292832928429285292862928729288292892929029291292922929329294292952929629297292982929929300293012930229303293042930529306293072930829309293102931129312293132931429315293162931729318293192932029321293222932329324293252932629327293282932929330293312933229333293342933529336293372933829339293402934129342293432934429345293462934729348293492935029351293522935329354293552935629357293582935929360293612936229363293642936529366293672936829369293702937129372293732937429375293762937729378293792938029381293822938329384293852938629387293882938929390293912939229393293942939529396293972939829399294002940129402294032940429405294062940729408294092941029411294122941329414294152941629417294182941929420294212942229423294242942529426294272942829429294302943129432294332943429435294362943729438294392944029441294422944329444294452944629447294482944929450294512945229453294542945529456294572945829459294602946129462294632946429465294662946729468294692947029471294722947329474294752947629477294782947929480294812948229483294842948529486294872948829489294902949129492294932949429495294962949729498294992950029501295022950329504295052950629507295082950929510295112951229513295142951529516295172951829519295202952129522295232952429525295262952729528295292953029531295322953329534295352953629537295382953929540295412954229543295442954529546295472954829549295502955129552295532955429555295562955729558295592956029561295622956329564295652956629567295682956929570295712957229573295742957529576295772957829579295802958129582295832958429585295862958729588295892959029591295922959329594295952959629597295982959929600296012960229603296042960529606296072960829609296102961129612296132961429615296162961729618296192962029621296222962329624296252962629627296282962929630296312963229633296342963529636296372963829639296402964129642296432964429645296462964729648296492965029651296522965329654296552965629657296582965929660296612966229663296642966529666296672966829669296702967129672296732967429675296762967729678296792968029681296822968329684296852968629687296882968929690296912969229693296942969529696296972969829699297002970129702297032970429705297062970729708297092971029711297122971329714297152971629717297182971929720297212972229723297242972529726297272972829729297302973129732297332973429735297362973729738297392974029741297422974329744297452974629747297482974929750297512975229753297542975529756297572975829759297602976129762297632976429765297662976729768297692977029771297722977329774297752977629777297782977929780297812978229783297842978529786297872978829789297902979129792297932979429795297962979729798297992980029801298022980329804298052980629807298082980929810298112981229813298142981529816298172981829819298202982129822298232982429825298262982729828298292983029831298322983329834298352983629837298382983929840298412984229843298442984529846298472984829849298502985129852298532985429855298562985729858298592986029861298622986329864298652986629867298682986929870298712987229873298742987529876298772987829879298802988129882298832988429885298862988729888298892989029891298922989329894298952989629897298982989929900299012990229903299042990529906299072990829909299102991129912299132991429915299162991729918299192992029921299222992329924299252992629927299282992929930299312993229933299342993529936299372993829939299402994129942299432994429945299462994729948299492995029951299522995329954299552995629957299582995929960299612996229963299642996529966299672996829969299702997129972299732997429975299762997729978299792998029981299822998329984299852998629987299882998929990299912999229993299942999529996299972999829999300003000130002300033000430005300063000730008300093001030011300123001330014300153001630017300183001930020300213002230023300243002530026300273002830029300303003130032300333003430035300363003730038300393004030041300423004330044300453004630047300483004930050300513005230053300543005530056300573005830059300603006130062300633006430065300663006730068300693007030071300723007330074300753007630077300783007930080300813008230083300843008530086300873008830089300903009130092300933009430095300963009730098300993010030101301023010330104301053010630107301083010930110301113011230113301143011530116301173011830119301203012130122301233012430125301263012730128301293013030131301323013330134301353013630137301383013930140301413014230143301443014530146301473014830149301503015130152301533015430155301563015730158301593016030161301623016330164301653016630167301683016930170301713017230173301743017530176301773017830179301803018130182301833018430185301863018730188301893019030191301923019330194301953019630197301983019930200302013020230203302043020530206302073020830209302103021130212302133021430215302163021730218302193022030221302223022330224302253022630227302283022930230302313023230233302343023530236302373023830239302403024130242302433024430245302463024730248302493025030251302523025330254302553025630257302583025930260302613026230263302643026530266302673026830269302703027130272302733027430275302763027730278302793028030281302823028330284302853028630287302883028930290302913029230293302943029530296302973029830299303003030130302303033030430305303063030730308303093031030311303123031330314303153031630317303183031930320303213032230323303243032530326303273032830329303303033130332303333033430335303363033730338303393034030341303423034330344303453034630347303483034930350303513035230353303543035530356303573035830359303603036130362303633036430365303663036730368303693037030371303723037330374303753037630377303783037930380303813038230383303843038530386303873038830389303903039130392303933039430395303963039730398303993040030401304023040330404304053040630407304083040930410304113041230413304143041530416304173041830419304203042130422304233042430425304263042730428304293043030431304323043330434304353043630437304383043930440304413044230443304443044530446304473044830449304503045130452304533045430455304563045730458304593046030461304623046330464304653046630467304683046930470304713047230473304743047530476304773047830479304803048130482304833048430485304863048730488304893049030491304923049330494304953049630497304983049930500305013050230503305043050530506305073050830509305103051130512305133051430515305163051730518305193052030521305223052330524305253052630527305283052930530305313053230533305343053530536305373053830539305403054130542305433054430545305463054730548305493055030551305523055330554305553055630557305583055930560305613056230563305643056530566305673056830569305703057130572305733057430575305763057730578305793058030581305823058330584305853058630587305883058930590305913059230593305943059530596305973059830599306003060130602306033060430605306063060730608306093061030611306123061330614306153061630617306183061930620306213062230623306243062530626306273062830629306303063130632306333063430635306363063730638306393064030641306423064330644306453064630647306483064930650306513065230653306543065530656306573065830659306603066130662306633066430665306663066730668306693067030671306723067330674306753067630677306783067930680306813068230683306843068530686306873068830689306903069130692306933069430695306963069730698306993070030701307023070330704307053070630707307083070930710307113071230713307143071530716307173071830719307203072130722307233072430725307263072730728307293073030731307323073330734307353073630737307383073930740307413074230743307443074530746307473074830749307503075130752307533075430755307563075730758307593076030761307623076330764307653076630767307683076930770307713077230773307743077530776307773077830779307803078130782307833078430785307863078730788307893079030791307923079330794307953079630797307983079930800308013080230803308043080530806308073080830809308103081130812308133081430815308163081730818308193082030821308223082330824308253082630827308283082930830308313083230833308343083530836308373083830839308403084130842308433084430845308463084730848308493085030851308523085330854308553085630857308583085930860308613086230863308643086530866308673086830869308703087130872308733087430875308763087730878308793088030881308823088330884308853088630887308883088930890308913089230893308943089530896308973089830899309003090130902309033090430905309063090730908309093091030911309123091330914309153091630917309183091930920309213092230923309243092530926309273092830929309303093130932309333093430935309363093730938309393094030941309423094330944309453094630947309483094930950309513095230953309543095530956309573095830959309603096130962309633096430965309663096730968309693097030971309723097330974309753097630977309783097930980309813098230983309843098530986309873098830989309903099130992309933099430995309963099730998309993100031001310023100331004310053100631007310083100931010310113101231013310143101531016310173101831019310203102131022310233102431025310263102731028310293103031031310323103331034310353103631037310383103931040310413104231043310443104531046310473104831049310503105131052310533105431055310563105731058310593106031061310623106331064310653106631067310683106931070310713107231073310743107531076310773107831079310803108131082310833108431085310863108731088310893109031091310923109331094310953109631097310983109931100311013110231103311043110531106311073110831109311103111131112311133111431115311163111731118311193112031121311223112331124311253112631127311283112931130311313113231133311343113531136311373113831139311403114131142311433114431145311463114731148311493115031151311523115331154311553115631157311583115931160311613116231163311643116531166311673116831169311703117131172311733117431175311763117731178311793118031181311823118331184311853118631187311883118931190311913119231193311943119531196311973119831199312003120131202312033120431205312063120731208312093121031211312123121331214312153121631217312183121931220312213122231223312243122531226312273122831229312303123131232312333123431235312363123731238312393124031241312423124331244312453124631247312483124931250312513125231253312543125531256312573125831259312603126131262312633126431265312663126731268312693127031271312723127331274312753127631277312783127931280312813128231283312843128531286312873128831289312903129131292312933129431295312963129731298312993130031301313023130331304313053130631307313083130931310313113131231313313143131531316313173131831319313203132131322313233132431325313263132731328313293133031331313323133331334313353133631337313383133931340313413134231343313443134531346313473134831349313503135131352313533135431355313563135731358313593136031361313623136331364313653136631367313683136931370313713137231373313743137531376313773137831379313803138131382313833138431385313863138731388313893139031391313923139331394313953139631397313983139931400314013140231403314043140531406314073140831409314103141131412314133141431415314163141731418314193142031421314223142331424314253142631427314283142931430314313143231433314343143531436314373143831439314403144131442314433144431445314463144731448314493145031451314523145331454314553145631457314583145931460314613146231463314643146531466314673146831469314703147131472314733147431475314763147731478314793148031481314823148331484314853148631487314883148931490314913149231493314943149531496314973149831499315003150131502315033150431505315063150731508315093151031511315123151331514315153151631517315183151931520315213152231523315243152531526315273152831529315303153131532315333153431535315363153731538315393154031541315423154331544315453154631547315483154931550315513155231553315543155531556315573155831559315603156131562315633156431565315663156731568315693157031571315723157331574315753157631577315783157931580315813158231583315843158531586315873158831589315903159131592315933159431595315963159731598315993160031601316023160331604316053160631607316083160931610316113161231613316143161531616316173161831619316203162131622316233162431625316263162731628316293163031631316323163331634316353163631637316383163931640316413164231643316443164531646316473164831649316503165131652316533165431655316563165731658316593166031661316623166331664316653166631667316683166931670316713167231673316743167531676316773167831679316803168131682316833168431685316863168731688316893169031691316923169331694316953169631697316983169931700317013170231703317043170531706317073170831709317103171131712317133171431715317163171731718317193172031721317223172331724317253172631727317283172931730317313173231733317343173531736317373173831739317403174131742317433174431745317463174731748317493175031751317523175331754317553175631757317583175931760317613176231763317643176531766317673176831769317703177131772317733177431775317763177731778317793178031781317823178331784317853178631787317883178931790317913179231793317943179531796317973179831799318003180131802318033180431805318063180731808318093181031811318123181331814318153181631817318183181931820318213182231823318243182531826318273182831829318303183131832318333183431835318363183731838318393184031841318423184331844318453184631847318483184931850318513185231853318543185531856318573185831859318603186131862318633186431865318663186731868318693187031871318723187331874318753187631877318783187931880318813188231883318843188531886318873188831889318903189131892318933189431895318963189731898318993190031901319023190331904319053190631907319083190931910319113191231913319143191531916319173191831919319203192131922319233192431925319263192731928319293193031931319323193331934319353193631937319383193931940319413194231943319443194531946319473194831949319503195131952319533195431955319563195731958319593196031961319623196331964319653196631967319683196931970319713197231973319743197531976319773197831979319803198131982319833198431985319863198731988319893199031991319923199331994319953199631997319983199932000320013200232003320043200532006320073200832009320103201132012320133201432015320163201732018320193202032021320223202332024320253202632027320283202932030320313203232033320343203532036320373203832039320403204132042320433204432045320463204732048320493205032051320523205332054320553205632057320583205932060320613206232063320643206532066320673206832069320703207132072320733207432075320763207732078320793208032081320823208332084320853208632087320883208932090320913209232093320943209532096320973209832099321003210132102321033210432105321063210732108321093211032111321123211332114321153211632117321183211932120321213212232123321243212532126321273212832129321303213132132321333213432135321363213732138321393214032141321423214332144321453214632147321483214932150321513215232153321543215532156321573215832159321603216132162321633216432165321663216732168321693217032171321723217332174321753217632177321783217932180321813218232183321843218532186321873218832189321903219132192321933219432195321963219732198321993220032201322023220332204322053220632207322083220932210322113221232213322143221532216322173221832219322203222132222322233222432225322263222732228322293223032231322323223332234322353223632237322383223932240322413224232243322443224532246322473224832249322503225132252322533225432255322563225732258322593226032261322623226332264322653226632267322683226932270322713227232273322743227532276322773227832279322803228132282322833228432285322863228732288322893229032291322923229332294322953229632297322983229932300323013230232303323043230532306323073230832309323103231132312323133231432315323163231732318323193232032321323223232332324323253232632327323283232932330323313233232333323343233532336323373233832339323403234132342323433234432345323463234732348323493235032351323523235332354323553235632357323583235932360323613236232363323643236532366323673236832369323703237132372323733237432375323763237732378323793238032381323823238332384323853238632387323883238932390323913239232393323943239532396323973239832399324003240132402324033240432405324063240732408324093241032411324123241332414324153241632417324183241932420324213242232423324243242532426324273242832429324303243132432324333243432435324363243732438324393244032441324423244332444324453244632447324483244932450324513245232453324543245532456324573245832459324603246132462324633246432465324663246732468324693247032471324723247332474324753247632477324783247932480324813248232483324843248532486324873248832489324903249132492324933249432495324963249732498324993250032501325023250332504325053250632507325083250932510325113251232513325143251532516325173251832519325203252132522325233252432525325263252732528325293253032531325323253332534325353253632537325383253932540325413254232543325443254532546325473254832549325503255132552325533255432555325563255732558325593256032561325623256332564325653256632567325683256932570325713257232573325743257532576325773257832579325803258132582325833258432585325863258732588325893259032591325923259332594325953259632597325983259932600326013260232603326043260532606326073260832609326103261132612326133261432615326163261732618326193262032621326223262332624326253262632627326283262932630326313263232633326343263532636326373263832639326403264132642326433264432645326463264732648326493265032651326523265332654326553265632657326583265932660326613266232663326643266532666326673266832669326703267132672326733267432675326763267732678326793268032681326823268332684326853268632687326883268932690326913269232693326943269532696326973269832699327003270132702327033270432705327063270732708327093271032711327123271332714327153271632717327183271932720327213272232723327243272532726327273272832729327303273132732327333273432735327363273732738327393274032741327423274332744327453274632747327483274932750327513275232753327543275532756327573275832759327603276132762327633276432765327663276732768327693277032771327723277332774327753277632777327783277932780327813278232783327843278532786327873278832789327903279132792327933279432795327963279732798327993280032801328023280332804328053280632807328083280932810328113281232813328143281532816328173281832819328203282132822328233282432825328263282732828328293283032831328323283332834328353283632837328383283932840328413284232843328443284532846328473284832849328503285132852328533285432855328563285732858328593286032861328623286332864328653286632867328683286932870328713287232873328743287532876328773287832879328803288132882328833288432885328863288732888328893289032891328923289332894328953289632897328983289932900329013290232903329043290532906329073290832909329103291132912329133291432915329163291732918329193292032921329223292332924329253292632927329283292932930329313293232933329343293532936329373293832939329403294132942329433294432945329463294732948329493295032951329523295332954329553295632957329583295932960329613296232963329643296532966329673296832969329703297132972329733297432975329763297732978329793298032981329823298332984329853298632987329883298932990329913299232993329943299532996329973299832999330003300133002330033300433005330063300733008330093301033011330123301333014330153301633017330183301933020330213302233023330243302533026330273302833029330303303133032330333303433035330363303733038330393304033041330423304333044330453304633047330483304933050330513305233053330543305533056330573305833059330603306133062330633306433065330663306733068330693307033071330723307333074330753307633077330783307933080330813308233083330843308533086330873308833089330903309133092330933309433095330963309733098330993310033101331023310333104331053310633107331083310933110331113311233113331143311533116331173311833119331203312133122331233312433125331263312733128331293313033131331323313333134331353313633137331383313933140331413314233143331443314533146331473314833149331503315133152331533315433155331563315733158331593316033161331623316333164331653316633167331683316933170331713317233173331743317533176331773317833179331803318133182331833318433185331863318733188331893319033191331923319333194331953319633197331983319933200332013320233203332043320533206332073320833209332103321133212332133321433215332163321733218332193322033221332223322333224332253322633227332283322933230332313323233233332343323533236332373323833239332403324133242332433324433245332463324733248332493325033251332523325333254332553325633257332583325933260332613326233263332643326533266332673326833269332703327133272332733327433275332763327733278332793328033281332823328333284332853328633287332883328933290332913329233293332943329533296332973329833299333003330133302333033330433305333063330733308333093331033311333123331333314333153331633317333183331933320333213332233323333243332533326333273332833329333303333133332333333333433335333363333733338333393334033341333423334333344333453334633347333483334933350333513335233353333543335533356333573335833359333603336133362333633336433365333663336733368333693337033371333723337333374333753337633377333783337933380333813338233383333843338533386333873338833389333903339133392333933339433395333963339733398333993340033401334023340333404334053340633407334083340933410334113341233413334143341533416334173341833419334203342133422334233342433425334263342733428334293343033431334323343333434334353343633437334383343933440334413344233443334443344533446334473344833449334503345133452334533345433455334563345733458334593346033461334623346333464334653346633467334683346933470334713347233473334743347533476334773347833479334803348133482334833348433485334863348733488334893349033491334923349333494334953349633497334983349933500335013350233503335043350533506335073350833509335103351133512335133351433515335163351733518335193352033521335223352333524335253352633527335283352933530335313353233533335343353533536335373353833539335403354133542335433354433545335463354733548335493355033551335523355333554335553355633557335583355933560335613356233563335643356533566335673356833569335703357133572335733357433575335763357733578335793358033581335823358333584335853358633587335883358933590335913359233593335943359533596335973359833599336003360133602336033360433605336063360733608336093361033611336123361333614336153361633617336183361933620336213362233623336243362533626336273362833629336303363133632336333363433635336363363733638336393364033641336423364333644336453364633647336483364933650336513365233653336543365533656336573365833659336603366133662336633366433665336663366733668336693367033671336723367333674336753367633677336783367933680336813368233683336843368533686336873368833689336903369133692336933369433695336963369733698336993370033701337023370333704337053370633707337083370933710337113371233713337143371533716337173371833719337203372133722337233372433725337263372733728337293373033731337323373333734337353373633737337383373933740337413374233743337443374533746337473374833749337503375133752337533375433755337563375733758337593376033761337623376333764337653376633767337683376933770337713377233773337743377533776337773377833779337803378133782337833378433785337863378733788337893379033791337923379333794337953379633797337983379933800338013380233803338043380533806338073380833809338103381133812338133381433815338163381733818338193382033821338223382333824338253382633827338283382933830338313383233833338343383533836338373383833839338403384133842338433384433845338463384733848338493385033851338523385333854338553385633857338583385933860338613386233863338643386533866338673386833869338703387133872338733387433875338763387733878338793388033881338823388333884338853388633887338883388933890338913389233893338943389533896338973389833899339003390133902339033390433905339063390733908339093391033911339123391333914339153391633917339183391933920339213392233923339243392533926339273392833929339303393133932339333393433935339363393733938339393394033941339423394333944339453394633947339483394933950339513395233953339543395533956339573395833959339603396133962339633396433965339663396733968339693397033971339723397333974339753397633977339783397933980339813398233983339843398533986339873398833989339903399133992339933399433995339963399733998339993400034001340023400334004340053400634007340083400934010340113401234013340143401534016340173401834019340203402134022340233402434025340263402734028340293403034031340323403334034340353403634037340383403934040340413404234043340443404534046340473404834049340503405134052340533405434055340563405734058340593406034061340623406334064340653406634067340683406934070340713407234073340743407534076340773407834079340803408134082340833408434085340863408734088340893409034091340923409334094340953409634097340983409934100341013410234103341043410534106341073410834109341103411134112341133411434115341163411734118341193412034121341223412334124341253412634127341283412934130341313413234133341343413534136341373413834139341403414134142341433414434145341463414734148341493415034151341523415334154341553415634157341583415934160341613416234163341643416534166341673416834169341703417134172341733417434175341763417734178341793418034181341823418334184341853418634187341883418934190341913419234193341943419534196341973419834199342003420134202342033420434205342063420734208342093421034211342123421334214342153421634217342183421934220342213422234223342243422534226342273422834229342303423134232342333423434235342363423734238342393424034241342423424334244342453424634247342483424934250342513425234253342543425534256342573425834259342603426134262342633426434265342663426734268342693427034271342723427334274342753427634277342783427934280342813428234283342843428534286342873428834289342903429134292342933429434295342963429734298342993430034301343023430334304343053430634307343083430934310343113431234313343143431534316343173431834319343203432134322343233432434325343263432734328343293433034331343323433334334343353433634337343383433934340343413434234343343443434534346343473434834349343503435134352343533435434355343563435734358343593436034361343623436334364343653436634367343683436934370343713437234373343743437534376343773437834379343803438134382343833438434385343863438734388343893439034391343923439334394343953439634397343983439934400344013440234403344043440534406344073440834409344103441134412344133441434415344163441734418344193442034421344223442334424344253442634427344283442934430344313443234433344343443534436344373443834439344403444134442344433444434445344463444734448344493445034451344523445334454344553445634457344583445934460344613446234463344643446534466344673446834469344703447134472344733447434475344763447734478344793448034481344823448334484344853448634487344883448934490344913449234493344943449534496344973449834499345003450134502345033450434505345063450734508345093451034511345123451334514345153451634517345183451934520345213452234523345243452534526345273452834529345303453134532345333453434535345363453734538345393454034541345423454334544345453454634547345483454934550345513455234553345543455534556345573455834559345603456134562345633456434565345663456734568345693457034571345723457334574345753457634577345783457934580345813458234583345843458534586345873458834589345903459134592345933459434595345963459734598345993460034601346023460334604346053460634607346083460934610346113461234613346143461534616346173461834619346203462134622346233462434625346263462734628346293463034631346323463334634346353463634637346383463934640346413464234643346443464534646346473464834649346503465134652346533465434655346563465734658346593466034661346623466334664346653466634667346683466934670346713467234673346743467534676346773467834679346803468134682346833468434685346863468734688346893469034691346923469334694346953469634697346983469934700347013470234703347043470534706347073470834709347103471134712347133471434715347163471734718347193472034721347223472334724347253472634727347283472934730347313473234733347343473534736347373473834739347403474134742347433474434745347463474734748347493475034751347523475334754347553475634757347583475934760347613476234763347643476534766347673476834769347703477134772347733477434775347763477734778347793478034781347823478334784347853478634787347883478934790347913479234793347943479534796347973479834799348003480134802348033480434805348063480734808348093481034811348123481334814348153481634817348183481934820348213482234823348243482534826348273482834829348303483134832348333483434835348363483734838348393484034841348423484334844348453484634847348483484934850348513485234853348543485534856348573485834859348603486134862348633486434865348663486734868348693487034871348723487334874348753487634877348783487934880348813488234883348843488534886348873488834889348903489134892348933489434895348963489734898348993490034901349023490334904349053490634907349083490934910349113491234913349143491534916349173491834919349203492134922349233492434925349263492734928349293493034931349323493334934349353493634937349383493934940349413494234943349443494534946349473494834949349503495134952349533495434955349563495734958349593496034961349623496334964349653496634967349683496934970349713497234973349743497534976349773497834979349803498134982349833498434985349863498734988349893499034991349923499334994349953499634997349983499935000350013500235003350043500535006350073500835009350103501135012350133501435015350163501735018350193502035021350223502335024350253502635027350283502935030350313503235033350343503535036350373503835039350403504135042350433504435045350463504735048350493505035051350523505335054350553505635057350583505935060350613506235063350643506535066350673506835069350703507135072350733507435075350763507735078350793508035081350823508335084350853508635087350883508935090350913509235093350943509535096350973509835099351003510135102351033510435105351063510735108351093511035111351123511335114351153511635117351183511935120351213512235123351243512535126351273512835129351303513135132351333513435135351363513735138351393514035141351423514335144351453514635147351483514935150351513515235153351543515535156351573515835159351603516135162351633516435165351663516735168351693517035171351723517335174351753517635177351783517935180351813518235183351843518535186351873518835189351903519135192351933519435195351963519735198351993520035201352023520335204352053520635207352083520935210352113521235213352143521535216352173521835219352203522135222352233522435225352263522735228352293523035231352323523335234352353523635237352383523935240352413524235243352443524535246352473524835249352503525135252352533525435255352563525735258352593526035261352623526335264352653526635267352683526935270352713527235273352743527535276352773527835279352803528135282352833528435285352863528735288352893529035291352923529335294352953529635297352983529935300353013530235303353043530535306353073530835309353103531135312353133531435315353163531735318353193532035321353223532335324353253532635327353283532935330353313533235333353343533535336353373533835339353403534135342353433534435345353463534735348353493535035351353523535335354353553535635357353583535935360353613536235363353643536535366353673536835369353703537135372353733537435375353763537735378353793538035381353823538335384353853538635387353883538935390353913539235393353943539535396353973539835399354003540135402354033540435405354063540735408354093541035411354123541335414354153541635417354183541935420354213542235423354243542535426354273542835429354303543135432354333543435435354363543735438354393544035441354423544335444354453544635447354483544935450354513545235453354543545535456354573545835459354603546135462354633546435465354663546735468354693547035471354723547335474354753547635477354783547935480354813548235483354843548535486354873548835489354903549135492354933549435495354963549735498354993550035501355023550335504355053550635507355083550935510355113551235513355143551535516355173551835519355203552135522355233552435525355263552735528355293553035531355323553335534355353553635537355383553935540355413554235543355443554535546355473554835549355503555135552355533555435555355563555735558355593556035561355623556335564355653556635567355683556935570355713557235573355743557535576355773557835579355803558135582355833558435585355863558735588355893559035591355923559335594355953559635597355983559935600356013560235603356043560535606356073560835609356103561135612356133561435615356163561735618356193562035621356223562335624356253562635627356283562935630356313563235633356343563535636356373563835639356403564135642356433564435645356463564735648356493565035651356523565335654356553565635657356583565935660356613566235663356643566535666356673566835669356703567135672356733567435675356763567735678356793568035681356823568335684356853568635687356883568935690356913569235693356943569535696356973569835699357003570135702357033570435705357063570735708357093571035711357123571335714357153571635717357183571935720357213572235723357243572535726357273572835729357303573135732357333573435735357363573735738357393574035741357423574335744357453574635747357483574935750357513575235753357543575535756357573575835759357603576135762357633576435765357663576735768357693577035771357723577335774357753577635777357783577935780357813578235783357843578535786357873578835789357903579135792357933579435795357963579735798357993580035801358023580335804358053580635807358083580935810358113581235813358143581535816358173581835819358203582135822358233582435825358263582735828358293583035831358323583335834358353583635837358383583935840358413584235843358443584535846358473584835849358503585135852358533585435855358563585735858358593586035861358623586335864358653586635867358683586935870358713587235873358743587535876358773587835879358803588135882358833588435885358863588735888358893589035891358923589335894358953589635897358983589935900359013590235903359043590535906359073590835909359103591135912359133591435915359163591735918359193592035921359223592335924359253592635927359283592935930359313593235933359343593535936359373593835939359403594135942359433594435945359463594735948359493595035951359523595335954359553595635957359583595935960359613596235963359643596535966359673596835969359703597135972359733597435975359763597735978359793598035981359823598335984359853598635987359883598935990359913599235993359943599535996359973599835999360003600136002360033600436005360063600736008360093601036011360123601336014360153601636017360183601936020360213602236023360243602536026360273602836029360303603136032360333603436035360363603736038360393604036041360423604336044360453604636047360483604936050360513605236053360543605536056360573605836059360603606136062360633606436065360663606736068360693607036071360723607336074360753607636077360783607936080360813608236083360843608536086360873608836089360903609136092360933609436095360963609736098360993610036101361023610336104361053610636107361083610936110361113611236113361143611536116361173611836119361203612136122361233612436125361263612736128361293613036131361323613336134361353613636137361383613936140361413614236143361443614536146361473614836149361503615136152361533615436155361563615736158361593616036161361623616336164361653616636167361683616936170361713617236173361743617536176361773617836179361803618136182361833618436185361863618736188361893619036191361923619336194361953619636197361983619936200362013620236203362043620536206362073620836209362103621136212362133621436215362163621736218362193622036221362223622336224362253622636227362283622936230362313623236233362343623536236362373623836239362403624136242362433624436245362463624736248362493625036251362523625336254362553625636257362583625936260362613626236263362643626536266362673626836269362703627136272362733627436275362763627736278362793628036281362823628336284362853628636287362883628936290362913629236293362943629536296362973629836299363003630136302363033630436305363063630736308363093631036311363123631336314363153631636317363183631936320363213632236323363243632536326363273632836329363303633136332363333633436335363363633736338363393634036341363423634336344363453634636347363483634936350363513635236353363543635536356363573635836359363603636136362363633636436365363663636736368363693637036371363723637336374363753637636377363783637936380363813638236383363843638536386363873638836389363903639136392363933639436395363963639736398363993640036401364023640336404364053640636407364083640936410364113641236413364143641536416364173641836419364203642136422364233642436425364263642736428364293643036431364323643336434364353643636437364383643936440364413644236443364443644536446364473644836449364503645136452364533645436455364563645736458364593646036461364623646336464364653646636467364683646936470364713647236473364743647536476364773647836479364803648136482364833648436485364863648736488364893649036491364923649336494364953649636497364983649936500365013650236503365043650536506365073650836509365103651136512365133651436515365163651736518365193652036521365223652336524365253652636527365283652936530365313653236533365343653536536365373653836539365403654136542365433654436545365463654736548365493655036551365523655336554365553655636557365583655936560365613656236563365643656536566365673656836569365703657136572365733657436575365763657736578365793658036581365823658336584365853658636587365883658936590365913659236593365943659536596365973659836599366003660136602366033660436605366063660736608366093661036611366123661336614366153661636617366183661936620366213662236623366243662536626366273662836629366303663136632366333663436635366363663736638366393664036641366423664336644366453664636647366483664936650366513665236653366543665536656366573665836659366603666136662366633666436665366663666736668366693667036671366723667336674366753667636677366783667936680366813668236683366843668536686366873668836689366903669136692366933669436695366963669736698366993670036701367023670336704367053670636707367083670936710367113671236713367143671536716367173671836719367203672136722367233672436725367263672736728367293673036731367323673336734367353673636737367383673936740367413674236743367443674536746367473674836749367503675136752367533675436755367563675736758367593676036761367623676336764367653676636767367683676936770367713677236773367743677536776367773677836779367803678136782367833678436785367863678736788367893679036791367923679336794367953679636797367983679936800368013680236803368043680536806368073680836809368103681136812368133681436815368163681736818368193682036821368223682336824368253682636827368283682936830368313683236833368343683536836368373683836839368403684136842368433684436845368463684736848368493685036851368523685336854368553685636857368583685936860368613686236863368643686536866368673686836869368703687136872368733687436875368763687736878368793688036881368823688336884368853688636887368883688936890368913689236893368943689536896368973689836899369003690136902369033690436905369063690736908369093691036911369123691336914369153691636917369183691936920369213692236923369243692536926369273692836929369303693136932369333693436935369363693736938369393694036941369423694336944369453694636947369483694936950369513695236953369543695536956369573695836959369603696136962369633696436965369663696736968369693697036971369723697336974369753697636977369783697936980369813698236983369843698536986369873698836989369903699136992369933699436995369963699736998369993700037001370023700337004370053700637007370083700937010370113701237013370143701537016370173701837019370203702137022370233702437025370263702737028370293703037031370323703337034370353703637037370383703937040370413704237043370443704537046370473704837049370503705137052370533705437055370563705737058370593706037061370623706337064370653706637067370683706937070370713707237073370743707537076370773707837079370803708137082370833708437085370863708737088370893709037091370923709337094370953709637097370983709937100371013710237103371043710537106371073710837109371103711137112371133711437115371163711737118371193712037121371223712337124371253712637127371283712937130371313713237133371343713537136371373713837139371403714137142371433714437145371463714737148371493715037151371523715337154371553715637157371583715937160371613716237163371643716537166371673716837169371703717137172371733717437175371763717737178371793718037181371823718337184371853718637187371883718937190371913719237193371943719537196371973719837199372003720137202372033720437205372063720737208372093721037211372123721337214372153721637217372183721937220372213722237223372243722537226372273722837229372303723137232372333723437235372363723737238372393724037241372423724337244372453724637247372483724937250372513725237253372543725537256372573725837259372603726137262372633726437265372663726737268372693727037271372723727337274372753727637277372783727937280372813728237283372843728537286372873728837289372903729137292372933729437295372963729737298372993730037301373023730337304373053730637307373083730937310373113731237313373143731537316373173731837319373203732137322373233732437325373263732737328373293733037331373323733337334373353733637337373383733937340373413734237343373443734537346373473734837349373503735137352373533735437355373563735737358373593736037361373623736337364373653736637367373683736937370373713737237373373743737537376373773737837379373803738137382373833738437385373863738737388373893739037391373923739337394373953739637397373983739937400374013740237403374043740537406374073740837409374103741137412374133741437415374163741737418374193742037421374223742337424374253742637427374283742937430374313743237433374343743537436374373743837439374403744137442374433744437445374463744737448374493745037451374523745337454374553745637457374583745937460374613746237463374643746537466374673746837469374703747137472374733747437475374763747737478374793748037481374823748337484374853748637487374883748937490374913749237493374943749537496374973749837499375003750137502375033750437505375063750737508375093751037511375123751337514375153751637517375183751937520375213752237523375243752537526375273752837529375303753137532375333753437535375363753737538375393754037541375423754337544375453754637547375483754937550375513755237553375543755537556375573755837559375603756137562375633756437565375663756737568375693757037571375723757337574375753757637577375783757937580375813758237583375843758537586375873758837589375903759137592375933759437595375963759737598375993760037601376023760337604376053760637607376083760937610376113761237613376143761537616376173761837619376203762137622376233762437625376263762737628376293763037631376323763337634376353763637637376383763937640376413764237643376443764537646376473764837649376503765137652376533765437655376563765737658376593766037661376623766337664376653766637667376683766937670376713767237673376743767537676376773767837679376803768137682376833768437685376863768737688376893769037691376923769337694376953769637697376983769937700377013770237703377043770537706377073770837709377103771137712377133771437715377163771737718377193772037721377223772337724377253772637727377283772937730377313773237733377343773537736377373773837739377403774137742377433774437745377463774737748377493775037751377523775337754377553775637757377583775937760377613776237763377643776537766377673776837769377703777137772377733777437775377763777737778377793778037781377823778337784377853778637787377883778937790377913779237793377943779537796377973779837799378003780137802378033780437805378063780737808378093781037811378123781337814378153781637817378183781937820378213782237823378243782537826378273782837829378303783137832378333783437835378363783737838378393784037841378423784337844378453784637847378483784937850378513785237853378543785537856378573785837859378603786137862378633786437865378663786737868378693787037871378723787337874378753787637877378783787937880378813788237883378843788537886378873788837889378903789137892378933789437895378963789737898378993790037901379023790337904379053790637907379083790937910379113791237913379143791537916379173791837919379203792137922379233792437925379263792737928379293793037931379323793337934379353793637937379383793937940379413794237943379443794537946379473794837949379503795137952379533795437955379563795737958379593796037961379623796337964379653796637967379683796937970379713797237973379743797537976379773797837979379803798137982379833798437985379863798737988379893799037991379923799337994379953799637997379983799938000380013800238003380043800538006380073800838009380103801138012380133801438015380163801738018380193802038021380223802338024380253802638027380283802938030380313803238033380343803538036380373803838039380403804138042380433804438045380463804738048380493805038051380523805338054380553805638057380583805938060380613806238063380643806538066380673806838069380703807138072380733807438075380763807738078380793808038081380823808338084380853808638087380883808938090380913809238093380943809538096380973809838099381003810138102381033810438105381063810738108381093811038111381123811338114381153811638117381183811938120381213812238123381243812538126381273812838129381303813138132381333813438135381363813738138381393814038141381423814338144381453814638147381483814938150381513815238153381543815538156381573815838159381603816138162381633816438165381663816738168381693817038171381723817338174381753817638177381783817938180381813818238183381843818538186381873818838189381903819138192381933819438195381963819738198381993820038201382023820338204382053820638207382083820938210382113821238213382143821538216382173821838219382203822138222382233822438225382263822738228382293823038231382323823338234382353823638237382383823938240382413824238243382443824538246382473824838249382503825138252382533825438255382563825738258382593826038261382623826338264382653826638267382683826938270382713827238273382743827538276382773827838279382803828138282382833828438285382863828738288382893829038291382923829338294382953829638297382983829938300383013830238303383043830538306383073830838309383103831138312383133831438315383163831738318383193832038321383223832338324383253832638327383283832938330383313833238333383343833538336383373833838339383403834138342383433834438345383463834738348383493835038351383523835338354383553835638357383583835938360383613836238363383643836538366383673836838369383703837138372383733837438375383763837738378383793838038381383823838338384383853838638387383883838938390383913839238393383943839538396383973839838399384003840138402384033840438405384063840738408384093841038411384123841338414384153841638417384183841938420384213842238423384243842538426384273842838429384303843138432384333843438435384363843738438384393844038441384423844338444384453844638447384483844938450384513845238453384543845538456384573845838459384603846138462384633846438465384663846738468384693847038471384723847338474384753847638477384783847938480384813848238483384843848538486384873848838489384903849138492384933849438495384963849738498384993850038501385023850338504385053850638507385083850938510385113851238513385143851538516385173851838519385203852138522385233852438525385263852738528385293853038531385323853338534385353853638537385383853938540385413854238543385443854538546385473854838549385503855138552385533855438555385563855738558385593856038561385623856338564385653856638567385683856938570385713857238573385743857538576385773857838579385803858138582385833858438585385863858738588385893859038591385923859338594385953859638597385983859938600386013860238603386043860538606386073860838609386103861138612386133861438615386163861738618386193862038621386223862338624386253862638627386283862938630386313863238633386343863538636386373863838639386403864138642386433864438645386463864738648386493865038651386523865338654386553865638657386583865938660386613866238663386643866538666386673866838669386703867138672386733867438675386763867738678386793868038681386823868338684386853868638687386883868938690386913869238693386943869538696386973869838699387003870138702387033870438705387063870738708387093871038711387123871338714387153871638717387183871938720387213872238723387243872538726387273872838729387303873138732387333873438735387363873738738387393874038741387423874338744387453874638747387483874938750387513875238753387543875538756387573875838759387603876138762387633876438765387663876738768387693877038771387723877338774387753877638777387783877938780387813878238783387843878538786387873878838789387903879138792387933879438795387963879738798387993880038801388023880338804388053880638807388083880938810388113881238813388143881538816388173881838819388203882138822388233882438825388263882738828388293883038831388323883338834388353883638837388383883938840388413884238843388443884538846388473884838849388503885138852388533885438855388563885738858388593886038861388623886338864388653886638867388683886938870388713887238873388743887538876388773887838879388803888138882388833888438885388863888738888388893889038891388923889338894388953889638897388983889938900389013890238903389043890538906389073890838909389103891138912389133891438915389163891738918389193892038921389223892338924389253892638927389283892938930389313893238933389343893538936389373893838939389403894138942389433894438945389463894738948389493895038951389523895338954389553895638957389583895938960389613896238963389643896538966389673896838969389703897138972389733897438975389763897738978389793898038981389823898338984389853898638987389883898938990389913899238993389943899538996389973899838999390003900139002390033900439005390063900739008390093901039011390123901339014390153901639017390183901939020390213902239023390243902539026390273902839029390303903139032390333903439035390363903739038390393904039041390423904339044390453904639047390483904939050390513905239053390543905539056390573905839059390603906139062390633906439065390663906739068390693907039071390723907339074390753907639077390783907939080390813908239083390843908539086390873908839089390903909139092390933909439095390963909739098390993910039101391023910339104391053910639107391083910939110391113911239113391143911539116391173911839119391203912139122391233912439125391263912739128391293913039131391323913339134391353913639137391383913939140391413914239143391443914539146391473914839149391503915139152391533915439155391563915739158391593916039161391623916339164391653916639167391683916939170391713917239173391743917539176391773917839179391803918139182391833918439185391863918739188391893919039191391923919339194391953919639197391983919939200392013920239203392043920539206392073920839209392103921139212392133921439215392163921739218392193922039221392223922339224392253922639227392283922939230392313923239233392343923539236392373923839239392403924139242392433924439245392463924739248392493925039251392523925339254392553925639257392583925939260392613926239263392643926539266392673926839269392703927139272392733927439275392763927739278392793928039281392823928339284392853928639287392883928939290392913929239293392943929539296392973929839299393003930139302393033930439305393063930739308393093931039311393123931339314393153931639317393183931939320393213932239323393243932539326393273932839329393303933139332393333933439335393363933739338393393934039341393423934339344393453934639347393483934939350393513935239353393543935539356393573935839359393603936139362393633936439365393663936739368393693937039371393723937339374393753937639377393783937939380393813938239383393843938539386393873938839389393903939139392393933939439395393963939739398393993940039401394023940339404394053940639407394083940939410394113941239413394143941539416394173941839419394203942139422394233942439425394263942739428394293943039431394323943339434394353943639437394383943939440394413944239443394443944539446394473944839449394503945139452394533945439455394563945739458394593946039461394623946339464394653946639467394683946939470394713947239473394743947539476394773947839479394803948139482394833948439485394863948739488394893949039491394923949339494394953949639497394983949939500395013950239503395043950539506395073950839509395103951139512395133951439515395163951739518395193952039521395223952339524395253952639527395283952939530395313953239533395343953539536395373953839539395403954139542395433954439545395463954739548395493955039551395523955339554395553955639557395583955939560395613956239563395643956539566395673956839569395703957139572395733957439575395763957739578395793958039581395823958339584395853958639587395883958939590395913959239593395943959539596395973959839599396003960139602396033960439605396063960739608396093961039611396123961339614396153961639617396183961939620396213962239623396243962539626396273962839629396303963139632396333963439635396363963739638396393964039641396423964339644396453964639647396483964939650396513965239653396543965539656396573965839659396603966139662396633966439665396663966739668396693967039671396723967339674396753967639677396783967939680396813968239683396843968539686396873968839689396903969139692396933969439695396963969739698396993970039701397023970339704397053970639707397083970939710397113971239713397143971539716397173971839719397203972139722397233972439725397263972739728397293973039731397323973339734397353973639737397383973939740397413974239743397443974539746397473974839749397503975139752397533975439755397563975739758397593976039761397623976339764397653976639767397683976939770397713977239773397743977539776397773977839779397803978139782397833978439785397863978739788397893979039791397923979339794397953979639797397983979939800398013980239803398043980539806398073980839809398103981139812398133981439815398163981739818398193982039821398223982339824398253982639827398283982939830398313983239833398343983539836398373983839839398403984139842398433984439845398463984739848398493985039851398523985339854398553985639857398583985939860398613986239863398643986539866398673986839869398703987139872398733987439875398763987739878398793988039881398823988339884398853988639887398883988939890398913989239893398943989539896398973989839899399003990139902399033990439905399063990739908399093991039911399123991339914399153991639917399183991939920399213992239923399243992539926399273992839929399303993139932399333993439935399363993739938399393994039941399423994339944399453994639947399483994939950399513995239953399543995539956399573995839959399603996139962399633996439965399663996739968399693997039971399723997339974399753997639977399783997939980399813998239983399843998539986399873998839989399903999139992399933999439995399963999739998399994000040001400024000340004400054000640007400084000940010400114001240013400144001540016400174001840019400204002140022400234002440025400264002740028400294003040031400324003340034400354003640037400384003940040400414004240043400444004540046400474004840049400504005140052400534005440055400564005740058400594006040061400624006340064400654006640067400684006940070400714007240073400744007540076400774007840079400804008140082400834008440085400864008740088400894009040091400924009340094400954009640097400984009940100401014010240103401044010540106401074010840109401104011140112401134011440115401164011740118401194012040121401224012340124401254012640127401284012940130401314013240133401344013540136401374013840139401404014140142401434014440145401464014740148401494015040151401524015340154401554015640157401584015940160401614016240163401644016540166401674016840169401704017140172401734017440175401764017740178401794018040181401824018340184401854018640187401884018940190401914019240193401944019540196401974019840199402004020140202402034020440205402064020740208402094021040211402124021340214402154021640217402184021940220402214022240223402244022540226402274022840229402304023140232402334023440235402364023740238402394024040241402424024340244402454024640247402484024940250402514025240253402544025540256402574025840259402604026140262402634026440265402664026740268402694027040271402724027340274402754027640277402784027940280402814028240283402844028540286402874028840289402904029140292402934029440295402964029740298402994030040301403024030340304403054030640307403084030940310403114031240313403144031540316403174031840319403204032140322403234032440325403264032740328403294033040331403324033340334403354033640337403384033940340403414034240343403444034540346403474034840349403504035140352403534035440355403564035740358403594036040361403624036340364403654036640367403684036940370403714037240373403744037540376403774037840379403804038140382403834038440385403864038740388403894039040391403924039340394403954039640397403984039940400404014040240403404044040540406404074040840409404104041140412404134041440415404164041740418404194042040421404224042340424404254042640427404284042940430404314043240433404344043540436404374043840439404404044140442404434044440445404464044740448404494045040451404524045340454404554045640457404584045940460404614046240463404644046540466404674046840469404704047140472404734047440475404764047740478404794048040481404824048340484404854048640487404884048940490404914049240493404944049540496404974049840499405004050140502405034050440505405064050740508405094051040511405124051340514405154051640517405184051940520405214052240523405244052540526405274052840529405304053140532405334053440535405364053740538405394054040541405424054340544405454054640547405484054940550405514055240553405544055540556405574055840559405604056140562405634056440565405664056740568405694057040571405724057340574405754057640577405784057940580405814058240583405844058540586405874058840589405904059140592405934059440595405964059740598405994060040601406024060340604406054060640607406084060940610406114061240613406144061540616406174061840619406204062140622406234062440625406264062740628406294063040631406324063340634406354063640637406384063940640406414064240643406444064540646406474064840649406504065140652406534065440655406564065740658406594066040661406624066340664406654066640667406684066940670406714067240673406744067540676406774067840679406804068140682406834068440685406864068740688406894069040691406924069340694406954069640697406984069940700407014070240703407044070540706407074070840709407104071140712407134071440715407164071740718407194072040721407224072340724407254072640727407284072940730407314073240733407344073540736407374073840739407404074140742
  1. /*!
  2. * pixi.js - v4.7.3
  3. * Compiled Wed, 04 Apr 2018 15:20:02 UTC
  4. *
  5. * pixi.js is licensed under the MIT License.
  6. * http://www.opensource.org/licenses/mit-license
  7. */
  8. (function (f) { if (typeof exports === "object" && typeof module !== "undefined") { module.exports = f() } else if (typeof define === "function" && define.amd) { define([], f) } else { var g; if (typeof window !== "undefined") { g = window } else if (typeof global !== "undefined") { g = global } else if (typeof self !== "undefined") { g = self } else { g = this } g.PIXI = f() } })(function () {
  9. var define, module, exports; return (function () { function e(t, n, r) { function s(o, u) { if (!n[o]) { if (!t[o]) { var a = typeof require == "function" && require; if (!u && a) return a(o, !0); if (i) return i(o, !0); var f = new Error("Cannot find module '" + o + "'"); throw f.code = "MODULE_NOT_FOUND", f } var l = n[o] = { exports: {} }; t[o][0].call(l.exports, function (e) { var n = t[o][1][e]; return s(n ? n : e) }, l, l.exports, e, t, n, r) } return n[o].exports } var i = typeof require == "function" && require; for (var o = 0; o < r.length; o++)s(r[o]); return s } return e })()({
  10. 1: [function (require, module, exports) {
  11. /**
  12. * Bit twiddling hacks for JavaScript.
  13. *
  14. * Author: Mikola Lysenko
  15. *
  16. * Ported from Stanford bit twiddling hack library:
  17. * http://graphics.stanford.edu/~seander/bithacks.html
  18. */
  19. "use strict"; "use restrict";
  20. //Number of bits in an integer
  21. var INT_BITS = 32;
  22. //Constants
  23. exports.INT_BITS = INT_BITS;
  24. exports.INT_MAX = 0x7fffffff;
  25. exports.INT_MIN = -1 << (INT_BITS - 1);
  26. //Returns -1, 0, +1 depending on sign of x
  27. exports.sign = function (v) {
  28. return (v > 0) - (v < 0);
  29. }
  30. //Computes absolute value of integer
  31. exports.abs = function (v) {
  32. var mask = v >> (INT_BITS - 1);
  33. return (v ^ mask) - mask;
  34. }
  35. //Computes minimum of integers x and y
  36. exports.min = function (x, y) {
  37. return y ^ ((x ^ y) & -(x < y));
  38. }
  39. //Computes maximum of integers x and y
  40. exports.max = function (x, y) {
  41. return x ^ ((x ^ y) & -(x < y));
  42. }
  43. //Checks if a number is a power of two
  44. exports.isPow2 = function (v) {
  45. return !(v & (v - 1)) && (!!v);
  46. }
  47. //Computes log base 2 of v
  48. exports.log2 = function (v) {
  49. var r, shift;
  50. r = (v > 0xFFFF) << 4; v >>>= r;
  51. shift = (v > 0xFF) << 3; v >>>= shift; r |= shift;
  52. shift = (v > 0xF) << 2; v >>>= shift; r |= shift;
  53. shift = (v > 0x3) << 1; v >>>= shift; r |= shift;
  54. return r | (v >> 1);
  55. }
  56. //Computes log base 10 of v
  57. exports.log10 = function (v) {
  58. return (v >= 1000000000) ? 9 : (v >= 100000000) ? 8 : (v >= 10000000) ? 7 :
  59. (v >= 1000000) ? 6 : (v >= 100000) ? 5 : (v >= 10000) ? 4 :
  60. (v >= 1000) ? 3 : (v >= 100) ? 2 : (v >= 10) ? 1 : 0;
  61. }
  62. //Counts number of bits
  63. exports.popCount = function (v) {
  64. v = v - ((v >>> 1) & 0x55555555);
  65. v = (v & 0x33333333) + ((v >>> 2) & 0x33333333);
  66. return ((v + (v >>> 4) & 0xF0F0F0F) * 0x1010101) >>> 24;
  67. }
  68. //Counts number of trailing zeros
  69. function countTrailingZeros(v) {
  70. var c = 32;
  71. v &= -v;
  72. if (v) c--;
  73. if (v & 0x0000FFFF) c -= 16;
  74. if (v & 0x00FF00FF) c -= 8;
  75. if (v & 0x0F0F0F0F) c -= 4;
  76. if (v & 0x33333333) c -= 2;
  77. if (v & 0x55555555) c -= 1;
  78. return c;
  79. }
  80. exports.countTrailingZeros = countTrailingZeros;
  81. //Rounds to next power of 2
  82. exports.nextPow2 = function (v) {
  83. v += v === 0;
  84. --v;
  85. v |= v >>> 1;
  86. v |= v >>> 2;
  87. v |= v >>> 4;
  88. v |= v >>> 8;
  89. v |= v >>> 16;
  90. return v + 1;
  91. }
  92. //Rounds down to previous power of 2
  93. exports.prevPow2 = function (v) {
  94. v |= v >>> 1;
  95. v |= v >>> 2;
  96. v |= v >>> 4;
  97. v |= v >>> 8;
  98. v |= v >>> 16;
  99. return v - (v >>> 1);
  100. }
  101. //Computes parity of word
  102. exports.parity = function (v) {
  103. v ^= v >>> 16;
  104. v ^= v >>> 8;
  105. v ^= v >>> 4;
  106. v &= 0xf;
  107. return (0x6996 >>> v) & 1;
  108. }
  109. var REVERSE_TABLE = new Array(256);
  110. (function (tab) {
  111. for (var i = 0; i < 256; ++i) {
  112. var v = i, r = i, s = 7;
  113. for (v >>>= 1; v; v >>>= 1) {
  114. r <<= 1;
  115. r |= v & 1;
  116. --s;
  117. }
  118. tab[i] = (r << s) & 0xff;
  119. }
  120. })(REVERSE_TABLE);
  121. //Reverse bits in a 32 bit word
  122. exports.reverse = function (v) {
  123. return (REVERSE_TABLE[v & 0xff] << 24) |
  124. (REVERSE_TABLE[(v >>> 8) & 0xff] << 16) |
  125. (REVERSE_TABLE[(v >>> 16) & 0xff] << 8) |
  126. REVERSE_TABLE[(v >>> 24) & 0xff];
  127. }
  128. //Interleave bits of 2 coordinates with 16 bits. Useful for fast quadtree codes
  129. exports.interleave2 = function (x, y) {
  130. x &= 0xFFFF;
  131. x = (x | (x << 8)) & 0x00FF00FF;
  132. x = (x | (x << 4)) & 0x0F0F0F0F;
  133. x = (x | (x << 2)) & 0x33333333;
  134. x = (x | (x << 1)) & 0x55555555;
  135. y &= 0xFFFF;
  136. y = (y | (y << 8)) & 0x00FF00FF;
  137. y = (y | (y << 4)) & 0x0F0F0F0F;
  138. y = (y | (y << 2)) & 0x33333333;
  139. y = (y | (y << 1)) & 0x55555555;
  140. return x | (y << 1);
  141. }
  142. //Extracts the nth interleaved component
  143. exports.deinterleave2 = function (v, n) {
  144. v = (v >>> n) & 0x55555555;
  145. v = (v | (v >>> 1)) & 0x33333333;
  146. v = (v | (v >>> 2)) & 0x0F0F0F0F;
  147. v = (v | (v >>> 4)) & 0x00FF00FF;
  148. v = (v | (v >>> 16)) & 0x000FFFF;
  149. return (v << 16) >> 16;
  150. }
  151. //Interleave bits of 3 coordinates, each with 10 bits. Useful for fast octree codes
  152. exports.interleave3 = function (x, y, z) {
  153. x &= 0x3FF;
  154. x = (x | (x << 16)) & 4278190335;
  155. x = (x | (x << 8)) & 251719695;
  156. x = (x | (x << 4)) & 3272356035;
  157. x = (x | (x << 2)) & 1227133513;
  158. y &= 0x3FF;
  159. y = (y | (y << 16)) & 4278190335;
  160. y = (y | (y << 8)) & 251719695;
  161. y = (y | (y << 4)) & 3272356035;
  162. y = (y | (y << 2)) & 1227133513;
  163. x |= (y << 1);
  164. z &= 0x3FF;
  165. z = (z | (z << 16)) & 4278190335;
  166. z = (z | (z << 8)) & 251719695;
  167. z = (z | (z << 4)) & 3272356035;
  168. z = (z | (z << 2)) & 1227133513;
  169. return x | (z << 2);
  170. }
  171. //Extracts nth interleaved component of a 3-tuple
  172. exports.deinterleave3 = function (v, n) {
  173. v = (v >>> n) & 1227133513;
  174. v = (v | (v >>> 2)) & 3272356035;
  175. v = (v | (v >>> 4)) & 251719695;
  176. v = (v | (v >>> 8)) & 4278190335;
  177. v = (v | (v >>> 16)) & 0x3FF;
  178. return (v << 22) >> 22;
  179. }
  180. //Computes next combination in colexicographic order (this is mistakenly called nextPermutation on the bit twiddling hacks page)
  181. exports.nextCombination = function (v) {
  182. var t = v | (v - 1);
  183. return (t + 1) | (((~t & -~t) - 1) >>> (countTrailingZeros(v) + 1));
  184. }
  185. }, {}], 2: [function (require, module, exports) {
  186. 'use strict';
  187. module.exports = earcut;
  188. module.exports.default = earcut;
  189. function earcut(data, holeIndices, dim) {
  190. dim = dim || 2;
  191. var hasHoles = holeIndices && holeIndices.length,
  192. outerLen = hasHoles ? holeIndices[0] * dim : data.length,
  193. outerNode = linkedList(data, 0, outerLen, dim, true),
  194. triangles = [];
  195. if (!outerNode) return triangles;
  196. var minX, minY, maxX, maxY, x, y, invSize;
  197. if (hasHoles) outerNode = eliminateHoles(data, holeIndices, outerNode, dim);
  198. // if the shape is not too simple, we'll use z-order curve hash later; calculate polygon bbox
  199. if (data.length > 80 * dim) {
  200. minX = maxX = data[0];
  201. minY = maxY = data[1];
  202. for (var i = dim; i < outerLen; i += dim) {
  203. x = data[i];
  204. y = data[i + 1];
  205. if (x < minX) minX = x;
  206. if (y < minY) minY = y;
  207. if (x > maxX) maxX = x;
  208. if (y > maxY) maxY = y;
  209. }
  210. // minX, minY and invSize are later used to transform coords into integers for z-order calculation
  211. invSize = Math.max(maxX - minX, maxY - minY);
  212. invSize = invSize !== 0 ? 1 / invSize : 0;
  213. }
  214. earcutLinked(outerNode, triangles, dim, minX, minY, invSize);
  215. return triangles;
  216. }
  217. // create a circular doubly linked list from polygon points in the specified winding order
  218. function linkedList(data, start, end, dim, clockwise) {
  219. var i, last;
  220. if (clockwise === (signedArea(data, start, end, dim) > 0)) {
  221. for (i = start; i < end; i += dim) last = insertNode(i, data[i], data[i + 1], last);
  222. } else {
  223. for (i = end - dim; i >= start; i -= dim) last = insertNode(i, data[i], data[i + 1], last);
  224. }
  225. if (last && equals(last, last.next)) {
  226. removeNode(last);
  227. last = last.next;
  228. }
  229. return last;
  230. }
  231. // eliminate colinear or duplicate points
  232. function filterPoints(start, end) {
  233. if (!start) return start;
  234. if (!end) end = start;
  235. var p = start,
  236. again;
  237. do {
  238. again = false;
  239. if (!p.steiner && (equals(p, p.next) || area(p.prev, p, p.next) === 0)) {
  240. removeNode(p);
  241. p = end = p.prev;
  242. if (p === p.next) break;
  243. again = true;
  244. } else {
  245. p = p.next;
  246. }
  247. } while (again || p !== end);
  248. return end;
  249. }
  250. // main ear slicing loop which triangulates a polygon (given as a linked list)
  251. function earcutLinked(ear, triangles, dim, minX, minY, invSize, pass) {
  252. if (!ear) return;
  253. // interlink polygon nodes in z-order
  254. if (!pass && invSize) indexCurve(ear, minX, minY, invSize);
  255. var stop = ear,
  256. prev, next;
  257. // iterate through ears, slicing them one by one
  258. while (ear.prev !== ear.next) {
  259. prev = ear.prev;
  260. next = ear.next;
  261. if (invSize ? isEarHashed(ear, minX, minY, invSize) : isEar(ear)) {
  262. // cut off the triangle
  263. triangles.push(prev.i / dim);
  264. triangles.push(ear.i / dim);
  265. triangles.push(next.i / dim);
  266. removeNode(ear);
  267. // skipping the next vertice leads to less sliver triangles
  268. ear = next.next;
  269. stop = next.next;
  270. continue;
  271. }
  272. ear = next;
  273. // if we looped through the whole remaining polygon and can't find any more ears
  274. if (ear === stop) {
  275. // try filtering points and slicing again
  276. if (!pass) {
  277. earcutLinked(filterPoints(ear), triangles, dim, minX, minY, invSize, 1);
  278. // if this didn't work, try curing all small self-intersections locally
  279. } else if (pass === 1) {
  280. ear = cureLocalIntersections(ear, triangles, dim);
  281. earcutLinked(ear, triangles, dim, minX, minY, invSize, 2);
  282. // as a last resort, try splitting the remaining polygon into two
  283. } else if (pass === 2) {
  284. splitEarcut(ear, triangles, dim, minX, minY, invSize);
  285. }
  286. break;
  287. }
  288. }
  289. }
  290. // check whether a polygon node forms a valid ear with adjacent nodes
  291. function isEar(ear) {
  292. var a = ear.prev,
  293. b = ear,
  294. c = ear.next;
  295. if (area(a, b, c) >= 0) return false; // reflex, can't be an ear
  296. // now make sure we don't have other points inside the potential ear
  297. var p = ear.next.next;
  298. while (p !== ear.prev) {
  299. if (pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y) &&
  300. area(p.prev, p, p.next) >= 0) return false;
  301. p = p.next;
  302. }
  303. return true;
  304. }
  305. function isEarHashed(ear, minX, minY, invSize) {
  306. var a = ear.prev,
  307. b = ear,
  308. c = ear.next;
  309. if (area(a, b, c) >= 0) return false; // reflex, can't be an ear
  310. // triangle bbox; min & max are calculated like this for speed
  311. var minTX = a.x < b.x ? (a.x < c.x ? a.x : c.x) : (b.x < c.x ? b.x : c.x),
  312. minTY = a.y < b.y ? (a.y < c.y ? a.y : c.y) : (b.y < c.y ? b.y : c.y),
  313. maxTX = a.x > b.x ? (a.x > c.x ? a.x : c.x) : (b.x > c.x ? b.x : c.x),
  314. maxTY = a.y > b.y ? (a.y > c.y ? a.y : c.y) : (b.y > c.y ? b.y : c.y);
  315. // z-order range for the current triangle bbox;
  316. var minZ = zOrder(minTX, minTY, minX, minY, invSize),
  317. maxZ = zOrder(maxTX, maxTY, minX, minY, invSize);
  318. var p = ear.prevZ,
  319. n = ear.nextZ;
  320. // look for points inside the triangle in both directions
  321. while (p && p.z >= minZ && n && n.z <= maxZ) {
  322. if (p !== ear.prev && p !== ear.next &&
  323. pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y) &&
  324. area(p.prev, p, p.next) >= 0) return false;
  325. p = p.prevZ;
  326. if (n !== ear.prev && n !== ear.next &&
  327. pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, n.x, n.y) &&
  328. area(n.prev, n, n.next) >= 0) return false;
  329. n = n.nextZ;
  330. }
  331. // look for remaining points in decreasing z-order
  332. while (p && p.z >= minZ) {
  333. if (p !== ear.prev && p !== ear.next &&
  334. pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y) &&
  335. area(p.prev, p, p.next) >= 0) return false;
  336. p = p.prevZ;
  337. }
  338. // look for remaining points in increasing z-order
  339. while (n && n.z <= maxZ) {
  340. if (n !== ear.prev && n !== ear.next &&
  341. pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, n.x, n.y) &&
  342. area(n.prev, n, n.next) >= 0) return false;
  343. n = n.nextZ;
  344. }
  345. return true;
  346. }
  347. // go through all polygon nodes and cure small local self-intersections
  348. function cureLocalIntersections(start, triangles, dim) {
  349. var p = start;
  350. do {
  351. var a = p.prev,
  352. b = p.next.next;
  353. if (!equals(a, b) && intersects(a, p, p.next, b) && locallyInside(a, b) && locallyInside(b, a)) {
  354. triangles.push(a.i / dim);
  355. triangles.push(p.i / dim);
  356. triangles.push(b.i / dim);
  357. // remove two nodes involved
  358. removeNode(p);
  359. removeNode(p.next);
  360. p = start = b;
  361. }
  362. p = p.next;
  363. } while (p !== start);
  364. return p;
  365. }
  366. // try splitting polygon into two and triangulate them independently
  367. function splitEarcut(start, triangles, dim, minX, minY, invSize) {
  368. // look for a valid diagonal that divides the polygon into two
  369. var a = start;
  370. do {
  371. var b = a.next.next;
  372. while (b !== a.prev) {
  373. if (a.i !== b.i && isValidDiagonal(a, b)) {
  374. // split the polygon in two by the diagonal
  375. var c = splitPolygon(a, b);
  376. // filter colinear points around the cuts
  377. a = filterPoints(a, a.next);
  378. c = filterPoints(c, c.next);
  379. // run earcut on each half
  380. earcutLinked(a, triangles, dim, minX, minY, invSize);
  381. earcutLinked(c, triangles, dim, minX, minY, invSize);
  382. return;
  383. }
  384. b = b.next;
  385. }
  386. a = a.next;
  387. } while (a !== start);
  388. }
  389. // link every hole into the outer loop, producing a single-ring polygon without holes
  390. function eliminateHoles(data, holeIndices, outerNode, dim) {
  391. var queue = [],
  392. i, len, start, end, list;
  393. for (i = 0, len = holeIndices.length; i < len; i++) {
  394. start = holeIndices[i] * dim;
  395. end = i < len - 1 ? holeIndices[i + 1] * dim : data.length;
  396. list = linkedList(data, start, end, dim, false);
  397. if (list === list.next) list.steiner = true;
  398. queue.push(getLeftmost(list));
  399. }
  400. queue.sort(compareX);
  401. // process holes from left to right
  402. for (i = 0; i < queue.length; i++) {
  403. eliminateHole(queue[i], outerNode);
  404. outerNode = filterPoints(outerNode, outerNode.next);
  405. }
  406. return outerNode;
  407. }
  408. function compareX(a, b) {
  409. return a.x - b.x;
  410. }
  411. // find a bridge between vertices that connects hole with an outer ring and and link it
  412. function eliminateHole(hole, outerNode) {
  413. outerNode = findHoleBridge(hole, outerNode);
  414. if (outerNode) {
  415. var b = splitPolygon(outerNode, hole);
  416. filterPoints(b, b.next);
  417. }
  418. }
  419. // David Eberly's algorithm for finding a bridge between hole and outer polygon
  420. function findHoleBridge(hole, outerNode) {
  421. var p = outerNode,
  422. hx = hole.x,
  423. hy = hole.y,
  424. qx = -Infinity,
  425. m;
  426. // find a segment intersected by a ray from the hole's leftmost point to the left;
  427. // segment's endpoint with lesser x will be potential connection point
  428. do {
  429. if (hy <= p.y && hy >= p.next.y && p.next.y !== p.y) {
  430. var x = p.x + (hy - p.y) * (p.next.x - p.x) / (p.next.y - p.y);
  431. if (x <= hx && x > qx) {
  432. qx = x;
  433. if (x === hx) {
  434. if (hy === p.y) return p;
  435. if (hy === p.next.y) return p.next;
  436. }
  437. m = p.x < p.next.x ? p : p.next;
  438. }
  439. }
  440. p = p.next;
  441. } while (p !== outerNode);
  442. if (!m) return null;
  443. if (hx === qx) return m.prev; // hole touches outer segment; pick lower endpoint
  444. // look for points inside the triangle of hole point, segment intersection and endpoint;
  445. // if there are no points found, we have a valid connection;
  446. // otherwise choose the point of the minimum angle with the ray as connection point
  447. var stop = m,
  448. mx = m.x,
  449. my = m.y,
  450. tanMin = Infinity,
  451. tan;
  452. p = m.next;
  453. while (p !== stop) {
  454. if (hx >= p.x && p.x >= mx && hx !== p.x &&
  455. pointInTriangle(hy < my ? hx : qx, hy, mx, my, hy < my ? qx : hx, hy, p.x, p.y)) {
  456. tan = Math.abs(hy - p.y) / (hx - p.x); // tangential
  457. if ((tan < tanMin || (tan === tanMin && p.x > m.x)) && locallyInside(p, hole)) {
  458. m = p;
  459. tanMin = tan;
  460. }
  461. }
  462. p = p.next;
  463. }
  464. return m;
  465. }
  466. // interlink polygon nodes in z-order
  467. function indexCurve(start, minX, minY, invSize) {
  468. var p = start;
  469. do {
  470. if (p.z === null) p.z = zOrder(p.x, p.y, minX, minY, invSize);
  471. p.prevZ = p.prev;
  472. p.nextZ = p.next;
  473. p = p.next;
  474. } while (p !== start);
  475. p.prevZ.nextZ = null;
  476. p.prevZ = null;
  477. sortLinked(p);
  478. }
  479. // Simon Tatham's linked list merge sort algorithm
  480. // http://www.chiark.greenend.org.uk/~sgtatham/algorithms/listsort.html
  481. function sortLinked(list) {
  482. var i, p, q, e, tail, numMerges, pSize, qSize,
  483. inSize = 1;
  484. do {
  485. p = list;
  486. list = null;
  487. tail = null;
  488. numMerges = 0;
  489. while (p) {
  490. numMerges++;
  491. q = p;
  492. pSize = 0;
  493. for (i = 0; i < inSize; i++) {
  494. pSize++;
  495. q = q.nextZ;
  496. if (!q) break;
  497. }
  498. qSize = inSize;
  499. while (pSize > 0 || (qSize > 0 && q)) {
  500. if (pSize !== 0 && (qSize === 0 || !q || p.z <= q.z)) {
  501. e = p;
  502. p = p.nextZ;
  503. pSize--;
  504. } else {
  505. e = q;
  506. q = q.nextZ;
  507. qSize--;
  508. }
  509. if (tail) tail.nextZ = e;
  510. else list = e;
  511. e.prevZ = tail;
  512. tail = e;
  513. }
  514. p = q;
  515. }
  516. tail.nextZ = null;
  517. inSize *= 2;
  518. } while (numMerges > 1);
  519. return list;
  520. }
  521. // z-order of a point given coords and inverse of the longer side of data bbox
  522. function zOrder(x, y, minX, minY, invSize) {
  523. // coords are transformed into non-negative 15-bit integer range
  524. x = 32767 * (x - minX) * invSize;
  525. y = 32767 * (y - minY) * invSize;
  526. x = (x | (x << 8)) & 0x00FF00FF;
  527. x = (x | (x << 4)) & 0x0F0F0F0F;
  528. x = (x | (x << 2)) & 0x33333333;
  529. x = (x | (x << 1)) & 0x55555555;
  530. y = (y | (y << 8)) & 0x00FF00FF;
  531. y = (y | (y << 4)) & 0x0F0F0F0F;
  532. y = (y | (y << 2)) & 0x33333333;
  533. y = (y | (y << 1)) & 0x55555555;
  534. return x | (y << 1);
  535. }
  536. // find the leftmost node of a polygon ring
  537. function getLeftmost(start) {
  538. var p = start,
  539. leftmost = start;
  540. do {
  541. if (p.x < leftmost.x) leftmost = p;
  542. p = p.next;
  543. } while (p !== start);
  544. return leftmost;
  545. }
  546. // check if a point lies within a convex triangle
  547. function pointInTriangle(ax, ay, bx, by, cx, cy, px, py) {
  548. return (cx - px) * (ay - py) - (ax - px) * (cy - py) >= 0 &&
  549. (ax - px) * (by - py) - (bx - px) * (ay - py) >= 0 &&
  550. (bx - px) * (cy - py) - (cx - px) * (by - py) >= 0;
  551. }
  552. // check if a diagonal between two polygon nodes is valid (lies in polygon interior)
  553. function isValidDiagonal(a, b) {
  554. return a.next.i !== b.i && a.prev.i !== b.i && !intersectsPolygon(a, b) &&
  555. locallyInside(a, b) && locallyInside(b, a) && middleInside(a, b);
  556. }
  557. // signed area of a triangle
  558. function area(p, q, r) {
  559. return (q.y - p.y) * (r.x - q.x) - (q.x - p.x) * (r.y - q.y);
  560. }
  561. // check if two points are equal
  562. function equals(p1, p2) {
  563. return p1.x === p2.x && p1.y === p2.y;
  564. }
  565. // check if two segments intersect
  566. function intersects(p1, q1, p2, q2) {
  567. if ((equals(p1, q1) && equals(p2, q2)) ||
  568. (equals(p1, q2) && equals(p2, q1))) return true;
  569. return area(p1, q1, p2) > 0 !== area(p1, q1, q2) > 0 &&
  570. area(p2, q2, p1) > 0 !== area(p2, q2, q1) > 0;
  571. }
  572. // check if a polygon diagonal intersects any polygon segments
  573. function intersectsPolygon(a, b) {
  574. var p = a;
  575. do {
  576. if (p.i !== a.i && p.next.i !== a.i && p.i !== b.i && p.next.i !== b.i &&
  577. intersects(p, p.next, a, b)) return true;
  578. p = p.next;
  579. } while (p !== a);
  580. return false;
  581. }
  582. // check if a polygon diagonal is locally inside the polygon
  583. function locallyInside(a, b) {
  584. return area(a.prev, a, a.next) < 0 ?
  585. area(a, b, a.next) >= 0 && area(a, a.prev, b) >= 0 :
  586. area(a, b, a.prev) < 0 || area(a, a.next, b) < 0;
  587. }
  588. // check if the middle point of a polygon diagonal is inside the polygon
  589. function middleInside(a, b) {
  590. var p = a,
  591. inside = false,
  592. px = (a.x + b.x) / 2,
  593. py = (a.y + b.y) / 2;
  594. do {
  595. if (((p.y > py) !== (p.next.y > py)) && p.next.y !== p.y &&
  596. (px < (p.next.x - p.x) * (py - p.y) / (p.next.y - p.y) + p.x))
  597. inside = !inside;
  598. p = p.next;
  599. } while (p !== a);
  600. return inside;
  601. }
  602. // link two polygon vertices with a bridge; if the vertices belong to the same ring, it splits polygon into two;
  603. // if one belongs to the outer ring and another to a hole, it merges it into a single ring
  604. function splitPolygon(a, b) {
  605. var a2 = new Node(a.i, a.x, a.y),
  606. b2 = new Node(b.i, b.x, b.y),
  607. an = a.next,
  608. bp = b.prev;
  609. a.next = b;
  610. b.prev = a;
  611. a2.next = an;
  612. an.prev = a2;
  613. b2.next = a2;
  614. a2.prev = b2;
  615. bp.next = b2;
  616. b2.prev = bp;
  617. return b2;
  618. }
  619. // create a node and optionally link it with previous one (in a circular doubly linked list)
  620. function insertNode(i, x, y, last) {
  621. var p = new Node(i, x, y);
  622. if (!last) {
  623. p.prev = p;
  624. p.next = p;
  625. } else {
  626. p.next = last.next;
  627. p.prev = last;
  628. last.next.prev = p;
  629. last.next = p;
  630. }
  631. return p;
  632. }
  633. function removeNode(p) {
  634. p.next.prev = p.prev;
  635. p.prev.next = p.next;
  636. if (p.prevZ) p.prevZ.nextZ = p.nextZ;
  637. if (p.nextZ) p.nextZ.prevZ = p.prevZ;
  638. }
  639. function Node(i, x, y) {
  640. // vertice index in coordinates array
  641. this.i = i;
  642. // vertex coordinates
  643. this.x = x;
  644. this.y = y;
  645. // previous and next vertice nodes in a polygon ring
  646. this.prev = null;
  647. this.next = null;
  648. // z-order curve value
  649. this.z = null;
  650. // previous and next nodes in z-order
  651. this.prevZ = null;
  652. this.nextZ = null;
  653. // indicates whether this is a steiner point
  654. this.steiner = false;
  655. }
  656. // return a percentage difference between the polygon area and its triangulation area;
  657. // used to verify correctness of triangulation
  658. earcut.deviation = function (data, holeIndices, dim, triangles) {
  659. var hasHoles = holeIndices && holeIndices.length;
  660. var outerLen = hasHoles ? holeIndices[0] * dim : data.length;
  661. var polygonArea = Math.abs(signedArea(data, 0, outerLen, dim));
  662. if (hasHoles) {
  663. for (var i = 0, len = holeIndices.length; i < len; i++) {
  664. var start = holeIndices[i] * dim;
  665. var end = i < len - 1 ? holeIndices[i + 1] * dim : data.length;
  666. polygonArea -= Math.abs(signedArea(data, start, end, dim));
  667. }
  668. }
  669. var trianglesArea = 0;
  670. for (i = 0; i < triangles.length; i += 3) {
  671. var a = triangles[i] * dim;
  672. var b = triangles[i + 1] * dim;
  673. var c = triangles[i + 2] * dim;
  674. trianglesArea += Math.abs(
  675. (data[a] - data[c]) * (data[b + 1] - data[a + 1]) -
  676. (data[a] - data[b]) * (data[c + 1] - data[a + 1]));
  677. }
  678. return polygonArea === 0 && trianglesArea === 0 ? 0 :
  679. Math.abs((trianglesArea - polygonArea) / polygonArea);
  680. };
  681. function signedArea(data, start, end, dim) {
  682. var sum = 0;
  683. for (var i = start, j = end - dim; i < end; i += dim) {
  684. sum += (data[j] - data[i]) * (data[i + 1] + data[j + 1]);
  685. j = i;
  686. }
  687. return sum;
  688. }
  689. // turn a polygon in a multi-dimensional array form (e.g. as in GeoJSON) into a form Earcut accepts
  690. earcut.flatten = function (data) {
  691. var dim = data[0][0].length,
  692. result = { vertices: [], holes: [], dimensions: dim },
  693. holeIndex = 0;
  694. for (var i = 0; i < data.length; i++) {
  695. for (var j = 0; j < data[i].length; j++) {
  696. for (var d = 0; d < dim; d++) result.vertices.push(data[i][j][d]);
  697. }
  698. if (i > 0) {
  699. holeIndex += data[i - 1].length;
  700. result.holes.push(holeIndex);
  701. }
  702. }
  703. return result;
  704. };
  705. }, {}], 3: [function (require, module, exports) {
  706. 'use strict';
  707. var has = Object.prototype.hasOwnProperty
  708. , prefix = '~';
  709. /**
  710. * Constructor to create a storage for our `EE` objects.
  711. * An `Events` instance is a plain object whose properties are event names.
  712. *
  713. * @constructor
  714. * @api private
  715. */
  716. function Events() { }
  717. //
  718. // We try to not inherit from `Object.prototype`. In some engines creating an
  719. // instance in this way is faster than calling `Object.create(null)` directly.
  720. // If `Object.create(null)` is not supported we prefix the event names with a
  721. // character to make sure that the built-in object properties are not
  722. // overridden or used as an attack vector.
  723. //
  724. if (Object.create) {
  725. Events.prototype = Object.create(null);
  726. //
  727. // This hack is needed because the `__proto__` property is still inherited in
  728. // some old browsers like Android 4, iPhone 5.1, Opera 11 and Safari 5.
  729. //
  730. if (!new Events().__proto__) prefix = false;
  731. }
  732. /**
  733. * Representation of a single event listener.
  734. *
  735. * @param {Function} fn The listener function.
  736. * @param {Mixed} context The context to invoke the listener with.
  737. * @param {Boolean} [once=false] Specify if the listener is a one-time listener.
  738. * @constructor
  739. * @api private
  740. */
  741. function EE(fn, context, once) {
  742. this.fn = fn;
  743. this.context = context;
  744. this.once = once || false;
  745. }
  746. /**
  747. * Minimal `EventEmitter` interface that is molded against the Node.js
  748. * `EventEmitter` interface.
  749. *
  750. * @constructor
  751. * @api public
  752. */
  753. function EventEmitter() {
  754. this._events = new Events();
  755. this._eventsCount = 0;
  756. }
  757. /**
  758. * Return an array listing the events for which the emitter has registered
  759. * listeners.
  760. *
  761. * @returns {Array}
  762. * @api public
  763. */
  764. EventEmitter.prototype.eventNames = function eventNames() {
  765. var names = []
  766. , events
  767. , name;
  768. if (this._eventsCount === 0) return names;
  769. for (name in (events = this._events)) {
  770. if (has.call(events, name)) names.push(prefix ? name.slice(1) : name);
  771. }
  772. if (Object.getOwnPropertySymbols) {
  773. return names.concat(Object.getOwnPropertySymbols(events));
  774. }
  775. return names;
  776. };
  777. /**
  778. * Return the listeners registered for a given event.
  779. *
  780. * @param {String|Symbol} event The event name.
  781. * @param {Boolean} exists Only check if there are listeners.
  782. * @returns {Array|Boolean}
  783. * @api public
  784. */
  785. EventEmitter.prototype.listeners = function listeners(event, exists) {
  786. var evt = prefix ? prefix + event : event
  787. , available = this._events[evt];
  788. if (exists) return !!available;
  789. if (!available) return [];
  790. if (available.fn) return [available.fn];
  791. for (var i = 0, l = available.length, ee = new Array(l); i < l; i++) {
  792. ee[i] = available[i].fn;
  793. }
  794. return ee;
  795. };
  796. /**
  797. * Calls each of the listeners registered for a given event.
  798. *
  799. * @param {String|Symbol} event The event name.
  800. * @returns {Boolean} `true` if the event had listeners, else `false`.
  801. * @api public
  802. */
  803. EventEmitter.prototype.emit = function emit(event, a1, a2, a3, a4, a5) {
  804. var evt = prefix ? prefix + event : event;
  805. if (!this._events[evt]) return false;
  806. var listeners = this._events[evt]
  807. , len = arguments.length
  808. , args
  809. , i;
  810. if (listeners.fn) {
  811. if (listeners.once) this.removeListener(event, listeners.fn, undefined, true);
  812. switch (len) {
  813. case 1: return listeners.fn.call(listeners.context), true;
  814. case 2: return listeners.fn.call(listeners.context, a1), true;
  815. case 3: return listeners.fn.call(listeners.context, a1, a2), true;
  816. case 4: return listeners.fn.call(listeners.context, a1, a2, a3), true;
  817. case 5: return listeners.fn.call(listeners.context, a1, a2, a3, a4), true;
  818. case 6: return listeners.fn.call(listeners.context, a1, a2, a3, a4, a5), true;
  819. }
  820. for (i = 1, args = new Array(len - 1); i < len; i++) {
  821. args[i - 1] = arguments[i];
  822. }
  823. listeners.fn.apply(listeners.context, args);
  824. } else {
  825. var length = listeners.length
  826. , j;
  827. for (i = 0; i < length; i++) {
  828. if (listeners[i].once) this.removeListener(event, listeners[i].fn, undefined, true);
  829. switch (len) {
  830. case 1: listeners[i].fn.call(listeners[i].context); break;
  831. case 2: listeners[i].fn.call(listeners[i].context, a1); break;
  832. case 3: listeners[i].fn.call(listeners[i].context, a1, a2); break;
  833. case 4: listeners[i].fn.call(listeners[i].context, a1, a2, a3); break;
  834. default:
  835. if (!args) for (j = 1, args = new Array(len - 1); j < len; j++) {
  836. args[j - 1] = arguments[j];
  837. }
  838. listeners[i].fn.apply(listeners[i].context, args);
  839. }
  840. }
  841. }
  842. return true;
  843. };
  844. /**
  845. * Add a listener for a given event.
  846. *
  847. * @param {String|Symbol} event The event name.
  848. * @param {Function} fn The listener function.
  849. * @param {Mixed} [context=this] The context to invoke the listener with.
  850. * @returns {EventEmitter} `this`.
  851. * @api public
  852. */
  853. EventEmitter.prototype.on = function on(event, fn, context) {
  854. var listener = new EE(fn, context || this)
  855. , evt = prefix ? prefix + event : event;
  856. if (!this._events[evt]) this._events[evt] = listener, this._eventsCount++;
  857. else if (!this._events[evt].fn) this._events[evt].push(listener);
  858. else this._events[evt] = [this._events[evt], listener];
  859. return this;
  860. };
  861. /**
  862. * Add a one-time listener for a given event.
  863. *
  864. * @param {String|Symbol} event The event name.
  865. * @param {Function} fn The listener function.
  866. * @param {Mixed} [context=this] The context to invoke the listener with.
  867. * @returns {EventEmitter} `this`.
  868. * @api public
  869. */
  870. EventEmitter.prototype.once = function once(event, fn, context) {
  871. var listener = new EE(fn, context || this, true)
  872. , evt = prefix ? prefix + event : event;
  873. if (!this._events[evt]) this._events[evt] = listener, this._eventsCount++;
  874. else if (!this._events[evt].fn) this._events[evt].push(listener);
  875. else this._events[evt] = [this._events[evt], listener];
  876. return this;
  877. };
  878. /**
  879. * Remove the listeners of a given event.
  880. *
  881. * @param {String|Symbol} event The event name.
  882. * @param {Function} fn Only remove the listeners that match this function.
  883. * @param {Mixed} context Only remove the listeners that have this context.
  884. * @param {Boolean} once Only remove one-time listeners.
  885. * @returns {EventEmitter} `this`.
  886. * @api public
  887. */
  888. EventEmitter.prototype.removeListener = function removeListener(event, fn, context, once) {
  889. var evt = prefix ? prefix + event : event;
  890. if (!this._events[evt]) return this;
  891. if (!fn) {
  892. if (--this._eventsCount === 0) this._events = new Events();
  893. else delete this._events[evt];
  894. return this;
  895. }
  896. var listeners = this._events[evt];
  897. if (listeners.fn) {
  898. if (
  899. listeners.fn === fn
  900. && (!once || listeners.once)
  901. && (!context || listeners.context === context)
  902. ) {
  903. if (--this._eventsCount === 0) this._events = new Events();
  904. else delete this._events[evt];
  905. }
  906. } else {
  907. for (var i = 0, events = [], length = listeners.length; i < length; i++) {
  908. if (
  909. listeners[i].fn !== fn
  910. || (once && !listeners[i].once)
  911. || (context && listeners[i].context !== context)
  912. ) {
  913. events.push(listeners[i]);
  914. }
  915. }
  916. //
  917. // Reset the array, or remove it completely if we have no more listeners.
  918. //
  919. if (events.length) this._events[evt] = events.length === 1 ? events[0] : events;
  920. else if (--this._eventsCount === 0) this._events = new Events();
  921. else delete this._events[evt];
  922. }
  923. return this;
  924. };
  925. /**
  926. * Remove all listeners, or those of the specified event.
  927. *
  928. * @param {String|Symbol} [event] The event name.
  929. * @returns {EventEmitter} `this`.
  930. * @api public
  931. */
  932. EventEmitter.prototype.removeAllListeners = function removeAllListeners(event) {
  933. var evt;
  934. if (event) {
  935. evt = prefix ? prefix + event : event;
  936. if (this._events[evt]) {
  937. if (--this._eventsCount === 0) this._events = new Events();
  938. else delete this._events[evt];
  939. }
  940. } else {
  941. this._events = new Events();
  942. this._eventsCount = 0;
  943. }
  944. return this;
  945. };
  946. //
  947. // Alias methods names because people roll like that.
  948. //
  949. EventEmitter.prototype.off = EventEmitter.prototype.removeListener;
  950. EventEmitter.prototype.addListener = EventEmitter.prototype.on;
  951. //
  952. // This function doesn't apply anymore.
  953. //
  954. EventEmitter.prototype.setMaxListeners = function setMaxListeners() {
  955. return this;
  956. };
  957. //
  958. // Expose the prefix.
  959. //
  960. EventEmitter.prefixed = prefix;
  961. //
  962. // Allow `EventEmitter` to be imported as module namespace.
  963. //
  964. EventEmitter.EventEmitter = EventEmitter;
  965. //
  966. // Expose the module.
  967. //
  968. if ('undefined' !== typeof module) {
  969. module.exports = EventEmitter;
  970. }
  971. }, {}], 4: [function (require, module, exports) {
  972. /**
  973. * isMobile.js v0.4.1
  974. *
  975. * A simple library to detect Apple phones and tablets,
  976. * Android phones and tablets, other mobile devices (like blackberry, mini-opera and windows phone),
  977. * and any kind of seven inch device, via user agent sniffing.
  978. *
  979. * @author: Kai Mallea (kmallea@gmail.com)
  980. *
  981. * @license: http://creativecommons.org/publicdomain/zero/1.0/
  982. */
  983. (function (global) {
  984. var apple_phone = /iPhone/i,
  985. apple_ipod = /iPod/i,
  986. apple_tablet = /iPad/i,
  987. android_phone = /(?=.*\bAndroid\b)(?=.*\bMobile\b)/i, // Match 'Android' AND 'Mobile'
  988. android_tablet = /Android/i,
  989. amazon_phone = /(?=.*\bAndroid\b)(?=.*\bSD4930UR\b)/i,
  990. amazon_tablet = /(?=.*\bAndroid\b)(?=.*\b(?:KFOT|KFTT|KFJWI|KFJWA|KFSOWI|KFTHWI|KFTHWA|KFAPWI|KFAPWA|KFARWI|KFASWI|KFSAWI|KFSAWA)\b)/i,
  991. windows_phone = /Windows Phone/i,
  992. windows_tablet = /(?=.*\bWindows\b)(?=.*\bARM\b)/i, // Match 'Windows' AND 'ARM'
  993. other_blackberry = /BlackBerry/i,
  994. other_blackberry_10 = /BB10/i,
  995. other_opera = /Opera Mini/i,
  996. other_chrome = /(CriOS|Chrome)(?=.*\bMobile\b)/i,
  997. other_firefox = /(?=.*\bFirefox\b)(?=.*\bMobile\b)/i, // Match 'Firefox' AND 'Mobile'
  998. seven_inch = new RegExp(
  999. '(?:' + // Non-capturing group
  1000. 'Nexus 7' + // Nexus 7
  1001. '|' + // OR
  1002. 'BNTV250' + // B&N Nook Tablet 7 inch
  1003. '|' + // OR
  1004. 'Kindle Fire' + // Kindle Fire
  1005. '|' + // OR
  1006. 'Silk' + // Kindle Fire, Silk Accelerated
  1007. '|' + // OR
  1008. 'GT-P1000' + // Galaxy Tab 7 inch
  1009. ')', // End non-capturing group
  1010. 'i'); // Case-insensitive matching
  1011. var match = function (regex, userAgent) {
  1012. return regex.test(userAgent);
  1013. };
  1014. var IsMobileClass = function (userAgent) {
  1015. var ua = userAgent || navigator.userAgent;
  1016. // Facebook mobile app's integrated browser adds a bunch of strings that
  1017. // match everything. Strip it out if it exists.
  1018. var tmp = ua.split('[FBAN');
  1019. if (typeof tmp[1] !== 'undefined') {
  1020. ua = tmp[0];
  1021. }
  1022. // Twitter mobile app's integrated browser on iPad adds a "Twitter for
  1023. // iPhone" string. Same probable happens on other tablet platforms.
  1024. // This will confuse detection so strip it out if it exists.
  1025. tmp = ua.split('Twitter');
  1026. if (typeof tmp[1] !== 'undefined') {
  1027. ua = tmp[0];
  1028. }
  1029. this.apple = {
  1030. phone: match(apple_phone, ua),
  1031. ipod: match(apple_ipod, ua),
  1032. tablet: !match(apple_phone, ua) && match(apple_tablet, ua),
  1033. device: match(apple_phone, ua) || match(apple_ipod, ua) || match(apple_tablet, ua)
  1034. };
  1035. this.amazon = {
  1036. phone: match(amazon_phone, ua),
  1037. tablet: !match(amazon_phone, ua) && match(amazon_tablet, ua),
  1038. device: match(amazon_phone, ua) || match(amazon_tablet, ua)
  1039. };
  1040. this.android = {
  1041. phone: match(amazon_phone, ua) || match(android_phone, ua),
  1042. tablet: !match(amazon_phone, ua) && !match(android_phone, ua) && (match(amazon_tablet, ua) || match(android_tablet, ua)),
  1043. device: match(amazon_phone, ua) || match(amazon_tablet, ua) || match(android_phone, ua) || match(android_tablet, ua)
  1044. };
  1045. this.windows = {
  1046. phone: match(windows_phone, ua),
  1047. tablet: match(windows_tablet, ua),
  1048. device: match(windows_phone, ua) || match(windows_tablet, ua)
  1049. };
  1050. this.other = {
  1051. blackberry: match(other_blackberry, ua),
  1052. blackberry10: match(other_blackberry_10, ua),
  1053. opera: match(other_opera, ua),
  1054. firefox: match(other_firefox, ua),
  1055. chrome: match(other_chrome, ua),
  1056. device: match(other_blackberry, ua) || match(other_blackberry_10, ua) || match(other_opera, ua) || match(other_firefox, ua) || match(other_chrome, ua)
  1057. };
  1058. this.seven_inch = match(seven_inch, ua);
  1059. this.any = this.apple.device || this.android.device || this.windows.device || this.other.device || this.seven_inch;
  1060. // excludes 'other' devices and ipods, targeting touchscreen phones
  1061. this.phone = this.apple.phone || this.android.phone || this.windows.phone;
  1062. // excludes 7 inch devices, classifying as phone or tablet is left to the user
  1063. this.tablet = this.apple.tablet || this.android.tablet || this.windows.tablet;
  1064. if (typeof window === 'undefined') {
  1065. return this;
  1066. }
  1067. };
  1068. var instantiate = function () {
  1069. var IM = new IsMobileClass();
  1070. IM.Class = IsMobileClass;
  1071. return IM;
  1072. };
  1073. if (typeof module !== 'undefined' && module.exports && typeof window === 'undefined') {
  1074. //node
  1075. module.exports = IsMobileClass;
  1076. } else if (typeof module !== 'undefined' && module.exports && typeof window !== 'undefined') {
  1077. //browserify
  1078. module.exports = instantiate();
  1079. } else if (typeof define === 'function' && define.amd) {
  1080. //AMD
  1081. define('isMobile', [], global.isMobile = instantiate());
  1082. } else {
  1083. global.isMobile = instantiate();
  1084. }
  1085. })(this);
  1086. }, {}], 5: [function (require, module, exports) {
  1087. 'use strict';
  1088. Object.defineProperty(exports, '__esModule', {
  1089. value: true
  1090. });
  1091. var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
  1092. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
  1093. var MiniSignalBinding = (function () {
  1094. function MiniSignalBinding(fn, once, thisArg) {
  1095. if (once === undefined) once = false;
  1096. _classCallCheck(this, MiniSignalBinding);
  1097. this._fn = fn;
  1098. this._once = once;
  1099. this._thisArg = thisArg;
  1100. this._next = this._prev = this._owner = null;
  1101. }
  1102. _createClass(MiniSignalBinding, [{
  1103. key: 'detach',
  1104. value: function detach() {
  1105. if (this._owner === null) return false;
  1106. this._owner.detach(this);
  1107. return true;
  1108. }
  1109. }]);
  1110. return MiniSignalBinding;
  1111. })();
  1112. function _addMiniSignalBinding(self, node) {
  1113. if (!self._head) {
  1114. self._head = node;
  1115. self._tail = node;
  1116. } else {
  1117. self._tail._next = node;
  1118. node._prev = self._tail;
  1119. self._tail = node;
  1120. }
  1121. node._owner = self;
  1122. return node;
  1123. }
  1124. var MiniSignal = (function () {
  1125. function MiniSignal() {
  1126. _classCallCheck(this, MiniSignal);
  1127. this._head = this._tail = undefined;
  1128. }
  1129. _createClass(MiniSignal, [{
  1130. key: 'handlers',
  1131. value: function handlers() {
  1132. var exists = arguments.length <= 0 || arguments[0] === undefined ? false : arguments[0];
  1133. var node = this._head;
  1134. if (exists) return !!node;
  1135. var ee = [];
  1136. while (node) {
  1137. ee.push(node);
  1138. node = node._next;
  1139. }
  1140. return ee;
  1141. }
  1142. }, {
  1143. key: 'has',
  1144. value: function has(node) {
  1145. if (!(node instanceof MiniSignalBinding)) {
  1146. throw new Error('MiniSignal#has(): First arg must be a MiniSignalBinding object.');
  1147. }
  1148. return node._owner === this;
  1149. }
  1150. }, {
  1151. key: 'dispatch',
  1152. value: function dispatch() {
  1153. var node = this._head;
  1154. if (!node) return false;
  1155. while (node) {
  1156. if (node._once) this.detach(node);
  1157. node._fn.apply(node._thisArg, arguments);
  1158. node = node._next;
  1159. }
  1160. return true;
  1161. }
  1162. }, {
  1163. key: 'add',
  1164. value: function add(fn) {
  1165. var thisArg = arguments.length <= 1 || arguments[1] === undefined ? null : arguments[1];
  1166. if (typeof fn !== 'function') {
  1167. throw new Error('MiniSignal#add(): First arg must be a Function.');
  1168. }
  1169. return _addMiniSignalBinding(this, new MiniSignalBinding(fn, false, thisArg));
  1170. }
  1171. }, {
  1172. key: 'once',
  1173. value: function once(fn) {
  1174. var thisArg = arguments.length <= 1 || arguments[1] === undefined ? null : arguments[1];
  1175. if (typeof fn !== 'function') {
  1176. throw new Error('MiniSignal#once(): First arg must be a Function.');
  1177. }
  1178. return _addMiniSignalBinding(this, new MiniSignalBinding(fn, true, thisArg));
  1179. }
  1180. }, {
  1181. key: 'detach',
  1182. value: function detach(node) {
  1183. if (!(node instanceof MiniSignalBinding)) {
  1184. throw new Error('MiniSignal#detach(): First arg must be a MiniSignalBinding object.');
  1185. }
  1186. if (node._owner !== this) return this;
  1187. if (node._prev) node._prev._next = node._next;
  1188. if (node._next) node._next._prev = node._prev;
  1189. if (node === this._head) {
  1190. this._head = node._next;
  1191. if (node._next === null) {
  1192. this._tail = null;
  1193. }
  1194. } else if (node === this._tail) {
  1195. this._tail = node._prev;
  1196. this._tail._next = null;
  1197. }
  1198. node._owner = null;
  1199. return this;
  1200. }
  1201. }, {
  1202. key: 'detachAll',
  1203. value: function detachAll() {
  1204. var node = this._head;
  1205. if (!node) return this;
  1206. this._head = this._tail = null;
  1207. while (node) {
  1208. node._owner = null;
  1209. node = node._next;
  1210. }
  1211. return this;
  1212. }
  1213. }]);
  1214. return MiniSignal;
  1215. })();
  1216. MiniSignal.MiniSignalBinding = MiniSignalBinding;
  1217. exports['default'] = MiniSignal;
  1218. module.exports = exports['default'];
  1219. }, {}], 6: [function (require, module, exports) {
  1220. /*
  1221. object-assign
  1222. (c) Sindre Sorhus
  1223. @license MIT
  1224. */
  1225. 'use strict';
  1226. /* eslint-disable no-unused-vars */
  1227. var getOwnPropertySymbols = Object.getOwnPropertySymbols;
  1228. var hasOwnProperty = Object.prototype.hasOwnProperty;
  1229. var propIsEnumerable = Object.prototype.propertyIsEnumerable;
  1230. function toObject(val) {
  1231. if (val === null || val === undefined) {
  1232. throw new TypeError('Object.assign cannot be called with null or undefined');
  1233. }
  1234. return Object(val);
  1235. }
  1236. function shouldUseNative() {
  1237. try {
  1238. if (!Object.assign) {
  1239. return false;
  1240. }
  1241. // Detect buggy property enumeration order in older V8 versions.
  1242. // https://bugs.chromium.org/p/v8/issues/detail?id=4118
  1243. var test1 = new String('abc'); // eslint-disable-line no-new-wrappers
  1244. test1[5] = 'de';
  1245. if (Object.getOwnPropertyNames(test1)[0] === '5') {
  1246. return false;
  1247. }
  1248. // https://bugs.chromium.org/p/v8/issues/detail?id=3056
  1249. var test2 = {};
  1250. for (var i = 0; i < 10; i++) {
  1251. test2['_' + String.fromCharCode(i)] = i;
  1252. }
  1253. var order2 = Object.getOwnPropertyNames(test2).map(function (n) {
  1254. return test2[n];
  1255. });
  1256. if (order2.join('') !== '0123456789') {
  1257. return false;
  1258. }
  1259. // https://bugs.chromium.org/p/v8/issues/detail?id=3056
  1260. var test3 = {};
  1261. 'abcdefghijklmnopqrst'.split('').forEach(function (letter) {
  1262. test3[letter] = letter;
  1263. });
  1264. if (Object.keys(Object.assign({}, test3)).join('') !==
  1265. 'abcdefghijklmnopqrst') {
  1266. return false;
  1267. }
  1268. return true;
  1269. } catch (err) {
  1270. // We don't expect any of the above to throw, but better to be safe.
  1271. return false;
  1272. }
  1273. }
  1274. module.exports = shouldUseNative() ? Object.assign : function (target, source) {
  1275. var from;
  1276. var to = toObject(target);
  1277. var symbols;
  1278. for (var s = 1; s < arguments.length; s++) {
  1279. from = Object(arguments[s]);
  1280. for (var key in from) {
  1281. if (hasOwnProperty.call(from, key)) {
  1282. to[key] = from[key];
  1283. }
  1284. }
  1285. if (getOwnPropertySymbols) {
  1286. symbols = getOwnPropertySymbols(from);
  1287. for (var i = 0; i < symbols.length; i++) {
  1288. if (propIsEnumerable.call(from, symbols[i])) {
  1289. to[symbols[i]] = from[symbols[i]];
  1290. }
  1291. }
  1292. }
  1293. }
  1294. return to;
  1295. };
  1296. }, {}], 7: [function (require, module, exports) {
  1297. 'use strict'
  1298. module.exports = function parseURI(str, opts) {
  1299. opts = opts || {}
  1300. var o = {
  1301. key: ['source', 'protocol', 'authority', 'userInfo', 'user', 'password', 'host', 'port', 'relative', 'path', 'directory', 'file', 'query', 'anchor'],
  1302. q: {
  1303. name: 'queryKey',
  1304. parser: /(?:^|&)([^&=]*)=?([^&]*)/g
  1305. },
  1306. parser: {
  1307. strict: /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,
  1308. loose: /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/
  1309. }
  1310. }
  1311. var m = o.parser[opts.strictMode ? 'strict' : 'loose'].exec(str)
  1312. var uri = {}
  1313. var i = 14
  1314. while (i--) uri[o.key[i]] = m[i] || ''
  1315. uri[o.q.name] = {}
  1316. uri[o.key[12]].replace(o.q.parser, function ($0, $1, $2) {
  1317. if ($1) uri[o.q.name][$1] = $2
  1318. })
  1319. return uri
  1320. }
  1321. }, {}], 8: [function (require, module, exports) {
  1322. (function (process) {
  1323. // Copyright Joyent, Inc. and other Node contributors.
  1324. //
  1325. // Permission is hereby granted, free of charge, to any person obtaining a
  1326. // copy of this software and associated documentation files (the
  1327. // "Software"), to deal in the Software without restriction, including
  1328. // without limitation the rights to use, copy, modify, merge, publish,
  1329. // distribute, sublicense, and/or sell copies of the Software, and to permit
  1330. // persons to whom the Software is furnished to do so, subject to the
  1331. // following conditions:
  1332. //
  1333. // The above copyright notice and this permission notice shall be included
  1334. // in all copies or substantial portions of the Software.
  1335. //
  1336. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  1337. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  1338. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  1339. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  1340. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  1341. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  1342. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  1343. // resolves . and .. elements in a path array with directory names there
  1344. // must be no slashes, empty elements, or device names (c:\) in the array
  1345. // (so also no leading and trailing slashes - it does not distinguish
  1346. // relative and absolute paths)
  1347. function normalizeArray(parts, allowAboveRoot) {
  1348. // if the path tries to go above the root, `up` ends up > 0
  1349. var up = 0;
  1350. for (var i = parts.length - 1; i >= 0; i--) {
  1351. var last = parts[i];
  1352. if (last === '.') {
  1353. parts.splice(i, 1);
  1354. } else if (last === '..') {
  1355. parts.splice(i, 1);
  1356. up++;
  1357. } else if (up) {
  1358. parts.splice(i, 1);
  1359. up--;
  1360. }
  1361. }
  1362. // if the path is allowed to go above the root, restore leading ..s
  1363. if (allowAboveRoot) {
  1364. for (; up--; up) {
  1365. parts.unshift('..');
  1366. }
  1367. }
  1368. return parts;
  1369. }
  1370. // Split a filename into [root, dir, basename, ext], unix version
  1371. // 'root' is just a slash, or nothing.
  1372. var splitPathRe =
  1373. /^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/;
  1374. var splitPath = function (filename) {
  1375. return splitPathRe.exec(filename).slice(1);
  1376. };
  1377. // path.resolve([from ...], to)
  1378. // posix version
  1379. exports.resolve = function () {
  1380. var resolvedPath = '',
  1381. resolvedAbsolute = false;
  1382. for (var i = arguments.length - 1; i >= -1 && !resolvedAbsolute; i--) {
  1383. var path = (i >= 0) ? arguments[i] : process.cwd();
  1384. // Skip empty and invalid entries
  1385. if (typeof path !== 'string') {
  1386. throw new TypeError('Arguments to path.resolve must be strings');
  1387. } else if (!path) {
  1388. continue;
  1389. }
  1390. resolvedPath = path + '/' + resolvedPath;
  1391. resolvedAbsolute = path.charAt(0) === '/';
  1392. }
  1393. // At this point the path should be resolved to a full absolute path, but
  1394. // handle relative paths to be safe (might happen when process.cwd() fails)
  1395. // Normalize the path
  1396. resolvedPath = normalizeArray(filter(resolvedPath.split('/'), function (p) {
  1397. return !!p;
  1398. }), !resolvedAbsolute).join('/');
  1399. return ((resolvedAbsolute ? '/' : '') + resolvedPath) || '.';
  1400. };
  1401. // path.normalize(path)
  1402. // posix version
  1403. exports.normalize = function (path) {
  1404. var isAbsolute = exports.isAbsolute(path),
  1405. trailingSlash = substr(path, -1) === '/';
  1406. // Normalize the path
  1407. path = normalizeArray(filter(path.split('/'), function (p) {
  1408. return !!p;
  1409. }), !isAbsolute).join('/');
  1410. if (!path && !isAbsolute) {
  1411. path = '.';
  1412. }
  1413. if (path && trailingSlash) {
  1414. path += '/';
  1415. }
  1416. return (isAbsolute ? '/' : '') + path;
  1417. };
  1418. // posix version
  1419. exports.isAbsolute = function (path) {
  1420. return path.charAt(0) === '/';
  1421. };
  1422. // posix version
  1423. exports.join = function () {
  1424. var paths = Array.prototype.slice.call(arguments, 0);
  1425. return exports.normalize(filter(paths, function (p, index) {
  1426. if (typeof p !== 'string') {
  1427. throw new TypeError('Arguments to path.join must be strings');
  1428. }
  1429. return p;
  1430. }).join('/'));
  1431. };
  1432. // path.relative(from, to)
  1433. // posix version
  1434. exports.relative = function (from, to) {
  1435. from = exports.resolve(from).substr(1);
  1436. to = exports.resolve(to).substr(1);
  1437. function trim(arr) {
  1438. var start = 0;
  1439. for (; start < arr.length; start++) {
  1440. if (arr[start] !== '') break;
  1441. }
  1442. var end = arr.length - 1;
  1443. for (; end >= 0; end--) {
  1444. if (arr[end] !== '') break;
  1445. }
  1446. if (start > end) return [];
  1447. return arr.slice(start, end - start + 1);
  1448. }
  1449. var fromParts = trim(from.split('/'));
  1450. var toParts = trim(to.split('/'));
  1451. var length = Math.min(fromParts.length, toParts.length);
  1452. var samePartsLength = length;
  1453. for (var i = 0; i < length; i++) {
  1454. if (fromParts[i] !== toParts[i]) {
  1455. samePartsLength = i;
  1456. break;
  1457. }
  1458. }
  1459. var outputParts = [];
  1460. for (var i = samePartsLength; i < fromParts.length; i++) {
  1461. outputParts.push('..');
  1462. }
  1463. outputParts = outputParts.concat(toParts.slice(samePartsLength));
  1464. return outputParts.join('/');
  1465. };
  1466. exports.sep = '/';
  1467. exports.delimiter = ':';
  1468. exports.dirname = function (path) {
  1469. var result = splitPath(path),
  1470. root = result[0],
  1471. dir = result[1];
  1472. if (!root && !dir) {
  1473. // No dirname whatsoever
  1474. return '.';
  1475. }
  1476. if (dir) {
  1477. // It has a dirname, strip trailing slash
  1478. dir = dir.substr(0, dir.length - 1);
  1479. }
  1480. return root + dir;
  1481. };
  1482. exports.basename = function (path, ext) {
  1483. var f = splitPath(path)[2];
  1484. // TODO: make this comparison case-insensitive on windows?
  1485. if (ext && f.substr(-1 * ext.length) === ext) {
  1486. f = f.substr(0, f.length - ext.length);
  1487. }
  1488. return f;
  1489. };
  1490. exports.extname = function (path) {
  1491. return splitPath(path)[3];
  1492. };
  1493. function filter(xs, f) {
  1494. if (xs.filter) return xs.filter(f);
  1495. var res = [];
  1496. for (var i = 0; i < xs.length; i++) {
  1497. if (f(xs[i], i, xs)) res.push(xs[i]);
  1498. }
  1499. return res;
  1500. }
  1501. // String.prototype.substr - negative index don't work in IE8
  1502. var substr = 'ab'.substr(-1) === 'b'
  1503. ? function (str, start, len) { return str.substr(start, len) }
  1504. : function (str, start, len) {
  1505. if (start < 0) start = str.length + start;
  1506. return str.substr(start, len);
  1507. }
  1508. ;
  1509. }).call(this, require('_process'))
  1510. }, { "_process": 26 }], 9: [function (require, module, exports) {
  1511. var EMPTY_ARRAY_BUFFER = new ArrayBuffer(0);
  1512. /**
  1513. * Helper class to create a webGL buffer
  1514. *
  1515. * @class
  1516. * @memberof PIXI.glCore
  1517. * @param gl {WebGLRenderingContext} The current WebGL rendering context
  1518. * @param type {gl.ARRAY_BUFFER | gl.ELEMENT_ARRAY_BUFFER} @mat
  1519. * @param data {ArrayBuffer| SharedArrayBuffer|ArrayBufferView} an array of data
  1520. * @param drawType {gl.STATIC_DRAW|gl.DYNAMIC_DRAW|gl.STREAM_DRAW}
  1521. */
  1522. var Buffer = function (gl, type, data, drawType) {
  1523. /**
  1524. * The current WebGL rendering context
  1525. *
  1526. * @member {WebGLRenderingContext}
  1527. */
  1528. this.gl = gl;
  1529. /**
  1530. * The WebGL buffer, created upon instantiation
  1531. *
  1532. * @member {WebGLBuffer}
  1533. */
  1534. this.buffer = gl.createBuffer();
  1535. /**
  1536. * The type of the buffer
  1537. *
  1538. * @member {gl.ARRAY_BUFFER|gl.ELEMENT_ARRAY_BUFFER}
  1539. */
  1540. this.type = type || gl.ARRAY_BUFFER;
  1541. /**
  1542. * The draw type of the buffer
  1543. *
  1544. * @member {gl.STATIC_DRAW|gl.DYNAMIC_DRAW|gl.STREAM_DRAW}
  1545. */
  1546. this.drawType = drawType || gl.STATIC_DRAW;
  1547. /**
  1548. * The data in the buffer, as a typed array
  1549. *
  1550. * @member {ArrayBuffer| SharedArrayBuffer|ArrayBufferView}
  1551. */
  1552. this.data = EMPTY_ARRAY_BUFFER;
  1553. if (data) {
  1554. this.upload(data);
  1555. }
  1556. this._updateID = 0;
  1557. };
  1558. /**
  1559. * Uploads the buffer to the GPU
  1560. * @param data {ArrayBuffer| SharedArrayBuffer|ArrayBufferView} an array of data to upload
  1561. * @param offset {Number} if only a subset of the data should be uploaded, this is the amount of data to subtract
  1562. * @param dontBind {Boolean} whether to bind the buffer before uploading it
  1563. */
  1564. Buffer.prototype.upload = function (data, offset, dontBind) {
  1565. // todo - needed?
  1566. if (!dontBind) this.bind();
  1567. var gl = this.gl;
  1568. data = data || this.data;
  1569. offset = offset || 0;
  1570. if (this.data.byteLength >= data.byteLength) {
  1571. gl.bufferSubData(this.type, offset, data);
  1572. }
  1573. else {
  1574. gl.bufferData(this.type, data, this.drawType);
  1575. }
  1576. this.data = data;
  1577. };
  1578. /**
  1579. * Binds the buffer
  1580. *
  1581. */
  1582. Buffer.prototype.bind = function () {
  1583. var gl = this.gl;
  1584. gl.bindBuffer(this.type, this.buffer);
  1585. };
  1586. Buffer.createVertexBuffer = function (gl, data, drawType) {
  1587. return new Buffer(gl, gl.ARRAY_BUFFER, data, drawType);
  1588. };
  1589. Buffer.createIndexBuffer = function (gl, data, drawType) {
  1590. return new Buffer(gl, gl.ELEMENT_ARRAY_BUFFER, data, drawType);
  1591. };
  1592. Buffer.create = function (gl, type, data, drawType) {
  1593. return new Buffer(gl, type, data, drawType);
  1594. };
  1595. /**
  1596. * Destroys the buffer
  1597. *
  1598. */
  1599. Buffer.prototype.destroy = function () {
  1600. this.gl.deleteBuffer(this.buffer);
  1601. };
  1602. module.exports = Buffer;
  1603. }, {}], 10: [function (require, module, exports) {
  1604. var Texture = require('./GLTexture');
  1605. /**
  1606. * Helper class to create a webGL Framebuffer
  1607. *
  1608. * @class
  1609. * @memberof PIXI.glCore
  1610. * @param gl {WebGLRenderingContext} The current WebGL rendering context
  1611. * @param width {Number} the width of the drawing area of the frame buffer
  1612. * @param height {Number} the height of the drawing area of the frame buffer
  1613. */
  1614. var Framebuffer = function (gl, width, height) {
  1615. /**
  1616. * The current WebGL rendering context
  1617. *
  1618. * @member {WebGLRenderingContext}
  1619. */
  1620. this.gl = gl;
  1621. /**
  1622. * The frame buffer
  1623. *
  1624. * @member {WebGLFramebuffer}
  1625. */
  1626. this.framebuffer = gl.createFramebuffer();
  1627. /**
  1628. * The stencil buffer
  1629. *
  1630. * @member {WebGLRenderbuffer}
  1631. */
  1632. this.stencil = null;
  1633. /**
  1634. * The stencil buffer
  1635. *
  1636. * @member {PIXI.glCore.GLTexture}
  1637. */
  1638. this.texture = null;
  1639. /**
  1640. * The width of the drawing area of the buffer
  1641. *
  1642. * @member {Number}
  1643. */
  1644. this.width = width || 100;
  1645. /**
  1646. * The height of the drawing area of the buffer
  1647. *
  1648. * @member {Number}
  1649. */
  1650. this.height = height || 100;
  1651. };
  1652. /**
  1653. * Adds a texture to the frame buffer
  1654. * @param texture {PIXI.glCore.GLTexture}
  1655. */
  1656. Framebuffer.prototype.enableTexture = function (texture) {
  1657. var gl = this.gl;
  1658. this.texture = texture || new Texture(gl);
  1659. this.texture.bind();
  1660. //gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, this.width, this.height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
  1661. this.bind();
  1662. gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, this.texture.texture, 0);
  1663. };
  1664. /**
  1665. * Initialises the stencil buffer
  1666. */
  1667. Framebuffer.prototype.enableStencil = function () {
  1668. if (this.stencil) return;
  1669. var gl = this.gl;
  1670. this.stencil = gl.createRenderbuffer();
  1671. gl.bindRenderbuffer(gl.RENDERBUFFER, this.stencil);
  1672. // TODO.. this is depth AND stencil?
  1673. gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_STENCIL_ATTACHMENT, gl.RENDERBUFFER, this.stencil);
  1674. gl.renderbufferStorage(gl.RENDERBUFFER, gl.DEPTH_STENCIL, this.width, this.height);
  1675. };
  1676. /**
  1677. * Erases the drawing area and fills it with a colour
  1678. * @param r {Number} the red value of the clearing colour
  1679. * @param g {Number} the green value of the clearing colour
  1680. * @param b {Number} the blue value of the clearing colour
  1681. * @param a {Number} the alpha value of the clearing colour
  1682. */
  1683. Framebuffer.prototype.clear = function (r, g, b, a) {
  1684. this.bind();
  1685. var gl = this.gl;
  1686. gl.clearColor(r, g, b, a);
  1687. gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
  1688. };
  1689. /**
  1690. * Binds the frame buffer to the WebGL context
  1691. */
  1692. Framebuffer.prototype.bind = function () {
  1693. var gl = this.gl;
  1694. gl.bindFramebuffer(gl.FRAMEBUFFER, this.framebuffer);
  1695. };
  1696. /**
  1697. * Unbinds the frame buffer to the WebGL context
  1698. */
  1699. Framebuffer.prototype.unbind = function () {
  1700. var gl = this.gl;
  1701. gl.bindFramebuffer(gl.FRAMEBUFFER, null);
  1702. };
  1703. /**
  1704. * Resizes the drawing area of the buffer to the given width and height
  1705. * @param width {Number} the new width
  1706. * @param height {Number} the new height
  1707. */
  1708. Framebuffer.prototype.resize = function (width, height) {
  1709. var gl = this.gl;
  1710. this.width = width;
  1711. this.height = height;
  1712. if (this.texture) {
  1713. this.texture.uploadData(null, width, height);
  1714. }
  1715. if (this.stencil) {
  1716. // update the stencil buffer width and height
  1717. gl.bindRenderbuffer(gl.RENDERBUFFER, this.stencil);
  1718. gl.renderbufferStorage(gl.RENDERBUFFER, gl.DEPTH_STENCIL, width, height);
  1719. }
  1720. };
  1721. /**
  1722. * Destroys this buffer
  1723. */
  1724. Framebuffer.prototype.destroy = function () {
  1725. var gl = this.gl;
  1726. //TODO
  1727. if (this.texture) {
  1728. this.texture.destroy();
  1729. }
  1730. gl.deleteFramebuffer(this.framebuffer);
  1731. this.gl = null;
  1732. this.stencil = null;
  1733. this.texture = null;
  1734. };
  1735. /**
  1736. * Creates a frame buffer with a texture containing the given data
  1737. * @static
  1738. * @param gl {WebGLRenderingContext} The current WebGL rendering context
  1739. * @param width {Number} the width of the drawing area of the frame buffer
  1740. * @param height {Number} the height of the drawing area of the frame buffer
  1741. * @param data {ArrayBuffer| SharedArrayBuffer|ArrayBufferView} an array of data
  1742. */
  1743. Framebuffer.createRGBA = function (gl, width, height, data) {
  1744. var texture = Texture.fromData(gl, null, width, height);
  1745. texture.enableNearestScaling();
  1746. texture.enableWrapClamp();
  1747. //now create the framebuffer object and attach the texture to it.
  1748. var fbo = new Framebuffer(gl, width, height);
  1749. fbo.enableTexture(texture);
  1750. //fbo.enableStencil(); // get this back on soon!
  1751. //fbo.enableStencil(); // get this back on soon!
  1752. fbo.unbind();
  1753. return fbo;
  1754. };
  1755. /**
  1756. * Creates a frame buffer with a texture containing the given data
  1757. * @static
  1758. * @param gl {WebGLRenderingContext} The current WebGL rendering context
  1759. * @param width {Number} the width of the drawing area of the frame buffer
  1760. * @param height {Number} the height of the drawing area of the frame buffer
  1761. * @param data {ArrayBuffer| SharedArrayBuffer|ArrayBufferView} an array of data
  1762. */
  1763. Framebuffer.createFloat32 = function (gl, width, height, data) {
  1764. // create a new texture..
  1765. var texture = new Texture.fromData(gl, data, width, height);
  1766. texture.enableNearestScaling();
  1767. texture.enableWrapClamp();
  1768. //now create the framebuffer object and attach the texture to it.
  1769. var fbo = new Framebuffer(gl, width, height);
  1770. fbo.enableTexture(texture);
  1771. fbo.unbind();
  1772. return fbo;
  1773. };
  1774. module.exports = Framebuffer;
  1775. }, { "./GLTexture": 12 }], 11: [function (require, module, exports) {
  1776. var compileProgram = require('./shader/compileProgram'),
  1777. extractAttributes = require('./shader/extractAttributes'),
  1778. extractUniforms = require('./shader/extractUniforms'),
  1779. setPrecision = require('./shader/setPrecision'),
  1780. generateUniformAccessObject = require('./shader/generateUniformAccessObject');
  1781. /**
  1782. * Helper class to create a webGL Shader
  1783. *
  1784. * @class
  1785. * @memberof PIXI.glCore
  1786. * @param gl {WebGLRenderingContext}
  1787. * @param vertexSrc {string|string[]} The vertex shader source as an array of strings.
  1788. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings.
  1789. * @param precision {string} The float precision of the shader. Options are 'lowp', 'mediump' or 'highp'.
  1790. * @param attributeLocations {object} A key value pair showing which location eact attribute should sit eg {position:0, uvs:1}
  1791. */
  1792. var Shader = function (gl, vertexSrc, fragmentSrc, precision, attributeLocations) {
  1793. /**
  1794. * The current WebGL rendering context
  1795. *
  1796. * @member {WebGLRenderingContext}
  1797. */
  1798. this.gl = gl;
  1799. if (precision) {
  1800. vertexSrc = setPrecision(vertexSrc, precision);
  1801. fragmentSrc = setPrecision(fragmentSrc, precision);
  1802. }
  1803. /**
  1804. * The shader program
  1805. *
  1806. * @member {WebGLProgram}
  1807. */
  1808. // First compile the program..
  1809. this.program = compileProgram(gl, vertexSrc, fragmentSrc, attributeLocations);
  1810. /**
  1811. * The attributes of the shader as an object containing the following properties
  1812. * {
  1813. * type,
  1814. * size,
  1815. * location,
  1816. * pointer
  1817. * }
  1818. * @member {Object}
  1819. */
  1820. // next extract the attributes
  1821. this.attributes = extractAttributes(gl, this.program);
  1822. this.uniformData = extractUniforms(gl, this.program);
  1823. /**
  1824. * The uniforms of the shader as an object containing the following properties
  1825. * {
  1826. * gl,
  1827. * data
  1828. * }
  1829. * @member {Object}
  1830. */
  1831. this.uniforms = generateUniformAccessObject(gl, this.uniformData);
  1832. };
  1833. /**
  1834. * Uses this shader
  1835. *
  1836. * @return {PIXI.glCore.GLShader} Returns itself.
  1837. */
  1838. Shader.prototype.bind = function () {
  1839. this.gl.useProgram(this.program);
  1840. return this;
  1841. };
  1842. /**
  1843. * Destroys this shader
  1844. * TODO
  1845. */
  1846. Shader.prototype.destroy = function () {
  1847. this.attributes = null;
  1848. this.uniformData = null;
  1849. this.uniforms = null;
  1850. var gl = this.gl;
  1851. gl.deleteProgram(this.program);
  1852. };
  1853. module.exports = Shader;
  1854. }, { "./shader/compileProgram": 17, "./shader/extractAttributes": 19, "./shader/extractUniforms": 20, "./shader/generateUniformAccessObject": 21, "./shader/setPrecision": 25 }], 12: [function (require, module, exports) {
  1855. /**
  1856. * Helper class to create a WebGL Texture
  1857. *
  1858. * @class
  1859. * @memberof PIXI.glCore
  1860. * @param gl {WebGLRenderingContext} The current WebGL context
  1861. * @param width {number} the width of the texture
  1862. * @param height {number} the height of the texture
  1863. * @param format {number} the pixel format of the texture. defaults to gl.RGBA
  1864. * @param type {number} the gl type of the texture. defaults to gl.UNSIGNED_BYTE
  1865. */
  1866. var Texture = function (gl, width, height, format, type) {
  1867. /**
  1868. * The current WebGL rendering context
  1869. *
  1870. * @member {WebGLRenderingContext}
  1871. */
  1872. this.gl = gl;
  1873. /**
  1874. * The WebGL texture
  1875. *
  1876. * @member {WebGLTexture}
  1877. */
  1878. this.texture = gl.createTexture();
  1879. /**
  1880. * If mipmapping was used for this texture, enable and disable with enableMipmap()
  1881. *
  1882. * @member {Boolean}
  1883. */
  1884. // some settings..
  1885. this.mipmap = false;
  1886. /**
  1887. * Set to true to enable pre-multiplied alpha
  1888. *
  1889. * @member {Boolean}
  1890. */
  1891. this.premultiplyAlpha = false;
  1892. /**
  1893. * The width of texture
  1894. *
  1895. * @member {Number}
  1896. */
  1897. this.width = width || -1;
  1898. /**
  1899. * The height of texture
  1900. *
  1901. * @member {Number}
  1902. */
  1903. this.height = height || -1;
  1904. /**
  1905. * The pixel format of the texture. defaults to gl.RGBA
  1906. *
  1907. * @member {Number}
  1908. */
  1909. this.format = format || gl.RGBA;
  1910. /**
  1911. * The gl type of the texture. defaults to gl.UNSIGNED_BYTE
  1912. *
  1913. * @member {Number}
  1914. */
  1915. this.type = type || gl.UNSIGNED_BYTE;
  1916. };
  1917. /**
  1918. * Uploads this texture to the GPU
  1919. * @param source {HTMLImageElement|ImageData|HTMLVideoElement} the source image of the texture
  1920. */
  1921. Texture.prototype.upload = function (source) {
  1922. this.bind();
  1923. var gl = this.gl;
  1924. gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, this.premultiplyAlpha);
  1925. var newWidth = source.videoWidth || source.width;
  1926. var newHeight = source.videoHeight || source.height;
  1927. if (newHeight !== this.height || newWidth !== this.width) {
  1928. gl.texImage2D(gl.TEXTURE_2D, 0, this.format, this.format, this.type, source);
  1929. }
  1930. else {
  1931. gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, this.format, this.type, source);
  1932. }
  1933. // if the source is a video, we need to use the videoWidth / videoHeight properties as width / height will be incorrect.
  1934. this.width = newWidth;
  1935. this.height = newHeight;
  1936. };
  1937. var FLOATING_POINT_AVAILABLE = false;
  1938. /**
  1939. * Use a data source and uploads this texture to the GPU
  1940. * @param data {TypedArray} the data to upload to the texture
  1941. * @param width {number} the new width of the texture
  1942. * @param height {number} the new height of the texture
  1943. */
  1944. Texture.prototype.uploadData = function (data, width, height) {
  1945. this.bind();
  1946. var gl = this.gl;
  1947. if (data instanceof Float32Array) {
  1948. if (!FLOATING_POINT_AVAILABLE) {
  1949. var ext = gl.getExtension("OES_texture_float");
  1950. if (ext) {
  1951. FLOATING_POINT_AVAILABLE = true;
  1952. }
  1953. else {
  1954. throw new Error('floating point textures not available');
  1955. }
  1956. }
  1957. this.type = gl.FLOAT;
  1958. }
  1959. else {
  1960. // TODO support for other types
  1961. this.type = this.type || gl.UNSIGNED_BYTE;
  1962. }
  1963. // what type of data?
  1964. gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, this.premultiplyAlpha);
  1965. if (width !== this.width || height !== this.height) {
  1966. gl.texImage2D(gl.TEXTURE_2D, 0, this.format, width, height, 0, this.format, this.type, data || null);
  1967. }
  1968. else {
  1969. gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, width, height, this.format, this.type, data || null);
  1970. }
  1971. this.width = width;
  1972. this.height = height;
  1973. // texSubImage2D
  1974. };
  1975. /**
  1976. * Binds the texture
  1977. * @param location
  1978. */
  1979. Texture.prototype.bind = function (location) {
  1980. var gl = this.gl;
  1981. if (location !== undefined) {
  1982. gl.activeTexture(gl.TEXTURE0 + location);
  1983. }
  1984. gl.bindTexture(gl.TEXTURE_2D, this.texture);
  1985. };
  1986. /**
  1987. * Unbinds the texture
  1988. */
  1989. Texture.prototype.unbind = function () {
  1990. var gl = this.gl;
  1991. gl.bindTexture(gl.TEXTURE_2D, null);
  1992. };
  1993. /**
  1994. * @param linear {Boolean} if we want to use linear filtering or nearest neighbour interpolation
  1995. */
  1996. Texture.prototype.minFilter = function (linear) {
  1997. var gl = this.gl;
  1998. this.bind();
  1999. if (this.mipmap) {
  2000. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, linear ? gl.LINEAR_MIPMAP_LINEAR : gl.NEAREST_MIPMAP_NEAREST);
  2001. }
  2002. else {
  2003. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, linear ? gl.LINEAR : gl.NEAREST);
  2004. }
  2005. };
  2006. /**
  2007. * @param linear {Boolean} if we want to use linear filtering or nearest neighbour interpolation
  2008. */
  2009. Texture.prototype.magFilter = function (linear) {
  2010. var gl = this.gl;
  2011. this.bind();
  2012. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, linear ? gl.LINEAR : gl.NEAREST);
  2013. };
  2014. /**
  2015. * Enables mipmapping
  2016. */
  2017. Texture.prototype.enableMipmap = function () {
  2018. var gl = this.gl;
  2019. this.bind();
  2020. this.mipmap = true;
  2021. gl.generateMipmap(gl.TEXTURE_2D);
  2022. };
  2023. /**
  2024. * Enables linear filtering
  2025. */
  2026. Texture.prototype.enableLinearScaling = function () {
  2027. this.minFilter(true);
  2028. this.magFilter(true);
  2029. };
  2030. /**
  2031. * Enables nearest neighbour interpolation
  2032. */
  2033. Texture.prototype.enableNearestScaling = function () {
  2034. this.minFilter(false);
  2035. this.magFilter(false);
  2036. };
  2037. /**
  2038. * Enables clamping on the texture so WebGL will not repeat it
  2039. */
  2040. Texture.prototype.enableWrapClamp = function () {
  2041. var gl = this.gl;
  2042. this.bind();
  2043. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
  2044. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
  2045. };
  2046. /**
  2047. * Enable tiling on the texture
  2048. */
  2049. Texture.prototype.enableWrapRepeat = function () {
  2050. var gl = this.gl;
  2051. this.bind();
  2052. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.REPEAT);
  2053. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.REPEAT);
  2054. };
  2055. Texture.prototype.enableWrapMirrorRepeat = function () {
  2056. var gl = this.gl;
  2057. this.bind();
  2058. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.MIRRORED_REPEAT);
  2059. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.MIRRORED_REPEAT);
  2060. };
  2061. /**
  2062. * Destroys this texture
  2063. */
  2064. Texture.prototype.destroy = function () {
  2065. var gl = this.gl;
  2066. //TODO
  2067. gl.deleteTexture(this.texture);
  2068. };
  2069. /**
  2070. * @static
  2071. * @param gl {WebGLRenderingContext} The current WebGL context
  2072. * @param source {HTMLImageElement|ImageData} the source image of the texture
  2073. * @param premultiplyAlpha {Boolean} If we want to use pre-multiplied alpha
  2074. */
  2075. Texture.fromSource = function (gl, source, premultiplyAlpha) {
  2076. var texture = new Texture(gl);
  2077. texture.premultiplyAlpha = premultiplyAlpha || false;
  2078. texture.upload(source);
  2079. return texture;
  2080. };
  2081. /**
  2082. * @static
  2083. * @param gl {WebGLRenderingContext} The current WebGL context
  2084. * @param data {TypedArray} the data to upload to the texture
  2085. * @param width {number} the new width of the texture
  2086. * @param height {number} the new height of the texture
  2087. */
  2088. Texture.fromData = function (gl, data, width, height) {
  2089. //console.log(data, width, height);
  2090. var texture = new Texture(gl);
  2091. texture.uploadData(data, width, height);
  2092. return texture;
  2093. };
  2094. module.exports = Texture;
  2095. }, {}], 13: [function (require, module, exports) {
  2096. // state object//
  2097. var setVertexAttribArrays = require('./setVertexAttribArrays');
  2098. /**
  2099. * Helper class to work with WebGL VertexArrayObjects (vaos)
  2100. * Only works if WebGL extensions are enabled (they usually are)
  2101. *
  2102. * @class
  2103. * @memberof PIXI.glCore
  2104. * @param gl {WebGLRenderingContext} The current WebGL rendering context
  2105. */
  2106. function VertexArrayObject(gl, state) {
  2107. this.nativeVaoExtension = null;
  2108. if (!VertexArrayObject.FORCE_NATIVE) {
  2109. this.nativeVaoExtension = gl.getExtension('OES_vertex_array_object') ||
  2110. gl.getExtension('MOZ_OES_vertex_array_object') ||
  2111. gl.getExtension('WEBKIT_OES_vertex_array_object');
  2112. }
  2113. this.nativeState = state;
  2114. if (this.nativeVaoExtension) {
  2115. this.nativeVao = this.nativeVaoExtension.createVertexArrayOES();
  2116. var maxAttribs = gl.getParameter(gl.MAX_VERTEX_ATTRIBS);
  2117. // VAO - overwrite the state..
  2118. this.nativeState = {
  2119. tempAttribState: new Array(maxAttribs),
  2120. attribState: new Array(maxAttribs)
  2121. };
  2122. }
  2123. /**
  2124. * The current WebGL rendering context
  2125. *
  2126. * @member {WebGLRenderingContext}
  2127. */
  2128. this.gl = gl;
  2129. /**
  2130. * An array of attributes
  2131. *
  2132. * @member {Array}
  2133. */
  2134. this.attributes = [];
  2135. /**
  2136. * @member {PIXI.glCore.GLBuffer}
  2137. */
  2138. this.indexBuffer = null;
  2139. /**
  2140. * A boolean flag
  2141. *
  2142. * @member {Boolean}
  2143. */
  2144. this.dirty = false;
  2145. }
  2146. VertexArrayObject.prototype.constructor = VertexArrayObject;
  2147. module.exports = VertexArrayObject;
  2148. /**
  2149. * Some devices behave a bit funny when using the newer extensions (im looking at you ipad 2!)
  2150. * If you find on older devices that things have gone a bit weird then set this to true.
  2151. */
  2152. /**
  2153. * Lets the VAO know if you should use the WebGL extension or the native methods.
  2154. * Some devices behave a bit funny when using the newer extensions (im looking at you ipad 2!)
  2155. * If you find on older devices that things have gone a bit weird then set this to true.
  2156. * @static
  2157. * @property {Boolean} FORCE_NATIVE
  2158. */
  2159. VertexArrayObject.FORCE_NATIVE = false;
  2160. /**
  2161. * Binds the buffer
  2162. */
  2163. VertexArrayObject.prototype.bind = function () {
  2164. if (this.nativeVao) {
  2165. this.nativeVaoExtension.bindVertexArrayOES(this.nativeVao);
  2166. if (this.dirty) {
  2167. this.dirty = false;
  2168. this.activate();
  2169. return this;
  2170. }
  2171. if (this.indexBuffer) {
  2172. this.indexBuffer.bind();
  2173. }
  2174. }
  2175. else {
  2176. this.activate();
  2177. }
  2178. return this;
  2179. };
  2180. /**
  2181. * Unbinds the buffer
  2182. */
  2183. VertexArrayObject.prototype.unbind = function () {
  2184. if (this.nativeVao) {
  2185. this.nativeVaoExtension.bindVertexArrayOES(null);
  2186. }
  2187. return this;
  2188. };
  2189. /**
  2190. * Uses this vao
  2191. */
  2192. VertexArrayObject.prototype.activate = function () {
  2193. var gl = this.gl;
  2194. var lastBuffer = null;
  2195. for (var i = 0; i < this.attributes.length; i++) {
  2196. var attrib = this.attributes[i];
  2197. if (lastBuffer !== attrib.buffer) {
  2198. attrib.buffer.bind();
  2199. lastBuffer = attrib.buffer;
  2200. }
  2201. gl.vertexAttribPointer(attrib.attribute.location,
  2202. attrib.attribute.size,
  2203. attrib.type || gl.FLOAT,
  2204. attrib.normalized || false,
  2205. attrib.stride || 0,
  2206. attrib.start || 0);
  2207. }
  2208. setVertexAttribArrays(gl, this.attributes, this.nativeState);
  2209. if (this.indexBuffer) {
  2210. this.indexBuffer.bind();
  2211. }
  2212. return this;
  2213. };
  2214. /**
  2215. *
  2216. * @param buffer {PIXI.gl.GLBuffer}
  2217. * @param attribute {*}
  2218. * @param type {String}
  2219. * @param normalized {Boolean}
  2220. * @param stride {Number}
  2221. * @param start {Number}
  2222. */
  2223. VertexArrayObject.prototype.addAttribute = function (buffer, attribute, type, normalized, stride, start) {
  2224. this.attributes.push({
  2225. buffer: buffer,
  2226. attribute: attribute,
  2227. location: attribute.location,
  2228. type: type || this.gl.FLOAT,
  2229. normalized: normalized || false,
  2230. stride: stride || 0,
  2231. start: start || 0
  2232. });
  2233. this.dirty = true;
  2234. return this;
  2235. };
  2236. /**
  2237. *
  2238. * @param buffer {PIXI.gl.GLBuffer}
  2239. */
  2240. VertexArrayObject.prototype.addIndex = function (buffer/*, options*/) {
  2241. this.indexBuffer = buffer;
  2242. this.dirty = true;
  2243. return this;
  2244. };
  2245. /**
  2246. * Unbinds this vao and disables it
  2247. */
  2248. VertexArrayObject.prototype.clear = function () {
  2249. // var gl = this.gl;
  2250. // TODO - should this function unbind after clear?
  2251. // for now, no but lets see what happens in the real world!
  2252. if (this.nativeVao) {
  2253. this.nativeVaoExtension.bindVertexArrayOES(this.nativeVao);
  2254. }
  2255. this.attributes.length = 0;
  2256. this.indexBuffer = null;
  2257. return this;
  2258. };
  2259. /**
  2260. * @param type {Number}
  2261. * @param size {Number}
  2262. * @param start {Number}
  2263. */
  2264. VertexArrayObject.prototype.draw = function (type, size, start) {
  2265. var gl = this.gl;
  2266. if (this.indexBuffer) {
  2267. gl.drawElements(type, size || this.indexBuffer.data.length, gl.UNSIGNED_SHORT, (start || 0) * 2);
  2268. }
  2269. else {
  2270. // TODO need a better way to calculate size..
  2271. gl.drawArrays(type, start, size || this.getSize());
  2272. }
  2273. return this;
  2274. };
  2275. /**
  2276. * Destroy this vao
  2277. */
  2278. VertexArrayObject.prototype.destroy = function () {
  2279. // lose references
  2280. this.gl = null;
  2281. this.indexBuffer = null;
  2282. this.attributes = null;
  2283. this.nativeState = null;
  2284. if (this.nativeVao) {
  2285. this.nativeVaoExtension.deleteVertexArrayOES(this.nativeVao);
  2286. }
  2287. this.nativeVaoExtension = null;
  2288. this.nativeVao = null;
  2289. };
  2290. VertexArrayObject.prototype.getSize = function () {
  2291. var attrib = this.attributes[0];
  2292. return attrib.buffer.data.length / ((attrib.stride / 4) || attrib.attribute.size);
  2293. };
  2294. }, { "./setVertexAttribArrays": 16 }], 14: [function (require, module, exports) {
  2295. /**
  2296. * Helper class to create a webGL Context
  2297. *
  2298. * @class
  2299. * @memberof PIXI.glCore
  2300. * @param canvas {HTMLCanvasElement} the canvas element that we will get the context from
  2301. * @param options {Object} An options object that gets passed in to the canvas element containing the context attributes,
  2302. * see https://developer.mozilla.org/en/docs/Web/API/HTMLCanvasElement/getContext for the options available
  2303. * @return {WebGLRenderingContext} the WebGL context
  2304. */
  2305. var createContext = function (canvas, options) {
  2306. var gl = canvas.getContext('webgl', options) ||
  2307. canvas.getContext('experimental-webgl', options);
  2308. if (!gl) {
  2309. // fail, not able to get a context
  2310. throw new Error('This browser does not support webGL. Try using the canvas renderer');
  2311. }
  2312. return gl;
  2313. };
  2314. module.exports = createContext;
  2315. }, {}], 15: [function (require, module, exports) {
  2316. var gl = {
  2317. createContext: require('./createContext'),
  2318. setVertexAttribArrays: require('./setVertexAttribArrays'),
  2319. GLBuffer: require('./GLBuffer'),
  2320. GLFramebuffer: require('./GLFramebuffer'),
  2321. GLShader: require('./GLShader'),
  2322. GLTexture: require('./GLTexture'),
  2323. VertexArrayObject: require('./VertexArrayObject'),
  2324. shader: require('./shader')
  2325. };
  2326. // Export for Node-compatible environments
  2327. if (typeof module !== 'undefined' && module.exports) {
  2328. // Export the module
  2329. module.exports = gl;
  2330. }
  2331. // Add to the browser window pixi.gl
  2332. if (typeof window !== 'undefined') {
  2333. // add the window object
  2334. window.PIXI = window.PIXI || {};
  2335. window.PIXI.glCore = gl;
  2336. }
  2337. }, { "./GLBuffer": 9, "./GLFramebuffer": 10, "./GLShader": 11, "./GLTexture": 12, "./VertexArrayObject": 13, "./createContext": 14, "./setVertexAttribArrays": 16, "./shader": 22 }], 16: [function (require, module, exports) {
  2338. // var GL_MAP = {};
  2339. /**
  2340. * @param gl {WebGLRenderingContext} The current WebGL context
  2341. * @param attribs {*}
  2342. * @param state {*}
  2343. */
  2344. var setVertexAttribArrays = function (gl, attribs, state) {
  2345. var i;
  2346. if (state) {
  2347. var tempAttribState = state.tempAttribState,
  2348. attribState = state.attribState;
  2349. for (i = 0; i < tempAttribState.length; i++) {
  2350. tempAttribState[i] = false;
  2351. }
  2352. // set the new attribs
  2353. for (i = 0; i < attribs.length; i++) {
  2354. tempAttribState[attribs[i].attribute.location] = true;
  2355. }
  2356. for (i = 0; i < attribState.length; i++) {
  2357. if (attribState[i] !== tempAttribState[i]) {
  2358. attribState[i] = tempAttribState[i];
  2359. if (state.attribState[i]) {
  2360. gl.enableVertexAttribArray(i);
  2361. }
  2362. else {
  2363. gl.disableVertexAttribArray(i);
  2364. }
  2365. }
  2366. }
  2367. }
  2368. else {
  2369. for (i = 0; i < attribs.length; i++) {
  2370. var attrib = attribs[i];
  2371. gl.enableVertexAttribArray(attrib.attribute.location);
  2372. }
  2373. }
  2374. };
  2375. module.exports = setVertexAttribArrays;
  2376. }, {}], 17: [function (require, module, exports) {
  2377. /**
  2378. * @class
  2379. * @memberof PIXI.glCore.shader
  2380. * @param gl {WebGLRenderingContext} The current WebGL context {WebGLProgram}
  2381. * @param vertexSrc {string|string[]} The vertex shader source as an array of strings.
  2382. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings.
  2383. * @param attributeLocations {Object} An attribute location map that lets you manually set the attribute locations
  2384. * @return {WebGLProgram} the shader program
  2385. */
  2386. var compileProgram = function (gl, vertexSrc, fragmentSrc, attributeLocations) {
  2387. var glVertShader = compileShader(gl, gl.VERTEX_SHADER, vertexSrc);
  2388. var glFragShader = compileShader(gl, gl.FRAGMENT_SHADER, fragmentSrc);
  2389. var program = gl.createProgram();
  2390. gl.attachShader(program, glVertShader);
  2391. gl.attachShader(program, glFragShader);
  2392. // optionally, set the attributes manually for the program rather than letting WebGL decide..
  2393. if (attributeLocations) {
  2394. for (var i in attributeLocations) {
  2395. gl.bindAttribLocation(program, attributeLocations[i], i);
  2396. }
  2397. }
  2398. gl.linkProgram(program);
  2399. // if linking fails, then log and cleanup
  2400. if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
  2401. console.error('Pixi.js Error: Could not initialize shader.');
  2402. console.error('gl.VALIDATE_STATUS', gl.getProgramParameter(program, gl.VALIDATE_STATUS));
  2403. console.error('gl.getError()', gl.getError());
  2404. // if there is a program info log, log it
  2405. if (gl.getProgramInfoLog(program) !== '') {
  2406. console.warn('Pixi.js Warning: gl.getProgramInfoLog()', gl.getProgramInfoLog(program));
  2407. }
  2408. gl.deleteProgram(program);
  2409. program = null;
  2410. }
  2411. // clean up some shaders
  2412. gl.deleteShader(glVertShader);
  2413. gl.deleteShader(glFragShader);
  2414. return program;
  2415. };
  2416. /**
  2417. * @private
  2418. * @param gl {WebGLRenderingContext} The current WebGL context {WebGLProgram}
  2419. * @param type {Number} the type, can be either VERTEX_SHADER or FRAGMENT_SHADER
  2420. * @param vertexSrc {string|string[]} The vertex shader source as an array of strings.
  2421. * @return {WebGLShader} the shader
  2422. */
  2423. var compileShader = function (gl, type, src) {
  2424. var shader = gl.createShader(type);
  2425. gl.shaderSource(shader, src);
  2426. gl.compileShader(shader);
  2427. if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
  2428. console.log(gl.getShaderInfoLog(shader));
  2429. return null;
  2430. }
  2431. return shader;
  2432. };
  2433. module.exports = compileProgram;
  2434. }, {}], 18: [function (require, module, exports) {
  2435. /**
  2436. * @class
  2437. * @memberof PIXI.glCore.shader
  2438. * @param type {String} Type of value
  2439. * @param size {Number}
  2440. */
  2441. var defaultValue = function (type, size) {
  2442. switch (type) {
  2443. case 'float':
  2444. return 0;
  2445. case 'vec2':
  2446. return new Float32Array(2 * size);
  2447. case 'vec3':
  2448. return new Float32Array(3 * size);
  2449. case 'vec4':
  2450. return new Float32Array(4 * size);
  2451. case 'int':
  2452. case 'sampler2D':
  2453. return 0;
  2454. case 'ivec2':
  2455. return new Int32Array(2 * size);
  2456. case 'ivec3':
  2457. return new Int32Array(3 * size);
  2458. case 'ivec4':
  2459. return new Int32Array(4 * size);
  2460. case 'bool':
  2461. return false;
  2462. case 'bvec2':
  2463. return booleanArray(2 * size);
  2464. case 'bvec3':
  2465. return booleanArray(3 * size);
  2466. case 'bvec4':
  2467. return booleanArray(4 * size);
  2468. case 'mat2':
  2469. return new Float32Array([1, 0,
  2470. 0, 1]);
  2471. case 'mat3':
  2472. return new Float32Array([1, 0, 0,
  2473. 0, 1, 0,
  2474. 0, 0, 1]);
  2475. case 'mat4':
  2476. return new Float32Array([1, 0, 0, 0,
  2477. 0, 1, 0, 0,
  2478. 0, 0, 1, 0,
  2479. 0, 0, 0, 1]);
  2480. }
  2481. };
  2482. var booleanArray = function (size) {
  2483. var array = new Array(size);
  2484. for (var i = 0; i < array.length; i++) {
  2485. array[i] = false;
  2486. }
  2487. return array;
  2488. };
  2489. module.exports = defaultValue;
  2490. }, {}], 19: [function (require, module, exports) {
  2491. var mapType = require('./mapType');
  2492. var mapSize = require('./mapSize');
  2493. /**
  2494. * Extracts the attributes
  2495. * @class
  2496. * @memberof PIXI.glCore.shader
  2497. * @param gl {WebGLRenderingContext} The current WebGL rendering context
  2498. * @param program {WebGLProgram} The shader program to get the attributes from
  2499. * @return attributes {Object}
  2500. */
  2501. var extractAttributes = function (gl, program) {
  2502. var attributes = {};
  2503. var totalAttributes = gl.getProgramParameter(program, gl.ACTIVE_ATTRIBUTES);
  2504. for (var i = 0; i < totalAttributes; i++) {
  2505. var attribData = gl.getActiveAttrib(program, i);
  2506. var type = mapType(gl, attribData.type);
  2507. attributes[attribData.name] = {
  2508. type: type,
  2509. size: mapSize(type),
  2510. location: gl.getAttribLocation(program, attribData.name),
  2511. //TODO - make an attribute object
  2512. pointer: pointer
  2513. };
  2514. }
  2515. return attributes;
  2516. };
  2517. var pointer = function (type, normalized, stride, start) {
  2518. // console.log(this.location)
  2519. gl.vertexAttribPointer(this.location, this.size, type || gl.FLOAT, normalized || false, stride || 0, start || 0);
  2520. };
  2521. module.exports = extractAttributes;
  2522. }, { "./mapSize": 23, "./mapType": 24 }], 20: [function (require, module, exports) {
  2523. var mapType = require('./mapType');
  2524. var defaultValue = require('./defaultValue');
  2525. /**
  2526. * Extracts the uniforms
  2527. * @class
  2528. * @memberof PIXI.glCore.shader
  2529. * @param gl {WebGLRenderingContext} The current WebGL rendering context
  2530. * @param program {WebGLProgram} The shader program to get the uniforms from
  2531. * @return uniforms {Object}
  2532. */
  2533. var extractUniforms = function (gl, program) {
  2534. var uniforms = {};
  2535. var totalUniforms = gl.getProgramParameter(program, gl.ACTIVE_UNIFORMS);
  2536. for (var i = 0; i < totalUniforms; i++) {
  2537. var uniformData = gl.getActiveUniform(program, i);
  2538. var name = uniformData.name.replace(/\[.*?\]/, "");
  2539. var type = mapType(gl, uniformData.type);
  2540. uniforms[name] = {
  2541. type: type,
  2542. size: uniformData.size,
  2543. location: gl.getUniformLocation(program, name),
  2544. value: defaultValue(type, uniformData.size)
  2545. };
  2546. }
  2547. return uniforms;
  2548. };
  2549. module.exports = extractUniforms;
  2550. }, { "./defaultValue": 18, "./mapType": 24 }], 21: [function (require, module, exports) {
  2551. /**
  2552. * Extracts the attributes
  2553. * @class
  2554. * @memberof PIXI.glCore.shader
  2555. * @param gl {WebGLRenderingContext} The current WebGL rendering context
  2556. * @param uniforms {Array} @mat ?
  2557. * @return attributes {Object}
  2558. */
  2559. var generateUniformAccessObject = function (gl, uniformData) {
  2560. // this is the object we will be sending back.
  2561. // an object hierachy will be created for structs
  2562. var uniforms = { data: {} };
  2563. uniforms.gl = gl;
  2564. var uniformKeys = Object.keys(uniformData);
  2565. for (var i = 0; i < uniformKeys.length; i++) {
  2566. var fullName = uniformKeys[i];
  2567. var nameTokens = fullName.split('.');
  2568. var name = nameTokens[nameTokens.length - 1];
  2569. var uniformGroup = getUniformGroup(nameTokens, uniforms);
  2570. var uniform = uniformData[fullName];
  2571. uniformGroup.data[name] = uniform;
  2572. uniformGroup.gl = gl;
  2573. Object.defineProperty(uniformGroup, name, {
  2574. get: generateGetter(name),
  2575. set: generateSetter(name, uniform)
  2576. });
  2577. }
  2578. return uniforms;
  2579. };
  2580. var generateGetter = function (name) {
  2581. return function () {
  2582. return this.data[name].value;
  2583. };
  2584. };
  2585. var GLSL_SINGLE_SETTERS = {
  2586. float: function setSingleFloat(gl, location, value) { gl.uniform1f(location, value); },
  2587. vec2: function setSingleVec2(gl, location, value) { gl.uniform2f(location, value[0], value[1]); },
  2588. vec3: function setSingleVec3(gl, location, value) { gl.uniform3f(location, value[0], value[1], value[2]); },
  2589. vec4: function setSingleVec4(gl, location, value) { gl.uniform4f(location, value[0], value[1], value[2], value[3]); },
  2590. int: function setSingleInt(gl, location, value) { gl.uniform1i(location, value); },
  2591. ivec2: function setSingleIvec2(gl, location, value) { gl.uniform2i(location, value[0], value[1]); },
  2592. ivec3: function setSingleIvec3(gl, location, value) { gl.uniform3i(location, value[0], value[1], value[2]); },
  2593. ivec4: function setSingleIvec4(gl, location, value) { gl.uniform4i(location, value[0], value[1], value[2], value[3]); },
  2594. bool: function setSingleBool(gl, location, value) { gl.uniform1i(location, value); },
  2595. bvec2: function setSingleBvec2(gl, location, value) { gl.uniform2i(location, value[0], value[1]); },
  2596. bvec3: function setSingleBvec3(gl, location, value) { gl.uniform3i(location, value[0], value[1], value[2]); },
  2597. bvec4: function setSingleBvec4(gl, location, value) { gl.uniform4i(location, value[0], value[1], value[2], value[3]); },
  2598. mat2: function setSingleMat2(gl, location, value) { gl.uniformMatrix2fv(location, false, value); },
  2599. mat3: function setSingleMat3(gl, location, value) { gl.uniformMatrix3fv(location, false, value); },
  2600. mat4: function setSingleMat4(gl, location, value) { gl.uniformMatrix4fv(location, false, value); },
  2601. sampler2D: function setSingleSampler2D(gl, location, value) { gl.uniform1i(location, value); },
  2602. };
  2603. var GLSL_ARRAY_SETTERS = {
  2604. float: function setFloatArray(gl, location, value) { gl.uniform1fv(location, value); },
  2605. vec2: function setVec2Array(gl, location, value) { gl.uniform2fv(location, value); },
  2606. vec3: function setVec3Array(gl, location, value) { gl.uniform3fv(location, value); },
  2607. vec4: function setVec4Array(gl, location, value) { gl.uniform4fv(location, value); },
  2608. int: function setIntArray(gl, location, value) { gl.uniform1iv(location, value); },
  2609. ivec2: function setIvec2Array(gl, location, value) { gl.uniform2iv(location, value); },
  2610. ivec3: function setIvec3Array(gl, location, value) { gl.uniform3iv(location, value); },
  2611. ivec4: function setIvec4Array(gl, location, value) { gl.uniform4iv(location, value); },
  2612. bool: function setBoolArray(gl, location, value) { gl.uniform1iv(location, value); },
  2613. bvec2: function setBvec2Array(gl, location, value) { gl.uniform2iv(location, value); },
  2614. bvec3: function setBvec3Array(gl, location, value) { gl.uniform3iv(location, value); },
  2615. bvec4: function setBvec4Array(gl, location, value) { gl.uniform4iv(location, value); },
  2616. sampler2D: function setSampler2DArray(gl, location, value) { gl.uniform1iv(location, value); },
  2617. };
  2618. function generateSetter(name, uniform) {
  2619. return function (value) {
  2620. this.data[name].value = value;
  2621. var location = this.data[name].location;
  2622. if (uniform.size === 1) {
  2623. GLSL_SINGLE_SETTERS[uniform.type](this.gl, location, value);
  2624. }
  2625. else {
  2626. // glslSetArray(gl, location, type, value) {
  2627. GLSL_ARRAY_SETTERS[uniform.type](this.gl, location, value);
  2628. }
  2629. };
  2630. }
  2631. function getUniformGroup(nameTokens, uniform) {
  2632. var cur = uniform;
  2633. for (var i = 0; i < nameTokens.length - 1; i++) {
  2634. var o = cur[nameTokens[i]] || { data: {} };
  2635. cur[nameTokens[i]] = o;
  2636. cur = o;
  2637. }
  2638. return cur;
  2639. }
  2640. module.exports = generateUniformAccessObject;
  2641. }, {}], 22: [function (require, module, exports) {
  2642. module.exports = {
  2643. compileProgram: require('./compileProgram'),
  2644. defaultValue: require('./defaultValue'),
  2645. extractAttributes: require('./extractAttributes'),
  2646. extractUniforms: require('./extractUniforms'),
  2647. generateUniformAccessObject: require('./generateUniformAccessObject'),
  2648. setPrecision: require('./setPrecision'),
  2649. mapSize: require('./mapSize'),
  2650. mapType: require('./mapType')
  2651. };
  2652. }, { "./compileProgram": 17, "./defaultValue": 18, "./extractAttributes": 19, "./extractUniforms": 20, "./generateUniformAccessObject": 21, "./mapSize": 23, "./mapType": 24, "./setPrecision": 25 }], 23: [function (require, module, exports) {
  2653. /**
  2654. * @class
  2655. * @memberof PIXI.glCore.shader
  2656. * @param type {String}
  2657. * @return {Number}
  2658. */
  2659. var mapSize = function (type) {
  2660. return GLSL_TO_SIZE[type];
  2661. };
  2662. var GLSL_TO_SIZE = {
  2663. 'float': 1,
  2664. 'vec2': 2,
  2665. 'vec3': 3,
  2666. 'vec4': 4,
  2667. 'int': 1,
  2668. 'ivec2': 2,
  2669. 'ivec3': 3,
  2670. 'ivec4': 4,
  2671. 'bool': 1,
  2672. 'bvec2': 2,
  2673. 'bvec3': 3,
  2674. 'bvec4': 4,
  2675. 'mat2': 4,
  2676. 'mat3': 9,
  2677. 'mat4': 16,
  2678. 'sampler2D': 1
  2679. };
  2680. module.exports = mapSize;
  2681. }, {}], 24: [function (require, module, exports) {
  2682. var mapType = function (gl, type) {
  2683. if (!GL_TABLE) {
  2684. var typeNames = Object.keys(GL_TO_GLSL_TYPES);
  2685. GL_TABLE = {};
  2686. for (var i = 0; i < typeNames.length; ++i) {
  2687. var tn = typeNames[i];
  2688. GL_TABLE[gl[tn]] = GL_TO_GLSL_TYPES[tn];
  2689. }
  2690. }
  2691. return GL_TABLE[type];
  2692. };
  2693. var GL_TABLE = null;
  2694. var GL_TO_GLSL_TYPES = {
  2695. 'FLOAT': 'float',
  2696. 'FLOAT_VEC2': 'vec2',
  2697. 'FLOAT_VEC3': 'vec3',
  2698. 'FLOAT_VEC4': 'vec4',
  2699. 'INT': 'int',
  2700. 'INT_VEC2': 'ivec2',
  2701. 'INT_VEC3': 'ivec3',
  2702. 'INT_VEC4': 'ivec4',
  2703. 'BOOL': 'bool',
  2704. 'BOOL_VEC2': 'bvec2',
  2705. 'BOOL_VEC3': 'bvec3',
  2706. 'BOOL_VEC4': 'bvec4',
  2707. 'FLOAT_MAT2': 'mat2',
  2708. 'FLOAT_MAT3': 'mat3',
  2709. 'FLOAT_MAT4': 'mat4',
  2710. 'SAMPLER_2D': 'sampler2D'
  2711. };
  2712. module.exports = mapType;
  2713. }, {}], 25: [function (require, module, exports) {
  2714. /**
  2715. * Sets the float precision on the shader. If the precision is already present this function will do nothing
  2716. * @param {string} src the shader source
  2717. * @param {string} precision The float precision of the shader. Options are 'lowp', 'mediump' or 'highp'.
  2718. *
  2719. * @return {string} modified shader source
  2720. */
  2721. var setPrecision = function (src, precision) {
  2722. if (src.substring(0, 9) !== 'precision') {
  2723. return 'precision ' + precision + ' float;\n' + src;
  2724. }
  2725. return src;
  2726. };
  2727. module.exports = setPrecision;
  2728. }, {}], 26: [function (require, module, exports) {
  2729. // shim for using process in browser
  2730. var process = module.exports = {};
  2731. // cached from whatever global is present so that test runners that stub it
  2732. // don't break things. But we need to wrap it in a try catch in case it is
  2733. // wrapped in strict mode code which doesn't define any globals. It's inside a
  2734. // function because try/catches deoptimize in certain engines.
  2735. var cachedSetTimeout;
  2736. var cachedClearTimeout;
  2737. function defaultSetTimout() {
  2738. throw new Error('setTimeout has not been defined');
  2739. }
  2740. function defaultClearTimeout() {
  2741. throw new Error('clearTimeout has not been defined');
  2742. }
  2743. (function () {
  2744. try {
  2745. if (typeof setTimeout === 'function') {
  2746. cachedSetTimeout = setTimeout;
  2747. } else {
  2748. cachedSetTimeout = defaultSetTimout;
  2749. }
  2750. } catch (e) {
  2751. cachedSetTimeout = defaultSetTimout;
  2752. }
  2753. try {
  2754. if (typeof clearTimeout === 'function') {
  2755. cachedClearTimeout = clearTimeout;
  2756. } else {
  2757. cachedClearTimeout = defaultClearTimeout;
  2758. }
  2759. } catch (e) {
  2760. cachedClearTimeout = defaultClearTimeout;
  2761. }
  2762. }())
  2763. function runTimeout(fun) {
  2764. if (cachedSetTimeout === setTimeout) {
  2765. //normal enviroments in sane situations
  2766. return setTimeout(fun, 0);
  2767. }
  2768. // if setTimeout wasn't available but was latter defined
  2769. if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
  2770. cachedSetTimeout = setTimeout;
  2771. return setTimeout(fun, 0);
  2772. }
  2773. try {
  2774. // when when somebody has screwed with setTimeout but no I.E. maddness
  2775. return cachedSetTimeout(fun, 0);
  2776. } catch (e) {
  2777. try {
  2778. // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
  2779. return cachedSetTimeout.call(null, fun, 0);
  2780. } catch (e) {
  2781. // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error
  2782. return cachedSetTimeout.call(this, fun, 0);
  2783. }
  2784. }
  2785. }
  2786. function runClearTimeout(marker) {
  2787. if (cachedClearTimeout === clearTimeout) {
  2788. //normal enviroments in sane situations
  2789. return clearTimeout(marker);
  2790. }
  2791. // if clearTimeout wasn't available but was latter defined
  2792. if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
  2793. cachedClearTimeout = clearTimeout;
  2794. return clearTimeout(marker);
  2795. }
  2796. try {
  2797. // when when somebody has screwed with setTimeout but no I.E. maddness
  2798. return cachedClearTimeout(marker);
  2799. } catch (e) {
  2800. try {
  2801. // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
  2802. return cachedClearTimeout.call(null, marker);
  2803. } catch (e) {
  2804. // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error.
  2805. // Some versions of I.E. have different rules for clearTimeout vs setTimeout
  2806. return cachedClearTimeout.call(this, marker);
  2807. }
  2808. }
  2809. }
  2810. var queue = [];
  2811. var draining = false;
  2812. var currentQueue;
  2813. var queueIndex = -1;
  2814. function cleanUpNextTick() {
  2815. if (!draining || !currentQueue) {
  2816. return;
  2817. }
  2818. draining = false;
  2819. if (currentQueue.length) {
  2820. queue = currentQueue.concat(queue);
  2821. } else {
  2822. queueIndex = -1;
  2823. }
  2824. if (queue.length) {
  2825. drainQueue();
  2826. }
  2827. }
  2828. function drainQueue() {
  2829. if (draining) {
  2830. return;
  2831. }
  2832. var timeout = runTimeout(cleanUpNextTick);
  2833. draining = true;
  2834. var len = queue.length;
  2835. while (len) {
  2836. currentQueue = queue;
  2837. queue = [];
  2838. while (++queueIndex < len) {
  2839. if (currentQueue) {
  2840. currentQueue[queueIndex].run();
  2841. }
  2842. }
  2843. queueIndex = -1;
  2844. len = queue.length;
  2845. }
  2846. currentQueue = null;
  2847. draining = false;
  2848. runClearTimeout(timeout);
  2849. }
  2850. process.nextTick = function (fun) {
  2851. var args = new Array(arguments.length - 1);
  2852. if (arguments.length > 1) {
  2853. for (var i = 1; i < arguments.length; i++) {
  2854. args[i - 1] = arguments[i];
  2855. }
  2856. }
  2857. queue.push(new Item(fun, args));
  2858. if (queue.length === 1 && !draining) {
  2859. runTimeout(drainQueue);
  2860. }
  2861. };
  2862. // v8 likes predictible objects
  2863. function Item(fun, array) {
  2864. this.fun = fun;
  2865. this.array = array;
  2866. }
  2867. Item.prototype.run = function () {
  2868. this.fun.apply(null, this.array);
  2869. };
  2870. process.title = 'browser';
  2871. process.browser = true;
  2872. process.env = {};
  2873. process.argv = [];
  2874. process.version = ''; // empty string to avoid regexp issues
  2875. process.versions = {};
  2876. function noop() { }
  2877. process.on = noop;
  2878. process.addListener = noop;
  2879. process.once = noop;
  2880. process.off = noop;
  2881. process.removeListener = noop;
  2882. process.removeAllListeners = noop;
  2883. process.emit = noop;
  2884. process.prependListener = noop;
  2885. process.prependOnceListener = noop;
  2886. process.listeners = function (name) { return [] }
  2887. process.binding = function (name) {
  2888. throw new Error('process.binding is not supported');
  2889. };
  2890. process.cwd = function () { return '/' };
  2891. process.chdir = function (dir) {
  2892. throw new Error('process.chdir is not supported');
  2893. };
  2894. process.umask = function () { return 0; };
  2895. }, {}], 27: [function (require, module, exports) {
  2896. (function (global) {
  2897. /*! https://mths.be/punycode v1.4.1 by @mathias */
  2898. ; (function (root) {
  2899. /** Detect free variables */
  2900. var freeExports = typeof exports == 'object' && exports &&
  2901. !exports.nodeType && exports;
  2902. var freeModule = typeof module == 'object' && module &&
  2903. !module.nodeType && module;
  2904. var freeGlobal = typeof global == 'object' && global;
  2905. if (
  2906. freeGlobal.global === freeGlobal ||
  2907. freeGlobal.window === freeGlobal ||
  2908. freeGlobal.self === freeGlobal
  2909. ) {
  2910. root = freeGlobal;
  2911. }
  2912. /**
  2913. * The `punycode` object.
  2914. * @name punycode
  2915. * @type Object
  2916. */
  2917. var punycode,
  2918. /** Highest positive signed 32-bit float value */
  2919. maxInt = 2147483647, // aka. 0x7FFFFFFF or 2^31-1
  2920. /** Bootstring parameters */
  2921. base = 36,
  2922. tMin = 1,
  2923. tMax = 26,
  2924. skew = 38,
  2925. damp = 700,
  2926. initialBias = 72,
  2927. initialN = 128, // 0x80
  2928. delimiter = '-', // '\x2D'
  2929. /** Regular expressions */
  2930. regexPunycode = /^xn--/,
  2931. regexNonASCII = /[^\x20-\x7E]/, // unprintable ASCII chars + non-ASCII chars
  2932. regexSeparators = /[\x2E\u3002\uFF0E\uFF61]/g, // RFC 3490 separators
  2933. /** Error messages */
  2934. errors = {
  2935. 'overflow': 'Overflow: input needs wider integers to process',
  2936. 'not-basic': 'Illegal input >= 0x80 (not a basic code point)',
  2937. 'invalid-input': 'Invalid input'
  2938. },
  2939. /** Convenience shortcuts */
  2940. baseMinusTMin = base - tMin,
  2941. floor = Math.floor,
  2942. stringFromCharCode = String.fromCharCode,
  2943. /** Temporary variable */
  2944. key;
  2945. /*--------------------------------------------------------------------------*/
  2946. /**
  2947. * A generic error utility function.
  2948. * @private
  2949. * @param {String} type The error type.
  2950. * @returns {Error} Throws a `RangeError` with the applicable error message.
  2951. */
  2952. function error(type) {
  2953. throw new RangeError(errors[type]);
  2954. }
  2955. /**
  2956. * A generic `Array#map` utility function.
  2957. * @private
  2958. * @param {Array} array The array to iterate over.
  2959. * @param {Function} callback The function that gets called for every array
  2960. * item.
  2961. * @returns {Array} A new array of values returned by the callback function.
  2962. */
  2963. function map(array, fn) {
  2964. var length = array.length;
  2965. var result = [];
  2966. while (length--) {
  2967. result[length] = fn(array[length]);
  2968. }
  2969. return result;
  2970. }
  2971. /**
  2972. * A simple `Array#map`-like wrapper to work with domain name strings or email
  2973. * addresses.
  2974. * @private
  2975. * @param {String} domain The domain name or email address.
  2976. * @param {Function} callback The function that gets called for every
  2977. * character.
  2978. * @returns {Array} A new string of characters returned by the callback
  2979. * function.
  2980. */
  2981. function mapDomain(string, fn) {
  2982. var parts = string.split('@');
  2983. var result = '';
  2984. if (parts.length > 1) {
  2985. // In email addresses, only the domain name should be punycoded. Leave
  2986. // the local part (i.e. everything up to `@`) intact.
  2987. result = parts[0] + '@';
  2988. string = parts[1];
  2989. }
  2990. // Avoid `split(regex)` for IE8 compatibility. See #17.
  2991. string = string.replace(regexSeparators, '\x2E');
  2992. var labels = string.split('.');
  2993. var encoded = map(labels, fn).join('.');
  2994. return result + encoded;
  2995. }
  2996. /**
  2997. * Creates an array containing the numeric code points of each Unicode
  2998. * character in the string. While JavaScript uses UCS-2 internally,
  2999. * this function will convert a pair of surrogate halves (each of which
  3000. * UCS-2 exposes as separate characters) into a single code point,
  3001. * matching UTF-16.
  3002. * @see `punycode.ucs2.encode`
  3003. * @see <https://mathiasbynens.be/notes/javascript-encoding>
  3004. * @memberOf punycode.ucs2
  3005. * @name decode
  3006. * @param {String} string The Unicode input string (UCS-2).
  3007. * @returns {Array} The new array of code points.
  3008. */
  3009. function ucs2decode(string) {
  3010. var output = [],
  3011. counter = 0,
  3012. length = string.length,
  3013. value,
  3014. extra;
  3015. while (counter < length) {
  3016. value = string.charCodeAt(counter++);
  3017. if (value >= 0xD800 && value <= 0xDBFF && counter < length) {
  3018. // high surrogate, and there is a next character
  3019. extra = string.charCodeAt(counter++);
  3020. if ((extra & 0xFC00) == 0xDC00) { // low surrogate
  3021. output.push(((value & 0x3FF) << 10) + (extra & 0x3FF) + 0x10000);
  3022. } else {
  3023. // unmatched surrogate; only append this code unit, in case the next
  3024. // code unit is the high surrogate of a surrogate pair
  3025. output.push(value);
  3026. counter--;
  3027. }
  3028. } else {
  3029. output.push(value);
  3030. }
  3031. }
  3032. return output;
  3033. }
  3034. /**
  3035. * Creates a string based on an array of numeric code points.
  3036. * @see `punycode.ucs2.decode`
  3037. * @memberOf punycode.ucs2
  3038. * @name encode
  3039. * @param {Array} codePoints The array of numeric code points.
  3040. * @returns {String} The new Unicode string (UCS-2).
  3041. */
  3042. function ucs2encode(array) {
  3043. return map(array, function (value) {
  3044. var output = '';
  3045. if (value > 0xFFFF) {
  3046. value -= 0x10000;
  3047. output += stringFromCharCode(value >>> 10 & 0x3FF | 0xD800);
  3048. value = 0xDC00 | value & 0x3FF;
  3049. }
  3050. output += stringFromCharCode(value);
  3051. return output;
  3052. }).join('');
  3053. }
  3054. /**
  3055. * Converts a basic code point into a digit/integer.
  3056. * @see `digitToBasic()`
  3057. * @private
  3058. * @param {Number} codePoint The basic numeric code point value.
  3059. * @returns {Number} The numeric value of a basic code point (for use in
  3060. * representing integers) in the range `0` to `base - 1`, or `base` if
  3061. * the code point does not represent a value.
  3062. */
  3063. function basicToDigit(codePoint) {
  3064. if (codePoint - 48 < 10) {
  3065. return codePoint - 22;
  3066. }
  3067. if (codePoint - 65 < 26) {
  3068. return codePoint - 65;
  3069. }
  3070. if (codePoint - 97 < 26) {
  3071. return codePoint - 97;
  3072. }
  3073. return base;
  3074. }
  3075. /**
  3076. * Converts a digit/integer into a basic code point.
  3077. * @see `basicToDigit()`
  3078. * @private
  3079. * @param {Number} digit The numeric value of a basic code point.
  3080. * @returns {Number} The basic code point whose value (when used for
  3081. * representing integers) is `digit`, which needs to be in the range
  3082. * `0` to `base - 1`. If `flag` is non-zero, the uppercase form is
  3083. * used; else, the lowercase form is used. The behavior is undefined
  3084. * if `flag` is non-zero and `digit` has no uppercase form.
  3085. */
  3086. function digitToBasic(digit, flag) {
  3087. // 0..25 map to ASCII a..z or A..Z
  3088. // 26..35 map to ASCII 0..9
  3089. return digit + 22 + 75 * (digit < 26) - ((flag != 0) << 5);
  3090. }
  3091. /**
  3092. * Bias adaptation function as per section 3.4 of RFC 3492.
  3093. * https://tools.ietf.org/html/rfc3492#section-3.4
  3094. * @private
  3095. */
  3096. function adapt(delta, numPoints, firstTime) {
  3097. var k = 0;
  3098. delta = firstTime ? floor(delta / damp) : delta >> 1;
  3099. delta += floor(delta / numPoints);
  3100. for (/* no initialization */; delta > baseMinusTMin * tMax >> 1; k += base) {
  3101. delta = floor(delta / baseMinusTMin);
  3102. }
  3103. return floor(k + (baseMinusTMin + 1) * delta / (delta + skew));
  3104. }
  3105. /**
  3106. * Converts a Punycode string of ASCII-only symbols to a string of Unicode
  3107. * symbols.
  3108. * @memberOf punycode
  3109. * @param {String} input The Punycode string of ASCII-only symbols.
  3110. * @returns {String} The resulting string of Unicode symbols.
  3111. */
  3112. function decode(input) {
  3113. // Don't use UCS-2
  3114. var output = [],
  3115. inputLength = input.length,
  3116. out,
  3117. i = 0,
  3118. n = initialN,
  3119. bias = initialBias,
  3120. basic,
  3121. j,
  3122. index,
  3123. oldi,
  3124. w,
  3125. k,
  3126. digit,
  3127. t,
  3128. /** Cached calculation results */
  3129. baseMinusT;
  3130. // Handle the basic code points: let `basic` be the number of input code
  3131. // points before the last delimiter, or `0` if there is none, then copy
  3132. // the first basic code points to the output.
  3133. basic = input.lastIndexOf(delimiter);
  3134. if (basic < 0) {
  3135. basic = 0;
  3136. }
  3137. for (j = 0; j < basic; ++j) {
  3138. // if it's not a basic code point
  3139. if (input.charCodeAt(j) >= 0x80) {
  3140. error('not-basic');
  3141. }
  3142. output.push(input.charCodeAt(j));
  3143. }
  3144. // Main decoding loop: start just after the last delimiter if any basic code
  3145. // points were copied; start at the beginning otherwise.
  3146. for (index = basic > 0 ? basic + 1 : 0; index < inputLength; /* no final expression */) {
  3147. // `index` is the index of the next character to be consumed.
  3148. // Decode a generalized variable-length integer into `delta`,
  3149. // which gets added to `i`. The overflow checking is easier
  3150. // if we increase `i` as we go, then subtract off its starting
  3151. // value at the end to obtain `delta`.
  3152. for (oldi = i, w = 1, k = base; /* no condition */; k += base) {
  3153. if (index >= inputLength) {
  3154. error('invalid-input');
  3155. }
  3156. digit = basicToDigit(input.charCodeAt(index++));
  3157. if (digit >= base || digit > floor((maxInt - i) / w)) {
  3158. error('overflow');
  3159. }
  3160. i += digit * w;
  3161. t = k <= bias ? tMin : (k >= bias + tMax ? tMax : k - bias);
  3162. if (digit < t) {
  3163. break;
  3164. }
  3165. baseMinusT = base - t;
  3166. if (w > floor(maxInt / baseMinusT)) {
  3167. error('overflow');
  3168. }
  3169. w *= baseMinusT;
  3170. }
  3171. out = output.length + 1;
  3172. bias = adapt(i - oldi, out, oldi == 0);
  3173. // `i` was supposed to wrap around from `out` to `0`,
  3174. // incrementing `n` each time, so we'll fix that now:
  3175. if (floor(i / out) > maxInt - n) {
  3176. error('overflow');
  3177. }
  3178. n += floor(i / out);
  3179. i %= out;
  3180. // Insert `n` at position `i` of the output
  3181. output.splice(i++, 0, n);
  3182. }
  3183. return ucs2encode(output);
  3184. }
  3185. /**
  3186. * Converts a string of Unicode symbols (e.g. a domain name label) to a
  3187. * Punycode string of ASCII-only symbols.
  3188. * @memberOf punycode
  3189. * @param {String} input The string of Unicode symbols.
  3190. * @returns {String} The resulting Punycode string of ASCII-only symbols.
  3191. */
  3192. function encode(input) {
  3193. var n,
  3194. delta,
  3195. handledCPCount,
  3196. basicLength,
  3197. bias,
  3198. j,
  3199. m,
  3200. q,
  3201. k,
  3202. t,
  3203. currentValue,
  3204. output = [],
  3205. /** `inputLength` will hold the number of code points in `input`. */
  3206. inputLength,
  3207. /** Cached calculation results */
  3208. handledCPCountPlusOne,
  3209. baseMinusT,
  3210. qMinusT;
  3211. // Convert the input in UCS-2 to Unicode
  3212. input = ucs2decode(input);
  3213. // Cache the length
  3214. inputLength = input.length;
  3215. // Initialize the state
  3216. n = initialN;
  3217. delta = 0;
  3218. bias = initialBias;
  3219. // Handle the basic code points
  3220. for (j = 0; j < inputLength; ++j) {
  3221. currentValue = input[j];
  3222. if (currentValue < 0x80) {
  3223. output.push(stringFromCharCode(currentValue));
  3224. }
  3225. }
  3226. handledCPCount = basicLength = output.length;
  3227. // `handledCPCount` is the number of code points that have been handled;
  3228. // `basicLength` is the number of basic code points.
  3229. // Finish the basic string - if it is not empty - with a delimiter
  3230. if (basicLength) {
  3231. output.push(delimiter);
  3232. }
  3233. // Main encoding loop:
  3234. while (handledCPCount < inputLength) {
  3235. // All non-basic code points < n have been handled already. Find the next
  3236. // larger one:
  3237. for (m = maxInt, j = 0; j < inputLength; ++j) {
  3238. currentValue = input[j];
  3239. if (currentValue >= n && currentValue < m) {
  3240. m = currentValue;
  3241. }
  3242. }
  3243. // Increase `delta` enough to advance the decoder's <n,i> state to <m,0>,
  3244. // but guard against overflow
  3245. handledCPCountPlusOne = handledCPCount + 1;
  3246. if (m - n > floor((maxInt - delta) / handledCPCountPlusOne)) {
  3247. error('overflow');
  3248. }
  3249. delta += (m - n) * handledCPCountPlusOne;
  3250. n = m;
  3251. for (j = 0; j < inputLength; ++j) {
  3252. currentValue = input[j];
  3253. if (currentValue < n && ++delta > maxInt) {
  3254. error('overflow');
  3255. }
  3256. if (currentValue == n) {
  3257. // Represent delta as a generalized variable-length integer
  3258. for (q = delta, k = base; /* no condition */; k += base) {
  3259. t = k <= bias ? tMin : (k >= bias + tMax ? tMax : k - bias);
  3260. if (q < t) {
  3261. break;
  3262. }
  3263. qMinusT = q - t;
  3264. baseMinusT = base - t;
  3265. output.push(
  3266. stringFromCharCode(digitToBasic(t + qMinusT % baseMinusT, 0))
  3267. );
  3268. q = floor(qMinusT / baseMinusT);
  3269. }
  3270. output.push(stringFromCharCode(digitToBasic(q, 0)));
  3271. bias = adapt(delta, handledCPCountPlusOne, handledCPCount == basicLength);
  3272. delta = 0;
  3273. ++handledCPCount;
  3274. }
  3275. }
  3276. ++delta;
  3277. ++n;
  3278. }
  3279. return output.join('');
  3280. }
  3281. /**
  3282. * Converts a Punycode string representing a domain name or an email address
  3283. * to Unicode. Only the Punycoded parts of the input will be converted, i.e.
  3284. * it doesn't matter if you call it on a string that has already been
  3285. * converted to Unicode.
  3286. * @memberOf punycode
  3287. * @param {String} input The Punycoded domain name or email address to
  3288. * convert to Unicode.
  3289. * @returns {String} The Unicode representation of the given Punycode
  3290. * string.
  3291. */
  3292. function toUnicode(input) {
  3293. return mapDomain(input, function (string) {
  3294. return regexPunycode.test(string)
  3295. ? decode(string.slice(4).toLowerCase())
  3296. : string;
  3297. });
  3298. }
  3299. /**
  3300. * Converts a Unicode string representing a domain name or an email address to
  3301. * Punycode. Only the non-ASCII parts of the domain name will be converted,
  3302. * i.e. it doesn't matter if you call it with a domain that's already in
  3303. * ASCII.
  3304. * @memberOf punycode
  3305. * @param {String} input The domain name or email address to convert, as a
  3306. * Unicode string.
  3307. * @returns {String} The Punycode representation of the given domain name or
  3308. * email address.
  3309. */
  3310. function toASCII(input) {
  3311. return mapDomain(input, function (string) {
  3312. return regexNonASCII.test(string)
  3313. ? 'xn--' + encode(string)
  3314. : string;
  3315. });
  3316. }
  3317. /*--------------------------------------------------------------------------*/
  3318. /** Define the public API */
  3319. punycode = {
  3320. /**
  3321. * A string representing the current Punycode.js version number.
  3322. * @memberOf punycode
  3323. * @type String
  3324. */
  3325. 'version': '1.4.1',
  3326. /**
  3327. * An object of methods to convert from JavaScript's internal character
  3328. * representation (UCS-2) to Unicode code points, and back.
  3329. * @see <https://mathiasbynens.be/notes/javascript-encoding>
  3330. * @memberOf punycode
  3331. * @type Object
  3332. */
  3333. 'ucs2': {
  3334. 'decode': ucs2decode,
  3335. 'encode': ucs2encode
  3336. },
  3337. 'decode': decode,
  3338. 'encode': encode,
  3339. 'toASCII': toASCII,
  3340. 'toUnicode': toUnicode
  3341. };
  3342. /** Expose `punycode` */
  3343. // Some AMD build optimizers, like r.js, check for specific condition patterns
  3344. // like the following:
  3345. if (
  3346. typeof define == 'function' &&
  3347. typeof define.amd == 'object' &&
  3348. define.amd
  3349. ) {
  3350. define('punycode', function () {
  3351. return punycode;
  3352. });
  3353. } else if (freeExports && freeModule) {
  3354. if (module.exports == freeExports) {
  3355. // in Node.js, io.js, or RingoJS v0.8.0+
  3356. freeModule.exports = punycode;
  3357. } else {
  3358. // in Narwhal or RingoJS v0.7.0-
  3359. for (key in punycode) {
  3360. punycode.hasOwnProperty(key) && (freeExports[key] = punycode[key]);
  3361. }
  3362. }
  3363. } else {
  3364. // in Rhino or a web browser
  3365. root.punycode = punycode;
  3366. }
  3367. }(this));
  3368. }).call(this, typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  3369. }, {}], 28: [function (require, module, exports) {
  3370. // Copyright Joyent, Inc. and other Node contributors.
  3371. //
  3372. // Permission is hereby granted, free of charge, to any person obtaining a
  3373. // copy of this software and associated documentation files (the
  3374. // "Software"), to deal in the Software without restriction, including
  3375. // without limitation the rights to use, copy, modify, merge, publish,
  3376. // distribute, sublicense, and/or sell copies of the Software, and to permit
  3377. // persons to whom the Software is furnished to do so, subject to the
  3378. // following conditions:
  3379. //
  3380. // The above copyright notice and this permission notice shall be included
  3381. // in all copies or substantial portions of the Software.
  3382. //
  3383. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  3384. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  3385. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  3386. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  3387. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  3388. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  3389. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  3390. 'use strict';
  3391. // If obj.hasOwnProperty has been overridden, then calling
  3392. // obj.hasOwnProperty(prop) will break.
  3393. // See: https://github.com/joyent/node/issues/1707
  3394. function hasOwnProperty(obj, prop) {
  3395. return Object.prototype.hasOwnProperty.call(obj, prop);
  3396. }
  3397. module.exports = function (qs, sep, eq, options) {
  3398. sep = sep || '&';
  3399. eq = eq || '=';
  3400. var obj = {};
  3401. if (typeof qs !== 'string' || qs.length === 0) {
  3402. return obj;
  3403. }
  3404. var regexp = /\+/g;
  3405. qs = qs.split(sep);
  3406. var maxKeys = 1000;
  3407. if (options && typeof options.maxKeys === 'number') {
  3408. maxKeys = options.maxKeys;
  3409. }
  3410. var len = qs.length;
  3411. // maxKeys <= 0 means that we should not limit keys count
  3412. if (maxKeys > 0 && len > maxKeys) {
  3413. len = maxKeys;
  3414. }
  3415. for (var i = 0; i < len; ++i) {
  3416. var x = qs[i].replace(regexp, '%20'),
  3417. idx = x.indexOf(eq),
  3418. kstr, vstr, k, v;
  3419. if (idx >= 0) {
  3420. kstr = x.substr(0, idx);
  3421. vstr = x.substr(idx + 1);
  3422. } else {
  3423. kstr = x;
  3424. vstr = '';
  3425. }
  3426. k = decodeURIComponent(kstr);
  3427. v = decodeURIComponent(vstr);
  3428. if (!hasOwnProperty(obj, k)) {
  3429. obj[k] = v;
  3430. } else if (isArray(obj[k])) {
  3431. obj[k].push(v);
  3432. } else {
  3433. obj[k] = [obj[k], v];
  3434. }
  3435. }
  3436. return obj;
  3437. };
  3438. var isArray = Array.isArray || function (xs) {
  3439. return Object.prototype.toString.call(xs) === '[object Array]';
  3440. };
  3441. }, {}], 29: [function (require, module, exports) {
  3442. // Copyright Joyent, Inc. and other Node contributors.
  3443. //
  3444. // Permission is hereby granted, free of charge, to any person obtaining a
  3445. // copy of this software and associated documentation files (the
  3446. // "Software"), to deal in the Software without restriction, including
  3447. // without limitation the rights to use, copy, modify, merge, publish,
  3448. // distribute, sublicense, and/or sell copies of the Software, and to permit
  3449. // persons to whom the Software is furnished to do so, subject to the
  3450. // following conditions:
  3451. //
  3452. // The above copyright notice and this permission notice shall be included
  3453. // in all copies or substantial portions of the Software.
  3454. //
  3455. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  3456. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  3457. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  3458. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  3459. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  3460. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  3461. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  3462. 'use strict';
  3463. var stringifyPrimitive = function (v) {
  3464. switch (typeof v) {
  3465. case 'string':
  3466. return v;
  3467. case 'boolean':
  3468. return v ? 'true' : 'false';
  3469. case 'number':
  3470. return isFinite(v) ? v : '';
  3471. default:
  3472. return '';
  3473. }
  3474. };
  3475. module.exports = function (obj, sep, eq, name) {
  3476. sep = sep || '&';
  3477. eq = eq || '=';
  3478. if (obj === null) {
  3479. obj = undefined;
  3480. }
  3481. if (typeof obj === 'object') {
  3482. return map(objectKeys(obj), function (k) {
  3483. var ks = encodeURIComponent(stringifyPrimitive(k)) + eq;
  3484. if (isArray(obj[k])) {
  3485. return map(obj[k], function (v) {
  3486. return ks + encodeURIComponent(stringifyPrimitive(v));
  3487. }).join(sep);
  3488. } else {
  3489. return ks + encodeURIComponent(stringifyPrimitive(obj[k]));
  3490. }
  3491. }).join(sep);
  3492. }
  3493. if (!name) return '';
  3494. return encodeURIComponent(stringifyPrimitive(name)) + eq +
  3495. encodeURIComponent(stringifyPrimitive(obj));
  3496. };
  3497. var isArray = Array.isArray || function (xs) {
  3498. return Object.prototype.toString.call(xs) === '[object Array]';
  3499. };
  3500. function map(xs, f) {
  3501. if (xs.map) return xs.map(f);
  3502. var res = [];
  3503. for (var i = 0; i < xs.length; i++) {
  3504. res.push(f(xs[i], i));
  3505. }
  3506. return res;
  3507. }
  3508. var objectKeys = Object.keys || function (obj) {
  3509. var res = [];
  3510. for (var key in obj) {
  3511. if (Object.prototype.hasOwnProperty.call(obj, key)) res.push(key);
  3512. }
  3513. return res;
  3514. };
  3515. }, {}], 30: [function (require, module, exports) {
  3516. 'use strict';
  3517. exports.decode = exports.parse = require('./decode');
  3518. exports.encode = exports.stringify = require('./encode');
  3519. }, { "./decode": 28, "./encode": 29 }], 31: [function (require, module, exports) {
  3520. 'use strict'
  3521. /**
  3522. * Remove a range of items from an array
  3523. *
  3524. * @function removeItems
  3525. * @param {Array<*>} arr The target array
  3526. * @param {number} startIdx The index to begin removing from (inclusive)
  3527. * @param {number} removeCount How many items to remove
  3528. */
  3529. module.exports = function removeItems(arr, startIdx, removeCount) {
  3530. var i, length = arr.length
  3531. if (startIdx >= length || removeCount === 0) {
  3532. return
  3533. }
  3534. removeCount = (startIdx + removeCount > length ? length - startIdx : removeCount)
  3535. var len = length - removeCount
  3536. for (i = startIdx; i < len; ++i) {
  3537. arr[i] = arr[i + removeCount]
  3538. }
  3539. arr.length = len
  3540. }
  3541. }, {}], 32: [function (require, module, exports) {
  3542. 'use strict';
  3543. exports.__esModule = true;
  3544. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
  3545. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  3546. var _miniSignals = require('mini-signals');
  3547. var _miniSignals2 = _interopRequireDefault(_miniSignals);
  3548. var _parseUri = require('parse-uri');
  3549. var _parseUri2 = _interopRequireDefault(_parseUri);
  3550. var _async = require('./async');
  3551. var async = _interopRequireWildcard(_async);
  3552. var _Resource = require('./Resource');
  3553. var _Resource2 = _interopRequireDefault(_Resource);
  3554. function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
  3555. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  3556. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  3557. // some constants
  3558. var MAX_PROGRESS = 100;
  3559. var rgxExtractUrlHash = /(#[\w-]+)?$/;
  3560. /**
  3561. * Manages the state and loading of multiple resources to load.
  3562. *
  3563. * @class
  3564. */
  3565. var Loader = function () {
  3566. /**
  3567. * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader.
  3568. * @param {number} [concurrency=10] - The number of resources to load concurrently.
  3569. */
  3570. function Loader() {
  3571. var _this = this;
  3572. var baseUrl = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
  3573. var concurrency = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 10;
  3574. _classCallCheck(this, Loader);
  3575. /**
  3576. * The base url for all resources loaded by this loader.
  3577. *
  3578. * @member {string}
  3579. */
  3580. this.baseUrl = baseUrl;
  3581. /**
  3582. * The progress percent of the loader going through the queue.
  3583. *
  3584. * @member {number}
  3585. */
  3586. this.progress = 0;
  3587. /**
  3588. * Loading state of the loader, true if it is currently loading resources.
  3589. *
  3590. * @member {boolean}
  3591. */
  3592. this.loading = false;
  3593. /**
  3594. * A querystring to append to every URL added to the loader.
  3595. *
  3596. * This should be a valid query string *without* the question-mark (`?`). The loader will
  3597. * also *not* escape values for you. Make sure to escape your parameters with
  3598. * [`encodeURIComponent`](https://mdn.io/encodeURIComponent) before assigning this property.
  3599. *
  3600. * @example
  3601. * const loader = new Loader();
  3602. *
  3603. * loader.defaultQueryString = 'user=me&password=secret';
  3604. *
  3605. * // This will request 'image.png?user=me&password=secret'
  3606. * loader.add('image.png').load();
  3607. *
  3608. * loader.reset();
  3609. *
  3610. * // This will request 'image.png?v=1&user=me&password=secret'
  3611. * loader.add('iamge.png?v=1').load();
  3612. */
  3613. this.defaultQueryString = '';
  3614. /**
  3615. * The middleware to run before loading each resource.
  3616. *
  3617. * @member {function[]}
  3618. */
  3619. this._beforeMiddleware = [];
  3620. /**
  3621. * The middleware to run after loading each resource.
  3622. *
  3623. * @member {function[]}
  3624. */
  3625. this._afterMiddleware = [];
  3626. /**
  3627. * The tracks the resources we are currently completing parsing for.
  3628. *
  3629. * @member {Resource[]}
  3630. */
  3631. this._resourcesParsing = [];
  3632. /**
  3633. * The `_loadResource` function bound with this object context.
  3634. *
  3635. * @private
  3636. * @member {function}
  3637. * @param {Resource} r - The resource to load
  3638. * @param {Function} d - The dequeue function
  3639. * @return {undefined}
  3640. */
  3641. this._boundLoadResource = function (r, d) {
  3642. return _this._loadResource(r, d);
  3643. };
  3644. /**
  3645. * The resources waiting to be loaded.
  3646. *
  3647. * @private
  3648. * @member {Resource[]}
  3649. */
  3650. this._queue = async.queue(this._boundLoadResource, concurrency);
  3651. this._queue.pause();
  3652. /**
  3653. * All the resources for this loader keyed by name.
  3654. *
  3655. * @member {object<string, Resource>}
  3656. */
  3657. this.resources = {};
  3658. /**
  3659. * Dispatched once per loaded or errored resource.
  3660. *
  3661. * The callback looks like {@link Loader.OnProgressSignal}.
  3662. *
  3663. * @member {Signal}
  3664. */
  3665. this.onProgress = new _miniSignals2.default();
  3666. /**
  3667. * Dispatched once per errored resource.
  3668. *
  3669. * The callback looks like {@link Loader.OnErrorSignal}.
  3670. *
  3671. * @member {Signal}
  3672. */
  3673. this.onError = new _miniSignals2.default();
  3674. /**
  3675. * Dispatched once per loaded resource.
  3676. *
  3677. * The callback looks like {@link Loader.OnLoadSignal}.
  3678. *
  3679. * @member {Signal}
  3680. */
  3681. this.onLoad = new _miniSignals2.default();
  3682. /**
  3683. * Dispatched when the loader begins to process the queue.
  3684. *
  3685. * The callback looks like {@link Loader.OnStartSignal}.
  3686. *
  3687. * @member {Signal}
  3688. */
  3689. this.onStart = new _miniSignals2.default();
  3690. /**
  3691. * Dispatched when the queued resources all load.
  3692. *
  3693. * The callback looks like {@link Loader.OnCompleteSignal}.
  3694. *
  3695. * @member {Signal}
  3696. */
  3697. this.onComplete = new _miniSignals2.default();
  3698. /**
  3699. * When the progress changes the loader and resource are disaptched.
  3700. *
  3701. * @memberof Loader
  3702. * @callback OnProgressSignal
  3703. * @param {Loader} loader - The loader the progress is advancing on.
  3704. * @param {Resource} resource - The resource that has completed or failed to cause the progress to advance.
  3705. */
  3706. /**
  3707. * When an error occurrs the loader and resource are disaptched.
  3708. *
  3709. * @memberof Loader
  3710. * @callback OnErrorSignal
  3711. * @param {Loader} loader - The loader the error happened in.
  3712. * @param {Resource} resource - The resource that caused the error.
  3713. */
  3714. /**
  3715. * When a load completes the loader and resource are disaptched.
  3716. *
  3717. * @memberof Loader
  3718. * @callback OnLoadSignal
  3719. * @param {Loader} loader - The loader that laoded the resource.
  3720. * @param {Resource} resource - The resource that has completed loading.
  3721. */
  3722. /**
  3723. * When the loader starts loading resources it dispatches this callback.
  3724. *
  3725. * @memberof Loader
  3726. * @callback OnStartSignal
  3727. * @param {Loader} loader - The loader that has started loading resources.
  3728. */
  3729. /**
  3730. * When the loader completes loading resources it dispatches this callback.
  3731. *
  3732. * @memberof Loader
  3733. * @callback OnCompleteSignal
  3734. * @param {Loader} loader - The loader that has finished loading resources.
  3735. */
  3736. }
  3737. /**
  3738. * Adds a resource (or multiple resources) to the loader queue.
  3739. *
  3740. * This function can take a wide variety of different parameters. The only thing that is always
  3741. * required the url to load. All the following will work:
  3742. *
  3743. * ```js
  3744. * loader
  3745. * // normal param syntax
  3746. * .add('key', 'http://...', function () {})
  3747. * .add('http://...', function () {})
  3748. * .add('http://...')
  3749. *
  3750. * // object syntax
  3751. * .add({
  3752. * name: 'key2',
  3753. * url: 'http://...'
  3754. * }, function () {})
  3755. * .add({
  3756. * url: 'http://...'
  3757. * }, function () {})
  3758. * .add({
  3759. * name: 'key3',
  3760. * url: 'http://...'
  3761. * onComplete: function () {}
  3762. * })
  3763. * .add({
  3764. * url: 'https://...',
  3765. * onComplete: function () {},
  3766. * crossOrigin: true
  3767. * })
  3768. *
  3769. * // you can also pass an array of objects or urls or both
  3770. * .add([
  3771. * { name: 'key4', url: 'http://...', onComplete: function () {} },
  3772. * { url: 'http://...', onComplete: function () {} },
  3773. * 'http://...'
  3774. * ])
  3775. *
  3776. * // and you can use both params and options
  3777. * .add('key', 'http://...', { crossOrigin: true }, function () {})
  3778. * .add('http://...', { crossOrigin: true }, function () {});
  3779. * ```
  3780. *
  3781. * @param {string} [name] - The name of the resource to load, if not passed the url is used.
  3782. * @param {string} [url] - The url for this resource, relative to the baseUrl of this loader.
  3783. * @param {object} [options] - The options for the load.
  3784. * @param {boolean} [options.crossOrigin] - Is this request cross-origin? Default is to determine automatically.
  3785. * @param {Resource.LOAD_TYPE} [options.loadType=Resource.LOAD_TYPE.XHR] - How should this resource be loaded?
  3786. * @param {Resource.XHR_RESPONSE_TYPE} [options.xhrType=Resource.XHR_RESPONSE_TYPE.DEFAULT] - How should
  3787. * the data being loaded be interpreted when using XHR?
  3788. * @param {object} [options.metadata] - Extra configuration for middleware and the Resource object.
  3789. * @param {HTMLImageElement|HTMLAudioElement|HTMLVideoElement} [options.metadata.loadElement=null] - The
  3790. * element to use for loading, instead of creating one.
  3791. * @param {boolean} [options.metadata.skipSource=false] - Skips adding source(s) to the load element. This
  3792. * is useful if you want to pass in a `loadElement` that you already added load sources to.
  3793. * @param {function} [cb] - Function to call when this specific resource completes loading.
  3794. * @return {Loader} Returns itself.
  3795. */
  3796. Loader.prototype.add = function add(name, url, options, cb) {
  3797. // special case of an array of objects or urls
  3798. if (Array.isArray(name)) {
  3799. for (var i = 0; i < name.length; ++i) {
  3800. this.add(name[i]);
  3801. }
  3802. return this;
  3803. }
  3804. // if an object is passed instead of params
  3805. if ((typeof name === 'undefined' ? 'undefined' : _typeof(name)) === 'object') {
  3806. cb = url || name.callback || name.onComplete;
  3807. options = name;
  3808. url = name.url;
  3809. name = name.name || name.key || name.url;
  3810. }
  3811. // case where no name is passed shift all args over by one.
  3812. if (typeof url !== 'string') {
  3813. cb = options;
  3814. options = url;
  3815. url = name;
  3816. }
  3817. // now that we shifted make sure we have a proper url.
  3818. if (typeof url !== 'string') {
  3819. throw new Error('No url passed to add resource to loader.');
  3820. }
  3821. // options are optional so people might pass a function and no options
  3822. if (typeof options === 'function') {
  3823. cb = options;
  3824. options = null;
  3825. }
  3826. // if loading already you can only add resources that have a parent.
  3827. if (this.loading && (!options || !options.parentResource)) {
  3828. throw new Error('Cannot add resources while the loader is running.');
  3829. }
  3830. // check if resource already exists.
  3831. if (this.resources[name]) {
  3832. throw new Error('Resource named "' + name + '" already exists.');
  3833. }
  3834. // add base url if this isn't an absolute url
  3835. url = this._prepareUrl(url);
  3836. // create the store the resource
  3837. this.resources[name] = new _Resource2.default(name, url, options);
  3838. if (typeof cb === 'function') {
  3839. this.resources[name].onAfterMiddleware.once(cb);
  3840. }
  3841. // if actively loading, make sure to adjust progress chunks for that parent and its children
  3842. if (this.loading) {
  3843. var parent = options.parentResource;
  3844. var incompleteChildren = [];
  3845. for (var _i = 0; _i < parent.children.length; ++_i) {
  3846. if (!parent.children[_i].isComplete) {
  3847. incompleteChildren.push(parent.children[_i]);
  3848. }
  3849. }
  3850. var fullChunk = parent.progressChunk * (incompleteChildren.length + 1); // +1 for parent
  3851. var eachChunk = fullChunk / (incompleteChildren.length + 2); // +2 for parent & new child
  3852. parent.children.push(this.resources[name]);
  3853. parent.progressChunk = eachChunk;
  3854. for (var _i2 = 0; _i2 < incompleteChildren.length; ++_i2) {
  3855. incompleteChildren[_i2].progressChunk = eachChunk;
  3856. }
  3857. this.resources[name].progressChunk = eachChunk;
  3858. }
  3859. // add the resource to the queue
  3860. this._queue.push(this.resources[name]);
  3861. return this;
  3862. };
  3863. /**
  3864. * Sets up a middleware function that will run *before* the
  3865. * resource is loaded.
  3866. *
  3867. * @method before
  3868. * @param {function} fn - The middleware function to register.
  3869. * @return {Loader} Returns itself.
  3870. */
  3871. Loader.prototype.pre = function pre(fn) {
  3872. this._beforeMiddleware.push(fn);
  3873. return this;
  3874. };
  3875. /**
  3876. * Sets up a middleware function that will run *after* the
  3877. * resource is loaded.
  3878. *
  3879. * @alias use
  3880. * @method after
  3881. * @param {function} fn - The middleware function to register.
  3882. * @return {Loader} Returns itself.
  3883. */
  3884. Loader.prototype.use = function use(fn) {
  3885. this._afterMiddleware.push(fn);
  3886. return this;
  3887. };
  3888. /**
  3889. * Resets the queue of the loader to prepare for a new load.
  3890. *
  3891. * @return {Loader} Returns itself.
  3892. */
  3893. Loader.prototype.reset = function reset() {
  3894. this.progress = 0;
  3895. this.loading = false;
  3896. this._queue.kill();
  3897. this._queue.pause();
  3898. // abort all resource loads
  3899. for (var k in this.resources) {
  3900. var res = this.resources[k];
  3901. if (res._onLoadBinding) {
  3902. res._onLoadBinding.detach();
  3903. }
  3904. if (res.isLoading) {
  3905. res.abort();
  3906. }
  3907. }
  3908. this.resources = {};
  3909. return this;
  3910. };
  3911. /**
  3912. * Starts loading the queued resources.
  3913. *
  3914. * @param {function} [cb] - Optional callback that will be bound to the `complete` event.
  3915. * @return {Loader} Returns itself.
  3916. */
  3917. Loader.prototype.load = function load(cb) {
  3918. // register complete callback if they pass one
  3919. if (typeof cb === 'function') {
  3920. this.onComplete.once(cb);
  3921. }
  3922. // if the queue has already started we are done here
  3923. if (this.loading) {
  3924. return this;
  3925. }
  3926. if (this._queue.idle()) {
  3927. this._onStart();
  3928. this._onComplete();
  3929. } else {
  3930. // distribute progress chunks
  3931. var numTasks = this._queue._tasks.length;
  3932. var chunk = 100 / numTasks;
  3933. for (var i = 0; i < this._queue._tasks.length; ++i) {
  3934. this._queue._tasks[i].data.progressChunk = chunk;
  3935. }
  3936. // notify we are starting
  3937. this._onStart();
  3938. // start loading
  3939. this._queue.resume();
  3940. }
  3941. return this;
  3942. };
  3943. /**
  3944. * The number of resources to load concurrently.
  3945. *
  3946. * @member {number}
  3947. * @default 10
  3948. */
  3949. /**
  3950. * Prepares a url for usage based on the configuration of this object
  3951. *
  3952. * @private
  3953. * @param {string} url - The url to prepare.
  3954. * @return {string} The prepared url.
  3955. */
  3956. Loader.prototype._prepareUrl = function _prepareUrl(url) {
  3957. var parsedUrl = (0, _parseUri2.default)(url, { strictMode: true });
  3958. var result = void 0;
  3959. // absolute url, just use it as is.
  3960. if (parsedUrl.protocol || !parsedUrl.path || url.indexOf('//') === 0) {
  3961. result = url;
  3962. }
  3963. // if baseUrl doesn't end in slash and url doesn't start with slash, then add a slash inbetween
  3964. else if (this.baseUrl.length && this.baseUrl.lastIndexOf('/') !== this.baseUrl.length - 1 && url.charAt(0) !== '/') {
  3965. result = this.baseUrl + '/' + url;
  3966. } else {
  3967. result = this.baseUrl + url;
  3968. }
  3969. // if we need to add a default querystring, there is a bit more work
  3970. if (this.defaultQueryString) {
  3971. var hash = rgxExtractUrlHash.exec(result)[0];
  3972. result = result.substr(0, result.length - hash.length);
  3973. if (result.indexOf('?') !== -1) {
  3974. result += '&' + this.defaultQueryString;
  3975. } else {
  3976. result += '?' + this.defaultQueryString;
  3977. }
  3978. result += hash;
  3979. }
  3980. return result;
  3981. };
  3982. /**
  3983. * Loads a single resource.
  3984. *
  3985. * @private
  3986. * @param {Resource} resource - The resource to load.
  3987. * @param {function} dequeue - The function to call when we need to dequeue this item.
  3988. */
  3989. Loader.prototype._loadResource = function _loadResource(resource, dequeue) {
  3990. var _this2 = this;
  3991. resource._dequeue = dequeue;
  3992. // run before middleware
  3993. async.eachSeries(this._beforeMiddleware, function (fn, next) {
  3994. fn.call(_this2, resource, function () {
  3995. // if the before middleware marks the resource as complete,
  3996. // break and don't process any more before middleware
  3997. next(resource.isComplete ? {} : null);
  3998. });
  3999. }, function () {
  4000. if (resource.isComplete) {
  4001. _this2._onLoad(resource);
  4002. } else {
  4003. resource._onLoadBinding = resource.onComplete.once(_this2._onLoad, _this2);
  4004. resource.load();
  4005. }
  4006. }, true);
  4007. };
  4008. /**
  4009. * Called once loading has started.
  4010. *
  4011. * @private
  4012. */
  4013. Loader.prototype._onStart = function _onStart() {
  4014. this.progress = 0;
  4015. this.loading = true;
  4016. this.onStart.dispatch(this);
  4017. };
  4018. /**
  4019. * Called once each resource has loaded.
  4020. *
  4021. * @private
  4022. */
  4023. Loader.prototype._onComplete = function _onComplete() {
  4024. this.progress = MAX_PROGRESS;
  4025. this.loading = false;
  4026. this.onComplete.dispatch(this, this.resources);
  4027. };
  4028. /**
  4029. * Called each time a resources is loaded.
  4030. *
  4031. * @private
  4032. * @param {Resource} resource - The resource that was loaded
  4033. */
  4034. Loader.prototype._onLoad = function _onLoad(resource) {
  4035. var _this3 = this;
  4036. resource._onLoadBinding = null;
  4037. // remove this resource from the async queue, and add it to our list of resources that are being parsed
  4038. this._resourcesParsing.push(resource);
  4039. resource._dequeue();
  4040. // run all the after middleware for this resource
  4041. async.eachSeries(this._afterMiddleware, function (fn, next) {
  4042. fn.call(_this3, resource, next);
  4043. }, function () {
  4044. resource.onAfterMiddleware.dispatch(resource);
  4045. _this3.progress += resource.progressChunk;
  4046. _this3.onProgress.dispatch(_this3, resource);
  4047. if (resource.error) {
  4048. _this3.onError.dispatch(resource.error, _this3, resource);
  4049. } else {
  4050. _this3.onLoad.dispatch(_this3, resource);
  4051. }
  4052. _this3._resourcesParsing.splice(_this3._resourcesParsing.indexOf(resource), 1);
  4053. // do completion check
  4054. if (_this3._queue.idle() && _this3._resourcesParsing.length === 0) {
  4055. _this3._onComplete();
  4056. }
  4057. }, true);
  4058. };
  4059. _createClass(Loader, [{
  4060. key: 'concurrency',
  4061. get: function get() {
  4062. return this._queue.concurrency;
  4063. }
  4064. // eslint-disable-next-line require-jsdoc
  4065. ,
  4066. set: function set(concurrency) {
  4067. this._queue.concurrency = concurrency;
  4068. }
  4069. }]);
  4070. return Loader;
  4071. }();
  4072. exports.default = Loader;
  4073. }, { "./Resource": 33, "./async": 34, "mini-signals": 5, "parse-uri": 7 }], 33: [function (require, module, exports) {
  4074. 'use strict';
  4075. exports.__esModule = true;
  4076. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  4077. var _parseUri = require('parse-uri');
  4078. var _parseUri2 = _interopRequireDefault(_parseUri);
  4079. var _miniSignals = require('mini-signals');
  4080. var _miniSignals2 = _interopRequireDefault(_miniSignals);
  4081. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  4082. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  4083. // tests is CORS is supported in XHR, if not we need to use XDR
  4084. var useXdr = !!(window.XDomainRequest && !('withCredentials' in new XMLHttpRequest()));
  4085. var tempAnchor = null;
  4086. // some status constants
  4087. var STATUS_NONE = 0;
  4088. var STATUS_OK = 200;
  4089. var STATUS_EMPTY = 204;
  4090. var STATUS_IE_BUG_EMPTY = 1223;
  4091. var STATUS_TYPE_OK = 2;
  4092. // noop
  4093. function _noop() { } /* empty */
  4094. /**
  4095. * Manages the state and loading of a resource and all child resources.
  4096. *
  4097. * @class
  4098. */
  4099. var Resource = function () {
  4100. /**
  4101. * Sets the load type to be used for a specific extension.
  4102. *
  4103. * @static
  4104. * @param {string} extname - The extension to set the type for, e.g. "png" or "fnt"
  4105. * @param {Resource.LOAD_TYPE} loadType - The load type to set it to.
  4106. */
  4107. Resource.setExtensionLoadType = function setExtensionLoadType(extname, loadType) {
  4108. setExtMap(Resource._loadTypeMap, extname, loadType);
  4109. };
  4110. /**
  4111. * Sets the load type to be used for a specific extension.
  4112. *
  4113. * @static
  4114. * @param {string} extname - The extension to set the type for, e.g. "png" or "fnt"
  4115. * @param {Resource.XHR_RESPONSE_TYPE} xhrType - The xhr type to set it to.
  4116. */
  4117. Resource.setExtensionXhrType = function setExtensionXhrType(extname, xhrType) {
  4118. setExtMap(Resource._xhrTypeMap, extname, xhrType);
  4119. };
  4120. /**
  4121. * @param {string} name - The name of the resource to load.
  4122. * @param {string|string[]} url - The url for this resource, for audio/video loads you can pass
  4123. * an array of sources.
  4124. * @param {object} [options] - The options for the load.
  4125. * @param {string|boolean} [options.crossOrigin] - Is this request cross-origin? Default is to
  4126. * determine automatically.
  4127. * @param {Resource.LOAD_TYPE} [options.loadType=Resource.LOAD_TYPE.XHR] - How should this resource
  4128. * be loaded?
  4129. * @param {Resource.XHR_RESPONSE_TYPE} [options.xhrType=Resource.XHR_RESPONSE_TYPE.DEFAULT] - How
  4130. * should the data being loaded be interpreted when using XHR?
  4131. * @param {object} [options.metadata] - Extra configuration for middleware and the Resource object.
  4132. * @param {HTMLImageElement|HTMLAudioElement|HTMLVideoElement} [options.metadata.loadElement=null] - The
  4133. * element to use for loading, instead of creating one.
  4134. * @param {boolean} [options.metadata.skipSource=false] - Skips adding source(s) to the load element. This
  4135. * is useful if you want to pass in a `loadElement` that you already added load sources to.
  4136. * @param {string|string[]} [options.metadata.mimeType] - The mime type to use for the source element of a video/audio
  4137. * elment. If the urls are an array, you can pass this as an array as well where each index is the mime type to
  4138. * use for the corresponding url index.
  4139. */
  4140. function Resource(name, url, options) {
  4141. _classCallCheck(this, Resource);
  4142. if (typeof name !== 'string' || typeof url !== 'string') {
  4143. throw new Error('Both name and url are required for constructing a resource.');
  4144. }
  4145. options = options || {};
  4146. /**
  4147. * The state flags of this resource.
  4148. *
  4149. * @member {number}
  4150. */
  4151. this._flags = 0;
  4152. // set data url flag, needs to be set early for some _determineX checks to work.
  4153. this._setFlag(Resource.STATUS_FLAGS.DATA_URL, url.indexOf('data:') === 0);
  4154. /**
  4155. * The name of this resource.
  4156. *
  4157. * @member {string}
  4158. * @readonly
  4159. */
  4160. this.name = name;
  4161. /**
  4162. * The url used to load this resource.
  4163. *
  4164. * @member {string}
  4165. * @readonly
  4166. */
  4167. this.url = url;
  4168. /**
  4169. * The extension used to load this resource.
  4170. *
  4171. * @member {string}
  4172. * @readonly
  4173. */
  4174. this.extension = this._getExtension();
  4175. /**
  4176. * The data that was loaded by the resource.
  4177. *
  4178. * @member {any}
  4179. */
  4180. this.data = null;
  4181. /**
  4182. * Is this request cross-origin? If unset, determined automatically.
  4183. *
  4184. * @member {string}
  4185. */
  4186. this.crossOrigin = options.crossOrigin === true ? 'anonymous' : options.crossOrigin;
  4187. /**
  4188. * The method of loading to use for this resource.
  4189. *
  4190. * @member {Resource.LOAD_TYPE}
  4191. */
  4192. this.loadType = options.loadType || this._determineLoadType();
  4193. /**
  4194. * The type used to load the resource via XHR. If unset, determined automatically.
  4195. *
  4196. * @member {string}
  4197. */
  4198. this.xhrType = options.xhrType;
  4199. /**
  4200. * Extra info for middleware, and controlling specifics about how the resource loads.
  4201. *
  4202. * Note that if you pass in a `loadElement`, the Resource class takes ownership of it.
  4203. * Meaning it will modify it as it sees fit.
  4204. *
  4205. * @member {object}
  4206. * @property {HTMLImageElement|HTMLAudioElement|HTMLVideoElement} [loadElement=null] - The
  4207. * element to use for loading, instead of creating one.
  4208. * @property {boolean} [skipSource=false] - Skips adding source(s) to the load element. This
  4209. * is useful if you want to pass in a `loadElement` that you already added load sources
  4210. * to.
  4211. */
  4212. this.metadata = options.metadata || {};
  4213. /**
  4214. * The error that occurred while loading (if any).
  4215. *
  4216. * @member {Error}
  4217. * @readonly
  4218. */
  4219. this.error = null;
  4220. /**
  4221. * The XHR object that was used to load this resource. This is only set
  4222. * when `loadType` is `Resource.LOAD_TYPE.XHR`.
  4223. *
  4224. * @member {XMLHttpRequest}
  4225. * @readonly
  4226. */
  4227. this.xhr = null;
  4228. /**
  4229. * The child resources this resource owns.
  4230. *
  4231. * @member {Resource[]}
  4232. * @readonly
  4233. */
  4234. this.children = [];
  4235. /**
  4236. * The resource type.
  4237. *
  4238. * @member {Resource.TYPE}
  4239. * @readonly
  4240. */
  4241. this.type = Resource.TYPE.UNKNOWN;
  4242. /**
  4243. * The progress chunk owned by this resource.
  4244. *
  4245. * @member {number}
  4246. * @readonly
  4247. */
  4248. this.progressChunk = 0;
  4249. /**
  4250. * The `dequeue` method that will be used a storage place for the async queue dequeue method
  4251. * used privately by the loader.
  4252. *
  4253. * @private
  4254. * @member {function}
  4255. */
  4256. this._dequeue = _noop;
  4257. /**
  4258. * Used a storage place for the on load binding used privately by the loader.
  4259. *
  4260. * @private
  4261. * @member {function}
  4262. */
  4263. this._onLoadBinding = null;
  4264. /**
  4265. * The `complete` function bound to this resource's context.
  4266. *
  4267. * @private
  4268. * @member {function}
  4269. */
  4270. this._boundComplete = this.complete.bind(this);
  4271. /**
  4272. * The `_onError` function bound to this resource's context.
  4273. *
  4274. * @private
  4275. * @member {function}
  4276. */
  4277. this._boundOnError = this._onError.bind(this);
  4278. /**
  4279. * The `_onProgress` function bound to this resource's context.
  4280. *
  4281. * @private
  4282. * @member {function}
  4283. */
  4284. this._boundOnProgress = this._onProgress.bind(this);
  4285. // xhr callbacks
  4286. this._boundXhrOnError = this._xhrOnError.bind(this);
  4287. this._boundXhrOnAbort = this._xhrOnAbort.bind(this);
  4288. this._boundXhrOnLoad = this._xhrOnLoad.bind(this);
  4289. this._boundXdrOnTimeout = this._xdrOnTimeout.bind(this);
  4290. /**
  4291. * Dispatched when the resource beings to load.
  4292. *
  4293. * The callback looks like {@link Resource.OnStartSignal}.
  4294. *
  4295. * @member {Signal}
  4296. */
  4297. this.onStart = new _miniSignals2.default();
  4298. /**
  4299. * Dispatched each time progress of this resource load updates.
  4300. * Not all resources types and loader systems can support this event
  4301. * so sometimes it may not be available. If the resource
  4302. * is being loaded on a modern browser, using XHR, and the remote server
  4303. * properly sets Content-Length headers, then this will be available.
  4304. *
  4305. * The callback looks like {@link Resource.OnProgressSignal}.
  4306. *
  4307. * @member {Signal}
  4308. */
  4309. this.onProgress = new _miniSignals2.default();
  4310. /**
  4311. * Dispatched once this resource has loaded, if there was an error it will
  4312. * be in the `error` property.
  4313. *
  4314. * The callback looks like {@link Resource.OnCompleteSignal}.
  4315. *
  4316. * @member {Signal}
  4317. */
  4318. this.onComplete = new _miniSignals2.default();
  4319. /**
  4320. * Dispatched after this resource has had all the *after* middleware run on it.
  4321. *
  4322. * The callback looks like {@link Resource.OnCompleteSignal}.
  4323. *
  4324. * @member {Signal}
  4325. */
  4326. this.onAfterMiddleware = new _miniSignals2.default();
  4327. /**
  4328. * When the resource starts to load.
  4329. *
  4330. * @memberof Resource
  4331. * @callback OnStartSignal
  4332. * @param {Resource} resource - The resource that the event happened on.
  4333. */
  4334. /**
  4335. * When the resource reports loading progress.
  4336. *
  4337. * @memberof Resource
  4338. * @callback OnProgressSignal
  4339. * @param {Resource} resource - The resource that the event happened on.
  4340. * @param {number} percentage - The progress of the load in the range [0, 1].
  4341. */
  4342. /**
  4343. * When the resource finishes loading.
  4344. *
  4345. * @memberof Resource
  4346. * @callback OnCompleteSignal
  4347. * @param {Resource} resource - The resource that the event happened on.
  4348. */
  4349. }
  4350. /**
  4351. * Stores whether or not this url is a data url.
  4352. *
  4353. * @member {boolean}
  4354. * @readonly
  4355. */
  4356. /**
  4357. * Marks the resource as complete.
  4358. *
  4359. */
  4360. Resource.prototype.complete = function complete() {
  4361. // TODO: Clean this up in a wrapper or something...gross....
  4362. if (this.data && this.data.removeEventListener) {
  4363. this.data.removeEventListener('error', this._boundOnError, false);
  4364. this.data.removeEventListener('load', this._boundComplete, false);
  4365. this.data.removeEventListener('progress', this._boundOnProgress, false);
  4366. this.data.removeEventListener('canplaythrough', this._boundComplete, false);
  4367. }
  4368. if (this.xhr) {
  4369. if (this.xhr.removeEventListener) {
  4370. this.xhr.removeEventListener('error', this._boundXhrOnError, false);
  4371. this.xhr.removeEventListener('abort', this._boundXhrOnAbort, false);
  4372. this.xhr.removeEventListener('progress', this._boundOnProgress, false);
  4373. this.xhr.removeEventListener('load', this._boundXhrOnLoad, false);
  4374. } else {
  4375. this.xhr.onerror = null;
  4376. this.xhr.ontimeout = null;
  4377. this.xhr.onprogress = null;
  4378. this.xhr.onload = null;
  4379. }
  4380. }
  4381. if (this.isComplete) {
  4382. throw new Error('Complete called again for an already completed resource.');
  4383. }
  4384. this._setFlag(Resource.STATUS_FLAGS.COMPLETE, true);
  4385. this._setFlag(Resource.STATUS_FLAGS.LOADING, false);
  4386. this.onComplete.dispatch(this);
  4387. };
  4388. /**
  4389. * Aborts the loading of this resource, with an optional message.
  4390. *
  4391. * @param {string} message - The message to use for the error
  4392. */
  4393. Resource.prototype.abort = function abort(message) {
  4394. // abort can be called multiple times, ignore subsequent calls.
  4395. if (this.error) {
  4396. return;
  4397. }
  4398. // store error
  4399. this.error = new Error(message);
  4400. // abort the actual loading
  4401. if (this.xhr) {
  4402. this.xhr.abort();
  4403. } else if (this.xdr) {
  4404. this.xdr.abort();
  4405. } else if (this.data) {
  4406. // single source
  4407. if (this.data.src) {
  4408. this.data.src = Resource.EMPTY_GIF;
  4409. }
  4410. // multi-source
  4411. else {
  4412. while (this.data.firstChild) {
  4413. this.data.removeChild(this.data.firstChild);
  4414. }
  4415. }
  4416. }
  4417. // done now.
  4418. this.complete();
  4419. };
  4420. /**
  4421. * Kicks off loading of this resource. This method is asynchronous.
  4422. *
  4423. * @param {function} [cb] - Optional callback to call once the resource is loaded.
  4424. */
  4425. Resource.prototype.load = function load(cb) {
  4426. var _this = this;
  4427. if (this.isLoading) {
  4428. return;
  4429. }
  4430. if (this.isComplete) {
  4431. if (cb) {
  4432. setTimeout(function () {
  4433. return cb(_this);
  4434. }, 1);
  4435. }
  4436. return;
  4437. } else if (cb) {
  4438. this.onComplete.once(cb);
  4439. }
  4440. this._setFlag(Resource.STATUS_FLAGS.LOADING, true);
  4441. this.onStart.dispatch(this);
  4442. // if unset, determine the value
  4443. if (this.crossOrigin === false || typeof this.crossOrigin !== 'string') {
  4444. this.crossOrigin = this._determineCrossOrigin(this.url);
  4445. }
  4446. switch (this.loadType) {
  4447. case Resource.LOAD_TYPE.IMAGE:
  4448. this.type = Resource.TYPE.IMAGE;
  4449. this._loadElement('image');
  4450. break;
  4451. case Resource.LOAD_TYPE.AUDIO:
  4452. this.type = Resource.TYPE.AUDIO;
  4453. this._loadSourceElement('audio');
  4454. break;
  4455. case Resource.LOAD_TYPE.VIDEO:
  4456. this.type = Resource.TYPE.VIDEO;
  4457. this._loadSourceElement('video');
  4458. break;
  4459. case Resource.LOAD_TYPE.XHR:
  4460. /* falls through */
  4461. default:
  4462. if (useXdr && this.crossOrigin) {
  4463. this._loadXdr();
  4464. } else {
  4465. this._loadXhr();
  4466. }
  4467. break;
  4468. }
  4469. };
  4470. /**
  4471. * Checks if the flag is set.
  4472. *
  4473. * @private
  4474. * @param {number} flag - The flag to check.
  4475. * @return {boolean} True if the flag is set.
  4476. */
  4477. Resource.prototype._hasFlag = function _hasFlag(flag) {
  4478. return !!(this._flags & flag);
  4479. };
  4480. /**
  4481. * (Un)Sets the flag.
  4482. *
  4483. * @private
  4484. * @param {number} flag - The flag to (un)set.
  4485. * @param {boolean} value - Whether to set or (un)set the flag.
  4486. */
  4487. Resource.prototype._setFlag = function _setFlag(flag, value) {
  4488. this._flags = value ? this._flags | flag : this._flags & ~flag;
  4489. };
  4490. /**
  4491. * Loads this resources using an element that has a single source,
  4492. * like an HTMLImageElement.
  4493. *
  4494. * @private
  4495. * @param {string} type - The type of element to use.
  4496. */
  4497. Resource.prototype._loadElement = function _loadElement(type) {
  4498. if (this.metadata.loadElement) {
  4499. this.data = this.metadata.loadElement;
  4500. } else if (type === 'image' && typeof window.Image !== 'undefined') {
  4501. this.data = new Image();
  4502. } else {
  4503. this.data = document.createElement(type);
  4504. }
  4505. if (this.crossOrigin) {
  4506. this.data.crossOrigin = this.crossOrigin;
  4507. }
  4508. if (!this.metadata.skipSource) {
  4509. this.data.src = this.url;
  4510. }
  4511. this.data.addEventListener('error', this._boundOnError, false);
  4512. this.data.addEventListener('load', this._boundComplete, false);
  4513. this.data.addEventListener('progress', this._boundOnProgress, false);
  4514. };
  4515. /**
  4516. * Loads this resources using an element that has multiple sources,
  4517. * like an HTMLAudioElement or HTMLVideoElement.
  4518. *
  4519. * @private
  4520. * @param {string} type - The type of element to use.
  4521. */
  4522. Resource.prototype._loadSourceElement = function _loadSourceElement(type) {
  4523. if (this.metadata.loadElement) {
  4524. this.data = this.metadata.loadElement;
  4525. } else if (type === 'audio' && typeof window.Audio !== 'undefined') {
  4526. this.data = new Audio();
  4527. } else {
  4528. this.data = document.createElement(type);
  4529. }
  4530. if (this.data === null) {
  4531. this.abort('Unsupported element: ' + type);
  4532. return;
  4533. }
  4534. if (!this.metadata.skipSource) {
  4535. // support for CocoonJS Canvas+ runtime, lacks document.createElement('source')
  4536. if (navigator.isCocoonJS) {
  4537. this.data.src = Array.isArray(this.url) ? this.url[0] : this.url;
  4538. } else if (Array.isArray(this.url)) {
  4539. var mimeTypes = this.metadata.mimeType;
  4540. for (var i = 0; i < this.url.length; ++i) {
  4541. this.data.appendChild(this._createSource(type, this.url[i], Array.isArray(mimeTypes) ? mimeTypes[i] : mimeTypes));
  4542. }
  4543. } else {
  4544. var _mimeTypes = this.metadata.mimeType;
  4545. this.data.appendChild(this._createSource(type, this.url, Array.isArray(_mimeTypes) ? _mimeTypes[0] : _mimeTypes));
  4546. }
  4547. }
  4548. this.data.addEventListener('error', this._boundOnError, false);
  4549. this.data.addEventListener('load', this._boundComplete, false);
  4550. this.data.addEventListener('progress', this._boundOnProgress, false);
  4551. this.data.addEventListener('canplaythrough', this._boundComplete, false);
  4552. this.data.load();
  4553. };
  4554. /**
  4555. * Loads this resources using an XMLHttpRequest.
  4556. *
  4557. * @private
  4558. */
  4559. Resource.prototype._loadXhr = function _loadXhr() {
  4560. // if unset, determine the value
  4561. if (typeof this.xhrType !== 'string') {
  4562. this.xhrType = this._determineXhrType();
  4563. }
  4564. var xhr = this.xhr = new XMLHttpRequest();
  4565. // set the request type and url
  4566. xhr.open('GET', this.url, true);
  4567. // load json as text and parse it ourselves. We do this because some browsers
  4568. // *cough* safari *cough* can't deal with it.
  4569. if (this.xhrType === Resource.XHR_RESPONSE_TYPE.JSON || this.xhrType === Resource.XHR_RESPONSE_TYPE.DOCUMENT) {
  4570. xhr.responseType = Resource.XHR_RESPONSE_TYPE.TEXT;
  4571. } else {
  4572. xhr.responseType = this.xhrType;
  4573. }
  4574. xhr.addEventListener('error', this._boundXhrOnError, false);
  4575. xhr.addEventListener('abort', this._boundXhrOnAbort, false);
  4576. xhr.addEventListener('progress', this._boundOnProgress, false);
  4577. xhr.addEventListener('load', this._boundXhrOnLoad, false);
  4578. xhr.send();
  4579. };
  4580. /**
  4581. * Loads this resources using an XDomainRequest. This is here because we need to support IE9 (gross).
  4582. *
  4583. * @private
  4584. */
  4585. Resource.prototype._loadXdr = function _loadXdr() {
  4586. // if unset, determine the value
  4587. if (typeof this.xhrType !== 'string') {
  4588. this.xhrType = this._determineXhrType();
  4589. }
  4590. var xdr = this.xhr = new XDomainRequest();
  4591. // XDomainRequest has a few quirks. Occasionally it will abort requests
  4592. // A way to avoid this is to make sure ALL callbacks are set even if not used
  4593. // More info here: http://stackoverflow.com/questions/15786966/xdomainrequest-aborts-post-on-ie-9
  4594. xdr.timeout = 5000;
  4595. xdr.onerror = this._boundXhrOnError;
  4596. xdr.ontimeout = this._boundXdrOnTimeout;
  4597. xdr.onprogress = this._boundOnProgress;
  4598. xdr.onload = this._boundXhrOnLoad;
  4599. xdr.open('GET', this.url, true);
  4600. // Note: The xdr.send() call is wrapped in a timeout to prevent an
  4601. // issue with the interface where some requests are lost if multiple
  4602. // XDomainRequests are being sent at the same time.
  4603. // Some info here: https://github.com/photonstorm/phaser/issues/1248
  4604. setTimeout(function () {
  4605. return xdr.send();
  4606. }, 1);
  4607. };
  4608. /**
  4609. * Creates a source used in loading via an element.
  4610. *
  4611. * @private
  4612. * @param {string} type - The element type (video or audio).
  4613. * @param {string} url - The source URL to load from.
  4614. * @param {string} [mime] - The mime type of the video
  4615. * @return {HTMLSourceElement} The source element.
  4616. */
  4617. Resource.prototype._createSource = function _createSource(type, url, mime) {
  4618. if (!mime) {
  4619. mime = type + '/' + this._getExtension(url);
  4620. }
  4621. var source = document.createElement('source');
  4622. source.src = url;
  4623. source.type = mime;
  4624. return source;
  4625. };
  4626. /**
  4627. * Called if a load errors out.
  4628. *
  4629. * @param {Event} event - The error event from the element that emits it.
  4630. * @private
  4631. */
  4632. Resource.prototype._onError = function _onError(event) {
  4633. this.abort('Failed to load element using: ' + event.target.nodeName);
  4634. };
  4635. /**
  4636. * Called if a load progress event fires for xhr/xdr.
  4637. *
  4638. * @private
  4639. * @param {XMLHttpRequestProgressEvent|Event} event - Progress event.
  4640. */
  4641. Resource.prototype._onProgress = function _onProgress(event) {
  4642. if (event && event.lengthComputable) {
  4643. this.onProgress.dispatch(this, event.loaded / event.total);
  4644. }
  4645. };
  4646. /**
  4647. * Called if an error event fires for xhr/xdr.
  4648. *
  4649. * @private
  4650. * @param {XMLHttpRequestErrorEvent|Event} event - Error event.
  4651. */
  4652. Resource.prototype._xhrOnError = function _xhrOnError() {
  4653. var xhr = this.xhr;
  4654. this.abort(reqType(xhr) + ' Request failed. Status: ' + xhr.status + ', text: "' + xhr.statusText + '"');
  4655. };
  4656. /**
  4657. * Called if an abort event fires for xhr.
  4658. *
  4659. * @private
  4660. * @param {XMLHttpRequestAbortEvent} event - Abort Event
  4661. */
  4662. Resource.prototype._xhrOnAbort = function _xhrOnAbort() {
  4663. this.abort(reqType(this.xhr) + ' Request was aborted by the user.');
  4664. };
  4665. /**
  4666. * Called if a timeout event fires for xdr.
  4667. *
  4668. * @private
  4669. * @param {Event} event - Timeout event.
  4670. */
  4671. Resource.prototype._xdrOnTimeout = function _xdrOnTimeout() {
  4672. this.abort(reqType(this.xhr) + ' Request timed out.');
  4673. };
  4674. /**
  4675. * Called when data successfully loads from an xhr/xdr request.
  4676. *
  4677. * @private
  4678. * @param {XMLHttpRequestLoadEvent|Event} event - Load event
  4679. */
  4680. Resource.prototype._xhrOnLoad = function _xhrOnLoad() {
  4681. var xhr = this.xhr;
  4682. var text = '';
  4683. var status = typeof xhr.status === 'undefined' ? STATUS_OK : xhr.status; // XDR has no `.status`, assume 200.
  4684. // responseText is accessible only if responseType is '' or 'text' and on older browsers
  4685. if (xhr.responseType === '' || xhr.responseType === 'text' || typeof xhr.responseType === 'undefined') {
  4686. text = xhr.responseText;
  4687. }
  4688. // status can be 0 when using the `file://` protocol so we also check if a response is set.
  4689. // If it has a response, we assume 200; otherwise a 0 status code with no contents is an aborted request.
  4690. if (status === STATUS_NONE && (text.length > 0 || xhr.responseType === Resource.XHR_RESPONSE_TYPE.BUFFER)) {
  4691. status = STATUS_OK;
  4692. }
  4693. // handle IE9 bug: http://stackoverflow.com/questions/10046972/msie-returns-status-code-of-1223-for-ajax-request
  4694. else if (status === STATUS_IE_BUG_EMPTY) {
  4695. status = STATUS_EMPTY;
  4696. }
  4697. var statusType = status / 100 | 0;
  4698. if (statusType === STATUS_TYPE_OK) {
  4699. // if text, just return it
  4700. if (this.xhrType === Resource.XHR_RESPONSE_TYPE.TEXT) {
  4701. this.data = text;
  4702. this.type = Resource.TYPE.TEXT;
  4703. }
  4704. // if json, parse into json object
  4705. else if (this.xhrType === Resource.XHR_RESPONSE_TYPE.JSON) {
  4706. try {
  4707. this.data = JSON.parse(text);
  4708. this.type = Resource.TYPE.JSON;
  4709. } catch (e) {
  4710. this.abort('Error trying to parse loaded json: ' + e);
  4711. return;
  4712. }
  4713. }
  4714. // if xml, parse into an xml document or div element
  4715. else if (this.xhrType === Resource.XHR_RESPONSE_TYPE.DOCUMENT) {
  4716. try {
  4717. if (window.DOMParser) {
  4718. var domparser = new DOMParser();
  4719. this.data = domparser.parseFromString(text, 'text/xml');
  4720. } else {
  4721. var div = document.createElement('div');
  4722. div.innerHTML = text;
  4723. this.data = div;
  4724. }
  4725. this.type = Resource.TYPE.XML;
  4726. } catch (e) {
  4727. this.abort('Error trying to parse loaded xml: ' + e);
  4728. return;
  4729. }
  4730. }
  4731. // other types just return the response
  4732. else {
  4733. this.data = xhr.response || text;
  4734. }
  4735. } else {
  4736. this.abort('[' + xhr.status + '] ' + xhr.statusText + ': ' + xhr.responseURL);
  4737. return;
  4738. }
  4739. this.complete();
  4740. };
  4741. /**
  4742. * Sets the `crossOrigin` property for this resource based on if the url
  4743. * for this resource is cross-origin. If crossOrigin was manually set, this
  4744. * function does nothing.
  4745. *
  4746. * @private
  4747. * @param {string} url - The url to test.
  4748. * @param {object} [loc=window.location] - The location object to test against.
  4749. * @return {string} The crossOrigin value to use (or empty string for none).
  4750. */
  4751. Resource.prototype._determineCrossOrigin = function _determineCrossOrigin(url, loc) {
  4752. // data: and javascript: urls are considered same-origin
  4753. if (url.indexOf('data:') === 0) {
  4754. return '';
  4755. }
  4756. // default is window.location
  4757. loc = loc || window.location;
  4758. if (!tempAnchor) {
  4759. tempAnchor = document.createElement('a');
  4760. }
  4761. // let the browser determine the full href for the url of this resource and then
  4762. // parse with the node url lib, we can't use the properties of the anchor element
  4763. // because they don't work in IE9 :(
  4764. tempAnchor.href = url;
  4765. url = (0, _parseUri2.default)(tempAnchor.href, { strictMode: true });
  4766. var samePort = !url.port && loc.port === '' || url.port === loc.port;
  4767. var protocol = url.protocol ? url.protocol + ':' : '';
  4768. // if cross origin
  4769. if (url.host !== loc.hostname || !samePort || protocol !== loc.protocol) {
  4770. return 'anonymous';
  4771. }
  4772. return '';
  4773. };
  4774. /**
  4775. * Determines the responseType of an XHR request based on the extension of the
  4776. * resource being loaded.
  4777. *
  4778. * @private
  4779. * @return {Resource.XHR_RESPONSE_TYPE} The responseType to use.
  4780. */
  4781. Resource.prototype._determineXhrType = function _determineXhrType() {
  4782. return Resource._xhrTypeMap[this.extension] || Resource.XHR_RESPONSE_TYPE.TEXT;
  4783. };
  4784. /**
  4785. * Determines the loadType of a resource based on the extension of the
  4786. * resource being loaded.
  4787. *
  4788. * @private
  4789. * @return {Resource.LOAD_TYPE} The loadType to use.
  4790. */
  4791. Resource.prototype._determineLoadType = function _determineLoadType() {
  4792. return Resource._loadTypeMap[this.extension] || Resource.LOAD_TYPE.XHR;
  4793. };
  4794. /**
  4795. * Extracts the extension (sans '.') of the file being loaded by the resource.
  4796. *
  4797. * @private
  4798. * @return {string} The extension.
  4799. */
  4800. Resource.prototype._getExtension = function _getExtension() {
  4801. var url = this.url;
  4802. var ext = '';
  4803. if (this.isDataUrl) {
  4804. var slashIndex = url.indexOf('/');
  4805. ext = url.substring(slashIndex + 1, url.indexOf(';', slashIndex));
  4806. } else {
  4807. var queryStart = url.indexOf('?');
  4808. var hashStart = url.indexOf('#');
  4809. var index = Math.min(queryStart > -1 ? queryStart : url.length, hashStart > -1 ? hashStart : url.length);
  4810. url = url.substring(0, index);
  4811. ext = url.substring(url.lastIndexOf('.') + 1);
  4812. }
  4813. return ext.toLowerCase();
  4814. };
  4815. /**
  4816. * Determines the mime type of an XHR request based on the responseType of
  4817. * resource being loaded.
  4818. *
  4819. * @private
  4820. * @param {Resource.XHR_RESPONSE_TYPE} type - The type to get a mime type for.
  4821. * @return {string} The mime type to use.
  4822. */
  4823. Resource.prototype._getMimeFromXhrType = function _getMimeFromXhrType(type) {
  4824. switch (type) {
  4825. case Resource.XHR_RESPONSE_TYPE.BUFFER:
  4826. return 'application/octet-binary';
  4827. case Resource.XHR_RESPONSE_TYPE.BLOB:
  4828. return 'application/blob';
  4829. case Resource.XHR_RESPONSE_TYPE.DOCUMENT:
  4830. return 'application/xml';
  4831. case Resource.XHR_RESPONSE_TYPE.JSON:
  4832. return 'application/json';
  4833. case Resource.XHR_RESPONSE_TYPE.DEFAULT:
  4834. case Resource.XHR_RESPONSE_TYPE.TEXT:
  4835. /* falls through */
  4836. default:
  4837. return 'text/plain';
  4838. }
  4839. };
  4840. _createClass(Resource, [{
  4841. key: 'isDataUrl',
  4842. get: function get() {
  4843. return this._hasFlag(Resource.STATUS_FLAGS.DATA_URL);
  4844. }
  4845. /**
  4846. * Describes if this resource has finished loading. Is true when the resource has completely
  4847. * loaded.
  4848. *
  4849. * @member {boolean}
  4850. * @readonly
  4851. */
  4852. }, {
  4853. key: 'isComplete',
  4854. get: function get() {
  4855. return this._hasFlag(Resource.STATUS_FLAGS.COMPLETE);
  4856. }
  4857. /**
  4858. * Describes if this resource is currently loading. Is true when the resource starts loading,
  4859. * and is false again when complete.
  4860. *
  4861. * @member {boolean}
  4862. * @readonly
  4863. */
  4864. }, {
  4865. key: 'isLoading',
  4866. get: function get() {
  4867. return this._hasFlag(Resource.STATUS_FLAGS.LOADING);
  4868. }
  4869. }]);
  4870. return Resource;
  4871. }();
  4872. /**
  4873. * The types of resources a resource could represent.
  4874. *
  4875. * @static
  4876. * @readonly
  4877. * @enum {number}
  4878. */
  4879. exports.default = Resource;
  4880. Resource.STATUS_FLAGS = {
  4881. NONE: 0,
  4882. DATA_URL: 1 << 0,
  4883. COMPLETE: 1 << 1,
  4884. LOADING: 1 << 2
  4885. };
  4886. /**
  4887. * The types of resources a resource could represent.
  4888. *
  4889. * @static
  4890. * @readonly
  4891. * @enum {number}
  4892. */
  4893. Resource.TYPE = {
  4894. UNKNOWN: 0,
  4895. JSON: 1,
  4896. XML: 2,
  4897. IMAGE: 3,
  4898. AUDIO: 4,
  4899. VIDEO: 5,
  4900. TEXT: 6
  4901. };
  4902. /**
  4903. * The types of loading a resource can use.
  4904. *
  4905. * @static
  4906. * @readonly
  4907. * @enum {number}
  4908. */
  4909. Resource.LOAD_TYPE = {
  4910. /** Uses XMLHttpRequest to load the resource. */
  4911. XHR: 1,
  4912. /** Uses an `Image` object to load the resource. */
  4913. IMAGE: 2,
  4914. /** Uses an `Audio` object to load the resource. */
  4915. AUDIO: 3,
  4916. /** Uses a `Video` object to load the resource. */
  4917. VIDEO: 4
  4918. };
  4919. /**
  4920. * The XHR ready states, used internally.
  4921. *
  4922. * @static
  4923. * @readonly
  4924. * @enum {string}
  4925. */
  4926. Resource.XHR_RESPONSE_TYPE = {
  4927. /** string */
  4928. DEFAULT: 'text',
  4929. /** ArrayBuffer */
  4930. BUFFER: 'arraybuffer',
  4931. /** Blob */
  4932. BLOB: 'blob',
  4933. /** Document */
  4934. DOCUMENT: 'document',
  4935. /** Object */
  4936. JSON: 'json',
  4937. /** String */
  4938. TEXT: 'text'
  4939. };
  4940. Resource._loadTypeMap = {
  4941. // images
  4942. gif: Resource.LOAD_TYPE.IMAGE,
  4943. png: Resource.LOAD_TYPE.IMAGE,
  4944. bmp: Resource.LOAD_TYPE.IMAGE,
  4945. jpg: Resource.LOAD_TYPE.IMAGE,
  4946. jpeg: Resource.LOAD_TYPE.IMAGE,
  4947. tif: Resource.LOAD_TYPE.IMAGE,
  4948. tiff: Resource.LOAD_TYPE.IMAGE,
  4949. webp: Resource.LOAD_TYPE.IMAGE,
  4950. tga: Resource.LOAD_TYPE.IMAGE,
  4951. svg: Resource.LOAD_TYPE.IMAGE,
  4952. 'svg+xml': Resource.LOAD_TYPE.IMAGE, // for SVG data urls
  4953. // audio
  4954. mp3: Resource.LOAD_TYPE.AUDIO,
  4955. ogg: Resource.LOAD_TYPE.AUDIO,
  4956. wav: Resource.LOAD_TYPE.AUDIO,
  4957. // videos
  4958. mp4: Resource.LOAD_TYPE.VIDEO,
  4959. webm: Resource.LOAD_TYPE.VIDEO
  4960. };
  4961. Resource._xhrTypeMap = {
  4962. // xml
  4963. xhtml: Resource.XHR_RESPONSE_TYPE.DOCUMENT,
  4964. html: Resource.XHR_RESPONSE_TYPE.DOCUMENT,
  4965. htm: Resource.XHR_RESPONSE_TYPE.DOCUMENT,
  4966. xml: Resource.XHR_RESPONSE_TYPE.DOCUMENT,
  4967. tmx: Resource.XHR_RESPONSE_TYPE.DOCUMENT,
  4968. svg: Resource.XHR_RESPONSE_TYPE.DOCUMENT,
  4969. // This was added to handle Tiled Tileset XML, but .tsx is also a TypeScript React Component.
  4970. // Since it is way less likely for people to be loading TypeScript files instead of Tiled files,
  4971. // this should probably be fine.
  4972. tsx: Resource.XHR_RESPONSE_TYPE.DOCUMENT,
  4973. // images
  4974. gif: Resource.XHR_RESPONSE_TYPE.BLOB,
  4975. png: Resource.XHR_RESPONSE_TYPE.BLOB,
  4976. bmp: Resource.XHR_RESPONSE_TYPE.BLOB,
  4977. jpg: Resource.XHR_RESPONSE_TYPE.BLOB,
  4978. jpeg: Resource.XHR_RESPONSE_TYPE.BLOB,
  4979. tif: Resource.XHR_RESPONSE_TYPE.BLOB,
  4980. tiff: Resource.XHR_RESPONSE_TYPE.BLOB,
  4981. webp: Resource.XHR_RESPONSE_TYPE.BLOB,
  4982. tga: Resource.XHR_RESPONSE_TYPE.BLOB,
  4983. // json
  4984. json: Resource.XHR_RESPONSE_TYPE.JSON,
  4985. // text
  4986. text: Resource.XHR_RESPONSE_TYPE.TEXT,
  4987. txt: Resource.XHR_RESPONSE_TYPE.TEXT,
  4988. // fonts
  4989. ttf: Resource.XHR_RESPONSE_TYPE.BUFFER,
  4990. otf: Resource.XHR_RESPONSE_TYPE.BUFFER
  4991. };
  4992. // We can't set the `src` attribute to empty string, so on abort we set it to this 1px transparent gif
  4993. Resource.EMPTY_GIF = 'data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==';
  4994. /**
  4995. * Quick helper to set a value on one of the extension maps. Ensures there is no
  4996. * dot at the start of the extension.
  4997. *
  4998. * @ignore
  4999. * @param {object} map - The map to set on.
  5000. * @param {string} extname - The extension (or key) to set.
  5001. * @param {number} val - The value to set.
  5002. */
  5003. function setExtMap(map, extname, val) {
  5004. if (extname && extname.indexOf('.') === 0) {
  5005. extname = extname.substring(1);
  5006. }
  5007. if (!extname) {
  5008. return;
  5009. }
  5010. map[extname] = val;
  5011. }
  5012. /**
  5013. * Quick helper to get string xhr type.
  5014. *
  5015. * @ignore
  5016. * @param {XMLHttpRequest|XDomainRequest} xhr - The request to check.
  5017. * @return {string} The type.
  5018. */
  5019. function reqType(xhr) {
  5020. return xhr.toString().replace('object ', '');
  5021. }
  5022. }, { "mini-signals": 5, "parse-uri": 7 }], 34: [function (require, module, exports) {
  5023. 'use strict';
  5024. exports.__esModule = true;
  5025. exports.eachSeries = eachSeries;
  5026. exports.queue = queue;
  5027. /**
  5028. * Smaller version of the async library constructs.
  5029. *
  5030. */
  5031. function _noop() { } /* empty */
  5032. /**
  5033. * Iterates an array in series.
  5034. *
  5035. * @param {Array.<*>} array - Array to iterate.
  5036. * @param {function} iterator - Function to call for each element.
  5037. * @param {function} callback - Function to call when done, or on error.
  5038. * @param {boolean} [deferNext=false] - Break synchronous each loop by calling next with a setTimeout of 1.
  5039. */
  5040. function eachSeries(array, iterator, callback, deferNext) {
  5041. var i = 0;
  5042. var len = array.length;
  5043. (function next(err) {
  5044. if (err || i === len) {
  5045. if (callback) {
  5046. callback(err);
  5047. }
  5048. return;
  5049. }
  5050. if (deferNext) {
  5051. setTimeout(function () {
  5052. iterator(array[i++], next);
  5053. }, 1);
  5054. } else {
  5055. iterator(array[i++], next);
  5056. }
  5057. })();
  5058. }
  5059. /**
  5060. * Ensures a function is only called once.
  5061. *
  5062. * @param {function} fn - The function to wrap.
  5063. * @return {function} The wrapping function.
  5064. */
  5065. function onlyOnce(fn) {
  5066. return function onceWrapper() {
  5067. if (fn === null) {
  5068. throw new Error('Callback was already called.');
  5069. }
  5070. var callFn = fn;
  5071. fn = null;
  5072. callFn.apply(this, arguments);
  5073. };
  5074. }
  5075. /**
  5076. * Async queue implementation,
  5077. *
  5078. * @param {function} worker - The worker function to call for each task.
  5079. * @param {number} concurrency - How many workers to run in parrallel.
  5080. * @return {*} The async queue object.
  5081. */
  5082. function queue(worker, concurrency) {
  5083. if (concurrency == null) {
  5084. // eslint-disable-line no-eq-null,eqeqeq
  5085. concurrency = 1;
  5086. } else if (concurrency === 0) {
  5087. throw new Error('Concurrency must not be zero');
  5088. }
  5089. var workers = 0;
  5090. var q = {
  5091. _tasks: [],
  5092. concurrency: concurrency,
  5093. saturated: _noop,
  5094. unsaturated: _noop,
  5095. buffer: concurrency / 4,
  5096. empty: _noop,
  5097. drain: _noop,
  5098. error: _noop,
  5099. started: false,
  5100. paused: false,
  5101. push: function push(data, callback) {
  5102. _insert(data, false, callback);
  5103. },
  5104. kill: function kill() {
  5105. workers = 0;
  5106. q.drain = _noop;
  5107. q.started = false;
  5108. q._tasks = [];
  5109. },
  5110. unshift: function unshift(data, callback) {
  5111. _insert(data, true, callback);
  5112. },
  5113. process: function process() {
  5114. while (!q.paused && workers < q.concurrency && q._tasks.length) {
  5115. var task = q._tasks.shift();
  5116. if (q._tasks.length === 0) {
  5117. q.empty();
  5118. }
  5119. workers += 1;
  5120. if (workers === q.concurrency) {
  5121. q.saturated();
  5122. }
  5123. worker(task.data, onlyOnce(_next(task)));
  5124. }
  5125. },
  5126. length: function length() {
  5127. return q._tasks.length;
  5128. },
  5129. running: function running() {
  5130. return workers;
  5131. },
  5132. idle: function idle() {
  5133. return q._tasks.length + workers === 0;
  5134. },
  5135. pause: function pause() {
  5136. if (q.paused === true) {
  5137. return;
  5138. }
  5139. q.paused = true;
  5140. },
  5141. resume: function resume() {
  5142. if (q.paused === false) {
  5143. return;
  5144. }
  5145. q.paused = false;
  5146. // Need to call q.process once per concurrent
  5147. // worker to preserve full concurrency after pause
  5148. for (var w = 1; w <= q.concurrency; w++) {
  5149. q.process();
  5150. }
  5151. }
  5152. };
  5153. function _insert(data, insertAtFront, callback) {
  5154. if (callback != null && typeof callback !== 'function') {
  5155. // eslint-disable-line no-eq-null,eqeqeq
  5156. throw new Error('task callback must be a function');
  5157. }
  5158. q.started = true;
  5159. if (data == null && q.idle()) {
  5160. // eslint-disable-line no-eq-null,eqeqeq
  5161. // call drain immediately if there are no tasks
  5162. setTimeout(function () {
  5163. return q.drain();
  5164. }, 1);
  5165. return;
  5166. }
  5167. var item = {
  5168. data: data,
  5169. callback: typeof callback === 'function' ? callback : _noop
  5170. };
  5171. if (insertAtFront) {
  5172. q._tasks.unshift(item);
  5173. } else {
  5174. q._tasks.push(item);
  5175. }
  5176. setTimeout(function () {
  5177. return q.process();
  5178. }, 1);
  5179. }
  5180. function _next(task) {
  5181. return function next() {
  5182. workers -= 1;
  5183. task.callback.apply(task, arguments);
  5184. if (arguments[0] != null) {
  5185. // eslint-disable-line no-eq-null,eqeqeq
  5186. q.error(arguments[0], task.data);
  5187. }
  5188. if (workers <= q.concurrency - q.buffer) {
  5189. q.unsaturated();
  5190. }
  5191. if (q.idle()) {
  5192. q.drain();
  5193. }
  5194. q.process();
  5195. };
  5196. }
  5197. return q;
  5198. }
  5199. }, {}], 35: [function (require, module, exports) {
  5200. 'use strict';
  5201. exports.__esModule = true;
  5202. exports.encodeBinary = encodeBinary;
  5203. var _keyStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
  5204. function encodeBinary(input) {
  5205. var output = '';
  5206. var inx = 0;
  5207. while (inx < input.length) {
  5208. // Fill byte buffer array
  5209. var bytebuffer = [0, 0, 0];
  5210. var encodedCharIndexes = [0, 0, 0, 0];
  5211. for (var jnx = 0; jnx < bytebuffer.length; ++jnx) {
  5212. if (inx < input.length) {
  5213. // throw away high-order byte, as documented at:
  5214. // https://developer.mozilla.org/En/Using_XMLHttpRequest#Handling_binary_data
  5215. bytebuffer[jnx] = input.charCodeAt(inx++) & 0xff;
  5216. } else {
  5217. bytebuffer[jnx] = 0;
  5218. }
  5219. }
  5220. // Get each encoded character, 6 bits at a time
  5221. // index 1: first 6 bits
  5222. encodedCharIndexes[0] = bytebuffer[0] >> 2;
  5223. // index 2: second 6 bits (2 least significant bits from input byte 1 + 4 most significant bits from byte 2)
  5224. encodedCharIndexes[1] = (bytebuffer[0] & 0x3) << 4 | bytebuffer[1] >> 4;
  5225. // index 3: third 6 bits (4 least significant bits from input byte 2 + 2 most significant bits from byte 3)
  5226. encodedCharIndexes[2] = (bytebuffer[1] & 0x0f) << 2 | bytebuffer[2] >> 6;
  5227. // index 3: forth 6 bits (6 least significant bits from input byte 3)
  5228. encodedCharIndexes[3] = bytebuffer[2] & 0x3f;
  5229. // Determine whether padding happened, and adjust accordingly
  5230. var paddingBytes = inx - (input.length - 1);
  5231. switch (paddingBytes) {
  5232. case 2:
  5233. // Set last 2 characters to padding char
  5234. encodedCharIndexes[3] = 64;
  5235. encodedCharIndexes[2] = 64;
  5236. break;
  5237. case 1:
  5238. // Set last character to padding char
  5239. encodedCharIndexes[3] = 64;
  5240. break;
  5241. default:
  5242. break; // No padding - proceed
  5243. }
  5244. // Now we will grab each appropriate character out of our keystring
  5245. // based on our index array and append it to the output string
  5246. for (var _jnx = 0; _jnx < encodedCharIndexes.length; ++_jnx) {
  5247. output += _keyStr.charAt(encodedCharIndexes[_jnx]);
  5248. }
  5249. }
  5250. return output;
  5251. }
  5252. }, {}], 36: [function (require, module, exports) {
  5253. 'use strict';
  5254. // import Loader from './Loader';
  5255. // import Resource from './Resource';
  5256. // import * as async from './async';
  5257. // import * as b64 from './b64';
  5258. /* eslint-disable no-undef */
  5259. var Loader = require('./Loader').default;
  5260. var Resource = require('./Resource').default;
  5261. var async = require('./async');
  5262. var b64 = require('./b64');
  5263. Loader.Resource = Resource;
  5264. Loader.async = async;
  5265. Loader.base64 = b64;
  5266. // export manually, and also as default
  5267. module.exports = Loader;
  5268. // export default Loader;
  5269. module.exports.default = Loader;
  5270. }, { "./Loader": 32, "./Resource": 33, "./async": 34, "./b64": 35 }], 37: [function (require, module, exports) {
  5271. 'use strict';
  5272. exports.__esModule = true;
  5273. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
  5274. exports.blobMiddlewareFactory = blobMiddlewareFactory;
  5275. var _Resource = require('../../Resource');
  5276. var _Resource2 = _interopRequireDefault(_Resource);
  5277. var _b = require('../../b64');
  5278. var _b2 = _interopRequireDefault(_b);
  5279. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  5280. var Url = window.URL || window.URL;
  5281. // a middleware for transforming XHR loaded Blobs into more useful objects
  5282. function blobMiddlewareFactory() {
  5283. return function blobMiddleware(resource, next) {
  5284. if (!resource.data) {
  5285. next();
  5286. return;
  5287. }
  5288. // if this was an XHR load of a blob
  5289. if (resource.xhr && resource.xhrType === _Resource2.default.XHR_RESPONSE_TYPE.BLOB) {
  5290. // if there is no blob support we probably got a binary string back
  5291. if (!window.Blob || typeof resource.data === 'string') {
  5292. var type = resource.xhr.getResponseHeader('content-type');
  5293. // this is an image, convert the binary string into a data url
  5294. if (type && type.indexOf('image') === 0) {
  5295. resource.data = new Image();
  5296. resource.data.src = 'data:' + type + ';base64,' + _b2.default.encodeBinary(resource.xhr.responseText);
  5297. resource.type = _Resource2.default.TYPE.IMAGE;
  5298. // wait until the image loads and then callback
  5299. resource.data.onload = function () {
  5300. resource.data.onload = null;
  5301. next();
  5302. };
  5303. // next will be called on load
  5304. return;
  5305. }
  5306. }
  5307. // if content type says this is an image, then we should transform the blob into an Image object
  5308. else if (resource.data.type.indexOf('image') === 0) {
  5309. var _ret = function () {
  5310. var src = Url.createObjectURL(resource.data);
  5311. resource.blob = resource.data;
  5312. resource.data = new Image();
  5313. resource.data.src = src;
  5314. resource.type = _Resource2.default.TYPE.IMAGE;
  5315. // cleanup the no longer used blob after the image loads
  5316. // TODO: Is this correct? Will the image be invalid after revoking?
  5317. resource.data.onload = function () {
  5318. Url.revokeObjectURL(src);
  5319. resource.data.onload = null;
  5320. next();
  5321. };
  5322. // next will be called on load.
  5323. return {
  5324. v: void 0
  5325. };
  5326. }();
  5327. if ((typeof _ret === 'undefined' ? 'undefined' : _typeof(_ret)) === "object") return _ret.v;
  5328. }
  5329. }
  5330. next();
  5331. };
  5332. }
  5333. }, { "../../Resource": 33, "../../b64": 35 }], 38: [function (require, module, exports) {
  5334. // Copyright Joyent, Inc. and other Node contributors.
  5335. //
  5336. // Permission is hereby granted, free of charge, to any person obtaining a
  5337. // copy of this software and associated documentation files (the
  5338. // "Software"), to deal in the Software without restriction, including
  5339. // without limitation the rights to use, copy, modify, merge, publish,
  5340. // distribute, sublicense, and/or sell copies of the Software, and to permit
  5341. // persons to whom the Software is furnished to do so, subject to the
  5342. // following conditions:
  5343. //
  5344. // The above copyright notice and this permission notice shall be included
  5345. // in all copies or substantial portions of the Software.
  5346. //
  5347. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  5348. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  5349. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  5350. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  5351. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  5352. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  5353. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  5354. 'use strict';
  5355. var punycode = require('punycode');
  5356. var util = require('./util');
  5357. exports.parse = urlParse;
  5358. exports.resolve = urlResolve;
  5359. exports.resolveObject = urlResolveObject;
  5360. exports.format = urlFormat;
  5361. exports.Url = Url;
  5362. function Url() {
  5363. this.protocol = null;
  5364. this.slashes = null;
  5365. this.auth = null;
  5366. this.host = null;
  5367. this.port = null;
  5368. this.hostname = null;
  5369. this.hash = null;
  5370. this.search = null;
  5371. this.query = null;
  5372. this.pathname = null;
  5373. this.path = null;
  5374. this.href = null;
  5375. }
  5376. // Reference: RFC 3986, RFC 1808, RFC 2396
  5377. // define these here so at least they only have to be
  5378. // compiled once on the first module load.
  5379. var protocolPattern = /^([a-z0-9.+-]+:)/i,
  5380. portPattern = /:[0-9]*$/,
  5381. // Special case for a simple path URL
  5382. simplePathPattern = /^(\/\/?(?!\/)[^\?\s]*)(\?[^\s]*)?$/,
  5383. // RFC 2396: characters reserved for delimiting URLs.
  5384. // We actually just auto-escape these.
  5385. delims = ['<', '>', '"', '`', ' ', '\r', '\n', '\t'],
  5386. // RFC 2396: characters not allowed for various reasons.
  5387. unwise = ['{', '}', '|', '\\', '^', '`'].concat(delims),
  5388. // Allowed by RFCs, but cause of XSS attacks. Always escape these.
  5389. autoEscape = ['\''].concat(unwise),
  5390. // Characters that are never ever allowed in a hostname.
  5391. // Note that any invalid chars are also handled, but these
  5392. // are the ones that are *expected* to be seen, so we fast-path
  5393. // them.
  5394. nonHostChars = ['%', '/', '?', ';', '#'].concat(autoEscape),
  5395. hostEndingChars = ['/', '?', '#'],
  5396. hostnameMaxLen = 255,
  5397. hostnamePartPattern = /^[+a-z0-9A-Z_-]{0,63}$/,
  5398. hostnamePartStart = /^([+a-z0-9A-Z_-]{0,63})(.*)$/,
  5399. // protocols that can allow "unsafe" and "unwise" chars.
  5400. unsafeProtocol = {
  5401. 'javascript': true,
  5402. 'javascript:': true
  5403. },
  5404. // protocols that never have a hostname.
  5405. hostlessProtocol = {
  5406. 'javascript': true,
  5407. 'javascript:': true
  5408. },
  5409. // protocols that always contain a // bit.
  5410. slashedProtocol = {
  5411. 'http': true,
  5412. 'https': true,
  5413. 'ftp': true,
  5414. 'gopher': true,
  5415. 'file': true,
  5416. 'http:': true,
  5417. 'https:': true,
  5418. 'ftp:': true,
  5419. 'gopher:': true,
  5420. 'file:': true
  5421. },
  5422. querystring = require('querystring');
  5423. function urlParse(url, parseQueryString, slashesDenoteHost) {
  5424. if (url && util.isObject(url) && url instanceof Url) return url;
  5425. var u = new Url;
  5426. u.parse(url, parseQueryString, slashesDenoteHost);
  5427. return u;
  5428. }
  5429. Url.prototype.parse = function (url, parseQueryString, slashesDenoteHost) {
  5430. if (!util.isString(url)) {
  5431. throw new TypeError("Parameter 'url' must be a string, not " + typeof url);
  5432. }
  5433. // Copy chrome, IE, opera backslash-handling behavior.
  5434. // Back slashes before the query string get converted to forward slashes
  5435. // See: https://code.google.com/p/chromium/issues/detail?id=25916
  5436. var queryIndex = url.indexOf('?'),
  5437. splitter =
  5438. (queryIndex !== -1 && queryIndex < url.indexOf('#')) ? '?' : '#',
  5439. uSplit = url.split(splitter),
  5440. slashRegex = /\\/g;
  5441. uSplit[0] = uSplit[0].replace(slashRegex, '/');
  5442. url = uSplit.join(splitter);
  5443. var rest = url;
  5444. // trim before proceeding.
  5445. // This is to support parse stuff like " http://foo.com \n"
  5446. rest = rest.trim();
  5447. if (!slashesDenoteHost && url.split('#').length === 1) {
  5448. // Try fast path regexp
  5449. var simplePath = simplePathPattern.exec(rest);
  5450. if (simplePath) {
  5451. this.path = rest;
  5452. this.href = rest;
  5453. this.pathname = simplePath[1];
  5454. if (simplePath[2]) {
  5455. this.search = simplePath[2];
  5456. if (parseQueryString) {
  5457. this.query = querystring.parse(this.search.substr(1));
  5458. } else {
  5459. this.query = this.search.substr(1);
  5460. }
  5461. } else if (parseQueryString) {
  5462. this.search = '';
  5463. this.query = {};
  5464. }
  5465. return this;
  5466. }
  5467. }
  5468. var proto = protocolPattern.exec(rest);
  5469. if (proto) {
  5470. proto = proto[0];
  5471. var lowerProto = proto.toLowerCase();
  5472. this.protocol = lowerProto;
  5473. rest = rest.substr(proto.length);
  5474. }
  5475. // figure out if it's got a host
  5476. // user@server is *always* interpreted as a hostname, and url
  5477. // resolution will treat //foo/bar as host=foo,path=bar because that's
  5478. // how the browser resolves relative URLs.
  5479. if (slashesDenoteHost || proto || rest.match(/^\/\/[^@\/]+@[^@\/]+/)) {
  5480. var slashes = rest.substr(0, 2) === '//';
  5481. if (slashes && !(proto && hostlessProtocol[proto])) {
  5482. rest = rest.substr(2);
  5483. this.slashes = true;
  5484. }
  5485. }
  5486. if (!hostlessProtocol[proto] &&
  5487. (slashes || (proto && !slashedProtocol[proto]))) {
  5488. // there's a hostname.
  5489. // the first instance of /, ?, ;, or # ends the host.
  5490. //
  5491. // If there is an @ in the hostname, then non-host chars *are* allowed
  5492. // to the left of the last @ sign, unless some host-ending character
  5493. // comes *before* the @-sign.
  5494. // URLs are obnoxious.
  5495. //
  5496. // ex:
  5497. // http://a@b@c/ => user:a@b host:c
  5498. // http://a@b?@c => user:a host:c path:/?@c
  5499. // v0.12 TODO(isaacs): This is not quite how Chrome does things.
  5500. // Review our test case against browsers more comprehensively.
  5501. // find the first instance of any hostEndingChars
  5502. var hostEnd = -1;
  5503. for (var i = 0; i < hostEndingChars.length; i++) {
  5504. var hec = rest.indexOf(hostEndingChars[i]);
  5505. if (hec !== -1 && (hostEnd === -1 || hec < hostEnd))
  5506. hostEnd = hec;
  5507. }
  5508. // at this point, either we have an explicit point where the
  5509. // auth portion cannot go past, or the last @ char is the decider.
  5510. var auth, atSign;
  5511. if (hostEnd === -1) {
  5512. // atSign can be anywhere.
  5513. atSign = rest.lastIndexOf('@');
  5514. } else {
  5515. // atSign must be in auth portion.
  5516. // http://a@b/c@d => host:b auth:a path:/c@d
  5517. atSign = rest.lastIndexOf('@', hostEnd);
  5518. }
  5519. // Now we have a portion which is definitely the auth.
  5520. // Pull that off.
  5521. if (atSign !== -1) {
  5522. auth = rest.slice(0, atSign);
  5523. rest = rest.slice(atSign + 1);
  5524. this.auth = decodeURIComponent(auth);
  5525. }
  5526. // the host is the remaining to the left of the first non-host char
  5527. hostEnd = -1;
  5528. for (var i = 0; i < nonHostChars.length; i++) {
  5529. var hec = rest.indexOf(nonHostChars[i]);
  5530. if (hec !== -1 && (hostEnd === -1 || hec < hostEnd))
  5531. hostEnd = hec;
  5532. }
  5533. // if we still have not hit it, then the entire thing is a host.
  5534. if (hostEnd === -1)
  5535. hostEnd = rest.length;
  5536. this.host = rest.slice(0, hostEnd);
  5537. rest = rest.slice(hostEnd);
  5538. // pull out port.
  5539. this.parseHost();
  5540. // we've indicated that there is a hostname,
  5541. // so even if it's empty, it has to be present.
  5542. this.hostname = this.hostname || '';
  5543. // if hostname begins with [ and ends with ]
  5544. // assume that it's an IPv6 address.
  5545. var ipv6Hostname = this.hostname[0] === '[' &&
  5546. this.hostname[this.hostname.length - 1] === ']';
  5547. // validate a little.
  5548. if (!ipv6Hostname) {
  5549. var hostparts = this.hostname.split(/\./);
  5550. for (var i = 0, l = hostparts.length; i < l; i++) {
  5551. var part = hostparts[i];
  5552. if (!part) continue;
  5553. if (!part.match(hostnamePartPattern)) {
  5554. var newpart = '';
  5555. for (var j = 0, k = part.length; j < k; j++) {
  5556. if (part.charCodeAt(j) > 127) {
  5557. // we replace non-ASCII char with a temporary placeholder
  5558. // we need this to make sure size of hostname is not
  5559. // broken by replacing non-ASCII by nothing
  5560. newpart += 'x';
  5561. } else {
  5562. newpart += part[j];
  5563. }
  5564. }
  5565. // we test again with ASCII char only
  5566. if (!newpart.match(hostnamePartPattern)) {
  5567. var validParts = hostparts.slice(0, i);
  5568. var notHost = hostparts.slice(i + 1);
  5569. var bit = part.match(hostnamePartStart);
  5570. if (bit) {
  5571. validParts.push(bit[1]);
  5572. notHost.unshift(bit[2]);
  5573. }
  5574. if (notHost.length) {
  5575. rest = '/' + notHost.join('.') + rest;
  5576. }
  5577. this.hostname = validParts.join('.');
  5578. break;
  5579. }
  5580. }
  5581. }
  5582. }
  5583. if (this.hostname.length > hostnameMaxLen) {
  5584. this.hostname = '';
  5585. } else {
  5586. // hostnames are always lower case.
  5587. this.hostname = this.hostname.toLowerCase();
  5588. }
  5589. if (!ipv6Hostname) {
  5590. // IDNA Support: Returns a punycoded representation of "domain".
  5591. // It only converts parts of the domain name that
  5592. // have non-ASCII characters, i.e. it doesn't matter if
  5593. // you call it with a domain that already is ASCII-only.
  5594. this.hostname = punycode.toASCII(this.hostname);
  5595. }
  5596. var p = this.port ? ':' + this.port : '';
  5597. var h = this.hostname || '';
  5598. this.host = h + p;
  5599. this.href += this.host;
  5600. // strip [ and ] from the hostname
  5601. // the host field still retains them, though
  5602. if (ipv6Hostname) {
  5603. this.hostname = this.hostname.substr(1, this.hostname.length - 2);
  5604. if (rest[0] !== '/') {
  5605. rest = '/' + rest;
  5606. }
  5607. }
  5608. }
  5609. // now rest is set to the post-host stuff.
  5610. // chop off any delim chars.
  5611. if (!unsafeProtocol[lowerProto]) {
  5612. // First, make 100% sure that any "autoEscape" chars get
  5613. // escaped, even if encodeURIComponent doesn't think they
  5614. // need to be.
  5615. for (var i = 0, l = autoEscape.length; i < l; i++) {
  5616. var ae = autoEscape[i];
  5617. if (rest.indexOf(ae) === -1)
  5618. continue;
  5619. var esc = encodeURIComponent(ae);
  5620. if (esc === ae) {
  5621. esc = escape(ae);
  5622. }
  5623. rest = rest.split(ae).join(esc);
  5624. }
  5625. }
  5626. // chop off from the tail first.
  5627. var hash = rest.indexOf('#');
  5628. if (hash !== -1) {
  5629. // got a fragment string.
  5630. this.hash = rest.substr(hash);
  5631. rest = rest.slice(0, hash);
  5632. }
  5633. var qm = rest.indexOf('?');
  5634. if (qm !== -1) {
  5635. this.search = rest.substr(qm);
  5636. this.query = rest.substr(qm + 1);
  5637. if (parseQueryString) {
  5638. this.query = querystring.parse(this.query);
  5639. }
  5640. rest = rest.slice(0, qm);
  5641. } else if (parseQueryString) {
  5642. // no query string, but parseQueryString still requested
  5643. this.search = '';
  5644. this.query = {};
  5645. }
  5646. if (rest) this.pathname = rest;
  5647. if (slashedProtocol[lowerProto] &&
  5648. this.hostname && !this.pathname) {
  5649. this.pathname = '/';
  5650. }
  5651. //to support http.request
  5652. if (this.pathname || this.search) {
  5653. var p = this.pathname || '';
  5654. var s = this.search || '';
  5655. this.path = p + s;
  5656. }
  5657. // finally, reconstruct the href based on what has been validated.
  5658. this.href = this.format();
  5659. return this;
  5660. };
  5661. // format a parsed object into a url string
  5662. function urlFormat(obj) {
  5663. // ensure it's an object, and not a string url.
  5664. // If it's an obj, this is a no-op.
  5665. // this way, you can call url_format() on strings
  5666. // to clean up potentially wonky urls.
  5667. if (util.isString(obj)) obj = urlParse(obj);
  5668. if (!(obj instanceof Url)) return Url.prototype.format.call(obj);
  5669. return obj.format();
  5670. }
  5671. Url.prototype.format = function () {
  5672. var auth = this.auth || '';
  5673. if (auth) {
  5674. auth = encodeURIComponent(auth);
  5675. auth = auth.replace(/%3A/i, ':');
  5676. auth += '@';
  5677. }
  5678. var protocol = this.protocol || '',
  5679. pathname = this.pathname || '',
  5680. hash = this.hash || '',
  5681. host = false,
  5682. query = '';
  5683. if (this.host) {
  5684. host = auth + this.host;
  5685. } else if (this.hostname) {
  5686. host = auth + (this.hostname.indexOf(':') === -1 ?
  5687. this.hostname :
  5688. '[' + this.hostname + ']');
  5689. if (this.port) {
  5690. host += ':' + this.port;
  5691. }
  5692. }
  5693. if (this.query &&
  5694. util.isObject(this.query) &&
  5695. Object.keys(this.query).length) {
  5696. query = querystring.stringify(this.query);
  5697. }
  5698. var search = this.search || (query && ('?' + query)) || '';
  5699. if (protocol && protocol.substr(-1) !== ':') protocol += ':';
  5700. // only the slashedProtocols get the //. Not mailto:, xmpp:, etc.
  5701. // unless they had them to begin with.
  5702. if (this.slashes ||
  5703. (!protocol || slashedProtocol[protocol]) && host !== false) {
  5704. host = '//' + (host || '');
  5705. if (pathname && pathname.charAt(0) !== '/') pathname = '/' + pathname;
  5706. } else if (!host) {
  5707. host = '';
  5708. }
  5709. if (hash && hash.charAt(0) !== '#') hash = '#' + hash;
  5710. if (search && search.charAt(0) !== '?') search = '?' + search;
  5711. pathname = pathname.replace(/[?#]/g, function (match) {
  5712. return encodeURIComponent(match);
  5713. });
  5714. search = search.replace('#', '%23');
  5715. return protocol + host + pathname + search + hash;
  5716. };
  5717. function urlResolve(source, relative) {
  5718. return urlParse(source, false, true).resolve(relative);
  5719. }
  5720. Url.prototype.resolve = function (relative) {
  5721. return this.resolveObject(urlParse(relative, false, true)).format();
  5722. };
  5723. function urlResolveObject(source, relative) {
  5724. if (!source) return relative;
  5725. return urlParse(source, false, true).resolveObject(relative);
  5726. }
  5727. Url.prototype.resolveObject = function (relative) {
  5728. if (util.isString(relative)) {
  5729. var rel = new Url();
  5730. rel.parse(relative, false, true);
  5731. relative = rel;
  5732. }
  5733. var result = new Url();
  5734. var tkeys = Object.keys(this);
  5735. for (var tk = 0; tk < tkeys.length; tk++) {
  5736. var tkey = tkeys[tk];
  5737. result[tkey] = this[tkey];
  5738. }
  5739. // hash is always overridden, no matter what.
  5740. // even href="" will remove it.
  5741. result.hash = relative.hash;
  5742. // if the relative url is empty, then there's nothing left to do here.
  5743. if (relative.href === '') {
  5744. result.href = result.format();
  5745. return result;
  5746. }
  5747. // hrefs like //foo/bar always cut to the protocol.
  5748. if (relative.slashes && !relative.protocol) {
  5749. // take everything except the protocol from relative
  5750. var rkeys = Object.keys(relative);
  5751. for (var rk = 0; rk < rkeys.length; rk++) {
  5752. var rkey = rkeys[rk];
  5753. if (rkey !== 'protocol')
  5754. result[rkey] = relative[rkey];
  5755. }
  5756. //urlParse appends trailing / to urls like http://www.example.com
  5757. if (slashedProtocol[result.protocol] &&
  5758. result.hostname && !result.pathname) {
  5759. result.path = result.pathname = '/';
  5760. }
  5761. result.href = result.format();
  5762. return result;
  5763. }
  5764. if (relative.protocol && relative.protocol !== result.protocol) {
  5765. // if it's a known url protocol, then changing
  5766. // the protocol does weird things
  5767. // first, if it's not file:, then we MUST have a host,
  5768. // and if there was a path
  5769. // to begin with, then we MUST have a path.
  5770. // if it is file:, then the host is dropped,
  5771. // because that's known to be hostless.
  5772. // anything else is assumed to be absolute.
  5773. if (!slashedProtocol[relative.protocol]) {
  5774. var keys = Object.keys(relative);
  5775. for (var v = 0; v < keys.length; v++) {
  5776. var k = keys[v];
  5777. result[k] = relative[k];
  5778. }
  5779. result.href = result.format();
  5780. return result;
  5781. }
  5782. result.protocol = relative.protocol;
  5783. if (!relative.host && !hostlessProtocol[relative.protocol]) {
  5784. var relPath = (relative.pathname || '').split('/');
  5785. while (relPath.length && !(relative.host = relPath.shift()));
  5786. if (!relative.host) relative.host = '';
  5787. if (!relative.hostname) relative.hostname = '';
  5788. if (relPath[0] !== '') relPath.unshift('');
  5789. if (relPath.length < 2) relPath.unshift('');
  5790. result.pathname = relPath.join('/');
  5791. } else {
  5792. result.pathname = relative.pathname;
  5793. }
  5794. result.search = relative.search;
  5795. result.query = relative.query;
  5796. result.host = relative.host || '';
  5797. result.auth = relative.auth;
  5798. result.hostname = relative.hostname || relative.host;
  5799. result.port = relative.port;
  5800. // to support http.request
  5801. if (result.pathname || result.search) {
  5802. var p = result.pathname || '';
  5803. var s = result.search || '';
  5804. result.path = p + s;
  5805. }
  5806. result.slashes = result.slashes || relative.slashes;
  5807. result.href = result.format();
  5808. return result;
  5809. }
  5810. var isSourceAbs = (result.pathname && result.pathname.charAt(0) === '/'),
  5811. isRelAbs = (
  5812. relative.host ||
  5813. relative.pathname && relative.pathname.charAt(0) === '/'
  5814. ),
  5815. mustEndAbs = (isRelAbs || isSourceAbs ||
  5816. (result.host && relative.pathname)),
  5817. removeAllDots = mustEndAbs,
  5818. srcPath = result.pathname && result.pathname.split('/') || [],
  5819. relPath = relative.pathname && relative.pathname.split('/') || [],
  5820. psychotic = result.protocol && !slashedProtocol[result.protocol];
  5821. // if the url is a non-slashed url, then relative
  5822. // links like ../.. should be able
  5823. // to crawl up to the hostname, as well. This is strange.
  5824. // result.protocol has already been set by now.
  5825. // Later on, put the first path part into the host field.
  5826. if (psychotic) {
  5827. result.hostname = '';
  5828. result.port = null;
  5829. if (result.host) {
  5830. if (srcPath[0] === '') srcPath[0] = result.host;
  5831. else srcPath.unshift(result.host);
  5832. }
  5833. result.host = '';
  5834. if (relative.protocol) {
  5835. relative.hostname = null;
  5836. relative.port = null;
  5837. if (relative.host) {
  5838. if (relPath[0] === '') relPath[0] = relative.host;
  5839. else relPath.unshift(relative.host);
  5840. }
  5841. relative.host = null;
  5842. }
  5843. mustEndAbs = mustEndAbs && (relPath[0] === '' || srcPath[0] === '');
  5844. }
  5845. if (isRelAbs) {
  5846. // it's absolute.
  5847. result.host = (relative.host || relative.host === '') ?
  5848. relative.host : result.host;
  5849. result.hostname = (relative.hostname || relative.hostname === '') ?
  5850. relative.hostname : result.hostname;
  5851. result.search = relative.search;
  5852. result.query = relative.query;
  5853. srcPath = relPath;
  5854. // fall through to the dot-handling below.
  5855. } else if (relPath.length) {
  5856. // it's relative
  5857. // throw away the existing file, and take the new path instead.
  5858. if (!srcPath) srcPath = [];
  5859. srcPath.pop();
  5860. srcPath = srcPath.concat(relPath);
  5861. result.search = relative.search;
  5862. result.query = relative.query;
  5863. } else if (!util.isNullOrUndefined(relative.search)) {
  5864. // just pull out the search.
  5865. // like href='?foo'.
  5866. // Put this after the other two cases because it simplifies the booleans
  5867. if (psychotic) {
  5868. result.hostname = result.host = srcPath.shift();
  5869. //occationaly the auth can get stuck only in host
  5870. //this especially happens in cases like
  5871. //url.resolveObject('mailto:local1@domain1', 'local2@domain2')
  5872. var authInHost = result.host && result.host.indexOf('@') > 0 ?
  5873. result.host.split('@') : false;
  5874. if (authInHost) {
  5875. result.auth = authInHost.shift();
  5876. result.host = result.hostname = authInHost.shift();
  5877. }
  5878. }
  5879. result.search = relative.search;
  5880. result.query = relative.query;
  5881. //to support http.request
  5882. if (!util.isNull(result.pathname) || !util.isNull(result.search)) {
  5883. result.path = (result.pathname ? result.pathname : '') +
  5884. (result.search ? result.search : '');
  5885. }
  5886. result.href = result.format();
  5887. return result;
  5888. }
  5889. if (!srcPath.length) {
  5890. // no path at all. easy.
  5891. // we've already handled the other stuff above.
  5892. result.pathname = null;
  5893. //to support http.request
  5894. if (result.search) {
  5895. result.path = '/' + result.search;
  5896. } else {
  5897. result.path = null;
  5898. }
  5899. result.href = result.format();
  5900. return result;
  5901. }
  5902. // if a url ENDs in . or .., then it must get a trailing slash.
  5903. // however, if it ends in anything else non-slashy,
  5904. // then it must NOT get a trailing slash.
  5905. var last = srcPath.slice(-1)[0];
  5906. var hasTrailingSlash = (
  5907. (result.host || relative.host || srcPath.length > 1) &&
  5908. (last === '.' || last === '..') || last === '');
  5909. // strip single dots, resolve double dots to parent dir
  5910. // if the path tries to go above the root, `up` ends up > 0
  5911. var up = 0;
  5912. for (var i = srcPath.length; i >= 0; i--) {
  5913. last = srcPath[i];
  5914. if (last === '.') {
  5915. srcPath.splice(i, 1);
  5916. } else if (last === '..') {
  5917. srcPath.splice(i, 1);
  5918. up++;
  5919. } else if (up) {
  5920. srcPath.splice(i, 1);
  5921. up--;
  5922. }
  5923. }
  5924. // if the path is allowed to go above the root, restore leading ..s
  5925. if (!mustEndAbs && !removeAllDots) {
  5926. for (; up--; up) {
  5927. srcPath.unshift('..');
  5928. }
  5929. }
  5930. if (mustEndAbs && srcPath[0] !== '' &&
  5931. (!srcPath[0] || srcPath[0].charAt(0) !== '/')) {
  5932. srcPath.unshift('');
  5933. }
  5934. if (hasTrailingSlash && (srcPath.join('/').substr(-1) !== '/')) {
  5935. srcPath.push('');
  5936. }
  5937. var isAbsolute = srcPath[0] === '' ||
  5938. (srcPath[0] && srcPath[0].charAt(0) === '/');
  5939. // put the host back
  5940. if (psychotic) {
  5941. result.hostname = result.host = isAbsolute ? '' :
  5942. srcPath.length ? srcPath.shift() : '';
  5943. //occationaly the auth can get stuck only in host
  5944. //this especially happens in cases like
  5945. //url.resolveObject('mailto:local1@domain1', 'local2@domain2')
  5946. var authInHost = result.host && result.host.indexOf('@') > 0 ?
  5947. result.host.split('@') : false;
  5948. if (authInHost) {
  5949. result.auth = authInHost.shift();
  5950. result.host = result.hostname = authInHost.shift();
  5951. }
  5952. }
  5953. mustEndAbs = mustEndAbs || (result.host && srcPath.length);
  5954. if (mustEndAbs && !isAbsolute) {
  5955. srcPath.unshift('');
  5956. }
  5957. if (!srcPath.length) {
  5958. result.pathname = null;
  5959. result.path = null;
  5960. } else {
  5961. result.pathname = srcPath.join('/');
  5962. }
  5963. //to support request.http
  5964. if (!util.isNull(result.pathname) || !util.isNull(result.search)) {
  5965. result.path = (result.pathname ? result.pathname : '') +
  5966. (result.search ? result.search : '');
  5967. }
  5968. result.auth = relative.auth || result.auth;
  5969. result.slashes = result.slashes || relative.slashes;
  5970. result.href = result.format();
  5971. return result;
  5972. };
  5973. Url.prototype.parseHost = function () {
  5974. var host = this.host;
  5975. var port = portPattern.exec(host);
  5976. if (port) {
  5977. port = port[0];
  5978. if (port !== ':') {
  5979. this.port = port.substr(1);
  5980. }
  5981. host = host.substr(0, host.length - port.length);
  5982. }
  5983. if (host) this.hostname = host;
  5984. };
  5985. }, { "./util": 39, "punycode": 27, "querystring": 30 }], 39: [function (require, module, exports) {
  5986. 'use strict';
  5987. module.exports = {
  5988. isString: function (arg) {
  5989. return typeof (arg) === 'string';
  5990. },
  5991. isObject: function (arg) {
  5992. return typeof (arg) === 'object' && arg !== null;
  5993. },
  5994. isNull: function (arg) {
  5995. return arg === null;
  5996. },
  5997. isNullOrUndefined: function (arg) {
  5998. return arg == null;
  5999. }
  6000. };
  6001. }, {}], 40: [function (require, module, exports) {
  6002. 'use strict';
  6003. exports.__esModule = true;
  6004. var _core = require('../core');
  6005. var core = _interopRequireWildcard(_core);
  6006. var _ismobilejs = require('ismobilejs');
  6007. var _ismobilejs2 = _interopRequireDefault(_ismobilejs);
  6008. var _accessibleTarget = require('./accessibleTarget');
  6009. var _accessibleTarget2 = _interopRequireDefault(_accessibleTarget);
  6010. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  6011. function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
  6012. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  6013. // add some extra variables to the container..
  6014. core.utils.mixins.delayMixin(core.DisplayObject.prototype, _accessibleTarget2.default);
  6015. var KEY_CODE_TAB = 9;
  6016. var DIV_TOUCH_SIZE = 100;
  6017. var DIV_TOUCH_POS_X = 0;
  6018. var DIV_TOUCH_POS_Y = 0;
  6019. var DIV_TOUCH_ZINDEX = 2;
  6020. var DIV_HOOK_SIZE = 1;
  6021. var DIV_HOOK_POS_X = -1000;
  6022. var DIV_HOOK_POS_Y = -1000;
  6023. var DIV_HOOK_ZINDEX = 2;
  6024. /**
  6025. * The Accessibility manager recreates the ability to tab and have content read by screen
  6026. * readers. This is very important as it can possibly help people with disabilities access pixi
  6027. * content.
  6028. *
  6029. * Much like interaction any DisplayObject can be made accessible. This manager will map the
  6030. * events as if the mouse was being used, minimizing the effort required to implement.
  6031. *
  6032. * An instance of this class is automatically created by default, and can be found at renderer.plugins.accessibility
  6033. *
  6034. * @class
  6035. * @memberof PIXI.accessibility
  6036. */
  6037. var AccessibilityManager = function () {
  6038. /**
  6039. * @param {PIXI.CanvasRenderer|PIXI.WebGLRenderer} renderer - A reference to the current renderer
  6040. */
  6041. function AccessibilityManager(renderer) {
  6042. _classCallCheck(this, AccessibilityManager);
  6043. if ((_ismobilejs2.default.tablet || _ismobilejs2.default.phone) && !navigator.isCocoonJS) {
  6044. this.createTouchHook();
  6045. }
  6046. // first we create a div that will sit over the PixiJS element. This is where the div overlays will go.
  6047. var div = document.createElement('div');
  6048. div.style.width = DIV_TOUCH_SIZE + 'px';
  6049. div.style.height = DIV_TOUCH_SIZE + 'px';
  6050. div.style.position = 'absolute';
  6051. div.style.top = DIV_TOUCH_POS_X + 'px';
  6052. div.style.left = DIV_TOUCH_POS_Y + 'px';
  6053. div.style.zIndex = DIV_TOUCH_ZINDEX;
  6054. /**
  6055. * This is the dom element that will sit over the PixiJS element. This is where the div overlays will go.
  6056. *
  6057. * @type {HTMLElement}
  6058. * @private
  6059. */
  6060. this.div = div;
  6061. /**
  6062. * A simple pool for storing divs.
  6063. *
  6064. * @type {*}
  6065. * @private
  6066. */
  6067. this.pool = [];
  6068. /**
  6069. * This is a tick used to check if an object is no longer being rendered.
  6070. *
  6071. * @type {Number}
  6072. * @private
  6073. */
  6074. this.renderId = 0;
  6075. /**
  6076. * Setting this to true will visually show the divs.
  6077. *
  6078. * @type {boolean}
  6079. */
  6080. this.debug = false;
  6081. /**
  6082. * The renderer this accessibility manager works for.
  6083. *
  6084. * @member {PIXI.SystemRenderer}
  6085. */
  6086. this.renderer = renderer;
  6087. /**
  6088. * The array of currently active accessible items.
  6089. *
  6090. * @member {Array<*>}
  6091. * @private
  6092. */
  6093. this.children = [];
  6094. /**
  6095. * pre-bind the functions
  6096. *
  6097. * @private
  6098. */
  6099. this._onKeyDown = this._onKeyDown.bind(this);
  6100. this._onMouseMove = this._onMouseMove.bind(this);
  6101. /**
  6102. * stores the state of the manager. If there are no accessible objects or the mouse is moving, this will be false.
  6103. *
  6104. * @member {Array<*>}
  6105. * @private
  6106. */
  6107. this.isActive = false;
  6108. this.isMobileAccessabillity = false;
  6109. // let listen for tab.. once pressed we can fire up and show the accessibility layer
  6110. window.addEventListener('keydown', this._onKeyDown, false);
  6111. }
  6112. /**
  6113. * Creates the touch hooks.
  6114. *
  6115. */
  6116. AccessibilityManager.prototype.createTouchHook = function createTouchHook() {
  6117. var _this = this;
  6118. var hookDiv = document.createElement('button');
  6119. hookDiv.style.width = DIV_HOOK_SIZE + 'px';
  6120. hookDiv.style.height = DIV_HOOK_SIZE + 'px';
  6121. hookDiv.style.position = 'absolute';
  6122. hookDiv.style.top = DIV_HOOK_POS_X + 'px';
  6123. hookDiv.style.left = DIV_HOOK_POS_Y + 'px';
  6124. hookDiv.style.zIndex = DIV_HOOK_ZINDEX;
  6125. hookDiv.style.backgroundColor = '#FF0000';
  6126. hookDiv.title = 'HOOK DIV';
  6127. hookDiv.addEventListener('focus', function () {
  6128. _this.isMobileAccessabillity = true;
  6129. _this.activate();
  6130. document.body.removeChild(hookDiv);
  6131. });
  6132. document.body.appendChild(hookDiv);
  6133. };
  6134. /**
  6135. * Activating will cause the Accessibility layer to be shown. This is called when a user
  6136. * preses the tab key.
  6137. *
  6138. * @private
  6139. */
  6140. AccessibilityManager.prototype.activate = function activate() {
  6141. if (this.isActive) {
  6142. return;
  6143. }
  6144. this.isActive = true;
  6145. window.document.addEventListener('mousemove', this._onMouseMove, true);
  6146. window.removeEventListener('keydown', this._onKeyDown, false);
  6147. this.renderer.on('postrender', this.update, this);
  6148. if (this.renderer.view.parentNode) {
  6149. this.renderer.view.parentNode.appendChild(this.div);
  6150. }
  6151. };
  6152. /**
  6153. * Deactivating will cause the Accessibility layer to be hidden. This is called when a user moves
  6154. * the mouse.
  6155. *
  6156. * @private
  6157. */
  6158. AccessibilityManager.prototype.deactivate = function deactivate() {
  6159. if (!this.isActive || this.isMobileAccessabillity) {
  6160. return;
  6161. }
  6162. this.isActive = false;
  6163. window.document.removeEventListener('mousemove', this._onMouseMove);
  6164. window.addEventListener('keydown', this._onKeyDown, false);
  6165. this.renderer.off('postrender', this.update);
  6166. if (this.div.parentNode) {
  6167. this.div.parentNode.removeChild(this.div);
  6168. }
  6169. };
  6170. /**
  6171. * This recursive function will run through the scene graph and add any new accessible objects to the DOM layer.
  6172. *
  6173. * @private
  6174. * @param {PIXI.Container} displayObject - The DisplayObject to check.
  6175. */
  6176. AccessibilityManager.prototype.updateAccessibleObjects = function updateAccessibleObjects(displayObject) {
  6177. if (!displayObject.visible) {
  6178. return;
  6179. }
  6180. if (displayObject.accessible && displayObject.interactive) {
  6181. if (!displayObject._accessibleActive) {
  6182. this.addChild(displayObject);
  6183. }
  6184. displayObject.renderId = this.renderId;
  6185. }
  6186. var children = displayObject.children;
  6187. for (var i = children.length - 1; i >= 0; i--) {
  6188. this.updateAccessibleObjects(children[i]);
  6189. }
  6190. };
  6191. /**
  6192. * Before each render this function will ensure that all divs are mapped correctly to their DisplayObjects.
  6193. *
  6194. * @private
  6195. */
  6196. AccessibilityManager.prototype.update = function update() {
  6197. if (!this.renderer.renderingToScreen) {
  6198. return;
  6199. }
  6200. // update children...
  6201. this.updateAccessibleObjects(this.renderer._lastObjectRendered);
  6202. var rect = this.renderer.view.getBoundingClientRect();
  6203. var sx = rect.width / this.renderer.width;
  6204. var sy = rect.height / this.renderer.height;
  6205. var div = this.div;
  6206. div.style.left = rect.left + 'px';
  6207. div.style.top = rect.top + 'px';
  6208. div.style.width = this.renderer.width + 'px';
  6209. div.style.height = this.renderer.height + 'px';
  6210. for (var i = 0; i < this.children.length; i++) {
  6211. var child = this.children[i];
  6212. if (child.renderId !== this.renderId) {
  6213. child._accessibleActive = false;
  6214. core.utils.removeItems(this.children, i, 1);
  6215. this.div.removeChild(child._accessibleDiv);
  6216. this.pool.push(child._accessibleDiv);
  6217. child._accessibleDiv = null;
  6218. i--;
  6219. if (this.children.length === 0) {
  6220. this.deactivate();
  6221. }
  6222. } else {
  6223. // map div to display..
  6224. div = child._accessibleDiv;
  6225. var hitArea = child.hitArea;
  6226. var wt = child.worldTransform;
  6227. if (child.hitArea) {
  6228. div.style.left = (wt.tx + hitArea.x * wt.a) * sx + 'px';
  6229. div.style.top = (wt.ty + hitArea.y * wt.d) * sy + 'px';
  6230. div.style.width = hitArea.width * wt.a * sx + 'px';
  6231. div.style.height = hitArea.height * wt.d * sy + 'px';
  6232. } else {
  6233. hitArea = child.getBounds();
  6234. this.capHitArea(hitArea);
  6235. div.style.left = hitArea.x * sx + 'px';
  6236. div.style.top = hitArea.y * sy + 'px';
  6237. div.style.width = hitArea.width * sx + 'px';
  6238. div.style.height = hitArea.height * sy + 'px';
  6239. }
  6240. }
  6241. }
  6242. // increment the render id..
  6243. this.renderId++;
  6244. };
  6245. /**
  6246. * TODO: docs.
  6247. *
  6248. * @param {Rectangle} hitArea - TODO docs
  6249. */
  6250. AccessibilityManager.prototype.capHitArea = function capHitArea(hitArea) {
  6251. if (hitArea.x < 0) {
  6252. hitArea.width += hitArea.x;
  6253. hitArea.x = 0;
  6254. }
  6255. if (hitArea.y < 0) {
  6256. hitArea.height += hitArea.y;
  6257. hitArea.y = 0;
  6258. }
  6259. if (hitArea.x + hitArea.width > this.renderer.width) {
  6260. hitArea.width = this.renderer.width - hitArea.x;
  6261. }
  6262. if (hitArea.y + hitArea.height > this.renderer.height) {
  6263. hitArea.height = this.renderer.height - hitArea.y;
  6264. }
  6265. };
  6266. /**
  6267. * Adds a DisplayObject to the accessibility manager
  6268. *
  6269. * @private
  6270. * @param {DisplayObject} displayObject - The child to make accessible.
  6271. */
  6272. AccessibilityManager.prototype.addChild = function addChild(displayObject) {
  6273. // this.activate();
  6274. var div = this.pool.pop();
  6275. if (!div) {
  6276. div = document.createElement('button');
  6277. div.style.width = DIV_TOUCH_SIZE + 'px';
  6278. div.style.height = DIV_TOUCH_SIZE + 'px';
  6279. div.style.backgroundColor = this.debug ? 'rgba(255,0,0,0.5)' : 'transparent';
  6280. div.style.position = 'absolute';
  6281. div.style.zIndex = DIV_TOUCH_ZINDEX;
  6282. div.style.borderStyle = 'none';
  6283. div.addEventListener('click', this._onClick.bind(this));
  6284. div.addEventListener('focus', this._onFocus.bind(this));
  6285. div.addEventListener('focusout', this._onFocusOut.bind(this));
  6286. }
  6287. if (displayObject.accessibleTitle) {
  6288. div.title = displayObject.accessibleTitle;
  6289. } else if (!displayObject.accessibleTitle && !displayObject.accessibleHint) {
  6290. div.title = 'displayObject ' + this.tabIndex;
  6291. }
  6292. if (displayObject.accessibleHint) {
  6293. div.setAttribute('aria-label', displayObject.accessibleHint);
  6294. }
  6295. //
  6296. displayObject._accessibleActive = true;
  6297. displayObject._accessibleDiv = div;
  6298. div.displayObject = displayObject;
  6299. this.children.push(displayObject);
  6300. this.div.appendChild(displayObject._accessibleDiv);
  6301. displayObject._accessibleDiv.tabIndex = displayObject.tabIndex;
  6302. };
  6303. /**
  6304. * Maps the div button press to pixi's InteractionManager (click)
  6305. *
  6306. * @private
  6307. * @param {MouseEvent} e - The click event.
  6308. */
  6309. AccessibilityManager.prototype._onClick = function _onClick(e) {
  6310. var interactionManager = this.renderer.plugins.interaction;
  6311. interactionManager.dispatchEvent(e.target.displayObject, 'click', interactionManager.eventData);
  6312. };
  6313. /**
  6314. * Maps the div focus events to pixi's InteractionManager (mouseover)
  6315. *
  6316. * @private
  6317. * @param {FocusEvent} e - The focus event.
  6318. */
  6319. AccessibilityManager.prototype._onFocus = function _onFocus(e) {
  6320. var interactionManager = this.renderer.plugins.interaction;
  6321. interactionManager.dispatchEvent(e.target.displayObject, 'mouseover', interactionManager.eventData);
  6322. };
  6323. /**
  6324. * Maps the div focus events to pixi's InteractionManager (mouseout)
  6325. *
  6326. * @private
  6327. * @param {FocusEvent} e - The focusout event.
  6328. */
  6329. AccessibilityManager.prototype._onFocusOut = function _onFocusOut(e) {
  6330. var interactionManager = this.renderer.plugins.interaction;
  6331. interactionManager.dispatchEvent(e.target.displayObject, 'mouseout', interactionManager.eventData);
  6332. };
  6333. /**
  6334. * Is called when a key is pressed
  6335. *
  6336. * @private
  6337. * @param {KeyboardEvent} e - The keydown event.
  6338. */
  6339. AccessibilityManager.prototype._onKeyDown = function _onKeyDown(e) {
  6340. if (e.keyCode !== KEY_CODE_TAB) {
  6341. return;
  6342. }
  6343. this.activate();
  6344. };
  6345. /**
  6346. * Is called when the mouse moves across the renderer element
  6347. *
  6348. * @private
  6349. */
  6350. AccessibilityManager.prototype._onMouseMove = function _onMouseMove() {
  6351. this.deactivate();
  6352. };
  6353. /**
  6354. * Destroys the accessibility manager
  6355. *
  6356. */
  6357. AccessibilityManager.prototype.destroy = function destroy() {
  6358. this.div = null;
  6359. for (var i = 0; i < this.children.length; i++) {
  6360. this.children[i].div = null;
  6361. }
  6362. window.document.removeEventListener('mousemove', this._onMouseMove);
  6363. window.removeEventListener('keydown', this._onKeyDown);
  6364. this.pool = null;
  6365. this.children = null;
  6366. this.renderer = null;
  6367. };
  6368. return AccessibilityManager;
  6369. }();
  6370. exports.default = AccessibilityManager;
  6371. core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager);
  6372. core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager);
  6373. }, { "../core": 65, "./accessibleTarget": 41, "ismobilejs": 4 }], 41: [function (require, module, exports) {
  6374. "use strict";
  6375. exports.__esModule = true;
  6376. /**
  6377. * Default property values of accessible objects
  6378. * used by {@link PIXI.accessibility.AccessibilityManager}.
  6379. *
  6380. * @function accessibleTarget
  6381. * @memberof PIXI.accessibility
  6382. * @example
  6383. * function MyObject() {}
  6384. *
  6385. * Object.assign(
  6386. * MyObject.prototype,
  6387. * PIXI.accessibility.accessibleTarget
  6388. * );
  6389. */
  6390. exports.default = {
  6391. /**
  6392. * Flag for if the object is accessible. If true AccessibilityManager will overlay a
  6393. * shadow div with attributes set
  6394. *
  6395. * @member {boolean}
  6396. */
  6397. accessible: false,
  6398. /**
  6399. * Sets the title attribute of the shadow div
  6400. * If accessibleTitle AND accessibleHint has not been this will default to 'displayObject [tabIndex]'
  6401. *
  6402. * @member {string}
  6403. */
  6404. accessibleTitle: null,
  6405. /**
  6406. * Sets the aria-label attribute of the shadow div
  6407. *
  6408. * @member {string}
  6409. */
  6410. accessibleHint: null,
  6411. /**
  6412. * @todo Needs docs.
  6413. */
  6414. tabIndex: 0,
  6415. /**
  6416. * @todo Needs docs.
  6417. */
  6418. _accessibleActive: false,
  6419. /**
  6420. * @todo Needs docs.
  6421. */
  6422. _accessibleDiv: false
  6423. };
  6424. }, {}], 42: [function (require, module, exports) {
  6425. 'use strict';
  6426. exports.__esModule = true;
  6427. var _accessibleTarget = require('./accessibleTarget');
  6428. Object.defineProperty(exports, 'accessibleTarget', {
  6429. enumerable: true,
  6430. get: function get() {
  6431. return _interopRequireDefault(_accessibleTarget).default;
  6432. }
  6433. });
  6434. var _AccessibilityManager = require('./AccessibilityManager');
  6435. Object.defineProperty(exports, 'AccessibilityManager', {
  6436. enumerable: true,
  6437. get: function get() {
  6438. return _interopRequireDefault(_AccessibilityManager).default;
  6439. }
  6440. });
  6441. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  6442. }, { "./AccessibilityManager": 40, "./accessibleTarget": 41 }], 43: [function (require, module, exports) {
  6443. 'use strict';
  6444. exports.__esModule = true;
  6445. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  6446. var _autoDetectRenderer = require('./autoDetectRenderer');
  6447. var _Container = require('./display/Container');
  6448. var _Container2 = _interopRequireDefault(_Container);
  6449. var _ticker = require('./ticker');
  6450. var _settings = require('./settings');
  6451. var _settings2 = _interopRequireDefault(_settings);
  6452. var _const = require('./const');
  6453. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  6454. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  6455. /**
  6456. * Convenience class to create a new PIXI application.
  6457. * This class automatically creates the renderer, ticker
  6458. * and root container.
  6459. *
  6460. * @example
  6461. * // Create the application
  6462. * const app = new PIXI.Application();
  6463. *
  6464. * // Add the view to the DOM
  6465. * document.body.appendChild(app.view);
  6466. *
  6467. * // ex, add display objects
  6468. * app.stage.addChild(PIXI.Sprite.fromImage('something.png'));
  6469. *
  6470. * @class
  6471. * @memberof PIXI
  6472. */
  6473. var Application = function () {
  6474. // eslint-disable-next-line valid-jsdoc
  6475. /**
  6476. * @param {object} [options] - The optional renderer parameters
  6477. * @param {boolean} [options.autoStart=true] - automatically starts the rendering after the construction.
  6478. * Note that setting this parameter to false does NOT stop the shared ticker even if you set
  6479. * options.sharedTicker to true in case that it is already started. Stop it by your own.
  6480. * @param {number} [options.width=800] - the width of the renderers view
  6481. * @param {number} [options.height=600] - the height of the renderers view
  6482. * @param {HTMLCanvasElement} [options.view] - the canvas to use as a view, optional
  6483. * @param {boolean} [options.transparent=false] - If the render view is transparent, default false
  6484. * @param {boolean} [options.antialias=false] - sets antialias (only applicable in chrome at the moment)
  6485. * @param {boolean} [options.preserveDrawingBuffer=false] - enables drawing buffer preservation, enable this if you
  6486. * need to call toDataUrl on the webgl context
  6487. * @param {number} [options.resolution=1] - The resolution / device pixel ratio of the renderer, retina would be 2
  6488. * @param {boolean} [options.forceCanvas=false] - prevents selection of WebGL renderer, even if such is present
  6489. * @param {number} [options.backgroundColor=0x000000] - The background color of the rendered area
  6490. * (shown if not transparent).
  6491. * @param {boolean} [options.clearBeforeRender=true] - This sets if the renderer will clear the canvas or
  6492. * not before the new render pass.
  6493. * @param {boolean} [options.roundPixels=false] - If true PixiJS will Math.floor() x/y values when rendering,
  6494. * stopping pixel interpolation.
  6495. * @param {boolean} [options.forceFXAA=false] - forces FXAA antialiasing to be used over native.
  6496. * FXAA is faster, but may not always look as great **webgl only**
  6497. * @param {boolean} [options.legacy=false] - `true` to ensure compatibility with older / less advanced devices.
  6498. * If you experience unexplained flickering try setting this to true. **webgl only**
  6499. * @param {string} [options.powerPreference] - Parameter passed to webgl context, set to "high-performance"
  6500. * for devices with dual graphics card **webgl only**
  6501. * @param {boolean} [options.sharedTicker=false] - `true` to use PIXI.ticker.shared, `false` to create new ticker.
  6502. * @param {boolean} [options.sharedLoader=false] - `true` to use PIXI.loaders.shared, `false` to create new Loader.
  6503. */
  6504. function Application(options, arg2, arg3, arg4, arg5) {
  6505. _classCallCheck(this, Application);
  6506. // Support for constructor(width, height, options, noWebGL, useSharedTicker)
  6507. if (typeof options === 'number') {
  6508. options = Object.assign({
  6509. width: options,
  6510. height: arg2 || _settings2.default.RENDER_OPTIONS.height,
  6511. forceCanvas: !!arg4,
  6512. sharedTicker: !!arg5
  6513. }, arg3);
  6514. }
  6515. /**
  6516. * The default options, so we mixin functionality later.
  6517. * @member {object}
  6518. * @protected
  6519. */
  6520. this._options = options = Object.assign({
  6521. autoStart: true,
  6522. sharedTicker: false,
  6523. forceCanvas: false,
  6524. sharedLoader: false
  6525. }, options);
  6526. /**
  6527. * WebGL renderer if available, otherwise CanvasRenderer
  6528. * @member {PIXI.WebGLRenderer|PIXI.CanvasRenderer}
  6529. */
  6530. this.renderer = (0, _autoDetectRenderer.autoDetectRenderer)(options);
  6531. /**
  6532. * The root display container that's rendered.
  6533. * @member {PIXI.Container}
  6534. */
  6535. this.stage = new _Container2.default();
  6536. /**
  6537. * Internal reference to the ticker
  6538. * @member {PIXI.ticker.Ticker}
  6539. * @private
  6540. */
  6541. this._ticker = null;
  6542. /**
  6543. * Ticker for doing render updates.
  6544. * @member {PIXI.ticker.Ticker}
  6545. * @default PIXI.ticker.shared
  6546. */
  6547. this.ticker = options.sharedTicker ? _ticker.shared : new _ticker.Ticker();
  6548. // Start the rendering
  6549. if (options.autoStart) {
  6550. this.start();
  6551. }
  6552. }
  6553. /**
  6554. * Render the current stage.
  6555. */
  6556. Application.prototype.render = function render() {
  6557. this.renderer.render(this.stage);
  6558. };
  6559. /**
  6560. * Convenience method for stopping the render.
  6561. */
  6562. Application.prototype.stop = function stop() {
  6563. this._ticker.stop();
  6564. };
  6565. /**
  6566. * Convenience method for starting the render.
  6567. */
  6568. Application.prototype.start = function start() {
  6569. this._ticker.start();
  6570. };
  6571. /**
  6572. * Reference to the renderer's canvas element.
  6573. * @member {HTMLCanvasElement}
  6574. * @readonly
  6575. */
  6576. /**
  6577. * Destroy and don't use after this.
  6578. * @param {Boolean} [removeView=false] Automatically remove canvas from DOM.
  6579. */
  6580. Application.prototype.destroy = function destroy(removeView) {
  6581. if (this._ticker) {
  6582. var oldTicker = this._ticker;
  6583. this.ticker = null;
  6584. oldTicker.destroy();
  6585. }
  6586. this.stage.destroy();
  6587. this.stage = null;
  6588. this.renderer.destroy(removeView);
  6589. this.renderer = null;
  6590. this._options = null;
  6591. };
  6592. _createClass(Application, [{
  6593. key: 'ticker',
  6594. set: function set(ticker) // eslint-disable-line require-jsdoc
  6595. {
  6596. if (this._ticker) {
  6597. this._ticker.remove(this.render, this);
  6598. }
  6599. this._ticker = ticker;
  6600. if (ticker) {
  6601. ticker.add(this.render, this, _const.UPDATE_PRIORITY.LOW);
  6602. }
  6603. },
  6604. get: function get() // eslint-disable-line require-jsdoc
  6605. {
  6606. return this._ticker;
  6607. }
  6608. }, {
  6609. key: 'view',
  6610. get: function get() {
  6611. return this.renderer.view;
  6612. }
  6613. /**
  6614. * Reference to the renderer's screen rectangle. Its safe to use as filterArea or hitArea for whole screen
  6615. * @member {PIXI.Rectangle}
  6616. * @readonly
  6617. */
  6618. }, {
  6619. key: 'screen',
  6620. get: function get() {
  6621. return this.renderer.screen;
  6622. }
  6623. }]);
  6624. return Application;
  6625. }();
  6626. exports.default = Application;
  6627. }, { "./autoDetectRenderer": 45, "./const": 46, "./display/Container": 48, "./settings": 101, "./ticker": 121 }], 44: [function (require, module, exports) {
  6628. 'use strict';
  6629. exports.__esModule = true;
  6630. var _pixiGlCore = require('pixi-gl-core');
  6631. var _settings = require('./settings');
  6632. var _settings2 = _interopRequireDefault(_settings);
  6633. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  6634. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  6635. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  6636. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  6637. function checkPrecision(src, def) {
  6638. if (src instanceof Array) {
  6639. if (src[0].substring(0, 9) !== 'precision') {
  6640. var copy = src.slice(0);
  6641. copy.unshift('precision ' + def + ' float;');
  6642. return copy;
  6643. }
  6644. } else if (src.trim().substring(0, 9) !== 'precision') {
  6645. return 'precision ' + def + ' float;\n' + src;
  6646. }
  6647. return src;
  6648. }
  6649. /**
  6650. * Wrapper class, webGL Shader for Pixi.
  6651. * Adds precision string if vertexSrc or fragmentSrc have no mention of it.
  6652. *
  6653. * @class
  6654. * @extends GLShader
  6655. * @memberof PIXI
  6656. */
  6657. var Shader = function (_GLShader) {
  6658. _inherits(Shader, _GLShader);
  6659. /**
  6660. *
  6661. * @param {WebGLRenderingContext} gl - The current WebGL rendering context
  6662. * @param {string|string[]} vertexSrc - The vertex shader source as an array of strings.
  6663. * @param {string|string[]} fragmentSrc - The fragment shader source as an array of strings.
  6664. * @param {object} [attributeLocations] - A key value pair showing which location eact attribute should sit.
  6665. e.g. {position:0, uvs:1}.
  6666. * @param {string} [precision] - The float precision of the shader. Options are 'lowp', 'mediump' or 'highp'.
  6667. */
  6668. function Shader(gl, vertexSrc, fragmentSrc, attributeLocations, precision) {
  6669. _classCallCheck(this, Shader);
  6670. return _possibleConstructorReturn(this, _GLShader.call(this, gl, checkPrecision(vertexSrc, precision || _settings2.default.PRECISION_VERTEX), checkPrecision(fragmentSrc, precision || _settings2.default.PRECISION_FRAGMENT), undefined, attributeLocations));
  6671. }
  6672. return Shader;
  6673. }(_pixiGlCore.GLShader);
  6674. exports.default = Shader;
  6675. }, { "./settings": 101, "pixi-gl-core": 15 }], 45: [function (require, module, exports) {
  6676. 'use strict';
  6677. exports.__esModule = true;
  6678. exports.autoDetectRenderer = autoDetectRenderer;
  6679. var _utils = require('./utils');
  6680. var utils = _interopRequireWildcard(_utils);
  6681. var _CanvasRenderer = require('./renderers/canvas/CanvasRenderer');
  6682. var _CanvasRenderer2 = _interopRequireDefault(_CanvasRenderer);
  6683. var _WebGLRenderer = require('./renderers/webgl/WebGLRenderer');
  6684. var _WebGLRenderer2 = _interopRequireDefault(_WebGLRenderer);
  6685. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  6686. function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
  6687. // eslint-disable-next-line valid-jsdoc
  6688. /**
  6689. * This helper function will automatically detect which renderer you should be using.
  6690. * WebGL is the preferred renderer as it is a lot faster. If webGL is not supported by
  6691. * the browser then this function will return a canvas renderer
  6692. *
  6693. * @memberof PIXI
  6694. * @function autoDetectRenderer
  6695. * @param {object} [options] - The optional renderer parameters
  6696. * @param {number} [options.width=800] - the width of the renderers view
  6697. * @param {number} [options.height=600] - the height of the renderers view
  6698. * @param {HTMLCanvasElement} [options.view] - the canvas to use as a view, optional
  6699. * @param {boolean} [options.transparent=false] - If the render view is transparent, default false
  6700. * @param {boolean} [options.antialias=false] - sets antialias (only applicable in chrome at the moment)
  6701. * @param {boolean} [options.preserveDrawingBuffer=false] - enables drawing buffer preservation, enable this if you
  6702. * need to call toDataUrl on the webgl context
  6703. * @param {number} [options.backgroundColor=0x000000] - The background color of the rendered area
  6704. * (shown if not transparent).
  6705. * @param {boolean} [options.clearBeforeRender=true] - This sets if the renderer will clear the canvas or
  6706. * not before the new render pass.
  6707. * @param {number} [options.resolution=1] - The resolution / device pixel ratio of the renderer, retina would be 2
  6708. * @param {boolean} [options.forceCanvas=false] - prevents selection of WebGL renderer, even if such is present
  6709. * @param {boolean} [options.roundPixels=false] - If true PixiJS will Math.floor() x/y values when rendering,
  6710. * stopping pixel interpolation.
  6711. * @param {boolean} [options.forceFXAA=false] - forces FXAA antialiasing to be used over native.
  6712. * FXAA is faster, but may not always look as great **webgl only**
  6713. * @param {boolean} [options.legacy=false] - `true` to ensure compatibility with older / less advanced devices.
  6714. * If you experience unexplained flickering try setting this to true. **webgl only**
  6715. * @param {string} [options.powerPreference] - Parameter passed to webgl context, set to "high-performance"
  6716. * for devices with dual graphics card **webgl only**
  6717. * @return {PIXI.WebGLRenderer|PIXI.CanvasRenderer} Returns WebGL renderer if available, otherwise CanvasRenderer
  6718. */
  6719. function autoDetectRenderer(options, arg1, arg2, arg3) {
  6720. // Backward-compatible support for noWebGL option
  6721. var forceCanvas = options && options.forceCanvas;
  6722. if (arg3 !== undefined) {
  6723. forceCanvas = arg3;
  6724. }
  6725. if (!forceCanvas && utils.isWebGLSupported()) {
  6726. return new _WebGLRenderer2.default(options, arg1, arg2);
  6727. }
  6728. return new _CanvasRenderer2.default(options, arg1, arg2);
  6729. }
  6730. }, { "./renderers/canvas/CanvasRenderer": 77, "./renderers/webgl/WebGLRenderer": 84, "./utils": 125 }], 46: [function (require, module, exports) {
  6731. 'use strict';
  6732. exports.__esModule = true;
  6733. /**
  6734. * String of the current PIXI version.
  6735. *
  6736. * @static
  6737. * @constant
  6738. * @memberof PIXI
  6739. * @name VERSION
  6740. * @type {string}
  6741. */
  6742. var VERSION = exports.VERSION = '4.7.3';
  6743. /**
  6744. * Two Pi.
  6745. *
  6746. * @static
  6747. * @constant
  6748. * @memberof PIXI
  6749. * @type {number}
  6750. */
  6751. var PI_2 = exports.PI_2 = Math.PI * 2;
  6752. /**
  6753. * Conversion factor for converting radians to degrees.
  6754. *
  6755. * @static
  6756. * @constant
  6757. * @memberof PIXI
  6758. * @type {number}
  6759. */
  6760. var RAD_TO_DEG = exports.RAD_TO_DEG = 180 / Math.PI;
  6761. /**
  6762. * Conversion factor for converting degrees to radians.
  6763. *
  6764. * @static
  6765. * @constant
  6766. * @memberof PIXI
  6767. * @type {number}
  6768. */
  6769. var DEG_TO_RAD = exports.DEG_TO_RAD = Math.PI / 180;
  6770. /**
  6771. * Constant to identify the Renderer Type.
  6772. *
  6773. * @static
  6774. * @constant
  6775. * @memberof PIXI
  6776. * @name RENDERER_TYPE
  6777. * @type {object}
  6778. * @property {number} UNKNOWN - Unknown render type.
  6779. * @property {number} WEBGL - WebGL render type.
  6780. * @property {number} CANVAS - Canvas render type.
  6781. */
  6782. var RENDERER_TYPE = exports.RENDERER_TYPE = {
  6783. UNKNOWN: 0,
  6784. WEBGL: 1,
  6785. CANVAS: 2
  6786. };
  6787. /**
  6788. * Various blend modes supported by PIXI.
  6789. *
  6790. * IMPORTANT - The WebGL renderer only supports the NORMAL, ADD, MULTIPLY and SCREEN blend modes.
  6791. * Anything else will silently act like NORMAL.
  6792. *
  6793. * @static
  6794. * @constant
  6795. * @memberof PIXI
  6796. * @name BLEND_MODES
  6797. * @type {object}
  6798. * @property {number} NORMAL
  6799. * @property {number} ADD
  6800. * @property {number} MULTIPLY
  6801. * @property {number} SCREEN
  6802. * @property {number} OVERLAY
  6803. * @property {number} DARKEN
  6804. * @property {number} LIGHTEN
  6805. * @property {number} COLOR_DODGE
  6806. * @property {number} COLOR_BURN
  6807. * @property {number} HARD_LIGHT
  6808. * @property {number} SOFT_LIGHT
  6809. * @property {number} DIFFERENCE
  6810. * @property {number} EXCLUSION
  6811. * @property {number} HUE
  6812. * @property {number} SATURATION
  6813. * @property {number} COLOR
  6814. * @property {number} LUMINOSITY
  6815. */
  6816. var BLEND_MODES = exports.BLEND_MODES = {
  6817. NORMAL: 0,
  6818. ADD: 1,
  6819. MULTIPLY: 2,
  6820. SCREEN: 3,
  6821. OVERLAY: 4,
  6822. DARKEN: 5,
  6823. LIGHTEN: 6,
  6824. COLOR_DODGE: 7,
  6825. COLOR_BURN: 8,
  6826. HARD_LIGHT: 9,
  6827. SOFT_LIGHT: 10,
  6828. DIFFERENCE: 11,
  6829. EXCLUSION: 12,
  6830. HUE: 13,
  6831. SATURATION: 14,
  6832. COLOR: 15,
  6833. LUMINOSITY: 16,
  6834. NORMAL_NPM: 17,
  6835. ADD_NPM: 18,
  6836. SCREEN_NPM: 19
  6837. };
  6838. /**
  6839. * Various webgl draw modes. These can be used to specify which GL drawMode to use
  6840. * under certain situations and renderers.
  6841. *
  6842. * @static
  6843. * @constant
  6844. * @memberof PIXI
  6845. * @name DRAW_MODES
  6846. * @type {object}
  6847. * @property {number} POINTS
  6848. * @property {number} LINES
  6849. * @property {number} LINE_LOOP
  6850. * @property {number} LINE_STRIP
  6851. * @property {number} TRIANGLES
  6852. * @property {number} TRIANGLE_STRIP
  6853. * @property {number} TRIANGLE_FAN
  6854. */
  6855. var DRAW_MODES = exports.DRAW_MODES = {
  6856. POINTS: 0,
  6857. LINES: 1,
  6858. LINE_LOOP: 2,
  6859. LINE_STRIP: 3,
  6860. TRIANGLES: 4,
  6861. TRIANGLE_STRIP: 5,
  6862. TRIANGLE_FAN: 6
  6863. };
  6864. /**
  6865. * The scale modes that are supported by pixi.
  6866. *
  6867. * The {@link PIXI.settings.SCALE_MODE} scale mode affects the default scaling mode of future operations.
  6868. * It can be re-assigned to either LINEAR or NEAREST, depending upon suitability.
  6869. *
  6870. * @static
  6871. * @constant
  6872. * @memberof PIXI
  6873. * @name SCALE_MODES
  6874. * @type {object}
  6875. * @property {number} LINEAR Smooth scaling
  6876. * @property {number} NEAREST Pixelating scaling
  6877. */
  6878. var SCALE_MODES = exports.SCALE_MODES = {
  6879. LINEAR: 0,
  6880. NEAREST: 1
  6881. };
  6882. /**
  6883. * The wrap modes that are supported by pixi.
  6884. *
  6885. * The {@link PIXI.settings.WRAP_MODE} wrap mode affects the default wrapping mode of future operations.
  6886. * It can be re-assigned to either CLAMP or REPEAT, depending upon suitability.
  6887. * If the texture is non power of two then clamp will be used regardless as webGL can
  6888. * only use REPEAT if the texture is po2.
  6889. *
  6890. * This property only affects WebGL.
  6891. *
  6892. * @static
  6893. * @constant
  6894. * @name WRAP_MODES
  6895. * @memberof PIXI
  6896. * @type {object}
  6897. * @property {number} CLAMP - The textures uvs are clamped
  6898. * @property {number} REPEAT - The texture uvs tile and repeat
  6899. * @property {number} MIRRORED_REPEAT - The texture uvs tile and repeat with mirroring
  6900. */
  6901. var WRAP_MODES = exports.WRAP_MODES = {
  6902. CLAMP: 0,
  6903. REPEAT: 1,
  6904. MIRRORED_REPEAT: 2
  6905. };
  6906. /**
  6907. * The gc modes that are supported by pixi.
  6908. *
  6909. * The {@link PIXI.settings.GC_MODE} Garbage Collection mode for PixiJS textures is AUTO
  6910. * If set to GC_MODE, the renderer will occasionally check textures usage. If they are not
  6911. * used for a specified period of time they will be removed from the GPU. They will of course
  6912. * be uploaded again when they are required. This is a silent behind the scenes process that
  6913. * should ensure that the GPU does not get filled up.
  6914. *
  6915. * Handy for mobile devices!
  6916. * This property only affects WebGL.
  6917. *
  6918. * @static
  6919. * @constant
  6920. * @name GC_MODES
  6921. * @memberof PIXI
  6922. * @type {object}
  6923. * @property {number} AUTO - Garbage collection will happen periodically automatically
  6924. * @property {number} MANUAL - Garbage collection will need to be called manually
  6925. */
  6926. var GC_MODES = exports.GC_MODES = {
  6927. AUTO: 0,
  6928. MANUAL: 1
  6929. };
  6930. /**
  6931. * Regexp for image type by extension.
  6932. *
  6933. * @static
  6934. * @constant
  6935. * @memberof PIXI
  6936. * @type {RegExp|string}
  6937. * @example `image.png`
  6938. */
  6939. var URL_FILE_EXTENSION = exports.URL_FILE_EXTENSION = /\.(\w{3,4})(?:$|\?|#)/i;
  6940. /**
  6941. * Regexp for data URI.
  6942. * Based on: {@link https://github.com/ragingwind/data-uri-regex}
  6943. *
  6944. * @static
  6945. * @constant
  6946. * @name DATA_URI
  6947. * @memberof PIXI
  6948. * @type {RegExp|string}
  6949. * @example data:image/png;base64
  6950. */
  6951. var DATA_URI = exports.DATA_URI = /^\s*data:(?:([\w-]+)\/([\w+.-]+))?(?:;(charset=[\w-]+|base64))?,(.*)/i;
  6952. /**
  6953. * Regexp for SVG size.
  6954. *
  6955. * @static
  6956. * @constant
  6957. * @name SVG_SIZE
  6958. * @memberof PIXI
  6959. * @type {RegExp|string}
  6960. * @example &lt;svg width="100" height="100"&gt;&lt;/svg&gt;
  6961. */
  6962. var SVG_SIZE = exports.SVG_SIZE = /<svg[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len
  6963. /**
  6964. * Constants that identify shapes, mainly to prevent `instanceof` calls.
  6965. *
  6966. * @static
  6967. * @constant
  6968. * @name SHAPES
  6969. * @memberof PIXI
  6970. * @type {object}
  6971. * @property {number} POLY Polygon
  6972. * @property {number} RECT Rectangle
  6973. * @property {number} CIRC Circle
  6974. * @property {number} ELIP Ellipse
  6975. * @property {number} RREC Rounded Rectangle
  6976. */
  6977. var SHAPES = exports.SHAPES = {
  6978. POLY: 0,
  6979. RECT: 1,
  6980. CIRC: 2,
  6981. ELIP: 3,
  6982. RREC: 4
  6983. };
  6984. /**
  6985. * Constants that specify float precision in shaders.
  6986. *
  6987. * @static
  6988. * @constant
  6989. * @name PRECISION
  6990. * @memberof PIXI
  6991. * @type {object}
  6992. * @property {string} LOW='lowp'
  6993. * @property {string} MEDIUM='mediump'
  6994. * @property {string} HIGH='highp'
  6995. */
  6996. var PRECISION = exports.PRECISION = {
  6997. LOW: 'lowp',
  6998. MEDIUM: 'mediump',
  6999. HIGH: 'highp'
  7000. };
  7001. /**
  7002. * Constants that specify the transform type.
  7003. *
  7004. * @static
  7005. * @constant
  7006. * @name TRANSFORM_MODE
  7007. * @memberof PIXI
  7008. * @type {object}
  7009. * @property {number} STATIC
  7010. * @property {number} DYNAMIC
  7011. */
  7012. var TRANSFORM_MODE = exports.TRANSFORM_MODE = {
  7013. STATIC: 0,
  7014. DYNAMIC: 1
  7015. };
  7016. /**
  7017. * Constants that define the type of gradient on text.
  7018. *
  7019. * @static
  7020. * @constant
  7021. * @name TEXT_GRADIENT
  7022. * @memberof PIXI
  7023. * @type {object}
  7024. * @property {number} LINEAR_VERTICAL Vertical gradient
  7025. * @property {number} LINEAR_HORIZONTAL Linear gradient
  7026. */
  7027. var TEXT_GRADIENT = exports.TEXT_GRADIENT = {
  7028. LINEAR_VERTICAL: 0,
  7029. LINEAR_HORIZONTAL: 1
  7030. };
  7031. /**
  7032. * Represents the update priorities used by internal PIXI classes when registered with
  7033. * the {@link PIXI.ticker.Ticker} object. Higher priority items are updated first and lower
  7034. * priority items, such as render, should go later.
  7035. *
  7036. * @static
  7037. * @constant
  7038. * @name UPDATE_PRIORITY
  7039. * @memberof PIXI
  7040. * @type {object}
  7041. * @property {number} INTERACTION=50 Highest priority, used for {@link PIXI.interaction.InteractionManager}
  7042. * @property {number} HIGH=25 High priority updating, {@link PIXI.VideoBaseTexture} and {@link PIXI.extras.AnimatedSprite}
  7043. * @property {number} NORMAL=0 Default priority for ticker events, see {@link PIXI.ticker.Ticker#add}.
  7044. * @property {number} LOW=-25 Low priority used for {@link PIXI.Application} rendering.
  7045. * @property {number} UTILITY=-50 Lowest priority used for {@link PIXI.prepare.BasePrepare} utility.
  7046. */
  7047. var UPDATE_PRIORITY = exports.UPDATE_PRIORITY = {
  7048. INTERACTION: 50,
  7049. HIGH: 25,
  7050. NORMAL: 0,
  7051. LOW: -25,
  7052. UTILITY: -50
  7053. };
  7054. }, {}], 47: [function (require, module, exports) {
  7055. 'use strict';
  7056. exports.__esModule = true;
  7057. var _math = require('../math');
  7058. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  7059. /**
  7060. * 'Builder' pattern for bounds rectangles
  7061. * Axis-Aligned Bounding Box
  7062. * It is not a shape! Its mutable thing, no 'EMPTY' or that kind of problems
  7063. *
  7064. * @class
  7065. * @memberof PIXI
  7066. */
  7067. var Bounds = function () {
  7068. /**
  7069. *
  7070. */
  7071. function Bounds() {
  7072. _classCallCheck(this, Bounds);
  7073. /**
  7074. * @member {number}
  7075. * @default 0
  7076. */
  7077. this.minX = Infinity;
  7078. /**
  7079. * @member {number}
  7080. * @default 0
  7081. */
  7082. this.minY = Infinity;
  7083. /**
  7084. * @member {number}
  7085. * @default 0
  7086. */
  7087. this.maxX = -Infinity;
  7088. /**
  7089. * @member {number}
  7090. * @default 0
  7091. */
  7092. this.maxY = -Infinity;
  7093. this.rect = null;
  7094. }
  7095. /**
  7096. * Checks if bounds are empty.
  7097. *
  7098. * @return {boolean} True if empty.
  7099. */
  7100. Bounds.prototype.isEmpty = function isEmpty() {
  7101. return this.minX > this.maxX || this.minY > this.maxY;
  7102. };
  7103. /**
  7104. * Clears the bounds and resets.
  7105. *
  7106. */
  7107. Bounds.prototype.clear = function clear() {
  7108. this.updateID++;
  7109. this.minX = Infinity;
  7110. this.minY = Infinity;
  7111. this.maxX = -Infinity;
  7112. this.maxY = -Infinity;
  7113. };
  7114. /**
  7115. * Can return Rectangle.EMPTY constant, either construct new rectangle, either use your rectangle
  7116. * It is not guaranteed that it will return tempRect
  7117. *
  7118. * @param {PIXI.Rectangle} rect - temporary object will be used if AABB is not empty
  7119. * @returns {PIXI.Rectangle} A rectangle of the bounds
  7120. */
  7121. Bounds.prototype.getRectangle = function getRectangle(rect) {
  7122. if (this.minX > this.maxX || this.minY > this.maxY) {
  7123. return _math.Rectangle.EMPTY;
  7124. }
  7125. rect = rect || new _math.Rectangle(0, 0, 1, 1);
  7126. rect.x = this.minX;
  7127. rect.y = this.minY;
  7128. rect.width = this.maxX - this.minX;
  7129. rect.height = this.maxY - this.minY;
  7130. return rect;
  7131. };
  7132. /**
  7133. * This function should be inlined when its possible.
  7134. *
  7135. * @param {PIXI.Point} point - The point to add.
  7136. */
  7137. Bounds.prototype.addPoint = function addPoint(point) {
  7138. this.minX = Math.min(this.minX, point.x);
  7139. this.maxX = Math.max(this.maxX, point.x);
  7140. this.minY = Math.min(this.minY, point.y);
  7141. this.maxY = Math.max(this.maxY, point.y);
  7142. };
  7143. /**
  7144. * Adds a quad, not transformed
  7145. *
  7146. * @param {Float32Array} vertices - The verts to add.
  7147. */
  7148. Bounds.prototype.addQuad = function addQuad(vertices) {
  7149. var minX = this.minX;
  7150. var minY = this.minY;
  7151. var maxX = this.maxX;
  7152. var maxY = this.maxY;
  7153. var x = vertices[0];
  7154. var y = vertices[1];
  7155. minX = x < minX ? x : minX;
  7156. minY = y < minY ? y : minY;
  7157. maxX = x > maxX ? x : maxX;
  7158. maxY = y > maxY ? y : maxY;
  7159. x = vertices[2];
  7160. y = vertices[3];
  7161. minX = x < minX ? x : minX;
  7162. minY = y < minY ? y : minY;
  7163. maxX = x > maxX ? x : maxX;
  7164. maxY = y > maxY ? y : maxY;
  7165. x = vertices[4];
  7166. y = vertices[5];
  7167. minX = x < minX ? x : minX;
  7168. minY = y < minY ? y : minY;
  7169. maxX = x > maxX ? x : maxX;
  7170. maxY = y > maxY ? y : maxY;
  7171. x = vertices[6];
  7172. y = vertices[7];
  7173. minX = x < minX ? x : minX;
  7174. minY = y < minY ? y : minY;
  7175. maxX = x > maxX ? x : maxX;
  7176. maxY = y > maxY ? y : maxY;
  7177. this.minX = minX;
  7178. this.minY = minY;
  7179. this.maxX = maxX;
  7180. this.maxY = maxY;
  7181. };
  7182. /**
  7183. * Adds sprite frame, transformed.
  7184. *
  7185. * @param {PIXI.TransformBase} transform - TODO
  7186. * @param {number} x0 - TODO
  7187. * @param {number} y0 - TODO
  7188. * @param {number} x1 - TODO
  7189. * @param {number} y1 - TODO
  7190. */
  7191. Bounds.prototype.addFrame = function addFrame(transform, x0, y0, x1, y1) {
  7192. var matrix = transform.worldTransform;
  7193. var a = matrix.a;
  7194. var b = matrix.b;
  7195. var c = matrix.c;
  7196. var d = matrix.d;
  7197. var tx = matrix.tx;
  7198. var ty = matrix.ty;
  7199. var minX = this.minX;
  7200. var minY = this.minY;
  7201. var maxX = this.maxX;
  7202. var maxY = this.maxY;
  7203. var x = a * x0 + c * y0 + tx;
  7204. var y = b * x0 + d * y0 + ty;
  7205. minX = x < minX ? x : minX;
  7206. minY = y < minY ? y : minY;
  7207. maxX = x > maxX ? x : maxX;
  7208. maxY = y > maxY ? y : maxY;
  7209. x = a * x1 + c * y0 + tx;
  7210. y = b * x1 + d * y0 + ty;
  7211. minX = x < minX ? x : minX;
  7212. minY = y < minY ? y : minY;
  7213. maxX = x > maxX ? x : maxX;
  7214. maxY = y > maxY ? y : maxY;
  7215. x = a * x0 + c * y1 + tx;
  7216. y = b * x0 + d * y1 + ty;
  7217. minX = x < minX ? x : minX;
  7218. minY = y < minY ? y : minY;
  7219. maxX = x > maxX ? x : maxX;
  7220. maxY = y > maxY ? y : maxY;
  7221. x = a * x1 + c * y1 + tx;
  7222. y = b * x1 + d * y1 + ty;
  7223. minX = x < minX ? x : minX;
  7224. minY = y < minY ? y : minY;
  7225. maxX = x > maxX ? x : maxX;
  7226. maxY = y > maxY ? y : maxY;
  7227. this.minX = minX;
  7228. this.minY = minY;
  7229. this.maxX = maxX;
  7230. this.maxY = maxY;
  7231. };
  7232. /**
  7233. * Add an array of vertices
  7234. *
  7235. * @param {PIXI.TransformBase} transform - TODO
  7236. * @param {Float32Array} vertices - TODO
  7237. * @param {number} beginOffset - TODO
  7238. * @param {number} endOffset - TODO
  7239. */
  7240. Bounds.prototype.addVertices = function addVertices(transform, vertices, beginOffset, endOffset) {
  7241. var matrix = transform.worldTransform;
  7242. var a = matrix.a;
  7243. var b = matrix.b;
  7244. var c = matrix.c;
  7245. var d = matrix.d;
  7246. var tx = matrix.tx;
  7247. var ty = matrix.ty;
  7248. var minX = this.minX;
  7249. var minY = this.minY;
  7250. var maxX = this.maxX;
  7251. var maxY = this.maxY;
  7252. for (var i = beginOffset; i < endOffset; i += 2) {
  7253. var rawX = vertices[i];
  7254. var rawY = vertices[i + 1];
  7255. var x = a * rawX + c * rawY + tx;
  7256. var y = d * rawY + b * rawX + ty;
  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. }
  7262. this.minX = minX;
  7263. this.minY = minY;
  7264. this.maxX = maxX;
  7265. this.maxY = maxY;
  7266. };
  7267. /**
  7268. * Adds other Bounds
  7269. *
  7270. * @param {PIXI.Bounds} bounds - TODO
  7271. */
  7272. Bounds.prototype.addBounds = function addBounds(bounds) {
  7273. var minX = this.minX;
  7274. var minY = this.minY;
  7275. var maxX = this.maxX;
  7276. var maxY = this.maxY;
  7277. this.minX = bounds.minX < minX ? bounds.minX : minX;
  7278. this.minY = bounds.minY < minY ? bounds.minY : minY;
  7279. this.maxX = bounds.maxX > maxX ? bounds.maxX : maxX;
  7280. this.maxY = bounds.maxY > maxY ? bounds.maxY : maxY;
  7281. };
  7282. /**
  7283. * Adds other Bounds, masked with Bounds
  7284. *
  7285. * @param {PIXI.Bounds} bounds - TODO
  7286. * @param {PIXI.Bounds} mask - TODO
  7287. */
  7288. Bounds.prototype.addBoundsMask = function addBoundsMask(bounds, mask) {
  7289. var _minX = bounds.minX > mask.minX ? bounds.minX : mask.minX;
  7290. var _minY = bounds.minY > mask.minY ? bounds.minY : mask.minY;
  7291. var _maxX = bounds.maxX < mask.maxX ? bounds.maxX : mask.maxX;
  7292. var _maxY = bounds.maxY < mask.maxY ? bounds.maxY : mask.maxY;
  7293. if (_minX <= _maxX && _minY <= _maxY) {
  7294. var minX = this.minX;
  7295. var minY = this.minY;
  7296. var maxX = this.maxX;
  7297. var maxY = this.maxY;
  7298. this.minX = _minX < minX ? _minX : minX;
  7299. this.minY = _minY < minY ? _minY : minY;
  7300. this.maxX = _maxX > maxX ? _maxX : maxX;
  7301. this.maxY = _maxY > maxY ? _maxY : maxY;
  7302. }
  7303. };
  7304. /**
  7305. * Adds other Bounds, masked with Rectangle
  7306. *
  7307. * @param {PIXI.Bounds} bounds - TODO
  7308. * @param {PIXI.Rectangle} area - TODO
  7309. */
  7310. Bounds.prototype.addBoundsArea = function addBoundsArea(bounds, area) {
  7311. var _minX = bounds.minX > area.x ? bounds.minX : area.x;
  7312. var _minY = bounds.minY > area.y ? bounds.minY : area.y;
  7313. var _maxX = bounds.maxX < area.x + area.width ? bounds.maxX : area.x + area.width;
  7314. var _maxY = bounds.maxY < area.y + area.height ? bounds.maxY : area.y + area.height;
  7315. if (_minX <= _maxX && _minY <= _maxY) {
  7316. var minX = this.minX;
  7317. var minY = this.minY;
  7318. var maxX = this.maxX;
  7319. var maxY = this.maxY;
  7320. this.minX = _minX < minX ? _minX : minX;
  7321. this.minY = _minY < minY ? _minY : minY;
  7322. this.maxX = _maxX > maxX ? _maxX : maxX;
  7323. this.maxY = _maxY > maxY ? _maxY : maxY;
  7324. }
  7325. };
  7326. return Bounds;
  7327. }();
  7328. exports.default = Bounds;
  7329. }, { "../math": 70 }], 48: [function (require, module, exports) {
  7330. 'use strict';
  7331. exports.__esModule = true;
  7332. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  7333. var _utils = require('../utils');
  7334. var _DisplayObject2 = require('./DisplayObject');
  7335. var _DisplayObject3 = _interopRequireDefault(_DisplayObject2);
  7336. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  7337. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  7338. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  7339. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  7340. /**
  7341. * A Container represents a collection of display objects.
  7342. * It is the base class of all display objects that act as a container for other objects.
  7343. *
  7344. *```js
  7345. * let container = new PIXI.Container();
  7346. * container.addChild(sprite);
  7347. * ```
  7348. *
  7349. * @class
  7350. * @extends PIXI.DisplayObject
  7351. * @memberof PIXI
  7352. */
  7353. var Container = function (_DisplayObject) {
  7354. _inherits(Container, _DisplayObject);
  7355. /**
  7356. *
  7357. */
  7358. function Container() {
  7359. _classCallCheck(this, Container);
  7360. /**
  7361. * The array of children of this container.
  7362. *
  7363. * @member {PIXI.DisplayObject[]}
  7364. * @readonly
  7365. */
  7366. var _this = _possibleConstructorReturn(this, _DisplayObject.call(this));
  7367. _this.children = [];
  7368. return _this;
  7369. }
  7370. /**
  7371. * Overridable method that can be used by Container subclasses whenever the children array is modified
  7372. *
  7373. * @private
  7374. */
  7375. Container.prototype.onChildrenChange = function onChildrenChange() { }
  7376. /* empty */
  7377. /**
  7378. * Adds one or more children to the container.
  7379. *
  7380. * Multiple items can be added like so: `myContainer.addChild(thingOne, thingTwo, thingThree)`
  7381. *
  7382. * @param {...PIXI.DisplayObject} child - The DisplayObject(s) to add to the container
  7383. * @return {PIXI.DisplayObject} The first child that was added.
  7384. */
  7385. ;
  7386. Container.prototype.addChild = function addChild(child) {
  7387. var argumentsLength = arguments.length;
  7388. // if there is only one argument we can bypass looping through the them
  7389. if (argumentsLength > 1) {
  7390. // loop through the arguments property and add all children
  7391. // use it the right way (.length and [i]) so that this function can still be optimised by JS runtimes
  7392. for (var i = 0; i < argumentsLength; i++) {
  7393. this.addChild(arguments[i]);
  7394. }
  7395. } else {
  7396. // if the child has a parent then lets remove it as PixiJS objects can only exist in one place
  7397. if (child.parent) {
  7398. child.parent.removeChild(child);
  7399. }
  7400. child.parent = this;
  7401. // ensure child transform will be recalculated
  7402. child.transform._parentID = -1;
  7403. this.children.push(child);
  7404. // ensure bounds will be recalculated
  7405. this._boundsID++;
  7406. // TODO - lets either do all callbacks or all events.. not both!
  7407. this.onChildrenChange(this.children.length - 1);
  7408. child.emit('added', this);
  7409. }
  7410. return child;
  7411. };
  7412. /**
  7413. * Adds a child to the container at a specified index. If the index is out of bounds an error will be thrown
  7414. *
  7415. * @param {PIXI.DisplayObject} child - The child to add
  7416. * @param {number} index - The index to place the child in
  7417. * @return {PIXI.DisplayObject} The child that was added.
  7418. */
  7419. Container.prototype.addChildAt = function addChildAt(child, index) {
  7420. if (index < 0 || index > this.children.length) {
  7421. throw new Error(child + 'addChildAt: The index ' + index + ' supplied is out of bounds ' + this.children.length);
  7422. }
  7423. if (child.parent) {
  7424. child.parent.removeChild(child);
  7425. }
  7426. child.parent = this;
  7427. // ensure child transform will be recalculated
  7428. child.transform._parentID = -1;
  7429. this.children.splice(index, 0, child);
  7430. // ensure bounds will be recalculated
  7431. this._boundsID++;
  7432. // TODO - lets either do all callbacks or all events.. not both!
  7433. this.onChildrenChange(index);
  7434. child.emit('added', this);
  7435. return child;
  7436. };
  7437. /**
  7438. * Swaps the position of 2 Display Objects within this container.
  7439. *
  7440. * @param {PIXI.DisplayObject} child - First display object to swap
  7441. * @param {PIXI.DisplayObject} child2 - Second display object to swap
  7442. */
  7443. Container.prototype.swapChildren = function swapChildren(child, child2) {
  7444. if (child === child2) {
  7445. return;
  7446. }
  7447. var index1 = this.getChildIndex(child);
  7448. var index2 = this.getChildIndex(child2);
  7449. this.children[index1] = child2;
  7450. this.children[index2] = child;
  7451. this.onChildrenChange(index1 < index2 ? index1 : index2);
  7452. };
  7453. /**
  7454. * Returns the index position of a child DisplayObject instance
  7455. *
  7456. * @param {PIXI.DisplayObject} child - The DisplayObject instance to identify
  7457. * @return {number} The index position of the child display object to identify
  7458. */
  7459. Container.prototype.getChildIndex = function getChildIndex(child) {
  7460. var index = this.children.indexOf(child);
  7461. if (index === -1) {
  7462. throw new Error('The supplied DisplayObject must be a child of the caller');
  7463. }
  7464. return index;
  7465. };
  7466. /**
  7467. * Changes the position of an existing child in the display object container
  7468. *
  7469. * @param {PIXI.DisplayObject} child - The child DisplayObject instance for which you want to change the index number
  7470. * @param {number} index - The resulting index number for the child display object
  7471. */
  7472. Container.prototype.setChildIndex = function setChildIndex(child, index) {
  7473. if (index < 0 || index >= this.children.length) {
  7474. throw new Error('The index ' + index + ' supplied is out of bounds ' + this.children.length);
  7475. }
  7476. var currentIndex = this.getChildIndex(child);
  7477. (0, _utils.removeItems)(this.children, currentIndex, 1); // remove from old position
  7478. this.children.splice(index, 0, child); // add at new position
  7479. this.onChildrenChange(index);
  7480. };
  7481. /**
  7482. * Returns the child at the specified index
  7483. *
  7484. * @param {number} index - The index to get the child at
  7485. * @return {PIXI.DisplayObject} The child at the given index, if any.
  7486. */
  7487. Container.prototype.getChildAt = function getChildAt(index) {
  7488. if (index < 0 || index >= this.children.length) {
  7489. throw new Error('getChildAt: Index (' + index + ') does not exist.');
  7490. }
  7491. return this.children[index];
  7492. };
  7493. /**
  7494. * Removes one or more children from the container.
  7495. *
  7496. * @param {...PIXI.DisplayObject} child - The DisplayObject(s) to remove
  7497. * @return {PIXI.DisplayObject} The first child that was removed.
  7498. */
  7499. Container.prototype.removeChild = function removeChild(child) {
  7500. var argumentsLength = arguments.length;
  7501. // if there is only one argument we can bypass looping through the them
  7502. if (argumentsLength > 1) {
  7503. // loop through the arguments property and add all children
  7504. // use it the right way (.length and [i]) so that this function can still be optimised by JS runtimes
  7505. for (var i = 0; i < argumentsLength; i++) {
  7506. this.removeChild(arguments[i]);
  7507. }
  7508. } else {
  7509. var index = this.children.indexOf(child);
  7510. if (index === -1) return null;
  7511. child.parent = null;
  7512. // ensure child transform will be recalculated
  7513. child.transform._parentID = -1;
  7514. (0, _utils.removeItems)(this.children, index, 1);
  7515. // ensure bounds will be recalculated
  7516. this._boundsID++;
  7517. // TODO - lets either do all callbacks or all events.. not both!
  7518. this.onChildrenChange(index);
  7519. child.emit('removed', this);
  7520. }
  7521. return child;
  7522. };
  7523. /**
  7524. * Removes a child from the specified index position.
  7525. *
  7526. * @param {number} index - The index to get the child from
  7527. * @return {PIXI.DisplayObject} The child that was removed.
  7528. */
  7529. Container.prototype.removeChildAt = function removeChildAt(index) {
  7530. var child = this.getChildAt(index);
  7531. // ensure child transform will be recalculated..
  7532. child.parent = null;
  7533. child.transform._parentID = -1;
  7534. (0, _utils.removeItems)(this.children, index, 1);
  7535. // ensure bounds will be recalculated
  7536. this._boundsID++;
  7537. // TODO - lets either do all callbacks or all events.. not both!
  7538. this.onChildrenChange(index);
  7539. child.emit('removed', this);
  7540. return child;
  7541. };
  7542. /**
  7543. * Removes all children from this container that are within the begin and end indexes.
  7544. *
  7545. * @param {number} [beginIndex=0] - The beginning position.
  7546. * @param {number} [endIndex=this.children.length] - The ending position. Default value is size of the container.
  7547. * @returns {DisplayObject[]} List of removed children
  7548. */
  7549. Container.prototype.removeChildren = function removeChildren() {
  7550. var beginIndex = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
  7551. var endIndex = arguments[1];
  7552. var begin = beginIndex;
  7553. var end = typeof endIndex === 'number' ? endIndex : this.children.length;
  7554. var range = end - begin;
  7555. var removed = void 0;
  7556. if (range > 0 && range <= end) {
  7557. removed = this.children.splice(begin, range);
  7558. for (var i = 0; i < removed.length; ++i) {
  7559. removed[i].parent = null;
  7560. if (removed[i].transform) {
  7561. removed[i].transform._parentID = -1;
  7562. }
  7563. }
  7564. this._boundsID++;
  7565. this.onChildrenChange(beginIndex);
  7566. for (var _i = 0; _i < removed.length; ++_i) {
  7567. removed[_i].emit('removed', this);
  7568. }
  7569. return removed;
  7570. } else if (range === 0 && this.children.length === 0) {
  7571. return [];
  7572. }
  7573. throw new RangeError('removeChildren: numeric values are outside the acceptable range.');
  7574. };
  7575. /**
  7576. * Updates the transform on all children of this container for rendering
  7577. */
  7578. Container.prototype.updateTransform = function updateTransform() {
  7579. this._boundsID++;
  7580. this.transform.updateTransform(this.parent.transform);
  7581. // TODO: check render flags, how to process stuff here
  7582. this.worldAlpha = this.alpha * this.parent.worldAlpha;
  7583. for (var i = 0, j = this.children.length; i < j; ++i) {
  7584. var child = this.children[i];
  7585. if (child.visible) {
  7586. child.updateTransform();
  7587. }
  7588. }
  7589. };
  7590. /**
  7591. * Recalculates the bounds of the container.
  7592. *
  7593. */
  7594. Container.prototype.calculateBounds = function calculateBounds() {
  7595. this._bounds.clear();
  7596. this._calculateBounds();
  7597. for (var i = 0; i < this.children.length; i++) {
  7598. var child = this.children[i];
  7599. if (!child.visible || !child.renderable) {
  7600. continue;
  7601. }
  7602. child.calculateBounds();
  7603. // TODO: filter+mask, need to mask both somehow
  7604. if (child._mask) {
  7605. child._mask.calculateBounds();
  7606. this._bounds.addBoundsMask(child._bounds, child._mask._bounds);
  7607. } else if (child.filterArea) {
  7608. this._bounds.addBoundsArea(child._bounds, child.filterArea);
  7609. } else {
  7610. this._bounds.addBounds(child._bounds);
  7611. }
  7612. }
  7613. this._lastBoundsID = this._boundsID;
  7614. };
  7615. /**
  7616. * Recalculates the bounds of the object. Override this to
  7617. * calculate the bounds of the specific object (not including children).
  7618. *
  7619. */
  7620. Container.prototype._calculateBounds = function _calculateBounds() { }
  7621. // FILL IN//
  7622. /**
  7623. * Renders the object using the WebGL renderer
  7624. *
  7625. * @param {PIXI.WebGLRenderer} renderer - The renderer
  7626. */
  7627. ;
  7628. Container.prototype.renderWebGL = function renderWebGL(renderer) {
  7629. // if the object is not visible or the alpha is 0 then no need to render this element
  7630. if (!this.visible || this.worldAlpha <= 0 || !this.renderable) {
  7631. return;
  7632. }
  7633. // do a quick check to see if this element has a mask or a filter.
  7634. if (this._mask || this._filters) {
  7635. this.renderAdvancedWebGL(renderer);
  7636. } else {
  7637. this._renderWebGL(renderer);
  7638. // simple render children!
  7639. for (var i = 0, j = this.children.length; i < j; ++i) {
  7640. this.children[i].renderWebGL(renderer);
  7641. }
  7642. }
  7643. };
  7644. /**
  7645. * Render the object using the WebGL renderer and advanced features.
  7646. *
  7647. * @private
  7648. * @param {PIXI.WebGLRenderer} renderer - The renderer
  7649. */
  7650. Container.prototype.renderAdvancedWebGL = function renderAdvancedWebGL(renderer) {
  7651. renderer.flush();
  7652. var filters = this._filters;
  7653. var mask = this._mask;
  7654. // push filter first as we need to ensure the stencil buffer is correct for any masking
  7655. if (filters) {
  7656. if (!this._enabledFilters) {
  7657. this._enabledFilters = [];
  7658. }
  7659. this._enabledFilters.length = 0;
  7660. for (var i = 0; i < filters.length; i++) {
  7661. if (filters[i].enabled) {
  7662. this._enabledFilters.push(filters[i]);
  7663. }
  7664. }
  7665. if (this._enabledFilters.length) {
  7666. renderer.filterManager.pushFilter(this, this._enabledFilters);
  7667. }
  7668. }
  7669. if (mask) {
  7670. renderer.maskManager.pushMask(this, this._mask);
  7671. }
  7672. // add this object to the batch, only rendered if it has a texture.
  7673. this._renderWebGL(renderer);
  7674. // now loop through the children and make sure they get rendered
  7675. for (var _i2 = 0, j = this.children.length; _i2 < j; _i2++) {
  7676. this.children[_i2].renderWebGL(renderer);
  7677. }
  7678. renderer.flush();
  7679. if (mask) {
  7680. renderer.maskManager.popMask(this, this._mask);
  7681. }
  7682. if (filters && this._enabledFilters && this._enabledFilters.length) {
  7683. renderer.filterManager.popFilter();
  7684. }
  7685. };
  7686. /**
  7687. * To be overridden by the subclasses.
  7688. *
  7689. * @private
  7690. * @param {PIXI.WebGLRenderer} renderer - The renderer
  7691. */
  7692. Container.prototype._renderWebGL = function _renderWebGL(renderer) // eslint-disable-line no-unused-vars
  7693. { }
  7694. // this is where content itself gets rendered...
  7695. /**
  7696. * To be overridden by the subclass
  7697. *
  7698. * @private
  7699. * @param {PIXI.CanvasRenderer} renderer - The renderer
  7700. */
  7701. ;
  7702. Container.prototype._renderCanvas = function _renderCanvas(renderer) // eslint-disable-line no-unused-vars
  7703. { }
  7704. // this is where content itself gets rendered...
  7705. /**
  7706. * Renders the object using the Canvas renderer
  7707. *
  7708. * @param {PIXI.CanvasRenderer} renderer - The renderer
  7709. */
  7710. ;
  7711. Container.prototype.renderCanvas = function renderCanvas(renderer) {
  7712. // if not visible or the alpha is 0 then no need to render this
  7713. if (!this.visible || this.worldAlpha <= 0 || !this.renderable) {
  7714. return;
  7715. }
  7716. if (this._mask) {
  7717. renderer.maskManager.pushMask(this._mask);
  7718. }
  7719. this._renderCanvas(renderer);
  7720. for (var i = 0, j = this.children.length; i < j; ++i) {
  7721. this.children[i].renderCanvas(renderer);
  7722. }
  7723. if (this._mask) {
  7724. renderer.maskManager.popMask(renderer);
  7725. }
  7726. };
  7727. /**
  7728. * Removes all internal references and listeners as well as removes children from the display list.
  7729. * Do not use a Container after calling `destroy`.
  7730. *
  7731. * @param {object|boolean} [options] - Options parameter. A boolean will act as if all options
  7732. * have been set to that value
  7733. * @param {boolean} [options.children=false] - if set to true, all the children will have their destroy
  7734. * method called as well. 'options' will be passed on to those calls.
  7735. * @param {boolean} [options.texture=false] - Only used for child Sprites if options.children is set to true
  7736. * Should it destroy the texture of the child sprite
  7737. * @param {boolean} [options.baseTexture=false] - Only used for child Sprites if options.children is set to true
  7738. * Should it destroy the base texture of the child sprite
  7739. */
  7740. Container.prototype.destroy = function destroy(options) {
  7741. _DisplayObject.prototype.destroy.call(this);
  7742. var destroyChildren = typeof options === 'boolean' ? options : options && options.children;
  7743. var oldChildren = this.removeChildren(0, this.children.length);
  7744. if (destroyChildren) {
  7745. for (var i = 0; i < oldChildren.length; ++i) {
  7746. oldChildren[i].destroy(options);
  7747. }
  7748. }
  7749. };
  7750. /**
  7751. * The width of the Container, setting this will actually modify the scale to achieve the value set
  7752. *
  7753. * @member {number}
  7754. */
  7755. _createClass(Container, [{
  7756. key: 'width',
  7757. get: function get() {
  7758. return this.scale.x * this.getLocalBounds().width;
  7759. },
  7760. set: function set(value) // eslint-disable-line require-jsdoc
  7761. {
  7762. var width = this.getLocalBounds().width;
  7763. if (width !== 0) {
  7764. this.scale.x = value / width;
  7765. } else {
  7766. this.scale.x = 1;
  7767. }
  7768. this._width = value;
  7769. }
  7770. /**
  7771. * The height of the Container, setting this will actually modify the scale to achieve the value set
  7772. *
  7773. * @member {number}
  7774. */
  7775. }, {
  7776. key: 'height',
  7777. get: function get() {
  7778. return this.scale.y * this.getLocalBounds().height;
  7779. },
  7780. set: function set(value) // eslint-disable-line require-jsdoc
  7781. {
  7782. var height = this.getLocalBounds().height;
  7783. if (height !== 0) {
  7784. this.scale.y = value / height;
  7785. } else {
  7786. this.scale.y = 1;
  7787. }
  7788. this._height = value;
  7789. }
  7790. }]);
  7791. return Container;
  7792. }(_DisplayObject3.default);
  7793. // performance increase to avoid using call.. (10x faster)
  7794. exports.default = Container;
  7795. Container.prototype.containerUpdateTransform = Container.prototype.updateTransform;
  7796. }, { "../utils": 125, "./DisplayObject": 49 }], 49: [function (require, module, exports) {
  7797. 'use strict';
  7798. exports.__esModule = true;
  7799. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  7800. var _eventemitter = require('eventemitter3');
  7801. var _eventemitter2 = _interopRequireDefault(_eventemitter);
  7802. var _const = require('../const');
  7803. var _settings = require('../settings');
  7804. var _settings2 = _interopRequireDefault(_settings);
  7805. var _TransformStatic = require('./TransformStatic');
  7806. var _TransformStatic2 = _interopRequireDefault(_TransformStatic);
  7807. var _Transform = require('./Transform');
  7808. var _Transform2 = _interopRequireDefault(_Transform);
  7809. var _Bounds = require('./Bounds');
  7810. var _Bounds2 = _interopRequireDefault(_Bounds);
  7811. var _math = require('../math');
  7812. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  7813. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  7814. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  7815. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  7816. // _tempDisplayObjectParent = new DisplayObject();
  7817. /**
  7818. * The base class for all objects that are rendered on the screen.
  7819. * This is an abstract class and should not be used on its own rather it should be extended.
  7820. *
  7821. * @class
  7822. * @extends EventEmitter
  7823. * @memberof PIXI
  7824. */
  7825. var DisplayObject = function (_EventEmitter) {
  7826. _inherits(DisplayObject, _EventEmitter);
  7827. /**
  7828. *
  7829. */
  7830. function DisplayObject() {
  7831. _classCallCheck(this, DisplayObject);
  7832. var _this = _possibleConstructorReturn(this, _EventEmitter.call(this));
  7833. var TransformClass = _settings2.default.TRANSFORM_MODE === _const.TRANSFORM_MODE.STATIC ? _TransformStatic2.default : _Transform2.default;
  7834. _this.tempDisplayObjectParent = null;
  7835. // TODO: need to create Transform from factory
  7836. /**
  7837. * World transform and local transform of this object.
  7838. * This will become read-only later, please do not assign anything there unless you know what are you doing
  7839. *
  7840. * @member {PIXI.TransformBase}
  7841. */
  7842. _this.transform = new TransformClass();
  7843. /**
  7844. * The opacity of the object.
  7845. *
  7846. * @member {number}
  7847. */
  7848. _this.alpha = 1;
  7849. /**
  7850. * The visibility of the object. If false the object will not be drawn, and
  7851. * the updateTransform function will not be called.
  7852. *
  7853. * Only affects recursive calls from parent. You can ask for bounds or call updateTransform manually
  7854. *
  7855. * @member {boolean}
  7856. */
  7857. _this.visible = true;
  7858. /**
  7859. * Can this object be rendered, if false the object will not be drawn but the updateTransform
  7860. * methods will still be called.
  7861. *
  7862. * Only affects recursive calls from parent. You can ask for bounds manually
  7863. *
  7864. * @member {boolean}
  7865. */
  7866. _this.renderable = true;
  7867. /**
  7868. * The display object container that contains this display object.
  7869. *
  7870. * @member {PIXI.Container}
  7871. * @readonly
  7872. */
  7873. _this.parent = null;
  7874. /**
  7875. * The multiplied alpha of the displayObject
  7876. *
  7877. * @member {number}
  7878. * @readonly
  7879. */
  7880. _this.worldAlpha = 1;
  7881. /**
  7882. * The area the filter is applied to. This is used as more of an optimisation
  7883. * rather than figuring out the dimensions of the displayObject each frame you can set this rectangle
  7884. *
  7885. * Also works as an interaction mask
  7886. *
  7887. * @member {PIXI.Rectangle}
  7888. */
  7889. _this.filterArea = null;
  7890. _this._filters = null;
  7891. _this._enabledFilters = null;
  7892. /**
  7893. * The bounds object, this is used to calculate and store the bounds of the displayObject
  7894. *
  7895. * @member {PIXI.Rectangle}
  7896. * @private
  7897. */
  7898. _this._bounds = new _Bounds2.default();
  7899. _this._boundsID = 0;
  7900. _this._lastBoundsID = -1;
  7901. _this._boundsRect = null;
  7902. _this._localBoundsRect = null;
  7903. /**
  7904. * The original, cached mask of the object
  7905. *
  7906. * @member {PIXI.Graphics|PIXI.Sprite}
  7907. * @private
  7908. */
  7909. _this._mask = null;
  7910. /**
  7911. * If the object has been destroyed via destroy(). If true, it should not be used.
  7912. *
  7913. * @member {boolean}
  7914. * @private
  7915. * @readonly
  7916. */
  7917. _this._destroyed = false;
  7918. /**
  7919. * Fired when this DisplayObject is added to a Container.
  7920. *
  7921. * @event PIXI.DisplayObject#added
  7922. * @param {PIXI.Container} container - The container added to.
  7923. */
  7924. /**
  7925. * Fired when this DisplayObject is removed from a Container.
  7926. *
  7927. * @event PIXI.DisplayObject#removed
  7928. * @param {PIXI.Container} container - The container removed from.
  7929. */
  7930. return _this;
  7931. }
  7932. /**
  7933. * @private
  7934. * @member {PIXI.DisplayObject}
  7935. */
  7936. /**
  7937. * Updates the object transform for rendering
  7938. *
  7939. * TODO - Optimization pass!
  7940. */
  7941. DisplayObject.prototype.updateTransform = function updateTransform() {
  7942. this.transform.updateTransform(this.parent.transform);
  7943. // multiply the alphas..
  7944. this.worldAlpha = this.alpha * this.parent.worldAlpha;
  7945. this._bounds.updateID++;
  7946. };
  7947. /**
  7948. * recursively updates transform of all objects from the root to this one
  7949. * internal function for toLocal()
  7950. */
  7951. DisplayObject.prototype._recursivePostUpdateTransform = function _recursivePostUpdateTransform() {
  7952. if (this.parent) {
  7953. this.parent._recursivePostUpdateTransform();
  7954. this.transform.updateTransform(this.parent.transform);
  7955. } else {
  7956. this.transform.updateTransform(this._tempDisplayObjectParent.transform);
  7957. }
  7958. };
  7959. /**
  7960. * Retrieves the bounds of the displayObject as a rectangle object.
  7961. *
  7962. * @param {boolean} skipUpdate - setting to true will stop the transforms of the scene graph from
  7963. * being updated. This means the calculation returned MAY be out of date BUT will give you a
  7964. * nice performance boost
  7965. * @param {PIXI.Rectangle} rect - Optional rectangle to store the result of the bounds calculation
  7966. * @return {PIXI.Rectangle} the rectangular bounding area
  7967. */
  7968. DisplayObject.prototype.getBounds = function getBounds(skipUpdate, rect) {
  7969. if (!skipUpdate) {
  7970. if (!this.parent) {
  7971. this.parent = this._tempDisplayObjectParent;
  7972. this.updateTransform();
  7973. this.parent = null;
  7974. } else {
  7975. this._recursivePostUpdateTransform();
  7976. this.updateTransform();
  7977. }
  7978. }
  7979. if (this._boundsID !== this._lastBoundsID) {
  7980. this.calculateBounds();
  7981. }
  7982. if (!rect) {
  7983. if (!this._boundsRect) {
  7984. this._boundsRect = new _math.Rectangle();
  7985. }
  7986. rect = this._boundsRect;
  7987. }
  7988. return this._bounds.getRectangle(rect);
  7989. };
  7990. /**
  7991. * Retrieves the local bounds of the displayObject as a rectangle object
  7992. *
  7993. * @param {PIXI.Rectangle} [rect] - Optional rectangle to store the result of the bounds calculation
  7994. * @return {PIXI.Rectangle} the rectangular bounding area
  7995. */
  7996. DisplayObject.prototype.getLocalBounds = function getLocalBounds(rect) {
  7997. var transformRef = this.transform;
  7998. var parentRef = this.parent;
  7999. this.parent = null;
  8000. this.transform = this._tempDisplayObjectParent.transform;
  8001. if (!rect) {
  8002. if (!this._localBoundsRect) {
  8003. this._localBoundsRect = new _math.Rectangle();
  8004. }
  8005. rect = this._localBoundsRect;
  8006. }
  8007. var bounds = this.getBounds(false, rect);
  8008. this.parent = parentRef;
  8009. this.transform = transformRef;
  8010. return bounds;
  8011. };
  8012. /**
  8013. * Calculates the global position of the display object
  8014. *
  8015. * @param {PIXI.Point} position - The world origin to calculate from
  8016. * @param {PIXI.Point} [point] - A Point object in which to store the value, optional
  8017. * (otherwise will create a new Point)
  8018. * @param {boolean} [skipUpdate=false] - Should we skip the update transform.
  8019. * @return {PIXI.Point} A point object representing the position of this object
  8020. */
  8021. DisplayObject.prototype.toGlobal = function toGlobal(position, point) {
  8022. var skipUpdate = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  8023. if (!skipUpdate) {
  8024. this._recursivePostUpdateTransform();
  8025. // this parent check is for just in case the item is a root object.
  8026. // If it is we need to give it a temporary parent so that displayObjectUpdateTransform works correctly
  8027. // this is mainly to avoid a parent check in the main loop. Every little helps for performance :)
  8028. if (!this.parent) {
  8029. this.parent = this._tempDisplayObjectParent;
  8030. this.displayObjectUpdateTransform();
  8031. this.parent = null;
  8032. } else {
  8033. this.displayObjectUpdateTransform();
  8034. }
  8035. }
  8036. // don't need to update the lot
  8037. return this.worldTransform.apply(position, point);
  8038. };
  8039. /**
  8040. * Calculates the local position of the display object relative to another point
  8041. *
  8042. * @param {PIXI.Point} position - The world origin to calculate from
  8043. * @param {PIXI.DisplayObject} [from] - The DisplayObject to calculate the global position from
  8044. * @param {PIXI.Point} [point] - A Point object in which to store the value, optional
  8045. * (otherwise will create a new Point)
  8046. * @param {boolean} [skipUpdate=false] - Should we skip the update transform
  8047. * @return {PIXI.Point} A point object representing the position of this object
  8048. */
  8049. DisplayObject.prototype.toLocal = function toLocal(position, from, point, skipUpdate) {
  8050. if (from) {
  8051. position = from.toGlobal(position, point, skipUpdate);
  8052. }
  8053. if (!skipUpdate) {
  8054. this._recursivePostUpdateTransform();
  8055. // this parent check is for just in case the item is a root object.
  8056. // If it is we need to give it a temporary parent so that displayObjectUpdateTransform works correctly
  8057. // this is mainly to avoid a parent check in the main loop. Every little helps for performance :)
  8058. if (!this.parent) {
  8059. this.parent = this._tempDisplayObjectParent;
  8060. this.displayObjectUpdateTransform();
  8061. this.parent = null;
  8062. } else {
  8063. this.displayObjectUpdateTransform();
  8064. }
  8065. }
  8066. // simply apply the matrix..
  8067. return this.worldTransform.applyInverse(position, point);
  8068. };
  8069. /**
  8070. * Renders the object using the WebGL renderer
  8071. *
  8072. * @param {PIXI.WebGLRenderer} renderer - The renderer
  8073. */
  8074. DisplayObject.prototype.renderWebGL = function renderWebGL(renderer) // eslint-disable-line no-unused-vars
  8075. { }
  8076. // OVERWRITE;
  8077. /**
  8078. * Renders the object using the Canvas renderer
  8079. *
  8080. * @param {PIXI.CanvasRenderer} renderer - The renderer
  8081. */
  8082. ;
  8083. DisplayObject.prototype.renderCanvas = function renderCanvas(renderer) // eslint-disable-line no-unused-vars
  8084. { }
  8085. // OVERWRITE;
  8086. /**
  8087. * Set the parent Container of this DisplayObject
  8088. *
  8089. * @param {PIXI.Container} container - The Container to add this DisplayObject to
  8090. * @return {PIXI.Container} The Container that this DisplayObject was added to
  8091. */
  8092. ;
  8093. DisplayObject.prototype.setParent = function setParent(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 setTransform() {
  8115. var x = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
  8116. var y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
  8117. var scaleX = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
  8118. var scaleY = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 1;
  8119. var rotation = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 0;
  8120. var skewX = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : 0;
  8121. var skewY = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : 0;
  8122. var pivotX = arguments.length > 7 && arguments[7] !== undefined ? arguments[7] : 0;
  8123. var pivotY = arguments.length > 8 && arguments[8] !== undefined ? arguments[8] : 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 destroy() {
  8143. this.removeAllListeners();
  8144. if (this.parent) {
  8145. this.parent.removeChild(this);
  8146. }
  8147. this.transform = null;
  8148. this.parent = null;
  8149. this._bounds = null;
  8150. this._currentBounds = null;
  8151. this._mask = null;
  8152. this.filterArea = null;
  8153. this.interactive = false;
  8154. this.interactiveChildren = false;
  8155. this._destroyed = true;
  8156. };
  8157. /**
  8158. * The position of the displayObject on the x axis relative to the local coordinates of the parent.
  8159. * An alias to position.x
  8160. *
  8161. * @member {number}
  8162. */
  8163. _createClass(DisplayObject, [{
  8164. key: '_tempDisplayObjectParent',
  8165. get: function get() {
  8166. if (this.tempDisplayObjectParent === null) {
  8167. this.tempDisplayObjectParent = new DisplayObject();
  8168. }
  8169. return this.tempDisplayObjectParent;
  8170. }
  8171. }, {
  8172. key: 'x',
  8173. get: function get() {
  8174. return this.position.x;
  8175. },
  8176. set: function set(value) // eslint-disable-line require-jsdoc
  8177. {
  8178. this.transform.position.x = value;
  8179. }
  8180. /**
  8181. * The position of the displayObject on the y axis relative to the local coordinates of the parent.
  8182. * An alias to position.y
  8183. *
  8184. * @member {number}
  8185. */
  8186. }, {
  8187. key: 'y',
  8188. get: function get() {
  8189. return this.position.y;
  8190. },
  8191. set: function set(value) // eslint-disable-line require-jsdoc
  8192. {
  8193. this.transform.position.y = value;
  8194. }
  8195. /**
  8196. * Current transform of the object based on world (parent) factors
  8197. *
  8198. * @member {PIXI.Matrix}
  8199. * @readonly
  8200. */
  8201. }, {
  8202. key: 'worldTransform',
  8203. get: function get() {
  8204. return this.transform.worldTransform;
  8205. }
  8206. /**
  8207. * Current transform of the object based on local factors: position, scale, other stuff
  8208. *
  8209. * @member {PIXI.Matrix}
  8210. * @readonly
  8211. */
  8212. }, {
  8213. key: 'localTransform',
  8214. get: function get() {
  8215. return this.transform.localTransform;
  8216. }
  8217. /**
  8218. * The coordinate of the object relative to the local coordinates of the parent.
  8219. * Assignment by value since pixi-v4.
  8220. *
  8221. * @member {PIXI.Point|PIXI.ObservablePoint}
  8222. */
  8223. }, {
  8224. key: 'position',
  8225. get: function get() {
  8226. return this.transform.position;
  8227. },
  8228. set: function set(value) // eslint-disable-line require-jsdoc
  8229. {
  8230. this.transform.position.copy(value);
  8231. }
  8232. /**
  8233. * The scale factor of the object.
  8234. * Assignment by value since pixi-v4.
  8235. *
  8236. * @member {PIXI.Point|PIXI.ObservablePoint}
  8237. */
  8238. }, {
  8239. key: 'scale',
  8240. get: function get() {
  8241. return this.transform.scale;
  8242. },
  8243. set: function set(value) // eslint-disable-line require-jsdoc
  8244. {
  8245. this.transform.scale.copy(value);
  8246. }
  8247. /**
  8248. * The pivot point of the displayObject that it rotates around
  8249. * Assignment by value since pixi-v4.
  8250. *
  8251. * @member {PIXI.Point|PIXI.ObservablePoint}
  8252. */
  8253. }, {
  8254. key: 'pivot',
  8255. get: function get() {
  8256. return this.transform.pivot;
  8257. },
  8258. set: function set(value) // eslint-disable-line require-jsdoc
  8259. {
  8260. this.transform.pivot.copy(value);
  8261. }
  8262. /**
  8263. * The skew factor for the object in radians.
  8264. * Assignment by value since pixi-v4.
  8265. *
  8266. * @member {PIXI.ObservablePoint}
  8267. */
  8268. }, {
  8269. key: 'skew',
  8270. get: function get() {
  8271. return this.transform.skew;
  8272. },
  8273. set: function set(value) // eslint-disable-line require-jsdoc
  8274. {
  8275. this.transform.skew.copy(value);
  8276. }
  8277. /**
  8278. * The rotation of the object in radians.
  8279. *
  8280. * @member {number}
  8281. */
  8282. }, {
  8283. key: 'rotation',
  8284. get: function get() {
  8285. return this.transform.rotation;
  8286. },
  8287. set: function set(value) // eslint-disable-line require-jsdoc
  8288. {
  8289. this.transform.rotation = value;
  8290. }
  8291. /**
  8292. * Indicates if the object is globally visible.
  8293. *
  8294. * @member {boolean}
  8295. * @readonly
  8296. */
  8297. }, {
  8298. key: 'worldVisible',
  8299. get: function get() {
  8300. var item = this;
  8301. do {
  8302. if (!item.visible) {
  8303. return false;
  8304. }
  8305. item = item.parent;
  8306. } while (item);
  8307. return true;
  8308. }
  8309. /**
  8310. * Sets a mask for the displayObject. A mask is an object that limits the visibility of an
  8311. * object to the shape of the mask applied to it. In PIXI a regular mask must be a
  8312. * PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it
  8313. * utilises shape clipping. To remove a mask, set this property to null.
  8314. *
  8315. * @todo For the moment, PIXI.CanvasRenderer doesn't support PIXI.Sprite as mask.
  8316. *
  8317. * @member {PIXI.Graphics|PIXI.Sprite}
  8318. */
  8319. }, {
  8320. key: 'mask',
  8321. get: function get() {
  8322. return this._mask;
  8323. },
  8324. set: function set(value) // eslint-disable-line require-jsdoc
  8325. {
  8326. if (this._mask) {
  8327. this._mask.renderable = true;
  8328. this._mask.isMask = false;
  8329. }
  8330. this._mask = value;
  8331. if (this._mask) {
  8332. this._mask.renderable = false;
  8333. this._mask.isMask = true;
  8334. }
  8335. }
  8336. /**
  8337. * Sets the filters for the displayObject.
  8338. * * IMPORTANT: This is a webGL only feature and will be ignored by the canvas renderer.
  8339. * To remove filters simply set this property to 'null'
  8340. *
  8341. * @member {PIXI.Filter[]}
  8342. */
  8343. }, {
  8344. key: 'filters',
  8345. get: function get() {
  8346. return this._filters && this._filters.slice();
  8347. },
  8348. set: function set(value) // eslint-disable-line require-jsdoc
  8349. {
  8350. this._filters = value && value.slice();
  8351. }
  8352. }]);
  8353. return DisplayObject;
  8354. }(_eventemitter2.default);
  8355. // performance increase to avoid using call.. (10x faster)
  8356. exports.default = DisplayObject;
  8357. DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform;
  8358. }, { "../const": 46, "../math": 70, "../settings": 101, "./Bounds": 47, "./Transform": 50, "./TransformStatic": 52, "eventemitter3": 3 }], 50: [function (require, module, exports) {
  8359. 'use strict';
  8360. exports.__esModule = true;
  8361. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  8362. var _math = require('../math');
  8363. var _TransformBase2 = require('./TransformBase');
  8364. var _TransformBase3 = _interopRequireDefault(_TransformBase2);
  8365. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  8366. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  8367. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  8368. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  8369. /**
  8370. * Generic class to deal with traditional 2D matrix transforms
  8371. * local transformation is calculated from position,scale,skew and rotation
  8372. *
  8373. * @class
  8374. * @extends PIXI.TransformBase
  8375. * @memberof PIXI
  8376. */
  8377. var Transform = function (_TransformBase) {
  8378. _inherits(Transform, _TransformBase);
  8379. /**
  8380. *
  8381. */
  8382. function Transform() {
  8383. _classCallCheck(this, Transform);
  8384. /**
  8385. * The coordinate of the object relative to the local coordinates of the parent.
  8386. *
  8387. * @member {PIXI.Point}
  8388. */
  8389. var _this = _possibleConstructorReturn(this, _TransformBase.call(this));
  8390. _this.position = new _math.Point(0, 0);
  8391. /**
  8392. * The scale factor of the object.
  8393. *
  8394. * @member {PIXI.Point}
  8395. */
  8396. _this.scale = new _math.Point(1, 1);
  8397. /**
  8398. * The skew amount, on the x and y axis.
  8399. *
  8400. * @member {PIXI.ObservablePoint}
  8401. */
  8402. _this.skew = new _math.ObservablePoint(_this.updateSkew, _this, 0, 0);
  8403. /**
  8404. * The pivot point of the displayObject that it rotates around
  8405. *
  8406. * @member {PIXI.Point}
  8407. */
  8408. _this.pivot = new _math.Point(0, 0);
  8409. /**
  8410. * The rotation value of the object, in radians
  8411. *
  8412. * @member {Number}
  8413. * @private
  8414. */
  8415. _this._rotation = 0;
  8416. _this._cx = 1; // cos rotation + skewY;
  8417. _this._sx = 0; // sin rotation + skewY;
  8418. _this._cy = 0; // cos rotation + Math.PI/2 - skewX;
  8419. _this._sy = 1; // sin rotation + Math.PI/2 - skewX;
  8420. return _this;
  8421. }
  8422. /**
  8423. * Updates the skew values when the skew or rotation changes.
  8424. *
  8425. * @private
  8426. */
  8427. Transform.prototype.updateSkew = function updateSkew() {
  8428. this._cx = Math.cos(this._rotation + this.skew._y);
  8429. this._sx = Math.sin(this._rotation + this.skew._y);
  8430. this._cy = -Math.sin(this._rotation - this.skew._x); // cos, added PI/2
  8431. this._sy = Math.cos(this._rotation - this.skew._x); // sin, added PI/2
  8432. };
  8433. /**
  8434. * Updates only local matrix
  8435. */
  8436. Transform.prototype.updateLocalTransform = function updateLocalTransform() {
  8437. var lt = this.localTransform;
  8438. lt.a = this._cx * this.scale.x;
  8439. lt.b = this._sx * this.scale.x;
  8440. lt.c = this._cy * this.scale.y;
  8441. lt.d = this._sy * this.scale.y;
  8442. lt.tx = this.position.x - (this.pivot.x * lt.a + this.pivot.y * lt.c);
  8443. lt.ty = this.position.y - (this.pivot.x * lt.b + this.pivot.y * lt.d);
  8444. };
  8445. /**
  8446. * Updates the values of the object and applies the parent's transform.
  8447. *
  8448. * @param {PIXI.Transform} parentTransform - The transform of the parent of this object
  8449. */
  8450. Transform.prototype.updateTransform = function updateTransform(parentTransform) {
  8451. var lt = this.localTransform;
  8452. lt.a = this._cx * this.scale.x;
  8453. lt.b = this._sx * this.scale.x;
  8454. lt.c = this._cy * this.scale.y;
  8455. lt.d = this._sy * this.scale.y;
  8456. lt.tx = this.position.x - (this.pivot.x * lt.a + this.pivot.y * lt.c);
  8457. lt.ty = this.position.y - (this.pivot.x * lt.b + this.pivot.y * lt.d);
  8458. // concat the parent matrix with the objects transform.
  8459. var pt = parentTransform.worldTransform;
  8460. var wt = this.worldTransform;
  8461. wt.a = lt.a * pt.a + lt.b * pt.c;
  8462. wt.b = lt.a * pt.b + lt.b * pt.d;
  8463. wt.c = lt.c * pt.a + lt.d * pt.c;
  8464. wt.d = lt.c * pt.b + lt.d * pt.d;
  8465. wt.tx = lt.tx * pt.a + lt.ty * pt.c + pt.tx;
  8466. wt.ty = lt.tx * pt.b + lt.ty * pt.d + pt.ty;
  8467. this._worldID++;
  8468. };
  8469. /**
  8470. * Decomposes a matrix and sets the transforms properties based on it.
  8471. *
  8472. * @param {PIXI.Matrix} matrix - The matrix to decompose
  8473. */
  8474. Transform.prototype.setFromMatrix = function setFromMatrix(matrix) {
  8475. matrix.decompose(this);
  8476. };
  8477. /**
  8478. * The rotation of the object in radians.
  8479. *
  8480. * @member {number}
  8481. */
  8482. _createClass(Transform, [{
  8483. key: 'rotation',
  8484. get: function get() {
  8485. return this._rotation;
  8486. },
  8487. set: function set(value) // eslint-disable-line require-jsdoc
  8488. {
  8489. this._rotation = value;
  8490. this.updateSkew();
  8491. }
  8492. }]);
  8493. return Transform;
  8494. }(_TransformBase3.default);
  8495. exports.default = Transform;
  8496. }, { "../math": 70, "./TransformBase": 51 }], 51: [function (require, module, exports) {
  8497. 'use strict';
  8498. exports.__esModule = true;
  8499. var _math = require('../math');
  8500. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  8501. /**
  8502. * Generic class to deal with traditional 2D matrix transforms
  8503. *
  8504. * @class
  8505. * @memberof PIXI
  8506. */
  8507. var TransformBase = function () {
  8508. /**
  8509. *
  8510. */
  8511. function TransformBase() {
  8512. _classCallCheck(this, TransformBase);
  8513. /**
  8514. * The global matrix transform. It can be swapped temporarily by some functions like getLocalBounds()
  8515. *
  8516. * @member {PIXI.Matrix}
  8517. */
  8518. this.worldTransform = new _math.Matrix();
  8519. /**
  8520. * The local matrix transform
  8521. *
  8522. * @member {PIXI.Matrix}
  8523. */
  8524. this.localTransform = new _math.Matrix();
  8525. this._worldID = 0;
  8526. this._parentID = 0;
  8527. }
  8528. /**
  8529. * TransformBase does not have decomposition, so this function wont do anything
  8530. */
  8531. TransformBase.prototype.updateLocalTransform = function updateLocalTransform() { }
  8532. // empty
  8533. /**
  8534. * Updates the values of the object and applies the parent's transform.
  8535. *
  8536. * @param {PIXI.TransformBase} parentTransform - The transform of the parent of this object
  8537. */
  8538. ;
  8539. TransformBase.prototype.updateTransform = function updateTransform(parentTransform) {
  8540. var pt = parentTransform.worldTransform;
  8541. var wt = this.worldTransform;
  8542. var lt = this.localTransform;
  8543. // concat the parent matrix with the objects transform.
  8544. wt.a = lt.a * pt.a + lt.b * pt.c;
  8545. wt.b = lt.a * pt.b + lt.b * pt.d;
  8546. wt.c = lt.c * pt.a + lt.d * pt.c;
  8547. wt.d = lt.c * pt.b + lt.d * pt.d;
  8548. wt.tx = lt.tx * pt.a + lt.ty * pt.c + pt.tx;
  8549. wt.ty = lt.tx * pt.b + lt.ty * pt.d + pt.ty;
  8550. this._worldID++;
  8551. };
  8552. return TransformBase;
  8553. }();
  8554. /**
  8555. * Updates the values of the object and applies the parent's transform.
  8556. * @param parentTransform {PIXI.Transform} The transform of the parent of this object
  8557. *
  8558. */
  8559. exports.default = TransformBase;
  8560. TransformBase.prototype.updateWorldTransform = TransformBase.prototype.updateTransform;
  8561. TransformBase.IDENTITY = new TransformBase();
  8562. }, { "../math": 70 }], 52: [function (require, module, exports) {
  8563. 'use strict';
  8564. exports.__esModule = true;
  8565. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  8566. var _math = require('../math');
  8567. var _TransformBase2 = require('./TransformBase');
  8568. var _TransformBase3 = _interopRequireDefault(_TransformBase2);
  8569. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  8570. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  8571. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  8572. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  8573. /**
  8574. * Transform that takes care about its versions
  8575. *
  8576. * @class
  8577. * @extends PIXI.TransformBase
  8578. * @memberof PIXI
  8579. */
  8580. var TransformStatic = function (_TransformBase) {
  8581. _inherits(TransformStatic, _TransformBase);
  8582. /**
  8583. *
  8584. */
  8585. function TransformStatic() {
  8586. _classCallCheck(this, TransformStatic);
  8587. /**
  8588. * The coordinate of the object relative to the local coordinates of the parent.
  8589. *
  8590. * @member {PIXI.ObservablePoint}
  8591. */
  8592. var _this = _possibleConstructorReturn(this, _TransformBase.call(this));
  8593. _this.position = new _math.ObservablePoint(_this.onChange, _this, 0, 0);
  8594. /**
  8595. * The scale factor of the object.
  8596. *
  8597. * @member {PIXI.ObservablePoint}
  8598. */
  8599. _this.scale = new _math.ObservablePoint(_this.onChange, _this, 1, 1);
  8600. /**
  8601. * The pivot point of the displayObject that it rotates around
  8602. *
  8603. * @member {PIXI.ObservablePoint}
  8604. */
  8605. _this.pivot = new _math.ObservablePoint(_this.onChange, _this, 0, 0);
  8606. /**
  8607. * The skew amount, on the x and y axis.
  8608. *
  8609. * @member {PIXI.ObservablePoint}
  8610. */
  8611. _this.skew = new _math.ObservablePoint(_this.updateSkew, _this, 0, 0);
  8612. _this._rotation = 0;
  8613. _this._cx = 1; // cos rotation + skewY;
  8614. _this._sx = 0; // sin rotation + skewY;
  8615. _this._cy = 0; // cos rotation + Math.PI/2 - skewX;
  8616. _this._sy = 1; // sin rotation + Math.PI/2 - skewX;
  8617. _this._localID = 0;
  8618. _this._currentLocalID = 0;
  8619. return _this;
  8620. }
  8621. /**
  8622. * Called when a value changes.
  8623. *
  8624. * @private
  8625. */
  8626. TransformStatic.prototype.onChange = function onChange() {
  8627. this._localID++;
  8628. };
  8629. /**
  8630. * Called when skew or rotation changes
  8631. *
  8632. * @private
  8633. */
  8634. TransformStatic.prototype.updateSkew = function updateSkew() {
  8635. this._cx = Math.cos(this._rotation + this.skew._y);
  8636. this._sx = Math.sin(this._rotation + this.skew._y);
  8637. this._cy = -Math.sin(this._rotation - this.skew._x); // cos, added PI/2
  8638. this._sy = Math.cos(this._rotation - this.skew._x); // sin, added PI/2
  8639. this._localID++;
  8640. };
  8641. /**
  8642. * Updates only local matrix
  8643. */
  8644. TransformStatic.prototype.updateLocalTransform = function updateLocalTransform() {
  8645. var lt = this.localTransform;
  8646. if (this._localID !== this._currentLocalID) {
  8647. // get the matrix values of the displayobject based on its transform properties..
  8648. lt.a = this._cx * this.scale._x;
  8649. lt.b = this._sx * this.scale._x;
  8650. lt.c = this._cy * this.scale._y;
  8651. lt.d = this._sy * this.scale._y;
  8652. lt.tx = this.position._x - (this.pivot._x * lt.a + this.pivot._y * lt.c);
  8653. lt.ty = this.position._y - (this.pivot._x * lt.b + this.pivot._y * lt.d);
  8654. this._currentLocalID = this._localID;
  8655. // force an update..
  8656. this._parentID = -1;
  8657. }
  8658. };
  8659. /**
  8660. * Updates the values of the object and applies the parent's transform.
  8661. *
  8662. * @param {PIXI.Transform} parentTransform - The transform of the parent of this object
  8663. */
  8664. TransformStatic.prototype.updateTransform = function updateTransform(parentTransform) {
  8665. var lt = this.localTransform;
  8666. if (this._localID !== this._currentLocalID) {
  8667. // get the matrix values of the displayobject based on its transform properties..
  8668. lt.a = this._cx * this.scale._x;
  8669. lt.b = this._sx * this.scale._x;
  8670. lt.c = this._cy * this.scale._y;
  8671. lt.d = this._sy * this.scale._y;
  8672. lt.tx = this.position._x - (this.pivot._x * lt.a + this.pivot._y * lt.c);
  8673. lt.ty = this.position._y - (this.pivot._x * lt.b + this.pivot._y * lt.d);
  8674. this._currentLocalID = this._localID;
  8675. // force an update..
  8676. this._parentID = -1;
  8677. }
  8678. if (this._parentID !== parentTransform._worldID) {
  8679. // concat the parent matrix with the objects transform.
  8680. var pt = parentTransform.worldTransform;
  8681. var wt = this.worldTransform;
  8682. wt.a = lt.a * pt.a + lt.b * pt.c;
  8683. wt.b = lt.a * pt.b + lt.b * pt.d;
  8684. wt.c = lt.c * pt.a + lt.d * pt.c;
  8685. wt.d = lt.c * pt.b + lt.d * pt.d;
  8686. wt.tx = lt.tx * pt.a + lt.ty * pt.c + pt.tx;
  8687. wt.ty = lt.tx * pt.b + lt.ty * pt.d + pt.ty;
  8688. this._parentID = parentTransform._worldID;
  8689. // update the id of the transform..
  8690. this._worldID++;
  8691. }
  8692. };
  8693. /**
  8694. * Decomposes a matrix and sets the transforms properties based on it.
  8695. *
  8696. * @param {PIXI.Matrix} matrix - The matrix to decompose
  8697. */
  8698. TransformStatic.prototype.setFromMatrix = function setFromMatrix(matrix) {
  8699. matrix.decompose(this);
  8700. this._localID++;
  8701. };
  8702. /**
  8703. * The rotation of the object in radians.
  8704. *
  8705. * @member {number}
  8706. */
  8707. _createClass(TransformStatic, [{
  8708. key: 'rotation',
  8709. get: function get() {
  8710. return this._rotation;
  8711. },
  8712. set: function set(value) // eslint-disable-line require-jsdoc
  8713. {
  8714. this._rotation = value;
  8715. this.updateSkew();
  8716. }
  8717. }]);
  8718. return TransformStatic;
  8719. }(_TransformBase3.default);
  8720. exports.default = TransformStatic;
  8721. }, { "../math": 70, "./TransformBase": 51 }], 53: [function (require, module, exports) {
  8722. 'use strict';
  8723. exports.__esModule = true;
  8724. var _Container2 = require('../display/Container');
  8725. var _Container3 = _interopRequireDefault(_Container2);
  8726. var _RenderTexture = require('../textures/RenderTexture');
  8727. var _RenderTexture2 = _interopRequireDefault(_RenderTexture);
  8728. var _Texture = require('../textures/Texture');
  8729. var _Texture2 = _interopRequireDefault(_Texture);
  8730. var _GraphicsData = require('./GraphicsData');
  8731. var _GraphicsData2 = _interopRequireDefault(_GraphicsData);
  8732. var _Sprite = require('../sprites/Sprite');
  8733. var _Sprite2 = _interopRequireDefault(_Sprite);
  8734. var _math = require('../math');
  8735. var _utils = require('../utils');
  8736. var _const = require('../const');
  8737. var _Bounds = require('../display/Bounds');
  8738. var _Bounds2 = _interopRequireDefault(_Bounds);
  8739. var _bezierCurveTo2 = require('./utils/bezierCurveTo');
  8740. var _bezierCurveTo3 = _interopRequireDefault(_bezierCurveTo2);
  8741. var _CanvasRenderer = require('../renderers/canvas/CanvasRenderer');
  8742. var _CanvasRenderer2 = _interopRequireDefault(_CanvasRenderer);
  8743. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  8744. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  8745. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  8746. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  8747. var canvasRenderer = void 0;
  8748. var tempMatrix = new _math.Matrix();
  8749. var tempPoint = new _math.Point();
  8750. var tempColor1 = new Float32Array(4);
  8751. var tempColor2 = new Float32Array(4);
  8752. /**
  8753. * The Graphics class contains methods used to draw primitive shapes such as lines, circles and
  8754. * rectangles to the display, and to color and fill them.
  8755. *
  8756. * @class
  8757. * @extends PIXI.Container
  8758. * @memberof PIXI
  8759. */
  8760. var Graphics = function (_Container) {
  8761. _inherits(Graphics, _Container);
  8762. /**
  8763. *
  8764. * @param {boolean} [nativeLines=false] - If true the lines will be draw using LINES instead of TRIANGLE_STRIP
  8765. */
  8766. function Graphics() {
  8767. var nativeLines = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  8768. _classCallCheck(this, Graphics);
  8769. /**
  8770. * The alpha value used when filling the Graphics object.
  8771. *
  8772. * @member {number}
  8773. * @default 1
  8774. */
  8775. var _this = _possibleConstructorReturn(this, _Container.call(this));
  8776. _this.fillAlpha = 1;
  8777. /**
  8778. * The width (thickness) of any lines drawn.
  8779. *
  8780. * @member {number}
  8781. * @default 0
  8782. */
  8783. _this.lineWidth = 0;
  8784. /**
  8785. * If true the lines will be draw using LINES instead of TRIANGLE_STRIP
  8786. *
  8787. * @member {boolean}
  8788. */
  8789. _this.nativeLines = nativeLines;
  8790. /**
  8791. * The color of any lines drawn.
  8792. *
  8793. * @member {string}
  8794. * @default 0
  8795. */
  8796. _this.lineColor = 0;
  8797. /**
  8798. * Graphics data
  8799. *
  8800. * @member {PIXI.GraphicsData[]}
  8801. * @private
  8802. */
  8803. _this.graphicsData = [];
  8804. /**
  8805. * The tint applied to the graphic shape. This is a hex value. Apply a value of 0xFFFFFF to
  8806. * reset the tint.
  8807. *
  8808. * @member {number}
  8809. * @default 0xFFFFFF
  8810. */
  8811. _this.tint = 0xFFFFFF;
  8812. /**
  8813. * The previous tint applied to the graphic shape. Used to compare to the current tint and
  8814. * check if theres change.
  8815. *
  8816. * @member {number}
  8817. * @private
  8818. * @default 0xFFFFFF
  8819. */
  8820. _this._prevTint = 0xFFFFFF;
  8821. /**
  8822. * The blend mode to be applied to the graphic shape. Apply a value of
  8823. * `PIXI.BLEND_MODES.NORMAL` to reset the blend mode.
  8824. *
  8825. * @member {number}
  8826. * @default PIXI.BLEND_MODES.NORMAL;
  8827. * @see PIXI.BLEND_MODES
  8828. */
  8829. _this.blendMode = _const.BLEND_MODES.NORMAL;
  8830. /**
  8831. * Current path
  8832. *
  8833. * @member {PIXI.GraphicsData}
  8834. * @private
  8835. */
  8836. _this.currentPath = null;
  8837. /**
  8838. * Array containing some WebGL-related properties used by the WebGL renderer.
  8839. *
  8840. * @member {object<number, object>}
  8841. * @private
  8842. */
  8843. // TODO - _webgl should use a prototype object, not a random undocumented object...
  8844. _this._webGL = {};
  8845. /**
  8846. * Whether this shape is being used as a mask.
  8847. *
  8848. * @member {boolean}
  8849. */
  8850. _this.isMask = false;
  8851. /**
  8852. * The bounds' padding used for bounds calculation.
  8853. *
  8854. * @member {number}
  8855. */
  8856. _this.boundsPadding = 0;
  8857. /**
  8858. * A cache of the local bounds to prevent recalculation.
  8859. *
  8860. * @member {PIXI.Rectangle}
  8861. * @private
  8862. */
  8863. _this._localBounds = new _Bounds2.default();
  8864. /**
  8865. * Used to detect if the graphics object has changed. If this is set to true then the graphics
  8866. * object will be recalculated.
  8867. *
  8868. * @member {boolean}
  8869. * @private
  8870. */
  8871. _this.dirty = 0;
  8872. /**
  8873. * Used to detect if we need to do a fast rect check using the id compare method
  8874. * @type {Number}
  8875. */
  8876. _this.fastRectDirty = -1;
  8877. /**
  8878. * Used to detect if we clear the graphics webGL data
  8879. * @type {Number}
  8880. */
  8881. _this.clearDirty = 0;
  8882. /**
  8883. * Used to detect if we we need to recalculate local bounds
  8884. * @type {Number}
  8885. */
  8886. _this.boundsDirty = -1;
  8887. /**
  8888. * Used to detect if the cached sprite object needs to be updated.
  8889. *
  8890. * @member {boolean}
  8891. * @private
  8892. */
  8893. _this.cachedSpriteDirty = false;
  8894. _this._spriteRect = null;
  8895. _this._fastRect = false;
  8896. /**
  8897. * When cacheAsBitmap is set to true the graphics object will be rendered as if it was a sprite.
  8898. * This is useful if your graphics element does not change often, as it will speed up the rendering
  8899. * of the object in exchange for taking up texture memory. It is also useful if you need the graphics
  8900. * object to be anti-aliased, because it will be rendered using canvas. This is not recommended if
  8901. * you are constantly redrawing the graphics element.
  8902. *
  8903. * @name cacheAsBitmap
  8904. * @member {boolean}
  8905. * @memberof PIXI.Graphics#
  8906. * @default false
  8907. */
  8908. return _this;
  8909. }
  8910. /**
  8911. * Creates a new Graphics object with the same values as this one.
  8912. * Note that the only the properties of the object are cloned, not its transform (position,scale,etc)
  8913. *
  8914. * @return {PIXI.Graphics} A clone of the graphics object
  8915. */
  8916. Graphics.prototype.clone = function clone() {
  8917. var clone = new Graphics();
  8918. clone.renderable = this.renderable;
  8919. clone.fillAlpha = this.fillAlpha;
  8920. clone.lineWidth = this.lineWidth;
  8921. clone.lineColor = this.lineColor;
  8922. clone.tint = this.tint;
  8923. clone.blendMode = this.blendMode;
  8924. clone.isMask = this.isMask;
  8925. clone.boundsPadding = this.boundsPadding;
  8926. clone.dirty = 0;
  8927. clone.cachedSpriteDirty = this.cachedSpriteDirty;
  8928. // copy graphics data
  8929. for (var i = 0; i < this.graphicsData.length; ++i) {
  8930. clone.graphicsData.push(this.graphicsData[i].clone());
  8931. }
  8932. clone.currentPath = clone.graphicsData[clone.graphicsData.length - 1];
  8933. clone.updateLocalBounds();
  8934. return clone;
  8935. };
  8936. /**
  8937. * Specifies the line style used for subsequent calls to Graphics methods such as the lineTo()
  8938. * method or the drawCircle() method.
  8939. *
  8940. * @param {number} [lineWidth=0] - width of the line to draw, will update the objects stored style
  8941. * @param {number} [color=0] - color of the line to draw, will update the objects stored style
  8942. * @param {number} [alpha=1] - alpha of the line to draw, will update the objects stored style
  8943. * @return {PIXI.Graphics} This Graphics object. Good for chaining method calls
  8944. */
  8945. Graphics.prototype.lineStyle = function lineStyle() {
  8946. var lineWidth = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
  8947. var color = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
  8948. var alpha = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
  8949. this.lineWidth = lineWidth;
  8950. this.lineColor = color;
  8951. this.lineAlpha = alpha;
  8952. if (this.currentPath) {
  8953. if (this.currentPath.shape.points.length) {
  8954. // halfway through a line? start a new one!
  8955. var shape = new _math.Polygon(this.currentPath.shape.points.slice(-2));
  8956. shape.closed = false;
  8957. this.drawShape(shape);
  8958. } else {
  8959. // otherwise its empty so lets just set the line properties
  8960. this.currentPath.lineWidth = this.lineWidth;
  8961. this.currentPath.lineColor = this.lineColor;
  8962. this.currentPath.lineAlpha = this.lineAlpha;
  8963. }
  8964. }
  8965. return this;
  8966. };
  8967. /**
  8968. * Moves the current drawing position to x, y.
  8969. *
  8970. * @param {number} x - the X coordinate to move to
  8971. * @param {number} y - the Y coordinate to move to
  8972. * @return {PIXI.Graphics} This Graphics object. Good for chaining method calls
  8973. */
  8974. Graphics.prototype.moveTo = function moveTo(x, y) {
  8975. var shape = new _math.Polygon([x, y]);
  8976. shape.closed = false;
  8977. this.drawShape(shape);
  8978. return this;
  8979. };
  8980. /**
  8981. * Draws a line using the current line style from the current drawing position to (x, y);
  8982. * The current drawing position is then set to (x, y).
  8983. *
  8984. * @param {number} x - the X coordinate to draw to
  8985. * @param {number} y - the Y coordinate to draw to
  8986. * @return {PIXI.Graphics} This Graphics object. Good for chaining method calls
  8987. */
  8988. Graphics.prototype.lineTo = function lineTo(x, y) {
  8989. this.currentPath.shape.points.push(x, y);
  8990. this.dirty++;
  8991. return this;
  8992. };
  8993. /**
  8994. * Calculate the points for a quadratic bezier curve and then draws it.
  8995. * Based on: https://stackoverflow.com/questions/785097/how-do-i-implement-a-bezier-curve-in-c
  8996. *
  8997. * @param {number} cpX - Control point x
  8998. * @param {number} cpY - Control point y
  8999. * @param {number} toX - Destination point x
  9000. * @param {number} toY - Destination point y
  9001. * @return {PIXI.Graphics} This Graphics object. Good for chaining method calls
  9002. */
  9003. Graphics.prototype.quadraticCurveTo = function quadraticCurveTo(cpX, cpY, toX, toY) {
  9004. if (this.currentPath) {
  9005. if (this.currentPath.shape.points.length === 0) {
  9006. this.currentPath.shape.points = [0, 0];
  9007. }
  9008. } else {
  9009. this.moveTo(0, 0);
  9010. }
  9011. var n = 20;
  9012. var points = this.currentPath.shape.points;
  9013. var xa = 0;
  9014. var ya = 0;
  9015. if (points.length === 0) {
  9016. this.moveTo(0, 0);
  9017. }
  9018. var fromX = points[points.length - 2];
  9019. var fromY = points[points.length - 1];
  9020. for (var i = 1; i <= n; ++i) {
  9021. var j = i / n;
  9022. xa = fromX + (cpX - fromX) * j;
  9023. ya = fromY + (cpY - fromY) * j;
  9024. points.push(xa + (cpX + (toX - cpX) * j - xa) * j, ya + (cpY + (toY - cpY) * j - ya) * j);
  9025. }
  9026. this.dirty++;
  9027. return this;
  9028. };
  9029. /**
  9030. * Calculate the points for a bezier curve and then draws it.
  9031. *
  9032. * @param {number} cpX - Control point x
  9033. * @param {number} cpY - Control point y
  9034. * @param {number} cpX2 - Second Control point x
  9035. * @param {number} cpY2 - Second Control point y
  9036. * @param {number} toX - Destination point x
  9037. * @param {number} toY - Destination point y
  9038. * @return {PIXI.Graphics} This Graphics object. Good for chaining method calls
  9039. */
  9040. Graphics.prototype.bezierCurveTo = function bezierCurveTo(cpX, cpY, cpX2, cpY2, toX, toY) {
  9041. if (this.currentPath) {
  9042. if (this.currentPath.shape.points.length === 0) {
  9043. this.currentPath.shape.points = [0, 0];
  9044. }
  9045. } else {
  9046. this.moveTo(0, 0);
  9047. }
  9048. var points = this.currentPath.shape.points;
  9049. var fromX = points[points.length - 2];
  9050. var fromY = points[points.length - 1];
  9051. points.length -= 2;
  9052. (0, _bezierCurveTo3.default)(fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, points);
  9053. this.dirty++;
  9054. return this;
  9055. };
  9056. /**
  9057. * The arcTo() method creates an arc/curve between two tangents on the canvas.
  9058. *
  9059. * "borrowed" from https://code.google.com/p/fxcanvas/ - thanks google!
  9060. *
  9061. * @param {number} x1 - The x-coordinate of the beginning of the arc
  9062. * @param {number} y1 - The y-coordinate of the beginning of the arc
  9063. * @param {number} x2 - The x-coordinate of the end of the arc
  9064. * @param {number} y2 - The y-coordinate of the end of the arc
  9065. * @param {number} radius - The radius of the arc
  9066. * @return {PIXI.Graphics} This Graphics object. Good for chaining method calls
  9067. */
  9068. Graphics.prototype.arcTo = function arcTo(x1, y1, x2, y2, radius) {
  9069. if (this.currentPath) {
  9070. if (this.currentPath.shape.points.length === 0) {
  9071. this.currentPath.shape.points.push(x1, y1);
  9072. }
  9073. } else {
  9074. this.moveTo(x1, y1);
  9075. }
  9076. var points = this.currentPath.shape.points;
  9077. var fromX = points[points.length - 2];
  9078. var fromY = points[points.length - 1];
  9079. var a1 = fromY - y1;
  9080. var b1 = fromX - x1;
  9081. var a2 = y2 - y1;
  9082. var b2 = x2 - x1;
  9083. var mm = Math.abs(a1 * b2 - b1 * a2);
  9084. if (mm < 1.0e-8 || radius === 0) {
  9085. if (points[points.length - 2] !== x1 || points[points.length - 1] !== y1) {
  9086. points.push(x1, y1);
  9087. }
  9088. } else {
  9089. var dd = a1 * a1 + b1 * b1;
  9090. var cc = a2 * a2 + b2 * b2;
  9091. var tt = a1 * a2 + b1 * b2;
  9092. var k1 = radius * Math.sqrt(dd) / mm;
  9093. var k2 = radius * Math.sqrt(cc) / mm;
  9094. var j1 = k1 * tt / dd;
  9095. var j2 = k2 * tt / cc;
  9096. var cx = k1 * b2 + k2 * b1;
  9097. var cy = k1 * a2 + k2 * a1;
  9098. var px = b1 * (k2 + j1);
  9099. var py = a1 * (k2 + j1);
  9100. var qx = b2 * (k1 + j2);
  9101. var qy = a2 * (k1 + j2);
  9102. var startAngle = Math.atan2(py - cy, px - cx);
  9103. var endAngle = Math.atan2(qy - cy, qx - cx);
  9104. this.arc(cx + x1, cy + y1, radius, startAngle, endAngle, b1 * a2 > b2 * a1);
  9105. }
  9106. this.dirty++;
  9107. return this;
  9108. };
  9109. /**
  9110. * The arc method creates an arc/curve (used to create circles, or parts of circles).
  9111. *
  9112. * @param {number} cx - The x-coordinate of the center of the circle
  9113. * @param {number} cy - The y-coordinate of the center of the circle
  9114. * @param {number} radius - The radius of the circle
  9115. * @param {number} startAngle - The starting angle, in radians (0 is at the 3 o'clock position
  9116. * of the arc's circle)
  9117. * @param {number} endAngle - The ending angle, in radians
  9118. * @param {boolean} [anticlockwise=false] - Specifies whether the drawing should be
  9119. * counter-clockwise or clockwise. False is default, and indicates clockwise, while true
  9120. * indicates counter-clockwise.
  9121. * @return {PIXI.Graphics} This Graphics object. Good for chaining method calls
  9122. */
  9123. Graphics.prototype.arc = function arc(cx, cy, radius, startAngle, endAngle) {
  9124. var anticlockwise = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : false;
  9125. if (startAngle === endAngle) {
  9126. return this;
  9127. }
  9128. if (!anticlockwise && endAngle <= startAngle) {
  9129. endAngle += _const.PI_2;
  9130. } else if (anticlockwise && startAngle <= endAngle) {
  9131. startAngle += _const.PI_2;
  9132. }
  9133. var sweep = endAngle - startAngle;
  9134. var segs = Math.ceil(Math.abs(sweep) / _const.PI_2) * 40;
  9135. if (sweep === 0) {
  9136. return this;
  9137. }
  9138. var startX = cx + Math.cos(startAngle) * radius;
  9139. var startY = cy + Math.sin(startAngle) * radius;
  9140. // If the currentPath exists, take its points. Otherwise call `moveTo` to start a path.
  9141. var points = this.currentPath ? this.currentPath.shape.points : null;
  9142. if (points) {
  9143. if (points[points.length - 2] !== startX || points[points.length - 1] !== startY) {
  9144. points.push(startX, startY);
  9145. }
  9146. } else {
  9147. this.moveTo(startX, startY);
  9148. points = this.currentPath.shape.points;
  9149. }
  9150. var theta = sweep / (segs * 2);
  9151. var theta2 = theta * 2;
  9152. var cTheta = Math.cos(theta);
  9153. var sTheta = Math.sin(theta);
  9154. var segMinus = segs - 1;
  9155. var remainder = segMinus % 1 / segMinus;
  9156. for (var i = 0; i <= segMinus; ++i) {
  9157. var real = i + remainder * i;
  9158. var angle = theta + startAngle + theta2 * real;
  9159. var c = Math.cos(angle);
  9160. var s = -Math.sin(angle);
  9161. points.push((cTheta * c + sTheta * s) * radius + cx, (cTheta * -s + sTheta * c) * radius + cy);
  9162. }
  9163. this.dirty++;
  9164. return this;
  9165. };
  9166. /**
  9167. * Specifies a simple one-color fill that subsequent calls to other Graphics methods
  9168. * (such as lineTo() or drawCircle()) use when drawing.
  9169. *
  9170. * @param {number} [color=0] - the color of the fill
  9171. * @param {number} [alpha=1] - the alpha of the fill
  9172. * @return {PIXI.Graphics} This Graphics object. Good for chaining method calls
  9173. */
  9174. Graphics.prototype.beginFill = function beginFill() {
  9175. var color = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
  9176. var alpha = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
  9177. this.filling = true;
  9178. this.fillColor = color;
  9179. this.fillAlpha = alpha;
  9180. if (this.currentPath) {
  9181. if (this.currentPath.shape.points.length <= 2) {
  9182. this.currentPath.fill = this.filling;
  9183. this.currentPath.fillColor = this.fillColor;
  9184. this.currentPath.fillAlpha = this.fillAlpha;
  9185. }
  9186. }
  9187. return this;
  9188. };
  9189. /**
  9190. * Applies a fill to the lines and shapes that were added since the last call to the beginFill() method.
  9191. *
  9192. * @return {PIXI.Graphics} This Graphics object. Good for chaining method calls
  9193. */
  9194. Graphics.prototype.endFill = function endFill() {
  9195. this.filling = false;
  9196. this.fillColor = null;
  9197. this.fillAlpha = 1;
  9198. return this;
  9199. };
  9200. /**
  9201. *
  9202. * @param {number} x - The X coord of the top-left of the rectangle
  9203. * @param {number} y - The Y coord of the top-left of the rectangle
  9204. * @param {number} width - The width of the rectangle
  9205. * @param {number} height - The height of the rectangle
  9206. * @return {PIXI.Graphics} This Graphics object. Good for chaining method calls
  9207. */
  9208. Graphics.prototype.drawRect = function drawRect(x, y, width, height) {
  9209. this.drawShape(new _math.Rectangle(x, y, width, height));
  9210. return this;
  9211. };
  9212. /**
  9213. *
  9214. * @param {number} x - The X coord of the top-left of the rectangle
  9215. * @param {number} y - The Y coord of the top-left of the rectangle
  9216. * @param {number} width - The width of the rectangle
  9217. * @param {number} height - The height of the rectangle
  9218. * @param {number} radius - Radius of the rectangle corners
  9219. * @return {PIXI.Graphics} This Graphics object. Good for chaining method calls
  9220. */
  9221. Graphics.prototype.drawRoundedRect = function drawRoundedRect(x, y, width, height, radius) {
  9222. this.drawShape(new _math.RoundedRectangle(x, y, width, height, radius));
  9223. return this;
  9224. };
  9225. /**
  9226. * Draws a circle.
  9227. *
  9228. * @param {number} x - The X coordinate of the center of the circle
  9229. * @param {number} y - The Y coordinate of the center of the circle
  9230. * @param {number} radius - The radius of the circle
  9231. * @return {PIXI.Graphics} This Graphics object. Good for chaining method calls
  9232. */
  9233. Graphics.prototype.drawCircle = function drawCircle(x, y, radius) {
  9234. this.drawShape(new _math.Circle(x, y, radius));
  9235. return this;
  9236. };
  9237. /**
  9238. * Draws an ellipse.
  9239. *
  9240. * @param {number} x - The X coordinate of the center of the ellipse
  9241. * @param {number} y - The Y coordinate of the center of the ellipse
  9242. * @param {number} width - The half width of the ellipse
  9243. * @param {number} height - The half height of the ellipse
  9244. * @return {PIXI.Graphics} This Graphics object. Good for chaining method calls
  9245. */
  9246. Graphics.prototype.drawEllipse = function drawEllipse(x, y, width, height) {
  9247. this.drawShape(new _math.Ellipse(x, y, width, height));
  9248. return this;
  9249. };
  9250. /**
  9251. * Draws a polygon using the given path.
  9252. *
  9253. * @param {number[]|PIXI.Point[]|PIXI.Polygon} path - The path data used to construct the polygon.
  9254. * @return {PIXI.Graphics} This Graphics object. Good for chaining method calls
  9255. */
  9256. Graphics.prototype.drawPolygon = function drawPolygon(path) {
  9257. // prevents an argument assignment deopt
  9258. // see section 3.1: https://github.com/petkaantonov/bluebird/wiki/Optimization-killers#3-managing-arguments
  9259. var points = path;
  9260. var closed = true;
  9261. if (points instanceof _math.Polygon) {
  9262. closed = points.closed;
  9263. points = points.points;
  9264. }
  9265. if (!Array.isArray(points)) {
  9266. // prevents an argument leak deopt
  9267. // see section 3.2: https://github.com/petkaantonov/bluebird/wiki/Optimization-killers#3-managing-arguments
  9268. points = new Array(arguments.length);
  9269. for (var i = 0; i < points.length; ++i) {
  9270. points[i] = arguments[i]; // eslint-disable-line prefer-rest-params
  9271. }
  9272. }
  9273. var shape = new _math.Polygon(points);
  9274. shape.closed = closed;
  9275. this.drawShape(shape);
  9276. return this;
  9277. };
  9278. /**
  9279. * Draw a star shape with an abitrary number of points.
  9280. *
  9281. * @param {number} x - Center X position of the star
  9282. * @param {number} y - Center Y position of the star
  9283. * @param {number} points - The number of points of the star, must be > 1
  9284. * @param {number} radius - The outer radius of the star
  9285. * @param {number} [innerRadius] - The inner radius between points, default half `radius`
  9286. * @param {number} [rotation=0] - The rotation of the star in radians, where 0 is vertical
  9287. * @return {PIXI.Graphics} This Graphics object. Good for chaining method calls
  9288. */
  9289. Graphics.prototype.drawStar = function drawStar(x, y, points, radius, innerRadius) {
  9290. var rotation = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : 0;
  9291. innerRadius = innerRadius || radius / 2;
  9292. var startAngle = -1 * Math.PI / 2 + rotation;
  9293. var len = points * 2;
  9294. var delta = _const.PI_2 / len;
  9295. var polygon = [];
  9296. for (var i = 0; i < len; i++) {
  9297. var r = i % 2 ? innerRadius : radius;
  9298. var angle = i * delta + startAngle;
  9299. polygon.push(x + r * Math.cos(angle), y + r * Math.sin(angle));
  9300. }
  9301. return this.drawPolygon(polygon);
  9302. };
  9303. /**
  9304. * Clears the graphics that were drawn to this Graphics object, and resets fill and line style settings.
  9305. *
  9306. * @return {PIXI.Graphics} This Graphics object. Good for chaining method calls
  9307. */
  9308. Graphics.prototype.clear = function clear() {
  9309. if (this.lineWidth || this.filling || this.graphicsData.length > 0) {
  9310. this.lineWidth = 0;
  9311. this.filling = false;
  9312. this.boundsDirty = -1;
  9313. this.dirty++;
  9314. this.clearDirty++;
  9315. this.graphicsData.length = 0;
  9316. }
  9317. this.currentPath = null;
  9318. this._spriteRect = null;
  9319. return this;
  9320. };
  9321. /**
  9322. * True if graphics consists of one rectangle, and thus, can be drawn like a Sprite and
  9323. * masked with gl.scissor.
  9324. *
  9325. * @returns {boolean} True if only 1 rect.
  9326. */
  9327. Graphics.prototype.isFastRect = function isFastRect() {
  9328. return this.graphicsData.length === 1 && this.graphicsData[0].shape.type === _const.SHAPES.RECT && !this.graphicsData[0].lineWidth;
  9329. };
  9330. /**
  9331. * Renders the object using the WebGL renderer
  9332. *
  9333. * @private
  9334. * @param {PIXI.WebGLRenderer} renderer - The renderer
  9335. */
  9336. Graphics.prototype._renderWebGL = function _renderWebGL(renderer) {
  9337. // if the sprite is not visible or the alpha is 0 then no need to render this element
  9338. if (this.dirty !== this.fastRectDirty) {
  9339. this.fastRectDirty = this.dirty;
  9340. this._fastRect = this.isFastRect();
  9341. }
  9342. // TODO this check can be moved to dirty?
  9343. if (this._fastRect) {
  9344. this._renderSpriteRect(renderer);
  9345. } else {
  9346. renderer.setObjectRenderer(renderer.plugins.graphics);
  9347. renderer.plugins.graphics.render(this);
  9348. }
  9349. };
  9350. /**
  9351. * Renders a sprite rectangle.
  9352. *
  9353. * @private
  9354. * @param {PIXI.WebGLRenderer} renderer - The renderer
  9355. */
  9356. Graphics.prototype._renderSpriteRect = function _renderSpriteRect(renderer) {
  9357. var rect = this.graphicsData[0].shape;
  9358. if (!this._spriteRect) {
  9359. this._spriteRect = new _Sprite2.default(new _Texture2.default(_Texture2.default.WHITE));
  9360. }
  9361. var sprite = this._spriteRect;
  9362. if (this.tint === 0xffffff) {
  9363. sprite.tint = this.graphicsData[0].fillColor;
  9364. } else {
  9365. var t1 = tempColor1;
  9366. var t2 = tempColor2;
  9367. (0, _utils.hex2rgb)(this.graphicsData[0].fillColor, t1);
  9368. (0, _utils.hex2rgb)(this.tint, t2);
  9369. t1[0] *= t2[0];
  9370. t1[1] *= t2[1];
  9371. t1[2] *= t2[2];
  9372. sprite.tint = (0, _utils.rgb2hex)(t1);
  9373. }
  9374. sprite.alpha = this.graphicsData[0].fillAlpha;
  9375. sprite.worldAlpha = this.worldAlpha * sprite.alpha;
  9376. sprite.blendMode = this.blendMode;
  9377. sprite._texture._frame.width = rect.width;
  9378. sprite._texture._frame.height = rect.height;
  9379. sprite.transform.worldTransform = this.transform.worldTransform;
  9380. sprite.anchor.set(-rect.x / rect.width, -rect.y / rect.height);
  9381. sprite._onAnchorUpdate();
  9382. sprite._renderWebGL(renderer);
  9383. };
  9384. /**
  9385. * Renders the object using the Canvas renderer
  9386. *
  9387. * @private
  9388. * @param {PIXI.CanvasRenderer} renderer - The renderer
  9389. */
  9390. Graphics.prototype._renderCanvas = function _renderCanvas(renderer) {
  9391. if (this.isMask === true) {
  9392. return;
  9393. }
  9394. renderer.plugins.graphics.render(this);
  9395. };
  9396. /**
  9397. * Retrieves the bounds of the graphic shape as a rectangle object
  9398. *
  9399. * @private
  9400. */
  9401. Graphics.prototype._calculateBounds = function _calculateBounds() {
  9402. if (this.boundsDirty !== this.dirty) {
  9403. this.boundsDirty = this.dirty;
  9404. this.updateLocalBounds();
  9405. this.cachedSpriteDirty = true;
  9406. }
  9407. var lb = this._localBounds;
  9408. this._bounds.addFrame(this.transform, lb.minX, lb.minY, lb.maxX, lb.maxY);
  9409. };
  9410. /**
  9411. * Tests if a point is inside this graphics object
  9412. *
  9413. * @param {PIXI.Point} point - the point to test
  9414. * @return {boolean} the result of the test
  9415. */
  9416. Graphics.prototype.containsPoint = function containsPoint(point) {
  9417. this.worldTransform.applyInverse(point, tempPoint);
  9418. var graphicsData = this.graphicsData;
  9419. for (var i = 0; i < graphicsData.length; ++i) {
  9420. var data = graphicsData[i];
  9421. if (!data.fill) {
  9422. continue;
  9423. }
  9424. // only deal with fills..
  9425. if (data.shape) {
  9426. if (data.shape.contains(tempPoint.x, tempPoint.y)) {
  9427. if (data.holes) {
  9428. for (var _i = 0; _i < data.holes.length; _i++) {
  9429. var hole = data.holes[_i];
  9430. if (hole.contains(tempPoint.x, tempPoint.y)) {
  9431. return false;
  9432. }
  9433. }
  9434. }
  9435. return true;
  9436. }
  9437. }
  9438. }
  9439. return false;
  9440. };
  9441. /**
  9442. * Update the bounds of the object
  9443. *
  9444. */
  9445. Graphics.prototype.updateLocalBounds = function updateLocalBounds() {
  9446. var minX = Infinity;
  9447. var maxX = -Infinity;
  9448. var minY = Infinity;
  9449. var maxY = -Infinity;
  9450. if (this.graphicsData.length) {
  9451. var shape = 0;
  9452. var x = 0;
  9453. var y = 0;
  9454. var w = 0;
  9455. var h = 0;
  9456. for (var i = 0; i < this.graphicsData.length; i++) {
  9457. var data = this.graphicsData[i];
  9458. var type = data.type;
  9459. var lineWidth = data.lineWidth;
  9460. shape = data.shape;
  9461. if (type === _const.SHAPES.RECT || type === _const.SHAPES.RREC) {
  9462. x = shape.x - lineWidth / 2;
  9463. y = shape.y - lineWidth / 2;
  9464. w = shape.width + lineWidth;
  9465. h = shape.height + lineWidth;
  9466. minX = x < minX ? x : minX;
  9467. maxX = x + w > maxX ? x + w : maxX;
  9468. minY = y < minY ? y : minY;
  9469. maxY = y + h > maxY ? y + h : maxY;
  9470. } else if (type === _const.SHAPES.CIRC) {
  9471. x = shape.x;
  9472. y = shape.y;
  9473. w = shape.radius + lineWidth / 2;
  9474. h = shape.radius + lineWidth / 2;
  9475. minX = x - w < minX ? x - w : minX;
  9476. maxX = x + w > maxX ? x + w : maxX;
  9477. minY = y - h < minY ? y - h : minY;
  9478. maxY = y + h > maxY ? y + h : maxY;
  9479. } else if (type === _const.SHAPES.ELIP) {
  9480. x = shape.x;
  9481. y = shape.y;
  9482. w = shape.width + lineWidth / 2;
  9483. h = shape.height + lineWidth / 2;
  9484. minX = x - w < minX ? x - w : minX;
  9485. maxX = x + w > maxX ? x + w : maxX;
  9486. minY = y - h < minY ? y - h : minY;
  9487. maxY = y + h > maxY ? y + h : maxY;
  9488. } else {
  9489. // POLY
  9490. var points = shape.points;
  9491. var x2 = 0;
  9492. var y2 = 0;
  9493. var dx = 0;
  9494. var dy = 0;
  9495. var rw = 0;
  9496. var rh = 0;
  9497. var cx = 0;
  9498. var cy = 0;
  9499. for (var j = 0; j + 2 < points.length; j += 2) {
  9500. x = points[j];
  9501. y = points[j + 1];
  9502. x2 = points[j + 2];
  9503. y2 = points[j + 3];
  9504. dx = Math.abs(x2 - x);
  9505. dy = Math.abs(y2 - y);
  9506. h = lineWidth;
  9507. w = Math.sqrt(dx * dx + dy * dy);
  9508. if (w < 1e-9) {
  9509. continue;
  9510. }
  9511. rw = (h / w * dy + dx) / 2;
  9512. rh = (h / w * dx + dy) / 2;
  9513. cx = (x2 + x) / 2;
  9514. cy = (y2 + y) / 2;
  9515. minX = cx - rw < minX ? cx - rw : minX;
  9516. maxX = cx + rw > maxX ? cx + rw : maxX;
  9517. minY = cy - rh < minY ? cy - rh : minY;
  9518. maxY = cy + rh > maxY ? cy + rh : maxY;
  9519. }
  9520. }
  9521. }
  9522. } else {
  9523. minX = 0;
  9524. maxX = 0;
  9525. minY = 0;
  9526. maxY = 0;
  9527. }
  9528. var padding = this.boundsPadding;
  9529. this._localBounds.minX = minX - padding;
  9530. this._localBounds.maxX = maxX + padding;
  9531. this._localBounds.minY = minY - padding;
  9532. this._localBounds.maxY = maxY + padding;
  9533. };
  9534. /**
  9535. * Draws the given shape to this Graphics object. Can be any of Circle, Rectangle, Ellipse, Line or Polygon.
  9536. *
  9537. * @param {PIXI.Circle|PIXI.Ellipse|PIXI.Polygon|PIXI.Rectangle|PIXI.RoundedRectangle} shape - The shape object to draw.
  9538. * @return {PIXI.GraphicsData} The generated GraphicsData object.
  9539. */
  9540. Graphics.prototype.drawShape = function drawShape(shape) {
  9541. if (this.currentPath) {
  9542. // check current path!
  9543. if (this.currentPath.shape.points.length <= 2) {
  9544. this.graphicsData.pop();
  9545. }
  9546. }
  9547. this.currentPath = null;
  9548. var data = new _GraphicsData2.default(this.lineWidth, this.lineColor, this.lineAlpha, this.fillColor, this.fillAlpha, this.filling, this.nativeLines, shape);
  9549. this.graphicsData.push(data);
  9550. if (data.type === _const.SHAPES.POLY) {
  9551. data.shape.closed = data.shape.closed || this.filling;
  9552. this.currentPath = data;
  9553. }
  9554. this.dirty++;
  9555. return data;
  9556. };
  9557. /**
  9558. * Generates a canvas texture.
  9559. *
  9560. * @param {number} scaleMode - The scale mode of the texture.
  9561. * @param {number} resolution - The resolution of the texture.
  9562. * @return {PIXI.Texture} The new texture.
  9563. */
  9564. Graphics.prototype.generateCanvasTexture = function generateCanvasTexture(scaleMode) {
  9565. var resolution = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
  9566. var bounds = this.getLocalBounds();
  9567. var canvasBuffer = _RenderTexture2.default.create(bounds.width, bounds.height, scaleMode, resolution);
  9568. if (!canvasRenderer) {
  9569. canvasRenderer = new _CanvasRenderer2.default();
  9570. }
  9571. this.transform.updateLocalTransform();
  9572. this.transform.localTransform.copy(tempMatrix);
  9573. tempMatrix.invert();
  9574. tempMatrix.tx -= bounds.x;
  9575. tempMatrix.ty -= bounds.y;
  9576. canvasRenderer.render(this, canvasBuffer, true, tempMatrix);
  9577. var texture = _Texture2.default.fromCanvas(canvasBuffer.baseTexture._canvasRenderTarget.canvas, scaleMode, 'graphics');
  9578. texture.baseTexture.resolution = resolution;
  9579. texture.baseTexture.update();
  9580. return texture;
  9581. };
  9582. /**
  9583. * Closes the current path.
  9584. *
  9585. * @return {PIXI.Graphics} Returns itself.
  9586. */
  9587. Graphics.prototype.closePath = function closePath() {
  9588. // ok so close path assumes next one is a hole!
  9589. var currentPath = this.currentPath;
  9590. if (currentPath && currentPath.shape) {
  9591. currentPath.shape.close();
  9592. }
  9593. return this;
  9594. };
  9595. /**
  9596. * Adds a hole in the current path.
  9597. *
  9598. * @return {PIXI.Graphics} Returns itself.
  9599. */
  9600. Graphics.prototype.addHole = function addHole() {
  9601. // this is a hole!
  9602. var hole = this.graphicsData.pop();
  9603. this.currentPath = this.graphicsData[this.graphicsData.length - 1];
  9604. this.currentPath.addHole(hole.shape);
  9605. this.currentPath = null;
  9606. return this;
  9607. };
  9608. /**
  9609. * Destroys the Graphics object.
  9610. *
  9611. * @param {object|boolean} [options] - Options parameter. A boolean will act as if all
  9612. * options have been set to that value
  9613. * @param {boolean} [options.children=false] - if set to true, all the children will have
  9614. * their destroy method called as well. 'options' will be passed on to those calls.
  9615. * @param {boolean} [options.texture=false] - Only used for child Sprites if options.children is set to true
  9616. * Should it destroy the texture of the child sprite
  9617. * @param {boolean} [options.baseTexture=false] - Only used for child Sprites if options.children is set to true
  9618. * Should it destroy the base texture of the child sprite
  9619. */
  9620. Graphics.prototype.destroy = function destroy(options) {
  9621. _Container.prototype.destroy.call(this, options);
  9622. // destroy each of the GraphicsData objects
  9623. for (var i = 0; i < this.graphicsData.length; ++i) {
  9624. this.graphicsData[i].destroy();
  9625. }
  9626. // for each webgl data entry, destroy the WebGLGraphicsData
  9627. for (var id in this._webgl) {
  9628. for (var j = 0; j < this._webgl[id].data.length; ++j) {
  9629. this._webgl[id].data[j].destroy();
  9630. }
  9631. }
  9632. if (this._spriteRect) {
  9633. this._spriteRect.destroy();
  9634. }
  9635. this.graphicsData = null;
  9636. this.currentPath = null;
  9637. this._webgl = null;
  9638. this._localBounds = null;
  9639. };
  9640. return Graphics;
  9641. }(_Container3.default);
  9642. exports.default = Graphics;
  9643. Graphics._SPRITE_TEXTURE = null;
  9644. }, { "../const": 46, "../display/Bounds": 47, "../display/Container": 48, "../math": 70, "../renderers/canvas/CanvasRenderer": 77, "../sprites/Sprite": 102, "../textures/RenderTexture": 113, "../textures/Texture": 115, "../utils": 125, "./GraphicsData": 54, "./utils/bezierCurveTo": 56 }], 54: [function (require, module, exports) {
  9645. "use strict";
  9646. exports.__esModule = true;
  9647. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  9648. /**
  9649. * A GraphicsData object.
  9650. *
  9651. * @class
  9652. * @memberof PIXI
  9653. */
  9654. var GraphicsData = function () {
  9655. /**
  9656. *
  9657. * @param {number} lineWidth - the width of the line to draw
  9658. * @param {number} lineColor - the color of the line to draw
  9659. * @param {number} lineAlpha - the alpha of the line to draw
  9660. * @param {number} fillColor - the color of the fill
  9661. * @param {number} fillAlpha - the alpha of the fill
  9662. * @param {boolean} fill - whether or not the shape is filled with a colour
  9663. * @param {boolean} nativeLines - the method for drawing lines
  9664. * @param {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} shape - The shape object to draw.
  9665. */
  9666. function GraphicsData(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, nativeLines, shape) {
  9667. _classCallCheck(this, GraphicsData);
  9668. /**
  9669. * the width of the line to draw
  9670. * @member {number}
  9671. */
  9672. this.lineWidth = lineWidth;
  9673. /**
  9674. * if true the liens will be draw using LINES instead of TRIANGLE_STRIP
  9675. * @member {boolean}
  9676. */
  9677. this.nativeLines = nativeLines;
  9678. /**
  9679. * the color of the line to draw
  9680. * @member {number}
  9681. */
  9682. this.lineColor = lineColor;
  9683. /**
  9684. * the alpha of the line to draw
  9685. * @member {number}
  9686. */
  9687. this.lineAlpha = lineAlpha;
  9688. /**
  9689. * cached tint of the line to draw
  9690. * @member {number}
  9691. * @private
  9692. */
  9693. this._lineTint = lineColor;
  9694. /**
  9695. * the color of the fill
  9696. * @member {number}
  9697. */
  9698. this.fillColor = fillColor;
  9699. /**
  9700. * the alpha of the fill
  9701. * @member {number}
  9702. */
  9703. this.fillAlpha = fillAlpha;
  9704. /**
  9705. * cached tint of the fill
  9706. * @member {number}
  9707. * @private
  9708. */
  9709. this._fillTint = fillColor;
  9710. /**
  9711. * whether or not the shape is filled with a colour
  9712. * @member {boolean}
  9713. */
  9714. this.fill = fill;
  9715. this.holes = [];
  9716. /**
  9717. * The shape object to draw.
  9718. * @member {PIXI.Circle|PIXI.Ellipse|PIXI.Polygon|PIXI.Rectangle|PIXI.RoundedRectangle}
  9719. */
  9720. this.shape = shape;
  9721. /**
  9722. * The type of the shape, see the Const.Shapes file for all the existing types,
  9723. * @member {number}
  9724. */
  9725. this.type = shape.type;
  9726. }
  9727. /**
  9728. * Creates a new GraphicsData object with the same values as this one.
  9729. *
  9730. * @return {PIXI.GraphicsData} Cloned GraphicsData object
  9731. */
  9732. GraphicsData.prototype.clone = function clone() {
  9733. return new GraphicsData(this.lineWidth, this.lineColor, this.lineAlpha, this.fillColor, this.fillAlpha, this.fill, this.nativeLines, this.shape);
  9734. };
  9735. /**
  9736. * Adds a hole to the shape.
  9737. *
  9738. * @param {PIXI.Rectangle|PIXI.Circle} shape - The shape of the hole.
  9739. */
  9740. GraphicsData.prototype.addHole = function addHole(shape) {
  9741. this.holes.push(shape);
  9742. };
  9743. /**
  9744. * Destroys the Graphics data.
  9745. */
  9746. GraphicsData.prototype.destroy = function destroy() {
  9747. this.shape = null;
  9748. this.holes = null;
  9749. };
  9750. return GraphicsData;
  9751. }();
  9752. exports.default = GraphicsData;
  9753. }, {}], 55: [function (require, module, exports) {
  9754. 'use strict';
  9755. exports.__esModule = true;
  9756. var _CanvasRenderer = require('../../renderers/canvas/CanvasRenderer');
  9757. var _CanvasRenderer2 = _interopRequireDefault(_CanvasRenderer);
  9758. var _const = require('../../const');
  9759. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  9760. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  9761. /**
  9762. * @author Mat Groves
  9763. *
  9764. * Big thanks to the very clever Matt DesLauriers <mattdesl> https://github.com/mattdesl/
  9765. * for creating the original PixiJS version!
  9766. * Also a thanks to https://github.com/bchevalier for tweaking the tint and alpha so that they
  9767. * now share 4 bytes on the vertex buffer
  9768. *
  9769. * Heavily inspired by LibGDX's CanvasGraphicsRenderer:
  9770. * https://github.com/libgdx/libgdx/blob/1.0.0/gdx/src/com/badlogic/gdx/graphics/glutils/ShapeRenderer.java
  9771. */
  9772. /**
  9773. * Renderer dedicated to drawing and batching graphics objects.
  9774. *
  9775. * @class
  9776. * @private
  9777. * @memberof PIXI
  9778. */
  9779. var CanvasGraphicsRenderer = function () {
  9780. /**
  9781. * @param {PIXI.CanvasRenderer} renderer - The current PIXI renderer.
  9782. */
  9783. function CanvasGraphicsRenderer(renderer) {
  9784. _classCallCheck(this, CanvasGraphicsRenderer);
  9785. this.renderer = renderer;
  9786. }
  9787. /**
  9788. * Renders a Graphics object to a canvas.
  9789. *
  9790. * @param {PIXI.Graphics} graphics - the actual graphics object to render
  9791. */
  9792. CanvasGraphicsRenderer.prototype.render = function render(graphics) {
  9793. var renderer = this.renderer;
  9794. var context = renderer.context;
  9795. var worldAlpha = graphics.worldAlpha;
  9796. var transform = graphics.transform.worldTransform;
  9797. var resolution = renderer.resolution;
  9798. // if the tint has changed, set the graphics object to dirty.
  9799. if (this._prevTint !== this.tint) {
  9800. this.dirty = true;
  9801. }
  9802. context.setTransform(transform.a * resolution, transform.b * resolution, transform.c * resolution, transform.d * resolution, transform.tx * resolution, transform.ty * resolution);
  9803. if (graphics.dirty) {
  9804. this.updateGraphicsTint(graphics);
  9805. graphics.dirty = false;
  9806. }
  9807. renderer.setBlendMode(graphics.blendMode);
  9808. for (var i = 0; i < graphics.graphicsData.length; i++) {
  9809. var data = graphics.graphicsData[i];
  9810. var shape = data.shape;
  9811. var fillColor = data._fillTint;
  9812. var lineColor = data._lineTint;
  9813. context.lineWidth = data.lineWidth;
  9814. if (data.type === _const.SHAPES.POLY) {
  9815. context.beginPath();
  9816. this.renderPolygon(shape.points, shape.closed, context);
  9817. for (var j = 0; j < data.holes.length; j++) {
  9818. this.renderPolygon(data.holes[j].points, true, context);
  9819. }
  9820. if (data.fill) {
  9821. context.globalAlpha = data.fillAlpha * worldAlpha;
  9822. context.fillStyle = '#' + ('00000' + (fillColor | 0).toString(16)).substr(-6);
  9823. context.fill();
  9824. }
  9825. if (data.lineWidth) {
  9826. context.globalAlpha = data.lineAlpha * worldAlpha;
  9827. context.strokeStyle = '#' + ('00000' + (lineColor | 0).toString(16)).substr(-6);
  9828. context.stroke();
  9829. }
  9830. } else if (data.type === _const.SHAPES.RECT) {
  9831. if (data.fillColor || data.fillColor === 0) {
  9832. context.globalAlpha = data.fillAlpha * worldAlpha;
  9833. context.fillStyle = '#' + ('00000' + (fillColor | 0).toString(16)).substr(-6);
  9834. context.fillRect(shape.x, shape.y, shape.width, shape.height);
  9835. }
  9836. if (data.lineWidth) {
  9837. context.globalAlpha = data.lineAlpha * worldAlpha;
  9838. context.strokeStyle = '#' + ('00000' + (lineColor | 0).toString(16)).substr(-6);
  9839. context.strokeRect(shape.x, shape.y, shape.width, shape.height);
  9840. }
  9841. } else if (data.type === _const.SHAPES.CIRC) {
  9842. // TODO - need to be Undefined!
  9843. context.beginPath();
  9844. context.arc(shape.x, shape.y, shape.radius, 0, 2 * Math.PI);
  9845. context.closePath();
  9846. if (data.fill) {
  9847. context.globalAlpha = data.fillAlpha * worldAlpha;
  9848. context.fillStyle = '#' + ('00000' + (fillColor | 0).toString(16)).substr(-6);
  9849. context.fill();
  9850. }
  9851. if (data.lineWidth) {
  9852. context.globalAlpha = data.lineAlpha * worldAlpha;
  9853. context.strokeStyle = '#' + ('00000' + (lineColor | 0).toString(16)).substr(-6);
  9854. context.stroke();
  9855. }
  9856. } else if (data.type === _const.SHAPES.ELIP) {
  9857. // ellipse code taken from: http://stackoverflow.com/questions/2172798/how-to-draw-an-oval-in-html5-canvas
  9858. var w = shape.width * 2;
  9859. var h = shape.height * 2;
  9860. var x = shape.x - w / 2;
  9861. var y = shape.y - h / 2;
  9862. context.beginPath();
  9863. var kappa = 0.5522848;
  9864. var ox = w / 2 * kappa; // control point offset horizontal
  9865. var oy = h / 2 * kappa; // control point offset vertical
  9866. var xe = x + w; // x-end
  9867. var ye = y + h; // y-end
  9868. var xm = x + w / 2; // x-middle
  9869. var ym = y + h / 2; // y-middle
  9870. context.moveTo(x, ym);
  9871. context.bezierCurveTo(x, ym - oy, xm - ox, y, xm, y);
  9872. context.bezierCurveTo(xm + ox, y, xe, ym - oy, xe, ym);
  9873. context.bezierCurveTo(xe, ym + oy, xm + ox, ye, xm, ye);
  9874. context.bezierCurveTo(xm - ox, ye, x, ym + oy, x, ym);
  9875. context.closePath();
  9876. if (data.fill) {
  9877. context.globalAlpha = data.fillAlpha * worldAlpha;
  9878. context.fillStyle = '#' + ('00000' + (fillColor | 0).toString(16)).substr(-6);
  9879. context.fill();
  9880. }
  9881. if (data.lineWidth) {
  9882. context.globalAlpha = data.lineAlpha * worldAlpha;
  9883. context.strokeStyle = '#' + ('00000' + (lineColor | 0).toString(16)).substr(-6);
  9884. context.stroke();
  9885. }
  9886. } else if (data.type === _const.SHAPES.RREC) {
  9887. var rx = shape.x;
  9888. var ry = shape.y;
  9889. var width = shape.width;
  9890. var height = shape.height;
  9891. var radius = shape.radius;
  9892. var maxRadius = Math.min(width, height) / 2 | 0;
  9893. radius = radius > maxRadius ? maxRadius : radius;
  9894. context.beginPath();
  9895. context.moveTo(rx, ry + radius);
  9896. context.lineTo(rx, ry + height - radius);
  9897. context.quadraticCurveTo(rx, ry + height, rx + radius, ry + height);
  9898. context.lineTo(rx + width - radius, ry + height);
  9899. context.quadraticCurveTo(rx + width, ry + height, rx + width, ry + height - radius);
  9900. context.lineTo(rx + width, ry + radius);
  9901. context.quadraticCurveTo(rx + width, ry, rx + width - radius, ry);
  9902. context.lineTo(rx + radius, ry);
  9903. context.quadraticCurveTo(rx, ry, rx, ry + radius);
  9904. context.closePath();
  9905. if (data.fillColor || data.fillColor === 0) {
  9906. context.globalAlpha = data.fillAlpha * worldAlpha;
  9907. context.fillStyle = '#' + ('00000' + (fillColor | 0).toString(16)).substr(-6);
  9908. context.fill();
  9909. }
  9910. if (data.lineWidth) {
  9911. context.globalAlpha = data.lineAlpha * worldAlpha;
  9912. context.strokeStyle = '#' + ('00000' + (lineColor | 0).toString(16)).substr(-6);
  9913. context.stroke();
  9914. }
  9915. }
  9916. }
  9917. };
  9918. /**
  9919. * Updates the tint of a graphics object
  9920. *
  9921. * @private
  9922. * @param {PIXI.Graphics} graphics - the graphics that will have its tint updated
  9923. */
  9924. CanvasGraphicsRenderer.prototype.updateGraphicsTint = function updateGraphicsTint(graphics) {
  9925. graphics._prevTint = graphics.tint;
  9926. var tintR = (graphics.tint >> 16 & 0xFF) / 255;
  9927. var tintG = (graphics.tint >> 8 & 0xFF) / 255;
  9928. var tintB = (graphics.tint & 0xFF) / 255;
  9929. for (var i = 0; i < graphics.graphicsData.length; ++i) {
  9930. var data = graphics.graphicsData[i];
  9931. var fillColor = data.fillColor | 0;
  9932. var lineColor = data.lineColor | 0;
  9933. // super inline cos im an optimization NAZI :)
  9934. data._fillTint = ((fillColor >> 16 & 0xFF) / 255 * tintR * 255 << 16) + ((fillColor >> 8 & 0xFF) / 255 * tintG * 255 << 8) + (fillColor & 0xFF) / 255 * tintB * 255;
  9935. data._lineTint = ((lineColor >> 16 & 0xFF) / 255 * tintR * 255 << 16) + ((lineColor >> 8 & 0xFF) / 255 * tintG * 255 << 8) + (lineColor & 0xFF) / 255 * tintB * 255;
  9936. }
  9937. };
  9938. /**
  9939. * Renders a polygon.
  9940. *
  9941. * @param {PIXI.Point[]} points - The points to render
  9942. * @param {boolean} close - Should the polygon be closed
  9943. * @param {CanvasRenderingContext2D} context - The rendering context to use
  9944. */
  9945. CanvasGraphicsRenderer.prototype.renderPolygon = function renderPolygon(points, close, context) {
  9946. context.moveTo(points[0], points[1]);
  9947. for (var j = 1; j < points.length / 2; ++j) {
  9948. context.lineTo(points[j * 2], points[j * 2 + 1]);
  9949. }
  9950. if (close) {
  9951. context.closePath();
  9952. }
  9953. };
  9954. /**
  9955. * destroy graphics object
  9956. *
  9957. */
  9958. CanvasGraphicsRenderer.prototype.destroy = function destroy() {
  9959. this.renderer = null;
  9960. };
  9961. return CanvasGraphicsRenderer;
  9962. }();
  9963. exports.default = CanvasGraphicsRenderer;
  9964. _CanvasRenderer2.default.registerPlugin('graphics', CanvasGraphicsRenderer);
  9965. }, { "../../const": 46, "../../renderers/canvas/CanvasRenderer": 77 }], 56: [function (require, module, exports) {
  9966. "use strict";
  9967. exports.__esModule = true;
  9968. exports.default = bezierCurveTo;
  9969. /**
  9970. * Calculate the points for a bezier curve and then draws it.
  9971. *
  9972. * Ignored from docs since it is not directly exposed.
  9973. *
  9974. * @ignore
  9975. * @param {number} fromX - Starting point x
  9976. * @param {number} fromY - Starting point y
  9977. * @param {number} cpX - Control point x
  9978. * @param {number} cpY - Control point y
  9979. * @param {number} cpX2 - Second Control point x
  9980. * @param {number} cpY2 - Second Control point y
  9981. * @param {number} toX - Destination point x
  9982. * @param {number} toY - Destination point y
  9983. * @param {number[]} [path=[]] - Path array to push points into
  9984. * @return {number[]} Array of points of the curve
  9985. */
  9986. function bezierCurveTo(fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY) {
  9987. var path = arguments.length > 8 && arguments[8] !== undefined ? arguments[8] : [];
  9988. var n = 20;
  9989. var dt = 0;
  9990. var dt2 = 0;
  9991. var dt3 = 0;
  9992. var t2 = 0;
  9993. var t3 = 0;
  9994. path.push(fromX, fromY);
  9995. for (var i = 1, j = 0; i <= n; ++i) {
  9996. j = i / n;
  9997. dt = 1 - j;
  9998. dt2 = dt * dt;
  9999. dt3 = dt2 * dt;
  10000. t2 = j * j;
  10001. t3 = t2 * j;
  10002. path.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);
  10003. }
  10004. return path;
  10005. }
  10006. }, {}], 57: [function (require, module, exports) {
  10007. 'use strict';
  10008. exports.__esModule = true;
  10009. var _utils = require('../../utils');
  10010. var _const = require('../../const');
  10011. var _ObjectRenderer2 = require('../../renderers/webgl/utils/ObjectRenderer');
  10012. var _ObjectRenderer3 = _interopRequireDefault(_ObjectRenderer2);
  10013. var _WebGLRenderer = require('../../renderers/webgl/WebGLRenderer');
  10014. var _WebGLRenderer2 = _interopRequireDefault(_WebGLRenderer);
  10015. var _WebGLGraphicsData = require('./WebGLGraphicsData');
  10016. var _WebGLGraphicsData2 = _interopRequireDefault(_WebGLGraphicsData);
  10017. var _PrimitiveShader = require('./shaders/PrimitiveShader');
  10018. var _PrimitiveShader2 = _interopRequireDefault(_PrimitiveShader);
  10019. var _buildPoly = require('./utils/buildPoly');
  10020. var _buildPoly2 = _interopRequireDefault(_buildPoly);
  10021. var _buildRectangle = require('./utils/buildRectangle');
  10022. var _buildRectangle2 = _interopRequireDefault(_buildRectangle);
  10023. var _buildRoundedRectangle = require('./utils/buildRoundedRectangle');
  10024. var _buildRoundedRectangle2 = _interopRequireDefault(_buildRoundedRectangle);
  10025. var _buildCircle = require('./utils/buildCircle');
  10026. var _buildCircle2 = _interopRequireDefault(_buildCircle);
  10027. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  10028. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  10029. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  10030. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  10031. /**
  10032. * Renders the graphics object.
  10033. *
  10034. * @class
  10035. * @memberof PIXI
  10036. * @extends PIXI.ObjectRenderer
  10037. */
  10038. var GraphicsRenderer = function (_ObjectRenderer) {
  10039. _inherits(GraphicsRenderer, _ObjectRenderer);
  10040. /**
  10041. * @param {PIXI.WebGLRenderer} renderer - The renderer this object renderer works for.
  10042. */
  10043. function GraphicsRenderer(renderer) {
  10044. _classCallCheck(this, GraphicsRenderer);
  10045. var _this = _possibleConstructorReturn(this, _ObjectRenderer.call(this, renderer));
  10046. _this.graphicsDataPool = [];
  10047. _this.primitiveShader = null;
  10048. _this.gl = renderer.gl;
  10049. // easy access!
  10050. _this.CONTEXT_UID = 0;
  10051. return _this;
  10052. }
  10053. /**
  10054. * Called when there is a WebGL context change
  10055. *
  10056. * @private
  10057. *
  10058. */
  10059. GraphicsRenderer.prototype.onContextChange = function onContextChange() {
  10060. this.gl = this.renderer.gl;
  10061. this.CONTEXT_UID = this.renderer.CONTEXT_UID;
  10062. this.primitiveShader = new _PrimitiveShader2.default(this.gl);
  10063. };
  10064. /**
  10065. * Destroys this renderer.
  10066. *
  10067. */
  10068. GraphicsRenderer.prototype.destroy = function destroy() {
  10069. _ObjectRenderer3.default.prototype.destroy.call(this);
  10070. for (var i = 0; i < this.graphicsDataPool.length; ++i) {
  10071. this.graphicsDataPool[i].destroy();
  10072. }
  10073. this.graphicsDataPool = null;
  10074. };
  10075. /**
  10076. * Renders a graphics object.
  10077. *
  10078. * @param {PIXI.Graphics} graphics - The graphics object to render.
  10079. */
  10080. GraphicsRenderer.prototype.render = function render(graphics) {
  10081. var renderer = this.renderer;
  10082. var gl = renderer.gl;
  10083. var webGLData = void 0;
  10084. var webGL = graphics._webGL[this.CONTEXT_UID];
  10085. if (!webGL || graphics.dirty !== webGL.dirty) {
  10086. this.updateGraphics(graphics);
  10087. webGL = graphics._webGL[this.CONTEXT_UID];
  10088. }
  10089. // This could be speeded up for sure!
  10090. var shader = this.primitiveShader;
  10091. renderer.bindShader(shader);
  10092. renderer.state.setBlendMode(graphics.blendMode);
  10093. for (var i = 0, n = webGL.data.length; i < n; i++) {
  10094. webGLData = webGL.data[i];
  10095. var shaderTemp = webGLData.shader;
  10096. renderer.bindShader(shaderTemp);
  10097. shaderTemp.uniforms.translationMatrix = graphics.transform.worldTransform.toArray(true);
  10098. shaderTemp.uniforms.tint = (0, _utils.hex2rgb)(graphics.tint);
  10099. shaderTemp.uniforms.alpha = graphics.worldAlpha;
  10100. renderer.bindVao(webGLData.vao);
  10101. if (webGLData.nativeLines) {
  10102. gl.drawArrays(gl.LINES, 0, webGLData.points.length / 6);
  10103. } else {
  10104. webGLData.vao.draw(gl.TRIANGLE_STRIP, webGLData.indices.length);
  10105. }
  10106. }
  10107. };
  10108. /**
  10109. * Updates the graphics object
  10110. *
  10111. * @private
  10112. * @param {PIXI.Graphics} graphics - The graphics object to update
  10113. */
  10114. GraphicsRenderer.prototype.updateGraphics = function updateGraphics(graphics) {
  10115. var gl = this.renderer.gl;
  10116. // get the contexts graphics object
  10117. var webGL = graphics._webGL[this.CONTEXT_UID];
  10118. // if the graphics object does not exist in the webGL context time to create it!
  10119. if (!webGL) {
  10120. webGL = graphics._webGL[this.CONTEXT_UID] = { lastIndex: 0, data: [], gl: gl, clearDirty: -1, dirty: -1 };
  10121. }
  10122. // flag the graphics as not dirty as we are about to update it...
  10123. webGL.dirty = graphics.dirty;
  10124. // if the user cleared the graphics object we will need to clear every object
  10125. if (graphics.clearDirty !== webGL.clearDirty) {
  10126. webGL.clearDirty = graphics.clearDirty;
  10127. // loop through and return all the webGLDatas to the object pool so than can be reused later on
  10128. for (var i = 0; i < webGL.data.length; i++) {
  10129. this.graphicsDataPool.push(webGL.data[i]);
  10130. }
  10131. // clear the array and reset the index..
  10132. webGL.data.length = 0;
  10133. webGL.lastIndex = 0;
  10134. }
  10135. var webGLData = void 0;
  10136. var webGLDataNativeLines = void 0;
  10137. // loop through the graphics datas and construct each one..
  10138. // if the object is a complex fill then the new stencil buffer technique will be used
  10139. // other wise graphics objects will be pushed into a batch..
  10140. for (var _i = webGL.lastIndex; _i < graphics.graphicsData.length; _i++) {
  10141. var data = graphics.graphicsData[_i];
  10142. // TODO - this can be simplified
  10143. webGLData = this.getWebGLData(webGL, 0);
  10144. if (data.nativeLines && data.lineWidth) {
  10145. webGLDataNativeLines = this.getWebGLData(webGL, 0, true);
  10146. webGL.lastIndex++;
  10147. }
  10148. if (data.type === _const.SHAPES.POLY) {
  10149. (0, _buildPoly2.default)(data, webGLData, webGLDataNativeLines);
  10150. }
  10151. if (data.type === _const.SHAPES.RECT) {
  10152. (0, _buildRectangle2.default)(data, webGLData, webGLDataNativeLines);
  10153. } else if (data.type === _const.SHAPES.CIRC || data.type === _const.SHAPES.ELIP) {
  10154. (0, _buildCircle2.default)(data, webGLData, webGLDataNativeLines);
  10155. } else if (data.type === _const.SHAPES.RREC) {
  10156. (0, _buildRoundedRectangle2.default)(data, webGLData, webGLDataNativeLines);
  10157. }
  10158. webGL.lastIndex++;
  10159. }
  10160. this.renderer.bindVao(null);
  10161. // upload all the dirty data...
  10162. for (var _i2 = 0; _i2 < webGL.data.length; _i2++) {
  10163. webGLData = webGL.data[_i2];
  10164. if (webGLData.dirty) {
  10165. webGLData.upload();
  10166. }
  10167. }
  10168. };
  10169. /**
  10170. *
  10171. * @private
  10172. * @param {WebGLRenderingContext} gl - the current WebGL drawing context
  10173. * @param {number} type - TODO @Alvin
  10174. * @param {number} nativeLines - indicate whether the webGLData use for nativeLines.
  10175. * @return {*} TODO
  10176. */
  10177. GraphicsRenderer.prototype.getWebGLData = function getWebGLData(gl, type, nativeLines) {
  10178. var webGLData = gl.data[gl.data.length - 1];
  10179. if (!webGLData || webGLData.nativeLines !== nativeLines || webGLData.points.length > 320000) {
  10180. webGLData = this.graphicsDataPool.pop() || new _WebGLGraphicsData2.default(this.renderer.gl, this.primitiveShader, this.renderer.state.attribsState);
  10181. webGLData.nativeLines = nativeLines;
  10182. webGLData.reset(type);
  10183. gl.data.push(webGLData);
  10184. }
  10185. webGLData.dirty = true;
  10186. return webGLData;
  10187. };
  10188. return GraphicsRenderer;
  10189. }(_ObjectRenderer3.default);
  10190. exports.default = GraphicsRenderer;
  10191. _WebGLRenderer2.default.registerPlugin('graphics', GraphicsRenderer);
  10192. }, { "../../const": 46, "../../renderers/webgl/WebGLRenderer": 84, "../../renderers/webgl/utils/ObjectRenderer": 94, "../../utils": 125, "./WebGLGraphicsData": 58, "./shaders/PrimitiveShader": 59, "./utils/buildCircle": 60, "./utils/buildPoly": 62, "./utils/buildRectangle": 63, "./utils/buildRoundedRectangle": 64 }], 58: [function (require, module, exports) {
  10193. 'use strict';
  10194. exports.__esModule = true;
  10195. var _pixiGlCore = require('pixi-gl-core');
  10196. var _pixiGlCore2 = _interopRequireDefault(_pixiGlCore);
  10197. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  10198. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  10199. /**
  10200. * An object containing WebGL specific properties to be used by the WebGL renderer
  10201. *
  10202. * @class
  10203. * @private
  10204. * @memberof PIXI
  10205. */
  10206. var WebGLGraphicsData = function () {
  10207. /**
  10208. * @param {WebGLRenderingContext} gl - The current WebGL drawing context
  10209. * @param {PIXI.Shader} shader - The shader
  10210. * @param {object} attribsState - The state for the VAO
  10211. */
  10212. function WebGLGraphicsData(gl, shader, attribsState) {
  10213. _classCallCheck(this, WebGLGraphicsData);
  10214. /**
  10215. * The current WebGL drawing context
  10216. *
  10217. * @member {WebGLRenderingContext}
  10218. */
  10219. this.gl = gl;
  10220. // TODO does this need to be split before uploading??
  10221. /**
  10222. * An array of color components (r,g,b)
  10223. * @member {number[]}
  10224. */
  10225. this.color = [0, 0, 0]; // color split!
  10226. /**
  10227. * An array of points to draw
  10228. * @member {PIXI.Point[]}
  10229. */
  10230. this.points = [];
  10231. /**
  10232. * The indices of the vertices
  10233. * @member {number[]}
  10234. */
  10235. this.indices = [];
  10236. /**
  10237. * The main buffer
  10238. * @member {WebGLBuffer}
  10239. */
  10240. this.buffer = _pixiGlCore2.default.GLBuffer.createVertexBuffer(gl);
  10241. /**
  10242. * The index buffer
  10243. * @member {WebGLBuffer}
  10244. */
  10245. this.indexBuffer = _pixiGlCore2.default.GLBuffer.createIndexBuffer(gl);
  10246. /**
  10247. * Whether this graphics is dirty or not
  10248. * @member {boolean}
  10249. */
  10250. this.dirty = true;
  10251. /**
  10252. * Whether this graphics is nativeLines or not
  10253. * @member {boolean}
  10254. */
  10255. this.nativeLines = false;
  10256. this.glPoints = null;
  10257. this.glIndices = null;
  10258. /**
  10259. *
  10260. * @member {PIXI.Shader}
  10261. */
  10262. this.shader = shader;
  10263. this.vao = new _pixiGlCore2.default.VertexArrayObject(gl, attribsState).addIndex(this.indexBuffer).addAttribute(this.buffer, shader.attributes.aVertexPosition, gl.FLOAT, false, 4 * 6, 0).addAttribute(this.buffer, shader.attributes.aColor, gl.FLOAT, false, 4 * 6, 2 * 4);
  10264. }
  10265. /**
  10266. * Resets the vertices and the indices
  10267. */
  10268. WebGLGraphicsData.prototype.reset = function reset() {
  10269. this.points.length = 0;
  10270. this.indices.length = 0;
  10271. };
  10272. /**
  10273. * Binds the buffers and uploads the data
  10274. */
  10275. WebGLGraphicsData.prototype.upload = function upload() {
  10276. this.glPoints = new Float32Array(this.points);
  10277. this.buffer.upload(this.glPoints);
  10278. this.glIndices = new Uint16Array(this.indices);
  10279. this.indexBuffer.upload(this.glIndices);
  10280. this.dirty = false;
  10281. };
  10282. /**
  10283. * Empties all the data
  10284. */
  10285. WebGLGraphicsData.prototype.destroy = function destroy() {
  10286. this.color = null;
  10287. this.points = null;
  10288. this.indices = null;
  10289. this.vao.destroy();
  10290. this.buffer.destroy();
  10291. this.indexBuffer.destroy();
  10292. this.gl = null;
  10293. this.buffer = null;
  10294. this.indexBuffer = null;
  10295. this.glPoints = null;
  10296. this.glIndices = null;
  10297. };
  10298. return WebGLGraphicsData;
  10299. }();
  10300. exports.default = WebGLGraphicsData;
  10301. }, { "pixi-gl-core": 15 }], 59: [function (require, module, exports) {
  10302. 'use strict';
  10303. exports.__esModule = true;
  10304. var _Shader2 = require('../../../Shader');
  10305. var _Shader3 = _interopRequireDefault(_Shader2);
  10306. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  10307. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  10308. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  10309. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  10310. /**
  10311. * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}.
  10312. *
  10313. * @class
  10314. * @memberof PIXI
  10315. * @extends PIXI.Shader
  10316. */
  10317. var PrimitiveShader = function (_Shader) {
  10318. _inherits(PrimitiveShader, _Shader);
  10319. /**
  10320. * @param {WebGLRenderingContext} gl - The webgl shader manager this shader works for.
  10321. */
  10322. function PrimitiveShader(gl) {
  10323. _classCallCheck(this, PrimitiveShader);
  10324. return _possibleConstructorReturn(this, _Shader.call(this, gl,
  10325. // vertex shader
  10326. ['attribute vec2 aVertexPosition;', 'attribute vec4 aColor;', 'uniform mat3 translationMatrix;', 'uniform mat3 projectionMatrix;', 'uniform float alpha;', 'uniform vec3 tint;', 'varying vec4 vColor;', 'void main(void){', ' gl_Position = vec4((projectionMatrix * translationMatrix * vec3(aVertexPosition, 1.0)).xy, 0.0, 1.0);', ' vColor = aColor * vec4(tint * alpha, alpha);', '}'].join('\n'),
  10327. // fragment shader
  10328. ['varying vec4 vColor;', 'void main(void){', ' gl_FragColor = vColor;', '}'].join('\n')));
  10329. }
  10330. return PrimitiveShader;
  10331. }(_Shader3.default);
  10332. exports.default = PrimitiveShader;
  10333. }, { "../../../Shader": 44 }], 60: [function (require, module, exports) {
  10334. 'use strict';
  10335. exports.__esModule = true;
  10336. exports.default = buildCircle;
  10337. var _buildLine = require('./buildLine');
  10338. var _buildLine2 = _interopRequireDefault(_buildLine);
  10339. var _const = require('../../../const');
  10340. var _utils = require('../../../utils');
  10341. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  10342. /**
  10343. * Builds a circle to draw
  10344. *
  10345. * Ignored from docs since it is not directly exposed.
  10346. *
  10347. * @ignore
  10348. * @private
  10349. * @param {PIXI.WebGLGraphicsData} graphicsData - The graphics object to draw
  10350. * @param {object} webGLData - an object containing all the webGL-specific information to create this shape
  10351. * @param {object} webGLDataNativeLines - an object containing all the webGL-specific information to create nativeLines
  10352. */
  10353. function buildCircle(graphicsData, webGLData, webGLDataNativeLines) {
  10354. // need to convert points to a nice regular data
  10355. var circleData = graphicsData.shape;
  10356. var x = circleData.x;
  10357. var y = circleData.y;
  10358. var width = void 0;
  10359. var height = void 0;
  10360. // TODO - bit hacky??
  10361. if (graphicsData.type === _const.SHAPES.CIRC) {
  10362. width = circleData.radius;
  10363. height = circleData.radius;
  10364. } else {
  10365. width = circleData.width;
  10366. height = circleData.height;
  10367. }
  10368. if (width === 0 || height === 0) {
  10369. return;
  10370. }
  10371. var totalSegs = Math.floor(30 * Math.sqrt(circleData.radius)) || Math.floor(15 * Math.sqrt(circleData.width + circleData.height));
  10372. var seg = Math.PI * 2 / totalSegs;
  10373. if (graphicsData.fill) {
  10374. var color = (0, _utils.hex2rgb)(graphicsData.fillColor);
  10375. var alpha = graphicsData.fillAlpha;
  10376. var r = color[0] * alpha;
  10377. var g = color[1] * alpha;
  10378. var b = color[2] * alpha;
  10379. var verts = webGLData.points;
  10380. var indices = webGLData.indices;
  10381. var vecPos = verts.length / 6;
  10382. indices.push(vecPos);
  10383. for (var i = 0; i < totalSegs + 1; i++) {
  10384. verts.push(x, y, r, g, b, alpha);
  10385. verts.push(x + Math.sin(seg * i) * width, y + Math.cos(seg * i) * height, r, g, b, alpha);
  10386. indices.push(vecPos++, vecPos++);
  10387. }
  10388. indices.push(vecPos - 1);
  10389. }
  10390. if (graphicsData.lineWidth) {
  10391. var tempPoints = graphicsData.points;
  10392. graphicsData.points = [];
  10393. for (var _i = 0; _i < totalSegs + 1; _i++) {
  10394. graphicsData.points.push(x + Math.sin(seg * _i) * width, y + Math.cos(seg * _i) * height);
  10395. }
  10396. (0, _buildLine2.default)(graphicsData, webGLData, webGLDataNativeLines);
  10397. graphicsData.points = tempPoints;
  10398. }
  10399. }
  10400. }, { "../../../const": 46, "../../../utils": 125, "./buildLine": 61 }], 61: [function (require, module, exports) {
  10401. 'use strict';
  10402. exports.__esModule = true;
  10403. exports.default = function (graphicsData, webGLData, webGLDataNativeLines) {
  10404. if (graphicsData.nativeLines) {
  10405. buildNativeLine(graphicsData, webGLDataNativeLines);
  10406. } else {
  10407. buildLine(graphicsData, webGLData);
  10408. }
  10409. };
  10410. var _math = require('../../../math');
  10411. var _utils = require('../../../utils');
  10412. /**
  10413. * Builds a line to draw using the poligon method.
  10414. *
  10415. * Ignored from docs since it is not directly exposed.
  10416. *
  10417. * @ignore
  10418. * @private
  10419. * @param {PIXI.WebGLGraphicsData} graphicsData - The graphics object containing all the necessary properties
  10420. * @param {object} webGLData - an object containing all the webGL-specific information to create this shape
  10421. */
  10422. function buildLine(graphicsData, webGLData) {
  10423. // TODO OPTIMISE!
  10424. var points = graphicsData.points;
  10425. if (points.length === 0) {
  10426. return;
  10427. }
  10428. // if the line width is an odd number add 0.5 to align to a whole pixel
  10429. // commenting this out fixes #711 and #1620
  10430. // if (graphicsData.lineWidth%2)
  10431. // {
  10432. // for (i = 0; i < points.length; i++)
  10433. // {
  10434. // points[i] += 0.5;
  10435. // }
  10436. // }
  10437. // get first and last point.. figure out the middle!
  10438. var firstPoint = new _math.Point(points[0], points[1]);
  10439. var lastPoint = new _math.Point(points[points.length - 2], points[points.length - 1]);
  10440. // if the first point is the last point - gonna have issues :)
  10441. if (firstPoint.x === lastPoint.x && firstPoint.y === lastPoint.y) {
  10442. // need to clone as we are going to slightly modify the shape..
  10443. points = points.slice();
  10444. points.pop();
  10445. points.pop();
  10446. lastPoint = new _math.Point(points[points.length - 2], points[points.length - 1]);
  10447. var midPointX = lastPoint.x + (firstPoint.x - lastPoint.x) * 0.5;
  10448. var midPointY = lastPoint.y + (firstPoint.y - lastPoint.y) * 0.5;
  10449. points.unshift(midPointX, midPointY);
  10450. points.push(midPointX, midPointY);
  10451. }
  10452. var verts = webGLData.points;
  10453. var indices = webGLData.indices;
  10454. var length = points.length / 2;
  10455. var indexCount = points.length;
  10456. var indexStart = verts.length / 6;
  10457. // DRAW the Line
  10458. var width = graphicsData.lineWidth / 2;
  10459. // sort color
  10460. var color = (0, _utils.hex2rgb)(graphicsData.lineColor);
  10461. var alpha = graphicsData.lineAlpha;
  10462. var r = color[0] * alpha;
  10463. var g = color[1] * alpha;
  10464. var b = color[2] * alpha;
  10465. var p1x = points[0];
  10466. var p1y = points[1];
  10467. var p2x = points[2];
  10468. var p2y = points[3];
  10469. var p3x = 0;
  10470. var p3y = 0;
  10471. var perpx = -(p1y - p2y);
  10472. var perpy = p1x - p2x;
  10473. var perp2x = 0;
  10474. var perp2y = 0;
  10475. var perp3x = 0;
  10476. var perp3y = 0;
  10477. var dist = Math.sqrt(perpx * perpx + perpy * perpy);
  10478. perpx /= dist;
  10479. perpy /= dist;
  10480. perpx *= width;
  10481. perpy *= width;
  10482. // start
  10483. verts.push(p1x - perpx, p1y - perpy, r, g, b, alpha);
  10484. verts.push(p1x + perpx, p1y + perpy, r, g, b, alpha);
  10485. for (var i = 1; i < length - 1; ++i) {
  10486. p1x = points[(i - 1) * 2];
  10487. p1y = points[(i - 1) * 2 + 1];
  10488. p2x = points[i * 2];
  10489. p2y = points[i * 2 + 1];
  10490. p3x = points[(i + 1) * 2];
  10491. p3y = points[(i + 1) * 2 + 1];
  10492. perpx = -(p1y - p2y);
  10493. perpy = p1x - p2x;
  10494. dist = Math.sqrt(perpx * perpx + perpy * perpy);
  10495. perpx /= dist;
  10496. perpy /= dist;
  10497. perpx *= width;
  10498. perpy *= width;
  10499. perp2x = -(p2y - p3y);
  10500. perp2y = p2x - p3x;
  10501. dist = Math.sqrt(perp2x * perp2x + perp2y * perp2y);
  10502. perp2x /= dist;
  10503. perp2y /= dist;
  10504. perp2x *= width;
  10505. perp2y *= width;
  10506. var a1 = -perpy + p1y - (-perpy + p2y);
  10507. var b1 = -perpx + p2x - (-perpx + p1x);
  10508. var c1 = (-perpx + p1x) * (-perpy + p2y) - (-perpx + p2x) * (-perpy + p1y);
  10509. var a2 = -perp2y + p3y - (-perp2y + p2y);
  10510. var b2 = -perp2x + p2x - (-perp2x + p3x);
  10511. var c2 = (-perp2x + p3x) * (-perp2y + p2y) - (-perp2x + p2x) * (-perp2y + p3y);
  10512. var denom = a1 * b2 - a2 * b1;
  10513. if (Math.abs(denom) < 0.1) {
  10514. denom += 10.1;
  10515. verts.push(p2x - perpx, p2y - perpy, r, g, b, alpha);
  10516. verts.push(p2x + perpx, p2y + perpy, r, g, b, alpha);
  10517. continue;
  10518. }
  10519. var px = (b1 * c2 - b2 * c1) / denom;
  10520. var py = (a2 * c1 - a1 * c2) / denom;
  10521. var pdist = (px - p2x) * (px - p2x) + (py - p2y) * (py - p2y);
  10522. if (pdist > 196 * width * width) {
  10523. perp3x = perpx - perp2x;
  10524. perp3y = perpy - perp2y;
  10525. dist = Math.sqrt(perp3x * perp3x + perp3y * perp3y);
  10526. perp3x /= dist;
  10527. perp3y /= dist;
  10528. perp3x *= width;
  10529. perp3y *= width;
  10530. verts.push(p2x - perp3x, p2y - perp3y);
  10531. verts.push(r, g, b, alpha);
  10532. verts.push(p2x + perp3x, p2y + perp3y);
  10533. verts.push(r, g, b, alpha);
  10534. verts.push(p2x - perp3x, p2y - perp3y);
  10535. verts.push(r, g, b, alpha);
  10536. indexCount++;
  10537. } else {
  10538. verts.push(px, py);
  10539. verts.push(r, g, b, alpha);
  10540. verts.push(p2x - (px - p2x), p2y - (py - p2y));
  10541. verts.push(r, g, b, alpha);
  10542. }
  10543. }
  10544. p1x = points[(length - 2) * 2];
  10545. p1y = points[(length - 2) * 2 + 1];
  10546. p2x = points[(length - 1) * 2];
  10547. p2y = points[(length - 1) * 2 + 1];
  10548. perpx = -(p1y - p2y);
  10549. perpy = p1x - p2x;
  10550. dist = Math.sqrt(perpx * perpx + perpy * perpy);
  10551. perpx /= dist;
  10552. perpy /= dist;
  10553. perpx *= width;
  10554. perpy *= width;
  10555. verts.push(p2x - perpx, p2y - perpy);
  10556. verts.push(r, g, b, alpha);
  10557. verts.push(p2x + perpx, p2y + perpy);
  10558. verts.push(r, g, b, alpha);
  10559. indices.push(indexStart);
  10560. for (var _i = 0; _i < indexCount; ++_i) {
  10561. indices.push(indexStart++);
  10562. }
  10563. indices.push(indexStart - 1);
  10564. }
  10565. /**
  10566. * Builds a line to draw using the gl.drawArrays(gl.LINES) method
  10567. *
  10568. * Ignored from docs since it is not directly exposed.
  10569. *
  10570. * @ignore
  10571. * @private
  10572. * @param {PIXI.WebGLGraphicsData} graphicsData - The graphics object containing all the necessary properties
  10573. * @param {object} webGLData - an object containing all the webGL-specific information to create this shape
  10574. */
  10575. /**
  10576. * Builds a line to draw
  10577. *
  10578. * Ignored from docs since it is not directly exposed.
  10579. *
  10580. * @ignore
  10581. * @private
  10582. * @param {PIXI.WebGLGraphicsData} graphicsData - The graphics object containing all the necessary properties
  10583. * @param {object} webGLData - an object containing all the webGL-specific information to create this shape
  10584. * @param {object} webGLDataNativeLines - an object containing all the webGL-specific information to create nativeLines
  10585. */
  10586. function buildNativeLine(graphicsData, webGLData) {
  10587. var i = 0;
  10588. var points = graphicsData.points;
  10589. if (points.length === 0) return;
  10590. var verts = webGLData.points;
  10591. var length = points.length / 2;
  10592. // sort color
  10593. var color = (0, _utils.hex2rgb)(graphicsData.lineColor);
  10594. var alpha = graphicsData.lineAlpha;
  10595. var r = color[0] * alpha;
  10596. var g = color[1] * alpha;
  10597. var b = color[2] * alpha;
  10598. for (i = 1; i < length; i++) {
  10599. var p1x = points[(i - 1) * 2];
  10600. var p1y = points[(i - 1) * 2 + 1];
  10601. var p2x = points[i * 2];
  10602. var p2y = points[i * 2 + 1];
  10603. verts.push(p1x, p1y);
  10604. verts.push(r, g, b, alpha);
  10605. verts.push(p2x, p2y);
  10606. verts.push(r, g, b, alpha);
  10607. }
  10608. }
  10609. }, { "../../../math": 70, "../../../utils": 125 }], 62: [function (require, module, exports) {
  10610. 'use strict';
  10611. exports.__esModule = true;
  10612. exports.default = buildPoly;
  10613. var _buildLine = require('./buildLine');
  10614. var _buildLine2 = _interopRequireDefault(_buildLine);
  10615. var _utils = require('../../../utils');
  10616. var _earcut = require('earcut');
  10617. var _earcut2 = _interopRequireDefault(_earcut);
  10618. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  10619. /**
  10620. * Builds a polygon to draw
  10621. *
  10622. * Ignored from docs since it is not directly exposed.
  10623. *
  10624. * @ignore
  10625. * @private
  10626. * @param {PIXI.WebGLGraphicsData} graphicsData - The graphics object containing all the necessary properties
  10627. * @param {object} webGLData - an object containing all the webGL-specific information to create this shape
  10628. * @param {object} webGLDataNativeLines - an object containing all the webGL-specific information to create nativeLines
  10629. */
  10630. function buildPoly(graphicsData, webGLData, webGLDataNativeLines) {
  10631. graphicsData.points = graphicsData.shape.points.slice();
  10632. var points = graphicsData.points;
  10633. if (graphicsData.fill && points.length >= 6) {
  10634. var holeArray = [];
  10635. // Process holes..
  10636. var holes = graphicsData.holes;
  10637. for (var i = 0; i < holes.length; i++) {
  10638. var hole = holes[i];
  10639. holeArray.push(points.length / 2);
  10640. points = points.concat(hole.points);
  10641. }
  10642. // get first and last point.. figure out the middle!
  10643. var verts = webGLData.points;
  10644. var indices = webGLData.indices;
  10645. var length = points.length / 2;
  10646. // sort color
  10647. var color = (0, _utils.hex2rgb)(graphicsData.fillColor);
  10648. var alpha = graphicsData.fillAlpha;
  10649. var r = color[0] * alpha;
  10650. var g = color[1] * alpha;
  10651. var b = color[2] * alpha;
  10652. var triangles = (0, _earcut2.default)(points, holeArray, 2);
  10653. if (!triangles) {
  10654. return;
  10655. }
  10656. var vertPos = verts.length / 6;
  10657. for (var _i = 0; _i < triangles.length; _i += 3) {
  10658. indices.push(triangles[_i] + vertPos);
  10659. indices.push(triangles[_i] + vertPos);
  10660. indices.push(triangles[_i + 1] + vertPos);
  10661. indices.push(triangles[_i + 2] + vertPos);
  10662. indices.push(triangles[_i + 2] + vertPos);
  10663. }
  10664. for (var _i2 = 0; _i2 < length; _i2++) {
  10665. verts.push(points[_i2 * 2], points[_i2 * 2 + 1], r, g, b, alpha);
  10666. }
  10667. }
  10668. if (graphicsData.lineWidth > 0) {
  10669. (0, _buildLine2.default)(graphicsData, webGLData, webGLDataNativeLines);
  10670. }
  10671. }
  10672. }, { "../../../utils": 125, "./buildLine": 61, "earcut": 2 }], 63: [function (require, module, exports) {
  10673. 'use strict';
  10674. exports.__esModule = true;
  10675. exports.default = buildRectangle;
  10676. var _buildLine = require('./buildLine');
  10677. var _buildLine2 = _interopRequireDefault(_buildLine);
  10678. var _utils = require('../../../utils');
  10679. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  10680. /**
  10681. * Builds a rectangle to draw
  10682. *
  10683. * Ignored from docs since it is not directly exposed.
  10684. *
  10685. * @ignore
  10686. * @private
  10687. * @param {PIXI.WebGLGraphicsData} graphicsData - The graphics object containing all the necessary properties
  10688. * @param {object} webGLData - an object containing all the webGL-specific information to create this shape
  10689. * @param {object} webGLDataNativeLines - an object containing all the webGL-specific information to create nativeLines
  10690. */
  10691. function buildRectangle(graphicsData, webGLData, webGLDataNativeLines) {
  10692. // --- //
  10693. // need to convert points to a nice regular data
  10694. //
  10695. var rectData = graphicsData.shape;
  10696. var x = rectData.x;
  10697. var y = rectData.y;
  10698. var width = rectData.width;
  10699. var height = rectData.height;
  10700. if (graphicsData.fill) {
  10701. var color = (0, _utils.hex2rgb)(graphicsData.fillColor);
  10702. var alpha = graphicsData.fillAlpha;
  10703. var r = color[0] * alpha;
  10704. var g = color[1] * alpha;
  10705. var b = color[2] * alpha;
  10706. var verts = webGLData.points;
  10707. var indices = webGLData.indices;
  10708. var vertPos = verts.length / 6;
  10709. // start
  10710. verts.push(x, y);
  10711. verts.push(r, g, b, alpha);
  10712. verts.push(x + width, y);
  10713. verts.push(r, g, b, alpha);
  10714. verts.push(x, y + height);
  10715. verts.push(r, g, b, alpha);
  10716. verts.push(x + width, y + height);
  10717. verts.push(r, g, b, alpha);
  10718. // insert 2 dead triangles..
  10719. indices.push(vertPos, vertPos, vertPos + 1, vertPos + 2, vertPos + 3, vertPos + 3);
  10720. }
  10721. if (graphicsData.lineWidth) {
  10722. var tempPoints = graphicsData.points;
  10723. graphicsData.points = [x, y, x + width, y, x + width, y + height, x, y + height, x, y];
  10724. (0, _buildLine2.default)(graphicsData, webGLData, webGLDataNativeLines);
  10725. graphicsData.points = tempPoints;
  10726. }
  10727. }
  10728. }, { "../../../utils": 125, "./buildLine": 61 }], 64: [function (require, module, exports) {
  10729. 'use strict';
  10730. exports.__esModule = true;
  10731. exports.default = buildRoundedRectangle;
  10732. var _earcut = require('earcut');
  10733. var _earcut2 = _interopRequireDefault(_earcut);
  10734. var _buildLine = require('./buildLine');
  10735. var _buildLine2 = _interopRequireDefault(_buildLine);
  10736. var _utils = require('../../../utils');
  10737. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  10738. /**
  10739. * Builds a rounded rectangle to draw
  10740. *
  10741. * Ignored from docs since it is not directly exposed.
  10742. *
  10743. * @ignore
  10744. * @private
  10745. * @param {PIXI.WebGLGraphicsData} graphicsData - The graphics object containing all the necessary properties
  10746. * @param {object} webGLData - an object containing all the webGL-specific information to create this shape
  10747. * @param {object} webGLDataNativeLines - an object containing all the webGL-specific information to create nativeLines
  10748. */
  10749. function buildRoundedRectangle(graphicsData, webGLData, webGLDataNativeLines) {
  10750. var rrectData = graphicsData.shape;
  10751. var x = rrectData.x;
  10752. var y = rrectData.y;
  10753. var width = rrectData.width;
  10754. var height = rrectData.height;
  10755. var radius = rrectData.radius;
  10756. var recPoints = [];
  10757. recPoints.push(x, y + radius);
  10758. quadraticBezierCurve(x, y + height - radius, x, y + height, x + radius, y + height, recPoints);
  10759. quadraticBezierCurve(x + width - radius, y + height, x + width, y + height, x + width, y + height - radius, recPoints);
  10760. quadraticBezierCurve(x + width, y + radius, x + width, y, x + width - radius, y, recPoints);
  10761. quadraticBezierCurve(x + radius, y, x, y, x, y + radius + 0.0000000001, recPoints);
  10762. // this tiny number deals with the issue that occurs when points overlap and earcut fails to triangulate the item.
  10763. // TODO - fix this properly, this is not very elegant.. but it works for now.
  10764. if (graphicsData.fill) {
  10765. var color = (0, _utils.hex2rgb)(graphicsData.fillColor);
  10766. var alpha = graphicsData.fillAlpha;
  10767. var r = color[0] * alpha;
  10768. var g = color[1] * alpha;
  10769. var b = color[2] * alpha;
  10770. var verts = webGLData.points;
  10771. var indices = webGLData.indices;
  10772. var vecPos = verts.length / 6;
  10773. var triangles = (0, _earcut2.default)(recPoints, null, 2);
  10774. for (var i = 0, j = triangles.length; i < j; i += 3) {
  10775. indices.push(triangles[i] + vecPos);
  10776. indices.push(triangles[i] + vecPos);
  10777. indices.push(triangles[i + 1] + vecPos);
  10778. indices.push(triangles[i + 2] + vecPos);
  10779. indices.push(triangles[i + 2] + vecPos);
  10780. }
  10781. for (var _i = 0, _j = recPoints.length; _i < _j; _i++) {
  10782. verts.push(recPoints[_i], recPoints[++_i], r, g, b, alpha);
  10783. }
  10784. }
  10785. if (graphicsData.lineWidth) {
  10786. var tempPoints = graphicsData.points;
  10787. graphicsData.points = recPoints;
  10788. (0, _buildLine2.default)(graphicsData, webGLData, webGLDataNativeLines);
  10789. graphicsData.points = tempPoints;
  10790. }
  10791. }
  10792. /**
  10793. * Calculate a single point for a quadratic bezier curve.
  10794. * Utility function used by quadraticBezierCurve.
  10795. * Ignored from docs since it is not directly exposed.
  10796. *
  10797. * @ignore
  10798. * @private
  10799. * @param {number} n1 - first number
  10800. * @param {number} n2 - second number
  10801. * @param {number} perc - percentage
  10802. * @return {number} the result
  10803. *
  10804. */
  10805. function getPt(n1, n2, perc) {
  10806. var diff = n2 - n1;
  10807. return n1 + diff * perc;
  10808. }
  10809. /**
  10810. * Calculate the points for a quadratic bezier curve. (helper function..)
  10811. * Based on: https://stackoverflow.com/questions/785097/how-do-i-implement-a-bezier-curve-in-c
  10812. *
  10813. * Ignored from docs since it is not directly exposed.
  10814. *
  10815. * @ignore
  10816. * @private
  10817. * @param {number} fromX - Origin point x
  10818. * @param {number} fromY - Origin point x
  10819. * @param {number} cpX - Control point x
  10820. * @param {number} cpY - Control point y
  10821. * @param {number} toX - Destination point x
  10822. * @param {number} toY - Destination point y
  10823. * @param {number[]} [out=[]] - The output array to add points into. If not passed, a new array is created.
  10824. * @return {number[]} an array of points
  10825. */
  10826. function quadraticBezierCurve(fromX, fromY, cpX, cpY, toX, toY) {
  10827. var out = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : [];
  10828. var n = 20;
  10829. var points = out;
  10830. var xa = 0;
  10831. var ya = 0;
  10832. var xb = 0;
  10833. var yb = 0;
  10834. var x = 0;
  10835. var y = 0;
  10836. for (var i = 0, j = 0; i <= n; ++i) {
  10837. j = i / n;
  10838. // The Green Line
  10839. xa = getPt(fromX, cpX, j);
  10840. ya = getPt(fromY, cpY, j);
  10841. xb = getPt(cpX, toX, j);
  10842. yb = getPt(cpY, toY, j);
  10843. // The Black Dot
  10844. x = getPt(xa, xb, j);
  10845. y = getPt(ya, yb, j);
  10846. points.push(x, y);
  10847. }
  10848. return points;
  10849. }
  10850. }, { "../../../utils": 125, "./buildLine": 61, "earcut": 2 }], 65: [function (require, module, exports) {
  10851. 'use strict';
  10852. exports.__esModule = true;
  10853. exports.autoDetectRenderer = exports.Application = exports.Filter = exports.SpriteMaskFilter = exports.Quad = exports.RenderTarget = exports.ObjectRenderer = exports.WebGLManager = exports.Shader = exports.CanvasRenderTarget = exports.TextureUvs = exports.VideoBaseTexture = exports.BaseRenderTexture = exports.RenderTexture = exports.BaseTexture = exports.TextureMatrix = exports.Texture = exports.Spritesheet = exports.CanvasGraphicsRenderer = exports.GraphicsRenderer = exports.GraphicsData = exports.Graphics = exports.TextMetrics = exports.TextStyle = exports.Text = exports.SpriteRenderer = exports.CanvasTinter = exports.CanvasSpriteRenderer = exports.Sprite = exports.TransformBase = exports.TransformStatic = exports.Transform = exports.Container = exports.DisplayObject = exports.Bounds = exports.glCore = exports.WebGLRenderer = exports.CanvasRenderer = exports.ticker = exports.utils = exports.settings = undefined;
  10854. var _const = require('./const');
  10855. Object.keys(_const).forEach(function (key) {
  10856. if (key === "default" || key === "__esModule") return;
  10857. Object.defineProperty(exports, key, {
  10858. enumerable: true,
  10859. get: function get() {
  10860. return _const[key];
  10861. }
  10862. });
  10863. });
  10864. var _math = require('./math');
  10865. Object.keys(_math).forEach(function (key) {
  10866. if (key === "default" || key === "__esModule") return;
  10867. Object.defineProperty(exports, key, {
  10868. enumerable: true,
  10869. get: function get() {
  10870. return _math[key];
  10871. }
  10872. });
  10873. });
  10874. var _pixiGlCore = require('pixi-gl-core');
  10875. Object.defineProperty(exports, 'glCore', {
  10876. enumerable: true,
  10877. get: function get() {
  10878. return _interopRequireDefault(_pixiGlCore).default;
  10879. }
  10880. });
  10881. var _Bounds = require('./display/Bounds');
  10882. Object.defineProperty(exports, 'Bounds', {
  10883. enumerable: true,
  10884. get: function get() {
  10885. return _interopRequireDefault(_Bounds).default;
  10886. }
  10887. });
  10888. var _DisplayObject = require('./display/DisplayObject');
  10889. Object.defineProperty(exports, 'DisplayObject', {
  10890. enumerable: true,
  10891. get: function get() {
  10892. return _interopRequireDefault(_DisplayObject).default;
  10893. }
  10894. });
  10895. var _Container = require('./display/Container');
  10896. Object.defineProperty(exports, 'Container', {
  10897. enumerable: true,
  10898. get: function get() {
  10899. return _interopRequireDefault(_Container).default;
  10900. }
  10901. });
  10902. var _Transform = require('./display/Transform');
  10903. Object.defineProperty(exports, 'Transform', {
  10904. enumerable: true,
  10905. get: function get() {
  10906. return _interopRequireDefault(_Transform).default;
  10907. }
  10908. });
  10909. var _TransformStatic = require('./display/TransformStatic');
  10910. Object.defineProperty(exports, 'TransformStatic', {
  10911. enumerable: true,
  10912. get: function get() {
  10913. return _interopRequireDefault(_TransformStatic).default;
  10914. }
  10915. });
  10916. var _TransformBase = require('./display/TransformBase');
  10917. Object.defineProperty(exports, 'TransformBase', {
  10918. enumerable: true,
  10919. get: function get() {
  10920. return _interopRequireDefault(_TransformBase).default;
  10921. }
  10922. });
  10923. var _Sprite = require('./sprites/Sprite');
  10924. Object.defineProperty(exports, 'Sprite', {
  10925. enumerable: true,
  10926. get: function get() {
  10927. return _interopRequireDefault(_Sprite).default;
  10928. }
  10929. });
  10930. var _CanvasSpriteRenderer = require('./sprites/canvas/CanvasSpriteRenderer');
  10931. Object.defineProperty(exports, 'CanvasSpriteRenderer', {
  10932. enumerable: true,
  10933. get: function get() {
  10934. return _interopRequireDefault(_CanvasSpriteRenderer).default;
  10935. }
  10936. });
  10937. var _CanvasTinter = require('./sprites/canvas/CanvasTinter');
  10938. Object.defineProperty(exports, 'CanvasTinter', {
  10939. enumerable: true,
  10940. get: function get() {
  10941. return _interopRequireDefault(_CanvasTinter).default;
  10942. }
  10943. });
  10944. var _SpriteRenderer = require('./sprites/webgl/SpriteRenderer');
  10945. Object.defineProperty(exports, 'SpriteRenderer', {
  10946. enumerable: true,
  10947. get: function get() {
  10948. return _interopRequireDefault(_SpriteRenderer).default;
  10949. }
  10950. });
  10951. var _Text = require('./text/Text');
  10952. Object.defineProperty(exports, 'Text', {
  10953. enumerable: true,
  10954. get: function get() {
  10955. return _interopRequireDefault(_Text).default;
  10956. }
  10957. });
  10958. var _TextStyle = require('./text/TextStyle');
  10959. Object.defineProperty(exports, 'TextStyle', {
  10960. enumerable: true,
  10961. get: function get() {
  10962. return _interopRequireDefault(_TextStyle).default;
  10963. }
  10964. });
  10965. var _TextMetrics = require('./text/TextMetrics');
  10966. Object.defineProperty(exports, 'TextMetrics', {
  10967. enumerable: true,
  10968. get: function get() {
  10969. return _interopRequireDefault(_TextMetrics).default;
  10970. }
  10971. });
  10972. var _Graphics = require('./graphics/Graphics');
  10973. Object.defineProperty(exports, 'Graphics', {
  10974. enumerable: true,
  10975. get: function get() {
  10976. return _interopRequireDefault(_Graphics).default;
  10977. }
  10978. });
  10979. var _GraphicsData = require('./graphics/GraphicsData');
  10980. Object.defineProperty(exports, 'GraphicsData', {
  10981. enumerable: true,
  10982. get: function get() {
  10983. return _interopRequireDefault(_GraphicsData).default;
  10984. }
  10985. });
  10986. var _GraphicsRenderer = require('./graphics/webgl/GraphicsRenderer');
  10987. Object.defineProperty(exports, 'GraphicsRenderer', {
  10988. enumerable: true,
  10989. get: function get() {
  10990. return _interopRequireDefault(_GraphicsRenderer).default;
  10991. }
  10992. });
  10993. var _CanvasGraphicsRenderer = require('./graphics/canvas/CanvasGraphicsRenderer');
  10994. Object.defineProperty(exports, 'CanvasGraphicsRenderer', {
  10995. enumerable: true,
  10996. get: function get() {
  10997. return _interopRequireDefault(_CanvasGraphicsRenderer).default;
  10998. }
  10999. });
  11000. var _Spritesheet = require('./textures/Spritesheet');
  11001. Object.defineProperty(exports, 'Spritesheet', {
  11002. enumerable: true,
  11003. get: function get() {
  11004. return _interopRequireDefault(_Spritesheet).default;
  11005. }
  11006. });
  11007. var _Texture = require('./textures/Texture');
  11008. Object.defineProperty(exports, 'Texture', {
  11009. enumerable: true,
  11010. get: function get() {
  11011. return _interopRequireDefault(_Texture).default;
  11012. }
  11013. });
  11014. var _TextureMatrix = require('./textures/TextureMatrix');
  11015. Object.defineProperty(exports, 'TextureMatrix', {
  11016. enumerable: true,
  11017. get: function get() {
  11018. return _interopRequireDefault(_TextureMatrix).default;
  11019. }
  11020. });
  11021. var _BaseTexture = require('./textures/BaseTexture');
  11022. Object.defineProperty(exports, 'BaseTexture', {
  11023. enumerable: true,
  11024. get: function get() {
  11025. return _interopRequireDefault(_BaseTexture).default;
  11026. }
  11027. });
  11028. var _RenderTexture = require('./textures/RenderTexture');
  11029. Object.defineProperty(exports, 'RenderTexture', {
  11030. enumerable: true,
  11031. get: function get() {
  11032. return _interopRequireDefault(_RenderTexture).default;
  11033. }
  11034. });
  11035. var _BaseRenderTexture = require('./textures/BaseRenderTexture');
  11036. Object.defineProperty(exports, 'BaseRenderTexture', {
  11037. enumerable: true,
  11038. get: function get() {
  11039. return _interopRequireDefault(_BaseRenderTexture).default;
  11040. }
  11041. });
  11042. var _VideoBaseTexture = require('./textures/VideoBaseTexture');
  11043. Object.defineProperty(exports, 'VideoBaseTexture', {
  11044. enumerable: true,
  11045. get: function get() {
  11046. return _interopRequireDefault(_VideoBaseTexture).default;
  11047. }
  11048. });
  11049. var _TextureUvs = require('./textures/TextureUvs');
  11050. Object.defineProperty(exports, 'TextureUvs', {
  11051. enumerable: true,
  11052. get: function get() {
  11053. return _interopRequireDefault(_TextureUvs).default;
  11054. }
  11055. });
  11056. var _CanvasRenderTarget = require('./renderers/canvas/utils/CanvasRenderTarget');
  11057. Object.defineProperty(exports, 'CanvasRenderTarget', {
  11058. enumerable: true,
  11059. get: function get() {
  11060. return _interopRequireDefault(_CanvasRenderTarget).default;
  11061. }
  11062. });
  11063. var _Shader = require('./Shader');
  11064. Object.defineProperty(exports, 'Shader', {
  11065. enumerable: true,
  11066. get: function get() {
  11067. return _interopRequireDefault(_Shader).default;
  11068. }
  11069. });
  11070. var _WebGLManager = require('./renderers/webgl/managers/WebGLManager');
  11071. Object.defineProperty(exports, 'WebGLManager', {
  11072. enumerable: true,
  11073. get: function get() {
  11074. return _interopRequireDefault(_WebGLManager).default;
  11075. }
  11076. });
  11077. var _ObjectRenderer = require('./renderers/webgl/utils/ObjectRenderer');
  11078. Object.defineProperty(exports, 'ObjectRenderer', {
  11079. enumerable: true,
  11080. get: function get() {
  11081. return _interopRequireDefault(_ObjectRenderer).default;
  11082. }
  11083. });
  11084. var _RenderTarget = require('./renderers/webgl/utils/RenderTarget');
  11085. Object.defineProperty(exports, 'RenderTarget', {
  11086. enumerable: true,
  11087. get: function get() {
  11088. return _interopRequireDefault(_RenderTarget).default;
  11089. }
  11090. });
  11091. var _Quad = require('./renderers/webgl/utils/Quad');
  11092. Object.defineProperty(exports, 'Quad', {
  11093. enumerable: true,
  11094. get: function get() {
  11095. return _interopRequireDefault(_Quad).default;
  11096. }
  11097. });
  11098. var _SpriteMaskFilter = require('./renderers/webgl/filters/spriteMask/SpriteMaskFilter');
  11099. Object.defineProperty(exports, 'SpriteMaskFilter', {
  11100. enumerable: true,
  11101. get: function get() {
  11102. return _interopRequireDefault(_SpriteMaskFilter).default;
  11103. }
  11104. });
  11105. var _Filter = require('./renderers/webgl/filters/Filter');
  11106. Object.defineProperty(exports, 'Filter', {
  11107. enumerable: true,
  11108. get: function get() {
  11109. return _interopRequireDefault(_Filter).default;
  11110. }
  11111. });
  11112. var _Application = require('./Application');
  11113. Object.defineProperty(exports, 'Application', {
  11114. enumerable: true,
  11115. get: function get() {
  11116. return _interopRequireDefault(_Application).default;
  11117. }
  11118. });
  11119. var _autoDetectRenderer = require('./autoDetectRenderer');
  11120. Object.defineProperty(exports, 'autoDetectRenderer', {
  11121. enumerable: true,
  11122. get: function get() {
  11123. return _autoDetectRenderer.autoDetectRenderer;
  11124. }
  11125. });
  11126. var _utils = require('./utils');
  11127. var utils = _interopRequireWildcard(_utils);
  11128. var _ticker = require('./ticker');
  11129. var ticker = _interopRequireWildcard(_ticker);
  11130. var _settings = require('./settings');
  11131. var _settings2 = _interopRequireDefault(_settings);
  11132. var _CanvasRenderer = require('./renderers/canvas/CanvasRenderer');
  11133. var _CanvasRenderer2 = _interopRequireDefault(_CanvasRenderer);
  11134. var _WebGLRenderer = require('./renderers/webgl/WebGLRenderer');
  11135. var _WebGLRenderer2 = _interopRequireDefault(_WebGLRenderer);
  11136. function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
  11137. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  11138. exports.settings = _settings2.default;
  11139. exports.utils = utils;
  11140. exports.ticker = ticker;
  11141. exports.CanvasRenderer = _CanvasRenderer2.default;
  11142. exports.WebGLRenderer = _WebGLRenderer2.default; /**
  11143. * @namespace PIXI
  11144. */
  11145. }, { "./Application": 43, "./Shader": 44, "./autoDetectRenderer": 45, "./const": 46, "./display/Bounds": 47, "./display/Container": 48, "./display/DisplayObject": 49, "./display/Transform": 50, "./display/TransformBase": 51, "./display/TransformStatic": 52, "./graphics/Graphics": 53, "./graphics/GraphicsData": 54, "./graphics/canvas/CanvasGraphicsRenderer": 55, "./graphics/webgl/GraphicsRenderer": 57, "./math": 70, "./renderers/canvas/CanvasRenderer": 77, "./renderers/canvas/utils/CanvasRenderTarget": 79, "./renderers/webgl/WebGLRenderer": 84, "./renderers/webgl/filters/Filter": 86, "./renderers/webgl/filters/spriteMask/SpriteMaskFilter": 89, "./renderers/webgl/managers/WebGLManager": 93, "./renderers/webgl/utils/ObjectRenderer": 94, "./renderers/webgl/utils/Quad": 95, "./renderers/webgl/utils/RenderTarget": 96, "./settings": 101, "./sprites/Sprite": 102, "./sprites/canvas/CanvasSpriteRenderer": 103, "./sprites/canvas/CanvasTinter": 104, "./sprites/webgl/SpriteRenderer": 106, "./text/Text": 108, "./text/TextMetrics": 109, "./text/TextStyle": 110, "./textures/BaseRenderTexture": 111, "./textures/BaseTexture": 112, "./textures/RenderTexture": 113, "./textures/Spritesheet": 114, "./textures/Texture": 115, "./textures/TextureMatrix": 116, "./textures/TextureUvs": 117, "./textures/VideoBaseTexture": 118, "./ticker": 121, "./utils": 125, "pixi-gl-core": 15 }], 66: [function (require, module, exports) {
  11146. 'use strict';
  11147. exports.__esModule = true;
  11148. var _Matrix = require('./Matrix');
  11149. var _Matrix2 = _interopRequireDefault(_Matrix);
  11150. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  11151. var ux = [1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1]; // Your friendly neighbour https://en.wikipedia.org/wiki/Dihedral_group of order 16
  11152. var uy = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1];
  11153. var vx = [0, -1, -1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 0, -1, -1, -1];
  11154. var vy = [1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 0, 1, 1, 1, 0, -1];
  11155. var tempMatrices = [];
  11156. var mul = [];
  11157. function signum(x) {
  11158. if (x < 0) {
  11159. return -1;
  11160. }
  11161. if (x > 0) {
  11162. return 1;
  11163. }
  11164. return 0;
  11165. }
  11166. function init() {
  11167. for (var i = 0; i < 16; i++) {
  11168. var row = [];
  11169. mul.push(row);
  11170. for (var j = 0; j < 16; j++) {
  11171. var _ux = signum(ux[i] * ux[j] + vx[i] * uy[j]);
  11172. var _uy = signum(uy[i] * ux[j] + vy[i] * uy[j]);
  11173. var _vx = signum(ux[i] * vx[j] + vx[i] * vy[j]);
  11174. var _vy = signum(uy[i] * vx[j] + vy[i] * vy[j]);
  11175. for (var k = 0; k < 16; k++) {
  11176. if (ux[k] === _ux && uy[k] === _uy && vx[k] === _vx && vy[k] === _vy) {
  11177. row.push(k);
  11178. break;
  11179. }
  11180. }
  11181. }
  11182. }
  11183. for (var _i = 0; _i < 16; _i++) {
  11184. var mat = new _Matrix2.default();
  11185. mat.set(ux[_i], uy[_i], vx[_i], vy[_i], 0, 0);
  11186. tempMatrices.push(mat);
  11187. }
  11188. }
  11189. init();
  11190. /**
  11191. * Implements Dihedral Group D_8, see [group D4]{@link http://mathworld.wolfram.com/DihedralGroupD4.html},
  11192. * D8 is the same but with diagonals. Used for texture rotations.
  11193. *
  11194. * Vector xX(i), xY(i) is U-axis of sprite with rotation i
  11195. * Vector yY(i), yY(i) is V-axis of sprite with rotation i
  11196. * Rotations: 0 grad (0), 90 grad (2), 180 grad (4), 270 grad (6)
  11197. * Mirrors: vertical (8), main diagonal (10), horizontal (12), reverse diagonal (14)
  11198. * This is the small part of gameofbombs.com portal system. It works.
  11199. *
  11200. * @author Ivan @ivanpopelyshev
  11201. * @class
  11202. * @memberof PIXI
  11203. */
  11204. var GroupD8 = {
  11205. E: 0,
  11206. SE: 1,
  11207. S: 2,
  11208. SW: 3,
  11209. W: 4,
  11210. NW: 5,
  11211. N: 6,
  11212. NE: 7,
  11213. MIRROR_VERTICAL: 8,
  11214. MIRROR_HORIZONTAL: 12,
  11215. uX: function uX(ind) {
  11216. return ux[ind];
  11217. },
  11218. uY: function uY(ind) {
  11219. return uy[ind];
  11220. },
  11221. vX: function vX(ind) {
  11222. return vx[ind];
  11223. },
  11224. vY: function vY(ind) {
  11225. return vy[ind];
  11226. },
  11227. inv: function inv(rotation) {
  11228. if (rotation & 8) {
  11229. return rotation & 15;
  11230. }
  11231. return -rotation & 7;
  11232. },
  11233. add: function add(rotationSecond, rotationFirst) {
  11234. return mul[rotationSecond][rotationFirst];
  11235. },
  11236. sub: function sub(rotationSecond, rotationFirst) {
  11237. return mul[rotationSecond][GroupD8.inv(rotationFirst)];
  11238. },
  11239. /**
  11240. * Adds 180 degrees to rotation. Commutative operation.
  11241. *
  11242. * @memberof PIXI.GroupD8
  11243. * @param {number} rotation - The number to rotate.
  11244. * @returns {number} rotated number
  11245. */
  11246. rotate180: function rotate180(rotation) {
  11247. return rotation ^ 4;
  11248. },
  11249. /**
  11250. * Direction of main vector can be horizontal, vertical or diagonal.
  11251. * Some objects work with vertical directions different.
  11252. *
  11253. * @memberof PIXI.GroupD8
  11254. * @param {number} rotation - The number to check.
  11255. * @returns {boolean} Whether or not the direction is vertical
  11256. */
  11257. isVertical: function isVertical(rotation) {
  11258. return (rotation & 3) === 2;
  11259. },
  11260. /**
  11261. * @memberof PIXI.GroupD8
  11262. * @param {number} dx - TODO
  11263. * @param {number} dy - TODO
  11264. *
  11265. * @return {number} TODO
  11266. */
  11267. byDirection: function byDirection(dx, dy) {
  11268. if (Math.abs(dx) * 2 <= Math.abs(dy)) {
  11269. if (dy >= 0) {
  11270. return GroupD8.S;
  11271. }
  11272. return GroupD8.N;
  11273. } else if (Math.abs(dy) * 2 <= Math.abs(dx)) {
  11274. if (dx > 0) {
  11275. return GroupD8.E;
  11276. }
  11277. return GroupD8.W;
  11278. } else if (dy > 0) {
  11279. if (dx > 0) {
  11280. return GroupD8.SE;
  11281. }
  11282. return GroupD8.SW;
  11283. } else if (dx > 0) {
  11284. return GroupD8.NE;
  11285. }
  11286. return GroupD8.NW;
  11287. },
  11288. /**
  11289. * Helps sprite to compensate texture packer rotation.
  11290. *
  11291. * @memberof PIXI.GroupD8
  11292. * @param {PIXI.Matrix} matrix - sprite world matrix
  11293. * @param {number} rotation - The rotation factor to use.
  11294. * @param {number} tx - sprite anchoring
  11295. * @param {number} ty - sprite anchoring
  11296. */
  11297. matrixAppendRotationInv: function matrixAppendRotationInv(matrix, rotation) {
  11298. var tx = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
  11299. var ty = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
  11300. // Packer used "rotation", we use "inv(rotation)"
  11301. var mat = tempMatrices[GroupD8.inv(rotation)];
  11302. mat.tx = tx;
  11303. mat.ty = ty;
  11304. matrix.append(mat);
  11305. }
  11306. };
  11307. exports.default = GroupD8;
  11308. }, { "./Matrix": 67 }], 67: [function (require, module, exports) {
  11309. 'use strict';
  11310. exports.__esModule = true;
  11311. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  11312. var _Point = require('./Point');
  11313. var _Point2 = _interopRequireDefault(_Point);
  11314. var _const = require('../const');
  11315. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  11316. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  11317. /**
  11318. * The PixiJS Matrix class as an object, which makes it a lot faster,
  11319. * here is a representation of it :
  11320. * | a | c | tx|
  11321. * | b | d | ty|
  11322. * | 0 | 0 | 1 |
  11323. *
  11324. * @class
  11325. * @memberof PIXI
  11326. */
  11327. var Matrix = function () {
  11328. /**
  11329. * @param {number} [a=1] - x scale
  11330. * @param {number} [b=0] - x skew
  11331. * @param {number} [c=0] - y skew
  11332. * @param {number} [d=1] - y scale
  11333. * @param {number} [tx=0] - x translation
  11334. * @param {number} [ty=0] - y translation
  11335. */
  11336. function Matrix() {
  11337. var a = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;
  11338. var b = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
  11339. var c = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
  11340. var d = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 1;
  11341. var tx = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 0;
  11342. var ty = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : 0;
  11343. _classCallCheck(this, Matrix);
  11344. /**
  11345. * @member {number}
  11346. * @default 1
  11347. */
  11348. this.a = a;
  11349. /**
  11350. * @member {number}
  11351. * @default 0
  11352. */
  11353. this.b = b;
  11354. /**
  11355. * @member {number}
  11356. * @default 0
  11357. */
  11358. this.c = c;
  11359. /**
  11360. * @member {number}
  11361. * @default 1
  11362. */
  11363. this.d = d;
  11364. /**
  11365. * @member {number}
  11366. * @default 0
  11367. */
  11368. this.tx = tx;
  11369. /**
  11370. * @member {number}
  11371. * @default 0
  11372. */
  11373. this.ty = ty;
  11374. this.array = null;
  11375. }
  11376. /**
  11377. * Creates a Matrix object based on the given array. The Element to Matrix mapping order is as follows:
  11378. *
  11379. * a = array[0]
  11380. * b = array[1]
  11381. * c = array[3]
  11382. * d = array[4]
  11383. * tx = array[2]
  11384. * ty = array[5]
  11385. *
  11386. * @param {number[]} array - The array that the matrix will be populated from.
  11387. */
  11388. Matrix.prototype.fromArray = function fromArray(array) {
  11389. this.a = array[0];
  11390. this.b = array[1];
  11391. this.c = array[3];
  11392. this.d = array[4];
  11393. this.tx = array[2];
  11394. this.ty = array[5];
  11395. };
  11396. /**
  11397. * sets the matrix properties
  11398. *
  11399. * @param {number} a - Matrix component
  11400. * @param {number} b - Matrix component
  11401. * @param {number} c - Matrix component
  11402. * @param {number} d - Matrix component
  11403. * @param {number} tx - Matrix component
  11404. * @param {number} ty - Matrix component
  11405. *
  11406. * @return {PIXI.Matrix} This matrix. Good for chaining method calls.
  11407. */
  11408. Matrix.prototype.set = function set(a, b, c, d, tx, ty) {
  11409. this.a = a;
  11410. this.b = b;
  11411. this.c = c;
  11412. this.d = d;
  11413. this.tx = tx;
  11414. this.ty = ty;
  11415. return this;
  11416. };
  11417. /**
  11418. * Creates an array from the current Matrix object.
  11419. *
  11420. * @param {boolean} transpose - Whether we need to transpose the matrix or not
  11421. * @param {Float32Array} [out=new Float32Array(9)] - If provided the array will be assigned to out
  11422. * @return {number[]} the newly created array which contains the matrix
  11423. */
  11424. Matrix.prototype.toArray = function toArray(transpose, out) {
  11425. if (!this.array) {
  11426. this.array = new Float32Array(9);
  11427. }
  11428. var array = out || this.array;
  11429. if (transpose) {
  11430. array[0] = this.a;
  11431. array[1] = this.b;
  11432. array[2] = 0;
  11433. array[3] = this.c;
  11434. array[4] = this.d;
  11435. array[5] = 0;
  11436. array[6] = this.tx;
  11437. array[7] = this.ty;
  11438. array[8] = 1;
  11439. } else {
  11440. array[0] = this.a;
  11441. array[1] = this.c;
  11442. array[2] = this.tx;
  11443. array[3] = this.b;
  11444. array[4] = this.d;
  11445. array[5] = this.ty;
  11446. array[6] = 0;
  11447. array[7] = 0;
  11448. array[8] = 1;
  11449. }
  11450. return array;
  11451. };
  11452. /**
  11453. * Get a new position with the current transformation applied.
  11454. * Can be used to go from a child's coordinate space to the world coordinate space. (e.g. rendering)
  11455. *
  11456. * @param {PIXI.Point} pos - The origin
  11457. * @param {PIXI.Point} [newPos] - The point that the new position is assigned to (allowed to be same as input)
  11458. * @return {PIXI.Point} The new point, transformed through this matrix
  11459. */
  11460. Matrix.prototype.apply = function apply(pos, newPos) {
  11461. newPos = newPos || new _Point2.default();
  11462. var x = pos.x;
  11463. var y = pos.y;
  11464. newPos.x = this.a * x + this.c * y + this.tx;
  11465. newPos.y = this.b * x + this.d * y + this.ty;
  11466. return newPos;
  11467. };
  11468. /**
  11469. * Get a new position with the inverse of the current transformation applied.
  11470. * Can be used to go from the world coordinate space to a child's coordinate space. (e.g. input)
  11471. *
  11472. * @param {PIXI.Point} pos - The origin
  11473. * @param {PIXI.Point} [newPos] - The point that the new position is assigned to (allowed to be same as input)
  11474. * @return {PIXI.Point} The new point, inverse-transformed through this matrix
  11475. */
  11476. Matrix.prototype.applyInverse = function applyInverse(pos, newPos) {
  11477. newPos = newPos || new _Point2.default();
  11478. var id = 1 / (this.a * this.d + this.c * -this.b);
  11479. var x = pos.x;
  11480. var y = pos.y;
  11481. newPos.x = this.d * id * x + -this.c * id * y + (this.ty * this.c - this.tx * this.d) * id;
  11482. newPos.y = this.a * id * y + -this.b * id * x + (-this.ty * this.a + this.tx * this.b) * id;
  11483. return newPos;
  11484. };
  11485. /**
  11486. * Translates the matrix on the x and y.
  11487. *
  11488. * @param {number} x How much to translate x by
  11489. * @param {number} y How much to translate y by
  11490. * @return {PIXI.Matrix} This matrix. Good for chaining method calls.
  11491. */
  11492. Matrix.prototype.translate = function translate(x, y) {
  11493. this.tx += x;
  11494. this.ty += y;
  11495. return this;
  11496. };
  11497. /**
  11498. * Applies a scale transformation to the matrix.
  11499. *
  11500. * @param {number} x The amount to scale horizontally
  11501. * @param {number} y The amount to scale vertically
  11502. * @return {PIXI.Matrix} This matrix. Good for chaining method calls.
  11503. */
  11504. Matrix.prototype.scale = function scale(x, y) {
  11505. this.a *= x;
  11506. this.d *= y;
  11507. this.c *= x;
  11508. this.b *= y;
  11509. this.tx *= x;
  11510. this.ty *= y;
  11511. return this;
  11512. };
  11513. /**
  11514. * Applies a rotation transformation to the matrix.
  11515. *
  11516. * @param {number} angle - The angle in radians.
  11517. * @return {PIXI.Matrix} This matrix. Good for chaining method calls.
  11518. */
  11519. Matrix.prototype.rotate = function rotate(angle) {
  11520. var cos = Math.cos(angle);
  11521. var sin = Math.sin(angle);
  11522. var a1 = this.a;
  11523. var c1 = this.c;
  11524. var tx1 = this.tx;
  11525. this.a = a1 * cos - this.b * sin;
  11526. this.b = a1 * sin + this.b * cos;
  11527. this.c = c1 * cos - this.d * sin;
  11528. this.d = c1 * sin + this.d * cos;
  11529. this.tx = tx1 * cos - this.ty * sin;
  11530. this.ty = tx1 * sin + this.ty * cos;
  11531. return this;
  11532. };
  11533. /**
  11534. * Appends the given Matrix to this Matrix.
  11535. *
  11536. * @param {PIXI.Matrix} matrix - The matrix to append.
  11537. * @return {PIXI.Matrix} This matrix. Good for chaining method calls.
  11538. */
  11539. Matrix.prototype.append = function append(matrix) {
  11540. var a1 = this.a;
  11541. var b1 = this.b;
  11542. var c1 = this.c;
  11543. var d1 = this.d;
  11544. this.a = matrix.a * a1 + matrix.b * c1;
  11545. this.b = matrix.a * b1 + matrix.b * d1;
  11546. this.c = matrix.c * a1 + matrix.d * c1;
  11547. this.d = matrix.c * b1 + matrix.d * d1;
  11548. this.tx = matrix.tx * a1 + matrix.ty * c1 + this.tx;
  11549. this.ty = matrix.tx * b1 + matrix.ty * d1 + this.ty;
  11550. return this;
  11551. };
  11552. /**
  11553. * Sets the matrix based on all the available properties
  11554. *
  11555. * @param {number} x - Position on the x axis
  11556. * @param {number} y - Position on the y axis
  11557. * @param {number} pivotX - Pivot on the x axis
  11558. * @param {number} pivotY - Pivot on the y axis
  11559. * @param {number} scaleX - Scale on the x axis
  11560. * @param {number} scaleY - Scale on the y axis
  11561. * @param {number} rotation - Rotation in radians
  11562. * @param {number} skewX - Skew on the x axis
  11563. * @param {number} skewY - Skew on the y axis
  11564. * @return {PIXI.Matrix} This matrix. Good for chaining method calls.
  11565. */
  11566. Matrix.prototype.setTransform = function setTransform(x, y, pivotX, pivotY, scaleX, scaleY, rotation, skewX, skewY) {
  11567. this.a = Math.cos(rotation + skewY) * scaleX;
  11568. this.b = Math.sin(rotation + skewY) * scaleX;
  11569. this.c = -Math.sin(rotation - skewX) * scaleY;
  11570. this.d = Math.cos(rotation - skewX) * scaleY;
  11571. this.tx = x - (pivotX * this.a + pivotY * this.c);
  11572. this.ty = y - (pivotX * this.b + pivotY * this.d);
  11573. return this;
  11574. };
  11575. /**
  11576. * Prepends the given Matrix to this Matrix.
  11577. *
  11578. * @param {PIXI.Matrix} matrix - The matrix to prepend
  11579. * @return {PIXI.Matrix} This matrix. Good for chaining method calls.
  11580. */
  11581. Matrix.prototype.prepend = function prepend(matrix) {
  11582. var tx1 = this.tx;
  11583. if (matrix.a !== 1 || matrix.b !== 0 || matrix.c !== 0 || matrix.d !== 1) {
  11584. var a1 = this.a;
  11585. var c1 = this.c;
  11586. this.a = a1 * matrix.a + this.b * matrix.c;
  11587. this.b = a1 * matrix.b + this.b * matrix.d;
  11588. this.c = c1 * matrix.a + this.d * matrix.c;
  11589. this.d = c1 * matrix.b + this.d * matrix.d;
  11590. }
  11591. this.tx = tx1 * matrix.a + this.ty * matrix.c + matrix.tx;
  11592. this.ty = tx1 * matrix.b + this.ty * matrix.d + matrix.ty;
  11593. return this;
  11594. };
  11595. /**
  11596. * Decomposes the matrix (x, y, scaleX, scaleY, and rotation) and sets the properties on to a transform.
  11597. *
  11598. * @param {PIXI.Transform|PIXI.TransformStatic} transform - The transform to apply the properties to.
  11599. * @return {PIXI.Transform|PIXI.TransformStatic} The transform with the newly applied properties
  11600. */
  11601. Matrix.prototype.decompose = function decompose(transform) {
  11602. // sort out rotation / skew..
  11603. var a = this.a;
  11604. var b = this.b;
  11605. var c = this.c;
  11606. var d = this.d;
  11607. var skewX = -Math.atan2(-c, d);
  11608. var skewY = Math.atan2(b, a);
  11609. var delta = Math.abs(skewX + skewY);
  11610. if (delta < 0.00001 || Math.abs(_const.PI_2 - delta) < 0.00001) {
  11611. transform.rotation = skewY;
  11612. if (a < 0 && d >= 0) {
  11613. transform.rotation += transform.rotation <= 0 ? Math.PI : -Math.PI;
  11614. }
  11615. transform.skew.x = transform.skew.y = 0;
  11616. } else {
  11617. transform.rotation = 0;
  11618. transform.skew.x = skewX;
  11619. transform.skew.y = skewY;
  11620. }
  11621. // next set scale
  11622. transform.scale.x = Math.sqrt(a * a + b * b);
  11623. transform.scale.y = Math.sqrt(c * c + d * d);
  11624. // next set position
  11625. transform.position.x = this.tx;
  11626. transform.position.y = this.ty;
  11627. return transform;
  11628. };
  11629. /**
  11630. * Inverts this matrix
  11631. *
  11632. * @return {PIXI.Matrix} This matrix. Good for chaining method calls.
  11633. */
  11634. Matrix.prototype.invert = function invert() {
  11635. var a1 = this.a;
  11636. var b1 = this.b;
  11637. var c1 = this.c;
  11638. var d1 = this.d;
  11639. var tx1 = this.tx;
  11640. var n = a1 * d1 - b1 * c1;
  11641. this.a = d1 / n;
  11642. this.b = -b1 / n;
  11643. this.c = -c1 / n;
  11644. this.d = a1 / n;
  11645. this.tx = (c1 * this.ty - d1 * tx1) / n;
  11646. this.ty = -(a1 * this.ty - b1 * tx1) / n;
  11647. return this;
  11648. };
  11649. /**
  11650. * Resets this Matix to an identity (default) matrix.
  11651. *
  11652. * @return {PIXI.Matrix} This matrix. Good for chaining method calls.
  11653. */
  11654. Matrix.prototype.identity = function identity() {
  11655. this.a = 1;
  11656. this.b = 0;
  11657. this.c = 0;
  11658. this.d = 1;
  11659. this.tx = 0;
  11660. this.ty = 0;
  11661. return this;
  11662. };
  11663. /**
  11664. * Creates a new Matrix object with the same values as this one.
  11665. *
  11666. * @return {PIXI.Matrix} A copy of this matrix. Good for chaining method calls.
  11667. */
  11668. Matrix.prototype.clone = function clone() {
  11669. var matrix = new Matrix();
  11670. matrix.a = this.a;
  11671. matrix.b = this.b;
  11672. matrix.c = this.c;
  11673. matrix.d = this.d;
  11674. matrix.tx = this.tx;
  11675. matrix.ty = this.ty;
  11676. return matrix;
  11677. };
  11678. /**
  11679. * Changes the values of the given matrix to be the same as the ones in this matrix
  11680. *
  11681. * @param {PIXI.Matrix} matrix - The matrix to copy from.
  11682. * @return {PIXI.Matrix} The matrix given in parameter with its values updated.
  11683. */
  11684. Matrix.prototype.copy = function copy(matrix) {
  11685. matrix.a = this.a;
  11686. matrix.b = this.b;
  11687. matrix.c = this.c;
  11688. matrix.d = this.d;
  11689. matrix.tx = this.tx;
  11690. matrix.ty = this.ty;
  11691. return matrix;
  11692. };
  11693. /**
  11694. * A default (identity) matrix
  11695. *
  11696. * @static
  11697. * @const
  11698. */
  11699. _createClass(Matrix, null, [{
  11700. key: 'IDENTITY',
  11701. get: function get() {
  11702. return new Matrix();
  11703. }
  11704. /**
  11705. * A temp matrix
  11706. *
  11707. * @static
  11708. * @const
  11709. */
  11710. }, {
  11711. key: 'TEMP_MATRIX',
  11712. get: function get() {
  11713. return new Matrix();
  11714. }
  11715. }]);
  11716. return Matrix;
  11717. }();
  11718. exports.default = Matrix;
  11719. }, { "../const": 46, "./Point": 69 }], 68: [function (require, module, exports) {
  11720. "use strict";
  11721. exports.__esModule = true;
  11722. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  11723. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  11724. /**
  11725. * The Point object represents a location in a two-dimensional coordinate system, where x represents
  11726. * the horizontal axis and y represents the vertical axis.
  11727. * An observable point is a point that triggers a callback when the point's position is changed.
  11728. *
  11729. * @class
  11730. * @memberof PIXI
  11731. */
  11732. var ObservablePoint = function () {
  11733. /**
  11734. * @param {Function} cb - callback when changed
  11735. * @param {object} scope - owner of callback
  11736. * @param {number} [x=0] - position of the point on the x axis
  11737. * @param {number} [y=0] - position of the point on the y axis
  11738. */
  11739. function ObservablePoint(cb, scope) {
  11740. var x = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
  11741. var y = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
  11742. _classCallCheck(this, ObservablePoint);
  11743. this._x = x;
  11744. this._y = y;
  11745. this.cb = cb;
  11746. this.scope = scope;
  11747. }
  11748. /**
  11749. * Sets the point to a new x and y position.
  11750. * If y is omitted, both x and y will be set to x.
  11751. *
  11752. * @param {number} [x=0] - position of the point on the x axis
  11753. * @param {number} [y=0] - position of the point on the y axis
  11754. */
  11755. ObservablePoint.prototype.set = function set(x, y) {
  11756. var _x = x || 0;
  11757. var _y = y || (y !== 0 ? _x : 0);
  11758. if (this._x !== _x || this._y !== _y) {
  11759. this._x = _x;
  11760. this._y = _y;
  11761. this.cb.call(this.scope);
  11762. }
  11763. };
  11764. /**
  11765. * Copies the data from another point
  11766. *
  11767. * @param {PIXI.Point|PIXI.ObservablePoint} point - point to copy from
  11768. */
  11769. ObservablePoint.prototype.copy = function copy(point) {
  11770. if (this._x !== point.x || this._y !== point.y) {
  11771. this._x = point.x;
  11772. this._y = point.y;
  11773. this.cb.call(this.scope);
  11774. }
  11775. };
  11776. /**
  11777. * The position of the displayObject on the x axis relative to the local coordinates of the parent.
  11778. *
  11779. * @member {number}
  11780. */
  11781. _createClass(ObservablePoint, [{
  11782. key: "x",
  11783. get: function get() {
  11784. return this._x;
  11785. },
  11786. set: function set(value) // eslint-disable-line require-jsdoc
  11787. {
  11788. if (this._x !== value) {
  11789. this._x = value;
  11790. this.cb.call(this.scope);
  11791. }
  11792. }
  11793. /**
  11794. * The position of the displayObject on the x axis relative to the local coordinates of the parent.
  11795. *
  11796. * @member {number}
  11797. */
  11798. }, {
  11799. key: "y",
  11800. get: function get() {
  11801. return this._y;
  11802. },
  11803. set: function set(value) // eslint-disable-line require-jsdoc
  11804. {
  11805. if (this._y !== value) {
  11806. this._y = value;
  11807. this.cb.call(this.scope);
  11808. }
  11809. }
  11810. }]);
  11811. return ObservablePoint;
  11812. }();
  11813. exports.default = ObservablePoint;
  11814. }, {}], 69: [function (require, module, exports) {
  11815. "use strict";
  11816. exports.__esModule = true;
  11817. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  11818. /**
  11819. * The Point object represents a location in a two-dimensional coordinate system, where x represents
  11820. * the horizontal axis and y represents the vertical axis.
  11821. *
  11822. * @class
  11823. * @memberof PIXI
  11824. */
  11825. var Point = function () {
  11826. /**
  11827. * @param {number} [x=0] - position of the point on the x axis
  11828. * @param {number} [y=0] - position of the point on the y axis
  11829. */
  11830. function Point() {
  11831. var x = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
  11832. var y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
  11833. _classCallCheck(this, Point);
  11834. /**
  11835. * @member {number}
  11836. * @default 0
  11837. */
  11838. this.x = x;
  11839. /**
  11840. * @member {number}
  11841. * @default 0
  11842. */
  11843. this.y = y;
  11844. }
  11845. /**
  11846. * Creates a clone of this point
  11847. *
  11848. * @return {PIXI.Point} a copy of the point
  11849. */
  11850. Point.prototype.clone = function clone() {
  11851. return new Point(this.x, this.y);
  11852. };
  11853. /**
  11854. * Copies x and y from the given point
  11855. *
  11856. * @param {PIXI.Point} p - The point to copy.
  11857. */
  11858. Point.prototype.copy = function copy(p) {
  11859. this.set(p.x, p.y);
  11860. };
  11861. /**
  11862. * Returns true if the given point is equal to this point
  11863. *
  11864. * @param {PIXI.Point} p - The point to check
  11865. * @returns {boolean} Whether the given point equal to this point
  11866. */
  11867. Point.prototype.equals = function equals(p) {
  11868. return p.x === this.x && p.y === this.y;
  11869. };
  11870. /**
  11871. * Sets the point to a new x and y position.
  11872. * If y is omitted, both x and y will be set to x.
  11873. *
  11874. * @param {number} [x=0] - position of the point on the x axis
  11875. * @param {number} [y=0] - position of the point on the y axis
  11876. */
  11877. Point.prototype.set = function set(x, y) {
  11878. this.x = x || 0;
  11879. this.y = y || (y !== 0 ? this.x : 0);
  11880. };
  11881. return Point;
  11882. }();
  11883. exports.default = Point;
  11884. }, {}], 70: [function (require, module, exports) {
  11885. 'use strict';
  11886. exports.__esModule = true;
  11887. var _Point = require('./Point');
  11888. Object.defineProperty(exports, 'Point', {
  11889. enumerable: true,
  11890. get: function get() {
  11891. return _interopRequireDefault(_Point).default;
  11892. }
  11893. });
  11894. var _ObservablePoint = require('./ObservablePoint');
  11895. Object.defineProperty(exports, 'ObservablePoint', {
  11896. enumerable: true,
  11897. get: function get() {
  11898. return _interopRequireDefault(_ObservablePoint).default;
  11899. }
  11900. });
  11901. var _Matrix = require('./Matrix');
  11902. Object.defineProperty(exports, 'Matrix', {
  11903. enumerable: true,
  11904. get: function get() {
  11905. return _interopRequireDefault(_Matrix).default;
  11906. }
  11907. });
  11908. var _GroupD = require('./GroupD8');
  11909. Object.defineProperty(exports, 'GroupD8', {
  11910. enumerable: true,
  11911. get: function get() {
  11912. return _interopRequireDefault(_GroupD).default;
  11913. }
  11914. });
  11915. var _Circle = require('./shapes/Circle');
  11916. Object.defineProperty(exports, 'Circle', {
  11917. enumerable: true,
  11918. get: function get() {
  11919. return _interopRequireDefault(_Circle).default;
  11920. }
  11921. });
  11922. var _Ellipse = require('./shapes/Ellipse');
  11923. Object.defineProperty(exports, 'Ellipse', {
  11924. enumerable: true,
  11925. get: function get() {
  11926. return _interopRequireDefault(_Ellipse).default;
  11927. }
  11928. });
  11929. var _Polygon = require('./shapes/Polygon');
  11930. Object.defineProperty(exports, 'Polygon', {
  11931. enumerable: true,
  11932. get: function get() {
  11933. return _interopRequireDefault(_Polygon).default;
  11934. }
  11935. });
  11936. var _Rectangle = require('./shapes/Rectangle');
  11937. Object.defineProperty(exports, 'Rectangle', {
  11938. enumerable: true,
  11939. get: function get() {
  11940. return _interopRequireDefault(_Rectangle).default;
  11941. }
  11942. });
  11943. var _RoundedRectangle = require('./shapes/RoundedRectangle');
  11944. Object.defineProperty(exports, 'RoundedRectangle', {
  11945. enumerable: true,
  11946. get: function get() {
  11947. return _interopRequireDefault(_RoundedRectangle).default;
  11948. }
  11949. });
  11950. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  11951. }, { "./GroupD8": 66, "./Matrix": 67, "./ObservablePoint": 68, "./Point": 69, "./shapes/Circle": 71, "./shapes/Ellipse": 72, "./shapes/Polygon": 73, "./shapes/Rectangle": 74, "./shapes/RoundedRectangle": 75 }], 71: [function (require, module, exports) {
  11952. 'use strict';
  11953. exports.__esModule = true;
  11954. var _Rectangle = require('./Rectangle');
  11955. var _Rectangle2 = _interopRequireDefault(_Rectangle);
  11956. var _const = require('../../const');
  11957. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  11958. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  11959. /**
  11960. * The Circle object can be used to specify a hit area for displayObjects
  11961. *
  11962. * @class
  11963. * @memberof PIXI
  11964. */
  11965. var Circle = function () {
  11966. /**
  11967. * @param {number} [x=0] - The X coordinate of the center of this circle
  11968. * @param {number} [y=0] - The Y coordinate of the center of this circle
  11969. * @param {number} [radius=0] - The radius of the circle
  11970. */
  11971. function Circle() {
  11972. var x = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
  11973. var y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
  11974. var radius = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
  11975. _classCallCheck(this, Circle);
  11976. /**
  11977. * @member {number}
  11978. * @default 0
  11979. */
  11980. this.x = x;
  11981. /**
  11982. * @member {number}
  11983. * @default 0
  11984. */
  11985. this.y = y;
  11986. /**
  11987. * @member {number}
  11988. * @default 0
  11989. */
  11990. this.radius = radius;
  11991. /**
  11992. * The type of the object, mainly used to avoid `instanceof` checks
  11993. *
  11994. * @member {number}
  11995. * @readOnly
  11996. * @default PIXI.SHAPES.CIRC
  11997. * @see PIXI.SHAPES
  11998. */
  11999. this.type = _const.SHAPES.CIRC;
  12000. }
  12001. /**
  12002. * Creates a clone of this Circle instance
  12003. *
  12004. * @return {PIXI.Circle} a copy of the Circle
  12005. */
  12006. Circle.prototype.clone = function clone() {
  12007. return new Circle(this.x, this.y, this.radius);
  12008. };
  12009. /**
  12010. * Checks whether the x and y coordinates given are contained within this circle
  12011. *
  12012. * @param {number} x - The X coordinate of the point to test
  12013. * @param {number} y - The Y coordinate of the point to test
  12014. * @return {boolean} Whether the x/y coordinates are within this Circle
  12015. */
  12016. Circle.prototype.contains = function contains(x, y) {
  12017. if (this.radius <= 0) {
  12018. return false;
  12019. }
  12020. var r2 = this.radius * this.radius;
  12021. var dx = this.x - x;
  12022. var dy = this.y - y;
  12023. dx *= dx;
  12024. dy *= dy;
  12025. return dx + dy <= r2;
  12026. };
  12027. /**
  12028. * Returns the framing rectangle of the circle as a Rectangle object
  12029. *
  12030. * @return {PIXI.Rectangle} the framing rectangle
  12031. */
  12032. Circle.prototype.getBounds = function getBounds() {
  12033. return new _Rectangle2.default(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2);
  12034. };
  12035. return Circle;
  12036. }();
  12037. exports.default = Circle;
  12038. }, { "../../const": 46, "./Rectangle": 74 }], 72: [function (require, module, exports) {
  12039. 'use strict';
  12040. exports.__esModule = true;
  12041. var _Rectangle = require('./Rectangle');
  12042. var _Rectangle2 = _interopRequireDefault(_Rectangle);
  12043. var _const = require('../../const');
  12044. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  12045. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  12046. /**
  12047. * The Ellipse object can be used to specify a hit area for displayObjects
  12048. *
  12049. * @class
  12050. * @memberof PIXI
  12051. */
  12052. var Ellipse = function () {
  12053. /**
  12054. * @param {number} [x=0] - The X coordinate of the center of this circle
  12055. * @param {number} [y=0] - The Y coordinate of the center of this circle
  12056. * @param {number} [width=0] - The half width of this ellipse
  12057. * @param {number} [height=0] - The half height of this ellipse
  12058. */
  12059. function Ellipse() {
  12060. var x = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
  12061. var y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
  12062. var width = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
  12063. var height = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
  12064. _classCallCheck(this, Ellipse);
  12065. /**
  12066. * @member {number}
  12067. * @default 0
  12068. */
  12069. this.x = x;
  12070. /**
  12071. * @member {number}
  12072. * @default 0
  12073. */
  12074. this.y = y;
  12075. /**
  12076. * @member {number}
  12077. * @default 0
  12078. */
  12079. this.width = width;
  12080. /**
  12081. * @member {number}
  12082. * @default 0
  12083. */
  12084. this.height = height;
  12085. /**
  12086. * The type of the object, mainly used to avoid `instanceof` checks
  12087. *
  12088. * @member {number}
  12089. * @readOnly
  12090. * @default PIXI.SHAPES.ELIP
  12091. * @see PIXI.SHAPES
  12092. */
  12093. this.type = _const.SHAPES.ELIP;
  12094. }
  12095. /**
  12096. * Creates a clone of this Ellipse instance
  12097. *
  12098. * @return {PIXI.Ellipse} a copy of the ellipse
  12099. */
  12100. Ellipse.prototype.clone = function clone() {
  12101. return new Ellipse(this.x, this.y, this.width, this.height);
  12102. };
  12103. /**
  12104. * Checks whether the x and y coordinates given are contained within this ellipse
  12105. *
  12106. * @param {number} x - The X coordinate of the point to test
  12107. * @param {number} y - The Y coordinate of the point to test
  12108. * @return {boolean} Whether the x/y coords are within this ellipse
  12109. */
  12110. Ellipse.prototype.contains = function contains(x, y) {
  12111. if (this.width <= 0 || this.height <= 0) {
  12112. return false;
  12113. }
  12114. // normalize the coords to an ellipse with center 0,0
  12115. var normx = (x - this.x) / this.width;
  12116. var normy = (y - this.y) / this.height;
  12117. normx *= normx;
  12118. normy *= normy;
  12119. return normx + normy <= 1;
  12120. };
  12121. /**
  12122. * Returns the framing rectangle of the ellipse as a Rectangle object
  12123. *
  12124. * @return {PIXI.Rectangle} the framing rectangle
  12125. */
  12126. Ellipse.prototype.getBounds = function getBounds() {
  12127. return new _Rectangle2.default(this.x - this.width, this.y - this.height, this.width, this.height);
  12128. };
  12129. return Ellipse;
  12130. }();
  12131. exports.default = Ellipse;
  12132. }, { "../../const": 46, "./Rectangle": 74 }], 73: [function (require, module, exports) {
  12133. 'use strict';
  12134. exports.__esModule = true;
  12135. var _Point = require('../Point');
  12136. var _Point2 = _interopRequireDefault(_Point);
  12137. var _const = require('../../const');
  12138. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  12139. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  12140. /**
  12141. * @class
  12142. * @memberof PIXI
  12143. */
  12144. var Polygon = function () {
  12145. /**
  12146. * @param {PIXI.Point[]|number[]} points - This can be an array of Points
  12147. * that form the polygon, a flat array of numbers that will be interpreted as [x,y, x,y, ...], or
  12148. * the arguments passed can be all the points of the polygon e.g.
  12149. * `new PIXI.Polygon(new PIXI.Point(), new PIXI.Point(), ...)`, or the arguments passed can be flat
  12150. * x,y values e.g. `new Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are Numbers.
  12151. */
  12152. function Polygon() {
  12153. for (var _len = arguments.length, points = Array(_len), _key = 0; _key < _len; _key++) {
  12154. points[_key] = arguments[_key];
  12155. }
  12156. _classCallCheck(this, Polygon);
  12157. if (Array.isArray(points[0])) {
  12158. points = points[0];
  12159. }
  12160. // if this is an array of points, convert it to a flat array of numbers
  12161. if (points[0] instanceof _Point2.default) {
  12162. var p = [];
  12163. for (var i = 0, il = points.length; i < il; i++) {
  12164. p.push(points[i].x, points[i].y);
  12165. }
  12166. points = p;
  12167. }
  12168. this.closed = true;
  12169. /**
  12170. * An array of the points of this polygon
  12171. *
  12172. * @member {number[]}
  12173. */
  12174. this.points = points;
  12175. /**
  12176. * The type of the object, mainly used to avoid `instanceof` checks
  12177. *
  12178. * @member {number}
  12179. * @readOnly
  12180. * @default PIXI.SHAPES.POLY
  12181. * @see PIXI.SHAPES
  12182. */
  12183. this.type = _const.SHAPES.POLY;
  12184. }
  12185. /**
  12186. * Creates a clone of this polygon
  12187. *
  12188. * @return {PIXI.Polygon} a copy of the polygon
  12189. */
  12190. Polygon.prototype.clone = function clone() {
  12191. return new Polygon(this.points.slice());
  12192. };
  12193. /**
  12194. * Closes the polygon, adding points if necessary.
  12195. *
  12196. */
  12197. Polygon.prototype.close = function close() {
  12198. var points = this.points;
  12199. // close the poly if the value is true!
  12200. if (points[0] !== points[points.length - 2] || points[1] !== points[points.length - 1]) {
  12201. points.push(points[0], points[1]);
  12202. }
  12203. };
  12204. /**
  12205. * Checks whether the x and y coordinates passed to this function are contained within this polygon
  12206. *
  12207. * @param {number} x - The X coordinate of the point to test
  12208. * @param {number} y - The Y coordinate of the point to test
  12209. * @return {boolean} Whether the x/y coordinates are within this polygon
  12210. */
  12211. Polygon.prototype.contains = function contains(x, y) {
  12212. var inside = false;
  12213. // use some raycasting to test hits
  12214. // https://github.com/substack/point-in-polygon/blob/master/index.js
  12215. var length = this.points.length / 2;
  12216. for (var i = 0, j = length - 1; i < length; j = i++) {
  12217. var xi = this.points[i * 2];
  12218. var yi = this.points[i * 2 + 1];
  12219. var xj = this.points[j * 2];
  12220. var yj = this.points[j * 2 + 1];
  12221. var intersect = yi > y !== yj > y && x < (xj - xi) * ((y - yi) / (yj - yi)) + xi;
  12222. if (intersect) {
  12223. inside = !inside;
  12224. }
  12225. }
  12226. return inside;
  12227. };
  12228. return Polygon;
  12229. }();
  12230. exports.default = Polygon;
  12231. }, { "../../const": 46, "../Point": 69 }], 74: [function (require, module, exports) {
  12232. 'use strict';
  12233. exports.__esModule = true;
  12234. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  12235. var _const = require('../../const');
  12236. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  12237. /**
  12238. * Rectangle object is an area defined by its position, as indicated by its top-left corner
  12239. * point (x, y) and by its width and its height.
  12240. *
  12241. * @class
  12242. * @memberof PIXI
  12243. */
  12244. var Rectangle = function () {
  12245. /**
  12246. * @param {number} [x=0] - The X coordinate of the upper-left corner of the rectangle
  12247. * @param {number} [y=0] - The Y coordinate of the upper-left corner of the rectangle
  12248. * @param {number} [width=0] - The overall width of this rectangle
  12249. * @param {number} [height=0] - The overall height of this rectangle
  12250. */
  12251. function Rectangle() {
  12252. var x = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
  12253. var y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
  12254. var width = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
  12255. var height = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
  12256. _classCallCheck(this, Rectangle);
  12257. /**
  12258. * @member {number}
  12259. * @default 0
  12260. */
  12261. this.x = Number(x);
  12262. /**
  12263. * @member {number}
  12264. * @default 0
  12265. */
  12266. this.y = Number(y);
  12267. /**
  12268. * @member {number}
  12269. * @default 0
  12270. */
  12271. this.width = Number(width);
  12272. /**
  12273. * @member {number}
  12274. * @default 0
  12275. */
  12276. this.height = Number(height);
  12277. /**
  12278. * The type of the object, mainly used to avoid `instanceof` checks
  12279. *
  12280. * @member {number}
  12281. * @readOnly
  12282. * @default PIXI.SHAPES.RECT
  12283. * @see PIXI.SHAPES
  12284. */
  12285. this.type = _const.SHAPES.RECT;
  12286. }
  12287. /**
  12288. * returns the left edge of the rectangle
  12289. *
  12290. * @member {number}
  12291. */
  12292. /**
  12293. * Creates a clone of this Rectangle
  12294. *
  12295. * @return {PIXI.Rectangle} a copy of the rectangle
  12296. */
  12297. Rectangle.prototype.clone = function clone() {
  12298. return new Rectangle(this.x, this.y, this.width, this.height);
  12299. };
  12300. /**
  12301. * Copies another rectangle to this one.
  12302. *
  12303. * @param {PIXI.Rectangle} rectangle - The rectangle to copy.
  12304. * @return {PIXI.Rectangle} Returns itself.
  12305. */
  12306. Rectangle.prototype.copy = function copy(rectangle) {
  12307. this.x = rectangle.x;
  12308. this.y = rectangle.y;
  12309. this.width = rectangle.width;
  12310. this.height = rectangle.height;
  12311. return this;
  12312. };
  12313. /**
  12314. * Checks whether the x and y coordinates given are contained within this Rectangle
  12315. *
  12316. * @param {number} x - The X coordinate of the point to test
  12317. * @param {number} y - The Y coordinate of the point to test
  12318. * @return {boolean} Whether the x/y coordinates are within this Rectangle
  12319. */
  12320. Rectangle.prototype.contains = function contains(x, y) {
  12321. if (this.width <= 0 || this.height <= 0) {
  12322. return false;
  12323. }
  12324. if (x >= this.x && x < this.x + this.width) {
  12325. if (y >= this.y && y < this.y + this.height) {
  12326. return true;
  12327. }
  12328. }
  12329. return false;
  12330. };
  12331. /**
  12332. * Pads the rectangle making it grow in all directions.
  12333. *
  12334. * @param {number} paddingX - The horizontal padding amount.
  12335. * @param {number} [paddingY] - The vertical padding amount.
  12336. */
  12337. Rectangle.prototype.pad = function pad(paddingX, paddingY) {
  12338. paddingX = paddingX || 0;
  12339. paddingY = paddingY || (paddingY !== 0 ? paddingX : 0);
  12340. this.x -= paddingX;
  12341. this.y -= paddingY;
  12342. this.width += paddingX * 2;
  12343. this.height += paddingY * 2;
  12344. };
  12345. /**
  12346. * Fits this rectangle around the passed one.
  12347. *
  12348. * @param {PIXI.Rectangle} rectangle - The rectangle to fit.
  12349. */
  12350. Rectangle.prototype.fit = function fit(rectangle) {
  12351. if (this.x < rectangle.x) {
  12352. this.width += this.x;
  12353. if (this.width < 0) {
  12354. this.width = 0;
  12355. }
  12356. this.x = rectangle.x;
  12357. }
  12358. if (this.y < rectangle.y) {
  12359. this.height += this.y;
  12360. if (this.height < 0) {
  12361. this.height = 0;
  12362. }
  12363. this.y = rectangle.y;
  12364. }
  12365. if (this.x + this.width > rectangle.x + rectangle.width) {
  12366. this.width = rectangle.width - this.x;
  12367. if (this.width < 0) {
  12368. this.width = 0;
  12369. }
  12370. }
  12371. if (this.y + this.height > rectangle.y + rectangle.height) {
  12372. this.height = rectangle.height - this.y;
  12373. if (this.height < 0) {
  12374. this.height = 0;
  12375. }
  12376. }
  12377. };
  12378. /**
  12379. * Enlarges this rectangle to include the passed rectangle.
  12380. *
  12381. * @param {PIXI.Rectangle} rectangle - The rectangle to include.
  12382. */
  12383. Rectangle.prototype.enlarge = function enlarge(rectangle) {
  12384. var x1 = Math.min(this.x, rectangle.x);
  12385. var x2 = Math.max(this.x + this.width, rectangle.x + rectangle.width);
  12386. var y1 = Math.min(this.y, rectangle.y);
  12387. var y2 = Math.max(this.y + this.height, rectangle.y + rectangle.height);
  12388. this.x = x1;
  12389. this.width = x2 - x1;
  12390. this.y = y1;
  12391. this.height = y2 - y1;
  12392. };
  12393. _createClass(Rectangle, [{
  12394. key: 'left',
  12395. get: function get() {
  12396. return this.x;
  12397. }
  12398. /**
  12399. * returns the right edge of the rectangle
  12400. *
  12401. * @member {number}
  12402. */
  12403. }, {
  12404. key: 'right',
  12405. get: function get() {
  12406. return this.x + this.width;
  12407. }
  12408. /**
  12409. * returns the top edge of the rectangle
  12410. *
  12411. * @member {number}
  12412. */
  12413. }, {
  12414. key: 'top',
  12415. get: function get() {
  12416. return this.y;
  12417. }
  12418. /**
  12419. * returns the bottom edge of the rectangle
  12420. *
  12421. * @member {number}
  12422. */
  12423. }, {
  12424. key: 'bottom',
  12425. get: function get() {
  12426. return this.y + this.height;
  12427. }
  12428. /**
  12429. * A constant empty rectangle.
  12430. *
  12431. * @static
  12432. * @constant
  12433. */
  12434. }], [{
  12435. key: 'EMPTY',
  12436. get: function get() {
  12437. return new Rectangle(0, 0, 0, 0);
  12438. }
  12439. }]);
  12440. return Rectangle;
  12441. }();
  12442. exports.default = Rectangle;
  12443. }, { "../../const": 46 }], 75: [function (require, module, exports) {
  12444. 'use strict';
  12445. exports.__esModule = true;
  12446. var _const = require('../../const');
  12447. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  12448. /**
  12449. * The Rounded Rectangle object is an area that has nice rounded corners, as indicated by its
  12450. * top-left corner point (x, y) and by its width and its height and its radius.
  12451. *
  12452. * @class
  12453. * @memberof PIXI
  12454. */
  12455. var RoundedRectangle = function () {
  12456. /**
  12457. * @param {number} [x=0] - The X coordinate of the upper-left corner of the rounded rectangle
  12458. * @param {number} [y=0] - The Y coordinate of the upper-left corner of the rounded rectangle
  12459. * @param {number} [width=0] - The overall width of this rounded rectangle
  12460. * @param {number} [height=0] - The overall height of this rounded rectangle
  12461. * @param {number} [radius=20] - Controls the radius of the rounded corners
  12462. */
  12463. function RoundedRectangle() {
  12464. var x = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
  12465. var y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
  12466. var width = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
  12467. var height = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
  12468. var radius = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 20;
  12469. _classCallCheck(this, RoundedRectangle);
  12470. /**
  12471. * @member {number}
  12472. * @default 0
  12473. */
  12474. this.x = x;
  12475. /**
  12476. * @member {number}
  12477. * @default 0
  12478. */
  12479. this.y = y;
  12480. /**
  12481. * @member {number}
  12482. * @default 0
  12483. */
  12484. this.width = width;
  12485. /**
  12486. * @member {number}
  12487. * @default 0
  12488. */
  12489. this.height = height;
  12490. /**
  12491. * @member {number}
  12492. * @default 20
  12493. */
  12494. this.radius = radius;
  12495. /**
  12496. * The type of the object, mainly used to avoid `instanceof` checks
  12497. *
  12498. * @member {number}
  12499. * @readonly
  12500. * @default PIXI.SHAPES.RREC
  12501. * @see PIXI.SHAPES
  12502. */
  12503. this.type = _const.SHAPES.RREC;
  12504. }
  12505. /**
  12506. * Creates a clone of this Rounded Rectangle
  12507. *
  12508. * @return {PIXI.RoundedRectangle} a copy of the rounded rectangle
  12509. */
  12510. RoundedRectangle.prototype.clone = function clone() {
  12511. return new RoundedRectangle(this.x, this.y, this.width, this.height, this.radius);
  12512. };
  12513. /**
  12514. * Checks whether the x and y coordinates given are contained within this Rounded Rectangle
  12515. *
  12516. * @param {number} x - The X coordinate of the point to test
  12517. * @param {number} y - The Y coordinate of the point to test
  12518. * @return {boolean} Whether the x/y coordinates are within this Rounded Rectangle
  12519. */
  12520. RoundedRectangle.prototype.contains = function contains(x, y) {
  12521. if (this.width <= 0 || this.height <= 0) {
  12522. return false;
  12523. }
  12524. if (x >= this.x && x <= this.x + this.width) {
  12525. if (y >= this.y && y <= this.y + this.height) {
  12526. if (y >= this.y + this.radius && y <= this.y + this.height - this.radius || x >= this.x + this.radius && x <= this.x + this.width - this.radius) {
  12527. return true;
  12528. }
  12529. var dx = x - (this.x + this.radius);
  12530. var dy = y - (this.y + this.radius);
  12531. var radius2 = this.radius * this.radius;
  12532. if (dx * dx + dy * dy <= radius2) {
  12533. return true;
  12534. }
  12535. dx = x - (this.x + this.width - this.radius);
  12536. if (dx * dx + dy * dy <= radius2) {
  12537. return true;
  12538. }
  12539. dy = y - (this.y + this.height - this.radius);
  12540. if (dx * dx + dy * dy <= radius2) {
  12541. return true;
  12542. }
  12543. dx = x - (this.x + this.radius);
  12544. if (dx * dx + dy * dy <= radius2) {
  12545. return true;
  12546. }
  12547. }
  12548. }
  12549. return false;
  12550. };
  12551. return RoundedRectangle;
  12552. }();
  12553. exports.default = RoundedRectangle;
  12554. }, { "../../const": 46 }], 76: [function (require, module, exports) {
  12555. 'use strict';
  12556. exports.__esModule = true;
  12557. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  12558. var _utils = require('../utils');
  12559. var _math = require('../math');
  12560. var _const = require('../const');
  12561. var _settings = require('../settings');
  12562. var _settings2 = _interopRequireDefault(_settings);
  12563. var _Container = require('../display/Container');
  12564. var _Container2 = _interopRequireDefault(_Container);
  12565. var _RenderTexture = require('../textures/RenderTexture');
  12566. var _RenderTexture2 = _interopRequireDefault(_RenderTexture);
  12567. var _eventemitter = require('eventemitter3');
  12568. var _eventemitter2 = _interopRequireDefault(_eventemitter);
  12569. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  12570. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  12571. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  12572. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  12573. var tempMatrix = new _math.Matrix();
  12574. /**
  12575. * The SystemRenderer is the base for a PixiJS Renderer. It is extended by the {@link PIXI.CanvasRenderer}
  12576. * and {@link PIXI.WebGLRenderer} which can be used for rendering a PixiJS scene.
  12577. *
  12578. * @abstract
  12579. * @class
  12580. * @extends EventEmitter
  12581. * @memberof PIXI
  12582. */
  12583. var SystemRenderer = function (_EventEmitter) {
  12584. _inherits(SystemRenderer, _EventEmitter);
  12585. // eslint-disable-next-line valid-jsdoc
  12586. /**
  12587. * @param {string} system - The name of the system this renderer is for.
  12588. * @param {object} [options] - The optional renderer parameters
  12589. * @param {number} [options.width=800] - the width of the screen
  12590. * @param {number} [options.height=600] - the height of the screen
  12591. * @param {HTMLCanvasElement} [options.view] - the canvas to use as a view, optional
  12592. * @param {boolean} [options.transparent=false] - If the render view is transparent, default false
  12593. * @param {boolean} [options.autoResize=false] - If the render view is automatically resized, default false
  12594. * @param {boolean} [options.antialias=false] - sets antialias (only applicable in chrome at the moment)
  12595. * @param {number} [options.resolution=1] - The resolution / device pixel ratio of the renderer. The
  12596. * resolution of the renderer retina would be 2.
  12597. * @param {boolean} [options.preserveDrawingBuffer=false] - enables drawing buffer preservation,
  12598. * enable this if you need to call toDataUrl on the webgl context.
  12599. * @param {boolean} [options.clearBeforeRender=true] - This sets if the renderer will clear the canvas or
  12600. * not before the new render pass.
  12601. * @param {number} [options.backgroundColor=0x000000] - The background color of the rendered area
  12602. * (shown if not transparent).
  12603. * @param {boolean} [options.roundPixels=false] - If true PixiJS will Math.floor() x/y values when rendering,
  12604. * stopping pixel interpolation.
  12605. */
  12606. function SystemRenderer(system, options, arg2, arg3) {
  12607. _classCallCheck(this, SystemRenderer);
  12608. var _this = _possibleConstructorReturn(this, _EventEmitter.call(this));
  12609. (0, _utils.sayHello)(system);
  12610. // Support for constructor(system, screenWidth, screenHeight, options)
  12611. if (typeof options === 'number') {
  12612. options = Object.assign({
  12613. width: options,
  12614. height: arg2 || _settings2.default.RENDER_OPTIONS.height
  12615. }, arg3);
  12616. }
  12617. // Add the default render options
  12618. options = Object.assign({}, _settings2.default.RENDER_OPTIONS, options);
  12619. /**
  12620. * The supplied constructor options.
  12621. *
  12622. * @member {Object}
  12623. * @readOnly
  12624. */
  12625. _this.options = options;
  12626. /**
  12627. * The type of the renderer.
  12628. *
  12629. * @member {number}
  12630. * @default PIXI.RENDERER_TYPE.UNKNOWN
  12631. * @see PIXI.RENDERER_TYPE
  12632. */
  12633. _this.type = _const.RENDERER_TYPE.UNKNOWN;
  12634. /**
  12635. * Measurements of the screen. (0, 0, screenWidth, screenHeight)
  12636. *
  12637. * Its safe to use as filterArea or hitArea for whole stage
  12638. *
  12639. * @member {PIXI.Rectangle}
  12640. */
  12641. _this.screen = new _math.Rectangle(0, 0, options.width, options.height);
  12642. /**
  12643. * The canvas element that everything is drawn to
  12644. *
  12645. * @member {HTMLCanvasElement}
  12646. */
  12647. _this.view = options.view || document.createElement('canvas');
  12648. /**
  12649. * The resolution / device pixel ratio of the renderer
  12650. *
  12651. * @member {number}
  12652. * @default 1
  12653. */
  12654. _this.resolution = options.resolution || _settings2.default.RESOLUTION;
  12655. /**
  12656. * Whether the render view is transparent
  12657. *
  12658. * @member {boolean}
  12659. */
  12660. _this.transparent = options.transparent;
  12661. /**
  12662. * Whether css dimensions of canvas view should be resized to screen dimensions automatically
  12663. *
  12664. * @member {boolean}
  12665. */
  12666. _this.autoResize = options.autoResize || false;
  12667. /**
  12668. * Tracks the blend modes useful for this renderer.
  12669. *
  12670. * @member {object<string, mixed>}
  12671. */
  12672. _this.blendModes = null;
  12673. /**
  12674. * The value of the preserveDrawingBuffer flag affects whether or not the contents of
  12675. * the stencil buffer is retained after rendering.
  12676. *
  12677. * @member {boolean}
  12678. */
  12679. _this.preserveDrawingBuffer = options.preserveDrawingBuffer;
  12680. /**
  12681. * This sets if the CanvasRenderer will clear the canvas or not before the new render pass.
  12682. * If the scene is NOT transparent PixiJS will use a canvas sized fillRect operation every
  12683. * frame to set the canvas background color. If the scene is transparent PixiJS will use clearRect
  12684. * to clear the canvas every frame. Disable this by setting this to false. For example if
  12685. * your game has a canvas filling background image you often don't need this set.
  12686. *
  12687. * @member {boolean}
  12688. * @default
  12689. */
  12690. _this.clearBeforeRender = options.clearBeforeRender;
  12691. /**
  12692. * If true PixiJS will Math.floor() x/y values when rendering, stopping pixel interpolation.
  12693. * Handy for crisp pixel art and speed on legacy devices.
  12694. *
  12695. * @member {boolean}
  12696. */
  12697. _this.roundPixels = options.roundPixels;
  12698. /**
  12699. * The background color as a number.
  12700. *
  12701. * @member {number}
  12702. * @private
  12703. */
  12704. _this._backgroundColor = 0x000000;
  12705. /**
  12706. * The background color as an [R, G, B] array.
  12707. *
  12708. * @member {number[]}
  12709. * @private
  12710. */
  12711. _this._backgroundColorRgba = [0, 0, 0, 0];
  12712. /**
  12713. * The background color as a string.
  12714. *
  12715. * @member {string}
  12716. * @private
  12717. */
  12718. _this._backgroundColorString = '#000000';
  12719. _this.backgroundColor = options.backgroundColor || _this._backgroundColor; // run bg color setter
  12720. /**
  12721. * This temporary display object used as the parent of the currently being rendered item
  12722. *
  12723. * @member {PIXI.DisplayObject}
  12724. * @private
  12725. */
  12726. _this._tempDisplayObjectParent = new _Container2.default();
  12727. /**
  12728. * The last root object that the renderer tried to render.
  12729. *
  12730. * @member {PIXI.DisplayObject}
  12731. * @private
  12732. */
  12733. _this._lastObjectRendered = _this._tempDisplayObjectParent;
  12734. return _this;
  12735. }
  12736. /**
  12737. * Same as view.width, actual number of pixels in the canvas by horizontal
  12738. *
  12739. * @member {number}
  12740. * @readonly
  12741. * @default 800
  12742. */
  12743. /**
  12744. * Resizes the screen and canvas to the specified width and height
  12745. * Canvas dimensions are multiplied by resolution
  12746. *
  12747. * @param {number} screenWidth - the new width of the screen
  12748. * @param {number} screenHeight - the new height of the screen
  12749. */
  12750. SystemRenderer.prototype.resize = function resize(screenWidth, screenHeight) {
  12751. this.screen.width = screenWidth;
  12752. this.screen.height = screenHeight;
  12753. this.view.width = screenWidth * this.resolution;
  12754. this.view.height = screenHeight * this.resolution;
  12755. if (this.autoResize) {
  12756. this.view.style.width = screenWidth + 'px';
  12757. this.view.style.height = screenHeight + 'px';
  12758. }
  12759. };
  12760. /**
  12761. * Useful function that returns a texture of the display object that can then be used to create sprites
  12762. * This can be quite useful if your displayObject is complicated and needs to be reused multiple times.
  12763. *
  12764. * @param {PIXI.DisplayObject} displayObject - The displayObject the object will be generated from
  12765. * @param {number} scaleMode - Should be one of the scaleMode consts
  12766. * @param {number} resolution - The resolution / device pixel ratio of the texture being generated
  12767. * @param {PIXI.Rectangle} [region] - The region of the displayObject, that shall be rendered,
  12768. * if no region is specified, defaults to the local bounds of the displayObject.
  12769. * @return {PIXI.Texture} a texture of the graphics object
  12770. */
  12771. SystemRenderer.prototype.generateTexture = function generateTexture(displayObject, scaleMode, resolution, region) {
  12772. region = region || displayObject.getLocalBounds();
  12773. var renderTexture = _RenderTexture2.default.create(region.width | 0, region.height | 0, scaleMode, resolution);
  12774. tempMatrix.tx = -region.x;
  12775. tempMatrix.ty = -region.y;
  12776. this.render(displayObject, renderTexture, false, tempMatrix, true);
  12777. return renderTexture;
  12778. };
  12779. /**
  12780. * Removes everything from the renderer and optionally removes the Canvas DOM element.
  12781. *
  12782. * @param {boolean} [removeView=false] - Removes the Canvas element from the DOM.
  12783. */
  12784. SystemRenderer.prototype.destroy = function destroy(removeView) {
  12785. if (removeView && this.view.parentNode) {
  12786. this.view.parentNode.removeChild(this.view);
  12787. }
  12788. this.type = _const.RENDERER_TYPE.UNKNOWN;
  12789. this.view = null;
  12790. this.screen = null;
  12791. this.resolution = 0;
  12792. this.transparent = false;
  12793. this.autoResize = false;
  12794. this.blendModes = null;
  12795. this.options = null;
  12796. this.preserveDrawingBuffer = false;
  12797. this.clearBeforeRender = false;
  12798. this.roundPixels = false;
  12799. this._backgroundColor = 0;
  12800. this._backgroundColorRgba = null;
  12801. this._backgroundColorString = null;
  12802. this._tempDisplayObjectParent = null;
  12803. this._lastObjectRendered = null;
  12804. };
  12805. /**
  12806. * The background color to fill if not transparent
  12807. *
  12808. * @member {number}
  12809. */
  12810. _createClass(SystemRenderer, [{
  12811. key: 'width',
  12812. get: function get() {
  12813. return this.view.width;
  12814. }
  12815. /**
  12816. * Same as view.height, actual number of pixels in the canvas by vertical
  12817. *
  12818. * @member {number}
  12819. * @readonly
  12820. * @default 600
  12821. */
  12822. }, {
  12823. key: 'height',
  12824. get: function get() {
  12825. return this.view.height;
  12826. }
  12827. }, {
  12828. key: 'backgroundColor',
  12829. get: function get() {
  12830. return this._backgroundColor;
  12831. },
  12832. set: function set(value) // eslint-disable-line require-jsdoc
  12833. {
  12834. this._backgroundColor = value;
  12835. this._backgroundColorString = (0, _utils.hex2string)(value);
  12836. (0, _utils.hex2rgb)(value, this._backgroundColorRgba);
  12837. }
  12838. }]);
  12839. return SystemRenderer;
  12840. }(_eventemitter2.default);
  12841. exports.default = SystemRenderer;
  12842. }, { "../const": 46, "../display/Container": 48, "../math": 70, "../settings": 101, "../textures/RenderTexture": 113, "../utils": 125, "eventemitter3": 3 }], 77: [function (require, module, exports) {
  12843. 'use strict';
  12844. exports.__esModule = true;
  12845. var _SystemRenderer2 = require('../SystemRenderer');
  12846. var _SystemRenderer3 = _interopRequireDefault(_SystemRenderer2);
  12847. var _CanvasMaskManager = require('./utils/CanvasMaskManager');
  12848. var _CanvasMaskManager2 = _interopRequireDefault(_CanvasMaskManager);
  12849. var _CanvasRenderTarget = require('./utils/CanvasRenderTarget');
  12850. var _CanvasRenderTarget2 = _interopRequireDefault(_CanvasRenderTarget);
  12851. var _mapCanvasBlendModesToPixi = require('./utils/mapCanvasBlendModesToPixi');
  12852. var _mapCanvasBlendModesToPixi2 = _interopRequireDefault(_mapCanvasBlendModesToPixi);
  12853. var _utils = require('../../utils');
  12854. var _const = require('../../const');
  12855. var _settings = require('../../settings');
  12856. var _settings2 = _interopRequireDefault(_settings);
  12857. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  12858. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  12859. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  12860. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  12861. /**
  12862. * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should
  12863. * be used for browsers that do not support WebGL. Don't forget to add the CanvasRenderer.view to
  12864. * your DOM or you will not see anything :)
  12865. *
  12866. * @class
  12867. * @memberof PIXI
  12868. * @extends PIXI.SystemRenderer
  12869. */
  12870. var CanvasRenderer = function (_SystemRenderer) {
  12871. _inherits(CanvasRenderer, _SystemRenderer);
  12872. // eslint-disable-next-line valid-jsdoc
  12873. /**
  12874. * @param {object} [options] - The optional renderer parameters
  12875. * @param {number} [options.width=800] - the width of the screen
  12876. * @param {number} [options.height=600] - the height of the screen
  12877. * @param {HTMLCanvasElement} [options.view] - the canvas to use as a view, optional
  12878. * @param {boolean} [options.transparent=false] - If the render view is transparent, default false
  12879. * @param {boolean} [options.autoResize=false] - If the render view is automatically resized, default false
  12880. * @param {boolean} [options.antialias=false] - sets antialias (only applicable in chrome at the moment)
  12881. * @param {number} [options.resolution=1] - The resolution / device pixel ratio of the renderer. The
  12882. * resolution of the renderer retina would be 2.
  12883. * @param {boolean} [options.preserveDrawingBuffer=false] - enables drawing buffer preservation,
  12884. * enable this if you need to call toDataUrl on the webgl context.
  12885. * @param {boolean} [options.clearBeforeRender=true] - This sets if the renderer will clear the canvas or
  12886. * not before the new render pass.
  12887. * @param {number} [options.backgroundColor=0x000000] - The background color of the rendered area
  12888. * (shown if not transparent).
  12889. * @param {boolean} [options.roundPixels=false] - If true PixiJS will Math.floor() x/y values when rendering,
  12890. * stopping pixel interpolation.
  12891. */
  12892. function CanvasRenderer(options, arg2, arg3) {
  12893. _classCallCheck(this, CanvasRenderer);
  12894. var _this = _possibleConstructorReturn(this, _SystemRenderer.call(this, 'Canvas', options, arg2, arg3));
  12895. _this.type = _const.RENDERER_TYPE.CANVAS;
  12896. /**
  12897. * The root canvas 2d context that everything is drawn with.
  12898. *
  12899. * @member {CanvasRenderingContext2D}
  12900. */
  12901. _this.rootContext = _this.view.getContext('2d', { alpha: _this.transparent });
  12902. /**
  12903. * The currently active canvas 2d context (could change with renderTextures)
  12904. *
  12905. * @member {CanvasRenderingContext2D}
  12906. */
  12907. _this.context = _this.rootContext;
  12908. /**
  12909. * Boolean flag controlling canvas refresh.
  12910. *
  12911. * @member {boolean}
  12912. */
  12913. _this.refresh = true;
  12914. /**
  12915. * Instance of a CanvasMaskManager, handles masking when using the canvas renderer.
  12916. *
  12917. * @member {PIXI.CanvasMaskManager}
  12918. */
  12919. _this.maskManager = new _CanvasMaskManager2.default(_this);
  12920. /**
  12921. * The canvas property used to set the canvas smoothing property.
  12922. *
  12923. * @member {string}
  12924. */
  12925. _this.smoothProperty = 'imageSmoothingEnabled';
  12926. if (!_this.rootContext.imageSmoothingEnabled) {
  12927. if (_this.rootContext.webkitImageSmoothingEnabled) {
  12928. _this.smoothProperty = 'webkitImageSmoothingEnabled';
  12929. } else if (_this.rootContext.mozImageSmoothingEnabled) {
  12930. _this.smoothProperty = 'mozImageSmoothingEnabled';
  12931. } else if (_this.rootContext.oImageSmoothingEnabled) {
  12932. _this.smoothProperty = 'oImageSmoothingEnabled';
  12933. } else if (_this.rootContext.msImageSmoothingEnabled) {
  12934. _this.smoothProperty = 'msImageSmoothingEnabled';
  12935. }
  12936. }
  12937. _this.initPlugins();
  12938. _this.blendModes = (0, _mapCanvasBlendModesToPixi2.default)();
  12939. _this._activeBlendMode = null;
  12940. _this.renderingToScreen = false;
  12941. _this.resize(_this.options.width, _this.options.height);
  12942. /**
  12943. * Fired after rendering finishes.
  12944. *
  12945. * @event PIXI.CanvasRenderer#postrender
  12946. */
  12947. /**
  12948. * Fired before rendering starts.
  12949. *
  12950. * @event PIXI.CanvasRenderer#prerender
  12951. */
  12952. return _this;
  12953. }
  12954. /**
  12955. * Renders the object to this canvas view
  12956. *
  12957. * @param {PIXI.DisplayObject} displayObject - The object to be rendered
  12958. * @param {PIXI.RenderTexture} [renderTexture] - A render texture to be rendered to.
  12959. * If unset, it will render to the root context.
  12960. * @param {boolean} [clear=false] - Whether to clear the canvas before drawing
  12961. * @param {PIXI.Transform} [transform] - A transformation to be applied
  12962. * @param {boolean} [skipUpdateTransform=false] - Whether to skip the update transform
  12963. */
  12964. CanvasRenderer.prototype.render = function render(displayObject, renderTexture, clear, transform, skipUpdateTransform) {
  12965. if (!this.view) {
  12966. return;
  12967. }
  12968. // can be handy to know!
  12969. this.renderingToScreen = !renderTexture;
  12970. this.emit('prerender');
  12971. var rootResolution = this.resolution;
  12972. if (renderTexture) {
  12973. renderTexture = renderTexture.baseTexture || renderTexture;
  12974. if (!renderTexture._canvasRenderTarget) {
  12975. renderTexture._canvasRenderTarget = new _CanvasRenderTarget2.default(renderTexture.width, renderTexture.height, renderTexture.resolution);
  12976. renderTexture.source = renderTexture._canvasRenderTarget.canvas;
  12977. renderTexture.valid = true;
  12978. }
  12979. this.context = renderTexture._canvasRenderTarget.context;
  12980. this.resolution = renderTexture._canvasRenderTarget.resolution;
  12981. } else {
  12982. this.context = this.rootContext;
  12983. }
  12984. var context = this.context;
  12985. if (!renderTexture) {
  12986. this._lastObjectRendered = displayObject;
  12987. }
  12988. if (!skipUpdateTransform) {
  12989. // update the scene graph
  12990. var cacheParent = displayObject.parent;
  12991. var tempWt = this._tempDisplayObjectParent.transform.worldTransform;
  12992. if (transform) {
  12993. transform.copy(tempWt);
  12994. // lets not forget to flag the parent transform as dirty...
  12995. this._tempDisplayObjectParent.transform._worldID = -1;
  12996. } else {
  12997. tempWt.identity();
  12998. }
  12999. displayObject.parent = this._tempDisplayObjectParent;
  13000. displayObject.updateTransform();
  13001. displayObject.parent = cacheParent;
  13002. // displayObject.hitArea = //TODO add a temp hit area
  13003. }
  13004. context.save();
  13005. context.setTransform(1, 0, 0, 1, 0, 0);
  13006. context.globalAlpha = 1;
  13007. this._activeBlendMode = _const.BLEND_MODES.NORMAL;
  13008. context.globalCompositeOperation = this.blendModes[_const.BLEND_MODES.NORMAL];
  13009. if (navigator.isCocoonJS && this.view.screencanvas) {
  13010. context.fillStyle = 'black';
  13011. context.clear();
  13012. }
  13013. if (clear !== undefined ? clear : this.clearBeforeRender) {
  13014. if (this.renderingToScreen) {
  13015. if (this.transparent) {
  13016. context.clearRect(0, 0, this.width, this.height);
  13017. } else {
  13018. context.fillStyle = this._backgroundColorString;
  13019. context.fillRect(0, 0, this.width, this.height);
  13020. }
  13021. } // else {
  13022. // TODO: implement background for CanvasRenderTarget or RenderTexture?
  13023. // }
  13024. }
  13025. // TODO RENDER TARGET STUFF HERE..
  13026. var tempContext = this.context;
  13027. this.context = context;
  13028. displayObject.renderCanvas(this);
  13029. this.context = tempContext;
  13030. context.restore();
  13031. this.resolution = rootResolution;
  13032. this.emit('postrender');
  13033. };
  13034. /**
  13035. * Clear the canvas of renderer.
  13036. *
  13037. * @param {string} [clearColor] - Clear the canvas with this color, except the canvas is transparent.
  13038. */
  13039. CanvasRenderer.prototype.clear = function clear(clearColor) {
  13040. var context = this.context;
  13041. clearColor = clearColor || this._backgroundColorString;
  13042. if (!this.transparent && clearColor) {
  13043. context.fillStyle = clearColor;
  13044. context.fillRect(0, 0, this.width, this.height);
  13045. } else {
  13046. context.clearRect(0, 0, this.width, this.height);
  13047. }
  13048. };
  13049. /**
  13050. * Sets the blend mode of the renderer.
  13051. *
  13052. * @param {number} blendMode - See {@link PIXI.BLEND_MODES} for valid values.
  13053. */
  13054. CanvasRenderer.prototype.setBlendMode = function setBlendMode(blendMode) {
  13055. if (this._activeBlendMode === blendMode) {
  13056. return;
  13057. }
  13058. this._activeBlendMode = blendMode;
  13059. this.context.globalCompositeOperation = this.blendModes[blendMode];
  13060. };
  13061. /**
  13062. * Removes everything from the renderer and optionally removes the Canvas DOM element.
  13063. *
  13064. * @param {boolean} [removeView=false] - Removes the Canvas element from the DOM.
  13065. */
  13066. CanvasRenderer.prototype.destroy = function destroy(removeView) {
  13067. this.destroyPlugins();
  13068. // call the base destroy
  13069. _SystemRenderer.prototype.destroy.call(this, removeView);
  13070. this.context = null;
  13071. this.refresh = true;
  13072. this.maskManager.destroy();
  13073. this.maskManager = null;
  13074. this.smoothProperty = null;
  13075. };
  13076. /**
  13077. * Resizes the canvas view to the specified width and height.
  13078. *
  13079. * @extends PIXI.SystemRenderer#resize
  13080. *
  13081. * @param {number} screenWidth - the new width of the screen
  13082. * @param {number} screenHeight - the new height of the screen
  13083. */
  13084. CanvasRenderer.prototype.resize = function resize(screenWidth, screenHeight) {
  13085. _SystemRenderer.prototype.resize.call(this, screenWidth, screenHeight);
  13086. // reset the scale mode.. oddly this seems to be reset when the canvas is resized.
  13087. // surely a browser bug?? Let PixiJS fix that for you..
  13088. if (this.smoothProperty) {
  13089. this.rootContext[this.smoothProperty] = _settings2.default.SCALE_MODE === _const.SCALE_MODES.LINEAR;
  13090. }
  13091. };
  13092. /**
  13093. * Checks if blend mode has changed.
  13094. */
  13095. CanvasRenderer.prototype.invalidateBlendMode = function invalidateBlendMode() {
  13096. this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation);
  13097. };
  13098. return CanvasRenderer;
  13099. }(_SystemRenderer3.default);
  13100. /**
  13101. * Collection of installed plugins. These are included by default in PIXI, but can be excluded
  13102. * by creating a custom build. Consult the README for more information about creating custom
  13103. * builds and excluding plugins.
  13104. * @name PIXI.CanvasRenderer#plugins
  13105. * @type {object}
  13106. * @readonly
  13107. * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements.
  13108. * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer.
  13109. * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events.
  13110. * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects.
  13111. */
  13112. /**
  13113. * Adds a plugin to the renderer.
  13114. *
  13115. * @method PIXI.CanvasRenderer#registerPlugin
  13116. * @param {string} pluginName - The name of the plugin.
  13117. * @param {Function} ctor - The constructor function or class for the plugin.
  13118. */
  13119. exports.default = CanvasRenderer;
  13120. _utils.pluginTarget.mixin(CanvasRenderer);
  13121. }, { "../../const": 46, "../../settings": 101, "../../utils": 125, "../SystemRenderer": 76, "./utils/CanvasMaskManager": 78, "./utils/CanvasRenderTarget": 79, "./utils/mapCanvasBlendModesToPixi": 81 }], 78: [function (require, module, exports) {
  13122. 'use strict';
  13123. exports.__esModule = true;
  13124. var _const = require('../../../const');
  13125. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  13126. /**
  13127. * A set of functions used to handle masking.
  13128. *
  13129. * @class
  13130. * @memberof PIXI
  13131. */
  13132. var CanvasMaskManager = function () {
  13133. /**
  13134. * @param {PIXI.CanvasRenderer} renderer - The canvas renderer.
  13135. */
  13136. function CanvasMaskManager(renderer) {
  13137. _classCallCheck(this, CanvasMaskManager);
  13138. this.renderer = renderer;
  13139. }
  13140. /**
  13141. * This method adds it to the current stack of masks.
  13142. *
  13143. * @param {object} maskData - the maskData that will be pushed
  13144. */
  13145. CanvasMaskManager.prototype.pushMask = function pushMask(maskData) {
  13146. var renderer = this.renderer;
  13147. renderer.context.save();
  13148. var cacheAlpha = maskData.alpha;
  13149. var transform = maskData.transform.worldTransform;
  13150. var resolution = renderer.resolution;
  13151. renderer.context.setTransform(transform.a * resolution, transform.b * resolution, transform.c * resolution, transform.d * resolution, transform.tx * resolution, transform.ty * resolution);
  13152. // TODO suport sprite alpha masks??
  13153. // lots of effort required. If demand is great enough..
  13154. if (!maskData._texture) {
  13155. this.renderGraphicsShape(maskData);
  13156. renderer.context.clip();
  13157. }
  13158. maskData.worldAlpha = cacheAlpha;
  13159. };
  13160. /**
  13161. * Renders a PIXI.Graphics shape.
  13162. *
  13163. * @param {PIXI.Graphics} graphics - The object to render.
  13164. */
  13165. CanvasMaskManager.prototype.renderGraphicsShape = function renderGraphicsShape(graphics) {
  13166. var context = this.renderer.context;
  13167. var len = graphics.graphicsData.length;
  13168. if (len === 0) {
  13169. return;
  13170. }
  13171. context.beginPath();
  13172. for (var i = 0; i < len; i++) {
  13173. var data = graphics.graphicsData[i];
  13174. var shape = data.shape;
  13175. if (data.type === _const.SHAPES.POLY) {
  13176. var points = shape.points;
  13177. context.moveTo(points[0], points[1]);
  13178. for (var j = 1; j < points.length / 2; j++) {
  13179. context.lineTo(points[j * 2], points[j * 2 + 1]);
  13180. }
  13181. // if the first and last point are the same close the path - much neater :)
  13182. if (points[0] === points[points.length - 2] && points[1] === points[points.length - 1]) {
  13183. context.closePath();
  13184. }
  13185. } else if (data.type === _const.SHAPES.RECT) {
  13186. context.rect(shape.x, shape.y, shape.width, shape.height);
  13187. context.closePath();
  13188. } else if (data.type === _const.SHAPES.CIRC) {
  13189. // TODO - need to be Undefined!
  13190. context.arc(shape.x, shape.y, shape.radius, 0, 2 * Math.PI);
  13191. context.closePath();
  13192. } else if (data.type === _const.SHAPES.ELIP) {
  13193. // ellipse code taken from: http://stackoverflow.com/questions/2172798/how-to-draw-an-oval-in-html5-canvas
  13194. var w = shape.width * 2;
  13195. var h = shape.height * 2;
  13196. var x = shape.x - w / 2;
  13197. var y = shape.y - h / 2;
  13198. var kappa = 0.5522848;
  13199. var ox = w / 2 * kappa; // control point offset horizontal
  13200. var oy = h / 2 * kappa; // control point offset vertical
  13201. var xe = x + w; // x-end
  13202. var ye = y + h; // y-end
  13203. var xm = x + w / 2; // x-middle
  13204. var ym = y + h / 2; // y-middle
  13205. context.moveTo(x, ym);
  13206. context.bezierCurveTo(x, ym - oy, xm - ox, y, xm, y);
  13207. context.bezierCurveTo(xm + ox, y, xe, ym - oy, xe, ym);
  13208. context.bezierCurveTo(xe, ym + oy, xm + ox, ye, xm, ye);
  13209. context.bezierCurveTo(xm - ox, ye, x, ym + oy, x, ym);
  13210. context.closePath();
  13211. } else if (data.type === _const.SHAPES.RREC) {
  13212. var rx = shape.x;
  13213. var ry = shape.y;
  13214. var width = shape.width;
  13215. var height = shape.height;
  13216. var radius = shape.radius;
  13217. var maxRadius = Math.min(width, height) / 2 | 0;
  13218. radius = radius > maxRadius ? maxRadius : radius;
  13219. context.moveTo(rx, ry + radius);
  13220. context.lineTo(rx, ry + height - radius);
  13221. context.quadraticCurveTo(rx, ry + height, rx + radius, ry + height);
  13222. context.lineTo(rx + width - radius, ry + height);
  13223. context.quadraticCurveTo(rx + width, ry + height, rx + width, ry + height - radius);
  13224. context.lineTo(rx + width, ry + radius);
  13225. context.quadraticCurveTo(rx + width, ry, rx + width - radius, ry);
  13226. context.lineTo(rx + radius, ry);
  13227. context.quadraticCurveTo(rx, ry, rx, ry + radius);
  13228. context.closePath();
  13229. }
  13230. }
  13231. };
  13232. /**
  13233. * Restores the current drawing context to the state it was before the mask was applied.
  13234. *
  13235. * @param {PIXI.CanvasRenderer} renderer - The renderer context to use.
  13236. */
  13237. CanvasMaskManager.prototype.popMask = function popMask(renderer) {
  13238. renderer.context.restore();
  13239. renderer.invalidateBlendMode();
  13240. };
  13241. /**
  13242. * Destroys this canvas mask manager.
  13243. *
  13244. */
  13245. CanvasMaskManager.prototype.destroy = function destroy() {
  13246. /* empty */
  13247. };
  13248. return CanvasMaskManager;
  13249. }();
  13250. exports.default = CanvasMaskManager;
  13251. }, { "../../../const": 46 }], 79: [function (require, module, exports) {
  13252. 'use strict';
  13253. exports.__esModule = true;
  13254. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  13255. var _settings = require('../../../settings');
  13256. var _settings2 = _interopRequireDefault(_settings);
  13257. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  13258. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  13259. /**
  13260. * Creates a Canvas element of the given size.
  13261. *
  13262. * @class
  13263. * @memberof PIXI
  13264. */
  13265. var CanvasRenderTarget = function () {
  13266. /**
  13267. * @param {number} width - the width for the newly created canvas
  13268. * @param {number} height - the height for the newly created canvas
  13269. * @param {number} [resolution=1] - The resolution / device pixel ratio of the canvas
  13270. */
  13271. function CanvasRenderTarget(width, height, resolution) {
  13272. _classCallCheck(this, CanvasRenderTarget);
  13273. /**
  13274. * The Canvas object that belongs to this CanvasRenderTarget.
  13275. *
  13276. * @member {HTMLCanvasElement}
  13277. */
  13278. this.canvas = document.createElement('canvas');
  13279. /**
  13280. * A CanvasRenderingContext2D object representing a two-dimensional rendering context.
  13281. *
  13282. * @member {CanvasRenderingContext2D}
  13283. */
  13284. this.context = this.canvas.getContext('2d');
  13285. this.resolution = resolution || _settings2.default.RESOLUTION;
  13286. this.resize(width, height);
  13287. }
  13288. /**
  13289. * Clears the canvas that was created by the CanvasRenderTarget class.
  13290. *
  13291. * @private
  13292. */
  13293. CanvasRenderTarget.prototype.clear = function clear() {
  13294. this.context.setTransform(1, 0, 0, 1, 0, 0);
  13295. this.context.clearRect(0, 0, this.canvas.width, this.canvas.height);
  13296. };
  13297. /**
  13298. * Resizes the canvas to the specified width and height.
  13299. *
  13300. * @param {number} width - the new width of the canvas
  13301. * @param {number} height - the new height of the canvas
  13302. */
  13303. CanvasRenderTarget.prototype.resize = function resize(width, height) {
  13304. this.canvas.width = width * this.resolution;
  13305. this.canvas.height = height * this.resolution;
  13306. };
  13307. /**
  13308. * Destroys this canvas.
  13309. *
  13310. */
  13311. CanvasRenderTarget.prototype.destroy = function destroy() {
  13312. this.context = null;
  13313. this.canvas = null;
  13314. };
  13315. /**
  13316. * The width of the canvas buffer in pixels.
  13317. *
  13318. * @member {number}
  13319. */
  13320. _createClass(CanvasRenderTarget, [{
  13321. key: 'width',
  13322. get: function get() {
  13323. return this.canvas.width;
  13324. },
  13325. set: function set(val) // eslint-disable-line require-jsdoc
  13326. {
  13327. this.canvas.width = val;
  13328. }
  13329. /**
  13330. * The height of the canvas buffer in pixels.
  13331. *
  13332. * @member {number}
  13333. */
  13334. }, {
  13335. key: 'height',
  13336. get: function get() {
  13337. return this.canvas.height;
  13338. },
  13339. set: function set(val) // eslint-disable-line require-jsdoc
  13340. {
  13341. this.canvas.height = val;
  13342. }
  13343. }]);
  13344. return CanvasRenderTarget;
  13345. }();
  13346. exports.default = CanvasRenderTarget;
  13347. }, { "../../../settings": 101 }], 80: [function (require, module, exports) {
  13348. 'use strict';
  13349. exports.__esModule = true;
  13350. exports.default = canUseNewCanvasBlendModes;
  13351. /**
  13352. * Creates a little colored canvas
  13353. *
  13354. * @ignore
  13355. * @param {string} color - The color to make the canvas
  13356. * @return {canvas} a small canvas element
  13357. */
  13358. function createColoredCanvas(color) {
  13359. var canvas = document.createElement('canvas');
  13360. canvas.width = 6;
  13361. canvas.height = 1;
  13362. var context = canvas.getContext('2d');
  13363. context.fillStyle = color;
  13364. context.fillRect(0, 0, 6, 1);
  13365. return canvas;
  13366. }
  13367. /**
  13368. * Checks whether the Canvas BlendModes are supported by the current browser
  13369. *
  13370. * @return {boolean} whether they are supported
  13371. */
  13372. function canUseNewCanvasBlendModes() {
  13373. if (typeof document === 'undefined') {
  13374. return false;
  13375. }
  13376. var magenta = createColoredCanvas('#ff00ff');
  13377. var yellow = createColoredCanvas('#ffff00');
  13378. var canvas = document.createElement('canvas');
  13379. canvas.width = 6;
  13380. canvas.height = 1;
  13381. var context = canvas.getContext('2d');
  13382. context.globalCompositeOperation = 'multiply';
  13383. context.drawImage(magenta, 0, 0);
  13384. context.drawImage(yellow, 2, 0);
  13385. var imageData = context.getImageData(2, 0, 1, 1);
  13386. if (!imageData) {
  13387. return false;
  13388. }
  13389. var data = imageData.data;
  13390. return data[0] === 255 && data[1] === 0 && data[2] === 0;
  13391. }
  13392. }, {}], 81: [function (require, module, exports) {
  13393. 'use strict';
  13394. exports.__esModule = true;
  13395. exports.default = mapCanvasBlendModesToPixi;
  13396. var _const = require('../../../const');
  13397. var _canUseNewCanvasBlendModes = require('./canUseNewCanvasBlendModes');
  13398. var _canUseNewCanvasBlendModes2 = _interopRequireDefault(_canUseNewCanvasBlendModes);
  13399. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  13400. /**
  13401. * Maps blend combinations to Canvas.
  13402. *
  13403. * @memberof PIXI
  13404. * @function mapCanvasBlendModesToPixi
  13405. * @private
  13406. * @param {string[]} [array=[]] - The array to output into.
  13407. * @return {string[]} Mapped modes.
  13408. */
  13409. function mapCanvasBlendModesToPixi() {
  13410. var array = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
  13411. if ((0, _canUseNewCanvasBlendModes2.default)()) {
  13412. array[_const.BLEND_MODES.NORMAL] = 'source-over';
  13413. array[_const.BLEND_MODES.ADD] = 'lighter'; // IS THIS OK???
  13414. array[_const.BLEND_MODES.MULTIPLY] = 'multiply';
  13415. array[_const.BLEND_MODES.SCREEN] = 'screen';
  13416. array[_const.BLEND_MODES.OVERLAY] = 'overlay';
  13417. array[_const.BLEND_MODES.DARKEN] = 'darken';
  13418. array[_const.BLEND_MODES.LIGHTEN] = 'lighten';
  13419. array[_const.BLEND_MODES.COLOR_DODGE] = 'color-dodge';
  13420. array[_const.BLEND_MODES.COLOR_BURN] = 'color-burn';
  13421. array[_const.BLEND_MODES.HARD_LIGHT] = 'hard-light';
  13422. array[_const.BLEND_MODES.SOFT_LIGHT] = 'soft-light';
  13423. array[_const.BLEND_MODES.DIFFERENCE] = 'difference';
  13424. array[_const.BLEND_MODES.EXCLUSION] = 'exclusion';
  13425. array[_const.BLEND_MODES.HUE] = 'hue';
  13426. array[_const.BLEND_MODES.SATURATION] = 'saturate';
  13427. array[_const.BLEND_MODES.COLOR] = 'color';
  13428. array[_const.BLEND_MODES.LUMINOSITY] = 'luminosity';
  13429. } else {
  13430. // this means that the browser does not support the cool new blend modes in canvas 'cough' ie 'cough'
  13431. array[_const.BLEND_MODES.NORMAL] = 'source-over';
  13432. array[_const.BLEND_MODES.ADD] = 'lighter'; // IS THIS OK???
  13433. array[_const.BLEND_MODES.MULTIPLY] = 'source-over';
  13434. array[_const.BLEND_MODES.SCREEN] = 'source-over';
  13435. array[_const.BLEND_MODES.OVERLAY] = 'source-over';
  13436. array[_const.BLEND_MODES.DARKEN] = 'source-over';
  13437. array[_const.BLEND_MODES.LIGHTEN] = 'source-over';
  13438. array[_const.BLEND_MODES.COLOR_DODGE] = 'source-over';
  13439. array[_const.BLEND_MODES.COLOR_BURN] = 'source-over';
  13440. array[_const.BLEND_MODES.HARD_LIGHT] = 'source-over';
  13441. array[_const.BLEND_MODES.SOFT_LIGHT] = 'source-over';
  13442. array[_const.BLEND_MODES.DIFFERENCE] = 'source-over';
  13443. array[_const.BLEND_MODES.EXCLUSION] = 'source-over';
  13444. array[_const.BLEND_MODES.HUE] = 'source-over';
  13445. array[_const.BLEND_MODES.SATURATION] = 'source-over';
  13446. array[_const.BLEND_MODES.COLOR] = 'source-over';
  13447. array[_const.BLEND_MODES.LUMINOSITY] = 'source-over';
  13448. }
  13449. // not-premultiplied, only for webgl
  13450. array[_const.BLEND_MODES.NORMAL_NPM] = array[_const.BLEND_MODES.NORMAL];
  13451. array[_const.BLEND_MODES.ADD_NPM] = array[_const.BLEND_MODES.ADD];
  13452. array[_const.BLEND_MODES.SCREEN_NPM] = array[_const.BLEND_MODES.SCREEN];
  13453. return array;
  13454. }
  13455. }, { "../../../const": 46, "./canUseNewCanvasBlendModes": 80 }], 82: [function (require, module, exports) {
  13456. 'use strict';
  13457. exports.__esModule = true;
  13458. var _const = require('../../const');
  13459. var _settings = require('../../settings');
  13460. var _settings2 = _interopRequireDefault(_settings);
  13461. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  13462. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  13463. /**
  13464. * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged
  13465. * up with textures that are no longer being used.
  13466. *
  13467. * @class
  13468. * @memberof PIXI
  13469. */
  13470. var TextureGarbageCollector = function () {
  13471. /**
  13472. * @param {PIXI.WebGLRenderer} renderer - The renderer this manager works for.
  13473. */
  13474. function TextureGarbageCollector(renderer) {
  13475. _classCallCheck(this, TextureGarbageCollector);
  13476. this.renderer = renderer;
  13477. this.count = 0;
  13478. this.checkCount = 0;
  13479. this.maxIdle = _settings2.default.GC_MAX_IDLE;
  13480. this.checkCountMax = _settings2.default.GC_MAX_CHECK_COUNT;
  13481. this.mode = _settings2.default.GC_MODE;
  13482. }
  13483. /**
  13484. * Checks to see when the last time a texture was used
  13485. * if the texture has not been used for a specified amount of time it will be removed from the GPU
  13486. */
  13487. TextureGarbageCollector.prototype.update = function update() {
  13488. this.count++;
  13489. if (this.mode === _const.GC_MODES.MANUAL) {
  13490. return;
  13491. }
  13492. this.checkCount++;
  13493. if (this.checkCount > this.checkCountMax) {
  13494. this.checkCount = 0;
  13495. this.run();
  13496. }
  13497. };
  13498. /**
  13499. * Checks to see when the last time a texture was used
  13500. * if the texture has not been used for a specified amount of time it will be removed from the GPU
  13501. */
  13502. TextureGarbageCollector.prototype.run = function run() {
  13503. var tm = this.renderer.textureManager;
  13504. var managedTextures = tm._managedTextures;
  13505. var wasRemoved = false;
  13506. for (var i = 0; i < managedTextures.length; i++) {
  13507. var texture = managedTextures[i];
  13508. // only supports non generated textures at the moment!
  13509. if (!texture._glRenderTargets && this.count - texture.touched > this.maxIdle) {
  13510. tm.destroyTexture(texture, true);
  13511. managedTextures[i] = null;
  13512. wasRemoved = true;
  13513. }
  13514. }
  13515. if (wasRemoved) {
  13516. var j = 0;
  13517. for (var _i = 0; _i < managedTextures.length; _i++) {
  13518. if (managedTextures[_i] !== null) {
  13519. managedTextures[j++] = managedTextures[_i];
  13520. }
  13521. }
  13522. managedTextures.length = j;
  13523. }
  13524. };
  13525. /**
  13526. * Removes all the textures within the specified displayObject and its children from the GPU
  13527. *
  13528. * @param {PIXI.DisplayObject} displayObject - the displayObject to remove the textures from.
  13529. */
  13530. TextureGarbageCollector.prototype.unload = function unload(displayObject) {
  13531. var tm = this.renderer.textureManager;
  13532. // only destroy non generated textures
  13533. if (displayObject._texture && displayObject._texture._glRenderTargets) {
  13534. tm.destroyTexture(displayObject._texture, true);
  13535. }
  13536. for (var i = displayObject.children.length - 1; i >= 0; i--) {
  13537. this.unload(displayObject.children[i]);
  13538. }
  13539. };
  13540. return TextureGarbageCollector;
  13541. }();
  13542. exports.default = TextureGarbageCollector;
  13543. }, { "../../const": 46, "../../settings": 101 }], 83: [function (require, module, exports) {
  13544. 'use strict';
  13545. exports.__esModule = true;
  13546. var _pixiGlCore = require('pixi-gl-core');
  13547. var _const = require('../../const');
  13548. var _RenderTarget = require('./utils/RenderTarget');
  13549. var _RenderTarget2 = _interopRequireDefault(_RenderTarget);
  13550. var _utils = require('../../utils');
  13551. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  13552. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  13553. /**
  13554. * Helper class to create a webGL Texture
  13555. *
  13556. * @class
  13557. * @memberof PIXI
  13558. */
  13559. var TextureManager = function () {
  13560. /**
  13561. * @param {PIXI.WebGLRenderer} renderer - A reference to the current renderer
  13562. */
  13563. function TextureManager(renderer) {
  13564. _classCallCheck(this, TextureManager);
  13565. /**
  13566. * A reference to the current renderer
  13567. *
  13568. * @member {PIXI.WebGLRenderer}
  13569. */
  13570. this.renderer = renderer;
  13571. /**
  13572. * The current WebGL rendering context
  13573. *
  13574. * @member {WebGLRenderingContext}
  13575. */
  13576. this.gl = renderer.gl;
  13577. /**
  13578. * Track textures in the renderer so we can no longer listen to them on destruction.
  13579. *
  13580. * @member {Array<*>}
  13581. * @private
  13582. */
  13583. this._managedTextures = [];
  13584. }
  13585. /**
  13586. * Binds a texture.
  13587. *
  13588. */
  13589. TextureManager.prototype.bindTexture = function bindTexture() { }
  13590. // empty
  13591. /**
  13592. * Gets a texture.
  13593. *
  13594. */
  13595. ;
  13596. TextureManager.prototype.getTexture = function getTexture() { }
  13597. // empty
  13598. /**
  13599. * Updates and/or Creates a WebGL texture for the renderer's context.
  13600. *
  13601. * @param {PIXI.BaseTexture|PIXI.Texture} texture - the texture to update
  13602. * @param {number} location - the location the texture will be bound to.
  13603. * @return {GLTexture} The gl texture.
  13604. */
  13605. ;
  13606. TextureManager.prototype.updateTexture = function updateTexture(texture, location) {
  13607. // assume it good!
  13608. // texture = texture.baseTexture || texture;
  13609. var gl = this.gl;
  13610. var isRenderTexture = !!texture._glRenderTargets;
  13611. if (!texture.hasLoaded) {
  13612. return null;
  13613. }
  13614. var boundTextures = this.renderer.boundTextures;
  13615. // if the location is undefined then this may have been called by n event.
  13616. // this being the case the texture may already be bound to a slot. As a texture can only be bound once
  13617. // we need to find its current location if it exists.
  13618. if (location === undefined) {
  13619. location = 0;
  13620. // TODO maybe we can use texture bound ids later on...
  13621. // check if texture is already bound..
  13622. for (var i = 0; i < boundTextures.length; ++i) {
  13623. if (boundTextures[i] === texture) {
  13624. location = i;
  13625. break;
  13626. }
  13627. }
  13628. }
  13629. boundTextures[location] = texture;
  13630. gl.activeTexture(gl.TEXTURE0 + location);
  13631. var glTexture = texture._glTextures[this.renderer.CONTEXT_UID];
  13632. if (!glTexture) {
  13633. if (isRenderTexture) {
  13634. var renderTarget = new _RenderTarget2.default(this.gl, texture.width, texture.height, texture.scaleMode, texture.resolution);
  13635. renderTarget.resize(texture.width, texture.height);
  13636. texture._glRenderTargets[this.renderer.CONTEXT_UID] = renderTarget;
  13637. glTexture = renderTarget.texture;
  13638. } else {
  13639. glTexture = new _pixiGlCore.GLTexture(this.gl, null, null, null, null);
  13640. glTexture.bind(location);
  13641. glTexture.premultiplyAlpha = true;
  13642. glTexture.upload(texture.source);
  13643. }
  13644. texture._glTextures[this.renderer.CONTEXT_UID] = glTexture;
  13645. texture.on('update', this.updateTexture, this);
  13646. texture.on('dispose', this.destroyTexture, this);
  13647. this._managedTextures.push(texture);
  13648. if (texture.isPowerOfTwo) {
  13649. if (texture.mipmap) {
  13650. glTexture.enableMipmap();
  13651. }
  13652. if (texture.wrapMode === _const.WRAP_MODES.CLAMP) {
  13653. glTexture.enableWrapClamp();
  13654. } else if (texture.wrapMode === _const.WRAP_MODES.REPEAT) {
  13655. glTexture.enableWrapRepeat();
  13656. } else {
  13657. glTexture.enableWrapMirrorRepeat();
  13658. }
  13659. } else {
  13660. glTexture.enableWrapClamp();
  13661. }
  13662. if (texture.scaleMode === _const.SCALE_MODES.NEAREST) {
  13663. glTexture.enableNearestScaling();
  13664. } else {
  13665. glTexture.enableLinearScaling();
  13666. }
  13667. }
  13668. // the texture already exists so we only need to update it..
  13669. else if (isRenderTexture) {
  13670. texture._glRenderTargets[this.renderer.CONTEXT_UID].resize(texture.width, texture.height);
  13671. } else {
  13672. glTexture.upload(texture.source);
  13673. }
  13674. return glTexture;
  13675. };
  13676. /**
  13677. * Deletes the texture from WebGL
  13678. *
  13679. * @param {PIXI.BaseTexture|PIXI.Texture} texture - the texture to destroy
  13680. * @param {boolean} [skipRemove=false] - Whether to skip removing the texture from the TextureManager.
  13681. */
  13682. TextureManager.prototype.destroyTexture = function destroyTexture(texture, skipRemove) {
  13683. texture = texture.baseTexture || texture;
  13684. if (!texture.hasLoaded) {
  13685. return;
  13686. }
  13687. var uid = this.renderer.CONTEXT_UID;
  13688. var glTextures = texture._glTextures;
  13689. var glRenderTargets = texture._glRenderTargets;
  13690. if (glTextures[uid]) {
  13691. this.renderer.unbindTexture(texture);
  13692. glTextures[uid].destroy();
  13693. texture.off('update', this.updateTexture, this);
  13694. texture.off('dispose', this.destroyTexture, this);
  13695. delete glTextures[uid];
  13696. if (!skipRemove) {
  13697. var i = this._managedTextures.indexOf(texture);
  13698. if (i !== -1) {
  13699. (0, _utils.removeItems)(this._managedTextures, i, 1);
  13700. }
  13701. }
  13702. }
  13703. if (glRenderTargets && glRenderTargets[uid]) {
  13704. glRenderTargets[uid].destroy();
  13705. delete glRenderTargets[uid];
  13706. }
  13707. };
  13708. /**
  13709. * Deletes all the textures from WebGL
  13710. */
  13711. TextureManager.prototype.removeAll = function removeAll() {
  13712. // empty all the old gl textures as they are useless now
  13713. for (var i = 0; i < this._managedTextures.length; ++i) {
  13714. var texture = this._managedTextures[i];
  13715. if (texture._glTextures[this.renderer.CONTEXT_UID]) {
  13716. delete texture._glTextures[this.renderer.CONTEXT_UID];
  13717. }
  13718. }
  13719. };
  13720. /**
  13721. * Destroys this manager and removes all its textures
  13722. */
  13723. TextureManager.prototype.destroy = function destroy() {
  13724. // destroy managed textures
  13725. for (var i = 0; i < this._managedTextures.length; ++i) {
  13726. var texture = this._managedTextures[i];
  13727. this.destroyTexture(texture, true);
  13728. texture.off('update', this.updateTexture, this);
  13729. texture.off('dispose', this.destroyTexture, this);
  13730. }
  13731. this._managedTextures = null;
  13732. };
  13733. return TextureManager;
  13734. }();
  13735. exports.default = TextureManager;
  13736. }, { "../../const": 46, "../../utils": 125, "./utils/RenderTarget": 96, "pixi-gl-core": 15 }], 84: [function (require, module, exports) {
  13737. 'use strict';
  13738. exports.__esModule = true;
  13739. var _SystemRenderer2 = require('../SystemRenderer');
  13740. var _SystemRenderer3 = _interopRequireDefault(_SystemRenderer2);
  13741. var _MaskManager = require('./managers/MaskManager');
  13742. var _MaskManager2 = _interopRequireDefault(_MaskManager);
  13743. var _StencilManager = require('./managers/StencilManager');
  13744. var _StencilManager2 = _interopRequireDefault(_StencilManager);
  13745. var _FilterManager = require('./managers/FilterManager');
  13746. var _FilterManager2 = _interopRequireDefault(_FilterManager);
  13747. var _RenderTarget = require('./utils/RenderTarget');
  13748. var _RenderTarget2 = _interopRequireDefault(_RenderTarget);
  13749. var _ObjectRenderer = require('./utils/ObjectRenderer');
  13750. var _ObjectRenderer2 = _interopRequireDefault(_ObjectRenderer);
  13751. var _TextureManager = require('./TextureManager');
  13752. var _TextureManager2 = _interopRequireDefault(_TextureManager);
  13753. var _BaseTexture = require('../../textures/BaseTexture');
  13754. var _BaseTexture2 = _interopRequireDefault(_BaseTexture);
  13755. var _TextureGarbageCollector = require('./TextureGarbageCollector');
  13756. var _TextureGarbageCollector2 = _interopRequireDefault(_TextureGarbageCollector);
  13757. var _WebGLState = require('./WebGLState');
  13758. var _WebGLState2 = _interopRequireDefault(_WebGLState);
  13759. var _mapWebGLDrawModesToPixi = require('./utils/mapWebGLDrawModesToPixi');
  13760. var _mapWebGLDrawModesToPixi2 = _interopRequireDefault(_mapWebGLDrawModesToPixi);
  13761. var _validateContext = require('./utils/validateContext');
  13762. var _validateContext2 = _interopRequireDefault(_validateContext);
  13763. var _utils = require('../../utils');
  13764. var _pixiGlCore = require('pixi-gl-core');
  13765. var _pixiGlCore2 = _interopRequireDefault(_pixiGlCore);
  13766. var _const = require('../../const');
  13767. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  13768. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  13769. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  13770. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  13771. var CONTEXT_UID = 0;
  13772. /**
  13773. * The WebGLRenderer draws the scene and all its content onto a webGL enabled canvas. This renderer
  13774. * should be used for browsers that support webGL. This Render works by automatically managing webGLBatchs.
  13775. * So no need for Sprite Batches or Sprite Clouds.
  13776. * Don't forget to add the view to your DOM or you will not see anything :)
  13777. *
  13778. * @class
  13779. * @memberof PIXI
  13780. * @extends PIXI.SystemRenderer
  13781. */
  13782. var WebGLRenderer = function (_SystemRenderer) {
  13783. _inherits(WebGLRenderer, _SystemRenderer);
  13784. // eslint-disable-next-line valid-jsdoc
  13785. /**
  13786. *
  13787. * @param {object} [options] - The optional renderer parameters
  13788. * @param {number} [options.width=800] - the width of the screen
  13789. * @param {number} [options.height=600] - the height of the screen
  13790. * @param {HTMLCanvasElement} [options.view] - the canvas to use as a view, optional
  13791. * @param {boolean} [options.transparent=false] - If the render view is transparent, default false
  13792. * @param {boolean} [options.autoResize=false] - If the render view is automatically resized, default false
  13793. * @param {boolean} [options.antialias=false] - sets antialias. If not available natively then FXAA
  13794. * antialiasing is used
  13795. * @param {boolean} [options.forceFXAA=false] - forces FXAA antialiasing to be used over native.
  13796. * FXAA is faster, but may not always look as great
  13797. * @param {number} [options.resolution=1] - The resolution / device pixel ratio of the renderer.
  13798. * The resolution of the renderer retina would be 2.
  13799. * @param {boolean} [options.clearBeforeRender=true] - This sets if the renderer will clear
  13800. * the canvas or not before the new render pass. If you wish to set this to false, you *must* set
  13801. * preserveDrawingBuffer to `true`.
  13802. * @param {boolean} [options.preserveDrawingBuffer=false] - enables drawing buffer preservation,
  13803. * enable this if you need to call toDataUrl on the webgl context.
  13804. * @param {boolean} [options.roundPixels=false] - If true PixiJS will Math.floor() x/y values when
  13805. * rendering, stopping pixel interpolation.
  13806. * @param {number} [options.backgroundColor=0x000000] - The background color of the rendered area
  13807. * (shown if not transparent).
  13808. * @param {boolean} [options.legacy=false] - If true PixiJS will aim to ensure compatibility
  13809. * with older / less advanced devices. If you experiance unexplained flickering try setting this to true.
  13810. * @param {string} [options.powerPreference] - Parameter passed to webgl context, set to "high-performance"
  13811. * for devices with dual graphics card
  13812. */
  13813. function WebGLRenderer(options, arg2, arg3) {
  13814. _classCallCheck(this, WebGLRenderer);
  13815. var _this = _possibleConstructorReturn(this, _SystemRenderer.call(this, 'WebGL', options, arg2, arg3));
  13816. _this.legacy = _this.options.legacy;
  13817. if (_this.legacy) {
  13818. _pixiGlCore2.default.VertexArrayObject.FORCE_NATIVE = true;
  13819. }
  13820. /**
  13821. * The type of this renderer as a standardised const
  13822. *
  13823. * @member {number}
  13824. * @see PIXI.RENDERER_TYPE
  13825. */
  13826. _this.type = _const.RENDERER_TYPE.WEBGL;
  13827. _this.handleContextLost = _this.handleContextLost.bind(_this);
  13828. _this.handleContextRestored = _this.handleContextRestored.bind(_this);
  13829. _this.view.addEventListener('webglcontextlost', _this.handleContextLost, false);
  13830. _this.view.addEventListener('webglcontextrestored', _this.handleContextRestored, false);
  13831. /**
  13832. * The options passed in to create a new webgl context.
  13833. *
  13834. * @member {object}
  13835. * @private
  13836. */
  13837. _this._contextOptions = {
  13838. alpha: _this.transparent,
  13839. antialias: _this.options.antialias,
  13840. premultipliedAlpha: _this.transparent && _this.transparent !== 'notMultiplied',
  13841. stencil: true,
  13842. preserveDrawingBuffer: _this.options.preserveDrawingBuffer,
  13843. powerPreference: _this.options.powerPreference
  13844. };
  13845. _this._backgroundColorRgba[3] = _this.transparent ? 0 : 1;
  13846. /**
  13847. * Manages the masks using the stencil buffer.
  13848. *
  13849. * @member {PIXI.MaskManager}
  13850. */
  13851. _this.maskManager = new _MaskManager2.default(_this);
  13852. /**
  13853. * Manages the stencil buffer.
  13854. *
  13855. * @member {PIXI.StencilManager}
  13856. */
  13857. _this.stencilManager = new _StencilManager2.default(_this);
  13858. /**
  13859. * An empty renderer.
  13860. *
  13861. * @member {PIXI.ObjectRenderer}
  13862. */
  13863. _this.emptyRenderer = new _ObjectRenderer2.default(_this);
  13864. /**
  13865. * The currently active ObjectRenderer.
  13866. *
  13867. * @member {PIXI.ObjectRenderer}
  13868. */
  13869. _this.currentRenderer = _this.emptyRenderer;
  13870. /**
  13871. * Manages textures
  13872. * @member {PIXI.TextureManager}
  13873. */
  13874. _this.textureManager = null;
  13875. /**
  13876. * Manages the filters.
  13877. *
  13878. * @member {PIXI.FilterManager}
  13879. */
  13880. _this.filterManager = null;
  13881. _this.initPlugins();
  13882. /**
  13883. * The current WebGL rendering context, it is created here
  13884. *
  13885. * @member {WebGLRenderingContext}
  13886. */
  13887. // initialize the context so it is ready for the managers.
  13888. if (_this.options.context) {
  13889. // checks to see if a context is valid..
  13890. (0, _validateContext2.default)(_this.options.context);
  13891. }
  13892. _this.gl = _this.options.context || _pixiGlCore2.default.createContext(_this.view, _this._contextOptions);
  13893. _this.CONTEXT_UID = CONTEXT_UID++;
  13894. /**
  13895. * The currently active ObjectRenderer.
  13896. *
  13897. * @member {PIXI.WebGLState}
  13898. */
  13899. _this.state = new _WebGLState2.default(_this.gl);
  13900. _this.renderingToScreen = true;
  13901. /**
  13902. * Holds the current state of textures bound to the GPU.
  13903. * @type {Array}
  13904. */
  13905. _this.boundTextures = null;
  13906. /**
  13907. * Holds the current shader
  13908. *
  13909. * @member {PIXI.Shader}
  13910. */
  13911. _this._activeShader = null;
  13912. _this._activeVao = null;
  13913. /**
  13914. * Holds the current render target
  13915. *
  13916. * @member {PIXI.RenderTarget}
  13917. */
  13918. _this._activeRenderTarget = null;
  13919. _this._initContext();
  13920. // map some webGL blend and drawmodes..
  13921. _this.drawModes = (0, _mapWebGLDrawModesToPixi2.default)(_this.gl);
  13922. _this._nextTextureLocation = 0;
  13923. _this.setBlendMode(0);
  13924. /**
  13925. * Fired after rendering finishes.
  13926. *
  13927. * @event PIXI.WebGLRenderer#postrender
  13928. */
  13929. /**
  13930. * Fired before rendering starts.
  13931. *
  13932. * @event PIXI.WebGLRenderer#prerender
  13933. */
  13934. /**
  13935. * Fired when the WebGL context is set.
  13936. *
  13937. * @event PIXI.WebGLRenderer#context
  13938. * @param {WebGLRenderingContext} gl - WebGL context.
  13939. */
  13940. return _this;
  13941. }
  13942. /**
  13943. * Creates the WebGL context
  13944. *
  13945. * @private
  13946. */
  13947. WebGLRenderer.prototype._initContext = function _initContext() {
  13948. var gl = this.gl;
  13949. // restore a context if it was previously lost
  13950. if (gl.isContextLost() && gl.getExtension('WEBGL_lose_context')) {
  13951. gl.getExtension('WEBGL_lose_context').restoreContext();
  13952. }
  13953. var maxTextures = gl.getParameter(gl.MAX_TEXTURE_IMAGE_UNITS);
  13954. this._activeShader = null;
  13955. this._activeVao = null;
  13956. this.boundTextures = new Array(maxTextures);
  13957. this.emptyTextures = new Array(maxTextures);
  13958. // create a texture manager...
  13959. this.textureManager = new _TextureManager2.default(this);
  13960. this.filterManager = new _FilterManager2.default(this);
  13961. this.textureGC = new _TextureGarbageCollector2.default(this);
  13962. this.state.resetToDefault();
  13963. this.rootRenderTarget = new _RenderTarget2.default(gl, this.width, this.height, null, this.resolution, true);
  13964. this.rootRenderTarget.clearColor = this._backgroundColorRgba;
  13965. this.bindRenderTarget(this.rootRenderTarget);
  13966. // now lets fill up the textures with empty ones!
  13967. var emptyGLTexture = new _pixiGlCore2.default.GLTexture.fromData(gl, null, 1, 1);
  13968. var tempObj = { _glTextures: {} };
  13969. tempObj._glTextures[this.CONTEXT_UID] = {};
  13970. for (var i = 0; i < maxTextures; i++) {
  13971. var empty = new _BaseTexture2.default();
  13972. empty._glTextures[this.CONTEXT_UID] = emptyGLTexture;
  13973. this.boundTextures[i] = tempObj;
  13974. this.emptyTextures[i] = empty;
  13975. this.bindTexture(null, i);
  13976. }
  13977. this.emit('context', gl);
  13978. // setup the width/height properties and gl viewport
  13979. this.resize(this.screen.width, this.screen.height);
  13980. };
  13981. /**
  13982. * Renders the object to its webGL view
  13983. *
  13984. * @param {PIXI.DisplayObject} displayObject - the object to be rendered
  13985. * @param {PIXI.RenderTexture} renderTexture - The render texture to render to.
  13986. * @param {boolean} [clear] - Should the canvas be cleared before the new render
  13987. * @param {PIXI.Transform} [transform] - A transform to apply to the render texture before rendering.
  13988. * @param {boolean} [skipUpdateTransform] - Should we skip the update transform pass?
  13989. */
  13990. WebGLRenderer.prototype.render = function render(displayObject, renderTexture, clear, transform, skipUpdateTransform) {
  13991. // can be handy to know!
  13992. this.renderingToScreen = !renderTexture;
  13993. this.emit('prerender');
  13994. // no point rendering if our context has been blown up!
  13995. if (!this.gl || this.gl.isContextLost()) {
  13996. return;
  13997. }
  13998. this._nextTextureLocation = 0;
  13999. if (!renderTexture) {
  14000. this._lastObjectRendered = displayObject;
  14001. }
  14002. if (!skipUpdateTransform) {
  14003. // update the scene graph
  14004. var cacheParent = displayObject.parent;
  14005. displayObject.parent = this._tempDisplayObjectParent;
  14006. displayObject.updateTransform();
  14007. displayObject.parent = cacheParent;
  14008. // displayObject.hitArea = //TODO add a temp hit area
  14009. }
  14010. this.bindRenderTexture(renderTexture, transform);
  14011. this.currentRenderer.start();
  14012. if (clear !== undefined ? clear : this.clearBeforeRender) {
  14013. this._activeRenderTarget.clear();
  14014. }
  14015. displayObject.renderWebGL(this);
  14016. // apply transform..
  14017. this.currentRenderer.flush();
  14018. // this.setObjectRenderer(this.emptyRenderer);
  14019. this.textureGC.update();
  14020. this.emit('postrender');
  14021. };
  14022. /**
  14023. * Changes the current renderer to the one given in parameter
  14024. *
  14025. * @param {PIXI.ObjectRenderer} objectRenderer - The object renderer to use.
  14026. */
  14027. WebGLRenderer.prototype.setObjectRenderer = function setObjectRenderer(objectRenderer) {
  14028. if (this.currentRenderer === objectRenderer) {
  14029. return;
  14030. }
  14031. this.currentRenderer.stop();
  14032. this.currentRenderer = objectRenderer;
  14033. this.currentRenderer.start();
  14034. };
  14035. /**
  14036. * This should be called if you wish to do some custom rendering
  14037. * It will basically render anything that may be batched up such as sprites
  14038. *
  14039. */
  14040. WebGLRenderer.prototype.flush = function flush() {
  14041. this.setObjectRenderer(this.emptyRenderer);
  14042. };
  14043. /**
  14044. * Resizes the webGL view to the specified width and height.
  14045. *
  14046. * @param {number} screenWidth - the new width of the screen
  14047. * @param {number} screenHeight - the new height of the screen
  14048. */
  14049. WebGLRenderer.prototype.resize = function resize(screenWidth, screenHeight) {
  14050. // if(width * this.resolution === this.width && height * this.resolution === this.height)return;
  14051. _SystemRenderer3.default.prototype.resize.call(this, screenWidth, screenHeight);
  14052. this.rootRenderTarget.resize(screenWidth, screenHeight);
  14053. if (this._activeRenderTarget === this.rootRenderTarget) {
  14054. this.rootRenderTarget.activate();
  14055. if (this._activeShader) {
  14056. this._activeShader.uniforms.projectionMatrix = this.rootRenderTarget.projectionMatrix.toArray(true);
  14057. }
  14058. }
  14059. };
  14060. /**
  14061. * Resizes the webGL view to the specified width and height.
  14062. *
  14063. * @param {number} blendMode - the desired blend mode
  14064. */
  14065. WebGLRenderer.prototype.setBlendMode = function setBlendMode(blendMode) {
  14066. this.state.setBlendMode(blendMode);
  14067. };
  14068. /**
  14069. * Erases the active render target and fills the drawing area with a colour
  14070. *
  14071. * @param {number} [clearColor] - The colour
  14072. */
  14073. WebGLRenderer.prototype.clear = function clear(clearColor) {
  14074. this._activeRenderTarget.clear(clearColor);
  14075. };
  14076. /**
  14077. * Sets the transform of the active render target to the given matrix
  14078. *
  14079. * @param {PIXI.Matrix} matrix - The transformation matrix
  14080. */
  14081. WebGLRenderer.prototype.setTransform = function setTransform(matrix) {
  14082. this._activeRenderTarget.transform = matrix;
  14083. };
  14084. /**
  14085. * Erases the render texture and fills the drawing area with a colour
  14086. *
  14087. * @param {PIXI.RenderTexture} renderTexture - The render texture to clear
  14088. * @param {number} [clearColor] - The colour
  14089. * @return {PIXI.WebGLRenderer} Returns itself.
  14090. */
  14091. WebGLRenderer.prototype.clearRenderTexture = function clearRenderTexture(renderTexture, clearColor) {
  14092. var baseTexture = renderTexture.baseTexture;
  14093. var renderTarget = baseTexture._glRenderTargets[this.CONTEXT_UID];
  14094. if (renderTarget) {
  14095. renderTarget.clear(clearColor);
  14096. }
  14097. return this;
  14098. };
  14099. /**
  14100. * Binds a render texture for rendering
  14101. *
  14102. * @param {PIXI.RenderTexture} renderTexture - The render texture to render
  14103. * @param {PIXI.Transform} transform - The transform to be applied to the render texture
  14104. * @return {PIXI.WebGLRenderer} Returns itself.
  14105. */
  14106. WebGLRenderer.prototype.bindRenderTexture = function bindRenderTexture(renderTexture, transform) {
  14107. var renderTarget = void 0;
  14108. if (renderTexture) {
  14109. var baseTexture = renderTexture.baseTexture;
  14110. if (!baseTexture._glRenderTargets[this.CONTEXT_UID]) {
  14111. // bind the current texture
  14112. this.textureManager.updateTexture(baseTexture, 0);
  14113. }
  14114. this.unbindTexture(baseTexture);
  14115. renderTarget = baseTexture._glRenderTargets[this.CONTEXT_UID];
  14116. renderTarget.setFrame(renderTexture.frame);
  14117. } else {
  14118. renderTarget = this.rootRenderTarget;
  14119. }
  14120. renderTarget.transform = transform;
  14121. this.bindRenderTarget(renderTarget);
  14122. return this;
  14123. };
  14124. /**
  14125. * Changes the current render target to the one given in parameter
  14126. *
  14127. * @param {PIXI.RenderTarget} renderTarget - the new render target
  14128. * @return {PIXI.WebGLRenderer} Returns itself.
  14129. */
  14130. WebGLRenderer.prototype.bindRenderTarget = function bindRenderTarget(renderTarget) {
  14131. if (renderTarget !== this._activeRenderTarget) {
  14132. this._activeRenderTarget = renderTarget;
  14133. renderTarget.activate();
  14134. if (this._activeShader) {
  14135. this._activeShader.uniforms.projectionMatrix = renderTarget.projectionMatrix.toArray(true);
  14136. }
  14137. this.stencilManager.setMaskStack(renderTarget.stencilMaskStack);
  14138. }
  14139. return this;
  14140. };
  14141. /**
  14142. * Changes the current shader to the one given in parameter
  14143. *
  14144. * @param {PIXI.Shader} shader - the new shader
  14145. * @param {boolean} [autoProject=true] - Whether automatically set the projection matrix
  14146. * @return {PIXI.WebGLRenderer} Returns itself.
  14147. */
  14148. WebGLRenderer.prototype.bindShader = function bindShader(shader, autoProject) {
  14149. // TODO cache
  14150. if (this._activeShader !== shader) {
  14151. this._activeShader = shader;
  14152. shader.bind();
  14153. // `autoProject` normally would be a default parameter set to true
  14154. // but because of how Babel transpiles default parameters
  14155. // it hinders the performance of this method.
  14156. if (autoProject !== false) {
  14157. // automatically set the projection matrix
  14158. shader.uniforms.projectionMatrix = this._activeRenderTarget.projectionMatrix.toArray(true);
  14159. }
  14160. }
  14161. return this;
  14162. };
  14163. /**
  14164. * Binds the texture. This will return the location of the bound texture.
  14165. * It may not be the same as the one you pass in. This is due to optimisation that prevents
  14166. * needless binding of textures. For example if the texture is already bound it will return the
  14167. * current location of the texture instead of the one provided. To bypass this use force location
  14168. *
  14169. * @param {PIXI.Texture} texture - the new texture
  14170. * @param {number} location - the suggested texture location
  14171. * @param {boolean} forceLocation - force the location
  14172. * @return {number} bound texture location
  14173. */
  14174. WebGLRenderer.prototype.bindTexture = function bindTexture(texture, location, forceLocation) {
  14175. texture = texture || this.emptyTextures[location];
  14176. texture = texture.baseTexture || texture;
  14177. texture.touched = this.textureGC.count;
  14178. if (!forceLocation) {
  14179. // TODO - maybe look into adding boundIds.. save us the loop?
  14180. for (var i = 0; i < this.boundTextures.length; i++) {
  14181. if (this.boundTextures[i] === texture) {
  14182. return i;
  14183. }
  14184. }
  14185. if (location === undefined) {
  14186. this._nextTextureLocation++;
  14187. this._nextTextureLocation %= this.boundTextures.length;
  14188. location = this.boundTextures.length - this._nextTextureLocation - 1;
  14189. }
  14190. } else {
  14191. location = location || 0;
  14192. }
  14193. var gl = this.gl;
  14194. var glTexture = texture._glTextures[this.CONTEXT_UID];
  14195. if (!glTexture) {
  14196. // this will also bind the texture..
  14197. this.textureManager.updateTexture(texture, location);
  14198. } else {
  14199. // bind the current texture
  14200. this.boundTextures[location] = texture;
  14201. gl.activeTexture(gl.TEXTURE0 + location);
  14202. gl.bindTexture(gl.TEXTURE_2D, glTexture.texture);
  14203. }
  14204. return location;
  14205. };
  14206. /**
  14207. * unbinds the texture ...
  14208. *
  14209. * @param {PIXI.Texture} texture - the texture to unbind
  14210. * @return {PIXI.WebGLRenderer} Returns itself.
  14211. */
  14212. WebGLRenderer.prototype.unbindTexture = function unbindTexture(texture) {
  14213. var gl = this.gl;
  14214. texture = texture.baseTexture || texture;
  14215. for (var i = 0; i < this.boundTextures.length; i++) {
  14216. if (this.boundTextures[i] === texture) {
  14217. this.boundTextures[i] = this.emptyTextures[i];
  14218. gl.activeTexture(gl.TEXTURE0 + i);
  14219. gl.bindTexture(gl.TEXTURE_2D, this.emptyTextures[i]._glTextures[this.CONTEXT_UID].texture);
  14220. }
  14221. }
  14222. return this;
  14223. };
  14224. /**
  14225. * Creates a new VAO from this renderer's context and state.
  14226. *
  14227. * @return {VertexArrayObject} The new VAO.
  14228. */
  14229. WebGLRenderer.prototype.createVao = function createVao() {
  14230. return new _pixiGlCore2.default.VertexArrayObject(this.gl, this.state.attribState);
  14231. };
  14232. /**
  14233. * Changes the current Vao to the one given in parameter
  14234. *
  14235. * @param {PIXI.VertexArrayObject} vao - the new Vao
  14236. * @return {PIXI.WebGLRenderer} Returns itself.
  14237. */
  14238. WebGLRenderer.prototype.bindVao = function bindVao(vao) {
  14239. if (this._activeVao === vao) {
  14240. return this;
  14241. }
  14242. if (vao) {
  14243. vao.bind();
  14244. } else if (this._activeVao) {
  14245. // TODO this should always be true i think?
  14246. this._activeVao.unbind();
  14247. }
  14248. this._activeVao = vao;
  14249. return this;
  14250. };
  14251. /**
  14252. * Resets the WebGL state so you can render things however you fancy!
  14253. *
  14254. * @return {PIXI.WebGLRenderer} Returns itself.
  14255. */
  14256. WebGLRenderer.prototype.reset = function reset() {
  14257. this.setObjectRenderer(this.emptyRenderer);
  14258. this.bindVao(null);
  14259. this._activeShader = null;
  14260. this._activeRenderTarget = this.rootRenderTarget;
  14261. for (var i = 0; i < this.boundTextures.length; i++) {
  14262. this.boundTextures[i] = this.emptyTextures[i];
  14263. }
  14264. // bind the main frame buffer (the screen);
  14265. this.rootRenderTarget.activate();
  14266. this.state.resetToDefault();
  14267. return this;
  14268. };
  14269. /**
  14270. * Handles a lost webgl context
  14271. *
  14272. * @private
  14273. * @param {WebGLContextEvent} event - The context lost event.
  14274. */
  14275. WebGLRenderer.prototype.handleContextLost = function handleContextLost(event) {
  14276. event.preventDefault();
  14277. };
  14278. /**
  14279. * Handles a restored webgl context
  14280. *
  14281. * @private
  14282. */
  14283. WebGLRenderer.prototype.handleContextRestored = function handleContextRestored() {
  14284. this.textureManager.removeAll();
  14285. this.filterManager.destroy(true);
  14286. this._initContext();
  14287. };
  14288. /**
  14289. * Removes everything from the renderer (event listeners, spritebatch, etc...)
  14290. *
  14291. * @param {boolean} [removeView=false] - Removes the Canvas element from the DOM.
  14292. * See: https://github.com/pixijs/pixi.js/issues/2233
  14293. */
  14294. WebGLRenderer.prototype.destroy = function destroy(removeView) {
  14295. this.destroyPlugins();
  14296. // remove listeners
  14297. this.view.removeEventListener('webglcontextlost', this.handleContextLost);
  14298. this.view.removeEventListener('webglcontextrestored', this.handleContextRestored);
  14299. this.textureManager.destroy();
  14300. // call base destroy
  14301. _SystemRenderer.prototype.destroy.call(this, removeView);
  14302. this.uid = 0;
  14303. // destroy the managers
  14304. this.maskManager.destroy();
  14305. this.stencilManager.destroy();
  14306. this.filterManager.destroy();
  14307. this.maskManager = null;
  14308. this.filterManager = null;
  14309. this.textureManager = null;
  14310. this.currentRenderer = null;
  14311. this.handleContextLost = null;
  14312. this.handleContextRestored = null;
  14313. this._contextOptions = null;
  14314. this.gl.useProgram(null);
  14315. if (this.gl.getExtension('WEBGL_lose_context')) {
  14316. this.gl.getExtension('WEBGL_lose_context').loseContext();
  14317. }
  14318. this.gl = null;
  14319. // this = null;
  14320. };
  14321. return WebGLRenderer;
  14322. }(_SystemRenderer3.default);
  14323. /**
  14324. * Collection of installed plugins. These are included by default in PIXI, but can be excluded
  14325. * by creating a custom build. Consult the README for more information about creating custom
  14326. * builds and excluding plugins.
  14327. * @name PIXI.WebGLRenderer#plugins
  14328. * @type {object}
  14329. * @readonly
  14330. * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements.
  14331. * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer.
  14332. * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events.
  14333. * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects.
  14334. */
  14335. /**
  14336. * Adds a plugin to the renderer.
  14337. *
  14338. * @method PIXI.WebGLRenderer#registerPlugin
  14339. * @param {string} pluginName - The name of the plugin.
  14340. * @param {Function} ctor - The constructor function or class for the plugin.
  14341. */
  14342. exports.default = WebGLRenderer;
  14343. _utils.pluginTarget.mixin(WebGLRenderer);
  14344. }, { "../../const": 46, "../../textures/BaseTexture": 112, "../../utils": 125, "../SystemRenderer": 76, "./TextureGarbageCollector": 82, "./TextureManager": 83, "./WebGLState": 85, "./managers/FilterManager": 90, "./managers/MaskManager": 91, "./managers/StencilManager": 92, "./utils/ObjectRenderer": 94, "./utils/RenderTarget": 96, "./utils/mapWebGLDrawModesToPixi": 99, "./utils/validateContext": 100, "pixi-gl-core": 15 }], 85: [function (require, module, exports) {
  14345. 'use strict';
  14346. exports.__esModule = true;
  14347. var _mapWebGLBlendModesToPixi = require('./utils/mapWebGLBlendModesToPixi');
  14348. var _mapWebGLBlendModesToPixi2 = _interopRequireDefault(_mapWebGLBlendModesToPixi);
  14349. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  14350. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  14351. var BLEND = 0;
  14352. var DEPTH_TEST = 1;
  14353. var FRONT_FACE = 2;
  14354. var CULL_FACE = 3;
  14355. var BLEND_FUNC = 4;
  14356. /**
  14357. * A WebGL state machines
  14358. *
  14359. * @memberof PIXI
  14360. * @class
  14361. */
  14362. var WebGLState = function () {
  14363. /**
  14364. * @param {WebGLRenderingContext} gl - The current WebGL rendering context
  14365. */
  14366. function WebGLState(gl) {
  14367. _classCallCheck(this, WebGLState);
  14368. /**
  14369. * The current active state
  14370. *
  14371. * @member {Uint8Array}
  14372. */
  14373. this.activeState = new Uint8Array(16);
  14374. /**
  14375. * The default state
  14376. *
  14377. * @member {Uint8Array}
  14378. */
  14379. this.defaultState = new Uint8Array(16);
  14380. // default blend mode..
  14381. this.defaultState[0] = 1;
  14382. /**
  14383. * The current state index in the stack
  14384. *
  14385. * @member {number}
  14386. * @private
  14387. */
  14388. this.stackIndex = 0;
  14389. /**
  14390. * The stack holding all the different states
  14391. *
  14392. * @member {Array<*>}
  14393. * @private
  14394. */
  14395. this.stack = [];
  14396. /**
  14397. * The current WebGL rendering context
  14398. *
  14399. * @member {WebGLRenderingContext}
  14400. */
  14401. this.gl = gl;
  14402. this.maxAttribs = gl.getParameter(gl.MAX_VERTEX_ATTRIBS);
  14403. this.attribState = {
  14404. tempAttribState: new Array(this.maxAttribs),
  14405. attribState: new Array(this.maxAttribs)
  14406. };
  14407. this.blendModes = (0, _mapWebGLBlendModesToPixi2.default)(gl);
  14408. // check we have vao..
  14409. this.nativeVaoExtension = gl.getExtension('OES_vertex_array_object') || gl.getExtension('MOZ_OES_vertex_array_object') || gl.getExtension('WEBKIT_OES_vertex_array_object');
  14410. }
  14411. /**
  14412. * Pushes a new active state
  14413. */
  14414. WebGLState.prototype.push = function push() {
  14415. // next state..
  14416. var state = this.stack[this.stackIndex];
  14417. if (!state) {
  14418. state = this.stack[this.stackIndex] = new Uint8Array(16);
  14419. }
  14420. ++this.stackIndex;
  14421. // copy state..
  14422. // set active state so we can force overrides of gl state
  14423. for (var i = 0; i < this.activeState.length; i++) {
  14424. state[i] = this.activeState[i];
  14425. }
  14426. };
  14427. /**
  14428. * Pops a state out
  14429. */
  14430. WebGLState.prototype.pop = function pop() {
  14431. var state = this.stack[--this.stackIndex];
  14432. this.setState(state);
  14433. };
  14434. /**
  14435. * Sets the current state
  14436. *
  14437. * @param {*} state - The state to set.
  14438. */
  14439. WebGLState.prototype.setState = function setState(state) {
  14440. this.setBlend(state[BLEND]);
  14441. this.setDepthTest(state[DEPTH_TEST]);
  14442. this.setFrontFace(state[FRONT_FACE]);
  14443. this.setCullFace(state[CULL_FACE]);
  14444. this.setBlendMode(state[BLEND_FUNC]);
  14445. };
  14446. /**
  14447. * Enables or disabled blending.
  14448. *
  14449. * @param {boolean} value - Turn on or off webgl blending.
  14450. */
  14451. WebGLState.prototype.setBlend = function setBlend(value) {
  14452. value = value ? 1 : 0;
  14453. if (this.activeState[BLEND] === value) {
  14454. return;
  14455. }
  14456. this.activeState[BLEND] = value;
  14457. this.gl[value ? 'enable' : 'disable'](this.gl.BLEND);
  14458. };
  14459. /**
  14460. * Sets the blend mode.
  14461. *
  14462. * @param {number} value - The blend mode to set to.
  14463. */
  14464. WebGLState.prototype.setBlendMode = function setBlendMode(value) {
  14465. if (value === this.activeState[BLEND_FUNC]) {
  14466. return;
  14467. }
  14468. this.activeState[BLEND_FUNC] = value;
  14469. var mode = this.blendModes[value];
  14470. if (mode.length === 2) {
  14471. this.gl.blendFunc(mode[0], mode[1]);
  14472. } else {
  14473. this.gl.blendFuncSeparate(mode[0], mode[1], mode[2], mode[3]);
  14474. }
  14475. };
  14476. /**
  14477. * Sets whether to enable or disable depth test.
  14478. *
  14479. * @param {boolean} value - Turn on or off webgl depth testing.
  14480. */
  14481. WebGLState.prototype.setDepthTest = function setDepthTest(value) {
  14482. value = value ? 1 : 0;
  14483. if (this.activeState[DEPTH_TEST] === value) {
  14484. return;
  14485. }
  14486. this.activeState[DEPTH_TEST] = value;
  14487. this.gl[value ? 'enable' : 'disable'](this.gl.DEPTH_TEST);
  14488. };
  14489. /**
  14490. * Sets whether to enable or disable cull face.
  14491. *
  14492. * @param {boolean} value - Turn on or off webgl cull face.
  14493. */
  14494. WebGLState.prototype.setCullFace = function setCullFace(value) {
  14495. value = value ? 1 : 0;
  14496. if (this.activeState[CULL_FACE] === value) {
  14497. return;
  14498. }
  14499. this.activeState[CULL_FACE] = value;
  14500. this.gl[value ? 'enable' : 'disable'](this.gl.CULL_FACE);
  14501. };
  14502. /**
  14503. * Sets the gl front face.
  14504. *
  14505. * @param {boolean} value - true is clockwise and false is counter-clockwise
  14506. */
  14507. WebGLState.prototype.setFrontFace = function setFrontFace(value) {
  14508. value = value ? 1 : 0;
  14509. if (this.activeState[FRONT_FACE] === value) {
  14510. return;
  14511. }
  14512. this.activeState[FRONT_FACE] = value;
  14513. this.gl.frontFace(this.gl[value ? 'CW' : 'CCW']);
  14514. };
  14515. /**
  14516. * Disables all the vaos in use
  14517. *
  14518. */
  14519. WebGLState.prototype.resetAttributes = function resetAttributes() {
  14520. for (var i = 0; i < this.attribState.tempAttribState.length; i++) {
  14521. this.attribState.tempAttribState[i] = 0;
  14522. }
  14523. for (var _i = 0; _i < this.attribState.attribState.length; _i++) {
  14524. this.attribState.attribState[_i] = 0;
  14525. }
  14526. // im going to assume one is always active for performance reasons.
  14527. for (var _i2 = 1; _i2 < this.maxAttribs; _i2++) {
  14528. this.gl.disableVertexAttribArray(_i2);
  14529. }
  14530. };
  14531. // used
  14532. /**
  14533. * Resets all the logic and disables the vaos
  14534. */
  14535. WebGLState.prototype.resetToDefault = function resetToDefault() {
  14536. // unbind any VAO if they exist..
  14537. if (this.nativeVaoExtension) {
  14538. this.nativeVaoExtension.bindVertexArrayOES(null);
  14539. }
  14540. // reset all attributes..
  14541. this.resetAttributes();
  14542. // set active state so we can force overrides of gl state
  14543. for (var i = 0; i < this.activeState.length; ++i) {
  14544. this.activeState[i] = 32;
  14545. }
  14546. this.gl.pixelStorei(this.gl.UNPACK_FLIP_Y_WEBGL, false);
  14547. this.setState(this.defaultState);
  14548. };
  14549. return WebGLState;
  14550. }();
  14551. exports.default = WebGLState;
  14552. }, { "./utils/mapWebGLBlendModesToPixi": 98 }], 86: [function (require, module, exports) {
  14553. 'use strict';
  14554. exports.__esModule = true;
  14555. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  14556. var _extractUniformsFromSrc = require('./extractUniformsFromSrc');
  14557. var _extractUniformsFromSrc2 = _interopRequireDefault(_extractUniformsFromSrc);
  14558. var _utils = require('../../../utils');
  14559. var _const = require('../../../const');
  14560. var _settings = require('../../../settings');
  14561. var _settings2 = _interopRequireDefault(_settings);
  14562. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  14563. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  14564. var SOURCE_KEY_MAP = {};
  14565. // let math = require('../../../math');
  14566. /**
  14567. * @class
  14568. * @memberof PIXI
  14569. * @extends PIXI.Shader
  14570. */
  14571. var Filter = function () {
  14572. /**
  14573. * @param {string} [vertexSrc] - The source of the vertex shader.
  14574. * @param {string} [fragmentSrc] - The source of the fragment shader.
  14575. * @param {object} [uniforms] - Custom uniforms to use to augment the built-in ones.
  14576. */
  14577. function Filter(vertexSrc, fragmentSrc, uniforms) {
  14578. _classCallCheck(this, Filter);
  14579. /**
  14580. * The vertex shader.
  14581. *
  14582. * @member {string}
  14583. */
  14584. this.vertexSrc = vertexSrc || Filter.defaultVertexSrc;
  14585. /**
  14586. * The fragment shader.
  14587. *
  14588. * @member {string}
  14589. */
  14590. this.fragmentSrc = fragmentSrc || Filter.defaultFragmentSrc;
  14591. this._blendMode = _const.BLEND_MODES.NORMAL;
  14592. this.uniformData = uniforms || (0, _extractUniformsFromSrc2.default)(this.vertexSrc, this.fragmentSrc, 'projectionMatrix|uSampler');
  14593. /**
  14594. * An object containing the current values of custom uniforms.
  14595. * @example <caption>Updating the value of a custom uniform</caption>
  14596. * filter.uniforms.time = performance.now();
  14597. *
  14598. * @member {object}
  14599. */
  14600. this.uniforms = {};
  14601. for (var i in this.uniformData) {
  14602. this.uniforms[i] = this.uniformData[i].value;
  14603. if (this.uniformData[i].type) {
  14604. this.uniformData[i].type = this.uniformData[i].type.toLowerCase();
  14605. }
  14606. }
  14607. // this is where we store shader references..
  14608. // TODO we could cache this!
  14609. this.glShaders = {};
  14610. // used for cacheing.. sure there is a better way!
  14611. if (!SOURCE_KEY_MAP[this.vertexSrc + this.fragmentSrc]) {
  14612. SOURCE_KEY_MAP[this.vertexSrc + this.fragmentSrc] = (0, _utils.uid)();
  14613. }
  14614. this.glShaderKey = SOURCE_KEY_MAP[this.vertexSrc + this.fragmentSrc];
  14615. /**
  14616. * The padding of the filter. Some filters require extra space to breath such as a blur.
  14617. * Increasing this will add extra width and height to the bounds of the object that the
  14618. * filter is applied to.
  14619. *
  14620. * @member {number}
  14621. */
  14622. this.padding = 4;
  14623. /**
  14624. * The resolution of the filter. Setting this to be lower will lower the quality but
  14625. * increase the performance of the filter.
  14626. *
  14627. * @member {number}
  14628. */
  14629. this.resolution = _settings2.default.FILTER_RESOLUTION;
  14630. /**
  14631. * If enabled is true the filter is applied, if false it will not.
  14632. *
  14633. * @member {boolean}
  14634. */
  14635. this.enabled = true;
  14636. /**
  14637. * If enabled, PixiJS will fit the filter area into boundaries for better performance.
  14638. * Switch it off if it does not work for specific shader.
  14639. *
  14640. * @member {boolean}
  14641. */
  14642. this.autoFit = true;
  14643. }
  14644. /**
  14645. * Applies the filter
  14646. *
  14647. * @param {PIXI.FilterManager} filterManager - The renderer to retrieve the filter from
  14648. * @param {PIXI.RenderTarget} input - The input render target.
  14649. * @param {PIXI.RenderTarget} output - The target to output to.
  14650. * @param {boolean} clear - Should the output be cleared before rendering to it
  14651. * @param {object} [currentState] - It's current state of filter.
  14652. * There are some useful properties in the currentState :
  14653. * target, filters, sourceFrame, destinationFrame, renderTarget, resolution
  14654. */
  14655. Filter.prototype.apply = function apply(filterManager, input, output, clear, currentState) // eslint-disable-line no-unused-vars
  14656. {
  14657. // --- //
  14658. // this.uniforms.filterMatrix = filterManager.calculateSpriteMatrix(tempMatrix, window.panda );
  14659. // do as you please!
  14660. filterManager.applyFilter(this, input, output, clear);
  14661. // or just do a regular render..
  14662. };
  14663. /**
  14664. * Sets the blendmode of the filter
  14665. *
  14666. * @member {number}
  14667. * @default PIXI.BLEND_MODES.NORMAL
  14668. */
  14669. _createClass(Filter, [{
  14670. key: 'blendMode',
  14671. get: function get() {
  14672. return this._blendMode;
  14673. },
  14674. set: function set(value) // eslint-disable-line require-jsdoc
  14675. {
  14676. this._blendMode = value;
  14677. }
  14678. /**
  14679. * The default vertex shader source
  14680. *
  14681. * @static
  14682. * @constant
  14683. */
  14684. }], [{
  14685. key: 'defaultVertexSrc',
  14686. get: function get() {
  14687. return ['attribute vec2 aVertexPosition;', 'attribute vec2 aTextureCoord;', 'uniform mat3 projectionMatrix;', 'uniform mat3 filterMatrix;', 'varying vec2 vTextureCoord;', 'varying vec2 vFilterCoord;', 'void main(void){', ' gl_Position = vec4((projectionMatrix * vec3(aVertexPosition, 1.0)).xy, 0.0, 1.0);', ' vFilterCoord = ( filterMatrix * vec3( aTextureCoord, 1.0) ).xy;', ' vTextureCoord = aTextureCoord ;', '}'].join('\n');
  14688. }
  14689. /**
  14690. * The default fragment shader source
  14691. *
  14692. * @static
  14693. * @constant
  14694. */
  14695. }, {
  14696. key: 'defaultFragmentSrc',
  14697. get: function get() {
  14698. return ['varying vec2 vTextureCoord;', 'varying vec2 vFilterCoord;', 'uniform sampler2D uSampler;', 'uniform sampler2D filterSampler;', 'void main(void){', ' vec4 masky = texture2D(filterSampler, vFilterCoord);', ' vec4 sample = texture2D(uSampler, vTextureCoord);', ' vec4 color;', ' if(mod(vFilterCoord.x, 1.0) > 0.5)', ' {', ' color = vec4(1.0, 0.0, 0.0, 1.0);', ' }', ' else', ' {', ' color = vec4(0.0, 1.0, 0.0, 1.0);', ' }',
  14699. // ' gl_FragColor = vec4(mod(vFilterCoord.x, 1.5), vFilterCoord.y,0.0,1.0);',
  14700. ' gl_FragColor = mix(sample, masky, 0.5);', ' gl_FragColor *= sample.a;', '}'].join('\n');
  14701. }
  14702. }]);
  14703. return Filter;
  14704. }();
  14705. exports.default = Filter;
  14706. }, { "../../../const": 46, "../../../settings": 101, "../../../utils": 125, "./extractUniformsFromSrc": 87 }], 87: [function (require, module, exports) {
  14707. 'use strict';
  14708. exports.__esModule = true;
  14709. exports.default = extractUniformsFromSrc;
  14710. var _pixiGlCore = require('pixi-gl-core');
  14711. var _pixiGlCore2 = _interopRequireDefault(_pixiGlCore);
  14712. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  14713. var defaultValue = _pixiGlCore2.default.shader.defaultValue;
  14714. function extractUniformsFromSrc(vertexSrc, fragmentSrc, mask) {
  14715. var vertUniforms = extractUniformsFromString(vertexSrc, mask);
  14716. var fragUniforms = extractUniformsFromString(fragmentSrc, mask);
  14717. return Object.assign(vertUniforms, fragUniforms);
  14718. }
  14719. function extractUniformsFromString(string) {
  14720. var maskRegex = new RegExp('^(projectionMatrix|uSampler|filterArea|filterClamp)$');
  14721. var uniforms = {};
  14722. var nameSplit = void 0;
  14723. // clean the lines a little - remove extra spaces / tabs etc
  14724. // then split along ';'
  14725. var lines = string.replace(/\s+/g, ' ').split(/\s*;\s*/);
  14726. // loop through..
  14727. for (var i = 0; i < lines.length; i++) {
  14728. var line = lines[i].trim();
  14729. if (line.indexOf('uniform') > -1) {
  14730. var splitLine = line.split(' ');
  14731. var type = splitLine[1];
  14732. var name = splitLine[2];
  14733. var size = 1;
  14734. if (name.indexOf('[') > -1) {
  14735. // array!
  14736. nameSplit = name.split(/\[|]/);
  14737. name = nameSplit[0];
  14738. size *= Number(nameSplit[1]);
  14739. }
  14740. if (!name.match(maskRegex)) {
  14741. uniforms[name] = {
  14742. value: defaultValue(type, size),
  14743. name: name,
  14744. type: type
  14745. };
  14746. }
  14747. }
  14748. }
  14749. return uniforms;
  14750. }
  14751. }, { "pixi-gl-core": 15 }], 88: [function (require, module, exports) {
  14752. 'use strict';
  14753. exports.__esModule = true;
  14754. exports.calculateScreenSpaceMatrix = calculateScreenSpaceMatrix;
  14755. exports.calculateNormalizedScreenSpaceMatrix = calculateNormalizedScreenSpaceMatrix;
  14756. exports.calculateSpriteMatrix = calculateSpriteMatrix;
  14757. var _math = require('../../../math');
  14758. /**
  14759. * Calculates the mapped matrix
  14760. * @param filterArea {Rectangle} The filter area
  14761. * @param sprite {Sprite} the target sprite
  14762. * @param outputMatrix {Matrix} @alvin
  14763. * @private
  14764. */
  14765. // TODO playing around here.. this is temporary - (will end up in the shader)
  14766. // this returns a matrix that will normalise map filter cords in the filter to screen space
  14767. function calculateScreenSpaceMatrix(outputMatrix, filterArea, textureSize) {
  14768. // let worldTransform = sprite.worldTransform.copy(Matrix.TEMP_MATRIX),
  14769. // let texture = {width:1136, height:700};//sprite._texture.baseTexture;
  14770. // TODO unwrap?
  14771. var mappedMatrix = outputMatrix.identity();
  14772. mappedMatrix.translate(filterArea.x / textureSize.width, filterArea.y / textureSize.height);
  14773. mappedMatrix.scale(textureSize.width, textureSize.height);
  14774. return mappedMatrix;
  14775. }
  14776. function calculateNormalizedScreenSpaceMatrix(outputMatrix, filterArea, textureSize) {
  14777. var mappedMatrix = outputMatrix.identity();
  14778. mappedMatrix.translate(filterArea.x / textureSize.width, filterArea.y / textureSize.height);
  14779. var translateScaleX = textureSize.width / filterArea.width;
  14780. var translateScaleY = textureSize.height / filterArea.height;
  14781. mappedMatrix.scale(translateScaleX, translateScaleY);
  14782. return mappedMatrix;
  14783. }
  14784. // this will map the filter coord so that a texture can be used based on the transform of a sprite
  14785. function calculateSpriteMatrix(outputMatrix, filterArea, textureSize, sprite) {
  14786. var orig = sprite._texture.orig;
  14787. var mappedMatrix = outputMatrix.set(textureSize.width, 0, 0, textureSize.height, filterArea.x, filterArea.y);
  14788. var worldTransform = sprite.worldTransform.copy(_math.Matrix.TEMP_MATRIX);
  14789. worldTransform.invert();
  14790. mappedMatrix.prepend(worldTransform);
  14791. mappedMatrix.scale(1.0 / orig.width, 1.0 / orig.height);
  14792. mappedMatrix.translate(sprite.anchor.x, sprite.anchor.y);
  14793. return mappedMatrix;
  14794. }
  14795. }, { "../../../math": 70 }], 89: [function (require, module, exports) {
  14796. 'use strict';
  14797. exports.__esModule = true;
  14798. var _Filter2 = require('../Filter');
  14799. var _Filter3 = _interopRequireDefault(_Filter2);
  14800. var _math = require('../../../../math');
  14801. var _path = require('path');
  14802. var _TextureMatrix = require('../../../../textures/TextureMatrix');
  14803. var _TextureMatrix2 = _interopRequireDefault(_TextureMatrix);
  14804. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  14805. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  14806. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  14807. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  14808. /**
  14809. * The SpriteMaskFilter class
  14810. *
  14811. * @class
  14812. * @extends PIXI.Filter
  14813. * @memberof PIXI
  14814. */
  14815. var SpriteMaskFilter = function (_Filter) {
  14816. _inherits(SpriteMaskFilter, _Filter);
  14817. /**
  14818. * @param {PIXI.Sprite} sprite - the target sprite
  14819. */
  14820. function SpriteMaskFilter(sprite) {
  14821. _classCallCheck(this, SpriteMaskFilter);
  14822. var maskMatrix = new _math.Matrix();
  14823. var _this = _possibleConstructorReturn(this, _Filter.call(this, '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', 'varying vec2 vMaskCoord;\nvarying vec2 vTextureCoord;\n\nuniform sampler2D uSampler;\nuniform sampler2D mask;\nuniform float alpha;\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\n original *= (masky.r * masky.a * alpha * clip);\n\n gl_FragColor = original;\n}\n'));
  14824. sprite.renderable = false;
  14825. _this.maskSprite = sprite;
  14826. _this.maskMatrix = maskMatrix;
  14827. return _this;
  14828. }
  14829. /**
  14830. * Applies the filter
  14831. *
  14832. * @param {PIXI.FilterManager} filterManager - The renderer to retrieve the filter from
  14833. * @param {PIXI.RenderTarget} input - The input render target.
  14834. * @param {PIXI.RenderTarget} output - The target to output to.
  14835. */
  14836. SpriteMaskFilter.prototype.apply = function apply(filterManager, input, output) {
  14837. var maskSprite = this.maskSprite;
  14838. var tex = this.maskSprite.texture;
  14839. if (!tex.valid) {
  14840. return;
  14841. }
  14842. if (!tex.transform) {
  14843. // margin = 0.0, let it bleed a bit, shader code becomes easier
  14844. // assuming that atlas textures were made with 1-pixel padding
  14845. tex.transform = new _TextureMatrix2.default(tex, 0.0);
  14846. }
  14847. tex.transform.update();
  14848. this.uniforms.mask = tex;
  14849. this.uniforms.otherMatrix = filterManager.calculateSpriteMatrix(this.maskMatrix, maskSprite).prepend(tex.transform.mapCoord);
  14850. this.uniforms.alpha = maskSprite.worldAlpha;
  14851. this.uniforms.maskClamp = tex.transform.uClampFrame;
  14852. filterManager.applyFilter(this, input, output);
  14853. };
  14854. return SpriteMaskFilter;
  14855. }(_Filter3.default);
  14856. exports.default = SpriteMaskFilter;
  14857. }, { "../../../../math": 70, "../../../../textures/TextureMatrix": 116, "../Filter": 86, "path": 8 }], 90: [function (require, module, exports) {
  14858. 'use strict';
  14859. exports.__esModule = true;
  14860. var _WebGLManager2 = require('./WebGLManager');
  14861. var _WebGLManager3 = _interopRequireDefault(_WebGLManager2);
  14862. var _RenderTarget = require('../utils/RenderTarget');
  14863. var _RenderTarget2 = _interopRequireDefault(_RenderTarget);
  14864. var _Quad = require('../utils/Quad');
  14865. var _Quad2 = _interopRequireDefault(_Quad);
  14866. var _math = require('../../../math');
  14867. var _Shader = require('../../../Shader');
  14868. var _Shader2 = _interopRequireDefault(_Shader);
  14869. var _filterTransforms = require('../filters/filterTransforms');
  14870. var filterTransforms = _interopRequireWildcard(_filterTransforms);
  14871. var _bitTwiddle = require('bit-twiddle');
  14872. var _bitTwiddle2 = _interopRequireDefault(_bitTwiddle);
  14873. function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
  14874. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  14875. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  14876. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  14877. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  14878. /**
  14879. * @ignore
  14880. * @class
  14881. */
  14882. var FilterState =
  14883. /**
  14884. *
  14885. */
  14886. function FilterState() {
  14887. _classCallCheck(this, FilterState);
  14888. this.renderTarget = null;
  14889. this.sourceFrame = new _math.Rectangle();
  14890. this.destinationFrame = new _math.Rectangle();
  14891. this.filters = [];
  14892. this.target = null;
  14893. this.resolution = 1;
  14894. };
  14895. var screenKey = 'screen';
  14896. /**
  14897. * @class
  14898. * @memberof PIXI
  14899. * @extends PIXI.WebGLManager
  14900. */
  14901. var FilterManager = function (_WebGLManager) {
  14902. _inherits(FilterManager, _WebGLManager);
  14903. /**
  14904. * @param {PIXI.WebGLRenderer} renderer - The renderer this manager works for.
  14905. */
  14906. function FilterManager(renderer) {
  14907. _classCallCheck(this, FilterManager);
  14908. var _this = _possibleConstructorReturn(this, _WebGLManager.call(this, renderer));
  14909. _this.gl = _this.renderer.gl;
  14910. // know about sprites!
  14911. _this.quad = new _Quad2.default(_this.gl, renderer.state.attribState);
  14912. _this.shaderCache = {};
  14913. // todo add default!
  14914. _this.pool = {};
  14915. _this.filterData = null;
  14916. _this.managedFilters = [];
  14917. _this.renderer.on('prerender', _this.onPrerender, _this);
  14918. _this._screenWidth = renderer.view.width;
  14919. _this._screenHeight = renderer.view.height;
  14920. return _this;
  14921. }
  14922. /**
  14923. * Adds a new filter to the manager.
  14924. *
  14925. * @param {PIXI.DisplayObject} target - The target of the filter to render.
  14926. * @param {PIXI.Filter[]} filters - The filters to apply.
  14927. */
  14928. FilterManager.prototype.pushFilter = function pushFilter(target, filters) {
  14929. var renderer = this.renderer;
  14930. var filterData = this.filterData;
  14931. if (!filterData) {
  14932. filterData = this.renderer._activeRenderTarget.filterStack;
  14933. // add new stack
  14934. var filterState = new FilterState();
  14935. filterState.sourceFrame = filterState.destinationFrame = this.renderer._activeRenderTarget.size;
  14936. filterState.renderTarget = renderer._activeRenderTarget;
  14937. this.renderer._activeRenderTarget.filterData = filterData = {
  14938. index: 0,
  14939. stack: [filterState]
  14940. };
  14941. this.filterData = filterData;
  14942. }
  14943. // get the current filter state..
  14944. var currentState = filterData.stack[++filterData.index];
  14945. var renderTargetFrame = filterData.stack[0].destinationFrame;
  14946. if (!currentState) {
  14947. currentState = filterData.stack[filterData.index] = new FilterState();
  14948. }
  14949. var fullScreen = target.filterArea && target.filterArea.x === 0 && target.filterArea.y === 0 && target.filterArea.width === renderer.screen.width && target.filterArea.height === renderer.screen.height;
  14950. // for now we go off the filter of the first resolution..
  14951. var resolution = filters[0].resolution;
  14952. var padding = filters[0].padding | 0;
  14953. var targetBounds = fullScreen ? renderer.screen : target.filterArea || target.getBounds(true);
  14954. var sourceFrame = currentState.sourceFrame;
  14955. var destinationFrame = currentState.destinationFrame;
  14956. sourceFrame.x = (targetBounds.x * resolution | 0) / resolution;
  14957. sourceFrame.y = (targetBounds.y * resolution | 0) / resolution;
  14958. sourceFrame.width = (targetBounds.width * resolution | 0) / resolution;
  14959. sourceFrame.height = (targetBounds.height * resolution | 0) / resolution;
  14960. if (!fullScreen) {
  14961. if (filterData.stack[0].renderTarget.transform) {//
  14962. // TODO we should fit the rect around the transform..
  14963. } else if (filters[0].autoFit) {
  14964. sourceFrame.fit(renderTargetFrame);
  14965. }
  14966. // lets apply the padding After we fit the element to the screen.
  14967. // this should stop the strange side effects that can occur when cropping to the edges
  14968. sourceFrame.pad(padding);
  14969. }
  14970. destinationFrame.width = sourceFrame.width;
  14971. destinationFrame.height = sourceFrame.height;
  14972. // lets play the padding after we fit the element to the screen.
  14973. // this should stop the strange side effects that can occur when cropping to the edges
  14974. var renderTarget = this.getPotRenderTarget(renderer.gl, sourceFrame.width, sourceFrame.height, resolution);
  14975. currentState.target = target;
  14976. currentState.filters = filters;
  14977. currentState.resolution = resolution;
  14978. currentState.renderTarget = renderTarget;
  14979. // bind the render target to draw the shape in the top corner..
  14980. renderTarget.setFrame(destinationFrame, sourceFrame);
  14981. // bind the render target
  14982. renderer.bindRenderTarget(renderTarget);
  14983. renderTarget.clear();
  14984. };
  14985. /**
  14986. * Pops off the filter and applies it.
  14987. *
  14988. */
  14989. FilterManager.prototype.popFilter = function popFilter() {
  14990. var filterData = this.filterData;
  14991. var lastState = filterData.stack[filterData.index - 1];
  14992. var currentState = filterData.stack[filterData.index];
  14993. this.quad.map(currentState.renderTarget.size, currentState.sourceFrame).upload();
  14994. var filters = currentState.filters;
  14995. if (filters.length === 1) {
  14996. filters[0].apply(this, currentState.renderTarget, lastState.renderTarget, false, currentState);
  14997. this.freePotRenderTarget(currentState.renderTarget);
  14998. } else {
  14999. var flip = currentState.renderTarget;
  15000. var flop = this.getPotRenderTarget(this.renderer.gl, currentState.sourceFrame.width, currentState.sourceFrame.height, currentState.resolution);
  15001. flop.setFrame(currentState.destinationFrame, currentState.sourceFrame);
  15002. // finally lets clear the render target before drawing to it..
  15003. flop.clear();
  15004. var i = 0;
  15005. for (i = 0; i < filters.length - 1; ++i) {
  15006. filters[i].apply(this, flip, flop, true, currentState);
  15007. var t = flip;
  15008. flip = flop;
  15009. flop = t;
  15010. }
  15011. filters[i].apply(this, flip, lastState.renderTarget, false, currentState);
  15012. this.freePotRenderTarget(flip);
  15013. this.freePotRenderTarget(flop);
  15014. }
  15015. filterData.index--;
  15016. if (filterData.index === 0) {
  15017. this.filterData = null;
  15018. }
  15019. };
  15020. /**
  15021. * Draws a filter.
  15022. *
  15023. * @param {PIXI.Filter} filter - The filter to draw.
  15024. * @param {PIXI.RenderTarget} input - The input render target.
  15025. * @param {PIXI.RenderTarget} output - The target to output to.
  15026. * @param {boolean} clear - Should the output be cleared before rendering to it
  15027. */
  15028. FilterManager.prototype.applyFilter = function applyFilter(filter, input, output, clear) {
  15029. var renderer = this.renderer;
  15030. var gl = renderer.gl;
  15031. var shader = filter.glShaders[renderer.CONTEXT_UID];
  15032. // cacheing..
  15033. if (!shader) {
  15034. if (filter.glShaderKey) {
  15035. shader = this.shaderCache[filter.glShaderKey];
  15036. if (!shader) {
  15037. shader = new _Shader2.default(this.gl, filter.vertexSrc, filter.fragmentSrc);
  15038. filter.glShaders[renderer.CONTEXT_UID] = this.shaderCache[filter.glShaderKey] = shader;
  15039. this.managedFilters.push(filter);
  15040. }
  15041. } else {
  15042. shader = filter.glShaders[renderer.CONTEXT_UID] = new _Shader2.default(this.gl, filter.vertexSrc, filter.fragmentSrc);
  15043. this.managedFilters.push(filter);
  15044. }
  15045. // TODO - this only needs to be done once?
  15046. renderer.bindVao(null);
  15047. this.quad.initVao(shader);
  15048. }
  15049. renderer.bindVao(this.quad.vao);
  15050. renderer.bindRenderTarget(output);
  15051. if (clear) {
  15052. gl.disable(gl.SCISSOR_TEST);
  15053. renderer.clear(); // [1, 1, 1, 1]);
  15054. gl.enable(gl.SCISSOR_TEST);
  15055. }
  15056. // in case the render target is being masked using a scissor rect
  15057. if (output === renderer.maskManager.scissorRenderTarget) {
  15058. renderer.maskManager.pushScissorMask(null, renderer.maskManager.scissorData);
  15059. }
  15060. renderer.bindShader(shader);
  15061. // free unit 0 for us, doesn't matter what was there
  15062. // don't try to restore it, because syncUniforms can upload it to another slot
  15063. // and it'll be a problem
  15064. var tex = this.renderer.emptyTextures[0];
  15065. this.renderer.boundTextures[0] = tex;
  15066. // this syncs the PixiJS filters uniforms with glsl uniforms
  15067. this.syncUniforms(shader, filter);
  15068. renderer.state.setBlendMode(filter.blendMode);
  15069. gl.activeTexture(gl.TEXTURE0);
  15070. gl.bindTexture(gl.TEXTURE_2D, input.texture.texture);
  15071. this.quad.vao.draw(this.renderer.gl.TRIANGLES, 6, 0);
  15072. gl.bindTexture(gl.TEXTURE_2D, tex._glTextures[this.renderer.CONTEXT_UID].texture);
  15073. };
  15074. /**
  15075. * Uploads the uniforms of the filter.
  15076. *
  15077. * @param {GLShader} shader - The underlying gl shader.
  15078. * @param {PIXI.Filter} filter - The filter we are synchronizing.
  15079. */
  15080. FilterManager.prototype.syncUniforms = function syncUniforms(shader, filter) {
  15081. var uniformData = filter.uniformData;
  15082. var uniforms = filter.uniforms;
  15083. // 0 is reserved for the PixiJS texture so we start at 1!
  15084. var textureCount = 1;
  15085. var currentState = void 0;
  15086. // filterArea and filterClamp that are handled by FilterManager directly
  15087. // they must not appear in uniformData
  15088. if (shader.uniforms.filterArea) {
  15089. currentState = this.filterData.stack[this.filterData.index];
  15090. var filterArea = shader.uniforms.filterArea;
  15091. filterArea[0] = currentState.renderTarget.size.width;
  15092. filterArea[1] = currentState.renderTarget.size.height;
  15093. filterArea[2] = currentState.sourceFrame.x;
  15094. filterArea[3] = currentState.sourceFrame.y;
  15095. shader.uniforms.filterArea = filterArea;
  15096. }
  15097. // use this to clamp displaced texture coords so they belong to filterArea
  15098. // see displacementFilter fragment shader for an example
  15099. if (shader.uniforms.filterClamp) {
  15100. currentState = currentState || this.filterData.stack[this.filterData.index];
  15101. var filterClamp = shader.uniforms.filterClamp;
  15102. filterClamp[0] = 0;
  15103. filterClamp[1] = 0;
  15104. filterClamp[2] = (currentState.sourceFrame.width - 1) / currentState.renderTarget.size.width;
  15105. filterClamp[3] = (currentState.sourceFrame.height - 1) / currentState.renderTarget.size.height;
  15106. shader.uniforms.filterClamp = filterClamp;
  15107. }
  15108. // TODO Cacheing layer..
  15109. for (var i in uniformData) {
  15110. var type = uniformData[i].type;
  15111. if (type === 'sampler2d' && uniforms[i] !== 0) {
  15112. if (uniforms[i].baseTexture) {
  15113. shader.uniforms[i] = this.renderer.bindTexture(uniforms[i].baseTexture, textureCount);
  15114. } else {
  15115. shader.uniforms[i] = textureCount;
  15116. // TODO
  15117. // this is helpful as renderTargets can also be set.
  15118. // Although thinking about it, we could probably
  15119. // make the filter texture cache return a RenderTexture
  15120. // rather than a renderTarget
  15121. var gl = this.renderer.gl;
  15122. this.renderer.boundTextures[textureCount] = this.renderer.emptyTextures[textureCount];
  15123. gl.activeTexture(gl.TEXTURE0 + textureCount);
  15124. uniforms[i].texture.bind();
  15125. }
  15126. textureCount++;
  15127. } else if (type === 'mat3') {
  15128. // check if its PixiJS matrix..
  15129. if (uniforms[i].a !== undefined) {
  15130. shader.uniforms[i] = uniforms[i].toArray(true);
  15131. } else {
  15132. shader.uniforms[i] = uniforms[i];
  15133. }
  15134. } else if (type === 'vec2') {
  15135. // check if its a point..
  15136. if (uniforms[i].x !== undefined) {
  15137. var val = shader.uniforms[i] || new Float32Array(2);
  15138. val[0] = uniforms[i].x;
  15139. val[1] = uniforms[i].y;
  15140. shader.uniforms[i] = val;
  15141. } else {
  15142. shader.uniforms[i] = uniforms[i];
  15143. }
  15144. } else if (type === 'float') {
  15145. if (shader.uniforms.data[i].value !== uniformData[i]) {
  15146. shader.uniforms[i] = uniforms[i];
  15147. }
  15148. } else {
  15149. shader.uniforms[i] = uniforms[i];
  15150. }
  15151. }
  15152. };
  15153. /**
  15154. * Gets a render target from the pool, or creates a new one.
  15155. *
  15156. * @param {boolean} clear - Should we clear the render texture when we get it?
  15157. * @param {number} resolution - The resolution of the target.
  15158. * @return {PIXI.RenderTarget} The new render target
  15159. */
  15160. FilterManager.prototype.getRenderTarget = function getRenderTarget(clear, resolution) {
  15161. var currentState = this.filterData.stack[this.filterData.index];
  15162. var renderTarget = this.getPotRenderTarget(this.renderer.gl, currentState.sourceFrame.width, currentState.sourceFrame.height, resolution || currentState.resolution);
  15163. renderTarget.setFrame(currentState.destinationFrame, currentState.sourceFrame);
  15164. return renderTarget;
  15165. };
  15166. /**
  15167. * Returns a render target to the pool.
  15168. *
  15169. * @param {PIXI.RenderTarget} renderTarget - The render target to return.
  15170. */
  15171. FilterManager.prototype.returnRenderTarget = function returnRenderTarget(renderTarget) {
  15172. this.freePotRenderTarget(renderTarget);
  15173. };
  15174. /**
  15175. * Calculates the mapped matrix.
  15176. *
  15177. * TODO playing around here.. this is temporary - (will end up in the shader)
  15178. * this returns a matrix that will normalise map filter cords in the filter to screen space
  15179. *
  15180. * @param {PIXI.Matrix} outputMatrix - the matrix to output to.
  15181. * @return {PIXI.Matrix} The mapped matrix.
  15182. */
  15183. FilterManager.prototype.calculateScreenSpaceMatrix = function calculateScreenSpaceMatrix(outputMatrix) {
  15184. var currentState = this.filterData.stack[this.filterData.index];
  15185. return filterTransforms.calculateScreenSpaceMatrix(outputMatrix, currentState.sourceFrame, currentState.renderTarget.size);
  15186. };
  15187. /**
  15188. * Multiply vTextureCoord to this matrix to achieve (0,0,1,1) for filterArea
  15189. *
  15190. * @param {PIXI.Matrix} outputMatrix - The matrix to output to.
  15191. * @return {PIXI.Matrix} The mapped matrix.
  15192. */
  15193. FilterManager.prototype.calculateNormalizedScreenSpaceMatrix = function calculateNormalizedScreenSpaceMatrix(outputMatrix) {
  15194. var currentState = this.filterData.stack[this.filterData.index];
  15195. return filterTransforms.calculateNormalizedScreenSpaceMatrix(outputMatrix, currentState.sourceFrame, currentState.renderTarget.size, currentState.destinationFrame);
  15196. };
  15197. /**
  15198. * This will map the filter coord so that a texture can be used based on the transform of a sprite
  15199. *
  15200. * @param {PIXI.Matrix} outputMatrix - The matrix to output to.
  15201. * @param {PIXI.Sprite} sprite - The sprite to map to.
  15202. * @return {PIXI.Matrix} The mapped matrix.
  15203. */
  15204. FilterManager.prototype.calculateSpriteMatrix = function calculateSpriteMatrix(outputMatrix, sprite) {
  15205. var currentState = this.filterData.stack[this.filterData.index];
  15206. return filterTransforms.calculateSpriteMatrix(outputMatrix, currentState.sourceFrame, currentState.renderTarget.size, sprite);
  15207. };
  15208. /**
  15209. * Destroys this Filter Manager.
  15210. *
  15211. * @param {boolean} [contextLost=false] context was lost, do not free shaders
  15212. *
  15213. */
  15214. FilterManager.prototype.destroy = function destroy() {
  15215. var contextLost = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  15216. var renderer = this.renderer;
  15217. var filters = this.managedFilters;
  15218. renderer.off('prerender', this.onPrerender, this);
  15219. for (var i = 0; i < filters.length; i++) {
  15220. if (!contextLost) {
  15221. filters[i].glShaders[renderer.CONTEXT_UID].destroy();
  15222. }
  15223. delete filters[i].glShaders[renderer.CONTEXT_UID];
  15224. }
  15225. this.shaderCache = {};
  15226. if (!contextLost) {
  15227. this.emptyPool();
  15228. } else {
  15229. this.pool = {};
  15230. }
  15231. };
  15232. /**
  15233. * Gets a Power-of-Two render texture.
  15234. *
  15235. * TODO move to a seperate class could be on renderer?
  15236. * also - could cause issue with multiple contexts?
  15237. *
  15238. * @private
  15239. * @param {WebGLRenderingContext} gl - The webgl rendering context
  15240. * @param {number} minWidth - The minimum width of the render target.
  15241. * @param {number} minHeight - The minimum height of the render target.
  15242. * @param {number} resolution - The resolution of the render target.
  15243. * @return {PIXI.RenderTarget} The new render target.
  15244. */
  15245. FilterManager.prototype.getPotRenderTarget = function getPotRenderTarget(gl, minWidth, minHeight, resolution) {
  15246. var key = screenKey;
  15247. minWidth *= resolution;
  15248. minHeight *= resolution;
  15249. if (minWidth !== this._screenWidth || minHeight !== this._screenHeight) {
  15250. // TODO you could return a bigger texture if there is not one in the pool?
  15251. minWidth = _bitTwiddle2.default.nextPow2(minWidth);
  15252. minHeight = _bitTwiddle2.default.nextPow2(minHeight);
  15253. key = (minWidth & 0xFFFF) << 16 | minHeight & 0xFFFF;
  15254. }
  15255. if (!this.pool[key]) {
  15256. this.pool[key] = [];
  15257. }
  15258. var renderTarget = this.pool[key].pop();
  15259. // creating render target will cause texture to be bound!
  15260. if (!renderTarget) {
  15261. // temporary bypass cache..
  15262. var tex = this.renderer.boundTextures[0];
  15263. gl.activeTexture(gl.TEXTURE0);
  15264. // internally - this will cause a texture to be bound..
  15265. renderTarget = new _RenderTarget2.default(gl, minWidth, minHeight, null, 1);
  15266. // set the current one back
  15267. gl.bindTexture(gl.TEXTURE_2D, tex._glTextures[this.renderer.CONTEXT_UID].texture);
  15268. }
  15269. // manually tweak the resolution...
  15270. // this will not modify the size of the frame buffer, just its resolution.
  15271. renderTarget.resolution = resolution;
  15272. renderTarget.defaultFrame.width = renderTarget.size.width = minWidth / resolution;
  15273. renderTarget.defaultFrame.height = renderTarget.size.height = minHeight / resolution;
  15274. return renderTarget;
  15275. };
  15276. /**
  15277. * Empties the texture pool.
  15278. *
  15279. */
  15280. FilterManager.prototype.emptyPool = function emptyPool() {
  15281. for (var i in this.pool) {
  15282. var textures = this.pool[i];
  15283. if (textures) {
  15284. for (var j = 0; j < textures.length; j++) {
  15285. textures[j].destroy(true);
  15286. }
  15287. }
  15288. }
  15289. this.pool = {};
  15290. };
  15291. /**
  15292. * Frees a render target back into the pool.
  15293. *
  15294. * @param {PIXI.RenderTarget} renderTarget - The renderTarget to free
  15295. */
  15296. FilterManager.prototype.freePotRenderTarget = function freePotRenderTarget(renderTarget) {
  15297. var minWidth = renderTarget.size.width * renderTarget.resolution;
  15298. var minHeight = renderTarget.size.height * renderTarget.resolution;
  15299. var key = screenKey;
  15300. if (minWidth !== this._screenWidth || minHeight !== this._screenHeight) {
  15301. key = (minWidth & 0xFFFF) << 16 | minHeight & 0xFFFF;
  15302. }
  15303. this.pool[key].push(renderTarget);
  15304. };
  15305. /**
  15306. * Called before the renderer starts rendering.
  15307. *
  15308. */
  15309. FilterManager.prototype.onPrerender = function onPrerender() {
  15310. if (this._screenWidth !== this.renderer.view.width || this._screenHeight !== this.renderer.view.height) {
  15311. this._screenWidth = this.renderer.view.width;
  15312. this._screenHeight = this.renderer.view.height;
  15313. var textures = this.pool[screenKey];
  15314. if (textures) {
  15315. for (var j = 0; j < textures.length; j++) {
  15316. textures[j].destroy(true);
  15317. }
  15318. }
  15319. this.pool[screenKey] = [];
  15320. }
  15321. };
  15322. return FilterManager;
  15323. }(_WebGLManager3.default);
  15324. exports.default = FilterManager;
  15325. }, { "../../../Shader": 44, "../../../math": 70, "../filters/filterTransforms": 88, "../utils/Quad": 95, "../utils/RenderTarget": 96, "./WebGLManager": 93, "bit-twiddle": 1 }], 91: [function (require, module, exports) {
  15326. 'use strict';
  15327. exports.__esModule = true;
  15328. var _WebGLManager2 = require('./WebGLManager');
  15329. var _WebGLManager3 = _interopRequireDefault(_WebGLManager2);
  15330. var _SpriteMaskFilter = require('../filters/spriteMask/SpriteMaskFilter');
  15331. var _SpriteMaskFilter2 = _interopRequireDefault(_SpriteMaskFilter);
  15332. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  15333. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  15334. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  15335. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  15336. /**
  15337. * @class
  15338. * @extends PIXI.WebGLManager
  15339. * @memberof PIXI
  15340. */
  15341. var MaskManager = function (_WebGLManager) {
  15342. _inherits(MaskManager, _WebGLManager);
  15343. /**
  15344. * @param {PIXI.WebGLRenderer} renderer - The renderer this manager works for.
  15345. */
  15346. function MaskManager(renderer) {
  15347. _classCallCheck(this, MaskManager);
  15348. // TODO - we don't need both!
  15349. var _this = _possibleConstructorReturn(this, _WebGLManager.call(this, renderer));
  15350. _this.scissor = false;
  15351. _this.scissorData = null;
  15352. _this.scissorRenderTarget = null;
  15353. _this.enableScissor = true;
  15354. _this.alphaMaskPool = [];
  15355. _this.alphaMaskIndex = 0;
  15356. return _this;
  15357. }
  15358. /**
  15359. * Applies the Mask and adds it to the current filter stack.
  15360. *
  15361. * @param {PIXI.DisplayObject} target - Display Object to push the mask to
  15362. * @param {PIXI.Sprite|PIXI.Graphics} maskData - The masking data.
  15363. */
  15364. MaskManager.prototype.pushMask = function pushMask(target, maskData) {
  15365. // TODO the root check means scissor rect will not
  15366. // be used on render textures more info here:
  15367. // https://github.com/pixijs/pixi.js/pull/3545
  15368. if (maskData.texture) {
  15369. this.pushSpriteMask(target, maskData);
  15370. } else if (this.enableScissor && !this.scissor && this.renderer._activeRenderTarget.root && !this.renderer.stencilManager.stencilMaskStack.length && maskData.isFastRect()) {
  15371. var matrix = maskData.worldTransform;
  15372. var rot = Math.atan2(matrix.b, matrix.a);
  15373. // use the nearest degree!
  15374. rot = Math.round(rot * (180 / Math.PI));
  15375. if (rot % 90) {
  15376. this.pushStencilMask(maskData);
  15377. } else {
  15378. this.pushScissorMask(target, maskData);
  15379. }
  15380. } else {
  15381. this.pushStencilMask(maskData);
  15382. }
  15383. };
  15384. /**
  15385. * Removes the last mask from the mask stack and doesn't return it.
  15386. *
  15387. * @param {PIXI.DisplayObject} target - Display Object to pop the mask from
  15388. * @param {PIXI.Sprite|PIXI.Graphics} maskData - The masking data.
  15389. */
  15390. MaskManager.prototype.popMask = function popMask(target, maskData) {
  15391. if (maskData.texture) {
  15392. this.popSpriteMask(target, maskData);
  15393. } else if (this.enableScissor && !this.renderer.stencilManager.stencilMaskStack.length) {
  15394. this.popScissorMask(target, maskData);
  15395. } else {
  15396. this.popStencilMask(target, maskData);
  15397. }
  15398. };
  15399. /**
  15400. * Applies the Mask and adds it to the current filter stack.
  15401. *
  15402. * @param {PIXI.RenderTarget} target - Display Object to push the sprite mask to
  15403. * @param {PIXI.Sprite} maskData - Sprite to be used as the mask
  15404. */
  15405. MaskManager.prototype.pushSpriteMask = function pushSpriteMask(target, maskData) {
  15406. var alphaMaskFilter = this.alphaMaskPool[this.alphaMaskIndex];
  15407. if (!alphaMaskFilter) {
  15408. alphaMaskFilter = this.alphaMaskPool[this.alphaMaskIndex] = [new _SpriteMaskFilter2.default(maskData)];
  15409. }
  15410. alphaMaskFilter[0].resolution = this.renderer.resolution;
  15411. alphaMaskFilter[0].maskSprite = maskData;
  15412. // TODO - may cause issues!
  15413. target.filterArea = maskData.getBounds(true);
  15414. this.renderer.filterManager.pushFilter(target, alphaMaskFilter);
  15415. this.alphaMaskIndex++;
  15416. };
  15417. /**
  15418. * Removes the last filter from the filter stack and doesn't return it.
  15419. *
  15420. */
  15421. MaskManager.prototype.popSpriteMask = function popSpriteMask() {
  15422. this.renderer.filterManager.popFilter();
  15423. this.alphaMaskIndex--;
  15424. };
  15425. /**
  15426. * Applies the Mask and adds it to the current filter stack.
  15427. *
  15428. * @param {PIXI.Sprite|PIXI.Graphics} maskData - The masking data.
  15429. */
  15430. MaskManager.prototype.pushStencilMask = function pushStencilMask(maskData) {
  15431. this.renderer.currentRenderer.stop();
  15432. this.renderer.stencilManager.pushStencil(maskData);
  15433. };
  15434. /**
  15435. * Removes the last filter from the filter stack and doesn't return it.
  15436. *
  15437. */
  15438. MaskManager.prototype.popStencilMask = function popStencilMask() {
  15439. this.renderer.currentRenderer.stop();
  15440. this.renderer.stencilManager.popStencil();
  15441. };
  15442. /**
  15443. *
  15444. * @param {PIXI.DisplayObject} target - Display Object to push the mask to
  15445. * @param {PIXI.Graphics} maskData - The masking data.
  15446. */
  15447. MaskManager.prototype.pushScissorMask = function pushScissorMask(target, maskData) {
  15448. maskData.renderable = true;
  15449. var renderTarget = this.renderer._activeRenderTarget;
  15450. var bounds = maskData.getBounds();
  15451. bounds.fit(renderTarget.size);
  15452. maskData.renderable = false;
  15453. this.renderer.gl.enable(this.renderer.gl.SCISSOR_TEST);
  15454. var resolution = this.renderer.resolution;
  15455. this.renderer.gl.scissor(bounds.x * resolution, (renderTarget.root ? renderTarget.size.height - bounds.y - bounds.height : bounds.y) * resolution, bounds.width * resolution, bounds.height * resolution);
  15456. this.scissorRenderTarget = renderTarget;
  15457. this.scissorData = maskData;
  15458. this.scissor = true;
  15459. };
  15460. /**
  15461. *
  15462. *
  15463. */
  15464. MaskManager.prototype.popScissorMask = function popScissorMask() {
  15465. this.scissorRenderTarget = null;
  15466. this.scissorData = null;
  15467. this.scissor = false;
  15468. // must be scissor!
  15469. var gl = this.renderer.gl;
  15470. gl.disable(gl.SCISSOR_TEST);
  15471. };
  15472. return MaskManager;
  15473. }(_WebGLManager3.default);
  15474. exports.default = MaskManager;
  15475. }, { "../filters/spriteMask/SpriteMaskFilter": 89, "./WebGLManager": 93 }], 92: [function (require, module, exports) {
  15476. 'use strict';
  15477. exports.__esModule = true;
  15478. var _WebGLManager2 = require('./WebGLManager');
  15479. var _WebGLManager3 = _interopRequireDefault(_WebGLManager2);
  15480. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  15481. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  15482. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  15483. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  15484. /**
  15485. * @class
  15486. * @extends PIXI.WebGLManager
  15487. * @memberof PIXI
  15488. */
  15489. var StencilManager = function (_WebGLManager) {
  15490. _inherits(StencilManager, _WebGLManager);
  15491. /**
  15492. * @param {PIXI.WebGLRenderer} renderer - The renderer this manager works for.
  15493. */
  15494. function StencilManager(renderer) {
  15495. _classCallCheck(this, StencilManager);
  15496. var _this = _possibleConstructorReturn(this, _WebGLManager.call(this, renderer));
  15497. _this.stencilMaskStack = null;
  15498. return _this;
  15499. }
  15500. /**
  15501. * Changes the mask stack that is used by this manager.
  15502. *
  15503. * @param {PIXI.Graphics[]} stencilMaskStack - The mask stack
  15504. */
  15505. StencilManager.prototype.setMaskStack = function setMaskStack(stencilMaskStack) {
  15506. this.stencilMaskStack = stencilMaskStack;
  15507. var gl = this.renderer.gl;
  15508. if (stencilMaskStack.length === 0) {
  15509. gl.disable(gl.STENCIL_TEST);
  15510. } else {
  15511. gl.enable(gl.STENCIL_TEST);
  15512. }
  15513. };
  15514. /**
  15515. * Applies the Mask and adds it to the current stencil stack. @alvin
  15516. *
  15517. * @param {PIXI.Graphics} graphics - The mask
  15518. */
  15519. StencilManager.prototype.pushStencil = function pushStencil(graphics) {
  15520. this.renderer.setObjectRenderer(this.renderer.plugins.graphics);
  15521. this.renderer._activeRenderTarget.attachStencilBuffer();
  15522. var gl = this.renderer.gl;
  15523. var prevMaskCount = this.stencilMaskStack.length;
  15524. if (prevMaskCount === 0) {
  15525. gl.enable(gl.STENCIL_TEST);
  15526. }
  15527. this.stencilMaskStack.push(graphics);
  15528. // Increment the refference stencil value where the new mask overlaps with the old ones.
  15529. gl.colorMask(false, false, false, false);
  15530. gl.stencilFunc(gl.EQUAL, prevMaskCount, this._getBitwiseMask());
  15531. gl.stencilOp(gl.KEEP, gl.KEEP, gl.INCR);
  15532. this.renderer.plugins.graphics.render(graphics);
  15533. this._useCurrent();
  15534. };
  15535. /**
  15536. * Removes the last mask from the stencil stack. @alvin
  15537. */
  15538. StencilManager.prototype.popStencil = function popStencil() {
  15539. this.renderer.setObjectRenderer(this.renderer.plugins.graphics);
  15540. var gl = this.renderer.gl;
  15541. var graphics = this.stencilMaskStack.pop();
  15542. if (this.stencilMaskStack.length === 0) {
  15543. // the stack is empty!
  15544. gl.disable(gl.STENCIL_TEST);
  15545. gl.clear(gl.STENCIL_BUFFER_BIT);
  15546. gl.clearStencil(0);
  15547. } else {
  15548. // Decrement the refference stencil value where the popped mask overlaps with the other ones
  15549. gl.colorMask(false, false, false, false);
  15550. gl.stencilOp(gl.KEEP, gl.KEEP, gl.DECR);
  15551. this.renderer.plugins.graphics.render(graphics);
  15552. this._useCurrent();
  15553. }
  15554. };
  15555. /**
  15556. * Setup renderer to use the current stencil data.
  15557. */
  15558. StencilManager.prototype._useCurrent = function _useCurrent() {
  15559. var gl = this.renderer.gl;
  15560. gl.colorMask(true, true, true, true);
  15561. gl.stencilFunc(gl.EQUAL, this.stencilMaskStack.length, this._getBitwiseMask());
  15562. gl.stencilOp(gl.KEEP, gl.KEEP, gl.KEEP);
  15563. };
  15564. /**
  15565. * Fill 1s equal to the number of acitve stencil masks.
  15566. *
  15567. * @return {number} The bitwise mask.
  15568. */
  15569. StencilManager.prototype._getBitwiseMask = function _getBitwiseMask() {
  15570. return (1 << this.stencilMaskStack.length) - 1;
  15571. };
  15572. /**
  15573. * Destroys the mask stack.
  15574. *
  15575. */
  15576. StencilManager.prototype.destroy = function destroy() {
  15577. _WebGLManager3.default.prototype.destroy.call(this);
  15578. this.stencilMaskStack.stencilStack = null;
  15579. };
  15580. return StencilManager;
  15581. }(_WebGLManager3.default);
  15582. exports.default = StencilManager;
  15583. }, { "./WebGLManager": 93 }], 93: [function (require, module, exports) {
  15584. 'use strict';
  15585. exports.__esModule = true;
  15586. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  15587. /**
  15588. * @class
  15589. * @memberof PIXI
  15590. */
  15591. var WebGLManager = function () {
  15592. /**
  15593. * @param {PIXI.WebGLRenderer} renderer - The renderer this manager works for.
  15594. */
  15595. function WebGLManager(renderer) {
  15596. _classCallCheck(this, WebGLManager);
  15597. /**
  15598. * The renderer this manager works for.
  15599. *
  15600. * @member {PIXI.WebGLRenderer}
  15601. */
  15602. this.renderer = renderer;
  15603. this.renderer.on('context', this.onContextChange, this);
  15604. }
  15605. /**
  15606. * Generic method called when there is a WebGL context change.
  15607. *
  15608. */
  15609. WebGLManager.prototype.onContextChange = function onContextChange() { }
  15610. // do some codes init!
  15611. /**
  15612. * Generic destroy methods to be overridden by the subclass
  15613. *
  15614. */
  15615. ;
  15616. WebGLManager.prototype.destroy = function destroy() {
  15617. this.renderer.off('context', this.onContextChange, this);
  15618. this.renderer = null;
  15619. };
  15620. return WebGLManager;
  15621. }();
  15622. exports.default = WebGLManager;
  15623. }, {}], 94: [function (require, module, exports) {
  15624. 'use strict';
  15625. exports.__esModule = true;
  15626. var _WebGLManager2 = require('../managers/WebGLManager');
  15627. var _WebGLManager3 = _interopRequireDefault(_WebGLManager2);
  15628. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  15629. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  15630. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  15631. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  15632. /**
  15633. * Base for a common object renderer that can be used as a system renderer plugin.
  15634. *
  15635. * @class
  15636. * @extends PIXI.WebGLManager
  15637. * @memberof PIXI
  15638. */
  15639. var ObjectRenderer = function (_WebGLManager) {
  15640. _inherits(ObjectRenderer, _WebGLManager);
  15641. function ObjectRenderer() {
  15642. _classCallCheck(this, ObjectRenderer);
  15643. return _possibleConstructorReturn(this, _WebGLManager.apply(this, arguments));
  15644. }
  15645. /**
  15646. * Starts the renderer and sets the shader
  15647. *
  15648. */
  15649. ObjectRenderer.prototype.start = function start() { }
  15650. // set the shader..
  15651. /**
  15652. * Stops the renderer
  15653. *
  15654. */
  15655. ;
  15656. ObjectRenderer.prototype.stop = function stop() {
  15657. this.flush();
  15658. };
  15659. /**
  15660. * Stub method for rendering content and emptying the current batch.
  15661. *
  15662. */
  15663. ObjectRenderer.prototype.flush = function flush() { }
  15664. // flush!
  15665. /**
  15666. * Renders an object
  15667. *
  15668. * @param {PIXI.DisplayObject} object - The object to render.
  15669. */
  15670. ;
  15671. ObjectRenderer.prototype.render = function render(object) // eslint-disable-line no-unused-vars
  15672. {
  15673. // render the object
  15674. };
  15675. return ObjectRenderer;
  15676. }(_WebGLManager3.default);
  15677. exports.default = ObjectRenderer;
  15678. }, { "../managers/WebGLManager": 93 }], 95: [function (require, module, exports) {
  15679. 'use strict';
  15680. exports.__esModule = true;
  15681. var _pixiGlCore = require('pixi-gl-core');
  15682. var _pixiGlCore2 = _interopRequireDefault(_pixiGlCore);
  15683. var _createIndicesForQuads = require('../../../utils/createIndicesForQuads');
  15684. var _createIndicesForQuads2 = _interopRequireDefault(_createIndicesForQuads);
  15685. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  15686. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  15687. /**
  15688. * Helper class to create a quad
  15689. *
  15690. * @class
  15691. * @memberof PIXI
  15692. */
  15693. var Quad = function () {
  15694. /**
  15695. * @param {WebGLRenderingContext} gl - The gl context for this quad to use.
  15696. * @param {object} state - TODO: Description
  15697. */
  15698. function Quad(gl, state) {
  15699. _classCallCheck(this, Quad);
  15700. /**
  15701. * the current WebGL drawing context
  15702. *
  15703. * @member {WebGLRenderingContext}
  15704. */
  15705. this.gl = gl;
  15706. /**
  15707. * An array of vertices
  15708. *
  15709. * @member {Float32Array}
  15710. */
  15711. this.vertices = new Float32Array([-1, -1, 1, -1, 1, 1, -1, 1]);
  15712. /**
  15713. * The Uvs of the quad
  15714. *
  15715. * @member {Float32Array}
  15716. */
  15717. this.uvs = new Float32Array([0, 0, 1, 0, 1, 1, 0, 1]);
  15718. this.interleaved = new Float32Array(8 * 2);
  15719. for (var i = 0; i < 4; i++) {
  15720. this.interleaved[i * 4] = this.vertices[i * 2];
  15721. this.interleaved[i * 4 + 1] = this.vertices[i * 2 + 1];
  15722. this.interleaved[i * 4 + 2] = this.uvs[i * 2];
  15723. this.interleaved[i * 4 + 3] = this.uvs[i * 2 + 1];
  15724. }
  15725. /**
  15726. * An array containing the indices of the vertices
  15727. *
  15728. * @member {Uint16Array}
  15729. */
  15730. this.indices = (0, _createIndicesForQuads2.default)(1);
  15731. /**
  15732. * The vertex buffer
  15733. *
  15734. * @member {glCore.GLBuffer}
  15735. */
  15736. this.vertexBuffer = _pixiGlCore2.default.GLBuffer.createVertexBuffer(gl, this.interleaved, gl.STATIC_DRAW);
  15737. /**
  15738. * The index buffer
  15739. *
  15740. * @member {glCore.GLBuffer}
  15741. */
  15742. this.indexBuffer = _pixiGlCore2.default.GLBuffer.createIndexBuffer(gl, this.indices, gl.STATIC_DRAW);
  15743. /**
  15744. * The vertex array object
  15745. *
  15746. * @member {glCore.VertexArrayObject}
  15747. */
  15748. this.vao = new _pixiGlCore2.default.VertexArrayObject(gl, state);
  15749. }
  15750. /**
  15751. * Initialises the vaos and uses the shader.
  15752. *
  15753. * @param {PIXI.Shader} shader - the shader to use
  15754. */
  15755. Quad.prototype.initVao = function initVao(shader) {
  15756. this.vao.clear().addIndex(this.indexBuffer).addAttribute(this.vertexBuffer, shader.attributes.aVertexPosition, this.gl.FLOAT, false, 4 * 4, 0).addAttribute(this.vertexBuffer, shader.attributes.aTextureCoord, this.gl.FLOAT, false, 4 * 4, 2 * 4);
  15757. };
  15758. /**
  15759. * Maps two Rectangle to the quad.
  15760. *
  15761. * @param {PIXI.Rectangle} targetTextureFrame - the first rectangle
  15762. * @param {PIXI.Rectangle} destinationFrame - the second rectangle
  15763. * @return {PIXI.Quad} Returns itself.
  15764. */
  15765. Quad.prototype.map = function map(targetTextureFrame, destinationFrame) {
  15766. var x = 0; // destinationFrame.x / targetTextureFrame.width;
  15767. var y = 0; // destinationFrame.y / targetTextureFrame.height;
  15768. this.uvs[0] = x;
  15769. this.uvs[1] = y;
  15770. this.uvs[2] = x + destinationFrame.width / targetTextureFrame.width;
  15771. this.uvs[3] = y;
  15772. this.uvs[4] = x + destinationFrame.width / targetTextureFrame.width;
  15773. this.uvs[5] = y + destinationFrame.height / targetTextureFrame.height;
  15774. this.uvs[6] = x;
  15775. this.uvs[7] = y + destinationFrame.height / targetTextureFrame.height;
  15776. x = destinationFrame.x;
  15777. y = destinationFrame.y;
  15778. this.vertices[0] = x;
  15779. this.vertices[1] = y;
  15780. this.vertices[2] = x + destinationFrame.width;
  15781. this.vertices[3] = y;
  15782. this.vertices[4] = x + destinationFrame.width;
  15783. this.vertices[5] = y + destinationFrame.height;
  15784. this.vertices[6] = x;
  15785. this.vertices[7] = y + destinationFrame.height;
  15786. return this;
  15787. };
  15788. /**
  15789. * Binds the buffer and uploads the data
  15790. *
  15791. * @return {PIXI.Quad} Returns itself.
  15792. */
  15793. Quad.prototype.upload = function upload() {
  15794. for (var i = 0; i < 4; i++) {
  15795. this.interleaved[i * 4] = this.vertices[i * 2];
  15796. this.interleaved[i * 4 + 1] = this.vertices[i * 2 + 1];
  15797. this.interleaved[i * 4 + 2] = this.uvs[i * 2];
  15798. this.interleaved[i * 4 + 3] = this.uvs[i * 2 + 1];
  15799. }
  15800. this.vertexBuffer.upload(this.interleaved);
  15801. return this;
  15802. };
  15803. /**
  15804. * Removes this quad from WebGL
  15805. */
  15806. Quad.prototype.destroy = function destroy() {
  15807. var gl = this.gl;
  15808. gl.deleteBuffer(this.vertexBuffer);
  15809. gl.deleteBuffer(this.indexBuffer);
  15810. };
  15811. return Quad;
  15812. }();
  15813. exports.default = Quad;
  15814. }, { "../../../utils/createIndicesForQuads": 123, "pixi-gl-core": 15 }], 96: [function (require, module, exports) {
  15815. 'use strict';
  15816. exports.__esModule = true;
  15817. var _math = require('../../../math');
  15818. var _const = require('../../../const');
  15819. var _settings = require('../../../settings');
  15820. var _settings2 = _interopRequireDefault(_settings);
  15821. var _pixiGlCore = require('pixi-gl-core');
  15822. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  15823. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  15824. /**
  15825. * @class
  15826. * @memberof PIXI
  15827. */
  15828. var RenderTarget = function () {
  15829. /**
  15830. * @param {WebGLRenderingContext} gl - The current WebGL drawing context
  15831. * @param {number} [width=0] - the horizontal range of the filter
  15832. * @param {number} [height=0] - the vertical range of the filter
  15833. * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values
  15834. * @param {number} [resolution=1] - The current resolution / device pixel ratio
  15835. * @param {boolean} [root=false] - Whether this object is the root element or not
  15836. */
  15837. function RenderTarget(gl, width, height, scaleMode, resolution, root) {
  15838. _classCallCheck(this, RenderTarget);
  15839. // TODO Resolution could go here ( eg low res blurs )
  15840. /**
  15841. * The current WebGL drawing context.
  15842. *
  15843. * @member {WebGLRenderingContext}
  15844. */
  15845. this.gl = gl;
  15846. // next time to create a frame buffer and texture
  15847. /**
  15848. * A frame buffer
  15849. *
  15850. * @member {PIXI.glCore.GLFramebuffer}
  15851. */
  15852. this.frameBuffer = null;
  15853. /**
  15854. * The texture
  15855. *
  15856. * @member {PIXI.glCore.GLTexture}
  15857. */
  15858. this.texture = null;
  15859. /**
  15860. * The background colour of this render target, as an array of [r,g,b,a] values
  15861. *
  15862. * @member {number[]}
  15863. */
  15864. this.clearColor = [0, 0, 0, 0];
  15865. /**
  15866. * The size of the object as a rectangle
  15867. *
  15868. * @member {PIXI.Rectangle}
  15869. */
  15870. this.size = new _math.Rectangle(0, 0, 1, 1);
  15871. /**
  15872. * The current resolution / device pixel ratio
  15873. *
  15874. * @member {number}
  15875. * @default 1
  15876. */
  15877. this.resolution = resolution || _settings2.default.RESOLUTION;
  15878. /**
  15879. * The projection matrix
  15880. *
  15881. * @member {PIXI.Matrix}
  15882. */
  15883. this.projectionMatrix = new _math.Matrix();
  15884. /**
  15885. * The object's transform
  15886. *
  15887. * @member {PIXI.Matrix}
  15888. */
  15889. this.transform = null;
  15890. /**
  15891. * The frame.
  15892. *
  15893. * @member {PIXI.Rectangle}
  15894. */
  15895. this.frame = null;
  15896. /**
  15897. * The stencil buffer stores masking data for the render target
  15898. *
  15899. * @member {glCore.GLBuffer}
  15900. */
  15901. this.defaultFrame = new _math.Rectangle();
  15902. this.destinationFrame = null;
  15903. this.sourceFrame = null;
  15904. /**
  15905. * The stencil buffer stores masking data for the render target
  15906. *
  15907. * @member {glCore.GLBuffer}
  15908. */
  15909. this.stencilBuffer = null;
  15910. /**
  15911. * The data structure for the stencil masks
  15912. *
  15913. * @member {PIXI.Graphics[]}
  15914. */
  15915. this.stencilMaskStack = [];
  15916. /**
  15917. * Stores filter data for the render target
  15918. *
  15919. * @member {object[]}
  15920. */
  15921. this.filterData = null;
  15922. /**
  15923. * The scale mode.
  15924. *
  15925. * @member {number}
  15926. * @default PIXI.settings.SCALE_MODE
  15927. * @see PIXI.SCALE_MODES
  15928. */
  15929. this.scaleMode = scaleMode !== undefined ? scaleMode : _settings2.default.SCALE_MODE;
  15930. /**
  15931. * Whether this object is the root element or not
  15932. *
  15933. * @member {boolean}
  15934. */
  15935. this.root = root;
  15936. if (!this.root) {
  15937. this.frameBuffer = _pixiGlCore.GLFramebuffer.createRGBA(gl, 100, 100);
  15938. if (this.scaleMode === _const.SCALE_MODES.NEAREST) {
  15939. this.frameBuffer.texture.enableNearestScaling();
  15940. } else {
  15941. this.frameBuffer.texture.enableLinearScaling();
  15942. }
  15943. /*
  15944. A frame buffer needs a target to render to..
  15945. create a texture and bind it attach it to the framebuffer..
  15946. */
  15947. // this is used by the base texture
  15948. this.texture = this.frameBuffer.texture;
  15949. } else {
  15950. // make it a null framebuffer..
  15951. this.frameBuffer = new _pixiGlCore.GLFramebuffer(gl, 100, 100);
  15952. this.frameBuffer.framebuffer = null;
  15953. }
  15954. this.setFrame();
  15955. this.resize(width, height);
  15956. }
  15957. /**
  15958. * Clears the filter texture.
  15959. *
  15960. * @param {number[]} [clearColor=this.clearColor] - Array of [r,g,b,a] to clear the framebuffer
  15961. */
  15962. RenderTarget.prototype.clear = function clear(clearColor) {
  15963. var cc = clearColor || this.clearColor;
  15964. this.frameBuffer.clear(cc[0], cc[1], cc[2], cc[3]); // r,g,b,a);
  15965. };
  15966. /**
  15967. * Binds the stencil buffer.
  15968. *
  15969. */
  15970. RenderTarget.prototype.attachStencilBuffer = function attachStencilBuffer() {
  15971. // TODO check if stencil is done?
  15972. /**
  15973. * The stencil buffer is used for masking in pixi
  15974. * lets create one and then add attach it to the framebuffer..
  15975. */
  15976. if (!this.root) {
  15977. this.frameBuffer.enableStencil();
  15978. }
  15979. };
  15980. /**
  15981. * Sets the frame of the render target.
  15982. *
  15983. * @param {Rectangle} destinationFrame - The destination frame.
  15984. * @param {Rectangle} sourceFrame - The source frame.
  15985. */
  15986. RenderTarget.prototype.setFrame = function setFrame(destinationFrame, sourceFrame) {
  15987. this.destinationFrame = destinationFrame || this.destinationFrame || this.defaultFrame;
  15988. this.sourceFrame = sourceFrame || this.sourceFrame || this.destinationFrame;
  15989. };
  15990. /**
  15991. * Binds the buffers and initialises the viewport.
  15992. *
  15993. */
  15994. RenderTarget.prototype.activate = function activate() {
  15995. // TOOD refactor usage of frame..
  15996. var gl = this.gl;
  15997. // make sure the texture is unbound!
  15998. this.frameBuffer.bind();
  15999. this.calculateProjection(this.destinationFrame, this.sourceFrame);
  16000. if (this.transform) {
  16001. this.projectionMatrix.append(this.transform);
  16002. }
  16003. // TODO add a check as them may be the same!
  16004. if (this.destinationFrame !== this.sourceFrame) {
  16005. gl.enable(gl.SCISSOR_TEST);
  16006. gl.scissor(this.destinationFrame.x | 0, this.destinationFrame.y | 0, this.destinationFrame.width * this.resolution | 0, this.destinationFrame.height * this.resolution | 0);
  16007. } else {
  16008. gl.disable(gl.SCISSOR_TEST);
  16009. }
  16010. // TODO - does not need to be updated all the time??
  16011. gl.viewport(this.destinationFrame.x | 0, this.destinationFrame.y | 0, this.destinationFrame.width * this.resolution | 0, this.destinationFrame.height * this.resolution | 0);
  16012. };
  16013. /**
  16014. * Updates the projection matrix based on a projection frame (which is a rectangle)
  16015. *
  16016. * @param {Rectangle} destinationFrame - The destination frame.
  16017. * @param {Rectangle} sourceFrame - The source frame.
  16018. */
  16019. RenderTarget.prototype.calculateProjection = function calculateProjection(destinationFrame, sourceFrame) {
  16020. var pm = this.projectionMatrix;
  16021. sourceFrame = sourceFrame || destinationFrame;
  16022. pm.identity();
  16023. // TODO: make dest scale source
  16024. if (!this.root) {
  16025. pm.a = 1 / destinationFrame.width * 2;
  16026. pm.d = 1 / destinationFrame.height * 2;
  16027. pm.tx = -1 - sourceFrame.x * pm.a;
  16028. pm.ty = -1 - sourceFrame.y * pm.d;
  16029. } else {
  16030. pm.a = 1 / destinationFrame.width * 2;
  16031. pm.d = -1 / destinationFrame.height * 2;
  16032. pm.tx = -1 - sourceFrame.x * pm.a;
  16033. pm.ty = 1 - sourceFrame.y * pm.d;
  16034. }
  16035. };
  16036. /**
  16037. * Resizes the texture to the specified width and height
  16038. *
  16039. * @param {number} width - the new width of the texture
  16040. * @param {number} height - the new height of the texture
  16041. */
  16042. RenderTarget.prototype.resize = function resize(width, height) {
  16043. width = width | 0;
  16044. height = height | 0;
  16045. if (this.size.width === width && this.size.height === height) {
  16046. return;
  16047. }
  16048. this.size.width = width;
  16049. this.size.height = height;
  16050. this.defaultFrame.width = width;
  16051. this.defaultFrame.height = height;
  16052. this.frameBuffer.resize(width * this.resolution, height * this.resolution);
  16053. var projectionFrame = this.frame || this.size;
  16054. this.calculateProjection(projectionFrame);
  16055. };
  16056. /**
  16057. * Destroys the render target.
  16058. *
  16059. */
  16060. RenderTarget.prototype.destroy = function destroy() {
  16061. this.frameBuffer.destroy();
  16062. this.frameBuffer = null;
  16063. this.texture = null;
  16064. };
  16065. return RenderTarget;
  16066. }();
  16067. exports.default = RenderTarget;
  16068. }, { "../../../const": 46, "../../../math": 70, "../../../settings": 101, "pixi-gl-core": 15 }], 97: [function (require, module, exports) {
  16069. 'use strict';
  16070. exports.__esModule = true;
  16071. exports.default = checkMaxIfStatmentsInShader;
  16072. var _pixiGlCore = require('pixi-gl-core');
  16073. var _pixiGlCore2 = _interopRequireDefault(_pixiGlCore);
  16074. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  16075. var fragTemplate = ['precision mediump float;', 'void main(void){', 'float test = 0.1;', '%forloop%', 'gl_FragColor = vec4(0.0);', '}'].join('\n');
  16076. function checkMaxIfStatmentsInShader(maxIfs, gl) {
  16077. var createTempContext = !gl;
  16078. if (maxIfs === 0) {
  16079. throw new Error('Invalid value of `0` passed to `checkMaxIfStatementsInShader`');
  16080. }
  16081. if (createTempContext) {
  16082. var tinyCanvas = document.createElement('canvas');
  16083. tinyCanvas.width = 1;
  16084. tinyCanvas.height = 1;
  16085. gl = _pixiGlCore2.default.createContext(tinyCanvas);
  16086. }
  16087. var shader = gl.createShader(gl.FRAGMENT_SHADER);
  16088. while (true) // eslint-disable-line no-constant-condition
  16089. {
  16090. var fragmentSrc = fragTemplate.replace(/%forloop%/gi, generateIfTestSrc(maxIfs));
  16091. gl.shaderSource(shader, fragmentSrc);
  16092. gl.compileShader(shader);
  16093. if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
  16094. maxIfs = maxIfs / 2 | 0;
  16095. } else {
  16096. // valid!
  16097. break;
  16098. }
  16099. }
  16100. if (createTempContext) {
  16101. // get rid of context
  16102. if (gl.getExtension('WEBGL_lose_context')) {
  16103. gl.getExtension('WEBGL_lose_context').loseContext();
  16104. }
  16105. }
  16106. return maxIfs;
  16107. }
  16108. function generateIfTestSrc(maxIfs) {
  16109. var src = '';
  16110. for (var i = 0; i < maxIfs; ++i) {
  16111. if (i > 0) {
  16112. src += '\nelse ';
  16113. }
  16114. if (i < maxIfs - 1) {
  16115. src += 'if(test == ' + i + '.0){}';
  16116. }
  16117. }
  16118. return src;
  16119. }
  16120. }, { "pixi-gl-core": 15 }], 98: [function (require, module, exports) {
  16121. 'use strict';
  16122. exports.__esModule = true;
  16123. exports.default = mapWebGLBlendModesToPixi;
  16124. var _const = require('../../../const');
  16125. /**
  16126. * Maps gl blend combinations to WebGL.
  16127. *
  16128. * @memberof PIXI
  16129. * @function mapWebGLBlendModesToPixi
  16130. * @private
  16131. * @param {WebGLRenderingContext} gl - The rendering context.
  16132. * @param {string[]} [array=[]] - The array to output into.
  16133. * @return {string[]} Mapped modes.
  16134. */
  16135. function mapWebGLBlendModesToPixi(gl) {
  16136. var array = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
  16137. // TODO - premultiply alpha would be different.
  16138. // add a boolean for that!
  16139. array[_const.BLEND_MODES.NORMAL] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA];
  16140. array[_const.BLEND_MODES.ADD] = [gl.ONE, gl.DST_ALPHA];
  16141. array[_const.BLEND_MODES.MULTIPLY] = [gl.DST_COLOR, gl.ONE_MINUS_SRC_ALPHA];
  16142. array[_const.BLEND_MODES.SCREEN] = [gl.ONE, gl.ONE_MINUS_SRC_COLOR];
  16143. array[_const.BLEND_MODES.OVERLAY] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA];
  16144. array[_const.BLEND_MODES.DARKEN] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA];
  16145. array[_const.BLEND_MODES.LIGHTEN] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA];
  16146. array[_const.BLEND_MODES.COLOR_DODGE] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA];
  16147. array[_const.BLEND_MODES.COLOR_BURN] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA];
  16148. array[_const.BLEND_MODES.HARD_LIGHT] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA];
  16149. array[_const.BLEND_MODES.SOFT_LIGHT] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA];
  16150. array[_const.BLEND_MODES.DIFFERENCE] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA];
  16151. array[_const.BLEND_MODES.EXCLUSION] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA];
  16152. array[_const.BLEND_MODES.HUE] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA];
  16153. array[_const.BLEND_MODES.SATURATION] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA];
  16154. array[_const.BLEND_MODES.COLOR] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA];
  16155. array[_const.BLEND_MODES.LUMINOSITY] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA];
  16156. // not-premultiplied blend modes
  16157. array[_const.BLEND_MODES.NORMAL_NPM] = [gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA];
  16158. array[_const.BLEND_MODES.ADD_NPM] = [gl.SRC_ALPHA, gl.DST_ALPHA, gl.ONE, gl.DST_ALPHA];
  16159. array[_const.BLEND_MODES.SCREEN_NPM] = [gl.SRC_ALPHA, gl.ONE_MINUS_SRC_COLOR, gl.ONE, gl.ONE_MINUS_SRC_COLOR];
  16160. return array;
  16161. }
  16162. }, { "../../../const": 46 }], 99: [function (require, module, exports) {
  16163. 'use strict';
  16164. exports.__esModule = true;
  16165. exports.default = mapWebGLDrawModesToPixi;
  16166. var _const = require('../../../const');
  16167. /**
  16168. * Generic Mask Stack data structure.
  16169. *
  16170. * @memberof PIXI
  16171. * @function mapWebGLDrawModesToPixi
  16172. * @private
  16173. * @param {WebGLRenderingContext} gl - The current WebGL drawing context
  16174. * @param {object} [object={}] - The object to map into
  16175. * @return {object} The mapped draw modes.
  16176. */
  16177. function mapWebGLDrawModesToPixi(gl) {
  16178. var object = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  16179. object[_const.DRAW_MODES.POINTS] = gl.POINTS;
  16180. object[_const.DRAW_MODES.LINES] = gl.LINES;
  16181. object[_const.DRAW_MODES.LINE_LOOP] = gl.LINE_LOOP;
  16182. object[_const.DRAW_MODES.LINE_STRIP] = gl.LINE_STRIP;
  16183. object[_const.DRAW_MODES.TRIANGLES] = gl.TRIANGLES;
  16184. object[_const.DRAW_MODES.TRIANGLE_STRIP] = gl.TRIANGLE_STRIP;
  16185. object[_const.DRAW_MODES.TRIANGLE_FAN] = gl.TRIANGLE_FAN;
  16186. return object;
  16187. }
  16188. }, { "../../../const": 46 }], 100: [function (require, module, exports) {
  16189. 'use strict';
  16190. exports.__esModule = true;
  16191. exports.default = validateContext;
  16192. function validateContext(gl) {
  16193. var attributes = gl.getContextAttributes();
  16194. // this is going to be fairly simple for now.. but at least we have room to grow!
  16195. if (!attributes.stencil) {
  16196. /* eslint-disable no-console */
  16197. console.warn('Provided WebGL context does not have a stencil buffer, masks may not render correctly');
  16198. /* eslint-enable no-console */
  16199. }
  16200. }
  16201. }, {}], 101: [function (require, module, exports) {
  16202. 'use strict';
  16203. exports.__esModule = true;
  16204. var _maxRecommendedTextures = require('./utils/maxRecommendedTextures');
  16205. var _maxRecommendedTextures2 = _interopRequireDefault(_maxRecommendedTextures);
  16206. var _canUploadSameBuffer = require('./utils/canUploadSameBuffer');
  16207. var _canUploadSameBuffer2 = _interopRequireDefault(_canUploadSameBuffer);
  16208. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  16209. /**
  16210. * User's customizable globals for overriding the default PIXI settings, such
  16211. * as a renderer's default resolution, framerate, float percision, etc.
  16212. * @example
  16213. * // Use the native window resolution as the default resolution
  16214. * // will support high-density displays when rendering
  16215. * PIXI.settings.RESOLUTION = window.devicePixelRatio.
  16216. *
  16217. * // Disable interpolation when scaling, will make texture be pixelated
  16218. * PIXI.settings.SCALE_MODE = PIXI.SCALE_MODES.NEAREST;
  16219. * @namespace PIXI.settings
  16220. */
  16221. exports.default = {
  16222. /**
  16223. * Target frames per millisecond.
  16224. *
  16225. * @static
  16226. * @memberof PIXI.settings
  16227. * @type {number}
  16228. * @default 0.06
  16229. */
  16230. TARGET_FPMS: 0.06,
  16231. /**
  16232. * If set to true WebGL will attempt make textures mimpaped by default.
  16233. * Mipmapping will only succeed if the base texture uploaded has power of two dimensions.
  16234. *
  16235. * @static
  16236. * @memberof PIXI.settings
  16237. * @type {boolean}
  16238. * @default true
  16239. */
  16240. MIPMAP_TEXTURES: true,
  16241. /**
  16242. * Default resolution / device pixel ratio of the renderer.
  16243. *
  16244. * @static
  16245. * @memberof PIXI.settings
  16246. * @type {number}
  16247. * @default 1
  16248. */
  16249. RESOLUTION: 1,
  16250. /**
  16251. * Default filter resolution.
  16252. *
  16253. * @static
  16254. * @memberof PIXI.settings
  16255. * @type {number}
  16256. * @default 1
  16257. */
  16258. FILTER_RESOLUTION: 1,
  16259. /**
  16260. * The maximum textures that this device supports.
  16261. *
  16262. * @static
  16263. * @memberof PIXI.settings
  16264. * @type {number}
  16265. * @default 32
  16266. */
  16267. SPRITE_MAX_TEXTURES: (0, _maxRecommendedTextures2.default)(32),
  16268. // TODO: maybe change to SPRITE.BATCH_SIZE: 2000
  16269. // TODO: maybe add PARTICLE.BATCH_SIZE: 15000
  16270. /**
  16271. * The default sprite batch size.
  16272. *
  16273. * The default aims to balance desktop and mobile devices.
  16274. *
  16275. * @static
  16276. * @memberof PIXI.settings
  16277. * @type {number}
  16278. * @default 4096
  16279. */
  16280. SPRITE_BATCH_SIZE: 4096,
  16281. /**
  16282. * The prefix that denotes a URL is for a retina asset.
  16283. *
  16284. * @static
  16285. * @memberof PIXI.settings
  16286. * @type {RegExp}
  16287. * @example `@2x`
  16288. * @default /@([0-9\.]+)x/
  16289. */
  16290. RETINA_PREFIX: /@([0-9\.]+)x/,
  16291. /**
  16292. * The default render options if none are supplied to {@link PIXI.WebGLRenderer}
  16293. * or {@link PIXI.CanvasRenderer}.
  16294. *
  16295. * @static
  16296. * @constant
  16297. * @memberof PIXI.settings
  16298. * @type {object}
  16299. * @property {HTMLCanvasElement} view=null
  16300. * @property {number} resolution=1
  16301. * @property {boolean} antialias=false
  16302. * @property {boolean} forceFXAA=false
  16303. * @property {boolean} autoResize=false
  16304. * @property {boolean} transparent=false
  16305. * @property {number} backgroundColor=0x000000
  16306. * @property {boolean} clearBeforeRender=true
  16307. * @property {boolean} preserveDrawingBuffer=false
  16308. * @property {boolean} roundPixels=false
  16309. * @property {number} width=800
  16310. * @property {number} height=600
  16311. * @property {boolean} legacy=false
  16312. */
  16313. RENDER_OPTIONS: {
  16314. view: null,
  16315. antialias: false,
  16316. forceFXAA: false,
  16317. autoResize: false,
  16318. transparent: false,
  16319. backgroundColor: 0x000000,
  16320. clearBeforeRender: true,
  16321. preserveDrawingBuffer: false,
  16322. roundPixels: false,
  16323. width: 800,
  16324. height: 600,
  16325. legacy: false
  16326. },
  16327. /**
  16328. * Default transform type.
  16329. *
  16330. * @static
  16331. * @memberof PIXI.settings
  16332. * @type {PIXI.TRANSFORM_MODE}
  16333. * @default PIXI.TRANSFORM_MODE.STATIC
  16334. */
  16335. TRANSFORM_MODE: 0,
  16336. /**
  16337. * Default Garbage Collection mode.
  16338. *
  16339. * @static
  16340. * @memberof PIXI.settings
  16341. * @type {PIXI.GC_MODES}
  16342. * @default PIXI.GC_MODES.AUTO
  16343. */
  16344. GC_MODE: 0,
  16345. /**
  16346. * Default Garbage Collection max idle.
  16347. *
  16348. * @static
  16349. * @memberof PIXI.settings
  16350. * @type {number}
  16351. * @default 3600
  16352. */
  16353. GC_MAX_IDLE: 60 * 60,
  16354. /**
  16355. * Default Garbage Collection maximum check count.
  16356. *
  16357. * @static
  16358. * @memberof PIXI.settings
  16359. * @type {number}
  16360. * @default 600
  16361. */
  16362. GC_MAX_CHECK_COUNT: 60 * 10,
  16363. /**
  16364. * Default wrap modes that are supported by pixi.
  16365. *
  16366. * @static
  16367. * @memberof PIXI.settings
  16368. * @type {PIXI.WRAP_MODES}
  16369. * @default PIXI.WRAP_MODES.CLAMP
  16370. */
  16371. WRAP_MODE: 0,
  16372. /**
  16373. * The scale modes that are supported by pixi.
  16374. *
  16375. * @static
  16376. * @memberof PIXI.settings
  16377. * @type {PIXI.SCALE_MODES}
  16378. * @default PIXI.SCALE_MODES.LINEAR
  16379. */
  16380. SCALE_MODE: 0,
  16381. /**
  16382. * Default specify float precision in vertex shader.
  16383. *
  16384. * @static
  16385. * @memberof PIXI.settings
  16386. * @type {PIXI.PRECISION}
  16387. * @default PIXI.PRECISION.HIGH
  16388. */
  16389. PRECISION_VERTEX: 'highp',
  16390. /**
  16391. * Default specify float precision in fragment shader.
  16392. *
  16393. * @static
  16394. * @memberof PIXI.settings
  16395. * @type {PIXI.PRECISION}
  16396. * @default PIXI.PRECISION.MEDIUM
  16397. */
  16398. PRECISION_FRAGMENT: 'mediump',
  16399. /**
  16400. * Can we upload the same buffer in a single frame?
  16401. *
  16402. * @static
  16403. * @constant
  16404. * @memberof PIXI.settings
  16405. * @type {boolean}
  16406. */
  16407. CAN_UPLOAD_SAME_BUFFER: (0, _canUploadSameBuffer2.default)(),
  16408. /**
  16409. * Default Mesh `canvasPadding`.
  16410. *
  16411. * @see PIXI.mesh.Mesh#canvasPadding
  16412. * @static
  16413. * @constant
  16414. * @memberof PIXI.settings
  16415. * @type {number}
  16416. */
  16417. MESH_CANVAS_PADDING: 0
  16418. };
  16419. }, { "./utils/canUploadSameBuffer": 122, "./utils/maxRecommendedTextures": 127 }], 102: [function (require, module, exports) {
  16420. 'use strict';
  16421. exports.__esModule = true;
  16422. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  16423. var _math = require('../math');
  16424. var _utils = require('../utils');
  16425. var _const = require('../const');
  16426. var _Texture = require('../textures/Texture');
  16427. var _Texture2 = _interopRequireDefault(_Texture);
  16428. var _Container2 = require('../display/Container');
  16429. var _Container3 = _interopRequireDefault(_Container2);
  16430. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  16431. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  16432. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  16433. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  16434. var tempPoint = new _math.Point();
  16435. /**
  16436. * The Sprite object is the base for all textured objects that are rendered to the screen
  16437. *
  16438. * A sprite can be created directly from an image like this:
  16439. *
  16440. * ```js
  16441. * let sprite = new PIXI.Sprite.fromImage('assets/image.png');
  16442. * ```
  16443. *
  16444. * @class
  16445. * @extends PIXI.Container
  16446. * @memberof PIXI
  16447. */
  16448. var Sprite = function (_Container) {
  16449. _inherits(Sprite, _Container);
  16450. /**
  16451. * @param {PIXI.Texture} texture - The texture for this sprite
  16452. */
  16453. function Sprite(texture) {
  16454. _classCallCheck(this, Sprite);
  16455. /**
  16456. * The anchor sets the origin point of the texture.
  16457. * The default is 0,0 this means the texture's origin is the top left
  16458. * Setting the anchor to 0.5,0.5 means the texture's origin is centered
  16459. * Setting the anchor to 1,1 would mean the texture's origin point will be the bottom right corner
  16460. *
  16461. * @member {PIXI.ObservablePoint}
  16462. * @private
  16463. */
  16464. var _this = _possibleConstructorReturn(this, _Container.call(this));
  16465. _this._anchor = new _math.ObservablePoint(_this._onAnchorUpdate, _this);
  16466. /**
  16467. * The texture that the sprite is using
  16468. *
  16469. * @private
  16470. * @member {PIXI.Texture}
  16471. */
  16472. _this._texture = null;
  16473. /**
  16474. * The width of the sprite (this is initially set by the texture)
  16475. *
  16476. * @private
  16477. * @member {number}
  16478. */
  16479. _this._width = 0;
  16480. /**
  16481. * The height of the sprite (this is initially set by the texture)
  16482. *
  16483. * @private
  16484. * @member {number}
  16485. */
  16486. _this._height = 0;
  16487. /**
  16488. * The tint applied to the sprite. This is a hex value. A value of 0xFFFFFF will remove any tint effect.
  16489. *
  16490. * @private
  16491. * @member {number}
  16492. * @default 0xFFFFFF
  16493. */
  16494. _this._tint = null;
  16495. _this._tintRGB = null;
  16496. _this.tint = 0xFFFFFF;
  16497. /**
  16498. * The blend mode to be applied to the sprite. Apply a value of `PIXI.BLEND_MODES.NORMAL` to reset the blend mode.
  16499. *
  16500. * @member {number}
  16501. * @default PIXI.BLEND_MODES.NORMAL
  16502. * @see PIXI.BLEND_MODES
  16503. */
  16504. _this.blendMode = _const.BLEND_MODES.NORMAL;
  16505. /**
  16506. * The shader that will be used to render the sprite. Set to null to remove a current shader.
  16507. *
  16508. * @member {PIXI.Filter|PIXI.Shader}
  16509. */
  16510. _this.shader = null;
  16511. /**
  16512. * An internal cached value of the tint.
  16513. *
  16514. * @private
  16515. * @member {number}
  16516. * @default 0xFFFFFF
  16517. */
  16518. _this.cachedTint = 0xFFFFFF;
  16519. // call texture setter
  16520. _this.texture = texture || _Texture2.default.EMPTY;
  16521. /**
  16522. * this is used to store the vertex data of the sprite (basically a quad)
  16523. *
  16524. * @private
  16525. * @member {Float32Array}
  16526. */
  16527. _this.vertexData = new Float32Array(8);
  16528. /**
  16529. * This is used to calculate the bounds of the object IF it is a trimmed sprite
  16530. *
  16531. * @private
  16532. * @member {Float32Array}
  16533. */
  16534. _this.vertexTrimmedData = null;
  16535. _this._transformID = -1;
  16536. _this._textureID = -1;
  16537. _this._transformTrimmedID = -1;
  16538. _this._textureTrimmedID = -1;
  16539. /**
  16540. * Plugin that is responsible for rendering this element.
  16541. * Allows to customize the rendering process without overriding '_renderWebGL' & '_renderCanvas' methods.
  16542. *
  16543. * @member {string}
  16544. * @default 'sprite'
  16545. */
  16546. _this.pluginName = 'sprite';
  16547. return _this;
  16548. }
  16549. /**
  16550. * When the texture is updated, this event will fire to update the scale and frame
  16551. *
  16552. * @private
  16553. */
  16554. Sprite.prototype._onTextureUpdate = function _onTextureUpdate() {
  16555. this._textureID = -1;
  16556. this._textureTrimmedID = -1;
  16557. this.cachedTint = 0xFFFFFF;
  16558. // so if _width is 0 then width was not set..
  16559. if (this._width) {
  16560. this.scale.x = (0, _utils.sign)(this.scale.x) * this._width / this._texture.orig.width;
  16561. }
  16562. if (this._height) {
  16563. this.scale.y = (0, _utils.sign)(this.scale.y) * this._height / this._texture.orig.height;
  16564. }
  16565. };
  16566. /**
  16567. * Called when the anchor position updates.
  16568. *
  16569. * @private
  16570. */
  16571. Sprite.prototype._onAnchorUpdate = function _onAnchorUpdate() {
  16572. this._transformID = -1;
  16573. this._transformTrimmedID = -1;
  16574. };
  16575. /**
  16576. * calculates worldTransform * vertices, store it in vertexData
  16577. */
  16578. Sprite.prototype.calculateVertices = function calculateVertices() {
  16579. if (this._transformID === this.transform._worldID && this._textureID === this._texture._updateID) {
  16580. return;
  16581. }
  16582. this._transformID = this.transform._worldID;
  16583. this._textureID = this._texture._updateID;
  16584. // set the vertex data
  16585. var texture = this._texture;
  16586. var wt = this.transform.worldTransform;
  16587. var a = wt.a;
  16588. var b = wt.b;
  16589. var c = wt.c;
  16590. var d = wt.d;
  16591. var tx = wt.tx;
  16592. var ty = wt.ty;
  16593. var vertexData = this.vertexData;
  16594. var trim = texture.trim;
  16595. var orig = texture.orig;
  16596. var anchor = this._anchor;
  16597. var w0 = 0;
  16598. var w1 = 0;
  16599. var h0 = 0;
  16600. var h1 = 0;
  16601. if (trim) {
  16602. // if the sprite is trimmed and is not a tilingsprite then we need to add the extra
  16603. // space before transforming the sprite coords.
  16604. w1 = trim.x - anchor._x * orig.width;
  16605. w0 = w1 + trim.width;
  16606. h1 = trim.y - anchor._y * orig.height;
  16607. h0 = h1 + trim.height;
  16608. } else {
  16609. w1 = -anchor._x * orig.width;
  16610. w0 = w1 + orig.width;
  16611. h1 = -anchor._y * orig.height;
  16612. h0 = h1 + orig.height;
  16613. }
  16614. // xy
  16615. vertexData[0] = a * w1 + c * h1 + tx;
  16616. vertexData[1] = d * h1 + b * w1 + ty;
  16617. // xy
  16618. vertexData[2] = a * w0 + c * h1 + tx;
  16619. vertexData[3] = d * h1 + b * w0 + ty;
  16620. // xy
  16621. vertexData[4] = a * w0 + c * h0 + tx;
  16622. vertexData[5] = d * h0 + b * w0 + ty;
  16623. // xy
  16624. vertexData[6] = a * w1 + c * h0 + tx;
  16625. vertexData[7] = d * h0 + b * w1 + ty;
  16626. };
  16627. /**
  16628. * calculates worldTransform * vertices for a non texture with a trim. store it in vertexTrimmedData
  16629. * This is used to ensure that the true width and height of a trimmed texture is respected
  16630. */
  16631. Sprite.prototype.calculateTrimmedVertices = function calculateTrimmedVertices() {
  16632. if (!this.vertexTrimmedData) {
  16633. this.vertexTrimmedData = new Float32Array(8);
  16634. } else if (this._transformTrimmedID === this.transform._worldID && this._textureTrimmedID === this._texture._updateID) {
  16635. return;
  16636. }
  16637. this._transformTrimmedID = this.transform._worldID;
  16638. this._textureTrimmedID = this._texture._updateID;
  16639. // lets do some special trim code!
  16640. var texture = this._texture;
  16641. var vertexData = this.vertexTrimmedData;
  16642. var orig = texture.orig;
  16643. var anchor = this._anchor;
  16644. // lets calculate the new untrimmed bounds..
  16645. var wt = this.transform.worldTransform;
  16646. var a = wt.a;
  16647. var b = wt.b;
  16648. var c = wt.c;
  16649. var d = wt.d;
  16650. var tx = wt.tx;
  16651. var ty = wt.ty;
  16652. var w1 = -anchor._x * orig.width;
  16653. var w0 = w1 + orig.width;
  16654. var h1 = -anchor._y * orig.height;
  16655. var h0 = h1 + orig.height;
  16656. // xy
  16657. vertexData[0] = a * w1 + c * h1 + tx;
  16658. vertexData[1] = d * h1 + b * w1 + ty;
  16659. // xy
  16660. vertexData[2] = a * w0 + c * h1 + tx;
  16661. vertexData[3] = d * h1 + b * w0 + ty;
  16662. // xy
  16663. vertexData[4] = a * w0 + c * h0 + tx;
  16664. vertexData[5] = d * h0 + b * w0 + ty;
  16665. // xy
  16666. vertexData[6] = a * w1 + c * h0 + tx;
  16667. vertexData[7] = d * h0 + b * w1 + ty;
  16668. };
  16669. /**
  16670. *
  16671. * Renders the object using the WebGL renderer
  16672. *
  16673. * @private
  16674. * @param {PIXI.WebGLRenderer} renderer - The webgl renderer to use.
  16675. */
  16676. Sprite.prototype._renderWebGL = function _renderWebGL(renderer) {
  16677. this.calculateVertices();
  16678. renderer.setObjectRenderer(renderer.plugins[this.pluginName]);
  16679. renderer.plugins[this.pluginName].render(this);
  16680. };
  16681. /**
  16682. * Renders the object using the Canvas renderer
  16683. *
  16684. * @private
  16685. * @param {PIXI.CanvasRenderer} renderer - The renderer
  16686. */
  16687. Sprite.prototype._renderCanvas = function _renderCanvas(renderer) {
  16688. renderer.plugins[this.pluginName].render(this);
  16689. };
  16690. /**
  16691. * Updates the bounds of the sprite.
  16692. *
  16693. * @private
  16694. */
  16695. Sprite.prototype._calculateBounds = function _calculateBounds() {
  16696. var trim = this._texture.trim;
  16697. var orig = this._texture.orig;
  16698. // First lets check to see if the current texture has a trim..
  16699. if (!trim || trim.width === orig.width && trim.height === orig.height) {
  16700. // no trim! lets use the usual calculations..
  16701. this.calculateVertices();
  16702. this._bounds.addQuad(this.vertexData);
  16703. } else {
  16704. // lets calculate a special trimmed bounds...
  16705. this.calculateTrimmedVertices();
  16706. this._bounds.addQuad(this.vertexTrimmedData);
  16707. }
  16708. };
  16709. /**
  16710. * Gets the local bounds of the sprite object.
  16711. *
  16712. * @param {PIXI.Rectangle} rect - The output rectangle.
  16713. * @return {PIXI.Rectangle} The bounds.
  16714. */
  16715. Sprite.prototype.getLocalBounds = function getLocalBounds(rect) {
  16716. // we can do a fast local bounds if the sprite has no children!
  16717. if (this.children.length === 0) {
  16718. this._bounds.minX = this._texture.orig.width * -this._anchor._x;
  16719. this._bounds.minY = this._texture.orig.height * -this._anchor._y;
  16720. this._bounds.maxX = this._texture.orig.width * (1 - this._anchor._x);
  16721. this._bounds.maxY = this._texture.orig.height * (1 - this._anchor._y);
  16722. if (!rect) {
  16723. if (!this._localBoundsRect) {
  16724. this._localBoundsRect = new _math.Rectangle();
  16725. }
  16726. rect = this._localBoundsRect;
  16727. }
  16728. return this._bounds.getRectangle(rect);
  16729. }
  16730. return _Container.prototype.getLocalBounds.call(this, rect);
  16731. };
  16732. /**
  16733. * Tests if a point is inside this sprite
  16734. *
  16735. * @param {PIXI.Point} point - the point to test
  16736. * @return {boolean} the result of the test
  16737. */
  16738. Sprite.prototype.containsPoint = function containsPoint(point) {
  16739. this.worldTransform.applyInverse(point, tempPoint);
  16740. var width = this._texture.orig.width;
  16741. var height = this._texture.orig.height;
  16742. var x1 = -width * this.anchor.x;
  16743. var y1 = 0;
  16744. if (tempPoint.x >= x1 && tempPoint.x < x1 + width) {
  16745. y1 = -height * this.anchor.y;
  16746. if (tempPoint.y >= y1 && tempPoint.y < y1 + height) {
  16747. return true;
  16748. }
  16749. }
  16750. return false;
  16751. };
  16752. /**
  16753. * Destroys this sprite and optionally its texture and children
  16754. *
  16755. * @param {object|boolean} [options] - Options parameter. A boolean will act as if all options
  16756. * have been set to that value
  16757. * @param {boolean} [options.children=false] - if set to true, all the children will have their destroy
  16758. * method called as well. 'options' will be passed on to those calls.
  16759. * @param {boolean} [options.texture=false] - Should it destroy the current texture of the sprite as well
  16760. * @param {boolean} [options.baseTexture=false] - Should it destroy the base texture of the sprite as well
  16761. */
  16762. Sprite.prototype.destroy = function destroy(options) {
  16763. _Container.prototype.destroy.call(this, options);
  16764. this._anchor = null;
  16765. var destroyTexture = typeof options === 'boolean' ? options : options && options.texture;
  16766. if (destroyTexture) {
  16767. var destroyBaseTexture = typeof options === 'boolean' ? options : options && options.baseTexture;
  16768. this._texture.destroy(!!destroyBaseTexture);
  16769. }
  16770. this._texture = null;
  16771. this.shader = null;
  16772. };
  16773. // some helper functions..
  16774. /**
  16775. * Helper function that creates a new sprite based on the source you provide.
  16776. * The source can be - frame id, image url, video url, canvas element, video element, base texture
  16777. *
  16778. * @static
  16779. * @param {number|string|PIXI.BaseTexture|HTMLCanvasElement|HTMLVideoElement} source Source to create texture from
  16780. * @return {PIXI.Sprite} The newly created sprite
  16781. */
  16782. Sprite.from = function from(source) {
  16783. return new Sprite(_Texture2.default.from(source));
  16784. };
  16785. /**
  16786. * Helper function that creates a sprite that will contain a texture from the TextureCache based on the frameId
  16787. * The frame ids are created when a Texture packer file has been loaded
  16788. *
  16789. * @static
  16790. * @param {string} frameId - The frame Id of the texture in the cache
  16791. * @return {PIXI.Sprite} A new Sprite using a texture from the texture cache matching the frameId
  16792. */
  16793. Sprite.fromFrame = function fromFrame(frameId) {
  16794. var texture = _utils.TextureCache[frameId];
  16795. if (!texture) {
  16796. throw new Error('The frameId "' + frameId + '" does not exist in the texture cache');
  16797. }
  16798. return new Sprite(texture);
  16799. };
  16800. /**
  16801. * Helper function that creates a sprite that will contain a texture based on an image url
  16802. * If the image is not in the texture cache it will be loaded
  16803. *
  16804. * @static
  16805. * @param {string} imageId - The image url of the texture
  16806. * @param {boolean} [crossorigin=(auto)] - if you want to specify the cross-origin parameter
  16807. * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - if you want to specify the scale mode,
  16808. * see {@link PIXI.SCALE_MODES} for possible values
  16809. * @return {PIXI.Sprite} A new Sprite using a texture from the texture cache matching the image id
  16810. */
  16811. Sprite.fromImage = function fromImage(imageId, crossorigin, scaleMode) {
  16812. return new Sprite(_Texture2.default.fromImage(imageId, crossorigin, scaleMode));
  16813. };
  16814. /**
  16815. * The width of the sprite, setting this will actually modify the scale to achieve the value set
  16816. *
  16817. * @member {number}
  16818. */
  16819. _createClass(Sprite, [{
  16820. key: 'width',
  16821. get: function get() {
  16822. return Math.abs(this.scale.x) * this._texture.orig.width;
  16823. },
  16824. set: function set(value) // eslint-disable-line require-jsdoc
  16825. {
  16826. var s = (0, _utils.sign)(this.scale.x) || 1;
  16827. this.scale.x = s * value / this._texture.orig.width;
  16828. this._width = value;
  16829. }
  16830. /**
  16831. * The height of the sprite, setting this will actually modify the scale to achieve the value set
  16832. *
  16833. * @member {number}
  16834. */
  16835. }, {
  16836. key: 'height',
  16837. get: function get() {
  16838. return Math.abs(this.scale.y) * this._texture.orig.height;
  16839. },
  16840. set: function set(value) // eslint-disable-line require-jsdoc
  16841. {
  16842. var s = (0, _utils.sign)(this.scale.y) || 1;
  16843. this.scale.y = s * value / this._texture.orig.height;
  16844. this._height = value;
  16845. }
  16846. /**
  16847. * The anchor sets the origin point of the texture.
  16848. * The default is 0,0 this means the texture's origin is the top left
  16849. * Setting the anchor to 0.5,0.5 means the texture's origin is centered
  16850. * Setting the anchor to 1,1 would mean the texture's origin point will be the bottom right corner
  16851. *
  16852. * @member {PIXI.ObservablePoint}
  16853. */
  16854. }, {
  16855. key: 'anchor',
  16856. get: function get() {
  16857. return this._anchor;
  16858. },
  16859. set: function set(value) // eslint-disable-line require-jsdoc
  16860. {
  16861. this._anchor.copy(value);
  16862. }
  16863. /**
  16864. * The tint applied to the sprite. This is a hex value.
  16865. * A value of 0xFFFFFF will remove any tint effect.
  16866. *
  16867. * @member {number}
  16868. * @default 0xFFFFFF
  16869. */
  16870. }, {
  16871. key: 'tint',
  16872. get: function get() {
  16873. return this._tint;
  16874. },
  16875. set: function set(value) // eslint-disable-line require-jsdoc
  16876. {
  16877. this._tint = value;
  16878. this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16);
  16879. }
  16880. /**
  16881. * The texture that the sprite is using
  16882. *
  16883. * @member {PIXI.Texture}
  16884. */
  16885. }, {
  16886. key: 'texture',
  16887. get: function get() {
  16888. return this._texture;
  16889. },
  16890. set: function set(value) // eslint-disable-line require-jsdoc
  16891. {
  16892. if (this._texture === value) {
  16893. return;
  16894. }
  16895. this._texture = value;
  16896. this.cachedTint = 0xFFFFFF;
  16897. this._textureID = -1;
  16898. this._textureTrimmedID = -1;
  16899. if (value) {
  16900. // wait for the texture to load
  16901. if (value.baseTexture.hasLoaded) {
  16902. this._onTextureUpdate();
  16903. } else {
  16904. value.once('update', this._onTextureUpdate, this);
  16905. }
  16906. }
  16907. }
  16908. }]);
  16909. return Sprite;
  16910. }(_Container3.default);
  16911. exports.default = Sprite;
  16912. }, { "../const": 46, "../display/Container": 48, "../math": 70, "../textures/Texture": 115, "../utils": 125 }], 103: [function (require, module, exports) {
  16913. 'use strict';
  16914. exports.__esModule = true;
  16915. var _CanvasRenderer = require('../../renderers/canvas/CanvasRenderer');
  16916. var _CanvasRenderer2 = _interopRequireDefault(_CanvasRenderer);
  16917. var _const = require('../../const');
  16918. var _math = require('../../math');
  16919. var _CanvasTinter = require('./CanvasTinter');
  16920. var _CanvasTinter2 = _interopRequireDefault(_CanvasTinter);
  16921. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  16922. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  16923. var canvasRenderWorldTransform = new _math.Matrix();
  16924. /**
  16925. * @author Mat Groves
  16926. *
  16927. * Big thanks to the very clever Matt DesLauriers <mattdesl> https://github.com/mattdesl/
  16928. * for creating the original PixiJS version!
  16929. * Also a thanks to https://github.com/bchevalier for tweaking the tint and alpha so that they now
  16930. * share 4 bytes on the vertex buffer
  16931. *
  16932. * Heavily inspired by LibGDX's CanvasSpriteRenderer:
  16933. * https://github.com/libgdx/libgdx/blob/master/gdx/src/com/badlogic/gdx/graphics/g2d/CanvasSpriteRenderer.java
  16934. */
  16935. /**
  16936. * Renderer dedicated to drawing and batching sprites.
  16937. *
  16938. * @class
  16939. * @private
  16940. * @memberof PIXI
  16941. */
  16942. var CanvasSpriteRenderer = function () {
  16943. /**
  16944. * @param {PIXI.WebGLRenderer} renderer -The renderer sprite this batch works for.
  16945. */
  16946. function CanvasSpriteRenderer(renderer) {
  16947. _classCallCheck(this, CanvasSpriteRenderer);
  16948. this.renderer = renderer;
  16949. }
  16950. /**
  16951. * Renders the sprite object.
  16952. *
  16953. * @param {PIXI.Sprite} sprite - the sprite to render when using this spritebatch
  16954. */
  16955. CanvasSpriteRenderer.prototype.render = function render(sprite) {
  16956. var texture = sprite._texture;
  16957. var renderer = this.renderer;
  16958. var width = texture._frame.width;
  16959. var height = texture._frame.height;
  16960. var wt = sprite.transform.worldTransform;
  16961. var dx = 0;
  16962. var dy = 0;
  16963. if (texture.orig.width <= 0 || texture.orig.height <= 0 || !texture.baseTexture.source) {
  16964. return;
  16965. }
  16966. renderer.setBlendMode(sprite.blendMode);
  16967. // Ignore null sources
  16968. if (texture.valid) {
  16969. renderer.context.globalAlpha = sprite.worldAlpha;
  16970. // If smoothingEnabled is supported and we need to change the smoothing property for sprite texture
  16971. var smoothingEnabled = texture.baseTexture.scaleMode === _const.SCALE_MODES.LINEAR;
  16972. if (renderer.smoothProperty && renderer.context[renderer.smoothProperty] !== smoothingEnabled) {
  16973. renderer.context[renderer.smoothProperty] = smoothingEnabled;
  16974. }
  16975. if (texture.trim) {
  16976. dx = texture.trim.width / 2 + texture.trim.x - sprite.anchor.x * texture.orig.width;
  16977. dy = texture.trim.height / 2 + texture.trim.y - sprite.anchor.y * texture.orig.height;
  16978. } else {
  16979. dx = (0.5 - sprite.anchor.x) * texture.orig.width;
  16980. dy = (0.5 - sprite.anchor.y) * texture.orig.height;
  16981. }
  16982. if (texture.rotate) {
  16983. wt.copy(canvasRenderWorldTransform);
  16984. wt = canvasRenderWorldTransform;
  16985. _math.GroupD8.matrixAppendRotationInv(wt, texture.rotate, dx, dy);
  16986. // the anchor has already been applied above, so lets set it to zero
  16987. dx = 0;
  16988. dy = 0;
  16989. }
  16990. dx -= width / 2;
  16991. dy -= height / 2;
  16992. // Allow for pixel rounding
  16993. if (renderer.roundPixels) {
  16994. renderer.context.setTransform(wt.a, wt.b, wt.c, wt.d, wt.tx * renderer.resolution | 0, wt.ty * renderer.resolution | 0);
  16995. dx = dx | 0;
  16996. dy = dy | 0;
  16997. } else {
  16998. renderer.context.setTransform(wt.a, wt.b, wt.c, wt.d, wt.tx * renderer.resolution, wt.ty * renderer.resolution);
  16999. }
  17000. var resolution = texture.baseTexture.resolution;
  17001. if (sprite.tint !== 0xFFFFFF) {
  17002. if (sprite.cachedTint !== sprite.tint || sprite.tintedTexture.tintId !== sprite._texture._updateID) {
  17003. sprite.cachedTint = sprite.tint;
  17004. // TODO clean up caching - how to clean up the caches?
  17005. sprite.tintedTexture = _CanvasTinter2.default.getTintedTexture(sprite, sprite.tint);
  17006. }
  17007. renderer.context.drawImage(sprite.tintedTexture, 0, 0, width * resolution, height * resolution, dx * renderer.resolution, dy * renderer.resolution, width * renderer.resolution, height * renderer.resolution);
  17008. } else {
  17009. renderer.context.drawImage(texture.baseTexture.source, texture._frame.x * resolution, texture._frame.y * resolution, width * resolution, height * resolution, dx * renderer.resolution, dy * renderer.resolution, width * renderer.resolution, height * renderer.resolution);
  17010. }
  17011. }
  17012. };
  17013. /**
  17014. * destroy the sprite object.
  17015. *
  17016. */
  17017. CanvasSpriteRenderer.prototype.destroy = function destroy() {
  17018. this.renderer = null;
  17019. };
  17020. return CanvasSpriteRenderer;
  17021. }();
  17022. exports.default = CanvasSpriteRenderer;
  17023. _CanvasRenderer2.default.registerPlugin('sprite', CanvasSpriteRenderer);
  17024. }, { "../../const": 46, "../../math": 70, "../../renderers/canvas/CanvasRenderer": 77, "./CanvasTinter": 104 }], 104: [function (require, module, exports) {
  17025. 'use strict';
  17026. exports.__esModule = true;
  17027. var _utils = require('../../utils');
  17028. var _canUseNewCanvasBlendModes = require('../../renderers/canvas/utils/canUseNewCanvasBlendModes');
  17029. var _canUseNewCanvasBlendModes2 = _interopRequireDefault(_canUseNewCanvasBlendModes);
  17030. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  17031. /**
  17032. * Utility methods for Sprite/Texture tinting.
  17033. *
  17034. * @class
  17035. * @memberof PIXI
  17036. */
  17037. var CanvasTinter = {
  17038. /**
  17039. * Basically this method just needs a sprite and a color and tints the sprite with the given color.
  17040. *
  17041. * @memberof PIXI.CanvasTinter
  17042. * @param {PIXI.Sprite} sprite - the sprite to tint
  17043. * @param {number} color - the color to use to tint the sprite with
  17044. * @return {HTMLCanvasElement} The tinted canvas
  17045. */
  17046. getTintedTexture: function getTintedTexture(sprite, color) {
  17047. var texture = sprite._texture;
  17048. color = CanvasTinter.roundColor(color);
  17049. var stringColor = '#' + ('00000' + (color | 0).toString(16)).substr(-6);
  17050. texture.tintCache = texture.tintCache || {};
  17051. var cachedTexture = texture.tintCache[stringColor];
  17052. var canvas = void 0;
  17053. if (cachedTexture) {
  17054. if (cachedTexture.tintId === texture._updateID) {
  17055. return texture.tintCache[stringColor];
  17056. }
  17057. canvas = texture.tintCache[stringColor];
  17058. } else {
  17059. canvas = CanvasTinter.canvas || document.createElement('canvas');
  17060. }
  17061. CanvasTinter.tintMethod(texture, color, canvas);
  17062. canvas.tintId = texture._updateID;
  17063. if (CanvasTinter.convertTintToImage) {
  17064. // is this better?
  17065. var tintImage = new Image();
  17066. tintImage.src = canvas.toDataURL();
  17067. texture.tintCache[stringColor] = tintImage;
  17068. } else {
  17069. texture.tintCache[stringColor] = canvas;
  17070. // if we are not converting the texture to an image then we need to lose the reference to the canvas
  17071. CanvasTinter.canvas = null;
  17072. }
  17073. return canvas;
  17074. },
  17075. /**
  17076. * Tint a texture using the 'multiply' operation.
  17077. *
  17078. * @memberof PIXI.CanvasTinter
  17079. * @param {PIXI.Texture} texture - the texture to tint
  17080. * @param {number} color - the color to use to tint the sprite with
  17081. * @param {HTMLCanvasElement} canvas - the current canvas
  17082. */
  17083. tintWithMultiply: function tintWithMultiply(texture, color, canvas) {
  17084. var context = canvas.getContext('2d');
  17085. var crop = texture._frame.clone();
  17086. var resolution = texture.baseTexture.resolution;
  17087. crop.x *= resolution;
  17088. crop.y *= resolution;
  17089. crop.width *= resolution;
  17090. crop.height *= resolution;
  17091. canvas.width = Math.ceil(crop.width);
  17092. canvas.height = Math.ceil(crop.height);
  17093. context.save();
  17094. context.fillStyle = '#' + ('00000' + (color | 0).toString(16)).substr(-6);
  17095. context.fillRect(0, 0, crop.width, crop.height);
  17096. context.globalCompositeOperation = 'multiply';
  17097. context.drawImage(texture.baseTexture.source, crop.x, crop.y, crop.width, crop.height, 0, 0, crop.width, crop.height);
  17098. context.globalCompositeOperation = 'destination-atop';
  17099. context.drawImage(texture.baseTexture.source, crop.x, crop.y, crop.width, crop.height, 0, 0, crop.width, crop.height);
  17100. context.restore();
  17101. },
  17102. /**
  17103. * Tint a texture using the 'overlay' operation.
  17104. *
  17105. * @memberof PIXI.CanvasTinter
  17106. * @param {PIXI.Texture} texture - the texture to tint
  17107. * @param {number} color - the color to use to tint the sprite with
  17108. * @param {HTMLCanvasElement} canvas - the current canvas
  17109. */
  17110. tintWithOverlay: function tintWithOverlay(texture, color, canvas) {
  17111. var context = canvas.getContext('2d');
  17112. var crop = texture._frame.clone();
  17113. var resolution = texture.baseTexture.resolution;
  17114. crop.x *= resolution;
  17115. crop.y *= resolution;
  17116. crop.width *= resolution;
  17117. crop.height *= resolution;
  17118. canvas.width = Math.ceil(crop.width);
  17119. canvas.height = Math.ceil(crop.height);
  17120. context.save();
  17121. context.globalCompositeOperation = 'copy';
  17122. context.fillStyle = '#' + ('00000' + (color | 0).toString(16)).substr(-6);
  17123. context.fillRect(0, 0, crop.width, crop.height);
  17124. context.globalCompositeOperation = 'destination-atop';
  17125. context.drawImage(texture.baseTexture.source, crop.x, crop.y, crop.width, crop.height, 0, 0, crop.width, crop.height);
  17126. // context.globalCompositeOperation = 'copy';
  17127. context.restore();
  17128. },
  17129. /**
  17130. * Tint a texture pixel per pixel.
  17131. *
  17132. * @memberof PIXI.CanvasTinter
  17133. * @param {PIXI.Texture} texture - the texture to tint
  17134. * @param {number} color - the color to use to tint the sprite with
  17135. * @param {HTMLCanvasElement} canvas - the current canvas
  17136. */
  17137. tintWithPerPixel: function tintWithPerPixel(texture, color, canvas) {
  17138. var context = canvas.getContext('2d');
  17139. var crop = texture._frame.clone();
  17140. var resolution = texture.baseTexture.resolution;
  17141. crop.x *= resolution;
  17142. crop.y *= resolution;
  17143. crop.width *= resolution;
  17144. crop.height *= resolution;
  17145. canvas.width = Math.ceil(crop.width);
  17146. canvas.height = Math.ceil(crop.height);
  17147. context.save();
  17148. context.globalCompositeOperation = 'copy';
  17149. context.drawImage(texture.baseTexture.source, crop.x, crop.y, crop.width, crop.height, 0, 0, crop.width, crop.height);
  17150. context.restore();
  17151. var rgbValues = (0, _utils.hex2rgb)(color);
  17152. var r = rgbValues[0];
  17153. var g = rgbValues[1];
  17154. var b = rgbValues[2];
  17155. var pixelData = context.getImageData(0, 0, crop.width, crop.height);
  17156. var pixels = pixelData.data;
  17157. for (var i = 0; i < pixels.length; i += 4) {
  17158. pixels[i + 0] *= r;
  17159. pixels[i + 1] *= g;
  17160. pixels[i + 2] *= b;
  17161. }
  17162. context.putImageData(pixelData, 0, 0);
  17163. },
  17164. /**
  17165. * Rounds the specified color according to the CanvasTinter.cacheStepsPerColorChannel.
  17166. *
  17167. * @memberof PIXI.CanvasTinter
  17168. * @param {number} color - the color to round, should be a hex color
  17169. * @return {number} The rounded color.
  17170. */
  17171. roundColor: function roundColor(color) {
  17172. var step = CanvasTinter.cacheStepsPerColorChannel;
  17173. var rgbValues = (0, _utils.hex2rgb)(color);
  17174. rgbValues[0] = Math.min(255, rgbValues[0] / step * step);
  17175. rgbValues[1] = Math.min(255, rgbValues[1] / step * step);
  17176. rgbValues[2] = Math.min(255, rgbValues[2] / step * step);
  17177. return (0, _utils.rgb2hex)(rgbValues);
  17178. },
  17179. /**
  17180. * Number of steps which will be used as a cap when rounding colors.
  17181. *
  17182. * @memberof PIXI.CanvasTinter
  17183. * @type {number}
  17184. */
  17185. cacheStepsPerColorChannel: 8,
  17186. /**
  17187. * Tint cache boolean flag.
  17188. *
  17189. * @memberof PIXI.CanvasTinter
  17190. * @type {boolean}
  17191. */
  17192. convertTintToImage: false,
  17193. /**
  17194. * Whether or not the Canvas BlendModes are supported, consequently the ability to tint using the multiply method.
  17195. *
  17196. * @memberof PIXI.CanvasTinter
  17197. * @type {boolean}
  17198. */
  17199. canUseMultiply: (0, _canUseNewCanvasBlendModes2.default)(),
  17200. /**
  17201. * The tinting method that will be used.
  17202. *
  17203. * @memberof PIXI.CanvasTinter
  17204. * @type {tintMethodFunctionType}
  17205. */
  17206. tintMethod: 0
  17207. };
  17208. CanvasTinter.tintMethod = CanvasTinter.canUseMultiply ? CanvasTinter.tintWithMultiply : CanvasTinter.tintWithPerPixel;
  17209. /**
  17210. * The tintMethod type.
  17211. *
  17212. * @memberof PIXI.CanvasTinter
  17213. * @callback tintMethodFunctionType
  17214. * @param texture {PIXI.Texture} the texture to tint
  17215. * @param color {number} the color to use to tint the sprite with
  17216. * @param canvas {HTMLCanvasElement} the current canvas
  17217. */
  17218. exports.default = CanvasTinter;
  17219. }, { "../../renderers/canvas/utils/canUseNewCanvasBlendModes": 80, "../../utils": 125 }], 105: [function (require, module, exports) {
  17220. "use strict";
  17221. exports.__esModule = true;
  17222. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  17223. /**
  17224. * @class
  17225. * @memberof PIXI
  17226. */
  17227. var Buffer = function () {
  17228. /**
  17229. * @param {number} size - The size of the buffer in bytes.
  17230. */
  17231. function Buffer(size) {
  17232. _classCallCheck(this, Buffer);
  17233. this.vertices = new ArrayBuffer(size);
  17234. /**
  17235. * View on the vertices as a Float32Array for positions
  17236. *
  17237. * @member {Float32Array}
  17238. */
  17239. this.float32View = new Float32Array(this.vertices);
  17240. /**
  17241. * View on the vertices as a Uint32Array for uvs
  17242. *
  17243. * @member {Float32Array}
  17244. */
  17245. this.uint32View = new Uint32Array(this.vertices);
  17246. }
  17247. /**
  17248. * Destroys the buffer.
  17249. *
  17250. */
  17251. Buffer.prototype.destroy = function destroy() {
  17252. this.vertices = null;
  17253. this.positions = null;
  17254. this.uvs = null;
  17255. this.colors = null;
  17256. };
  17257. return Buffer;
  17258. }();
  17259. exports.default = Buffer;
  17260. }, {}], 106: [function (require, module, exports) {
  17261. 'use strict';
  17262. exports.__esModule = true;
  17263. var _ObjectRenderer2 = require('../../renderers/webgl/utils/ObjectRenderer');
  17264. var _ObjectRenderer3 = _interopRequireDefault(_ObjectRenderer2);
  17265. var _WebGLRenderer = require('../../renderers/webgl/WebGLRenderer');
  17266. var _WebGLRenderer2 = _interopRequireDefault(_WebGLRenderer);
  17267. var _createIndicesForQuads = require('../../utils/createIndicesForQuads');
  17268. var _createIndicesForQuads2 = _interopRequireDefault(_createIndicesForQuads);
  17269. var _generateMultiTextureShader = require('./generateMultiTextureShader');
  17270. var _generateMultiTextureShader2 = _interopRequireDefault(_generateMultiTextureShader);
  17271. var _checkMaxIfStatmentsInShader = require('../../renderers/webgl/utils/checkMaxIfStatmentsInShader');
  17272. var _checkMaxIfStatmentsInShader2 = _interopRequireDefault(_checkMaxIfStatmentsInShader);
  17273. var _BatchBuffer = require('./BatchBuffer');
  17274. var _BatchBuffer2 = _interopRequireDefault(_BatchBuffer);
  17275. var _settings = require('../../settings');
  17276. var _settings2 = _interopRequireDefault(_settings);
  17277. var _utils = require('../../utils');
  17278. var _pixiGlCore = require('pixi-gl-core');
  17279. var _pixiGlCore2 = _interopRequireDefault(_pixiGlCore);
  17280. var _bitTwiddle = require('bit-twiddle');
  17281. var _bitTwiddle2 = _interopRequireDefault(_bitTwiddle);
  17282. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  17283. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  17284. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  17285. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  17286. var TICK = 0;
  17287. var TEXTURE_TICK = 0;
  17288. /**
  17289. * Renderer dedicated to drawing and batching sprites.
  17290. *
  17291. * @class
  17292. * @private
  17293. * @memberof PIXI
  17294. * @extends PIXI.ObjectRenderer
  17295. */
  17296. var SpriteRenderer = function (_ObjectRenderer) {
  17297. _inherits(SpriteRenderer, _ObjectRenderer);
  17298. /**
  17299. * @param {PIXI.WebGLRenderer} renderer - The renderer this sprite batch works for.
  17300. */
  17301. function SpriteRenderer(renderer) {
  17302. _classCallCheck(this, SpriteRenderer);
  17303. /**
  17304. * Number of values sent in the vertex buffer.
  17305. * aVertexPosition(2), aTextureCoord(1), aColor(1), aTextureId(1) = 5
  17306. *
  17307. * @member {number}
  17308. */
  17309. var _this = _possibleConstructorReturn(this, _ObjectRenderer.call(this, renderer));
  17310. _this.vertSize = 5;
  17311. /**
  17312. * The size of the vertex information in bytes.
  17313. *
  17314. * @member {number}
  17315. */
  17316. _this.vertByteSize = _this.vertSize * 4;
  17317. /**
  17318. * The number of images in the SpriteRenderer before it flushes.
  17319. *
  17320. * @member {number}
  17321. */
  17322. _this.size = _settings2.default.SPRITE_BATCH_SIZE; // 2000 is a nice balance between mobile / desktop
  17323. // the total number of bytes in our batch
  17324. // let numVerts = this.size * 4 * this.vertByteSize;
  17325. _this.buffers = [];
  17326. for (var i = 1; i <= _bitTwiddle2.default.nextPow2(_this.size); i *= 2) {
  17327. _this.buffers.push(new _BatchBuffer2.default(i * 4 * _this.vertByteSize));
  17328. }
  17329. /**
  17330. * Holds the indices of the geometry (quads) to draw
  17331. *
  17332. * @member {Uint16Array}
  17333. */
  17334. _this.indices = (0, _createIndicesForQuads2.default)(_this.size);
  17335. /**
  17336. * The default shaders that is used if a sprite doesn't have a more specific one.
  17337. * there is a shader for each number of textures that can be rendererd.
  17338. * These shaders will also be generated on the fly as required.
  17339. * @member {PIXI.Shader[]}
  17340. */
  17341. _this.shader = null;
  17342. _this.currentIndex = 0;
  17343. _this.groups = [];
  17344. for (var k = 0; k < _this.size; k++) {
  17345. _this.groups[k] = { textures: [], textureCount: 0, ids: [], size: 0, start: 0, blend: 0 };
  17346. }
  17347. _this.sprites = [];
  17348. _this.vertexBuffers = [];
  17349. _this.vaos = [];
  17350. _this.vaoMax = 2;
  17351. _this.vertexCount = 0;
  17352. _this.renderer.on('prerender', _this.onPrerender, _this);
  17353. return _this;
  17354. }
  17355. /**
  17356. * Sets up the renderer context and necessary buffers.
  17357. *
  17358. * @private
  17359. */
  17360. SpriteRenderer.prototype.onContextChange = function onContextChange() {
  17361. var gl = this.renderer.gl;
  17362. if (this.renderer.legacy) {
  17363. this.MAX_TEXTURES = 1;
  17364. } else {
  17365. // step 1: first check max textures the GPU can handle.
  17366. this.MAX_TEXTURES = Math.min(gl.getParameter(gl.MAX_TEXTURE_IMAGE_UNITS), _settings2.default.SPRITE_MAX_TEXTURES);
  17367. // step 2: check the maximum number of if statements the shader can have too..
  17368. this.MAX_TEXTURES = (0, _checkMaxIfStatmentsInShader2.default)(this.MAX_TEXTURES, gl);
  17369. }
  17370. this.shader = (0, _generateMultiTextureShader2.default)(gl, this.MAX_TEXTURES);
  17371. // create a couple of buffers
  17372. this.indexBuffer = _pixiGlCore2.default.GLBuffer.createIndexBuffer(gl, this.indices, gl.STATIC_DRAW);
  17373. // we use the second shader as the first one depending on your browser may omit aTextureId
  17374. // as it is not used by the shader so is optimized out.
  17375. this.renderer.bindVao(null);
  17376. var attrs = this.shader.attributes;
  17377. for (var i = 0; i < this.vaoMax; i++) {
  17378. /* eslint-disable max-len */
  17379. var vertexBuffer = this.vertexBuffers[i] = _pixiGlCore2.default.GLBuffer.createVertexBuffer(gl, null, gl.STREAM_DRAW);
  17380. /* eslint-enable max-len */
  17381. // build the vao object that will render..
  17382. var vao = this.renderer.createVao().addIndex(this.indexBuffer).addAttribute(vertexBuffer, attrs.aVertexPosition, gl.FLOAT, false, this.vertByteSize, 0).addAttribute(vertexBuffer, attrs.aTextureCoord, gl.UNSIGNED_SHORT, true, this.vertByteSize, 2 * 4).addAttribute(vertexBuffer, attrs.aColor, gl.UNSIGNED_BYTE, true, this.vertByteSize, 3 * 4);
  17383. if (attrs.aTextureId) {
  17384. vao.addAttribute(vertexBuffer, attrs.aTextureId, gl.FLOAT, false, this.vertByteSize, 4 * 4);
  17385. }
  17386. this.vaos[i] = vao;
  17387. }
  17388. this.vao = this.vaos[0];
  17389. this.currentBlendMode = 99999;
  17390. this.boundTextures = new Array(this.MAX_TEXTURES);
  17391. };
  17392. /**
  17393. * Called before the renderer starts rendering.
  17394. *
  17395. */
  17396. SpriteRenderer.prototype.onPrerender = function onPrerender() {
  17397. this.vertexCount = 0;
  17398. };
  17399. /**
  17400. * Renders the sprite object.
  17401. *
  17402. * @param {PIXI.Sprite} sprite - the sprite to render when using this spritebatch
  17403. */
  17404. SpriteRenderer.prototype.render = function render(sprite) {
  17405. // TODO set blend modes..
  17406. // check texture..
  17407. if (this.currentIndex >= this.size) {
  17408. this.flush();
  17409. }
  17410. // get the uvs for the texture
  17411. // if the uvs have not updated then no point rendering just yet!
  17412. if (!sprite._texture._uvs) {
  17413. return;
  17414. }
  17415. // push a texture.
  17416. // increment the batchsize
  17417. this.sprites[this.currentIndex++] = sprite;
  17418. };
  17419. /**
  17420. * Renders the content and empties the current batch.
  17421. *
  17422. */
  17423. SpriteRenderer.prototype.flush = function flush() {
  17424. if (this.currentIndex === 0) {
  17425. return;
  17426. }
  17427. var gl = this.renderer.gl;
  17428. var MAX_TEXTURES = this.MAX_TEXTURES;
  17429. var np2 = _bitTwiddle2.default.nextPow2(this.currentIndex);
  17430. var log2 = _bitTwiddle2.default.log2(np2);
  17431. var buffer = this.buffers[log2];
  17432. var sprites = this.sprites;
  17433. var groups = this.groups;
  17434. var float32View = buffer.float32View;
  17435. var uint32View = buffer.uint32View;
  17436. var boundTextures = this.boundTextures;
  17437. var rendererBoundTextures = this.renderer.boundTextures;
  17438. var touch = this.renderer.textureGC.count;
  17439. var index = 0;
  17440. var nextTexture = void 0;
  17441. var currentTexture = void 0;
  17442. var groupCount = 1;
  17443. var textureCount = 0;
  17444. var currentGroup = groups[0];
  17445. var vertexData = void 0;
  17446. var uvs = void 0;
  17447. var blendMode = _utils.premultiplyBlendMode[sprites[0]._texture.baseTexture.premultipliedAlpha ? 1 : 0][sprites[0].blendMode];
  17448. currentGroup.textureCount = 0;
  17449. currentGroup.start = 0;
  17450. currentGroup.blend = blendMode;
  17451. TICK++;
  17452. var i = void 0;
  17453. // copy textures..
  17454. for (i = 0; i < MAX_TEXTURES; ++i) {
  17455. var bt = rendererBoundTextures[i];
  17456. if (bt._enabled === TICK) {
  17457. boundTextures[i] = this.renderer.emptyTextures[i];
  17458. continue;
  17459. }
  17460. boundTextures[i] = bt;
  17461. bt._virtalBoundId = i;
  17462. bt._enabled = TICK;
  17463. }
  17464. TICK++;
  17465. for (i = 0; i < this.currentIndex; ++i) {
  17466. // upload the sprite elemetns...
  17467. // they have all ready been calculated so we just need to push them into the buffer.
  17468. var sprite = sprites[i];
  17469. nextTexture = sprite._texture.baseTexture;
  17470. var spriteBlendMode = _utils.premultiplyBlendMode[Number(nextTexture.premultipliedAlpha)][sprite.blendMode];
  17471. if (blendMode !== spriteBlendMode) {
  17472. // finish a group..
  17473. blendMode = spriteBlendMode;
  17474. // force the batch to break!
  17475. currentTexture = null;
  17476. textureCount = MAX_TEXTURES;
  17477. TICK++;
  17478. }
  17479. if (currentTexture !== nextTexture) {
  17480. currentTexture = nextTexture;
  17481. if (nextTexture._enabled !== TICK) {
  17482. if (textureCount === MAX_TEXTURES) {
  17483. TICK++;
  17484. currentGroup.size = i - currentGroup.start;
  17485. textureCount = 0;
  17486. currentGroup = groups[groupCount++];
  17487. currentGroup.blend = blendMode;
  17488. currentGroup.textureCount = 0;
  17489. currentGroup.start = i;
  17490. }
  17491. nextTexture.touched = touch;
  17492. if (nextTexture._virtalBoundId === -1) {
  17493. for (var j = 0; j < MAX_TEXTURES; ++j) {
  17494. var tIndex = (j + TEXTURE_TICK) % MAX_TEXTURES;
  17495. var t = boundTextures[tIndex];
  17496. if (t._enabled !== TICK) {
  17497. TEXTURE_TICK++;
  17498. t._virtalBoundId = -1;
  17499. nextTexture._virtalBoundId = tIndex;
  17500. boundTextures[tIndex] = nextTexture;
  17501. break;
  17502. }
  17503. }
  17504. }
  17505. nextTexture._enabled = TICK;
  17506. currentGroup.textureCount++;
  17507. currentGroup.ids[textureCount] = nextTexture._virtalBoundId;
  17508. currentGroup.textures[textureCount++] = nextTexture;
  17509. }
  17510. }
  17511. vertexData = sprite.vertexData;
  17512. // TODO this sum does not need to be set each frame..
  17513. uvs = sprite._texture._uvs.uvsUint32;
  17514. if (this.renderer.roundPixels) {
  17515. var resolution = this.renderer.resolution;
  17516. // xy
  17517. float32View[index] = (vertexData[0] * resolution | 0) / resolution;
  17518. float32View[index + 1] = (vertexData[1] * resolution | 0) / resolution;
  17519. // xy
  17520. float32View[index + 5] = (vertexData[2] * resolution | 0) / resolution;
  17521. float32View[index + 6] = (vertexData[3] * resolution | 0) / resolution;
  17522. // xy
  17523. float32View[index + 10] = (vertexData[4] * resolution | 0) / resolution;
  17524. float32View[index + 11] = (vertexData[5] * resolution | 0) / resolution;
  17525. // xy
  17526. float32View[index + 15] = (vertexData[6] * resolution | 0) / resolution;
  17527. float32View[index + 16] = (vertexData[7] * resolution | 0) / resolution;
  17528. } else {
  17529. // xy
  17530. float32View[index] = vertexData[0];
  17531. float32View[index + 1] = vertexData[1];
  17532. // xy
  17533. float32View[index + 5] = vertexData[2];
  17534. float32View[index + 6] = vertexData[3];
  17535. // xy
  17536. float32View[index + 10] = vertexData[4];
  17537. float32View[index + 11] = vertexData[5];
  17538. // xy
  17539. float32View[index + 15] = vertexData[6];
  17540. float32View[index + 16] = vertexData[7];
  17541. }
  17542. uint32View[index + 2] = uvs[0];
  17543. uint32View[index + 7] = uvs[1];
  17544. uint32View[index + 12] = uvs[2];
  17545. uint32View[index + 17] = uvs[3];
  17546. /* eslint-disable max-len */
  17547. var alpha = Math.min(sprite.worldAlpha, 1.0);
  17548. // we dont call extra function if alpha is 1.0, that's faster
  17549. var argb = alpha < 1.0 && nextTexture.premultipliedAlpha ? (0, _utils.premultiplyTint)(sprite._tintRGB, alpha) : sprite._tintRGB + (alpha * 255 << 24);
  17550. uint32View[index + 3] = uint32View[index + 8] = uint32View[index + 13] = uint32View[index + 18] = argb;
  17551. float32View[index + 4] = float32View[index + 9] = float32View[index + 14] = float32View[index + 19] = nextTexture._virtalBoundId;
  17552. /* eslint-enable max-len */
  17553. index += 20;
  17554. }
  17555. currentGroup.size = i - currentGroup.start;
  17556. if (!_settings2.default.CAN_UPLOAD_SAME_BUFFER) {
  17557. // this is still needed for IOS performance..
  17558. // it really does not like uploading to the same buffer in a single frame!
  17559. if (this.vaoMax <= this.vertexCount) {
  17560. this.vaoMax++;
  17561. var attrs = this.shader.attributes;
  17562. /* eslint-disable max-len */
  17563. var vertexBuffer = this.vertexBuffers[this.vertexCount] = _pixiGlCore2.default.GLBuffer.createVertexBuffer(gl, null, gl.STREAM_DRAW);
  17564. /* eslint-enable max-len */
  17565. // build the vao object that will render..
  17566. var vao = this.renderer.createVao().addIndex(this.indexBuffer).addAttribute(vertexBuffer, attrs.aVertexPosition, gl.FLOAT, false, this.vertByteSize, 0).addAttribute(vertexBuffer, attrs.aTextureCoord, gl.UNSIGNED_SHORT, true, this.vertByteSize, 2 * 4).addAttribute(vertexBuffer, attrs.aColor, gl.UNSIGNED_BYTE, true, this.vertByteSize, 3 * 4);
  17567. if (attrs.aTextureId) {
  17568. vao.addAttribute(vertexBuffer, attrs.aTextureId, gl.FLOAT, false, this.vertByteSize, 4 * 4);
  17569. }
  17570. this.vaos[this.vertexCount] = vao;
  17571. }
  17572. this.renderer.bindVao(this.vaos[this.vertexCount]);
  17573. this.vertexBuffers[this.vertexCount].upload(buffer.vertices, 0, false);
  17574. this.vertexCount++;
  17575. } else {
  17576. // lets use the faster option, always use buffer number 0
  17577. this.vertexBuffers[this.vertexCount].upload(buffer.vertices, 0, true);
  17578. }
  17579. for (i = 0; i < MAX_TEXTURES; ++i) {
  17580. rendererBoundTextures[i]._virtalBoundId = -1;
  17581. }
  17582. // render the groups..
  17583. for (i = 0; i < groupCount; ++i) {
  17584. var group = groups[i];
  17585. var groupTextureCount = group.textureCount;
  17586. for (var _j = 0; _j < groupTextureCount; _j++) {
  17587. currentTexture = group.textures[_j];
  17588. // reset virtual ids..
  17589. // lets do a quick check..
  17590. if (rendererBoundTextures[group.ids[_j]] !== currentTexture) {
  17591. this.renderer.bindTexture(currentTexture, group.ids[_j], true);
  17592. }
  17593. // reset the virtualId..
  17594. currentTexture._virtalBoundId = -1;
  17595. }
  17596. // set the blend mode..
  17597. this.renderer.state.setBlendMode(group.blend);
  17598. gl.drawElements(gl.TRIANGLES, group.size * 6, gl.UNSIGNED_SHORT, group.start * 6 * 2);
  17599. }
  17600. // reset elements for the next flush
  17601. this.currentIndex = 0;
  17602. };
  17603. /**
  17604. * Starts a new sprite batch.
  17605. */
  17606. SpriteRenderer.prototype.start = function start() {
  17607. this.renderer.bindShader(this.shader);
  17608. if (_settings2.default.CAN_UPLOAD_SAME_BUFFER) {
  17609. // bind buffer #0, we don't need others
  17610. this.renderer.bindVao(this.vaos[this.vertexCount]);
  17611. this.vertexBuffers[this.vertexCount].bind();
  17612. }
  17613. };
  17614. /**
  17615. * Stops and flushes the current batch.
  17616. *
  17617. */
  17618. SpriteRenderer.prototype.stop = function stop() {
  17619. this.flush();
  17620. };
  17621. /**
  17622. * Destroys the SpriteRenderer.
  17623. *
  17624. */
  17625. SpriteRenderer.prototype.destroy = function destroy() {
  17626. for (var i = 0; i < this.vaoMax; i++) {
  17627. if (this.vertexBuffers[i]) {
  17628. this.vertexBuffers[i].destroy();
  17629. }
  17630. if (this.vaos[i]) {
  17631. this.vaos[i].destroy();
  17632. }
  17633. }
  17634. if (this.indexBuffer) {
  17635. this.indexBuffer.destroy();
  17636. }
  17637. this.renderer.off('prerender', this.onPrerender, this);
  17638. _ObjectRenderer.prototype.destroy.call(this);
  17639. if (this.shader) {
  17640. this.shader.destroy();
  17641. this.shader = null;
  17642. }
  17643. this.vertexBuffers = null;
  17644. this.vaos = null;
  17645. this.indexBuffer = null;
  17646. this.indices = null;
  17647. this.sprites = null;
  17648. for (var _i = 0; _i < this.buffers.length; ++_i) {
  17649. this.buffers[_i].destroy();
  17650. }
  17651. };
  17652. return SpriteRenderer;
  17653. }(_ObjectRenderer3.default);
  17654. exports.default = SpriteRenderer;
  17655. _WebGLRenderer2.default.registerPlugin('sprite', SpriteRenderer);
  17656. }, { "../../renderers/webgl/WebGLRenderer": 84, "../../renderers/webgl/utils/ObjectRenderer": 94, "../../renderers/webgl/utils/checkMaxIfStatmentsInShader": 97, "../../settings": 101, "../../utils": 125, "../../utils/createIndicesForQuads": 123, "./BatchBuffer": 105, "./generateMultiTextureShader": 107, "bit-twiddle": 1, "pixi-gl-core": 15 }], 107: [function (require, module, exports) {
  17657. 'use strict';
  17658. exports.__esModule = true;
  17659. exports.default = generateMultiTextureShader;
  17660. var _Shader = require('../../Shader');
  17661. var _Shader2 = _interopRequireDefault(_Shader);
  17662. var _path = require('path');
  17663. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  17664. var fragTemplate = ['varying vec2 vTextureCoord;', 'varying vec4 vColor;', 'varying float vTextureId;', 'uniform sampler2D uSamplers[%count%];', 'void main(void){', 'vec4 color;', 'float textureId = floor(vTextureId+0.5);', '%forloop%', 'gl_FragColor = color * vColor;', '}'].join('\n');
  17665. function generateMultiTextureShader(gl, maxTextures) {
  17666. var vertexSrc = 'precision highp float;\nattribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nattribute vec4 aColor;\nattribute float aTextureId;\n\nuniform mat3 projectionMatrix;\n\nvarying vec2 vTextureCoord;\nvarying vec4 vColor;\nvarying float vTextureId;\n\nvoid main(void){\n gl_Position = vec4((projectionMatrix * vec3(aVertexPosition, 1.0)).xy, 0.0, 1.0);\n\n vTextureCoord = aTextureCoord;\n vTextureId = aTextureId;\n vColor = aColor;\n}\n';
  17667. var fragmentSrc = fragTemplate;
  17668. fragmentSrc = fragmentSrc.replace(/%count%/gi, maxTextures);
  17669. fragmentSrc = fragmentSrc.replace(/%forloop%/gi, generateSampleSrc(maxTextures));
  17670. var shader = new _Shader2.default(gl, vertexSrc, fragmentSrc);
  17671. var sampleValues = [];
  17672. for (var i = 0; i < maxTextures; i++) {
  17673. sampleValues[i] = i;
  17674. }
  17675. shader.bind();
  17676. shader.uniforms.uSamplers = sampleValues;
  17677. return shader;
  17678. }
  17679. function generateSampleSrc(maxTextures) {
  17680. var src = '';
  17681. src += '\n';
  17682. src += '\n';
  17683. for (var i = 0; i < maxTextures; i++) {
  17684. if (i > 0) {
  17685. src += '\nelse ';
  17686. }
  17687. if (i < maxTextures - 1) {
  17688. src += 'if(textureId == ' + i + '.0)';
  17689. }
  17690. src += '\n{';
  17691. src += '\n\tcolor = texture2D(uSamplers[' + i + '], vTextureCoord);';
  17692. src += '\n}';
  17693. }
  17694. src += '\n';
  17695. src += '\n';
  17696. return src;
  17697. }
  17698. }, { "../../Shader": 44, "path": 8 }], 108: [function (require, module, exports) {
  17699. 'use strict';
  17700. exports.__esModule = true;
  17701. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  17702. var _Sprite2 = require('../sprites/Sprite');
  17703. var _Sprite3 = _interopRequireDefault(_Sprite2);
  17704. var _Texture = require('../textures/Texture');
  17705. var _Texture2 = _interopRequireDefault(_Texture);
  17706. var _math = require('../math');
  17707. var _utils = require('../utils');
  17708. var _const = require('../const');
  17709. var _settings = require('../settings');
  17710. var _settings2 = _interopRequireDefault(_settings);
  17711. var _TextStyle = require('./TextStyle');
  17712. var _TextStyle2 = _interopRequireDefault(_TextStyle);
  17713. var _TextMetrics = require('./TextMetrics');
  17714. var _TextMetrics2 = _interopRequireDefault(_TextMetrics);
  17715. var _trimCanvas = require('../utils/trimCanvas');
  17716. var _trimCanvas2 = _interopRequireDefault(_trimCanvas);
  17717. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  17718. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  17719. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  17720. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } /* eslint max-depth: [2, 8] */
  17721. var defaultDestroyOptions = {
  17722. texture: true,
  17723. children: false,
  17724. baseTexture: true
  17725. };
  17726. /**
  17727. * A Text Object will create a line or multiple lines of text. To split a line you can use '\n' in your text string,
  17728. * or add a wordWrap property set to true and and wordWrapWidth property with a value in the style object.
  17729. *
  17730. * A Text can be created directly from a string and a style object
  17731. *
  17732. * ```js
  17733. * let text = new PIXI.Text('This is a PixiJS text',{fontFamily : 'Arial', fontSize: 24, fill : 0xff1010, align : 'center'});
  17734. * ```
  17735. *
  17736. * @class
  17737. * @extends PIXI.Sprite
  17738. * @memberof PIXI
  17739. */
  17740. var Text = function (_Sprite) {
  17741. _inherits(Text, _Sprite);
  17742. /**
  17743. * @param {string} text - The string that you would like the text to display
  17744. * @param {object|PIXI.TextStyle} [style] - The style parameters
  17745. * @param {HTMLCanvasElement} [canvas] - The canvas element for drawing text
  17746. */
  17747. function Text(text, style, canvas) {
  17748. _classCallCheck(this, Text);
  17749. canvas = canvas || document.createElement('canvas');
  17750. canvas.width = 3;
  17751. canvas.height = 3;
  17752. var texture = _Texture2.default.fromCanvas(canvas, _settings2.default.SCALE_MODE, 'text');
  17753. texture.orig = new _math.Rectangle();
  17754. texture.trim = new _math.Rectangle();
  17755. // base texture is already automatically added to the cache, now adding the actual texture
  17756. var _this = _possibleConstructorReturn(this, _Sprite.call(this, texture));
  17757. _Texture2.default.addToCache(_this._texture, _this._texture.baseTexture.textureCacheIds[0]);
  17758. /**
  17759. * The canvas element that everything is drawn to
  17760. *
  17761. * @member {HTMLCanvasElement}
  17762. */
  17763. _this.canvas = canvas;
  17764. /**
  17765. * The canvas 2d context that everything is drawn with
  17766. * @member {CanvasRenderingContext2D}
  17767. */
  17768. _this.context = _this.canvas.getContext('2d');
  17769. /**
  17770. * The resolution / device pixel ratio of the canvas. This is set automatically by the renderer.
  17771. * @member {number}
  17772. * @default 1
  17773. */
  17774. _this.resolution = _settings2.default.RESOLUTION;
  17775. /**
  17776. * Private tracker for the current text.
  17777. *
  17778. * @member {string}
  17779. * @private
  17780. */
  17781. _this._text = null;
  17782. /**
  17783. * Private tracker for the current style.
  17784. *
  17785. * @member {object}
  17786. * @private
  17787. */
  17788. _this._style = null;
  17789. /**
  17790. * Private listener to track style changes.
  17791. *
  17792. * @member {Function}
  17793. * @private
  17794. */
  17795. _this._styleListener = null;
  17796. /**
  17797. * Private tracker for the current font.
  17798. *
  17799. * @member {string}
  17800. * @private
  17801. */
  17802. _this._font = '';
  17803. _this.text = text;
  17804. _this.style = style;
  17805. _this.localStyleID = -1;
  17806. return _this;
  17807. }
  17808. /**
  17809. * Renders text and updates it when needed.
  17810. *
  17811. * @private
  17812. * @param {boolean} respectDirty - Whether to abort updating the text if the Text isn't dirty and the function is called.
  17813. */
  17814. Text.prototype.updateText = function updateText(respectDirty) {
  17815. var style = this._style;
  17816. // check if style has changed..
  17817. if (this.localStyleID !== style.styleID) {
  17818. this.dirty = true;
  17819. this.localStyleID = style.styleID;
  17820. }
  17821. if (!this.dirty && respectDirty) {
  17822. return;
  17823. }
  17824. this._font = this._style.toFontString();
  17825. var context = this.context;
  17826. var measured = _TextMetrics2.default.measureText(this._text, this._style, this._style.wordWrap, this.canvas);
  17827. var width = measured.width;
  17828. var height = measured.height;
  17829. var lines = measured.lines;
  17830. var lineHeight = measured.lineHeight;
  17831. var lineWidths = measured.lineWidths;
  17832. var maxLineWidth = measured.maxLineWidth;
  17833. var fontProperties = measured.fontProperties;
  17834. this.canvas.width = Math.ceil((Math.max(1, width) + style.padding * 2) * this.resolution);
  17835. this.canvas.height = Math.ceil((Math.max(1, height) + style.padding * 2) * this.resolution);
  17836. context.scale(this.resolution, this.resolution);
  17837. context.clearRect(0, 0, this.canvas.width, this.canvas.height);
  17838. context.font = this._font;
  17839. context.strokeStyle = style.stroke;
  17840. context.lineWidth = style.strokeThickness;
  17841. context.textBaseline = style.textBaseline;
  17842. context.lineJoin = style.lineJoin;
  17843. context.miterLimit = style.miterLimit;
  17844. var linePositionX = void 0;
  17845. var linePositionY = void 0;
  17846. if (style.dropShadow) {
  17847. context.fillStyle = style.dropShadowColor;
  17848. context.globalAlpha = style.dropShadowAlpha;
  17849. context.shadowBlur = style.dropShadowBlur;
  17850. if (style.dropShadowBlur > 0) {
  17851. context.shadowColor = style.dropShadowColor;
  17852. }
  17853. var xShadowOffset = Math.cos(style.dropShadowAngle) * style.dropShadowDistance;
  17854. var yShadowOffset = Math.sin(style.dropShadowAngle) * style.dropShadowDistance;
  17855. for (var i = 0; i < lines.length; i++) {
  17856. linePositionX = style.strokeThickness / 2;
  17857. linePositionY = style.strokeThickness / 2 + i * lineHeight + fontProperties.ascent;
  17858. if (style.align === 'right') {
  17859. linePositionX += maxLineWidth - lineWidths[i];
  17860. } else if (style.align === 'center') {
  17861. linePositionX += (maxLineWidth - lineWidths[i]) / 2;
  17862. }
  17863. if (style.fill) {
  17864. this.drawLetterSpacing(lines[i], linePositionX + xShadowOffset + style.padding, linePositionY + yShadowOffset + style.padding);
  17865. if (style.stroke && style.strokeThickness) {
  17866. context.strokeStyle = style.dropShadowColor;
  17867. this.drawLetterSpacing(lines[i], linePositionX + xShadowOffset + style.padding, linePositionY + yShadowOffset + style.padding, true);
  17868. context.strokeStyle = style.stroke;
  17869. }
  17870. }
  17871. }
  17872. }
  17873. // reset the shadow blur and alpha that was set by the drop shadow, for the regular text
  17874. context.shadowBlur = 0;
  17875. context.globalAlpha = 1;
  17876. // set canvas text styles
  17877. context.fillStyle = this._generateFillStyle(style, lines);
  17878. // draw lines line by line
  17879. for (var _i = 0; _i < lines.length; _i++) {
  17880. linePositionX = style.strokeThickness / 2;
  17881. linePositionY = style.strokeThickness / 2 + _i * lineHeight + fontProperties.ascent;
  17882. if (style.align === 'right') {
  17883. linePositionX += maxLineWidth - lineWidths[_i];
  17884. } else if (style.align === 'center') {
  17885. linePositionX += (maxLineWidth - lineWidths[_i]) / 2;
  17886. }
  17887. if (style.stroke && style.strokeThickness) {
  17888. this.drawLetterSpacing(lines[_i], linePositionX + style.padding, linePositionY + style.padding, true);
  17889. }
  17890. if (style.fill) {
  17891. this.drawLetterSpacing(lines[_i], linePositionX + style.padding, linePositionY + style.padding);
  17892. }
  17893. }
  17894. this.updateTexture();
  17895. };
  17896. /**
  17897. * Render the text with letter-spacing.
  17898. * @param {string} text - The text to draw
  17899. * @param {number} x - Horizontal position to draw the text
  17900. * @param {number} y - Vertical position to draw the text
  17901. * @param {boolean} [isStroke=false] - Is this drawing for the outside stroke of the
  17902. * text? If not, it's for the inside fill
  17903. * @private
  17904. */
  17905. Text.prototype.drawLetterSpacing = function drawLetterSpacing(text, x, y) {
  17906. var isStroke = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
  17907. var style = this._style;
  17908. // letterSpacing of 0 means normal
  17909. var letterSpacing = style.letterSpacing;
  17910. if (letterSpacing === 0) {
  17911. if (isStroke) {
  17912. this.context.strokeText(text, x, y);
  17913. } else {
  17914. this.context.fillText(text, x, y);
  17915. }
  17916. return;
  17917. }
  17918. var characters = String.prototype.split.call(text, '');
  17919. var currentPosition = x;
  17920. var index = 0;
  17921. var current = '';
  17922. while (index < text.length) {
  17923. current = characters[index++];
  17924. if (isStroke) {
  17925. this.context.strokeText(current, currentPosition, y);
  17926. } else {
  17927. this.context.fillText(current, currentPosition, y);
  17928. }
  17929. currentPosition += this.context.measureText(current).width + letterSpacing;
  17930. }
  17931. };
  17932. /**
  17933. * Updates texture size based on canvas size
  17934. *
  17935. * @private
  17936. */
  17937. Text.prototype.updateTexture = function updateTexture() {
  17938. var canvas = this.canvas;
  17939. if (this._style.trim) {
  17940. var trimmed = (0, _trimCanvas2.default)(canvas);
  17941. canvas.width = trimmed.width;
  17942. canvas.height = trimmed.height;
  17943. this.context.putImageData(trimmed.data, 0, 0);
  17944. }
  17945. var texture = this._texture;
  17946. var style = this._style;
  17947. var padding = style.trim ? 0 : style.padding;
  17948. var baseTexture = texture.baseTexture;
  17949. baseTexture.hasLoaded = true;
  17950. baseTexture.resolution = this.resolution;
  17951. baseTexture.realWidth = canvas.width;
  17952. baseTexture.realHeight = canvas.height;
  17953. baseTexture.width = canvas.width / this.resolution;
  17954. baseTexture.height = canvas.height / this.resolution;
  17955. texture.trim.width = texture._frame.width = canvas.width / this.resolution;
  17956. texture.trim.height = texture._frame.height = canvas.height / this.resolution;
  17957. texture.trim.x = -padding;
  17958. texture.trim.y = -padding;
  17959. texture.orig.width = texture._frame.width - padding * 2;
  17960. texture.orig.height = texture._frame.height - padding * 2;
  17961. // call sprite onTextureUpdate to update scale if _width or _height were set
  17962. this._onTextureUpdate();
  17963. baseTexture.emit('update', baseTexture);
  17964. this.dirty = false;
  17965. };
  17966. /**
  17967. * Renders the object using the WebGL renderer
  17968. *
  17969. * @param {PIXI.WebGLRenderer} renderer - The renderer
  17970. */
  17971. Text.prototype.renderWebGL = function renderWebGL(renderer) {
  17972. if (this.resolution !== renderer.resolution) {
  17973. this.resolution = renderer.resolution;
  17974. this.dirty = true;
  17975. }
  17976. this.updateText(true);
  17977. _Sprite.prototype.renderWebGL.call(this, renderer);
  17978. };
  17979. /**
  17980. * Renders the object using the Canvas renderer
  17981. *
  17982. * @private
  17983. * @param {PIXI.CanvasRenderer} renderer - The renderer
  17984. */
  17985. Text.prototype._renderCanvas = function _renderCanvas(renderer) {
  17986. if (this.resolution !== renderer.resolution) {
  17987. this.resolution = renderer.resolution;
  17988. this.dirty = true;
  17989. }
  17990. this.updateText(true);
  17991. _Sprite.prototype._renderCanvas.call(this, renderer);
  17992. };
  17993. /**
  17994. * Gets the local bounds of the text object.
  17995. *
  17996. * @param {Rectangle} rect - The output rectangle.
  17997. * @return {Rectangle} The bounds.
  17998. */
  17999. Text.prototype.getLocalBounds = function getLocalBounds(rect) {
  18000. this.updateText(true);
  18001. return _Sprite.prototype.getLocalBounds.call(this, rect);
  18002. };
  18003. /**
  18004. * calculates the bounds of the Text as a rectangle. The bounds calculation takes the worldTransform into account.
  18005. */
  18006. Text.prototype._calculateBounds = function _calculateBounds() {
  18007. this.updateText(true);
  18008. this.calculateVertices();
  18009. // if we have already done this on THIS frame.
  18010. this._bounds.addQuad(this.vertexData);
  18011. };
  18012. /**
  18013. * Method to be called upon a TextStyle change.
  18014. * @private
  18015. */
  18016. Text.prototype._onStyleChange = function _onStyleChange() {
  18017. this.dirty = true;
  18018. };
  18019. /**
  18020. * Generates the fill style. Can automatically generate a gradient based on the fill style being an array
  18021. *
  18022. * @private
  18023. * @param {object} style - The style.
  18024. * @param {string[]} lines - The lines of text.
  18025. * @return {string|number|CanvasGradient} The fill style
  18026. */
  18027. Text.prototype._generateFillStyle = function _generateFillStyle(style, lines) {
  18028. if (!Array.isArray(style.fill)) {
  18029. return style.fill;
  18030. }
  18031. // cocoon on canvas+ cannot generate textures, so use the first colour instead
  18032. if (navigator.isCocoonJS) {
  18033. return style.fill[0];
  18034. }
  18035. // the gradient will be evenly spaced out according to how large the array is.
  18036. // ['#FF0000', '#00FF00', '#0000FF'] would created stops at 0.25, 0.5 and 0.75
  18037. var gradient = void 0;
  18038. var totalIterations = void 0;
  18039. var currentIteration = void 0;
  18040. var stop = void 0;
  18041. var width = this.canvas.width / this.resolution;
  18042. var height = this.canvas.height / this.resolution;
  18043. // make a copy of the style settings, so we can manipulate them later
  18044. var fill = style.fill.slice();
  18045. var fillGradientStops = style.fillGradientStops.slice();
  18046. // wanting to evenly distribute the fills. So an array of 4 colours should give fills of 0.25, 0.5 and 0.75
  18047. if (!fillGradientStops.length) {
  18048. var lengthPlus1 = fill.length + 1;
  18049. for (var i = 1; i < lengthPlus1; ++i) {
  18050. fillGradientStops.push(i / lengthPlus1);
  18051. }
  18052. }
  18053. // stop the bleeding of the last gradient on the line above to the top gradient of the this line
  18054. // by hard defining the first gradient colour at point 0, and last gradient colour at point 1
  18055. fill.unshift(style.fill[0]);
  18056. fillGradientStops.unshift(0);
  18057. fill.push(style.fill[style.fill.length - 1]);
  18058. fillGradientStops.push(1);
  18059. if (style.fillGradientType === _const.TEXT_GRADIENT.LINEAR_VERTICAL) {
  18060. // start the gradient at the top center of the canvas, and end at the bottom middle of the canvas
  18061. gradient = this.context.createLinearGradient(width / 2, 0, width / 2, height);
  18062. // we need to repeat the gradient so that each individual line of text has the same vertical gradient effect
  18063. // ['#FF0000', '#00FF00', '#0000FF'] over 2 lines would create stops at 0.125, 0.25, 0.375, 0.625, 0.75, 0.875
  18064. totalIterations = (fill.length + 1) * lines.length;
  18065. currentIteration = 0;
  18066. for (var _i2 = 0; _i2 < lines.length; _i2++) {
  18067. currentIteration += 1;
  18068. for (var j = 0; j < fill.length; j++) {
  18069. if (typeof fillGradientStops[j] === 'number') {
  18070. stop = fillGradientStops[j] / lines.length + _i2 / lines.length;
  18071. } else {
  18072. stop = currentIteration / totalIterations;
  18073. }
  18074. gradient.addColorStop(stop, fill[j]);
  18075. currentIteration++;
  18076. }
  18077. }
  18078. } else {
  18079. // start the gradient at the center left of the canvas, and end at the center right of the canvas
  18080. gradient = this.context.createLinearGradient(0, height / 2, width, height / 2);
  18081. // can just evenly space out the gradients in this case, as multiple lines makes no difference
  18082. // to an even left to right gradient
  18083. totalIterations = fill.length + 1;
  18084. currentIteration = 1;
  18085. for (var _i3 = 0; _i3 < fill.length; _i3++) {
  18086. if (typeof fillGradientStops[_i3] === 'number') {
  18087. stop = fillGradientStops[_i3];
  18088. } else {
  18089. stop = currentIteration / totalIterations;
  18090. }
  18091. gradient.addColorStop(stop, fill[_i3]);
  18092. currentIteration++;
  18093. }
  18094. }
  18095. return gradient;
  18096. };
  18097. /**
  18098. * Destroys this text object.
  18099. * Note* Unlike a Sprite, a Text object will automatically destroy its baseTexture and texture as
  18100. * the majority of the time the texture will not be shared with any other Sprites.
  18101. *
  18102. * @param {object|boolean} [options] - Options parameter. A boolean will act as if all options
  18103. * have been set to that value
  18104. * @param {boolean} [options.children=false] - if set to true, all the children will have their
  18105. * destroy method called as well. 'options' will be passed on to those calls.
  18106. * @param {boolean} [options.texture=true] - Should it destroy the current texture of the sprite as well
  18107. * @param {boolean} [options.baseTexture=true] - Should it destroy the base texture of the sprite as well
  18108. */
  18109. Text.prototype.destroy = function destroy(options) {
  18110. if (typeof options === 'boolean') {
  18111. options = { children: options };
  18112. }
  18113. options = Object.assign({}, defaultDestroyOptions, options);
  18114. _Sprite.prototype.destroy.call(this, options);
  18115. // make sure to reset the the context and canvas.. dont want this hanging around in memory!
  18116. this.context = null;
  18117. this.canvas = null;
  18118. this._style = null;
  18119. };
  18120. /**
  18121. * The width of the Text, setting this will actually modify the scale to achieve the value set
  18122. *
  18123. * @member {number}
  18124. */
  18125. _createClass(Text, [{
  18126. key: 'width',
  18127. get: function get() {
  18128. this.updateText(true);
  18129. return Math.abs(this.scale.x) * this._texture.orig.width;
  18130. },
  18131. set: function set(value) // eslint-disable-line require-jsdoc
  18132. {
  18133. this.updateText(true);
  18134. var s = (0, _utils.sign)(this.scale.x) || 1;
  18135. this.scale.x = s * value / this._texture.orig.width;
  18136. this._width = value;
  18137. }
  18138. /**
  18139. * The height of the Text, setting this will actually modify the scale to achieve the value set
  18140. *
  18141. * @member {number}
  18142. */
  18143. }, {
  18144. key: 'height',
  18145. get: function get() {
  18146. this.updateText(true);
  18147. return Math.abs(this.scale.y) * this._texture.orig.height;
  18148. },
  18149. set: function set(value) // eslint-disable-line require-jsdoc
  18150. {
  18151. this.updateText(true);
  18152. var s = (0, _utils.sign)(this.scale.y) || 1;
  18153. this.scale.y = s * value / this._texture.orig.height;
  18154. this._height = value;
  18155. }
  18156. /**
  18157. * Set the style of the text. Set up an event listener to listen for changes on the style
  18158. * object and mark the text as dirty.
  18159. *
  18160. * @member {object|PIXI.TextStyle}
  18161. */
  18162. }, {
  18163. key: 'style',
  18164. get: function get() {
  18165. return this._style;
  18166. },
  18167. set: function set(style) // eslint-disable-line require-jsdoc
  18168. {
  18169. style = style || {};
  18170. if (style instanceof _TextStyle2.default) {
  18171. this._style = style;
  18172. } else {
  18173. this._style = new _TextStyle2.default(style);
  18174. }
  18175. this.localStyleID = -1;
  18176. this.dirty = true;
  18177. }
  18178. /**
  18179. * Set the copy for the text object. To split a line you can use '\n'.
  18180. *
  18181. * @member {string}
  18182. */
  18183. }, {
  18184. key: 'text',
  18185. get: function get() {
  18186. return this._text;
  18187. },
  18188. set: function set(text) // eslint-disable-line require-jsdoc
  18189. {
  18190. text = String(text === '' || text === null || text === undefined ? ' ' : text);
  18191. if (this._text === text) {
  18192. return;
  18193. }
  18194. this._text = text;
  18195. this.dirty = true;
  18196. }
  18197. }]);
  18198. return Text;
  18199. }(_Sprite3.default);
  18200. exports.default = Text;
  18201. }, { "../const": 46, "../math": 70, "../settings": 101, "../sprites/Sprite": 102, "../textures/Texture": 115, "../utils": 125, "../utils/trimCanvas": 130, "./TextMetrics": 109, "./TextStyle": 110 }], 109: [function (require, module, exports) {
  18202. 'use strict';
  18203. exports.__esModule = true;
  18204. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  18205. /**
  18206. * The TextMetrics object represents the measurement of a block of text with a specified style.
  18207. *
  18208. * ```js
  18209. * let style = new PIXI.TextStyle({fontFamily : 'Arial', fontSize: 24, fill : 0xff1010, align : 'center'})
  18210. * let textMetrics = PIXI.TextMetrics.measureText('Your text', style)
  18211. * ```
  18212. *
  18213. * @class
  18214. * @memberOf PIXI
  18215. */
  18216. var TextMetrics = function () {
  18217. /**
  18218. * @param {string} text - the text that was measured
  18219. * @param {PIXI.TextStyle} style - the style that was measured
  18220. * @param {number} width - the measured width of the text
  18221. * @param {number} height - the measured height of the text
  18222. * @param {array} lines - an array of the lines of text broken by new lines and wrapping if specified in style
  18223. * @param {array} lineWidths - an array of the line widths for each line matched to `lines`
  18224. * @param {number} lineHeight - the measured line height for this style
  18225. * @param {number} maxLineWidth - the maximum line width for all measured lines
  18226. * @param {Object} fontProperties - the font properties object from TextMetrics.measureFont
  18227. */
  18228. function TextMetrics(text, style, width, height, lines, lineWidths, lineHeight, maxLineWidth, fontProperties) {
  18229. _classCallCheck(this, TextMetrics);
  18230. this.text = text;
  18231. this.style = style;
  18232. this.width = width;
  18233. this.height = height;
  18234. this.lines = lines;
  18235. this.lineWidths = lineWidths;
  18236. this.lineHeight = lineHeight;
  18237. this.maxLineWidth = maxLineWidth;
  18238. this.fontProperties = fontProperties;
  18239. }
  18240. /**
  18241. * Measures the supplied string of text and returns a Rectangle.
  18242. *
  18243. * @param {string} text - the text to measure.
  18244. * @param {PIXI.TextStyle} style - the text style to use for measuring
  18245. * @param {boolean} [wordWrap] - optional override for if word-wrap should be applied to the text.
  18246. * @param {HTMLCanvasElement} [canvas] - optional specification of the canvas to use for measuring.
  18247. * @return {PIXI.TextMetrics} measured width and height of the text.
  18248. */
  18249. TextMetrics.measureText = function measureText(text, style, wordWrap) {
  18250. var canvas = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : TextMetrics._canvas;
  18251. wordWrap = wordWrap || style.wordWrap;
  18252. var font = style.toFontString();
  18253. var fontProperties = TextMetrics.measureFont(font);
  18254. var context = canvas.getContext('2d');
  18255. context.font = font;
  18256. var outputText = wordWrap ? TextMetrics.wordWrap(text, style, canvas) : text;
  18257. var lines = outputText.split(/(?:\r\n|\r|\n)/);
  18258. var lineWidths = new Array(lines.length);
  18259. var maxLineWidth = 0;
  18260. for (var i = 0; i < lines.length; i++) {
  18261. var lineWidth = context.measureText(lines[i]).width + (lines[i].length - 1) * style.letterSpacing;
  18262. lineWidths[i] = lineWidth;
  18263. maxLineWidth = Math.max(maxLineWidth, lineWidth);
  18264. }
  18265. var width = maxLineWidth + style.strokeThickness;
  18266. if (style.dropShadow) {
  18267. width += style.dropShadowDistance;
  18268. }
  18269. var lineHeight = style.lineHeight || fontProperties.fontSize + style.strokeThickness;
  18270. var height = Math.max(lineHeight, fontProperties.fontSize + style.strokeThickness) + (lines.length - 1) * (lineHeight + style.leading);
  18271. if (style.dropShadow) {
  18272. height += style.dropShadowDistance;
  18273. }
  18274. return new TextMetrics(text, style, width, height, lines, lineWidths, lineHeight + style.leading, maxLineWidth, fontProperties);
  18275. };
  18276. /**
  18277. * Applies newlines to a string to have it optimally fit into the horizontal
  18278. * bounds set by the Text object's wordWrapWidth property.
  18279. *
  18280. * @private
  18281. * @param {string} text - String to apply word wrapping to
  18282. * @param {PIXI.TextStyle} style - the style to use when wrapping
  18283. * @param {HTMLCanvasElement} [canvas] - optional specification of the canvas to use for measuring.
  18284. * @return {string} New string with new lines applied where required
  18285. */
  18286. TextMetrics.wordWrap = function wordWrap(text, style) {
  18287. var canvas = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : TextMetrics._canvas;
  18288. var context = canvas.getContext('2d');
  18289. var line = '';
  18290. var width = 0;
  18291. var lines = '';
  18292. var cache = {};
  18293. var ls = style.letterSpacing;
  18294. // ideally there is letterSpacing after every char except the last one
  18295. // t_h_i_s_' '_i_s_' '_a_n_' '_e_x_a_m_p_l_e_' '_!
  18296. // so for convenience the above needs to be compared to width + 1 extra space
  18297. // t_h_i_s_' '_i_s_' '_a_n_' '_e_x_a_m_p_l_e_' '_!_
  18298. // ________________________________________________
  18299. // And then the final space is simply no appended to each line
  18300. var wordWrapWidth = style.wordWrapWidth + style.letterSpacing;
  18301. // get the width of a space and add it to cache
  18302. var spaceWidth = TextMetrics.getFromCache(' ', ls, cache, context);
  18303. // break text into words
  18304. var words = text.split(' ');
  18305. for (var i = 0; i < words.length; i++) {
  18306. var word = words[i];
  18307. // get word width from cache if possible
  18308. var wordWidth = TextMetrics.getFromCache(word, ls, cache, context);
  18309. // word is longer than desired bounds
  18310. if (wordWidth > wordWrapWidth) {
  18311. // break large word over multiple lines
  18312. if (style.breakWords) {
  18313. // add a space to the start of the word unless its at the beginning of the line
  18314. var tmpWord = line.length > 0 ? ' ' + word : word;
  18315. // break word into characters
  18316. var characters = tmpWord.split('');
  18317. // loop the characters
  18318. for (var j = 0; j < characters.length; j++) {
  18319. var character = characters[j];
  18320. var characterWidth = TextMetrics.getFromCache(character, ls, cache, context);
  18321. if (characterWidth + width > wordWrapWidth) {
  18322. lines += TextMetrics.addLine(line);
  18323. line = '';
  18324. width = 0;
  18325. }
  18326. line += character;
  18327. width += characterWidth;
  18328. }
  18329. }
  18330. // run word out of the bounds
  18331. else {
  18332. // if there are words in this line already
  18333. // finish that line and start a new one
  18334. if (line.length > 0) {
  18335. lines += TextMetrics.addLine(line);
  18336. line = '';
  18337. width = 0;
  18338. }
  18339. // give it its own line
  18340. lines += TextMetrics.addLine(word);
  18341. line = '';
  18342. width = 0;
  18343. }
  18344. }
  18345. // word could fit
  18346. else {
  18347. // word won't fit, start a new line
  18348. if (wordWidth + width > wordWrapWidth) {
  18349. lines += TextMetrics.addLine(line);
  18350. line = '';
  18351. width = 0;
  18352. }
  18353. // add the word to the current line
  18354. if (line.length > 0) {
  18355. // add a space if it is not the beginning
  18356. line += ' ' + word;
  18357. } else {
  18358. // add without a space if it is the beginning
  18359. line += word;
  18360. }
  18361. width += wordWidth + spaceWidth;
  18362. }
  18363. }
  18364. lines += TextMetrics.addLine(line, false);
  18365. return lines;
  18366. };
  18367. /**
  18368. * Convienience function for logging each line added
  18369. * during the wordWrap method
  18370. *
  18371. * @param {string} line - The line of text to add
  18372. * @param {boolean} newLine - Add new line character to end
  18373. * @return {string} A formatted line
  18374. */
  18375. TextMetrics.addLine = function addLine(line) {
  18376. var newLine = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
  18377. line = newLine ? line + '\n' : line;
  18378. return line;
  18379. };
  18380. /**
  18381. * Gets & sets the widths of calculated characters in a cache object
  18382. *
  18383. * @param {string} key The key
  18384. * @param {number} letterSpacing The letter spacing
  18385. * @param {object} cache The cache
  18386. * @param {CanvasRenderingContext2D} context The canvas context
  18387. * @return {number} The from cache.
  18388. */
  18389. TextMetrics.getFromCache = function getFromCache(key, letterSpacing, cache, context) {
  18390. var width = cache[key];
  18391. if (width === undefined) {
  18392. var spacing = key.length * letterSpacing;
  18393. width = context.measureText(key).width + spacing;
  18394. cache[key] = width;
  18395. }
  18396. return width;
  18397. };
  18398. /**
  18399. * Calculates the ascent, descent and fontSize of a given font-style
  18400. *
  18401. * @static
  18402. * @param {string} font - String representing the style of the font
  18403. * @return {PIXI.TextMetrics~FontMetrics} Font properties object
  18404. */
  18405. TextMetrics.measureFont = function measureFont(font) {
  18406. // as this method is used for preparing assets, don't recalculate things if we don't need to
  18407. if (TextMetrics._fonts[font]) {
  18408. return TextMetrics._fonts[font];
  18409. }
  18410. var properties = {};
  18411. var canvas = TextMetrics._canvas;
  18412. var context = TextMetrics._context;
  18413. context.font = font;
  18414. var width = Math.ceil(context.measureText('|MÉq').width);
  18415. var baseline = Math.ceil(context.measureText('M').width);
  18416. var height = 2 * baseline;
  18417. baseline = baseline * 1.4 | 0;
  18418. canvas.width = width;
  18419. canvas.height = height;
  18420. context.fillStyle = '#f00';
  18421. context.fillRect(0, 0, width, height);
  18422. context.font = font;
  18423. context.textBaseline = 'alphabetic';
  18424. context.fillStyle = '#000';
  18425. context.fillText('|MÉq', 0, baseline);
  18426. var imagedata = context.getImageData(0, 0, width, height).data;
  18427. var pixels = imagedata.length;
  18428. var line = width * 4;
  18429. var i = 0;
  18430. var idx = 0;
  18431. var stop = false;
  18432. // ascent. scan from top to bottom until we find a non red pixel
  18433. for (i = 0; i < baseline; ++i) {
  18434. for (var j = 0; j < line; j += 4) {
  18435. if (imagedata[idx + j] !== 255) {
  18436. stop = true;
  18437. break;
  18438. }
  18439. }
  18440. if (!stop) {
  18441. idx += line;
  18442. } else {
  18443. break;
  18444. }
  18445. }
  18446. properties.ascent = baseline - i;
  18447. idx = pixels - line;
  18448. stop = false;
  18449. // descent. scan from bottom to top until we find a non red pixel
  18450. for (i = height; i > baseline; --i) {
  18451. for (var _j = 0; _j < line; _j += 4) {
  18452. if (imagedata[idx + _j] !== 255) {
  18453. stop = true;
  18454. break;
  18455. }
  18456. }
  18457. if (!stop) {
  18458. idx -= line;
  18459. } else {
  18460. break;
  18461. }
  18462. }
  18463. properties.descent = i - baseline;
  18464. properties.fontSize = properties.ascent + properties.descent;
  18465. TextMetrics._fonts[font] = properties;
  18466. return properties;
  18467. };
  18468. return TextMetrics;
  18469. }();
  18470. /**
  18471. * Internal return object for {@link PIXI.TextMetrics.measureFont `TextMetrics.measureFont`}.
  18472. * @class FontMetrics
  18473. * @memberof PIXI.TextMetrics~
  18474. * @property {number} ascent - The ascent distance
  18475. * @property {number} descent - The descent distance
  18476. * @property {number} fontSize - Font size from ascent to descent
  18477. */
  18478. exports.default = TextMetrics;
  18479. var canvas = document.createElement('canvas');
  18480. canvas.width = canvas.height = 10;
  18481. /**
  18482. * Cached canvas element for measuring text
  18483. * @memberof PIXI.TextMetrics
  18484. * @type {HTMLCanvasElement}
  18485. * @private
  18486. */
  18487. TextMetrics._canvas = canvas;
  18488. /**
  18489. * Cache for context to use.
  18490. * @memberof PIXI.TextMetrics
  18491. * @type {CanvasRenderingContext2D}
  18492. * @private
  18493. */
  18494. TextMetrics._context = canvas.getContext('2d');
  18495. /**
  18496. * Cache of PIXI.TextMetrics~FontMetrics objects.
  18497. * @memberof PIXI.TextMetrics
  18498. * @type {Object}
  18499. * @private
  18500. */
  18501. TextMetrics._fonts = {};
  18502. }, {}], 110: [function (require, module, exports) {
  18503. 'use strict';
  18504. exports.__esModule = true;
  18505. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); // disabling eslint for now, going to rewrite this in v5
  18506. /* eslint-disable */
  18507. var _const = require('../const');
  18508. var _utils = require('../utils');
  18509. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  18510. var defaultStyle = {
  18511. align: 'left',
  18512. breakWords: false,
  18513. dropShadow: false,
  18514. dropShadowAlpha: 1,
  18515. dropShadowAngle: Math.PI / 6,
  18516. dropShadowBlur: 0,
  18517. dropShadowColor: 'black',
  18518. dropShadowDistance: 5,
  18519. fill: 'black',
  18520. fillGradientType: _const.TEXT_GRADIENT.LINEAR_VERTICAL,
  18521. fillGradientStops: [],
  18522. fontFamily: 'Arial',
  18523. fontSize: 26,
  18524. fontStyle: 'normal',
  18525. fontVariant: 'normal',
  18526. fontWeight: 'normal',
  18527. letterSpacing: 0,
  18528. lineHeight: 0,
  18529. lineJoin: 'miter',
  18530. miterLimit: 10,
  18531. padding: 0,
  18532. stroke: 'black',
  18533. strokeThickness: 0,
  18534. textBaseline: 'alphabetic',
  18535. trim: false,
  18536. wordWrap: false,
  18537. wordWrapWidth: 100,
  18538. leading: 0
  18539. };
  18540. /**
  18541. * A TextStyle Object decorates a Text Object. It can be shared between
  18542. * multiple Text objects. Changing the style will update all text objects using it.
  18543. *
  18544. * @class
  18545. * @memberof PIXI
  18546. */
  18547. var TextStyle = function () {
  18548. /**
  18549. * @param {object} [style] - The style parameters
  18550. * @param {string} [style.align='left'] - Alignment for multiline text ('left', 'center' or 'right'),
  18551. * does not affect single line text
  18552. * @param {boolean} [style.breakWords=false] - Indicates if lines can be wrapped within words, it
  18553. * needs wordWrap to be set to true
  18554. * @param {boolean} [style.dropShadow=false] - Set a drop shadow for the text
  18555. * @param {number} [style.dropShadowAlpha=1] - Set alpha for the drop shadow
  18556. * @param {number} [style.dropShadowAngle=Math.PI/6] - Set a angle of the drop shadow
  18557. * @param {number} [style.dropShadowBlur=0] - Set a shadow blur radius
  18558. * @param {string|number} [style.dropShadowColor='black'] - A fill style to be used on the dropshadow e.g 'red', '#00FF00'
  18559. * @param {number} [style.dropShadowDistance=5] - Set a distance of the drop shadow
  18560. * @param {string|string[]|number|number[]|CanvasGradient|CanvasPattern} [style.fill='black'] - A canvas
  18561. * fillstyle that will be used on the text e.g 'red', '#00FF00'. Can be an array to create a gradient
  18562. * eg ['#000000','#FFFFFF']
  18563. * {@link https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/fillStyle|MDN}
  18564. * @param {number} [style.fillGradientType=PIXI.TEXT_GRADIENT.LINEAR_VERTICAL] - If fill is an array of colours
  18565. * to create a gradient, this can change the type/direction of the gradient. See {@link PIXI.TEXT_GRADIENT}
  18566. * @param {number[]} [style.fillGradientStops] - If fill is an array of colours to create a gradient, this array can set
  18567. * the stop points (numbers between 0 and 1) for the color, overriding the default behaviour of evenly spacing them.
  18568. * @param {string|string[]} [style.fontFamily='Arial'] - The font family
  18569. * @param {number|string} [style.fontSize=26] - The font size (as a number it converts to px, but as a string,
  18570. * equivalents are '26px','20pt','160%' or '1.6em')
  18571. * @param {string} [style.fontStyle='normal'] - The font style ('normal', 'italic' or 'oblique')
  18572. * @param {string} [style.fontVariant='normal'] - The font variant ('normal' or 'small-caps')
  18573. * @param {string} [style.fontWeight='normal'] - The font weight ('normal', 'bold', 'bolder', 'lighter' and '100',
  18574. * '200', '300', '400', '500', '600', '700', 800' or '900')
  18575. * @param {number} [style.leading=0] - The space between lines
  18576. * @param {number} [style.letterSpacing=0] - The amount of spacing between letters, default is 0
  18577. * @param {number} [style.lineHeight] - The line height, a number that represents the vertical space that a letter uses
  18578. * @param {string} [style.lineJoin='miter'] - The lineJoin property sets the type of corner created, it can resolve
  18579. * spiked text issues. Possible values "miter" (creates a sharp corner), "round" (creates a round corner) or "bevel"
  18580. * (creates a squared corner).
  18581. * @param {number} [style.miterLimit=10] - The miter limit to use when using the 'miter' lineJoin mode. This can reduce
  18582. * or increase the spikiness of rendered text.
  18583. * @param {number} [style.padding=0] - Occasionally some fonts are cropped. Adding some padding will prevent this from
  18584. * happening by adding padding to all sides of the text.
  18585. * @param {string|number} [style.stroke='black'] - A canvas fillstyle that will be used on the text stroke
  18586. * e.g 'blue', '#FCFF00'
  18587. * @param {number} [style.strokeThickness=0] - A number that represents the thickness of the stroke.
  18588. * Default is 0 (no stroke)
  18589. * @param {boolean} [style.trim=false] - Trim transparent borders
  18590. * @param {string} [style.textBaseline='alphabetic'] - The baseline of the text that is rendered.
  18591. * @param {boolean} [style.wordWrap=false] - Indicates if word wrap should be used
  18592. * @param {number} [style.wordWrapWidth=100] - The width at which text will wrap, it needs wordWrap to be set to true
  18593. */
  18594. function TextStyle(style) {
  18595. _classCallCheck(this, TextStyle);
  18596. this.styleID = 0;
  18597. this.reset();
  18598. deepCopyProperties(this, style, style);
  18599. }
  18600. /**
  18601. * Creates a new TextStyle object with the same values as this one.
  18602. * Note that the only the properties of the object are cloned.
  18603. *
  18604. * @return {PIXI.TextStyle} New cloned TextStyle object
  18605. */
  18606. TextStyle.prototype.clone = function clone() {
  18607. var clonedProperties = {};
  18608. deepCopyProperties(clonedProperties, this, defaultStyle);
  18609. return new TextStyle(clonedProperties);
  18610. };
  18611. /**
  18612. * Resets all properties to the defaults specified in TextStyle.prototype._default
  18613. */
  18614. TextStyle.prototype.reset = function reset() {
  18615. deepCopyProperties(this, defaultStyle, defaultStyle);
  18616. };
  18617. /**
  18618. * Alignment for multiline text ('left', 'center' or 'right'), does not affect single line text
  18619. *
  18620. * @member {string}
  18621. */
  18622. /**
  18623. * Generates a font style string to use for `TextMetrics.measureFont()`.
  18624. *
  18625. * @return {string} Font style string, for passing to `TextMetrics.measureFont()`
  18626. */
  18627. TextStyle.prototype.toFontString = function toFontString() {
  18628. // build canvas api font setting from individual components. Convert a numeric this.fontSize to px
  18629. var fontSizeString = typeof this.fontSize === 'number' ? this.fontSize + 'px' : this.fontSize;
  18630. // Clean-up fontFamily property by quoting each font name
  18631. // this will support font names with spaces
  18632. var fontFamilies = this.fontFamily;
  18633. if (!Array.isArray(this.fontFamily)) {
  18634. fontFamilies = this.fontFamily.split(',');
  18635. }
  18636. for (var i = fontFamilies.length - 1; i >= 0; i--) {
  18637. // Trim any extra white-space
  18638. var fontFamily = fontFamilies[i].trim();
  18639. // Check if font already contains strings
  18640. if (!/([\"\'])[^\'\"]+\1/.test(fontFamily)) {
  18641. fontFamily = '"' + fontFamily + '"';
  18642. }
  18643. fontFamilies[i] = fontFamily;
  18644. }
  18645. return this.fontStyle + ' ' + this.fontVariant + ' ' + this.fontWeight + ' ' + fontSizeString + ' ' + fontFamilies.join(',');
  18646. };
  18647. _createClass(TextStyle, [{
  18648. key: 'align',
  18649. get: function get() {
  18650. return this._align;
  18651. },
  18652. set: function set(align) // eslint-disable-line require-jsdoc
  18653. {
  18654. if (this._align !== align) {
  18655. this._align = align;
  18656. this.styleID++;
  18657. }
  18658. }
  18659. /**
  18660. * Indicates if lines can be wrapped within words, it needs wordWrap to be set to true
  18661. *
  18662. * @member {boolean}
  18663. */
  18664. }, {
  18665. key: 'breakWords',
  18666. get: function get() {
  18667. return this._breakWords;
  18668. },
  18669. set: function set(breakWords) // eslint-disable-line require-jsdoc
  18670. {
  18671. if (this._breakWords !== breakWords) {
  18672. this._breakWords = breakWords;
  18673. this.styleID++;
  18674. }
  18675. }
  18676. /**
  18677. * Set a drop shadow for the text
  18678. *
  18679. * @member {boolean}
  18680. */
  18681. }, {
  18682. key: 'dropShadow',
  18683. get: function get() {
  18684. return this._dropShadow;
  18685. },
  18686. set: function set(dropShadow) // eslint-disable-line require-jsdoc
  18687. {
  18688. if (this._dropShadow !== dropShadow) {
  18689. this._dropShadow = dropShadow;
  18690. this.styleID++;
  18691. }
  18692. }
  18693. /**
  18694. * Set alpha for the drop shadow
  18695. *
  18696. * @member {number}
  18697. */
  18698. }, {
  18699. key: 'dropShadowAlpha',
  18700. get: function get() {
  18701. return this._dropShadowAlpha;
  18702. },
  18703. set: function set(dropShadowAlpha) // eslint-disable-line require-jsdoc
  18704. {
  18705. if (this._dropShadowAlpha !== dropShadowAlpha) {
  18706. this._dropShadowAlpha = dropShadowAlpha;
  18707. this.styleID++;
  18708. }
  18709. }
  18710. /**
  18711. * Set a angle of the drop shadow
  18712. *
  18713. * @member {number}
  18714. */
  18715. }, {
  18716. key: 'dropShadowAngle',
  18717. get: function get() {
  18718. return this._dropShadowAngle;
  18719. },
  18720. set: function set(dropShadowAngle) // eslint-disable-line require-jsdoc
  18721. {
  18722. if (this._dropShadowAngle !== dropShadowAngle) {
  18723. this._dropShadowAngle = dropShadowAngle;
  18724. this.styleID++;
  18725. }
  18726. }
  18727. /**
  18728. * Set a shadow blur radius
  18729. *
  18730. * @member {number}
  18731. */
  18732. }, {
  18733. key: 'dropShadowBlur',
  18734. get: function get() {
  18735. return this._dropShadowBlur;
  18736. },
  18737. set: function set(dropShadowBlur) // eslint-disable-line require-jsdoc
  18738. {
  18739. if (this._dropShadowBlur !== dropShadowBlur) {
  18740. this._dropShadowBlur = dropShadowBlur;
  18741. this.styleID++;
  18742. }
  18743. }
  18744. /**
  18745. * A fill style to be used on the dropshadow e.g 'red', '#00FF00'
  18746. *
  18747. * @member {string|number}
  18748. */
  18749. }, {
  18750. key: 'dropShadowColor',
  18751. get: function get() {
  18752. return this._dropShadowColor;
  18753. },
  18754. set: function set(dropShadowColor) // eslint-disable-line require-jsdoc
  18755. {
  18756. var outputColor = getColor(dropShadowColor);
  18757. if (this._dropShadowColor !== outputColor) {
  18758. this._dropShadowColor = outputColor;
  18759. this.styleID++;
  18760. }
  18761. }
  18762. /**
  18763. * Set a distance of the drop shadow
  18764. *
  18765. * @member {number}
  18766. */
  18767. }, {
  18768. key: 'dropShadowDistance',
  18769. get: function get() {
  18770. return this._dropShadowDistance;
  18771. },
  18772. set: function set(dropShadowDistance) // eslint-disable-line require-jsdoc
  18773. {
  18774. if (this._dropShadowDistance !== dropShadowDistance) {
  18775. this._dropShadowDistance = dropShadowDistance;
  18776. this.styleID++;
  18777. }
  18778. }
  18779. /**
  18780. * A canvas fillstyle that will be used on the text e.g 'red', '#00FF00'.
  18781. * Can be an array to create a gradient eg ['#000000','#FFFFFF']
  18782. * {@link https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/fillStyle|MDN}
  18783. *
  18784. * @member {string|string[]|number|number[]|CanvasGradient|CanvasPattern}
  18785. */
  18786. }, {
  18787. key: 'fill',
  18788. get: function get() {
  18789. return this._fill;
  18790. },
  18791. set: function set(fill) // eslint-disable-line require-jsdoc
  18792. {
  18793. var outputColor = getColor(fill);
  18794. if (this._fill !== outputColor) {
  18795. this._fill = outputColor;
  18796. this.styleID++;
  18797. }
  18798. }
  18799. /**
  18800. * If fill is an array of colours to create a gradient, this can change the type/direction of the gradient.
  18801. * See {@link PIXI.TEXT_GRADIENT}
  18802. *
  18803. * @member {number}
  18804. */
  18805. }, {
  18806. key: 'fillGradientType',
  18807. get: function get() {
  18808. return this._fillGradientType;
  18809. },
  18810. set: function set(fillGradientType) // eslint-disable-line require-jsdoc
  18811. {
  18812. if (this._fillGradientType !== fillGradientType) {
  18813. this._fillGradientType = fillGradientType;
  18814. this.styleID++;
  18815. }
  18816. }
  18817. /**
  18818. * If fill is an array of colours to create a gradient, this array can set the stop points
  18819. * (numbers between 0 and 1) for the color, overriding the default behaviour of evenly spacing them.
  18820. *
  18821. * @member {number[]}
  18822. */
  18823. }, {
  18824. key: 'fillGradientStops',
  18825. get: function get() {
  18826. return this._fillGradientStops;
  18827. },
  18828. set: function set(fillGradientStops) // eslint-disable-line require-jsdoc
  18829. {
  18830. if (!areArraysEqual(this._fillGradientStops, fillGradientStops)) {
  18831. this._fillGradientStops = fillGradientStops;
  18832. this.styleID++;
  18833. }
  18834. }
  18835. /**
  18836. * The font family
  18837. *
  18838. * @member {string|string[]}
  18839. */
  18840. }, {
  18841. key: 'fontFamily',
  18842. get: function get() {
  18843. return this._fontFamily;
  18844. },
  18845. set: function set(fontFamily) // eslint-disable-line require-jsdoc
  18846. {
  18847. if (this.fontFamily !== fontFamily) {
  18848. this._fontFamily = fontFamily;
  18849. this.styleID++;
  18850. }
  18851. }
  18852. /**
  18853. * The font size
  18854. * (as a number it converts to px, but as a string, equivalents are '26px','20pt','160%' or '1.6em')
  18855. *
  18856. * @member {number|string}
  18857. */
  18858. }, {
  18859. key: 'fontSize',
  18860. get: function get() {
  18861. return this._fontSize;
  18862. },
  18863. set: function set(fontSize) // eslint-disable-line require-jsdoc
  18864. {
  18865. if (this._fontSize !== fontSize) {
  18866. this._fontSize = fontSize;
  18867. this.styleID++;
  18868. }
  18869. }
  18870. /**
  18871. * The font style
  18872. * ('normal', 'italic' or 'oblique')
  18873. *
  18874. * @member {string}
  18875. */
  18876. }, {
  18877. key: 'fontStyle',
  18878. get: function get() {
  18879. return this._fontStyle;
  18880. },
  18881. set: function set(fontStyle) // eslint-disable-line require-jsdoc
  18882. {
  18883. if (this._fontStyle !== fontStyle) {
  18884. this._fontStyle = fontStyle;
  18885. this.styleID++;
  18886. }
  18887. }
  18888. /**
  18889. * The font variant
  18890. * ('normal' or 'small-caps')
  18891. *
  18892. * @member {string}
  18893. */
  18894. }, {
  18895. key: 'fontVariant',
  18896. get: function get() {
  18897. return this._fontVariant;
  18898. },
  18899. set: function set(fontVariant) // eslint-disable-line require-jsdoc
  18900. {
  18901. if (this._fontVariant !== fontVariant) {
  18902. this._fontVariant = fontVariant;
  18903. this.styleID++;
  18904. }
  18905. }
  18906. /**
  18907. * The font weight
  18908. * ('normal', 'bold', 'bolder', 'lighter' and '100', '200', '300', '400', '500', '600', '700', 800' or '900')
  18909. *
  18910. * @member {string}
  18911. */
  18912. }, {
  18913. key: 'fontWeight',
  18914. get: function get() {
  18915. return this._fontWeight;
  18916. },
  18917. set: function set(fontWeight) // eslint-disable-line require-jsdoc
  18918. {
  18919. if (this._fontWeight !== fontWeight) {
  18920. this._fontWeight = fontWeight;
  18921. this.styleID++;
  18922. }
  18923. }
  18924. /**
  18925. * The amount of spacing between letters, default is 0
  18926. *
  18927. * @member {number}
  18928. */
  18929. }, {
  18930. key: 'letterSpacing',
  18931. get: function get() {
  18932. return this._letterSpacing;
  18933. },
  18934. set: function set(letterSpacing) // eslint-disable-line require-jsdoc
  18935. {
  18936. if (this._letterSpacing !== letterSpacing) {
  18937. this._letterSpacing = letterSpacing;
  18938. this.styleID++;
  18939. }
  18940. }
  18941. /**
  18942. * The line height, a number that represents the vertical space that a letter uses
  18943. *
  18944. * @member {number}
  18945. */
  18946. }, {
  18947. key: 'lineHeight',
  18948. get: function get() {
  18949. return this._lineHeight;
  18950. },
  18951. set: function set(lineHeight) // eslint-disable-line require-jsdoc
  18952. {
  18953. if (this._lineHeight !== lineHeight) {
  18954. this._lineHeight = lineHeight;
  18955. this.styleID++;
  18956. }
  18957. }
  18958. /**
  18959. * The space between lines
  18960. *
  18961. * @member {number}
  18962. */
  18963. }, {
  18964. key: 'leading',
  18965. get: function get() {
  18966. return this._leading;
  18967. },
  18968. set: function set(leading) // eslint-disable-line require-jsdoc
  18969. {
  18970. if (this._leading !== leading) {
  18971. this._leading = leading;
  18972. this.styleID++;
  18973. }
  18974. }
  18975. /**
  18976. * The lineJoin property sets the type of corner created, it can resolve spiked text issues.
  18977. * Default is 'miter' (creates a sharp corner).
  18978. *
  18979. * @member {string}
  18980. */
  18981. }, {
  18982. key: 'lineJoin',
  18983. get: function get() {
  18984. return this._lineJoin;
  18985. },
  18986. set: function set(lineJoin) // eslint-disable-line require-jsdoc
  18987. {
  18988. if (this._lineJoin !== lineJoin) {
  18989. this._lineJoin = lineJoin;
  18990. this.styleID++;
  18991. }
  18992. }
  18993. /**
  18994. * The miter limit to use when using the 'miter' lineJoin mode
  18995. * This can reduce or increase the spikiness of rendered text.
  18996. *
  18997. * @member {number}
  18998. */
  18999. }, {
  19000. key: 'miterLimit',
  19001. get: function get() {
  19002. return this._miterLimit;
  19003. },
  19004. set: function set(miterLimit) // eslint-disable-line require-jsdoc
  19005. {
  19006. if (this._miterLimit !== miterLimit) {
  19007. this._miterLimit = miterLimit;
  19008. this.styleID++;
  19009. }
  19010. }
  19011. /**
  19012. * Occasionally some fonts are cropped. Adding some padding will prevent this from happening
  19013. * by adding padding to all sides of the text.
  19014. *
  19015. * @member {number}
  19016. */
  19017. }, {
  19018. key: 'padding',
  19019. get: function get() {
  19020. return this._padding;
  19021. },
  19022. set: function set(padding) // eslint-disable-line require-jsdoc
  19023. {
  19024. if (this._padding !== padding) {
  19025. this._padding = padding;
  19026. this.styleID++;
  19027. }
  19028. }
  19029. /**
  19030. * A canvas fillstyle that will be used on the text stroke
  19031. * e.g 'blue', '#FCFF00'
  19032. *
  19033. * @member {string|number}
  19034. */
  19035. }, {
  19036. key: 'stroke',
  19037. get: function get() {
  19038. return this._stroke;
  19039. },
  19040. set: function set(stroke) // eslint-disable-line require-jsdoc
  19041. {
  19042. var outputColor = getColor(stroke);
  19043. if (this._stroke !== outputColor) {
  19044. this._stroke = outputColor;
  19045. this.styleID++;
  19046. }
  19047. }
  19048. /**
  19049. * A number that represents the thickness of the stroke.
  19050. * Default is 0 (no stroke)
  19051. *
  19052. * @member {number}
  19053. */
  19054. }, {
  19055. key: 'strokeThickness',
  19056. get: function get() {
  19057. return this._strokeThickness;
  19058. },
  19059. set: function set(strokeThickness) // eslint-disable-line require-jsdoc
  19060. {
  19061. if (this._strokeThickness !== strokeThickness) {
  19062. this._strokeThickness = strokeThickness;
  19063. this.styleID++;
  19064. }
  19065. }
  19066. /**
  19067. * The baseline of the text that is rendered.
  19068. *
  19069. * @member {string}
  19070. */
  19071. }, {
  19072. key: 'textBaseline',
  19073. get: function get() {
  19074. return this._textBaseline;
  19075. },
  19076. set: function set(textBaseline) // eslint-disable-line require-jsdoc
  19077. {
  19078. if (this._textBaseline !== textBaseline) {
  19079. this._textBaseline = textBaseline;
  19080. this.styleID++;
  19081. }
  19082. }
  19083. /**
  19084. * Trim transparent borders
  19085. *
  19086. * @member {boolean}
  19087. */
  19088. }, {
  19089. key: 'trim',
  19090. get: function get() {
  19091. return this._trim;
  19092. },
  19093. set: function set(trim) // eslint-disable-line require-jsdoc
  19094. {
  19095. if (this._trim !== trim) {
  19096. this._trim = trim;
  19097. this.styleID++;
  19098. }
  19099. }
  19100. /**
  19101. * Indicates if word wrap should be used
  19102. *
  19103. * @member {boolean}
  19104. */
  19105. }, {
  19106. key: 'wordWrap',
  19107. get: function get() {
  19108. return this._wordWrap;
  19109. },
  19110. set: function set(wordWrap) // eslint-disable-line require-jsdoc
  19111. {
  19112. if (this._wordWrap !== wordWrap) {
  19113. this._wordWrap = wordWrap;
  19114. this.styleID++;
  19115. }
  19116. }
  19117. /**
  19118. * The width at which text will wrap, it needs wordWrap to be set to true
  19119. *
  19120. * @member {number}
  19121. */
  19122. }, {
  19123. key: 'wordWrapWidth',
  19124. get: function get() {
  19125. return this._wordWrapWidth;
  19126. },
  19127. set: function set(wordWrapWidth) // eslint-disable-line require-jsdoc
  19128. {
  19129. if (this._wordWrapWidth !== wordWrapWidth) {
  19130. this._wordWrapWidth = wordWrapWidth;
  19131. this.styleID++;
  19132. }
  19133. }
  19134. }]);
  19135. return TextStyle;
  19136. }();
  19137. /**
  19138. * Utility function to convert hexadecimal colors to strings, and simply return the color if it's a string.
  19139. * @private
  19140. * @param {number|number[]} color
  19141. * @return {string} The color as a string.
  19142. */
  19143. exports.default = TextStyle;
  19144. function getSingleColor(color) {
  19145. if (typeof color === 'number') {
  19146. return (0, _utils.hex2string)(color);
  19147. } else if (typeof color === 'string') {
  19148. if (color.indexOf('0x') === 0) {
  19149. color = color.replace('0x', '#');
  19150. }
  19151. }
  19152. return color;
  19153. }
  19154. /**
  19155. * Utility function to convert hexadecimal colors to strings, and simply return the color if it's a string.
  19156. * This version can also convert array of colors
  19157. * @private
  19158. * @param {number|number[]} color
  19159. * @return {string} The color as a string.
  19160. */
  19161. function getColor(color) {
  19162. if (!Array.isArray(color)) {
  19163. return getSingleColor(color);
  19164. } else {
  19165. for (var i = 0; i < color.length; ++i) {
  19166. color[i] = getSingleColor(color[i]);
  19167. }
  19168. return color;
  19169. }
  19170. }
  19171. /**
  19172. * Utility function to convert hexadecimal colors to strings, and simply return the color if it's a string.
  19173. * This version can also convert array of colors
  19174. * @private
  19175. * @param {Array} array1 First array to compare
  19176. * @param {Array} array2 Second array to compare
  19177. * @return {boolean} Do the arrays contain the same values in the same order
  19178. */
  19179. function areArraysEqual(array1, array2) {
  19180. if (!Array.isArray(array1) || !Array.isArray(array2)) {
  19181. return false;
  19182. }
  19183. if (array1.length !== array2.length) {
  19184. return false;
  19185. }
  19186. for (var i = 0; i < array1.length; ++i) {
  19187. if (array1[i] !== array2[i]) {
  19188. return false;
  19189. }
  19190. }
  19191. return true;
  19192. }
  19193. /**
  19194. * Utility function to ensure that object properties are copied by value, and not by reference
  19195. * @private
  19196. * @param {Object} target Target object to copy properties into
  19197. * @param {Object} source Source object for the proporties to copy
  19198. * @param {string} propertyObj Object containing properties names we want to loop over
  19199. */
  19200. function deepCopyProperties(target, source, propertyObj) {
  19201. for (var prop in propertyObj) {
  19202. if (Array.isArray(source[prop])) {
  19203. target[prop] = source[prop].slice();
  19204. } else {
  19205. target[prop] = source[prop];
  19206. }
  19207. }
  19208. }
  19209. }, { "../const": 46, "../utils": 125 }], 111: [function (require, module, exports) {
  19210. 'use strict';
  19211. exports.__esModule = true;
  19212. var _BaseTexture2 = require('./BaseTexture');
  19213. var _BaseTexture3 = _interopRequireDefault(_BaseTexture2);
  19214. var _settings = require('../settings');
  19215. var _settings2 = _interopRequireDefault(_settings);
  19216. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  19217. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  19218. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  19219. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  19220. /**
  19221. * A BaseRenderTexture is a special texture that allows any PixiJS display object to be rendered to it.
  19222. *
  19223. * __Hint__: All DisplayObjects (i.e. Sprites) that render to a BaseRenderTexture should be preloaded
  19224. * otherwise black rectangles will be drawn instead.
  19225. *
  19226. * A BaseRenderTexture takes a snapshot of any Display Object given to its render method. The position
  19227. * and rotation of the given Display Objects is ignored. For example:
  19228. *
  19229. * ```js
  19230. * let renderer = PIXI.autoDetectRenderer(1024, 1024, { view: canvas, ratio: 1 });
  19231. * let baseRenderTexture = new PIXI.BaseRenderTexture(renderer, 800, 600);
  19232. * let sprite = PIXI.Sprite.fromImage("spinObj_01.png");
  19233. *
  19234. * sprite.position.x = 800/2;
  19235. * sprite.position.y = 600/2;
  19236. * sprite.anchor.x = 0.5;
  19237. * sprite.anchor.y = 0.5;
  19238. *
  19239. * baseRenderTexture.render(sprite);
  19240. * ```
  19241. *
  19242. * The Sprite in this case will be rendered using its local transform. To render this sprite at 0,0
  19243. * you can clear the transform
  19244. *
  19245. * ```js
  19246. *
  19247. * sprite.setTransform()
  19248. *
  19249. * let baseRenderTexture = new PIXI.BaseRenderTexture(100, 100);
  19250. * let renderTexture = new PIXI.RenderTexture(baseRenderTexture);
  19251. *
  19252. * renderer.render(sprite, renderTexture); // Renders to center of RenderTexture
  19253. * ```
  19254. *
  19255. * @class
  19256. * @extends PIXI.BaseTexture
  19257. * @memberof PIXI
  19258. */
  19259. var BaseRenderTexture = function (_BaseTexture) {
  19260. _inherits(BaseRenderTexture, _BaseTexture);
  19261. /**
  19262. * @param {number} [width=100] - The width of the base render texture
  19263. * @param {number} [height=100] - The height of the base render texture
  19264. * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values
  19265. * @param {number} [resolution=1] - The resolution / device pixel ratio of the texture being generated
  19266. */
  19267. function BaseRenderTexture() {
  19268. var width = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 100;
  19269. var height = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 100;
  19270. var scaleMode = arguments[2];
  19271. var resolution = arguments[3];
  19272. _classCallCheck(this, BaseRenderTexture);
  19273. var _this = _possibleConstructorReturn(this, _BaseTexture.call(this, null, scaleMode));
  19274. _this.resolution = resolution || _settings2.default.RESOLUTION;
  19275. _this.width = Math.ceil(width);
  19276. _this.height = Math.ceil(height);
  19277. _this.realWidth = _this.width * _this.resolution;
  19278. _this.realHeight = _this.height * _this.resolution;
  19279. _this.scaleMode = scaleMode !== undefined ? scaleMode : _settings2.default.SCALE_MODE;
  19280. _this.hasLoaded = true;
  19281. /**
  19282. * A map of renderer IDs to webgl renderTargets
  19283. *
  19284. * @private
  19285. * @member {object<number, WebGLTexture>}
  19286. */
  19287. _this._glRenderTargets = {};
  19288. /**
  19289. * A reference to the canvas render target (we only need one as this can be shared across renderers)
  19290. *
  19291. * @private
  19292. * @member {object<number, WebGLTexture>}
  19293. */
  19294. _this._canvasRenderTarget = null;
  19295. /**
  19296. * This will let the renderer know if the texture is valid. If it's not then it cannot be rendered.
  19297. *
  19298. * @member {boolean}
  19299. */
  19300. _this.valid = false;
  19301. return _this;
  19302. }
  19303. /**
  19304. * Resizes the BaseRenderTexture.
  19305. *
  19306. * @param {number} width - The width to resize to.
  19307. * @param {number} height - The height to resize to.
  19308. */
  19309. BaseRenderTexture.prototype.resize = function resize(width, height) {
  19310. width = Math.ceil(width);
  19311. height = Math.ceil(height);
  19312. if (width === this.width && height === this.height) {
  19313. return;
  19314. }
  19315. this.valid = width > 0 && height > 0;
  19316. this.width = width;
  19317. this.height = height;
  19318. this.realWidth = this.width * this.resolution;
  19319. this.realHeight = this.height * this.resolution;
  19320. if (!this.valid) {
  19321. return;
  19322. }
  19323. this.emit('update', this);
  19324. };
  19325. /**
  19326. * Destroys this texture
  19327. *
  19328. */
  19329. BaseRenderTexture.prototype.destroy = function destroy() {
  19330. _BaseTexture.prototype.destroy.call(this, true);
  19331. this.renderer = null;
  19332. };
  19333. return BaseRenderTexture;
  19334. }(_BaseTexture3.default);
  19335. exports.default = BaseRenderTexture;
  19336. }, { "../settings": 101, "./BaseTexture": 112 }], 112: [function (require, module, exports) {
  19337. 'use strict';
  19338. exports.__esModule = true;
  19339. var _utils = require('../utils');
  19340. var _settings = require('../settings');
  19341. var _settings2 = _interopRequireDefault(_settings);
  19342. var _eventemitter = require('eventemitter3');
  19343. var _eventemitter2 = _interopRequireDefault(_eventemitter);
  19344. var _determineCrossOrigin = require('../utils/determineCrossOrigin');
  19345. var _determineCrossOrigin2 = _interopRequireDefault(_determineCrossOrigin);
  19346. var _bitTwiddle = require('bit-twiddle');
  19347. var _bitTwiddle2 = _interopRequireDefault(_bitTwiddle);
  19348. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  19349. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  19350. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  19351. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  19352. /**
  19353. * A texture stores the information that represents an image. All textures have a base texture.
  19354. *
  19355. * @class
  19356. * @extends EventEmitter
  19357. * @memberof PIXI
  19358. */
  19359. var BaseTexture = function (_EventEmitter) {
  19360. _inherits(BaseTexture, _EventEmitter);
  19361. /**
  19362. * @param {HTMLImageElement|HTMLCanvasElement} [source] - the source object of the texture.
  19363. * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values
  19364. * @param {number} [resolution=1] - The resolution / device pixel ratio of the texture
  19365. */
  19366. function BaseTexture(source, scaleMode, resolution) {
  19367. _classCallCheck(this, BaseTexture);
  19368. var _this = _possibleConstructorReturn(this, _EventEmitter.call(this));
  19369. _this.uid = (0, _utils.uid)();
  19370. _this.touched = 0;
  19371. /**
  19372. * The resolution / device pixel ratio of the texture
  19373. *
  19374. * @member {number}
  19375. * @default 1
  19376. */
  19377. _this.resolution = resolution || _settings2.default.RESOLUTION;
  19378. /**
  19379. * The width of the base texture set when the image has loaded
  19380. *
  19381. * @readonly
  19382. * @member {number}
  19383. */
  19384. _this.width = 100;
  19385. /**
  19386. * The height of the base texture set when the image has loaded
  19387. *
  19388. * @readonly
  19389. * @member {number}
  19390. */
  19391. _this.height = 100;
  19392. // TODO docs
  19393. // used to store the actual dimensions of the source
  19394. /**
  19395. * Used to store the actual width of the source of this texture
  19396. *
  19397. * @readonly
  19398. * @member {number}
  19399. */
  19400. _this.realWidth = 100;
  19401. /**
  19402. * Used to store the actual height of the source of this texture
  19403. *
  19404. * @readonly
  19405. * @member {number}
  19406. */
  19407. _this.realHeight = 100;
  19408. /**
  19409. * The scale mode to apply when scaling this texture
  19410. *
  19411. * @member {number}
  19412. * @default PIXI.settings.SCALE_MODE
  19413. * @see PIXI.SCALE_MODES
  19414. */
  19415. _this.scaleMode = scaleMode !== undefined ? scaleMode : _settings2.default.SCALE_MODE;
  19416. /**
  19417. * Set to true once the base texture has successfully loaded.
  19418. *
  19419. * This is never true if the underlying source fails to load or has no texture data.
  19420. *
  19421. * @readonly
  19422. * @member {boolean}
  19423. */
  19424. _this.hasLoaded = false;
  19425. /**
  19426. * Set to true if the source is currently loading.
  19427. *
  19428. * If an Image source is loading the 'loaded' or 'error' event will be
  19429. * dispatched when the operation ends. An underyling source that is
  19430. * immediately-available bypasses loading entirely.
  19431. *
  19432. * @readonly
  19433. * @member {boolean}
  19434. */
  19435. _this.isLoading = false;
  19436. /**
  19437. * The image source that is used to create the texture.
  19438. *
  19439. * TODO: Make this a setter that calls loadSource();
  19440. *
  19441. * @readonly
  19442. * @member {HTMLImageElement|HTMLCanvasElement}
  19443. */
  19444. _this.source = null; // set in loadSource, if at all
  19445. /**
  19446. * The image source that is used to create the texture. This is used to
  19447. * store the original Svg source when it is replaced with a canvas element.
  19448. *
  19449. * TODO: Currently not in use but could be used when re-scaling svg.
  19450. *
  19451. * @readonly
  19452. * @member {Image}
  19453. */
  19454. _this.origSource = null; // set in loadSvg, if at all
  19455. /**
  19456. * Type of image defined in source, eg. `png` or `svg`
  19457. *
  19458. * @readonly
  19459. * @member {string}
  19460. */
  19461. _this.imageType = null; // set in updateImageType
  19462. /**
  19463. * Scale for source image. Used with Svg images to scale them before rasterization.
  19464. *
  19465. * @readonly
  19466. * @member {number}
  19467. */
  19468. _this.sourceScale = 1.0;
  19469. /**
  19470. * Controls if RGB channels should be pre-multiplied by Alpha (WebGL only)
  19471. * All blend modes, and shaders written for default value. Change it on your own risk.
  19472. *
  19473. * @member {boolean}
  19474. * @default true
  19475. */
  19476. _this.premultipliedAlpha = true;
  19477. /**
  19478. * The image url of the texture
  19479. *
  19480. * @member {string}
  19481. */
  19482. _this.imageUrl = null;
  19483. /**
  19484. * Whether or not the texture is a power of two, try to use power of two textures as much
  19485. * as you can
  19486. *
  19487. * @private
  19488. * @member {boolean}
  19489. */
  19490. _this.isPowerOfTwo = false;
  19491. // used for webGL
  19492. /**
  19493. *
  19494. * Set this to true if a mipmap of this texture needs to be generated. This value needs
  19495. * to be set before the texture is used
  19496. * Also the texture must be a power of two size to work
  19497. *
  19498. * @member {boolean}
  19499. * @see PIXI.MIPMAP_TEXTURES
  19500. */
  19501. _this.mipmap = _settings2.default.MIPMAP_TEXTURES;
  19502. /**
  19503. *
  19504. * WebGL Texture wrap mode
  19505. *
  19506. * @member {number}
  19507. * @see PIXI.WRAP_MODES
  19508. */
  19509. _this.wrapMode = _settings2.default.WRAP_MODE;
  19510. /**
  19511. * A map of renderer IDs to webgl textures
  19512. *
  19513. * @private
  19514. * @member {object<number, WebGLTexture>}
  19515. */
  19516. _this._glTextures = {};
  19517. _this._enabled = 0;
  19518. _this._virtalBoundId = -1;
  19519. /**
  19520. * If the object has been destroyed via destroy(). If true, it should not be used.
  19521. *
  19522. * @member {boolean}
  19523. * @private
  19524. * @readonly
  19525. */
  19526. _this._destroyed = false;
  19527. /**
  19528. * The ids under which this BaseTexture has been added to the base texture cache. This is
  19529. * automatically set as long as BaseTexture.addToCache is used, but may not be set if a
  19530. * BaseTexture is added directly to the BaseTextureCache array.
  19531. *
  19532. * @member {string[]}
  19533. */
  19534. _this.textureCacheIds = [];
  19535. // if no source passed don't try to load
  19536. if (source) {
  19537. _this.loadSource(source);
  19538. }
  19539. /**
  19540. * Fired when a not-immediately-available source finishes loading.
  19541. *
  19542. * @protected
  19543. * @event PIXI.BaseTexture#loaded
  19544. * @param {PIXI.BaseTexture} baseTexture - Resource loaded.
  19545. */
  19546. /**
  19547. * Fired when a not-immediately-available source fails to load.
  19548. *
  19549. * @protected
  19550. * @event PIXI.BaseTexture#error
  19551. * @param {PIXI.BaseTexture} baseTexture - Resource errored.
  19552. */
  19553. /**
  19554. * Fired when BaseTexture is updated.
  19555. *
  19556. * @protected
  19557. * @event PIXI.BaseTexture#update
  19558. * @param {PIXI.BaseTexture} baseTexture - Instance of texture being updated.
  19559. */
  19560. /**
  19561. * Fired when BaseTexture is destroyed.
  19562. *
  19563. * @protected
  19564. * @event PIXI.BaseTexture#dispose
  19565. * @param {PIXI.BaseTexture} baseTexture - Instance of texture being destroyed.
  19566. */
  19567. return _this;
  19568. }
  19569. /**
  19570. * Updates the texture on all the webgl renderers, this also assumes the src has changed.
  19571. *
  19572. * @fires PIXI.BaseTexture#update
  19573. */
  19574. BaseTexture.prototype.update = function update() {
  19575. // Svg size is handled during load
  19576. if (this.imageType !== 'svg') {
  19577. this.realWidth = this.source.naturalWidth || this.source.videoWidth || this.source.width;
  19578. this.realHeight = this.source.naturalHeight || this.source.videoHeight || this.source.height;
  19579. this._updateDimensions();
  19580. }
  19581. this.emit('update', this);
  19582. };
  19583. /**
  19584. * Update dimensions from real values
  19585. */
  19586. BaseTexture.prototype._updateDimensions = function _updateDimensions() {
  19587. this.width = this.realWidth / this.resolution;
  19588. this.height = this.realHeight / this.resolution;
  19589. this.isPowerOfTwo = _bitTwiddle2.default.isPow2(this.realWidth) && _bitTwiddle2.default.isPow2(this.realHeight);
  19590. };
  19591. /**
  19592. * Load a source.
  19593. *
  19594. * If the source is not-immediately-available, such as an image that needs to be
  19595. * downloaded, then the 'loaded' or 'error' event will be dispatched in the future
  19596. * and `hasLoaded` will remain false after this call.
  19597. *
  19598. * The logic state after calling `loadSource` directly or indirectly (eg. `fromImage`, `new BaseTexture`) is:
  19599. *
  19600. * if (texture.hasLoaded) {
  19601. * // texture ready for use
  19602. * } else if (texture.isLoading) {
  19603. * // listen to 'loaded' and/or 'error' events on texture
  19604. * } else {
  19605. * // not loading, not going to load UNLESS the source is reloaded
  19606. * // (it may still make sense to listen to the events)
  19607. * }
  19608. *
  19609. * @protected
  19610. * @param {HTMLImageElement|HTMLCanvasElement} source - the source object of the texture.
  19611. */
  19612. BaseTexture.prototype.loadSource = function loadSource(source) {
  19613. var wasLoading = this.isLoading;
  19614. this.hasLoaded = false;
  19615. this.isLoading = false;
  19616. if (wasLoading && this.source) {
  19617. this.source.onload = null;
  19618. this.source.onerror = null;
  19619. }
  19620. var firstSourceLoaded = !this.source;
  19621. this.source = source;
  19622. // Apply source if loaded. Otherwise setup appropriate loading monitors.
  19623. if ((source.src && source.complete || source.getContext) && source.width && source.height) {
  19624. this._updateImageType();
  19625. if (this.imageType === 'svg') {
  19626. this._loadSvgSource();
  19627. } else {
  19628. this._sourceLoaded();
  19629. }
  19630. if (firstSourceLoaded) {
  19631. // send loaded event if previous source was null and we have been passed a pre-loaded IMG element
  19632. this.emit('loaded', this);
  19633. }
  19634. } else if (!source.getContext) {
  19635. // Image fail / not ready
  19636. this.isLoading = true;
  19637. var scope = this;
  19638. source.onload = function () {
  19639. scope._updateImageType();
  19640. source.onload = null;
  19641. source.onerror = null;
  19642. if (!scope.isLoading) {
  19643. return;
  19644. }
  19645. scope.isLoading = false;
  19646. scope._sourceLoaded();
  19647. if (scope.imageType === 'svg') {
  19648. scope._loadSvgSource();
  19649. return;
  19650. }
  19651. scope.emit('loaded', scope);
  19652. };
  19653. source.onerror = function () {
  19654. source.onload = null;
  19655. source.onerror = null;
  19656. if (!scope.isLoading) {
  19657. return;
  19658. }
  19659. scope.isLoading = false;
  19660. scope.emit('error', scope);
  19661. };
  19662. // Per http://www.w3.org/TR/html5/embedded-content-0.html#the-img-element
  19663. // "The value of `complete` can thus change while a script is executing."
  19664. // So complete needs to be re-checked after the callbacks have been added..
  19665. // NOTE: complete will be true if the image has no src so best to check if the src is set.
  19666. if (source.complete && source.src) {
  19667. // ..and if we're complete now, no need for callbacks
  19668. source.onload = null;
  19669. source.onerror = null;
  19670. if (scope.imageType === 'svg') {
  19671. scope._loadSvgSource();
  19672. return;
  19673. }
  19674. this.isLoading = false;
  19675. if (source.width && source.height) {
  19676. this._sourceLoaded();
  19677. // If any previous subscribers possible
  19678. if (wasLoading) {
  19679. this.emit('loaded', this);
  19680. }
  19681. }
  19682. // If any previous subscribers possible
  19683. else if (wasLoading) {
  19684. this.emit('error', this);
  19685. }
  19686. }
  19687. }
  19688. };
  19689. /**
  19690. * Updates type of the source image.
  19691. */
  19692. BaseTexture.prototype._updateImageType = function _updateImageType() {
  19693. if (!this.imageUrl) {
  19694. return;
  19695. }
  19696. var dataUri = (0, _utils.decomposeDataUri)(this.imageUrl);
  19697. var imageType = void 0;
  19698. if (dataUri && dataUri.mediaType === 'image') {
  19699. // Check for subType validity
  19700. var firstSubType = dataUri.subType.split('+')[0];
  19701. imageType = (0, _utils.getUrlFileExtension)('.' + firstSubType);
  19702. if (!imageType) {
  19703. throw new Error('Invalid image type in data URI.');
  19704. }
  19705. } else {
  19706. imageType = (0, _utils.getUrlFileExtension)(this.imageUrl);
  19707. if (!imageType) {
  19708. imageType = 'png';
  19709. }
  19710. }
  19711. this.imageType = imageType;
  19712. };
  19713. /**
  19714. * Checks if `source` is an SVG image and whether it's loaded via a URL or a data URI. Then calls
  19715. * `_loadSvgSourceUsingDataUri` or `_loadSvgSourceUsingXhr`.
  19716. */
  19717. BaseTexture.prototype._loadSvgSource = function _loadSvgSource() {
  19718. if (this.imageType !== 'svg') {
  19719. // Do nothing if source is not svg
  19720. return;
  19721. }
  19722. var dataUri = (0, _utils.decomposeDataUri)(this.imageUrl);
  19723. if (dataUri) {
  19724. this._loadSvgSourceUsingDataUri(dataUri);
  19725. } else {
  19726. // We got an URL, so we need to do an XHR to check the svg size
  19727. this._loadSvgSourceUsingXhr();
  19728. }
  19729. };
  19730. /**
  19731. * Reads an SVG string from data URI and then calls `_loadSvgSourceUsingString`.
  19732. *
  19733. * @param {string} dataUri - The data uri to load from.
  19734. */
  19735. BaseTexture.prototype._loadSvgSourceUsingDataUri = function _loadSvgSourceUsingDataUri(dataUri) {
  19736. var svgString = void 0;
  19737. if (dataUri.encoding === 'base64') {
  19738. if (!atob) {
  19739. throw new Error('Your browser doesn\'t support base64 conversions.');
  19740. }
  19741. svgString = atob(dataUri.data);
  19742. } else {
  19743. svgString = dataUri.data;
  19744. }
  19745. this._loadSvgSourceUsingString(svgString);
  19746. };
  19747. /**
  19748. * Loads an SVG string from `imageUrl` using XHR and then calls `_loadSvgSourceUsingString`.
  19749. */
  19750. BaseTexture.prototype._loadSvgSourceUsingXhr = function _loadSvgSourceUsingXhr() {
  19751. var _this2 = this;
  19752. var svgXhr = new XMLHttpRequest();
  19753. // This throws error on IE, so SVG Document can't be used
  19754. // svgXhr.responseType = 'document';
  19755. // This is not needed since we load the svg as string (breaks IE too)
  19756. // but overrideMimeType() can be used to force the response to be parsed as XML
  19757. // svgXhr.overrideMimeType('image/svg+xml');
  19758. svgXhr.onload = function () {
  19759. if (svgXhr.readyState !== svgXhr.DONE || svgXhr.status !== 200) {
  19760. throw new Error('Failed to load SVG using XHR.');
  19761. }
  19762. _this2._loadSvgSourceUsingString(svgXhr.response);
  19763. };
  19764. svgXhr.onerror = function () {
  19765. return _this2.emit('error', _this2);
  19766. };
  19767. svgXhr.open('GET', this.imageUrl, true);
  19768. svgXhr.send();
  19769. };
  19770. /**
  19771. * Loads texture using an SVG string. The original SVG Image is stored as `origSource` and the
  19772. * created canvas is the new `source`. The SVG is scaled using `sourceScale`. Called by
  19773. * `_loadSvgSourceUsingXhr` or `_loadSvgSourceUsingDataUri`.
  19774. *
  19775. * @param {string} svgString SVG source as string
  19776. *
  19777. * @fires PIXI.BaseTexture#loaded
  19778. */
  19779. BaseTexture.prototype._loadSvgSourceUsingString = function _loadSvgSourceUsingString(svgString) {
  19780. var svgSize = (0, _utils.getSvgSize)(svgString);
  19781. var svgWidth = svgSize.width;
  19782. var svgHeight = svgSize.height;
  19783. if (!svgWidth || !svgHeight) {
  19784. throw new Error('The SVG image must have width and height defined (in pixels), canvas API needs them.');
  19785. }
  19786. // Scale realWidth and realHeight
  19787. this.realWidth = Math.round(svgWidth * this.sourceScale);
  19788. this.realHeight = Math.round(svgHeight * this.sourceScale);
  19789. this._updateDimensions();
  19790. // Create a canvas element
  19791. var canvas = document.createElement('canvas');
  19792. canvas.width = this.realWidth;
  19793. canvas.height = this.realHeight;
  19794. canvas._pixiId = 'canvas_' + (0, _utils.uid)();
  19795. // Draw the Svg to the canvas
  19796. canvas.getContext('2d').drawImage(this.source, 0, 0, svgWidth, svgHeight, 0, 0, this.realWidth, this.realHeight);
  19797. // Replace the original source image with the canvas
  19798. this.origSource = this.source;
  19799. this.source = canvas;
  19800. // Add also the canvas in cache (destroy clears by `imageUrl` and `source._pixiId`)
  19801. BaseTexture.addToCache(this, canvas._pixiId);
  19802. this.isLoading = false;
  19803. this._sourceLoaded();
  19804. this.emit('loaded', this);
  19805. };
  19806. /**
  19807. * Used internally to update the width, height, and some other tracking vars once
  19808. * a source has successfully loaded.
  19809. *
  19810. * @private
  19811. */
  19812. BaseTexture.prototype._sourceLoaded = function _sourceLoaded() {
  19813. this.hasLoaded = true;
  19814. this.update();
  19815. };
  19816. /**
  19817. * Destroys this base texture
  19818. *
  19819. */
  19820. BaseTexture.prototype.destroy = function destroy() {
  19821. if (this.imageUrl) {
  19822. delete _utils.TextureCache[this.imageUrl];
  19823. this.imageUrl = null;
  19824. if (!navigator.isCocoonJS) {
  19825. this.source.src = '';
  19826. }
  19827. }
  19828. this.source = null;
  19829. this.dispose();
  19830. BaseTexture.removeFromCache(this);
  19831. this.textureCacheIds = null;
  19832. this._destroyed = true;
  19833. };
  19834. /**
  19835. * Frees the texture from WebGL memory without destroying this texture object.
  19836. * This means you can still use the texture later which will upload it to GPU
  19837. * memory again.
  19838. *
  19839. * @fires PIXI.BaseTexture#dispose
  19840. */
  19841. BaseTexture.prototype.dispose = function dispose() {
  19842. this.emit('dispose', this);
  19843. };
  19844. /**
  19845. * Changes the source image of the texture.
  19846. * The original source must be an Image element.
  19847. *
  19848. * @param {string} newSrc - the path of the image
  19849. */
  19850. BaseTexture.prototype.updateSourceImage = function updateSourceImage(newSrc) {
  19851. this.source.src = newSrc;
  19852. this.loadSource(this.source);
  19853. };
  19854. /**
  19855. * Helper function that creates a base texture from the given image url.
  19856. * If the image is not in the base texture cache it will be created and loaded.
  19857. *
  19858. * @static
  19859. * @param {string} imageUrl - The image url of the texture
  19860. * @param {boolean} [crossorigin=(auto)] - Should use anonymous CORS? Defaults to true if the URL is not a data-URI.
  19861. * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values
  19862. * @param {number} [sourceScale=(auto)] - Scale for the original image, used with Svg images.
  19863. * @return {PIXI.BaseTexture} The new base texture.
  19864. */
  19865. BaseTexture.fromImage = function fromImage(imageUrl, crossorigin, scaleMode, sourceScale) {
  19866. var baseTexture = _utils.BaseTextureCache[imageUrl];
  19867. if (!baseTexture) {
  19868. // new Image() breaks tex loading in some versions of Chrome.
  19869. // See https://code.google.com/p/chromium/issues/detail?id=238071
  19870. var image = new Image(); // document.createElement('img');
  19871. if (crossorigin === undefined && imageUrl.indexOf('data:') !== 0) {
  19872. image.crossOrigin = (0, _determineCrossOrigin2.default)(imageUrl);
  19873. } else if (crossorigin) {
  19874. image.crossOrigin = typeof crossorigin === 'string' ? crossorigin : 'anonymous';
  19875. }
  19876. baseTexture = new BaseTexture(image, scaleMode);
  19877. baseTexture.imageUrl = imageUrl;
  19878. if (sourceScale) {
  19879. baseTexture.sourceScale = sourceScale;
  19880. }
  19881. // if there is an @2x at the end of the url we are going to assume its a highres image
  19882. baseTexture.resolution = (0, _utils.getResolutionOfUrl)(imageUrl);
  19883. image.src = imageUrl; // Setting this triggers load
  19884. BaseTexture.addToCache(baseTexture, imageUrl);
  19885. }
  19886. return baseTexture;
  19887. };
  19888. /**
  19889. * Helper function that creates a base texture from the given canvas element.
  19890. *
  19891. * @static
  19892. * @param {HTMLCanvasElement} canvas - The canvas element source of the texture
  19893. * @param {number} scaleMode - See {@link PIXI.SCALE_MODES} for possible values
  19894. * @param {string} [origin='canvas'] - A string origin of who created the base texture
  19895. * @return {PIXI.BaseTexture} The new base texture.
  19896. */
  19897. BaseTexture.fromCanvas = function fromCanvas(canvas, scaleMode) {
  19898. var origin = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'canvas';
  19899. if (!canvas._pixiId) {
  19900. canvas._pixiId = origin + '_' + (0, _utils.uid)();
  19901. }
  19902. var baseTexture = _utils.BaseTextureCache[canvas._pixiId];
  19903. if (!baseTexture) {
  19904. baseTexture = new BaseTexture(canvas, scaleMode);
  19905. BaseTexture.addToCache(baseTexture, canvas._pixiId);
  19906. }
  19907. return baseTexture;
  19908. };
  19909. /**
  19910. * Helper function that creates a base texture based on the source you provide.
  19911. * The source can be - image url, image element, canvas element. If the
  19912. * source is an image url or an image element and not in the base texture
  19913. * cache, it will be created and loaded.
  19914. *
  19915. * @static
  19916. * @param {string|HTMLImageElement|HTMLCanvasElement} source - The source to create base texture from.
  19917. * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values
  19918. * @param {number} [sourceScale=(auto)] - Scale for the original image, used with Svg images.
  19919. * @return {PIXI.BaseTexture} The new base texture.
  19920. */
  19921. BaseTexture.from = function from(source, scaleMode, sourceScale) {
  19922. if (typeof source === 'string') {
  19923. return BaseTexture.fromImage(source, undefined, scaleMode, sourceScale);
  19924. } else if (source instanceof HTMLImageElement) {
  19925. var imageUrl = source.src;
  19926. var baseTexture = _utils.BaseTextureCache[imageUrl];
  19927. if (!baseTexture) {
  19928. baseTexture = new BaseTexture(source, scaleMode);
  19929. baseTexture.imageUrl = imageUrl;
  19930. if (sourceScale) {
  19931. baseTexture.sourceScale = sourceScale;
  19932. }
  19933. // if there is an @2x at the end of the url we are going to assume its a highres image
  19934. baseTexture.resolution = (0, _utils.getResolutionOfUrl)(imageUrl);
  19935. BaseTexture.addToCache(baseTexture, imageUrl);
  19936. }
  19937. return baseTexture;
  19938. } else if (source instanceof HTMLCanvasElement) {
  19939. return BaseTexture.fromCanvas(source, scaleMode);
  19940. }
  19941. // lets assume its a base texture!
  19942. return source;
  19943. };
  19944. /**
  19945. * Adds a BaseTexture to the global BaseTextureCache. This cache is shared across the whole PIXI object.
  19946. *
  19947. * @static
  19948. * @param {PIXI.BaseTexture} baseTexture - The BaseTexture to add to the cache.
  19949. * @param {string} id - The id that the BaseTexture will be stored against.
  19950. */
  19951. BaseTexture.addToCache = function addToCache(baseTexture, id) {
  19952. if (id) {
  19953. if (baseTexture.textureCacheIds.indexOf(id) === -1) {
  19954. baseTexture.textureCacheIds.push(id);
  19955. }
  19956. /* eslint-disable no-console */
  19957. if (_utils.BaseTextureCache[id]) {
  19958. console.warn('BaseTexture added to the cache with an id [' + id + '] that already had an entry');
  19959. }
  19960. /* eslint-enable no-console */
  19961. _utils.BaseTextureCache[id] = baseTexture;
  19962. }
  19963. };
  19964. /**
  19965. * Remove a BaseTexture from the global BaseTextureCache.
  19966. *
  19967. * @static
  19968. * @param {string|PIXI.BaseTexture} baseTexture - id of a BaseTexture to be removed, or a BaseTexture instance itself.
  19969. * @return {PIXI.BaseTexture|null} The BaseTexture that was removed.
  19970. */
  19971. BaseTexture.removeFromCache = function removeFromCache(baseTexture) {
  19972. if (typeof baseTexture === 'string') {
  19973. var baseTextureFromCache = _utils.BaseTextureCache[baseTexture];
  19974. if (baseTextureFromCache) {
  19975. var index = baseTextureFromCache.textureCacheIds.indexOf(baseTexture);
  19976. if (index > -1) {
  19977. baseTextureFromCache.textureCacheIds.splice(index, 1);
  19978. }
  19979. delete _utils.BaseTextureCache[baseTexture];
  19980. return baseTextureFromCache;
  19981. }
  19982. } else if (baseTexture && baseTexture.textureCacheIds) {
  19983. for (var i = 0; i < baseTexture.textureCacheIds.length; ++i) {
  19984. delete _utils.BaseTextureCache[baseTexture.textureCacheIds[i]];
  19985. }
  19986. baseTexture.textureCacheIds.length = 0;
  19987. return baseTexture;
  19988. }
  19989. return null;
  19990. };
  19991. return BaseTexture;
  19992. }(_eventemitter2.default);
  19993. exports.default = BaseTexture;
  19994. }, { "../settings": 101, "../utils": 125, "../utils/determineCrossOrigin": 124, "bit-twiddle": 1, "eventemitter3": 3 }], 113: [function (require, module, exports) {
  19995. 'use strict';
  19996. exports.__esModule = true;
  19997. var _BaseRenderTexture = require('./BaseRenderTexture');
  19998. var _BaseRenderTexture2 = _interopRequireDefault(_BaseRenderTexture);
  19999. var _Texture2 = require('./Texture');
  20000. var _Texture3 = _interopRequireDefault(_Texture2);
  20001. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  20002. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  20003. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  20004. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  20005. /**
  20006. * A RenderTexture is a special texture that allows any PixiJS display object to be rendered to it.
  20007. *
  20008. * __Hint__: All DisplayObjects (i.e. Sprites) that render to a RenderTexture should be preloaded
  20009. * otherwise black rectangles will be drawn instead.
  20010. *
  20011. * A RenderTexture takes a snapshot of any Display Object given to its render method. For example:
  20012. *
  20013. * ```js
  20014. * let renderer = PIXI.autoDetectRenderer(1024, 1024, { view: canvas, ratio: 1 });
  20015. * let renderTexture = PIXI.RenderTexture.create(800, 600);
  20016. * let sprite = PIXI.Sprite.fromImage("spinObj_01.png");
  20017. *
  20018. * sprite.position.x = 800/2;
  20019. * sprite.position.y = 600/2;
  20020. * sprite.anchor.x = 0.5;
  20021. * sprite.anchor.y = 0.5;
  20022. *
  20023. * renderer.render(sprite, renderTexture);
  20024. * ```
  20025. *
  20026. * The Sprite in this case will be rendered using its local transform. To render this sprite at 0,0
  20027. * you can clear the transform
  20028. *
  20029. * ```js
  20030. *
  20031. * sprite.setTransform()
  20032. *
  20033. * let renderTexture = new PIXI.RenderTexture.create(100, 100);
  20034. *
  20035. * renderer.render(sprite, renderTexture); // Renders to center of RenderTexture
  20036. * ```
  20037. *
  20038. * @class
  20039. * @extends PIXI.Texture
  20040. * @memberof PIXI
  20041. */
  20042. var RenderTexture = function (_Texture) {
  20043. _inherits(RenderTexture, _Texture);
  20044. /**
  20045. * @param {PIXI.BaseRenderTexture} baseRenderTexture - The renderer used for this RenderTexture
  20046. * @param {PIXI.Rectangle} [frame] - The rectangle frame of the texture to show
  20047. */
  20048. function RenderTexture(baseRenderTexture, frame) {
  20049. _classCallCheck(this, RenderTexture);
  20050. // support for legacy..
  20051. var _legacyRenderer = null;
  20052. if (!(baseRenderTexture instanceof _BaseRenderTexture2.default)) {
  20053. /* eslint-disable prefer-rest-params, no-console */
  20054. var width = arguments[1];
  20055. var height = arguments[2];
  20056. var scaleMode = arguments[3];
  20057. var resolution = arguments[4];
  20058. // we have an old render texture..
  20059. console.warn('Please use RenderTexture.create(' + width + ', ' + height + ') instead of the ctor directly.');
  20060. _legacyRenderer = arguments[0];
  20061. /* eslint-enable prefer-rest-params, no-console */
  20062. frame = null;
  20063. baseRenderTexture = new _BaseRenderTexture2.default(width, height, scaleMode, resolution);
  20064. }
  20065. /**
  20066. * The base texture object that this texture uses
  20067. *
  20068. * @member {BaseTexture}
  20069. */
  20070. var _this = _possibleConstructorReturn(this, _Texture.call(this, baseRenderTexture, frame));
  20071. _this.legacyRenderer = _legacyRenderer;
  20072. /**
  20073. * This will let the renderer know if the texture is valid. If it's not then it cannot be rendered.
  20074. *
  20075. * @member {boolean}
  20076. */
  20077. _this.valid = true;
  20078. _this._updateUvs();
  20079. return _this;
  20080. }
  20081. /**
  20082. * Resizes the RenderTexture.
  20083. *
  20084. * @param {number} width - The width to resize to.
  20085. * @param {number} height - The height to resize to.
  20086. * @param {boolean} doNotResizeBaseTexture - Should the baseTexture.width and height values be resized as well?
  20087. */
  20088. RenderTexture.prototype.resize = function resize(width, height, doNotResizeBaseTexture) {
  20089. width = Math.ceil(width);
  20090. height = Math.ceil(height);
  20091. // TODO - could be not required..
  20092. this.valid = width > 0 && height > 0;
  20093. this._frame.width = this.orig.width = width;
  20094. this._frame.height = this.orig.height = height;
  20095. if (!doNotResizeBaseTexture) {
  20096. this.baseTexture.resize(width, height);
  20097. }
  20098. this._updateUvs();
  20099. };
  20100. /**
  20101. * A short hand way of creating a render texture.
  20102. *
  20103. * @param {number} [width=100] - The width of the render texture
  20104. * @param {number} [height=100] - The height of the render texture
  20105. * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values
  20106. * @param {number} [resolution=1] - The resolution / device pixel ratio of the texture being generated
  20107. * @return {PIXI.RenderTexture} The new render texture
  20108. */
  20109. RenderTexture.create = function create(width, height, scaleMode, resolution) {
  20110. return new RenderTexture(new _BaseRenderTexture2.default(width, height, scaleMode, resolution));
  20111. };
  20112. return RenderTexture;
  20113. }(_Texture3.default);
  20114. exports.default = RenderTexture;
  20115. }, { "./BaseRenderTexture": 111, "./Texture": 115 }], 114: [function (require, module, exports) {
  20116. 'use strict';
  20117. exports.__esModule = true;
  20118. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  20119. var _ = require('../');
  20120. var _utils = require('../utils');
  20121. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  20122. /**
  20123. * Utility class for maintaining reference to a collection
  20124. * of Textures on a single Spritesheet.
  20125. *
  20126. * @class
  20127. * @memberof PIXI
  20128. */
  20129. var Spritesheet = function () {
  20130. _createClass(Spritesheet, null, [{
  20131. key: 'BATCH_SIZE',
  20132. /**
  20133. * The maximum number of Textures to build per process.
  20134. *
  20135. * @type {number}
  20136. * @default 1000
  20137. */
  20138. get: function get() {
  20139. return 1000;
  20140. }
  20141. /**
  20142. * @param {PIXI.BaseTexture} baseTexture Reference to the source BaseTexture object.
  20143. * @param {Object} data - Spritesheet image data.
  20144. * @param {string} [resolutionFilename] - The filename to consider when determining
  20145. * the resolution of the spritesheet. If not provided, the imageUrl will
  20146. * be used on the BaseTexture.
  20147. */
  20148. }]);
  20149. function Spritesheet(baseTexture, data) {
  20150. var resolutionFilename = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
  20151. _classCallCheck(this, Spritesheet);
  20152. /**
  20153. * Reference to ths source texture
  20154. * @type {PIXI.BaseTexture}
  20155. */
  20156. this.baseTexture = baseTexture;
  20157. /**
  20158. * Map of spritesheet textures.
  20159. * @type {Object}
  20160. */
  20161. this.textures = {};
  20162. /**
  20163. * Reference to the original JSON data.
  20164. * @type {Object}
  20165. */
  20166. this.data = data;
  20167. /**
  20168. * The resolution of the spritesheet.
  20169. * @type {number}
  20170. */
  20171. this.resolution = this._updateResolution(resolutionFilename || this.baseTexture.imageUrl);
  20172. /**
  20173. * Map of spritesheet frames.
  20174. * @type {Object}
  20175. * @private
  20176. */
  20177. this._frames = this.data.frames;
  20178. /**
  20179. * Collection of frame names.
  20180. * @type {string[]}
  20181. * @private
  20182. */
  20183. this._frameKeys = Object.keys(this._frames);
  20184. /**
  20185. * Current batch index being processed.
  20186. * @type {number}
  20187. * @private
  20188. */
  20189. this._batchIndex = 0;
  20190. /**
  20191. * Callback when parse is completed.
  20192. * @type {Function}
  20193. * @private
  20194. */
  20195. this._callback = null;
  20196. }
  20197. /**
  20198. * Generate the resolution from the filename or fallback
  20199. * to the meta.scale field of the JSON data.
  20200. *
  20201. * @private
  20202. * @param {string} resolutionFilename - The filename to use for resolving
  20203. * the default resolution.
  20204. * @return {number} Resolution to use for spritesheet.
  20205. */
  20206. Spritesheet.prototype._updateResolution = function _updateResolution(resolutionFilename) {
  20207. var scale = this.data.meta.scale;
  20208. // Use a defaultValue of `null` to check if a url-based resolution is set
  20209. var resolution = (0, _utils.getResolutionOfUrl)(resolutionFilename, null);
  20210. // No resolution found via URL
  20211. if (resolution === null) {
  20212. // Use the scale value or default to 1
  20213. resolution = scale !== undefined ? parseFloat(scale) : 1;
  20214. }
  20215. // For non-1 resolutions, update baseTexture
  20216. if (resolution !== 1) {
  20217. this.baseTexture.resolution = resolution;
  20218. this.baseTexture.update();
  20219. }
  20220. return resolution;
  20221. };
  20222. /**
  20223. * Parser spritesheet from loaded data. This is done asynchronously
  20224. * to prevent creating too many Texture within a single process.
  20225. *
  20226. * @param {Function} callback - Callback when complete returns
  20227. * a map of the Textures for this spritesheet.
  20228. */
  20229. Spritesheet.prototype.parse = function parse(callback) {
  20230. this._batchIndex = 0;
  20231. this._callback = callback;
  20232. if (this._frameKeys.length <= Spritesheet.BATCH_SIZE) {
  20233. this._processFrames(0);
  20234. this._parseComplete();
  20235. } else {
  20236. this._nextBatch();
  20237. }
  20238. };
  20239. /**
  20240. * Process a batch of frames
  20241. *
  20242. * @private
  20243. * @param {number} initialFrameIndex - The index of frame to start.
  20244. */
  20245. Spritesheet.prototype._processFrames = function _processFrames(initialFrameIndex) {
  20246. var frameIndex = initialFrameIndex;
  20247. var maxFrames = Spritesheet.BATCH_SIZE;
  20248. var sourceScale = this.baseTexture.sourceScale;
  20249. while (frameIndex - initialFrameIndex < maxFrames && frameIndex < this._frameKeys.length) {
  20250. var i = this._frameKeys[frameIndex];
  20251. var data = this._frames[i];
  20252. var rect = data.frame;
  20253. if (rect) {
  20254. var frame = null;
  20255. var trim = null;
  20256. var sourceSize = data.trimmed !== false && data.sourceSize ? data.sourceSize : data.frame;
  20257. var orig = new _.Rectangle(0, 0, Math.floor(sourceSize.w * sourceScale) / this.resolution, Math.floor(sourceSize.h * sourceScale) / this.resolution);
  20258. if (data.rotated) {
  20259. frame = new _.Rectangle(Math.floor(rect.x * sourceScale) / this.resolution, Math.floor(rect.y * sourceScale) / this.resolution, Math.floor(rect.h * sourceScale) / this.resolution, Math.floor(rect.w * sourceScale) / this.resolution);
  20260. } else {
  20261. frame = new _.Rectangle(Math.floor(rect.x * sourceScale) / this.resolution, Math.floor(rect.y * sourceScale) / this.resolution, Math.floor(rect.w * sourceScale) / this.resolution, Math.floor(rect.h * sourceScale) / this.resolution);
  20262. }
  20263. // Check to see if the sprite is trimmed
  20264. if (data.trimmed !== false && data.spriteSourceSize) {
  20265. trim = new _.Rectangle(Math.floor(data.spriteSourceSize.x * sourceScale) / this.resolution, Math.floor(data.spriteSourceSize.y * sourceScale) / this.resolution, Math.floor(rect.w * sourceScale) / this.resolution, Math.floor(rect.h * sourceScale) / this.resolution);
  20266. }
  20267. this.textures[i] = new _.Texture(this.baseTexture, frame, orig, trim, data.rotated ? 2 : 0);
  20268. // lets also add the frame to pixi's global cache for fromFrame and fromImage functions
  20269. _.Texture.addToCache(this.textures[i], i);
  20270. }
  20271. frameIndex++;
  20272. }
  20273. };
  20274. /**
  20275. * The parse has completed.
  20276. *
  20277. * @private
  20278. */
  20279. Spritesheet.prototype._parseComplete = function _parseComplete() {
  20280. var callback = this._callback;
  20281. this._callback = null;
  20282. this._batchIndex = 0;
  20283. callback.call(this, this.textures);
  20284. };
  20285. /**
  20286. * Begin the next batch of textures.
  20287. *
  20288. * @private
  20289. */
  20290. Spritesheet.prototype._nextBatch = function _nextBatch() {
  20291. var _this = this;
  20292. this._processFrames(this._batchIndex * Spritesheet.BATCH_SIZE);
  20293. this._batchIndex++;
  20294. setTimeout(function () {
  20295. if (_this._batchIndex * Spritesheet.BATCH_SIZE < _this._frameKeys.length) {
  20296. _this._nextBatch();
  20297. } else {
  20298. _this._parseComplete();
  20299. }
  20300. }, 0);
  20301. };
  20302. /**
  20303. * Destroy Spritesheet and don't use after this.
  20304. *
  20305. * @param {boolean} [destroyBase=false] Whether to destroy the base texture as well
  20306. */
  20307. Spritesheet.prototype.destroy = function destroy() {
  20308. var destroyBase = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  20309. for (var i in this.textures) {
  20310. this.textures[i].destroy();
  20311. }
  20312. this._frames = null;
  20313. this._frameKeys = null;
  20314. this.data = null;
  20315. this.textures = null;
  20316. if (destroyBase) {
  20317. this.baseTexture.destroy();
  20318. }
  20319. this.baseTexture = null;
  20320. };
  20321. return Spritesheet;
  20322. }();
  20323. exports.default = Spritesheet;
  20324. }, { "../": 65, "../utils": 125 }], 115: [function (require, module, exports) {
  20325. 'use strict';
  20326. exports.__esModule = true;
  20327. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  20328. var _BaseTexture = require('./BaseTexture');
  20329. var _BaseTexture2 = _interopRequireDefault(_BaseTexture);
  20330. var _VideoBaseTexture = require('./VideoBaseTexture');
  20331. var _VideoBaseTexture2 = _interopRequireDefault(_VideoBaseTexture);
  20332. var _TextureUvs = require('./TextureUvs');
  20333. var _TextureUvs2 = _interopRequireDefault(_TextureUvs);
  20334. var _eventemitter = require('eventemitter3');
  20335. var _eventemitter2 = _interopRequireDefault(_eventemitter);
  20336. var _math = require('../math');
  20337. var _utils = require('../utils');
  20338. var _settings = require('../settings');
  20339. var _settings2 = _interopRequireDefault(_settings);
  20340. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  20341. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  20342. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  20343. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  20344. /**
  20345. * A texture stores the information that represents an image or part of an image. It cannot be added
  20346. * to the display list directly. Instead use it as the texture for a Sprite. If no frame is provided
  20347. * then the whole image is used.
  20348. *
  20349. * You can directly create a texture from an image and then reuse it multiple times like this :
  20350. *
  20351. * ```js
  20352. * let texture = PIXI.Texture.fromImage('assets/image.png');
  20353. * let sprite1 = new PIXI.Sprite(texture);
  20354. * let sprite2 = new PIXI.Sprite(texture);
  20355. * ```
  20356. *
  20357. * Textures made from SVGs, loaded or not, cannot be used before the file finishes processing.
  20358. * You can check for this by checking the sprite's _textureID property.
  20359. * ```js
  20360. * var texture = PIXI.Texture.fromImage('assets/image.svg');
  20361. * var sprite1 = new PIXI.Sprite(texture);
  20362. * //sprite1._textureID should not be undefined if the texture has finished processing the SVG file
  20363. * ```
  20364. * You can use a ticker or rAF to ensure your sprites load the finished textures after processing. See issue #3068.
  20365. *
  20366. * @class
  20367. * @extends EventEmitter
  20368. * @memberof PIXI
  20369. */
  20370. var Texture = function (_EventEmitter) {
  20371. _inherits(Texture, _EventEmitter);
  20372. /**
  20373. * @param {PIXI.BaseTexture} baseTexture - The base texture source to create the texture from
  20374. * @param {PIXI.Rectangle} [frame] - The rectangle frame of the texture to show
  20375. * @param {PIXI.Rectangle} [orig] - The area of original texture
  20376. * @param {PIXI.Rectangle} [trim] - Trimmed rectangle of original texture
  20377. * @param {number} [rotate] - indicates how the texture was rotated by texture packer. See {@link PIXI.GroupD8}
  20378. */
  20379. function Texture(baseTexture, frame, orig, trim, rotate) {
  20380. _classCallCheck(this, Texture);
  20381. /**
  20382. * Does this Texture have any frame data assigned to it?
  20383. *
  20384. * @member {boolean}
  20385. */
  20386. var _this = _possibleConstructorReturn(this, _EventEmitter.call(this));
  20387. _this.noFrame = false;
  20388. if (!frame) {
  20389. _this.noFrame = true;
  20390. frame = new _math.Rectangle(0, 0, 1, 1);
  20391. }
  20392. if (baseTexture instanceof Texture) {
  20393. baseTexture = baseTexture.baseTexture;
  20394. }
  20395. /**
  20396. * The base texture that this texture uses.
  20397. *
  20398. * @member {PIXI.BaseTexture}
  20399. */
  20400. _this.baseTexture = baseTexture;
  20401. /**
  20402. * This is the area of the BaseTexture image to actually copy to the Canvas / WebGL when rendering,
  20403. * irrespective of the actual frame size or placement (which can be influenced by trimmed texture atlases)
  20404. *
  20405. * @member {PIXI.Rectangle}
  20406. */
  20407. _this._frame = frame;
  20408. /**
  20409. * This is the trimmed area of original texture, before it was put in atlas
  20410. * Please call `_updateUvs()` after you change coordinates of `trim` manually.
  20411. *
  20412. * @member {PIXI.Rectangle}
  20413. */
  20414. _this.trim = trim;
  20415. /**
  20416. * This will let the renderer know if the texture is valid. If it's not then it cannot be rendered.
  20417. *
  20418. * @member {boolean}
  20419. */
  20420. _this.valid = false;
  20421. /**
  20422. * This will let a renderer know that a texture has been updated (used mainly for webGL uv updates)
  20423. *
  20424. * @member {boolean}
  20425. */
  20426. _this.requiresUpdate = false;
  20427. /**
  20428. * The WebGL UV data cache.
  20429. *
  20430. * @member {PIXI.TextureUvs}
  20431. * @private
  20432. */
  20433. _this._uvs = null;
  20434. /**
  20435. * This is the area of original texture, before it was put in atlas
  20436. *
  20437. * @member {PIXI.Rectangle}
  20438. */
  20439. _this.orig = orig || frame; // new Rectangle(0, 0, 1, 1);
  20440. _this._rotate = Number(rotate || 0);
  20441. if (rotate === true) {
  20442. // this is old texturepacker legacy, some games/libraries are passing "true" for rotated textures
  20443. _this._rotate = 2;
  20444. } else if (_this._rotate % 2 !== 0) {
  20445. throw new Error('attempt to use diamond-shaped UVs. If you are sure, set rotation manually');
  20446. }
  20447. if (baseTexture.hasLoaded) {
  20448. if (_this.noFrame) {
  20449. frame = new _math.Rectangle(0, 0, baseTexture.width, baseTexture.height);
  20450. // if there is no frame we should monitor for any base texture changes..
  20451. baseTexture.on('update', _this.onBaseTextureUpdated, _this);
  20452. }
  20453. _this.frame = frame;
  20454. } else {
  20455. baseTexture.once('loaded', _this.onBaseTextureLoaded, _this);
  20456. }
  20457. /**
  20458. * Fired when the texture is updated. This happens if the frame or the baseTexture is updated.
  20459. *
  20460. * @event PIXI.Texture#update
  20461. * @protected
  20462. * @param {PIXI.Texture} texture - Instance of texture being updated.
  20463. */
  20464. _this._updateID = 0;
  20465. /**
  20466. * Contains data for uvs. May contain clamp settings and some matrices.
  20467. * Its a bit heavy, so by default that object is not created.
  20468. * @type {PIXI.TextureMatrix}
  20469. * @default null
  20470. */
  20471. _this.transform = null;
  20472. /**
  20473. * The ids under which this Texture has been added to the texture cache. This is
  20474. * automatically set as long as Texture.addToCache is used, but may not be set if a
  20475. * Texture is added directly to the TextureCache array.
  20476. *
  20477. * @member {string[]}
  20478. */
  20479. _this.textureCacheIds = [];
  20480. return _this;
  20481. }
  20482. /**
  20483. * Updates this texture on the gpu.
  20484. *
  20485. */
  20486. Texture.prototype.update = function update() {
  20487. this.baseTexture.update();
  20488. };
  20489. /**
  20490. * Called when the base texture is loaded
  20491. *
  20492. * @private
  20493. * @param {PIXI.BaseTexture} baseTexture - The base texture.
  20494. */
  20495. Texture.prototype.onBaseTextureLoaded = function onBaseTextureLoaded(baseTexture) {
  20496. this._updateID++;
  20497. // TODO this code looks confusing.. boo to abusing getters and setters!
  20498. if (this.noFrame) {
  20499. this.frame = new _math.Rectangle(0, 0, baseTexture.width, baseTexture.height);
  20500. } else {
  20501. this.frame = this._frame;
  20502. }
  20503. this.baseTexture.on('update', this.onBaseTextureUpdated, this);
  20504. this.emit('update', this);
  20505. };
  20506. /**
  20507. * Called when the base texture is updated
  20508. *
  20509. * @private
  20510. * @param {PIXI.BaseTexture} baseTexture - The base texture.
  20511. */
  20512. Texture.prototype.onBaseTextureUpdated = function onBaseTextureUpdated(baseTexture) {
  20513. this._updateID++;
  20514. this._frame.width = baseTexture.width;
  20515. this._frame.height = baseTexture.height;
  20516. this.emit('update', this);
  20517. };
  20518. /**
  20519. * Destroys this texture
  20520. *
  20521. * @param {boolean} [destroyBase=false] Whether to destroy the base texture as well
  20522. */
  20523. Texture.prototype.destroy = function destroy(destroyBase) {
  20524. if (this.baseTexture) {
  20525. if (destroyBase) {
  20526. // delete the texture if it exists in the texture cache..
  20527. // this only needs to be removed if the base texture is actually destroyed too..
  20528. if (_utils.TextureCache[this.baseTexture.imageUrl]) {
  20529. Texture.removeFromCache(this.baseTexture.imageUrl);
  20530. }
  20531. this.baseTexture.destroy();
  20532. }
  20533. this.baseTexture.off('update', this.onBaseTextureUpdated, this);
  20534. this.baseTexture.off('loaded', this.onBaseTextureLoaded, this);
  20535. this.baseTexture = null;
  20536. }
  20537. this._frame = null;
  20538. this._uvs = null;
  20539. this.trim = null;
  20540. this.orig = null;
  20541. this.valid = false;
  20542. Texture.removeFromCache(this);
  20543. this.textureCacheIds = null;
  20544. };
  20545. /**
  20546. * Creates a new texture object that acts the same as this one.
  20547. *
  20548. * @return {PIXI.Texture} The new texture
  20549. */
  20550. Texture.prototype.clone = function clone() {
  20551. return new Texture(this.baseTexture, this.frame, this.orig, this.trim, this.rotate);
  20552. };
  20553. /**
  20554. * Updates the internal WebGL UV cache. Use it after you change `frame` or `trim` of the texture.
  20555. */
  20556. Texture.prototype._updateUvs = function _updateUvs() {
  20557. if (!this._uvs) {
  20558. this._uvs = new _TextureUvs2.default();
  20559. }
  20560. this._uvs.set(this._frame, this.baseTexture, this.rotate);
  20561. this._updateID++;
  20562. };
  20563. /**
  20564. * Helper function that creates a Texture object from the given image url.
  20565. * If the image is not in the texture cache it will be created and loaded.
  20566. *
  20567. * @static
  20568. * @param {string} imageUrl - The image url of the texture
  20569. * @param {boolean} [crossorigin] - Whether requests should be treated as crossorigin
  20570. * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values
  20571. * @param {number} [sourceScale=(auto)] - Scale for the original image, used with SVG images.
  20572. * @return {PIXI.Texture} The newly created texture
  20573. */
  20574. Texture.fromImage = function fromImage(imageUrl, crossorigin, scaleMode, sourceScale) {
  20575. var texture = _utils.TextureCache[imageUrl];
  20576. if (!texture) {
  20577. texture = new Texture(_BaseTexture2.default.fromImage(imageUrl, crossorigin, scaleMode, sourceScale));
  20578. Texture.addToCache(texture, imageUrl);
  20579. }
  20580. return texture;
  20581. };
  20582. /**
  20583. * Helper function that creates a sprite that will contain a texture from the TextureCache based on the frameId
  20584. * The frame ids are created when a Texture packer file has been loaded
  20585. *
  20586. * @static
  20587. * @param {string} frameId - The frame Id of the texture in the cache
  20588. * @return {PIXI.Texture} The newly created texture
  20589. */
  20590. Texture.fromFrame = function fromFrame(frameId) {
  20591. var texture = _utils.TextureCache[frameId];
  20592. if (!texture) {
  20593. throw new Error('The frameId "' + frameId + '" does not exist in the texture cache');
  20594. }
  20595. return texture;
  20596. };
  20597. /**
  20598. * Helper function that creates a new Texture based on the given canvas element.
  20599. *
  20600. * @static
  20601. * @param {HTMLCanvasElement} canvas - The canvas element source of the texture
  20602. * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values
  20603. * @param {string} [origin='canvas'] - A string origin of who created the base texture
  20604. * @return {PIXI.Texture} The newly created texture
  20605. */
  20606. Texture.fromCanvas = function fromCanvas(canvas, scaleMode) {
  20607. var origin = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'canvas';
  20608. return new Texture(_BaseTexture2.default.fromCanvas(canvas, scaleMode, origin));
  20609. };
  20610. /**
  20611. * Helper function that creates a new Texture based on the given video element.
  20612. *
  20613. * @static
  20614. * @param {HTMLVideoElement|string} video - The URL or actual element of the video
  20615. * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values
  20616. * @return {PIXI.Texture} The newly created texture
  20617. */
  20618. Texture.fromVideo = function fromVideo(video, scaleMode) {
  20619. if (typeof video === 'string') {
  20620. return Texture.fromVideoUrl(video, scaleMode);
  20621. }
  20622. return new Texture(_VideoBaseTexture2.default.fromVideo(video, scaleMode));
  20623. };
  20624. /**
  20625. * Helper function that creates a new Texture based on the video url.
  20626. *
  20627. * @static
  20628. * @param {string} videoUrl - URL of the video
  20629. * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values
  20630. * @return {PIXI.Texture} The newly created texture
  20631. */
  20632. Texture.fromVideoUrl = function fromVideoUrl(videoUrl, scaleMode) {
  20633. return new Texture(_VideoBaseTexture2.default.fromUrl(videoUrl, scaleMode));
  20634. };
  20635. /**
  20636. * Helper function that creates a new Texture based on the source you provide.
  20637. * The source can be - frame id, image url, video url, canvas element, video element, base texture
  20638. *
  20639. * @static
  20640. * @param {number|string|HTMLImageElement|HTMLCanvasElement|HTMLVideoElement|PIXI.BaseTexture}
  20641. * source - Source to create texture from
  20642. * @return {PIXI.Texture} The newly created texture
  20643. */
  20644. Texture.from = function from(source) {
  20645. // TODO auto detect cross origin..
  20646. // TODO pass in scale mode?
  20647. if (typeof source === 'string') {
  20648. var texture = _utils.TextureCache[source];
  20649. if (!texture) {
  20650. // check if its a video..
  20651. var isVideo = source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/) !== null;
  20652. if (isVideo) {
  20653. return Texture.fromVideoUrl(source);
  20654. }
  20655. return Texture.fromImage(source);
  20656. }
  20657. return texture;
  20658. } else if (source instanceof HTMLImageElement) {
  20659. return new Texture(_BaseTexture2.default.from(source));
  20660. } else if (source instanceof HTMLCanvasElement) {
  20661. return Texture.fromCanvas(source, _settings2.default.SCALE_MODE, 'HTMLCanvasElement');
  20662. } else if (source instanceof HTMLVideoElement) {
  20663. return Texture.fromVideo(source);
  20664. } else if (source instanceof _BaseTexture2.default) {
  20665. return new Texture(source);
  20666. }
  20667. // lets assume its a texture!
  20668. return source;
  20669. };
  20670. /**
  20671. * Create a texture from a source and add to the cache.
  20672. *
  20673. * @static
  20674. * @param {HTMLImageElement|HTMLCanvasElement} source - The input source.
  20675. * @param {String} imageUrl - File name of texture, for cache and resolving resolution.
  20676. * @param {String} [name] - Human readible name for the texture cache. If no name is
  20677. * specified, only `imageUrl` will be used as the cache ID.
  20678. * @return {PIXI.Texture} Output texture
  20679. */
  20680. Texture.fromLoader = function fromLoader(source, imageUrl, name) {
  20681. var baseTexture = new _BaseTexture2.default(source, undefined, (0, _utils.getResolutionOfUrl)(imageUrl));
  20682. var texture = new Texture(baseTexture);
  20683. baseTexture.imageUrl = imageUrl;
  20684. // No name, use imageUrl instead
  20685. if (!name) {
  20686. name = imageUrl;
  20687. }
  20688. // lets also add the frame to pixi's global cache for fromFrame and fromImage fucntions
  20689. _BaseTexture2.default.addToCache(texture.baseTexture, name);
  20690. Texture.addToCache(texture, name);
  20691. // also add references by url if they are different.
  20692. if (name !== imageUrl) {
  20693. _BaseTexture2.default.addToCache(texture.baseTexture, imageUrl);
  20694. Texture.addToCache(texture, imageUrl);
  20695. }
  20696. return texture;
  20697. };
  20698. /**
  20699. * Adds a Texture to the global TextureCache. This cache is shared across the whole PIXI object.
  20700. *
  20701. * @static
  20702. * @param {PIXI.Texture} texture - The Texture to add to the cache.
  20703. * @param {string} id - The id that the Texture will be stored against.
  20704. */
  20705. Texture.addToCache = function addToCache(texture, id) {
  20706. if (id) {
  20707. if (texture.textureCacheIds.indexOf(id) === -1) {
  20708. texture.textureCacheIds.push(id);
  20709. }
  20710. /* eslint-disable no-console */
  20711. if (_utils.TextureCache[id]) {
  20712. console.warn('Texture added to the cache with an id [' + id + '] that already had an entry');
  20713. }
  20714. /* eslint-enable no-console */
  20715. _utils.TextureCache[id] = texture;
  20716. }
  20717. };
  20718. /**
  20719. * Remove a Texture from the global TextureCache.
  20720. *
  20721. * @static
  20722. * @param {string|PIXI.Texture} texture - id of a Texture to be removed, or a Texture instance itself
  20723. * @return {PIXI.Texture|null} The Texture that was removed
  20724. */
  20725. Texture.removeFromCache = function removeFromCache(texture) {
  20726. if (typeof texture === 'string') {
  20727. var textureFromCache = _utils.TextureCache[texture];
  20728. if (textureFromCache) {
  20729. var index = textureFromCache.textureCacheIds.indexOf(texture);
  20730. if (index > -1) {
  20731. textureFromCache.textureCacheIds.splice(index, 1);
  20732. }
  20733. delete _utils.TextureCache[texture];
  20734. return textureFromCache;
  20735. }
  20736. } else if (texture && texture.textureCacheIds) {
  20737. for (var i = 0; i < texture.textureCacheIds.length; ++i) {
  20738. // Check that texture matches the one being passed in before deleting it from the cache.
  20739. if (_utils.TextureCache[texture.textureCacheIds[i]] === texture) {
  20740. delete _utils.TextureCache[texture.textureCacheIds[i]];
  20741. }
  20742. }
  20743. texture.textureCacheIds.length = 0;
  20744. return texture;
  20745. }
  20746. return null;
  20747. };
  20748. /**
  20749. * The frame specifies the region of the base texture that this texture uses.
  20750. * Please call `_updateUvs()` after you change coordinates of `frame` manually.
  20751. *
  20752. * @member {PIXI.Rectangle}
  20753. */
  20754. _createClass(Texture, [{
  20755. key: 'frame',
  20756. get: function get() {
  20757. return this._frame;
  20758. },
  20759. set: function set(frame) // eslint-disable-line require-jsdoc
  20760. {
  20761. this._frame = frame;
  20762. this.noFrame = false;
  20763. var x = frame.x,
  20764. y = frame.y,
  20765. width = frame.width,
  20766. height = frame.height;
  20767. var xNotFit = x + width > this.baseTexture.width;
  20768. var yNotFit = y + height > this.baseTexture.height;
  20769. if (xNotFit || yNotFit) {
  20770. var relationship = xNotFit && yNotFit ? 'and' : 'or';
  20771. var errorX = 'X: ' + x + ' + ' + width + ' = ' + (x + width) + ' > ' + this.baseTexture.width;
  20772. var errorY = 'Y: ' + y + ' + ' + height + ' = ' + (y + height) + ' > ' + this.baseTexture.height;
  20773. throw new Error('Texture Error: frame does not fit inside the base Texture dimensions: ' + (errorX + ' ' + relationship + ' ' + errorY));
  20774. }
  20775. // this.valid = width && height && this.baseTexture.source && this.baseTexture.hasLoaded;
  20776. this.valid = width && height && this.baseTexture.hasLoaded;
  20777. if (!this.trim && !this.rotate) {
  20778. this.orig = frame;
  20779. }
  20780. if (this.valid) {
  20781. this._updateUvs();
  20782. }
  20783. }
  20784. /**
  20785. * Indicates whether the texture is rotated inside the atlas
  20786. * set to 2 to compensate for texture packer rotation
  20787. * set to 6 to compensate for spine packer rotation
  20788. * can be used to rotate or mirror sprites
  20789. * See {@link PIXI.GroupD8} for explanation
  20790. *
  20791. * @member {number}
  20792. */
  20793. }, {
  20794. key: 'rotate',
  20795. get: function get() {
  20796. return this._rotate;
  20797. },
  20798. set: function set(rotate) // eslint-disable-line require-jsdoc
  20799. {
  20800. this._rotate = rotate;
  20801. if (this.valid) {
  20802. this._updateUvs();
  20803. }
  20804. }
  20805. /**
  20806. * The width of the Texture in pixels.
  20807. *
  20808. * @member {number}
  20809. */
  20810. }, {
  20811. key: 'width',
  20812. get: function get() {
  20813. return this.orig.width;
  20814. }
  20815. /**
  20816. * The height of the Texture in pixels.
  20817. *
  20818. * @member {number}
  20819. */
  20820. }, {
  20821. key: 'height',
  20822. get: function get() {
  20823. return this.orig.height;
  20824. }
  20825. }]);
  20826. return Texture;
  20827. }(_eventemitter2.default);
  20828. exports.default = Texture;
  20829. function createWhiteTexture() {
  20830. var canvas = document.createElement('canvas');
  20831. canvas.width = 10;
  20832. canvas.height = 10;
  20833. var context = canvas.getContext('2d');
  20834. context.fillStyle = 'white';
  20835. context.fillRect(0, 0, 10, 10);
  20836. return new Texture(new _BaseTexture2.default(canvas));
  20837. }
  20838. function removeAllHandlers(tex) {
  20839. tex.destroy = function _emptyDestroy() {/* empty */ };
  20840. tex.on = function _emptyOn() {/* empty */ };
  20841. tex.once = function _emptyOnce() {/* empty */ };
  20842. tex.emit = function _emptyEmit() {/* empty */ };
  20843. }
  20844. /**
  20845. * An empty texture, used often to not have to create multiple empty textures.
  20846. * Can not be destroyed.
  20847. *
  20848. * @static
  20849. * @constant
  20850. */
  20851. Texture.EMPTY = new Texture(new _BaseTexture2.default());
  20852. removeAllHandlers(Texture.EMPTY);
  20853. removeAllHandlers(Texture.EMPTY.baseTexture);
  20854. /**
  20855. * A white texture of 10x10 size, used for graphics and other things
  20856. * Can not be destroyed.
  20857. *
  20858. * @static
  20859. * @constant
  20860. */
  20861. Texture.WHITE = createWhiteTexture();
  20862. removeAllHandlers(Texture.WHITE);
  20863. removeAllHandlers(Texture.WHITE.baseTexture);
  20864. }, { "../math": 70, "../settings": 101, "../utils": 125, "./BaseTexture": 112, "./TextureUvs": 117, "./VideoBaseTexture": 118, "eventemitter3": 3 }], 116: [function (require, module, exports) {
  20865. 'use strict';
  20866. exports.__esModule = true;
  20867. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  20868. var _Matrix = require('../math/Matrix');
  20869. var _Matrix2 = _interopRequireDefault(_Matrix);
  20870. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  20871. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  20872. var tempMat = new _Matrix2.default();
  20873. /**
  20874. * Class controls uv transform and frame clamp for texture
  20875. * Can be used in Texture "transform" field, or separately, you can use different clamp settings on the same texture.
  20876. * If you want to add support for texture region of certain feature or filter, that's what you're looking for.
  20877. *
  20878. * @see PIXI.Texture
  20879. * @see PIXI.mesh.Mesh
  20880. * @see PIXI.extras.TilingSprite
  20881. * @class
  20882. * @memberof PIXI
  20883. */
  20884. var TextureMatrix = function () {
  20885. /**
  20886. *
  20887. * @param {PIXI.Texture} texture observed texture
  20888. * @param {number} [clampMargin] Changes frame clamping, 0.5 by default. Use -0.5 for extra border.
  20889. * @constructor
  20890. */
  20891. function TextureMatrix(texture, clampMargin) {
  20892. _classCallCheck(this, TextureMatrix);
  20893. this._texture = texture;
  20894. this.mapCoord = new _Matrix2.default();
  20895. this.uClampFrame = new Float32Array(4);
  20896. this.uClampOffset = new Float32Array(2);
  20897. this._lastTextureID = -1;
  20898. /**
  20899. * Changes frame clamping
  20900. * Works with TilingSprite and Mesh
  20901. * Change to 1.5 if you texture has repeated right and bottom lines, that leads to smoother borders
  20902. *
  20903. * @default 0
  20904. * @member {number}
  20905. */
  20906. this.clampOffset = 0;
  20907. /**
  20908. * Changes frame clamping
  20909. * Works with TilingSprite and Mesh
  20910. * Change to -0.5 to add a pixel to the edge, recommended for transparent trimmed textures in atlas
  20911. *
  20912. * @default 0.5
  20913. * @member {number}
  20914. */
  20915. this.clampMargin = typeof clampMargin === 'undefined' ? 0.5 : clampMargin;
  20916. }
  20917. /**
  20918. * texture property
  20919. * @member {PIXI.Texture}
  20920. */
  20921. /**
  20922. * Multiplies uvs array to transform
  20923. * @param {Float32Array} uvs mesh uvs
  20924. * @param {Float32Array} [out=uvs] output
  20925. * @returns {Float32Array} output
  20926. */
  20927. TextureMatrix.prototype.multiplyUvs = function multiplyUvs(uvs, out) {
  20928. if (out === undefined) {
  20929. out = uvs;
  20930. }
  20931. var mat = this.mapCoord;
  20932. for (var i = 0; i < uvs.length; i += 2) {
  20933. var x = uvs[i];
  20934. var y = uvs[i + 1];
  20935. out[i] = x * mat.a + y * mat.c + mat.tx;
  20936. out[i + 1] = x * mat.b + y * mat.d + mat.ty;
  20937. }
  20938. return out;
  20939. };
  20940. /**
  20941. * updates matrices if texture was changed
  20942. * @param {boolean} forceUpdate if true, matrices will be updated any case
  20943. * @returns {boolean} whether or not it was updated
  20944. */
  20945. TextureMatrix.prototype.update = function update(forceUpdate) {
  20946. var tex = this._texture;
  20947. if (!tex || !tex.valid) {
  20948. return false;
  20949. }
  20950. if (!forceUpdate && this._lastTextureID === tex._updateID) {
  20951. return false;
  20952. }
  20953. this._lastTextureID = tex._updateID;
  20954. var uvs = tex._uvs;
  20955. this.mapCoord.set(uvs.x1 - uvs.x0, uvs.y1 - uvs.y0, uvs.x3 - uvs.x0, uvs.y3 - uvs.y0, uvs.x0, uvs.y0);
  20956. var orig = tex.orig;
  20957. var trim = tex.trim;
  20958. if (trim) {
  20959. tempMat.set(orig.width / trim.width, 0, 0, orig.height / trim.height, -trim.x / trim.width, -trim.y / trim.height);
  20960. this.mapCoord.append(tempMat);
  20961. }
  20962. var texBase = tex.baseTexture;
  20963. var frame = this.uClampFrame;
  20964. var margin = this.clampMargin / texBase.resolution;
  20965. var offset = this.clampOffset;
  20966. frame[0] = (tex._frame.x + margin + offset) / texBase.width;
  20967. frame[1] = (tex._frame.y + margin + offset) / texBase.height;
  20968. frame[2] = (tex._frame.x + tex._frame.width - margin + offset) / texBase.width;
  20969. frame[3] = (tex._frame.y + tex._frame.height - margin + offset) / texBase.height;
  20970. this.uClampOffset[0] = offset / texBase.realWidth;
  20971. this.uClampOffset[1] = offset / texBase.realHeight;
  20972. return true;
  20973. };
  20974. _createClass(TextureMatrix, [{
  20975. key: 'texture',
  20976. get: function get() {
  20977. return this._texture;
  20978. },
  20979. set: function set(value) // eslint-disable-line require-jsdoc
  20980. {
  20981. this._texture = value;
  20982. this._lastTextureID = -1;
  20983. }
  20984. }]);
  20985. return TextureMatrix;
  20986. }();
  20987. exports.default = TextureMatrix;
  20988. }, { "../math/Matrix": 67 }], 117: [function (require, module, exports) {
  20989. 'use strict';
  20990. exports.__esModule = true;
  20991. var _GroupD = require('../math/GroupD8');
  20992. var _GroupD2 = _interopRequireDefault(_GroupD);
  20993. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  20994. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  20995. /**
  20996. * A standard object to store the Uvs of a texture
  20997. *
  20998. * @class
  20999. * @private
  21000. * @memberof PIXI
  21001. */
  21002. var TextureUvs = function () {
  21003. /**
  21004. *
  21005. */
  21006. function TextureUvs() {
  21007. _classCallCheck(this, TextureUvs);
  21008. this.x0 = 0;
  21009. this.y0 = 0;
  21010. this.x1 = 1;
  21011. this.y1 = 0;
  21012. this.x2 = 1;
  21013. this.y2 = 1;
  21014. this.x3 = 0;
  21015. this.y3 = 1;
  21016. this.uvsUint32 = new Uint32Array(4);
  21017. }
  21018. /**
  21019. * Sets the texture Uvs based on the given frame information.
  21020. *
  21021. * @private
  21022. * @param {PIXI.Rectangle} frame - The frame of the texture
  21023. * @param {PIXI.Rectangle} baseFrame - The base frame of the texture
  21024. * @param {number} rotate - Rotation of frame, see {@link PIXI.GroupD8}
  21025. */
  21026. TextureUvs.prototype.set = function set(frame, baseFrame, rotate) {
  21027. var tw = baseFrame.width;
  21028. var th = baseFrame.height;
  21029. if (rotate) {
  21030. // width and height div 2 div baseFrame size
  21031. var w2 = frame.width / 2 / tw;
  21032. var h2 = frame.height / 2 / th;
  21033. // coordinates of center
  21034. var cX = frame.x / tw + w2;
  21035. var cY = frame.y / th + h2;
  21036. rotate = _GroupD2.default.add(rotate, _GroupD2.default.NW); // NW is top-left corner
  21037. this.x0 = cX + w2 * _GroupD2.default.uX(rotate);
  21038. this.y0 = cY + h2 * _GroupD2.default.uY(rotate);
  21039. rotate = _GroupD2.default.add(rotate, 2); // rotate 90 degrees clockwise
  21040. this.x1 = cX + w2 * _GroupD2.default.uX(rotate);
  21041. this.y1 = cY + h2 * _GroupD2.default.uY(rotate);
  21042. rotate = _GroupD2.default.add(rotate, 2);
  21043. this.x2 = cX + w2 * _GroupD2.default.uX(rotate);
  21044. this.y2 = cY + h2 * _GroupD2.default.uY(rotate);
  21045. rotate = _GroupD2.default.add(rotate, 2);
  21046. this.x3 = cX + w2 * _GroupD2.default.uX(rotate);
  21047. this.y3 = cY + h2 * _GroupD2.default.uY(rotate);
  21048. } else {
  21049. this.x0 = frame.x / tw;
  21050. this.y0 = frame.y / th;
  21051. this.x1 = (frame.x + frame.width) / tw;
  21052. this.y1 = frame.y / th;
  21053. this.x2 = (frame.x + frame.width) / tw;
  21054. this.y2 = (frame.y + frame.height) / th;
  21055. this.x3 = frame.x / tw;
  21056. this.y3 = (frame.y + frame.height) / th;
  21057. }
  21058. this.uvsUint32[0] = (this.y0 * 65535 & 0xFFFF) << 16 | this.x0 * 65535 & 0xFFFF;
  21059. this.uvsUint32[1] = (this.y1 * 65535 & 0xFFFF) << 16 | this.x1 * 65535 & 0xFFFF;
  21060. this.uvsUint32[2] = (this.y2 * 65535 & 0xFFFF) << 16 | this.x2 * 65535 & 0xFFFF;
  21061. this.uvsUint32[3] = (this.y3 * 65535 & 0xFFFF) << 16 | this.x3 * 65535 & 0xFFFF;
  21062. };
  21063. return TextureUvs;
  21064. }();
  21065. exports.default = TextureUvs;
  21066. }, { "../math/GroupD8": 66 }], 118: [function (require, module, exports) {
  21067. 'use strict';
  21068. exports.__esModule = true;
  21069. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  21070. var _BaseTexture2 = require('./BaseTexture');
  21071. var _BaseTexture3 = _interopRequireDefault(_BaseTexture2);
  21072. var _utils = require('../utils');
  21073. var _ticker = require('../ticker');
  21074. var _const = require('../const');
  21075. var _determineCrossOrigin = require('../utils/determineCrossOrigin');
  21076. var _determineCrossOrigin2 = _interopRequireDefault(_determineCrossOrigin);
  21077. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  21078. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  21079. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  21080. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  21081. /**
  21082. * A texture of a [playing] Video.
  21083. *
  21084. * Video base textures mimic PixiJS BaseTexture.from.... method in their creation process.
  21085. *
  21086. * This can be used in several ways, such as:
  21087. *
  21088. * ```js
  21089. * let texture = PIXI.VideoBaseTexture.fromUrl('http://mydomain.com/video.mp4');
  21090. *
  21091. * let texture = PIXI.VideoBaseTexture.fromUrl({ src: 'http://mydomain.com/video.mp4', mime: 'video/mp4' });
  21092. *
  21093. * let texture = PIXI.VideoBaseTexture.fromUrls(['/video.webm', '/video.mp4']);
  21094. *
  21095. * let texture = PIXI.VideoBaseTexture.fromUrls([
  21096. * { src: '/video.webm', mime: 'video/webm' },
  21097. * { src: '/video.mp4', mime: 'video/mp4' }
  21098. * ]);
  21099. * ```
  21100. *
  21101. * See the ["deus" demo](http://www.goodboydigital.com/pixijs/examples/deus/).
  21102. *
  21103. * @class
  21104. * @extends PIXI.BaseTexture
  21105. * @memberof PIXI
  21106. */
  21107. var VideoBaseTexture = function (_BaseTexture) {
  21108. _inherits(VideoBaseTexture, _BaseTexture);
  21109. /**
  21110. * @param {HTMLVideoElement} source - Video source
  21111. * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values
  21112. */
  21113. function VideoBaseTexture(source, scaleMode) {
  21114. _classCallCheck(this, VideoBaseTexture);
  21115. if (!source) {
  21116. throw new Error('No video source element specified.');
  21117. }
  21118. // hook in here to check if video is already available.
  21119. // BaseTexture looks for a source.complete boolean, plus width & height.
  21120. if ((source.readyState === source.HAVE_ENOUGH_DATA || source.readyState === source.HAVE_FUTURE_DATA) && source.width && source.height) {
  21121. source.complete = true;
  21122. }
  21123. var _this = _possibleConstructorReturn(this, _BaseTexture.call(this, source, scaleMode));
  21124. _this.width = source.videoWidth;
  21125. _this.height = source.videoHeight;
  21126. _this._autoUpdate = true;
  21127. _this._isAutoUpdating = false;
  21128. /**
  21129. * When set to true will automatically play videos used by this texture once
  21130. * they are loaded. If false, it will not modify the playing state.
  21131. *
  21132. * @member {boolean}
  21133. * @default true
  21134. */
  21135. _this.autoPlay = true;
  21136. _this.update = _this.update.bind(_this);
  21137. _this._onCanPlay = _this._onCanPlay.bind(_this);
  21138. source.addEventListener('play', _this._onPlayStart.bind(_this));
  21139. source.addEventListener('pause', _this._onPlayStop.bind(_this));
  21140. _this.hasLoaded = false;
  21141. _this.__loaded = false;
  21142. if (!_this._isSourceReady()) {
  21143. source.addEventListener('canplay', _this._onCanPlay);
  21144. source.addEventListener('canplaythrough', _this._onCanPlay);
  21145. } else {
  21146. _this._onCanPlay();
  21147. }
  21148. return _this;
  21149. }
  21150. /**
  21151. * Returns true if the underlying source is playing.
  21152. *
  21153. * @private
  21154. * @return {boolean} True if playing.
  21155. */
  21156. VideoBaseTexture.prototype._isSourcePlaying = function _isSourcePlaying() {
  21157. var source = this.source;
  21158. return source.currentTime > 0 && source.paused === false && source.ended === false && source.readyState > 2;
  21159. };
  21160. /**
  21161. * Returns true if the underlying source is ready for playing.
  21162. *
  21163. * @private
  21164. * @return {boolean} True if ready.
  21165. */
  21166. VideoBaseTexture.prototype._isSourceReady = function _isSourceReady() {
  21167. return this.source.readyState === 3 || this.source.readyState === 4;
  21168. };
  21169. /**
  21170. * Runs the update loop when the video is ready to play
  21171. *
  21172. * @private
  21173. */
  21174. VideoBaseTexture.prototype._onPlayStart = function _onPlayStart() {
  21175. // Just in case the video has not received its can play even yet..
  21176. if (!this.hasLoaded) {
  21177. this._onCanPlay();
  21178. }
  21179. if (!this._isAutoUpdating && this.autoUpdate) {
  21180. _ticker.shared.add(this.update, this, _const.UPDATE_PRIORITY.HIGH);
  21181. this._isAutoUpdating = true;
  21182. }
  21183. };
  21184. /**
  21185. * Fired when a pause event is triggered, stops the update loop
  21186. *
  21187. * @private
  21188. */
  21189. VideoBaseTexture.prototype._onPlayStop = function _onPlayStop() {
  21190. if (this._isAutoUpdating) {
  21191. _ticker.shared.remove(this.update, this);
  21192. this._isAutoUpdating = false;
  21193. }
  21194. };
  21195. /**
  21196. * Fired when the video is loaded and ready to play
  21197. *
  21198. * @private
  21199. */
  21200. VideoBaseTexture.prototype._onCanPlay = function _onCanPlay() {
  21201. this.hasLoaded = true;
  21202. if (this.source) {
  21203. this.source.removeEventListener('canplay', this._onCanPlay);
  21204. this.source.removeEventListener('canplaythrough', this._onCanPlay);
  21205. this.width = this.source.videoWidth;
  21206. this.height = this.source.videoHeight;
  21207. // prevent multiple loaded dispatches..
  21208. if (!this.__loaded) {
  21209. this.__loaded = true;
  21210. this.emit('loaded', this);
  21211. }
  21212. if (this._isSourcePlaying()) {
  21213. this._onPlayStart();
  21214. } else if (this.autoPlay) {
  21215. this.source.play();
  21216. }
  21217. }
  21218. };
  21219. /**
  21220. * Destroys this texture
  21221. *
  21222. */
  21223. VideoBaseTexture.prototype.destroy = function destroy() {
  21224. if (this._isAutoUpdating) {
  21225. _ticker.shared.remove(this.update, this);
  21226. }
  21227. if (this.source && this.source._pixiId) {
  21228. _BaseTexture3.default.removeFromCache(this.source._pixiId);
  21229. delete this.source._pixiId;
  21230. this.source.pause();
  21231. this.source.src = '';
  21232. this.source.load();
  21233. }
  21234. _BaseTexture.prototype.destroy.call(this);
  21235. };
  21236. /**
  21237. * Mimic PixiJS BaseTexture.from.... method.
  21238. *
  21239. * @static
  21240. * @param {HTMLVideoElement} video - Video to create texture from
  21241. * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values
  21242. * @return {PIXI.VideoBaseTexture} Newly created VideoBaseTexture
  21243. */
  21244. VideoBaseTexture.fromVideo = function fromVideo(video, scaleMode) {
  21245. if (!video._pixiId) {
  21246. video._pixiId = 'video_' + (0, _utils.uid)();
  21247. }
  21248. var baseTexture = _utils.BaseTextureCache[video._pixiId];
  21249. if (!baseTexture) {
  21250. baseTexture = new VideoBaseTexture(video, scaleMode);
  21251. _BaseTexture3.default.addToCache(baseTexture, video._pixiId);
  21252. }
  21253. return baseTexture;
  21254. };
  21255. /**
  21256. * Helper function that creates a new BaseTexture based on the given video element.
  21257. * This BaseTexture can then be used to create a texture
  21258. *
  21259. * @static
  21260. * @param {string|object|string[]|object[]} videoSrc - The URL(s) for the video.
  21261. * @param {string} [videoSrc.src] - One of the source urls for the video
  21262. * @param {string} [videoSrc.mime] - The mimetype of the video (e.g. 'video/mp4'). If not specified
  21263. * the url's extension will be used as the second part of the mime type.
  21264. * @param {number} scaleMode - See {@link PIXI.SCALE_MODES} for possible values
  21265. * @param {boolean} [crossorigin=(auto)] - Should use anonymous CORS? Defaults to true if the URL is not a data-URI.
  21266. * @return {PIXI.VideoBaseTexture} Newly created VideoBaseTexture
  21267. */
  21268. VideoBaseTexture.fromUrl = function fromUrl(videoSrc, scaleMode, crossorigin) {
  21269. var video = document.createElement('video');
  21270. video.setAttribute('webkit-playsinline', '');
  21271. video.setAttribute('playsinline', '');
  21272. var url = Array.isArray(videoSrc) ? videoSrc[0].src || videoSrc[0] : videoSrc.src || videoSrc;
  21273. if (crossorigin === undefined && url.indexOf('data:') !== 0) {
  21274. video.crossOrigin = (0, _determineCrossOrigin2.default)(url);
  21275. } else if (crossorigin) {
  21276. video.crossOrigin = typeof crossorigin === 'string' ? crossorigin : 'anonymous';
  21277. }
  21278. // array of objects or strings
  21279. if (Array.isArray(videoSrc)) {
  21280. for (var i = 0; i < videoSrc.length; ++i) {
  21281. video.appendChild(createSource(videoSrc[i].src || videoSrc[i], videoSrc[i].mime));
  21282. }
  21283. }
  21284. // single object or string
  21285. else {
  21286. video.appendChild(createSource(url, videoSrc.mime));
  21287. }
  21288. video.load();
  21289. return VideoBaseTexture.fromVideo(video, scaleMode);
  21290. };
  21291. /**
  21292. * Should the base texture automatically update itself, set to true by default
  21293. *
  21294. * @member {boolean}
  21295. */
  21296. _createClass(VideoBaseTexture, [{
  21297. key: 'autoUpdate',
  21298. get: function get() {
  21299. return this._autoUpdate;
  21300. },
  21301. set: function set(value) // eslint-disable-line require-jsdoc
  21302. {
  21303. if (value !== this._autoUpdate) {
  21304. this._autoUpdate = value;
  21305. if (!this._autoUpdate && this._isAutoUpdating) {
  21306. _ticker.shared.remove(this.update, this);
  21307. this._isAutoUpdating = false;
  21308. } else if (this._autoUpdate && !this._isAutoUpdating) {
  21309. _ticker.shared.add(this.update, this, _const.UPDATE_PRIORITY.HIGH);
  21310. this._isAutoUpdating = true;
  21311. }
  21312. }
  21313. }
  21314. }]);
  21315. return VideoBaseTexture;
  21316. }(_BaseTexture3.default);
  21317. exports.default = VideoBaseTexture;
  21318. VideoBaseTexture.fromUrls = VideoBaseTexture.fromUrl;
  21319. function createSource(path, type) {
  21320. if (!type) {
  21321. type = 'video/' + path.substr(path.lastIndexOf('.') + 1);
  21322. }
  21323. var source = document.createElement('source');
  21324. source.src = path;
  21325. source.type = type;
  21326. return source;
  21327. }
  21328. }, { "../const": 46, "../ticker": 121, "../utils": 125, "../utils/determineCrossOrigin": 124, "./BaseTexture": 112 }], 119: [function (require, module, exports) {
  21329. 'use strict';
  21330. exports.__esModule = true;
  21331. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  21332. var _settings = require('../settings');
  21333. var _settings2 = _interopRequireDefault(_settings);
  21334. var _const = require('../const');
  21335. var _TickerListener = require('./TickerListener');
  21336. var _TickerListener2 = _interopRequireDefault(_TickerListener);
  21337. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  21338. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  21339. /**
  21340. * A Ticker class that runs an update loop that other objects listen to.
  21341. * This class is composed around listeners
  21342. * meant for execution on the next requested animation frame.
  21343. * Animation frames are requested only when necessary,
  21344. * e.g. When the ticker is started and the emitter has listeners.
  21345. *
  21346. * @class
  21347. * @memberof PIXI.ticker
  21348. */
  21349. var Ticker = function () {
  21350. /**
  21351. *
  21352. */
  21353. function Ticker() {
  21354. var _this = this;
  21355. _classCallCheck(this, Ticker);
  21356. /**
  21357. * The first listener. All new listeners added are chained on this.
  21358. * @private
  21359. * @type {TickerListener}
  21360. */
  21361. this._head = new _TickerListener2.default(null, null, Infinity);
  21362. /**
  21363. * Internal current frame request ID
  21364. * @private
  21365. */
  21366. this._requestId = null;
  21367. /**
  21368. * Internal value managed by minFPS property setter and getter.
  21369. * This is the maximum allowed milliseconds between updates.
  21370. * @private
  21371. */
  21372. this._maxElapsedMS = 100;
  21373. /**
  21374. * Whether or not this ticker should invoke the method
  21375. * {@link PIXI.ticker.Ticker#start} automatically
  21376. * when a listener is added.
  21377. *
  21378. * @member {boolean}
  21379. * @default false
  21380. */
  21381. this.autoStart = false;
  21382. /**
  21383. * Scalar time value from last frame to this frame.
  21384. * This value is capped by setting {@link PIXI.ticker.Ticker#minFPS}
  21385. * and is scaled with {@link PIXI.ticker.Ticker#speed}.
  21386. * **Note:** The cap may be exceeded by scaling.
  21387. *
  21388. * @member {number}
  21389. * @default 1
  21390. */
  21391. this.deltaTime = 1;
  21392. /**
  21393. * Time elapsed in milliseconds from last frame to this frame.
  21394. * Opposed to what the scalar {@link PIXI.ticker.Ticker#deltaTime}
  21395. * is based, this value is neither capped nor scaled.
  21396. * If the platform supports DOMHighResTimeStamp,
  21397. * this value will have a precision of 1 µs.
  21398. * Defaults to target frame time
  21399. *
  21400. * @member {number}
  21401. * @default 16.66
  21402. */
  21403. this.elapsedMS = 1 / _settings2.default.TARGET_FPMS;
  21404. /**
  21405. * The last time {@link PIXI.ticker.Ticker#update} was invoked.
  21406. * This value is also reset internally outside of invoking
  21407. * update, but only when a new animation frame is requested.
  21408. * If the platform supports DOMHighResTimeStamp,
  21409. * this value will have a precision of 1 µs.
  21410. *
  21411. * @member {number}
  21412. * @default -1
  21413. */
  21414. this.lastTime = -1;
  21415. /**
  21416. * Factor of current {@link PIXI.ticker.Ticker#deltaTime}.
  21417. * @example
  21418. * // Scales ticker.deltaTime to what would be
  21419. * // the equivalent of approximately 120 FPS
  21420. * ticker.speed = 2;
  21421. *
  21422. * @member {number}
  21423. * @default 1
  21424. */
  21425. this.speed = 1;
  21426. /**
  21427. * Whether or not this ticker has been started.
  21428. * `true` if {@link PIXI.ticker.Ticker#start} has been called.
  21429. * `false` if {@link PIXI.ticker.Ticker#stop} has been called.
  21430. * While `false`, this value may change to `true` in the
  21431. * event of {@link PIXI.ticker.Ticker#autoStart} being `true`
  21432. * and a listener is added.
  21433. *
  21434. * @member {boolean}
  21435. * @default false
  21436. */
  21437. this.started = false;
  21438. /**
  21439. * Internal tick method bound to ticker instance.
  21440. * This is because in early 2015, Function.bind
  21441. * is still 60% slower in high performance scenarios.
  21442. * Also separating frame requests from update method
  21443. * so listeners may be called at any time and with
  21444. * any animation API, just invoke ticker.update(time).
  21445. *
  21446. * @private
  21447. * @param {number} time - Time since last tick.
  21448. */
  21449. this._tick = function (time) {
  21450. _this._requestId = null;
  21451. if (_this.started) {
  21452. // Invoke listeners now
  21453. _this.update(time);
  21454. // Listener side effects may have modified ticker state.
  21455. if (_this.started && _this._requestId === null && _this._head.next) {
  21456. _this._requestId = requestAnimationFrame(_this._tick);
  21457. }
  21458. }
  21459. };
  21460. }
  21461. /**
  21462. * Conditionally requests a new animation frame.
  21463. * If a frame has not already been requested, and if the internal
  21464. * emitter has listeners, a new frame is requested.
  21465. *
  21466. * @private
  21467. */
  21468. Ticker.prototype._requestIfNeeded = function _requestIfNeeded() {
  21469. if (this._requestId === null && this._head.next) {
  21470. // ensure callbacks get correct delta
  21471. this.lastTime = performance.now();
  21472. this._requestId = requestAnimationFrame(this._tick);
  21473. }
  21474. };
  21475. /**
  21476. * Conditionally cancels a pending animation frame.
  21477. *
  21478. * @private
  21479. */
  21480. Ticker.prototype._cancelIfNeeded = function _cancelIfNeeded() {
  21481. if (this._requestId !== null) {
  21482. cancelAnimationFrame(this._requestId);
  21483. this._requestId = null;
  21484. }
  21485. };
  21486. /**
  21487. * Conditionally requests a new animation frame.
  21488. * If the ticker has been started it checks if a frame has not already
  21489. * been requested, and if the internal emitter has listeners. If these
  21490. * conditions are met, a new frame is requested. If the ticker has not
  21491. * been started, but autoStart is `true`, then the ticker starts now,
  21492. * and continues with the previous conditions to request a new frame.
  21493. *
  21494. * @private
  21495. */
  21496. Ticker.prototype._startIfPossible = function _startIfPossible() {
  21497. if (this.started) {
  21498. this._requestIfNeeded();
  21499. } else if (this.autoStart) {
  21500. this.start();
  21501. }
  21502. };
  21503. /**
  21504. * Register a handler for tick events. Calls continuously unless
  21505. * it is removed or the ticker is stopped.
  21506. *
  21507. * @param {Function} fn - The listener function to be added for updates
  21508. * @param {Function} [context] - The listener context
  21509. * @param {number} [priority=PIXI.UPDATE_PRIORITY.NORMAL] - The priority for emitting
  21510. * @returns {PIXI.ticker.Ticker} This instance of a ticker
  21511. */
  21512. Ticker.prototype.add = function add(fn, context) {
  21513. var priority = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : _const.UPDATE_PRIORITY.NORMAL;
  21514. return this._addListener(new _TickerListener2.default(fn, context, priority));
  21515. };
  21516. /**
  21517. * Add a handler for the tick event which is only execute once.
  21518. *
  21519. * @param {Function} fn - The listener function to be added for one update
  21520. * @param {Function} [context] - The listener context
  21521. * @param {number} [priority=PIXI.UPDATE_PRIORITY.NORMAL] - The priority for emitting
  21522. * @returns {PIXI.ticker.Ticker} This instance of a ticker
  21523. */
  21524. Ticker.prototype.addOnce = function addOnce(fn, context) {
  21525. var priority = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : _const.UPDATE_PRIORITY.NORMAL;
  21526. return this._addListener(new _TickerListener2.default(fn, context, priority, true));
  21527. };
  21528. /**
  21529. * Internally adds the event handler so that it can be sorted by priority.
  21530. * Priority allows certain handler (user, AnimatedSprite, Interaction) to be run
  21531. * before the rendering.
  21532. *
  21533. * @private
  21534. * @param {TickerListener} listener - Current listener being added.
  21535. * @returns {PIXI.ticker.Ticker} This instance of a ticker
  21536. */
  21537. Ticker.prototype._addListener = function _addListener(listener) {
  21538. // For attaching to head
  21539. var current = this._head.next;
  21540. var previous = this._head;
  21541. // Add the first item
  21542. if (!current) {
  21543. listener.connect(previous);
  21544. } else {
  21545. // Go from highest to lowest priority
  21546. while (current) {
  21547. if (listener.priority > current.priority) {
  21548. listener.connect(previous);
  21549. break;
  21550. }
  21551. previous = current;
  21552. current = current.next;
  21553. }
  21554. // Not yet connected
  21555. if (!listener.previous) {
  21556. listener.connect(previous);
  21557. }
  21558. }
  21559. this._startIfPossible();
  21560. return this;
  21561. };
  21562. /**
  21563. * Removes any handlers matching the function and context parameters.
  21564. * If no handlers are left after removing, then it cancels the animation frame.
  21565. *
  21566. * @param {Function} fn - The listener function to be removed
  21567. * @param {Function} [context] - The listener context to be removed
  21568. * @returns {PIXI.ticker.Ticker} This instance of a ticker
  21569. */
  21570. Ticker.prototype.remove = function remove(fn, context) {
  21571. var listener = this._head.next;
  21572. while (listener) {
  21573. // We found a match, lets remove it
  21574. // no break to delete all possible matches
  21575. // incase a listener was added 2+ times
  21576. if (listener.match(fn, context)) {
  21577. listener = listener.destroy();
  21578. } else {
  21579. listener = listener.next;
  21580. }
  21581. }
  21582. if (!this._head.next) {
  21583. this._cancelIfNeeded();
  21584. }
  21585. return this;
  21586. };
  21587. /**
  21588. * Starts the ticker. If the ticker has listeners
  21589. * a new animation frame is requested at this point.
  21590. */
  21591. Ticker.prototype.start = function start() {
  21592. if (!this.started) {
  21593. this.started = true;
  21594. this._requestIfNeeded();
  21595. }
  21596. };
  21597. /**
  21598. * Stops the ticker. If the ticker has requested
  21599. * an animation frame it is canceled at this point.
  21600. */
  21601. Ticker.prototype.stop = function stop() {
  21602. if (this.started) {
  21603. this.started = false;
  21604. this._cancelIfNeeded();
  21605. }
  21606. };
  21607. /**
  21608. * Destroy the ticker and don't use after this. Calling
  21609. * this method removes all references to internal events.
  21610. */
  21611. Ticker.prototype.destroy = function destroy() {
  21612. this.stop();
  21613. var listener = this._head.next;
  21614. while (listener) {
  21615. listener = listener.destroy(true);
  21616. }
  21617. this._head.destroy();
  21618. this._head = null;
  21619. };
  21620. /**
  21621. * Triggers an update. An update entails setting the
  21622. * current {@link PIXI.ticker.Ticker#elapsedMS},
  21623. * the current {@link PIXI.ticker.Ticker#deltaTime},
  21624. * invoking all listeners with current deltaTime,
  21625. * and then finally setting {@link PIXI.ticker.Ticker#lastTime}
  21626. * with the value of currentTime that was provided.
  21627. * This method will be called automatically by animation
  21628. * frame callbacks if the ticker instance has been started
  21629. * and listeners are added.
  21630. *
  21631. * @param {number} [currentTime=performance.now()] - the current time of execution
  21632. */
  21633. Ticker.prototype.update = function update() {
  21634. var currentTime = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : performance.now();
  21635. var elapsedMS = void 0;
  21636. // If the difference in time is zero or negative, we ignore most of the work done here.
  21637. // If there is no valid difference, then should be no reason to let anyone know about it.
  21638. // A zero delta, is exactly that, nothing should update.
  21639. //
  21640. // The difference in time can be negative, and no this does not mean time traveling.
  21641. // This can be the result of a race condition between when an animation frame is requested
  21642. // on the current JavaScript engine event loop, and when the ticker's start method is invoked
  21643. // (which invokes the internal _requestIfNeeded method). If a frame is requested before
  21644. // _requestIfNeeded is invoked, then the callback for the animation frame the ticker requests,
  21645. // can receive a time argument that can be less than the lastTime value that was set within
  21646. // _requestIfNeeded. This difference is in microseconds, but this is enough to cause problems.
  21647. //
  21648. // This check covers this browser engine timing issue, as well as if consumers pass an invalid
  21649. // currentTime value. This may happen if consumers opt-out of the autoStart, and update themselves.
  21650. if (currentTime > this.lastTime) {
  21651. // Save uncapped elapsedMS for measurement
  21652. elapsedMS = this.elapsedMS = currentTime - this.lastTime;
  21653. // cap the milliseconds elapsed used for deltaTime
  21654. if (elapsedMS > this._maxElapsedMS) {
  21655. elapsedMS = this._maxElapsedMS;
  21656. }
  21657. this.deltaTime = elapsedMS * _settings2.default.TARGET_FPMS * this.speed;
  21658. // Cache a local reference, in-case ticker is destroyed
  21659. // during the emit, we can still check for head.next
  21660. var head = this._head;
  21661. // Invoke listeners added to internal emitter
  21662. var listener = head.next;
  21663. while (listener) {
  21664. listener = listener.emit(this.deltaTime);
  21665. }
  21666. if (!head.next) {
  21667. this._cancelIfNeeded();
  21668. }
  21669. } else {
  21670. this.deltaTime = this.elapsedMS = 0;
  21671. }
  21672. this.lastTime = currentTime;
  21673. };
  21674. /**
  21675. * The frames per second at which this ticker is running.
  21676. * The default is approximately 60 in most modern browsers.
  21677. * **Note:** This does not factor in the value of
  21678. * {@link PIXI.ticker.Ticker#speed}, which is specific
  21679. * to scaling {@link PIXI.ticker.Ticker#deltaTime}.
  21680. *
  21681. * @member {number}
  21682. * @readonly
  21683. */
  21684. _createClass(Ticker, [{
  21685. key: 'FPS',
  21686. get: function get() {
  21687. return 1000 / this.elapsedMS;
  21688. }
  21689. /**
  21690. * Manages the maximum amount of milliseconds allowed to
  21691. * elapse between invoking {@link PIXI.ticker.Ticker#update}.
  21692. * This value is used to cap {@link PIXI.ticker.Ticker#deltaTime},
  21693. * but does not effect the measured value of {@link PIXI.ticker.Ticker#FPS}.
  21694. * When setting this property it is clamped to a value between
  21695. * `0` and `PIXI.settings.TARGET_FPMS * 1000`.
  21696. *
  21697. * @member {number}
  21698. * @default 10
  21699. */
  21700. }, {
  21701. key: 'minFPS',
  21702. get: function get() {
  21703. return 1000 / this._maxElapsedMS;
  21704. },
  21705. set: function set(fps) // eslint-disable-line require-jsdoc
  21706. {
  21707. // Clamp: 0 to TARGET_FPMS
  21708. var minFPMS = Math.min(Math.max(0, fps) / 1000, _settings2.default.TARGET_FPMS);
  21709. this._maxElapsedMS = 1 / minFPMS;
  21710. }
  21711. }]);
  21712. return Ticker;
  21713. }();
  21714. exports.default = Ticker;
  21715. }, { "../const": 46, "../settings": 101, "./TickerListener": 120 }], 120: [function (require, module, exports) {
  21716. "use strict";
  21717. exports.__esModule = true;
  21718. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  21719. /**
  21720. * Internal class for handling the priority sorting of ticker handlers.
  21721. *
  21722. * @private
  21723. * @class
  21724. * @memberof PIXI.ticker
  21725. */
  21726. var TickerListener = function () {
  21727. /**
  21728. * Constructor
  21729. *
  21730. * @param {Function} fn - The listener function to be added for one update
  21731. * @param {Function} [context=null] - The listener context
  21732. * @param {number} [priority=0] - The priority for emitting
  21733. * @param {boolean} [once=false] - If the handler should fire once
  21734. */
  21735. function TickerListener(fn) {
  21736. var context = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
  21737. var priority = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
  21738. var once = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
  21739. _classCallCheck(this, TickerListener);
  21740. /**
  21741. * The handler function to execute.
  21742. * @member {Function}
  21743. */
  21744. this.fn = fn;
  21745. /**
  21746. * The calling to execute.
  21747. * @member {Function}
  21748. */
  21749. this.context = context;
  21750. /**
  21751. * The current priority.
  21752. * @member {number}
  21753. */
  21754. this.priority = priority;
  21755. /**
  21756. * If this should only execute once.
  21757. * @member {boolean}
  21758. */
  21759. this.once = once;
  21760. /**
  21761. * The next item in chain.
  21762. * @member {TickerListener}
  21763. */
  21764. this.next = null;
  21765. /**
  21766. * The previous item in chain.
  21767. * @member {TickerListener}
  21768. */
  21769. this.previous = null;
  21770. /**
  21771. * `true` if this listener has been destroyed already.
  21772. * @member {boolean}
  21773. * @private
  21774. */
  21775. this._destroyed = false;
  21776. }
  21777. /**
  21778. * Simple compare function to figure out if a function and context match.
  21779. *
  21780. * @param {Function} fn - The listener function to be added for one update
  21781. * @param {Function} context - The listener context
  21782. * @return {boolean} `true` if the listener match the arguments
  21783. */
  21784. TickerListener.prototype.match = function match(fn, context) {
  21785. context = context || null;
  21786. return this.fn === fn && this.context === context;
  21787. };
  21788. /**
  21789. * Emit by calling the current function.
  21790. * @param {number} deltaTime - time since the last emit.
  21791. * @return {TickerListener} Next ticker
  21792. */
  21793. TickerListener.prototype.emit = function emit(deltaTime) {
  21794. if (this.fn) {
  21795. if (this.context) {
  21796. this.fn.call(this.context, deltaTime);
  21797. } else {
  21798. this.fn(deltaTime);
  21799. }
  21800. }
  21801. var redirect = this.next;
  21802. if (this.once) {
  21803. this.destroy(true);
  21804. }
  21805. // Soft-destroying should remove
  21806. // the next reference
  21807. if (this._destroyed) {
  21808. this.next = null;
  21809. }
  21810. return redirect;
  21811. };
  21812. /**
  21813. * Connect to the list.
  21814. * @param {TickerListener} previous - Input node, previous listener
  21815. */
  21816. TickerListener.prototype.connect = function connect(previous) {
  21817. this.previous = previous;
  21818. if (previous.next) {
  21819. previous.next.previous = this;
  21820. }
  21821. this.next = previous.next;
  21822. previous.next = this;
  21823. };
  21824. /**
  21825. * Destroy and don't use after this.
  21826. * @param {boolean} [hard = false] `true` to remove the `next` reference, this
  21827. * is considered a hard destroy. Soft destroy maintains the next reference.
  21828. * @return {TickerListener} The listener to redirect while emitting or removing.
  21829. */
  21830. TickerListener.prototype.destroy = function destroy() {
  21831. var hard = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  21832. this._destroyed = true;
  21833. this.fn = null;
  21834. this.context = null;
  21835. // Disconnect, hook up next and previous
  21836. if (this.previous) {
  21837. this.previous.next = this.next;
  21838. }
  21839. if (this.next) {
  21840. this.next.previous = this.previous;
  21841. }
  21842. // Redirect to the next item
  21843. var redirect = this.previous;
  21844. // Remove references
  21845. this.next = hard ? null : redirect;
  21846. this.previous = null;
  21847. return redirect;
  21848. };
  21849. return TickerListener;
  21850. }();
  21851. exports.default = TickerListener;
  21852. }, {}], 121: [function (require, module, exports) {
  21853. 'use strict';
  21854. exports.__esModule = true;
  21855. exports.Ticker = exports.shared = undefined;
  21856. var _Ticker = require('./Ticker');
  21857. var _Ticker2 = _interopRequireDefault(_Ticker);
  21858. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  21859. /**
  21860. * The shared ticker instance used by {@link PIXI.extras.AnimatedSprite}.
  21861. * and by {@link PIXI.interaction.InteractionManager}.
  21862. * The property {@link PIXI.ticker.Ticker#autoStart} is set to `true`
  21863. * for this instance. Please follow the examples for usage, including
  21864. * how to opt-out of auto-starting the shared ticker.
  21865. *
  21866. * @example
  21867. * let ticker = PIXI.ticker.shared;
  21868. * // Set this to prevent starting this ticker when listeners are added.
  21869. * // By default this is true only for the PIXI.ticker.shared instance.
  21870. * ticker.autoStart = false;
  21871. * // FYI, call this to ensure the ticker is stopped. It should be stopped
  21872. * // if you have not attempted to render anything yet.
  21873. * ticker.stop();
  21874. * // Call this when you are ready for a running shared ticker.
  21875. * ticker.start();
  21876. *
  21877. * @example
  21878. * // You may use the shared ticker to render...
  21879. * let renderer = PIXI.autoDetectRenderer(800, 600);
  21880. * let stage = new PIXI.Container();
  21881. * let interactionManager = PIXI.interaction.InteractionManager(renderer);
  21882. * document.body.appendChild(renderer.view);
  21883. * ticker.add(function (time) {
  21884. * renderer.render(stage);
  21885. * });
  21886. *
  21887. * @example
  21888. * // Or you can just update it manually.
  21889. * ticker.autoStart = false;
  21890. * ticker.stop();
  21891. * function animate(time) {
  21892. * ticker.update(time);
  21893. * renderer.render(stage);
  21894. * requestAnimationFrame(animate);
  21895. * }
  21896. * animate(performance.now());
  21897. *
  21898. * @type {PIXI.ticker.Ticker}
  21899. * @memberof PIXI.ticker
  21900. */
  21901. var shared = new _Ticker2.default();
  21902. shared.autoStart = true;
  21903. shared.destroy = function () {
  21904. // protect destroying shared ticker
  21905. // this is used by other internal systems
  21906. // like AnimatedSprite and InteractionManager
  21907. };
  21908. /**
  21909. * This namespace contains an API for interacting with PIXI's internal global update loop.
  21910. *
  21911. * This ticker is used for rendering, {@link PIXI.extras.AnimatedSprite AnimatedSprite},
  21912. * {@link PIXI.interaction.InteractionManager InteractionManager} and many other time-based PIXI systems.
  21913. * @example
  21914. * const ticker = new PIXI.ticker.Ticker();
  21915. * ticker.stop();
  21916. * ticker.add((deltaTime) => {
  21917. * // do something every frame
  21918. * });
  21919. * ticker.start();
  21920. * @namespace PIXI.ticker
  21921. */
  21922. exports.shared = shared;
  21923. exports.Ticker = _Ticker2.default;
  21924. }, { "./Ticker": 119 }], 122: [function (require, module, exports) {
  21925. "use strict";
  21926. exports.__esModule = true;
  21927. exports.default = canUploadSameBuffer;
  21928. function canUploadSameBuffer() {
  21929. // Uploading the same buffer multiple times in a single frame can cause perf issues.
  21930. // Apparent on IOS so only check for that at the moment
  21931. // this check may become more complex if this issue pops up elsewhere.
  21932. var ios = !!navigator.platform && /iPad|iPhone|iPod/.test(navigator.platform);
  21933. return !ios;
  21934. }
  21935. }, {}], 123: [function (require, module, exports) {
  21936. "use strict";
  21937. exports.__esModule = true;
  21938. exports.default = createIndicesForQuads;
  21939. /**
  21940. * Generic Mask Stack data structure
  21941. *
  21942. * @memberof PIXI
  21943. * @function createIndicesForQuads
  21944. * @private
  21945. * @param {number} size - Number of quads
  21946. * @return {Uint16Array} indices
  21947. */
  21948. function createIndicesForQuads(size) {
  21949. // the total number of indices in our array, there are 6 points per quad.
  21950. var totalIndices = size * 6;
  21951. var indices = new Uint16Array(totalIndices);
  21952. // fill the indices with the quads to draw
  21953. for (var i = 0, j = 0; i < totalIndices; i += 6, j += 4) {
  21954. indices[i + 0] = j + 0;
  21955. indices[i + 1] = j + 1;
  21956. indices[i + 2] = j + 2;
  21957. indices[i + 3] = j + 0;
  21958. indices[i + 4] = j + 2;
  21959. indices[i + 5] = j + 3;
  21960. }
  21961. return indices;
  21962. }
  21963. }, {}], 124: [function (require, module, exports) {
  21964. 'use strict';
  21965. exports.__esModule = true;
  21966. exports.default = determineCrossOrigin;
  21967. var _url2 = require('url');
  21968. var _url3 = _interopRequireDefault(_url2);
  21969. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  21970. var tempAnchor = void 0;
  21971. /**
  21972. * Sets the `crossOrigin` property for this resource based on if the url
  21973. * for this resource is cross-origin. If crossOrigin was manually set, this
  21974. * function does nothing.
  21975. * Nipped from the resource loader!
  21976. *
  21977. * @ignore
  21978. * @param {string} url - The url to test.
  21979. * @param {object} [loc=window.location] - The location object to test against.
  21980. * @return {string} The crossOrigin value to use (or empty string for none).
  21981. */
  21982. function determineCrossOrigin(url) {
  21983. var loc = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : window.location;
  21984. // data: and javascript: urls are considered same-origin
  21985. if (url.indexOf('data:') === 0) {
  21986. return '';
  21987. }
  21988. // default is window.location
  21989. loc = loc || window.location;
  21990. if (!tempAnchor) {
  21991. tempAnchor = document.createElement('a');
  21992. }
  21993. // let the browser determine the full href for the url of this resource and then
  21994. // parse with the node url lib, we can't use the properties of the anchor element
  21995. // because they don't work in IE9 :(
  21996. tempAnchor.href = url;
  21997. url = _url3.default.parse(tempAnchor.href);
  21998. var samePort = !url.port && loc.port === '' || url.port === loc.port;
  21999. // if cross origin
  22000. if (url.hostname !== loc.hostname || !samePort || url.protocol !== loc.protocol) {
  22001. return 'anonymous';
  22002. }
  22003. return '';
  22004. }
  22005. }, { "url": 38 }], 125: [function (require, module, exports) {
  22006. 'use strict';
  22007. exports.__esModule = true;
  22008. exports.premultiplyBlendMode = exports.BaseTextureCache = exports.TextureCache = exports.earcut = exports.mixins = exports.pluginTarget = exports.EventEmitter = exports.removeItems = exports.isMobile = undefined;
  22009. exports.uid = uid;
  22010. exports.hex2rgb = hex2rgb;
  22011. exports.hex2string = hex2string;
  22012. exports.rgb2hex = rgb2hex;
  22013. exports.getResolutionOfUrl = getResolutionOfUrl;
  22014. exports.decomposeDataUri = decomposeDataUri;
  22015. exports.getUrlFileExtension = getUrlFileExtension;
  22016. exports.getSvgSize = getSvgSize;
  22017. exports.skipHello = skipHello;
  22018. exports.sayHello = sayHello;
  22019. exports.isWebGLSupported = isWebGLSupported;
  22020. exports.sign = sign;
  22021. exports.destroyTextureCache = destroyTextureCache;
  22022. exports.clearTextureCache = clearTextureCache;
  22023. exports.correctBlendMode = correctBlendMode;
  22024. exports.premultiplyTint = premultiplyTint;
  22025. exports.premultiplyRgba = premultiplyRgba;
  22026. exports.premultiplyTintToRgba = premultiplyTintToRgba;
  22027. var _const = require('../const');
  22028. var _settings = require('../settings');
  22029. var _settings2 = _interopRequireDefault(_settings);
  22030. var _eventemitter = require('eventemitter3');
  22031. var _eventemitter2 = _interopRequireDefault(_eventemitter);
  22032. var _pluginTarget = require('./pluginTarget');
  22033. var _pluginTarget2 = _interopRequireDefault(_pluginTarget);
  22034. var _mixin = require('./mixin');
  22035. var mixins = _interopRequireWildcard(_mixin);
  22036. var _ismobilejs = require('ismobilejs');
  22037. var isMobile = _interopRequireWildcard(_ismobilejs);
  22038. var _removeArrayItems = require('remove-array-items');
  22039. var _removeArrayItems2 = _interopRequireDefault(_removeArrayItems);
  22040. var _mapPremultipliedBlendModes = require('./mapPremultipliedBlendModes');
  22041. var _mapPremultipliedBlendModes2 = _interopRequireDefault(_mapPremultipliedBlendModes);
  22042. var _earcut = require('earcut');
  22043. var _earcut2 = _interopRequireDefault(_earcut);
  22044. function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
  22045. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  22046. var nextUid = 0;
  22047. var saidHello = false;
  22048. /**
  22049. * Generalized convenience utilities for PIXI.
  22050. * @example
  22051. * // Extend PIXI's internal Event Emitter.
  22052. * class MyEmitter extends PIXI.utils.EventEmitter {
  22053. * constructor() {
  22054. * super();
  22055. * console.log("Emitter created!");
  22056. * }
  22057. * }
  22058. *
  22059. * // Get info on current device
  22060. * console.log(PIXI.utils.isMobile);
  22061. *
  22062. * // Convert hex color to string
  22063. * console.log(PIXI.utils.hex2string(0xff00ff)); // returns: "#ff00ff"
  22064. * @namespace PIXI.utils
  22065. */
  22066. exports.isMobile = isMobile;
  22067. exports.removeItems = _removeArrayItems2.default;
  22068. exports.EventEmitter = _eventemitter2.default;
  22069. exports.pluginTarget = _pluginTarget2.default;
  22070. exports.mixins = mixins;
  22071. exports.earcut = _earcut2.default;
  22072. /**
  22073. * Gets the next unique identifier
  22074. *
  22075. * @memberof PIXI.utils
  22076. * @function uid
  22077. * @return {number} The next unique identifier to use.
  22078. */
  22079. function uid() {
  22080. return ++nextUid;
  22081. }
  22082. /**
  22083. * Converts a hex color number to an [R, G, B] array
  22084. *
  22085. * @memberof PIXI.utils
  22086. * @function hex2rgb
  22087. * @param {number} hex - The number to convert
  22088. * @param {number[]} [out=[]] If supplied, this array will be used rather than returning a new one
  22089. * @return {number[]} An array representing the [R, G, B] of the color.
  22090. */
  22091. function hex2rgb(hex, out) {
  22092. out = out || [];
  22093. out[0] = (hex >> 16 & 0xFF) / 255;
  22094. out[1] = (hex >> 8 & 0xFF) / 255;
  22095. out[2] = (hex & 0xFF) / 255;
  22096. return out;
  22097. }
  22098. /**
  22099. * Converts a hex color number to a string.
  22100. *
  22101. * @memberof PIXI.utils
  22102. * @function hex2string
  22103. * @param {number} hex - Number in hex
  22104. * @return {string} The string color.
  22105. */
  22106. function hex2string(hex) {
  22107. hex = hex.toString(16);
  22108. hex = '000000'.substr(0, 6 - hex.length) + hex;
  22109. return '#' + hex;
  22110. }
  22111. /**
  22112. * Converts a color as an [R, G, B] array to a hex number
  22113. *
  22114. * @memberof PIXI.utils
  22115. * @function rgb2hex
  22116. * @param {number[]} rgb - rgb array
  22117. * @return {number} The color number
  22118. */
  22119. function rgb2hex(rgb) {
  22120. return (rgb[0] * 255 << 16) + (rgb[1] * 255 << 8) + (rgb[2] * 255 | 0);
  22121. }
  22122. /**
  22123. * get the resolution / device pixel ratio of an asset by looking for the prefix
  22124. * used by spritesheets and image urls
  22125. *
  22126. * @memberof PIXI.utils
  22127. * @function getResolutionOfUrl
  22128. * @param {string} url - the image path
  22129. * @param {number} [defaultValue=1] - the defaultValue if no filename prefix is set.
  22130. * @return {number} resolution / device pixel ratio of an asset
  22131. */
  22132. function getResolutionOfUrl(url, defaultValue) {
  22133. var resolution = _settings2.default.RETINA_PREFIX.exec(url);
  22134. if (resolution) {
  22135. return parseFloat(resolution[1]);
  22136. }
  22137. return defaultValue !== undefined ? defaultValue : 1;
  22138. }
  22139. /**
  22140. * Typedef for decomposeDataUri return object.
  22141. *
  22142. * @typedef {object} PIXI.utils~DecomposedDataUri
  22143. * @property {mediaType} Media type, eg. `image`
  22144. * @property {subType} Sub type, eg. `png`
  22145. * @property {encoding} Data encoding, eg. `base64`
  22146. * @property {data} The actual data
  22147. */
  22148. /**
  22149. * Split a data URI into components. Returns undefined if
  22150. * parameter `dataUri` is not a valid data URI.
  22151. *
  22152. * @memberof PIXI.utils
  22153. * @function decomposeDataUri
  22154. * @param {string} dataUri - the data URI to check
  22155. * @return {PIXI.utils~DecomposedDataUri|undefined} The decomposed data uri or undefined
  22156. */
  22157. function decomposeDataUri(dataUri) {
  22158. var dataUriMatch = _const.DATA_URI.exec(dataUri);
  22159. if (dataUriMatch) {
  22160. return {
  22161. mediaType: dataUriMatch[1] ? dataUriMatch[1].toLowerCase() : undefined,
  22162. subType: dataUriMatch[2] ? dataUriMatch[2].toLowerCase() : undefined,
  22163. encoding: dataUriMatch[3] ? dataUriMatch[3].toLowerCase() : undefined,
  22164. data: dataUriMatch[4]
  22165. };
  22166. }
  22167. return undefined;
  22168. }
  22169. /**
  22170. * Get type of the image by regexp for extension. Returns undefined for unknown extensions.
  22171. *
  22172. * @memberof PIXI.utils
  22173. * @function getUrlFileExtension
  22174. * @param {string} url - the image path
  22175. * @return {string|undefined} image extension
  22176. */
  22177. function getUrlFileExtension(url) {
  22178. var extension = _const.URL_FILE_EXTENSION.exec(url);
  22179. if (extension) {
  22180. return extension[1].toLowerCase();
  22181. }
  22182. return undefined;
  22183. }
  22184. /**
  22185. * Typedef for Size object.
  22186. *
  22187. * @typedef {object} PIXI.utils~Size
  22188. * @property {width} Width component
  22189. * @property {height} Height component
  22190. */
  22191. /**
  22192. * Get size from an svg string using regexp.
  22193. *
  22194. * @memberof PIXI.utils
  22195. * @function getSvgSize
  22196. * @param {string} svgString - a serialized svg element
  22197. * @return {PIXI.utils~Size|undefined} image extension
  22198. */
  22199. function getSvgSize(svgString) {
  22200. var sizeMatch = _const.SVG_SIZE.exec(svgString);
  22201. var size = {};
  22202. if (sizeMatch) {
  22203. size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3]));
  22204. size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7]));
  22205. }
  22206. return size;
  22207. }
  22208. /**
  22209. * Skips the hello message of renderers that are created after this is run.
  22210. *
  22211. * @function skipHello
  22212. * @memberof PIXI.utils
  22213. */
  22214. function skipHello() {
  22215. saidHello = true;
  22216. }
  22217. /**
  22218. * Logs out the version and renderer information for this running instance of PIXI.
  22219. * If you don't want to see this message you can run `PIXI.utils.skipHello()` before
  22220. * creating your renderer. Keep in mind that doing that will forever makes you a jerk face.
  22221. *
  22222. * @static
  22223. * @function sayHello
  22224. * @memberof PIXI.utils
  22225. * @param {string} type - The string renderer type to log.
  22226. */
  22227. function sayHello(type) {
  22228. if (saidHello) {
  22229. return;
  22230. }
  22231. if (navigator.userAgent.toLowerCase().indexOf('chrome') > -1) {
  22232. var args = ['\n %c %c %c PixiJS ' + _const.VERSION + ' - \u2730 ' + type + ' \u2730 %c %c http://www.pixijs.com/ %c %c \u2665%c\u2665%c\u2665 \n\n', 'background: #ff66a5; padding:5px 0;', 'background: #ff66a5; padding:5px 0;', 'color: #ff66a5; background: #030307; padding:5px 0;', 'background: #ff66a5; padding:5px 0;', 'background: #ffc3dc; padding:5px 0;', 'background: #ff66a5; padding:5px 0;', 'color: #ff2424; background: #fff; padding:5px 0;', 'color: #ff2424; background: #fff; padding:5px 0;', 'color: #ff2424; background: #fff; padding:5px 0;'];
  22233. window.console.log.apply(console, args);
  22234. } else if (window.console) {
  22235. window.console.log('PixiJS ' + _const.VERSION + ' - ' + type + ' - http://www.pixijs.com/');
  22236. }
  22237. saidHello = true;
  22238. }
  22239. /**
  22240. * Helper for checking for webgl support
  22241. *
  22242. * @memberof PIXI.utils
  22243. * @function isWebGLSupported
  22244. * @return {boolean} is webgl supported
  22245. */
  22246. function isWebGLSupported() {
  22247. var contextOptions = { stencil: true, failIfMajorPerformanceCaveat: true };
  22248. try {
  22249. if (!window.WebGLRenderingContext) {
  22250. return false;
  22251. }
  22252. var canvas = document.createElement('canvas');
  22253. var gl = canvas.getContext('webgl', contextOptions) || canvas.getContext('experimental-webgl', contextOptions);
  22254. var success = !!(gl && gl.getContextAttributes().stencil);
  22255. if (gl) {
  22256. var loseContext = gl.getExtension('WEBGL_lose_context');
  22257. if (loseContext) {
  22258. loseContext.loseContext();
  22259. }
  22260. }
  22261. gl = null;
  22262. return success;
  22263. } catch (e) {
  22264. return false;
  22265. }
  22266. }
  22267. /**
  22268. * Returns sign of number
  22269. *
  22270. * @memberof PIXI.utils
  22271. * @function sign
  22272. * @param {number} n - the number to check the sign of
  22273. * @returns {number} 0 if `n` is 0, -1 if `n` is negative, 1 if `n` is positive
  22274. */
  22275. function sign(n) {
  22276. if (n === 0) return 0;
  22277. return n < 0 ? -1 : 1;
  22278. }
  22279. /**
  22280. * @todo Describe property usage
  22281. *
  22282. * @memberof PIXI.utils
  22283. * @private
  22284. */
  22285. var TextureCache = exports.TextureCache = Object.create(null);
  22286. /**
  22287. * @todo Describe property usage
  22288. *
  22289. * @memberof PIXI.utils
  22290. * @private
  22291. */
  22292. var BaseTextureCache = exports.BaseTextureCache = Object.create(null);
  22293. /**
  22294. * Destroys all texture in the cache
  22295. *
  22296. * @memberof PIXI.utils
  22297. * @function destroyTextureCache
  22298. */
  22299. function destroyTextureCache() {
  22300. var key = void 0;
  22301. for (key in TextureCache) {
  22302. TextureCache[key].destroy();
  22303. }
  22304. for (key in BaseTextureCache) {
  22305. BaseTextureCache[key].destroy();
  22306. }
  22307. }
  22308. /**
  22309. * Removes all textures from cache, but does not destroy them
  22310. *
  22311. * @memberof PIXI.utils
  22312. * @function clearTextureCache
  22313. */
  22314. function clearTextureCache() {
  22315. var key = void 0;
  22316. for (key in TextureCache) {
  22317. delete TextureCache[key];
  22318. }
  22319. for (key in BaseTextureCache) {
  22320. delete BaseTextureCache[key];
  22321. }
  22322. }
  22323. /**
  22324. * maps premultiply flag and blendMode to adjusted blendMode
  22325. * @memberof PIXI.utils
  22326. * @const premultiplyBlendMode
  22327. * @type {Array<number[]>}
  22328. */
  22329. var premultiplyBlendMode = exports.premultiplyBlendMode = (0, _mapPremultipliedBlendModes2.default)();
  22330. /**
  22331. * changes blendMode according to texture format
  22332. *
  22333. * @memberof PIXI.utils
  22334. * @function correctBlendMode
  22335. * @param {number} blendMode supposed blend mode
  22336. * @param {boolean} premultiplied whether source is premultiplied
  22337. * @returns {number} true blend mode for this texture
  22338. */
  22339. function correctBlendMode(blendMode, premultiplied) {
  22340. return premultiplyBlendMode[premultiplied ? 1 : 0][blendMode];
  22341. }
  22342. /**
  22343. * premultiplies tint
  22344. *
  22345. * @memberof PIXI.utils
  22346. * @param {number} tint integet RGB
  22347. * @param {number} alpha floating point alpha (0.0-1.0)
  22348. * @returns {number} tint multiplied by alpha
  22349. */
  22350. function premultiplyTint(tint, alpha) {
  22351. if (alpha === 1.0) {
  22352. return (alpha * 255 << 24) + tint;
  22353. }
  22354. if (alpha === 0.0) {
  22355. return 0;
  22356. }
  22357. var R = tint >> 16 & 0xFF;
  22358. var G = tint >> 8 & 0xFF;
  22359. var B = tint & 0xFF;
  22360. R = R * alpha + 0.5 | 0;
  22361. G = G * alpha + 0.5 | 0;
  22362. B = B * alpha + 0.5 | 0;
  22363. return (alpha * 255 << 24) + (R << 16) + (G << 8) + B;
  22364. }
  22365. /**
  22366. * combines rgb and alpha to out array
  22367. *
  22368. * @memberof PIXI.utils
  22369. * @param {Float32Array|number[]} rgb input rgb
  22370. * @param {number} alpha alpha param
  22371. * @param {Float32Array} [out] output
  22372. * @param {boolean} [premultiply=true] do premultiply it
  22373. * @returns {Float32Array} vec4 rgba
  22374. */
  22375. function premultiplyRgba(rgb, alpha, out, premultiply) {
  22376. out = out || new Float32Array(4);
  22377. if (premultiply || premultiply === undefined) {
  22378. out[0] = rgb[0] * alpha;
  22379. out[1] = rgb[1] * alpha;
  22380. out[2] = rgb[2] * alpha;
  22381. } else {
  22382. out[0] = rgb[0];
  22383. out[1] = rgb[1];
  22384. out[2] = rgb[2];
  22385. }
  22386. out[3] = alpha;
  22387. return out;
  22388. }
  22389. /**
  22390. * converts integer tint and float alpha to vec4 form, premultiplies by default
  22391. *
  22392. * @memberof PIXI.utils
  22393. * @param {number} tint input tint
  22394. * @param {number} alpha alpha param
  22395. * @param {Float32Array} [out] output
  22396. * @param {boolean} [premultiply=true] do premultiply it
  22397. * @returns {Float32Array} vec4 rgba
  22398. */
  22399. function premultiplyTintToRgba(tint, alpha, out, premultiply) {
  22400. out = out || new Float32Array(4);
  22401. out[0] = (tint >> 16 & 0xFF) / 255.0;
  22402. out[1] = (tint >> 8 & 0xFF) / 255.0;
  22403. out[2] = (tint & 0xFF) / 255.0;
  22404. if (premultiply || premultiply === undefined) {
  22405. out[0] *= alpha;
  22406. out[1] *= alpha;
  22407. out[2] *= alpha;
  22408. }
  22409. out[3] = alpha;
  22410. return out;
  22411. }
  22412. }, { "../const": 46, "../settings": 101, "./mapPremultipliedBlendModes": 126, "./mixin": 128, "./pluginTarget": 129, "earcut": 2, "eventemitter3": 3, "ismobilejs": 4, "remove-array-items": 31 }], 126: [function (require, module, exports) {
  22413. 'use strict';
  22414. exports.__esModule = true;
  22415. exports.default = mapPremultipliedBlendModes;
  22416. var _const = require('../const');
  22417. /**
  22418. * Corrects PixiJS blend, takes premultiplied alpha into account
  22419. *
  22420. * @memberof PIXI
  22421. * @function mapPremultipliedBlendModes
  22422. * @private
  22423. * @param {Array<number[]>} [array] - The array to output into.
  22424. * @return {Array<number[]>} Mapped modes.
  22425. */
  22426. function mapPremultipliedBlendModes() {
  22427. var pm = [];
  22428. var npm = [];
  22429. for (var i = 0; i < 32; i++) {
  22430. pm[i] = i;
  22431. npm[i] = i;
  22432. }
  22433. pm[_const.BLEND_MODES.NORMAL_NPM] = _const.BLEND_MODES.NORMAL;
  22434. pm[_const.BLEND_MODES.ADD_NPM] = _const.BLEND_MODES.ADD;
  22435. pm[_const.BLEND_MODES.SCREEN_NPM] = _const.BLEND_MODES.SCREEN;
  22436. npm[_const.BLEND_MODES.NORMAL] = _const.BLEND_MODES.NORMAL_NPM;
  22437. npm[_const.BLEND_MODES.ADD] = _const.BLEND_MODES.ADD_NPM;
  22438. npm[_const.BLEND_MODES.SCREEN] = _const.BLEND_MODES.SCREEN_NPM;
  22439. var array = [];
  22440. array.push(npm);
  22441. array.push(pm);
  22442. return array;
  22443. }
  22444. }, { "../const": 46 }], 127: [function (require, module, exports) {
  22445. 'use strict';
  22446. exports.__esModule = true;
  22447. exports.default = maxRecommendedTextures;
  22448. var _ismobilejs = require('ismobilejs');
  22449. var _ismobilejs2 = _interopRequireDefault(_ismobilejs);
  22450. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  22451. function maxRecommendedTextures(max) {
  22452. if (_ismobilejs2.default.tablet || _ismobilejs2.default.phone) {
  22453. // check if the res is iphone 6 or higher..
  22454. return 4;
  22455. }
  22456. // desktop should be ok
  22457. return max;
  22458. }
  22459. }, { "ismobilejs": 4 }], 128: [function (require, module, exports) {
  22460. "use strict";
  22461. exports.__esModule = true;
  22462. exports.mixin = mixin;
  22463. exports.delayMixin = delayMixin;
  22464. exports.performMixins = performMixins;
  22465. /**
  22466. * Mixes all enumerable properties and methods from a source object to a target object.
  22467. *
  22468. * @memberof PIXI.utils.mixins
  22469. * @function mixin
  22470. * @param {object} target The prototype or instance that properties and methods should be added to.
  22471. * @param {object} source The source of properties and methods to mix in.
  22472. */
  22473. function mixin(target, source) {
  22474. if (!target || !source) return;
  22475. // in ES8/ES2017, this would be really easy:
  22476. // Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
  22477. // get all the enumerable property keys
  22478. var keys = Object.keys(source);
  22479. // loop through properties
  22480. for (var i = 0; i < keys.length; ++i) {
  22481. var propertyName = keys[i];
  22482. // Set the property using the property descriptor - this works for accessors and normal value properties
  22483. Object.defineProperty(target, propertyName, Object.getOwnPropertyDescriptor(source, propertyName));
  22484. }
  22485. }
  22486. var mixins = [];
  22487. /**
  22488. * Queues a mixin to be handled towards the end of the initialization of PIXI, so that deprecation
  22489. * can take effect.
  22490. *
  22491. * @memberof PIXI.utils.mixins
  22492. * @function delayMixin
  22493. * @private
  22494. * @param {object} target The prototype or instance that properties and methods should be added to.
  22495. * @param {object} source The source of properties and methods to mix in.
  22496. */
  22497. function delayMixin(target, source) {
  22498. mixins.push(target, source);
  22499. }
  22500. /**
  22501. * Handles all mixins queued via delayMixin().
  22502. *
  22503. * @memberof PIXI.utils.mixins
  22504. * @function performMixins
  22505. * @private
  22506. */
  22507. function performMixins() {
  22508. for (var i = 0; i < mixins.length; i += 2) {
  22509. mixin(mixins[i], mixins[i + 1]);
  22510. }
  22511. mixins.length = 0;
  22512. }
  22513. }, {}], 129: [function (require, module, exports) {
  22514. "use strict";
  22515. exports.__esModule = true;
  22516. /**
  22517. * Mixins functionality to make an object have "plugins".
  22518. *
  22519. * @example
  22520. * function MyObject() {}
  22521. *
  22522. * pluginTarget.mixin(MyObject);
  22523. *
  22524. * @mixin
  22525. * @memberof PIXI.utils
  22526. * @param {object} obj - The object to mix into.
  22527. */
  22528. function pluginTarget(obj) {
  22529. obj.__plugins = {};
  22530. /**
  22531. * Adds a plugin to an object
  22532. *
  22533. * @param {string} pluginName - The events that should be listed.
  22534. * @param {Function} ctor - The constructor function for the plugin.
  22535. */
  22536. obj.registerPlugin = function registerPlugin(pluginName, ctor) {
  22537. obj.__plugins[pluginName] = ctor;
  22538. };
  22539. /**
  22540. * Instantiates all the plugins of this object
  22541. *
  22542. */
  22543. obj.prototype.initPlugins = function initPlugins() {
  22544. this.plugins = this.plugins || {};
  22545. for (var o in obj.__plugins) {
  22546. this.plugins[o] = new obj.__plugins[o](this);
  22547. }
  22548. };
  22549. /**
  22550. * Removes all the plugins of this object
  22551. *
  22552. */
  22553. obj.prototype.destroyPlugins = function destroyPlugins() {
  22554. for (var o in this.plugins) {
  22555. this.plugins[o].destroy();
  22556. this.plugins[o] = null;
  22557. }
  22558. this.plugins = null;
  22559. };
  22560. }
  22561. exports.default = {
  22562. /**
  22563. * Mixes in the properties of the pluginTarget into another object
  22564. *
  22565. * @param {object} obj - The obj to mix into
  22566. */
  22567. mixin: function mixin(obj) {
  22568. pluginTarget(obj);
  22569. }
  22570. };
  22571. }, {}], 130: [function (require, module, exports) {
  22572. 'use strict';
  22573. exports.__esModule = true;
  22574. exports.default = trimCanvas;
  22575. /**
  22576. * Trim transparent borders from a canvas
  22577. *
  22578. * @memberof PIXI
  22579. * @function trimCanvas
  22580. * @private
  22581. * @param {HTMLCanvasElement} canvas - the canvas to trim
  22582. * @returns {object} Trim data
  22583. */
  22584. function trimCanvas(canvas) {
  22585. // https://gist.github.com/remy/784508
  22586. var width = canvas.width;
  22587. var height = canvas.height;
  22588. var context = canvas.getContext('2d');
  22589. var imageData = context.getImageData(0, 0, width, height);
  22590. var pixels = imageData.data;
  22591. var len = pixels.length;
  22592. var bound = {
  22593. top: null,
  22594. left: null,
  22595. right: null,
  22596. bottom: null
  22597. };
  22598. var i = void 0;
  22599. var x = void 0;
  22600. var y = void 0;
  22601. for (i = 0; i < len; i += 4) {
  22602. if (pixels[i + 3] !== 0) {
  22603. x = i / 4 % width;
  22604. y = ~~(i / 4 / width);
  22605. if (bound.top === null) {
  22606. bound.top = y;
  22607. }
  22608. if (bound.left === null) {
  22609. bound.left = x;
  22610. } else if (x < bound.left) {
  22611. bound.left = x;
  22612. }
  22613. if (bound.right === null) {
  22614. bound.right = x + 1;
  22615. } else if (bound.right < x) {
  22616. bound.right = x + 1;
  22617. }
  22618. if (bound.bottom === null) {
  22619. bound.bottom = y;
  22620. } else if (bound.bottom < y) {
  22621. bound.bottom = y;
  22622. }
  22623. }
  22624. }
  22625. width = bound.right - bound.left;
  22626. height = bound.bottom - bound.top + 1;
  22627. var data = context.getImageData(bound.left, bound.top, width, height);
  22628. return {
  22629. height: height,
  22630. width: width,
  22631. data: data
  22632. };
  22633. }
  22634. }, {}], 131: [function (require, module, exports) {
  22635. 'use strict';
  22636. exports.__esModule = true;
  22637. exports.default = deprecation;
  22638. // provide method to give a stack track for warnings
  22639. // useful for tracking-down where deprecated methods/properties/classes
  22640. // are being used within the code
  22641. // A map of warning messages already fired
  22642. var warnings = {};
  22643. // provide method to give a stack track for warnings
  22644. // useful for tracking-down where deprecated methods/properties/classes
  22645. // are being used within the code
  22646. function warn(msg) {
  22647. // Ignore duplicat
  22648. if (warnings[msg]) {
  22649. return;
  22650. }
  22651. /* eslint-disable no-console */
  22652. var stack = new Error().stack;
  22653. // Handle IE < 10 and Safari < 6
  22654. if (typeof stack === 'undefined') {
  22655. console.warn('Deprecation Warning: ', msg);
  22656. } else {
  22657. // chop off the stack trace which includes pixi.js internal calls
  22658. stack = stack.split('\n').splice(3).join('\n');
  22659. if (console.groupCollapsed) {
  22660. console.groupCollapsed('%cDeprecation Warning: %c%s', 'color:#614108;background:#fffbe6', 'font-weight:normal;color:#614108;background:#fffbe6', msg);
  22661. console.warn(stack);
  22662. console.groupEnd();
  22663. } else {
  22664. console.warn('Deprecation Warning: ', msg);
  22665. console.warn(stack);
  22666. }
  22667. }
  22668. /* eslint-enable no-console */
  22669. warnings[msg] = true;
  22670. }
  22671. function deprecation(core) {
  22672. var mesh = core.mesh,
  22673. particles = core.particles,
  22674. extras = core.extras,
  22675. filters = core.filters,
  22676. prepare = core.prepare,
  22677. loaders = core.loaders,
  22678. interaction = core.interaction;
  22679. Object.defineProperties(core, {
  22680. /**
  22681. * @class
  22682. * @private
  22683. * @name SpriteBatch
  22684. * @memberof PIXI
  22685. * @see PIXI.ParticleContainer
  22686. * @throws {ReferenceError} SpriteBatch does not exist any more, please use the new ParticleContainer instead.
  22687. * @deprecated since version 3.0.0
  22688. */
  22689. SpriteBatch: {
  22690. get: function get() {
  22691. throw new ReferenceError('SpriteBatch does not exist any more, ' + 'please use the new ParticleContainer instead.');
  22692. }
  22693. },
  22694. /**
  22695. * @class
  22696. * @private
  22697. * @name AssetLoader
  22698. * @memberof PIXI
  22699. * @see PIXI.loaders.Loader
  22700. * @throws {ReferenceError} The loader system was overhauled in PixiJS v3,
  22701. * please see the new PIXI.loaders.Loader class.
  22702. * @deprecated since version 3.0.0
  22703. */
  22704. AssetLoader: {
  22705. get: function get() {
  22706. throw new ReferenceError('The loader system was overhauled in PixiJS v3, ' + 'please see the new PIXI.loaders.Loader class.');
  22707. }
  22708. },
  22709. /**
  22710. * @class
  22711. * @private
  22712. * @name Stage
  22713. * @memberof PIXI
  22714. * @see PIXI.Container
  22715. * @deprecated since version 3.0.0
  22716. */
  22717. Stage: {
  22718. get: function get() {
  22719. warn('You do not need to use a PIXI Stage any more, you can simply render any container.');
  22720. return core.Container;
  22721. }
  22722. },
  22723. /**
  22724. * @class
  22725. * @private
  22726. * @name DisplayObjectContainer
  22727. * @memberof PIXI
  22728. * @see PIXI.Container
  22729. * @deprecated since version 3.0.0
  22730. */
  22731. DisplayObjectContainer: {
  22732. get: function get() {
  22733. warn('DisplayObjectContainer has been shortened to Container, please use Container from now on.');
  22734. return core.Container;
  22735. }
  22736. },
  22737. /**
  22738. * @class
  22739. * @private
  22740. * @name Strip
  22741. * @memberof PIXI
  22742. * @see PIXI.mesh.Mesh
  22743. * @deprecated since version 3.0.0
  22744. */
  22745. Strip: {
  22746. get: function get() {
  22747. warn('The Strip class has been renamed to Mesh and moved to mesh.Mesh, please use mesh.Mesh from now on.');
  22748. return mesh.Mesh;
  22749. }
  22750. },
  22751. /**
  22752. * @class
  22753. * @private
  22754. * @name Rope
  22755. * @memberof PIXI
  22756. * @see PIXI.mesh.Rope
  22757. * @deprecated since version 3.0.0
  22758. */
  22759. Rope: {
  22760. get: function get() {
  22761. warn('The Rope class has been moved to mesh.Rope, please use mesh.Rope from now on.');
  22762. return mesh.Rope;
  22763. }
  22764. },
  22765. /**
  22766. * @class
  22767. * @private
  22768. * @name ParticleContainer
  22769. * @memberof PIXI
  22770. * @see PIXI.particles.ParticleContainer
  22771. * @deprecated since version 4.0.0
  22772. */
  22773. ParticleContainer: {
  22774. get: function get() {
  22775. warn('The ParticleContainer class has been moved to particles.ParticleContainer, ' + 'please use particles.ParticleContainer from now on.');
  22776. return particles.ParticleContainer;
  22777. }
  22778. },
  22779. /**
  22780. * @class
  22781. * @private
  22782. * @name MovieClip
  22783. * @memberof PIXI
  22784. * @see PIXI.extras.MovieClip
  22785. * @deprecated since version 3.0.0
  22786. */
  22787. MovieClip: {
  22788. get: function get() {
  22789. warn('The MovieClip class has been moved to extras.AnimatedSprite, please use extras.AnimatedSprite.');
  22790. return extras.AnimatedSprite;
  22791. }
  22792. },
  22793. /**
  22794. * @class
  22795. * @private
  22796. * @name TilingSprite
  22797. * @memberof PIXI
  22798. * @see PIXI.extras.TilingSprite
  22799. * @deprecated since version 3.0.0
  22800. */
  22801. TilingSprite: {
  22802. get: function get() {
  22803. warn('The TilingSprite class has been moved to extras.TilingSprite, ' + 'please use extras.TilingSprite from now on.');
  22804. return extras.TilingSprite;
  22805. }
  22806. },
  22807. /**
  22808. * @class
  22809. * @private
  22810. * @name BitmapText
  22811. * @memberof PIXI
  22812. * @see PIXI.extras.BitmapText
  22813. * @deprecated since version 3.0.0
  22814. */
  22815. BitmapText: {
  22816. get: function get() {
  22817. warn('The BitmapText class has been moved to extras.BitmapText, ' + 'please use extras.BitmapText from now on.');
  22818. return extras.BitmapText;
  22819. }
  22820. },
  22821. /**
  22822. * @class
  22823. * @private
  22824. * @name blendModes
  22825. * @memberof PIXI
  22826. * @see PIXI.BLEND_MODES
  22827. * @deprecated since version 3.0.0
  22828. */
  22829. blendModes: {
  22830. get: function get() {
  22831. warn('The blendModes has been moved to BLEND_MODES, please use BLEND_MODES from now on.');
  22832. return core.BLEND_MODES;
  22833. }
  22834. },
  22835. /**
  22836. * @class
  22837. * @private
  22838. * @name scaleModes
  22839. * @memberof PIXI
  22840. * @see PIXI.SCALE_MODES
  22841. * @deprecated since version 3.0.0
  22842. */
  22843. scaleModes: {
  22844. get: function get() {
  22845. warn('The scaleModes has been moved to SCALE_MODES, please use SCALE_MODES from now on.');
  22846. return core.SCALE_MODES;
  22847. }
  22848. },
  22849. /**
  22850. * @class
  22851. * @private
  22852. * @name BaseTextureCache
  22853. * @memberof PIXI
  22854. * @see PIXI.utils.BaseTextureCache
  22855. * @deprecated since version 3.0.0
  22856. */
  22857. BaseTextureCache: {
  22858. get: function get() {
  22859. warn('The BaseTextureCache class has been moved to utils.BaseTextureCache, ' + 'please use utils.BaseTextureCache from now on.');
  22860. return core.utils.BaseTextureCache;
  22861. }
  22862. },
  22863. /**
  22864. * @class
  22865. * @private
  22866. * @name TextureCache
  22867. * @memberof PIXI
  22868. * @see PIXI.utils.TextureCache
  22869. * @deprecated since version 3.0.0
  22870. */
  22871. TextureCache: {
  22872. get: function get() {
  22873. warn('The TextureCache class has been moved to utils.TextureCache, ' + 'please use utils.TextureCache from now on.');
  22874. return core.utils.TextureCache;
  22875. }
  22876. },
  22877. /**
  22878. * @namespace
  22879. * @private
  22880. * @name math
  22881. * @memberof PIXI
  22882. * @see PIXI
  22883. * @deprecated since version 3.0.6
  22884. */
  22885. math: {
  22886. get: function get() {
  22887. warn('The math namespace is deprecated, please access members already accessible on PIXI.');
  22888. return core;
  22889. }
  22890. },
  22891. /**
  22892. * @class
  22893. * @private
  22894. * @name PIXI.AbstractFilter
  22895. * @see PIXI.Filter
  22896. * @deprecated since version 3.0.6
  22897. */
  22898. AbstractFilter: {
  22899. get: function get() {
  22900. warn('AstractFilter has been renamed to Filter, please use PIXI.Filter');
  22901. return core.Filter;
  22902. }
  22903. },
  22904. /**
  22905. * @class
  22906. * @private
  22907. * @name PIXI.TransformManual
  22908. * @see PIXI.TransformBase
  22909. * @deprecated since version 4.0.0
  22910. */
  22911. TransformManual: {
  22912. get: function get() {
  22913. warn('TransformManual has been renamed to TransformBase, please update your pixi-spine');
  22914. return core.TransformBase;
  22915. }
  22916. },
  22917. /**
  22918. * @static
  22919. * @constant
  22920. * @name PIXI.TARGET_FPMS
  22921. * @see PIXI.settings.TARGET_FPMS
  22922. * @deprecated since version 4.2.0
  22923. */
  22924. TARGET_FPMS: {
  22925. get: function get() {
  22926. warn('PIXI.TARGET_FPMS has been deprecated, please use PIXI.settings.TARGET_FPMS');
  22927. return core.settings.TARGET_FPMS;
  22928. },
  22929. set: function set(value) {
  22930. warn('PIXI.TARGET_FPMS has been deprecated, please use PIXI.settings.TARGET_FPMS');
  22931. core.settings.TARGET_FPMS = value;
  22932. }
  22933. },
  22934. /**
  22935. * @static
  22936. * @constant
  22937. * @name PIXI.FILTER_RESOLUTION
  22938. * @see PIXI.settings.FILTER_RESOLUTION
  22939. * @deprecated since version 4.2.0
  22940. */
  22941. FILTER_RESOLUTION: {
  22942. get: function get() {
  22943. warn('PIXI.FILTER_RESOLUTION has been deprecated, please use PIXI.settings.FILTER_RESOLUTION');
  22944. return core.settings.FILTER_RESOLUTION;
  22945. },
  22946. set: function set(value) {
  22947. warn('PIXI.FILTER_RESOLUTION has been deprecated, please use PIXI.settings.FILTER_RESOLUTION');
  22948. core.settings.FILTER_RESOLUTION = value;
  22949. }
  22950. },
  22951. /**
  22952. * @static
  22953. * @constant
  22954. * @name PIXI.RESOLUTION
  22955. * @see PIXI.settings.RESOLUTION
  22956. * @deprecated since version 4.2.0
  22957. */
  22958. RESOLUTION: {
  22959. get: function get() {
  22960. warn('PIXI.RESOLUTION has been deprecated, please use PIXI.settings.RESOLUTION');
  22961. return core.settings.RESOLUTION;
  22962. },
  22963. set: function set(value) {
  22964. warn('PIXI.RESOLUTION has been deprecated, please use PIXI.settings.RESOLUTION');
  22965. core.settings.RESOLUTION = value;
  22966. }
  22967. },
  22968. /**
  22969. * @static
  22970. * @constant
  22971. * @name PIXI.MIPMAP_TEXTURES
  22972. * @see PIXI.settings.MIPMAP_TEXTURES
  22973. * @deprecated since version 4.2.0
  22974. */
  22975. MIPMAP_TEXTURES: {
  22976. get: function get() {
  22977. warn('PIXI.MIPMAP_TEXTURES has been deprecated, please use PIXI.settings.MIPMAP_TEXTURES');
  22978. return core.settings.MIPMAP_TEXTURES;
  22979. },
  22980. set: function set(value) {
  22981. warn('PIXI.MIPMAP_TEXTURES has been deprecated, please use PIXI.settings.MIPMAP_TEXTURES');
  22982. core.settings.MIPMAP_TEXTURES = value;
  22983. }
  22984. },
  22985. /**
  22986. * @static
  22987. * @constant
  22988. * @name PIXI.SPRITE_BATCH_SIZE
  22989. * @see PIXI.settings.SPRITE_BATCH_SIZE
  22990. * @deprecated since version 4.2.0
  22991. */
  22992. SPRITE_BATCH_SIZE: {
  22993. get: function get() {
  22994. warn('PIXI.SPRITE_BATCH_SIZE has been deprecated, please use PIXI.settings.SPRITE_BATCH_SIZE');
  22995. return core.settings.SPRITE_BATCH_SIZE;
  22996. },
  22997. set: function set(value) {
  22998. warn('PIXI.SPRITE_BATCH_SIZE has been deprecated, please use PIXI.settings.SPRITE_BATCH_SIZE');
  22999. core.settings.SPRITE_BATCH_SIZE = value;
  23000. }
  23001. },
  23002. /**
  23003. * @static
  23004. * @constant
  23005. * @name PIXI.SPRITE_MAX_TEXTURES
  23006. * @see PIXI.settings.SPRITE_MAX_TEXTURES
  23007. * @deprecated since version 4.2.0
  23008. */
  23009. SPRITE_MAX_TEXTURES: {
  23010. get: function get() {
  23011. warn('PIXI.SPRITE_MAX_TEXTURES has been deprecated, please use PIXI.settings.SPRITE_MAX_TEXTURES');
  23012. return core.settings.SPRITE_MAX_TEXTURES;
  23013. },
  23014. set: function set(value) {
  23015. warn('PIXI.SPRITE_MAX_TEXTURES has been deprecated, please use PIXI.settings.SPRITE_MAX_TEXTURES');
  23016. core.settings.SPRITE_MAX_TEXTURES = value;
  23017. }
  23018. },
  23019. /**
  23020. * @static
  23021. * @constant
  23022. * @name PIXI.RETINA_PREFIX
  23023. * @see PIXI.settings.RETINA_PREFIX
  23024. * @deprecated since version 4.2.0
  23025. */
  23026. RETINA_PREFIX: {
  23027. get: function get() {
  23028. warn('PIXI.RETINA_PREFIX has been deprecated, please use PIXI.settings.RETINA_PREFIX');
  23029. return core.settings.RETINA_PREFIX;
  23030. },
  23031. set: function set(value) {
  23032. warn('PIXI.RETINA_PREFIX has been deprecated, please use PIXI.settings.RETINA_PREFIX');
  23033. core.settings.RETINA_PREFIX = value;
  23034. }
  23035. },
  23036. /**
  23037. * @static
  23038. * @constant
  23039. * @name PIXI.DEFAULT_RENDER_OPTIONS
  23040. * @see PIXI.settings.RENDER_OPTIONS
  23041. * @deprecated since version 4.2.0
  23042. */
  23043. DEFAULT_RENDER_OPTIONS: {
  23044. get: function get() {
  23045. warn('PIXI.DEFAULT_RENDER_OPTIONS has been deprecated, please use PIXI.settings.DEFAULT_RENDER_OPTIONS');
  23046. return core.settings.RENDER_OPTIONS;
  23047. }
  23048. }
  23049. });
  23050. // Move the default properties to settings
  23051. var defaults = [{ parent: 'TRANSFORM_MODE', target: 'TRANSFORM_MODE' }, { parent: 'GC_MODES', target: 'GC_MODE' }, { parent: 'WRAP_MODES', target: 'WRAP_MODE' }, { parent: 'SCALE_MODES', target: 'SCALE_MODE' }, { parent: 'PRECISION', target: 'PRECISION_FRAGMENT' }];
  23052. var _loop = function _loop(i) {
  23053. var deprecation = defaults[i];
  23054. Object.defineProperty(core[deprecation.parent], 'DEFAULT', {
  23055. get: function get() {
  23056. warn('PIXI.' + deprecation.parent + '.DEFAULT has been deprecated, ' + ('please use PIXI.settings.' + deprecation.target));
  23057. return core.settings[deprecation.target];
  23058. },
  23059. set: function set(value) {
  23060. warn('PIXI.' + deprecation.parent + '.DEFAULT has been deprecated, ' + ('please use PIXI.settings.' + deprecation.target));
  23061. core.settings[deprecation.target] = value;
  23062. }
  23063. });
  23064. };
  23065. for (var i = 0; i < defaults.length; i++) {
  23066. _loop(i);
  23067. }
  23068. Object.defineProperties(core.settings, {
  23069. /**
  23070. * @static
  23071. * @name PRECISION
  23072. * @memberof PIXI.settings
  23073. * @see PIXI.PRECISION
  23074. * @deprecated since version 4.4.0
  23075. */
  23076. PRECISION: {
  23077. get: function get() {
  23078. warn('PIXI.settings.PRECISION has been deprecated, please use PIXI.settings.PRECISION_FRAGMENT');
  23079. return core.settings.PRECISION_FRAGMENT;
  23080. },
  23081. set: function set(value) {
  23082. warn('PIXI.settings.PRECISION has been deprecated, please use PIXI.settings.PRECISION_FRAGMENT');
  23083. core.settings.PRECISION_FRAGMENT = value;
  23084. }
  23085. }
  23086. });
  23087. if (extras.AnimatedSprite) {
  23088. Object.defineProperties(extras, {
  23089. /**
  23090. * @class
  23091. * @name MovieClip
  23092. * @memberof PIXI.extras
  23093. * @see PIXI.extras.AnimatedSprite
  23094. * @deprecated since version 4.2.0
  23095. */
  23096. MovieClip: {
  23097. get: function get() {
  23098. warn('The MovieClip class has been renamed to AnimatedSprite, please use AnimatedSprite from now on.');
  23099. return extras.AnimatedSprite;
  23100. }
  23101. }
  23102. });
  23103. }
  23104. if (extras) {
  23105. Object.defineProperties(extras, {
  23106. /**
  23107. * @class
  23108. * @name TextureTransform
  23109. * @memberof PIXI.extras
  23110. * @see PIXI.TextureMatrix
  23111. * @deprecated since version 4.6.0
  23112. */
  23113. TextureTransform: {
  23114. get: function get() {
  23115. warn('The TextureTransform class has been renamed to TextureMatrix, ' + 'please use PIXI.TextureMatrix from now on.');
  23116. return core.TextureMatrix;
  23117. }
  23118. }
  23119. });
  23120. }
  23121. core.DisplayObject.prototype.generateTexture = function generateTexture(renderer, scaleMode, resolution) {
  23122. warn('generateTexture has moved to the renderer, please use renderer.generateTexture(displayObject)');
  23123. return renderer.generateTexture(this, scaleMode, resolution);
  23124. };
  23125. core.Graphics.prototype.generateTexture = function generateTexture(scaleMode, resolution) {
  23126. warn('graphics generate texture has moved to the renderer. ' + 'Or to render a graphics to a texture using canvas please use generateCanvasTexture');
  23127. return this.generateCanvasTexture(scaleMode, resolution);
  23128. };
  23129. /**
  23130. * @method
  23131. * @name PIXI.GroupD8.isSwapWidthHeight
  23132. * @see PIXI.GroupD8.isVertical
  23133. * @param {number} rotation - The number to check.
  23134. * @returns {boolean} Whether or not the direction is vertical
  23135. * @deprecated since version 4.6.0
  23136. */
  23137. core.GroupD8.isSwapWidthHeight = function isSwapWidthHeight(rotation) {
  23138. warn('GroupD8.isSwapWidthHeight was renamed to GroupD8.isVertical');
  23139. return core.GroupD8.isVertical(rotation);
  23140. };
  23141. core.RenderTexture.prototype.render = function render(displayObject, matrix, clear, updateTransform) {
  23142. this.legacyRenderer.render(displayObject, this, clear, matrix, !updateTransform);
  23143. warn('RenderTexture.render is now deprecated, please use renderer.render(displayObject, renderTexture)');
  23144. };
  23145. core.RenderTexture.prototype.getImage = function getImage(target) {
  23146. warn('RenderTexture.getImage is now deprecated, please use renderer.extract.image(target)');
  23147. return this.legacyRenderer.extract.image(target);
  23148. };
  23149. core.RenderTexture.prototype.getBase64 = function getBase64(target) {
  23150. warn('RenderTexture.getBase64 is now deprecated, please use renderer.extract.base64(target)');
  23151. return this.legacyRenderer.extract.base64(target);
  23152. };
  23153. core.RenderTexture.prototype.getCanvas = function getCanvas(target) {
  23154. warn('RenderTexture.getCanvas is now deprecated, please use renderer.extract.canvas(target)');
  23155. return this.legacyRenderer.extract.canvas(target);
  23156. };
  23157. core.RenderTexture.prototype.getPixels = function getPixels(target) {
  23158. warn('RenderTexture.getPixels is now deprecated, please use renderer.extract.pixels(target)');
  23159. return this.legacyRenderer.pixels(target);
  23160. };
  23161. /**
  23162. * @method
  23163. * @private
  23164. * @name PIXI.Sprite#setTexture
  23165. * @see PIXI.Sprite#texture
  23166. * @deprecated since version 3.0.0
  23167. * @param {PIXI.Texture} texture - The texture to set to.
  23168. */
  23169. core.Sprite.prototype.setTexture = function setTexture(texture) {
  23170. this.texture = texture;
  23171. warn('setTexture is now deprecated, please use the texture property, e.g : sprite.texture = texture;');
  23172. };
  23173. if (extras.BitmapText) {
  23174. /**
  23175. * @method
  23176. * @name PIXI.extras.BitmapText#setText
  23177. * @see PIXI.extras.BitmapText#text
  23178. * @deprecated since version 3.0.0
  23179. * @param {string} text - The text to set to.
  23180. */
  23181. extras.BitmapText.prototype.setText = function setText(text) {
  23182. this.text = text;
  23183. warn('setText is now deprecated, please use the text property, e.g : myBitmapText.text = \'my text\';');
  23184. };
  23185. }
  23186. /**
  23187. * @method
  23188. * @name PIXI.Text#setText
  23189. * @see PIXI.Text#text
  23190. * @deprecated since version 3.0.0
  23191. * @param {string} text - The text to set to.
  23192. */
  23193. core.Text.prototype.setText = function setText(text) {
  23194. this.text = text;
  23195. warn('setText is now deprecated, please use the text property, e.g : myText.text = \'my text\';');
  23196. };
  23197. /**
  23198. * Calculates the ascent, descent and fontSize of a given fontStyle
  23199. *
  23200. * @name PIXI.Text.calculateFontProperties
  23201. * @see PIXI.TextMetrics.measureFont
  23202. * @deprecated since version 4.5.0
  23203. * @param {string} font - String representing the style of the font
  23204. * @return {Object} Font properties object
  23205. */
  23206. core.Text.calculateFontProperties = function calculateFontProperties(font) {
  23207. warn('Text.calculateFontProperties is now deprecated, please use the TextMetrics.measureFont');
  23208. return core.TextMetrics.measureFont(font);
  23209. };
  23210. Object.defineProperties(core.Text, {
  23211. fontPropertiesCache: {
  23212. get: function get() {
  23213. warn('Text.fontPropertiesCache is deprecated');
  23214. return core.TextMetrics._fonts;
  23215. }
  23216. },
  23217. fontPropertiesCanvas: {
  23218. get: function get() {
  23219. warn('Text.fontPropertiesCanvas is deprecated');
  23220. return core.TextMetrics._canvas;
  23221. }
  23222. },
  23223. fontPropertiesContext: {
  23224. get: function get() {
  23225. warn('Text.fontPropertiesContext is deprecated');
  23226. return core.TextMetrics._context;
  23227. }
  23228. }
  23229. });
  23230. /**
  23231. * @method
  23232. * @name PIXI.Text#setStyle
  23233. * @see PIXI.Text#style
  23234. * @deprecated since version 3.0.0
  23235. * @param {*} style - The style to set to.
  23236. */
  23237. core.Text.prototype.setStyle = function setStyle(style) {
  23238. this.style = style;
  23239. warn('setStyle is now deprecated, please use the style property, e.g : myText.style = style;');
  23240. };
  23241. /**
  23242. * @method
  23243. * @name PIXI.Text#determineFontProperties
  23244. * @see PIXI.Text#measureFontProperties
  23245. * @deprecated since version 4.2.0
  23246. * @private
  23247. * @param {string} fontStyle - String representing the style of the font
  23248. * @return {Object} Font properties object
  23249. */
  23250. core.Text.prototype.determineFontProperties = function determineFontProperties(fontStyle) {
  23251. warn('determineFontProperties is now deprecated, please use TextMetrics.measureFont method');
  23252. return core.TextMetrics.measureFont(fontStyle);
  23253. };
  23254. /**
  23255. * @method
  23256. * @name PIXI.Text.getFontStyle
  23257. * @see PIXI.TextMetrics.getFontStyle
  23258. * @deprecated since version 4.5.0
  23259. * @param {PIXI.TextStyle} style - The style to use.
  23260. * @return {string} Font string
  23261. */
  23262. core.Text.getFontStyle = function getFontStyle(style) {
  23263. warn('getFontStyle is now deprecated, please use TextStyle.toFontString() instead');
  23264. style = style || {};
  23265. if (!(style instanceof core.TextStyle)) {
  23266. style = new core.TextStyle(style);
  23267. }
  23268. return style.toFontString();
  23269. };
  23270. Object.defineProperties(core.TextStyle.prototype, {
  23271. /**
  23272. * Set all properties of a font as a single string
  23273. *
  23274. * @name PIXI.TextStyle#font
  23275. * @deprecated since version 4.0.0
  23276. */
  23277. font: {
  23278. get: function get() {
  23279. warn('text style property \'font\' is now deprecated, please use the ' + '\'fontFamily\', \'fontSize\', \'fontStyle\', \'fontVariant\' and \'fontWeight\' properties from now on');
  23280. var fontSizeString = typeof this._fontSize === 'number' ? this._fontSize + 'px' : this._fontSize;
  23281. return this._fontStyle + ' ' + this._fontVariant + ' ' + this._fontWeight + ' ' + fontSizeString + ' ' + this._fontFamily;
  23282. },
  23283. set: function set(font) {
  23284. warn('text style property \'font\' is now deprecated, please use the ' + '\'fontFamily\',\'fontSize\',fontStyle\',\'fontVariant\' and \'fontWeight\' properties from now on');
  23285. // can work out fontStyle from search of whole string
  23286. if (font.indexOf('italic') > 1) {
  23287. this._fontStyle = 'italic';
  23288. } else if (font.indexOf('oblique') > -1) {
  23289. this._fontStyle = 'oblique';
  23290. } else {
  23291. this._fontStyle = 'normal';
  23292. }
  23293. // can work out fontVariant from search of whole string
  23294. if (font.indexOf('small-caps') > -1) {
  23295. this._fontVariant = 'small-caps';
  23296. } else {
  23297. this._fontVariant = 'normal';
  23298. }
  23299. // fontWeight and fontFamily are tricker to find, but it's easier to find the fontSize due to it's units
  23300. var splits = font.split(' ');
  23301. var fontSizeIndex = -1;
  23302. this._fontSize = 26;
  23303. for (var i = 0; i < splits.length; ++i) {
  23304. if (splits[i].match(/(px|pt|em|%)/)) {
  23305. fontSizeIndex = i;
  23306. this._fontSize = splits[i];
  23307. break;
  23308. }
  23309. }
  23310. // we can now search for fontWeight as we know it must occur before the fontSize
  23311. this._fontWeight = 'normal';
  23312. for (var _i = 0; _i < fontSizeIndex; ++_i) {
  23313. if (splits[_i].match(/(bold|bolder|lighter|100|200|300|400|500|600|700|800|900)/)) {
  23314. this._fontWeight = splits[_i];
  23315. break;
  23316. }
  23317. }
  23318. // and finally join everything together after the fontSize in case the font family has multiple words
  23319. if (fontSizeIndex > -1 && fontSizeIndex < splits.length - 1) {
  23320. this._fontFamily = '';
  23321. for (var _i2 = fontSizeIndex + 1; _i2 < splits.length; ++_i2) {
  23322. this._fontFamily += splits[_i2] + ' ';
  23323. }
  23324. this._fontFamily = this._fontFamily.slice(0, -1);
  23325. } else {
  23326. this._fontFamily = 'Arial';
  23327. }
  23328. this.styleID++;
  23329. }
  23330. }
  23331. });
  23332. /**
  23333. * @method
  23334. * @name PIXI.Texture#setFrame
  23335. * @see PIXI.Texture#setFrame
  23336. * @deprecated since version 3.0.0
  23337. * @param {PIXI.Rectangle} frame - The frame to set.
  23338. */
  23339. core.Texture.prototype.setFrame = function setFrame(frame) {
  23340. this.frame = frame;
  23341. warn('setFrame is now deprecated, please use the frame property, e.g: myTexture.frame = frame;');
  23342. };
  23343. /**
  23344. * @static
  23345. * @function
  23346. * @name PIXI.Texture.addTextureToCache
  23347. * @see PIXI.Texture.addToCache
  23348. * @deprecated since 4.5.0
  23349. * @param {PIXI.Texture} texture - The Texture to add to the cache.
  23350. * @param {string} id - The id that the texture will be stored against.
  23351. */
  23352. core.Texture.addTextureToCache = function addTextureToCache(texture, id) {
  23353. core.Texture.addToCache(texture, id);
  23354. warn('Texture.addTextureToCache is deprecated, please use Texture.addToCache from now on.');
  23355. };
  23356. /**
  23357. * @static
  23358. * @function
  23359. * @name PIXI.Texture.removeTextureFromCache
  23360. * @see PIXI.Texture.removeFromCache
  23361. * @deprecated since 4.5.0
  23362. * @param {string} id - The id of the texture to be removed
  23363. * @return {PIXI.Texture|null} The texture that was removed
  23364. */
  23365. core.Texture.removeTextureFromCache = function removeTextureFromCache(id) {
  23366. warn('Texture.removeTextureFromCache is deprecated, please use Texture.removeFromCache from now on. ' + 'Be aware that Texture.removeFromCache does not automatically its BaseTexture from the BaseTextureCache. ' + 'For that, use BaseTexture.removeFromCache');
  23367. core.BaseTexture.removeFromCache(id);
  23368. return core.Texture.removeFromCache(id);
  23369. };
  23370. Object.defineProperties(filters, {
  23371. /**
  23372. * @class
  23373. * @private
  23374. * @name PIXI.filters.AbstractFilter
  23375. * @see PIXI.AbstractFilter
  23376. * @deprecated since version 3.0.6
  23377. */
  23378. AbstractFilter: {
  23379. get: function get() {
  23380. warn('AstractFilter has been renamed to Filter, please use PIXI.Filter');
  23381. return core.AbstractFilter;
  23382. }
  23383. },
  23384. /**
  23385. * @class
  23386. * @private
  23387. * @name PIXI.filters.SpriteMaskFilter
  23388. * @see PIXI.SpriteMaskFilter
  23389. * @deprecated since version 3.0.6
  23390. */
  23391. SpriteMaskFilter: {
  23392. get: function get() {
  23393. warn('filters.SpriteMaskFilter is an undocumented alias, please use SpriteMaskFilter from now on.');
  23394. return core.SpriteMaskFilter;
  23395. }
  23396. },
  23397. /**
  23398. * @class
  23399. * @private
  23400. * @name PIXI.filters.VoidFilter
  23401. * @see PIXI.filters.AlphaFilter
  23402. * @deprecated since version 4.5.7
  23403. */
  23404. VoidFilter: {
  23405. get: function get() {
  23406. warn('VoidFilter has been renamed to AlphaFilter, please use PIXI.filters.AlphaFilter');
  23407. return filters.AlphaFilter;
  23408. }
  23409. }
  23410. });
  23411. /**
  23412. * @method
  23413. * @name PIXI.utils.uuid
  23414. * @see PIXI.utils.uid
  23415. * @deprecated since version 3.0.6
  23416. * @return {number} The uid
  23417. */
  23418. core.utils.uuid = function () {
  23419. warn('utils.uuid() is deprecated, please use utils.uid() from now on.');
  23420. return core.utils.uid();
  23421. };
  23422. /**
  23423. * @method
  23424. * @name PIXI.utils.canUseNewCanvasBlendModes
  23425. * @see PIXI.CanvasTinter
  23426. * @deprecated
  23427. * @return {boolean} Can use blend modes.
  23428. */
  23429. core.utils.canUseNewCanvasBlendModes = function () {
  23430. warn('utils.canUseNewCanvasBlendModes() is deprecated, please use CanvasTinter.canUseMultiply from now on');
  23431. return core.CanvasTinter.canUseMultiply;
  23432. };
  23433. var saidHello = true;
  23434. /**
  23435. * @name PIXI.utils._saidHello
  23436. * @type {boolean}
  23437. * @see PIXI.utils.skipHello
  23438. * @deprecated since 4.1.0
  23439. */
  23440. Object.defineProperty(core.utils, '_saidHello', {
  23441. set: function set(bool) {
  23442. if (bool) {
  23443. warn('PIXI.utils._saidHello is deprecated, please use PIXI.utils.skipHello()');
  23444. this.skipHello();
  23445. }
  23446. saidHello = bool;
  23447. },
  23448. get: function get() {
  23449. return saidHello;
  23450. }
  23451. });
  23452. if (prepare.BasePrepare) {
  23453. /**
  23454. * @method
  23455. * @name PIXI.prepare.BasePrepare#register
  23456. * @see PIXI.prepare.BasePrepare#registerFindHook
  23457. * @deprecated since version 4.4.2
  23458. * @param {Function} [addHook] - Function call that takes two parameters: `item:*, queue:Array`
  23459. * function must return `true` if it was able to add item to the queue.
  23460. * @param {Function} [uploadHook] - Function call that takes two parameters: `prepare:CanvasPrepare, item:*` and
  23461. * function must return `true` if it was able to handle upload of item.
  23462. * @return {PIXI.BasePrepare} Instance of plugin for chaining.
  23463. */
  23464. prepare.BasePrepare.prototype.register = function register(addHook, uploadHook) {
  23465. warn('renderer.plugins.prepare.register is now deprecated, ' + 'please use renderer.plugins.prepare.registerFindHook & renderer.plugins.prepare.registerUploadHook');
  23466. if (addHook) {
  23467. this.registerFindHook(addHook);
  23468. }
  23469. if (uploadHook) {
  23470. this.registerUploadHook(uploadHook);
  23471. }
  23472. return this;
  23473. };
  23474. }
  23475. if (prepare.canvas) {
  23476. /**
  23477. * The number of graphics or textures to upload to the GPU.
  23478. *
  23479. * @name PIXI.prepare.canvas.UPLOADS_PER_FRAME
  23480. * @static
  23481. * @type {number}
  23482. * @see PIXI.prepare.BasePrepare.limiter
  23483. * @deprecated since 4.2.0
  23484. */
  23485. Object.defineProperty(prepare.canvas, 'UPLOADS_PER_FRAME', {
  23486. set: function set() {
  23487. warn('PIXI.CanvasPrepare.UPLOADS_PER_FRAME has been removed. Please set ' + 'renderer.plugins.prepare.limiter.maxItemsPerFrame on your renderer');
  23488. // because we don't have a reference to the renderer, we can't actually set
  23489. // the uploads per frame, so we'll have to stick with the warning.
  23490. },
  23491. get: function get() {
  23492. warn('PIXI.CanvasPrepare.UPLOADS_PER_FRAME has been removed. Please use ' + 'renderer.plugins.prepare.limiter');
  23493. return NaN;
  23494. }
  23495. });
  23496. }
  23497. if (prepare.webgl) {
  23498. /**
  23499. * The number of graphics or textures to upload to the GPU.
  23500. *
  23501. * @name PIXI.prepare.webgl.UPLOADS_PER_FRAME
  23502. * @static
  23503. * @type {number}
  23504. * @see PIXI.prepare.BasePrepare.limiter
  23505. * @deprecated since 4.2.0
  23506. */
  23507. Object.defineProperty(prepare.webgl, 'UPLOADS_PER_FRAME', {
  23508. set: function set() {
  23509. warn('PIXI.WebGLPrepare.UPLOADS_PER_FRAME has been removed. Please set ' + 'renderer.plugins.prepare.limiter.maxItemsPerFrame on your renderer');
  23510. // because we don't have a reference to the renderer, we can't actually set
  23511. // the uploads per frame, so we'll have to stick with the warning.
  23512. },
  23513. get: function get() {
  23514. warn('PIXI.WebGLPrepare.UPLOADS_PER_FRAME has been removed. Please use ' + 'renderer.plugins.prepare.limiter');
  23515. return NaN;
  23516. }
  23517. });
  23518. }
  23519. if (loaders.Loader) {
  23520. var Resource = loaders.Resource;
  23521. var Loader = loaders.Loader;
  23522. Object.defineProperties(Resource.prototype, {
  23523. isJson: {
  23524. get: function get() {
  23525. warn('The isJson property is deprecated, please use `resource.type === Resource.TYPE.JSON`.');
  23526. return this.type === Resource.TYPE.JSON;
  23527. }
  23528. },
  23529. isXml: {
  23530. get: function get() {
  23531. warn('The isXml property is deprecated, please use `resource.type === Resource.TYPE.XML`.');
  23532. return this.type === Resource.TYPE.XML;
  23533. }
  23534. },
  23535. isImage: {
  23536. get: function get() {
  23537. warn('The isImage property is deprecated, please use `resource.type === Resource.TYPE.IMAGE`.');
  23538. return this.type === Resource.TYPE.IMAGE;
  23539. }
  23540. },
  23541. isAudio: {
  23542. get: function get() {
  23543. warn('The isAudio property is deprecated, please use `resource.type === Resource.TYPE.AUDIO`.');
  23544. return this.type === Resource.TYPE.AUDIO;
  23545. }
  23546. },
  23547. isVideo: {
  23548. get: function get() {
  23549. warn('The isVideo property is deprecated, please use `resource.type === Resource.TYPE.VIDEO`.');
  23550. return this.type === Resource.TYPE.VIDEO;
  23551. }
  23552. }
  23553. });
  23554. Object.defineProperties(Loader.prototype, {
  23555. before: {
  23556. get: function get() {
  23557. warn('The before() method is deprecated, please use pre().');
  23558. return this.pre;
  23559. }
  23560. },
  23561. after: {
  23562. get: function get() {
  23563. warn('The after() method is deprecated, please use use().');
  23564. return this.use;
  23565. }
  23566. }
  23567. });
  23568. }
  23569. if (interaction.interactiveTarget) {
  23570. /**
  23571. * @name PIXI.interaction.interactiveTarget#defaultCursor
  23572. * @static
  23573. * @type {number}
  23574. * @see PIXI.interaction.interactiveTarget#cursor
  23575. * @deprecated since 4.3.0
  23576. */
  23577. Object.defineProperty(interaction.interactiveTarget, 'defaultCursor', {
  23578. set: function set(value) {
  23579. warn('Property defaultCursor has been replaced with \'cursor\'. ');
  23580. this.cursor = value;
  23581. },
  23582. get: function get() {
  23583. warn('Property defaultCursor has been replaced with \'cursor\'. ');
  23584. return this.cursor;
  23585. }
  23586. });
  23587. }
  23588. if (interaction.InteractionManager) {
  23589. /**
  23590. * @name PIXI.interaction.InteractionManager#defaultCursorStyle
  23591. * @static
  23592. * @type {string}
  23593. * @see PIXI.interaction.InteractionManager#cursorStyles
  23594. * @deprecated since 4.3.0
  23595. */
  23596. Object.defineProperty(interaction.InteractionManager, 'defaultCursorStyle', {
  23597. set: function set(value) {
  23598. warn('Property defaultCursorStyle has been replaced with \'cursorStyles.default\'. ');
  23599. this.cursorStyles.default = value;
  23600. },
  23601. get: function get() {
  23602. warn('Property defaultCursorStyle has been replaced with \'cursorStyles.default\'. ');
  23603. return this.cursorStyles.default;
  23604. }
  23605. });
  23606. /**
  23607. * @name PIXI.interaction.InteractionManager#currentCursorStyle
  23608. * @static
  23609. * @type {string}
  23610. * @see PIXI.interaction.InteractionManager#cursorStyles
  23611. * @deprecated since 4.3.0
  23612. */
  23613. Object.defineProperty(interaction.InteractionManager, 'currentCursorStyle', {
  23614. set: function set(value) {
  23615. warn('Property currentCursorStyle has been removed.' + 'See the currentCursorMode property, which works differently.');
  23616. this.currentCursorMode = value;
  23617. },
  23618. get: function get() {
  23619. warn('Property currentCursorStyle has been removed.' + 'See the currentCursorMode property, which works differently.');
  23620. return this.currentCursorMode;
  23621. }
  23622. });
  23623. }
  23624. }
  23625. }, {}], 132: [function (require, module, exports) {
  23626. 'use strict';
  23627. exports.__esModule = true;
  23628. var _core = require('../../core');
  23629. var core = _interopRequireWildcard(_core);
  23630. function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
  23631. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  23632. var TEMP_RECT = new core.Rectangle();
  23633. /**
  23634. * The extract manager provides functionality to export content from the renderers.
  23635. *
  23636. * An instance of this class is automatically created by default, and can be found at renderer.plugins.extract
  23637. *
  23638. * @class
  23639. * @memberof PIXI.extract
  23640. */
  23641. var CanvasExtract = function () {
  23642. /**
  23643. * @param {PIXI.CanvasRenderer} renderer - A reference to the current renderer
  23644. */
  23645. function CanvasExtract(renderer) {
  23646. _classCallCheck(this, CanvasExtract);
  23647. this.renderer = renderer;
  23648. /**
  23649. * Collection of methods for extracting data (image, pixels, etc.) from a display object or render texture
  23650. *
  23651. * @member {PIXI.extract.CanvasExtract} extract
  23652. * @memberof PIXI.CanvasRenderer#
  23653. * @see PIXI.extract.CanvasExtract
  23654. */
  23655. renderer.extract = this;
  23656. }
  23657. /**
  23658. * Will return a HTML Image of the target
  23659. *
  23660. * @param {PIXI.DisplayObject|PIXI.RenderTexture} target - A displayObject or renderTexture
  23661. * to convert. If left empty will use use the main renderer
  23662. * @return {HTMLImageElement} HTML Image of the target
  23663. */
  23664. CanvasExtract.prototype.image = function image(target) {
  23665. var image = new Image();
  23666. image.src = this.base64(target);
  23667. return image;
  23668. };
  23669. /**
  23670. * Will return a a base64 encoded string of this target. It works by calling
  23671. * `CanvasExtract.getCanvas` and then running toDataURL on that.
  23672. *
  23673. * @param {PIXI.DisplayObject|PIXI.RenderTexture} target - A displayObject or renderTexture
  23674. * to convert. If left empty will use use the main renderer
  23675. * @return {string} A base64 encoded string of the texture.
  23676. */
  23677. CanvasExtract.prototype.base64 = function base64(target) {
  23678. return this.canvas(target).toDataURL();
  23679. };
  23680. /**
  23681. * Creates a Canvas element, renders this target to it and then returns it.
  23682. *
  23683. * @param {PIXI.DisplayObject|PIXI.RenderTexture} target - A displayObject or renderTexture
  23684. * to convert. If left empty will use use the main renderer
  23685. * @return {HTMLCanvasElement} A Canvas element with the texture rendered on.
  23686. */
  23687. CanvasExtract.prototype.canvas = function canvas(target) {
  23688. var renderer = this.renderer;
  23689. var context = void 0;
  23690. var resolution = void 0;
  23691. var frame = void 0;
  23692. var renderTexture = void 0;
  23693. if (target) {
  23694. if (target instanceof core.RenderTexture) {
  23695. renderTexture = target;
  23696. } else {
  23697. renderTexture = renderer.generateTexture(target);
  23698. }
  23699. }
  23700. if (renderTexture) {
  23701. context = renderTexture.baseTexture._canvasRenderTarget.context;
  23702. resolution = renderTexture.baseTexture._canvasRenderTarget.resolution;
  23703. frame = renderTexture.frame;
  23704. } else {
  23705. context = renderer.rootContext;
  23706. frame = TEMP_RECT;
  23707. frame.width = this.renderer.width;
  23708. frame.height = this.renderer.height;
  23709. }
  23710. var width = frame.width * resolution;
  23711. var height = frame.height * resolution;
  23712. var canvasBuffer = new core.CanvasRenderTarget(width, height);
  23713. var canvasData = context.getImageData(frame.x * resolution, frame.y * resolution, width, height);
  23714. canvasBuffer.context.putImageData(canvasData, 0, 0);
  23715. // send the canvas back..
  23716. return canvasBuffer.canvas;
  23717. };
  23718. /**
  23719. * Will return a one-dimensional array containing the pixel data of the entire texture in RGBA
  23720. * order, with integer values between 0 and 255 (included).
  23721. *
  23722. * @param {PIXI.DisplayObject|PIXI.RenderTexture} target - A displayObject or renderTexture
  23723. * to convert. If left empty will use use the main renderer
  23724. * @return {Uint8ClampedArray} One-dimensional array containing the pixel data of the entire texture
  23725. */
  23726. CanvasExtract.prototype.pixels = function pixels(target) {
  23727. var renderer = this.renderer;
  23728. var context = void 0;
  23729. var resolution = void 0;
  23730. var frame = void 0;
  23731. var renderTexture = void 0;
  23732. if (target) {
  23733. if (target instanceof core.RenderTexture) {
  23734. renderTexture = target;
  23735. } else {
  23736. renderTexture = renderer.generateTexture(target);
  23737. }
  23738. }
  23739. if (renderTexture) {
  23740. context = renderTexture.baseTexture._canvasRenderTarget.context;
  23741. resolution = renderTexture.baseTexture._canvasRenderTarget.resolution;
  23742. frame = renderTexture.frame;
  23743. } else {
  23744. context = renderer.rootContext;
  23745. frame = TEMP_RECT;
  23746. frame.width = renderer.width;
  23747. frame.height = renderer.height;
  23748. }
  23749. return context.getImageData(0, 0, frame.width * resolution, frame.height * resolution).data;
  23750. };
  23751. /**
  23752. * Destroys the extract
  23753. *
  23754. */
  23755. CanvasExtract.prototype.destroy = function destroy() {
  23756. this.renderer.extract = null;
  23757. this.renderer = null;
  23758. };
  23759. return CanvasExtract;
  23760. }();
  23761. exports.default = CanvasExtract;
  23762. core.CanvasRenderer.registerPlugin('extract', CanvasExtract);
  23763. }, { "../../core": 65 }], 133: [function (require, module, exports) {
  23764. 'use strict';
  23765. exports.__esModule = true;
  23766. var _WebGLExtract = require('./webgl/WebGLExtract');
  23767. Object.defineProperty(exports, 'webgl', {
  23768. enumerable: true,
  23769. get: function get() {
  23770. return _interopRequireDefault(_WebGLExtract).default;
  23771. }
  23772. });
  23773. var _CanvasExtract = require('./canvas/CanvasExtract');
  23774. Object.defineProperty(exports, 'canvas', {
  23775. enumerable: true,
  23776. get: function get() {
  23777. return _interopRequireDefault(_CanvasExtract).default;
  23778. }
  23779. });
  23780. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  23781. }, { "./canvas/CanvasExtract": 132, "./webgl/WebGLExtract": 134 }], 134: [function (require, module, exports) {
  23782. 'use strict';
  23783. exports.__esModule = true;
  23784. var _core = require('../../core');
  23785. var core = _interopRequireWildcard(_core);
  23786. function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
  23787. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  23788. var TEMP_RECT = new core.Rectangle();
  23789. var BYTES_PER_PIXEL = 4;
  23790. /**
  23791. * The extract manager provides functionality to export content from the renderers.
  23792. *
  23793. * An instance of this class is automatically created by default, and can be found at renderer.plugins.extract
  23794. *
  23795. * @class
  23796. * @memberof PIXI.extract
  23797. */
  23798. var WebGLExtract = function () {
  23799. /**
  23800. * @param {PIXI.WebGLRenderer} renderer - A reference to the current renderer
  23801. */
  23802. function WebGLExtract(renderer) {
  23803. _classCallCheck(this, WebGLExtract);
  23804. this.renderer = renderer;
  23805. /**
  23806. * Collection of methods for extracting data (image, pixels, etc.) from a display object or render texture
  23807. *
  23808. * @member {PIXI.extract.WebGLExtract} extract
  23809. * @memberof PIXI.WebGLRenderer#
  23810. * @see PIXI.extract.WebGLExtract
  23811. */
  23812. renderer.extract = this;
  23813. }
  23814. /**
  23815. * Will return a HTML Image of the target
  23816. *
  23817. * @param {PIXI.DisplayObject|PIXI.RenderTexture} target - A displayObject or renderTexture
  23818. * to convert. If left empty will use use the main renderer
  23819. * @return {HTMLImageElement} HTML Image of the target
  23820. */
  23821. WebGLExtract.prototype.image = function image(target) {
  23822. var image = new Image();
  23823. image.src = this.base64(target);
  23824. return image;
  23825. };
  23826. /**
  23827. * Will return a a base64 encoded string of this target. It works by calling
  23828. * `WebGLExtract.getCanvas` and then running toDataURL on that.
  23829. *
  23830. * @param {PIXI.DisplayObject|PIXI.RenderTexture} target - A displayObject or renderTexture
  23831. * to convert. If left empty will use use the main renderer
  23832. * @return {string} A base64 encoded string of the texture.
  23833. */
  23834. WebGLExtract.prototype.base64 = function base64(target) {
  23835. return this.canvas(target).toDataURL();
  23836. };
  23837. /**
  23838. * Creates a Canvas element, renders this target to it and then returns it.
  23839. *
  23840. * @param {PIXI.DisplayObject|PIXI.RenderTexture} target - A displayObject or renderTexture
  23841. * to convert. If left empty will use use the main renderer
  23842. * @return {HTMLCanvasElement} A Canvas element with the texture rendered on.
  23843. */
  23844. WebGLExtract.prototype.canvas = function canvas(target) {
  23845. var renderer = this.renderer;
  23846. var textureBuffer = void 0;
  23847. var resolution = void 0;
  23848. var frame = void 0;
  23849. var flipY = false;
  23850. var renderTexture = void 0;
  23851. var generated = false;
  23852. if (target) {
  23853. if (target instanceof core.RenderTexture) {
  23854. renderTexture = target;
  23855. } else {
  23856. renderTexture = this.renderer.generateTexture(target);
  23857. generated = true;
  23858. }
  23859. }
  23860. if (renderTexture) {
  23861. textureBuffer = renderTexture.baseTexture._glRenderTargets[this.renderer.CONTEXT_UID];
  23862. resolution = textureBuffer.resolution;
  23863. frame = renderTexture.frame;
  23864. flipY = false;
  23865. } else {
  23866. textureBuffer = this.renderer.rootRenderTarget;
  23867. resolution = textureBuffer.resolution;
  23868. flipY = true;
  23869. frame = TEMP_RECT;
  23870. frame.width = textureBuffer.size.width;
  23871. frame.height = textureBuffer.size.height;
  23872. }
  23873. var width = frame.width * resolution;
  23874. var height = frame.height * resolution;
  23875. var canvasBuffer = new core.CanvasRenderTarget(width, height);
  23876. if (textureBuffer) {
  23877. // bind the buffer
  23878. renderer.bindRenderTarget(textureBuffer);
  23879. // set up an array of pixels
  23880. var webglPixels = new Uint8Array(BYTES_PER_PIXEL * width * height);
  23881. // read pixels to the array
  23882. var gl = renderer.gl;
  23883. gl.readPixels(frame.x * resolution, frame.y * resolution, width, height, gl.RGBA, gl.UNSIGNED_BYTE, webglPixels);
  23884. // add the pixels to the canvas
  23885. var canvasData = canvasBuffer.context.getImageData(0, 0, width, height);
  23886. canvasData.data.set(webglPixels);
  23887. canvasBuffer.context.putImageData(canvasData, 0, 0);
  23888. // pulling pixels
  23889. if (flipY) {
  23890. canvasBuffer.context.scale(1, -1);
  23891. canvasBuffer.context.drawImage(canvasBuffer.canvas, 0, -height);
  23892. }
  23893. }
  23894. if (generated) {
  23895. renderTexture.destroy(true);
  23896. }
  23897. // send the canvas back..
  23898. return canvasBuffer.canvas;
  23899. };
  23900. /**
  23901. * Will return a one-dimensional array containing the pixel data of the entire texture in RGBA
  23902. * order, with integer values between 0 and 255 (included).
  23903. *
  23904. * @param {PIXI.DisplayObject|PIXI.RenderTexture} target - A displayObject or renderTexture
  23905. * to convert. If left empty will use use the main renderer
  23906. * @return {Uint8ClampedArray} One-dimensional array containing the pixel data of the entire texture
  23907. */
  23908. WebGLExtract.prototype.pixels = function pixels(target) {
  23909. var renderer = this.renderer;
  23910. var textureBuffer = void 0;
  23911. var resolution = void 0;
  23912. var frame = void 0;
  23913. var renderTexture = void 0;
  23914. var generated = false;
  23915. if (target) {
  23916. if (target instanceof core.RenderTexture) {
  23917. renderTexture = target;
  23918. } else {
  23919. renderTexture = this.renderer.generateTexture(target);
  23920. generated = true;
  23921. }
  23922. }
  23923. if (renderTexture) {
  23924. textureBuffer = renderTexture.baseTexture._glRenderTargets[this.renderer.CONTEXT_UID];
  23925. resolution = textureBuffer.resolution;
  23926. frame = renderTexture.frame;
  23927. } else {
  23928. textureBuffer = this.renderer.rootRenderTarget;
  23929. resolution = textureBuffer.resolution;
  23930. frame = TEMP_RECT;
  23931. frame.width = textureBuffer.size.width;
  23932. frame.height = textureBuffer.size.height;
  23933. }
  23934. var width = frame.width * resolution;
  23935. var height = frame.height * resolution;
  23936. var webglPixels = new Uint8Array(BYTES_PER_PIXEL * width * height);
  23937. if (textureBuffer) {
  23938. // bind the buffer
  23939. renderer.bindRenderTarget(textureBuffer);
  23940. // read pixels to the array
  23941. var gl = renderer.gl;
  23942. gl.readPixels(frame.x * resolution, frame.y * resolution, width, height, gl.RGBA, gl.UNSIGNED_BYTE, webglPixels);
  23943. }
  23944. if (generated) {
  23945. renderTexture.destroy(true);
  23946. }
  23947. return webglPixels;
  23948. };
  23949. /**
  23950. * Destroys the extract
  23951. *
  23952. */
  23953. WebGLExtract.prototype.destroy = function destroy() {
  23954. this.renderer.extract = null;
  23955. this.renderer = null;
  23956. };
  23957. return WebGLExtract;
  23958. }();
  23959. exports.default = WebGLExtract;
  23960. core.WebGLRenderer.registerPlugin('extract', WebGLExtract);
  23961. }, { "../../core": 65 }], 135: [function (require, module, exports) {
  23962. 'use strict';
  23963. exports.__esModule = true;
  23964. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  23965. var _core = require('../core');
  23966. var core = _interopRequireWildcard(_core);
  23967. function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
  23968. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  23969. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  23970. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  23971. /**
  23972. * @typedef PIXI.extras.AnimatedSprite~FrameObject
  23973. * @type {object}
  23974. * @property {PIXI.Texture} texture - The {@link PIXI.Texture} of the frame
  23975. * @property {number} time - the duration of the frame in ms
  23976. */
  23977. /**
  23978. * An AnimatedSprite is a simple way to display an animation depicted by a list of textures.
  23979. *
  23980. * ```js
  23981. * let alienImages = ["image_sequence_01.png","image_sequence_02.png","image_sequence_03.png","image_sequence_04.png"];
  23982. * let textureArray = [];
  23983. *
  23984. * for (let i=0; i < 4; i++)
  23985. * {
  23986. * let texture = PIXI.Texture.fromImage(alienImages[i]);
  23987. * textureArray.push(texture);
  23988. * };
  23989. *
  23990. * let mc = new PIXI.AnimatedSprite(textureArray);
  23991. * ```
  23992. *
  23993. * @class
  23994. * @extends PIXI.Sprite
  23995. * @memberof PIXI.extras
  23996. */
  23997. var AnimatedSprite = function (_core$Sprite) {
  23998. _inherits(AnimatedSprite, _core$Sprite);
  23999. /**
  24000. * @param {PIXI.Texture[]|PIXI.extras.AnimatedSprite~FrameObject[]} textures - an array of {@link PIXI.Texture} or frame
  24001. * objects that make up the animation
  24002. * @param {boolean} [autoUpdate=true] - Whether to use PIXI.ticker.shared to auto update animation time.
  24003. */
  24004. function AnimatedSprite(textures, autoUpdate) {
  24005. _classCallCheck(this, AnimatedSprite);
  24006. /**
  24007. * @private
  24008. */
  24009. var _this = _possibleConstructorReturn(this, _core$Sprite.call(this, textures[0] instanceof core.Texture ? textures[0] : textures[0].texture));
  24010. _this._textures = null;
  24011. /**
  24012. * @private
  24013. */
  24014. _this._durations = null;
  24015. _this.textures = textures;
  24016. /**
  24017. * `true` uses PIXI.ticker.shared to auto update animation time.
  24018. * @type {boolean}
  24019. * @default true
  24020. * @private
  24021. */
  24022. _this._autoUpdate = autoUpdate !== false;
  24023. /**
  24024. * The speed that the AnimatedSprite will play at. Higher is faster, lower is slower
  24025. *
  24026. * @member {number}
  24027. * @default 1
  24028. */
  24029. _this.animationSpeed = 1;
  24030. /**
  24031. * Whether or not the animate sprite repeats after playing.
  24032. *
  24033. * @member {boolean}
  24034. * @default true
  24035. */
  24036. _this.loop = true;
  24037. /**
  24038. * Function to call when a AnimatedSprite finishes playing
  24039. *
  24040. * @member {Function}
  24041. */
  24042. _this.onComplete = null;
  24043. /**
  24044. * Function to call when a AnimatedSprite changes which texture is being rendered
  24045. *
  24046. * @member {Function}
  24047. */
  24048. _this.onFrameChange = null;
  24049. /**
  24050. * Function to call when 'loop' is true, and an AnimatedSprite is played and loops around to start again
  24051. *
  24052. * @member {Function}
  24053. */
  24054. _this.onLoop = null;
  24055. /**
  24056. * Elapsed time since animation has been started, used internally to display current texture
  24057. *
  24058. * @member {number}
  24059. * @private
  24060. */
  24061. _this._currentTime = 0;
  24062. /**
  24063. * Indicates if the AnimatedSprite is currently playing
  24064. *
  24065. * @member {boolean}
  24066. * @readonly
  24067. */
  24068. _this.playing = false;
  24069. return _this;
  24070. }
  24071. /**
  24072. * Stops the AnimatedSprite
  24073. *
  24074. */
  24075. AnimatedSprite.prototype.stop = function stop() {
  24076. if (!this.playing) {
  24077. return;
  24078. }
  24079. this.playing = false;
  24080. if (this._autoUpdate) {
  24081. core.ticker.shared.remove(this.update, this);
  24082. }
  24083. };
  24084. /**
  24085. * Plays the AnimatedSprite
  24086. *
  24087. */
  24088. AnimatedSprite.prototype.play = function play() {
  24089. if (this.playing) {
  24090. return;
  24091. }
  24092. this.playing = true;
  24093. if (this._autoUpdate) {
  24094. core.ticker.shared.add(this.update, this, core.UPDATE_PRIORITY.HIGH);
  24095. }
  24096. };
  24097. /**
  24098. * Stops the AnimatedSprite and goes to a specific frame
  24099. *
  24100. * @param {number} frameNumber - frame index to stop at
  24101. */
  24102. AnimatedSprite.prototype.gotoAndStop = function gotoAndStop(frameNumber) {
  24103. this.stop();
  24104. var previousFrame = this.currentFrame;
  24105. this._currentTime = frameNumber;
  24106. if (previousFrame !== this.currentFrame) {
  24107. this.updateTexture();
  24108. }
  24109. };
  24110. /**
  24111. * Goes to a specific frame and begins playing the AnimatedSprite
  24112. *
  24113. * @param {number} frameNumber - frame index to start at
  24114. */
  24115. AnimatedSprite.prototype.gotoAndPlay = function gotoAndPlay(frameNumber) {
  24116. var previousFrame = this.currentFrame;
  24117. this._currentTime = frameNumber;
  24118. if (previousFrame !== this.currentFrame) {
  24119. this.updateTexture();
  24120. }
  24121. this.play();
  24122. };
  24123. /**
  24124. * Updates the object transform for rendering.
  24125. *
  24126. * @private
  24127. * @param {number} deltaTime - Time since last tick.
  24128. */
  24129. AnimatedSprite.prototype.update = function update(deltaTime) {
  24130. var elapsed = this.animationSpeed * deltaTime;
  24131. var previousFrame = this.currentFrame;
  24132. if (this._durations !== null) {
  24133. var lag = this._currentTime % 1 * this._durations[this.currentFrame];
  24134. lag += elapsed / 60 * 1000;
  24135. while (lag < 0) {
  24136. this._currentTime--;
  24137. lag += this._durations[this.currentFrame];
  24138. }
  24139. var sign = Math.sign(this.animationSpeed * deltaTime);
  24140. this._currentTime = Math.floor(this._currentTime);
  24141. while (lag >= this._durations[this.currentFrame]) {
  24142. lag -= this._durations[this.currentFrame] * sign;
  24143. this._currentTime += sign;
  24144. }
  24145. this._currentTime += lag / this._durations[this.currentFrame];
  24146. } else {
  24147. this._currentTime += elapsed;
  24148. }
  24149. if (this._currentTime < 0 && !this.loop) {
  24150. this.gotoAndStop(0);
  24151. if (this.onComplete) {
  24152. this.onComplete();
  24153. }
  24154. } else if (this._currentTime >= this._textures.length && !this.loop) {
  24155. this.gotoAndStop(this._textures.length - 1);
  24156. if (this.onComplete) {
  24157. this.onComplete();
  24158. }
  24159. } else if (previousFrame !== this.currentFrame) {
  24160. if (this.loop && this.onLoop) {
  24161. if (this.animationSpeed > 0 && this.currentFrame < previousFrame) {
  24162. this.onLoop();
  24163. } else if (this.animationSpeed < 0 && this.currentFrame > previousFrame) {
  24164. this.onLoop();
  24165. }
  24166. }
  24167. this.updateTexture();
  24168. }
  24169. };
  24170. /**
  24171. * Updates the displayed texture to match the current frame index
  24172. *
  24173. * @private
  24174. */
  24175. AnimatedSprite.prototype.updateTexture = function updateTexture() {
  24176. this._texture = this._textures[this.currentFrame];
  24177. this._textureID = -1;
  24178. this.cachedTint = 0xFFFFFF;
  24179. if (this.onFrameChange) {
  24180. this.onFrameChange(this.currentFrame);
  24181. }
  24182. };
  24183. /**
  24184. * Stops the AnimatedSprite and destroys it
  24185. *
  24186. * @param {object|boolean} [options] - Options parameter. A boolean will act as if all options
  24187. * have been set to that value
  24188. * @param {boolean} [options.children=false] - if set to true, all the children will have their destroy
  24189. * method called as well. 'options' will be passed on to those calls.
  24190. * @param {boolean} [options.texture=false] - Should it destroy the current texture of the sprite as well
  24191. * @param {boolean} [options.baseTexture=false] - Should it destroy the base texture of the sprite as well
  24192. */
  24193. AnimatedSprite.prototype.destroy = function destroy(options) {
  24194. this.stop();
  24195. _core$Sprite.prototype.destroy.call(this, options);
  24196. };
  24197. /**
  24198. * A short hand way of creating a movieclip from an array of frame ids
  24199. *
  24200. * @static
  24201. * @param {string[]} frames - The array of frames ids the movieclip will use as its texture frames
  24202. * @return {AnimatedSprite} The new animated sprite with the specified frames.
  24203. */
  24204. AnimatedSprite.fromFrames = function fromFrames(frames) {
  24205. var textures = [];
  24206. for (var i = 0; i < frames.length; ++i) {
  24207. textures.push(core.Texture.fromFrame(frames[i]));
  24208. }
  24209. return new AnimatedSprite(textures);
  24210. };
  24211. /**
  24212. * A short hand way of creating a movieclip from an array of image ids
  24213. *
  24214. * @static
  24215. * @param {string[]} images - the array of image urls the movieclip will use as its texture frames
  24216. * @return {AnimatedSprite} The new animate sprite with the specified images as frames.
  24217. */
  24218. AnimatedSprite.fromImages = function fromImages(images) {
  24219. var textures = [];
  24220. for (var i = 0; i < images.length; ++i) {
  24221. textures.push(core.Texture.fromImage(images[i]));
  24222. }
  24223. return new AnimatedSprite(textures);
  24224. };
  24225. /**
  24226. * totalFrames is the total number of frames in the AnimatedSprite. This is the same as number of textures
  24227. * assigned to the AnimatedSprite.
  24228. *
  24229. * @readonly
  24230. * @member {number}
  24231. * @default 0
  24232. */
  24233. _createClass(AnimatedSprite, [{
  24234. key: 'totalFrames',
  24235. get: function get() {
  24236. return this._textures.length;
  24237. }
  24238. /**
  24239. * The array of textures used for this AnimatedSprite
  24240. *
  24241. * @member {PIXI.Texture[]}
  24242. */
  24243. }, {
  24244. key: 'textures',
  24245. get: function get() {
  24246. return this._textures;
  24247. },
  24248. set: function set(value) // eslint-disable-line require-jsdoc
  24249. {
  24250. if (value[0] instanceof core.Texture) {
  24251. this._textures = value;
  24252. this._durations = null;
  24253. } else {
  24254. this._textures = [];
  24255. this._durations = [];
  24256. for (var i = 0; i < value.length; i++) {
  24257. this._textures.push(value[i].texture);
  24258. this._durations.push(value[i].time);
  24259. }
  24260. }
  24261. this.gotoAndStop(0);
  24262. this.updateTexture();
  24263. }
  24264. /**
  24265. * The AnimatedSprites current frame index
  24266. *
  24267. * @member {number}
  24268. * @readonly
  24269. */
  24270. }, {
  24271. key: 'currentFrame',
  24272. get: function get() {
  24273. var currentFrame = Math.floor(this._currentTime) % this._textures.length;
  24274. if (currentFrame < 0) {
  24275. currentFrame += this._textures.length;
  24276. }
  24277. return currentFrame;
  24278. }
  24279. }]);
  24280. return AnimatedSprite;
  24281. }(core.Sprite);
  24282. exports.default = AnimatedSprite;
  24283. }, { "../core": 65 }], 136: [function (require, module, exports) {
  24284. 'use strict';
  24285. exports.__esModule = true;
  24286. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  24287. var _core = require('../core');
  24288. var core = _interopRequireWildcard(_core);
  24289. var _ObservablePoint = require('../core/math/ObservablePoint');
  24290. var _ObservablePoint2 = _interopRequireDefault(_ObservablePoint);
  24291. var _utils = require('../core/utils');
  24292. var _settings = require('../core/settings');
  24293. var _settings2 = _interopRequireDefault(_settings);
  24294. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  24295. function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
  24296. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  24297. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  24298. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  24299. /**
  24300. * A BitmapText object will create a line or multiple lines of text using bitmap font. To
  24301. * split a line you can use '\n', '\r' or '\r\n' in your string. You can generate the fnt files using:
  24302. *
  24303. * A BitmapText can only be created when the font is loaded
  24304. *
  24305. * ```js
  24306. * // in this case the font is in a file called 'desyrel.fnt'
  24307. * let bitmapText = new PIXI.extras.BitmapText("text using a fancy font!", {font: "35px Desyrel", align: "right"});
  24308. * ```
  24309. *
  24310. * http://www.angelcode.com/products/bmfont/ for windows or
  24311. * http://www.bmglyph.com/ for mac.
  24312. *
  24313. * @class
  24314. * @extends PIXI.Container
  24315. * @memberof PIXI.extras
  24316. */
  24317. var BitmapText = function (_core$Container) {
  24318. _inherits(BitmapText, _core$Container);
  24319. /**
  24320. * @param {string} text - The copy that you would like the text to display
  24321. * @param {object} style - The style parameters
  24322. * @param {string|object} style.font - The font descriptor for the object, can be passed as a string of form
  24323. * "24px FontName" or "FontName" or as an object with explicit name/size properties.
  24324. * @param {string} [style.font.name] - The bitmap font id
  24325. * @param {number} [style.font.size] - The size of the font in pixels, e.g. 24
  24326. * @param {string} [style.align='left'] - Alignment for multiline text ('left', 'center' or 'right'), does not affect
  24327. * single line text
  24328. * @param {number} [style.tint=0xFFFFFF] - The tint color
  24329. */
  24330. function BitmapText(text) {
  24331. var style = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  24332. _classCallCheck(this, BitmapText);
  24333. /**
  24334. * Private tracker for the width of the overall text
  24335. *
  24336. * @member {number}
  24337. * @private
  24338. */
  24339. var _this = _possibleConstructorReturn(this, _core$Container.call(this));
  24340. _this._textWidth = 0;
  24341. /**
  24342. * Private tracker for the height of the overall text
  24343. *
  24344. * @member {number}
  24345. * @private
  24346. */
  24347. _this._textHeight = 0;
  24348. /**
  24349. * Private tracker for the letter sprite pool.
  24350. *
  24351. * @member {PIXI.Sprite[]}
  24352. * @private
  24353. */
  24354. _this._glyphs = [];
  24355. /**
  24356. * Private tracker for the current style.
  24357. *
  24358. * @member {object}
  24359. * @private
  24360. */
  24361. _this._font = {
  24362. tint: style.tint !== undefined ? style.tint : 0xFFFFFF,
  24363. align: style.align || 'left',
  24364. name: null,
  24365. size: 0
  24366. };
  24367. /**
  24368. * Private tracker for the current font.
  24369. *
  24370. * @member {object}
  24371. * @private
  24372. */
  24373. _this.font = style.font; // run font setter
  24374. /**
  24375. * Private tracker for the current text.
  24376. *
  24377. * @member {string}
  24378. * @private
  24379. */
  24380. _this._text = text;
  24381. /**
  24382. * The max width of this bitmap text in pixels. If the text provided is longer than the
  24383. * value provided, line breaks will be automatically inserted in the last whitespace.
  24384. * Disable by setting value to 0
  24385. *
  24386. * @member {number}
  24387. * @private
  24388. */
  24389. _this._maxWidth = 0;
  24390. /**
  24391. * The max line height. This is useful when trying to use the total height of the Text,
  24392. * ie: when trying to vertically align.
  24393. *
  24394. * @member {number}
  24395. * @private
  24396. */
  24397. _this._maxLineHeight = 0;
  24398. /**
  24399. * Text anchor. read-only
  24400. *
  24401. * @member {PIXI.ObservablePoint}
  24402. * @private
  24403. */
  24404. _this._anchor = new _ObservablePoint2.default(function () {
  24405. _this.dirty = true;
  24406. }, _this, 0, 0);
  24407. /**
  24408. * The dirty state of this object.
  24409. *
  24410. * @member {boolean}
  24411. */
  24412. _this.dirty = false;
  24413. _this.updateText();
  24414. return _this;
  24415. }
  24416. /**
  24417. * Renders text and updates it when needed
  24418. *
  24419. * @private
  24420. */
  24421. BitmapText.prototype.updateText = function updateText() {
  24422. var data = BitmapText.fonts[this._font.name];
  24423. var scale = this._font.size / data.size;
  24424. var pos = new core.Point();
  24425. var chars = [];
  24426. var lineWidths = [];
  24427. var prevCharCode = null;
  24428. var lastLineWidth = 0;
  24429. var maxLineWidth = 0;
  24430. var line = 0;
  24431. var lastSpace = -1;
  24432. var lastSpaceWidth = 0;
  24433. var spacesRemoved = 0;
  24434. var maxLineHeight = 0;
  24435. for (var i = 0; i < this.text.length; i++) {
  24436. var charCode = this.text.charCodeAt(i);
  24437. if (/(\s)/.test(this.text.charAt(i))) {
  24438. lastSpace = i;
  24439. lastSpaceWidth = lastLineWidth;
  24440. }
  24441. if (/(?:\r\n|\r|\n)/.test(this.text.charAt(i))) {
  24442. lineWidths.push(lastLineWidth);
  24443. maxLineWidth = Math.max(maxLineWidth, lastLineWidth);
  24444. line++;
  24445. pos.x = 0;
  24446. pos.y += data.lineHeight;
  24447. prevCharCode = null;
  24448. continue;
  24449. }
  24450. if (lastSpace !== -1 && this._maxWidth > 0 && pos.x * scale > this._maxWidth) {
  24451. core.utils.removeItems(chars, lastSpace - spacesRemoved, i - lastSpace);
  24452. i = lastSpace;
  24453. lastSpace = -1;
  24454. ++spacesRemoved;
  24455. lineWidths.push(lastSpaceWidth);
  24456. maxLineWidth = Math.max(maxLineWidth, lastSpaceWidth);
  24457. line++;
  24458. pos.x = 0;
  24459. pos.y += data.lineHeight;
  24460. prevCharCode = null;
  24461. continue;
  24462. }
  24463. var charData = data.chars[charCode];
  24464. if (!charData) {
  24465. continue;
  24466. }
  24467. if (prevCharCode && charData.kerning[prevCharCode]) {
  24468. pos.x += charData.kerning[prevCharCode];
  24469. }
  24470. chars.push({
  24471. texture: charData.texture,
  24472. line: line,
  24473. charCode: charCode,
  24474. position: new core.Point(pos.x + charData.xOffset, pos.y + charData.yOffset)
  24475. });
  24476. lastLineWidth = pos.x + (charData.texture.width + charData.xOffset);
  24477. pos.x += charData.xAdvance;
  24478. maxLineHeight = Math.max(maxLineHeight, charData.yOffset + charData.texture.height);
  24479. prevCharCode = charCode;
  24480. }
  24481. lineWidths.push(lastLineWidth);
  24482. maxLineWidth = Math.max(maxLineWidth, lastLineWidth);
  24483. var lineAlignOffsets = [];
  24484. for (var _i = 0; _i <= line; _i++) {
  24485. var alignOffset = 0;
  24486. if (this._font.align === 'right') {
  24487. alignOffset = maxLineWidth - lineWidths[_i];
  24488. } else if (this._font.align === 'center') {
  24489. alignOffset = (maxLineWidth - lineWidths[_i]) / 2;
  24490. }
  24491. lineAlignOffsets.push(alignOffset);
  24492. }
  24493. var lenChars = chars.length;
  24494. var tint = this.tint;
  24495. for (var _i2 = 0; _i2 < lenChars; _i2++) {
  24496. var c = this._glyphs[_i2]; // get the next glyph sprite
  24497. if (c) {
  24498. c.texture = chars[_i2].texture;
  24499. } else {
  24500. c = new core.Sprite(chars[_i2].texture);
  24501. this._glyphs.push(c);
  24502. }
  24503. c.position.x = (chars[_i2].position.x + lineAlignOffsets[chars[_i2].line]) * scale;
  24504. c.position.y = chars[_i2].position.y * scale;
  24505. c.scale.x = c.scale.y = scale;
  24506. c.tint = tint;
  24507. if (!c.parent) {
  24508. this.addChild(c);
  24509. }
  24510. }
  24511. // remove unnecessary children.
  24512. for (var _i3 = lenChars; _i3 < this._glyphs.length; ++_i3) {
  24513. this.removeChild(this._glyphs[_i3]);
  24514. }
  24515. this._textWidth = maxLineWidth * scale;
  24516. this._textHeight = (pos.y + data.lineHeight) * scale;
  24517. // apply anchor
  24518. if (this.anchor.x !== 0 || this.anchor.y !== 0) {
  24519. for (var _i4 = 0; _i4 < lenChars; _i4++) {
  24520. this._glyphs[_i4].x -= this._textWidth * this.anchor.x;
  24521. this._glyphs[_i4].y -= this._textHeight * this.anchor.y;
  24522. }
  24523. }
  24524. this._maxLineHeight = maxLineHeight * scale;
  24525. };
  24526. /**
  24527. * Updates the transform of this object
  24528. *
  24529. * @private
  24530. */
  24531. BitmapText.prototype.updateTransform = function updateTransform() {
  24532. this.validate();
  24533. this.containerUpdateTransform();
  24534. };
  24535. /**
  24536. * Validates text before calling parent's getLocalBounds
  24537. *
  24538. * @return {PIXI.Rectangle} The rectangular bounding area
  24539. */
  24540. BitmapText.prototype.getLocalBounds = function getLocalBounds() {
  24541. this.validate();
  24542. return _core$Container.prototype.getLocalBounds.call(this);
  24543. };
  24544. /**
  24545. * Updates text when needed
  24546. *
  24547. * @private
  24548. */
  24549. BitmapText.prototype.validate = function validate() {
  24550. if (this.dirty) {
  24551. this.updateText();
  24552. this.dirty = false;
  24553. }
  24554. };
  24555. /**
  24556. * The tint of the BitmapText object
  24557. *
  24558. * @member {number}
  24559. */
  24560. /**
  24561. * Register a bitmap font with data and a texture.
  24562. *
  24563. * @static
  24564. * @param {XMLDocument} xml - The XML document data.
  24565. * @param {PIXI.Texture} texture - Texture with all symbols.
  24566. * @return {Object} Result font object with font, size, lineHeight and char fields.
  24567. */
  24568. BitmapText.registerFont = function registerFont(xml, texture) {
  24569. var data = {};
  24570. var info = xml.getElementsByTagName('info')[0];
  24571. var common = xml.getElementsByTagName('common')[0];
  24572. var fileName = xml.getElementsByTagName('page')[0].getAttribute('file');
  24573. var res = (0, _utils.getResolutionOfUrl)(fileName, _settings2.default.RESOLUTION);
  24574. data.font = info.getAttribute('face');
  24575. data.size = parseInt(info.getAttribute('size'), 10);
  24576. data.lineHeight = parseInt(common.getAttribute('lineHeight'), 10) / res;
  24577. data.chars = {};
  24578. // parse letters
  24579. var letters = xml.getElementsByTagName('char');
  24580. for (var i = 0; i < letters.length; i++) {
  24581. var letter = letters[i];
  24582. var charCode = parseInt(letter.getAttribute('id'), 10);
  24583. var textureRect = new core.Rectangle(parseInt(letter.getAttribute('x'), 10) / res + texture.frame.x / res, parseInt(letter.getAttribute('y'), 10) / res + texture.frame.y / res, parseInt(letter.getAttribute('width'), 10) / res, parseInt(letter.getAttribute('height'), 10) / res);
  24584. data.chars[charCode] = {
  24585. xOffset: parseInt(letter.getAttribute('xoffset'), 10) / res,
  24586. yOffset: parseInt(letter.getAttribute('yoffset'), 10) / res,
  24587. xAdvance: parseInt(letter.getAttribute('xadvance'), 10) / res,
  24588. kerning: {},
  24589. texture: new core.Texture(texture.baseTexture, textureRect)
  24590. };
  24591. }
  24592. // parse kernings
  24593. var kernings = xml.getElementsByTagName('kerning');
  24594. for (var _i5 = 0; _i5 < kernings.length; _i5++) {
  24595. var kerning = kernings[_i5];
  24596. var first = parseInt(kerning.getAttribute('first'), 10) / res;
  24597. var second = parseInt(kerning.getAttribute('second'), 10) / res;
  24598. var amount = parseInt(kerning.getAttribute('amount'), 10) / res;
  24599. if (data.chars[second]) {
  24600. data.chars[second].kerning[first] = amount;
  24601. }
  24602. }
  24603. // I'm leaving this as a temporary fix so we can test the bitmap fonts in v3
  24604. // but it's very likely to change
  24605. BitmapText.fonts[data.font] = data;
  24606. return data;
  24607. };
  24608. _createClass(BitmapText, [{
  24609. key: 'tint',
  24610. get: function get() {
  24611. return this._font.tint;
  24612. },
  24613. set: function set(value) // eslint-disable-line require-jsdoc
  24614. {
  24615. this._font.tint = typeof value === 'number' && value >= 0 ? value : 0xFFFFFF;
  24616. this.dirty = true;
  24617. }
  24618. /**
  24619. * The alignment of the BitmapText object
  24620. *
  24621. * @member {string}
  24622. * @default 'left'
  24623. */
  24624. }, {
  24625. key: 'align',
  24626. get: function get() {
  24627. return this._font.align;
  24628. },
  24629. set: function set(value) // eslint-disable-line require-jsdoc
  24630. {
  24631. this._font.align = value || 'left';
  24632. this.dirty = true;
  24633. }
  24634. /**
  24635. * The anchor sets the origin point of the text.
  24636. * The default is 0,0 this means the text's origin is the top left
  24637. * Setting the anchor to 0.5,0.5 means the text's origin is centered
  24638. * Setting the anchor to 1,1 would mean the text's origin point will be the bottom right corner
  24639. *
  24640. * @member {PIXI.Point | number}
  24641. */
  24642. }, {
  24643. key: 'anchor',
  24644. get: function get() {
  24645. return this._anchor;
  24646. },
  24647. set: function set(value) // eslint-disable-line require-jsdoc
  24648. {
  24649. if (typeof value === 'number') {
  24650. this._anchor.set(value);
  24651. } else {
  24652. this._anchor.copy(value);
  24653. }
  24654. }
  24655. /**
  24656. * The font descriptor of the BitmapText object
  24657. *
  24658. * @member {string|object}
  24659. */
  24660. }, {
  24661. key: 'font',
  24662. get: function get() {
  24663. return this._font;
  24664. },
  24665. set: function set(value) // eslint-disable-line require-jsdoc
  24666. {
  24667. if (!value) {
  24668. return;
  24669. }
  24670. if (typeof value === 'string') {
  24671. value = value.split(' ');
  24672. this._font.name = value.length === 1 ? value[0] : value.slice(1).join(' ');
  24673. this._font.size = value.length >= 2 ? parseInt(value[0], 10) : BitmapText.fonts[this._font.name].size;
  24674. } else {
  24675. this._font.name = value.name;
  24676. this._font.size = typeof value.size === 'number' ? value.size : parseInt(value.size, 10);
  24677. }
  24678. this.dirty = true;
  24679. }
  24680. /**
  24681. * The text of the BitmapText object
  24682. *
  24683. * @member {string}
  24684. */
  24685. }, {
  24686. key: 'text',
  24687. get: function get() {
  24688. return this._text;
  24689. },
  24690. set: function set(value) // eslint-disable-line require-jsdoc
  24691. {
  24692. value = value.toString() || ' ';
  24693. if (this._text === value) {
  24694. return;
  24695. }
  24696. this._text = value;
  24697. this.dirty = true;
  24698. }
  24699. /**
  24700. * The max width of this bitmap text in pixels. If the text provided is longer than the
  24701. * value provided, line breaks will be automatically inserted in the last whitespace.
  24702. * Disable by setting value to 0
  24703. *
  24704. * @member {number}
  24705. */
  24706. }, {
  24707. key: 'maxWidth',
  24708. get: function get() {
  24709. return this._maxWidth;
  24710. },
  24711. set: function set(value) // eslint-disable-line require-jsdoc
  24712. {
  24713. if (this._maxWidth === value) {
  24714. return;
  24715. }
  24716. this._maxWidth = value;
  24717. this.dirty = true;
  24718. }
  24719. /**
  24720. * The max line height. This is useful when trying to use the total height of the Text,
  24721. * ie: when trying to vertically align.
  24722. *
  24723. * @member {number}
  24724. * @readonly
  24725. */
  24726. }, {
  24727. key: 'maxLineHeight',
  24728. get: function get() {
  24729. this.validate();
  24730. return this._maxLineHeight;
  24731. }
  24732. /**
  24733. * The width of the overall text, different from fontSize,
  24734. * which is defined in the style object
  24735. *
  24736. * @member {number}
  24737. * @readonly
  24738. */
  24739. }, {
  24740. key: 'textWidth',
  24741. get: function get() {
  24742. this.validate();
  24743. return this._textWidth;
  24744. }
  24745. /**
  24746. * The height of the overall text, different from fontSize,
  24747. * which is defined in the style object
  24748. *
  24749. * @member {number}
  24750. * @readonly
  24751. */
  24752. }, {
  24753. key: 'textHeight',
  24754. get: function get() {
  24755. this.validate();
  24756. return this._textHeight;
  24757. }
  24758. }]);
  24759. return BitmapText;
  24760. }(core.Container);
  24761. exports.default = BitmapText;
  24762. BitmapText.fonts = {};
  24763. }, { "../core": 65, "../core/math/ObservablePoint": 68, "../core/settings": 101, "../core/utils": 125 }], 137: [function (require, module, exports) {
  24764. 'use strict';
  24765. exports.__esModule = true;
  24766. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  24767. var _core = require('../core');
  24768. var core = _interopRequireWildcard(_core);
  24769. var _CanvasTinter = require('../core/sprites/canvas/CanvasTinter');
  24770. var _CanvasTinter2 = _interopRequireDefault(_CanvasTinter);
  24771. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  24772. function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
  24773. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  24774. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  24775. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  24776. var tempPoint = new core.Point();
  24777. /**
  24778. * A tiling sprite is a fast way of rendering a tiling image
  24779. *
  24780. * @class
  24781. * @extends PIXI.Sprite
  24782. * @memberof PIXI.extras
  24783. */
  24784. var TilingSprite = function (_core$Sprite) {
  24785. _inherits(TilingSprite, _core$Sprite);
  24786. /**
  24787. * @param {PIXI.Texture} texture - the texture of the tiling sprite
  24788. * @param {number} [width=100] - the width of the tiling sprite
  24789. * @param {number} [height=100] - the height of the tiling sprite
  24790. */
  24791. function TilingSprite(texture) {
  24792. var width = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 100;
  24793. var height = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 100;
  24794. _classCallCheck(this, TilingSprite);
  24795. /**
  24796. * Tile transform
  24797. *
  24798. * @member {PIXI.TransformStatic}
  24799. */
  24800. var _this = _possibleConstructorReturn(this, _core$Sprite.call(this, texture));
  24801. _this.tileTransform = new core.TransformStatic();
  24802. // /// private
  24803. /**
  24804. * The with of the tiling sprite
  24805. *
  24806. * @member {number}
  24807. * @private
  24808. */
  24809. _this._width = width;
  24810. /**
  24811. * The height of the tiling sprite
  24812. *
  24813. * @member {number}
  24814. * @private
  24815. */
  24816. _this._height = height;
  24817. /**
  24818. * Canvas pattern
  24819. *
  24820. * @type {CanvasPattern}
  24821. * @private
  24822. */
  24823. _this._canvasPattern = null;
  24824. /**
  24825. * transform that is applied to UV to get the texture coords
  24826. *
  24827. * @member {PIXI.TextureMatrix}
  24828. */
  24829. _this.uvTransform = texture.transform || new core.TextureMatrix(texture);
  24830. /**
  24831. * Plugin that is responsible for rendering this element.
  24832. * Allows to customize the rendering process without overriding '_renderWebGL' method.
  24833. *
  24834. * @member {string}
  24835. * @default 'tilingSprite'
  24836. */
  24837. _this.pluginName = 'tilingSprite';
  24838. /**
  24839. * Whether or not anchor affects uvs
  24840. *
  24841. * @member {boolean}
  24842. * @default false
  24843. */
  24844. _this.uvRespectAnchor = false;
  24845. return _this;
  24846. }
  24847. /**
  24848. * Changes frame clamping in corresponding textureTransform, shortcut
  24849. * Change to -0.5 to add a pixel to the edge, recommended for transparent trimmed textures in atlas
  24850. *
  24851. * @default 0.5
  24852. * @member {number}
  24853. */
  24854. /**
  24855. * @private
  24856. */
  24857. TilingSprite.prototype._onTextureUpdate = function _onTextureUpdate() {
  24858. if (this.uvTransform) {
  24859. this.uvTransform.texture = this._texture;
  24860. }
  24861. this.cachedTint = 0xFFFFFF;
  24862. };
  24863. /**
  24864. * Renders the object using the WebGL renderer
  24865. *
  24866. * @private
  24867. * @param {PIXI.WebGLRenderer} renderer - The renderer
  24868. */
  24869. TilingSprite.prototype._renderWebGL = function _renderWebGL(renderer) {
  24870. // tweak our texture temporarily..
  24871. var texture = this._texture;
  24872. if (!texture || !texture.valid) {
  24873. return;
  24874. }
  24875. this.tileTransform.updateLocalTransform();
  24876. this.uvTransform.update();
  24877. renderer.setObjectRenderer(renderer.plugins[this.pluginName]);
  24878. renderer.plugins[this.pluginName].render(this);
  24879. };
  24880. /**
  24881. * Renders the object using the Canvas renderer
  24882. *
  24883. * @private
  24884. * @param {PIXI.CanvasRenderer} renderer - a reference to the canvas renderer
  24885. */
  24886. TilingSprite.prototype._renderCanvas = function _renderCanvas(renderer) {
  24887. var texture = this._texture;
  24888. if (!texture.baseTexture.hasLoaded) {
  24889. return;
  24890. }
  24891. var context = renderer.context;
  24892. var transform = this.worldTransform;
  24893. var resolution = renderer.resolution;
  24894. var baseTexture = texture.baseTexture;
  24895. var baseTextureResolution = baseTexture.resolution;
  24896. var modX = this.tilePosition.x / this.tileScale.x % texture._frame.width * baseTextureResolution;
  24897. var modY = this.tilePosition.y / this.tileScale.y % texture._frame.height * baseTextureResolution;
  24898. // create a nice shiny pattern!
  24899. if (this._textureID !== this._texture._updateID || this.cachedTint !== this.tint) {
  24900. this._textureID = this._texture._updateID;
  24901. // cut an object from a spritesheet..
  24902. var tempCanvas = new core.CanvasRenderTarget(texture._frame.width, texture._frame.height, baseTextureResolution);
  24903. // Tint the tiling sprite
  24904. if (this.tint !== 0xFFFFFF) {
  24905. this.tintedTexture = _CanvasTinter2.default.getTintedTexture(this, this.tint);
  24906. tempCanvas.context.drawImage(this.tintedTexture, 0, 0);
  24907. } else {
  24908. tempCanvas.context.drawImage(baseTexture.source, -texture._frame.x * baseTextureResolution, -texture._frame.y * baseTextureResolution);
  24909. }
  24910. this.cachedTint = this.tint;
  24911. this._canvasPattern = tempCanvas.context.createPattern(tempCanvas.canvas, 'repeat');
  24912. }
  24913. // set context state..
  24914. context.globalAlpha = this.worldAlpha;
  24915. context.setTransform(transform.a * resolution, transform.b * resolution, transform.c * resolution, transform.d * resolution, transform.tx * resolution, transform.ty * resolution);
  24916. renderer.setBlendMode(this.blendMode);
  24917. // fill the pattern!
  24918. context.fillStyle = this._canvasPattern;
  24919. // TODO - this should be rolled into the setTransform above..
  24920. context.scale(this.tileScale.x / baseTextureResolution, this.tileScale.y / baseTextureResolution);
  24921. var anchorX = this.anchor.x * -this._width;
  24922. var anchorY = this.anchor.y * -this._height;
  24923. if (this.uvRespectAnchor) {
  24924. context.translate(modX, modY);
  24925. context.fillRect(-modX + anchorX, -modY + anchorY, this._width / this.tileScale.x * baseTextureResolution, this._height / this.tileScale.y * baseTextureResolution);
  24926. } else {
  24927. context.translate(modX + anchorX, modY + anchorY);
  24928. context.fillRect(-modX, -modY, this._width / this.tileScale.x * baseTextureResolution, this._height / this.tileScale.y * baseTextureResolution);
  24929. }
  24930. };
  24931. /**
  24932. * Updates the bounds of the tiling sprite.
  24933. *
  24934. * @private
  24935. */
  24936. TilingSprite.prototype._calculateBounds = function _calculateBounds() {
  24937. var minX = this._width * -this._anchor._x;
  24938. var minY = this._height * -this._anchor._y;
  24939. var maxX = this._width * (1 - this._anchor._x);
  24940. var maxY = this._height * (1 - this._anchor._y);
  24941. this._bounds.addFrame(this.transform, minX, minY, maxX, maxY);
  24942. };
  24943. /**
  24944. * Gets the local bounds of the sprite object.
  24945. *
  24946. * @param {PIXI.Rectangle} rect - The output rectangle.
  24947. * @return {PIXI.Rectangle} The bounds.
  24948. */
  24949. TilingSprite.prototype.getLocalBounds = function getLocalBounds(rect) {
  24950. // we can do a fast local bounds if the sprite has no children!
  24951. if (this.children.length === 0) {
  24952. this._bounds.minX = this._width * -this._anchor._x;
  24953. this._bounds.minY = this._height * -this._anchor._y;
  24954. this._bounds.maxX = this._width * (1 - this._anchor._x);
  24955. this._bounds.maxY = this._height * (1 - this._anchor._x);
  24956. if (!rect) {
  24957. if (!this._localBoundsRect) {
  24958. this._localBoundsRect = new core.Rectangle();
  24959. }
  24960. rect = this._localBoundsRect;
  24961. }
  24962. return this._bounds.getRectangle(rect);
  24963. }
  24964. return _core$Sprite.prototype.getLocalBounds.call(this, rect);
  24965. };
  24966. /**
  24967. * Checks if a point is inside this tiling sprite.
  24968. *
  24969. * @param {PIXI.Point} point - the point to check
  24970. * @return {boolean} Whether or not the sprite contains the point.
  24971. */
  24972. TilingSprite.prototype.containsPoint = function containsPoint(point) {
  24973. this.worldTransform.applyInverse(point, tempPoint);
  24974. var width = this._width;
  24975. var height = this._height;
  24976. var x1 = -width * this.anchor._x;
  24977. if (tempPoint.x >= x1 && tempPoint.x < x1 + width) {
  24978. var y1 = -height * this.anchor._y;
  24979. if (tempPoint.y >= y1 && tempPoint.y < y1 + height) {
  24980. return true;
  24981. }
  24982. }
  24983. return false;
  24984. };
  24985. /**
  24986. * Destroys this sprite and optionally its texture and children
  24987. *
  24988. * @param {object|boolean} [options] - Options parameter. A boolean will act as if all options
  24989. * have been set to that value
  24990. * @param {boolean} [options.children=false] - if set to true, all the children will have their destroy
  24991. * method called as well. 'options' will be passed on to those calls.
  24992. * @param {boolean} [options.texture=false] - Should it destroy the current texture of the sprite as well
  24993. * @param {boolean} [options.baseTexture=false] - Should it destroy the base texture of the sprite as well
  24994. */
  24995. TilingSprite.prototype.destroy = function destroy(options) {
  24996. _core$Sprite.prototype.destroy.call(this, options);
  24997. this.tileTransform = null;
  24998. this.uvTransform = null;
  24999. };
  25000. /**
  25001. * Helper function that creates a new tiling sprite based on the source you provide.
  25002. * The source can be - frame id, image url, video url, canvas element, video element, base texture
  25003. *
  25004. * @static
  25005. * @param {number|string|PIXI.BaseTexture|HTMLCanvasElement|HTMLVideoElement} source - Source to create texture from
  25006. * @param {number} width - the width of the tiling sprite
  25007. * @param {number} height - the height of the tiling sprite
  25008. * @return {PIXI.Texture} The newly created texture
  25009. */
  25010. TilingSprite.from = function from(source, width, height) {
  25011. return new TilingSprite(core.Texture.from(source), width, height);
  25012. };
  25013. /**
  25014. * Helper function that creates a tiling sprite that will use a texture from the TextureCache based on the frameId
  25015. * The frame ids are created when a Texture packer file has been loaded
  25016. *
  25017. * @static
  25018. * @param {string} frameId - The frame Id of the texture in the cache
  25019. * @param {number} width - the width of the tiling sprite
  25020. * @param {number} height - the height of the tiling sprite
  25021. * @return {PIXI.extras.TilingSprite} A new TilingSprite using a texture from the texture cache matching the frameId
  25022. */
  25023. TilingSprite.fromFrame = function fromFrame(frameId, width, height) {
  25024. var texture = core.utils.TextureCache[frameId];
  25025. if (!texture) {
  25026. throw new Error('The frameId "' + frameId + '" does not exist in the texture cache ' + this);
  25027. }
  25028. return new TilingSprite(texture, width, height);
  25029. };
  25030. /**
  25031. * Helper function that creates a sprite that will contain a texture based on an image url
  25032. * If the image is not in the texture cache it will be loaded
  25033. *
  25034. * @static
  25035. * @param {string} imageId - The image url of the texture
  25036. * @param {number} width - the width of the tiling sprite
  25037. * @param {number} height - the height of the tiling sprite
  25038. * @param {boolean} [crossorigin] - if you want to specify the cross-origin parameter
  25039. * @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - if you want to specify the scale mode,
  25040. * see {@link PIXI.SCALE_MODES} for possible values
  25041. * @return {PIXI.extras.TilingSprite} A new TilingSprite using a texture from the texture cache matching the image id
  25042. */
  25043. TilingSprite.fromImage = function fromImage(imageId, width, height, crossorigin, scaleMode) {
  25044. return new TilingSprite(core.Texture.fromImage(imageId, crossorigin, scaleMode), width, height);
  25045. };
  25046. /**
  25047. * The width of the sprite, setting this will actually modify the scale to achieve the value set
  25048. *
  25049. * @member {number}
  25050. */
  25051. _createClass(TilingSprite, [{
  25052. key: 'clampMargin',
  25053. get: function get() {
  25054. return this.uvTransform.clampMargin;
  25055. },
  25056. set: function set(value) // eslint-disable-line require-jsdoc
  25057. {
  25058. this.uvTransform.clampMargin = value;
  25059. this.uvTransform.update(true);
  25060. }
  25061. /**
  25062. * The scaling of the image that is being tiled
  25063. *
  25064. * @member {PIXI.ObservablePoint}
  25065. */
  25066. }, {
  25067. key: 'tileScale',
  25068. get: function get() {
  25069. return this.tileTransform.scale;
  25070. },
  25071. set: function set(value) // eslint-disable-line require-jsdoc
  25072. {
  25073. this.tileTransform.scale.copy(value);
  25074. }
  25075. /**
  25076. * The offset of the image that is being tiled
  25077. *
  25078. * @member {PIXI.ObservablePoint}
  25079. */
  25080. }, {
  25081. key: 'tilePosition',
  25082. get: function get() {
  25083. return this.tileTransform.position;
  25084. },
  25085. set: function set(value) // eslint-disable-line require-jsdoc
  25086. {
  25087. this.tileTransform.position.copy(value);
  25088. }
  25089. }, {
  25090. key: 'width',
  25091. get: function get() {
  25092. return this._width;
  25093. },
  25094. set: function set(value) // eslint-disable-line require-jsdoc
  25095. {
  25096. this._width = value;
  25097. }
  25098. /**
  25099. * The height of the TilingSprite, setting this will actually modify the scale to achieve the value set
  25100. *
  25101. * @member {number}
  25102. */
  25103. }, {
  25104. key: 'height',
  25105. get: function get() {
  25106. return this._height;
  25107. },
  25108. set: function set(value) // eslint-disable-line require-jsdoc
  25109. {
  25110. this._height = value;
  25111. }
  25112. }]);
  25113. return TilingSprite;
  25114. }(core.Sprite);
  25115. exports.default = TilingSprite;
  25116. }, { "../core": 65, "../core/sprites/canvas/CanvasTinter": 104 }], 138: [function (require, module, exports) {
  25117. 'use strict';
  25118. var _core = require('../core');
  25119. var core = _interopRequireWildcard(_core);
  25120. var _Texture = require('../core/textures/Texture');
  25121. var _Texture2 = _interopRequireDefault(_Texture);
  25122. var _BaseTexture = require('../core/textures/BaseTexture');
  25123. var _BaseTexture2 = _interopRequireDefault(_BaseTexture);
  25124. var _utils = require('../core/utils');
  25125. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  25126. function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
  25127. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  25128. var DisplayObject = core.DisplayObject;
  25129. var _tempMatrix = new core.Matrix();
  25130. DisplayObject.prototype._cacheAsBitmap = false;
  25131. DisplayObject.prototype._cacheData = false;
  25132. // figured theres no point adding ALL the extra variables to prototype.
  25133. // this model can hold the information needed. This can also be generated on demand as
  25134. // most objects are not cached as bitmaps.
  25135. /**
  25136. * @class
  25137. * @ignore
  25138. */
  25139. var CacheData =
  25140. /**
  25141. *
  25142. */
  25143. function CacheData() {
  25144. _classCallCheck(this, CacheData);
  25145. this.textureCacheId = null;
  25146. this.originalRenderWebGL = null;
  25147. this.originalRenderCanvas = null;
  25148. this.originalCalculateBounds = null;
  25149. this.originalGetLocalBounds = null;
  25150. this.originalUpdateTransform = null;
  25151. this.originalHitTest = null;
  25152. this.originalDestroy = null;
  25153. this.originalMask = null;
  25154. this.originalFilterArea = null;
  25155. this.sprite = null;
  25156. };
  25157. Object.defineProperties(DisplayObject.prototype, {
  25158. /**
  25159. * Set this to true if you want this display object to be cached as a bitmap.
  25160. * This basically takes a snap shot of the display object as it is at that moment. It can
  25161. * provide a performance benefit for complex static displayObjects.
  25162. * To remove simply set this property to 'false'
  25163. *
  25164. * IMPORTANT GOTCHA - make sure that all your textures are preloaded BEFORE setting this property to true
  25165. * as it will take a snapshot of what is currently there. If the textures have not loaded then they will not appear.
  25166. *
  25167. * @member {boolean}
  25168. * @memberof PIXI.DisplayObject#
  25169. */
  25170. cacheAsBitmap: {
  25171. get: function get() {
  25172. return this._cacheAsBitmap;
  25173. },
  25174. set: function set(value) {
  25175. if (this._cacheAsBitmap === value) {
  25176. return;
  25177. }
  25178. this._cacheAsBitmap = value;
  25179. var data = void 0;
  25180. if (value) {
  25181. if (!this._cacheData) {
  25182. this._cacheData = new CacheData();
  25183. }
  25184. data = this._cacheData;
  25185. data.originalRenderWebGL = this.renderWebGL;
  25186. data.originalRenderCanvas = this.renderCanvas;
  25187. data.originalUpdateTransform = this.updateTransform;
  25188. data.originalCalculateBounds = this._calculateBounds;
  25189. data.originalGetLocalBounds = this.getLocalBounds;
  25190. data.originalDestroy = this.destroy;
  25191. data.originalContainsPoint = this.containsPoint;
  25192. data.originalMask = this._mask;
  25193. data.originalFilterArea = this.filterArea;
  25194. this.renderWebGL = this._renderCachedWebGL;
  25195. this.renderCanvas = this._renderCachedCanvas;
  25196. this.destroy = this._cacheAsBitmapDestroy;
  25197. } else {
  25198. data = this._cacheData;
  25199. if (data.sprite) {
  25200. this._destroyCachedDisplayObject();
  25201. }
  25202. this.renderWebGL = data.originalRenderWebGL;
  25203. this.renderCanvas = data.originalRenderCanvas;
  25204. this._calculateBounds = data.originalCalculateBounds;
  25205. this.getLocalBounds = data.originalGetLocalBounds;
  25206. this.destroy = data.originalDestroy;
  25207. this.updateTransform = data.originalUpdateTransform;
  25208. this.containsPoint = data.originalContainsPoint;
  25209. this._mask = data.originalMask;
  25210. this.filterArea = data.originalFilterArea;
  25211. }
  25212. }
  25213. }
  25214. });
  25215. /**
  25216. * Renders a cached version of the sprite with WebGL
  25217. *
  25218. * @private
  25219. * @memberof PIXI.DisplayObject#
  25220. * @param {PIXI.WebGLRenderer} renderer - the WebGL renderer
  25221. */
  25222. DisplayObject.prototype._renderCachedWebGL = function _renderCachedWebGL(renderer) {
  25223. if (!this.visible || this.worldAlpha <= 0 || !this.renderable) {
  25224. return;
  25225. }
  25226. this._initCachedDisplayObject(renderer);
  25227. this._cacheData.sprite._transformID = -1;
  25228. this._cacheData.sprite.worldAlpha = this.worldAlpha;
  25229. this._cacheData.sprite._renderWebGL(renderer);
  25230. };
  25231. /**
  25232. * Prepares the WebGL renderer to cache the sprite
  25233. *
  25234. * @private
  25235. * @memberof PIXI.DisplayObject#
  25236. * @param {PIXI.WebGLRenderer} renderer - the WebGL renderer
  25237. */
  25238. DisplayObject.prototype._initCachedDisplayObject = function _initCachedDisplayObject(renderer) {
  25239. if (this._cacheData && this._cacheData.sprite) {
  25240. return;
  25241. }
  25242. // make sure alpha is set to 1 otherwise it will get rendered as invisible!
  25243. var cacheAlpha = this.alpha;
  25244. this.alpha = 1;
  25245. // first we flush anything left in the renderer (otherwise it would get rendered to the cached texture)
  25246. renderer.currentRenderer.flush();
  25247. // this.filters= [];
  25248. // next we find the dimensions of the untransformed object
  25249. // this function also calls updatetransform on all its children as part of the measuring.
  25250. // This means we don't need to update the transform again in this function
  25251. // TODO pass an object to clone too? saves having to create a new one each time!
  25252. var bounds = this.getLocalBounds().clone();
  25253. // add some padding!
  25254. if (this._filters) {
  25255. var padding = this._filters[0].padding;
  25256. bounds.pad(padding);
  25257. }
  25258. // for now we cache the current renderTarget that the webGL renderer is currently using.
  25259. // this could be more elegent..
  25260. var cachedRenderTarget = renderer._activeRenderTarget;
  25261. // We also store the filter stack - I will definitely look to change how this works a little later down the line.
  25262. var stack = renderer.filterManager.filterStack;
  25263. // this renderTexture will be used to store the cached DisplayObject
  25264. var renderTexture = core.RenderTexture.create(bounds.width | 0, bounds.height | 0);
  25265. var textureCacheId = 'cacheAsBitmap_' + (0, _utils.uid)();
  25266. this._cacheData.textureCacheId = textureCacheId;
  25267. _BaseTexture2.default.addToCache(renderTexture.baseTexture, textureCacheId);
  25268. _Texture2.default.addToCache(renderTexture, textureCacheId);
  25269. // need to set //
  25270. var m = _tempMatrix;
  25271. m.tx = -bounds.x;
  25272. m.ty = -bounds.y;
  25273. // reset
  25274. this.transform.worldTransform.identity();
  25275. // set all properties to there original so we can render to a texture
  25276. this.renderWebGL = this._cacheData.originalRenderWebGL;
  25277. renderer.render(this, renderTexture, true, m, true);
  25278. // now restore the state be setting the new properties
  25279. renderer.bindRenderTarget(cachedRenderTarget);
  25280. renderer.filterManager.filterStack = stack;
  25281. this.renderWebGL = this._renderCachedWebGL;
  25282. this.updateTransform = this.displayObjectUpdateTransform;
  25283. this._mask = null;
  25284. this.filterArea = null;
  25285. // create our cached sprite
  25286. var cachedSprite = new core.Sprite(renderTexture);
  25287. cachedSprite.transform.worldTransform = this.transform.worldTransform;
  25288. cachedSprite.anchor.x = -(bounds.x / bounds.width);
  25289. cachedSprite.anchor.y = -(bounds.y / bounds.height);
  25290. cachedSprite.alpha = cacheAlpha;
  25291. cachedSprite._bounds = this._bounds;
  25292. // easy bounds..
  25293. this._calculateBounds = this._calculateCachedBounds;
  25294. this.getLocalBounds = this._getCachedLocalBounds;
  25295. this._cacheData.sprite = cachedSprite;
  25296. this.transform._parentID = -1;
  25297. // restore the transform of the cached sprite to avoid the nasty flicker..
  25298. if (!this.parent) {
  25299. this.parent = renderer._tempDisplayObjectParent;
  25300. this.updateTransform();
  25301. this.parent = null;
  25302. } else {
  25303. this.updateTransform();
  25304. }
  25305. // map the hit test..
  25306. this.containsPoint = cachedSprite.containsPoint.bind(cachedSprite);
  25307. };
  25308. /**
  25309. * Renders a cached version of the sprite with canvas
  25310. *
  25311. * @private
  25312. * @memberof PIXI.DisplayObject#
  25313. * @param {PIXI.WebGLRenderer} renderer - the WebGL renderer
  25314. */
  25315. DisplayObject.prototype._renderCachedCanvas = function _renderCachedCanvas(renderer) {
  25316. if (!this.visible || this.worldAlpha <= 0 || !this.renderable) {
  25317. return;
  25318. }
  25319. this._initCachedDisplayObjectCanvas(renderer);
  25320. this._cacheData.sprite.worldAlpha = this.worldAlpha;
  25321. this._cacheData.sprite.renderCanvas(renderer);
  25322. };
  25323. // TODO this can be the same as the webGL verison.. will need to do a little tweaking first though..
  25324. /**
  25325. * Prepares the Canvas renderer to cache the sprite
  25326. *
  25327. * @private
  25328. * @memberof PIXI.DisplayObject#
  25329. * @param {PIXI.WebGLRenderer} renderer - the WebGL renderer
  25330. */
  25331. DisplayObject.prototype._initCachedDisplayObjectCanvas = function _initCachedDisplayObjectCanvas(renderer) {
  25332. if (this._cacheData && this._cacheData.sprite) {
  25333. return;
  25334. }
  25335. // get bounds actually transforms the object for us already!
  25336. var bounds = this.getLocalBounds();
  25337. var cacheAlpha = this.alpha;
  25338. this.alpha = 1;
  25339. var cachedRenderTarget = renderer.context;
  25340. var renderTexture = core.RenderTexture.create(bounds.width | 0, bounds.height | 0);
  25341. var textureCacheId = 'cacheAsBitmap_' + (0, _utils.uid)();
  25342. this._cacheData.textureCacheId = textureCacheId;
  25343. _BaseTexture2.default.addToCache(renderTexture.baseTexture, textureCacheId);
  25344. _Texture2.default.addToCache(renderTexture, textureCacheId);
  25345. // need to set //
  25346. var m = _tempMatrix;
  25347. this.transform.localTransform.copy(m);
  25348. m.invert();
  25349. m.tx -= bounds.x;
  25350. m.ty -= bounds.y;
  25351. // m.append(this.transform.worldTransform.)
  25352. // set all properties to there original so we can render to a texture
  25353. this.renderCanvas = this._cacheData.originalRenderCanvas;
  25354. // renderTexture.render(this, m, true);
  25355. renderer.render(this, renderTexture, true, m, false);
  25356. // now restore the state be setting the new properties
  25357. renderer.context = cachedRenderTarget;
  25358. this.renderCanvas = this._renderCachedCanvas;
  25359. this._calculateBounds = this._calculateCachedBounds;
  25360. this._mask = null;
  25361. this.filterArea = null;
  25362. // create our cached sprite
  25363. var cachedSprite = new core.Sprite(renderTexture);
  25364. cachedSprite.transform.worldTransform = this.transform.worldTransform;
  25365. cachedSprite.anchor.x = -(bounds.x / bounds.width);
  25366. cachedSprite.anchor.y = -(bounds.y / bounds.height);
  25367. cachedSprite._bounds = this._bounds;
  25368. cachedSprite.alpha = cacheAlpha;
  25369. if (!this.parent) {
  25370. this.parent = renderer._tempDisplayObjectParent;
  25371. this.updateTransform();
  25372. this.parent = null;
  25373. } else {
  25374. this.updateTransform();
  25375. }
  25376. this.updateTransform = this.displayObjectUpdateTransform;
  25377. this._cacheData.sprite = cachedSprite;
  25378. this.containsPoint = cachedSprite.containsPoint.bind(cachedSprite);
  25379. };
  25380. /**
  25381. * Calculates the bounds of the cached sprite
  25382. *
  25383. * @private
  25384. */
  25385. DisplayObject.prototype._calculateCachedBounds = function _calculateCachedBounds() {
  25386. this._cacheData.sprite._calculateBounds();
  25387. };
  25388. /**
  25389. * Gets the bounds of the cached sprite.
  25390. *
  25391. * @private
  25392. * @return {Rectangle} The local bounds.
  25393. */
  25394. DisplayObject.prototype._getCachedLocalBounds = function _getCachedLocalBounds() {
  25395. return this._cacheData.sprite.getLocalBounds();
  25396. };
  25397. /**
  25398. * Destroys the cached sprite.
  25399. *
  25400. * @private
  25401. */
  25402. DisplayObject.prototype._destroyCachedDisplayObject = function _destroyCachedDisplayObject() {
  25403. this._cacheData.sprite._texture.destroy(true);
  25404. this._cacheData.sprite = null;
  25405. _BaseTexture2.default.removeFromCache(this._cacheData.textureCacheId);
  25406. _Texture2.default.removeFromCache(this._cacheData.textureCacheId);
  25407. this._cacheData.textureCacheId = null;
  25408. };
  25409. /**
  25410. * Destroys the cached object.
  25411. *
  25412. * @private
  25413. * @param {object|boolean} [options] - Options parameter. A boolean will act as if all options
  25414. * have been set to that value.
  25415. * Used when destroying containers, see the Container.destroy method.
  25416. */
  25417. DisplayObject.prototype._cacheAsBitmapDestroy = function _cacheAsBitmapDestroy(options) {
  25418. this.cacheAsBitmap = false;
  25419. this.destroy(options);
  25420. };
  25421. }, { "../core": 65, "../core/textures/BaseTexture": 112, "../core/textures/Texture": 115, "../core/utils": 125 }], 139: [function (require, module, exports) {
  25422. 'use strict';
  25423. var _core = require('../core');
  25424. var core = _interopRequireWildcard(_core);
  25425. function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
  25426. /**
  25427. * The instance name of the object.
  25428. *
  25429. * @memberof PIXI.DisplayObject#
  25430. * @member {string} name
  25431. */
  25432. core.DisplayObject.prototype.name = null;
  25433. /**
  25434. * Returns the display object in the container
  25435. *
  25436. * @method getChildByName
  25437. * @memberof PIXI.Container#
  25438. * @param {string} name - instance name
  25439. * @return {PIXI.DisplayObject} The child with the specified name.
  25440. */
  25441. core.Container.prototype.getChildByName = function getChildByName(name) {
  25442. for (var i = 0; i < this.children.length; i++) {
  25443. if (this.children[i].name === name) {
  25444. return this.children[i];
  25445. }
  25446. }
  25447. return null;
  25448. };
  25449. }, { "../core": 65 }], 140: [function (require, module, exports) {
  25450. 'use strict';
  25451. var _core = require('../core');
  25452. var core = _interopRequireWildcard(_core);
  25453. function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
  25454. /**
  25455. * Returns the global position of the displayObject. Does not depend on object scale, rotation and pivot.
  25456. *
  25457. * @method getGlobalPosition
  25458. * @memberof PIXI.DisplayObject#
  25459. * @param {Point} point - the point to write the global value to. If null a new point will be returned
  25460. * @param {boolean} skipUpdate - setting to true will stop the transforms of the scene graph from
  25461. * being updated. This means the calculation returned MAY be out of date BUT will give you a
  25462. * nice performance boost
  25463. * @return {Point} The updated point
  25464. */
  25465. core.DisplayObject.prototype.getGlobalPosition = function getGlobalPosition() {
  25466. var point = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : new core.Point();
  25467. var skipUpdate = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  25468. if (this.parent) {
  25469. this.parent.toGlobal(this.position, point, skipUpdate);
  25470. } else {
  25471. point.x = this.position.x;
  25472. point.y = this.position.y;
  25473. }
  25474. return point;
  25475. };
  25476. }, { "../core": 65 }], 141: [function (require, module, exports) {
  25477. 'use strict';
  25478. exports.__esModule = true;
  25479. exports.BitmapText = exports.TilingSpriteRenderer = exports.TilingSprite = exports.AnimatedSprite = undefined;
  25480. var _AnimatedSprite = require('./AnimatedSprite');
  25481. Object.defineProperty(exports, 'AnimatedSprite', {
  25482. enumerable: true,
  25483. get: function get() {
  25484. return _interopRequireDefault(_AnimatedSprite).default;
  25485. }
  25486. });
  25487. var _TilingSprite = require('./TilingSprite');
  25488. Object.defineProperty(exports, 'TilingSprite', {
  25489. enumerable: true,
  25490. get: function get() {
  25491. return _interopRequireDefault(_TilingSprite).default;
  25492. }
  25493. });
  25494. var _TilingSpriteRenderer = require('./webgl/TilingSpriteRenderer');
  25495. Object.defineProperty(exports, 'TilingSpriteRenderer', {
  25496. enumerable: true,
  25497. get: function get() {
  25498. return _interopRequireDefault(_TilingSpriteRenderer).default;
  25499. }
  25500. });
  25501. var _BitmapText = require('./BitmapText');
  25502. Object.defineProperty(exports, 'BitmapText', {
  25503. enumerable: true,
  25504. get: function get() {
  25505. return _interopRequireDefault(_BitmapText).default;
  25506. }
  25507. });
  25508. require('./cacheAsBitmap');
  25509. require('./getChildByName');
  25510. require('./getGlobalPosition');
  25511. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  25512. // imported for side effect of extending the prototype only, contains no exports
  25513. }, { "./AnimatedSprite": 135, "./BitmapText": 136, "./TilingSprite": 137, "./cacheAsBitmap": 138, "./getChildByName": 139, "./getGlobalPosition": 140, "./webgl/TilingSpriteRenderer": 142 }], 142: [function (require, module, exports) {
  25514. 'use strict';
  25515. exports.__esModule = true;
  25516. var _core = require('../../core');
  25517. var core = _interopRequireWildcard(_core);
  25518. var _const = require('../../core/const');
  25519. var _path = require('path');
  25520. function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
  25521. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  25522. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  25523. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  25524. var tempMat = new core.Matrix();
  25525. /**
  25526. * WebGL renderer plugin for tiling sprites
  25527. *
  25528. * @class
  25529. * @memberof PIXI.extras
  25530. * @extends PIXI.ObjectRenderer
  25531. */
  25532. var TilingSpriteRenderer = function (_core$ObjectRenderer) {
  25533. _inherits(TilingSpriteRenderer, _core$ObjectRenderer);
  25534. /**
  25535. * constructor for renderer
  25536. *
  25537. * @param {WebGLRenderer} renderer The renderer this tiling awesomeness works for.
  25538. */
  25539. function TilingSpriteRenderer(renderer) {
  25540. _classCallCheck(this, TilingSpriteRenderer);
  25541. var _this = _possibleConstructorReturn(this, _core$ObjectRenderer.call(this, renderer));
  25542. _this.shader = null;
  25543. _this.simpleShader = null;
  25544. _this.quad = null;
  25545. return _this;
  25546. }
  25547. /**
  25548. * Sets up the renderer context and necessary buffers.
  25549. *
  25550. * @private
  25551. */
  25552. TilingSpriteRenderer.prototype.onContextChange = function onContextChange() {
  25553. var gl = this.renderer.gl;
  25554. this.shader = new core.Shader(gl, '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', '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 = mod(vTextureCoord - uClampOffset, vec2(1.0, 1.0)) + uClampOffset;\n coord = (uMapCoord * vec3(coord, 1.0)).xy;\n coord = clamp(coord, uClampFrame.xy, uClampFrame.zw);\n\n vec4 sample = texture2D(uSampler, coord);\n gl_FragColor = sample * uColor;\n}\n');
  25555. this.simpleShader = new core.Shader(gl, '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', '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');
  25556. this.renderer.bindVao(null);
  25557. this.quad = new core.Quad(gl, this.renderer.state.attribState);
  25558. this.quad.initVao(this.shader);
  25559. };
  25560. /**
  25561. *
  25562. * @param {PIXI.extras.TilingSprite} ts tilingSprite to be rendered
  25563. */
  25564. TilingSpriteRenderer.prototype.render = function render(ts) {
  25565. var renderer = this.renderer;
  25566. var quad = this.quad;
  25567. renderer.bindVao(quad.vao);
  25568. var vertices = quad.vertices;
  25569. vertices[0] = vertices[6] = ts._width * -ts.anchor.x;
  25570. vertices[1] = vertices[3] = ts._height * -ts.anchor.y;
  25571. vertices[2] = vertices[4] = ts._width * (1.0 - ts.anchor.x);
  25572. vertices[5] = vertices[7] = ts._height * (1.0 - ts.anchor.y);
  25573. if (ts.uvRespectAnchor) {
  25574. vertices = quad.uvs;
  25575. vertices[0] = vertices[6] = -ts.anchor.x;
  25576. vertices[1] = vertices[3] = -ts.anchor.y;
  25577. vertices[2] = vertices[4] = 1.0 - ts.anchor.x;
  25578. vertices[5] = vertices[7] = 1.0 - ts.anchor.y;
  25579. }
  25580. quad.upload();
  25581. var tex = ts._texture;
  25582. var baseTex = tex.baseTexture;
  25583. var lt = ts.tileTransform.localTransform;
  25584. var uv = ts.uvTransform;
  25585. var isSimple = baseTex.isPowerOfTwo && tex.frame.width === baseTex.width && tex.frame.height === baseTex.height;
  25586. // auto, force repeat wrapMode for big tiling textures
  25587. if (isSimple) {
  25588. if (!baseTex._glTextures[renderer.CONTEXT_UID]) {
  25589. if (baseTex.wrapMode === _const.WRAP_MODES.CLAMP) {
  25590. baseTex.wrapMode = _const.WRAP_MODES.REPEAT;
  25591. }
  25592. } else {
  25593. isSimple = baseTex.wrapMode !== _const.WRAP_MODES.CLAMP;
  25594. }
  25595. }
  25596. var shader = isSimple ? this.simpleShader : this.shader;
  25597. renderer.bindShader(shader);
  25598. var w = tex.width;
  25599. var h = tex.height;
  25600. var W = ts._width;
  25601. var H = ts._height;
  25602. tempMat.set(lt.a * w / W, lt.b * w / H, lt.c * h / W, lt.d * h / H, lt.tx / W, lt.ty / H);
  25603. // that part is the same as above:
  25604. // tempMat.identity();
  25605. // tempMat.scale(tex.width, tex.height);
  25606. // tempMat.prepend(lt);
  25607. // tempMat.scale(1.0 / ts._width, 1.0 / ts._height);
  25608. tempMat.invert();
  25609. if (isSimple) {
  25610. tempMat.prepend(uv.mapCoord);
  25611. } else {
  25612. shader.uniforms.uMapCoord = uv.mapCoord.toArray(true);
  25613. shader.uniforms.uClampFrame = uv.uClampFrame;
  25614. shader.uniforms.uClampOffset = uv.uClampOffset;
  25615. }
  25616. shader.uniforms.uTransform = tempMat.toArray(true);
  25617. shader.uniforms.uColor = core.utils.premultiplyTintToRgba(ts.tint, ts.worldAlpha, shader.uniforms.uColor, baseTex.premultipliedAlpha);
  25618. shader.uniforms.translationMatrix = ts.transform.worldTransform.toArray(true);
  25619. shader.uniforms.uSampler = renderer.bindTexture(tex);
  25620. renderer.setBlendMode(core.utils.correctBlendMode(ts.blendMode, baseTex.premultipliedAlpha));
  25621. quad.vao.draw(this.renderer.gl.TRIANGLES, 6, 0);
  25622. };
  25623. return TilingSpriteRenderer;
  25624. }(core.ObjectRenderer);
  25625. exports.default = TilingSpriteRenderer;
  25626. core.WebGLRenderer.registerPlugin('tilingSprite', TilingSpriteRenderer);
  25627. }, { "../../core": 65, "../../core/const": 46, "path": 8 }], 143: [function (require, module, exports) {
  25628. 'use strict';
  25629. exports.__esModule = true;
  25630. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  25631. var _core = require('../../core');
  25632. var core = _interopRequireWildcard(_core);
  25633. var _path = require('path');
  25634. function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
  25635. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  25636. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  25637. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  25638. /**
  25639. * Simplest filter - applies alpha
  25640. *
  25641. * Use this instead of Container's alpha property to avoid visual layering of individual elements.
  25642. * AlphaFilter applies alpha evenly across the entire display object and any opaque elements it contains.
  25643. * If elements are not opaque, they will blend with each other anyway.
  25644. *
  25645. * Very handy if you want to use common features of all filters:
  25646. *
  25647. * 1. Assign a blendMode to this filter, blend all elements inside display object with background.
  25648. *
  25649. * 2. To use clipping in display coordinates, assign a filterArea to the same container that has this filter.
  25650. *
  25651. * @class
  25652. * @extends PIXI.Filter
  25653. * @memberof PIXI.filters
  25654. */
  25655. var AlphaFilter = function (_core$Filter) {
  25656. _inherits(AlphaFilter, _core$Filter);
  25657. /**
  25658. * @param {number} [alpha=1] Amount of alpha from 0 to 1, where 0 is transparent
  25659. */
  25660. function AlphaFilter() {
  25661. var alpha = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1.0;
  25662. _classCallCheck(this, AlphaFilter);
  25663. var _this = _possibleConstructorReturn(this, _core$Filter.call(this,
  25664. // vertex shader
  25665. '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}',
  25666. // fragment shader
  25667. 'varying vec2 vTextureCoord;\n\nuniform sampler2D uSampler;\nuniform float uAlpha;\n\nvoid main(void)\n{\n gl_FragColor = texture2D(uSampler, vTextureCoord) * uAlpha;\n}\n'));
  25668. _this.alpha = alpha;
  25669. _this.glShaderKey = 'alpha';
  25670. return _this;
  25671. }
  25672. /**
  25673. * Coefficient for alpha multiplication
  25674. *
  25675. * @member {number}
  25676. * @default 1
  25677. */
  25678. _createClass(AlphaFilter, [{
  25679. key: 'alpha',
  25680. get: function get() {
  25681. return this.uniforms.uAlpha;
  25682. },
  25683. set: function set(value) // eslint-disable-line require-jsdoc
  25684. {
  25685. this.uniforms.uAlpha = value;
  25686. }
  25687. }]);
  25688. return AlphaFilter;
  25689. }(core.Filter);
  25690. exports.default = AlphaFilter;
  25691. }, { "../../core": 65, "path": 8 }], 144: [function (require, module, exports) {
  25692. 'use strict';
  25693. exports.__esModule = true;
  25694. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  25695. var _core = require('../../core');
  25696. var core = _interopRequireWildcard(_core);
  25697. var _BlurXFilter = require('./BlurXFilter');
  25698. var _BlurXFilter2 = _interopRequireDefault(_BlurXFilter);
  25699. var _BlurYFilter = require('./BlurYFilter');
  25700. var _BlurYFilter2 = _interopRequireDefault(_BlurYFilter);
  25701. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  25702. function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
  25703. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  25704. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  25705. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  25706. /**
  25707. * The BlurFilter applies a Gaussian blur to an object.
  25708. * The strength of the blur can be set for x- and y-axis separately.
  25709. *
  25710. * @class
  25711. * @extends PIXI.Filter
  25712. * @memberof PIXI.filters
  25713. */
  25714. var BlurFilter = function (_core$Filter) {
  25715. _inherits(BlurFilter, _core$Filter);
  25716. /**
  25717. * @param {number} strength - The strength of the blur filter.
  25718. * @param {number} quality - The quality of the blur filter.
  25719. * @param {number} resolution - The resolution of the blur filter.
  25720. * @param {number} [kernelSize=5] - The kernelSize of the blur filter.Options: 5, 7, 9, 11, 13, 15.
  25721. */
  25722. function BlurFilter(strength, quality, resolution, kernelSize) {
  25723. _classCallCheck(this, BlurFilter);
  25724. var _this = _possibleConstructorReturn(this, _core$Filter.call(this));
  25725. _this.blurXFilter = new _BlurXFilter2.default(strength, quality, resolution, kernelSize);
  25726. _this.blurYFilter = new _BlurYFilter2.default(strength, quality, resolution, kernelSize);
  25727. _this.padding = 0;
  25728. _this.resolution = resolution || core.settings.RESOLUTION;
  25729. _this.quality = quality || 4;
  25730. _this.blur = strength || 8;
  25731. return _this;
  25732. }
  25733. /**
  25734. * Applies the filter.
  25735. *
  25736. * @param {PIXI.FilterManager} filterManager - The manager.
  25737. * @param {PIXI.RenderTarget} input - The input target.
  25738. * @param {PIXI.RenderTarget} output - The output target.
  25739. */
  25740. BlurFilter.prototype.apply = function apply(filterManager, input, output) {
  25741. var renderTarget = filterManager.getRenderTarget(true);
  25742. this.blurXFilter.apply(filterManager, input, renderTarget, true);
  25743. this.blurYFilter.apply(filterManager, renderTarget, output, false);
  25744. filterManager.returnRenderTarget(renderTarget);
  25745. };
  25746. /**
  25747. * Sets the strength of both the blurX and blurY properties simultaneously
  25748. *
  25749. * @member {number}
  25750. * @default 2
  25751. */
  25752. _createClass(BlurFilter, [{
  25753. key: 'blur',
  25754. get: function get() {
  25755. return this.blurXFilter.blur;
  25756. },
  25757. set: function set(value) // eslint-disable-line require-jsdoc
  25758. {
  25759. this.blurXFilter.blur = this.blurYFilter.blur = value;
  25760. this.padding = Math.max(Math.abs(this.blurXFilter.strength), Math.abs(this.blurYFilter.strength)) * 2;
  25761. }
  25762. /**
  25763. * Sets the number of passes for blur. More passes means higher quaility bluring.
  25764. *
  25765. * @member {number}
  25766. * @default 1
  25767. */
  25768. }, {
  25769. key: 'quality',
  25770. get: function get() {
  25771. return this.blurXFilter.quality;
  25772. },
  25773. set: function set(value) // eslint-disable-line require-jsdoc
  25774. {
  25775. this.blurXFilter.quality = this.blurYFilter.quality = value;
  25776. }
  25777. /**
  25778. * Sets the strength of the blurX property
  25779. *
  25780. * @member {number}
  25781. * @default 2
  25782. */
  25783. }, {
  25784. key: 'blurX',
  25785. get: function get() {
  25786. return this.blurXFilter.blur;
  25787. },
  25788. set: function set(value) // eslint-disable-line require-jsdoc
  25789. {
  25790. this.blurXFilter.blur = value;
  25791. this.padding = Math.max(Math.abs(this.blurXFilter.strength), Math.abs(this.blurYFilter.strength)) * 2;
  25792. }
  25793. /**
  25794. * Sets the strength of the blurY property
  25795. *
  25796. * @member {number}
  25797. * @default 2
  25798. */
  25799. }, {
  25800. key: 'blurY',
  25801. get: function get() {
  25802. return this.blurYFilter.blur;
  25803. },
  25804. set: function set(value) // eslint-disable-line require-jsdoc
  25805. {
  25806. this.blurYFilter.blur = value;
  25807. this.padding = Math.max(Math.abs(this.blurXFilter.strength), Math.abs(this.blurYFilter.strength)) * 2;
  25808. }
  25809. /**
  25810. * Sets the blendmode of the filter
  25811. *
  25812. * @member {number}
  25813. * @default PIXI.BLEND_MODES.NORMAL
  25814. */
  25815. }, {
  25816. key: 'blendMode',
  25817. get: function get() {
  25818. return this.blurYFilter._blendMode;
  25819. },
  25820. set: function set(value) // eslint-disable-line require-jsdoc
  25821. {
  25822. this.blurYFilter._blendMode = value;
  25823. }
  25824. }]);
  25825. return BlurFilter;
  25826. }(core.Filter);
  25827. exports.default = BlurFilter;
  25828. }, { "../../core": 65, "./BlurXFilter": 145, "./BlurYFilter": 146 }], 145: [function (require, module, exports) {
  25829. 'use strict';
  25830. exports.__esModule = true;
  25831. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  25832. var _core = require('../../core');
  25833. var core = _interopRequireWildcard(_core);
  25834. var _generateBlurVertSource = require('./generateBlurVertSource');
  25835. var _generateBlurVertSource2 = _interopRequireDefault(_generateBlurVertSource);
  25836. var _generateBlurFragSource = require('./generateBlurFragSource');
  25837. var _generateBlurFragSource2 = _interopRequireDefault(_generateBlurFragSource);
  25838. var _getMaxBlurKernelSize = require('./getMaxBlurKernelSize');
  25839. var _getMaxBlurKernelSize2 = _interopRequireDefault(_getMaxBlurKernelSize);
  25840. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  25841. function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
  25842. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  25843. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  25844. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  25845. /**
  25846. * The BlurXFilter applies a horizontal Gaussian blur to an object.
  25847. *
  25848. * @class
  25849. * @extends PIXI.Filter
  25850. * @memberof PIXI.filters
  25851. */
  25852. var BlurXFilter = function (_core$Filter) {
  25853. _inherits(BlurXFilter, _core$Filter);
  25854. /**
  25855. * @param {number} strength - The strength of the blur filter.
  25856. * @param {number} quality - The quality of the blur filter.
  25857. * @param {number} resolution - The resolution of the blur filter.
  25858. * @param {number} [kernelSize=5] - The kernelSize of the blur filter.Options: 5, 7, 9, 11, 13, 15.
  25859. */
  25860. function BlurXFilter(strength, quality, resolution, kernelSize) {
  25861. _classCallCheck(this, BlurXFilter);
  25862. kernelSize = kernelSize || 5;
  25863. var vertSrc = (0, _generateBlurVertSource2.default)(kernelSize, true);
  25864. var fragSrc = (0, _generateBlurFragSource2.default)(kernelSize);
  25865. var _this = _possibleConstructorReturn(this, _core$Filter.call(this,
  25866. // vertex shader
  25867. vertSrc,
  25868. // fragment shader
  25869. fragSrc));
  25870. _this.resolution = resolution || core.settings.RESOLUTION;
  25871. _this._quality = 0;
  25872. _this.quality = quality || 4;
  25873. _this.strength = strength || 8;
  25874. _this.firstRun = true;
  25875. return _this;
  25876. }
  25877. /**
  25878. * Applies the filter.
  25879. *
  25880. * @param {PIXI.FilterManager} filterManager - The manager.
  25881. * @param {PIXI.RenderTarget} input - The input target.
  25882. * @param {PIXI.RenderTarget} output - The output target.
  25883. * @param {boolean} clear - Should the output be cleared before rendering?
  25884. */
  25885. BlurXFilter.prototype.apply = function apply(filterManager, input, output, clear) {
  25886. if (this.firstRun) {
  25887. var gl = filterManager.renderer.gl;
  25888. var kernelSize = (0, _getMaxBlurKernelSize2.default)(gl);
  25889. this.vertexSrc = (0, _generateBlurVertSource2.default)(kernelSize, true);
  25890. this.fragmentSrc = (0, _generateBlurFragSource2.default)(kernelSize);
  25891. this.firstRun = false;
  25892. }
  25893. this.uniforms.strength = 1 / output.size.width * (output.size.width / input.size.width);
  25894. // screen space!
  25895. this.uniforms.strength *= this.strength;
  25896. this.uniforms.strength /= this.passes; // / this.passes//Math.pow(1, this.passes);
  25897. if (this.passes === 1) {
  25898. filterManager.applyFilter(this, input, output, clear);
  25899. } else {
  25900. var renderTarget = filterManager.getRenderTarget(true);
  25901. var flip = input;
  25902. var flop = renderTarget;
  25903. for (var i = 0; i < this.passes - 1; i++) {
  25904. filterManager.applyFilter(this, flip, flop, true);
  25905. var temp = flop;
  25906. flop = flip;
  25907. flip = temp;
  25908. }
  25909. filterManager.applyFilter(this, flip, output, clear);
  25910. filterManager.returnRenderTarget(renderTarget);
  25911. }
  25912. };
  25913. /**
  25914. * Sets the strength of both the blur.
  25915. *
  25916. * @member {number}
  25917. * @default 16
  25918. */
  25919. _createClass(BlurXFilter, [{
  25920. key: 'blur',
  25921. get: function get() {
  25922. return this.strength;
  25923. },
  25924. set: function set(value) // eslint-disable-line require-jsdoc
  25925. {
  25926. this.padding = Math.abs(value) * 2;
  25927. this.strength = value;
  25928. }
  25929. /**
  25930. * Sets the quality of the blur by modifying the number of passes. More passes means higher
  25931. * quaility bluring but the lower the performance.
  25932. *
  25933. * @member {number}
  25934. * @default 4
  25935. */
  25936. }, {
  25937. key: 'quality',
  25938. get: function get() {
  25939. return this._quality;
  25940. },
  25941. set: function set(value) // eslint-disable-line require-jsdoc
  25942. {
  25943. this._quality = value;
  25944. this.passes = value;
  25945. }
  25946. }]);
  25947. return BlurXFilter;
  25948. }(core.Filter);
  25949. exports.default = BlurXFilter;
  25950. }, { "../../core": 65, "./generateBlurFragSource": 147, "./generateBlurVertSource": 148, "./getMaxBlurKernelSize": 149 }], 146: [function (require, module, exports) {
  25951. 'use strict';
  25952. exports.__esModule = true;
  25953. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  25954. var _core = require('../../core');
  25955. var core = _interopRequireWildcard(_core);
  25956. var _generateBlurVertSource = require('./generateBlurVertSource');
  25957. var _generateBlurVertSource2 = _interopRequireDefault(_generateBlurVertSource);
  25958. var _generateBlurFragSource = require('./generateBlurFragSource');
  25959. var _generateBlurFragSource2 = _interopRequireDefault(_generateBlurFragSource);
  25960. var _getMaxBlurKernelSize = require('./getMaxBlurKernelSize');
  25961. var _getMaxBlurKernelSize2 = _interopRequireDefault(_getMaxBlurKernelSize);
  25962. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  25963. function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
  25964. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  25965. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  25966. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  25967. /**
  25968. * The BlurYFilter applies a horizontal Gaussian blur to an object.
  25969. *
  25970. * @class
  25971. * @extends PIXI.Filter
  25972. * @memberof PIXI.filters
  25973. */
  25974. var BlurYFilter = function (_core$Filter) {
  25975. _inherits(BlurYFilter, _core$Filter);
  25976. /**
  25977. * @param {number} strength - The strength of the blur filter.
  25978. * @param {number} quality - The quality of the blur filter.
  25979. * @param {number} resolution - The resolution of the blur filter.
  25980. * @param {number} [kernelSize=5] - The kernelSize of the blur filter.Options: 5, 7, 9, 11, 13, 15.
  25981. */
  25982. function BlurYFilter(strength, quality, resolution, kernelSize) {
  25983. _classCallCheck(this, BlurYFilter);
  25984. kernelSize = kernelSize || 5;
  25985. var vertSrc = (0, _generateBlurVertSource2.default)(kernelSize, false);
  25986. var fragSrc = (0, _generateBlurFragSource2.default)(kernelSize);
  25987. var _this = _possibleConstructorReturn(this, _core$Filter.call(this,
  25988. // vertex shader
  25989. vertSrc,
  25990. // fragment shader
  25991. fragSrc));
  25992. _this.resolution = resolution || core.settings.RESOLUTION;
  25993. _this._quality = 0;
  25994. _this.quality = quality || 4;
  25995. _this.strength = strength || 8;
  25996. _this.firstRun = true;
  25997. return _this;
  25998. }
  25999. /**
  26000. * Applies the filter.
  26001. *
  26002. * @param {PIXI.FilterManager} filterManager - The manager.
  26003. * @param {PIXI.RenderTarget} input - The input target.
  26004. * @param {PIXI.RenderTarget} output - The output target.
  26005. * @param {boolean} clear - Should the output be cleared before rendering?
  26006. */
  26007. BlurYFilter.prototype.apply = function apply(filterManager, input, output, clear) {
  26008. if (this.firstRun) {
  26009. var gl = filterManager.renderer.gl;
  26010. var kernelSize = (0, _getMaxBlurKernelSize2.default)(gl);
  26011. this.vertexSrc = (0, _generateBlurVertSource2.default)(kernelSize, false);
  26012. this.fragmentSrc = (0, _generateBlurFragSource2.default)(kernelSize);
  26013. this.firstRun = false;
  26014. }
  26015. this.uniforms.strength = 1 / output.size.height * (output.size.height / input.size.height);
  26016. this.uniforms.strength *= this.strength;
  26017. this.uniforms.strength /= this.passes;
  26018. if (this.passes === 1) {
  26019. filterManager.applyFilter(this, input, output, clear);
  26020. } else {
  26021. var renderTarget = filterManager.getRenderTarget(true);
  26022. var flip = input;
  26023. var flop = renderTarget;
  26024. for (var i = 0; i < this.passes - 1; i++) {
  26025. filterManager.applyFilter(this, flip, flop, true);
  26026. var temp = flop;
  26027. flop = flip;
  26028. flip = temp;
  26029. }
  26030. filterManager.applyFilter(this, flip, output, clear);
  26031. filterManager.returnRenderTarget(renderTarget);
  26032. }
  26033. };
  26034. /**
  26035. * Sets the strength of both the blur.
  26036. *
  26037. * @member {number}
  26038. * @default 2
  26039. */
  26040. _createClass(BlurYFilter, [{
  26041. key: 'blur',
  26042. get: function get() {
  26043. return this.strength;
  26044. },
  26045. set: function set(value) // eslint-disable-line require-jsdoc
  26046. {
  26047. this.padding = Math.abs(value) * 2;
  26048. this.strength = value;
  26049. }
  26050. /**
  26051. * Sets the quality of the blur by modifying the number of passes. More passes means higher
  26052. * quaility bluring but the lower the performance.
  26053. *
  26054. * @member {number}
  26055. * @default 4
  26056. */
  26057. }, {
  26058. key: 'quality',
  26059. get: function get() {
  26060. return this._quality;
  26061. },
  26062. set: function set(value) // eslint-disable-line require-jsdoc
  26063. {
  26064. this._quality = value;
  26065. this.passes = value;
  26066. }
  26067. }]);
  26068. return BlurYFilter;
  26069. }(core.Filter);
  26070. exports.default = BlurYFilter;
  26071. }, { "../../core": 65, "./generateBlurFragSource": 147, "./generateBlurVertSource": 148, "./getMaxBlurKernelSize": 149 }], 147: [function (require, module, exports) {
  26072. 'use strict';
  26073. exports.__esModule = true;
  26074. exports.default = generateFragBlurSource;
  26075. var GAUSSIAN_VALUES = {
  26076. 5: [0.153388, 0.221461, 0.250301],
  26077. 7: [0.071303, 0.131514, 0.189879, 0.214607],
  26078. 9: [0.028532, 0.067234, 0.124009, 0.179044, 0.20236],
  26079. 11: [0.0093, 0.028002, 0.065984, 0.121703, 0.175713, 0.198596],
  26080. 13: [0.002406, 0.009255, 0.027867, 0.065666, 0.121117, 0.174868, 0.197641],
  26081. 15: [0.000489, 0.002403, 0.009246, 0.02784, 0.065602, 0.120999, 0.174697, 0.197448]
  26082. };
  26083. var fragTemplate = ['varying vec2 vBlurTexCoords[%size%];', 'uniform sampler2D uSampler;', 'void main(void)', '{', ' gl_FragColor = vec4(0.0);', ' %blur%', '}'].join('\n');
  26084. function generateFragBlurSource(kernelSize) {
  26085. var kernel = GAUSSIAN_VALUES[kernelSize];
  26086. var halfLength = kernel.length;
  26087. var fragSource = fragTemplate;
  26088. var blurLoop = '';
  26089. var template = 'gl_FragColor += texture2D(uSampler, vBlurTexCoords[%index%]) * %value%;';
  26090. var value = void 0;
  26091. for (var i = 0; i < kernelSize; i++) {
  26092. var blur = template.replace('%index%', i);
  26093. value = i;
  26094. if (i >= halfLength) {
  26095. value = kernelSize - i - 1;
  26096. }
  26097. blur = blur.replace('%value%', kernel[value]);
  26098. blurLoop += blur;
  26099. blurLoop += '\n';
  26100. }
  26101. fragSource = fragSource.replace('%blur%', blurLoop);
  26102. fragSource = fragSource.replace('%size%', kernelSize);
  26103. return fragSource;
  26104. }
  26105. }, {}], 148: [function (require, module, exports) {
  26106. 'use strict';
  26107. exports.__esModule = true;
  26108. exports.default = generateVertBlurSource;
  26109. var vertTemplate = ['attribute vec2 aVertexPosition;', 'attribute vec2 aTextureCoord;', 'uniform float strength;', 'uniform mat3 projectionMatrix;', 'varying vec2 vBlurTexCoords[%size%];', 'void main(void)', '{', 'gl_Position = vec4((projectionMatrix * vec3((aVertexPosition), 1.0)).xy, 0.0, 1.0);', '%blur%', '}'].join('\n');
  26110. function generateVertBlurSource(kernelSize, x) {
  26111. var halfLength = Math.ceil(kernelSize / 2);
  26112. var vertSource = vertTemplate;
  26113. var blurLoop = '';
  26114. var template = void 0;
  26115. // let value;
  26116. if (x) {
  26117. template = 'vBlurTexCoords[%index%] = aTextureCoord + vec2(%sampleIndex% * strength, 0.0);';
  26118. } else {
  26119. template = 'vBlurTexCoords[%index%] = aTextureCoord + vec2(0.0, %sampleIndex% * strength);';
  26120. }
  26121. for (var i = 0; i < kernelSize; i++) {
  26122. var blur = template.replace('%index%', i);
  26123. // value = i;
  26124. // if(i >= halfLength)
  26125. // {
  26126. // value = kernelSize - i - 1;
  26127. // }
  26128. blur = blur.replace('%sampleIndex%', i - (halfLength - 1) + '.0');
  26129. blurLoop += blur;
  26130. blurLoop += '\n';
  26131. }
  26132. vertSource = vertSource.replace('%blur%', blurLoop);
  26133. vertSource = vertSource.replace('%size%', kernelSize);
  26134. return vertSource;
  26135. }
  26136. }, {}], 149: [function (require, module, exports) {
  26137. "use strict";
  26138. exports.__esModule = true;
  26139. exports.default = getMaxKernelSize;
  26140. function getMaxKernelSize(gl) {
  26141. var maxVaryings = gl.getParameter(gl.MAX_VARYING_VECTORS);
  26142. var kernelSize = 15;
  26143. while (kernelSize > maxVaryings) {
  26144. kernelSize -= 2;
  26145. }
  26146. return kernelSize;
  26147. }
  26148. }, {}], 150: [function (require, module, exports) {
  26149. 'use strict';
  26150. exports.__esModule = true;
  26151. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  26152. var _core = require('../../core');
  26153. var core = _interopRequireWildcard(_core);
  26154. var _path = require('path');
  26155. function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
  26156. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  26157. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  26158. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  26159. /**
  26160. * The ColorMatrixFilter class lets you apply a 5x4 matrix transformation on the RGBA
  26161. * color and alpha values of every pixel on your displayObject to produce a result
  26162. * with a new set of RGBA color and alpha values. It's pretty powerful!
  26163. *
  26164. * ```js
  26165. * let colorMatrix = new PIXI.filters.ColorMatrixFilter();
  26166. * container.filters = [colorMatrix];
  26167. * colorMatrix.contrast(2);
  26168. * ```
  26169. * @author Clément Chenebault <clement@goodboydigital.com>
  26170. * @class
  26171. * @extends PIXI.Filter
  26172. * @memberof PIXI.filters
  26173. */
  26174. var ColorMatrixFilter = function (_core$Filter) {
  26175. _inherits(ColorMatrixFilter, _core$Filter);
  26176. /**
  26177. *
  26178. */
  26179. function ColorMatrixFilter() {
  26180. _classCallCheck(this, ColorMatrixFilter);
  26181. var _this = _possibleConstructorReturn(this, _core$Filter.call(this,
  26182. // vertex shader
  26183. '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}',
  26184. // fragment shader
  26185. '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'));
  26186. _this.uniforms.m = [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0];
  26187. _this.alpha = 1;
  26188. return _this;
  26189. }
  26190. /**
  26191. * Transforms current matrix and set the new one
  26192. *
  26193. * @param {number[]} matrix - 5x4 matrix
  26194. * @param {boolean} multiply - if true, current matrix and matrix are multiplied. If false,
  26195. * just set the current matrix with @param matrix
  26196. */
  26197. ColorMatrixFilter.prototype._loadMatrix = function _loadMatrix(matrix) {
  26198. var multiply = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  26199. var newMatrix = matrix;
  26200. if (multiply) {
  26201. this._multiply(newMatrix, this.uniforms.m, matrix);
  26202. newMatrix = this._colorMatrix(newMatrix);
  26203. }
  26204. // set the new matrix
  26205. this.uniforms.m = newMatrix;
  26206. };
  26207. /**
  26208. * Multiplies two mat5's
  26209. *
  26210. * @private
  26211. * @param {number[]} out - 5x4 matrix the receiving matrix
  26212. * @param {number[]} a - 5x4 matrix the first operand
  26213. * @param {number[]} b - 5x4 matrix the second operand
  26214. * @returns {number[]} 5x4 matrix
  26215. */
  26216. ColorMatrixFilter.prototype._multiply = function _multiply(out, a, b) {
  26217. // Red Channel
  26218. out[0] = a[0] * b[0] + a[1] * b[5] + a[2] * b[10] + a[3] * b[15];
  26219. out[1] = a[0] * b[1] + a[1] * b[6] + a[2] * b[11] + a[3] * b[16];
  26220. out[2] = a[0] * b[2] + a[1] * b[7] + a[2] * b[12] + a[3] * b[17];
  26221. out[3] = a[0] * b[3] + a[1] * b[8] + a[2] * b[13] + a[3] * b[18];
  26222. out[4] = a[0] * b[4] + a[1] * b[9] + a[2] * b[14] + a[3] * b[19] + a[4];
  26223. // Green Channel
  26224. out[5] = a[5] * b[0] + a[6] * b[5] + a[7] * b[10] + a[8] * b[15];
  26225. out[6] = a[5] * b[1] + a[6] * b[6] + a[7] * b[11] + a[8] * b[16];
  26226. out[7] = a[5] * b[2] + a[6] * b[7] + a[7] * b[12] + a[8] * b[17];
  26227. out[8] = a[5] * b[3] + a[6] * b[8] + a[7] * b[13] + a[8] * b[18];
  26228. out[9] = a[5] * b[4] + a[6] * b[9] + a[7] * b[14] + a[8] * b[19] + a[9];
  26229. // Blue Channel
  26230. out[10] = a[10] * b[0] + a[11] * b[5] + a[12] * b[10] + a[13] * b[15];
  26231. out[11] = a[10] * b[1] + a[11] * b[6] + a[12] * b[11] + a[13] * b[16];
  26232. out[12] = a[10] * b[2] + a[11] * b[7] + a[12] * b[12] + a[13] * b[17];
  26233. out[13] = a[10] * b[3] + a[11] * b[8] + a[12] * b[13] + a[13] * b[18];
  26234. out[14] = a[10] * b[4] + a[11] * b[9] + a[12] * b[14] + a[13] * b[19] + a[14];
  26235. // Alpha Channel
  26236. out[15] = a[15] * b[0] + a[16] * b[5] + a[17] * b[10] + a[18] * b[15];
  26237. out[16] = a[15] * b[1] + a[16] * b[6] + a[17] * b[11] + a[18] * b[16];
  26238. out[17] = a[15] * b[2] + a[16] * b[7] + a[17] * b[12] + a[18] * b[17];
  26239. out[18] = a[15] * b[3] + a[16] * b[8] + a[17] * b[13] + a[18] * b[18];
  26240. out[19] = a[15] * b[4] + a[16] * b[9] + a[17] * b[14] + a[18] * b[19] + a[19];
  26241. return out;
  26242. };
  26243. /**
  26244. * Create a Float32 Array and normalize the offset component to 0-1
  26245. *
  26246. * @private
  26247. * @param {number[]} matrix - 5x4 matrix
  26248. * @return {number[]} 5x4 matrix with all values between 0-1
  26249. */
  26250. ColorMatrixFilter.prototype._colorMatrix = function _colorMatrix(matrix) {
  26251. // Create a Float32 Array and normalize the offset component to 0-1
  26252. var m = new Float32Array(matrix);
  26253. m[4] /= 255;
  26254. m[9] /= 255;
  26255. m[14] /= 255;
  26256. m[19] /= 255;
  26257. return m;
  26258. };
  26259. /**
  26260. * Adjusts brightness
  26261. *
  26262. * @param {number} b - value of the brigthness (0-1, where 0 is black)
  26263. * @param {boolean} multiply - if true, current matrix and matrix are multiplied. If false,
  26264. * just set the current matrix with @param matrix
  26265. */
  26266. ColorMatrixFilter.prototype.brightness = function brightness(b, multiply) {
  26267. var matrix = [b, 0, 0, 0, 0, 0, b, 0, 0, 0, 0, 0, b, 0, 0, 0, 0, 0, 1, 0];
  26268. this._loadMatrix(matrix, multiply);
  26269. };
  26270. /**
  26271. * Set the matrices in grey scales
  26272. *
  26273. * @param {number} scale - value of the grey (0-1, where 0 is black)
  26274. * @param {boolean} multiply - if true, current matrix and matrix are multiplied. If false,
  26275. * just set the current matrix with @param matrix
  26276. */
  26277. ColorMatrixFilter.prototype.greyscale = function greyscale(scale, multiply) {
  26278. var matrix = [scale, scale, scale, 0, 0, scale, scale, scale, 0, 0, scale, scale, scale, 0, 0, 0, 0, 0, 1, 0];
  26279. this._loadMatrix(matrix, multiply);
  26280. };
  26281. /**
  26282. * Set the black and white matrice.
  26283. *
  26284. * @param {boolean} multiply - if true, current matrix and matrix are multiplied. If false,
  26285. * just set the current matrix with @param matrix
  26286. */
  26287. ColorMatrixFilter.prototype.blackAndWhite = function blackAndWhite(multiply) {
  26288. var matrix = [0.3, 0.6, 0.1, 0, 0, 0.3, 0.6, 0.1, 0, 0, 0.3, 0.6, 0.1, 0, 0, 0, 0, 0, 1, 0];
  26289. this._loadMatrix(matrix, multiply);
  26290. };
  26291. /**
  26292. * Set the hue property of the color
  26293. *
  26294. * @param {number} rotation - in degrees
  26295. * @param {boolean} multiply - if true, current matrix and matrix are multiplied. If false,
  26296. * just set the current matrix with @param matrix
  26297. */
  26298. ColorMatrixFilter.prototype.hue = function hue(rotation, multiply) {
  26299. rotation = (rotation || 0) / 180 * Math.PI;
  26300. var cosR = Math.cos(rotation);
  26301. var sinR = Math.sin(rotation);
  26302. var sqrt = Math.sqrt;
  26303. /* a good approximation for hue rotation
  26304. This matrix is far better than the versions with magic luminance constants
  26305. formerly used here, but also used in the starling framework (flash) and known from this
  26306. old part of the internet: quasimondo.com/archives/000565.php
  26307. This new matrix is based on rgb cube rotation in space. Look here for a more descriptive
  26308. implementation as a shader not a general matrix:
  26309. https://github.com/evanw/glfx.js/blob/58841c23919bd59787effc0333a4897b43835412/src/filters/adjust/huesaturation.js
  26310. This is the source for the code:
  26311. see http://stackoverflow.com/questions/8507885/shift-hue-of-an-rgb-color/8510751#8510751
  26312. */
  26313. var w = 1 / 3;
  26314. var sqrW = sqrt(w); // weight is
  26315. var a00 = cosR + (1.0 - cosR) * w;
  26316. var a01 = w * (1.0 - cosR) - sqrW * sinR;
  26317. var a02 = w * (1.0 - cosR) + sqrW * sinR;
  26318. var a10 = w * (1.0 - cosR) + sqrW * sinR;
  26319. var a11 = cosR + w * (1.0 - cosR);
  26320. var a12 = w * (1.0 - cosR) - sqrW * sinR;
  26321. var a20 = w * (1.0 - cosR) - sqrW * sinR;
  26322. var a21 = w * (1.0 - cosR) + sqrW * sinR;
  26323. var a22 = cosR + w * (1.0 - cosR);
  26324. var matrix = [a00, a01, a02, 0, 0, a10, a11, a12, 0, 0, a20, a21, a22, 0, 0, 0, 0, 0, 1, 0];
  26325. this._loadMatrix(matrix, multiply);
  26326. };
  26327. /**
  26328. * Set the contrast matrix, increase the separation between dark and bright
  26329. * Increase contrast : shadows darker and highlights brighter
  26330. * Decrease contrast : bring the shadows up and the highlights down
  26331. *
  26332. * @param {number} amount - value of the contrast (0-1)
  26333. * @param {boolean} multiply - if true, current matrix and matrix are multiplied. If false,
  26334. * just set the current matrix with @param matrix
  26335. */
  26336. ColorMatrixFilter.prototype.contrast = function contrast(amount, multiply) {
  26337. var v = (amount || 0) + 1;
  26338. var o = -0.5 * (v - 1);
  26339. var matrix = [v, 0, 0, 0, o, 0, v, 0, 0, o, 0, 0, v, 0, o, 0, 0, 0, 1, 0];
  26340. this._loadMatrix(matrix, multiply);
  26341. };
  26342. /**
  26343. * Set the saturation matrix, increase the separation between colors
  26344. * Increase saturation : increase contrast, brightness, and sharpness
  26345. *
  26346. * @param {number} amount - The saturation amount (0-1)
  26347. * @param {boolean} multiply - if true, current matrix and matrix are multiplied. If false,
  26348. * just set the current matrix with @param matrix
  26349. */
  26350. ColorMatrixFilter.prototype.saturate = function saturate() {
  26351. var amount = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
  26352. var multiply = arguments[1];
  26353. var x = amount * 2 / 3 + 1;
  26354. var y = (x - 1) * -0.5;
  26355. var matrix = [x, y, y, 0, 0, y, x, y, 0, 0, y, y, x, 0, 0, 0, 0, 0, 1, 0];
  26356. this._loadMatrix(matrix, multiply);
  26357. };
  26358. /**
  26359. * Desaturate image (remove color)
  26360. *
  26361. * Call the saturate function
  26362. *
  26363. */
  26364. ColorMatrixFilter.prototype.desaturate = function desaturate() // eslint-disable-line no-unused-vars
  26365. {
  26366. this.saturate(-1);
  26367. };
  26368. /**
  26369. * Negative image (inverse of classic rgb matrix)
  26370. *
  26371. * @param {boolean} multiply - if true, current matrix and matrix are multiplied. If false,
  26372. * just set the current matrix with @param matrix
  26373. */
  26374. ColorMatrixFilter.prototype.negative = function negative(multiply) {
  26375. var matrix = [-1, 0, 0, 1, 0, 0, -1, 0, 1, 0, 0, 0, -1, 1, 0, 0, 0, 0, 1, 0];
  26376. this._loadMatrix(matrix, multiply);
  26377. };
  26378. /**
  26379. * Sepia image
  26380. *
  26381. * @param {boolean} multiply - if true, current matrix and matrix are multiplied. If false,
  26382. * just set the current matrix with @param matrix
  26383. */
  26384. ColorMatrixFilter.prototype.sepia = function sepia(multiply) {
  26385. var matrix = [0.393, 0.7689999, 0.18899999, 0, 0, 0.349, 0.6859999, 0.16799999, 0, 0, 0.272, 0.5339999, 0.13099999, 0, 0, 0, 0, 0, 1, 0];
  26386. this._loadMatrix(matrix, multiply);
  26387. };
  26388. /**
  26389. * Color motion picture process invented in 1916 (thanks Dominic Szablewski)
  26390. *
  26391. * @param {boolean} multiply - if true, current matrix and matrix are multiplied. If false,
  26392. * just set the current matrix with @param matrix
  26393. */
  26394. ColorMatrixFilter.prototype.technicolor = function technicolor(multiply) {
  26395. var matrix = [1.9125277891456083, -0.8545344976951645, -0.09155508482755585, 0, 11.793603434377337, -0.3087833385928097, 1.7658908555458428, -0.10601743074722245, 0, -70.35205161461398, -0.231103377548616, -0.7501899197440212, 1.847597816108189, 0, 30.950940869491138, 0, 0, 0, 1, 0];
  26396. this._loadMatrix(matrix, multiply);
  26397. };
  26398. /**
  26399. * Polaroid filter
  26400. *
  26401. * @param {boolean} multiply - if true, current matrix and matrix are multiplied. If false,
  26402. * just set the current matrix with @param matrix
  26403. */
  26404. ColorMatrixFilter.prototype.polaroid = function polaroid(multiply) {
  26405. var matrix = [1.438, -0.062, -0.062, 0, 0, -0.122, 1.378, -0.122, 0, 0, -0.016, -0.016, 1.483, 0, 0, 0, 0, 0, 1, 0];
  26406. this._loadMatrix(matrix, multiply);
  26407. };
  26408. /**
  26409. * Filter who transforms : Red -> Blue and Blue -> Red
  26410. *
  26411. * @param {boolean} multiply - if true, current matrix and matrix are multiplied. If false,
  26412. * just set the current matrix with @param matrix
  26413. */
  26414. ColorMatrixFilter.prototype.toBGR = function toBGR(multiply) {
  26415. var matrix = [0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0];
  26416. this._loadMatrix(matrix, multiply);
  26417. };
  26418. /**
  26419. * Color reversal film introduced by Eastman Kodak in 1935. (thanks Dominic Szablewski)
  26420. *
  26421. * @param {boolean} multiply - if true, current matrix and matrix are multiplied. If false,
  26422. * just set the current matrix with @param matrix
  26423. */
  26424. ColorMatrixFilter.prototype.kodachrome = function kodachrome(multiply) {
  26425. var matrix = [1.1285582396593525, -0.3967382283601348, -0.03992559172921793, 0, 63.72958762196502, -0.16404339962244616, 1.0835251566291304, -0.05498805115633132, 0, 24.732407896706203, -0.16786010706155763, -0.5603416277695248, 1.6014850761964943, 0, 35.62982807460946, 0, 0, 0, 1, 0];
  26426. this._loadMatrix(matrix, multiply);
  26427. };
  26428. /**
  26429. * Brown delicious browni filter (thanks Dominic Szablewski)
  26430. *
  26431. * @param {boolean} multiply - if true, current matrix and matrix are multiplied. If false,
  26432. * just set the current matrix with @param matrix
  26433. */
  26434. ColorMatrixFilter.prototype.browni = function browni(multiply) {
  26435. var matrix = [0.5997023498159715, 0.34553243048391263, -0.2708298674538042, 0, 47.43192855600873, -0.037703249837783157, 0.8609577587992641, 0.15059552388459913, 0, -36.96841498319127, 0.24113635128153335, -0.07441037908422492, 0.44972182064877153, 0, -7.562075277591283, 0, 0, 0, 1, 0];
  26436. this._loadMatrix(matrix, multiply);
  26437. };
  26438. /**
  26439. * Vintage filter (thanks Dominic Szablewski)
  26440. *
  26441. * @param {boolean} multiply - if true, current matrix and matrix are multiplied. If false,
  26442. * just set the current matrix with @param matrix
  26443. */
  26444. ColorMatrixFilter.prototype.vintage = function vintage(multiply) {
  26445. var matrix = [0.6279345635605994, 0.3202183420819367, -0.03965408211312453, 0, 9.651285835294123, 0.02578397704808868, 0.6441188644374771, 0.03259127616149294, 0, 7.462829176470591, 0.0466055556782719, -0.0851232987247891, 0.5241648018700465, 0, 5.159190588235296, 0, 0, 0, 1, 0];
  26446. this._loadMatrix(matrix, multiply);
  26447. };
  26448. /**
  26449. * We don't know exactly what it does, kind of gradient map, but funny to play with!
  26450. *
  26451. * @param {number} desaturation - Tone values.
  26452. * @param {number} toned - Tone values.
  26453. * @param {string} lightColor - Tone values, example: `0xFFE580`
  26454. * @param {string} darkColor - Tone values, example: `0xFFE580`
  26455. * @param {boolean} multiply - if true, current matrix and matrix are multiplied. If false,
  26456. * just set the current matrix with @param matrix
  26457. */
  26458. ColorMatrixFilter.prototype.colorTone = function colorTone(desaturation, toned, lightColor, darkColor, multiply) {
  26459. desaturation = desaturation || 0.2;
  26460. toned = toned || 0.15;
  26461. lightColor = lightColor || 0xFFE580;
  26462. darkColor = darkColor || 0x338000;
  26463. var lR = (lightColor >> 16 & 0xFF) / 255;
  26464. var lG = (lightColor >> 8 & 0xFF) / 255;
  26465. var lB = (lightColor & 0xFF) / 255;
  26466. var dR = (darkColor >> 16 & 0xFF) / 255;
  26467. var dG = (darkColor >> 8 & 0xFF) / 255;
  26468. var dB = (darkColor & 0xFF) / 255;
  26469. var matrix = [0.3, 0.59, 0.11, 0, 0, lR, lG, lB, desaturation, 0, dR, dG, dB, toned, 0, lR - dR, lG - dG, lB - dB, 0, 0];
  26470. this._loadMatrix(matrix, multiply);
  26471. };
  26472. /**
  26473. * Night effect
  26474. *
  26475. * @param {number} intensity - The intensity of the night effect.
  26476. * @param {boolean} multiply - if true, current matrix and matrix are multiplied. If false,
  26477. * just set the current matrix with @param matrix
  26478. */
  26479. ColorMatrixFilter.prototype.night = function night(intensity, multiply) {
  26480. intensity = intensity || 0.1;
  26481. var matrix = [intensity * -2.0, -intensity, 0, 0, 0, -intensity, 0, intensity, 0, 0, 0, intensity, intensity * 2.0, 0, 0, 0, 0, 0, 1, 0];
  26482. this._loadMatrix(matrix, multiply);
  26483. };
  26484. /**
  26485. * Predator effect
  26486. *
  26487. * Erase the current matrix by setting a new indepent one
  26488. *
  26489. * @param {number} amount - how much the predator feels his future victim
  26490. * @param {boolean} multiply - if true, current matrix and matrix are multiplied. If false,
  26491. * just set the current matrix with @param matrix
  26492. */
  26493. ColorMatrixFilter.prototype.predator = function predator(amount, multiply) {
  26494. var matrix = [
  26495. // row 1
  26496. 11.224130630493164 * amount, -4.794486999511719 * amount, -2.8746118545532227 * amount, 0 * amount, 0.40342438220977783 * amount,
  26497. // row 2
  26498. -3.6330697536468506 * amount, 9.193157196044922 * amount, -2.951810836791992 * amount, 0 * amount, -1.316135048866272 * amount,
  26499. // row 3
  26500. -3.2184197902679443 * amount, -4.2375030517578125 * amount, 7.476448059082031 * amount, 0 * amount, 0.8044459223747253 * amount,
  26501. // row 4
  26502. 0, 0, 0, 1, 0];
  26503. this._loadMatrix(matrix, multiply);
  26504. };
  26505. /**
  26506. * LSD effect
  26507. *
  26508. * Multiply the current matrix
  26509. *
  26510. * @param {boolean} multiply - if true, current matrix and matrix are multiplied. If false,
  26511. * just set the current matrix with @param matrix
  26512. */
  26513. ColorMatrixFilter.prototype.lsd = function lsd(multiply) {
  26514. var matrix = [2, -0.4, 0.5, 0, 0, -0.5, 2, -0.4, 0, 0, -0.4, -0.5, 3, 0, 0, 0, 0, 0, 1, 0];
  26515. this._loadMatrix(matrix, multiply);
  26516. };
  26517. /**
  26518. * Erase the current matrix by setting the default one
  26519. *
  26520. */
  26521. ColorMatrixFilter.prototype.reset = function reset() {
  26522. var matrix = [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0];
  26523. this._loadMatrix(matrix, false);
  26524. };
  26525. /**
  26526. * The matrix of the color matrix filter
  26527. *
  26528. * @member {number[]}
  26529. * @default [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0]
  26530. */
  26531. _createClass(ColorMatrixFilter, [{
  26532. key: 'matrix',
  26533. get: function get() {
  26534. return this.uniforms.m;
  26535. },
  26536. set: function set(value) // eslint-disable-line require-jsdoc
  26537. {
  26538. this.uniforms.m = value;
  26539. }
  26540. /**
  26541. * The opacity value to use when mixing the original and resultant colors.
  26542. *
  26543. * When the value is 0, the original color is used without modification.
  26544. * When the value is 1, the result color is used.
  26545. * When in the range (0, 1) the color is interpolated between the original and result by this amount.
  26546. *
  26547. * @member {number}
  26548. * @default 1
  26549. */
  26550. }, {
  26551. key: 'alpha',
  26552. get: function get() {
  26553. return this.uniforms.uAlpha;
  26554. },
  26555. set: function set(value) // eslint-disable-line require-jsdoc
  26556. {
  26557. this.uniforms.uAlpha = value;
  26558. }
  26559. }]);
  26560. return ColorMatrixFilter;
  26561. }(core.Filter);
  26562. // Americanized alias
  26563. exports.default = ColorMatrixFilter;
  26564. ColorMatrixFilter.prototype.grayscale = ColorMatrixFilter.prototype.greyscale;
  26565. }, { "../../core": 65, "path": 8 }], 151: [function (require, module, exports) {
  26566. 'use strict';
  26567. exports.__esModule = true;
  26568. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  26569. var _core = require('../../core');
  26570. var core = _interopRequireWildcard(_core);
  26571. var _path = require('path');
  26572. function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
  26573. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  26574. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  26575. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  26576. /**
  26577. * The DisplacementFilter class uses the pixel values from the specified texture
  26578. * (called the displacement map) to perform a displacement of an object. You can
  26579. * use this filter to apply all manor of crazy warping effects. Currently the r
  26580. * property of the texture is used to offset the x and the g property of the texture
  26581. * is used to offset the y.
  26582. *
  26583. * @class
  26584. * @extends PIXI.Filter
  26585. * @memberof PIXI.filters
  26586. */
  26587. var DisplacementFilter = function (_core$Filter) {
  26588. _inherits(DisplacementFilter, _core$Filter);
  26589. /**
  26590. * @param {PIXI.Sprite} sprite - The sprite used for the displacement map. (make sure its added to the scene!)
  26591. * @param {number} scale - The scale of the displacement
  26592. */
  26593. function DisplacementFilter(sprite, scale) {
  26594. _classCallCheck(this, DisplacementFilter);
  26595. var maskMatrix = new core.Matrix();
  26596. sprite.renderable = false;
  26597. var _this = _possibleConstructorReturn(this, _core$Filter.call(this,
  26598. // vertex shader
  26599. 'attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\n\nuniform mat3 projectionMatrix;\nuniform mat3 filterMatrix;\n\nvarying vec2 vTextureCoord;\nvarying vec2 vFilterCoord;\n\nvoid main(void)\n{\n gl_Position = vec4((projectionMatrix * vec3(aVertexPosition, 1.0)).xy, 0.0, 1.0);\n vFilterCoord = ( filterMatrix * vec3( aTextureCoord, 1.0) ).xy;\n vTextureCoord = aTextureCoord;\n}',
  26600. // fragment shader
  26601. 'varying vec2 vFilterCoord;\nvarying vec2 vTextureCoord;\n\nuniform vec2 scale;\n\nuniform sampler2D uSampler;\nuniform sampler2D mapSampler;\n\nuniform vec4 filterArea;\nuniform vec4 filterClamp;\n\nvoid main(void)\n{\n vec4 map = texture2D(mapSampler, vFilterCoord);\n\n map -= 0.5;\n map.xy *= scale / filterArea.xy;\n\n gl_FragColor = texture2D(uSampler, clamp(vec2(vTextureCoord.x + map.x, vTextureCoord.y + map.y), filterClamp.xy, filterClamp.zw));\n}\n'));
  26602. _this.maskSprite = sprite;
  26603. _this.maskMatrix = maskMatrix;
  26604. _this.uniforms.mapSampler = sprite._texture;
  26605. _this.uniforms.filterMatrix = maskMatrix;
  26606. _this.uniforms.scale = { x: 1, y: 1 };
  26607. if (scale === null || scale === undefined) {
  26608. scale = 20;
  26609. }
  26610. _this.scale = new core.Point(scale, scale);
  26611. return _this;
  26612. }
  26613. /**
  26614. * Applies the filter.
  26615. *
  26616. * @param {PIXI.FilterManager} filterManager - The manager.
  26617. * @param {PIXI.RenderTarget} input - The input target.
  26618. * @param {PIXI.RenderTarget} output - The output target.
  26619. */
  26620. DisplacementFilter.prototype.apply = function apply(filterManager, input, output) {
  26621. this.uniforms.filterMatrix = filterManager.calculateSpriteMatrix(this.maskMatrix, this.maskSprite);
  26622. this.uniforms.scale.x = this.scale.x;
  26623. this.uniforms.scale.y = this.scale.y;
  26624. // draw the filter...
  26625. filterManager.applyFilter(this, input, output);
  26626. };
  26627. /**
  26628. * The texture used for the displacement map. Must be power of 2 sized texture.
  26629. *
  26630. * @member {PIXI.Texture}
  26631. */
  26632. _createClass(DisplacementFilter, [{
  26633. key: 'map',
  26634. get: function get() {
  26635. return this.uniforms.mapSampler;
  26636. },
  26637. set: function set(value) // eslint-disable-line require-jsdoc
  26638. {
  26639. this.uniforms.mapSampler = value;
  26640. }
  26641. }]);
  26642. return DisplacementFilter;
  26643. }(core.Filter);
  26644. exports.default = DisplacementFilter;
  26645. }, { "../../core": 65, "path": 8 }], 152: [function (require, module, exports) {
  26646. 'use strict';
  26647. exports.__esModule = true;
  26648. var _core = require('../../core');
  26649. var core = _interopRequireWildcard(_core);
  26650. var _path = require('path');
  26651. function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
  26652. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  26653. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  26654. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  26655. /**
  26656. *
  26657. * Basic FXAA implementation based on the code on geeks3d.com with the
  26658. * modification that the texture2DLod stuff was removed since it's
  26659. * unsupported by WebGL.
  26660. *
  26661. * @see https://github.com/mitsuhiko/webgl-meincraft
  26662. *
  26663. * @class
  26664. * @extends PIXI.Filter
  26665. * @memberof PIXI.filters
  26666. *
  26667. */
  26668. var FXAAFilter = function (_core$Filter) {
  26669. _inherits(FXAAFilter, _core$Filter);
  26670. /**
  26671. *
  26672. */
  26673. function FXAAFilter() {
  26674. _classCallCheck(this, FXAAFilter);
  26675. // TODO - needs work
  26676. return _possibleConstructorReturn(this, _core$Filter.call(this,
  26677. // vertex shader
  26678. '\nattribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\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\nuniform vec4 filterArea;\n\nvarying vec2 vTextureCoord;\n\nvec2 mapCoord( vec2 coord )\n{\n coord *= filterArea.xy;\n coord += filterArea.zw;\n\n return coord;\n}\n\nvec2 unmapCoord( vec2 coord )\n{\n coord -= filterArea.zw;\n coord /= filterArea.xy;\n\n return coord;\n}\n\nvoid texcoords(vec2 fragCoord, vec2 resolution,\n out vec2 v_rgbNW, out vec2 v_rgbNE,\n out vec2 v_rgbSW, out vec2 v_rgbSE,\n out vec2 v_rgbM) {\n vec2 inverseVP = 1.0 / resolution.xy;\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 = vec4((projectionMatrix * vec3(aVertexPosition, 1.0)).xy, 0.0, 1.0);\n\n vTextureCoord = aTextureCoord;\n\n vec2 fragCoord = vTextureCoord * filterArea.xy;\n\n texcoords(fragCoord, filterArea.xy, v_rgbNW, v_rgbNE, v_rgbSW, v_rgbSE, v_rgbM);\n}',
  26679. // fragment shader
  26680. 'varying vec2 v_rgbNW;\nvarying vec2 v_rgbNE;\nvarying vec2 v_rgbSW;\nvarying vec2 v_rgbSE;\nvarying vec2 v_rgbM;\n\nvarying vec2 vTextureCoord;\nuniform sampler2D uSampler;\nuniform vec4 filterArea;\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 resolution,\n vec2 v_rgbNW, vec2 v_rgbNE,\n vec2 v_rgbSW, vec2 v_rgbSE,\n vec2 v_rgbM) {\n vec4 color;\n mediump vec2 inverseVP = vec2(1.0 / resolution.x, 1.0 / resolution.y);\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 vec2 fragCoord = vTextureCoord * filterArea.xy;\n\n vec4 color;\n\n color = fxaa(uSampler, fragCoord, filterArea.xy, v_rgbNW, v_rgbNE, v_rgbSW, v_rgbSE, v_rgbM);\n\n gl_FragColor = color;\n}\n'));
  26681. }
  26682. return FXAAFilter;
  26683. }(core.Filter);
  26684. exports.default = FXAAFilter;
  26685. }, { "../../core": 65, "path": 8 }], 153: [function (require, module, exports) {
  26686. 'use strict';
  26687. exports.__esModule = true;
  26688. var _FXAAFilter = require('./fxaa/FXAAFilter');
  26689. Object.defineProperty(exports, 'FXAAFilter', {
  26690. enumerable: true,
  26691. get: function get() {
  26692. return _interopRequireDefault(_FXAAFilter).default;
  26693. }
  26694. });
  26695. var _NoiseFilter = require('./noise/NoiseFilter');
  26696. Object.defineProperty(exports, 'NoiseFilter', {
  26697. enumerable: true,
  26698. get: function get() {
  26699. return _interopRequireDefault(_NoiseFilter).default;
  26700. }
  26701. });
  26702. var _DisplacementFilter = require('./displacement/DisplacementFilter');
  26703. Object.defineProperty(exports, 'DisplacementFilter', {
  26704. enumerable: true,
  26705. get: function get() {
  26706. return _interopRequireDefault(_DisplacementFilter).default;
  26707. }
  26708. });
  26709. var _BlurFilter = require('./blur/BlurFilter');
  26710. Object.defineProperty(exports, 'BlurFilter', {
  26711. enumerable: true,
  26712. get: function get() {
  26713. return _interopRequireDefault(_BlurFilter).default;
  26714. }
  26715. });
  26716. var _BlurXFilter = require('./blur/BlurXFilter');
  26717. Object.defineProperty(exports, 'BlurXFilter', {
  26718. enumerable: true,
  26719. get: function get() {
  26720. return _interopRequireDefault(_BlurXFilter).default;
  26721. }
  26722. });
  26723. var _BlurYFilter = require('./blur/BlurYFilter');
  26724. Object.defineProperty(exports, 'BlurYFilter', {
  26725. enumerable: true,
  26726. get: function get() {
  26727. return _interopRequireDefault(_BlurYFilter).default;
  26728. }
  26729. });
  26730. var _ColorMatrixFilter = require('./colormatrix/ColorMatrixFilter');
  26731. Object.defineProperty(exports, 'ColorMatrixFilter', {
  26732. enumerable: true,
  26733. get: function get() {
  26734. return _interopRequireDefault(_ColorMatrixFilter).default;
  26735. }
  26736. });
  26737. var _AlphaFilter = require('./alpha/AlphaFilter');
  26738. Object.defineProperty(exports, 'AlphaFilter', {
  26739. enumerable: true,
  26740. get: function get() {
  26741. return _interopRequireDefault(_AlphaFilter).default;
  26742. }
  26743. });
  26744. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  26745. }, { "./alpha/AlphaFilter": 143, "./blur/BlurFilter": 144, "./blur/BlurXFilter": 145, "./blur/BlurYFilter": 146, "./colormatrix/ColorMatrixFilter": 150, "./displacement/DisplacementFilter": 151, "./fxaa/FXAAFilter": 152, "./noise/NoiseFilter": 154 }], 154: [function (require, module, exports) {
  26746. 'use strict';
  26747. exports.__esModule = true;
  26748. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  26749. var _core = require('../../core');
  26750. var core = _interopRequireWildcard(_core);
  26751. var _path = require('path');
  26752. function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
  26753. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  26754. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  26755. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  26756. /**
  26757. * @author Vico @vicocotea
  26758. * original filter: https://github.com/evanw/glfx.js/blob/master/src/filters/adjust/noise.js
  26759. */
  26760. /**
  26761. * A Noise effect filter.
  26762. *
  26763. * @class
  26764. * @extends PIXI.Filter
  26765. * @memberof PIXI.filters
  26766. */
  26767. var NoiseFilter = function (_core$Filter) {
  26768. _inherits(NoiseFilter, _core$Filter);
  26769. /**
  26770. * @param {number} noise - The noise intensity, should be a normalized value in the range [0, 1].
  26771. * @param {number} seed - A random seed for the noise generation. Default is `Math.random()`.
  26772. */
  26773. function NoiseFilter() {
  26774. var noise = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0.5;
  26775. var seed = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : Math.random();
  26776. _classCallCheck(this, NoiseFilter);
  26777. var _this = _possibleConstructorReturn(this, _core$Filter.call(this,
  26778. // vertex shader
  26779. '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}',
  26780. // fragment shader
  26781. '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'));
  26782. _this.noise = noise;
  26783. _this.seed = seed;
  26784. return _this;
  26785. }
  26786. /**
  26787. * The amount of noise to apply, this value should be in the range (0, 1].
  26788. *
  26789. * @member {number}
  26790. * @default 0.5
  26791. */
  26792. _createClass(NoiseFilter, [{
  26793. key: 'noise',
  26794. get: function get() {
  26795. return this.uniforms.uNoise;
  26796. },
  26797. set: function set(value) // eslint-disable-line require-jsdoc
  26798. {
  26799. this.uniforms.uNoise = value;
  26800. }
  26801. /**
  26802. * A seed value to apply to the random noise generation. `Math.random()` is a good value to use.
  26803. *
  26804. * @member {number}
  26805. */
  26806. }, {
  26807. key: 'seed',
  26808. get: function get() {
  26809. return this.uniforms.uSeed;
  26810. },
  26811. set: function set(value) // eslint-disable-line require-jsdoc
  26812. {
  26813. this.uniforms.uSeed = value;
  26814. }
  26815. }]);
  26816. return NoiseFilter;
  26817. }(core.Filter);
  26818. exports.default = NoiseFilter;
  26819. }, { "../../core": 65, "path": 8 }], 155: [function (require, module, exports) {
  26820. 'use strict';
  26821. exports.__esModule = true;
  26822. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  26823. var _core = require('../core');
  26824. var core = _interopRequireWildcard(_core);
  26825. function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
  26826. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  26827. /**
  26828. * Holds all information related to an Interaction event
  26829. *
  26830. * @class
  26831. * @memberof PIXI.interaction
  26832. */
  26833. var InteractionData = function () {
  26834. /**
  26835. *
  26836. */
  26837. function InteractionData() {
  26838. _classCallCheck(this, InteractionData);
  26839. /**
  26840. * This point stores the global coords of where the touch/mouse event happened
  26841. *
  26842. * @member {PIXI.Point}
  26843. */
  26844. this.global = new core.Point();
  26845. /**
  26846. * The target DisplayObject that was interacted with
  26847. *
  26848. * @member {PIXI.DisplayObject}
  26849. */
  26850. this.target = null;
  26851. /**
  26852. * When passed to an event handler, this will be the original DOM Event that was captured
  26853. *
  26854. * @see https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent
  26855. * @see https://developer.mozilla.org/en-US/docs/Web/API/TouchEvent
  26856. * @see https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent
  26857. * @member {MouseEvent|TouchEvent|PointerEvent}
  26858. */
  26859. this.originalEvent = null;
  26860. /**
  26861. * Unique identifier for this interaction
  26862. *
  26863. * @member {number}
  26864. */
  26865. this.identifier = null;
  26866. /**
  26867. * Indicates whether or not the pointer device that created the event is the primary pointer.
  26868. * @see https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/isPrimary
  26869. * @type {Boolean}
  26870. */
  26871. this.isPrimary = false;
  26872. /**
  26873. * Indicates which button was pressed on the mouse or pointer device to trigger the event.
  26874. * @see https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/button
  26875. * @type {number}
  26876. */
  26877. this.button = 0;
  26878. /**
  26879. * Indicates which buttons are pressed on the mouse or pointer device when the event is triggered.
  26880. * @see https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/buttons
  26881. * @type {number}
  26882. */
  26883. this.buttons = 0;
  26884. /**
  26885. * The width of the pointer's contact along the x-axis, measured in CSS pixels.
  26886. * radiusX of TouchEvents will be represented by this value.
  26887. * @see https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/width
  26888. * @type {number}
  26889. */
  26890. this.width = 0;
  26891. /**
  26892. * The height of the pointer's contact along the y-axis, measured in CSS pixels.
  26893. * radiusY of TouchEvents will be represented by this value.
  26894. * @see https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/height
  26895. * @type {number}
  26896. */
  26897. this.height = 0;
  26898. /**
  26899. * The angle, in degrees, between the pointer device and the screen.
  26900. * @see https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/tiltX
  26901. * @type {number}
  26902. */
  26903. this.tiltX = 0;
  26904. /**
  26905. * The angle, in degrees, between the pointer device and the screen.
  26906. * @see https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/tiltY
  26907. * @type {number}
  26908. */
  26909. this.tiltY = 0;
  26910. /**
  26911. * The type of pointer that triggered the event.
  26912. * @see https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/pointerType
  26913. * @type {string}
  26914. */
  26915. this.pointerType = null;
  26916. /**
  26917. * Pressure applied by the pointing device during the event. A Touch's force property
  26918. * will be represented by this value.
  26919. * @see https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/pressure
  26920. * @type {number}
  26921. */
  26922. this.pressure = 0;
  26923. /**
  26924. * From TouchEvents (not PointerEvents triggered by touches), the rotationAngle of the Touch.
  26925. * @see https://developer.mozilla.org/en-US/docs/Web/API/Touch/rotationAngle
  26926. * @type {number}
  26927. */
  26928. this.rotationAngle = 0;
  26929. /**
  26930. * Twist of a stylus pointer.
  26931. * @see https://w3c.github.io/pointerevents/#pointerevent-interface
  26932. * @type {number}
  26933. */
  26934. this.twist = 0;
  26935. /**
  26936. * Barrel pressure on a stylus pointer.
  26937. * @see https://w3c.github.io/pointerevents/#pointerevent-interface
  26938. * @type {number}
  26939. */
  26940. this.tangentialPressure = 0;
  26941. }
  26942. /**
  26943. * The unique identifier of the pointer. It will be the same as `identifier`.
  26944. * @readonly
  26945. * @member {number}
  26946. * @see https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/pointerId
  26947. */
  26948. /**
  26949. * This will return the local coordinates of the specified displayObject for this InteractionData
  26950. *
  26951. * @param {PIXI.DisplayObject} displayObject - The DisplayObject that you would like the local
  26952. * coords off
  26953. * @param {PIXI.Point} [point] - A Point object in which to store the value, optional (otherwise
  26954. * will create a new point)
  26955. * @param {PIXI.Point} [globalPos] - A Point object containing your custom global coords, optional
  26956. * (otherwise will use the current global coords)
  26957. * @return {PIXI.Point} A point containing the coordinates of the InteractionData position relative
  26958. * to the DisplayObject
  26959. */
  26960. InteractionData.prototype.getLocalPosition = function getLocalPosition(displayObject, point, globalPos) {
  26961. return displayObject.worldTransform.applyInverse(globalPos || this.global, point);
  26962. };
  26963. /**
  26964. * Copies properties from normalized event data.
  26965. *
  26966. * @param {Touch|MouseEvent|PointerEvent} event The normalized event data
  26967. */
  26968. InteractionData.prototype.copyEvent = function copyEvent(event) {
  26969. // isPrimary should only change on touchstart/pointerdown, so we don't want to overwrite
  26970. // it with "false" on later events when our shim for it on touch events might not be
  26971. // accurate
  26972. if (event.isPrimary) {
  26973. this.isPrimary = true;
  26974. }
  26975. this.button = event.button;
  26976. // event.buttons is not available in all browsers (ie. Safari), but it does have a non-standard
  26977. // event.which property instead, which conveys the same information.
  26978. this.buttons = Number.isInteger(event.buttons) ? event.buttons : event.which;
  26979. this.width = event.width;
  26980. this.height = event.height;
  26981. this.tiltX = event.tiltX;
  26982. this.tiltY = event.tiltY;
  26983. this.pointerType = event.pointerType;
  26984. this.pressure = event.pressure;
  26985. this.rotationAngle = event.rotationAngle;
  26986. this.twist = event.twist || 0;
  26987. this.tangentialPressure = event.tangentialPressure || 0;
  26988. };
  26989. /**
  26990. * Resets the data for pooling.
  26991. */
  26992. InteractionData.prototype.reset = function reset() {
  26993. // isPrimary is the only property that we really need to reset - everything else is
  26994. // guaranteed to be overwritten
  26995. this.isPrimary = false;
  26996. };
  26997. _createClass(InteractionData, [{
  26998. key: 'pointerId',
  26999. get: function get() {
  27000. return this.identifier;
  27001. }
  27002. }]);
  27003. return InteractionData;
  27004. }();
  27005. exports.default = InteractionData;
  27006. }, { "../core": 65 }], 156: [function (require, module, exports) {
  27007. "use strict";
  27008. exports.__esModule = true;
  27009. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  27010. /**
  27011. * Event class that mimics native DOM events.
  27012. *
  27013. * @class
  27014. * @memberof PIXI.interaction
  27015. */
  27016. var InteractionEvent = function () {
  27017. /**
  27018. *
  27019. */
  27020. function InteractionEvent() {
  27021. _classCallCheck(this, InteractionEvent);
  27022. /**
  27023. * Whether this event will continue propagating in the tree
  27024. *
  27025. * @member {boolean}
  27026. */
  27027. this.stopped = false;
  27028. /**
  27029. * The object which caused this event to be dispatched.
  27030. * For listener callback see {@link PIXI.interaction.InteractionEvent.currentTarget}.
  27031. *
  27032. * @member {PIXI.DisplayObject}
  27033. */
  27034. this.target = null;
  27035. /**
  27036. * The object whose event listener’s callback is currently being invoked.
  27037. *
  27038. * @member {PIXI.DisplayObject}
  27039. */
  27040. this.currentTarget = null;
  27041. /**
  27042. * Type of the event
  27043. *
  27044. * @member {string}
  27045. */
  27046. this.type = null;
  27047. /**
  27048. * InteractionData related to this event
  27049. *
  27050. * @member {PIXI.interaction.InteractionData}
  27051. */
  27052. this.data = null;
  27053. }
  27054. /**
  27055. * Prevents event from reaching any objects other than the current object.
  27056. *
  27057. */
  27058. InteractionEvent.prototype.stopPropagation = function stopPropagation() {
  27059. this.stopped = true;
  27060. };
  27061. /**
  27062. * Resets the event.
  27063. */
  27064. InteractionEvent.prototype.reset = function reset() {
  27065. this.stopped = false;
  27066. this.currentTarget = null;
  27067. this.target = null;
  27068. };
  27069. return InteractionEvent;
  27070. }();
  27071. exports.default = InteractionEvent;
  27072. }, {}], 157: [function (require, module, exports) {
  27073. 'use strict';
  27074. exports.__esModule = true;
  27075. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
  27076. var _core = require('../core');
  27077. var core = _interopRequireWildcard(_core);
  27078. var _InteractionData = require('./InteractionData');
  27079. var _InteractionData2 = _interopRequireDefault(_InteractionData);
  27080. var _InteractionEvent = require('./InteractionEvent');
  27081. var _InteractionEvent2 = _interopRequireDefault(_InteractionEvent);
  27082. var _InteractionTrackingData = require('./InteractionTrackingData');
  27083. var _InteractionTrackingData2 = _interopRequireDefault(_InteractionTrackingData);
  27084. var _eventemitter = require('eventemitter3');
  27085. var _eventemitter2 = _interopRequireDefault(_eventemitter);
  27086. var _interactiveTarget = require('./interactiveTarget');
  27087. var _interactiveTarget2 = _interopRequireDefault(_interactiveTarget);
  27088. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  27089. function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
  27090. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  27091. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  27092. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  27093. // Mix interactiveTarget into core.DisplayObject.prototype, after deprecation has been handled
  27094. core.utils.mixins.delayMixin(core.DisplayObject.prototype, _interactiveTarget2.default);
  27095. var MOUSE_POINTER_ID = 1;
  27096. // helpers for hitTest() - only used inside hitTest()
  27097. var hitTestEvent = {
  27098. target: null,
  27099. data: {
  27100. global: null
  27101. }
  27102. };
  27103. /**
  27104. * The interaction manager deals with mouse, touch and pointer events. Any DisplayObject can be interactive
  27105. * if its interactive parameter is set to true
  27106. * This manager also supports multitouch.
  27107. *
  27108. * An instance of this class is automatically created by default, and can be found at renderer.plugins.interaction
  27109. *
  27110. * @class
  27111. * @extends EventEmitter
  27112. * @memberof PIXI.interaction
  27113. */
  27114. var InteractionManager = function (_EventEmitter) {
  27115. _inherits(InteractionManager, _EventEmitter);
  27116. /**
  27117. * @param {PIXI.CanvasRenderer|PIXI.WebGLRenderer} renderer - A reference to the current renderer
  27118. * @param {object} [options] - The options for the manager.
  27119. * @param {boolean} [options.autoPreventDefault=true] - Should the manager automatically prevent default browser actions.
  27120. * @param {number} [options.interactionFrequency=10] - Frequency increases the interaction events will be checked.
  27121. */
  27122. function InteractionManager(renderer, options) {
  27123. _classCallCheck(this, InteractionManager);
  27124. var _this = _possibleConstructorReturn(this, _EventEmitter.call(this));
  27125. options = options || {};
  27126. /**
  27127. * The renderer this interaction manager works for.
  27128. *
  27129. * @member {PIXI.SystemRenderer}
  27130. */
  27131. _this.renderer = renderer;
  27132. /**
  27133. * Should default browser actions automatically be prevented.
  27134. * Does not apply to pointer events for backwards compatibility
  27135. * preventDefault on pointer events stops mouse events from firing
  27136. * Thus, for every pointer event, there will always be either a mouse of touch event alongside it.
  27137. *
  27138. * @member {boolean}
  27139. * @default true
  27140. */
  27141. _this.autoPreventDefault = options.autoPreventDefault !== undefined ? options.autoPreventDefault : true;
  27142. /**
  27143. * Frequency in milliseconds that the mousemove, moveover & mouseout interaction events will be checked.
  27144. *
  27145. * @member {number}
  27146. * @default 10
  27147. */
  27148. _this.interactionFrequency = options.interactionFrequency || 10;
  27149. /**
  27150. * The mouse data
  27151. *
  27152. * @member {PIXI.interaction.InteractionData}
  27153. */
  27154. _this.mouse = new _InteractionData2.default();
  27155. _this.mouse.identifier = MOUSE_POINTER_ID;
  27156. // setting the mouse to start off far off screen will mean that mouse over does
  27157. // not get called before we even move the mouse.
  27158. _this.mouse.global.set(-999999);
  27159. /**
  27160. * Actively tracked InteractionData
  27161. *
  27162. * @private
  27163. * @member {Object.<number,PIXI.interation.InteractionData>}
  27164. */
  27165. _this.activeInteractionData = {};
  27166. _this.activeInteractionData[MOUSE_POINTER_ID] = _this.mouse;
  27167. /**
  27168. * Pool of unused InteractionData
  27169. *
  27170. * @private
  27171. * @member {PIXI.interation.InteractionData[]}
  27172. */
  27173. _this.interactionDataPool = [];
  27174. /**
  27175. * An event data object to handle all the event tracking/dispatching
  27176. *
  27177. * @member {object}
  27178. */
  27179. _this.eventData = new _InteractionEvent2.default();
  27180. /**
  27181. * The DOM element to bind to.
  27182. *
  27183. * @private
  27184. * @member {HTMLElement}
  27185. */
  27186. _this.interactionDOMElement = null;
  27187. /**
  27188. * This property determines if mousemove and touchmove events are fired only when the cursor
  27189. * is over the object.
  27190. * Setting to true will make things work more in line with how the DOM verison works.
  27191. * Setting to false can make things easier for things like dragging
  27192. * It is currently set to false as this is how PixiJS used to work. This will be set to true in
  27193. * future versions of pixi.
  27194. *
  27195. * @member {boolean}
  27196. * @default false
  27197. */
  27198. _this.moveWhenInside = false;
  27199. /**
  27200. * Have events been attached to the dom element?
  27201. *
  27202. * @private
  27203. * @member {boolean}
  27204. */
  27205. _this.eventsAdded = false;
  27206. /**
  27207. * Is the mouse hovering over the renderer?
  27208. *
  27209. * @private
  27210. * @member {boolean}
  27211. */
  27212. _this.mouseOverRenderer = false;
  27213. /**
  27214. * Does the device support touch events
  27215. * https://www.w3.org/TR/touch-events/
  27216. *
  27217. * @readonly
  27218. * @member {boolean}
  27219. */
  27220. _this.supportsTouchEvents = 'ontouchstart' in window;
  27221. /**
  27222. * Does the device support pointer events
  27223. * https://www.w3.org/Submission/pointer-events/
  27224. *
  27225. * @readonly
  27226. * @member {boolean}
  27227. */
  27228. _this.supportsPointerEvents = !!window.PointerEvent;
  27229. // this will make it so that you don't have to call bind all the time
  27230. /**
  27231. * @private
  27232. * @member {Function}
  27233. */
  27234. _this.onPointerUp = _this.onPointerUp.bind(_this);
  27235. _this.processPointerUp = _this.processPointerUp.bind(_this);
  27236. /**
  27237. * @private
  27238. * @member {Function}
  27239. */
  27240. _this.onPointerCancel = _this.onPointerCancel.bind(_this);
  27241. _this.processPointerCancel = _this.processPointerCancel.bind(_this);
  27242. /**
  27243. * @private
  27244. * @member {Function}
  27245. */
  27246. _this.onPointerDown = _this.onPointerDown.bind(_this);
  27247. _this.processPointerDown = _this.processPointerDown.bind(_this);
  27248. /**
  27249. * @private
  27250. * @member {Function}
  27251. */
  27252. _this.onPointerMove = _this.onPointerMove.bind(_this);
  27253. _this.processPointerMove = _this.processPointerMove.bind(_this);
  27254. /**
  27255. * @private
  27256. * @member {Function}
  27257. */
  27258. _this.onPointerOut = _this.onPointerOut.bind(_this);
  27259. _this.processPointerOverOut = _this.processPointerOverOut.bind(_this);
  27260. /**
  27261. * @private
  27262. * @member {Function}
  27263. */
  27264. _this.onPointerOver = _this.onPointerOver.bind(_this);
  27265. /**
  27266. * Dictionary of how different cursor modes are handled. Strings are handled as CSS cursor
  27267. * values, objects are handled as dictionaries of CSS values for interactionDOMElement,
  27268. * and functions are called instead of changing the CSS.
  27269. * Default CSS cursor values are provided for 'default' and 'pointer' modes.
  27270. * @member {Object.<string, (string|Function|Object.<string, string>)>}
  27271. */
  27272. _this.cursorStyles = {
  27273. default: 'inherit',
  27274. pointer: 'pointer'
  27275. };
  27276. /**
  27277. * The mode of the cursor that is being used.
  27278. * The value of this is a key from the cursorStyles dictionary.
  27279. *
  27280. * @member {string}
  27281. */
  27282. _this.currentCursorMode = null;
  27283. /**
  27284. * Internal cached let.
  27285. *
  27286. * @private
  27287. * @member {string}
  27288. */
  27289. _this.cursor = null;
  27290. /**
  27291. * Internal cached let.
  27292. *
  27293. * @private
  27294. * @member {PIXI.Point}
  27295. */
  27296. _this._tempPoint = new core.Point();
  27297. /**
  27298. * The current resolution / device pixel ratio.
  27299. *
  27300. * @member {number}
  27301. * @default 1
  27302. */
  27303. _this.resolution = 1;
  27304. _this.setTargetElement(_this.renderer.view, _this.renderer.resolution);
  27305. /**
  27306. * Fired when a pointer device button (usually a mouse left-button) is pressed on the display
  27307. * object.
  27308. *
  27309. * @event PIXI.interaction.InteractionManager#mousedown
  27310. * @param {PIXI.interaction.InteractionEvent} event - Interaction event
  27311. */
  27312. /**
  27313. * Fired when a pointer device secondary button (usually a mouse right-button) is pressed
  27314. * on the display object.
  27315. *
  27316. * @event PIXI.interaction.InteractionManager#rightdown
  27317. * @param {PIXI.interaction.InteractionEvent} event - Interaction event
  27318. */
  27319. /**
  27320. * Fired when a pointer device button (usually a mouse left-button) is released over the display
  27321. * object.
  27322. *
  27323. * @event PIXI.interaction.InteractionManager#mouseup
  27324. * @param {PIXI.interaction.InteractionEvent} event - Interaction event
  27325. */
  27326. /**
  27327. * Fired when a pointer device secondary button (usually a mouse right-button) is released
  27328. * over the display object.
  27329. *
  27330. * @event PIXI.interaction.InteractionManager#rightup
  27331. * @param {PIXI.interaction.InteractionEvent} event - Interaction event
  27332. */
  27333. /**
  27334. * Fired when a pointer device button (usually a mouse left-button) is pressed and released on
  27335. * the display object.
  27336. *
  27337. * @event PIXI.interaction.InteractionManager#click
  27338. * @param {PIXI.interaction.InteractionEvent} event - Interaction event
  27339. */
  27340. /**
  27341. * Fired when a pointer device secondary button (usually a mouse right-button) is pressed
  27342. * and released on the display object.
  27343. *
  27344. * @event PIXI.interaction.InteractionManager#rightclick
  27345. * @param {PIXI.interaction.InteractionEvent} event - Interaction event
  27346. */
  27347. /**
  27348. * Fired when a pointer device button (usually a mouse left-button) is released outside the
  27349. * display object that initially registered a
  27350. * [mousedown]{@link PIXI.interaction.InteractionManager#event:mousedown}.
  27351. *
  27352. * @event PIXI.interaction.InteractionManager#mouseupoutside
  27353. * @param {PIXI.interaction.InteractionEvent} event - Interaction event
  27354. */
  27355. /**
  27356. * Fired when a pointer device secondary button (usually a mouse right-button) is released
  27357. * outside the display object that initially registered a
  27358. * [rightdown]{@link PIXI.interaction.InteractionManager#event:rightdown}.
  27359. *
  27360. * @event PIXI.interaction.InteractionManager#rightupoutside
  27361. * @param {PIXI.interaction.InteractionEvent} event - Interaction event
  27362. */
  27363. /**
  27364. * Fired when a pointer device (usually a mouse) is moved while over the display object
  27365. *
  27366. * @event PIXI.interaction.InteractionManager#mousemove
  27367. * @param {PIXI.interaction.InteractionEvent} event - Interaction event
  27368. */
  27369. /**
  27370. * Fired when a pointer device (usually a mouse) is moved onto the display object
  27371. *
  27372. * @event PIXI.interaction.InteractionManager#mouseover
  27373. * @param {PIXI.interaction.InteractionEvent} event - Interaction event
  27374. */
  27375. /**
  27376. * Fired when a pointer device (usually a mouse) is moved off the display object
  27377. *
  27378. * @event PIXI.interaction.InteractionManager#mouseout
  27379. * @param {PIXI.interaction.InteractionEvent} event - Interaction event
  27380. */
  27381. /**
  27382. * Fired when a pointer device button is pressed on the display object.
  27383. *
  27384. * @event PIXI.interaction.InteractionManager#pointerdown
  27385. * @param {PIXI.interaction.InteractionEvent} event - Interaction event
  27386. */
  27387. /**
  27388. * Fired when a pointer device button is released over the display object.
  27389. *
  27390. * @event PIXI.interaction.InteractionManager#pointerup
  27391. * @param {PIXI.interaction.InteractionEvent} event - Interaction event
  27392. */
  27393. /**
  27394. * Fired when the operating system cancels a pointer event
  27395. *
  27396. * @event PIXI.interaction.InteractionManager#pointercancel
  27397. * @param {PIXI.interaction.InteractionEvent} event - Interaction event
  27398. */
  27399. /**
  27400. * Fired when a pointer device button is pressed and released on the display object.
  27401. *
  27402. * @event PIXI.interaction.InteractionManager#pointertap
  27403. * @param {PIXI.interaction.InteractionEvent} event - Interaction event
  27404. */
  27405. /**
  27406. * Fired when a pointer device button is released outside the display object that initially
  27407. * registered a [pointerdown]{@link PIXI.interaction.InteractionManager#event:pointerdown}.
  27408. *
  27409. * @event PIXI.interaction.InteractionManager#pointerupoutside
  27410. * @param {PIXI.interaction.InteractionEvent} event - Interaction event
  27411. */
  27412. /**
  27413. * Fired when a pointer device is moved while over the display object
  27414. *
  27415. * @event PIXI.interaction.InteractionManager#pointermove
  27416. * @param {PIXI.interaction.InteractionEvent} event - Interaction event
  27417. */
  27418. /**
  27419. * Fired when a pointer device is moved onto the display object
  27420. *
  27421. * @event PIXI.interaction.InteractionManager#pointerover
  27422. * @param {PIXI.interaction.InteractionEvent} event - Interaction event
  27423. */
  27424. /**
  27425. * Fired when a pointer device is moved off the display object
  27426. *
  27427. * @event PIXI.interaction.InteractionManager#pointerout
  27428. * @param {PIXI.interaction.InteractionEvent} event - Interaction event
  27429. */
  27430. /**
  27431. * Fired when a touch point is placed on the display object.
  27432. *
  27433. * @event PIXI.interaction.InteractionManager#touchstart
  27434. * @param {PIXI.interaction.InteractionEvent} event - Interaction event
  27435. */
  27436. /**
  27437. * Fired when a touch point is removed from the display object.
  27438. *
  27439. * @event PIXI.interaction.InteractionManager#touchend
  27440. * @param {PIXI.interaction.InteractionEvent} event - Interaction event
  27441. */
  27442. /**
  27443. * Fired when the operating system cancels a touch
  27444. *
  27445. * @event PIXI.interaction.InteractionManager#touchcancel
  27446. * @param {PIXI.interaction.InteractionEvent} event - Interaction event
  27447. */
  27448. /**
  27449. * Fired when a touch point is placed and removed from the display object.
  27450. *
  27451. * @event PIXI.interaction.InteractionManager#tap
  27452. * @param {PIXI.interaction.InteractionEvent} event - Interaction event
  27453. */
  27454. /**
  27455. * Fired when a touch point is removed outside of the display object that initially
  27456. * registered a [touchstart]{@link PIXI.interaction.InteractionManager#event:touchstart}.
  27457. *
  27458. * @event PIXI.interaction.InteractionManager#touchendoutside
  27459. * @param {PIXI.interaction.InteractionEvent} event - Interaction event
  27460. */
  27461. /**
  27462. * Fired when a touch point is moved along the display object.
  27463. *
  27464. * @event PIXI.interaction.InteractionManager#touchmove
  27465. * @param {PIXI.interaction.InteractionEvent} event - Interaction event
  27466. */
  27467. /**
  27468. * Fired when a pointer device button (usually a mouse left-button) is pressed on the display.
  27469. * object. DisplayObject's `interactive` property must be set to `true` to fire event.
  27470. *
  27471. * @event PIXI.DisplayObject#mousedown
  27472. * @param {PIXI.interaction.InteractionEvent} event - Interaction event
  27473. */
  27474. /**
  27475. * Fired when a pointer device secondary button (usually a mouse right-button) is pressed
  27476. * on the display object. DisplayObject's `interactive` property must be set to `true` to fire event.
  27477. *
  27478. * @event PIXI.DisplayObject#rightdown
  27479. * @param {PIXI.interaction.InteractionEvent} event - Interaction event
  27480. */
  27481. /**
  27482. * Fired when a pointer device button (usually a mouse left-button) is released over the display
  27483. * object. DisplayObject's `interactive` property must be set to `true` to fire event.
  27484. *
  27485. * @event PIXI.DisplayObject#mouseup
  27486. * @param {PIXI.interaction.InteractionEvent} event - Interaction event
  27487. */
  27488. /**
  27489. * Fired when a pointer device secondary button (usually a mouse right-button) is released
  27490. * over the display object. DisplayObject's `interactive` property must be set to `true` to fire event.
  27491. *
  27492. * @event PIXI.DisplayObject#rightup
  27493. * @param {PIXI.interaction.InteractionEvent} event - Interaction event
  27494. */
  27495. /**
  27496. * Fired when a pointer device button (usually a mouse left-button) is pressed and released on
  27497. * the display object. DisplayObject's `interactive` property must be set to `true` to fire event.
  27498. *
  27499. * @event PIXI.DisplayObject#click
  27500. * @param {PIXI.interaction.InteractionEvent} event - Interaction event
  27501. */
  27502. /**
  27503. * Fired when a pointer device secondary button (usually a mouse right-button) is pressed
  27504. * and released on the display object. DisplayObject's `interactive` property must be set to `true` to fire event.
  27505. *
  27506. * @event PIXI.DisplayObject#rightclick
  27507. * @param {PIXI.interaction.InteractionEvent} event - Interaction event
  27508. */
  27509. /**
  27510. * Fired when a pointer device button (usually a mouse left-button) is released outside the
  27511. * display object that initially registered a
  27512. * [mousedown]{@link PIXI.DisplayObject#event:mousedown}.
  27513. * DisplayObject's `interactive` property must be set to `true` to fire event.
  27514. *
  27515. * @event PIXI.DisplayObject#mouseupoutside
  27516. * @param {PIXI.interaction.InteractionEvent} event - Interaction event
  27517. */
  27518. /**
  27519. * Fired when a pointer device secondary button (usually a mouse right-button) is released
  27520. * outside the display object that initially registered a
  27521. * [rightdown]{@link PIXI.DisplayObject#event:rightdown}.
  27522. * DisplayObject's `interactive` property must be set to `true` to fire event.
  27523. *
  27524. * @event PIXI.DisplayObject#rightupoutside
  27525. * @param {PIXI.interaction.InteractionEvent} event - Interaction event
  27526. */
  27527. /**
  27528. * Fired when a pointer device (usually a mouse) is moved while over the display object.
  27529. * DisplayObject's `interactive` property must be set to `true` to fire event.
  27530. *
  27531. * @event PIXI.DisplayObject#mousemove
  27532. * @param {PIXI.interaction.InteractionEvent} event - Interaction event
  27533. */
  27534. /**
  27535. * Fired when a pointer device (usually a mouse) is moved onto the display object.
  27536. * DisplayObject's `interactive` property must be set to `true` to fire event.
  27537. *
  27538. * @event PIXI.DisplayObject#mouseover
  27539. * @param {PIXI.interaction.InteractionEvent} event - Interaction event
  27540. */
  27541. /**
  27542. * Fired when a pointer device (usually a mouse) is moved off the display object.
  27543. * DisplayObject's `interactive` property must be set to `true` to fire event.
  27544. *
  27545. * @event PIXI.DisplayObject#mouseout
  27546. * @param {PIXI.interaction.InteractionEvent} event - Interaction event
  27547. */
  27548. /**
  27549. * Fired when a pointer device button is pressed on the display object.
  27550. * DisplayObject's `interactive` property must be set to `true` to fire event.
  27551. *
  27552. * @event PIXI.DisplayObject#pointerdown
  27553. * @param {PIXI.interaction.InteractionEvent} event - Interaction event
  27554. */
  27555. /**
  27556. * Fired when a pointer device button is released over the display object.
  27557. * DisplayObject's `interactive` property must be set to `true` to fire event.
  27558. *
  27559. * @event PIXI.DisplayObject#pointerup
  27560. * @param {PIXI.interaction.InteractionEvent} event - Interaction event
  27561. */
  27562. /**
  27563. * Fired when the operating system cancels a pointer event.
  27564. * DisplayObject's `interactive` property must be set to `true` to fire event.
  27565. *
  27566. * @event PIXI.DisplayObject#pointercancel
  27567. * @param {PIXI.interaction.InteractionEvent} event - Interaction event
  27568. */
  27569. /**
  27570. * Fired when a pointer device button is pressed and released on the display object.
  27571. * DisplayObject's `interactive` property must be set to `true` to fire event.
  27572. *
  27573. * @event PIXI.DisplayObject#pointertap
  27574. * @param {PIXI.interaction.InteractionEvent} event - Interaction event
  27575. */
  27576. /**
  27577. * Fired when a pointer device button is released outside the display object that initially
  27578. * registered a [pointerdown]{@link PIXI.DisplayObject#event:pointerdown}.
  27579. * DisplayObject's `interactive` property must be set to `true` to fire event.
  27580. *
  27581. * @event PIXI.DisplayObject#pointerupoutside
  27582. * @param {PIXI.interaction.InteractionEvent} event - Interaction event
  27583. */
  27584. /**
  27585. * Fired when a pointer device is moved while over the display object.
  27586. * DisplayObject's `interactive` property must be set to `true` to fire event.
  27587. *
  27588. * @event PIXI.DisplayObject#pointermove
  27589. * @param {PIXI.interaction.InteractionEvent} event - Interaction event
  27590. */
  27591. /**
  27592. * Fired when a pointer device is moved onto the display object.
  27593. * DisplayObject's `interactive` property must be set to `true` to fire event.
  27594. *
  27595. * @event PIXI.DisplayObject#pointerover
  27596. * @param {PIXI.interaction.InteractionEvent} event - Interaction event
  27597. */
  27598. /**
  27599. * Fired when a pointer device is moved off the display object.
  27600. * DisplayObject's `interactive` property must be set to `true` to fire event.
  27601. *
  27602. * @event PIXI.DisplayObject#pointerout
  27603. * @param {PIXI.interaction.InteractionEvent} event - Interaction event
  27604. */
  27605. /**
  27606. * Fired when a touch point is placed on the display object.
  27607. * DisplayObject's `interactive` property must be set to `true` to fire event.
  27608. *
  27609. * @event PIXI.DisplayObject#touchstart
  27610. * @param {PIXI.interaction.InteractionEvent} event - Interaction event
  27611. */
  27612. /**
  27613. * Fired when a touch point is removed from the display object.
  27614. * DisplayObject's `interactive` property must be set to `true` to fire event.
  27615. *
  27616. * @event PIXI.DisplayObject#touchend
  27617. * @param {PIXI.interaction.InteractionEvent} event - Interaction event
  27618. */
  27619. /**
  27620. * Fired when the operating system cancels a touch.
  27621. * DisplayObject's `interactive` property must be set to `true` to fire event.
  27622. *
  27623. * @event PIXI.DisplayObject#touchcancel
  27624. * @param {PIXI.interaction.InteractionEvent} event - Interaction event
  27625. */
  27626. /**
  27627. * Fired when a touch point is placed and removed from the display object.
  27628. * DisplayObject's `interactive` property must be set to `true` to fire event.
  27629. *
  27630. * @event PIXI.DisplayObject#tap
  27631. * @param {PIXI.interaction.InteractionEvent} event - Interaction event
  27632. */
  27633. /**
  27634. * Fired when a touch point is removed outside of the display object that initially
  27635. * registered a [touchstart]{@link PIXI.DisplayObject#event:touchstart}.
  27636. * DisplayObject's `interactive` property must be set to `true` to fire event.
  27637. *
  27638. * @event PIXI.DisplayObject#touchendoutside
  27639. * @param {PIXI.interaction.InteractionEvent} event - Interaction event
  27640. */
  27641. /**
  27642. * Fired when a touch point is moved along the display object.
  27643. * DisplayObject's `interactive` property must be set to `true` to fire event.
  27644. *
  27645. * @event PIXI.DisplayObject#touchmove
  27646. * @param {PIXI.interaction.InteractionEvent} event - Interaction event
  27647. */
  27648. return _this;
  27649. }
  27650. /**
  27651. * Hit tests a point against the display tree, returning the first interactive object that is hit.
  27652. *
  27653. * @param {PIXI.Point} globalPoint - A point to hit test with, in global space.
  27654. * @param {PIXI.Container} [root] - The root display object to start from. If omitted, defaults
  27655. * to the last rendered root of the associated renderer.
  27656. * @return {PIXI.DisplayObject} The hit display object, if any.
  27657. */
  27658. InteractionManager.prototype.hitTest = function hitTest(globalPoint, root) {
  27659. // clear the target for our hit test
  27660. hitTestEvent.target = null;
  27661. // assign the global point
  27662. hitTestEvent.data.global = globalPoint;
  27663. // ensure safety of the root
  27664. if (!root) {
  27665. root = this.renderer._lastObjectRendered;
  27666. }
  27667. // run the hit test
  27668. this.processInteractive(hitTestEvent, root, null, true);
  27669. // return our found object - it'll be null if we didn't hit anything
  27670. return hitTestEvent.target;
  27671. };
  27672. /**
  27673. * Sets the DOM element which will receive mouse/touch events. This is useful for when you have
  27674. * other DOM elements on top of the renderers Canvas element. With this you'll be bale to deletegate
  27675. * another DOM element to receive those events.
  27676. *
  27677. * @param {HTMLCanvasElement} element - the DOM element which will receive mouse and touch events.
  27678. * @param {number} [resolution=1] - The resolution / device pixel ratio of the new element (relative to the canvas).
  27679. */
  27680. InteractionManager.prototype.setTargetElement = function setTargetElement(element) {
  27681. var resolution = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
  27682. this.removeEvents();
  27683. this.interactionDOMElement = element;
  27684. this.resolution = resolution;
  27685. this.addEvents();
  27686. };
  27687. /**
  27688. * Registers all the DOM events
  27689. *
  27690. * @private
  27691. */
  27692. InteractionManager.prototype.addEvents = function addEvents() {
  27693. if (!this.interactionDOMElement) {
  27694. return;
  27695. }
  27696. core.ticker.shared.add(this.update, this, core.UPDATE_PRIORITY.INTERACTION);
  27697. if (window.navigator.msPointerEnabled) {
  27698. this.interactionDOMElement.style['-ms-content-zooming'] = 'none';
  27699. this.interactionDOMElement.style['-ms-touch-action'] = 'none';
  27700. } else if (this.supportsPointerEvents) {
  27701. this.interactionDOMElement.style['touch-action'] = 'none';
  27702. }
  27703. /**
  27704. * These events are added first, so that if pointer events are normalised, they are fired
  27705. * in the same order as non-normalised events. ie. pointer event 1st, mouse / touch 2nd
  27706. */
  27707. if (this.supportsPointerEvents) {
  27708. window.document.addEventListener('pointermove', this.onPointerMove, true);
  27709. this.interactionDOMElement.addEventListener('pointerdown', this.onPointerDown, true);
  27710. // pointerout is fired in addition to pointerup (for touch events) and pointercancel
  27711. // we already handle those, so for the purposes of what we do in onPointerOut, we only
  27712. // care about the pointerleave event
  27713. this.interactionDOMElement.addEventListener('pointerleave', this.onPointerOut, true);
  27714. this.interactionDOMElement.addEventListener('pointerover', this.onPointerOver, true);
  27715. window.addEventListener('pointercancel', this.onPointerCancel, true);
  27716. window.addEventListener('pointerup', this.onPointerUp, true);
  27717. } else {
  27718. window.document.addEventListener('mousemove', this.onPointerMove, true);
  27719. this.interactionDOMElement.addEventListener('mousedown', this.onPointerDown, true);
  27720. this.interactionDOMElement.addEventListener('mouseout', this.onPointerOut, true);
  27721. this.interactionDOMElement.addEventListener('mouseover', this.onPointerOver, true);
  27722. window.addEventListener('mouseup', this.onPointerUp, true);
  27723. }
  27724. // always look directly for touch events so that we can provide original data
  27725. // In a future version we should change this to being just a fallback and rely solely on
  27726. // PointerEvents whenever available
  27727. if (this.supportsTouchEvents) {
  27728. this.interactionDOMElement.addEventListener('touchstart', this.onPointerDown, true);
  27729. this.interactionDOMElement.addEventListener('touchcancel', this.onPointerCancel, true);
  27730. this.interactionDOMElement.addEventListener('touchend', this.onPointerUp, true);
  27731. this.interactionDOMElement.addEventListener('touchmove', this.onPointerMove, true);
  27732. }
  27733. this.eventsAdded = true;
  27734. };
  27735. /**
  27736. * Removes all the DOM events that were previously registered
  27737. *
  27738. * @private
  27739. */
  27740. InteractionManager.prototype.removeEvents = function removeEvents() {
  27741. if (!this.interactionDOMElement) {
  27742. return;
  27743. }
  27744. core.ticker.shared.remove(this.update, this);
  27745. if (window.navigator.msPointerEnabled) {
  27746. this.interactionDOMElement.style['-ms-content-zooming'] = '';
  27747. this.interactionDOMElement.style['-ms-touch-action'] = '';
  27748. } else if (this.supportsPointerEvents) {
  27749. this.interactionDOMElement.style['touch-action'] = '';
  27750. }
  27751. if (this.supportsPointerEvents) {
  27752. window.document.removeEventListener('pointermove', this.onPointerMove, true);
  27753. this.interactionDOMElement.removeEventListener('pointerdown', this.onPointerDown, true);
  27754. this.interactionDOMElement.removeEventListener('pointerleave', this.onPointerOut, true);
  27755. this.interactionDOMElement.removeEventListener('pointerover', this.onPointerOver, true);
  27756. window.removeEventListener('pointercancel', this.onPointerCancel, true);
  27757. window.removeEventListener('pointerup', this.onPointerUp, true);
  27758. } else {
  27759. window.document.removeEventListener('mousemove', this.onPointerMove, true);
  27760. this.interactionDOMElement.removeEventListener('mousedown', this.onPointerDown, true);
  27761. this.interactionDOMElement.removeEventListener('mouseout', this.onPointerOut, true);
  27762. this.interactionDOMElement.removeEventListener('mouseover', this.onPointerOver, true);
  27763. window.removeEventListener('mouseup', this.onPointerUp, true);
  27764. }
  27765. if (this.supportsTouchEvents) {
  27766. this.interactionDOMElement.removeEventListener('touchstart', this.onPointerDown, true);
  27767. this.interactionDOMElement.removeEventListener('touchcancel', this.onPointerCancel, true);
  27768. this.interactionDOMElement.removeEventListener('touchend', this.onPointerUp, true);
  27769. this.interactionDOMElement.removeEventListener('touchmove', this.onPointerMove, true);
  27770. }
  27771. this.interactionDOMElement = null;
  27772. this.eventsAdded = false;
  27773. };
  27774. /**
  27775. * Updates the state of interactive objects.
  27776. * Invoked by a throttled ticker update from {@link PIXI.ticker.shared}.
  27777. *
  27778. * @param {number} deltaTime - time delta since last tick
  27779. */
  27780. InteractionManager.prototype.update = function update(deltaTime) {
  27781. this._deltaTime += deltaTime;
  27782. if (this._deltaTime < this.interactionFrequency) {
  27783. return;
  27784. }
  27785. this._deltaTime = 0;
  27786. if (!this.interactionDOMElement) {
  27787. return;
  27788. }
  27789. // if the user move the mouse this check has already been done using the mouse move!
  27790. if (this.didMove) {
  27791. this.didMove = false;
  27792. return;
  27793. }
  27794. this.cursor = null;
  27795. // Resets the flag as set by a stopPropagation call. This flag is usually reset by a user interaction of any kind,
  27796. // but there was a scenario of a display object moving under a static mouse cursor.
  27797. // In this case, mouseover and mouseevents would not pass the flag test in dispatchEvent function
  27798. for (var k in this.activeInteractionData) {
  27799. // eslint-disable-next-line no-prototype-builtins
  27800. if (this.activeInteractionData.hasOwnProperty(k)) {
  27801. var interactionData = this.activeInteractionData[k];
  27802. if (interactionData.originalEvent && interactionData.pointerType !== 'touch') {
  27803. var interactionEvent = this.configureInteractionEventForDOMEvent(this.eventData, interactionData.originalEvent, interactionData);
  27804. this.processInteractive(interactionEvent, this.renderer._lastObjectRendered, this.processPointerOverOut, true);
  27805. }
  27806. }
  27807. }
  27808. this.setCursorMode(this.cursor);
  27809. // TODO
  27810. };
  27811. /**
  27812. * Sets the current cursor mode, handling any callbacks or CSS style changes.
  27813. *
  27814. * @param {string} mode - cursor mode, a key from the cursorStyles dictionary
  27815. */
  27816. InteractionManager.prototype.setCursorMode = function setCursorMode(mode) {
  27817. mode = mode || 'default';
  27818. // if the mode didn't actually change, bail early
  27819. if (this.currentCursorMode === mode) {
  27820. return;
  27821. }
  27822. this.currentCursorMode = mode;
  27823. var style = this.cursorStyles[mode];
  27824. // only do things if there is a cursor style for it
  27825. if (style) {
  27826. switch (typeof style === 'undefined' ? 'undefined' : _typeof(style)) {
  27827. case 'string':
  27828. // string styles are handled as cursor CSS
  27829. this.interactionDOMElement.style.cursor = style;
  27830. break;
  27831. case 'function':
  27832. // functions are just called, and passed the cursor mode
  27833. style(mode);
  27834. break;
  27835. case 'object':
  27836. // if it is an object, assume that it is a dictionary of CSS styles,
  27837. // apply it to the interactionDOMElement
  27838. Object.assign(this.interactionDOMElement.style, style);
  27839. break;
  27840. }
  27841. } else if (typeof mode === 'string' && !Object.prototype.hasOwnProperty.call(this.cursorStyles, mode)) {
  27842. // if it mode is a string (not a Symbol) and cursorStyles doesn't have any entry
  27843. // for the mode, then assume that the dev wants it to be CSS for the cursor.
  27844. this.interactionDOMElement.style.cursor = mode;
  27845. }
  27846. };
  27847. /**
  27848. * Dispatches an event on the display object that was interacted with
  27849. *
  27850. * @param {PIXI.Container|PIXI.Sprite|PIXI.extras.TilingSprite} displayObject - the display object in question
  27851. * @param {string} eventString - the name of the event (e.g, mousedown)
  27852. * @param {object} eventData - the event data object
  27853. * @private
  27854. */
  27855. InteractionManager.prototype.dispatchEvent = function dispatchEvent(displayObject, eventString, eventData) {
  27856. if (!eventData.stopped) {
  27857. eventData.currentTarget = displayObject;
  27858. eventData.type = eventString;
  27859. displayObject.emit(eventString, eventData);
  27860. if (displayObject[eventString]) {
  27861. displayObject[eventString](eventData);
  27862. }
  27863. }
  27864. };
  27865. /**
  27866. * Maps x and y coords from a DOM object and maps them correctly to the PixiJS view. The
  27867. * resulting value is stored in the point. This takes into account the fact that the DOM
  27868. * element could be scaled and positioned anywhere on the screen.
  27869. *
  27870. * @param {PIXI.Point} point - the point that the result will be stored in
  27871. * @param {number} x - the x coord of the position to map
  27872. * @param {number} y - the y coord of the position to map
  27873. */
  27874. InteractionManager.prototype.mapPositionToPoint = function mapPositionToPoint(point, x, y) {
  27875. var rect = void 0;
  27876. // IE 11 fix
  27877. if (!this.interactionDOMElement.parentElement) {
  27878. rect = { x: 0, y: 0, width: 0, height: 0 };
  27879. } else {
  27880. rect = this.interactionDOMElement.getBoundingClientRect();
  27881. }
  27882. var resolutionMultiplier = navigator.isCocoonJS ? this.resolution : 1.0 / this.resolution;
  27883. point.x = (x - rect.left) * (this.interactionDOMElement.width / rect.width) * resolutionMultiplier;
  27884. point.y = (y - rect.top) * (this.interactionDOMElement.height / rect.height) * resolutionMultiplier;
  27885. };
  27886. /**
  27887. * This function is provides a neat way of crawling through the scene graph and running a
  27888. * specified function on all interactive objects it finds. It will also take care of hit
  27889. * testing the interactive objects and passes the hit across in the function.
  27890. *
  27891. * @private
  27892. * @param {PIXI.interaction.InteractionEvent} interactionEvent - event containing the point that
  27893. * is tested for collision
  27894. * @param {PIXI.Container|PIXI.Sprite|PIXI.extras.TilingSprite} displayObject - the displayObject
  27895. * that will be hit test (recursively crawls its children)
  27896. * @param {Function} [func] - the function that will be called on each interactive object. The
  27897. * interactionEvent, displayObject and hit will be passed to the function
  27898. * @param {boolean} [hitTest] - this indicates if the objects inside should be hit test against the point
  27899. * @param {boolean} [interactive] - Whether the displayObject is interactive
  27900. * @return {boolean} returns true if the displayObject hit the point
  27901. */
  27902. InteractionManager.prototype.processInteractive = function processInteractive(interactionEvent, displayObject, func, hitTest, interactive) {
  27903. if (!displayObject || !displayObject.visible) {
  27904. return false;
  27905. }
  27906. var point = interactionEvent.data.global;
  27907. // Took a little while to rework this function correctly! But now it is done and nice and optimised. ^_^
  27908. //
  27909. // This function will now loop through all objects and then only hit test the objects it HAS
  27910. // to, not all of them. MUCH faster..
  27911. // An object will be hit test if the following is true:
  27912. //
  27913. // 1: It is interactive.
  27914. // 2: It belongs to a parent that is interactive AND one of the parents children have not already been hit.
  27915. //
  27916. // As another little optimisation once an interactive object has been hit we can carry on
  27917. // through the scenegraph, but we know that there will be no more hits! So we can avoid extra hit tests
  27918. // A final optimisation is that an object is not hit test directly if a child has already been hit.
  27919. interactive = displayObject.interactive || interactive;
  27920. var hit = false;
  27921. var interactiveParent = interactive;
  27922. // Flag here can set to false if the event is outside the parents hitArea or mask
  27923. var hitTestChildren = true;
  27924. // If there is a hitArea, no need to test against anything else if the pointer is not within the hitArea
  27925. // There is also no longer a need to hitTest children.
  27926. if (displayObject.hitArea) {
  27927. if (hitTest) {
  27928. displayObject.worldTransform.applyInverse(point, this._tempPoint);
  27929. if (!displayObject.hitArea.contains(this._tempPoint.x, this._tempPoint.y)) {
  27930. hitTest = false;
  27931. hitTestChildren = false;
  27932. } else {
  27933. hit = true;
  27934. }
  27935. }
  27936. interactiveParent = false;
  27937. }
  27938. // If there is a mask, no need to test against anything else if the pointer is not within the mask
  27939. else if (displayObject._mask) {
  27940. if (hitTest) {
  27941. if (!displayObject._mask.containsPoint(point)) {
  27942. hitTest = false;
  27943. hitTestChildren = false;
  27944. }
  27945. }
  27946. }
  27947. // ** FREE TIP **! If an object is not interactive or has no buttons in it
  27948. // (such as a game scene!) set interactiveChildren to false for that displayObject.
  27949. // This will allow PixiJS to completely ignore and bypass checking the displayObjects children.
  27950. if (hitTestChildren && displayObject.interactiveChildren && displayObject.children) {
  27951. var children = displayObject.children;
  27952. for (var i = children.length - 1; i >= 0; i--) {
  27953. var child = children[i];
  27954. // time to get recursive.. if this function will return if something is hit..
  27955. var childHit = this.processInteractive(interactionEvent, child, func, hitTest, interactiveParent);
  27956. if (childHit) {
  27957. // its a good idea to check if a child has lost its parent.
  27958. // this means it has been removed whilst looping so its best
  27959. if (!child.parent) {
  27960. continue;
  27961. }
  27962. // we no longer need to hit test any more objects in this container as we we
  27963. // now know the parent has been hit
  27964. interactiveParent = false;
  27965. // If the child is interactive , that means that the object hit was actually
  27966. // interactive and not just the child of an interactive object.
  27967. // This means we no longer need to hit test anything else. We still need to run
  27968. // through all objects, but we don't need to perform any hit tests.
  27969. if (childHit) {
  27970. if (interactionEvent.target) {
  27971. hitTest = false;
  27972. }
  27973. hit = true;
  27974. }
  27975. }
  27976. }
  27977. }
  27978. // no point running this if the item is not interactive or does not have an interactive parent.
  27979. if (interactive) {
  27980. // if we are hit testing (as in we have no hit any objects yet)
  27981. // We also don't need to worry about hit testing if once of the displayObjects children
  27982. // has already been hit - but only if it was interactive, otherwise we need to keep
  27983. // looking for an interactive child, just in case we hit one
  27984. if (hitTest && !interactionEvent.target) {
  27985. // already tested against hitArea if it is defined
  27986. if (!displayObject.hitArea && displayObject.containsPoint) {
  27987. if (displayObject.containsPoint(point)) {
  27988. hit = true;
  27989. }
  27990. }
  27991. }
  27992. if (displayObject.interactive) {
  27993. if (hit && !interactionEvent.target) {
  27994. interactionEvent.target = displayObject;
  27995. }
  27996. if (func) {
  27997. func(interactionEvent, displayObject, !!hit);
  27998. }
  27999. }
  28000. }
  28001. return hit;
  28002. };
  28003. /**
  28004. * Is called when the pointer button is pressed down on the renderer element
  28005. *
  28006. * @private
  28007. * @param {PointerEvent} originalEvent - The DOM event of a pointer button being pressed down
  28008. */
  28009. InteractionManager.prototype.onPointerDown = function onPointerDown(originalEvent) {
  28010. // if we support touch events, then only use those for touch events, not pointer events
  28011. if (this.supportsTouchEvents && originalEvent.pointerType === 'touch') return;
  28012. var events = this.normalizeToPointerData(originalEvent);
  28013. /**
  28014. * No need to prevent default on natural pointer events, as there are no side effects
  28015. * Normalized events, however, may have the double mousedown/touchstart issue on the native android browser,
  28016. * so still need to be prevented.
  28017. */
  28018. // Guaranteed that there will be at least one event in events, and all events must have the same pointer type
  28019. if (this.autoPreventDefault && events[0].isNormalized) {
  28020. originalEvent.preventDefault();
  28021. }
  28022. var eventLen = events.length;
  28023. for (var i = 0; i < eventLen; i++) {
  28024. var event = events[i];
  28025. var interactionData = this.getInteractionDataForPointerId(event);
  28026. var interactionEvent = this.configureInteractionEventForDOMEvent(this.eventData, event, interactionData);
  28027. interactionEvent.data.originalEvent = originalEvent;
  28028. this.processInteractive(interactionEvent, this.renderer._lastObjectRendered, this.processPointerDown, true);
  28029. this.emit('pointerdown', interactionEvent);
  28030. if (event.pointerType === 'touch') {
  28031. this.emit('touchstart', interactionEvent);
  28032. }
  28033. // emit a mouse event for "pen" pointers, the way a browser would emit a fallback event
  28034. else if (event.pointerType === 'mouse' || event.pointerType === 'pen') {
  28035. var isRightButton = event.button === 2;
  28036. this.emit(isRightButton ? 'rightdown' : 'mousedown', this.eventData);
  28037. }
  28038. }
  28039. };
  28040. /**
  28041. * Processes the result of the pointer down check and dispatches the event if need be
  28042. *
  28043. * @private
  28044. * @param {PIXI.interaction.InteractionEvent} interactionEvent - The interaction event wrapping the DOM event
  28045. * @param {PIXI.Container|PIXI.Sprite|PIXI.extras.TilingSprite} displayObject - The display object that was tested
  28046. * @param {boolean} hit - the result of the hit test on the display object
  28047. */
  28048. InteractionManager.prototype.processPointerDown = function processPointerDown(interactionEvent, displayObject, hit) {
  28049. var data = interactionEvent.data;
  28050. var id = interactionEvent.data.identifier;
  28051. if (hit) {
  28052. if (!displayObject.trackedPointers[id]) {
  28053. displayObject.trackedPointers[id] = new _InteractionTrackingData2.default(id);
  28054. }
  28055. this.dispatchEvent(displayObject, 'pointerdown', interactionEvent);
  28056. if (data.pointerType === 'touch') {
  28057. this.dispatchEvent(displayObject, 'touchstart', interactionEvent);
  28058. } else if (data.pointerType === 'mouse' || data.pointerType === 'pen') {
  28059. var isRightButton = data.button === 2;
  28060. if (isRightButton) {
  28061. displayObject.trackedPointers[id].rightDown = true;
  28062. } else {
  28063. displayObject.trackedPointers[id].leftDown = true;
  28064. }
  28065. this.dispatchEvent(displayObject, isRightButton ? 'rightdown' : 'mousedown', interactionEvent);
  28066. }
  28067. }
  28068. };
  28069. /**
  28070. * Is called when the pointer button is released on the renderer element
  28071. *
  28072. * @private
  28073. * @param {PointerEvent} originalEvent - The DOM event of a pointer button being released
  28074. * @param {boolean} cancelled - true if the pointer is cancelled
  28075. * @param {Function} func - Function passed to {@link processInteractive}
  28076. */
  28077. InteractionManager.prototype.onPointerComplete = function onPointerComplete(originalEvent, cancelled, func) {
  28078. var events = this.normalizeToPointerData(originalEvent);
  28079. var eventLen = events.length;
  28080. // if the event wasn't targeting our canvas, then consider it to be pointerupoutside
  28081. // in all cases (unless it was a pointercancel)
  28082. var eventAppend = originalEvent.target !== this.interactionDOMElement ? 'outside' : '';
  28083. for (var i = 0; i < eventLen; i++) {
  28084. var event = events[i];
  28085. var interactionData = this.getInteractionDataForPointerId(event);
  28086. var interactionEvent = this.configureInteractionEventForDOMEvent(this.eventData, event, interactionData);
  28087. interactionEvent.data.originalEvent = originalEvent;
  28088. // perform hit testing for events targeting our canvas or cancel events
  28089. this.processInteractive(interactionEvent, this.renderer._lastObjectRendered, func, cancelled || !eventAppend);
  28090. this.emit(cancelled ? 'pointercancel' : 'pointerup' + eventAppend, interactionEvent);
  28091. if (event.pointerType === 'mouse' || event.pointerType === 'pen') {
  28092. var isRightButton = event.button === 2;
  28093. this.emit(isRightButton ? 'rightup' + eventAppend : 'mouseup' + eventAppend, interactionEvent);
  28094. } else if (event.pointerType === 'touch') {
  28095. this.emit(cancelled ? 'touchcancel' : 'touchend' + eventAppend, interactionEvent);
  28096. this.releaseInteractionDataForPointerId(event.pointerId, interactionData);
  28097. }
  28098. }
  28099. };
  28100. /**
  28101. * Is called when the pointer button is cancelled
  28102. *
  28103. * @private
  28104. * @param {PointerEvent} event - The DOM event of a pointer button being released
  28105. */
  28106. InteractionManager.prototype.onPointerCancel = function onPointerCancel(event) {
  28107. // if we support touch events, then only use those for touch events, not pointer events
  28108. if (this.supportsTouchEvents && event.pointerType === 'touch') return;
  28109. this.onPointerComplete(event, true, this.processPointerCancel);
  28110. };
  28111. /**
  28112. * Processes the result of the pointer cancel check and dispatches the event if need be
  28113. *
  28114. * @private
  28115. * @param {PIXI.interaction.InteractionEvent} interactionEvent - The interaction event wrapping the DOM event
  28116. * @param {PIXI.Container|PIXI.Sprite|PIXI.extras.TilingSprite} displayObject - The display object that was tested
  28117. */
  28118. InteractionManager.prototype.processPointerCancel = function processPointerCancel(interactionEvent, displayObject) {
  28119. var data = interactionEvent.data;
  28120. var id = interactionEvent.data.identifier;
  28121. if (displayObject.trackedPointers[id] !== undefined) {
  28122. delete displayObject.trackedPointers[id];
  28123. this.dispatchEvent(displayObject, 'pointercancel', interactionEvent);
  28124. if (data.pointerType === 'touch') {
  28125. this.dispatchEvent(displayObject, 'touchcancel', interactionEvent);
  28126. }
  28127. }
  28128. };
  28129. /**
  28130. * Is called when the pointer button is released on the renderer element
  28131. *
  28132. * @private
  28133. * @param {PointerEvent} event - The DOM event of a pointer button being released
  28134. */
  28135. InteractionManager.prototype.onPointerUp = function onPointerUp(event) {
  28136. // if we support touch events, then only use those for touch events, not pointer events
  28137. if (this.supportsTouchEvents && event.pointerType === 'touch') return;
  28138. this.onPointerComplete(event, false, this.processPointerUp);
  28139. };
  28140. /**
  28141. * Processes the result of the pointer up check and dispatches the event if need be
  28142. *
  28143. * @private
  28144. * @param {PIXI.interaction.InteractionEvent} interactionEvent - The interaction event wrapping the DOM event
  28145. * @param {PIXI.Container|PIXI.Sprite|PIXI.extras.TilingSprite} displayObject - The display object that was tested
  28146. * @param {boolean} hit - the result of the hit test on the display object
  28147. */
  28148. InteractionManager.prototype.processPointerUp = function processPointerUp(interactionEvent, displayObject, hit) {
  28149. var data = interactionEvent.data;
  28150. var id = interactionEvent.data.identifier;
  28151. var trackingData = displayObject.trackedPointers[id];
  28152. var isTouch = data.pointerType === 'touch';
  28153. var isMouse = data.pointerType === 'mouse' || data.pointerType === 'pen';
  28154. // Mouse only
  28155. if (isMouse) {
  28156. var isRightButton = data.button === 2;
  28157. var flags = _InteractionTrackingData2.default.FLAGS;
  28158. var test = isRightButton ? flags.RIGHT_DOWN : flags.LEFT_DOWN;
  28159. var isDown = trackingData !== undefined && trackingData.flags & test;
  28160. if (hit) {
  28161. this.dispatchEvent(displayObject, isRightButton ? 'rightup' : 'mouseup', interactionEvent);
  28162. if (isDown) {
  28163. this.dispatchEvent(displayObject, isRightButton ? 'rightclick' : 'click', interactionEvent);
  28164. }
  28165. } else if (isDown) {
  28166. this.dispatchEvent(displayObject, isRightButton ? 'rightupoutside' : 'mouseupoutside', interactionEvent);
  28167. }
  28168. // update the down state of the tracking data
  28169. if (trackingData) {
  28170. if (isRightButton) {
  28171. trackingData.rightDown = false;
  28172. } else {
  28173. trackingData.leftDown = false;
  28174. }
  28175. }
  28176. }
  28177. // Pointers and Touches, and Mouse
  28178. if (hit) {
  28179. this.dispatchEvent(displayObject, 'pointerup', interactionEvent);
  28180. if (isTouch) this.dispatchEvent(displayObject, 'touchend', interactionEvent);
  28181. if (trackingData) {
  28182. this.dispatchEvent(displayObject, 'pointertap', interactionEvent);
  28183. if (isTouch) {
  28184. this.dispatchEvent(displayObject, 'tap', interactionEvent);
  28185. // touches are no longer over (if they ever were) when we get the touchend
  28186. // so we should ensure that we don't keep pretending that they are
  28187. trackingData.over = false;
  28188. }
  28189. }
  28190. } else if (trackingData) {
  28191. this.dispatchEvent(displayObject, 'pointerupoutside', interactionEvent);
  28192. if (isTouch) this.dispatchEvent(displayObject, 'touchendoutside', interactionEvent);
  28193. }
  28194. // Only remove the tracking data if there is no over/down state still associated with it
  28195. if (trackingData && trackingData.none) {
  28196. delete displayObject.trackedPointers[id];
  28197. }
  28198. };
  28199. /**
  28200. * Is called when the pointer moves across the renderer element
  28201. *
  28202. * @private
  28203. * @param {PointerEvent} originalEvent - The DOM event of a pointer moving
  28204. */
  28205. InteractionManager.prototype.onPointerMove = function onPointerMove(originalEvent) {
  28206. // if we support touch events, then only use those for touch events, not pointer events
  28207. if (this.supportsTouchEvents && originalEvent.pointerType === 'touch') return;
  28208. var events = this.normalizeToPointerData(originalEvent);
  28209. if (events[0].pointerType === 'mouse' || events[0].pointerType === 'pen') {
  28210. this.didMove = true;
  28211. this.cursor = null;
  28212. }
  28213. var eventLen = events.length;
  28214. for (var i = 0; i < eventLen; i++) {
  28215. var event = events[i];
  28216. var interactionData = this.getInteractionDataForPointerId(event);
  28217. var interactionEvent = this.configureInteractionEventForDOMEvent(this.eventData, event, interactionData);
  28218. interactionEvent.data.originalEvent = originalEvent;
  28219. var interactive = event.pointerType === 'touch' ? this.moveWhenInside : true;
  28220. this.processInteractive(interactionEvent, this.renderer._lastObjectRendered, this.processPointerMove, interactive);
  28221. this.emit('pointermove', interactionEvent);
  28222. if (event.pointerType === 'touch') this.emit('touchmove', interactionEvent);
  28223. if (event.pointerType === 'mouse' || event.pointerType === 'pen') this.emit('mousemove', interactionEvent);
  28224. }
  28225. if (events[0].pointerType === 'mouse') {
  28226. this.setCursorMode(this.cursor);
  28227. // TODO BUG for parents interactive object (border order issue)
  28228. }
  28229. };
  28230. /**
  28231. * Processes the result of the pointer move check and dispatches the event if need be
  28232. *
  28233. * @private
  28234. * @param {PIXI.interaction.InteractionEvent} interactionEvent - The interaction event wrapping the DOM event
  28235. * @param {PIXI.Container|PIXI.Sprite|PIXI.extras.TilingSprite} displayObject - The display object that was tested
  28236. * @param {boolean} hit - the result of the hit test on the display object
  28237. */
  28238. InteractionManager.prototype.processPointerMove = function processPointerMove(interactionEvent, displayObject, hit) {
  28239. var data = interactionEvent.data;
  28240. var isTouch = data.pointerType === 'touch';
  28241. var isMouse = data.pointerType === 'mouse' || data.pointerType === 'pen';
  28242. if (isMouse) {
  28243. this.processPointerOverOut(interactionEvent, displayObject, hit);
  28244. }
  28245. if (!this.moveWhenInside || hit) {
  28246. this.dispatchEvent(displayObject, 'pointermove', interactionEvent);
  28247. if (isTouch) this.dispatchEvent(displayObject, 'touchmove', interactionEvent);
  28248. if (isMouse) this.dispatchEvent(displayObject, 'mousemove', interactionEvent);
  28249. }
  28250. };
  28251. /**
  28252. * Is called when the pointer is moved out of the renderer element
  28253. *
  28254. * @private
  28255. * @param {PointerEvent} originalEvent - The DOM event of a pointer being moved out
  28256. */
  28257. InteractionManager.prototype.onPointerOut = function onPointerOut(originalEvent) {
  28258. // if we support touch events, then only use those for touch events, not pointer events
  28259. if (this.supportsTouchEvents && originalEvent.pointerType === 'touch') return;
  28260. var events = this.normalizeToPointerData(originalEvent);
  28261. // Only mouse and pointer can call onPointerOut, so events will always be length 1
  28262. var event = events[0];
  28263. if (event.pointerType === 'mouse') {
  28264. this.mouseOverRenderer = false;
  28265. this.setCursorMode(null);
  28266. }
  28267. var interactionData = this.getInteractionDataForPointerId(event);
  28268. var interactionEvent = this.configureInteractionEventForDOMEvent(this.eventData, event, interactionData);
  28269. interactionEvent.data.originalEvent = event;
  28270. this.processInteractive(interactionEvent, this.renderer._lastObjectRendered, this.processPointerOverOut, false);
  28271. this.emit('pointerout', interactionEvent);
  28272. if (event.pointerType === 'mouse' || event.pointerType === 'pen') {
  28273. this.emit('mouseout', interactionEvent);
  28274. } else {
  28275. // we can get touchleave events after touchend, so we want to make sure we don't
  28276. // introduce memory leaks
  28277. this.releaseInteractionDataForPointerId(interactionData.identifier);
  28278. }
  28279. };
  28280. /**
  28281. * Processes the result of the pointer over/out check and dispatches the event if need be
  28282. *
  28283. * @private
  28284. * @param {PIXI.interaction.InteractionEvent} interactionEvent - The interaction event wrapping the DOM event
  28285. * @param {PIXI.Container|PIXI.Sprite|PIXI.extras.TilingSprite} displayObject - The display object that was tested
  28286. * @param {boolean} hit - the result of the hit test on the display object
  28287. */
  28288. InteractionManager.prototype.processPointerOverOut = function processPointerOverOut(interactionEvent, displayObject, hit) {
  28289. var data = interactionEvent.data;
  28290. var id = interactionEvent.data.identifier;
  28291. var isMouse = data.pointerType === 'mouse' || data.pointerType === 'pen';
  28292. var trackingData = displayObject.trackedPointers[id];
  28293. // if we just moused over the display object, then we need to track that state
  28294. if (hit && !trackingData) {
  28295. trackingData = displayObject.trackedPointers[id] = new _InteractionTrackingData2.default(id);
  28296. }
  28297. if (trackingData === undefined) return;
  28298. if (hit && this.mouseOverRenderer) {
  28299. if (!trackingData.over) {
  28300. trackingData.over = true;
  28301. this.dispatchEvent(displayObject, 'pointerover', interactionEvent);
  28302. if (isMouse) {
  28303. this.dispatchEvent(displayObject, 'mouseover', interactionEvent);
  28304. }
  28305. }
  28306. // only change the cursor if it has not already been changed (by something deeper in the
  28307. // display tree)
  28308. if (isMouse && this.cursor === null) {
  28309. this.cursor = displayObject.cursor;
  28310. }
  28311. } else if (trackingData.over) {
  28312. trackingData.over = false;
  28313. this.dispatchEvent(displayObject, 'pointerout', this.eventData);
  28314. if (isMouse) {
  28315. this.dispatchEvent(displayObject, 'mouseout', interactionEvent);
  28316. }
  28317. // if there is no mouse down information for the pointer, then it is safe to delete
  28318. if (trackingData.none) {
  28319. delete displayObject.trackedPointers[id];
  28320. }
  28321. }
  28322. };
  28323. /**
  28324. * Is called when the pointer is moved into the renderer element
  28325. *
  28326. * @private
  28327. * @param {PointerEvent} originalEvent - The DOM event of a pointer button being moved into the renderer view
  28328. */
  28329. InteractionManager.prototype.onPointerOver = function onPointerOver(originalEvent) {
  28330. var events = this.normalizeToPointerData(originalEvent);
  28331. // Only mouse and pointer can call onPointerOver, so events will always be length 1
  28332. var event = events[0];
  28333. var interactionData = this.getInteractionDataForPointerId(event);
  28334. var interactionEvent = this.configureInteractionEventForDOMEvent(this.eventData, event, interactionData);
  28335. interactionEvent.data.originalEvent = event;
  28336. if (event.pointerType === 'mouse') {
  28337. this.mouseOverRenderer = true;
  28338. }
  28339. this.emit('pointerover', interactionEvent);
  28340. if (event.pointerType === 'mouse' || event.pointerType === 'pen') {
  28341. this.emit('mouseover', interactionEvent);
  28342. }
  28343. };
  28344. /**
  28345. * Get InteractionData for a given pointerId. Store that data as well
  28346. *
  28347. * @private
  28348. * @param {PointerEvent} event - Normalized pointer event, output from normalizeToPointerData
  28349. * @return {PIXI.interaction.InteractionData} - Interaction data for the given pointer identifier
  28350. */
  28351. InteractionManager.prototype.getInteractionDataForPointerId = function getInteractionDataForPointerId(event) {
  28352. var pointerId = event.pointerId;
  28353. var interactionData = void 0;
  28354. if (pointerId === MOUSE_POINTER_ID || event.pointerType === 'mouse') {
  28355. interactionData = this.mouse;
  28356. } else if (this.activeInteractionData[pointerId]) {
  28357. interactionData = this.activeInteractionData[pointerId];
  28358. } else {
  28359. interactionData = this.interactionDataPool.pop() || new _InteractionData2.default();
  28360. interactionData.identifier = pointerId;
  28361. this.activeInteractionData[pointerId] = interactionData;
  28362. }
  28363. // copy properties from the event, so that we can make sure that touch/pointer specific
  28364. // data is available
  28365. interactionData.copyEvent(event);
  28366. return interactionData;
  28367. };
  28368. /**
  28369. * Return unused InteractionData to the pool, for a given pointerId
  28370. *
  28371. * @private
  28372. * @param {number} pointerId - Identifier from a pointer event
  28373. */
  28374. InteractionManager.prototype.releaseInteractionDataForPointerId = function releaseInteractionDataForPointerId(pointerId) {
  28375. var interactionData = this.activeInteractionData[pointerId];
  28376. if (interactionData) {
  28377. delete this.activeInteractionData[pointerId];
  28378. interactionData.reset();
  28379. this.interactionDataPool.push(interactionData);
  28380. }
  28381. };
  28382. /**
  28383. * Configure an InteractionEvent to wrap a DOM PointerEvent and InteractionData
  28384. *
  28385. * @private
  28386. * @param {PIXI.interaction.InteractionEvent} interactionEvent - The event to be configured
  28387. * @param {PointerEvent} pointerEvent - The DOM event that will be paired with the InteractionEvent
  28388. * @param {PIXI.interaction.InteractionData} interactionData - The InteractionData that will be paired
  28389. * with the InteractionEvent
  28390. * @return {PIXI.interaction.InteractionEvent} the interaction event that was passed in
  28391. */
  28392. InteractionManager.prototype.configureInteractionEventForDOMEvent = function configureInteractionEventForDOMEvent(interactionEvent, pointerEvent, interactionData) {
  28393. interactionEvent.data = interactionData;
  28394. this.mapPositionToPoint(interactionData.global, pointerEvent.clientX, pointerEvent.clientY);
  28395. // This is the way InteractionManager processed touch events before the refactoring, so I've kept
  28396. // it here. But it doesn't make that much sense to me, since mapPositionToPoint already factors
  28397. // in this.resolution, so this just divides by this.resolution twice for touch events...
  28398. if (navigator.isCocoonJS && pointerEvent.pointerType === 'touch') {
  28399. interactionData.global.x = interactionData.global.x / this.resolution;
  28400. interactionData.global.y = interactionData.global.y / this.resolution;
  28401. }
  28402. // Not really sure why this is happening, but it's how a previous version handled things
  28403. if (pointerEvent.pointerType === 'touch') {
  28404. pointerEvent.globalX = interactionData.global.x;
  28405. pointerEvent.globalY = interactionData.global.y;
  28406. }
  28407. interactionData.originalEvent = pointerEvent;
  28408. interactionEvent.reset();
  28409. return interactionEvent;
  28410. };
  28411. /**
  28412. * Ensures that the original event object contains all data that a regular pointer event would have
  28413. *
  28414. * @private
  28415. * @param {TouchEvent|MouseEvent|PointerEvent} event - The original event data from a touch or mouse event
  28416. * @return {PointerEvent[]} An array containing a single normalized pointer event, in the case of a pointer
  28417. * or mouse event, or a multiple normalized pointer events if there are multiple changed touches
  28418. */
  28419. InteractionManager.prototype.normalizeToPointerData = function normalizeToPointerData(event) {
  28420. var normalizedEvents = [];
  28421. if (this.supportsTouchEvents && event instanceof TouchEvent) {
  28422. for (var i = 0, li = event.changedTouches.length; i < li; i++) {
  28423. var touch = event.changedTouches[i];
  28424. if (typeof touch.button === 'undefined') touch.button = event.touches.length ? 1 : 0;
  28425. if (typeof touch.buttons === 'undefined') touch.buttons = event.touches.length ? 1 : 0;
  28426. if (typeof touch.isPrimary === 'undefined') {
  28427. touch.isPrimary = event.touches.length === 1 && event.type === 'touchstart';
  28428. }
  28429. if (typeof touch.width === 'undefined') touch.width = touch.radiusX || 1;
  28430. if (typeof touch.height === 'undefined') touch.height = touch.radiusY || 1;
  28431. if (typeof touch.tiltX === 'undefined') touch.tiltX = 0;
  28432. if (typeof touch.tiltY === 'undefined') touch.tiltY = 0;
  28433. if (typeof touch.pointerType === 'undefined') touch.pointerType = 'touch';
  28434. if (typeof touch.pointerId === 'undefined') touch.pointerId = touch.identifier || 0;
  28435. if (typeof touch.pressure === 'undefined') touch.pressure = touch.force || 0.5;
  28436. touch.twist = 0;
  28437. touch.tangentialPressure = 0;
  28438. // TODO: Remove these, as layerX/Y is not a standard, is deprecated, has uneven
  28439. // support, and the fill ins are not quite the same
  28440. // offsetX/Y might be okay, but is not the same as clientX/Y when the canvas's top
  28441. // left is not 0,0 on the page
  28442. if (typeof touch.layerX === 'undefined') touch.layerX = touch.offsetX = touch.clientX;
  28443. if (typeof touch.layerY === 'undefined') touch.layerY = touch.offsetY = touch.clientY;
  28444. // mark the touch as normalized, just so that we know we did it
  28445. touch.isNormalized = true;
  28446. normalizedEvents.push(touch);
  28447. }
  28448. }
  28449. // apparently PointerEvent subclasses MouseEvent, so yay
  28450. else if (event instanceof MouseEvent && (!this.supportsPointerEvents || !(event instanceof window.PointerEvent))) {
  28451. if (typeof event.isPrimary === 'undefined') event.isPrimary = true;
  28452. if (typeof event.width === 'undefined') event.width = 1;
  28453. if (typeof event.height === 'undefined') event.height = 1;
  28454. if (typeof event.tiltX === 'undefined') event.tiltX = 0;
  28455. if (typeof event.tiltY === 'undefined') event.tiltY = 0;
  28456. if (typeof event.pointerType === 'undefined') event.pointerType = 'mouse';
  28457. if (typeof event.pointerId === 'undefined') event.pointerId = MOUSE_POINTER_ID;
  28458. if (typeof event.pressure === 'undefined') event.pressure = 0.5;
  28459. event.twist = 0;
  28460. event.tangentialPressure = 0;
  28461. // mark the mouse event as normalized, just so that we know we did it
  28462. event.isNormalized = true;
  28463. normalizedEvents.push(event);
  28464. } else {
  28465. normalizedEvents.push(event);
  28466. }
  28467. return normalizedEvents;
  28468. };
  28469. /**
  28470. * Destroys the interaction manager
  28471. *
  28472. */
  28473. InteractionManager.prototype.destroy = function destroy() {
  28474. this.removeEvents();
  28475. this.removeAllListeners();
  28476. this.renderer = null;
  28477. this.mouse = null;
  28478. this.eventData = null;
  28479. this.interactionDOMElement = null;
  28480. this.onPointerDown = null;
  28481. this.processPointerDown = null;
  28482. this.onPointerUp = null;
  28483. this.processPointerUp = null;
  28484. this.onPointerCancel = null;
  28485. this.processPointerCancel = null;
  28486. this.onPointerMove = null;
  28487. this.processPointerMove = null;
  28488. this.onPointerOut = null;
  28489. this.processPointerOverOut = null;
  28490. this.onPointerOver = null;
  28491. this._tempPoint = null;
  28492. };
  28493. return InteractionManager;
  28494. }(_eventemitter2.default);
  28495. exports.default = InteractionManager;
  28496. core.WebGLRenderer.registerPlugin('interaction', InteractionManager);
  28497. core.CanvasRenderer.registerPlugin('interaction', InteractionManager);
  28498. }, { "../core": 65, "./InteractionData": 155, "./InteractionEvent": 156, "./InteractionTrackingData": 158, "./interactiveTarget": 160, "eventemitter3": 3 }], 158: [function (require, module, exports) {
  28499. "use strict";
  28500. exports.__esModule = true;
  28501. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  28502. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  28503. /**
  28504. * DisplayObjects with the {@link PIXI.interaction.interactiveTarget} mixin use this class to track interactions
  28505. *
  28506. * @class
  28507. * @private
  28508. * @memberof PIXI.interaction
  28509. */
  28510. var InteractionTrackingData = function () {
  28511. /**
  28512. * @param {number} pointerId - Unique pointer id of the event
  28513. */
  28514. function InteractionTrackingData(pointerId) {
  28515. _classCallCheck(this, InteractionTrackingData);
  28516. this._pointerId = pointerId;
  28517. this._flags = InteractionTrackingData.FLAGS.NONE;
  28518. }
  28519. /**
  28520. *
  28521. * @private
  28522. * @param {number} flag - The interaction flag to set
  28523. * @param {boolean} yn - Should the flag be set or unset
  28524. */
  28525. InteractionTrackingData.prototype._doSet = function _doSet(flag, yn) {
  28526. if (yn) {
  28527. this._flags = this._flags | flag;
  28528. } else {
  28529. this._flags = this._flags & ~flag;
  28530. }
  28531. };
  28532. /**
  28533. * Unique pointer id of the event
  28534. *
  28535. * @readonly
  28536. * @member {number}
  28537. */
  28538. _createClass(InteractionTrackingData, [{
  28539. key: "pointerId",
  28540. get: function get() {
  28541. return this._pointerId;
  28542. }
  28543. /**
  28544. * State of the tracking data, expressed as bit flags
  28545. *
  28546. * @member {number}
  28547. * @memberof PIXI.interaction.InteractionTrackingData#
  28548. */
  28549. }, {
  28550. key: "flags",
  28551. get: function get() {
  28552. return this._flags;
  28553. }
  28554. /**
  28555. * Set the flags for the tracking data
  28556. *
  28557. * @param {number} flags - Flags to set
  28558. */
  28559. ,
  28560. set: function set(flags) {
  28561. this._flags = flags;
  28562. }
  28563. /**
  28564. * Is the tracked event inactive (not over or down)?
  28565. *
  28566. * @member {number}
  28567. * @memberof PIXI.interaction.InteractionTrackingData#
  28568. */
  28569. }, {
  28570. key: "none",
  28571. get: function get() {
  28572. return this._flags === this.constructor.FLAGS.NONE;
  28573. }
  28574. /**
  28575. * Is the tracked event over the DisplayObject?
  28576. *
  28577. * @member {boolean}
  28578. * @memberof PIXI.interaction.InteractionTrackingData#
  28579. */
  28580. }, {
  28581. key: "over",
  28582. get: function get() {
  28583. return (this._flags & this.constructor.FLAGS.OVER) !== 0;
  28584. }
  28585. /**
  28586. * Set the over flag
  28587. *
  28588. * @param {boolean} yn - Is the event over?
  28589. */
  28590. ,
  28591. set: function set(yn) {
  28592. this._doSet(this.constructor.FLAGS.OVER, yn);
  28593. }
  28594. /**
  28595. * Did the right mouse button come down in the DisplayObject?
  28596. *
  28597. * @member {boolean}
  28598. * @memberof PIXI.interaction.InteractionTrackingData#
  28599. */
  28600. }, {
  28601. key: "rightDown",
  28602. get: function get() {
  28603. return (this._flags & this.constructor.FLAGS.RIGHT_DOWN) !== 0;
  28604. }
  28605. /**
  28606. * Set the right down flag
  28607. *
  28608. * @param {boolean} yn - Is the right mouse button down?
  28609. */
  28610. ,
  28611. set: function set(yn) {
  28612. this._doSet(this.constructor.FLAGS.RIGHT_DOWN, yn);
  28613. }
  28614. /**
  28615. * Did the left mouse button come down in the DisplayObject?
  28616. *
  28617. * @member {boolean}
  28618. * @memberof PIXI.interaction.InteractionTrackingData#
  28619. */
  28620. }, {
  28621. key: "leftDown",
  28622. get: function get() {
  28623. return (this._flags & this.constructor.FLAGS.LEFT_DOWN) !== 0;
  28624. }
  28625. /**
  28626. * Set the left down flag
  28627. *
  28628. * @param {boolean} yn - Is the left mouse button down?
  28629. */
  28630. ,
  28631. set: function set(yn) {
  28632. this._doSet(this.constructor.FLAGS.LEFT_DOWN, yn);
  28633. }
  28634. }]);
  28635. return InteractionTrackingData;
  28636. }();
  28637. exports.default = InteractionTrackingData;
  28638. InteractionTrackingData.FLAGS = Object.freeze({
  28639. NONE: 0,
  28640. OVER: 1 << 0,
  28641. LEFT_DOWN: 1 << 1,
  28642. RIGHT_DOWN: 1 << 2
  28643. });
  28644. }, {}], 159: [function (require, module, exports) {
  28645. 'use strict';
  28646. exports.__esModule = true;
  28647. var _InteractionData = require('./InteractionData');
  28648. Object.defineProperty(exports, 'InteractionData', {
  28649. enumerable: true,
  28650. get: function get() {
  28651. return _interopRequireDefault(_InteractionData).default;
  28652. }
  28653. });
  28654. var _InteractionManager = require('./InteractionManager');
  28655. Object.defineProperty(exports, 'InteractionManager', {
  28656. enumerable: true,
  28657. get: function get() {
  28658. return _interopRequireDefault(_InteractionManager).default;
  28659. }
  28660. });
  28661. var _interactiveTarget = require('./interactiveTarget');
  28662. Object.defineProperty(exports, 'interactiveTarget', {
  28663. enumerable: true,
  28664. get: function get() {
  28665. return _interopRequireDefault(_interactiveTarget).default;
  28666. }
  28667. });
  28668. var _InteractionTrackingData = require('./InteractionTrackingData');
  28669. Object.defineProperty(exports, 'InteractionTrackingData', {
  28670. enumerable: true,
  28671. get: function get() {
  28672. return _interopRequireDefault(_InteractionTrackingData).default;
  28673. }
  28674. });
  28675. var _InteractionEvent = require('./InteractionEvent');
  28676. Object.defineProperty(exports, 'InteractionEvent', {
  28677. enumerable: true,
  28678. get: function get() {
  28679. return _interopRequireDefault(_InteractionEvent).default;
  28680. }
  28681. });
  28682. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  28683. }, { "./InteractionData": 155, "./InteractionEvent": 156, "./InteractionManager": 157, "./InteractionTrackingData": 158, "./interactiveTarget": 160 }], 160: [function (require, module, exports) {
  28684. 'use strict';
  28685. exports.__esModule = true;
  28686. /**
  28687. * Default property values of interactive objects
  28688. * Used by {@link PIXI.interaction.InteractionManager} to automatically give all DisplayObjects these properties
  28689. *
  28690. * @private
  28691. * @name interactiveTarget
  28692. * @memberof PIXI.interaction
  28693. * @example
  28694. * function MyObject() {}
  28695. *
  28696. * Object.assign(
  28697. * core.DisplayObject.prototype,
  28698. * PIXI.interaction.interactiveTarget
  28699. * );
  28700. */
  28701. exports.default = {
  28702. /**
  28703. * Enable interaction events for the DisplayObject. Touch, pointer and mouse
  28704. * events will not be emitted unless `interactive` is set to `true`.
  28705. *
  28706. * @example
  28707. * const sprite = new PIXI.Sprite(texture);
  28708. * sprite.interactive = true;
  28709. * sprite.on('tap', (event) => {
  28710. * //handle event
  28711. * });
  28712. * @member {boolean}
  28713. * @memberof PIXI.DisplayObject#
  28714. */
  28715. interactive: false,
  28716. /**
  28717. * Determines if the children to the displayObject can be clicked/touched
  28718. * Setting this to false allows PixiJS to bypass a recursive `hitTest` function
  28719. *
  28720. * @member {boolean}
  28721. * @memberof PIXI.Container#
  28722. */
  28723. interactiveChildren: true,
  28724. /**
  28725. * Interaction shape. Children will be hit first, then this shape will be checked.
  28726. * Setting this will cause this shape to be checked in hit tests rather than the displayObject's bounds.
  28727. *
  28728. * @example
  28729. * const sprite = new PIXI.Sprite(texture);
  28730. * sprite.interactive = true;
  28731. * sprite.hitArea = new PIXI.Rectangle(0, 0, 100, 100);
  28732. * @member {PIXI.Rectangle|PIXI.Circle|PIXI.Ellipse|PIXI.Polygon|PIXI.RoundedRectangle}
  28733. * @memberof PIXI.DisplayObject#
  28734. */
  28735. hitArea: null,
  28736. /**
  28737. * If enabled, the mouse cursor use the pointer behavior when hovered over the displayObject if it is interactive
  28738. * Setting this changes the 'cursor' property to `'pointer'`.
  28739. *
  28740. * @example
  28741. * const sprite = new PIXI.Sprite(texture);
  28742. * sprite.interactive = true;
  28743. * sprite.buttonMode = true;
  28744. * @member {boolean}
  28745. * @memberof PIXI.DisplayObject#
  28746. */
  28747. get buttonMode() {
  28748. return this.cursor === 'pointer';
  28749. },
  28750. set buttonMode(value) {
  28751. if (value) {
  28752. this.cursor = 'pointer';
  28753. } else if (this.cursor === 'pointer') {
  28754. this.cursor = null;
  28755. }
  28756. },
  28757. /**
  28758. * This defines what cursor mode is used when the mouse cursor
  28759. * is hovered over the displayObject.
  28760. *
  28761. * @example
  28762. * const sprite = new PIXI.Sprite(texture);
  28763. * sprite.interactive = true;
  28764. * sprite.cursor = 'wait';
  28765. * @see https://developer.mozilla.org/en/docs/Web/CSS/cursor
  28766. *
  28767. * @member {string}
  28768. * @memberof PIXI.DisplayObject#
  28769. */
  28770. cursor: null,
  28771. /**
  28772. * Internal set of all active pointers, by identifier
  28773. *
  28774. * @member {Map<number, InteractionTrackingData>}
  28775. * @memberof PIXI.DisplayObject#
  28776. * @private
  28777. */
  28778. get trackedPointers() {
  28779. if (this._trackedPointers === undefined) this._trackedPointers = {};
  28780. return this._trackedPointers;
  28781. },
  28782. /**
  28783. * Map of all tracked pointers, by identifier. Use trackedPointers to access.
  28784. *
  28785. * @private
  28786. * @type {Map<number, InteractionTrackingData>}
  28787. */
  28788. _trackedPointers: undefined
  28789. };
  28790. }, {}], 161: [function (require, module, exports) {
  28791. 'use strict';
  28792. exports.__esModule = true;
  28793. exports.parse = parse;
  28794. exports.default = function () {
  28795. return function bitmapFontParser(resource, next) {
  28796. // skip if no data or not xml data
  28797. if (!resource.data || resource.type !== _resourceLoader.Resource.TYPE.XML) {
  28798. next();
  28799. return;
  28800. }
  28801. // skip if not bitmap font data, using some silly duck-typing
  28802. if (resource.data.getElementsByTagName('page').length === 0 || resource.data.getElementsByTagName('info').length === 0 || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null) {
  28803. next();
  28804. return;
  28805. }
  28806. var xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : '';
  28807. if (resource.isDataUrl) {
  28808. if (xmlUrl === '.') {
  28809. xmlUrl = '';
  28810. }
  28811. if (this.baseUrl && xmlUrl) {
  28812. // if baseurl has a trailing slash then add one to xmlUrl so the replace works below
  28813. if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') {
  28814. xmlUrl += '/';
  28815. }
  28816. }
  28817. }
  28818. // remove baseUrl from xmlUrl
  28819. xmlUrl = xmlUrl.replace(this.baseUrl, '');
  28820. // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty.
  28821. if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') {
  28822. xmlUrl += '/';
  28823. }
  28824. var textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file');
  28825. if (_core.utils.TextureCache[textureUrl]) {
  28826. // reuse existing texture
  28827. parse(resource, _core.utils.TextureCache[textureUrl]);
  28828. next();
  28829. } else {
  28830. var loadOptions = {
  28831. crossOrigin: resource.crossOrigin,
  28832. loadType: _resourceLoader.Resource.LOAD_TYPE.IMAGE,
  28833. metadata: resource.metadata.imageMetadata,
  28834. parentResource: resource
  28835. };
  28836. // load the texture for the font
  28837. this.add(resource.name + '_image', textureUrl, loadOptions, function (res) {
  28838. parse(resource, res.texture);
  28839. next();
  28840. });
  28841. }
  28842. };
  28843. };
  28844. var _path = require('path');
  28845. var path = _interopRequireWildcard(_path);
  28846. var _core = require('../core');
  28847. var _resourceLoader = require('resource-loader');
  28848. var _extras = require('../extras');
  28849. function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
  28850. /**
  28851. * Register a BitmapText font from loader resource.
  28852. *
  28853. * @function parseBitmapFontData
  28854. * @memberof PIXI.loaders
  28855. * @param {PIXI.loaders.Resource} resource - Loader resource.
  28856. * @param {PIXI.Texture} texture - Reference to texture.
  28857. */
  28858. function parse(resource, texture) {
  28859. resource.bitmapFont = _extras.BitmapText.registerFont(resource.data, texture);
  28860. }
  28861. }, { "../core": 65, "../extras": 141, "path": 8, "resource-loader": 36 }], 162: [function (require, module, exports) {
  28862. 'use strict';
  28863. exports.__esModule = true;
  28864. exports.shared = exports.Resource = exports.textureParser = exports.getResourcePath = exports.spritesheetParser = exports.parseBitmapFontData = exports.bitmapFontParser = exports.Loader = undefined;
  28865. var _bitmapFontParser = require('./bitmapFontParser');
  28866. Object.defineProperty(exports, 'bitmapFontParser', {
  28867. enumerable: true,
  28868. get: function get() {
  28869. return _interopRequireDefault(_bitmapFontParser).default;
  28870. }
  28871. });
  28872. Object.defineProperty(exports, 'parseBitmapFontData', {
  28873. enumerable: true,
  28874. get: function get() {
  28875. return _bitmapFontParser.parse;
  28876. }
  28877. });
  28878. var _spritesheetParser = require('./spritesheetParser');
  28879. Object.defineProperty(exports, 'spritesheetParser', {
  28880. enumerable: true,
  28881. get: function get() {
  28882. return _interopRequireDefault(_spritesheetParser).default;
  28883. }
  28884. });
  28885. Object.defineProperty(exports, 'getResourcePath', {
  28886. enumerable: true,
  28887. get: function get() {
  28888. return _spritesheetParser.getResourcePath;
  28889. }
  28890. });
  28891. var _textureParser = require('./textureParser');
  28892. Object.defineProperty(exports, 'textureParser', {
  28893. enumerable: true,
  28894. get: function get() {
  28895. return _interopRequireDefault(_textureParser).default;
  28896. }
  28897. });
  28898. var _resourceLoader = require('resource-loader');
  28899. Object.defineProperty(exports, 'Resource', {
  28900. enumerable: true,
  28901. get: function get() {
  28902. return _resourceLoader.Resource;
  28903. }
  28904. });
  28905. var _Application = require('../core/Application');
  28906. var _Application2 = _interopRequireDefault(_Application);
  28907. var _loader = require('./loader');
  28908. var _loader2 = _interopRequireDefault(_loader);
  28909. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  28910. /**
  28911. * This namespace contains APIs which extends the {@link https://github.com/englercj/resource-loader resource-loader} module
  28912. * for loading assets, data, and other resources dynamically.
  28913. * @example
  28914. * const loader = new PIXI.loaders.Loader();
  28915. * loader.add('bunny', 'data/bunny.png')
  28916. * .add('spaceship', 'assets/spritesheet.json');
  28917. * loader.load((loader, resources) => {
  28918. * // resources.bunny
  28919. * // resources.spaceship
  28920. * });
  28921. * @namespace PIXI.loaders
  28922. */
  28923. exports.Loader = _loader2.default;
  28924. /**
  28925. * A premade instance of the loader that can be used to load resources.
  28926. * @name shared
  28927. * @memberof PIXI.loaders
  28928. * @type {PIXI.loaders.Loader}
  28929. */
  28930. var shared = new _loader2.default();
  28931. shared.destroy = function () {
  28932. // protect destroying shared loader
  28933. };
  28934. exports.shared = shared;
  28935. // Mixin the loader construction
  28936. var AppPrototype = _Application2.default.prototype;
  28937. AppPrototype._loader = null;
  28938. /**
  28939. * Loader instance to help with asset loading.
  28940. * @name PIXI.Application#loader
  28941. * @type {PIXI.loaders.Loader}
  28942. */
  28943. Object.defineProperty(AppPrototype, 'loader', {
  28944. get: function get() {
  28945. if (!this._loader) {
  28946. var sharedLoader = this._options.sharedLoader;
  28947. this._loader = sharedLoader ? shared : new _loader2.default();
  28948. }
  28949. return this._loader;
  28950. }
  28951. });
  28952. // Override the destroy function
  28953. // making sure to destroy the current Loader
  28954. AppPrototype._parentDestroy = AppPrototype.destroy;
  28955. AppPrototype.destroy = function destroy(removeView) {
  28956. if (this._loader) {
  28957. this._loader.destroy();
  28958. this._loader = null;
  28959. }
  28960. this._parentDestroy(removeView);
  28961. };
  28962. }, { "../core/Application": 43, "./bitmapFontParser": 161, "./loader": 163, "./spritesheetParser": 164, "./textureParser": 165, "resource-loader": 36 }], 163: [function (require, module, exports) {
  28963. 'use strict';
  28964. exports.__esModule = true;
  28965. var _resourceLoader = require('resource-loader');
  28966. var _resourceLoader2 = _interopRequireDefault(_resourceLoader);
  28967. var _blob = require('resource-loader/lib/middlewares/parsing/blob');
  28968. var _eventemitter = require('eventemitter3');
  28969. var _eventemitter2 = _interopRequireDefault(_eventemitter);
  28970. var _textureParser = require('./textureParser');
  28971. var _textureParser2 = _interopRequireDefault(_textureParser);
  28972. var _spritesheetParser = require('./spritesheetParser');
  28973. var _spritesheetParser2 = _interopRequireDefault(_spritesheetParser);
  28974. var _bitmapFontParser = require('./bitmapFontParser');
  28975. var _bitmapFontParser2 = _interopRequireDefault(_bitmapFontParser);
  28976. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  28977. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  28978. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  28979. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  28980. /**
  28981. *
  28982. * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader
  28983. *
  28984. * ```js
  28985. * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use.
  28986. * //or
  28987. * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want
  28988. *
  28989. * const sprites = {};
  28990. *
  28991. * // Chainable `add` to enqueue a resource
  28992. * loader.add('bunny', 'data/bunny.png')
  28993. * .add('spaceship', 'assets/spritesheet.json');
  28994. * loader.add('scoreFont', 'assets/score.fnt');
  28995. *
  28996. * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource.
  28997. * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc).
  28998. * loader.pre(cachingMiddleware);
  28999. *
  29000. * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource.
  29001. * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc).
  29002. * loader.use(parsingMiddleware);
  29003. *
  29004. * // The `load` method loads the queue of resources, and calls the passed in callback called once all
  29005. * // resources have loaded.
  29006. * loader.load((loader, resources) => {
  29007. * // resources is an object where the key is the name of the resource loaded and the value is the resource object.
  29008. * // They have a couple default properties:
  29009. * // - `url`: The URL that the resource was loaded from
  29010. * // - `error`: The error that happened when trying to load (if any)
  29011. * // - `data`: The raw data that was loaded
  29012. * // also may contain other properties based on the middleware that runs.
  29013. * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture);
  29014. * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture);
  29015. * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture);
  29016. * });
  29017. *
  29018. * // throughout the process multiple signals can be dispatched.
  29019. * loader.onProgress.add(() => {}); // called once per loaded/errored file
  29020. * loader.onError.add(() => {}); // called once per errored file
  29021. * loader.onLoad.add(() => {}); // called once per loaded file
  29022. * loader.onComplete.add(() => {}); // called once when the queued resources all load.
  29023. * ```
  29024. *
  29025. * @see https://github.com/englercj/resource-loader
  29026. *
  29027. * @class
  29028. * @extends module:resource-loader.ResourceLoader
  29029. * @memberof PIXI.loaders
  29030. */
  29031. var Loader = function (_ResourceLoader) {
  29032. _inherits(Loader, _ResourceLoader);
  29033. /**
  29034. * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader.
  29035. * @param {number} [concurrency=10] - The number of resources to load concurrently.
  29036. */
  29037. function Loader(baseUrl, concurrency) {
  29038. _classCallCheck(this, Loader);
  29039. var _this = _possibleConstructorReturn(this, _ResourceLoader.call(this, baseUrl, concurrency));
  29040. _eventemitter2.default.call(_this);
  29041. for (var i = 0; i < Loader._pixiMiddleware.length; ++i) {
  29042. _this.use(Loader._pixiMiddleware[i]());
  29043. }
  29044. // Compat layer, translate the new v2 signals into old v1 events.
  29045. _this.onStart.add(function (l) {
  29046. return _this.emit('start', l);
  29047. });
  29048. _this.onProgress.add(function (l, r) {
  29049. return _this.emit('progress', l, r);
  29050. });
  29051. _this.onError.add(function (e, l, r) {
  29052. return _this.emit('error', e, l, r);
  29053. });
  29054. _this.onLoad.add(function (l, r) {
  29055. return _this.emit('load', l, r);
  29056. });
  29057. _this.onComplete.add(function (l, r) {
  29058. return _this.emit('complete', l, r);
  29059. });
  29060. return _this;
  29061. }
  29062. /**
  29063. * Adds a default middleware to the PixiJS loader.
  29064. *
  29065. * @static
  29066. * @param {Function} fn - The middleware to add.
  29067. */
  29068. Loader.addPixiMiddleware = function addPixiMiddleware(fn) {
  29069. Loader._pixiMiddleware.push(fn);
  29070. };
  29071. /**
  29072. * Destroy the loader, removes references.
  29073. */
  29074. Loader.prototype.destroy = function destroy() {
  29075. this.removeAllListeners();
  29076. this.reset();
  29077. };
  29078. return Loader;
  29079. }(_resourceLoader2.default);
  29080. // Copy EE3 prototype (mixin)
  29081. exports.default = Loader;
  29082. for (var k in _eventemitter2.default.prototype) {
  29083. Loader.prototype[k] = _eventemitter2.default.prototype[k];
  29084. }
  29085. Loader._pixiMiddleware = [
  29086. // parse any blob into more usable objects (e.g. Image)
  29087. _blob.blobMiddlewareFactory,
  29088. // parse any Image objects into textures
  29089. _textureParser2.default,
  29090. // parse any spritesheet data into multiple textures
  29091. _spritesheetParser2.default,
  29092. // parse bitmap font data into multiple textures
  29093. _bitmapFontParser2.default];
  29094. // Add custom extentions
  29095. var Resource = _resourceLoader2.default.Resource;
  29096. Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT);
  29097. }, { "./bitmapFontParser": 161, "./spritesheetParser": 164, "./textureParser": 165, "eventemitter3": 3, "resource-loader": 36, "resource-loader/lib/middlewares/parsing/blob": 37 }], 164: [function (require, module, exports) {
  29098. 'use strict';
  29099. exports.__esModule = true;
  29100. exports.default = function () {
  29101. return function spritesheetParser(resource, next) {
  29102. var imageResourceName = resource.name + '_image';
  29103. // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists
  29104. if (!resource.data || resource.type !== _resourceLoader.Resource.TYPE.JSON || !resource.data.frames || this.resources[imageResourceName]) {
  29105. next();
  29106. return;
  29107. }
  29108. var loadOptions = {
  29109. crossOrigin: resource.crossOrigin,
  29110. metadata: resource.metadata.imageMetadata,
  29111. parentResource: resource
  29112. };
  29113. var resourcePath = getResourcePath(resource, this.baseUrl);
  29114. // load the image for this sheet
  29115. this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) {
  29116. if (res.error) {
  29117. next(res.error);
  29118. return;
  29119. }
  29120. var spritesheet = new _core.Spritesheet(res.texture.baseTexture, resource.data, resource.url);
  29121. spritesheet.parse(function () {
  29122. resource.spritesheet = spritesheet;
  29123. resource.textures = spritesheet.textures;
  29124. next();
  29125. });
  29126. });
  29127. };
  29128. };
  29129. exports.getResourcePath = getResourcePath;
  29130. var _resourceLoader = require('resource-loader');
  29131. var _url = require('url');
  29132. var _url2 = _interopRequireDefault(_url);
  29133. var _core = require('../core');
  29134. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  29135. function getResourcePath(resource, baseUrl) {
  29136. // Prepend url path unless the resource image is a data url
  29137. if (resource.isDataUrl) {
  29138. return resource.data.meta.image;
  29139. }
  29140. return _url2.default.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image);
  29141. }
  29142. }, { "../core": 65, "resource-loader": 36, "url": 38 }], 165: [function (require, module, exports) {
  29143. 'use strict';
  29144. exports.__esModule = true;
  29145. exports.default = function () {
  29146. return function textureParser(resource, next) {
  29147. // create a new texture if the data is an Image object
  29148. if (resource.data && resource.type === _resourceLoader.Resource.TYPE.IMAGE) {
  29149. resource.texture = _Texture2.default.fromLoader(resource.data, resource.url, resource.name);
  29150. }
  29151. next();
  29152. };
  29153. };
  29154. var _resourceLoader = require('resource-loader');
  29155. var _Texture = require('../core/textures/Texture');
  29156. var _Texture2 = _interopRequireDefault(_Texture);
  29157. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  29158. }, { "../core/textures/Texture": 115, "resource-loader": 36 }], 166: [function (require, module, exports) {
  29159. 'use strict';
  29160. exports.__esModule = true;
  29161. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  29162. var _core = require('../core');
  29163. var core = _interopRequireWildcard(_core);
  29164. var _Texture = require('../core/textures/Texture');
  29165. var _Texture2 = _interopRequireDefault(_Texture);
  29166. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  29167. function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
  29168. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  29169. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  29170. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  29171. var tempPoint = new core.Point();
  29172. var tempPolygon = new core.Polygon();
  29173. /**
  29174. * Base mesh class
  29175. * @class
  29176. * @extends PIXI.Container
  29177. * @memberof PIXI.mesh
  29178. */
  29179. var Mesh = function (_core$Container) {
  29180. _inherits(Mesh, _core$Container);
  29181. /**
  29182. * @param {PIXI.Texture} texture - The texture to use
  29183. * @param {Float32Array} [vertices] - if you want to specify the vertices
  29184. * @param {Float32Array} [uvs] - if you want to specify the uvs
  29185. * @param {Uint16Array} [indices] - if you want to specify the indices
  29186. * @param {number} [drawMode] - the drawMode, can be any of the Mesh.DRAW_MODES consts
  29187. */
  29188. function Mesh(texture, vertices, uvs, indices, drawMode) {
  29189. _classCallCheck(this, Mesh);
  29190. /**
  29191. * The texture of the Mesh
  29192. *
  29193. * @member {PIXI.Texture}
  29194. * @default PIXI.Texture.EMPTY
  29195. * @private
  29196. */
  29197. var _this = _possibleConstructorReturn(this, _core$Container.call(this));
  29198. _this._texture = texture || _Texture2.default.EMPTY;
  29199. /**
  29200. * The Uvs of the Mesh
  29201. *
  29202. * @member {Float32Array}
  29203. */
  29204. _this.uvs = uvs || new Float32Array([0, 0, 1, 0, 1, 1, 0, 1]);
  29205. /**
  29206. * An array of vertices
  29207. *
  29208. * @member {Float32Array}
  29209. */
  29210. _this.vertices = vertices || new Float32Array([0, 0, 100, 0, 100, 100, 0, 100]);
  29211. /**
  29212. * An array containing the indices of the vertices
  29213. *
  29214. * @member {Uint16Array}
  29215. */
  29216. // TODO auto generate this based on draw mode!
  29217. _this.indices = indices || new Uint16Array([0, 1, 3, 2]);
  29218. /**
  29219. * Version of mesh uvs are dirty or not
  29220. *
  29221. * @member {number}
  29222. */
  29223. _this.dirty = 0;
  29224. /**
  29225. * Version of mesh indices
  29226. *
  29227. * @member {number}
  29228. */
  29229. _this.indexDirty = 0;
  29230. /**
  29231. * The blend mode to be applied to the sprite. Set to `PIXI.BLEND_MODES.NORMAL` to remove
  29232. * any blend mode.
  29233. *
  29234. * @member {number}
  29235. * @default PIXI.BLEND_MODES.NORMAL
  29236. * @see PIXI.BLEND_MODES
  29237. */
  29238. _this.blendMode = core.BLEND_MODES.NORMAL;
  29239. /**
  29240. * Triangles in canvas mode are automatically antialiased, use this value to force triangles
  29241. * to overlap a bit with each other.
  29242. *
  29243. * @member {number}
  29244. */
  29245. _this.canvasPadding = core.settings.MESH_CANVAS_PADDING;
  29246. /**
  29247. * The way the Mesh should be drawn, can be any of the {@link PIXI.mesh.Mesh.DRAW_MODES} consts
  29248. *
  29249. * @member {number}
  29250. * @see PIXI.mesh.Mesh.DRAW_MODES
  29251. */
  29252. _this.drawMode = drawMode || Mesh.DRAW_MODES.TRIANGLE_MESH;
  29253. /**
  29254. * The default shader that is used if a mesh doesn't have a more specific one.
  29255. *
  29256. * @member {PIXI.Shader}
  29257. */
  29258. _this.shader = null;
  29259. /**
  29260. * The tint applied to the mesh. This is a [r,g,b] value. A value of [1,1,1] will remove any
  29261. * tint effect.
  29262. *
  29263. * @member {number}
  29264. */
  29265. _this.tintRgb = new Float32Array([1, 1, 1]);
  29266. /**
  29267. * A map of renderer IDs to webgl render data
  29268. *
  29269. * @private
  29270. * @member {object<number, object>}
  29271. */
  29272. _this._glDatas = {};
  29273. /**
  29274. * transform that is applied to UV to get the texture coords
  29275. * its updated independently from texture uvTransform
  29276. * updates of uvs are tied to that thing
  29277. *
  29278. * @member {PIXI.TextureMatrix}
  29279. * @private
  29280. */
  29281. _this._uvTransform = new core.TextureMatrix(_this._texture);
  29282. /**
  29283. * whether or not upload uvTransform to shader
  29284. * if its false, then uvs should be pre-multiplied
  29285. * if you change it for generated mesh, please call 'refresh(true)'
  29286. * @member {boolean}
  29287. * @default false
  29288. */
  29289. _this.uploadUvTransform = false;
  29290. /**
  29291. * Plugin that is responsible for rendering this element.
  29292. * Allows to customize the rendering process without overriding '_renderWebGL' & '_renderCanvas' methods.
  29293. * @member {string}
  29294. * @default 'mesh'
  29295. */
  29296. _this.pluginName = 'mesh';
  29297. return _this;
  29298. }
  29299. /**
  29300. * Renders the object using the WebGL renderer
  29301. *
  29302. * @private
  29303. * @param {PIXI.WebGLRenderer} renderer - a reference to the WebGL renderer
  29304. */
  29305. Mesh.prototype._renderWebGL = function _renderWebGL(renderer) {
  29306. this.refresh();
  29307. renderer.setObjectRenderer(renderer.plugins[this.pluginName]);
  29308. renderer.plugins[this.pluginName].render(this);
  29309. };
  29310. /**
  29311. * Renders the object using the Canvas renderer
  29312. *
  29313. * @private
  29314. * @param {PIXI.CanvasRenderer} renderer - The canvas renderer.
  29315. */
  29316. Mesh.prototype._renderCanvas = function _renderCanvas(renderer) {
  29317. this.refresh();
  29318. renderer.plugins[this.pluginName].render(this);
  29319. };
  29320. /**
  29321. * When the texture is updated, this event will fire to update the scale and frame
  29322. *
  29323. * @private
  29324. */
  29325. Mesh.prototype._onTextureUpdate = function _onTextureUpdate() {
  29326. this._uvTransform.texture = this._texture;
  29327. this.refresh();
  29328. };
  29329. /**
  29330. * multiplies uvs only if uploadUvTransform is false
  29331. * call it after you change uvs manually
  29332. * make sure that texture is valid
  29333. */
  29334. Mesh.prototype.multiplyUvs = function multiplyUvs() {
  29335. if (!this.uploadUvTransform) {
  29336. this._uvTransform.multiplyUvs(this.uvs);
  29337. }
  29338. };
  29339. /**
  29340. * Refreshes uvs for generated meshes (rope, plane)
  29341. * sometimes refreshes vertices too
  29342. *
  29343. * @param {boolean} [forceUpdate=false] if true, matrices will be updated any case
  29344. */
  29345. Mesh.prototype.refresh = function refresh(forceUpdate) {
  29346. if (this._uvTransform.update(forceUpdate)) {
  29347. this._refresh();
  29348. }
  29349. };
  29350. /**
  29351. * re-calculates mesh coords
  29352. * @protected
  29353. */
  29354. Mesh.prototype._refresh = function _refresh() { }
  29355. /* empty */
  29356. /**
  29357. * Returns the bounds of the mesh as a rectangle. The bounds calculation takes the worldTransform into account.
  29358. *
  29359. */
  29360. ;
  29361. Mesh.prototype._calculateBounds = function _calculateBounds() {
  29362. // TODO - we can cache local bounds and use them if they are dirty (like graphics)
  29363. this._bounds.addVertices(this.transform, this.vertices, 0, this.vertices.length);
  29364. };
  29365. /**
  29366. * Tests if a point is inside this mesh. Works only for TRIANGLE_MESH
  29367. *
  29368. * @param {PIXI.Point} point - the point to test
  29369. * @return {boolean} the result of the test
  29370. */
  29371. Mesh.prototype.containsPoint = function containsPoint(point) {
  29372. if (!this.getBounds().contains(point.x, point.y)) {
  29373. return false;
  29374. }
  29375. this.worldTransform.applyInverse(point, tempPoint);
  29376. var vertices = this.vertices;
  29377. var points = tempPolygon.points;
  29378. var indices = this.indices;
  29379. var len = this.indices.length;
  29380. var step = this.drawMode === Mesh.DRAW_MODES.TRIANGLES ? 3 : 1;
  29381. for (var i = 0; i + 2 < len; i += step) {
  29382. var ind0 = indices[i] * 2;
  29383. var ind1 = indices[i + 1] * 2;
  29384. var ind2 = indices[i + 2] * 2;
  29385. points[0] = vertices[ind0];
  29386. points[1] = vertices[ind0 + 1];
  29387. points[2] = vertices[ind1];
  29388. points[3] = vertices[ind1 + 1];
  29389. points[4] = vertices[ind2];
  29390. points[5] = vertices[ind2 + 1];
  29391. if (tempPolygon.contains(tempPoint.x, tempPoint.y)) {
  29392. return true;
  29393. }
  29394. }
  29395. return false;
  29396. };
  29397. /**
  29398. * The texture that the mesh uses.
  29399. *
  29400. * @member {PIXI.Texture}
  29401. */
  29402. _createClass(Mesh, [{
  29403. key: 'texture',
  29404. get: function get() {
  29405. return this._texture;
  29406. },
  29407. set: function set(value) // eslint-disable-line require-jsdoc
  29408. {
  29409. if (this._texture === value) {
  29410. return;
  29411. }
  29412. this._texture = value;
  29413. if (value) {
  29414. // wait for the texture to load
  29415. if (value.baseTexture.hasLoaded) {
  29416. this._onTextureUpdate();
  29417. } else {
  29418. value.once('update', this._onTextureUpdate, this);
  29419. }
  29420. }
  29421. }
  29422. /**
  29423. * The tint applied to the mesh. This is a hex value. A value of 0xFFFFFF will remove any tint effect.
  29424. *
  29425. * @member {number}
  29426. * @default 0xFFFFFF
  29427. */
  29428. }, {
  29429. key: 'tint',
  29430. get: function get() {
  29431. return core.utils.rgb2hex(this.tintRgb);
  29432. },
  29433. set: function set(value) // eslint-disable-line require-jsdoc
  29434. {
  29435. this.tintRgb = core.utils.hex2rgb(value, this.tintRgb);
  29436. }
  29437. }]);
  29438. return Mesh;
  29439. }(core.Container);
  29440. /**
  29441. * Different drawing buffer modes supported
  29442. *
  29443. * @static
  29444. * @constant
  29445. * @type {object}
  29446. * @property {number} TRIANGLE_MESH
  29447. * @property {number} TRIANGLES
  29448. */
  29449. exports.default = Mesh;
  29450. Mesh.DRAW_MODES = {
  29451. TRIANGLE_MESH: 0,
  29452. TRIANGLES: 1
  29453. };
  29454. }, { "../core": 65, "../core/textures/Texture": 115 }], 167: [function (require, module, exports) {
  29455. 'use strict';
  29456. exports.__esModule = true;
  29457. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  29458. var _Plane2 = require('./Plane');
  29459. var _Plane3 = _interopRequireDefault(_Plane2);
  29460. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  29461. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  29462. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  29463. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  29464. var DEFAULT_BORDER_SIZE = 10;
  29465. /**
  29466. * The NineSlicePlane allows you to stretch a texture using 9-slice scaling. The corners will remain unscaled (useful
  29467. * for buttons with rounded corners for example) and the other areas will be scaled horizontally and or vertically
  29468. *
  29469. *```js
  29470. * let Plane9 = new PIXI.NineSlicePlane(PIXI.Texture.fromImage('BoxWithRoundedCorners.png'), 15, 15, 15, 15);
  29471. * ```
  29472. * <pre>
  29473. * A B
  29474. * +---+----------------------+---+
  29475. * C | 1 | 2 | 3 |
  29476. * +---+----------------------+---+
  29477. * | | | |
  29478. * | 4 | 5 | 6 |
  29479. * | | | |
  29480. * +---+----------------------+---+
  29481. * D | 7 | 8 | 9 |
  29482. * +---+----------------------+---+
  29483. * When changing this objects width and/or height:
  29484. * areas 1 3 7 and 9 will remain unscaled.
  29485. * areas 2 and 8 will be stretched horizontally
  29486. * areas 4 and 6 will be stretched vertically
  29487. * area 5 will be stretched both horizontally and vertically
  29488. * </pre>
  29489. *
  29490. * @class
  29491. * @extends PIXI.mesh.Plane
  29492. * @memberof PIXI.mesh
  29493. *
  29494. */
  29495. var NineSlicePlane = function (_Plane) {
  29496. _inherits(NineSlicePlane, _Plane);
  29497. /**
  29498. * @param {PIXI.Texture} texture - The texture to use on the NineSlicePlane.
  29499. * @param {int} [leftWidth=10] size of the left vertical bar (A)
  29500. * @param {int} [topHeight=10] size of the top horizontal bar (C)
  29501. * @param {int} [rightWidth=10] size of the right vertical bar (B)
  29502. * @param {int} [bottomHeight=10] size of the bottom horizontal bar (D)
  29503. */
  29504. function NineSlicePlane(texture, leftWidth, topHeight, rightWidth, bottomHeight) {
  29505. _classCallCheck(this, NineSlicePlane);
  29506. var _this = _possibleConstructorReturn(this, _Plane.call(this, texture, 4, 4));
  29507. _this._origWidth = texture.orig.width;
  29508. _this._origHeight = texture.orig.height;
  29509. /**
  29510. * The width of the NineSlicePlane, setting this will actually modify the vertices and UV's of this plane
  29511. *
  29512. * @member {number}
  29513. * @memberof PIXI.NineSlicePlane#
  29514. * @override
  29515. */
  29516. _this._width = _this._origWidth;
  29517. /**
  29518. * The height of the NineSlicePlane, setting this will actually modify the vertices and UV's of this plane
  29519. *
  29520. * @member {number}
  29521. * @memberof PIXI.NineSlicePlane#
  29522. * @override
  29523. */
  29524. _this._height = _this._origHeight;
  29525. /**
  29526. * The width of the left column (a)
  29527. *
  29528. * @member {number}
  29529. * @memberof PIXI.NineSlicePlane#
  29530. * @override
  29531. */
  29532. _this.leftWidth = typeof leftWidth !== 'undefined' ? leftWidth : DEFAULT_BORDER_SIZE;
  29533. /**
  29534. * The width of the right column (b)
  29535. *
  29536. * @member {number}
  29537. * @memberof PIXI.NineSlicePlane#
  29538. * @override
  29539. */
  29540. _this.rightWidth = typeof rightWidth !== 'undefined' ? rightWidth : DEFAULT_BORDER_SIZE;
  29541. /**
  29542. * The height of the top row (c)
  29543. *
  29544. * @member {number}
  29545. * @memberof PIXI.NineSlicePlane#
  29546. * @override
  29547. */
  29548. _this.topHeight = typeof topHeight !== 'undefined' ? topHeight : DEFAULT_BORDER_SIZE;
  29549. /**
  29550. * The height of the bottom row (d)
  29551. *
  29552. * @member {number}
  29553. * @memberof PIXI.NineSlicePlane#
  29554. * @override
  29555. */
  29556. _this.bottomHeight = typeof bottomHeight !== 'undefined' ? bottomHeight : DEFAULT_BORDER_SIZE;
  29557. _this.refresh(true);
  29558. return _this;
  29559. }
  29560. /**
  29561. * Updates the horizontal vertices.
  29562. *
  29563. */
  29564. NineSlicePlane.prototype.updateHorizontalVertices = function updateHorizontalVertices() {
  29565. var vertices = this.vertices;
  29566. vertices[9] = vertices[11] = vertices[13] = vertices[15] = this._topHeight;
  29567. vertices[17] = vertices[19] = vertices[21] = vertices[23] = this._height - this._bottomHeight;
  29568. vertices[25] = vertices[27] = vertices[29] = vertices[31] = this._height;
  29569. };
  29570. /**
  29571. * Updates the vertical vertices.
  29572. *
  29573. */
  29574. NineSlicePlane.prototype.updateVerticalVertices = function updateVerticalVertices() {
  29575. var vertices = this.vertices;
  29576. vertices[2] = vertices[10] = vertices[18] = vertices[26] = this._leftWidth;
  29577. vertices[4] = vertices[12] = vertices[20] = vertices[28] = this._width - this._rightWidth;
  29578. vertices[6] = vertices[14] = vertices[22] = vertices[30] = this._width;
  29579. };
  29580. /**
  29581. * Renders the object using the Canvas renderer
  29582. *
  29583. * @private
  29584. * @param {PIXI.CanvasRenderer} renderer - The canvas renderer to render with.
  29585. */
  29586. NineSlicePlane.prototype._renderCanvas = function _renderCanvas(renderer) {
  29587. var context = renderer.context;
  29588. context.globalAlpha = this.worldAlpha;
  29589. renderer.setBlendMode(this.blendMode);
  29590. var transform = this.worldTransform;
  29591. var res = renderer.resolution;
  29592. if (renderer.roundPixels) {
  29593. context.setTransform(transform.a * res, transform.b * res, transform.c * res, transform.d * res, transform.tx * res | 0, transform.ty * res | 0);
  29594. } else {
  29595. context.setTransform(transform.a * res, transform.b * res, transform.c * res, transform.d * res, transform.tx * res, transform.ty * res);
  29596. }
  29597. var base = this._texture.baseTexture;
  29598. var textureSource = base.source;
  29599. var w = base.width * base.resolution;
  29600. var h = base.height * base.resolution;
  29601. this.drawSegment(context, textureSource, w, h, 0, 1, 10, 11);
  29602. this.drawSegment(context, textureSource, w, h, 2, 3, 12, 13);
  29603. this.drawSegment(context, textureSource, w, h, 4, 5, 14, 15);
  29604. this.drawSegment(context, textureSource, w, h, 8, 9, 18, 19);
  29605. this.drawSegment(context, textureSource, w, h, 10, 11, 20, 21);
  29606. this.drawSegment(context, textureSource, w, h, 12, 13, 22, 23);
  29607. this.drawSegment(context, textureSource, w, h, 16, 17, 26, 27);
  29608. this.drawSegment(context, textureSource, w, h, 18, 19, 28, 29);
  29609. this.drawSegment(context, textureSource, w, h, 20, 21, 30, 31);
  29610. };
  29611. /**
  29612. * Renders one segment of the plane.
  29613. * to mimic the exact drawing behavior of stretching the image like WebGL does, we need to make sure
  29614. * that the source area is at least 1 pixel in size, otherwise nothing gets drawn when a slice size of 0 is used.
  29615. *
  29616. * @private
  29617. * @param {CanvasRenderingContext2D} context - The context to draw with.
  29618. * @param {CanvasImageSource} textureSource - The source to draw.
  29619. * @param {number} w - width of the texture
  29620. * @param {number} h - height of the texture
  29621. * @param {number} x1 - x index 1
  29622. * @param {number} y1 - y index 1
  29623. * @param {number} x2 - x index 2
  29624. * @param {number} y2 - y index 2
  29625. */
  29626. NineSlicePlane.prototype.drawSegment = function drawSegment(context, textureSource, w, h, x1, y1, x2, y2) {
  29627. // otherwise you get weird results when using slices of that are 0 wide or high.
  29628. var uvs = this.uvs;
  29629. var vertices = this.vertices;
  29630. var sw = (uvs[x2] - uvs[x1]) * w;
  29631. var sh = (uvs[y2] - uvs[y1]) * h;
  29632. var dw = vertices[x2] - vertices[x1];
  29633. var dh = vertices[y2] - vertices[y1];
  29634. // make sure the source is at least 1 pixel wide and high, otherwise nothing will be drawn.
  29635. if (sw < 1) {
  29636. sw = 1;
  29637. }
  29638. if (sh < 1) {
  29639. sh = 1;
  29640. }
  29641. // make sure destination is at least 1 pixel wide and high, otherwise you get
  29642. // lines when rendering close to original size.
  29643. if (dw < 1) {
  29644. dw = 1;
  29645. }
  29646. if (dh < 1) {
  29647. dh = 1;
  29648. }
  29649. context.drawImage(textureSource, uvs[x1] * w, uvs[y1] * h, sw, sh, vertices[x1], vertices[y1], dw, dh);
  29650. };
  29651. /**
  29652. * The width of the NineSlicePlane, setting this will actually modify the vertices and UV's of this plane
  29653. *
  29654. * @member {number}
  29655. */
  29656. /**
  29657. * Refreshes NineSlicePlane coords. All of them.
  29658. */
  29659. NineSlicePlane.prototype._refresh = function _refresh() {
  29660. _Plane.prototype._refresh.call(this);
  29661. var uvs = this.uvs;
  29662. var texture = this._texture;
  29663. this._origWidth = texture.orig.width;
  29664. this._origHeight = texture.orig.height;
  29665. var _uvw = 1.0 / this._origWidth;
  29666. var _uvh = 1.0 / this._origHeight;
  29667. uvs[0] = uvs[8] = uvs[16] = uvs[24] = 0;
  29668. uvs[1] = uvs[3] = uvs[5] = uvs[7] = 0;
  29669. uvs[6] = uvs[14] = uvs[22] = uvs[30] = 1;
  29670. uvs[25] = uvs[27] = uvs[29] = uvs[31] = 1;
  29671. uvs[2] = uvs[10] = uvs[18] = uvs[26] = _uvw * this._leftWidth;
  29672. uvs[4] = uvs[12] = uvs[20] = uvs[28] = 1 - _uvw * this._rightWidth;
  29673. uvs[9] = uvs[11] = uvs[13] = uvs[15] = _uvh * this._topHeight;
  29674. uvs[17] = uvs[19] = uvs[21] = uvs[23] = 1 - _uvh * this._bottomHeight;
  29675. this.updateHorizontalVertices();
  29676. this.updateVerticalVertices();
  29677. this.dirty++;
  29678. this.multiplyUvs();
  29679. };
  29680. _createClass(NineSlicePlane, [{
  29681. key: 'width',
  29682. get: function get() {
  29683. return this._width;
  29684. },
  29685. set: function set(value) // eslint-disable-line require-jsdoc
  29686. {
  29687. this._width = value;
  29688. this._refresh();
  29689. }
  29690. /**
  29691. * The height of the NineSlicePlane, setting this will actually modify the vertices and UV's of this plane
  29692. *
  29693. * @member {number}
  29694. */
  29695. }, {
  29696. key: 'height',
  29697. get: function get() {
  29698. return this._height;
  29699. },
  29700. set: function set(value) // eslint-disable-line require-jsdoc
  29701. {
  29702. this._height = value;
  29703. this._refresh();
  29704. }
  29705. /**
  29706. * The width of the left column
  29707. *
  29708. * @member {number}
  29709. */
  29710. }, {
  29711. key: 'leftWidth',
  29712. get: function get() {
  29713. return this._leftWidth;
  29714. },
  29715. set: function set(value) // eslint-disable-line require-jsdoc
  29716. {
  29717. this._leftWidth = value;
  29718. this._refresh();
  29719. }
  29720. /**
  29721. * The width of the right column
  29722. *
  29723. * @member {number}
  29724. */
  29725. }, {
  29726. key: 'rightWidth',
  29727. get: function get() {
  29728. return this._rightWidth;
  29729. },
  29730. set: function set(value) // eslint-disable-line require-jsdoc
  29731. {
  29732. this._rightWidth = value;
  29733. this._refresh();
  29734. }
  29735. /**
  29736. * The height of the top row
  29737. *
  29738. * @member {number}
  29739. */
  29740. }, {
  29741. key: 'topHeight',
  29742. get: function get() {
  29743. return this._topHeight;
  29744. },
  29745. set: function set(value) // eslint-disable-line require-jsdoc
  29746. {
  29747. this._topHeight = value;
  29748. this._refresh();
  29749. }
  29750. /**
  29751. * The height of the bottom row
  29752. *
  29753. * @member {number}
  29754. */
  29755. }, {
  29756. key: 'bottomHeight',
  29757. get: function get() {
  29758. return this._bottomHeight;
  29759. },
  29760. set: function set(value) // eslint-disable-line require-jsdoc
  29761. {
  29762. this._bottomHeight = value;
  29763. this._refresh();
  29764. }
  29765. }]);
  29766. return NineSlicePlane;
  29767. }(_Plane3.default);
  29768. exports.default = NineSlicePlane;
  29769. }, { "./Plane": 168 }], 168: [function (require, module, exports) {
  29770. 'use strict';
  29771. exports.__esModule = true;
  29772. var _Mesh2 = require('./Mesh');
  29773. var _Mesh3 = _interopRequireDefault(_Mesh2);
  29774. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  29775. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  29776. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  29777. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  29778. /**
  29779. * The Plane allows you to draw a texture across several points and them manipulate these points
  29780. *
  29781. *```js
  29782. * for (let i = 0; i < 20; i++) {
  29783. * points.push(new PIXI.Point(i * 50, 0));
  29784. * };
  29785. * let Plane = new PIXI.Plane(PIXI.Texture.fromImage("snake.png"), points);
  29786. * ```
  29787. *
  29788. * @class
  29789. * @extends PIXI.mesh.Mesh
  29790. * @memberof PIXI.mesh
  29791. *
  29792. */
  29793. var Plane = function (_Mesh) {
  29794. _inherits(Plane, _Mesh);
  29795. /**
  29796. * @param {PIXI.Texture} texture - The texture to use on the Plane.
  29797. * @param {number} verticesX - The number of vertices in the x-axis
  29798. * @param {number} verticesY - The number of vertices in the y-axis
  29799. */
  29800. function Plane(texture, verticesX, verticesY) {
  29801. _classCallCheck(this, Plane);
  29802. /**
  29803. * Tracker for if the Plane is ready to be drawn. Needed because Mesh ctor can
  29804. * call _onTextureUpdated which could call refresh too early.
  29805. *
  29806. * @member {boolean}
  29807. * @private
  29808. */
  29809. var _this = _possibleConstructorReturn(this, _Mesh.call(this, texture));
  29810. _this._ready = true;
  29811. _this.verticesX = verticesX || 10;
  29812. _this.verticesY = verticesY || 10;
  29813. _this.drawMode = _Mesh3.default.DRAW_MODES.TRIANGLES;
  29814. _this.refresh();
  29815. return _this;
  29816. }
  29817. /**
  29818. * Refreshes plane coordinates
  29819. *
  29820. */
  29821. Plane.prototype._refresh = function _refresh() {
  29822. var texture = this._texture;
  29823. var total = this.verticesX * this.verticesY;
  29824. var verts = [];
  29825. var colors = [];
  29826. var uvs = [];
  29827. var indices = [];
  29828. var segmentsX = this.verticesX - 1;
  29829. var segmentsY = this.verticesY - 1;
  29830. var sizeX = texture.width / segmentsX;
  29831. var sizeY = texture.height / segmentsY;
  29832. for (var i = 0; i < total; i++) {
  29833. var x = i % this.verticesX;
  29834. var y = i / this.verticesX | 0;
  29835. verts.push(x * sizeX, y * sizeY);
  29836. uvs.push(x / segmentsX, y / segmentsY);
  29837. }
  29838. // cons
  29839. var totalSub = segmentsX * segmentsY;
  29840. for (var _i = 0; _i < totalSub; _i++) {
  29841. var xpos = _i % segmentsX;
  29842. var ypos = _i / segmentsX | 0;
  29843. var value = ypos * this.verticesX + xpos;
  29844. var value2 = ypos * this.verticesX + xpos + 1;
  29845. var value3 = (ypos + 1) * this.verticesX + xpos;
  29846. var value4 = (ypos + 1) * this.verticesX + xpos + 1;
  29847. indices.push(value, value2, value3);
  29848. indices.push(value2, value4, value3);
  29849. }
  29850. // console.log(indices)
  29851. this.vertices = new Float32Array(verts);
  29852. this.uvs = new Float32Array(uvs);
  29853. this.colors = new Float32Array(colors);
  29854. this.indices = new Uint16Array(indices);
  29855. this.dirty++;
  29856. this.indexDirty++;
  29857. this.multiplyUvs();
  29858. };
  29859. /**
  29860. * Clear texture UVs when new texture is set
  29861. *
  29862. * @private
  29863. */
  29864. Plane.prototype._onTextureUpdate = function _onTextureUpdate() {
  29865. _Mesh3.default.prototype._onTextureUpdate.call(this);
  29866. // wait for the Plane ctor to finish before calling refresh
  29867. if (this._ready) {
  29868. this.refresh();
  29869. }
  29870. };
  29871. return Plane;
  29872. }(_Mesh3.default);
  29873. exports.default = Plane;
  29874. }, { "./Mesh": 166 }], 169: [function (require, module, exports) {
  29875. 'use strict';
  29876. exports.__esModule = true;
  29877. var _Mesh2 = require('./Mesh');
  29878. var _Mesh3 = _interopRequireDefault(_Mesh2);
  29879. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  29880. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  29881. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  29882. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  29883. /**
  29884. * The rope allows you to draw a texture across several points and them manipulate these points
  29885. *
  29886. *```js
  29887. * for (let i = 0; i < 20; i++) {
  29888. * points.push(new PIXI.Point(i * 50, 0));
  29889. * };
  29890. * let rope = new PIXI.Rope(PIXI.Texture.fromImage("snake.png"), points);
  29891. * ```
  29892. *
  29893. * @class
  29894. * @extends PIXI.mesh.Mesh
  29895. * @memberof PIXI.mesh
  29896. *
  29897. */
  29898. var Rope = function (_Mesh) {
  29899. _inherits(Rope, _Mesh);
  29900. /**
  29901. * @param {PIXI.Texture} texture - The texture to use on the rope.
  29902. * @param {PIXI.Point[]} points - An array of {@link PIXI.Point} objects to construct this rope.
  29903. */
  29904. function Rope(texture, points) {
  29905. _classCallCheck(this, Rope);
  29906. /**
  29907. * An array of points that determine the rope
  29908. *
  29909. * @member {PIXI.Point[]}
  29910. */
  29911. var _this = _possibleConstructorReturn(this, _Mesh.call(this, texture));
  29912. _this.points = points;
  29913. /**
  29914. * An array of vertices used to construct this rope.
  29915. *
  29916. * @member {Float32Array}
  29917. */
  29918. _this.vertices = new Float32Array(points.length * 4);
  29919. /**
  29920. * The WebGL Uvs of the rope.
  29921. *
  29922. * @member {Float32Array}
  29923. */
  29924. _this.uvs = new Float32Array(points.length * 4);
  29925. /**
  29926. * An array containing the color components
  29927. *
  29928. * @member {Float32Array}
  29929. */
  29930. _this.colors = new Float32Array(points.length * 2);
  29931. /**
  29932. * An array containing the indices of the vertices
  29933. *
  29934. * @member {Uint16Array}
  29935. */
  29936. _this.indices = new Uint16Array(points.length * 2);
  29937. /**
  29938. * refreshes vertices on every updateTransform
  29939. * @member {boolean}
  29940. * @default true
  29941. */
  29942. _this.autoUpdate = true;
  29943. _this.refresh();
  29944. return _this;
  29945. }
  29946. /**
  29947. * Refreshes
  29948. *
  29949. */
  29950. Rope.prototype._refresh = function _refresh() {
  29951. var points = this.points;
  29952. // if too little points, or texture hasn't got UVs set yet just move on.
  29953. if (points.length < 1 || !this._texture._uvs) {
  29954. return;
  29955. }
  29956. // if the number of points has changed we will need to recreate the arraybuffers
  29957. if (this.vertices.length / 4 !== points.length) {
  29958. this.vertices = new Float32Array(points.length * 4);
  29959. this.uvs = new Float32Array(points.length * 4);
  29960. this.colors = new Float32Array(points.length * 2);
  29961. this.indices = new Uint16Array(points.length * 2);
  29962. }
  29963. var uvs = this.uvs;
  29964. var indices = this.indices;
  29965. var colors = this.colors;
  29966. uvs[0] = 0;
  29967. uvs[1] = 0;
  29968. uvs[2] = 0;
  29969. uvs[3] = 1;
  29970. colors[0] = 1;
  29971. colors[1] = 1;
  29972. indices[0] = 0;
  29973. indices[1] = 1;
  29974. var total = points.length;
  29975. for (var i = 1; i < total; i++) {
  29976. // time to do some smart drawing!
  29977. var index = i * 4;
  29978. var amount = i / (total - 1);
  29979. uvs[index] = amount;
  29980. uvs[index + 1] = 0;
  29981. uvs[index + 2] = amount;
  29982. uvs[index + 3] = 1;
  29983. index = i * 2;
  29984. colors[index] = 1;
  29985. colors[index + 1] = 1;
  29986. index = i * 2;
  29987. indices[index] = index;
  29988. indices[index + 1] = index + 1;
  29989. }
  29990. // ensure that the changes are uploaded
  29991. this.dirty++;
  29992. this.indexDirty++;
  29993. this.multiplyUvs();
  29994. this.refreshVertices();
  29995. };
  29996. /**
  29997. * refreshes vertices of Rope mesh
  29998. */
  29999. Rope.prototype.refreshVertices = function refreshVertices() {
  30000. var points = this.points;
  30001. if (points.length < 1) {
  30002. return;
  30003. }
  30004. var lastPoint = points[0];
  30005. var nextPoint = void 0;
  30006. var perpX = 0;
  30007. var perpY = 0;
  30008. // this.count -= 0.2;
  30009. var vertices = this.vertices;
  30010. var total = points.length;
  30011. for (var i = 0; i < total; i++) {
  30012. var point = points[i];
  30013. var index = i * 4;
  30014. if (i < points.length - 1) {
  30015. nextPoint = points[i + 1];
  30016. } else {
  30017. nextPoint = point;
  30018. }
  30019. perpY = -(nextPoint.x - lastPoint.x);
  30020. perpX = nextPoint.y - lastPoint.y;
  30021. var ratio = (1 - i / (total - 1)) * 10;
  30022. if (ratio > 1) {
  30023. ratio = 1;
  30024. }
  30025. var perpLength = Math.sqrt(perpX * perpX + perpY * perpY);
  30026. var num = this._texture.height / 2; // (20 + Math.abs(Math.sin((i + this.count) * 0.3) * 50) )* ratio;
  30027. perpX /= perpLength;
  30028. perpY /= perpLength;
  30029. perpX *= num;
  30030. perpY *= num;
  30031. vertices[index] = point.x + perpX;
  30032. vertices[index + 1] = point.y + perpY;
  30033. vertices[index + 2] = point.x - perpX;
  30034. vertices[index + 3] = point.y - perpY;
  30035. lastPoint = point;
  30036. }
  30037. };
  30038. /**
  30039. * Updates the object transform for rendering
  30040. *
  30041. * @private
  30042. */
  30043. Rope.prototype.updateTransform = function updateTransform() {
  30044. if (this.autoUpdate) {
  30045. this.refreshVertices();
  30046. }
  30047. this.containerUpdateTransform();
  30048. };
  30049. return Rope;
  30050. }(_Mesh3.default);
  30051. exports.default = Rope;
  30052. }, { "./Mesh": 166 }], 170: [function (require, module, exports) {
  30053. 'use strict';
  30054. exports.__esModule = true;
  30055. var _core = require('../../core');
  30056. var core = _interopRequireWildcard(_core);
  30057. var _Mesh = require('../Mesh');
  30058. var _Mesh2 = _interopRequireDefault(_Mesh);
  30059. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  30060. function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
  30061. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  30062. /**
  30063. * Renderer dedicated to meshes.
  30064. *
  30065. * @class
  30066. * @private
  30067. * @memberof PIXI
  30068. */
  30069. var MeshSpriteRenderer = function () {
  30070. /**
  30071. * @param {PIXI.CanvasRenderer} renderer - The renderer this downport works for
  30072. */
  30073. function MeshSpriteRenderer(renderer) {
  30074. _classCallCheck(this, MeshSpriteRenderer);
  30075. this.renderer = renderer;
  30076. }
  30077. /**
  30078. * Renders the Mesh
  30079. *
  30080. * @param {PIXI.mesh.Mesh} mesh - the Mesh to render
  30081. */
  30082. MeshSpriteRenderer.prototype.render = function render(mesh) {
  30083. var renderer = this.renderer;
  30084. var context = renderer.context;
  30085. var transform = mesh.worldTransform;
  30086. var res = renderer.resolution;
  30087. if (renderer.roundPixels) {
  30088. context.setTransform(transform.a * res, transform.b * res, transform.c * res, transform.d * res, transform.tx * res | 0, transform.ty * res | 0);
  30089. } else {
  30090. context.setTransform(transform.a * res, transform.b * res, transform.c * res, transform.d * res, transform.tx * res, transform.ty * res);
  30091. }
  30092. renderer.context.globalAlpha = mesh.worldAlpha;
  30093. renderer.setBlendMode(mesh.blendMode);
  30094. if (mesh.drawMode === _Mesh2.default.DRAW_MODES.TRIANGLE_MESH) {
  30095. this._renderTriangleMesh(mesh);
  30096. } else {
  30097. this._renderTriangles(mesh);
  30098. }
  30099. };
  30100. /**
  30101. * Draws the object in Triangle Mesh mode
  30102. *
  30103. * @private
  30104. * @param {PIXI.mesh.Mesh} mesh - the Mesh to render
  30105. */
  30106. MeshSpriteRenderer.prototype._renderTriangleMesh = function _renderTriangleMesh(mesh) {
  30107. // draw triangles!!
  30108. var length = mesh.vertices.length / 2;
  30109. for (var i = 0; i < length - 2; i++) {
  30110. // draw some triangles!
  30111. var index = i * 2;
  30112. this._renderDrawTriangle(mesh, index, index + 2, index + 4);
  30113. }
  30114. };
  30115. /**
  30116. * Draws the object in triangle mode using canvas
  30117. *
  30118. * @private
  30119. * @param {PIXI.mesh.Mesh} mesh - the current mesh
  30120. */
  30121. MeshSpriteRenderer.prototype._renderTriangles = function _renderTriangles(mesh) {
  30122. // draw triangles!!
  30123. var indices = mesh.indices;
  30124. var length = indices.length;
  30125. for (var i = 0; i < length; i += 3) {
  30126. // draw some triangles!
  30127. var index0 = indices[i] * 2;
  30128. var index1 = indices[i + 1] * 2;
  30129. var index2 = indices[i + 2] * 2;
  30130. this._renderDrawTriangle(mesh, index0, index1, index2);
  30131. }
  30132. };
  30133. /**
  30134. * Draws one of the triangles that from the Mesh
  30135. *
  30136. * @private
  30137. * @param {PIXI.mesh.Mesh} mesh - the current mesh
  30138. * @param {number} index0 - the index of the first vertex
  30139. * @param {number} index1 - the index of the second vertex
  30140. * @param {number} index2 - the index of the third vertex
  30141. */
  30142. MeshSpriteRenderer.prototype._renderDrawTriangle = function _renderDrawTriangle(mesh, index0, index1, index2) {
  30143. var context = this.renderer.context;
  30144. var uvs = mesh.uvs;
  30145. var vertices = mesh.vertices;
  30146. var texture = mesh._texture;
  30147. if (!texture.valid) {
  30148. return;
  30149. }
  30150. var base = texture.baseTexture;
  30151. var textureSource = base.source;
  30152. var textureWidth = base.width;
  30153. var textureHeight = base.height;
  30154. var u0 = void 0;
  30155. var u1 = void 0;
  30156. var u2 = void 0;
  30157. var v0 = void 0;
  30158. var v1 = void 0;
  30159. var v2 = void 0;
  30160. if (mesh.uploadUvTransform) {
  30161. var ut = mesh._uvTransform.mapCoord;
  30162. u0 = (uvs[index0] * ut.a + uvs[index0 + 1] * ut.c + ut.tx) * base.width;
  30163. u1 = (uvs[index1] * ut.a + uvs[index1 + 1] * ut.c + ut.tx) * base.width;
  30164. u2 = (uvs[index2] * ut.a + uvs[index2 + 1] * ut.c + ut.tx) * base.width;
  30165. v0 = (uvs[index0] * ut.b + uvs[index0 + 1] * ut.d + ut.ty) * base.height;
  30166. v1 = (uvs[index1] * ut.b + uvs[index1 + 1] * ut.d + ut.ty) * base.height;
  30167. v2 = (uvs[index2] * ut.b + uvs[index2 + 1] * ut.d + ut.ty) * base.height;
  30168. } else {
  30169. u0 = uvs[index0] * base.width;
  30170. u1 = uvs[index1] * base.width;
  30171. u2 = uvs[index2] * base.width;
  30172. v0 = uvs[index0 + 1] * base.height;
  30173. v1 = uvs[index1 + 1] * base.height;
  30174. v2 = uvs[index2 + 1] * base.height;
  30175. }
  30176. var x0 = vertices[index0];
  30177. var x1 = vertices[index1];
  30178. var x2 = vertices[index2];
  30179. var y0 = vertices[index0 + 1];
  30180. var y1 = vertices[index1 + 1];
  30181. var y2 = vertices[index2 + 1];
  30182. var canvasPadding = mesh.canvasPadding / this.renderer.resolution;
  30183. if (canvasPadding > 0) {
  30184. var paddingX = canvasPadding / Math.abs(mesh.worldTransform.a);
  30185. var paddingY = canvasPadding / Math.abs(mesh.worldTransform.d);
  30186. var centerX = (x0 + x1 + x2) / 3;
  30187. var centerY = (y0 + y1 + y2) / 3;
  30188. var normX = x0 - centerX;
  30189. var normY = y0 - centerY;
  30190. var dist = Math.sqrt(normX * normX + normY * normY);
  30191. x0 = centerX + normX / dist * (dist + paddingX);
  30192. y0 = centerY + normY / dist * (dist + paddingY);
  30193. //
  30194. normX = x1 - centerX;
  30195. normY = y1 - centerY;
  30196. dist = Math.sqrt(normX * normX + normY * normY);
  30197. x1 = centerX + normX / dist * (dist + paddingX);
  30198. y1 = centerY + normY / dist * (dist + paddingY);
  30199. normX = x2 - centerX;
  30200. normY = y2 - centerY;
  30201. dist = Math.sqrt(normX * normX + normY * normY);
  30202. x2 = centerX + normX / dist * (dist + paddingX);
  30203. y2 = centerY + normY / dist * (dist + paddingY);
  30204. }
  30205. context.save();
  30206. context.beginPath();
  30207. context.moveTo(x0, y0);
  30208. context.lineTo(x1, y1);
  30209. context.lineTo(x2, y2);
  30210. context.closePath();
  30211. context.clip();
  30212. // Compute matrix transform
  30213. var delta = u0 * v1 + v0 * u2 + u1 * v2 - v1 * u2 - v0 * u1 - u0 * v2;
  30214. var deltaA = x0 * v1 + v0 * x2 + x1 * v2 - v1 * x2 - v0 * x1 - x0 * v2;
  30215. var deltaB = u0 * x1 + x0 * u2 + u1 * x2 - x1 * u2 - x0 * u1 - u0 * x2;
  30216. var deltaC = u0 * v1 * x2 + v0 * x1 * u2 + x0 * u1 * v2 - x0 * v1 * u2 - v0 * u1 * x2 - u0 * x1 * v2;
  30217. var deltaD = y0 * v1 + v0 * y2 + y1 * v2 - v1 * y2 - v0 * y1 - y0 * v2;
  30218. var deltaE = u0 * y1 + y0 * u2 + u1 * y2 - y1 * u2 - y0 * u1 - u0 * y2;
  30219. var deltaF = u0 * v1 * y2 + v0 * y1 * u2 + y0 * u1 * v2 - y0 * v1 * u2 - v0 * u1 * y2 - u0 * y1 * v2;
  30220. context.transform(deltaA / delta, deltaD / delta, deltaB / delta, deltaE / delta, deltaC / delta, deltaF / delta);
  30221. context.drawImage(textureSource, 0, 0, textureWidth * base.resolution, textureHeight * base.resolution, 0, 0, textureWidth, textureHeight);
  30222. context.restore();
  30223. this.renderer.invalidateBlendMode();
  30224. };
  30225. /**
  30226. * Renders a flat Mesh
  30227. *
  30228. * @private
  30229. * @param {PIXI.mesh.Mesh} mesh - The Mesh to render
  30230. */
  30231. MeshSpriteRenderer.prototype.renderMeshFlat = function renderMeshFlat(mesh) {
  30232. var context = this.renderer.context;
  30233. var vertices = mesh.vertices;
  30234. var length = vertices.length / 2;
  30235. // this.count++;
  30236. context.beginPath();
  30237. for (var i = 1; i < length - 2; ++i) {
  30238. // draw some triangles!
  30239. var index = i * 2;
  30240. var x0 = vertices[index];
  30241. var y0 = vertices[index + 1];
  30242. var x1 = vertices[index + 2];
  30243. var y1 = vertices[index + 3];
  30244. var x2 = vertices[index + 4];
  30245. var y2 = vertices[index + 5];
  30246. context.moveTo(x0, y0);
  30247. context.lineTo(x1, y1);
  30248. context.lineTo(x2, y2);
  30249. }
  30250. context.fillStyle = '#FF0000';
  30251. context.fill();
  30252. context.closePath();
  30253. };
  30254. /**
  30255. * destroy the the renderer.
  30256. *
  30257. */
  30258. MeshSpriteRenderer.prototype.destroy = function destroy() {
  30259. this.renderer = null;
  30260. };
  30261. return MeshSpriteRenderer;
  30262. }();
  30263. exports.default = MeshSpriteRenderer;
  30264. core.CanvasRenderer.registerPlugin('mesh', MeshSpriteRenderer);
  30265. }, { "../../core": 65, "../Mesh": 166 }], 171: [function (require, module, exports) {
  30266. 'use strict';
  30267. exports.__esModule = true;
  30268. var _Mesh = require('./Mesh');
  30269. Object.defineProperty(exports, 'Mesh', {
  30270. enumerable: true,
  30271. get: function get() {
  30272. return _interopRequireDefault(_Mesh).default;
  30273. }
  30274. });
  30275. var _MeshRenderer = require('./webgl/MeshRenderer');
  30276. Object.defineProperty(exports, 'MeshRenderer', {
  30277. enumerable: true,
  30278. get: function get() {
  30279. return _interopRequireDefault(_MeshRenderer).default;
  30280. }
  30281. });
  30282. var _CanvasMeshRenderer = require('./canvas/CanvasMeshRenderer');
  30283. Object.defineProperty(exports, 'CanvasMeshRenderer', {
  30284. enumerable: true,
  30285. get: function get() {
  30286. return _interopRequireDefault(_CanvasMeshRenderer).default;
  30287. }
  30288. });
  30289. var _Plane = require('./Plane');
  30290. Object.defineProperty(exports, 'Plane', {
  30291. enumerable: true,
  30292. get: function get() {
  30293. return _interopRequireDefault(_Plane).default;
  30294. }
  30295. });
  30296. var _NineSlicePlane = require('./NineSlicePlane');
  30297. Object.defineProperty(exports, 'NineSlicePlane', {
  30298. enumerable: true,
  30299. get: function get() {
  30300. return _interopRequireDefault(_NineSlicePlane).default;
  30301. }
  30302. });
  30303. var _Rope = require('./Rope');
  30304. Object.defineProperty(exports, 'Rope', {
  30305. enumerable: true,
  30306. get: function get() {
  30307. return _interopRequireDefault(_Rope).default;
  30308. }
  30309. });
  30310. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  30311. }, { "./Mesh": 166, "./NineSlicePlane": 167, "./Plane": 168, "./Rope": 169, "./canvas/CanvasMeshRenderer": 170, "./webgl/MeshRenderer": 172 }], 172: [function (require, module, exports) {
  30312. 'use strict';
  30313. exports.__esModule = true;
  30314. var _core = require('../../core');
  30315. var core = _interopRequireWildcard(_core);
  30316. var _pixiGlCore = require('pixi-gl-core');
  30317. var _pixiGlCore2 = _interopRequireDefault(_pixiGlCore);
  30318. var _Mesh = require('../Mesh');
  30319. var _Mesh2 = _interopRequireDefault(_Mesh);
  30320. var _path = require('path');
  30321. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  30322. function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
  30323. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  30324. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  30325. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  30326. var matrixIdentity = core.Matrix.IDENTITY;
  30327. /**
  30328. * WebGL renderer plugin for tiling sprites
  30329. *
  30330. * @class
  30331. * @memberof PIXI
  30332. * @extends PIXI.ObjectRenderer
  30333. */
  30334. var MeshRenderer = function (_core$ObjectRenderer) {
  30335. _inherits(MeshRenderer, _core$ObjectRenderer);
  30336. /**
  30337. * constructor for renderer
  30338. *
  30339. * @param {WebGLRenderer} renderer The renderer this tiling awesomeness works for.
  30340. */
  30341. function MeshRenderer(renderer) {
  30342. _classCallCheck(this, MeshRenderer);
  30343. var _this = _possibleConstructorReturn(this, _core$ObjectRenderer.call(this, renderer));
  30344. _this.shader = null;
  30345. return _this;
  30346. }
  30347. /**
  30348. * Sets up the renderer context and necessary buffers.
  30349. *
  30350. * @private
  30351. */
  30352. MeshRenderer.prototype.onContextChange = function onContextChange() {
  30353. var gl = this.renderer.gl;
  30354. this.shader = new core.Shader(gl, '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', 'varying vec2 vTextureCoord;\nuniform vec4 uColor;\n\nuniform sampler2D uSampler;\n\nvoid main(void)\n{\n gl_FragColor = texture2D(uSampler, vTextureCoord) * uColor;\n}\n');
  30355. };
  30356. /**
  30357. * renders mesh
  30358. *
  30359. * @param {PIXI.mesh.Mesh} mesh mesh instance
  30360. */
  30361. MeshRenderer.prototype.render = function render(mesh) {
  30362. var renderer = this.renderer;
  30363. var gl = renderer.gl;
  30364. var texture = mesh._texture;
  30365. if (!texture.valid) {
  30366. return;
  30367. }
  30368. var glData = mesh._glDatas[renderer.CONTEXT_UID];
  30369. if (!glData) {
  30370. renderer.bindVao(null);
  30371. glData = {
  30372. shader: this.shader,
  30373. vertexBuffer: _pixiGlCore2.default.GLBuffer.createVertexBuffer(gl, mesh.vertices, gl.STREAM_DRAW),
  30374. uvBuffer: _pixiGlCore2.default.GLBuffer.createVertexBuffer(gl, mesh.uvs, gl.STREAM_DRAW),
  30375. indexBuffer: _pixiGlCore2.default.GLBuffer.createIndexBuffer(gl, mesh.indices, gl.STATIC_DRAW),
  30376. // build the vao object that will render..
  30377. vao: null,
  30378. dirty: mesh.dirty,
  30379. indexDirty: mesh.indexDirty
  30380. };
  30381. // build the vao object that will render..
  30382. glData.vao = new _pixiGlCore2.default.VertexArrayObject(gl).addIndex(glData.indexBuffer).addAttribute(glData.vertexBuffer, glData.shader.attributes.aVertexPosition, gl.FLOAT, false, 2 * 4, 0).addAttribute(glData.uvBuffer, glData.shader.attributes.aTextureCoord, gl.FLOAT, false, 2 * 4, 0);
  30383. mesh._glDatas[renderer.CONTEXT_UID] = glData;
  30384. }
  30385. renderer.bindVao(glData.vao);
  30386. if (mesh.dirty !== glData.dirty) {
  30387. glData.dirty = mesh.dirty;
  30388. glData.uvBuffer.upload(mesh.uvs);
  30389. }
  30390. if (mesh.indexDirty !== glData.indexDirty) {
  30391. glData.indexDirty = mesh.indexDirty;
  30392. glData.indexBuffer.upload(mesh.indices);
  30393. }
  30394. glData.vertexBuffer.upload(mesh.vertices);
  30395. renderer.bindShader(glData.shader);
  30396. glData.shader.uniforms.uSampler = renderer.bindTexture(texture);
  30397. renderer.state.setBlendMode(core.utils.correctBlendMode(mesh.blendMode, texture.baseTexture.premultipliedAlpha));
  30398. if (glData.shader.uniforms.uTransform) {
  30399. if (mesh.uploadUvTransform) {
  30400. glData.shader.uniforms.uTransform = mesh._uvTransform.mapCoord.toArray(true);
  30401. } else {
  30402. glData.shader.uniforms.uTransform = matrixIdentity.toArray(true);
  30403. }
  30404. }
  30405. glData.shader.uniforms.translationMatrix = mesh.worldTransform.toArray(true);
  30406. glData.shader.uniforms.uColor = core.utils.premultiplyRgba(mesh.tintRgb, mesh.worldAlpha, glData.shader.uniforms.uColor, texture.baseTexture.premultipliedAlpha);
  30407. var drawMode = mesh.drawMode === _Mesh2.default.DRAW_MODES.TRIANGLE_MESH ? gl.TRIANGLE_STRIP : gl.TRIANGLES;
  30408. glData.vao.draw(drawMode, mesh.indices.length, 0);
  30409. };
  30410. return MeshRenderer;
  30411. }(core.ObjectRenderer);
  30412. exports.default = MeshRenderer;
  30413. core.WebGLRenderer.registerPlugin('mesh', MeshRenderer);
  30414. }, { "../../core": 65, "../Mesh": 166, "path": 8, "pixi-gl-core": 15 }], 173: [function (require, module, exports) {
  30415. 'use strict';
  30416. exports.__esModule = true;
  30417. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  30418. var _core = require('../core');
  30419. var core = _interopRequireWildcard(_core);
  30420. var _utils = require('../core/utils');
  30421. function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
  30422. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  30423. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  30424. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  30425. /**
  30426. * The ParticleContainer class is a really fast version of the Container built solely for speed,
  30427. * so use when you need a lot of sprites or particles. The tradeoff of the ParticleContainer is that most advanced
  30428. * functionality will not work. ParticleContainer implements the basic object transform (position, scale, rotation)
  30429. * and some advanced functionality like tint (as of v4.5.6).
  30430. * Other more advanced functionality like masking, children, filters, etc will not work on sprites in this batch.
  30431. *
  30432. * It's extremely easy to use :
  30433. *
  30434. * ```js
  30435. * let container = new ParticleContainer();
  30436. *
  30437. * for (let i = 0; i < 100; ++i)
  30438. * {
  30439. * let sprite = new PIXI.Sprite.fromImage("myImage.png");
  30440. * container.addChild(sprite);
  30441. * }
  30442. * ```
  30443. *
  30444. * And here you have a hundred sprites that will be rendered at the speed of light.
  30445. *
  30446. * @class
  30447. * @extends PIXI.Container
  30448. * @memberof PIXI.particles
  30449. */
  30450. var ParticleContainer = function (_core$Container) {
  30451. _inherits(ParticleContainer, _core$Container);
  30452. /**
  30453. * @param {number} [maxSize=1500] - The maximum number of particles that can be rendered by the container.
  30454. * Affects size of allocated buffers.
  30455. * @param {object} [properties] - The properties of children that should be uploaded to the gpu and applied.
  30456. * @param {boolean} [properties.vertices=false] - When true, vertices be uploaded and applied.
  30457. * if sprite's ` scale/anchor/trim/frame/orig` is dynamic, please set `true`.
  30458. * @param {boolean} [properties.position=true] - When true, position be uploaded and applied.
  30459. * @param {boolean} [properties.rotation=false] - When true, rotation be uploaded and applied.
  30460. * @param {boolean} [properties.uvs=false] - When true, uvs be uploaded and applied.
  30461. * @param {boolean} [properties.tint=false] - When true, alpha and tint be uploaded and applied.
  30462. * @param {number} [batchSize=16384] - Number of particles per batch. If less than maxSize, it uses maxSize instead.
  30463. * @param {boolean} [autoResize=false] If true, container allocates more batches in case
  30464. * there are more than `maxSize` particles.
  30465. */
  30466. function ParticleContainer() {
  30467. var maxSize = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1500;
  30468. var properties = arguments[1];
  30469. var batchSize = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 16384;
  30470. var autoResize = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
  30471. _classCallCheck(this, ParticleContainer);
  30472. // Making sure the batch size is valid
  30473. // 65535 is max vertex index in the index buffer (see ParticleRenderer)
  30474. // so max number of particles is 65536 / 4 = 16384
  30475. var _this = _possibleConstructorReturn(this, _core$Container.call(this));
  30476. var maxBatchSize = 16384;
  30477. if (batchSize > maxBatchSize) {
  30478. batchSize = maxBatchSize;
  30479. }
  30480. if (batchSize > maxSize) {
  30481. batchSize = maxSize;
  30482. }
  30483. /**
  30484. * Set properties to be dynamic (true) / static (false)
  30485. *
  30486. * @member {boolean[]}
  30487. * @private
  30488. */
  30489. _this._properties = [false, true, false, false, false];
  30490. /**
  30491. * @member {number}
  30492. * @private
  30493. */
  30494. _this._maxSize = maxSize;
  30495. /**
  30496. * @member {number}
  30497. * @private
  30498. */
  30499. _this._batchSize = batchSize;
  30500. /**
  30501. * @member {object<number, WebGLBuffer>}
  30502. * @private
  30503. */
  30504. _this._glBuffers = {};
  30505. /**
  30506. * for every batch stores _updateID corresponding to the last change in that batch
  30507. * @member {number[]}
  30508. * @private
  30509. */
  30510. _this._bufferUpdateIDs = [];
  30511. /**
  30512. * when child inserted, removed or changes position this number goes up
  30513. * @member {number[]}
  30514. * @private
  30515. */
  30516. _this._updateID = 0;
  30517. /**
  30518. * @member {boolean}
  30519. *
  30520. */
  30521. _this.interactiveChildren = false;
  30522. /**
  30523. * The blend mode to be applied to the sprite. Apply a value of `PIXI.BLEND_MODES.NORMAL`
  30524. * to reset the blend mode.
  30525. *
  30526. * @member {number}
  30527. * @default PIXI.BLEND_MODES.NORMAL
  30528. * @see PIXI.BLEND_MODES
  30529. */
  30530. _this.blendMode = core.BLEND_MODES.NORMAL;
  30531. /**
  30532. * If true, container allocates more batches in case there are more than `maxSize` particles.
  30533. * @member {boolean}
  30534. * @default false
  30535. */
  30536. _this.autoResize = autoResize;
  30537. /**
  30538. * Used for canvas renderering. If true then the elements will be positioned at the
  30539. * nearest pixel. This provides a nice speed boost.
  30540. *
  30541. * @member {boolean}
  30542. * @default true;
  30543. */
  30544. _this.roundPixels = true;
  30545. /**
  30546. * The texture used to render the children.
  30547. *
  30548. * @readonly
  30549. * @member {BaseTexture}
  30550. */
  30551. _this.baseTexture = null;
  30552. _this.setProperties(properties);
  30553. /**
  30554. * The tint applied to the container.
  30555. * This is a hex value. A value of 0xFFFFFF will remove any tint effect.
  30556. *
  30557. * @private
  30558. * @member {number}
  30559. * @default 0xFFFFFF
  30560. */
  30561. _this._tint = 0;
  30562. _this.tintRgb = new Float32Array(4);
  30563. _this.tint = 0xFFFFFF;
  30564. return _this;
  30565. }
  30566. /**
  30567. * Sets the private properties array to dynamic / static based on the passed properties object
  30568. *
  30569. * @param {object} properties - The properties to be uploaded
  30570. */
  30571. ParticleContainer.prototype.setProperties = function setProperties(properties) {
  30572. if (properties) {
  30573. this._properties[0] = 'vertices' in properties || 'scale' in properties ? !!properties.vertices || !!properties.scale : this._properties[0];
  30574. this._properties[1] = 'position' in properties ? !!properties.position : this._properties[1];
  30575. this._properties[2] = 'rotation' in properties ? !!properties.rotation : this._properties[2];
  30576. this._properties[3] = 'uvs' in properties ? !!properties.uvs : this._properties[3];
  30577. this._properties[4] = 'tint' in properties || 'alpha' in properties ? !!properties.tint || !!properties.alpha : this._properties[4];
  30578. }
  30579. };
  30580. /**
  30581. * Updates the object transform for rendering
  30582. *
  30583. * @private
  30584. */
  30585. ParticleContainer.prototype.updateTransform = function updateTransform() {
  30586. // TODO don't need to!
  30587. this.displayObjectUpdateTransform();
  30588. // PIXI.Container.prototype.updateTransform.call( this );
  30589. };
  30590. /**
  30591. * The tint applied to the container. This is a hex value.
  30592. * A value of 0xFFFFFF will remove any tint effect.
  30593. ** IMPORTANT: This is a webGL only feature and will be ignored by the canvas renderer.
  30594. * @member {number}
  30595. * @default 0xFFFFFF
  30596. */
  30597. /**
  30598. * Renders the container using the WebGL renderer
  30599. *
  30600. * @private
  30601. * @param {PIXI.WebGLRenderer} renderer - The webgl renderer
  30602. */
  30603. ParticleContainer.prototype.renderWebGL = function renderWebGL(renderer) {
  30604. var _this2 = this;
  30605. if (!this.visible || this.worldAlpha <= 0 || !this.children.length || !this.renderable) {
  30606. return;
  30607. }
  30608. if (!this.baseTexture) {
  30609. this.baseTexture = this.children[0]._texture.baseTexture;
  30610. if (!this.baseTexture.hasLoaded) {
  30611. this.baseTexture.once('update', function () {
  30612. return _this2.onChildrenChange(0);
  30613. });
  30614. }
  30615. }
  30616. renderer.setObjectRenderer(renderer.plugins.particle);
  30617. renderer.plugins.particle.render(this);
  30618. };
  30619. /**
  30620. * Set the flag that static data should be updated to true
  30621. *
  30622. * @private
  30623. * @param {number} smallestChildIndex - The smallest child index
  30624. */
  30625. ParticleContainer.prototype.onChildrenChange = function onChildrenChange(smallestChildIndex) {
  30626. var bufferIndex = Math.floor(smallestChildIndex / this._batchSize);
  30627. while (this._bufferUpdateIDs.length < bufferIndex) {
  30628. this._bufferUpdateIDs.push(0);
  30629. }
  30630. this._bufferUpdateIDs[bufferIndex] = ++this._updateID;
  30631. };
  30632. /**
  30633. * Renders the object using the Canvas renderer
  30634. *
  30635. * @private
  30636. * @param {PIXI.CanvasRenderer} renderer - The canvas renderer
  30637. */
  30638. ParticleContainer.prototype.renderCanvas = function renderCanvas(renderer) {
  30639. if (!this.visible || this.worldAlpha <= 0 || !this.children.length || !this.renderable) {
  30640. return;
  30641. }
  30642. var context = renderer.context;
  30643. var transform = this.worldTransform;
  30644. var isRotated = true;
  30645. var positionX = 0;
  30646. var positionY = 0;
  30647. var finalWidth = 0;
  30648. var finalHeight = 0;
  30649. renderer.setBlendMode(this.blendMode);
  30650. context.globalAlpha = this.worldAlpha;
  30651. this.displayObjectUpdateTransform();
  30652. for (var i = 0; i < this.children.length; ++i) {
  30653. var child = this.children[i];
  30654. if (!child.visible) {
  30655. continue;
  30656. }
  30657. var frame = child._texture.frame;
  30658. context.globalAlpha = this.worldAlpha * child.alpha;
  30659. if (child.rotation % (Math.PI * 2) === 0) {
  30660. // this is the fastest way to optimise! - if rotation is 0 then we can avoid any kind of setTransform call
  30661. if (isRotated) {
  30662. context.setTransform(transform.a, transform.b, transform.c, transform.d, transform.tx * renderer.resolution, transform.ty * renderer.resolution);
  30663. isRotated = false;
  30664. }
  30665. positionX = child.anchor.x * (-frame.width * child.scale.x) + child.position.x + 0.5;
  30666. positionY = child.anchor.y * (-frame.height * child.scale.y) + child.position.y + 0.5;
  30667. finalWidth = frame.width * child.scale.x;
  30668. finalHeight = frame.height * child.scale.y;
  30669. } else {
  30670. if (!isRotated) {
  30671. isRotated = true;
  30672. }
  30673. child.displayObjectUpdateTransform();
  30674. var childTransform = child.worldTransform;
  30675. if (renderer.roundPixels) {
  30676. context.setTransform(childTransform.a, childTransform.b, childTransform.c, childTransform.d, childTransform.tx * renderer.resolution | 0, childTransform.ty * renderer.resolution | 0);
  30677. } else {
  30678. context.setTransform(childTransform.a, childTransform.b, childTransform.c, childTransform.d, childTransform.tx * renderer.resolution, childTransform.ty * renderer.resolution);
  30679. }
  30680. positionX = child.anchor.x * -frame.width + 0.5;
  30681. positionY = child.anchor.y * -frame.height + 0.5;
  30682. finalWidth = frame.width;
  30683. finalHeight = frame.height;
  30684. }
  30685. var resolution = child._texture.baseTexture.resolution;
  30686. context.drawImage(child._texture.baseTexture.source, frame.x * resolution, frame.y * resolution, frame.width * resolution, frame.height * resolution, positionX * renderer.resolution, positionY * renderer.resolution, finalWidth * renderer.resolution, finalHeight * renderer.resolution);
  30687. }
  30688. };
  30689. /**
  30690. * Destroys the container
  30691. *
  30692. * @param {object|boolean} [options] - Options parameter. A boolean will act as if all options
  30693. * have been set to that value
  30694. * @param {boolean} [options.children=false] - if set to true, all the children will have their
  30695. * destroy method called as well. 'options' will be passed on to those calls.
  30696. * @param {boolean} [options.texture=false] - Only used for child Sprites if options.children is set to true
  30697. * Should it destroy the texture of the child sprite
  30698. * @param {boolean} [options.baseTexture=false] - Only used for child Sprites if options.children is set to true
  30699. * Should it destroy the base texture of the child sprite
  30700. */
  30701. ParticleContainer.prototype.destroy = function destroy(options) {
  30702. _core$Container.prototype.destroy.call(this, options);
  30703. if (this._buffers) {
  30704. for (var i = 0; i < this._buffers.length; ++i) {
  30705. this._buffers[i].destroy();
  30706. }
  30707. }
  30708. this._properties = null;
  30709. this._buffers = null;
  30710. this._bufferUpdateIDs = null;
  30711. };
  30712. _createClass(ParticleContainer, [{
  30713. key: 'tint',
  30714. get: function get() {
  30715. return this._tint;
  30716. },
  30717. set: function set(value) // eslint-disable-line require-jsdoc
  30718. {
  30719. this._tint = value;
  30720. (0, _utils.hex2rgb)(value, this.tintRgb);
  30721. }
  30722. }]);
  30723. return ParticleContainer;
  30724. }(core.Container);
  30725. exports.default = ParticleContainer;
  30726. }, { "../core": 65, "../core/utils": 125 }], 174: [function (require, module, exports) {
  30727. 'use strict';
  30728. exports.__esModule = true;
  30729. var _ParticleContainer = require('./ParticleContainer');
  30730. Object.defineProperty(exports, 'ParticleContainer', {
  30731. enumerable: true,
  30732. get: function get() {
  30733. return _interopRequireDefault(_ParticleContainer).default;
  30734. }
  30735. });
  30736. var _ParticleRenderer = require('./webgl/ParticleRenderer');
  30737. Object.defineProperty(exports, 'ParticleRenderer', {
  30738. enumerable: true,
  30739. get: function get() {
  30740. return _interopRequireDefault(_ParticleRenderer).default;
  30741. }
  30742. });
  30743. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  30744. }, { "./ParticleContainer": 173, "./webgl/ParticleRenderer": 176 }], 175: [function (require, module, exports) {
  30745. 'use strict';
  30746. exports.__esModule = true;
  30747. var _pixiGlCore = require('pixi-gl-core');
  30748. var _pixiGlCore2 = _interopRequireDefault(_pixiGlCore);
  30749. var _createIndicesForQuads = require('../../core/utils/createIndicesForQuads');
  30750. var _createIndicesForQuads2 = _interopRequireDefault(_createIndicesForQuads);
  30751. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  30752. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  30753. /**
  30754. * @author Mat Groves
  30755. *
  30756. * Big thanks to the very clever Matt DesLauriers <mattdesl> https://github.com/mattdesl/
  30757. * for creating the original PixiJS version!
  30758. * Also a thanks to https://github.com/bchevalier for tweaking the tint and alpha so that
  30759. * they now share 4 bytes on the vertex buffer
  30760. *
  30761. * Heavily inspired by LibGDX's ParticleBuffer:
  30762. * https://github.com/libgdx/libgdx/blob/master/gdx/src/com/badlogic/gdx/graphics/g2d/ParticleBuffer.java
  30763. */
  30764. /**
  30765. * The particle buffer manages the static and dynamic buffers for a particle container.
  30766. *
  30767. * @class
  30768. * @private
  30769. * @memberof PIXI
  30770. */
  30771. var ParticleBuffer = function () {
  30772. /**
  30773. * @param {WebGLRenderingContext} gl - The rendering context.
  30774. * @param {object} properties - The properties to upload.
  30775. * @param {boolean[]} dynamicPropertyFlags - Flags for which properties are dynamic.
  30776. * @param {number} size - The size of the batch.
  30777. */
  30778. function ParticleBuffer(gl, properties, dynamicPropertyFlags, size) {
  30779. _classCallCheck(this, ParticleBuffer);
  30780. /**
  30781. * The current WebGL drawing context.
  30782. *
  30783. * @member {WebGLRenderingContext}
  30784. */
  30785. this.gl = gl;
  30786. /**
  30787. * The number of particles the buffer can hold
  30788. *
  30789. * @member {number}
  30790. */
  30791. this.size = size;
  30792. /**
  30793. * A list of the properties that are dynamic.
  30794. *
  30795. * @member {object[]}
  30796. */
  30797. this.dynamicProperties = [];
  30798. /**
  30799. * A list of the properties that are static.
  30800. *
  30801. * @member {object[]}
  30802. */
  30803. this.staticProperties = [];
  30804. for (var i = 0; i < properties.length; ++i) {
  30805. var property = properties[i];
  30806. // Make copy of properties object so that when we edit the offset it doesn't
  30807. // change all other instances of the object literal
  30808. property = {
  30809. attribute: property.attribute,
  30810. size: property.size,
  30811. uploadFunction: property.uploadFunction,
  30812. unsignedByte: property.unsignedByte,
  30813. offset: property.offset
  30814. };
  30815. if (dynamicPropertyFlags[i]) {
  30816. this.dynamicProperties.push(property);
  30817. } else {
  30818. this.staticProperties.push(property);
  30819. }
  30820. }
  30821. this.staticStride = 0;
  30822. this.staticBuffer = null;
  30823. this.staticData = null;
  30824. this.staticDataUint32 = null;
  30825. this.dynamicStride = 0;
  30826. this.dynamicBuffer = null;
  30827. this.dynamicData = null;
  30828. this.dynamicDataUint32 = null;
  30829. this._updateID = 0;
  30830. this.initBuffers();
  30831. }
  30832. /**
  30833. * Sets up the renderer context and necessary buffers.
  30834. *
  30835. * @private
  30836. */
  30837. ParticleBuffer.prototype.initBuffers = function initBuffers() {
  30838. var gl = this.gl;
  30839. var dynamicOffset = 0;
  30840. /**
  30841. * Holds the indices of the geometry (quads) to draw
  30842. *
  30843. * @member {Uint16Array}
  30844. */
  30845. this.indices = (0, _createIndicesForQuads2.default)(this.size);
  30846. this.indexBuffer = _pixiGlCore2.default.GLBuffer.createIndexBuffer(gl, this.indices, gl.STATIC_DRAW);
  30847. this.dynamicStride = 0;
  30848. for (var i = 0; i < this.dynamicProperties.length; ++i) {
  30849. var property = this.dynamicProperties[i];
  30850. property.offset = dynamicOffset;
  30851. dynamicOffset += property.size;
  30852. this.dynamicStride += property.size;
  30853. }
  30854. var dynBuffer = new ArrayBuffer(this.size * this.dynamicStride * 4 * 4);
  30855. this.dynamicData = new Float32Array(dynBuffer);
  30856. this.dynamicDataUint32 = new Uint32Array(dynBuffer);
  30857. this.dynamicBuffer = _pixiGlCore2.default.GLBuffer.createVertexBuffer(gl, dynBuffer, gl.STREAM_DRAW);
  30858. // static //
  30859. var staticOffset = 0;
  30860. this.staticStride = 0;
  30861. for (var _i = 0; _i < this.staticProperties.length; ++_i) {
  30862. var _property = this.staticProperties[_i];
  30863. _property.offset = staticOffset;
  30864. staticOffset += _property.size;
  30865. this.staticStride += _property.size;
  30866. }
  30867. var statBuffer = new ArrayBuffer(this.size * this.staticStride * 4 * 4);
  30868. this.staticData = new Float32Array(statBuffer);
  30869. this.staticDataUint32 = new Uint32Array(statBuffer);
  30870. this.staticBuffer = _pixiGlCore2.default.GLBuffer.createVertexBuffer(gl, statBuffer, gl.STATIC_DRAW);
  30871. this.vao = new _pixiGlCore2.default.VertexArrayObject(gl).addIndex(this.indexBuffer);
  30872. for (var _i2 = 0; _i2 < this.dynamicProperties.length; ++_i2) {
  30873. var _property2 = this.dynamicProperties[_i2];
  30874. if (_property2.unsignedByte) {
  30875. this.vao.addAttribute(this.dynamicBuffer, _property2.attribute, gl.UNSIGNED_BYTE, true, this.dynamicStride * 4, _property2.offset * 4);
  30876. } else {
  30877. this.vao.addAttribute(this.dynamicBuffer, _property2.attribute, gl.FLOAT, false, this.dynamicStride * 4, _property2.offset * 4);
  30878. }
  30879. }
  30880. for (var _i3 = 0; _i3 < this.staticProperties.length; ++_i3) {
  30881. var _property3 = this.staticProperties[_i3];
  30882. if (_property3.unsignedByte) {
  30883. this.vao.addAttribute(this.staticBuffer, _property3.attribute, gl.UNSIGNED_BYTE, true, this.staticStride * 4, _property3.offset * 4);
  30884. } else {
  30885. this.vao.addAttribute(this.staticBuffer, _property3.attribute, gl.FLOAT, false, this.staticStride * 4, _property3.offset * 4);
  30886. }
  30887. }
  30888. };
  30889. /**
  30890. * Uploads the dynamic properties.
  30891. *
  30892. * @param {PIXI.DisplayObject[]} children - The children to upload.
  30893. * @param {number} startIndex - The index to start at.
  30894. * @param {number} amount - The number to upload.
  30895. */
  30896. ParticleBuffer.prototype.uploadDynamic = function uploadDynamic(children, startIndex, amount) {
  30897. for (var i = 0; i < this.dynamicProperties.length; i++) {
  30898. var property = this.dynamicProperties[i];
  30899. property.uploadFunction(children, startIndex, amount, property.unsignedByte ? this.dynamicDataUint32 : this.dynamicData, this.dynamicStride, property.offset);
  30900. }
  30901. this.dynamicBuffer.upload();
  30902. };
  30903. /**
  30904. * Uploads the static properties.
  30905. *
  30906. * @param {PIXI.DisplayObject[]} children - The children to upload.
  30907. * @param {number} startIndex - The index to start at.
  30908. * @param {number} amount - The number to upload.
  30909. */
  30910. ParticleBuffer.prototype.uploadStatic = function uploadStatic(children, startIndex, amount) {
  30911. for (var i = 0; i < this.staticProperties.length; i++) {
  30912. var property = this.staticProperties[i];
  30913. property.uploadFunction(children, startIndex, amount, property.unsignedByte ? this.staticDataUint32 : this.staticData, this.staticStride, property.offset);
  30914. }
  30915. this.staticBuffer.upload();
  30916. };
  30917. /**
  30918. * Destroys the ParticleBuffer.
  30919. *
  30920. */
  30921. ParticleBuffer.prototype.destroy = function destroy() {
  30922. this.dynamicProperties = null;
  30923. this.dynamicBuffer.destroy();
  30924. this.dynamicBuffer = null;
  30925. this.dynamicData = null;
  30926. this.dynamicDataUint32 = null;
  30927. this.staticProperties = null;
  30928. this.staticBuffer.destroy();
  30929. this.staticBuffer = null;
  30930. this.staticData = null;
  30931. this.staticDataUint32 = null;
  30932. };
  30933. return ParticleBuffer;
  30934. }();
  30935. exports.default = ParticleBuffer;
  30936. }, { "../../core/utils/createIndicesForQuads": 123, "pixi-gl-core": 15 }], 176: [function (require, module, exports) {
  30937. 'use strict';
  30938. exports.__esModule = true;
  30939. var _core = require('../../core');
  30940. var core = _interopRequireWildcard(_core);
  30941. var _ParticleShader = require('./ParticleShader');
  30942. var _ParticleShader2 = _interopRequireDefault(_ParticleShader);
  30943. var _ParticleBuffer = require('./ParticleBuffer');
  30944. var _ParticleBuffer2 = _interopRequireDefault(_ParticleBuffer);
  30945. var _utils = require('../../core/utils');
  30946. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  30947. function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
  30948. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  30949. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  30950. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  30951. /**
  30952. * @author Mat Groves
  30953. *
  30954. * Big thanks to the very clever Matt DesLauriers <mattdesl> https://github.com/mattdesl/
  30955. * for creating the original PixiJS version!
  30956. * Also a thanks to https://github.com/bchevalier for tweaking the tint and alpha so that they now
  30957. * share 4 bytes on the vertex buffer
  30958. *
  30959. * Heavily inspired by LibGDX's ParticleRenderer:
  30960. * https://github.com/libgdx/libgdx/blob/master/gdx/src/com/badlogic/gdx/graphics/g2d/ParticleRenderer.java
  30961. */
  30962. /**
  30963. *
  30964. * @class
  30965. * @private
  30966. * @memberof PIXI
  30967. */
  30968. var ParticleRenderer = function (_core$ObjectRenderer) {
  30969. _inherits(ParticleRenderer, _core$ObjectRenderer);
  30970. /**
  30971. * @param {PIXI.WebGLRenderer} renderer - The renderer this sprite batch works for.
  30972. */
  30973. function ParticleRenderer(renderer) {
  30974. _classCallCheck(this, ParticleRenderer);
  30975. // 65535 is max vertex index in the index buffer (see ParticleRenderer)
  30976. // so max number of particles is 65536 / 4 = 16384
  30977. // and max number of element in the index buffer is 16384 * 6 = 98304
  30978. // Creating a full index buffer, overhead is 98304 * 2 = 196Ko
  30979. // let numIndices = 98304;
  30980. /**
  30981. * The default shader that is used if a sprite doesn't have a more specific one.
  30982. *
  30983. * @member {PIXI.Shader}
  30984. */
  30985. var _this = _possibleConstructorReturn(this, _core$ObjectRenderer.call(this, renderer));
  30986. _this.shader = null;
  30987. _this.indexBuffer = null;
  30988. _this.properties = null;
  30989. _this.tempMatrix = new core.Matrix();
  30990. _this.CONTEXT_UID = 0;
  30991. return _this;
  30992. }
  30993. /**
  30994. * When there is a WebGL context change
  30995. *
  30996. * @private
  30997. */
  30998. ParticleRenderer.prototype.onContextChange = function onContextChange() {
  30999. var gl = this.renderer.gl;
  31000. this.CONTEXT_UID = this.renderer.CONTEXT_UID;
  31001. // setup default shader
  31002. this.shader = new _ParticleShader2.default(gl);
  31003. this.properties = [
  31004. // verticesData
  31005. {
  31006. attribute: this.shader.attributes.aVertexPosition,
  31007. size: 2,
  31008. uploadFunction: this.uploadVertices,
  31009. offset: 0
  31010. },
  31011. // positionData
  31012. {
  31013. attribute: this.shader.attributes.aPositionCoord,
  31014. size: 2,
  31015. uploadFunction: this.uploadPosition,
  31016. offset: 0
  31017. },
  31018. // rotationData
  31019. {
  31020. attribute: this.shader.attributes.aRotation,
  31021. size: 1,
  31022. uploadFunction: this.uploadRotation,
  31023. offset: 0
  31024. },
  31025. // uvsData
  31026. {
  31027. attribute: this.shader.attributes.aTextureCoord,
  31028. size: 2,
  31029. uploadFunction: this.uploadUvs,
  31030. offset: 0
  31031. },
  31032. // tintData
  31033. {
  31034. attribute: this.shader.attributes.aColor,
  31035. size: 1,
  31036. unsignedByte: true,
  31037. uploadFunction: this.uploadTint,
  31038. offset: 0
  31039. }];
  31040. };
  31041. /**
  31042. * Starts a new particle batch.
  31043. *
  31044. */
  31045. ParticleRenderer.prototype.start = function start() {
  31046. this.renderer.bindShader(this.shader);
  31047. };
  31048. /**
  31049. * Renders the particle container object.
  31050. *
  31051. * @param {PIXI.ParticleContainer} container - The container to render using this ParticleRenderer
  31052. */
  31053. ParticleRenderer.prototype.render = function render(container) {
  31054. var children = container.children;
  31055. var maxSize = container._maxSize;
  31056. var batchSize = container._batchSize;
  31057. var renderer = this.renderer;
  31058. var totalChildren = children.length;
  31059. if (totalChildren === 0) {
  31060. return;
  31061. } else if (totalChildren > maxSize) {
  31062. totalChildren = maxSize;
  31063. }
  31064. var buffers = container._glBuffers[renderer.CONTEXT_UID];
  31065. if (!buffers) {
  31066. buffers = container._glBuffers[renderer.CONTEXT_UID] = this.generateBuffers(container);
  31067. }
  31068. var baseTexture = children[0]._texture.baseTexture;
  31069. // if the uvs have not updated then no point rendering just yet!
  31070. this.renderer.setBlendMode(core.utils.correctBlendMode(container.blendMode, baseTexture.premultipliedAlpha));
  31071. var gl = renderer.gl;
  31072. var m = container.worldTransform.copy(this.tempMatrix);
  31073. m.prepend(renderer._activeRenderTarget.projectionMatrix);
  31074. this.shader.uniforms.projectionMatrix = m.toArray(true);
  31075. this.shader.uniforms.uColor = core.utils.premultiplyRgba(container.tintRgb, container.worldAlpha, this.shader.uniforms.uColor, baseTexture.premultipliedAlpha);
  31076. // make sure the texture is bound..
  31077. this.shader.uniforms.uSampler = renderer.bindTexture(baseTexture);
  31078. var updateStatic = false;
  31079. // now lets upload and render the buffers..
  31080. for (var i = 0, j = 0; i < totalChildren; i += batchSize, j += 1) {
  31081. var amount = totalChildren - i;
  31082. if (amount > batchSize) {
  31083. amount = batchSize;
  31084. }
  31085. if (j >= buffers.length) {
  31086. if (!container.autoResize) {
  31087. break;
  31088. }
  31089. buffers.push(this._generateOneMoreBuffer(container));
  31090. }
  31091. var buffer = buffers[j];
  31092. // we always upload the dynamic
  31093. buffer.uploadDynamic(children, i, amount);
  31094. var bid = container._bufferUpdateIDs[i] || 0;
  31095. updateStatic = updateStatic || buffer._updateID < bid;
  31096. // we only upload the static content when we have to!
  31097. if (updateStatic) {
  31098. buffer._updateID = container._updateID;
  31099. buffer.uploadStatic(children, i, amount);
  31100. }
  31101. // bind the buffer
  31102. renderer.bindVao(buffer.vao);
  31103. buffer.vao.draw(gl.TRIANGLES, amount * 6);
  31104. }
  31105. };
  31106. /**
  31107. * Creates one particle buffer for each child in the container we want to render and updates internal properties
  31108. *
  31109. * @param {PIXI.ParticleContainer} container - The container to render using this ParticleRenderer
  31110. * @return {PIXI.ParticleBuffer[]} The buffers
  31111. */
  31112. ParticleRenderer.prototype.generateBuffers = function generateBuffers(container) {
  31113. var gl = this.renderer.gl;
  31114. var buffers = [];
  31115. var size = container._maxSize;
  31116. var batchSize = container._batchSize;
  31117. var dynamicPropertyFlags = container._properties;
  31118. for (var i = 0; i < size; i += batchSize) {
  31119. buffers.push(new _ParticleBuffer2.default(gl, this.properties, dynamicPropertyFlags, batchSize));
  31120. }
  31121. return buffers;
  31122. };
  31123. /**
  31124. * Creates one more particle buffer, because container has autoResize feature
  31125. *
  31126. * @param {PIXI.ParticleContainer} container - The container to render using this ParticleRenderer
  31127. * @return {PIXI.ParticleBuffer} generated buffer
  31128. * @private
  31129. */
  31130. ParticleRenderer.prototype._generateOneMoreBuffer = function _generateOneMoreBuffer(container) {
  31131. var gl = this.renderer.gl;
  31132. var batchSize = container._batchSize;
  31133. var dynamicPropertyFlags = container._properties;
  31134. return new _ParticleBuffer2.default(gl, this.properties, dynamicPropertyFlags, batchSize);
  31135. };
  31136. /**
  31137. * Uploads the verticies.
  31138. *
  31139. * @param {PIXI.DisplayObject[]} children - the array of display objects to render
  31140. * @param {number} startIndex - the index to start from in the children array
  31141. * @param {number} amount - the amount of children that will have their vertices uploaded
  31142. * @param {number[]} array - The vertices to upload.
  31143. * @param {number} stride - Stride to use for iteration.
  31144. * @param {number} offset - Offset to start at.
  31145. */
  31146. ParticleRenderer.prototype.uploadVertices = function uploadVertices(children, startIndex, amount, array, stride, offset) {
  31147. var w0 = 0;
  31148. var w1 = 0;
  31149. var h0 = 0;
  31150. var h1 = 0;
  31151. for (var i = 0; i < amount; ++i) {
  31152. var sprite = children[startIndex + i];
  31153. var texture = sprite._texture;
  31154. var sx = sprite.scale.x;
  31155. var sy = sprite.scale.y;
  31156. var trim = texture.trim;
  31157. var orig = texture.orig;
  31158. if (trim) {
  31159. // if the sprite is trimmed and is not a tilingsprite then we need to add the
  31160. // extra space before transforming the sprite coords..
  31161. w1 = trim.x - sprite.anchor.x * orig.width;
  31162. w0 = w1 + trim.width;
  31163. h1 = trim.y - sprite.anchor.y * orig.height;
  31164. h0 = h1 + trim.height;
  31165. } else {
  31166. w0 = orig.width * (1 - sprite.anchor.x);
  31167. w1 = orig.width * -sprite.anchor.x;
  31168. h0 = orig.height * (1 - sprite.anchor.y);
  31169. h1 = orig.height * -sprite.anchor.y;
  31170. }
  31171. array[offset] = w1 * sx;
  31172. array[offset + 1] = h1 * sy;
  31173. array[offset + stride] = w0 * sx;
  31174. array[offset + stride + 1] = h1 * sy;
  31175. array[offset + stride * 2] = w0 * sx;
  31176. array[offset + stride * 2 + 1] = h0 * sy;
  31177. array[offset + stride * 3] = w1 * sx;
  31178. array[offset + stride * 3 + 1] = h0 * sy;
  31179. offset += stride * 4;
  31180. }
  31181. };
  31182. /**
  31183. *
  31184. * @param {PIXI.DisplayObject[]} children - the array of display objects to render
  31185. * @param {number} startIndex - the index to start from in the children array
  31186. * @param {number} amount - the amount of children that will have their positions uploaded
  31187. * @param {number[]} array - The vertices to upload.
  31188. * @param {number} stride - Stride to use for iteration.
  31189. * @param {number} offset - Offset to start at.
  31190. */
  31191. ParticleRenderer.prototype.uploadPosition = function uploadPosition(children, startIndex, amount, array, stride, offset) {
  31192. for (var i = 0; i < amount; i++) {
  31193. var spritePosition = children[startIndex + i].position;
  31194. array[offset] = spritePosition.x;
  31195. array[offset + 1] = spritePosition.y;
  31196. array[offset + stride] = spritePosition.x;
  31197. array[offset + stride + 1] = spritePosition.y;
  31198. array[offset + stride * 2] = spritePosition.x;
  31199. array[offset + stride * 2 + 1] = spritePosition.y;
  31200. array[offset + stride * 3] = spritePosition.x;
  31201. array[offset + stride * 3 + 1] = spritePosition.y;
  31202. offset += stride * 4;
  31203. }
  31204. };
  31205. /**
  31206. *
  31207. * @param {PIXI.DisplayObject[]} children - the array of display objects to render
  31208. * @param {number} startIndex - the index to start from in the children array
  31209. * @param {number} amount - the amount of children that will have their rotation uploaded
  31210. * @param {number[]} array - The vertices to upload.
  31211. * @param {number} stride - Stride to use for iteration.
  31212. * @param {number} offset - Offset to start at.
  31213. */
  31214. ParticleRenderer.prototype.uploadRotation = function uploadRotation(children, startIndex, amount, array, stride, offset) {
  31215. for (var i = 0; i < amount; i++) {
  31216. var spriteRotation = children[startIndex + i].rotation;
  31217. array[offset] = spriteRotation;
  31218. array[offset + stride] = spriteRotation;
  31219. array[offset + stride * 2] = spriteRotation;
  31220. array[offset + stride * 3] = spriteRotation;
  31221. offset += stride * 4;
  31222. }
  31223. };
  31224. /**
  31225. *
  31226. * @param {PIXI.DisplayObject[]} children - the array of display objects to render
  31227. * @param {number} startIndex - the index to start from in the children array
  31228. * @param {number} amount - the amount of children that will have their rotation uploaded
  31229. * @param {number[]} array - The vertices to upload.
  31230. * @param {number} stride - Stride to use for iteration.
  31231. * @param {number} offset - Offset to start at.
  31232. */
  31233. ParticleRenderer.prototype.uploadUvs = function uploadUvs(children, startIndex, amount, array, stride, offset) {
  31234. for (var i = 0; i < amount; ++i) {
  31235. var textureUvs = children[startIndex + i]._texture._uvs;
  31236. if (textureUvs) {
  31237. array[offset] = textureUvs.x0;
  31238. array[offset + 1] = textureUvs.y0;
  31239. array[offset + stride] = textureUvs.x1;
  31240. array[offset + stride + 1] = textureUvs.y1;
  31241. array[offset + stride * 2] = textureUvs.x2;
  31242. array[offset + stride * 2 + 1] = textureUvs.y2;
  31243. array[offset + stride * 3] = textureUvs.x3;
  31244. array[offset + stride * 3 + 1] = textureUvs.y3;
  31245. offset += stride * 4;
  31246. } else {
  31247. // TODO you know this can be easier!
  31248. array[offset] = 0;
  31249. array[offset + 1] = 0;
  31250. array[offset + stride] = 0;
  31251. array[offset + stride + 1] = 0;
  31252. array[offset + stride * 2] = 0;
  31253. array[offset + stride * 2 + 1] = 0;
  31254. array[offset + stride * 3] = 0;
  31255. array[offset + stride * 3 + 1] = 0;
  31256. offset += stride * 4;
  31257. }
  31258. }
  31259. };
  31260. /**
  31261. *
  31262. * @param {PIXI.DisplayObject[]} children - the array of display objects to render
  31263. * @param {number} startIndex - the index to start from in the children array
  31264. * @param {number} amount - the amount of children that will have their rotation uploaded
  31265. * @param {number[]} array - The vertices to upload.
  31266. * @param {number} stride - Stride to use for iteration.
  31267. * @param {number} offset - Offset to start at.
  31268. */
  31269. ParticleRenderer.prototype.uploadTint = function uploadTint(children, startIndex, amount, array, stride, offset) {
  31270. for (var i = 0; i < amount; ++i) {
  31271. var sprite = children[startIndex + i];
  31272. var premultiplied = sprite._texture.baseTexture.premultipliedAlpha;
  31273. var alpha = sprite.alpha;
  31274. // we dont call extra function if alpha is 1.0, that's faster
  31275. var argb = alpha < 1.0 && premultiplied ? (0, _utils.premultiplyTint)(sprite._tintRGB, alpha) : sprite._tintRGB + (alpha * 255 << 24);
  31276. array[offset] = argb;
  31277. array[offset + stride] = argb;
  31278. array[offset + stride * 2] = argb;
  31279. array[offset + stride * 3] = argb;
  31280. offset += stride * 4;
  31281. }
  31282. };
  31283. /**
  31284. * Destroys the ParticleRenderer.
  31285. *
  31286. */
  31287. ParticleRenderer.prototype.destroy = function destroy() {
  31288. if (this.renderer.gl) {
  31289. this.renderer.gl.deleteBuffer(this.indexBuffer);
  31290. }
  31291. _core$ObjectRenderer.prototype.destroy.call(this);
  31292. this.shader.destroy();
  31293. this.indices = null;
  31294. this.tempMatrix = null;
  31295. };
  31296. return ParticleRenderer;
  31297. }(core.ObjectRenderer);
  31298. exports.default = ParticleRenderer;
  31299. core.WebGLRenderer.registerPlugin('particle', ParticleRenderer);
  31300. }, { "../../core": 65, "../../core/utils": 125, "./ParticleBuffer": 175, "./ParticleShader": 177 }], 177: [function (require, module, exports) {
  31301. 'use strict';
  31302. exports.__esModule = true;
  31303. var _Shader2 = require('../../core/Shader');
  31304. var _Shader3 = _interopRequireDefault(_Shader2);
  31305. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  31306. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  31307. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  31308. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  31309. /**
  31310. * @class
  31311. * @extends PIXI.Shader
  31312. * @memberof PIXI
  31313. */
  31314. var ParticleShader = function (_Shader) {
  31315. _inherits(ParticleShader, _Shader);
  31316. /**
  31317. * @param {PIXI.Shader} gl - The webgl shader manager this shader works for.
  31318. */
  31319. function ParticleShader(gl) {
  31320. _classCallCheck(this, ParticleShader);
  31321. return _possibleConstructorReturn(this, _Shader.call(this, gl,
  31322. // vertex shader
  31323. ['attribute vec2 aVertexPosition;', 'attribute vec2 aTextureCoord;', 'attribute vec4 aColor;', 'attribute vec2 aPositionCoord;', 'attribute float aRotation;', 'uniform mat3 projectionMatrix;', 'uniform vec4 uColor;', 'varying vec2 vTextureCoord;', 'varying vec4 vColor;', 'void main(void){', ' float x = (aVertexPosition.x) * cos(aRotation) - (aVertexPosition.y) * sin(aRotation);', ' float y = (aVertexPosition.x) * sin(aRotation) + (aVertexPosition.y) * cos(aRotation);', ' vec2 v = vec2(x, y);', ' v = v + aPositionCoord;', ' gl_Position = vec4((projectionMatrix * vec3(v, 1.0)).xy, 0.0, 1.0);', ' vTextureCoord = aTextureCoord;', ' vColor = aColor * uColor;', '}'].join('\n'),
  31324. // hello
  31325. ['varying vec2 vTextureCoord;', 'varying vec4 vColor;', 'uniform sampler2D uSampler;', 'void main(void){', ' vec4 color = texture2D(uSampler, vTextureCoord) * vColor;', ' gl_FragColor = color;', '}'].join('\n')));
  31326. }
  31327. return ParticleShader;
  31328. }(_Shader3.default);
  31329. exports.default = ParticleShader;
  31330. }, { "../../core/Shader": 44 }], 178: [function (require, module, exports) {
  31331. "use strict";
  31332. // References:
  31333. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sign
  31334. if (!Math.sign) {
  31335. Math.sign = function mathSign(x) {
  31336. x = Number(x);
  31337. if (x === 0 || isNaN(x)) {
  31338. return x;
  31339. }
  31340. return x > 0 ? 1 : -1;
  31341. };
  31342. }
  31343. }, {}], 179: [function (require, module, exports) {
  31344. 'use strict';
  31345. // References:
  31346. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isInteger
  31347. if (!Number.isInteger) {
  31348. Number.isInteger = function numberIsInteger(value) {
  31349. return typeof value === 'number' && isFinite(value) && Math.floor(value) === value;
  31350. };
  31351. }
  31352. }, {}], 180: [function (require, module, exports) {
  31353. 'use strict';
  31354. var _objectAssign = require('object-assign');
  31355. var _objectAssign2 = _interopRequireDefault(_objectAssign);
  31356. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  31357. if (!Object.assign) {
  31358. Object.assign = _objectAssign2.default;
  31359. } // References:
  31360. // https://github.com/sindresorhus/object-assign
  31361. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign
  31362. }, { "object-assign": 6 }], 181: [function (require, module, exports) {
  31363. 'use strict';
  31364. require('./Object.assign');
  31365. require('./requestAnimationFrame');
  31366. require('./Math.sign');
  31367. require('./Number.isInteger');
  31368. if (!window.ArrayBuffer) {
  31369. window.ArrayBuffer = Array;
  31370. }
  31371. if (!window.Float32Array) {
  31372. window.Float32Array = Array;
  31373. }
  31374. if (!window.Uint32Array) {
  31375. window.Uint32Array = Array;
  31376. }
  31377. if (!window.Uint16Array) {
  31378. window.Uint16Array = Array;
  31379. }
  31380. }, { "./Math.sign": 178, "./Number.isInteger": 179, "./Object.assign": 180, "./requestAnimationFrame": 182 }], 182: [function (require, module, exports) {
  31381. (function (global) {
  31382. 'use strict';
  31383. // References:
  31384. // http://paulirish.com/2011/requestanimationframe-for-smart-animating/
  31385. // https://gist.github.com/1579671
  31386. // http://updates.html5rocks.com/2012/05/requestAnimationFrame-API-now-with-sub-millisecond-precision
  31387. // https://gist.github.com/timhall/4078614
  31388. // https://github.com/Financial-Times/polyfill-service/tree/master/polyfills/requestAnimationFrame
  31389. // Expected to be used with Browserfiy
  31390. // Browserify automatically detects the use of `global` and passes the
  31391. // correct reference of `global`, `self`, and finally `window`
  31392. var ONE_FRAME_TIME = 16;
  31393. // Date.now
  31394. if (!(Date.now && Date.prototype.getTime)) {
  31395. Date.now = function now() {
  31396. return new Date().getTime();
  31397. };
  31398. }
  31399. // performance.now
  31400. if (!(global.performance && global.performance.now)) {
  31401. var startTime = Date.now();
  31402. if (!global.performance) {
  31403. global.performance = {};
  31404. }
  31405. global.performance.now = function () {
  31406. return Date.now() - startTime;
  31407. };
  31408. }
  31409. // requestAnimationFrame
  31410. var lastTime = Date.now();
  31411. var vendors = ['ms', 'moz', 'webkit', 'o'];
  31412. for (var x = 0; x < vendors.length && !global.requestAnimationFrame; ++x) {
  31413. var p = vendors[x];
  31414. global.requestAnimationFrame = global[p + 'RequestAnimationFrame'];
  31415. global.cancelAnimationFrame = global[p + 'CancelAnimationFrame'] || global[p + 'CancelRequestAnimationFrame'];
  31416. }
  31417. if (!global.requestAnimationFrame) {
  31418. global.requestAnimationFrame = function (callback) {
  31419. if (typeof callback !== 'function') {
  31420. throw new TypeError(callback + 'is not a function');
  31421. }
  31422. var currentTime = Date.now();
  31423. var delay = ONE_FRAME_TIME + lastTime - currentTime;
  31424. if (delay < 0) {
  31425. delay = 0;
  31426. }
  31427. lastTime = currentTime;
  31428. return setTimeout(function () {
  31429. lastTime = Date.now();
  31430. callback(performance.now());
  31431. }, delay);
  31432. };
  31433. }
  31434. if (!global.cancelAnimationFrame) {
  31435. global.cancelAnimationFrame = function (id) {
  31436. return clearTimeout(id);
  31437. };
  31438. }
  31439. }).call(this, typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  31440. }, {}], 183: [function (require, module, exports) {
  31441. 'use strict';
  31442. exports.__esModule = true;
  31443. var _core = require('../core');
  31444. var core = _interopRequireWildcard(_core);
  31445. var _CountLimiter = require('./limiters/CountLimiter');
  31446. var _CountLimiter2 = _interopRequireDefault(_CountLimiter);
  31447. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  31448. function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
  31449. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  31450. var SharedTicker = core.ticker.shared;
  31451. /**
  31452. * Default number of uploads per frame using prepare plugin.
  31453. *
  31454. * @static
  31455. * @memberof PIXI.settings
  31456. * @name UPLOADS_PER_FRAME
  31457. * @type {number}
  31458. * @default 4
  31459. */
  31460. core.settings.UPLOADS_PER_FRAME = 4;
  31461. /**
  31462. * The prepare manager provides functionality to upload content to the GPU. BasePrepare handles
  31463. * basic queuing functionality and is extended by {@link PIXI.prepare.WebGLPrepare} and {@link PIXI.prepare.CanvasPrepare}
  31464. * to provide preparation capabilities specific to their respective renderers.
  31465. *
  31466. * @example
  31467. * // Create a sprite
  31468. * const sprite = new PIXI.Sprite.fromImage('something.png');
  31469. *
  31470. * // Load object into GPU
  31471. * app.renderer.plugins.prepare.upload(sprite, () => {
  31472. *
  31473. * //Texture(s) has been uploaded to GPU
  31474. * app.stage.addChild(sprite);
  31475. *
  31476. * })
  31477. *
  31478. * @abstract
  31479. * @class
  31480. * @memberof PIXI.prepare
  31481. */
  31482. var BasePrepare = function () {
  31483. /**
  31484. * @param {PIXI.SystemRenderer} renderer - A reference to the current renderer
  31485. */
  31486. function BasePrepare(renderer) {
  31487. var _this = this;
  31488. _classCallCheck(this, BasePrepare);
  31489. /**
  31490. * The limiter to be used to control how quickly items are prepared.
  31491. * @type {PIXI.prepare.CountLimiter|PIXI.prepare.TimeLimiter}
  31492. */
  31493. this.limiter = new _CountLimiter2.default(core.settings.UPLOADS_PER_FRAME);
  31494. /**
  31495. * Reference to the renderer.
  31496. * @type {PIXI.SystemRenderer}
  31497. * @protected
  31498. */
  31499. this.renderer = renderer;
  31500. /**
  31501. * The only real difference between CanvasPrepare and WebGLPrepare is what they pass
  31502. * to upload hooks. That different parameter is stored here.
  31503. * @type {PIXI.prepare.CanvasPrepare|PIXI.WebGLRenderer}
  31504. * @protected
  31505. */
  31506. this.uploadHookHelper = null;
  31507. /**
  31508. * Collection of items to uploads at once.
  31509. * @type {Array<*>}
  31510. * @private
  31511. */
  31512. this.queue = [];
  31513. /**
  31514. * Collection of additional hooks for finding assets.
  31515. * @type {Array<Function>}
  31516. * @private
  31517. */
  31518. this.addHooks = [];
  31519. /**
  31520. * Collection of additional hooks for processing assets.
  31521. * @type {Array<Function>}
  31522. * @private
  31523. */
  31524. this.uploadHooks = [];
  31525. /**
  31526. * Callback to call after completed.
  31527. * @type {Array<Function>}
  31528. * @private
  31529. */
  31530. this.completes = [];
  31531. /**
  31532. * If prepare is ticking (running).
  31533. * @type {boolean}
  31534. * @private
  31535. */
  31536. this.ticking = false;
  31537. /**
  31538. * 'bound' call for prepareItems().
  31539. * @type {Function}
  31540. * @private
  31541. */
  31542. this.delayedTick = function () {
  31543. // unlikely, but in case we were destroyed between tick() and delayedTick()
  31544. if (!_this.queue) {
  31545. return;
  31546. }
  31547. _this.prepareItems();
  31548. };
  31549. // hooks to find the correct texture
  31550. this.registerFindHook(findText);
  31551. this.registerFindHook(findTextStyle);
  31552. this.registerFindHook(findMultipleBaseTextures);
  31553. this.registerFindHook(findBaseTexture);
  31554. this.registerFindHook(findTexture);
  31555. // upload hooks
  31556. this.registerUploadHook(drawText);
  31557. this.registerUploadHook(calculateTextStyle);
  31558. }
  31559. /**
  31560. * Upload all the textures and graphics to the GPU.
  31561. *
  31562. * @param {Function|PIXI.DisplayObject|PIXI.Container|PIXI.BaseTexture|PIXI.Texture|PIXI.Graphics|PIXI.Text} item -
  31563. * Either the container or display object to search for items to upload, the items to upload themselves,
  31564. * or the callback function, if items have been added using `prepare.add`.
  31565. * @param {Function} [done] - Optional callback when all queued uploads have completed
  31566. */
  31567. BasePrepare.prototype.upload = function upload(item, done) {
  31568. if (typeof item === 'function') {
  31569. done = item;
  31570. item = null;
  31571. }
  31572. // If a display object, search for items
  31573. // that we could upload
  31574. if (item) {
  31575. this.add(item);
  31576. }
  31577. // Get the items for upload from the display
  31578. if (this.queue.length) {
  31579. if (done) {
  31580. this.completes.push(done);
  31581. }
  31582. if (!this.ticking) {
  31583. this.ticking = true;
  31584. SharedTicker.addOnce(this.tick, this, core.UPDATE_PRIORITY.UTILITY);
  31585. }
  31586. } else if (done) {
  31587. done();
  31588. }
  31589. };
  31590. /**
  31591. * Handle tick update
  31592. *
  31593. * @private
  31594. */
  31595. BasePrepare.prototype.tick = function tick() {
  31596. setTimeout(this.delayedTick, 0);
  31597. };
  31598. /**
  31599. * Actually prepare items. This is handled outside of the tick because it will take a while
  31600. * and we do NOT want to block the current animation frame from rendering.
  31601. *
  31602. * @private
  31603. */
  31604. BasePrepare.prototype.prepareItems = function prepareItems() {
  31605. this.limiter.beginFrame();
  31606. // Upload the graphics
  31607. while (this.queue.length && this.limiter.allowedToUpload()) {
  31608. var item = this.queue[0];
  31609. var uploaded = false;
  31610. if (item && !item._destroyed) {
  31611. for (var i = 0, len = this.uploadHooks.length; i < len; i++) {
  31612. if (this.uploadHooks[i](this.uploadHookHelper, item)) {
  31613. this.queue.shift();
  31614. uploaded = true;
  31615. break;
  31616. }
  31617. }
  31618. }
  31619. if (!uploaded) {
  31620. this.queue.shift();
  31621. }
  31622. }
  31623. // We're finished
  31624. if (!this.queue.length) {
  31625. this.ticking = false;
  31626. var completes = this.completes.slice(0);
  31627. this.completes.length = 0;
  31628. for (var _i = 0, _len = completes.length; _i < _len; _i++) {
  31629. completes[_i]();
  31630. }
  31631. } else {
  31632. // if we are not finished, on the next rAF do this again
  31633. SharedTicker.addOnce(this.tick, this, core.UPDATE_PRIORITY.UTILITY);
  31634. }
  31635. };
  31636. /**
  31637. * Adds hooks for finding items.
  31638. *
  31639. * @param {Function} addHook - Function call that takes two parameters: `item:*, queue:Array`
  31640. * function must return `true` if it was able to add item to the queue.
  31641. * @return {PIXI.BasePrepare} Instance of plugin for chaining.
  31642. */
  31643. BasePrepare.prototype.registerFindHook = function registerFindHook(addHook) {
  31644. if (addHook) {
  31645. this.addHooks.push(addHook);
  31646. }
  31647. return this;
  31648. };
  31649. /**
  31650. * Adds hooks for uploading items.
  31651. *
  31652. * @param {Function} uploadHook - Function call that takes two parameters: `prepare:CanvasPrepare, item:*` and
  31653. * function must return `true` if it was able to handle upload of item.
  31654. * @return {PIXI.BasePrepare} Instance of plugin for chaining.
  31655. */
  31656. BasePrepare.prototype.registerUploadHook = function registerUploadHook(uploadHook) {
  31657. if (uploadHook) {
  31658. this.uploadHooks.push(uploadHook);
  31659. }
  31660. return this;
  31661. };
  31662. /**
  31663. * Manually add an item to the uploading queue.
  31664. *
  31665. * @param {PIXI.DisplayObject|PIXI.Container|PIXI.BaseTexture|PIXI.Texture|PIXI.Graphics|PIXI.Text|*} item - Object to
  31666. * add to the queue
  31667. * @return {PIXI.CanvasPrepare} Instance of plugin for chaining.
  31668. */
  31669. BasePrepare.prototype.add = function add(item) {
  31670. // Add additional hooks for finding elements on special
  31671. // types of objects that
  31672. for (var i = 0, len = this.addHooks.length; i < len; i++) {
  31673. if (this.addHooks[i](item, this.queue)) {
  31674. break;
  31675. }
  31676. }
  31677. // Get childen recursively
  31678. if (item instanceof core.Container) {
  31679. for (var _i2 = item.children.length - 1; _i2 >= 0; _i2--) {
  31680. this.add(item.children[_i2]);
  31681. }
  31682. }
  31683. return this;
  31684. };
  31685. /**
  31686. * Destroys the plugin, don't use after this.
  31687. *
  31688. */
  31689. BasePrepare.prototype.destroy = function destroy() {
  31690. if (this.ticking) {
  31691. SharedTicker.remove(this.tick, this);
  31692. }
  31693. this.ticking = false;
  31694. this.addHooks = null;
  31695. this.uploadHooks = null;
  31696. this.renderer = null;
  31697. this.completes = null;
  31698. this.queue = null;
  31699. this.limiter = null;
  31700. this.uploadHookHelper = null;
  31701. };
  31702. return BasePrepare;
  31703. }();
  31704. /**
  31705. * Built-in hook to find multiple textures from objects like AnimatedSprites.
  31706. *
  31707. * @private
  31708. * @param {PIXI.DisplayObject} item - Display object to check
  31709. * @param {Array<*>} queue - Collection of items to upload
  31710. * @return {boolean} if a PIXI.Texture object was found.
  31711. */
  31712. exports.default = BasePrepare;
  31713. function findMultipleBaseTextures(item, queue) {
  31714. var result = false;
  31715. // Objects with mutliple textures
  31716. if (item && item._textures && item._textures.length) {
  31717. for (var i = 0; i < item._textures.length; i++) {
  31718. if (item._textures[i] instanceof core.Texture) {
  31719. var baseTexture = item._textures[i].baseTexture;
  31720. if (queue.indexOf(baseTexture) === -1) {
  31721. queue.push(baseTexture);
  31722. result = true;
  31723. }
  31724. }
  31725. }
  31726. }
  31727. return result;
  31728. }
  31729. /**
  31730. * Built-in hook to find BaseTextures from Sprites.
  31731. *
  31732. * @private
  31733. * @param {PIXI.DisplayObject} item - Display object to check
  31734. * @param {Array<*>} queue - Collection of items to upload
  31735. * @return {boolean} if a PIXI.Texture object was found.
  31736. */
  31737. function findBaseTexture(item, queue) {
  31738. // Objects with textures, like Sprites/Text
  31739. if (item instanceof core.BaseTexture) {
  31740. if (queue.indexOf(item) === -1) {
  31741. queue.push(item);
  31742. }
  31743. return true;
  31744. }
  31745. return false;
  31746. }
  31747. /**
  31748. * Built-in hook to find textures from objects.
  31749. *
  31750. * @private
  31751. * @param {PIXI.DisplayObject} item - Display object to check
  31752. * @param {Array<*>} queue - Collection of items to upload
  31753. * @return {boolean} if a PIXI.Texture object was found.
  31754. */
  31755. function findTexture(item, queue) {
  31756. if (item._texture && item._texture instanceof core.Texture) {
  31757. var texture = item._texture.baseTexture;
  31758. if (queue.indexOf(texture) === -1) {
  31759. queue.push(texture);
  31760. }
  31761. return true;
  31762. }
  31763. return false;
  31764. }
  31765. /**
  31766. * Built-in hook to draw PIXI.Text to its texture.
  31767. *
  31768. * @private
  31769. * @param {PIXI.WebGLRenderer|PIXI.CanvasPrepare} helper - Not used by this upload handler
  31770. * @param {PIXI.DisplayObject} item - Item to check
  31771. * @return {boolean} If item was uploaded.
  31772. */
  31773. function drawText(helper, item) {
  31774. if (item instanceof core.Text) {
  31775. // updating text will return early if it is not dirty
  31776. item.updateText(true);
  31777. return true;
  31778. }
  31779. return false;
  31780. }
  31781. /**
  31782. * Built-in hook to calculate a text style for a PIXI.Text object.
  31783. *
  31784. * @private
  31785. * @param {PIXI.WebGLRenderer|PIXI.CanvasPrepare} helper - Not used by this upload handler
  31786. * @param {PIXI.DisplayObject} item - Item to check
  31787. * @return {boolean} If item was uploaded.
  31788. */
  31789. function calculateTextStyle(helper, item) {
  31790. if (item instanceof core.TextStyle) {
  31791. var font = item.toFontString();
  31792. core.TextMetrics.measureFont(font);
  31793. return true;
  31794. }
  31795. return false;
  31796. }
  31797. /**
  31798. * Built-in hook to find Text objects.
  31799. *
  31800. * @private
  31801. * @param {PIXI.DisplayObject} item - Display object to check
  31802. * @param {Array<*>} queue - Collection of items to upload
  31803. * @return {boolean} if a PIXI.Text object was found.
  31804. */
  31805. function findText(item, queue) {
  31806. if (item instanceof core.Text) {
  31807. // push the text style to prepare it - this can be really expensive
  31808. if (queue.indexOf(item.style) === -1) {
  31809. queue.push(item.style);
  31810. }
  31811. // also push the text object so that we can render it (to canvas/texture) if needed
  31812. if (queue.indexOf(item) === -1) {
  31813. queue.push(item);
  31814. }
  31815. // also push the Text's texture for upload to GPU
  31816. var texture = item._texture.baseTexture;
  31817. if (queue.indexOf(texture) === -1) {
  31818. queue.push(texture);
  31819. }
  31820. return true;
  31821. }
  31822. return false;
  31823. }
  31824. /**
  31825. * Built-in hook to find TextStyle objects.
  31826. *
  31827. * @private
  31828. * @param {PIXI.TextStyle} item - Display object to check
  31829. * @param {Array<*>} queue - Collection of items to upload
  31830. * @return {boolean} if a PIXI.TextStyle object was found.
  31831. */
  31832. function findTextStyle(item, queue) {
  31833. if (item instanceof core.TextStyle) {
  31834. if (queue.indexOf(item) === -1) {
  31835. queue.push(item);
  31836. }
  31837. return true;
  31838. }
  31839. return false;
  31840. }
  31841. }, { "../core": 65, "./limiters/CountLimiter": 186 }], 184: [function (require, module, exports) {
  31842. 'use strict';
  31843. exports.__esModule = true;
  31844. var _core = require('../../core');
  31845. var core = _interopRequireWildcard(_core);
  31846. var _BasePrepare2 = require('../BasePrepare');
  31847. var _BasePrepare3 = _interopRequireDefault(_BasePrepare2);
  31848. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  31849. function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
  31850. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  31851. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  31852. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  31853. var CANVAS_START_SIZE = 16;
  31854. /**
  31855. * The prepare manager provides functionality to upload content to the GPU
  31856. * This cannot be done directly for Canvas like in WebGL, but the effect can be achieved by drawing
  31857. * textures to an offline canvas.
  31858. * This draw call will force the texture to be moved onto the GPU.
  31859. *
  31860. * An instance of this class is automatically created by default, and can be found at renderer.plugins.prepare
  31861. *
  31862. * @class
  31863. * @extends PIXI.prepare.BasePrepare
  31864. * @memberof PIXI.prepare
  31865. */
  31866. var CanvasPrepare = function (_BasePrepare) {
  31867. _inherits(CanvasPrepare, _BasePrepare);
  31868. /**
  31869. * @param {PIXI.CanvasRenderer} renderer - A reference to the current renderer
  31870. */
  31871. function CanvasPrepare(renderer) {
  31872. _classCallCheck(this, CanvasPrepare);
  31873. var _this = _possibleConstructorReturn(this, _BasePrepare.call(this, renderer));
  31874. _this.uploadHookHelper = _this;
  31875. /**
  31876. * An offline canvas to render textures to
  31877. * @type {HTMLCanvasElement}
  31878. * @private
  31879. */
  31880. _this.canvas = document.createElement('canvas');
  31881. _this.canvas.width = CANVAS_START_SIZE;
  31882. _this.canvas.height = CANVAS_START_SIZE;
  31883. /**
  31884. * The context to the canvas
  31885. * @type {CanvasRenderingContext2D}
  31886. * @private
  31887. */
  31888. _this.ctx = _this.canvas.getContext('2d');
  31889. // Add textures to upload
  31890. _this.registerUploadHook(uploadBaseTextures);
  31891. return _this;
  31892. }
  31893. /**
  31894. * Destroys the plugin, don't use after this.
  31895. *
  31896. */
  31897. CanvasPrepare.prototype.destroy = function destroy() {
  31898. _BasePrepare.prototype.destroy.call(this);
  31899. this.ctx = null;
  31900. this.canvas = null;
  31901. };
  31902. return CanvasPrepare;
  31903. }(_BasePrepare3.default);
  31904. /**
  31905. * Built-in hook to upload PIXI.Texture objects to the GPU.
  31906. *
  31907. * @private
  31908. * @param {*} prepare - Instance of CanvasPrepare
  31909. * @param {*} item - Item to check
  31910. * @return {boolean} If item was uploaded.
  31911. */
  31912. exports.default = CanvasPrepare;
  31913. function uploadBaseTextures(prepare, item) {
  31914. if (item instanceof core.BaseTexture) {
  31915. var image = item.source;
  31916. // Sometimes images (like atlas images) report a size of zero, causing errors on windows phone.
  31917. // So if the width or height is equal to zero then use the canvas size
  31918. // Otherwise use whatever is smaller, the image dimensions or the canvas dimensions.
  31919. var imageWidth = image.width === 0 ? prepare.canvas.width : Math.min(prepare.canvas.width, image.width);
  31920. var imageHeight = image.height === 0 ? prepare.canvas.height : Math.min(prepare.canvas.height, image.height);
  31921. // Only a small subsections is required to be drawn to have the whole texture uploaded to the GPU
  31922. // A smaller draw can be faster.
  31923. prepare.ctx.drawImage(image, 0, 0, imageWidth, imageHeight, 0, 0, prepare.canvas.width, prepare.canvas.height);
  31924. return true;
  31925. }
  31926. return false;
  31927. }
  31928. core.CanvasRenderer.registerPlugin('prepare', CanvasPrepare);
  31929. }, { "../../core": 65, "../BasePrepare": 183 }], 185: [function (require, module, exports) {
  31930. 'use strict';
  31931. exports.__esModule = true;
  31932. var _WebGLPrepare = require('./webgl/WebGLPrepare');
  31933. Object.defineProperty(exports, 'webgl', {
  31934. enumerable: true,
  31935. get: function get() {
  31936. return _interopRequireDefault(_WebGLPrepare).default;
  31937. }
  31938. });
  31939. var _CanvasPrepare = require('./canvas/CanvasPrepare');
  31940. Object.defineProperty(exports, 'canvas', {
  31941. enumerable: true,
  31942. get: function get() {
  31943. return _interopRequireDefault(_CanvasPrepare).default;
  31944. }
  31945. });
  31946. var _BasePrepare = require('./BasePrepare');
  31947. Object.defineProperty(exports, 'BasePrepare', {
  31948. enumerable: true,
  31949. get: function get() {
  31950. return _interopRequireDefault(_BasePrepare).default;
  31951. }
  31952. });
  31953. var _CountLimiter = require('./limiters/CountLimiter');
  31954. Object.defineProperty(exports, 'CountLimiter', {
  31955. enumerable: true,
  31956. get: function get() {
  31957. return _interopRequireDefault(_CountLimiter).default;
  31958. }
  31959. });
  31960. var _TimeLimiter = require('./limiters/TimeLimiter');
  31961. Object.defineProperty(exports, 'TimeLimiter', {
  31962. enumerable: true,
  31963. get: function get() {
  31964. return _interopRequireDefault(_TimeLimiter).default;
  31965. }
  31966. });
  31967. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  31968. }, { "./BasePrepare": 183, "./canvas/CanvasPrepare": 184, "./limiters/CountLimiter": 186, "./limiters/TimeLimiter": 187, "./webgl/WebGLPrepare": 188 }], 186: [function (require, module, exports) {
  31969. "use strict";
  31970. exports.__esModule = true;
  31971. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  31972. /**
  31973. * CountLimiter limits the number of items handled by a {@link PIXI.prepare.BasePrepare} to a specified
  31974. * number of items per frame.
  31975. *
  31976. * @class
  31977. * @memberof PIXI
  31978. */
  31979. var CountLimiter = function () {
  31980. /**
  31981. * @param {number} maxItemsPerFrame - The maximum number of items that can be prepared each frame.
  31982. */
  31983. function CountLimiter(maxItemsPerFrame) {
  31984. _classCallCheck(this, CountLimiter);
  31985. /**
  31986. * The maximum number of items that can be prepared each frame.
  31987. * @private
  31988. */
  31989. this.maxItemsPerFrame = maxItemsPerFrame;
  31990. /**
  31991. * The number of items that can be prepared in the current frame.
  31992. * @type {number}
  31993. * @private
  31994. */
  31995. this.itemsLeft = 0;
  31996. }
  31997. /**
  31998. * Resets any counting properties to start fresh on a new frame.
  31999. */
  32000. CountLimiter.prototype.beginFrame = function beginFrame() {
  32001. this.itemsLeft = this.maxItemsPerFrame;
  32002. };
  32003. /**
  32004. * Checks to see if another item can be uploaded. This should only be called once per item.
  32005. * @return {boolean} If the item is allowed to be uploaded.
  32006. */
  32007. CountLimiter.prototype.allowedToUpload = function allowedToUpload() {
  32008. return this.itemsLeft-- > 0;
  32009. };
  32010. return CountLimiter;
  32011. }();
  32012. exports.default = CountLimiter;
  32013. }, {}], 187: [function (require, module, exports) {
  32014. "use strict";
  32015. exports.__esModule = true;
  32016. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  32017. /**
  32018. * TimeLimiter limits the number of items handled by a {@link PIXI.BasePrepare} to a specified
  32019. * number of milliseconds per frame.
  32020. *
  32021. * @class
  32022. * @memberof PIXI
  32023. */
  32024. var TimeLimiter = function () {
  32025. /**
  32026. * @param {number} maxMilliseconds - The maximum milliseconds that can be spent preparing items each frame.
  32027. */
  32028. function TimeLimiter(maxMilliseconds) {
  32029. _classCallCheck(this, TimeLimiter);
  32030. /**
  32031. * The maximum milliseconds that can be spent preparing items each frame.
  32032. * @private
  32033. */
  32034. this.maxMilliseconds = maxMilliseconds;
  32035. /**
  32036. * The start time of the current frame.
  32037. * @type {number}
  32038. * @private
  32039. */
  32040. this.frameStart = 0;
  32041. }
  32042. /**
  32043. * Resets any counting properties to start fresh on a new frame.
  32044. */
  32045. TimeLimiter.prototype.beginFrame = function beginFrame() {
  32046. this.frameStart = Date.now();
  32047. };
  32048. /**
  32049. * Checks to see if another item can be uploaded. This should only be called once per item.
  32050. * @return {boolean} If the item is allowed to be uploaded.
  32051. */
  32052. TimeLimiter.prototype.allowedToUpload = function allowedToUpload() {
  32053. return Date.now() - this.frameStart < this.maxMilliseconds;
  32054. };
  32055. return TimeLimiter;
  32056. }();
  32057. exports.default = TimeLimiter;
  32058. }, {}], 188: [function (require, module, exports) {
  32059. 'use strict';
  32060. exports.__esModule = true;
  32061. var _core = require('../../core');
  32062. var core = _interopRequireWildcard(_core);
  32063. var _BasePrepare2 = require('../BasePrepare');
  32064. var _BasePrepare3 = _interopRequireDefault(_BasePrepare2);
  32065. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  32066. function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
  32067. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  32068. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  32069. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  32070. /**
  32071. * The prepare manager provides functionality to upload content to the GPU.
  32072. *
  32073. * An instance of this class is automatically created by default, and can be found at renderer.plugins.prepare
  32074. *
  32075. * @class
  32076. * @extends PIXI.prepare.BasePrepare
  32077. * @memberof PIXI.prepare
  32078. */
  32079. var WebGLPrepare = function (_BasePrepare) {
  32080. _inherits(WebGLPrepare, _BasePrepare);
  32081. /**
  32082. * @param {PIXI.WebGLRenderer} renderer - A reference to the current renderer
  32083. */
  32084. function WebGLPrepare(renderer) {
  32085. _classCallCheck(this, WebGLPrepare);
  32086. var _this = _possibleConstructorReturn(this, _BasePrepare.call(this, renderer));
  32087. _this.uploadHookHelper = _this.renderer;
  32088. // Add textures and graphics to upload
  32089. _this.registerFindHook(findGraphics);
  32090. _this.registerUploadHook(uploadBaseTextures);
  32091. _this.registerUploadHook(uploadGraphics);
  32092. return _this;
  32093. }
  32094. return WebGLPrepare;
  32095. }(_BasePrepare3.default);
  32096. /**
  32097. * Built-in hook to upload PIXI.Texture objects to the GPU.
  32098. *
  32099. * @private
  32100. * @param {PIXI.WebGLRenderer} renderer - instance of the webgl renderer
  32101. * @param {PIXI.DisplayObject} item - Item to check
  32102. * @return {boolean} If item was uploaded.
  32103. */
  32104. exports.default = WebGLPrepare;
  32105. function uploadBaseTextures(renderer, item) {
  32106. if (item instanceof core.BaseTexture) {
  32107. // if the texture already has a GL texture, then the texture has been prepared or rendered
  32108. // before now. If the texture changed, then the changer should be calling texture.update() which
  32109. // reuploads the texture without need for preparing it again
  32110. if (!item._glTextures[renderer.CONTEXT_UID]) {
  32111. renderer.textureManager.updateTexture(item);
  32112. }
  32113. return true;
  32114. }
  32115. return false;
  32116. }
  32117. /**
  32118. * Built-in hook to upload PIXI.Graphics to the GPU.
  32119. *
  32120. * @private
  32121. * @param {PIXI.WebGLRenderer} renderer - instance of the webgl renderer
  32122. * @param {PIXI.DisplayObject} item - Item to check
  32123. * @return {boolean} If item was uploaded.
  32124. */
  32125. function uploadGraphics(renderer, item) {
  32126. if (item instanceof core.Graphics) {
  32127. // if the item is not dirty and already has webgl data, then it got prepared or rendered
  32128. // before now and we shouldn't waste time updating it again
  32129. if (item.dirty || item.clearDirty || !item._webGL[renderer.plugins.graphics.CONTEXT_UID]) {
  32130. renderer.plugins.graphics.updateGraphics(item);
  32131. }
  32132. return true;
  32133. }
  32134. return false;
  32135. }
  32136. /**
  32137. * Built-in hook to find graphics.
  32138. *
  32139. * @private
  32140. * @param {PIXI.DisplayObject} item - Display object to check
  32141. * @param {Array<*>} queue - Collection of items to upload
  32142. * @return {boolean} if a PIXI.Graphics object was found.
  32143. */
  32144. function findGraphics(item, queue) {
  32145. if (item instanceof core.Graphics) {
  32146. queue.push(item);
  32147. return true;
  32148. }
  32149. return false;
  32150. }
  32151. core.WebGLRenderer.registerPlugin('prepare', WebGLPrepare);
  32152. }, { "../../core": 65, "../BasePrepare": 183 }], 189: [function (require, module, exports) {
  32153. (function (global) {
  32154. 'use strict';
  32155. exports.__esModule = true;
  32156. exports.loader = exports.prepare = exports.particles = exports.mesh = exports.loaders = exports.interaction = exports.filters = exports.extras = exports.extract = exports.accessibility = undefined;
  32157. var _polyfill = require('./polyfill');
  32158. Object.keys(_polyfill).forEach(function (key) {
  32159. if (key === "default" || key === "__esModule") return;
  32160. Object.defineProperty(exports, key, {
  32161. enumerable: true,
  32162. get: function get() {
  32163. return _polyfill[key];
  32164. }
  32165. });
  32166. });
  32167. var _core = require('./core');
  32168. Object.keys(_core).forEach(function (key) {
  32169. if (key === "default" || key === "__esModule") return;
  32170. Object.defineProperty(exports, key, {
  32171. enumerable: true,
  32172. get: function get() {
  32173. return _core[key];
  32174. }
  32175. });
  32176. });
  32177. var _deprecation = require('./deprecation');
  32178. var _deprecation2 = _interopRequireDefault(_deprecation);
  32179. var _accessibility = require('./accessibility');
  32180. var accessibility = _interopRequireWildcard(_accessibility);
  32181. var _extract = require('./extract');
  32182. var extract = _interopRequireWildcard(_extract);
  32183. var _extras = require('./extras');
  32184. var extras = _interopRequireWildcard(_extras);
  32185. var _filters = require('./filters');
  32186. var filters = _interopRequireWildcard(_filters);
  32187. var _interaction = require('./interaction');
  32188. var interaction = _interopRequireWildcard(_interaction);
  32189. var _loaders = require('./loaders');
  32190. var loaders = _interopRequireWildcard(_loaders);
  32191. var _mesh = require('./mesh');
  32192. var mesh = _interopRequireWildcard(_mesh);
  32193. var _particles = require('./particles');
  32194. var particles = _interopRequireWildcard(_particles);
  32195. var _prepare = require('./prepare');
  32196. var prepare = _interopRequireWildcard(_prepare);
  32197. function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
  32198. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  32199. // export core
  32200. _core.utils.mixins.performMixins();
  32201. /**
  32202. * Alias for {@link PIXI.loaders.shared}.
  32203. * @name loader
  32204. * @memberof PIXI
  32205. * @type {PIXI.loader.Loader}
  32206. */
  32207. // handle mixins now, after all code has been added, including deprecation
  32208. // export libs
  32209. // import polyfills. Done as an export to make sure polyfills are imported first
  32210. var loader = loaders.shared || null;
  32211. exports.accessibility = accessibility;
  32212. exports.extract = extract;
  32213. exports.extras = extras;
  32214. exports.filters = filters;
  32215. exports.interaction = interaction;
  32216. exports.loaders = loaders;
  32217. exports.mesh = mesh;
  32218. exports.particles = particles;
  32219. exports.prepare = prepare;
  32220. exports.loader = loader;
  32221. // Apply the deprecations
  32222. if (typeof _deprecation2.default === 'function') {
  32223. (0, _deprecation2.default)(exports);
  32224. }
  32225. // Always export PixiJS globally.
  32226. global.PIXI = exports; // eslint-disable-line
  32227. }).call(this, typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  32228. }, { "./accessibility": 42, "./core": 65, "./deprecation": 131, "./extract": 133, "./extras": 141, "./filters": 153, "./interaction": 159, "./loaders": 162, "./mesh": 171, "./particles": 174, "./polyfill": 181, "./prepare": 185 }]
  32229. }, {}, [189])(189)
  32230. });