-
Notifications
You must be signed in to change notification settings - Fork 0
feat(products): add designer customizable products #105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 14 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
ea22100
feat(customizations): add product customization capability model and …
4498f5c
Merge pull request #98 from henri318/feat/customizations-backend-pr1
henri318 3e3150f
feat(customizations): add PDP customization preview experience
faa7298
Merge pull request #100 from henri318/feat/customizations-frontend-pr2
henri318 c2e4dcd
Merge remote-tracking branch 'origin/main' into feat/product-customiz…
8072e19
Merge remote-tracking branch 'origin/main' into feat/designer-customi…
2e20299
feat(products): add designer customizable products
e1f6dc4
customize your order design
a633000
fix test
431c481
fix typescript
c26333c
Merge pull request #111 from henri318/feat/designer-customizable-prod…
henri318 512eaac
merge
5577256
merge
baff07d
merge fix
240d8b8
fix ci
ed2e272
fix test
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| { | ||
| "fingerprint": "d11040d9c59a89af514af78b245d01c57a37d79a" | ||
| "fingerprint": "52eb4455fccd840aa5bcee63cf799aa6f1f7fb3e" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,3 +39,6 @@ yarn-error.log* | |
| # typescript | ||
| *.tsbuildinfo | ||
| next-env.d.ts | ||
|
|
||
| # local agent/tool state | ||
| .serena/ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| export { CartView } from '@/modules/cart/presentation/components/cart-view'; | ||
| export type { CartItemDTO } from '@/modules/cart/presentation/components/cart-view'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,139 @@ | ||
| 'use client'; | ||
|
|
||
| import { useEffect, useRef } from 'react'; | ||
|
|
||
| export interface DesignPositionData { | ||
| imageUrl: string; | ||
| x: number; | ||
| y: number; | ||
| scale: number; | ||
| rotation_deg: number; | ||
| opacity: number; | ||
| blend_mode: string; | ||
| } | ||
|
|
||
| interface DesignPreviewProps { | ||
| productImageUrl: string; | ||
| designImageUrl: string; | ||
| designPosition: DesignPositionData; | ||
| width?: number; | ||
| height?: number; | ||
| borderRadius?: number; | ||
| } | ||
|
|
||
| export function DesignPreview({ | ||
| productImageUrl, | ||
| designImageUrl, | ||
| designPosition, | ||
| width = 100, | ||
| height = 100, | ||
| borderRadius = 6, | ||
| }: DesignPreviewProps) { | ||
| const canvasRef = useRef<HTMLCanvasElement | null>(null); | ||
|
|
||
| useEffect(() => { | ||
| let cancelled = false; | ||
|
|
||
| async function draw() { | ||
| const c = canvasRef.current?.getContext('2d'); | ||
| if (!c) return; | ||
|
|
||
| const productImg = await loadImage(productImageUrl); | ||
| const designImg = await loadImage(designImageUrl); | ||
| if (cancelled) return; | ||
|
|
||
| c.clearRect(0, 0, width, height); | ||
| c.fillStyle = '#f4f2e6'; | ||
| c.fillRect(0, 0, width, height); | ||
|
|
||
| if (productImg) { | ||
| drawCover(c, productImg, width, height); | ||
| } | ||
|
|
||
| if (designImg) { | ||
| c.globalCompositeOperation = | ||
| designPosition.blend_mode === 'multiply' | ||
| ? 'multiply' | ||
| : ('source-over' as GlobalCompositeOperation); | ||
| c.globalAlpha = designPosition.opacity / 100; | ||
| drawDesign(c, designImg, designPosition, width, height); | ||
| } | ||
| } | ||
|
|
||
| draw(); | ||
|
|
||
| return () => { | ||
| cancelled = true; | ||
| }; | ||
| }, [productImageUrl, designImageUrl, designPosition, width, height]); | ||
|
|
||
| return ( | ||
| <canvas | ||
| ref={canvasRef} | ||
| width={width} | ||
| height={height} | ||
| style={{ | ||
| width, | ||
| height, | ||
| borderRadius, | ||
| display: 'block', | ||
| flexShrink: 0, | ||
| }} | ||
| /> | ||
| ); | ||
| } | ||
|
|
||
| function loadImage(src: string): Promise<HTMLImageElement | null> { | ||
| return new Promise((resolve) => { | ||
| const img = new Image(); | ||
| img.crossOrigin = 'anonymous'; | ||
| img.onload = () => resolve(img); | ||
| img.onerror = () => resolve(null); | ||
| img.src = src; | ||
| }); | ||
| } | ||
|
|
||
| function drawCover( | ||
| ctx: CanvasRenderingContext2D, | ||
| image: HTMLImageElement, | ||
| width: number, | ||
| height: number, | ||
| ) { | ||
| const ratio = image.naturalWidth / image.naturalHeight; | ||
| const targetRatio = width / height; | ||
| let drawWidth: number; | ||
| let drawHeight: number; | ||
|
|
||
| if (ratio > targetRatio) { | ||
| drawHeight = height; | ||
| drawWidth = height * ratio; | ||
| } else { | ||
| drawWidth = width; | ||
| drawHeight = width / ratio; | ||
| } | ||
|
|
||
| const offsetX = (width - drawWidth) / 2; | ||
| const offsetY = (height - drawHeight) / 2; | ||
| ctx.drawImage(image, offsetX, offsetY, drawWidth, drawHeight); | ||
| } | ||
|
|
||
| function drawDesign( | ||
| ctx: CanvasRenderingContext2D, | ||
| image: HTMLImageElement, | ||
| position: DesignPositionData, | ||
| width: number, | ||
| height: number, | ||
| ) { | ||
| const scaleFactor = position.scale / 100; | ||
| const baseWidth = Math.min(width, image.naturalWidth); | ||
| const ratio = image.naturalHeight / image.naturalWidth; | ||
| const drawWidth = baseWidth * scaleFactor; | ||
| const drawHeight = drawWidth * ratio; | ||
|
|
||
| const centerX = position.x * width; | ||
| const centerY = position.y * height; | ||
|
|
||
| ctx.translate(centerX, centerY); | ||
| ctx.rotate((position.rotation_deg * Math.PI) / 180); | ||
| ctx.drawImage(image, -drawWidth / 2, -drawHeight / 2, drawWidth, drawHeight); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
El estado del contexto 2D no se reinicia entre repintados.
drawDesignaplicatranslate/rotatesobre la matriz del contexto, perodraw()nunca la restablece. Como el mismo<canvas>/contexto persiste entre renders, en el siguiente repintadoclearRect/fillRect/drawCoverse ejecutan bajo la matriz transformada del render anterior, yglobalAlpha/globalCompositeOperationtambién quedan con valores residuales. Esto produce recortes y posiciones incorrectas tras cambiardesignPosition,widthoheight.🐛 Reinicio de la matriz y guardado del estado del contexto
const productImg = await loadImage(productImageUrl); const designImg = await loadImage(designImageUrl); if (cancelled) return; + c.setTransform(1, 0, 0, 1, 0, 0); + c.globalAlpha = 1; + c.globalCompositeOperation = 'source-over'; c.clearRect(0, 0, width, height); c.fillStyle = '`#f4f2e6`'; c.fillRect(0, 0, width, height); if (productImg) { drawCover(c, productImg, width, height); } if (designImg) { + c.save(); c.globalCompositeOperation = designPosition.blend_mode === 'multiply' ? 'multiply' : ('source-over' as GlobalCompositeOperation); c.globalAlpha = designPosition.opacity / 100; drawDesign(c, designImg, designPosition, width, height); + c.restore(); }📝 Committable suggestion
🤖 Prompt for AI Agents