@uploadista/flow-images-sharp 0.0.12 → 0.0.13-beta.1

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 +1 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":["../src/image-plugin.ts"],"sourcesContent":["import { UploadistaError } from \"@uploadista/core/errors\";\nimport { ImagePlugin } from \"@uploadista/core/flow\";\nimport { Effect, Layer } from \"effect\";\nimport sharp from \"sharp\";\n\nconst mapFitToSharp = (fit: \"fill\" | \"contain\" | \"cover\") => {\n switch (fit) {\n case \"fill\":\n return \"cover\";\n case \"contain\":\n return \"contain\";\n }\n};\n\n/**\n * Calculate position coordinates for overlays based on position string and offsets.\n */\nconst calculateOverlayPosition = (\n position: string,\n imageWidth: number,\n imageHeight: number,\n overlayWidth: number,\n overlayHeight: number,\n offsetX = 0,\n offsetY = 0,\n): { top: number; left: number } => {\n let top = 0;\n let left = 0;\n\n switch (position) {\n case \"top-left\":\n top = offsetY;\n left = offsetX;\n break;\n case \"top-right\":\n top = offsetY;\n left = imageWidth - overlayWidth - offsetX;\n break;\n case \"bottom-left\":\n top = imageHeight - overlayHeight - offsetY;\n left = offsetX;\n break;\n case \"bottom-right\":\n top = imageHeight - overlayHeight - offsetY;\n left = imageWidth - overlayWidth - offsetX;\n break;\n case \"center\":\n top = Math.floor((imageHeight - overlayHeight) / 2) + offsetY;\n left = Math.floor((imageWidth - overlayWidth) / 2) + offsetX;\n break;\n }\n\n return { top, left };\n};\n\nexport const imagePlugin = Layer.succeed(\n ImagePlugin,\n ImagePlugin.of({\n optimize: (inputBytes, { quality, format }) => {\n return Effect.gen(function* () {\n const outputBytes = yield* Effect.tryPromise({\n try: async () =>\n await sharp(inputBytes).toFormat(format, { quality }).toBuffer(),\n catch: (error) => {\n return UploadistaError.fromCode(\"UNKNOWN_ERROR\", {\n cause: error,\n });\n },\n });\n return new Uint8Array(outputBytes);\n });\n },\n resize: (inputBytes, { width, height, fit }) => {\n return Effect.gen(function* () {\n if (!width && !height) {\n throw new Error(\n \"Either width or height must be specified for resize\",\n );\n }\n\n const sharpFit = mapFitToSharp(fit);\n const outputBytes = yield* Effect.tryPromise({\n try: async () =>\n await sharp(inputBytes)\n .resize(width, height, { fit: sharpFit })\n .toBuffer(),\n catch: (error) => {\n return UploadistaError.fromCode(\"UNKNOWN_ERROR\", {\n cause: error,\n });\n },\n });\n\n return new Uint8Array(outputBytes);\n });\n },\n transform: (inputBytes, transformation) => {\n return Effect.gen(function* () {\n let pipeline = sharp(inputBytes);\n\n switch (transformation.type) {\n case \"resize\": {\n const sharpFit = mapFitToSharp(transformation.fit);\n pipeline = pipeline.resize(\n transformation.width,\n transformation.height,\n {\n fit: sharpFit,\n },\n );\n break;\n }\n\n case \"blur\": {\n pipeline = pipeline.blur(transformation.sigma);\n break;\n }\n\n case \"rotate\": {\n const options = transformation.background\n ? { background: transformation.background }\n : undefined;\n pipeline = pipeline.rotate(transformation.angle, options);\n break;\n }\n\n case \"flip\": {\n if (transformation.direction === \"horizontal\") {\n pipeline = pipeline.flop();\n } else {\n pipeline = pipeline.flip();\n }\n break;\n }\n\n case \"grayscale\": {\n pipeline = pipeline.grayscale();\n break;\n }\n\n case \"sepia\": {\n // Apply sepia tone using tint\n pipeline = pipeline.tint({ r: 112, g: 66, b: 20 });\n break;\n }\n\n case \"brightness\": {\n // Convert -100 to +100 range to multiplier (0 to 2)\n const multiplier = 1 + transformation.value / 100;\n pipeline = pipeline.modulate({ brightness: multiplier });\n break;\n }\n\n case \"contrast\": {\n // Convert -100 to +100 range to linear adjustment\n const a = 1 + transformation.value / 100;\n pipeline = pipeline.linear(a, 0);\n break;\n }\n\n case \"sharpen\": {\n if (transformation.sigma !== undefined) {\n pipeline = pipeline.sharpen({ sigma: transformation.sigma });\n } else {\n pipeline = pipeline.sharpen();\n }\n break;\n }\n\n case \"watermark\": {\n // Fetch watermark image from URL\n const watermarkBuffer = yield* Effect.tryPromise({\n try: async () => {\n const response = await fetch(transformation.imagePath);\n if (!response.ok) {\n throw new Error(`Failed to fetch watermark: ${response.statusText}`);\n }\n const arrayBuffer = await response.arrayBuffer();\n return Buffer.from(arrayBuffer);\n },\n catch: (error) => {\n return UploadistaError.fromCode(\"FILE_NOT_FOUND\", {\n body: `Watermark image not found or failed to fetch: ${transformation.imagePath}`,\n cause: error,\n });\n },\n });\n\n // Get image metadata to calculate positioning\n const metadata = yield* Effect.tryPromise({\n try: async () => await pipeline.metadata(),\n catch: (error) => {\n return UploadistaError.fromCode(\"UNKNOWN_ERROR\", {\n body: \"Failed to read image metadata\",\n cause: error,\n });\n },\n });\n\n // Get watermark metadata\n const watermarkMetadata = yield* Effect.tryPromise({\n try: async () => await sharp(watermarkBuffer).metadata(),\n catch: (error) => {\n return UploadistaError.fromCode(\"UNKNOWN_ERROR\", {\n body: \"Failed to read watermark metadata\",\n cause: error,\n });\n },\n });\n\n if (\n !metadata.width ||\n !metadata.height ||\n !watermarkMetadata.width ||\n !watermarkMetadata.height\n ) {\n return yield* Effect.fail(\n UploadistaError.fromCode(\"UNKNOWN_ERROR\", {\n body: \"Could not determine image or watermark dimensions\",\n }),\n );\n }\n\n const { top, left } = calculateOverlayPosition(\n transformation.position,\n metadata.width,\n metadata.height,\n watermarkMetadata.width,\n watermarkMetadata.height,\n transformation.offsetX,\n transformation.offsetY,\n );\n\n // Apply watermark with opacity\n const watermarkWithOpacity = yield* Effect.tryPromise({\n try: async () =>\n await sharp(watermarkBuffer)\n .composite([\n {\n input: Buffer.from([\n 255,\n 255,\n 255,\n Math.round(transformation.opacity * 255),\n ]),\n raw: {\n width: 1,\n height: 1,\n channels: 4,\n },\n tile: true,\n blend: \"dest-in\",\n },\n ])\n .toBuffer(),\n catch: (error) => {\n return UploadistaError.fromCode(\"UNKNOWN_ERROR\", {\n body: \"Failed to apply watermark opacity\",\n cause: error,\n });\n },\n });\n\n pipeline = pipeline.composite([\n {\n input: watermarkWithOpacity,\n top,\n left,\n },\n ]);\n break;\n }\n\n case \"logo\": {\n // Fetch logo image from URL\n const logoBuffer = yield* Effect.tryPromise({\n try: async () => {\n const response = await fetch(transformation.imagePath);\n if (!response.ok) {\n throw new Error(`Failed to fetch logo: ${response.statusText}`);\n }\n const arrayBuffer = await response.arrayBuffer();\n return Buffer.from(arrayBuffer);\n },\n catch: (error) => {\n return UploadistaError.fromCode(\"FILE_NOT_FOUND\", {\n body: `Logo image not found or failed to fetch: ${transformation.imagePath}`,\n cause: error,\n });\n },\n });\n\n // Get image metadata\n const metadata = yield* Effect.tryPromise({\n try: async () => await pipeline.metadata(),\n catch: (error) => {\n return UploadistaError.fromCode(\"UNKNOWN_ERROR\", {\n body: \"Failed to read image metadata\",\n cause: error,\n });\n },\n });\n\n // Get logo metadata\n const logoMetadata = yield* Effect.tryPromise({\n try: async () => await sharp(logoBuffer).metadata(),\n catch: (error) => {\n return UploadistaError.fromCode(\"UNKNOWN_ERROR\", {\n body: \"Failed to read logo metadata\",\n cause: error,\n });\n },\n });\n\n if (\n !metadata.width ||\n !metadata.height ||\n !logoMetadata.width ||\n !logoMetadata.height\n ) {\n return yield* Effect.fail(\n UploadistaError.fromCode(\"UNKNOWN_ERROR\", {\n body: \"Could not determine image or logo dimensions\",\n }),\n );\n }\n\n // Scale logo\n const scaledLogoWidth = Math.round(\n logoMetadata.width * transformation.scale,\n );\n const scaledLogoHeight = Math.round(\n logoMetadata.height * transformation.scale,\n );\n\n const scaledLogo = yield* Effect.tryPromise({\n try: async () =>\n await sharp(logoBuffer)\n .resize(scaledLogoWidth, scaledLogoHeight)\n .toBuffer(),\n catch: (error) => {\n return UploadistaError.fromCode(\"UNKNOWN_ERROR\", {\n body: \"Failed to scale logo\",\n cause: error,\n });\n },\n });\n\n const { top, left } = calculateOverlayPosition(\n transformation.position,\n metadata.width,\n metadata.height,\n scaledLogoWidth,\n scaledLogoHeight,\n transformation.offsetX,\n transformation.offsetY,\n );\n\n pipeline = pipeline.composite([\n {\n input: scaledLogo,\n top,\n left,\n },\n ]);\n break;\n }\n\n case \"text\": {\n // Get image metadata\n const metadata = yield* Effect.tryPromise({\n try: async () => await pipeline.metadata(),\n catch: (error) => {\n return UploadistaError.fromCode(\"UNKNOWN_ERROR\", {\n body: \"Failed to read image metadata\",\n cause: error,\n });\n },\n });\n\n if (!metadata.width || !metadata.height) {\n return yield* Effect.fail(\n UploadistaError.fromCode(\"UNKNOWN_ERROR\", {\n body: \"Could not determine image dimensions\",\n }),\n );\n }\n\n // Create SVG text overlay\n const fontFamily = transformation.fontFamily || \"sans-serif\";\n\n // Estimate text dimensions (rough approximation)\n const textWidth =\n transformation.text.length * transformation.fontSize * 0.6;\n const textHeight = transformation.fontSize;\n\n const { top, left } = calculateOverlayPosition(\n transformation.position,\n metadata.width,\n metadata.height,\n textWidth,\n textHeight,\n transformation.offsetX,\n transformation.offsetY,\n );\n\n // Create positioned SVG\n const positionedSvg = `\n <svg width=\"${metadata.width}\" height=\"${metadata.height}\">\n <text\n x=\"${left}\"\n y=\"${top + transformation.fontSize}\"\n font-family=\"${fontFamily}\"\n font-size=\"${transformation.fontSize}\"\n fill=\"${transformation.color}\"\n >${transformation.text}</text>\n </svg>\n `;\n\n pipeline = pipeline.composite([\n {\n input: Buffer.from(positionedSvg),\n top: 0,\n left: 0,\n },\n ]);\n break;\n }\n\n default: {\n // TypeScript should ensure this is unreachable\n return yield* Effect.fail(\n UploadistaError.fromCode(\"UNKNOWN_ERROR\", {\n body: `Unsupported transformation type: ${(transformation as { type: string }).type}`,\n }),\n );\n }\n }\n\n // Convert pipeline to buffer\n const outputBytes = yield* Effect.tryPromise({\n try: async () => await pipeline.toBuffer(),\n catch: (error) => {\n return UploadistaError.fromCode(\"UNKNOWN_ERROR\", {\n body: `Failed to apply transformation: ${transformation.type}`,\n cause: error,\n });\n },\n });\n\n return new Uint8Array(outputBytes);\n });\n },\n }),\n);\n"],"mappings":"8KAKA,MAAM,EAAiB,GAAsC,CAC3D,OAAQ,EAAR,CACE,IAAK,OACH,MAAO,QACT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B,SAAS,gBAAiB,CAC/C,KAAM,gCACN,MAAO,EACR,CAAC,CAEL,CAAC,CAEF,GAAI,CAAC,EAAS,OAAS,CAAC,EAAS,OAC/B,OAAO,MAAO,EAAO,KACnB,EAAgB,SAAS,gBAAiB,CACxC,KAAM,uCACP,CAAC,CACH,CAIH,IAAM,EAAa,EAAe,YAAc,aAG1C,EACJ,EAAe,KAAK,OAAS,EAAe,SAAW,GACnD,EAAa,EAAe,SAE5B,CAAE,MAAK,QAAS,EACpB,EAAe,SACf,EAAS,MACT,EAAS,OACT,EACA,EACA,EAAe,QACf,EAAe,QAChB,CAGK,EAAgB;4BACN,EAAS,MAAM,YAAY,EAAS,OAAO;;uBAEhD,EAAK;uBACL,EAAM,EAAe,SAAS;iCACpB,EAAW;+BACb,EAAe,SAAS;0BAC7B,EAAe,MAAM;mBAC5B,EAAe,KAAK;;cAI3B,EAAW,EAAS,UAAU,CAC5B,CACE,MAAO,OAAO,KAAK,EAAc,CACjC,IAAK,EACL,KAAM,EACP,CACF,CAAC,CACF,MAGF,QAEE,OAAO,MAAO,EAAO,KACnB,EAAgB,SAAS,gBAAiB,CACxC,KAAM,oCAAqC,EAAoC,OAChF,CAAC,CACH,CAKL,IAAM,EAAc,MAAO,EAAO,WAAW,CAC3C,IAAK,SAAY,MAAM,EAAS,UAAU,CAC1C,MAAQ,GACC,EAAgB,SAAS,gBAAiB,CAC/C,KAAM,mCAAmC,EAAe,OACxD,MAAO,EACR,CAAC,CAEL,CAAC,CAEF,OAAO,IAAI,WAAW,EAAY,EAClC,CAEL,CAAC,CACH"}
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../src/image-plugin.ts"],"sourcesContent":["import { UploadistaError } from \"@uploadista/core/errors\";\nimport { ImagePlugin } from \"@uploadista/core/flow\";\nimport { Effect, Layer } from \"effect\";\nimport sharp from \"sharp\";\n\nconst mapFitToSharp = (fit: \"fill\" | \"contain\" | \"cover\") => {\n switch (fit) {\n case \"fill\":\n return \"cover\";\n case \"contain\":\n return \"contain\";\n }\n};\n\n/**\n * Calculate position coordinates for overlays based on position string and offsets.\n */\nconst calculateOverlayPosition = (\n position: string,\n imageWidth: number,\n imageHeight: number,\n overlayWidth: number,\n overlayHeight: number,\n offsetX = 0,\n offsetY = 0,\n): { top: number; left: number } => {\n let top = 0;\n let left = 0;\n\n switch (position) {\n case \"top-left\":\n top = offsetY;\n left = offsetX;\n break;\n case \"top-right\":\n top = offsetY;\n left = imageWidth - overlayWidth - offsetX;\n break;\n case \"bottom-left\":\n top = imageHeight - overlayHeight - offsetY;\n left = offsetX;\n break;\n case \"bottom-right\":\n top = imageHeight - overlayHeight - offsetY;\n left = imageWidth - overlayWidth - offsetX;\n break;\n case \"center\":\n top = Math.floor((imageHeight - overlayHeight) / 2) + offsetY;\n left = Math.floor((imageWidth - overlayWidth) / 2) + offsetX;\n break;\n }\n\n return { top, left };\n};\n\nexport const imagePlugin = Layer.succeed(\n ImagePlugin,\n ImagePlugin.of({\n optimize: (inputBytes, { quality, format }) => {\n return Effect.gen(function* () {\n const outputBytes = yield* Effect.tryPromise({\n try: async () =>\n await sharp(inputBytes).toFormat(format, { quality }).toBuffer(),\n catch: (error) => {\n return UploadistaError.fromCode(\"UNKNOWN_ERROR\", {\n cause: error,\n });\n },\n });\n return new Uint8Array(outputBytes);\n });\n },\n resize: (inputBytes, { width, height, fit }) => {\n return Effect.gen(function* () {\n if (!width && !height) {\n throw new Error(\n \"Either width or height must be specified for resize\",\n );\n }\n\n const sharpFit = mapFitToSharp(fit);\n const outputBytes = yield* Effect.tryPromise({\n try: async () =>\n await sharp(inputBytes)\n .resize(width, height, { fit: sharpFit })\n .toBuffer(),\n catch: (error) => {\n return UploadistaError.fromCode(\"UNKNOWN_ERROR\", {\n cause: error,\n });\n },\n });\n\n return new Uint8Array(outputBytes);\n });\n },\n transform: (inputBytes, transformation) => {\n return Effect.gen(function* () {\n let pipeline = sharp(inputBytes);\n\n switch (transformation.type) {\n case \"resize\": {\n const sharpFit = mapFitToSharp(transformation.fit);\n pipeline = pipeline.resize(\n transformation.width,\n transformation.height,\n {\n fit: sharpFit,\n },\n );\n break;\n }\n\n case \"blur\": {\n pipeline = pipeline.blur(transformation.sigma);\n break;\n }\n\n case \"rotate\": {\n const options = transformation.background\n ? { background: transformation.background }\n : undefined;\n pipeline = pipeline.rotate(transformation.angle, options);\n break;\n }\n\n case \"flip\": {\n if (transformation.direction === \"horizontal\") {\n pipeline = pipeline.flop();\n } else {\n pipeline = pipeline.flip();\n }\n break;\n }\n\n case \"grayscale\": {\n pipeline = pipeline.grayscale();\n break;\n }\n\n case \"sepia\": {\n // Apply sepia tone using tint\n pipeline = pipeline.tint({ r: 112, g: 66, b: 20 });\n break;\n }\n\n case \"brightness\": {\n // Convert -100 to +100 range to multiplier (0 to 2)\n const multiplier = 1 + transformation.value / 100;\n pipeline = pipeline.modulate({ brightness: multiplier });\n break;\n }\n\n case \"contrast\": {\n // Convert -100 to +100 range to linear adjustment\n const a = 1 + transformation.value / 100;\n pipeline = pipeline.linear(a, 0);\n break;\n }\n\n case \"sharpen\": {\n if (transformation.sigma !== undefined) {\n pipeline = pipeline.sharpen({ sigma: transformation.sigma });\n } else {\n pipeline = pipeline.sharpen();\n }\n break;\n }\n\n case \"watermark\": {\n // Fetch watermark image from URL\n const watermarkBuffer = yield* Effect.tryPromise({\n try: async () => {\n const response = await fetch(transformation.imagePath);\n if (!response.ok) {\n throw new Error(\n `Failed to fetch watermark: ${response.statusText}`,\n );\n }\n const arrayBuffer = await response.arrayBuffer();\n return Buffer.from(arrayBuffer);\n },\n catch: (error) => {\n return UploadistaError.fromCode(\"FILE_NOT_FOUND\", {\n body: `Watermark image not found or failed to fetch: ${transformation.imagePath}`,\n cause: error,\n });\n },\n });\n\n // Get image metadata to calculate positioning\n const metadata = yield* Effect.tryPromise({\n try: async () => await pipeline.metadata(),\n catch: (error) => {\n return UploadistaError.fromCode(\"UNKNOWN_ERROR\", {\n body: \"Failed to read image metadata\",\n cause: error,\n });\n },\n });\n\n // Get watermark metadata\n const watermarkMetadata = yield* Effect.tryPromise({\n try: async () => await sharp(watermarkBuffer).metadata(),\n catch: (error) => {\n return UploadistaError.fromCode(\"UNKNOWN_ERROR\", {\n body: \"Failed to read watermark metadata\",\n cause: error,\n });\n },\n });\n\n if (\n !metadata.width ||\n !metadata.height ||\n !watermarkMetadata.width ||\n !watermarkMetadata.height\n ) {\n return yield* Effect.fail(\n UploadistaError.fromCode(\"UNKNOWN_ERROR\", {\n body: \"Could not determine image or watermark dimensions\",\n }),\n );\n }\n\n const { top, left } = calculateOverlayPosition(\n transformation.position,\n metadata.width,\n metadata.height,\n watermarkMetadata.width,\n watermarkMetadata.height,\n transformation.offsetX,\n transformation.offsetY,\n );\n\n // Apply watermark with opacity\n const watermarkWithOpacity = yield* Effect.tryPromise({\n try: async () =>\n await sharp(watermarkBuffer)\n .composite([\n {\n input: Buffer.from([\n 255,\n 255,\n 255,\n Math.round(transformation.opacity * 255),\n ]),\n raw: {\n width: 1,\n height: 1,\n channels: 4,\n },\n tile: true,\n blend: \"dest-in\",\n },\n ])\n .toBuffer(),\n catch: (error) => {\n return UploadistaError.fromCode(\"UNKNOWN_ERROR\", {\n body: \"Failed to apply watermark opacity\",\n cause: error,\n });\n },\n });\n\n pipeline = pipeline.composite([\n {\n input: watermarkWithOpacity,\n top,\n left,\n },\n ]);\n break;\n }\n\n case \"logo\": {\n // Fetch logo image from URL\n const logoBuffer = yield* Effect.tryPromise({\n try: async () => {\n const response = await fetch(transformation.imagePath);\n if (!response.ok) {\n throw new Error(\n `Failed to fetch logo: ${response.statusText}`,\n );\n }\n const arrayBuffer = await response.arrayBuffer();\n return Buffer.from(arrayBuffer);\n },\n catch: (error) => {\n return UploadistaError.fromCode(\"FILE_NOT_FOUND\", {\n body: `Logo image not found or failed to fetch: ${transformation.imagePath}`,\n cause: error,\n });\n },\n });\n\n // Get image metadata\n const metadata = yield* Effect.tryPromise({\n try: async () => await pipeline.metadata(),\n catch: (error) => {\n return UploadistaError.fromCode(\"UNKNOWN_ERROR\", {\n body: \"Failed to read image metadata\",\n cause: error,\n });\n },\n });\n\n // Get logo metadata\n const logoMetadata = yield* Effect.tryPromise({\n try: async () => await sharp(logoBuffer).metadata(),\n catch: (error) => {\n return UploadistaError.fromCode(\"UNKNOWN_ERROR\", {\n body: \"Failed to read logo metadata\",\n cause: error,\n });\n },\n });\n\n if (\n !metadata.width ||\n !metadata.height ||\n !logoMetadata.width ||\n !logoMetadata.height\n ) {\n return yield* Effect.fail(\n UploadistaError.fromCode(\"UNKNOWN_ERROR\", {\n body: \"Could not determine image or logo dimensions\",\n }),\n );\n }\n\n // Scale logo\n const scaledLogoWidth = Math.round(\n logoMetadata.width * transformation.scale,\n );\n const scaledLogoHeight = Math.round(\n logoMetadata.height * transformation.scale,\n );\n\n const scaledLogo = yield* Effect.tryPromise({\n try: async () =>\n await sharp(logoBuffer)\n .resize(scaledLogoWidth, scaledLogoHeight)\n .toBuffer(),\n catch: (error) => {\n return UploadistaError.fromCode(\"UNKNOWN_ERROR\", {\n body: \"Failed to scale logo\",\n cause: error,\n });\n },\n });\n\n const { top, left } = calculateOverlayPosition(\n transformation.position,\n metadata.width,\n metadata.height,\n scaledLogoWidth,\n scaledLogoHeight,\n transformation.offsetX,\n transformation.offsetY,\n );\n\n pipeline = pipeline.composite([\n {\n input: scaledLogo,\n top,\n left,\n },\n ]);\n break;\n }\n\n case \"text\": {\n // Get image metadata\n const metadata = yield* Effect.tryPromise({\n try: async () => await pipeline.metadata(),\n catch: (error) => {\n return UploadistaError.fromCode(\"UNKNOWN_ERROR\", {\n body: \"Failed to read image metadata\",\n cause: error,\n });\n },\n });\n\n if (!metadata.width || !metadata.height) {\n return yield* Effect.fail(\n UploadistaError.fromCode(\"UNKNOWN_ERROR\", {\n body: \"Could not determine image dimensions\",\n }),\n );\n }\n\n // Create SVG text overlay\n const fontFamily = transformation.fontFamily || \"sans-serif\";\n\n // Estimate text dimensions (rough approximation)\n const textWidth =\n transformation.text.length * transformation.fontSize * 0.6;\n const textHeight = transformation.fontSize;\n\n const { top, left } = calculateOverlayPosition(\n transformation.position,\n metadata.width,\n metadata.height,\n textWidth,\n textHeight,\n transformation.offsetX,\n transformation.offsetY,\n );\n\n // Create positioned SVG\n const positionedSvg = `\n <svg width=\"${metadata.width}\" height=\"${metadata.height}\">\n <text\n x=\"${left}\"\n y=\"${top + transformation.fontSize}\"\n font-family=\"${fontFamily}\"\n font-size=\"${transformation.fontSize}\"\n fill=\"${transformation.color}\"\n >${transformation.text}</text>\n </svg>\n `;\n\n pipeline = pipeline.composite([\n {\n input: Buffer.from(positionedSvg),\n top: 0,\n left: 0,\n },\n ]);\n break;\n }\n\n default: {\n // TypeScript should ensure this is unreachable\n return yield* Effect.fail(\n UploadistaError.fromCode(\"UNKNOWN_ERROR\", {\n body: `Unsupported transformation type: ${(transformation as { type: string }).type}`,\n }),\n );\n }\n }\n\n // Convert pipeline to buffer\n const outputBytes = yield* Effect.tryPromise({\n try: async () => await pipeline.toBuffer(),\n catch: (error) => {\n return UploadistaError.fromCode(\"UNKNOWN_ERROR\", {\n body: `Failed to apply transformation: ${transformation.type}`,\n cause: error,\n });\n },\n });\n\n return new Uint8Array(outputBytes);\n });\n },\n }),\n);\n"],"mappings":"8KAKA,MAAM,EAAiB,GAAsC,CAC3D,OAAQ,EAAR,CACE,IAAK,OACH,MAAO,QACT,IAAK,UACH,MAAO,YAOP,GACJ,EACA,EACA,EACA,EACA,EACA,EAAU,EACV,EAAU,IACwB,CAClC,IAAI,EAAM,EACN,EAAO,EAEX,OAAQ,EAAR,CACE,IAAK,WACH,EAAM,EACN,EAAO,EACP,MACF,IAAK,YACH,EAAM,EACN,EAAO,EAAa,EAAe,EACnC,MACF,IAAK,cACH,EAAM,EAAc,EAAgB,EACpC,EAAO,EACP,MACF,IAAK,eACH,EAAM,EAAc,EAAgB,EACpC,EAAO,EAAa,EAAe,EACnC,MACF,IAAK,SACH,EAAM,KAAK,OAAO,EAAc,GAAiB,EA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AAgB;4BACN,EAAS,MAAM,YAAY,EAAS,OAAO;;uBAEhD,EAAK;uBACL,EAAM,EAAe,SAAS;iCACpB,EAAW;+BACb,EAAe,SAAS;0BAC7B,EAAe,MAAM;mBAC5B,EAAe,KAAK;;cAI3B,EAAW,EAAS,UAAU,CAC5B,CACE,MAAO,OAAO,KAAK,EAAc,CACjC,IAAK,EACL,KAAM,EACP,CACF,CAAC,CACF,MAGF,QAEE,OAAO,MAAO,EAAO,KACnB,EAAgB,SAAS,gBAAiB,CACxC,KAAM,oCAAqC,EAAoC,OAChF,CAAC,CACH,CAKL,IAAM,EAAc,MAAO,EAAO,WAAW,CAC3C,IAAK,SAAY,MAAM,EAAS,UAAU,CAC1C,MAAQ,GACC,EAAgB,SAAS,gBAAiB,CAC/C,KAAM,mCAAmC,EAAe,OACxD,MAAO,EACR,CAAC,CAEL,CAAC,CAEF,OAAO,IAAI,WAAW,EAAY,EAClC,CAEL,CAAC,CACH"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@uploadista/flow-images-sharp",
3
3
  "type": "module",
