@dicebear/core 5.0.0-alpha.26 → 5.0.0-alpha.29
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/core.js +3 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/types.d.ts +1 -0
- package/lib/utils/escape.d.ts +0 -1
- package/lib/utils/escape.js +0 -4
- package/lib/utils/license.js +0 -1
- package/lib/utils/prng.js +7 -0
- package/lib/utils/svg.d.ts +3 -9
- package/lib/utils/svg.js +17 -5
- package/package.json +3 -3
package/lib/core.js
CHANGED
|
@@ -31,7 +31,9 @@ export function createAvatar(style, options = {}) {
|
|
|
31
31
|
if (options.radius || options.clip) {
|
|
32
32
|
result.body = svgUtils.addViewboxMask(result, (_b = options.radius) !== null && _b !== void 0 ? _b : 0);
|
|
33
33
|
}
|
|
34
|
-
|
|
34
|
+
// Reduces the occurrence of ID collisions when rendering multiple avatars on one HTML page.
|
|
35
|
+
result.body = svgUtils.randomizeIds(result, prng.seed);
|
|
36
|
+
const attributes = svgUtils.createAttrString(result);
|
|
35
37
|
const description = '<desc>Created with dicebear.com</desc>';
|
|
36
38
|
const metadata = license.xml(style);
|
|
37
39
|
const exif = license.exif(style);
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
package/lib/types.d.ts
CHANGED
|
@@ -29,6 +29,7 @@ export interface Prng {
|
|
|
29
29
|
bool(likelihood?: number): boolean;
|
|
30
30
|
integer(min: number, max: number): number;
|
|
31
31
|
pick<T>(arr: T[]): T;
|
|
32
|
+
string(length: number, characters?: string): string;
|
|
32
33
|
}
|
|
33
34
|
export declare type StyleSchema = JSONSchema7;
|
|
34
35
|
export declare type StyleOptions<O extends {}> = Partial<O & Options>;
|
package/lib/utils/escape.d.ts
CHANGED
package/lib/utils/escape.js
CHANGED
package/lib/utils/license.js
CHANGED
|
@@ -14,7 +14,6 @@ export function xml(style) {
|
|
|
14
14
|
? `<cc:license rdf:resource="${_.xml(style.meta.license.url)}" />`
|
|
15
15
|
: '';
|
|
16
16
|
return ('<metadata' +
|
|
17
|
-
' id="license"' +
|
|
18
17
|
' xmlns:dc="http://purl.org/dc/elements/1.1/"' +
|
|
19
18
|
' xmlns:cc="http://creativecommons.org/ns#"' +
|
|
20
19
|
' xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">' +
|
package/lib/utils/prng.js
CHANGED
|
@@ -35,5 +35,12 @@ export function create(seed) {
|
|
|
35
35
|
pick(arr) {
|
|
36
36
|
return arr[integer(0, arr.length - 1)];
|
|
37
37
|
},
|
|
38
|
+
string(length, characters = 'abcdefghijklmnopqrstuvwxyz1234567890') {
|
|
39
|
+
let str = '';
|
|
40
|
+
for (let i = 0; i < length; i++) {
|
|
41
|
+
str += characters[integer(0, characters.length - 1)];
|
|
42
|
+
}
|
|
43
|
+
return str;
|
|
44
|
+
},
|
|
38
45
|
};
|
|
39
46
|
}
|
package/lib/utils/svg.d.ts
CHANGED
|
@@ -1,10 +1,4 @@
|
|
|
1
|
-
import type { StyleCreateResult
|
|
2
|
-
declare type CreateGroupProps = {
|
|
3
|
-
children: string;
|
|
4
|
-
x: number;
|
|
5
|
-
y: number;
|
|
6
|
-
};
|
|
7
|
-
export declare function createGroup({ children, x, y }: CreateGroupProps): string;
|
|
1
|
+
import type { StyleCreateResult } from '../types.js';
|
|
8
2
|
export declare function getViewBox(result: StyleCreateResult): {
|
|
9
3
|
x: number;
|
|
10
4
|
y: number;
|
|
@@ -17,5 +11,5 @@ export declare function addTranslate(result: StyleCreateResult, x?: number, y?:
|
|
|
17
11
|
export declare function addRotate(result: StyleCreateResult, rotate: number): string;
|
|
18
12
|
export declare function addFlip(result: StyleCreateResult): string;
|
|
19
13
|
export declare function addViewboxMask(result: StyleCreateResult, radius: number): string;
|
|
20
|
-
export declare function createAttrString(
|
|
21
|
-
export
|
|
14
|
+
export declare function createAttrString(result: StyleCreateResult): string;
|
|
15
|
+
export declare function randomizeIds(result: StyleCreateResult, seed: string): string;
|
package/lib/utils/svg.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import * as escape from './escape.js';
|
|
2
|
-
|
|
3
|
-
return `<g transform="translate(${x}, ${y})">${children}</g>`;
|
|
4
|
-
}
|
|
2
|
+
import { create as createPrng } from './prng.js';
|
|
5
3
|
export function getViewBox(result) {
|
|
6
4
|
let viewBox = result.attributes['viewBox'].split(' ');
|
|
7
5
|
let x = parseInt(viewBox[0]);
|
|
@@ -49,9 +47,23 @@ export function addViewboxMask(result, radius) {
|
|
|
49
47
|
`</mask>` +
|
|
50
48
|
`<g mask="url(#viewboxMask)">${result.body}</g>`);
|
|
51
49
|
}
|
|
52
|
-
export function createAttrString(
|
|
53
|
-
attributes = {
|
|
50
|
+
export function createAttrString(result) {
|
|
51
|
+
const attributes = {
|
|
52
|
+
xmlns: 'http://www.w3.org/2000/svg',
|
|
53
|
+
...result.attributes,
|
|
54
|
+
};
|
|
54
55
|
return Object.keys(attributes)
|
|
55
56
|
.map((attr) => `${escape.xml(attr)}="${escape.xml(attributes[attr])}"`)
|
|
56
57
|
.join(' ');
|
|
57
58
|
}
|
|
59
|
+
export function randomizeIds(result, seed) {
|
|
60
|
+
const prng = createPrng(JSON.stringify({
|
|
61
|
+
attributes: result.attributes,
|
|
62
|
+
seed,
|
|
63
|
+
}));
|
|
64
|
+
const ids = {};
|
|
65
|
+
return result.body.replace(/(id="|url\(#)([a-z0-9-_]+)([")])/gi, (match, m1, m2, m3) => {
|
|
66
|
+
ids[m2] = ids[m2] || prng.string(8);
|
|
67
|
+
return `${m1}${ids[m2]}${m3}`;
|
|
68
|
+
});
|
|
69
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dicebear/core",
|
|
3
|
-
"version": "5.0.0-alpha.
|
|
3
|
+
"version": "5.0.0-alpha.29",
|
|
4
4
|
"description": "An avatar library for designers and developers.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"avatar",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"test": "uvu tests"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@dicebear/converter": "^5.0.0-alpha.
|
|
34
|
+
"@dicebear/converter": "^5.0.0-alpha.29",
|
|
35
35
|
"@types/json-schema": "^7.0.7"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
@@ -46,5 +46,5 @@
|
|
|
46
46
|
"publishConfig": {
|
|
47
47
|
"access": "public"
|
|
48
48
|
},
|
|
49
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "775410bda059fa21dcb79b38c72ebadb80896243"
|
|
50
50
|
}
|