picross-image-processor 1.0.0 → 1.0.1
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/imageProcessor.js +10 -16
- package/dist/imageProcessor.js.map +1 -1
- package/dist/index.js +4 -25
- package/dist/index.js.map +1 -1
- package/dist/types.js +1 -2
- package/dist/utils/imageAnalysis.js +1 -4
- package/dist/utils/imageAnalysis.js.map +1 -1
- package/dist/utils/pixelAnalysis.js +5 -12
- package/dist/utils/pixelAnalysis.js.map +1 -1
- package/package.json +60 -53
package/dist/imageProcessor.js
CHANGED
|
@@ -1,15 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.processImageData = processImageData;
|
|
4
|
-
exports.processCanvasImage = processCanvasImage;
|
|
5
|
-
exports.processImageUrl = processImageUrl;
|
|
6
|
-
exports.processImageFile = processImageFile;
|
|
7
|
-
const pixelAnalysis_1 = require("./utils/pixelAnalysis");
|
|
8
|
-
const imageAnalysis_1 = require("./utils/imageAnalysis");
|
|
1
|
+
import { isOpaque, hasTransparentNeighbor, hasSignificantColorChange, } from './utils/pixelAnalysis';
|
|
2
|
+
import { calculateBoundingBox } from './utils/imageAnalysis';
|
|
9
3
|
/**
|
|
10
4
|
* Process ImageData directly
|
|
11
5
|
*/
|
|
12
|
-
function processImageData(imageData, config) {
|
|
6
|
+
export function processImageData(imageData, config) {
|
|
13
7
|
const boardSize = config?.boardSize || 16;
|
|
14
8
|
const colorThreshold = config?.colorThreshold || 80;
|
|
15
9
|
const alphaThreshold = config?.alphaThreshold || 128;
|
|
@@ -17,16 +11,16 @@ function processImageData(imageData, config) {
|
|
|
17
11
|
const width = imageData.width;
|
|
18
12
|
const height = imageData.height;
|
|
19
13
|
// Step 1: Find bounding box
|
|
20
|
-
const bbox =
|
|
14
|
+
const bbox = calculateBoundingBox(data, width, height, alphaThreshold);
|
|
21
15
|
// Step 2: Create scaled image data
|
|
22
16
|
const scaledData = scaleImageData(data, width, height, bbox, boardSize);
|
|
23
17
|
// Step 3: Convert to binary matrix
|
|
24
18
|
const board = Array.from({ length: boardSize }, () => Array(boardSize).fill(0));
|
|
25
19
|
for (let row = 0; row < boardSize; row++) {
|
|
26
20
|
for (let col = 0; col < boardSize; col++) {
|
|
27
|
-
const isOpaquePixel =
|
|
28
|
-
const hasTransparent =
|
|
29
|
-
const hasColorChange =
|
|
21
|
+
const isOpaquePixel = isOpaque(scaledData, boardSize, row, col, alphaThreshold);
|
|
22
|
+
const hasTransparent = hasTransparentNeighbor(scaledData, boardSize, row, col, alphaThreshold);
|
|
23
|
+
const hasColorChange = hasSignificantColorChange(scaledData, boardSize, row, col, colorThreshold, alphaThreshold);
|
|
30
24
|
if (isOpaquePixel && (hasTransparent || hasColorChange)) {
|
|
31
25
|
board[row][col] = 1;
|
|
32
26
|
}
|
|
@@ -69,7 +63,7 @@ function scaleImageData(sourceData, sourceWidth, sourceHeight, bbox, boardSize)
|
|
|
69
63
|
/**
|
|
70
64
|
* Process an image using Canvas API (browser compatible)
|
|
71
65
|
*/
|
|
72
|
-
async function processCanvasImage(image, config) {
|
|
66
|
+
export async function processCanvasImage(image, config) {
|
|
73
67
|
const canvas = new OffscreenCanvas(image.width, image.height);
|
|
74
68
|
const ctx = canvas.getContext('2d');
|
|
75
69
|
if (!ctx)
|
|
@@ -81,7 +75,7 @@ async function processCanvasImage(image, config) {
|
|
|
81
75
|
/**
|
|
82
76
|
* Process an image from a data URL (browser compatible)
|
|
83
77
|
*/
|
|
84
|
-
async function processImageUrl(imageUrl, config) {
|
|
78
|
+
export async function processImageUrl(imageUrl, config) {
|
|
85
79
|
return new Promise((resolve, reject) => {
|
|
86
80
|
const img = new Image();
|
|
87
81
|
img.crossOrigin = 'Anonymous';
|
|
@@ -102,7 +96,7 @@ async function processImageUrl(imageUrl, config) {
|
|
|
102
96
|
* Process using canvas library (Node.js)
|
|
103
97
|
* This will use the canvas package if available
|
|
104
98
|
*/
|
|
105
|
-
async function processImageFile(filePath, config) {
|
|
99
|
+
export async function processImageFile(filePath, config) {
|
|
106
100
|
try {
|
|
107
101
|
// Try to use canvas library if available
|
|
108
102
|
const canvas = require('canvas');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"imageProcessor.js","sourceRoot":"","sources":["../src/imageProcessor.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"imageProcessor.js","sourceRoot":"","sources":["../src/imageProcessor.ts"],"names":[],"mappings":"AACA,OAAO,EACL,QAAQ,EACR,sBAAsB,EACtB,yBAAyB,GAC1B,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAE7D;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAC9B,SAAoB,EACpB,MAAyB;IAEzB,MAAM,SAAS,GAAG,MAAM,EAAE,SAAS,IAAI,EAAE,CAAC;IAC1C,MAAM,cAAc,GAAG,MAAM,EAAE,cAAc,IAAI,EAAE,CAAC;IACpD,MAAM,cAAc,GAAG,MAAM,EAAE,cAAc,IAAI,GAAG,CAAC;IAErD,MAAM,IAAI,GAAG,SAAS,CAAC,IAAI,CAAC;IAC5B,MAAM,KAAK,GAAG,SAAS,CAAC,KAAK,CAAC;IAC9B,MAAM,MAAM,GAAG,SAAS,CAAC,MAAM,CAAC;IAEhC,4BAA4B;IAC5B,MAAM,IAAI,GAAG,oBAAoB,CAAC,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,cAAc,CAAC,CAAC;IAEvE,mCAAmC;IACnC,MAAM,UAAU,GAAG,cAAc,CAAC,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,CAAC,CAAC;IAExE,mCAAmC;IACnC,MAAM,KAAK,GAAe,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,SAAS,EAAE,EAAE,GAAG,EAAE,CAC/D,KAAK,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CACzB,CA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GG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,QAAgB,EAChB,MAAyB;IAEzB,IAAI,CAAC;QACH,yCAAyC;QACzC,MAAM,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;QACjC,MAAM,KAAK,GAAG,MAAM,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;QAE/C,MAAM,aAAa,GAAG,MAAM,CAAC,YAAY,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;QACrE,MAAM,GAAG,GAAG,aAAa,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;QAC3C,GAAG,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;QAE3B,MAAM,SAAS,GAAG,GAAG,CAAC,YAAY,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,CAAC,KAAK,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;QACpE,OAAO,gBAAgB,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;IAC7C,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CACb,8FAA8F,CAC/F,CAAC;IACJ,CAAC;AACH,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,27 +1,6 @@
|
|
|
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.processImageFile = exports.processImageUrl = exports.processCanvasImage = exports.processImageData = void 0;
|
|
18
1
|
// Main entry point
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
Object.defineProperty(exports, "processImageUrl", { enumerable: true, get: function () { return imageProcessor_1.processImageUrl; } });
|
|
24
|
-
Object.defineProperty(exports, "processImageFile", { enumerable: true, get: function () { return imageProcessor_1.processImageFile; } });
|
|
25
|
-
__exportStar(require("./utils/pixelAnalysis"), exports);
|
|
26
|
-
__exportStar(require("./utils/imageAnalysis"), exports);
|
|
2
|
+
export * from './types';
|
|
3
|
+
export { processImageData, processCanvasImage, processImageUrl, processImageFile, } from './imageProcessor';
|
|
4
|
+
export * from './utils/pixelAnalysis';
|
|
5
|
+
export * from './utils/imageAnalysis';
|
|
27
6
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,mBAAmB;AACnB,cAAc,SAAS,CAAC;AACxB,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAClB,eAAe,EACf,gBAAgB,GACjB,MAAM,kBAAkB,CAAC;AAC1B,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC"}
|
package/dist/types.js
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.calculateBoundingBox = calculateBoundingBox;
|
|
4
1
|
/**
|
|
5
2
|
* Calculate bounding box of opaque pixels in image data
|
|
6
3
|
*/
|
|
7
|
-
function calculateBoundingBox(data, width, height, alphaThreshold = 128) {
|
|
4
|
+
export function calculateBoundingBox(data, width, height, alphaThreshold = 128) {
|
|
8
5
|
let minX = width;
|
|
9
6
|
let minY = height;
|
|
10
7
|
let maxX = 0;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"imageAnalysis.js","sourceRoot":"","sources":["../../src/utils/imageAnalysis.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"imageAnalysis.js","sourceRoot":"","sources":["../../src/utils/imageAnalysis.ts"],"names":[],"mappings":"AAYA;;GAEG;AACH,MAAM,UAAU,oBAAoB,CAClC,IAAoC,EACpC,KAAa,EACb,MAAc,EACd,iBAAyB,GAAG;IAE5B,IAAI,IAAI,GAAG,KAAK,CAAC;IACjB,IAAI,IAAI,GAAG,MAAM,CAAC;IAClB,IAAI,IAAI,GAAG,CAAC,CAAC;IACb,IAAI,IAAI,GAAG,CAAC,CAAC;IAEb,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QAChC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,EAAE,CAAC,EAAE,EAAE,CAAC;YAC/B,MAAM,KAAK,GAAG,CAAC,CAAC,GAAG,KAAK,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;YAClC,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC;YAE9B,IAAI,KAAK,GAAG,cAAc,EAAE,CAAC;gBAC3B,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;gBACzB,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;gBACzB,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;gBACzB,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;YAC3B,CAAC;QACH,CAAC;IACH,CAAC;IAED,MAAM,SAAS,GAAG,IAAI,GAAG,IAAI,GAAG,CAAC,CAAC;IAClC,MAAM,UAAU,GAAG,IAAI,GAAG,IAAI,GAAG,CAAC,CAAC;IAEnC,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,CAAC;AAC1E,CAAC"}
|
|
@@ -1,14 +1,7 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getPixelData = getPixelData;
|
|
4
|
-
exports.isOpaque = isOpaque;
|
|
5
|
-
exports.colorDifference = colorDifference;
|
|
6
|
-
exports.hasTransparentNeighbor = hasTransparentNeighbor;
|
|
7
|
-
exports.hasSignificantColorChange = hasSignificantColorChange;
|
|
8
1
|
/**
|
|
9
2
|
* Get pixel data from ImageData at a specific row and column
|
|
10
3
|
*/
|
|
11
|
-
function getPixelData(data, boardSize, row, col) {
|
|
4
|
+
export function getPixelData(data, boardSize, row, col) {
|
|
12
5
|
if (row < 0 || row >= boardSize || col < 0 || col >= boardSize) {
|
|
13
6
|
return { r: 0, g: 0, b: 0, a: 0 };
|
|
14
7
|
}
|
|
@@ -23,14 +16,14 @@ function getPixelData(data, boardSize, row, col) {
|
|
|
23
16
|
/**
|
|
24
17
|
* Check if a pixel is opaque based on alpha threshold
|
|
25
18
|
*/
|
|
26
|
-
function isOpaque(data, boardSize, row, col, alphaThreshold = 128) {
|
|
19
|
+
export function isOpaque(data, boardSize, row, col, alphaThreshold = 128) {
|
|
27
20
|
const pixel = getPixelData(data, boardSize, row, col);
|
|
28
21
|
return pixel.a > alphaThreshold;
|
|
29
22
|
}
|
|
30
23
|
/**
|
|
31
24
|
* Calculate color difference between two pixels using Euclidean distance
|
|
32
25
|
*/
|
|
33
|
-
function colorDifference(pixel1, pixel2) {
|
|
26
|
+
export function colorDifference(pixel1, pixel2) {
|
|
34
27
|
// If either pixel is transparent, return 0
|
|
35
28
|
if (pixel1.a <= 128 || pixel2.a <= 128) {
|
|
36
29
|
return 0;
|
|
@@ -43,7 +36,7 @@ function colorDifference(pixel1, pixel2) {
|
|
|
43
36
|
/**
|
|
44
37
|
* Check if pixel has at least one transparent neighbor
|
|
45
38
|
*/
|
|
46
|
-
function hasTransparentNeighbor(data, boardSize, row, col, alphaThreshold = 128) {
|
|
39
|
+
export function hasTransparentNeighbor(data, boardSize, row, col, alphaThreshold = 128) {
|
|
47
40
|
const neighbors = [
|
|
48
41
|
[row - 1, col],
|
|
49
42
|
[row + 1, col],
|
|
@@ -64,7 +57,7 @@ function hasTransparentNeighbor(data, boardSize, row, col, alphaThreshold = 128)
|
|
|
64
57
|
/**
|
|
65
58
|
* Check if pixel has significant color change with neighbors
|
|
66
59
|
*/
|
|
67
|
-
function hasSignificantColorChange(data, boardSize, row, col, colorThreshold = 80, alphaThreshold = 128) {
|
|
60
|
+
export function hasSignificantColorChange(data, boardSize, row, col, colorThreshold = 80, alphaThreshold = 128) {
|
|
68
61
|
if (!isOpaque(data, boardSize, row, col, alphaThreshold)) {
|
|
69
62
|
return false;
|
|
70
63
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pixelAnalysis.js","sourceRoot":"","sources":["../../src/utils/pixelAnalysis.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"pixelAnalysis.js","sourceRoot":"","sources":["../../src/utils/pixelAnalysis.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,UAAU,YAAY,CAC1B,IAAuB,EACvB,SAAiB,EACjB,GAAW,EACX,GAAW;IAEX,IAAI,GAAG,GAAG,CAAC,IAAI,GAAG,IAAI,SAAS,IAAI,GAAG,GAAG,CAA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E,GAAG,CAAC;QACd,CAAC,GAAG,GAAG,CAAC,EAAE,GAAG,CAAC;QACd,CAAC,GAAG,EAAE,GAAG,GAAG,CAAC,CAAC;QACd,CAAC,GAAG,EAAE,GAAG,GAAG,CAAC,CAAC;KACf,CAAC;IAEF,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,SAAS,EAAE,CAAC;QAC/B,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,SAAS,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,SAAS,EAAE,CAAC;YACvD,MAAM,aAAa,GAAG,YAAY,CAAC,IAAI,EAAE,SAAS,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;YAC1D,IAAI,aAAa,CAAC,CAAC,GAAG,cAAc,EAAE,CAAC;gBACrC,MAAM,IAAI,GAAG,eAAe,CAAC,YAAY,EAAE,aAAa,CAAC,CAAC;gBAC1D,IAAI,IAAI,GAAG,cAAc,EAAE,CAAC;oBAC1B,OAAO,IAAI,CAAC;gBACd,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,54 +1,61 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "picross-image-processor",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "A library to convert images to picross board representations by detecting contours and color changes",
|
|
5
|
-
"main": "dist/index.js",
|
|
6
|
-
"
|
|
7
|
-
"
|
|
8
|
-
|
|
9
|
-
"
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
"
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
|
|
25
|
-
"
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
"
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
"
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "picross-image-processor",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "A library to convert images to picross board representations by detecting contours and color changes",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"module": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"require": "./dist/index.js",
|
|
12
|
+
"types": "./dist/index.d.ts"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"README.md",
|
|
18
|
+
"LICENSE"
|
|
19
|
+
],
|
|
20
|
+
"scripts": {
|
|
21
|
+
"build": "tsc",
|
|
22
|
+
"test": "jest",
|
|
23
|
+
"prepublishOnly": "npm run build"
|
|
24
|
+
},
|
|
25
|
+
"keywords": [
|
|
26
|
+
"picross",
|
|
27
|
+
"nonogram",
|
|
28
|
+
"image-processing",
|
|
29
|
+
"canvas",
|
|
30
|
+
"puzzle",
|
|
31
|
+
"image-to-puzzle"
|
|
32
|
+
],
|
|
33
|
+
"author": "",
|
|
34
|
+
"license": "MIT",
|
|
35
|
+
"repository": {
|
|
36
|
+
"type": "git",
|
|
37
|
+
"url": "git+https://github.com/yourusername/picross-image-processor.git"
|
|
38
|
+
},
|
|
39
|
+
"bugs": {
|
|
40
|
+
"url": "https://github.com/yourusername/picross-image-processor/issues"
|
|
41
|
+
},
|
|
42
|
+
"homepage": "https://github.com/yourusername/picross-image-processor#readme",
|
|
43
|
+
"engines": {
|
|
44
|
+
"node": ">=16.0.0"
|
|
45
|
+
},
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"@types/jest": "^29.5.0",
|
|
48
|
+
"@types/node": "^20.0.0",
|
|
49
|
+
"jest": "^29.5.0",
|
|
50
|
+
"ts-jest": "^29.1.0",
|
|
51
|
+
"typescript": "^5.0.0"
|
|
52
|
+
},
|
|
53
|
+
"peerDependencies": {
|
|
54
|
+
"canvas": "^2.11.2"
|
|
55
|
+
},
|
|
56
|
+
"peerDependenciesMeta": {
|
|
57
|
+
"canvas": {
|
|
58
|
+
"optional": true
|
|
59
|
+
}
|
|
60
|
+
}
|
|
53
61
|
}
|
|
54
|
-
|