@enslo/sd-metadata 1.7.0 → 1.7.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/README.ja.md CHANGED
@@ -149,7 +149,7 @@ if (result.status === 'success') {
149
149
  > 本番環境では `@latest` の代わりに特定のバージョンを指定してください:
150
150
  >
151
151
  > ```text
152
- > https://cdn.jsdelivr.net/npm/@enslo/sd-metadata@1.7.0/dist/index.js
152
+ > https://cdn.jsdelivr.net/npm/@enslo/sd-metadata@1.7.1/dist/index.js
153
153
  > ```
154
154
 
155
155
  ### 応用例
package/README.md CHANGED
@@ -148,7 +148,7 @@ if (result.status === 'success') {
148
148
  > For production use, pin to a specific version instead of `@latest`:
149
149
  >
150
150
  > ```text
151
- > https://cdn.jsdelivr.net/npm/@enslo/sd-metadata@1.7.0/dist/index.js
151
+ > https://cdn.jsdelivr.net/npm/@enslo/sd-metadata@1.7.1/dist/index.js
152
152
  > ```
153
153
 
154
154
  ### Advanced Examples
package/dist/index.js CHANGED
@@ -1993,6 +1993,12 @@ function createEncodedChunk(keyword, text, strategy) {
1993
1993
  }
1994
1994
  }
1995
1995
  }
1996
+ function createEncodedChunks(entries, encodingMap) {
1997
+ return entries.flatMap(([keyword, text]) => {
1998
+ const strategy = encodingMap[keyword] ?? encodingMap.default;
1999
+ return createEncodedChunk(keyword, text, strategy);
2000
+ });
2001
+ }
1996
2002
 
1997
2003
  // src/converters/a1111.ts
1998
2004
  function convertA1111PngToSegments(chunks) {
@@ -2049,7 +2055,7 @@ function convertCivitaiSegmentsToPng(segments) {
2049
2055
  if (!isJson) {
2050
2056
  return convertA1111SegmentsToPng(segments);
2051
2057
  }
2052
- return createEncodedChunk("prompt", userComment.data, "text-utf8-raw");
2058
+ return createEncodedChunk("prompt", userComment.data, "text-unicode-escape");
2053
2059
  }
2054
2060
 
2055
2061
  // src/converters/base-json.ts
@@ -2109,7 +2115,7 @@ var tryParseExtendedFormat = (segments) => {
2109
2115
  ];
2110
2116
  };
2111
2117
  var tryParseSaveImagePlusFormat = (segments) => {
2112
- const chunks = convertKvSegmentsToPng(segments, "text-utf8-raw");
2118
+ const chunks = convertKvSegmentsToPng(segments, "text-unicode-escape");
2113
2119
  return chunks.length > 0 ? chunks : null;
2114
2120
  };
2115
2121
  function convertComfyUISegmentsToPng(segments) {
@@ -2249,6 +2255,39 @@ function createSegmentsToPng(keyword, encodingStrategy) {
2249
2255
  };
2250
2256
  }
2251
2257
 
2258
+ // src/converters/stability-matrix.ts
2259
+ var STABILITY_MATRIX_ENCODING = {
2260
+ parameters: "text-utf8-raw",
2261
+ default: "text-unicode-escape"
2262
+ };
2263
+ function convertStabilityMatrixPngToSegments(chunks) {
2264
+ const data = {};
2265
+ for (const chunk of chunks) {
2266
+ const parsed = parseJson(chunk.text);
2267
+ data[chunk.keyword] = parsed.ok ? parsed.value : chunk.text;
2268
+ }
2269
+ return [
2270
+ {
2271
+ source: { type: "exifUserComment" },
2272
+ data: JSON.stringify(data)
2273
+ }
2274
+ ];
2275
+ }
2276
+ function convertStabilityMatrixSegmentsToPng(segments) {
2277
+ const userComment = findSegment(segments, "exifUserComment");
2278
+ if (!userComment) return [];
2279
+ const parsed = parseJson(userComment.data);
2280
+ if (!parsed.ok || parsed.type !== "object") return [];
2281
+ const value = parsed.value;
2282
+ const entries = Object.entries(value).map(
2283
+ ([key, val]) => {
2284
+ const text = stringify(val);
2285
+ return [key, text !== void 0 ? unescapeUnicode(text) : void 0];
2286
+ }
2287
+ );
2288
+ return createEncodedChunks(entries, STABILITY_MATRIX_ENCODING);
2289
+ }
2290
+
2252
2291
  // src/converters/swarmui.ts
