@wiajs/core 0.1.19 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.js +104 -73
- package/.prettierignore +5 -7
- package/LICENSE +1 -1
- package/babel.config.js +73 -19
- package/babel.web.js +86 -0
- package/dist/core.cmn.js +2209 -0
- package/dist/core.esm.js +1463 -1509
- package/dist/core.js +406 -893
- package/dist/core.min.js +9 -4
- package/gulpfile.js +57 -8
- package/index.js +2 -2
- package/package.json +17 -19
- package/prettier.config.js +4 -1
- package/test/test.js +73 -0
- package/util/tool.js +29 -26
- package/build.js +0 -102
- package/config.js +0 -69
- package/dist/core.common.js +0 -2257
- package/dist/core.common.min.js +0 -6
- package/dist/core.esm.min.js +0 -6
package/dist/core.min.js
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* wia core
|
|
3
|
-
* (c)
|
|
4
|
-
*
|
|
2
|
+
* wia core v1.0.1
|
|
3
|
+
* (c) 2015-2023 Sibyl Yu and contributors
|
|
4
|
+
* Released under the MIT License.
|
|
5
5
|
*/
|
|
6
|
-
var e,t;e=this,t=function(e){"use strict";var t=function(){function e(){}var t=e.prototype;return t.post=function(e,t){return new Promise((function(n,o){var r=$.getXhr();r.onreadystatechange=function(){4===r.readyState&&(200===r.status?n(r.responseText):o(new Error(r.statusText),r.responseText))},r.open("POST",e,!0);var a=t;"object"==typeof t&&(a=function(e){var t=[];for(var n in e)e.hasOwnProperty(n)&&t.push(n+"="+e[n]);return t.sort().join("&")}(t)),r.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),r.send(a)}))},t.postForm=function(e,t){return new Promise((function(n,o){var r=$.getXhr();r.onreadystatechange=function(){4===r.readyState&&(200===r.status?n(null,r.responseText):o(new Error(r.status),r.responseText))},r.open("POST",e,!0),r.send(t)}))},t.get=function(e,t){return $.get(e,t)},e}();function n(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}function o(e,t,o){return t&&n(e.prototype,t),o&&n(e,o),e}function r(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,a(e,t)}function a(e,t){return a=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},a(e,t)}function i(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}function s(e,t,n){return s=i()?Reflect.construct:function(e,t,n){var o=[null];o.push.apply(o,t);var r=new(Function.bind.apply(e,o));return n&&a(r,n.prototype),r},s.apply(null,arguments)}function c(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}var u=1,l={uniqueNumber:function(){return u+=1},id:function(e,t){return void 0===e&&(e="xxxxxxxxxx"),void 0===t&&(t="0123456789abcdef"),$.uid(e,t)},mdPreloaderContent:'\n <span class="preloader-inner">\n\t\t\t<svg viewBox="0 0 36 36">\n\t\t\t\t<circle cx="18" cy="18" r="16"></circle>\n\t\t\t</svg>\n </span>\n '.trim(),iosPreloaderContent:('\n <span class="preloader-inner">\n\t\t\t'+[0,1,2,3,4,5,6,7].map((function(){return'<span class="preloader-inner-line"></span>'})).join("")+"\n </span>\n ").trim(),auroraPreloaderContent:'\n <span class="preloader-inner">\n <span class="preloader-inner-circle"></span>\n </span>\n ',eventNameToColonCase:function(e){var t;return e.split("").map((function(e,n){return e.match(/[A-Z]/)&&0!==n&&!t?(t=!0,":"+e.toLowerCase()):e.toLowerCase()})).join("")},deleteProps:function(e){$.deleteProps(e)},nextTick:function(e,t){return void 0===t&&(t=0),setTimeout(e,t)},nextFrame:function(e){return $.nextFrame(e)},now:function(){return Date.now()},requestAnimationFrame:function(e){return $.requestAnimationFrame(e)},cancelAnimationFrame:function(e){return $.cancelAnimationFrame(e)},parseUrlQuery:function(e){return $.urlParam(e)},getTranslate:function(e,t){return void 0===t&&(t="x"),$.getTranslate(e,t)},serializeObject:function(e,t){if(void 0===t&&(t=[]),"string"==typeof e)return e;var n,o=[];function r(e){if(t.length>0){for(var n="",o=0;o<t.length;o+=1)n+=0===o?t[o]:"["+encodeURIComponent(t[o])+"]";return n+"["+encodeURIComponent(e)+"]"}return encodeURIComponent(e)}function a(e){return encodeURIComponent(e)}return Object.keys(e).forEach((function(i){var s;if(Array.isArray(e[i])){s=[];for(var c=0;c<e[i].length;c+=1)Array.isArray(e[i][c])||"object"!=typeof e[i][c]?s.push(r(i)+"[]="+a(e[i][c])):((n=t.slice()).push(i),n.push(String(c)),s.push(l.serializeObject(e[i][c],n)));s.length>0&&o.push(s.join("&"))}else null===e[i]||""===e[i]?o.push(r(i)+"="):"object"==typeof e[i]?((n=t.slice()).push(i),""!==(s=l.serializeObject(e[i],n))&&o.push(s)):void 0!==e[i]&&""!==e[i]?o.push(r(i)+"="+a(e[i])):""===e[i]&&o.push(r(i))})),o.join("&")},isObject:function(e){return"object"==typeof e&&null!==e&&e.constructor&&e.constructor===Object},merge:function(){var e;return(e=$).merge.apply(e,arguments)},extend:function(){for(var e,t=arguments.length,n=new Array(t),o=0;o<t;o++)n[o]=arguments[o];var r=n[0];return n.splice(0,1),(e=$).assign.apply(e,[r].concat(n))},bindMethods:function(e,t){var n=this;Object.keys(t).forEach((function(o){n.isObject(t[o])&&Object.keys(t[o]).forEach((function(n){"function"==typeof t[o][n]&&(t[o][n]=t[o][n].bind(e))})),e[o]=t[o]}))},colorHexToRgb:function(e){var t=e.replace(/^#?([a-f\d])([a-f\d])([a-f\d])$/i,(function(e,t,n,o){return t+t+n+n+o+o})),n=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(t);return n?n.slice(1).map((function(e){return parseInt(e,16)})):null},colorRgbToHex:function(e,t,n){return"#"+[e,t,n].map((function(e){var t=e.toString(16);return 1===t.length?"0"+t:t})).join("")},colorRgbToHsl:function(e,t,n){e/=255,t/=255,n/=255;var o,r=Math.max(e,t,n),a=Math.min(e,t,n),i=r-a;0===i?o=0:r===e?o=(t-n)/i%6:r===t?o=(n-e)/i+2:r===n&&(o=(e-t)/i+4);var s=(a+r)/2;return o<0&&(o=6+o),[60*o,0===i?0:i/(1-Math.abs(2*s-1)),s]},colorHslToRgb:function(e,t,n){var o,r=(1-Math.abs(2*n-1))*t,a=e/60,i=r*(1-Math.abs(a%2-1));Number.isNaN(e)||void 0===e?o=[0,0,0]:a<=1?o=[r,i,0]:a<=2?o=[i,r,0]:a<=3?o=[0,r,i]:a<=4?o=[0,i,r]:a<=5?o=[i,0,r]:a<=6&&(o=[r,0,i]);var s=n-r/2;return o.map((function(e){return Math.max(0,Math.min(255,Math.round(255*(e+s))))}))},colorHsbToHsl:function(e,t,n){var o={h:e,s:0,l:0},r=t,a=n;return o.l=(2-r)*a/2,o.s=o.l&&o.l<1?r*a/(o.l<.5?2*o.l:2-2*o.l):o.s,[o.h,o.s,o.l]},colorHslToHsb:function(e,t,n){var o={h:e,s:0,b:0},r=n,a=t*(r<.5?r:1-r);return o.b=r+a,o.s=r>0?2*a/o.b:o.s,[o.h,o.s,o.b]},colorThemeCSSProperties:function(){for(var e,t,n=arguments.length,o=new Array(n),r=0;r<n;r++)o[r]=arguments[r];if(1===o.length?(e=o[0],t=l.colorHexToRgb(e)):3===o.length&&(t=o,e=l.colorRgbToHex.apply(l,t)),!t)return{};var a=l.colorRgbToHsl.apply(l,t),i=[a[0],a[1],Math.max(0,a[2]-.08)],s=[a[0],a[1],Math.max(0,a[2]+.08)],c=l.colorRgbToHex.apply(l,l.colorHslToRgb.apply(l,i)),u=l.colorRgbToHex.apply(l,l.colorHslToRgb.apply(l,s));return{"--f7-theme-color":e,"--f7-theme-color-rgb":t.join(", "),"--f7-theme-color-shade":c,"--f7-theme-color-tint":u}}},d=function(){function e(e,t){void 0===e&&(e={}),void 0===t&&(t=[]);var n=this;n.params=e,n.eventsParents=t,n.eventsListeners={},n.params&&n.params.on&&Object.keys(n.params.on).forEach((function(e){n.on(e,n.params.on[e])}))}var t=e.prototype;return t.on=function(e,t,n){var o=this;if("function"!=typeof t)return o;var r=n?"unshift":"push";return e.split(" ").forEach((function(e){o.eventsListeners[e]||(o.eventsListeners[e]=[]),o.eventsListeners[e][r](t)})),o},t.once=function(e,t,n){var o=this;if("function"!=typeof t)return o;function r(){o.off(e,r),r.proxy&&delete r.proxy;for(var n=arguments.length,a=new Array(n),i=0;i<n;i++)a[i]=arguments[i];t.apply(o,a)}return r.proxy=t,o.on(e,r,n)},t.off=function(e,t){var n=this;return n.eventsListeners?(e.split(" ").forEach((function(e){void 0===t?n.eventsListeners[e]=[]:n.eventsListeners[e]&&n.eventsListeners[e].forEach((function(o,r){(o===t||o.proxy&&o.proxy===t)&&n.eventsListeners[e].splice(r,1)}))})),n):n},t.emit=function(){var e,t,n,o,r=this;if(!r.eventsListeners)return r;for(var a=arguments.length,i=new Array(a),s=0;s<a;s++)i[s]=arguments[s];"string"==typeof i[0]||Array.isArray(i[0])?(e=i[0],t=i.slice(1,i.length),n=r,o=r.eventsParents):(e=i[0].events,t=i[0].data,n=i[0].context||r,o=i[0].local?[]:i[0].parents||r.eventsParents);var c=Array.isArray(e)?e:e.split(" "),u=c.map((function(e){return e.replace("local::","")})),l=c.filter((function(e){return e.indexOf("local::")<0}));return u.forEach((function(e){if(r.eventsListeners&&r.eventsListeners[e]){var o=[];r.eventsListeners[e].forEach((function(e){o.push(e)})),o.forEach((function(e){e.apply(n,t)}))}})),o&&o.length>0&&o.forEach((function(e){e.emit.apply(e,[l].concat(t))})),r},e}(),f=function(e){function t(t,n){return void 0===t&&(t={}),void 0===n&&(n=[]),e.call(this,t,n)||this}r(t,e);var n=t.prototype;return n.useModuleParams=function(e,t){if(e.params){var n={};Object.keys(e.params).forEach((function(e){void 0!==t[e]&&(n[e]=$.extend({},t[e]))})),$.extend(t,e.params),Object.keys(n).forEach((function(e){$.extend(t[e],n[e])}))}},n.useModulesParams=function(e){var t=this;t.modules&&Object.keys(t.modules).forEach((function(n){var o=t.modules[n];o.params&&$.extend(e,o.params)}))},n.useModule=function(e,t){void 0===e&&(e=""),void 0===t&&(t={});var n=this;if(n.modules){var o="string"==typeof e?n.modules[e]:e;o&&(o.instance&&Object.keys(o.instance).forEach((function(e){var t=o.instance[e];n[e]="function"==typeof t?t.bind(n):t})),o.on&&n.on&&Object.keys(o.on).forEach((function(e){n.on(e,o.on[e])})),o.vnode&&(n.vnodeHooks||(n.vnodeHooks={}),Object.keys(o.vnode).forEach((function(e){Object.keys(o.vnode[e]).forEach((function(t){var r=o.vnode[e][t];n.vnodeHooks[t]||(n.vnodeHooks[t]={}),n.vnodeHooks[t][e]||(n.vnodeHooks[t][e]=[]),n.vnodeHooks[t][e].push(r.bind(n))}))}))),o.create&&o.create.bind(n)(t))}},n.useModules=function(e){void 0===e&&(e={});var t=this;t.modules&&Object.keys(t.modules).forEach((function(n){var o=e[n]||{};t.useModule(n,o)}))},t.installModule=function(e){var t=this;t.prototype.modules||(t.prototype.modules={});var n=e.name||Object.keys(t.prototype.modules).length+"_"+$.now();if(t.prototype.modules[n]=e,e.proto&&Object.keys(e.proto).forEach((function(n){t.prototype[n]=e.proto[n]})),e.static&&Object.keys(e.static).forEach((function(n){t[n]=e.static[n]})),e.install){for(var o=arguments.length,r=new Array(o>1?o-1:0),a=1;a<o;a++)r[a-1]=arguments[a];e.install.apply(t,r)}return t},t.use=function(e){var t=this;if(Array.isArray(e))return e.forEach((function(e){return t.installModule(e)})),t;for(var n=arguments.length,o=new Array(n>1?n-1:0),r=1;r<n;r++)o[r-1]=arguments[r];return t.installModule.apply(t,[e].concat(o))},o(t,null,[{key:"components",set:function(e){this.use&&this.use(e)}}]),t}(d);function p(e){void 0===e&&(e={});var t=e,n=t.defaultSelector,o=t.constructor,r=t.domProp,a=t.app,i=t.addMethods,c={create:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return s(o,a?[a].concat(t):t)},get:function(e){if(void 0===e&&(e=n),e instanceof o)return e;var t=$(e);return 0!==t.length?t[0][r]:void 0},destroy:function(e){var t=c.get(e);if(t&&t.destroy)return t.destroy()}};return i&&Array.isArray(i)&&i.forEach((function(e){c[e]=function(t){void 0===t&&(t=n);for(var o=c.get(t),r=arguments.length,a=new Array(r>1?r-1:0),i=1;i<r;i++)a[i-1]=arguments[i];if(o&&o[e])return o[e].apply(o,a)}})),c}function m(e){void 0===e&&(e={});var t=e,n=t.defaultSelector,o=t.constructor,r=t.app;return $.extend(p({defaultSelector:n,constructor:o,app:r,domProp:"f7Modal"}),{open:function(e,t){var n=$(e),a=n[0].f7Modal;return a||(a=new o(r,{el:n})),a.open(t)},close:function(e,t){void 0===e&&(e=n);var a=$(e);if(0!==a.length){var i=a[0].f7Modal;return i||(i=new o(r,{el:a})),i.close(t)}}})}var h=[];function v(e){var t=this;return new Promise((function(n,o){var r,a,i,s=t.instance;if(e){if("string"==typeof e){var c=e.match(/([a-z0-9-]*)/i);if(e.indexOf(".")<0&&c&&c[0].length===e.length){if(!s||s&&!s.params.lazyModulesPath)return void o(new Error('Wia: "lazyModulesPath" app parameter must be specified to fetch module by name'));r=s.params.lazyModulesPath+"/"+e+".js"}else r=e}else"function"==typeof e?i=e:a=e;if(i){var u=i(t,!1);if(!u)return void o(new Error("Wia: Can't find Wia component in specified component function"));if(t.prototype.modules&&t.prototype.modules[u.name])return void n();p(u),n()}if(a){var l=a;if(!l)return void o(new Error("Wia: Can't find Wia component in specified component"));if(t.prototype.modules&&t.prototype.modules[l.name])return void n();p(l),n()}if(r){if(h.indexOf(r)>=0)return void n();h.push(r);var d=new Promise((function(e,n){t.request.get(r,(function(o){var a="wia_component_loader_callback_"+$.id(),i=document.createElement("script");i.innerHTML="window."+a+" = function (Wia, WiaAutoInstallComponent) {return "+o.trim()+"}",$("head").append(i);var s=window[a];delete window[a],$(i).remove();var c=s(t,!1);c?(t.prototype.modules&&t.prototype.modules[c.name]||p(c),e()):n(new Error("Wia: Can't find Wia component in "+r+" file"))}),(function(e,t){n(e,t)}))})),f=new Promise((function(e){t.request.get(r.replace(".js",s.rtl?".rtl.css":".css"),(function(t){var n=document.createElement("style");n.innerHTML=t,$("head").append(n),e()}),(function(){e()}))}));Promise.all([d,f]).then((function(){n()})).catch((function(e){o(e)}))}}else o(new Error("Wia: Lazy module must be specified"));function p(e){t.use(e),s&&(s.useModuleParams(e,s.params),s.useModule(e))}}))}var y={name:"resize",instance:{getSize:function(){var e=this;if(!e.root[0])return{width:0,height:0,left:0,top:0};var t=e.root.offset(),n=[e.root[0].offsetWidth,e.root[0].offsetHeight,t.left,t.top],o=n[0],r=n[1],a=n[2],i=n[3];return e.width=o,e.height=r,e.left=a,e.top=i,{width:o,height:r,left:a,top:i}}},on:{init:function(){var e=this;e.getSize(),window.addEventListener("resize",(function(){e.emit("resize")}),!1),window.addEventListener("orientationchange",(function(){e.emit("orientationchange")}))},orientationchange:function(){this.device.ipad&&(document.body.scrollLeft=0,setTimeout((function(){document.body.scrollLeft=0}),0))},resize:function(){this.getSize()}}};function g(e){var t,n,o;t=function(t){e.emit({events:"click",data:[t]})},$.support.touch?(document.addEventListener("touchstart",(function(e){n=e.changedTouches[0].clientX,o=e.changedTouches[0].clientY}),!0),document.addEventListener("touchend",(function(e){var r=Math.abs(e.changedTouches[0].clientX-n),a=Math.abs(e.changedTouches[0].clientY-o);r<=5&&a<=5&&t.call(this,e)}),!0)):document.addEventListener("click",t,!0),e.on("click",(function(t){var n=$(t.target),o=n.closest("a");o.length>0&&o.attr("href"),Object.keys(e.modules).forEach((function(o){var r=e.modules[o].clicks;r&&(t.preventF7Router||Object.keys(r).forEach((function(o){var a=n.closest(o).eq(0);a.length>0&&r[o].call(e,a,a.dataset(),t)})))}))}))}var w={name:"clicks",params:{clicks:{externalLinks:".ext"}},on:{init:function(){g(this)}}},b={registrations:[],register:function(e,t){var n=this;return"serviceWorker"in window.navigator&&n.serviceWorker.container?new Promise((function(o,r){n.serviceWorker.container.register(e,t?{scope:t}:{}).then((function(e){b.registrations.push(e),n.emit("serviceWorkerRegisterSuccess",e),o(e)})).catch((function(e){n.emit("serviceWorkerRegisterError",e),r(e)}))})):new Promise((function(e,t){t(new Error("Service worker is not supported"))}))},unregister:function(e){var t,n=this;return"serviceWorker"in window.navigator&&n.serviceWorker.container?(t=e?Array.isArray(e)?e:[e]:b.registrations,Promise.all(t.map((function(e){return new Promise((function(t,o){e.unregister().then((function(){b.registrations.indexOf(e)>=0&&b.registrations.splice(b.registrations.indexOf(e),1),n.emit("serviceWorkerUnregisterSuccess",e),t()})).catch((function(t){n.emit("serviceWorkerUnregisterError",e,t),o(t)}))}))})))):new Promise((function(e,t){t(new Error("Service worker is not supported"))}))}},k={name:"sw",params:{serviceWorker:{path:void 0,scope:void 0}},create:function(){var e=this;$.extend(e,{serviceWorker:{container:"serviceWorker"in window.navigator?window.navigator.serviceWorker:void 0,registrations:b.registrations,register:b.register.bind(e),unregister:b.unregister.bind(e)}})},on:{init:function(){if("serviceWorker"in window.navigator){var e=this;if(e.serviceWorker.container){var t=e.params.serviceWorker.path,n=e.params.serviceWorker.scope;!t||Array.isArray(t)&&!t.length||(Array.isArray(t)?t:[t]).forEach((function(t){e.serviceWorker.register(t,n)}))}}}}},C=$.support,x=$.device,E=function(e){function t(t){var n;n=e.call(this,t)||this;var o=$.extend({},t),r=c(n);r.device=x,r.support=C;var a={version:"0.0.1",root:"body",theme:"auto",language:window.navigator.language,routes:[],lazyModulesPath:null,initOnDeviceReady:!0,autoDarkTheme:!1,iosTranslucentBars:!0,iosTranslucentModals:!0,component:void 0,componentUrl:void 0};r.useModulesParams(a),r.params=$.extend(a,t);var i=$(r.params.root);$.extend(r,{owner:r.params.owner,name:r.params.name,id:r.params.owner+"."+r.params.name,version:r.params.version,routes:r.params.routes,language:r.params.language,root:i,$el:i,cfg:r.params.cfg,api:r.params.api,rtl:"rtl"===i.css("direction"),theme:"auto"===r.params.theme?x.ios?"ios":x.desktop?"aurora":"md":r.params.theme,passedParams:o,online:window.navigator.onLine}),r.root&&r.root[0]&&(r.root[0].wia=r),r.touchEvents={start:C.touch?"touchstart":C.pointerEvents?"pointerdown":"mousedown",move:C.touch?"touchmove":C.pointerEvents?"pointermove":"mousemove",end:C.touch?"touchend":C.pointerEvents?"pointerup":"mouseup"},r.useModules(),r.initData();var s="(prefers-color-scheme: dark)",u="(prefers-color-scheme: light)";return r.mq={},window.matchMedia&&(r.mq.dark=window.matchMedia(s),r.mq.light=window.matchMedia(u)),r.colorSchemeListener=function(e){var t=e.matches,n=e.media;if(t){var o=document.querySelector("html");n===s?o.classList.add("theme-dark"):n===u&&o.classList.remove("theme-dark")}},r.params.init&&(x.cordova&&r.params.initOnDeviceReady?$(document).on("deviceready",(function(){r.init()})):r.init()),r||c(n)}r(t,e);var n=t.prototype;return n.load=function(e){this.emit("local::load appLoad",e)},n.show=function(e,t){this.emit("local::show appShow",e,t)},n.hide=function(){this.emit("local::hide appHide")},n.unload=function(){this.emit("local::unload appUnload")},n.initData=function(){var e=this;e.data={},e.params.data&&"function"==typeof e.params.data?$.extend(e.data,e.params.data.bind(e)()):e.params.data&&$.extend(e.data,e.params.data),e.methods={},e.params.methods&&Object.keys(e.params.methods).forEach((function(t){"function"==typeof e.params.methods[t]?e.methods[t]=e.params.methods[t].bind(e):e.methods[t]=e.params.methods[t]}))},n.enableAutoDarkTheme=function(){if(window.matchMedia){var e=this,t=document.querySelector("html");e.mq.dark&&e.mq.light&&(e.mq.dark.addListener(e.colorSchemeListener),e.mq.light.addListener(e.colorSchemeListener)),e.mq.dark&&e.mq.dark.matches?t.classList.add("theme-dark"):e.mq.light&&e.mq.light.matches&&t.classList.remove("theme-dark")}},n.disableAutoDarkTheme=function(){if(window.matchMedia){var e=this;e.mq.dark&&e.mq.dark.removeListener(e.colorSchemeListener),e.mq.light&&e.mq.light.removeListener(e.colorSchemeListener)}},n.init=function(){var e,n,o,r=this;return r.initialized||($.App=t,x.ios&&x.webView&&window.addEventListener("touchstart",(function(){})),r.root.addClass("framework7-initializing"),r.rtl&&$("html").attr("dir","rtl"),r.params.autoDarkTheme&&r.enableAutoDarkTheme(),window.addEventListener("offline",(function(){r.online=!1,r.emit("offline"),r.emit("connection",!1)})),window.addEventListener("online",(function(){r.online=!0,r.emit("online"),r.emit("connection",!0)})),r.root.addClass("framework7-root"),$("html").removeClass("ios md aurora").addClass(r.theme),r.params.iosTranslucentBars&&"ios"===r.theme&&x.ios&&$("html").addClass("ios-translucent-bars"),r.params.iosTranslucentModals&&"ios"===r.theme&&x.ios&&$("html").addClass("ios-translucent-modals"),$.nextFrame((function(){r.root.removeClass("framework7-initializing")})),e=[],n=document.querySelector("html"),o=document.querySelector('meta[name="apple-mobile-web-app-status-bar-style"]'),n&&(x.standalone&&x.ios&&o&&"black-translucent"===o.content&&e.push("device-full-viewport"),e.push("device-pixel-ratio-"+Math.floor(x.pixelRatio)),x.os&&!x.desktop?e.push("device-"+x.os):x.desktop&&(e.push("device-desktop"),x.os&&e.push("device-"+x.os)),(x.cordova||x.phonegap)&&e.push("device-cordova"),e.forEach((function(e){n.classList.add(e)}))),r.initialized=!0,r.emit("init")),r},n.loadModule=function(e){t.loadModule(e),this[e.name].init&&this[e.name].init()},n.loadModules=function(){return t.loadModules.apply(t,arguments)},n.getVnodeHooks=function(e,t){var n=this;return n.vnodeHooks&&n.vnodeHooks[e]&&n.vnodeHooks[e][t]||[]},o(t,[{key:"$",get:function(){return $}}],[{key:"Dom",get:function(){return $}},{key:"$",get:function(){return $}},{key:"Module",get:function(){return f}},{key:"Event",get:function(){return d}}]),t}(f);E.apps={},E.ModalMethods=m,E.ConstructorMethods=p,E.loadModule=v,E.loadModules=function(e){return Promise.all(e.map((function(e){return E.loadModule(e)})))},E.support=C,E.device=x,E.utils=l,E.use([y,w,k]);var M,L,O,A,j={normal:"nor",retina:"ret",srcset:"set",threshold:0},T=window.innerHeight,P=S(),q=document.body.classList.contains("srcset")||"srcset"in document.createElement("img"),H=window.devicePixelRatio||window.screen.deviceXDPI/window.screen.logicalXDPI,R=function(){function e(e){M=$.assign({},j,e)}var t=e.prototype;return t.start=function(e){return["scroll","resize"].forEach((function(t){return e.addEventListener(t,W)})),A=e,this},t.stop=function(){return["scroll","resize"].forEach((function(e){return A.removeEventListener(e,W)})),this},t.update=function(){setTimeout((function(){_(),D()}),1)},e}();function S(){return window.scrollY||window.pageYOffset}function W(){P=S(),L||(window.requestAnimationFrame((function(){return D()})),L=!0)}function z(e){var t=P,n=t+T,o=function(e){return e.getBoundingClientRect().top+P}(e),r=o+e.offsetHeight,a=M.threshold/100*T;return r>=t-a&&o<=n+a}function D(){if(O)return T=window.innerHeight,O.forEach((function(e){return z(e)&&function(e){if($.emit("lazy:src:before",e),q&&e.hasAttribute(M.srcset))e.setAttribute("srcset",e.getAttribute(M.srcset));else{var t=H>1&&e.getAttribute(M.retina)||e.getAttribute(M.normal);e.setAttribute("src",t),console.log("set src:"+t)}$.emit("lazy:src:after",e),[M.normal,M.retina,M.srcset].forEach((function(t){return e.removeAttribute(t)})),_()}(e)})),L=!1,this}function _(e){return O=e?Array.prototype.slice.call(e.querySelectorAll("["+M.normal+"]")):Array.prototype.slice.call(document.querySelectorAll("["+M.normal+"]")),this}var B=function(e){function t(t,n,o,r){var a;return(a=e.call(this,null,[t])||this).app=t,a.cfg=t.cfg,a.name=n,a.title=o,a.style=r||"./page/"+n+".css",a.path=""+n,a.view=null,a.el=null,a.$el=null,a.html="",a.css="",a.js="",a.data={},a.param={},a}r(t,e);var n=t.prototype;return n.load=function(e){this.emit("local::load pageLoad",e)},n.ready=function(e,t,n){this.init(),this.emit("local::ready pageReady",e,t,n)},n.init=function(e){var t=this.view,n=(e=e?$(e):t).qus("[name]");null==n||n.forEach((function(e){var n=$(e),o=n.attr("name");t[o]&&t[o].dom===e||(t[o]=n)})),e.qus("[name$=-tp]").hide(),e.qus('a[href=""]').attr("href","javascript:;")},n.show=function(e,t){e.qus("[name$=-tp]").hide(),e.qus('a[href=""]').attr("href","javascript:;"),this.reset&&this.reset(),this.emit("local::show pageShow",e,t)},n.back=function(e,t){e.qus("[name$=-tp]").hide(),e.qus('a[href=""]').attr("href","javascript:;"),this.emit("local::back pageBack",e,t)},n.hide=function(e){this.emit("local::hide pageHide",e)},t}(d),F=[],U=[],I=function(e){function t(t,n){var o,r=c(o=e.call(this,n,[t])||this);return r.params=l.extend({},n),r.opened=!1,c(o)||c(o)}r(t,e);var n=t.prototype;return n.onOpen=function(){var e=this;e.opened=!0,F.push(e),$("html").addClass("with-modal-"+e.type.toLowerCase()),e.$el.trigger("modal:open "+e.type.toLowerCase()+":open"),e.emit("local::open modalOpen "+e.type+"Open",e)},n.onOpened=function(){var e=this;e.$el.trigger("modal:opened "+e.type.toLowerCase()+":opened"),e.emit("local::opened modalOpened "+e.type+"Opened",e)},n.onClose=function(){var e=this;e.opened=!1,e.type&&e.$el&&(F.splice(F.indexOf(e),1),$("html").removeClass("with-modal-"+e.type.toLowerCase()),e.$el.trigger("modal:close "+e.type.toLowerCase()+":close"),e.emit("local::close modalClose "+e.type+"Close",e))},n.onClosed=function(){var e=this;e.type&&e.$el&&(e.$el.removeClass("modal-out"),e.$el.hide(),e.$el.trigger("modal:closed "+e.type.toLowerCase()+":closed"),e.emit("local::closed modalClosed "+e.type+"Closed",e))},n.open=function(e){var t,n=this,o=n.app,r=n.$el,a=n.type,i=n.$backdropEl,s=n.params.moveToRoot,c=!0;if(void 0!==e?c=e:void 0!==n.params.animate&&(c=n.params.animate),!r||r.hasClass("modal-in"))return n;if("dialog"===a&&o.params.modal.queueDialogs&&($(".dialog.modal-in").length>0?t=!0:F.length>0&&F.forEach((function(e){"dialog"===e.type&&(t=!0)})),t))return U.push(n),n;var u=r.parent(),l=r.parents(document).length>0;function d(){r.hasClass("modal-out")?n.onClosed():r.hasClass("modal-in")&&n.onOpened()}return s&&o.params.modal.moveToRoot&&!u.is(o.root)&&(o.root.append(r),n.once(a+"Closed",(function(){l?u.append(r):r.remove()}))),r.show(),n._clientLeft=r[0].clientLeft,c?(i&&(i.removeClass("not-animated"),i.addClass("backdrop-in")),r.animationEnd((function(){d()})),r.transitionEnd((function(){d()})),r.removeClass("modal-out not-animated").addClass("modal-in"),n.onOpen()):(i&&i.addClass("backdrop-in not-animated"),r.removeClass("modal-out").addClass("modal-in not-animated"),n.onOpen(),n.onOpened()),n},n.close=function(e){var t=this,n=t.$el,o=t.$backdropEl,r=!0;if(void 0!==e?r=e:void 0!==t.params.animate&&(r=t.params.animate),!n||!n.hasClass("modal-in"))return U.indexOf(t)>=0&&U.splice(U.indexOf(t),1),t;if(o){var a=!0;"popup"===t.type&&t.$el.prevAll(".popup.modal-in").each((function(e,n){var o=n.f7Modal;o&&o.params.closeByBackdropClick&&o.params.backdrop&&o.backdropEl===t.backdropEl&&(a=!1)})),a&&(o[r?"removeClass":"addClass"]("not-animated"),o.removeClass("backdrop-in"))}function i(){n.hasClass("modal-out")?t.onClosed():n.hasClass("modal-in")&&t.onOpened()}return n[r?"removeClass":"addClass"]("not-animated"),r?(n.animationEnd((function(){i()})),n.transitionEnd((function(){i()})),n.removeClass("modal-in").addClass("modal-out"),t.onClose()):(n.addClass("not-animated").removeClass("modal-in").addClass("modal-out"),t.onClose(),t.onClosed()),"dialog"===t.type&&0!==U.length&&U.shift().open(),t},n.destroy=function(){var e=this;e.destroyed||(e.emit("local::beforeDestroy modalBeforeDestroy "+e.type+"BeforeDestroy",e),e.$el&&(e.$el.trigger("modal:beforedestroy "+e.type.toLowerCase()+":beforedestroy"),e.$el.length&&e.$el[0].f7Modal&&delete e.$el[0].f7Modal),l.deleteProps(e),e.destroyed=!0)},t}(d),X=$.support,N=$.device;e.Ajax=t,e.App=E,e.Constructors=p,e.Device=N,e.Event=d,e.Lazy=R,e.Modal=I,e.Modals=m,e.Module=f,e.Page=B,e.Resize=y,e.SW=k,e.Support=X,e.Utils=l,e.jsx=function(e,t){for(var n=t||{},o=arguments.length,r=new Array(o>2?o-2:0),a=2;a<o;a++)r[a-2]=arguments[a];var i=r||[],s=Object.keys(n).map((function(e){return"_"===e[0]?n[e]?e.replace("_",""):"":e+'="'+n[e]+'"'})).filter((function(e){return!!e})).join(" ");if(["path","img","circle","polygon","line","input"].indexOf(e)>=0)return("<"+e+" "+s+" />").trim();var c=i.filter((function(e){return!!e})).map((function(e){return Array.isArray(e)?e.join(""):e})).join("");return("<"+e+" "+s+">"+c+"</"+e+">").trim()},e.loadModule=v,Object.defineProperty(e,"__esModule",{value:!0})},"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self)["@wiajs/Core"]={});
|
|
6
|
+
/*!
|
|
7
|
+
* wia core v1.0.1
|
|
8
|
+
* (c) 2015-2023 Sibyl Yu and contributors
|
|
9
|
+
* Released under the MIT License.
|
|
10
|
+
*/
|
|
11
|
+
var e,t;e=this,t=function(e){"use strict";var t=function(){function e(){}var t=e.prototype;return t.post=function(e,t){return new Promise((function(n,o){var r=$.getXhr();r.onreadystatechange=function(){4===r.readyState&&(200===r.status?n(r.responseText):o(new Error(r.statusText),r.responseText))},r.open("POST",e,!0);var i=t;"object"==typeof t&&(i=function(e){var t=[];for(var n in e)e.hasOwnProperty(n)&&t.push(n+"="+e[n]);return t.sort().join("&")}(t)),r.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),r.send(i)}))},t.postForm=function(e,t){return new Promise((function(n,o){var r=$.getXhr();r.onreadystatechange=function(){4===r.readyState&&(200===r.status?n(null,r.responseText):o(new Error(r.status),r.responseText))},r.open("POST",e,!0),r.send(t)}))},t.get=function(e,t){return $.get(e,t)},e}();function n(e){return n="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},n(e)}function o(e){var t=function(e,t){if("object"!==n(e)||null===e)return e;var o=e[Symbol.toPrimitive];if(void 0!==o){var r=o.call(e,t||"default");if("object"!==n(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"===n(t)?t:String(t)}function r(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,o(r.key),r)}}function i(e,t,n){return t&&r(e.prototype,t),n&&r(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e}function a(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function s(e,t){return s=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},s(e,t)}function c(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,s(e,t)}var u=1,l={uniqueNumber:function(){return u+=1},id:function(e,t){return void 0===e&&(e="xxxxxxxxxx"),void 0===t&&(t="0123456789abcdef"),$.uid(e,t)},mdPreloaderContent:'\n\t\t<span class="preloader-inner">\n\t\t\t<svg viewBox="0 0 36 36">\n\t\t\t\t<circle cx="18" cy="18" r="16"></circle>\n\t\t\t</svg>\n </span>\n '.trim(),iosPreloaderContent:('\n\t\t<span class="preloader-inner">\n\t\t\t'+[0,1,2,3,4,5,6,7].map((function(){return'<span class="preloader-inner-line"></span>'})).join("")+"\n\t\t</span>\n ").trim(),auroraPreloaderContent:'\n <span class="preloader-inner">\n <span class="preloader-inner-circle"></span>\n </span>\n',eventNameToColonCase:function(e){var t;return e.split("").map((function(e,n){return e.match(/[A-Z]/)&&0!==n&&!t?(t=!0,":"+e.toLowerCase()):e.toLowerCase()})).join("")},deleteProps:function(e){$.deleteProps(e)},nextTick:function(e,t){return void 0===t&&(t=0),setTimeout(e,t)},nextFrame:function(e){return $.nextFrame(e)},now:function(){return Date.now()},requestAnimationFrame:function(e){return $.requestAnimationFrame(e)},cancelAnimationFrame:function(e){return $.cancelAnimationFrame(e)},parseUrlQuery:function(e){return $.urlParam(e)},getTranslate:function(e,t){return void 0===t&&(t="x"),$.getTranslate(e,t)},serializeObject:function(e,t){if(void 0===t&&(t=[]),"string"==typeof e)return e;var n,o=[];function r(e){if(t.length>0){for(var n="",o=0;o<t.length;o+=1)n+=0===o?t[o]:"["+encodeURIComponent(t[o])+"]";return n+"["+encodeURIComponent(e)+"]"}return encodeURIComponent(e)}function i(e){return encodeURIComponent(e)}return Object.keys(e).forEach((function(a){var s;if(Array.isArray(e[a])){s=[];for(var c=0;c<e[a].length;c+=1)Array.isArray(e[a][c])||"object"!=typeof e[a][c]?s.push(r(a)+"[]="+i(e[a][c])):((n=t.slice()).push(a),n.push(String(c)),s.push(l.serializeObject(e[a][c],n)));s.length>0&&o.push(s.join("&"))}else null===e[a]||""===e[a]?o.push(r(a)+"="):"object"==typeof e[a]?((n=t.slice()).push(a),""!==(s=l.serializeObject(e[a],n))&&o.push(s)):void 0!==e[a]&&""!==e[a]?o.push(r(a)+"="+i(e[a])):""===e[a]&&o.push(r(a))})),o.join("&")},isObject:function(e){return"object"==typeof e&&null!==e&&e.constructor&&e.constructor===Object},merge:function(){var e;return(e=$).merge.apply(e,arguments)},extend:function(){for(var e,t=arguments.length,n=new Array(t),o=0;o<t;o++)n[o]=arguments[o];var r=n[0];return n.splice(0,1),(e=$).assign.apply(e,[r].concat(n))},bindMethods:function(e,t){var n=this;Object.keys(t).forEach((function(o){n.isObject(t[o])&&Object.keys(t[o]).forEach((function(n){"function"==typeof t[o][n]&&(t[o][n]=t[o][n].bind(e))})),e[o]=t[o]}))},colorHexToRgb:function(e){var t=e.replace(/^#?([a-f\d])([a-f\d])([a-f\d])$/i,(function(e,t,n,o){return t+t+n+n+o+o})),n=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(t);return n?n.slice(1).map((function(e){return parseInt(e,16)})):null},colorRgbToHex:function(e,t,n){return"#"+[e,t,n].map((function(e){var t=e.toString(16);return 1===t.length?"0"+t:t})).join("")},colorRgbToHsl:function(e,t,n){e/=255,t/=255,n/=255;var o,r=Math.max(e,t,n),i=Math.min(e,t,n),a=r-i;0===a?o=0:r===e?o=(t-n)/a%6:r===t?o=(n-e)/a+2:r===n&&(o=(e-t)/a+4);var s=(i+r)/2;return o<0&&(o=6+o),[60*o,0===a?0:a/(1-Math.abs(2*s-1)),s]},colorHslToRgb:function(e,t,n){var o,r=(1-Math.abs(2*n-1))*t,i=e/60,a=r*(1-Math.abs(i%2-1));Number.isNaN(e)||void 0===e?o=[0,0,0]:i<=1?o=[r,a,0]:i<=2?o=[a,r,0]:i<=3?o=[0,r,a]:i<=4?o=[0,a,r]:i<=5?o=[a,0,r]:i<=6&&(o=[r,0,a]);var s=n-r/2;return o.map((function(e){return Math.max(0,Math.min(255,Math.round(255*(e+s))))}))},colorHsbToHsl:function(e,t,n){var o={h:e,s:0,l:0},r=t,i=n;return o.l=(2-r)*i/2,o.s=o.l&&o.l<1?r*i/(o.l<.5?2*o.l:2-2*o.l):o.s,[o.h,o.s,o.l]},colorHslToHsb:function(e,t,n){var o={h:e,s:0,b:0},r=n,i=t*(r<.5?r:1-r);return o.b=r+i,o.s=r>0?2*i/o.b:o.s,[o.h,o.s,o.b]},colorThemeCSSProperties:function(){for(var e,t,n=arguments.length,o=new Array(n),r=0;r<n;r++)o[r]=arguments[r];if(1===o.length?(e=o[0],t=l.colorHexToRgb(e)):3===o.length&&(t=o,e=l.colorRgbToHex.apply(l,t)),!t)return{};var i=l.colorRgbToHsl.apply(l,t),a=[i[0],i[1],Math.max(0,i[2]-.08)],s=[i[0],i[1],Math.max(0,i[2]+.08)],c=l.colorRgbToHex.apply(l,l.colorHslToRgb.apply(l,a)),u=l.colorRgbToHex.apply(l,l.colorHslToRgb.apply(l,s));return{"--f7-theme-color":e,"--f7-theme-color-rgb":t.join(", "),"--f7-theme-color-shade":c,"--f7-theme-color-tint":u}}},d=function(){function e(e,t,n){void 0===e&&(e={}),void 0===t&&(t=[]),void 0===n&&(n="");var o=this;o.params=e,t?Array.isArray(t)?o.eventsParents=t.filter((function(e){return e})):o.eventsParents=[t]:o.eventsParents=[],o.eventsListeners={},o.pre=n,o.params&&o.params.on&&Object.keys(o.params.on).forEach((function(e){o.on(e,o.params.on[e])}))}var t=e.prototype;return t.on=function(e,t,n){void 0===n&&(n=!1);var o=this;if("function"!=typeof t)return o;var r=n?"unshift":"push";return e.split(" ").forEach((function(e){var n={owner:"",appName:"",handler:t};if(e.includes("app::")){var i=null;if($.isPage(o)?i=o:$.isPage(null==o?void 0:o.page)?i=o.page:$.isPage(null==o?void 0:o.parent)&&(i=o.parent),i&&i.app&&$.isApp(i.app)){n.owner=i.owner,n.appName=i.appName;var a=i.app,s=e.replace("app::","");a.eventsListeners[s]||(a.eventsListeners[s]=[]),a.eventsListeners[s][r](n)}}else o.eventsListeners[e]||(o.eventsListeners[e]=[]),o.eventsListeners[e][r](n)})),o},t.once=function(e,t,n){void 0===n&&(n=!1);var o=this;if("function"!=typeof t)return o;function r(){if(o.off(e,r),r.proxy){for(var t=arguments.length,n=new Array(t),i=0;i<t;i++)n[i]=arguments[i];r.proxy.apply(o,n),delete r.proxy}}return r.proxy=t,o.on(e,r,n)},t.off=function(e,t){var n=this;return n.eventsListeners?(e?e.split(" ").forEach((function(e){if(void 0===t)n.eventsListeners[e]=[];else if(n.eventsListeners[e])for(var o=n.eventsListeners[e],r=o.length-1;r>=0;r--){var i,a=o[r];a.handler!==t&&(null==(i=a.handler)?void 0:i.proxy)!==t||o.splice(r,1)}})):n.eventsListeners={},n):n},t.emit=function(){var e,t,n,o,r,i=this;if(!i.eventsListeners)return i;for(var a=!1,s=arguments.length,c=new Array(s),u=0;u<s;u++)c[u]=arguments[u];var l=c[0];if(!l)return i;"string"==typeof l||Array.isArray(l)?(l=l.split(" "),i.pre?(t=[],l.forEach((function(e){t.push("."+e),t.push(""+i.pre+e[0].toUpperCase()+e.substr(1))}))):t=l,n=c.slice(1,c.length),o=i,r=i.eventsParents):(a=l.pop,t=l.events,n=l.data,o=l.context||i,r=l.local?[]:l.parents||i.eventsParents);var d=Array.isArray(t)?t:t.split(" "),p=d.map((function(e){return e.replace(/local::|^[.]/,"")})),f=null;if(a)f=l;else{var m=d.filter((function(e){return!e.match(/^local::|^[.]/)}));null!=m&&m.length&&(f={pop:!0,events:m,context:i,data:n,owner:"",appName:""})}return f&&$.isPage(i)&&(f.owner=null==i?void 0:i.owner,f.appName=null==i?void 0:i.appName),p.forEach((function(e){if(i.eventsListeners&&i.eventsListeners[e]){var t=[];i.eventsListeners[e].forEach((function(n){n.owner&&n.appName?a&&n.owner===e.owner&&n.appName===e.appName&&t.push(n.handler):t.push(n.handler)})),t.forEach((function(e){e.apply(o,n)}))}})),f&&(null==(e=r)?void 0:e.length)>0&&r.forEach((function(e){return e.emit(f)})),i},e}(),p=function(e){function t(t,n,o,r){var i;return(i=e.call(this,null,[t])||this).app=t,i.cfg=t.cfg,i.name=n,i.title=o,i.style=r||"./page/"+n+".css",i.owner="",i.appName="",i.path="",i.view=null,i.dom=null,i.$el=null,i.el=null,i.html="",i.css="",i.js="",i.data={},i.param={},i}c(t,e);var n=t.prototype;return n.load=function(e){this.emit("local::load pageLoad",e),this.emit("pageLoad",this)},n.ready=function(e,t,n){this.init(),this.emit("local::ready",e,t,n),this.emit("pageReady",this)},n.init=function(e){var t=this.view;e=e?$(e):t},n.show=function(e,t){e.qus("[name$=-tp]").hide(),e.qus('a[href=""]').attr("href","javascript:;"),this.reset&&this.reset(),this.emit("local::show",e,t),this.emit("pageShow",this)},n.back=function(e,t){e.qus("[name$=-tp]").hide(),e.qus('a[href=""]').attr("href","javascript:;"),this.emit("local::back",e,t),this.emit("pageBack",this)},n.hide=function(e){this.emit("local::hide",e),this.emit("pageHide",this)},n.unload=function(e){this.emit("local::unload",e),this.emit("pageUnload",this)},t}(d),f=function(e){function t(t,n){return void 0===t&&(t={}),void 0===n&&(n=[]),e.call(this,t,n)||this}c(t,e);var n=t.prototype;return n.useModuleParams=function(e,t){if(e.params){var n={};Object.keys(e.params).forEach((function(e){void 0!==t[e]&&(n[e]=$.extend({},t[e]))})),$.extend(t,e.params),Object.keys(n).forEach((function(e){$.extend(t[e],n[e])}))}},n.useModulesParams=function(e){var t=this;t.modules&&Object.keys(t.modules).forEach((function(n){var o=t.modules[n];o.params&&$.extend(e,o.params)}))},n.useModule=function(e,t){void 0===e&&(e=""),void 0===t&&(t={});var n=this;if(n.modules){var o="string"==typeof e?n.modules[e]:e;o&&(o.instance&&Object.keys(o.instance).forEach((function(e){var t=o.instance[e];n[e]="function"==typeof t?t.bind(n):t})),o.on&&n.on&&Object.keys(o.on).forEach((function(e){n.on(e,o.on[e])})),o.vnode&&(n.vnodeHooks||(n.vnodeHooks={}),Object.keys(o.vnode).forEach((function(e){Object.keys(o.vnode[e]).forEach((function(t){var r=o.vnode[e][t];n.vnodeHooks[t]||(n.vnodeHooks[t]={}),n.vnodeHooks[t][e]||(n.vnodeHooks[t][e]=[]),n.vnodeHooks[t][e].push(r.bind(n))}))}))),o.create&&o.create.bind(n)(t))}},n.useModules=function(e){void 0===e&&(e={});var t=this;t.modules&&Object.keys(t.modules).forEach((function(n){var o=e[n]||{};t.useModule(n,o)}))},t.installModule=function(e){var t=this;t.prototype.modules||(t.prototype.modules={});var n=e.name||Object.keys(t.prototype.modules).length+"_"+$.now();if(t.prototype.modules[n]=e,e.proto&&Object.keys(e.proto).forEach((function(n){t.prototype[n]=e.proto[n]})),e.static&&Object.keys(e.static).forEach((function(n){t[n]=e.static[n]})),e.install){for(var o=arguments.length,r=new Array(o>1?o-1:0),i=1;i<o;i++)r[i-1]=arguments[i];e.install.apply(t,r)}return t},t.use=function(e){var t=this;if(Array.isArray(e))return e.forEach((function(e){return t.installModule(e)})),t;for(var n=arguments.length,o=new Array(n>1?n-1:0),r=1;r<n;r++)o[r-1]=arguments[r];return t.installModule.apply(t,[e].concat(o))},i(t,null,[{key:"components",set:function(e){this.use&&this.use(e)}}]),t}(d);function m(e,t,n){return m=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}()?Reflect.construct.bind():function(e,t,n){var o=[null];o.push.apply(o,t);var r=new(Function.bind.apply(e,o));return n&&s(r,n.prototype),r},m.apply(null,arguments)}function h(e){void 0===e&&(e={});var t=e,n=t.defaultSelector,o=t.constructor,r=t.domProp,i=t.app,a=t.addMethods,s={create:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return m(o,i?[i].concat(t):t)},get:function(e){if(void 0===e&&(e=n),e instanceof o)return e;var t=$(e);return 0!==t.length?t[0][r]:void 0},destroy:function(e){var t=s.get(e);if(t&&t.destroy)return t.destroy()}};return a&&Array.isArray(a)&&a.forEach((function(e){s[e]=function(t){void 0===t&&(t=n);for(var o=s.get(t),r=arguments.length,i=new Array(r>1?r-1:0),a=1;a<r;a++)i[a-1]=arguments[a];if(o&&o[e])return o[e].apply(o,i)}})),s}function v(e){void 0===e&&(e={});var t=e,n=t.defaultSelector,o=t.constructor,r=t.app;return $.extend(h({defaultSelector:n,constructor:o,app:r,domProp:"f7Modal"}),{open:function(e,t){var n=$(e),i=n[0].f7Modal;return i||(i=new o(r,{el:n})),i.open(t)},close:function(e,t){void 0===e&&(e=n);var i=$(e);if(0!==i.length){var a=i[0].f7Modal;return a||(a=new o(r,{el:i})),a.close(t)}}})}var y=[];function g(e){var t=this;return new Promise((function(n,o){var r,i,a,s=t.instance;if(e){if("string"==typeof e){var c=e.match(/([a-z0-9-]*)/i);if(e.indexOf(".")<0&&c&&c[0].length===e.length){if(!s||s&&!s.params.lazyModulesPath)return void o(new Error('Wia: "lazyModulesPath" app parameter must be specified to fetch module by name'));r=s.params.lazyModulesPath+"/"+e+".js"}else r=e}else"function"==typeof e?a=e:i=e;if(a){var u=a(t,!1);if(!u)return void o(new Error("Wia: Can't find Wia component in specified component function"));if(t.prototype.modules&&t.prototype.modules[u.name])return void n();f(u),n()}if(i){var l=i;if(!l)return void o(new Error("Wia: Can't find Wia component in specified component"));if(t.prototype.modules&&t.prototype.modules[l.name])return void n();f(l),n()}if(r){if(y.indexOf(r)>=0)return void n();y.push(r);var d=new Promise((function(e,n){t.request.get(r,(function(o){var i="wia_component_loader_callback_"+$.id(),a=document.createElement("script");a.innerHTML="window."+i+" = function (Wia, WiaAutoInstallComponent) {return "+o.trim()+"}",$("head").append(a);var s=window[i];delete window[i],$(a).remove();var c=s(t,!1);c?(t.prototype.modules&&t.prototype.modules[c.name]||f(c),e()):n(new Error("Wia: Can't find Wia component in "+r+" file"))}),(function(e,t){n(e,t)}))})),p=new Promise((function(e){t.request.get(r.replace(".js",s.rtl?".rtl.css":".css"),(function(t){var n=document.createElement("style");n.innerHTML=t,$("head").append(n),e()}),(function(){e()}))}));Promise.all([d,p]).then((function(){n()})).catch((function(e){o(e)}))}}else o(new Error("Wia: Lazy module must be specified"));function f(e){t.use(e),s&&(s.useModuleParams(e,s.params),s.useModule(e))}}))}var w={name:"resize",instance:{getSize:function(){var e=this;if(!e.root[0])return{width:0,height:0,left:0,top:0};var t=e.root.offset(),n=[e.root[0].offsetWidth,e.root[0].offsetHeight,t.left,t.top],o=n[0],r=n[1],i=n[2],a=n[3];return e.width=o,e.height=r,e.left=i,e.top=a,{width:o,height:r,left:i,top:a}}},on:{init:function(){var e=this;e.getSize(),window.addEventListener("resize",(function(){e.emit("resize")}),!1),window.addEventListener("orientationchange",(function(){e.emit("orientationchange")}))},orientationchange:function(){this.device.ipad&&(document.body.scrollLeft=0,setTimeout((function(){document.body.scrollLeft=0}),0))},resize:function(){this.getSize()}}};function b(e){var t,n,o;t=function(t){e.emit({events:"click",data:[t]})},$.support.touch?(document.addEventListener("touchstart",(function(e){n=e.changedTouches[0].clientX,o=e.changedTouches[0].clientY}),!0),document.addEventListener("touchend",(function(e){var r=Math.abs(e.changedTouches[0].clientX-n),i=Math.abs(e.changedTouches[0].clientY-o);r<=5&&i<=5&&t.call(this,e)}),!0)):document.addEventListener("click",t,!0),e.on("click",(function(t){var n=$(t.target),o=n.closest("a");o.length>0&&o.attr("href"),Object.keys(e.modules).forEach((function(o){var r=e.modules[o].clicks;r&&(t.preventF7Router||Object.keys(r).forEach((function(o){var i=n.closest(o).eq(0);i.length>0&&r[o].call(e,i,i.dataset(),t)})))}))}))}var k={name:"clicks",params:{clicks:{externalLinks:".ext"}},on:{init:function(){b(this)}}},C={registrations:[],register:function(e,t){var n=this;return"serviceWorker"in window.navigator&&n.serviceWorker.container?new Promise((function(o,r){n.serviceWorker.container.register(e,t?{scope:t}:{}).then((function(e){C.registrations.push(e),n.emit("serviceWorkerRegisterSuccess",e),o(e)})).catch((function(e){n.emit("serviceWorkerRegisterError",e),r(e)}))})):new Promise((function(e,t){t(new Error("Service worker is not supported"))}))},unregister:function(e){var t,n=this;return"serviceWorker"in window.navigator&&n.serviceWorker.container?(t=e?Array.isArray(e)?e:[e]:C.registrations,Promise.all(t.map((function(e){return new Promise((function(t,o){e.unregister().then((function(){C.registrations.indexOf(e)>=0&&C.registrations.splice(C.registrations.indexOf(e),1),n.emit("serviceWorkerUnregisterSuccess",e),t()})).catch((function(t){n.emit("serviceWorkerUnregisterError",e,t),o(t)}))}))})))):new Promise((function(e,t){t(new Error("Service worker is not supported"))}))}},x={name:"sw",params:{serviceWorker:{path:void 0,scope:void 0}},create:function(){var e=this;$.extend(e,{serviceWorker:{container:"serviceWorker"in window.navigator?window.navigator.serviceWorker:void 0,registrations:C.registrations,register:C.register.bind(e),unregister:C.unregister.bind(e)}})},on:{init:function(){if("serviceWorker"in window.navigator){var e=this;if(e.serviceWorker.container){var t=e.params.serviceWorker.path,n=e.params.serviceWorker.scope;!t||Array.isArray(t)&&!t.length||(Array.isArray(t)?t:[t]).forEach((function(t){e.serviceWorker.register(t,n)}))}}}}},E=$.support,L=$.device,M=function(e){function t(n){var o;o=e.call(this,n)||this;var r=$.extend({},n),i=a(o);i.device=L,i.support=E,console.log("App constructor",{Device:L,Support:E});var s={version:"0.0.1",root:"body",theme:"auto",language:window.navigator.language,routes:[],lazyModulesPath:null,initOnDeviceReady:!0,autoDarkTheme:!1,iosTranslucentBars:!0,iosTranslucentModals:!0,component:void 0,componentUrl:void 0};i.useModulesParams(s),i.params=$.extend(s,n);var c=$(i.params.root);$.isPage=function(e){return e instanceof p},$.isApp=function(e){return e instanceof t},$.extend(i,{owner:i.params.owner,name:i.params.name,id:i.params.owner+"."+i.params.name,version:i.params.version,routes:i.params.routes,language:i.params.language,root:c,$el:c,cfg:i.params.cfg,api:i.params.api,rtl:"rtl"===c.css("direction"),theme:"auto"===i.params.theme?L.ios?"ios":L.desktop?"aurora":"md":i.params.theme,passedParams:r,online:window.navigator.onLine}),i.root&&i.root[0]&&(i.root[0].wia=i),i.touchEvents={start:E.touch?"touchstart":E.pointerEvents?"pointerdown":"mousedown",move:E.touch?"touchmove":E.pointerEvents?"pointermove":"mousemove",end:E.touch?"touchend":E.pointerEvents?"pointerup":"mouseup"},i.useModules(),i.initData();var u="(prefers-color-scheme: dark)",l="(prefers-color-scheme: light)";return i.mq={},window.matchMedia&&(i.mq.dark=window.matchMedia(u),i.mq.light=window.matchMedia(l)),i.colorSchemeListener=function(e){var t=e.matches,n=e.media;if(t){var o=document.querySelector("html");n===u?o.classList.add("theme-dark"):n===l&&o.classList.remove("theme-dark")}},i.params.init&&(L.cordova&&i.params.initOnDeviceReady?$(document).on("deviceready",(function(){i.init()})):i.init()),i||a(o)}c(t,e);var n=t.prototype;return n.load=function(e){this.emit("local::load appLoad",e)},n.show=function(e,t){this.emit("local::show appShow",e,t)},n.hide=function(){this.emit("local::hide appHide")},n.unload=function(){this.emit("local::unload appUnload")},n.initData=function(){var e=this;e.data={},e.params.data&&"function"==typeof e.params.data?$.extend(e.data,e.params.data.bind(e)()):e.params.data&&$.extend(e.data,e.params.data),e.methods={},e.params.methods&&Object.keys(e.params.methods).forEach((function(t){"function"==typeof e.params.methods[t]?e.methods[t]=e.params.methods[t].bind(e):e.methods[t]=e.params.methods[t]}))},n.enableAutoDarkTheme=function(){if(window.matchMedia){var e=this,t=document.querySelector("html");e.mq.dark&&e.mq.light&&(e.mq.dark.addListener(e.colorSchemeListener),e.mq.light.addListener(e.colorSchemeListener)),e.mq.dark&&e.mq.dark.matches?t.classList.add("theme-dark"):e.mq.light&&e.mq.light.matches&&t.classList.remove("theme-dark")}},n.disableAutoDarkTheme=function(){if(window.matchMedia){var e=this;e.mq.dark&&e.mq.dark.removeListener(e.colorSchemeListener),e.mq.light&&e.mq.light.removeListener(e.colorSchemeListener)}},n.init=function(){var e,n,o,r=this;return r.initialized||($.App=t,L.ios&&L.webView&&window.addEventListener("touchstart",(function(){})),r.root.addClass("framework7-initializing"),r.rtl&&$("html").attr("dir","rtl"),r.params.autoDarkTheme&&r.enableAutoDarkTheme(),window.addEventListener("offline",(function(){r.online=!1,r.emit("offline"),r.emit("connection",!1)})),window.addEventListener("online",(function(){r.online=!0,r.emit("online"),r.emit("connection",!0)})),r.root.addClass("framework7-root"),$("html").removeClass("ios md aurora").addClass(r.theme),r.params.iosTranslucentBars&&"ios"===r.theme&&L.ios&&$("html").addClass("ios-translucent-bars"),r.params.iosTranslucentModals&&"ios"===r.theme&&L.ios&&$("html").addClass("ios-translucent-modals"),$.nextFrame((function(){r.root.removeClass("framework7-initializing")})),e=[],n=document.querySelector("html"),o=document.querySelector('meta[name="apple-mobile-web-app-status-bar-style"]'),n&&(L.standalone&&L.ios&&o&&"black-translucent"===o.content&&e.push("device-full-viewport"),e.push("device-pixel-ratio-"+Math.floor(L.pixelRatio)),L.os&&!L.desktop?e.push("device-"+L.os):L.desktop&&(e.push("device-desktop"),L.os&&e.push("device-"+L.os)),(L.cordova||L.phonegap)&&e.push("device-cordova"),e.forEach((function(e){n.classList.add(e)}))),r.initialized=!0,r.emit("init")),r},n.loadModule=function(e){t.loadModule(e),this[e.name].init&&this[e.name].init()},n.loadModules=function(){return t.loadModules.apply(t,arguments)},n.getVnodeHooks=function(e,t){var n=this;return n.vnodeHooks&&n.vnodeHooks[e]&&n.vnodeHooks[e][t]||[]},i(t,[{key:"$",get:function(){return $}}],[{key:"Dom",get:function(){return $}},{key:"$",get:function(){return $}},{key:"Module",get:function(){return f}},{key:"Event",get:function(){return d}}]),t}(f);M.apps={},M.ModalMethods=v,M.ConstructorMethods=h,M.loadModule=g,M.loadModules=function(e){return Promise.all(e.map((function(e){return M.loadModule(e)})))},M.support=E,M.device=L,M.utils=l,M.use([w,k,x]);var A,O,j,P,T={normal:"nor",retina:"ret",srcset:"set",threshold:0},S=window.innerHeight,H=z(),q=document.body.classList.contains("srcset")||"srcset"in document.createElement("img"),R=window.devicePixelRatio||window.screen.deviceXDPI/window.screen.logicalXDPI,W=function(){function e(e){A=$.assign({},T,e)}var t=e.prototype;return t.start=function(e){return["scroll","resize"].forEach((function(t){return e.addEventListener(t,D)})),P=e,this},t.stop=function(){return["scroll","resize"].forEach((function(e){return P.removeEventListener(e,D)})),this},t.update=function(){setTimeout((function(){_(),U()}),1)},e}();function z(){return window.scrollY||window.pageYOffset}function D(){H=z(),O||(window.requestAnimationFrame((function(){return U()})),O=!0)}function N(e){var t=H,n=t+S,o=function(e){return e.getBoundingClientRect().top+H}(e),r=o+e.offsetHeight,i=A.threshold/100*S;return r>=t-i&&o<=n+i}function U(){if(j)return S=window.innerHeight,j.forEach((function(e){return N(e)&&function(e){if($.emit("lazy:src:before",e),q&&e.hasAttribute(A.srcset))e.setAttribute("srcset",e.getAttribute(A.srcset));else{var t=R>1&&e.getAttribute(A.retina)||e.getAttribute(A.normal);e.setAttribute("src",t),console.log("set src:"+t)}$.emit("lazy:src:after",e),[A.normal,A.retina,A.srcset].forEach((function(t){return e.removeAttribute(t)})),_()}(e)})),O=!1,this}function _(e){return j=e?Array.prototype.slice.call(e.querySelectorAll("["+A.normal+"]")):Array.prototype.slice.call(document.querySelectorAll("["+A.normal+"]")),this}var B=[],F=[],I=function(e){function t(t,n){var o,r=a(o=e.call(this,n,[t])||this);return r.params=l.extend({},n),r.opened=!1,a(o)||a(o)}c(t,e);var n=t.prototype;return n.onOpen=function(){var e=this;e.opened=!0,B.push(e),$("html").addClass("with-modal-"+e.type.toLowerCase()),e.$el.trigger("modal:open "+e.type.toLowerCase()+":open"),e.emit("local::open modalOpen "+e.type+"Open",e)},n.onOpened=function(){var e=this;e.$el.trigger("modal:opened "+e.type.toLowerCase()+":opened"),e.emit("local::opened modalOpened "+e.type+"Opened",e)},n.onClose=function(){var e=this;e.opened=!1,e.type&&e.$el&&(B.splice(B.indexOf(e),1),$("html").removeClass("with-modal-"+e.type.toLowerCase()),e.$el.trigger("modal:close "+e.type.toLowerCase()+":close"),e.emit("local::close modalClose "+e.type+"Close",e))},n.onClosed=function(){var e=this;e.type&&e.$el&&(e.$el.removeClass("modal-out"),e.$el.hide(),e.$el.trigger("modal:closed "+e.type.toLowerCase()+":closed"),e.emit("local::closed modalClosed "+e.type+"Closed",e))},n.open=function(e){var t,n=this,o=n.app,r=n.$el,i=n.type,a=n.$backdropEl,s=n.params.moveToRoot,c=!0;if(void 0!==e?c=e:void 0!==n.params.animate&&(c=n.params.animate),!r||r.hasClass("modal-in"))return n;if("dialog"===i&&o.params.modal.queueDialogs&&($(".dialog.modal-in").length>0?t=!0:B.length>0&&B.forEach((function(e){"dialog"===e.type&&(t=!0)})),t))return F.push(n),n;var u=r.parent(),l=r.parents(document).length>0;function d(){r.hasClass("modal-out")?n.onClosed():r.hasClass("modal-in")&&n.onOpened()}return s&&o.params.modal.moveToRoot&&!u.is(o.root)&&(o.root.append(r),n.once(i+"Closed",(function(){l?u.append(r):r.remove()}))),r.show(),n._clientLeft=r[0].clientLeft,c?(a&&(a.removeClass("not-animated"),a.addClass("backdrop-in")),r.animationEnd((function(){d()})),r.transitionEnd((function(){d()})),r.removeClass("modal-out not-animated").addClass("modal-in"),n.onOpen()):(a&&a.addClass("backdrop-in not-animated"),r.removeClass("modal-out").addClass("modal-in not-animated"),n.onOpen(),n.onOpened()),n},n.close=function(e){var t=this,n=t.$el,o=t.$backdropEl,r=!0;if(void 0!==e?r=e:void 0!==t.params.animate&&(r=t.params.animate),!n||!n.hasClass("modal-in"))return F.indexOf(t)>=0&&F.splice(F.indexOf(t),1),t;if(o){var i=!0;"popup"===t.type&&t.$el.prevAll(".popup.modal-in").each((function(e,n){var o=n.f7Modal;o&&o.params.closeByBackdropClick&&o.params.backdrop&&o.backdropEl===t.backdropEl&&(i=!1)})),i&&(o[r?"removeClass":"addClass"]("not-animated"),o.removeClass("backdrop-in"))}function a(){n.hasClass("modal-out")?t.onClosed():n.hasClass("modal-in")&&t.onOpened()}return n[r?"removeClass":"addClass"]("not-animated"),r?(n.animationEnd((function(){a()})),n.transitionEnd((function(){a()})),n.removeClass("modal-in").addClass("modal-out"),t.onClose()):(n.addClass("not-animated").removeClass("modal-in").addClass("modal-out"),t.onClose(),t.onClosed()),"dialog"===t.type&&0!==F.length&&F.shift().open(),t},n.destroy=function(){var e=this;e.destroyed||(e.emit("local::beforeDestroy modalBeforeDestroy "+e.type+"BeforeDestroy",e),e.$el&&(e.$el.trigger("modal:beforedestroy "+e.type.toLowerCase()+":beforedestroy"),e.$el.length&&e.$el[0].f7Modal&&delete e.$el[0].f7Modal),l.deleteProps(e),e.destroyed=!0)},t}(d),X=$.support,Y=$.device;e.Ajax=t,e.App=M,e.Constructors=h,e.Device=Y,e.Event=d,e.Lazy=W,e.Modal=I,e.Modals=v,e.Module=f,e.Page=p,e.Resize=w,e.SW=x,e.Support=X,e.Utils=l,e.jsx=function(e,t){for(var n=t||{},o=arguments.length,r=new Array(o>2?o-2:0),i=2;i<o;i++)r[i-2]=arguments[i];var a=r||[],s=Object.keys(n).map((function(e){return"_"===e[0]?n[e]?e.replace("_",""):"":e+'="'+n[e]+'"'})).filter((function(e){return!!e})).join(" ");return["path","img","circle","polygon","line","input"].indexOf(e)>=0?("<"+e+" "+s+" />").trim():("<"+e+" "+s+">"+a.filter((function(e){return!!e})).map((function(e){return Array.isArray(e)?e.join(""):e})).join("")+"</"+e+">").trim()},e.loadModule=g},"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self)["@wiajs/core"]={});
|
package/gulpfile.js
CHANGED
|
@@ -1,22 +1,71 @@
|
|
|
1
|
-
|
|
1
|
+
/* eslint-disable import/no-extraneous-dependencies */
|
|
2
2
|
const gulp = require('gulp');
|
|
3
|
-
const
|
|
4
|
-
const
|
|
3
|
+
const fs = require('fs-extra');
|
|
4
|
+
const build = require('./script/build');
|
|
5
|
+
const configs = require('./script/config');
|
|
5
6
|
|
|
6
|
-
const
|
|
7
|
+
const nodeEnv = process.env.NODE_ENV || 'development';
|
|
7
8
|
const src = './src';
|
|
8
9
|
const out = './dist';
|
|
9
|
-
|
|
10
|
+
|
|
11
|
+
console.log(`env:${nodeEnv} src:${src} out:${out}`);
|
|
10
12
|
|
|
11
13
|
if (!fs.existsSync(out)) {
|
|
12
14
|
fs.mkdirSync(out);
|
|
13
15
|
}
|
|
14
16
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
+
/**
|
|
18
|
+
* ɾ�����з����ļ���ȫ����������
|
|
19
|
+
* @returns
|
|
20
|
+
*/
|
|
21
|
+
async function clean(cb) {
|
|
22
|
+
// const toRemove = ['*.map'].map(cmd => `rm -rf ${cmd}`);
|
|
23
|
+
// await exec.promise(`cd dist && ${toRemove.join(' && ')}`);
|
|
24
|
+
await fs.emptyDir('./dist/');
|
|
25
|
+
cb && cb();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* ͬʱ����umd��cjs��esm ���ָ�ʽ����ļ�
|
|
30
|
+
*/
|
|
31
|
+
const buildAll = gulp.series(clean, cb => {
|
|
32
|
+
console.log('start build ...');
|
|
17
33
|
build(configs, cb);
|
|
18
34
|
});
|
|
19
35
|
|
|
36
|
+
/**
|
|
37
|
+
* ������cjs ��ʽ
|
|
38
|
+
*/
|
|
39
|
+
gulp.task('cjs', cb => {
|
|
40
|
+
console.log('dev cjs...');
|
|
41
|
+
// filter configs
|
|
42
|
+
const cfg = configs.filter(c => c.output.format === 'cjs');
|
|
43
|
+
build(cfg, cb);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* ������ esm ��ʽ
|
|
48
|
+
*/
|
|
49
|
+
gulp.task('esm', cb => {
|
|
50
|
+
console.log('dev esm...');
|
|
51
|
+
// filter configs
|
|
52
|
+
const cfg = configs.filter(c => c.output.format === 'esm');
|
|
53
|
+
build(cfg, cb);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* ������ umd ��ʽ
|
|
58
|
+
*/
|
|
59
|
+
gulp.task('umd', cb => {
|
|
60
|
+
console.log('dev umd...');
|
|
61
|
+
// filter configs
|
|
62
|
+
const cfg = configs.filter(c => c.output.format === 'umd');
|
|
63
|
+
build(cfg, cb);
|
|
64
|
+
});
|
|
65
|
+
|
|
20
66
|
gulp.task('watch', () => {
|
|
21
|
-
gulp.watch(`${src}/*.js`, gulp.series([
|
|
67
|
+
gulp.watch(`${src}/*.js`, gulp.series([buildAll]));
|
|
22
68
|
});
|
|
69
|
+
|
|
70
|
+
module.default = buildAll;
|
|
71
|
+
module.exports = {build: buildAll};
|
package/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wiajs/core",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "wia app core package.
|
|
3
|
+
"version": "1.0.2",
|
|
4
|
+
"description": "wia app core package. refer to Framework7.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "dist/core.d.ts",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"build": "cross-env NODE_ENV=production gulp build",
|
|
9
|
-
"build-dev": "cross-env NODE_ENV=development gulp build"
|
|
9
|
+
"build-dev": "cross-env NODE_ENV=development gulp build",
|
|
10
|
+
"dev": "cross-env NODE_ENV=development gulp cjs",
|
|
11
|
+
"dev:umd": "cross-env NODE_ENV=development gulp umd",
|
|
12
|
+
"dev:esm": "cross-env NODE_ENV=development gulp esm",
|
|
13
|
+
"release": "bash release.sh"
|
|
10
14
|
},
|
|
11
15
|
"repository": {
|
|
12
16
|
"type": "git",
|
|
@@ -29,23 +33,17 @@
|
|
|
29
33
|
"access": "public"
|
|
30
34
|
},
|
|
31
35
|
"devDependencies": {
|
|
32
|
-
"babel
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"eslint-plugin-jsx-a11y": "^6.2.3",
|
|
41
|
-
"eslint-plugin-react": "^7.14.3",
|
|
36
|
+
"@rollup/plugin-babel": "^6.0.3",
|
|
37
|
+
"@rollup/plugin-commonjs": "^25.0.1",
|
|
38
|
+
"@rollup/plugin-node-resolve": "^15.1.0",
|
|
39
|
+
"@rollup/plugin-replace": "^5.0.2",
|
|
40
|
+
"@rollup/plugin-terser": "^0.4.3",
|
|
41
|
+
"cross-env": "^7.0.3",
|
|
42
|
+
"debug": "^4.3.4",
|
|
43
|
+
"fs-extra": "^11.1.1",
|
|
42
44
|
"gulp": "^4.0.2",
|
|
43
|
-
"rollup": "^
|
|
44
|
-
"
|
|
45
|
-
"rollup-plugin-commonjs": "^10.1.0",
|
|
46
|
-
"rollup-plugin-node-resolve": "^5.2.0",
|
|
47
|
-
"rollup-plugin-replace": "^2.2.0",
|
|
48
|
-
"terser": "^4.4.0"
|
|
45
|
+
"rollup": "^3.25.1",
|
|
46
|
+
"terser": "^5.18.0"
|
|
49
47
|
},
|
|
50
48
|
"dependencies": {}
|
|
51
49
|
}
|
package/prettier.config.js
CHANGED
|
@@ -6,5 +6,8 @@ module.exports = {
|
|
|
6
6
|
bracketSpacing: false, // 大括号内的首尾需要空格
|
|
7
7
|
trailingComma: 'es5', // 末尾是否需要逗号
|
|
8
8
|
jsxBracketSameLine: true, // jsx 标签的反尖括号不换行
|
|
9
|
-
|
|
9
|
+
arrowParens: 'avoid', // 尽可能省略箭头函数参数括号。 示例:x => x
|
|
10
|
+
printWidth: 100, // 代码换行长度
|
|
11
|
+
endOfLine: 'auto',
|
|
12
|
+
// jsxSingleQuote: false, // jsx 使用双引号
|
|
10
13
|
};
|
package/test/test.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
function format(f, ...args) {
|
|
2
|
+
let i = 0;
|
|
3
|
+
const len = args.length;
|
|
4
|
+
const str = String(f).replace(/%[sdj%]/g, x => {
|
|
5
|
+
if (x === '%%') return '%';
|
|
6
|
+
if (i >= len) return x;
|
|
7
|
+
switch (x) {
|
|
8
|
+
case '%s':
|
|
9
|
+
return String(args[i++]);
|
|
10
|
+
case '%d':
|
|
11
|
+
return Number(args[i++]);
|
|
12
|
+
case '%j':
|
|
13
|
+
return JSON.stringify(args[i++]);
|
|
14
|
+
default:
|
|
15
|
+
return x;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
return str;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function trimEnd(s, c) {
|
|
23
|
+
if (!s) return '';
|
|
24
|
+
|
|
25
|
+
if (!c) return String(s).replace(/(\s*$)/g, '');
|
|
26
|
+
|
|
27
|
+
const rx = new RegExp(format('%s*$', c));
|
|
28
|
+
return String(s).replace(rx, '');
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function dates(fmt, d) {
|
|
32
|
+
if (!fmt) fmt = 'yyyy-MM-dd';
|
|
33
|
+
|
|
34
|
+
if (!d) d = new Date();
|
|
35
|
+
else if (typeof d === 'string') {
|
|
36
|
+
// 兼容
|
|
37
|
+
d = d
|
|
38
|
+
.replace(/\-/g, '/')
|
|
39
|
+
.replace(/T/g, ' ')
|
|
40
|
+
.replace(/\.+[0-9]+[A-Z]$/, '');
|
|
41
|
+
// 还原时区,内部保存为标准时间
|
|
42
|
+
d = new Date(d).getTime() - 3600000 * (new Date().getTimezoneOffset() / 60);
|
|
43
|
+
d = new Date(d);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Date.getXXX 函数会自动还原时区!!!
|
|
47
|
+
const o = {
|
|
48
|
+
y: d.getFullYear().toString(),
|
|
49
|
+
M: d.getMonth() + 1, // 月份
|
|
50
|
+
d: d.getDate(), // 日
|
|
51
|
+
h: d.getHours(), // 小时
|
|
52
|
+
m: d.getMinutes(), // 分
|
|
53
|
+
s: d.getSeconds(), // 秒
|
|
54
|
+
q: Math.floor((d.getMonth() + 3) / 3), // 季度
|
|
55
|
+
S: d.getMilliseconds().toString().padStart(3, '0'), // 毫秒
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
// yy几个就返回 几个数字,使用 slice -4 倒数4个,再往后
|
|
59
|
+
fmt = fmt.replace(/(S+)/g, o.S).replace(/(y+)/gi, v => o.y.slice(-v.length));
|
|
60
|
+
fmt = fmt.replace(/(M+|d+|h+|m+|s+|q+)/g, v =>
|
|
61
|
+
((v.length > 1 ? '0' : '') + o[v.slice(-1)]).slice(-2)
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
return trimEnd(fmt, ' 00:00:00');
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
console.log(dates('yyyy-MM-dd'));
|
|
68
|
+
console.log(dates('yy-MM-dd'));
|
|
69
|
+
console.log(dates('yyyy-M-d'));
|
|
70
|
+
console.log(dates('yyyy-MM-dd hh:mm:ss'));
|
|
71
|
+
console.log(dates('yyyy-MM-dd h:m:s'));
|
|
72
|
+
console.log(dates('yyyy-MM-dd hh:mm:ss.S'));
|
|
73
|
+
console.log(dates('yyyy-M-dd h:m:s', '2020-05-22 8:9:8'));
|
package/util/tool.js
CHANGED
|
@@ -136,32 +136,35 @@ function newFileName(len) {
|
|
|
136
136
|
*/
|
|
137
137
|
function compareObj(k, desc, type) {
|
|
138
138
|
return function (o1, o2) {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
139
|
+
let R = 0;
|
|
140
|
+
try {
|
|
141
|
+
let v1 = o1[k];
|
|
142
|
+
let v2 = o2[k];
|
|
143
|
+
// 数字、日期字符串,按数字、日期排序
|
|
144
|
+
if ($.isStr(v1) || $.isStr(v2)) {
|
|
145
|
+
// 金额可能有千字分隔符,需替换
|
|
146
|
+
if (type.toLowerCase() === 'number') {
|
|
147
|
+
v1 = v1.replaceAll(',', '');
|
|
148
|
+
v2 = v2.replaceAll(',', '');
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
if ($.isDateStr(v1) && $.isDateStr(v2)) {
|
|
152
|
+
v1 = Date.parse(v1);
|
|
153
|
+
v2 = Date.parse(v2);
|
|
154
|
+
} else if ($.isNumStr(v1) && $.isNumStr(v2)) {
|
|
155
|
+
v1 = Number(v1);
|
|
156
|
+
v2 = Number(v2);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
if (v1 < v2) {
|
|
161
|
+
R = desc ? 1 : -1;
|
|
162
|
+
} else if (v1 > v2) {
|
|
163
|
+
R = desc ? -1 : 1;
|
|
164
|
+
}
|
|
165
|
+
} catch(ex) {
|
|
166
|
+
console.log('compareObj exp:', ex.message);
|
|
167
|
+
}
|
|
165
168
|
return R;
|
|
166
169
|
};
|
|
167
170
|
}
|
package/build.js
DELETED
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
const fs = require('fs');
|
|
2
|
-
const path = require('path');
|
|
3
|
-
const zlib = require('zlib');
|
|
4
|
-
const { minify } = require('terser');
|
|
5
|
-
const rollup = require('rollup');
|
|
6
|
-
|
|
7
|
-
const env = process.env.NODE_ENV || 'development';
|
|
8
|
-
|
|
9
|
-
const isProd = env === 'production';
|
|
10
|
-
|
|
11
|
-
function build(cfg, cb) {
|
|
12
|
-
let built = 0;
|
|
13
|
-
const total = cfg.length;
|
|
14
|
-
const next = () => {
|
|
15
|
-
buildEntry(cfg[built])
|
|
16
|
-
.then(() => {
|
|
17
|
-
built++;
|
|
18
|
-
if (built < total) next();
|
|
19
|
-
else cb && cb();
|
|
20
|
-
})
|
|
21
|
-
.catch(logError);
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
next();
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function buildEntry({input, output}) {
|
|
28
|
-
const {file, banner} = output;
|
|
29
|
-
return rollup
|
|
30
|
-
.rollup(input)
|
|
31
|
-
.then(bundle => bundle.write(output)) // bundle.generate(output))
|
|
32
|
-
.then(async bundle => {
|
|
33
|
-
// console.log(bundle)
|
|
34
|
-
const {code} = bundle.output[0];
|
|
35
|
-
report(code, file);
|
|
36
|
-
|
|
37
|
-
if (isProd) {
|
|
38
|
-
const minCode =
|
|
39
|
-
// (banner ? banner + '\n' : '') +
|
|
40
|
-
/* await minify(code, {
|
|
41
|
-
sourceMap: false,
|
|
42
|
-
});
|
|
43
|
-
*/
|
|
44
|
-
await minify(code, {
|
|
45
|
-
sourceMap: false,
|
|
46
|
-
toplevel: true,
|
|
47
|
-
output: {
|
|
48
|
-
ascii_only: true,
|
|
49
|
-
},
|
|
50
|
-
compress: {
|
|
51
|
-
pure_funcs: ['makeMap'],
|
|
52
|
-
},
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
return write(file.replace('.js', '.min.js'), minCode.code, true);
|
|
56
|
-
}
|
|
57
|
-
// else {
|
|
58
|
-
// return write(file, code);
|
|
59
|
-
// }
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
function report(code, dest, extra) {
|
|
64
|
-
console.log(
|
|
65
|
-
blue(path.relative(process.cwd(), dest)) +
|
|
66
|
-
' ' +
|
|
67
|
-
getSize(code) +
|
|
68
|
-
(extra || '')
|
|
69
|
-
);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
function write(dest, code, zip) {
|
|
73
|
-
return new Promise((resolve, reject) => {
|
|
74
|
-
fs.writeFile(dest, code, err => {
|
|
75
|
-
if (err) return reject(err);
|
|
76
|
-
if (zip) {
|
|
77
|
-
zlib.gzip(code, (err, zipped) => {
|
|
78
|
-
if (err) return reject(err);
|
|
79
|
-
report(code, dest, ' (gzipped: ' + getSize(zipped) + ')');
|
|
80
|
-
resolve();
|
|
81
|
-
});
|
|
82
|
-
} else {
|
|
83
|
-
report(code, dest);
|
|
84
|
-
resolve();
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
function getSize(code) {
|
|
91
|
-
return (code.length / 1024).toFixed(2) + 'kb';
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
function logError(e) {
|
|
95
|
-
console.log(e);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
function blue(str) {
|
|
99
|
-
return '\x1b[1m\x1b[34m' + str + '\x1b[39m\x1b[22m';
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
module.exports = build;
|
package/config.js
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
const path = require('path');
|
|
2
|
-
const babel = require('rollup-plugin-babel');
|
|
3
|
-
// const buble = require('rollup-plugin-buble');
|
|
4
|
-
const cjs = require('rollup-plugin-commonjs');
|
|
5
|
-
const node = require('rollup-plugin-node-resolve');
|
|
6
|
-
const replace = require('rollup-plugin-replace');
|
|
7
|
-
|
|
8
|
-
const version = process.env.VERSION || require('./package.json').version;
|
|
9
|
-
const banner = `/*!
|
|
10
|
-
* wia core v${version}
|
|
11
|
-
* (c) ${new Date().getFullYear()} Sibyl Yu
|
|
12
|
-
* @license MIT
|
|
13
|
-
*/`;
|
|
14
|
-
|
|
15
|
-
const env = process.env.NODE_ENV || 'development';
|
|
16
|
-
|
|
17
|
-
const resolve = _path => path.resolve(__dirname, './', _path);
|
|
18
|
-
|
|
19
|
-
module.exports = [
|
|
20
|
-
// browser dev
|
|
21
|
-
{
|
|
22
|
-
file: resolve('dist/core.js'),
|
|
23
|
-
format: 'umd',
|
|
24
|
-
},
|
|
25
|
-
{
|
|
26
|
-
file: resolve('dist/core.common.js'),
|
|
27
|
-
format: 'cjs',
|
|
28
|
-
},
|
|
29
|
-
{
|
|
30
|
-
file: resolve('dist/core.esm.js'),
|
|
31
|
-
format: 'es',
|
|
32
|
-
},
|
|
33
|
-
].map(genConfig);
|
|
34
|
-
|
|
35
|
-
function genConfig(opts) {
|
|
36
|
-
const config = {
|
|
37
|
-
input: {
|
|
38
|
-
input: resolve('src/index.js'),
|
|
39
|
-
plugins: [
|
|
40
|
-
babel({exclude: /node_modules/, sourceMaps: true}),
|
|
41
|
-
node(),
|
|
42
|
-
cjs(),
|
|
43
|
-
// 替换特定字符串
|
|
44
|
-
replace({
|
|
45
|
-
'process.env.NODE_ENV': JSON.stringify(env),
|
|
46
|
-
__VERSION__: version,
|
|
47
|
-
}),
|
|
48
|
-
// babel({exclude: /node_modules/, sourceMaps: true, rootMode: 'upward'}),
|
|
49
|
-
],
|
|
50
|
-
external: [], // 外部变量,不打入包中
|
|
51
|
-
},
|
|
52
|
-
output: {
|
|
53
|
-
file: opts.file,
|
|
54
|
-
format: opts.format,
|
|
55
|
-
sourcemap: process.env.NODE_ENV === 'development',
|
|
56
|
-
banner,
|
|
57
|
-
name: '@wiajs/Core',
|
|
58
|
-
globals: {}, // 全局变量
|
|
59
|
-
},
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
// if (opts.transpile !== false) {
|
|
63
|
-
// config.input.plugins.push(
|
|
64
|
-
// babel({exclude: /node_modules/, sourceMaps: true, rootMode: 'upward'})
|
|
65
|
-
// ); // buble());
|
|
66
|
-
// }
|
|
67
|
-
|
|
68
|
-
return config;
|
|
69
|
-
}
|