@wewear/virtual-try-on 1.0.0 → 1.2.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.
- package/dist/api.d.ts +2 -0
- package/dist/camera.d.ts +3 -0
- package/dist/components/button.d.ts +1 -0
- package/dist/components/camera-modal.d.ts +4 -0
- package/dist/components/image-modal.d.ts +1 -0
- package/dist/components/index.d.ts +4 -0
- package/dist/components/review-modal.d.ts +5 -0
- package/dist/constants.d.ts +37 -0
- package/dist/index.d.ts +4 -23
- package/dist/index.esm.js +580 -281
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +580 -280
- package/dist/index.js.map +1 -1
- package/dist/installer.d.ts +0 -17
- package/dist/utils.d.ts +3 -0
- package/dist/widget.d.ts +12 -39
- package/package.json +2 -2
- package/README.md +0 -82
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/widget.ts","../src/installer.ts"],"sourcesContent":["/**\n * WeWear Virtual Try-On Widget Implementation\n *\n * Core widget class that handles virtual try-on functionality integration.\n * Manages button creation, API communication, and modal display.\n */\n\nimport type { VirtualTryOnConfig, VirtualTryOnResult } from \"./index.js\";\n\n/** Default configuration constants */\nconst DEFAULT_CONFIG = {\n BASE_URL: \"https://virtual-try-on-widget.vercel.app\",\n PRODUCT_PAGE_SELECTOR: \"/product/\",\n GALLERY_SELECTOR: \".woocommerce-product-gallery__image\",\n SKU_SELECTOR: \".sku\",\n BUTTON_POSITION: \"bottom-right\" as const,\n} as const;\n\n/** CSS class names for consistent styling */\nconst CSS_CLASSES = {\n BUTTON_CONTAINER: \"wewear-vto-button-container\",\n BUTTON: \"wewear-vto-button\",\n MODAL: \"wewear-vto-modal\",\n} as const;\n\n/** Z-index values for proper layering */\nconst Z_INDEX = {\n BUTTON: 10,\n MODAL: 99999,\n} as const;\n\nexport class VirtualTryOnWidget {\n private readonly config: Required<VirtualTryOnConfig>;\n\n constructor(config: VirtualTryOnConfig = {}) {\n this.config = {\n baseUrl: config.baseUrl || DEFAULT_CONFIG.BASE_URL,\n productPageSelector:\n config.productPageSelector || DEFAULT_CONFIG.PRODUCT_PAGE_SELECTOR,\n gallerySelector:\n config.gallerySelector || DEFAULT_CONFIG.GALLERY_SELECTOR,\n skuSelector: config.skuSelector || DEFAULT_CONFIG.SKU_SELECTOR,\n buttonPosition: config.buttonPosition || DEFAULT_CONFIG.BUTTON_POSITION,\n };\n }\n\n /**\n * Retrieves a cookie value by name\n * @param name - Cookie name to retrieve\n * @returns Cookie value or null if not found\n */\n private getCookie(name: string): string | null {\n if (typeof document === \"undefined\") return null;\n\n const value = `; ${document.cookie}`;\n const parts = value.split(`; ${name}=`);\n\n if (parts.length === 2) {\n const part = parts.pop();\n return part ? part.split(\";\").shift()?.trim() || null : null;\n }\n\n return null;\n }\n\n /**\n * Makes API call to virtual try-on service\n * @param ww_access_token - Optional authentication token\n * @param ww_user_id - User identifier\n * @param ww_product_id - Product identifier\n * @returns Promise with virtual try-on result or null if failed\n */\n private async callVirtualTryOnApi(\n ww_access_token: string | null,\n ww_user_id: string,\n ww_product_id: string,\n ): Promise<VirtualTryOnResult | null> {\n try {\n const response = await fetch(\n `${this.config.baseUrl}/api/virtual-try-on`,\n {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n Accept: \"application/json\",\n },\n body: JSON.stringify({\n ww_access_token,\n ww_user_id,\n ww_product_id,\n }),\n },\n );\n\n if (!response.ok) {\n throw new Error(\n `API responded with status ${response.status}: ${response.statusText}`,\n );\n }\n\n const result = await response.json();\n\n if (!result.imageUrl) {\n throw new Error(\"API response missing imageUrl\");\n }\n\n return result;\n } catch (error) {\n console.error(\"[WeWear VTO] API call failed:\", error);\n return null;\n }\n }\n\n /**\n * Creates the virtual try-on button element\n * @param onClick - Click handler function\n * @returns Button container element\n */\n private createButton(onClick: () => void): HTMLElement {\n const container = document.createElement(\"div\");\n container.className = CSS_CLASSES.BUTTON_CONTAINER;\n\n const positionStyles = this.getPositionStyles();\n container.style.cssText = `\n position: absolute;\n ${positionStyles}\n display: flex;\n border-radius: 50%;\n background: #000000;\n padding: 4px;\n box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);\n z-index: ${Z_INDEX.BUTTON};\n transition: transform 0.2s ease, box-shadow 0.2s ease;\n `;\n\n const button = document.createElement(\"button\");\n button.type = \"button\";\n button.className = CSS_CLASSES.BUTTON;\n button.setAttribute(\"aria-label\", \"Virtual Try-On\");\n button.setAttribute(\"title\", \"Try this product virtually\");\n button.style.cssText = `\n display: flex;\n width: 36px;\n height: 36px;\n cursor: pointer;\n align-items: center;\n justify-content: center;\n border-radius: 50%;\n padding: 10px;\n border: none;\n background: transparent;\n color: #ffffff;\n `;\n\n // Add hover effects\n container.addEventListener(\"mouseenter\", () => {\n container.style.transform = \"scale(1.05)\";\n container.style.boxShadow = \"0 30px 60px -12px rgba(0, 0, 0, 0.35)\";\n });\n\n container.addEventListener(\"mouseleave\", () => {\n container.style.transform = \"scale(1)\";\n container.style.boxShadow = \"0 25px 50px -12px rgba(0, 0, 0, 0.25)\";\n });\n\n button.innerHTML = `\n <svg xmlns=\"http://www.w3.org/2000/svg\" width=\"18\" height=\"18\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" aria-hidden=\"true\">\n <path d=\"M14.5 4h-5L7 7H4a2 2 0 0 0-2 2v9a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2V9a2 2 0 0 0-2-2h-3l-2.5-3z\"></path>\n <circle cx=\"12\" cy=\"13\" r=\"3\"></circle>\n </svg>\n `;\n\n button.onclick = onClick;\n container.appendChild(button);\n return container;\n }\n\n /**\n * Gets CSS position styles based on button position configuration\n * @returns CSS position string\n */\n private getPositionStyles(): string {\n switch (this.config.buttonPosition) {\n case \"bottom-left\":\n return \"left: 20px; bottom: 20px;\";\n case \"top-right\":\n return \"right: 20px; top: 20px;\";\n case \"top-left\":\n return \"left: 20px; top: 20px;\";\n default:\n return \"right: 20px; bottom: 20px;\";\n }\n }\n\n /**\n * Displays the virtual try-on result in a modal\n * @param imageUrl - URL of the virtual try-on image\n */\n private showImageModal(imageUrl: string): void {\n // Remove any existing modals first\n const existingModals = document.querySelectorAll(`.${CSS_CLASSES.MODAL}`);\n existingModals.forEach((modal) => {\n modal.remove();\n });\n\n const modal = document.createElement(\"div\");\n modal.className = CSS_CLASSES.MODAL;\n modal.setAttribute(\"role\", \"dialog\");\n modal.setAttribute(\"aria-modal\", \"true\");\n modal.setAttribute(\"aria-label\", \"Virtual Try-On Result\");\n modal.style.cssText = `\n position: fixed;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n background: rgba(0, 0, 0, 0.8);\n display: flex;\n align-items: center;\n justify-content: center;\n z-index: ${Z_INDEX.MODAL};\n animation: fadeIn 0.3s ease;\n `;\n\n modal.innerHTML = `\n <div style=\"\n background: #ffffff;\n padding: 20px;\n border-radius: 12px;\n max-width: 90vw;\n max-height: 90vh;\n box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);\n animation: slideIn 0.3s ease;\n \">\n <img \n src=\"${imageUrl}\" \n alt=\"Virtual Try-On Result\"\n style=\"\n max-width: 100%;\n max-height: 80vh;\n border-radius: 8px;\n display: block;\n \" \n />\n <div style=\"\n text-align: right;\n margin-top: 15px;\n \">\n <button \n type=\"button\"\n style=\"\n padding: 8px 16px;\n border: none;\n background: #000000;\n color: #ffffff;\n border-radius: 6px;\n cursor: pointer;\n font-size: 14px;\n font-weight: 500;\n transition: background-color 0.2s ease;\n \"\n onmouseover=\"this.style.backgroundColor='#333333'\"\n onmouseout=\"this.style.backgroundColor='#000000'\"\n >\n Close\n </button>\n </div>\n </div>\n <style>\n @keyframes fadeIn {\n from { opacity: 0; }\n to { opacity: 1; }\n }\n @keyframes slideIn {\n from { transform: scale(0.9) translateY(20px); opacity: 0; }\n to { transform: scale(1) translateY(0); opacity: 1; }\n }\n </style>\n `;\n\n const closeButton = modal.querySelector(\"button\");\n const modalContent = modal.querySelector(\"div\");\n\n // Close on button click\n if (closeButton) {\n closeButton.onclick = () => modal.remove();\n }\n\n // Close on backdrop click\n modal.onclick = (e) => {\n if (e.target === modal) {\n modal.remove();\n }\n };\n\n // Prevent content clicks from closing modal\n if (modalContent) {\n modalContent.onclick = (e) => e.stopPropagation();\n }\n\n // Close on Escape key\n const handleEscape = (e: KeyboardEvent) => {\n if (e.key === \"Escape\") {\n modal.remove();\n document.removeEventListener(\"keydown\", handleEscape);\n }\n };\n document.addEventListener(\"keydown\", handleEscape);\n\n document.body.appendChild(modal);\n }\n\n /**\n * Initializes the virtual try-on widget on the current page\n * @returns Promise that resolves when initialization is complete\n */\n public async init(): Promise<void> {\n try {\n // Check if we're on a product page\n if (!window.location.pathname.includes(this.config.productPageSelector)) {\n return;\n }\n\n // Find the gallery container\n const container = document.querySelector(this.config.gallerySelector);\n if (!container || !(container instanceof HTMLElement)) {\n console.warn(\n \"[WeWear VTO] Gallery container not found:\",\n this.config.gallerySelector,\n );\n return;\n }\n\n // Ensure container has relative positioning for button placement\n if (getComputedStyle(container).position === \"static\") {\n container.style.position = \"relative\";\n }\n\n // Create and add the virtual try-on button\n const button = this.createButton(async () => {\n await this.handleTryOnClick();\n });\n\n container.appendChild(button);\n console.log(\"[WeWear VTO] Widget initialized successfully\");\n } catch (error) {\n console.error(\"[WeWear VTO] Initialization failed:\", error);\n }\n }\n\n /**\n * Handles virtual try-on button click\n * @private\n */\n private async handleTryOnClick(): Promise<void> {\n try {\n // Get required data\n const ww_access_token = this.getCookie(\"ww_access_token\");\n const ww_user_id = this.getCookie(\"ww_user_id\");\n const skuElement = document.querySelector(this.config.skuSelector);\n const ww_product_id = skuElement?.textContent?.trim();\n\n // Validate required data\n if (!ww_user_id) {\n console.warn(\"[WeWear VTO] Missing required cookie: ww_user_id\");\n this.showError(\"Please sign in to use virtual try-on\");\n return;\n }\n\n if (!ww_product_id) {\n console.warn(\n \"[WeWear VTO] Product SKU not found:\",\n this.config.skuSelector,\n );\n this.showError(\"Product information not available\");\n return;\n }\n\n // Show loading state (could be implemented)\n console.log(\"[WeWear VTO] Processing virtual try-on request...\");\n\n // Make API call\n const result = await this.callVirtualTryOnApi(\n ww_access_token,\n ww_user_id,\n ww_product_id,\n );\n\n if (result?.imageUrl) {\n this.showImageModal(result.imageUrl);\n } else {\n this.showError(\n \"Virtual try-on service is currently unavailable. Please try again later.\",\n );\n }\n } catch (error) {\n console.error(\"[WeWear VTO] Try-on request failed:\", error);\n this.showError(\"An unexpected error occurred. Please try again.\");\n }\n }\n\n /**\n * Shows an error message to the user\n * @param message - Error message to display\n * @private\n */\n private showError(message: string): void {\n // Simple alert for now - could be enhanced with a custom modal\n alert(`WeWear Virtual Try-On: ${message}`);\n }\n\n /**\n * Destroys the widget and cleans up resources\n */\n public destroy(): void {\n try {\n // Remove all buttons\n const buttons = document.querySelectorAll(\n `.${CSS_CLASSES.BUTTON_CONTAINER}`,\n );\n buttons.forEach((button) => {\n button.remove();\n });\n\n // Remove all modals\n const modals = document.querySelectorAll(`.${CSS_CLASSES.MODAL}`);\n modals.forEach((modal) => {\n modal.remove();\n });\n\n console.log(\"[WeWear VTO] Widget destroyed successfully\");\n } catch (error) {\n console.error(\"[WeWear VTO] Error during widget destruction:\", error);\n }\n }\n}\n","/**\n * WeWear Virtual Try-On Widget Auto-Installer\n *\n * Provides automatic initialization and management of the virtual try-on widget.\n * Handles DOM ready states and widget lifecycle management.\n */\n\nimport type { VirtualTryOnConfig } from \"./index.js\";\nimport { VirtualTryOnWidget } from \"./widget.js\";\n\nlet widgetInstance: VirtualTryOnWidget | null = null;\n\n/**\n * Initializes the virtual try-on widget with optional configuration\n * @param config - Widget configuration options\n */\nexport function initVirtualTryOn(config?: VirtualTryOnConfig): void {\n try {\n // Clean up any existing instance\n if (widgetInstance) {\n widgetInstance.destroy();\n widgetInstance = null;\n }\n\n // Create and initialize new instance\n widgetInstance = new VirtualTryOnWidget(config);\n\n // Initialize immediately if DOM is ready, otherwise wait for it\n if (document.readyState === \"loading\") {\n document.addEventListener(\"DOMContentLoaded\", () => {\n widgetInstance?.init().catch((error) => {\n console.error(\n \"[WeWear VTO] Failed to initialize after DOM ready:\",\n error,\n );\n });\n });\n } else {\n widgetInstance.init().catch((error) => {\n console.error(\"[WeWear VTO] Failed to initialize:\", error);\n });\n }\n } catch (error) {\n console.error(\"[WeWear VTO] Initialization error:\", error);\n }\n}\n\n/**\n * Destroys the current widget instance and cleans up resources\n */\nexport function destroyVirtualTryOn(): void {\n try {\n if (widgetInstance) {\n widgetInstance.destroy();\n widgetInstance = null;\n console.log(\"[WeWear VTO] Widget instance destroyed\");\n }\n } catch (error) {\n console.error(\"[WeWear VTO] Error destroying widget:\", error);\n }\n}\n\n/**\n * Gets the current widget instance (for debugging purposes)\n * @returns Current widget instance or null\n */\nexport function getWidgetInstance(): VirtualTryOnWidget | null {\n return widgetInstance;\n}\n\n// Auto-initialize if window object exists (browser environment)\nif (typeof window !== \"undefined\") {\n initVirtualTryOn();\n}\n"],"names":[],"mappings":";;;;;;IAAA;;;;;IAKG;IAIH;IACA,MAAM,cAAc,GAAG;IACrB,IAAA,QAAQ,EAAE,0CAA0C;IACpD,IAAA,qBAAqB,EAAE,WAAW;IAClC,IAAA,gBAAgB,EAAE,qCAAqC;IACvD,IAAA,YAAY,EAAE,MAAM;IACpB,IAAA,eAAe,EAAE,cAAuB;KAChC;IAEV;IACA,MAAM,WAAW,GAAG;IAClB,IAAA,gBAAgB,EAAE,6BAA6B;IAC/C,IAAA,MAAM,EAAE,mBAAmB;IAC3B,IAAA,KAAK,EAAE,kBAAkB;KACjB;IAEV;IACA,MAAM,OAAO,GAAG;IACd,IAAA,MAAM,EAAE,EAAE;IACV,IAAA,KAAK,EAAE,KAAK;KACJ;UAEG,kBAAkB,CAAA;IAG7B,IAAA,WAAA,CAAY,SAA6B,EAAE,EAAA;YACzC,IAAI,CAAC,MAAM,GAAG;IAC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A,IAAA,IAAd,cAAc,KAAA,KAAA,CAAA,GAAA,KAAA,CAAA,GAAd,cAAc,CAAE,IAAI,EAAA,CAAG,KAAK,CAAC,CAAC,KAAK,KAAI;IACrC,oBAAA,OAAO,CAAC,KAAK,CACX,oDAAoD,EACpD,KAAK,CACN;IACH,gBAAA,CAAC,CAAC;IACJ,YAAA,CAAC,CAAC;YACJ;iBAAO;gBACL,cAAc,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,KAAI;IACpC,gBAAA,OAAO,CAAC,KAAK,CAAC,oCAAoC,EAAE,KAAK,CAAC;IAC5D,YAAA,CAAC,CAAC;YACJ;QACF;QAAE,OAAO,KAAK,EAAE;IACd,QAAA,OAAO,CAAC,KAAK,CAAC,oCAAoC,EAAE,KAAK,CAAC;QAC5D;IACF;IAEA;;IAEG;aACa,mBAAmB,GAAA;IACjC,IAAA,IAAI;YACF,IAAI,cAAc,EAAE;gBAClB,cAAc,CAAC,OAAO,EAAE;gBACxB,cAAc,GAAG,IAAI;IACrB,YAAA,OAAO,CAAC,GAAG,CAAC,wCAAwC,CAAC;YACvD;QACF;QAAE,OAAO,KAAK,EAAE;IACd,QAAA,OAAO,CAAC,KAAK,CAAC,uCAAuC,EAAE,KAAK,CAAC;QAC/D;IACF;IAUA;IACA,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE;IACjC,IAAA,gBAAgB,EAAE;IACpB;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/api.ts","../src/constants.ts","../src/camera.ts","../src/utils.ts","../src/components/button.ts","../src/components/camera-modal.ts","../src/components/image-modal.ts","../src/components/review-modal.ts","../src/widget.ts","../src/installer.ts"],"sourcesContent":["import type { VirtualTryOnResult } from \"./index.js\";\n\nexport async function callVirtualTryOnApi(\n baseUrl: string,\n ww_access_token: string,\n ww_user_id: string,\n ww_product_id: string,\n ww_image: Blob,\n): Promise<VirtualTryOnResult | null> {\n try {\n const formData = new FormData();\n formData.append(\"ww_user_id\", ww_user_id);\n formData.append(\"ww_product_id\", ww_product_id);\n formData.append(\"ww_image\", ww_image, \"captured-image.jpg\");\n formData.append(\"ww_access_token\", ww_access_token);\n\n const response = await fetch(`${baseUrl}/api/virtual-try-on`, {\n method: \"POST\",\n body: formData,\n });\n\n if (!response.ok) {\n console.error(\n \"[WeWear VTO] API request failed:\",\n response.status,\n response.statusText,\n );\n return null;\n }\n\n const result = await response.json();\n console.log(\"[WeWear VTO] API response:\", result);\n return result;\n } catch (error) {\n console.error(\"[WeWear VTO] API call failed:\", error);\n return null;\n }\n}\n","/** Default configuration constants */\nexport const DEFAULT_CONFIG = {\n BASE_URL: \"https://virtual-try-on-widget.vercel.app\",\n PRODUCT_PAGE_SELECTOR: \"/product/\",\n GALLERY_SELECTOR: \".woocommerce-product-gallery__image\",\n SKU_SELECTOR: \".sku\",\n BUTTON_POSITION: \"bottom-right\" as const,\n} as const;\n\n/** CSS class names for consistent styling */\nexport const CSS_CLASSES = {\n BUTTON_CONTAINER: \"wewear-vto-button-container\",\n BUTTON: \"wewear-vto-button\",\n MODAL: \"wewear-vto-modal\",\n} as const;\n\n/** Z-index values for proper layering */\nexport const Z_INDEX = {\n BUTTON: 10,\n MODAL: 99999,\n} as const;\n\n/** Camera constraints for optimal capture */\nexport const CAMERA_CONSTRAINTS = {\n video: {\n width: { ideal: 1280 },\n height: { ideal: 720 },\n facingMode: \"user\", // Front-facing camera\n },\n audio: false,\n} as const;\n\n/** Image capture settings */\nexport const IMAGE_SETTINGS = {\n FORMAT: \"image/jpeg\",\n QUALITY: 0.8,\n} as const;\n","import { CAMERA_CONSTRAINTS, IMAGE_SETTINGS } from \"./constants.js\";\n\nexport async function startCamera(\n video: HTMLVideoElement,\n loadingIndicator: HTMLElement,\n captureButton: HTMLButtonElement,\n): Promise<void> {\n console.log(\"[WeWear VTO] Starting camera...\");\n\n try {\n console.log(\"[WeWear VTO] Requesting camera access...\");\n const stream =\n await navigator.mediaDevices.getUserMedia(CAMERA_CONSTRAINTS);\n video.srcObject = stream;\n\n video.onloadedmetadata = () => {\n console.log(\"[WeWear VTO] Camera stream loaded successfully\");\n loadingIndicator.style.display = \"none\";\n captureButton.style.display = \"flex\";\n };\n } catch (error) {\n console.error(\"[WeWear VTO] Camera access error:\", error);\n loadingIndicator.innerHTML =\n \"Camera access denied. Please allow camera permissions.\";\n }\n}\n\nexport function stopCamera(video: HTMLVideoElement): void {\n const stream = video.srcObject as MediaStream;\n if (stream) {\n const tracks = stream.getTracks();\n tracks.forEach((track) => {\n track.stop();\n });\n video.srcObject = null;\n }\n}\n\nexport async function captureImageFromVideo(\n video: HTMLVideoElement,\n canvas: HTMLCanvasElement,\n): Promise<Blob> {\n // Set canvas dimensions to match video\n canvas.width = video.videoWidth;\n canvas.height = video.videoHeight;\n\n // Draw video frame to canvas\n const ctx = canvas.getContext(\"2d\");\n if (!ctx) {\n throw new Error(\"Could not get canvas context\");\n }\n\n ctx.drawImage(video, 0, 0, canvas.width, canvas.height);\n\n // Convert canvas to blob\n return new Promise<Blob>((resolve, reject) => {\n canvas.toBlob(\n (blob) => {\n if (blob) {\n resolve(blob);\n } else {\n reject(new Error(\"Failed to create blob from canvas\"));\n }\n },\n IMAGE_SETTINGS.FORMAT,\n IMAGE_SETTINGS.QUALITY,\n );\n });\n}\n","export function getCookie(name: string): string | null {\n if (typeof document === \"undefined\") return null;\n\n const value = `; ${document.cookie}`;\n const parts = value.split(`; ${name}=`);\n\n if (parts.length === 2) {\n const part = parts.pop();\n return part ? part.split(\";\").shift()?.trim() || null : null;\n }\n\n return null;\n}\n\nexport function getPositionStyles(position: string): string {\n switch (position) {\n case \"bottom-left\":\n return \"left: 20px; bottom: 20px;\";\n case \"top-right\":\n return \"right: 20px; top: 20px;\";\n case \"top-left\":\n return \"left: 20px; top: 20px;\";\n default:\n return \"right: 20px; bottom: 20px;\";\n }\n}\n\nexport function removeElements(selector: string): void {\n const elements = document.querySelectorAll(selector);\n elements.forEach((element) => {\n element.remove();\n });\n}\n","import { CSS_CLASSES, Z_INDEX } from \"../constants.js\";\nimport { getPositionStyles } from \"../utils.js\";\n\nexport function createButton(\n buttonPosition: string,\n onClick: () => void,\n): HTMLElement {\n const container = document.createElement(\"div\");\n container.className = CSS_CLASSES.BUTTON_CONTAINER;\n\n const positionStyles = getPositionStyles(buttonPosition);\n container.style.cssText = `\n position: absolute;\n ${positionStyles}\n display: flex;\n border-radius: 50%;\n background: #000000;\n padding: 4px;\n box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);\n z-index: ${Z_INDEX.BUTTON};\n `;\n\n const button = document.createElement(\"button\");\n button.type = \"button\";\n button.className = CSS_CLASSES.BUTTON;\n button.setAttribute(\"aria-label\", \"Virtual Try-On\");\n button.style.cssText = `\n display: flex;\n width: 36px;\n height: 36px;\n cursor: pointer;\n align-items: center;\n justify-content: center;\n border-radius: 50%;\n padding: 10px;\n border: none;\n background: transparent;\n color: #ffffff;\n `;\n\n button.innerHTML = `\n <svg xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" class=\"lucide lucide-camera-icon lucide-camera\"><path d=\"M13.997 4a2 2 0 0 1 1.76 1.05l.486.9A2 2 0 0 0 18.003 7H20a2 2 0 0 1 2 2v9a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V9a2 2 0 0 1 2-2h1.997a2 2 0 0 0 1.759-1.048l.489-.904A2 2 0 0 1 10.004 4z\"/><circle cx=\"12\" cy=\"13\" r=\"3\"/></svg>\n `;\n\n button.onclick = onClick;\n container.appendChild(button);\n return container;\n}\n","import { startCamera, stopCamera } from \"../camera.js\";\nimport { CSS_CLASSES, Z_INDEX } from \"../constants.js\";\nimport { removeElements } from \"../utils.js\";\n\nexport interface CameraModalCallbacks {\n onCapture: (\n video: HTMLVideoElement,\n canvas: HTMLCanvasElement,\n ) => Promise<void>;\n}\n\nexport function showCameraModal(callbacks: CameraModalCallbacks): void {\n console.log(\"[WeWear VTO] Opening camera modal...\");\n\n // Remove any existing modals first\n removeElements(`.${CSS_CLASSES.MODAL}`);\n\n // Create modal container\n const modal = document.createElement(\"div\");\n modal.className = CSS_CLASSES.MODAL;\n modal.style.cssText = `\n position: fixed;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n background-color: rgba(0, 0, 0, 0.95);\n display: flex;\n flex-direction: column;\n align-items: center;\n justify-content: center;\n z-index: ${Z_INDEX.MODAL};\n padding: 20px;\n box-sizing: border-box;\n `;\n\n // Create camera container\n const cameraContainer = document.createElement(\"div\");\n cameraContainer.style.cssText = `\n position: relative;\n width: 100%;\n max-width: 500px;\n height: 70vh;\n background-color: #000;\n border-radius: 12px;\n overflow: hidden;\n display: flex;\n flex-direction: column;\n align-items: center;\n justify-content: center;\n `;\n\n // Create video element\n const video = document.createElement(\"video\");\n video.autoplay = true;\n video.playsInline = true;\n video.muted = true;\n video.style.cssText = `\n width: 100%;\n height: 100%;\n object-fit: cover;\n border-radius: 12px;\n `;\n\n // Create canvas for capturing\n const canvas = document.createElement(\"canvas\");\n canvas.style.display = \"none\";\n\n // Create capture button\n const captureButton = document.createElement(\"button\");\n captureButton.innerHTML = \"\";\n captureButton.style.cssText = `\n position: absolute;\n bottom: 20px;\n left: 50%;\n transform: translateX(-50%);\n width: 60px;\n height: 60px;\n border: 3px solid white;\n background-color: rgba(0, 0, 0, 0.7);\n border-radius: 50%;\n cursor: pointer;\n display: none;\n align-items: center;\n justify-content: center;\n transition: all 0.2s ease;\n `;\n\n // Create close button\n const closeButton = document.createElement(\"button\");\n closeButton.innerHTML = \"×\";\n closeButton.style.cssText = `\n position: absolute;\n top: 15px;\n right: 15px;\n width: 40px;\n height: 40px;\n border: none;\n background-color: rgba(0, 0, 0, 0.7);\n color: white;\n font-size: 24px;\n font-weight: bold;\n cursor: pointer;\n border-radius: 50%;\n display: flex;\n align-items: center;\n justify-content: center;\n `;\n\n // Create loading indicator\n const loadingIndicator = document.createElement(\"div\");\n loadingIndicator.innerHTML = \"Initializing camera...\";\n loadingIndicator.style.cssText = `\n color: white;\n font-size: 16px;\n position: absolute;\n top: 50%;\n left: 50%;\n transform: translate(-50%, -50%);\n `;\n\n // Add event listeners\n closeButton.onclick = () => {\n stopCamera(video);\n modal.remove();\n };\n\n captureButton.onclick = async () => {\n await callbacks.onCapture(video, canvas);\n };\n\n // Assemble the camera modal\n cameraContainer.appendChild(video);\n cameraContainer.appendChild(canvas);\n cameraContainer.appendChild(captureButton);\n cameraContainer.appendChild(closeButton);\n cameraContainer.appendChild(loadingIndicator);\n modal.appendChild(cameraContainer);\n\n document.body.appendChild(modal);\n console.log(\"[WeWear VTO] Camera modal added to DOM\");\n\n // Start camera\n startCamera(video, loadingIndicator, captureButton);\n}\n","import { CSS_CLASSES, Z_INDEX } from \"../constants.js\";\nimport { removeElements } from \"../utils.js\";\n\nexport function showImageModal(imageUrl: string): void {\n // Remove any existing modals first\n removeElements(`.${CSS_CLASSES.MODAL}`);\n\n // Create modal container\n const modal = document.createElement(\"div\");\n modal.className = CSS_CLASSES.MODAL;\n modal.style.cssText = `\n position: fixed;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n background-color: rgba(0, 0, 0, 0.9);\n display: flex;\n align-items: center;\n justify-content: center;\n z-index: ${Z_INDEX.MODAL};\n padding: 20px;\n box-sizing: border-box;\n `;\n\n // Create image container\n const imageContainer = document.createElement(\"div\");\n imageContainer.style.cssText = `\n position: relative;\n width: 100%;\n max-width: 500px;\n height: 70vh;\n background-color: #000;\n border-radius: 12px;\n overflow: hidden;\n display: flex;\n flex-direction: column;\n align-items: center;\n justify-content: center;\n `;\n\n // Create image element\n const image = document.createElement(\"img\");\n image.src = imageUrl;\n image.alt = \"Virtual Try-On Result\";\n image.style.cssText = `\n width: 100%;\n height: 100%;\n object-fit: cover;\n border-radius: 12px;\n `;\n\n // Create close button\n const closeButton = document.createElement(\"button\");\n closeButton.innerHTML = \"×\";\n closeButton.style.cssText = `\n position: absolute;\n top: 15px;\n right: 15px;\n width: 40px;\n height: 40px;\n border: none;\n background-color: rgba(0, 0, 0, 0.7);\n color: white;\n font-size: 24px;\n font-weight: bold;\n cursor: pointer;\n border-radius: 50%;\n display: flex;\n align-items: center;\n justify-content: center;\n `;\n\n closeButton.onclick = () => {\n modal.remove();\n };\n\n // Close on backdrop click\n modal.onclick = (e) => {\n if (e.target === modal) {\n modal.remove();\n }\n };\n\n // Close on Escape key\n const handleEscape = (e: KeyboardEvent) => {\n if (e.key === \"Escape\") {\n modal.remove();\n document.removeEventListener(\"keydown\", handleEscape);\n }\n };\n document.addEventListener(\"keydown\", handleEscape);\n\n imageContainer.appendChild(image);\n imageContainer.appendChild(closeButton);\n modal.appendChild(imageContainer);\n document.body.appendChild(modal);\n}\n","import { CSS_CLASSES, Z_INDEX } from \"../constants.js\";\nimport { removeElements } from \"../utils.js\";\n\nexport interface ReviewModalCallbacks {\n onRetake: () => void;\n onAccept: (imageBlob: Blob) => Promise<void>;\n}\n\nexport function showReviewModal(\n imageBlob: Blob,\n callbacks: ReviewModalCallbacks,\n): void {\n console.log(\"[WeWear VTO] Opening review modal...\");\n\n // Remove any existing modals first\n removeElements(`.${CSS_CLASSES.MODAL}`);\n\n // Create image URL for preview\n const imageUrl = URL.createObjectURL(imageBlob);\n\n // Create modal container\n const modal = document.createElement(\"div\");\n modal.className = CSS_CLASSES.MODAL;\n modal.style.cssText = `\n position: fixed;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n background-color: rgba(0, 0, 0, 0.95);\n display: flex;\n flex-direction: column;\n align-items: center;\n justify-content: center;\n z-index: ${Z_INDEX.MODAL};\n padding: 20px;\n box-sizing: border-box;\n `;\n\n // Create review container\n const reviewContainer = document.createElement(\"div\");\n reviewContainer.style.cssText = `\n position: relative;\n width: 100%;\n max-width: 500px;\n height: 70vh;\n background-color: #000;\n border-radius: 12px;\n overflow: hidden;\n display: flex;\n flex-direction: column;\n align-items: center;\n justify-content: center;\n `;\n\n // Create image element\n const image = document.createElement(\"img\");\n image.src = imageUrl;\n image.alt = \"Review your photo\";\n image.style.cssText = `\n width: 100%;\n height: 100%;\n object-fit: cover;\n border-radius: 12px;\n `;\n\n // Create close button\n const closeButton = document.createElement(\"button\");\n closeButton.innerHTML = \"×\";\n closeButton.style.cssText = `\n position: absolute;\n top: 15px;\n right: 15px;\n width: 40px;\n height: 40px;\n border: none;\n background-color: rgba(0, 0, 0, 0.7);\n color: white;\n font-size: 24px;\n font-weight: bold;\n cursor: pointer;\n border-radius: 50%;\n display: flex;\n align-items: center;\n justify-content: center;\n `;\n\n // Create button container\n const buttonContainer = document.createElement(\"div\");\n buttonContainer.style.cssText = `\n position: absolute;\n bottom: 20px;\n left: 50%;\n transform: translateX(-50%);\n display: flex;\n gap: 15px;\n width: calc(100% - 40px);\n max-width: 300px;\n `;\n\n // Create retake button\n const retakeButton = document.createElement(\"button\");\n retakeButton.textContent = \"Retake\";\n retakeButton.style.cssText = `\n flex: 1;\n padding: 12px 24px;\n background-color: rgba(0, 0, 0, 0.7);\n color: white;\n border-radius: 8px;\n border: none;\n font-size: 16px;\n font-weight: 600;\n cursor: pointer;\n transition: all 0.2s ease;\n `;\n\n // Create use photo button\n const usePhotoButton = document.createElement(\"button\");\n usePhotoButton.textContent = \"Use Photo\";\n usePhotoButton.style.cssText = `\n flex: 1;\n padding: 12px 24px;\n background-color: rgba(0, 0, 0, 0.7);\n color: white;\n border-radius: 8px;\n border: none;\n font-size: 16px;\n font-weight: 600;\n cursor: pointer;\n transition: all 0.2s ease;\n `;\n\n // Add event listeners\n closeButton.onclick = () => {\n URL.revokeObjectURL(imageUrl); // Clean up\n modal.remove();\n };\n\n retakeButton.onclick = () => {\n URL.revokeObjectURL(imageUrl); // Clean up\n modal.remove();\n callbacks.onRetake();\n };\n\n usePhotoButton.onclick = async () => {\n URL.revokeObjectURL(imageUrl); // Clean up\n modal.remove();\n await callbacks.onAccept(imageBlob);\n };\n\n // Assemble the review modal\n buttonContainer.appendChild(retakeButton);\n buttonContainer.appendChild(usePhotoButton);\n reviewContainer.appendChild(image);\n reviewContainer.appendChild(closeButton);\n reviewContainer.appendChild(buttonContainer);\n modal.appendChild(reviewContainer);\n\n document.body.appendChild(modal);\n console.log(\"[WeWear VTO] Review modal added to DOM\");\n}\n","import { callVirtualTryOnApi } from \"./api.js\";\nimport { captureImageFromVideo, stopCamera } from \"./camera.js\";\nimport {\n type CameraModalCallbacks,\n createButton,\n type ReviewModalCallbacks,\n showCameraModal,\n showImageModal,\n showReviewModal,\n} from \"./components/index.js\";\nimport { CSS_CLASSES, DEFAULT_CONFIG } from \"./constants.js\";\nimport type { VirtualTryOnConfig } from \"./index.js\";\nimport { getCookie, removeElements } from \"./utils.js\";\n\nexport class VirtualTryOnWidget {\n private readonly config: Required<VirtualTryOnConfig>;\n\n constructor(config: VirtualTryOnConfig = {}) {\n this.config = {\n baseUrl: config.baseUrl || DEFAULT_CONFIG.BASE_URL,\n productPageSelector:\n config.productPageSelector || DEFAULT_CONFIG.PRODUCT_PAGE_SELECTOR,\n gallerySelector:\n config.gallerySelector || DEFAULT_CONFIG.GALLERY_SELECTOR,\n skuSelector: config.skuSelector || DEFAULT_CONFIG.SKU_SELECTOR,\n buttonPosition: config.buttonPosition || DEFAULT_CONFIG.BUTTON_POSITION,\n };\n }\n\n /**\n * Initializes the virtual try-on widget on the current page\n * @returns Promise that resolves when initialization is complete\n */\n public async init(): Promise<void> {\n try {\n // Check if we're on a product page\n if (!window.location.pathname.includes(this.config.productPageSelector)) {\n return;\n }\n\n // Find the gallery container\n const container = document.querySelector(this.config.gallerySelector);\n if (!container || !(container instanceof HTMLElement)) {\n console.warn(\n \"[WeWear VTO] Gallery container not found:\",\n this.config.gallerySelector,\n );\n return;\n }\n\n // Ensure container has relative positioning for button placement\n if (getComputedStyle(container).position === \"static\") {\n container.style.position = \"relative\";\n }\n\n // Create and add the virtual try-on button\n const button = createButton(this.config.buttonPosition, async () => {\n await this.handleTryOnClick();\n });\n\n container.appendChild(button);\n console.log(\"[WeWear VTO] Widget initialized successfully\");\n } catch (error) {\n console.error(\"[WeWear VTO] Initialization failed:\", error);\n }\n }\n\n /**\n * Handles virtual try-on button click\n * @private\n */\n private async handleTryOnClick(): Promise<void> {\n console.log(\"[WeWear VTO] Button clicked, starting try-on process...\");\n\n try {\n // Get required data\n const ww_access_token = getCookie(\"ww_access_token\");\n const ww_user_id = getCookie(\"ww_user_id\");\n const skuElement = document.querySelector(this.config.skuSelector);\n const ww_product_id = skuElement?.textContent?.trim();\n\n console.log(\"[WeWear VTO] Retrieved data:\", {\n ww_user_id,\n ww_product_id,\n ww_access_token,\n });\n\n // Validate required data\n if (!ww_user_id) {\n console.warn(\"[WeWear VTO] Missing required cookie: ww_user_id\");\n return;\n }\n\n if (!ww_product_id) {\n console.warn(\n \"[WeWear VTO] Product SKU not found:\",\n this.config.skuSelector,\n );\n return;\n }\n\n if (!ww_access_token) {\n console.warn(\"[WeWear VTO] Missing required cookie: ww_access_token\");\n return;\n }\n\n // Show camera capture modal\n this.showCameraModalWithCallbacks(\n ww_access_token,\n ww_user_id,\n ww_product_id,\n );\n } catch (error) {\n console.error(\"[WeWear VTO] Try-on request failed:\", error);\n }\n }\n\n /**\n * Shows camera modal with appropriate callbacks\n * @private\n */\n private showCameraModalWithCallbacks(\n ww_access_token: string,\n ww_user_id: string,\n ww_product_id: string,\n ): void {\n const callbacks: CameraModalCallbacks = {\n onCapture: async (video: HTMLVideoElement, canvas: HTMLCanvasElement) => {\n try {\n // Capture image from video\n const imageBlob = await captureImageFromVideo(video, canvas);\n\n // Stop camera and show review modal\n stopCamera(video);\n\n // Show review modal instead of immediately processing\n this.showReviewModalWithCallbacks(\n imageBlob,\n ww_access_token,\n ww_user_id,\n ww_product_id,\n );\n } catch (error) {\n console.error(\"[WeWear VTO] Image capture error:\", error);\n }\n },\n };\n\n showCameraModal(callbacks);\n }\n\n /**\n * Shows review modal with appropriate callbacks\n * @private\n */\n private showReviewModalWithCallbacks(\n imageBlob: Blob,\n ww_access_token: string,\n ww_user_id: string,\n ww_product_id: string,\n ): void {\n const callbacks: ReviewModalCallbacks = {\n onRetake: () => {\n // Reopen camera modal\n this.showCameraModalWithCallbacks(\n ww_access_token,\n ww_user_id,\n ww_product_id,\n );\n },\n onAccept: async (acceptedImageBlob: Blob) => {\n await this.processAcceptedImage(\n acceptedImageBlob,\n ww_access_token,\n ww_user_id,\n ww_product_id,\n );\n },\n };\n\n showReviewModal(imageBlob, callbacks);\n }\n\n /**\n * Processes the accepted image by calling the API\n * @private\n */\n private async processAcceptedImage(\n imageBlob: Blob,\n ww_access_token: string,\n ww_user_id: string,\n ww_product_id: string,\n ): Promise<void> {\n try {\n console.log(\"[WeWear VTO] Processing accepted image...\");\n\n // Call the API with the accepted image\n const result = await callVirtualTryOnApi(\n this.config.baseUrl,\n ww_access_token,\n ww_user_id,\n ww_product_id,\n imageBlob,\n );\n\n if (result?.imageUrl) {\n showImageModal(result.imageUrl);\n } else {\n console.error(\"[WeWear VTO] Invalid API response:\", result);\n }\n } catch (error) {\n console.error(\"[WeWear VTO] Error processing accepted image:\", error);\n }\n }\n\n /**\n * Destroys the widget and cleans up resources\n */\n public destroy(): void {\n try {\n // Remove all buttons\n removeElements(`.${CSS_CLASSES.BUTTON_CONTAINER}`);\n\n // Remove all modals\n removeElements(`.${CSS_CLASSES.MODAL}`);\n\n console.log(\"[WeWear VTO] Widget destroyed successfully\");\n } catch (error) {\n console.error(\"[WeWear VTO] Error during widget destruction:\", error);\n }\n }\n}\n","import type { VirtualTryOnConfig } from \"./index.js\";\nimport { VirtualTryOnWidget } from \"./widget.js\";\n\nlet widgetInstance: VirtualTryOnWidget | null = null;\n\nexport function initVirtualTryOn(config?: VirtualTryOnConfig): void {\n try {\n // Clean up any existing instance\n if (widgetInstance) {\n widgetInstance.destroy();\n widgetInstance = null;\n }\n\n // Create and initialize new instance\n widgetInstance = new VirtualTryOnWidget(config);\n\n // Initialize immediately if DOM is ready, otherwise wait for it\n if (document.readyState === \"loading\") {\n document.addEventListener(\"DOMContentLoaded\", () => {\n widgetInstance?.init().catch((error) => {\n console.error(\n \"[WeWear VTO] Failed to initialize after DOM ready:\",\n error,\n );\n });\n });\n } else {\n widgetInstance.init().catch((error) => {\n console.error(\"[WeWear VTO] Failed to initialize:\", error);\n });\n }\n } catch (error) {\n console.error(\"[WeWear VTO] Initialization error:\", error);\n }\n}\n\nexport function destroyVirtualTryOn(): void {\n try {\n if (widgetInstance) {\n widgetInstance.destroy();\n widgetInstance = null;\n console.log(\"[WeWear VTO] Widget instance destroyed\");\n }\n } catch (error) {\n console.error(\"[WeWear VTO] Error destroying widget:\", error);\n }\n}\n\nexport function getWidgetInstance(): VirtualTryOnWidget | null {\n return widgetInstance;\n}\n\nif (typeof window !== \"undefined\") {\n initVirtualTryOn();\n}\n"],"names":[],"mappings":";;;;;;IAEO,eAAe,mBAAmB,CACrC,OAAe,EACf,eAAuB,EACvB,UAAkB,EAClB,aAAqB,EACrB,QAAc,EAAA;IAEd,IAAA,IAAI;IACA,QAAA,MAAM,QAAQ,GAAG,IAAI,QAAQ,EAAE;IAC/B,QAAA,QAAQ,CAAC,MAAM,CAAC,YAAY,EAAE,UAAU,CAAC;IACzC,QAAA,QAAQ,CAAC,MAAM,CAAC,eAAe,EAAE,aAAa,CAAC;YAC/C,QAAQ,CAAC,MAAM,CAAC,UAAU,EAAE,QAAQ,EAAE,oBAAoB,CAAC;IAC3D,QAAA,QAAQ,CAAC,MAAM,CAAC,iBAAiB,EAAE,eAAe,CAAC;YAEnD,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,CAAA,EAAG,OAAO,qBAAqB,EAAE;IAC1D,YAAA,MAAM,EAAE,MAAM;IACd,YAAA,IAAI,EAAE,QAAQ;IACjB,SAAA,CAAC;IAEF,QAAA,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE;IACd,YAAA,OAAO,CAAC,KAAK,CACT,kCAAkC,EAClC,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AAC,KAAK,KAAI;IACnC,oBAAA,OAAO,CAAC,KAAK,CACT,oDAAoD,EACpD,KAAK,CACR;IACL,gBAAA,CAAC,CAAC;IACN,YAAA,CAAC,CAAC;YACN;iBAAO;gBACH,cAAc,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,KAAI;IAClC,gBAAA,OAAO,CAAC,KAAK,CAAC,oCAAoC,EAAE,KAAK,CAAC;IAC9D,YAAA,CAAC,CAAC;YACN;QACJ;QAAE,OAAO,KAAK,EAAE;IACZ,QAAA,OAAO,CAAC,KAAK,CAAC,oCAAoC,EAAE,KAAK,CAAC;QAC9D;IACJ;aAEgB,mBAAmB,GAAA;IAC/B,IAAA,IAAI;YACA,IAAI,cAAc,EAAE;gBAChB,cAAc,CAAC,OAAO,EAAE;gBACxB,cAAc,GAAG,IAAI;IACrB,YAAA,OAAO,CAAC,GAAG,CAAC,wCAAwC,CAAC;YACzD;QACJ;QAAE,OAAO,KAAK,EAAE;IACZ,QAAA,OAAO,CAAC,KAAK,CAAC,uCAAuC,EAAE,KAAK,CAAC;QACjE;IACJ;aAEgB,iBAAiB,GAAA;IAC7B,IAAA,OAAO,cAAc;IACzB;IAEA,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE;IAC/B,IAAA,gBAAgB,EAAE;IACtB;;;;;;;;;;;"}
|
package/dist/installer.d.ts
CHANGED
|
@@ -1,22 +1,5 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* WeWear Virtual Try-On Widget Auto-Installer
|
|
3
|
-
*
|
|
4
|
-
* Provides automatic initialization and management of the virtual try-on widget.
|
|
5
|
-
* Handles DOM ready states and widget lifecycle management.
|
|
6
|
-
*/
|
|
7
1
|
import type { VirtualTryOnConfig } from "./index.js";
|
|
8
2
|
import { VirtualTryOnWidget } from "./widget.js";
|
|
9
|
-
/**
|
|
10
|
-
* Initializes the virtual try-on widget with optional configuration
|
|
11
|
-
* @param config - Widget configuration options
|
|
12
|
-
*/
|
|
13
3
|
export declare function initVirtualTryOn(config?: VirtualTryOnConfig): void;
|
|
14
|
-
/**
|
|
15
|
-
* Destroys the current widget instance and cleans up resources
|
|
16
|
-
*/
|
|
17
4
|
export declare function destroyVirtualTryOn(): void;
|
|
18
|
-
/**
|
|
19
|
-
* Gets the current widget instance (for debugging purposes)
|
|
20
|
-
* @returns Current widget instance or null
|
|
21
|
-
*/
|
|
22
5
|
export declare function getWidgetInstance(): VirtualTryOnWidget | null;
|
package/dist/utils.d.ts
ADDED
package/dist/widget.d.ts
CHANGED
|
@@ -1,43 +1,7 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* WeWear Virtual Try-On Widget Implementation
|
|
3
|
-
*
|
|
4
|
-
* Core widget class that handles virtual try-on functionality integration.
|
|
5
|
-
* Manages button creation, API communication, and modal display.
|
|
6
|
-
*/
|
|
7
1
|
import type { VirtualTryOnConfig } from "./index.js";
|
|
8
2
|
export declare class VirtualTryOnWidget {
|
|
9
3
|
private readonly config;
|
|
10
4
|
constructor(config?: VirtualTryOnConfig);
|
|
11
|
-
/**
|
|
12
|
-
* Retrieves a cookie value by name
|
|
13
|
-
* @param name - Cookie name to retrieve
|
|
14
|
-
* @returns Cookie value or null if not found
|
|
15
|
-
*/
|
|
16
|
-
private getCookie;
|
|
17
|
-
/**
|
|
18
|
-
* Makes API call to virtual try-on service
|
|
19
|
-
* @param ww_access_token - Optional authentication token
|
|
20
|
-
* @param ww_user_id - User identifier
|
|
21
|
-
* @param ww_product_id - Product identifier
|
|
22
|
-
* @returns Promise with virtual try-on result or null if failed
|
|
23
|
-
*/
|
|
24
|
-
private callVirtualTryOnApi;
|
|
25
|
-
/**
|
|
26
|
-
* Creates the virtual try-on button element
|
|
27
|
-
* @param onClick - Click handler function
|
|
28
|
-
* @returns Button container element
|
|
29
|
-
*/
|
|
30
|
-
private createButton;
|
|
31
|
-
/**
|
|
32
|
-
* Gets CSS position styles based on button position configuration
|
|
33
|
-
* @returns CSS position string
|
|
34
|
-
*/
|
|
35
|
-
private getPositionStyles;
|
|
36
|
-
/**
|
|
37
|
-
* Displays the virtual try-on result in a modal
|
|
38
|
-
* @param imageUrl - URL of the virtual try-on image
|
|
39
|
-
*/
|
|
40
|
-
private showImageModal;
|
|
41
5
|
/**
|
|
42
6
|
* Initializes the virtual try-on widget on the current page
|
|
43
7
|
* @returns Promise that resolves when initialization is complete
|
|
@@ -49,11 +13,20 @@ export declare class VirtualTryOnWidget {
|
|
|
49
13
|
*/
|
|
50
14
|
private handleTryOnClick;
|
|
51
15
|
/**
|
|
52
|
-
* Shows
|
|
53
|
-
* @
|
|
16
|
+
* Shows camera modal with appropriate callbacks
|
|
17
|
+
* @private
|
|
18
|
+
*/
|
|
19
|
+
private showCameraModalWithCallbacks;
|
|
20
|
+
/**
|
|
21
|
+
* Shows review modal with appropriate callbacks
|
|
22
|
+
* @private
|
|
23
|
+
*/
|
|
24
|
+
private showReviewModalWithCallbacks;
|
|
25
|
+
/**
|
|
26
|
+
* Processes the accepted image by calling the API
|
|
54
27
|
* @private
|
|
55
28
|
*/
|
|
56
|
-
private
|
|
29
|
+
private processAcceptedImage;
|
|
57
30
|
/**
|
|
58
31
|
* Destroys the widget and cleans up resources
|
|
59
32
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wewear/virtual-try-on",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Virtual Try-On widget for e-commerce integration",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"peerDependencies": {},
|
|
32
32
|
"repository": {
|
|
33
33
|
"type": "git",
|
|
34
|
-
"url": "https://github.com/wewearita/virtual-try-on-widget.git",
|
|
34
|
+
"url": "git+https://github.com/wewearita/virtual-try-on-widget.git",
|
|
35
35
|
"directory": "packages/wewear-virtual-try-on"
|
|
36
36
|
}
|
|
37
37
|
}
|
package/README.md
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
# @wewear/virtual-try-on
|
|
2
|
-
|
|
3
|
-
A lightweight virtual try-on widget for WooCommerce integration.
|
|
4
|
-
|
|
5
|
-
## Installation
|
|
6
|
-
|
|
7
|
-
```bash
|
|
8
|
-
npm install @wewear/virtual-try-on
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
## Usage
|
|
12
|
-
|
|
13
|
-
### Basic Usage (Auto-initialization)
|
|
14
|
-
|
|
15
|
-
Simply include the script in your page and it will automatically initialize:
|
|
16
|
-
|
|
17
|
-
```html
|
|
18
|
-
<script src="node_modules/@wewear/virtual-try-on/dist/index.js"></script>
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
### Manual Initialization
|
|
22
|
-
|
|
23
|
-
```javascript
|
|
24
|
-
import { initVirtualTryOn } from '@wewear/virtual-try-on';
|
|
25
|
-
|
|
26
|
-
// Initialize with default configuration
|
|
27
|
-
initVirtualTryOn();
|
|
28
|
-
|
|
29
|
-
// Or with custom configuration
|
|
30
|
-
initVirtualTryOn({
|
|
31
|
-
baseUrl: 'https://your-custom-api.com',
|
|
32
|
-
buttonPosition: 'top-right',
|
|
33
|
-
gallerySelector: '.custom-gallery-selector'
|
|
34
|
-
});
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
### Using the Widget Class
|
|
38
|
-
|
|
39
|
-
```javascript
|
|
40
|
-
import { VirtualTryOnWidget } from '@wewear/virtual-try-on';
|
|
41
|
-
|
|
42
|
-
const widget = new VirtualTryOnWidget({
|
|
43
|
-
baseUrl: 'https://your-api.com',
|
|
44
|
-
buttonPosition: 'bottom-left'
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
widget.init();
|
|
48
|
-
|
|
49
|
-
// Later, destroy the widget
|
|
50
|
-
widget.destroy();
|
|
51
|
-
```
|
|
52
|
-
|
|
53
|
-
## Configuration Options
|
|
54
|
-
|
|
55
|
-
| Option | Type | Default | Description |
|
|
56
|
-
|--------|------|---------|-------------|
|
|
57
|
-
| `baseUrl` | string | `'https://virtual-try-on-widget.vercel.app'` | Base URL for the virtual try-on API |
|
|
58
|
-
| `productPageSelector` | string | `'/product/'` | URL path pattern to identify product pages |
|
|
59
|
-
| `gallerySelector` | string | `'.woocommerce-product-gallery__image'` | CSS selector for the product gallery container |
|
|
60
|
-
| `skuSelector` | string | `'.sku'` | CSS selector for the product SKU element |
|
|
61
|
-
| `buttonPosition` | string | `'bottom-right'` | Position of the try-on button (`'bottom-right'`, `'bottom-left'`, `'top-right'`, `'top-left'`) |
|
|
62
|
-
|
|
63
|
-
## Requirements
|
|
64
|
-
|
|
65
|
-
- The page must have cookies set for `ww_user_id` (required) and `ww_access_token` (optional)
|
|
66
|
-
- The product page must contain an element matching the `skuSelector` with the product SKU
|
|
67
|
-
- The product gallery must contain an element matching the `gallerySelector`
|
|
68
|
-
|
|
69
|
-
## API
|
|
70
|
-
|
|
71
|
-
### Functions
|
|
72
|
-
|
|
73
|
-
- `initVirtualTryOn(config?: VirtualTryOnConfig)` - Initialize the virtual try-on widget
|
|
74
|
-
- `destroyVirtualTryOn()` - Destroy the current widget instance
|
|
75
|
-
|
|
76
|
-
### Classes
|
|
77
|
-
|
|
78
|
-
- `VirtualTryOnWidget` - Main widget class for advanced usage
|
|
79
|
-
|
|
80
|
-
## License
|
|
81
|
-
|
|
82
|
-
MIT
|