Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions packages/imagekit-editor-dev/src/schema/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2199,7 +2199,7 @@ export const transformationSchema: TransformationSchema[] = [
transformationKey: "x",
transformationGroup: "textLayer",
helpText: "Specify horizontal offset for the text.",
examples: ["10", "bw_div_2"],
examples: ["10", "-20", "N30", "bw_div_2"],
},
{
label: "Position Y",
Expand All @@ -2209,7 +2209,7 @@ export const transformationSchema: TransformationSchema[] = [
transformationKey: "y",
transformationGroup: "textLayer",
helpText: "Specify vertical offset for the text.",
examples: ["10", "bh_div_2"],
examples: ["10", "-20", "N30", "bh_div_2"],
},
{
label: "Font Size",
Expand Down Expand Up @@ -2517,7 +2517,7 @@ export const transformationSchema: TransformationSchema[] = [
transformationKey: "x",
transformationGroup: "imageLayer",
helpText: "Specify the horizontal offset for the overlay image.",
examples: ["10"],
examples: ["10", "-20", "N30", "bw_div_2"],
},
{
label: "Position Y",
Expand All @@ -2527,7 +2527,7 @@ export const transformationSchema: TransformationSchema[] = [
transformationKey: "y",
transformationGroup: "imageLayer",
helpText: "Specify the vertical offset for the overlay image.",
examples: ["10"],
examples: ["10", "-20", "N30", "bh_div_2"],
},
{
label: "Opacity",
Expand Down Expand Up @@ -2926,13 +2926,13 @@ export const transformationFormatters: Record<
typeof values.positionX === "number" ||
typeof values.positionX === "string"
) {
position.x = values.positionX
position.x = values.positionX.toString().replace(/^-/,"N")
}
if (
typeof values.positionY === "number" ||
typeof values.positionY === "string"
) {
position.y = values.positionY
position.y = values.positionY.toString().replace(/^-/,"N")
}
if (Object.keys(position).length > 0) {
overlay.position = position
Expand Down Expand Up @@ -3032,10 +3032,10 @@ export const transformationFormatters: Record<
// Positioning via x/y or focus anchor
const position: Record<string, unknown> = {}
if (values.positionX) {
position.x = values.positionX
position.x = values.positionX.toString().replace(/^-/,"N")
}
if (values.positionY) {
position.y = values.positionY
position.y = values.positionY.toString().replace(/^-/,"N")
}

if (Object.keys(position).length > 0) {
Expand Down
16 changes: 6 additions & 10 deletions packages/imagekit-editor-dev/src/schema/transformation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,8 @@ export const aspectRatioValidator = z.any().superRefine((val, ctx) => {
})

const layerXNumber = z.coerce
.number({ invalid_type_error: "Should be a number." })
.min(0, {
message: "Layer X must be a positive number.",
})
.string()
.regex(/^[N-]?\d+(\.\d{1,2})?$/)

const layerXExpr = z
.string()
Expand All @@ -97,15 +95,13 @@ export const layerXValidator = z.any().superRefine((val, ctx) => {
}
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: "Layer X must be a positive number or a valid expression string.",
message: "Layer X must be a number or a valid expression string.",
})
})

const layerYNumber = z.coerce
.number({ invalid_type_error: "Should be a number." })
.min(0, {
message: "Layer Y must be a positive number.",
})
.string()
.regex(/^[N-]?\d+(\.\d{1,2})?$/)

const layerYExpr = z
.string()
Expand All @@ -121,6 +117,6 @@ export const layerYValidator = z.any().superRefine((val, ctx) => {
}
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: "Layer Y must be a positive number or a valid expression string.",
message: "Layer Y must be a number or a valid expression string.",
})
})