@ikijs/mcp 0.9.0 → 0.10.0
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 +4 -3
- package/dist/{chunk-R6LYJVYC.mjs → chunk-OCIICRUA.mjs} +85 -13
- package/dist/chunk-OCIICRUA.mjs.map +1 -0
- package/dist/cli.js +84 -12
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +1 -1
- package/dist/index.d.mts +7 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +84 -12
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
- package/dist/chunk-R6LYJVYC.mjs.map +0 -1
package/dist/cli.js
CHANGED
|
@@ -1062,7 +1062,8 @@ var EYE_ASPECT_MIN = 0.5;
|
|
|
1062
1062
|
var IRIS_OFFSET_MAX_X = 3;
|
|
1063
1063
|
var IRIS_OFFSET_MAX_Y = 10;
|
|
1064
1064
|
var EDGE_SOLID_MAX = 0.5;
|
|
1065
|
-
var
|
|
1065
|
+
var LASH_STRAY_TOL_FRAC = 0.02;
|
|
1066
|
+
var EYE_FACING_TOL_FRAC = 0.02;
|
|
1066
1067
|
var EDGE_RUN_MIN_PX = 40;
|
|
1067
1068
|
var FLAT_CUT_MAX_FRAC = 0.1;
|
|
1068
1069
|
var FLAT_CUT_MIN_PX = 40;
|
|
@@ -1143,6 +1144,21 @@ async function layerStats(filePath) {
|
|
|
1143
1144
|
};
|
|
1144
1145
|
}
|
|
1145
1146
|
var pct = (v) => `${(v * 100).toFixed(0)}%`;
|
|
1147
|
+
async function lashOffSclera(eyePath, lashPath) {
|
|
1148
|
+
const eye = await decodePng(eyePath);
|
|
1149
|
+
const lash = await decodePng(lashPath);
|
|
1150
|
+
let opaque = 0;
|
|
1151
|
+
let off = 0;
|
|
1152
|
+
for (let y = 0; y < lash.height; y++) {
|
|
1153
|
+
for (let x = 0; x < lash.width; x++) {
|
|
1154
|
+
if (lash.rgba[(y * lash.width + x) * 4 + 3] < 128) continue;
|
|
1155
|
+
opaque++;
|
|
1156
|
+
const onEye = x < eye.width && y < eye.height;
|
|
1157
|
+
if (!onEye || eye.rgba[(y * eye.width + x) * 4 + 3] <= 8) off++;
|
|
1158
|
+
}
|
|
1159
|
+
}
|
|
1160
|
+
return { opaque, off };
|
|
1161
|
+
}
|
|
1146
1162
|
async function measureDir(absDir) {
|
|
1147
1163
|
const files = import_node_fs2.default.readdirSync(absDir).filter((f) => f.endsWith(".png") && f !== "preview.png").sort();
|
|
1148
1164
|
if (files.length === 0) {
|
|
@@ -1224,12 +1240,28 @@ async function measureDir(absDir) {
|
|
|
1224
1240
|
}
|
|
1225
1241
|
}
|
|
1226
1242
|
if (lash) {
|
|
1227
|
-
const
|
|
1243
|
+
const { opaque, off } = await lashOffSclera(
|
|
1244
|
+
import_node_path4.default.join(absDir, `eye_${side}.png`),
|
|
1245
|
+
import_node_path4.default.join(absDir, `lash_${side}.png`)
|
|
1246
|
+
);
|
|
1228
1247
|
const dTop = lash.marginTop - eye.marginTop;
|
|
1229
|
-
|
|
1248
|
+
const faults = [
|
|
1249
|
+
...off > opaque * LASH_STRAY_TOL_FRAC ? [`${off} of its ${opaque} opaque px lie off eye_${side}'s sclera`] : [],
|
|
1250
|
+
...Math.abs(dTop) > 0.5 ? [`its top edge is ${dTop.toFixed(1)} px off the sclera's`] : []
|
|
1251
|
+
];
|
|
1252
|
+
if (faults.length > 0) {
|
|
1230
1253
|
warnings.push(
|
|
1231
|
-
`lash_${side}:
|
|
1254
|
+
`lash_${side}: ${faults.join(" and ")} \u2014 they are split from one source and MUST share cx/cy/w/h in layout, or the blink fold tears. Retune to match.`
|
|
1232
1255
|
);
|
|
1256
|
+
} else {
|
|
1257
|
+
const bareLeft = lash.marginLeft - eye.marginLeft;
|
|
1258
|
+
const bareRight = lash.marginRight - eye.marginRight;
|
|
1259
|
+
const [bareOuter, bareInner] = side === "R" ? [bareLeft, bareRight] : [bareRight, bareLeft];
|
|
1260
|
+
if ((bareOuter - bareInner) / eye.w > EYE_FACING_TOL_FRAC) {
|
|
1261
|
+
warnings.push(
|
|
1262
|
+
`eye_${side}: its lash stops ${pct(bareOuter / eye.w)} of the eye width short of the outer corner and ${pct(bareInner / eye.w)} short of the nose side \u2014 the eyewhite is drawn facing the other way, lash wing at the inner corner. The composer reads eyewhite.png as the eye on the screen LEFT: lash wing at the image's left end, lash-free tear duct at its right. Free fix: compose again with mirrorParts: ["eyewhite.png"] \u2014 no regeneration.`
|
|
1263
|
+
);
|
|
1264
|
+
}
|
|
1233
1265
|
}
|
|
1234
1266
|
}
|
|
1235
1267
|
}
|
|
@@ -1361,6 +1393,12 @@ var ORDER = [
|
|
|
1361
1393
|
"brow_R",
|
|
1362
1394
|
"hair_front"
|
|
1363
1395
|
];
|
|
1396
|
+
var PART_FILES = [
|
|
1397
|
+
...new Set(
|
|
1398
|
+
Object.values(DEFAULT_LAYOUT).map((cfg) => cfg.src).filter((src) => !src.startsWith("eyewhite_"))
|
|
1399
|
+
),
|
|
1400
|
+
EYEWHITE_SRC
|
|
1401
|
+
];
|
|
1364
1402
|
function resolveLayout(overrides) {
|
|
1365
1403
|
const resolved = { ...DEFAULT_LAYOUT };
|
|
1366
1404
|
if (overrides === void 0) return resolved;
|
|
@@ -1396,6 +1434,18 @@ function resolveLayout(overrides) {
|
|
|
1396
1434
|
}
|
|
1397
1435
|
return resolved;
|
|
1398
1436
|
}
|
|
1437
|
+
function resolveMirrorParts(names) {
|
|
1438
|
+
const mirrored = /* @__PURE__ */ new Set();
|
|
1439
|
+
for (const [i, name] of (names ?? []).entries()) {
|
|
1440
|
+
if (!PART_FILES.includes(name)) {
|
|
1441
|
+
throw new AutoRigInputError(
|
|
1442
|
+
`mirrorParts[${i}]: unknown part ${JSON.stringify(name)} \u2014 expected one of ${PART_FILES.join(", ")}`
|
|
1443
|
+
);
|
|
1444
|
+
}
|
|
1445
|
+
mirrored.add(name);
|
|
1446
|
+
}
|
|
1447
|
+
return mirrored;
|
|
1448
|
+
}
|
|
1399
1449
|
function keyWhiteToAlpha(rgba) {
|
|
1400
1450
|
const keyed = Buffer.from(rgba);
|
|
1401
1451
|
for (let i = 0; i < keyed.length; i += 4) {
|
|
@@ -1405,7 +1455,7 @@ function keyWhiteToAlpha(rgba) {
|
|
|
1405
1455
|
}
|
|
1406
1456
|
return keyed;
|
|
1407
1457
|
}
|
|
1408
|
-
async function partBuffer(role, cfg, partsDir, inMemory) {
|
|
1458
|
+
async function partBuffer(role, cfg, partsDir, inMemory, flipSource) {
|
|
1409
1459
|
let img;
|
|
1410
1460
|
if (inMemory !== void 0) {
|
|
1411
1461
|
img = (0, import_sharp2.default)(inMemory);
|
|
@@ -1423,7 +1473,7 @@ async function partBuffer(role, cfg, partsDir, inMemory) {
|
|
|
1423
1473
|
});
|
|
1424
1474
|
}
|
|
1425
1475
|
if (!cfg.noTrim) img = img.trim({ threshold: 12 });
|
|
1426
|
-
if (cfg.mirror) img = img.flop();
|
|
1476
|
+
if ((cfg.mirror ?? false) !== flipSource) img = img.flop();
|
|
1427
1477
|
const trimmed = await img.png().toBuffer({ resolveWithObject: true });
|
|
1428
1478
|
if (cfg.h === void 0) {
|
|
1429
1479
|
const scaledH = Math.round(
|
|
@@ -1520,28 +1570,47 @@ async function composeLayersFromParts(input) {
|
|
|
1520
1570
|
);
|
|
1521
1571
|
}
|
|
1522
1572
|
const layout = resolveLayout(input.layout);
|
|
1573
|
+
const mirrored = resolveMirrorParts(input.mirrorParts);
|
|
1523
1574
|
const split = await prepEyeSplit(partsDir);
|
|
1524
1575
|
const splitSources = /* @__PURE__ */ new Map([
|
|
1525
1576
|
["eyewhite_sclera.png", split.sclera],
|
|
1526
1577
|
["eyewhite_lash.png", split.lash]
|
|
1527
1578
|
]);
|
|
1528
|
-
const
|
|
1579
|
+
const placed = [];
|
|
1529
1580
|
const skipped = [];
|
|
1530
|
-
const preview = [];
|
|
1531
1581
|
for (const role of ORDER) {
|
|
1532
1582
|
const cfg = layout[role];
|
|
1583
|
+
const inMemory = splitSources.get(cfg.src);
|
|
1533
1584
|
const part = await partBuffer(
|
|
1534
1585
|
role,
|
|
1535
1586
|
cfg,
|
|
1536
1587
|
partsDir,
|
|
1537
|
-
|
|
1588
|
+
inMemory,
|
|
1589
|
+
// The split halves are cut from eyewhite.png, the file a caller names.
|
|
1590
|
+
mirrored.has(inMemory === void 0 ? cfg.src : EYEWHITE_SRC)
|
|
1538
1591
|
);
|
|
1539
1592
|
if (part === null) {
|
|
1540
1593
|
skipped.push(role);
|
|
1541
|
-
import_node_fs3.default.rmSync(import_node_path5.default.join(outDir, `${role}.png`), { force: true });
|
|
1542
1594
|
continue;
|
|
1543
1595
|
}
|
|
1544
1596
|
const { left, top } = placement(role, cfg, part.w, part.h);
|
|
1597
|
+
if (role === "lash_L" || role === "lash_R") {
|
|
1598
|
+
const eyeRole = role === "lash_L" ? "eye_L" : "eye_R";
|
|
1599
|
+
const eye = placed.find((p) => p.role === eyeRole);
|
|
1600
|
+
if (eye !== void 0 && (eye.left !== left || eye.top !== top || eye.part.w !== part.w || eye.part.h !== part.h)) {
|
|
1601
|
+
throw new AutoRigInputError(
|
|
1602
|
+
`layout.${role} places the lash at ${part.w}x${part.h} (${left},${top}), but layout.${eyeRole} places its sclera at ${eye.part.w}x${eye.part.h} (${eye.left},${eye.top}) \u2014 they are cut from one eyewhite into one frame, and the blink fold tears where they part. Set cx/cy/w/h the same on both.`
|
|
1603
|
+
);
|
|
1604
|
+
}
|
|
1605
|
+
}
|
|
1606
|
+
placed.push({ role, part, left, top });
|
|
1607
|
+
}
|
|
1608
|
+
for (const role of skipped) {
|
|
1609
|
+
import_node_fs3.default.rmSync(import_node_path5.default.join(outDir, `${role}.png`), { force: true });
|
|
1610
|
+
}
|
|
1611
|
+
const layers = [];
|
|
1612
|
+
const preview = [];
|
|
1613
|
+
for (const { role, part, left, top } of placed) {
|
|
1545
1614
|
const layer = await blankCanvas().composite([{ input: part.buf, left, top }]).png().toBuffer();
|
|
1546
1615
|
const outPath = import_node_path5.default.join(outDir, `${role}.png`);
|
|
1547
1616
|
writeFileAtomic(outPath, layer);
|
|
@@ -1582,7 +1651,7 @@ async function composeLayersFromParts(input) {
|
|
|
1582
1651
|
|
|
1583
1652
|
// src/server.ts
|
|
1584
1653
|
function createIkiMcpServer() {
|
|
1585
|
-
const server = new import_mcp.McpServer({ name: "iki", version: "0.
|
|
1654
|
+
const server = new import_mcp.McpServer({ name: "iki", version: "0.10.0" });
|
|
1586
1655
|
server.registerTool(
|
|
1587
1656
|
"validate_iki",
|
|
1588
1657
|
{
|
|
@@ -1709,7 +1778,10 @@ function createIkiMcpServer() {
|
|
|
1709
1778
|
h: import_zod.z.number()
|
|
1710
1779
|
}).partial()
|
|
1711
1780
|
).optional().describe(
|
|
1712
|
-
"Per-role override merged over the built-in defaults, keyed by role \u2014 hair_back, body, face, nose, mouth, mouth_open, eye_L, eye_R, iris_L, iris_R, lash_L, lash_R, brow_L, brow_R, hair_front \u2014 e.g. `{ eye_L: { cx: 660 } }`. `w` and `h` are integers in 1..1100; omit `h` to keep the part's own aspect, set it to stretch
|
|
1781
|
+
"Per-role override merged over the built-in defaults, keyed by role \u2014 hair_back, body, face, nose, mouth, mouth_open, eye_L, eye_R, iris_L, iris_R, lash_L, lash_R, brow_L, brow_R, hair_front \u2014 e.g. `{ eye_L: { cx: 660 } }`. `w` and `h` are integers in 1..1100; omit `h` to keep the part's own aspect, set it to stretch. eye_L/lash_L and eye_R/lash_R are cut from one eyewhite into one frame, so each pair must land on the same frame \u2014 a pair set to land apart is rejected."
|
|
1782
|
+
),
|
|
1783
|
+
mirrorParts: import_zod.z.array(import_zod.z.string()).optional().describe(
|
|
1784
|
+
"Part files to flip left-right as they are read, e.g. `[\"eyewhite.png\"]`. The composer reads eyewhite.png as the eye on the screen LEFT (lash wing at the image's left end, lash-free tear duct at its right) and brow.png as the brow on the screen RIGHT (thick head at the image's left end, tail at its right); a part drawn the other way round is fixed here for free. It flips the source, so every role cut from it flips together and an eye's sclera and lash stay in one frame."
|
|
1713
1785
|
)
|
|
1714
1786
|
}
|
|
1715
1787
|
},
|