@design-edito/tools 0.1.54 → 0.1.56
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/agnostic/arrays/index.js +7 -7
- package/agnostic/arrays/random-pick/index.js +4 -4
- package/agnostic/css/index.js +11 -11
- package/agnostic/css/styles-set/index.js +4 -4
- package/agnostic/html/hyper-json/cast/index.js +6 -6
- package/agnostic/html/hyper-json/index.js +7 -7
- package/agnostic/html/hyper-json/smart-tags/coalesced/add/index.js +6 -6
- package/agnostic/html/hyper-json/smart-tags/coalesced/addclass/index.js +6 -6
- package/agnostic/html/hyper-json/smart-tags/coalesced/and/index.js +6 -6
- package/agnostic/html/hyper-json/smart-tags/coalesced/append/index.js +6 -6
- package/agnostic/html/hyper-json/smart-tags/coalesced/at/index.js +6 -6
- package/agnostic/html/hyper-json/smart-tags/coalesced/call/index.js +6 -6
- package/agnostic/html/hyper-json/smart-tags/coalesced/clone/index.js +6 -6
- package/agnostic/html/hyper-json/smart-tags/coalesced/deleteproperties/index.js +6 -6
- package/agnostic/html/hyper-json/smart-tags/coalesced/equals/index.js +6 -6
- package/agnostic/html/hyper-json/smart-tags/coalesced/getattribute/index.js +6 -6
- package/agnostic/html/hyper-json/smart-tags/coalesced/getproperties/index.js +6 -6
- package/agnostic/html/hyper-json/smart-tags/coalesced/getproperty/index.js +6 -6
- package/agnostic/html/hyper-json/smart-tags/coalesced/if/index.js +6 -6
- package/agnostic/html/hyper-json/smart-tags/coalesced/initialize/index.js +6 -6
- package/agnostic/html/hyper-json/smart-tags/coalesced/join/index.js +6 -6
- package/agnostic/html/hyper-json/smart-tags/coalesced/length/index.js +6 -6
- package/agnostic/html/hyper-json/smart-tags/coalesced/map/index.js +6 -6
- package/agnostic/html/hyper-json/smart-tags/coalesced/negate/index.js +6 -6
- package/agnostic/html/hyper-json/smart-tags/coalesced/notrailing/index.js +6 -6
- package/agnostic/html/hyper-json/smart-tags/coalesced/or/index.js +6 -6
- package/agnostic/html/hyper-json/smart-tags/coalesced/pickrandom/index.js +6 -6
- package/agnostic/html/hyper-json/smart-tags/coalesced/populate/index.js +6 -6
- package/agnostic/html/hyper-json/smart-tags/coalesced/print/index.js +6 -6
- package/agnostic/html/hyper-json/smart-tags/coalesced/push/index.js +6 -6
- package/agnostic/html/hyper-json/smart-tags/coalesced/pusheach/index.js +6 -6
- package/agnostic/html/hyper-json/smart-tags/coalesced/recordtoarray/index.js +6 -6
- package/agnostic/html/hyper-json/smart-tags/coalesced/removeattribute/index.js +6 -6
- package/agnostic/html/hyper-json/smart-tags/coalesced/removeclass/index.js +6 -6
- package/agnostic/html/hyper-json/smart-tags/coalesced/renameproperty/index.js +6 -6
- package/agnostic/html/hyper-json/smart-tags/coalesced/replace/index.js +6 -6
- package/agnostic/html/hyper-json/smart-tags/coalesced/select/index.js +6 -6
- package/agnostic/html/hyper-json/smart-tags/coalesced/set/index.js +6 -6
- package/agnostic/html/hyper-json/smart-tags/coalesced/setattribute/index.js +6 -6
- package/agnostic/html/hyper-json/smart-tags/coalesced/setproperty/index.js +6 -6
- package/agnostic/html/hyper-json/smart-tags/coalesced/sorton/index.js +6 -6
- package/agnostic/html/hyper-json/smart-tags/coalesced/split/index.js +6 -6
- package/agnostic/html/hyper-json/smart-tags/coalesced/spread/index.js +6 -6
- package/agnostic/html/hyper-json/smart-tags/coalesced/toarray/index.js +6 -6
- package/agnostic/html/hyper-json/smart-tags/coalesced/toboolean/index.js +6 -6
- package/agnostic/html/hyper-json/smart-tags/coalesced/toelement/index.js +6 -6
- package/agnostic/html/hyper-json/smart-tags/coalesced/toggleclass/index.js +6 -6
- package/agnostic/html/hyper-json/smart-tags/coalesced/tonodelist/index.js +6 -6
- package/agnostic/html/hyper-json/smart-tags/coalesced/tonull/index.js +6 -6
- package/agnostic/html/hyper-json/smart-tags/coalesced/tonumber/index.js +6 -6
- package/agnostic/html/hyper-json/smart-tags/coalesced/torecord/index.js +6 -6
- package/agnostic/html/hyper-json/smart-tags/coalesced/toref/index.js +6 -6
- package/agnostic/html/hyper-json/smart-tags/coalesced/tostring/index.js +6 -6
- package/agnostic/html/hyper-json/smart-tags/coalesced/totext/index.js +6 -6
- package/agnostic/html/hyper-json/smart-tags/coalesced/transformselected/index.js +6 -6
- package/agnostic/html/hyper-json/smart-tags/coalesced/trim/index.js +6 -6
- package/agnostic/html/hyper-json/smart-tags/isolated/boolean/index.js +6 -6
- package/agnostic/html/hyper-json/smart-tags/isolated/element/index.js +6 -6
- package/agnostic/html/hyper-json/smart-tags/isolated/get/index.js +6 -6
- package/agnostic/html/hyper-json/smart-tags/isolated/global/index.js +6 -6
- package/agnostic/html/hyper-json/smart-tags/isolated/guess/index.js +6 -6
- package/agnostic/html/hyper-json/smart-tags/isolated/nodelist/index.js +6 -6
- package/agnostic/html/hyper-json/smart-tags/isolated/number/index.js +6 -6
- package/agnostic/html/hyper-json/smart-tags/isolated/record/index.js +6 -6
- package/agnostic/html/hyper-json/smart-tags/isolated/ref/index.js +6 -6
- package/agnostic/html/hyper-json/smart-tags/isolated/string/index.js +6 -6
- package/agnostic/html/hyper-json/smart-tags/isolated/text/index.js +6 -6
- package/agnostic/html/hyper-json/tree/index.js +6 -6
- package/agnostic/html/hyper-json/utils/index.js +6 -6
- package/agnostic/html/index.js +20 -20
- package/agnostic/html/sanitize/index.js +4 -4
- package/agnostic/html/selector-to-element/index.js +4 -4
- package/agnostic/html/string-to-nodes/index.js +5 -5
- package/agnostic/misc/crossenv/index.js +2 -2
- package/agnostic/misc/index.js +21 -21
- package/agnostic/misc/logs/index.js +2 -2
- package/agnostic/misc/lorem-ipsum/index.js +8 -8
- package/agnostic/objects/index.js +14 -14
- package/agnostic/strings/index.js +7 -7
- package/agnostic/time/index.js +3 -3
- package/chunks/chunk-2PNFMIXN.js +20 -0
- package/chunks/chunk-3DJI3JTM.js +56 -0
- package/chunks/chunk-3SSUHWUD.js +56 -0
- package/chunks/chunk-454MZ5UE.js +239 -0
- package/chunks/chunk-4CAHGPFA.js +32 -0
- package/chunks/chunk-55MT7BMY.js +16 -0
- package/chunks/chunk-5IPSIDXB.js +31 -0
- package/chunks/chunk-5P7LHIDR.js +37 -0
- package/chunks/chunk-6PNTQUTX.js +20 -0
- package/chunks/chunk-6WVNJVBE.js +34 -0
- package/chunks/chunk-7N7BJA6C.js +36 -0
- package/chunks/chunk-AE6L2HYA.js +56 -0
- package/chunks/chunk-AIESW26U.js +47 -0
- package/chunks/chunk-AM26FWT6.js +31 -0
- package/chunks/chunk-AZLVQV5A.js +39 -0
- package/chunks/chunk-BW3XNPCJ.js +191 -0
- package/chunks/chunk-C2VF2MJV.js +60 -0
- package/chunks/chunk-CMWR77VW.js +54 -0
- package/chunks/chunk-D2NTUAFE.js +4284 -0
- package/chunks/chunk-D5E2CIDK.js +20 -0
- package/chunks/chunk-EHVYR4OU.js +56 -0
- package/chunks/chunk-GDFWDU4Q.js +2369 -0
- package/chunks/chunk-GKG3UQH3.js +191 -0
- package/chunks/chunk-HKTNK262.js +23 -0
- package/chunks/chunk-HQGZVWBB.js +56 -0
- package/chunks/chunk-I4EBRCSJ.js +20 -0
- package/chunks/chunk-IJ7SOXLA.js +107 -0
- package/chunks/chunk-ILG6VQTL.js +100 -0
- package/chunks/chunk-ISAIFQAY.js +100 -0
- package/chunks/chunk-JSYVAPV6.js +6 -0
- package/chunks/chunk-KFW3ORPQ.js +20 -0
- package/chunks/chunk-KH5JTC2N.js +49 -0
- package/chunks/chunk-KTB7NX4Q.js +56 -0
- package/chunks/chunk-KUIQRVIC.js +100 -0
- package/chunks/chunk-L2L27BLX.js +56 -0
- package/chunks/chunk-LXZULGNN.js +37 -0
- package/chunks/chunk-MC5RLVK5.js +4284 -0
- package/chunks/chunk-MUZGZ3ZF.js +50 -0
- package/chunks/chunk-MV7CCO4Y.js +4430 -0
- package/chunks/chunk-N5QAGJXV.js +49 -0
- package/chunks/chunk-NRRDPNOH.js +100 -0
- package/chunks/chunk-OD33BN4K.js +32 -0
- package/chunks/chunk-OJI6SN6F.js +31 -0
- package/chunks/chunk-OPO25SDO.js +28 -0
- package/chunks/chunk-P3QFJTAE.js +129 -0
- package/chunks/chunk-PEOXR2Q6.js +191 -0
- package/chunks/chunk-QSSQOTGV.js +20 -0
- package/chunks/chunk-QUWGF5WZ.js +191 -0
- package/chunks/chunk-QZPBUDX2.js +20 -0
- package/chunks/chunk-RORBHBEN.js +20 -0
- package/chunks/chunk-RWWYR54P.js +31 -0
- package/chunks/chunk-SEB7TFUB.js +20 -0
- package/chunks/chunk-UHH75BZP.js +56 -0
- package/chunks/chunk-UJN2WZGO.js +32 -0
- package/chunks/chunk-UT75PSLP.js +20 -0
- package/chunks/chunk-VHCD3Z4T.js +20 -0
- package/chunks/chunk-VLHSIIPO.js +20 -0
- package/chunks/chunk-W5LE6YQ5.js +16 -0
- package/chunks/chunk-WDXNM5YB.js +20 -0
- package/chunks/chunk-WO2R3QFK.js +20 -0
- package/chunks/chunk-X4XXZ44B.js +37 -0
- package/chunks/chunk-XC2YGMNJ.js +203 -0
- package/chunks/chunk-ZBQEB3X7.js +4430 -0
- package/chunks/chunk-ZLQUBC5B.js +31 -0
- package/node/@aws-s3/index.d.ts +2 -0
- package/node/@aws-s3/index.js +12 -0
- package/node/@aws-s3/storage/file/download/index.d.ts +22 -0
- package/node/@aws-s3/storage/file/download/index.js +9 -0
- package/node/@aws-s3/storage/file/index.d.ts +3 -0
- package/node/@aws-s3/storage/file/index.js +14 -0
- package/node/@aws-s3/storage/file/upload/index.d.ts +28 -0
- package/node/@aws-s3/storage/file/upload/index.js +9 -0
- package/node/@aws-s3/storage/index.d.ts +2 -0
- package/node/@aws-s3/storage/index.js +12 -0
- package/node/@design-edito/index.js +3 -3
- package/node/@design-edito/thumbnails/index.js +5 -5
- package/node/@design-edito/thumbnails/layout/index.js +2 -2
- package/node/@google-cloud/index.js +13 -13
- package/node/@google-cloud/storage/file/copy/index.d.ts +3 -3
- package/node/@google-cloud/storage/file/copy/index.js +1 -1
- package/node/@google-cloud/storage/file/download/index.d.ts +5 -4
- package/node/@google-cloud/storage/file/download/index.js +1 -1
- package/node/@google-cloud/storage/file/index.js +20 -20
- package/node/@google-cloud/storage/file/move/index.d.ts +3 -3
- package/node/@google-cloud/storage/file/move/index.js +1 -1
- package/node/@google-cloud/storage/file/revoke-signed-urls/index.js +3 -3
- package/node/@google-cloud/storage/file/upload/index.d.ts +13 -9
- package/node/@google-cloud/storage/file/upload/index.js +1 -1
- package/node/@google-cloud/storage/index.js +15 -15
- package/node/cloud-storage/client/index.d.ts +14 -0
- package/node/cloud-storage/client/index.js +20 -0
- package/node/cloud-storage/credentials/index.d.ts +38 -0
- package/node/cloud-storage/credentials/index.js +16 -0
- package/node/cloud-storage/endpoint/index.d.ts +24 -0
- package/node/cloud-storage/endpoint/index.js +13 -0
- package/node/cloud-storage/index.d.ts +5 -0
- package/node/cloud-storage/index.js +32 -0
- package/node/cloud-storage/operations/download/index.d.ts +5 -0
- package/node/cloud-storage/operations/download/index.js +15 -0
- package/node/cloud-storage/operations/index.d.ts +3 -0
- package/node/cloud-storage/operations/index.js +24 -0
- package/node/cloud-storage/operations/upload/index.d.ts +6 -0
- package/node/cloud-storage/operations/upload/index.js +15 -0
- package/node/encryption/buffer/index.d.ts +5 -4
- package/node/encryption/buffer/index.js +10 -10
- package/node/encryption/index.d.ts +4 -5
- package/node/encryption/index.js +9 -21
- package/node/encryption/key/index.d.ts +16 -0
- package/node/encryption/key/index.js +7 -0
- package/node/encryption/uint8-array/index.js +1 -1
- package/node/ftps/file/download/index.d.ts +22 -0
- package/node/ftps/file/download/index.js +9 -0
- package/node/ftps/file/index.d.ts +3 -0
- package/node/ftps/file/index.js +14 -0
- package/node/ftps/file/upload/index.d.ts +24 -0
- package/node/ftps/file/upload/index.js +9 -0
- package/node/ftps/index.d.ts +2 -0
- package/node/ftps/index.js +11 -0
- package/node/images/index.js +9 -9
- package/node/images/prepare/index.js +7 -7
- package/node/images/transform/area-composition/index.js +4 -4
- package/node/images/transform/index.d.ts +182 -5
- package/node/images/transform/index.js +5 -5
- package/node/index.d.ts +5 -1
- package/node/sftp/file/download/index.d.ts +20 -0
- package/node/sftp/file/download/index.js +9 -0
- package/node/sftp/file/index.d.ts +3 -0
- package/node/sftp/file/index.js +14 -0
- package/node/sftp/file/upload/index.d.ts +24 -0
- package/node/sftp/file/upload/index.js +9 -0
- package/node/sftp/index.d.ts +2 -0
- package/node/sftp/index.js +11 -0
- package/package.json +15 -10
@@ -0,0 +1,203 @@
|
|
1
|
+
import {
|
2
|
+
thumbnails_exports
|
3
|
+
} from "./chunk-OPO25SDO.js";
|
4
|
+
|
5
|
+
// src/node/images/transform/area-composition/index.ts
|
6
|
+
import sharp from "sharp";
|
7
|
+
var DEFAULT_GENERATE_OPTIONS = {
|
8
|
+
formats: ["jpeg"],
|
9
|
+
nbOutputs: 1,
|
10
|
+
imagePosition: "center",
|
11
|
+
imageOccupation: 60,
|
12
|
+
dimensions: { w: 300, h: 500 },
|
13
|
+
palette: ["default"],
|
14
|
+
maxPaletteDensity: 100,
|
15
|
+
extractPaletteDensity: 8,
|
16
|
+
lightenIntensity: 20,
|
17
|
+
saturateIntensity: 20,
|
18
|
+
colorFilterApply: "all",
|
19
|
+
tileDensityA: { min: 1, max: 1 },
|
20
|
+
tileDensityB: { min: 1, max: 1 },
|
21
|
+
tileCoverage: 50,
|
22
|
+
tileFormat: "default",
|
23
|
+
tileXEasing: "none",
|
24
|
+
tileYEasing: "none"
|
25
|
+
};
|
26
|
+
async function areaCompose(inputSharp, customOptions) {
|
27
|
+
const options = getOptions(customOptions);
|
28
|
+
const inputMetadata = await inputSharp.metadata();
|
29
|
+
const initialDimensions = {
|
30
|
+
w: inputMetadata.width || 0,
|
31
|
+
h: inputMetadata.height || 0
|
32
|
+
};
|
33
|
+
const inputBufferData = await inputSharp.raw().toBuffer();
|
34
|
+
const imagePalette = thumbnails_exports.Colors.extractPaletteFromImage(inputBufferData, initialDimensions, options);
|
35
|
+
const composedPalette = composePalette(imagePalette, options.palette, options.maxPaletteDensity);
|
36
|
+
inputSharp.png({ quality: 100 });
|
37
|
+
const outputDimensions = {
|
38
|
+
w: options.dimensions.w,
|
39
|
+
h: options.dimensions.h
|
40
|
+
};
|
41
|
+
const resizeInputDimensions = getNewInputImageDimensions(outputDimensions, options.imageOccupation);
|
42
|
+
const resizedInput = inputSharp.resize({
|
43
|
+
width: resizeInputDimensions.w,
|
44
|
+
height: resizeInputDimensions.h,
|
45
|
+
fit: "contain",
|
46
|
+
background: { r: 255, g: 255, b: 255, alpha: 0 }
|
47
|
+
// Add a transparent background
|
48
|
+
}).toFormat("png");
|
49
|
+
const resizedInputPositions = getImagePositions(options.imagePosition, resizeInputDimensions, resizeInputDimensions, outputDimensions);
|
50
|
+
const shapesLayout = thumbnails_exports.Layout.packAreasAndTiles(
|
51
|
+
{
|
52
|
+
...resizedInputPositions,
|
53
|
+
...resizeInputDimensions
|
54
|
+
},
|
55
|
+
outputDimensions,
|
56
|
+
options.tileCoverage,
|
57
|
+
{ A: options.tileDensityA, B: options.tileDensityB },
|
58
|
+
{ X: options.tileXEasing, Y: options.tileYEasing }
|
59
|
+
);
|
60
|
+
const sharpShapes = getSharpTilesInputs(shapesLayout, composedPalette);
|
61
|
+
const sharpShapesForComposite = [];
|
62
|
+
for await (const sharpShape of sharpShapes) {
|
63
|
+
;
|
64
|
+
sharpShapesForComposite.push({
|
65
|
+
input: await sharpShape.input.toFormat("png").toBuffer(),
|
66
|
+
left: sharpShape.left,
|
67
|
+
top: sharpShape.top
|
68
|
+
});
|
69
|
+
}
|
70
|
+
const background = composedPalette[0] || [255, 255, 255];
|
71
|
+
const outputSharp = await createSharpShape(outputDimensions, background).toFormat("webp");
|
72
|
+
const composedSharp = outputSharp.composite([
|
73
|
+
{
|
74
|
+
input: await resizedInput.toFormat("webp").toBuffer(),
|
75
|
+
/* Converting to png to handle alpha */
|
76
|
+
left: Math.round(resizedInputPositions.x),
|
77
|
+
top: Math.round(resizedInputPositions.y)
|
78
|
+
},
|
79
|
+
...sharpShapesForComposite
|
80
|
+
]);
|
81
|
+
return await composedSharp.flatten();
|
82
|
+
}
|
83
|
+
function getOptions(customOptions) {
|
84
|
+
if (!customOptions) {
|
85
|
+
return DEFAULT_GENERATE_OPTIONS;
|
86
|
+
}
|
87
|
+
;
|
88
|
+
const options = {
|
89
|
+
...DEFAULT_GENERATE_OPTIONS,
|
90
|
+
...customOptions
|
91
|
+
};
|
92
|
+
return options;
|
93
|
+
}
|
94
|
+
function getNewInputImageDimensions(formatDimensions, imageOccupation) {
|
95
|
+
const placeRatio = imageOccupation / 100;
|
96
|
+
return {
|
97
|
+
w: Math.round(formatDimensions.w * placeRatio),
|
98
|
+
h: Math.round(formatDimensions.h * placeRatio)
|
99
|
+
};
|
100
|
+
}
|
101
|
+
function composePalette(palette, paletteOption, maxPaletteDensity) {
|
102
|
+
let composedPalette = [];
|
103
|
+
if (paletteOption.includes("default-lighten")) {
|
104
|
+
composedPalette = [...composedPalette, ...palette.default.lighten];
|
105
|
+
}
|
106
|
+
if (paletteOption.includes("default-saturate")) {
|
107
|
+
composedPalette = [...composedPalette, ...palette.default.saturate];
|
108
|
+
}
|
109
|
+
if (paletteOption.includes("complementary")) {
|
110
|
+
composedPalette = [...composedPalette, ...palette.complementary.default];
|
111
|
+
}
|
112
|
+
if (paletteOption.includes("complementary-lighten")) {
|
113
|
+
composedPalette = [...composedPalette, ...palette.complementary.lighten];
|
114
|
+
}
|
115
|
+
if (paletteOption.includes("complementary-saturate")) {
|
116
|
+
composedPalette = [...composedPalette, ...palette.complementary.saturate];
|
117
|
+
}
|
118
|
+
if (paletteOption.includes("default") || !composedPalette.length) {
|
119
|
+
composedPalette = [...composedPalette, ...palette.default.default];
|
120
|
+
}
|
121
|
+
const shuffledPalette = thumbnails_exports.Common.shuffleArray(composedPalette);
|
122
|
+
const outputPalette = composedPalette.length > maxPaletteDensity ? shuffledPalette.splice(0, maxPaletteDensity) : shuffledPalette;
|
123
|
+
return outputPalette;
|
124
|
+
}
|
125
|
+
function getImagePositions(position, resizedImageDimensions, containedImageDimensions, wrapperDimensions) {
|
126
|
+
switch (position) {
|
127
|
+
case "top-left":
|
128
|
+
return thumbnails_exports.Layout.alignTopLeft(resizedImageDimensions, containedImageDimensions, wrapperDimensions);
|
129
|
+
case "top-center":
|
130
|
+
return thumbnails_exports.Layout.alignTopCenter(resizedImageDimensions, containedImageDimensions, wrapperDimensions);
|
131
|
+
case "top-right":
|
132
|
+
return thumbnails_exports.Layout.alignTopRight(resizedImageDimensions, containedImageDimensions, wrapperDimensions);
|
133
|
+
case "left-center":
|
134
|
+
return thumbnails_exports.Layout.alignLeftCenter(resizedImageDimensions, containedImageDimensions, wrapperDimensions);
|
135
|
+
case "center":
|
136
|
+
return thumbnails_exports.Layout.alignCenter(resizedImageDimensions, containedImageDimensions, wrapperDimensions);
|
137
|
+
case "right-center":
|
138
|
+
return thumbnails_exports.Layout.alignRightCenter(resizedImageDimensions, containedImageDimensions, wrapperDimensions);
|
139
|
+
case "bottom-left":
|
140
|
+
return thumbnails_exports.Layout.alignBottomLeft(resizedImageDimensions, containedImageDimensions, wrapperDimensions);
|
141
|
+
case "bottom-center":
|
142
|
+
return thumbnails_exports.Layout.alignBottomCenter(resizedImageDimensions, containedImageDimensions, wrapperDimensions);
|
143
|
+
case "bottom-right":
|
144
|
+
return thumbnails_exports.Layout.alignBottomRight(resizedImageDimensions, containedImageDimensions, wrapperDimensions);
|
145
|
+
default:
|
146
|
+
return { x: 0, y: 0 };
|
147
|
+
}
|
148
|
+
}
|
149
|
+
function createSharpShape(dimensions, background) {
|
150
|
+
return sharp(
|
151
|
+
{
|
152
|
+
create: getCreateSharpShape(dimensions, background)
|
153
|
+
}
|
154
|
+
);
|
155
|
+
}
|
156
|
+
function getCreateSharpShape(dimensions, background) {
|
157
|
+
return {
|
158
|
+
width: Math.round(dimensions.w),
|
159
|
+
height: Math.round(dimensions.h),
|
160
|
+
channels: 4,
|
161
|
+
background: { r: background[0], g: background[1], b: background[2], alpha: 1 }
|
162
|
+
};
|
163
|
+
}
|
164
|
+
function getSharpTilesInputs(tiles, palette) {
|
165
|
+
let usedColorsIndexes = [];
|
166
|
+
const paletteLength = palette.length;
|
167
|
+
const getUnusedColorIndex = () => {
|
168
|
+
const paletteIndex = thumbnails_exports.Common.randomInt(paletteLength);
|
169
|
+
resetUnusedColorIndexesIfNeeded();
|
170
|
+
if (usedColorsIndexes.includes(paletteIndex)) {
|
171
|
+
return getUnusedColorIndex();
|
172
|
+
}
|
173
|
+
usedColorsIndexes.push(paletteIndex);
|
174
|
+
return paletteIndex;
|
175
|
+
};
|
176
|
+
const resetUnusedColorIndexesIfNeeded = () => {
|
177
|
+
if (usedColorsIndexes.length !== paletteLength) {
|
178
|
+
return;
|
179
|
+
}
|
180
|
+
usedColorsIndexes = [];
|
181
|
+
};
|
182
|
+
return tiles.map((tile) => {
|
183
|
+
const paletteIndex = getUnusedColorIndex();
|
184
|
+
const color = palette[paletteIndex];
|
185
|
+
if (!color) {
|
186
|
+
return;
|
187
|
+
}
|
188
|
+
return {
|
189
|
+
top: Math.round(tile.y),
|
190
|
+
left: Math.round(tile.x),
|
191
|
+
input: sharp(
|
192
|
+
{
|
193
|
+
create: getCreateSharpShape(tile, color)
|
194
|
+
}
|
195
|
+
)
|
196
|
+
};
|
197
|
+
}).filter((sharpShape) => sharpShape !== void 0);
|
198
|
+
}
|
199
|
+
|
200
|
+
export {
|
201
|
+
areaCompose,
|
202
|
+
getSharpTilesInputs
|
203
|
+
};
|