diff --git a/templates/alipay-mini-game/game.ejs b/templates/alipay-mini-game/game.ejs new file mode 100644 index 0000000000..6b1cf42d76 --- /dev/null +++ b/templates/alipay-mini-game/game.ejs @@ -0,0 +1,34 @@ +require('./web-adapter'); + +<% if(polyfillsBundleFile) { %> +// Polyfills bundle. +require("<%= polyfillsBundleFile %>"); +<% } %> + +// SystemJS support. +window.self = window; +require("<%= systemJsBundleFile %>"); + +const importMap = require("<%= importMapFile%>").default; +System.warmup({ + importMap, + importMapUrl: '<%= importMapFile%>', + defaultHandler: (urlNoSchema) => { + require('.' + urlNoSchema); + }, +}); + +System.import('<%= applicationJs %>').then(({ Application }) => { + return new Application(); +}).then((application) => { + return onApplicationCreated(application); +}).catch((err) => { + console.error(err); +}); + +function onApplicationCreated(application) { + return System.import('cc').then((cc) => { + require('./engine-adapter'); + return application.init(cc); + }).then(() => application.start()); +} diff --git a/templates/alipay-mini-game/game.json b/templates/alipay-mini-game/game.json new file mode 100644 index 0000000000..36f140aeb1 --- /dev/null +++ b/templates/alipay-mini-game/game.json @@ -0,0 +1,10 @@ +{ + "screenOrientation": "landscape", + "networkTimeout": { + "request": 5000, + "connectSocket": 5000, + "download": 500000, + "upload": 5000 + }, + "showStatusBar": false +} diff --git a/templates/baidu-mini-game/game.ejs b/templates/baidu-mini-game/game.ejs new file mode 100644 index 0000000000..ca88c89a6d --- /dev/null +++ b/templates/baidu-mini-game/game.ejs @@ -0,0 +1,66 @@ +globalThis.__baiduRequire = require; // FIX: require implementation in browserify conflicts with baidu webpack +require('./web-adapter'); + +<% if(polyfillsBundleFile) { %> +// Polyfills bundle. +require("<%= polyfillsBundleFile %>"); +<% } %> + +// SystemJS support. +require("<%= systemJsBundleFile %>"); +// 这句只有百度需要,因为百度的 webpack 提供了假的 System +const System = globalThis.System; + +// Adapt for IOS, swap if opposite +if (canvas) { + var _w = canvas.width; + var _h = canvas.height; + if (screen.width < screen.height) { + if (canvas.width > canvas.height) { + _w = canvas.height; + _h = canvas.width; + } + } else { + if (canvas.width < canvas.height) { + _w = canvas.height; + _h = canvas.width; + } + } + canvas.width = _w; + canvas.height = _h; +} + +// Adjust initial canvas size +if (canvas && window.devicePixelRatio >= 2) {canvas.width *= 2; canvas.height *= 2;} + +const importMap = require("<%= importMapFile%>").default; +System.warmup({ + importMap, + importMapUrl: '<%= importMapFile%>', + defaultHandler: (urlNoSchema) => { + require('.' + urlNoSchema); + }, +}); + +System.import('<%= applicationJs %>').then(({ Application }) => { + return new Application(); +}).then((application) => { + return onApplicationCreated(application); +}).catch((err) => { + console.error(err); +}); + +function onApplicationCreated(application) { + return System.import('cc').then((cc) => { + require('./engine-adapter'); + + // post system info to open data context + swan.getOpenDataContext().postMessage({ + type: 'engine', + event: 'systemInfo', + systemInfo: swan.getSystemInfoSync(), + }); + + return application.init(cc); + }).then(() => application.start()); +} diff --git a/templates/baidu-mini-game/game.json b/templates/baidu-mini-game/game.json new file mode 100644 index 0000000000..a54684d76d --- /dev/null +++ b/templates/baidu-mini-game/game.json @@ -0,0 +1,11 @@ +{ + "deviceOrientation": "landscape", + "openDataContext": "", + "networkTimeout": + { + "request": 5000, + "connectSocket": 5000, + "uploadFile": 5000, + "downloadFile": 500000 + } +} \ No newline at end of file diff --git a/templates/baidu-mini-game/project.swan.json b/templates/baidu-mini-game/project.swan.json new file mode 100644 index 0000000000..423d9923b8 --- /dev/null +++ b/templates/baidu-mini-game/project.swan.json @@ -0,0 +1,14 @@ +{ + "appid": "", + "compileType": "game", + "libVersion": "1.0.0", + "bundle": + { + "exclude": ["node_moudules"], + "entry": "game.js", + "compilers": [ + { + "type": "babel" + }] + } +} \ No newline at end of file diff --git a/templates/bytedance-mini-game/game.ejs b/templates/bytedance-mini-game/game.ejs new file mode 100644 index 0000000000..db3c39e972 --- /dev/null +++ b/templates/bytedance-mini-game/game.ejs @@ -0,0 +1,105 @@ +<% if (isUsePhysX) { %> +const systemInfo = tt.getSystemInfoSync(); +// a hack way to load physics provide by bytedance +if (tt.getPhysx) { + tt.getPhysx({ + success (physx) { + if (!physx) { + console.error('can not use native PhysX'); + } else { + console.info('physics plugin load success, version=' + physx.getVersion()); + GameGlobal.nativePhysX = physx; + } + loadCC(); + }, + fail () { + loadCC(); + } + }); +} else if (systemInfo.platform === 'android' && tt.getLoader && tt.getLoader()) { + const appid = "<%= appid %>"; + const loader = tt.getLoader().loader; + loader.load('physics', appid, "token", message => { + if (message) { + console.error('[tt.loader]:' + message); + } else { + console.info('[tt.loader]: physics plugin load success, version=' + tt.getPhy().getVersion()); + GameGlobal.nativePhysX = tt.getPhy(); + } + loadCC(); + }) +} else { + loadCC(); +} +<% } %> + +<% if (!isUsePhysX) { %> +loadCC(); +<% } %> + +function loadCC() { + require('./web-adapter'); + +<% if(polyfillsBundleFile) { %> + // Polyfills bundle. + require("<%= polyfillsBundleFile %>"); +<% } %> + + // SystemJS support. + require("<%= systemJsBundleFile %>"); + + // Adapt for IOS, swap if opposite + if (canvas){ + var _w = canvas.width; + var _h = canvas.height; + if (screen.width < screen.height) { + if (canvas.width > canvas.height) { + _w = canvas.height; + _h = canvas.width; + } + } else { + if (canvas.width < canvas.height) { + _w = canvas.height; + _h = canvas.width; + } + } + canvas.width = _w; + canvas.height = _h; + } + + // Adjust initial canvas size + if (canvas && window.devicePixelRatio >= 2) {canvas.width *= 2; canvas.height *= 2;} + + const importMap = require("<%= importMapFile%>").default; + System.warmup({ + importMap, + importMapUrl: '<%= importMapFile%>', + defaultHandler: (urlNoSchema) => { + require('.' + urlNoSchema); + }, + handlers: { + 'plugin:': (urlNoSchema) => { + typeof requirePlugin === 'function' ? requirePlugin(urlNoSchema) : require(urlNoSchema); + }, + 'project:': (urlNoSchema) => { + require(urlNoSchema); + }, + }, + }); + + System.import('<%= applicationJs %>').then(({ Application }) => { + return new Application(); + }).then((application) => { + return onApplicationCreated(application); + }).catch((err) => { + console.error(err); + }); + + function onApplicationCreated(application) { + return System.import('cc').then((cc) => { + require('./engine-adapter'); + return application.init(cc); + }).then(() => { return application.start(); }); + } + +} diff --git a/templates/bytedance-mini-game/game.json b/templates/bytedance-mini-game/game.json new file mode 100644 index 0000000000..bbc582a9e6 --- /dev/null +++ b/templates/bytedance-mini-game/game.json @@ -0,0 +1,11 @@ +{ + "deviceOrientation": "portrait", + "showStatusBar": false, + "openDataContext": "", + "networkTimeout": { + "request": 5000, + "connectSocket": 5000, + "uploadFile": 5000, + "downloadFile": 500000 + } +} \ No newline at end of file diff --git a/templates/bytedance-mini-game/project.config.json b/templates/bytedance-mini-game/project.config.json new file mode 100644 index 0000000000..b8fdb18c37 --- /dev/null +++ b/templates/bytedance-mini-game/project.config.json @@ -0,0 +1,11 @@ +{ + "setting": { + "urlCheck": true, + "es6": false, + "postcss": true, + "minified": true, + "newFeature": true + }, + "appid": "testappId", + "projectname": "" +} \ No newline at end of file diff --git a/templates/fb-instant-games/fbapp-config.json b/templates/fb-instant-games/fbapp-config.json new file mode 100644 index 0000000000..913675bf85 --- /dev/null +++ b/templates/fb-instant-games/fbapp-config.json @@ -0,0 +1,8 @@ +{ + "instant_games": { + "orientation": "PORTRAIT", + "override_web_orientation": "PORTRAIT", + "platform_version": "RICH_GAMEPLAY", + "navigation_menu_version": "NAV_FLOATING" + } +} \ No newline at end of file diff --git a/templates/fb-instant-games/index-plugin.ejs b/templates/fb-instant-games/index-plugin.ejs new file mode 100644 index 0000000000..464bfaf88b --- /dev/null +++ b/templates/fb-instant-games/index-plugin.ejs @@ -0,0 +1,24 @@ +<% if (webDebuggerSrc) { %> + + +<% } %> + + + + + + + + + + + + + + + diff --git a/templates/fb-instant-games/index.ejs b/templates/fb-instant-games/index.ejs new file mode 100644 index 0000000000..3e278ac692 --- /dev/null +++ b/templates/fb-instant-games/index.ejs @@ -0,0 +1,48 @@ + + + + + + Cocos Creator | <%= projectName %> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +
+
+ <%- include(cocosTemplate, {}) %> + + diff --git a/templates/fb-instant-games/index.js.ejs b/templates/fb-instant-games/index.js.ejs new file mode 100644 index 0000000000..93d33fd38a --- /dev/null +++ b/templates/fb-instant-games/index.js.ejs @@ -0,0 +1,29 @@ +import { Application } from '<%= applicationJS %>'; + +const canvas = document.getElementById('GameCanvas'); +const $p = canvas.parentElement; +const bcr = $p.getBoundingClientRect(); +canvas.width = bcr.width; +canvas.height = bcr.height; + +function topLevelImport (url) { + return System.import(url); +} + +const application = new Application(); + +FBInstant.initializeAsync().then(function () { + FBInstant.setLoadingProgress(10); + return topLevelImport('cc'); +}).then(function (engine) { + FBInstant.setLoadingProgress(50); + return application.init(engine); +}).then(function () { + FBInstant.setLoadingProgress(99); + return application.start(); +}).then(function () { + FBInstant.setLoadingProgress(100); + return FBInstant.startGameAsync(); +}).catch((err) => { + console.error(err); +}); diff --git a/templates/fb-instant-games/style.css b/templates/fb-instant-games/style.css new file mode 100644 index 0000000000..4e69d6bd2b --- /dev/null +++ b/templates/fb-instant-games/style.css @@ -0,0 +1,61 @@ +html { + -ms-touch-action: none; +} + +body, canvas, div { + display: block; + outline: none; + -webkit-tap-highlight-color: rgba(0, 0, 0, 0); + + user-select: none; + -moz-user-select: none; + -webkit-user-select: none; + -ms-user-select: none; + -khtml-user-select: none; + -webkit-tap-highlight-color: rgba(0, 0, 0, 0); +} + +/* Remove spin of input type number */ +input::-webkit-outer-spin-button, +input::-webkit-inner-spin-button { + /* display: none; <- Crashes Chrome on hover */ + -webkit-appearance: none; + margin: 0; /* <-- Apparently some margin are still there even though it's hidden */ +} + +body { + position: absolute; + top: 0; + left: 0; + width: 100%; + height: 100%; + padding: 0; + border: 0; + margin: 0; + + cursor: default; + color: #888; + background-color: #333; + + text-align: center; + font-family: Helvetica, Verdana, Arial, sans-serif; + + display: flex; + flex-direction: column; +} + +canvas { + background-color: rgba(0, 0, 0, 0); +} + +#GameDiv, #Cocos3dGameContainer, #GameCanvas { + width: 100%; + height: 100%; +} + +:root { + --safe-top: env(safe-area-inset-top); + --safe-right: env(safe-area-inset-right); + --safe-bottom: env(safe-area-inset-bottom); + --safe-left: env(safe-area-inset-left); +} diff --git a/templates/fb-instant-games/vconsole.min.js b/templates/fb-instant-games/vconsole.min.js new file mode 100644 index 0000000000..829c835fef --- /dev/null +++ b/templates/fb-instant-games/vconsole.min.js @@ -0,0 +1,10 @@ +/*! + * vConsole v3.3.2 (https://github.com/Tencent/vConsole) + * + * Tencent is pleased to support the open source community by making vConsole available. + * Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. + * Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at + * http://opensource.org/licenses/MIT + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. + */ +!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("VConsole",[],t):"object"==typeof exports?exports.VConsole=t():e.VConsole=t()}(window,function(){return function(e){var t={};function o(n){if(t[n])return t[n].exports;var r=t[n]={i:n,l:!1,exports:{}};return e[n].call(r.exports,r,r.exports,o),r.l=!0,r.exports}return o.m=e,o.c=t,o.d=function(e,t,n){o.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},o.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},o.t=function(e,t){if(1&t&&(e=o(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(o.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)o.d(n,r,function(t){return e[t]}.bind(null,r));return n},o.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return o.d(t,"a",t),t},o.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},o.p="",o(o.s=6)}([function(e,t,o){var n,r,i;r=[t],void 0===(i="function"==typeof(n=function(e){"use strict";function t(e){return(t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function o(e){return"[object Number]"==Object.prototype.toString.call(e)}function n(e){return"[object String]"==Object.prototype.toString.call(e)}function r(e){return"[object Array]"==Object.prototype.toString.call(e)}function i(e){return"[object Boolean]"==Object.prototype.toString.call(e)}function a(e){return void 0===e}function l(e){return null===e}function c(e){return"[object Symbol]"==Object.prototype.toString.call(e)}function s(e){return!("[object Object]"!=Object.prototype.toString.call(e)&&(o(e)||n(e)||i(e)||r(e)||l(e)||d(e)||a(e)||c(e)))}function d(e){return"[object Function]"==Object.prototype.toString.call(e)}function u(e){var t=Object.prototype.toString.call(e);return"[object global]"==t||"[object Window]"==t||"[object DOMWindow]"==t}function f(e){if(!s(e)&&!r(e))return[];if(r(e)){var t=[];return e.forEach(function(e,o){t.push(o)}),t}return Object.getOwnPropertyNames(e).sort()}Object.defineProperty(e,"__esModule",{value:!0}),e.getDate=function(e){var t=e>0?new Date(e):new Date,o=t.getDate()<10?"0"+t.getDate():t.getDate(),n=t.getMonth()<9?"0"+(t.getMonth()+1):t.getMonth()+1,r=t.getFullYear(),i=t.getHours()<10?"0"+t.getHours():t.getHours(),a=t.getMinutes()<10?"0"+t.getMinutes():t.getMinutes(),l=t.getSeconds()<10?"0"+t.getSeconds():t.getSeconds(),c=t.getMilliseconds()<10?"0"+t.getMilliseconds():t.getMilliseconds();return c<100&&(c="0"+c),{time:+t,year:r,month:n,day:o,hour:i,minute:a,second:l,millisecond:c}},e.isNumber=o,e.isString=n,e.isArray=r,e.isBoolean=i,e.isUndefined=a,e.isNull=l,e.isSymbol=c,e.isObject=s,e.isFunction=d,e.isElement=function(e){return"object"===("undefined"==typeof HTMLElement?"undefined":t(HTMLElement))?e instanceof HTMLElement:e&&"object"===t(e)&&null!==e&&1===e.nodeType&&"string"==typeof e.nodeName},e.isWindow=u,e.isPlainObject=function(e){var o,n=Object.prototype.hasOwnProperty;if(!e||"object"!==t(e)||e.nodeType||u(e))return!1;try{if(e.constructor&&!n.call(e,"constructor")&&!n.call(e.constructor.prototype,"isPrototypeOf"))return!1}catch(e){return!1}for(o in e);return void 0===o||n.call(e,o)},e.htmlEncode=function(e){return document.createElement("a").appendChild(document.createTextNode(e)).parentNode.innerHTML},e.JSONStringify=function(e){if(!s(e)&&!r(e))return JSON.stringify(e);var t="{",o="}";r(e)&&(t="[",o="]");for(var n=t,i=f(e),a=0;a-1||(i.push(t),e[o].className=i.join(" "))}}},removeClass:function(e,t){if(e){(0,n.isArray)(e)||(e=[e]);for(var o=0;o1&&void 0!==arguments[1]?arguments[1]:"newPlugin";!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.id=t,this.name=o,this.isReady=!1,this.eventList={}}return t=e,(o=[{key:"on",value:function(e,t){return this.eventList[e]=t,this}},{key:"trigger",value:function(e,t){if("function"==typeof this.eventList[e])this.eventList[e].call(this,t);else{var o="on"+e.charAt(0).toUpperCase()+e.slice(1);"function"==typeof this[o]&&this[o].call(this,t)}return this}},{key:"id",get:function(){return this._id},set:function(e){if(!e)throw"Plugin ID cannot be empty";this._id=e.toLowerCase()}},{key:"name",get:function(){return this._name},set:function(e){if(!e)throw"Plugin name cannot be empty";this._name=e}},{key:"vConsole",get:function(){return this._vConsole||void 0},set:function(e){if(!e)throw"vConsole cannot be empty";this._vConsole=e}}])&&n(t.prototype,o),r&&n(t,r),e;var t,o,r}();o.default=r,e.exports=t.default})?n.apply(t,r):n)||(e.exports=i)},function(e,t,o){"use strict";e.exports=function(e){var t=[];return t.toString=function(){return this.map(function(t){var o=function(e,t){var o=e[1]||"",n=e[3];if(!n)return o;if(t&&"function"==typeof btoa){var r=(a=n,"/*# sourceMappingURL=data:application/json;charset=utf-8;base64,"+btoa(unescape(encodeURIComponent(JSON.stringify(a))))+" */"),i=n.sources.map(function(e){return"/*# sourceURL="+n.sourceRoot+e+" */"});return[o].concat(i).concat([r]).join("\n")}var a;return[o].join("\n")}(t,e);return t[2]?"@media "+t[2]+"{"+o+"}":o}).join("")},t.i=function(e,o){"string"==typeof e&&(e=[[null,e,""]]);for(var n={},r=0;r=0&&d.splice(t,1)}function h(e){var t=document.createElement("style");if(void 0===e.attrs.type&&(e.attrs.type="text/css"),void 0===e.attrs.nonce){var n=function(){0;return o.nc}();n&&(e.attrs.nonce=n)}return g(t,e.attrs),p(e,t),t}function g(e,t){Object.keys(t).forEach(function(o){e.setAttribute(o,t[o])})}function m(e,t){var o,n,r,i;if(t.transform&&e.css){if(!(i="function"==typeof t.transform?t.transform(e.css):t.transform.default(e.css)))return function(){};e.css=i}if(t.singleton){var a=s++;o=c||(c=h(t)),n=w.bind(null,o,a,!1),r=w.bind(null,o,a,!0)}else e.sourceMap&&"function"==typeof URL&&"function"==typeof URL.createObjectURL&&"function"==typeof URL.revokeObjectURL&&"function"==typeof Blob&&"function"==typeof btoa?(o=function(e){var t=document.createElement("link");return void 0===e.attrs.type&&(e.attrs.type="text/css"),e.attrs.rel="stylesheet",g(t,e.attrs),p(e,t),t}(t),n=function(e,t,o){var n=o.css,r=o.sourceMap,i=void 0===t.convertToAbsoluteUrls&&r;(t.convertToAbsoluteUrls||i)&&(n=u(n));r&&(n+="\n/*# sourceMappingURL=data:application/json;base64,"+btoa(unescape(encodeURIComponent(JSON.stringify(r))))+" */");var a=new Blob([n],{type:"text/css"}),l=e.href;e.href=URL.createObjectURL(a),l&&URL.revokeObjectURL(l)}.bind(null,o,t),r=function(){b(o),o.href&&URL.revokeObjectURL(o.href)}):(o=h(t),n=function(e,t){var o=t.css,n=t.media;n&&e.setAttribute("media",n);if(e.styleSheet)e.styleSheet.cssText=o;else{for(;e.firstChild;)e.removeChild(e.firstChild);e.appendChild(document.createTextNode(o))}}.bind(null,o),r=function(){b(o)});return n(e),function(t){if(t){if(t.css===e.css&&t.media===e.media&&t.sourceMap===e.sourceMap)return;n(e=t)}else r()}}e.exports=function(e,t){if("undefined"!=typeof DEBUG&&DEBUG&&"object"!=typeof document)throw new Error("The style-loader cannot be used in a non-browser environment");(t=t||{}).attrs="object"==typeof t.attrs?t.attrs:{},t.singleton||"boolean"==typeof t.singleton||(t.singleton=a()),t.insertInto||(t.insertInto="head"),t.insertAt||(t.insertAt="bottom");var o=v(e,t);return f(o,t),function(e){for(var n=[],r=0;r=o.scrollHeight?e.isInBottom=!0:e.isInBottom=!1)});for(var n=0;n-1&&h.splice(e,1)}},{key:"onShow",value:function(){this.isShow=!0,1==this.isInBottom&&this.autoScrollToBottom()}},{key:"onHide",value:function(){this.isShow=!1}},{key:"onShowConsole",value:function(){1==this.isInBottom&&this.autoScrollToBottom()}},{key:"onUpdateOption",value:function(){this.vConsole.option.maxLogNumber!=this.maxLogNumber&&(this.updateMaxLogNumber(),this.limitMaxLogs())}},{key:"updateMaxLogNumber",value:function(){this.maxLogNumber=this.vConsole.option.maxLogNumber||b,this.maxLogNumber=Math.max(1,this.maxLogNumber)}},{key:"limitMaxLogs",value:function(){if(this.isReady)for(;this.logNumber>this.maxLogNumber;){var e=r.default.one(".vc-item",this.$tabbox);if(!e)break;e.parentNode.removeChild(e),this.logNumber--}}},{key:"showLogType",value:function(e){var t=r.default.one(".vc-log",this.$tabbox);r.default.removeClass(t,"vc-log-partly-log"),r.default.removeClass(t,"vc-log-partly-info"),r.default.removeClass(t,"vc-log-partly-warn"),r.default.removeClass(t,"vc-log-partly-error"),"all"==e?r.default.removeClass(t,"vc-log-partly"):(r.default.addClass(t,"vc-log-partly"),r.default.addClass(t,"vc-log-partly-"+e))}},{key:"autoScrollToBottom",value:function(){this.vConsole.option.disableLogScrolling||this.scrollToBottom()}},{key:"scrollToBottom",value:function(){var e=r.default.one(".vc-content");e&&(e.scrollTop=e.scrollHeight-e.offsetHeight)}},{key:"mockConsole",value:function(){var e=this,t=this,o=["log","info","warn","debug","error"];window.console?(o.map(function(e){t.console[e]=window.console[e]}),t.console.time=window.console.time,t.console.timeEnd=window.console.timeEnd,t.console.clear=window.console.clear):window.console={},o.map(function(t){window.console[t]=function(){for(var o=arguments.length,n=new Array(o),r=0;r0&&(r=a[1].toLowerCase(),i=h.indexOf(r)>-1)}if(r===this.id||!0!==i&&"default"===this.id)if(e._id||(e._id="__vc_"+Math.random().toString(36).substring(2,8)),e.date||(e.date=+new Date),this.isReady){n.isString(t[0])&&i&&(t[0]=t[0].replace(o,""),""===t[0]&&t.shift());for(var l={_id:e._id,logType:e.logType,logText:[],hasContent:!!e.content,count:1},c=0;c "+t[l].toString()+"":n.isObject(t[l])||n.isArray(t[l])?this.getFoldedLine(t[l]):" "+n.htmlEncode(t[l]).replace(/\n/g,"
")+"
"}catch(e){c=" ["+d(t[l])+"]"}c&&("string"==typeof c?i.insertAdjacentHTML("beforeend",c):i.insertAdjacentElement("beforeend",c))}n.isObject(e.content)&&i.insertAdjacentElement("beforeend",e.content),r.default.one(".vc-log",this.$tabbox).insertAdjacentElement("beforeend",o),this.logNumber++,this.limitMaxLogs()}},{key:"getFoldedLine",value:function(e,t){var o=this;if(!t){var i=n.JSONStringify(e),a=i.substr(0,36);t=n.getObjName(e),i.length>36&&(a+="..."),t+=" "+a}var s=r.default.render(l.default,{outer:t,lineType:"obj"});return r.default.bind(r.default.one(".vc-fold-outer",s),"click",function(t){t.preventDefault(),t.stopPropagation(),r.default.hasClass(s,"vc-toggle")?(r.default.removeClass(s,"vc-toggle"),r.default.removeClass(r.default.one(".vc-fold-inner",s),"vc-toggle"),r.default.removeClass(r.default.one(".vc-fold-outer",s),"vc-toggle")):(r.default.addClass(s,"vc-toggle"),r.default.addClass(r.default.one(".vc-fold-inner",s),"vc-toggle"),r.default.addClass(r.default.one(".vc-fold-outer",s),"vc-toggle"));var i=r.default.one(".vc-fold-inner",s);return setTimeout(function(){if(0==i.children.length&&e){for(var t=n.getObjAllKeys(e),a=0;adocument.documentElement.offsetWidth&&(o=document.documentElement.offsetWidth-t.offsetWidth),n+t.offsetHeight>document.documentElement.offsetHeight&&(n=document.documentElement.offsetHeight-t.offsetHeight),o<0&&(o=0),n<0&&(n=0),this.switchPos.x=o,this.switchPos.y=n,i.default.one(".vc-switch").style.right=o+"px",i.default.one(".vc-switch").style.bottom=n+"px");var a=window.devicePixelRatio||1,c=document.querySelector('[name="viewport"]');if(c&&c.content){var s=c.content.match(/initial\-scale\=\d+(\.\d+)?/),d=s?parseFloat(s[0].split("=")[1]):1;d<1&&(this.$dom.style.fontSize=13*a+"px")}i.default.one(".vc-mask",this.$dom).style.display="none"}},{key:"_mockTap",value:function(){var e,t,o,n=!1,r=null;this.$dom.addEventListener("touchstart",function(n){if(void 0===e){var i=n.targetTouches[0];t=i.pageX,o=i.pageY,e=n.timeStamp,r=n.target.nodeType===Node.TEXT_NODE?n.target.parentNode:n.target}},!1),this.$dom.addEventListener("touchmove",function(e){var r=e.changedTouches[0];(Math.abs(r.pageX-t)>10||Math.abs(r.pageY-o)>10)&&(n=!0)}),this.$dom.addEventListener("touchend",function(t){if(!1===n&&t.timeStamp-e<700&&null!=r){var o=r.tagName.toLowerCase(),i=!1;switch(o){case"textarea":i=!0;break;case"input":switch(r.type){case"button":case"checkbox":case"file":case"image":case"radio":case"submit":i=!1;break;default:i=!r.disabled&&!r.readOnly}}i?r.focus():t.preventDefault();var a=t.changedTouches[0],l=document.createEvent("MouseEvents");l.initMouseEvent("click",!0,!0,window,1,a.screenX,a.screenY,a.clientX,a.clientY,!1,!1,!1,!1,0,null),l.forwardedTouchEvent=!0,l.initEvent("click",!0,!0),r.dispatchEvent(l)}e=void 0,n=!1,r=null},!1)}},{key:"_bindEvent",value:function(){var e=this,t=i.default.one(".vc-switch",e.$dom);i.default.bind(t,"touchstart",function(t){e.switchPos.startX=t.touches[0].pageX,e.switchPos.startY=t.touches[0].pageY}),i.default.bind(t,"touchend",function(t){e.switchPos.x=e.switchPos.endX,e.switchPos.y=e.switchPos.endY,e.switchPos.startX=0,e.switchPos.startY=0,r.setStorage("switch_x",e.switchPos.x),r.setStorage("switch_y",e.switchPos.y)}),i.default.bind(t,"touchmove",function(o){if(o.touches.length>0){var n=o.touches[0].pageX-e.switchPos.startX,r=o.touches[0].pageY-e.switchPos.startY,i=e.switchPos.x-n,a=e.switchPos.y-r;i+t.offsetWidth>document.documentElement.offsetWidth&&(i=document.documentElement.offsetWidth-t.offsetWidth),a+t.offsetHeight>document.documentElement.offsetHeight&&(a=document.documentElement.offsetHeight-t.offsetHeight),i<0&&(i=0),a<0&&(a=0),t.style.right=i+"px",t.style.bottom=a+"px",e.switchPos.endX=i,e.switchPos.endY=a,o.preventDefault()}}),i.default.bind(i.default.one(".vc-switch",e.$dom),"click",function(){e.show()}),i.default.bind(i.default.one(".vc-hide",e.$dom),"click",function(){e.hide()}),i.default.bind(i.default.one(".vc-mask",e.$dom),"click",function(t){if(t.target!=i.default.one(".vc-mask"))return!1;e.hide()}),i.default.delegate(i.default.one(".vc-tabbar",e.$dom),"click",".vc-tab",function(t){var o=this.dataset.tab;o!=e.activedTab&&e.showTab(o)}),i.default.bind(i.default.one(".vc-panel",e.$dom),"transitionend webkitTransitionEnd oTransitionEnd otransitionend",function(t){if(t.target!=i.default.one(".vc-panel"))return!1;i.default.hasClass(e.$dom,"vc-toggle")||(t.target.style.display="none")});var o=i.default.one(".vc-content",e.$dom),n=!1;i.default.bind(o,"touchstart",function(e){var t=o.scrollTop,r=o.scrollHeight,a=t+o.offsetHeight;0===t?(o.scrollTop=1,0===o.scrollTop&&(i.default.hasClass(e.target,"vc-cmd-input")||(n=!0))):a===r&&(o.scrollTop=t-1,o.scrollTop===t&&(i.default.hasClass(e.target,"vc-cmd-input")||(n=!0)))}),i.default.bind(o,"touchmove",function(e){n&&e.preventDefault()}),i.default.bind(o,"touchend",function(e){n=!1})}},{key:"_autoRun",value:function(){for(var e in this.isInited=!0,this.pluginList)this._initPlugin(this.pluginList[e]);this.tabList.length>0&&this.showTab(this.tabList[0]),this.triggerEvent("ready")}},{key:"triggerEvent",value:function(e,t){e="on"+e.charAt(0).toUpperCase()+e.slice(1),r.isFunction(this.option[e])&&this.option[e].apply(this,t)}},{key:"_initPlugin",value:function(e){var t=this;e.vConsole=this,e.trigger("init"),e.trigger("renderTab",function(o){t.tabList.push(e.id);var n=i.default.render(c.default,{id:e.id,name:e.name});i.default.one(".vc-tabbar",t.$dom).insertAdjacentElement("beforeend",n);var a=i.default.render(s.default,{id:e.id});o&&(r.isString(o)?a.innerHTML+=o:r.isFunction(o.appendTo)?o.appendTo(a):r.isElement(o)&&a.insertAdjacentElement("beforeend",o)),i.default.one(".vc-content",t.$dom).insertAdjacentElement("beforeend",a)}),e.trigger("addTopBar",function(o){if(o)for(var n=i.default.one(".vc-topbar",t.$dom),a=function(t){var a=o[t],l=i.default.render(d.default,{name:a.name||"Undefined",className:a.className||"",pluginID:e.id});if(a.data)for(var c in a.data)l.dataset[c]=a.data[c];r.isFunction(a.onClick)&&i.default.bind(l,"click",function(t){var o=a.onClick.call(l);!1===o||(i.default.removeClass(i.default.all(".vc-topbar-"+e.id),"vc-actived"),i.default.addClass(l,"vc-actived"))}),n.insertAdjacentElement("beforeend",l)},l=0;l-1&&this.tabList.splice(s,1);try{delete this.pluginList[e]}catch(t){this.pluginList[e]=void 0}return this.activedTab==e&&this.tabList.length>0&&this.showTab(this.tabList[0]),!0}},{key:"show",value:function(){if(this.isInited){var e=this,t=i.default.one(".vc-panel",this.$dom);t.style.display="block",setTimeout(function(){i.default.addClass(e.$dom,"vc-toggle"),e._triggerPluginsEvent("showConsole");var t=i.default.one(".vc-mask",e.$dom);t.style.display="block"},10)}}},{key:"hide",value:function(){if(this.isInited){i.default.removeClass(this.$dom,"vc-toggle"),this._triggerPluginsEvent("hideConsole");var e=i.default.one(".vc-mask",this.$dom),t=i.default.one(".vc-panel",this.$dom);i.default.bind(e,"transitionend",function(o){e.style.display="none",t.style.display="none"})}}},{key:"showSwitch",value:function(){if(this.isInited){var e=i.default.one(".vc-switch",this.$dom);e.style.display="block"}}},{key:"hideSwitch",value:function(){if(this.isInited){var e=i.default.one(".vc-switch",this.$dom);e.style.display="none"}}},{key:"showTab",value:function(e){if(this.isInited){var t=i.default.one("#__vc_log_"+e);i.default.removeClass(i.default.all(".vc-tab",this.$dom),"vc-actived"),i.default.addClass(i.default.one("#__vc_tab_"+e),"vc-actived"),i.default.removeClass(i.default.all(".vc-logbox",this.$dom),"vc-actived"),i.default.addClass(t,"vc-actived");var o=i.default.all(".vc-topbar-"+e,this.$dom);i.default.removeClass(i.default.all(".vc-toptab",this.$dom),"vc-toggle"),i.default.addClass(o,"vc-toggle"),o.length>0?i.default.addClass(i.default.one(".vc-content",this.$dom),"vc-has-topbar"):i.default.removeClass(i.default.one(".vc-content",this.$dom),"vc-has-topbar"),i.default.removeClass(i.default.all(".vc-tool",this.$dom),"vc-toggle"),i.default.addClass(i.default.all(".vc-tool-"+e,this.$dom),"vc-toggle"),this.activedTab&&this._triggerPluginEvent(this.activedTab,"hide"),this.activedTab=e,this._triggerPluginEvent(this.activedTab,"show")}}},{key:"setOption",value:function(e,t){if(r.isString(e))this.option[e]=t,this._triggerPluginsEvent("updateOption");else if(r.isObject(e)){for(var o in e)this.option[o]=e[o];this._triggerPluginsEvent("updateOption")}else console.debug("The first parameter of vConsole.setOption() must be a string or an object.")}},{key:"destroy",value:function(){if(this.isInited){for(var e=Object.keys(this.pluginList),t=e.length-1;t>=0;t--)this.removePlugin(e[t]);this.$dom.parentNode.removeChild(this.$dom),this.isInited=!1}}}])&&m(t.prototype,o),a&&m(t,a),e;var t,o,a}();o.default=_,e.exports=t.default})?n.apply(t,r):n)||(e.exports=i)},function(e){e.exports={name:"vconsole",version:"3.3.2",description:"A lightweight, extendable front-end developer tool for mobile web page.",homepage:"https://github.com/Tencent/vConsole",main:"dist/vconsole.min.js",typings:"./index.d.ts",scripts:{test:"mocha",dist:"webpack"},keywords:["console","debug","mobile"],repository:{type:"git",url:"git+https://github.com/Tencent/vConsole.git"},dependencies:{},devDependencies:{"@babel/core":"^7.2.2","@babel/plugin-proposal-class-properties":"^7.3.0","@babel/plugin-proposal-export-namespace-from":"^7.2.0","@babel/plugin-proposal-object-rest-spread":"^7.3.1","@babel/preset-env":"^7.3.1","babel-loader":"^8.0.4","babel-plugin-add-module-exports":"^1.0.0",chai:"^4.2.0","copy-webpack-plugin":"^5.0.3","css-loader":"^2.1.0","html-loader":"^0.5.5",jsdom:"^13.2.0","json-loader":"^0.5.7",less:"^3.9.0","less-loader":"^4.1.0",mocha:"^5.2.0","style-loader":"^0.23.1",webpack:"^4.29.0","webpack-cli":"^3.2.1"},author:"Tencent",license:"MIT"}},function(e,t,o){var n,r,i;r=[t],void 0===(i="function"==typeof(n=function(o){"use strict";Object.defineProperty(o,"__esModule",{value:!0}),o.default=function(e,t,o){var n=/\{\{([^\}]+)\}\}/g,r="",i="",a=0,l=[],c=function(e,t){""!==e&&(t?e.match(/^ ?else/g)?r+="} "+e+" {\n":e.match(/\/(if|for|switch)/g)?r+="}\n":e.match(/^ ?if|for|switch/g)?r+=e+" {\n":e.match(/^ ?(break|continue) ?$/g)?r+=e+";\n":e.match(/^ ?(case|default)/g)?r+=e+":\n":r+="arr.push("+e+");\n":r+='arr.push("'+e.replace(/"/g,'\\"')+'");\n')};for(window.__mito_data=t,window.__mito_code="",window.__mito_result="",e=(e=e.replace(/(\{\{ ?switch(.+?)\}\})[\r\n\t ]+\{\{/g,"$1{{")).replace(/^[\r\n]/,"").replace(/\n/g,"\\\n").replace(/\r/g,"\\\r"),i="(function(){\n",r="var arr = [];\n";l=n.exec(e);)c(e.slice(a,l.index),!1),c(l[1],!0),a=l.index+l[0].length;c(e.substr(a,e.length-a),!1),i+=r="with (__mito_data) {\n"+(r+='__mito_result = arr.join("");')+"\n}",i+="})();";var s=document.getElementsByTagName("script"),d="";s.length>0&&(d=s[0].nonce||"");var u=document.createElement("SCRIPT");u.innerHTML=i,u.setAttribute("nonce",d),document.documentElement.appendChild(u);var f=__mito_result;if(document.documentElement.removeChild(u),!o){var v=document.createElement("DIV");v.innerHTML=f,f=v.children[0]}return f},e.exports=t.default})?n.apply(t,r):n)||(e.exports=i)},function(e,t,o){var n=o(12);"string"==typeof n&&(n=[[e.i,n,""]]);var r={hmr:!0,transform:void 0,insertInto:void 0};o(4)(n,r);n.locals&&(e.exports=n.locals)},function(e,t,o){(e.exports=o(3)(!1)).push([e.i,'#__vconsole {\n color: #000;\n font-size: 13px;\n font-family: Helvetica Neue, Helvetica, Arial, sans-serif;\n /* global */\n /* compoment */\n}\n#__vconsole .vc-max-height {\n max-height: 19.23076923em;\n}\n#__vconsole .vc-max-height-line {\n max-height: 3.38461538em;\n}\n#__vconsole .vc-min-height {\n min-height: 3.07692308em;\n}\n#__vconsole dd,\n#__vconsole dl,\n#__vconsole pre {\n margin: 0;\n}\n#__vconsole .vc-switch {\n display: block;\n position: fixed;\n right: 0.76923077em;\n bottom: 0.76923077em;\n color: #FFF;\n background-color: #04BE02;\n line-height: 1;\n font-size: 1.07692308em;\n padding: 0.61538462em 1.23076923em;\n z-index: 10000;\n border-radius: 0.30769231em;\n box-shadow: 0 0 0.61538462em rgba(0, 0, 0, 0.4);\n}\n#__vconsole .vc-mask {\n display: none;\n position: fixed;\n top: 0;\n left: 0;\n right: 0;\n bottom: 0;\n background: rgba(0, 0, 0, 0);\n z-index: 10001;\n transition: background 0.3s;\n -webkit-tap-highlight-color: transparent;\n overflow-y: scroll;\n}\n#__vconsole .vc-panel {\n display: none;\n position: fixed;\n min-height: 85%;\n left: 0;\n right: 0;\n bottom: 0;\n z-index: 10002;\n background-color: #EFEFF4;\n -webkit-transition: -webkit-transform 0.3s;\n transition: -webkit-transform 0.3s;\n transition: transform 0.3s;\n transition: transform 0.3s, -webkit-transform 0.3s;\n -webkit-transform: translate(0, 100%);\n transform: translate(0, 100%);\n}\n#__vconsole .vc-tabbar {\n border-bottom: 1px solid #D9D9D9;\n overflow-x: auto;\n height: 3em;\n width: auto;\n white-space: nowrap;\n}\n#__vconsole .vc-tabbar .vc-tab {\n display: inline-block;\n line-height: 3em;\n padding: 0 1.15384615em;\n border-right: 1px solid #D9D9D9;\n text-decoration: none;\n color: #000;\n -webkit-tap-highlight-color: transparent;\n -webkit-touch-callout: none;\n}\n#__vconsole .vc-tabbar .vc-tab:active {\n background-color: rgba(0, 0, 0, 0.15);\n}\n#__vconsole .vc-tabbar .vc-tab.vc-actived {\n background-color: #FFF;\n}\n#__vconsole .vc-content {\n background-color: #FFF;\n overflow-x: hidden;\n overflow-y: auto;\n position: absolute;\n top: 3.07692308em;\n left: 0;\n right: 0;\n bottom: 3.07692308em;\n -webkit-overflow-scrolling: touch;\n margin-bottom: constant(safe-area-inset-bottom);\n margin-bottom: env(safe-area-inset-bottom);\n}\n#__vconsole .vc-content.vc-has-topbar {\n top: 5.46153846em;\n}\n#__vconsole .vc-topbar {\n background-color: #FBF9FE;\n display: flex;\n display: -webkit-box;\n flex-direction: row;\n flex-wrap: wrap;\n -webkit-box-direction: row;\n -webkit-flex-wrap: wrap;\n width: 100%;\n}\n#__vconsole .vc-topbar .vc-toptab {\n display: none;\n flex: 1;\n -webkit-box-flex: 1;\n line-height: 2.30769231em;\n padding: 0 1.15384615em;\n border-bottom: 1px solid #D9D9D9;\n text-decoration: none;\n text-align: center;\n color: #000;\n -webkit-tap-highlight-color: transparent;\n -webkit-touch-callout: none;\n}\n#__vconsole .vc-topbar .vc-toptab.vc-toggle {\n display: block;\n}\n#__vconsole .vc-topbar .vc-toptab:active {\n background-color: rgba(0, 0, 0, 0.15);\n}\n#__vconsole .vc-topbar .vc-toptab.vc-actived {\n border-bottom: 1px solid #3e82f7;\n}\n#__vconsole .vc-logbox {\n display: none;\n position: relative;\n min-height: 100%;\n}\n#__vconsole .vc-logbox i {\n font-style: normal;\n}\n#__vconsole .vc-logbox .vc-log {\n padding-bottom: 3em;\n -webkit-tap-highlight-color: transparent;\n}\n#__vconsole .vc-logbox .vc-log:empty:before {\n content: "Empty";\n color: #999;\n position: absolute;\n top: 45%;\n left: 0;\n right: 0;\n bottom: 0;\n font-size: 1.15384615em;\n text-align: center;\n}\n#__vconsole .vc-logbox .vc-item {\n margin: 0;\n padding: 0.46153846em 0.61538462em;\n overflow: hidden;\n line-height: 1.3;\n border-bottom: 1px solid #EEE;\n word-break: break-word;\n}\n#__vconsole .vc-logbox .vc-item-info {\n color: #6A5ACD;\n}\n#__vconsole .vc-logbox .vc-item-debug {\n color: #DAA520;\n}\n#__vconsole .vc-logbox .vc-item-warn {\n color: #FFA500;\n border-color: #FFB930;\n background-color: #FFFACD;\n}\n#__vconsole .vc-logbox .vc-item-error {\n color: #DC143C;\n border-color: #F4A0AB;\n background-color: #FFE4E1;\n}\n#__vconsole .vc-logbox .vc-log.vc-log-partly .vc-item {\n display: none;\n}\n#__vconsole .vc-logbox .vc-log.vc-log-partly-log .vc-item-log,\n#__vconsole .vc-logbox .vc-log.vc-log-partly-info .vc-item-info,\n#__vconsole .vc-logbox .vc-log.vc-log-partly-warn .vc-item-warn,\n#__vconsole .vc-logbox .vc-log.vc-log-partly-error .vc-item-error {\n display: block;\n}\n#__vconsole .vc-logbox .vc-item .vc-item-content {\n margin-right: 4.61538462em;\n display: inline-block;\n}\n#__vconsole .vc-logbox .vc-item .vc-item-repeat {\n display: inline-block;\n margin-right: 0.30769231em;\n padding: 0 6.5px;\n color: #D7E0EF;\n background-color: #42597F;\n border-radius: 8.66666667px;\n}\n#__vconsole .vc-logbox .vc-item.vc-item-error .vc-item-repeat {\n color: #901818;\n background-color: #DC2727;\n}\n#__vconsole .vc-logbox .vc-item.vc-item-warn .vc-item-repeat {\n color: #987D20;\n background-color: #F4BD02;\n}\n#__vconsole .vc-logbox .vc-item .vc-item-code {\n display: block;\n white-space: pre-wrap;\n overflow: auto;\n position: relative;\n}\n#__vconsole .vc-logbox .vc-item .vc-item-code.vc-item-code-input,\n#__vconsole .vc-logbox .vc-item .vc-item-code.vc-item-code-output {\n padding-left: 0.92307692em;\n}\n#__vconsole .vc-logbox .vc-item .vc-item-code.vc-item-code-input:before,\n#__vconsole .vc-logbox .vc-item .vc-item-code.vc-item-code-output:before {\n content: "›";\n position: absolute;\n top: -0.23076923em;\n left: 0;\n font-size: 1.23076923em;\n color: #6A5ACD;\n}\n#__vconsole .vc-logbox .vc-item .vc-item-code.vc-item-code-output:before {\n content: "‹";\n}\n#__vconsole .vc-logbox .vc-item .vc-fold {\n display: block;\n overflow: auto;\n -webkit-overflow-scrolling: touch;\n}\n#__vconsole .vc-logbox .vc-item .vc-fold .vc-fold-outer {\n display: block;\n font-style: italic;\n padding-left: 0.76923077em;\n position: relative;\n}\n#__vconsole .vc-logbox .vc-item .vc-fold .vc-fold-outer:active {\n background-color: #E6E6E6;\n}\n#__vconsole .vc-logbox .vc-item .vc-fold .vc-fold-outer:before {\n content: "";\n position: absolute;\n top: 0.30769231em;\n left: 0.15384615em;\n width: 0;\n height: 0;\n border: transparent solid 0.30769231em;\n border-left-color: #000;\n}\n#__vconsole .vc-logbox .vc-item .vc-fold .vc-fold-outer.vc-toggle:before {\n top: 0.46153846em;\n left: 0;\n border-top-color: #000;\n border-left-color: transparent;\n}\n#__vconsole .vc-logbox .vc-item .vc-fold .vc-fold-inner {\n display: none;\n margin-left: 0.76923077em;\n}\n#__vconsole .vc-logbox .vc-item .vc-fold .vc-fold-inner.vc-toggle {\n display: block;\n}\n#__vconsole .vc-logbox .vc-item .vc-fold .vc-fold-inner .vc-code-key {\n margin-left: 0.76923077em;\n}\n#__vconsole .vc-logbox .vc-item .vc-fold .vc-fold-outer .vc-code-key {\n margin-left: 0;\n}\n#__vconsole .vc-logbox .vc-code-key {\n color: #905;\n}\n#__vconsole .vc-logbox .vc-code-private-key {\n color: #D391B5;\n}\n#__vconsole .vc-logbox .vc-code-function {\n color: #905;\n font-style: italic;\n}\n#__vconsole .vc-logbox .vc-code-number,\n#__vconsole .vc-logbox .vc-code-boolean {\n color: #0086B3;\n}\n#__vconsole .vc-logbox .vc-code-string {\n color: #183691;\n}\n#__vconsole .vc-logbox .vc-code-null,\n#__vconsole .vc-logbox .vc-code-undefined {\n color: #666;\n}\n#__vconsole .vc-logbox .vc-cmd {\n position: absolute;\n height: 3.07692308em;\n left: 0;\n right: 0;\n bottom: 0;\n border-top: 1px solid #D9D9D9;\n display: block!important;\n}\n#__vconsole .vc-logbox .vc-cmd .vc-cmd-input-wrap {\n display: block;\n height: 2.15384615em;\n margin-right: 3.07692308em;\n padding: 0.46153846em 0.61538462em;\n}\n#__vconsole .vc-logbox .vc-cmd .vc-cmd-input {\n width: 100%;\n border: none;\n resize: none;\n outline: none;\n padding: 0;\n font-size: 0.92307692em;\n}\n#__vconsole .vc-logbox .vc-cmd .vc-cmd-input::-webkit-input-placeholder {\n line-height: 2.15384615em;\n}\n#__vconsole .vc-logbox .vc-cmd .vc-cmd-btn {\n position: absolute;\n top: 0;\n right: 0;\n bottom: 0;\n width: 3.07692308em;\n border: none;\n background-color: #EFEFF4;\n outline: none;\n -webkit-touch-callout: none;\n font-size: 1em;\n}\n#__vconsole .vc-logbox .vc-cmd .vc-cmd-btn:active {\n background-color: rgba(0, 0, 0, 0.15);\n}\n#__vconsole .vc-logbox .vc-cmd .vc-cmd-prompted {\n position: fixed;\n width: 100%;\n background-color: #FBF9FE;\n border: 1px solid #D9D9D9;\n overflow-x: scroll;\n display: none;\n}\n#__vconsole .vc-logbox .vc-cmd .vc-cmd-prompted li {\n list-style: none;\n line-height: 30px;\n padding: 0 0.46153846em;\n border-bottom: 1px solid #D9D9D9;\n}\n#__vconsole .vc-logbox .vc-group .vc-group-preview {\n -webkit-touch-callout: none;\n}\n#__vconsole .vc-logbox .vc-group .vc-group-preview:active {\n background-color: #E6E6E6;\n}\n#__vconsole .vc-logbox .vc-group .vc-group-detail {\n display: none;\n padding: 0 0 0.76923077em 1.53846154em;\n border-bottom: 1px solid #EEE;\n}\n#__vconsole .vc-logbox .vc-group.vc-actived .vc-group-detail {\n display: block;\n background-color: #FBF9FE;\n}\n#__vconsole .vc-logbox .vc-group.vc-actived .vc-table-row {\n background-color: #FFF;\n}\n#__vconsole .vc-logbox .vc-group.vc-actived .vc-group-preview {\n background-color: #FBF9FE;\n}\n#__vconsole .vc-logbox .vc-table .vc-table-row {\n display: flex;\n display: -webkit-flex;\n flex-direction: row;\n flex-wrap: wrap;\n -webkit-box-direction: row;\n -webkit-flex-wrap: wrap;\n overflow: hidden;\n border-bottom: 1px solid #EEE;\n}\n#__vconsole .vc-logbox .vc-table .vc-table-row.vc-left-border {\n border-left: 1px solid #EEE;\n}\n#__vconsole .vc-logbox .vc-table .vc-table-col {\n flex: 1;\n -webkit-box-flex: 1;\n padding: 0.23076923em 0.30769231em;\n border-left: 1px solid #EEE;\n overflow: auto;\n white-space: pre-wrap;\n word-break: break-word;\n /*white-space: nowrap;\n text-overflow: ellipsis;*/\n -webkit-overflow-scrolling: touch;\n}\n#__vconsole .vc-logbox .vc-table .vc-table-col:first-child {\n border: none;\n}\n#__vconsole .vc-logbox .vc-table .vc-small .vc-table-col {\n padding: 0 0.30769231em;\n font-size: 0.92307692em;\n}\n#__vconsole .vc-logbox .vc-table .vc-table-col-2 {\n flex: 2;\n -webkit-box-flex: 2;\n}\n#__vconsole .vc-logbox .vc-table .vc-table-col-3 {\n flex: 3;\n -webkit-box-flex: 3;\n}\n#__vconsole .vc-logbox .vc-table .vc-table-col-4 {\n flex: 4;\n -webkit-box-flex: 4;\n}\n#__vconsole .vc-logbox .vc-table .vc-table-col-5 {\n flex: 5;\n -webkit-box-flex: 5;\n}\n#__vconsole .vc-logbox .vc-table .vc-table-col-6 {\n flex: 6;\n -webkit-box-flex: 6;\n}\n#__vconsole .vc-logbox .vc-table .vc-table-row-error {\n border-color: #F4A0AB;\n background-color: #FFE4E1;\n}\n#__vconsole .vc-logbox .vc-table .vc-table-row-error .vc-table-col {\n color: #DC143C;\n border-color: #F4A0AB;\n}\n#__vconsole .vc-logbox .vc-table .vc-table-col-title {\n font-weight: bold;\n}\n#__vconsole .vc-logbox.vc-actived {\n display: block;\n}\n#__vconsole .vc-toolbar {\n border-top: 1px solid #D9D9D9;\n line-height: 3em;\n position: absolute;\n left: 0;\n right: 0;\n bottom: 0;\n display: flex;\n display: -webkit-box;\n flex-direction: row;\n -webkit-box-direction: row;\n}\n#__vconsole .vc-toolbar .vc-tool {\n display: none;\n text-decoration: none;\n color: #000;\n width: 50%;\n flex: 1;\n -webkit-box-flex: 1;\n text-align: center;\n position: relative;\n -webkit-touch-callout: none;\n}\n#__vconsole .vc-toolbar .vc-tool.vc-toggle,\n#__vconsole .vc-toolbar .vc-tool.vc-global-tool {\n display: block;\n}\n#__vconsole .vc-toolbar .vc-tool:active {\n background-color: rgba(0, 0, 0, 0.15);\n}\n#__vconsole .vc-toolbar .vc-tool:after {\n content: " ";\n position: absolute;\n top: 0.53846154em;\n bottom: 0.53846154em;\n right: 0;\n border-left: 1px solid #D9D9D9;\n}\n#__vconsole .vc-toolbar .vc-tool-last:after {\n border: none;\n}\n@supports (bottom: constant(safe-area-inset-bottom)) or (bottom: env(safe-area-inset-bottom)) {\n #__vconsole .vc-toolbar,\n #__vconsole .vc-switch {\n bottom: constant(safe-area-inset-bottom);\n bottom: env(safe-area-inset-bottom);\n }\n}\n#__vconsole.vc-toggle .vc-switch {\n display: none;\n}\n#__vconsole.vc-toggle .vc-mask {\n background: rgba(0, 0, 0, 0.6);\n display: block;\n}\n#__vconsole.vc-toggle .vc-panel {\n -webkit-transform: translate(0, 0);\n transform: translate(0, 0);\n}\n',""])},function(e,t){e.exports=function(e){var t="undefined"!=typeof window&&window.location;if(!t)throw new Error("fixUrls requires window.location");if(!e||"string"!=typeof e)return e;var o=t.protocol+"//"+t.host,n=o+t.pathname.replace(/\/[^\/]*$/,"/");return e.replace(/url\s*\(((?:[^)(]|\((?:[^)(]+|\([^)(]*\))*\))*)\)/gi,function(e,t){var r,i=t.trim().replace(/^"(.*)"$/,function(e,t){return t}).replace(/^'(.*)'$/,function(e,t){return t});return/^(#|data:|http:\/\/|https:\/\/|file:\/\/\/|\s*$)/i.test(i)?e:(r=0===i.indexOf("//")?i:0===i.indexOf("/")?o+i:n+i.replace(/^\.\//,""),"url("+JSON.stringify(r)+")")})}},function(e,t){e.exports='
\n
vConsole
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n Hide\n
\n
\n
'},function(e,t){e.exports='{{name}}'},function(e,t){e.exports='
\n \n
'},function(e,t){e.exports='{{name}}'},function(e,t){e.exports='{{name}}'},function(module,exports,__webpack_require__){var __WEBPACK_AMD_DEFINE_FACTORY__,__WEBPACK_AMD_DEFINE_ARRAY__,__WEBPACK_AMD_DEFINE_RESULT__,factory;factory=function(_exports,_query,tool,_log,_tabbox_default,_item_code){"use strict";function _interopRequireWildcard(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var o in e)if(Object.prototype.hasOwnProperty.call(e,o)){var n=Object.defineProperty&&Object.getOwnPropertyDescriptor?Object.getOwnPropertyDescriptor(e,o):{};n.get||n.set?Object.defineProperty(t,o,n):t[o]=e[o]}return t.default=e,t}function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}function _typeof(e){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _defineProperties(e,t){for(var o=0;o=0&&o.test(e[r]);r--)n.push(e[r]);if(0==n.length){o=/\./;for(var i=t-1;i>=0&&o.test(e[i]);i--)n.push(e[i])}if(0===n.length){var a=e.match(/[\(\)\[\]\{\}]/gi)||[];return a[a.length-1]}return n.reverse().join("")};_query.default.bind(_query.default.one(".vc-cmd-input"),"keyup",function(e){var isDeleteKeyCode=8===e.keyCode||46===e.keyCode,$prompted=_query.default.one(".vc-cmd-prompted");$prompted.style.display="none",$prompted.innerHTML="";var tempValue=this.value,value=retrievePrecedingIdentifier(this.value,this.value.length);if(value&&value.length>0){if(/\(/.test(value)&&!isDeleteKeyCode)return void(_query.default.one(".vc-cmd-input").value+=")");if(/\[/.test(value)&&!isDeleteKeyCode)return void(_query.default.one(".vc-cmd-input").value+="]");if(/\{/.test(value)&&!isDeleteKeyCode)return void(_query.default.one(".vc-cmd-input").value+="}");if("."===value){var key=retrievePrecedingIdentifier(tempValue,tempValue.length-1);if(!cacheObj[key])try{cacheObj[key]=Object.getOwnPropertyNames(eval("("+key+")")).sort()}catch(e){}try{for(var _i3=0;_i3=0){var _$li=document.createElement("li");_$li.innerHTML=winKeys[_i4],_$li.onclick=function(){_query.default.one(".vc-cmd-input").value="",_query.default.one(".vc-cmd-input").value=this.innerHTML,"function"==keyTypes[this.innerHTML]&&(_query.default.one(".vc-cmd-input").value+="()"),$prompted.style.display="none"},$prompted.appendChild(_$li)}}else{var arr=value.split(".");if(cacheObj[arr[0]]){cacheObj[arr[0]].sort();for(var _i5=0;_i5=0&&(_$li2.innerHTML=_key3,_$li2.onclick=function(){_query.default.one(".vc-cmd-input").value="",_query.default.one(".vc-cmd-input").value=tempValue+this.innerHTML,$prompted.style.display="none"},$prompted.appendChild(_$li2))}}}if($prompted.children.length>0){var m=Math.min(200,31*$prompted.children.length);$prompted.style.display="block",$prompted.style.height=m+"px",$prompted.style.marginTop=-m+"px"}}else $prompted.style.display="none"}),_query.default.bind(_query.default.one(".vc-cmd",this.$tabbox),"submit",function(e){e.preventDefault();var t=_query.default.one(".vc-cmd-input",e.target),o=t.value;t.value="",""!==o&&that.evalCommand(o);var n=_query.default.one(".vc-cmd-prompted");n&&(n.style.display="none")});var code="";code+="if (!!window) {",code+="window.__vConsole_cmd_result = undefined;",code+="window.__vConsole_cmd_error = false;",code+="}";var scriptList=document.getElementsByTagName("script"),nonce="";scriptList.length>0&&(nonce=scriptList[0].nonce||"");var script=document.createElement("SCRIPT");script.innerHTML=code,script.setAttribute("nonce",nonce),document.documentElement.appendChild(script),document.documentElement.removeChild(script)}},{key:"mockConsole",value:function(){_get(_getPrototypeOf(VConsoleDefaultTab.prototype),"mockConsole",this).call(this);var e=this;tool.isFunction(window.onerror)&&(this.windowOnError=window.onerror),window.onerror=function(t,o,n,r,i){var a=t;o&&(a+="\n"+o.replace(location.origin,"")),(n||r)&&(a+=":"+n+":"+r);var l=!!i&&!!i.stack&&i.stack.toString()||"";e.printLog({logType:"error",logs:[a,l],noOrigin:!0}),tool.isFunction(e.windowOnError)&&e.windowOnError.call(window,t,o,n,r,i)}}},{key:"evalCommand",value:function(e){this.printLog({logType:"log",content:_query.default.render(_item_code.default,{content:e,type:"input"}),style:""});var t,o=void 0;try{o=eval.call(window,"("+e+")")}catch(t){try{o=eval.call(window,e)}catch(e){}}tool.isArray(o)||tool.isObject(o)?t=this.getFoldedLine(o):(tool.isNull(o)?o="null":tool.isUndefined(o)?o="undefined":tool.isFunction(o)?o="function()":tool.isString(o)&&(o='"'+o+'"'),t=_query.default.render(_item_code.default,{content:o,type:"output"})),this.printLog({logType:"log",content:t,style:""}),window.winKeys=Object.getOwnPropertyNames(window).sort()}}]),VConsoleDefaultTab}(_log.default),_default=VConsoleDefaultTab;_exports.default=_default,module.exports=exports.default},__WEBPACK_AMD_DEFINE_ARRAY__=[exports,__webpack_require__(1),__webpack_require__(0),__webpack_require__(5),__webpack_require__(23),__webpack_require__(24)],void 0===(__WEBPACK_AMD_DEFINE_RESULT__="function"==typeof(__WEBPACK_AMD_DEFINE_FACTORY__=factory)?__WEBPACK_AMD_DEFINE_FACTORY__.apply(exports,__WEBPACK_AMD_DEFINE_ARRAY__):__WEBPACK_AMD_DEFINE_FACTORY__)||(module.exports=__WEBPACK_AMD_DEFINE_RESULT__)},function(e,t){e.exports='
\n\t
\n
'},function(e,t){e.exports='
\n {{if (lineType == \'obj\')}}\n {{outer}}\n
\n {{else if (lineType == \'value\')}}\n {{value}}\n {{else if (lineType == \'kv\')}}\n {{key}}: {{value}}\n {{/if}}\n
'},function(e,t){e.exports='\n {{key}}: {{value}}\n'},function(e,t){e.exports='
\n
\n
\n \n
    \n
    \n \n
    \n
    \n
    '},function(e,t){e.exports='
    {{content}}
    '},function(e,t,o){var n,r,i;r=[t,o(5),o(26)],void 0===(i="function"==typeof(n=function(o,n,r){"use strict";function i(e){return e&&e.__esModule?e:{default:e}}function a(e){return(a="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function l(e,t){for(var o=0;o\n
    \n'},function(e,t,o){var n,r,i;r=[t,o(1),o(0),o(2),o(28),o(29),o(30)],void 0===(i="function"==typeof(n=function(o,n,r,i,a,l,c){"use strict";function s(e){return e&&e.__esModule?e:{default:e}}function d(e){return(d="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function u(e,t){for(var o=0;o=t.scrollHeight?e.isInBottom=!0:e.isInBottom=!1)}),e.reqList)e.updateRequest(o,{})}},{key:"onRemove",value:function(){window.XMLHttpRequest&&(window.XMLHttpRequest.prototype.open=this._open,window.XMLHttpRequest.prototype.send=this._send,this._open=void 0,this._send=void 0)}},{key:"onShow",value:function(){this.isShow=!0,1==this.isInBottom&&this.scrollToBottom()}},{key:"onHide",value:function(){this.isShow=!1}},{key:"onShowConsole",value:function(){1==this.isInBottom&&this.scrollToBottom()}},{key:"scrollToBottom",value:function(){var e=n.default.one(".vc-content");e.scrollTop=e.scrollHeight-e.offsetHeight}},{key:"clearLog",value:function(){for(var e in this.reqList={},this.domList)this.domList[e].remove(),this.domList[e]=void 0;this.domList={},this.renderHeader()}},{key:"renderHeader",value:function(){var e=Object.keys(this.reqList).length,t=n.default.render(l.default,{count:e}),o=n.default.one(".vc-log",this.$tabbox);this.$header?this.$header.parentNode.replaceChild(t,this.$header):o.parentNode.insertBefore(t,o),this.$header=t}},{key:"updateRequest",value:function(e,t){var o=Object.keys(this.reqList).length,i=this.reqList[e]||{};for(var a in t)i[a]=t[a];if(this.reqList[e]=i,this.isReady){var l={id:e,url:i.url,status:i.status,method:i.method||"-",costTime:i.costTime>0?i.costTime+"ms":"-",header:i.header||null,getData:i.getData||null,postData:i.postData||null,response:null,actived:!!i.actived};switch(i.responseType){case"":case"text":if(r.isString(i.response))try{l.response=JSON.parse(i.response),l.response=JSON.stringify(l.response,null,1),l.response=r.htmlEncode(l.response)}catch(e){l.response=r.htmlEncode(i.response)}else void 0!==i.response&&(l.response=Object.prototype.toString.call(i.response));break;case"json":void 0!==i.response&&(l.response=JSON.stringify(i.response,null,1),l.response=r.htmlEncode(l.response));break;case"blob":case"document":case"arraybuffer":default:void 0!==i.response&&(l.response=Object.prototype.toString.call(i.response))}0==i.readyState||1==i.readyState?l.status="Pending":2==i.readyState||3==i.readyState?l.status="Loading":4==i.readyState||(l.status="Unknown");var s=n.default.render(c.default,l),d=this.domList[e];i.status>=400&&n.default.addClass(n.default.one(".vc-group-preview",s),"vc-table-row-error"),d?d.parentNode.replaceChild(s,d):n.default.one(".vc-log",this.$tabbox).insertAdjacentElement("beforeend",s),this.domList[e]=s;var u=Object.keys(this.reqList).length;u!=o&&this.renderHeader(),this.isInBottom&&this.scrollToBottom()}}},{key:"mockAjax",value:function(){var e=window.XMLHttpRequest;if(e){var t=this,o=window.XMLHttpRequest.prototype.open,n=window.XMLHttpRequest.prototype.send;t._open=o,t._send=n,window.XMLHttpRequest.prototype.open=function(){var e=this,n=[].slice.call(arguments),r=n[0],i=n[1],a=t.getUniqueID(),l=null;e._requestID=a,e._method=r,e._url=i;var c=e.onreadystatechange||function(){},s=function(){var o=t.reqList[a]||{};if(o.readyState=e.readyState,o.status=0,e.readyState>1&&(o.status=e.status),o.responseType=e.responseType,0==e.readyState)o.startTime||(o.startTime=+new Date);else if(1==e.readyState)o.startTime||(o.startTime=+new Date);else if(2==e.readyState){o.header={};for(var n=e.getAllResponseHeaders()||"",r=n.split("\n"),i=0;i0){i.getData={},a=(a=a.join("?")).split("&");var l=!0,c=!1,s=void 0;try{for(var d,u=a[Symbol.iterator]();!(l=(d=u.next()).done);l=!0){var f=d.value;f=f.split("="),i.getData[f[0]]=decodeURIComponent(f[1])}}catch(e){c=!0,s=e}finally{try{l||null==u.return||u.return()}finally{if(c)throw s}}}if("POST"==i.method)if(r.isString(o)){var v=o.split("&");i.postData={};var p=!0,b=!1,h=void 0;try{for(var g,m=v[Symbol.iterator]();!(p=(g=m.next()).done);p=!0){var y=g.value;y=y.split("="),i.postData[y[0]]=y[1]}}catch(e){b=!0,h=e}finally{try{p||null==m.return||m.return()}finally{if(b)throw h}}}else r.isPlainObject(o)&&(i.postData=o);return this._noVConsole||t.updateRequest(this._requestID,i),n.apply(this,e)}}}},{key:"getUniqueID",value:function(){var e="xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(e){var t=16*Math.random()|0,o="x"==e?t:3&t|8;return o.toString(16)});return e}}])&&u(o.prototype,i),s&&u(o,s),t;var o,i,s}(i.default);o.default=b,e.exports=t.default})?n.apply(t,r):n)||(e.exports=i)},function(e,t){e.exports='
    \n
    \n
    '},function(e,t){e.exports='
    \n
    Name {{if (count > 0)}}({{count}}){{/if}}
    \n
    Method
    \n
    Status
    \n
    Time
    \n
    '},function(e,t){e.exports='
    \n
    \n
    {{url}}
    \n
    {{method}}
    \n
    {{status}}
    \n
    {{costTime}}
    \n
    \n
    \n {{if (header !== null)}}\n
    \n
    \n
    Headers
    \n
    \n {{for (var key in header)}}\n
    \n
    {{key}}
    \n
    {{header[key]}}
    \n
    \n {{/for}}\n
    \n {{/if}}\n {{if (getData !== null)}}\n
    \n
    \n
    Query String Parameters
    \n
    \n {{for (var key in getData)}}\n
    \n
    {{key}}
    \n
    {{getData[key]}}
    \n
    \n {{/for}}\n
    \n {{/if}}\n {{if (postData !== null)}}\n
    \n
    \n
    Form Data
    \n
    \n {{for (var key in postData)}}\n
    \n
    {{key}}
    \n
    {{postData[key]}}
    \n
    \n {{/for}}\n
    \n {{/if}}\n
    \n
    \n
    Response
    \n
    \n
    \n
    {{response || \'\'}}
    \n
    \n
    \n
    \n
    '},function(e,t,o){var n,r,i;r=[t,o(32),o(2),o(34),o(35),o(0),o(1)],void 0===(i="function"==typeof(n=function(o,n,r,i,a,l,c){"use strict";function s(e){return e&&e.__esModule?e:{default:e}}function d(e){return(d="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function u(e,t){for(var o=0;o0&&this.onChildRemove(e),e.addedNodes.length>0&&this.onChildAdd(e);break;case"attributes":this.onAttributesChange(e);break;case"characterData":this.onCharacterDataChange(e)}}},{key:"onChildRemove",value:function(e){var t=e.target,o=t.__vconsole_node;if(o){for(var n=0;n0||(e.childNodes[r]?n.renderView(e.childNodes[r],a,"replace"):a.style.display="none"))}}}),o){case"replace":t.parentNode.replaceChild(r,t);break;case"insertBefore":t.parentNode.insertBefore(r,t);break;default:t.appendChild(r)}return r}},{key:"getNode",value:function(e){if(!this._isIgnoredElement(e)){var t=e.__vconsole_node||{};if(t.nodeType=e.nodeType,t.nodeName=e.nodeName,t.tagName=e.tagName||"",t.textContent="",t.nodeType!=e.TEXT_NODE&&t.nodeType!=e.DOCUMENT_TYPE_NODE||(t.textContent=e.textContent),t.id=e.id||"",t.className=e.className||"",t.attributes=[],e.hasAttributes&&e.hasAttributes())for(var o=0;o0)for(var n=0;n .vcelm-node {\n display: block;\n}\n.vcelm-l .vcelm-node:active {\n background-color: rgba(0, 0, 0, 0.15);\n}\n.vcelm-l.vcelm-noc .vcelm-node:active {\n background-color: transparent;\n}\n.vcelm-t {\n white-space: pre-wrap;\n word-wrap: break-word;\n}\n/* level */\n.vcelm-l .vcelm-l {\n display: none;\n}\n.vcelm-l.vc-toggle > .vcelm-l {\n margin-left: 4px;\n display: block;\n}\n/* arrow */\n.vcelm-l:before {\n content: "";\n display: block;\n position: absolute;\n top: 6px;\n left: 3px;\n width: 0;\n height: 0;\n border: transparent solid 3px;\n border-left-color: #000;\n}\n.vcelm-l.vc-toggle:before {\n display: block;\n top: 6px;\n left: 0;\n border-top-color: #000;\n border-left-color: transparent;\n}\n.vcelm-l.vcelm-noc:before {\n display: none;\n}\n',""])},function(e,t){e.exports='
    \n
    \n
    '},function(e,t,o){var n,r,i;r=[t,o(36),o(37),o(0),o(1)],void 0===(i="function"==typeof(n=function(o,n,r,i,a){"use strict";function l(e){return e&&e.__esModule?e:{default:e}}function c(e,t){for(var o=0;o-1),l=i;0==e.childNodes.length&&(l=!0);var c=a.default.render(n.default,{node:e}),s=a.default.render(r.default,{node:e});if(l)a.default.addClass(t,"vcelm-noc"),t.appendChild(c),i||t.appendChild(s);else{t.appendChild(c);for(var d=0;d<{{node.tagName.toLowerCase()}}{{if (node.className || node.attributes.length)}}\n \n {{for (var i = 0; i < node.attributes.length; i++)}}\n {{if (node.attributes[i].value !== \'\')}}\n {{node.attributes[i].name}}="{{node.attributes[i].value}}"{{else}}\n {{node.attributes[i].name}}{{/if}}{{/for}}{{/if}}>'},function(e,t){e.exports='</{{node.tagName.toLowerCase()}}>'},function(e,t,o){var n,r,i;r=[t,o(2),o(39),o(40),o(0),o(1)],void 0===(i="function"==typeof(n=function(o,n,r,i,a,l){"use strict";function c(e){return e&&e.__esModule?e:{default:e}}function s(e){return(s="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function d(e,t){for(var o=0;o\n
    \n'},function(e,t){e.exports='
    \n
    \n
    Name
    \n
    Value
    \n
    \n {{for (var i = 0; i < list.length; i++)}}\n
    \n
    {{list[i].name}}
    \n
    {{list[i].value}}
    \n
    \n {{/for}}\n
    '}])}); \ No newline at end of file diff --git a/templates/taobao-creative-app/app.acss b/templates/taobao-creative-app/app.acss new file mode 100644 index 0000000000..b0c2c7f048 --- /dev/null +++ b/templates/taobao-creative-app/app.acss @@ -0,0 +1,5 @@ +page { + background: #f7f7f7; + display: flex; + flex: 1; +} diff --git a/templates/taobao-creative-app/app.ejs b/templates/taobao-creative-app/app.ejs new file mode 100644 index 0000000000..3ff590e712 --- /dev/null +++ b/templates/taobao-creative-app/app.ejs @@ -0,0 +1,56 @@ +$global._onShowCB = null; +$global._onHideCB = null; + +// HACK: on some devices my.createCanvas is undefined +if (!my.createCanvas) { + my.createCanvas = my._createCanvas; +} +if (!my.createOffscreenCanvas) { + my.createOffscreenCanvas = my._createOffscreenCanvas; +} + +App({ + onLaunch: function onLaunch(options) { + console.info('App onLaunched'); + + $global.__onCanvasCreated = function () { + <% if(polyfillsBundleFile) { %> + // Polyfills bundle. + require('./<%= polyfillsBundleFile %>'); + <% } %> + require('./<%= systemJsBundleFile %>'); + require('./load-module.js'); + const importMap = require('./<%= importMapFile %>').default; + let System = $global.System; + System.warmup({ + importMap, + importMapUrl: 'src/import-map.js', + }); + System.import('./web-adapter.js') + .then(() => { + return System.import('cc'); + }) + .then((cc) => { + return System.import('./engine-adapter.js') + .then(() => { + require('./load-module-plugin.js'); + return System.import('<%= applicationJs %>') + .then(({ Application }) => { + const application = new Application(); + application.init(cc); + return application.start(); + }); + }); + }) + .catch((err) => { + console.error(err); + }); + }; + }, + onShow: function onShow(options) { + $global._onShowCB && $global._onShowCB(); + }, + onHide: function onHide(options) { + $global._onHideCB && $global._onHideCB(); + } +}); \ No newline at end of file diff --git a/templates/taobao-creative-app/app.json b/templates/taobao-creative-app/app.json new file mode 100644 index 0000000000..c3b7d261c5 --- /dev/null +++ b/templates/taobao-creative-app/app.json @@ -0,0 +1,13 @@ +{ + "deviceOrientation": "portrait", + "pages": [ + "pages/index/index" + ], + "window": { + "defaultTitle": "CocosCreator", + "allowsBounceVertical":"NO", + "enableMultiAudio":true, + "enableAudioAlign":true, + "enableSkia":true + } +} diff --git a/templates/taobao-creative-app/mini.project.json b/templates/taobao-creative-app/mini.project.json new file mode 100644 index 0000000000..84539fa4c1 --- /dev/null +++ b/templates/taobao-creative-app/mini.project.json @@ -0,0 +1,9 @@ +{ + "include": [ + "**/assets/**/*", + "**/remote/**/*", + "**/src/**/*" + ], + "enableAppxNg": true, + "component2": true +} diff --git a/templates/taobao-creative-app/pages/index/index.axml b/templates/taobao-creative-app/pages/index/index.axml new file mode 100644 index 0000000000..b4c6524ebd --- /dev/null +++ b/templates/taobao-creative-app/pages/index/index.axml @@ -0,0 +1,12 @@ + + + \ No newline at end of file diff --git a/templates/taobao-creative-app/pages/index/index.js b/templates/taobao-creative-app/pages/index/index.js new file mode 100644 index 0000000000..c236d55461 --- /dev/null +++ b/templates/taobao-creative-app/pages/index/index.js @@ -0,0 +1,47 @@ +$global._touchstartCB = null; +$global._touchcancelCB = null; +$global._touchendCB = null; +$global._touchmoveCB = null; + +// HACK: on some devices my.createCanvas is undefined +if (!my.createCanvas) { + my.createCanvas = my._createCanvas; +} +if (!my.createOffscreenCanvas) { + my.createOffscreenCanvas = my._createOffscreenCanvas; +} + +Page({ + onReady () { }, + onError (err) { + console.error('error in page: ', err); + }, + onTouchStart (event) { + $global._touchstartCB && $global._touchstartCB(event); + }, + onTouchCancel (event) { + $global._touchcancelCB && $global._touchcancelCB(event); + }, + onTouchEnd (event) { + $global._touchendCB && $global._touchendCB(event); + }, + onTouchMove (event) { + $global._touchmoveCB && $global._touchmoveCB(event); + }, + canvasOnReady () { + my.createCanvas({ + id:'GameCanvas', + success(canvas){ + $global.screencanvas = canvas; + if (!canvas.addEventListener) { + // fix: undefined addEventListener + canvas.addEventListener = function () {} + } + $global.__onCanvasCreated(); + }, + fail (err) { + console.error('failed to init on screen canvas', err) + } + }); + } +}); diff --git a/templates/taobao-creative-app/pages/index/index.json b/templates/taobao-creative-app/pages/index/index.json new file mode 100644 index 0000000000..9e26dfeeb6 --- /dev/null +++ b/templates/taobao-creative-app/pages/index/index.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/templates/taobao-mini-game/game.ejs b/templates/taobao-mini-game/game.ejs new file mode 100644 index 0000000000..3ae735585b --- /dev/null +++ b/templates/taobao-mini-game/game.ejs @@ -0,0 +1,82 @@ + +if (!globalThis.window) { + globalThis.window = globalThis; +} +globalThis.self = $global; + +globalThis.__taobaoRequire = (urlNoSchema) => { + if (urlNoSchema.startsWith('./')) { + urlNoSchema = urlNoSchema.replace('./', ''); + } + require('./' + urlNoSchema); +}; +loadCC(); + +function loadCC() { + + require('./web-adapter'); + +<% if(polyfillsBundleFile) { %> + // Polyfills bundle. + require("<%= polyfillsBundleFile %>"); +<% } %> + + // SystemJS support. + require("<%= systemJsBundleFile %>"); + + + // Adapt for IOS, swap if opposite + if (canvas){ + var _w = canvas.width; + var _h = canvas.height; + if (screen.width < screen.height) { + if (canvas.width > canvas.height) { + _w = canvas.height; + _h = canvas.width; + } + } else { + if (canvas.width < canvas.height) { + _w = canvas.height; + _h = canvas.width; + } + } + canvas.width = _w; + canvas.height = _h; + } + + let System = $global.System; + globalThis.System = System; + const importMap = require("<%= importMapFile%>").default; + System.warmup({ + importMap, + importMapUrl: '<%= importMapFile%>', + defaultHandler: (urlNoSchema) => { + require('.' + urlNoSchema); + }, + handlers: { + 'plugin:': (urlNoSchema) => { + requirePlugin(urlNoSchema); + }, + 'project:': (urlNoSchema) => { + urlNoSchema = urlNoSchema.replace("//", ""); + require("./" + urlNoSchema); + }, + }, + }); + + System.import('<%= applicationJs %>').then(({ Application }) => { + return new Application(); + }).then((application) => { + return onApplicationCreated(application); + }).catch((err) => { + console.error(err); + }); + + function onApplicationCreated(application) { + return System.import('cc').then((cc) => { + require('./engine-adapter'); + return application.init(cc); + }).then(() => { return application.start(); }); + } + +} diff --git a/templates/taobao-mini-game/game.json b/templates/taobao-mini-game/game.json new file mode 100644 index 0000000000..1eeeb398ec --- /dev/null +++ b/templates/taobao-mini-game/game.json @@ -0,0 +1,9 @@ +{ + "deviceOrientation": "portrait", + "window": { + "allowsBounceVertical": "NO", + "transparentTitle": "always", + "enableAudioAlign": true, + "enableMultiAudio": true + } +} \ No newline at end of file diff --git a/templates/taobao-mini-game/mini.project.json b/templates/taobao-mini-game/mini.project.json new file mode 100644 index 0000000000..9dd8e2c19d --- /dev/null +++ b/templates/taobao-mini-game/mini.project.json @@ -0,0 +1,7 @@ +{ + "miniprogramRoot": "client", + "pluginRoot": "widget", + "compileType": "minigame", + "enableAppxNg": true, + "widgetRuntimeVersion": "3.0-vue" +} diff --git a/templates/taobao-mini-game/patch.json b/templates/taobao-mini-game/patch.json new file mode 100644 index 0000000000..0db3279e44 --- /dev/null +++ b/templates/taobao-mini-game/patch.json @@ -0,0 +1,3 @@ +{ + +} diff --git a/templates/wechatgame/background.png b/templates/wechatgame/background.png new file mode 100644 index 0000000000..3cc8e399ea Binary files /dev/null and b/templates/wechatgame/background.png differ diff --git a/templates/wechatgame/cocos-script.ejs b/templates/wechatgame/cocos-script.ejs new file mode 100644 index 0000000000..e753734f86 --- /dev/null +++ b/templates/wechatgame/cocos-script.ejs @@ -0,0 +1,6 @@ +<% if(polyfillsBundleFile) { %> +// Polyfills bundle. +require("<%= polyfillsBundleFile %>"); +<% } %> +// SystemJS support. +require("<%= systemJsBundleFile %>"); diff --git a/templates/wechatgame/first-screen.ejs b/templates/wechatgame/first-screen.ejs new file mode 100644 index 0000000000..e4c7c6c179 --- /dev/null +++ b/templates/wechatgame/first-screen.ejs @@ -0,0 +1,514 @@ +const VS_LOGO = ` +attribute vec4 a_Position; +attribute vec2 a_TexCoord; +varying vec2 v_TexCoord; +void main() { + gl_Position = a_Position; + v_TexCoord = a_TexCoord; +}`; + +const FS_LOGO = ` +precision mediump float; +uniform sampler2D u_Sampler; +varying vec2 v_TexCoord; +void main() { + gl_FragColor = texture2D(u_Sampler, v_TexCoord); +}`; + +const VS_BG = ` +attribute vec4 a_Position; +attribute vec2 a_TexCoord; +varying vec2 v_TexCoord; +void main() { + gl_Position = a_Position; + v_TexCoord = a_TexCoord; +}`; + +const FS_BG = ` +precision mediump float; +uniform sampler2D u_Sampler; +uniform float u_flip; +varying vec2 v_TexCoord; +void main() { + vec2 texCoord = v_TexCoord; + if(u_flip > 0.5) { + texCoord.y = 1.0 - texCoord.y; + } + gl_FragColor = texture2D(u_Sampler, texCoord); +}`; + +const VS_PROGRESSBAR = ` +precision mediump float; +attribute vec4 a_Position; +attribute float a_Progress; +varying float v_Progress; +void main() { + gl_Position = a_Position; + v_Progress = a_Progress; +}`; + +const FS_PROGRESSBAR = ` +precision mediump float; +uniform float u_CurrentProgress; +varying float v_Progress; +uniform vec4 u_ProgressBarColor; +uniform vec4 u_ProgressBackground; +void main() { + gl_FragColor = v_Progress <= u_CurrentProgress ? u_ProgressBarColor : u_ProgressBackground; +}`; + +const options = { + alpha: false, + antialias: true, + depth: true, + stencil: true, + premultipliedAlpha: false, + preserveDrawingBuffer: false, + powerPreference: 'default', + failIfMajorPerformanceCaveat: false, +}; + +let gl = null; +let image = null; +let slogan = null; +let bg = null; +let program = null; +let programBg = null; +let programProgress = null; +let rafHandle = null; +let logoTexture = null; +let sloganTexture = null; +let bgTexture = null; +let vertexBuffer = null; +let sloganVertexBuffer = null; +let bgVertexBuffer = null; +let vertexBufferProgress = null; +let progress = 0.0; +let progressBarColor = [61 / 255, 197 / 255, 222 / 255, 1]; +let progressBackground = [100 / 255, 111 / 255, 118 / 255, 1]; +let afterTick = null; +let backgroundFilp = 1.0; // set 0 to not flip +let displayRatio = <%= displayRatio%>; +let bgColor = [<%= bgColor%>]; +let useCustomBg = <%= useCustomBg%>; +let useLogo = <%= useLogo%>; +let useDefaultLogo = <%= useDefaultLogo%>; +let logoName = '<%= logoName %>'; +let bgName = '<%= bgName %>'; +let fitWidth = <%= fitWidth %>; +let fitHeight = <%= fitHeight %>; + +function initShaders(vshader, fshader) { + return createProgram(vshader, fshader); +} + +function createProgram(vshader, fshader) { + var vertexShader = loadShader(gl.VERTEX_SHADER, vshader); + var fragmentShader = loadShader(gl.FRAGMENT_SHADER, fshader); + var program = gl.createProgram(); + gl.attachShader(program, vertexShader); + gl.attachShader(program, fragmentShader); + gl.linkProgram(program); + var linked = gl.getProgramParameter(program, gl.LINK_STATUS); + if (!linked) { + var error = gl.getProgramInfoLog(program); + console.log('Failed to link program: ' + error); + gl.deleteProgram(program); + program = null; + } + gl.deleteShader(fragmentShader); + gl.deleteShader(vertexShader); + return program; +} + +function loadShader(type, source) { + var shader = gl.createShader(type); + gl.shaderSource(shader, source); + gl.compileShader(shader); + var compiled = gl.getShaderParameter(shader, gl.COMPILE_STATUS); + if (!compiled) { + var error = gl.getShaderInfoLog(shader); + console.log('Failed to compile shader: ' + error); + gl.deleteShader(shader); + return null; + } + return shader; +} + +function initVertexBuffer() { + const widthRatio = 2 / canvas.width; + const heightRatio = 2 / canvas.height; + const heightOffset = 0.225; + const vertices = new Float32Array([ + widthRatio,heightRatio + heightOffset, 1.0, 1.0, + widthRatio, heightRatio + heightOffset, 1.0, 0.0, + -widthRatio, heightRatio + heightOffset, 0.0, 1.0, + -widthRatio, heightRatio + heightOffset, 0.0, 0.0, + ]); + vertexBuffer = gl.createBuffer(); + gl.bindBuffer(gl.ARRAY_BUFFER, vertexBuffer); + gl.bufferData(gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW); +} + +function initSloganVertexBuffer() { + const widthRatio = 2 / canvas.width; + const heightRatio = 2 / canvas.height; + const vertices = new Float32Array([ + widthRatio, heightRatio, 1.0, 1.0, + widthRatio, heightRatio, 1.0, 0.0, + -widthRatio, heightRatio, 0.0, 1.0, + -widthRatio, heightRatio, 0.0, 0.0, + ]); + sloganVertexBuffer = gl.createBuffer(); + gl.bindBuffer(gl.ARRAY_BUFFER, sloganVertexBuffer); + gl.bufferData(gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW); +} + +function initBgVertexBuffer() { + const vertices = new Float32Array([ + 1.0, 1.0, 1.0, 1.0, + 1.0, 0.0, 1.0, 0.0, + 0.0, 1.0, 0.0, 1.0, + 0.0, 0.0, 0.0, 0.0, + ]); + bgVertexBuffer = gl.createBuffer(); + gl.bindBuffer(gl.ARRAY_BUFFER, bgVertexBuffer); + gl.bufferData(gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW); +} + +function initProgressVertexBuffer() { + // the ratio value may be adjusted according to the image pixels + const widthRatio = 0.5; + const heightRatio = (window.devicePixelRatio >= 2 ? 6 : 3) / canvas.height * 1.35; + const heightOffset = -0.8; + const vertices = new Float32Array([ + widthRatio, heightOffset - heightRatio, 1, + widthRatio, heightOffset + heightRatio, 1, + -widthRatio, heightOffset - heightRatio, 0, + -widthRatio, heightOffset + heightRatio, 0, + ]); + vertexBufferProgress = gl.createBuffer(); + gl.bindBuffer(gl.ARRAY_BUFFER, vertexBufferProgress); + gl.bufferData(gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW); +} + +function updateVertexBuffer() { + const heightRatio = 1.0 * 0.185 * displayRatio; + const widthRatio = image.width * (canvas.height * 0.185 / image.height) / canvas.width * displayRatio; + + const vertices = new Float32Array([ + widthRatio, -heightRatio, 1.0, 1.0, + widthRatio, heightRatio, 1.0, 0.0, + -widthRatio, -heightRatio, 0.0, 1.0, + -widthRatio, heightRatio, 0.0, 0.0, + ]); + gl.bindBuffer(gl.ARRAY_BUFFER, vertexBuffer); + gl.bufferData(gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW); +} + +function updateSloganVertexBuffer() { + // the ratio value may be adjusted according to the image pixels + const widthRatio = slogan.width / canvas.width * 0.75; + const heightRatio = slogan.height / canvas.height * 0.75; + const logoHeightRatio = image.height / canvas.height * 1.35 * displayRatio; + const heightOffset = (5/12 + logoHeightRatio * 1/2 + heightRatio * 3/2) * (-2) + 1; // 5/12 is ui design layout for logo + const vertices = new Float32Array([ + widthRatio, heightOffset - heightRatio, 1.0, 1.0, + widthRatio, heightOffset + heightRatio, 1.0, 0.0, + -widthRatio, heightOffset - heightRatio, 0.0, 1.0, + -widthRatio, heightOffset + heightRatio, 0.0, 0.0, + ]); + gl.bindBuffer(gl.ARRAY_BUFFER, sloganVertexBuffer); + gl.bufferData(gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW); +} + +function updateBgVertexBuffer() { + let widthRatio = 1; + let heightRatio = 1; + if(fitWidth && !fitHeight) { + widthRatio = canvas.width; + heightRatio = (canvas.width / bg.width) * bg.height; + } else if(!fitWidth && fitHeight) { + widthRatio = (canvas.height / bg.height) * bg.width; + heightRatio = canvas.height; + } else if(fitWidth && fitHeight) { + if ((bg.width / bg.height) > (canvas.width / canvas.height)) { + widthRatio = canvas.width; + heightRatio = (canvas.width / bg.width) * bg.height; + } else { + widthRatio = (canvas.height / bg.height) * bg.width; + heightRatio = canvas.height; + } + } else if(!fitWidth && !fitHeight) { + if ((bg.width / bg.height) > (canvas.width / canvas.height)) { + widthRatio = (canvas.height / bg.height) * bg.width; + heightRatio = canvas.height; + } else { + widthRatio = canvas.width; + heightRatio = (canvas.width / bg.width) * bg.height; + } + } else { + widthRatio = canvas.width; + heightRatio = canvas.height; + } + widthRatio /= canvas.width; + heightRatio /= canvas.height; + + const vertices = new Float32Array([ + widthRatio, heightRatio, 1.0, 1.0, + widthRatio, -heightRatio, 1.0, 0.0, + -widthRatio, heightRatio, 0.0, 1.0, + -widthRatio, -heightRatio, 0.0, 0.0, + ]); + gl.bindBuffer(gl.ARRAY_BUFFER, bgVertexBuffer); + gl.bufferData(gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW); +} + +function loadBackground(bgPath) { + return new Promise((resolve, reject) => { + bg = new Image(); + bg.premultiplyAlpha = false; + bg.onload = function() { + resolve(bg); + }; + bg.onerror = function(err) { + reject(err); + }; + bg.src = bgPath.replace('#', '%23'); + }); +} + +function loadImage(imgPath) { + return new Promise((resolve, reject) => { + image = new Image(); + image.premultiplyAlpha = false; + image.onload = function() { + resolve(image); + }; + image.onerror = function(err) { + reject(err); + }; + image.src = imgPath.replace('#', '%23'); + }); +} + +function loadSlogan(sloganPath) { + return new Promise((resolve, reject) => { + slogan = new Image(); + slogan.premultiplyAlpha = false; + slogan.onload = function() { + resolve(slogan); + }; + slogan.onerror = function(err) { + reject(err); + }; + slogan.src = sloganPath.replace('#', '%23'); + }); +} + + +function initLogoTexture() { + logoTexture = gl.createTexture(); + gl.activeTexture(gl.TEXTURE0); + gl.bindTexture(gl.TEXTURE_2D, logoTexture); + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR); + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR); + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); + gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 2, 2, 0, gl.RGBA, gl.UNSIGNED_BYTE, new Uint8Array([0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255])); +} + +function initSloganTexture() { + sloganTexture = gl.createTexture(); + gl.activeTexture(gl.TEXTURE0); + gl.bindTexture(gl.TEXTURE_2D, sloganTexture); + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR); + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR); + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); + gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 2, 2, 0, gl.RGBA, gl.UNSIGNED_BYTE, new Uint8Array([0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255])); +} + +function initBgTexture() { + bgTexture = gl.createTexture(); + gl.activeTexture(gl.TEXTURE0); + gl.bindTexture(gl.TEXTURE_2D, bgTexture); + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR); + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR); + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); + gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 2, 2, 0, gl.RGBA, gl.UNSIGNED_BYTE, new Uint8Array([0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255])); +} + +function updateLogoTexture() { + gl.activeTexture(gl.TEXTURE0); + gl.bindTexture(gl.TEXTURE_2D, logoTexture); + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR); + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR); + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); + gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image); +} + +function updateSloganTexture() { + gl.activeTexture(gl.TEXTURE0); + gl.bindTexture(gl.TEXTURE_2D, sloganTexture); + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR); + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR); + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); + gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, slogan); +} + +function updateBgTexture() { + gl.activeTexture(gl.TEXTURE0); + gl.bindTexture(gl.TEXTURE_2D, bgTexture); + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR); + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR); + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); + gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, bg); +} + +function drawTexture(gl, program, texture, vertexBuffer, vertexFormatLength) { + gl.useProgram(program); + gl.activeTexture(gl.TEXTURE0); + gl.bindTexture(gl.TEXTURE_2D, texture); + var uSampler = gl.getUniformLocation(program, 'u_Sampler'); + gl.uniform1i(uSampler, 0); + var uFlip = gl.getUniformLocation(program, 'u_flip'); + gl.uniform1f(uFlip, backgroundFilp); + gl.bindBuffer(gl.ARRAY_BUFFER, vertexBuffer); + var aPosition = gl.getAttribLocation(program, 'a_Position'); + gl.enableVertexAttribArray(aPosition); + gl.vertexAttribPointer(aPosition, 2, gl.FLOAT, false, vertexFormatLength * 4, 0); + var aTexCoord = gl.getAttribLocation(program, 'a_TexCoord'); + gl.enableVertexAttribArray(aTexCoord); + gl.vertexAttribPointer(aTexCoord, 2, gl.FLOAT, false, vertexFormatLength * 4, vertexFormatLength * 2); + gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4); +} + +function drawProgressBar(gl, program, vertexBuffer, vertexFormatLength, progress, progressBarColor, progressBackground) { + gl.useProgram(program); + var uCurrentProgress = gl.getUniformLocation(program, 'u_CurrentProgress'); + gl.uniform1f(uCurrentProgress, progress); + var uProgressBarColor = gl.getUniformLocation(program, 'u_ProgressBarColor'); + gl.uniform4fv(uProgressBarColor, progressBarColor); + var uProgressBackground = gl.getUniformLocation(program, 'u_ProgressBackground'); + gl.uniform4fv(uProgressBackground, progressBackground); + gl.bindBuffer(gl.ARRAY_BUFFER, vertexBuffer); + var aPosition = gl.getAttribLocation(program, 'a_Position'); + gl.enableVertexAttribArray(aPosition); + var vertexFormatLength = 4; + gl.vertexAttribPointer(aPosition, 2, gl.FLOAT, false, vertexFormatLength * 3, 0); + var aProgress = gl.getAttribLocation(program, 'a_Progress'); + gl.enableVertexAttribArray(aProgress); + gl.vertexAttribPointer(aProgress, 1, gl.FLOAT, false, vertexFormatLength * 3, vertexFormatLength * 2); + gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4); +} + +function draw() { + gl.enable(gl.BLEND); + gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA); + gl.clearColor(bgColor[0], bgColor[1], bgColor[2], bgColor[3]); + gl.clear(gl.COLOR_BUFFER_BIT); + // draw background + useCustomBg && drawTexture(gl, programBg, bgTexture, bgVertexBuffer, 4); + // draw logo + useLogo && drawTexture(gl, program, logoTexture, vertexBuffer, 4); + // draw slogan + useLogo && useDefaultLogo && drawTexture(gl, program, sloganTexture, sloganVertexBuffer, 4); + // draw progress bar + drawProgressBar(gl, programProgress, vertexBufferProgress, 3, progress, progressBarColor, progressBackground); +} + +function tick() { + rafHandle = requestAnimationFrame(() => { + draw(); + tick(); + if (afterTick) { + afterTick(); + afterTick = null; + } + }); +} + +function end() { + return setProgress(1).then(() => { + cancelAnimationFrame(rafHandle); + gl.useProgram(null); + gl.bindTexture(gl.TEXTURE_2D, null); + gl.bindBuffer(gl.ARRAY_BUFFER, null); + useLogo && gl.deleteTexture(logoTexture); + useLogo && useDefaultLogo && gl.deleteTexture(sloganTexture); + useCustomBg && gl.deleteTexture(bgTexture); + gl.deleteBuffer(vertexBuffer); + useCustomBg && gl.deleteBuffer(bgVertexBuffer); + useLogo && useDefaultLogo && gl.deleteBuffer(sloganVertexBuffer); + gl.deleteBuffer(vertexBufferProgress); + gl.deleteProgram(program); + gl.deleteProgram(programBg); + gl.deleteProgram(programProgress); + }); +} + +function setProgress(val) { + progress = val; + return new Promise((resolve, reject) => { + afterTick = () => { + resolve(); + }; + }); +} + +function start(alpha, antialias, useWebgl2) { + options.alpha = alpha === 'true' ? true : false; + options.antialias = antialias === 'false' ? false : true; + if (useWebgl2 === 'true') { + gl = window.canvas.getContext("webgl2", options); + } + // TODO: this is a hack method to detect whether WebGL2RenderingContext is supported + if (gl) { + window.WebGL2RenderingContext = true; + } else { + window.WebGL2RenderingContext = false; + gl = window.canvas.getContext("webgl", options); + } + initVertexBuffer(); + useCustomBg && initBgVertexBuffer(); + useLogo && useDefaultLogo && initSloganVertexBuffer(); + initProgressVertexBuffer(); + + initLogoTexture(); + useCustomBg && initBgTexture(); + useLogo && useDefaultLogo && initSloganTexture(); + + if (useLogo) { + program = initShaders(VS_LOGO, FS_LOGO); + } + if (useCustomBg) { + programBg = initShaders(VS_BG, FS_BG); + } + programProgress = initShaders(VS_PROGRESSBAR, FS_PROGRESSBAR); + tick(); + + return Promise.all([ + //logo should be loaded earlier than slogan + useLogo && loadImage(logoName).then(() => { + updateVertexBuffer(); + updateLogoTexture(); + }).then(() => { + return useLogo && useDefaultLogo && loadSlogan('slogan.png').then(() => { + updateSloganVertexBuffer(); + updateSloganTexture(); + }); + }), + useCustomBg && loadBackground(bgName).then(() => { + updateBgVertexBuffer(); + updateBgTexture(); + }) + ]).then(() => { + return setProgress(0); + }); +} +module.exports = { start, end, setProgress }; diff --git a/templates/wechatgame/game.ejs b/templates/wechatgame/game.ejs new file mode 100644 index 0000000000..111d1f62e6 --- /dev/null +++ b/templates/wechatgame/game.ejs @@ -0,0 +1,80 @@ +function __initApp () { // init app +globalThis.__wxRequire = require; // FIX: require cannot work in separate engine +require('./web-adapter'); +const firstScreen = require('./first-screen'); + +<%- include(cocosTemplate, {}) %> + +// Adapt for IOS, swap if opposite +const info = wx.getSystemInfoSync(); +if (canvas){ + var _w = canvas.width; + var _h = canvas.height; + if (info.screenWidth < info.screenHeight) { + if (canvas.width > canvas.height) { + _w = canvas.height; + _h = canvas.width; + } + } else { + if (canvas.width < canvas.height) { + _w = canvas.height; + _h = canvas.width; + } + } + canvas.width = _w; + canvas.height = _h; +} +// Adjust initial canvas size +if (canvas && window.devicePixelRatio >= 2) {canvas.width *= info.devicePixelRatio; canvas.height *= info.devicePixelRatio;} + +const importMap = require("<%= importMapFile%>").default; +System.warmup({ + importMap, + importMapUrl: '<%= importMapFile%>', + defaultHandler: (urlNoSchema) => { + require('.' + urlNoSchema); + }, + handlers: { + 'plugin:': (urlNoSchema) => { + requirePlugin(urlNoSchema); + }, + 'project:': (urlNoSchema) => { + require(urlNoSchema); + }, + }, +}); + +firstScreen.start('<%= alpha %>', '<%= antialias %>', '<%= useWebgl2 %>').then(() => { + return System.import('<%= applicationJs %>'); +}).then((module) => { + return firstScreen.setProgress(0.2).then(() => Promise.resolve(module)); +}).then(({ Application }) => { + return new Application(); +}).then((application) => { + return firstScreen.setProgress(0.4).then(() => Promise.resolve(application)); +}).then((application) => { + return onApplicationCreated(application); +}).catch((err) => { + console.error(err); +}); + +function onApplicationCreated(application) { + return System.import('cc').then((module) => { + return firstScreen.setProgress(0.6).then(() => Promise.resolve(module)); + }).then((cc) => { + require('./engine-adapter'); + return application.init(cc); + }).then(() => { + return firstScreen.end().then(() => application.start()); + }); +} + +} // init app + +// NOTE: on WeChat Android end, we can only get the correct screen size at the second tick of game. +var sysInfo = wx.getSystemInfoSync(); +if (sysInfo.platform.toLocaleLowerCase() === 'android') { + GameGlobal.requestAnimationFrame (__initApp); +} else { + __initApp(); +} diff --git a/templates/wechatgame/game.json b/templates/wechatgame/game.json new file mode 100644 index 0000000000..4b8f7bcdf9 --- /dev/null +++ b/templates/wechatgame/game.json @@ -0,0 +1,10 @@ +{ + "deviceOrientation": "portrait", + "openDataContext": "", + "networkTimeout": { + "request": 5000, + "connectSocket": 5000, + "uploadFile": 5000, + "downloadFile": 500000 + } +} \ No newline at end of file diff --git a/templates/wechatgame/logo.png b/templates/wechatgame/logo.png new file mode 100644 index 0000000000..54b297ba75 Binary files /dev/null and b/templates/wechatgame/logo.png differ diff --git a/templates/wechatgame/patch.json b/templates/wechatgame/patch.json new file mode 100644 index 0000000000..030bf0b4a9 --- /dev/null +++ b/templates/wechatgame/patch.json @@ -0,0 +1,3 @@ +{ + "_plugin-version": "3.2.2" +} diff --git a/templates/wechatgame/project.config.json b/templates/wechatgame/project.config.json new file mode 100644 index 0000000000..ef1fd7343b --- /dev/null +++ b/templates/wechatgame/project.config.json @@ -0,0 +1,35 @@ +{ + "description": "项目配置文件。", + "miniprogramRoot": "./", + "setting": { + "urlCheck": true, + "postcss": true, + "minified": true, + "newFeature": false, + "enhance": true, + "useIsolateContext": true + }, + "compileType": "game", + "libVersion": "widelyUsed", + "appid": "", + "projectname": "", + "condition": { + "search": { + "current": -1, + "list": [] + }, + "conversation": { + "current": -1, + "list": [] + }, + "game": { + "currentL": -1, + "list": [], + "current": -1 + }, + "miniprogram": { + "current": -1, + "list": [] + } + } +} diff --git a/templates/wechatgame/slogan.png b/templates/wechatgame/slogan.png new file mode 100644 index 0000000000..1fb6e6fe3d Binary files /dev/null and b/templates/wechatgame/slogan.png differ diff --git a/templates/wechatprogram/app.js b/templates/wechatprogram/app.js new file mode 100755 index 0000000000..5b59f4571c --- /dev/null +++ b/templates/wechatprogram/app.js @@ -0,0 +1,35 @@ +// app.js +App({ + GameGlobal: { + screencanvas: undefined, + canvas: undefined, + System: undefined, + Image: undefined, + cc: undefined, + CocosEngine: undefined, + ccwindow: undefined, + fsUtils: undefined, + document: undefined, + requestAnimationFrame: undefined, + cancelAnimationFrame: undefined, + Image: undefined, + ImageBitmap: undefined, + XMLHttpRequest: undefined, + WebSocket: undefined, + DOMParser: undefined, + WebAssembly: undefined, + WXWebAssembly: undefined, + CCWebAssembly: undefined, + _touchStart: undefined, + _touchMove: undefined, + _touchEnd: undefined, + _touchCancel: undefined, + showInput: false, + indexThis: undefined, + _onKeyboardInput: undefined, + _onKeyboardConfirm: undefined, + _onKeyboardComplete: undefined, + }, + onLaunch() { + }, +}) diff --git a/templates/wechatprogram/app.json b/templates/wechatprogram/app.json new file mode 100755 index 0000000000..79518f96b7 --- /dev/null +++ b/templates/wechatprogram/app.json @@ -0,0 +1,16 @@ +{ + "pages": [ + "index" + ], + "window": { + "backgroundTextStyle": "light", + "navigationBarBackgroundColor": "#fff", + "navigationBarTitleText": "CocosCreator", + "navigationBarTextStyle": "black", + "navigationStyle": "custom", + "pageOrientation": "portrait" + }, + "style": "v2", + "sitemapLocation": "sitemap.json", + "subPackages": [] +} diff --git a/templates/wechatprogram/app.wxss b/templates/wechatprogram/app.wxss new file mode 100755 index 0000000000..771e34219e --- /dev/null +++ b/templates/wechatprogram/app.wxss @@ -0,0 +1,8 @@ +/**app.wxss**/ +.container { + height: 100%; + width: 100%; + position: absolute; + top: 0px; + bottom: 0px; +} diff --git a/templates/wechatprogram/cocos-script.ejs b/templates/wechatprogram/cocos-script.ejs new file mode 100644 index 0000000000..e753734f86 --- /dev/null +++ b/templates/wechatprogram/cocos-script.ejs @@ -0,0 +1,6 @@ +<% if(polyfillsBundleFile) { %> +// Polyfills bundle. +require("<%= polyfillsBundleFile %>"); +<% } %> +// SystemJS support. +require("<%= systemJsBundleFile %>"); diff --git a/templates/wechatprogram/first-screen.js b/templates/wechatprogram/first-screen.js new file mode 100644 index 0000000000..f2a0b7917f --- /dev/null +++ b/templates/wechatprogram/first-screen.js @@ -0,0 +1,280 @@ +// TODO: insert global variable access by build process in Editor +const GameGlobal = getApp().GameGlobal; +const window = GameGlobal; +const requestAnimationFrame = GameGlobal.canvas.requestAnimationFrame; +const cancelAnimationFrame = GameGlobal.canvas.cancelAnimationFrame; + +const VS_LOGO = ` +attribute vec4 a_Position; +attribute vec2 a_TexCoord; +varying vec2 v_TexCoord; +void main() { + gl_Position = a_Position; + v_TexCoord = a_TexCoord; +}`; + +const FS_LOGO = ` +precision mediump float; +uniform sampler2D u_Sampler; +varying vec2 v_TexCoord; +void main() { + gl_FragColor = texture2D(u_Sampler, v_TexCoord); +}`; + +const VS_PROGRESSBAR = ` +precision mediump float; +attribute vec4 a_Position; +attribute float a_Progress; +varying float v_Progress; +void main() { + gl_Position = a_Position; + v_Progress = a_Progress; +}`; + +const FS_PROGRESSBAR = ` +precision mediump float; +uniform float u_CurrentProgress; +varying float v_Progress; +uniform vec4 u_ProgressBarColor; +uniform vec4 u_ProgressBackground; +void main() { + gl_FragColor = v_Progress <= u_CurrentProgress ? u_ProgressBarColor : u_ProgressBackground; +}`; + +const options = { + alpha: false, + antialias: true, + depth: true, + stencil: true, + premultipliedAlpha: false, + preserveDrawingBuffer: false, + powerPreference: 'default', + failIfMajorPerformanceCaveat: false, +}; + +//NOTE: canvas +let canvas = null; +let gl = null; +let image = null; +let program = null; +let programProgress = null; +let rafHandle = null; +let texture = null; +let vertexBuffer = null; +let vertexBufferProgress = null; +let progress = 0.0; +let progressBarColor = [61 / 255, 197 / 255, 222 / 255, 1]; +let progressBackground = [100 / 255, 111 / 255, 118 / 255, 1]; +let afterTick = null; + +function initShaders(vshader, fshader) { + return createProgram(vshader, fshader); +} + +function createProgram(vshader, fshader) { + var vertexShader = loadShader(gl.VERTEX_SHADER, vshader); + var fragmentShader = loadShader(gl.FRAGMENT_SHADER, fshader); + var program = gl.createProgram(); + gl.attachShader(program, vertexShader); + gl.attachShader(program, fragmentShader); + gl.linkProgram(program); + var linked = gl.getProgramParameter(program, gl.LINK_STATUS); + if (!linked) { + var error = gl.getProgramInfoLog(program); + console.log('Failed to link program: ' + error); + gl.deleteProgram(program); + program = null; + } + gl.deleteShader(fragmentShader); + gl.deleteShader(vertexShader); + return program; +} + +function loadShader(type, source) { + var shader = gl.createShader(type); + gl.shaderSource(shader, source); + gl.compileShader(shader); + var compiled = gl.getShaderParameter(shader, gl.COMPILE_STATUS); + if (!compiled) { + var error = gl.getShaderInfoLog(shader); + console.log('Failed to compile shader: ' + error); + gl.deleteShader(shader); + return null; + } + return shader; +} + +function initVertexBuffer() { + const widthRatio = 2 / canvas.width; + const heightRatio = 2 / canvas.height; + const vertices = new Float32Array([ + widthRatio, heightRatio, 1.0, 1.0, + widthRatio, heightRatio, 1.0, 0.0, + -widthRatio, heightRatio, 0.0, 1.0, + -widthRatio, heightRatio, 0.0, 0.0, + ]); + vertexBuffer = gl.createBuffer(); + gl.bindBuffer(gl.ARRAY_BUFFER, vertexBuffer); + gl.bufferData(gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW); +} + +function initProgressVertexBuffer() { + const widthRatio = 0.405; + const heightRatio = (window.devicePixelRatio >= 2 ? 6 : 3) / canvas.height; + const heightOffset = -0.25; + const vertices = new Float32Array([ + widthRatio, heightOffset - heightRatio, 1, + widthRatio, heightOffset + heightRatio, 1, + -widthRatio, heightOffset - heightRatio, 0, + -widthRatio, heightOffset + heightRatio, 0, + ]); + vertexBufferProgress = gl.createBuffer(); + gl.bindBuffer(gl.ARRAY_BUFFER, vertexBufferProgress); + gl.bufferData(gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW); +} + +function updateVertexBuffer() { + const widthRatio = image.width / canvas.width; + const heightRatio = image.height / canvas.height; + const vertices = new Float32Array([ + widthRatio, -heightRatio, 1.0, 1.0, + widthRatio, heightRatio, 1.0, 0.0, + -widthRatio, -heightRatio, 0.0, 1.0, + -widthRatio, heightRatio, 0.0, 0.0, + ]); + gl.bindBuffer(gl.ARRAY_BUFFER, vertexBuffer); + gl.bufferData(gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW); +} + +function loadImage(imgPath) { + return new Promise((resolve, reject) => { + // TODO:replace? + // image = new Image(); + image = GameGlobal.canvas.createImage(); + image.premultiplyAlpha = false; + image.onload = function() { + resolve(image); + }; + image.onerror = function(err) { + reject(err); + }; + image.src = imgPath.replace('#', '%23'); + }); +} + +function initTexture() { + texture = gl.createTexture(); + gl.activeTexture(gl.TEXTURE0); + gl.bindTexture(gl.TEXTURE_2D, texture); + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR); + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR); + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); + gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 2, 2, 0, gl.RGBA, gl.UNSIGNED_BYTE, new Uint8Array([0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255])); +} + +function updateTexture() { + gl.activeTexture(gl.TEXTURE0); + gl.bindTexture(gl.TEXTURE_2D, texture); + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR); + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR); + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); + gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image); +} + +function draw() { + gl.clearColor(0.0, 0.0, 0.0, 0.0); + gl.clear(gl.COLOR_BUFFER_BIT); + gl.useProgram(program); + gl.activeTexture(gl.TEXTURE0); + gl.bindTexture(gl.TEXTURE_2D, texture); + var uSampler = gl.getUniformLocation(program, 'u_Sampler'); + gl.uniform1i(uSampler, 0); + gl.bindBuffer(gl.ARRAY_BUFFER, vertexBuffer); + var vertexFormatLength = 4; + var aPosition = gl.getAttribLocation(program, 'a_Position'); + gl.enableVertexAttribArray(aPosition); + gl.vertexAttribPointer(aPosition, 2, gl.FLOAT, false, vertexFormatLength * 4, 0); + var aTexCoord = gl.getAttribLocation(program, 'a_TexCoord'); + gl.enableVertexAttribArray(aTexCoord); + gl.vertexAttribPointer(aTexCoord, 2, gl.FLOAT, false, vertexFormatLength * 4, vertexFormatLength * 2); + gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4); + gl.useProgram(programProgress); + var uCurrentProgress = gl.getUniformLocation(programProgress, 'u_CurrentProgress'); + gl.uniform1f(uCurrentProgress, progress); + var uProgressBarColor = gl.getUniformLocation(programProgress, 'u_ProgressBarColor'); + gl.uniform4fv(uProgressBarColor, progressBarColor); + var uProgressBackground = gl.getUniformLocation(programProgress, 'u_ProgressBackground'); + gl.uniform4fv(uProgressBackground, progressBackground); + gl.bindBuffer(gl.ARRAY_BUFFER, vertexBufferProgress); + aPosition = gl.getAttribLocation(programProgress, 'a_Position'); + gl.enableVertexAttribArray(aPosition); + gl.vertexAttribPointer(aPosition, 2, gl.FLOAT, false, vertexFormatLength * 3, 0); + var aProgress = gl.getAttribLocation(programProgress, 'a_Progress'); + gl.enableVertexAttribArray(aProgress); + gl.vertexAttribPointer(aProgress, 1, gl.FLOAT, false, vertexFormatLength * 3, vertexFormatLength * 2); + gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4); +} + +function tick() { + rafHandle = requestAnimationFrame(() => { + draw(); + tick(); + if (afterTick) { + afterTick(); + afterTick = null; + } + }); +} + +function end() { + return setProgress(1).then(() => { + cancelAnimationFrame(rafHandle); + gl.useProgram(null); + gl.bindTexture(gl.TEXTURE_2D, null); + gl.bindBuffer(gl.ARRAY_BUFFER, null); + gl.deleteTexture(texture); + gl.deleteBuffer(vertexBuffer); + gl.deleteBuffer(vertexBufferProgress); + gl.deleteProgram(program); + gl.deleteProgram(programProgress); + }); +} + +function setProgress(val) { + progress = val; + return new Promise((resolve, reject) => { + afterTick = () => { + resolve(); + }; + }); +} + +function start(alpha, antialias, useWebgl2) { + options.alpha = alpha === 'true' ? true : false; + options.antialias = antialias === 'false' ? false : true; + if (useWebgl2 === 'true') { + gl = window.canvas.getContext("webgl2", options); + } + // TODO: this is a hack method to detect whether WebGL2RenderingContext is supported + if (gl) { + window.WebGL2RenderingContext = true; + } else { + window.WebGL2RenderingContext = false; + gl = window.canvas.getContext("webgl", options); + } + canvas = window.canvas; + initVertexBuffer(); + initProgressVertexBuffer(); + initTexture(); + program = initShaders(VS_LOGO, FS_LOGO); + programProgress = initShaders(VS_PROGRESSBAR, FS_PROGRESSBAR); + tick(); + return loadImage('splash.png').then(() => { + updateVertexBuffer(); + updateTexture(); + return setProgress(0); + }); +} +module.exports = { start, end, setProgress }; diff --git a/templates/wechatprogram/game.ejs b/templates/wechatprogram/game.ejs new file mode 100644 index 0000000000..ab5a5d6ed4 --- /dev/null +++ b/templates/wechatprogram/game.ejs @@ -0,0 +1,100 @@ +globalThis.__wxRequire = require; +var GameGlobal = getApp().GameGlobal; +Page({ + onReady() { + GameGlobal.indexThis = this; + const query = wx.createSelectorQuery() + query.select('#myCanvas').node().exec(async (res) => { + const canvas = res[0].node; + let width = canvas.width; + let height = canvas.height; + const adapter = require('./miniapp-adapter'); + adapter.adapt(canvas, width, height); + require('./web-adapter'); + const firstScreen = require('./first-screen'); + <%- include(cocosTemplate, {}) %> + const loader = require('load-module.js'); + await loader.loadModules(); + + require('./application.js'); + // Adjust initial canvas size + if (canvas && GameGlobal.devicePixelRatio >= 2) { + canvas.width *= 2; canvas.height *= 2; + } + + const importMap = require("<%= importMapFile%>").default; + const System = GameGlobal.System; + System.warmup({ + importMap, + importMapUrl: '<%= importMapFile%>', + // defaultHandler: (urlNoSchema) => { + // require('.' + urlNoSchema); + // }, + // handlers: { + // 'plugin:': (urlNoSchema) => { + // requirePlugin(urlNoSchema); + // }, + // 'project:': (urlNoSchema) => { + // require(urlNoSchema); + // }, + // }, + }); + + firstScreen.start('<%= alpha %>', '<%= antialias %>', '<%= useWebgl2 %>').then(() => { + return System.import('<%= applicationJs %>'); + }).then((module) => { + return firstScreen.setProgress(0.2).then(() => Promise.resolve(module)); + }).then(({ Application }) => { + return new Application(); + }).then((application) => { + return firstScreen.setProgress(0.4).then(() => Promise.resolve(application)); + }).then((application) => { + return onApplicationCreated(application); + }).catch((err) => { + console.error(err); + }); + + function onApplicationCreated(application) { + return System.import('cc').then((module) => { + return firstScreen.setProgress(0.6).then(() => Promise.resolve(module)); + }).then((cc) => { + require('./engine-adapter'); + return application.init(cc); + }).then(() => { + return firstScreen.end().then(() => application.start()); + }); + } + + }) + }, + + onKeyboardInput: function (event) { + GameGlobal._onKeyboardInput && GameGlobal._onKeyboardInput(event); + }, + + onKeyboardConfirm: function (event) { + console.log(event.detail.value); + GameGlobal._onKeyboardConfirm && GameGlobal._onKeyboardConfirm(event); + }, + + onKeyboardComplete: function (event) { + console.log(event.detail.value); + GameGlobal._onKeyboardComplete && GameGlobal._onKeyboardComplete(event); + }, + + touchStart(event) { + GameGlobal._touchStart && GameGlobal._touchStart(event); + }, + + touchEnd(event) { + GameGlobal._touchEnd && GameGlobal._touchEnd(event); + }, + + touchMove(event) { + GameGlobal._touchMove && GameGlobal._touchMove(event); + }, + + touchCancel(event) { + GameGlobal._touchCancel && GameGlobal._touchCancel(event); + } +}) \ No newline at end of file diff --git a/templates/wechatprogram/game.json b/templates/wechatprogram/game.json new file mode 100644 index 0000000000..4b8f7bcdf9 --- /dev/null +++ b/templates/wechatprogram/game.json @@ -0,0 +1,10 @@ +{ + "deviceOrientation": "portrait", + "openDataContext": "", + "networkTimeout": { + "request": 5000, + "connectSocket": 5000, + "uploadFile": 5000, + "downloadFile": 500000 + } +} \ No newline at end of file diff --git a/templates/wechatprogram/index.json b/templates/wechatprogram/index.json new file mode 100755 index 0000000000..8835af0699 --- /dev/null +++ b/templates/wechatprogram/index.json @@ -0,0 +1,3 @@ +{ + "usingComponents": {} +} \ No newline at end of file diff --git a/templates/wechatprogram/index.wxml b/templates/wechatprogram/index.wxml new file mode 100755 index 0000000000..08154ba88a --- /dev/null +++ b/templates/wechatprogram/index.wxml @@ -0,0 +1,23 @@ + + + + + + + diff --git a/templates/wechatprogram/index.wxss b/templates/wechatprogram/index.wxss new file mode 100755 index 0000000000..4c1ec2dc69 --- /dev/null +++ b/templates/wechatprogram/index.wxss @@ -0,0 +1,14 @@ +/**app.wxss**/ +#myCanvas { + height: 100%; + width: 100%; + position: absolute; + top: 0px; + bottom: 0px; +} + +input { + color: transparent; + text-shadow: 0 0 0 #000; + opacity: 0; +} \ No newline at end of file diff --git a/templates/wechatprogram/miniapp-adapter.js b/templates/wechatprogram/miniapp-adapter.js new file mode 100644 index 0000000000..d5721d773b --- /dev/null +++ b/templates/wechatprogram/miniapp-adapter.js @@ -0,0 +1,98 @@ +var GameGlobal = getApp().GameGlobal; +exports.adapt = function (canvas, width, height) { + GameGlobal.canvas = canvas; + GameGlobal.CCWebAssembly = GameGlobal.WXWebAssembly = WXWebAssembly; + GameGlobal.requestAnimationFrame = GameGlobal.canvas.requestAnimationFrame || globalThis.setTimeout; + GameGlobal.cancelAnimationFrame = GameGlobal.canvas.cancelAnimationFrame || globalThis.setTimeout; + GameGlobal.setTimeout = globalThis.setTimeout; + GameGlobal.setInterval = globalThis.setInterval; + GameGlobal.clearTimeout = globalThis.clearTimeout; + GameGlobal.clearInterval = globalThis.clearInterval; + + let isFirstCall = true; + + wx.createCanvas = function () { + console.log('wx.createCanvas called'); + if (isFirstCall) { + isFirstCall = false; + return canvas; + } else { + return wx.createOffscreenCanvas({type:"2d", width: width, height: height}); + } + } + + wx.createImage = function () { + console.log('wx.creatImage in miniapp-adapter') + let image = canvas.createImage(); + return image; + } + + wx.onTouchStart = function (cb) { + GameGlobal._touchStart = function (event) { + handleTouchEvent(event); + cb(event); + }; + }; + wx.onTouchMove = function (cb) { + GameGlobal._touchMove = function (event) { + handleTouchEvent(event); + cb(event); + }; + }; + wx.onTouchEnd = function (cb) { + GameGlobal._touchEnd = function (event) { + handleTouchEvent(event); + cb(event); + }; + }; + wx.onTouchCancel = function (cb) { + GameGlobal._touchCancel = function (event) { + handleTouchEvent(event); + cb(event); + }; + }; + + wx.onKeyboardInput = function (cb) { + GameGlobal._onKeyboardInput = function (event) { + cb(event.detail); + }; + }; + + wx.onKeyboardConfirm = function (cb) { + GameGlobal._onKeyboardConfirm = function (event) { + cb(event.detail); + }; + }; + + wx.onKeyboardComplete = function (cb) { + GameGlobal._onKeyboardComplete = function (event) { + GameGlobal.indexThis.setData({ + showInput: false, + }); + cb(event.detail); + }; + }; + + wx.showKeyboard = function (obj) { + GameGlobal.indexThis.setData({ + showInput: true, + isPassword: false, + maxLength: obj.maxLength, + confirmType: obj.confirmType + }); + }; + + function handleTouchEvent (event) { + let changedTouches = event.changedTouches; + if (changedTouches) { + for (let touch of changedTouches) { + touch.clientX = touch.x; + touch.clientY = touch.y; + } + } + } + + //TODO: use wx.onDeviceMotionChange to instead + wx.onDeviceOrientationChange = function () { + } +}; diff --git a/templates/wechatprogram/patch.json b/templates/wechatprogram/patch.json new file mode 100644 index 0000000000..030bf0b4a9 --- /dev/null +++ b/templates/wechatprogram/patch.json @@ -0,0 +1,3 @@ +{ + "_plugin-version": "3.2.2" +} diff --git a/templates/wechatprogram/project.config.json b/templates/wechatprogram/project.config.json new file mode 100755 index 0000000000..968d398839 --- /dev/null +++ b/templates/wechatprogram/project.config.json @@ -0,0 +1,53 @@ +{ + "description": "项目配置文件", + "packOptions": { + "ignore": [], + "include": [] + }, + "setting": { + "ignoreDevUnusedFiles": false, + "ignoreUploadUnusedFiles": false, + "bundle": false, + "userConfirmedBundleSwitch": false, + "urlCheck": true, + "scopeDataCheck": false, + "coverView": true, + "es6": true, + "postcss": true, + "compileHotReLoad": false, + "lazyloadPlaceholderEnable": false, + "preloadBackgroundData": false, + "minified": true, + "autoAudits": false, + "newFeature": false, + "uglifyFileName": false, + "uploadWithSourceMap": true, + "useIsolateContext": true, + "nodeModules": false, + "enhance": true, + "useMultiFrameRuntime": true, + "useApiHook": true, + "useApiHostProcess": true, + "showShadowRootInWxmlPanel": true, + "packNpmManually": false, + "enableEngineNative": false, + "packNpmRelationList": [], + "minifyWXSS": true, + "showES6CompileOption": false, + "minifyWXML": true, + "babelSetting": { + "ignore": [], + "disablePlugins": [], + "outputPath": "" + } + }, + "compileType": "miniprogram", + "libVersion": "2.19.4", + "appid": "wx2c815291f1aa4d1c", + "projectname": "miniprogram-92", + "condition": {}, + "editorSetting": { + "tabIndent": "insertSpaces", + "tabSize": 4 + } +} \ No newline at end of file diff --git a/templates/wechatprogram/sitemap.json b/templates/wechatprogram/sitemap.json new file mode 100755 index 0000000000..ca02add20b --- /dev/null +++ b/templates/wechatprogram/sitemap.json @@ -0,0 +1,7 @@ +{ + "desc": "关于本文件的更多信息,请参考文档 https://developers.weixin.qq.com/miniprogram/dev/framework/sitemap.html", + "rules": [{ + "action": "allow", + "page": "*" + }] +} \ No newline at end of file diff --git a/templates/wechatprogram/splash.png b/templates/wechatprogram/splash.png new file mode 100644 index 0000000000..ef17f51c69 Binary files /dev/null and b/templates/wechatprogram/splash.png differ diff --git a/templates/xiaomi-quick-game/babel.config.js b/templates/xiaomi-quick-game/babel.config.js new file mode 100644 index 0000000000..1af3ae2db1 --- /dev/null +++ b/templates/xiaomi-quick-game/babel.config.js @@ -0,0 +1,8 @@ +module.exports = function(api) { + api.cache(true); + return { + presets: ["@babel/preset-env"], + plugins: ["@babel/plugin-transform-modules-commonjs"], + babelrcRoots: [".", "node_modules"] + }; +} \ No newline at end of file diff --git a/templates/xiaomi-quick-game/certificate/certificate.pem b/templates/xiaomi-quick-game/certificate/certificate.pem new file mode 100644 index 0000000000..fe635b145e --- /dev/null +++ b/templates/xiaomi-quick-game/certificate/certificate.pem @@ -0,0 +1,20 @@ +-----BEGIN CERTIFICATE----- +MIIDMTCCAhmgAwIBAgIJAMKpjyszxkDpMA0GCSqGSIb3DQEBCwUAMC4xCzAJBgNV +BAYTAkNOMQwwCgYDVQQKDANSUEsxETAPBgNVBAMMCFJQS0RlYnVnMCAXDTE3MDQx +OTAyMzE0OVoYDzIxMTYwMzI2MDIzMTQ5WjAuMQswCQYDVQQGEwJDTjEMMAoGA1UE +CgwDUlBLMREwDwYDVQQDDAhSUEtEZWJ1ZzCCASIwDQYJKoZIhvcNAQEBBQADggEP +ADCCAQoCggEBAK3kPd9jzvTctTIA3XNZVv9cHHDbAc6nTBfdZp9mtPOTkXFpvyCb +kL0QjOog0+1pv8D7dFeP4ptWXU5CT3ImvaPR+16dAtMRcsxEr5q4zieJzx3O6huL +UBa1k+xrzjXpRzkcOysmc8fTxt0tAwbDgJ2AA5TlXLTcVyb7GmJ+hl5CjnhoG5NN +LrkqI7S29c1U3uokj8Q7hzaj0TURu/uB5ZIMCLZY9KFDugqaEcvmUyJiD0fuV6sA +O/4kpiZUOnhV8/xWpRbMI4WFQsfgLOCV+X9uzUa29D677y//46t/EDSuQTHyBZbl +AcNMENkpMWZsH7J/+F19+U0/Hd5bJgneVRkCAwEAAaNQME4wHQYDVR0OBBYEFKDN +SZtt47ttOBDQzIchFYyxsg3mMB8GA1UdIwQYMBaAFKDNSZtt47ttOBDQzIchFYyx +sg3mMAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQELBQADggEBABaZctNrn4gLmNf/ +eNJ3x5CJIPjPwm6j9nwKhtadJ6BF+TIzSkJuHSgxULjW436F37otv94NPzT5PCBF +WxgXoqgLqnWwvsaqC4LUEjsZviWW4CB824YDUquEUVGFLE/U5KTZ7Kh1ceyUk4N8 ++mtkXkanWoBBk0OF24lNrAsNLB63yTLr9HxEe75+kmvxf1qVJUGtaOEWIhiFMiAB +5D4w/j2EFWktumjuy5TTwU0zhl52bc8V9SNixM1IaqzNrVPrdjv8viUX548pU3WT +xZ5ylDsxhMC1q4BXQVeIY8C0cMEX+WHOmOCvWrkxCkP91pKsSPkuVrWlzrkn8Ojo +swP6sBw= +-----END CERTIFICATE----- diff --git a/templates/xiaomi-quick-game/certificate/private.pem b/templates/xiaomi-quick-game/certificate/private.pem new file mode 100644 index 0000000000..50d0707f36 --- /dev/null +++ b/templates/xiaomi-quick-game/certificate/private.pem @@ -0,0 +1,28 @@ +-----BEGIN PRIVATE KEY----- +MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCt5D3fY8703LUy +AN1zWVb/XBxw2wHOp0wX3WafZrTzk5Fxab8gm5C9EIzqINPtab/A+3RXj+KbVl1O +Qk9yJr2j0ftenQLTEXLMRK+auM4nic8dzuobi1AWtZPsa8416Uc5HDsrJnPH08bd +LQMGw4CdgAOU5Vy03Fcm+xpifoZeQo54aBuTTS65KiO0tvXNVN7qJI/EO4c2o9E1 +Ebv7geWSDAi2WPShQ7oKmhHL5lMiYg9H7lerADv+JKYmVDp4VfP8VqUWzCOFhULH +4Czglfl/bs1GtvQ+u+8v/+OrfxA0rkEx8gWW5QHDTBDZKTFmbB+yf/hdfflNPx3e +WyYJ3lUZAgMBAAECggEBAJTnCBBdUB+fSs1prjeS/gsmnfgJoY+K9H7PCIxgj3yw +FXAvZAmRDKzJGlF2EOOQlTG0YNiGDj6EAtv7rjoKcINyULSg8IU6wLmn61MrAuUa +fa+Bujgh4E/B5swhOHAztNhzkzsM70Hi17wXSislh+HWd7qteOgqcbqgdOR4gaj+ +HUqtcxG3H3hCL3dWugnjLZMtestLKGHSSZvbQNjYM3kKy2LvO8NpxmDE4a+TXygK +qhaZjmS/dc/nJBJzOfkzby58RvGbzlJflfW/Uu3/gizj13GFQKWonq1xh630RAhv +xX5ySok2aAx/+/SiJSpNXvM09grQuoORSr7D1tm+5rECgYEA3vf0hRfua0XAOu6f +pyzNvLRRJ/pEew7XpNPCyS2TuMTd1yvXjGVxQfP46N6x1IM3SRU0zE+LSk80EF7l +u1Or7GyCEhabYNe/7P2F8ENP73Do0HwvcI1jGrgr6r9oK0J27Xei+f6Q0bgJOPI2 +qaLj+V37cOjkNSM1mhTjtDwK8k0CgYEAx6cMrkjHl1+lDIIOc3qAEL3jb3xQveYk +WrMF/B+j048k6boU4VvFJAIyQxOxMNxLjw3/9+zXCFJT4WaZK3TMXlg614ASGx3H +tKjJM9O07ywwMq1gbutFS4nHCg3L3Os6esL0SPwMdATR3Yh22n5OGI9o+/aURulL +GPEXef1Z2/0CgYEAgmwp5LxV4vu+8Pnp+4DSq4ISQr861XyeGTUhKEp3sUm+tgFY +KTChakHKpHS3Mqa6bQ5xft08je/8dWL9IHFWDIqAHxKIOsKY6oh1k0/cbyPtmx45 +Ja4efV+jmMHzrfJH3KnxdCg7D+GFy4CrBtlYXuJhlO81pft9fC6h7yh8ArUCgYBq +gvkl5Zftbs4rnRq+iqTVyagTKvwcQzIz3PwdZHfO/rfPpUFMdNv4eN99n3zRN0Vs +HSjoiEazntA3GLgwUdBRqLpDi4SdSMbo337vkksdqbJQ5uPiaMuAIBG6kF+pDSkW +ovkWErlGD+gySoI10FozihaVDRhPuFgjB0PiBcIxtQKBgGNSzX+Bx5+ux1Qny0Sn +SUcBtepLnO8M8wafoGNyehbMnLzfuMbaDiJOdozGlBNHZTtPB3r4AYb8WnltdKW0 +7i3fk26YZGiMVeUJvewA6/LOBEaqMdwoNwnoptvbR6ehHeE/PPtRtge2cD3bPIM7 +U9VlWgfgj9Dxfwhslqb9hmyp +-----END PRIVATE KEY----- diff --git a/templates/xiaomi-quick-game/game.ejs b/templates/xiaomi-quick-game/game.ejs new file mode 100644 index 0000000000..ac5eba0ade --- /dev/null +++ b/templates/xiaomi-quick-game/game.ejs @@ -0,0 +1,39 @@ +require('./web-adapter'); + +<% if(polyfillsBundleFile) { %> +// Polyfills bundle. +require("<%= polyfillsBundleFile %>"); +<% } %> + +// SystemJS support. +require("<%= systemJsBundleFile %>"); + +// hack for Xiaomi havent screen; +screen = window.screen; + +// Adjust initial canvas size +if (canvas && window.devicePixelRatio >= 2) {canvas.width *= 2; canvas.height *= 2;} + +const importMap = require("./<%= importMapFile%>").default; +System.warmup({ + importMap, + importMapUrl: '<%= importMapFile%>', + defaultHandler: (urlNoSchema) => { + require('.' + urlNoSchema); + }, +}); + +System.import('<%= applicationJs %>').then(({ Application }) => { + return new Application(); +}).then((application) => { + return onApplicationCreated(application); +}).catch((err) => { + console.error(err); +}); + +function onApplicationCreated(application) { + return System.import('cc').then((cc) => { + require('./engine-adapter'); + return application.init(cc); + }).then(() => application.start()); +} diff --git a/templates/xiaomi-quick-game/manifest.json b/templates/xiaomi-quick-game/manifest.json new file mode 100644 index 0000000000..89881cd0d5 --- /dev/null +++ b/templates/xiaomi-quick-game/manifest.json @@ -0,0 +1,13 @@ +{ + "package": "", + "name": "", + "versionName": "1.0.0", + "versionCode": 1201, + "minPlatformVersion": 1056, + "icon": "/image/icon.png", + "orientation": "portrait", + "type": "game", + "config": {}, + "display": {}, + "subpackages": [] +} \ No newline at end of file diff --git a/templates/xiaomi-quick-game/package.json b/templates/xiaomi-quick-game/package.json new file mode 100644 index 0000000000..bd6f186065 --- /dev/null +++ b/templates/xiaomi-quick-game/package.json @@ -0,0 +1,21 @@ +{ + "name": "xiaomi-adapter", + "version": "1.0.0", + "build-template": "xiaomigame", + "scripts": { + "build": "quickgame build --cocos-wx-game --include-file-ext .pem,.pkm,.webp,.astc", + "build-ignore-res": "quickgame build --cocos-wx-game --include-file-ext .pem,.pkm,.webp,.astc --ignore remote,res", + "release": "quickgame release --cocos-wx-game --include-file-ext .pem,.pkm,.webp,.astc", + "release-ignore-res": "quickgame release --cocos-wx-game --include-file-ext .pem,.pkm,.webp,.astc --ignore remote,res", + "server": "quickgame server", + "debug": "quickgame debug" + }, + "babel": { + "plugins": [ + "babel-plugin-transform-remove-strict-mode" + ] + }, + "dependencies": { + "quickgame-cli": "^0.1.19" + } +}