@pixzle/core 0.0.18 → 0.0.20
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/block-operations.cjs +146 -0
- package/dist/block-operations.d.cts +56 -0
- package/dist/block-operations.d.ts.map +1 -0
- package/dist/block-operations.js +20 -14
- package/dist/block-operations.js.map +1 -1
- package/dist/block-utils.cjs +86 -0
- package/dist/block-utils.d.cts +47 -0
- package/dist/block-utils.d.ts.map +1 -0
- package/dist/block-utils.js +14 -6
- package/dist/block-utils.js.map +1 -1
- package/dist/cjs/block-operations.d.ts +56 -0
- package/dist/cjs/block-operations.d.ts.map +1 -0
- package/dist/cjs/block-operations.js +146 -0
- package/dist/cjs/block-operations.js.map +1 -0
- package/dist/cjs/block-utils.d.ts +47 -0
- package/dist/cjs/block-utils.d.ts.map +1 -0
- package/dist/cjs/block-utils.js +86 -0
- package/dist/cjs/block-utils.js.map +1 -0
- package/dist/cjs/constants.d.ts +8 -0
- package/dist/cjs/constants.d.ts.map +1 -0
- package/dist/cjs/constants.js +11 -0
- package/dist/cjs/constants.js.map +1 -0
- package/dist/cjs/helpers.d.ts +45 -0
- package/dist/cjs/helpers.d.ts.map +1 -0
- package/dist/cjs/helpers.js +101 -0
- package/dist/cjs/helpers.js.map +1 -0
- package/dist/cjs/index.d.ts +8 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js +27 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/types.d.ts +65 -0
- package/dist/cjs/types.d.ts.map +1 -0
- package/dist/cjs/types.js +3 -0
- package/dist/cjs/types.js.map +1 -0
- package/dist/cjs/validators.d.ts +16 -0
- package/dist/cjs/validators.d.ts.map +1 -0
- package/dist/cjs/validators.js +48 -0
- package/dist/cjs/validators.js.map +1 -0
- package/dist/constants.cjs +11 -0
- package/dist/constants.d.cts +8 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +5 -2
- package/dist/constants.js.map +1 -1
- package/dist/esm/block-operations.d.ts +56 -0
- package/dist/esm/block-operations.d.ts.map +1 -0
- package/dist/esm/block-operations.js +140 -0
- package/dist/esm/block-operations.js.map +1 -0
- package/dist/esm/block-utils.d.ts +47 -0
- package/dist/esm/block-utils.d.ts.map +1 -0
- package/dist/esm/block-utils.js +78 -0
- package/dist/esm/block-utils.js.map +1 -0
- package/dist/esm/constants.d.ts +8 -0
- package/dist/esm/constants.d.ts.map +1 -0
- package/dist/esm/constants.js +8 -0
- package/dist/esm/constants.js.map +1 -0
- package/dist/esm/helpers.d.ts +45 -0
- package/dist/esm/helpers.d.ts.map +1 -0
- package/dist/esm/helpers.js +93 -0
- package/dist/esm/helpers.js.map +1 -0
- package/dist/esm/index.d.ts +8 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +9 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/types.d.ts +65 -0
- package/dist/esm/types.d.ts.map +1 -0
- package/dist/esm/types.js +2 -0
- package/dist/esm/types.js.map +1 -0
- package/dist/esm/validators.d.ts +16 -0
- package/dist/esm/validators.d.ts.map +1 -0
- package/dist/esm/validators.js +44 -0
- package/dist/esm/validators.js.map +1 -0
- package/dist/helpers.cjs +101 -0
- package/dist/helpers.d.cts +45 -0
- package/dist/helpers.d.ts.map +1 -0
- package/dist/helpers.js +14 -6
- package/dist/helpers.js.map +1 -1
- package/dist/index.cjs +27 -0
- package/dist/index.d.cts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +25 -7
- package/dist/index.js.map +1 -1
- package/dist/types.cjs +3 -0
- package/dist/types.d.cts +65 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -1
- package/dist/validators.cjs +48 -0
- package/dist/validators.d.cts +16 -0
- package/dist/validators.d.ts.map +1 -0
- package/dist/validators.js +8 -4
- package/dist/validators.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.extractBlock = extractBlock;
|
|
4
|
+
exports.placeBlock = placeBlock;
|
|
5
|
+
exports.splitImageToBlocks = splitImageToBlocks;
|
|
6
|
+
exports.blocksToImageBuffer = blocksToImageBuffer;
|
|
7
|
+
const block_utils_1 = require("./block-utils");
|
|
8
|
+
/**
|
|
9
|
+
* Extract a block from an image buffer
|
|
10
|
+
* @param buffer Source image buffer (RGBA format)
|
|
11
|
+
* @param imageWidth Image width in pixels
|
|
12
|
+
* @param imageHeight Image height in pixels (optional, defaults to calculated height)
|
|
13
|
+
* @param startX Block top-left X coordinate
|
|
14
|
+
* @param startY Block top-left Y coordinate
|
|
15
|
+
* @param blockSize Maximum block size
|
|
16
|
+
* @returns Block buffer containing pixel data
|
|
17
|
+
*/
|
|
18
|
+
function extractBlock(buffer, imageWidth, imageHeight, startX, startY, blockSize) {
|
|
19
|
+
// Calculate actual block dimensions considering image boundaries
|
|
20
|
+
const blockWidth = Math.min(blockSize, imageWidth - startX);
|
|
21
|
+
const blockHeight = imageHeight !== undefined
|
|
22
|
+
? Math.min(blockSize, imageHeight - startY)
|
|
23
|
+
: blockSize;
|
|
24
|
+
const blockData = [];
|
|
25
|
+
// Extract pixel data row by row
|
|
26
|
+
for (let y = 0; y < blockHeight; y++) {
|
|
27
|
+
for (let x = 0; x < blockWidth; x++) {
|
|
28
|
+
const pixelX = startX + x;
|
|
29
|
+
const pixelY = startY + y;
|
|
30
|
+
const pixelIndex = (pixelY * imageWidth + pixelX) * block_utils_1.RGBA_CHANNELS;
|
|
31
|
+
// Copy RGBA channels
|
|
32
|
+
for (let channel = 0; channel < block_utils_1.RGBA_CHANNELS; channel++) {
|
|
33
|
+
blockData.push(buffer[pixelIndex + channel] || 0);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return new Uint8Array(blockData);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Place block data at the specified position in the target image buffer
|
|
41
|
+
* @param targetBuffer Target image buffer to place the block into
|
|
42
|
+
* @param blockData Block data to place
|
|
43
|
+
* @param targetWidth Target image width in pixels
|
|
44
|
+
* @param destX Destination X coordinate
|
|
45
|
+
* @param destY Destination Y coordinate
|
|
46
|
+
* @param blockSize Standard block size
|
|
47
|
+
* @param blockWidth Actual block width (optional, defaults to blockSize)
|
|
48
|
+
* @param blockHeight Actual block height (optional, defaults to blockSize)
|
|
49
|
+
*/
|
|
50
|
+
function placeBlock(targetBuffer, blockData, targetWidth, destX, destY, blockSize, blockWidth, blockHeight) {
|
|
51
|
+
const actualWidth = blockWidth ?? blockSize;
|
|
52
|
+
const actualHeight = blockHeight ?? blockSize;
|
|
53
|
+
// Place pixels row by row
|
|
54
|
+
for (let y = 0; y < actualHeight; y++) {
|
|
55
|
+
for (let x = 0; x < actualWidth; x++) {
|
|
56
|
+
const sourceIndex = (y * actualWidth + x) * block_utils_1.RGBA_CHANNELS;
|
|
57
|
+
const targetIndex = ((destY + y) * targetWidth + (destX + x)) * block_utils_1.RGBA_CHANNELS;
|
|
58
|
+
// Ensure we don't write beyond buffer bounds
|
|
59
|
+
if (targetIndex + block_utils_1.RGBA_CHANNELS <= targetBuffer.length) {
|
|
60
|
+
// Copy RGBA channels
|
|
61
|
+
for (let channel = 0; channel < block_utils_1.RGBA_CHANNELS; channel++) {
|
|
62
|
+
targetBuffer[targetIndex + channel] =
|
|
63
|
+
blockData[sourceIndex + channel];
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Calculate actual block dimensions at edge positions
|
|
71
|
+
* @param position Block position (x or y)
|
|
72
|
+
* @param blockSize Standard block size
|
|
73
|
+
* @param imageSize Image dimension (width or height)
|
|
74
|
+
* @param blockCount Total block count in that dimension
|
|
75
|
+
* @returns Actual block dimension
|
|
76
|
+
*/
|
|
77
|
+
function calculateActualBlockSize(position, blockSize, imageSize, blockCount) {
|
|
78
|
+
const isEdgeBlock = position === blockCount - 1;
|
|
79
|
+
return isEdgeBlock ? imageSize - position * blockSize : blockSize;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Calculate block dimensions considering edge cases
|
|
83
|
+
* @param position Block position
|
|
84
|
+
* @param blockSize Standard block size
|
|
85
|
+
* @param imageWidth Image width
|
|
86
|
+
* @param imageHeight Image height
|
|
87
|
+
* @param blockCounts Block counts
|
|
88
|
+
* @returns Block dimensions
|
|
89
|
+
*/
|
|
90
|
+
function calculateBlockDimensions(position, blockSize, imageWidth, imageHeight, blockCounts) {
|
|
91
|
+
return {
|
|
92
|
+
width: calculateActualBlockSize(position.x, blockSize, imageWidth, blockCounts.blockCountX),
|
|
93
|
+
height: calculateActualBlockSize(position.y, blockSize, imageHeight, blockCounts.blockCountY),
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Split an RGBA image buffer into an array of blocks
|
|
98
|
+
* @param buffer Source image buffer (RGBA format)
|
|
99
|
+
* @param width Image width in pixels
|
|
100
|
+
* @param height Image height in pixels
|
|
101
|
+
* @param blockSize Block size in pixels
|
|
102
|
+
* @returns Array of block buffers
|
|
103
|
+
*/
|
|
104
|
+
function splitImageToBlocks(buffer, width, height, blockSize) {
|
|
105
|
+
const blocks = [];
|
|
106
|
+
const blockCounts = (0, block_utils_1.calculateBlockCounts)(width, height, blockSize);
|
|
107
|
+
// Process blocks row by row, left to right
|
|
108
|
+
for (let blockY = 0; blockY < blockCounts.blockCountY; blockY++) {
|
|
109
|
+
for (let blockX = 0; blockX < blockCounts.blockCountX; blockX++) {
|
|
110
|
+
const startX = blockX * blockSize;
|
|
111
|
+
const startY = blockY * blockSize;
|
|
112
|
+
const block = extractBlock(buffer, width, height, startX, startY, blockSize);
|
|
113
|
+
blocks.push(block);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return blocks;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Reconstruct an RGBA image buffer from an array of blocks
|
|
120
|
+
* @param blocks Array of block buffers
|
|
121
|
+
* @param width Target image width in pixels
|
|
122
|
+
* @param height Target image height in pixels
|
|
123
|
+
* @param blockSize Block size in pixels
|
|
124
|
+
* @returns Reconstructed image buffer
|
|
125
|
+
*/
|
|
126
|
+
function blocksToImageBuffer(blocks, width, height, blockSize) {
|
|
127
|
+
const imageBuffer = new Uint8Array(width * height * block_utils_1.RGBA_CHANNELS);
|
|
128
|
+
const blockCounts = (0, block_utils_1.calculateBlockCounts)(width, height, blockSize);
|
|
129
|
+
let blockIndex = 0;
|
|
130
|
+
// Place blocks row by row, left to right
|
|
131
|
+
for (let blockY = 0; blockY < blockCounts.blockCountY; blockY++) {
|
|
132
|
+
for (let blockX = 0; blockX < blockCounts.blockCountX; blockX++) {
|
|
133
|
+
if (blockIndex >= blocks.length) {
|
|
134
|
+
break;
|
|
135
|
+
}
|
|
136
|
+
const position = { x: blockX, y: blockY };
|
|
137
|
+
const dimensions = calculateBlockDimensions(position, blockSize, width, height, blockCounts);
|
|
138
|
+
const destX = blockX * blockSize;
|
|
139
|
+
const destY = blockY * blockSize;
|
|
140
|
+
placeBlock(imageBuffer, blocks[blockIndex], width, destX, destY, blockSize, dimensions.width, dimensions.height);
|
|
141
|
+
blockIndex++;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return imageBuffer;
|
|
145
|
+
}
|
|
146
|
+
//# sourceMappingURL=block-operations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"block-operations.js","sourceRoot":"","sources":["../../src/block-operations.ts"],"names":[],"mappings":";;AAgCA,oCAgCC;AAaD,gCA8BC;AA4DD,gDA6BC;AAUD,kDA8CC;AA5PD,+CAIuB;AAkBvB;;;;;;;;;GASG;AACH,SAAgB,YAAY,CAC1B,MAAkB,EAClB,UAAkB,EAClB,WAA+B,EAC/B,MAAc,EACd,MAAc,EACd,S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,WAAW,EAAE,MAAM,EAAE,EAAE,CAAC;QAChE,KAAK,IAAI,MAAM,GAAG,CAAC,EAAE,MAAM,GAAG,WAAW,CAAC,WAAW,EAAE,MAAM,EAAE,EAAE,CAAC;YAChE,IAAI,UAAU,IAAI,MAAM,CAAC,MAAM,EAAE,CAAC;gBAChC,MAAM;YACR,CAAC;YAED,MAAM,QAAQ,GAAkB,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC;YACzD,MAAM,UAAU,GAAG,wBAAwB,CACzC,QAAQ,EACR,SAAS,EACT,KAAK,EACL,MAAM,EACN,WAAW,CACZ,CAAC;YAEF,MAAM,KAAK,GAAG,MAAM,GAAG,SAAS,CAAC;YACjC,MAAM,KAAK,GAAG,MAAM,GAAG,SAAS,CAAC;YAEjC,UAAU,CACR,WAAW,EACX,MAAM,CAAC,UAAU,CAAC,EAClB,KAAK,EACL,KAAK,EACL,KAAK,EACL,SAAS,EACT,UAAU,CAAC,KAAK,EAChB,UAAU,CAAC,MAAM,CAClB,CAAC;YAEF,UAAU,EAAE,CAAC;QACf,CAAC;IACH,CAAC;IAED,OAAO,WAAW,CAAC;AACrB,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { ImageInfo } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Number of channels in RGBA format
|
|
4
|
+
*/
|
|
5
|
+
export declare const RGBA_CHANNELS = 4;
|
|
6
|
+
export interface BlockCounts {
|
|
7
|
+
blockCountX: number;
|
|
8
|
+
blockCountY: number;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Calculate block counts for width and height
|
|
12
|
+
* @param width Image width
|
|
13
|
+
* @param height Image height
|
|
14
|
+
* @param blockSize Block size
|
|
15
|
+
* @returns Object with blockCountX and blockCountY
|
|
16
|
+
*/
|
|
17
|
+
export declare function calculateBlockCounts(width: number, height: number, blockSize: number): BlockCounts;
|
|
18
|
+
/**
|
|
19
|
+
* Calculate the range of blocks for a specific image index
|
|
20
|
+
* @param blockCounts Array of block counts per image
|
|
21
|
+
* @param targetIndex Target image index
|
|
22
|
+
* @returns Object with start and end indices
|
|
23
|
+
*/
|
|
24
|
+
export declare function calculateBlockRange(blockCounts: number[], targetIndex: number): {
|
|
25
|
+
start: number;
|
|
26
|
+
end: number;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Calculate how many blocks each fragment should contain for cross-image shuffling
|
|
30
|
+
* @param totalBlocks Total number of blocks to distribute
|
|
31
|
+
* @param fragmentCount Number of fragments to create
|
|
32
|
+
* @returns Array of block counts for each fragment
|
|
33
|
+
*/
|
|
34
|
+
export declare function calculateBlockCountsForCrossImages(totalBlocks: number, fragmentCount: number): number[];
|
|
35
|
+
/**
|
|
36
|
+
* Calculate block counts for each image
|
|
37
|
+
* @param images Array of ImageInfo objects
|
|
38
|
+
* @returns Array of block counts per image (x * y)
|
|
39
|
+
*/
|
|
40
|
+
export declare function calculateBlockCountsPerImage(images: ImageInfo[]): number[];
|
|
41
|
+
/**
|
|
42
|
+
* Calculate total number of blocks from images
|
|
43
|
+
* @param images Array of ImageInfo objects
|
|
44
|
+
* @returns Total block count
|
|
45
|
+
*/
|
|
46
|
+
export declare function calculateTotalBlocks(images: ImageInfo[]): number;
|
|
47
|
+
//# sourceMappingURL=block-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"block-utils.d.ts","sourceRoot":"","sources":["../../src/block-utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAEzC;;GAEG;AACH,eAAO,MAAM,aAAa,IAAI,CAAC;AAE/B,MAAM,WAAW,WAAW;IAC1B,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;CACrB;AAED;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,MAAM,GAChB,WAAW,CAKb;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CACjC,WAAW,EAAE,MAAM,EAAE,EACrB,WAAW,EAAE,MAAM,GAClB;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,CAOhC;AAED;;;;;GAKG;AACH,wBAAgB,kCAAkC,CAChD,WAAW,EAAE,MAAM,EACnB,aAAa,EAAE,MAAM,GACpB,MAAM,EAAE,CAgCV;AAED;;;;GAIG;AACH,wBAAgB,4BAA4B,CAAC,MAAM,EAAE,SAAS,EAAE,GAAG,MAAM,EAAE,CAE1E;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,SAAS,EAAE,GAAG,MAAM,CAEhE"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RGBA_CHANNELS = void 0;
|
|
4
|
+
exports.calculateBlockCounts = calculateBlockCounts;
|
|
5
|
+
exports.calculateBlockRange = calculateBlockRange;
|
|
6
|
+
exports.calculateBlockCountsForCrossImages = calculateBlockCountsForCrossImages;
|
|
7
|
+
exports.calculateBlockCountsPerImage = calculateBlockCountsPerImage;
|
|
8
|
+
exports.calculateTotalBlocks = calculateTotalBlocks;
|
|
9
|
+
/**
|
|
10
|
+
* Number of channels in RGBA format
|
|
11
|
+
*/
|
|
12
|
+
exports.RGBA_CHANNELS = 4;
|
|
13
|
+
/**
|
|
14
|
+
* Calculate block counts for width and height
|
|
15
|
+
* @param width Image width
|
|
16
|
+
* @param height Image height
|
|
17
|
+
* @param blockSize Block size
|
|
18
|
+
* @returns Object with blockCountX and blockCountY
|
|
19
|
+
*/
|
|
20
|
+
function calculateBlockCounts(width, height, blockSize) {
|
|
21
|
+
return {
|
|
22
|
+
blockCountX: Math.ceil(width / blockSize),
|
|
23
|
+
blockCountY: Math.ceil(height / blockSize),
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Calculate the range of blocks for a specific image index
|
|
28
|
+
* @param blockCounts Array of block counts per image
|
|
29
|
+
* @param targetIndex Target image index
|
|
30
|
+
* @returns Object with start and end indices
|
|
31
|
+
*/
|
|
32
|
+
function calculateBlockRange(blockCounts, targetIndex) {
|
|
33
|
+
const start = blockCounts
|
|
34
|
+
.slice(0, targetIndex)
|
|
35
|
+
.reduce((sum, count) => sum + count, 0);
|
|
36
|
+
const end = start + blockCounts[targetIndex];
|
|
37
|
+
return { start, end };
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Calculate how many blocks each fragment should contain for cross-image shuffling
|
|
41
|
+
* @param totalBlocks Total number of blocks to distribute
|
|
42
|
+
* @param fragmentCount Number of fragments to create
|
|
43
|
+
* @returns Array of block counts for each fragment
|
|
44
|
+
*/
|
|
45
|
+
function calculateBlockCountsForCrossImages(totalBlocks, fragmentCount) {
|
|
46
|
+
if (fragmentCount <= 0) {
|
|
47
|
+
throw new Error("Fragment count must be greater than 0");
|
|
48
|
+
}
|
|
49
|
+
if (totalBlocks <= 0) {
|
|
50
|
+
return new Array(fragmentCount).fill(0);
|
|
51
|
+
}
|
|
52
|
+
const baseBlocksPerFragment = Math.ceil(totalBlocks / fragmentCount);
|
|
53
|
+
const fragmentBlockCounts = [];
|
|
54
|
+
let remainingBlocks = totalBlocks;
|
|
55
|
+
// Distribute blocks, ensuring no fragment gets more blocks than available
|
|
56
|
+
for (let i = 0; i < fragmentCount; i++) {
|
|
57
|
+
const blocksForThisFragment = Math.min(baseBlocksPerFragment, remainingBlocks);
|
|
58
|
+
fragmentBlockCounts.push(blocksForThisFragment);
|
|
59
|
+
remainingBlocks -= blocksForThisFragment;
|
|
60
|
+
// If no blocks remain, fill remaining fragments with 0
|
|
61
|
+
if (remainingBlocks <= 0) {
|
|
62
|
+
for (let j = i + 1; j < fragmentCount; j++) {
|
|
63
|
+
fragmentBlockCounts.push(0);
|
|
64
|
+
}
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return fragmentBlockCounts;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Calculate block counts for each image
|
|
72
|
+
* @param images Array of ImageInfo objects
|
|
73
|
+
* @returns Array of block counts per image (x * y)
|
|
74
|
+
*/
|
|
75
|
+
function calculateBlockCountsPerImage(images) {
|
|
76
|
+
return images.map((info) => info.x * info.y);
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Calculate total number of blocks from images
|
|
80
|
+
* @param images Array of ImageInfo objects
|
|
81
|
+
* @returns Total block count
|
|
82
|
+
*/
|
|
83
|
+
function calculateTotalBlocks(images) {
|
|
84
|
+
return images.reduce((total, image) => total + image.x * image.y, 0);
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=block-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"block-utils.js","sourceRoot":"","sources":["../../src/block-utils.ts"],"names":[],"mappings":";;;AAmBA,oDASC;AAQD,kDAUC;AAQD,gFAmCC;AAOD,oEAEC;AAOD,oDAEC;AAzGD;;GAEG;AACU,QAAA,aAAa,GAAG,CAAC,CAAC;AAO/B;;;;;;GAMG;AACH,SAAgB,oBAAoB,CAClC,KAAa,EACb,MAAc,EACd,SAAiB;IAEjB,OAAO;QACL,WAAW,EAAE,IAAI,CAAC,IAAI,CAAC,KAAK,GAAG,SAAS,CAAC;QACzC,WAAW,EAAE,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,SAAS,CAAC;KAC3C,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,SAAgB,mBAAmB,CACjC,WAAqB,EACrB,WAAmB;IAEnB,MAAM,KAAK,GAAG,WAAW;SACtB,KAAK,CAAC,CAAC,EAAE,WAAW,CAAC;SACrB,MAAM,CAAC,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE,CAAC,GAAG,GAAG,KAAK,EAAE,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,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;AAC/C,CAAC;AAED;;;;GAIG;AACH,SAAgB,oBAAoB,CAAC,MAAmB;IACtD,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,KAAK,GAAG,KAAK,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AACvE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,kBAAkB,kBAAkB,CAAC;AAElD,eAAO,MAAM,4BAA4B;;;;;CAKxC,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DEFAULT_FRAGMENTATION_CONFIG = exports.MANIFEST_FILE_NAME = void 0;
|
|
4
|
+
exports.MANIFEST_FILE_NAME = "manifest.json";
|
|
5
|
+
exports.DEFAULT_FRAGMENTATION_CONFIG = {
|
|
6
|
+
BLOCK_SIZE: 2,
|
|
7
|
+
PREFIX: "img",
|
|
8
|
+
PRESERVE_NAME: false,
|
|
9
|
+
CROSS_IMAGE_SHUFFLE: false,
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,kBAAkB,GAAG,eAAe,CAAC;AAErC,QAAA,4BAA4B,GAAG;IAC1C,UAAU,EAAE,CAAC;IACb,MAAM,EAAE,KAAK;IACb,aAAa,EAAE,KAAK;IACpB,mBAAmB,EAAE,KAAK;CAC3B,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { ManifestData } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Encode file name to base64 for safe storage (cross-platform)
|
|
4
|
+
* @param name - Original file name
|
|
5
|
+
* @returns Base64 encoded file name
|
|
6
|
+
*/
|
|
7
|
+
export declare function encodeFileName(name: string): string;
|
|
8
|
+
/**
|
|
9
|
+
* Decode file name from base64 (cross-platform)
|
|
10
|
+
* @param encodedName - Base64 encoded file name
|
|
11
|
+
* @returns Decoded original file name
|
|
12
|
+
*/
|
|
13
|
+
export declare function decodeFileName(encodedName: string): string;
|
|
14
|
+
/**
|
|
15
|
+
* Generate a file name with prefix, 1-based zero-padded index, and extension
|
|
16
|
+
* @param manifest - Manifest data
|
|
17
|
+
* @param index - Index number (0-based, but output is 1-based)
|
|
18
|
+
* @param options - Options for the file name
|
|
19
|
+
* @param options.isFragmented - Whether the fragment is fragmented
|
|
20
|
+
* @returns File name (e.g., img_1.png.enc)
|
|
21
|
+
*/
|
|
22
|
+
export declare function generateFileName(manifest: ManifestData, index: number, options?: {
|
|
23
|
+
isFragmented: boolean;
|
|
24
|
+
}): string;
|
|
25
|
+
/**
|
|
26
|
+
* Generate a fragment file name
|
|
27
|
+
* @param manifest - Manifest data
|
|
28
|
+
* @param index - Index number (0-based, but output is 1-based)
|
|
29
|
+
* @returns Fragment file name (e.g., img_1_fragmented.png)
|
|
30
|
+
*/
|
|
31
|
+
export declare function generateFragmentFileName(manifest: ManifestData, index: number): string;
|
|
32
|
+
/**
|
|
33
|
+
* Generate a restored file name
|
|
34
|
+
* @param manifest - Manifest data
|
|
35
|
+
* @param index - Index number (0-based, but output is 1-based)
|
|
36
|
+
* @returns Restored file name (e.g., img_1.png)
|
|
37
|
+
*/
|
|
38
|
+
export declare function generateRestoredFileName(manifest: ManifestData, index: number): string;
|
|
39
|
+
/**
|
|
40
|
+
* Generate a restored original file name
|
|
41
|
+
* @param imageInfo - Image information
|
|
42
|
+
* @returns Restored original file name
|
|
43
|
+
*/
|
|
44
|
+
export declare function generateRestoredOriginalFileName(imageInfo: ManifestData["images"][number]): string | undefined;
|
|
45
|
+
//# sourceMappingURL=helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE5C;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAYnD;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAQ1D;AAED;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,YAAY,EACtB,KAAK,EAAE,MAAM,EACb,OAAO,GAAE;IACP,YAAY,EAAE,OAAO,CAAC;CAGvB,GACA,MAAM,CASR;AAED;;;;;GAKG;AACH,wBAAgB,wBAAwB,CACtC,QAAQ,EAAE,YAAY,EACtB,KAAK,EAAE,MAAM,GACZ,MAAM,CAIR;AAED;;;;;GAKG;AACH,wBAAgB,wBAAwB,CACtC,QAAQ,EAAE,YAAY,EACtB,KAAK,EAAE,MAAM,GACZ,MAAM,CAIR;AAED;;;;GAIG;AACH,wBAAgB,gCAAgC,CAC9C,SAAS,EAAE,YAAY,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,GACxC,MAAM,GAAG,SAAS,CAWpB"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.encodeFileName = encodeFileName;
|
|
4
|
+
exports.decodeFileName = decodeFileName;
|
|
5
|
+
exports.generateFileName = generateFileName;
|
|
6
|
+
exports.generateFragmentFileName = generateFragmentFileName;
|
|
7
|
+
exports.generateRestoredFileName = generateRestoredFileName;
|
|
8
|
+
exports.generateRestoredOriginalFileName = generateRestoredOriginalFileName;
|
|
9
|
+
/**
|
|
10
|
+
* Encode file name to base64 for safe storage (cross-platform)
|
|
11
|
+
* @param name - Original file name
|
|
12
|
+
* @returns Base64 encoded file name
|
|
13
|
+
*/
|
|
14
|
+
function encodeFileName(name) {
|
|
15
|
+
// Use TextEncoder for UTF-8 encoding (available in both browser and Node.js)
|
|
16
|
+
const encoder = new TextEncoder();
|
|
17
|
+
const bytes = encoder.encode(name);
|
|
18
|
+
// Convert bytes to binary string for btoa (cross-platform)
|
|
19
|
+
// Use loop to avoid stack overflow with large arrays
|
|
20
|
+
let binaryString = "";
|
|
21
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
22
|
+
const byte = bytes[i];
|
|
23
|
+
binaryString += String.fromCharCode(byte);
|
|
24
|
+
}
|
|
25
|
+
return btoa(binaryString);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Decode file name from base64 (cross-platform)
|
|
29
|
+
* @param encodedName - Base64 encoded file name
|
|
30
|
+
* @returns Decoded original file name
|
|
31
|
+
*/
|
|
32
|
+
function decodeFileName(encodedName) {
|
|
33
|
+
// Use atob for base64 decoding (cross-platform)
|
|
34
|
+
const binaryString = atob(encodedName);
|
|
35
|
+
// Convert binary string to bytes
|
|
36
|
+
const bytes = Uint8Array.from(binaryString, (c) => c.charCodeAt(0));
|
|
37
|
+
// Use TextDecoder for UTF-8 decoding (available in both browser and Node.js)
|
|
38
|
+
const decoder = new TextDecoder();
|
|
39
|
+
return decoder.decode(bytes);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Generate a file name with prefix, 1-based zero-padded index, and extension
|
|
43
|
+
* @param manifest - Manifest data
|
|
44
|
+
* @param index - Index number (0-based, but output is 1-based)
|
|
45
|
+
* @param options - Options for the file name
|
|
46
|
+
* @param options.isFragmented - Whether the fragment is fragmented
|
|
47
|
+
* @returns File name (e.g., img_1.png.enc)
|
|
48
|
+
*/
|
|
49
|
+
function generateFileName(manifest, index, options = {
|
|
50
|
+
isFragmented: false,
|
|
51
|
+
}) {
|
|
52
|
+
const prefix = manifest.config.prefix;
|
|
53
|
+
const totalLength = manifest.images.length;
|
|
54
|
+
const extension = "png";
|
|
55
|
+
const numDigits = String(totalLength).length;
|
|
56
|
+
const paddedIndex = String(index + 1).padStart(numDigits, "0");
|
|
57
|
+
const filenameSuffix = options.isFragmented ? "_fragmented" : "";
|
|
58
|
+
const filename = `${prefix}_${paddedIndex}${filenameSuffix}`;
|
|
59
|
+
return `${filename}.${extension}`;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Generate a fragment file name
|
|
63
|
+
* @param manifest - Manifest data
|
|
64
|
+
* @param index - Index number (0-based, but output is 1-based)
|
|
65
|
+
* @returns Fragment file name (e.g., img_1_fragmented.png)
|
|
66
|
+
*/
|
|
67
|
+
function generateFragmentFileName(manifest, index) {
|
|
68
|
+
return generateFileName(manifest, index, {
|
|
69
|
+
isFragmented: true,
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Generate a restored file name
|
|
74
|
+
* @param manifest - Manifest data
|
|
75
|
+
* @param index - Index number (0-based, but output is 1-based)
|
|
76
|
+
* @returns Restored file name (e.g., img_1.png)
|
|
77
|
+
*/
|
|
78
|
+
function generateRestoredFileName(manifest, index) {
|
|
79
|
+
return generateFileName(manifest, index, {
|
|
80
|
+
isFragmented: false,
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Generate a restored original file name
|
|
85
|
+
* @param imageInfo - Image information
|
|
86
|
+
* @returns Restored original file name
|
|
87
|
+
*/
|
|
88
|
+
function generateRestoredOriginalFileName(imageInfo) {
|
|
89
|
+
if (!imageInfo.name) {
|
|
90
|
+
return undefined;
|
|
91
|
+
}
|
|
92
|
+
try {
|
|
93
|
+
const decodedName = decodeFileName(imageInfo.name);
|
|
94
|
+
return decodedName ? `${decodedName}.png` : undefined;
|
|
95
|
+
}
|
|
96
|
+
catch {
|
|
97
|
+
// Fallback: if decoding fails, treat as already decoded (backward compatibility)
|
|
98
|
+
return `${imageInfo.name}.png`;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
//# sourceMappingURL=helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../src/helpers.ts"],"names":[],"mappings":";;AAOA,wCAYC;AAOD,wCAQC;AAUD,4CAiBC;AAQD,4DAOC;AAQD,4DAOC;AAOD,4EAaC;AA7GD;;;;GAIG;AACH,SAAgB,cAAc,CAAC,IAAY;IACzC,6EAA6E;IAC7E,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;IAClC,MAAM,KAAK,GAAG,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACnC,2DAA2D;IAC3D,qDAAqD;IACrD,IAAI,YAAY,GAAG,EAAE,CAAC;IACtB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACtC,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;QACtB,YAAY,IAAI,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;IAC5C,CAAC;IACD,OAAO,IAAI,CAAC,YAAY,CAAC,CAAC;AAC5B,CAAC;AAED;;;;GAIG;AACH,SAAgB,cAAc,CAAC,WAAmB;IAChD,gDAAgD;IAChD,MAAM,YAAY,GAAG,IAAI,CAAC,WAAW,CAAC,CAAC;IACvC,iCAAiC;IACjC,MAAM,KAAK,GAAG,UAAU,CAAC,IAAI,CAAC,YAAY,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;IACpE,6EAA6E;IAC7E,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;IAClC,OAAO,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAC/B,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D,OAAO,WAAW,CAAC,CAAC,CAAC,GAAG,WAAW,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC;IACxD,CAAC;IAAC,MAAM,CAAC;QACP,iFAAiF;QACjF,OAAO,GAAG,SAAS,CAAC,IAAI,MAAM,CAAC;IACjC,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from "./types";
|
|
2
|
+
export * from "./constants";
|
|
3
|
+
export * from "./helpers";
|
|
4
|
+
export * from "./block-utils";
|
|
5
|
+
export * from "./block-operations";
|
|
6
|
+
export * from "./validators";
|
|
7
|
+
export { DEFAULT_FRAGMENTATION_CONFIG } from "./constants";
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,eAAe,CAAC;AAC9B,cAAc,oBAAoB,CAAC;AACnC,cAAc,cAAc,CAAC;AAG7B,OAAO,EAAE,4BAA4B,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.DEFAULT_FRAGMENTATION_CONFIG = void 0;
|
|
18
|
+
__exportStar(require("./types"), exports);
|
|
19
|
+
__exportStar(require("./constants"), exports);
|
|
20
|
+
__exportStar(require("./helpers"), exports);
|
|
21
|
+
__exportStar(require("./block-utils"), exports);
|
|
22
|
+
__exportStar(require("./block-operations"), exports);
|
|
23
|
+
__exportStar(require("./validators"), exports);
|
|
24
|
+
// Re-export constants with old name for backward compatibility
|
|
25
|
+
var constants_1 = require("./constants");
|
|
26
|
+
Object.defineProperty(exports, "DEFAULT_FRAGMENTATION_CONFIG", { enumerable: true, get: function () { return constants_1.DEFAULT_FRAGMENTATION_CONFIG; } });
|
|
27
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,0CAAwB;AACxB,8CAA4B;AAC5B,4CAA0B;AAC1B,gDAA8B;AAC9B,qDAAmC;AACnC,+CAA6B;AAE7B,+DAA+D;AAC/D,yCAA2D;AAAlD,yHAAA,4BAA4B,OAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"commonjs"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
export interface ShuffleOptions {
|
|
2
|
+
/** Image paths (e.g., ["image1.png", "image2.png"]) */
|
|
3
|
+
imagePaths: string[];
|
|
4
|
+
/** Fragmentation config */
|
|
5
|
+
config?: FragmentationConfig;
|
|
6
|
+
/** Output directory (e.g., "./output/fragments") */
|
|
7
|
+
outputDir: string;
|
|
8
|
+
}
|
|
9
|
+
export interface RestoreOptions {
|
|
10
|
+
/** Image paths (e.g., ["fragment1.png", "fragment2.png"]) */
|
|
11
|
+
imagePaths: string[];
|
|
12
|
+
/** Manifest path (e.g., "./output/fragments/manifest.json") */
|
|
13
|
+
manifestPath: string;
|
|
14
|
+
/** Output directory (e.g., "./output/restored") */
|
|
15
|
+
outputDir: string;
|
|
16
|
+
}
|
|
17
|
+
export interface FragmentationConfig {
|
|
18
|
+
/** Pixel block size (e.g., 10x10 to 10) */
|
|
19
|
+
blockSize?: number;
|
|
20
|
+
/** Prefix for fragment files (optional, default: "fragment") */
|
|
21
|
+
prefix?: string;
|
|
22
|
+
/** Random seed (auto-generated if not specified) */
|
|
23
|
+
seed?: number | string;
|
|
24
|
+
/** Preserve original file name (optional, default: false) */
|
|
25
|
+
preserveName?: boolean;
|
|
26
|
+
/** Shuffle blocks across all images instead of within each image independently (optional, default: false) */
|
|
27
|
+
crossImageShuffle?: boolean;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Information about the image before fragmentation.
|
|
31
|
+
* This includes dimensions, channels, and block counts.
|
|
32
|
+
*/
|
|
33
|
+
export interface ImageInfo {
|
|
34
|
+
/** Width */
|
|
35
|
+
w: number;
|
|
36
|
+
/** Height */
|
|
37
|
+
h: number;
|
|
38
|
+
/** Number of channels */
|
|
39
|
+
c: number;
|
|
40
|
+
/** Number of blocks X */
|
|
41
|
+
x: number;
|
|
42
|
+
/** Number of blocks Y */
|
|
43
|
+
y: number;
|
|
44
|
+
/** Original file name in base64 encoding (optional) */
|
|
45
|
+
name?: string;
|
|
46
|
+
}
|
|
47
|
+
export interface ManifestData {
|
|
48
|
+
/** UUID */
|
|
49
|
+
id: string;
|
|
50
|
+
/** Version */
|
|
51
|
+
version: string;
|
|
52
|
+
/** Timestamp */
|
|
53
|
+
timestamp: string;
|
|
54
|
+
/** Config */
|
|
55
|
+
config: Required<FragmentationConfig>;
|
|
56
|
+
/** Image information */
|
|
57
|
+
images: ImageInfo[];
|
|
58
|
+
}
|
|
59
|
+
export interface FragmentationResult {
|
|
60
|
+
/** Manifest data */
|
|
61
|
+
manifest: ManifestData;
|
|
62
|
+
/** Fragmented images */
|
|
63
|
+
fragmentedImages: Buffer[];
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,cAAc;IAC7B,uDAAuD;IACvD,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,2BAA2B;IAC3B,MAAM,CAAC,EAAE,mBAAmB,CAAC;IAC7B,oDAAoD;IACpD,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,cAAc;IAC7B,6DAA6D;IAC7D,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,+DAA+D;IAC/D,YAAY,EAAE,MAAM,CAAC;IACrB,mDAAmD;IACnD,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,mBAAmB;IAClC,2CAA2C;IAC3C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,gEAAgE;IAChE,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,oDAAoD;IACpD,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACvB,6DAA6D;IAC7D,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,6GAA6G;IAC7G,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B;AAED;;;GAGG;AACH,MAAM,WAAW,SAAS;IACxB,YAAY;IACZ,CAAC,EAAE,MAAM,CAAC;IACV,aAAa;IACb,CAAC,EAAE,MAAM,CAAC;IACV,yBAAyB;IACzB,CAAC,EAAE,MAAM,CAAC;IACV,yBAAyB;IACzB,CAAC,EAAE,MAAM,CAAC;IACV,yBAAyB;IACzB,CAAC,EAAE,MAAM,CAAC;IACV,uDAAuD;IACvD,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,YAAY;IAC3B,WAAW;IACX,EAAE,EAAE,MAAM,CAAC;IACX,cAAc;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,gBAAgB;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa;IACb,MAAM,EAAE,QAAQ,CAAC,mBAAmB,CAAC,CAAC;IACtC,wBAAwB;IACxB,MAAM,EAAE,SAAS,EAAE,CAAC;CACrB;AAED,MAAM,WAAW,mBAAmB;IAClC,oBAAoB;IACpB,QAAQ,EAAE,YAAY,CAAC;IACvB,wBAAwB;IACxB,gBAAgB,EAAE,MAAM,EAAE,CAAC;CAC5B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ImageInfo, ManifestData } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Validates that the number of fragment images matches the number of images in the manifest
|
|
4
|
+
* @param fragmentImages - Array of fragment images (file paths or buffers)
|
|
5
|
+
* @param manifest - The manifest data containing image information
|
|
6
|
+
* @throws {Error} When the counts don't match
|
|
7
|
+
*/
|
|
8
|
+
export declare function validateFragmentImageCount(fragmentImages: (string | Buffer)[], manifest: ManifestData): void;
|
|
9
|
+
/**
|
|
10
|
+
* Validates that there are no duplicate file names in the image infos
|
|
11
|
+
* @param imageInfos - Array of image information objects
|
|
12
|
+
* @param preserveName - Whether name preservation is enabled
|
|
13
|
+
* @throws {Error} When duplicate file names are detected
|
|
14
|
+
*/
|
|
15
|
+
export declare function validateFileNames(imageInfos: ImageInfo[], preserveName: boolean): void;
|
|
16
|
+
//# sourceMappingURL=validators.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validators.d.ts","sourceRoot":"","sources":["../../src/validators.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEvD;;;;;GAKG;AACH,wBAAgB,0BAA0B,CACxC,cAAc,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,EACnC,QAAQ,EAAE,YAAY,GACrB,IAAI,CASN;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAC/B,UAAU,EAAE,SAAS,EAAE,EACvB,YAAY,EAAE,OAAO,GACpB,IAAI,CAuBN"}
|