@usenavii/core 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -1
- package/dist/index.cjs +11 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +33 -1
- package/dist/index.d.ts +33 -1
- package/dist/index.js +11 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -183,6 +183,37 @@ declare function build(spec?: BuildSpec, options?: AvatarOptions): string;
|
|
|
183
183
|
* ```
|
|
184
184
|
*/
|
|
185
185
|
declare function createAvatar(seed: string, options?: AvatarOptions): string;
|
|
186
|
+
/**
|
|
187
|
+
* Generate a random avatar without supplying a seed.
|
|
188
|
+
*
|
|
189
|
+
* Picks a fresh UUID seed via `crypto.randomUUID()` (or a `Math.random()`
|
|
190
|
+
* fallback when WebCrypto is unavailable) and renders the avatar. The seed
|
|
191
|
+
* is returned alongside the SVG so callers can **persist it** — e.g. save
|
|
192
|
+
* to the user's profile so future renders are stable.
|
|
193
|
+
*
|
|
194
|
+
* Use for: "spin again" UX, dev/demo seeding, lazy onboarding flows where
|
|
195
|
+
* the user gets an avatar before picking one.
|
|
196
|
+
*
|
|
197
|
+
* Each call returns a different avatar — DO NOT call inline in a render
|
|
198
|
+
* function or the avatar will change every re-render. Stabilize with a
|
|
199
|
+
* `useState`/`useMemo` init or persist the returned seed:
|
|
200
|
+
*
|
|
201
|
+
* @example
|
|
202
|
+
* ```ts
|
|
203
|
+
* const { svg, seed } = Navii.random({ size: 96 });
|
|
204
|
+
* saveToProfile(user.id, { naviiSeed: seed });
|
|
205
|
+
* ```
|
|
206
|
+
*
|
|
207
|
+
* @example React
|
|
208
|
+
* ```tsx
|
|
209
|
+
* const [random] = useState(() => Navii.random());
|
|
210
|
+
* return <Navii seed={random.seed} />;
|
|
211
|
+
* ```
|
|
212
|
+
*/
|
|
213
|
+
declare function random(options?: AvatarOptions): {
|
|
214
|
+
svg: string;
|
|
215
|
+
seed: string;
|
|
216
|
+
};
|
|
186
217
|
/**
|
|
187
218
|
* Convenience namespace — bundles every public function under one import.
|
|
188
219
|
*
|
|
@@ -198,6 +229,7 @@ declare function createAvatar(seed: string, options?: AvatarOptions): string;
|
|
|
198
229
|
*/
|
|
199
230
|
declare const Navii: {
|
|
200
231
|
readonly create: typeof createAvatar;
|
|
232
|
+
readonly random: typeof random;
|
|
201
233
|
readonly render: typeof renderAvatar;
|
|
202
234
|
readonly select: typeof selectAvatar;
|
|
203
235
|
readonly group: typeof renderGroup;
|
|
@@ -205,4 +237,4 @@ declare const Navii: {
|
|
|
205
237
|
readonly build: typeof build;
|
|
206
238
|
};
|
|
207
239
|
|
|
208
|
-
export { AccessoryId, AntennaStyleId, AvatarOptions, AvatarSpec, BackgroundId, BodyShapeId, type BuildSpec, EyeStyleId, type GroupOptions, MouthStyleId, Navii, OutfitId, type SeedFields, TopperId, build, createAvatar, createRng, cyrb53, renderAvatar, renderAvatarInner, renderGroup, seed, selectAvatar };
|
|
240
|
+
export { AccessoryId, AntennaStyleId, AvatarOptions, AvatarSpec, BackgroundId, BodyShapeId, type BuildSpec, EyeStyleId, type GroupOptions, MouthStyleId, Navii, OutfitId, type SeedFields, TopperId, build, createAvatar, createRng, cyrb53, random, renderAvatar, renderAvatarInner, renderGroup, seed, selectAvatar };
|
package/dist/index.d.ts
CHANGED
|
@@ -183,6 +183,37 @@ declare function build(spec?: BuildSpec, options?: AvatarOptions): string;
|
|
|
183
183
|
* ```
|
|
184
184
|
*/
|
|
185
185
|
declare function createAvatar(seed: string, options?: AvatarOptions): string;
|
|
186
|
+
/**
|
|
187
|
+
* Generate a random avatar without supplying a seed.
|
|
188
|
+
*
|
|
189
|
+
* Picks a fresh UUID seed via `crypto.randomUUID()` (or a `Math.random()`
|
|
190
|
+
* fallback when WebCrypto is unavailable) and renders the avatar. The seed
|
|
191
|
+
* is returned alongside the SVG so callers can **persist it** — e.g. save
|
|
192
|
+
* to the user's profile so future renders are stable.
|
|
193
|
+
*
|
|
194
|
+
* Use for: "spin again" UX, dev/demo seeding, lazy onboarding flows where
|
|
195
|
+
* the user gets an avatar before picking one.
|
|
196
|
+
*
|
|
197
|
+
* Each call returns a different avatar — DO NOT call inline in a render
|
|
198
|
+
* function or the avatar will change every re-render. Stabilize with a
|
|
199
|
+
* `useState`/`useMemo` init or persist the returned seed:
|
|
200
|
+
*
|
|
201
|
+
* @example
|
|
202
|
+
* ```ts
|
|
203
|
+
* const { svg, seed } = Navii.random({ size: 96 });
|
|
204
|
+
* saveToProfile(user.id, { naviiSeed: seed });
|
|
205
|
+
* ```
|
|
206
|
+
*
|
|
207
|
+
* @example React
|
|
208
|
+
* ```tsx
|
|
209
|
+
* const [random] = useState(() => Navii.random());
|
|
210
|
+
* return <Navii seed={random.seed} />;
|
|
211
|
+
* ```
|
|
212
|
+
*/
|
|
213
|
+
declare function random(options?: AvatarOptions): {
|
|
214
|
+
svg: string;
|
|
215
|
+
seed: string;
|
|
216
|
+
};
|
|
186
217
|
/**
|
|
187
218
|
* Convenience namespace — bundles every public function under one import.
|
|
188
219
|
*
|
|
@@ -198,6 +229,7 @@ declare function createAvatar(seed: string, options?: AvatarOptions): string;
|
|
|
198
229
|
*/
|
|
199
230
|
declare const Navii: {
|
|
200
231
|
readonly create: typeof createAvatar;
|
|
232
|
+
readonly random: typeof random;
|
|
201
233
|
readonly render: typeof renderAvatar;
|
|
202
234
|
readonly select: typeof selectAvatar;
|
|
203
235
|
readonly group: typeof renderGroup;
|
|
@@ -205,4 +237,4 @@ declare const Navii: {
|
|
|
205
237
|
readonly build: typeof build;
|
|
206
238
|
};
|
|
207
239
|
|
|
208
|
-
export { AccessoryId, AntennaStyleId, AvatarOptions, AvatarSpec, BackgroundId, BodyShapeId, type BuildSpec, EyeStyleId, type GroupOptions, MouthStyleId, Navii, OutfitId, type SeedFields, TopperId, build, createAvatar, createRng, cyrb53, renderAvatar, renderAvatarInner, renderGroup, seed, selectAvatar };
|
|
240
|
+
export { AccessoryId, AntennaStyleId, AvatarOptions, AvatarSpec, BackgroundId, BodyShapeId, type BuildSpec, EyeStyleId, type GroupOptions, MouthStyleId, Navii, OutfitId, type SeedFields, TopperId, build, createAvatar, createRng, cyrb53, random, renderAvatar, renderAvatarInner, renderGroup, seed, selectAvatar };
|
package/dist/index.js
CHANGED
|
@@ -948,8 +948,18 @@ function createAvatar(seed2, options = {}) {
|
|
|
948
948
|
}
|
|
949
949
|
return renderAvatar(selectAvatar(seed2, options), options);
|
|
950
950
|
}
|
|
951
|
+
function random(options = {}) {
|
|
952
|
+
const seed2 = randomSeed();
|
|
953
|
+
return { svg: createAvatar(seed2, options), seed: seed2 };
|
|
954
|
+
}
|
|
955
|
+
function randomSeed() {
|
|
956
|
+
const c = globalThis.crypto;
|
|
957
|
+
if (c && typeof c.randomUUID === "function") return c.randomUUID();
|
|
958
|
+
return Math.random().toString(36).slice(2) + Math.random().toString(36).slice(2);
|
|
959
|
+
}
|
|
951
960
|
var Navii = {
|
|
952
961
|
create: createAvatar,
|
|
962
|
+
random,
|
|
953
963
|
render: renderAvatar,
|
|
954
964
|
select: selectAvatar,
|
|
955
965
|
group: renderGroup,
|
|
@@ -957,6 +967,6 @@ var Navii = {
|
|
|
957
967
|
build
|
|
958
968
|
};
|
|
959
969
|
|
|
960
|
-
export { Navii, build, createAvatar, createRng, cyrb53, renderAvatar, renderAvatarInner, renderGroup, seed, selectAvatar };
|
|
970
|
+
export { Navii, build, createAvatar, createRng, cyrb53, random, renderAvatar, renderAvatarInner, renderGroup, seed, selectAvatar };
|
|
961
971
|
//# sourceMappingURL=index.js.map
|
|
962
972
|
//# sourceMappingURL=index.js.map
|