@dicebear/core 11.0.0-rc.3 → 11.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/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  <h1><img src="https://www.dicebear.com/logo-readme.svg" width="28" /> DiceBear Core (JavaScript)</h1>
2
2
 
3
3
  [![stars](https://www.dicebear.com/badges/stars.svg)](https://github.com/dicebear/dicebear/stargazers)
4
- [![license](https://www.dicebear.com/badges/license.svg)](https://github.com/dicebear/dicebear/blob/10.x/LICENSE)
4
+ [![license](https://www.dicebear.com/badges/license.svg)](https://github.com/dicebear/dicebear/blob/11.x/LICENSE)
5
5
 
6
6
  JavaScript implementation of the DiceBear avatar library. Generates
7
7
  deterministic SVG avatars from style definitions and a seed string.
@@ -16,9 +16,12 @@ style, and options, regardless of the language used.
16
16
  ## Installation
17
17
 
18
18
  ```sh
19
- npm install @dicebear/core
19
+ npm install @dicebear/core @dicebear/styles
20
20
  ```
21
21
 
22
+ `@dicebear/styles` holds the definitions of the avatar styles. Leave it out when
23
+ you bring your own definitions.
24
+
22
25
  Requires Node.js 22+ or any modern browser.
23
26
 
24
27
  ## Usage
package/lib/Avatar.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Style } from './Style.js';
2
- import type { StyleOptions } from './StyleOptions.js';
2
+ import type { NoInferStyle, StyleOptions } from './StyleOptions.js';
3
3
  interface AvatarJson<D = unknown> {
4
4
  readonly svg: string;
5
5
  readonly options: StyleOptions<D>;
@@ -16,7 +16,7 @@ export declare class Avatar<D = unknown> {
16
16
  * Pass a {@link Style} instance and reuse it across avatars. The parsed
17
17
  * style carries the validation, so nothing is re-checked per render.
18
18
  */
19
- constructor(style: Style<D>, optionsInput?: StyleOptions<D>);
19
+ constructor(style: Style<D>, optionsInput?: StyleOptions<NoInferStyle<D>>);
20
20
  /**
21
21
  * Returns the rendered SVG markup.
22
22
  */
package/lib/Options.d.ts CHANGED
@@ -13,9 +13,18 @@ import type { StyleOptions, StyleOptionsFlipValue, StyleOptionsColorFillValue, S
13
13
  export declare class Options<D = unknown> {
14
14
  #private;
15
15
  constructor(data?: StyleOptions<D>);
16
+ /**
17
+ * The seed, with every lone surrogate replaced by U+FFFD: ill-formed text
18
+ * has no meaning another port could reproduce, so the hash and the initials
19
+ * read the same text everywhere.
20
+ */
16
21
  seed(): string | undefined;
17
22
  size(): number | undefined;
18
23
  idRandomization(): boolean | undefined;
24
+ /**
25
+ * The title, with every lone surrogate replaced by U+FFFD, so no ill-formed
26
+ * text reaches the SVG.
27
+ */
19
28
  title(): string | undefined;
20
29
  flip(): readonly StyleOptionsFlipValue[];
21
30
  fontFamily(): readonly string[];
@@ -38,7 +47,7 @@ export declare class Options<D = unknown> {
38
47
  */
39
48
  animationSpeedFor(name: string): Range | undefined;
40
49
  animationDelay(): Range | undefined;
41
- animationMotionQuery(): boolean | undefined;
50
+ animationRespectReducedMotion(): boolean | undefined;
42
51
  /**
43
52
  * Returns the `${name}AnimationDelay` option for one animation name as a
44
53
  * range, or `undefined` when unset.
package/lib/Options.js CHANGED
@@ -9,7 +9,8 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
9
9
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
10
10
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
11
  };
12
- var _Options_instances, _Options_data, _Options_tags, _Options_dynamic, _Options_asArray, _Options_toRange;
12
+ var _Options_instances, _Options_data, _Options_tags, _Options_dynamic, _Options_asArray, _Options_wellFormed, _Options_toRange;
13
+ import { Text } from './Utils/Text.js';
13
14
  /**
14
15
  * Validates the raw user-supplied options and exposes them through typed
15
16
  * accessors. Each accessor returns the user's input in a normalized form
@@ -25,10 +26,16 @@ export class Options {
25
26
  _Options_instances.add(this);
26
27
  _Options_data.set(this, void 0);
27
28
  _Options_tags.set(this, void 0);
28
- __classPrivateFieldSet(this, _Options_data, structuredClone(data), "f");
29
+ // `null` renders the default avatar, as in the other ports.
30
+ __classPrivateFieldSet(this, _Options_data, structuredClone(data ?? {}), "f");
29
31
  }
32
+ /**
33
+ * The seed, with every lone surrogate replaced by U+FFFD: ill-formed text
34
+ * has no meaning another port could reproduce, so the hash and the initials
35
+ * read the same text everywhere.
36
+ */
30
37
  seed() {
31
- return __classPrivateFieldGet(this, _Options_data, "f").seed;
38
+ return __classPrivateFieldGet(this, _Options_instances, "m", _Options_wellFormed).call(this, __classPrivateFieldGet(this, _Options_data, "f").seed);
32
39
  }
33
40
  size() {
34
41
  return __classPrivateFieldGet(this, _Options_data, "f").size;
@@ -36,8 +43,12 @@ export class Options {
36
43
  idRandomization() {
37
44
  return __classPrivateFieldGet(this, _Options_data, "f").idRandomization;
38
45
  }
46
+ /**
47
+ * The title, with every lone surrogate replaced by U+FFFD, so no ill-formed
48
+ * text reaches the SVG.
49
+ */
39
50
  title() {
40
- return __classPrivateFieldGet(this, _Options_data, "f").title;
51
+ return __classPrivateFieldGet(this, _Options_instances, "m", _Options_wellFormed).call(this, __classPrivateFieldGet(this, _Options_data, "f").title);
41
52
  }
42
53
  flip() {
43
54
  return __classPrivateFieldGet(this, _Options_instances, "m", _Options_asArray).call(this, __classPrivateFieldGet(this, _Options_data, "f").flip);
@@ -86,8 +97,8 @@ export class Options {
86
97
  animationDelay() {
87
98
  return __classPrivateFieldGet(this, _Options_instances, "m", _Options_toRange).call(this, __classPrivateFieldGet(this, _Options_data, "f").animationDelay);
88
99
  }
89
- animationMotionQuery() {
90
- return __classPrivateFieldGet(this, _Options_data, "f").animationMotionQuery;
100
+ animationRespectReducedMotion() {
101
+ return __classPrivateFieldGet(this, _Options_data, "f").animationRespectReducedMotion;
91
102
  }
92
103
  /**
93
104
  * Returns the `${name}AnimationDelay` option for one animation name as a
@@ -169,6 +180,8 @@ _Options_data = new WeakMap(), _Options_tags = new WeakMap(), _Options_instances
169
180
  return value;
170
181
  }
171
182
  return [value];
183
+ }, _Options_wellFormed = function _Options_wellFormed(value) {
184
+ return typeof value === 'string' ? Text.wellFormed(value) : value;
172
185
  }, _Options_toRange = function _Options_toRange(value) {
173
186
  if (value === undefined) {
174
187
  return undefined;
@@ -115,7 +115,7 @@ _a = OptionsDescriptor, _OptionsDescriptor_descriptor = new WeakMap(), _OptionsD
115
115
  result.animation = { type: 'boolean' };
116
116
  result.animationSpeed = { type: 'range', min: 0.1, max: 10 };
117
117
  result.animationDelay = { type: 'range', min: -3600, max: 3600 };
118
- result.animationMotionQuery = { type: 'boolean' };
118
+ result.animationRespectReducedMotion = { type: 'boolean' };
119
119
  for (const name of __classPrivateFieldGet(this, _OptionsDescriptor_style, "f").animationNames()) {
120
120
  result[`${name}Animation`] = { type: 'boolean' };
121
121
  result[`${name}AnimationSpeed`] = { type: 'range', min: 0.1, max: 10 };
package/lib/Renderer.js CHANGED
@@ -359,7 +359,7 @@ _a = Renderer, _Renderer_style = new WeakMap(), _Renderer_resolver = new WeakMap
359
359
  // Without the media query the rules apply to every viewer. A render that
360
360
  // keeps the query must not pick them up on the same page, so the two get
361
361
  // different names. The default adds nothing and leaves the hash as it was.
362
- const motion = __classPrivateFieldGet(this, _Renderer_resolver, "f").animationMotionQuery()
362
+ const motion = __classPrivateFieldGet(this, _Renderer_resolver, "f").animationRespectReducedMotion()
363
363
  ? ''
364
364
  : ':nomotionquery';
365
365
  return (__classPrivateFieldSet(this, _Renderer_cachedAnimationHash, Fnv1a.hex((__classPrivateFieldGet(this, _Renderer_style, "f").meta().source().name() ?? '') +
@@ -503,7 +503,7 @@ _a = Renderer, _Renderer_style = new WeakMap(), _Renderer_resolver = new WeakMap
503
503
  key += '-';
504
504
  }
505
505
  const css = __classPrivateFieldGet(this, _Renderer_keyframesCss, "f").join('') + __classPrivateFieldGet(this, _Renderer_animationCss, "f").join('');
506
- __classPrivateFieldGet(this, _Renderer_defs, "f").set(key, __classPrivateFieldGet(this, _Renderer_resolver, "f").animationMotionQuery()
506
+ __classPrivateFieldGet(this, _Renderer_defs, "f").set(key, __classPrivateFieldGet(this, _Renderer_resolver, "f").animationRespectReducedMotion()
507
507
  ? `<style>@media (prefers-reduced-motion:no-preference){${css}}</style>`
508
508
  : `<style>${css}</style>`);
509
509
  };
package/lib/Resolver.d.ts CHANGED
@@ -45,7 +45,7 @@ export declare class Resolver<D = unknown> {
45
45
  * query. On by default. Renderers that ignore media queries need it off,
46
46
  * and the app then decides about `animation` from the system setting.
47
47
  */
48
- animationMotionQuery(): boolean;
48
+ animationRespectReducedMotion(): boolean;
49
49
  title(): string | undefined;
50
50
  flip(): StyleOptionsFlipValue;
51
51
  fontFamily(): string;
package/lib/Resolver.js CHANGED
@@ -102,8 +102,8 @@ export class Resolver {
102
102
  * query. On by default. Renderers that ignore media queries need it off,
103
103
  * and the app then decides about `animation` from the system setting.
104
104
  */
105
- animationMotionQuery() {
106
- return __classPrivateFieldGet(this, _Resolver_instances, "m", _Resolver_memo).call(this, 'animationMotionQuery', () => __classPrivateFieldGet(this, _Resolver_options, "f").animationMotionQuery() ?? true);
105
+ animationRespectReducedMotion() {
106
+ return __classPrivateFieldGet(this, _Resolver_instances, "m", _Resolver_memo).call(this, 'animationRespectReducedMotion', () => __classPrivateFieldGet(this, _Resolver_options, "f").animationRespectReducedMotion() ?? true);
107
107
  }
108
108
  title() {
109
109
  return __classPrivateFieldGet(this, _Resolver_instances, "m", _Resolver_memo).call(this, 'title', () => __classPrivateFieldGet(this, _Resolver_options, "f").title());
package/lib/Style.d.ts CHANGED
@@ -4,6 +4,8 @@ import { Canvas } from './Style/Canvas.js';
4
4
  import { Component } from './Style/Component.js';
5
5
  import { Color } from './Style/Color.js';
6
6
  export type { StyleDefinition } from './StyleDefinition.js';
7
+ /** Key of the type-only member that carries the definition type. */
8
+ declare const definitionType: unique symbol;
7
9
  /**
8
10
  * Validated, lazily-decomposed wrapper around a style definition. Construction
9
11
  * runs the JSON Schema validator and stores a deep clone of the input so that
@@ -11,6 +13,12 @@ export type { StyleDefinition } from './StyleDefinition.js';
11
13
  */
12
14
  export declare class Style<D = unknown> {
13
15
  #private;
16
+ /**
17
+ * Carries `D` in the shape of the class, so the definition type survives
18
+ * when a style is passed around, and `new Avatar(style, options)` checks the
19
+ * options against it. It exists for the type checker only and is never set.
20
+ */
21
+ readonly [definitionType]?: D;
14
22
  constructor(data: D);
15
23
  /**
16
24
  * Returns the definition's `$id`, or `undefined` when not set.
@@ -13,6 +13,15 @@ export interface TagFilterToken {
13
13
  readonly value?: string;
14
14
  readonly negated: boolean;
15
15
  }
16
+ /**
17
+ * Keeps TypeScript from inferring `T` at this position, so the options of an
18
+ * avatar are checked against the style instead of widening the style's type
19
+ * to fit them. The same as the built-in `NoInfer` of TypeScript 5.4, written
20
+ * out so that the declarations also work with older compilers.
21
+ *
22
+ * @internal
23
+ */
24
+ export type NoInferStyle<T> = [T][T extends unknown ? 0 : never];
16
25
  type ComponentNames<D> = D extends {
17
26
  components: Record<infer K extends string, unknown>;
18
27
  } ? string extends K ? never : K : never;
@@ -46,7 +55,7 @@ export interface StyleOptionsBase {
46
55
  readonly animation?: boolean;
47
56
  readonly animationSpeed?: number | readonly [number, number];
48
57
  readonly animationDelay?: number | readonly [number, number];
49
- readonly animationMotionQuery?: boolean;
58
+ readonly animationRespectReducedMotion?: boolean;
50
59
  }
51
60
  type ComponentVariantOption<D, K extends string> = VariantNames<D, K> | readonly VariantNames<D, K>[] | Readonly<Partial<Record<VariantNames<D, K>, number>>>;
52
61
  type IsAlias<D, C extends string> = D extends {
@@ -71,9 +80,9 @@ type ColorOptions<C extends string> = [C] extends [never] ? unknown : {
71
80
  readonly [K in C as `${K}ColorOrder`]?: StyleOptionsColorOrderValue;
72
81
  };
73
82
  type AnimationOptions = {
74
- readonly [key: `${string}Animation`]: boolean | undefined;
75
- readonly [key: `${string}AnimationSpeed`]: number | readonly [number, number] | undefined;
76
- readonly [key: `${string}AnimationDelay`]: number | readonly [number, number] | undefined;
83
+ readonly [key: `${string}Animation`]: unknown;
84
+ readonly [key: `${string}AnimationSpeed`]: unknown;
85
+ readonly [key: `${string}AnimationDelay`]: unknown;
77
86
  };
78
87
  export type StyleOptions<D = unknown> = StyleOptionsBase & ComponentOptions<D, ComponentNames<D>> & ColorOptions<AllColorNames<D>> & (HasSpecificKeys<D> extends true ? AnimationOptions : {
79
88
  readonly [key: string]: unknown;
@@ -0,0 +1,26 @@
1
+ /**
2
+ * The nesting limit for style definitions and options.
3
+ *
4
+ * A port may turn down a value nested deeper than {@link Depth.MAX} levels
5
+ * before it runs the schema, and some must: their schema validators run out of
6
+ * stack on a few thousand levels. Every port applies the same limit, so a
7
+ * definition renders in all of them or in none. Valid options nest two levels
8
+ * and the deepest style definition uses less than a quarter of the limit.
9
+ */
10
+ export declare class Depth {
11
+ #private;
12
+ /**
13
+ * How many levels of objects and arrays a value may nest, counting the value
14
+ * itself as the first.
15
+ */
16
+ static readonly MAX = 64;
17
+ /**
18
+ * What a validator reports when {@link Depth.exceeds} holds.
19
+ */
20
+ static readonly MESSAGE: string;
21
+ /**
22
+ * Returns whether `value` nests objects and arrays deeper than
23
+ * {@link Depth.MAX} levels. A value that contains itself does.
24
+ */
25
+ static exceeds(value: unknown): boolean;
26
+ }
@@ -0,0 +1,47 @@
1
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
2
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
3
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
4
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
5
+ };
6
+ var _a, _Depth_exceeds;
7
+ /**
8
+ * The nesting limit for style definitions and options.
9
+ *
10
+ * A port may turn down a value nested deeper than {@link Depth.MAX} levels
11
+ * before it runs the schema, and some must: their schema validators run out of
12
+ * stack on a few thousand levels. Every port applies the same limit, so a
13
+ * definition renders in all of them or in none. Valid options nest two levels
14
+ * and the deepest style definition uses less than a quarter of the limit.
15
+ */
16
+ export class Depth {
17
+ /**
18
+ * Returns whether `value` nests objects and arrays deeper than
19
+ * {@link Depth.MAX} levels. A value that contains itself does.
20
+ */
21
+ static exceeds(value) {
22
+ return __classPrivateFieldGet(_a, _a, "m", _Depth_exceeds).call(_a, value, 1, new Map());
23
+ }
24
+ }
25
+ _a = Depth, _Depth_exceeds = function _Depth_exceeds(value, depth, checked) {
26
+ if (value === null || typeof value !== 'object') {
27
+ return false;
28
+ }
29
+ if (depth > _a.MAX) {
30
+ return true;
31
+ }
32
+ if ((checked.get(value) ?? 0) >= depth) {
33
+ return false;
34
+ }
35
+ checked.set(value, depth);
36
+ const items = Array.isArray(value) ? value : Object.values(value);
37
+ return items.some((item) => __classPrivateFieldGet(_a, _a, "m", _Depth_exceeds).call(_a, item, depth + 1, checked));
38
+ };
39
+ /**
40
+ * How many levels of objects and arrays a value may nest, counting the value
41
+ * itself as the first.
42
+ */
43
+ Depth.MAX = 64;
44
+ /**
45
+ * What a validator reports when {@link Depth.exceeds} holds.
46
+ */
47
+ Depth.MESSAGE = `nesting is deeper than the ${_a.MAX} levels this port reads`;
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Finds a number in the options that is not finite.
3
+ *
4
+ * JSON cannot carry Infinity or NaN, so every other port turns such a value
5
+ * down before or during validation. The compiled JS validator lets one
6
+ * through where the schema sets no maximum, a variant weight for example, and
7
+ * the avatar then rendered here but nowhere else.
8
+ */
9
+ export declare class Finite {
10
+ static readonly MESSAGE = "must be a finite number";
11
+ /**
12
+ * Returns the JSON pointer of the first non-finite number in `value`, or
13
+ * `undefined` if there is none. Runs after the depth check, so the value
14
+ * nests at most a few levels.
15
+ */
16
+ static find(value: unknown, path?: string): string | undefined;
17
+ }
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Finds a number in the options that is not finite.
3
+ *
4
+ * JSON cannot carry Infinity or NaN, so every other port turns such a value
5
+ * down before or during validation. The compiled JS validator lets one
6
+ * through where the schema sets no maximum, a variant weight for example, and
7
+ * the avatar then rendered here but nowhere else.
8
+ */
9
+ export class Finite {
10
+ /**
11
+ * Returns the JSON pointer of the first non-finite number in `value`, or
12
+ * `undefined` if there is none. Runs after the depth check, so the value
13
+ * nests at most a few levels.
14
+ */
15
+ static find(value, path = '') {
16
+ if (typeof value === 'number') {
17
+ return Number.isFinite(value) ? undefined : path;
18
+ }
19
+ if (value === null || typeof value !== 'object') {
20
+ return undefined;
21
+ }
22
+ for (const [key, inner] of Object.entries(value)) {
23
+ const pointer = `${path}/${key.replace(/~/g, '~0').replace(/\//g, '~1')}`;
24
+ const found = Finite.find(inner, pointer);
25
+ if (found !== undefined) {
26
+ return found;
27
+ }
28
+ }
29
+ return undefined;
30
+ }
31
+ }
32
+ Finite.MESSAGE = 'must be a finite number';
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Makes user text well-formed before the core reads it.
3
+ *
4
+ * A JS string can hold a lone UTF-16 surrogate, for example half of an emoji
5
+ * cut off by a slice. Ports that keep strings as UTF-8 can hold ill-formed
6
+ * bytes instead. Neither has a meaning another port could reproduce, so every
7
+ * port replaces them with U+FFFD first. Here that is each lone surrogate, the
8
+ * same as `String.prototype.toWellFormed()`.
9
+ */
10
+ export declare class Text {
11
+ /**
12
+ * Returns `value` with every lone surrogate replaced by U+FFFD. A
13
+ * well-formed string comes back unchanged.
14
+ */
15
+ static wellFormed(value: string): string;
16
+ }
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Makes user text well-formed before the core reads it.
3
+ *
4
+ * A JS string can hold a lone UTF-16 surrogate, for example half of an emoji
5
+ * cut off by a slice. Ports that keep strings as UTF-8 can hold ill-formed
6
+ * bytes instead. Neither has a meaning another port could reproduce, so every
7
+ * port replaces them with U+FFFD first. Here that is each lone surrogate, the
8
+ * same as `String.prototype.toWellFormed()`.
9
+ */
10
+ export class Text {
11
+ /**
12
+ * Returns `value` with every lone surrogate replaced by U+FFFD. A
13
+ * well-formed string comes back unchanged.
14
+ */
15
+ static wellFormed(value) {
16
+ let result = '';
17
+ let start = 0;
18
+ for (let i = 0; i < value.length; i++) {
19
+ const unit = value.charCodeAt(i);
20
+ if (unit < 0xd800 || unit > 0xdfff) {
21
+ continue;
22
+ }
23
+ const next = i + 1 < value.length ? value.charCodeAt(i + 1) : 0;
24
+ if (unit <= 0xdbff && next >= 0xdc00 && next <= 0xdfff) {
25
+ // A valid pair: keep both units.
26
+ i++;
27
+ continue;
28
+ }
29
+ result += value.slice(start, i) + '�';
30
+ start = i + 1;
31
+ }
32
+ return start === 0 ? value : result + value.slice(start);
33
+ }
34
+ }
@@ -1192,11 +1192,11 @@ const validate = (function () {
1192
1192
  errorCount++;
1193
1193
  }
1194
1194
  }
1195
- if (data.animationMotionQuery !== undefined && hasOwn(data, "animationMotionQuery")) {
1196
- if (!(typeof data.animationMotionQuery === "boolean")) {
1195
+ if (data.animationRespectReducedMotion !== undefined && hasOwn(data, "animationRespectReducedMotion")) {
1196
+ if (!(typeof data.animationRespectReducedMotion === "boolean")) {
1197
1197
  if (validate.errors === null)
1198
1198
  validate.errors = [];
1199
- validate.errors.push({ keywordLocation: "#/properties/animationMotionQuery/type", instanceLocation: "#/animationMotionQuery" });
1199
+ validate.errors.push({ keywordLocation: "#/properties/animationRespectReducedMotion/type", instanceLocation: "#/animationRespectReducedMotion" });
1200
1200
  errorCount++;
1201
1201
  }
1202
1202
  }
@@ -1600,7 +1600,7 @@ const validate = (function () {
1600
1600
  }
1601
1601
  }
1602
1602
  for (const key4 of Object.keys(data)) {
1603
- if (key4 !== "seed" && key4 !== "size" && key4 !== "idRandomization" && key4 !== "title" && key4 !== "flip" && key4 !== "rotate" && key4 !== "scale" && key4 !== "translateX" && key4 !== "translateY" && key4 !== "borderRadius" && key4 !== "fontFamily" && key4 !== "fontWeight" && key4 !== "tags" && key4 !== "animation" && key4 !== "animationSpeed" && key4 !== "animationDelay" && key4 !== "animationMotionQuery" && !pattern2.test(key4) && !pattern4.test(key4) && !pattern5.test(key4) && !pattern7.test(key4) && !pattern8.test(key4) && !pattern9.test(key4) && !pattern10.test(key4) && !pattern11.test(key4) && !pattern12.test(key4) && !pattern13.test(key4)) {
1603
+ if (key4 !== "seed" && key4 !== "size" && key4 !== "idRandomization" && key4 !== "title" && key4 !== "flip" && key4 !== "rotate" && key4 !== "scale" && key4 !== "translateX" && key4 !== "translateY" && key4 !== "borderRadius" && key4 !== "fontFamily" && key4 !== "fontWeight" && key4 !== "tags" && key4 !== "animation" && key4 !== "animationSpeed" && key4 !== "animationDelay" && key4 !== "animationRespectReducedMotion" && !pattern2.test(key4) && !pattern4.test(key4) && !pattern5.test(key4) && !pattern7.test(key4) && !pattern8.test(key4) && !pattern9.test(key4) && !pattern10.test(key4) && !pattern11.test(key4) && !pattern12.test(key4) && !pattern13.test(key4)) {
1604
1604
  if (validate.errors === null)
1605
1605
  validate.errors = [];
1606
1606
  validate.errors.push({ keywordLocation: "#/additionalProperties", instanceLocation: "#/" + pointerPart(key4) });
package/lib/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Style as StyleBase, type StyleDefinition } from './Style.js';
2
2
  import { Avatar as AvatarBase } from './Avatar.js';
3
- import type { StyleOptions } from './StyleOptions.js';
3
+ import type { NoInferStyle, StyleOptions } from './StyleOptions.js';
4
4
  /**
5
5
  * A style whose definition is checked against the definition schema before
6
6
  * it is parsed. `@dicebear/core/lite` exports the same class without the
@@ -15,8 +15,13 @@ export declare class Style<D = unknown> extends StyleBase<D> {
15
15
  * for options that come from your own code.
16
16
  */
17
17
  export declare class Avatar<D = unknown> extends AvatarBase<D> {
18
- constructor(style: StyleBase<D>, optionsInput?: StyleOptions<D>);
18
+ constructor(style: StyleBase<D>, optionsInput?: StyleOptions<NoInferStyle<D>>);
19
19
  }
20
20
  export type { StyleDefinition };
21
21
  export { OptionsDescriptor } from './OptionsDescriptor.js';
22
22
  export type { StyleOptions } from './StyleOptions.js';
23
+ export { ValidationError } from './Error/ValidationError.js';
24
+ export type { ValidationErrorDetail } from './Error/ValidationError.js';
25
+ export { StyleValidationError } from './Error/StyleValidationError.js';
26
+ export { OptionsValidationError } from './Error/OptionsValidationError.js';
27
+ export { CircularColorReferenceError } from './Error/CircularColorReferenceError.js';
package/lib/index.js CHANGED
@@ -2,6 +2,10 @@ import { Style as StyleBase } from './Style.js';
2
2
  import { Avatar as AvatarBase } from './Avatar.js';
3
3
  import { StyleValidator } from './Validator/StyleValidator.js';
4
4
  import { OptionsValidator } from './Validator/OptionsValidator.js';
5
+ import { StyleValidationError } from './Error/StyleValidationError.js';
6
+ import { OptionsValidationError } from './Error/OptionsValidationError.js';
7
+ import { Depth } from './Utils/Depth.js';
8
+ import { Finite } from './Utils/Finite.js';
5
9
  /**
6
10
  * A style whose definition is checked against the definition schema before
7
11
  * it is parsed. `@dicebear/core/lite` exports the same class without the
@@ -9,6 +13,9 @@ import { OptionsValidator } from './Validator/OptionsValidator.js';
9
13
  */
10
14
  export class Style extends StyleBase {
11
15
  constructor(data) {
16
+ if (Depth.exceeds(data)) {
17
+ throw new StyleValidationError([{ message: Depth.MESSAGE }]);
18
+ }
12
19
  StyleValidator.validate(data);
13
20
  super(data);
14
21
  }
@@ -20,8 +27,21 @@ export class Style extends StyleBase {
20
27
  */
21
28
  export class Avatar extends AvatarBase {
22
29
  constructor(style, optionsInput) {
30
+ if (Depth.exceeds(optionsInput)) {
31
+ throw new OptionsValidationError([{ message: Depth.MESSAGE }]);
32
+ }
23
33
  OptionsValidator.validate(optionsInput ?? {});
34
+ const nonFinite = Finite.find(optionsInput);
35
+ if (nonFinite !== undefined) {
36
+ throw new OptionsValidationError([
37
+ { instancePath: nonFinite, keyword: 'type', message: Finite.MESSAGE },
38
+ ]);
39
+ }
24
40
  super(style, optionsInput);
25
41
  }
26
42
  }
27
43
  export { OptionsDescriptor } from './OptionsDescriptor.js';
44
+ export { ValidationError } from './Error/ValidationError.js';
45
+ export { StyleValidationError } from './Error/StyleValidationError.js';
46
+ export { OptionsValidationError } from './Error/OptionsValidationError.js';
47
+ export { CircularColorReferenceError } from './Error/CircularColorReferenceError.js';
package/lib/lite.d.ts CHANGED
@@ -2,3 +2,8 @@ export { Style, type StyleDefinition } from './Style.js';
2
2
  export { Avatar } from './Avatar.js';
3
3
  export { OptionsDescriptor } from './OptionsDescriptor.js';
4
4
  export type { StyleOptions } from './StyleOptions.js';
5
+ export { ValidationError } from './Error/ValidationError.js';
6
+ export type { ValidationErrorDetail } from './Error/ValidationError.js';
7
+ export { StyleValidationError } from './Error/StyleValidationError.js';
8
+ export { OptionsValidationError } from './Error/OptionsValidationError.js';
9
+ export { CircularColorReferenceError } from './Error/CircularColorReferenceError.js';
package/lib/lite.js CHANGED
@@ -6,3 +6,9 @@
6
6
  export { Style } from './Style.js';
7
7
  export { Avatar } from './Avatar.js';
8
8
  export { OptionsDescriptor } from './OptionsDescriptor.js';
9
+ // The lite entry validates nothing, but the circular color check still runs,
10
+ // and code shared with the root entry may catch the validation errors.
11
+ export { ValidationError } from './Error/ValidationError.js';
12
+ export { StyleValidationError } from './Error/StyleValidationError.js';
13
+ export { OptionsValidationError } from './Error/OptionsValidationError.js';
14
+ export { CircularColorReferenceError } from './Error/CircularColorReferenceError.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dicebear/core",
3
- "version": "11.0.0-rc.3",
3
+ "version": "11.0.0",
4
4
  "description": "Unique avatars from dozens of styles — deterministic, customizable, vector-based.",
5
5
  "keywords": [
6
6
  "avatar",
@@ -27,6 +27,13 @@
27
27
  "./lite": "./lib/lite.js"
28
28
  },
29
29
  "types": "./lib/index.d.ts",
30
+ "typesVersions": {
31
+ "*": {
32
+ "lite": [
33
+ "./lib/lite.d.ts"
34
+ ]
35
+ }
36
+ },
30
37
  "sideEffects": false,
31
38
  "files": [
32
39
  "LICENSE",
@@ -42,7 +49,7 @@
42
49
  "test": "node --test"
43
50
  },
44
51
  "devDependencies": {
45
- "@dicebear/schema": "^2.1.0",
52
+ "@dicebear/schema": "^3.0.0",
46
53
  "@exodus/schemasafe": "^1.3.0",
47
54
  "@tsconfig/recommended": "^1.0.13",
48
55
  "del-cli": "^7.0.0",