@design-edito/tools 0.1.68 → 0.1.70

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.
Files changed (160) hide show
  1. package/agnostic/arrays/index.js +10 -10
  2. package/agnostic/arrays/random-pick/index.js +4 -4
  3. package/agnostic/colors/index.js +8 -8
  4. package/agnostic/css/index.js +10 -10
  5. package/agnostic/css/styles-set/index.js +4 -4
  6. package/agnostic/html/hyper-json/cast/index.js +7 -7
  7. package/agnostic/html/hyper-json/index.js +8 -8
  8. package/agnostic/html/hyper-json/smart-tags/coalesced/add/index.js +7 -7
  9. package/agnostic/html/hyper-json/smart-tags/coalesced/addclass/index.js +7 -7
  10. package/agnostic/html/hyper-json/smart-tags/coalesced/and/index.js +7 -7
  11. package/agnostic/html/hyper-json/smart-tags/coalesced/append/index.js +7 -7
  12. package/agnostic/html/hyper-json/smart-tags/coalesced/at/index.js +7 -7
  13. package/agnostic/html/hyper-json/smart-tags/coalesced/call/index.js +7 -7
  14. package/agnostic/html/hyper-json/smart-tags/coalesced/clone/index.js +7 -7
  15. package/agnostic/html/hyper-json/smart-tags/coalesced/deleteproperties/index.js +7 -7
  16. package/agnostic/html/hyper-json/smart-tags/coalesced/equals/index.js +7 -7
  17. package/agnostic/html/hyper-json/smart-tags/coalesced/getattribute/index.js +7 -7
  18. package/agnostic/html/hyper-json/smart-tags/coalesced/getproperties/index.js +7 -7
  19. package/agnostic/html/hyper-json/smart-tags/coalesced/getproperty/index.js +7 -7
  20. package/agnostic/html/hyper-json/smart-tags/coalesced/if/index.js +7 -7
  21. package/agnostic/html/hyper-json/smart-tags/coalesced/initialize/index.js +7 -7
  22. package/agnostic/html/hyper-json/smart-tags/coalesced/join/index.js +7 -7
  23. package/agnostic/html/hyper-json/smart-tags/coalesced/length/index.js +7 -7
  24. package/agnostic/html/hyper-json/smart-tags/coalesced/map/index.js +7 -7
  25. package/agnostic/html/hyper-json/smart-tags/coalesced/negate/index.js +7 -7
  26. package/agnostic/html/hyper-json/smart-tags/coalesced/notrailing/index.js +7 -7
  27. package/agnostic/html/hyper-json/smart-tags/coalesced/or/index.js +7 -7
  28. package/agnostic/html/hyper-json/smart-tags/coalesced/pickrandom/index.js +7 -7
  29. package/agnostic/html/hyper-json/smart-tags/coalesced/populate/index.js +7 -7
  30. package/agnostic/html/hyper-json/smart-tags/coalesced/print/index.js +7 -7
  31. package/agnostic/html/hyper-json/smart-tags/coalesced/push/index.js +7 -7
  32. package/agnostic/html/hyper-json/smart-tags/coalesced/pusheach/index.js +7 -7
  33. package/agnostic/html/hyper-json/smart-tags/coalesced/recordtoarray/index.js +7 -7
  34. package/agnostic/html/hyper-json/smart-tags/coalesced/removeattribute/index.js +7 -7
  35. package/agnostic/html/hyper-json/smart-tags/coalesced/removeclass/index.js +7 -7
  36. package/agnostic/html/hyper-json/smart-tags/coalesced/renameproperty/index.js +7 -7
  37. package/agnostic/html/hyper-json/smart-tags/coalesced/replace/index.js +7 -7
  38. package/agnostic/html/hyper-json/smart-tags/coalesced/select/index.js +7 -7
  39. package/agnostic/html/hyper-json/smart-tags/coalesced/set/index.js +7 -7
  40. package/agnostic/html/hyper-json/smart-tags/coalesced/setattribute/index.js +7 -7
  41. package/agnostic/html/hyper-json/smart-tags/coalesced/setproperty/index.js +7 -7
  42. package/agnostic/html/hyper-json/smart-tags/coalesced/sorton/index.js +7 -7
  43. package/agnostic/html/hyper-json/smart-tags/coalesced/split/index.js +7 -7
  44. package/agnostic/html/hyper-json/smart-tags/coalesced/spread/index.js +7 -7
  45. package/agnostic/html/hyper-json/smart-tags/coalesced/toarray/index.js +7 -7
  46. package/agnostic/html/hyper-json/smart-tags/coalesced/toboolean/index.js +7 -7
  47. package/agnostic/html/hyper-json/smart-tags/coalesced/toelement/index.js +7 -7
  48. package/agnostic/html/hyper-json/smart-tags/coalesced/toggleclass/index.js +7 -7
  49. package/agnostic/html/hyper-json/smart-tags/coalesced/tonodelist/index.js +7 -7
  50. package/agnostic/html/hyper-json/smart-tags/coalesced/tonull/index.js +7 -7
  51. package/agnostic/html/hyper-json/smart-tags/coalesced/tonumber/index.js +7 -7
  52. package/agnostic/html/hyper-json/smart-tags/coalesced/torecord/index.js +7 -7
  53. package/agnostic/html/hyper-json/smart-tags/coalesced/toref/index.js +7 -7
  54. package/agnostic/html/hyper-json/smart-tags/coalesced/tostring/index.js +7 -7
  55. package/agnostic/html/hyper-json/smart-tags/coalesced/totext/index.js +7 -7
  56. package/agnostic/html/hyper-json/smart-tags/coalesced/transformselected/index.js +7 -7
  57. package/agnostic/html/hyper-json/smart-tags/coalesced/trim/index.js +7 -7
  58. package/agnostic/html/hyper-json/smart-tags/isolated/boolean/index.js +7 -7
  59. package/agnostic/html/hyper-json/smart-tags/isolated/element/index.js +7 -7
  60. package/agnostic/html/hyper-json/smart-tags/isolated/get/index.js +7 -7
  61. package/agnostic/html/hyper-json/smart-tags/isolated/global/index.js +7 -7
  62. package/agnostic/html/hyper-json/smart-tags/isolated/guess/index.js +7 -7
  63. package/agnostic/html/hyper-json/smart-tags/isolated/nodelist/index.js +7 -7
  64. package/agnostic/html/hyper-json/smart-tags/isolated/number/index.js +7 -7
  65. package/agnostic/html/hyper-json/smart-tags/isolated/record/index.js +7 -7
  66. package/agnostic/html/hyper-json/smart-tags/isolated/ref/index.js +7 -7
  67. package/agnostic/html/hyper-json/smart-tags/isolated/string/index.js +7 -7
  68. package/agnostic/html/hyper-json/smart-tags/isolated/text/index.js +7 -7
  69. package/agnostic/html/hyper-json/tree/index.js +7 -7
  70. package/agnostic/html/hyper-json/utils/index.js +7 -7
  71. package/agnostic/html/index.js +20 -20
  72. package/agnostic/html/sanitize/index.js +4 -4
  73. package/agnostic/html/selector-to-element/index.js +4 -4
  74. package/agnostic/html/string-to-nodes/index.js +5 -5
  75. package/agnostic/misc/crossenv/index.js +2 -2
  76. package/agnostic/misc/index.js +29 -29
  77. package/agnostic/misc/logs/index.js +2 -2
  78. package/agnostic/misc/lorem-ipsum/index.js +11 -11
  79. package/agnostic/misc/normalize-extension/index.d.ts +1 -0
  80. package/agnostic/misc/normalize-extension/index.js +92 -0
  81. package/agnostic/numbers/index.js +7 -7
  82. package/agnostic/objects/index.js +13 -13
  83. package/agnostic/strings/index.js +9 -9
  84. package/agnostic/time/index.js +4 -4
  85. package/chunks/chunk-2M5P5V6U.js +56 -0
  86. package/chunks/chunk-336RBB5E.js +151 -0
  87. package/chunks/chunk-3LPD7IXF.js +56 -0
  88. package/chunks/chunk-4Y5XR6WC.js +2456 -0
  89. package/chunks/chunk-5B7VSD44.js +37 -0
  90. package/chunks/chunk-5OBHNGEH.js +20 -0
  91. package/chunks/chunk-6ZBDBWLW.js +164 -0
  92. package/chunks/chunk-7JUKBN7P.js +54 -0
  93. package/chunks/chunk-7U5NS3AR.js +151 -0
  94. package/chunks/chunk-7UDN6KBA.js +151 -0
  95. package/chunks/chunk-A6OSVHIK.js +20 -0
  96. package/chunks/chunk-B5XLWFTJ.js +20 -0
  97. package/chunks/chunk-BPBWY4OT.js +191 -0
  98. package/chunks/chunk-BWKM2VQJ.js +191 -0
  99. package/chunks/chunk-CKCTYZF7.js +48 -0
  100. package/chunks/chunk-E2BDKTLL.js +48 -0
  101. package/chunks/chunk-ECGOI4MT.js +20 -0
  102. package/chunks/chunk-FFNIZRZU.js +31 -0
  103. package/chunks/chunk-FZJUZYTP.js +177 -0
  104. package/chunks/chunk-GD6Y5QJV.js +98 -0
  105. package/chunks/chunk-GSZSM3BU.js +37 -0
  106. package/chunks/chunk-GVS2ZPGJ.js +2456 -0
  107. package/chunks/chunk-HBKSSDSX.js +20 -0
  108. package/chunks/chunk-HFH6DXXC.js +2456 -0
  109. package/chunks/chunk-HV2AHV5R.js +164 -0
  110. package/chunks/chunk-IXM6DCIE.js +151 -0
  111. package/chunks/chunk-JBUM5Q5C.js +48 -0
  112. package/chunks/chunk-JJ7PBKSG.js +37 -0
  113. package/chunks/chunk-JS3NE4VI.js +2456 -0
  114. package/chunks/chunk-K66UXFDQ.js +63 -0
  115. package/chunks/chunk-KBCULP7X.js +177 -0
  116. package/chunks/chunk-KC76PUJY.js +48 -0
  117. package/chunks/chunk-MDVYILPB.js +56 -0
  118. package/chunks/chunk-PCTJ7TUG.js +191 -0
  119. package/chunks/chunk-Q4MSGUKR.js +37 -0
  120. package/chunks/chunk-QHQPS7EU.js +31 -0
  121. package/chunks/chunk-REN2I723.js +98 -0
  122. package/chunks/chunk-RQECU6DI.js +56 -0
  123. package/chunks/chunk-SARTUWB5.js +20 -0
  124. package/chunks/chunk-SDFTYOAK.js +20 -0
  125. package/chunks/chunk-TDOBYMTK.js +56 -0
  126. package/chunks/chunk-TPMYILTC.js +191 -0
  127. package/chunks/chunk-TZ7MNWDS.js +20 -0
  128. package/chunks/chunk-U4UHXVMV.js +37 -0
  129. package/chunks/chunk-UYRX3PTS.js +2456 -0
  130. package/chunks/chunk-UZPXYAJR.js +177 -0
  131. package/chunks/chunk-VLC7LRED.js +191 -0
  132. package/chunks/chunk-WGQHXHXS.js +31 -0
  133. package/chunks/chunk-XB3YCG6I.js +48 -0
  134. package/chunks/chunk-XEMFIV2W.js +177 -0
  135. package/chunks/chunk-XVYKCWPR.js +48 -0
  136. package/chunks/chunk-Y5GGIBPI.js +31 -0
  137. package/chunks/chunk-YMF7CUJA.js +20 -0
  138. package/chunks/chunk-Z6ZTRJ67.js +177 -0
  139. package/chunks/chunk-ZLNDBNP4.js +31 -0
  140. package/chunks/chunk-ZVZAGTIT.js +151 -0
  141. package/node/@express/@multer/index.d.ts +6 -1
  142. package/node/@express/@multer/index.js +2 -1
  143. package/node/@express/index.js +2 -1
  144. package/node/@google-cloud/index.js +5 -5
  145. package/node/@google-cloud/storage/file/index.js +9 -9
  146. package/node/@google-cloud/storage/index.js +5 -5
  147. package/node/cloud-storage/index.js +6 -6
  148. package/node/cloud-storage/operations/download/index.js +2 -2
  149. package/node/cloud-storage/operations/index.js +5 -5
  150. package/node/cloud-storage/operations/upload/index.js +2 -2
  151. package/node/files/index.js +4 -4
  152. package/node/images/index.js +21 -21
  153. package/node/images/prepare/index.js +21 -21
  154. package/node/images/transform/frame/index.js +2 -2
  155. package/node/images/transform/index.js +20 -20
  156. package/node/images/transform/operations/_utils/frame/backgrounds/create-line-background/index.js +2 -2
  157. package/node/images/transform/operations/_utils/frame/backgrounds/create-tile-background/index.js +2 -2
  158. package/node/images/transform/operations/_utils/frame/create-color-palette/index.js +2 -2
  159. package/node/images/transform/operations/_utils/frame/index.js +6 -6
  160. package/package.json +1 -1
