mazey 1.4.37 → 2.0.0

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/lib/index.esm.js CHANGED
@@ -2415,6 +2415,10 @@ if (NOT_GENERIC || INCORRECT_NAME) {
2415
2415
  }, { unsafe: true });
2416
2416
  }
2417
2417
 
2418
+ _export({ target: 'RegExp', proto: true, forced: /./.exec !== regexpExec }, {
2419
+ exec: regexpExec
2420
+ });
2421
+
2418
2422
  // TODO: Remove from `core-js@4` since it's moved to entry points
2419
2423
 
2420
2424
 
@@ -2980,7 +2984,28 @@ function _typeof(obj) {
2980
2984
  module.exports = _typeof;
2981
2985
  });
2982
2986
 
2983
- /* Deal */
2987
+ /*! *****************************************************************************
2988
+ Copyright (c) Microsoft Corporation.
2989
+
2990
+ Permission to use, copy, modify, and/or distribute this software for any
2991
+ purpose with or without fee is hereby granted.
2992
+
2993
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
2994
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
2995
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
2996
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
2997
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
2998
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
2999
+ PERFORMANCE OF THIS SOFTWARE.
3000
+ ***************************************************************************** */
3001
+
3002
+ function __spreadArrays() {
3003
+ for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
3004
+ for (var r = Array(s), k = 0, i = 0; i < il; i++)
3005
+ for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
3006
+ r[k] = a[j];
3007
+ return r;
3008
+ }
2984
3009
 
2985
3010
  /**
2986
3011
  * @method calLongestCommonSubstring
@@ -2989,7 +3014,16 @@ module.exports = _typeof;
2989
3014
  * @param {String} bStr 字符串
2990
3015
  * @return {Number} 长度
2991
3016
  */
