@ikijs/mcp 0.13.0 → 0.13.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/README.md +1 -1
- package/dist/{chunk-4EW6OSEC.mjs → chunk-KPYHC6X2.mjs} +71 -3
- package/dist/chunk-KPYHC6X2.mjs.map +1 -0
- package/dist/cli.js +70 -2
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +1 -1
- package/dist/index.js +70 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
- package/dist/chunk-4EW6OSEC.mjs.map +0 -1
package/dist/cli.mjs
CHANGED
package/dist/index.js
CHANGED
|
@@ -1235,6 +1235,8 @@ var IRIS_W = Math.round(EYE_W * 0.5625);
|
|
|
1235
1235
|
var EYEWHITE_SRC = "eyewhite.png";
|
|
1236
1236
|
var EYE_LASH_LUMA = 120;
|
|
1237
1237
|
var LASH_KEEP_FRACTION = 0.5;
|
|
1238
|
+
var TRIM_THRESHOLD = 12;
|
|
1239
|
+
var STRAY_SPECK_FRACTION = 0.01;
|
|
1238
1240
|
var NOSE_TIP_AT = 0.86;
|
|
1239
1241
|
var DEFAULT_LAYOUT = {
|
|
1240
1242
|
// Back hair and body sit behind the face. Both are OPTIONAL: a parts dir
|
|
@@ -1423,7 +1425,15 @@ async function partBuffer(role, cfg, partsDir, inMemory, flipSource) {
|
|
|
1423
1425
|
raw: { width: png.width, height: png.height, channels: 4 }
|
|
1424
1426
|
});
|
|
1425
1427
|
}
|
|
1426
|
-
if (!cfg.noTrim)
|
|
1428
|
+
if (!cfg.noTrim) {
|
|
1429
|
+
const kept = await img.trim({ threshold: TRIM_THRESHOLD }).ensureAlpha().raw().toBuffer({ resolveWithObject: true });
|
|
1430
|
+
const { width: keptW, height: keptH } = kept.info;
|
|
1431
|
+
img = (0, import_sharp2.default)(kept.data, {
|
|
1432
|
+
raw: { width: keptW, height: keptH, channels: 4 }
|
|
1433
|
+
});
|
|
1434
|
+
const box = boxWithoutStraySpecks(kept.data, keptW, keptH);
|
|
1435
|
+
if (box !== null) img = img.extract(box);
|
|
1436
|
+
}
|
|
1427
1437
|
if ((cfg.mirror ?? false) !== flipSource) img = img.flop();
|
|
1428
1438
|
const trimmed = await img.png().toBuffer({ resolveWithObject: true });
|
|
1429
1439
|
const { width: trimmedW, height: trimmedH } = trimmed.info;
|
|
@@ -1493,6 +1503,64 @@ function blankCanvas() {
|
|
|
1493
1503
|
function luma(rgba, i) {
|
|
1494
1504
|
return 0.299 * rgba[i] + 0.587 * rgba[i + 1] + 0.114 * rgba[i + 2];
|
|
1495
1505
|
}
|
|
1506
|
+
function boxWithoutStraySpecks(rgba, W, H) {
|
|
1507
|
+
const n = W * H;
|
|
1508
|
+
let kept = 0;
|
|
1509
|
+
for (let p = 0; p < n; p++) if (rgba[p * 4 + 3] > TRIM_THRESHOLD) kept++;
|
|
1510
|
+
const visited = new Uint8Array(n);
|
|
1511
|
+
let stack = new Int32Array(1024);
|
|
1512
|
+
const drawing = [W, H, -1, -1];
|
|
1513
|
+
const strays = [W, H, -1, -1];
|
|
1514
|
+
let anyOpaque = false;
|
|
1515
|
+
for (let start = 0; start < n; start++) {
|
|
1516
|
+
if (visited[start] || rgba[start * 4 + 3] <= TRIM_THRESHOLD) continue;
|
|
1517
|
+
let setLeft = W;
|
|
1518
|
+
let setTop = H;
|
|
1519
|
+
let setRight = -1;
|
|
1520
|
+
let setBottom = -1;
|
|
1521
|
+
let size = 0;
|
|
1522
|
+
let opaque = false;
|
|
1523
|
+
let depth = 0;
|
|
1524
|
+
visited[start] = 1;
|
|
1525
|
+
stack[depth++] = start;
|
|
1526
|
+
while (depth > 0) {
|
|
1527
|
+
const p = stack[--depth];
|
|
1528
|
+
size++;
|
|
1529
|
+
if (rgba[p * 4 + 3] >= import_editor5.ALPHA_OPAQUE) opaque = true;
|
|
1530
|
+
const px = p % W;
|
|
1531
|
+
const py = (p - px) / W;
|
|
1532
|
+
setLeft = Math.min(setLeft, px);
|
|
1533
|
+
setTop = Math.min(setTop, py);
|
|
1534
|
+
setRight = Math.max(setRight, px);
|
|
1535
|
+
setBottom = Math.max(setBottom, py);
|
|
1536
|
+
for (let y = Math.max(0, py - 1); y <= Math.min(H - 1, py + 1); y++) {
|
|
1537
|
+
for (let x = Math.max(0, px - 1); x <= Math.min(W - 1, px + 1); x++) {
|
|
1538
|
+
const q = y * W + x;
|
|
1539
|
+
if (!visited[q] && rgba[q * 4 + 3] > TRIM_THRESHOLD) {
|
|
1540
|
+
visited[q] = 1;
|
|
1541
|
+
if (depth === stack.length) {
|
|
1542
|
+
const grown = new Int32Array(Math.min(n, stack.length * 2));
|
|
1543
|
+
grown.set(stack);
|
|
1544
|
+
stack = grown;
|
|
1545
|
+
}
|
|
1546
|
+
stack[depth++] = q;
|
|
1547
|
+
}
|
|
1548
|
+
}
|
|
1549
|
+
}
|
|
1550
|
+
}
|
|
1551
|
+
anyOpaque ||= opaque;
|
|
1552
|
+
const into = !opaque && size < kept * STRAY_SPECK_FRACTION ? strays : drawing;
|
|
1553
|
+
into[0] = Math.min(into[0], setLeft);
|
|
1554
|
+
into[1] = Math.min(into[1], setTop);
|
|
1555
|
+
into[2] = Math.max(into[2], setRight);
|
|
1556
|
+
into[3] = Math.max(into[3], setBottom);
|
|
1557
|
+
}
|
|
1558
|
+
if (!anyOpaque || strays[2] < 0) return null;
|
|
1559
|
+
const [left, top, right, bottom] = drawing;
|
|
1560
|
+
if (strays[0] >= left && strays[1] >= top && strays[2] <= right && strays[3] <= bottom)
|
|
1561
|
+
return null;
|
|
1562
|
+
return { left, top, width: right - left + 1, height: bottom - top + 1 };
|
|
1563
|
+
}
|
|
1496
1564
|
function detachedAboveWhite(rgba, W, H) {
|
|
1497
1565
|
const n = W * H;
|
|
1498
1566
|
const ink = new Uint8Array(n);
|
|
@@ -1728,7 +1796,7 @@ async function composeLayersFromParts(input) {
|
|
|
1728
1796
|
var import_mcp = require("@modelcontextprotocol/sdk/server/mcp.js");
|
|
1729
1797
|
var import_zod = require("zod");
|
|
1730
1798
|
function createIkiMcpServer() {
|
|
1731
|
-
const server = new import_mcp.McpServer({ name: "iki", version: "0.13.
|
|
1799
|
+
const server = new import_mcp.McpServer({ name: "iki", version: "0.13.1" });
|
|
1732
1800
|
server.registerTool(
|
|
1733
1801
|
"validate_iki",
|
|
1734
1802
|
{
|