utils.js 132 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259
  1. /*!
  2. * @pixi/utils - v6.5.10
  3. * Compiled Thu, 06 Jul 2023 15:25:11 UTC
  4. *
  5. * @pixi/utils is licensed under the MIT License.
  6. * http://www.opensource.org/licenses/mit-license
  7. */
  8. this.PIXI = this.PIXI || {};
  9. this.PIXI.utils = this.PIXI.utils || {};
  10. var _pixi_utils = (function (exports, settings, constants) {
  11. 'use strict';
  12. var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
  13. function getDefaultExportFromCjs (x) {
  14. return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
  15. }
  16. function createCommonjsModule(fn, basedir, module) {
  17. return module = {
  18. path: basedir,
  19. exports: {},
  20. require: function (path, base) {
  21. return commonjsRequire(path, (base === undefined || base === null) ? module.path : base);
  22. }
  23. }, fn(module, module.exports), module.exports;
  24. }
  25. function getDefaultExportFromNamespaceIfPresent (n) {
  26. return n && Object.prototype.hasOwnProperty.call(n, 'default') ? n['default'] : n;
  27. }
  28. function getDefaultExportFromNamespaceIfNotNamed (n) {
  29. return n && Object.prototype.hasOwnProperty.call(n, 'default') && Object.keys(n).length === 1 ? n['default'] : n;
  30. }
  31. function getAugmentedNamespace(n) {
  32. if (n.__esModule) return n;
  33. var a = Object.defineProperty({}, '__esModule', {value: true});
  34. Object.keys(n).forEach(function (k) {
  35. var d = Object.getOwnPropertyDescriptor(n, k);
  36. Object.defineProperty(a, k, d.get ? d : {
  37. enumerable: true,
  38. get: function () {
  39. return n[k];
  40. }
  41. });
  42. });
  43. return a;
  44. }
  45. function commonjsRequire () {
  46. throw new Error('Dynamic requires are not currently supported by @rollup/plugin-commonjs');
  47. }
  48. var eventemitter3 = createCommonjsModule(function (module) {
  49. 'use strict';
  50. var has = Object.prototype.hasOwnProperty
  51. , prefix = '~';
  52. /**
  53. * Constructor to create a storage for our `EE` objects.
  54. * An `Events` instance is a plain object whose properties are event names.
  55. *
  56. * @constructor
  57. * @private
  58. */
  59. function Events() {}
  60. //
  61. // We try to not inherit from `Object.prototype`. In some engines creating an
  62. // instance in this way is faster than calling `Object.create(null)` directly.
  63. // If `Object.create(null)` is not supported we prefix the event names with a
  64. // character to make sure that the built-in object properties are not
  65. // overridden or used as an attack vector.
  66. //
  67. if (Object.create) {
  68. Events.prototype = Object.create(null);
  69. //
  70. // This hack is needed because the `__proto__` property is still inherited in
  71. // some old browsers like Android 4, iPhone 5.1, Opera 11 and Safari 5.
  72. //
  73. if (!new Events().__proto__) { prefix = false; }
  74. }
  75. /**
  76. * Representation of a single event listener.
  77. *
  78. * @param {Function} fn The listener function.
  79. * @param {*} context The context to invoke the listener with.
  80. * @param {Boolean} [once=false] Specify if the listener is a one-time listener.
  81. * @constructor
  82. * @private
  83. */
  84. function EE(fn, context, once) {
  85. this.fn = fn;
  86. this.context = context;
  87. this.once = once || false;
  88. }
  89. /**
  90. * Add a listener for a given event.
  91. *
  92. * @param {EventEmitter} emitter Reference to the `EventEmitter` instance.
  93. * @param {(String|Symbol)} event The event name.
  94. * @param {Function} fn The listener function.
  95. * @param {*} context The context to invoke the listener with.
  96. * @param {Boolean} once Specify if the listener is a one-time listener.
  97. * @returns {EventEmitter}
  98. * @private
  99. */
  100. function addListener(emitter, event, fn, context, once) {
  101. if (typeof fn !== 'function') {
  102. throw new TypeError('The listener must be a function');
  103. }
  104. var listener = new EE(fn, context || emitter, once)
  105. , evt = prefix ? prefix + event : event;
  106. if (!emitter._events[evt]) { emitter._events[evt] = listener, emitter._eventsCount++; }
  107. else if (!emitter._events[evt].fn) { emitter._events[evt].push(listener); }
  108. else { emitter._events[evt] = [emitter._events[evt], listener]; }
  109. return emitter;
  110. }
  111. /**
  112. * Clear event by name.
  113. *
  114. * @param {EventEmitter} emitter Reference to the `EventEmitter` instance.
  115. * @param {(String|Symbol)} evt The Event name.
  116. * @private
  117. */
  118. function clearEvent(emitter, evt) {
  119. if (--emitter._eventsCount === 0) { emitter._events = new Events(); }
  120. else { delete emitter._events[evt]; }
  121. }
  122. /**
  123. * Minimal `EventEmitter` interface that is molded against the Node.js
  124. * `EventEmitter` interface.
  125. *
  126. * @constructor
  127. * @public
  128. */
  129. function EventEmitter() {
  130. this._events = new Events();
  131. this._eventsCount = 0;
  132. }
  133. /**
  134. * Return an array listing the events for which the emitter has registered
  135. * listeners.
  136. *
  137. * @returns {Array}
  138. * @public
  139. */
  140. EventEmitter.prototype.eventNames = function eventNames() {
  141. var names = []
  142. , events
  143. , name;
  144. if (this._eventsCount === 0) { return names; }
  145. for (name in (events = this._events)) {
  146. if (has.call(events, name)) { names.push(prefix ? name.slice(1) : name); }
  147. }
  148. if (Object.getOwnPropertySymbols) {
  149. return names.concat(Object.getOwnPropertySymbols(events));
  150. }
  151. return names;
  152. };
  153. /**
  154. * Return the listeners registered for a given event.
  155. *
  156. * @param {(String|Symbol)} event The event name.
  157. * @returns {Array} The registered listeners.
  158. * @public
  159. */
  160. EventEmitter.prototype.listeners = function listeners(event) {
  161. var evt = prefix ? prefix + event : event
  162. , handlers = this._events[evt];
  163. if (!handlers) { return []; }
  164. if (handlers.fn) { return [handlers.fn]; }
  165. for (var i = 0, l = handlers.length, ee = new Array(l); i < l; i++) {
  166. ee[i] = handlers[i].fn;
  167. }
  168. return ee;
  169. };
  170. /**
  171. * Return the number of listeners listening to a given event.
  172. *
  173. * @param {(String|Symbol)} event The event name.
  174. * @returns {Number} The number of listeners.
  175. * @public
  176. */
  177. EventEmitter.prototype.listenerCount = function listenerCount(event) {
  178. var evt = prefix ? prefix + event : event
  179. , listeners = this._events[evt];
  180. if (!listeners) { return 0; }
  181. if (listeners.fn) { return 1; }
  182. return listeners.length;
  183. };
  184. /**
  185. * Calls each of the listeners registered for a given event.
  186. *
  187. * @param {(String|Symbol)} event The event name.
  188. * @returns {Boolean} `true` if the event had listeners, else `false`.
  189. * @public
  190. */
  191. EventEmitter.prototype.emit = function emit(event, a1, a2, a3, a4, a5) {
  192. var arguments$1 = arguments;
  193. var evt = prefix ? prefix + event : event;
  194. if (!this._events[evt]) { return false; }
  195. var listeners = this._events[evt]
  196. , len = arguments.length
  197. , args
  198. , i;
  199. if (listeners.fn) {
  200. if (listeners.once) { this.removeListener(event, listeners.fn, undefined, true); }
  201. switch (len) {
  202. case 1: return listeners.fn.call(listeners.context), true;
  203. case 2: return listeners.fn.call(listeners.context, a1), true;
  204. case 3: return listeners.fn.call(listeners.context, a1, a2), true;
  205. case 4: return listeners.fn.call(listeners.context, a1, a2, a3), true;
  206. case 5: return listeners.fn.call(listeners.context, a1, a2, a3, a4), true;
  207. case 6: return listeners.fn.call(listeners.context, a1, a2, a3, a4, a5), true;
  208. }
  209. for (i = 1, args = new Array(len -1); i < len; i++) {
  210. args[i - 1] = arguments$1[i];
  211. }
  212. listeners.fn.apply(listeners.context, args);
  213. } else {
  214. var length = listeners.length
  215. , j;
  216. for (i = 0; i < length; i++) {
  217. if (listeners[i].once) { this.removeListener(event, listeners[i].fn, undefined, true); }
  218. switch (len) {
  219. case 1: listeners[i].fn.call(listeners[i].context); break;
  220. case 2: listeners[i].fn.call(listeners[i].context, a1); break;
  221. case 3: listeners[i].fn.call(listeners[i].context, a1, a2); break;
  222. case 4: listeners[i].fn.call(listeners[i].context, a1, a2, a3); break;
  223. default:
  224. if (!args) { for (j = 1, args = new Array(len -1); j < len; j++) {
  225. args[j - 1] = arguments$1[j];
  226. } }
  227. listeners[i].fn.apply(listeners[i].context, args);
  228. }
  229. }
  230. }
  231. return true;
  232. };
  233. /**
  234. * Add a listener for a given event.
  235. *
  236. * @param {(String|Symbol)} event The event name.
  237. * @param {Function} fn The listener function.
  238. * @param {*} [context=this] The context to invoke the listener with.
  239. * @returns {EventEmitter} `this`.
  240. * @public
  241. */
  242. EventEmitter.prototype.on = function on(event, fn, context) {
  243. return addListener(this, event, fn, context, false);
  244. };
  245. /**
  246. * Add a one-time listener for a given event.
  247. *
  248. * @param {(String|Symbol)} event The event name.
  249. * @param {Function} fn The listener function.
  250. * @param {*} [context=this] The context to invoke the listener with.
  251. * @returns {EventEmitter} `this`.
  252. * @public
  253. */
  254. EventEmitter.prototype.once = function once(event, fn, context) {
  255. return addListener(this, event, fn, context, true);
  256. };
  257. /**
  258. * Remove the listeners of a given event.
  259. *
  260. * @param {(String|Symbol)} event The event name.
  261. * @param {Function} fn Only remove the listeners that match this function.
  262. * @param {*} context Only remove the listeners that have this context.
  263. * @param {Boolean} once Only remove one-time listeners.
  264. * @returns {EventEmitter} `this`.
  265. * @public
  266. */
  267. EventEmitter.prototype.removeListener = function removeListener(event, fn, context, once) {
  268. var evt = prefix ? prefix + event : event;
  269. if (!this._events[evt]) { return this; }
  270. if (!fn) {
  271. clearEvent(this, evt);
  272. return this;
  273. }
  274. var listeners = this._events[evt];
  275. if (listeners.fn) {
  276. if (
  277. listeners.fn === fn &&
  278. (!once || listeners.once) &&
  279. (!context || listeners.context === context)
  280. ) {
  281. clearEvent(this, evt);
  282. }
  283. } else {
  284. for (var i = 0, events = [], length = listeners.length; i < length; i++) {
  285. if (
  286. listeners[i].fn !== fn ||
  287. (once && !listeners[i].once) ||
  288. (context && listeners[i].context !== context)
  289. ) {
  290. events.push(listeners[i]);
  291. }
  292. }
  293. //
  294. // Reset the array, or remove it completely if we have no more listeners.
  295. //
  296. if (events.length) { this._events[evt] = events.length === 1 ? events[0] : events; }
  297. else { clearEvent(this, evt); }
  298. }
  299. return this;
  300. };
  301. /**
  302. * Remove all listeners, or those of the specified event.
  303. *
  304. * @param {(String|Symbol)} [event] The event name.
  305. * @returns {EventEmitter} `this`.
  306. * @public
  307. */
  308. EventEmitter.prototype.removeAllListeners = function removeAllListeners(event) {
  309. var evt;
  310. if (event) {
  311. evt = prefix ? prefix + event : event;
  312. if (this._events[evt]) { clearEvent(this, evt); }
  313. } else {
  314. this._events = new Events();
  315. this._eventsCount = 0;
  316. }
  317. return this;
  318. };
  319. //
  320. // Alias methods names because people roll like that.
  321. //
  322. EventEmitter.prototype.off = EventEmitter.prototype.removeListener;
  323. EventEmitter.prototype.addListener = EventEmitter.prototype.on;
  324. //
  325. // Expose the prefix.
  326. //
  327. EventEmitter.prefixed = prefix;
  328. //
  329. // Allow `EventEmitter` to be imported as module namespace.
  330. //
  331. EventEmitter.EventEmitter = EventEmitter;
  332. //
  333. // Expose the module.
  334. //
  335. if ('undefined' !== 'object') {
  336. module.exports = EventEmitter;
  337. }
  338. });
  339. 'use strict';
  340. var earcut_1 = earcut;
  341. var _default = earcut;
  342. function earcut(data, holeIndices, dim) {
  343. dim = dim || 2;
  344. var hasHoles = holeIndices && holeIndices.length,
  345. outerLen = hasHoles ? holeIndices[0] * dim : data.length,
  346. outerNode = linkedList(data, 0, outerLen, dim, true),
  347. triangles = [];
  348. if (!outerNode || outerNode.next === outerNode.prev) { return triangles; }
  349. var minX, minY, maxX, maxY, x, y, invSize;
  350. if (hasHoles) { outerNode = eliminateHoles(data, holeIndices, outerNode, dim); }
  351. // if the shape is not too simple, we'll use z-order curve hash later; calculate polygon bbox
  352. if (data.length > 80 * dim) {
  353. minX = maxX = data[0];
  354. minY = maxY = data[1];
  355. for (var i = dim; i < outerLen; i += dim) {
  356. x = data[i];
  357. y = data[i + 1];
  358. if (x < minX) { minX = x; }
  359. if (y < minY) { minY = y; }
  360. if (x > maxX) { maxX = x; }
  361. if (y > maxY) { maxY = y; }
  362. }
  363. // minX, minY and invSize are later used to transform coords into integers for z-order calculation
  364. invSize = Math.max(maxX - minX, maxY - minY);
  365. invSize = invSize !== 0 ? 32767 / invSize : 0;
  366. }
  367. earcutLinked(outerNode, triangles, dim, minX, minY, invSize, 0);
  368. return triangles;
  369. }
  370. // create a circular doubly linked list from polygon points in the specified winding order
  371. function linkedList(data, start, end, dim, clockwise) {
  372. var i, last;
  373. if (clockwise === (signedArea(data, start, end, dim) > 0)) {
  374. for (i = start; i < end; i += dim) { last = insertNode(i, data[i], data[i + 1], last); }
  375. } else {
  376. for (i = end - dim; i >= start; i -= dim) { last = insertNode(i, data[i], data[i + 1], last); }
  377. }
  378. if (last && equals(last, last.next)) {
  379. removeNode(last);
  380. last = last.next;
  381. }
  382. return last;
  383. }
  384. // eliminate colinear or duplicate points
  385. function filterPoints(start, end) {
  386. if (!start) { return start; }
  387. if (!end) { end = start; }
  388. var p = start,
  389. again;
  390. do {
  391. again = false;
  392. if (!p.steiner && (equals(p, p.next) || area(p.prev, p, p.next) === 0)) {
  393. removeNode(p);
  394. p = end = p.prev;
  395. if (p === p.next) { break; }
  396. again = true;
  397. } else {
  398. p = p.next;
  399. }
  400. } while (again || p !== end);
  401. return end;
  402. }
  403. // main ear slicing loop which triangulates a polygon (given as a linked list)
  404. function earcutLinked(ear, triangles, dim, minX, minY, invSize, pass) {
  405. if (!ear) { return; }
  406. // interlink polygon nodes in z-order
  407. if (!pass && invSize) { indexCurve(ear, minX, minY, invSize); }
  408. var stop = ear,
  409. prev, next;
  410. // iterate through ears, slicing them one by one
  411. while (ear.prev !== ear.next) {
  412. prev = ear.prev;
  413. next = ear.next;
  414. if (invSize ? isEarHashed(ear, minX, minY, invSize) : isEar(ear)) {
  415. // cut off the triangle
  416. triangles.push(prev.i / dim | 0);
  417. triangles.push(ear.i / dim | 0);
  418. triangles.push(next.i / dim | 0);
  419. removeNode(ear);
  420. // skipping the next vertex leads to less sliver triangles
  421. ear = next.next;
  422. stop = next.next;
  423. continue;
  424. }
  425. ear = next;
  426. // if we looped through the whole remaining polygon and can't find any more ears
  427. if (ear === stop) {
  428. // try filtering points and slicing again
  429. if (!pass) {
  430. earcutLinked(filterPoints(ear), triangles, dim, minX, minY, invSize, 1);
  431. // if this didn't work, try curing all small self-intersections locally
  432. } else if (pass === 1) {
  433. ear = cureLocalIntersections(filterPoints(ear), triangles, dim);
  434. earcutLinked(ear, triangles, dim, minX, minY, invSize, 2);
  435. // as a last resort, try splitting the remaining polygon into two
  436. } else if (pass === 2) {
  437. splitEarcut(ear, triangles, dim, minX, minY, invSize);
  438. }
  439. break;
  440. }
  441. }
  442. }
  443. // check whether a polygon node forms a valid ear with adjacent nodes
  444. function isEar(ear) {
  445. var a = ear.prev,
  446. b = ear,
  447. c = ear.next;
  448. if (area(a, b, c) >= 0) { return false; } // reflex, can't be an ear
  449. // now make sure we don't have other points inside the potential ear
  450. var ax = a.x, bx = b.x, cx = c.x, ay = a.y, by = b.y, cy = c.y;
  451. // triangle bbox; min & max are calculated like this for speed
  452. var x0 = ax < bx ? (ax < cx ? ax : cx) : (bx < cx ? bx : cx),
  453. y0 = ay < by ? (ay < cy ? ay : cy) : (by < cy ? by : cy),
  454. x1 = ax > bx ? (ax > cx ? ax : cx) : (bx > cx ? bx : cx),
  455. y1 = ay > by ? (ay > cy ? ay : cy) : (by > cy ? by : cy);
  456. var p = c.next;
  457. while (p !== a) {
  458. if (p.x >= x0 && p.x <= x1 && p.y >= y0 && p.y <= y1 &&
  459. pointInTriangle(ax, ay, bx, by, cx, cy, p.x, p.y) &&
  460. area(p.prev, p, p.next) >= 0) { return false; }
  461. p = p.next;
  462. }
  463. return true;
  464. }
  465. function isEarHashed(ear, minX, minY, invSize) {
  466. var a = ear.prev,
  467. b = ear,
  468. c = ear.next;
  469. if (area(a, b, c) >= 0) { return false; } // reflex, can't be an ear
  470. var ax = a.x, bx = b.x, cx = c.x, ay = a.y, by = b.y, cy = c.y;
  471. // triangle bbox; min & max are calculated like this for speed
  472. var x0 = ax < bx ? (ax < cx ? ax : cx) : (bx < cx ? bx : cx),
  473. y0 = ay < by ? (ay < cy ? ay : cy) : (by < cy ? by : cy),
  474. x1 = ax > bx ? (ax > cx ? ax : cx) : (bx > cx ? bx : cx),
  475. y1 = ay > by ? (ay > cy ? ay : cy) : (by > cy ? by : cy);
  476. // z-order range for the current triangle bbox;
  477. var minZ = zOrder(x0, y0, minX, minY, invSize),
  478. maxZ = zOrder(x1, y1, minX, minY, invSize);
  479. var p = ear.prevZ,
  480. n = ear.nextZ;
  481. // look for points inside the triangle in both directions
  482. while (p && p.z >= minZ && n && n.z <= maxZ) {
  483. if (p.x >= x0 && p.x <= x1 && p.y >= y0 && p.y <= y1 && p !== a && p !== c &&
  484. pointInTriangle(ax, ay, bx, by, cx, cy, p.x, p.y) && area(p.prev, p, p.next) >= 0) { return false; }
  485. p = p.prevZ;
  486. if (n.x >= x0 && n.x <= x1 && n.y >= y0 && n.y <= y1 && n !== a && n !== c &&
  487. pointInTriangle(ax, ay, bx, by, cx, cy, n.x, n.y) && area(n.prev, n, n.next) >= 0) { return false; }
  488. n = n.nextZ;
  489. }
  490. // look for remaining points in decreasing z-order
  491. while (p && p.z >= minZ) {
  492. if (p.x >= x0 && p.x <= x1 && p.y >= y0 && p.y <= y1 && p !== a && p !== c &&
  493. pointInTriangle(ax, ay, bx, by, cx, cy, p.x, p.y) && area(p.prev, p, p.next) >= 0) { return false; }
  494. p = p.prevZ;
  495. }
  496. // look for remaining points in increasing z-order
  497. while (n && n.z <= maxZ) {
  498. if (n.x >= x0 && n.x <= x1 && n.y >= y0 && n.y <= y1 && n !== a && n !== c &&
  499. pointInTriangle(ax, ay, bx, by, cx, cy, n.x, n.y) && area(n.prev, n, n.next) >= 0) { return false; }
  500. n = n.nextZ;
  501. }
  502. return true;
  503. }
  504. // go through all polygon nodes and cure small local self-intersections
  505. function cureLocalIntersections(start, triangles, dim) {
  506. var p = start;
  507. do {
  508. var a = p.prev,
  509. b = p.next.next;
  510. if (!equals(a, b) && intersects(a, p, p.next, b) && locallyInside(a, b) && locallyInside(b, a)) {
  511. triangles.push(a.i / dim | 0);
  512. triangles.push(p.i / dim | 0);
  513. triangles.push(b.i / dim | 0);
  514. // remove two nodes involved
  515. removeNode(p);
  516. removeNode(p.next);
  517. p = start = b;
  518. }
  519. p = p.next;
  520. } while (p !== start);
  521. return filterPoints(p);
  522. }
  523. // try splitting polygon into two and triangulate them independently
  524. function splitEarcut(start, triangles, dim, minX, minY, invSize) {
  525. // look for a valid diagonal that divides the polygon into two
  526. var a = start;
  527. do {
  528. var b = a.next.next;
  529. while (b !== a.prev) {
  530. if (a.i !== b.i && isValidDiagonal(a, b)) {
  531. // split the polygon in two by the diagonal
  532. var c = splitPolygon(a, b);
  533. // filter colinear points around the cuts
  534. a = filterPoints(a, a.next);
  535. c = filterPoints(c, c.next);
  536. // run earcut on each half
  537. earcutLinked(a, triangles, dim, minX, minY, invSize, 0);
  538. earcutLinked(c, triangles, dim, minX, minY, invSize, 0);
  539. return;
  540. }
  541. b = b.next;
  542. }
  543. a = a.next;
  544. } while (a !== start);
  545. }
  546. // link every hole into the outer loop, producing a single-ring polygon without holes
  547. function eliminateHoles(data, holeIndices, outerNode, dim) {
  548. var queue = [],
  549. i, len, start, end, list;
  550. for (i = 0, len = holeIndices.length; i < len; i++) {
  551. start = holeIndices[i] * dim;
  552. end = i < len - 1 ? holeIndices[i + 1] * dim : data.length;
  553. list = linkedList(data, start, end, dim, false);
  554. if (list === list.next) { list.steiner = true; }
  555. queue.push(getLeftmost(list));
  556. }
  557. queue.sort(compareX);
  558. // process holes from left to right
  559. for (i = 0; i < queue.length; i++) {
  560. outerNode = eliminateHole(queue[i], outerNode);
  561. }
  562. return outerNode;
  563. }
  564. function compareX(a, b) {
  565. return a.x - b.x;
  566. }
  567. // find a bridge between vertices that connects hole with an outer ring and and link it
  568. function eliminateHole(hole, outerNode) {
  569. var bridge = findHoleBridge(hole, outerNode);
  570. if (!bridge) {
  571. return outerNode;
  572. }
  573. var bridgeReverse = splitPolygon(bridge, hole);
  574. // filter collinear points around the cuts
  575. filterPoints(bridgeReverse, bridgeReverse.next);
  576. return filterPoints(bridge, bridge.next);
  577. }
  578. // David Eberly's algorithm for finding a bridge between hole and outer polygon
  579. function findHoleBridge(hole, outerNode) {
  580. var p = outerNode,
  581. hx = hole.x,
  582. hy = hole.y,
  583. qx = -Infinity,
  584. m;
  585. // find a segment intersected by a ray from the hole's leftmost point to the left;
  586. // segment's endpoint with lesser x will be potential connection point
  587. do {
  588. if (hy <= p.y && hy >= p.next.y && p.next.y !== p.y) {
  589. var x = p.x + (hy - p.y) * (p.next.x - p.x) / (p.next.y - p.y);
  590. if (x <= hx && x > qx) {
  591. qx = x;
  592. m = p.x < p.next.x ? p : p.next;
  593. if (x === hx) { return m; } // hole touches outer segment; pick leftmost endpoint
  594. }
  595. }
  596. p = p.next;
  597. } while (p !== outerNode);
  598. if (!m) { return null; }
  599. // look for points inside the triangle of hole point, segment intersection and endpoint;
  600. // if there are no points found, we have a valid connection;
  601. // otherwise choose the point of the minimum angle with the ray as connection point
  602. var stop = m,
  603. mx = m.x,
  604. my = m.y,
  605. tanMin = Infinity,
  606. tan;
  607. p = m;
  608. do {
  609. if (hx >= p.x && p.x >= mx && hx !== p.x &&
  610. pointInTriangle(hy < my ? hx : qx, hy, mx, my, hy < my ? qx : hx, hy, p.x, p.y)) {
  611. tan = Math.abs(hy - p.y) / (hx - p.x); // tangential
  612. if (locallyInside(p, hole) &&
  613. (tan < tanMin || (tan === tanMin && (p.x > m.x || (p.x === m.x && sectorContainsSector(m, p)))))) {
  614. m = p;
  615. tanMin = tan;
  616. }
  617. }
  618. p = p.next;
  619. } while (p !== stop);
  620. return m;
  621. }
  622. // whether sector in vertex m contains sector in vertex p in the same coordinates
  623. function sectorContainsSector(m, p) {
  624. return area(m.prev, m, p.prev) < 0 && area(p.next, m, m.next) < 0;
  625. }
  626. // interlink polygon nodes in z-order
  627. function indexCurve(start, minX, minY, invSize) {
  628. var p = start;
  629. do {
  630. if (p.z === 0) { p.z = zOrder(p.x, p.y, minX, minY, invSize); }
  631. p.prevZ = p.prev;
  632. p.nextZ = p.next;
  633. p = p.next;
  634. } while (p !== start);
  635. p.prevZ.nextZ = null;
  636. p.prevZ = null;
  637. sortLinked(p);
  638. }
  639. // Simon Tatham's linked list merge sort algorithm
  640. // http://www.chiark.greenend.org.uk/~sgtatham/algorithms/listsort.html
  641. function sortLinked(list) {
  642. var i, p, q, e, tail, numMerges, pSize, qSize,
  643. inSize = 1;
  644. do {
  645. p = list;
  646. list = null;
  647. tail = null;
  648. numMerges = 0;
  649. while (p) {
  650. numMerges++;
  651. q = p;
  652. pSize = 0;
  653. for (i = 0; i < inSize; i++) {
  654. pSize++;
  655. q = q.nextZ;
  656. if (!q) { break; }
  657. }
  658. qSize = inSize;
  659. while (pSize > 0 || (qSize > 0 && q)) {
  660. if (pSize !== 0 && (qSize === 0 || !q || p.z <= q.z)) {
  661. e = p;
  662. p = p.nextZ;
  663. pSize--;
  664. } else {
  665. e = q;
  666. q = q.nextZ;
  667. qSize--;
  668. }
  669. if (tail) { tail.nextZ = e; }
  670. else { list = e; }
  671. e.prevZ = tail;
  672. tail = e;
  673. }
  674. p = q;
  675. }
  676. tail.nextZ = null;
  677. inSize *= 2;
  678. } while (numMerges > 1);
  679. return list;
  680. }
  681. // z-order of a point given coords and inverse of the longer side of data bbox
  682. function zOrder(x, y, minX, minY, invSize) {
  683. // coords are transformed into non-negative 15-bit integer range
  684. x = (x - minX) * invSize | 0;
  685. y = (y - minY) * invSize | 0;
  686. x = (x | (x << 8)) & 0x00FF00FF;
  687. x = (x | (x << 4)) & 0x0F0F0F0F;
  688. x = (x | (x << 2)) & 0x33333333;
  689. x = (x | (x << 1)) & 0x55555555;
  690. y = (y | (y << 8)) & 0x00FF00FF;
  691. y = (y | (y << 4)) & 0x0F0F0F0F;
  692. y = (y | (y << 2)) & 0x33333333;
  693. y = (y | (y << 1)) & 0x55555555;
  694. return x | (y << 1);
  695. }
  696. // find the leftmost node of a polygon ring
  697. function getLeftmost(start) {
  698. var p = start,
  699. leftmost = start;
  700. do {
  701. if (p.x < leftmost.x || (p.x === leftmost.x && p.y < leftmost.y)) { leftmost = p; }
  702. p = p.next;
  703. } while (p !== start);
  704. return leftmost;
  705. }
  706. // check if a point lies within a convex triangle
  707. function pointInTriangle(ax, ay, bx, by, cx, cy, px, py) {
  708. return (cx - px) * (ay - py) >= (ax - px) * (cy - py) &&
  709. (ax - px) * (by - py) >= (bx - px) * (ay - py) &&
  710. (bx - px) * (cy - py) >= (cx - px) * (by - py);
  711. }
  712. // check if a diagonal between two polygon nodes is valid (lies in polygon interior)
  713. function isValidDiagonal(a, b) {
  714. return a.next.i !== b.i && a.prev.i !== b.i && !intersectsPolygon(a, b) && // dones't intersect other edges
  715. (locallyInside(a, b) && locallyInside(b, a) && middleInside(a, b) && // locally visible
  716. (area(a.prev, a, b.prev) || area(a, b.prev, b)) || // does not create opposite-facing sectors
  717. equals(a, b) && area(a.prev, a, a.next) > 0 && area(b.prev, b, b.next) > 0); // special zero-length case
  718. }
  719. // signed area of a triangle
  720. function area(p, q, r) {
  721. return (q.y - p.y) * (r.x - q.x) - (q.x - p.x) * (r.y - q.y);
  722. }
  723. // check if two points are equal
  724. function equals(p1, p2) {
  725. return p1.x === p2.x && p1.y === p2.y;
  726. }
  727. // check if two segments intersect
  728. function intersects(p1, q1, p2, q2) {
  729. var o1 = sign$1(area(p1, q1, p2));
  730. var o2 = sign$1(area(p1, q1, q2));
  731. var o3 = sign$1(area(p2, q2, p1));
  732. var o4 = sign$1(area(p2, q2, q1));
  733. if (o1 !== o2 && o3 !== o4) { return true; } // general case
  734. if (o1 === 0 && onSegment(p1, p2, q1)) { return true; } // p1, q1 and p2 are collinear and p2 lies on p1q1
  735. if (o2 === 0 && onSegment(p1, q2, q1)) { return true; } // p1, q1 and q2 are collinear and q2 lies on p1q1
  736. if (o3 === 0 && onSegment(p2, p1, q2)) { return true; } // p2, q2 and p1 are collinear and p1 lies on p2q2
  737. if (o4 === 0 && onSegment(p2, q1, q2)) { return true; } // p2, q2 and q1 are collinear and q1 lies on p2q2
  738. return false;
  739. }
  740. // for collinear points p, q, r, check if point q lies on segment pr
  741. function onSegment(p, q, r) {
  742. return q.x <= Math.max(p.x, r.x) && q.x >= Math.min(p.x, r.x) && q.y <= Math.max(p.y, r.y) && q.y >= Math.min(p.y, r.y);
  743. }
  744. function sign$1(num) {
  745. return num > 0 ? 1 : num < 0 ? -1 : 0;
  746. }
  747. // check if a polygon diagonal intersects any polygon segments
  748. function intersectsPolygon(a, b) {
  749. var p = a;
  750. do {
  751. if (p.i !== a.i && p.next.i !== a.i && p.i !== b.i && p.next.i !== b.i &&
  752. intersects(p, p.next, a, b)) { return true; }
  753. p = p.next;
  754. } while (p !== a);
  755. return false;
  756. }
  757. // check if a polygon diagonal is locally inside the polygon
  758. function locallyInside(a, b) {
  759. return area(a.prev, a, a.next) < 0 ?
  760. area(a, b, a.next) >= 0 && area(a, a.prev, b) >= 0 :
  761. area(a, b, a.prev) < 0 || area(a, a.next, b) < 0;
  762. }
  763. // check if the middle point of a polygon diagonal is inside the polygon
  764. function middleInside(a, b) {
  765. var p = a,
  766. inside = false,
  767. px = (a.x + b.x) / 2,
  768. py = (a.y + b.y) / 2;
  769. do {
  770. if (((p.y > py) !== (p.next.y > py)) && p.next.y !== p.y &&
  771. (px < (p.next.x - p.x) * (py - p.y) / (p.next.y - p.y) + p.x))
  772. { inside = !inside; }
  773. p = p.next;
  774. } while (p !== a);
  775. return inside;
  776. }
  777. // link two polygon vertices with a bridge; if the vertices belong to the same ring, it splits polygon into two;
  778. // if one belongs to the outer ring and another to a hole, it merges it into a single ring
  779. function splitPolygon(a, b) {
  780. var a2 = new Node(a.i, a.x, a.y),
  781. b2 = new Node(b.i, b.x, b.y),
  782. an = a.next,
  783. bp = b.prev;
  784. a.next = b;
  785. b.prev = a;
  786. a2.next = an;
  787. an.prev = a2;
  788. b2.next = a2;
  789. a2.prev = b2;
  790. bp.next = b2;
  791. b2.prev = bp;
  792. return b2;
  793. }
  794. // create a node and optionally link it with previous one (in a circular doubly linked list)
  795. function insertNode(i, x, y, last) {
  796. var p = new Node(i, x, y);
  797. if (!last) {
  798. p.prev = p;
  799. p.next = p;
  800. } else {
  801. p.next = last.next;
  802. p.prev = last;
  803. last.next.prev = p;
  804. last.next = p;
  805. }
  806. return p;
  807. }
  808. function removeNode(p) {
  809. p.next.prev = p.prev;
  810. p.prev.next = p.next;
  811. if (p.prevZ) { p.prevZ.nextZ = p.nextZ; }
  812. if (p.nextZ) { p.nextZ.prevZ = p.prevZ; }
  813. }
  814. function Node(i, x, y) {
  815. // vertex index in coordinates array
  816. this.i = i;
  817. // vertex coordinates
  818. this.x = x;
  819. this.y = y;
  820. // previous and next vertex nodes in a polygon ring
  821. this.prev = null;
  822. this.next = null;
  823. // z-order curve value
  824. this.z = 0;
  825. // previous and next nodes in z-order
  826. this.prevZ = null;
  827. this.nextZ = null;
  828. // indicates whether this is a steiner point
  829. this.steiner = false;
  830. }
  831. // return a percentage difference between the polygon area and its triangulation area;
  832. // used to verify correctness of triangulation
  833. earcut.deviation = function (data, holeIndices, dim, triangles) {
  834. var hasHoles = holeIndices && holeIndices.length;
  835. var outerLen = hasHoles ? holeIndices[0] * dim : data.length;
  836. var polygonArea = Math.abs(signedArea(data, 0, outerLen, dim));
  837. if (hasHoles) {
  838. for (var i = 0, len = holeIndices.length; i < len; i++) {
  839. var start = holeIndices[i] * dim;
  840. var end = i < len - 1 ? holeIndices[i + 1] * dim : data.length;
  841. polygonArea -= Math.abs(signedArea(data, start, end, dim));
  842. }
  843. }
  844. var trianglesArea = 0;
  845. for (i = 0; i < triangles.length; i += 3) {
  846. var a = triangles[i] * dim;
  847. var b = triangles[i + 1] * dim;
  848. var c = triangles[i + 2] * dim;
  849. trianglesArea += Math.abs(
  850. (data[a] - data[c]) * (data[b + 1] - data[a + 1]) -
  851. (data[a] - data[b]) * (data[c + 1] - data[a + 1]));
  852. }
  853. return polygonArea === 0 && trianglesArea === 0 ? 0 :
  854. Math.abs((trianglesArea - polygonArea) / polygonArea);
  855. };
  856. function signedArea(data, start, end, dim) {
  857. var sum = 0;
  858. for (var i = start, j = end - dim; i < end; i += dim) {
  859. sum += (data[j] - data[i]) * (data[i + 1] + data[j + 1]);
  860. j = i;
  861. }
  862. return sum;
  863. }
  864. // turn a polygon in a multi-dimensional array form (e.g. as in GeoJSON) into a form Earcut accepts
  865. earcut.flatten = function (data) {
  866. var dim = data[0][0].length,
  867. result = {vertices: [], holes: [], dimensions: dim},
  868. holeIndex = 0;
  869. for (var i = 0; i < data.length; i++) {
  870. for (var j = 0; j < data[i].length; j++) {
  871. for (var d = 0; d < dim; d++) { result.vertices.push(data[i][j][d]); }
  872. }
  873. if (i > 0) {
  874. holeIndex += data[i - 1].length;
  875. result.holes.push(holeIndex);
  876. }
  877. }
  878. return result;
  879. };
  880. earcut_1.default = _default;
  881. var punycode = createCommonjsModule(function (module, exports) {
  882. /*! https://mths.be/punycode v1.3.2 by @mathias */
  883. ;(function(root) {
  884. /** Detect free variables */
  885. var freeExports = 'object' == 'object' && exports &&
  886. !exports.nodeType && exports;
  887. var freeModule = 'object' == 'object' && module &&
  888. !module.nodeType && module;
  889. var freeGlobal = typeof commonjsGlobal == 'object' && commonjsGlobal;
  890. if (
  891. freeGlobal.global === freeGlobal ||
  892. freeGlobal.window === freeGlobal ||
  893. freeGlobal.self === freeGlobal
  894. ) {
  895. root = freeGlobal;
  896. }
  897. /**
  898. * The `punycode` object.
  899. * @name punycode
  900. * @type Object
  901. */
  902. var punycode,
  903. /** Highest positive signed 32-bit float value */
  904. maxInt = 2147483647, // aka. 0x7FFFFFFF or 2^31-1
  905. /** Bootstring parameters */
  906. base = 36,
  907. tMin = 1,
  908. tMax = 26,
  909. skew = 38,
  910. damp = 700,
  911. initialBias = 72,
  912. initialN = 128, // 0x80
  913. delimiter = '-', // '\x2D'
  914. /** Regular expressions */
  915. regexPunycode = /^xn--/,
  916. regexNonASCII = /[^\x20-\x7E]/, // unprintable ASCII chars + non-ASCII chars
  917. regexSeparators = /[\x2E\u3002\uFF0E\uFF61]/g, // RFC 3490 separators
  918. /** Error messages */
  919. errors = {
  920. 'overflow': 'Overflow: input needs wider integers to process',
  921. 'not-basic': 'Illegal input >= 0x80 (not a basic code point)',
  922. 'invalid-input': 'Invalid input'
  923. },
  924. /** Convenience shortcuts */
  925. baseMinusTMin = base - tMin,
  926. floor = Math.floor,
  927. stringFromCharCode = String.fromCharCode,
  928. /** Temporary variable */
  929. key;
  930. /*--------------------------------------------------------------------------*/
  931. /**
  932. * A generic error utility function.
  933. * @private
  934. * @param {String} type The error type.
  935. * @returns {Error} Throws a `RangeError` with the applicable error message.
  936. */
  937. function error(type) {
  938. throw RangeError(errors[type]);
  939. }
  940. /**
  941. * A generic `Array#map` utility function.
  942. * @private
  943. * @param {Array} array The array to iterate over.
  944. * @param {Function} callback The function that gets called for every array
  945. * item.
  946. * @returns {Array} A new array of values returned by the callback function.
  947. */
  948. function map(array, fn) {
  949. var length = array.length;
  950. var result = [];
  951. while (length--) {
  952. result[length] = fn(array[length]);
  953. }
  954. return result;
  955. }
  956. /**
  957. * A simple `Array#map`-like wrapper to work with domain name strings or email
  958. * addresses.
  959. * @private
  960. * @param {String} domain The domain name or email address.
  961. * @param {Function} callback The function that gets called for every
  962. * character.
  963. * @returns {Array} A new string of characters returned by the callback
  964. * function.
  965. */
  966. function mapDomain(string, fn) {
  967. var parts = string.split('@');
  968. var result = '';
  969. if (parts.length > 1) {
  970. // In email addresses, only the domain name should be punycoded. Leave
  971. // the local part (i.e. everything up to `@`) intact.
  972. result = parts[0] + '@';
  973. string = parts[1];
  974. }
  975. // Avoid `split(regex)` for IE8 compatibility. See #17.
  976. string = string.replace(regexSeparators, '\x2E');
  977. var labels = string.split('.');
  978. var encoded = map(labels, fn).join('.');
  979. return result + encoded;
  980. }
  981. /**
  982. * Creates an array containing the numeric code points of each Unicode
  983. * character in the string. While JavaScript uses UCS-2 internally,
  984. * this function will convert a pair of surrogate halves (each of which
  985. * UCS-2 exposes as separate characters) into a single code point,
  986. * matching UTF-16.
  987. * @see `punycode.ucs2.encode`
  988. * @see <https://mathiasbynens.be/notes/javascript-encoding>
  989. * @memberOf punycode.ucs2
  990. * @name decode
  991. * @param {String} string The Unicode input string (UCS-2).
  992. * @returns {Array} The new array of code points.
  993. */
  994. function ucs2decode(string) {
  995. var output = [],
  996. counter = 0,
  997. length = string.length,
  998. value,
  999. extra;
  1000. while (counter < length) {
  1001. value = string.charCodeAt(counter++);
  1002. if (value >= 0xD800 && value <= 0xDBFF && counter < length) {
  1003. // high surrogate, and there is a next character
  1004. extra = string.charCodeAt(counter++);
  1005. if ((extra & 0xFC00) == 0xDC00) { // low surrogate
  1006. output.push(((value & 0x3FF) << 10) + (extra & 0x3FF) + 0x10000);
  1007. } else {
  1008. // unmatched surrogate; only append this code unit, in case the next
  1009. // code unit is the high surrogate of a surrogate pair
  1010. output.push(value);
  1011. counter--;
  1012. }
  1013. } else {
  1014. output.push(value);
  1015. }
  1016. }
  1017. return output;
  1018. }
  1019. /**
  1020. * Creates a string based on an array of numeric code points.
  1021. * @see `punycode.ucs2.decode`
  1022. * @memberOf punycode.ucs2
  1023. * @name encode
  1024. * @param {Array} codePoints The array of numeric code points.
  1025. * @returns {String} The new Unicode string (UCS-2).
  1026. */
  1027. function ucs2encode(array) {
  1028. return map(array, function(value) {
  1029. var output = '';
  1030. if (value > 0xFFFF) {
  1031. value -= 0x10000;
  1032. output += stringFromCharCode(value >>> 10 & 0x3FF | 0xD800);
  1033. value = 0xDC00 | value & 0x3FF;
  1034. }
  1035. output += stringFromCharCode(value);
  1036. return output;
  1037. }).join('');
  1038. }
  1039. /**
  1040. * Converts a basic code point into a digit/integer.
  1041. * @see `digitToBasic()`
  1042. * @private
  1043. * @param {Number} codePoint The basic numeric code point value.
  1044. * @returns {Number} The numeric value of a basic code point (for use in
  1045. * representing integers) in the range `0` to `base - 1`, or `base` if
  1046. * the code point does not represent a value.
  1047. */
  1048. function basicToDigit(codePoint) {
  1049. if (codePoint - 48 < 10) {
  1050. return codePoint - 22;
  1051. }
  1052. if (codePoint - 65 < 26) {
  1053. return codePoint - 65;
  1054. }
  1055. if (codePoint - 97 < 26) {
  1056. return codePoint - 97;
  1057. }
  1058. return base;
  1059. }
  1060. /**
  1061. * Converts a digit/integer into a basic code point.
  1062. * @see `basicToDigit()`
  1063. * @private
  1064. * @param {Number} digit The numeric value of a basic code point.
  1065. * @returns {Number} The basic code point whose value (when used for
  1066. * representing integers) is `digit`, which needs to be in the range
  1067. * `0` to `base - 1`. If `flag` is non-zero, the uppercase form is
  1068. * used; else, the lowercase form is used. The behavior is undefined
  1069. * if `flag` is non-zero and `digit` has no uppercase form.
  1070. */
  1071. function digitToBasic(digit, flag) {
  1072. // 0..25 map to ASCII a..z or A..Z
  1073. // 26..35 map to ASCII 0..9
  1074. return digit + 22 + 75 * (digit < 26) - ((flag != 0) << 5);
  1075. }
  1076. /**
  1077. * Bias adaptation function as per section 3.4 of RFC 3492.
  1078. * http://tools.ietf.org/html/rfc3492#section-3.4
  1079. * @private
  1080. */
  1081. function adapt(delta, numPoints, firstTime) {
  1082. var k = 0;
  1083. delta = firstTime ? floor(delta / damp) : delta >> 1;
  1084. delta += floor(delta / numPoints);
  1085. for (/* no initialization */; delta > baseMinusTMin * tMax >> 1; k += base) {
  1086. delta = floor(delta / baseMinusTMin);
  1087. }
  1088. return floor(k + (baseMinusTMin + 1) * delta / (delta + skew));
  1089. }
  1090. /**
  1091. * Converts a Punycode string of ASCII-only symbols to a string of Unicode
  1092. * symbols.
  1093. * @memberOf punycode
  1094. * @param {String} input The Punycode string of ASCII-only symbols.
  1095. * @returns {String} The resulting string of Unicode symbols.
  1096. */
  1097. function decode(input) {
  1098. // Don't use UCS-2
  1099. var output = [],
  1100. inputLength = input.length,
  1101. out,
  1102. i = 0,
  1103. n = initialN,
  1104. bias = initialBias,
  1105. basic,
  1106. j,
  1107. index,
  1108. oldi,
  1109. w,
  1110. k,
  1111. digit,
  1112. t,
  1113. /** Cached calculation results */
  1114. baseMinusT;
  1115. // Handle the basic code points: let `basic` be the number of input code
  1116. // points before the last delimiter, or `0` if there is none, then copy
  1117. // the first basic code points to the output.
  1118. basic = input.lastIndexOf(delimiter);
  1119. if (basic < 0) {
  1120. basic = 0;
  1121. }
  1122. for (j = 0; j < basic; ++j) {
  1123. // if it's not a basic code point
  1124. if (input.charCodeAt(j) >= 0x80) {
  1125. error('not-basic');
  1126. }
  1127. output.push(input.charCodeAt(j));
  1128. }
  1129. // Main decoding loop: start just after the last delimiter if any basic code
  1130. // points were copied; start at the beginning otherwise.
  1131. for (index = basic > 0 ? basic + 1 : 0; index < inputLength; /* no final expression */) {
  1132. // `index` is the index of the next character to be consumed.
  1133. // Decode a generalized variable-length integer into `delta`,
  1134. // which gets added to `i`. The overflow checking is easier
  1135. // if we increase `i` as we go, then subtract off its starting
  1136. // value at the end to obtain `delta`.
  1137. for (oldi = i, w = 1, k = base; /* no condition */; k += base) {
  1138. if (index >= inputLength) {
  1139. error('invalid-input');
  1140. }
  1141. digit = basicToDigit(input.charCodeAt(index++));
  1142. if (digit >= base || digit > floor((maxInt - i) / w)) {
  1143. error('overflow');
  1144. }
  1145. i += digit * w;
  1146. t = k <= bias ? tMin : (k >= bias + tMax ? tMax : k - bias);
  1147. if (digit < t) {
  1148. break;
  1149. }
  1150. baseMinusT = base - t;
  1151. if (w > floor(maxInt / baseMinusT)) {
  1152. error('overflow');
  1153. }
  1154. w *= baseMinusT;
  1155. }
  1156. out = output.length + 1;
  1157. bias = adapt(i - oldi, out, oldi == 0);
  1158. // `i` was supposed to wrap around from `out` to `0`,
  1159. // incrementing `n` each time, so we'll fix that now:
  1160. if (floor(i / out) > maxInt - n) {
  1161. error('overflow');
  1162. }
  1163. n += floor(i / out);
  1164. i %= out;
  1165. // Insert `n` at position `i` of the output
  1166. output.splice(i++, 0, n);
  1167. }
  1168. return ucs2encode(output);
  1169. }
  1170. /**
  1171. * Converts a string of Unicode symbols (e.g. a domain name label) to a
  1172. * Punycode string of ASCII-only symbols.
  1173. * @memberOf punycode
  1174. * @param {String} input The string of Unicode symbols.
  1175. * @returns {String} The resulting Punycode string of ASCII-only symbols.
  1176. */
  1177. function encode(input) {
  1178. var n,
  1179. delta,
  1180. handledCPCount,
  1181. basicLength,
  1182. bias,
  1183. j,
  1184. m,
  1185. q,
  1186. k,
  1187. t,
  1188. currentValue,
  1189. output = [],
  1190. /** `inputLength` will hold the number of code points in `input`. */
  1191. inputLength,
  1192. /** Cached calculation results */
  1193. handledCPCountPlusOne,
  1194. baseMinusT,
  1195. qMinusT;
  1196. // Convert the input in UCS-2 to Unicode
  1197. input = ucs2decode(input);
  1198. // Cache the length
  1199. inputLength = input.length;
  1200. // Initialize the state
  1201. n = initialN;
  1202. delta = 0;
  1203. bias = initialBias;
  1204. // Handle the basic code points
  1205. for (j = 0; j < inputLength; ++j) {
  1206. currentValue = input[j];
  1207. if (currentValue < 0x80) {
  1208. output.push(stringFromCharCode(currentValue));
  1209. }
  1210. }
  1211. handledCPCount = basicLength = output.length;
  1212. // `handledCPCount` is the number of code points that have been handled;
  1213. // `basicLength` is the number of basic code points.
  1214. // Finish the basic string - if it is not empty - with a delimiter
  1215. if (basicLength) {
  1216. output.push(delimiter);
  1217. }
  1218. // Main encoding loop:
  1219. while (handledCPCount < inputLength) {
  1220. // All non-basic code points < n have been handled already. Find the next
  1221. // larger one:
  1222. for (m = maxInt, j = 0; j < inputLength; ++j) {
  1223. currentValue = input[j];
  1224. if (currentValue >= n && currentValue < m) {
  1225. m = currentValue;
  1226. }
  1227. }
  1228. // Increase `delta` enough to advance the decoder's <n,i> state to <m,0>,
  1229. // but guard against overflow
  1230. handledCPCountPlusOne = handledCPCount + 1;
  1231. if (m - n > floor((maxInt - delta) / handledCPCountPlusOne)) {
  1232. error('overflow');
  1233. }
  1234. delta += (m - n) * handledCPCountPlusOne;
  1235. n = m;
  1236. for (j = 0; j < inputLength; ++j) {
  1237. currentValue = input[j];
  1238. if (currentValue < n && ++delta > maxInt) {
  1239. error('overflow');
  1240. }
  1241. if (currentValue == n) {
  1242. // Represent delta as a generalized variable-length integer
  1243. for (q = delta, k = base; /* no condition */; k += base) {
  1244. t = k <= bias ? tMin : (k >= bias + tMax ? tMax : k - bias);
  1245. if (q < t) {
  1246. break;
  1247. }
  1248. qMinusT = q - t;
  1249. baseMinusT = base - t;
  1250. output.push(
  1251. stringFromCharCode(digitToBasic(t + qMinusT % baseMinusT, 0))
  1252. );
  1253. q = floor(qMinusT / baseMinusT);
  1254. }
  1255. output.push(stringFromCharCode(digitToBasic(q, 0)));
  1256. bias = adapt(delta, handledCPCountPlusOne, handledCPCount == basicLength);
  1257. delta = 0;
  1258. ++handledCPCount;
  1259. }
  1260. }
  1261. ++delta;
  1262. ++n;
  1263. }
  1264. return output.join('');
  1265. }
  1266. /**
  1267. * Converts a Punycode string representing a domain name or an email address
  1268. * to Unicode. Only the Punycoded parts of the input will be converted, i.e.
  1269. * it doesn't matter if you call it on a string that has already been
  1270. * converted to Unicode.
  1271. * @memberOf punycode
  1272. * @param {String} input The Punycoded domain name or email address to
  1273. * convert to Unicode.
  1274. * @returns {String} The Unicode representation of the given Punycode
  1275. * string.
  1276. */
  1277. function toUnicode(input) {
  1278. return mapDomain(input, function(string) {
  1279. return regexPunycode.test(string)
  1280. ? decode(string.slice(4).toLowerCase())
  1281. : string;
  1282. });
  1283. }
  1284. /**
  1285. * Converts a Unicode string representing a domain name or an email address to
  1286. * Punycode. Only the non-ASCII parts of the domain name will be converted,
  1287. * i.e. it doesn't matter if you call it with a domain that's already in
  1288. * ASCII.
  1289. * @memberOf punycode
  1290. * @param {String} input The domain name or email address to convert, as a
  1291. * Unicode string.
  1292. * @returns {String} The Punycode representation of the given domain name or
  1293. * email address.
  1294. */
  1295. function toASCII(input) {
  1296. return mapDomain(input, function(string) {
  1297. return regexNonASCII.test(string)
  1298. ? 'xn--' + encode(string)
  1299. : string;
  1300. });
  1301. }
  1302. /*--------------------------------------------------------------------------*/
  1303. /** Define the public API */
  1304. punycode = {
  1305. /**
  1306. * A string representing the current Punycode.js version number.
  1307. * @memberOf punycode
  1308. * @type String
  1309. */
  1310. 'version': '1.3.2',
  1311. /**
  1312. * An object of methods to convert from JavaScript's internal character
  1313. * representation (UCS-2) to Unicode code points, and back.
  1314. * @see <https://mathiasbynens.be/notes/javascript-encoding>
  1315. * @memberOf punycode
  1316. * @type Object
  1317. */
  1318. 'ucs2': {
  1319. 'decode': ucs2decode,
  1320. 'encode': ucs2encode
  1321. },
  1322. 'decode': decode,
  1323. 'encode': encode,
  1324. 'toASCII': toASCII,
  1325. 'toUnicode': toUnicode
  1326. };
  1327. /** Expose `punycode` */
  1328. // Some AMD build optimizers, like r.js, check for specific condition patterns
  1329. // like the following:
  1330. if (
  1331. typeof undefined == 'function' &&
  1332. typeof undefined.amd == 'object' &&
  1333. undefined.amd
  1334. ) {
  1335. undefined('punycode', function() {
  1336. return punycode;
  1337. });
  1338. } else if (freeExports && freeModule) {
  1339. if (module.exports == freeExports) { // in Node.js or RingoJS v0.8.0+
  1340. freeModule.exports = punycode;
  1341. } else { // in Narwhal or RingoJS v0.7.0-
  1342. for (key in punycode) {
  1343. punycode.hasOwnProperty(key) && (freeExports[key] = punycode[key]);
  1344. }
  1345. }
  1346. } else { // in Rhino or a web browser
  1347. root.punycode = punycode;
  1348. }
  1349. }(commonjsGlobal));
  1350. });
  1351. 'use strict';
  1352. var util = {
  1353. isString: function(arg) {
  1354. return typeof(arg) === 'string';
  1355. },
  1356. isObject: function(arg) {
  1357. return typeof(arg) === 'object' && arg !== null;
  1358. },
  1359. isNull: function(arg) {
  1360. return arg === null;
  1361. },
  1362. isNullOrUndefined: function(arg) {
  1363. return arg == null;
  1364. }
  1365. };
  1366. // Copyright Joyent, Inc. and other Node contributors.
  1367. //
  1368. // Permission is hereby granted, free of charge, to any person obtaining a
  1369. // copy of this software and associated documentation files (the
  1370. // "Software"), to deal in the Software without restriction, including
  1371. // without limitation the rights to use, copy, modify, merge, publish,
  1372. // distribute, sublicense, and/or sell copies of the Software, and to permit
  1373. // persons to whom the Software is furnished to do so, subject to the
  1374. // following conditions:
  1375. //
  1376. // The above copyright notice and this permission notice shall be included
  1377. // in all copies or substantial portions of the Software.
  1378. //
  1379. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  1380. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  1381. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  1382. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  1383. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  1384. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  1385. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  1386. 'use strict';
  1387. // If obj.hasOwnProperty has been overridden, then calling
  1388. // obj.hasOwnProperty(prop) will break.
  1389. // See: https://github.com/joyent/node/issues/1707
  1390. function hasOwnProperty(obj, prop) {
  1391. return Object.prototype.hasOwnProperty.call(obj, prop);
  1392. }
  1393. var decode = function(qs, sep, eq, options) {
  1394. sep = sep || '&';
  1395. eq = eq || '=';
  1396. var obj = {};
  1397. if (typeof qs !== 'string' || qs.length === 0) {
  1398. return obj;
  1399. }
  1400. var regexp = /\+/g;
  1401. qs = qs.split(sep);
  1402. var maxKeys = 1000;
  1403. if (options && typeof options.maxKeys === 'number') {
  1404. maxKeys = options.maxKeys;
  1405. }
  1406. var len = qs.length;
  1407. // maxKeys <= 0 means that we should not limit keys count
  1408. if (maxKeys > 0 && len > maxKeys) {
  1409. len = maxKeys;
  1410. }
  1411. for (var i = 0; i < len; ++i) {
  1412. var x = qs[i].replace(regexp, '%20'),
  1413. idx = x.indexOf(eq),
  1414. kstr, vstr, k, v;
  1415. if (idx >= 0) {
  1416. kstr = x.substr(0, idx);
  1417. vstr = x.substr(idx + 1);
  1418. } else {
  1419. kstr = x;
  1420. vstr = '';
  1421. }
  1422. k = decodeURIComponent(kstr);
  1423. v = decodeURIComponent(vstr);
  1424. if (!hasOwnProperty(obj, k)) {
  1425. obj[k] = v;
  1426. } else if (Array.isArray(obj[k])) {
  1427. obj[k].push(v);
  1428. } else {
  1429. obj[k] = [obj[k], v];
  1430. }
  1431. }
  1432. return obj;
  1433. };
  1434. // Copyright Joyent, Inc. and other Node contributors.
  1435. //
  1436. // Permission is hereby granted, free of charge, to any person obtaining a
  1437. // copy of this software and associated documentation files (the
  1438. // "Software"), to deal in the Software without restriction, including
  1439. // without limitation the rights to use, copy, modify, merge, publish,
  1440. // distribute, sublicense, and/or sell copies of the Software, and to permit
  1441. // persons to whom the Software is furnished to do so, subject to the
  1442. // following conditions:
  1443. //
  1444. // The above copyright notice and this permission notice shall be included
  1445. // in all copies or substantial portions of the Software.
  1446. //
  1447. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  1448. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  1449. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  1450. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  1451. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  1452. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  1453. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  1454. 'use strict';
  1455. var stringifyPrimitive = function(v) {
  1456. switch (typeof v) {
  1457. case 'string':
  1458. return v;
  1459. case 'boolean':
  1460. return v ? 'true' : 'false';
  1461. case 'number':
  1462. return isFinite(v) ? v : '';
  1463. default:
  1464. return '';
  1465. }
  1466. };
  1467. var encode = function(obj, sep, eq, name) {
  1468. sep = sep || '&';
  1469. eq = eq || '=';
  1470. if (obj === null) {
  1471. obj = undefined;
  1472. }
  1473. if (typeof obj === 'object') {
  1474. return Object.keys(obj).map(function(k) {
  1475. var ks = encodeURIComponent(stringifyPrimitive(k)) + eq;
  1476. if (Array.isArray(obj[k])) {
  1477. return obj[k].map(function(v) {
  1478. return ks + encodeURIComponent(stringifyPrimitive(v));
  1479. }).join(sep);
  1480. } else {
  1481. return ks + encodeURIComponent(stringifyPrimitive(obj[k]));
  1482. }
  1483. }).join(sep);
  1484. }
  1485. if (!name) { return ''; }
  1486. return encodeURIComponent(stringifyPrimitive(name)) + eq +
  1487. encodeURIComponent(stringifyPrimitive(obj));
  1488. };
  1489. var querystring = createCommonjsModule(function (module, exports) {
  1490. 'use strict';
  1491. exports.decode = exports.parse = decode;
  1492. exports.encode = exports.stringify = encode;
  1493. });
  1494. // Copyright Joyent, Inc. and other Node contributors.
  1495. //
  1496. // Permission is hereby granted, free of charge, to any person obtaining a
  1497. // copy of this software and associated documentation files (the
  1498. // "Software"), to deal in the Software without restriction, including
  1499. // without limitation the rights to use, copy, modify, merge, publish,
  1500. // distribute, sublicense, and/or sell copies of the Software, and to permit
  1501. // persons to whom the Software is furnished to do so, subject to the
  1502. // following conditions:
  1503. //
  1504. // The above copyright notice and this permission notice shall be included
  1505. // in all copies or substantial portions of the Software.
  1506. //
  1507. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  1508. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  1509. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  1510. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  1511. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  1512. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  1513. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  1514. 'use strict';
  1515. var parse = urlParse;
  1516. var resolve = urlResolve;
  1517. var resolveObject = urlResolveObject;
  1518. var format = urlFormat;
  1519. var Url_1 = Url;
  1520. function Url() {
  1521. this.protocol = null;
  1522. this.slashes = null;
  1523. this.auth = null;
  1524. this.host = null;
  1525. this.port = null;
  1526. this.hostname = null;
  1527. this.hash = null;
  1528. this.search = null;
  1529. this.query = null;
  1530. this.pathname = null;
  1531. this.path = null;
  1532. this.href = null;
  1533. }
  1534. // Reference: RFC 3986, RFC 1808, RFC 2396
  1535. // define these here so at least they only have to be
  1536. // compiled once on the first module load.
  1537. var protocolPattern = /^([a-z0-9.+-]+:)/i,
  1538. portPattern = /:[0-9]*$/,
  1539. // Special case for a simple path URL
  1540. simplePathPattern = /^(\/\/?(?!\/)[^\?\s]*)(\?[^\s]*)?$/,
  1541. // RFC 2396: characters reserved for delimiting URLs.
  1542. // We actually just auto-escape these.
  1543. delims = ['<', '>', '"', '`', ' ', '\r', '\n', '\t'],
  1544. // RFC 2396: characters not allowed for various reasons.
  1545. unwise = ['{', '}', '|', '\\', '^', '`'].concat(delims),
  1546. // Allowed by RFCs, but cause of XSS attacks. Always escape these.
  1547. autoEscape = ['\''].concat(unwise),
  1548. // Characters that are never ever allowed in a hostname.
  1549. // Note that any invalid chars are also handled, but these
  1550. // are the ones that are *expected* to be seen, so we fast-path
  1551. // them.
  1552. nonHostChars = ['%', '/', '?', ';', '#'].concat(autoEscape),
  1553. hostEndingChars = ['/', '?', '#'],
  1554. hostnameMaxLen = 255,
  1555. hostnamePartPattern = /^[+a-z0-9A-Z_-]{0,63}$/,
  1556. hostnamePartStart = /^([+a-z0-9A-Z_-]{0,63})(.*)$/,
  1557. // protocols that can allow "unsafe" and "unwise" chars.
  1558. unsafeProtocol = {
  1559. 'javascript': true,
  1560. 'javascript:': true
  1561. },
  1562. // protocols that never have a hostname.
  1563. hostlessProtocol = {
  1564. 'javascript': true,
  1565. 'javascript:': true
  1566. },
  1567. // protocols that always contain a // bit.
  1568. slashedProtocol = {
  1569. 'http': true,
  1570. 'https': true,
  1571. 'ftp': true,
  1572. 'gopher': true,
  1573. 'file': true,
  1574. 'http:': true,
  1575. 'https:': true,
  1576. 'ftp:': true,
  1577. 'gopher:': true,
  1578. 'file:': true
  1579. };
  1580. function urlParse(url, parseQueryString, slashesDenoteHost) {
  1581. if (url && util.isObject(url) && url instanceof Url) { return url; }
  1582. var u = new Url;
  1583. u.parse(url, parseQueryString, slashesDenoteHost);
  1584. return u;
  1585. }
  1586. Url.prototype.parse = function(url, parseQueryString, slashesDenoteHost) {
  1587. if (!util.isString(url)) {
  1588. throw new TypeError("Parameter 'url' must be a string, not " + typeof url);
  1589. }
  1590. // Copy chrome, IE, opera backslash-handling behavior.
  1591. // Back slashes before the query string get converted to forward slashes
  1592. // See: https://code.google.com/p/chromium/issues/detail?id=25916
  1593. var queryIndex = url.indexOf('?'),
  1594. splitter =
  1595. (queryIndex !== -1 && queryIndex < url.indexOf('#')) ? '?' : '#',
  1596. uSplit = url.split(splitter),
  1597. slashRegex = /\\/g;
  1598. uSplit[0] = uSplit[0].replace(slashRegex, '/');
  1599. url = uSplit.join(splitter);
  1600. var rest = url;
  1601. // trim before proceeding.
  1602. // This is to support parse stuff like " http://foo.com \n"
  1603. rest = rest.trim();
  1604. if (!slashesDenoteHost && url.split('#').length === 1) {
  1605. // Try fast path regexp
  1606. var simplePath = simplePathPattern.exec(rest);
  1607. if (simplePath) {
  1608. this.path = rest;
  1609. this.href = rest;
  1610. this.pathname = simplePath[1];
  1611. if (simplePath[2]) {
  1612. this.search = simplePath[2];
  1613. if (parseQueryString) {
  1614. this.query = querystring.parse(this.search.substr(1));
  1615. } else {
  1616. this.query = this.search.substr(1);
  1617. }
  1618. } else if (parseQueryString) {
  1619. this.search = '';
  1620. this.query = {};
  1621. }
  1622. return this;
  1623. }
  1624. }
  1625. var proto = protocolPattern.exec(rest);
  1626. if (proto) {
  1627. proto = proto[0];
  1628. var lowerProto = proto.toLowerCase();
  1629. this.protocol = lowerProto;
  1630. rest = rest.substr(proto.length);
  1631. }
  1632. // figure out if it's got a host
  1633. // user@server is *always* interpreted as a hostname, and url
  1634. // resolution will treat //foo/bar as host=foo,path=bar because that's
  1635. // how the browser resolves relative URLs.
  1636. if (slashesDenoteHost || proto || rest.match(/^\/\/[^@\/]+@[^@\/]+/)) {
  1637. var slashes = rest.substr(0, 2) === '//';
  1638. if (slashes && !(proto && hostlessProtocol[proto])) {
  1639. rest = rest.substr(2);
  1640. this.slashes = true;
  1641. }
  1642. }
  1643. if (!hostlessProtocol[proto] &&
  1644. (slashes || (proto && !slashedProtocol[proto]))) {
  1645. // there's a hostname.
  1646. // the first instance of /, ?, ;, or # ends the host.
  1647. //
  1648. // If there is an @ in the hostname, then non-host chars *are* allowed
  1649. // to the left of the last @ sign, unless some host-ending character
  1650. // comes *before* the @-sign.
  1651. // URLs are obnoxious.
  1652. //
  1653. // ex:
  1654. // http://a@b@c/ => user:a@b host:c
  1655. // http://a@b?@c => user:a host:c path:/?@c
  1656. // v0.12 TODO(isaacs): This is not quite how Chrome does things.
  1657. // Review our test case against browsers more comprehensively.
  1658. // find the first instance of any hostEndingChars
  1659. var hostEnd = -1;
  1660. for (var i = 0; i < hostEndingChars.length; i++) {
  1661. var hec = rest.indexOf(hostEndingChars[i]);
  1662. if (hec !== -1 && (hostEnd === -1 || hec < hostEnd))
  1663. { hostEnd = hec; }
  1664. }
  1665. // at this point, either we have an explicit point where the
  1666. // auth portion cannot go past, or the last @ char is the decider.
  1667. var auth, atSign;
  1668. if (hostEnd === -1) {
  1669. // atSign can be anywhere.
  1670. atSign = rest.lastIndexOf('@');
  1671. } else {
  1672. // atSign must be in auth portion.
  1673. // http://a@b/c@d => host:b auth:a path:/c@d
  1674. atSign = rest.lastIndexOf('@', hostEnd);
  1675. }
  1676. // Now we have a portion which is definitely the auth.
  1677. // Pull that off.
  1678. if (atSign !== -1) {
  1679. auth = rest.slice(0, atSign);
  1680. rest = rest.slice(atSign + 1);
  1681. this.auth = decodeURIComponent(auth);
  1682. }
  1683. // the host is the remaining to the left of the first non-host char
  1684. hostEnd = -1;
  1685. for (var i = 0; i < nonHostChars.length; i++) {
  1686. var hec = rest.indexOf(nonHostChars[i]);
  1687. if (hec !== -1 && (hostEnd === -1 || hec < hostEnd))
  1688. { hostEnd = hec; }
  1689. }
  1690. // if we still have not hit it, then the entire thing is a host.
  1691. if (hostEnd === -1)
  1692. { hostEnd = rest.length; }
  1693. this.host = rest.slice(0, hostEnd);
  1694. rest = rest.slice(hostEnd);
  1695. // pull out port.
  1696. this.parseHost();
  1697. // we've indicated that there is a hostname,
  1698. // so even if it's empty, it has to be present.
  1699. this.hostname = this.hostname || '';
  1700. // if hostname begins with [ and ends with ]
  1701. // assume that it's an IPv6 address.
  1702. var ipv6Hostname = this.hostname[0] === '[' &&
  1703. this.hostname[this.hostname.length - 1] === ']';
  1704. // validate a little.
  1705. if (!ipv6Hostname) {
  1706. var hostparts = this.hostname.split(/\./);
  1707. for (var i = 0, l = hostparts.length; i < l; i++) {
  1708. var part = hostparts[i];
  1709. if (!part) { continue; }
  1710. if (!part.match(hostnamePartPattern)) {
  1711. var newpart = '';
  1712. for (var j = 0, k = part.length; j < k; j++) {
  1713. if (part.charCodeAt(j) > 127) {
  1714. // we replace non-ASCII char with a temporary placeholder
  1715. // we need this to make sure size of hostname is not
  1716. // broken by replacing non-ASCII by nothing
  1717. newpart += 'x';
  1718. } else {
  1719. newpart += part[j];
  1720. }
  1721. }
  1722. // we test again with ASCII char only
  1723. if (!newpart.match(hostnamePartPattern)) {
  1724. var validParts = hostparts.slice(0, i);
  1725. var notHost = hostparts.slice(i + 1);
  1726. var bit = part.match(hostnamePartStart);
  1727. if (bit) {
  1728. validParts.push(bit[1]);
  1729. notHost.unshift(bit[2]);
  1730. }
  1731. if (notHost.length) {
  1732. rest = '/' + notHost.join('.') + rest;
  1733. }
  1734. this.hostname = validParts.join('.');
  1735. break;
  1736. }
  1737. }
  1738. }
  1739. }
  1740. if (this.hostname.length > hostnameMaxLen) {
  1741. this.hostname = '';
  1742. } else {
  1743. // hostnames are always lower case.
  1744. this.hostname = this.hostname.toLowerCase();
  1745. }
  1746. if (!ipv6Hostname) {
  1747. // IDNA Support: Returns a punycoded representation of "domain".
  1748. // It only converts parts of the domain name that
  1749. // have non-ASCII characters, i.e. it doesn't matter if
  1750. // you call it with a domain that already is ASCII-only.
  1751. this.hostname = punycode.toASCII(this.hostname);
  1752. }
  1753. var p = this.port ? ':' + this.port : '';
  1754. var h = this.hostname || '';
  1755. this.host = h + p;
  1756. this.href += this.host;
  1757. // strip [ and ] from the hostname
  1758. // the host field still retains them, though
  1759. if (ipv6Hostname) {
  1760. this.hostname = this.hostname.substr(1, this.hostname.length - 2);
  1761. if (rest[0] !== '/') {
  1762. rest = '/' + rest;
  1763. }
  1764. }
  1765. }
  1766. // now rest is set to the post-host stuff.
  1767. // chop off any delim chars.
  1768. if (!unsafeProtocol[lowerProto]) {
  1769. // First, make 100% sure that any "autoEscape" chars get
  1770. // escaped, even if encodeURIComponent doesn't think they
  1771. // need to be.
  1772. for (var i = 0, l = autoEscape.length; i < l; i++) {
  1773. var ae = autoEscape[i];
  1774. if (rest.indexOf(ae) === -1)
  1775. { continue; }
  1776. var esc = encodeURIComponent(ae);
  1777. if (esc === ae) {
  1778. esc = escape(ae);
  1779. }
  1780. rest = rest.split(ae).join(esc);
  1781. }
  1782. }
  1783. // chop off from the tail first.
  1784. var hash = rest.indexOf('#');
  1785. if (hash !== -1) {
  1786. // got a fragment string.
  1787. this.hash = rest.substr(hash);
  1788. rest = rest.slice(0, hash);
  1789. }
  1790. var qm = rest.indexOf('?');
  1791. if (qm !== -1) {
  1792. this.search = rest.substr(qm);
  1793. this.query = rest.substr(qm + 1);
  1794. if (parseQueryString) {
  1795. this.query = querystring.parse(this.query);
  1796. }
  1797. rest = rest.slice(0, qm);
  1798. } else if (parseQueryString) {
  1799. // no query string, but parseQueryString still requested
  1800. this.search = '';
  1801. this.query = {};
  1802. }
  1803. if (rest) { this.pathname = rest; }
  1804. if (slashedProtocol[lowerProto] &&
  1805. this.hostname && !this.pathname) {
  1806. this.pathname = '/';
  1807. }
  1808. //to support http.request
  1809. if (this.pathname || this.search) {
  1810. var p = this.pathname || '';
  1811. var s = this.search || '';
  1812. this.path = p + s;
  1813. }
  1814. // finally, reconstruct the href based on what has been validated.
  1815. this.href = this.format();
  1816. return this;
  1817. };
  1818. // format a parsed object into a url string
  1819. function urlFormat(obj) {
  1820. // ensure it's an object, and not a string url.
  1821. // If it's an obj, this is a no-op.
  1822. // this way, you can call url_format() on strings
  1823. // to clean up potentially wonky urls.
  1824. if (util.isString(obj)) { obj = urlParse(obj); }
  1825. if (!(obj instanceof Url)) { return Url.prototype.format.call(obj); }
  1826. return obj.format();
  1827. }
  1828. Url.prototype.format = function() {
  1829. var auth = this.auth || '';
  1830. if (auth) {
  1831. auth = encodeURIComponent(auth);
  1832. auth = auth.replace(/%3A/i, ':');
  1833. auth += '@';
  1834. }
  1835. var protocol = this.protocol || '',
  1836. pathname = this.pathname || '',
  1837. hash = this.hash || '',
  1838. host = false,
  1839. query = '';
  1840. if (this.host) {
  1841. host = auth + this.host;
  1842. } else if (this.hostname) {
  1843. host = auth + (this.hostname.indexOf(':') === -1 ?
  1844. this.hostname :
  1845. '[' + this.hostname + ']');
  1846. if (this.port) {
  1847. host += ':' + this.port;
  1848. }
  1849. }
  1850. if (this.query &&
  1851. util.isObject(this.query) &&
  1852. Object.keys(this.query).length) {
  1853. query = querystring.stringify(this.query);
  1854. }
  1855. var search = this.search || (query && ('?' + query)) || '';
  1856. if (protocol && protocol.substr(-1) !== ':') { protocol += ':'; }
  1857. // only the slashedProtocols get the //. Not mailto:, xmpp:, etc.
  1858. // unless they had them to begin with.
  1859. if (this.slashes ||
  1860. (!protocol || slashedProtocol[protocol]) && host !== false) {
  1861. host = '//' + (host || '');
  1862. if (pathname && pathname.charAt(0) !== '/') { pathname = '/' + pathname; }
  1863. } else if (!host) {
  1864. host = '';
  1865. }
  1866. if (hash && hash.charAt(0) !== '#') { hash = '#' + hash; }
  1867. if (search && search.charAt(0) !== '?') { search = '?' + search; }
  1868. pathname = pathname.replace(/[?#]/g, function(match) {
  1869. return encodeURIComponent(match);
  1870. });
  1871. search = search.replace('#', '%23');
  1872. return protocol + host + pathname + search + hash;
  1873. };
  1874. function urlResolve(source, relative) {
  1875. return urlParse(source, false, true).resolve(relative);
  1876. }
  1877. Url.prototype.resolve = function(relative) {
  1878. return this.resolveObject(urlParse(relative, false, true)).format();
  1879. };
  1880. function urlResolveObject(source, relative) {
  1881. if (!source) { return relative; }
  1882. return urlParse(source, false, true).resolveObject(relative);
  1883. }
  1884. Url.prototype.resolveObject = function(relative) {
  1885. if (util.isString(relative)) {
  1886. var rel = new Url();
  1887. rel.parse(relative, false, true);
  1888. relative = rel;
  1889. }
  1890. var result = new Url();
  1891. var tkeys = Object.keys(this);
  1892. for (var tk = 0; tk < tkeys.length; tk++) {
  1893. var tkey = tkeys[tk];
  1894. result[tkey] = this[tkey];
  1895. }
  1896. // hash is always overridden, no matter what.
  1897. // even href="" will remove it.
  1898. result.hash = relative.hash;
  1899. // if the relative url is empty, then there's nothing left to do here.
  1900. if (relative.href === '') {
  1901. result.href = result.format();
  1902. return result;
  1903. }
  1904. // hrefs like //foo/bar always cut to the protocol.
  1905. if (relative.slashes && !relative.protocol) {
  1906. // take everything except the protocol from relative
  1907. var rkeys = Object.keys(relative);
  1908. for (var rk = 0; rk < rkeys.length; rk++) {
  1909. var rkey = rkeys[rk];
  1910. if (rkey !== 'protocol')
  1911. { result[rkey] = relative[rkey]; }
  1912. }
  1913. //urlParse appends trailing / to urls like http://www.example.com
  1914. if (slashedProtocol[result.protocol] &&
  1915. result.hostname && !result.pathname) {
  1916. result.path = result.pathname = '/';
  1917. }
  1918. result.href = result.format();
  1919. return result;
  1920. }
  1921. if (relative.protocol && relative.protocol !== result.protocol) {
  1922. // if it's a known url protocol, then changing
  1923. // the protocol does weird things
  1924. // first, if it's not file:, then we MUST have a host,
  1925. // and if there was a path
  1926. // to begin with, then we MUST have a path.
  1927. // if it is file:, then the host is dropped,
  1928. // because that's known to be hostless.
  1929. // anything else is assumed to be absolute.
  1930. if (!slashedProtocol[relative.protocol]) {
  1931. var keys = Object.keys(relative);
  1932. for (var v = 0; v < keys.length; v++) {
  1933. var k = keys[v];
  1934. result[k] = relative[k];
  1935. }
  1936. result.href = result.format();
  1937. return result;
  1938. }
  1939. result.protocol = relative.protocol;
  1940. if (!relative.host && !hostlessProtocol[relative.protocol]) {
  1941. var relPath = (relative.pathname || '').split('/');
  1942. while (relPath.length && !(relative.host = relPath.shift())){ ; }
  1943. if (!relative.host) { relative.host = ''; }
  1944. if (!relative.hostname) { relative.hostname = ''; }
  1945. if (relPath[0] !== '') { relPath.unshift(''); }
  1946. if (relPath.length < 2) { relPath.unshift(''); }
  1947. result.pathname = relPath.join('/');
  1948. } else {
  1949. result.pathname = relative.pathname;
  1950. }
  1951. result.search = relative.search;
  1952. result.query = relative.query;
  1953. result.host = relative.host || '';
  1954. result.auth = relative.auth;
  1955. result.hostname = relative.hostname || relative.host;
  1956. result.port = relative.port;
  1957. // to support http.request
  1958. if (result.pathname || result.search) {
  1959. var p = result.pathname || '';
  1960. var s = result.search || '';
  1961. result.path = p + s;
  1962. }
  1963. result.slashes = result.slashes || relative.slashes;
  1964. result.href = result.format();
  1965. return result;
  1966. }
  1967. var isSourceAbs = (result.pathname && result.pathname.charAt(0) === '/'),
  1968. isRelAbs = (
  1969. relative.host ||
  1970. relative.pathname && relative.pathname.charAt(0) === '/'
  1971. ),
  1972. mustEndAbs = (isRelAbs || isSourceAbs ||
  1973. (result.host && relative.pathname)),
  1974. removeAllDots = mustEndAbs,
  1975. srcPath = result.pathname && result.pathname.split('/') || [],
  1976. relPath = relative.pathname && relative.pathname.split('/') || [],
  1977. psychotic = result.protocol && !slashedProtocol[result.protocol];
  1978. // if the url is a non-slashed url, then relative
  1979. // links like ../.. should be able
  1980. // to crawl up to the hostname, as well. This is strange.
  1981. // result.protocol has already been set by now.
  1982. // Later on, put the first path part into the host field.
  1983. if (psychotic) {
  1984. result.hostname = '';
  1985. result.port = null;
  1986. if (result.host) {
  1987. if (srcPath[0] === '') { srcPath[0] = result.host; }
  1988. else { srcPath.unshift(result.host); }
  1989. }
  1990. result.host = '';
  1991. if (relative.protocol) {
  1992. relative.hostname = null;
  1993. relative.port = null;
  1994. if (relative.host) {
  1995. if (relPath[0] === '') { relPath[0] = relative.host; }
  1996. else { relPath.unshift(relative.host); }
  1997. }
  1998. relative.host = null;
  1999. }
  2000. mustEndAbs = mustEndAbs && (relPath[0] === '' || srcPath[0] === '');
  2001. }
  2002. if (isRelAbs) {
  2003. // it's absolute.
  2004. result.host = (relative.host || relative.host === '') ?
  2005. relative.host : result.host;
  2006. result.hostname = (relative.hostname || relative.hostname === '') ?
  2007. relative.hostname : result.hostname;
  2008. result.search = relative.search;
  2009. result.query = relative.query;
  2010. srcPath = relPath;
  2011. // fall through to the dot-handling below.
  2012. } else if (relPath.length) {
  2013. // it's relative
  2014. // throw away the existing file, and take the new path instead.
  2015. if (!srcPath) { srcPath = []; }
  2016. srcPath.pop();
  2017. srcPath = srcPath.concat(relPath);
  2018. result.search = relative.search;
  2019. result.query = relative.query;
  2020. } else if (!util.isNullOrUndefined(relative.search)) {
  2021. // just pull out the search.
  2022. // like href='?foo'.
  2023. // Put this after the other two cases because it simplifies the booleans
  2024. if (psychotic) {
  2025. result.hostname = result.host = srcPath.shift();
  2026. //occationaly the auth can get stuck only in host
  2027. //this especially happens in cases like
  2028. //url.resolveObject('mailto:local1@domain1', 'local2@domain2')
  2029. var authInHost = result.host && result.host.indexOf('@') > 0 ?
  2030. result.host.split('@') : false;
  2031. if (authInHost) {
  2032. result.auth = authInHost.shift();
  2033. result.host = result.hostname = authInHost.shift();
  2034. }
  2035. }
  2036. result.search = relative.search;
  2037. result.query = relative.query;
  2038. //to support http.request
  2039. if (!util.isNull(result.pathname) || !util.isNull(result.search)) {
  2040. result.path = (result.pathname ? result.pathname : '') +
  2041. (result.search ? result.search : '');
  2042. }
  2043. result.href = result.format();
  2044. return result;
  2045. }
  2046. if (!srcPath.length) {
  2047. // no path at all. easy.
  2048. // we've already handled the other stuff above.
  2049. result.pathname = null;
  2050. //to support http.request
  2051. if (result.search) {
  2052. result.path = '/' + result.search;
  2053. } else {
  2054. result.path = null;
  2055. }
  2056. result.href = result.format();
  2057. return result;
  2058. }
  2059. // if a url ENDs in . or .., then it must get a trailing slash.
  2060. // however, if it ends in anything else non-slashy,
  2061. // then it must NOT get a trailing slash.
  2062. var last = srcPath.slice(-1)[0];
  2063. var hasTrailingSlash = (
  2064. (result.host || relative.host || srcPath.length > 1) &&
  2065. (last === '.' || last === '..') || last === '');
  2066. // strip single dots, resolve double dots to parent dir
  2067. // if the path tries to go above the root, `up` ends up > 0
  2068. var up = 0;
  2069. for (var i = srcPath.length; i >= 0; i--) {
  2070. last = srcPath[i];
  2071. if (last === '.') {
  2072. srcPath.splice(i, 1);
  2073. } else if (last === '..') {
  2074. srcPath.splice(i, 1);
  2075. up++;
  2076. } else if (up) {
  2077. srcPath.splice(i, 1);
  2078. up--;
  2079. }
  2080. }
  2081. // if the path is allowed to go above the root, restore leading ..s
  2082. if (!mustEndAbs && !removeAllDots) {
  2083. for (; up--; up) {
  2084. srcPath.unshift('..');
  2085. }
  2086. }
  2087. if (mustEndAbs && srcPath[0] !== '' &&
  2088. (!srcPath[0] || srcPath[0].charAt(0) !== '/')) {
  2089. srcPath.unshift('');
  2090. }
  2091. if (hasTrailingSlash && (srcPath.join('/').substr(-1) !== '/')) {
  2092. srcPath.push('');
  2093. }
  2094. var isAbsolute = srcPath[0] === '' ||
  2095. (srcPath[0] && srcPath[0].charAt(0) === '/');
  2096. // put the host back
  2097. if (psychotic) {
  2098. result.hostname = result.host = isAbsolute ? '' :
  2099. srcPath.length ? srcPath.shift() : '';
  2100. //occationaly the auth can get stuck only in host
  2101. //this especially happens in cases like
  2102. //url.resolveObject('mailto:local1@domain1', 'local2@domain2')
  2103. var authInHost = result.host && result.host.indexOf('@') > 0 ?
  2104. result.host.split('@') : false;
  2105. if (authInHost) {
  2106. result.auth = authInHost.shift();
  2107. result.host = result.hostname = authInHost.shift();
  2108. }
  2109. }
  2110. mustEndAbs = mustEndAbs || (result.host && srcPath.length);
  2111. if (mustEndAbs && !isAbsolute) {
  2112. srcPath.unshift('');
  2113. }
  2114. if (!srcPath.length) {
  2115. result.pathname = null;
  2116. result.path = null;
  2117. } else {
  2118. result.pathname = srcPath.join('/');
  2119. }
  2120. //to support request.http
  2121. if (!util.isNull(result.pathname) || !util.isNull(result.search)) {
  2122. result.path = (result.pathname ? result.pathname : '') +
  2123. (result.search ? result.search : '');
  2124. }
  2125. result.auth = relative.auth || result.auth;
  2126. result.slashes = result.slashes || relative.slashes;
  2127. result.href = result.format();
  2128. return result;
  2129. };
  2130. Url.prototype.parseHost = function() {
  2131. var host = this.host;
  2132. var port = portPattern.exec(host);
  2133. if (port) {
  2134. port = port[0];
  2135. if (port !== ':') {
  2136. this.port = port.substr(1);
  2137. }
  2138. host = host.substr(0, host.length - port.length);
  2139. }
  2140. if (host) { this.hostname = host; }
  2141. };
  2142. var url$1 = {
  2143. parse: parse,
  2144. resolve: resolve,
  2145. resolveObject: resolveObject,
  2146. format: format,
  2147. Url: Url_1
  2148. };
  2149. /**
  2150. * This file contains redeclared types for Node `url` and `querystring` modules. These modules
  2151. * don't provide their own typings but instead are a part of the full Node typings. The purpose of
  2152. * this file is to redeclare the required types to avoid having the whole Node types as a
  2153. * dependency.
  2154. */
  2155. var url = {
  2156. parse: parse,
  2157. format: format,
  2158. resolve: resolve,
  2159. };
  2160. function assertPath(path) {
  2161. if (typeof path !== 'string') {
  2162. throw new TypeError("Path must be a string. Received " + JSON.stringify(path));
  2163. }
  2164. }
  2165. function removeUrlParams(url) {
  2166. var re = url.split('?')[0];
  2167. return re.split('#')[0];
  2168. }
  2169. function escapeRegExp(string) {
  2170. return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string
  2171. }
  2172. function replaceAll(str, find, replace) {
  2173. return str.replace(new RegExp(escapeRegExp(find), 'g'), replace);
  2174. }
  2175. // Resolves . and .. elements in a path with directory names
  2176. function normalizeStringPosix(path, allowAboveRoot) {
  2177. var res = '';
  2178. var lastSegmentLength = 0;
  2179. var lastSlash = -1;
  2180. var dots = 0;
  2181. var code;
  2182. for (var i = 0; i <= path.length; ++i) {
  2183. if (i < path.length) {
  2184. code = path.charCodeAt(i);
  2185. }
  2186. else if (code === 47) {
  2187. break;
  2188. }
  2189. else {
  2190. code = 47;
  2191. }
  2192. if (code === 47) {
  2193. if (lastSlash === i - 1 || dots === 1) {
  2194. // NOOP
  2195. }
  2196. else if (lastSlash !== i - 1 && dots === 2) {
  2197. if (res.length < 2
  2198. || lastSegmentLength !== 2
  2199. || res.charCodeAt(res.length - 1) !== 46
  2200. || res.charCodeAt(res.length - 2) !== 46) {
  2201. if (res.length > 2) {
  2202. var lastSlashIndex = res.lastIndexOf('/');
  2203. if (lastSlashIndex !== res.length - 1) {
  2204. if (lastSlashIndex === -1) {
  2205. res = '';
  2206. lastSegmentLength = 0;
  2207. }
  2208. else {
  2209. res = res.slice(0, lastSlashIndex);
  2210. lastSegmentLength = res.length - 1 - res.lastIndexOf('/');
  2211. }
  2212. lastSlash = i;
  2213. dots = 0;
  2214. continue;
  2215. }
  2216. }
  2217. else if (res.length === 2 || res.length === 1) {
  2218. res = '';
  2219. lastSegmentLength = 0;
  2220. lastSlash = i;
  2221. dots = 0;
  2222. continue;
  2223. }
  2224. }
  2225. if (allowAboveRoot) {
  2226. if (res.length > 0) {
  2227. res += '/..';
  2228. }
  2229. else {
  2230. res = '..';
  2231. }
  2232. lastSegmentLength = 2;
  2233. }
  2234. }
  2235. else {
  2236. if (res.length > 0) {
  2237. res += "/" + path.slice(lastSlash + 1, i);
  2238. }
  2239. else {
  2240. res = path.slice(lastSlash + 1, i);
  2241. }
  2242. lastSegmentLength = i - lastSlash - 1;
  2243. }
  2244. lastSlash = i;
  2245. dots = 0;
  2246. }
  2247. else if (code === 46 && dots !== -1) {
  2248. ++dots;
  2249. }
  2250. else {
  2251. dots = -1;
  2252. }
  2253. }
  2254. return res;
  2255. }
  2256. var path = {
  2257. /**
  2258. * Converts a path to posix format.
  2259. * @param path - The path to convert to posix
  2260. */
  2261. toPosix: function (path) { return replaceAll(path, '\\', '/'); },
  2262. /**
  2263. * Checks if the path is a URL
  2264. * @param path - The path to check
  2265. */
  2266. isUrl: function (path) { return (/^https?:/).test(this.toPosix(path)); },
  2267. /**
  2268. * Checks if the path is a data URL
  2269. * @param path - The path to check
  2270. */
  2271. isDataUrl: function (path) {
  2272. // eslint-disable-next-line max-len
  2273. return (/^data:([a-z]+\/[a-z0-9-+.]+(;[a-z0-9-.!#$%*+.{}|~`]+=[a-z0-9-.!#$%*+.{}()_|~`]+)*)?(;base64)?,([a-z0-9!$&',()*+;=\-._~:@\/?%\s<>]*?)$/i)
  2274. .test(path);
  2275. },
  2276. /**
  2277. * Checks if the path has a protocol e.g. http://
  2278. * This will return true for windows file paths
  2279. * @param path - The path to check
  2280. */
  2281. hasProtocol: function (path) { return (/^[^/:]+:\//).test(this.toPosix(path)); },
  2282. /**
  2283. * Returns the protocol of the path e.g. http://, C:/, file:///
  2284. * @param path - The path to get the protocol from
  2285. */
  2286. getProtocol: function (path) {
  2287. assertPath(path);
  2288. path = this.toPosix(path);
  2289. var protocol = '';
  2290. var isFile = (/^file:\/\/\//).exec(path);
  2291. var isHttp = (/^[^/:]+:\/\//).exec(path);
  2292. var isWindows = (/^[^/:]+:\//).exec(path);
  2293. if (isFile || isHttp || isWindows) {
  2294. var arr = (isFile === null || isFile === void 0 ? void 0 : isFile[0]) || (isHttp === null || isHttp === void 0 ? void 0 : isHttp[0]) || (isWindows === null || isWindows === void 0 ? void 0 : isWindows[0]);
  2295. protocol = arr;
  2296. path = path.slice(arr.length);
  2297. }
  2298. return protocol;
  2299. },
  2300. /**
  2301. * Converts URL to an absolute path.
  2302. * When loading from a Web Worker, we must use absolute paths.
  2303. * If the URL is already absolute we return it as is
  2304. * If it's not, we convert it
  2305. * @param url - The URL to test
  2306. * @param customBaseUrl - The base URL to use
  2307. * @param customRootUrl - The root URL to use
  2308. */
  2309. toAbsolute: function (url, customBaseUrl, customRootUrl) {
  2310. if (this.isDataUrl(url))
  2311. { return url; }
  2312. var baseUrl = removeUrlParams(this.toPosix(customBaseUrl !== null && customBaseUrl !== void 0 ? customBaseUrl : settings.settings.ADAPTER.getBaseUrl()));
  2313. var rootUrl = removeUrlParams(this.toPosix(customRootUrl !== null && customRootUrl !== void 0 ? customRootUrl : this.rootname(baseUrl)));
  2314. assertPath(url);
  2315. url = this.toPosix(url);
  2316. // root relative url
  2317. if (url.startsWith('/')) {
  2318. return path.join(rootUrl, url.slice(1));
  2319. }
  2320. var absolutePath = this.isAbsolute(url) ? url : this.join(baseUrl, url);
  2321. return absolutePath;
  2322. },
  2323. /**
  2324. * Normalizes the given path, resolving '..' and '.' segments
  2325. * @param path - The path to normalize
  2326. */
  2327. normalize: function (path) {
  2328. path = this.toPosix(path);
  2329. assertPath(path);
  2330. if (path.length === 0)
  2331. { return '.'; }
  2332. var protocol = '';
  2333. var isAbsolute = path.startsWith('/');
  2334. if (this.hasProtocol(path)) {
  2335. protocol = this.rootname(path);
  2336. path = path.slice(protocol.length);
  2337. }
  2338. var trailingSeparator = path.endsWith('/');
  2339. // Normalize the path
  2340. path = normalizeStringPosix(path, false);
  2341. if (path.length > 0 && trailingSeparator)
  2342. { path += '/'; }
  2343. if (isAbsolute)
  2344. { return "/" + path; }
  2345. return protocol + path;
  2346. },
  2347. /**
  2348. * Determines if path is an absolute path.
  2349. * Absolute paths can be urls, data urls, or paths on disk
  2350. * @param path - The path to test
  2351. */
  2352. isAbsolute: function (path) {
  2353. assertPath(path);
  2354. path = this.toPosix(path);
  2355. if (this.hasProtocol(path))
  2356. { return true; }
  2357. return path.startsWith('/');
  2358. },
  2359. /**
  2360. * Joins all given path segments together using the platform-specific separator as a delimiter,
  2361. * then normalizes the resulting path
  2362. * @param segments - The segments of the path to join
  2363. */
  2364. join: function () {
  2365. var arguments$1 = arguments;
  2366. var _a;
  2367. var segments = [];
  2368. for (var _i = 0; _i < arguments.length; _i++) {
  2369. segments[_i] = arguments$1[_i];
  2370. }
  2371. if (segments.length === 0) {
  2372. return '.';
  2373. }
  2374. var joined;
  2375. for (var i = 0; i < segments.length; ++i) {
  2376. var arg = segments[i];
  2377. assertPath(arg);
  2378. if (arg.length > 0) {
  2379. if (joined === undefined)
  2380. { joined = arg; }
  2381. else {
  2382. var prevArg = (_a = segments[i - 1]) !== null && _a !== void 0 ? _a : '';
  2383. if (this.extname(prevArg)) {
  2384. joined += "/../" + arg;
  2385. }
  2386. else {
  2387. joined += "/" + arg;
  2388. }
  2389. }
  2390. }
  2391. }
  2392. if (joined === undefined) {
  2393. return '.';
  2394. }
  2395. return this.normalize(joined);
  2396. },
  2397. /**
  2398. * Returns the directory name of a path
  2399. * @param path - The path to parse
  2400. */
  2401. dirname: function (path) {
  2402. assertPath(path);
  2403. if (path.length === 0)
  2404. { return '.'; }
  2405. path = this.toPosix(path);
  2406. var code = path.charCodeAt(0);
  2407. var hasRoot = code === 47;
  2408. var end = -1;
  2409. var matchedSlash = true;
  2410. var proto = this.getProtocol(path);
  2411. var origpath = path;
  2412. path = path.slice(proto.length);
  2413. for (var i = path.length - 1; i >= 1; --i) {
  2414. code = path.charCodeAt(i);
  2415. if (code === 47) {
  2416. if (!matchedSlash) {
  2417. end = i;
  2418. break;
  2419. }
  2420. }
  2421. else {
  2422. // We saw the first non-path separator
  2423. matchedSlash = false;
  2424. }
  2425. }
  2426. // if end is -1 and its a url then we need to add the path back
  2427. // eslint-disable-next-line no-nested-ternary
  2428. if (end === -1)
  2429. { return hasRoot ? '/' : this.isUrl(origpath) ? proto + path : proto; }
  2430. if (hasRoot && end === 1)
  2431. { return '//'; }
  2432. return proto + path.slice(0, end);
  2433. },
  2434. /**
  2435. * Returns the root of the path e.g. /, C:/, file:///, http://domain.com/
  2436. * @param path - The path to parse
  2437. */
  2438. rootname: function (path) {
  2439. assertPath(path);
  2440. path = this.toPosix(path);
  2441. var root = '';
  2442. if (path.startsWith('/'))
  2443. { root = '/'; }
  2444. else {
  2445. root = this.getProtocol(path);
  2446. }
  2447. if (this.isUrl(path)) {
  2448. // need to find the first path separator
  2449. var index = path.indexOf('/', root.length);
  2450. if (index !== -1) {
  2451. root = path.slice(0, index);
  2452. }
  2453. else
  2454. { root = path; }
  2455. if (!root.endsWith('/'))
  2456. { root += '/'; }
  2457. }
  2458. return root;
  2459. },
  2460. /**
  2461. * Returns the last portion of a path
  2462. * @param path - The path to test
  2463. * @param ext - Optional extension to remove
  2464. */
  2465. basename: function (path, ext) {
  2466. assertPath(path);
  2467. if (ext)
  2468. { assertPath(ext); }
  2469. path = this.toPosix(path);
  2470. var start = 0;
  2471. var end = -1;
  2472. var matchedSlash = true;
  2473. var i;
  2474. if (ext !== undefined && ext.length > 0 && ext.length <= path.length) {
  2475. if (ext.length === path.length && ext === path)
  2476. { return ''; }
  2477. var extIdx = ext.length - 1;
  2478. var firstNonSlashEnd = -1;
  2479. for (i = path.length - 1; i >= 0; --i) {
  2480. var code = path.charCodeAt(i);
  2481. if (code === 47) {
  2482. // If we reached a path separator that was not part of a set of path
  2483. // separators at the end of the string, stop now
  2484. if (!matchedSlash) {
  2485. start = i + 1;
  2486. break;
  2487. }
  2488. }
  2489. else {
  2490. if (firstNonSlashEnd === -1) {
  2491. // We saw the first non-path separator, remember this index in case
  2492. // we need it if the extension ends up not matching
  2493. matchedSlash = false;
  2494. firstNonSlashEnd = i + 1;
  2495. }
  2496. if (extIdx >= 0) {
  2497. // Try to match the explicit extension
  2498. if (code === ext.charCodeAt(extIdx)) {
  2499. if (--extIdx === -1) {
  2500. // We matched the extension, so mark this as the end of our path
  2501. // component
  2502. end = i;
  2503. }
  2504. }
  2505. else {
  2506. // Extension does not match, so our result is the entire path
  2507. // component
  2508. extIdx = -1;
  2509. end = firstNonSlashEnd;
  2510. }
  2511. }
  2512. }
  2513. }
  2514. if (start === end)
  2515. { end = firstNonSlashEnd; }
  2516. else if (end === -1)
  2517. { end = path.length; }
  2518. return path.slice(start, end);
  2519. }
  2520. for (i = path.length - 1; i >= 0; --i) {
  2521. if (path.charCodeAt(i) === 47) {
  2522. // If we reached a path separator that was not part of a set of path
  2523. // separators at the end of the string, stop now
  2524. if (!matchedSlash) {
  2525. start = i + 1;
  2526. break;
  2527. }
  2528. }
  2529. else if (end === -1) {
  2530. // We saw the first non-path separator, mark this as the end of our
  2531. // path component
  2532. matchedSlash = false;
  2533. end = i + 1;
  2534. }
  2535. }
  2536. if (end === -1)
  2537. { return ''; }
  2538. return path.slice(start, end);
  2539. },
  2540. /**
  2541. * Returns the extension of the path, from the last occurrence of the . (period) character to end of string in the last
  2542. * portion of the path. If there is no . in the last portion of the path, or if there are no . characters other than
  2543. * the first character of the basename of path, an empty string is returned.
  2544. * @param path - The path to parse
  2545. */
  2546. extname: function (path) {
  2547. assertPath(path);
  2548. path = this.toPosix(path);
  2549. var startDot = -1;
  2550. var startPart = 0;
  2551. var end = -1;
  2552. var matchedSlash = true;
  2553. // Track the state of characters (if any) we see before our first dot and
  2554. // after any path separator we find
  2555. var preDotState = 0;
  2556. for (var i = path.length - 1; i >= 0; --i) {
  2557. var code = path.charCodeAt(i);
  2558. if (code === 47) {
  2559. // If we reached a path separator that was not part of a set of path
  2560. // separators at the end of the string, stop now
  2561. if (!matchedSlash) {
  2562. startPart = i + 1;
  2563. break;
  2564. }
  2565. continue;
  2566. }
  2567. if (end === -1) {
  2568. // We saw the first non-path separator, mark this as the end of our
  2569. // extension
  2570. matchedSlash = false;
  2571. end = i + 1;
  2572. }
  2573. if (code === 46) {
  2574. // If this is our first dot, mark it as the start of our extension
  2575. if (startDot === -1)
  2576. { startDot = i; }
  2577. else if (preDotState !== 1)
  2578. { preDotState = 1; }
  2579. }
  2580. else if (startDot !== -1) {
  2581. // We saw a non-dot and non-path separator before our dot, so we should
  2582. // have a good chance at having a non-empty extension
  2583. preDotState = -1;
  2584. }
  2585. }
  2586. if (startDot === -1 || end === -1
  2587. // We saw a non-dot character immediately before the dot
  2588. || preDotState === 0
  2589. // The (right-most) trimmed path component is exactly '..'
  2590. // eslint-disable-next-line no-mixed-operators
  2591. || preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) {
  2592. return '';
  2593. }
  2594. return path.slice(startDot, end);
  2595. },
  2596. /**
  2597. * Parses a path into an object containing the 'root', `dir`, `base`, `ext`, and `name` properties.
  2598. * @param path - The path to parse
  2599. */
  2600. parse: function (path) {
  2601. assertPath(path);
  2602. var ret = { root: '', dir: '', base: '', ext: '', name: '' };
  2603. if (path.length === 0)
  2604. { return ret; }
  2605. path = this.toPosix(path);
  2606. var code = path.charCodeAt(0);
  2607. var isAbsolute = this.isAbsolute(path);
  2608. var start;
  2609. var protocol = '';
  2610. ret.root = this.rootname(path);
  2611. if (isAbsolute || this.hasProtocol(path)) {
  2612. start = 1;
  2613. }
  2614. else {
  2615. start = 0;
  2616. }
  2617. var startDot = -1;
  2618. var startPart = 0;
  2619. var end = -1;
  2620. var matchedSlash = true;
  2621. var i = path.length - 1;
  2622. // Track the state of characters (if any) we see before our first dot and
  2623. // after any path separator we find
  2624. var preDotState = 0;
  2625. // Get non-dir info
  2626. for (; i >= start; --i) {
  2627. code = path.charCodeAt(i);
  2628. if (code === 47) {
  2629. // If we reached a path separator that was not part of a set of path
  2630. // separators at the end of the string, stop now
  2631. if (!matchedSlash) {
  2632. startPart = i + 1;
  2633. break;
  2634. }
  2635. continue;
  2636. }
  2637. if (end === -1) {
  2638. // We saw the first non-path separator, mark this as the end of our
  2639. // extension
  2640. matchedSlash = false;
  2641. end = i + 1;
  2642. }
  2643. if (code === 46) {
  2644. // If this is our first dot, mark it as the start of our extension
  2645. if (startDot === -1)
  2646. { startDot = i; }
  2647. else if (preDotState !== 1)
  2648. { preDotState = 1; }
  2649. }
  2650. else if (startDot !== -1) {
  2651. // We saw a non-dot and non-path separator before our dot, so we should
  2652. // have a good chance at having a non-empty extension
  2653. preDotState = -1;
  2654. }
  2655. }
  2656. if (startDot === -1 || end === -1
  2657. // We saw a non-dot character immediately before the dot
  2658. || preDotState === 0
  2659. // The (right-most) trimmed path component is exactly '..'
  2660. // eslint-disable-next-line no-mixed-operators
  2661. || preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) {
  2662. if (end !== -1) {
  2663. if (startPart === 0 && isAbsolute)
  2664. { ret.base = ret.name = path.slice(1, end); }
  2665. else
  2666. { ret.base = ret.name = path.slice(startPart, end); }
  2667. }
  2668. }
  2669. else {
  2670. if (startPart === 0 && isAbsolute) {
  2671. ret.name = path.slice(1, startDot);
  2672. ret.base = path.slice(1, end);
  2673. }
  2674. else {
  2675. ret.name = path.slice(startPart, startDot);
  2676. ret.base = path.slice(startPart, end);
  2677. }
  2678. ret.ext = path.slice(startDot, end);
  2679. }
  2680. ret.dir = this.dirname(path);
  2681. if (protocol)
  2682. { ret.dir = protocol + ret.dir; }
  2683. return ret;
  2684. },
  2685. sep: '/',
  2686. delimiter: ':'
  2687. };
  2688. /**
  2689. * The prefix that denotes a URL is for a retina asset.
  2690. * @static
  2691. * @name RETINA_PREFIX
  2692. * @memberof PIXI.settings
  2693. * @type {RegExp}
  2694. * @default /@([0-9\.]+)x/
  2695. * @example `@2x`
  2696. */
  2697. settings.settings.RETINA_PREFIX = /@([0-9\.]+)x/;
  2698. /**
  2699. * Should the `failIfMajorPerformanceCaveat` flag be enabled as a context option used in the `isWebGLSupported` function.
  2700. * If set to true, a WebGL renderer can fail to be created if the browser thinks there could be performance issues when
  2701. * using WebGL.
  2702. *
  2703. * In PixiJS v6 this has changed from true to false by default, to allow WebGL to work in as many scenarios as possible.
  2704. * However, some users may have a poor experience, for example, if a user has a gpu or driver version blacklisted by the
  2705. * browser.
  2706. *
  2707. * If your application requires high performance rendering, you may wish to set this to false.
  2708. * We recommend one of two options if you decide to set this flag to false:
  2709. *
  2710. * 1: Use the `pixi.js-legacy` package, which includes a Canvas renderer as a fallback in case high performance WebGL is
  2711. * not supported.
  2712. *
  2713. * 2: Call `isWebGLSupported` (which if found in the PIXI.utils package) in your code before attempting to create a PixiJS
  2714. * renderer, and show an error message to the user if the function returns false, explaining that their device & browser
  2715. * combination does not support high performance WebGL.
  2716. * This is a much better strategy than trying to create a PixiJS renderer and finding it then fails.
  2717. * @static
  2718. * @name FAIL_IF_MAJOR_PERFORMANCE_CAVEAT
  2719. * @memberof PIXI.settings
  2720. * @type {boolean}
  2721. * @default false
  2722. */
  2723. settings.settings.FAIL_IF_MAJOR_PERFORMANCE_CAVEAT = false;
  2724. var saidHello = false;
  2725. var VERSION = '6.5.10';
  2726. /**
  2727. * Skips the hello message of renderers that are created after this is run.
  2728. * @function skipHello
  2729. * @memberof PIXI.utils
  2730. */
  2731. function skipHello() {
  2732. saidHello = true;
  2733. }
  2734. /**
  2735. * Logs out the version and renderer information for this running instance of PIXI.
  2736. * If you don't want to see this message you can run `PIXI.utils.skipHello()` before
  2737. * creating your renderer. Keep in mind that doing that will forever make you a jerk face.
  2738. * @static
  2739. * @function sayHello
  2740. * @memberof PIXI.utils
  2741. * @param {string} type - The string renderer type to log.
  2742. */
  2743. function sayHello(type) {
  2744. var _a;
  2745. if (saidHello) {
  2746. return;
  2747. }
  2748. if (settings.settings.ADAPTER.getNavigator().userAgent.toLowerCase().indexOf('chrome') > -1) {
  2749. var args = [
  2750. "\n %c %c %c PixiJS " + VERSION + " - \u2730 " + type + " \u2730 %c %c http://www.pixijs.com/ %c %c \u2665%c\u2665%c\u2665 \n\n",
  2751. 'background: #ff66a5; padding:5px 0;',
  2752. 'background: #ff66a5; padding:5px 0;',
  2753. 'color: #ff66a5; background: #030307; padding:5px 0;',
  2754. 'background: #ff66a5; padding:5px 0;',
  2755. 'background: #ffc3dc; padding:5px 0;',
  2756. 'background: #ff66a5; padding:5px 0;',
  2757. 'color: #ff2424; background: #fff; padding:5px 0;',
  2758. 'color: #ff2424; background: #fff; padding:5px 0;',
  2759. 'color: #ff2424; background: #fff; padding:5px 0;' ];
  2760. (_a = globalThis.console).log.apply(_a, args);
  2761. }
  2762. else if (globalThis.console) {
  2763. globalThis.console.log("PixiJS " + VERSION + " - " + type + " - http://www.pixijs.com/");
  2764. }
  2765. saidHello = true;
  2766. }
  2767. var supported;
  2768. /**
  2769. * Helper for checking for WebGL support.
  2770. * @memberof PIXI.utils
  2771. * @function isWebGLSupported
  2772. * @returns {boolean} Is WebGL supported.
  2773. */
  2774. function isWebGLSupported() {
  2775. if (typeof supported === 'undefined') {
  2776. supported = (function supported() {
  2777. var contextOptions = {
  2778. stencil: true,
  2779. failIfMajorPerformanceCaveat: settings.settings.FAIL_IF_MAJOR_PERFORMANCE_CAVEAT,
  2780. };
  2781. try {
  2782. if (!settings.settings.ADAPTER.getWebGLRenderingContext()) {
  2783. return false;
  2784. }
  2785. var canvas = settings.settings.ADAPTER.createCanvas();
  2786. var gl = (canvas.getContext('webgl', contextOptions)
  2787. || canvas.getContext('experimental-webgl', contextOptions));
  2788. var success = !!(gl && gl.getContextAttributes().stencil);
  2789. if (gl) {
  2790. var loseContext = gl.getExtension('WEBGL_lose_context');
  2791. if (loseContext) {
  2792. loseContext.loseContext();
  2793. }
  2794. }
  2795. gl = null;
  2796. return success;
  2797. }
  2798. catch (e) {
  2799. return false;
  2800. }
  2801. })();
  2802. }
  2803. return supported;
  2804. }
  2805. var aliceblue = "#f0f8ff";
  2806. var antiquewhite = "#faebd7";
  2807. var aqua = "#00ffff";
  2808. var aquamarine = "#7fffd4";
  2809. var azure = "#f0ffff";
  2810. var beige = "#f5f5dc";
  2811. var bisque = "#ffe4c4";
  2812. var black = "#000000";
  2813. var blanchedalmond = "#ffebcd";
  2814. var blue = "#0000ff";
  2815. var blueviolet = "#8a2be2";
  2816. var brown = "#a52a2a";
  2817. var burlywood = "#deb887";
  2818. var cadetblue = "#5f9ea0";
  2819. var chartreuse = "#7fff00";
  2820. var chocolate = "#d2691e";
  2821. var coral = "#ff7f50";
  2822. var cornflowerblue = "#6495ed";
  2823. var cornsilk = "#fff8dc";
  2824. var crimson = "#dc143c";
  2825. var cyan = "#00ffff";
  2826. var darkblue = "#00008b";
  2827. var darkcyan = "#008b8b";
  2828. var darkgoldenrod = "#b8860b";
  2829. var darkgray = "#a9a9a9";
  2830. var darkgreen = "#006400";
  2831. var darkgrey = "#a9a9a9";
  2832. var darkkhaki = "#bdb76b";
  2833. var darkmagenta = "#8b008b";
  2834. var darkolivegreen = "#556b2f";
  2835. var darkorange = "#ff8c00";
  2836. var darkorchid = "#9932cc";
  2837. var darkred = "#8b0000";
  2838. var darksalmon = "#e9967a";
  2839. var darkseagreen = "#8fbc8f";
  2840. var darkslateblue = "#483d8b";
  2841. var darkslategray = "#2f4f4f";
  2842. var darkslategrey = "#2f4f4f";
  2843. var darkturquoise = "#00ced1";
  2844. var darkviolet = "#9400d3";
  2845. var deeppink = "#ff1493";
  2846. var deepskyblue = "#00bfff";
  2847. var dimgray = "#696969";
  2848. var dimgrey = "#696969";
  2849. var dodgerblue = "#1e90ff";
  2850. var firebrick = "#b22222";
  2851. var floralwhite = "#fffaf0";
  2852. var forestgreen = "#228b22";
  2853. var fuchsia = "#ff00ff";
  2854. var gainsboro = "#dcdcdc";
  2855. var ghostwhite = "#f8f8ff";
  2856. var goldenrod = "#daa520";
  2857. var gold = "#ffd700";
  2858. var gray = "#808080";
  2859. var green = "#008000";
  2860. var greenyellow = "#adff2f";
  2861. var grey = "#808080";
  2862. var honeydew = "#f0fff0";
  2863. var hotpink = "#ff69b4";
  2864. var indianred = "#cd5c5c";
  2865. var indigo = "#4b0082";
  2866. var ivory = "#fffff0";
  2867. var khaki = "#f0e68c";
  2868. var lavenderblush = "#fff0f5";
  2869. var lavender = "#e6e6fa";
  2870. var lawngreen = "#7cfc00";
  2871. var lemonchiffon = "#fffacd";
  2872. var lightblue = "#add8e6";
  2873. var lightcoral = "#f08080";
  2874. var lightcyan = "#e0ffff";
  2875. var lightgoldenrodyellow = "#fafad2";
  2876. var lightgray = "#d3d3d3";
  2877. var lightgreen = "#90ee90";
  2878. var lightgrey = "#d3d3d3";
  2879. var lightpink = "#ffb6c1";
  2880. var lightsalmon = "#ffa07a";
  2881. var lightseagreen = "#20b2aa";
  2882. var lightskyblue = "#87cefa";
  2883. var lightslategray = "#778899";
  2884. var lightslategrey = "#778899";
  2885. var lightsteelblue = "#b0c4de";
  2886. var lightyellow = "#ffffe0";
  2887. var lime = "#00ff00";
  2888. var limegreen = "#32cd32";
  2889. var linen = "#faf0e6";
  2890. var magenta = "#ff00ff";
  2891. var maroon = "#800000";
  2892. var mediumaquamarine = "#66cdaa";
  2893. var mediumblue = "#0000cd";
  2894. var mediumorchid = "#ba55d3";
  2895. var mediumpurple = "#9370db";
  2896. var mediumseagreen = "#3cb371";
  2897. var mediumslateblue = "#7b68ee";
  2898. var mediumspringgreen = "#00fa9a";
  2899. var mediumturquoise = "#48d1cc";
  2900. var mediumvioletred = "#c71585";
  2901. var midnightblue = "#191970";
  2902. var mintcream = "#f5fffa";
  2903. var mistyrose = "#ffe4e1";
  2904. var moccasin = "#ffe4b5";
  2905. var navajowhite = "#ffdead";
  2906. var navy = "#000080";
  2907. var oldlace = "#fdf5e6";
  2908. var olive = "#808000";
  2909. var olivedrab = "#6b8e23";
  2910. var orange = "#ffa500";
  2911. var orangered = "#ff4500";
  2912. var orchid = "#da70d6";
  2913. var palegoldenrod = "#eee8aa";
  2914. var palegreen = "#98fb98";
  2915. var paleturquoise = "#afeeee";
  2916. var palevioletred = "#db7093";
  2917. var papayawhip = "#ffefd5";
  2918. var peachpuff = "#ffdab9";
  2919. var peru = "#cd853f";
  2920. var pink = "#ffc0cb";
  2921. var plum = "#dda0dd";
  2922. var powderblue = "#b0e0e6";
  2923. var purple = "#800080";
  2924. var rebeccapurple = "#663399";
  2925. var red = "#ff0000";
  2926. var rosybrown = "#bc8f8f";
  2927. var royalblue = "#4169e1";
  2928. var saddlebrown = "#8b4513";
  2929. var salmon = "#fa8072";
  2930. var sandybrown = "#f4a460";
  2931. var seagreen = "#2e8b57";
  2932. var seashell = "#fff5ee";
  2933. var sienna = "#a0522d";
  2934. var silver = "#c0c0c0";
  2935. var skyblue = "#87ceeb";
  2936. var slateblue = "#6a5acd";
  2937. var slategray = "#708090";
  2938. var slategrey = "#708090";
  2939. var snow = "#fffafa";
  2940. var springgreen = "#00ff7f";
  2941. var steelblue = "#4682b4";
  2942. var tan = "#d2b48c";
  2943. var teal = "#008080";
  2944. var thistle = "#d8bfd8";
  2945. var tomato = "#ff6347";
  2946. var turquoise = "#40e0d0";
  2947. var violet = "#ee82ee";
  2948. var wheat = "#f5deb3";
  2949. var white = "#ffffff";
  2950. var whitesmoke = "#f5f5f5";
  2951. var yellow = "#ffff00";
  2952. var yellowgreen = "#9acd32";
  2953. var cssColorNames = {
  2954. aliceblue: aliceblue,
  2955. antiquewhite: antiquewhite,
  2956. aqua: aqua,
  2957. aquamarine: aquamarine,
  2958. azure: azure,
  2959. beige: beige,
  2960. bisque: bisque,
  2961. black: black,
  2962. blanchedalmond: blanchedalmond,
  2963. blue: blue,
  2964. blueviolet: blueviolet,
  2965. brown: brown,
  2966. burlywood: burlywood,
  2967. cadetblue: cadetblue,
  2968. chartreuse: chartreuse,
  2969. chocolate: chocolate,
  2970. coral: coral,
  2971. cornflowerblue: cornflowerblue,
  2972. cornsilk: cornsilk,
  2973. crimson: crimson,
  2974. cyan: cyan,
  2975. darkblue: darkblue,
  2976. darkcyan: darkcyan,
  2977. darkgoldenrod: darkgoldenrod,
  2978. darkgray: darkgray,
  2979. darkgreen: darkgreen,
  2980. darkgrey: darkgrey,
  2981. darkkhaki: darkkhaki,
  2982. darkmagenta: darkmagenta,
  2983. darkolivegreen: darkolivegreen,
  2984. darkorange: darkorange,
  2985. darkorchid: darkorchid,
  2986. darkred: darkred,
  2987. darksalmon: darksalmon,
  2988. darkseagreen: darkseagreen,
  2989. darkslateblue: darkslateblue,
  2990. darkslategray: darkslategray,
  2991. darkslategrey: darkslategrey,
  2992. darkturquoise: darkturquoise,
  2993. darkviolet: darkviolet,
  2994. deeppink: deeppink,
  2995. deepskyblue: deepskyblue,
  2996. dimgray: dimgray,
  2997. dimgrey: dimgrey,
  2998. dodgerblue: dodgerblue,
  2999. firebrick: firebrick,
  3000. floralwhite: floralwhite,
  3001. forestgreen: forestgreen,
  3002. fuchsia: fuchsia,
  3003. gainsboro: gainsboro,
  3004. ghostwhite: ghostwhite,
  3005. goldenrod: goldenrod,
  3006. gold: gold,
  3007. gray: gray,
  3008. green: green,
  3009. greenyellow: greenyellow,
  3010. grey: grey,
  3011. honeydew: honeydew,
  3012. hotpink: hotpink,
  3013. indianred: indianred,
  3014. indigo: indigo,
  3015. ivory: ivory,
  3016. khaki: khaki,
  3017. lavenderblush: lavenderblush,
  3018. lavender: lavender,
  3019. lawngreen: lawngreen,
  3020. lemonchiffon: lemonchiffon,
  3021. lightblue: lightblue,
  3022. lightcoral: lightcoral,
  3023. lightcyan: lightcyan,
  3024. lightgoldenrodyellow: lightgoldenrodyellow,
  3025. lightgray: lightgray,
  3026. lightgreen: lightgreen,
  3027. lightgrey: lightgrey,
  3028. lightpink: lightpink,
  3029. lightsalmon: lightsalmon,
  3030. lightseagreen: lightseagreen,
  3031. lightskyblue: lightskyblue,
  3032. lightslategray: lightslategray,
  3033. lightslategrey: lightslategrey,
  3034. lightsteelblue: lightsteelblue,
  3035. lightyellow: lightyellow,
  3036. lime: lime,
  3037. limegreen: limegreen,
  3038. linen: linen,
  3039. magenta: magenta,
  3040. maroon: maroon,
  3041. mediumaquamarine: mediumaquamarine,
  3042. mediumblue: mediumblue,
  3043. mediumorchid: mediumorchid,
  3044. mediumpurple: mediumpurple,
  3045. mediumseagreen: mediumseagreen,
  3046. mediumslateblue: mediumslateblue,
  3047. mediumspringgreen: mediumspringgreen,
  3048. mediumturquoise: mediumturquoise,
  3049. mediumvioletred: mediumvioletred,
  3050. midnightblue: midnightblue,
  3051. mintcream: mintcream,
  3052. mistyrose: mistyrose,
  3053. moccasin: moccasin,
  3054. navajowhite: navajowhite,
  3055. navy: navy,
  3056. oldlace: oldlace,
  3057. olive: olive,
  3058. olivedrab: olivedrab,
  3059. orange: orange,
  3060. orangered: orangered,
  3061. orchid: orchid,
  3062. palegoldenrod: palegoldenrod,
  3063. palegreen: palegreen,
  3064. paleturquoise: paleturquoise,
  3065. palevioletred: palevioletred,
  3066. papayawhip: papayawhip,
  3067. peachpuff: peachpuff,
  3068. peru: peru,
  3069. pink: pink,
  3070. plum: plum,
  3071. powderblue: powderblue,
  3072. purple: purple,
  3073. rebeccapurple: rebeccapurple,
  3074. red: red,
  3075. rosybrown: rosybrown,
  3076. royalblue: royalblue,
  3077. saddlebrown: saddlebrown,
  3078. salmon: salmon,
  3079. sandybrown: sandybrown,
  3080. seagreen: seagreen,
  3081. seashell: seashell,
  3082. sienna: sienna,
  3083. silver: silver,
  3084. skyblue: skyblue,
  3085. slateblue: slateblue,
  3086. slategray: slategray,
  3087. slategrey: slategrey,
  3088. snow: snow,
  3089. springgreen: springgreen,
  3090. steelblue: steelblue,
  3091. tan: tan,
  3092. teal: teal,
  3093. thistle: thistle,
  3094. tomato: tomato,
  3095. turquoise: turquoise,
  3096. violet: violet,
  3097. wheat: wheat,
  3098. white: white,
  3099. whitesmoke: whitesmoke,
  3100. yellow: yellow,
  3101. yellowgreen: yellowgreen
  3102. };
  3103. /**
  3104. * Converts a hexadecimal color number to an [R, G, B] array of normalized floats (numbers from 0.0 to 1.0).
  3105. * @example
  3106. * PIXI.utils.hex2rgb(0xffffff); // returns [1, 1, 1]
  3107. * @memberof PIXI.utils
  3108. * @function hex2rgb
  3109. * @param {number} hex - The hexadecimal number to convert
  3110. * @param {number[]} [out=[]] - If supplied, this array will be used rather than returning a new one
  3111. * @returns {number[]} An array representing the [R, G, B] of the color where all values are floats.
  3112. */
  3113. function hex2rgb(hex, out) {
  3114. if (out === void 0) { out = []; }
  3115. out[0] = ((hex >> 16) & 0xFF) / 255;
  3116. out[1] = ((hex >> 8) & 0xFF) / 255;
  3117. out[2] = (hex & 0xFF) / 255;
  3118. return out;
  3119. }
  3120. /**
  3121. * Converts a hexadecimal color number to a string.
  3122. * @example
  3123. * PIXI.utils.hex2string(0xffffff); // returns "#ffffff"
  3124. * @memberof PIXI.utils
  3125. * @function hex2string
  3126. * @param {number} hex - Number in hex (e.g., `0xffffff`)
  3127. * @returns {string} The string color (e.g., `"#ffffff"`).
  3128. */
  3129. function hex2string(hex) {
  3130. var hexString = hex.toString(16);
  3131. hexString = '000000'.substring(0, 6 - hexString.length) + hexString;
  3132. return "#" + hexString;
  3133. }
  3134. /**
  3135. * Converts a string to a hexadecimal color number.
  3136. * It can handle:
  3137. * hex strings starting with #: "#ffffff"
  3138. * hex strings starting with 0x: "0xffffff"
  3139. * hex strings without prefix: "ffffff"
  3140. * css colors: "black"
  3141. * @example
  3142. * PIXI.utils.string2hex("#ffffff"); // returns 0xffffff, which is 16777215 as an integer
  3143. * @memberof PIXI.utils
  3144. * @function string2hex
  3145. * @param {string} string - The string color (e.g., `"#ffffff"`)
  3146. * @returns {number} Number in hexadecimal.
  3147. */
  3148. function string2hex(string) {
  3149. if (typeof string === 'string') {
  3150. string = cssColorNames[string.toLowerCase()] || string;
  3151. if (string[0] === '#') {
  3152. string = string.slice(1);
  3153. }
  3154. }
  3155. return parseInt(string, 16);
  3156. }
  3157. /**
  3158. * Converts a color as an [R, G, B] array of normalized floats to a hexadecimal number.
  3159. * @example
  3160. * PIXI.utils.rgb2hex([1, 1, 1]); // returns 0xffffff, which is 16777215 as an integer
  3161. * @memberof PIXI.utils
  3162. * @function rgb2hex
  3163. * @param {number[]} rgb - Array of numbers where all values are normalized floats from 0.0 to 1.0.
  3164. * @returns {number} Number in hexadecimal.
  3165. */
  3166. function rgb2hex(rgb) {
  3167. return (((rgb[0] * 255) << 16) + ((rgb[1] * 255) << 8) + (rgb[2] * 255 | 0));
  3168. }
  3169. /**
  3170. * Corrects PixiJS blend, takes premultiplied alpha into account
  3171. * @memberof PIXI.utils
  3172. * @function mapPremultipliedBlendModes
  3173. * @private
  3174. * @returns {Array<number[]>} Mapped modes.
  3175. */
  3176. function mapPremultipliedBlendModes() {
  3177. var pm = [];
  3178. var npm = [];
  3179. for (var i = 0; i < 32; i++) {
  3180. pm[i] = i;
  3181. npm[i] = i;
  3182. }
  3183. pm[constants.BLEND_MODES.NORMAL_NPM] = constants.BLEND_MODES.NORMAL;
  3184. pm[constants.BLEND_MODES.ADD_NPM] = constants.BLEND_MODES.ADD;
  3185. pm[constants.BLEND_MODES.SCREEN_NPM] = constants.BLEND_MODES.SCREEN;
  3186. npm[constants.BLEND_MODES.NORMAL] = constants.BLEND_MODES.NORMAL_NPM;
  3187. npm[constants.BLEND_MODES.ADD] = constants.BLEND_MODES.ADD_NPM;
  3188. npm[constants.BLEND_MODES.SCREEN] = constants.BLEND_MODES.SCREEN_NPM;
  3189. var array = [];
  3190. array.push(npm);
  3191. array.push(pm);
  3192. return array;
  3193. }
  3194. /**
  3195. * maps premultiply flag and blendMode to adjusted blendMode
  3196. * @memberof PIXI.utils
  3197. * @constant premultiplyBlendMode
  3198. * @type {Array<number[]>}
  3199. */
  3200. var premultiplyBlendMode = mapPremultipliedBlendModes();
  3201. /**
  3202. * changes blendMode according to texture format
  3203. * @memberof PIXI.utils
  3204. * @function correctBlendMode
  3205. * @param {number} blendMode - supposed blend mode
  3206. * @param {boolean} premultiplied - whether source is premultiplied
  3207. * @returns {number} true blend mode for this texture
  3208. */
  3209. function correctBlendMode(blendMode, premultiplied) {
  3210. return premultiplyBlendMode[premultiplied ? 1 : 0][blendMode];
  3211. }
  3212. /**
  3213. * combines rgb and alpha to out array
  3214. * @memberof PIXI.utils
  3215. * @function premultiplyRgba
  3216. * @param {Float32Array|number[]} rgb - input rgb
  3217. * @param {number} alpha - alpha param
  3218. * @param {Float32Array} [out] - output
  3219. * @param {boolean} [premultiply=true] - do premultiply it
  3220. * @returns {Float32Array} vec4 rgba
  3221. */
  3222. function premultiplyRgba(rgb, alpha, out, premultiply) {
  3223. out = out || new Float32Array(4);
  3224. if (premultiply || premultiply === undefined) {
  3225. out[0] = rgb[0] * alpha;
  3226. out[1] = rgb[1] * alpha;
  3227. out[2] = rgb[2] * alpha;
  3228. }
  3229. else {
  3230. out[0] = rgb[0];
  3231. out[1] = rgb[1];
  3232. out[2] = rgb[2];
  3233. }
  3234. out[3] = alpha;
  3235. return out;
  3236. }
  3237. /**
  3238. * premultiplies tint
  3239. * @memberof PIXI.utils
  3240. * @function premultiplyTint
  3241. * @param {number} tint - integer RGB
  3242. * @param {number} alpha - floating point alpha (0.0-1.0)
  3243. * @returns {number} tint multiplied by alpha
  3244. */
  3245. function premultiplyTint(tint, alpha) {
  3246. if (alpha === 1.0) {
  3247. return (alpha * 255 << 24) + tint;
  3248. }
  3249. if (alpha === 0.0) {
  3250. return 0;
  3251. }
  3252. var R = ((tint >> 16) & 0xFF);
  3253. var G = ((tint >> 8) & 0xFF);
  3254. var B = (tint & 0xFF);
  3255. R = ((R * alpha) + 0.5) | 0;
  3256. G = ((G * alpha) + 0.5) | 0;
  3257. B = ((B * alpha) + 0.5) | 0;
  3258. return (alpha * 255 << 24) + (R << 16) + (G << 8) + B;
  3259. }
  3260. /**
  3261. * converts integer tint and float alpha to vec4 form, premultiplies by default
  3262. * @memberof PIXI.utils
  3263. * @function premultiplyTintToRgba
  3264. * @param {number} tint - input tint
  3265. * @param {number} alpha - alpha param
  3266. * @param {Float32Array} [out] - output
  3267. * @param {boolean} [premultiply=true] - do premultiply it
  3268. * @returns {Float32Array} vec4 rgba
  3269. */
  3270. function premultiplyTintToRgba(tint, alpha, out, premultiply) {
  3271. out = out || new Float32Array(4);
  3272. out[0] = ((tint >> 16) & 0xFF) / 255.0;
  3273. out[1] = ((tint >> 8) & 0xFF) / 255.0;
  3274. out[2] = (tint & 0xFF) / 255.0;
  3275. if (premultiply || premultiply === undefined) {
  3276. out[0] *= alpha;
  3277. out[1] *= alpha;
  3278. out[2] *= alpha;
  3279. }
  3280. out[3] = alpha;
  3281. return out;
  3282. }
  3283. /**
  3284. * Generic Mask Stack data structure
  3285. * @memberof PIXI.utils
  3286. * @function createIndicesForQuads
  3287. * @param {number} size - Number of quads
  3288. * @param {Uint16Array|Uint32Array} [outBuffer] - Buffer for output, length has to be `6 * size`
  3289. * @returns {Uint16Array|Uint32Array} - Resulting index buffer
  3290. */
  3291. function createIndicesForQuads(size, outBuffer) {
  3292. if (outBuffer === void 0) { outBuffer = null; }
  3293. // the total number of indices in our array, there are 6 points per quad.
  3294. var totalIndices = size * 6;
  3295. outBuffer = outBuffer || new Uint16Array(totalIndices);
  3296. if (outBuffer.length !== totalIndices) {
  3297. throw new Error("Out buffer length is incorrect, got " + outBuffer.length + " and expected " + totalIndices);
  3298. }
  3299. // fill the indices with the quads to draw
  3300. for (var i = 0, j = 0; i < totalIndices; i += 6, j += 4) {
  3301. outBuffer[i + 0] = j + 0;
  3302. outBuffer[i + 1] = j + 1;
  3303. outBuffer[i + 2] = j + 2;
  3304. outBuffer[i + 3] = j + 0;
  3305. outBuffer[i + 4] = j + 2;
  3306. outBuffer[i + 5] = j + 3;
  3307. }
  3308. return outBuffer;
  3309. }
  3310. function getBufferType(array) {
  3311. if (array.BYTES_PER_ELEMENT === 4) {
  3312. if (array instanceof Float32Array) {
  3313. return 'Float32Array';
  3314. }
  3315. else if (array instanceof Uint32Array) {
  3316. return 'Uint32Array';
  3317. }
  3318. return 'Int32Array';
  3319. }
  3320. else if (array.BYTES_PER_ELEMENT === 2) {
  3321. if (array instanceof Uint16Array) {
  3322. return 'Uint16Array';
  3323. }
  3324. }
  3325. else if (array.BYTES_PER_ELEMENT === 1) {
  3326. if (array instanceof Uint8Array) {
  3327. return 'Uint8Array';
  3328. }
  3329. }
  3330. // TODO map out the rest of the array elements!
  3331. return null;
  3332. }
  3333. /* eslint-disable object-shorthand */
  3334. var map = { Float32Array: Float32Array, Uint32Array: Uint32Array, Int32Array: Int32Array, Uint8Array: Uint8Array };
  3335. function interleaveTypedArrays(arrays, sizes) {
  3336. var outSize = 0;
  3337. var stride = 0;
  3338. var views = {};
  3339. for (var i = 0; i < arrays.length; i++) {
  3340. stride += sizes[i];
  3341. outSize += arrays[i].length;
  3342. }
  3343. var buffer = new ArrayBuffer(outSize * 4);
  3344. var out = null;
  3345. var littleOffset = 0;
  3346. for (var i = 0; i < arrays.length; i++) {
  3347. var size = sizes[i];
  3348. var array = arrays[i];
  3349. /*
  3350. @todo This is unsafe casting but consistent with how the code worked previously. Should it stay this way
  3351. or should and `getBufferTypeUnsafe` function be exposed that throws an Error if unsupported type is passed?
  3352. */
  3353. var type = getBufferType(array);
  3354. if (!views[type]) {
  3355. views[type] = new map[type](buffer);
  3356. }
  3357. out = views[type];
  3358. for (var j = 0; j < array.length; j++) {
  3359. var indexStart = ((j / size | 0) * stride) + littleOffset;
  3360. var index = j % size;
  3361. out[indexStart + index] = array[j];
  3362. }
  3363. littleOffset += size;
  3364. }
  3365. return new Float32Array(buffer);
  3366. }
  3367. // Taken from the bit-twiddle package
  3368. /**
  3369. * Rounds to next power of two.
  3370. * @function nextPow2
  3371. * @memberof PIXI.utils
  3372. * @param {number} v - input value
  3373. * @returns {number} - next rounded power of two
  3374. */
  3375. function nextPow2(v) {
  3376. v += v === 0 ? 1 : 0;
  3377. --v;
  3378. v |= v >>> 1;
  3379. v |= v >>> 2;
  3380. v |= v >>> 4;
  3381. v |= v >>> 8;
  3382. v |= v >>> 16;
  3383. return v + 1;
  3384. }
  3385. /**
  3386. * Checks if a number is a power of two.
  3387. * @function isPow2
  3388. * @memberof PIXI.utils
  3389. * @param {number} v - input value
  3390. * @returns {boolean} `true` if value is power of two
  3391. */
  3392. function isPow2(v) {
  3393. return !(v & (v - 1)) && (!!v);
  3394. }
  3395. /**
  3396. * Computes ceil of log base 2
  3397. * @function log2
  3398. * @memberof PIXI.utils
  3399. * @param {number} v - input value
  3400. * @returns {number} logarithm base 2
  3401. */
  3402. function log2(v) {
  3403. var r = (v > 0xFFFF ? 1 : 0) << 4;
  3404. v >>>= r;
  3405. var shift = (v > 0xFF ? 1 : 0) << 3;
  3406. v >>>= shift;
  3407. r |= shift;
  3408. shift = (v > 0xF ? 1 : 0) << 2;
  3409. v >>>= shift;
  3410. r |= shift;
  3411. shift = (v > 0x3 ? 1 : 0) << 1;
  3412. v >>>= shift;
  3413. r |= shift;
  3414. return r | (v >> 1);
  3415. }
  3416. /**
  3417. * Remove items from a javascript array without generating garbage
  3418. * @function removeItems
  3419. * @memberof PIXI.utils
  3420. * @param {Array<any>} arr - Array to remove elements from
  3421. * @param {number} startIdx - starting index
  3422. * @param {number} removeCount - how many to remove
  3423. */
  3424. function removeItems(arr, startIdx, removeCount) {
  3425. var length = arr.length;
  3426. var i;
  3427. if (startIdx >= length || removeCount === 0) {
  3428. return;
  3429. }
  3430. removeCount = (startIdx + removeCount > length ? length - startIdx : removeCount);
  3431. var len = length - removeCount;
  3432. for (i = startIdx; i < len; ++i) {
  3433. arr[i] = arr[i + removeCount];
  3434. }
  3435. arr.length = len;
  3436. }
  3437. /**
  3438. * Returns sign of number
  3439. * @memberof PIXI.utils
  3440. * @function sign
  3441. * @param {number} n - the number to check the sign of
  3442. * @returns {number} 0 if `n` is 0, -1 if `n` is negative, 1 if `n` is positive
  3443. */
  3444. function sign(n) {
  3445. if (n === 0)
  3446. { return 0; }
  3447. return n < 0 ? -1 : 1;
  3448. }
  3449. var nextUid = 0;
  3450. /**
  3451. * Gets the next unique identifier
  3452. * @memberof PIXI.utils
  3453. * @function uid
  3454. * @returns {number} The next unique identifier to use.
  3455. */
  3456. function uid() {
  3457. return ++nextUid;
  3458. }
  3459. // A map of warning messages already fired
  3460. var warnings = {};
  3461. /**
  3462. * Helper for warning developers about deprecated features & settings.
  3463. * A stack track for warnings is given; useful for tracking-down where
  3464. * deprecated methods/properties/classes are being used within the code.
  3465. * @memberof PIXI.utils
  3466. * @function deprecation
  3467. * @param {string} version - The version where the feature became deprecated
  3468. * @param {string} message - Message should include what is deprecated, where, and the new solution
  3469. * @param {number} [ignoreDepth=3] - The number of steps to ignore at the top of the error stack
  3470. * this is mostly to ignore internal deprecation calls.
  3471. */
  3472. function deprecation(version, message, ignoreDepth) {
  3473. if (ignoreDepth === void 0) { ignoreDepth = 3; }
  3474. // Ignore duplicat
  3475. if (warnings[message]) {
  3476. return;
  3477. }
  3478. /* eslint-disable no-console */
  3479. var stack = new Error().stack;
  3480. // Handle IE < 10 and Safari < 6
  3481. if (typeof stack === 'undefined') {
  3482. console.warn('PixiJS Deprecation Warning: ', message + "\nDeprecated since v" + version);
  3483. }
  3484. else {
  3485. // chop off the stack trace which includes PixiJS internal calls
  3486. stack = stack.split('\n').splice(ignoreDepth).join('\n');
  3487. if (console.groupCollapsed) {
  3488. console.groupCollapsed('%cPixiJS Deprecation Warning: %c%s', 'color:#614108;background:#fffbe6', 'font-weight:normal;color:#614108;background:#fffbe6', message + "\nDeprecated since v" + version);
  3489. console.warn(stack);
  3490. console.groupEnd();
  3491. }
  3492. else {
  3493. console.warn('PixiJS Deprecation Warning: ', message + "\nDeprecated since v" + version);
  3494. console.warn(stack);
  3495. }
  3496. }
  3497. /* eslint-enable no-console */
  3498. warnings[message] = true;
  3499. }
  3500. /**
  3501. * @todo Describe property usage
  3502. * @static
  3503. * @name ProgramCache
  3504. * @memberof PIXI.utils
  3505. * @type {object}
  3506. */
  3507. var ProgramCache = {};
  3508. /**
  3509. * @todo Describe property usage
  3510. * @static
  3511. * @name TextureCache
  3512. * @memberof PIXI.utils
  3513. * @type {object}
  3514. */
  3515. var TextureCache = Object.create(null);
  3516. /**
  3517. * @todo Describe property usage
  3518. * @static
  3519. * @name BaseTextureCache
  3520. * @memberof PIXI.utils
  3521. * @type {object}
  3522. */
  3523. var BaseTextureCache = Object.create(null);
  3524. /**
  3525. * Destroys all texture in the cache
  3526. * @memberof PIXI.utils
  3527. * @function destroyTextureCache
  3528. */
  3529. function destroyTextureCache() {
  3530. var key;
  3531. for (key in TextureCache) {
  3532. TextureCache[key].destroy();
  3533. }
  3534. for (key in BaseTextureCache) {
  3535. BaseTextureCache[key].destroy();
  3536. }
  3537. }
  3538. /**
  3539. * Removes all textures from cache, but does not destroy them
  3540. * @memberof PIXI.utils
  3541. * @function clearTextureCache
  3542. */
  3543. function clearTextureCache() {
  3544. var key;
  3545. for (key in TextureCache) {
  3546. delete TextureCache[key];
  3547. }
  3548. for (key in BaseTextureCache) {
  3549. delete BaseTextureCache[key];
  3550. }
  3551. }
  3552. /**
  3553. * Creates a Canvas element of the given size to be used as a target for rendering to.
  3554. * @class
  3555. * @memberof PIXI.utils
  3556. */
  3557. var CanvasRenderTarget = /** @class */ (function () {
  3558. /**
  3559. * @param width - the width for the newly created canvas
  3560. * @param height - the height for the newly created canvas
  3561. * @param {number} [resolution=PIXI.settings.RESOLUTION] - The resolution / device pixel ratio of the canvas
  3562. */
  3563. function CanvasRenderTarget(width, height, resolution) {
  3564. this.canvas = settings.settings.ADAPTER.createCanvas();
  3565. this.context = this.canvas.getContext('2d');
  3566. this.resolution = resolution || settings.settings.RESOLUTION;
  3567. this.resize(width, height);
  3568. }
  3569. /**
  3570. * Clears the canvas that was created by the CanvasRenderTarget class.
  3571. * @private
  3572. */
  3573. CanvasRenderTarget.prototype.clear = function () {
  3574. this.context.setTransform(1, 0, 0, 1, 0, 0);
  3575. this.context.clearRect(0, 0, this.canvas.width, this.canvas.height);
  3576. };
  3577. /**
  3578. * Resizes the canvas to the specified width and height.
  3579. * @param desiredWidth - the desired width of the canvas
  3580. * @param desiredHeight - the desired height of the canvas
  3581. */
  3582. CanvasRenderTarget.prototype.resize = function (desiredWidth, desiredHeight) {
  3583. this.canvas.width = Math.round(desiredWidth * this.resolution);
  3584. this.canvas.height = Math.round(desiredHeight * this.resolution);
  3585. };
  3586. /** Destroys this canvas. */
  3587. CanvasRenderTarget.prototype.destroy = function () {
  3588. this.context = null;
  3589. this.canvas = null;
  3590. };
  3591. Object.defineProperty(CanvasRenderTarget.prototype, "width", {
  3592. /**
  3593. * The width of the canvas buffer in pixels.
  3594. * @member {number}
  3595. */
  3596. get: function () {
  3597. return this.canvas.width;
  3598. },
  3599. set: function (val) {
  3600. this.canvas.width = Math.round(val);
  3601. },
  3602. enumerable: false,
  3603. configurable: true
  3604. });
  3605. Object.defineProperty(CanvasRenderTarget.prototype, "height", {
  3606. /**
  3607. * The height of the canvas buffer in pixels.
  3608. * @member {number}
  3609. */
  3610. get: function () {
  3611. return this.canvas.height;
  3612. },
  3613. set: function (val) {
  3614. this.canvas.height = Math.round(val);
  3615. },
  3616. enumerable: false,
  3617. configurable: true
  3618. });
  3619. return CanvasRenderTarget;
  3620. }());
  3621. /**
  3622. * Trim transparent borders from a canvas
  3623. * @memberof PIXI.utils
  3624. * @function trimCanvas
  3625. * @param {HTMLCanvasElement} canvas - the canvas to trim
  3626. * @returns {object} Trim data
  3627. */
  3628. function trimCanvas(canvas) {
  3629. // https://gist.github.com/remy/784508
  3630. var width = canvas.width;
  3631. var height = canvas.height;
  3632. var context = canvas.getContext('2d', {
  3633. willReadFrequently: true,
  3634. });
  3635. var imageData = context.getImageData(0, 0, width, height);
  3636. var pixels = imageData.data;
  3637. var len = pixels.length;
  3638. var bound = {
  3639. top: null,
  3640. left: null,
  3641. right: null,
  3642. bottom: null,
  3643. };
  3644. var data = null;
  3645. var i;
  3646. var x;
  3647. var y;
  3648. for (i = 0; i < len; i += 4) {
  3649. if (pixels[i + 3] !== 0) {
  3650. x = (i / 4) % width;
  3651. y = ~~((i / 4) / width);
  3652. if (bound.top === null) {
  3653. bound.top = y;
  3654. }
  3655. if (bound.left === null) {
  3656. bound.left = x;
  3657. }
  3658. else if (x < bound.left) {
  3659. bound.left = x;
  3660. }
  3661. if (bound.right === null) {
  3662. bound.right = x + 1;
  3663. }
  3664. else if (bound.right < x) {
  3665. bound.right = x + 1;
  3666. }
  3667. if (bound.bottom === null) {
  3668. bound.bottom = y;
  3669. }
  3670. else if (bound.bottom < y) {
  3671. bound.bottom = y;
  3672. }
  3673. }
  3674. }
  3675. if (bound.top !== null) {
  3676. width = bound.right - bound.left;
  3677. height = bound.bottom - bound.top + 1;
  3678. data = context.getImageData(bound.left, bound.top, width, height);
  3679. }
  3680. return {
  3681. height: height,
  3682. width: width,
  3683. data: data,
  3684. };
  3685. }
  3686. /**
  3687. * Regexp for data URI.
  3688. * Based on: {@link https://github.com/ragingwind/data-uri-regex}
  3689. * @static
  3690. * @constant {RegExp|string} DATA_URI
  3691. * @memberof PIXI
  3692. * @example data:image/png;base64
  3693. */
  3694. var DATA_URI = /^\s*data:(?:([\w-]+)\/([\w+.-]+))?(?:;charset=([\w-]+))?(?:;(base64))?,(.*)/i;
  3695. /**
  3696. * @memberof PIXI.utils
  3697. * @interface DecomposedDataUri
  3698. */
  3699. /**
  3700. * type, eg. `image`
  3701. * @memberof PIXI.utils.DecomposedDataUri#
  3702. * @member {string} mediaType
  3703. */
  3704. /**
  3705. * Sub type, eg. `png`
  3706. * @memberof PIXI.utils.DecomposedDataUri#
  3707. * @member {string} subType
  3708. */
  3709. /**
  3710. * @memberof PIXI.utils.DecomposedDataUri#
  3711. * @member {string} charset
  3712. */
  3713. /**
  3714. * Data encoding, eg. `base64`
  3715. * @memberof PIXI.utils.DecomposedDataUri#
  3716. * @member {string} encoding
  3717. */
  3718. /**
  3719. * The actual data
  3720. * @memberof PIXI.utils.DecomposedDataUri#
  3721. * @member {string} data
  3722. */
  3723. /**
  3724. * Split a data URI into components. Returns undefined if
  3725. * parameter `dataUri` is not a valid data URI.
  3726. * @memberof PIXI.utils
  3727. * @function decomposeDataUri
  3728. * @param {string} dataUri - the data URI to check
  3729. * @returns {PIXI.utils.DecomposedDataUri|undefined} The decomposed data uri or undefined
  3730. */
  3731. function decomposeDataUri(dataUri) {
  3732. var dataUriMatch = DATA_URI.exec(dataUri);
  3733. if (dataUriMatch) {
  3734. return {
  3735. mediaType: dataUriMatch[1] ? dataUriMatch[1].toLowerCase() : undefined,
  3736. subType: dataUriMatch[2] ? dataUriMatch[2].toLowerCase() : undefined,
  3737. charset: dataUriMatch[3] ? dataUriMatch[3].toLowerCase() : undefined,
  3738. encoding: dataUriMatch[4] ? dataUriMatch[4].toLowerCase() : undefined,
  3739. data: dataUriMatch[5],
  3740. };
  3741. }
  3742. return undefined;
  3743. }
  3744. var tempAnchor;
  3745. /**
  3746. * Sets the `crossOrigin` property for this resource based on if the url
  3747. * for this resource is cross-origin. If crossOrigin was manually set, this
  3748. * function does nothing.
  3749. * Nipped from the resource loader!
  3750. * @ignore
  3751. * @param {string} url - The url to test.
  3752. * @param {object} [loc=window.location] - The location object to test against.
  3753. * @returns {string} The crossOrigin value to use (or empty string for none).
  3754. */
  3755. function determineCrossOrigin(url$1, loc) {
  3756. if (loc === void 0) { loc = globalThis.location; }
  3757. // data: and javascript: urls are considered same-origin
  3758. if (url$1.indexOf('data:') === 0) {
  3759. return '';
  3760. }
  3761. // default is window.location
  3762. loc = loc || globalThis.location;
  3763. if (!tempAnchor) {
  3764. tempAnchor = document.createElement('a');
  3765. }
  3766. // let the browser determine the full href for the url of this resource and then
  3767. // parse with the node url lib, we can't use the properties of the anchor element
  3768. // because they don't work in IE9 :(
  3769. tempAnchor.href = url$1;
  3770. var parsedUrl = url.parse(tempAnchor.href);
  3771. var samePort = (!parsedUrl.port && loc.port === '') || (parsedUrl.port === loc.port);
  3772. // if cross origin
  3773. if (parsedUrl.hostname !== loc.hostname || !samePort || parsedUrl.protocol !== loc.protocol) {
  3774. return 'anonymous';
  3775. }
  3776. return '';
  3777. }
  3778. /**
  3779. * get the resolution / device pixel ratio of an asset by looking for the prefix
  3780. * used by spritesheets and image urls
  3781. * @memberof PIXI.utils
  3782. * @function getResolutionOfUrl
  3783. * @param {string} url - the image path
  3784. * @param {number} [defaultValue=1] - the defaultValue if no filename prefix is set.
  3785. * @returns {number} resolution / device pixel ratio of an asset
  3786. */
  3787. function getResolutionOfUrl(url, defaultValue) {
  3788. var resolution = settings.settings.RETINA_PREFIX.exec(url);
  3789. if (resolution) {
  3790. return parseFloat(resolution[1]);
  3791. }
  3792. return defaultValue !== undefined ? defaultValue : 1;
  3793. }
  3794. /**
  3795. * Generalized convenience utilities for PIXI.
  3796. * @example
  3797. * // Extend PIXI's internal Event Emitter.
  3798. * class MyEmitter extends PIXI.utils.EventEmitter {
  3799. * constructor() {
  3800. * super();
  3801. * console.log("Emitter created!");
  3802. * }
  3803. * }
  3804. *
  3805. * // Get info on current device
  3806. * console.log(PIXI.utils.isMobile);
  3807. *
  3808. * // Convert hex color to string
  3809. * console.log(PIXI.utils.hex2string(0xff00ff)); // returns: "#ff00ff"
  3810. * @namespace PIXI.utils
  3811. */
  3812. Object.defineProperty(exports, 'isMobile', {
  3813. enumerable: true,
  3814. get: function () { return settings.isMobile; }
  3815. });
  3816. exports.BaseTextureCache = BaseTextureCache;
  3817. exports.CanvasRenderTarget = CanvasRenderTarget;
  3818. exports.DATA_URI = DATA_URI;
  3819. exports.EventEmitter = eventemitter3;
  3820. exports.ProgramCache = ProgramCache;
  3821. exports.TextureCache = TextureCache;
  3822. exports.clearTextureCache = clearTextureCache;
  3823. exports.correctBlendMode = correctBlendMode;
  3824. exports.createIndicesForQuads = createIndicesForQuads;
  3825. exports.decomposeDataUri = decomposeDataUri;
  3826. exports.deprecation = deprecation;
  3827. exports.destroyTextureCache = destroyTextureCache;
  3828. exports.determineCrossOrigin = determineCrossOrigin;
  3829. exports.earcut = earcut_1;
  3830. exports.getBufferType = getBufferType;
  3831. exports.getResolutionOfUrl = getResolutionOfUrl;
  3832. exports.hex2rgb = hex2rgb;
  3833. exports.hex2string = hex2string;
  3834. exports.interleaveTypedArrays = interleaveTypedArrays;
  3835. exports.isPow2 = isPow2;
  3836. exports.isWebGLSupported = isWebGLSupported;
  3837. exports.log2 = log2;
  3838. exports.nextPow2 = nextPow2;
  3839. exports.path = path;
  3840. exports.premultiplyBlendMode = premultiplyBlendMode;
  3841. exports.premultiplyRgba = premultiplyRgba;
  3842. exports.premultiplyTint = premultiplyTint;
  3843. exports.premultiplyTintToRgba = premultiplyTintToRgba;
  3844. exports.removeItems = removeItems;
  3845. exports.rgb2hex = rgb2hex;
  3846. exports.sayHello = sayHello;
  3847. exports.sign = sign;
  3848. exports.skipHello = skipHello;
  3849. exports.string2hex = string2hex;
  3850. exports.trimCanvas = trimCanvas;
  3851. exports.uid = uid;
  3852. exports.url = url;
  3853. Object.defineProperty(exports, '__esModule', { value: true });
  3854. return exports;
  3855. })({}, PIXI, PIXI);
  3856. Object.assign(this.PIXI.utils, _pixi_utils);
  3857. //# sourceMappingURL=utils.js.map