mx-ui-template 0.1.4 → 0.1.6
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.
|
@@ -1,20 +1,44 @@
|
|
|
1
|
-
function
|
|
1
|
+
function i(t, e, o) {
|
|
2
|
+
const n = document.createElement("canvas");
|
|
3
|
+
n.width = e, n.height = e;
|
|
4
|
+
const r = n.getContext("2d");
|
|
5
|
+
return r.beginPath(), r.arc(e / 2, e / 2, e / 2, 0, Math.PI * 2), r.fillStyle = a(t), r.fill(), r.font = `bold ${e / o}rem Arial`, r.textAlign = "center", r.textBaseline = "middle", r.fillStyle = "#fff", r.fillText(
|
|
6
|
+
t.charAt(0).toUpperCase() + t.charAt(1).toUpperCase(),
|
|
7
|
+
e / 2,
|
|
8
|
+
e / 2
|
|
9
|
+
), n.toDataURL("image/png");
|
|
10
|
+
}
|
|
11
|
+
function a(t) {
|
|
12
|
+
let e = 0;
|
|
13
|
+
for (let n = 0; n < t.length; n++)
|
|
14
|
+
e = t.charCodeAt(n) + ((e << 5) - e);
|
|
15
|
+
return "#" + (e & 16777215).toString(16).padStart(6, "0");
|
|
16
|
+
}
|
|
17
|
+
function c(t, e) {
|
|
2
18
|
if (!t) return "";
|
|
3
|
-
const
|
|
4
|
-
if (Number.isNaN(
|
|
5
|
-
const n =
|
|
6
|
-
|
|
19
|
+
const o = t instanceof Date ? t : new Date(t);
|
|
20
|
+
if (Number.isNaN(o.getTime())) return "";
|
|
21
|
+
const n = e?.locale ?? void 0, r = e?.options ?? {
|
|
22
|
+
year: "numeric",
|
|
23
|
+
month: "2-digit",
|
|
24
|
+
day: "2-digit"
|
|
25
|
+
};
|
|
26
|
+
return new Intl.DateTimeFormat(n, r).format(o);
|
|
7
27
|
}
|
|
8
|
-
function
|
|
28
|
+
function l(t) {
|
|
9
29
|
return t == null ? !0 : typeof t == "string" ? t.trim() === "" : Array.isArray(t) ? t.length === 0 : typeof t == "object" ? Object.keys(t).length === 0 : !1;
|
|
10
30
|
}
|
|
11
|
-
const
|
|
12
|
-
formatDate:
|
|
13
|
-
isEmpty:
|
|
31
|
+
const f = {
|
|
32
|
+
formatDate: c,
|
|
33
|
+
isEmpty: l,
|
|
34
|
+
generateTextAvatar: i,
|
|
35
|
+
generateColor: a
|
|
14
36
|
};
|
|
15
37
|
export {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
38
|
+
f as default,
|
|
39
|
+
c as formatDate,
|
|
40
|
+
a as generateColor,
|
|
41
|
+
i as generateTextAvatar,
|
|
42
|
+
l as isEmpty,
|
|
43
|
+
f as utils
|
|
20
44
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(n,i){typeof exports=="object"&&typeof module<"u"?i(exports):typeof define=="function"&&define.amd?define(["exports"],i):(n=typeof globalThis<"u"?globalThis:n||self,i(n.MxUIUtils={}))})(this,(function(n){"use strict";function i(t,e,a){const o=document.createElement("canvas");o.width=e,o.height=e;const r=o.getContext("2d");return r.beginPath(),r.arc(e/2,e/2,e/2,0,Math.PI*2),r.fillStyle=f(t),r.fill(),r.font=`bold ${e/a}rem Arial`,r.textAlign="center",r.textBaseline="middle",r.fillStyle="#fff",r.fillText(t.charAt(0).toUpperCase()+t.charAt(1).toUpperCase(),e/2,e/2),o.toDataURL("image/png")}function f(t){let e=0;for(let o=0;o<t.length;o++)e=t.charCodeAt(o)+((e<<5)-e);return"#"+(e&16777215).toString(16).padStart(6,"0")}function l(t,e){if(!t)return"";const a=t instanceof Date?t:new Date(t);if(Number.isNaN(a.getTime()))return"";const o=e?.locale??void 0,r=e?.options??{year:"numeric",month:"2-digit",day:"2-digit"};return new Intl.DateTimeFormat(o,r).format(a)}function c(t){return t==null?!0:typeof t=="string"?t.trim()==="":Array.isArray(t)?t.length===0:typeof t=="object"?Object.keys(t).length===0:!1}const d={formatDate:l,isEmpty:c,generateTextAvatar:i,generateColor:f};n.default=d,n.formatDate=l,n.generateColor=f,n.generateTextAvatar=i,n.isEmpty=c,n.utils=d,Object.defineProperties(n,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
|
package/package.json
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mx-ui-template",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.6",
|
|
5
|
+
"description": "根据名称生产头像",
|
|
5
6
|
"type": "module",
|
|
6
7
|
"main": "./dist/mx-ui-template.umd.cjs",
|
|
7
8
|
"module": "./dist/mx-ui-template.js",
|
|
@@ -12,7 +13,8 @@
|
|
|
12
13
|
"require": "./dist/mx-ui-template.umd.cjs",
|
|
13
14
|
"types": "./dist/index.d.ts"
|
|
14
15
|
},
|
|
15
|
-
"./style.css": "./dist/mx-ui-template.css"
|
|
16
|
+
"./style.css": "./dist/mx-ui-template.css",
|
|
17
|
+
"./utils": "./dist/mx-ui-template_utils.js"
|
|
16
18
|
},
|
|
17
19
|
"files": [
|
|
18
20
|
"dist"
|