@dicebear/core 10.0.0-rc.1 → 10.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.
Files changed (59) hide show
  1. package/lib/Avatar.d.ts +17 -1
  2. package/lib/Avatar.js +23 -5
  3. package/lib/Error/CircularColorReferenceError.d.ts +4 -0
  4. package/lib/Error/CircularColorReferenceError.js +4 -0
  5. package/lib/Error/OptionsValidationError.d.ts +3 -0
  6. package/lib/Error/OptionsValidationError.js +3 -0
  7. package/lib/Error/StyleValidationError.d.ts +3 -0
  8. package/lib/Error/StyleValidationError.js +3 -0
  9. package/lib/Error/ValidationError.d.ts +4 -0
  10. package/lib/Error/ValidationError.js +4 -0
  11. package/lib/Options.d.ts +39 -18
  12. package/lib/Options.js +64 -164
  13. package/lib/OptionsDescriptor.d.ts +8 -0
  14. package/lib/OptionsDescriptor.js +14 -6
  15. package/lib/Prng/Fnv1a.d.ts +14 -0
  16. package/lib/Prng/Fnv1a.js +14 -3
  17. package/lib/Prng/Mulberry32.d.ts +22 -0
  18. package/lib/Prng/Mulberry32.js +22 -8
  19. package/lib/Prng.d.ts +35 -0
  20. package/lib/Prng.js +35 -6
  21. package/lib/Renderer.d.ts +11 -2
  22. package/lib/Renderer.js +60 -54
  23. package/lib/Resolver.d.ts +62 -0
  24. package/lib/Resolver.js +203 -0
  25. package/lib/Style/Canvas.d.ts +14 -0
  26. package/lib/Style/Canvas.js +14 -0
  27. package/lib/Style/Color.d.ts +14 -0
  28. package/lib/Style/Color.js +14 -0
  29. package/lib/Style/Component.d.ts +50 -1
  30. package/lib/Style/Component.js +88 -9
  31. package/lib/Style/ComponentTranslate.d.ts +10 -0
  32. package/lib/Style/ComponentTranslate.js +10 -0
  33. package/lib/Style/ComponentVariant.d.ts +10 -0
  34. package/lib/Style/ComponentVariant.js +10 -0
  35. package/lib/Style/Element.d.ts +25 -0
  36. package/lib/Style/Element.js +25 -0
  37. package/lib/Style/Meta.d.ts +16 -0
  38. package/lib/Style/Meta.js +16 -0
  39. package/lib/Style/MetaCreator.d.ts +9 -0
  40. package/lib/Style/MetaCreator.js +9 -0
  41. package/lib/Style/MetaLicense.d.ts +12 -0
  42. package/lib/Style/MetaLicense.js +12 -0
  43. package/lib/Style/MetaSource.d.ts +10 -0
  44. package/lib/Style/MetaSource.js +10 -0
  45. package/lib/Style.d.ts +37 -1
  46. package/lib/Style.js +90 -6
  47. package/lib/StyleDefinition.d.ts +8 -3
  48. package/lib/StyleOptions.d.ts +12 -10
  49. package/lib/Utils/Color.d.ts +28 -0
  50. package/lib/Utils/Color.js +28 -8
  51. package/lib/Utils/Initials.d.ts +10 -0
  52. package/lib/Utils/Initials.js +10 -3
  53. package/lib/Utils/License.d.ts +14 -0
  54. package/lib/Utils/License.js +14 -0
  55. package/lib/Utils/Xml.d.ts +6 -0
  56. package/lib/Utils/Xml.js +6 -0
  57. package/lib/Validator/OptionsValidator.js +1569 -1700
  58. package/lib/Validator/StyleValidator.js +3453 -3197
  59. package/package.json +2 -2
