pixi.js 1.6 MB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431204322043320434204352043620437204382043920440204412044220443204442044520446204472044820449204502045120452204532045420455204562045720458204592046020461204622046320464204652046620467204682046920470204712047220473204742047520476204772047820479204802048120482204832048420485204862048720488204892049020491204922049320494204952049620497204982049920500205012050220503205042050520506205072050820509205102051120512205132051420515205162051720518205192052020521205222052320524205252052620527205282052920530205312053220533205342053520536205372053820539205402054120542205432054420545205462054720548205492055020551205522055320554205552055620557205582055920560205612056220563205642056520566205672056820569205702057120572205732057420575205762057720578205792058020581205822058320584205852058620587205882058920590205912059220593205942059520596205972059820599206002060120602206032060420605206062060720608206092061020611206122061320614206152061620617206182061920620206212062220623206242062520626206272062820629206302063120632206332063420635206362063720638206392064020641206422064320644206452064620647206482064920650206512065220653206542065520656206572065820659206602066120662206632066420665206662066720668206692067020671206722067320674206752067620677206782067920680206812068220683206842068520686206872068820689206902069120692206932069420695206962069720698206992070020701207022070320704207052070620707207082070920710207112071220713207142071520716207172071820719207202072120722207232072420725207262072720728207292073020731207322073320734207352073620737207382073920740207412074220743207442074520746207472074820749207502075120752207532075420755207562075720758207592076020761207622076320764207652076620767207682076920770207712077220773207742077520776207772077820779207802078120782207832078420785207862078720788207892079020791207922079320794207952079620797207982079920800208012080220803208042080520806208072080820809208102081120812208132081420815208162081720818208192082020821208222082320824208252082620827208282082920830208312083220833208342083520836208372083820839208402084120842208432084420845208462084720848208492085020851208522085320854208552085620857208582085920860208612086220863208642086520866208672086820869208702087120872208732087420875208762087720878208792088020881208822088320884208852088620887208882088920890208912089220893208942089520896208972089820899209002090120902209032090420905209062090720908209092091020911209122091320914209152091620917209182091920920209212092220923209242092520926209272092820929209302093120932209332093420935209362093720938209392094020941209422094320944209452094620947209482094920950209512095220953209542095520956209572095820959209602096120962209632096420965209662096720968209692097020971209722097320974209752097620977209782097920980209812098220983209842098520986209872098820989209902099120992209932099420995209962099720998209992100021001210022100321004210052100621007210082100921010210112101221013210142101521016210172101821019210202102121022210232102421025210262102721028210292103021031210322103321034210352103621037210382103921040210412104221043210442104521046210472104821049210502105121052210532105421055210562105721058210592106021061210622106321064210652106621067210682106921070210712107221073210742107521076210772107821079210802108121082210832108421085210862108721088210892109021091210922109321094210952109621097210982109921100211012110221103211042110521106211072110821109211102111121112211132111421115211162111721118211192112021121211222112321124211252112621127211282112921130211312113221133211342113521136211372113821139211402114121142211432114421145211462114721148211492115021151211522115321154211552115621157211582115921160211612116221163211642116521166211672116821169211702117121172211732117421175211762117721178211792118021181211822118321184211852118621187211882118921190211912119221193211942119521196211972119821199212002120121202212032120421205212062120721208212092121021211212122121321214212152121621217212182121921220212212122221223212242122521226212272122821229212302123121232212332123421235212362123721238212392124021241212422124321244212452124621247212482124921250212512125221253212542125521256212572125821259212602126121262212632126421265212662126721268212692127021271212722127321274212752127621277212782127921280212812128221283212842128521286212872128821289212902129121292212932129421295212962129721298212992130021301213022130321304213052130621307213082130921310213112131221313213142131521316213172131821319213202132121322213232132421325213262132721328213292133021331213322133321334213352133621337213382133921340213412134221343213442134521346213472134821349213502135121352213532135421355213562135721358213592136021361213622136321364213652136621367213682136921370213712137221373213742137521376213772137821379213802138121382213832138421385213862138721388213892139021391213922139321394213952139621397213982139921400214012140221403214042140521406214072140821409214102141121412214132141421415214162141721418214192142021421214222142321424214252142621427214282142921430214312143221433214342143521436214372143821439214402144121442214432144421445214462144721448214492145021451214522145321454214552145621457214582145921460214612146221463214642146521466214672146821469214702147121472214732147421475214762147721478214792148021481214822148321484214852148621487214882148921490214912149221493214942149521496214972149821499215002150121502215032150421505215062150721508215092151021511215122151321514215152151621517215182151921520215212152221523215242152521526215272152821529215302153121532215332153421535215362153721538215392154021541215422154321544215452154621547215482154921550215512155221553215542155521556215572155821559215602156121562215632156421565215662156721568215692157021571215722157321574215752157621577215782157921580215812158221583215842158521586215872158821589215902159121592215932159421595215962159721598215992160021601216022160321604216052160621607216082160921610216112161221613216142161521616216172161821619216202162121622216232162421625216262162721628216292163021631216322163321634216352163621637216382163921640216412164221643216442164521646216472164821649216502165121652216532165421655216562165721658216592166021661216622166321664216652166621667216682166921670216712167221673216742167521676216772167821679216802168121682216832168421685216862168721688216892169021691216922169321694216952169621697216982169921700217012170221703217042170521706217072170821709217102171121712217132171421715217162171721718217192172021721217222172321724217252172621727217282172921730217312173221733217342173521736217372173821739217402174121742217432174421745217462174721748217492175021751217522175321754217552175621757217582175921760217612176221763217642176521766217672176821769217702177121772217732177421775217762177721778217792178021781217822178321784217852178621787217882178921790217912179221793217942179521796217972179821799218002180121802218032180421805218062180721808218092181021811218122181321814218152181621817218182181921820218212182221823218242182521826218272182821829218302183121832218332183421835218362183721838218392184021841218422184321844218452184621847218482184921850218512185221853218542185521856218572185821859218602186121862218632186421865218662186721868218692187021871218722187321874218752187621877218782187921880218812188221883218842188521886218872188821889218902189121892218932189421895218962189721898218992190021901219022190321904219052190621907219082190921910219112191221913219142191521916219172191821919219202192121922219232192421925219262192721928219292193021931219322193321934219352193621937219382193921940219412194221943219442194521946219472194821949219502195121952219532195421955219562195721958219592196021961219622196321964219652196621967219682196921970219712197221973219742197521976219772197821979219802198121982219832198421985219862198721988219892199021991219922199321994219952199621997219982199922000220012200222003220042200522006220072200822009220102201122012220132201422015220162201722018220192202022021220222202322024220252202622027220282202922030220312203222033220342203522036220372203822039220402204122042220432204422045220462204722048220492205022051220522205322054220552205622057220582205922060220612206222063220642206522066220672206822069220702207122072220732207422075220762207722078220792208022081220822208322084220852208622087220882208922090220912209222093220942209522096220972209822099221002210122102221032210422105221062210722108221092211022111221122211322114221152211622117221182211922120221212212222123221242212522126221272212822129221302213122132221332213422135221362213722138221392214022141221422214322144221452214622147221482214922150221512215222153221542215522156221572215822159221602216122162221632216422165221662216722168221692217022171221722217322174221752217622177221782217922180221812218222183221842218522186221872218822189221902219122192221932219422195221962219722198221992220022201222022220322204222052220622207222082220922210222112221222213222142221522216222172221822219222202222122222222232222422225222262222722228222292223022231222322223322234222352223622237222382223922240222412224222243222442224522246222472224822249222502225122252222532225422255222562225722258222592226022261222622226322264222652226622267222682226922270222712227222273222742227522276222772227822279222802228122282222832228422285222862228722288222892229022291222922229322294222952229622297222982229922300223012230222303223042230522306223072230822309223102231122312223132231422315223162231722318223192232022321223222232322324223252232622327223282232922330223312233222333223342233522336223372233822339223402234122342223432234422345223462234722348223492235022351223522235322354223552235622357223582235922360223612236222363223642236522366223672236822369223702237122372223732237422375223762237722378223792238022381223822238322384223852238622387223882238922390223912239222393223942239522396223972239822399224002240122402224032240422405224062240722408224092241022411224122241322414224152241622417224182241922420224212242222423224242242522426224272242822429224302243122432224332243422435224362243722438224392244022441224422244322444224452244622447224482244922450224512245222453224542245522456224572245822459224602246122462224632246422465224662246722468224692247022471224722247322474224752247622477224782247922480224812248222483224842248522486224872248822489224902249122492224932249422495224962249722498224992250022501225022250322504225052250622507225082250922510225112251222513225142251522516225172251822519225202252122522225232252422525225262252722528225292253022531225322253322534225352253622537225382253922540225412254222543225442254522546225472254822549225502255122552225532255422555225562255722558225592256022561225622256322564225652256622567225682256922570225712257222573225742257522576225772257822579225802258122582225832258422585225862258722588225892259022591225922259322594225952259622597225982259922600226012260222603226042260522606226072260822609226102261122612226132261422615226162261722618226192262022621226222262322624226252262622627226282262922630226312263222633226342263522636226372263822639226402264122642226432264422645226462264722648226492265022651226522265322654226552265622657226582265922660226612266222663226642266522666226672266822669226702267122672226732267422675226762267722678226792268022681226822268322684226852268622687226882268922690226912269222693226942269522696226972269822699227002270122702227032270422705227062270722708227092271022711227122271322714227152271622717227182271922720227212272222723227242272522726227272272822729227302273122732227332273422735227362273722738227392274022741227422274322744227452274622747227482274922750227512275222753227542275522756227572275822759227602276122762227632276422765227662276722768227692277022771227722277322774227752277622777227782277922780227812278222783227842278522786227872278822789227902279122792227932279422795227962279722798227992280022801228022280322804228052280622807228082280922810228112281222813228142281522816228172281822819228202282122822228232282422825228262282722828228292283022831228322283322834228352283622837228382283922840228412284222843228442284522846228472284822849228502285122852228532285422855228562285722858228592286022861228622286322864228652286622867228682286922870228712287222873228742287522876228772287822879228802288122882228832288422885228862288722888228892289022891228922289322894228952289622897228982289922900229012290222903229042290522906229072290822909229102291122912229132291422915229162291722918229192292022921229222292322924229252292622927229282292922930229312293222933229342293522936229372293822939229402294122942229432294422945229462294722948229492295022951229522295322954229552295622957229582295922960229612296222963229642296522966229672296822969229702297122972229732297422975229762297722978229792298022981229822298322984229852298622987229882298922990229912299222993229942299522996229972299822999230002300123002230032300423005230062300723008230092301023011230122301323014230152301623017230182301923020230212302223023230242302523026230272302823029230302303123032230332303423035230362303723038230392304023041230422304323044230452304623047230482304923050230512305223053230542305523056230572305823059230602306123062230632306423065230662306723068230692307023071230722307323074230752307623077230782307923080230812308223083230842308523086230872308823089230902309123092230932309423095230962309723098230992310023101231022310323104231052310623107231082310923110231112311223113231142311523116231172311823119231202312123122231232312423125231262312723128231292313023131231322313323134231352313623137231382313923140231412314223143231442314523146231472314823149231502315123152231532315423155231562315723158231592316023161231622316323164231652316623167231682316923170231712317223173231742317523176231772317823179231802318123182231832318423185231862318723188231892319023191231922319323194231952319623197231982319923200232012320223203232042320523206232072320823209232102321123212232132321423215232162321723218232192322023221232222322323224232252322623227232282322923230232312323223233232342323523236232372323823239232402324123242232432324423245232462324723248232492325023251232522325323254232552325623257232582325923260232612326223263232642326523266232672326823269232702327123272232732327423275232762327723278232792328023281232822328323284232852328623287232882328923290232912329223293232942329523296232972329823299233002330123302233032330423305233062330723308233092331023311233122331323314233152331623317233182331923320233212332223323233242332523326233272332823329233302333123332233332333423335233362333723338233392334023341233422334323344233452334623347233482334923350233512335223353233542335523356233572335823359233602336123362233632336423365233662336723368233692337023371233722337323374233752337623377233782337923380233812338223383233842338523386233872338823389233902339123392233932339423395233962339723398233992340023401234022340323404234052340623407234082340923410234112341223413234142341523416234172341823419234202342123422234232342423425234262342723428234292343023431234322343323434234352343623437234382343923440234412344223443234442344523446234472344823449234502345123452234532345423455234562345723458234592346023461234622346323464234652346623467234682346923470234712347223473234742347523476234772347823479234802348123482234832348423485234862348723488234892349023491234922349323494234952349623497234982349923500235012350223503235042350523506235072350823509235102351123512235132351423515235162351723518235192352023521235222352323524235252352623527235282352923530235312353223533235342353523536235372353823539235402354123542235432354423545235462354723548235492355023551235522355323554235552355623557235582355923560235612356223563235642356523566235672356823569235702357123572235732357423575235762357723578235792358023581235822358323584235852358623587235882358923590235912359223593235942359523596235972359823599236002360123602236032360423605236062360723608236092361023611236122361323614236152361623617236182361923620236212362223623236242362523626236272362823629236302363123632236332363423635236362363723638236392364023641236422364323644236452364623647236482364923650236512365223653236542365523656236572365823659236602366123662236632366423665236662366723668236692367023671236722367323674236752367623677236782367923680236812368223683236842368523686236872368823689236902369123692236932369423695236962369723698236992370023701237022370323704237052370623707237082370923710237112371223713237142371523716237172371823719237202372123722237232372423725237262372723728237292373023731237322373323734237352373623737237382373923740237412374223743237442374523746237472374823749237502375123752237532375423755237562375723758237592376023761237622376323764237652376623767237682376923770237712377223773237742377523776237772377823779237802378123782237832378423785237862378723788237892379023791237922379323794237952379623797237982379923800238012380223803238042380523806238072380823809238102381123812238132381423815238162381723818238192382023821238222382323824238252382623827238282382923830238312383223833238342383523836238372383823839238402384123842238432384423845238462384723848238492385023851238522385323854238552385623857238582385923860238612386223863238642386523866238672386823869238702387123872238732387423875238762387723878238792388023881238822388323884238852388623887238882388923890238912389223893238942389523896238972389823899239002390123902239032390423905239062390723908239092391023911239122391323914239152391623917239182391923920239212392223923239242392523926239272392823929239302393123932239332393423935239362393723938239392394023941239422394323944239452394623947239482394923950239512395223953239542395523956239572395823959239602396123962239632396423965239662396723968239692397023971239722397323974239752397623977239782397923980239812398223983239842398523986239872398823989239902399123992239932399423995239962399723998239992400024001240022400324004240052400624007240082400924010240112401224013240142401524016240172401824019240202402124022240232402424025240262402724028240292403024031240322403324034240352403624037240382403924040240412404224043240442404524046240472404824049240502405124052240532405424055240562405724058240592406024061240622406324064240652406624067240682406924070240712407224073240742407524076240772407824079240802408124082240832408424085240862408724088240892409024091240922409324094240952409624097240982409924100241012410224103241042410524106241072410824109241102411124112241132411424115241162411724118241192412024121241222412324124241252412624127241282412924130241312413224133241342413524136241372413824139241402414124142241432414424145241462414724148241492415024151241522415324154241552415624157241582415924160241612416224163241642416524166241672416824169241702417124172241732417424175241762417724178241792418024181241822418324184241852418624187241882418924190241912419224193241942419524196241972419824199242002420124202242032420424205242062420724208242092421024211242122421324214242152421624217242182421924220242212422224223242242422524226242272422824229242302423124232242332423424235242362423724238242392424024241242422424324244242452424624247242482424924250242512425224253242542425524256242572425824259242602426124262242632426424265242662426724268242692427024271242722427324274242752427624277242782427924280242812428224283242842428524286242872428824289242902429124292242932429424295242962429724298242992430024301243022430324304243052430624307243082430924310243112431224313243142431524316243172431824319243202432124322243232432424325243262432724328243292433024331243322433324334243352433624337243382433924340243412434224343243442434524346243472434824349243502435124352243532435424355243562435724358243592436024361243622436324364243652436624367243682436924370243712437224373243742437524376243772437824379243802438124382243832438424385243862438724388243892439024391243922439324394243952439624397243982439924400244012440224403244042440524406244072440824409244102441124412244132441424415244162441724418244192442024421244222442324424244252442624427244282442924430244312443224433244342443524436244372443824439244402444124442244432444424445244462444724448244492445024451244522445324454244552445624457244582445924460244612446224463244642446524466244672446824469244702447124472244732447424475244762447724478244792448024481244822448324484244852448624487244882448924490244912449224493244942449524496244972449824499245002450124502245032450424505245062450724508245092451024511245122451324514245152451624517245182451924520245212452224523245242452524526245272452824529245302453124532245332453424535245362453724538245392454024541245422454324544245452454624547245482454924550245512455224553245542455524556245572455824559245602456124562245632456424565245662456724568245692457024571245722457324574245752457624577245782457924580245812458224583245842458524586245872458824589245902459124592245932459424595245962459724598245992460024601246022460324604246052460624607246082460924610246112461224613246142461524616246172461824619246202462124622246232462424625246262462724628246292463024631246322463324634246352463624637246382463924640246412464224643246442464524646246472464824649246502465124652246532465424655246562465724658246592466024661246622466324664246652466624667246682466924670246712467224673246742467524676246772467824679246802468124682246832468424685246862468724688246892469024691246922469324694246952469624697246982469924700247012470224703247042470524706247072470824709247102471124712247132471424715247162471724718247192472024721247222472324724247252472624727247282472924730247312473224733247342473524736247372473824739247402474124742247432474424745247462474724748247492475024751247522475324754247552475624757247582475924760247612476224763247642476524766247672476824769247702477124772247732477424775247762477724778247792478024781247822478324784247852478624787247882478924790247912479224793247942479524796247972479824799248002480124802248032480424805248062480724808248092481024811248122481324814248152481624817248182481924820248212482224823248242482524826248272482824829248302483124832248332483424835248362483724838248392484024841248422484324844248452484624847248482484924850248512485224853248542485524856248572485824859248602486124862248632486424865248662486724868248692487024871248722487324874248752487624877248782487924880248812488224883248842488524886248872488824889248902489124892248932489424895248962489724898248992490024901249022490324904249052490624907249082490924910249112491224913249142491524916249172491824919249202492124922249232492424925249262492724928249292493024931249322493324934249352493624937249382493924940249412494224943249442494524946249472494824949249502495124952249532495424955249562495724958249592496024961249622496324964249652496624967249682496924970249712497224973249742497524976249772497824979249802498124982249832498424985249862498724988249892499024991249922499324994249952499624997249982499925000250012500225003250042500525006250072500825009250102501125012250132501425015250162501725018250192502025021250222502325024250252502625027250282502925030250312503225033250342503525036250372503825039250402504125042250432504425045250462504725048250492505025051250522505325054250552505625057250582505925060250612506225063250642506525066250672506825069250702507125072250732507425075250762507725078250792508025081250822508325084250852508625087250882508925090250912509225093250942509525096250972509825099251002510125102251032510425105251062510725108251092511025111251122511325114251152511625117251182511925120251212512225123251242512525126251272512825129251302513125132251332513425135251362513725138251392514025141251422514325144251452514625147251482514925150251512515225153251542515525156251572515825159251602516125162251632516425165251662516725168251692517025171251722517325174251752517625177251782517925180251812518225183251842518525186251872518825189251902519125192251932519425195251962519725198251992520025201252022520325204252052520625207252082520925210252112521225213252142521525216252172521825219252202522125222252232522425225252262522725228252292523025231252322523325234252352523625237252382523925240252412524225243252442524525246252472524825249252502525125252252532525425255252562525725258252592526025261252622526325264252652526625267252682526925270252712527225273252742527525276252772527825279252802528125282252832528425285252862528725288252892529025291252922529325294252952529625297252982529925300253012530225303253042530525306253072530825309253102531125312253132531425315253162531725318253192532025321253222532325324253252532625327253282532925330253312533225333253342533525336253372533825339253402534125342253432534425345253462534725348253492535025351253522535325354253552535625357253582535925360253612536225363253642536525366253672536825369253702537125372253732537425375253762537725378253792538025381253822538325384253852538625387253882538925390253912539225393253942539525396253972539825399254002540125402254032540425405254062540725408254092541025411254122541325414254152541625417254182541925420254212542225423254242542525426254272542825429254302543125432254332543425435254362543725438254392544025441254422544325444254452544625447254482544925450254512545225453254542545525456254572545825459254602546125462254632546425465254662546725468254692547025471254722547325474254752547625477254782547925480254812548225483254842548525486254872548825489254902549125492254932549425495254962549725498254992550025501255022550325504255052550625507255082550925510255112551225513255142551525516255172551825519255202552125522255232552425525255262552725528255292553025531255322553325534255352553625537255382553925540255412554225543255442554525546255472554825549255502555125552255532555425555255562555725558255592556025561255622556325564255652556625567255682556925570255712557225573255742557525576255772557825579255802558125582255832558425585255862558725588255892559025591255922559325594255952559625597255982559925600256012560225603256042560525606256072560825609256102561125612256132561425615256162561725618256192562025621256222562325624256252562625627256282562925630256312563225633256342563525636256372563825639256402564125642256432564425645256462564725648256492565025651256522565325654256552565625657256582565925660256612566225663256642566525666256672566825669256702567125672256732567425675256762567725678256792568025681256822568325684256852568625687256882568925690256912569225693256942569525696256972569825699257002570125702257032570425705257062570725708257092571025711257122571325714257152571625717257182571925720257212572225723257242572525726257272572825729257302573125732257332573425735257362573725738257392574025741257422574325744257452574625747257482574925750257512575225753257542575525756257572575825759257602576125762257632576425765257662576725768257692577025771257722577325774257752577625777257782577925780257812578225783257842578525786257872578825789257902579125792257932579425795257962579725798257992580025801258022580325804258052580625807258082580925810258112581225813258142581525816258172581825819258202582125822258232582425825258262582725828258292583025831258322583325834258352583625837258382583925840258412584225843258442584525846258472584825849258502585125852258532585425855258562585725858258592586025861258622586325864258652586625867258682586925870258712587225873258742587525876258772587825879258802588125882258832588425885258862588725888258892589025891258922589325894258952589625897258982589925900259012590225903259042590525906259072590825909259102591125912259132591425915259162591725918259192592025921259222592325924259252592625927259282592925930259312593225933259342593525936259372593825939259402594125942259432594425945259462594725948259492595025951259522595325954259552595625957259582595925960259612596225963259642596525966259672596825969259702597125972259732597425975259762597725978259792598025981259822598325984259852598625987259882598925990259912599225993259942599525996259972599825999260002600126002260032600426005260062600726008260092601026011260122601326014260152601626017260182601926020260212602226023260242602526026260272602826029260302603126032260332603426035260362603726038260392604026041260422604326044260452604626047260482604926050260512605226053260542605526056260572605826059260602606126062260632606426065260662606726068260692607026071260722607326074260752607626077260782607926080260812608226083260842608526086260872608826089260902609126092260932609426095260962609726098260992610026101261022610326104261052610626107261082610926110261112611226113261142611526116261172611826119261202612126122261232612426125261262612726128261292613026131261322613326134261352613626137261382613926140261412614226143261442614526146261472614826149261502615126152261532615426155261562615726158261592616026161261622616326164261652616626167261682616926170261712617226173261742617526176261772617826179261802618126182261832618426185261862618726188261892619026191261922619326194261952619626197261982619926200262012620226203262042620526206262072620826209262102621126212262132621426215262162621726218262192622026221262222622326224262252622626227262282622926230262312623226233262342623526236262372623826239262402624126242262432624426245262462624726248262492625026251262522625326254262552625626257262582625926260262612626226263262642626526266262672626826269262702627126272262732627426275262762627726278262792628026281262822628326284262852628626287262882628926290262912629226293262942629526296262972629826299263002630126302263032630426305263062630726308263092631026311263122631326314263152631626317263182631926320263212632226323263242632526326263272632826329263302633126332263332633426335263362633726338263392634026341263422634326344263452634626347263482634926350263512635226353263542635526356263572635826359263602636126362263632636426365263662636726368263692637026371263722637326374263752637626377263782637926380263812638226383263842638526386263872638826389263902639126392263932639426395263962639726398263992640026401264022640326404264052640626407264082640926410264112641226413264142641526416264172641826419264202642126422264232642426425264262642726428264292643026431264322643326434264352643626437264382643926440264412644226443264442644526446264472644826449264502645126452264532645426455264562645726458264592646026461264622646326464264652646626467264682646926470264712647226473264742647526476264772647826479264802648126482264832648426485264862648726488264892649026491264922649326494264952649626497264982649926500265012650226503265042650526506265072650826509265102651126512265132651426515265162651726518265192652026521265222652326524265252652626527265282652926530265312653226533265342653526536265372653826539265402654126542265432654426545265462654726548265492655026551265522655326554265552655626557265582655926560265612656226563265642656526566265672656826569265702657126572265732657426575265762657726578265792658026581265822658326584265852658626587265882658926590265912659226593265942659526596265972659826599266002660126602266032660426605266062660726608266092661026611266122661326614266152661626617266182661926620266212662226623266242662526626266272662826629266302663126632266332663426635266362663726638266392664026641266422664326644266452664626647266482664926650266512665226653266542665526656266572665826659266602666126662266632666426665266662666726668266692667026671266722667326674266752667626677266782667926680266812668226683266842668526686266872668826689266902669126692266932669426695266962669726698266992670026701267022670326704267052670626707267082670926710267112671226713267142671526716267172671826719267202672126722267232672426725267262672726728267292673026731267322673326734267352673626737267382673926740267412674226743267442674526746267472674826749267502675126752267532675426755267562675726758267592676026761267622676326764267652676626767267682676926770267712677226773267742677526776267772677826779267802678126782267832678426785267862678726788267892679026791267922679326794267952679626797267982679926800268012680226803268042680526806268072680826809268102681126812268132681426815268162681726818268192682026821268222682326824268252682626827268282682926830268312683226833268342683526836268372683826839268402684126842268432684426845268462684726848268492685026851268522685326854268552685626857268582685926860268612686226863268642686526866268672686826869268702687126872268732687426875268762687726878268792688026881268822688326884268852688626887268882688926890268912689226893268942689526896268972689826899269002690126902269032690426905269062690726908269092691026911269122691326914269152691626917269182691926920269212692226923269242692526926269272692826929269302693126932269332693426935269362693726938269392694026941269422694326944269452694626947269482694926950269512695226953269542695526956269572695826959269602696126962269632696426965269662696726968269692697026971269722697326974269752697626977269782697926980269812698226983269842698526986269872698826989269902699126992269932699426995269962699726998269992700027001270022700327004270052700627007270082700927010270112701227013270142701527016270172701827019270202702127022270232702427025270262702727028270292703027031270322703327034270352703627037270382703927040270412704227043270442704527046270472704827049270502705127052270532705427055270562705727058270592706027061270622706327064270652706627067270682706927070270712707227073270742707527076270772707827079270802708127082270832708427085270862708727088270892709027091270922709327094270952709627097270982709927100271012710227103271042710527106271072710827109271102711127112271132711427115271162711727118271192712027121271222712327124271252712627127271282712927130271312713227133271342713527136271372713827139271402714127142271432714427145271462714727148271492715027151271522715327154271552715627157271582715927160271612716227163271642716527166271672716827169271702717127172271732717427175271762717727178271792718027181271822718327184271852718627187271882718927190271912719227193271942719527196271972719827199272002720127202272032720427205272062720727208272092721027211272122721327214272152721627217272182721927220272212722227223272242722527226272272722827229272302723127232272332723427235272362723727238272392724027241272422724327244272452724627247272482724927250272512725227253272542725527256272572725827259272602726127262272632726427265272662726727268272692727027271272722727327274272752727627277272782727927280272812728227283272842728527286272872728827289272902729127292272932729427295272962729727298272992730027301273022730327304273052730627307273082730927310273112731227313273142731527316273172731827319273202732127322273232732427325273262732727328273292733027331273322733327334273352733627337273382733927340273412734227343273442734527346273472734827349273502735127352273532735427355273562735727358273592736027361273622736327364273652736627367273682736927370273712737227373273742737527376273772737827379273802738127382273832738427385273862738727388273892739027391273922739327394273952739627397273982739927400274012740227403274042740527406274072740827409274102741127412274132741427415274162741727418274192742027421274222742327424274252742627427274282742927430274312743227433274342743527436274372743827439274402744127442274432744427445274462744727448274492745027451274522745327454274552745627457274582745927460274612746227463274642746527466274672746827469274702747127472274732747427475274762747727478274792748027481274822748327484274852748627487274882748927490274912749227493274942749527496274972749827499275002750127502275032750427505275062750727508275092751027511275122751327514275152751627517275182751927520275212752227523275242752527526275272752827529275302753127532275332753427535275362753727538275392754027541275422754327544275452754627547275482754927550275512755227553275542755527556275572755827559275602756127562275632756427565275662756727568275692757027571275722757327574275752757627577275782757927580275812758227583275842758527586275872758827589275902759127592275932759427595275962759727598275992760027601276022760327604276052760627607276082760927610276112761227613276142761527616276172761827619276202762127622276232762427625276262762727628276292763027631276322763327634276352763627637276382763927640276412764227643276442764527646276472764827649276502765127652276532765427655276562765727658276592766027661276622766327664276652766627667276682766927670276712767227673276742767527676276772767827679276802768127682276832768427685276862768727688276892769027691276922769327694276952769627697276982769927700277012770227703277042770527706277072770827709277102771127712277132771427715277162771727718277192772027721277222772327724277252772627727277282772927730277312773227733277342773527736277372773827739277402774127742277432774427745277462774727748277492775027751277522775327754277552775627757277582775927760277612776227763277642776527766277672776827769277702777127772277732777427775277762777727778277792778027781277822778327784277852778627787277882778927790277912779227793277942779527796277972779827799278002780127802278032780427805278062780727808278092781027811278122781327814278152781627817278182781927820278212782227823278242782527826278272782827829278302783127832278332783427835278362783727838278392784027841278422784327844278452784627847278482784927850278512785227853278542785527856278572785827859278602786127862278632786427865278662786727868278692787027871278722787327874278752787627877278782787927880278812788227883278842788527886278872788827889278902789127892278932789427895278962789727898278992790027901279022790327904279052790627907279082790927910279112791227913279142791527916279172791827919279202792127922279232792427925279262792727928279292793027931279322793327934279352793627937279382793927940279412794227943279442794527946279472794827949279502795127952279532795427955279562795727958279592796027961279622796327964279652796627967279682796927970279712797227973279742797527976279772797827979279802798127982279832798427985279862798727988279892799027991279922799327994279952799627997279982799928000280012800228003280042800528006280072800828009280102801128012280132801428015280162801728018280192802028021280222802328024280252802628027280282802928030280312803228033280342803528036280372803828039280402804128042280432804428045280462804728048280492805028051280522805328054280552805628057280582805928060280612806228063280642806528066280672806828069280702807128072280732807428075280762807728078280792808028081280822808328084280852808628087280882808928090280912809228093280942809528096280972809828099281002810128102281032810428105281062810728108281092811028111281122811328114281152811628117281182811928120281212812228123281242812528126281272812828129281302813128132281332813428135281362813728138281392814028141281422814328144281452814628147281482814928150281512815228153281542815528156281572815828159281602816128162281632816428165281662816728168281692817028171281722817328174281752817628177281782817928180281812818228183281842818528186281872818828189281902819128192281932819428195281962819728198281992820028201282022820328204282052820628207282082820928210282112821228213282142821528216282172821828219282202822128222282232822428225282262822728228282292823028231282322823328234282352823628237282382823928240282412824228243282442824528246282472824828249282502825128252282532825428255282562825728258282592826028261282622826328264282652826628267282682826928270282712827228273282742827528276282772827828279282802828128282282832828428285282862828728288282892829028291282922829328294282952829628297282982829928300283012830228303283042830528306283072830828309283102831128312283132831428315283162831728318283192832028321283222832328324283252832628327283282832928330283312833228333283342833528336283372833828339283402834128342283432834428345283462834728348283492835028351283522835328354283552835628357283582835928360283612836228363283642836528366283672836828369283702837128372283732837428375283762837728378283792838028381283822838328384283852838628387283882838928390283912839228393283942839528396283972839828399284002840128402284032840428405284062840728408284092841028411284122841328414284152841628417284182841928420284212842228423284242842528426284272842828429284302843128432284332843428435284362843728438284392844028441284422844328444284452844628447284482844928450284512845228453284542845528456284572845828459284602846128462284632846428465284662846728468284692847028471284722847328474284752847628477284782847928480284812848228483284842848528486284872848828489284902849128492284932849428495284962849728498284992850028501285022850328504285052850628507285082850928510285112851228513285142851528516285172851828519285202852128522285232852428525285262852728528285292853028531285322853328534285352853628537285382853928540285412854228543285442854528546285472854828549285502855128552285532855428555285562855728558285592856028561285622856328564285652856628567285682856928570285712857228573285742857528576285772857828579285802858128582285832858428585285862858728588285892859028591285922859328594285952859628597285982859928600286012860228603286042860528606286072860828609286102861128612286132861428615286162861728618286192862028621286222862328624286252862628627286282862928630286312863228633286342863528636286372863828639286402864128642286432864428645286462864728648286492865028651286522865328654286552865628657286582865928660286612866228663286642866528666286672866828669286702867128672286732867428675286762867728678286792868028681286822868328684286852868628687286882868928690286912869228693286942869528696286972869828699287002870128702287032870428705287062870728708287092871028711287122871328714287152871628717287182871928720287212872228723287242872528726287272872828729287302873128732287332873428735287362873728738287392874028741287422874328744287452874628747287482874928750287512875228753287542875528756287572875828759287602876128762287632876428765287662876728768287692877028771287722877328774287752877628777287782877928780287812878228783287842878528786287872878828789287902879128792287932879428795287962879728798287992880028801288022880328804288052880628807288082880928810288112881228813288142881528816288172881828819288202882128822288232882428825288262882728828288292883028831288322883328834288352883628837288382883928840288412884228843288442884528846288472884828849288502885128852288532885428855288562885728858288592886028861288622886328864288652886628867288682886928870288712887228873288742887528876288772887828879288802888128882288832888428885288862888728888288892889028891288922889328894288952889628897288982889928900289012890228903289042890528906289072890828909289102891128912289132891428915289162891728918289192892028921289222892328924289252892628927289282892928930289312893228933289342893528936289372893828939289402894128942289432894428945289462894728948289492895028951289522895328954289552895628957289582895928960289612896228963289642896528966289672896828969289702897128972289732897428975289762897728978289792898028981289822898328984289852898628987289882898928990289912899228993289942899528996289972899828999290002900129002290032900429005290062900729008290092901029011290122901329014290152901629017290182901929020290212902229023290242902529026290272902829029290302903129032290332903429035290362903729038290392904029041290422904329044290452904629047290482904929050290512905229053290542905529056290572905829059290602906129062290632906429065290662906729068290692907029071290722907329074290752907629077290782907929080290812908229083290842908529086290872908829089290902909129092290932909429095290962909729098290992910029101291022910329104291052910629107291082910929110291112911229113291142911529116291172911829119291202912129122291232912429125291262912729128291292913029131291322913329134291352913629137291382913929140291412914229143291442914529146291472914829149291502915129152291532915429155291562915729158291592916029161291622916329164291652916629167291682916929170291712917229173291742917529176291772917829179291802918129182291832918429185291862918729188291892919029191291922919329194291952919629197291982919929200292012920229203292042920529206292072920829209292102921129212292132921429215292162921729218292192922029221292222922329224292252922629227292282922929230292312923229233292342923529236292372923829239292402924129242292432924429245292462924729248292492925029251292522925329254292552925629257292582925929260292612926229263292642926529266292672926829269292702927129272292732927429275292762927729278292792928029281292822928329284292852928629287292882928929290292912929229293292942929529296292972929829299293002930129302293032930429305293062930729308293092931029311293122931329314293152931629317293182931929320293212932229323293242932529326293272932829329293302933129332293332933429335293362933729338293392934029341293422934329344293452934629347293482934929350293512935229353293542935529356293572935829359293602936129362293632936429365293662936729368293692937029371293722937329374293752937629377293782937929380293812938229383293842938529386293872938829389293902939129392293932939429395293962939729398293992940029401294022940329404294052940629407294082940929410294112941229413294142941529416294172941829419294202942129422294232942429425294262942729428294292943029431294322943329434294352943629437294382943929440294412944229443294442944529446294472944829449294502945129452294532945429455294562945729458294592946029461294622946329464294652946629467294682946929470294712947229473294742947529476294772947829479294802948129482294832948429485294862948729488294892949029491294922949329494294952949629497294982949929500295012950229503295042950529506295072950829509295102951129512295132951429515295162951729518295192952029521295222952329524295252952629527295282952929530295312953229533295342953529536295372953829539295402954129542295432954429545295462954729548295492955029551295522955329554295552955629557295582955929560295612956229563295642956529566295672956829569295702957129572295732957429575295762957729578295792958029581295822958329584295852958629587295882958929590295912959229593295942959529596295972959829599296002960129602296032960429605296062960729608296092961029611296122961329614296152961629617296182961929620296212962229623296242962529626296272962829629296302963129632296332963429635296362963729638296392964029641296422964329644296452964629647296482964929650296512965229653296542965529656296572965829659296602966129662296632966429665296662966729668296692967029671296722967329674296752967629677296782967929680296812968229683296842968529686296872968829689296902969129692296932969429695296962969729698296992970029701297022970329704297052970629707297082970929710297112971229713297142971529716297172971829719297202972129722297232972429725297262972729728297292973029731297322973329734297352973629737297382973929740297412974229743297442974529746297472974829749297502975129752297532975429755297562975729758297592976029761297622976329764297652976629767297682976929770297712977229773297742977529776297772977829779297802978129782297832978429785297862978729788297892979029791297922979329794297952979629797297982979929800298012980229803298042980529806298072980829809298102981129812298132981429815298162981729818298192982029821298222982329824298252982629827298282982929830298312983229833298342983529836298372983829839298402984129842298432984429845298462984729848298492985029851298522985329854298552985629857298582985929860298612986229863298642986529866298672986829869298702987129872298732987429875298762987729878298792988029881298822988329884298852988629887298882988929890298912989229893298942989529896298972989829899299002990129902299032990429905299062990729908299092991029911299122991329914299152991629917299182991929920299212992229923299242992529926299272992829929299302993129932299332993429935299362993729938299392994029941299422994329944299452994629947299482994929950299512995229953299542995529956299572995829959299602996129962299632996429965299662996729968299692997029971299722997329974299752997629977299782997929980299812998229983299842998529986299872998829989299902999129992299932999429995299962999729998299993000030001300023000330004300053000630007300083000930010300113001230013300143001530016300173001830019300203002130022300233002430025300263002730028300293003030031300323003330034300353003630037300383003930040300413004230043300443004530046300473004830049300503005130052300533005430055300563005730058300593006030061300623006330064300653006630067300683006930070300713007230073300743007530076300773007830079300803008130082300833008430085300863008730088300893009030091300923009330094300953009630097300983009930100301013010230103301043010530106301073010830109301103011130112301133011430115301163011730118301193012030121301223012330124301253012630127301283012930130301313013230133301343013530136301373013830139301403014130142301433014430145301463014730148301493015030151301523015330154301553015630157301583015930160301613016230163301643016530166301673016830169301703017130172301733017430175301763017730178301793018030181301823018330184301853018630187301883018930190301913019230193301943019530196301973019830199302003020130202302033020430205302063020730208302093021030211302123021330214302153021630217302183021930220302213022230223302243022530226302273022830229302303023130232302333023430235302363023730238302393024030241302423024330244302453024630247302483024930250302513025230253302543025530256302573025830259302603026130262302633026430265302663026730268302693027030271302723027330274302753027630277302783027930280302813028230283302843028530286302873028830289302903029130292302933029430295302963029730298302993030030301303023030330304303053030630307303083030930310303113031230313303143031530316303173031830319303203032130322303233032430325303263032730328303293033030331303323033330334303353033630337303383033930340303413034230343303443034530346303473034830349303503035130352303533035430355303563035730358303593036030361303623036330364303653036630367303683036930370303713037230373303743037530376303773037830379303803038130382303833038430385303863038730388303893039030391303923039330394303953039630397303983039930400304013040230403304043040530406304073040830409304103041130412304133041430415304163041730418304193042030421304223042330424304253042630427304283042930430304313043230433304343043530436304373043830439304403044130442304433044430445304463044730448304493045030451304523045330454304553045630457304583045930460304613046230463304643046530466304673046830469304703047130472304733047430475304763047730478304793048030481304823048330484304853048630487304883048930490304913049230493304943049530496304973049830499305003050130502305033050430505305063050730508305093051030511305123051330514305153051630517305183051930520305213052230523305243052530526305273052830529305303053130532305333053430535305363053730538305393054030541305423054330544305453054630547305483054930550305513055230553305543055530556305573055830559305603056130562305633056430565305663056730568305693057030571305723057330574305753057630577305783057930580305813058230583305843058530586305873058830589305903059130592305933059430595305963059730598305993060030601306023060330604306053060630607306083060930610306113061230613306143061530616306173061830619306203062130622306233062430625306263062730628306293063030631306323063330634306353063630637306383063930640306413064230643306443064530646306473064830649306503065130652306533065430655306563065730658306593066030661306623066330664306653066630667306683066930670306713067230673306743067530676306773067830679306803068130682306833068430685306863068730688306893069030691306923069330694306953069630697306983069930700307013070230703307043070530706307073070830709307103071130712307133071430715307163071730718307193072030721307223072330724307253072630727307283072930730307313073230733307343073530736307373073830739307403074130742307433074430745307463074730748307493075030751307523075330754307553075630757307583075930760307613076230763307643076530766307673076830769307703077130772307733077430775307763077730778307793078030781307823078330784307853078630787307883078930790307913079230793307943079530796307973079830799308003080130802308033080430805308063080730808308093081030811308123081330814308153081630817308183081930820308213082230823308243082530826308273082830829308303083130832308333083430835308363083730838308393084030841308423084330844308453084630847308483084930850308513085230853308543085530856308573085830859308603086130862308633086430865308663086730868308693087030871308723087330874308753087630877308783087930880308813088230883308843088530886308873088830889308903089130892308933089430895308963089730898308993090030901309023090330904309053090630907309083090930910309113091230913309143091530916309173091830919309203092130922309233092430925309263092730928309293093030931309323093330934309353093630937309383093930940309413094230943309443094530946309473094830949309503095130952309533095430955309563095730958309593096030961309623096330964309653096630967309683096930970309713097230973309743097530976309773097830979309803098130982309833098430985309863098730988309893099030991309923099330994309953099630997309983099931000310013100231003310043100531006310073100831009310103101131012310133101431015310163101731018310193102031021310223102331024310253102631027310283102931030310313103231033310343103531036310373103831039310403104131042310433104431045310463104731048310493105031051310523105331054310553105631057310583105931060310613106231063310643106531066310673106831069310703107131072310733107431075310763107731078310793108031081310823108331084310853108631087310883108931090310913109231093310943109531096310973109831099311003110131102311033110431105311063110731108311093111031111311123111331114311153111631117311183111931120311213112231123311243112531126311273112831129311303113131132311333113431135311363113731138311393114031141311423114331144311453114631147311483114931150311513115231153311543115531156311573115831159311603116131162311633116431165311663116731168311693117031171311723117331174311753117631177311783117931180311813118231183311843118531186311873118831189311903119131192311933119431195311963119731198311993120031201312023120331204312053120631207312083120931210312113121231213312143121531216312173121831219312203122131222312233122431225312263122731228312293123031231312323123331234312353123631237312383123931240312413124231243312443124531246312473124831249312503125131252312533125431255312563125731258312593126031261312623126331264312653126631267312683126931270312713127231273312743127531276312773127831279312803128131282312833128431285312863128731288312893129031291312923129331294312953129631297312983129931300313013130231303313043130531306313073130831309313103131131312313133131431315313163131731318313193132031321313223132331324313253132631327313283132931330313313133231333313343133531336313373133831339313403134131342313433134431345313463134731348313493135031351313523135331354313553135631357313583135931360313613136231363313643136531366313673136831369313703137131372313733137431375313763137731378313793138031381313823138331384313853138631387313883138931390313913139231393313943139531396313973139831399314003140131402314033140431405314063140731408314093141031411314123141331414314153141631417314183141931420314213142231423314243142531426314273142831429314303143131432314333143431435314363143731438314393144031441314423144331444314453144631447314483144931450314513145231453314543145531456314573145831459314603146131462314633146431465314663146731468314693147031471314723147331474314753147631477314783147931480314813148231483314843148531486314873148831489314903149131492314933149431495314963149731498314993150031501315023150331504315053150631507315083150931510315113151231513315143151531516315173151831519315203152131522315233152431525315263152731528315293153031531315323153331534315353153631537315383153931540315413154231543315443154531546315473154831549315503155131552315533155431555315563155731558315593156031561315623156331564315653156631567315683156931570315713157231573315743157531576315773157831579315803158131582315833158431585315863158731588315893159031591315923159331594315953159631597315983159931600316013160231603316043160531606316073160831609316103161131612316133161431615316163161731618316193162031621316223162331624316253162631627316283162931630316313163231633316343163531636316373163831639316403164131642316433164431645316463164731648316493165031651316523165331654316553165631657316583165931660316613166231663316643166531666316673166831669316703167131672316733167431675316763167731678316793168031681316823168331684316853168631687316883168931690316913169231693316943169531696316973169831699317003170131702317033170431705317063170731708317093171031711317123171331714317153171631717317183171931720317213172231723317243172531726317273172831729317303173131732317333173431735317363173731738317393174031741317423174331744317453174631747317483174931750317513175231753317543175531756317573175831759317603176131762317633176431765317663176731768317693177031771317723177331774317753177631777317783177931780317813178231783317843178531786317873178831789317903179131792317933179431795317963179731798317993180031801318023180331804318053180631807318083180931810318113181231813318143181531816318173181831819318203182131822318233182431825318263182731828318293183031831318323183331834318353183631837318383183931840318413184231843318443184531846318473184831849318503185131852318533185431855318563185731858318593186031861318623186331864318653186631867318683186931870318713187231873318743187531876318773187831879318803188131882318833188431885318863188731888318893189031891318923189331894318953189631897318983189931900319013190231903319043190531906319073190831909319103191131912319133191431915319163191731918319193192031921319223192331924319253192631927319283192931930319313193231933319343193531936319373193831939319403194131942319433194431945319463194731948319493195031951319523195331954319553195631957319583195931960319613196231963319643196531966319673196831969319703197131972319733197431975319763197731978319793198031981319823198331984319853198631987319883198931990319913199231993319943199531996319973199831999320003200132002320033200432005320063200732008320093201032011320123201332014320153201632017320183201932020320213202232023320243202532026320273202832029320303203132032320333203432035320363203732038320393204032041320423204332044320453204632047320483204932050320513205232053320543205532056320573205832059320603206132062320633206432065320663206732068320693207032071320723207332074320753207632077320783207932080320813208232083320843208532086320873208832089320903209132092320933209432095320963209732098320993210032101321023210332104321053210632107321083210932110321113211232113321143211532116321173211832119321203212132122321233212432125321263212732128321293213032131321323213332134321353213632137321383213932140321413214232143321443214532146321473214832149321503215132152321533215432155321563215732158321593216032161321623216332164321653216632167321683216932170321713217232173321743217532176321773217832179321803218132182321833218432185321863218732188321893219032191321923219332194321953219632197321983219932200322013220232203322043220532206322073220832209322103221132212322133221432215322163221732218322193222032221322223222332224322253222632227322283222932230322313223232233322343223532236322373223832239322403224132242322433224432245322463224732248322493225032251322523225332254322553225632257322583225932260322613226232263322643226532266322673226832269322703227132272322733227432275322763227732278322793228032281322823228332284322853228632287322883228932290322913229232293322943229532296322973229832299323003230132302323033230432305323063230732308323093231032311323123231332314323153231632317323183231932320323213232232323323243232532326323273232832329323303233132332323333233432335323363233732338323393234032341323423234332344323453234632347323483234932350323513235232353323543235532356323573235832359323603236132362323633236432365323663236732368323693237032371323723237332374323753237632377323783237932380323813238232383323843238532386323873238832389323903239132392323933239432395323963239732398323993240032401324023240332404324053240632407324083240932410324113241232413324143241532416324173241832419324203242132422324233242432425324263242732428324293243032431324323243332434324353243632437324383243932440324413244232443324443244532446324473244832449324503245132452324533245432455324563245732458324593246032461324623246332464324653246632467324683246932470324713247232473324743247532476324773247832479324803248132482324833248432485324863248732488324893249032491324923249332494324953249632497324983249932500325013250232503325043250532506325073250832509325103251132512325133251432515325163251732518325193252032521325223252332524325253252632527325283252932530325313253232533325343253532536325373253832539325403254132542325433254432545325463254732548325493255032551325523255332554325553255632557325583255932560325613256232563325643256532566325673256832569325703257132572325733257432575325763257732578325793258032581325823258332584325853258632587325883258932590325913259232593325943259532596325973259832599326003260132602326033260432605326063260732608326093261032611326123261332614326153261632617326183261932620326213262232623326243262532626326273262832629326303263132632326333263432635326363263732638326393264032641326423264332644326453264632647326483264932650326513265232653326543265532656326573265832659326603266132662326633266432665326663266732668326693267032671326723267332674326753267632677326783267932680326813268232683326843268532686326873268832689326903269132692326933269432695326963269732698326993270032701327023270332704327053270632707327083270932710327113271232713327143271532716327173271832719327203272132722327233272432725327263272732728327293273032731327323273332734327353273632737327383273932740327413274232743327443274532746327473274832749327503275132752327533275432755327563275732758327593276032761327623276332764327653276632767327683276932770327713277232773327743277532776327773277832779327803278132782327833278432785327863278732788327893279032791327923279332794327953279632797327983279932800328013280232803328043280532806328073280832809328103281132812328133281432815328163281732818328193282032821328223282332824328253282632827328283282932830328313283232833328343283532836328373283832839328403284132842328433284432845328463284732848328493285032851328523285332854328553285632857328583285932860328613286232863328643286532866328673286832869328703287132872328733287432875328763287732878328793288032881328823288332884328853288632887328883288932890328913289232893328943289532896328973289832899329003290132902329033290432905329063290732908329093291032911329123291332914329153291632917329183291932920329213292232923329243292532926329273292832929329303293132932329333293432935329363293732938329393294032941329423294332944329453294632947329483294932950329513295232953329543295532956329573295832959329603296132962329633296432965329663296732968329693297032971329723297332974329753297632977329783297932980329813298232983329843298532986329873298832989329903299132992329933299432995329963299732998329993300033001330023300333004330053300633007330083300933010330113301233013330143301533016330173301833019330203302133022330233302433025330263302733028330293303033031330323303333034330353303633037330383303933040330413304233043330443304533046330473304833049330503305133052330533305433055330563305733058330593306033061330623306333064330653306633067330683306933070330713307233073330743307533076330773307833079330803308133082330833308433085330863308733088330893309033091330923309333094330953309633097330983309933100331013310233103331043310533106331073310833109331103311133112331133311433115331163311733118331193312033121331223312333124331253312633127331283312933130331313313233133331343313533136331373313833139331403314133142331433314433145331463314733148331493315033151331523315333154331553315633157331583315933160331613316233163331643316533166331673316833169331703317133172331733317433175331763317733178331793318033181331823318333184331853318633187331883318933190331913319233193331943319533196331973319833199332003320133202332033320433205332063320733208332093321033211332123321333214332153321633217332183321933220332213322233223332243322533226332273322833229332303323133232332333323433235332363323733238332393324033241332423324333244332453324633247332483324933250332513325233253332543325533256332573325833259332603326133262332633326433265332663326733268332693327033271332723327333274332753327633277332783327933280332813328233283332843328533286332873328833289332903329133292332933329433295332963329733298332993330033301333023330333304333053330633307333083330933310333113331233313333143331533316333173331833319333203332133322333233332433325333263332733328333293333033331333323333333334333353333633337333383333933340333413334233343333443334533346333473334833349333503335133352333533335433355333563335733358333593336033361333623336333364333653336633367333683336933370333713337233373333743337533376333773337833379333803338133382333833338433385333863338733388333893339033391333923339333394333953339633397333983339933400334013340233403334043340533406334073340833409334103341133412334133341433415334163341733418334193342033421334223342333424334253342633427334283342933430334313343233433334343343533436334373343833439334403344133442334433344433445334463344733448334493345033451334523345333454334553345633457334583345933460334613346233463334643346533466334673346833469334703347133472334733347433475334763347733478334793348033481334823348333484334853348633487334883348933490334913349233493334943349533496334973349833499335003350133502335033350433505335063350733508335093351033511335123351333514335153351633517335183351933520335213352233523335243352533526335273352833529335303353133532335333353433535335363353733538335393354033541335423354333544335453354633547335483354933550335513355233553335543355533556335573355833559335603356133562335633356433565335663356733568335693357033571335723357333574335753357633577335783357933580335813358233583335843358533586335873358833589335903359133592335933359433595335963359733598335993360033601336023360333604336053360633607336083360933610336113361233613336143361533616336173361833619336203362133622336233362433625336263362733628336293363033631336323363333634336353363633637336383363933640336413364233643336443364533646336473364833649336503365133652336533365433655336563365733658336593366033661336623366333664336653366633667336683366933670336713367233673336743367533676336773367833679336803368133682336833368433685336863368733688336893369033691336923369333694336953369633697336983369933700337013370233703337043370533706337073370833709337103371133712337133371433715337163371733718337193372033721337223372333724337253372633727337283372933730337313373233733337343373533736337373373833739337403374133742337433374433745337463374733748337493375033751337523375333754337553375633757337583375933760337613376233763337643376533766337673376833769337703377133772337733377433775337763377733778337793378033781337823378333784337853378633787337883378933790337913379233793337943379533796337973379833799338003380133802338033380433805338063380733808338093381033811338123381333814338153381633817338183381933820338213382233823338243382533826338273382833829338303383133832338333383433835338363383733838338393384033841338423384333844338453384633847338483384933850338513385233853338543385533856338573385833859338603386133862338633386433865338663386733868338693387033871338723387333874338753387633877338783387933880338813388233883338843388533886338873388833889338903389133892338933389433895338963389733898338993390033901339023390333904339053390633907339083390933910339113391233913339143391533916339173391833919339203392133922339233392433925339263392733928339293393033931339323393333934339353393633937339383393933940339413394233943339443394533946339473394833949339503395133952339533395433955339563395733958339593396033961339623396333964339653396633967339683396933970339713397233973339743397533976339773397833979339803398133982339833398433985339863398733988339893399033991339923399333994339953399633997339983399934000340013400234003340043400534006340073400834009340103401134012340133401434015340163401734018340193402034021340223402334024340253402634027340283402934030340313403234033340343403534036340373403834039340403404134042340433404434045340463404734048340493405034051340523405334054340553405634057340583405934060340613406234063340643406534066340673406834069340703407134072340733407434075340763407734078340793408034081340823408334084340853408634087340883408934090340913409234093340943409534096340973409834099341003410134102341033410434105341063410734108341093411034111341123411334114341153411634117341183411934120341213412234123341243412534126341273412834129341303413134132341333413434135341363413734138341393414034141341423414334144341453414634147341483414934150341513415234153341543415534156341573415834159341603416134162341633416434165341663416734168341693417034171341723417334174341753417634177341783417934180341813418234183341843418534186341873418834189341903419134192341933419434195341963419734198341993420034201342023420334204342053420634207342083420934210342113421234213342143421534216342173421834219342203422134222342233422434225342263422734228342293423034231342323423334234342353423634237342383423934240342413424234243342443424534246342473424834249342503425134252342533425434255342563425734258342593426034261342623426334264342653426634267342683426934270342713427234273342743427534276342773427834279342803428134282342833428434285342863428734288342893429034291342923429334294342953429634297342983429934300343013430234303343043430534306343073430834309343103431134312343133431434315343163431734318343193432034321343223432334324343253432634327343283432934330343313433234333343343433534336343373433834339343403434134342343433434434345343463434734348343493435034351343523435334354343553435634357343583435934360343613436234363343643436534366343673436834369343703437134372343733437434375343763437734378343793438034381343823438334384343853438634387343883438934390343913439234393343943439534396343973439834399344003440134402344033440434405344063440734408344093441034411344123441334414344153441634417344183441934420344213442234423344243442534426344273442834429344303443134432344333443434435344363443734438344393444034441344423444334444344453444634447344483444934450344513445234453344543445534456344573445834459344603446134462344633446434465344663446734468344693447034471344723447334474344753447634477344783447934480344813448234483344843448534486344873448834489344903449134492344933449434495344963449734498344993450034501345023450334504345053450634507345083450934510345113451234513345143451534516345173451834519345203452134522345233452434525345263452734528345293453034531345323453334534345353453634537345383453934540345413454234543345443454534546345473454834549345503455134552345533455434555345563455734558345593456034561345623456334564345653456634567345683456934570345713457234573345743457534576345773457834579345803458134582345833458434585345863458734588345893459034591345923459334594345953459634597345983459934600346013460234603346043460534606346073460834609346103461134612346133461434615346163461734618346193462034621346223462334624346253462634627346283462934630346313463234633346343463534636346373463834639346403464134642346433464434645346463464734648346493465034651346523465334654346553465634657346583465934660346613466234663346643466534666346673466834669346703467134672346733467434675346763467734678346793468034681346823468334684346853468634687346883468934690346913469234693346943469534696346973469834699347003470134702347033470434705347063470734708347093471034711347123471334714347153471634717347183471934720347213472234723347243472534726347273472834729347303473134732347333473434735347363473734738347393474034741347423474334744347453474634747347483474934750347513475234753347543475534756347573475834759347603476134762347633476434765347663476734768347693477034771347723477334774347753477634777347783477934780347813478234783347843478534786347873478834789347903479134792347933479434795347963479734798347993480034801348023480334804348053480634807348083480934810348113481234813348143481534816348173481834819348203482134822348233482434825348263482734828348293483034831348323483334834348353483634837348383483934840348413484234843348443484534846348473484834849348503485134852348533485434855348563485734858348593486034861348623486334864348653486634867348683486934870348713487234873348743487534876348773487834879348803488134882348833488434885348863488734888348893489034891348923489334894348953489634897348983489934900349013490234903349043490534906349073490834909349103491134912349133491434915349163491734918349193492034921349223492334924349253492634927349283492934930349313493234933349343493534936349373493834939349403494134942349433494434945349463494734948349493495034951349523495334954349553495634957349583495934960349613496234963349643496534966349673496834969349703497134972349733497434975349763497734978349793498034981349823498334984349853498634987349883498934990349913499234993349943499534996349973499834999350003500135002350033500435005350063500735008350093501035011350123501335014350153501635017350183501935020350213502235023350243502535026350273502835029350303503135032350333503435035350363503735038350393504035041350423504335044350453504635047350483504935050350513505235053350543505535056350573505835059350603506135062350633506435065350663506735068350693507035071350723507335074350753507635077350783507935080350813508235083350843508535086350873508835089350903509135092350933509435095350963509735098350993510035101351023510335104351053510635107351083510935110351113511235113351143511535116351173511835119351203512135122351233512435125351263512735128351293513035131351323513335134351353513635137351383513935140351413514235143351443514535146351473514835149351503515135152351533515435155351563515735158351593516035161351623516335164351653516635167351683516935170351713517235173351743517535176351773517835179351803518135182351833518435185351863518735188351893519035191351923519335194351953519635197351983519935200352013520235203352043520535206352073520835209352103521135212352133521435215352163521735218352193522035221352223522335224352253522635227352283522935230352313523235233352343523535236352373523835239352403524135242352433524435245352463524735248352493525035251352523525335254352553525635257352583525935260352613526235263352643526535266352673526835269352703527135272352733527435275352763527735278352793528035281352823528335284352853528635287352883528935290352913529235293352943529535296352973529835299353003530135302353033530435305353063530735308353093531035311353123531335314353153531635317353183531935320353213532235323353243532535326353273532835329353303533135332353333533435335353363533735338353393534035341353423534335344353453534635347353483534935350353513535235353353543535535356353573535835359353603536135362353633536435365353663536735368353693537035371353723537335374353753537635377353783537935380353813538235383353843538535386353873538835389353903539135392353933539435395353963539735398353993540035401354023540335404354053540635407354083540935410354113541235413354143541535416354173541835419354203542135422354233542435425354263542735428354293543035431354323543335434354353543635437354383543935440354413544235443354443544535446354473544835449354503545135452354533545435455354563545735458354593546035461354623546335464354653546635467354683546935470354713547235473354743547535476354773547835479354803548135482354833548435485354863548735488354893549035491354923549335494354953549635497354983549935500355013550235503355043550535506355073550835509355103551135512355133551435515355163551735518355193552035521355223552335524355253552635527355283552935530355313553235533355343553535536355373553835539355403554135542355433554435545355463554735548355493555035551355523555335554355553555635557355583555935560355613556235563355643556535566355673556835569355703557135572355733557435575355763557735578355793558035581355823558335584355853558635587355883558935590355913559235593355943559535596355973559835599356003560135602356033560435605356063560735608356093561035611356123561335614356153561635617356183561935620356213562235623356243562535626356273562835629356303563135632356333563435635356363563735638356393564035641356423564335644356453564635647356483564935650356513565235653356543565535656356573565835659356603566135662356633566435665356663566735668356693567035671356723567335674356753567635677356783567935680356813568235683356843568535686356873568835689356903569135692356933569435695356963569735698356993570035701357023570335704357053570635707357083570935710357113571235713357143571535716357173571835719357203572135722357233572435725357263572735728357293573035731357323573335734357353573635737357383573935740357413574235743357443574535746357473574835749357503575135752357533575435755357563575735758357593576035761357623576335764357653576635767357683576935770357713577235773357743577535776357773577835779357803578135782357833578435785357863578735788357893579035791357923579335794357953579635797357983579935800358013580235803358043580535806358073580835809358103581135812358133581435815358163581735818358193582035821358223582335824358253582635827358283582935830358313583235833358343583535836358373583835839358403584135842358433584435845358463584735848358493585035851358523585335854358553585635857358583585935860358613586235863358643586535866358673586835869358703587135872358733587435875358763587735878358793588035881358823588335884358853588635887358883588935890358913589235893358943589535896358973589835899359003590135902359033590435905359063590735908359093591035911359123591335914359153591635917359183591935920359213592235923359243592535926359273592835929359303593135932359333593435935359363593735938359393594035941359423594335944359453594635947359483594935950359513595235953359543595535956359573595835959359603596135962359633596435965359663596735968359693597035971359723597335974359753597635977359783597935980359813598235983359843598535986359873598835989359903599135992359933599435995359963599735998359993600036001360023600336004360053600636007360083600936010360113601236013360143601536016360173601836019360203602136022360233602436025360263602736028360293603036031360323603336034360353603636037360383603936040360413604236043360443604536046360473604836049360503605136052360533605436055360563605736058360593606036061360623606336064360653606636067360683606936070360713607236073360743607536076360773607836079360803608136082360833608436085360863608736088360893609036091360923609336094360953609636097360983609936100361013610236103361043610536106361073610836109361103611136112361133611436115361163611736118361193612036121361223612336124361253612636127361283612936130361313613236133361343613536136361373613836139361403614136142361433614436145361463614736148361493615036151361523615336154361553615636157361583615936160361613616236163361643616536166361673616836169361703617136172361733617436175361763617736178361793618036181361823618336184361853618636187361883618936190361913619236193361943619536196361973619836199362003620136202362033620436205362063620736208362093621036211362123621336214362153621636217362183621936220362213622236223362243622536226362273622836229362303623136232362333623436235362363623736238362393624036241362423624336244362453624636247362483624936250362513625236253362543625536256362573625836259362603626136262362633626436265362663626736268362693627036271362723627336274362753627636277362783627936280362813628236283362843628536286362873628836289362903629136292362933629436295362963629736298362993630036301363023630336304363053630636307363083630936310363113631236313363143631536316363173631836319363203632136322363233632436325363263632736328363293633036331363323633336334363353633636337363383633936340363413634236343363443634536346363473634836349363503635136352363533635436355363563635736358363593636036361363623636336364363653636636367363683636936370363713637236373363743637536376363773637836379363803638136382363833638436385363863638736388363893639036391363923639336394363953639636397363983639936400364013640236403364043640536406364073640836409364103641136412364133641436415364163641736418364193642036421364223642336424364253642636427364283642936430364313643236433364343643536436364373643836439364403644136442364433644436445364463644736448364493645036451364523645336454364553645636457364583645936460364613646236463364643646536466364673646836469364703647136472364733647436475364763647736478364793648036481364823648336484364853648636487364883648936490364913649236493364943649536496364973649836499365003650136502365033650436505365063650736508365093651036511365123651336514365153651636517365183651936520365213652236523365243652536526365273652836529365303653136532365333653436535365363653736538365393654036541365423654336544365453654636547365483654936550365513655236553365543655536556365573655836559365603656136562365633656436565365663656736568365693657036571365723657336574365753657636577365783657936580365813658236583365843658536586365873658836589365903659136592365933659436595365963659736598365993660036601366023660336604366053660636607366083660936610366113661236613366143661536616366173661836619366203662136622366233662436625366263662736628366293663036631366323663336634366353663636637366383663936640366413664236643366443664536646366473664836649366503665136652366533665436655366563665736658366593666036661366623666336664366653666636667366683666936670366713667236673366743667536676366773667836679366803668136682366833668436685366863668736688366893669036691366923669336694366953669636697366983669936700367013670236703367043670536706367073670836709367103671136712367133671436715367163671736718367193672036721367223672336724367253672636727367283672936730367313673236733367343673536736367373673836739367403674136742367433674436745367463674736748367493675036751367523675336754367553675636757367583675936760367613676236763367643676536766367673676836769367703677136772367733677436775367763677736778367793678036781367823678336784367853678636787367883678936790367913679236793367943679536796367973679836799368003680136802368033680436805368063680736808368093681036811368123681336814368153681636817368183681936820368213682236823368243682536826368273682836829368303683136832368333683436835368363683736838368393684036841368423684336844368453684636847368483684936850368513685236853368543685536856368573685836859368603686136862368633686436865368663686736868368693687036871368723687336874368753687636877368783687936880368813688236883368843688536886368873688836889368903689136892368933689436895368963689736898368993690036901369023690336904369053690636907369083690936910369113691236913369143691536916369173691836919369203692136922369233692436925369263692736928369293693036931369323693336934369353693636937369383693936940369413694236943369443694536946369473694836949369503695136952369533695436955369563695736958369593696036961369623696336964369653696636967369683696936970369713697236973369743697536976369773697836979369803698136982369833698436985369863698736988369893699036991369923699336994369953699636997369983699937000370013700237003370043700537006370073700837009370103701137012370133701437015370163701737018370193702037021370223702337024370253702637027370283702937030370313703237033370343703537036370373703837039370403704137042370433704437045370463704737048370493705037051370523705337054370553705637057370583705937060370613706237063370643706537066370673706837069370703707137072370733707437075370763707737078370793708037081370823708337084370853708637087370883708937090370913709237093370943709537096370973709837099371003710137102371033710437105371063710737108371093711037111371123711337114371153711637117371183711937120371213712237123371243712537126371273712837129371303713137132371333713437135371363713737138371393714037141371423714337144371453714637147371483714937150371513715237153371543715537156371573715837159371603716137162371633716437165371663716737168371693717037171371723717337174371753717637177371783717937180371813718237183371843718537186371873718837189371903719137192371933719437195371963719737198371993720037201372023720337204372053720637207372083720937210372113721237213372143721537216372173721837219372203722137222372233722437225372263722737228372293723037231372323723337234372353723637237372383723937240372413724237243372443724537246372473724837249372503725137252372533725437255372563725737258372593726037261372623726337264372653726637267372683726937270372713727237273372743727537276372773727837279372803728137282372833728437285372863728737288372893729037291372923729337294372953729637297372983729937300373013730237303373043730537306373073730837309373103731137312373133731437315373163731737318373193732037321373223732337324373253732637327373283732937330373313733237333373343733537336373373733837339373403734137342373433734437345373463734737348373493735037351373523735337354373553735637357373583735937360373613736237363373643736537366373673736837369373703737137372373733737437375373763737737378373793738037381373823738337384373853738637387373883738937390373913739237393373943739537396373973739837399374003740137402374033740437405374063740737408374093741037411374123741337414374153741637417374183741937420374213742237423374243742537426374273742837429374303743137432374333743437435374363743737438374393744037441374423744337444374453744637447374483744937450374513745237453374543745537456374573745837459374603746137462374633746437465374663746737468374693747037471374723747337474374753747637477374783747937480374813748237483374843748537486374873748837489374903749137492374933749437495374963749737498374993750037501375023750337504375053750637507375083750937510375113751237513375143751537516375173751837519375203752137522375233752437525375263752737528375293753037531375323753337534375353753637537375383753937540375413754237543375443754537546375473754837549375503755137552375533755437555375563755737558375593756037561375623756337564375653756637567375683756937570375713757237573375743757537576375773757837579375803758137582375833758437585375863758737588375893759037591375923759337594375953759637597375983759937600376013760237603376043760537606376073760837609376103761137612376133761437615376163761737618376193762037621376223762337624376253762637627376283762937630376313763237633376343763537636376373763837639376403764137642376433764437645376463764737648376493765037651376523765337654376553765637657376583765937660376613766237663376643766537666376673766837669376703767137672376733767437675376763767737678376793768037681376823768337684376853768637687376883768937690376913769237693376943769537696376973769837699377003770137702377033770437705377063770737708377093771037711377123771337714377153771637717377183771937720377213772237723377243772537726377273772837729377303773137732377333773437735377363773737738377393774037741377423774337744377453774637747377483774937750377513775237753377543775537756377573775837759377603776137762377633776437765377663776737768377693777037771377723777337774377753777637777377783777937780377813778237783377843778537786377873778837789377903779137792377933779437795377963779737798377993780037801378023780337804378053780637807378083780937810378113781237813378143781537816378173781837819378203782137822378233782437825378263782737828378293783037831378323783337834378353783637837378383783937840378413784237843378443784537846378473784837849378503785137852378533785437855378563785737858378593786037861378623786337864378653786637867378683786937870378713787237873378743787537876378773787837879378803788137882378833788437885378863788737888378893789037891378923789337894378953789637897378983789937900379013790237903379043790537906379073790837909379103791137912379133791437915379163791737918379193792037921379223792337924379253792637927379283792937930379313793237933379343793537936379373793837939379403794137942379433794437945379463794737948379493795037951379523795337954379553795637957379583795937960379613796237963379643796537966379673796837969379703797137972379733797437975379763797737978379793798037981379823798337984379853798637987379883798937990379913799237993379943799537996379973799837999380003800138002380033800438005380063800738008380093801038011380123801338014380153801638017380183801938020380213802238023380243802538026380273802838029380303803138032380333803438035380363803738038380393804038041380423804338044380453804638047380483804938050380513805238053380543805538056380573805838059380603806138062380633806438065380663806738068380693807038071380723807338074380753807638077380783807938080380813808238083380843808538086380873808838089380903809138092380933809438095380963809738098380993810038101381023810338104381053810638107381083810938110381113811238113381143811538116381173811838119381203812138122381233812438125381263812738128381293813038131381323813338134381353813638137381383813938140381413814238143381443814538146381473814838149381503815138152381533815438155381563815738158381593816038161381623816338164381653816638167381683816938170381713817238173381743817538176381773817838179381803818138182381833818438185381863818738188381893819038191381923819338194381953819638197381983819938200382013820238203382043820538206382073820838209382103821138212382133821438215382163821738218382193822038221382223822338224382253822638227382283822938230382313823238233382343823538236382373823838239382403824138242382433824438245382463824738248382493825038251382523825338254382553825638257382583825938260382613826238263382643826538266382673826838269382703827138272382733827438275382763827738278382793828038281382823828338284382853828638287382883828938290382913829238293382943829538296382973829838299383003830138302383033830438305383063830738308383093831038311383123831338314383153831638317383183831938320383213832238323383243832538326383273832838329383303833138332383333833438335383363833738338383393834038341383423834338344383453834638347383483834938350383513835238353383543835538356383573835838359383603836138362383633836438365383663836738368383693837038371383723837338374383753837638377383783837938380383813838238383383843838538386383873838838389383903839138392383933839438395383963839738398383993840038401384023840338404384053840638407384083840938410384113841238413384143841538416384173841838419384203842138422384233842438425384263842738428384293843038431384323843338434384353843638437384383843938440384413844238443384443844538446384473844838449384503845138452384533845438455384563845738458384593846038461384623846338464384653846638467384683846938470384713847238473384743847538476384773847838479384803848138482384833848438485384863848738488384893849038491384923849338494384953849638497384983849938500385013850238503385043850538506385073850838509385103851138512385133851438515385163851738518385193852038521385223852338524385253852638527385283852938530385313853238533385343853538536385373853838539385403854138542385433854438545385463854738548385493855038551385523855338554385553855638557385583855938560385613856238563385643856538566385673856838569385703857138572385733857438575385763857738578385793858038581385823858338584385853858638587385883858938590385913859238593385943859538596385973859838599386003860138602386033860438605386063860738608386093861038611386123861338614386153861638617386183861938620386213862238623386243862538626386273862838629386303863138632386333863438635386363863738638386393864038641386423864338644386453864638647386483864938650386513865238653386543865538656386573865838659386603866138662386633866438665386663866738668386693867038671386723867338674386753867638677386783867938680386813868238683386843868538686386873868838689386903869138692386933869438695386963869738698386993870038701387023870338704387053870638707387083870938710387113871238713387143871538716387173871838719387203872138722387233872438725387263872738728387293873038731387323873338734387353873638737387383873938740387413874238743387443874538746387473874838749387503875138752387533875438755387563875738758387593876038761387623876338764387653876638767387683876938770387713877238773387743877538776387773877838779387803878138782387833878438785387863878738788387893879038791387923879338794387953879638797387983879938800388013880238803388043880538806388073880838809388103881138812388133881438815388163881738818388193882038821388223882338824388253882638827388283882938830388313883238833388343883538836388373883838839388403884138842388433884438845388463884738848388493885038851388523885338854388553885638857388583885938860388613886238863388643886538866388673886838869388703887138872388733887438875388763887738878388793888038881388823888338884388853888638887388883888938890388913889238893388943889538896388973889838899389003890138902389033890438905389063890738908389093891038911389123891338914389153891638917389183891938920389213892238923389243892538926389273892838929389303893138932389333893438935389363893738938389393894038941389423894338944389453894638947389483894938950389513895238953389543895538956389573895838959389603896138962389633896438965389663896738968389693897038971389723897338974389753897638977389783897938980389813898238983389843898538986389873898838989389903899138992389933899438995389963899738998389993900039001390023900339004390053900639007390083900939010390113901239013390143901539016390173901839019390203902139022390233902439025390263902739028390293903039031390323903339034390353903639037390383903939040390413904239043390443904539046390473904839049390503905139052390533905439055390563905739058390593906039061390623906339064390653906639067390683906939070390713907239073390743907539076390773907839079390803908139082390833908439085390863908739088390893909039091390923909339094390953909639097390983909939100391013910239103391043910539106391073910839109391103911139112391133911439115391163911739118391193912039121391223912339124391253912639127391283912939130391313913239133391343913539136391373913839139391403914139142391433914439145391463914739148391493915039151391523915339154391553915639157391583915939160391613916239163391643916539166391673916839169391703917139172391733917439175391763917739178391793918039181391823918339184391853918639187391883918939190391913919239193391943919539196391973919839199392003920139202392033920439205392063920739208392093921039211392123921339214392153921639217392183921939220392213922239223392243922539226392273922839229392303923139232392333923439235392363923739238392393924039241392423924339244392453924639247392483924939250392513925239253392543925539256392573925839259392603926139262392633926439265392663926739268392693927039271392723927339274392753927639277392783927939280392813928239283392843928539286392873928839289392903929139292392933929439295392963929739298392993930039301393023930339304393053930639307393083930939310393113931239313393143931539316393173931839319393203932139322393233932439325393263932739328393293933039331393323933339334393353933639337393383933939340393413934239343393443934539346393473934839349393503935139352393533935439355393563935739358393593936039361393623936339364393653936639367393683936939370393713937239373393743937539376393773937839379393803938139382393833938439385393863938739388393893939039391393923939339394393953939639397393983939939400394013940239403394043940539406394073940839409394103941139412394133941439415394163941739418394193942039421394223942339424394253942639427394283942939430394313943239433394343943539436394373943839439394403944139442394433944439445394463944739448394493945039451394523945339454394553945639457394583945939460394613946239463394643946539466394673946839469394703947139472394733947439475394763947739478394793948039481394823948339484394853948639487394883948939490394913949239493394943949539496394973949839499395003950139502395033950439505395063950739508395093951039511395123951339514395153951639517395183951939520395213952239523395243952539526395273952839529395303953139532395333953439535395363953739538395393954039541395423954339544395453954639547395483954939550395513955239553395543955539556395573955839559395603956139562395633956439565395663956739568395693957039571395723957339574395753957639577395783957939580395813958239583395843958539586395873958839589395903959139592395933959439595395963959739598395993960039601396023960339604396053960639607396083960939610396113961239613396143961539616396173961839619396203962139622396233962439625396263962739628396293963039631396323963339634396353963639637396383963939640396413964239643396443964539646396473964839649396503965139652396533965439655396563965739658396593966039661396623966339664396653966639667396683966939670396713967239673396743967539676396773967839679396803968139682396833968439685396863968739688396893969039691396923969339694396953969639697396983969939700397013970239703397043970539706397073970839709397103971139712397133971439715397163971739718397193972039721397223972339724397253972639727397283972939730397313973239733397343973539736397373973839739397403974139742397433974439745397463974739748397493975039751397523975339754397553975639757397583975939760397613976239763397643976539766397673976839769397703977139772397733977439775397763977739778397793978039781397823978339784397853978639787397883978939790397913979239793397943979539796397973979839799398003980139802398033980439805398063980739808398093981039811398123981339814398153981639817398183981939820398213982239823398243982539826398273982839829398303983139832398333983439835398363983739838398393984039841398423984339844398453984639847398483984939850398513985239853398543985539856398573985839859398603986139862398633986439865398663986739868398693987039871398723987339874398753987639877398783987939880398813988239883398843988539886398873988839889398903989139892398933989439895398963989739898398993990039901399023990339904399053990639907399083990939910399113991239913399143991539916399173991839919399203992139922399233992439925399263992739928399293993039931399323993339934399353993639937399383993939940399413994239943399443994539946399473994839949399503995139952399533995439955399563995739958399593996039961399623996339964399653996639967399683996939970399713997239973399743997539976399773997839979399803998139982399833998439985399863998739988399893999039991399923999339994399953999639997399983999940000400014000240003400044000540006400074000840009400104001140012400134001440015400164001740018400194002040021400224002340024400254002640027400284002940030400314003240033400344003540036400374003840039400404004140042400434004440045400464004740048400494005040051400524005340054400554005640057400584005940060400614006240063400644006540066400674006840069400704007140072400734007440075400764007740078400794008040081400824008340084400854008640087400884008940090400914009240093400944009540096400974009840099401004010140102401034010440105401064010740108401094011040111401124011340114401154011640117401184011940120401214012240123401244012540126401274012840129401304013140132401334013440135401364013740138401394014040141401424014340144401454014640147401484014940150401514015240153401544015540156401574015840159401604016140162401634016440165401664016740168401694017040171401724017340174401754017640177401784017940180401814018240183401844018540186401874018840189401904019140192401934019440195401964019740198401994020040201402024020340204402054020640207402084020940210402114021240213402144021540216402174021840219402204022140222402234022440225402264022740228402294023040231402324023340234402354023640237402384023940240402414024240243402444024540246402474024840249402504025140252402534025440255402564025740258402594026040261402624026340264402654026640267402684026940270402714027240273402744027540276402774027840279402804028140282402834028440285402864028740288402894029040291402924029340294402954029640297402984029940300403014030240303403044030540306403074030840309403104031140312403134031440315403164031740318403194032040321403224032340324403254032640327403284032940330403314033240333403344033540336403374033840339403404034140342403434034440345403464034740348403494035040351403524035340354403554035640357403584035940360403614036240363403644036540366403674036840369403704037140372403734037440375403764037740378403794038040381403824038340384403854038640387403884038940390403914039240393403944039540396403974039840399404004040140402404034040440405404064040740408404094041040411404124041340414404154041640417404184041940420404214042240423404244042540426404274042840429404304043140432404334043440435404364043740438404394044040441404424044340444404454044640447404484044940450404514045240453404544045540456404574045840459404604046140462404634046440465404664046740468404694047040471404724047340474404754047640477404784047940480404814048240483404844048540486404874048840489404904049140492404934049440495404964049740498404994050040501405024050340504405054050640507405084050940510405114051240513405144051540516405174051840519405204052140522405234052440525405264052740528405294053040531405324053340534405354053640537405384053940540405414054240543405444054540546405474054840549405504055140552405534055440555405564055740558405594056040561405624056340564405654056640567405684056940570405714057240573405744057540576405774057840579405804058140582405834058440585405864058740588405894059040591405924059340594405954059640597405984059940600406014060240603406044060540606406074060840609406104061140612406134061440615406164061740618406194062040621406224062340624406254062640627406284062940630406314063240633406344063540636406374063840639406404064140642406434064440645406464064740648406494065040651406524065340654406554065640657406584065940660406614066240663406644066540666406674066840669406704067140672406734067440675406764067740678406794068040681406824068340684406854068640687406884068940690406914069240693406944069540696406974069840699407004070140702407034070440705407064070740708407094071040711407124071340714407154071640717407184071940720407214072240723407244072540726407274072840729407304073140732407334073440735407364073740738407394074040741
  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. });