@dicebear/core 10.3.2 → 10.4.0-rc.2
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 +10 -1
- package/lib/Options.js +21 -2
- package/lib/OptionsDescriptor.d.ts +1 -0
- package/lib/OptionsDescriptor.js +22 -2
- package/lib/Renderer.js +2 -2
- package/lib/Resolver.d.ts +4 -9
- package/lib/Resolver.js +81 -27
- package/lib/Style/ComponentVariant.d.ts +14 -0
- package/lib/Style/ComponentVariant.js +21 -0
- package/lib/StyleDefinition.d.ts +1 -0
- package/lib/StyleOptions.d.ts +11 -0
- package/package.json +2 -2
package/lib/Options.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Range } from './StyleDefinition.js';
|
|
2
|
-
import type { StyleOptions, StyleOptionsFlipValue, StyleOptionsColorFillValue } from './StyleOptions.js';
|
|
2
|
+
import type { StyleOptions, StyleOptionsFlipValue, StyleOptionsColorFillValue, TagFilterToken } from './StyleOptions.js';
|
|
3
3
|
/**
|
|
4
4
|
* Validates the raw user-supplied options and exposes them through typed
|
|
5
5
|
* accessors. Each accessor returns the user's input in a normalized form
|
|
@@ -25,6 +25,15 @@ export declare class Options<D = unknown> {
|
|
|
25
25
|
rotate(): Range | undefined;
|
|
26
26
|
translateX(): Range | undefined;
|
|
27
27
|
translateY(): Range | undefined;
|
|
28
|
+
/**
|
|
29
|
+
* Returns the global `tags` filter as parsed tokens, or an empty array when
|
|
30
|
+
* unset. Each raw token (`category` / `category:value`, optionally
|
|
31
|
+
* `!`-prefixed to disallow) is decoded into `{ category, value?, negated }` so
|
|
32
|
+
* the resolver composes the filter without parsing the grammar itself. An
|
|
33
|
+
* empty list means no tag filtering (classic behavior). Memoized, since the
|
|
34
|
+
* resolver reads it once per component.
|
|
35
|
+
*/
|
|
36
|
+
tags(): readonly TagFilterToken[];
|
|
28
37
|
/**
|
|
29
38
|
* Returns the user-set variant constraint for `name` as a weighted map, or
|
|
30
39
|
* `undefined` when `${name}Variant` is unset. A bare string or string list
|
package/lib/Options.js
CHANGED
|
@@ -9,7 +9,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
9
9
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
10
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
11
|
};
|
|
12
|
-
var _Options_instances, _Options_data, _Options_dynamic, _Options_asArray, _Options_toRange;
|
|
12
|
+
var _Options_instances, _Options_data, _Options_tags, _Options_dynamic, _Options_asArray, _Options_toRange;
|
|
13
13
|
import { OptionsValidator } from './Validator/OptionsValidator.js';
|
|
14
14
|
/**
|
|
15
15
|
* Validates the raw user-supplied options and exposes them through typed
|
|
@@ -25,6 +25,7 @@ export class Options {
|
|
|
25
25
|
constructor(data = {}) {
|
|
26
26
|
_Options_instances.add(this);
|
|
27
27
|
_Options_data.set(this, void 0);
|
|
28
|
+
_Options_tags.set(this, void 0);
|
|
28
29
|
OptionsValidator.validate(data);
|
|
29
30
|
__classPrivateFieldSet(this, _Options_data, structuredClone(data), "f");
|
|
30
31
|
}
|
|
@@ -64,6 +65,24 @@ export class Options {
|
|
|
64
65
|
translateY() {
|
|
65
66
|
return __classPrivateFieldGet(this, _Options_instances, "m", _Options_toRange).call(this, __classPrivateFieldGet(this, _Options_data, "f").translateY);
|
|
66
67
|
}
|
|
68
|
+
/**
|
|
69
|
+
* Returns the global `tags` filter as parsed tokens, or an empty array when
|
|
70
|
+
* unset. Each raw token (`category` / `category:value`, optionally
|
|
71
|
+
* `!`-prefixed to disallow) is decoded into `{ category, value?, negated }` so
|
|
72
|
+
* the resolver composes the filter without parsing the grammar itself. An
|
|
73
|
+
* empty list means no tag filtering (classic behavior). Memoized, since the
|
|
74
|
+
* resolver reads it once per component.
|
|
75
|
+
*/
|
|
76
|
+
tags() {
|
|
77
|
+
return (__classPrivateFieldSet(this, _Options_tags, __classPrivateFieldGet(this, _Options_tags, "f") ?? __classPrivateFieldGet(this, _Options_instances, "m", _Options_asArray).call(this, __classPrivateFieldGet(this, _Options_data, "f").tags).map((token) => {
|
|
78
|
+
const negated = token.startsWith('!');
|
|
79
|
+
const body = negated ? token.slice(1) : token;
|
|
80
|
+
const sep = body.indexOf(':');
|
|
81
|
+
return sep === -1
|
|
82
|
+
? { category: body, negated }
|
|
83
|
+
: { category: body.slice(0, sep), value: body.slice(sep + 1), negated };
|
|
84
|
+
}), "f"));
|
|
85
|
+
}
|
|
67
86
|
/**
|
|
68
87
|
* Returns the user-set variant constraint for `name` as a weighted map, or
|
|
69
88
|
* `undefined` when `${name}Variant` is unset. A bare string or string list
|
|
@@ -106,7 +125,7 @@ export class Options {
|
|
|
106
125
|
return __classPrivateFieldGet(this, _Options_instances, "m", _Options_toRange).call(this, __classPrivateFieldGet(this, _Options_instances, "m", _Options_dynamic).call(this, `${name}ColorFillStops`));
|
|
107
126
|
}
|
|
108
127
|
}
|
|
109
|
-
_Options_data = new WeakMap(), _Options_instances = new WeakSet(), _Options_dynamic = function _Options_dynamic(key) {
|
|
128
|
+
_Options_data = new WeakMap(), _Options_tags = new WeakMap(), _Options_instances = new WeakSet(), _Options_dynamic = function _Options_dynamic(key) {
|
|
110
129
|
return __classPrivateFieldGet(this, _Options_data, "f")[key];
|
|
111
130
|
}, _Options_asArray = function _Options_asArray(value) {
|
|
112
131
|
if (value === undefined) {
|
package/lib/OptionsDescriptor.js
CHANGED
|
@@ -49,18 +49,24 @@ _a = OptionsDescriptor, _OptionsDescriptor_descriptor = new WeakMap(), _OptionsD
|
|
|
49
49
|
translateX: __classPrivateFieldGet(_a, _a, "f", _OptionsDescriptor_translateRange),
|
|
50
50
|
translateY: __classPrivateFieldGet(_a, _a, "f", _OptionsDescriptor_translateRange),
|
|
51
51
|
};
|
|
52
|
+
const tags = new Set();
|
|
52
53
|
for (const [name, component] of __classPrivateFieldGet(this, _OptionsDescriptor_style, "f").components()) {
|
|
53
54
|
if (component.extendsName() !== undefined) {
|
|
54
55
|
continue;
|
|
55
56
|
}
|
|
56
|
-
const variants =
|
|
57
|
+
const variants = component.variants();
|
|
57
58
|
result[`${name}Variant`] = {
|
|
58
59
|
type: 'enum',
|
|
59
|
-
values: variants,
|
|
60
|
+
values: Array.from(variants.keys()).sort(),
|
|
60
61
|
list: true,
|
|
61
62
|
weighted: true,
|
|
62
63
|
};
|
|
63
64
|
result[`${name}Probability`] = { type: 'number', min: 0, max: 100 };
|
|
65
|
+
for (const variant of variants.values()) {
|
|
66
|
+
for (const tag of variant.tags()) {
|
|
67
|
+
tags.add(tag);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
64
70
|
}
|
|
65
71
|
for (const name of [...__classPrivateFieldGet(this, _OptionsDescriptor_style, "f").colors().keys(), 'background']) {
|
|
66
72
|
const contrastTo = __classPrivateFieldGet(this, _OptionsDescriptor_style, "f").colors().get(name)?.contrastTo();
|
|
@@ -77,6 +83,20 @@ _a = OptionsDescriptor, _OptionsDescriptor_descriptor = new WeakMap(), _OptionsD
|
|
|
77
83
|
result[`${name}ColorFillStops`] = { type: 'range', min: 2 };
|
|
78
84
|
result[`${name}ColorAngle`] = __classPrivateFieldGet(_a, _a, "f", _OptionsDescriptor_rotateRange);
|
|
79
85
|
}
|
|
86
|
+
// Only advertise the `tags` filter when the style actually carries tags.
|
|
87
|
+
// The values are the sorted union of every tag across the style's variants,
|
|
88
|
+
// but `open` marks them as suggestions: the filter also accepts `!`
|
|
89
|
+
// disallows and bare categories. Only an unknown category is ignored. An
|
|
90
|
+
// unknown value inside a category the style does use matches nothing, so
|
|
91
|
+
// every variant tagged on that axis is dropped.
|
|
92
|
+
if (tags.size > 0) {
|
|
93
|
+
result.tags = {
|
|
94
|
+
type: 'enum',
|
|
95
|
+
values: Array.from(tags).sort(),
|
|
96
|
+
list: true,
|
|
97
|
+
open: true,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
80
100
|
return result;
|
|
81
101
|
};
|
|
82
102
|
_OptionsDescriptor_rotateRange = { value: { type: 'range', min: -360, max: 360 } };
|
package/lib/Renderer.js
CHANGED
|
@@ -72,7 +72,7 @@ export class Renderer {
|
|
|
72
72
|
attrs.push(`width="${sizeValue}"`, `height="${sizeValue}"`);
|
|
73
73
|
}
|
|
74
74
|
const titleElement = escapedTitle !== undefined ? `<title>${escapedTitle}</title>` : '';
|
|
75
|
-
let svg = `<svg ${attrs.join(' ')}><!-- Generated by DiceBear (https://dicebear.com) -->${metadata}${defs}${titleElement}${body}</svg>`;
|
|
75
|
+
let svg = `<svg ${attrs.join(' ')}><!-- Generated by DiceBear (https://www.dicebear.com) -->${metadata}${defs}${titleElement}${body}</svg>`;
|
|
76
76
|
if (__classPrivateFieldGet(this, _Renderer_resolver, "f").idRandomization()) {
|
|
77
77
|
svg = __classPrivateFieldGet(this, _Renderer_instances, "m", _Renderer_randomizeIds).call(this, svg);
|
|
78
78
|
}
|
|
@@ -313,5 +313,5 @@ _Renderer_style = new WeakMap(), _Renderer_resolver = new WeakMap(), _Renderer_d
|
|
|
313
313
|
}, _Renderer_initials = function _Renderer_initials() {
|
|
314
314
|
return (__classPrivateFieldSet(this, _Renderer_cachedInitials, __classPrivateFieldGet(this, _Renderer_cachedInitials, "f") ?? Initials.fromSeed(__classPrivateFieldGet(this, _Renderer_resolver, "f").seed()), "f"));
|
|
315
315
|
}, _Renderer_hashSeed = function _Renderer_hashSeed() {
|
|
316
|
-
return (__classPrivateFieldSet(this, _Renderer_cachedSeedHash, __classPrivateFieldGet(this, _Renderer_cachedSeedHash, "f") ?? Fnv1a.hex(__classPrivateFieldGet(this, _Renderer_resolver, "f").seed()), "f"));
|
|
316
|
+
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"));
|
|
317
317
|
};
|
package/lib/Resolver.d.ts
CHANGED
|
@@ -26,15 +26,10 @@ export declare class Resolver<D = unknown> {
|
|
|
26
26
|
translateX(): number;
|
|
27
27
|
translateY(): number;
|
|
28
28
|
/**
|
|
29
|
-
* Selects a variant for the given component.
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
* - otherwise: PRNG picks using the user-supplied weighted map (a bare
|
|
34
|
-
* string or string list is normalized to weight `1` each in
|
|
35
|
-
* {@link Options.componentVariant}).
|
|
36
|
-
*
|
|
37
|
-
* Only variants that exist in the style definition are considered.
|
|
29
|
+
* Selects a variant for the given component. The pool the PRNG draws from is
|
|
30
|
+
* built from the per-component `${name}Variant` option and the global `tags`
|
|
31
|
+
* filter (see {@link #variantWeights}). Only variants that exist in the style
|
|
32
|
+
* definition are considered.
|
|
38
33
|
*/
|
|
39
34
|
variant(name: string): string | undefined;
|
|
40
35
|
color(name: string): readonly string[];
|
package/lib/Resolver.js
CHANGED
|
@@ -9,7 +9,7 @@ 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 _Resolver_instances, _Resolver_style, _Resolver_options, _Resolver_prng, _Resolver_colorResolving, _Resolver_result, _Resolver_probability, _Resolver_isVisible, _Resolver_resolveColor, _Resolver_colorFillStops, _Resolver_memoFloat, _Resolver_memo;
|
|
12
|
+
var _Resolver_instances, _Resolver_style, _Resolver_options, _Resolver_prng, _Resolver_colorResolving, _Resolver_result, _Resolver_tagFilterCache, _Resolver_probability, _Resolver_isVisible, _Resolver_variantWeights, _Resolver_tagFilter, _Resolver_tagFilteredNames, _Resolver_resolveColor, _Resolver_colorFillStops, _Resolver_memoFloat, _Resolver_memo;
|
|
13
13
|
import { Prng } from './Prng.js';
|
|
14
14
|
import { Color } from './Utils/Color.js';
|
|
15
15
|
import { CircularColorReferenceError } from './Error/CircularColorReferenceError.js';
|
|
@@ -30,6 +30,7 @@ export class Resolver {
|
|
|
30
30
|
_Resolver_prng.set(this, void 0);
|
|
31
31
|
_Resolver_colorResolving.set(this, []);
|
|
32
32
|
_Resolver_result.set(this, {});
|
|
33
|
+
_Resolver_tagFilterCache.set(this, void 0);
|
|
33
34
|
__classPrivateFieldSet(this, _Resolver_style, style, "f");
|
|
34
35
|
__classPrivateFieldSet(this, _Resolver_options, options, "f");
|
|
35
36
|
__classPrivateFieldSet(this, _Resolver_prng, new Prng(this.seed()), "f");
|
|
@@ -74,15 +75,10 @@ export class Resolver {
|
|
|
74
75
|
return __classPrivateFieldGet(this, _Resolver_instances, "m", _Resolver_memoFloat).call(this, 'translateY', __classPrivateFieldGet(this, _Resolver_options, "f").translateY(), 0);
|
|
75
76
|
}
|
|
76
77
|
/**
|
|
77
|
-
* Selects a variant for the given component.
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
* - otherwise: PRNG picks using the user-supplied weighted map (a bare
|
|
82
|
-
* string or string list is normalized to weight `1` each in
|
|
83
|
-
* {@link Options.componentVariant}).
|
|
84
|
-
*
|
|
85
|
-
* Only variants that exist in the style definition are considered.
|
|
78
|
+
* Selects a variant for the given component. The pool the PRNG draws from is
|
|
79
|
+
* built from the per-component `${name}Variant` option and the global `tags`
|
|
80
|
+
* filter (see {@link #variantWeights}). Only variants that exist in the style
|
|
81
|
+
* definition are considered.
|
|
86
82
|
*/
|
|
87
83
|
variant(name) {
|
|
88
84
|
return __classPrivateFieldGet(this, _Resolver_instances, "m", _Resolver_memo).call(this, `${name}Variant`, () => {
|
|
@@ -90,22 +86,7 @@ export class Resolver {
|
|
|
90
86
|
if (!component || !__classPrivateFieldGet(this, _Resolver_instances, "m", _Resolver_isVisible).call(this, name, component)) {
|
|
91
87
|
return undefined;
|
|
92
88
|
}
|
|
93
|
-
|
|
94
|
-
const variants = component.variants();
|
|
95
|
-
const weights = {};
|
|
96
|
-
if (raw === undefined) {
|
|
97
|
-
for (const [v, variant] of variants) {
|
|
98
|
-
weights[v] = variant.weight();
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
else {
|
|
102
|
-
for (const [v, w] of Object.entries(raw)) {
|
|
103
|
-
if (variants.has(v)) {
|
|
104
|
-
weights[v] = w;
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
return __classPrivateFieldGet(this, _Resolver_prng, "f").weightedPick(`${name}Variant`, weights);
|
|
89
|
+
return __classPrivateFieldGet(this, _Resolver_prng, "f").weightedPick(`${name}Variant`, __classPrivateFieldGet(this, _Resolver_instances, "m", _Resolver_variantWeights).call(this, component));
|
|
109
90
|
});
|
|
110
91
|
}
|
|
111
92
|
color(name) {
|
|
@@ -152,11 +133,84 @@ export class Resolver {
|
|
|
152
133
|
return __classPrivateFieldGet(this, _Resolver_result, "f");
|
|
153
134
|
}
|
|
154
135
|
}
|
|
155
|
-
_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) {
|
|
136
|
+
_Resolver_style = new WeakMap(), _Resolver_options = new WeakMap(), _Resolver_prng = new WeakMap(), _Resolver_colorResolving = new WeakMap(), _Resolver_result = new WeakMap(), _Resolver_tagFilterCache = new WeakMap(), _Resolver_instances = new WeakSet(), _Resolver_probability = function _Resolver_probability(component) {
|
|
156
137
|
const raw = __classPrivateFieldGet(this, _Resolver_options, "f").componentProbability(component.sourceName());
|
|
157
138
|
return raw ?? component.probability();
|
|
158
139
|
}, _Resolver_isVisible = function _Resolver_isVisible(name, component) {
|
|
159
140
|
return __classPrivateFieldGet(this, _Resolver_prng, "f").bool(`${name}Probability`, __classPrivateFieldGet(this, _Resolver_instances, "m", _Resolver_probability).call(this, component));
|
|
141
|
+
}, _Resolver_variantWeights = function _Resolver_variantWeights(component) {
|
|
142
|
+
const variants = component.variants();
|
|
143
|
+
const named = __classPrivateFieldGet(this, _Resolver_options, "f").componentVariant(component.sourceName());
|
|
144
|
+
const weights = {};
|
|
145
|
+
const names = named
|
|
146
|
+
? Object.keys(named)
|
|
147
|
+
: __classPrivateFieldGet(this, _Resolver_options, "f").tags().length > 0
|
|
148
|
+
? __classPrivateFieldGet(this, _Resolver_instances, "m", _Resolver_tagFilteredNames).call(this, variants)
|
|
149
|
+
: variants.keys();
|
|
150
|
+
for (const name of names) {
|
|
151
|
+
const variant = variants.get(name);
|
|
152
|
+
if (variant !== undefined) {
|
|
153
|
+
weights[name] = named ? named[name] : variant.weight();
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
return weights;
|
|
157
|
+
}, _Resolver_tagFilter = function _Resolver_tagFilter() {
|
|
158
|
+
if (__classPrivateFieldGet(this, _Resolver_tagFilterCache, "f")) {
|
|
159
|
+
return __classPrivateFieldGet(this, _Resolver_tagFilterCache, "f");
|
|
160
|
+
}
|
|
161
|
+
const allows = new Map();
|
|
162
|
+
const bares = new Set();
|
|
163
|
+
const disallows = [];
|
|
164
|
+
const bareDisallows = new Set();
|
|
165
|
+
for (const { category, value, negated } of __classPrivateFieldGet(this, _Resolver_options, "f").tags()) {
|
|
166
|
+
if (negated) {
|
|
167
|
+
disallows.push({ category, value });
|
|
168
|
+
if (value === undefined) {
|
|
169
|
+
bareDisallows.add(category);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
else if (value !== undefined) {
|
|
173
|
+
const values = allows.get(category) ?? [];
|
|
174
|
+
values.push(value);
|
|
175
|
+
allows.set(category, values);
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
bares.add(category);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
__classPrivateFieldSet(this, _Resolver_tagFilterCache, {
|
|
182
|
+
// Materialize the allow groups once, not on every variant.
|
|
183
|
+
allowGroups: [...allows],
|
|
184
|
+
bares,
|
|
185
|
+
disallows,
|
|
186
|
+
bareDisallows,
|
|
187
|
+
}, "f");
|
|
188
|
+
return __classPrivateFieldGet(this, _Resolver_tagFilterCache, "f");
|
|
189
|
+
}, _Resolver_tagFilteredNames = function _Resolver_tagFilteredNames(variants) {
|
|
190
|
+
const { allowGroups, bares, disallows, bareDisallows } = __classPrivateFieldGet(this, _Resolver_instances, "m", _Resolver_tagFilter).call(this);
|
|
191
|
+
// A bare token only binds where its category is in use, so this narrowing
|
|
192
|
+
// — unlike the classification above — is genuinely per-component.
|
|
193
|
+
const required = [...bares].filter((category) => {
|
|
194
|
+
if (bareDisallows.has(category)) {
|
|
195
|
+
return false;
|
|
196
|
+
}
|
|
197
|
+
for (const variant of variants.values()) {
|
|
198
|
+
if (variant.hasTag(category)) {
|
|
199
|
+
return true;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
return false;
|
|
203
|
+
});
|
|
204
|
+
const names = [];
|
|
205
|
+
for (const [name, variant] of variants) {
|
|
206
|
+
const allowed = allowGroups.every(([category, values]) => !variant.hasTag(category) ||
|
|
207
|
+
values.some((value) => variant.hasTag(category, value))) && required.every((category) => variant.hasTag(category));
|
|
208
|
+
const disallowed = disallows.some(({ category, value }) => variant.hasTag(category, value));
|
|
209
|
+
if (allowed && !disallowed) {
|
|
210
|
+
names.push(name);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
return names;
|
|
160
214
|
}, _Resolver_resolveColor = function _Resolver_resolveColor(name) {
|
|
161
215
|
const userColors = __classPrivateFieldGet(this, _Resolver_options, "f").color(name);
|
|
162
216
|
const styleColor = __classPrivateFieldGet(this, _Resolver_style, "f").colors().get(name);
|
|
@@ -15,4 +15,18 @@ export declare class ComponentVariant {
|
|
|
15
15
|
* Returns the weighted-pick weight for this variant, defaulting to `1`.
|
|
16
16
|
*/
|
|
17
17
|
weight(): number;
|
|
18
|
+
/**
|
|
19
|
+
* Returns the variant's descriptive tags (e.g. `hairLength:long`), or an
|
|
20
|
+
* empty list when none are authored. Consumed by the `tags` render option
|
|
21
|
+
* to filter the variant pool.
|
|
22
|
+
*/
|
|
23
|
+
tags(): readonly string[];
|
|
24
|
+
/**
|
|
25
|
+
* Tests this variant against a single tag-filter token's grammar. With no
|
|
26
|
+
* `value`, it matches a whole category: the bare `category` tag or any
|
|
27
|
+
* `category:value` tag. With a `value`, it matches only the exact
|
|
28
|
+
* `category:value` tag. The resolver composes these checks into the
|
|
29
|
+
* allow/disallow filter structure.
|
|
30
|
+
*/
|
|
31
|
+
hasTag(category: string, value?: string): boolean;
|
|
18
32
|
}
|
|
@@ -34,5 +34,26 @@ export class ComponentVariant {
|
|
|
34
34
|
weight() {
|
|
35
35
|
return __classPrivateFieldGet(this, _ComponentVariant_data, "f").weight ?? 1;
|
|
36
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* Returns the variant's descriptive tags (e.g. `hairLength:long`), or an
|
|
39
|
+
* empty list when none are authored. Consumed by the `tags` render option
|
|
40
|
+
* to filter the variant pool.
|
|
41
|
+
*/
|
|
42
|
+
tags() {
|
|
43
|
+
return __classPrivateFieldGet(this, _ComponentVariant_data, "f").tags ?? [];
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Tests this variant against a single tag-filter token's grammar. With no
|
|
47
|
+
* `value`, it matches a whole category: the bare `category` tag or any
|
|
48
|
+
* `category:value` tag. With a `value`, it matches only the exact
|
|
49
|
+
* `category:value` tag. The resolver composes these checks into the
|
|
50
|
+
* allow/disallow filter structure.
|
|
51
|
+
*/
|
|
52
|
+
hasTag(category, value) {
|
|
53
|
+
if (value === undefined) {
|
|
54
|
+
return this.tags().some((tag) => tag === category || tag.startsWith(`${category}:`));
|
|
55
|
+
}
|
|
56
|
+
return this.tags().includes(`${category}:${value}`);
|
|
57
|
+
}
|
|
37
58
|
}
|
|
38
59
|
_ComponentVariant_data = new WeakMap(), _ComponentVariant_elements = new WeakMap();
|
package/lib/StyleDefinition.d.ts
CHANGED
|
@@ -73,6 +73,7 @@ export interface StyleDefinitionComponentTranslate {
|
|
|
73
73
|
export interface StyleDefinitionComponentVariant {
|
|
74
74
|
readonly elements: readonly StyleDefinitionElement[];
|
|
75
75
|
readonly weight?: number;
|
|
76
|
+
readonly tags?: readonly string[];
|
|
76
77
|
}
|
|
77
78
|
export interface StyleDefinitionComponentBase {
|
|
78
79
|
readonly width: number;
|
package/lib/StyleOptions.d.ts
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
export type StyleOptionsFlipValue = 'none' | 'horizontal' | 'vertical' | 'both';
|
|
2
2
|
export type StyleOptionsColorFillValue = 'solid' | 'linear' | 'radial';
|
|
3
|
+
/**
|
|
4
|
+
* A parsed `tags` filter token. {@link Options.tags} decodes each raw
|
|
5
|
+
* `category` / `category:value` / `!…` string into this shape so the resolver
|
|
6
|
+
* composes the filter without parsing the grammar itself.
|
|
7
|
+
*/
|
|
8
|
+
export interface TagFilterToken {
|
|
9
|
+
readonly category: string;
|
|
10
|
+
readonly value?: string;
|
|
11
|
+
readonly negated: boolean;
|
|
12
|
+
}
|
|
3
13
|
type ComponentNames<D> = D extends {
|
|
4
14
|
components: Record<infer K extends string, unknown>;
|
|
5
15
|
} ? string extends K ? never : K : never;
|
|
@@ -29,6 +39,7 @@ export interface StyleOptionsBase {
|
|
|
29
39
|
readonly rotate?: number | readonly [number, number];
|
|
30
40
|
readonly translateX?: number | readonly [number, number];
|
|
31
41
|
readonly translateY?: number | readonly [number, number];
|
|
42
|
+
readonly tags?: string | readonly string[];
|
|
32
43
|
}
|
|
33
44
|
type ComponentVariantOption<D, K extends string> = VariantNames<D, K> | readonly VariantNames<D, K>[] | Readonly<Partial<Record<VariantNames<D, K>, number>>>;
|
|
34
45
|
type IsAlias<D, C extends string> = D extends {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dicebear/core",
|
|
3
|
-
"version": "10.
|
|
3
|
+
"version": "10.4.0-rc.2",
|
|
4
4
|
"description": "Unique avatars from dozens of styles — deterministic, customizable, vector-based.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"avatar",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"test": "node --test"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@dicebear/schema": "^1.
|
|
41
|
+
"@dicebear/schema": "^1.3.0",
|
|
42
42
|
"@tsconfig/recommended": "^1.0.13",
|
|
43
43
|
"ajv": "^8.17.1",
|
|
44
44
|
"del-cli": "^7.0.0",
|