@primestyleai/tryon 2.0.5 → 2.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.
@@ -1,5 +1,5 @@
1
1
  import { type CSSProperties } from "react";
2
- import type { ButtonStyles, ModalStyles, PrimeStyleClassNames } from "../types";
2
+ import type { ButtonStyles, ModalStyles, PrimeStyleClassNames, SizeGuideData } from "../types";
3
3
  export interface PrimeStyleTryonProps {
4
4
  productImage: string;
5
5
  productTitle?: string;
@@ -23,5 +23,27 @@ export interface PrimeStyleTryonProps {
23
23
  message: string;
24
24
  code?: string;
25
25
  }) => void;
26
+ /** Pre-computed size guide — skips AI extraction if provided */
27
+ sizeGuide?: SizeGuideData;
28
+ /** Product description HTML for AI size guide extraction */
29
+ productDescription?: string;
30
+ /** Product vendor/brand for AI extraction */
31
+ productVendor?: string;
32
+ /** Product type (e.g. "T-Shirt", "Jacket") */
33
+ productType?: string;
34
+ /** Product tags for AI extraction */
35
+ productTags?: string[];
36
+ /** Product variants with size options */
37
+ productVariants?: Array<{
38
+ title: string;
39
+ option1?: string | null;
40
+ option2?: string | null;
41
+ option3?: string | null;
42
+ }>;
43
+ /** Product options (e.g. [{name: "Size", values: ["S","M","L"]}]) */
44
+ productOptions?: Array<{
45
+ name: string;
46
+ values?: string[];
47
+ }>;
26
48
  }
27
- export declare function PrimeStyleTryon({ productImage, productTitle, buttonText, apiUrl, showPoweredBy, buttonStyles: btnS, modalStyles: mdlS, classNames: cn, className, style, onOpen, onClose, onUpload, onProcessing, onComplete, onError, }: PrimeStyleTryonProps): import("react/jsx-runtime").JSX.Element;
49
+ export declare function PrimeStyleTryon(props: PrimeStyleTryonProps): import("react/jsx-runtime").JSX.Element | null;
@@ -1,6 +1,6 @@
1
1
  "use client";
2
- import { jsxs, jsx, Fragment } from "react/jsx-runtime";
3
- import { useState, useRef, useEffect, useMemo, useCallback } from "react";
2
+ import { jsx, jsxs, Fragment } from "react/jsx-runtime";
3
+ import { useState, useEffect, useRef, useMemo, useCallback } from "react";
4
4
  import { A as ApiClient, S as SseClient, i as isValidImageFile, c as compressImage, P as PrimeStyleError } from "../image-utils-C9bJ1zKO.js";
5
5
  function cx(base, override) {
6
6
  return override ? `${base} ${override}` : base;
@@ -154,7 +154,15 @@ function getApiKey() {
154
154
  function getApiUrl(override) {
155
155
  return override || process.env.NEXT_PUBLIC_PRIMESTYLE_API_URL || "https://myaifitting.com";
156
156
  }
157
- function PrimeStyleTryon({
157
+ function PrimeStyleTryon(props) {
158
+ const [mounted, setMounted] = useState(false);
159
+ useEffect(() => {
160
+ setMounted(true);
161
+ }, []);
162
+ if (!mounted) return null;
163
+ return /* @__PURE__ */ jsx(PrimeStyleTryonInner, { ...props });
164
+ }
165
+ function PrimeStyleTryonInner({
158
166
  productImage,
159
167
  productTitle = "Product",
160
168
  buttonText = "Virtual Try-On",
@@ -170,7 +178,14 @@ function PrimeStyleTryon({
170
178
  onUpload,
171
179
  onProcessing,
172
180
  onComplete,
173
- onError
181
+ onError,
182
+ sizeGuide: sizeGuideProp,
183
+ productDescription,
184
+ productVendor,
185
+ productType,
186
+ productTags,
187
+ productVariants,
188
+ productOptions
174
189
  }) {
175
190
  const [view, setView] = useState("idle");
176
191
  const [selectedFile, setSelectedFile] = useState(null);
@@ -275,18 +290,31 @@ function PrimeStyleTryon({
275
290
  useEffect(() => {
276
291
  if (view !== "sizing-choice" || sizeGuideFetchedRef.current || !apiRef.current) return;
277
292
  sizeGuideFetchedRef.current = true;
293
+ if (sizeGuideProp) {
294
+ setSizeGuide(sizeGuideProp);
295
+ return;
296
+ }
278
297
  setSizeGuideFetching(true);
279
298
  const baseUrl = getApiUrl(apiUrl);
280
299
  const key = getApiKey();
300
+ const productPayload = {
301
+ title: productTitle,
302
+ variants: productVariants || []
303
+ };
304
+ if (productDescription) productPayload.description = productDescription;
305
+ if (productVendor) productPayload.vendor = productVendor;
306
+ if (productType) productPayload.productType = productType;
307
+ if (productTags?.length) productPayload.tags = productTags;
308
+ if (productOptions?.length) productPayload.options = productOptions;
281
309
  fetch(`${baseUrl}/api/v1/sizing/sizeguide`, {
282
310
  method: "POST",
283
311
  headers: { "Content-Type": "application/json", Authorization: `Bearer ${key}` },
284
- body: JSON.stringify({ product: { title: productTitle, variants: [] } })
312
+ body: JSON.stringify({ product: productPayload })
285
313
  }).then((r) => r.ok ? r.json() : null).then((data) => {
286
314
  if (data) setSizeGuide(data);
287
315
  else setSizeGuide({ found: false });
288
316
  }).catch(() => setSizeGuide({ found: false })).finally(() => setSizeGuideFetching(false));
289
- }, [view, apiUrl, productTitle]);
317
+ }, [view, apiUrl, productTitle, sizeGuideProp]);
290
318
  const stepIndex = useMemo(() => {
291
319
  switch (view) {
292
320
  case "welcome":
@@ -394,7 +422,14 @@ function PrimeStyleTryon({
394
422
  const payload = {
395
423
  method: sizingMethod,
396
424
  locale: sizingCountry,
397
- product: { title: productTitle, variants: [] }
425
+ product: {
426
+ title: productTitle,
427
+ description: productDescription || "",
428
+ variants: productVariants || [],
429
+ ...productVendor && { vendor: productVendor },
430
+ ...productType && { productType },
431
+ ...productTags?.length && { tags: productTags }
432
+ }
398
433
  };
399
434
  if (sizeGuide?.found) payload.sizeGuide = sizeGuide;
400
435
  if (sizingMethod === "exact") {
package/dist/types.d.ts CHANGED
@@ -130,6 +130,13 @@ export interface PrimeStyleClassNames {
130
130
  /** Powered by footer */
131
131
  poweredBy?: string;
132
132
  }
133
+ /** Pre-computed size guide data — pass directly to skip AI extraction */
134
+ export interface SizeGuideData {
135
+ found: true;
136
+ title?: string;
137
+ headers: string[];
138
+ rows: string[][];
139
+ }
133
140
  /** Custom events emitted by the component */
134
141
  export interface PrimeStyleEvents {
135
142
  "ps:open": CustomEvent<void>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@primestyleai/tryon",
3
- "version": "2.0.5",
3
+ "version": "2.1.0",
4
4
  "description": "PrimeStyle Virtual Try-On SDK — React component & Web Component",
5
5
  "type": "module",
6
6
  "main": "dist/primestyle-tryon.js",