@blobbies/react 0.0.0-stage → 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Blobbies contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,62 @@
1
- # Temporary Holding Version
1
+ # @blobbies/react
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ React bindings for [blobbies](https://www.npmjs.com/package/blobbies) —
4
+ deterministic, cute SVG avatars with an optional CSS blink and JS cursor follow.
5
+
6
+ ```tsx
7
+ import { Avatar } from '@blobbies/react';
8
+
9
+ <Avatar name="Sourav Nanda" size={64} animate="all" wink />
10
+ ```
11
+
12
+ Inline, SSR-safe SVG with `role="img"` and `aria-label`. The avatar is memoised
13
+ so unrelated re-renders never reset the blink animation, and pointer movement
14
+ never triggers a React render — motion is written straight to CSS variables by
15
+ the shared runtime.
16
+
17
+ ## Install
18
+
19
+ ```sh
20
+ npm i @blobbies/react
21
+ ```
22
+
23
+ React 18 or newer is a peer dependency. `blobbies` is the only runtime
24
+ dependency.
25
+
26
+ ## `<Avatar>`
27
+
28
+ Takes every [blobbies option](https://www.npmjs.com/package/blobbies) plus the
29
+ usual SVG props.
30
+
31
+ | Prop | Type | Default |
32
+ | --- | --- | --- |
33
+ | `name` | `string` | required |
34
+ | `size` | `number \| string` | `48` |
35
+ | `animate` | `boolean \| 'blink' \| 'follow' \| 'all'` | `false` |
36
+ | `blinkInterval` | `[min, max]` ms | `[2500, 6000]` |
37
+ | `followRange` | `number` | `6` |
38
+ | `smoothing` | `0..1` | `0.15` |
39
+ | `idleTimeout` | `number` ms | `2500` |
40
+ | `paused` | `boolean` | `false` |
41
+ | `respectReducedMotion` | `boolean` | `true` |
42
+ | `wink` / `glance` / `surprise` | `boolean` | `false` |
43
+ | `rounded` | `boolean` | `false` |
44
+
45
+ ## `useAvatarMotion`
46
+
47
+ Bring your own SVG and attach the same runtime:
48
+
49
+ ```tsx
50
+ import { useRef } from 'react';
51
+ import { useAvatarMotion } from '@blobbies/react';
52
+
53
+ function Mine() {
54
+ const ref = useRef<SVGSVGElement>(null);
55
+ useAvatarMotion(ref, { animate: 'follow', followRange: 6 });
56
+ return <svg ref={ref} viewBox="0 0 100 100">{/* bb-* layers */}</svg>;
57
+ }
58
+ ```
59
+
60
+ ## Licence
61
+
62
+ MIT
package/dist/index.cjs ADDED
@@ -0,0 +1,3 @@
1
+ 'use strict';var react=require('react'),blobbies=require('blobbies'),motion=require('blobbies/motion'),jsxRuntime=require('react/jsx-runtime');function l(a,t={}){let e=react.useRef({...t});Object.assign(e.current,t);let o=blobbies.wantsFollow({animate:t.animate,follow:t.follow});react.useEffect(()=>{let r=a.current;if(!(!o||!r))return motion.attachAvatarMotion(r,e.current)},[o,t.followTarget,a]);}function B(a){let{name:t,size:e,rounded:o,className:r,title:m,palette:p,animate:n,blink:f,blinkInterval:c,follow:b,followRange:v,followTarget:u,smoothing:A,idleTimeout:d,paused:y,respectReducedMotion:S,wink:g,glance:w,surprise:O,style:M,...s}=a,P={size:e,rounded:o,className:r,title:m,palette:p,animate:n,blink:f,blinkInterval:c,follow:b,followRange:v,followTarget:u,smoothing:A,idleTimeout:d,paused:y,respectReducedMotion:S,wink:g,glance:w,surprise:O},G=JSON.stringify([t,n,f,c,p,m,o,e,r]),i=react.useMemo(()=>blobbies.renderAvatarBody(t,P),[G]),x=react.useRef(null);l(x,{animate:n,follow:b,followRange:v,followTarget:u,smoothing:A,idleTimeout:d,paused:y,respectReducedMotion:S,wink:g,glance:w,surprise:O});let V=["bb",i.prefix,r].filter(Boolean).join(" "),h=o?{borderRadius:"50%",...M}:M;return jsxRuntime.jsx("svg",{...s,ref:x,xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 100 100",role:s.role??"img","aria-label":s["aria-label"]??t,width:e??48,height:e??48,className:V,style:h,"data-blobbies":i.letters,dangerouslySetInnerHTML:{__html:i.body}})}
2
+ exports.Avatar=B;exports.useAvatarMotion=l;//# sourceMappingURL=index.cjs.map
3
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/useAvatarMotion.ts","../src/Avatar.tsx"],"names":["useAvatarMotion","ref","options","stable","useRef","enabled","wantsFollow","useEffect","element","attachAvatarMotion","Avatar","props","name","size","rounded","className","title","palette","animate","blink","blinkInterval","follow","followRange","followTarget","smoothing","idleTimeout","paused","respectReducedMotion","wink","glance","surprise","style","svgProps","bodyKey","resolved","useMemo","renderAvatarBody","classes","mergedStyle","jsx"],"mappings":"+IAoBO,SAASA,CAAAA,CACdC,CAAAA,CACAC,CAAAA,CAAkC,EAAC,CAC7B,CACN,IAAMC,CAAAA,CAASC,aAA+B,CAAE,GAAGF,CAAQ,CAAC,CAAA,CAE5D,MAAA,CAAO,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A,CAAYA,CAAAA,CAAS,YAAY,CAAA,EAAKpB,EACtC,KAAA,CAAOC,CAAAA,EAAQ,EAAA,CACf,MAAA,CAAQA,CAAAA,EAAQ,EAAA,CAChB,SAAA,CAAWwB,CAAAA,CACX,MAAOC,CAAAA,CACP,eAAA,CAAeJ,CAAAA,CAAS,OAAA,CACxB,wBAAyB,CAAE,MAAA,CAAQA,CAAAA,CAAS,IAAK,EACnD,CAEJ","file":"index.cjs","sourcesContent":["import { useEffect, useRef } from 'react';\nimport type { RefObject } from 'react';\nimport { wantsFollow } from 'blobbies';\nimport { attachAvatarMotion } from 'blobbies/motion';\nimport type { MotionOptions } from 'blobbies';\nimport type { AvatarAnimate } from 'blobbies';\n\nexport interface UseAvatarMotionOptions extends MotionOptions {\n animate?: AvatarAnimate;\n /** Explicit override; defaults to true when `animate` includes follow. */\n follow?: boolean;\n}\n\n/**\n * Attach cursor-following motion to an SVG produced by Blobbies.\n *\n * The element keeps a single, stable options object which is mutated on every\n * render — so changing smoothing/idle/range never re-registers listeners, and\n * nothing re-renders on pointer move.\n */\nexport function useAvatarMotion(\n ref: RefObject<SVGSVGElement | null>,\n options: UseAvatarMotionOptions = {},\n): void {\n const stable = useRef<UseAvatarMotionOptions>({ ...options });\n // Mutate the same object every render; the motion runtime reads it live.\n Object.assign(stable.current, options);\n\n const enabled = wantsFollow({ animate: options.animate, follow: options.follow });\n\n useEffect(() => {\n const element = ref.current;\n if (!enabled || !element) return undefined;\n return attachAvatarMotion(element, stable.current);\n }, [enabled, options.followTarget, ref]);\n}\n","import { useMemo, useRef } from 'react';\nimport type { CSSProperties, SVGProps } from 'react';\nimport { renderAvatarBody } from 'blobbies';\nimport type { AvatarOptions } from 'blobbies';\nimport { useAvatarMotion } from './useAvatarMotion.js';\n\nexport interface AvatarProps\n extends AvatarOptions,\n Omit<SVGProps<SVGSVGElement>, 'name' | 'className' | 'color' | 'style'> {\n /** The name to derive the avatar from. */\n name: string;\n /** Extra inline styles for the root svg. */\n style?: CSSProperties;\n}\n\n/**\n * Inline SVG avatar. SSR-safe, accessible and deterministic.\n *\n * Cursor-follow only works on inline SVG (i.e. this component), never on an\n * `<img>`; the blink is pure CSS and works in both.\n */\nexport function Avatar(props: AvatarProps): JSX.Element {\n const {\n name,\n size,\n rounded,\n className,\n title,\n palette,\n animate,\n blink,\n blinkInterval,\n follow,\n followRange,\n followTarget,\n smoothing,\n idleTimeout,\n paused,\n respectReducedMotion,\n wink,\n glance,\n surprise,\n style,\n ...svgProps\n } = props;\n\n const options: AvatarOptions = {\n size,\n rounded,\n className,\n title,\n palette,\n animate,\n blink,\n blinkInterval,\n follow,\n followRange,\n followTarget,\n smoothing,\n idleTimeout,\n paused,\n respectReducedMotion,\n wink,\n glance,\n surprise,\n };\n\n // Only recompute the inner markup when body-affecting options change. This\n // keeps the embedded blink animation from being reset on unrelated renders.\n const bodyKey = JSON.stringify([\n name,\n animate,\n blink,\n blinkInterval,\n palette,\n title,\n rounded,\n size,\n className,\n ]);\n const resolved = useMemo(\n () => renderAvatarBody(name, options),\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [bodyKey],\n );\n\n const ref = useRef<SVGSVGElement>(null);\n useAvatarMotion(ref, {\n animate,\n follow,\n followRange,\n followTarget,\n smoothing,\n idleTimeout,\n paused,\n respectReducedMotion,\n wink,\n glance,\n surprise,\n });\n\n const classes = ['bb', resolved.prefix, className].filter(Boolean).join(' ');\n const mergedStyle: CSSProperties | undefined = rounded\n ? { borderRadius: '50%', ...style }\n : style;\n\n return (\n <svg\n {...svgProps}\n ref={ref}\n xmlns=\"http://www.w3.org/2000/svg\"\n viewBox=\"0 0 100 100\"\n role={svgProps.role ?? 'img'}\n aria-label={svgProps['aria-label'] ?? name}\n width={size ?? 48}\n height={size ?? 48}\n className={classes}\n style={mergedStyle}\n data-blobbies={resolved.letters}\n dangerouslySetInnerHTML={{ __html: resolved.body }}\n />\n );\n}\n"]}
@@ -0,0 +1,33 @@
1
+ import { SVGProps, CSSProperties, RefObject } from 'react';
2
+ import { AvatarOptions, MotionOptions, AvatarAnimate } from 'blobbies';
3
+ export { AvatarAnimate, AvatarOptions, FollowTarget, MotionOptions } from 'blobbies';
4
+
5
+ interface AvatarProps extends AvatarOptions, Omit<SVGProps<SVGSVGElement>, 'name' | 'className' | 'color' | 'style'> {
6
+ /** The name to derive the avatar from. */
7
+ name: string;
8
+ /** Extra inline styles for the root svg. */
9
+ style?: CSSProperties;
10
+ }
11
+ /**
12
+ * Inline SVG avatar. SSR-safe, accessible and deterministic.
13
+ *
14
+ * Cursor-follow only works on inline SVG (i.e. this component), never on an
15
+ * `<img>`; the blink is pure CSS and works in both.
16
+ */
17
+ declare function Avatar(props: AvatarProps): JSX.Element;
18
+
19
+ interface UseAvatarMotionOptions extends MotionOptions {
20
+ animate?: AvatarAnimate;
21
+ /** Explicit override; defaults to true when `animate` includes follow. */
22
+ follow?: boolean;
23
+ }
24
+ /**
25
+ * Attach cursor-following motion to an SVG produced by Blobbies.
26
+ *
27
+ * The element keeps a single, stable options object which is mutated on every
28
+ * render — so changing smoothing/idle/range never re-registers listeners, and
29
+ * nothing re-renders on pointer move.
30
+ */
31
+ declare function useAvatarMotion(ref: RefObject<SVGSVGElement | null>, options?: UseAvatarMotionOptions): void;
32
+
33
+ export { Avatar, type AvatarProps, type UseAvatarMotionOptions, useAvatarMotion };
@@ -0,0 +1,33 @@
1
+ import { SVGProps, CSSProperties, RefObject } from 'react';
2
+ import { AvatarOptions, MotionOptions, AvatarAnimate } from 'blobbies';
3
+ export { AvatarAnimate, AvatarOptions, FollowTarget, MotionOptions } from 'blobbies';
4
+
5
+ interface AvatarProps extends AvatarOptions, Omit<SVGProps<SVGSVGElement>, 'name' | 'className' | 'color' | 'style'> {
6
+ /** The name to derive the avatar from. */
7
+ name: string;
8
+ /** Extra inline styles for the root svg. */
9
+ style?: CSSProperties;
10
+ }
11
+ /**
12
+ * Inline SVG avatar. SSR-safe, accessible and deterministic.
13
+ *
14
+ * Cursor-follow only works on inline SVG (i.e. this component), never on an
15
+ * `<img>`; the blink is pure CSS and works in both.
16
+ */
17
+ declare function Avatar(props: AvatarProps): JSX.Element;
18
+
19
+ interface UseAvatarMotionOptions extends MotionOptions {
20
+ animate?: AvatarAnimate;
21
+ /** Explicit override; defaults to true when `animate` includes follow. */
22
+ follow?: boolean;
23
+ }
24
+ /**
25
+ * Attach cursor-following motion to an SVG produced by Blobbies.
26
+ *
27
+ * The element keeps a single, stable options object which is mutated on every
28
+ * render — so changing smoothing/idle/range never re-registers listeners, and
29
+ * nothing re-renders on pointer move.
30
+ */
31
+ declare function useAvatarMotion(ref: RefObject<SVGSVGElement | null>, options?: UseAvatarMotionOptions): void;
32
+
33
+ export { Avatar, type AvatarProps, type UseAvatarMotionOptions, useAvatarMotion };
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ import {useRef,useEffect,useMemo}from'react';import {wantsFollow,renderAvatarBody}from'blobbies';import {attachAvatarMotion}from'blobbies/motion';import {jsx}from'react/jsx-runtime';function l(a,t={}){let e=useRef({...t});Object.assign(e.current,t);let o=wantsFollow({animate:t.animate,follow:t.follow});useEffect(()=>{let r=a.current;if(!(!o||!r))return attachAvatarMotion(r,e.current)},[o,t.followTarget,a]);}function B(a){let{name:t,size:e,rounded:o,className:r,title:m,palette:p,animate:n,blink:f,blinkInterval:c,follow:b,followRange:v,followTarget:u,smoothing:A,idleTimeout:d,paused:y,respectReducedMotion:S,wink:g,glance:w,surprise:O,style:M,...s}=a,P={size:e,rounded:o,className:r,title:m,palette:p,animate:n,blink:f,blinkInterval:c,follow:b,followRange:v,followTarget:u,smoothing:A,idleTimeout:d,paused:y,respectReducedMotion:S,wink:g,glance:w,surprise:O},G=JSON.stringify([t,n,f,c,p,m,o,e,r]),i=useMemo(()=>renderAvatarBody(t,P),[G]),x=useRef(null);l(x,{animate:n,follow:b,followRange:v,followTarget:u,smoothing:A,idleTimeout:d,paused:y,respectReducedMotion:S,wink:g,glance:w,surprise:O});let V=["bb",i.prefix,r].filter(Boolean).join(" "),h=o?{borderRadius:"50%",...M}:M;return jsx("svg",{...s,ref:x,xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 100 100",role:s.role??"img","aria-label":s["aria-label"]??t,width:e??48,height:e??48,className:V,style:h,"data-blobbies":i.letters,dangerouslySetInnerHTML:{__html:i.body}})}
2
+ export{B as Avatar,l as useAvatarMotion};//# sourceMappingURL=index.js.map
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/useAvatarMotion.ts","../src/Avatar.tsx"],"names":["useAvatarMotion","ref","options","stable","useRef","enabled","wantsFollow","useEffect","element","attachAvatarMotion","Avatar","props","name","size","rounded","className","title","palette","animate","blink","blinkInterval","follow","followRange","followTarget","smoothing","idleTimeout","paused","respectReducedMotion","wink","glance","surprise","style","svgProps","bodyKey","resolved","useMemo","renderAvatarBody","classes","mergedStyle","jsx"],"mappings":"sLAoBO,SAASA,CAAAA,CACdC,CAAAA,CACAC,CAAAA,CAAkC,EAAC,CAC7B,CACN,IAAMC,CAAAA,CAASC,OAA+B,CAAE,GAAGF,CAAQ,CAAC,CAAA,CAE5D,MAAA,CAAO,MAAA,CAAOC,CAAAA,CAAO,QAASD,CAAO,CAAA,CAErC,IAAMG,CAAAA,CAAUC,WAAAA,CAAY,CAAE,OAAA,CAASJ,CAAAA,CAAQ,QAAS,MAAA,CAAQA,CAAAA,CAAQ,MAAO,CAAC,CAAA,CAEhFK,SAAAA,CAAU,IAAM,CACd,IAAMC,CAAAA,CAAUP,CAAAA,CAAI,OAAA,CACpB,GAAI,GAACI,CAAAA,EAAW,CAACG,CAAAA,CAAAA,CACjB,OAAOC,mBAAmBD,CAAAA,CAASL,CAAAA,CAAO,OAAO,CACnD,CAAA,CAAG,CAACE,CAAAA,CAASH,CAAAA,CAAQ,aAAcD,CAAG,CAAC,EACzC,CCdO,SAASS,EAAOC,CAAAA,CAAiC,CACtD,GAAM,CACJ,IAAA,CAAAC,CAAAA,CACA,IAA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CAAA,CACtCJ,CAAAA,CAAgBC,CAAAA,CAAK,CACnB,QAAAiB,CAAAA,CACA,MAAA,CAAAG,CAAAA,CACA,WAAA,CAAAC,EACA,YAAA,CAAAC,CAAAA,CACA,SAAA,CAAAC,CAAAA,CACA,YAAAC,CAAAA,CACA,MAAA,CAAAC,CAAAA,CACA,oBAAA,CAAAC,CAAAA,CACA,IAAA,CAAAC,CAAAA,CACA,MAAA,CAAAC,EACA,QAAA,CAAAC,CACF,CAAC,CAAA,CAED,IAAMO,CAAAA,CAAU,CAAC,IAAA,CAAMH,EAAS,MAAA,CAAQnB,CAAS,CAAA,CAAE,MAAA,CAAO,OAAO,CAAA,CAAE,IAAA,CAAK,GAAG,EACrEuB,CAAAA,CAAyCxB,CAAAA,CAC3C,CAAE,YAAA,CAAc,MAAO,GAAGiB,CAAM,CAAA,CAChCA,CAAAA,CAEJ,OACEQ,GAAAA,CAAC,KAAA,CAAA,CACE,GAAGP,CAAAA,CACJ,GAAA,CAAK/B,CAAAA,CACL,KAAA,CAAM,4BAAA,CACN,QAAQ,aAAA,CACR,IAAA,CAAM+B,CAAAA,CAAS,IAAA,EAAQ,MACvB,YAAA,CAAYA,CAAAA,CAAS,YAAY,CAAA,EAAKpB,EACtC,KAAA,CAAOC,CAAAA,EAAQ,EAAA,CACf,MAAA,CAAQA,CAAAA,EAAQ,EAAA,CAChB,SAAA,CAAWwB,CAAAA,CACX,MAAOC,CAAAA,CACP,eAAA,CAAeJ,CAAAA,CAAS,OAAA,CACxB,wBAAyB,CAAE,MAAA,CAAQA,CAAAA,CAAS,IAAK,EACnD,CAEJ","file":"index.js","sourcesContent":["import { useEffect, useRef } from 'react';\nimport type { RefObject } from 'react';\nimport { wantsFollow } from 'blobbies';\nimport { attachAvatarMotion } from 'blobbies/motion';\nimport type { MotionOptions } from 'blobbies';\nimport type { AvatarAnimate } from 'blobbies';\n\nexport interface UseAvatarMotionOptions extends MotionOptions {\n animate?: AvatarAnimate;\n /** Explicit override; defaults to true when `animate` includes follow. */\n follow?: boolean;\n}\n\n/**\n * Attach cursor-following motion to an SVG produced by Blobbies.\n *\n * The element keeps a single, stable options object which is mutated on every\n * render — so changing smoothing/idle/range never re-registers listeners, and\n * nothing re-renders on pointer move.\n */\nexport function useAvatarMotion(\n ref: RefObject<SVGSVGElement | null>,\n options: UseAvatarMotionOptions = {},\n): void {\n const stable = useRef<UseAvatarMotionOptions>({ ...options });\n // Mutate the same object every render; the motion runtime reads it live.\n Object.assign(stable.current, options);\n\n const enabled = wantsFollow({ animate: options.animate, follow: options.follow });\n\n useEffect(() => {\n const element = ref.current;\n if (!enabled || !element) return undefined;\n return attachAvatarMotion(element, stable.current);\n }, [enabled, options.followTarget, ref]);\n}\n","import { useMemo, useRef } from 'react';\nimport type { CSSProperties, SVGProps } from 'react';\nimport { renderAvatarBody } from 'blobbies';\nimport type { AvatarOptions } from 'blobbies';\nimport { useAvatarMotion } from './useAvatarMotion.js';\n\nexport interface AvatarProps\n extends AvatarOptions,\n Omit<SVGProps<SVGSVGElement>, 'name' | 'className' | 'color' | 'style'> {\n /** The name to derive the avatar from. */\n name: string;\n /** Extra inline styles for the root svg. */\n style?: CSSProperties;\n}\n\n/**\n * Inline SVG avatar. SSR-safe, accessible and deterministic.\n *\n * Cursor-follow only works on inline SVG (i.e. this component), never on an\n * `<img>`; the blink is pure CSS and works in both.\n */\nexport function Avatar(props: AvatarProps): JSX.Element {\n const {\n name,\n size,\n rounded,\n className,\n title,\n palette,\n animate,\n blink,\n blinkInterval,\n follow,\n followRange,\n followTarget,\n smoothing,\n idleTimeout,\n paused,\n respectReducedMotion,\n wink,\n glance,\n surprise,\n style,\n ...svgProps\n } = props;\n\n const options: AvatarOptions = {\n size,\n rounded,\n className,\n title,\n palette,\n animate,\n blink,\n blinkInterval,\n follow,\n followRange,\n followTarget,\n smoothing,\n idleTimeout,\n paused,\n respectReducedMotion,\n wink,\n glance,\n surprise,\n };\n\n // Only recompute the inner markup when body-affecting options change. This\n // keeps the embedded blink animation from being reset on unrelated renders.\n const bodyKey = JSON.stringify([\n name,\n animate,\n blink,\n blinkInterval,\n palette,\n title,\n rounded,\n size,\n className,\n ]);\n const resolved = useMemo(\n () => renderAvatarBody(name, options),\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [bodyKey],\n );\n\n const ref = useRef<SVGSVGElement>(null);\n useAvatarMotion(ref, {\n animate,\n follow,\n followRange,\n followTarget,\n smoothing,\n idleTimeout,\n paused,\n respectReducedMotion,\n wink,\n glance,\n surprise,\n });\n\n const classes = ['bb', resolved.prefix, className].filter(Boolean).join(' ');\n const mergedStyle: CSSProperties | undefined = rounded\n ? { borderRadius: '50%', ...style }\n : style;\n\n return (\n <svg\n {...svgProps}\n ref={ref}\n xmlns=\"http://www.w3.org/2000/svg\"\n viewBox=\"0 0 100 100\"\n role={svgProps.role ?? 'img'}\n aria-label={svgProps['aria-label'] ?? name}\n width={size ?? 48}\n height={size ?? 48}\n className={classes}\n style={mergedStyle}\n data-blobbies={resolved.letters}\n dangerouslySetInnerHTML={{ __html: resolved.body }}\n />\n );\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,59 @@
1
1
  {
2
2
  "name": "@blobbies/react",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.0",
4
+ "description": "React bindings for Blobbies — deterministic, cute SVG avatars with blink and cursor-follow.",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "sideEffects": false,
8
+ "keywords": [
9
+ "avatar",
10
+ "avatars",
11
+ "react",
12
+ "svg",
13
+ "blobbies",
14
+ "profile"
15
+ ],
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/SouravInsights/blobbies.git",
19
+ "directory": "packages/react"
20
+ },
21
+ "main": "./dist/index.cjs",
22
+ "module": "./dist/index.js",
23
+ "types": "./dist/index.d.ts",
24
+ "exports": {
25
+ ".": {
26
+ "types": "./dist/index.d.ts",
27
+ "import": "./dist/index.js",
28
+ "require": "./dist/index.cjs"
29
+ },
30
+ "./package.json": "./package.json"
31
+ },
32
+ "files": [
33
+ "dist"
34
+ ],
35
+ "dependencies": {
36
+ "blobbies": "0.1.0"
37
+ },
38
+ "peerDependencies": {
39
+ "react": ">=18.0.0",
40
+ "react-dom": ">=18.0.0"
41
+ },
42
+ "publishConfig": {
43
+ "access": "public"
44
+ },
45
+ "devDependencies": {
46
+ "@testing-library/react": "^16.1.0",
47
+ "@types/react": "^18.3.18",
48
+ "@types/react-dom": "^18.3.5",
49
+ "jsdom": "^25.0.1",
50
+ "react": "^18.3.1",
51
+ "react-dom": "^18.3.1"
52
+ },
53
+ "scripts": {
54
+ "build": "tsup",
55
+ "test": "vitest run",
56
+ "test:watch": "vitest",
57
+ "typecheck": "tsc --noEmit"
58
+ }
6
59
  }