@dicebear/core 9.4.2 → 10.0.0-rc.1

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.
Files changed (82) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +12 -0
  3. package/lib/Avatar.d.ts +15 -0
  4. package/lib/Avatar.js +38 -0
  5. package/lib/Error/CircularColorReferenceError.d.ts +4 -0
  6. package/lib/Error/CircularColorReferenceError.js +8 -0
  7. package/lib/Error/OptionsValidationError.d.ts +5 -0
  8. package/lib/Error/OptionsValidationError.js +7 -0
  9. package/lib/Error/StyleValidationError.d.ts +5 -0
  10. package/lib/Error/StyleValidationError.js +7 -0
  11. package/lib/Error/ValidationError.d.ts +8 -0
  12. package/lib/Error/ValidationError.js +18 -0
  13. package/lib/Options.d.ts +23 -0
  14. package/lib/Options.js +217 -0
  15. package/lib/OptionsDescriptor.d.ts +37 -0
  16. package/lib/OptionsDescriptor.js +70 -0
  17. package/lib/Prng/Fnv1a.d.ts +4 -0
  18. package/lib/Prng/Fnv1a.js +16 -0
  19. package/lib/Prng/Mulberry32.d.ts +7 -0
  20. package/lib/Prng/Mulberry32.js +40 -0
  21. package/lib/Prng.d.ts +11 -0
  22. package/lib/Prng.js +101 -0
  23. package/lib/Renderer.d.ts +7 -0
  24. package/lib/Renderer.js +293 -0
  25. package/lib/Style/Canvas.d.ts +9 -0
  26. package/lib/Style/Canvas.js +31 -0
  27. package/lib/Style/Color.d.ts +8 -0
  28. package/lib/Style/Color.js +28 -0
  29. package/lib/Style/Component.d.ts +13 -0
  30. package/lib/Style/Component.js +46 -0
  31. package/lib/Style/ComponentTranslate.d.ts +7 -0
  32. package/lib/Style/ComponentTranslate.js +25 -0
  33. package/lib/Style/ComponentVariant.d.ts +8 -0
  34. package/lib/Style/ComponentVariant.js +28 -0
  35. package/lib/Style/Element.d.ts +10 -0
  36. package/lib/Style/Element.js +36 -0
  37. package/lib/Style/Meta.d.ts +11 -0
  38. package/lib/Style/Meta.js +37 -0
  39. package/lib/Style/MetaCreator.d.ts +7 -0
  40. package/lib/Style/MetaCreator.js +25 -0
  41. package/lib/Style/MetaLicense.d.ts +8 -0
  42. package/lib/Style/MetaLicense.js +28 -0
  43. package/lib/Style/MetaSource.d.ts +7 -0
  44. package/lib/Style/MetaSource.js +25 -0
  45. package/lib/Style.d.ts +18 -0
  46. package/lib/Style.js +63 -0
  47. package/lib/StyleDefinition.d.ts +83 -0
  48. package/lib/StyleOptions.d.ts +54 -0
  49. package/lib/StyleOptions.js +1 -0
  50. package/lib/Utils/Color.d.ts +9 -0
  51. package/lib/Utils/Color.js +67 -0
  52. package/lib/Utils/Initials.d.ts +3 -0
  53. package/lib/Utils/Initials.js +26 -0
  54. package/lib/Utils/License.d.ts +5 -0
  55. package/lib/Utils/License.js +64 -0
  56. package/lib/Utils/Xml.d.ts +4 -0
  57. package/lib/Utils/Xml.js +20 -0
  58. package/lib/Validator/OptionsValidator.d.ts +3 -0
  59. package/lib/Validator/OptionsValidator.js +2203 -0
  60. package/lib/Validator/StyleValidator.d.ts +3 -0
  61. package/lib/Validator/StyleValidator.js +4986 -0
  62. package/lib/index.d.ts +4 -12
  63. package/lib/index.js +3 -12
  64. package/package.json +13 -8
  65. package/lib/core.d.ts +0 -2
  66. package/lib/core.js +0 -67
  67. package/lib/schema.d.ts +0 -2
  68. package/lib/schema.js +0 -79
  69. package/lib/types.d.ts +0 -73
  70. package/lib/utils/color.d.ts +0 -6
  71. package/lib/utils/color.js +0 -35
  72. package/lib/utils/escape.d.ts +0 -1
  73. package/lib/utils/escape.js +0 -8
  74. package/lib/utils/license.d.ts +0 -3
  75. package/lib/utils/license.js +0 -54
  76. package/lib/utils/options.d.ts +0 -3
  77. package/lib/utils/options.js +0 -32
  78. package/lib/utils/prng.d.ts +0 -2
  79. package/lib/utils/prng.js +0 -68
  80. package/lib/utils/svg.d.ts +0 -15
  81. package/lib/utils/svg.js +0 -79
  82. /package/lib/{types.js → StyleDefinition.js} +0 -0
