@dicebear/core 11.0.0-rc.2 → 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/lib/Options.d.ts CHANGED
@@ -38,6 +38,7 @@ export declare class Options<D = unknown> {
38
38
  */
39
39
  animationSpeedFor(name: string): Range | undefined;
40
40
  animationDelay(): Range | undefined;
41
+ animationMotionQuery(): boolean | undefined;
41
42
  /**
42
43
  * Returns the `${name}AnimationDelay` option for one animation name as a
43
44
  * range, or `undefined` when unset.
package/lib/Options.js CHANGED
@@ -86,6 +86,9 @@ export class Options {
86
86
  animationDelay() {
87
87
  return __classPrivateFieldGet(this, _Options_instances, "m", _Options_toRange).call(this, __classPrivateFieldGet(this, _Options_data, "f").animationDelay);
88
88
  }
89
+ animationMotionQuery() {
90
+ return __classPrivateFieldGet(this, _Options_data, "f").animationMotionQuery;
91
+ }
89
92
  /**
90
93
  * Returns the `${name}AnimationDelay` option for one animation name as a
91
94
  * range, or `undefined` when unset.
@@ -115,6 +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
119
  for (const name of __classPrivateFieldGet(this, _OptionsDescriptor_style, "f").animationNames()) {
119
120
  result[`${name}Animation`] = { type: 'boolean' };
120
121
  result[`${name}AnimationSpeed`] = { type: 'range', min: 0.1, max: 10 };
package/lib/Renderer.js CHANGED
@@ -245,7 +245,7 @@ _a = Renderer, _Renderer_style = new WeakMap(), _Renderer_resolver = new WeakMap
245
245
  mergedAttributes = { ...userAttributes, transform: allParts.join(' ') };
246
246
  }
247
247
  const attrs = __classPrivateFieldGet(this, _Renderer_instances, "m", _Renderer_renderAttributes).call(this, mergedAttributes);
248
- return __classPrivateFieldGet(this, _Renderer_instances, "m", _Renderer_applyAnimations).call(this, `<use${attrs} href="#${id}"/>`, element, active);
248
+ return __classPrivateFieldGet(this, _Renderer_instances, "m", _Renderer_applyAnimations).call(this, `<use${attrs} href="#${id}" data-dicebear-component="${componentName}"/>`, element, active);
249
249
  }, _Renderer_buildTransforms = function _Renderer_buildTransforms(component) {
250
250
  const { rotate, translateX, translateY, scale } = __classPrivateFieldGet(this, _Renderer_resolver, "f").componentTransform(component.name());
251
251
  if (translateX === 0 && translateY === 0 && rotate === 0 && scale === 1) {
@@ -356,6 +356,12 @@ _a = Renderer, _Renderer_style = new WeakMap(), _Renderer_resolver = new WeakMap
356
356
  ? `${name}:${Number.format(__classPrivateFieldGet(this, _Renderer_resolver, "f").animationSpeedFor(name))}:${Number.format(__classPrivateFieldGet(this, _Renderer_resolver, "f").animationDelayFor(name))}`
357
357
  : `${name}:off`);
358
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';
359
365
  return (__classPrivateFieldSet(this, _Renderer_cachedAnimationHash, Fnv1a.hex((__classPrivateFieldGet(this, _Renderer_style, "f").meta().source().name() ?? '') +
360
366
  ':' +
361
367
  __classPrivateFieldGet(this, _Renderer_resolver, "f").seed() +
@@ -364,6 +370,7 @@ _a = Renderer, _Renderer_style = new WeakMap(), _Renderer_resolver = new WeakMap
364
370
  ':' +
365
371
  Number.format(__classPrivateFieldGet(this, _Renderer_resolver, "f").animationDelay()) +
366
372
  named +
373
+ motion +
367
374
  random), "f"));
368
375
  }, _Renderer_activeAnimations = function _Renderer_activeAnimations(element) {
369
376
  const animations = element.animations();
@@ -495,7 +502,10 @@ _a = Renderer, _Renderer_style = new WeakMap(), _Renderer_resolver = new WeakMap
495
502
  while (__classPrivateFieldGet(this, _Renderer_defs, "f").has(key)) {
496
503
  key += '-';
497
504
  }
498
- __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>`);
499
509
  };
500
510
  /**
501
511
  * The canonical track order, outermost wrapper to innermost. It mirrors the
package/lib/Resolver.d.ts CHANGED
@@ -40,6 +40,12 @@ export declare class Resolver<D = unknown> {
40
40
  * always follow the global offset.
41
41
  */
42
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;
43
49
  title(): string | undefined;
44
50
  flip(): StyleOptionsFlipValue;
45
51
  fontFamily(): string;
package/lib/Resolver.js CHANGED
@@ -97,6 +97,14 @@ export class Resolver {
97
97
  }
98
98
  return __classPrivateFieldGet(this, _Resolver_instances, "m", _Resolver_memoFloat).call(this, `${name}AnimationDelay`, range, 0);
99
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
+ }
100
108
  title() {
101
109
  return __classPrivateFieldGet(this, _Resolver_instances, "m", _Resolver_memo).call(this, 'title', () => __classPrivateFieldGet(this, _Resolver_options, "f").title());
102
110
  }
