@primestyleai/tryon 5.8.44 → 5.8.45
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/react/index.js
CHANGED
|
@@ -13422,6 +13422,69 @@ function PrimeStyleTryonInner({
|
|
|
13422
13422
|
const method = methodOverride || sizingMethod;
|
|
13423
13423
|
const baseUrl = getApiUrl(apiUrl);
|
|
13424
13424
|
const key = getApiKey();
|
|
13425
|
+
const measurementType = detectMeasurementType(productTitle);
|
|
13426
|
+
if (measurementType === "face" || measurementType === "head") {
|
|
13427
|
+
const f = formRef.current;
|
|
13428
|
+
const toNum = (v) => {
|
|
13429
|
+
if (!v) return void 0;
|
|
13430
|
+
const n = parseFloat(v);
|
|
13431
|
+
return Number.isFinite(n) && n > 0 ? n : void 0;
|
|
13432
|
+
};
|
|
13433
|
+
const inputUnit = f.sizingUnit || sizingUnit || (measurementType === "head" ? "cm" : "mm");
|
|
13434
|
+
const toMm = (n) => {
|
|
13435
|
+
if (n == null) return void 0;
|
|
13436
|
+
if (inputUnit === "mm") return n;
|
|
13437
|
+
if (inputUnit === "cm") return n * 10;
|
|
13438
|
+
if (inputUnit === "in") return n * 25.4;
|
|
13439
|
+
return n;
|
|
13440
|
+
};
|
|
13441
|
+
const faceMm = {};
|
|
13442
|
+
const src = {
|
|
13443
|
+
bridgeWidth: toMm(toNum(f.bridgeWidth)),
|
|
13444
|
+
templeLength: toMm(toNum(f.templeLength) ?? toNum(f.armLength)),
|
|
13445
|
+
lensWidth: toMm(toNum(f.lensWidth)),
|
|
13446
|
+
lensHeight: toMm(toNum(f.lensHeight)),
|
|
13447
|
+
faceWidth: toMm(toNum(f.faceWidth) ?? toNum(f.frameWidth)),
|
|
13448
|
+
pd: toMm(toNum(f.pd)),
|
|
13449
|
+
// Headwear — circumference usually typed in cm; keep as mm internally.
|
|
13450
|
+
headCircumference: toMm(toNum(f.headCircumference)),
|
|
13451
|
+
headWidth: toMm(toNum(f.headWidth))
|
|
13452
|
+
};
|
|
13453
|
+
for (const [k, v] of Object.entries(src)) if (typeof v === "number") faceMm[k] = v;
|
|
13454
|
+
const facePayload = {
|
|
13455
|
+
product: { title: productTitle, productId },
|
|
13456
|
+
sizeGuide: sizeGuide?.found ? sizeGuide : { found: false },
|
|
13457
|
+
sizingUnit: measurementType === "head" ? "cm" : "mm",
|
|
13458
|
+
category: measurementType,
|
|
13459
|
+
...Object.keys(faceMm).length > 0 && { faceMeasurementsMm: faceMm, irisConfidence: 1 }
|
|
13460
|
+
};
|
|
13461
|
+
try {
|
|
13462
|
+
const resp = await fetch(`${baseUrl}/api/v1/sizing/face-recommend`, {
|
|
13463
|
+
method: "POST",
|
|
13464
|
+
headers: { "Content-Type": "application/json", Authorization: `Bearer ${key}` },
|
|
13465
|
+
body: JSON.stringify(facePayload)
|
|
13466
|
+
});
|
|
13467
|
+
if (resp.ok) {
|
|
13468
|
+
const data = await resp.json();
|
|
13469
|
+
setSizingResult(data);
|
|
13470
|
+
onComplete?.(data);
|
|
13471
|
+
} else {
|
|
13472
|
+
const body = await resp.text().catch(() => "");
|
|
13473
|
+
console.error("[PS-SDK] face-recommend failed:", resp.status, body);
|
|
13474
|
+
setErrorMessage(t("Unable to get size recommendation. Please try again."));
|
|
13475
|
+
setView("error");
|
|
13476
|
+
setEstimationDone(true);
|
|
13477
|
+
}
|
|
13478
|
+
} catch (err) {
|
|
13479
|
+
console.error("[PS-SDK] face-recommend network error:", err);
|
|
13480
|
+
setErrorMessage(t("Unable to connect to sizing service. Please try again."));
|
|
13481
|
+
setView("error");
|
|
13482
|
+
setEstimationDone(true);
|
|
13483
|
+
} finally {
|
|
13484
|
+
setSizingLoading(false);
|
|
13485
|
+
}
|
|
13486
|
+
return;
|
|
13487
|
+
}
|
|
13425
13488
|
const payload = {
|
|
13426
13489
|
method,
|
|
13427
13490
|
locale: sizingCountry,
|
|
@@ -22846,6 +22846,69 @@ function PrimeStyleTryonInner({
|
|
|
22846
22846
|
const method = methodOverride || sizingMethod;
|
|
22847
22847
|
const baseUrl = getApiUrl(apiUrl);
|
|
22848
22848
|
const key = getApiKey();
|
|
22849
|
+
const measurementType = detectMeasurementType(productTitle);
|
|
22850
|
+
if (measurementType === "face" || measurementType === "head") {
|
|
22851
|
+
const f2 = formRef.current;
|
|
22852
|
+
const toNum = (v2) => {
|
|
22853
|
+
if (!v2) return void 0;
|
|
22854
|
+
const n2 = parseFloat(v2);
|
|
22855
|
+
return Number.isFinite(n2) && n2 > 0 ? n2 : void 0;
|
|
22856
|
+
};
|
|
22857
|
+
const inputUnit = f2.sizingUnit || sizingUnit || (measurementType === "head" ? "cm" : "mm");
|
|
22858
|
+
const toMm = (n2) => {
|
|
22859
|
+
if (n2 == null) return void 0;
|
|
22860
|
+
if (inputUnit === "mm") return n2;
|
|
22861
|
+
if (inputUnit === "cm") return n2 * 10;
|
|
22862
|
+
if (inputUnit === "in") return n2 * 25.4;
|
|
22863
|
+
return n2;
|
|
22864
|
+
};
|
|
22865
|
+
const faceMm = {};
|
|
22866
|
+
const src = {
|
|
22867
|
+
bridgeWidth: toMm(toNum(f2.bridgeWidth)),
|
|
22868
|
+
templeLength: toMm(toNum(f2.templeLength) ?? toNum(f2.armLength)),
|
|
22869
|
+
lensWidth: toMm(toNum(f2.lensWidth)),
|
|
22870
|
+
lensHeight: toMm(toNum(f2.lensHeight)),
|
|
22871
|
+
faceWidth: toMm(toNum(f2.faceWidth) ?? toNum(f2.frameWidth)),
|
|
22872
|
+
pd: toMm(toNum(f2.pd)),
|
|
22873
|
+
// Headwear — circumference usually typed in cm; keep as mm internally.
|
|
22874
|
+
headCircumference: toMm(toNum(f2.headCircumference)),
|
|
22875
|
+
headWidth: toMm(toNum(f2.headWidth))
|
|
22876
|
+
};
|
|
22877
|
+
for (const [k2, v2] of Object.entries(src)) if (typeof v2 === "number") faceMm[k2] = v2;
|
|
22878
|
+
const facePayload = {
|
|
22879
|
+
product: { title: productTitle, productId },
|
|
22880
|
+
sizeGuide: sizeGuide?.found ? sizeGuide : { found: false },
|
|
22881
|
+
sizingUnit: measurementType === "head" ? "cm" : "mm",
|
|
22882
|
+
category: measurementType,
|
|
22883
|
+
...Object.keys(faceMm).length > 0 && { faceMeasurementsMm: faceMm, irisConfidence: 1 }
|
|
22884
|
+
};
|
|
22885
|
+
try {
|
|
22886
|
+
const resp = await fetch(`${baseUrl}/api/v1/sizing/face-recommend`, {
|
|
22887
|
+
method: "POST",
|
|
22888
|
+
headers: { "Content-Type": "application/json", Authorization: `Bearer ${key}` },
|
|
22889
|
+
body: JSON.stringify(facePayload)
|
|
22890
|
+
});
|
|
22891
|
+
if (resp.ok) {
|
|
22892
|
+
const data = await resp.json();
|
|
22893
|
+
setSizingResult(data);
|
|
22894
|
+
onComplete?.(data);
|
|
22895
|
+
} else {
|
|
22896
|
+
const body = await resp.text().catch(() => "");
|
|
22897
|
+
console.error("[PS-SDK] face-recommend failed:", resp.status, body);
|
|
22898
|
+
setErrorMessage(t2("Unable to get size recommendation. Please try again."));
|
|
22899
|
+
setView("error");
|
|
22900
|
+
setEstimationDone(true);
|
|
22901
|
+
}
|
|
22902
|
+
} catch (err) {
|
|
22903
|
+
console.error("[PS-SDK] face-recommend network error:", err);
|
|
22904
|
+
setErrorMessage(t2("Unable to connect to sizing service. Please try again."));
|
|
22905
|
+
setView("error");
|
|
22906
|
+
setEstimationDone(true);
|
|
22907
|
+
} finally {
|
|
22908
|
+
setSizingLoading(false);
|
|
22909
|
+
}
|
|
22910
|
+
return;
|
|
22911
|
+
}
|
|
22849
22912
|
const payload = {
|
|
22850
22913
|
method,
|
|
22851
22914
|
locale: sizingCountry,
|