weapp-adapter.js 48 KB

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