-
Notifications
You must be signed in to change notification settings - Fork 1
Piyush/enhancements #6
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
base: IK-2461/enhancements
Are you sure you want to change the base?
Conversation
…ma with validation and integration
… with enhanced validation and default values
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.
Pull request overview
This PR adds image enhancement features to both base images and layers, including trim, color replace, border, and sharpen transformations.
Changes:
- Added four new adjustment transformations for base images: Border, Trim, Color Replace, and Sharpen
- Extended layer transformations with trim threshold, border, and sharpen capabilities
- Enhanced ColorPickerField component to accept and apply fieldProps configuration
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| packages/imagekit-editor-dev/src/schema/index.ts | Added schema definitions for new transformations (border, trim, color-replace, sharpen) and updated layer transformation handling |
| packages/imagekit-editor-dev/src/components/sidebar/transformation-config-sidebar.tsx | Added fieldProps prop to ColorPickerField component |
| packages/imagekit-editor-dev/src/components/common/ColorPickerField.tsx | Updated to accept and spread fieldProps into the ColorPicker component |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| { | ||
| key: "ai", | ||
| name: "AI Transformations", | ||
| items: [{ |
Copilot
AI
Jan 27, 2026
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.
Inconsistent formatting: the opening bracket should be on a new line to match the formatting pattern used elsewhere in this array (see line 1578 and others).
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.
@copilot open a new pull request to apply changes based on this feedback
| overlayTransform.sharpen = values.sharpen | ||
| } | ||
| } | ||
| if ((values.borderWidth && typeof values.borderWidth === "number" && values.borderWidth > 0) && (values.borderColor && typeof values.borderColor === "string")) { |
Copilot
AI
Jan 27, 2026
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.
Excessive nested parentheses reduce readability. Consider extracting conditions into named boolean variables or simplifying the expression structure.
| if ((values.borderWidth && typeof values.borderWidth === "number" && values.borderWidth > 0) && (values.borderColor && typeof values.borderColor === "string")) { | |
| const hasValidBorderWidth = | |
| typeof values.borderWidth === "number" && values.borderWidth > 0 | |
| const hasValidBorderColor = | |
| typeof values.borderColor === "string" && values.borderColor.length > 0 | |
| if (hasValidBorderWidth && hasValidBorderColor) { |
packages/imagekit-editor-dev/src/components/common/ColorPickerField.tsx
Outdated
Show resolved
Hide resolved
Co-authored-by: Copilot <[email protected]>
|
@piyushryn I've opened a new pull request, #7, to work on those changes. Once the pull request is ready, I'll request review from you. |
…Field.tsx Co-authored-by: Copilot <[email protected]>
Co-authored-by: piyushryn <[email protected]>
Fix inconsistent array formatting in AI transformations schema
…se union type and improve visibility logic
…th validation and integration
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.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated 8 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
|
|
||
| export const optionalPositiveFloatNumberValidator = z.preprocess( | ||
| (val) => (val === "" || val === undefined || val === null) ? undefined : val, |
Copilot
AI
Jan 30, 2026
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.
The preprocessor function returns undefined for empty strings, undefined, and null, but the validator chain already includes .optional(). This makes the undefined return redundant. Consider simplifying to just handle empty strings: (val) => (val === '') ? undefined : val
| (val) => (val === "" || val === undefined || val === null) ? undefined : val, | |
| (val) => (val === "" || val === null) ? undefined : val, |
| defaultTransformation: {}, | ||
| schema: z | ||
| .object({ | ||
| borderWidth: z.union([widthValidator, heightValidator]).optional(), |
Copilot
AI
Jan 30, 2026
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.
Using heightValidator for borderWidth is confusing. Consider creating a dedicated borderWidthValidator or using just widthValidator if the validation logic is identical.
| borderWidth: z.union([widthValidator, heightValidator]).optional(), | |
| borderWidth: widthValidator.optional(), |
| return false | ||
| }, | ||
| { | ||
| message: "Border width and color are required", |
Copilot
AI
Jan 30, 2026
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.
The error message states both width and color are required, but the schema makes both optional and the refine check passes if either is provided. The message should be 'At least one of border width or color is required' to match the validation logic.
| message: "Border width and color are required", | |
| message: "At least one of border width or color is required", |
| unsharpenMaskRadius: z.coerce.number().positive({ message: "Should be a positive floating point number." }), | ||
| unsharpenMaskSigma: z.coerce.number().positive({ message: "Should be a positive floating point number." }), | ||
| unsharpenMaskAmount: z.coerce.number().positive({ message: "Should be a positive floating point number." }), | ||
| unsharpenMaskThreshold: z.coerce.number().positive({ message: "Should be a positive floating point number." }), |
Copilot
AI
Jan 30, 2026
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.
These four fields have identical validation logic. Consider extracting this as a reusable validator (similar to optionalPositiveFloatNumberValidator) to reduce duplication and improve maintainability.
| isTransformation: false, | ||
| transformationGroup: "imageLayer", | ||
| helpText: | ||
| "Toggle to unsharpen the overlay image to remove the edges and finer details within an image.", |
Copilot
AI
Jan 30, 2026
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.
The help text incorrectly describes unsharpen mask as removing edges and details, when it actually enhances them. Based on the description at line 1850, it should read: 'Toggle to apply unsharpen mask to the overlay image to enhance edge contrast and make details appear clearer.'
| "Toggle to unsharpen the overlay image to remove the edges and finer details within an image.", | |
| "Toggle to apply unsharpen mask to the overlay image to enhance edge contrast and make details appear clearer.", |
| const offsetX = Number(shadowOffsetX) | ||
| if (!Number.isNaN(offsetX) && offsetX < 0) { | ||
| params.push(`x-N${Math.abs(offsetX)}`) | ||
| } else { | ||
| params.push(`x-${shadowOffsetX}`) | ||
| params.push(`x-${offsetX}`) |
Copilot
AI
Jan 30, 2026
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.
When offsetX is NaN (e.g., if shadowOffsetX is a non-numeric string), the code pushes x-NaN to params. Add an early return or guard to skip processing when the conversion results in NaN.
| const offsetY = Number(shadowOffsetY) | ||
| if (!Number.isNaN(offsetY) && offsetY < 0) { | ||
| params.push(`y-N${Math.abs(offsetY)}`) | ||
| } else { | ||
| params.push(`y-${shadowOffsetY}`) | ||
| params.push(`y-${offsetY}`) |
Copilot
AI
Jan 30, 2026
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.
When offsetY is NaN (e.g., if shadowOffsetY is a non-numeric string), the code pushes y-NaN to params. Add an early return or guard to skip processing when the conversion results in NaN.
| const { unsharpenMaskRadius, unsharpenMaskSigma, unsharpenMaskAmount, unsharpenMaskThreshold } = values as { | ||
| unsharpenMaskRadius: number | ||
| unsharpenMaskSigma: number | ||
| unsharpenMaskAmount: number | ||
| unsharpenMaskThreshold: number | ||
| } |
Copilot
AI
Jan 30, 2026
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.
The formatter unconditionally builds the transform string even when the required fields may be undefined. This could produce invalid transforms like undefined-undefined-undefined-undefined. Add validation to ensure all four parameters exist before constructing the transform, or check if unsharpenMask is enabled.
| const { unsharpenMaskRadius, unsharpenMaskSigma, unsharpenMaskAmount, unsharpenMaskThreshold } = values as { | |
| unsharpenMaskRadius: number | |
| unsharpenMaskSigma: number | |
| unsharpenMaskAmount: number | |
| unsharpenMaskThreshold: number | |
| } | |
| const { | |
| unsharpenMaskRadius, | |
| unsharpenMaskSigma, | |
| unsharpenMaskAmount, | |
| unsharpenMaskThreshold, | |
| } = values as { | |
| unsharpenMaskRadius: number | |
| unsharpenMaskSigma: number | |
| unsharpenMaskAmount: number | |
| unsharpenMaskThreshold: number | |
| } | |
| if ( | |
| typeof unsharpenMaskRadius !== "number" || | |
| typeof unsharpenMaskSigma !== "number" || | |
| typeof unsharpenMaskAmount !== "number" || | |
| typeof unsharpenMaskThreshold !== "number" | |
| ) { | |
| return | |
| } |
…ns, and improve validation logic
…nd remove debug log
Adds
trim,color-replace,border,sharpen,unsharpen maskto base imagetrimadjustment ,border,sharpen&unsharpen maskto layers