2253
2292
  function convertSwarmUIPngToSegments(chunks) {
2254
2293
  const parametersChunk = chunks.find((c) => c.keyword === "parameters");
@@ -2283,6 +2322,39 @@ function convertSwarmUISegmentsToPng(segments) {
2283
2322
  return chunks;
2284
2323
  }
2285
2324
 
2325
+ // src/converters/tensorart.ts
2326
+ var TENSORART_ENCODING = {
2327
+ generation_data: "text-utf8-raw",
2328
+ default: "text-unicode-escape"
2329
+ };
2330
+ function convertTensorArtPngToSegments(chunks) {
2331
+ const data = {};
2332
+ for (const chunk of chunks) {
2333
+ const parsed = parseJson(chunk.text);
2334
+ data[chunk.keyword] = parsed.ok ? parsed.value : chunk.text;
2335
+ }
2336
+ return [
2337
+ {
2338
+ source: { type: "exifUserComment" },
2339
+ data: JSON.stringify(data)
2340
+ }
2341
+ ];
2342
+ }
2343
+ function convertTensorArtSegmentsToPng(segments) {
2344
+ const userComment = findSegment(segments, "exifUserComment");
2345
+ if (!userComment) return [];
2346
+ const parsed = parseJson(userComment.data);
2347
+ if (!parsed.ok || parsed.type !== "object") return [];
2348
+ const value = parsed.value;
2349
+ const entries = Object.entries(value).map(
2350
+ ([key, val]) => {
2351
+ const text = stringify(val);
2352
+ return [key, text !== void 0 ? unescapeUnicode(text) : void 0];
2353
+ }
2354
+ );
2355
+ return createEncodedChunks(entries, TENSORART_ENCODING);
2356
+ }
2357
+
2286
2358
  // src/converters/index.ts
2287
2359
  function convertMetadata(parseResult, targetFormat) {
2288
2360
  if (parseResult.status === "empty") {
@@ -2370,6 +2442,14 @@ var convertCivitai = createFormatConverter(
2370
2442
  convertCivitaiPngToSegments,
2371
2443
  convertCivitaiSegmentsToPng
2372
2444
  );
2445
+ var convertStabilityMatrix = createFormatConverter(
2446
+ convertStabilityMatrixPngToSegments,
2447
+ convertStabilityMatrixSegmentsToPng
2448
+ );
2449
+ var convertTensorArt = createFormatConverter(
2450
+ convertTensorArtPngToSegments,
2451
+ convertTensorArtSegmentsToPng
2452
+ );
2373
2453
  var softwareConverters = {
2374
2454
  // NovelAI
2375
2455
  novelai: convertNovelai,
@@ -2380,10 +2460,12 @@ var softwareConverters = {
2380
2460
  "forge-neo": convertA1111,
2381
2461
  // CivitAI Orchestration format
2382
2462
  civitai: convertCivitai,
2383
- // ComfyUI-format (comfyui, tensorart, stability-matrix)
2463
+ // ComfyUI-format
2384
2464
  comfyui: convertComfyUI,
2385
- tensorart: convertComfyUI,
2386
- "stability-matrix": convertComfyUI,
2465
+ // TensorArt (per-chunk encoding: generation_data uses raw UTF-8)
2466
+ tensorart: convertTensorArt,
2467
+ // Stability Matrix (per-chunk encoding: parameters uses raw UTF-8)
2468
+ "stability-matrix": convertStabilityMatrix,
2387
2469
  // Easy Diffusion
2388
2470
  easydiffusion: convertEasyDiffusion,
2389
2471
  // Fooocus variants