@souldi/try-on 0.1.0 → 0.1.1
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 +214 -0
- package/dist/widget.mjs +517 -588
- package/dist/widget.umd.js +545 -115
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
# @souldi/try-on
|
|
2
|
+
|
|
3
|
+
**Drop a virtual try-on button into any e-commerce site in under 5 minutes.**
|
|
4
|
+
|
|
5
|
+
Let your customers see how clothes look on them — powered by AI, embedded with a single script tag. No iframes, no redirects, no heavy dependencies.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Quick Start
|
|
10
|
+
|
|
11
|
+
### 1. Install
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm install @souldi/try-on
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Or load directly via CDN:
|
|
18
|
+
|
|
19
|
+
```html
|
|
20
|
+
<script src="https://unpkg.com/@souldi/try-on/dist/widget.umd.js"></script>
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
### 2. Initialize
|
|
24
|
+
|
|
25
|
+
```html
|
|
26
|
+
<script>
|
|
27
|
+
VirtualTryOn.init({
|
|
28
|
+
apiBaseUrl: 'https://api.yourdomain.com',
|
|
29
|
+
tenantApiKey: 'your_publishable_api_key',
|
|
30
|
+
});
|
|
31
|
+
</script>
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### 3. Add a Try-On Button
|
|
35
|
+
|
|
36
|
+
```html
|
|
37
|
+
<div id="try-on-jacket"></div>
|
|
38
|
+
|
|
39
|
+
<script>
|
|
40
|
+
VirtualTryOn.createButton({
|
|
41
|
+
containerId: 'try-on-jacket',
|
|
42
|
+
garmentUrl: 'https://your-cdn.com/images/jacket.png',
|
|
43
|
+
targetImageId: 'product-image', // optional: auto-swaps this <img> with the result
|
|
44
|
+
});
|
|
45
|
+
</script>
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
That's it. Your customers can now try on clothes with AI.
|
|
49
|
+
|
|
50
|
+
---
|
|
51
|
+
|
|
52
|
+
## How It Works
|
|
53
|
+
|
|
54
|
+
1. Customer clicks the **Try On** button
|
|
55
|
+
2. First-time users verify their email (magic link OTP — no passwords)
|
|
56
|
+
3. They upload a photo of themselves
|
|
57
|
+
4. AI generates a realistic try-on image in seconds
|
|
58
|
+
5. The result appears directly on your product page
|
|
59
|
+
|
|
60
|
+
Returning users skip straight to step 4 — their session and photo are remembered.
|
|
61
|
+
|
|
62
|
+
---
|
|
63
|
+
|
|
64
|
+
## Configuration
|
|
65
|
+
|
|
66
|
+
### `init(options)`
|
|
67
|
+
|
|
68
|
+
Call once per page load to configure the widget.
|
|
69
|
+
|
|
70
|
+
| Option | Type | Required | Description |
|
|
71
|
+
|--------|------|----------|-------------|
|
|
72
|
+
| `apiBaseUrl` | `string` | Yes | Your Souldi API endpoint URL |
|
|
73
|
+
| `tenantApiKey` | `string` | Yes | Your publishable API key (from your Souldi dashboard) |
|
|
74
|
+
| `theme` | `object` | No | Customize the widget appearance ([see Theming](#theming)) |
|
|
75
|
+
| `onGenerationStart` | `function` | No | Called when AI generation begins |
|
|
76
|
+
| `onGenerationSuccess` | `function(resultUrl)` | No | Called with the result image URL on success |
|
|
77
|
+
| `onError` | `function(message)` | No | Called when something goes wrong |
|
|
78
|
+
| `onLogout` | `function` | No | Called when the user logs out |
|
|
79
|
+
|
|
80
|
+
### `createButton(options)`
|
|
81
|
+
|
|
82
|
+
Add a try-on button for a specific garment. Call once per product on the page.
|
|
83
|
+
|
|
84
|
+
| Option | Type | Required | Description |
|
|
85
|
+
|--------|------|----------|-------------|
|
|
86
|
+
| `containerId` | `string` | Yes | ID of the DOM element where the button will render |
|
|
87
|
+
| `garmentUrl` | `string` | Yes | Public URL of the garment image |
|
|
88
|
+
| `targetImageId` | `string` | No | ID of an `<img>` element to auto-swap with the try-on result |
|
|
89
|
+
|
|
90
|
+
---
|
|
91
|
+
|
|
92
|
+
## Theming
|
|
93
|
+
|
|
94
|
+
The widget ships with **dark** and **light** themes and supports deep customization to match your store's brand.
|
|
95
|
+
|
|
96
|
+
### Theme Modes
|
|
97
|
+
|
|
98
|
+
```javascript
|
|
99
|
+
VirtualTryOn.init({
|
|
100
|
+
apiBaseUrl: 'https://api.yourdomain.com',
|
|
101
|
+
tenantApiKey: 'your_key',
|
|
102
|
+
theme: {
|
|
103
|
+
mode: 'light', // 'dark' (default) or 'light'
|
|
104
|
+
},
|
|
105
|
+
});
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### Custom Brand Colors
|
|
109
|
+
|
|
110
|
+
Override individual properties to match your brand:
|
|
111
|
+
|
|
112
|
+
```javascript
|
|
113
|
+
VirtualTryOn.init({
|
|
114
|
+
apiBaseUrl: 'https://api.yourdomain.com',
|
|
115
|
+
tenantApiKey: 'your_key',
|
|
116
|
+
theme: {
|
|
117
|
+
mode: 'dark',
|
|
118
|
+
accentColor: '#7C3AED', // Primary button & accent color
|
|
119
|
+
accentTextColor: '#FFFFFF', // Text color on accent buttons
|
|
120
|
+
borderRadius: '8px', // Border radius for cards & modals
|
|
121
|
+
fontFamily: '"Inter", sans-serif',
|
|
122
|
+
headingFontFamily: '"Playfair Display", serif',
|
|
123
|
+
buttonOutlineColor: '#7C3AED', // Outline on the split button
|
|
124
|
+
},
|
|
125
|
+
});
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
### Available Theme Options
|
|
129
|
+
|
|
130
|
+
| Property | Type | Default | Description |
|
|
131
|
+
|----------|------|---------|-------------|
|
|
132
|
+
| `mode` | `'dark' \| 'light'` | `'dark'` | Base color palette |
|
|
133
|
+
| `accentColor` | CSS color | `#adcfab` (dark) / `#4d7c4b` (light) | Primary action color |
|
|
134
|
+
| `accentTextColor` | CSS color | `#193620` (dark) / `#ffffff` (light) | Text on accent buttons |
|
|
135
|
+
| `borderRadius` | CSS value | `12px` | Corner rounding for cards and modals |
|
|
136
|
+
| `fontFamily` | CSS font stack | `'Manrope', system-ui, sans-serif` | Body text font |
|
|
137
|
+
| `headingFontFamily` | CSS font stack | `'Newsreader', serif` | Heading font |
|
|
138
|
+
| `buttonOutlineColor` | CSS color | `transparent` | Border color on the try-on button |
|
|
139
|
+
|
|
140
|
+
All UI is rendered inside a **Shadow DOM**, so your site's CSS will never leak into the widget and the widget will never break your styles.
|
|
141
|
+
|
|
142
|
+
---
|
|
143
|
+
|
|
144
|
+
## Full Example
|
|
145
|
+
|
|
146
|
+
```html
|
|
147
|
+
<!DOCTYPE html>
|
|
148
|
+
<html>
|
|
149
|
+
<head>
|
|
150
|
+
<title>My Store</title>
|
|
151
|
+
<script src="https://unpkg.com/@souldi/try-on/dist/widget.umd.js"></script>
|
|
152
|
+
</head>
|
|
153
|
+
<body>
|
|
154
|
+
<div class="product-card">
|
|
155
|
+
<img id="product-image" src="/images/jacket.jpg" alt="Jacket" />
|
|
156
|
+
<h2>Classic Denim Jacket</h2>
|
|
157
|
+
<p>$89.00</p>
|
|
158
|
+
|
|
159
|
+
<!-- The try-on button renders here -->
|
|
160
|
+
<div id="try-on-btn"></div>
|
|
161
|
+
</div>
|
|
162
|
+
|
|
163
|
+
<script>
|
|
164
|
+
VirtualTryOn.init({
|
|
165
|
+
apiBaseUrl: 'https://api.yourdomain.com',
|
|
166
|
+
tenantApiKey: 'pk_live_abc123',
|
|
167
|
+
theme: { mode: 'light', accentColor: '#2563EB' },
|
|
168
|
+
onGenerationSuccess: (url) => {
|
|
169
|
+
console.log('Try-on result:', url);
|
|
170
|
+
},
|
|
171
|
+
onError: (msg) => {
|
|
172
|
+
console.error('Try-on error:', msg);
|
|
173
|
+
},
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
VirtualTryOn.createButton({
|
|
177
|
+
containerId: 'try-on-btn',
|
|
178
|
+
garmentUrl: 'https://your-cdn.com/images/jacket-flat.png',
|
|
179
|
+
targetImageId: 'product-image',
|
|
180
|
+
});
|
|
181
|
+
</script>
|
|
182
|
+
</body>
|
|
183
|
+
</html>
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
---
|
|
187
|
+
|
|
188
|
+
## Keys & Authentication
|
|
189
|
+
|
|
190
|
+
| Key | Where to use | Purpose |
|
|
191
|
+
|-----|-------------|---------|
|
|
192
|
+
| **Publishable API Key** (`tenantApiKey`) | In your frontend code | Identifies your store — safe to expose in client-side code |
|
|
193
|
+
| **Secret API Key** | Backend only, never in frontend | Used for server-to-server API calls (manage your account, view usage, etc.) |
|
|
194
|
+
|
|
195
|
+
Your API keys are available in your **Souldi Dashboard**. The publishable key is scoped to the domains you whitelist — it cannot be used from unauthorized origins.
|
|
196
|
+
|
|
197
|
+
> **Security note:** The widget communicates exclusively with your Souldi API endpoint. No third-party services are contacted from the browser. All authentication, file uploads, and AI generation are handled server-side.
|
|
198
|
+
|
|
199
|
+
---
|
|
200
|
+
|
|
201
|
+
## Browser Support
|
|
202
|
+
|
|
203
|
+
Works in all modern browsers:
|
|
204
|
+
|
|
205
|
+
- Chrome 80+
|
|
206
|
+
- Firefox 78+
|
|
207
|
+
- Safari 14+
|
|
208
|
+
- Edge 80+
|
|
209
|
+
|
|
210
|
+
---
|
|
211
|
+
|
|
212
|
+
## License
|
|
213
|
+
|
|
214
|
+
UNLICENSED - Proprietary software. See your Souldi service agreement for usage terms.
|