pixelkiln 0.147.0 → 0.148.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -580,14 +580,13 @@ function proTierCost(width, height) {
580
580
  if (px <= 102400) return PRO_TIER_PRICES[1];
581
581
  return PRO_TIER_PRICES[2];
582
582
  }
583
+ var PIXMINIMAX_STEPS = [1, 1, 2, 2, 3, 3, 4, 5, 5, 6];
583
584
  function pixMiniMaxCost(width, height, frames, enhancePrompt = false) {
584
- const f = width * height * Math.max(1, frames) / 4096;
585
- let units;
586
- if (f <= 8) units = 1;
587
- else if (f <= 16) units = 1 + (f - 8) / 8;
588
- else if (f <= 40) units = 2 + (f - 16) / 6;
589
- else units = 6 + (f - 40) / 6;
590
- const base = Math.max(1, Math.ceil(units - 1e-9));
585
+ const side = Math.max(1, width, height);
586
+ const upscaled = side * (side <= 64 ? 4 : side <= 128 ? 2 : 1);
587
+ const reference = Math.max(1, frames) * upscaled * upscaled / 65536;
588
+ const step = Math.max(1, Math.ceil(reference / 4 - 1e-9));
589
+ const base = PIXMINIMAX_STEPS[Math.min(step, PIXMINIMAX_STEPS.length) - 1];
591
590
  return enhancePrompt ? base + 0.05 : base;
592
591
  }
593
592
  function tilesCost(tileSize, variations) {
@@ -682,7 +681,7 @@ var CharacterProportionsSchema = import_zod.z.union([
682
681
  hipWidth: import_zod.z.number().min(0.5).max(2).optional()
683
682
  }).strict()
684
683
  ]);
