@primestyleai/tryon 5.10.143 → 5.10.169
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/dist/{index-GW10cktY.js → index-B1_VQgps.js} +53 -68
- package/dist/{index-GW10cktY.js.map → index-B1_VQgps.js.map} +1 -1
- package/dist/primestyle-tryon.js +2 -2
- package/dist/react/index.js +4908 -4585
- package/dist/react/index.js.map +1 -1
- package/dist/react/styles.d.ts +1 -1
- package/dist/sizing/fit-compute.d.ts +13 -4
- package/dist/storefront/primestyle-tryon.js +624 -130
- package/package.json +1 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
const
|
|
2
|
+
const p = "ps_session";
|
|
3
3
|
const E = "ps_mem_";
|
|
4
|
-
let
|
|
5
|
-
function
|
|
4
|
+
let f = null;
|
|
5
|
+
function y() {
|
|
6
6
|
try {
|
|
7
7
|
return typeof window < "u" && typeof window.localStorage < "u";
|
|
8
8
|
} catch {
|
|
@@ -18,9 +18,9 @@ function b() {
|
|
|
18
18
|
return e;
|
|
19
19
|
}
|
|
20
20
|
function P() {
|
|
21
|
-
if (!
|
|
21
|
+
if (!y()) return f;
|
|
22
22
|
try {
|
|
23
|
-
const t = window.localStorage.getItem(
|
|
23
|
+
const t = window.localStorage.getItem(p);
|
|
24
24
|
if (!t) return null;
|
|
25
25
|
const e = JSON.parse(t);
|
|
26
26
|
return typeof e.id != "string" || typeof e.issuedAt != "number" ? null : {
|
|
@@ -32,19 +32,19 @@ function P() {
|
|
|
32
32
|
return null;
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
|
-
function
|
|
36
|
-
if (
|
|
35
|
+
function g(t) {
|
|
36
|
+
if (f = t, !!y())
|
|
37
37
|
try {
|
|
38
|
-
window.localStorage.setItem(
|
|
38
|
+
window.localStorage.setItem(p, JSON.stringify(t));
|
|
39
39
|
} catch {
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
42
|
function A() {
|
|
43
43
|
const t = Date.now(), e = P();
|
|
44
44
|
if (e && t - e.lastSeenAt < 2592e6)
|
|
45
|
-
return t - e.lastSeenAt > 5 * 60 * 1e3 &&
|
|
45
|
+
return t - e.lastSeenAt > 5 * 60 * 1e3 && g({ ...e, lastSeenAt: t }), e.id;
|
|
46
46
|
const o = { id: b(), issuedAt: t, lastSeenAt: t };
|
|
47
|
-
return
|
|
47
|
+
return g(o), o.id;
|
|
48
48
|
}
|
|
49
49
|
function I() {
|
|
50
50
|
if (typeof navigator > "u") return null;
|
|
@@ -62,8 +62,8 @@ class O {
|
|
|
62
62
|
Authorization: `Bearer ${this.apiKey}`
|
|
63
63
|
};
|
|
64
64
|
}
|
|
65
|
-
async submitTryOn(e, o, a,
|
|
66
|
-
const
|
|
65
|
+
async submitTryOn(e, o, a, u, r) {
|
|
66
|
+
const i = {
|
|
67
67
|
garmentImage: o,
|
|
68
68
|
// Attribution fields — backend logs these into the TryOnEvent collection
|
|
69
69
|
// so non-technical operators can answer "which products are being tried on
|
|
@@ -71,41 +71,26 @@ class O {
|
|
|
71
71
|
sessionId: A(),
|
|
72
72
|
deviceHint: I()
|
|
73
73
|
};
|
|
74
|
-
if (r?.modelImageId && (
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
fit: i.fit,
|
|
81
|
-
userValue: i.userValue,
|
|
82
|
-
garmentRange: i.garmentRange
|
|
83
|
-
})) || null,
|
|
84
|
-
silhouetteContext: r?.silhouetteContext || null
|
|
85
|
-
}), a && a.length > 0) {
|
|
86
|
-
console.log("[ps-sdk:api] Body vs Garment (what Gemini will see):");
|
|
87
|
-
for (const i of a) {
|
|
88
|
-
const l = (i.garmentRange || "").replace(/[^\d.\-–]/g, " ").trim().split(/[\s\-–]+/).filter(Boolean).map(Number).filter((h) => !isNaN(h));
|
|
89
|
-
let u = "";
|
|
90
|
-
if (l.length && i.userValue != null) {
|
|
91
|
-
const h = (Math.min(...l) + Math.max(...l)) / 2, c = Math.round((i.userValue - h) * 10) / 10;
|
|
92
|
-
u = c > 0 ? `garment ${c} smaller` : c < 0 ? `garment ${Math.abs(c)} larger` : "matched";
|
|
74
|
+
if (r?.modelImageId && (i.modelImageId = r.modelImageId), e && (i.modelImage = e), a && a.length > 0 && (i.fitInfo = a), u && u !== "apparel" && (i.category = u), r?.productId && (i.productId = r.productId), r?.productTitle && (i.productTitle = r.productTitle), r?.productDescription && (i.productDescription = r.productDescription), r?.productMaterial && (i.productMaterial = r.productMaterial), r?.silhouetteContext && (i.silhouetteContext = r.silhouetteContext), r?.editFromPrevious && (i.editFromPrevious = !0), a && a.length > 0)
|
|
75
|
+
for (const s of a) {
|
|
76
|
+
const n = (s.garmentRange || "").replace(/[^\d.\-–]/g, " ").trim().split(/[\s\-–]+/).filter(Boolean).map(Number).filter((l) => !isNaN(l));
|
|
77
|
+
if (n.length && s.userValue != null) {
|
|
78
|
+
const l = (Math.min(...n) + Math.max(...n)) / 2;
|
|
79
|
+
Math.round((s.userValue - l) * 10) / 10;
|
|
93
80
|
}
|
|
94
|
-
console.log(`[ps-sdk:api] ${i.area.padEnd(10)} body=${i.userValue ?? "?"} garment=${i.garmentRange ?? "?"} → ${u}`);
|
|
95
81
|
}
|
|
96
|
-
}
|
|
97
82
|
const d = await fetch(`${this.baseUrl}/api/v1/tryon`, {
|
|
98
83
|
method: "POST",
|
|
99
84
|
headers: this.headers,
|
|
100
|
-
body: JSON.stringify(
|
|
85
|
+
body: JSON.stringify(i)
|
|
101
86
|
});
|
|
102
87
|
if (!d.ok) {
|
|
103
|
-
const
|
|
104
|
-
throw d.status === 402 ? new
|
|
105
|
-
|
|
88
|
+
const s = await d.json().catch(() => ({}));
|
|
89
|
+
throw d.status === 402 ? new c(
|
|
90
|
+
s.message || "Insufficient try-ons",
|
|
106
91
|
"INSUFFICIENT_BALANCE"
|
|
107
|
-
) : new
|
|
108
|
-
|
|
92
|
+
) : new c(
|
|
93
|
+
s.message || "Failed to submit try-on",
|
|
109
94
|
"API_ERROR"
|
|
110
95
|
);
|
|
111
96
|
}
|
|
@@ -117,7 +102,7 @@ class O {
|
|
|
117
102
|
});
|
|
118
103
|
if (!o.ok) {
|
|
119
104
|
const a = await o.json().catch(() => ({}));
|
|
120
|
-
throw new
|
|
105
|
+
throw new c(
|
|
121
106
|
a.message || "Failed to get status",
|
|
122
107
|
"API_ERROR"
|
|
123
108
|
);
|
|
@@ -128,7 +113,7 @@ class O {
|
|
|
128
113
|
return `${this.baseUrl}/api/v1/tryon/stream?key=${encodeURIComponent(this.apiKey)}`;
|
|
129
114
|
}
|
|
130
115
|
}
|
|
131
|
-
class
|
|
116
|
+
class c extends Error {
|
|
132
117
|
constructor(e, o) {
|
|
133
118
|
super(e), this.name = "PrimeStyleError", this.code = o;
|
|
134
119
|
}
|
|
@@ -165,7 +150,7 @@ class W {
|
|
|
165
150
|
}
|
|
166
151
|
emit(e, o) {
|
|
167
152
|
const a = this.listeners.get(e);
|
|
168
|
-
a && a.forEach((
|
|
153
|
+
a && a.forEach((u) => u(o));
|
|
169
154
|
}
|
|
170
155
|
disconnect() {
|
|
171
156
|
this.reconnectTimer && (clearTimeout(this.reconnectTimer), this.reconnectTimer = null), this.eventSource && (this.eventSource.close(), this.eventSource = null), this.listeners.clear(), this.reconnectAttempts = 0;
|
|
@@ -174,28 +159,28 @@ class W {
|
|
|
174
159
|
const v = 512, w = 0.65;
|
|
175
160
|
function C(t, e = {}) {
|
|
176
161
|
const o = e.maxDimension ?? v, a = e.quality ?? w;
|
|
177
|
-
return new Promise((
|
|
178
|
-
const
|
|
179
|
-
|
|
162
|
+
return new Promise((u, r) => {
|
|
163
|
+
const i = new FileReader();
|
|
164
|
+
i.onload = () => {
|
|
180
165
|
const d = new Image();
|
|
181
166
|
d.onload = () => {
|
|
182
167
|
try {
|
|
183
|
-
const
|
|
184
|
-
let { width:
|
|
185
|
-
(
|
|
186
|
-
const
|
|
187
|
-
if (!
|
|
168
|
+
const s = document.createElement("canvas");
|
|
169
|
+
let { width: n, height: l } = d;
|
|
170
|
+
(n > o || l > o) && (n > l ? (l = Math.round(l * o / n), n = o) : (n = Math.round(n * o / l), l = o)), s.width = n, s.height = l;
|
|
171
|
+
const m = s.getContext("2d");
|
|
172
|
+
if (!m) {
|
|
188
173
|
r(new Error("Canvas context not available"));
|
|
189
174
|
return;
|
|
190
175
|
}
|
|
191
|
-
|
|
192
|
-
const
|
|
193
|
-
|
|
194
|
-
} catch (
|
|
195
|
-
r(
|
|
176
|
+
m.drawImage(d, 0, 0, n, l);
|
|
177
|
+
const S = s.toDataURL("image/jpeg", a);
|
|
178
|
+
u(S);
|
|
179
|
+
} catch (s) {
|
|
180
|
+
r(s);
|
|
196
181
|
}
|
|
197
|
-
}, d.onerror = () => r(new Error("Failed to load image")), d.src =
|
|
198
|
-
},
|
|
182
|
+
}, d.onerror = () => r(new Error("Failed to load image")), d.src = i.result;
|
|
183
|
+
}, i.onerror = () => r(new Error("Failed to read file")), i.readAsDataURL(t);
|
|
199
184
|
});
|
|
200
185
|
}
|
|
201
186
|
function Y(t) {
|
|
@@ -203,7 +188,7 @@ function Y(t) {
|
|
|
203
188
|
}
|
|
204
189
|
async function F(t, e, o) {
|
|
205
190
|
try {
|
|
206
|
-
const a = typeof t == "string" ? t : await C(t, { maxDimension: 384, quality: 0.6 }),
|
|
191
|
+
const a = typeof t == "string" ? t : await C(t, { maxDimension: 384, quality: 0.6 }), u = await fetch(`${e}/api/v1/sizing/age-check`, {
|
|
207
192
|
method: "POST",
|
|
208
193
|
headers: {
|
|
209
194
|
"Content-Type": "application/json",
|
|
@@ -211,26 +196,26 @@ async function F(t, e, o) {
|
|
|
211
196
|
},
|
|
212
197
|
body: JSON.stringify({ bodyImage: a })
|
|
213
198
|
});
|
|
214
|
-
if (!
|
|
215
|
-
return
|
|
216
|
-
const r = await
|
|
199
|
+
if (!u.ok)
|
|
200
|
+
return { isAdult: !0, confidence: "low" };
|
|
201
|
+
const r = await u.json();
|
|
217
202
|
return {
|
|
218
203
|
isAdult: r?.isAdult !== !1,
|
|
219
204
|
// anything other than explicit false → allow
|
|
220
205
|
confidence: r?.confidence === "high" ? "high" : "low",
|
|
221
206
|
reasoning: typeof r?.reasoning == "string" ? r.reasoning : void 0
|
|
222
207
|
};
|
|
223
|
-
} catch
|
|
224
|
-
return
|
|
208
|
+
} catch {
|
|
209
|
+
return { isAdult: !0, confidence: "low" };
|
|
225
210
|
}
|
|
226
211
|
}
|
|
227
|
-
const
|
|
212
|
+
const h = {};
|
|
228
213
|
function U(t, e) {
|
|
229
|
-
|
|
214
|
+
h[t] = { ...h[t] || {}, ...e };
|
|
230
215
|
}
|
|
231
216
|
function K(t) {
|
|
232
217
|
const e = t?.toLowerCase().split("-")[0] || "en";
|
|
233
|
-
return (o) => e === "en" || !
|
|
218
|
+
return (o) => e === "en" || !h[e] ? o : h[e][o] ?? o;
|
|
234
219
|
}
|
|
235
220
|
function V() {
|
|
236
221
|
return typeof navigator > "u" ? "en" : (navigator.language || navigator.userLanguage || "en").split("-")[0].toLowerCase();
|
|
@@ -2716,7 +2701,7 @@ for (const [t, e] of Object.entries(G))
|
|
|
2716
2701
|
export {
|
|
2717
2702
|
O as A,
|
|
2718
2703
|
x as L,
|
|
2719
|
-
|
|
2704
|
+
c as P,
|
|
2720
2705
|
W as S,
|
|
2721
2706
|
J as T,
|
|
2722
2707
|
C as a,
|
|
@@ -2727,4 +2712,4 @@ export {
|
|
|
2727
2712
|
Y as i,
|
|
2728
2713
|
U as r
|
|
2729
2714
|
};
|
|
2730
|
-
//# sourceMappingURL=index-
|
|
2715
|
+
//# sourceMappingURL=index-B1_VQgps.js.map
|