mazey 1.4.39 → 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
@@ -3016,6 +3016,14 @@ function __spreadArrays() {
3016
3016
  */
3017
3017
 
3018
3018
  function calLongestCommonSubstring(aStr, bStr) {
3019
+ if (aStr === void 0) {
3020
+ aStr = '';
3021
+ }
3022
+
3023
+ if (bStr === void 0) {
3024
+ bStr = '';
3025
+ }
3026
+
3019
3027
  var aLen = aStr.length;
3020
3028
  var bLen = bStr.length; // 创建二维数组并且深拷贝
3021
3029
 
@@ -3050,6 +3058,14 @@ function calLongestCommonSubstring(aStr, bStr) {
3050
3058
  */
3051
3059
 
3052
3060
  function calLongestCommonSubsequence(aStr, bStr) {
3061
+ if (aStr === void 0) {
3062
+ aStr = '';
3063
+ }
3064
+
3065
+ if (bStr === void 0) {
3066
+ bStr = '';
3067
+ }
3068
+
3053
3069
  var aLen = aStr.length;
3054
3070
  var bLen = bStr.length; // 创建二维数组并且深拷贝
3055
3071
 
@@ -3090,148 +3106,178 @@ function calLongestCommonSubsequence(aStr, bStr) {
3090
3106
  return maxLong;
3091
3107
  }
3092
3108
  /**
3093
- * @method join
3094
- * @description 将一系列值连接成固定字符分隔的字符串 123,456 => 123 - 456。
3095
- * @param {String} joinStr 连接值的字符串。
3096
- * @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
3097
3113
  * */
3098
3114
 
3099
- function join(joinStr) {
3100
- var rest = [];
3101
-
3102
- for (var _i = 1; _i < arguments.length; _i++) {
3103
- rest[_i - 1] = arguments[_i];
3115
+ function getQueryParam(param) {
3116
+ if (param === void 0) {
3117
+ param = '';
3104
3118
  }
3105
3119
 
3106
- var ret = '';
3107
- var len = joinStr.length;
3108
-
3109
- for (var _a = 0, rest_1 = rest; _a < rest_1.length; _a++) {
3110
- var v = rest_1[_a];
3120
+ var reg = new RegExp('(^|&)' + param + '=([^&]*)(&|$)');
3121
+ var r = location.search.substr(1).match(reg);
3111
3122
 
3112
- if (v) {
3113
- ret += "" + joinStr + v;
3114
- }
3115
- }
3116
-
3117
- if (ret) {
3118
- ret = ret.substring(len);
3123
+ if (r !== null) {
3124
+ return decodeURIComponent(unescape(r[2]));
3119
3125
  }
3120
3126
 
3121
- return ret;
3127
+ return '';
3122
3128
  }
3123
3129
  /**
3124
- * @method renderTable
3125
- * @description 渲染表格
3126
- * @param {DOM Object} tbID
3127
- * @param {Array} data
3128
- * @param {Array} property
3129
- */
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
+ * */
3130
3136
 
3131
- function renderTable(tbID, data, property) {
3132
- if (tbID === void 0) {
3133
- tbID = null;
3137
+ function getUrlParam(url, param) {
3138
+ if (url === void 0) {
3139
+ url = '';
3134
3140
  }
3135
3141
 
3136
- if (data === void 0) {
3137
- data = [];
3142
+ if (param === void 0) {
3143
+ param = '';
3138
3144
  }
3139
3145
 
3140
- if (property === void 0) {
3141
- property = [];
3142
- }
3146
+ var result = {}; // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace
3147
+
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
+ // }
3143
3160
 
3144
- var TBODY = document.querySelector("#" + tbID + " tbody");
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
+ * */
3145
3171
 
3146
- function mNullToNA(str) {
3147
- return str === null ? 'N.A.' : str;
3172
+ function updateQueryParam(url, param, value) {
3173
+ if (url === void 0) {
3174
+ url = '';
3148
3175
  }
3149
3176
 
3150
- var content = '';
3151
- TBODY.innerHTML = ''; // 无数据
3177
+ if (param === void 0) {
3178
+ param = '';
3179
+ }
3152
3180
 
3153
- if (!data.length) {
3154
- content = "<tr><td colspan=\"" + property.length + "\">\u65E0\u6570\u636E</td></tr>";
3155
- } else {
3156
- for (var _a = [0, data.length], i = _a[0], max = _a[1]; i < max; ++i) {
3157
- var item = data[i];
3158
- content += '<tr>';
3181
+ if (value === void 0) {
3182
+ value = '';
3183
+ }
3159
3184
 
3160
- for (var _b = [0, property.length], i_1 = _b[0], max_1 = _b[1]; i_1 < max_1; ++i_1) {
3161
- content += "<td>" + mNullToNA(item[property[i_1]]) + "</td>";
3162
- }
3185
+ var re = new RegExp('([?&])' + param + '=.*?(&|$)', 'i');
3186
+ var separator = url.indexOf('?') !== -1 ? '&' : '?';
3163
3187
 
3164
- content += '</tr>';
3165
- }
3188
+ if (url.match(re)) {
3189
+ return url.replace(re, '$1' + param + '=' + value + '$2');
3190
+ } else {
3191
+ return url + separator + param + '=' + value;
3166
3192
  }
3167
-
3168
- TBODY.innerHTML = content;
3169
3193
  }
3170
3194
  /**
3171
3195
  * @method getHashQueryParam
3172
- * @description 获取地址栏 hash 后面的参数。
3173
- * @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
3174
3199
  */
3175
3200
 
3176
3201
  function getHashQueryParam(param) {
3177
- var hashs = window.location.hash.split('?');
3202
+ if (param === void 0) {
3203
+ param = '';
3204
+ }
3205
+
3206
+ var hashs = location.hash.split('?');
3178
3207
 
3179
3208
  if (hashs.length === 1) {
3180
- return null;
3209
+ return '';
3181
3210
  }
3182
3211
 
3183
3212
  var reg = new RegExp("(^|&)" + param + "=([^&]*)(&|$)");
3184
3213
  var ret = hashs[1].match(reg);
3185
- 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
+ }, '');
3186
3238
  }
3187
3239
  /**
3188
3240
  * @method camelCaseToKebabCase
3189
- * @description 驼峰转连接线。
3190
- * @param {String} camelCase
3241
+ * @description Transfer CamelCase to KebabCase.
3242
+ * @param {String} camelCase 'aBC' or 'ABC'
3243
+ * @return {String} 'a-b-c'
3191
3244
  * */
3192
3245
 
3193
3246
  function camelCaseToKebabCase(camelCase) {
3247
+ if (camelCase === void 0) {
3248
+ camelCase = '';
3249
+ }
3250
+
3194
3251
  var kebabCase = camelCase.replace(/([A-Z])/g, '-$1').toLowerCase();
3195
3252
  return kebabCase[0] === '-' ? kebabCase.substr(1) : kebabCase;
3196
3253
  }
3197
3254
  /**
3198
3255
  * @method camelCase2Underscore
3199
- * @description 驼峰转下划线。
3200
- * @param {String} camelCase
3256
+ * @description Transfer CamelCase to Underscore.
3257
+ * @param {String} camelCase 'aBC' or 'ABC'
3258
+ * @return {String} 'a_b_c'
3201
3259
  * */
3202
3260
 
3203
3261
  function camelCase2Underscore(camelCase) {
3262
+ if (camelCase === void 0) {
3263
+ camelCase = '';
3264
+ }
3265
+
3204
3266
  var kebabCase = camelCase.replace(/([A-Z])/g, '_$1').toLowerCase();
3205
3267
  return kebabCase[0] === '_' ? kebabCase.substr(1) : kebabCase;
3206
3268
  }
3207
3269
  /**
3208
- * @method getDomain
3209
- * @description 获取地址中的域名(及其他参数)。
3210
- * @param {String} url
3211
- * @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.
3212
3274
  * */
3213
3275
 
3214
- function getDomain(_a) {
3215
- var _b = _a === void 0 ? {} : _a,
3216
- _c = _b.url,
3217
- url = _c === void 0 ? '' : _c,
3218
- _d = _b.rules,
3219
- rules = _d === void 0 ? ['hostname'] : _d;
3220
-
3221
- var aEl = document.createElement('a');
3222
- aEl.href = url;
3223
- return rules.reduce(function (ret, v, index) {
3224
- ret += aEl[v];
3225
- return ret;
3226
- }, '');
3227
- }
3228
- /**
3229
- * @method trim
3230
- * @description 去除左右空格。
3231
- * @param {String} str 需要去除两边空格的字符串。
3232
- * */
3276
+ function mTrim(str) {
3277
+ if (str === void 0) {
3278
+ str = '';
3279
+ }
3233
3280
 
3234
- function trim$1(str) {
3235
3281
  str = str.replace(/^\s+/, ''); // 去除头部空格
3236
3282
 
3237
3283
  var end = str.length - 1;
@@ -3245,11 +3291,16 @@ function trim$1(str) {
3245
3291
  }
3246
3292
  /**
3247
3293
  * @method newLine
3248
- * @description html换行。
3249
- * @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 />`.
3250
3297
  * */
3251
3298
 
3252
3299
  function newLine(str) {
3300
+ if (str === void 0) {
3301
+ str = '';
3302
+ }
3303
+
3253
3304
  if (!str) {
3254
3305
  return '';
3255
3306
  }
@@ -3259,22 +3310,48 @@ function newLine(str) {
3259
3310
  }
3260
3311
  /**
3261
3312
  * @method deepCopyObject
3262
- * @description 对象深拷贝。
3263
- * @param {Object} obj 被拷贝的对象。
3264
- * @return {Object}
3313
+ * @description Clone Object deeply.
3314
+ * @param {Object} obj The value to clone.
3315
+ * @return {Object} Returns the deep cloned value.
3265
3316
  * */
3266
3317
 
3267
3318
  function deepCopyObject(obj) {
3268
3319
  return JSON.parse(JSON.stringify(obj));
3269
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
+ }
3270
3343
  /**
3271
3344
  * @method generateRndNum
3272
- * @description 生成随机数 mGenerateRndNum(7) => 7658495。
3273
- * @param {Number} n 随机数的长度
3274
- * @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.
3275
3348
  * */
3276
3349
 
3277
3350
  function generateRndNum(n) {
3351
+ if (n === void 0) {
3352
+ n = 5;
3353
+ }
3354
+
3278
3355
  var ret = '';
3279
3356
 
3280
3357
  while (n--) {
@@ -3290,36 +3367,15 @@ function generateRndNum(n) {
3290
3367
  * */
3291
3368
 
3292
3369
  function generateUniqueNum(n) {
3370
+ if (n === void 0) {
3371
+ n = 3;
3372
+ }
3373
+
3293
3374
  var _a = [mNow(), generateRndNum(n || 3)],
3294
3375
  now = _a[0],
3295
3376
  rnd = _a[1];
3296
3377
  return now + rnd;
3297
3378
  }
3298
- /**
3299
- * @method resetForm
3300
- * @description 重置表单输入值为原始(空)状态。
3301
- * @param {String} rest name1,name2,name3...NAME属性,可以多个。
3302
- * */
3303
-
3304
- function resetForm() {
3305
- var rest = [];
3306
-
3307
- for (var _i = 0; _i < arguments.length; _i++) {
3308
- rest[_i] = arguments[_i];
3309
- }
3310
-
3311
- for (var i = 0; i < rest.length; i++) {
3312
- var tagMz = document.getElementsByName(rest[i])[0]; // tag object
3313
-
3314
- var tagNameMz = tagMz.tagName.toLowerCase(); // tag name
3315
-
3316
- if (tagNameMz === 'input') {
3317
- tagMz.value = '';
3318
- } else if (tagNameMz === 'select') {
3319
- tagMz.options[0].selected = true;
3320
- }
3321
- }
3322
- }
3323
3379
  /**
3324
3380
  * @method floatToPercent
3325
3381
  * @description 浮点数转为百分比 0.2 => 20%。
@@ -3328,17 +3384,23 @@ function resetForm() {
3328
3384
  * */
3329
3385
 
3330
3386
  function floatToPercent(num, fixSize) {
3387
+ if (num === void 0) {
3388
+ num = 0;
3389
+ }
3390
+
3331
3391
  if (fixSize === void 0) {
3332
3392
  fixSize = 0;
3333
3393
  }
3334
3394
 
3395
+ var ret = '';
3396
+
3335
3397
  if (fixSize) {
3336
- num = (num * 100).toFixed(fixSize);
3398
+ ret = (num * 100).toFixed(fixSize);
3337
3399
  } else {
3338
- num = Math.floor(num * 100);
3400
+ ret = String(Math.floor(num * 100));
3339
3401
  }
3340
3402
 
3341
- return num + "%";
3403
+ return ret + "%";
3342
3404
  }
3343
3405
  /**
3344
3406
  * @method floatFixed
@@ -3346,23 +3408,11 @@ function floatToPercent(num, fixSize) {
3346
3408
  * */
3347
3409
 
3348
3410
  function floatFixed(num, size) {
3349
- return parseFloat(num).toFixed(size);
3350
- }
3351
- /**
3352
- * @method compatibleExist
3353
- * @description 不存在返回 ——。
3354
- * */
3355
-
3356
- function compatibleExist(instance, replaceStr) {
3357
- var ret = '';
3358
-
3359
- try {
3360
- ret = instance || replaceStr || '——';
3361
- } catch (e) {
3362
- ret = '——';
3411
+ if (size === void 0) {
3412
+ size = 0;
3363
3413
  }
3364
3414
 
3365
- return ret;
3415
+ return parseFloat(num).toFixed(size);
3366
3416
  }
3367
3417
  /**
3368
3418
  * @method cancelBubble
@@ -3609,7 +3659,7 @@ function friendlyInterval(_a) {
3609
3659
  /**
3610
3660
  * @method isNumber
3611
3661
  * @description 判断是否有效数字
3612
- * @param {Any} num 被判断的值
3662
+ * @param {*} num 被判断的值
3613
3663
  * @param {Boolean} isNaNAsNumber 是否 NaN 算数字(默认不算)
3614
3664
  * @param {Boolean} isUnFiniteAsNumber 是否 无限 算数字(默认不算)
3615
3665
  * @return {Boolean} true 是数字
@@ -3642,84 +3692,6 @@ function isNumber(num, _a) {
3642
3692
 
3643
3693
  return ret;
3644
3694
  }
3645
- /**
3646
- * @method updateQueryStringParameter
3647
- * @description 替换或添加地址栏参数。
3648
- * */
3649
-
3650
- function updateQueryStringParameter(uri, key, value) {
3651
- var re = new RegExp('([?&])' + key + '=.*?(&|$)', 'i');
3652
- var separator = uri.indexOf('?') !== -1 ? '&' : '?';
3653
-
3654
- if (uri.match(re)) {
3655
- return uri.replace(re, '$1' + key + '=' + value + '$2');
3656
- } else {
3657
- return uri + separator + key + '=' + value;
3658
- }
3659
- }
3660
- /**
3661
- * @method isJsonString
3662
- * @description 判断是否合法 JSON 字符串。
3663
- * */
3664
-
3665
- function isJsonString(str) {
3666
- try {
3667
- if (_typeof_1(JSON.parse(str)) === 'object') {
3668
- return true;
3669
- }
3670
- } catch (e) {
3671
- /* pass */
3672
- }
3673
-
3674
- return false;
3675
- }
3676
- /**
3677
- * @method getUrlParam
3678
- * @description 链接参数
3679
- * @param {String} sUrl 链接
3680
- * @param {String} sKey 参数
3681
- * */
3682
-
3683
- function getUrlParam(sUrl, sKey) {
3684
- var result = {};
3685
- sUrl.replace(/\??(\w+)=([^&]*)&?/g, function (a, k, v) {
3686
- if (result[k] !== undefined) {
3687
- var t = result[k];
3688
- result[k] = [].concat(t, v);
3689
- } else {
3690
- result[k] = v;
3691
- }
3692
- });
3693
-
3694
- if (sKey === undefined) {
3695
- return result;
3696
- } else {
3697
- return result[sKey] || '';
3698
- }
3699
- }
3700
- /**
3701
- * @method getSearchQueryParam
3702
- * @description 地址栏参数。
3703
- * */
3704
-
3705
- function getSearchQueryParam(name) {
3706
- var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)');
3707
- var r = window.location.search.substr(1).match(reg);
3708
-
3709
- if (r != null) {
3710
- return decodeURIComponent(unescape(r[2]));
3711
- }
3712
-
3713
- return null;
3714
- }
3715
- /**
3716
- * @method getQueryParam
3717
- * @description 地址栏参数,getSearchQueryParam 的别名。
3718
- * */
3719
-
3720
- function getQueryParam(name) {
3721
- return getSearchQueryParam(name);
3722
- }
3723
3695
  /**
3724
3696
  * @method doFn
3725
3697
  * @description 执行有效函数
@@ -3761,7 +3733,7 @@ function setSessionStorage(key, value) {
3761
3733
  * @method getSessionStorage
3762
3734
  * @description 存储数据到 sessionStorage
3763
3735
  * @param {String} key 键
3764
- * @return {Any} 返回值
3736
+ * @return {*} 返回值
3765
3737
  * */
3766
3738
 
3767
3739
  function getSessionStorage(key) {
@@ -3797,7 +3769,7 @@ function setLocalStorage(key, value) {
3797
3769
  * @method getLocalStorage
3798
3770
  * @description 存储数据到 localStorage
3799
3771
  * @param {String} key 键
3800
- * @return {Any} 返回值
3772
+ * @return {*} 返回值
3801
3773
  * */
3802
3774
 
3803
3775
  function getLocalStorage(key) {
@@ -4090,7 +4062,7 @@ function getCookie(name) {
4090
4062
  if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
4091
4063
  }
4092
4064
 
4093
- return null;
4065
+ return '';
4094
4066
  }
4095
4067
  /**
4096
4068
  * @method getPerformance
@@ -4731,232 +4703,6 @@ function addInlineStyle(_a) {
4731
4703
 
4732
4704
  return true;
4733
4705
  }
4734
- /**
4735
- * @method customScrollBarForTransformEle
4736
- * @description 为进行变换(transform)的元素设置滚动条
4737
- * @param {String} containerClassName 进行变换(transform)的元素↓的容器(Father)的类名
4738
- * @param {String} imgBoxClassName 图片的容器(transform It's YOU!)的类名
4739
- * @param {String} imgBoxDom 图片的容器 Dom 对象
4740
- * @param {String} imgClassName 图片的类名
4741
- * @param {Object} imgDom 图片 Dom 对象
4742
- * @param {String} action 操作类型 hide 隐藏指定 `containerClassName` 滚动条
4743
- * @param {String} customStyle 滚动条的定制样式,会覆盖默认样式
4744
- * @return {Boolean} 设置成功
4745
- */
4746
-
4747
- function customScrollBarForTransformEle(_a) {
4748
- var _b = _a === void 0 ? {} : _a,
4749
- _c = _b.containerClassName,
4750
- containerClassName = _c === void 0 ? '' : _c,
4751
- _d = _b.imgBoxClassName,
4752
- imgBoxClassName = _d === void 0 ? '' : _d,
4753
- _e = _b.imgBoxDom,
4754
- imgBoxDom = _e === void 0 ? null : _e,
4755
- _f = _b.imgClassName,
4756
- imgClassName = _f === void 0 ? '' : _f,
4757
- _g = _b.imgDom,
4758
- imgDom = _g === void 0 ? null : _g,
4759
- _h = _b.action,
4760
- action = _h === void 0 ? '' : _h,
4761
- _j = _b.customStyle,
4762
- customStyle = _j === void 0 ? '' : _j; // 变量
4763
-
4764
-
4765
- var barIsHideId = 'bar-is-hide';
4766
- var barTopId = 'bar-top';
4767
- var barBottomId = 'bar-bottom';
4768
-
4769
- if (action === 'hide') {
4770
- addInlineStyle({
4771
- inlineStyle: "\n ." + containerClassName + "::after {\n display: none;\n }\n ",
4772
- id: barIsHideId
4773
- });
4774
- return true;
4775
- }
4776
-
4777
- setTimeout(function () {
4778
- // 样式初始化
4779
- addInlineStyle({
4780
- 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 ",
4781
- id: 'bar-init'
4782
- });
4783
- var imgInstance = imgDom || document.querySelector("." + imgClassName);
4784
-
4785
- if (!imgInstance) {
4786
- console.warn('Need element\'s Dom instance.');
4787
- return false;
4788
- }
4789
-
4790
- var imgBoxInstance = imgBoxDom || document.querySelector("." + imgBoxClassName);
4791
-
4792
- if (!imgBoxInstance) {
4793
- console.warn('Need element box\'s Dom instance.');
4794
- return false;
4795
- }
4796
-
4797
- var Box2ToRes = getBox2To(); // console.log('获取图片距离顶部的距离', Box2ToRes);
4798
-
4799
- var ImgHeightRes = getImgHeight(); // console.log('获取图片的高度', ImgHeightRes);
4800
-
4801
- var WindowHeightRes = getWindowHeight(); // console.log('获取窗口的高度', WindowHeightRes);
4802
-
4803
- var TopOverflowPercentRes = getTopOverflowPercent(); // console.log('获取顶部溢出的百分比', TopOverflowPercentRes);
4804
-
4805
- var BottomOverflowPercentRes = getBottomOverflowPercent(); // console.log('获取顶部溢出的百分比', BottomOverflowPercentRes);
4806
-
4807
- var hideBarRes = hideBar(); // console.log('如果都是 0 ,隐藏滚动条', hideBarRes);
4808
-
4809
- if (!hideBarRes) {
4810
- setBarTop(); // const setBarTopRes = setBarTop();
4811
- // console.log('设置顶部状态栏', setBarTopRes);
4812
-
4813
- setBarBottom(); // const setBarBottomRes = setBarBottom();
4814
- // console.log('设置底部状态栏', setBarBottomRes);
4815
- } // 获取图片距离顶部的距离
4816
-
4817
-
4818
- function getBox2To() {
4819
- var translates = window.getComputedStyle(imgBoxInstance, null).transform;
4820
- var tanslateY = parseFloat(translates.substring(6).split(',')[5]);
4821
- return tanslateY;
4822
- } // 获取图片的高度
4823
-
4824
-
4825
- function getImgHeight() {
4826
- var _a;
4827
-
4828
- return (_a = imgInstance) === null || _a === void 0 ? void 0 : _a.clientHeight;
4829
- } // 获取窗口的高度
4830
-
4831
-
4832
- function getWindowHeight() {
4833
- return document.querySelector("." + containerClassName).clientHeight; // window.outerHeight;
4834
- } // 获取顶部溢出的百分比
4835
-
4836
-
4837
- function getTopOverflowPercent() {
4838
- var box2To = Box2ToRes;
4839
-
4840
- if (box2To >= 0) {
4841
- box2To = 0;
4842
- }
4843
-
4844
- box2To = Math.abs(box2To); // 图片高度
4845
-
4846
- var imgHeight = ImgHeightRes;
4847
- var per = floatToPercent(box2To / imgHeight, 2);
4848
- return {
4849
- box2To: box2To,
4850
- per: per
4851
- };
4852
- } // 获取底部溢出的百分比
4853
-
4854
-
4855
- function getBottomOverflowPercent() {
4856
- // 窗口高度
4857
- var windowHeight = WindowHeightRes; // 图片高度
4858
-
4859
- var imgHeight = ImgHeightRes; // 上面溢出的高度
4860
-
4861
- var box2To = Box2ToRes; // 底部
4862
-
4863
- var remindImageHeight = windowHeight - box2To;
4864
- var box2ToBottom = imgHeight - remindImageHeight;
4865
-
4866
- if (box2ToBottom <= 0) {
4867
- box2ToBottom = 0;
4868
- }
4869
-
4870
- var per = floatToPercent(box2ToBottom / imgHeight, 2);
4871
- return {
4872
- box2ToBottom: box2ToBottom,
4873
- per: per
4874
- };
4875
- } // 如果都是 0 ,隐藏滚动条
4876
-
4877
-
4878
- function hideBar() {
4879
- var box2To = TopOverflowPercentRes.box2To;
4880
- var box2ToBottom = BottomOverflowPercentRes.box2ToBottom;
4881
-
4882
- if (!box2To && !box2ToBottom) {
4883
- return addInlineStyle({
4884
- inlineStyle: "\n ." + containerClassName + "::after {\n display: none;\n }\n ",
4885
- id: barIsHideId
4886
- });
4887
- } else {
4888
- addInlineStyle({
4889
- inlineStyle: "\n ." + containerClassName + "::after {\n display: block;\n }\n ",
4890
- id: barIsHideId
4891
- });
4892
- }
4893
-
4894
- return false;
4895
- } // 设置顶部状态栏
4896
-
4897
-
4898
- function setBarTop() {
4899
- var per = TopOverflowPercentRes.per;
4900
- return addInlineStyle({
4901
- inlineStyle: "\n ." + containerClassName + "::after {\n top: " + per + ";\n }\n ",
4902
- id: barTopId
4903
- });
4904
- } // 设置底部状态栏
4905
-
4906
-
4907
- function setBarBottom() {
4908
- var per = BottomOverflowPercentRes.per;
4909
- return addInlineStyle({
4910
- inlineStyle: "\n ." + containerClassName + "::after {\n bottom: " + per + ";\n }\n ",
4911
- id: barBottomId
4912
- });
4913
- }
4914
- }, 25);
4915
- return true;
4916
- }
4917
- /**
4918
- * @method calcContainImageSizeAndPosition
4919
- * @description 计算适配容器宽度的图片的尺寸、距离顶部的距离。如果高度不足以占满容器,使其垂直居中;如果高度比容器长,由上向下铺开。
4920
- * @param {Number} oriImageWidth 图片原始宽度
4921
- * @param {Number} oriImageHeight 图片原始高度
4922
- * @param {Number} viewportWidth 可视窗口宽度
4923
- * @param {Number} viewportHeight 可视窗口高度
4924
- * @return {Object} 结果 {"targetImageWidth":375,"targetImageHeight":375,"top":218.5,"wPer":1.25}
4925
- */
4926
-
4927
- function calcContainImageSizeAndPosition(_a) {
4928
- var _b = _a === void 0 ? {} : _a,
4929
- _c = _b.oriImageWidth,
4930
- oriImageWidth = _c === void 0 ? 0 : _c,
4931
- _d = _b.oriImageHeight,
4932
- oriImageHeight = _d === void 0 ? 0 : _d,
4933
- _e = _b.viewportWidth,
4934
- viewportWidth = _e === void 0 ? 0 : _e,
4935
- _f = _b.viewportHeight,
4936
- viewportHeight = _f === void 0 ? 0 : _f;
4937
-
4938
- var targetImageWidth = viewportWidth;
4939
- var _g = [0, 0, 0],
4940
- targetImageHeight = _g[0],
4941
- top = _g[1],
4942
- wPer = _g[2]; // 比例
4943
-
4944
- wPer = viewportWidth / oriImageWidth; // 1.+ 1.1 1.5
4945
-
4946
- targetImageHeight = oriImageHeight * wPer;
4947
-
4948
- if (targetImageHeight < viewportHeight) {
4949
- var doubleGap = viewportHeight - targetImageHeight;
4950
- top = doubleGap / 2;
4951
- }
4952
-
4953
- return {
4954
- targetImageWidth: targetImageWidth,
4955
- targetImageHeight: targetImageHeight,
4956
- top: top,
4957
- wPer: wPer
4958
- };
4959
- }
4960
4706
  /**
4961
4707
  * @method genCustomConsole
4962
4708
  * @description 生成自定义控制台打印
@@ -4967,8 +4713,7 @@ function calcContainImageSizeAndPosition(_a) {
4967
4713
 
4968
4714
  function genCustomConsole(_a) {
4969
4715
  var _b = (_a === void 0 ? {} : _a).prefix,
4970
- prefix = _b === void 0 ? '' : _b; // ...
4971
-
4716
+ prefix = _b === void 0 ? '' : _b;
4972
4717
  var methods = ['log', 'info', 'warn', 'error'];
4973
4718
  var newConsole = Object.create(null);
4974
4719
  methods.forEach(function (method) {
@@ -4991,4 +4736,4 @@ function genCustomConsole(_a) {
4991
4736
  return newConsole;
4992
4737
  }
4993
4738
 
4994
- export { addClass, addInlineStyle, calLongestCommonSubsequence, calLongestCommonSubstring, calcContainImageSizeAndPosition, camelCase2Underscore, camelCaseToKebabCase, cancelBubble, clearHtml, compatibleExist, customScrollBarForTransformEle, cutCHSString, debounce, deepCopyObject, doFn, floatFixed, floatToPercent, friendlyInterval, genCustomConsole, 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 };