685
- var CharacterAnimationModeSchema = import_zod.z.enum(["template", "skeleton-v3", "v3", "pro"]);
684
+ var CharacterAnimationModeSchema = import_zod.z.enum(["template", "skeleton-v3", "v3", "pixminimax", "pro"]);
686
685
  var UiPieceSchema = import_zod.z.discriminatedUnion("kind", [
687
686
  import_zod.z.object({
688
687
  id: import_zod.z.string().min(1),
@@ -1006,12 +1005,13 @@ var CharacterAnimationSchema = import_zod.z.object({
1006
1005
  motionFrom: import_zod.z.string().min(1).optional(),
1007
1006
  /**
1008
1007
  * Frames to generate without a template. A v3 loop takes an even 4 to 16;
1009
- * a sentence loop (`mode: "skeleton-v3"` with no `template`) takes 3 to 15.
1008
+ * a pixminimax loop a multiple of 4 from 4 to 40; a sentence loop
1009
+ * (`mode: "skeleton-v3"` with no `template`) takes 3 to 15.
1010
1010
  */
1011
- frames: import_zod.z.number().int().min(3).max(16).optional(),
1011
+ frames: import_zod.z.number().int().min(3).max(40).optional(),
1012
1012
  /** Playback rate recorded with the frames; PixelLab does not store one. */
1013
1013
  fps: import_zod.z.number().int().min(1).max(60).default(8),
1014
- /** v3 only: keep the resting pose as frame 0, so `frames` generated frames land as `frames + 1` files. */
1014
+ /** v3 and pixminimax: keep the resting pose as frame 0, so `frames` generated frames land as `frames + 1` files. */
1015
1015
  keepFirstFrame: import_zod.z.boolean().default(true),
1016
1016
  /**
1017
1017
  * `character` loops: strip the ghost pixels an animation model leaves
@@ -1025,28 +1025,41 @@ var CharacterAnimationSchema = import_zod.z.object({
1025
1025
  * `template` when a template is named, otherwise `v3`; `skeleton-v3`
1026
1026
  * poses a template with PixelLab's skeleton model instead, or, with no
1027
1027
  * template, animates the asset's prompt as a sentence written into one 3D
1028
- * motion (a v3 base; 3-15 `frames`); `pro` for the sequential
1029
- * high-quality engine.
1028
+ * motion (a v3 base; 3-15 `frames`); `pixminimax` draws from the
1029
+ * prompt on PixelLab's PixMiniMax engine (4 to 40 `frames`, a multiple
1030
+ * of 4); `pro` for the sequential high-quality engine.
1030
1031
  */
1031
1032
  mode: CharacterAnimationModeSchema.optional(),
1032
1033
  /**
1033
- * v3 only: a manifest-relative image of the pose to start from, instead
1034
- * of the character's rotation for this direction. Up to 256px.
1034
+ * v3 and pixminimax: a manifest-relative image of the pose to start from,
1035
+ * instead of the character's rotation for this direction. Up to 256px.
1035
1036
  */
1036
1037
  startFrame: import_zod.z.string().min(1).optional(),
1037
1038
  /**
1038
- * v3 only: a pose to animate toward. The loop then interpolates from the
1039
- * start frame (the rotation, or `startFrame`) to this image, which must
1040
- * be the same size as the start frame.
1039
+ * v3 and pixminimax: a pose to animate toward. The loop then interpolates
1040
+ * from the start frame (the rotation, or `startFrame`) to this image,
1041
+ * which must be the same size as the start frame. The same image as
1042
+ * `startFrame` closes a loop.
1041
1043
  */
1042
1044
  endFrame: import_zod.z.string().min(1).optional(),
1043
- /** What is being animated, when the character's own description would mislead the model. */
1045
+ /**
1046
+ * What is being animated, when the character's own description would
1047
+ * mislead the model. On a pixminimax loop it is PixelLab's
1048
+ * `subject_description`, one noun phrase of up to 300 characters; left
1049
+ * out, PixelLab reads it off the start frame.
1050
+ */
1044
1051
  subject: import_zod.z.string().min(1).optional(),
1052
+ /**
1053
+ * pixminimax only: the pose the start frame shows, up to 300 characters
1054
+ * ("standing beside the pole, one hand on it"). Left out, PixelLab reads
1055
+ * it off the image.
1056
+ */
1057
+ initialPose: import_zod.z.string().min(1).max(300).optional(),
1045
1058
  /** Template mode only: style hints for this loop, over the character's own. */
1046
1059
  outline: import_zod.z.string().min(1).optional(),
1047
1060
  shading: import_zod.z.string().min(1).optional(),
1048
1061
  detail: import_zod.z.string().min(1).optional(),
1049
- /** v3 text loops only: let PixelLab expand the action into a fuller motion description first. */
1062
+ /** v3 and pixminimax text loops only: let PixelLab expand the action into a fuller motion description first. */
1050
1063
  enhancePrompt: import_zod.z.boolean().optional()
1051
1064
  }).strict().superRefine((animation, context) => {
1052
1065
  if (animation.directions !== void 0) {
@@ -1057,22 +1070,29 @@ var CharacterAnimationSchema = import_zod.z.object({
1057
1070
  });
1058
1071
  }
1059
1072
  const sentence = animation.mode === "skeleton-v3" && !animation.template;
1060
- if (animation.frames !== void 0 && !sentence && animation.mode !== "pro") {
1073
+ const pixminimax = animation.mode === "pixminimax";
1074
+ if (animation.frames !== void 0 && pixminimax) {
1075
+ if (animation.frames % 4 !== 0 || animation.frames < 4) {
1076
+ context.addIssue({ code: import_zod.z.ZodIssueCode.custom, message: "a pixminimax loop takes a multiple of 4 frames, 4 to 40", path: ["frames"] });
1077
+ }
1078
+ } else if (animation.frames !== void 0 && !sentence && animation.mode !== "pro") {
1061
1079
  if (animation.frames % 2 !== 0) {
1062
1080
  context.addIssue({ code: import_zod.z.ZodIssueCode.custom, message: "frames must be even", path: ["frames"] });
1063
- } else if (animation.frames < 4) {
1064
- context.addIssue({ code: import_zod.z.ZodIssueCode.custom, message: "frames must be 4 to 16", path: ["frames"] });
1081
+ } else if (animation.frames < 4 || animation.frames > 16) {
1082
+ context.addIssue({ code: import_zod.z.ZodIssueCode.custom, message: "frames must be 4 to 16 (a pixminimax loop takes up to 40)", path: ["frames"] });
1065
1083
  }
1084
+ } else if (animation.frames !== void 0 && animation.mode === "pro" && animation.frames > 16) {
1085
+ context.addIssue({ code: import_zod.z.ZodIssueCode.custom, message: "frames must be 16 or fewer", path: ["frames"] });
1066
1086
  }
1067
1087
  if (animation.frames !== void 0 && sentence && animation.frames > 15) {
1068
1088
  context.addIssue({ code: import_zod.z.ZodIssueCode.custom, message: "a skeleton-v3 loop from a sentence takes 3 to 15 frames", path: ["frames"] });
1069
1089
  }
1070
1090
  const mode2 = animation.mode ?? (animation.template ? "template" : "v3");
1071
1091
  for (const key3 of ["startFrame", "endFrame", "enhancePrompt"]) {
1072
- if (animation[key3] !== void 0 && mode2 !== "v3") {
1092
+ if (animation[key3] !== void 0 && mode2 !== "v3" && mode2 !== "pixminimax") {
1073
1093
  context.addIssue({
1074
1094
  code: import_zod.z.ZodIssueCode.custom,
1075
- message: `${key3} is for v3 loops; a ${mode2} loop ${mode2 === "template" || mode2 === "skeleton-v3" ? `starts from the character's rotation and ${animation.template ? "follows its template" : "animates its sentence"}` : "takes neither"}`,
1095
+ message: `${key3} is for v3 and pixminimax loops; a ${mode2} loop ${mode2 === "template" || mode2 === "skeleton-v3" ? `starts from the character's rotation and ${animation.template ? "follows its template" : "animates its sentence"}` : "takes neither"}`,
1076
1096
  path: [key3]
1077
1097
  });
1078
1098
  }
@@ -1082,6 +1102,12 @@ var CharacterAnimationSchema = import_zod.z.object({
1082
1102
  context.addIssue({ code: import_zod.z.ZodIssueCode.custom, message: `${key3} overrides apply to template loops only`, path: [key3] });
1083
1103
  }
1084
1104
  }
1105
+ if (animation.initialPose !== void 0 && mode2 !== "pixminimax") {
1106
+ context.addIssue({ code: import_zod.z.ZodIssueCode.custom, message: `initialPose is for pixminimax loops; PixelLab's ${mode2} engine takes no pose caption`, path: ["initialPose"] });
1107
+ }
1108
+ if (pixminimax && animation.subject !== void 0 && animation.subject.length > 300) {
1109
+ context.addIssue({ code: import_zod.z.ZodIssueCode.custom, message: "a pixminimax loop's subject is one noun phrase of up to 300 characters", path: ["subject"] });
1110
+ }
1085
1111
  if (animation.template && animation.mode && animation.mode !== "template" && animation.mode !== "skeleton-v3") {
1086
1112
  context.addIssue({
1087
1113
  code: import_zod.z.ZodIssueCode.custom,
@@ -4194,8 +4220,11 @@ var PixelLabClient = class {
4194
4220
  * One animation of one character. Template mode costs a generation per
4195
4221
  * direction and fixes the frame count; skeleton-v3 poses the same template
4196
4222
  * with the skeleton video model (2-4 generations per direction); v3 draws
4197
- * `frameCount` frames from the action text; pro is the sequential engine.
4198
- * One job per direction.
4223
+ * `frameCount` frames from the action text; pixminimax does the same on
4224
+ * PixelLab's PixMiniMax engine (a multiple of 4 frames up to 40, the same
4225
+ * start/end frames, `keep_first_frame` and `enhance_prompt`, plus its own
4226
+ * `subject_description` and `initial_pose` captions); pro is the
4227
+ * sequential engine. One job per direction.
4199
4228
  *
4200
4229
  * Every mode but skeleton-v3 goes to `/animate-character`, the path whose
4201
4230
  * shapes were measured live. skeleton-v3 is documented only on
@@ -4211,6 +4240,7 @@ var PixelLabClient = class {
4211
4240
  async animateCharacter(args) {
4212
4241
  const encode = (image) => ({ type: "base64", base64: image.base64, format: image.format });
4213
4242
  const endpoint = args.mode === "skeleton-v3" ? "/characters/animations" : "/animate-character";
4243
+ const custom = args.mode === "v3" || args.mode === "pixminimax";
4214
4244
  const raw = await this.request(endpoint, {
4215
4245
  method: "POST",
4216
4246
  body: JSON.stringify({
@@ -4222,12 +4252,14 @@ var PixelLabClient = class {
4222
4252
  ...args.template ? { template_animation_id: args.template } : {},
4223
4253
  ...args.actionDescription ? { action_description: args.actionDescription } : {},
4224
4254
  ...args.description ? { description: args.description } : {},
4225
- // A template fixes its own frame count; v3 and a skeleton-v3 sentence take one.
4226
- ...(args.mode === "v3" || args.mode === "skeleton-v3" && !args.template) && args.frameCount ? { frame_count: args.frameCount } : {},
4227
- ...args.mode === "v3" && args.keepFirstFrame === false ? { keep_first_frame: false } : {},
4228
- ...args.mode === "v3" && args.startFrame ? { custom_start_frame: encode(args.startFrame) } : {},
4229
- ...args.mode === "v3" && args.endFrame ? { end_frame: encode(args.endFrame) } : {},
4230
- ...args.mode === "v3" && args.enhancePrompt ? { enhance_prompt: true } : {},
4255
+ // A template fixes its own frame count; v3, pixminimax and a skeleton-v3 sentence take one.
4256
+ ...(custom || args.mode === "skeleton-v3" && !args.template) && args.frameCount ? { frame_count: args.frameCount } : {},
4257
+ ...custom && args.keepFirstFrame === false ? { keep_first_frame: false } : {},
4258
+ ...custom && args.startFrame ? { custom_start_frame: encode(args.startFrame) } : {},
4259
+ ...custom && args.endFrame ? { end_frame: encode(args.endFrame) } : {},
4260
+ ...custom && args.enhancePrompt ? { enhance_prompt: true } : {},
4261
+ ...args.mode === "pixminimax" && args.subjectDescription ? { subject_description: args.subjectDescription } : {},
4262
+ ...args.mode === "pixminimax" && args.initialPose ? { initial_pose: args.initialPose } : {},
4231
4263
  ...args.mode === "template" && args.textGuidanceScale !== void 0 ? { text_guidance_scale: args.textGuidanceScale } : {},
4232
4264
  ...args.mode === "template" && args.outline ? { outline: args.outline } : {},
4233
4265
  ...args.mode === "template" && args.shading ? { shading: args.shading } : {},
@@ -7330,10 +7362,10 @@ function despeckle(png, options) {
7330
7362
  for (const still of options.reference) {
7331
7363
  const { pixels } = decodePng(still);
7332
7364
  for (let i = 0; i < pixels.length; i += 4) {
7333
- if (pixels[i + 3] === 0 || outline(pixels, i)) continue;
7365
+ if (pixels[i + 3] === 0) continue;
7334
7366
  const rgb = pixels[i] << 16 | pixels[i + 1] << 8 | pixels[i + 2];
7335
7367
  palette.set(rgb, (palette.get(rgb) ?? 0) + 1);
7336
- total++;
7368
+ if (!outline(pixels, i)) total++;
7337
7369
  }
7338
7370
  }
7339
7371
  if (!total) throw new Error("the reference stills have no opaque pixels that are not outline");
@@ -7393,7 +7425,7 @@ function despeckle(png, options) {
7393
7425
  const strange = run.filter(([x, y]) => foreign(at(image, x, y))).length / run.length > 0.5;
7394
7426
  let debris;
7395
7427
  const exposed = run.some(([x, y]) => STEPS.some(([dx, dy]) => open(x + dx, y + dy)));
7396
- if (strange && !exposed && run.length > limb) {
7428
+ if (strange && run.length > limb) {
7397
7429
  debris = false;
7398
7430
  limbs.add(index);
7399
7431
  } else if (exposed) {
@@ -7428,6 +7460,7 @@ function despeckle(png, options) {
7428
7460
  if (src[at(image, x, y) + 3] > 0 && out[at(image, x, y) + 3] === 0) frontier.push([x, y]);
7429
7461
  }
7430
7462
  }
7463
+ const seeds = frontier.length;
7431
7464
  for (let n = 0; n < frontier.length; n++) {
7432
7465
  const [fx, fy] = frontier[n];
7433
7466
  for (let dy = -1; dy <= 1; dy++) {
@@ -7451,6 +7484,31 @@ function despeckle(png, options) {
7451
7484
  }
7452
7485
  }
7453
7486
  }
7487
+ const chained = new Set(frontier.slice(seeds).map(([x, y]) => local(x, y)));
7488
+ const visited = /* @__PURE__ */ new Set();
7489
+ for (const [sx, sy] of frontier.slice(seeds)) {
7490
+ if (visited.has(local(sx, sy))) continue;
7491
+ const group = [[sx, sy]];
7492
+ visited.add(local(sx, sy));
7493
+ for (let n = 0; n < group.length; n++) {
7494
+ const [gx, gy] = group[n];
7495
+ for (let dy = -1; dy <= 1; dy++) {
7496
+ for (let dx = -1; dx <= 1; dx++) {
7497
+ const x = gx + dx;
7498
+ const y = gy + dy;
7499
+ if (!inside(cell, x, y) || visited.has(local(x, y)) || !chained.has(local(x, y))) continue;
7500
+ visited.add(local(x, y));
7501
+ group.push([x, y]);
7502
+ }
7503
+ }
7504
+ }
7505
+ if (group.length <= limb) continue;
7506
+ for (const [x, y] of group) {
7507
+ const i = at(image, x, y);
7508
+ src.copy(out, i, i, i + 4);
7509
+ removed--;
7510
+ }
7511
+ }
7454
7512
  }
7455
7513
  return { png: encodeRgbaPng(image.width, image.height, out), removed };
7456
7514
  }
@@ -8254,10 +8312,13 @@ function applyPostprocess(bytes, mediaType, record, reference = [], role) {
8254
8312
  if (mediaType !== MediaType.PNG || !record?.palette && !record?.despeckle && !record?.offset) return { bytes, changed: false };
8255
8313
  let out = bytes;
8256
8314
  let removed = 0;
8315
+ let opaque2 = 0;
8257
8316
  if (record.despeckle) {
8258
8317
  if (!reference.length) throw new Error(`cleaning needs the rotations of ${record.despeckle.of}, and none were given`);
8259
8318
  const cleaned = despeckle(out, { reference });
8260
8319
  if (cleaned.removed) {
8320
+ const { pixels } = decodePng(out);
8321
+ for (let i = 3; i < pixels.length; i += 4) if (pixels[i] > 0) opaque2++;
8261
8322
  out = cleaned.png;
8262
8323
  removed = cleaned.removed;
8263
8324
  }
@@ -8281,8 +8342,9 @@ function applyPostprocess(bytes, mediaType, record, reference = [], role) {
8281
8342
  }
8282
8343
  }
8283
8344
  if (!removed && !snapped && !moved) return { bytes, changed: false };
8284
- return { bytes: out, changed: true, ...removed ? { removed } : {}, ...snapped ? { snapped } : {}, ...moved ? { moved } : {} };
8345
+ return { bytes: out, changed: true, ...removed ? { removed, opaque: opaque2 } : {}, ...snapped ? { snapped } : {}, ...moved ? { moved } : {} };
8285
8346
  }
8347
+ var CLEAN_DAMAGE_SHARE = 0.03;
8286
8348
 
8287
8349
  // src/pipeline/mirror.ts
8288
8350
  function mirrorSourceHash(source) {
@@ -8580,6 +8642,13 @@ function characterCost(spec) {
8580
8642
  if (animation.mode === "template") return 1;
8581
8643
  if (animation.mode === "skeleton-v3") return 4;
8582
8644
  if (animation.mode === "v3") return Math.max(1, Math.ceil(px * animation.frames / 65536));
8645
+ if (animation.mode === "pixminimax") {
8646
+ const start = animation.startFrame;
8647
+ return Math.max(
8648
+ pixMiniMaxCost(spec.width, spec.height, animation.frames, animation.enhancePrompt),
8649
+ start ? pixMiniMaxCost(start.width, start.height, animation.frames, animation.enhancePrompt) : 0
8650
+ );
8651
+ }
8583
8652
  return proCharacterTierCost(spec.width, spec.height);
8584
8653
  }
8585
8654
  if (character.kind === "state" || character.kind === "portrait") return proCharacterTierCost(spec.width, spec.height);
@@ -9321,7 +9390,7 @@ var PixelLabProvider = class _PixelLabProvider {
9321
9390
  const { startFrame, endFrame } = character.animation;
9322
9391
  for (const [name, image] of [["start frame", startFrame], ["end frame", endFrame]]) {
9323
9392
  if (image && (image.width > 256 || image.height > 256)) {
9324
- throw new Error(`${label}: ${name} is ${image.width}x${image.height}; PixelLab v3 takes up to 256px`);
9393
+ throw new Error(`${label}: ${name} is ${image.width}x${image.height}; PixelLab ${character.animation.mode} takes up to 256px`);
9325
9394
  }
9326
9395
  }
9327
9396
  if (endFrame) {
@@ -9436,6 +9505,9 @@ var PixelLabProvider = class _PixelLabProvider {
9436
9505
  `${spec.styleId}/${spec.assetId} needs a prompt describing the motion, or a template` + (sentence ? ' (a skeleton-v3 loop with no template animates its prompt, e.g. "swinging a sword in a wide arc")' : "")
9437
9506
  );
9438
9507
  }
9508
+ if (character.animation.mode === "pixminimax" && (character.animation.frames % 4 !== 0 || character.animation.frames < 4 || character.animation.frames > 40)) {
9509
+ throw new Error(`${spec.styleId}/${spec.assetId}: a pixminimax loop takes a multiple of 4 frames, 4 to 40; ${character.animation.frames} is not one`);
9510
+ }
9439
9511
  if (sentence && (character.animation.frames < 3 || character.animation.frames > 15)) {
9440
9512
  throw new Error(`${spec.styleId}/${spec.assetId}: a skeleton-v3 loop from a sentence takes 3 to 15 frames; ${character.animation.frames} is out of range`);
9441
9513
  }
@@ -9747,7 +9819,9 @@ var PixelLabProvider = class _PixelLabProvider {
9747
9819
  isometric: character.isometric,
9748
9820
  startFrame: animation.startFrame ? readPose(spec, "start frame", animation.startFrame) : void 0,
9749
9821
  endFrame: animation.endFrame ? readPose(spec, "end frame", animation.endFrame) : void 0,
9750
- description: animation.subject,
9822
+ // PixMiniMax captions its start frame with its own two fields; the
9823
+ // other engines take `subject` as the general `description`.
9824
+ ...animation.mode === "pixminimax" ? { subjectDescription: animation.subject, initialPose: animation.initialPose } : { description: animation.subject },
9751
9825
  outline: animation.outline,
9752
9826
  shading: animation.shading,
9753
9827
  detail: animation.detail,
@@ -15726,6 +15800,8 @@ async function resolveCharacterShape(asset, style, kind, files) {
15726
15800
  ...asset.animation.startFrame ? { startFrame: await pose(asset.animation.startFrame, "Animation start frame") } : {},
15727
15801
  ...asset.animation.endFrame ? { endFrame: await pose(asset.animation.endFrame, "Animation end frame") } : {},
15728
15802
  ...asset.animation.subject ? { subject: asset.animation.subject } : {},
15803
+ // Set only on a pixminimax loop (the schema refuses it elsewhere), so no other spec's hash moves.
15804
+ ...asset.animation.initialPose ? { initialPose: asset.animation.initialPose } : {},
15729
15805
  ...asset.animation.outline ? { outline: asset.animation.outline } : {},
15730
15806
  ...asset.animation.shading ? { shading: asset.animation.shading } : {},
15731
15807
  ...asset.animation.detail ? { detail: asset.animation.detail } : {},
@@ -15764,6 +15840,7 @@ async function resolveObjectProShape(assetId, asset, style, kind, files) {
15764
15840
  for (const [field, value] of Object.entries({
15765
15841
  template: asset.animation.template,
15766
15842
  subject: asset.animation.subject,
15843
+ initialPose: asset.animation.initialPose,
15767
15844
  outline: asset.animation.outline,
15768
15845
  shading: asset.animation.shading,
15769
15846
  detail: asset.animation.detail
@@ -15777,7 +15854,7 @@ async function resolveObjectProShape(assetId, asset, style, kind, files) {
15777
15854
  if (asset.animation.clean !== void 0) {
15778
15855
  throw new Error(`assets.${assetId}: animation.clean applies to character loops; objectPro loops are not cleaned`);
15779
15856
  }
15780
- if (asset.animation.mode === "template" || asset.animation.mode === "skeleton-v3") {
15857
+ if (asset.animation.mode === "template" || asset.animation.mode === "skeleton-v3" || asset.animation.mode === "pixminimax") {
15781
15858
  throw new Error(`assets.${assetId}: objectPro animations have no "${asset.animation.mode}" mode; use "v3" or "pro"`);
15782
15859
  }
15783
15860
  const pose = async (rel, what) => {
@@ -17532,10 +17609,15 @@ async function buildPlan(specs, lock, opts = {}) {
17532
17609
  } else if (spec.mirror && entry.status === "downloaded" && entry.outputs.some((_output, index) => !(0, import_node_fs16.existsSync)(currentEntryOutputPath(entry, spec, index)))) {
17533
17610
  state = "stale";
17534
17611
  reason = "mirror output missing on disk; flip it again (no generation cost)";
17535
- } else if (spec.character?.kind === "outfit" && entry.outfit?.sourceSha256 !== mirrorSourceHash(lock.entries[lockKey(spec.styleId, spec.character.parentAssetId)] ?? { outputs: [] })) {
17612
+ } else if (
17613
+ // A mirror carries its source's character shape, but it is a flip of
17614
+ // the source's files: whether it is current is the check above, never
17615
+ // the outfit or layer rule its source answers to (#418).
17616
+ !spec.mirror && spec.character?.kind === "outfit" && entry.outfit?.sourceSha256 !== mirrorSourceHash(lock.entries[lockKey(spec.styleId, spec.character.parentAssetId)] ?? { outputs: [] })
17617
+ ) {
17536
17618
  state = "stale";
17537
17619
  reason = `outfit source ${spec.character.parentAssetId} changed; re-clothe the loop again`;
17538
- } else if (spec.character?.kind === "layer" && changedLayerSource(spec, entry, lock)) {
17620
+ } else if (!spec.mirror && spec.character?.kind === "layer" && changedLayerSource(spec, entry, lock)) {
17539
17621
  state = "stale";
17540
17622
  reason = isHeldItem(spec) ? `layer source ${changedLayerSource(spec, entry, lock)} changed; place the item again (no generation cost)` : `layer source ${changedLayerSource(spec, entry, lock)} changed; dress the frames again`;
17541
17623
  } else if (isHeldItem(spec) && entry.status === "downloaded" && entry.outputs.some((_output, index) => !(0, import_node_fs16.existsSync)(currentEntryOutputPath(entry, spec, index)))) {
@@ -17603,6 +17685,7 @@ async function buildPlan(specs, lock, opts = {}) {
17603
17685
  }
17604
17686
  const isActionable = (i) => i.state === "missing" || i.state === "stale" || i.state === "failed";
17605
17687
  const stateOf = new Map(items.map((i) => [i.key, i.state]));
17688
+ const waiting = /* @__PURE__ */ new Set();
17606
17689
  for (const item of items) {
17607
17690
  if (!isActionable(item)) continue;
17608
17691
  for (const parent of dependencies(item.spec)) {
@@ -17611,11 +17694,35 @@ async function buildPlan(specs, lock, opts = {}) {
17611
17694
  if (parentState && isActionable({ state: parentState })) {
17612
17695
  item.state = "blocked";
17613
17696
  item.reason = `parent ${parentKey} is being generated in this run; this follows in the next wave`;
17697
+ waiting.add(item.key);
17614
17698
  break;
17615
17699
  }
17616
17700
  if ((item.spec.mirror || item.spec.derive || isHeldItem(item.spec)) && (parentState === "recoverable" || parentState === "in-flight")) {
17617
17701
  item.state = "blocked";
17618
17702
  item.reason = `mirror source ${parentKey} is ${parentState}; this follows in the next wave`;
17703
+ waiting.add(item.key);
17704
+ break;
17705
+ }
17706
+ }
17707
+ }
17708
+ const byKey = new Map(items.map((i) => [i.key, i]));
17709
+ for (let changed = true; changed; ) {
17710
+ changed = false;
17711
+ for (const item of items) {
17712
+ if (item.state !== "blocked" || waiting.has(item.key)) continue;
17713
+ for (const parent of dependencies(item.spec)) {
17714
+ const parentKey = lockKey(parent.styleId, parent.assetId);
17715
+ const parentItem = byKey.get(parentKey);
17716
+ if (!parentItem || !item.reason.includes(`${parentKey} is not ready`)) continue;
17717
+ if (isActionable(parentItem)) {
17718
+ item.reason = `waits for ${parentKey}, which this run generates first; follows in a later wave (${item.reason})`;
17719
+ } else if (waiting.has(parentKey)) {
17720
+ item.reason = `waits for ${parentKey}, which itself follows in a later wave of this run (${item.reason})`;
17721
+ } else {
17722
+ continue;
17723
+ }
17724
+ waiting.add(item.key);
17725
+ changed = true;
17619
17726
  break;
17620
17727
  }
17621
17728
  }
@@ -20332,6 +20439,9 @@ async function fetchAssets(provider, specs, lock, lockPath, opts = {}) {
20332
20439
  if (processed.changed) rawHash = sha256(raw);
20333
20440
  if (processed.moved?.clipped) log(` moved ${import_node_path30.default.relative(process.cwd(), target)}: ${processed.moved.clipped} pixels fell off the canvas; raise layer.padding to keep them`);
20334
20441
  if (processed.removed) log(` cleaned ${import_node_path30.default.relative(process.cwd(), target)} (${processed.removed} ghost pixels)`);
20442
+ if (processed.removed && processed.opaque && processed.removed > processed.opaque * CLEAN_DAMAGE_SHARE) {
20443
+ log(` warning: cleaning took ${processed.removed} of ${processed.opaque} opaque pixels (${(100 * processed.removed / processed.opaque).toFixed(1)}%) from ${import_node_path30.default.relative(process.cwd(), target)}; check the frame for holes, and set clean: false then fetch to restore the provider's bytes`);
20444
+ }
20335
20445
  if (processed.snapped) log(` snapped ${import_node_path30.default.relative(process.cwd(), target)} to ${wanted.palette.colors.length} colours`);
20336
20446
  }
20337
20447
  if (cacheDir) await cacheMedia(cacheDir, buf, mediaType);
@@ -23270,12 +23380,12 @@ async function adopt(provider, specs, lock, lockPath, opts = {}) {
23270
23380
  provider: provider.id
23271
23381
  });
23272
23382
  matched++;
23273
- log(` adopted ${key3} \u2190 ${obj.id}`);
23383
+ log(` ${opts.dryRun ? "would adopt" : "adopted"} ${key3} \u2190 ${obj.id}`);
23274
23384
  }
23275
23385
  }
23276
23386
  }
23277
23387
  await Promise.all(Array.from({ length: Math.min(concurrency, remote.length || 1) }, worker));
23278
- await saveLock(lockPath, lock);
23388
+ if (!opts.dryRun) await saveLock(lockPath, lock);
23279
23389
  if (!opts.noCache) {
23280
23390
  pruneCache(cache, new Set(remote.map((o) => o.id)));
23281
23391
  await saveCache(cachePath, cache);
@@ -23312,8 +23422,9 @@ async function tagAdopted(provider, specs, lock, opts = {}) {
23312
23422
  var import_node_fs35 = require("fs");
23313
23423
  var import_promises26 = require("fs/promises");
23314
23424
  var import_node_path38 = __toESM(require("path"), 1);
23315
- function buildImportedEntry(spec, bytes, opts = {}, now = /* @__PURE__ */ new Date()) {
23425
+ function buildImportedEntry(spec, bytes, opts = {}, now = /* @__PURE__ */ new Date(), frames) {
23316
23426
  const png = decodePng(bytes);
23427
+ for (const frame of frames ?? []) decodePng(frame.bytes);
23317
23428
  const at2 = now.toISOString();
23318
23429
  const origin = {
23319
23430
  ...opts.tool ? { tool: opts.tool } : {},
@@ -23338,7 +23449,14 @@ function buildImportedEntry(spec, bytes, opts = {}, now = /* @__PURE__ */ new Da
23338
23449
  error: null,
23339
23450
  sourceUrl: null,
23340
23451
  sourceUrls: [],
23341
- outputs: [{ path: portableOutputPath(spec.outFile, spec.root), sha256: sha256(bytes) }],
23452
+ // A frame set is recorded the way fetch records one: an output per frame,
23453
+ // in order, each with its `frame-NN` role, so `plan` resolves the same paths.
23454
+ outputs: frames?.length ? frames.map((frame) => ({
23455
+ path: portableOutputPath(frame.file, spec.root),
23456
+ sha256: sha256(frame.bytes),
23457
+ role: frame.role,
23458
+ mediaType: MediaType.PNG
23459
+ })) : [{ path: portableOutputPath(spec.outFile, spec.root), sha256: sha256(bytes) }],
23342
23460
  submittedAt: null,
23343
23461
  downloadedAt: at2,
23344
23462
  cost: opts.cost ?? 0,
@@ -23353,6 +23471,32 @@ function buildImportedEntry(spec, bytes, opts = {}, now = /* @__PURE__ */ new Da
23353
23471
  }
23354
23472
  };
23355
23473
  }
23474
+ var frameRole2 = (index) => `frame-${String(index).padStart(2, "0")}`;
23475
+ async function findFrames(spec) {
23476
+ const at2 = (index) => memberPath(spec.outFile, frameRole2(index), 0, 2, MediaType.PNG);
23477
+ const base = import_node_path38.default.basename(at2(0)).replace(/00\.png$/, "");
23478
+ let names = [];
23479
+ try {
23480
+ names = await (0, import_promises26.readdir)(import_node_path38.default.dirname(spec.outFile));
23481
+ } catch {
23482
+ names = [];
23483
+ }
23484
+ const found = /* @__PURE__ */ new Set();
23485
+ for (const name of names) {
23486
+ if (!name.startsWith(base)) continue;
23487
+ const match = /^(\d+)\.png$/i.exec(name.slice(base.length));
23488
+ if (match) found.add(Number(match[1]));
23489
+ }
23490
+ const expected = spec.revision?.frames;
23491
+ const expectsFrames = expected !== void 0 || spec.generator === "frames";
23492
+ if (!found.size && !expectsFrames) return null;
23493
+ const highest = found.size ? Math.max(...found) : -1;
23494
+ const upTo = Math.max(highest + 1, expected ?? 0, expectsFrames ? 1 : 0);
23495
+ const missing = [];
23496
+ for (let index = 0; index < upTo; index++) if (!found.has(index)) missing.push(at2(index));
23497
+ if (missing.length) return { missing };
23498
+ return { files: Array.from({ length: upTo }, (_, index) => ({ role: frameRole2(index), file: at2(index) })) };
23499
+ }
23356
23500
  function unimportable(spec) {
23357
23501
  if (spec.character) return "a character is several files; import it with account adopt";
23358
23502
  if (spec.vfx) return "an effect is rendered from its recipe, not imported";
@@ -23385,9 +23529,18 @@ async function importLocal(specs, lock, lockPath, opts = {}) {
23385
23529
  skipped.push({ key: key3, reason });
23386
23530
  continue;
23387
23531
  }
23532
+ let frameFiles;
23388
23533
  if (!(0, import_node_fs35.existsSync)(spec.outFile)) {
23389
- skipped.push({ key: key3, reason: `no file at ${spec.outFile}` });
23390
- continue;
23534
+ const frames2 = await findFrames(spec);
23535
+ if (!frames2) {
23536
+ skipped.push({ key: key3, reason: `no file at ${spec.outFile}` });
23537
+ continue;
23538
+ }
23539
+ if ("missing" in frames2) {
23540
+ skipped.push({ key: key3, reason: `frame set is missing ${frames2.missing.map((file) => import_node_path38.default.basename(file)).join(", ")} (in ${import_node_path38.default.dirname(spec.outFile)})` });
23541
+ continue;
23542
+ }
23543
+ frameFiles = frames2.files;
23391
23544
  }
23392
23545
  if (lock.entries[key3] && !opts.force) {
23393
23546
  skipped.push({ key: key3, reason: "already in the lockfile (use --force to replace it)" });
@@ -23395,9 +23548,11 @@ async function importLocal(specs, lock, lockPath, opts = {}) {
23395
23548
  }
23396
23549
  let patch;
23397
23550
  let bytes;
23551
+ let frames;
23398
23552
  try {
23399
- bytes = await (0, import_promises26.readFile)(spec.outFile);
23400
- patch = buildImportedEntry(spec, bytes, { ...opts, rawSha256 }, /* @__PURE__ */ new Date());
23553
+ frames = frameFiles ? await Promise.all(frameFiles.map(async (frame) => ({ ...frame, bytes: await (0, import_promises26.readFile)(frame.file) }))) : void 0;
23554
+ bytes = frames ? frames[0].bytes : await (0, import_promises26.readFile)(spec.outFile);
23555
+ patch = buildImportedEntry(spec, bytes, { ...opts, rawSha256 }, /* @__PURE__ */ new Date(), frames);
23401
23556
  } catch (error) {
23402
23557
  skipped.push({ key: key3, reason: `invalid PNG: ${error instanceof Error ? error.message : String(error)}` });
23403
23558
  continue;
@@ -23407,9 +23562,10 @@ async function importLocal(specs, lock, lockPath, opts = {}) {
23407
23562
  continue;
23408
23563
  }
23409
23564
  const existing = lock.entries[key3];
23410
- const history = existing?.outputs[0]?.sha256 === sha256(bytes) ? existing.history : historyAfterReplacing(existing, opts.historyLimit ?? DEFAULT_HISTORY_LIMIT, patch.downloadedAt ?? (/* @__PURE__ */ new Date()).toISOString());
23565
+ const sameBytes = existing !== void 0 && existing.outputs.length === patch.outputs.length && existing.outputs.every((output, index) => output.sha256 === patch.outputs[index].sha256);
23566
+ const history = sameBytes ? existing.history : historyAfterReplacing(existing, opts.historyLimit ?? DEFAULT_HISTORY_LIMIT, patch.downloadedAt ?? (/* @__PURE__ */ new Date()).toISOString());
23411
23567
  if (cacheDir) {
23412
- await cacheMedia(cacheDir, bytes, MediaType.PNG);
23568
+ for (const member of frames ?? [{ bytes }]) await cacheMedia(cacheDir, member.bytes, MediaType.PNG);
23413
23569
  if (rawBytes) await cacheMedia(cacheDir, rawBytes, MediaType.PNG);
23414
23570
  }
23415
23571
  imported.push({ key: key3, entry: upsert(lock, key3, {
@@ -25375,7 +25531,8 @@ var NewAnimationSchema = import_zod9.z.object({
25375
25531
  /** A PixelLab template id (`character` only; `objectPro` has no template concept). */
25376
25532
  template: import_zod9.z.string().min(1).optional(),
25377
25533
  direction: CharacterDirectionSchema.optional(),
25378
- frames: import_zod9.z.number().int().min(4).max(16).optional(),
25534
+ /** 4 to 16; a pixminimax loop takes a multiple of 4 up to 40. The manifest's own schema checks the rest. */
25535
+ frames: import_zod9.z.number().int().min(4).max(40).optional(),
25379
25536
  fps: import_zod9.z.number().int().min(1).max(60).optional(),
25380
25537
  /** One loop per named direction, plus free mirrors; expanded when the manifest loads. */
25381
25538
  directions: import_zod9.z.array(CharacterDirectionSchema).min(1).optional(),