@enslo/sd-metadata 1.4.2 → 1.6.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/README.ja.md CHANGED
@@ -117,9 +117,7 @@ fileInput.addEventListener('change', async (e) => {
117
117
  if (!file) return;
118
118
 
119
119
  const arrayBuffer = await file.arrayBuffer();
120
- const imageData = new Uint8Array(arrayBuffer);
121
-
122
- const result = read(imageData);
120
+ const result = read(arrayBuffer);
123
121
 
124
122
  if (result.status === 'success') {
125
123
  document.getElementById('tool').textContent = result.metadata.software;
@@ -137,12 +135,10 @@ fileInput.addEventListener('change', async (e) => {
137
135
  // CDNからインポート
138
136
  import { read } from 'https://cdn.jsdelivr.net/npm/@enslo/sd-metadata@latest/dist/index.js';
139
137
 
140
- // 画像を取得してメタデータを読み込み
141
138
  const response = await fetch(imageUrl);
142
139
  const arrayBuffer = await response.arrayBuffer();
143
- const imageData = new Uint8Array(arrayBuffer);
140
+ const result = read(arrayBuffer);
144
141
 
145
- const result = read(imageData);
146
142
  if (result.status === 'success') {
147
143
  console.log('Tool:', result.metadata.software);
148
144
  console.log('Prompt:', result.metadata.prompt);
@@ -153,7 +149,7 @@ if (result.status === 'success') {
153
149
  > 本番環境では `@latest` の代わりに特定のバージョンを指定してください:
154
150
  >
155
151
  > ```text
156
- > https://cdn.jsdelivr.net/npm/@enslo/sd-metadata@1.4.1/dist/index.js
152
+ > https://cdn.jsdelivr.net/npm/@enslo/sd-metadata@1.6.0/dist/index.js
157
153
  > ```
158
154
 
159
155
  ### 応用例
@@ -335,7 +331,7 @@ if (result.status === 'success') {
335
331
 
336
332
  ## APIリファレンス
337
333
 
338
- ### `read(data: Uint8Array): ParseResult`
334
+ ### `read(input: Uint8Array | ArrayBuffer): ParseResult`
339
335
 
340
336
  画像ファイルからメタデータを読み込み、パースします。
341
337
 
@@ -350,13 +346,13 @@ if (result.status === 'success') {
350
346
  - `{ status: 'invalid', message? }` - 破損または非対応の画像フォーマット
351
347
  - `message`: オプションのエラー説明
352
348
 
353
- ### `write(data: Uint8Array, metadata: ParseResult): WriteResult`
349
+ ### `write(input: Uint8Array | ArrayBuffer, metadata: ParseResult): WriteResult`
354
350
 
355
351
  画像ファイルにメタデータを書き込みます。
356
352
 
357
353
  **パラメータ:**
358
354
 
359
- - `data` - ターゲット画像ファイルデータ(PNG、JPEG、またはWebP)
355
+ - `input` - ターゲット画像ファイルデータ(PNG、JPEG、またはWebP)
360
356
  - `metadata` - `read()` から得られた `ParseResult`
361
357
  - `status: 'success'` または `'empty'` - 直接書き込み可能
362
358
  - `status: 'unrecognized'` - 同じフォーマット:そのまま書き込み、異なるフォーマット:warning付きでメタデータ削除
@@ -370,13 +366,13 @@ if (result.status === 'success') {
370
366
  - `'conversionFailed'`: メタデータ変換に失敗(例:互換性のないフォーマット)
371
367
  - `'writeFailed'`: 画像へのメタデータ埋め込みに失敗
372
368
 
373
- ### `writeAsWebUI(data: Uint8Array, metadata: GenerationMetadata): WriteResult`
369
+ ### `writeAsWebUI(input: Uint8Array | ArrayBuffer, metadata: GenerationMetadata): WriteResult`
374
370
 
375
371
  SD WebUI (A1111) フォーマットで画像にメタデータを書き込みます。
376
372
 
377
373
  **パラメータ:**
378
374
 
379
- - `data` - ターゲット画像ファイルデータ(PNG、JPEG、またはWebP)
375
+ - `input` - ターゲット画像ファイルデータ(PNG、JPEG、またはWebP)
380
376
  - `metadata` - 埋め込む生成メタデータ
381
377
  - 任意のツールからでも、カスタム作成でも可能
382
378
  - 自動的にWebUIフォーマットに変換される
package/README.md CHANGED
@@ -93,7 +93,6 @@ const { read } = require('@enslo/sd-metadata');
93
93
  import { read, write } from '@enslo/sd-metadata';
94
94
  import { readFileSync, writeFileSync } from 'fs';
95
95
 
96
- // Read metadata from any supported format
97
96
  const imageData = readFileSync('image.png');
98
97
  const result = read(imageData);
99
98
 
@@ -117,9 +116,7 @@ fileInput.addEventListener('change', async (e) => {
117
116
  if (!file) return;
118
117
 
119
118
  const arrayBuffer = await file.arrayBuffer();
120
- const imageData = new Uint8Array(arrayBuffer);
121
-
122
- const result = read(imageData);
119
+ const result = read(arrayBuffer);
123
120
 
124
121
  if (result.status === 'success') {
125
122
  document.getElementById('tool').textContent = result.metadata.software;
@@ -137,12 +134,10 @@ For bookmarklets or userscripts (Tampermonkey, Violentmonkey, etc.), load from j
137
134
  // Import from CDN
138
135
  import { read } from 'https://cdn.jsdelivr.net/npm/@enslo/sd-metadata@latest/dist/index.js';
139
136
 
140
- // Fetch image and read metadata
141
137
  const response = await fetch(imageUrl);
142
138
  const arrayBuffer = await response.arrayBuffer();
143
- const imageData = new Uint8Array(arrayBuffer);
139
+ const result = read(arrayBuffer);
144
140
 
145
- const result = read(imageData);
146
141
  if (result.status === 'success') {
147
142
  console.log('Tool:', result.metadata.software);
148
143
  console.log('Prompt:', result.metadata.prompt);
@@ -153,7 +148,7 @@ if (result.status === 'success') {
153
148
  > For production use, pin to a specific version instead of `@latest`:
154
149
  >
155
150
  > ```text
156
- > https://cdn.jsdelivr.net/npm/@enslo/sd-metadata@1.4.2/dist/index.js
151
+ > https://cdn.jsdelivr.net/npm/@enslo/sd-metadata@1.6.0/dist/index.js
157
152
  > ```
158
153
 
159
154
  ### Advanced Examples
@@ -335,7 +330,7 @@ if (result.status === 'success') {
335
330
 
336
331
  ## API Reference
337
332
 
338
- ### `read(data: Uint8Array): ParseResult`
333
+ ### `read(input: Uint8Array | ArrayBuffer): ParseResult`
339
334
 
340
335
  Reads and parses metadata from an image file.
341
336
 
@@ -350,13 +345,13 @@ Reads and parses metadata from an image file.
350
345
  - `{ status: 'invalid', message? }` - Corrupted or unsupported image format
351
346
  - `message`: Optional error description
352
347
 
353
- ### `write(data: Uint8Array, metadata: ParseResult): WriteResult`
348
+ ### `write(input: Uint8Array | ArrayBuffer, metadata: ParseResult): WriteResult`
354
349
 
355
350
  Writes metadata to an image file.
356
351
 
357
352
  **Parameters:**
358
353
 
359
- - `data` - Target image file data (PNG, JPEG, or WebP)
354
+ - `input` - Target image file data (PNG, JPEG, or WebP)
360
355
  - `metadata` - `ParseResult` from `read()`
361
356
  - `status: 'success'` or `'empty'` - Can write directly
362
357
  - `status: 'unrecognized'` - Same format: writes as-is; Cross-format: drops metadata with warning
@@ -370,13 +365,13 @@ Writes metadata to an image file.
370
365
  - `'conversionFailed'`: Metadata conversion failed (e.g., incompatible format)
371
366
  - `'writeFailed'`: Failed to embed metadata into the image
372
367
 
373
- ### `writeAsWebUI(data: Uint8Array, metadata: GenerationMetadata): WriteResult`
368
+ ### `writeAsWebUI(input: Uint8Array | ArrayBuffer, metadata: GenerationMetadata): WriteResult`
374
369
 
375
370
  Writes metadata to an image in SD WebUI (A1111) format.
376
371
 
377
372
  **Parameters:**
378
373
 
379
- - `data` - Target image file data (PNG, JPEG, or WebP)
374
+ - `input` - Target image file data (PNG, JPEG, or WebP)
380
375
  - `metadata` - Generation metadata to embed
381
376
  - Can be from any tool or custom-created
382
377
  - Automatically converted to WebUI format
package/dist/index.d.ts CHANGED
@@ -294,16 +294,26 @@ type ParseResult = {
294
294
  * Automatically detects image format and extracts embedded generation metadata.
295
295
  */
296
296
 
297
+ /** Options for the read function */
298
+ interface ReadOptions {
299
+ /**
300
+ * When true, dimensions are taken strictly from metadata only.
301
+ * When false (default), missing dimensions are extracted from image headers.
302
+ * @default false
303
+ */
304
+ strict?: boolean;
305
+ }
297
306
  /**
298
307
  * Read and parse metadata from an image
299
308
  *
300
309
  * Automatically detects the image format (PNG, JPEG, WebP) and parses
301
310
  * any embedded generation metadata.
302
311
  *
303
- * @param data - Image file data
312
+ * @param input - Image file data (Uint8Array or ArrayBuffer)
313
+ * @param options - Read options
304
314
  * @returns Parse result containing metadata and raw data
305
315
  */
306
- declare function read(data: Uint8Array): ParseResult;
316
+ declare function read(input: Uint8Array | ArrayBuffer, options?: ReadOptions): ParseResult;
307
317
 
308
318
  /**
309
319
  * Write API for sd-metadata
@@ -351,11 +361,11 @@ type WriteResult = {
351
361
  * if necessary. For unrecognized metadata with cross-format conversion,
352
362
  * metadata is dropped and a warning is returned.
353
363
  *
354
- * @param data - Target image file data
364
+ * @param input - Target image file data (Uint8Array or ArrayBuffer)
355
365
  * @param metadata - ParseResult from `read()`
356
366
  * @returns New image data with embedded metadata (or warning if metadata was dropped)
357
367
  */
358
- declare function write(data: Uint8Array, metadata: ParseResult): WriteResult;
368
+ declare function write(input: Uint8Array | ArrayBuffer, metadata: ParseResult): WriteResult;
359
369
 
360
370
  /**
361
371
  * WebUI (A1111) format writer for sd-metadata
@@ -377,7 +387,7 @@ declare function write(data: Uint8Array, metadata: ParseResult): WriteResult;
377
387
  * - PNG: `parameters` tEXt/iTXt chunk (encoding auto-selected based on content)
378
388
  * - JPEG/WebP: Exif UserComment field
379
389
  *
380
- * @param data - Target image file data (PNG, JPEG, or WebP)
390
+ * @param input - Target image file data (Uint8Array or ArrayBuffer)
381
391
  * @param metadata - Generation metadata to embed
382
392
  * @returns New image data with embedded metadata, or error
383
393
  *
@@ -403,7 +413,7 @@ declare function write(data: Uint8Array, metadata: ParseResult): WriteResult;
403
413
  * }
404
414
  * ```
405
415
  */
406
- declare function writeAsWebUI(data: Uint8Array, metadata: GenerationMetadata): WriteResult;
416
+ declare function writeAsWebUI(input: Uint8Array | ArrayBuffer, metadata: GenerationMetadata): WriteResult;
407
417
 
408
418
  /**
409
419
  * A1111-format metadata serialization utilities
@@ -477,4 +487,4 @@ declare function formatAsWebUI(metadata: GenerationMetadata): string;
477
487
  */
478
488
  declare function formatRaw(raw: RawMetadata): string;
479
489
 
480
- export { type CharacterPrompt, type GenerationMetadata, type HiresSettings, type ITXtChunk, type MetadataSegment, type MetadataSegmentSource, type ModelSettings, type ParseResult, type PngTextChunk, type RawMetadata, type SamplingSettings, type TExtChunk, type UpscaleSettings, type WriteResult, type WriteWarning, formatAsWebUI, formatRaw, read, write, writeAsWebUI };
490
+ export { type CharacterPrompt, type ComfyNode, type ComfyNodeGraph, type ComfyNodeInputValue, type ComfyNodeReference, type GenerationMetadata, type HiresSettings, type ITXtChunk, type MetadataSegment, type MetadataSegmentSource, type ModelSettings, type ParseResult, type PngTextChunk, type RawMetadata, type ReadOptions, type SamplingSettings, type TExtChunk, type UpscaleSettings, type WriteResult, type WriteWarning, formatAsWebUI, formatRaw, read, write, writeAsWebUI };