@dicebear/core 10.2.0 → 10.3.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/README.md +4 -4
- package/lib/Avatar.d.ts +5 -0
- package/lib/Avatar.js +15 -0
- package/lib/Renderer.js +2 -2
- package/lib/Utils/Number.d.ts +5 -4
- package/lib/Utils/Number.js +5 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
<h1><img src="https://www.dicebear.com/logo-readme.svg" width="28" /> DiceBear Core (JavaScript)</h1>
|
|
2
2
|
|
|
3
|
-
JavaScript implementation of the DiceBear avatar library. Generates
|
|
4
|
-
SVG avatars from style definitions and a seed string.
|
|
3
|
+
JavaScript implementation of the DiceBear avatar library. Generates
|
|
4
|
+
deterministic SVG avatars from style definitions and a seed string.
|
|
5
5
|
|
|
6
6
|
DiceBear is available for multiple languages. All implementations share the same
|
|
7
7
|
PRNG and rendering pipeline, producing identical SVG output for the same seed,
|
|
8
|
-
style, and options
|
|
8
|
+
style, and options, regardless of the language used.
|
|
9
9
|
|
|
10
10
|
[Playground](https://www.dicebear.com/playground) |
|
|
11
11
|
[Documentation](https://www.dicebear.com/how-to-use/js-library/)
|
|
@@ -31,7 +31,7 @@ const avatar = new Avatar(definition, {
|
|
|
31
31
|
size: 128,
|
|
32
32
|
});
|
|
33
33
|
|
|
34
|
-
avatar.toString();
|
|
34
|
+
avatar.toString(); // SVG string
|
|
35
35
|
avatar.toDataUri(); // data:image/svg+xml;charset=utf-8,...
|
|
36
36
|
```
|
|
37
37
|
|
package/lib/Avatar.d.ts
CHANGED
|
@@ -13,6 +13,11 @@ interface AvatarJson<D = unknown> {
|
|
|
13
13
|
*/
|
|
14
14
|
export declare class Avatar<D = unknown> {
|
|
15
15
|
#private;
|
|
16
|
+
/**
|
|
17
|
+
* Pass a {@link Style} instance. Passing a raw style definition is
|
|
18
|
+
* deprecated and will be removed in v11; wrap it with `new Style(...)` and
|
|
19
|
+
* reuse the instance across avatars.
|
|
20
|
+
*/
|
|
16
21
|
constructor(styleInput: D, optionsInput?: StyleOptions<UnwrapStyle<D>>);
|
|
17
22
|
/**
|
|
18
23
|
* Returns the rendered SVG markup.
|
package/lib/Avatar.js
CHANGED
|
@@ -14,6 +14,10 @@ import { Style } from './Style.js';
|
|
|
14
14
|
import { Options } from './Options.js';
|
|
15
15
|
import { Resolver } from './Resolver.js';
|
|
16
16
|
import { Renderer } from './Renderer.js';
|
|
17
|
+
// Emitted at most once per process: passing a raw definition is deprecated, but
|
|
18
|
+
// it was the documented usage for a long time, so a per-call warning would be
|
|
19
|
+
// noisy.
|
|
20
|
+
let definitionInputWarned = false;
|
|
17
21
|
/**
|
|
18
22
|
* Top-level entry point for rendering an avatar from a style and options.
|
|
19
23
|
*
|
|
@@ -21,9 +25,20 @@ import { Renderer } from './Renderer.js';
|
|
|
21
25
|
* accessor methods return different serializations of that result.
|
|
22
26
|
*/
|
|
23
27
|
export class Avatar {
|
|
28
|
+
/**
|
|
29
|
+
* Pass a {@link Style} instance. Passing a raw style definition is
|
|
30
|
+
* deprecated and will be removed in v11; wrap it with `new Style(...)` and
|
|
31
|
+
* reuse the instance across avatars.
|
|
32
|
+
*/
|
|
24
33
|
constructor(styleInput, optionsInput) {
|
|
25
34
|
_Avatar_svg.set(this, void 0);
|
|
26
35
|
_Avatar_resolvedOptions.set(this, void 0);
|
|
36
|
+
if (!(styleInput instanceof Style) && !definitionInputWarned) {
|
|
37
|
+
definitionInputWarned = true;
|
|
38
|
+
console.warn('[DiceBear] Passing a style definition to `new Avatar()` is deprecated ' +
|
|
39
|
+
'and will be removed in v11. Wrap it in a Style first: ' +
|
|
40
|
+
'`new Avatar(new Style(definition), options)`.');
|
|
41
|
+
}
|
|
27
42
|
const style = styleInput instanceof Style ? styleInput : new Style(styleInput);
|
|
28
43
|
const options = new Options(optionsInput);
|
|
29
44
|
const resolver = new Resolver(style, options);
|
package/lib/Renderer.js
CHANGED
|
@@ -72,7 +72,7 @@ export class Renderer {
|
|
|
72
72
|
attrs.push(`width="${sizeValue}"`, `height="${sizeValue}"`);
|
|
73
73
|
}
|
|
74
74
|
const titleElement = escapedTitle !== undefined ? `<title>${escapedTitle}</title>` : '';
|
|
75
|
-
let svg = `<svg ${attrs.join(' ')}
|
|
75
|
+
let svg = `<svg ${attrs.join(' ')}><!-- Generated by DiceBear (https://dicebear.com) -->${metadata}${defs}${titleElement}${body}</svg>`;
|
|
76
76
|
if (__classPrivateFieldGet(this, _Renderer_resolver, "f").idRandomization()) {
|
|
77
77
|
svg = __classPrivateFieldGet(this, _Renderer_instances, "m", _Renderer_randomizeIds).call(this, svg);
|
|
78
78
|
}
|
|
@@ -299,7 +299,7 @@ _Renderer_style = new WeakMap(), _Renderer_resolver = new WeakMap(), _Renderer_d
|
|
|
299
299
|
case 'initial': {
|
|
300
300
|
// charAt(0) would return a lone surrogate (ill-formed XML) for
|
|
301
301
|
// supplementary-plane initials; take the full first code point
|
|
302
|
-
// instead, like the PHP/Python/Rust/Go ports.
|
|
302
|
+
// instead, like the PHP/Python/Rust/Go/Dart ports.
|
|
303
303
|
const first = __classPrivateFieldGet(this, _Renderer_instances, "m", _Renderer_initials).call(this).codePointAt(0);
|
|
304
304
|
return first !== undefined ? String.fromCodePoint(first) : '';
|
|
305
305
|
}
|
package/lib/Utils/Number.d.ts
CHANGED
|
@@ -2,10 +2,11 @@
|
|
|
2
2
|
* Formats a number for SVG output, rounded to at most 5 decimal places.
|
|
3
3
|
*
|
|
4
4
|
* Rounding to a fixed precision keeps the output bounded and identical across
|
|
5
|
-
* the JS, PHP, and
|
|
6
|
-
* SVG coordinate range, which has no exponential form,
|
|
7
|
-
* from integer arithmetic (no locale- or
|
|
8
|
-
* Five decimals is far below sub-pixel
|
|
5
|
+
* the JS, PHP, Python, Rust, Go, and Dart ports: every value becomes a
|
|
6
|
+
* multiple of 1e-5 in the SVG coordinate range, which has no exponential form,
|
|
7
|
+
* so the result is built from integer arithmetic (no locale- or
|
|
8
|
+
* language-specific float stringifying). Five decimals is far below sub-pixel
|
|
9
|
+
* precision for any realistic canvas.
|
|
9
10
|
*/
|
|
10
11
|
export declare class Number {
|
|
11
12
|
static format(value: number): string;
|
package/lib/Utils/Number.js
CHANGED
|
@@ -2,10 +2,11 @@
|
|
|
2
2
|
* Formats a number for SVG output, rounded to at most 5 decimal places.
|
|
3
3
|
*
|
|
4
4
|
* Rounding to a fixed precision keeps the output bounded and identical across
|
|
5
|
-
* the JS, PHP, and
|
|
6
|
-
* SVG coordinate range, which has no exponential form,
|
|
7
|
-
* from integer arithmetic (no locale- or
|
|
8
|
-
* Five decimals is far below sub-pixel
|
|
5
|
+
* the JS, PHP, Python, Rust, Go, and Dart ports: every value becomes a
|
|
6
|
+
* multiple of 1e-5 in the SVG coordinate range, which has no exponential form,
|
|
7
|
+
* so the result is built from integer arithmetic (no locale- or
|
|
8
|
+
* language-specific float stringifying). Five decimals is far below sub-pixel
|
|
9
|
+
* precision for any realistic canvas.
|
|
9
10
|
*/
|
|
10
11
|
export class Number {
|
|
11
12
|
static format(value) {
|