@@ -46,6 +46,7 @@ export interface StyleOptionsBase {
46
46
  readonly animation?: boolean;
47
47
  readonly animationSpeed?: number | readonly [number, number];
48
48
  readonly animationDelay?: number | readonly [number, number];
49
+ readonly animationMotionQuery?: boolean;
49
50
  }
50
51
  type ComponentVariantOption<D, K extends string> = VariantNames<D, K> | readonly VariantNames<D, K>[] | Readonly<Partial<Record<VariantNames<D, K>, number>>>;
51
52
  type IsAlias<D, C extends string> = D extends {
@@ -1192,6 +1192,14 @@ const validate = (function () {
1192
1192
  errorCount++;
1193
1193
  }
1194
1194
  }
1195
+ if (data.animationMotionQuery !== undefined && hasOwn(data, "animationMotionQuery")) {
1196
+ if (!(typeof data.animationMotionQuery === "boolean")) {
1197
+ if (validate.errors === null)
1198
+ validate.errors = [];
1199
+ validate.errors.push({ keywordLocation: "#/properties/animationMotionQuery/type", instanceLocation: "#/animationMotionQuery" });
1200
+ errorCount++;
1201
+ }
1202
+ }
1195
1203
  if (errorCount === prev0) {
1196
1204
  for (const key1 of Object.keys(data)) {
1197
1205
  if (pattern2.test(key1)) {
@@ -1592,7 +1600,7 @@ const validate = (function () {
1592
1600
  }
1593
1601
  }
1594
1602
  for (const key4 of Object.keys(data)) {
1595
- 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" && !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 !== "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)) {
1596
1604
  if (validate.errors === null)
1597
1605
  validate.errors = [];
1598
1606
  validate.errors.push({ keywordLocation: "#/additionalProperties", instanceLocation: "#/" + pointerPart(key4) });
package/lib/index.d.ts CHANGED
@@ -18,6 +18,5 @@ export declare class Avatar<D = unknown> extends AvatarBase<D> {
18
18
  constructor(style: StyleBase<D>, optionsInput?: StyleOptions<D>);
19
19
  }
20
20
  export type { StyleDefinition };
21
- export { Color } from './Utils/Color.js';
22
21
  export { OptionsDescriptor } from './OptionsDescriptor.js';
23
22
  export type { StyleOptions } from './StyleOptions.js';
package/lib/index.js CHANGED
@@ -24,5 +24,4 @@ export class Avatar extends AvatarBase {
24
24
  super(style, optionsInput);
25
25
  }
26
26
  }
27
- export { Color } from './Utils/Color.js';
28
27
  export { OptionsDescriptor } from './OptionsDescriptor.js';
package/lib/lite.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  export { Style, type StyleDefinition } from './Style.js';
2
2
  export { Avatar } from './Avatar.js';
3
- export { Color } from './Utils/Color.js';
4
3
  export { OptionsDescriptor } from './OptionsDescriptor.js';
5
4
  export type { StyleOptions } from './StyleOptions.js';
package/lib/lite.js CHANGED
@@ -5,5 +5,4 @@
5
5
  // either arrives from outside.
6
6
  export { Style } from './Style.js';
7
7
  export { Avatar } from './Avatar.js';
8
- export { Color } from './Utils/Color.js';
9
8
  export { OptionsDescriptor } from './OptionsDescriptor.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dicebear/core",
3
- "version": "11.0.0-rc.2",
3
+ "version": "11.0.0-rc.3",
4
4
  "description": "Unique avatars from dozens of styles — deterministic, customizable, vector-based.",
5
5
  "keywords": [
6
6
  "avatar",
@@ -42,7 +42,7 @@
42
42
  "test": "node --test"
43
43
  },
44
44
  "devDependencies": {
45
- "@dicebear/schema": "^2.0.1",
45
+ "@dicebear/schema": "^2.1.0",
46
46
  "@exodus/schemasafe": "^1.3.0",
47
47
  "@tsconfig/recommended": "^1.0.13",
48
48
  "del-cli": "^7.0.0",