3017
+
2992
3018
  function calLongestCommonSubstring(aStr, bStr) {
3019
+ if (aStr === void 0) {
3020
+ aStr = '';
3021
+ }
3022
+
3023
+ if (bStr === void 0) {
3024
+ bStr = '';
3025
+ }
3026
+
2993
3027
  var aLen = aStr.length;
2994
3028
  var bLen = bStr.length; // 创建二维数组并且深拷贝
2995
3029
 
@@ -3024,6 +3058,14 @@ function calLongestCommonSubstring(aStr, bStr) {
3024
3058
  */
3025
3059
 
3026
3060
  function calLongestCommonSubsequence(aStr, bStr) {
3061
+ if (aStr === void 0) {
3062
+ aStr = '';
3063
+ }
3064
+
3065
+ if (bStr === void 0) {
3066
+ bStr = '';
3067
+ }
3068
+
3027
3069
  var aLen = aStr.length;
3028
3070
  var bLen = bStr.length; // 创建二维数组并且深拷贝
3029
3071
 
@@ -3064,148 +3106,178 @@ function calLongestCommonSubsequence(aStr, bStr) {
3064
3106
  return maxLong;
3065
3107
  }
3066
3108
  /**
3067
- * @method join
3068
- * @description 将一系列值连接成固定字符分隔的字符串 123,456 => 123 - 456。
3069
- * @param {String} joinStr 连接值的字符串。
3070
- * @param {Rest} ...rest 需要连接的值 。
3109
+ * @method getQueryParam
3110
+ * @description Get the query param's value of the current Web URL(`location.search`).
3111
+ * @param {String} param Query param.
3112
+ * @return {String} value
3071
3113
  * */
3072
3114
 
3073
- function join(joinStr) {
3074
- var rest = [];
3075
-
3076
- for (var _i = 1; _i < arguments.length; _i++) {
3077
- rest[_i - 1] = arguments[_i];
3115
+ function getQueryParam(param) {
3116
+ if (param === void 0) {
3117
+ param = '';
3078
3118
  }
3079
3119
 
3080
- var ret = '';
3081
- var len = joinStr.length;
3082
-
3083
- for (var _a = 0, rest_1 = rest; _a < rest_1.length; _a++) {
3084
- var v = rest_1[_a];
3085
-
3086
- if (v) {
3087
- ret += "" + joinStr + v;
3088
- }
3089
- }
3120
+ var reg = new RegExp('(^|&)' + param + '=([^&]*)(&|$)');
3121
+ var r = location.search.substr(1).match(reg);
3090
3122
 
3091
- if (ret) {
3092
- ret = ret.substring(len);
3123
+ if (r !== null) {
3124
+ return decodeURIComponent(unescape(r[2]));
3093
3125
  }
3094
3126
 
3095
- return ret;
3127
+ return '';
3096
3128
  }
3097
3129
  /**
3098
- * @method renderTable
3099
- * @description 渲染表格
3100
- * @param {DOM Object} tbID
3101
- * @param {Array} data
3102
- * @param {Array} property
3103
- */
3130
+ * @method getUrlParam
3131
+ * @description Get the query param's value of the input URL.
3132
+ * @param {String} url URL string.
3133
+ * @param {String} param Query param.
3134
+ * @return {String} value
3135
+ * */
3104
3136
 
3105
- function renderTable(tbID, data, property) {
3106
- if (tbID === void 0) {
3107
- tbID = null;
3137
+ function getUrlParam(url, param) {
3138
+ if (url === void 0) {
3139
+ url = '';
3108
3140
  }
3109
3141
 
3110
- if (data === void 0) {
3111
- data = [];
3142
+ if (param === void 0) {
3143
+ param = '';
3112
3144
  }
3113
3145
 
3114
- if (property === void 0) {
3115
- property = [];
3116
- }
3146
+ var result = {}; // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace
3117
3147
 
3118
- var TBODY = document.querySelector("#" + tbID + " tbody");
3148
+ url.replace(/\??(\w+)=([^&]*)&?/g, function (a, k, v) {
3149
+ if (result[k] !== undefined) {
3150
+ var t = result[k];
3151
+ result[k] = [].concat(t, v);
3152
+ } else {
3153
+ result[k] = v;
3154
+ }
3155
+ }); // if (param === undefined) {
3156
+ // return result;
3157
+ // } else {
3158
+ // return result[param] || '';
3159
+ // }
3160
+
3161
+ return result[param] || '';
3162
+ }
3163
+ /**
3164
+ * @method updateQueryParam
3165
+ * @description Update the query param's value of the input URL.
3166
+ * @param {String} url URL string.
3167
+ * @param {String} param Query param.
3168
+ * @param {String} value Param's value.
3169
+ * @return {String} URL.
3170
+ * */
3119
3171
 
3120
- function mNullToNA(str) {
3121
- return str === null ? 'N.A.' : str;
3172
+ function updateQueryParam(url, param, value) {
3173
+ if (url === void 0) {
3174
+ url = '';
3122
3175
  }
3123
3176
 
3124
- var content = '';
3125
- TBODY.innerHTML = ''; // 无数据
3177
+ if (param === void 0) {
3178
+ param = '';
3179
+ }
3126
3180
 
3127
- if (!data.length) {
3128
- content = "<tr><td colspan=\"" + property.length + "\">\u65E0\u6570\u636E</td></tr>";
3129
- } else {
3130
- for (var _a = [0, data.length], i = _a[0], max = _a[1]; i < max; ++i) {
3131
- var item = data[i];
3132
- content += '<tr>';
3181
+ if (value === void 0) {
3182
+ value = '';
3183
+ }
3133
3184
 
3134
- for (var _b = [0, property.length], i_1 = _b[0], max_1 = _b[1]; i_1 < max_1; ++i_1) {
3135
- content += "<td>" + mNullToNA(item[property[i_1]]) + "</td>";
3136
- }
3185
+ var re = new RegExp('([?&])' + param + '=.*?(&|$)', 'i');
3186
+ var separator = url.indexOf('?') !== -1 ? '&' : '?';
3137
3187
 
3138
- content += '</tr>';
3139
- }
3188
+ if (url.match(re)) {
3189
+ return url.replace(re, '$1' + param + '=' + value + '$2');
3190
+ } else {
3191
+ return url + separator + param + '=' + value;
3140
3192
  }
3141
-
3142
- TBODY.innerHTML = content;
3143
3193
  }
3144
3194
  /**
3145
3195
  * @method getHashQueryParam
3146
- * @description 获取地址栏 hash 后面的参数。
3147
- * @param {String} param 获取参数的名字。
3196
+ * @description Get the hash query param's value of the current Web URL(`location.hash`).
3197
+ * @param {String} param Query param.
3198
+ * @return {String} value
3148
3199
  */
3149
3200
 
3150
3201
  function getHashQueryParam(param) {
3151
- var hashs = window.location.hash.split('?');
3202
+ if (param === void 0) {
3203
+ param = '';
3204
+ }
3205
+
3206
+ var hashs = location.hash.split('?');
3152
3207
 
3153
3208
  if (hashs.length === 1) {
3154
- return null;
3209
+ return '';
3155
3210
  }
3156
3211
 
3157
3212
  var reg = new RegExp("(^|&)" + param + "=([^&]*)(&|$)");
3158
3213
  var ret = hashs[1].match(reg);
3159
- return ret ? ret[2] : null;
3214
+ return ret ? ret[2] : '';
3215
+ }
3216
+ /**
3217
+ * @method getDomain
3218
+ * @description Get the domain of URL, and other params.
3219
+ * @param {String} url
3220
+ * @param {Array} rules Object.keys(location), ['href', 'protocol', 'host', 'hostname', 'port', 'pathname', 'search', 'hash'], ['hostname', 'pathname'] = 'km.mazey.net/plugins/servlet/mobile'
3221
+ * */
3222
+
3223
+ function getDomain(url, rules) {
3224
+ if (url === void 0) {
3225
+ url = '';
3226
+ }
3227
+
3228
+ if (rules === void 0) {
3229
+ rules = ['hostname'];
3230
+ }
3231
+
3232
+ var aEl = document.createElement('a');
3233
+ aEl.href = url;
3234
+ return rules.reduce(function (ret, v) {
3235
+ ret += aEl[v];
3236
+ return ret;
3237
+ }, '');
3160
3238
  }
3161
3239
  /**
3162
3240
  * @method camelCaseToKebabCase
3163
- * @description 驼峰转连接线。
3164
- * @param {String} camelCase
3241
+ * @description Transfer CamelCase to KebabCase.
3242
+ * @param {String} camelCase 'aBC' or 'ABC'
3243
+ * @return {String} 'a-b-c'
3165
3244
  * */
3166
3245
 
3167
3246
  function camelCaseToKebabCase(camelCase) {
3247
+ if (camelCase === void 0) {
3248
+ camelCase = '';
3249
+ }
3250
+
3168
3251
  var kebabCase = camelCase.replace(/([A-Z])/g, '-$1').toLowerCase();
3169
3252
  return kebabCase[0] === '-' ? kebabCase.substr(1) : kebabCase;
3170
3253
  }
3171
3254
  /**
3172
3255
  * @method camelCase2Underscore
3173
- * @description 驼峰转下划线。
3174
- * @param {String} camelCase
3256
+ * @description Transfer CamelCase to Underscore.
3257
+ * @param {String} camelCase 'aBC' or 'ABC'
3258
+ * @return {String} 'a_b_c'
3175
3259
  * */
3176
3260
 
3177
3261
  function camelCase2Underscore(camelCase) {
3262
+ if (camelCase === void 0) {
3263
+ camelCase = '';
3264
+ }
3265
+
3178
3266
  var kebabCase = camelCase.replace(/([A-Z])/g, '_$1').toLowerCase();
3179
3267
  return kebabCase[0] === '_' ? kebabCase.substr(1) : kebabCase;
3180
3268
  }
3181
3269
  /**
3182
- * @method getDomain
3183
- * @description 获取地址中的域名(及其他参数)。
3184
- * @param {String} url
3185
- * @param {Array} rules ['hostname', 'pathname'] = 'km.mazey.net/plugins/servlet/mobile'
3270
+ * @method mTrim
3271
+ * @description Remove leading and trailing whitespace or specified characters from string.
3272
+ * @param {String} str The string to trim.
3273
+ * @return {String} Trimmed string.
3186
3274
  * */
3187
3275
 
3188
- function getDomain(_a) {
3189
- var _b = _a === void 0 ? {} : _a,
3190
- _c = _b.url,
3191
- url = _c === void 0 ? '' : _c,
3192
- _d = _b.rules,
3193
- rules = _d === void 0 ? ['hostname'] : _d;
3194
-
3195
- var aEl = document.createElement('a');
3196
- aEl.href = url;
3197
- return rules.reduce(function (ret, v, index) {
3198
- ret += aEl[v];
3199
- return ret;
3200
- }, '');
3201
- }
3202
- /**
3203
- * @method trim
3204
- * @description 去除左右空格。
3205
- * @param {String} str 需要去除两边空格的字符串。
3206
- * */
3276
+ function mTrim(str) {
3277
+ if (str === void 0) {
3278
+ str = '';
3279
+ }
3207
3280
 
3208
- function trim$1(str) {
3209
3281
  str = str.replace(/^\s+/, ''); // 去除头部空格
3210
3282
 
3211
3283
  var end = str.length - 1;
@@ -3219,11 +3291,16 @@ function trim$1(str) {
3219
3291
  }
3220
3292
  /**
3221
3293
  * @method newLine
3222
- * @description html换行。
3223
- * @param {String} str
3294
+ * @description Make a newline of HTML.
3295
+ * @param {String} str The string to make a newline.
3296
+ * @return {String} A newline with `<br />`.
3224
3297
  * */
3225
3298
 
3226
3299
  function newLine(str) {
3300
+ if (str === void 0) {
3301
+ str = '';
3302
+ }
3303
+
3227
3304
  if (!str) {
3228
3305
  return '';
3229
3306
  }
@@ -3233,22 +3310,48 @@ function newLine(str) {
3233
3310
  }
3234
3311
  /**
3235
3312
  * @method deepCopyObject
3236
- * @description 对象深拷贝。
3237
- * @param {Object} obj 被拷贝的对象。
3238
- * @return {Object}
3313
+ * @description Clone Object deeply.
3314
+ * @param {Object} obj The value to clone.
3315
+ * @return {Object} Returns the deep cloned value.
3239
3316
  * */
3240
3317
 
3241
3318
  function deepCopyObject(obj) {
3242
3319
  return JSON.parse(JSON.stringify(obj));
3243
3320
  }
3321
+ /**
3322
+ * @method isJsonString
3323
+ * @description Check whether it is a valid JSON string.
3324
+ * @param {String} str The string to check.
3325
+ * @return {Boolean} Return the result of checking.
3326
+ * */
3327
+
3328
+ function isJsonString(str) {
3329
+ if (str === void 0) {
3330
+ str = '';
3331
+ }
3332
+
3333
+ try {
3334
+ if (_typeof_1(JSON.parse(str)) === 'object') {
3335
+ return true;
3336
+ }
3337
+ } catch (e) {
3338
+ /* pass */
3339
+ }
3340
+
3341
+ return false;
3342
+ }
3244
3343
  /**
3245
3344
  * @method generateRndNum
3246
- * @description 生成随机数 mGenerateRndNum(7) => 7658495。
3247
- * @param {Number} n 随机数的长度
3248
- * @return {String}
3345
+ * @description Produce a random string of number, `generateRndNum(7)` => '7658495'.
3346
+ * @param {Number} n Length
3347
+ * @return {String} Return the random string.
3249
3348
  * */
3250
3349
 
3251
3350
  function generateRndNum(n) {
3351
+ if (n === void 0) {
3352
+ n = 5;
3353
+ }
3354
+
3252
3355
  var ret = '';
3253
3356
 
3254
3357
  while (n--) {
@@ -3264,36 +3367,15 @@ function generateRndNum(n) {
3264
3367
  * */
3265
3368
 
3266
3369
  function generateUniqueNum(n) {
3370
+ if (n === void 0) {
3371
+ n = 3;
3372
+ }
3373
+
3267
3374
  var _a = [mNow(), generateRndNum(n || 3)],
3268
3375
  now = _a[0],
3269
3376
  rnd = _a[1];
3270
3377
  return now + rnd;
3271
3378
  }
3272
- /**
3273
- * @method resetForm
3274
- * @description 重置表单输入值为原始(空)状态。
3275
- * @param {String} rest name1,name2,name3...NAME属性,可以多个。
3276
- * */
3277
-
3278
- function resetForm() {
3279
- var rest = [];
3280
-
3281
- for (var _i = 0; _i < arguments.length; _i++) {
3282
- rest[_i] = arguments[_i];
3283
- }
3284
-
3285
- for (var i = 0; i < rest.length; i++) {
3286
- var tagMz = document.getElementsByName(rest[i])[0]; // tag object
3287
-
3288
- var tagNameMz = tagMz.tagName.toLowerCase(); // tag name
3289
-
3290
- if (tagNameMz === 'input') {
3291
- tagMz.value = '';
3292
- } else if (tagNameMz === 'select') {
3293
- tagMz.options[0].selected = true;
3294
- }
3295
- }
3296
- }
3297
3379
  /**
3298
3380
  * @method floatToPercent
3299
3381
  * @description 浮点数转为百分比 0.2 => 20%。
@@ -3302,17 +3384,23 @@ function resetForm() {
3302
3384
  * */
3303
3385
 
3304
3386
  function floatToPercent(num, fixSize) {
3387
+ if (num === void 0) {
3388
+ num = 0;
3389
+ }
3390
+
3305
3391
  if (fixSize === void 0) {
3306
3392
  fixSize = 0;
3307
3393
  }
3308
3394
 
3395
+ var ret = '';
3396
+
3309
3397
  if (fixSize) {
3310
- num = (num * 100).toFixed(fixSize);
3398
+ ret = (num * 100).toFixed(fixSize);
3311
3399
  } else {
3312
- num = Math.floor(num * 100);
3400
+ ret = String(Math.floor(num * 100));
3313
3401
  }
3314
3402
 
3315
- return num + "%";
3403
+ return ret + "%";
3316
3404
  }
3317
3405
  /**
3318
3406
  * @method floatFixed
@@ -3320,23 +3408,11 @@ function floatToPercent(num, fixSize) {
3320
3408
  * */
3321
3409
 
3322
3410
  function floatFixed(num, size) {
3323
- return parseFloat(num).toFixed(size);
3324
- }
3325
- /**
3326
- * @method compatibleExist
3327
- * @description 不存在返回 ——。
3328
- * */
3329
-
3330
- function compatibleExist(instance, replaceStr) {
3331
- var ret = '';
3332
-
3333
- try {
3334
- ret = instance || replaceStr || '——';
3335
- } catch (e) {
3336
- ret = '——';
3411
+ if (size === void 0) {
3412
+ size = 0;
3337
3413
  }
3338
3414
 
3339
- return ret;
3415
+ return parseFloat(num).toFixed(size);
3340
3416
  }
3341
3417
  /**
3342
3418
  * @method cancelBubble
@@ -3583,7 +3659,7 @@ function friendlyInterval(_a) {
3583
3659
  /**
3584
3660
  * @method isNumber
3585
3661
  * @description 判断是否有效数字
3586
- * @param {Any} num 被判断的值
3662
+ * @param {*} num 被判断的值
3587
3663
  * @param {Boolean} isNaNAsNumber 是否 NaN 算数字(默认不算)
3588
3664
  * @param {Boolean} isUnFiniteAsNumber 是否 无限 算数字(默认不算)
3589
3665
  * @return {Boolean} true 是数字
@@ -3616,84 +3692,6 @@ function isNumber(num, _a) {
3616
3692
 
3617
3693
  return ret;
3618
3694
  }
3619
- /**
3620
- * @method updateQueryStringParameter
3621
- * @description 替换或添加地址栏参数。
3622
- * */
3623
-
3624
- function updateQueryStringParameter(uri, key, value) {
3625
- var re = new RegExp('([?&])' + key + '=.*?(&|$)', 'i');
3626
- var separator = uri.indexOf('?') !== -1 ? '&' : '?';
3627
-
3628
- if (uri.match(re)) {
3629
- return uri.replace(re, '$1' + key + '=' + value + '$2');
3630
- } else {
3631
- return uri + separator + key + '=' + value;
3632
- }
3633
- }
3634
- /**
3635
- * @method isJsonString
3636
- * @description 判断是否合法 JSON 字符串。
3637
- * */
3638
-
3639
- function isJsonString(str) {
3640
- try {
3641
- if (_typeof_1(JSON.parse(str)) === 'object') {
3642
- return true;
3643
- }
3644
- } catch (e) {
3645
- /* pass */
3646
- }
3647
-
3648
- return false;
3649
- }
3650
- /**
3651
- * @method getUrlParam
3652
- * @description 链接参数
3653
- * @param {String} sUrl 链接
3654
- * @param {String} sKey 参数
3655
- * */
3656
-
3657
- function getUrlParam(sUrl, sKey) {
3658
- var result = {};
3659
- sUrl.replace(/\??(\w+)=([^&]*)&?/g, function (a, k, v) {
3660
- if (result[k] !== undefined) {
3661
- var t = result[k];
3662
- result[k] = [].concat(t, v);
3663
- } else {
3664
- result[k] = v;
3665
- }
3666
- });
3667
-
3668
- if (sKey === undefined) {
3669
- return result;
3670
- } else {
3671
- return result[sKey] || '';
3672
- }
3673
- }
3674
- /**
3675
- * @method getSearchQueryParam
3676
- * @description 地址栏参数。
3677
- * */
3678
-
3679
- function getSearchQueryParam(name) {
3680
- var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)');
3681
- var r = window.location.search.substr(1).match(reg);
3682
-
3683
- if (r != null) {
3684
- return decodeURIComponent(unescape(r[2]));
3685
- }
3686
-
3687
- return null;
3688
- }
3689
- /**
3690
- * @method getQueryParam
3691
- * @description 地址栏参数,getSearchQueryParam 的别名。
3692
- * */
3693
-
3694
- function getQueryParam(name) {
3695
- return getSearchQueryParam(name);
3696
- }
3697
3695
  /**
3698
3696
  * @method doFn
3699
3697
  * @description 执行有效函数
@@ -3735,7 +3733,7 @@ function setSessionStorage(key, value) {
3735
3733
  * @method getSessionStorage
3736
3734
  * @description 存储数据到 sessionStorage
3737
3735
  * @param {String} key 键
3738
- * @return {Any} 返回值
3736
+ * @return {*} 返回值
3739
3737
  * */
3740
3738
 
3741
3739
  function getSessionStorage(key) {
@@ -3771,7 +3769,7 @@ function setLocalStorage(key, value) {
3771
3769
  * @method getLocalStorage
3772
3770
  * @description 存储数据到 localStorage
3773
3771
  * @param {String} key 键
3774
- * @return {Any} 返回值
3772
+ * @return {*} 返回值
3775
3773
  * */
3776
3774
 
3777
3775
  function getLocalStorage(key) {
@@ -4064,7 +4062,7 @@ function getCookie(name) {
4064
4062
  if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
4065
4063
  }
4066
4064
 
4067
- return null;
4065
+ return '';
4068
4066
  }
4069
4067
  /**
4070
4068
  * @method getPerformance
@@ -4706,230 +4704,36 @@ function addInlineStyle(_a) {
4706
4704
  return true;
4707
4705
  }
4708
4706
  /**
4709
- * @method customScrollBarForTransformEle
4710
- * @description 为进行变换(transform)的元素设置滚动条
4711
- * @param {String} containerClassName 进行变换(transform)的元素↓的容器(Father)的类名
4712
- * @param {String} imgBoxClassName 图片的容器(transform It's YOU!)的类名
4713
- * @param {String} imgBoxDom 图片的容器 Dom 对象
4714
- * @param {String} imgClassName 图片的类名
4715
- * @param {Object} imgDom 图片 Dom 对象
4716
- * @param {String} action 操作类型 hide 隐藏指定 `containerClassName` 滚动条
4717
- * @param {String} customStyle 滚动条的定制样式,会覆盖默认样式
4718
- * @return {Boolean} 设置成功
4707
+ * @method genCustomConsole
4708
+ * @description 生成自定义控制台打印
4709
+ * @param {String} prefix 前缀
4710
+ * @param {Function} allowFn 允许打印的判断函数
4711
+ * @return {Object} 新实例
4719
4712
  */
4720
4713
 
4721
- function customScrollBarForTransformEle(_a) {
4722
- var _b = _a === void 0 ? {} : _a,
4723
- _c = _b.containerClassName,
4724
- containerClassName = _c === void 0 ? '' : _c,
4725
- _d = _b.imgBoxClassName,
4726
- imgBoxClassName = _d === void 0 ? '' : _d,
4727
- _e = _b.imgBoxDom,
4728
- imgBoxDom = _e === void 0 ? null : _e,
4729
- _f = _b.imgClassName,
4730
- imgClassName = _f === void 0 ? '' : _f,
4731
- _g = _b.imgDom,
4732
- imgDom = _g === void 0 ? null : _g,
4733
- _h = _b.action,
4734
- action = _h === void 0 ? '' : _h,
4735
- _j = _b.customStyle,
4736
- customStyle = _j === void 0 ? '' : _j; // 变量
4737
-
4738
-
4739
- var barIsHideId = 'bar-is-hide';
4740
- var barTopId = 'bar-top';
4741
- var barBottomId = 'bar-bottom';
4742
-
4743
- if (action === 'hide') {
4744
- addInlineStyle({
4745
- inlineStyle: "\n ." + containerClassName + "::after {\n display: none;\n }\n ",
4746
- id: barIsHideId
4747
- });
4748
- return true;
4749
- }
4750
-
4751
- setTimeout(function () {
4752
- // 样式初始化
4753
- addInlineStyle({
4754
- inlineStyle: "\n ." + containerClassName + "::after {\n content: ' ';\n position: fixed;\n top: 0;\n right: 2px;\n min-height: 0vh;\n max-height: 100vh;\n width: 6px;\n border-radius: 3px;\n box-shadow: inset 0 0 6px rgba(0,0,0,.3);\n -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,.3);\n background-color: rgb(109, 108, 109);\n " + customStyle + "\n }\n ",
4755
- id: 'bar-init'
4756
- });
4757
- var imgInstance = imgDom || document.querySelector("." + imgClassName);
4758
-
4759
- if (!imgInstance) {
4760
- console.warn('Need element\'s Dom instance.');
4761
- return false;
4762
- }
4763
-
4764
- var imgBoxInstance = imgBoxDom || document.querySelector("." + imgBoxClassName);
4765
-
4766
- if (!imgBoxInstance) {
4767
- console.warn('Need element box\'s Dom instance.');
4768
- return false;
4769
- }
4770
-
4771
- var Box2ToRes = getBox2To(); // console.log('获取图片距离顶部的距离', Box2ToRes);
4772
-
4773
- var ImgHeightRes = getImgHeight(); // console.log('获取图片的高度', ImgHeightRes);
4774
-
4775
- var WindowHeightRes = getWindowHeight(); // console.log('获取窗口的高度', WindowHeightRes);
4776
-
4777
- var TopOverflowPercentRes = getTopOverflowPercent(); // console.log('获取顶部溢出的百分比', TopOverflowPercentRes);
4778
-
4779
- var BottomOverflowPercentRes = getBottomOverflowPercent(); // console.log('获取顶部溢出的百分比', BottomOverflowPercentRes);
4780
-
4781
- var hideBarRes = hideBar(); // console.log('如果都是 0 ,隐藏滚动条', hideBarRes);
4782
-
4783
- if (!hideBarRes) {
4784
- setBarTop(); // const setBarTopRes = setBarTop();
4785
- // console.log('设置顶部状态栏', setBarTopRes);
4786
-
4787
- setBarBottom(); // const setBarBottomRes = setBarBottom();
4788
- // console.log('设置底部状态栏', setBarBottomRes);
4789
- } // 获取图片距离顶部的距离
4790
-
4791
-
4792
- function getBox2To() {
4793
- var translates = window.getComputedStyle(imgBoxInstance, null).transform;
4794
- var tanslateY = parseFloat(translates.substring(6).split(',')[5]);
4795
- return tanslateY;
4796
- } // 获取图片的高度
4797
-
4798
-
4799
- function getImgHeight() {
4800
- var _a;
4801
-
4802
- return (_a = imgInstance) === null || _a === void 0 ? void 0 : _a.clientHeight;
4803
- } // 获取窗口的高度
4804
-
4805
-
4806
- function getWindowHeight() {
4807
- return document.querySelector("." + containerClassName).clientHeight; // window.outerHeight;
4808
- } // 获取顶部溢出的百分比
4809
-
4810
-
4811
- function getTopOverflowPercent() {
4812
- var box2To = Box2ToRes;
4813
-
4814
- if (box2To >= 0) {
4815
- box2To = 0;
4816
- }
4817
-
4818
- box2To = Math.abs(box2To); // 图片高度
4819
-
4820
- var imgHeight = ImgHeightRes;
4821
- var per = floatToPercent(box2To / imgHeight, 2);
4822
- return {
4823
- box2To: box2To,
4824
- per: per
4825
- };
4826
- } // 获取底部溢出的百分比
4714
+ function genCustomConsole(_a) {
4715
+ var _b = (_a === void 0 ? {} : _a).prefix,
4716
+ prefix = _b === void 0 ? '' : _b;
4717
+ var methods = ['log', 'info', 'warn', 'error'];
4718
+ var newConsole = Object.create(null);
4719
+ methods.forEach(function (method) {
4720
+ newConsole[method] = function () {
4721
+ var _a, _b;
4827
4722
 
4723
+ var argu = [];
4828
4724
 
4829
- function getBottomOverflowPercent() {
4830
- // 窗口高度
4831
- var windowHeight = WindowHeightRes; // 图片高度
4832
-
4833
- var imgHeight = ImgHeightRes; // 上面溢出的高度
4834
-
4835
- var box2To = Box2ToRes; // 底部
4836
-
4837
- var remindImageHeight = windowHeight - box2To;
4838
- var box2ToBottom = imgHeight - remindImageHeight;
4839
-
4840
- if (box2ToBottom <= 0) {
4841
- box2ToBottom = 0;
4725
+ for (var _i = 0; _i < arguments.length; _i++) {
4726
+ argu[_i] = arguments[_i];
4842
4727
  }
4843
4728
 
4844
- var per = floatToPercent(box2ToBottom / imgHeight, 2);
4845
- return {
4846
- box2ToBottom: box2ToBottom,
4847
- per: per
4848
- };
4849
- } // 如果都是 0 ,隐藏滚动条
4850
-
4851
-
4852
- function hideBar() {
4853
- var box2To = TopOverflowPercentRes.box2To;
4854
- var box2ToBottom = BottomOverflowPercentRes.box2ToBottom;
4855
-
4856
- if (!box2To && !box2ToBottom) {
4857
- return addInlineStyle({
4858
- inlineStyle: "\n ." + containerClassName + "::after {\n display: none;\n }\n ",
4859
- id: barIsHideId
4860
- });
4729
+ if (prefix) {
4730
+ (_a = console)[method].apply(_a, __spreadArrays([prefix], argu));
4861
4731
  } else {
4862
- addInlineStyle({
4863
- inlineStyle: "\n ." + containerClassName + "::after {\n display: block;\n }\n ",
4864
- id: barIsHideId
4865
- });
4732
+ (_b = console)[method].apply(_b, argu);
4866
4733
  }
4867
-
4868
- return false;
4869
- } // 设置顶部状态栏
4870
-
4871
-
4872
- function setBarTop() {
4873
- var per = TopOverflowPercentRes.per;
4874
- return addInlineStyle({
4875
- inlineStyle: "\n ." + containerClassName + "::after {\n top: " + per + ";\n }\n ",
4876
- id: barTopId
4877
- });
4878
- } // 设置底部状态栏
4879
-
4880
-
4881
- function setBarBottom() {
4882
- var per = BottomOverflowPercentRes.per;
4883
- return addInlineStyle({
4884
- inlineStyle: "\n ." + containerClassName + "::after {\n bottom: " + per + ";\n }\n ",
4885
- id: barBottomId
4886
- });
4887
- }
4888
- }, 25);
4889
- return true;
4890
- }
4891
- /**
4892
- * @method calcContainImageSizeAndPosition
4893
- * @description 计算适配容器宽度的图片的尺寸、距离顶部的距离。如果高度不足以占满容器,使其垂直居中;如果高度比容器长,由上向下铺开。
4894
- * @param {Number} oriImageWidth 图片原始宽度
4895
- * @param {Number} oriImageHeight 图片原始高度
4896
- * @param {Number} viewportWidth 可视窗口宽度
4897
- * @param {Number} viewportHeight 可视窗口高度
4898
- * @return {Object} 结果 {"targetImageWidth":375,"targetImageHeight":375,"top":218.5,"wPer":1.25}
4899
- */
4900
-
4901
- function calcContainImageSizeAndPosition(_a) {
4902
- var _b = _a === void 0 ? {} : _a,
4903
- _c = _b.oriImageWidth,
4904
- oriImageWidth = _c === void 0 ? 0 : _c,
4905
- _d = _b.oriImageHeight,
4906
- oriImageHeight = _d === void 0 ? 0 : _d,
4907
- _e = _b.viewportWidth,
4908
- viewportWidth = _e === void 0 ? 0 : _e,
4909
- _f = _b.viewportHeight,
4910
- viewportHeight = _f === void 0 ? 0 : _f;
4911
-
4912
- var targetImageWidth = viewportWidth;
4913
- var _g = [0, 0, 0],
4914
- targetImageHeight = _g[0],
4915
- top = _g[1],
4916
- wPer = _g[2]; // 比例
4917
-
4918
- wPer = viewportWidth / oriImageWidth; // 1.+ 1.1 1.5
4919
-
4920
- targetImageHeight = oriImageHeight * wPer;
4921
-
4922
- if (targetImageHeight < viewportHeight) {
4923
- var doubleGap = viewportHeight - targetImageHeight;
4924
- top = doubleGap / 2;
4925
- }
4926
-
4927
- return {
4928
- targetImageWidth: targetImageWidth,
4929
- targetImageHeight: targetImageHeight,
4930
- top: top,
4931
- wPer: wPer
4932
- };
4734
+ };
4735
+ });
4736
+ return newConsole;
4933
4737
  }
4934
4738
 
4935
- export { addClass, addInlineStyle, calLongestCommonSubsequence, calLongestCommonSubstring, calcContainImageSizeAndPosition, camelCase2Underscore, camelCaseToKebabCase, cancelBubble, clearHtml, compatibleExist, customScrollBarForTransformEle, cutCHSString, debounce, deepCopyObject, doFn, floatFixed, floatToPercent, friendlyInterval, generateRndNum, generateUniqueNum, getBrowserType, getCookie, getDomain, getHashQueryParam, getLocalStorage, getPerformance, getQueryParam, getSearchQueryParam, getSessionStorage, getUrlParam, hasClass, inRate, isJsonString, isNumber, isSafePWAEnv, join, loadCSS, loadScript, mNow, newLine, removeClass, renderTable, resetForm, setCookie, setLocalStorage, setSessionStorage, throttle, trim$1 as trim, updateQueryStringParameter, windowLoaded };
4739
+ export { addClass, addInlineStyle, calLongestCommonSubsequence, calLongestCommonSubstring, camelCase2Underscore, camelCaseToKebabCase, cancelBubble, clearHtml, cutCHSString, debounce, deepCopyObject, doFn, floatFixed, floatToPercent, friendlyInterval, genCustomConsole, generateRndNum, generateUniqueNum, getBrowserType, getCookie, getDomain, getHashQueryParam, getLocalStorage, getPerformance, getQueryParam, getSessionStorage, getUrlParam, hasClass, inRate, isJsonString, isNumber, isSafePWAEnv, loadCSS, loadScript, mNow, mTrim, newLine, removeClass, setCookie, setLocalStorage, setSessionStorage, throttle, updateQueryParam, windowLoaded };