weapp-adapter.js 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662
  1. /******/ (function(modules) { // webpackBootstrap
  2. /******/ // The module cache
  3. /******/ var installedModules = {};
  4. /******/ // The require function
  5. /******/ function __webpack_require__(moduleId) {
  6. /******/ // Check if module is in cache
  7. /******/ if(installedModules[moduleId])
  8. /******/ return installedModules[moduleId].exports;
  9. /******/ // Create a new module (and put it into the cache)
  10. /******/ var module = installedModules[moduleId] = {
  11. /******/ exports: {},
  12. /******/ id: moduleId,
  13. /******/ loaded: false
  14. /******/ };
  15. /******/ // Execute the module function
  16. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  17. /******/ // Flag the module as loaded
  18. /******/ module.loaded = true;
  19. /******/ // Return the exports of the module
  20. /******/ return module.exports;
  21. /******/ }
  22. /******/ // expose the modules object (__webpack_modules__)
  23. /******/ __webpack_require__.m = modules;
  24. /******/ // expose the module cache
  25. /******/ __webpack_require__.c = installedModules;
  26. /******/ // __webpack_public_path__
  27. /******/ __webpack_require__.p = "";
  28. /******/ // Load entry module and return exports
  29. /******/ return __webpack_require__(0);
  30. /******/ })
  31. /************************************************************************/
  32. /******/ ([
  33. /* 0 */
  34. /***/ (function(module, exports, __webpack_require__) {
  35. 'use strict';
  36. var _window2 = __webpack_require__(1);
  37. var _window = _interopRequireWildcard(_window2);
  38. var _HTMLElement = __webpack_require__(4);
  39. var _HTMLElement2 = _interopRequireDefault(_HTMLElement);
  40. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  41. function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
  42. var global = GameGlobal;
  43. function inject() {
  44. _window.addEventListener = function (type, listener) {
  45. _window.document.addEventListener(type, listener);
  46. };
  47. _window.removeEventListener = function (type, listener) {
  48. _window.document.removeEventListener(type, listener);
  49. };
  50. if (_window.canvas) {
  51. _window.canvas.addEventListener = _window.addEventListener;
  52. _window.canvas.removeEventListener = _window.removeEventListener;
  53. }
  54. if (global.sharedCanvas) {
  55. // eslint-disable-next-line no-undef
  56. sharedCanvas.__proto__.__proto__ = new _HTMLElement2.default('canvas');
  57. // eslint-disable-next-line no-undef
  58. sharedCanvas.addEventListener = _window.addEventListener;
  59. // eslint-disable-next-line no-undef
  60. sharedCanvas.removeEventListener = _window.removeEventListener;
  61. }
  62. var _wx$getSystemInfoSync = wx.getSystemInfoSync(),
  63. platform = _wx$getSystemInfoSync.platform;
  64. // 开发者工具无法重定义 window
  65. if (typeof __devtoolssubcontext === 'undefined' && platform === 'devtools') {
  66. for (var key in _window) {
  67. var descriptor = Object.getOwnPropertyDescriptor(global, key);
  68. if (!descriptor || descriptor.configurable === true) {
  69. Object.defineProperty(window, key, {
  70. value: _window[key]
  71. });
  72. }
  73. }
  74. for (var _key in _window.document) {
  75. var _descriptor = Object.getOwnPropertyDescriptor(global.document, _key);
  76. if (!_descriptor || _descriptor.configurable === true) {
  77. Object.defineProperty(global.document, _key, {
  78. value: _window.document[_key]
  79. });
  80. }
  81. }
  82. window.parent = window;
  83. } else {
  84. for (var _key2 in _window) {
  85. global[_key2] = _window[_key2];
  86. }
  87. global.window = _window;
  88. window = global;
  89. window.top = window.parent = window;
  90. }
  91. }
  92. if (!GameGlobal.__isAdapterInjected) {
  93. GameGlobal.__isAdapterInjected = true;
  94. inject();
  95. }
  96. /***/ }),
  97. /* 1 */
  98. /***/ (function(module, exports, __webpack_require__) {
  99. 'use strict';
  100. Object.defineProperty(exports, "__esModule", {
  101. value: true
  102. });
  103. exports.cancelAnimationFrame = exports.requestAnimationFrame = exports.clearInterval = exports.clearTimeout = exports.setInterval = exports.setTimeout = exports.canvas = exports.location = exports.localStorage = exports.HTMLElement = exports.FileReader = exports.Audio = exports.Image = exports.WebSocket = exports.XMLHttpRequest = exports.navigator = exports.document = undefined;
  104. var _WindowProperties = __webpack_require__(2);
  105. Object.keys(_WindowProperties).forEach(function (key) {
  106. if (key === "default" || key === "__esModule") return;
  107. Object.defineProperty(exports, key, {
  108. enumerable: true,
  109. get: function get() {
  110. return _WindowProperties[key];
  111. }
  112. });
  113. });
  114. var _constructor = __webpack_require__(3);
  115. Object.keys(_constructor).forEach(function (key) {
  116. if (key === "default" || key === "__esModule") return;
  117. Object.defineProperty(exports, key, {
  118. enumerable: true,
  119. get: function get() {
  120. return _constructor[key];
  121. }
  122. });
  123. });
  124. var _Canvas = __webpack_require__(9);
  125. var _Canvas2 = _interopRequireDefault(_Canvas);
  126. var _Util = __webpack_require__(17);
  127. var _document2 = __webpack_require__(10);
  128. var _document3 = _interopRequireDefault(_document2);
  129. var _navigator2 = __webpack_require__(18);
  130. var _navigator3 = _interopRequireDefault(_navigator2);
  131. var _XMLHttpRequest2 = __webpack_require__(19);
  132. var _XMLHttpRequest3 = _interopRequireDefault(_XMLHttpRequest2);
  133. var _WebSocket2 = __webpack_require__(20);
  134. var _WebSocket3 = _interopRequireDefault(_WebSocket2);
  135. var _Image2 = __webpack_require__(11);
  136. var _Image3 = _interopRequireDefault(_Image2);
  137. var _Audio2 = __webpack_require__(12);
  138. var _Audio3 = _interopRequireDefault(_Audio2);
  139. var _FileReader2 = __webpack_require__(21);
  140. var _FileReader3 = _interopRequireDefault(_FileReader2);
  141. var _HTMLElement2 = __webpack_require__(4);
  142. var _HTMLElement3 = _interopRequireDefault(_HTMLElement2);
  143. var _localStorage2 = __webpack_require__(22);
  144. var _localStorage3 = _interopRequireDefault(_localStorage2);
  145. var _location2 = __webpack_require__(23);
  146. var _location3 = _interopRequireDefault(_location2);
  147. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  148. exports.document = _document3.default;
  149. exports.navigator = _navigator3.default;
  150. exports.XMLHttpRequest = _XMLHttpRequest3.default;
  151. exports.WebSocket = _WebSocket3.default;
  152. exports.Image = _Image3.default;
  153. exports.Audio = _Audio3.default;
  154. exports.FileReader = _FileReader3.default;
  155. exports.HTMLElement = _HTMLElement3.default;
  156. exports.localStorage = _localStorage3.default;
  157. exports.location = _location3.default;
  158. // 暴露全局的 canvas
  159. var canvas = (0, _Util.isSubContext)() ? undefined : new _Canvas2.default();
  160. exports.canvas = canvas;
  161. exports.setTimeout = setTimeout;
  162. exports.setInterval = setInterval;
  163. exports.clearTimeout = clearTimeout;
  164. exports.clearInterval = clearInterval;
  165. exports.requestAnimationFrame = requestAnimationFrame;
  166. exports.cancelAnimationFrame = cancelAnimationFrame;
  167. /***/ }),
  168. /* 2 */
  169. /***/ (function(module, exports) {
  170. "use strict";
  171. Object.defineProperty(exports, "__esModule", {
  172. value: true
  173. });
  174. var _wx$getSystemInfoSync = wx.getSystemInfoSync(),
  175. screenWidth = _wx$getSystemInfoSync.screenWidth,
  176. screenHeight = _wx$getSystemInfoSync.screenHeight,
  177. devicePixelRatio = _wx$getSystemInfoSync.devicePixelRatio;
  178. var innerWidth = exports.innerWidth = screenWidth;
  179. var innerHeight = exports.innerHeight = screenHeight;
  180. exports.devicePixelRatio = devicePixelRatio;
  181. var screen = exports.screen = {
  182. availWidth: innerWidth,
  183. availHeight: innerHeight
  184. };
  185. var performance = exports.performance = {
  186. now: function now() {
  187. return Date.now() / 1000;
  188. }
  189. };
  190. var ontouchstart = exports.ontouchstart = null;
  191. var ontouchmove = exports.ontouchmove = null;
  192. var ontouchend = exports.ontouchend = null;
  193. /***/ }),
  194. /* 3 */
  195. /***/ (function(module, exports, __webpack_require__) {
  196. 'use strict';
  197. Object.defineProperty(exports, "__esModule", {
  198. value: true
  199. });
  200. exports.HTMLCanvasElement = exports.HTMLImageElement = undefined;
  201. var _HTMLElement3 = __webpack_require__(4);
  202. var _HTMLElement4 = _interopRequireDefault(_HTMLElement3);
  203. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  204. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  205. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  206. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  207. var HTMLImageElement = exports.HTMLImageElement = function (_HTMLElement) {
  208. _inherits(HTMLImageElement, _HTMLElement);
  209. function HTMLImageElement() {
  210. _classCallCheck(this, HTMLImageElement);
  211. return _possibleConstructorReturn(this, (HTMLImageElement.__proto__ || Object.getPrototypeOf(HTMLImageElement)).call(this, 'img'));
  212. }
  213. return HTMLImageElement;
  214. }(_HTMLElement4.default);
  215. var HTMLCanvasElement = exports.HTMLCanvasElement = function (_HTMLElement2) {
  216. _inherits(HTMLCanvasElement, _HTMLElement2);
  217. function HTMLCanvasElement() {
  218. _classCallCheck(this, HTMLCanvasElement);
  219. return _possibleConstructorReturn(this, (HTMLCanvasElement.__proto__ || Object.getPrototypeOf(HTMLCanvasElement)).call(this, 'canvas'));
  220. }
  221. return HTMLCanvasElement;
  222. }(_HTMLElement4.default);
  223. /***/ }),
  224. /* 4 */
  225. /***/ (function(module, exports, __webpack_require__) {
  226. 'use strict';
  227. Object.defineProperty(exports, "__esModule", {
  228. value: true
  229. });
  230. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  231. var _Element2 = __webpack_require__(5);
  232. var _Element3 = _interopRequireDefault(_Element2);
  233. var _util = __webpack_require__(8);
  234. var _WindowProperties = __webpack_require__(2);
  235. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  236. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  237. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  238. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  239. var HTMLElement = function (_Element) {
  240. _inherits(HTMLElement, _Element);
  241. function HTMLElement() {
  242. var tagName = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
  243. _classCallCheck(this, HTMLElement);
  244. var _this = _possibleConstructorReturn(this, (HTMLElement.__proto__ || Object.getPrototypeOf(HTMLElement)).call(this));
  245. _this.className = '';
  246. _this.childern = [];
  247. _this.style = {
  248. width: _WindowProperties.innerWidth + 'px',
  249. height: _WindowProperties.innerHeight + 'px'
  250. };
  251. _this.insertBefore = _util.noop;
  252. _this.innerHTML = '';
  253. _this.tagName = tagName.toUpperCase();
  254. return _this;
  255. }
  256. _createClass(HTMLElement, [{
  257. key: 'setAttribute',
  258. value: function setAttribute(name, value) {
  259. this[name] = value;
  260. }
  261. }, {
  262. key: 'getAttribute',
  263. value: function getAttribute(name) {
  264. return this[name];
  265. }
  266. }, {
  267. key: 'getBoundingClientRect',
  268. value: function getBoundingClientRect() {
  269. return {
  270. top: 0,
  271. left: 0,
  272. width: _WindowProperties.innerWidth,
  273. height: _WindowProperties.innerHeight
  274. };
  275. }
  276. }, {
  277. key: 'focus',
  278. value: function focus() {}
  279. }, {
  280. key: 'clientWidth',
  281. get: function get() {
  282. var ret = parseInt(this.style.fontSize, 10) * this.innerHTML.length;
  283. return Number.isNaN(ret) ? 0 : ret;
  284. }
  285. }, {
  286. key: 'clientHeight',
  287. get: function get() {
  288. var ret = parseInt(this.style.fontSize, 10);
  289. return Number.isNaN(ret) ? 0 : ret;
  290. }
  291. }]);
  292. return HTMLElement;
  293. }(_Element3.default);
  294. exports.default = HTMLElement;
  295. /***/ }),
  296. /* 5 */
  297. /***/ (function(module, exports, __webpack_require__) {
  298. 'use strict';
  299. Object.defineProperty(exports, "__esModule", {
  300. value: true
  301. });
  302. var _Node2 = __webpack_require__(6);
  303. var _Node3 = _interopRequireDefault(_Node2);
  304. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  305. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  306. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  307. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  308. var ELement = function (_Node) {
  309. _inherits(ELement, _Node);
  310. function ELement() {
  311. _classCallCheck(this, ELement);
  312. var _this = _possibleConstructorReturn(this, (ELement.__proto__ || Object.getPrototypeOf(ELement)).call(this));
  313. _this.className = '';
  314. _this.children = [];
  315. return _this;
  316. }
  317. return ELement;
  318. }(_Node3.default);
  319. exports.default = ELement;
  320. /***/ }),
  321. /* 6 */
  322. /***/ (function(module, exports, __webpack_require__) {
  323. 'use strict';
  324. Object.defineProperty(exports, "__esModule", {
  325. value: true
  326. });
  327. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  328. var _EventTarget2 = __webpack_require__(7);
  329. var _EventTarget3 = _interopRequireDefault(_EventTarget2);
  330. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  331. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  332. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  333. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  334. var Node = function (_EventTarget) {
  335. _inherits(Node, _EventTarget);
  336. function Node() {
  337. _classCallCheck(this, Node);
  338. var _this = _possibleConstructorReturn(this, (Node.__proto__ || Object.getPrototypeOf(Node)).call(this));
  339. _this.childNodes = [];
  340. return _this;
  341. }
  342. _createClass(Node, [{
  343. key: 'appendChild',
  344. value: function appendChild(node) {
  345. if (node instanceof Node) {
  346. this.childNodes.push(node);
  347. } else {
  348. throw new TypeError('Failed to executed \'appendChild\' on \'Node\': parameter 1 is not of type \'Node\'.');
  349. }
  350. }
  351. }, {
  352. key: 'cloneNode',
  353. value: function cloneNode() {
  354. var copyNode = Object.create(this);
  355. Object.assign(copyNode, this);
  356. return copyNode;
  357. }
  358. }, {
  359. key: 'removeChild',
  360. value: function removeChild(node) {
  361. var index = this.childNodes.findIndex(function (child) {
  362. return child === node;
  363. });
  364. if (index > -1) {
  365. return this.childNodes.splice(index, 1);
  366. }
  367. return null;
  368. }
  369. }]);
  370. return Node;
  371. }(_EventTarget3.default);
  372. exports.default = Node;
  373. /***/ }),
  374. /* 7 */
  375. /***/ (function(module, exports) {
  376. 'use strict';
  377. Object.defineProperty(exports, "__esModule", {
  378. value: true
  379. });
  380. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  381. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  382. var _events = new WeakMap();
  383. var EventTarget = function () {
  384. function EventTarget() {
  385. _classCallCheck(this, EventTarget);
  386. _events.set(this, {});
  387. }
  388. _createClass(EventTarget, [{
  389. key: 'addEventListener',
  390. value: function addEventListener(type, listener) {
  391. var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  392. var events = _events.get(this);
  393. if (!events) {
  394. events = {};
  395. _events.set(this, events);
  396. }
  397. if (!events[type]) {
  398. events[type] = [];
  399. }
  400. events[type].push(listener);
  401. if (options.capture) {
  402. console.warn('EventTarget.addEventListener: options.capture is not implemented.');
  403. }
  404. if (options.once) {
  405. console.warn('EventTarget.addEventListener: options.once is not implemented.');
  406. }
  407. if (options.passive) {
  408. console.warn('EventTarget.addEventListener: options.passive is not implemented.');
  409. }
  410. }
  411. }, {
  412. key: 'removeEventListener',
  413. value: function removeEventListener(type, listener) {
  414. var listeners = _events.get(this)[type];
  415. if (listeners && listeners.length > 0) {
  416. for (var i = listeners.length; i--; i > 0) {
  417. if (listeners[i] === listener) {
  418. listeners.splice(i, 1);
  419. break;
  420. }
  421. }
  422. }
  423. }
  424. }, {
  425. key: 'dispatchEvent',
  426. value: function dispatchEvent() {
  427. var event = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  428. var listeners = _events.get(this)[event.type];
  429. if (listeners) {
  430. for (var i = 0; i < listeners.length; i++) {
  431. listeners[i](event);
  432. }
  433. }
  434. }
  435. }]);
  436. return EventTarget;
  437. }();
  438. exports.default = EventTarget;
  439. /***/ }),
  440. /* 8 */
  441. /***/ (function(module, exports) {
  442. 'use strict';
  443. Object.defineProperty(exports, "__esModule", {
  444. value: true
  445. });
  446. exports.noop = noop;
  447. exports.isSubContext = isSubContext;
  448. function noop() {}
  449. function isSubContext() {
  450. return typeof GameGlobal !== 'undefined' && GameGlobal.__isSubContext === true;
  451. }
  452. /***/ }),
  453. /* 9 */
  454. /***/ (function(module, exports, __webpack_require__) {
  455. 'use strict';
  456. Object.defineProperty(exports, "__esModule", {
  457. value: true
  458. });
  459. exports.default = Canvas;
  460. var _constructor = __webpack_require__(3);
  461. var _HTMLElement = __webpack_require__(4);
  462. var _HTMLElement2 = _interopRequireDefault(_HTMLElement);
  463. var _document = __webpack_require__(10);
  464. var _document2 = _interopRequireDefault(_document);
  465. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  466. var hasModifiedCanvasPrototype = false;
  467. var hasInit2DContextConstructor = false;
  468. var hasInitWebGLContextConstructor = false;
  469. function Canvas() {
  470. var canvas = wx.createCanvas();
  471. canvas.type = 'canvas';
  472. canvas.__proto__.__proto__ = new _HTMLElement2.default('canvas');
  473. var _getContext = canvas.getContext;
  474. canvas.getBoundingClientRect = function () {
  475. var ret = {
  476. top: 0,
  477. left: 0,
  478. width: window.innerWidth,
  479. height: window.innerHeight
  480. };
  481. return ret;
  482. };
  483. return canvas;
  484. }
  485. /***/ }),
  486. /* 10 */
  487. /***/ (function(module, exports, __webpack_require__) {
  488. 'use strict';
  489. Object.defineProperty(exports, "__esModule", {
  490. value: true
  491. });
  492. var _window = __webpack_require__(1);
  493. var window = _interopRequireWildcard(_window);
  494. var _HTMLElement = __webpack_require__(4);
  495. var _HTMLElement2 = _interopRequireDefault(_HTMLElement);
  496. var _Image = __webpack_require__(11);
  497. var _Image2 = _interopRequireDefault(_Image);
  498. var _Audio = __webpack_require__(12);
  499. var _Audio2 = _interopRequireDefault(_Audio);
  500. var _Canvas = __webpack_require__(9);
  501. var _Canvas2 = _interopRequireDefault(_Canvas);
  502. __webpack_require__(15);
  503. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  504. function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
  505. var events = {};
  506. var document = {
  507. readyState: 'complete',
  508. visibilityState: 'visible',
  509. documentElement: window,
  510. hidden: false,
  511. style: {},
  512. location: window.location,
  513. ontouchstart: null,
  514. ontouchmove: null,
  515. ontouchend: null,
  516. head: new _HTMLElement2.default('head'),
  517. body: new _HTMLElement2.default('body'),
  518. createElement: function createElement(tagName) {
  519. if (tagName === 'canvas') {
  520. return new _Canvas2.default();
  521. } else if (tagName === 'audio') {
  522. return new _Audio2.default();
  523. } else if (tagName === 'img') {
  524. return new _Image2.default();
  525. }
  526. return new _HTMLElement2.default(tagName);
  527. },
  528. getElementById: function getElementById(id) {
  529. if (id === window.canvas.id) {
  530. return window.canvas;
  531. }
  532. return null;
  533. },
  534. getElementsByTagName: function getElementsByTagName(tagName) {
  535. if (tagName === 'head') {
  536. return [document.head];
  537. } else if (tagName === 'body') {
  538. return [document.body];
  539. } else if (tagName === 'canvas') {
  540. return [window.canvas];
  541. }
  542. return [];
  543. },
  544. querySelector: function querySelector(query) {
  545. if (query === 'head') {
  546. return document.head;
  547. } else if (query === 'body') {
  548. return document.body;
  549. } else if (query === 'canvas') {
  550. return window.canvas;
  551. } else if (query === '#' + window.canvas.id) {
  552. return window.canvas;
  553. }
  554. return null;
  555. },
  556. querySelectorAll: function querySelectorAll(query) {
  557. if (query === 'head') {
  558. return [document.head];
  559. } else if (query === 'body') {
  560. return [document.body];
  561. } else if (query === 'canvas') {
  562. return [window.canvas];
  563. }
  564. return [];
  565. },
  566. addEventListener: function addEventListener(type, listener) {
  567. if (!events[type]) {
  568. events[type] = [];
  569. }
  570. events[type].push(listener);
  571. },
  572. removeEventListener: function removeEventListener(type, listener) {
  573. var listeners = events[type];
  574. if (listeners && listeners.length > 0) {
  575. for (var i = listeners.length; i--; i > 0) {
  576. if (listeners[i] === listener) {
  577. listeners.splice(i, 1);
  578. break;
  579. }
  580. }
  581. }
  582. },
  583. dispatchEvent: function dispatchEvent(event) {
  584. var listeners = events[event.type];
  585. if (listeners) {
  586. for (var i = 0; i < listeners.length; i++) {
  587. listeners[i](event);
  588. }
  589. }
  590. }
  591. };
  592. exports.default = document;
  593. /***/ }),
  594. /* 11 */
  595. /***/ (function(module, exports) {
  596. "use strict";
  597. Object.defineProperty(exports, "__esModule", {
  598. value: true
  599. });
  600. exports.default = Image;
  601. function Image() {
  602. var image = wx.createImage();
  603. return image;
  604. }
  605. /***/ }),
  606. /* 12 */
  607. /***/ (function(module, exports, __webpack_require__) {
  608. 'use strict';
  609. Object.defineProperty(exports, "__esModule", {
  610. value: true
  611. });
  612. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  613. var _HTMLAudioElement2 = __webpack_require__(13);
  614. var _HTMLAudioElement3 = _interopRequireDefault(_HTMLAudioElement2);
  615. var _util = __webpack_require__(8);
  616. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  617. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  618. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  619. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  620. var HAVE_NOTHING = 0;
  621. var HAVE_METADATA = 1;
  622. var HAVE_CURRENT_DATA = 2;
  623. var HAVE_FUTURE_DATA = 3;
  624. var HAVE_ENOUGH_DATA = 4;
  625. var _innerAudioContext = new WeakMap();
  626. var _src = new WeakMap();
  627. var _loop = new WeakMap();
  628. var _autoplay = new WeakMap();
  629. var Audio = function (_HTMLAudioElement) {
  630. _inherits(Audio, _HTMLAudioElement);
  631. function Audio(url) {
  632. _classCallCheck(this, Audio);
  633. var _this = _possibleConstructorReturn(this, (Audio.__proto__ || Object.getPrototypeOf(Audio)).call(this));
  634. _this.HAVE_NOTHING = HAVE_NOTHING;
  635. _this.HAVE_METADATA = HAVE_METADATA;
  636. _this.HAVE_CURRENT_DATA = HAVE_CURRENT_DATA;
  637. _this.HAVE_FUTURE_DATA = HAVE_FUTURE_DATA;
  638. _this.HAVE_ENOUGH_DATA = HAVE_ENOUGH_DATA;
  639. _this.readyState = HAVE_NOTHING;
  640. if ((0, _util.isSubContext)()) {
  641. console.warn('HTMLAudioElement is not supported in SubContext.');
  642. return _possibleConstructorReturn(_this);
  643. }
  644. _src.set(_this, '');
  645. var innerAudioContext = wx.createInnerAudioContext();
  646. _innerAudioContext.set(_this, innerAudioContext);
  647. innerAudioContext.onCanplay(function () {
  648. _this.dispatchEvent({ type: 'load' });
  649. _this.dispatchEvent({ type: 'loadend' });
  650. _this.dispatchEvent({ type: 'canplay' });
  651. _this.dispatchEvent({ type: 'canplaythrough' });
  652. _this.dispatchEvent({ type: 'loadedmetadata' });
  653. _this.readyState = HAVE_CURRENT_DATA;
  654. });
  655. innerAudioContext.onPlay(function () {
  656. _this.dispatchEvent({ type: 'play' });
  657. });
  658. innerAudioContext.onPause(function () {
  659. _this.dispatchEvent({ type: 'pause' });
  660. });
  661. innerAudioContext.onEnded(function () {
  662. _this.dispatchEvent({ type: 'ended' });
  663. _this.readyState = HAVE_ENOUGH_DATA;
  664. });
  665. innerAudioContext.onError(function () {
  666. _this.dispatchEvent({ type: 'error' });
  667. });
  668. if (url) {
  669. _innerAudioContext.get(_this).src = url;
  670. }
  671. return _this;
  672. }
  673. _createClass(Audio, [{
  674. key: 'load',
  675. value: function load() {
  676. console.warn('HTMLAudioElement.load() is not implemented.');
  677. }
  678. }, {
  679. key: 'play',
  680. value: function play() {
  681. if (!(0, _util.isSubContext)()) {
  682. _innerAudioContext.get(this).play();
  683. }
  684. }
  685. }, {
  686. key: 'pause',
  687. value: function pause() {
  688. if (!(0, _util.isSubContext)()) {
  689. _innerAudioContext.get(this).pause();
  690. }
  691. }
  692. }, {
  693. key: 'canPlayType',
  694. value: function canPlayType() {
  695. var mediaType = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
  696. if (typeof mediaType !== 'string') {
  697. return '';
  698. }
  699. if (mediaType.indexOf('audio/mpeg') > -1 || mediaType.indexOf('audio/mp4')) {
  700. return 'probably';
  701. }
  702. return '';
  703. }
  704. }, {
  705. key: 'cloneNode',
  706. value: function cloneNode() {
  707. var newAudio = new Audio();
  708. if (!(0, _util.isSubContext)()) {
  709. newAudio.loop = _innerAudioContext.get(this).loop;
  710. newAudio.autoplay = _innerAudioContext.get(this).loop;
  711. newAudio.src = this.src;
  712. }
  713. return newAudio;
  714. }
  715. }, {
  716. key: 'currentTime',
  717. get: function get() {
  718. if (!(0, _util.isSubContext)()) {
  719. return _innerAudioContext.get(this).currentTime;
  720. }
  721. return 0;
  722. },
  723. set: function set(value) {
  724. if (!(0, _util.isSubContext)()) {
  725. _innerAudioContext.get(this).seek(value);
  726. }
  727. }
  728. }, {
  729. key: 'src',
  730. get: function get() {
  731. return _src.get(this);
  732. },
  733. set: function set(value) {
  734. _src.set(this, value);
  735. if (!(0, _util.isSubContext)()) {
  736. _innerAudioContext.get(this).src = value;
  737. }
  738. }
  739. }, {
  740. key: 'loop',
  741. get: function get() {
  742. if (!(0, _util.isSubContext)()) {
  743. return _innerAudioContext.get(this).loop;
  744. }
  745. return false;
  746. },
  747. set: function set(value) {
  748. if (!(0, _util.isSubContext)()) {
  749. _innerAudioContext.get(this).loop = value;
  750. }
  751. }
  752. }, {
  753. key: 'autoplay',
  754. get: function get() {
  755. if (!(0, _util.isSubContext)()) {
  756. return _innerAudioContext.get(this).autoplay;
  757. }
  758. return false;
  759. },
  760. set: function set(value) {
  761. if (!(0, _util.isSubContext)()) {
  762. _innerAudioContext.get(this).autoplay = value;
  763. }
  764. }
  765. }, {
  766. key: 'paused',
  767. get: function get() {
  768. if (!(0, _util.isSubContext)()) {
  769. return _innerAudioContext.get(this).paused;
  770. }
  771. return false;
  772. }
  773. }]);
  774. return Audio;
  775. }(_HTMLAudioElement3.default);
  776. exports.default = Audio;
  777. /***/ }),
  778. /* 13 */
  779. /***/ (function(module, exports, __webpack_require__) {
  780. 'use strict';
  781. Object.defineProperty(exports, "__esModule", {
  782. value: true
  783. });
  784. var _HTMLMediaElement2 = __webpack_require__(14);
  785. var _HTMLMediaElement3 = _interopRequireDefault(_HTMLMediaElement2);
  786. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  787. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  788. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  789. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  790. var HTMLAudioElement = function (_HTMLMediaElement) {
  791. _inherits(HTMLAudioElement, _HTMLMediaElement);
  792. function HTMLAudioElement() {
  793. _classCallCheck(this, HTMLAudioElement);
  794. return _possibleConstructorReturn(this, (HTMLAudioElement.__proto__ || Object.getPrototypeOf(HTMLAudioElement)).call(this, 'audio'));
  795. }
  796. return HTMLAudioElement;
  797. }(_HTMLMediaElement3.default);
  798. exports.default = HTMLAudioElement;
  799. /***/ }),
  800. /* 14 */
  801. /***/ (function(module, exports, __webpack_require__) {
  802. 'use strict';
  803. Object.defineProperty(exports, "__esModule", {
  804. value: true
  805. });
  806. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  807. var _HTMLElement2 = __webpack_require__(4);
  808. var _HTMLElement3 = _interopRequireDefault(_HTMLElement2);
  809. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  810. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  811. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  812. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  813. var HTMLMediaElement = function (_HTMLElement) {
  814. _inherits(HTMLMediaElement, _HTMLElement);
  815. function HTMLMediaElement(type) {
  816. _classCallCheck(this, HTMLMediaElement);
  817. return _possibleConstructorReturn(this, (HTMLMediaElement.__proto__ || Object.getPrototypeOf(HTMLMediaElement)).call(this, type));
  818. }
  819. _createClass(HTMLMediaElement, [{
  820. key: 'addTextTrack',
  821. value: function addTextTrack() {}
  822. }, {
  823. key: 'captureStream',
  824. value: function captureStream() {}
  825. }, {
  826. key: 'fastSeek',
  827. value: function fastSeek() {}
  828. }, {
  829. key: 'load',
  830. value: function load() {}
  831. }, {
  832. key: 'pause',
  833. value: function pause() {}
  834. }, {
  835. key: 'play',
  836. value: function play() {}
  837. }]);
  838. return HTMLMediaElement;
  839. }(_HTMLElement3.default);
  840. exports.default = HTMLMediaElement;
  841. /***/ }),
  842. /* 15 */
  843. /***/ (function(module, exports, __webpack_require__) {
  844. 'use strict';
  845. __webpack_require__(16);
  846. /***/ }),
  847. /* 16 */
  848. /***/ (function(module, exports, __webpack_require__) {
  849. 'use strict';
  850. var _window = __webpack_require__(1);
  851. var window = _interopRequireWildcard(_window);
  852. var _document = __webpack_require__(10);
  853. var _document2 = _interopRequireDefault(_document);
  854. var _util = __webpack_require__(8);
  855. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  856. function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
  857. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  858. var TouchEvent = function TouchEvent(type) {
  859. _classCallCheck(this, TouchEvent);
  860. this.target = window.canvas;
  861. this.currentTarget = window.canvas;
  862. this.touches = [];
  863. this.targetTouches = [];
  864. this.changedTouches = [];
  865. this.preventDefault = _util.noop;
  866. this.stopPropagation = _util.noop;
  867. this.type = type;
  868. };
  869. function touchEventHandlerFactory(type) {
  870. return function (event) {
  871. var touchEvent = new TouchEvent(type);
  872. touchEvent.touches = event.touches;
  873. touchEvent.targetTouches = Array.prototype.slice.call(event.touches);
  874. touchEvent.changedTouches = event.changedTouches;
  875. touchEvent.timeStamp = event.timeStamp;
  876. _document2.default.dispatchEvent(touchEvent);
  877. };
  878. }
  879. wx.onTouchStart(touchEventHandlerFactory('touchstart'));
  880. wx.onTouchMove(touchEventHandlerFactory('touchmove'));
  881. wx.onTouchEnd(touchEventHandlerFactory('touchend'));
  882. wx.onTouchCancel(touchEventHandlerFactory('touchcancel'));
  883. /***/ }),
  884. /* 17 */
  885. /***/ (function(module, exports) {
  886. 'use strict';
  887. Object.defineProperty(exports, "__esModule", {
  888. value: true
  889. });
  890. exports.noop = noop;
  891. exports.isSubContext = isSubContext;
  892. function noop() {}
  893. function isSubContext() {
  894. return typeof GameGlobal !== 'undefined' && GameGlobal.__isSubContext === true;
  895. }
  896. /***/ }),
  897. /* 18 */
  898. /***/ (function(module, exports, __webpack_require__) {
  899. 'use strict';
  900. Object.defineProperty(exports, "__esModule", {
  901. value: true
  902. });
  903. var _util = __webpack_require__(8);
  904. // TODO 需要 wx.getSystemInfo 获取更详细信息
  905. var _wx$getSystemInfoSync = wx.getSystemInfoSync(),
  906. platform = _wx$getSystemInfoSync.platform;
  907. var navigator = {
  908. platform: platform,
  909. language: 'zh-cn',
  910. appVersion: '5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1',
  911. userAgent: 'Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_1 like Mac OS X) AppleWebKit/603.1.30 (KHTML, like Gecko) Mobile/14E8301 MicroMessenger/6.6.0 MiniGame NetType/WIFI Language/zh_CN',
  912. onLine: true, // TODO 用 wx.getNetworkStateChange 和 wx.onNetworkStateChange 来返回真实的状态
  913. // TODO 用 wx.getLocation 来封装 geolocation
  914. geolocation: {
  915. getCurrentPosition: _util.noop,
  916. watchPosition: _util.noop,
  917. clearWatch: _util.noop
  918. }
  919. };
  920. exports.default = navigator;
  921. /***/ }),
  922. /* 19 */
  923. /***/ (function(module, exports) {
  924. 'use strict';
  925. Object.defineProperty(exports, "__esModule", {
  926. value: true
  927. });
  928. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  929. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  930. var _url = new WeakMap();
  931. var _method = new WeakMap();
  932. var _requestHeader = new WeakMap();
  933. var _responseHeader = new WeakMap();
  934. var _requestTask = new WeakMap();
  935. function _triggerEvent(type) {
  936. if (typeof this['on' + type] === 'function') {
  937. for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
  938. args[_key - 1] = arguments[_key];
  939. }
  940. this['on' + type].apply(this, args);
  941. }
  942. }
  943. function _changeReadyState(readyState) {
  944. this.readyState = readyState;
  945. _triggerEvent.call(this, 'readystatechange');
  946. }
  947. var XMLHttpRequest = function () {
  948. // TODO 没法模拟 HEADERS_RECEIVED 和 LOADING 两个状态
  949. function XMLHttpRequest() {
  950. _classCallCheck(this, XMLHttpRequest);
  951. this.onabort = null;
  952. this.onerror = null;
  953. this.onload = null;
  954. this.onloadstart = null;
  955. this.onprogress = null;
  956. this.ontimeout = null;
  957. this.onloadend = null;
  958. this.onreadystatechange = null;
  959. this.readyState = 0;
  960. this.response = null;
  961. this.responseText = null;
  962. this.responseType = '';
  963. this.responseXML = null;
  964. this.status = 0;
  965. this.statusText = '';
  966. this.upload = {};
  967. this.withCredentials = false;
  968. _requestHeader.set(this, {
  969. 'content-type': 'application/x-www-form-urlencoded'
  970. });
  971. _responseHeader.set(this, {});
  972. }
  973. /*
  974. * TODO 这一批事件应该是在 XMLHttpRequestEventTarget.prototype 上面的
  975. */
  976. _createClass(XMLHttpRequest, [{
  977. key: 'abort',
  978. value: function abort() {
  979. var myRequestTask = _requestTask.get(this);
  980. if (myRequestTask) {
  981. myRequestTask.abort();
  982. }
  983. }
  984. }, {
  985. key: 'getAllResponseHeaders',
  986. value: function getAllResponseHeaders() {
  987. var responseHeader = _responseHeader.get(this);
  988. return Object.keys(responseHeader).map(function (header) {
  989. return header + ': ' + responseHeader[header];
  990. }).join('\n');
  991. }
  992. }, {
  993. key: 'getResponseHeader',
  994. value: function getResponseHeader(header) {
  995. return _responseHeader.get(this)[header];
  996. }
  997. }, {
  998. key: 'open',
  999. value: function open(method, url /* async, user, password 这几个参数在小程序内不支持*/) {
  1000. _method.set(this, method);
  1001. _url.set(this, url);
  1002. _changeReadyState.call(this, XMLHttpRequest.OPENED);
  1003. }
  1004. }, {
  1005. key: 'overrideMimeType',
  1006. value: function overrideMimeType() {}
  1007. }, {
  1008. key: 'send',
  1009. value: function send() {
  1010. var _this = this;
  1011. var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
  1012. if (this.readyState !== XMLHttpRequest.OPENED) {
  1013. throw new Error("Failed to execute 'send' on 'XMLHttpRequest': The object's state must be OPENED.");
  1014. } else {
  1015. wx.request({
  1016. data: data,
  1017. url: _url.get(this),
  1018. method: _method.get(this),
  1019. header: _requestHeader.get(this),
  1020. responseType: this.responseType,
  1021. success: function success(_ref) {
  1022. var data = _ref.data,
  1023. statusCode = _ref.statusCode,
  1024. header = _ref.header;
  1025. if (typeof data !== 'string' && !(data instanceof ArrayBuffer)) {
  1026. try {
  1027. data = JSON.stringify(data);
  1028. } catch (e) {
  1029. data = data;
  1030. }
  1031. }
  1032. _this.status = statusCode;
  1033. _responseHeader.set(_this, header);
  1034. _triggerEvent.call(_this, 'loadstart');
  1035. _changeReadyState.call(_this, XMLHttpRequest.HEADERS_RECEIVED);
  1036. _changeReadyState.call(_this, XMLHttpRequest.LOADING);
  1037. _this.response = data;
  1038. if (data instanceof ArrayBuffer) {
  1039. _this.responseText = '';
  1040. var bytes = new Uint8Array(data);
  1041. var len = bytes.byteLength;
  1042. for (var i = 0; i < len; i++) {
  1043. _this.responseText += String.fromCharCode(bytes[i]);
  1044. }
  1045. } else {
  1046. _this.responseText = data;
  1047. }
  1048. _changeReadyState.call(_this, XMLHttpRequest.DONE);
  1049. _triggerEvent.call(_this, 'load');
  1050. _triggerEvent.call(_this, 'loadend');
  1051. },
  1052. fail: function fail(_ref2) {
  1053. var errMsg = _ref2.errMsg;
  1054. // TODO 规范错误
  1055. if (errMsg.indexOf('abort') !== -1) {
  1056. _triggerEvent.call(_this, 'abort');
  1057. } else {
  1058. _triggerEvent.call(_this, 'error', errMsg);
  1059. }
  1060. _triggerEvent.call(_this, 'loadend');
  1061. }
  1062. });
  1063. }
  1064. }
  1065. }, {
  1066. key: 'setRequestHeader',
  1067. value: function setRequestHeader(header, value) {
  1068. var myHeader = _requestHeader.get(this);
  1069. myHeader[header] = value;
  1070. _requestHeader.set(this, myHeader);
  1071. }
  1072. }]);
  1073. return XMLHttpRequest;
  1074. }();
  1075. XMLHttpRequest.UNSEND = 0;
  1076. XMLHttpRequest.OPENED = 1;
  1077. XMLHttpRequest.HEADERS_RECEIVED = 2;
  1078. XMLHttpRequest.LOADING = 3;
  1079. XMLHttpRequest.DONE = 4;
  1080. exports.default = XMLHttpRequest;
  1081. /***/ }),
  1082. /* 20 */
  1083. /***/ (function(module, exports, __webpack_require__) {
  1084. 'use strict';
  1085. Object.defineProperty(exports, "__esModule", {
  1086. value: true
  1087. });
  1088. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  1089. var _util = __webpack_require__(8);
  1090. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  1091. var _socketTask = new WeakMap();
  1092. var WebSocket = function () {
  1093. // TODO 更新 binaryType
  1094. // The connection is in the process of closing.
  1095. // The connection is not yet open.
  1096. function WebSocket(url) {
  1097. var _this = this;
  1098. var protocols = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
  1099. _classCallCheck(this, WebSocket);
  1100. this.binaryType = '';
  1101. this.bufferedAmount = 0;
  1102. this.extensions = '';
  1103. this.onclose = null;
  1104. this.onerror = null;
  1105. this.onmessage = null;
  1106. this.onopen = null;
  1107. this.protocol = '';
  1108. this.readyState = 3;
  1109. if ((0, _util.isSubContext)()) {
  1110. throw new Error('WebSocket is not supported in SubContext.');
  1111. }
  1112. if (typeof url !== 'string' || !/(^ws:\/\/)|(^wss:\/\/)/.test(url)) {
  1113. throw new TypeError('Failed to construct \'WebSocket\': The URL \'' + url + '\' is invalid');
  1114. }
  1115. this.url = url;
  1116. this.readyState = WebSocket.CONNECTING;
  1117. var socketTask = wx.connectSocket({
  1118. url: url,
  1119. protocols: Array.isArray(protocols) ? protocols : [protocols]
  1120. });
  1121. _socketTask.set(this, socketTask);
  1122. socketTask.onClose(function (res) {
  1123. _this.readyState = WebSocket.CLOSED;
  1124. if (typeof _this.onclose === 'function') {
  1125. _this.onclose(res);
  1126. }
  1127. });
  1128. socketTask.onMessage(function (res) {
  1129. if (typeof _this.onmessage === 'function') {
  1130. _this.onmessage(res);
  1131. }
  1132. });
  1133. socketTask.onOpen(function () {
  1134. _this.readyState = WebSocket.OPEN;
  1135. if (typeof _this.onopen === 'function') {
  1136. _this.onopen();
  1137. }
  1138. });
  1139. socketTask.onError(function (res) {
  1140. if (typeof _this.onerror === 'function') {
  1141. _this.onerror(new Error(res.errMsg));
  1142. }
  1143. });
  1144. return this;
  1145. } // TODO 小程序内目前获取不到,实际上需要根据服务器选择的 sub-protocol 返回
  1146. // TODO 更新 bufferedAmount
  1147. // The connection is closed or couldn't be opened.
  1148. // The connection is open and ready to communicate.
  1149. _createClass(WebSocket, [{
  1150. key: 'close',
  1151. value: function close(code, reason) {
  1152. this.readyState = WebSocket.CLOSING;
  1153. var socketTask = _socketTask.get(this);
  1154. socketTask.close({
  1155. code: code,
  1156. reason: reason
  1157. });
  1158. }
  1159. }, {
  1160. key: 'send',
  1161. value: function send(data) {
  1162. if (typeof data !== 'string' && !(data instanceof ArrayBuffer)) {
  1163. throw new TypeError('Failed to send message: The data ' + data + ' is invalid');
  1164. }
  1165. var socketTask = _socketTask.get(this);
  1166. socketTask.send({
  1167. data: data
  1168. });
  1169. }
  1170. }]);
  1171. return WebSocket;
  1172. }();
  1173. WebSocket.CONNECTING = 0;
  1174. WebSocket.OPEN = 1;
  1175. WebSocket.CLOSING = 2;
  1176. WebSocket.CLOSED = 3;
  1177. exports.default = WebSocket;
  1178. /***/ }),
  1179. /* 21 */
  1180. /***/ (function(module, exports, __webpack_require__) {
  1181. 'use strict';
  1182. Object.defineProperty(exports, "__esModule", {
  1183. value: true
  1184. });
  1185. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  1186. var _util = __webpack_require__(8);
  1187. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  1188. /*
  1189. * TODO 使用 wx.readFile 来封装 FileReader
  1190. */
  1191. var FileReader = function () {
  1192. function FileReader() {
  1193. _classCallCheck(this, FileReader);
  1194. }
  1195. _createClass(FileReader, [{
  1196. key: 'construct',
  1197. value: function construct() {
  1198. if ((0, _util.isSubContext)()) {
  1199. throw new Error('FileReader is not supported in SubContext.');
  1200. }
  1201. }
  1202. }]);
  1203. return FileReader;
  1204. }();
  1205. exports.default = FileReader;
  1206. /***/ }),
  1207. /* 22 */
  1208. /***/ (function(module, exports, __webpack_require__) {
  1209. 'use strict';
  1210. Object.defineProperty(exports, "__esModule", {
  1211. value: true
  1212. });
  1213. var _util = __webpack_require__(8);
  1214. var mainContext = {
  1215. get length() {
  1216. var _wx$getStorageInfoSyn = wx.getStorageInfoSync(),
  1217. keys = _wx$getStorageInfoSyn.keys;
  1218. return keys.length;
  1219. },
  1220. key: function key(n) {
  1221. var _wx$getStorageInfoSyn2 = wx.getStorageInfoSync(),
  1222. keys = _wx$getStorageInfoSyn2.keys;
  1223. return keys[n];
  1224. },
  1225. getItem: function getItem(key) {
  1226. return wx.getStorageSync(key);
  1227. },
  1228. setItem: function setItem(key, value) {
  1229. return wx.setStorageSync(key, value);
  1230. },
  1231. removeItem: function removeItem(key) {
  1232. wx.removeStorageSync(key);
  1233. },
  1234. clear: function clear() {
  1235. wx.clearStorageSync();
  1236. }
  1237. };
  1238. var memLocalStorage = {};
  1239. var subContext = {
  1240. get length() {
  1241. var keys = Object.keys(memLocalStorage);
  1242. return keys.length;
  1243. },
  1244. key: function key(n) {
  1245. var keys = Object.keys(memLocalStorage);
  1246. return keys[n];
  1247. },
  1248. getItem: function getItem(key) {
  1249. return memLocalStorage[key];
  1250. },
  1251. setItem: function setItem(key, value) {
  1252. memLocalStorage[key] = value;
  1253. },
  1254. removeItem: function removeItem(key) {
  1255. delete memLocalStorage[key];
  1256. },
  1257. clear: function clear() {
  1258. memLocalStorage = {};
  1259. }
  1260. };
  1261. var localStorage = (0, _util.isSubContext)() ? subContext : mainContext;
  1262. exports.default = localStorage;
  1263. /***/ }),
  1264. /* 23 */
  1265. /***/ (function(module, exports) {
  1266. 'use strict';
  1267. Object.defineProperty(exports, "__esModule", {
  1268. value: true
  1269. });
  1270. var location = {
  1271. href: 'game.js',
  1272. reload: function reload() {}
  1273. };
  1274. exports.default = location;
  1275. /***/ })
  1276. /******/ ]);