@@ -0,0 +1,37 @@
1
+ import {
2
+ Cast,
3
+ Tree,
4
+ Utils
5
+ } from "./chunk-HFH6DXXC.js";
6
+ import {
7
+ Types
8
+ } from "./chunk-XEQ2PBT2.js";
9
+ import {
10
+ SmartTags
11
+ } from "./chunk-UT2J62LH.js";
12
+ import {
13
+ Serialize
14
+ } from "./chunk-SXRWMH3U.js";
15
+ import {
16
+ Transformer
17
+ } from "./chunk-BKO7GLC2.js";
18
+ import {
19
+ Method
20
+ } from "./chunk-RW7VAKJW.js";
21
+
22
+ // src/agnostic/html/hyper-json/index.ts
23
+ var HyperJson;
24
+ ((HyperJson2) => {
25
+ HyperJson2.Cast = Cast;
26
+ HyperJson2.Method = Method;
27
+ HyperJson2.Serialize = Serialize;
28
+ HyperJson2.SmartTags = SmartTags;
29
+ HyperJson2.Transformer = Transformer;
30
+ HyperJson2.Tree = Tree;
31
+ HyperJson2.Types = Types;
32
+ HyperJson2.Utils = Utils;
33
+ })(HyperJson || (HyperJson = {}));
34
+
35
+ export {
36
+ HyperJson
37
+ };
@@ -0,0 +1,20 @@
1
+ import {
2
+ bucket_exports
3
+ } from "./chunk-XSVBWVVC.js";
4
+ import {
5
+ file_exports
6
+ } from "./chunk-TDOBYMTK.js";
7
+ import {
8
+ __export
9
+ } from "./chunk-NZLE2WMY.js";
10
+
11
+ // src/node/@google-cloud/storage/index.ts
12
+ var storage_exports = {};
13
+ __export(storage_exports, {
14
+ Bucket: () => bucket_exports,
15
+ File: () => file_exports
16
+ });
17
+
18
+ export {
19
+ storage_exports
20
+ };
@@ -0,0 +1,164 @@
1
+ import {
2
+ createColorPalette
3
+ } from "./chunk-GD6Y5QJV.js";
4
+ import {
5
+ createLineBackground
6
+ } from "./chunk-C4Q4PC53.js";
7
+ import {
8
+ createTileBackground
9
+ } from "./chunk-CP454IJD.js";
10
+ import {
11
+ getRelativePxPositionsInWrapperFor
12
+ } from "./chunk-OCM3RLO6.js";
13
+ import {
14
+ clamp
15
+ } from "./chunk-OSAXBA7G.js";
16
+
17
+ // src/node/images/transform/operations/_utils/frame/index.ts
18
+ import sharp from "sharp";
19
+ async function frame(imageSharp, params) {
20
+ const imageMetadata = await imageSharp.metadata();
21
+ const imageDimensions = {
22
+ widthPx: imageMetadata.width ?? 0,
23
+ heightPx: imageMetadata.height ?? 0
24
+ };
25
+ const scaledImage = scaleImageToFrame(
26
+ imageSharp,
27
+ imageDimensions,
28
+ params.dimensions,
29
+ params.imageScale
30
+ );
31
+ imageSharp = scaledImage.sharpInstance;
32
+ imageDimensions.widthPx = scaledImage.widthPx;
33
+ imageDimensions.heightPx = scaledImage.heightPx;
34
+ const defaultBackgroundColorCreate = getDefaultBackgroundColor(params.background);
35
+ const imagePositions = getRelativePxPositionsInWrapperFor(imageDimensions, params.dimensions, params.positions);
36
+ const backgroundOverlays = await getBackgroundOverlays(
37
+ {
38
+ sharp: imageSharp,
39
+ dimensions: imageDimensions
40
+ },
41
+ params.background,
42
+ params.dimensions,
43
+ {
44
+ x: imagePositions.x,
45
+ y: imagePositions.y,
46
+ w: imageDimensions.widthPx,
47
+ h: imageDimensions.heightPx
48
+ }
49
+ );
50
+ const composition = [
51
+ ...backgroundOverlays,
52
+ {
53
+ input: await imageSharp.toFormat("png").png({ quality: 100 }).toBuffer(),
54
+ /* Make sure we work with the best quality of our file */
55
+ left: imagePositions.x,
56
+ top: imagePositions.y
57
+ }
58
+ ];
59
+ const frameSharpInstance = sharp({
60
+ create: {
61
+ background: defaultBackgroundColorCreate,
62
+ width: params.dimensions.widthPx,
63
+ height: params.dimensions.heightPx,
64
+ channels: 4
65
+ }
66
+ }).ensureAlpha(0).composite(composition).png({ quality: 100 });
67
+ return frameSharpInstance;
68
+ }
69
+ var scaleImageToFrame = (imageSharp, imageDimensions, frameDimensions, imageScale) => {
70
+ const scale = {
71
+ xRatio: 1,
72
+ yRatio: 1
73
+ };
74
+ const frameZoneDimensions = {
75
+ widthPx: frameDimensions.widthPx,
76
+ heightPx: frameDimensions.heightPx
77
+ };
78
+ if (imageScale) {
79
+ frameZoneDimensions.widthPx = frameDimensions.widthPx * (imageScale.xRatio || 1);
80
+ frameZoneDimensions.heightPx = frameDimensions.heightPx * (imageScale.yRatio || 1);
81
+ }
82
+ const containedRatiosPercents = getContainedRatios(
83
+ imageDimensions.widthPx,
84
+ imageDimensions.heightPx,
85
+ frameZoneDimensions.widthPx,
86
+ frameZoneDimensions.heightPx
87
+ );
88
+ if (imageScale || !imageScale && imageDimensions.widthPx < frameDimensions.widthPx && imageDimensions.heightPx < frameDimensions.heightPx) {
89
+ scale.xRatio = containedRatiosPercents.xPercent;
90
+ scale.yRatio = containedRatiosPercents.yPercent;
91
+ }
92
+ if (scale.xRatio !== 1 || scale.yRatio !== 1) {
93
+ imageDimensions.widthPx = clamp(Math.round(imageDimensions.widthPx * scale.xRatio), 0, frameDimensions.widthPx);
94
+ imageDimensions.heightPx = clamp(Math.round(imageDimensions.heightPx * scale.yRatio), 0, frameDimensions.heightPx);
95
+ imageSharp = imageSharp.resize({
96
+ width: imageDimensions.widthPx,
97
+ height: imageDimensions.heightPx,
98
+ fit: sharp.fit.inside,
99
+ position: "center",
100
+ fastShrinkOnLoad: false
101
+ });
102
+ }
103
+ return {
104
+ sharpInstance: imageSharp,
105
+ widthPx: imageDimensions.widthPx,
106
+ heightPx: imageDimensions.heightPx
107
+ };
108
+ };
109
+ var getDefaultBackgroundColor = (background) => {
110
+ if (background && (typeof background === "object" && "r" in background)) {
111
+ return {
112
+ r: background.r || 255,
113
+ g: background.g || 255,
114
+ b: background.b || 255,
115
+ alpha: background.alpha || 0
116
+ };
117
+ }
118
+ return { r: 255, g: 255, b: 255, alpha: 0 };
119
+ };
120
+ var getBackgroundOverlays = (imageInput, background, dimensions, imageCoordinates) => {
121
+ const backgroundOverlays = [];
122
+ return new Promise(async (resolve, reject) => {
123
+ if (!background || typeof background !== "object" || typeof background === "object" && !("type" in background)) {
124
+ resolve(backgroundOverlays);
125
+ return;
126
+ }
127
+ const imageBuffer = await imageInput.sharp.raw().toBuffer();
128
+ const nbImageChannels = (await imageInput.sharp.metadata()).channels || 3;
129
+ const colorPalette = createColorPalette(
130
+ {
131
+ buffer: imageBuffer,
132
+ nbChannels: nbImageChannels,
133
+ dimensions: imageInput.dimensions
134
+ },
135
+ background.colorPalette
136
+ );
137
+ switch (background.type) {
138
+ case "line":
139
+ return resolve(createLineBackground(background, dimensions, colorPalette));
140
+ case "tile":
141
+ return resolve(createTileBackground(background, dimensions, imageCoordinates, colorPalette));
142
+ default:
143
+ resolve(backgroundOverlays);
144
+ }
145
+ reject(new Error("Unknown background type"));
146
+ });
147
+ };
148
+ function getContainedRatios(widthPx, heightPx, wrapperWidthPx, wrapperHeightPx, withoutReduction) {
149
+ if (withoutReduction && widthPx <= wrapperWidthPx && heightPx <= wrapperHeightPx) {
150
+ return { xPercent: 100, yPercent: 100 };
151
+ }
152
+ const wrapperRatio = wrapperWidthPx / wrapperHeightPx;
153
+ const imgRatio = widthPx / heightPx;
154
+ const containRatio = clamp(imgRatio > wrapperRatio ? wrapperWidthPx / widthPx : wrapperHeightPx / heightPx, 0, 100);
155
+ return {
156
+ xPercent: containRatio,
157
+ yPercent: containRatio
158
+ };
159
+ }
160
+
161
+ export {
162
+ frame,
163
+ getContainedRatios
164
+ };
@@ -0,0 +1,54 @@
1
+ import {
2
+ Outcome
3
+ } from "./chunk-JMU5PDBD.js";
4
+ import {
5
+ unknownToString
6
+ } from "./chunk-FENXVJYO.js";
7
+ import {
8
+ __export
9
+ } from "./chunk-NZLE2WMY.js";
10
+
11
+ // src/node/@express/@multer/index.ts
12
+ var multer_exports = {};
13
+ __export(multer_exports, {
14
+ useMulterMiddleware: () => useMulterMiddleware
15
+ });
16
+ import multer from "multer";
17
+ async function useMulterMiddleware(req, res, options) {
18
+ const { storage, limits, fileFilter } = options;
19
+ const uploader = multer({
20
+ storage: storage ?? multer.memoryStorage(),
21
+ limits,
22
+ fileFilter
23
+ });
24
+ let middleware;
25
+ if (options.mode === "none") {
26
+ middleware = uploader.none();
27
+ } else if (options.mode === "single") {
28
+ middleware = uploader.single(options.fieldName);
29
+ } else if (options.mode === "array") {
30
+ middleware = uploader.array(options.fieldName, options.maxCount);
31
+ } else if (options.mode === "fields") {
32
+ middleware = uploader.fields(options.fields);
33
+ } else {
34
+ middleware = uploader.any();
35
+ }
36
+ return await new Promise((resolve) => middleware(req, res, (err) => {
37
+ if (err instanceof multer.MulterError) return resolve(Outcome.makeFailure({
38
+ code: err.code,
39
+ message: err.message,
40
+ field: err.field
41
+ }));
42
+ return resolve(
43
+ err !== void 0 ? Outcome.makeFailure({
44
+ code: "UNKNOWN",
45
+ message: unknownToString(err)
46
+ }) : Outcome.makeSuccess(true)
47
+ );
48
+ }));
49
+ }
50
+
51
+ export {
52
+ useMulterMiddleware,
53
+ multer_exports
54
+ };
@@ -0,0 +1,151 @@
1
+ import {
2
+ formatImage
3
+ } from "./chunk-SJFY537W.js";
4
+ import {
5
+ transform
6
+ } from "./chunk-XEMFIV2W.js";
7
+ import {
8
+ __export
9
+ } from "./chunk-NZLE2WMY.js";
10
+
11
+ // src/node/images/prepare/index.ts
12
+ var prepare_exports = {};
13
+ __export(prepare_exports, {
14
+ MAX_NB_OUTPUTS: () => MAX_NB_OUTPUTS,
15
+ OUTPUT_ZIP_FOLDER: () => OUTPUT_ZIP_FOLDER,
16
+ exportZipBuffer: () => exportZipBuffer,
17
+ prepareImage: () => prepareImage
18
+ });
19
+ import sharp from "sharp";
20
+ import { Writable } from "node:stream";
21
+ import archiver from "archiver";
22
+ var MAX_NB_OUTPUTS = 50;
23
+ var OUTPUT_ZIP_FOLDER = "./output-zips";
24
+ async function prepareImage(imageBuffer, customOptions) {
25
+ const sharpImage = sharp(imageBuffer);
26
+ const sharpImageMetadata = await sharpImage.metadata();
27
+ const imageBufferMetadata = {
28
+ width: sharpImageMetadata.width ?? 0,
29
+ height: sharpImageMetadata.height ?? 0,
30
+ format: sharpImageMetadata.format || "png"
31
+ };
32
+ const options = getOptions(imageBufferMetadata, customOptions);
33
+ const nbOutputs = options.qualities.length * (options.ratios.length + 1) * (options.widths.length + 1) * (options.heights.length + 1);
34
+ if (nbOutputs > MAX_NB_OUTPUTS) throw Error("Nb output exceeds supported max nb output");
35
+ let transformedBuffer = imageBuffer;
36
+ try {
37
+ transformedBuffer = await transform(imageBuffer, options.inputOperations, options.checkValidOperations);
38
+ } catch (e) {
39
+ console.log("Images:Prepare:Transform:Buffer:Error", { e });
40
+ }
41
+ const transformedBufferMetadata = await sharp(transformedBuffer).metadata();
42
+ const exportsBuffers = [
43
+ {
44
+ buffer: imageBuffer,
45
+ name: generateFileName({
46
+ ...imageBufferMetadata,
47
+ quality: 100,
48
+ suffix: "original",
49
+ prefix: options.name
50
+ })
51
+ },
52
+ {
53
+ buffer: transformedBuffer,
54
+ name: generateFileName({
55
+ width: transformedBufferMetadata.width || 0,
56
+ height: transformedBufferMetadata.height || 0,
57
+ format: transformedBufferMetadata.format || "png",
58
+ quality: 100,
59
+ suffix: "transformed-unresized",
60
+ prefix: options.name
61
+ })
62
+ }
63
+ ];
64
+ for (const width of options.widths) {
65
+ for (const height of options.heights) {
66
+ for (const quality of options.qualities) {
67
+ for (const format of options.formats) {
68
+ const exportBuffer = await formatImage(transformedBuffer, {
69
+ format,
70
+ quality,
71
+ width,
72
+ height
73
+ });
74
+ exportsBuffers.push({
75
+ buffer: exportBuffer,
76
+ name: generateFileName({
77
+ width,
78
+ height,
79
+ quality,
80
+ format,
81
+ prefix: options.name
82
+ })
83
+ });
84
+ }
85
+ }
86
+ }
87
+ }
88
+ console.log("Images:Transform:Export:ZIP", generateZipName(options.name));
89
+ const zipBuffer = exportZipBuffer(exportsBuffers, generateZipName(options.name));
90
+ return zipBuffer;
91
+ }
92
+ function exportZipBuffer(zipSources, zipDirectoryName) {
93
+ return new Promise(async (resolve) => {
94
+ const archive = archiver("zip", { zlib: { level: 9 } });
95
+ if (zipDirectoryName) {
96
+ archive.directory(zipDirectoryName + "/", false);
97
+ }
98
+ zipSources.forEach((zipSource) => {
99
+ const fileName = zipDirectoryName ? `${zipDirectoryName}/${zipSource.name}` : zipSource.name;
100
+ archive.append(zipSource.buffer, { name: fileName });
101
+ });
102
+ const chunks = [];
103
+ const writable = new Writable();
104
+ writable._write = (chunk, _enc, callback) => {
105
+ chunks.push(chunk);
106
+ callback();
107
+ };
108
+ archive.pipe(writable);
109
+ await archive.finalize();
110
+ const bufferZip = Buffer.concat(chunks);
111
+ resolve(bufferZip);
112
+ });
113
+ }
114
+ function getOptions(imageBufferMetadata, options) {
115
+ return {
116
+ center: [0.5, 0.5],
117
+ qualities: [100],
118
+ inputOperations: [],
119
+ ...options,
120
+ checkValidOperations: options?.checkValidOperations ?? false,
121
+ name: options?.name ?? "",
122
+ formats: [imageBufferMetadata.format, ...options?.formats ? options.formats : []],
123
+ ratios: [...options?.ratios ? options.ratios : []],
124
+ widths: [imageBufferMetadata.width, ...options?.widths ? options.widths : []],
125
+ heights: [imageBufferMetadata.height, ...options?.heights ? options.heights : []]
126
+ };
127
+ }
128
+ function generateZipName(name = "") {
129
+ const date = /* @__PURE__ */ new Date();
130
+ return `${name}_image-exports_${date.toLocaleDateString()}_${date.toLocaleTimeString()}_${date.getTime()}`.replace(/\/|:/g, "-").replace(/ /g, "").trim();
131
+ }
132
+ function generateFileName({
133
+ width,
134
+ height,
135
+ quality,
136
+ format,
137
+ suffix,
138
+ prefix
139
+ }) {
140
+ prefix = prefix ? `${prefix}_` : "image-formats_";
141
+ suffix = `${suffix ? `_${suffix}` : ""}.${format}`;
142
+ return `${prefix}${width}x${height}_Q${quality}${suffix}`;
143
+ }
144
+
145
+ export {
146
+ MAX_NB_OUTPUTS,
147
+ OUTPUT_ZIP_FOLDER,
148
+ prepareImage,
149
+ exportZipBuffer,
150
+ prepare_exports
151
+ };
@@ -0,0 +1,151 @@
1
+ import {
2
+ formatImage
3
+ } from "./chunk-SJFY537W.js";
4
+ import {
5
+ transform
6
+ } from "./chunk-FZJUZYTP.js";
7
+ import {
8
+ __export
9
+ } from "./chunk-NZLE2WMY.js";
10
+
11
+ // src/node/images/prepare/index.ts
12
+ var prepare_exports = {};
13
+ __export(prepare_exports, {
14
+ MAX_NB_OUTPUTS: () => MAX_NB_OUTPUTS,
15
+ OUTPUT_ZIP_FOLDER: () => OUTPUT_ZIP_FOLDER,
16
+ exportZipBuffer: () => exportZipBuffer,
17
+ prepareImage: () => prepareImage
18
+ });
19
+ import sharp from "sharp";
20
+ import { Writable } from "node:stream";
21
+ import archiver from "archiver";
22
+ var MAX_NB_OUTPUTS = 50;
23
+ var OUTPUT_ZIP_FOLDER = "./output-zips";
24
+ async function prepareImage(imageBuffer, customOptions) {
25
+ const sharpImage = sharp(imageBuffer);
26
+ const sharpImageMetadata = await sharpImage.metadata();
27
+ const imageBufferMetadata = {
28
+ width: sharpImageMetadata.width ?? 0,
29
+ height: sharpImageMetadata.height ?? 0,
30
+ format: sharpImageMetadata.format || "png"
31
+ };
32
+ const options = getOptions(imageBufferMetadata, customOptions);
33
+ const nbOutputs = options.qualities.length * (options.ratios.length + 1) * (options.widths.length + 1) * (options.heights.length + 1);
34
+ if (nbOutputs > MAX_NB_OUTPUTS) throw Error("Nb output exceeds supported max nb output");
35
+ let transformedBuffer = imageBuffer;
36
+ try {
37
+ transformedBuffer = await transform(imageBuffer, options.inputOperations, options.checkValidOperations);
38
+ } catch (e) {
39
+ console.log("Images:Prepare:Transform:Buffer:Error", { e });
40
+ }
41
+ const transformedBufferMetadata = await sharp(transformedBuffer).metadata();
42
+ const exportsBuffers = [
43
+ {
44
+ buffer: imageBuffer,
45
+ name: generateFileName({
46
+ ...imageBufferMetadata,
47
+ quality: 100,
48
+ suffix: "original",
49
+ prefix: options.name
50
+ })
51
+ },
52
+ {
53
+ buffer: transformedBuffer,
54
+ name: generateFileName({
55
+ width: transformedBufferMetadata.width || 0,
56
+ height: transformedBufferMetadata.height || 0,
57
+ format: transformedBufferMetadata.format || "png",
58
+ quality: 100,
59
+ suffix: "transformed-unresized",
60
+ prefix: options.name
61
+ })
62
+ }
63
+ ];
64
+ for (const width of options.widths) {
65
+ for (const height of options.heights) {
66
+ for (const quality of options.qualities) {
67
+ for (const format of options.formats) {
68
+ const exportBuffer = await formatImage(transformedBuffer, {
69
+ format,
70
+ quality,
71
+ width,
72
+ height
73
+ });
74
+ exportsBuffers.push({
75
+ buffer: exportBuffer,
76
+ name: generateFileName({
77
+ width,
78
+ height,
79
+ quality,
80
+ format,
81
+ prefix: options.name
82
+ })
83
+ });
84
+ }
85
+ }
86
+ }
87
+ }
88
+ console.log("Images:Transform:Export:ZIP", generateZipName(options.name));
89
+ const zipBuffer = exportZipBuffer(exportsBuffers, generateZipName(options.name));
90
+ return zipBuffer;
91
+ }
92
+ function exportZipBuffer(zipSources, zipDirectoryName) {
93
+ return new Promise(async (resolve) => {
94
+ const archive = archiver("zip", { zlib: { level: 9 } });
95
+ if (zipDirectoryName) {
96
+ archive.directory(zipDirectoryName + "/", false);
97
+ }
98
+ zipSources.forEach((zipSource) => {
99
+ const fileName = zipDirectoryName ? `${zipDirectoryName}/${zipSource.name}` : zipSource.name;
100
+ archive.append(zipSource.buffer, { name: fileName });
101
+ });
102
+ const chunks = [];
103
+ const writable = new Writable();
104
+ writable._write = (chunk, _enc, callback) => {
105
+ chunks.push(chunk);
106
+ callback();
107
+ };
108
+ archive.pipe(writable);
109
+ await archive.finalize();
110
+ const bufferZip = Buffer.concat(chunks);
111
+ resolve(bufferZip);
112
+ });
113
+ }
114
+ function getOptions(imageBufferMetadata, options) {
115
+ return {
116
+ center: [0.5, 0.5],
117
+ qualities: [100],
118
+ inputOperations: [],
119
+ ...options,
120
+ checkValidOperations: options?.checkValidOperations ?? false,
121
+ name: options?.name ?? "",
122
+ formats: [imageBufferMetadata.format, ...options?.formats ? options.formats : []],
123
+ ratios: [...options?.ratios ? options.ratios : []],
124
+ widths: [imageBufferMetadata.width, ...options?.widths ? options.widths : []],
125
+ heights: [imageBufferMetadata.height, ...options?.heights ? options.heights : []]
126
+ };
127
+ }
128
+ function generateZipName(name = "") {
129
+ const date = /* @__PURE__ */ new Date();
130
+ return `${name}_image-exports_${date.toLocaleDateString()}_${date.toLocaleTimeString()}_${date.getTime()}`.replace(/\/|:/g, "-").replace(/ /g, "").trim();
131
+ }
132
+ function generateFileName({
133
+ width,
134
+ height,
135
+ quality,
136
+ format,
137
+ suffix,
138
+ prefix
139
+ }) {
140
+ prefix = prefix ? `${prefix}_` : "image-formats_";
141
+ suffix = `${suffix ? `_${suffix}` : ""}.${format}`;
142
+ return `${prefix}${width}x${height}_Q${quality}${suffix}`;
143
+ }
144
+
145
+ export {
146
+ MAX_NB_OUTPUTS,
147
+ OUTPUT_ZIP_FOLDER,
148
+ prepareImage,
149
+ exportZipBuffer,
150
+ prepare_exports
151
+ };
@@ -0,0 +1,20 @@
1
+ import {
2
+ upload_exports
3
+ } from "./chunk-EA4L7AGZ.js";
4
+ import {
5
+ download_exports
6
+ } from "./chunk-ZZH6RUS3.js";
7
+ import {
8
+ __export
9
+ } from "./chunk-NZLE2WMY.js";
10
+
11
+ // src/node/cloud-storage/operations/index.ts
12
+ var operations_exports = {};
13
+ __export(operations_exports, {
14
+ Download: () => download_exports,
15
+ Upload: () => upload_exports
16
+ });
17
+
18
+ export {
19
+ operations_exports
20
+ };
@@ -0,0 +1,20 @@
1
+ import {
2
+ download_exports
3
+ } from "./chunk-XVYKCWPR.js";
4
+ import {
5
+ upload_exports
6
+ } from "./chunk-XB3YCG6I.js";
7
+ import {
8
+ __export
9
+ } from "./chunk-NZLE2WMY.js";
10
+
11
+ // src/node/cloud-storage/operations/index.ts
12
+ var operations_exports = {};
13
+ __export(operations_exports, {
14
+ Download: () => download_exports,
15
+ Upload: () => upload_exports
16
+ });
17
+
18
+ export {
19
+ operations_exports
20
+ };