pixelkiln 0.98.0 → 0.100.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.cjs CHANGED
@@ -106,9 +106,12 @@ __export(index_exports, {
106
106
  MediaType: () => MediaType,
107
107
  NORMAL_MAP_CONVENTIONS: () => NORMAL_MAP_CONVENTIONS,
108
108
  NORMAL_MAP_COST_GENERATIONS: () => NORMAL_MAP_COST_GENERATIONS,
109
+ NORMAL_MAP_KINDS: () => NORMAL_MAP_KINDS,
109
110
  NORMAL_MAP_MAX_FRAMES: () => NORMAL_MAP_MAX_FRAMES,
110
111
  NORMAL_MAP_MAX_SIDE: () => NORMAL_MAP_MAX_SIDE,
111
112
  NORMAL_MAP_MIN_SIDE: () => NORMAL_MAP_MIN_SIDE,
113
+ NORMAL_MAP_MODES: () => NORMAL_MAP_MODES,
114
+ NORMAL_MAP_SHAPE_RANGES: () => NORMAL_MAP_SHAPE_RANGES,
112
115
  NormalMapConventionSchema: () => NormalMapConventionSchema,
113
116
  OverwriteRefusedError: () => OverwriteRefusedError,
114
117
  PIXELATE_COST_GENERATIONS: () => PIXELATE_COST_GENERATIONS,
@@ -276,6 +279,7 @@ __export(index_exports, {
276
279
  mountStyle: () => mountStyle,
277
280
  musicCost: () => musicCost,
278
281
  musicOutputPaths: () => musicOutputPaths,
282
+ normalMapCost: () => normalMapCost,
279
283
  normalMapFile: () => normalMapFile,
280
284
  normalMapResultPng: () => normalMapResultPng,
281
285
  normalMapSizeProblem: () => normalMapSizeProblem,
@@ -961,6 +965,24 @@ var RevisionSchema = import_zod.z.object({
961
965
  removalTask: import_zod.z.enum(["simple", "complex"]).optional(),
962
966
  /** `normal-map` only: `opengl` (green up; PixelLab's default) or `directx` (green down, for Unreal). */
963
967
  convention: NormalMapConventionSchema.optional(),
968
+ /**
969
+ * `normal-map` only: `lite` (PixelLab's default, 0.1 generation) makes the
970
+ * map from the art alone; `pro` (0.5) plans each part's shape, what is in
971
+ * front and what is sunk.
972
+ */
973
+ normalMapMode: import_zod.z.enum(["lite", "pro"]).optional(),
974
+ /** `normal-map` only: what the picture is. Left out, PixelLab reads it from the picture; set it for sidescroller, isometric and UI art. */
975
+ normalMapKind: import_zod.z.enum(["character", "object", "topdown", "side", "iso", "ui"]).optional(),
976
+ /** `normal-map` only: how far every pixel tilts away from facing the viewer, 0 to 2 (the API refuses more). */
977
+ normalMapStrength: import_zod.z.number().min(0).max(2).optional(),
978
+ /** `normal-map` only: how much the outline rounds off, 0 to 3; 0 keeps it flat to the edge. */
979
+ outlineRounding: import_zod.z.number().min(0).max(3).optional(),
980
+ /** `normal-map` only: how much the sprite's 3D parts (a round head, an arm) add, 0 to 2. */
981
+ partShapes: import_zod.z.number().min(0).max(2).optional(),
982
+ /** `normal-map` only: the art's own light and dark as bumps, 0 to 2; 0 for a smooth surface. */
983
+ surfaceDetail: import_zod.z.number().min(0).max(2).optional(),
984
+ /** `normal-map` only: how far that detail is blurred, 0.6 to 3 px. */
985
+ detailSoftness: import_zod.z.number().min(0.6).max(3).optional(),
964
986
  /**
965
987
  * `animate-skeleton`: what the character *looks like*, a noun
966
988
  * phrase (colours, clothing, held items) — distinct from the asset's
@@ -1121,6 +1143,15 @@ var RevisionSchema = import_zod.z.object({
1121
1143
  path: ["convention"]
1122
1144
  });
1123
1145
  }
1146
+ for (const field of ["normalMapMode", "normalMapKind", "normalMapStrength", "outlineRounding", "partShapes", "surfaceDetail", "detailSoftness"]) {
1147
+ if (revision[field] !== void 0 && revision.mode !== "normal-map") {
1148
+ context.addIssue({
1149
+ code: import_zod.z.ZodIssueCode.custom,
1150
+ message: `${field} applies to normal-map revisions only`,
1151
+ path: [field]
1152
+ });
1153
+ }
1154
+ }
1124
1155
  if (revision.description !== void 0 && revision.mode !== "animate-skeleton" && revision.mode !== "remove-background") {
1125
1156
  context.addIssue({
1126
1157
  code: import_zod.z.ZodIssueCode.custom,
@@ -1757,6 +1788,17 @@ var AssetSchema = import_zod.z.object({
1757
1788
  * (a sword hand, a parted fringe) comes out the other way round.
1758
1789
  */
1759
1790
  mirror: import_zod.z.string().min(1).optional(),
1791
+ /**
1792
+ * `pixflux`, `map` and `isometricTile` styles: a PNG to start the drawing
1793
+ * from, relative to the manifest. PixelLab reworks it toward the prompt
1794
+ * instead of starting from nothing.
1795
+ */
1796
+ initImage: import_zod.z.string().min(1).optional(),
1797
+ /**
1798
+ * With `initImage`: how strongly the starting image holds, 1 to 999.
1799
+ * PixelLab's default is 300.
1800
+ */
1801
+ initImageStrength: import_zod.z.number().int().min(1).max(999).optional(),
1760
1802
  /**
1761
1803
  * `terrain` styles only: a PNG per terrain for PixelLab to take that
1762
1804
  * terrain's look from, paths relative to the manifest. Top-down sets
@@ -1820,6 +1862,13 @@ var AssetSchema = import_zod.z.object({
1820
1862
  path: [shapes[1]]
1821
1863
  });
1822
1864
  }
1865
+ if (asset.initImageStrength !== void 0 && !asset.initImage) {
1866
+ context.addIssue({
1867
+ code: import_zod.z.ZodIssueCode.custom,
1868
+ message: "initImageStrength sets how strongly initImage holds; add an initImage or drop it",
1869
+ path: ["initImageStrength"]
1870
+ });
1871
+ }
1823
1872
  for (const shape of ["derive", "external"]) {
1824
1873
  if (asset[shape] && (asset.source || Object.keys(asset.sourceByStyle).length)) {
1825
1874
  context.addIssue({
@@ -2831,6 +2880,14 @@ function targetPaletteBody(palette) {
2831
2880
  }
2832
2881
  };
2833
2882
  }
2883
+ var NORMAL_MAP_MODES = ["lite", "pro"];
2884
+ var NORMAL_MAP_KINDS = ["character", "object", "topdown", "side", "iso", "ui"];
2885
+ var NORMAL_MAP_SHAPE_RANGES = {
2886
+ outlineRounding: [0, 3],
2887
+ partShapes: [0, 2],
2888
+ surfaceDetail: [0, 2],
2889
+ detailSoftness: [0.6, 3]
2890
+ };
2834
2891
  var PixelLabClient = class {
2835
2892
  constructor(apiKey, timeoutMs = 12e4) {
2836
2893
  this.apiKey = apiKey;
@@ -2928,6 +2985,10 @@ var PixelLabClient = class {
2928
2985
  if (args.outline) body.outline = args.outline;
2929
2986
  if (args.shading) body.shading = args.shading;
2930
2987
  if (args.detail) body.detail = args.detail;
2988
+ if (args.initImage) {
2989
+ body.init_image = { type: "base64", base64: args.initImage.base64, format: args.initImage.format };
2990
+ if (args.initImageStrength != null) body.init_image_strength = args.initImageStrength;
2991
+ }
2931
2992
  if (args.seed != null) body.seed = args.seed;
2932
2993
  if (args.scene) {
2933
2994
  const encode = (image) => ({ type: "base64", base64: image.base64, format: image.format });
@@ -3096,6 +3157,10 @@ var PixelLabClient = class {
3096
3157
  if (args.outline) body.outline = args.outline;
3097
3158
  if (args.shading) body.shading = args.shading;
3098
3159
  if (args.detail) body.detail = args.detail;
3160
+ if (args.initImage) {
3161
+ body.init_image = { type: "base64", base64: args.initImage.base64, format: args.initImage.format };
3162
+ if (args.initImageStrength != null) body.init_image_strength = args.initImageStrength;
3163
+ }
3099
3164
  if (args.seed != null) body.seed = args.seed;
3100
3165
  return validateResponse(
3101
3166
  IsometricTileSubmitSchema,
@@ -3220,6 +3285,10 @@ var PixelLabClient = class {
3220
3285
  if (args.paletteSwatchBase64) {
3221
3286
  body.color_image = { type: "base64", base64: args.paletteSwatchBase64, format: "png" };
3222
3287
  }
3288
+ if (args.initImage) {
3289
+ body.init_image = { type: "base64", base64: args.initImage.base64, format: args.initImage.format };
3290
+ if (args.initImageStrength != null) body.init_image_strength = args.initImageStrength;
3291
+ }
3223
3292
  if (args.seed != null) body.seed = args.seed;
3224
3293
  const res = validateResponse(
3225
3294
  PixfluxResponseSchema,
@@ -3909,8 +3978,15 @@ var PixelLabClient = class {
3909
3978
  */
3910
3979
  async normalMap(args) {
3911
3980
  const body = { image: args.image };
3981
+ if (args.mode) body.mode = args.mode;
3982
+ if (args.kind) body.kind = args.kind;
3983
+ if (args.shape?.strength != null) body.strength = args.shape.strength;
3912
3984
  if (args.frames != null && args.frames !== 1) body.frames = args.frames;
3913
3985
  if (args.convention) body.convention = args.convention;
3986
+ if (args.shape?.outlineRounding != null) body.outline_rounding = args.shape.outlineRounding;
3987
+ if (args.shape?.partShapes != null) body.part_shapes = args.shape.partShapes;
3988
+ if (args.shape?.surfaceDetail != null) body.surface_detail = args.shape.surfaceDetail;
3989
+ if (args.shape?.detailSoftness != null) body.detail_softness = args.shape.detailSoftness;
3914
3990
  return validateResponse(
3915
3991
  RevisionJobSubmitSchema,
3916
3992
  await this.request("/normal-map", { method: "POST", body: JSON.stringify(body) }),
@@ -5036,6 +5112,8 @@ function specHash(spec, styleImageHashes, providerOptionIdentity = spec.provider
5036
5112
  terrainEnhance: spec.terrainEnhance,
5037
5113
  terrainPlatformThickness: spec.terrainPlatformThickness,
5038
5114
  // Reference images enter as their bytes' hashes, never their paths.
5115
+ // The starting image by its bytes, with its strength only when set.
5116
+ initImage: spec.initImage ? { sha256: spec.initImage.sha256, strength: spec.initImage.strength } : void 0,
5039
5117
  terrainReferences: spec.terrainReferences && Object.keys(spec.terrainReferences).length ? Object.fromEntries(
5040
5118
  ["lower", "upper", "transition"].flatMap((side) => {
5041
5119
  const reference = spec.terrainReferences[side];
@@ -5174,6 +5252,14 @@ function specHash(spec, styleImageHashes, providerOptionIdentity = spec.provider
5174
5252
  description: spec.revision.description,
5175
5253
  removalTask: spec.revision.removalTask,
5176
5254
  convention: spec.revision.convention,
5255
+ // Each only when set, so normal-map revisions made before them keep their hash.
5256
+ normalMapMode: spec.revision.normalMapMode,
5257
+ normalMapKind: spec.revision.normalMapKind,
5258
+ normalMapStrength: spec.revision.normalMapStrength,
5259
+ outlineRounding: spec.revision.outlineRounding,
5260
+ partShapes: spec.revision.partShapes,
5261
+ surfaceDetail: spec.revision.surfaceDetail,
5262
+ detailSoftness: spec.revision.detailSoftness,
5177
5263
  driftThreshold: spec.revision.driftThreshold,
5178
5264
  subjectDescription: spec.revision.subjectDescription,
5179
5265
  initialPose: spec.revision.initialPose,
@@ -5950,6 +6036,9 @@ async function pixelateFile(client2, input, opts = {}) {
5950
6036
  await sleep3(interval);
5951
6037
  }
5952
6038
  }
6039
+ function normalMapCost(mode2) {
6040
+ return mode2 === "pro" ? 0.5 : 0.1;
6041
+ }
5953
6042
  var NORMAL_MAP_COST_GENERATIONS = 0.5;
5954
6043
  var NORMAL_MAP_MIN_SIDE = 8;
5955
6044
  var NORMAL_MAP_MAX_SIDE = 512;
@@ -5994,7 +6083,10 @@ async function normalMapFile(client2, input, opts = {}) {
5994
6083
  const submitted = await client2.normalMap({
5995
6084
  image: { base64: bytes.toString("base64"), format: "png" },
5996
6085
  frames,
5997
- convention: opts.convention
6086
+ convention: opts.convention,
6087
+ shape: opts.shape,
6088
+ mode: opts.mode,
6089
+ kind: opts.kind
5998
6090
  });
5999
6091
  const jobId = submitted.background_job_id;
6000
6092
  const started = Date.now();
@@ -6259,7 +6351,7 @@ var PixelLabProvider = class _PixelLabProvider {
6259
6351
  return { unit: "generations", amount: 1, candidates: 1 };
6260
6352
  }
6261
6353
  if (spec.revision?.mode === "normal-map") {
6262
- return { unit: "generations", amount: NORMAL_MAP_COST_GENERATIONS, candidates: 1 };
6354
+ return { unit: "generations", amount: normalMapCost(spec.revision.normalMapMode), candidates: 1 };
6263
6355
  }
6264
6356
  if (spec.revision?.mode === "reduce-colors" || spec.revision?.mode === "correct-pixelart") {
6265
6357
  return { unit: "generations", amount: 0.1, candidates: 1 };
@@ -7463,7 +7555,8 @@ var PixelLabProvider = class _PixelLabProvider {
7463
7555
  height: spec.height,
7464
7556
  noBackground: spec.noBackground,
7465
7557
  paletteSwatchBase64: swatch,
7466
- seed: spec.seed
7558
+ seed: spec.seed,
7559
+ ...await initImageArgs(spec)
7467
7560
  });
7468
7561
  const jobId = (0, import_node_crypto2.randomUUID)();
7469
7562
  (0, import_node_fs4.writeFileSync)(import_node_path3.default.join(_PixelLabProvider.cacheDir(), `${jobId}.png`), png);
@@ -7576,7 +7669,8 @@ var PixelLabProvider = class _PixelLabProvider {
7576
7669
  outline: spec.outline,
7577
7670
  shading: spec.shading,
7578
7671
  detail: spec.detail,
7579
- seed: spec.seed
7672
+ seed: spec.seed,
7673
+ ...await initImageArgs(spec)
7580
7674
  });
7581
7675
  return { jobId: res2.tile_id, metadata: { backgroundJobId: res2.background_job_id } };
7582
7676
  }
@@ -7620,6 +7714,7 @@ var PixelLabProvider = class _PixelLabProvider {
7620
7714
  shading: spec.shading,
7621
7715
  detail: spec.detail,
7622
7716
  seed: spec.seed,
7717
+ ...await initImageArgs(spec),
7623
7718
  scene: spec.scene ? mapScenePayload(spec) : void 0
7624
7719
  });
7625
7720
  return { jobId: res.object_id, metadata: { backgroundJobId: res.background_job_id } };
@@ -7733,7 +7828,20 @@ var PixelLabProvider = class _PixelLabProvider {
7733
7828
  }
7734
7829
  if (revision.mode === "normal-map") {
7735
7830
  const strip = roles ? { base64: joinStripPng(images.map((member) => Buffer.from(member.base64, "base64"))).toString("base64"), format: "png" } : image;
7736
- const res2 = await this.client.normalMap({ image: strip, frames: roles?.length ?? 1, convention: revision.convention });
7831
+ const res2 = await this.client.normalMap({
7832
+ image: strip,
7833
+ frames: roles?.length ?? 1,
7834
+ convention: revision.convention,
7835
+ mode: revision.normalMapMode,
7836
+ kind: revision.normalMapKind,
7837
+ shape: {
7838
+ strength: revision.normalMapStrength,
7839
+ outlineRounding: revision.outlineRounding,
7840
+ partShapes: revision.partShapes,
7841
+ surfaceDetail: revision.surfaceDetail,
7842
+ detailSoftness: revision.detailSoftness
7843
+ }
7844
+ });
7737
7845
  return {
7738
7846
  jobId: res2.background_job_id,
7739
7847
  metadata: roles ? { revisionMembers: roles, ...revision.sourceFps != null ? { revisionFps: revision.sourceFps } : {} } : {}
@@ -8735,6 +8843,16 @@ function sendsTargetPalette(spec) {
8735
8843
  return false;
8736
8844
  }
8737
8845
  }
8846
+ async function initImageArgs(spec) {
8847
+ const init = spec.initImage;
8848
+ if (!init) return {};
8849
+ if (!(0, import_node_fs4.existsSync)(init.file)) throw new Error(`init image is missing: ${init.file}`);
8850
+ const bytes = (0, import_node_fs4.readFileSync)(init.file);
8851
+ if (sha256(bytes) !== init.sha256) {
8852
+ throw new Error(`init image changed after the manifest was resolved: ${init.file}; run the command again`);
8853
+ }
8854
+ return { initImage: { base64: bytes.toString("base64"), format: "png" }, ...init.strength == null ? {} : { initImageStrength: init.strength } };
8855
+ }
8738
8856
  async function terrainReferenceImage(spec, side) {
8739
8857
  const reference = spec.terrainReferences?.[side];
8740
8858
  if (!reference) return void 0;
@@ -12392,6 +12510,13 @@ async function resolveSpecs(loaded, filter) {
12392
12510
  ...asset.revision.description ? { description: asset.revision.description } : {},
12393
12511
  ...asset.revision.removalTask ? { removalTask: asset.revision.removalTask } : {},
12394
12512
  ...asset.revision.convention ? { convention: asset.revision.convention } : {},
12513
+ ...asset.revision.normalMapMode ? { normalMapMode: asset.revision.normalMapMode } : {},
12514
+ ...asset.revision.normalMapKind ? { normalMapKind: asset.revision.normalMapKind } : {},
12515
+ ...asset.revision.normalMapStrength == null ? {} : { normalMapStrength: asset.revision.normalMapStrength },
12516
+ ...asset.revision.outlineRounding == null ? {} : { outlineRounding: asset.revision.outlineRounding },
12517
+ ...asset.revision.partShapes == null ? {} : { partShapes: asset.revision.partShapes },
12518
+ ...asset.revision.surfaceDetail == null ? {} : { surfaceDetail: asset.revision.surfaceDetail },
12519
+ ...asset.revision.detailSoftness == null ? {} : { detailSoftness: asset.revision.detailSoftness },
12395
12520
  ...asset.revision.driftThreshold == null ? {} : { driftThreshold: asset.revision.driftThreshold },
12396
12521
  ...asset.revision.subjectDescription ? { subjectDescription: asset.revision.subjectDescription } : {},
12397
12522
  ...asset.revision.initialPose ? { initialPose: asset.revision.initialPose } : {},
@@ -12466,6 +12591,23 @@ async function resolveSpecs(loaded, filter) {
12466
12591
  }
12467
12592
  resolved.terrainConnect = links;
12468
12593
  }
12594
+ if (asset.initImage) {
12595
+ if (!["pixflux", "map", "isometricTile"].includes(resolved.generator)) {
12596
+ throw new Error(
12597
+ `assets.${assetId}.initImage: a starting image is taken by pixflux, map and isometricTile styles; style "${styleId}" uses "${resolved.generator}"`
12598
+ );
12599
+ }
12600
+ const file = import_node_path8.default.resolve(root, asset.initImage);
12601
+ const image = await optionalRevisionImage(file, "init image", "png");
12602
+ if (!image) throw new Error(`assets.${assetId}.initImage: ${asset.initImage} is missing or not a PNG`);
12603
+ resolved.initImage = {
12604
+ file,
12605
+ sha256: image?.hash ?? null,
12606
+ width: image?.width ?? null,
12607
+ height: image?.height ?? null,
12608
+ ...asset.initImageStrength == null ? {} : { strength: asset.initImageStrength }
12609
+ };
12610
+ }
12469
12611
  if (asset.terrainReferences) {
12470
12612
  if (resolved.generator !== "terrain") {
12471
12613
  throw new Error(`assets.${assetId}.terrainReferences: only a terrain set takes terrain references; style "${styleId}" uses "${resolved.generator}"`);
@@ -23479,9 +23621,12 @@ async function workspaceStatus(ws, dir) {
23479
23621
  MediaType,
23480
23622
  NORMAL_MAP_CONVENTIONS,
23481
23623
  NORMAL_MAP_COST_GENERATIONS,
23624
+ NORMAL_MAP_KINDS,
23482
23625
  NORMAL_MAP_MAX_FRAMES,
23483
23626
  NORMAL_MAP_MAX_SIDE,
23484
23627
  NORMAL_MAP_MIN_SIDE,
23628
+ NORMAL_MAP_MODES,
23629
+ NORMAL_MAP_SHAPE_RANGES,
23485
23630
  NormalMapConventionSchema,
23486
23631
  OverwriteRefusedError,
23487
23632
  PIXELATE_COST_GENERATIONS,
@@ -23649,6 +23794,7 @@ async function workspaceStatus(ws, dir) {
23649
23794
  mountStyle,
23650
23795
  musicCost,
23651
23796
  musicOutputPaths,
23797
+ normalMapCost,
23652
23798
  normalMapFile,
23653
23799
  normalMapResultPng,
23654
23800
  normalMapSizeProblem,