@pixzle/node 0.0.23 → 0.0.25
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/package.json +2 -2
- package/dist/block.cjs +0 -158
- package/dist/block.d.cts +0 -71
- package/dist/block.d.ts.map +0 -1
- package/dist/cjs/block.d.ts +0 -71
- package/dist/cjs/block.d.ts.map +0 -1
- package/dist/cjs/block.js +0 -158
- package/dist/cjs/block.js.map +0 -1
- package/dist/cjs/constants.d.ts +0 -2
- package/dist/cjs/constants.d.ts.map +0 -1
- package/dist/cjs/constants.js +0 -6
- package/dist/cjs/constants.js.map +0 -1
- package/dist/cjs/file.d.ts +0 -33
- package/dist/cjs/file.d.ts.map +0 -1
- package/dist/cjs/file.js +0 -57
- package/dist/cjs/file.js.map +0 -1
- package/dist/cjs/fragmenter.d.ts +0 -14
- package/dist/cjs/fragmenter.d.ts.map +0 -1
- package/dist/cjs/fragmenter.js +0 -95
- package/dist/cjs/fragmenter.js.map +0 -1
- package/dist/cjs/index.d.ts +0 -12
- package/dist/cjs/index.d.ts.map +0 -1
- package/dist/cjs/index.js +0 -59
- package/dist/cjs/index.js.map +0 -1
- package/dist/cjs/package.json +0 -1
- package/dist/cjs/restorer.d.ts +0 -10
- package/dist/cjs/restorer.d.ts.map +0 -1
- package/dist/cjs/restorer.js +0 -54
- package/dist/cjs/restorer.js.map +0 -1
- package/dist/cjs/utils.d.ts +0 -6
- package/dist/cjs/utils.d.ts.map +0 -1
- package/dist/cjs/utils.js +0 -15
- package/dist/cjs/utils.js.map +0 -1
- package/dist/constants.cjs +0 -6
- package/dist/constants.d.cts +0 -2
- package/dist/constants.d.ts.map +0 -1
- package/dist/esm/block.d.ts +0 -71
- package/dist/esm/block.d.ts.map +0 -1
- package/dist/esm/block.js +0 -149
- package/dist/esm/block.js.map +0 -1
- package/dist/esm/constants.d.ts +0 -2
- package/dist/esm/constants.d.ts.map +0 -1
- package/dist/esm/constants.js +0 -3
- package/dist/esm/constants.js.map +0 -1
- package/dist/esm/file.d.ts +0 -33
- package/dist/esm/file.d.ts.map +0 -1
- package/dist/esm/file.js +0 -47
- package/dist/esm/file.js.map +0 -1
- package/dist/esm/fragmenter.d.ts +0 -14
- package/dist/esm/fragmenter.d.ts.map +0 -1
- package/dist/esm/fragmenter.js +0 -91
- package/dist/esm/fragmenter.js.map +0 -1
- package/dist/esm/index.d.ts +0 -12
- package/dist/esm/index.d.ts.map +0 -1
- package/dist/esm/index.js +0 -55
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/restorer.d.ts +0 -10
- package/dist/esm/restorer.d.ts.map +0 -1
- package/dist/esm/restorer.js +0 -50
- package/dist/esm/restorer.js.map +0 -1
- package/dist/esm/utils.d.ts +0 -6
- package/dist/esm/utils.d.ts.map +0 -1
- package/dist/esm/utils.js +0 -9
- package/dist/esm/utils.js.map +0 -1
- package/dist/file.cjs +0 -57
- package/dist/file.d.cts +0 -33
- package/dist/file.d.ts.map +0 -1
- package/dist/fragmenter.cjs +0 -95
- package/dist/fragmenter.d.cts +0 -14
- package/dist/fragmenter.d.ts.map +0 -1
- package/dist/index.cjs +0 -59
- package/dist/index.d.cts +0 -12
- package/dist/index.d.ts.map +0 -1
- package/dist/restorer.cjs +0 -54
- package/dist/restorer.d.cts +0 -10
- package/dist/restorer.d.ts.map +0 -1
- package/dist/utils.cjs +0 -15
- package/dist/utils.d.cts +0 -6
- package/dist/utils.d.ts.map +0 -1
package/dist/esm/file.js
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { promises as fs } from "node:fs";
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
/**
|
|
4
|
-
* Create a directory
|
|
5
|
-
* @param dir Directory path
|
|
6
|
-
* @param recursive Create parent directories if they don't exist
|
|
7
|
-
*/
|
|
8
|
-
export async function createDir(dir, recursive = false) {
|
|
9
|
-
await fs.mkdir(dir, { recursive });
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* Write a file
|
|
13
|
-
* @param dir Directory path
|
|
14
|
-
* @param filename Filename
|
|
15
|
-
* @param data Data to write
|
|
16
|
-
* @returns Path to the file
|
|
17
|
-
*/
|
|
18
|
-
export async function writeFile(dir, filename, data) {
|
|
19
|
-
const filePath = path.join(dir, filename);
|
|
20
|
-
await fs.writeFile(filePath, data);
|
|
21
|
-
return filePath;
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Read a JSON file and return its content
|
|
25
|
-
* @param filePath Path to the JSON file
|
|
26
|
-
* @returns Content of the JSON file
|
|
27
|
-
*/
|
|
28
|
-
export async function readJsonFile(filePath) {
|
|
29
|
-
return JSON.parse(await fs.readFile(filePath, "utf8"));
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Read a file and return its content
|
|
33
|
-
* @param filePath Path to the file
|
|
34
|
-
* @returns Content of the file
|
|
35
|
-
*/
|
|
36
|
-
export async function readFileBuffer(filePath) {
|
|
37
|
-
return await fs.readFile(filePath);
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Get the filename without the extension
|
|
41
|
-
* @param filePath Path to the file
|
|
42
|
-
* @returns Filename without the extension
|
|
43
|
-
*/
|
|
44
|
-
export function fileNameWithoutExtension(filePath) {
|
|
45
|
-
return path.basename(filePath, path.extname(filePath));
|
|
46
|
-
}
|
|
47
|
-
//# sourceMappingURL=file.js.map
|
package/dist/esm/file.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"file.js","sourceRoot":"","sources":["../../src/file.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,GAAW,EAAE,SAAS,GAAG,KAAK;IAC5D,MAAM,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,EAAE,SAAS,EAAE,CAAC,CAAC;AACrC,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,SAAS,CAC7B,GAAW,EACX,QAAgB,EAChB,IAAqB;IAErB,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;IAC1C,MAAM,EAAE,CAAC,SAAS,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;IACnC,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAAI,QAAgB;IACpD,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAC;AACzD,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,QAAgB;IACnD,OAAO,MAAM,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;AACrC,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,wBAAwB,CAAC,QAAgB;IACvD,OAAO,IAAI,CAAC,QAAQ,CAAC,QAAQ,EAAE,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC;AACzD,CAAC"}
|
package/dist/esm/fragmenter.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { type FragmentationConfig, type FragmentationResult } from "@pixzle/core";
|
|
2
|
-
export declare class ImageFragmenter {
|
|
3
|
-
private config;
|
|
4
|
-
constructor(config: FragmentationConfig);
|
|
5
|
-
private _initializeConfig;
|
|
6
|
-
fragmentImages(paths: string[]): Promise<FragmentationResult>;
|
|
7
|
-
private _createImages;
|
|
8
|
-
private _createManifest;
|
|
9
|
-
private _prepareData;
|
|
10
|
-
private _processImages;
|
|
11
|
-
private _processImage;
|
|
12
|
-
private _createImage;
|
|
13
|
-
}
|
|
14
|
-
//# sourceMappingURL=fragmenter.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fragmenter.d.ts","sourceRoot":"","sources":["../../src/fragmenter.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,mBAAmB,EACxB,KAAK,mBAAmB,EAQzB,MAAM,cAAc,CAAC;AAOtB,qBAAa,eAAe;IAC1B,OAAO,CAAC,MAAM,CAAgC;gBAElC,MAAM,EAAE,mBAAmB;IAIvC,OAAO,CAAC,iBAAiB;IAenB,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,mBAAmB,CAAC;YA6BrD,aAAa;IAc3B,OAAO,CAAC,eAAe;YAaT,YAAY;YAyBZ,cAAc;YAcd,aAAa;YAuBb,YAAY;CAW3B"}
|
package/dist/esm/fragmenter.js
DELETED
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import { DEFAULT_FRAGMENTATION_CONFIG, calculateBlockCountsForCrossImages, calculateBlockCountsPerImage, calculateBlockRange, encodeFileName, validateFileNames, } from "@pixzle/core";
|
|
2
|
-
import { SeededRandom, shuffle } from "@tuki0918/seeded-shuffle";
|
|
3
|
-
import { blocksPerImage, blocksToPngImage, imageFileToBlocks } from "./block";
|
|
4
|
-
import { VERSION } from "./constants";
|
|
5
|
-
import { fileNameWithoutExtension, readFileBuffer } from "./file";
|
|
6
|
-
import { generateManifestId } from "./utils";
|
|
7
|
-
export class ImageFragmenter {
|
|
8
|
-
config;
|
|
9
|
-
constructor(config) {
|
|
10
|
-
this.config = this._initializeConfig(config);
|
|
11
|
-
}
|
|
12
|
-
_initializeConfig(config) {
|
|
13
|
-
return {
|
|
14
|
-
blockSize: config.blockSize ?? DEFAULT_FRAGMENTATION_CONFIG.BLOCK_SIZE,
|
|
15
|
-
prefix: config.prefix ?? DEFAULT_FRAGMENTATION_CONFIG.PREFIX,
|
|
16
|
-
seed: config.seed || SeededRandom.generateSeed(),
|
|
17
|
-
preserveName: config.preserveName ?? DEFAULT_FRAGMENTATION_CONFIG.PRESERVE_NAME,
|
|
18
|
-
crossImageShuffle: config.crossImageShuffle ??
|
|
19
|
-
DEFAULT_FRAGMENTATION_CONFIG.CROSS_IMAGE_SHUFFLE,
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
async fragmentImages(paths) {
|
|
23
|
-
const { manifest, blocks, blockCountsForCrossImages, blockCountsPerImage } = await this._prepareData(paths);
|
|
24
|
-
const shuffled = this.config.crossImageShuffle
|
|
25
|
-
? shuffle(blocks, manifest.config.seed)
|
|
26
|
-
: blocksPerImage(blocks, blockCountsPerImage, manifest.config.seed, shuffle);
|
|
27
|
-
const blockCounts = this.config.crossImageShuffle
|
|
28
|
-
? blockCountsForCrossImages
|
|
29
|
-
: blockCountsPerImage;
|
|
30
|
-
const fragmentedImages = await this._createImages(shuffled, blockCounts, manifest);
|
|
31
|
-
return {
|
|
32
|
-
manifest,
|
|
33
|
-
fragmentedImages,
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
async _createImages(blocks, blockCounts, manifest) {
|
|
37
|
-
return await Promise.all(manifest.images.map(async (_, index) => {
|
|
38
|
-
const { start, end } = calculateBlockRange(blockCounts, index);
|
|
39
|
-
const imageBlocks = blocks.slice(start, end);
|
|
40
|
-
return await this._createImage(imageBlocks, manifest.config.blockSize);
|
|
41
|
-
}));
|
|
42
|
-
}
|
|
43
|
-
_createManifest(manifestId, imageInfos) {
|
|
44
|
-
return {
|
|
45
|
-
id: manifestId,
|
|
46
|
-
version: VERSION,
|
|
47
|
-
timestamp: new Date().toISOString(),
|
|
48
|
-
config: this.config,
|
|
49
|
-
images: imageInfos,
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
async _prepareData(paths) {
|
|
53
|
-
const manifestId = generateManifestId();
|
|
54
|
-
const { imageInfos, blocks } = await this._processImages(paths);
|
|
55
|
-
validateFileNames(imageInfos, this.config.preserveName);
|
|
56
|
-
const manifest = this._createManifest(manifestId, imageInfos);
|
|
57
|
-
const blockCountsForCrossImages = calculateBlockCountsForCrossImages(blocks.length, paths.length);
|
|
58
|
-
// Calculate actual block counts per image for per-image shuffle
|
|
59
|
-
const blockCountsPerImage = calculateBlockCountsPerImage(imageInfos);
|
|
60
|
-
return { manifest, blocks, blockCountsForCrossImages, blockCountsPerImage };
|
|
61
|
-
}
|
|
62
|
-
async _processImages(paths) {
|
|
63
|
-
const results = await Promise.all(paths.map((path) => this._processImage(path)));
|
|
64
|
-
const imageInfos = results.map((r) => r.imageInfo);
|
|
65
|
-
const blocks = results.flatMap((r) => r.blocks);
|
|
66
|
-
return { imageInfos, blocks };
|
|
67
|
-
}
|
|
68
|
-
async _processImage(path) {
|
|
69
|
-
const buffer = await readFileBuffer(path);
|
|
70
|
-
const { blocks, width, height, blockCountX, blockCountY } = await imageFileToBlocks(buffer, this.config.blockSize);
|
|
71
|
-
const imageInfo = {
|
|
72
|
-
w: width,
|
|
73
|
-
h: height,
|
|
74
|
-
c: 4, // Always use 4 channels (RGBA) for generated PNG
|
|
75
|
-
x: blockCountX,
|
|
76
|
-
y: blockCountY,
|
|
77
|
-
name: this.config.preserveName
|
|
78
|
-
? encodeFileName(fileNameWithoutExtension(path))
|
|
79
|
-
: undefined,
|
|
80
|
-
};
|
|
81
|
-
return { imageInfo, blocks };
|
|
82
|
-
}
|
|
83
|
-
async _createImage(blocks, blockSize) {
|
|
84
|
-
const blockCount = blocks.length;
|
|
85
|
-
const blocksPerRow = Math.ceil(Math.sqrt(blockCount));
|
|
86
|
-
const imageWidth = blocksPerRow * blockSize;
|
|
87
|
-
const imageHeight = Math.ceil(blockCount / blocksPerRow) * blockSize;
|
|
88
|
-
return await blocksToPngImage(blocks, imageWidth, imageHeight, blockSize);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
//# sourceMappingURL=fragmenter.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fragmenter.js","sourceRoot":"","sources":["../../src/fragmenter.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,4BAA4B,EAK5B,kCAAkC,EACl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AC3B,CAAC,EAAE,KAAK;YACR,CAAC,EAAE,MAAM;YACT,CAAC,EAAE,CAAC,EAAE,iDAAiD;YACvD,CAAC,EAAE,WAAW;YACd,CAAC,EAAE,WAAW;YACd,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,YAAY;gBAC5B,CAAC,CAAC,cAAc,CAAC,wBAAwB,CAAC,IAAI,CAAC,CAAC;gBAChD,CAAC,CAAC,SAAS;SACd,CAAC;QAEF,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,CAAC;IAC/B,CAAC;IAEO,KAAK,CAAC,YAAY,CACxB,MAAgB,EAChB,SAAiB;QAEjB,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC;QACjC,MAAM,YAAY,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC;QACtD,MAAM,UAAU,GAAG,YAAY,GAAG,SAAS,CAAC;QAC5C,MAAM,WAAW,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,GAAG,YAAY,CAAC,GAAG,SAAS,CAAC;QAErE,OAAO,MAAM,gBAAgB,CAAC,MAAM,EAAE,UAAU,EAAE,WAAW,EAAE,SAAS,CAAC,CAAC;IAC5E,CAAC;CACF"}
|
package/dist/esm/index.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { type FragmentationConfig, type ManifestData, type RestoreOptions, type ShuffleOptions } from "@pixzle/core";
|
|
2
|
-
import { ImageFragmenter } from "./fragmenter";
|
|
3
|
-
import { ImageRestorer } from "./restorer";
|
|
4
|
-
export { ImageFragmenter, ImageRestorer, type FragmentationConfig, type ManifestData, };
|
|
5
|
-
declare function shuffle(options: ShuffleOptions): Promise<void>;
|
|
6
|
-
declare function restore(options: RestoreOptions): Promise<void>;
|
|
7
|
-
declare const pixzle: {
|
|
8
|
-
shuffle: typeof shuffle;
|
|
9
|
-
restore: typeof restore;
|
|
10
|
-
};
|
|
11
|
-
export default pixzle;
|
|
12
|
-
//# sourceMappingURL=index.d.ts.map
|
package/dist/esm/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,mBAAmB,EAExB,KAAK,YAAY,EACjB,KAAK,cAAc,EACnB,KAAK,cAAc,EAKpB,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAE3C,OAAO,EACL,eAAe,EACf,aAAa,EACb,KAAK,mBAAmB,EACxB,KAAK,YAAY,GAClB,CAAC;AAEF,iBAAe,OAAO,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAoB7D;AAED,iBAAe,OAAO,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAsB7D;AAED,QAAA,MAAM,MAAM;;;CAGX,CAAC;AAEF,eAAe,MAAM,CAAC"}
|
package/dist/esm/index.js
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { MANIFEST_FILE_NAME, generateFragmentFileName, generateRestoredFileName, generateRestoredOriginalFileName, validateFragmentImageCount, } from "@pixzle/core";
|
|
2
|
-
import { createDir, readJsonFile, writeFile } from "./file";
|
|
3
|
-
import { ImageFragmenter } from "./fragmenter";
|
|
4
|
-
import { ImageRestorer } from "./restorer";
|
|
5
|
-
export { ImageFragmenter, ImageRestorer, };
|
|
6
|
-
async function shuffle(options) {
|
|
7
|
-
const { imagePaths, config, outputDir } = validateShuffleOptions(options);
|
|
8
|
-
const fragmenter = new ImageFragmenter(config ?? {});
|
|
9
|
-
const { manifest, fragmentedImages } = await fragmenter.fragmentImages(imagePaths);
|
|
10
|
-
await createDir(outputDir, true);
|
|
11
|
-
await writeFile(outputDir, MANIFEST_FILE_NAME, JSON.stringify(manifest, null, 2));
|
|
12
|
-
await Promise.all(fragmentedImages.map((img, i) => {
|
|
13
|
-
const filename = generateFragmentFileName(manifest, i);
|
|
14
|
-
return writeFile(outputDir, filename, img);
|
|
15
|
-
}));
|
|
16
|
-
}
|
|
17
|
-
async function restore(options) {
|
|
18
|
-
const { imagePaths, manifestPath, outputDir } = validateRestoreOptions(options);
|
|
19
|
-
const manifest = await readJsonFile(manifestPath);
|
|
20
|
-
validateFragmentImageCount(imagePaths, manifest);
|
|
21
|
-
const restorer = new ImageRestorer();
|
|
22
|
-
const restoredImages = await restorer.restoreImages(imagePaths, manifest);
|
|
23
|
-
await createDir(outputDir, true);
|
|
24
|
-
const imageInfos = manifest.images;
|
|
25
|
-
await Promise.all(restoredImages.map((img, i) => {
|
|
26
|
-
const filename = generateRestoredOriginalFileName(imageInfos[i]) ??
|
|
27
|
-
generateRestoredFileName(manifest, i);
|
|
28
|
-
return writeFile(outputDir, filename, img);
|
|
29
|
-
}));
|
|
30
|
-
}
|
|
31
|
-
const pixzle = {
|
|
32
|
-
shuffle,
|
|
33
|
-
restore,
|
|
34
|
-
};
|
|
35
|
-
export default pixzle;
|
|
36
|
-
function validateCommonOptions(options, context) {
|
|
37
|
-
if (!options)
|
|
38
|
-
throw new Error(`[${context}] Options object is required.`);
|
|
39
|
-
const { imagePaths, outputDir } = options;
|
|
40
|
-
if (!imagePaths || !Array.isArray(imagePaths) || imagePaths.length === 0)
|
|
41
|
-
throw new Error(`[${context}] imagePaths must be a non-empty array.`);
|
|
42
|
-
if (!outputDir || typeof outputDir !== "string")
|
|
43
|
-
throw new Error(`[${context}] outputDir is required and must be a string.`);
|
|
44
|
-
return options;
|
|
45
|
-
}
|
|
46
|
-
function validateShuffleOptions(options) {
|
|
47
|
-
return validateCommonOptions(options, "shuffle");
|
|
48
|
-
}
|
|
49
|
-
function validateRestoreOptions(options) {
|
|
50
|
-
const { manifestPath } = options;
|
|
51
|
-
if (!manifestPath || typeof manifestPath !== "string")
|
|
52
|
-
throw new Error("[restore] manifestPath is required and must be a string.");
|
|
53
|
-
return validateCommonOptions(options, "restore");
|
|
54
|
-
}
|
|
55
|
-
//# sourceMappingURL=index.js.map
|
package/dist/esm/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,kBAAkB,EAIlB,wBAAwB,EACxB,wBAAwB,EACxB,gCAAgC,EAChC,0BAA0B,GAC3B,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAC5D,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAE3C,OAAO,EACL,eAAe,EACf,aAAa,GAGd,CAAC;AAEF,KAAK,UAAU,OAAO,CAAC,OAAuB;IAC5C,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,sBAAsB,CAAC,OAAO,CAAC,CAAC;IAE1E,MAAM,UAAU,GAAG,IAAI,eAAe,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC;IACrD,MAAM,EAAE,QAAQ,EAAE,gBAAgB,EAAE,GAClC,MAAM,UAAU,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC;IAE9C,MAAM,SAAS,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;IACjC,MAAM,SAAS,CACb,SAAS,EACT,kBAAkB,EAClB,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,CAClC,CAAC;IAEF,MAAM,OAAO,CAAC,GAAG,CACf,gBAAgB,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE;QAC9B,MAAM,QAAQ,GAAG,wBAAwB,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC;QACvD,OAAO,SAAS,CAAC,SAAS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UAAU,CAAC,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC;QACtE,MAAM,IAAI,KAAK,CAAC,IAAI,OAAO,yCAAyC,CAAC,CAAC;IACxE,IAAI,CAAC,SAAS,IAAI,OAAO,SAAS,KAAK,QAAQ;QAC7C,MAAM,IAAI,KAAK,CAAC,IAAI,OAAO,+CAA+C,CAAC,CAAC;IAC9E,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,SAAS,sBAAsB,CAAC,OAAuB;IACrD,OAAO,qBAAqB,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;AACnD,CAAC;AAED,SAAS,sBAAsB,CAAC,OAAuB;IACrD,MAAM,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC;IACjC,IAAI,CAAC,YAAY,IAAI,OAAO,YAAY,KAAK,QAAQ;QACnD,MAAM,IAAI,KAAK,CAAC,0DAA0D,CAAC,CAAC;IAC9E,OAAO,qBAAqB,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;AACnD,CAAC"}
|
package/dist/esm/restorer.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { type ManifestData } from "@pixzle/core";
|
|
2
|
-
export declare class ImageRestorer {
|
|
3
|
-
restoreImages(fragments: (string | Buffer)[], manifest: ManifestData): Promise<Buffer[]>;
|
|
4
|
-
private _reconstructImages;
|
|
5
|
-
private _prepareData;
|
|
6
|
-
private _readBlocksFromFragment;
|
|
7
|
-
private _readBlocks;
|
|
8
|
-
private _createImage;
|
|
9
|
-
}
|
|
10
|
-
//# sourceMappingURL=restorer.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"restorer.d.ts","sourceRoot":"","sources":["../../src/restorer.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,YAAY,EAKlB,MAAM,cAAc,CAAC;AAKtB,qBAAa,aAAa;IAClB,aAAa,CACjB,SAAS,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,EAC9B,QAAQ,EAAE,YAAY,GACrB,OAAO,CAAC,MAAM,EAAE,CAAC;YAkBN,kBAAkB;YAkBlB,YAAY;YA2BZ,uBAAuB;YAgBvB,WAAW;YAaX,YAAY;CAQ3B"}
|
package/dist/esm/restorer.js
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { calculateBlockCountsForCrossImages, calculateBlockCountsPerImage, calculateBlockRange, calculateTotalBlocks, } from "@pixzle/core";
|
|
2
|
-
import { unshuffle } from "@tuki0918/seeded-shuffle";
|
|
3
|
-
import { blocksPerImage, blocksToPngImage, imageFileToBlocks } from "./block";
|
|
4
|
-
import { readFileBuffer } from "./file";
|
|
5
|
-
export class ImageRestorer {
|
|
6
|
-
async restoreImages(fragments, manifest) {
|
|
7
|
-
const { blocks, blockCountsPerImage } = await this._prepareData(fragments, manifest);
|
|
8
|
-
const restored = manifest.config.crossImageShuffle
|
|
9
|
-
? unshuffle(blocks, manifest.config.seed)
|
|
10
|
-
: blocksPerImage(blocks, blockCountsPerImage, manifest.config.seed, unshuffle);
|
|
11
|
-
return await this._reconstructImages(restored, manifest);
|
|
12
|
-
}
|
|
13
|
-
async _reconstructImages(blocks, manifest) {
|
|
14
|
-
const blockCountsPerImage = calculateBlockCountsPerImage(manifest.images);
|
|
15
|
-
return await Promise.all(manifest.images.map(async (imageInfo, index) => {
|
|
16
|
-
const { start, end } = calculateBlockRange(blockCountsPerImage, index);
|
|
17
|
-
const imageBlocks = blocks.slice(start, end);
|
|
18
|
-
return await this._createImage(imageBlocks, manifest.config.blockSize, imageInfo);
|
|
19
|
-
}));
|
|
20
|
-
}
|
|
21
|
-
async _prepareData(fragments, manifest) {
|
|
22
|
-
const totalBlocks = calculateTotalBlocks(manifest.images);
|
|
23
|
-
const blockCountsForCrossImages = calculateBlockCountsForCrossImages(totalBlocks, fragments.length);
|
|
24
|
-
// Calculate actual block counts per image for per-image unshuffle
|
|
25
|
-
const blockCountsPerImage = calculateBlockCountsPerImage(manifest.images);
|
|
26
|
-
// Use blockCountsPerImage when crossImageShuffle is false
|
|
27
|
-
const blockCounts = manifest.config.crossImageShuffle
|
|
28
|
-
? blockCountsForCrossImages
|
|
29
|
-
: blockCountsPerImage;
|
|
30
|
-
const blocks = await this._readBlocks(fragments, manifest, blockCounts);
|
|
31
|
-
return { blocks, blockCountsPerImage };
|
|
32
|
-
}
|
|
33
|
-
// Extract an array of blocks (Buffer) from a fragment image
|
|
34
|
-
async _readBlocksFromFragment(fragment, manifest, expectedCount) {
|
|
35
|
-
const buffer = Buffer.isBuffer(fragment)
|
|
36
|
-
? fragment
|
|
37
|
-
: await readFileBuffer(fragment);
|
|
38
|
-
const { blocks } = await imageFileToBlocks(buffer, manifest.config.blockSize);
|
|
39
|
-
return blocks.slice(0, expectedCount);
|
|
40
|
-
}
|
|
41
|
-
async _readBlocks(fragments, manifest, blockCounts) {
|
|
42
|
-
const blockGroups = await Promise.all(fragments.map((fragment, i) => this._readBlocksFromFragment(fragment, manifest, blockCounts[i])));
|
|
43
|
-
return blockGroups.flat();
|
|
44
|
-
}
|
|
45
|
-
async _createImage(blocks, blockSize, imageInfo) {
|
|
46
|
-
const { w, h } = imageInfo;
|
|
47
|
-
return await blocksToPngImage(blocks, w, h, blockSize);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
//# sourceMappingURL=restorer.js.map
|
package/dist/esm/restorer.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"restorer.js","sourceRoot":"","sources":["../../src/restorer.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,kCAAkC,EAClC,4BAA4B,EAC5B,mBAAmB,EACnB,oBAAoB,GACrB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAC9E,OAAO,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAC;AAExC,MA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AAgB,EAChB,SAAiB,EACjB,SAAoB;QAEpB,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,GAAG,SAAS,CAAC;QAC3B,OAAO,MAAM,gBAAgB,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,SAAS,CAAC,CAAC;IACzD,CAAC;CACF"}
|
package/dist/esm/utils.d.ts
DELETED
package/dist/esm/utils.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,wBAAgB,kBAAkB,IAAI,MAAM,CAE3C"}
|
package/dist/esm/utils.js
DELETED
package/dist/esm/utils.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,aAAa,CAAC;AAEjC;;;GAGG;AACH,MAAM,UAAU,kBAAkB;IAChC,OAAO,MAAM,CAAC,UAAU,EAAE,CAAC;AAC7B,CAAC"}
|
package/dist/file.cjs
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.createDir = createDir;
|
|
7
|
-
exports.writeFile = writeFile;
|
|
8
|
-
exports.readJsonFile = readJsonFile;
|
|
9
|
-
exports.readFileBuffer = readFileBuffer;
|
|
10
|
-
exports.fileNameWithoutExtension = fileNameWithoutExtension;
|
|
11
|
-
const node_fs_1 = require("node:fs");
|
|
12
|
-
const node_path_1 = __importDefault(require("node:path"));
|
|
13
|
-
/**
|
|
14
|
-
* Create a directory
|
|
15
|
-
* @param dir Directory path
|
|
16
|
-
* @param recursive Create parent directories if they don't exist
|
|
17
|
-
*/
|
|
18
|
-
async function createDir(dir, recursive = false) {
|
|
19
|
-
await node_fs_1.promises.mkdir(dir, { recursive });
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Write a file
|
|
23
|
-
* @param dir Directory path
|
|
24
|
-
* @param filename Filename
|
|
25
|
-
* @param data Data to write
|
|
26
|
-
* @returns Path to the file
|
|
27
|
-
*/
|
|
28
|
-
async function writeFile(dir, filename, data) {
|
|
29
|
-
const filePath = node_path_1.default.join(dir, filename);
|
|
30
|
-
await node_fs_1.promises.writeFile(filePath, data);
|
|
31
|
-
return filePath;
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Read a JSON file and return its content
|
|
35
|
-
* @param filePath Path to the JSON file
|
|
36
|
-
* @returns Content of the JSON file
|
|
37
|
-
*/
|
|
38
|
-
async function readJsonFile(filePath) {
|
|
39
|
-
return JSON.parse(await node_fs_1.promises.readFile(filePath, "utf8"));
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Read a file and return its content
|
|
43
|
-
* @param filePath Path to the file
|
|
44
|
-
* @returns Content of the file
|
|
45
|
-
*/
|
|
46
|
-
async function readFileBuffer(filePath) {
|
|
47
|
-
return await node_fs_1.promises.readFile(filePath);
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Get the filename without the extension
|
|
51
|
-
* @param filePath Path to the file
|
|
52
|
-
* @returns Filename without the extension
|
|
53
|
-
*/
|
|
54
|
-
function fileNameWithoutExtension(filePath) {
|
|
55
|
-
return node_path_1.default.basename(filePath, node_path_1.default.extname(filePath));
|
|
56
|
-
}
|
|
57
|
-
//# sourceMappingURL=file.js.map
|
package/dist/file.d.cts
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Create a directory
|
|
3
|
-
* @param dir Directory path
|
|
4
|
-
* @param recursive Create parent directories if they don't exist
|
|
5
|
-
*/
|
|
6
|
-
export declare function createDir(dir: string, recursive?: boolean): Promise<void>;
|
|
7
|
-
/**
|
|
8
|
-
* Write a file
|
|
9
|
-
* @param dir Directory path
|
|
10
|
-
* @param filename Filename
|
|
11
|
-
* @param data Data to write
|
|
12
|
-
* @returns Path to the file
|
|
13
|
-
*/
|
|
14
|
-
export declare function writeFile(dir: string, filename: string, data: string | Buffer): Promise<string>;
|
|
15
|
-
/**
|
|
16
|
-
* Read a JSON file and return its content
|
|
17
|
-
* @param filePath Path to the JSON file
|
|
18
|
-
* @returns Content of the JSON file
|
|
19
|
-
*/
|
|
20
|
-
export declare function readJsonFile<T>(filePath: string): Promise<T>;
|
|
21
|
-
/**
|
|
22
|
-
* Read a file and return its content
|
|
23
|
-
* @param filePath Path to the file
|
|
24
|
-
* @returns Content of the file
|
|
25
|
-
*/
|
|
26
|
-
export declare function readFileBuffer(filePath: string): Promise<Buffer>;
|
|
27
|
-
/**
|
|
28
|
-
* Get the filename without the extension
|
|
29
|
-
* @param filePath Path to the file
|
|
30
|
-
* @returns Filename without the extension
|
|
31
|
-
*/
|
|
32
|
-
export declare function fileNameWithoutExtension(filePath: string): string;
|
|
33
|
-
//# sourceMappingURL=file.d.ts.map
|
package/dist/file.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"file.d.ts","sourceRoot":"","sources":["../src/file.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AACH,wBAAsB,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,SAAS,UAAQ,iBAE7D;AAED;;;;;;GAMG;AACH,wBAAsB,SAAS,CAC7B,GAAG,EAAE,MAAM,EACX,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,GAAG,MAAM,mBAKtB;AAED;;;;GAIG;AACH,wBAAsB,YAAY,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC,CAElE;AAED;;;;GAIG;AACH,wBAAsB,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAEtE;AAED;;;;GAIG;AACH,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAEjE"}
|
package/dist/fragmenter.cjs
DELETED
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ImageFragmenter = void 0;
|
|
4
|
-
const core_1 = require("@pixzle/core");
|
|
5
|
-
const seeded_shuffle_1 = require("@tuki0918/seeded-shuffle");
|
|
6
|
-
const block_1 = require("./block");
|
|
7
|
-
const constants_1 = require("./constants");
|
|
8
|
-
const file_1 = require("./file");
|
|
9
|
-
const utils_1 = require("./utils");
|
|
10
|
-
class ImageFragmenter {
|
|
11
|
-
config;
|
|
12
|
-
constructor(config) {
|
|
13
|
-
this.config = this._initializeConfig(config);
|
|
14
|
-
}
|
|
15
|
-
_initializeConfig(config) {
|
|
16
|
-
return {
|
|
17
|
-
blockSize: config.blockSize ?? core_1.DEFAULT_FRAGMENTATION_CONFIG.BLOCK_SIZE,
|
|
18
|
-
prefix: config.prefix ?? core_1.DEFAULT_FRAGMENTATION_CONFIG.PREFIX,
|
|
19
|
-
seed: config.seed || seeded_shuffle_1.SeededRandom.generateSeed(),
|
|
20
|
-
preserveName: config.preserveName ?? core_1.DEFAULT_FRAGMENTATION_CONFIG.PRESERVE_NAME,
|
|
21
|
-
crossImageShuffle: config.crossImageShuffle ??
|
|
22
|
-
core_1.DEFAULT_FRAGMENTATION_CONFIG.CROSS_IMAGE_SHUFFLE,
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
async fragmentImages(paths) {
|
|
26
|
-
const { manifest, blocks, blockCountsForCrossImages, blockCountsPerImage } = await this._prepareData(paths);
|
|
27
|
-
const shuffled = this.config.crossImageShuffle
|
|
28
|
-
? (0, seeded_shuffle_1.shuffle)(blocks, manifest.config.seed)
|
|
29
|
-
: (0, block_1.blocksPerImage)(blocks, blockCountsPerImage, manifest.config.seed, seeded_shuffle_1.shuffle);
|
|
30
|
-
const blockCounts = this.config.crossImageShuffle
|
|
31
|
-
? blockCountsForCrossImages
|
|
32
|
-
: blockCountsPerImage;
|
|
33
|
-
const fragmentedImages = await this._createImages(shuffled, blockCounts, manifest);
|
|
34
|
-
return {
|
|
35
|
-
manifest,
|
|
36
|
-
fragmentedImages,
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
async _createImages(blocks, blockCounts, manifest) {
|
|
40
|
-
return await Promise.all(manifest.images.map(async (_, index) => {
|
|
41
|
-
const { start, end } = (0, core_1.calculateBlockRange)(blockCounts, index);
|
|
42
|
-
const imageBlocks = blocks.slice(start, end);
|
|
43
|
-
return await this._createImage(imageBlocks, manifest.config.blockSize);
|
|
44
|
-
}));
|
|
45
|
-
}
|
|
46
|
-
_createManifest(manifestId, imageInfos) {
|
|
47
|
-
return {
|
|
48
|
-
id: manifestId,
|
|
49
|
-
version: constants_1.VERSION,
|
|
50
|
-
timestamp: new Date().toISOString(),
|
|
51
|
-
config: this.config,
|
|
52
|
-
images: imageInfos,
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
async _prepareData(paths) {
|
|
56
|
-
const manifestId = (0, utils_1.generateManifestId)();
|
|
57
|
-
const { imageInfos, blocks } = await this._processImages(paths);
|
|
58
|
-
(0, core_1.validateFileNames)(imageInfos, this.config.preserveName);
|
|
59
|
-
const manifest = this._createManifest(manifestId, imageInfos);
|
|
60
|
-
const blockCountsForCrossImages = (0, core_1.calculateBlockCountsForCrossImages)(blocks.length, paths.length);
|
|
61
|
-
// Calculate actual block counts per image for per-image shuffle
|
|
62
|
-
const blockCountsPerImage = (0, core_1.calculateBlockCountsPerImage)(imageInfos);
|
|
63
|
-
return { manifest, blocks, blockCountsForCrossImages, blockCountsPerImage };
|
|
64
|
-
}
|
|
65
|
-
async _processImages(paths) {
|
|
66
|
-
const results = await Promise.all(paths.map((path) => this._processImage(path)));
|
|
67
|
-
const imageInfos = results.map((r) => r.imageInfo);
|
|
68
|
-
const blocks = results.flatMap((r) => r.blocks);
|
|
69
|
-
return { imageInfos, blocks };
|
|
70
|
-
}
|
|
71
|
-
async _processImage(path) {
|
|
72
|
-
const buffer = await (0, file_1.readFileBuffer)(path);
|
|
73
|
-
const { blocks, width, height, blockCountX, blockCountY } = await (0, block_1.imageFileToBlocks)(buffer, this.config.blockSize);
|
|
74
|
-
const imageInfo = {
|
|
75
|
-
w: width,
|
|
76
|
-
h: height,
|
|
77
|
-
c: 4, // Always use 4 channels (RGBA) for generated PNG
|
|
78
|
-
x: blockCountX,
|
|
79
|
-
y: blockCountY,
|
|
80
|
-
name: this.config.preserveName
|
|
81
|
-
? (0, core_1.encodeFileName)((0, file_1.fileNameWithoutExtension)(path))
|
|
82
|
-
: undefined,
|
|
83
|
-
};
|
|
84
|
-
return { imageInfo, blocks };
|
|
85
|
-
}
|
|
86
|
-
async _createImage(blocks, blockSize) {
|
|
87
|
-
const blockCount = blocks.length;
|
|
88
|
-
const blocksPerRow = Math.ceil(Math.sqrt(blockCount));
|
|
89
|
-
const imageWidth = blocksPerRow * blockSize;
|
|
90
|
-
const imageHeight = Math.ceil(blockCount / blocksPerRow) * blockSize;
|
|
91
|
-
return await (0, block_1.blocksToPngImage)(blocks, imageWidth, imageHeight, blockSize);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
exports.ImageFragmenter = ImageFragmenter;
|
|
95
|
-
//# sourceMappingURL=fragmenter.js.map
|
package/dist/fragmenter.d.cts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { type FragmentationConfig, type FragmentationResult } from "@pixzle/core";
|
|
2
|
-
export declare class ImageFragmenter {
|
|
3
|
-
private config;
|
|
4
|
-
constructor(config: FragmentationConfig);
|
|
5
|
-
private _initializeConfig;
|
|
6
|
-
fragmentImages(paths: string[]): Promise<FragmentationResult>;
|
|
7
|
-
private _createImages;
|
|
8
|
-
private _createManifest;
|
|
9
|
-
private _prepareData;
|
|
10
|
-
private _processImages;
|
|
11
|
-
private _processImage;
|
|
12
|
-
private _createImage;
|
|
13
|
-
}
|
|
14
|
-
//# sourceMappingURL=fragmenter.d.ts.map
|
package/dist/fragmenter.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fragmenter.d.ts","sourceRoot":"","sources":["../src/fragmenter.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,mBAAmB,EACxB,KAAK,mBAAmB,EAQzB,MAAM,cAAc,CAAC;AAOtB,qBAAa,eAAe;IAC1B,OAAO,CAAC,MAAM,CAAgC;gBAElC,MAAM,EAAE,mBAAmB;IAIvC,OAAO,CAAC,iBAAiB;IAenB,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,mBAAmB,CAAC;YA6BrD,aAAa;IAc3B,OAAO,CAAC,eAAe;YAaT,YAAY;YAyBZ,cAAc;YAcd,aAAa;YAuBb,YAAY;CAW3B"}
|
package/dist/index.cjs
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ImageRestorer = exports.ImageFragmenter = void 0;
|
|
4
|
-
const core_1 = require("@pixzle/core");
|
|
5
|
-
const file_1 = require("./file");
|
|
6
|
-
const fragmenter_1 = require("./fragmenter");
|
|
7
|
-
Object.defineProperty(exports, "ImageFragmenter", { enumerable: true, get: function () { return fragmenter_1.ImageFragmenter; } });
|
|
8
|
-
const restorer_1 = require("./restorer");
|
|
9
|
-
Object.defineProperty(exports, "ImageRestorer", { enumerable: true, get: function () { return restorer_1.ImageRestorer; } });
|
|
10
|
-
async function shuffle(options) {
|
|
11
|
-
const { imagePaths, config, outputDir } = validateShuffleOptions(options);
|
|
12
|
-
const fragmenter = new fragmenter_1.ImageFragmenter(config ?? {});
|
|
13
|
-
const { manifest, fragmentedImages } = await fragmenter.fragmentImages(imagePaths);
|
|
14
|
-
await (0, file_1.createDir)(outputDir, true);
|
|
15
|
-
await (0, file_1.writeFile)(outputDir, core_1.MANIFEST_FILE_NAME, JSON.stringify(manifest, null, 2));
|
|
16
|
-
await Promise.all(fragmentedImages.map((img, i) => {
|
|
17
|
-
const filename = (0, core_1.generateFragmentFileName)(manifest, i);
|
|
18
|
-
return (0, file_1.writeFile)(outputDir, filename, img);
|
|
19
|
-
}));
|
|
20
|
-
}
|
|
21
|
-
async function restore(options) {
|
|
22
|
-
const { imagePaths, manifestPath, outputDir } = validateRestoreOptions(options);
|
|
23
|
-
const manifest = await (0, file_1.readJsonFile)(manifestPath);
|
|
24
|
-
(0, core_1.validateFragmentImageCount)(imagePaths, manifest);
|
|
25
|
-
const restorer = new restorer_1.ImageRestorer();
|
|
26
|
-
const restoredImages = await restorer.restoreImages(imagePaths, manifest);
|
|
27
|
-
await (0, file_1.createDir)(outputDir, true);
|
|
28
|
-
const imageInfos = manifest.images;
|
|
29
|
-
await Promise.all(restoredImages.map((img, i) => {
|
|
30
|
-
const filename = (0, core_1.generateRestoredOriginalFileName)(imageInfos[i]) ??
|
|
31
|
-
(0, core_1.generateRestoredFileName)(manifest, i);
|
|
32
|
-
return (0, file_1.writeFile)(outputDir, filename, img);
|
|
33
|
-
}));
|
|
34
|
-
}
|
|
35
|
-
const pixzle = {
|
|
36
|
-
shuffle,
|
|
37
|
-
restore,
|
|
38
|
-
};
|
|
39
|
-
exports.default = pixzle;
|
|
40
|
-
function validateCommonOptions(options, context) {
|
|
41
|
-
if (!options)
|
|
42
|
-
throw new Error(`[${context}] Options object is required.`);
|
|
43
|
-
const { imagePaths, outputDir } = options;
|
|
44
|
-
if (!imagePaths || !Array.isArray(imagePaths) || imagePaths.length === 0)
|
|
45
|
-
throw new Error(`[${context}] imagePaths must be a non-empty array.`);
|
|
46
|
-
if (!outputDir || typeof outputDir !== "string")
|
|
47
|
-
throw new Error(`[${context}] outputDir is required and must be a string.`);
|
|
48
|
-
return options;
|
|
49
|
-
}
|
|
50
|
-
function validateShuffleOptions(options) {
|
|
51
|
-
return validateCommonOptions(options, "shuffle");
|
|
52
|
-
}
|
|
53
|
-
function validateRestoreOptions(options) {
|
|
54
|
-
const { manifestPath } = options;
|
|
55
|
-
if (!manifestPath || typeof manifestPath !== "string")
|
|
56
|
-
throw new Error("[restore] manifestPath is required and must be a string.");
|
|
57
|
-
return validateCommonOptions(options, "restore");
|
|
58
|
-
}
|
|
59
|
-
//# sourceMappingURL=index.js.map
|
package/dist/index.d.cts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { type FragmentationConfig, type ManifestData, type RestoreOptions, type ShuffleOptions } from "@pixzle/core";
|
|
2
|
-
import { ImageFragmenter } from "./fragmenter";
|
|
3
|
-
import { ImageRestorer } from "./restorer";
|
|
4
|
-
export { ImageFragmenter, ImageRestorer, type FragmentationConfig, type ManifestData, };
|
|
5
|
-
declare function shuffle(options: ShuffleOptions): Promise<void>;
|
|
6
|
-
declare function restore(options: RestoreOptions): Promise<void>;
|
|
7
|
-
declare const pixzle: {
|
|
8
|
-
shuffle: typeof shuffle;
|
|
9
|
-
restore: typeof restore;
|
|
10
|
-
};
|
|
11
|
-
export default pixzle;
|
|
12
|
-
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,mBAAmB,EAExB,KAAK,YAAY,EACjB,KAAK,cAAc,EACnB,KAAK,cAAc,EAKpB,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAE3C,OAAO,EACL,eAAe,EACf,aAAa,EACb,KAAK,mBAAmB,EACxB,KAAK,YAAY,GAClB,CAAC;AAEF,iBAAe,OAAO,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAoB7D;AAED,iBAAe,OAAO,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAsB7D;AAED,QAAA,MAAM,MAAM;;;CAGX,CAAC;AAEF,eAAe,MAAM,CAAC"}
|