@dicebear/core 11.0.0-rc.1 → 11.0.0-rc.3

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
@@ -24,13 +24,13 @@ Requires Node.js 22+ or any modern browser.
24
24
  ## Usage
25
25
 
26
26
  ```js
27
- import { Avatar } from '@dicebear/core';
27
+ import { Avatar, Style } from '@dicebear/core';
28
28
 
29
29
  // From a style definition (here from the @dicebear/styles package)
30
30
  import definition from '@dicebear/styles/lorelei.json' with { type: 'json' };
31
31
 
32
- const avatar = new Avatar(definition, {
33
- seed: 'John Doe',
32
+ const avatar = new Avatar(new Style(definition), {
33
+ seed: 'John',
34
34
  size: 128,
35
35
  });
36
36
 
@@ -50,6 +50,21 @@ const avatar1 = new Avatar(style, { seed: 'Alice' });
50
50
  const avatar2 = new Avatar(style, { seed: 'Bob' });
51
51
  ```
52
52
 
53
+ ## Smaller bundle without validation
54
+
55
+ About half of the package is the two schema validators. `@dicebear/core/lite`
56
+ exports the same API without them, about 14 kB instead of 30 kB gzipped.
57
+
58
+ > **Warning:** The validation is what keeps unsafe content such as scripts,
59
+ > event handlers and external references out of the SVG, and what turns a wrong
60
+ > option into an error instead of odd output. The lite entry renders whatever it
61
+ > gets. Use it only for definitions and options you wrote or generated yourself,
62
+ > never for anything from an upload, a URL or another source you do not control.
63
+
64
+ ```js
65
+ import { Style, Avatar } from '@dicebear/core/lite';
66
+ ```
67
+
53
68
  ## Sponsors
54
69
 
55
70
  Advertisement: Many thanks to our sponsors who provide us with free or
package/lib/Avatar.d.ts CHANGED
@@ -1,9 +1,8 @@
1
1
  import { Style } from './Style.js';
2
2
  import type { StyleOptions } from './StyleOptions.js';
3
- type UnwrapStyle<D> = D extends Style<infer S> ? S : D;
4
3
  interface AvatarJson<D = unknown> {
5
4
  readonly svg: string;
6
- readonly options: StyleOptions<UnwrapStyle<D>>;
5
+ readonly options: StyleOptions<D>;
7
6
  }
8
7
  /**
9
8
  * Top-level entry point for rendering an avatar from a style and options.
@@ -14,11 +13,10 @@ interface AvatarJson<D = unknown> {
14
13
  export declare class Avatar<D = unknown> {
15
14
  #private;
16
15
  /**
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.
16
+ * Pass a {@link Style} instance and reuse it across avatars. The parsed
17
+ * style carries the validation, so nothing is re-checked per render.
20
18
  */
21
- constructor(styleInput: D, optionsInput?: StyleOptions<UnwrapStyle<D>>);
19
+ constructor(style: Style<D>, optionsInput?: StyleOptions<D>);
22
20
  /**
23
21
  * Returns the rendered SVG markup.
24
22
  */
package/lib/Avatar.js CHANGED
@@ -14,10 +14,6 @@ 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;
21
17
  /**
22
18
  * Top-level entry point for rendering an avatar from a style and options.
23
19
  *
@@ -26,20 +22,16 @@ let definitionInputWarned = false;
26
22
  */
