pixelkiln 0.99.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
@@ -1788,6 +1788,17 @@ var AssetSchema = import_zod.z.object({
1788
1788
  * (a sword hand, a parted fringe) comes out the other way round.
1789
1789
  */
1790
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(),
1791
1802
  /**
1792
1803
  * `terrain` styles only: a PNG per terrain for PixelLab to take that
1793
1804
  * terrain's look from, paths relative to the manifest. Top-down sets
@@ -1851,6 +1862,13 @@ var AssetSchema = import_zod.z.object({
1851
1862
  path: [shapes[1]]
1852
1863
  });
1853
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
+ }
1854
1872
  for (const shape of ["derive", "external"]) {
1855
1873
  if (asset[shape] && (asset.source || Object.keys(asset.sourceByStyle).length)) {
1856
1874
  context.addIssue({
@@ -2967,6 +2985,10 @@ var PixelLabClient = class {
2967
2985
  if (args.outline) body.outline = args.outline;
2968
2986
  if (args.shading) body.shading = args.shading;
2969
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
+ }
2970
2992
  if (args.seed != null) body.seed = args.seed;
2971
2993
  if (args.scene) {
2972
2994
  const encode = (image) => ({ type: "base64", base64: image.base64, format: image.format });
@@ -3135,6 +3157,10 @@ var PixelLabClient = class {
3135
3157
  if (args.outline) body.outline = args.outline;
3136
3158
  if (args.shading) body.shading = args.shading;
3137
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
+ }
3138
3164
  if (args.seed != null) body.seed = args.seed;
3139
3165
  return validateResponse(
3140
3166
  IsometricTileSubmitSchema,
@@ -3259,6 +3285,10 @@ var PixelLabClient = class {
3259
3285
  if (args.paletteSwatchBase64) {
3260
3286
  body.color_image = { type: "base64", base64: args.paletteSwatchBase64, format: "png" };
3261
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
+ }
3262
3292
  if (args.seed != null) body.seed = args.seed;
3263
3293
  const res = validateResponse(
3264
3294
  PixfluxResponseSchema,
@@ -5082,6 +5112,8 @@ function specHash(spec, styleImageHashes, providerOptionIdentity = spec.provider
5082
5112
  terrainEnhance: spec.terrainEnhance,
5083
5113
  terrainPlatformThickness: spec.terrainPlatformThickness,
5084
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,
5085
5117
  terrainReferences: spec.terrainReferences && Object.keys(spec.terrainReferences).length ? Object.fromEntries(
5086
5118
  ["lower", "upper", "transition"].flatMap((side) => {
5087
5119
  const reference = spec.terrainReferences[side];
@@ -7523,7 +7555,8 @@ var PixelLabProvider = class _PixelLabProvider {
7523
7555
  height: spec.height,
7524
7556
  noBackground: spec.noBackground,
7525
7557
  paletteSwatchBase64: swatch,
7526
- seed: spec.seed
7558
+ seed: spec.seed,
7559
+ ...await initImageArgs(spec)
7527
7560
  });
7528
7561
  const jobId = (0, import_node_crypto2.randomUUID)();
7529
7562
  (0, import_node_fs4.writeFileSync)(import_node_path3.default.join(_PixelLabProvider.cacheDir(), `${jobId}.png`), png);
@@ -7636,7 +7669,8 @@ var PixelLabProvider = class _PixelLabProvider {
7636
7669
  outline: spec.outline,
7637
7670
  shading: spec.shading,
7638
7671
  detail: spec.detail,
7639
- seed: spec.seed
7672
+ seed: spec.seed,
7673
+ ...await initImageArgs(spec)
7640
7674
  });
7641
7675
  return { jobId: res2.tile_id, metadata: { backgroundJobId: res2.background_job_id } };
7642
7676
  }
@@ -7680,6 +7714,7 @@ var PixelLabProvider = class _PixelLabProvider {
7680
7714
  shading: spec.shading,
7681
7715
  detail: spec.detail,
7682
7716
  seed: spec.seed,
7717
+ ...await initImageArgs(spec),
7683
7718
  scene: spec.scene ? mapScenePayload(spec) : void 0
7684
7719
  });
7685
7720
  return { jobId: res.object_id, metadata: { backgroundJobId: res.background_job_id } };
@@ -8808,6 +8843,16 @@ function sendsTargetPalette(spec) {
8808
8843
  return false;
8809
8844
  }
8810
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
+ }
8811
8856
  async function terrainReferenceImage(spec, side) {
8812
8857
  const reference = spec.terrainReferences?.[side];
8813
8858
  if (!reference) return void 0;
@@ -12546,6 +12591,23 @@ async function resolveSpecs(loaded, filter) {
12546
12591
  }
12547
12592
  resolved.terrainConnect = links;
12548
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
+ }
12549
12611
  if (asset.terrainReferences) {
12550
12612
  if (resolved.generator !== "terrain") {
12551
12613
  throw new Error(`assets.${assetId}.terrainReferences: only a terrain set takes terrain references; style "${styleId}" uses "${resolved.generator}"`);