weapp-adapter.js 49 KB

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