@@ -0,0 +1,203 @@
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 _Resolver_instances, _Resolver_style, _Resolver_options, _Resolver_prng, _Resolver_colorResolving, _Resolver_result, _Resolver_probability, _Resolver_isVisible, _Resolver_resolveColor, _Resolver_colorFillStops, _Resolver_pickFloat, _Resolver_memo;
13
+ import { Prng } from './Prng.js';
14
+ import { Color } from './Utils/Color.js';
15
+ import { CircularColorReferenceError } from './Error/CircularColorReferenceError.js';
16
+ /**
17
+ * Bundles the three inputs needed to derive any deterministic value for an
18
+ * avatar — the {@link Style}, the validated user {@link Options}, and a
19
+ * seeded {@link Prng} — and exposes them as named accessors. Each accessor
20
+ * memoizes its result so that repeated calls cannot drift, and the memo
21
+ * doubles as the snapshot returned by {@link resolved}.
22
+ */
23
+ export class Resolver {
24
+ constructor(style, options) {
25
+ _Resolver_instances.add(this);
26
+ _Resolver_style.set(this, void 0);
27
+ _Resolver_options.set(this, void 0);
28
+ _Resolver_prng.set(this, void 0);
29
+ _Resolver_colorResolving.set(this, []);
30
+ _Resolver_result.set(this, {});
31
+ __classPrivateFieldSet(this, _Resolver_style, style, "f");
32
+ __classPrivateFieldSet(this, _Resolver_options, options, "f");
33
+ __classPrivateFieldSet(this, _Resolver_prng, new Prng(this.seed()), "f");
34
+ }
35
+ seed() {
36
+ return __classPrivateFieldGet(this, _Resolver_instances, "m", _Resolver_memo).call(this, 'seed', () => __classPrivateFieldGet(this, _Resolver_options, "f").seed() ?? '');
37
+ }
38
+ size() {
39
+ return __classPrivateFieldGet(this, _Resolver_instances, "m", _Resolver_memo).call(this, 'size', () => __classPrivateFieldGet(this, _Resolver_options, "f").size());
40
+ }
41
+ idRandomization() {
42
+ return __classPrivateFieldGet(this, _Resolver_instances, "m", _Resolver_memo).call(this, 'idRandomization', () => __classPrivateFieldGet(this, _Resolver_options, "f").idRandomization() ?? false);
43
+ }
44
+ title() {
45
+ return __classPrivateFieldGet(this, _Resolver_instances, "m", _Resolver_memo).call(this, 'title', () => __classPrivateFieldGet(this, _Resolver_options, "f").title());
46
+ }
47
+ flip() {
48
+ return __classPrivateFieldGet(this, _Resolver_instances, "m", _Resolver_memo).call(this, 'flip', () => __classPrivateFieldGet(this, _Resolver_prng, "f").pick('flip', __classPrivateFieldGet(this, _Resolver_options, "f").flip()) ?? 'none');
49
+ }
50
+ fontFamily() {
51
+ return __classPrivateFieldGet(this, _Resolver_instances, "m", _Resolver_memo).call(this, 'fontFamily', () => __classPrivateFieldGet(this, _Resolver_prng, "f").pick('fontFamily', __classPrivateFieldGet(this, _Resolver_options, "f").fontFamily()) ?? 'system-ui');
52
+ }
53
+ fontWeight() {
54
+ return __classPrivateFieldGet(this, _Resolver_instances, "m", _Resolver_memo).call(this, 'fontWeight', () => __classPrivateFieldGet(this, _Resolver_prng, "f").pick('fontWeight', __classPrivateFieldGet(this, _Resolver_options, "f").fontWeight()) ?? 400);
55
+ }
56
+ scale() {
57
+ return __classPrivateFieldGet(this, _Resolver_instances, "m", _Resolver_memo).call(this, 'scale', () => __classPrivateFieldGet(this, _Resolver_prng, "f").float('scale', __classPrivateFieldGet(this, _Resolver_options, "f").scale()) ?? 1);
58
+ }
59
+ borderRadius() {
60
+ return __classPrivateFieldGet(this, _Resolver_instances, "m", _Resolver_memo).call(this, 'borderRadius', () => __classPrivateFieldGet(this, _Resolver_prng, "f").float('borderRadius', __classPrivateFieldGet(this, _Resolver_options, "f").borderRadius()) ?? 0);
61
+ }
62
+ rotate() {
63
+ return __classPrivateFieldGet(this, _Resolver_instances, "m", _Resolver_memo).call(this, 'rotate', () => __classPrivateFieldGet(this, _Resolver_prng, "f").float('rotate', __classPrivateFieldGet(this, _Resolver_options, "f").rotate()) ?? 0);
64
+ }
65
+ translateX() {
66
+ return __classPrivateFieldGet(this, _Resolver_instances, "m", _Resolver_memo).call(this, 'translateX', () => __classPrivateFieldGet(this, _Resolver_prng, "f").float('translateX', __classPrivateFieldGet(this, _Resolver_options, "f").translateX()) ?? 0);
67
+ }
68
+ translateY() {
69
+ return __classPrivateFieldGet(this, _Resolver_instances, "m", _Resolver_memo).call(this, 'translateY', () => __classPrivateFieldGet(this, _Resolver_prng, "f").float('translateY', __classPrivateFieldGet(this, _Resolver_options, "f").translateY()) ?? 0);
70
+ }
71
+ /**
72
+ * Selects a variant for the given component. Depending on what was passed
73
+ * as `${name}Variant` in the input data:
74
+ *
75
+ * - `undefined`: PRNG picks from all style variants using their weights.
76
+ * - `string` or `string[]`: PRNG picks from the given subset (weight 1 each).
77
+ * - `Record<string, number>`: PRNG picks using the provided weights.
78
+ *
79
+ * Only variants that exist in the style definition are considered.
80
+ */
81
+ variant(name) {
82
+ return __classPrivateFieldGet(this, _Resolver_instances, "m", _Resolver_memo).call(this, `${name}Variant`, () => {
83
+ const component = __classPrivateFieldGet(this, _Resolver_style, "f").components().get(name);
84
+ if (!component || !__classPrivateFieldGet(this, _Resolver_instances, "m", _Resolver_isVisible).call(this, name, component)) {
85
+ return undefined;
86
+ }
87
+ const raw = __classPrivateFieldGet(this, _Resolver_options, "f").componentVariant(component.sourceName());
88
+ const variants = component.variants();
89
+ let entries;
90
+ if (raw === undefined) {
91
+ entries = Array.from(variants).map(([v, variant]) => [
92
+ v,
93
+ variant.weight(),
94
+ ]);
95
+ }
96
+ else if (Array.isArray(raw)) {
97
+ entries = raw
98
+ .filter((v) => variants.has(v))
99
+ .map((v) => [v, 1]);
100
+ }
101
+ else {
102
+ entries = Object.entries(raw).filter(([v]) => variants.has(v));
103
+ }
104
+ return __classPrivateFieldGet(this, _Resolver_prng, "f").weightedPick(`${name}Variant`, entries);
105
+ });
106
+ }
107
+ color(name) {
108
+ return __classPrivateFieldGet(this, _Resolver_instances, "m", _Resolver_memo).call(this, `${name}Color`, () => __classPrivateFieldGet(this, _Resolver_instances, "m", _Resolver_resolveColor).call(this, name));
109
+ }
110
+ colorFill(name) {
111
+ return __classPrivateFieldGet(this, _Resolver_instances, "m", _Resolver_memo).call(this, `${name}ColorFill`, () => __classPrivateFieldGet(this, _Resolver_prng, "f").pick(`${name}ColorFill`, __classPrivateFieldGet(this, _Resolver_options, "f").colorFill(name)) ??
112
+ 'solid');
113
+ }
114
+ colorAngle(name) {
115
+ return __classPrivateFieldGet(this, _Resolver_instances, "m", _Resolver_memo).call(this, `${name}ColorAngle`, () => __classPrivateFieldGet(this, _Resolver_prng, "f").float(`${name}ColorAngle`, __classPrivateFieldGet(this, _Resolver_options, "f").colorAngle(name)) ?? 0);
116
+ }
117
+ /**
118
+ * Per-component transform values are render-time decorations derived per
119
+ * `<use>` reference, not user-input options that should round-trip. They
120
+ * are intentionally not memoized and so never appear in {@link resolved}.
121
+ */
122
+ componentTransform(name) {
123
+ const component = __classPrivateFieldGet(this, _Resolver_style, "f").components().get(name);
124
+ return {
125
+ rotate: __classPrivateFieldGet(this, _Resolver_instances, "m", _Resolver_pickFloat).call(this, name, 'Rotate', component?.rotate() ?? [], 0),
126
+ translateX: __classPrivateFieldGet(this, _Resolver_instances, "m", _Resolver_pickFloat).call(this, name, 'TranslateX', component?.translate().x() ?? [], 0),
127
+ translateY: __classPrivateFieldGet(this, _Resolver_instances, "m", _Resolver_pickFloat).call(this, name, 'TranslateY', component?.translate().y() ?? [], 0),
128
+ scale: __classPrivateFieldGet(this, _Resolver_instances, "m", _Resolver_pickFloat).call(this, name, 'Scale', component?.scale() ?? [], 1),
129
+ };
130
+ }
131
+ /**
132
+ * Returns every value that has been touched during this resolution. Only
133
+ * memoized entries are included; unset options remain `undefined` and
134
+ * disappear on `JSON.stringify()`. Per-component transform values from
135
+ * {@link componentTransform} are intentionally not memoized and therefore
136
+ * do not appear in the snapshot.
137
+ *
138
+ * The returned object aliases the internal cache; callers that need
139
+ * isolation (e.g. {@link Avatar.toJSON}) clone it themselves.
140
+ */
141
+ resolved() {
142
+ return __classPrivateFieldGet(this, _Resolver_result, "f");
143
+ }
144
+ }
145
+ _Resolver_style = new WeakMap(), _Resolver_options = new WeakMap(), _Resolver_prng = new WeakMap(), _Resolver_colorResolving = new WeakMap(), _Resolver_result = new WeakMap(), _Resolver_instances = new WeakSet(), _Resolver_probability = function _Resolver_probability(component) {
146
+ const raw = __classPrivateFieldGet(this, _Resolver_options, "f").componentProbability(component.sourceName());
147
+ return raw ?? component.probability();
148
+ }, _Resolver_isVisible = function _Resolver_isVisible(name, component) {
149
+ return __classPrivateFieldGet(this, _Resolver_prng, "f").bool(`${name}Probability`, __classPrivateFieldGet(this, _Resolver_instances, "m", _Resolver_probability).call(this, component));
150
+ }, _Resolver_resolveColor = function _Resolver_resolveColor(name) {
151
+ const userColors = __classPrivateFieldGet(this, _Resolver_options, "f").color(name);
152
+ const styleColor = __classPrivateFieldGet(this, _Resolver_style, "f").colors().get(name);
153
+ const source = userColors ?? styleColor?.values() ?? [];
154
+ let candidates = source.map((c) => Color.toHex(c));
155
+ const fill = this.colorFill(name);
156
+ const stops = fill === 'solid' ? 1 : __classPrivateFieldGet(this, _Resolver_instances, "m", _Resolver_colorFillStops).call(this, name);
157
+ if (!styleColor) {
158
+ return __classPrivateFieldGet(this, _Resolver_prng, "f").shuffle(`${name}Color`, candidates).slice(0, stops);
159
+ }
160
+ // Detect circular references (e.g. a.contrastTo = b, b.contrastTo = a)
161
+ if (__classPrivateFieldGet(this, _Resolver_colorResolving, "f").includes(name)) {
162
+ throw new CircularColorReferenceError(__classPrivateFieldGet(this, _Resolver_colorResolving, "f").concat(name));
163
+ }
164
+ __classPrivateFieldGet(this, _Resolver_colorResolving, "f").push(name);
165
+ const contrastTo = styleColor.contrastTo();
166
+ const notEqualTo = styleColor.notEqualTo();
167
+ try {
168
+ if (contrastTo) {
169
+ const refColor = this.color(contrastTo)[0];
170
+ if (refColor) {
171
+ candidates = Color.sortByContrast(candidates, refColor);
172
+ }
173
+ }
174
+ if (notEqualTo.length > 0) {
175
+ const excluded = [];
176
+ for (const ref of notEqualTo) {
177
+ for (const color of this.color(ref)) {
178
+ excluded.push(color);
179
+ }
180
+ }
181
+ candidates = Color.filterNotEqualTo(candidates, excluded);
182
+ }
183
+ }
184
+ finally {
185
+ __classPrivateFieldGet(this, _Resolver_colorResolving, "f").pop();
186
+ }
187
+ // Skip shuffle when sorted by contrast to preserve the ordering
188
+ const ordered = contrastTo
189
+ ? candidates
190
+ : __classPrivateFieldGet(this, _Resolver_prng, "f").shuffle(`${name}Color`, candidates);
191
+ return ordered.slice(0, stops);
192
+ }, _Resolver_colorFillStops = function _Resolver_colorFillStops(name) {
193
+ return (__classPrivateFieldGet(this, _Resolver_prng, "f").integer(`${name}ColorFillStops`, __classPrivateFieldGet(this, _Resolver_options, "f").colorFillStops(name)) ?? 2);
194
+ }, _Resolver_pickFloat = function _Resolver_pickFloat(name, suffix, range, fallback) {
195
+ return __classPrivateFieldGet(this, _Resolver_prng, "f").float(`${name}${suffix}`, range) ?? fallback;
196
+ }, _Resolver_memo = function _Resolver_memo(key, compute) {
197
+ if (key in __classPrivateFieldGet(this, _Resolver_result, "f")) {
198
+ return __classPrivateFieldGet(this, _Resolver_result, "f")[key];
199
+ }
200
+ const value = compute();
201
+ __classPrivateFieldGet(this, _Resolver_result, "f")[key] = value;
202
+ return value;
203
+ };
@@ -1,9 +1,23 @@
1
1
  import type { StyleDefinitionCanvas } from '../StyleDefinition.js';
