hsu-utils 0.0.9 → 0.0.10
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/dist/hsu-utils.js +2 -2
- package/dist/hsu-utils.min.js +1 -1
- package/dist/hsu-utils.min.js.LICENSE.txt +1 -1
- package/es/GetStrWidth/index.d.ts +10 -1
- package/es/GetStrWidth/index.js +7 -5
- package/lib/GetStrWidth/index.d.ts +10 -1
- package/lib/GetStrWidth/index.js +8 -6
- package/package.json +4 -2
package/dist/hsu-utils.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
/*!
|
2
2
|
*
|
3
|
-
* hsu-utils v0.0.
|
3
|
+
* hsu-utils v0.0.9
|
4
4
|
*
|
5
5
|
* some front-end utils
|
6
6
|
*
|
@@ -95,7 +95,7 @@ eval("\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nexpo
|
|
95
95
|
\************************************/
|
96
96
|
/***/ ((__unused_webpack_module, exports) => {
|
97
97
|
|
98
|
-
eval("\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nfunction get_string_width(str) {\n
|
98
|
+
eval("\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nfunction get_string_width(str, font) {\n if (font === void 0) { font = {}; }\n var _a = font.style, style = _a === void 0 ? 'normal' : _a, _b = font.variant, variant = _b === void 0 ? 'normal' : _b, _c = font.weight, weight = _c === void 0 ? 'normal' : _c, _d = font.size, size = _d === void 0 ? 12 : _d, _e = font.lineHeight, lineHeight = _e === void 0 ? 1 : _e, _f = font.family, fontFamily = _f === void 0 ? '微软雅黑, \"Microsoft YaHei\", -apple-system' : _f;\n var canvas = document.createElement('canvas');\n var ctx = canvas.getContext('2d');\n ctx.font = \"\".concat(style, \" \").concat(variant, \" \").concat(weight, \" \").concat(size, \"px/\").concat(lineHeight, \" \").concat(fontFamily);\n var metrics = ctx.measureText(str);\n var width = +(+metrics.width.toFixed(2) + 0.01).toFixed(2);\n return width;\n}\nexports[\"default\"] = get_string_width;\n\n\n//# sourceURL=webpack://hsu-utils/./tools/GetStrWidth/index.ts?");
|
99
99
|
|
100
100
|
/***/ }),
|
101
101
|
|
package/dist/hsu-utils.min.js
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
/*! For license information please see hsu-utils.min.js.LICENSE.txt */
|
2
|
-
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports["hsu-utils"]=t():e["hsu-utils"]=t()}(this,(()=>(()=>{"use strict";var e={442:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0});var r="+",o="-",n="|",a=" ",u="";function
|
2
|
+
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports["hsu-utils"]=t():e["hsu-utils"]=t()}(this,(()=>(()=>{"use strict";var e={442:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0});var r="+",o="-",n="|",a=" ",u="";function i(e){for(var t=0,r=0,o=e;r<o.length;r++){var n=o[r];t+=n.charCodeAt(0)<128&&n.charCodeAt(0)>=0?1:2}return t}function f(e,t){void 0===t&&(t=!1);var n=e.length,a="";return e.forEach((function(e,i){a+=r+function(e){for(var t="",r=0;r<=e;r++)t+=o;return t}(e+1),a+=i===n-1?r+(t?u:"\n"):u})),a}function l(e){for(var t="",r=0;r<=e;r++)t+=a;return t}t.default=function(e,t){var r=e.length,o=function(e){for(var t=Object.keys(e[0]).map((function(e){return+e})),r=0,o=e;r<o.length;r++)o[r].forEach((function(e,r){var o=i(e.toString());t[r]=Math.max(o,t[r])}));return t}(e),c="";e.forEach((function(e,t){t<=1&&(c+=f(o)),c+=function(e,t){var r=e.length,o="";return e.forEach((function(e,f){var c=t[f],s="";isNaN(+c)?s+=a+(null!=c?c:"")+l(e-i((null!=c?c:"").toString())):s+=l(e-i(c.toString()))+c+a,o+=n+s,o+=f===r-1?n+"\n":u})),o}(o,e),t===r-1&&(c+=f(o,!0))})),console.log(c),t&&t(c)}},84:(e,t)=>{function r(e,t){void 0===t&&(t={});var r,o,n=t.benchmark,a=t.textType,u=void 0===a?"lowercase":a,i={lowercase:["零","一","二","三","四","五","六","七","八","九"],uppercase:["零","壹","贰","叁","肆","伍","陆","柒","捌","玖"]},f={lowercase:["","十","百","千"],uppercase:["","拾","佰","仟"]},l={lowercase:["","万","亿","兆"],uppercase:["","万","亿","兆"]},c="";if(n&&(e=+(e*=n).toFixed(4)),e>1e16)return"超出转换范围";var s=e.toString();if(r=s.split(".")[0],o=s.split(".")[1],r)for(var d=0,p=0;p<r.length;p++){var v=r.length-p-1,y=+r[p],h=Math.floor(v/4),b=v%(4*(0===h?1:h));0==+r[p]?d++:(d>0&&(c+=i[u][0],d=0),c+="".concat(i[u][y]+f[u][b]),v%4==0&&(c+=l[u][h]))}if(o){c+="点";for(p=0;p<o.length;p++){var g=+o[p];0==+o[p]?c+="".concat(i[u][0]):c+="".concat(i[u][g])}}return""===c&&(c+=i[u][0]),c}Object.defineProperty(t,"__esModule",{value:!0}),t.toChineseNum=void 0,t.toChineseNum=r;var o={toChineseNum:r};t.default=o},819:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0});var o=r(243);t.default=function e(t){if("date"===(0,o.Typeof)(t))return new Date(t.toISOString());if("formdata"===(0,o.Typeof)(t)){var r=t,n=new FormData;return r.forEach((function(e,t){n.append(t,e)})),n}if(Array.isArray(t))return t.map((function(t){return"object"==typeof t?e(t):t}));if(t&&"object"===(0,o.Typeof)(t)){var a=t,u={};return Object.keys(a).forEach((function(t){var r=a[t];u[t]="object"==typeof r?e(r):r})),u}return t}},962:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ObjEqual=t.ValEqual=t.TypeEqual=void 0;var o=r(243);function n(e,t){return(0,o.Typeof)(e)===(0,o.Typeof)(t)}function a(e,t){return null===e&&void 0===t||void 0===e&&null===t||("object"==typeof e&&"object"==typeof t?u(e,t):"function"==typeof e&&"function"==typeof t?JSON.stringify(e)===JSON.stringify(t):e===t)}function u(e,t){var r=!1,n=(0,o.deepCopy)(e),u=(0,o.deepCopy)(t);if(null!==n&&null!==u){if(Array.isArray(n)&&Array.isArray(u))if(n.sort(),u.sort(),n.length!==u.length)r=!1;else{r=!0;for(var i=0;i<n.length&&(r=a(n[i],u[i]));i++);}else if("object"==typeof n&&"object"==typeof u)if(Object.keys(n).length!==Object.keys(u).length)r=!1;else for(var f in r=!0,n)if(!(r=a(n[f],u[f])))break}else null===n&&null===u&&(r=!0);return r}t.TypeEqual=n,t.ValEqual=a,t.ObjEqual=u;var i={ValEqual:a,TypeEqual:n,ObjEqual:u};t.default=i},285:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e,t){void 0===t&&(t={});var r=t.style,o=void 0===r?"normal":r,n=t.variant,a=void 0===n?"normal":n,u=t.weight,i=void 0===u?"normal":u,f=t.size,l=void 0===f?12:f,c=t.lineHeight,s=void 0===c?1:c,d=t.family,p=void 0===d?'微软雅黑, "Microsoft YaHei", -apple-system':d,v=document.createElement("canvas").getContext("2d");return v.font="".concat(o," ").concat(a," ").concat(i," ").concat(l,"px/").concat(s," ").concat(p),+(+v.measureText(e).width.toFixed(2)+.01).toFixed(2)}},332:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e){var t=Object.prototype.toString.call(e),r=new RegExp(" (.+?)]");return t.match(r)[1].toLowerCase()}},243:function(e,t,r){var o=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.ConvertNumbers=t.get_string_width=t.Typeof=t.Equal=t.deepCopy=t.console_table=void 0;var n=o(r(442));t.console_table=n.default;var a=o(r(819));t.deepCopy=a.default;var u=o(r(962));t.Equal=u.default;var i=o(r(332));t.Typeof=i.default;var f=o(r(285));t.get_string_width=f.default;var l=o(r(84));t.ConvertNumbers=l.default}},t={};var r=function r(o){var n=t[o];if(void 0!==n)return n.exports;var a=t[o]={exports:{}};return e[o].call(a.exports,a,a.exports,r),a.exports}(243);return r})()));
|
@@ -1 +1,10 @@
|
|
1
|
-
|
1
|
+
interface Font {
|
2
|
+
style?: string;
|
3
|
+
variant?: string;
|
4
|
+
weight?: string;
|
5
|
+
size?: number;
|
6
|
+
lineHeight?: number;
|
7
|
+
family?: string;
|
8
|
+
}
|
9
|
+
export default function get_string_width(str: string, font?: Font): number;
|
10
|
+
export {};
|
package/es/GetStrWidth/index.js
CHANGED
@@ -1,7 +1,9 @@
|
|
1
|
-
export default function get_string_width(str) {
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
}
|
1
|
+
export default function get_string_width(str, font = {}) {
|
2
|
+
const { style = 'normal', variant = 'normal', weight = 'normal', size = 12, lineHeight = 1, family: fontFamily = '微软雅黑, "Microsoft YaHei", -apple-system' } = font;
|
3
|
+
const canvas = document.createElement('canvas');
|
4
|
+
const ctx = canvas.getContext('2d');
|
5
|
+
ctx.font = `${style} ${variant} ${weight} ${size}px/${lineHeight} ${fontFamily}`;
|
6
|
+
const metrics = ctx.measureText(str);
|
7
|
+
const width = +(+metrics.width.toFixed(2) + 0.01).toFixed(2);
|
6
8
|
return width;
|
7
9
|
}
|
@@ -1 +1,10 @@
|
|
1
|
-
|
1
|
+
interface Font {
|
2
|
+
style?: string;
|
3
|
+
variant?: string;
|
4
|
+
weight?: string;
|
5
|
+
size?: number;
|
6
|
+
lineHeight?: number;
|
7
|
+
family?: string;
|
8
|
+
}
|
9
|
+
export default function get_string_width(str: string, font?: Font): number;
|
10
|
+
export {};
|
package/lib/GetStrWidth/index.js
CHANGED
@@ -1,11 +1,13 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
function get_string_width(str) {
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
3
|
+
function get_string_width(str, font) {
|
4
|
+
if (font === void 0) { font = {}; }
|
5
|
+
var _a = font.style, style = _a === void 0 ? 'normal' : _a, _b = font.variant, variant = _b === void 0 ? 'normal' : _b, _c = font.weight, weight = _c === void 0 ? 'normal' : _c, _d = font.size, size = _d === void 0 ? 12 : _d, _e = font.lineHeight, lineHeight = _e === void 0 ? 1 : _e, _f = font.family, fontFamily = _f === void 0 ? '微软雅黑, "Microsoft YaHei", -apple-system' : _f;
|
6
|
+
var canvas = document.createElement('canvas');
|
7
|
+
var ctx = canvas.getContext('2d');
|
8
|
+
ctx.font = "".concat(style, " ").concat(variant, " ").concat(weight, " ").concat(size, "px/").concat(lineHeight, " ").concat(fontFamily);
|
9
|
+
var metrics = ctx.measureText(str);
|
10
|
+
var width = +(+metrics.width.toFixed(2) + 0.01).toFixed(2);
|
9
11
|
return width;
|
10
12
|
}
|
11
13
|
exports.default = get_string_width;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "hsu-utils",
|
3
|
-
"version": "0.0.
|
3
|
+
"version": "0.0.10",
|
4
4
|
"description": "some front-end utils",
|
5
5
|
"repository": "git@github.com:VitaTsui/hsu-utils.git",
|
6
6
|
"author": "VitaHsu <vitahsu7@gmail.com>",
|
@@ -32,7 +32,8 @@
|
|
32
32
|
"test": "jest",
|
33
33
|
"publish:patch": "yarn build && yarn publish --new-version patch",
|
34
34
|
"publish:minor": "yarn build && yarn publish --new-version minor",
|
35
|
-
"publish:major": "yarn build && yarn publish --new-version major"
|
35
|
+
"publish:major": "yarn build && yarn publish --new-version major",
|
36
|
+
"publish:alpha": "yarn build && yarn publish --tag alpha"
|
36
37
|
},
|
37
38
|
"devDependencies": {
|
38
39
|
"@jest/globals": "^29.5.0",
|
@@ -40,6 +41,7 @@
|
|
40
41
|
"@types/jest": "^29.5.2",
|
41
42
|
"cross-env": "^7.0.3",
|
42
43
|
"jest": "^29.5.0",
|
44
|
+
"jest-canvas-mock": "^2.5.2",
|
43
45
|
"jest-environment-jsdom": "^29.5.0",
|
44
46
|
"jsdom": "^22.1.0",
|
45
47
|
"rimraf": "^5.0.1",
|