@@ -0,0 +1,36 @@
1
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
2
+ if (kind === "m") throw new TypeError("Private method is not writable");
3
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
4
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
5
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
6
+ };
7
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
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
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
+ };
12
+ var _Element_data, _Element_children;
13
+ export class Element {
14
+ constructor(data) {
15
+ _Element_data.set(this, void 0);
16
+ _Element_children.set(this, void 0);
17
+ __classPrivateFieldSet(this, _Element_data, data, "f");
18
+ }
19
+ type() {
20
+ return __classPrivateFieldGet(this, _Element_data, "f").type;
21
+ }
22
+ name() {
23
+ return __classPrivateFieldGet(this, _Element_data, "f").name;
24
+ }
25
+ value() {
26
+ return __classPrivateFieldGet(this, _Element_data, "f").value;
27
+ }
28
+ attributes() {
29
+ return __classPrivateFieldGet(this, _Element_data, "f").attributes;
30
+ }
31
+ children() {
32
+ __classPrivateFieldSet(this, _Element_children, __classPrivateFieldGet(this, _Element_children, "f") ?? (__classPrivateFieldGet(this, _Element_data, "f").children ?? []).map((child) => new Element(child)), "f");
33
+ return __classPrivateFieldGet(this, _Element_children, "f");
34
+ }
35
+ }
36
+ _Element_data = new WeakMap(), _Element_children = new WeakMap();
@@ -0,0 +1,11 @@
1
+ import type { StyleDefinitionMeta } from '../StyleDefinition.js';
2
+ import { MetaLicense } from './MetaLicense.js';
3
+ import { MetaCreator } from './MetaCreator.js';
4
+ import { MetaSource } from './MetaSource.js';
5
+ export declare class Meta {
6
+ #private;
7
+ constructor(data: StyleDefinitionMeta);
8
+ license(): MetaLicense;
9
+ creator(): MetaCreator;
10
+ source(): MetaSource;
11
+ }
@@ -0,0 +1,37 @@
1
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
2
+ if (kind === "m") throw new TypeError("Private method is not writable");
3
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
4
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
5
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
6
+ };
7
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
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
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
+ };
12
+ var _Meta_data, _Meta_license, _Meta_creator, _Meta_source;
13
+ import { MetaLicense } from './MetaLicense.js';
14
+ import { MetaCreator } from './MetaCreator.js';
15
+ import { MetaSource } from './MetaSource.js';
16
+ export class Meta {
17
+ constructor(data) {
18
+ _Meta_data.set(this, void 0);
19
+ _Meta_license.set(this, void 0);
20
+ _Meta_creator.set(this, void 0);
21
+ _Meta_source.set(this, void 0);
22
+ __classPrivateFieldSet(this, _Meta_data, data, "f");
23
+ }
24
+ license() {
25
+ __classPrivateFieldSet(this, _Meta_license, __classPrivateFieldGet(this, _Meta_license, "f") ?? new MetaLicense(__classPrivateFieldGet(this, _Meta_data, "f").license ?? {}), "f");
26
+ return __classPrivateFieldGet(this, _Meta_license, "f");
27
+ }
28
+ creator() {
29
+ __classPrivateFieldSet(this, _Meta_creator, __classPrivateFieldGet(this, _Meta_creator, "f") ?? new MetaCreator(__classPrivateFieldGet(this, _Meta_data, "f").creator ?? {}), "f");
30
+ return __classPrivateFieldGet(this, _Meta_creator, "f");
31
+ }
32
+ source() {
33
+ __classPrivateFieldSet(this, _Meta_source, __classPrivateFieldGet(this, _Meta_source, "f") ?? new MetaSource(__classPrivateFieldGet(this, _Meta_data, "f").source ?? {}), "f");
34
+ return __classPrivateFieldGet(this, _Meta_source, "f");
35
+ }
36
+ }
37
+ _Meta_data = new WeakMap(), _Meta_license = new WeakMap(), _Meta_creator = new WeakMap(), _Meta_source = new WeakMap();
@@ -0,0 +1,7 @@
1
+ import type { StyleDefinitionMetaCreator } from '../StyleDefinition.js';
2
+ export declare class MetaCreator {
3
+ #private;
4
+ constructor(data: StyleDefinitionMetaCreator);
5
+ name(): string | undefined;
6
+ url(): string | undefined;
7
+ }
@@ -0,0 +1,25 @@
1
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
2
+ if (kind === "m") throw new TypeError("Private method is not writable");
3
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
4
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
5
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
6
+ };
7
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
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
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
+ };
12
+ var _MetaCreator_data;
13
+ export class MetaCreator {
14
+ constructor(data) {
15
+ _MetaCreator_data.set(this, void 0);
16
+ __classPrivateFieldSet(this, _MetaCreator_data, data, "f");
17
+ }
18
+ name() {
19
+ return __classPrivateFieldGet(this, _MetaCreator_data, "f").name;
20
+ }
21
+ url() {
22
+ return __classPrivateFieldGet(this, _MetaCreator_data, "f").url;
23
+ }
24
+ }
25
+ _MetaCreator_data = new WeakMap();
@@ -0,0 +1,8 @@
1
+ import type { StyleDefinitionMetaLicense } from '../StyleDefinition.js';
2
+ export declare class MetaLicense {
3
+ #private;
4
+ constructor(data: StyleDefinitionMetaLicense);
5
+ name(): string | undefined;
6
+ url(): string | undefined;
7
+ text(): string | undefined;
8
+ }
@@ -0,0 +1,28 @@
1
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
2
+ if (kind === "m") throw new TypeError("Private method is not writable");
3
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
4
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
5
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
6
+ };
7
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
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
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
+ };
12
+ var _MetaLicense_data;
13
+ export class MetaLicense {
14
+ constructor(data) {
15
+ _MetaLicense_data.set(this, void 0);
16
+ __classPrivateFieldSet(this, _MetaLicense_data, data, "f");
17
+ }
18
+ name() {
19
+ return __classPrivateFieldGet(this, _MetaLicense_data, "f").name;
20
+ }
21
+ url() {
22
+ return __classPrivateFieldGet(this, _MetaLicense_data, "f").url;
23
+ }
24
+ text() {
25
+ return __classPrivateFieldGet(this, _MetaLicense_data, "f").text;
26
+ }
27
+ }
28
+ _MetaLicense_data = new WeakMap();
@@ -0,0 +1,7 @@
1
+ import type { StyleDefinitionMetaSource } from '../StyleDefinition.js';
2
+ export declare class MetaSource {
3
+ #private;
4
+ constructor(data: StyleDefinitionMetaSource);
5
+ name(): string | undefined;
6
+ url(): string | undefined;
7
+ }
@@ -0,0 +1,25 @@
1
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
2
+ if (kind === "m") throw new TypeError("Private method is not writable");
3
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
4
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
5
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
6
+ };
7
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
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
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
+ };
12
+ var _MetaSource_data;
13
+ export class MetaSource {
14
+ constructor(data) {
15
+ _MetaSource_data.set(this, void 0);
16
+ __classPrivateFieldSet(this, _MetaSource_data, data, "f");
17
+ }
18
+ name() {
19
+ return __classPrivateFieldGet(this, _MetaSource_data, "f").name;
20
+ }
21
+ url() {
22
+ return __classPrivateFieldGet(this, _MetaSource_data, "f").url;
23
+ }
24
+ }
25
+ _MetaSource_data = new WeakMap();
package/lib/Style.d.ts ADDED
@@ -0,0 +1,18 @@
1
+ import type { StyleDefinitionAttributes } from './StyleDefinition.js';
2
+ import { Meta } from './Style/Meta.js';
3
+ import { Canvas } from './Style/Canvas.js';
4
+ import { Component } from './Style/Component.js';
5
+ import { Color } from './Style/Color.js';
6
+ export type { StyleDefinition } from './StyleDefinition.js';
7
+ export declare class Style<D = unknown> {
8
+ #private;
9
+ constructor(data: D);
10
+ id(): string | undefined;
11
+ schema(): string | undefined;
12
+ comment(): string | undefined;
13
+ meta(): Meta;
14
+ attributes(): StyleDefinitionAttributes;
15
+ canvas(): Canvas;
16
+ components(): ReadonlyMap<string, Component>;
17
+ colors(): ReadonlyMap<string, Color>;
18
+ }
package/lib/Style.js ADDED
@@ -0,0 +1,63 @@
1
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
2
+ if (kind === "m") throw new TypeError("Private method is not writable");
3
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
4
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
5
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
6
+ };
7
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
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
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
+ };
12
+ var _Style_data, _Style_meta, _Style_canvas, _Style_components, _Style_colors;
13
+ import { StyleValidator } from './Validator/StyleValidator.js';
14
+ import { Meta } from './Style/Meta.js';
15
+ import { Canvas } from './Style/Canvas.js';
16
+ import { Component } from './Style/Component.js';
17
+ import { Color } from './Style/Color.js';
18
+ export class Style {
19
+ constructor(data) {
20
+ _Style_data.set(this, void 0);
21
+ _Style_meta.set(this, void 0);
22
+ _Style_canvas.set(this, void 0);
23
+ _Style_components.set(this, void 0);
24
+ _Style_colors.set(this, void 0);
25
+ StyleValidator.validate(data);
26
+ __classPrivateFieldSet(this, _Style_data, structuredClone(data), "f");
27
+ }
28
+ id() {
29
+ return __classPrivateFieldGet(this, _Style_data, "f").$id;
30
+ }
31
+ schema() {
32
+ return __classPrivateFieldGet(this, _Style_data, "f").$schema;
33
+ }
34
+ comment() {
35
+ return __classPrivateFieldGet(this, _Style_data, "f").$comment;
36
+ }
37
+ meta() {
38
+ __classPrivateFieldSet(this, _Style_meta, __classPrivateFieldGet(this, _Style_meta, "f") ?? new Meta(__classPrivateFieldGet(this, _Style_data, "f").meta ?? {}), "f");
39
+ return __classPrivateFieldGet(this, _Style_meta, "f");
40
+ }
41
+ attributes() {
42
+ return structuredClone(__classPrivateFieldGet(this, _Style_data, "f").attributes ?? {});
43
+ }
44
+ canvas() {
45
+ __classPrivateFieldSet(this, _Style_canvas, __classPrivateFieldGet(this, _Style_canvas, "f") ?? new Canvas(__classPrivateFieldGet(this, _Style_data, "f").canvas), "f");
46
+ return __classPrivateFieldGet(this, _Style_canvas, "f");
47
+ }
48
+ components() {
49
+ __classPrivateFieldSet(this, _Style_components, __classPrivateFieldGet(this, _Style_components, "f") ?? new Map(Object.entries(__classPrivateFieldGet(this, _Style_data, "f").components ?? {}).map(([name, data]) => [
50
+ name,
51
+ new Component(data),
52
+ ])), "f");
53
+ return __classPrivateFieldGet(this, _Style_components, "f");
54
+ }
55
+ colors() {
56
+ __classPrivateFieldSet(this, _Style_colors, __classPrivateFieldGet(this, _Style_colors, "f") ?? new Map(Object.entries(__classPrivateFieldGet(this, _Style_data, "f").colors ?? {}).map(([name, data]) => [
57
+ name,
58
+ new Color(data),
59
+ ])), "f");
60
+ return __classPrivateFieldGet(this, _Style_colors, "f");
61
+ }
62
+ }
63
+ _Style_data = new WeakMap(), _Style_meta = new WeakMap(), _Style_canvas = new WeakMap(), _Style_components = new WeakMap(), _Style_colors = new WeakMap();
@@ -0,0 +1,83 @@
1
+ export interface StyleDefinitionMetaLicense {
2
+ readonly name?: string;
3
+ readonly url?: string;
4
+ readonly text?: string;
5
+ }
6
+ export interface StyleDefinitionMetaCreator {
7
+ readonly name?: string;
8
+ readonly url?: string;
9
+ }
10
+ export interface StyleDefinitionMetaSource {
11
+ readonly name?: string;
12
+ readonly url?: string;
13
+ }
14
+ export interface StyleDefinitionMeta {
15
+ readonly license?: StyleDefinitionMetaLicense;
16
+ readonly creator?: StyleDefinitionMetaCreator;
17
+ readonly source?: StyleDefinitionMetaSource;
18
+ }
19
+ export interface StyleDefinitionVariableReference {
20
+ readonly type: 'variable';
21
+ readonly value: 'initial' | 'initials' | 'fontWeight' | 'fontFamily';
22
+ }
23
+ export interface StyleDefinitionColorReference {
24
+ readonly type: 'color';
25
+ readonly value: string;
26
+ }
27
+ export type StyleDefinitionColorAttributeValue = string | StyleDefinitionColorReference;
28
+ export type StyleDefinitionElementValue = string | StyleDefinitionVariableReference;
29
+ export type StyleDefinitionElementType = 'element' | 'text' | 'component';
30
+ export interface StyleDefinitionAttributes {
31
+ readonly color?: StyleDefinitionColorAttributeValue;
32
+ readonly 'flood-color'?: StyleDefinitionColorAttributeValue;
33
+ readonly 'lighting-color'?: StyleDefinitionColorAttributeValue;
34
+ readonly 'stop-color'?: StyleDefinitionColorAttributeValue;
35
+ readonly fill?: StyleDefinitionColorAttributeValue;
36
+ readonly stroke?: StyleDefinitionColorAttributeValue;
37
+ readonly 'font-family'?: string | StyleDefinitionVariableReference;
38
+ readonly 'font-weight'?: string | StyleDefinitionVariableReference;
39
+ readonly [key: string]: string | StyleDefinitionColorReference | StyleDefinitionVariableReference | undefined;
40
+ }
41
+ export interface StyleDefinitionElement {
42
+ readonly type: StyleDefinitionElementType;
43
+ readonly name?: string;
44
+ readonly value?: StyleDefinitionElementValue;
45
+ readonly attributes?: StyleDefinitionAttributes;
46
+ readonly children?: readonly StyleDefinitionElement[];
47
+ }
48
+ export interface StyleDefinitionCanvas {
49
+ readonly width: number;
50
+ readonly height: number;
51
+ readonly elements: readonly StyleDefinitionElement[];
52
+ }
53
+ export interface StyleDefinitionColor {
54
+ readonly values: readonly string[];
55
+ readonly notEqualTo?: readonly string[];
56
+ readonly contrastTo?: string;
57
+ }
58
+ export interface StyleDefinitionComponentTranslate {
59
+ readonly x?: readonly number[];
60
+ readonly y?: readonly number[];
61
+ }
62
+ export interface StyleDefinitionComponentVariant {
63
+ readonly elements: readonly StyleDefinitionElement[];
64
+ readonly weight?: number;
65
+ }
66
+ export interface StyleDefinitionComponent {
67
+ readonly width: number;
68
+ readonly height: number;
69
+ readonly probability?: number;
70
+ readonly rotate?: readonly number[];
71
+ readonly translate?: StyleDefinitionComponentTranslate;
72
+ readonly variants: Readonly<Record<string, StyleDefinitionComponentVariant>>;
73
+ }
74
+ export interface StyleDefinition {
75
+ readonly $id?: string;
76
+ readonly $schema?: string;
77
+ readonly $comment?: string;
78
+ readonly meta?: StyleDefinitionMeta;
79
+ readonly attributes?: StyleDefinitionAttributes;
80
+ readonly canvas: StyleDefinitionCanvas;
81
+ readonly components?: Readonly<Record<string, StyleDefinitionComponent>>;
82
+ readonly colors?: Readonly<Record<string, StyleDefinitionColor>>;
83
+ }
@@ -0,0 +1,54 @@
1
+ export type StyleOptionsFlipValue = 'none' | 'horizontal' | 'vertical' | 'both';
2
+ export type StyleOptionsColorFillValue = 'solid' | 'linear' | 'radial';
3
+ type ComponentNames<D> = D extends {
4
+ components: Record<infer K extends string, unknown>;
5
+ } ? string extends K ? never : K : never;
6
+ type ColorNames<D> = D extends {
7
+ colors: Record<infer K extends string, unknown>;
8
+ } ? string extends K ? never : K : never;
9
+ type AllColorNames<D> = ColorNames<D> | 'background';
10
+ type VariantNames<D, C extends string> = D extends {
11
+ components: Record<string, unknown>;
12
+ } ? C extends keyof D['components'] ? D['components'][C] extends {
13
+ variants: Record<infer V extends string, unknown>;
14
+ } ? string extends V ? string : V : string : string : string;
15
+ type HasSpecificKeys<D> = [ComponentNames<D>] extends [never] ? [ColorNames<D>] extends [never] ? false : true : true;
16
+ export interface StyleOptionsBase {
17
+ readonly seed?: string;
18
+ readonly size?: number;
19
+ readonly idRandomization?: boolean;
20
+ readonly title?: string;
21
+ readonly flip?: StyleOptionsFlipValue | readonly StyleOptionsFlipValue[];
22
+ readonly fontFamily?: string | readonly string[];
23
+ readonly fontWeight?: number | readonly number[];
24
+ readonly scale?: number | readonly [number, number];
25
+ readonly borderRadius?: number | readonly [number, number];
26
+ readonly rotate?: number | readonly [number, number];
27
+ readonly translateX?: number | readonly [number, number];
28
+ readonly translateY?: number | readonly [number, number];
29
+ }
30
+ type ComponentVariantOption<D, K extends string> = VariantNames<D, K> | readonly VariantNames<D, K>[] | Readonly<Partial<Record<VariantNames<D, K>, number>>>;
31
+ type ComponentOptions<D, C extends string> = [C] extends [never] ? unknown : {
32
+ readonly [K in C as `${K}Variant`]?: ComponentVariantOption<D, K>;
33
+ } & {
34
+ readonly [K in C as `${K}Probability`]?: number;
35
+ } & {
36
+ readonly [K in C as `${K}Rotate`]?: number | readonly [number, number];
37
+ } & {
38
+ readonly [K in C as `${K}TranslateX`]?: number | readonly [number, number];
39
+ } & {
40
+ readonly [K in C as `${K}TranslateY`]?: number | readonly [number, number];
41
+ };
42
+ type ColorOptions<C extends string> = [C] extends [never] ? unknown : {
43
+ readonly [K in C as `${K}Color`]?: string | readonly string[];
44
+ } & {
45
+ readonly [K in C as `${K}ColorFill`]?: StyleOptionsColorFillValue | readonly StyleOptionsColorFillValue[];
46
+ } & {
47
+ readonly [K in C as `${K}ColorFillStops`]?: number | readonly [number, number];
48
+ } & {
49
+ readonly [K in C as `${K}ColorAngle`]?: number | readonly [number, number];
50
+ };
51
+ export type StyleOptions<D = unknown> = StyleOptionsBase & ComponentOptions<D, ComponentNames<D>> & ColorOptions<AllColorNames<D>> & (HasSpecificKeys<D> extends true ? unknown : {
52
+ readonly [key: string]: unknown;
53
+ });
54
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,9 @@
1
+ export declare class Color {
2
+ #private;
3
+ static toHex(hex: string): string;
4
+ static toRgbHex(hex: string): string;
5
+ static parseHex(hex: string): [number, number, number];
6
+ static luminance(hex: string): number;
7
+ static sortByContrast(candidates: readonly string[], refColor: string): string[];
8
+ static filterNotEqualTo(candidates: readonly string[], excluded: readonly string[]): string[];
9
+ }
@@ -0,0 +1,67 @@
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, _Color_linearize;
7
+ export class Color {
8
+ // Normalizes any hex format to 6- or 8-digit lowercase with '#' prefix.
9
+ static toHex(hex) {
10
+ const h = hex.replace(/^#/, '').toLowerCase();
11
+ if (h.length === 3) {
12
+ return '#' + h[0] + h[0] + h[1] + h[1] + h[2] + h[2];
13
+ }
14
+ if (h.length === 4) {
15
+ return '#' + h[0] + h[0] + h[1] + h[1] + h[2] + h[2] + h[3] + h[3];
16
+ }
17
+ return '#' + h;
18
+ }
19
+ // Like toHex, but strips the alpha channel to always return 6-digit hex.
20
+ static toRgbHex(hex) {
21
+ const h = this.toHex(hex);
22
+ return h.length > 7 ? h.slice(0, 7) : h;
23
+ }
24
+ static parseHex(hex) {
25
+ const h = this.toHex(hex).slice(1);
26
+ return [
27
+ parseInt(h.slice(0, 2), 16),
28
+ parseInt(h.slice(2, 4), 16),
29
+ parseInt(h.slice(4, 6), 16),
30
+ ];
31
+ }
32
+ // WCAG 2.1 relative luminance with sRGB linearization.
33
+ // https://www.w3.org/WAI/GL/wiki/Relative_luminance
34
+ static luminance(hex) {
35
+ const rgb = this.parseHex(hex);
36
+ const linearR = __classPrivateFieldGet(this, _a, "m", _Color_linearize).call(this, rgb[0]);
37
+ const linearG = __classPrivateFieldGet(this, _a, "m", _Color_linearize).call(this, rgb[1]);
38
+ const linearB = __classPrivateFieldGet(this, _a, "m", _Color_linearize).call(this, rgb[2]);
39
+ return 0.2126 * linearR + 0.7152 * linearG + 0.0722 * linearB;
40
+ }
41
+ // Returns a new array sorted by descending contrast against the reference color.
42
+ // https://www.w3.org/WAI/GL/wiki/Contrast_ratio
43
+ static sortByContrast(candidates, refColor) {
44
+ const refLum = this.luminance(refColor);
45
+ const withRatio = candidates.map((c) => {
46
+ const lum = this.luminance(c);
47
+ const ratio = (Math.max(lum, refLum) + 0.05) / (Math.min(lum, refLum) + 0.05);
48
+ return { color: c, ratio };
49
+ });
50
+ withRatio.sort((a, b) => b.ratio - a.ratio);
51
+ return withRatio.map((e) => e.color);
52
+ }
53
+ // Returns a new array with excluded colors removed.
54
+ // Returns the original candidates if filtering would empty the list.
55
+ static filterNotEqualTo(candidates, excluded) {
56
+ const normalized = new Set(excluded.map((c) => this.toRgbHex(c)));
57
+ const filtered = candidates.filter((c) => !normalized.has(this.toRgbHex(c)));
58
+ return filtered.length > 0 ? filtered : Array.from(candidates);
59
+ }
60
+ }
61
+ _a = Color, _Color_linearize = function _Color_linearize(channel) {
62
+ const s = channel / 255;
63
+ if (s <= 0.04045) {
64
+ return s / 12.92;
65
+ }
66
+ return ((s + 0.055) / 1.055) ** 2.4;
67
+ };
@@ -0,0 +1,3 @@
1
+ export declare class Initials {
2
+ static fromSeed(seed: string, discardAtSymbol?: boolean): string;
3
+ }
@@ -0,0 +1,26 @@
1
+ // @see https://www.regular-expressions.info/unicode.html
2
+ export class Initials {
3
+ // Strips '@...' so email addresses yield a single initial instead
4
+ // of being treated as two words.
5
+ static fromSeed(seed, discardAtSymbol = true) {
6
+ let input = seed;
7
+ if (discardAtSymbol) {
8
+ input = seed.replace(/@.*/, '');
9
+ }
10
+ input = input.replace(/[`´'ʼ]/g, '');
11
+ const matches = input.match(/(\p{L}[\p{L}\p{M}]*)/gu);
12
+ if (!matches) {
13
+ return discardAtSymbol ? this.fromSeed(seed, false) : '';
14
+ }
15
+ if (matches.length === 1) {
16
+ const match = matches[0].match(/^(?:\p{L}\p{M}*){1,2}/u);
17
+ return match ? match[0].toUpperCase() : '';
18
+ }
19
+ const first = matches[0].match(/^(?:\p{L}\p{M}*)/u);
20
+ const last = matches[matches.length - 1].match(/^(?:\p{L}\p{M}*)/u);
21
+ if (!first || !last) {
22
+ return '';
23
+ }
24
+ return (first[0] + last[0]).toUpperCase();
25
+ }
26
+ }
@@ -0,0 +1,5 @@
1
+ import type { Meta } from '../Style/Meta.js';
2
+ export declare class License {
3
+ static text(meta: Meta): string;
4
+ static xml(meta: Meta): string;
5
+ }
@@ -0,0 +1,64 @@
1
+ import { Xml } from './Xml.js';
2
+ export class License {
3
+ static text(meta) {
4
+ const sourceName = meta.source().name();
5
+ const sourceUrl = meta.source().url();
6
+ const creatorName = meta.creator().name();
7
+ const licenseName = meta.license().name();
8
+ const licenseUrl = meta.license().url();
9
+ if (!sourceName && !creatorName && !licenseName) {
10
+ return '';
11
+ }
12
+ let title = sourceName ? `“${sourceName}”` : 'Design';
13
+ if (sourceUrl) {
14
+ title += ` (${sourceUrl})`;
15
+ }
16
+ const creator = `“${creatorName ?? 'Unknown'}”`;
17
+ let result = '';
18
+ // Skip "Remix of" prefix for MIT-licensed or DiceBear-original styles.
19
+ if (licenseName !== 'MIT' && creatorName !== 'DiceBear' && sourceName) {
20
+ result += 'Remix of ';
21
+ }
22
+ result += `${title} by ${creator}`;
23
+ if (licenseName) {
24
+ result += `, licensed under “${licenseName}”`;
25
+ if (licenseUrl) {
26
+ result += ` (${licenseUrl})`;
27
+ }
28
+ }
29
+ return result;
30
+ }
31
+ static xml(meta) {
32
+ const title = meta.source().name();
33
+ const creatorName = meta.creator().name();
34
+ const sourceUrl = meta.source().url();
35
+ const licenseUrl = meta.license().url();
36
+ const rights = this.text(meta);
37
+ if (!title && !creatorName && !sourceUrl && !licenseUrl && !rights) {
38
+ return '';
39
+ }
40
+ const fields = [];
41
+ if (title) {
42
+ fields.push(`<dc:title>${Xml.escape(title)}</dc:title>`);
43
+ }
44
+ if (creatorName) {
45
+ fields.push(`<dc:creator>${Xml.escape(creatorName)}</dc:creator>`);
46
+ }
47
+ if (sourceUrl) {
48
+ fields.push(`<dc:source xsi:type="dcterms:URI">${Xml.escape(sourceUrl)}</dc:source>`);
49
+ }
50
+ if (licenseUrl) {
51
+ fields.push(`<dcterms:license xsi:type="dcterms:URI">${Xml.escape(licenseUrl)}</dcterms:license>`);
52
+ }
53
+ if (rights) {
54
+ fields.push(`<dc:rights>${Xml.escape(rights)}</dc:rights>`);
55
+ }
56
+ return ('<metadata' +
57
+ ' xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"' +
58
+ ' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"' +
59
+ ' xmlns:dc="http://purl.org/dc/elements/1.1/"' +
60
+ ' xmlns:dcterms="http://purl.org/dc/terms/">' +
61
+ `<rdf:RDF><rdf:Description>${fields.join('')}</rdf:Description></rdf:RDF>` +
62
+ '</metadata>');
63
+ }
64
+ }
@@ -0,0 +1,4 @@
1
+ export declare class Xml {
2
+ #private;
3
+ static escape(value: string): string;
4
+ }
@@ -0,0 +1,20 @@
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, _Xml_entities, _Xml_pattern;
7
+ export class Xml {
8
+ static escape(value) {
9
+ return value.replace(__classPrivateFieldGet(_a, _a, "f", _Xml_pattern), (ch) => __classPrivateFieldGet(_a, _a, "f", _Xml_entities)[ch]);
10
+ }
11
+ }
12
+ _a = Xml;
13
+ _Xml_entities = { value: {
14
+ '&': '&amp;',
15
+ "'": '&apos;',
16
+ '"': '&quot;',
17
+ '<': '&lt;',
18
+ '>': '&gt;',
19
+ } };
20
+ _Xml_pattern = { value: new RegExp(`[${Object.keys(__classPrivateFieldGet(_a, _a, "f", _Xml_entities)).join('')}]`, 'g') };
@@ -0,0 +1,3 @@
1
+ export class OptionsValidator {
2
+ static validate(data: any): void;
3
+ }