@uploadista/flow-images-photon 0.1.2 → 0.1.3-beta.3
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/{common-ChU3HbEt.mjs → common-DTrnaMP7.mjs} +1 -1
- package/dist/{common-ChU3HbEt.mjs.map → common-DTrnaMP7.mjs.map} +1 -1
- package/dist/node.d.cts.map +1 -1
- package/dist/node.d.mts.map +1 -1
- package/dist/node.mjs +1 -1
- package/dist/serverless.d.cts.map +1 -1
- package/dist/serverless.d.mts.map +1 -1
- package/dist/serverless.mjs +1 -1
- package/package.json +8 -8
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
const e=e=>Math.round((e+2**-52)*100)/100,t=(t,n,r,i,a)=>{let o={};switch(t){case`contain`:{let e=i/n,t=a/r,s=Math.min(e,t);o={width:n*s,height:r*s};break}case`cover`:{let e=i/n,t=a/r,s=Math.max(e,t),c=n*s,l=r*s;if(c<i||l<a){let e=Math.max(i/n,a/r);o={width:n*e,height:r*e};break}o={width:c,height:l};break}case`fill`:o={width:i,height:a};break;case`none`:o={width:n,height:r};break;case`scale-down`:{let e=i/n,t=a/r,s=Math.min(1,Math.min(e,t));o={width:n*s,height:r*s};break}default:throw Error(`Invalid object fit value`)}if(!o?.width||!o?.height)throw Error(`Invalid dimensions`);return{width:e(o.width),height:e(o.height)}};export{t};
|
|
2
|
-
//# sourceMappingURL=common-
|
|
2
|
+
//# sourceMappingURL=common-DTrnaMP7.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common-
|
|
1
|
+
{"version":3,"file":"common-DTrnaMP7.mjs","names":[],"sources":["../src/common.ts"],"sourcesContent":["export const round2dp = (num: number) =>\n Math.round((num + Number.EPSILON) * 100) / 100;\n\nexport const calculateImageSize = (\n objectFit: \"contain\" | \"cover\" | \"fill\" | \"none\" | \"scale-down\",\n currentWidth: number,\n currentHeight: number,\n containerWidth: number,\n containerHeight: number,\n) => {\n let newSize: {\n width?: number;\n height?: number;\n } = {};\n\n switch (objectFit) {\n case \"contain\": {\n // Calculate dimensions while maintaining aspect ratio\n const widthRatioContain = containerWidth / currentWidth;\n const heightRatioContain = containerHeight / currentHeight;\n const scaleContain = Math.min(widthRatioContain, heightRatioContain);\n newSize = {\n width: currentWidth * scaleContain,\n height: currentHeight * scaleContain,\n };\n break;\n }\n case \"cover\": {\n // Calculate dimensions while maintaining aspect ratio\n const widthRatioCover = containerWidth / currentWidth;\n const heightRatioCover = containerHeight / currentHeight;\n const scaleCover = Math.max(widthRatioCover, heightRatioCover);\n const newWidthCover = currentWidth * scaleCover;\n const newHeightCover = currentHeight * scaleCover;\n // Adjust dimensions if it doesn't cover the container completely\n if (newWidthCover < containerWidth || newHeightCover < containerHeight) {\n const scaleCoverAdjusted = Math.max(\n containerWidth / currentWidth,\n containerHeight / currentHeight,\n );\n newSize = {\n width: currentWidth * scaleCoverAdjusted,\n height: currentHeight * scaleCoverAdjusted,\n };\n break;\n }\n newSize = {\n width: newWidthCover,\n height: newHeightCover,\n };\n break;\n }\n case \"fill\":\n // Stretch image to fill container\n newSize = {\n width: containerWidth,\n height: containerHeight,\n };\n break;\n case \"none\":\n // Keep original image size\n newSize = {\n width: currentWidth,\n height: currentHeight,\n };\n break;\n case \"scale-down\": {\n // Calculate dimensions based on contain and none values\n const widthRatioScaleDown = containerWidth / currentWidth;\n const heightRatioScaleDown = containerHeight / currentHeight;\n const scaleScaleDown = Math.min(\n 1,\n Math.min(widthRatioScaleDown, heightRatioScaleDown),\n );\n newSize = {\n width: currentWidth * scaleScaleDown,\n height: currentHeight * scaleScaleDown,\n };\n break;\n }\n default:\n throw new Error(\"Invalid object fit value\");\n }\n\n if (!newSize?.width || !newSize?.height) {\n throw new Error(\"Invalid dimensions\");\n }\n\n return {\n width: round2dp(newSize.width),\n height: round2dp(newSize.height),\n };\n\n // return newSize;\n};\n"],"mappings":"AAAA,MAAa,EAAY,GACvB,KAAK,OAAO,UAAwB,IAAI,CAAG,IAEhC,GACX,EACA,EACA,EACA,EACA,IACG,CACH,IAAI,EAGA,EAAE,CAEN,OAAQ,EAAR,CACE,IAAK,UAAW,CAEd,IAAM,EAAoB,EAAiB,EACrC,EAAqB,EAAkB,EACvC,EAAe,KAAK,IAAI,EAAmB,EAAmB,CACpE,EAAU,CACR,MAAO,EAAe,EACtB,OAAQ,EAAgB,EACzB,CACD,MAEF,IAAK,QAAS,CAEZ,IAAM,EAAkB,EAAiB,EACnC,EAAmB,EAAkB,EACrC,EAAa,KAAK,IAAI,EAAiB,EAAiB,CACxD,EAAgB,EAAe,EAC/B,EAAiB,EAAgB,EAEvC,GAAI,EAAgB,GAAkB,EAAiB,EAAiB,CACtE,IAAM,EAAqB,KAAK,IAC9B,EAAiB,EACjB,EAAkB,EACnB,CACD,EAAU,CACR,MAAO,EAAe,EACtB,OAAQ,EAAgB,EACzB,CACD,MAEF,EAAU,CACR,MAAO,EACP,OAAQ,EACT,CACD,MAEF,IAAK,OAEH,EAAU,CACR,MAAO,EACP,OAAQ,EACT,CACD,MACF,IAAK,OAEH,EAAU,CACR,MAAO,EACP,OAAQ,EACT,CACD,MACF,IAAK,aAAc,CAEjB,IAAM,EAAsB,EAAiB,EACvC,EAAuB,EAAkB,EACzC,EAAiB,KAAK,IAC1B,EACA,KAAK,IAAI,EAAqB,EAAqB,CACpD,CACD,EAAU,CACR,MAAO,EAAe,EACtB,OAAQ,EAAgB,EACzB,CACD,MAEF,QACE,MAAU,MAAM,2BAA2B,CAG/C,GAAI,CAAC,GAAS,OAAS,CAAC,GAAS,OAC/B,MAAU,MAAM,qBAAqB,CAGvC,MAAO,CACL,MAAO,EAAS,EAAQ,MAAM,CAC9B,OAAQ,EAAS,EAAQ,OAAO,CACjC"}
|
package/dist/node.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node.d.cts","names":[],"sources":["../src/image-plugin-node.ts"],"
|
|
1
|
+
{"version":3,"file":"node.d.cts","names":[],"sources":["../src/image-plugin-node.ts"],"mappings":";;;;;;cAyBa,qBAAA,GAAyB,KAAA,EAAO,SAAA,CAAU,QAAA,KAAQ,IAAA;AAAA,cAKlD,UAAA,GACX,KAAA,EAAO,WAAA,EACP,QAAA,WACA,SAAA,WACA,OAAA;EACE,GAAA;EACA,yBAAA,GAA4B,SAAA,CAAU,QAAA;AAAA,MACvC,WAAA;AAAA,cA8EU,aAAA,GACX,KAAA,EAAO,WAAA,EACP,MAAA,2BACA,OAAA;EACE,YAAA;AAAA,MACD,UAAA,CAAA,eAAA;AAAA,cAqBU,eAAA,EAAe,KAAA,CAAA,KAAA,CAAA,WAAA"}
|
package/dist/node.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node.d.mts","names":[],"sources":["../src/image-plugin-node.ts"],"
|
|
1
|
+
{"version":3,"file":"node.d.mts","names":[],"sources":["../src/image-plugin-node.ts"],"mappings":";;;;;;cAyBa,qBAAA,GAAyB,KAAA,EAAO,SAAA,CAAU,QAAA,KAAQ,IAAA;AAAA,cAKlD,UAAA,GACX,KAAA,EAAO,WAAA,EACP,QAAA,WACA,SAAA,WACA,OAAA;EACE,GAAA;EACA,yBAAA,GAA4B,SAAA,CAAU,QAAA;AAAA,MACvC,WAAA;AAAA,cA8EU,aAAA,GACX,KAAA,EAAO,WAAA,EACP,MAAA,2BACA,OAAA;EACE,YAAA;AAAA,MACD,UAAA,CAAA,eAAA;AAAA,cAqBU,eAAA,EAAe,KAAA,CAAA,KAAA,CAAA,WAAA"}
|
package/dist/node.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{t as e}from"./common-
|
|
1
|
+
import{t as e}from"./common-DTrnaMP7.mjs";import{PhotonImage as t,Rgba as n,adjust_brightness as r,adjust_contrast as i,crop as a,fliph as o,flipv as s,gaussian_blur as c,grayscale as l,padding_bottom as u,padding_left as d,padding_right as f,padding_top as p,resize as m,sepia as h,sharpen as g}from"@cf-wasm/photon/node";import{UploadistaError as _}from"@uploadista/core/errors";import{ImagePlugin as v}from"@uploadista/core/flow";import{withOperationSpan as y}from"@uploadista/observability";import{Effect as b,Layer as x}from"effect";const S=e=>{let t=e.toRgb();return new n(t.r,t.g,t.b,t.a)},C=(t,n,r,i)=>{let o=t.get_width(),s=t.get_height();if(!n&&!r)throw Error(`At least one of width or height is required`);if(n&&!r?r=Math.floor(n/o*s):r&&!n&&(n=Math.floor(r/s*o)),!n||!r)throw Error(`Invalid width or height`);if(n===o&&r===s)return t;let c=i?.fit||`cover`,l=e(c,o,s,n,r);t=m(t,l.width,l.height,1);let[h,g]=[t.get_width(),t.get_height()];if(c===`contain`&&i?.fit_cover_letterbox_color){let e=Math.floor((n-h)/2),a=Math.floor((r-g)/2);a>0&&(t=p(t,a,S(i.fit_cover_letterbox_color)),t=u(t,a,S(i.fit_cover_letterbox_color))),e>0&&(t=d(t,e,S(i.fit_cover_letterbox_color)),t=f(t,e,S(i.fit_cover_letterbox_color)))}else if(c===`cover`){let e=Math.floor(h-n)/2,i=Math.floor(g-r)/2;t=a(t,e,i,n+e,r+i)}return t},w=(e,t,n)=>{let r;switch(t){case`webp`:r=e.get_bytes_webp();break;case`jpeg`:r=e.get_bytes_jpeg(n?.jpeg_quality||100);break;case`png`:r=e.get_bytes();break;default:r=e.get_bytes_jpeg(n?.jpeg_quality||100)}return r},T=x.succeed(v,v.of({optimize:(e,{quality:n})=>{let r=t.new_from_byteslice(e),i=r.get_bytes_jpeg(n);return r.free(),b.succeed(i).pipe(y(`image`,`optimize`,{"image.quality":n,"image.input_size":e.byteLength}))},resize:(e,{width:n,height:r,fit:i})=>{if(!n&&!r)throw Error(`Either width or height must be specified for resize`);let a=t.new_from_byteslice(e),o=C(a,n??a.get_width(),r??a.get_height(),{fit:i}),s=o.get_bytes_webp();return a.free(),o.free(),b.succeed(s).pipe(y(`image`,`resize`,{"image.width":n,"image.height":r,"image.fit":i,"image.input_size":e.byteLength}))},transform:(e,n)=>b.gen(function*(){if([`watermark`,`logo`,`text`].includes(n.type))return yield*b.fail(_.fromCode(`UNKNOWN_ERROR`,{body:`Photon plugin does not support '${n.type}'. Use sharp plugin or remove this transformation.`}));let a=t.new_from_byteslice(e);try{switch(n.type){case`resize`:a=C(a,n.width,n.height,{fit:n.fit});break;case`blur`:{let e=Math.round(n.sigma);c(a,e);break}case`rotate`:return yield*b.fail(_.fromCode(`UNKNOWN_ERROR`,{body:`Rotate transformation is not fully supported in photon plugin. Use sharp plugin instead.`}));case`flip`:n.direction===`horizontal`?o(a):s(a);break;case`grayscale`:l(a);break;case`sepia`:h(a);break;case`brightness`:{let e=Math.round(n.value*2.55);r(a,e);break}case`contrast`:{let e=n.value;i(a,e);break}case`sharpen`:g(a);break;default:return yield*b.fail(_.fromCode(`UNKNOWN_ERROR`,{body:`Unknown transformation type: ${n.type}`}))}return a.get_bytes_webp()}finally{a.free()}}).pipe(y(`image`,`transform`,{"image.transformation_type":n.type,"image.input_size":e.byteLength}))}));export{C as autoResize,T as imagePluginNode,w as imageToFormat,S as tinyColorToPhotonRGBA};
|
|
2
2
|
//# sourceMappingURL=node.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serverless.d.cts","names":[],"sources":["../src/image-plugin-serverless.ts"],"
|
|
1
|
+
{"version":3,"file":"serverless.d.cts","names":[],"sources":["../src/image-plugin-serverless.ts"],"mappings":";;;;cAkHa,qBAAA,EAAqB,KAAA,CAAA,KAAA,CAAA,WAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serverless.d.mts","names":[],"sources":["../src/image-plugin-serverless.ts"],"
|
|
1
|
+
{"version":3,"file":"serverless.d.mts","names":[],"sources":["../src/image-plugin-serverless.ts"],"mappings":";;;;cAkHa,qBAAA,EAAqB,KAAA,CAAA,KAAA,CAAA,WAAA"}
|
package/dist/serverless.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{t as e}from"./common-
|
|
1
|
+
import{t as e}from"./common-DTrnaMP7.mjs";import{UploadistaError as t}from"@uploadista/core/errors";import{ImagePlugin as n}from"@uploadista/core/flow";import{Effect as r,Layer as i}from"effect";import{PhotonImage as a,Rgba as o,adjust_brightness as s,adjust_contrast as c,crop as l,fliph as u,flipv as d,gaussian_blur as f,grayscale as p,padding_bottom as m,padding_left as h,padding_right as g,padding_top as _,resize as v,sepia as y,sharpen as b}from"@cf-wasm/photon";const x=e=>{let t=e.toRgb();return new o(t.r,t.g,t.b,t.a)},S=(t,n,r,i)=>{let a=t.get_width(),o=t.get_height();if(!n&&!r)throw Error(`At least one of width or height is required`);if(n&&!r?r=Math.floor(n/a*o):r&&!n&&(n=Math.floor(r/o*a)),!n||!r)throw Error(`Invalid width or height`);if(n===a&&r===o)return t;let s=i?.fit||`cover`,c=e(s,a,o,n,r);t=v(t,c.width,c.height,1);let[u,d]=[t.get_width(),t.get_height()];if(s===`contain`&&i?.fit_cover_letterbox_color){let e=Math.floor((n-u)/2),a=Math.floor((r-d)/2);a>0&&(t=_(t,a,x(i.fit_cover_letterbox_color)),t=m(t,a,x(i.fit_cover_letterbox_color))),e>0&&(t=h(t,e,x(i.fit_cover_letterbox_color)),t=g(t,e,x(i.fit_cover_letterbox_color)))}else if(s===`cover`){let e=Math.floor(u-n)/2,i=Math.floor(d-r)/2;t=l(t,e,i,n+e,r+i)}return t},C=i.succeed(n,n.of({optimize:(e,{quality:t})=>{let n=a.new_from_byteslice(e),i=n.get_bytes_jpeg(t);return n.free(),r.succeed(i)},resize:(e,{width:t,height:n,fit:i})=>{if(!t&&!n)throw Error(`Either width or height must be specified for resize`);let o=a.new_from_byteslice(e),s=S(o,t??o.get_width(),n??o.get_height(),{fit:i}),c=s.get_bytes_webp();return o.free(),s.free(),r.succeed(c)},transform:(e,n)=>r.gen(function*(){if([`watermark`,`logo`,`text`].includes(n.type))return yield*r.fail(t.fromCode(`UNKNOWN_ERROR`,{body:`Photon plugin does not support '${n.type}'. Use sharp plugin or remove this transformation.`}));let i=a.new_from_byteslice(e);try{switch(n.type){case`resize`:i=S(i,n.width,n.height,{fit:n.fit});break;case`blur`:{let e=Math.round(n.sigma);f(i,e);break}case`rotate`:return yield*r.fail(t.fromCode(`UNKNOWN_ERROR`,{body:`Rotate transformation is not fully supported in photon plugin. Use sharp plugin instead.`}));case`flip`:n.direction===`horizontal`?u(i):d(i);break;case`grayscale`:p(i);break;case`sepia`:y(i);break;case`brightness`:{let e=Math.round(n.value*2.55);s(i,e);break}case`contrast`:{let e=n.value;c(i,e);break}case`sharpen`:b(i);break;default:return yield*r.fail(t.fromCode(`UNKNOWN_ERROR`,{body:`Unknown transformation type: ${n.type}`}))}return i.get_bytes_webp()}finally{i.free()}})}));export{C as imagePluginServerless};
|
|
2
2
|
//# sourceMappingURL=serverless.mjs.map
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uploadista/flow-images-photon",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.3-beta.3",
|
|
5
5
|
"description": "Photon image processing service for Uploadista Flow",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"author": "Uploadista",
|
|
@@ -22,8 +22,8 @@
|
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"@cf-wasm/photon": "0.3.4",
|
|
24
24
|
"tinycolor2": "1.6.0",
|
|
25
|
-
"@uploadista/core": "0.1.
|
|
26
|
-
"@uploadista/observability": "0.1.
|
|
25
|
+
"@uploadista/core": "0.1.3-beta.3",
|
|
26
|
+
"@uploadista/observability": "0.1.3-beta.3"
|
|
27
27
|
},
|
|
28
28
|
"peerDependencies": {
|
|
29
29
|
"effect": "^3.0.0",
|
|
@@ -33,11 +33,11 @@
|
|
|
33
33
|
"@effect/vitest": "0.27.0",
|
|
34
34
|
"@types/node": "24.10.9",
|
|
35
35
|
"@types/tinycolor2": "1.4.6",
|
|
36
|
-
"effect": "3.19.
|
|
37
|
-
"tsdown": "0.
|
|
38
|
-
"vitest": "4.0.
|
|
39
|
-
"zod": "4.3.
|
|
40
|
-
"@uploadista/typescript-config": "0.1.
|
|
36
|
+
"effect": "3.19.15",
|
|
37
|
+
"tsdown": "0.20.1",
|
|
38
|
+
"vitest": "4.0.18",
|
|
39
|
+
"zod": "4.3.6",
|
|
40
|
+
"@uploadista/typescript-config": "0.1.3-beta.3"
|
|
41
41
|
},
|
|
42
42
|
"scripts": {
|
|
43
43
|
"build": "tsc --noEmit && tsdown",
|