27
23
  export class Avatar {
28
24
  /**
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.
25
+ * Pass a {@link Style} instance and reuse it across avatars. The parsed
26
+ * style carries the validation, so nothing is re-checked per render.
32
27
  */
33
- constructor(styleInput, optionsInput) {
28
+ constructor(style, optionsInput) {
34
29
  _Avatar_svg.set(this, void 0);
35
30
  _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: ' +
31
+ if (!(style instanceof Style)) {
32
+ throw new TypeError('[DiceBear] `new Avatar()` expects a Style. Wrap the definition first: ' +
40
33
  '`new Avatar(new Style(definition), options)`.');
41
34
  }
42
- const style = styleInput instanceof Style ? styleInput : new Style(styleInput);
43
35
  const options = new Options(optionsInput);
44
36
  const resolver = new Resolver(style, options);
45
37
  __classPrivateFieldSet(this, _Avatar_svg, new Renderer(style, resolver).render(), "f");
package/lib/Options.d.ts CHANGED
@@ -25,12 +25,25 @@ export declare class Options<D = unknown> {
25
25
  rotate(): Range | undefined;
26
26
  translateX(): Range | undefined;
27
27
  translateY(): Range | undefined;
28
+ animation(): boolean | undefined;
28
29
  /**
29
- * Returns the animation switch as given for booleans, and normalizes a
30
- * single animation name to a one-element array.
30
+ * Returns the `${name}Animation` switch for one animation name, or
31
+ * `undefined` when unset.
31
32
  */
32
- animation(): boolean | readonly string[] | undefined;
33
+ animationFor(name: string): boolean | undefined;
33
34
  animationSpeed(): Range | undefined;
35
+ /**
36
+ * Returns the `${name}AnimationSpeed` option for one animation name as a
37
+ * range, or `undefined` when unset.
38
+ */
39
+ animationSpeedFor(name: string): Range | undefined;
40
+ animationDelay(): Range | undefined;
41
+ animationMotionQuery(): boolean | undefined;
42
+ /**
43
+ * Returns the `${name}AnimationDelay` option for one animation name as a
44
+ * range, or `undefined` when unset.
45
+ */
46
+ animationDelayFor(name: string): Range | undefined;
34
47
  /**
35
48
  * Returns the global `tags` filter as parsed tokens, or an empty array when
36
49
  * unset. Each raw token (`category` / `category:value`, optionally
package/lib/Options.js CHANGED
@@ -10,7 +10,6 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
10
10
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
11
  };
12
12
  var _Options_instances, _Options_data, _Options_tags, _Options_dynamic, _Options_asArray, _Options_toRange;
13
- import { OptionsValidator } from './Validator/OptionsValidator.js';
14
13
  /**
15
14
  * Validates the raw user-supplied options and exposes them through typed
16
15
  * accessors. Each accessor returns the user's input in a normalized form
@@ -26,7 +25,6 @@ export class Options {
26
25
  _Options_instances.add(this);
27
26
  _Options_data.set(this, void 0);
28
27
  _Options_tags.set(this, void 0);
29
- OptionsValidator.validate(data);
30
28
  __classPrivateFieldSet(this, _Options_data, structuredClone(data), "f");
31
29
  }
32
30
  seed() {
@@ -65,20 +63,39 @@ export class Options {
65
63
  translateY() {
66
64
  return __classPrivateFieldGet(this, _Options_instances, "m", _Options_toRange).call(this, __classPrivateFieldGet(this, _Options_data, "f").translateY);
67
65
  }
66
+ animation() {
67
+ return __classPrivateFieldGet(this, _Options_data, "f").animation;
68
+ }
68
69
  /**
69
- * Returns the animation switch as given for booleans, and normalizes a
70
- * single animation name to a one-element array.
70
+ * Returns the `${name}Animation` switch for one animation name, or
71
+ * `undefined` when unset.
71
72
  */
72
- animation() {
73
- const raw = __classPrivateFieldGet(this, _Options_data, "f").animation;
74
- if (raw === undefined || typeof raw === 'boolean') {
75
- return raw;
76
- }
77
- return __classPrivateFieldGet(this, _Options_instances, "m", _Options_asArray).call(this, raw);
73
+ animationFor(name) {
74
+ return __classPrivateFieldGet(this, _Options_instances, "m", _Options_dynamic).call(this, `${name}Animation`);
78
75
  }
79
76
  animationSpeed() {
80
77
  return __classPrivateFieldGet(this, _Options_instances, "m", _Options_toRange).call(this, __classPrivateFieldGet(this, _Options_data, "f").animationSpeed);
81
78
  }
79
+ /**
80
+ * Returns the `${name}AnimationSpeed` option for one animation name as a
81
+ * range, or `undefined` when unset.
82
+ */
83
+ animationSpeedFor(name) {
84
+ return __classPrivateFieldGet(this, _Options_instances, "m", _Options_toRange).call(this, __classPrivateFieldGet(this, _Options_instances, "m", _Options_dynamic).call(this, `${name}AnimationSpeed`));
85
+ }
86
+ animationDelay() {
87
+ return __classPrivateFieldGet(this, _Options_instances, "m", _Options_toRange).call(this, __classPrivateFieldGet(this, _Options_data, "f").animationDelay);
88
+ }
89
+ animationMotionQuery() {
90
+ return __classPrivateFieldGet(this, _Options_data, "f").animationMotionQuery;
91
+ }
92
+ /**
93
+ * Returns the `${name}AnimationDelay` option for one animation name as a
94
+ * range, or `undefined` when unset.
95
+ */
96
+ animationDelayFor(name) {
97
+ return __classPrivateFieldGet(this, _Options_instances, "m", _Options_toRange).call(this, __classPrivateFieldGet(this, _Options_instances, "m", _Options_dynamic).call(this, `${name}AnimationDelay`));
98
+ }
82
99
  /**
83
100
  * Returns the global `tags` filter as parsed tokens, or an empty array when
84
101
  * unset. Each raw token (`category` / `category:value`, optionally
@@ -30,11 +30,7 @@ interface RangeField {
30
30
  readonly min?: number;
31
31
  readonly max?: number;
32
32
  }
33
- interface AnimationField {
34
- readonly type: 'animation';
35
- readonly values: readonly string[];
36
- }
37
- export type FieldDescriptor = StringField | NumberField | BooleanField | EnumField | ColorField | RangeField | AnimationField;
33
+ export type FieldDescriptor = StringField | NumberField | BooleanField | EnumField | ColorField | RangeField;
38
34
  export type Descriptor = Record<string, FieldDescriptor>;
39
35
  /**
40
36
  * Builds a descriptor of every option a given style accepts. Tooling such as
@@ -108,13 +108,23 @@ _a = OptionsDescriptor, _OptionsDescriptor_descriptor = new WeakMap(), _OptionsD
108
108
  };
109
109
  }
110
110
  // Only advertise the animation options when the style carries declarative
111
- // animations — on a static style both are accepted but have no effect.
111
+ // animations. On a static style they are accepted but have no effect.
112
+ // Every animation name gets its own switch, speed and delay field, in the
113
+ // order of the name list.
112
114
  if (__classPrivateFieldGet(this, _OptionsDescriptor_style, "f").hasAnimations()) {
113
- result.animation = {
114
- type: 'animation',
115
- values: __classPrivateFieldGet(this, _OptionsDescriptor_style, "f").animationNames(),
116
- };
115
+ result.animation = { type: 'boolean' };
117
116
  result.animationSpeed = { type: 'range', min: 0.1, max: 10 };
117
+ result.animationDelay = { type: 'range', min: -3600, max: 3600 };
118
+ result.animationMotionQuery = { type: 'boolean' };
119
+ for (const name of __classPrivateFieldGet(this, _OptionsDescriptor_style, "f").animationNames()) {
120
+ result[`${name}Animation`] = { type: 'boolean' };
121
+ result[`${name}AnimationSpeed`] = { type: 'range', min: 0.1, max: 10 };
122
+ result[`${name}AnimationDelay`] = {
123
+ type: 'range',
124
+ min: -3600,
125
+ max: 3600,
126
+ };
127
+ }
118
128
  }
119
129
  return result;
120
130
  };
package/lib/Renderer.js CHANGED
@@ -188,21 +188,26 @@ _a = Renderer, _Renderer_style = new WeakMap(), _Renderer_resolver = new WeakMap
188
188
  }
189
189
  return '';
190
190
  }
191
- const attrs = __classPrivateFieldGet(this, _Renderer_instances, "m", _Renderer_renderAttributes).call(this, __classPrivateFieldGet(this, _Renderer_instances, "m", _Renderer_attributesWithoutAnimatedOpacity).call(this, element.attributes(), element));
192
191
  const children = __classPrivateFieldGet(this, _Renderer_instances, "m", _Renderer_renderElements).call(this, element.children());
192
+ // A wrapper whose children all rendered to nothing, because an optional
193
+ // component came up empty, has no content left to group. It draws
194
+ // nothing either way, but a masked group without content has an empty
195
+ // bounding box, and strict SVG parsers reject the whole document over
196
+ // it. Wrappers that carry an id stay, so references keep resolving.
197
+ if (children.length === 0 &&
198
+ element.children().length > 0 &&
199
+ element.attributes()?.id === undefined) {
200
+ return '';
201
+ }
202
+ // The animation switches are read once the element is known to render,
203
+ // after its children, so the resolved options record them in one order
204
+ // regardless of the attributes the element carries.
205
+ const active = __classPrivateFieldGet(this, _Renderer_instances, "m", _Renderer_activeAnimations).call(this, element);
206
+ const attrs = __classPrivateFieldGet(this, _Renderer_instances, "m", _Renderer_renderAttributes).call(this, __classPrivateFieldGet(this, _Renderer_instances, "m", _Renderer_attributesWithoutAnimatedOpacity).call(this, element.attributes(), active));
193
207
  if (children.length === 0) {
194
- // A wrapper whose children all rendered to nothing, because an optional
195
- // component came up empty, has no content left to group. It draws
196
- // nothing either way, but a masked group without content has an empty
197
- // bounding box, and strict SVG parsers reject the whole document over
198
- // it. Wrappers that carry an id stay, so references keep resolving.
199
- if (element.children().length > 0 &&
200
- element.attributes()?.id === undefined) {
201
- return '';
202
- }
203
- return __classPrivateFieldGet(this, _Renderer_instances, "m", _Renderer_applyAnimations).call(this, `<${name}${attrs}/>`, element);
208
+ return __classPrivateFieldGet(this, _Renderer_instances, "m", _Renderer_applyAnimations).call(this, `<${name}${attrs}/>`, element, active);
204
209
  }
205
- return __classPrivateFieldGet(this, _Renderer_instances, "m", _Renderer_applyAnimations).call(this, `<${name}${attrs}>${children}</${name}>`, element);
210
+ return __classPrivateFieldGet(this, _Renderer_instances, "m", _Renderer_applyAnimations).call(this, `<${name}${attrs}>${children}</${name}>`, element, active);
206
211
  }, _Renderer_renderTextElement = function _Renderer_renderTextElement(element) {
207
212
  const value = element.value();
208
213
  return value !== undefined ? Xml.escape(__classPrivateFieldGet(this, _Renderer_instances, "m", _Renderer_resolveValue).call(this, value)) : '';
@@ -229,7 +234,8 @@ _a = Renderer, _Renderer_style = new WeakMap(), _Renderer_resolver = new WeakMap
229
234
  __classPrivateFieldGet(this, _Renderer_defs, "f").set(id, `<g id="${id}">${body}</g>`);
230
235
  }
231
236
  const transforms = __classPrivateFieldGet(this, _Renderer_instances, "m", _Renderer_buildTransforms).call(this, component);
232
- const userAttributes = __classPrivateFieldGet(this, _Renderer_instances, "m", _Renderer_attributesWithoutAnimatedOpacity).call(this, element.attributes(), element);
237
+ const active = __classPrivateFieldGet(this, _Renderer_instances, "m", _Renderer_activeAnimations).call(this, element);
238
+ const userAttributes = __classPrivateFieldGet(this, _Renderer_instances, "m", _Renderer_attributesWithoutAnimatedOpacity).call(this, element.attributes(), active);
233
239
  let mergedAttributes = userAttributes;
234
240
  if (transforms.length > 0) {
235
241
  const userTransform = userAttributes?.transform;
@@ -239,7 +245,7 @@ _a = Renderer, _Renderer_style = new WeakMap(), _Renderer_resolver = new WeakMap
239
245
  mergedAttributes = { ...userAttributes, transform: allParts.join(' ') };
240
246
  }
241
247
  const attrs = __classPrivateFieldGet(this, _Renderer_instances, "m", _Renderer_renderAttributes).call(this, mergedAttributes);
242
- return __classPrivateFieldGet(this, _Renderer_instances, "m", _Renderer_applyAnimations).call(this, `<use${attrs} href="#${id}"/>`, element);
248
+ return __classPrivateFieldGet(this, _Renderer_instances, "m", _Renderer_applyAnimations).call(this, `<use${attrs} href="#${id}" data-dicebear-component="${componentName}"/>`, element, active);
243
249
  }, _Renderer_buildTransforms = function _Renderer_buildTransforms(component) {
244
250
  const { rotate, translateX, translateY, scale } = __classPrivateFieldGet(this, _Renderer_resolver, "f").componentTransform(component.name());
245
251
  if (translateX === 0 && translateY === 0 && rotate === 0 && scale === 1) {
@@ -334,52 +340,58 @@ _a = Renderer, _Renderer_style = new WeakMap(), _Renderer_resolver = new WeakMap
334
340
  }, _Renderer_hashSeed = function _Renderer_hashSeed() {
335
341
  return (__classPrivateFieldSet(this, _Renderer_cachedSeedHash, __classPrivateFieldGet(this, _Renderer_cachedSeedHash, "f") ?? Fnv1a.hex((__classPrivateFieldGet(this, _Renderer_style, "f").meta().source().name() ?? '') + ':' + __classPrivateFieldGet(this, _Renderer_resolver, "f").seed()), "f"));
336
342
  }, _Renderer_animationHash = function _Renderer_animationHash() {
337
- const selection = __classPrivateFieldGet(this, _Renderer_resolver, "f").animation();
338
- const names = Array.isArray(selection)
339
- ? ':' + [...new Set(selection)].sort().join(',')
340
- : '';
343
+ if (__classPrivateFieldGet(this, _Renderer_cachedAnimationHash, "f") !== undefined) {
344
+ return __classPrivateFieldGet(this, _Renderer_cachedAnimationHash, "f");
345
+ }
341
346
  const random = __classPrivateFieldGet(this, _Renderer_resolver, "f").idRandomization()
342
347
  ? ':' + __classPrivateFieldGet(this, _Renderer_instances, "m", _Renderer_randomSuffix).call(this)
343
348
  : '';
344
- return (__classPrivateFieldSet(this, _Renderer_cachedAnimationHash, __classPrivateFieldGet(this, _Renderer_cachedAnimationHash, "f") ?? Fnv1a.hex((__classPrivateFieldGet(this, _Renderer_style, "f").meta().source().name() ?? '') +
349
+ // Every named timeline the style carries joins the hash with its state,
350
+ // `off` or the factor and offset it plays at, so two renders that differ
351
+ // only in a per-name animation option never share their rules. The style
352
+ // lists its names in byte order already.
353
+ const states = __classPrivateFieldGet(this, _Renderer_style, "f")
354
+ .animationNames()
355
+ .map((name) => __classPrivateFieldGet(this, _Renderer_resolver, "f").animationPlays(name)
356
+ ? `${name}:${Number.format(__classPrivateFieldGet(this, _Renderer_resolver, "f").animationSpeedFor(name))}:${Number.format(__classPrivateFieldGet(this, _Renderer_resolver, "f").animationDelayFor(name))}`
357
+ : `${name}:off`);
358
+ const named = states.length > 0 ? ':' + states.join(',') : '';
359
+ // Without the media query the rules apply to every viewer. A render that
360
+ // keeps the query must not pick them up on the same page, so the two get
361
+ // different names. The default adds nothing and leaves the hash as it was.
362
+ const motion = __classPrivateFieldGet(this, _Renderer_resolver, "f").animationMotionQuery()
363
+ ? ''
364
+ : ':nomotionquery';
365
+ return (__classPrivateFieldSet(this, _Renderer_cachedAnimationHash, Fnv1a.hex((__classPrivateFieldGet(this, _Renderer_style, "f").meta().source().name() ?? '') +
345
366
  ':' +
346
367
  __classPrivateFieldGet(this, _Renderer_resolver, "f").seed() +
347
368
  ':' +
348
369
  Number.format(__classPrivateFieldGet(this, _Renderer_resolver, "f").animationSpeed()) +
349
- names +
370
+ ':' +
371
+ Number.format(__classPrivateFieldGet(this, _Renderer_resolver, "f").animationDelay()) +
372
+ named +
373
+ motion +
350
374
  random), "f"));
351
375
  }, _Renderer_activeAnimations = function _Renderer_activeAnimations(element) {
352
376
  const animations = element.animations();
353
377
  if (animations.length === 0) {
354
378
  return animations;
355
379
  }
356
- const selection = __classPrivateFieldGet(this, _Renderer_resolver, "f").animation();
357
- // `true` plays every timeline. A name array plays only the timelines
358
- // carrying one of those names, so unnamed timelines stay static then.
359
- return selection === true
360
- ? animations
361
- : selection === false
362
- ? []
363
- : animations.filter((animation) => animation.name !== undefined &&
364
- selection.includes(animation.name));
365
- }, _Renderer_attributesWithoutAnimatedOpacity = function _Renderer_attributesWithoutAnimatedOpacity(attributes, element) {
380
+ // The global switch is read first so it lands in the resolved options
381
+ // whenever a node carries animations, on or off. Named timelines then
382
+ // follow their own switch when the user set one.
383
+ __classPrivateFieldGet(this, _Renderer_resolver, "f").animation();
384
+ return animations.filter((animation) => __classPrivateFieldGet(this, _Renderer_resolver, "f").animationPlays(animation.name));
385
+ }, _Renderer_attributesWithoutAnimatedOpacity = function _Renderer_attributesWithoutAnimatedOpacity(attributes, active) {
366
386
  if (attributes?.opacity === undefined ||
367
- element.animations().length === 0) {
368
- return attributes;
369
- }
370
- const active = __classPrivateFieldGet(this, _Renderer_instances, "m", _Renderer_activeAnimations).call(this, element);
371
- if (!active.some((animation) => animation.tracks.opacity !== undefined)) {
387
+ !active.some((animation) => animation.tracks.opacity !== undefined)) {
372
388
  return attributes;
373
389
  }
374
390
  const rest = { ...attributes };
375
391
  delete rest.opacity;
376
392
  return rest;
377
- }, _Renderer_applyAnimations = function _Renderer_applyAnimations(markup, element) {
378
- if (markup.length === 0) {
379
- return markup;
380
- }
381
- const active = __classPrivateFieldGet(this, _Renderer_instances, "m", _Renderer_activeAnimations).call(this, element);
382
- if (active.length === 0) {
393
+ }, _Renderer_applyAnimations = function _Renderer_applyAnimations(markup, element, active) {
394
+ if (markup.length === 0 || active.length === 0) {
383
395
  return markup;
384
396
  }
385
397
  const classes = [];
@@ -414,9 +426,12 @@ _a = Renderer, _Renderer_style = new WeakMap(), _Renderer_resolver = new WeakMap
414
426
  __classPrivateFieldGet(this, _Renderer_keyframesByContent, "f").set(body, keyframesName);
415
427
  __classPrivateFieldGet(this, _Renderer_keyframesCss, "f").push(`@keyframes ${keyframesName}{${body}}`);
416
428
  }
417
- const speed = __classPrivateFieldGet(this, _Renderer_resolver, "f").animationSpeed();
429
+ const speed = __classPrivateFieldGet(this, _Renderer_resolver, "f").animationSpeedFor(animation.name);
418
430
  const duration = Number.format(animation.duration / speed);
419
- const delay = Number.format((animation.delay ?? 0) / speed);
431
+ // The user's offset is in seconds of playback, so it is added after the
432
+ // speed has scaled the authored delay.
433
+ const delay = Number.format((animation.delay ?? 0) / speed +
434
+ __classPrivateFieldGet(this, _Renderer_resolver, "f").animationDelayFor(animation.name));
420
435
  const iterations = animation.iterations === undefined || animation.iterations === 'infinite'
421
436
  ? 'infinite'
422
437
  : Number.format(animation.iterations);
@@ -487,7 +502,10 @@ _a = Renderer, _Renderer_style = new WeakMap(), _Renderer_resolver = new WeakMap
487
502
  while (__classPrivateFieldGet(this, _Renderer_defs, "f").has(key)) {
488
503
  key += '-';
489
504
  }
490
- __classPrivateFieldGet(this, _Renderer_defs, "f").set(key, `<style>@media (prefers-reduced-motion:no-preference){${__classPrivateFieldGet(this, _Renderer_keyframesCss, "f").join('')}${__classPrivateFieldGet(this, _Renderer_animationCss, "f").join('')}}</style>`);
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()
507
+ ? `<style>@media (prefers-reduced-motion:no-preference){${css}}</style>`
508
+ : `<style>${css}</style>`);
491
509
  };
492
510
  /**
493
511
  * The canonical track order, outermost wrapper to innermost. It mirrors the
package/lib/Resolver.d.ts CHANGED
@@ -16,8 +16,36 @@ export declare class Resolver<D = unknown> {
16
16
  seed(): string;
17
17
  size(): number | undefined;
18
18
  idRandomization(): boolean;
19
- animation(): boolean | readonly string[];
19
+ animation(): boolean;
20
+ /**
21
+ * Whether one timeline plays. A named timeline follows its
22
+ * `${name}Animation` switch when the user set one, recorded under that
23
+ * key, and the global `animation` switch otherwise. Unnamed timelines
24
+ * always follow the global switch.
25
+ */
26
+ animationPlays(name: string | undefined): boolean;
20
27
  animationSpeed(): number;
28
+ /**
29
+ * Returns the speed factor of one timeline. A named timeline plays at its
30
+ * `${name}AnimationSpeed` option when the user set one, drawn under that
31
+ * key, and at the global factor otherwise. Unnamed timelines always follow
32
+ * the global factor.
33
+ */
34
+ animationSpeedFor(name: string | undefined): number;
35
+ animationDelay(): number;
36
+ /**
37
+ * Returns the start offset of one timeline in seconds. A named timeline
38
+ * uses its `${name}AnimationDelay` option when the user set one, drawn
39
+ * under that key, and the global offset otherwise. Unnamed timelines
40
+ * always follow the global offset.
41
+ */
42
+ animationDelayFor(name: string | undefined): number;
43
+ /**
44
+ * Whether the animation CSS sits inside a `prefers-reduced-motion` media
45
+ * query. On by default. Renderers that ignore media queries need it off,
46
+ * and the app then decides about `animation` from the system setting.
47
+ */
48
+ animationMotionQuery(): boolean;
21
49
  title(): string | undefined;
22
50
  flip(): StyleOptionsFlipValue;
23
51
  fontFamily(): string;
package/lib/Resolver.js CHANGED
@@ -48,14 +48,63 @@ export class Resolver {
48
48
  return __classPrivateFieldGet(this, _Resolver_instances, "m", _Resolver_memo).call(this, 'idRandomization', () => __classPrivateFieldGet(this, _Resolver_options, "f").idRandomization() ?? false);
49
49
  }
50
50
  animation() {
51
- // Deliberately without PRNG involvement — whether and what animates must
52
- // not depend on the seed. `true` plays every timeline, a name array only
53
- // the timelines carrying one of those names.
51
+ // Deliberately without PRNG involvement: whether an avatar animates must
52
+ // not depend on the seed.
54
53
  return __classPrivateFieldGet(this, _Resolver_instances, "m", _Resolver_memo).call(this, 'animation', () => __classPrivateFieldGet(this, _Resolver_options, "f").animation() ?? false);
55
54
  }
55
+ /**
56
+ * Whether one timeline plays. A named timeline follows its
57
+ * `${name}Animation` switch when the user set one, recorded under that
58
+ * key, and the global `animation` switch otherwise. Unnamed timelines
59
+ * always follow the global switch.
60
+ */
61
+ animationPlays(name) {
62
+ const value = name === undefined ? undefined : __classPrivateFieldGet(this, _Resolver_options, "f").animationFor(name);
63
+ if (name === undefined || value === undefined) {
64
+ return this.animation();
65
+ }
66
+ return __classPrivateFieldGet(this, _Resolver_instances, "m", _Resolver_memo).call(this, `${name}Animation`, () => value);
67
+ }
56
68
  animationSpeed() {
57
69
  return __classPrivateFieldGet(this, _Resolver_instances, "m", _Resolver_memoFloat).call(this, 'animationSpeed', __classPrivateFieldGet(this, _Resolver_options, "f").animationSpeed(), 1);
58
70
  }
71
+ /**
72
+ * Returns the speed factor of one timeline. A named timeline plays at its
73
+ * `${name}AnimationSpeed` option when the user set one, drawn under that
74
+ * key, and at the global factor otherwise. Unnamed timelines always follow
75
+ * the global factor.
76
+ */
77
+ animationSpeedFor(name) {
78
+ const range = name === undefined ? undefined : __classPrivateFieldGet(this, _Resolver_options, "f").animationSpeedFor(name);
79
+ if (name === undefined || range === undefined) {
80
+ return this.animationSpeed();
81
+ }
82
+ return __classPrivateFieldGet(this, _Resolver_instances, "m", _Resolver_memoFloat).call(this, `${name}AnimationSpeed`, range, 1);
83
+ }
84
+ animationDelay() {
85
+ return __classPrivateFieldGet(this, _Resolver_instances, "m", _Resolver_memoFloat).call(this, 'animationDelay', __classPrivateFieldGet(this, _Resolver_options, "f").animationDelay(), 0);
86
+ }
87
+ /**
88
+ * Returns the start offset of one timeline in seconds. A named timeline
89
+ * uses its `${name}AnimationDelay` option when the user set one, drawn
90
+ * under that key, and the global offset otherwise. Unnamed timelines
91
+ * always follow the global offset.
92
+ */
93
+ animationDelayFor(name) {
94
+ const range = name === undefined ? undefined : __classPrivateFieldGet(this, _Resolver_options, "f").animationDelayFor(name);
95
+ if (name === undefined || range === undefined) {
96
+ return this.animationDelay();
97
+ }
98
+ return __classPrivateFieldGet(this, _Resolver_instances, "m", _Resolver_memoFloat).call(this, `${name}AnimationDelay`, range, 0);
99
+ }
100
+ /**
101
+ * Whether the animation CSS sits inside a `prefers-reduced-motion` media
102
+ * query. On by default. Renderers that ignore media queries need it off,
103
+ * and the app then decides about `animation` from the system setting.
104
+ */
105
+ animationMotionQuery() {
106
+ return __classPrivateFieldGet(this, _Resolver_instances, "m", _Resolver_memo).call(this, 'animationMotionQuery', () => __classPrivateFieldGet(this, _Resolver_options, "f").animationMotionQuery() ?? true);
107
+ }
59
108
  title() {
60
109
  return __classPrivateFieldGet(this, _Resolver_instances, "m", _Resolver_memo).call(this, 'title', () => __classPrivateFieldGet(this, _Resolver_options, "f").title());
61
110
  }
@@ -232,13 +281,12 @@ _Resolver_style = new WeakMap(), _Resolver_options = new WeakMap(), _Resolver_pr
232
281
  const source = userColors ?? styleColor?.values() ?? [];
233
282
  let candidates = source.map((c) => Color.toHex(c));
234
283
  const fixed = this.colorOrder(name) === COLOR_ORDER_FIXED;
235
- const verbatim = userColors !== undefined && fixed;
236
284
  const fill = this.colorFill(name);
237
285
  const stops = fill === 'solid'
238
286
  ? 1
239
- : __classPrivateFieldGet(this, _Resolver_instances, "m", _Resolver_colorFillStops).call(this, name, verbatim ? candidates.length : 2);
287
+ : __classPrivateFieldGet(this, _Resolver_instances, "m", _Resolver_colorFillStops).call(this, name, fixed ? candidates.length : 2);
240
288
  if (!styleColor) {
241
- return __classPrivateFieldGet(this, _Resolver_instances, "m", _Resolver_order).call(this, name, candidates, fixed, verbatim).slice(0, stops);
289
+ return __classPrivateFieldGet(this, _Resolver_instances, "m", _Resolver_order).call(this, name, candidates, fixed).slice(0, stops);
242
290
  }
243
291
  // Detect circular references (e.g. a.contrastTo = b, b.contrastTo = a)
244
292
  if (__classPrivateFieldGet(this, _Resolver_colorResolving, "f").includes(name)) {
@@ -248,7 +296,7 @@ _Resolver_style = new WeakMap(), _Resolver_options = new WeakMap(), _Resolver_pr
248
296
  const contrastTo = styleColor.contrastTo();
249
297
  const notEqualTo = styleColor.notEqualTo();
250
298
  try {
251
- if (contrastTo && !verbatim) {
299
+ if (contrastTo && !fixed) {
252
300
  const refColor = this.color(contrastTo)[0];
253
301
  if (refColor) {
254
302
  candidates = Color.sortByContrast(candidates, refColor);
@@ -270,19 +318,10 @@ _Resolver_style = new WeakMap(), _Resolver_options = new WeakMap(), _Resolver_pr
270
318
  // Skip shuffle when sorted by contrast to preserve the ordering
271
319
  const ordered = contrastTo
272
320
  ? candidates
273
- : __classPrivateFieldGet(this, _Resolver_instances, "m", _Resolver_order).call(this, name, candidates, fixed, verbatim);
321
+ : __classPrivateFieldGet(this, _Resolver_instances, "m", _Resolver_order).call(this, name, candidates, fixed);
274
322
  return ordered.slice(0, stops);
275
- }, _Resolver_order = function _Resolver_order(name, candidates, fixed, verbatim) {
276
- if (!fixed) {
277
- return __classPrivateFieldGet(this, _Resolver_prng, "f").shuffle(`${name}Color`, candidates);
278
- }
279
- if (verbatim) {
280
- return candidates;
281
- }
282
- // Deprecated: DiceBear 11 will take the palette in its definition order
283
- // here, the same verbatim rule as user-supplied colors, and drop this
284
- // sort (see CHANGELOG.md, "Deprecated").
285
- return Array.from(new Set(candidates)).sort();
323
+ }, _Resolver_order = function _Resolver_order(name, candidates, fixed) {
324
+ return fixed ? candidates : __classPrivateFieldGet(this, _Resolver_prng, "f").shuffle(`${name}Color`, candidates);
286
325
  }, _Resolver_colorFillStops = function _Resolver_colorFillStops(name, fallback) {
287
326
  const range = __classPrivateFieldGet(this, _Resolver_options, "f").colorFillStops(name);
288
327
  return range
package/lib/Style.d.ts CHANGED
@@ -56,9 +56,9 @@ export declare class Style<D = unknown> {
56
56
  /**
57
57
  * Returns the sorted distinct names of the definition's animation
58
58
  * timelines. Computed once and cached. Consumed by the options descriptor
59
- * so tooling can offer the by-name form of the `animation` option. Sorted
60
- * so every port reports the same order regardless of how it walks the
61
- * definition.
59
+ * so tooling can offer a switch, a speed and a delay per animation name.
60
+ * Sorted so every port reports the same order regardless of how it walks
61
+ * the definition.
62
62
  */
63
63
  animationNames(): readonly string[];
64
64
  /**
package/lib/Style.js CHANGED
@@ -10,7 +10,6 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
10
10
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
11
  };
12
12
  var _Style_instances, _a, _Style_data, _Style_meta, _Style_canvas, _Style_components, _Style_colors, _Style_hasAnimations, _Style_animationNames, _Style_validateAliases, _Style_isAlias, _Style_validateAnimations, _Style_visitElements;
13
- import { StyleValidator } from './Validator/StyleValidator.js';
14
13
  import { StyleValidationError } from './Error/StyleValidationError.js';
15
14
  import { Meta } from './Style/Meta.js';
16
15
  import { Canvas } from './Style/Canvas.js';
@@ -31,7 +30,6 @@ export class Style {
31
30
  _Style_colors.set(this, void 0);
32
31
  _Style_hasAnimations.set(this, void 0);
33
32
  _Style_animationNames.set(this, void 0);
34
- StyleValidator.validate(data);
35
33
  __classPrivateFieldSet(this, _Style_data, structuredClone(data), "f");
36
34
  __classPrivateFieldGet(this, _Style_instances, "m", _Style_validateAliases).call(this);
37
35
  __classPrivateFieldGet(this, _Style_instances, "m", _Style_validateAnimations).call(this);
@@ -125,9 +123,9 @@ export class Style {
125
123
  /**
126
124
  * Returns the sorted distinct names of the definition's animation
127
125
  * timelines. Computed once and cached. Consumed by the options descriptor
128
- * so tooling can offer the by-name form of the `animation` option. Sorted
129
- * so every port reports the same order regardless of how it walks the
130
- * definition.
126
+ * so tooling can offer a switch, a speed and a delay per animation name.
127
+ * Sorted so every port reports the same order regardless of how it walks
128
+ * the definition.
131
129
  */
132
130
  animationNames() {
133
131
  if (__classPrivateFieldGet(this, _Style_animationNames, "f") === undefined) {
@@ -78,9 +78,10 @@ export interface StyleDefinitionAnimationOrigin {
78
78
  * `animation` render option is enabled. Absent fields carry these defaults:
79
79
  * `delay` 0, `iterations` `'infinite'`, `direction` `'normal'`, `fill`
80
80
  * `'none'`, `easing` `'linear'`, `origin` center (50/50). The optional
81
- * `name` groups the timeline under a user-selectable animation: the
82
- * `animation` option accepts these names to play a subset, and a timeline
83
- * without a name only plays when the option enables all animations.
81
+ * `name` groups the timeline under a user-selectable animation: a named
82
+ * timeline follows its `${name}Animation`, `${name}AnimationSpeed` and
83
+ * `${name}AnimationDelay` options when set, and a timeline without a name
84
+ * always follows the global `animation` switch.
84
85
  */
85
86
  export interface StyleDefinitionAnimation {
86
87
  readonly name?: string;