4
- "version": "0.0.12",
4
+ "version": "0.0.13-beta.1",
5
5
  "description": "Sharp image processing service for Uploadista Flow",
6
6
  "license": "MIT",
7
7
  "author": "Uploadista",
@@ -14,17 +14,17 @@
14
14
  }
15
15
  },
16
16
  "dependencies": {
17
- "sharp": "0.34.4",
18
- "effect": "3.19.1",
17
+ "sharp": "0.34.5",
18
+ "effect": "3.19.2",
19
19
  "tinycolor2": "1.6.0",
20
20
  "zod": "4.1.12",
21
- "@uploadista/core": "0.0.12"
21
+ "@uploadista/core": "0.0.13-beta.1"
22
22
  },
23
23
  "devDependencies": {
24
24
  "@types/node": "24.10.0",
25
25
  "@types/tinycolor2": "1.4.6",
26
26
  "tsdown": "0.16.0",
27
- "@uploadista/typescript-config": "0.0.12"
27
+ "@uploadista/typescript-config": "0.0.13-beta.1"
28
28
  },
29
29
  "scripts": {
30
30
  "build": "tsdown",
@@ -173,7 +173,9 @@ export const imagePlugin = Layer.succeed(
173
173
  try: async () => {
174
174
  const response = await fetch(transformation.imagePath);
175
175
  if (!response.ok) {
176
- throw new Error(`Failed to fetch watermark: ${response.statusText}`);
176
+ throw new Error(
177
+ `Failed to fetch watermark: ${response.statusText}`,
178
+ );
177
179
  }
178
180
  const arrayBuffer = await response.arrayBuffer();
179
181
  return Buffer.from(arrayBuffer);
@@ -277,7 +279,9 @@ export const imagePlugin = Layer.succeed(
277
279
  try: async () => {
278
280
  const response = await fetch(transformation.imagePath);
279
281
  if (!response.ok) {
280
- throw new Error(`Failed to fetch logo: ${response.statusText}`);
282
+ throw new Error(
283
+ `Failed to fetch logo: ${response.statusText}`,
284
+ );
281
285
  }
282
286
  const arrayBuffer = await response.arrayBuffer();
283
287
  return Buffer.from(arrayBuffer);