@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 CHANGED
@@ -64,6 +64,7 @@ It picks the most unique field automatically: `id` → `email` → `name + creat
64
64
 
65
65
  ```ts
66
66
  createAvatar(seed: string, options?: AvatarOptions): string
67
+ random(options?: AvatarOptions): { svg: string; seed: string }
67
68
  selectAvatar(seed: string, options?: AvatarOptions): AvatarSpec
68
69
  renderAvatar(spec: AvatarSpec, options?: AvatarOptions): string
69
70
  renderGroup(seeds: string[], options?: GroupOptions): string
@@ -71,7 +72,7 @@ renderGroup(seeds: string[], options?: GroupOptions): string
71
72
  seed(fields: SeedFields): string // pick most-unique field
72
73
  build(spec?: BuildSpec, opts?): string // manual mix-and-match (no seed)
73
74
 
74
- Navii.{ create, render, select, group, seed, build }
75
+ Navii.{ create, random, render, select, group, seed, build }
75
76
  ```
76
77
 
77
78
  ### `AvatarOptions`
@@ -85,6 +86,22 @@ Navii.{ create, render, select, group, seed, build }
85
86
  | `title` | accessible label (sets `<title>` + `aria-label`) | none |
86
87
  | `animated` | `boolean` — idle float / blink / sway / pulse / twinkle | `false` |
87
88
 
89
+ ### `random()` — pick a seed for you
90
+
91
+ For "spin again" UX, onboarding before the user picks an avatar, dev/demo seeding. Returns the chosen seed so you can persist it:
92
+
93
+ ```ts
94
+ const { svg, seed } = Navii.random({ size: 96 });
95
+ await db.users.update(user.id, { naviiSeed: seed });
96
+ ```
97
+
98
+ Calling `random()` in a React render gives a new avatar every re-render. Stabilize with `useState`:
99
+
100
+ ```tsx
101
+ const [{ seed }] = useState(() => Navii.random());
102
+ return <Navii seed={seed} />;
103
+ ```
104
+
88
105
  ### `build()` — direct construction without a seed
89
106
 
90
107
  Use for brand mascots, logo marks, designer-curated avatars:
package/dist/index.cjs CHANGED
@@ -950,8 +950,18 @@ function createAvatar(seed2, options = {}) {
950
950
  }
951
951
  return renderAvatar(selectAvatar(seed2, options), options);
952
952
  }
953
+ function random(options = {}) {
954
+ const seed2 = randomSeed();
955
+ return { svg: createAvatar(seed2, options), seed: seed2 };
956
+ }
957
+ function randomSeed() {
958
+ const c = globalThis.crypto;
959
+ if (c && typeof c.randomUUID === "function") return c.randomUUID();
960
+ return Math.random().toString(36).slice(2) + Math.random().toString(36).slice(2);
961
+ }
953
962
  var Navii = {
954
963
  create: createAvatar,
964
+ random,
955
965
  render: renderAvatar,
956
966
  select: selectAvatar,
957
967
  group: renderGroup,
@@ -964,6 +974,7 @@ exports.build = build;
964
974
  exports.createAvatar = createAvatar;
965
975
  exports.createRng = createRng;
966
976
  exports.cyrb53 = cyrb53;
977
+ exports.random = random;
967
978
  exports.renderAvatar = renderAvatar;
968
979
  exports.renderAvatarInner = renderAvatarInner;
969
980
  exports.renderGroup = renderGroup;