@dicebear/initials 5.0.3 → 5.1.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/LICENSE +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.js +13 -4
- package/lib/schema.js +10 -0
- package/lib/types.d.ts +1 -0
- package/lib/utils/convertColor.d.ts +7 -0
- package/lib/utils/convertColor.js +9 -0
- package/package.json +3 -3
package/LICENSE
CHANGED
package/lib/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* DiceBear Initials (@dicebear/initials)
|
|
3
3
|
*
|
|
4
4
|
* Code licensed under MIT (https://github.com/dicebear/dicebear/blob/v4/packages/initials/LICENSE)
|
|
5
|
-
* Copyright (c)
|
|
5
|
+
* Copyright (c) 2023 Florian Körner
|
|
6
6
|
*/
|
|
7
7
|
import type { StyleCreate, StyleMeta } from '@dicebear/core';
|
|
8
8
|
import type { Options } from './types.js';
|
package/lib/index.js
CHANGED
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
* DiceBear Initials (@dicebear/initials)
|
|
3
3
|
*
|
|
4
4
|
* Code licensed under MIT (https://github.com/dicebear/dicebear/blob/v4/packages/initials/LICENSE)
|
|
5
|
-
* Copyright (c)
|
|
5
|
+
* Copyright (c) 2023 Florian Körner
|
|
6
6
|
*/
|
|
7
7
|
import { getInitials } from './utils/initials.js';
|
|
8
|
+
import { convertColor } from './utils/convertColor.js';
|
|
8
9
|
export const meta = {
|
|
9
10
|
title: 'Initials',
|
|
10
11
|
creator: 'Florian Körner',
|
|
@@ -15,20 +16,28 @@ export const meta = {
|
|
|
15
16
|
},
|
|
16
17
|
};
|
|
17
18
|
export const create = ({ prng, options }) => {
|
|
18
|
-
var _a, _b, _c, _d, _e;
|
|
19
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
19
20
|
const fontFamily = (_b = (_a = options.fontFamily) === null || _a === void 0 ? void 0 : _a.join(', ')) !== null && _b !== void 0 ? _b : 'Arial, sans-serif';
|
|
20
21
|
const fontSize = (_c = options.fontSize) !== null && _c !== void 0 ? _c : 50;
|
|
21
22
|
const fontWeight = (_d = options.fontWeight) !== null && _d !== void 0 ? _d : 400;
|
|
22
|
-
const
|
|
23
|
+
const textColor = convertColor((_f = prng.pick((_e = options.textColor) !== null && _e !== void 0 ? _e : [])) !== null && _f !== void 0 ? _f : 'ffffff');
|
|
24
|
+
const initials = getInitials(prng.seed.trim()).slice(0, (_g = options.chars) !== null && _g !== void 0 ? _g : 2);
|
|
23
25
|
// prettier-ignore
|
|
24
26
|
const svg = [
|
|
25
|
-
`<text x="50%" y="50%" font-family="${fontFamily}" font-size="${fontSize}"
|
|
27
|
+
`<text x="50%" y="50%" font-family="${fontFamily}" font-size="${fontSize}" font-weight="${fontWeight}" fill="${textColor}" text-anchor="middle" dy="${(fontSize * .356).toFixed(3)}">${initials}</text>`,
|
|
26
28
|
].join('');
|
|
27
29
|
return {
|
|
28
30
|
attributes: {
|
|
29
31
|
viewBox: '0 0 100 100',
|
|
30
32
|
},
|
|
31
33
|
body: svg,
|
|
34
|
+
extra: () => ({
|
|
35
|
+
fontFamily,
|
|
36
|
+
fontSize,
|
|
37
|
+
fontWeight,
|
|
38
|
+
textColor,
|
|
39
|
+
initials
|
|
40
|
+
})
|
|
32
41
|
};
|
|
33
42
|
};
|
|
34
43
|
export { schema } from './schema.js';
|
package/lib/schema.js
CHANGED
|
@@ -26,6 +26,16 @@ export const schema = {
|
|
|
26
26
|
'f4511e',
|
|
27
27
|
],
|
|
28
28
|
},
|
|
29
|
+
textColor: {
|
|
30
|
+
type: 'array',
|
|
31
|
+
items: {
|
|
32
|
+
type: 'string',
|
|
33
|
+
pattern: '^(transparent|[a-fA-F0-9]{6})$',
|
|
34
|
+
},
|
|
35
|
+
default: [
|
|
36
|
+
'ffffff'
|
|
37
|
+
],
|
|
38
|
+
},
|
|
29
39
|
fontFamily: {
|
|
30
40
|
type: 'array',
|
|
31
41
|
minItems: 1,
|
package/lib/types.d.ts
CHANGED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Do not change this file manually! This file was generated with the "Dicebear Exporter"-Plugin for Figma.
|
|
3
|
+
*
|
|
4
|
+
* Plugin: https://www.figma.com/community/plugin/1005765655729342787
|
|
5
|
+
* File: https://www.figma.com/file/BRj9eonsORJ7GIUdm8gnu5
|
|
6
|
+
*/
|
|
7
|
+
export declare function convertColor(color: string): string;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Do not change this file manually! This file was generated with the "Dicebear Exporter"-Plugin for Figma.
|
|
3
|
+
*
|
|
4
|
+
* Plugin: https://www.figma.com/community/plugin/1005765655729342787
|
|
5
|
+
* File: https://www.figma.com/file/BRj9eonsORJ7GIUdm8gnu5
|
|
6
|
+
*/
|
|
7
|
+
export function convertColor(color) {
|
|
8
|
+
return 'transparent' === color ? color : `#${color}`;
|
|
9
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dicebear/initials",
|
|
3
|
-
"version": "5.0
|
|
3
|
+
"version": "5.1.0",
|
|
4
4
|
"description": "Initials avatar style for DiceBear",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"dicebear"
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"test": "uvu tests"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@dicebear/core": "^5.0
|
|
32
|
+
"@dicebear/core": "^5.1.0",
|
|
33
33
|
"@tsconfig/recommended": "^1.0.1",
|
|
34
34
|
"del-cli": "^4.0.1",
|
|
35
35
|
"typescript": "^4.6.3",
|
|
@@ -44,5 +44,5 @@
|
|
|
44
44
|
"publishConfig": {
|
|
45
45
|
"access": "public"
|
|
46
46
|
},
|
|
47
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "4f9e4686aa33809026d6ce25c4a5f2d0750d59f4"
|
|
48
48
|
}
|