2
2
  import { Element } from './Element.js';
3
+ /**
4
+ * Read-only view over a style definition's `canvas` block, exposing the
5
+ * drawing area dimensions and the top-level element list.
6
+ */
3
7
  export declare class Canvas {
4
8
  #private;
5
9
  constructor(data: StyleDefinitionCanvas);
10
+ /**
11
+ * Returns the canvas width — the `width` value of the SVG `viewBox`.
12
+ */
6
13
  width(): number;
14
+ /**
15
+ * Returns the canvas height — the `height` value of the SVG `viewBox`.
16
+ */
7
17
  height(): number;
18
+ /**
19
+ * Returns the top-level elements rendered onto the canvas, lazily wrapped
20
+ * as {@link Element} instances on first access.
21
+ */
8
22
  elements(): readonly Element[];
9
23
  }
@@ -11,18 +11,32 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
11
11
  };
12
12
  var _Canvas_data, _Canvas_elements;
13
13
  import { Element } from './Element.js';
14
+ /**
15
+ * Read-only view over a style definition's `canvas` block, exposing the
16
+ * drawing area dimensions and the top-level element list.
17
+ */
14
18
  export class Canvas {
15
19
  constructor(data) {
16
20
  _Canvas_data.set(this, void 0);
17
21
  _Canvas_elements.set(this, void 0);
18
22
  __classPrivateFieldSet(this, _Canvas_data, data, "f");
19
23
  }
24
+ /**
25
+ * Returns the canvas width — the `width` value of the SVG `viewBox`.
26
+ */
20
27
  width() {
21
28
  return __classPrivateFieldGet(this, _Canvas_data, "f").width;
22
29
  }
30
+ /**
31
+ * Returns the canvas height — the `height` value of the SVG `viewBox`.
32
+ */
23
33
  height() {
24
34
  return __classPrivateFieldGet(this, _Canvas_data, "f").height;
25
35
  }
36
+ /**
37
+ * Returns the top-level elements rendered onto the canvas, lazily wrapped
38
+ * as {@link Element} instances on first access.
39
+ */
26
40
  elements() {
27
41
  __classPrivateFieldSet(this, _Canvas_elements, __classPrivateFieldGet(this, _Canvas_elements, "f") ?? __classPrivateFieldGet(this, _Canvas_data, "f").elements.map((el) => new Element(el)), "f");
28
42
  return __classPrivateFieldGet(this, _Canvas_elements, "f");
@@ -1,8 +1,22 @@
1
1
  import type { StyleDefinitionColor } from '../StyleDefinition.js';
2
+ /**
3
+ * Read-only view over an entry in a style definition's `colors` block.
4
+ */
2
5
  export declare class Color {
3
6
  #private;
4
7
  constructor(data: StyleDefinitionColor);
8
+ /**
9
+ * Returns the candidate color values, in definition order.
10
+ */
5
11
  values(): readonly string[];
12
+ /**
13
+ * Returns the colors that the resolver should avoid picking, or an empty
14
+ * list when the field is unset.
15
+ */
6
16
  notEqualTo(): readonly string[];
17
+ /**
18
+ * Returns the name of another color that this one should contrast against,
19
+ * or `undefined` when no contrast constraint is defined.
20
+ */
7
21
  contrastTo(): string | undefined;
8
22
  }
@@ -10,17 +10,31 @@ 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 _Color_data;
13
+ /**
14
+ * Read-only view over an entry in a style definition's `colors` block.
15
+ */
13
16
  export class Color {
14
17
  constructor(data) {
15
18
  _Color_data.set(this, void 0);
16
19
  __classPrivateFieldSet(this, _Color_data, data, "f");
17
20
  }
21
+ /**
22
+ * Returns the candidate color values, in definition order.
23
+ */
18
24
  values() {
19
25
  return __classPrivateFieldGet(this, _Color_data, "f").values;
20
26
  }
27
+ /**
28
+ * Returns the colors that the resolver should avoid picking, or an empty
29
+ * list when the field is unset.
30
+ */
21
31
  notEqualTo() {
22
32
  return __classPrivateFieldGet(this, _Color_data, "f").notEqualTo ?? [];
23
33
  }
34
+ /**
35
+ * Returns the name of another color that this one should contrast against,
36
+ * or `undefined` when no contrast constraint is defined.
37
+ */
24
38
  contrastTo() {
25
39
  return __classPrivateFieldGet(this, _Color_data, "f").contrastTo;
26
40
  }
@@ -1,13 +1,62 @@
1
1
  import type { StyleDefinitionComponent } from '../StyleDefinition.js';
2
2
  import { ComponentTranslate } from './ComponentTranslate.js';
3
3
  import { ComponentVariant } from './ComponentVariant.js';
4
+ /**
5
+ * Read-only view over an entry in a style definition's `components` block.
6
+ *
7
+ * An entry is either a base component with its own dimensions and variants
8
+ * or an alias declared via `extends`. Aliases are pure references — they
9
+ * inherit dimensions, variants, and all transforms from the source.
10
+ */
4
11
  export declare class Component {
5
12
  #private;
6
- constructor(data: StyleDefinitionComponent);
13
+ constructor(name: string, data: StyleDefinitionComponent, source?: Component);
14
+ /**
15
+ * Returns the entry's own name as declared in the style definition. For
16
+ * aliases this is the alias key, not the source component's name (use
17
+ * {@link sourceName} for the canonical user-option key prefix).
18
+ */
19
+ name(): string;
20
+ /**
21
+ * Returns the source component name when this entry is an alias, or
22
+ * `undefined` for a base component.
23
+ */
24
+ extendsName(): string | undefined;
25
+ /**
26
+ * Returns the canonical user-option key prefix: the source component's
27
+ * name when this entry is an alias, otherwise the entry's own name.
28
+ */
29
+ sourceName(): string;
30
+ /**
31
+ * Returns the component's intrinsic width in canvas coordinates. For
32
+ * aliases the source component's width is returned.
33
+ */
7
34
  width(): number;
35
+ /**
36
+ * Returns the component's intrinsic height in canvas coordinates. For
37
+ * aliases the source component's height is returned.
38
+ */
8
39
  height(): number;
40
+ /**
41
+ * Returns the probability (0–100) that this component is rendered.
42
+ * Aliases delegate to the source; defaults to 100 (always visible).
43
+ */
9
44
  probability(): number;
45
+ /**
46
+ * Returns the rotation range definition. Aliases delegate to the source.
47
+ */
10
48
  rotate(): readonly number[];
49
+ /**
50
+ * Returns the scale range definition. Aliases delegate to the source.
51
+ */
52
+ scale(): readonly number[];
53
+ /**
54
+ * Returns the translate descriptor. Aliases delegate to the source.
55
+ */
11
56
  translate(): ComponentTranslate;
57
+ /**
58
+ * Returns a name → {@link ComponentVariant} map for all defined variants.
59
+ * Aliases delegate to the source component's variants.
60
+ */
12
61
  variants(): ReadonlyMap<string, ComponentVariant>;
13
62
  }
@@ -9,38 +9,117 @@ 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 _Component_data, _Component_translate, _Component_variants;
12
+ var _Component_instances, _Component_data, _Component_name, _Component_source, _Component_translate, _Component_variants, _Component_asBase;
13
13
  import { ComponentTranslate } from './ComponentTranslate.js';
14
14
  import { ComponentVariant } from './ComponentVariant.js';
15
+ /**
16
+ * Read-only view over an entry in a style definition's `components` block.
17
+ *
18
+ * An entry is either a base component with its own dimensions and variants
19
+ * or an alias declared via `extends`. Aliases are pure references — they
20
+ * inherit dimensions, variants, and all transforms from the source.
21
+ */
15
22
  export class Component {
16
- constructor(data) {
23
+ constructor(name, data, source) {
24
+ _Component_instances.add(this);
17
25
  _Component_data.set(this, void 0);
26
+ _Component_name.set(this, void 0);
27
+ _Component_source.set(this, void 0);
18
28
  _Component_translate.set(this, void 0);
19
29
  _Component_variants.set(this, void 0);
20
30
  __classPrivateFieldSet(this, _Component_data, data, "f");
31
+ __classPrivateFieldSet(this, _Component_name, name, "f");
32
+ __classPrivateFieldSet(this, _Component_source, source, "f");
21
33
  }
34
+ /**
35
+ * Returns the entry's own name as declared in the style definition. For
36
+ * aliases this is the alias key, not the source component's name (use
37
+ * {@link sourceName} for the canonical user-option key prefix).
38
+ */
39
+ name() {
40
+ return __classPrivateFieldGet(this, _Component_name, "f");
41
+ }
42
+ /**
43
+ * Returns the source component name when this entry is an alias, or
44
+ * `undefined` for a base component.
45
+ */
46
+ extendsName() {
47
+ return 'extends' in __classPrivateFieldGet(this, _Component_data, "f") ? __classPrivateFieldGet(this, _Component_data, "f").extends : undefined;
48
+ }
49
+ /**
50
+ * Returns the canonical user-option key prefix: the source component's
51
+ * name when this entry is an alias, otherwise the entry's own name.
52
+ */
53
+ sourceName() {
54
+ return this.extendsName() ?? __classPrivateFieldGet(this, _Component_name, "f");
55
+ }
56
+ /**
57
+ * Returns the component's intrinsic width in canvas coordinates. For
58
+ * aliases the source component's width is returned.
59
+ */
22
60
  width() {
23
- return __classPrivateFieldGet(this, _Component_data, "f").width;
61
+ return __classPrivateFieldGet(this, _Component_source, "f") ? __classPrivateFieldGet(this, _Component_source, "f").width() : __classPrivateFieldGet(this, _Component_instances, "m", _Component_asBase).call(this).width;
24
62
  }
63
+ /**
64
+ * Returns the component's intrinsic height in canvas coordinates. For
65
+ * aliases the source component's height is returned.
66
+ */
25
67
  height() {
26
- return __classPrivateFieldGet(this, _Component_data, "f").height;
68
+ return __classPrivateFieldGet(this, _Component_source, "f") ? __classPrivateFieldGet(this, _Component_source, "f").height() : __classPrivateFieldGet(this, _Component_instances, "m", _Component_asBase).call(this).height;
27
69
  }
70
+ /**
71
+ * Returns the probability (0–100) that this component is rendered.
72
+ * Aliases delegate to the source; defaults to 100 (always visible).
73
+ */
28
74
  probability() {
29
- return __classPrivateFieldGet(this, _Component_data, "f").probability ?? 100;
75
+ if (__classPrivateFieldGet(this, _Component_source, "f")) {
76
+ return __classPrivateFieldGet(this, _Component_source, "f").probability();
77
+ }
78
+ return __classPrivateFieldGet(this, _Component_instances, "m", _Component_asBase).call(this).probability ?? 100;
30
79
  }
80
+ /**
81
+ * Returns the rotation range definition. Aliases delegate to the source.
82
+ */
31
83
  rotate() {
32
- return __classPrivateFieldGet(this, _Component_data, "f").rotate ?? [];
84
+ if (__classPrivateFieldGet(this, _Component_source, "f")) {
85
+ return __classPrivateFieldGet(this, _Component_source, "f").rotate();
86
+ }
87
+ return __classPrivateFieldGet(this, _Component_instances, "m", _Component_asBase).call(this).rotate ?? [];
33
88
  }
89
+ /**
90
+ * Returns the scale range definition. Aliases delegate to the source.
91
+ */
92
+ scale() {
93
+ if (__classPrivateFieldGet(this, _Component_source, "f")) {
94
+ return __classPrivateFieldGet(this, _Component_source, "f").scale();
95
+ }
96
+ return __classPrivateFieldGet(this, _Component_instances, "m", _Component_asBase).call(this).scale ?? [];
97
+ }
98
+ /**
99
+ * Returns the translate descriptor. Aliases delegate to the source.
100
+ */
34
101
  translate() {
35
- __classPrivateFieldSet(this, _Component_translate, __classPrivateFieldGet(this, _Component_translate, "f") ?? new ComponentTranslate(__classPrivateFieldGet(this, _Component_data, "f").translate ?? {}), "f");
102
+ if (__classPrivateFieldGet(this, _Component_source, "f")) {
103
+ return __classPrivateFieldGet(this, _Component_source, "f").translate();
104
+ }
105
+ __classPrivateFieldSet(this, _Component_translate, __classPrivateFieldGet(this, _Component_translate, "f") ?? new ComponentTranslate(__classPrivateFieldGet(this, _Component_instances, "m", _Component_asBase).call(this).translate ?? {}), "f");
36
106
  return __classPrivateFieldGet(this, _Component_translate, "f");
37
107
  }
108
+ /**
109
+ * Returns a name → {@link ComponentVariant} map for all defined variants.
110
+ * Aliases delegate to the source component's variants.
111
+ */
38
112
  variants() {
39
- __classPrivateFieldSet(this, _Component_variants, __classPrivateFieldGet(this, _Component_variants, "f") ?? new Map(Object.entries(__classPrivateFieldGet(this, _Component_data, "f").variants).map(([name, data]) => [
113
+ if (__classPrivateFieldGet(this, _Component_source, "f")) {
114
+ return __classPrivateFieldGet(this, _Component_source, "f").variants();
115
+ }
116
+ __classPrivateFieldSet(this, _Component_variants, __classPrivateFieldGet(this, _Component_variants, "f") ?? new Map(Object.entries(__classPrivateFieldGet(this, _Component_instances, "m", _Component_asBase).call(this).variants).map(([name, data]) => [
40
117
  name,
41
118
  new ComponentVariant(data),
42
119
  ])), "f");
43
120
  return __classPrivateFieldGet(this, _Component_variants, "f");
44
121
  }
45
122
  }
46
- _Component_data = new WeakMap(), _Component_translate = new WeakMap(), _Component_variants = new WeakMap();
123
+ _Component_data = new WeakMap(), _Component_name = new WeakMap(), _Component_source = new WeakMap(), _Component_translate = new WeakMap(), _Component_variants = new WeakMap(), _Component_instances = new WeakSet(), _Component_asBase = function _Component_asBase() {
124
+ return __classPrivateFieldGet(this, _Component_data, "f");
125
+ };
@@ -1,7 +1,17 @@
1
1
  import type { StyleDefinitionComponentTranslate } from '../StyleDefinition.js';
2
+ /**
3
+ * Read-only view over a component's `translate` block, providing the X and Y
4
+ * offset ranges.
5
+ */
2
6
  export declare class ComponentTranslate {
3
7
  #private;
4
8
  constructor(data: StyleDefinitionComponentTranslate);
9
+ /**
10
+ * Returns the horizontal offset range, or an empty list when unset.
11
+ */
5
12
  x(): readonly number[];
13
+ /**
14
+ * Returns the vertical offset range, or an empty list when unset.
15
+ */
6
16
  y(): readonly number[];
7
17
  }
@@ -10,14 +10,24 @@ 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 _ComponentTranslate_data;
13
+ /**
14
+ * Read-only view over a component's `translate` block, providing the X and Y
15
+ * offset ranges.
16
+ */
13
17
  export class ComponentTranslate {
14
18
  constructor(data) {
15
19
  _ComponentTranslate_data.set(this, void 0);
16
20
  __classPrivateFieldSet(this, _ComponentTranslate_data, data, "f");
17
21
  }
22
+ /**
23
+ * Returns the horizontal offset range, or an empty list when unset.
24
+ */
18
25
  x() {
19
26
  return __classPrivateFieldGet(this, _ComponentTranslate_data, "f").x ?? [];
20
27
  }
28
+ /**
29
+ * Returns the vertical offset range, or an empty list when unset.
30
+ */
21
31
  y() {
22
32
  return __classPrivateFieldGet(this, _ComponentTranslate_data, "f").y ?? [];
23
33
  }
@@ -1,8 +1,18 @@
1
1
  import type { StyleDefinitionComponentVariant } from '../StyleDefinition.js';
2
2
  import { Element } from './Element.js';
3
+ /**
4
+ * Read-only view over an entry in a component's `variants` block.
5
+ */
3
6
  export declare class ComponentVariant {
4
7
  #private;
5
8
  constructor(data: StyleDefinitionComponentVariant);
9
+ /**
10
+ * Returns the variant's elements, lazily wrapped as {@link Element}
11
+ * instances on first access.
12
+ */
6
13
  elements(): readonly Element[];
14
+ /**
15
+ * Returns the weighted-pick weight for this variant, defaulting to `1`.
16
+ */
7
17
  weight(): number;
8
18
  }
@@ -11,16 +11,26 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
11
11
  };
12
12
  var _ComponentVariant_data, _ComponentVariant_elements;
13
13
  import { Element } from './Element.js';
14
+ /**
15
+ * Read-only view over an entry in a component's `variants` block.
16
+ */
14
17
  export class ComponentVariant {
15
18
  constructor(data) {
16
19
  _ComponentVariant_data.set(this, void 0);
17
20
  _ComponentVariant_elements.set(this, void 0);
18
21
  __classPrivateFieldSet(this, _ComponentVariant_data, data, "f");
19
22
  }
23
+ /**
24
+ * Returns the variant's elements, lazily wrapped as {@link Element}
25
+ * instances on first access.
26
+ */
20
27
  elements() {
21
28
  __classPrivateFieldSet(this, _ComponentVariant_elements, __classPrivateFieldGet(this, _ComponentVariant_elements, "f") ?? __classPrivateFieldGet(this, _ComponentVariant_data, "f").elements.map((el) => new Element(el)), "f");
22
29
  return __classPrivateFieldGet(this, _ComponentVariant_elements, "f");
23
30
  }
31
+ /**
32
+ * Returns the weighted-pick weight for this variant, defaulting to `1`.
33
+ */
24
34
  weight() {
25
35
  return __classPrivateFieldGet(this, _ComponentVariant_data, "f").weight ?? 1;
26
36
  }
@@ -1,10 +1,35 @@
1
1
  import type { StyleDefinitionElement, StyleDefinitionElementValue, StyleDefinitionElementType, StyleDefinitionAttributes } from '../StyleDefinition.js';
2
+ /**
3
+ * Read-only view over a single render-tree element from a style definition.
4
+ *
5
+ * The same node type covers SVG elements, text, and component references —
6
+ * `type()` discriminates between them.
7
+ */
2
8
  export declare class Element {
3
9
  #private;
4
10
  constructor(data: StyleDefinitionElement);
11
+ /**
12
+ * Returns the element type discriminator (`svg`, `text`, `component`, …).
13
+ */
5
14
  type(): StyleDefinitionElementType;
15
+ /**
16
+ * Returns the element's tag/component name, or `undefined` for elements
17
+ * that don't have one.
18
+ */
6
19
  name(): string | undefined;
20
+ /**
21
+ * Returns the element's textual value (for `text` elements) or template
22
+ * fragment, or `undefined` when not applicable.
23
+ */
7
24
  value(): StyleDefinitionElementValue | undefined;
25
+ /**
26
+ * Returns the element's raw attribute map, or `undefined` when no
27
+ * attributes are defined.
28
+ */
8
29
  attributes(): StyleDefinitionAttributes | undefined;
30
+ /**
31
+ * Returns the element's children, lazily wrapped as {@link Element}
32
+ * instances on first access.
33
+ */
9
34
  children(): readonly Element[];
10
35
  }