@pixzle/core 0.0.19 → 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.
Files changed (43) hide show
  1. package/dist/block-operations.cjs +146 -0
  2. package/dist/block-operations.d.cts +56 -0
  3. package/dist/block-operations.d.ts +55 -0
  4. package/dist/block-operations.d.ts.map +1 -0
  5. package/dist/block-operations.js +146 -0
  6. package/dist/block-operations.js.map +1 -0
  7. package/dist/block-utils.cjs +86 -0
  8. package/dist/block-utils.d.cts +47 -0
  9. package/dist/block-utils.d.ts +46 -0
  10. package/dist/block-utils.d.ts.map +1 -0
  11. package/dist/block-utils.js +86 -0
  12. package/dist/block-utils.js.map +1 -0
  13. package/dist/constants.cjs +11 -0
  14. package/dist/constants.d.cts +8 -0
  15. package/dist/constants.d.ts +7 -0
  16. package/dist/constants.d.ts.map +1 -0
  17. package/dist/constants.js +11 -0
  18. package/dist/constants.js.map +1 -0
  19. package/dist/helpers.cjs +101 -0
  20. package/dist/helpers.d.cts +45 -0
  21. package/dist/helpers.d.ts +44 -0
  22. package/dist/helpers.d.ts.map +1 -0
  23. package/dist/helpers.js +101 -0
  24. package/dist/helpers.js.map +1 -0
  25. package/dist/index.cjs +27 -0
  26. package/dist/index.d.cts +8 -0
  27. package/dist/index.d.ts +7 -0
  28. package/dist/index.d.ts.map +1 -0
  29. package/dist/index.js +27 -0
  30. package/dist/index.js.map +1 -0
  31. package/dist/types.cjs +3 -0
  32. package/dist/types.d.cts +65 -0
  33. package/dist/types.d.ts +64 -0
  34. package/dist/types.d.ts.map +1 -0
  35. package/dist/types.js +3 -0
  36. package/dist/types.js.map +1 -0
  37. package/dist/validators.cjs +48 -0
  38. package/dist/validators.d.cts +16 -0
  39. package/dist/validators.d.ts +15 -0
  40. package/dist/validators.d.ts.map +1 -0
  41. package/dist/validators.js +48 -0
  42. package/dist/validators.js.map +1 -0
  43. package/package.json +4 -20
@@ -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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;;;GAIG;AACH,SAAgB,4BAA4B,CAAC,MAAmB;IAC9D,OAAO,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,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,8 @@
1
+ export declare const MANIFEST_FILE_NAME = "manifest.json";
2
+ export declare const DEFAULT_FRAGMENTATION_CONFIG: {
3
+ BLOCK_SIZE: number;
4
+ PREFIX: string;
5
+ PRESERVE_NAME: boolean;
6
+ CROSS_IMAGE_SHUFFLE: boolean;
7
+ };
8
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1,7 @@
1
+ export declare const MANIFEST_FILE_NAME = "manifest.json";
2
+ export declare const DEFAULT_FRAGMENTATION_CONFIG: {
3
+ BLOCK_SIZE: number;
4
+ PREFIX: string;
5
+ PRESERVE_NAME: boolean;
6
+ CROSS_IMAGE_SHUFFLE: boolean;
7
+ };
@@ -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,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,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,44 @@
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;
@@ -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,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E,KAAK;KACpB,CAAC,CAAC;AACL,CAAC;AAED;;;;GAIG;AACH,SAAgB,gCAAgC,CAC9C,SAAyC;IAEzC,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC;QACpB,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,IAAI,CAAC;QACH,MAAM,WAAW,GAAG,cAAc,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;QACnD,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"}
package/dist/index.cjs ADDED
@@ -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,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,7 @@
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";
@@ -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"}
package/dist/index.js ADDED
@@ -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"}
package/dist/types.cjs ADDED
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -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,64 @@
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
+ }