@pixzle/core 0.0.19 → 0.0.21
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 +55 -0
- package/dist/block-operations.d.ts.map +1 -0
- package/dist/block-operations.js +147 -0
- package/dist/block-operations.js.map +1 -0
- package/dist/block-utils.cjs +86 -0
- package/dist/block-utils.d.cts +47 -0
- package/dist/block-utils.d.ts +48 -0
- package/dist/block-utils.d.ts.map +1 -0
- package/dist/block-utils.js +94 -0
- package/dist/block-utils.js.map +1 -0
- package/dist/constants.cjs +11 -0
- package/dist/constants.d.cts +8 -0
- package/dist/constants.d.ts +7 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +11 -0
- package/dist/constants.js.map +1 -0
- package/dist/helpers.cjs +101 -0
- package/dist/helpers.d.cts +45 -0
- package/dist/helpers.d.ts +44 -0
- package/dist/helpers.d.ts.map +1 -0
- package/dist/helpers.js +101 -0
- package/dist/helpers.js.map +1 -0
- package/dist/index.cjs +27 -0
- package/dist/index.d.cts +8 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +27 -0
- package/dist/index.js.map +1 -0
- package/dist/types.cjs +3 -0
- package/dist/types.d.cts +65 -0
- package/dist/types.d.ts +63 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/dist/validators.cjs +48 -0
- package/dist/validators.d.cts +16 -0
- package/dist/validators.d.ts +15 -0
- package/dist/validators.d.ts.map +1 -0
- package/dist/validators.js +48 -0
- package/dist/validators.js.map +1 -0
- package/package.json +6 -21
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
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
|
+
/** Manifest data object (alternative to manifestPath) */
|
|
15
|
+
manifestData?: ManifestData;
|
|
16
|
+
/** Output directory (e.g., "./output/restored") */
|
|
17
|
+
outputDir: string;
|
|
18
|
+
}
|
|
19
|
+
export interface FragmentationConfig {
|
|
20
|
+
/**
|
|
21
|
+
* Pixel block size (e.g., 10x10 to 10)
|
|
22
|
+
* Smaller -> High Obfuscation / Larger -> High Performance
|
|
23
|
+
*/
|
|
24
|
+
blockSize?: number;
|
|
25
|
+
/** Prefix for fragment files (optional, default: "img") */
|
|
26
|
+
prefix?: string;
|
|
27
|
+
/** Random seed (auto-generated if not specified) */
|
|
28
|
+
seed?: number | string;
|
|
29
|
+
/** Preserve original file name (optional, default: false) */
|
|
30
|
+
preserveName?: boolean;
|
|
31
|
+
/** Shuffle blocks across all images instead of within each image independently (optional, default: false) */
|
|
32
|
+
crossImageShuffle?: boolean;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Information about the image before fragmentation.
|
|
36
|
+
* This includes dimensions, channels, and block counts.
|
|
37
|
+
*/
|
|
38
|
+
export interface ImageInfo {
|
|
39
|
+
/** Width */
|
|
40
|
+
w: number;
|
|
41
|
+
/** Height */
|
|
42
|
+
h: number;
|
|
43
|
+
/** Original file name in base64 encoding (optional) */
|
|
44
|
+
name?: string;
|
|
45
|
+
}
|
|
46
|
+
export interface ManifestData {
|
|
47
|
+
/** UUID */
|
|
48
|
+
id: string;
|
|
49
|
+
/** Version */
|
|
50
|
+
version: string;
|
|
51
|
+
/** Timestamp */
|
|
52
|
+
timestamp: string;
|
|
53
|
+
/** Config */
|
|
54
|
+
config: Required<FragmentationConfig>;
|
|
55
|
+
/** Image information */
|
|
56
|
+
images: ImageInfo[];
|
|
57
|
+
}
|
|
58
|
+
export interface FragmentationResult {
|
|
59
|
+
/** Manifest data */
|
|
60
|
+
manifest: ManifestData;
|
|
61
|
+
/** Fragmented images */
|
|
62
|
+
fragmentedImages: Buffer[];
|
|
63
|
+
}
|
|
@@ -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"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateFragmentImageCount = validateFragmentImageCount;
|
|
4
|
+
exports.validateFileNames = validateFileNames;
|
|
5
|
+
const helpers_1 = require("./helpers");
|
|
6
|
+
/**
|
|
7
|
+
* Validates that the number of fragment images matches the number of images in the manifest
|
|
8
|
+
* @param fragmentImages - Array of fragment images (file paths or buffers)
|
|
9
|
+
* @param manifest - The manifest data containing image information
|
|
10
|
+
* @throws {Error} When the counts don't match
|
|
11
|
+
*/
|
|
12
|
+
function validateFragmentImageCount(fragmentImages, manifest) {
|
|
13
|
+
const manifestImageCount = manifest.images.length;
|
|
14
|
+
const fragmentImageCount = fragmentImages.length;
|
|
15
|
+
if (manifestImageCount !== fragmentImageCount) {
|
|
16
|
+
throw new Error(`Fragment image count mismatch: expected ${manifestImageCount} but got ${fragmentImageCount}`);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Validates that there are no duplicate file names in the image infos
|
|
21
|
+
* @param imageInfos - Array of image information objects
|
|
22
|
+
* @param preserveName - Whether name preservation is enabled
|
|
23
|
+
* @throws {Error} When duplicate file names are detected
|
|
24
|
+
*/
|
|
25
|
+
function validateFileNames(imageInfos, preserveName) {
|
|
26
|
+
if (!preserveName || imageInfos.length <= 1) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
const nameSet = new Set();
|
|
30
|
+
for (const info of imageInfos) {
|
|
31
|
+
if (info.name !== undefined) {
|
|
32
|
+
// Decode base64 to get original name for comparison
|
|
33
|
+
let decodedName;
|
|
34
|
+
try {
|
|
35
|
+
decodedName = (0, helpers_1.decodeFileName)(info.name);
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
// If decoding fails, treat as already decoded (backward compatibility)
|
|
39
|
+
decodedName = info.name;
|
|
40
|
+
}
|
|
41
|
+
if (nameSet.has(decodedName)) {
|
|
42
|
+
throw new Error(`Duplicate file name detected: ${decodedName}`);
|
|
43
|
+
}
|
|
44
|
+
nameSet.add(decodedName);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=validators.js.map
|
|
@@ -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,15 @@
|
|
|
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;
|
|
@@ -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"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateFragmentImageCount = validateFragmentImageCount;
|
|
4
|
+
exports.validateFileNames = validateFileNames;
|
|
5
|
+
const helpers_1 = require("./helpers");
|
|
6
|
+
/**
|
|
7
|
+
* Validates that the number of fragment images matches the number of images in the manifest
|
|
8
|
+
* @param fragmentImages - Array of fragment images (file paths or buffers)
|
|
9
|
+
* @param manifest - The manifest data containing image information
|
|
10
|
+
* @throws {Error} When the counts don't match
|
|
11
|
+
*/
|
|
12
|
+
function validateFragmentImageCount(fragmentImages, manifest) {
|
|
13
|
+
const manifestImageCount = manifest.images.length;
|
|
14
|
+
const fragmentImageCount = fragmentImages.length;
|
|
15
|
+
if (manifestImageCount !== fragmentImageCount) {
|
|
16
|
+
throw new Error(`Fragment image count mismatch: expected ${manifestImageCount} but got ${fragmentImageCount}`);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Validates that there are no duplicate file names in the image infos
|
|
21
|
+
* @param imageInfos - Array of image information objects
|
|
22
|
+
* @param preserveName - Whether name preservation is enabled
|
|
23
|
+
* @throws {Error} When duplicate file names are detected
|
|
24
|
+
*/
|
|
25
|
+
function validateFileNames(imageInfos, preserveName) {
|
|
26
|
+
if (!preserveName || imageInfos.length <= 1) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
const nameSet = new Set();
|
|
30
|
+
for (const info of imageInfos) {
|
|
31
|
+
if (info.name !== undefined) {
|
|
32
|
+
// Decode base64 to get original name for comparison
|
|
33
|
+
let decodedName;
|
|
34
|
+
try {
|
|
35
|
+
decodedName = (0, helpers_1.decodeFileName)(info.name);
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
// If decoding fails, treat as already decoded (backward compatibility)
|
|
39
|
+
decodedName = info.name;
|
|
40
|
+
}
|
|
41
|
+
if (nameSet.has(decodedName)) {
|
|
42
|
+
throw new Error(`Duplicate file name detected: ${decodedName}`);
|
|
43
|
+
}
|
|
44
|
+
nameSet.add(decodedName);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=validators.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validators.js","sourceRoot":"","sources":["../src/validators.ts"],"names":[],"mappings":";;AAUA,gEAYC;AAQD,8CA0BC;AAvDD,uCAA2C;AAG3C;;;;;GAKG;AACH,SAAgB,0BAA0B,CACxC,cAAmC,EACnC,QAAsB;IAEtB,MAAM,kBAAkB,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC;IAClD,MAAM,kBAAkB,GAAG,cAAc,CAAC,MAAM,CAAC;IAEjD,IAAI,kBAAkB,KAAK,kBAAkB,EAAE,CAAC;QAC9C,MAAM,IAAI,KAAK,CACb,2CAA2C,kBAAkB,YAAY,kBAAkB,EAAE,CAC9F,CAAC;IACJ,CAAC;AACH,CAAC;AAED;;;;;GAKG;AACH,SAAgB,iBAAiB,CAC/B,UAAuB,EACvB,YAAqB;IAErB,IAAI,CAAC,YAAY,IAAI,UAAU,CAAC,MAAM,IAAI,CAAC,EAAE,CAAC;QAC5C,OAAO;IACT,CAAC;IAED,MAAM,OAAO,GAAG,IAAI,GAAG,EAAU,CAAC;IAElC,KAAK,MAAM,IAAI,IAAI,UAAU,EAAE,CAAC;QAC9B,IAAI,IAAI,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;YAC5B,oDAAoD;YACpD,IAAI,WAAmB,CAAC;YACxB,IAAI,CAAC;gBACH,WAAW,GAAG,IAAA,wBAAc,EAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAC1C,CAAC;YAAC,MAAM,CAAC;gBACP,uEAAuE;gBACvE,WAAW,GAAG,IAAI,CAAC,IAAI,CAAC;YAC1B,CAAC;YACD,IAAI,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE,CAAC;gBAC7B,MAAM,IAAI,KAAK,CAAC,iCAAiC,WAAW,EAAE,CAAC,CAAC;YAClE,CAAC;YACD,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;QAC3B,CAAC;IACH,CAAC;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,23 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pixzle/core",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.21",
|
|
4
4
|
"description": "Core image fragmentation and restoration logic",
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
"module": "dist/esm/index.js",
|
|
8
|
-
"types": "dist/esm/index.d.ts",
|
|
9
|
-
"exports": {
|
|
10
|
-
".": {
|
|
11
|
-
"import": {
|
|
12
|
-
"types": "./dist/esm/index.d.ts",
|
|
13
|
-
"default": "./dist/esm/index.js"
|
|
14
|
-
},
|
|
15
|
-
"require": {
|
|
16
|
-
"types": "./dist/cjs/index.d.ts",
|
|
17
|
-
"default": "./dist/cjs/index.js"
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
},
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
21
7
|
"files": [
|
|
22
8
|
"dist"
|
|
23
9
|
],
|
|
@@ -41,10 +27,9 @@
|
|
|
41
27
|
"vitest": "^3.1.4"
|
|
42
28
|
},
|
|
43
29
|
"scripts": {
|
|
44
|
-
"build": "
|
|
45
|
-
"build:esm": "tsc -p tsconfig.build.json --outDir dist/esm --module ES2022 --moduleResolution bundler",
|
|
46
|
-
"build:cjs": "tsc -p tsconfig.build.json --outDir dist/cjs --module CommonJS --moduleResolution node && echo '{\"type\":\"commonjs\"}' > dist/cjs/package.json",
|
|
30
|
+
"build": "tsc -p tsconfig.build.json",
|
|
47
31
|
"build:check": "tsc -p tsconfig.build.json --noEmit",
|
|
48
|
-
"test": "vitest"
|
|
32
|
+
"test": "vitest run",
|
|
33
|
+
"test:watch": "vitest"
|
|
49
34
|
}
|
|
50
35
|
}
|