@dicebear/core 5.0.0-alpha.2 → 5.0.0-alpha.20
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.d.ts +2 -0
- package/lib/core.js +48 -0
- package/lib/index.d.ts +10 -0
- package/lib/index.js +10 -0
- package/lib/schema.d.ts +2 -0
- package/lib/schema.js +71 -0
- package/{dist → lib}/types.d.ts +62 -54
- package/lib/types.js +1 -0
- package/lib/utils/escape.d.ts +2 -0
- package/lib/utils/escape.js +12 -0
- package/lib/utils/license.d.ts +3 -0
- package/lib/utils/license.js +51 -0
- package/lib/utils/options.d.ts +3 -0
- package/lib/utils/options.js +32 -0
- package/{dist → lib}/utils/prng.d.ts +2 -2
- package/lib/utils/prng.js +39 -0
- package/lib/utils/svg.d.ts +21 -0
- package/lib/utils/svg.js +57 -0
- package/package.json +19 -21
- package/dist/core.d.ts +0 -3
- package/dist/index.d.ts +0 -12
- package/dist/index.es.js +0 -523
- package/dist/index.js +0 -530
- package/dist/index.umd.js +0 -8
- package/dist/options.d.ts +0 -18
- package/dist/utils/escape.d.ts +0 -1
- package/dist/utils/index.d.ts +0 -5
- package/dist/utils/options.d.ts +0 -2
- package/dist/utils/schema.d.ts +0 -5
- package/dist/utils/svg.d.ts +0 -39
package/LICENSE
CHANGED
package/lib/core.d.ts
ADDED
package/lib/core.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import * as svgUtils from './utils/svg.js';
|
|
2
|
+
import { merge as mergeOptions } from './utils/options.js';
|
|
3
|
+
import { create as createPrng } from './utils/prng.js';
|
|
4
|
+
import * as license from './utils/license.js';
|
|
5
|
+
import * as convert from '@dicebear/converter';
|
|
6
|
+
export function createAvatar(style, options = {}) {
|
|
7
|
+
var _a, _b;
|
|
8
|
+
options = mergeOptions(style, options);
|
|
9
|
+
const prng = createPrng(options.seed);
|
|
10
|
+
const result = style.create({ prng: prng, options });
|
|
11
|
+
const backgroundColor = prng.pick((_a = options.backgroundColor) !== null && _a !== void 0 ? _a : []);
|
|
12
|
+
if (options.size) {
|
|
13
|
+
result.attributes.width = options.size.toString();
|
|
14
|
+
result.attributes.height = options.size.toString();
|
|
15
|
+
}
|
|
16
|
+
if (options.scale !== undefined && options.scale !== 100) {
|
|
17
|
+
result.body = svgUtils.addScale(result, options.scale);
|
|
18
|
+
}
|
|
19
|
+
if (options.flip) {
|
|
20
|
+
result.body = svgUtils.addFlip(result);
|
|
21
|
+
}
|
|
22
|
+
if (options.rotate) {
|
|
23
|
+
result.body = svgUtils.addRotate(result, options.rotate);
|
|
24
|
+
}
|
|
25
|
+
if (options.translateX || options.translateY) {
|
|
26
|
+
result.body = svgUtils.addTranslate(result, options.translateX, options.translateY);
|
|
27
|
+
}
|
|
28
|
+
if (backgroundColor && backgroundColor !== 'transparent') {
|
|
29
|
+
result.body = svgUtils.addBackgroundColor(result, backgroundColor);
|
|
30
|
+
}
|
|
31
|
+
if (options.radius || options.clip) {
|
|
32
|
+
result.body = svgUtils.addViewboxMask(result, (_b = options.radius) !== null && _b !== void 0 ? _b : 0);
|
|
33
|
+
}
|
|
34
|
+
const attributes = svgUtils.createAttrString(result.attributes);
|
|
35
|
+
const description = '<desc>Created with dicebear.com</desc>';
|
|
36
|
+
const metadata = license.xml(style);
|
|
37
|
+
const exif = license.exif(style);
|
|
38
|
+
const avatar = `<svg ${attributes}>${description}${metadata}${result.body}</svg>`;
|
|
39
|
+
return Object.assign(avatar, {
|
|
40
|
+
svg: () => convert.toFormat(avatar, 'svg'),
|
|
41
|
+
png: ({ includeExif = false }) => {
|
|
42
|
+
return convert.toFormat(avatar, 'png', includeExif ? exif : undefined);
|
|
43
|
+
},
|
|
44
|
+
jpeg: ({ includeExif = false }) => {
|
|
45
|
+
return convert.toFormat(avatar, 'jpeg', includeExif ? exif : undefined);
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
}
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* DiceBear (@dicebear/core)
|
|
3
|
+
*
|
|
4
|
+
* Code licensed under MIT (https://github.com/dicebear/dicebear/blob/main/LICENSE)
|
|
5
|
+
* Copyright (c) 2022 Florian Körner
|
|
6
|
+
*/
|
|
7
|
+
export * from './core.js';
|
|
8
|
+
export * from './schema.js';
|
|
9
|
+
export * as license from './utils/license.js';
|
|
10
|
+
export * from './types.js';
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* DiceBear (@dicebear/core)
|
|
3
|
+
*
|
|
4
|
+
* Code licensed under MIT (https://github.com/dicebear/dicebear/blob/main/LICENSE)
|
|
5
|
+
* Copyright (c) 2022 Florian Körner
|
|
6
|
+
*/
|
|
7
|
+
export * from './core.js';
|
|
8
|
+
export * from './schema.js';
|
|
9
|
+
export * as license from './utils/license.js';
|
|
10
|
+
export * from './types.js';
|
package/lib/schema.d.ts
ADDED
package/lib/schema.js
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
export const schema = {
|
|
2
|
+
type: 'object',
|
|
3
|
+
$schema: 'http://json-schema.org/draft-07/schema#',
|
|
4
|
+
title: 'Options',
|
|
5
|
+
properties: {
|
|
6
|
+
seed: {
|
|
7
|
+
type: 'string',
|
|
8
|
+
examples: ['Jane Doe', 'John Doe'],
|
|
9
|
+
},
|
|
10
|
+
flip: {
|
|
11
|
+
type: 'boolean',
|
|
12
|
+
default: false,
|
|
13
|
+
examples: [true, false],
|
|
14
|
+
},
|
|
15
|
+
rotate: {
|
|
16
|
+
type: 'integer',
|
|
17
|
+
minimum: 0,
|
|
18
|
+
maximum: 360,
|
|
19
|
+
default: 0,
|
|
20
|
+
examples: [0, 45, 90, 135, 180, 225, 270, 315],
|
|
21
|
+
},
|
|
22
|
+
scale: {
|
|
23
|
+
type: 'integer',
|
|
24
|
+
minimum: 0,
|
|
25
|
+
maximum: 200,
|
|
26
|
+
default: 100,
|
|
27
|
+
examples: [50, 100, 150],
|
|
28
|
+
},
|
|
29
|
+
radius: {
|
|
30
|
+
type: 'integer',
|
|
31
|
+
minimum: 0,
|
|
32
|
+
maximum: 50,
|
|
33
|
+
default: 0,
|
|
34
|
+
examples: [0, 10, 20, 30, 40, 50],
|
|
35
|
+
},
|
|
36
|
+
size: {
|
|
37
|
+
type: 'integer',
|
|
38
|
+
minimum: 1,
|
|
39
|
+
examples: [128, 256, 512, 1024],
|
|
40
|
+
},
|
|
41
|
+
backgroundColor: {
|
|
42
|
+
type: 'array',
|
|
43
|
+
uniqueItems: true,
|
|
44
|
+
items: {
|
|
45
|
+
type: 'string',
|
|
46
|
+
pattern: '^([0-9a-zA-Z]+|#[a-fA-F0-9]{3}|#[a-fA-F0-9]{4}|#[a-fA-F0-9]{6}|#[a-fA-F0-9]{8})$',
|
|
47
|
+
},
|
|
48
|
+
examples: ['#FFD5DC', '#FFDFBF', '#C0EADE', '#B6E3F4', '#D1D4F9'],
|
|
49
|
+
},
|
|
50
|
+
translateX: {
|
|
51
|
+
type: 'integer',
|
|
52
|
+
minimum: -100,
|
|
53
|
+
maximum: 100,
|
|
54
|
+
default: 0,
|
|
55
|
+
examples: [-50, -25, 0, 25, 50],
|
|
56
|
+
},
|
|
57
|
+
translateY: {
|
|
58
|
+
type: 'integer',
|
|
59
|
+
minimum: -100,
|
|
60
|
+
maximum: 100,
|
|
61
|
+
default: 0,
|
|
62
|
+
examples: [-50, -25, 0, 25, 50],
|
|
63
|
+
},
|
|
64
|
+
clip: {
|
|
65
|
+
type: 'boolean',
|
|
66
|
+
default: true,
|
|
67
|
+
examples: [true, false],
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
additionalProperties: false,
|
|
71
|
+
};
|
package/{dist → lib}/types.d.ts
RENAMED
|
@@ -1,54 +1,62 @@
|
|
|
1
|
-
import type { JSONSchema7 } from 'json-schema';
|
|
2
|
-
import type {
|
|
3
|
-
export interface
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
export interface
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
export declare type
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
39
|
-
export
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
1
|
+
import type { JSONSchema7 } from 'json-schema';
|
|
2
|
+
import type { BinaryResult } from '@dicebear/converter';
|
|
3
|
+
export interface ResultConvertOptions {
|
|
4
|
+
includeExif?: boolean;
|
|
5
|
+
}
|
|
6
|
+
export declare type Result = string & {
|
|
7
|
+
svg(): BinaryResult;
|
|
8
|
+
png(options?: ResultConvertOptions): BinaryResult;
|
|
9
|
+
jpeg(options?: ResultConvertOptions): BinaryResult;
|
|
10
|
+
};
|
|
11
|
+
export interface Options {
|
|
12
|
+
seed?: string;
|
|
13
|
+
flip?: boolean;
|
|
14
|
+
rotate?: number;
|
|
15
|
+
scale?: number;
|
|
16
|
+
radius?: number;
|
|
17
|
+
size?: number;
|
|
18
|
+
backgroundColor?: string[];
|
|
19
|
+
translateX?: number;
|
|
20
|
+
translateY?: number;
|
|
21
|
+
clip?: boolean;
|
|
22
|
+
}
|
|
23
|
+
export interface Exif {
|
|
24
|
+
[key: string]: string;
|
|
25
|
+
}
|
|
26
|
+
export declare type SchemaDefaults = Record<string, unknown>;
|
|
27
|
+
export interface Prng {
|
|
28
|
+
seed: string;
|
|
29
|
+
bool(likelihood?: number): boolean;
|
|
30
|
+
integer(min: number, max: number): number;
|
|
31
|
+
pick<T>(arr: T[]): T;
|
|
32
|
+
}
|
|
33
|
+
export declare type StyleSchema = JSONSchema7;
|
|
34
|
+
export declare type StyleOptions<O extends {}> = Partial<O & Options>;
|
|
35
|
+
export interface StyleCreateProps<O> {
|
|
36
|
+
prng: Prng;
|
|
37
|
+
options: StyleOptions<O>;
|
|
38
|
+
}
|
|
39
|
+
export declare type StyleCreate<O extends {}> = (props: StyleCreateProps<O>) => StyleCreateResult;
|
|
40
|
+
export interface StyleCreateResultAttributes {
|
|
41
|
+
viewBox: string;
|
|
42
|
+
[key: string]: string;
|
|
43
|
+
}
|
|
44
|
+
export interface StyleCreateResult {
|
|
45
|
+
attributes: StyleCreateResultAttributes;
|
|
46
|
+
body: string;
|
|
47
|
+
}
|
|
48
|
+
export interface StyleMeta {
|
|
49
|
+
title?: string;
|
|
50
|
+
source?: string;
|
|
51
|
+
creator?: string;
|
|
52
|
+
homepage?: string;
|
|
53
|
+
license?: {
|
|
54
|
+
name: string;
|
|
55
|
+
url: string;
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
export interface Style<O extends {}> {
|
|
59
|
+
meta: StyleMeta;
|
|
60
|
+
schema: StyleSchema;
|
|
61
|
+
create: StyleCreate<O>;
|
|
62
|
+
}
|
package/lib/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export function xml(content) {
|
|
2
|
+
return content
|
|
3
|
+
.replace(/&/g, '&')
|
|
4
|
+
.replace(/'/g, ''')
|
|
5
|
+
.replace(/"/g, '"')
|
|
6
|
+
.replace(/</g, '<')
|
|
7
|
+
.replace(/>/g, '>');
|
|
8
|
+
}
|
|
9
|
+
export function md(content) {
|
|
10
|
+
const result = content.replace(/([\\`*_{}[\]()#+-.!])/g, '\\$1');
|
|
11
|
+
return xml(result);
|
|
12
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import * as _ from './escape.js';
|
|
2
|
+
export function xml(style) {
|
|
3
|
+
var _a, _b, _c, _d;
|
|
4
|
+
const xmlTitle = `<dc:title>${_.xml((_a = style.meta.title) !== null && _a !== void 0 ? _a : 'Unnamed')}</dc:title>`;
|
|
5
|
+
const xmlCreator = '<dc:creator>' +
|
|
6
|
+
`<cc:Agent rdf:about="${_.xml((_b = style.meta.homepage) !== null && _b !== void 0 ? _b : '')}">` +
|
|
7
|
+
`<dc:title>${_.xml((_c = style.meta.creator) !== null && _c !== void 0 ? _c : 'Unknown')}</dc:title>` +
|
|
8
|
+
'</cc:Agent>' +
|
|
9
|
+
'</dc:creator>';
|
|
10
|
+
const xmlSource = style.meta.source
|
|
11
|
+
? `<dc:source>${_.xml(style.meta.source)}</dc:source>`
|
|
12
|
+
: '';
|
|
13
|
+
const xmlLicense = ((_d = style.meta.license) === null || _d === void 0 ? void 0 : _d.url)
|
|
14
|
+
? `<cc:license rdf:resource="${_.xml(style.meta.license.url)}" />`
|
|
15
|
+
: '';
|
|
16
|
+
return ('<metadata' +
|
|
17
|
+
' id="license"' +
|
|
18
|
+
' xmlns:dc="http://purl.org/dc/elements/1.1/"' +
|
|
19
|
+
' xmlns:cc="http://creativecommons.org/ns#"' +
|
|
20
|
+
' xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">' +
|
|
21
|
+
'<rdf:RDF>' +
|
|
22
|
+
'<cc:Work>' +
|
|
23
|
+
xmlTitle +
|
|
24
|
+
xmlCreator +
|
|
25
|
+
xmlSource +
|
|
26
|
+
xmlLicense +
|
|
27
|
+
'</cc:Work>' +
|
|
28
|
+
'</rdf:RDF>' +
|
|
29
|
+
'</metadata>');
|
|
30
|
+
}
|
|
31
|
+
export function exif(style) {
|
|
32
|
+
var _a, _b, _c, _d;
|
|
33
|
+
const title = (_a = style.meta.title) !== null && _a !== void 0 ? _a : 'Unnamed';
|
|
34
|
+
const creator = (_b = style.meta.creator) !== null && _b !== void 0 ? _b : 'Unknown';
|
|
35
|
+
let copyright = `"${title}" by "${creator}"`;
|
|
36
|
+
if ((_c = style.meta.license) === null || _c === void 0 ? void 0 : _c.name) {
|
|
37
|
+
copyright += ` is licensed under "${style.meta.license.name}".`;
|
|
38
|
+
}
|
|
39
|
+
const exif = {
|
|
40
|
+
Copyright: copyright,
|
|
41
|
+
'XMP-dc:Title': title,
|
|
42
|
+
'XMP-dc:Creator': creator,
|
|
43
|
+
};
|
|
44
|
+
if (style.meta.source) {
|
|
45
|
+
exif['XMP-dc:Source'] = style.meta.source;
|
|
46
|
+
}
|
|
47
|
+
if ((_d = style.meta.license) === null || _d === void 0 ? void 0 : _d.url) {
|
|
48
|
+
exif['XMP-cc:License'] = style.meta.license.url;
|
|
49
|
+
}
|
|
50
|
+
return exif;
|
|
51
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { schema } from '../schema.js';
|
|
2
|
+
export function defaults(schema) {
|
|
3
|
+
var _a;
|
|
4
|
+
let result = {};
|
|
5
|
+
let props = (_a = schema.properties) !== null && _a !== void 0 ? _a : {};
|
|
6
|
+
Object.keys(props).forEach((key) => {
|
|
7
|
+
let val = props[key];
|
|
8
|
+
if (typeof val === 'object' && undefined !== val.default) {
|
|
9
|
+
if (Array.isArray(val.default)) {
|
|
10
|
+
result[key] = [...val.default];
|
|
11
|
+
}
|
|
12
|
+
else if (typeof val.default === 'object') {
|
|
13
|
+
result[key] = { ...val.default };
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
result[key] = val.default;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
return result;
|
|
21
|
+
}
|
|
22
|
+
export function merge(style, options) {
|
|
23
|
+
let result = {
|
|
24
|
+
...{
|
|
25
|
+
seed: Math.random().toString(),
|
|
26
|
+
},
|
|
27
|
+
...defaults(schema),
|
|
28
|
+
...defaults(style.schema),
|
|
29
|
+
...options,
|
|
30
|
+
};
|
|
31
|
+
return result;
|
|
32
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { Prng } from '../types';
|
|
2
|
-
export declare function create(seed?: string): Prng;
|
|
1
|
+
import type { Prng } from '../types.js';
|
|
2
|
+
export declare function create(seed?: string): Prng;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
const MIN = -2147483648;
|
|
2
|
+
const MAX = 2147483647;
|
|
3
|
+
function xorshift(value) {
|
|
4
|
+
value ^= value << 13;
|
|
5
|
+
value ^= value >> 17;
|
|
6
|
+
value ^= value << 5;
|
|
7
|
+
return value;
|
|
8
|
+
}
|
|
9
|
+
function hashSeed(seed) {
|
|
10
|
+
let hash = 0;
|
|
11
|
+
for (let i = 0; i < seed.length; i++) {
|
|
12
|
+
hash = ((hash << 5) - hash + seed.charCodeAt(i)) | 0;
|
|
13
|
+
hash = xorshift(hash);
|
|
14
|
+
}
|
|
15
|
+
return hash;
|
|
16
|
+
}
|
|
17
|
+
function randomSeed() {
|
|
18
|
+
return MIN + Math.floor((MAX - MIN) * Math.random()).toString();
|
|
19
|
+
}
|
|
20
|
+
export function create(seed) {
|
|
21
|
+
seed = seed !== null && seed !== void 0 ? seed : randomSeed();
|
|
22
|
+
let value = hashSeed(seed) || 1;
|
|
23
|
+
const next = () => (value = xorshift(value));
|
|
24
|
+
const integer = (min, max) => {
|
|
25
|
+
return Math.floor(((next() - MIN) / (MAX - MIN)) * (max + 1 - min) + min);
|
|
26
|
+
};
|
|
27
|
+
return {
|
|
28
|
+
seed,
|
|
29
|
+
bool(likelihood = 50) {
|
|
30
|
+
return integer(0, 100) <= likelihood;
|
|
31
|
+
},
|
|
32
|
+
integer(min, max) {
|
|
33
|
+
return integer(min, max);
|
|
34
|
+
},
|
|
35
|
+
pick(arr) {
|
|
36
|
+
return arr[integer(0, arr.length - 1)];
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { StyleCreateResult, StyleCreateResultAttributes } from '../types.js';
|
|
2
|
+
declare type CreateGroupProps = {
|
|
3
|
+
children: string;
|
|
4
|
+
x: number;
|
|
5
|
+
y: number;
|
|
6
|
+
};
|
|
7
|
+
export declare function createGroup({ children, x, y }: CreateGroupProps): string;
|
|
8
|
+
export declare function getViewBox(result: StyleCreateResult): {
|
|
9
|
+
x: number;
|
|
10
|
+
y: number;
|
|
11
|
+
width: number;
|
|
12
|
+
height: number;
|
|
13
|
+
};
|
|
14
|
+
export declare function addBackgroundColor(result: StyleCreateResult, backgroundColor: string): string;
|
|
15
|
+
export declare function addScale(result: StyleCreateResult, scale: number): string;
|
|
16
|
+
export declare function addTranslate(result: StyleCreateResult, x?: number, y?: number): string;
|
|
17
|
+
export declare function addRotate(result: StyleCreateResult, rotate: number): string;
|
|
18
|
+
export declare function addFlip(result: StyleCreateResult): string;
|
|
19
|
+
export declare function addViewboxMask(result: StyleCreateResult, radius: number): string;
|
|
20
|
+
export declare function createAttrString(attributes: StyleCreateResultAttributes): string;
|
|
21
|
+
export {};
|
package/lib/utils/svg.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import * as escape from './escape.js';
|
|
2
|
+
export function createGroup({ children, x, y }) {
|
|
3
|
+
return `<g transform="translate(${x}, ${y})">${children}</g>`;
|
|
4
|
+
}
|
|
5
|
+
export function getViewBox(result) {
|
|
6
|
+
let viewBox = result.attributes['viewBox'].split(' ');
|
|
7
|
+
let x = parseInt(viewBox[0]);
|
|
8
|
+
let y = parseInt(viewBox[1]);
|
|
9
|
+
let width = parseInt(viewBox[2]);
|
|
10
|
+
let height = parseInt(viewBox[3]);
|
|
11
|
+
return {
|
|
12
|
+
x,
|
|
13
|
+
y,
|
|
14
|
+
width,
|
|
15
|
+
height,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
export function addBackgroundColor(result, backgroundColor) {
|
|
19
|
+
let { width, height, x, y } = getViewBox(result);
|
|
20
|
+
return `<rect fill="${backgroundColor}" width="${width}" height="${height}" x="${x}" y="${y}" />${result.body}`;
|
|
21
|
+
}
|
|
22
|
+
export function addScale(result, scale) {
|
|
23
|
+
let { width, height, x, y } = getViewBox(result);
|
|
24
|
+
let percent = scale ? (scale - 100) / 100 : 0;
|
|
25
|
+
let translateX = (width / 2 + x) * percent * -1;
|
|
26
|
+
let translateY = (height / 2 + y) * percent * -1;
|
|
27
|
+
return `<g transform="translate(${translateX} ${translateY}) scale(${scale / 100})">${result.body}</g>`;
|
|
28
|
+
}
|
|
29
|
+
export function addTranslate(result, x, y) {
|
|
30
|
+
let viewBox = getViewBox(result);
|
|
31
|
+
let translateX = (viewBox.width + viewBox.x * 2) * ((x !== null && x !== void 0 ? x : 0) / 100);
|
|
32
|
+
let translateY = (viewBox.height + viewBox.y * 2) * ((y !== null && y !== void 0 ? y : 0) / 100);
|
|
33
|
+
return `<g transform="translate(${translateX} ${translateY})">${result.body}</g>`;
|
|
34
|
+
}
|
|
35
|
+
export function addRotate(result, rotate) {
|
|
36
|
+
let { width, height, x, y } = getViewBox(result);
|
|
37
|
+
return `<g transform="rotate(${rotate}, ${width / 2 + x}, ${height / 2 + y})">${result.body}</g>`;
|
|
38
|
+
}
|
|
39
|
+
export function addFlip(result) {
|
|
40
|
+
let { width, x } = getViewBox(result);
|
|
41
|
+
return `<g transform="scale(-1 1) translate(${width * -1 - x * 2} 0)">${result.body}</g>`;
|
|
42
|
+
}
|
|
43
|
+
export function addViewboxMask(result, radius) {
|
|
44
|
+
let { width, height, x, y } = getViewBox(result);
|
|
45
|
+
let rx = radius ? (width * radius) / 100 : 0;
|
|
46
|
+
let ry = radius ? (height * radius) / 100 : 0;
|
|
47
|
+
return (`<mask id="viewboxMask">` +
|
|
48
|
+
`<rect width="${width}" height="${height}" rx="${rx}" ry="${ry}" x="${x}" y="${y}" fill="#fff" />` +
|
|
49
|
+
`</mask>` +
|
|
50
|
+
`<g mask="url(#viewboxMask)">${result.body}</g>`);
|
|
51
|
+
}
|
|
52
|
+
export function createAttrString(attributes) {
|
|
53
|
+
attributes = { xmlns: 'http://www.w3.org/2000/svg', ...attributes };
|
|
54
|
+
return Object.keys(attributes)
|
|
55
|
+
.map((attr) => `${escape.xml(attr)}="${escape.xml(attributes[attr])}"`)
|
|
56
|
+
.join(' ');
|
|
57
|
+
}
|
package/package.json
CHANGED
|
@@ -1,52 +1,50 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dicebear/core",
|
|
3
|
-
"version": "5.0.0-alpha.
|
|
3
|
+
"version": "5.0.0-alpha.20",
|
|
4
4
|
"description": "An avatar library for designers and developers.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"avatar",
|
|
7
7
|
"identicon"
|
|
8
8
|
],
|
|
9
|
-
"homepage": "https://
|
|
9
|
+
"homepage": "https://dicebear.com",
|
|
10
10
|
"bugs": {
|
|
11
11
|
"url": "https://github.com/dicebear/dicebear/issues"
|
|
12
12
|
},
|
|
13
13
|
"repository": {
|
|
14
14
|
"type": "git",
|
|
15
|
-
"url": "git
|
|
16
|
-
"directory": "/packages/@dicebear/core"
|
|
15
|
+
"url": "git+https://github.com/dicebear/dicebear.git"
|
|
17
16
|
},
|
|
18
17
|
"license": "MIT",
|
|
19
18
|
"author": "Florian Körner <contact@florian-koerner.com>",
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
"browser": "dist/index.umd.js",
|
|
24
|
-
"types": "dist/index.d.ts",
|
|
19
|
+
"type": "module",
|
|
20
|
+
"exports": "./lib/index.js",
|
|
21
|
+
"types": "./lib/index.d.ts",
|
|
25
22
|
"files": [
|
|
26
23
|
"LICENSE",
|
|
27
|
-
"
|
|
24
|
+
"lib",
|
|
28
25
|
"README.md"
|
|
29
26
|
],
|
|
30
27
|
"scripts": {
|
|
31
|
-
"
|
|
28
|
+
"prebuild": "del-cli lib",
|
|
29
|
+
"build": "tsc",
|
|
32
30
|
"prepublishOnly": "npm run build",
|
|
33
|
-
"
|
|
34
|
-
"build": "dicebear-project build DiceBear"
|
|
31
|
+
"test": "uvu tests"
|
|
35
32
|
},
|
|
36
33
|
"dependencies": {
|
|
34
|
+
"@dicebear/converter": "^5.0.0-alpha.20",
|
|
37
35
|
"@types/json-schema": "^7.0.7"
|
|
38
36
|
},
|
|
39
37
|
"devDependencies": {
|
|
40
|
-
"@tsconfig/recommended": "^1.0.
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
"
|
|
38
|
+
"@tsconfig/recommended": "^1.0.1",
|
|
39
|
+
"del-cli": "^4.0.1",
|
|
40
|
+
"typescript": "^4.6.3",
|
|
41
|
+
"uvu": "^0.5.3"
|
|
42
|
+
},
|
|
43
|
+
"engines": {
|
|
44
|
+
"node": "^14.13.1 || >=16.0.0"
|
|
47
45
|
},
|
|
48
46
|
"publishConfig": {
|
|
49
47
|
"access": "public"
|
|
50
48
|
},
|
|
51
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "6b1c2bd64294365be21d0a133a362ede5ed62b5a"
|
|
52
50
|
}
|
package/dist/core.d.ts
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import type { Style, StyleOptions } from './types';
|
|
2
|
-
export declare function createAvatar<O extends {}>(style: Style<O>, options?: StyleOptions<O>): string;
|
|
3
|
-
export declare function createPreview<O extends {}>(style: Style<O>, options: StyleOptions<O>, property: keyof StyleOptions<O>): string | undefined;
|
package/dist/index.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* DiceBear (@dicebear/core)
|
|
3
|
-
*
|
|
4
|
-
* Code licensed under MIT (https://github.com/dicebear/dicebear/blob/main/LICENSE)
|
|
5
|
-
* Copyright (c) 2021 Florian Körner
|
|
6
|
-
*/
|
|
7
|
-
import { JSONSchema7 } from 'json-schema';
|
|
8
|
-
export declare const schema: JSONSchema7;
|
|
9
|
-
export * from './core';
|
|
10
|
-
export * from './types';
|
|
11
|
-
export * from './options';
|
|
12
|
-
export * as utils from './utils';
|