@dicebear/core 8.0.2 → 9.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/LICENSE +1 -1
- package/lib/core.js +6 -11
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -1
- package/lib/types.d.ts +2 -5
- package/lib/utils/license.d.ts +1 -2
- package/lib/utils/license.js +9 -27
- package/package.json +3 -4
package/LICENSE
CHANGED
package/lib/core.js
CHANGED
|
@@ -2,7 +2,6 @@ import * as svgUtils from './utils/svg.js';
|
|
|
2
2
|
import { merge as mergeOptions } from './utils/options.js';
|
|
3
3
|
import { create as createPrng } from './utils/prng.js';
|
|
4
4
|
import * as license from './utils/license.js';
|
|
5
|
-
import { toFormat } from '@dicebear/converter';
|
|
6
5
|
import { getBackgroundColors } from './utils/color.js';
|
|
7
6
|
export function createAvatar(style, options = {}) {
|
|
8
7
|
var _a, _b, _c, _d, _e;
|
|
@@ -11,7 +10,11 @@ export function createAvatar(style, options = {}) {
|
|
|
11
10
|
const result = style.create({ prng: prng, options });
|
|
12
11
|
const backgroundType = prng.pick((_a = options.backgroundType) !== null && _a !== void 0 ? _a : [], 'solid');
|
|
13
12
|
const { primary: primaryBackgroundColor, secondary: secondaryBackgroundColor, } = getBackgroundColors(prng, (_b = options.backgroundColor) !== null && _b !== void 0 ? _b : [], backgroundType);
|
|
14
|
-
const backgroundRotation = prng.integer(((_c = options.backgroundRotation) === null || _c === void 0 ? void 0 : _c.length)
|
|
13
|
+
const backgroundRotation = prng.integer(((_c = options.backgroundRotation) === null || _c === void 0 ? void 0 : _c.length)
|
|
14
|
+
? Math.min(...options.backgroundRotation)
|
|
15
|
+
: 0, ((_d = options.backgroundRotation) === null || _d === void 0 ? void 0 : _d.length)
|
|
16
|
+
? Math.max(...options.backgroundRotation)
|
|
17
|
+
: 0);
|
|
15
18
|
if (options.size) {
|
|
16
19
|
result.attributes.width = options.size.toString();
|
|
17
20
|
result.attributes.height = options.size.toString();
|
|
@@ -41,7 +44,6 @@ export function createAvatar(style, options = {}) {
|
|
|
41
44
|
}
|
|
42
45
|
const attributes = svgUtils.createAttrString(result);
|
|
43
46
|
const metadata = license.xml(style);
|
|
44
|
-
const exif = license.exif(style);
|
|
45
47
|
const svg = `<svg ${attributes}>${metadata}${result.body}</svg>`;
|
|
46
48
|
return {
|
|
47
49
|
toString: () => svg,
|
|
@@ -58,15 +60,8 @@ export function createAvatar(style, options = {}) {
|
|
|
58
60
|
},
|
|
59
61
|
});
|
|
60
62
|
},
|
|
61
|
-
|
|
63
|
+
toDataUri: () => {
|
|
62
64
|
return `data:image/svg+xml;utf8,${encodeURIComponent(svg)}`;
|
|
63
65
|
},
|
|
64
|
-
...toFormat(svg, 'svg'),
|
|
65
|
-
png: ({ includeExif = false } = {}) => {
|
|
66
|
-
return toFormat(svg, 'png', includeExif ? exif : undefined);
|
|
67
|
-
},
|
|
68
|
-
jpeg: ({ includeExif = false } = {}) => {
|
|
69
|
-
return toFormat(svg, 'jpeg', includeExif ? exif : undefined);
|
|
70
|
-
},
|
|
71
66
|
};
|
|
72
67
|
}
|
package/lib/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* DiceBear (@dicebear/core)
|
|
3
3
|
*
|
|
4
4
|
* Code licensed under MIT (https://github.com/dicebear/dicebear/blob/main/LICENSE)
|
|
5
|
-
* Copyright (c)
|
|
5
|
+
* Copyright (c) 2024 Florian Körner
|
|
6
6
|
*/
|
|
7
7
|
import * as license from './utils/license.js';
|
|
8
8
|
import * as escape from './utils/escape.js';
|
package/lib/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* DiceBear (@dicebear/core)
|
|
3
3
|
*
|
|
4
4
|
* Code licensed under MIT (https://github.com/dicebear/dicebear/blob/main/LICENSE)
|
|
5
|
-
* Copyright (c)
|
|
5
|
+
* Copyright (c) 2024 Florian Körner
|
|
6
6
|
*/
|
|
7
7
|
import * as license from './utils/license.js';
|
|
8
8
|
import * as escape from './utils/escape.js';
|
package/lib/types.d.ts
CHANGED
|
@@ -1,17 +1,14 @@
|
|
|
1
1
|
import type { JSONSchema7 } from 'json-schema';
|
|
2
|
-
import type { Result as ConverterResult } from '@dicebear/converter';
|
|
3
2
|
export interface ResultConvertOptions {
|
|
4
3
|
includeExif?: boolean;
|
|
5
4
|
}
|
|
6
|
-
export interface Result
|
|
7
|
-
png(options?: ResultConvertOptions): ConverterResult;
|
|
8
|
-
jpeg(options?: ResultConvertOptions): ConverterResult;
|
|
5
|
+
export interface Result {
|
|
9
6
|
toString(): string;
|
|
10
7
|
toJson(): {
|
|
11
8
|
svg: string;
|
|
12
9
|
extra: Record<string, unknown>;
|
|
13
10
|
};
|
|
14
|
-
|
|
11
|
+
toDataUri(): string;
|
|
15
12
|
}
|
|
16
13
|
export type BackgroundType = 'solid' | 'gradientLinear';
|
|
17
14
|
export interface Options {
|
package/lib/utils/license.d.ts
CHANGED
package/lib/utils/license.js
CHANGED
|
@@ -19,8 +19,12 @@ export function xml(style) {
|
|
|
19
19
|
'<rdf:Description>' +
|
|
20
20
|
(title ? `<dc:title>${_.xml(title)}</dc:title>` : '') +
|
|
21
21
|
(creator ? `<dc:creator>${_.xml(creator)}</dc:creator>` : '') +
|
|
22
|
-
(source
|
|
23
|
-
|
|
22
|
+
(source
|
|
23
|
+
? `<dc:source xsi:type="dcterms:URI">${_.xml((_g = (_f = style.meta) === null || _f === void 0 ? void 0 : _f.source) !== null && _g !== void 0 ? _g : '')}</dc:source>`
|
|
24
|
+
: '') +
|
|
25
|
+
(license
|
|
26
|
+
? `<dcterms:license xsi:type="dcterms:URI">${_.xml(license)}</dcterms:license>`
|
|
27
|
+
: '') +
|
|
24
28
|
(rights ? `<dc:rights>${_.xml(rights)}</dc:rights>` : '') +
|
|
25
29
|
'</rdf:Description>' +
|
|
26
30
|
'</rdf:RDF>' +
|
|
@@ -34,7 +38,9 @@ export function text(style) {
|
|
|
34
38
|
title += ` (${style.meta.source})`;
|
|
35
39
|
}
|
|
36
40
|
let result = '';
|
|
37
|
-
if (((_g = (_f = style.meta) === null || _f === void 0 ? void 0 : _f.license) === null || _g === void 0 ? void 0 : _g.name) !== 'MIT' &&
|
|
41
|
+
if (((_g = (_f = style.meta) === null || _f === void 0 ? void 0 : _f.license) === null || _g === void 0 ? void 0 : _g.name) !== 'MIT' &&
|
|
42
|
+
((_h = style.meta) === null || _h === void 0 ? void 0 : _h.creator) !== 'DiceBear' &&
|
|
43
|
+
((_j = style.meta) === null || _j === void 0 ? void 0 : _j.title)) {
|
|
38
44
|
result += 'Remix of ';
|
|
39
45
|
}
|
|
40
46
|
result += `${title} by ${creator}`;
|
|
@@ -46,27 +52,3 @@ export function text(style) {
|
|
|
46
52
|
}
|
|
47
53
|
return result;
|
|
48
54
|
}
|
|
49
|
-
export function exif(style) {
|
|
50
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
51
|
-
const copyright = text(style);
|
|
52
|
-
// https://www.iptc.org/std/photometadata/specification/IPTC-PhotoMetadata
|
|
53
|
-
// https://developers.google.com/search/docs/appearance/structured-data/image-license-metadata
|
|
54
|
-
return {
|
|
55
|
-
// Title
|
|
56
|
-
'IPTC:ObjectName': (_a = style.meta) === null || _a === void 0 ? void 0 : _a.title,
|
|
57
|
-
'XMP-dc:Title': (_b = style.meta) === null || _b === void 0 ? void 0 : _b.title,
|
|
58
|
-
// Copyright
|
|
59
|
-
'IPTC:CopyrightNotice': copyright,
|
|
60
|
-
'XMP-dc:Rights': copyright,
|
|
61
|
-
// Creator
|
|
62
|
-
'IPTC:By-line': (_c = style.meta) === null || _c === void 0 ? void 0 : _c.creator,
|
|
63
|
-
'XMP-dc:Creator': (_d = style.meta) === null || _d === void 0 ? void 0 : _d.creator,
|
|
64
|
-
// Credit
|
|
65
|
-
'IPTC:Credit': (_e = style.meta) === null || _e === void 0 ? void 0 : _e.creator,
|
|
66
|
-
'XMP-photoshop:Credit': (_f = style.meta) === null || _f === void 0 ? void 0 : _f.creator,
|
|
67
|
-
// Licensor
|
|
68
|
-
'XMP-plus:LicensorURL': (_g = style.meta) === null || _g === void 0 ? void 0 : _g.source,
|
|
69
|
-
// Rights
|
|
70
|
-
'XMP-xmpRights:WebStatement': (_j = (_h = style.meta) === null || _h === void 0 ? void 0 : _h.license) === null || _j === void 0 ? void 0 : _j.url,
|
|
71
|
-
};
|
|
72
|
-
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dicebear/core",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "9.0.0",
|
|
4
4
|
"description": "An avatar library for designers and developers.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"avatar",
|
|
@@ -32,7 +32,6 @@
|
|
|
32
32
|
"test": "uvu tests"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@dicebear/converter": "8.0.2",
|
|
36
35
|
"@types/json-schema": "^7.0.11"
|
|
37
36
|
},
|
|
38
37
|
"devDependencies": {
|
|
@@ -42,10 +41,10 @@
|
|
|
42
41
|
"uvu": "^0.5.6"
|
|
43
42
|
},
|
|
44
43
|
"engines": {
|
|
45
|
-
"node": ">=
|
|
44
|
+
"node": ">=18.0.0"
|
|
46
45
|
},
|
|
47
46
|
"publishConfig": {
|
|
48
47
|
"access": "public"
|
|
49
48
|
},
|
|
50
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "c9e66450840d4f29faee6362249348bb3d18798b"
|
|
51
50
|
}
|