weapp-adapter.js 51 KB

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