weapp-adapter.js 51 KB

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