@ikijs/mcp 0.31.1 → 0.33.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/dist/index.js CHANGED
@@ -30,8 +30,10 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // src/index.ts
31
31
  var index_exports = {};
32
32
  __export(index_exports, {
33
+ SWEEP_PRESETS: () => SWEEP_PRESETS,
33
34
  autoRigFromLayers: () => autoRigFromLayers,
34
35
  checkModelFolds: () => checkModelFolds,
36
+ checkNod: () => checkNod,
35
37
  checkSweep: () => checkSweep,
36
38
  composeLayersFromParts: () => composeLayersFromParts,
37
39
  createIkiMcpServer: () => createIkiMcpServer,
@@ -39,7 +41,9 @@ __export(index_exports, {
39
41
  describeIkiAt: () => describeIkiAt,
40
42
  describeRigPlan: () => describeRigPlan,
41
43
  formatFoldReport: () => formatFoldReport,
44
+ formatHairSideReport: () => formatHairSideReport,
42
45
  formatMeasureReport: () => formatMeasureReport,
46
+ formatNodReport: () => formatNodReport,
43
47
  formatPhysicsReport: () => formatPhysicsReport,
44
48
  formatRigPlanReport: () => formatRigPlanReport,
45
49
  formatSweepReport: () => formatSweepReport,
@@ -2261,6 +2265,83 @@ function pop(v) {
2261
2265
  }
2262
2266
  return most / mean;
2263
2267
  }
2268
+ var NOD_TURNS = [-30, 0, 30];
2269
+ var NOD_PARTS = [
2270
+ "face",
2271
+ "eye_L",
2272
+ "eye_R",
2273
+ "iris_L",
2274
+ "iris_R",
2275
+ "nose",
2276
+ "lip_upper",
2277
+ "mouth"
2278
+ ];
2279
+ var NOD_ENDS = [0, -LADDER_MIN, LADDER_MAX - LADDER_MIN];
2280
+ function checkNod(model) {
2281
+ const face = model.parts.find((p) => p.id === "face");
2282
+ if (!face) return { unavailable: "no face part" };
2283
+ const hasEyes = ["eye_L", "eye_R"].every(
2284
+ (id) => model.parts.some((p) => p.id === id)
2285
+ );
2286
+ if (!hasEyes) return { unavailable: "no eye_L and eye_R parts" };
2287
+ const fw = face.width;
2288
+ const ladders = NOD_TURNS.map(
2289
+ (x) => Array.from(
2290
+ { length: LADDER_MAX - LADDER_MIN + 1 },
2291
+ (_, i) => landParts(
2292
+ model,
2293
+ { ParamAngleX: x, ParamAngleY: LADDER_MIN + i },
2294
+ NOD_PARTS
2295
+ )
2296
+ )
2297
+ );
2298
+ const has = (id) => ladders[0][0].has(id);
2299
+ const boxes = (id) => ladders.map((ladder) => ladder.map((l) => box(l.get(id), fw)));
2300
+ const spread = (v) => Math.max(...v) - Math.min(...v);
2301
+ const ranges = (values) => {
2302
+ const [m30, zero, p30] = NOD_TURNS.map(
2303
+ (_, b) => spread(
2304
+ Array.from(
2305
+ { length: LADDER_MAX - LADDER_MIN + 1 },
2306
+ (_2, i) => values(b, i)
2307
+ )
2308
+ )
2309
+ );
2310
+ return { m30, zero, p30 };
2311
+ };
2312
+ const gap = (l, r) => {
2313
+ const bl = boxes(l);
2314
+ const br = boxes(r);
2315
+ return ranges((b, i) => br[b][i].x - bl[b][i].x);
2316
+ };
2317
+ const nod = [{ id: "eyes", range: gap("eye_L", "eye_R") }];
2318
+ if (has("iris_L") && has("iris_R")) {
2319
+ nod.push({ id: "irises", range: gap("iris_L", "iris_R") });
2320
+ }
2321
+ const mouthId = has("lip_upper") ? "lip_upper" : has("mouth") ? "mouth" : null;
2322
+ if (mouthId) {
2323
+ const bm = boxes(mouthId);
2324
+ nod.push({ id: "mouth", range: ranges((b, i) => bm[b][i].width) });
2325
+ }
2326
+ const corner = ["eye_L", "eye_R", "nose"].filter(has).map((id) => {
2327
+ const b = boxes(id);
2328
+ const at = (t, j) => b[t][NOD_ENDS[j]];
2329
+ const residual = (t, j) => {
2330
+ const r = (axis) => at(t, j)[axis] - at(t, 1)[axis] - at(1, j)[axis] + at(1, 1)[axis];
2331
+ return Math.max(Math.abs(r("x")), Math.abs(r("y")));
2332
+ };
2333
+ return {
2334
+ id,
2335
+ residual: {
2336
+ mm: residual(0, 0),
2337
+ mp: residual(0, 2),
2338
+ pm: residual(2, 0),
2339
+ pp: residual(2, 2)
2340
+ }
2341
+ };
2342
+ });
2343
+ return { unit: "fw", faceWidth: fw, nod, corner };
2344
+ }
2264
2345
  function checkSweep(model) {
2265
2346
  const face = model.parts.find((p) => p.id === "face");
2266
2347
  if (!face) return { preset: "turn", unavailable: "no face part" };
@@ -2330,6 +2411,19 @@ function formatSweepReport(report) {
2330
2411
  `SWEEP turn plate: amplitude ${fw3(report.plateAmplitude)} fw`
2331
2412
  ];
2332
2413
  }
2414
+ function formatNodReport(report) {
2415
+ if ("unavailable" in report) {
2416
+ return [`SWEEP nod: unavailable \u2014 ${report.unavailable}`];
2417
+ }
2418
+ return [
2419
+ ...report.nod.map(
2420
+ ({ id, range: r }) => `SWEEP nod ${id}: ${id === "mouth" ? "width" : "gap"} range X -30 ${fw3(r.m30)} / 0 ${fw3(r.zero)} / +30 ${fw3(r.p30)} fw`
2421
+ ),
2422
+ ...report.corner.map(
2423
+ ({ id, residual: r }) => `SWEEP corner ${id}: residual (-30,-30) ${fw3(r.mm)} / (-30,+30) ${fw3(r.mp)} / (+30,-30) ${fw3(r.pm)} / (+30,+30) ${fw3(r.pp)} fw`
2424
+ )
2425
+ ];
2426
+ }
2333
2427
 
2334
2428
  // src/sweep.ts
2335
2429
  var import_node_fs3 = __toESM(require("fs"));
@@ -2337,6 +2431,8 @@ var import_node_path3 = __toESM(require("path"));
2337
2431
  var SWEEP_CLOCK_HZ = 60;
2338
2432
  var SWEEP_FPS = 30;
2339
2433
  var SWEEP_DURATION_S = 3;
2434
+ var BOX_DURATION_S = 6;
2435
+ var SWEEP_PRESETS = ["turn", "turn-nod"];
2340
2436
  var SWEEP_WARMUP_S = 0.5;
2341
2437
  var SWEEP_FRAME_MS = 1e3 / SWEEP_CLOCK_HZ * (1 + 1e-9);
2342
2438
  var SHEET_THETAS = [-30, -20, -10, -5, 0, 5, 10, 20, 30];
@@ -2344,16 +2440,75 @@ var SHEET_MAX_SIDE = 2e3;
2344
2440
  var SHEET_MARGIN = 8;
2345
2441
  var SHEET_LABEL_BAND = 24;
2346
2442
  var KYMOGRAPH_BAND = 3;
2347
- var SWEEP_PARAMETER = "ParamAngleX";
2348
- var STEPS = SWEEP_CLOCK_HZ * SWEEP_DURATION_S;
2349
2443
  var CAPTURE_EVERY = SWEEP_CLOCK_HZ / SWEEP_FPS;
2350
- var FRAMES = STEPS / CAPTURE_EVERY;
2351
2444
  var LEG_FROM_S = 0.75;
2352
2445
  var LEG_TO_S = 2.25;
2353
2446
  var AMPLITUDE_DEG = 30;
2447
+ var BOX_CORNERS = [
2448
+ [0, 0],
2449
+ [0, -30],
2450
+ [-30, -30],
2451
+ [-30, 30],
2452
+ [30, 30],
2453
+ [30, -30],
2454
+ [0, -30],
2455
+ [0, 0]
2456
+ ];
2457
+ var BOX_SPEED_DEG_S = 50;
2458
+ var BOX_SHEET_STOPS = [
2459
+ [-30, 30],
2460
+ [0, 30],
2461
+ [30, 30],
2462
+ [-30, 0],
2463
+ [0, 0],
2464
+ [30, 0],
2465
+ [-30, -30],
2466
+ [0, -30],
2467
+ [30, -30]
2468
+ ];
2354
2469
  function turnTheta(t) {
2355
2470
  return -AMPLITUDE_DEG * Math.sin(2 * Math.PI * t / SWEEP_DURATION_S);
2356
2471
  }
2472
+ function boxAngles(t) {
2473
+ let start = 0;
2474
+ for (let i = 0; i + 1 < BOX_CORNERS.length; i++) {
2475
+ const [fx, fy] = BOX_CORNERS[i];
2476
+ const [tx, ty] = BOX_CORNERS[i + 1];
2477
+ const len = Math.max(Math.abs(tx - fx), Math.abs(ty - fy));
2478
+ const dur = len / BOX_SPEED_DEG_S;
2479
+ if (t < start + dur) {
2480
+ const u = (t - start) / dur;
2481
+ const e = (1 - Math.cos(Math.PI * u)) / 2;
2482
+ return { x: fx + (tx - fx) * e, y: fy + (ty - fy) * e };
2483
+ }
2484
+ start += dur;
2485
+ }
2486
+ return { x: 0, y: 0 };
2487
+ }
2488
+ function sweepDurationS(preset) {
2489
+ return preset === "turn" ? SWEEP_DURATION_S : BOX_DURATION_S;
2490
+ }
2491
+ function schedule(preset) {
2492
+ const durationS = sweepDurationS(preset);
2493
+ const n = SWEEP_CLOCK_HZ * durationS;
2494
+ if (preset === "turn") {
2495
+ return {
2496
+ parameters: ["ParamAngleX"],
2497
+ steps: Array.from({ length: n }, (_, j) => ({
2498
+ ParamAngleX: turnTheta(j / SWEEP_CLOCK_HZ)
2499
+ })),
2500
+ durationS
2501
+ };
2502
+ }
2503
+ return {
2504
+ parameters: ["ParamAngleX", "ParamAngleY"],
2505
+ steps: Array.from({ length: n }, (_, j) => {
2506
+ const { x, y } = boxAngles(j / SWEEP_CLOCK_HZ);
2507
+ return { ParamAngleX: x, ParamAngleY: y };
2508
+ }),
2509
+ durationS
2510
+ };
2511
+ }
2357
2512
  function eyeRowModelPx(model) {
2358
2513
  const landed = landParts(model, {}, ["eye_L", "eye_R"]);
2359
2514
  const l = landed.get("eye_L");
@@ -2378,35 +2533,44 @@ function physicsOutputIds(model) {
2378
2533
  }
2379
2534
  return [...ids];
2380
2535
  }
2381
- function sheetFrames(thetas) {
2536
+ function turnSheetFrames(steps, frames) {
2382
2537
  const onLeg = [];
2383
- for (let k = 0; k < FRAMES; k++) {
2538
+ for (let k = 0; k < frames; k++) {
2384
2539
  const t = k / SWEEP_FPS;
2385
2540
  if (t >= LEG_FROM_S && t <= LEG_TO_S) onLeg.push(k);
2386
2541
  }
2542
+ const x = (k) => steps[CAPTURE_EVERY * k].ParamAngleX;
2387
2543
  const picked = [];
2388
2544
  for (const target2 of SHEET_THETAS) {
2389
2545
  let best = onLeg[0];
2390
2546
  for (const k of onLeg) {
2391
- if (Math.abs(thetas[CAPTURE_EVERY * k] - target2) < Math.abs(thetas[CAPTURE_EVERY * best] - target2)) {
2392
- best = k;
2393
- }
2547
+ if (Math.abs(x(k) - target2) < Math.abs(x(best) - target2)) best = k;
2394
2548
  }
2395
2549
  if (!picked.includes(best)) picked.push(best);
2396
2550
  }
2397
2551
  return picked.sort((a, b) => a - b);
2398
2552
  }
2399
- function sheetLabel(theta, t) {
2400
- const rounded = Math.round(theta * 10) / 10 + 0;
2553
+ function boxSheetFrames(steps, frames) {
2554
+ return BOX_SHEET_STOPS.map(([sx, sy]) => {
2555
+ const miss = (k) => {
2556
+ const s = steps[CAPTURE_EVERY * k];
2557
+ return Math.abs(s.ParamAngleX - sx) + Math.abs(s.ParamAngleY - sy);
2558
+ };
2559
+ let best = 0;
2560
+ for (let k = 1; k < frames; k++) {
2561
+ if (miss(k) < miss(best)) best = k;
2562
+ }
2563
+ return best;
2564
+ });
2565
+ }
2566
+ function signedDeg(angle) {
2567
+ const rounded = Math.round(angle * 10) / 10 + 0;
2401
2568
  const deg = rounded.toFixed(1);
2402
- const signed2 = rounded > 0 ? `+${deg}` : deg.replace("-", "\u2212");
2403
- return `\u03B8 ${signed2}\xB0 t ${t.toFixed(2)} s`;
2569
+ return rounded > 0 ? `+${deg}` : deg.replace("-", "\u2212");
2404
2570
  }
2405
- function sweepSpec(model, crop) {
2406
- const thetas = Array.from(
2407
- { length: STEPS },
2408
- (_, j) => turnTheta(j / SWEEP_CLOCK_HZ)
2409
- );
2571
+ function sweepSpec(model, preset, crop) {
2572
+ const { parameters, steps, durationS } = schedule(preset);
2573
+ const frameCount = durationS * SWEEP_FPS;
2410
2574
  const dw = crop ? crop.dw : BUST_SIZE;
2411
2575
  const dh = crop ? crop.dh : BUST_SIZE;
2412
2576
  const m = SHEET_MARGIN;
@@ -2416,29 +2580,38 @@ function sweepSpec(model, crop) {
2416
2580
  (SHEET_MAX_SIDE - 2 * m) / (3 * dw),
2417
2581
  (SHEET_MAX_SIDE - 2 * m - 3 * b) / (3 * dh)
2418
2582
  );
2419
- const frames = sheetFrames(thetas);
2583
+ const frames = preset === "turn" ? turnSheetFrames(steps, frameCount) : boxSheetFrames(steps, frameCount);
2584
+ const labelOf = (k) => {
2585
+ const s = steps[CAPTURE_EVERY * k];
2586
+ const t = (k / SWEEP_FPS).toFixed(2);
2587
+ return preset === "turn" ? `\u03B8 ${signedDeg(s.ParamAngleX)}\xB0 t ${t} s` : `X ${signedDeg(s.ParamAngleX)}\xB0 Y ${signedDeg(s.ParamAngleY)}\xB0 t ${t} s`;
2588
+ };
2420
2589
  const { width: W, height: H } = model.canvas;
2421
- const yModel = eyeRowModelPx(model);
2422
- let row = Math.round(dh / 2);
2423
- let at = "middle";
2424
- if (yModel !== void 0) {
2425
- const y0 = bustPadY(W, H);
2426
- const s = BUST_SIZE / W;
2427
- const eyeRow = Math.round(
2428
- crop ? (y0 + yModel * s - crop.sy) * crop.dh / crop.sh : y0 + yModel * s
2429
- );
2430
- if (eyeRow >= 1 && eyeRow <= dh - 2) {
2431
- row = eyeRow;
2432
- at = "eye row";
2590
+ let kymograph;
2591
+ if (preset === "turn") {
2592
+ const yModel = eyeRowModelPx(model);
2593
+ let row = Math.round(dh / 2);
2594
+ let at = "middle";
2595
+ if (yModel !== void 0) {
2596
+ const y0 = bustPadY(W, H);
2597
+ const s = BUST_SIZE / W;
2598
+ const eyeRow = Math.round(
2599
+ crop ? (y0 + yModel * s - crop.sy) * crop.dh / crop.sh : y0 + yModel * s
2600
+ );
2601
+ if (eyeRow >= 1 && eyeRow <= dh - 2) {
2602
+ row = eyeRow;
2603
+ at = "eye row";
2604
+ }
2433
2605
  }
2606
+ kymograph = { row, band: KYMOGRAPH_BAND, at };
2434
2607
  }
2435
2608
  return {
2436
- parameter: SWEEP_PARAMETER,
2609
+ parameters,
2437
2610
  frameMs: SWEEP_FRAME_MS,
2438
2611
  warmup: SWEEP_WARMUP_S * SWEEP_CLOCK_HZ,
2439
- thetas,
2612
+ steps,
2440
2613
  captureEvery: CAPTURE_EVERY,
2441
- frames: FRAMES,
2614
+ frames: frameCount,
2442
2615
  frame: { width: dw, height: dh },
2443
2616
  physicsOutputs: physicsOutputIds(model),
2444
2617
  sheet: {
@@ -2449,11 +2622,9 @@ function sweepSpec(model, crop) {
2449
2622
  },
2450
2623
  margin: m,
2451
2624
  labelBand: b,
2452
- labels: frames.map(
2453
- (k) => sheetLabel(thetas[CAPTURE_EVERY * k], k / SWEEP_FPS)
2454
- )
2625
+ labels: frames.map(labelOf)
2455
2626
  },
2456
- kymograph: { row, band: KYMOGRAPH_BAND, at },
2627
+ kymograph,
2457
2628
  crop
2458
2629
  };
2459
2630
  }
@@ -2463,7 +2634,7 @@ function flipbookHtml(manifest) {
2463
2634
  <html lang="en">
2464
2635
  <head>
2465
2636
  <meta charset="utf-8">
2466
- <title>turn sweep</title>
2637
+ <title>${manifest.preset} sweep</title>
2467
2638
  <style>
2468
2639
  body { font: 14px system-ui, sans-serif; margin: 16px; background: #222; color: #eee; }
2469
2640
  .row { display: flex; gap: 16px; align-items: flex-start; }
@@ -2496,13 +2667,18 @@ img { max-width: 48vw; height: auto; background: #444; }
2496
2667
  var playing = true;
2497
2668
  scrub.max = String(n - 1);
2498
2669
  if (b) { bi.style.display = "block"; }
2670
+ function short(id) {
2671
+ return id === "ParamAngleX" ? "X" : id === "ParamAngleY" ? "Y" : id;
2672
+ }
2499
2673
  function show(k) {
2500
2674
  i = k;
2501
2675
  var f = m.frames[k];
2502
2676
  a.src = f.file;
2503
2677
  if (b) { bi.src = b.replace(/\\/$/, "") + "/" + f.file; }
2504
2678
  scrub.value = String(k);
2505
- readout.textContent = "frame " + k + " \\u03b8 " + f.theta.toFixed(1) + "\\u00b0 t " + f.t.toFixed(2) + " s";
2679
+ readout.textContent = "frame " + k + m.parameters.map(function (id) {
2680
+ return " " + short(id) + " " + f.values[id].toFixed(1) + "\\u00b0";
2681
+ }).join("") + " t " + f.t.toFixed(2) + " s";
2506
2682
  }
2507
2683
  play.addEventListener("click", function () {
2508
2684
  playing = !playing;
@@ -2521,7 +2697,14 @@ img { max-width: 48vw; height: auto; background: #444; }
2521
2697
  </html>
2522
2698
  `;
2523
2699
  }
2524
- function prepareSweepDir(outDir, name) {
2700
+ var STALE_FILE = /^f\d{3}\.png$/;
2701
+ var STALE_NAMES = [
2702
+ "kymograph.png",
2703
+ "sheet.png",
2704
+ "manifest.json",
2705
+ "index.html"
2706
+ ];
2707
+ function prepareSweepDir(outDir, name, label) {
2525
2708
  const dir = import_node_path3.default.join(outDir, name);
2526
2709
  try {
2527
2710
  import_node_fs3.default.mkdirSync(dir);
@@ -2532,13 +2715,19 @@ function prepareSweepDir(outDir, name) {
2532
2715
  }
2533
2716
  const stat = import_node_fs3.default.lstatSync(dir);
2534
2717
  if (stat.isSymbolicLink()) {
2535
- throw new AutoRigInputError(`sweep.name names ${dir}, a symbolic link`);
2718
+ throw new AutoRigInputError(`${label}.name names ${dir}, a symbolic link`);
2536
2719
  }
2537
2720
  if (!stat.isDirectory()) {
2538
- throw new AutoRigInputError(`sweep.name names ${dir}, not a directory`);
2721
+ throw new AutoRigInputError(`${label}.name names ${dir}, not a directory`);
2722
+ }
2723
+ return confineToWorkingDirectory(process.cwd(), dir, "sweep dir", name);
2724
+ }
2725
+ function clearSweepDir(real) {
2726
+ for (const entry of import_node_fs3.default.readdirSync(real)) {
2727
+ if (STALE_FILE.test(entry) || STALE_NAMES.includes(entry)) {
2728
+ import_node_fs3.default.rmSync(import_node_path3.default.join(real, entry));
2729
+ }
2539
2730
  }
2540
- const real = confineToWorkingDirectory(process.cwd(), dir, "sweep dir", name);
2541
- return real;
2542
2731
  }
2543
2732
 
2544
2733
  // src/render-poses.ts
@@ -2551,7 +2740,7 @@ var SWEEP_NAME = /^[A-Za-z0-9][A-Za-z0-9_.-]*$/;
2551
2740
  function bustPadY(width, height) {
2552
2741
  return Math.max(0, (BUST_SIZE - BUST_SIZE * height / width) / 2);
2553
2742
  }
2554
- function planRenders(model, requested, sweep) {
2743
+ function planRenders(model, requested, sweep, sweeps) {
2555
2744
  const { width: W, height: H } = model.canvas;
2556
2745
  const fullBody = H > W;
2557
2746
  const canvas = fullBody ? {
@@ -2606,12 +2795,37 @@ function planRenders(model, requested, sweep) {
2606
2795
  dh
2607
2796
  };
2608
2797
  };
2609
- if (sweep && !SWEEP_NAME.test(sweep.name)) {
2610
- throw new AutoRigInputError(
2611
- `sweep.name must match ${SWEEP_NAME.source} (it names <outDir>/<name>/): ${JSON.stringify(sweep.name)}`
2612
- );
2798
+ if (sweeps && sweeps.length === 0) {
2799
+ throw new AutoRigInputError("sweeps is empty");
2613
2800
  }
2614
- const sweepCrop = sweep ? sweep.crop ? toRenderCrop(sweep.crop, "sweep.crop") : squareCrop : void 0;
2801
+ const asked = [
2802
+ ...sweep ? [{ label: "sweep", entry: sweep }] : [],
2803
+ ...(sweeps ?? []).map((entry, i) => ({ label: `sweeps[${i}]`, entry }))
2804
+ ];
2805
+ asked.forEach(({ label, entry }, i) => {
2806
+ if (!SWEEP_NAME.test(entry.name)) {
2807
+ throw new AutoRigInputError(
2808
+ `${label}.name must match ${SWEEP_NAME.source} (it names <outDir>/<name>/): ${JSON.stringify(entry.name)}`
2809
+ );
2810
+ }
2811
+ const sameName = asked.findIndex(
2812
+ (a) => a.entry.name.toLowerCase() === entry.name.toLowerCase()
2813
+ );
2814
+ if (sameName < i) {
2815
+ throw new AutoRigInputError(
2816
+ `${label}.name ${JSON.stringify(entry.name)} repeats ${asked[sameName].label}.name ${JSON.stringify(asked[sameName].entry.name)} (ignoring case: one directory on a case-insensitive disk)`
2817
+ );
2818
+ }
2819
+ const samePreset = asked.findIndex((a) => a.entry.preset === entry.preset);
2820
+ if (samePreset < i) {
2821
+ throw new AutoRigInputError(
2822
+ `${label}.preset ${JSON.stringify(entry.preset)} repeats ${asked[samePreset].label}.preset (the same frames twice)`
2823
+ );
2824
+ }
2825
+ });
2826
+ const cropOf = (entry, label) => entry.crop ? toRenderCrop(entry.crop, `${label}.crop`) : squareCrop;
2827
+ const sweepCrop = sweep ? cropOf(sweep, "sweep") : void 0;
2828
+ const sweepsCrops = sweeps?.map((entry, i) => cropOf(entry, `sweeps[${i}]`));
2615
2829
  if (requested) {
2616
2830
  if (requested.length === 0) throw new AutoRigInputError("poses is empty");
2617
2831
  const poses2 = requested.map((pose, i) => {
@@ -2623,7 +2837,7 @@ function planRenders(model, requested, sweep) {
2623
2837
  crop: toRenderCrop(pose.crop, `poses[${i}].crop`)
2624
2838
  };
2625
2839
  });
2626
- return { canvas, view, fullBody, mouth, poses: poses2, sweepCrop };
2840
+ return { canvas, view, fullBody, mouth, poses: poses2, sweepCrop, sweepsCrops };
2627
2841
  }
2628
2842
  const bodyAngles = Object.fromEntries(
2629
2843
  [
@@ -2731,7 +2945,7 @@ function planRenders(model, requested, sweep) {
2731
2945
  );
2732
2946
  }
2733
2947
  }
2734
- return { canvas, view, fullBody, mouth, poses, sweepCrop };
2948
+ return { canvas, view, fullBody, mouth, poses, sweepCrop, sweepsCrops };
2735
2949
  }
2736
2950
  function checkRequest(requested, i) {
2737
2951
  const { name, values } = requested[i];
@@ -2771,8 +2985,8 @@ function readPageScript() {
2771
2985
  );
2772
2986
  }
2773
2987
  }
2774
- async function captureSweep(evaluate, model, plan, requested, dir, report) {
2775
- const spec = sweepSpec(model, plan.sweepCrop);
2988
+ async function captureSweep(evaluate, model, requested, crop, dir, report, nod) {
2989
+ const spec = sweepSpec(model, requested.preset, crop);
2776
2990
  await evaluate(
2777
2991
  `window.__ikiRender.sweepBegin(${JSON.stringify(spec)})`,
2778
2992
  CAPTURE_MS
@@ -2797,12 +3011,12 @@ async function captureSweep(evaluate, model, plan, requested, dir, report) {
2797
3011
  i: k,
2798
3012
  file,
2799
3013
  t: k / SWEEP_FPS,
2800
- theta: spec.thetas[spec.captureEvery * k],
2801
3014
  values
2802
3015
  });
2803
3016
  }
2804
3017
  const end = await evaluate("window.__ikiRender.sweepEnd()", CAPTURE_MS);
2805
3018
  for (const [what, url] of Object.entries(end)) {
3019
+ if (url === void 0) continue;
2806
3020
  if (typeof url !== "string" || !url.startsWith(PNG_PREFIX)) {
2807
3021
  throw new Error(
2808
3022
  `sweep ${requested.name} ${what}: the page returned no PNG`
@@ -2810,26 +3024,29 @@ async function captureSweep(evaluate, model, plan, requested, dir, report) {
2810
3024
  }
2811
3025
  }
2812
3026
  const sheet = import_node_path4.default.join(dir, "sheet.png");
2813
- const kymograph = import_node_path4.default.join(dir, "kymograph.png");
2814
3027
  writeFileAtomic(
2815
3028
  sheet,
2816
3029
  Buffer.from(end.sheet.slice(PNG_PREFIX.length), "base64")
2817
3030
  );
2818
- writeFileAtomic(
2819
- kymograph,
2820
- Buffer.from(end.kymograph.slice(PNG_PREFIX.length), "base64")
2821
- );
3031
+ let kymograph;
3032
+ if (end.kymograph !== void 0) {
3033
+ kymograph = import_node_path4.default.join(dir, "kymograph.png");
3034
+ writeFileAtomic(
3035
+ kymograph,
3036
+ Buffer.from(end.kymograph.slice(PNG_PREFIX.length), "base64")
3037
+ );
3038
+ }
2822
3039
  const manifest = {
2823
- version: 1,
3040
+ version: 2,
2824
3041
  preset: requested.preset,
2825
- parameter: spec.parameter,
3042
+ parameters: spec.parameters,
2826
3043
  fps: SWEEP_FPS,
2827
3044
  clockHz: SWEEP_CLOCK_HZ,
2828
3045
  warmupS: SWEEP_WARMUP_S,
2829
- durationS: SWEEP_DURATION_S,
3046
+ durationS: sweepDurationS(requested.preset),
2830
3047
  crop: requested.crop ?? null,
2831
3048
  frame: spec.frame,
2832
- kymographRow: { row: spec.kymograph.row, at: spec.kymograph.at },
3049
+ kymographRow: spec.kymograph ? { row: spec.kymograph.row, at: spec.kymograph.at } : null,
2833
3050
  sheet: { frames: spec.sheet.frames, cell: spec.sheet.cell },
2834
3051
  physicsOutputs: spec.physicsOutputs,
2835
3052
  frames
@@ -2846,9 +3063,10 @@ async function captureSweep(evaluate, model, plan, requested, dir, report) {
2846
3063
  frames: spec.frames,
2847
3064
  manifest: manifestPath,
2848
3065
  sheet,
2849
- kymograph,
3066
+ ...kymograph ? { kymograph } : {},
2850
3067
  flipbook,
2851
- report
3068
+ report,
3069
+ nod
2852
3070
  };
2853
3071
  }
2854
3072
  async function renderPoses(input) {
@@ -2861,7 +3079,7 @@ async function renderPoses(input) {
2861
3079
  );
2862
3080
  const outDir = resolveOutputDir(input.outDir);
2863
3081
  const model = (0, import_format8.loadIkiModel)((0, import_node_fs4.readFileSync)(modelFile, "utf8"));
2864
- const plan = planRenders(model, input.poses, input.sweep);
3082
+ const plan = planRenders(model, input.poses, input.sweep, input.sweeps);
2865
3083
  const browser = findBrowser();
2866
3084
  if (!browser) return { ok: false, error: NO_BROWSER_MESSAGE };
2867
3085
  const pageScript = readPageScript();
@@ -2870,9 +3088,16 @@ async function renderPoses(input) {
2870
3088
  input.poses?.map((p) => p.values)
2871
3089
  );
2872
3090
  const physics = checkPhysics(model);
2873
- const sweepDir = input.sweep ? prepareSweepDir(outDir, input.sweep.name) : void 0;
2874
- const sweepReport = input.sweep ? checkSweep(model) : void 0;
2875
- const { failedTextures, poses, sweep } = await withBrowser(
3091
+ const sweepDir = input.sweep ? prepareSweepDir(outDir, input.sweep.name, "sweep") : void 0;
3092
+ const sweepsDirs = input.sweeps?.map(
3093
+ (s, i) => prepareSweepDir(outDir, s.name, `sweeps[${i}]`)
3094
+ );
3095
+ for (const d of [sweepDir, ...sweepsDirs ?? []]) {
3096
+ if (d) clearSweepDir(d);
3097
+ }
3098
+ const sweepReport = input.sweep || input.sweeps ? checkSweep(model) : void 0;
3099
+ const nodReport = input.sweep || input.sweeps ? checkNod(model) : void 0;
3100
+ const { failedTextures, poses, sweep, sweeps } = await withBrowser(
2876
3101
  browser,
2877
3102
  async (evaluate) => {
2878
3103
  await evaluate(pageScript, PAGE_SCRIPT_MS);
@@ -2896,15 +3121,38 @@ async function renderPoses(input) {
2896
3121
  );
2897
3122
  written.push({ name: pose.name, path: file });
2898
3123
  }
2899
- const sweep2 = input.sweep && sweepDir && sweepReport ? await captureSweep(
3124
+ const sweep2 = input.sweep && sweepDir && sweepReport && nodReport ? await captureSweep(
2900
3125
  evaluate,
2901
3126
  model,
2902
- plan,
2903
3127
  input.sweep,
3128
+ plan.sweepCrop,
2904
3129
  sweepDir,
2905
- sweepReport
3130
+ sweepReport,
3131
+ nodReport
2906
3132
  ) : void 0;
2907
- return { failedTextures: loaded.failedTextures, poses: written, sweep: sweep2 };
3133
+ let sweeps2;
3134
+ if (input.sweeps && sweepsDirs && sweepReport && nodReport) {
3135
+ sweeps2 = [];
3136
+ for (const [i, requested] of input.sweeps.entries()) {
3137
+ sweeps2.push(
3138
+ await captureSweep(
3139
+ evaluate,
3140
+ model,
3141
+ requested,
3142
+ plan.sweepsCrops?.[i],
3143
+ sweepsDirs[i],
3144
+ sweepReport,
3145
+ nodReport
3146
+ )
3147
+ );
3148
+ }
3149
+ }
3150
+ return {
3151
+ failedTextures: loaded.failedTextures,
3152
+ poses: written,
3153
+ sweep: sweep2,
3154
+ sweeps: sweeps2
3155
+ };
2908
3156
  }
2909
3157
  );
2910
3158
  return {
@@ -2918,7 +3166,8 @@ async function renderPoses(input) {
2918
3166
  modelCanvas: model.canvas,
2919
3167
  folds,
2920
3168
  physics,
2921
- sweep
3169
+ sweep,
3170
+ sweeps
2922
3171
  };
2923
3172
  } catch (error) {
2924
3173
  if (error instanceof AutoRigInputError || error instanceof import_format8.IkiFormatError) {
@@ -3489,7 +3738,7 @@ async function autoRigFromLayers(input) {
3489
3738
  var import_node_fs7 = __toESM(require("fs"));
3490
3739
  var import_node_path10 = __toESM(require("path"));
3491
3740
  var import_sharp4 = __toESM(require("sharp"));
3492
- var import_editor12 = require("@ikijs/editor");
3741
+ var import_editor13 = require("@ikijs/editor");
3493
3742
 
3494
3743
  // src/trim.ts
3495
3744
  var import_editor4 = require("@ikijs/editor");
@@ -3632,8 +3881,184 @@ function capWarning(arm, g, body) {
3632
3881
  return `${arm}: its shoulder cap reaches ${px(overlap)} px under the torso's edge on its pivot row (y=${row}), under half its radius (${px(need)} px) \u2014 a gap opens beside the shoulder once the arm raises. Move layout.${arm}.cx ${Math.ceil(need - overlap)} px toward the body (free).`;
3633
3882
  }
3634
3883
 
3635
- // src/measure-forearm-pose.ts
3884
+ // src/measure-hair-side.ts
3636
3885
  var import_editor6 = require("@ikijs/editor");
3886
+ var LOCK_ROLES = ["hair_side_R", "hair_side_L"];
3887
+ var VISIBLE_MIN_PX = 3;
3888
+ var LEAN_HH = 0.12;
3889
+ var TWO_LOCKS_RUN = 0.25;
3890
+ var TWO_LOCKS_GAP = 0.1;
3891
+ function covers(runs, x) {
3892
+ for (let i = 0; i + 1 < runs.length; i += 2) {
3893
+ if (x >= runs[i] && x < runs[i + 1]) return true;
3894
+ }
3895
+ return false;
3896
+ }
3897
+ function runsAt(layer, y) {
3898
+ return layer?.rowRuns?.[y - layer.bbox.y] ?? [];
3899
+ }
3900
+ function opaqueRows(layer) {
3901
+ const runs = layer.rowRuns ?? [];
3902
+ const top = runs.findIndex((r) => r.length > 0);
3903
+ if (top < 0) return void 0;
3904
+ let bottom = runs.length - 1;
3905
+ while (runs[bottom].length === 0) bottom--;
3906
+ return { top: layer.bbox.y + top, bottom: layer.bbox.y + bottom };
3907
+ }
3908
+ async function hairSideWarnings(absDir, layers) {
3909
+ const present = LOCK_ROLES.filter((r) => layers[r] !== void 0);
3910
+ if (present.length === 0) return [];
3911
+ const warnings = [];
3912
+ if (layers.hair_front === void 0) {
3913
+ for (const role of present) {
3914
+ warnings.push(
3915
+ `${role}: needs hair_front \u2014 the rig refuses a lock without the bangs its root hides under. Remove hair_side.png and recompose (free), or draw hair_front.png. Billed.`
3916
+ );
3917
+ }
3918
+ return warnings;
3919
+ }
3920
+ const ref = layers.hair_front;
3921
+ let mismatched = false;
3922
+ for (const r of [...present, "hair_back", "face"]) {
3923
+ const stats = layers[r];
3924
+ if (stats === void 0) continue;
3925
+ if (stats.canvasW !== ref.canvasW || stats.canvasH !== ref.canvasH) {
3926
+ mismatched = true;
3927
+ warnings.push(
3928
+ `${r}: its canvas ${stats.canvasW}x${stats.canvasH} differs from hair_front's ${ref.canvasW}x${ref.canvasH} \u2014 auto_rig_from_layers refuses layers of different sizes; recompose them together.`
3929
+ );
3930
+ }
3931
+ }
3932
+ if (mismatched) return warnings;
3933
+ const measurer = (0, import_editor6.createLayerSetMeasurer)({
3934
+ width: ref.canvasW,
3935
+ height: ref.canvasH
3936
+ });
3937
+ const read = (role) => layers[role] === void 0 ? void 0 : measured(measurer, absDir, role);
3938
+ const front = await read("hair_front");
3939
+ const back = await read("hair_back");
3940
+ const face = await read("face");
3941
+ const axisX = face ? face.bbox.x + face.bbox.w / 2 : ref.canvasW / 2;
3942
+ const locks = /* @__PURE__ */ new Map();
3943
+ for (const role of present) {
3944
+ const lock = await measured(measurer, absDir, role);
3945
+ locks.set(role, lock);
3946
+ const side = lock.bbox.x + lock.bbox.w / 2 < axisX ? -1 : 1;
3947
+ const eyeRole = ["eye_L", "eye_R"].find(
3948
+ (r) => layers[r] !== void 0 && (layers[r].bboxCx < axisX ? -1 : 1) === side
3949
+ );
3950
+ const eye = eyeRole === void 0 ? void 0 : layers[eyeRole];
3951
+ const root = rootWarning(role, lock, front);
3952
+ if (root !== void 0) warnings.push(root);
3953
+ if (eyeRole !== void 0 && eye !== void 0) {
3954
+ const w = eyeCornerWarning(role, lock, side, eyeRole, eye);
3955
+ if (w !== void 0) warnings.push(w);
3956
+ }
3957
+ const rowEye = eye ?? layers.eye_L ?? layers.eye_R;
3958
+ if (face !== void 0 && rowEye !== void 0) {
3959
+ const w = leanWarning(role, lock, side, face, back, rowEye);
3960
+ if (w !== void 0) warnings.push(w);
3961
+ }
3962
+ }
3963
+ if (drawsTwoLocks(locks.get("hair_side_R") ?? locks.get(present[0]))) {
3964
+ warnings.push(
3965
+ `hair_side.png draws two locks \u2014 draw ONE lock, the screen-left one; the composer mirrors it into hair_side_L. Billed.`
3966
+ );
3967
+ }
3968
+ return warnings;
3969
+ }
3970
+ function rootWarning(role, lock, front) {
3971
+ const y = opaqueRows(lock)?.top;
3972
+ if (y === void 0) return void 0;
3973
+ const frontRuns = runsAt(front, y);
3974
+ const lockRuns = runsAt(lock, y);
3975
+ let shown = 0;
3976
+ for (let i = 0; i + 1 < lockRuns.length; i += 2) {
3977
+ let stretch = 0;
3978
+ for (let x = lockRuns[i]; x <= lockRuns[i + 1]; x++) {
3979
+ if (x < lockRuns[i + 1] && !covers(frontRuns, x)) {
3980
+ stretch++;
3981
+ continue;
3982
+ }
3983
+ if (stretch >= VISIBLE_MIN_PX) shown += stretch;
3984
+ stretch = 0;
3985
+ }
3986
+ }
3987
+ if (shown === 0) return void 0;
3988
+ return `${role}: its top row (canvas y ${y}) shows past hair_front on ${shown} px \u2014 the root is visible at rest. Move it under the bangs \u2014 up (layout.${role}.cy) or toward the face (layout.${role}.cx) (free), or regenerate hair_side.png with a longer hidden root. Billed.`;
3989
+ }
3990
+ function eyeCornerWarning(role, lock, side, eyeRole, eye) {
3991
+ const row = Math.floor(eye.bboxCy);
3992
+ const corner = side < 0 ? eye.marginLeft : eye.marginLeft + eye.w - 1;
3993
+ const runs = runsAt(lock, row);
3994
+ let overlap = 0;
3995
+ for (let i = 0; i + 1 < runs.length; i += 2) {
3996
+ if (corner < runs[i] || corner >= runs[i + 1]) continue;
3997
+ overlap = side < 0 ? runs[i + 1] - corner : corner - runs[i] + 1;
3998
+ }
3999
+ if (overlap < VISIBLE_MIN_PX) return void 0;
4000
+ return `${role}: covers ${eyeRole}'s outer corner at rest (canvas x ${corner}, y ${row}) by ${overlap} px \u2014 the eye's outer tail may only slide under it on the turn. Move layout.${role}.cx ${overlap} px ${side < 0 ? "left" : "right"}, outward (free), or regenerate it narrower. Billed.`;
4001
+ }
4002
+ function leanWarning(role, lock, side, face, back, eye) {
4003
+ const faceRows = opaqueRows(face);
4004
+ const lockRows = opaqueRows(lock);
4005
+ if (faceRows === void 0 || lockRows === void 0) return void 0;
4006
+ const faceBottom = faceRows.bottom;
4007
+ const lean = Math.round(LEAN_HH * (faceBottom - Math.floor(eye.bboxCy)));
4008
+ if (lean < 1) return void 0;
4009
+ const bare = /* @__PURE__ */ new Set();
4010
+ const rows = /* @__PURE__ */ new Set();
4011
+ for (let y = lockRows.top; y <= Math.min(lockRows.bottom, faceBottom); y++) {
4012
+ const runs = runsAt(lock, y);
4013
+ if (runs.length === 0) continue;
4014
+ const from = side < 0 ? runs[0] : runs[runs.length - 2];
4015
+ const to = side < 0 ? runs[1] : runs[runs.length - 1];
4016
+ const start = side < 0 ? from : Math.max(from, to - lean);
4017
+ const end = side < 0 ? Math.min(to, from + lean) : to;
4018
+ const faceRuns = runsAt(face, y);
4019
+ const backRuns = runsAt(back, y);
4020
+ for (let x = start; x < end; x++) {
4021
+ if (covers(faceRuns, x) || covers(backRuns, x)) continue;
4022
+ bare.add(x);
4023
+ rows.add(y);
4024
+ }
4025
+ }
4026
+ if (bare.size === 0) return void 0;
4027
+ const cols = [...bare].sort((a, b) => a - b);
4028
+ const ys = [...rows].sort((a, b) => a - b);
4029
+ const where = `leaves bare pixels spanning columns ${cols[0]}\u2013${cols[cols.length - 1]}, rows ${ys[0]}\u2013${ys[ys.length - 1]}`;
4030
+ const lead = `${role}: when the head turns away from it the lock leans inward about ${lean} px and ${where}, where`;
4031
+ if (back === void 0) {
4032
+ return `${lead} the face is not painted \u2014 draw hair_back.png behind the locks. Billed.`;
4033
+ }
4034
+ return `${lead} neither hair_back nor the face is painted \u2014 widen hair_back there (layout.hair_back.w) (free), or regenerate it fuller behind the locks. Billed.`;
4035
+ }
4036
+ function drawsTwoLocks(lock) {
4037
+ const w = lock.bbox.w;
4038
+ const col = new Array(w).fill(false);
4039
+ for (const runs of lock.rowRuns ?? []) {
4040
+ for (let i = 0; i + 1 < runs.length; i += 2) {
4041
+ for (let x = runs[i]; x < runs[i + 1]; x++) col[x - lock.bbox.x] = true;
4042
+ }
4043
+ }
4044
+ const big = [];
4045
+ let start = -1;
4046
+ for (let x = 0; x <= w; x++) {
4047
+ if (x < w && col[x]) {
4048
+ if (start < 0) start = x;
4049
+ } else if (start >= 0) {
4050
+ if (x - start >= TWO_LOCKS_RUN * w) big.push([start, x]);
4051
+ start = -1;
4052
+ }
4053
+ }
4054
+ for (let i = 1; i < big.length; i++) {
4055
+ if (big[i][0] - big[i - 1][1] >= TWO_LOCKS_GAP * w) return true;
4056
+ }
4057
+ return false;
4058
+ }
4059
+
4060
+ // src/measure-forearm-pose.ts
4061
+ var import_editor7 = require("@ikijs/editor");
3637
4062
  var POSE_ROLES = ["forearm_pose_L", "forearm_pose_R"];
3638
4063
  var ARM_OF = {
3639
4064
  forearm_pose_L: "arm_L",
@@ -3667,7 +4092,7 @@ async function forearmPoseWarnings(absDir, layers) {
3667
4092
  continue;
3668
4093
  }
3669
4094
  if (layers.body === void 0) continue;
3670
- const measurer = (0, import_editor6.createLayerSetMeasurer)({
4095
+ const measurer = (0, import_editor7.createLayerSetMeasurer)({
3671
4096
  width: stats.canvasW,
3672
4097
  height: stats.canvasH
3673
4098
  });
@@ -3675,12 +4100,12 @@ async function forearmPoseWarnings(absDir, layers) {
3675
4100
  let armLayer;
3676
4101
  try {
3677
4102
  armLayer = await measured(measurer, absDir, arm);
3678
- a = (0, import_editor6.armGeometry)(armLayer, arm === "arm_R" ? Infinity : -Infinity);
4103
+ a = (0, import_editor7.armGeometry)(armLayer, arm === "arm_R" ? Infinity : -Infinity);
3679
4104
  } catch (err) {
3680
- if (err instanceof import_editor6.LayerGeometryError) continue;
4105
+ if (err instanceof import_editor7.LayerGeometryError) continue;
3681
4106
  throw err;
3682
4107
  }
3683
- const b = (0, import_editor6.forearmPoseGeometry)(await measured(measurer, absDir, pose));
4108
+ const b = (0, import_editor7.forearmPoseGeometry)(await measured(measurer, absDir, pose));
3684
4109
  warnings.push(...jointWarnings(pose, arm, stats, a, armLayer, b));
3685
4110
  }
3686
4111
  return warnings;
@@ -3720,11 +4145,11 @@ function jointWarnings(pose, arm, stats, a, armLayer, b) {
3720
4145
 
3721
4146
  // src/measure-lips.ts
3722
4147
  var import_node_path7 = __toESM(require("path"));
3723
- var import_editor8 = require("@ikijs/editor");
4148
+ var import_editor9 = require("@ikijs/editor");
3724
4149
 
3725
4150
  // src/compose-lips.ts
3726
4151
  var import_sharp2 = __toESM(require("sharp"));
3727
- var import_editor7 = require("@ikijs/editor");
4152
+ var import_editor8 = require("@ikijs/editor");
3728
4153
  var KEYED_SRC = "mouth_keyed.png";
3729
4154
  var INTERIOR_SRC = "mouth_interior.png";
3730
4155
  var KEY_CANDIDATE = 0.5;
@@ -3822,7 +4247,7 @@ function keyGreen(rgba, W, H) {
3822
4247
  let candidates = 0;
3823
4248
  for (let p = 0; p < n; p++) {
3824
4249
  const i = p * 4;
3825
- if (rgba[i + 3] < import_editor7.ALPHA_OPAQUE) continue;
4250
+ if (rgba[i + 3] < import_editor8.ALPHA_OPAQUE) continue;
3826
4251
  const excess = (rgba[i + 1] - Math.max(rgba[i], rgba[i + 2])) / 255;
3827
4252
  if (excess < KEY_CANDIDATE) continue;
3828
4253
  candidates++;
@@ -3849,7 +4274,7 @@ function keyGreen(rgba, W, H) {
3849
4274
  const dg = rgba[i + 1] - G[1];
3850
4275
  const db = rgba[i + 2] - G[2];
3851
4276
  const green = dr * dr + dg * dg + db * db <= KEY_FILL_DIST * KEY_FILL_DIST;
3852
- if (rgba[i + 3] < import_editor7.ALPHA_OPAQUE) {
4277
+ if (rgba[i + 3] < import_editor8.ALPHA_OPAQUE) {
3853
4278
  if (green) out[i + 3] = 0;
3854
4279
  } else if (green) {
3855
4280
  fill[p] = 1;
@@ -4025,7 +4450,7 @@ async function prepInterior(rgba, W, H) {
4025
4450
  for (let y = box2.y; y < box2.y + box2.h; y++) {
4026
4451
  for (let x = box2.x; x < box2.x + box2.w; x++) {
4027
4452
  const i = (y * cw + x) * 4;
4028
- if (crop[i + 3] < import_editor7.ALPHA_OPAQUE) continue;
4453
+ if (crop[i + 3] < import_editor8.ALPHA_OPAQUE) continue;
4029
4454
  count++;
4030
4455
  for (let c = 0; c < 3; c++) all[c] += crop[i + c];
4031
4456
  if (luma(crop, i) < CAVITY_LUMA) {
@@ -4048,7 +4473,7 @@ function enclosedHole(frame, w, h) {
4048
4473
  const stack = new Int32Array(n);
4049
4474
  let depth = 0;
4050
4475
  const seed = (p) => {
4051
- if (!outside[p] && alpha(p) < import_editor7.ALPHA_OPAQUE) {
4476
+ if (!outside[p] && alpha(p) < import_editor8.ALPHA_OPAQUE) {
4052
4477
  outside[p] = 1;
4053
4478
  stack[depth++] = p;
4054
4479
  }
@@ -4071,7 +4496,7 @@ function enclosedHole(frame, w, h) {
4071
4496
  }
4072
4497
  const mask = new Uint8Array(n);
4073
4498
  for (let p = 0; p < n; p++) {
4074
- if (alpha(p) < import_editor7.ALPHA_OPAQUE && !outside[p]) mask[p] = 1;
4499
+ if (alpha(p) < import_editor8.ALPHA_OPAQUE && !outside[p]) mask[p] = 1;
4075
4500
  }
4076
4501
  const { label, sizes, boxes } = components(mask, w, h);
4077
4502
  const main = largest(sizes);
@@ -4098,7 +4523,7 @@ function enclosedHole(frame, w, h) {
4098
4523
  return { label, main, box: box2 };
4099
4524
  }
4100
4525
  function measureLips(layers, w, h) {
4101
- const measurer = (0, import_editor7.createLayerSetMeasurer)({ width: w, height: h });
4526
+ const measurer = (0, import_editor8.createLayerSetMeasurer)({ width: w, height: h });
4102
4527
  return new Map(
4103
4528
  Object.entries(layers).map(([role, rgba]) => [
4104
4529
  role,
@@ -4116,8 +4541,8 @@ function assertFoldContract(layers, w, h) {
4116
4541
  }
4117
4542
  byRole.set(role, layer);
4118
4543
  }
4119
- const opening = (0, import_editor7.mouthOpening)(byRole);
4120
- const runs = (0, import_editor7.columnRuns)(byRole.get("mouth_inner"));
4544
+ const opening = (0, import_editor8.mouthOpening)(byRole);
4545
+ const runs = (0, import_editor8.columnRuns)(byRole.get("mouth_inner"));
4121
4546
  for (let col = opening.x0; col <= opening.x1; col++) {
4122
4547
  const c = opening.at(col);
4123
4548
  const why = !runs.has(col) ? "has no interior run" : c.Tu > c.T ? `has a gap between the line and the interior (Tu ${c.Tu} > T ${c.T})` : c.T > c.lineTop || c.lineH <= 0 ? `has no line above the interior (T ${c.T}, line top ${c.lineTop})` : c.Bl < c.Bb ? `has a gap between the interior and the skin (Bl ${c.Bl} < Bb ${c.Bb})` : null;
@@ -4147,18 +4572,18 @@ async function splitLipSet(keyedPng, w, h, interior) {
4147
4572
  }
4148
4573
  const centre = Math.round((hb.x0 + hb.x1) / 2);
4149
4574
  let stroke = 0;
4150
- while (top[centre] - 1 - stroke >= 0 && alpha((top[centre] - 1 - stroke) * w + centre) >= import_editor7.ALPHA_OPAQUE)
4575
+ while (top[centre] - 1 - stroke >= 0 && alpha((top[centre] - 1 - stroke) * w + centre) >= import_editor8.ALPHA_OPAQUE)
4151
4576
  stroke++;
4152
4577
  const bandCap = BAND_CAP * Math.max(1, stroke);
4153
4578
  const skinRow = new Int32Array(w).fill(-1);
4154
4579
  const inM = new Uint8Array(n);
4155
4580
  for (let x = hb.x0; x <= hb.x1; x++) {
4156
4581
  let y = bot[x];
4157
- while (y < h && y - bot[x] < bandCap && alpha(y * w + x) >= import_editor7.ALPHA_OPAQUE && luma(frame, (y * w + x) * 4) < BAND_LUMA)
4582
+ while (y < h && y - bot[x] < bandCap && alpha(y * w + x) >= import_editor8.ALPHA_OPAQUE && luma(frame, (y * w + x) * 4) < BAND_LUMA)
4158
4583
  y++;
4159
4584
  for (let k = top[x]; k < y; k++) inM[k * w + x] = 1;
4160
4585
  let r = y;
4161
- while (r < h && alpha(r * w + x) < import_editor7.ALPHA_OPAQUE) r++;
4586
+ while (r < h && alpha(r * w + x) < import_editor8.ALPHA_OPAQUE) r++;
4162
4587
  if (r < h) {
4163
4588
  skinRow[x] = r;
4164
4589
  inM[r * w + x] = 1;
@@ -4168,7 +4593,7 @@ async function splitLipSet(keyedPng, w, h, interior) {
4168
4593
  for (let y = 0; y < h; y++) {
4169
4594
  for (let x = 0; x < w; x++) {
4170
4595
  const p = y * w + x;
4171
- if (inM[p] || alpha(p) < import_editor7.ALPHA_OPAQUE) continue;
4596
+ if (inM[p] || alpha(p) < import_editor8.ALPHA_OPAQUE) continue;
4172
4597
  if (top[x] >= 0 && y < top[x]) continue;
4173
4598
  if (x > 0 && inM[p - 1] || x < w - 1 && inM[p + 1]) grown[p] = 1;
4174
4599
  }
@@ -4178,7 +4603,7 @@ async function splitLipSet(keyedPng, w, h, interior) {
4178
4603
  if (x < 0 || x >= w) continue;
4179
4604
  let first = 0;
4180
4605
  while (first < h && !(grown[first * w + x] && !inM[first * w + x])) first++;
4181
- if (first > 0 && first < h && alpha((first - 1) * w + x) >= import_editor7.ALPHA_OPAQUE)
4606
+ if (first > 0 && first < h && alpha((first - 1) * w + x) >= import_editor8.ALPHA_OPAQUE)
4182
4607
  wall[x] = 1;
4183
4608
  }
4184
4609
  const gx = hb.x0 - 1;
@@ -4205,7 +4630,7 @@ async function splitLipSet(keyedPng, w, h, interior) {
4205
4630
  if (inOpening && skinRow[x] >= 0 && y >= skinRow[x]) copy(lower, p);
4206
4631
  if (!grown[p]) {
4207
4632
  const a = alpha(p);
4208
- if (a >= import_editor7.ALPHA_OPAQUE && a < 255 && besideHole(p, x, y)) {
4633
+ if (a >= import_editor8.ALPHA_OPAQUE && a < 255 && besideHole(p, x, y)) {
4209
4634
  inner.set(interior.cavity, p * 4);
4210
4635
  inner[p * 4 + 3] = 255 - a;
4211
4636
  }
@@ -4270,7 +4695,7 @@ async function restShiftOf(layers, width, height) {
4270
4695
  }
4271
4696
  byRole.set(role, layer);
4272
4697
  }
4273
- return (0, import_editor7.mouthRestShift)(byRole);
4698
+ return (0, import_editor8.mouthRestShift)(byRole);
4274
4699
  }
4275
4700
  async function closedLips(upper, lower, shift, left, top) {
4276
4701
  const shut = async (png, role) => {
@@ -4320,7 +4745,7 @@ async function closedLips(upper, lower, shift, left, top) {
4320
4745
  }
4321
4746
 
4322
4747
  // src/measure-lips.ts
4323
- var isLipLayerRole = (role) => import_editor8.LIP_ROLES.includes(role) || (0, import_editor8.isLipInsideRole)(role);
4748
+ var isLipLayerRole = (role) => import_editor9.LIP_ROLES.includes(role) || (0, import_editor9.isLipInsideRole)(role);
4324
4749
  var MIN_OPENING_ROWS = 8;
4325
4750
  var MIN_LINE_ROWS = 2;
4326
4751
  var GREEN_EXCESS = 40;
@@ -4328,8 +4753,8 @@ var INTERIOR_GAP_FRACTION = 0.05;
4328
4753
  var columns = (cols) => `${cols.length} column${cols.length === 1 ? "" : "s"} (first at x=${cols[0]})`;
4329
4754
  async function lipWarnings(absDir, layers) {
4330
4755
  const warnings = [];
4331
- const present = import_editor8.LIP_ROLES.filter((role) => layers[role] !== void 0);
4332
- const inside = import_editor8.LIP_INSIDE_ROLES.filter((role) => layers[role] !== void 0);
4756
+ const present = import_editor9.LIP_ROLES.filter((role) => layers[role] !== void 0);
4757
+ const inside = import_editor9.LIP_INSIDE_ROLES.filter((role) => layers[role] !== void 0);
4333
4758
  if (present.length === 0) {
4334
4759
  if (inside.length > 0) {
4335
4760
  warnings.push(
@@ -4346,8 +4771,8 @@ async function lipWarnings(absDir, layers) {
4346
4771
  `${present.join("/")}: the lip set cannot be mixed with ${legacy.join("/")} \u2014 auto_rig_from_layers refuses it. Remove one route: compose again with only mouth_keyed.png + mouth_interior.png, or without them.`
4347
4772
  );
4348
4773
  }
4349
- if (present.length < import_editor8.LIP_ROLES.length) {
4350
- const missing = import_editor8.LIP_ROLES.filter((role) => layers[role] === void 0);
4774
+ if (present.length < import_editor9.LIP_ROLES.length) {
4775
+ const missing = import_editor9.LIP_ROLES.filter((role) => layers[role] === void 0);
4351
4776
  warnings.push(
4352
4777
  `${present.join("/")}: partial lip set, missing ${missing.join("/")} \u2014 auto_rig_from_layers refuses it. Compose mouth_keyed.png + mouth_interior.png together, which cuts all three.`
4353
4778
  );
@@ -4378,18 +4803,18 @@ async function lipWarnings(absDir, layers) {
4378
4803
  );
4379
4804
  }
4380
4805
  }
4381
- const measurer = (0, import_editor8.createLayerSetMeasurer)({
4806
+ const measurer = (0, import_editor9.createLayerSetMeasurer)({
4382
4807
  width: inner.canvasW,
4383
4808
  height: inner.canvasH
4384
4809
  });
4385
4810
  const set = /* @__PURE__ */ new Map();
4386
4811
  const green = [];
4387
- for (const role of import_editor8.LIP_ROLES) {
4812
+ for (const role of import_editor9.LIP_ROLES) {
4388
4813
  const fileName = `${role}.png`;
4389
4814
  const { rgba } = await decodePng(import_node_path7.default.join(absDir, fileName));
4390
4815
  set.set(role, measurer.add({ role, fileName, rgba }));
4391
4816
  for (let i = 0; i < rgba.length; i += 4) {
4392
- if (rgba[i + 3] >= import_editor8.ALPHA_OPAQUE && rgba[i + 1] - Math.max(rgba[i], rgba[i + 2]) > GREEN_EXCESS) {
4817
+ if (rgba[i + 3] >= import_editor9.ALPHA_OPAQUE && rgba[i + 1] - Math.max(rgba[i], rgba[i + 2]) > GREEN_EXCESS) {
4393
4818
  green.push(role);
4394
4819
  break;
4395
4820
  }
@@ -4397,15 +4822,15 @@ async function lipWarnings(absDir, layers) {
4397
4822
  }
4398
4823
  let opening;
4399
4824
  try {
4400
- opening = (0, import_editor8.mouthOpening)(set);
4825
+ opening = (0, import_editor9.mouthOpening)(set);
4401
4826
  } catch (err) {
4402
- if (err instanceof import_editor8.LayerGeometryError) {
4827
+ if (err instanceof import_editor9.LayerGeometryError) {
4403
4828
  warnings.push(err.message);
4404
4829
  return { warnings };
4405
4830
  }
4406
4831
  throw err;
4407
4832
  }
4408
- const innerRuns = (0, import_editor8.columnRuns)(set.get("mouth_inner"));
4833
+ const innerRuns = (0, import_editor9.columnRuns)(set.get("mouth_inner"));
4409
4834
  const noInterior = [];
4410
4835
  const gap = [];
4411
4836
  const noLine = [];
@@ -4491,8 +4916,8 @@ async function lipWarnings(absDir, layers) {
4491
4916
 
4492
4917
  // src/measure-turn.ts
4493
4918
  var import_node_path8 = __toESM(require("path"));
4494
- var import_editor9 = require("@ikijs/editor");
4495
4919
  var import_editor10 = require("@ikijs/editor");
4920
+ var import_editor11 = require("@ikijs/editor");
4496
4921
  var DEFAULT_IRIS = { hueMin: 230, hueMax: 300, satMin: 0.22 };
4497
4922
  var IRIS_V_MIN = 0.18;
4498
4923
  var IRIS_V_MAX = 0.95;
@@ -4642,7 +5067,7 @@ async function measureTurnImage(filePath, iris) {
4642
5067
  let transparent = false;
4643
5068
  if (hasAlpha) {
4644
5069
  for (let i = 0; i < n; i++) {
4645
- if (rgba[i * 4 + 3] < import_editor9.ALPHA_OPAQUE) {
5070
+ if (rgba[i * 4 + 3] < import_editor10.ALPHA_OPAQUE) {
4646
5071
  transparent = true;
4647
5072
  break;
4648
5073
  }
@@ -4653,7 +5078,7 @@ async function measureTurnImage(filePath, iris) {
4653
5078
  const fg = new Uint8Array(n);
4654
5079
  const value = new Float32Array(n);
4655
5080
  for (let i = 0; i < n; i++) {
4656
- if (rgba[i * 4 + 3] < import_editor9.ALPHA_OPAQUE) continue;
5081
+ if (rgba[i * 4 + 3] < import_editor10.ALPHA_OPAQUE) continue;
4657
5082
  const [hue, s, v] = rgbToHsv(rgba[i * 4], rgba[i * 4 + 1], rgba[i * 4 + 2]);
4658
5083
  if (maskMode === "alpha") {
4659
5084
  fg[i] = 1;
@@ -4719,12 +5144,12 @@ async function measureTurnImage(filePath, iris) {
4719
5144
  }
4720
5145
  const [irisL, irisR] = best.pair;
4721
5146
  const eyeRow = Math.round((irisL.cy + irisR.cy) / 2);
4722
- const { left, right } = (0, import_editor9.foregroundSpan)(
5147
+ const { left, right } = (0, import_editor10.foregroundSpan)(
4723
5148
  fg,
4724
5149
  width,
4725
5150
  height,
4726
- eyeRow - import_editor9.HEAD_BAND,
4727
- eyeRow + import_editor9.HEAD_BAND
5151
+ eyeRow - import_editor10.HEAD_BAND,
5152
+ eyeRow + import_editor10.HEAD_BAND
4728
5153
  );
4729
5154
  if (right <= left) {
4730
5155
  throw new AutoRigInputError(
@@ -4748,7 +5173,7 @@ async function measureTurnImage(filePath, iris) {
4748
5173
  left,
4749
5174
  right,
4750
5175
  cx: (left + right) / 2,
4751
- half: (0, import_editor9.headHalfOf)({ left, right })
5176
+ half: (0, import_editor10.headHalfOf)({ left, right })
4752
5177
  },
4753
5178
  pairCx: (irisL.cx + irisR.cx) / 2,
4754
5179
  eyeGap: irisR.cx - irisL.cx
@@ -4939,7 +5364,7 @@ function noseSpeckWarning({ core, part }, source) {
4939
5364
  `the layer's dense core is ${core.w}x${core.h} in its ${part.w}x${part.h} crop`,
4940
5365
  `auto_rig_from_layers turns and tilts the nose about its whole crop instead`
4941
5366
  ];
4942
- return `nose: ${found} \u2014 under ${import_editor10.SPECK_CORE_FRACTION} of its width or height, a speck: a lone nostril mark or highlight at alpha >= 128, not the drawing, so ${consequence}. Regenerate the nose with its shading painted denser, so the drawing itself reaches alpha 128. Billed.`;
5367
+ return `nose: ${found} \u2014 under ${import_editor11.SPECK_CORE_FRACTION} of its width or height, a speck: a lone nostril mark or highlight at alpha >= 128, not the drawing, so ${consequence}. Regenerate the nose with its shading painted denser, so the drawing itself reaches alpha 128. Billed.`;
4943
5368
  }
4944
5369
  async function lashOffSclera(eyePath, lashPath) {
4945
5370
  const eye = await decodePng(eyePath);
@@ -5020,6 +5445,7 @@ async function measureDir(absDir, noseSpeck) {
5020
5445
  warnings.push(...await forearmPoseWarnings(absDir, layers));
5021
5446
  const lip = await lipWarnings(absDir, layers);
5022
5447
  warnings.push(...lip.warnings);
5448
+ warnings.push(...await hairSideWarnings(absDir, layers));
5023
5449
  for (const side of ["L", "R"]) {
5024
5450
  const eye = layers[`eye_${side}`];
5025
5451
  const iris = layers[`iris_${side}`];
@@ -5076,10 +5502,10 @@ async function measureDir(absDir, noseSpeck) {
5076
5502
  warnings.push(noseSpeckWarning(noseSpeck, "compose"));
5077
5503
  } else if (layers.nose !== void 0) {
5078
5504
  const nose = await decodePng(import_node_path9.default.join(absDir, "nose.png"));
5079
- const core = (0, import_editor10.denseCoreOf)(nose.rgba, nose.width, nose.height);
5505
+ const core = (0, import_editor11.denseCoreOf)(nose.rgba, nose.width, nose.height);
5080
5506
  if (core !== null) {
5081
5507
  const crop = detectAlphaBbox(nose.rgba, nose.width, nose.height);
5082
- if ((0, import_editor10.isSpeckCore)(core, crop))
5508
+ if ((0, import_editor11.isSpeckCore)(core, crop))
5083
5509
  warnings.push(noseSpeckWarning({ core, part: crop }, "layer"));
5084
5510
  }
5085
5511
  }
@@ -5150,12 +5576,12 @@ function formatMeasureReport(result) {
5150
5576
 
5151
5577
  // src/compose-arms.ts
5152
5578
  var import_sharp3 = __toESM(require("sharp"));
5153
- var import_editor11 = require("@ikijs/editor");
5579
+ var import_editor12 = require("@ikijs/editor");
5154
5580
  var ARM_WIDTH = 0.4;
5155
5581
  var SHOULDER_DROP = 0.12;
5156
5582
  async function armPlacement(role, cfg, part, body) {
5157
5583
  const { data } = await (0, import_sharp3.default)(part.buf).ensureAlpha().raw().toBuffer({ resolveWithObject: true });
5158
- const layer = (0, import_editor11.createLayerSetMeasurer)({ width: part.w, height: part.h }).add({
5584
+ const layer = (0, import_editor12.createLayerSetMeasurer)({ width: part.w, height: part.h }).add({
5159
5585
  role,
5160
5586
  fileName: "arm.png",
5161
5587
  rgba: data
@@ -5167,9 +5593,9 @@ async function armPlacement(role, cfg, part, body) {
5167
5593
  }
5168
5594
  let g;
5169
5595
  try {
5170
- g = (0, import_editor11.armGeometry)(layer, role === "arm_R" ? Infinity : -Infinity);
5596
+ g = (0, import_editor12.armGeometry)(layer, role === "arm_R" ? Infinity : -Infinity);
5171
5597
  } catch (err) {
5172
- if (err instanceof import_editor11.LayerGeometryError) {
5598
+ if (err instanceof import_editor12.LayerGeometryError) {
5173
5599
  throw new AutoRigInputError(`layout.${role}: ${err.message}`);
5174
5600
  }
5175
5601
  throw err;
@@ -5196,7 +5622,7 @@ async function armPlacement(role, cfg, part, body) {
5196
5622
  }
5197
5623
  async function poseGeometryOf(role, png, size, when) {
5198
5624
  const { data } = await (0, import_sharp3.default)(png).ensureAlpha().raw().toBuffer({ resolveWithObject: true });
5199
- const layer = (0, import_editor11.createLayerSetMeasurer)({
5625
+ const layer = (0, import_editor12.createLayerSetMeasurer)({
5200
5626
  width: size.w,
5201
5627
  height: size.h
5202
5628
  }).add({ role, fileName: "forearm_pose.png", rgba: data });
@@ -5205,7 +5631,7 @@ async function poseGeometryOf(role, png, size, when) {
5205
5631
  `layout.${role}: forearm_pose.png is empty after alpha threshold${when}`
5206
5632
  );
5207
5633
  }
5208
- return (0, import_editor11.forearmPoseGeometry)(layer);
5634
+ return (0, import_editor12.forearmPoseGeometry)(layer);
5209
5635
  }
5210
5636
  async function forearmPoseWidth(role, trimmed, elbowRun) {
5211
5637
  const g = await poseGeometryOf(role, trimmed.data, trimmed, "");
@@ -5322,6 +5748,23 @@ var DEFAULT_LAYOUT = {
5322
5748
  // prettier-ignore
5323
5749
  brow_L: { src: "brow.png", cx: 645, cy: 405, w: 105, mirror: false },
5324
5750
  brow_R: { src: "brow.png", cx: 455, cy: 405, w: 105, mirror: true },
5751
+ // The front side locks, one part for both: hair_side_R (screen left) takes
5752
+ // hair_side.png as drawn and hair_side_L mirrors it, like the blush. They
5753
+ // draw over the face, brows and lashes and under the bangs. Mint's tuned
5754
+ // placement (cy 545 at mint's face cy 431, carried to the default face:
5755
+ // 437 + 114 = 551), tuned per character through `layout.hair_side_*`: the
5756
+ // lock's root top lies above the brow row (405) so the bangs' temple hides it
5757
+ // (for a 1:5 lock, whose height follows the image's aspect: w 90 is 450 tall,
5758
+ // so cy 551 puts the top at 326), and the lock runs from the temple over the
5759
+ // front of the ear and down along the cheek's edge, the ear's rim and lobe
5760
+ // showing beside it. Its box overlaps the eye's by about 15 px at the
5761
+ // default face, fine only because a drawn lock's root tapers (the measure's "covers
5762
+ // the eye's outer corner" check catches a lock that does not).
5763
+ // OPTIONAL: a parts dir without it composes.
5764
+ hair_side_L: { src: "hair_side.png", cx: 715, cy: 551, w: 90, optional: true, mirror: true },
5765
+ // prettier-ignore
5766
+ hair_side_R: { src: "hair_side.png", cx: 385, cy: 551, w: 90, optional: true, mirror: false },
5767
+ // prettier-ignore
5325
5768
  hair_front: { src: "hair_front.png", cx: 550, cy: 425, w: 660 },
5326
5769
  // The pose forearms, one drawing for both: forearm_pose_R (screen left)
5327
5770
  // takes forearm_pose.png as drawn and forearm_pose_L mirrors it, like the
@@ -5360,6 +5803,8 @@ var ORDER = [
5360
5803
  "lash_R",
5361
5804
  "brow_L",
5362
5805
  "brow_R",
5806
+ "hair_side_L",
5807
+ "hair_side_R",
5363
5808
  "hair_front",
5364
5809
  "forearm_pose_L",
5365
5810
  "forearm_pose_R"
@@ -5384,7 +5829,9 @@ var FACE_FEATURES = [
5384
5829
  "lash_L",
5385
5830
  "lash_R",
5386
5831
  "brow_L",
5387
- "brow_R"
5832
+ "brow_R",
5833
+ "hair_side_L",
5834
+ "hair_side_R"
5388
5835
  ];
5389
5836
  function resolveLayout(overrides, canvas) {
5390
5837
  const resolved = { ...DEFAULT_LAYOUT };
@@ -5482,18 +5929,18 @@ function keyWhiteToAlpha(rgba) {
5482
5929
  async function coreAndBoundsOf(png) {
5483
5930
  const { data, info } = await (0, import_sharp4.default)(png).ensureAlpha().raw().toBuffer({ resolveWithObject: true });
5484
5931
  return {
5485
- core: (0, import_editor10.denseCoreOf)(data, info.width, info.height),
5932
+ core: (0, import_editor11.denseCoreOf)(data, info.width, info.height),
5486
5933
  bounds: { x: 0, y: 0, w: info.width, h: info.height }
5487
5934
  };
5488
5935
  }
5489
5936
  async function hasCoverage(png) {
5490
5937
  const { data, info } = await (0, import_sharp4.default)(png).ensureAlpha().raw().toBuffer({ resolveWithObject: true });
5491
- return (0, import_editor12.detectAlphaBbox)(data, info.width, info.height) !== null;
5938
+ return (0, import_editor13.detectAlphaBbox)(data, info.width, info.height) !== null;
5492
5939
  }
5493
5940
  async function noseSizingOf(png) {
5494
5941
  const { core, bounds } = await coreAndBoundsOf(png);
5495
5942
  if (core === null) return { box: bounds, whole: true };
5496
- if ((0, import_editor10.isSpeckCore)(core, bounds)) {
5943
+ if ((0, import_editor11.isSpeckCore)(core, bounds)) {
5497
5944
  return {
5498
5945
  box: bounds,
5499
5946
  whole: true,
@@ -5615,7 +6062,7 @@ function detachedAboveWhite(rgba, W, H) {
5615
6062
  for (let p = 0; p < n; p++) {
5616
6063
  const alpha = rgba[p * 4 + 3];
5617
6064
  if (alpha > 0 && luma(rgba, p * 4) >= EYE_LASH_LUMA)
5618
- ink[p] = alpha >= import_editor12.ALPHA_OPAQUE ? 2 : 1;
6065
+ ink[p] = alpha >= import_editor13.ALPHA_OPAQUE ? 2 : 1;
5619
6066
  }
5620
6067
  const label = new Int32Array(n).fill(-1);
5621
6068
  const stack = new Int32Array(n);
@@ -5720,7 +6167,7 @@ async function prepEyeSplit(partsDir) {
5720
6167
  const lashCutoffY = minY + LASH_KEEP_FRACTION * (maxY - minY + 1);
5721
6168
  const detached = detachedAboveWhite(data, W, H);
5722
6169
  const isDark = (i) => data[i + 3] > 0 && luma(data, i) < EYE_LASH_LUMA;
5723
- const isLight = (i) => data[i + 3] >= import_editor12.ALPHA_OPAQUE && luma(data, i) >= EYE_LASH_LUMA;
6170
+ const isLight = (i) => data[i + 3] >= import_editor13.ALPHA_OPAQUE && luma(data, i) >= EYE_LASH_LUMA;
5724
6171
  const isWarm = (i) => data[i] - data[i + 2] >= EYE_LID_WARMTH;
5725
6172
  const whiteTop = new Int32Array(W).fill(-1);
5726
6173
  for (let x = 0; x < W; x++) {
@@ -5890,7 +6337,7 @@ async function composeLayersFromParts(input) {
5890
6337
  lip_lower: split2.lower,
5891
6338
  lip_upper: split2.upper
5892
6339
  }[role];
5893
- if ((0, import_editor12.isLipInsideRole)(role) && !await hasCoverage(buf)) {
6340
+ if ((0, import_editor13.isLipInsideRole)(role) && !await hasCoverage(buf)) {
5894
6341
  skipped.push(role);
5895
6342
  continue;
5896
6343
  }
@@ -6085,7 +6532,7 @@ async function composeLayersFromParts(input) {
6085
6532
  });
6086
6533
  }
6087
6534
  const restInput = (role, buf) => {
6088
- if (role === "mouth_inner" || (0, import_editor12.isLipInsideRole)(role)) return null;
6535
+ if (role === "mouth_inner" || (0, import_editor13.isLipInsideRole)(role)) return null;
6089
6536
  if (closed === void 0) return buf;
6090
6537
  if (role === "lip_upper") return closed.upper;
6091
6538
  if (role === "lip_lower") return closed.lower;
@@ -6168,6 +6615,40 @@ function pxText(px2) {
6168
6615
  return (Math.floor(px2 * 10) / 10).toFixed(1);
6169
6616
  }
6170
6617
 
6618
+ // src/hair-side-report.ts
6619
+ function signedPx(px2) {
6620
+ const s = px2.toFixed(1);
6621
+ if (s === "-0.0") return "+0.0";
6622
+ return s.startsWith("-") ? s : `+${s}`;
6623
+ }
6624
+ function formatHairSideReport(hairSide, canvas) {
6625
+ if (hairSide === void 0) return [];
6626
+ return [hairSide.left, hairSide.right].flatMap(
6627
+ (room) => room === void 0 ? [] : roomLines(room, canvas)
6628
+ );
6629
+ }
6630
+ function roomLines(room, canvas) {
6631
+ const { role, cover, tail, unavailable } = room;
6632
+ if (unavailable !== void 0) {
6633
+ return [`HAIRSIDE ${role}: unavailable \u2014 ${unavailable}`];
6634
+ }
6635
+ const lines = [];
6636
+ if (cover !== void 0) {
6637
+ const row = Math.floor(canvas.height / 2 - cover.y);
6638
+ lines.push(
6639
+ `HAIRSIDE cover ${role}: the lock's outer edge ${signedPx(cover.px)} model px outside the head's edge at ParamAngleX=${cover.deg}, ${signedPx(cover.rest)} at rest (least over the rows it covers at rest, at model y ${cover.y.toFixed(1)}, row ${row} model px from the top; negative: the turn bares cheek the lock hides at rest)`
6640
+ );
6641
+ }
6642
+ if (tail !== void 0) {
6643
+ const lash = tail.lashToLock === void 0 ? "" : ` / lash ${signedPx(tail.lashToLock)} model px`;
6644
+ lines.push(
6645
+ `HAIRSIDE tail ${role}: eye ${signedPx(tail.eyeToLock)} model px${lash} from the lock's face-side edge at ParamAngleX=${tail.deg} (negative: under the lock, intended), corner ${signedPx(tail.eyeToPlate)} model px from the head's edge (positive: inside it; negative: past it)`
6646
+ );
6647
+ }
6648
+ if (lines.length === 0) lines.push(`HAIRSIDE ${role}: no cover or tail row`);
6649
+ return lines;
6650
+ }
6651
+
6171
6652
  // src/server.ts
6172
6653
  var import_mcp = require("@modelcontextprotocol/sdk/server/mcp.js");
6173
6654
  var import_zod = require("zod");
@@ -6179,7 +6660,7 @@ function formatPatchReports(reports) {
6179
6660
  });
6180
6661
  }
6181
6662
  function createIkiMcpServer() {
6182
- const server = new import_mcp.McpServer({ name: "iki", version: "0.31.1" });
6663
+ const server = new import_mcp.McpServer({ name: "iki", version: "0.33.0" });
6183
6664
  server.registerTool(
6184
6665
  "validate_iki",
6185
6666
  {
@@ -6271,7 +6752,7 @@ function createIkiMcpServer() {
6271
6752
  server.registerTool(
6272
6753
  "auto_rig_from_layers",
6273
6754
  {
6274
- description: "Auto-rigs role-named PNG layers (face, eye_L/eye_R and either mouth or the lip set (mouth_inner + lip_lower + lip_upper, a mouth that folds open instead of crossfading) required; iris_L/R, brow_L/R, hair_front, body, arm_L/arm_R, forearm_pose_L/forearm_pose_R, mouth_tongue/mouth_teeth (only with the lip set: drawn under its lips and clipped to mouth_inner), etc. optional; an arm needs the body, a pose forearm needs its arm, and a partial lip set, one mixed with mouth/mouth_open, or mouth_tongue/mouth_teeth without it is refused) into a renderable .iki written to disk. Pass full-canvas PNG file paths; returns the output path + summary (the model is NOT inlined). Filenames map to roles unless `fileName` is given. The result's `folds` is the written rig's fold report, printed after the path the way render_poses prints it, and report-only: a fold never refuses the rig. The `RIGPLAN:` line (the result's `rigPlan`: `effective`, `clamped`, `overriddenBy`) follows the path and precedes the `PATCH` lines. The `PHYSICS` lines follow the fold report (the result's `physics`), one per physics rig output \u2014 a spring's, or each chain segment's \u2014 reading ok, frozen or unstable with the step and idle amplitudes, or `PHYSICS: no rigs`; report-only too. `patches` (see its field) adds displacements to existing keyform stops of the freshly generated rig; each op then prints one line between the path and the fold report \u2014 `PATCH <i> <target> at <Param=v \u2026>: <moved> of <of> points (cols a-b, rows c-d), largest move <maxPx> model px`, with `(vertices)` in place of the columns and rows for a mesh part \u2014 and the result's `patches` carries the same reports (`index`, `target`, `at`, `moved`, `of`, `cols`/`rows` for a grid, `maxPx`), present whenever `patches` was passed, `[]` included. An op the input schema accepts but the rig refuses comes back as `INVALID: patches[i]\u2026` and nothing is written; an op with a missing field or a field of the wrong type is the SDK's input validation error.",
6755
+ description: "Auto-rigs role-named PNG layers (face, eye_L/eye_R and either mouth or the lip set (mouth_inner + lip_lower + lip_upper, a mouth that folds open instead of crossfading) required; iris_L/R, brow_L/R, hair_front, body, arm_L/arm_R, forearm_pose_L/forearm_pose_R, hair_side_L/hair_side_R, mouth_tongue/mouth_teeth (only with the lip set: drawn under its lips and clipped to mouth_inner), etc. optional; an arm needs the body, a pose forearm needs its arm, a side lock needs hair_front, and a partial lip set, one mixed with mouth/mouth_open, or mouth_tongue/mouth_teeth without it is refused) into a renderable .iki written to disk. Pass full-canvas PNG file paths; returns the output path + summary (the model is NOT inlined). Filenames map to roles unless `fileName` is given. The result's `folds` is the written rig's fold report, printed after the path the way render_poses prints it, and report-only: a fold never refuses the rig. The `RIGPLAN:` line (the result's `rigPlan`: `effective`, `clamped`, `overriddenBy`) follows the path and precedes the `PATCH` lines. The `PHYSICS` lines follow the fold report (the result's `physics`), one per physics rig output \u2014 a spring's, or each chain segment's \u2014 reading ok, frozen or unstable with the step and idle amplitudes, or `PHYSICS: no rigs`; report-only too. With side locks and a `nose` (which `turn` needs) the `HAIRSIDE` lines follow the `PHYSICS` lines (the result's `turn.hairSide`), each naming the lock's role, report-only as well. `patches` (see its field) adds displacements to existing keyform stops of the freshly generated rig; each op then prints one line between the path and the fold report \u2014 `PATCH <i> <target> at <Param=v \u2026>: <moved> of <of> points (cols a-b, rows c-d), largest move <maxPx> model px`, with `(vertices)` in place of the columns and rows for a mesh part \u2014 and the result's `patches` carries the same reports (`index`, `target`, `at`, `moved`, `of`, `cols`/`rows` for a grid, `maxPx`), present whenever `patches` was passed, `[]` included. An op the input schema accepts but the rig refuses comes back as `INVALID: patches[i]\u2026` and nothing is written; an op with a missing field or a field of the wrong type is the SDK's input validation error.",
6275
6756
  inputSchema: {
6276
6757
  layers: import_zod.z.array(
6277
6758
  import_zod.z.object({
@@ -6348,7 +6829,8 @@ function createIkiMcpServer() {
6348
6829
  formatRigPlanReport(r.rigPlan),
6349
6830
  ...formatPatchReports(r.patches ?? []),
6350
6831
  ...formatFoldReport(r.folds, r.canvas),
6351
- ...formatPhysicsReport(r.physics)
6832
+ ...formatPhysicsReport(r.physics),
6833
+ ...formatHairSideReport(r.turn?.hairSide, r.canvas)
6352
6834
  ].join("\n") : `INVALID: ${r.error}`;
6353
6835
  return { content: [{ type: "text", text }], structuredContent: r };
6354
6836
  } catch (err) {
@@ -6364,7 +6846,7 @@ function createIkiMcpServer() {
6364
6846
  server.registerTool(
6365
6847
  "compose_layers_from_parts",
6366
6848
  {
6367
- description: "Composes AI-generated part PNGs into canvas-aligned, role-named PNG layers on disk, ready for auto_rig_from_layers (the eyewhite split, alpha-trim/white-key, and placement pipeline the character-generation skill needs), with the same geometry report measure_layers returns standalone included inline. face, eyewhite, iris, brow, hair_front are required, with mouth.png \u2014 or the lip set's mouth_keyed.png (the open mouth, its inside painted flat #00FF00) + mouth_interior.png (the cavity, teeth and tongue alone), which the composer keys and splits into mouth_inner / lip_lower / lip_upper on one frame so auto_rig_from_layers folds the mouth open like the eyelid, the interior's light paint (luma 100 and over) written as mouth_tongue and mouth_teeth on the same frame, riding the opening's bottom and the upper line and clipped to the cavity (listed in `skipped` when the interior has none); the two routes cannot be mixed, one keyed file without the other is refused, and a key that fails (no green, green outside the opening, an outline not closed round it, more than one opening, no skin under the opening, an interior that is only lips, or one drawn opaque on a non-white or noisy ground) is refused naming the regeneration; with the lip set neither mouth nor mouth_open is written and preview.png shows the mouth closed, as the rig draws the rest pose. hair_back, body, mouth_open (legacy route only), blush (one blush.png makes the blush_L/blush_R pair) and nose are optional \u2014 without a nose layer the head still turns on the rig's default profile, but it has no nose to lead the turn, and `auto_rig_from_layers` fits no turn to the art (`turnTargets` is inert, no `turn` report). One arm.png \u2014 the arm on the screen LEFT, drawn hanging with its shoulder at the top \u2014 makes both arms of a full body: arm_R takes it as drawn and arm_L mirrored. The arms are opt-in: without arm.png the compose is a bust's and `skipped` never lists them. arm.png needs body.png, and each arm is hung on the body's shoulder by default (see `layout`). One forearm_pose.png \u2014 the arm's forearm raised, on the screen LEFT, standing up from its elbow with the hand at the top \u2014 makes both pose forearms (forearm_pose_R as drawn, forearm_pose_L mirrored): each is scaled so its elbow end is as wide as its arm's elbow run and pinned on that arm's elbow (see `layout`), and it needs arm.png. With one, preview-pose.png shows the switch at 1 as the rig draws it (the hanging forearms hidden below the elbow, the pose forearms over everything) while preview.png stays the rest pose; without one it is removed. The inline report carries the full-body checks too: a body whose feet a tall canvas's bottom cuts off, an arm without a body, an arm whose shoulder cap does not reach under the torso's edge, and a pose forearm without its arm or off its arm's elbow in pivot, width or length. A nose whose dense core is a speck \u2014 under a quarter of its trimmed part's width or height, such as a lone nostril mark or highlight \u2014 is sized and placed whole, and the inline report warns of it. A light mark drawn detached above the eye white, such as a double-eyelid crease, is dropped from the sclera (the iris's clip); dark strokes there stay lash ink. The eyewhite's dark lower lid \u2014 its line and lashes \u2014 becomes lash_lower_L/lash_lower_R, drawn over the iris; a white with none writes none and lists them in `skipped`.",
6849
+ description: "Composes AI-generated part PNGs into canvas-aligned, role-named PNG layers on disk, ready for auto_rig_from_layers (the eyewhite split, alpha-trim/white-key, and placement pipeline the character-generation skill needs), with the same geometry report measure_layers returns standalone included inline. face, eyewhite, iris, brow, hair_front are required, with mouth.png \u2014 or the lip set's mouth_keyed.png (the open mouth, its inside painted flat #00FF00) + mouth_interior.png (the cavity, teeth and tongue alone), which the composer keys and splits into mouth_inner / lip_lower / lip_upper on one frame so auto_rig_from_layers folds the mouth open like the eyelid, the interior's light paint (luma 100 and over) written as mouth_tongue and mouth_teeth on the same frame, riding the opening's bottom and the upper line and clipped to the cavity (listed in `skipped` when the interior has none); the two routes cannot be mixed, one keyed file without the other is refused, and a key that fails (no green, green outside the opening, an outline not closed round it, more than one opening, no skin under the opening, an interior that is only lips, or one drawn opaque on a non-white or noisy ground) is refused naming the regeneration; with the lip set neither mouth nor mouth_open is written and preview.png shows the mouth closed, as the rig draws the rest pose. hair_back, body, mouth_open (legacy route only), blush (one blush.png makes the blush_L/blush_R pair), hair_side (one hair_side.png makes the hair_side_L/hair_side_R pair) and nose are optional \u2014 without a nose layer the head still turns on the rig's default profile, but it has no nose to lead the turn, and `auto_rig_from_layers` fits no turn to the art (`turnTargets` is inert, no `turn` report). The hair_side.png is the front side lock on the screen LEFT, hanging beside the ear with its root at the image's top: hair_side_R is as drawn and hair_side_L mirrored, both drawn over the face, brows and lashes and under hair_front, and without the file both are listed in `skipped`. One arm.png \u2014 the arm on the screen LEFT, drawn hanging with its shoulder at the top \u2014 makes both arms of a full body: arm_R takes it as drawn and arm_L mirrored. The arms are opt-in: without arm.png the compose is a bust's and `skipped` never lists them. arm.png needs body.png, and each arm is hung on the body's shoulder by default (see `layout`). One forearm_pose.png \u2014 the arm's forearm raised, on the screen LEFT, standing up from its elbow with the hand at the top \u2014 makes both pose forearms (forearm_pose_R as drawn, forearm_pose_L mirrored): each is scaled so its elbow end is as wide as its arm's elbow run and pinned on that arm's elbow (see `layout`), and it needs arm.png. With one, preview-pose.png shows the switch at 1 as the rig draws it (the hanging forearms hidden below the elbow, the pose forearms over everything) while preview.png stays the rest pose; without one it is removed. The inline report carries the full-body checks too: a body whose feet a tall canvas's bottom cuts off, an arm without a body, an arm whose shoulder cap does not reach under the torso's edge, and a pose forearm without its arm or off its arm's elbow in pivot, width or length. A nose whose dense core is a speck \u2014 under a quarter of its trimmed part's width or height, such as a lone nostril mark or highlight \u2014 is sized and placed whole, and the inline report warns of it. A light mark drawn detached above the eye white, such as a double-eyelid crease, is dropped from the sclera (the iris's clip); dark strokes there stay lash ink. The eyewhite's dark lower lid \u2014 its line and lashes \u2014 becomes lash_lower_L/lash_lower_R, drawn over the iris; a white with none writes none and lists them in `skipped`.",
6368
6850
  inputSchema: {
6369
6851
  partsDir: import_zod.z.string().describe(
6370
6852
  "Directory of the source part PNGs (resolved against cwd)."
@@ -6381,10 +6863,10 @@ function createIkiMcpServer() {
6381
6863
  h: import_zod.z.number()
6382
6864
  }).partial()
6383
6865
  ).optional().describe(
6384
- "Per-role override merged over the built-in defaults, keyed by role \u2014 hair_back, body, arm_L, arm_R, face, blush_L, blush_R, nose, mouth, mouth_open, mouth_inner, eye_L, eye_R, iris_L, iris_R, lash_L, lash_R, brow_L, brow_R, hair_front, forearm_pose_L, forearm_pose_R \u2014 e.g. `{ eye_L: { cx: 660 } }`. `w` is an integer in 1..1100 (the canvas width) and `h` in 1..canvasHeight; omit `h` to keep the part's own aspect, set it to stretch. The defaults of the face's features \u2014 blush, nose, mouth, mouth_open, mouth_inner, eyes, irises, lashes, brows \u2014 are proportions of the face: an override of face.cx, face.cy or face.w carries them with it (scaled by the width; face.h stretches the face alone), while a feature's own override names canvas px. The nose is sized and placed by its dense core (its pixels at alpha >= 128, the drawing inside a soft nose's feather), not its whole part: `w`/`h` size the core, `cx` centres it, and a set `cy` centres its rows. A nose whose core is a speck \u2014 under a quarter of the trimmed part's width or height, such as a lone nostril mark or highlight \u2014 is sized and placed whole instead, and the report warns of it. Its `cy` defaults to unset, which lands the core's bottom row (the tip) 0.66 of the way from the eye row down to the mouth's, so the nose follows a retuned eye or mouth row. 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. lash_lower_L/lash_lower_R are cut from it too and have no key: they land on their eye's frame. mouth_inner is the lip set's one frame (mouth_open's place by default; lip_lower, lip_upper, mouth_tongue and mouth_teeth have no key and land on it, so a retune moves them together), and with the lip set the nose's tip rule reads layout.mouth_inner.cy. arm_L/arm_R have no cx/cy/w defaults: an unset `w` is 0.4 of the placed body's width, and an unset `cx` or `cy` hangs the arm's shoulder pivot \u2014 the one auto_rig_from_layers turns it about \u2014 on the body box's shoulder corner on that axis: its left edge for arm_R, its right edge for arm_L, 0.12 of its height under its top. A set one centres the arm as for every other role. forearm_pose_L/forearm_pose_R have no cx/cy/w defaults either: an unset `w` scales the forearm so its elbow end (the shoulder rule run from its bottom) is as wide as the placed arm's elbow run, and an unset `cx` or `cy` pins that elbow end's pivot on the arm's elbow \u2014 the one auto_rig_from_layers hangs it from."
6866
+ "Per-role override merged over the built-in defaults, keyed by role \u2014 hair_back, body, arm_L, arm_R, face, blush_L, blush_R, nose, mouth, mouth_open, mouth_inner, eye_L, eye_R, iris_L, iris_R, lash_L, lash_R, brow_L, brow_R, hair_side_L, hair_side_R, hair_front, forearm_pose_L, forearm_pose_R \u2014 e.g. `{ eye_L: { cx: 660 } }`. `w` is an integer in 1..1100 (the canvas width) and `h` in 1..canvasHeight; omit `h` to keep the part's own aspect, set it to stretch. The defaults of the face's features \u2014 blush, nose, mouth, mouth_open, mouth_inner, eyes, irises, lashes, brows, side locks \u2014 are proportions of the face: an override of face.cx, face.cy or face.w carries them with it (scaled by the width; face.h stretches the face alone), while a feature's own override names canvas px. The nose is sized and placed by its dense core (its pixels at alpha >= 128, the drawing inside a soft nose's feather), not its whole part: `w`/`h` size the core, `cx` centres it, and a set `cy` centres its rows. A nose whose core is a speck \u2014 under a quarter of the trimmed part's width or height, such as a lone nostril mark or highlight \u2014 is sized and placed whole instead, and the report warns of it. Its `cy` defaults to unset, which lands the core's bottom row (the tip) 0.66 of the way from the eye row down to the mouth's, so the nose follows a retuned eye or mouth row. 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. lash_lower_L/lash_lower_R are cut from it too and have no key: they land on their eye's frame. mouth_inner is the lip set's one frame (mouth_open's place by default; lip_lower, lip_upper, mouth_tongue and mouth_teeth have no key and land on it, so a retune moves them together), and with the lip set the nose's tip rule reads layout.mouth_inner.cy. arm_L/arm_R have no cx/cy/w defaults: an unset `w` is 0.4 of the placed body's width, and an unset `cx` or `cy` hangs the arm's shoulder pivot \u2014 the one auto_rig_from_layers turns it about \u2014 on the body box's shoulder corner on that axis: its left edge for arm_R, its right edge for arm_L, 0.12 of its height under its top. A set one centres the arm as for every other role. forearm_pose_L/forearm_pose_R have no cx/cy/w defaults either: an unset `w` scales the forearm so its elbow end (the shoulder rule run from its bottom) is as wide as the placed arm's elbow run, and an unset `cx` or `cy` pins that elbow end's pivot on the arm's elbow \u2014 the one auto_rig_from_layers hangs it from."
6385
6867
  ),
6386
6868
  mirrorParts: import_zod.z.array(import_zod.z.string()).optional().describe(
6387
- "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), brow.png as the brow on the screen RIGHT (thick head at the image's left end, tail at its right), blush.png as the blush on the screen LEFT (outer end, toward the face's edge, at the image's left end, inner end at its right), arm.png as the arm on the screen LEFT (the character's right, hanging, its shoulder at the image's top), and forearm_pose.png as the raised forearm on the screen LEFT (standing up from its elbow, the hand at the image's top, the thumb toward the body at the image's 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."
6869
+ "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), brow.png as the brow on the screen RIGHT (thick head at the image's left end, tail at its right), blush.png as the blush on the screen LEFT (outer end, toward the face's edge, at the image's left end, inner end at its right), hair_side.png as the front side lock on the screen LEFT (hanging, its root at the image's top), arm.png as the arm on the screen LEFT (the character's right, hanging, its shoulder at the image's top), and forearm_pose.png as the raised forearm on the screen LEFT (standing up from its elbow, the hand at the image's top, the thumb toward the body at the image's 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."
6388
6870
  ),
6389
6871
  canvasHeight: import_zod.z.number().optional().describe(
6390
6872
  "The canvas's height in px: an even integer in 1100..4096, default 1100 (a square bust canvas; at 1100 every output is byte-identical to leaving it out). The width stays 1100. The canvas grows downward: every default and every override keeps its canvas px from the top-left, so the head lands where it does on a bust and a full body gets room below. An odd height is refused \u2014 model space is centred on the canvas, so it would put the head on a half pixel \u2014 and it is checked before any part decodes."
@@ -6412,7 +6894,7 @@ function createIkiMcpServer() {
6412
6894
  server.registerTool(
6413
6895
  "measure_layers",
6414
6896
  {
6415
- description: "Reports read-only geometry checks over an already-composed layers directory \u2014 the same checks compose_layers_from_parts returns inline (iris ratio/offset, eye aspect, cropped/cut edges, a nose whose dense core is a speck of its crop, missing optional roles, a body whose feet a tall canvas's bottom cuts off, an arm without a body, an arm whose shoulder cap does not reach under the torso's edge on its shoulder pivot's row, a pose forearm without its arm or whose elbow end is off its arm's elbow in pivot, width or length, and the lip set: a partial one or one beside mouth/mouth_open, the fold's contract per column of the opening, an opening too narrow or short, a line too thin, green left, an interior with holes, and of mouth_tongue/mouth_teeth: one with no lip set, one on another canvas, one whose box leaves mouth_inner's \u2014 with the opening's size and the MouthOpen below which no slit shows). Every preview*.png is skipped. Use to re-check a layers dir without recomposing. Its nose check reads the composed file against its crop, which is what auto_rig_from_layers acts on. Compose's inline report does the same unless the composer found the source part's core a speck, which it reports instead \u2014 so a speck that resampling erased from the layer shows there and not here.",
6897
+ description: "Reports read-only geometry checks over an already-composed layers directory \u2014 the same checks compose_layers_from_parts returns inline (iris ratio/offset, eye aspect, cropped/cut edges, a nose whose dense core is a speck of its crop, missing optional roles, a body whose feet a tall canvas's bottom cuts off, an arm without a body, an arm whose shoulder cap does not reach under the torso's edge on its shoulder pivot's row, a pose forearm without its arm or whose elbow end is off its arm's elbow in pivot, width or length, a front side lock without hair_front, one whose top row shows past the bangs at rest, one covering the eye white's outer corner at rest, one whose lean on the turn away from it would bare columns neither hair_back nor the face paints, a hair_side.png drawing two locks, and the lip set: a partial one or one beside mouth/mouth_open, the fold's contract per column of the opening, an opening too narrow or short, a line too thin, green left, an interior with holes, and of mouth_tongue/mouth_teeth: one with no lip set, one on another canvas, one whose box leaves mouth_inner's \u2014 with the opening's size and the MouthOpen below which no slit shows). Every preview*.png is skipped. Use to re-check a layers dir without recomposing. Its nose check reads the composed file against its crop, which is what auto_rig_from_layers acts on. Compose's inline report does the same unless the composer found the source part's core a speck, which it reports instead \u2014 so a speck that resampling erased from the layer shows there and not here.",
6416
6898
  inputSchema: {
6417
6899
  layersDir: import_zod.z.string().describe(
6418
6900
  "Directory of role-named layer PNGs (resolved against cwd)."
@@ -6477,7 +6959,7 @@ function createIkiMcpServer() {
6477
6959
  server.registerTool(
6478
6960
  "render_poses",
6479
6961
  {
6480
- description: "Renders a rigged .iki into the character loop's pose PNGs with the real engine, through the installed Chrome, Edge or Chromium run headless (set CHROME_PATH to pick one). The model decides the set: a bust gets 560x560 shots (rest, turns, nod, blinks, gaze, combined \u2014 ParamAngleX/Y/Z all at 30 \u2014 and stress: ParamAngleX/Y/Z all at -30, ParamMouthOpenY 1, both eyes at 0.5, the brows at opposite extremes (ParamBrowLY -1, ParamBrowRY 1, ParamBrowLAngle 1, ParamBrowRAngle -1) and each body angle the model declares at -10); a mouth adds 720x480 mouth crops; a full body (taller than wide) adds the full-canvas body, arm and elbow poses on a 1400-wide canvas, and a model with a pose forearm adds the full-pose-* shots. Given `poses` (see its field), the standard set is not rendered: only those poses are, each crop clamped to the model's canvas. Writes <pose>.png files into outDir, overwriting same-named files in place; returns the written paths one per line, then the model's fold report (the result's `folds`), checked by the engine over its own pose set plus any `poses`, each of which a `FOLD` line names by its settings, not its PNG name: a `FOLD` line per warp deformer or mesh part that flips (ratio <= 0) or collapses (under 0.1) at some pose \u2014 its cell or triangle, the ratio of its area there to at rest, the pose as its parameter settings (`rest` for none) and where it rests, in model space and in model px from the top-left (the layer PNGs' own pixels, not a render's) \u2014 or `FOLDS: none over N poses`, then a `FOLDS expected:` line naming the closures the rig draws on purpose (an eye or the mouth shut), each by part id, ratio and the parameter that shuts it. Report-only: a fold never fails the render. The `PHYSICS` lines follow the fold report (the result's `physics`), one per physics rig output of the model's own rigs \u2014 `poses` do not enter it \u2014 reading ok, frozen or unstable with the step and idle amplitudes, or `PHYSICS: no rigs`; report-only too. Given `sweep`, also renders an eased turn of the head (see its field) and prints its paths and `SWEEP` lines. Fails with INVALID when no browser is found or an input is refused; a browser that cannot start is a tool error.",
6962
+ description: "Renders a rigged .iki into the character loop's pose PNGs with the real engine, through the installed Chrome, Edge or Chromium run headless (set CHROME_PATH to pick one). The model decides the set: a bust gets 560x560 shots (rest, turns, nod, blinks, gaze, combined \u2014 ParamAngleX/Y/Z all at 30 \u2014 and stress: ParamAngleX/Y/Z all at -30, ParamMouthOpenY 1, both eyes at 0.5, the brows at opposite extremes (ParamBrowLY -1, ParamBrowRY 1, ParamBrowLAngle 1, ParamBrowRAngle -1) and each body angle the model declares at -10); a mouth adds 720x480 mouth crops; a full body (taller than wide) adds the full-canvas body, arm and elbow poses on a 1400-wide canvas, and a model with a pose forearm adds the full-pose-* shots. Given `poses` (see its field), the standard set is not rendered: only those poses are, each crop clamped to the model's canvas. Writes <pose>.png files into outDir, overwriting same-named files in place; returns the written paths one per line, then the model's fold report (the result's `folds`), checked by the engine over its own pose set plus any `poses`, each of which a `FOLD` line names by its settings, not its PNG name: a `FOLD` line per warp deformer or mesh part that flips (ratio <= 0) or collapses (under 0.1) at some pose \u2014 its cell or triangle, the ratio of its area there to at rest, the pose as its parameter settings (`rest` for none) and where it rests, in model space and in model px from the top-left (the layer PNGs' own pixels, not a render's) \u2014 or `FOLDS: none over N poses`, then a `FOLDS expected:` line naming the closures the rig draws on purpose (an eye or the mouth shut), each by part id, ratio and the parameter that shuts it. Report-only: a fold never fails the render. The `PHYSICS` lines follow the fold report (the result's `physics`), one per physics rig output of the model's own rigs \u2014 `poses` do not enter it \u2014 reading ok, frozen or unstable with the step and idle amplitudes, or `PHYSICS: no rigs`; report-only too. Given `sweep`, also renders an eased turn of the head (see its field) and prints its paths and `SWEEP` lines (and, with `sweeps`, the turn-and-nod box). Fails with INVALID when no browser is found or an input is refused; a browser that cannot start is a tool error.",
6481
6963
  inputSchema: {
6482
6964
  modelPath: import_zod.z.string().describe(
6483
6965
  "Rigged .iki file path (resolved against cwd; must sit under the working directory)."
@@ -6509,7 +6991,21 @@ function createIkiMcpServer() {
6509
6991
  h: import_zod.z.number()
6510
6992
  }).optional()
6511
6993
  }).optional().describe(
6512
- "A turn sweep rendered IN ADDITION to the poses, `{ name, preset: \"turn\", crop? }`: an eased `ParamAngleX` turn (0 to -30 to +30 to 0 over 3 s, sinusoidal) at 30 fps on a 60 Hz physics clock, with the hair physics running and the idle off, every other parameter at its default. `crop` is a rectangle in model px as a pose's, fixed for every frame; without one the frames are framed as the standard shots. Written into `<outDir>/<name>/` (created; `name` starts with a letter or digit, then letters, digits, `_`, `.`, `-`): `fNNN.png` (90 frames), `manifest.json` (each frame's time, angle and effective values), `sheet.png` (nine frames of the -30 to +30 leg, labelled with angle and time, at most 2000 px a side), `kymograph.png` (the eye row of every frame stacked over time), `index.html` (a flipbook to open from disk; add `?b=<relative dir of another sweep>` for two side by side). The text then lists the paths and, after the `PHYSICS` lines, a `SWEEP turn` line per landmark (eyes, nose) from the engine's geometry: amplitude in face widths, the kink of x and of the eye width through angle 0, the lead over the local face plate at each end, and the pop \u2014 report-only, like `FOLD` and `PHYSICS`."
6994
+ "A turn sweep rendered IN ADDITION to the poses, `{ name, preset: \"turn\", crop? }`: an eased `ParamAngleX` turn (0 to -30 to +30 to 0 over 3 s, sinusoidal) at 30 fps on a 60 Hz physics clock, with the hair physics running and the idle off, every other parameter at its default. `crop` is a rectangle in model px as a pose's, fixed for every frame; without one the frames are framed as the standard shots. Written into `<outDir>/<name>/` (created; `name` starts with a letter or digit, then letters, digits, `_`, `.`, `-`): `fNNN.png` (90 frames), `manifest.json` (each frame's time, angle and effective values), `sheet.png` (nine frames of the -30 to +30 leg, labelled with angle and time, at most 2000 px a side), `kymograph.png` (the eye row of every frame stacked over time), `index.html` (a flipbook to open from disk; add `?b=<relative dir of another sweep>` for two side by side). The text then lists the paths and, after the `PHYSICS` lines, a `SWEEP turn` line per landmark (eyes, nose) from the engine's geometry: amplitude in face widths, the kink of x and of the eye width through angle 0, the lead over the local face plate at each end, and the pop \u2014 report-only, like `FOLD` and `PHYSICS`. `sweeps` renders more sweeps beside this one. The `SWEEP nod` and `SWEEP corner` lines follow the `SWEEP turn` ones."
6995
+ ),
6996
+ sweeps: import_zod.z.array(
6997
+ import_zod.z.object({
6998
+ name: import_zod.z.string(),
6999
+ preset: import_zod.z.enum(SWEEP_PRESETS),
7000
+ crop: import_zod.z.object({
7001
+ x: import_zod.z.number(),
7002
+ y: import_zod.z.number(),
7003
+ w: import_zod.z.number(),
7004
+ h: import_zod.z.number()
7005
+ }).optional()
7006
+ })
7007
+ ).optional().describe(
7008
+ "More sweeps rendered after `sweep`, each `{ name, preset, crop? }` into its own `<outDir>/<name>/` (files and `crop` as `sweep`'s). Names are distinct from `sweep`'s and from each other's ignoring case, and presets are distinct (at most one of each). `turn` is `sweep`'s. `turn-nod` is the box (0,0) -> (0,-30) -> (-30,-30) -> (-30,+30) -> (+30,+30) -> (+30,-30) -> (0,-30) -> (0,0) of `ParamAngleX` x `ParamAngleY`, each leg eased, 6 s, 180 frames; its `sheet.png` is a 3 x 3 grid BY ANGLE (columns AngleX -30/0/+30, rows AngleY +30/0/-30, rest in the centre, cells labelled X, Y and t) and it has no kymograph. `manifest.json` is version 2 (`parameters`, and per frame `t` and `values`). A sweep dir's earlier frames, sheet, kymograph, manifest and flipbook are cleared first. An empty list, a repeated name or preset, or a bad crop comes back as `INVALID: sweeps...`. A server before 0.32.0 strips `sweeps` and renders the rest. The `SWEEP nod` lines (the eye-pair and iris-pair gap range and the mouth width range along the nod at each turn, in face widths) and `SWEEP corner` lines (the additivity residual per landmark at the four corners, the rest term included; 0 on an additive rig) print once per call whenever `sweep` or `sweeps` was asked for, report-only like `FOLD` and `PHYSICS`."
6513
7009
  )
6514
7010
  }
6515
7011
  },
@@ -6518,16 +7014,21 @@ function createIkiMcpServer() {
6518
7014
  const r = await renderPoses(args);
6519
7015
  const text = r.ok ? [
6520
7016
  ...r.poses.map((p) => p.path),
6521
- ...r.sweep ? [
6522
- r.sweep.dir,
6523
- r.sweep.sheet,
6524
- r.sweep.kymograph,
6525
- r.sweep.flipbook,
6526
- r.sweep.manifest
6527
- ] : [],
7017
+ ...[...r.sweep ? [r.sweep] : [], ...r.sweeps ?? []].flatMap(
7018
+ (w) => [
7019
+ w.dir,
7020
+ w.sheet,
7021
+ ...w.kymograph ? [w.kymograph] : [],
7022
+ w.flipbook,
7023
+ w.manifest
7024
+ ]
7025
+ ),
6528
7026
  ...formatFoldReport(r.folds, r.modelCanvas),
6529
7027
  ...formatPhysicsReport(r.physics),
6530
- ...r.sweep ? formatSweepReport(r.sweep.report) : []
7028
+ ...r.sweep ?? r.sweeps?.[0] ? [
7029
+ ...formatSweepReport((r.sweep ?? r.sweeps[0]).report),
7030
+ ...formatNodReport((r.sweep ?? r.sweeps[0]).nod)
7031
+ ] : []
6531
7032
  ].join("\n") : `INVALID: ${r.error}`;
6532
7033
  return { content: [{ type: "text", text }], structuredContent: r };
6533
7034
  } catch (err) {
@@ -6544,8 +7045,10 @@ function createIkiMcpServer() {
6544
7045
  }
6545
7046
  // Annotate the CommonJS export names for ESM import in node:
6546
7047
  0 && (module.exports = {
7048
+ SWEEP_PRESETS,
6547
7049
  autoRigFromLayers,
6548
7050
  checkModelFolds,
7051
+ checkNod,
6549
7052
  checkSweep,
6550
7053
  composeLayersFromParts,
6551
7054
  createIkiMcpServer,
@@ -6553,7 +7056,9 @@ function createIkiMcpServer() {
6553
7056
  describeIkiAt,
6554
7057
  describeRigPlan,
6555
7058
  formatFoldReport,
7059
+ formatHairSideReport,
6556
7060
  formatMeasureReport,
7061
+ formatNodReport,
6557
7062
  formatPhysicsReport,
6558
7063
  formatRigPlanReport,
6559
7064
  formatSweepReport,