@blobbies/react 0.2.0 → 0.2.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/README.md +180 -9
- package/dist/index.cjs +42 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -1
- package/dist/index.d.ts +7 -1
- package/dist/index.js +42 -10
- package/dist/index.js.map +1 -1
- package/package.json +10 -5
package/README.md
CHANGED
|
@@ -1,18 +1,26 @@
|
|
|
1
1
|
# @blobbies/react
|
|
2
2
|
|
|
3
|
-
React bindings for [blobbies](https://www.npmjs.com/package/blobbies) —
|
|
4
|
-
deterministic, cute SVG avatars
|
|
3
|
+
**React bindings for [blobbies](https://www.npmjs.com/package/blobbies)** —
|
|
4
|
+
deterministic, cute SVG avatars, a drop-in avatar picker, and the hooks to build
|
|
5
|
+
your own UI on top.
|
|
6
|
+
|
|
7
|
+
<p>
|
|
8
|
+
<a href="https://www.npmjs.com/package/@blobbies/react"><img alt="npm" src="https://img.shields.io/npm/v/@blobbies/react?color=6CC8FF&labelColor=1c1c1c"></a>
|
|
9
|
+
<a href="https://www.npmjs.com/package/blobbies"><img alt="blobbies" src="https://img.shields.io/badge/blobbies-FFD43B?labelColor=1c1c1c"></a>
|
|
10
|
+
<a href="LICENSE"><img alt="MIT" src="https://img.shields.io/badge/license-MIT-B79CFF?labelColor=1c1c1c"></a>
|
|
11
|
+
</p>
|
|
5
12
|
|
|
6
13
|
```tsx
|
|
7
|
-
import { Avatar } from '@blobbies/react';
|
|
14
|
+
import { Avatar, AvatarPicker } from '@blobbies/react';
|
|
8
15
|
|
|
9
16
|
<Avatar name="Sourav Nanda" size={64} animate="all" wink />
|
|
10
|
-
```
|
|
11
17
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
18
|
+
<AvatarPicker
|
|
19
|
+
name="Sourav Nanda"
|
|
20
|
+
defaultValue={user.look}
|
|
21
|
+
onSave={(look) => updateUser({ look })}
|
|
22
|
+
/>
|
|
23
|
+
```
|
|
16
24
|
|
|
17
25
|
## Install
|
|
18
26
|
|
|
@@ -21,10 +29,15 @@ npm i @blobbies/react
|
|
|
21
29
|
```
|
|
22
30
|
|
|
23
31
|
React 18 or newer is a peer dependency. `blobbies` is the only runtime
|
|
24
|
-
dependency.
|
|
32
|
+
dependency. Fully typed, `sideEffects: false`, and safe to render on the server.
|
|
25
33
|
|
|
26
34
|
## `<Avatar>`
|
|
27
35
|
|
|
36
|
+
Inline, SSR-safe SVG with `role="img"` and `aria-label`. The avatar is memoised
|
|
37
|
+
so unrelated re-renders never reset the blink animation, and pointer movement
|
|
38
|
+
never triggers a React render — motion is written straight to CSS variables by
|
|
39
|
+
the shared runtime.
|
|
40
|
+
|
|
28
41
|
Takes every [blobbies option](https://www.npmjs.com/package/blobbies) plus the
|
|
29
42
|
usual SVG props.
|
|
30
43
|
|
|
@@ -32,6 +45,13 @@ usual SVG props.
|
|
|
32
45
|
| --- | --- | --- |
|
|
33
46
|
| `name` | `string` | required |
|
|
34
47
|
| `size` | `number \| string` | `48` |
|
|
48
|
+
| `color` | `string` — any CSS colour, e.g. `COLORS.sky` | seeded |
|
|
49
|
+
| `shape` | `'tall' \| 'wide' \| 'squat' \| 'round' \| 'mid'` | seeded |
|
|
50
|
+
| `expression` | `'smile' \| 'smirk' \| …` | seeded |
|
|
51
|
+
| `blush` | `boolean` | seeded |
|
|
52
|
+
| `tilt` | `number` | seeded |
|
|
53
|
+
| `variant` | `number` | `0` |
|
|
54
|
+
| `palette` | `readonly string[]` | built-in |
|
|
35
55
|
| `animate` | `boolean \| 'blink' \| 'follow' \| 'all'` | `false` |
|
|
36
56
|
| `blinkInterval` | `[min, max]` ms | `[2500, 6000]` |
|
|
37
57
|
| `followRange` | `number` | `6` |
|
|
@@ -42,6 +62,143 @@ usual SVG props.
|
|
|
42
62
|
| `wink` / `glance` / `surprise` | `boolean` | `false` |
|
|
43
63
|
| `rounded` | `boolean` | `false` |
|
|
44
64
|
|
|
65
|
+
```tsx
|
|
66
|
+
<Avatar name="Sourav Nanda" color={COLORS.sky} expression="smirk" shape="round" blush />;
|
|
67
|
+
|
|
68
|
+
// Your brand's colours are just an array.
|
|
69
|
+
<Avatar name="Sourav Nanda" palette={['#0FA3B1', '#FFD166', '#EF476F']} />;
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## `<AvatarPicker>`
|
|
73
|
+
|
|
74
|
+
A ready-made **look map**. Columns are colours, rows are moods, and the map wraps
|
|
75
|
+
in both directions, so it never ends. Every face is a version of the same person
|
|
76
|
+
— the eyes come from `name` and never change.
|
|
77
|
+
|
|
78
|
+
**Drag or swipe** to pan, **trackpad** to glide, **arrow keys** to move.
|
|
79
|
+
Hovering brings a face forward; cells shrink and fade with distance from it, so
|
|
80
|
+
the edges dissolve without ever clipping the chosen face.
|
|
81
|
+
|
|
82
|
+
The map sizes its own grid to whatever box it is given — a full settings page, a
|
|
83
|
+
380px popover, or a phone dialog — so it never clips its edge faces.
|
|
84
|
+
|
|
85
|
+
```tsx
|
|
86
|
+
import { useState } from 'react';
|
|
87
|
+
import { Avatar, AvatarPicker } from '@blobbies/react';
|
|
88
|
+
import type { AvatarOptions } from '@blobbies/react';
|
|
89
|
+
|
|
90
|
+
function Profile() {
|
|
91
|
+
const [saved, setSaved] = useState<AvatarOptions | null>(null);
|
|
92
|
+
const [open, setOpen] = useState(false);
|
|
93
|
+
|
|
94
|
+
return (
|
|
95
|
+
<>
|
|
96
|
+
<button onClick={() => setOpen(true)}>
|
|
97
|
+
<Avatar name={user.name} {...saved} size={40} />
|
|
98
|
+
</button>
|
|
99
|
+
|
|
100
|
+
{open && (
|
|
101
|
+
<AvatarPicker
|
|
102
|
+
name={user.name}
|
|
103
|
+
defaultValue={saved ?? undefined}
|
|
104
|
+
onSave={(look) => {
|
|
105
|
+
setSaved(look);
|
|
106
|
+
setOpen(false);
|
|
107
|
+
}}
|
|
108
|
+
onCancel={() => setOpen(false)}
|
|
109
|
+
/>
|
|
110
|
+
)}
|
|
111
|
+
</>
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
The saved look is the same props you pass to `<Avatar>`.
|
|
117
|
+
|
|
118
|
+
| Prop | Default | What it does |
|
|
119
|
+
| --- | --- | --- |
|
|
120
|
+
| `name` | required | The person's name — the eyes every look shares. |
|
|
121
|
+
| `defaultValue` | seeded | The look to open on (`AvatarOptions`). Read once. |
|
|
122
|
+
| `palette` | `PALETTE` | The colours the map offers — pass your own. |
|
|
123
|
+
| `onChange` | – | Called with the current look as it changes. |
|
|
124
|
+
| `onSave` | – | Called with the look when Save is pressed. |
|
|
125
|
+
| `onCancel` | – | Shows Cancel and calls this. |
|
|
126
|
+
| `title` / `description` | `'Choose an avatar'` / … | Header copy. Pass `''` to hide. |
|
|
127
|
+
| `saveLabel` | `'Save'` | Save button label. |
|
|
128
|
+
| `spotlight` | `true` | Start with the depth-of-field spotlight on. The picker also ships a Spotlight toggle. |
|
|
129
|
+
| `className` | – | Added to the root. |
|
|
130
|
+
| `unstyled` | `false` | Skip the panel styles; style the parts yourself. |
|
|
131
|
+
|
|
132
|
+
### Theme it
|
|
133
|
+
|
|
134
|
+
The panel is themed entirely with CSS variables. Set them on the root (or any
|
|
135
|
+
ancestor) and the picker follows your product.
|
|
136
|
+
|
|
137
|
+
| Variable | |
|
|
138
|
+
| --- | --- |
|
|
139
|
+
| `--bb-picker-panel` | Surface background |
|
|
140
|
+
| `--bb-picker-ink` | Primary text and marks |
|
|
141
|
+
| `--bb-picker-muted` | Secondary text |
|
|
142
|
+
| `--bb-picker-line` | Borders and dividers |
|
|
143
|
+
| `--bb-picker-accent` | Save button background |
|
|
144
|
+
| `--bb-picker-accent-ink` | Save button text |
|
|
145
|
+
| `--bb-picker-radius` | Panel corner radius |
|
|
146
|
+
| `--bb-picker-shadow` | Panel shadow |
|
|
147
|
+
| `--bb-picker-spring` | The spring curve for pops |
|
|
148
|
+
| `--bb-picker-fade` | The short curve for colour |
|
|
149
|
+
|
|
150
|
+
```css
|
|
151
|
+
.brand-picker {
|
|
152
|
+
--bb-picker-panel: #101014;
|
|
153
|
+
--bb-picker-accent: #ffd43b;
|
|
154
|
+
--bb-picker-accent-ink: #1c1c1c;
|
|
155
|
+
}
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
### Rebuild the layout
|
|
159
|
+
|
|
160
|
+
The preset is only a composition of parts. Import the parts, keep the state, and
|
|
161
|
+
lay them out however your product needs. Every part carries a `data-part`
|
|
162
|
+
attribute (`root`, `header`, `title`, `description`, `surface`, `preview`,
|
|
163
|
+
`mood`, `blush`, `spotlight`, `reset`, `cancel`, `save`, `footer`) for your own
|
|
164
|
+
CSS hooks, and `unstyled` skips the bundled styles entirely.
|
|
165
|
+
|
|
166
|
+
```tsx
|
|
167
|
+
import {
|
|
168
|
+
AvatarPickerRoot,
|
|
169
|
+
AvatarPickerSurface,
|
|
170
|
+
AvatarPickerPreview,
|
|
171
|
+
AvatarPickerMood,
|
|
172
|
+
AvatarPickerBlush,
|
|
173
|
+
AvatarPickerSpotlight,
|
|
174
|
+
AvatarPickerReset,
|
|
175
|
+
AvatarPickerSave,
|
|
176
|
+
AvatarPickerCancel,
|
|
177
|
+
useAvatarPicker,
|
|
178
|
+
} from '@blobbies/react';
|
|
179
|
+
|
|
180
|
+
<AvatarPickerRoot name={user.name} defaultValue={user.look} onSave={save} unstyled>
|
|
181
|
+
<AvatarPickerPreview size={72} />
|
|
182
|
+
<AvatarPickerSurface />
|
|
183
|
+
<AvatarPickerMood />
|
|
184
|
+
<AvatarPickerBlush />
|
|
185
|
+
<AvatarPickerSpotlight />
|
|
186
|
+
<AvatarPickerReset />
|
|
187
|
+
<AvatarPickerSave>Keep it</AvatarPickerSave>
|
|
188
|
+
<AvatarPickerCancel />
|
|
189
|
+
</AvatarPickerRoot>;
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
`useAvatarPicker()` exposes the state when you want to render your own controls:
|
|
193
|
+
|
|
194
|
+
```ts
|
|
195
|
+
const {
|
|
196
|
+
value, changed, blush, spotlight, palette,
|
|
197
|
+
expressionName, nextExpression, previousExpression,
|
|
198
|
+
toggleBlush, toggleSpotlight, reset, save, cancel, hasCancel,
|
|
199
|
+
} = useAvatarPicker();
|
|
200
|
+
```
|
|
201
|
+
|
|
45
202
|
## `useAvatarMotion`
|
|
46
203
|
|
|
47
204
|
Bring your own SVG and attach the same runtime:
|
|
@@ -57,6 +214,20 @@ function Mine() {
|
|
|
57
214
|
}
|
|
58
215
|
```
|
|
59
216
|
|
|
217
|
+
It keeps one stable options object and only re-attaches when the follow target or
|
|
218
|
+
enabled state changes — pointer movement never triggers a re-render.
|
|
219
|
+
|
|
220
|
+
## Exports
|
|
221
|
+
|
|
222
|
+
| Export | |
|
|
223
|
+
| --- | --- |
|
|
224
|
+
| `<Avatar>`, `AvatarProps` | Inline, SSR-safe SVG. |
|
|
225
|
+
| `<AvatarPicker>`, `AvatarPickerProps` | The preset look map. |
|
|
226
|
+
| `AvatarPickerRoot`, `AvatarPickerSurface`, `AvatarPickerPreview`, `AvatarPickerMood`, `AvatarPickerBlush`, `AvatarPickerSpotlight`, `AvatarPickerReset`, `AvatarPickerSave`, `AvatarPickerCancel` | The composable parts. |
|
|
227
|
+
| `useAvatarPicker`, `AvatarPickerState` | Picker state for custom controls. |
|
|
228
|
+
| `useAvatarMotion`, `UseAvatarMotionOptions` | The motion hook. |
|
|
229
|
+
| `COLORS`, `PALETTE`, `EXPRESSIONS`, `SHAPES`, `EXPRESSION_NAMES`, `EXPRESSION_COUNT`, `SHAPE_COUNT` | Re-exported for building custom UIs. |
|
|
230
|
+
|
|
60
231
|
## Licence
|
|
61
232
|
|
|
62
233
|
MIT
|
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
'use strict';var react=require('react'),blobbies=require('blobbies'),motion=require('blobbies/motion'),jsxRuntime=require('react/jsx-runtime');function
|
|
1
|
+
'use strict';var react=require('react'),blobbies=require('blobbies'),motion=require('blobbies/motion'),jsxRuntime=require('react/jsx-runtime');function ze(r,n={}){let o=react.useRef({...n});Object.assign(o.current,n);let p=blobbies.wantsFollow({animate:n.animate,follow:n.follow});react.useEffect(()=>{let u=r.current;if(!(!p||!u))return motion.attachAvatarMotion(u,o.current)},[p,n.followTarget,r]);}function Se(r){let{name:n,size:o,rounded:p,className:u,title:d,palette:b,variant:f,color:C,shape:ie,expression:Q,blush:I,tilt:Z,animate:k,blink:X,blinkInterval:ee,follow:F,followRange:re,followTarget:ae,smoothing:w,idleTimeout:z,paused:m,respectReducedMotion:y,wink:Y,glance:R,surprise:_,style:ue,...G}=r,ce={size:o,rounded:p,className:u,title:d,palette:b,variant:f,color:C,shape:ie,expression:Q,blush:I,tilt:Z,animate:k,blink:X,blinkInterval:ee,follow:F,followRange:re,followTarget:ae,smoothing:w,idleTimeout:z,paused:m,respectReducedMotion:y,wink:Y,glance:R,surprise:_},be=JSON.stringify([n,k,X,ee,b,f,C,ie,Q,I,Z,d,p,o,u]),de=react.useMemo(()=>blobbies.renderAvatarBody(n,ce),[be]),he=react.useRef(null);ze(he,{animate:k,follow:F,followRange:re,followTarget:ae,smoothing:w,idleTimeout:z,paused:m,respectReducedMotion:y,wink:Y,glance:R,surprise:_});let L=["bb",de.prefix,u].filter(Boolean).join(" "),se=p?{borderRadius:"50%",...ue}:ue;return jsxRuntime.jsx("svg",{...G,ref:he,xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 100 100",role:G.role??"img","aria-label":G["aria-label"]??n,width:o??48,height:o??48,className:L,style:se,"data-blobbies":de.letters,dangerouslySetInnerHTML:{__html:de.body}})}var sr="blobbies-picker-styles",Wr=`
|
|
2
2
|
.bb-picker {
|
|
3
3
|
--bb-picker-panel: #ffffff;
|
|
4
4
|
--bb-picker-ink: #18181b;
|
|
@@ -24,9 +24,17 @@
|
|
|
24
24
|
container-type: inline-size;
|
|
25
25
|
font-size: 14px;
|
|
26
26
|
line-height: 1.5;
|
|
27
|
+
-webkit-tap-highlight-color: transparent;
|
|
27
28
|
}
|
|
28
29
|
.bb-picker * { box-sizing: border-box; }
|
|
29
|
-
.bb-picker button {
|
|
30
|
+
.bb-picker button {
|
|
31
|
+
font: inherit;
|
|
32
|
+
cursor: pointer;
|
|
33
|
+
touch-action: manipulation;
|
|
34
|
+
user-select: none;
|
|
35
|
+
-webkit-user-select: none;
|
|
36
|
+
-webkit-touch-callout: none;
|
|
37
|
+
}
|
|
30
38
|
.bb-picker h3 { margin: 0; font-size: 16px; font-weight: 600; letter-spacing: -0.02em; }
|
|
31
39
|
.bb-picker p { margin: 0; }
|
|
32
40
|
|
|
@@ -42,6 +50,7 @@
|
|
|
42
50
|
touch-action: none;
|
|
43
51
|
user-select: none;
|
|
44
52
|
-webkit-user-select: none;
|
|
53
|
+
-webkit-touch-callout: none;
|
|
45
54
|
outline: none;
|
|
46
55
|
}
|
|
47
56
|
.bb-picker-surface[data-dragging] { cursor: grabbing; }
|
|
@@ -127,12 +136,15 @@
|
|
|
127
136
|
transition: background-color var(--bb-picker-fade), color var(--bb-picker-fade), transform 160ms var(--bb-picker-ease-out);
|
|
128
137
|
}
|
|
129
138
|
.bb-picker-step:active { transform: scale(0.94); }
|
|
130
|
-
|
|
139
|
+
@media (hover: hover) and (pointer: fine) {
|
|
140
|
+
.bb-picker-step:hover { background: color-mix(in oklab, var(--bb-picker-ink) 8%, transparent); color: var(--bb-picker-ink); }
|
|
141
|
+
}
|
|
131
142
|
.bb-picker-step:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--bb-picker-panel), 0 0 0 3.5px var(--bb-picker-ink); }
|
|
132
143
|
|
|
133
144
|
.bb-picker-foot {
|
|
134
145
|
display: flex;
|
|
135
146
|
align-items: center;
|
|
147
|
+
flex-wrap: wrap;
|
|
136
148
|
gap: 8px;
|
|
137
149
|
padding: 12px 16px;
|
|
138
150
|
border-top: 1px solid var(--bb-picker-line);
|
|
@@ -155,10 +167,14 @@
|
|
|
155
167
|
transition: background-color var(--bb-picker-fade), transform 160ms var(--bb-picker-ease-out);
|
|
156
168
|
}
|
|
157
169
|
.bb-picker-btn:active { transform: scale(0.97); }
|
|
158
|
-
|
|
170
|
+
@media (hover: hover) and (pointer: fine) {
|
|
171
|
+
.bb-picker-btn:hover { background: color-mix(in oklab, var(--bb-picker-ink) 14%, transparent); }
|
|
172
|
+
}
|
|
159
173
|
.bb-picker-btn:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--bb-picker-panel), 0 0 0 3.5px var(--bb-picker-ink); }
|
|
160
174
|
.bb-picker-primary { background: var(--bb-picker-accent); color: var(--bb-picker-accent-ink); }
|
|
161
|
-
|
|
175
|
+
@media (hover: hover) and (pointer: fine) {
|
|
176
|
+
.bb-picker-primary:hover { background: color-mix(in oklab, var(--bb-picker-accent) 86%, var(--bb-picker-panel)); }
|
|
177
|
+
}
|
|
162
178
|
|
|
163
179
|
.bb-picker-reset {
|
|
164
180
|
height: 28px;
|
|
@@ -172,7 +188,11 @@
|
|
|
172
188
|
transition: transform 160ms var(--bb-picker-ease-out);
|
|
173
189
|
}
|
|
174
190
|
.bb-picker-reset:active { transform: scale(0.97); }
|
|
175
|
-
|
|
191
|
+
@media (hover: hover) and (pointer: fine) {
|
|
192
|
+
.bb-picker-reset:hover { color: var(--bb-picker-ink); }
|
|
193
|
+
}
|
|
194
|
+
/* Hidden, not removed: the reset appears on the first change, and taking it
|
|
195
|
+
out of the flow would reflow the footer under the finger that just chose. */
|
|
176
196
|
.bb-picker-reset:disabled { visibility: hidden; pointer-events: none; }
|
|
177
197
|
|
|
178
198
|
.bb-picker-blush,
|
|
@@ -201,8 +221,10 @@
|
|
|
201
221
|
border: 1.5px solid currentColor;
|
|
202
222
|
transition: background-color var(--bb-picker-fade), border-color var(--bb-picker-fade);
|
|
203
223
|
}
|
|
204
|
-
|
|
205
|
-
.bb-picker-
|
|
224
|
+
@media (hover: hover) and (pointer: fine) {
|
|
225
|
+
.bb-picker-blush:hover,
|
|
226
|
+
.bb-picker-spotlight:hover { border-color: var(--bb-picker-muted); color: var(--bb-picker-ink); }
|
|
227
|
+
}
|
|
206
228
|
.bb-picker-blush[data-on],
|
|
207
229
|
.bb-picker-spotlight[data-on] { color: var(--bb-picker-ink); border-color: color-mix(in oklab, var(--bb-picker-ink) 28%, transparent); }
|
|
208
230
|
.bb-picker-blush[data-on]::before,
|
|
@@ -210,10 +232,20 @@
|
|
|
210
232
|
|
|
211
233
|
@keyframes bb-picker-mood-in { from { opacity: 0; translate: 0 3px; } }
|
|
212
234
|
|
|
213
|
-
@container (max-width:
|
|
235
|
+
@container (max-width: 440px) {
|
|
214
236
|
.bb-picker-head { padding: 14px 14px 8px; }
|
|
215
237
|
.bb-picker-mood { padding: 6px 14px 8px; }
|
|
216
238
|
.bb-picker-foot { padding: 10px 12px; }
|
|
239
|
+
/* The grower becomes a full-width break, so Cancel and Save share the last
|
|
240
|
+
row instead of being pushed past the edge of a phone-sized panel. */
|
|
241
|
+
.bb-picker-foot .bb-picker-grow { flex-basis: 100%; height: 0; }
|
|
242
|
+
.bb-picker-foot .bb-picker-btn { flex: 1 1 0; justify-content: center; }
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
@container (max-width: 360px) {
|
|
246
|
+
.bb-picker-foot { gap: 6px; }
|
|
247
|
+
.bb-picker-blush,
|
|
248
|
+
.bb-picker-spotlight { padding: 0 9px; }
|
|
217
249
|
}
|
|
218
250
|
|
|
219
251
|
@media (prefers-reduced-motion: reduce) {
|
|
@@ -221,5 +253,5 @@
|
|
|
221
253
|
.bb-picker-world { will-change: auto; }
|
|
222
254
|
.bb-picker-cell, .bb-picker-lift, .bb-picker-ring, .bb-picker-mood-name { transition: none; animation: none; }
|
|
223
255
|
}
|
|
224
|
-
`;function nr(){react.useInsertionEffect(()=>{if(typeof document>"u"||document.getElementById(tr))return;let t=document.createElement("style");t.id=tr,t.textContent=zr,document.head.prepend(t);},[]);}var ie=5,Ee=3,j=2,T=1,Yr=ie+2,Gr=Ee+2,be=8,Wr=48,Kr=78,qr=2.6,ir=3.2,Jr=6,pe=be,W=(t,o)=>(Math.trunc(t)%o+o)%o,ue=(t,o,a)=>Math.min(a,Math.max(o,t)),cr=react.createContext(null);function _(){let t=react.useContext(cr);if(!t)throw new Error("AvatarPicker parts must be used inside <AvatarPickerRoot>.");return t}function Qr(){let{map:t,...o}=_();return o}function ar({dir:t}){return jsxRuntime.jsx("svg",{viewBox:"0 0 12 12",width:"10",height:"10",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:jsxRuntime.jsx("path",{d:t==="l"?"M7.5 2.5 4 6l3.5 3.5":"M4.5 2.5 8 6l-3.5 3.5"})})}function Zr(t){return t.ctrlKey||t.deltaMode!==0?false:t.deltaX!==0||Math.abs(t.deltaY)<40||!Number.isInteger(t.deltaY)}function sr(t){let{name:o,defaultValue:a,onChange:l,onSave:u,onCancel:d,palette:b=blobbies.PALETTE,spotlight:f=true,unstyled:S=false,className:K,style:U,children:B,...q}=t;nr();let k=react.useRef({color:(()=>{let e=a?.color?b.indexOf(a.color):j;return e>=0?e:j})(),expression:(()=>{let e=a?.expression?blobbies.EXPRESSIONS.indexOf(a.expression):T;return e>=0?e:T})(),blush:a?.blush??true}),[x,J]=react.useState(68),[D,V]=react.useState(k.current.blush??true),[Q,P]=react.useState(null),[v,H]=react.useState(f),[A,ae]=react.useState(false),[C,F]=react.useState(null),[ce,Y]=react.useState(false),[Z,fe]=react.useState(false),[se,ke]=react.useState(0),le=x+be,Se=ie*x+(ie-1)*be,vr=Ee*x+(Ee-1)*be,mr=Se+pe*2,xr=vr+pe*2,I=react.useRef(k.current.color-j),M=react.useRef(k.current.expression-T),E=react.useRef({i:j,j:T}),i=react.useRef({x:0,y:0}),R=react.useRef({x:0,y:0}),w=react.useRef("idle"),y=react.useRef(0),ve=react.useRef(false),ee=react.useRef(0),me=react.useRef(0),Xe=react.useRef(0),re=react.useRef(false),z=react.useRef(le);z.current=le;let $e=react.useRef(null),Ce=react.useRef(null),xe=react.useRef(null),Re=react.useRef(new Map),te=react.useRef({x:0,y:0}),he=react.useRef(typeof window<"u"&&typeof window.matchMedia=="function"?window.matchMedia("(prefers-reduced-motion: reduce)").matches:false),Ne=react.useRef(C),_e=react.useRef(A),Ue=react.useRef(Z),Ve=react.useRef(x),Oe=react.useRef(false),ge=react.useRef(false),Ye=react.useRef(v);Ye.current=v,Ne.current=C,_e.current=A,Ue.current=Z,Ve.current=x;let X=()=>ke(e=>e+1),Le=()=>{let e=z.current,n=Ve.current,r=Ne.current&&!_e.current&&!re.current&&!Ue.current?Ne.current:null;if(!r){if(!Oe.current&&ge.current)return;Oe.current=false,ge.current=true;for(let[g,O]of Re.current){let[G,oe]=g.split(":").map(Number);O.style.transform=`translate3d(${(G*e).toFixed(1)}px, ${(oe*e).toFixed(1)}px, 0)`,O.style.opacity="1",O.style.filter="";}return}Oe.current=true,ge.current=true;let p=(r.i+.5)*e+i.current.x,h=(r.j+.5)*e+i.current.y;for(let[g,O]of Re.current){let[G,oe]=g.split(":").map(Number),Te=G*e+i.current.x+n/2,Be=oe*e+i.current.y+n/2,we=Math.hypot(Te-p,Be-h)/e,De=Math.min(1,we/qr),qe=1-De*De,Je=0,Qe=0;if(we>=.001){let er=Math.hypot(Te-p,Be-h)||1,rr=he.current?0:qe*Jr;Je=(Te-p)/er*rr,Qe=(Be-h)/er*rr;}let Nr=we<.001?1:.7+.3*qe,Ze=Ye.current&&we>=.001?Math.min(ir,De*ir):0;O.style.transform=`translate3d(${(G*e+Je).toFixed(1)}px, ${(oe*e+Qe).toFixed(1)}px, 0)`,O.style.opacity=Nr.toFixed(3),O.style.filter=Ze>.06?`blur(${Ze.toFixed(2)}px)`:"";}},Ge=(e,n)=>{let r=xe.current?.getBoundingClientRect();if(!r)return null;let p=z.current,h=Math.floor((e-r.left-pe-i.current.x)/p),g=Math.floor((n-r.top-pe-i.current.y)/p);return h>=-1&&h<=ie&&g>=-1&&g<=Ee?{i:h,j:g}:null},hr=e=>{let n=Ce.current;n&&(n.style.transform=`translate3d(${i.current.x}px, ${i.current.y+e}px, 0)`),Le();},m=()=>{let e=Ce.current;e&&(e.style.transform=`translate3d(${i.current.x}px, ${i.current.y}px, 0)`);let n=z.current,r=i.current.x<n/2?j:j-1,p=i.current.y<n/2?T:T-1;(r!==E.current.i||p!==E.current.j)&&(E.current={i:r,j:p},X()),Le();},ne=()=>{let e=z.current,n=false,r=Math.floor(i.current.x/e),p=Math.floor(i.current.y/e);r!==0&&(I.current-=r,i.current.x-=r*e,n=true),p!==0&&(M.current-=p,i.current.y-=p*e,n=true),n&&X();},ye=()=>{y.current||(y.current=requestAnimationFrame(function(){y.current=0;let n=z.current;if(w.current==="glide")i.current.x+=R.current.x,i.current.y+=R.current.y,R.current.x*=.9,R.current.y*=.9,Math.abs(R.current.x)<.4&&Math.abs(R.current.y)<.4&&(w.current="snap"),ne(),m(),ye();else if(w.current==="snap"){let r=i.current.x<n/2?0:n,p=i.current.y<n/2?0:n;Math.abs(r-i.current.x)<.4&&Math.abs(p-i.current.y)<.4?(i.current={x:r,y:p},ne(),m(),w.current="idle",fe(false)):(i.current.x+=(r-i.current.x)*.22,i.current.y+=(p-i.current.y)*.22,ne(),m(),ye());}}));},Pe=e=>{if(re.current)return;if(P(null),he.current){M.current+=e,X(),m();return}re.current=true,Xe.current=e,Y(true);let n=z.current,r=-e*n,p=performance.now(),h=300,g=O=>{let G=Math.min(1,(O-p)/h),oe=1-Math.pow(1-G,3);me.current=r*oe,hr(me.current),G<1?ee.current=requestAnimationFrame(g):(M.current+=e,me.current=0,ee.current=0,re.current=false,Y(false),X(),m());};ee.current=requestAnimationFrame(g);};react.useLayoutEffect(()=>{let e=$e.current;if(!e)return;let n=()=>{let p=e.clientWidth,h=ue(Math.floor((p-32-pe*2-(ie-1)*be)/ie),Wr,Kr);J(g=>g===h?g:h);};if(n(),typeof ResizeObserver>"u")return;let r=new ResizeObserver(n);return r.observe(e),()=>r.disconnect()},[]),react.useLayoutEffect(()=>{i.current={x:0,y:0},ge.current=false,w.current="idle",y.current&&(cancelAnimationFrame(y.current),y.current=0),m();},[x]),react.useLayoutEffect(()=>{Le();}),react.useEffect(()=>{let e=xe.current;if(!e)return;let n=r=>{if(Zr(r)){if(r.preventDefault(),he.current){r.deltaX&&(I.current+=r.deltaX>0?1:-1),r.deltaY&&(M.current+=r.deltaY>0?1:-1),X(),m();return}y.current&&(cancelAnimationFrame(y.current),y.current=0),i.current.x+=r.deltaX,i.current.y+=r.deltaY,R.current={x:ue(r.deltaX*.8,-40,40),y:ue(r.deltaY*.8,-40,40)},ne(),m(),w.current="glide",ye();}};return e.addEventListener("wheel",n,{passive:false}),()=>e.removeEventListener("wheel",n)},[]);let gr=e=>{if(e.button===0){try{xe.current?.setPointerCapture(e.pointerId);}catch{}y.current&&(cancelAnimationFrame(y.current),y.current=0),re.current&&(ee.current&&cancelAnimationFrame(ee.current),M.current+=Xe.current,me.current=0,ee.current=0,re.current=false,Y(false),m()),w.current="drag",ve.current=false,ae(true),F(null),te.current={x:e.clientX,y:e.clientY},R.current={x:0,y:0};}},yr=e=>{if(w.current==="drag"){let r=e.clientX-te.current.x,p=e.clientY-te.current.y;Math.abs(r)+Math.abs(p)>2&&(ve.current||P(null),ve.current=true),te.current={x:e.clientX,y:e.clientY},i.current.x+=r,i.current.y+=p,R.current={x:ue(r*.85,-40,40),y:ue(p*.85,-40,40)},ne(),m();return}let n=Ge(e.clientX,e.clientY);F(r=>n&&r&&r.i===n.i&&r.j===n.j?r:n);},We=()=>{if(w.current==="drag"){if(ae(false),!ve.current){let e=Ge(te.current.x,te.current.y);e&&P({color:W(I.current+e.i,b.length),expression:W(M.current+e.j,blobbies.EXPRESSION_COUNT)}),F(null);}if(he.current){let e=z.current;i.current.x=i.current.x<e/2?0:e,i.current.y=i.current.y<e/2?0:e,ne(),m(),w.current="idle";return}w.current="glide",fe(true),ye();}},Pr=e=>{switch(e.key){case "ArrowRight":e.preventDefault(),P(null),I.current+=1,X(),m();break;case "ArrowLeft":e.preventDefault(),P(null),I.current-=1,X(),m();break;case "ArrowDown":e.preventDefault(),Pe(1);break;case "ArrowUp":e.preventDefault(),Pe(-1);break;}},Ke=react.useMemo(()=>{let e=[];for(let n=-1;n<Gr-1;n++)for(let r=-1;r<Yr-1;r++)e.push({key:`${r}:${n}`,i:r,j:n,color:W(I.current+r,b.length),expression:W(M.current+n,blobbies.EXPRESSION_COUNT)});return e},[se,b.length]);C??{i:E.current.i,j:E.current.j};let $=Q??{color:W(I.current+E.current.i,b.length),expression:W(M.current+E.current.j,blobbies.EXPRESSION_COUNT)},N={color:b[$.color],expression:blobbies.EXPRESSIONS[$.expression],blush:D},je=Ke.find(e=>e.color===$.color&&e.expression===$.expression),Ar=je?{i:je.i,j:je.j}:{i:E.current.i,j:E.current.j},wr=A||ce||Z?null:C??Ar,Mr=$.color!==k.current.color||$.expression!==k.current.expression||D!==k.current.blush,Ae=react.useRef(null);react.useEffect(()=>{let e=`${N.color}.${N.expression}.${N.blush}`;if(Ae.current===null){Ae.current=e;return}Ae.current!==e&&(Ae.current=e,l?.(N));},[N.color,N.expression,N.blush]);let Er=()=>{P(null),I.current=(k.current.color??j)-j,M.current=(k.current.expression??T)-T,V(k.current.blush??true),i.current={x:0,y:0},E.current={i:j,j:T},F(null),X(),m();},Sr={stageRef:xe,worldRef:Ce,cellEls:Re,cell:x,pitch:le,vw:mr,vh:xr,cells:Ke,focus:wr,selected:$,dragging:A,moving:A||ce||Z,handlers:{onPointerDown:gr,onPointerMove:yr,onPointerUp:We,onPointerCancel:We,onPointerLeave:()=>F(null),onKeyDown:Pr}},Cr={name:o,value:N,changed:Mr,blush:D,expressionName:blobbies.EXPRESSION_NAMES[C?W(M.current+C.j,blobbies.EXPRESSION_COUNT):$.expression],nextExpression:()=>Pe(1),previousExpression:()=>Pe(-1),toggleBlush:()=>V(e=>!e),spotlight:v,toggleSpotlight:()=>H(e=>!e),palette:b,reset:Er,save:()=>u?.(N),cancel:()=>d?.(),hasCancel:!!d,map:Sr},Rr=[S?"":"bb-picker",K].filter(Boolean).join(" ");return jsxRuntime.jsx(cr.Provider,{value:Cr,children:jsxRuntime.jsx("div",{...q,ref:$e,className:Rr||void 0,"data-part":"root",style:U,children:B})})}function lr(t){let{className:o,...a}=t,{name:l,blush:u,value:d,palette:b,map:f}=_(),{stageRef:S,worldRef:K,cellEls:U,cell:B,cells:q,focus:k,selected:x,dragging:J,moving:D,handlers:V,vw:Q,vh:P}=f;return jsxRuntime.jsx("div",{...a,...V,ref:S,role:"group",tabIndex:0,"aria-label":"A map of looks. Drag, swipe or use the arrow keys.","data-part":"surface","data-dragging":J?"1":void 0,className:["bb-picker-surface",o].filter(Boolean).join(" "),style:{width:Q,height:P},children:jsxRuntime.jsx("div",{className:"bb-picker-viewport",children:jsxRuntime.jsx("div",{className:"bb-picker-world",ref:K,children:q.map(v=>{let H=!!k&&v.i===k.i&&v.j===k.j;return jsxRuntime.jsxs("div",{ref:A=>{A?U.current?.set(v.key,A):U.current?.delete(v.key);},className:"bb-picker-cell","data-focus":H?"1":void 0,style:{width:B,height:B,zIndex:H?6:1},"aria-hidden":"true",children:[jsxRuntime.jsx("span",{className:"bb-picker-lift",children:jsxRuntime.jsx(Fe,{name:l,color:b[v.color],expression:blobbies.EXPRESSIONS[v.expression],blush:u,size:B,animate:"all",follow:H,blinkInterval:[4e3,1e4]})}),jsxRuntime.jsx("span",{className:"bb-picker-ring","aria-hidden":"true"}),jsxRuntime.jsx("span",{className:"bb-picker-check","data-on":!D&&v.color===x.color&&v.expression===x.expression?"1":void 0,"aria-hidden":"true",children:jsxRuntime.jsx("svg",{viewBox:"0 0 12 12",width:"10",height:"10",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:jsxRuntime.jsx("path",{d:"M2.5 6.2 4.8 8.5 9.5 3.5"})})})]},v.key)})})})})}function pr(t){let{className:o,...a}=t,{expressionName:l,previousExpression:u,nextExpression:d}=_();return jsxRuntime.jsxs("div",{...a,className:["bb-picker-mood",o].filter(Boolean).join(" "),"data-part":"mood",children:[jsxRuntime.jsx("button",{type:"button",className:"bb-picker-step",onClick:u,"aria-label":"Previous expression",children:jsxRuntime.jsx(ar,{dir:"l"})}),jsxRuntime.jsx("span",{className:"bb-picker-mood-name","aria-live":"polite",children:l},l),jsxRuntime.jsx("button",{type:"button",className:"bb-picker-step",onClick:d,"aria-label":"Next expression",children:jsxRuntime.jsx(ar,{dir:"r"})})]})}function ur(t){let{className:o,children:a,onClick:l,...u}=t,{blush:d,toggleBlush:b}=_();return jsxRuntime.jsx("button",{type:"button",...u,className:["bb-picker-blush",o].filter(Boolean).join(" "),"data-part":"blush","data-on":d?"1":void 0,"aria-pressed":d,onClick:f=>{l?.(f),f.defaultPrevented||b();},children:a??"Blush"})}function br(t){let{className:o,children:a,onClick:l,...u}=t,{spotlight:d,toggleSpotlight:b}=_();return jsxRuntime.jsx("button",{type:"button",...u,className:["bb-picker-spotlight",o].filter(Boolean).join(" "),"data-part":"spotlight","data-on":d?"1":void 0,"aria-pressed":d,onClick:f=>{l?.(f),f.defaultPrevented||b();},children:a??"Spotlight"})}function dr(t){let{className:o,children:a,onClick:l,disabled:u,...d}=t,{changed:b,reset:f}=_();return jsxRuntime.jsx("button",{type:"button",...d,className:["bb-picker-reset",o].filter(Boolean).join(" "),"data-part":"reset",disabled:u||!b,onClick:S=>{l?.(S),S.defaultPrevented||f();},children:a??"Reset"})}function fr(t){let{className:o,children:a,onClick:l,...u}=t,{save:d}=_();return jsxRuntime.jsx("button",{type:"button",...u,className:["bb-picker-btn","bb-picker-primary",o].filter(Boolean).join(" "),"data-part":"save",onClick:b=>{l?.(b),b.defaultPrevented||d();},children:a??"Save"})}function kr(t){let{className:o,children:a,onClick:l,...u}=t,{cancel:d,hasCancel:b}=_();return b?jsxRuntime.jsx("button",{type:"button",...u,className:["bb-picker-btn",o].filter(Boolean).join(" "),"data-part":"cancel",onClick:f=>{l?.(f),f.defaultPrevented||d();},children:a??"Cancel"}):null}function et(t){let{title:o="Choose an avatar",description:a="Drag across for colour, down for mood, then keep one.",saveLabel:l="Save",onCancel:u,...d}=t;return jsxRuntime.jsxs(sr,{...d,onCancel:u,children:[(o||a)&&jsxRuntime.jsxs("div",{className:"bb-picker-head","data-part":"header",children:[o&&jsxRuntime.jsx("h3",{"data-part":"title",children:o}),a&&jsxRuntime.jsx("p",{"data-part":"description",children:a})]}),jsxRuntime.jsx(lr,{}),jsxRuntime.jsx(pr,{}),jsxRuntime.jsxs("div",{className:"bb-picker-foot","data-part":"footer",children:[jsxRuntime.jsx(ur,{}),jsxRuntime.jsx(br,{}),jsxRuntime.jsx(dr,{}),jsxRuntime.jsx("span",{className:"bb-picker-grow"}),jsxRuntime.jsx(kr,{}),jsxRuntime.jsx(fr,{children:l})]})]})}Object.defineProperty(exports,"COLORS",{enumerable:true,get:function(){return blobbies.COLORS}});Object.defineProperty(exports,"EXPRESSIONS",{enumerable:true,get:function(){return blobbies.EXPRESSIONS}});Object.defineProperty(exports,"EXPRESSION_COUNT",{enumerable:true,get:function(){return blobbies.EXPRESSION_COUNT}});Object.defineProperty(exports,"EXPRESSION_NAMES",{enumerable:true,get:function(){return blobbies.EXPRESSION_NAMES}});Object.defineProperty(exports,"PALETTE",{enumerable:true,get:function(){return blobbies.PALETTE}});Object.defineProperty(exports,"SHAPES",{enumerable:true,get:function(){return blobbies.SHAPES}});Object.defineProperty(exports,"SHAPE_COUNT",{enumerable:true,get:function(){return blobbies.SHAPE_COUNT}});exports.Avatar=Fe;exports.AvatarPicker=et;exports.AvatarPickerBlush=ur;exports.AvatarPickerCancel=kr;exports.AvatarPickerMood=pr;exports.AvatarPickerReset=dr;exports.AvatarPickerRoot=sr;exports.AvatarPickerSave=fr;exports.AvatarPickerSpotlight=br;exports.AvatarPickerSurface=lr;exports.useAvatarMotion=He;exports.useAvatarPicker=Qr;//# sourceMappingURL=index.cjs.map
|
|
256
|
+
`;function lr(){react.useInsertionEffect(()=>{if(typeof document>"u"||document.getElementById(sr))return;let r=document.createElement("style");r.id=sr,r.textContent=Wr,document.head.prepend(r);},[]);}function pr(r){return r==="mouse"?3:r==="pen"?6:10}function ur(r,n,o){let p=n.x-r.x,u=n.y-r.y;return p*p+u*u>o*o}function br(r){let n=r.x-r.pad,o=r.y-r.pad;return n<0||o<0||n>=r.width||o>=r.height?null:{i:Math.floor((n-r.offsetX)/r.pitch),j:Math.floor((o-r.offsetY)/r.pitch)}}var Ye=typeof window<"u"?react.useLayoutEffect:react.useEffect,me=5,Ue=3,D=2,H=1,rt=me+2,tt=Ue+2,nt=4,dr=8,ot=24,it=78,at=2.6,fr=3.2,ct=6,Re=8,oe=(r,n)=>(Math.trunc(r)%n+n)%n,J=(r,n,o)=>Math.min(o,Math.max(n,r)),mr=react.createContext(null);function B(){let r=react.useContext(mr);if(!r)throw new Error("AvatarPicker parts must be used inside <AvatarPickerRoot>.");return r}function st(){let{map:r,...n}=B();return n}function vr({dir:r}){return jsxRuntime.jsx("svg",{viewBox:"0 0 12 12",width:"10",height:"10",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:jsxRuntime.jsx("path",{d:r==="l"?"M7.5 2.5 4 6l3.5 3.5":"M4.5 2.5 8 6l-3.5 3.5"})})}function lt(r){return r.ctrlKey||r.deltaMode!==0?false:r.deltaX!==0||Math.abs(r.deltaY)<40||!Number.isInteger(r.deltaY)}function kr(r){let{name:n,defaultValue:o,onChange:p,onSave:u,onCancel:d,palette:b=blobbies.PALETTE,spotlight:f=true,unstyled:C=false,className:ie,style:Q,children:I,...Z}=r;lr();let k=react.useRef({color:(()=>{let e=o?.color?b.indexOf(o.color):D;return e>=0?e:D})(),expression:(()=>{let e=o?.expression?blobbies.EXPRESSIONS.indexOf(o.expression):H;return e>=0?e:H})(),blush:o?.blush??true}),[X,ee]=react.useState({cell:68,gap:dr}),[F,re]=react.useState(k.current.blush??true),[ae,w]=react.useState(null),[z,m]=react.useState(f),[y,Y]=react.useState(false),[R,_]=react.useState(null),[ue,G]=react.useState(false),[ce,be]=react.useState(false),[de,he]=react.useState(0),{cell:L,gap:se}=X,Le=L+se,Ve=me*L+(me-1)*se,$e=Ue*L+(Ue-1)*se,Mr=Ve+Re*2,Er=$e+Re*2,U=react.useRef(k.current.color-D),M=react.useRef(k.current.expression-H),E=react.useRef({i:D,j:H}),a=react.useRef({x:0,y:0}),S=react.useRef({x:0,y:0}),v=react.useRef("idle"),P=react.useRef(0),N=react.useRef(0),xe=react.useRef(0),We=react.useRef(0),V=react.useRef(false),$=react.useRef(Le);$.current=Le;let Ke=react.useRef(null),Ne=react.useRef(null),fe=react.useRef(null),Oe=react.useRef(new Map),ve=react.useRef({x:0,y:0}),le=react.useRef(null),je=react.useRef(null),ge=react.useRef({x:0,y:0}),Te=react.useRef(0),ye=react.useRef(typeof window<"u"&&typeof window.matchMedia=="function"?window.matchMedia("(prefers-reduced-motion: reduce)").matches:false),De=react.useRef(R),qe=react.useRef(y),Je=react.useRef(ce),Qe=react.useRef(L),He=react.useRef(false),Pe=react.useRef(false),Ze=react.useRef(z);Ze.current=z,De.current=R,qe.current=y,Je.current=ce,Qe.current=L;let W=()=>he(e=>e+1),Be=()=>{let e=$.current,i=Qe.current,t=De.current&&!qe.current&&!V.current&&!Je.current?De.current:null;if(!t){if(!He.current&&Pe.current)return;He.current=false,Pe.current=true;for(let[,x]of Oe.current)x.style.transform="",x.style.opacity="1",x.style.filter="";return}He.current=true,Pe.current=true;let s=(t.i+.5)*e+a.current.x,g=(t.j+.5)*e+a.current.y;for(let[x,A]of Oe.current){let[j,te]=x.split(":").map(Number),pe=j*e+a.current.x+i/2,ne=te*e+a.current.y+i/2,Ee=Math.hypot(pe-s,ne-g)/e,Fe=Math.min(1,Ee/at),tr=1-Fe*Fe,nr=0,or=0;if(Ee>=.001){let ar=Math.hypot(pe-s,ne-g)||1,cr=ye.current?0:tr*ct;nr=(pe-s)/ar*cr,or=(ne-g)/ar*cr;}let Ir=Ee<.001?1:.7+.3*tr,ir=Ze.current&&Ee>=.001?Math.min(fr,Fe*fr):0;A.style.transform=`translate3d(${nr.toFixed(1)}px, ${or.toFixed(1)}px, 0)`,A.style.opacity=Ir.toFixed(3),A.style.filter=ir>.06?`blur(${ir.toFixed(2)}px)`:"";}},er=(e,i)=>{let t=fe.current?.getBoundingClientRect();return t?br({x:e-t.left,y:i-t.top,pad:Re,offsetX:a.current.x,offsetY:a.current.y,pitch:$.current,width:Ve,height:$e}):null},Sr=e=>{let i=Ne.current;i&&(i.style.transform=`translate3d(${a.current.x}px, ${a.current.y+e}px, 0)`),Be();},h=()=>{let e=Ne.current;e&&(e.style.transform=`translate3d(${a.current.x}px, ${a.current.y}px, 0)`);let i=$.current,t=a.current.x<i/2?D:D-1,s=a.current.y<i/2?H:H-1;(t!==E.current.i||s!==E.current.j)&&(E.current={i:t,j:s},W()),Be();},K=()=>{let e=$.current,i=false,t=Math.floor(a.current.x/e),s=Math.floor(a.current.y/e);t!==0&&(U.current-=t,a.current.x-=t*e,i=true),s!==0&&(M.current-=s,a.current.y-=s*e,i=true),i&&W();},Ae=()=>{P.current||(P.current=requestAnimationFrame(function(){P.current=0;let i=$.current;if(v.current==="glide")a.current.x+=S.current.x,a.current.y+=S.current.y,S.current.x*=.9,S.current.y*=.9,Math.abs(S.current.x)<.4&&Math.abs(S.current.y)<.4&&(v.current="snap"),K(),h(),Ae();else if(v.current==="snap"){let t=a.current.x<i/2?0:i,s=a.current.y<i/2?0:i;Math.abs(t-a.current.x)<.4&&Math.abs(s-a.current.y)<.4?(a.current={x:t,y:s},K(),h(),v.current="idle",be(false)):(a.current.x+=(t-a.current.x)*.22,a.current.y+=(s-a.current.y)*.22,K(),h(),Ae());}}));},we=e=>{if(V.current)return;if(w(null),ye.current){M.current+=e,W(),h();return}V.current=true,We.current=e,G(true);let i=$.current,t=-e*i,s=performance.now(),g=300,x=A=>{let j=Math.min(1,(A-s)/g),te=1-Math.pow(1-j,3);xe.current=t*te,Sr(xe.current),j<1?N.current=requestAnimationFrame(x):(M.current+=e,xe.current=0,N.current=0,V.current=false,G(false),W(),h());};N.current=requestAnimationFrame(x);};Ye(()=>{let e=Ke.current;if(!e)return;let i=fe.current?.parentElement??e,t=()=>{let g=getComputedStyle(i),x=(parseFloat(g.paddingLeft)||0)+(parseFloat(g.paddingRight)||0),A=i.clientWidth-x,j=Math.min(16,Math.max(6,Math.round(A*.03))),te=J(Math.round(A*.02),nt,dr),pe=J(Math.floor((A-j*2-Re*2-(me-1)*te)/me),ot,it);ee(ne=>ne.cell===pe&&ne.gap===te?ne:{cell:pe,gap:te});};if(t(),typeof ResizeObserver>"u")return;let s=new ResizeObserver(t);return s.observe(i),()=>s.disconnect()},[]),Ye(()=>{P.current&&(cancelAnimationFrame(P.current),P.current=0),V.current&&N.current&&(cancelAnimationFrame(N.current),N.current=0,V.current=false),G(false),be(false),v.current="idle",K(),Pe.current=false,h();},[L,se]),Ye(()=>{Be();}),react.useEffect(()=>{let e=fe.current;if(!e)return;let i=t=>{if(lt(t)){if(t.preventDefault(),ye.current){t.deltaX&&(U.current+=t.deltaX>0?1:-1),t.deltaY&&(M.current+=t.deltaY>0?1:-1),W(),h();return}P.current&&(cancelAnimationFrame(P.current),P.current=0),a.current.x+=t.deltaX,a.current.y+=t.deltaY,S.current={x:J(t.deltaX*.8,-40,40),y:J(t.deltaY*.8,-40,40)},K(),h(),v.current="glide",Ae();}};return e.addEventListener("wheel",i,{passive:false}),()=>e.removeEventListener("wheel",i)},[]);let Cr=e=>{if(!(e.button>0)&&le.current===null){le.current=e.pointerId;try{fe.current?.setPointerCapture(e.pointerId);}catch{}P.current&&(cancelAnimationFrame(P.current),P.current=0),V.current&&(N.current&&cancelAnimationFrame(N.current),M.current+=We.current,xe.current=0,N.current=0,V.current=false,G(false),h()),je.current=er(e.clientX,e.clientY),v.current="press",Te.current=pr(e.pointerType),ge.current={x:e.clientX,y:e.clientY},ve.current={x:e.clientX,y:e.clientY},S.current={x:0,y:0},_(null);}},Rr=e=>{if(v.current==="press"||v.current==="drag"){if(e.pointerId!==le.current)return;if(v.current==="press"){if(ur(ge.current,{x:e.clientX,y:e.clientY},Te.current)){v.current="drag";let g=e.clientX-ge.current.x,x=e.clientY-ge.current.y,A=Math.hypot(g,x)||1,j=(A-Te.current)/A;a.current.x+=g*j,a.current.y+=x*j,ve.current={x:e.clientX,y:e.clientY},S.current={x:J(g*.85,-40,40),y:J(x*.85,-40,40)},K(),h(),w(null),Y(true);}return}let t=e.clientX-ve.current.x,s=e.clientY-ve.current.y;ve.current={x:e.clientX,y:e.clientY},a.current.x+=t,a.current.y+=s,S.current={x:J(t*.85,-40,40),y:J(s*.85,-40,40)},K(),h();return}if(e.pointerType==="touch")return;let i=er(e.clientX,e.clientY);_(t=>i&&t&&t.i===i.i&&t.j===i.j?t:i);},Ie=(e,i)=>{if(le.current!==null&&e.pointerId!==le.current||(le.current=null,v.current!=="press"&&v.current!=="drag"))return;let t=v.current==="press";if(Y(false),t&&i){let s=je.current;s&&w({color:oe(U.current+s.i,b.length),expression:oe(M.current+s.j,blobbies.EXPRESSION_COUNT)});}if(_(null),je.current=null,ye.current){let s=$.current;a.current.x=a.current.x<s/2?0:s,a.current.y=a.current.y<s/2?0:s,K(),h(),v.current="idle";return}v.current="glide",be(true),Ae();},Lr=e=>{switch(e.key){case "ArrowRight":e.preventDefault(),w(null),U.current+=1,W(),h();break;case "ArrowLeft":e.preventDefault(),w(null),U.current-=1,W(),h();break;case "ArrowDown":e.preventDefault(),we(1);break;case "ArrowUp":e.preventDefault(),we(-1);break;}},rr=react.useMemo(()=>{let e=[];for(let i=-1;i<tt-1;i++)for(let t=-1;t<rt-1;t++)e.push({key:`${t}:${i}`,i:t,j:i,color:oe(U.current+t,b.length),expression:oe(M.current+i,blobbies.EXPRESSION_COUNT)});return e},[de,b.length]);R??{i:E.current.i,j:E.current.j};let q=ae??{color:oe(U.current+E.current.i,b.length),expression:oe(M.current+E.current.j,blobbies.EXPRESSION_COUNT)},O={color:b[q.color],expression:blobbies.EXPRESSIONS[q.expression],blush:F},Xe=rr.find(e=>e.color===q.color&&e.expression===q.expression),Nr=Xe?{i:Xe.i,j:Xe.j}:{i:E.current.i,j:E.current.j},Or=y||ue||ce?null:R??Nr,jr=q.color!==k.current.color||q.expression!==k.current.expression||F!==k.current.blush,Me=react.useRef(null);react.useEffect(()=>{let e=`${O.color}.${O.expression}.${O.blush}`;if(Me.current===null){Me.current=e;return}Me.current!==e&&(Me.current=e,p?.(O));},[O.color,O.expression,O.blush]);let Tr=()=>{w(null),U.current=(k.current.color??D)-D,M.current=(k.current.expression??H)-H,re(k.current.blush??true),a.current={x:0,y:0},E.current={i:D,j:H},_(null),W(),h();},Dr={stageRef:fe,worldRef:Ne,cellEls:Oe,cell:L,pitch:Le,vw:Mr,vh:Er,cells:rr,focus:Or,selected:q,dragging:y,moving:y||ue||ce,handlers:{onPointerDown:Cr,onPointerMove:Rr,onPointerUp:e=>Ie(e,true),onPointerCancel:e=>Ie(e,false),onLostPointerCapture:e=>Ie(e,false),onPointerLeave:()=>{v.current==="idle"&&_(null);},onKeyDown:Lr}},Hr={name:n,value:O,changed:jr,blush:F,expressionName:blobbies.EXPRESSION_NAMES[R?oe(M.current+R.j,blobbies.EXPRESSION_COUNT):q.expression],nextExpression:()=>we(1),previousExpression:()=>we(-1),toggleBlush:()=>re(e=>!e),spotlight:z,toggleSpotlight:()=>m(e=>!e),palette:b,reset:Tr,save:()=>u?.(O),cancel:()=>d?.(),hasCancel:!!d,map:Dr},Br=[C?"":"bb-picker",ie].filter(Boolean).join(" ");return jsxRuntime.jsx(mr.Provider,{value:Hr,children:jsxRuntime.jsx("div",{...Z,ref:Ke,className:Br||void 0,"data-part":"root",style:Q,children:I})})}function hr(r){let{className:n,...o}=r,{name:p,blush:u,value:d,palette:b,map:f}=B(),{stageRef:C,worldRef:ie,cellEls:Q,cell:I,pitch:Z,cells:k,focus:X,selected:ee,dragging:F,moving:re,handlers:ae,vw:w,vh:z}=f;return jsxRuntime.jsx("div",{...o,...ae,ref:C,role:"group",tabIndex:0,"aria-label":"A map of looks. Drag, swipe or use the arrow keys.","data-part":"surface","data-dragging":F?"1":void 0,className:["bb-picker-surface",n].filter(Boolean).join(" "),style:{width:w,height:z},children:jsxRuntime.jsx("div",{className:"bb-picker-viewport",children:jsxRuntime.jsx("div",{className:"bb-picker-world",ref:ie,children:k.map(m=>{let y=!!X&&m.i===X.i&&m.j===X.j;return jsxRuntime.jsxs("div",{ref:Y=>{Y?Q.current?.set(m.key,Y):Q.current?.delete(m.key);},className:"bb-picker-cell","data-focus":y?"1":void 0,style:{left:m.i*Z,top:m.j*Z,width:I,height:I,zIndex:y?6:1},"aria-hidden":"true",children:[jsxRuntime.jsx("span",{className:"bb-picker-lift",children:jsxRuntime.jsx(Se,{name:p,color:b[m.color],expression:blobbies.EXPRESSIONS[m.expression],blush:u,size:I,animate:"all",follow:y,blinkInterval:[4e3,1e4]})}),jsxRuntime.jsx("span",{className:"bb-picker-ring","aria-hidden":"true"}),jsxRuntime.jsx("span",{className:"bb-picker-check","data-on":!re&&m.color===ee.color&&m.expression===ee.expression?"1":void 0,"aria-hidden":"true",children:jsxRuntime.jsx("svg",{viewBox:"0 0 12 12",width:"10",height:"10",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:jsxRuntime.jsx("path",{d:"M2.5 6.2 4.8 8.5 9.5 3.5"})})})]},m.key)})})})})}function pt(r){let{name:n,value:o}=B();return jsxRuntime.jsx(Se,{name:n,...o,...r,"data-part":"preview"})}function xr(r){let{className:n,...o}=r,{expressionName:p,previousExpression:u,nextExpression:d}=B();return jsxRuntime.jsxs("div",{...o,className:["bb-picker-mood",n].filter(Boolean).join(" "),"data-part":"mood",children:[jsxRuntime.jsx("button",{type:"button",className:"bb-picker-step",onClick:u,"aria-label":"Previous expression",children:jsxRuntime.jsx(vr,{dir:"l"})}),jsxRuntime.jsx("span",{className:"bb-picker-mood-name","aria-live":"polite",children:p},p),jsxRuntime.jsx("button",{type:"button",className:"bb-picker-step",onClick:d,"aria-label":"Next expression",children:jsxRuntime.jsx(vr,{dir:"r"})})]})}function gr(r){let{className:n,children:o,onClick:p,...u}=r,{blush:d,toggleBlush:b}=B();return jsxRuntime.jsx("button",{type:"button",...u,className:["bb-picker-blush",n].filter(Boolean).join(" "),"data-part":"blush","data-on":d?"1":void 0,"aria-pressed":d,onClick:f=>{p?.(f),f.defaultPrevented||b();},children:o??"Blush"})}function yr(r){let{className:n,children:o,onClick:p,...u}=r,{spotlight:d,toggleSpotlight:b}=B();return jsxRuntime.jsx("button",{type:"button",...u,className:["bb-picker-spotlight",n].filter(Boolean).join(" "),"data-part":"spotlight","data-on":d?"1":void 0,"aria-pressed":d,onClick:f=>{p?.(f),f.defaultPrevented||b();},children:o??"Spotlight"})}function Pr(r){let{className:n,children:o,onClick:p,disabled:u,...d}=r,{changed:b,reset:f}=B();return jsxRuntime.jsx("button",{type:"button",...d,className:["bb-picker-reset",n].filter(Boolean).join(" "),"data-part":"reset",disabled:u||!b,onClick:C=>{p?.(C),C.defaultPrevented||f();},children:o??"Reset"})}function Ar(r){let{className:n,children:o,onClick:p,...u}=r,{save:d}=B();return jsxRuntime.jsx("button",{type:"button",...u,className:["bb-picker-btn","bb-picker-primary",n].filter(Boolean).join(" "),"data-part":"save",onClick:b=>{p?.(b),b.defaultPrevented||d();},children:o??"Save"})}function wr(r){let{className:n,children:o,onClick:p,...u}=r,{cancel:d,hasCancel:b}=B();return b?jsxRuntime.jsx("button",{type:"button",...u,className:["bb-picker-btn",n].filter(Boolean).join(" "),"data-part":"cancel",onClick:f=>{p?.(f),f.defaultPrevented||d();},children:o??"Cancel"}):null}function ut(r){let{title:n="Choose an avatar",description:o="Drag across for colour, down for mood, then keep one.",saveLabel:p="Save",onCancel:u,...d}=r;return jsxRuntime.jsxs(kr,{...d,onCancel:u,children:[(n||o)&&jsxRuntime.jsxs("div",{className:"bb-picker-head","data-part":"header",children:[n&&jsxRuntime.jsx("h3",{"data-part":"title",children:n}),o&&jsxRuntime.jsx("p",{"data-part":"description",children:o})]}),jsxRuntime.jsx(hr,{}),jsxRuntime.jsx(xr,{}),jsxRuntime.jsxs("div",{className:"bb-picker-foot","data-part":"footer",children:[jsxRuntime.jsx(gr,{}),jsxRuntime.jsx(yr,{}),jsxRuntime.jsx(Pr,{}),jsxRuntime.jsx("span",{className:"bb-picker-grow"}),jsxRuntime.jsx(wr,{}),jsxRuntime.jsx(Ar,{children:p})]})]})}Object.defineProperty(exports,"COLORS",{enumerable:true,get:function(){return blobbies.COLORS}});Object.defineProperty(exports,"EXPRESSIONS",{enumerable:true,get:function(){return blobbies.EXPRESSIONS}});Object.defineProperty(exports,"EXPRESSION_COUNT",{enumerable:true,get:function(){return blobbies.EXPRESSION_COUNT}});Object.defineProperty(exports,"EXPRESSION_NAMES",{enumerable:true,get:function(){return blobbies.EXPRESSION_NAMES}});Object.defineProperty(exports,"PALETTE",{enumerable:true,get:function(){return blobbies.PALETTE}});Object.defineProperty(exports,"SHAPES",{enumerable:true,get:function(){return blobbies.SHAPES}});Object.defineProperty(exports,"SHAPE_COUNT",{enumerable:true,get:function(){return blobbies.SHAPE_COUNT}});exports.Avatar=Se;exports.AvatarPicker=ut;exports.AvatarPickerBlush=gr;exports.AvatarPickerCancel=wr;exports.AvatarPickerMood=xr;exports.AvatarPickerPreview=pt;exports.AvatarPickerReset=Pr;exports.AvatarPickerRoot=kr;exports.AvatarPickerSave=Ar;exports.AvatarPickerSpotlight=yr;exports.AvatarPickerSurface=hr;exports.useAvatarMotion=ze;exports.useAvatarPicker=st;//# sourceMappingURL=index.cjs.map
|
|
225
257
|
//# sourceMappingURL=index.cjs.map
|