@enslo/sd-metadata-lite 1.1.0 → 1.3.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/CHANGELOG.md +29 -0
- package/README.ja.md +14 -4
- package/README.md +14 -4
- package/dist/index.d.ts +7 -3
- package/dist/index.d.ts.map +1 -0
- package/dist/index.global.js +1 -1
- package/dist/index.js +513 -405
- package/dist/index.js.map +1 -1
- package/package.json +10 -10
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,35 @@ All notable changes to `@enslo/sd-metadata-lite` will be documented in this file
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/).
|
|
7
7
|
|
|
8
|
+
## [1.3.0] - 2026-06-07
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- **C2PA Content Credentials detection** (#235): For PNG images with no
|
|
13
|
+
recognized generation parameters, `parse()` now falls back to C2PA Content
|
|
14
|
+
Credentials and returns the generator name (e.g. ChatGPT / Gemini exports)
|
|
15
|
+
instead of an empty string. Detection only — the signature is not verified.
|
|
16
|
+
|
|
17
|
+
### Maintenance
|
|
18
|
+
|
|
19
|
+
- IIFE bundle size: 6,571 → 6,911 bytes (+340 bytes uncompressed; #235)
|
|
20
|
+
- Update development dependencies
|
|
21
|
+
|
|
22
|
+
## [1.2.0] - 2026-05-30
|
|
23
|
+
|
|
24
|
+
### Improved
|
|
25
|
+
|
|
26
|
+
- **ComfyUI metadata parsing** (#219): Recognise `ShowText|pysssss` and
|
|
27
|
+
`PromptStashSaver` nodes in the flat scanner.
|
|
28
|
+
|
|
29
|
+
### Maintenance
|
|
30
|
+
|
|
31
|
+
- IIFE bundle size: 6,519 → 6,571 bytes (+52 bytes uncompressed; #219)
|
|
32
|
+
- ESM bundle size: ~15.7 KB → ~17.7 KB (+13%); tsdown now preserves JSDoc
|
|
33
|
+
comments by default — does not affect minified CDN or bookmarklet usage (#216)
|
|
34
|
+
- Add `index.d.ts.map` (declaration sourcemaps) to the published output (#216)
|
|
35
|
+
- Update development dependencies
|
|
36
|
+
|
|
8
37
|
## [1.1.0] - 2026-02-25
|
|
9
38
|
|
|
10
39
|
### Improved
|
package/README.ja.md
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
AI生成画像のメタデータを読み取る軽量パーサーです。
|
|
11
11
|
バンドルサイズが重要なブックマークレットやユーザースクリプト向けに設計されています。
|
|
12
12
|
|
|
13
|
-
- **超軽量**: **6,
|
|
13
|
+
- **超軽量**: **6,911 bytes** のminified IIFEビルド
|
|
14
14
|
- **読み取り専用**: メタデータを抽出し、A1111形式のテキストで返却
|
|
15
15
|
- **ゼロ依存**: Node.jsとブラウザの両方で動作
|
|
16
16
|
- **18以上のツール対応**: 主要なAI画像生成ツールをサポート
|
|
@@ -51,7 +51,7 @@ if (text) {
|
|
|
51
51
|
// ==UserScript==
|
|
52
52
|
// @name My Script
|
|
53
53
|
// @namespace https://example.com
|
|
54
|
-
// @require https://cdn.jsdelivr.net/npm/@enslo/sd-metadata-lite@1.
|
|
54
|
+
// @require https://cdn.jsdelivr.net/npm/@enslo/sd-metadata-lite@1.3.0/dist/index.global.js
|
|
55
55
|
// ==/UserScript==
|
|
56
56
|
|
|
57
57
|
const response = await fetch(imageUrl);
|
|
@@ -70,7 +70,7 @@ if (text) {
|
|
|
70
70
|
|
|
71
71
|
多くのサイトではCSPにより外部スクリプトの読み込みがブロックされます。代わりに、IIFEバンドルをインラインで貼り付けてください:
|
|
72
72
|
|
|
73
|
-
1. `dist/index.global.js` の内容をコピー(または[npm](https://cdn.jsdelivr.net/npm/@enslo/sd-metadata-lite@1.
|
|
73
|
+
1. `dist/index.global.js` の内容をコピー(または[npm](https://cdn.jsdelivr.net/npm/@enslo/sd-metadata-lite@1.3.0/dist/index.global.js)からダウンロード)
|
|
74
74
|
2. コードをインラインでブックマークレットに組み込みます:
|
|
75
75
|
|
|
76
76
|
```javascript
|
|
@@ -92,6 +92,7 @@ IIFEは `var sdml` に代入するため、インラインコードの直後か
|
|
|
92
92
|
**戻り値:**
|
|
93
93
|
|
|
94
94
|
- メタデータが見つかった場合はA1111形式のテキスト
|
|
95
|
+
- 生成パラメータを持たないPNGでは、C2PA Content Credentialsの生成元名(例: `OpenAI Media Service API`、`Google C2PA Core Generator Library`)があればそれを返却
|
|
95
96
|
- メタデータが見つからない、またはフォーマットが認識できない場合は空文字列(`""`)
|
|
96
97
|
|
|
97
98
|
### 出力フォーマット
|
|
@@ -104,7 +105,7 @@ Negative prompt: lowres, bad quality
|
|
|
104
105
|
Steps: 20, Sampler: Euler a, Schedule type: Karras, CFG scale: 7, Seed: 12345, Size: 512x768, Model hash: a1b2c3d4, Model: model.safetensors
|
|
105
106
|
```
|
|
106
107
|
|
|
107
|
-
|
|
108
|
+
プロンプトや設定値の各フィールドは、画像のメタデータに含まれているものだけが出力されます。
|
|
108
109
|
|
|
109
110
|
## 対応ツール
|
|
110
111
|
|
|
@@ -129,6 +130,15 @@ PNG、JPEG、WebPのメタデータを読み取り可能:
|
|
|
129
130
|
> [!NOTE]
|
|
130
131
|
> \* リファレンスコードの解析に基づく実装であり、実際のサンプルファイルでは未検証です。
|
|
131
132
|
|
|
133
|
+
### Content Credentials (C2PA)
|
|
134
|
+
|
|
135
|
+
[C2PA](https://c2pa.org/) Content Credentialsで署名された商用ツールのPNGは、生成パラメータの代わりに生成元名で判別します:
|
|
136
|
+
|
|
137
|
+
- OpenAI ChatGPT
|
|
138
|
+
- Google Gemini
|
|
139
|
+
|
|
140
|
+
これらの画像では `parse()` が生成元名(例: `OpenAI Media Service API`)を返します。判別はベストエフォートです。Content Credentialsは再保存や再アップロードで簡単に失われ、また存在する場合も署名検証は行いません。
|
|
141
|
+
|
|
132
142
|
## グローバル変数
|
|
133
143
|
|
|
134
144
|
`<script>` タグまたはユーザースクリプトの `@require` で読み込んだ場合、IIFEビルドは以下を公開します:
|
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
A lightweight, read-only metadata parser for AI-generated images.
|
|
11
11
|
Designed for bookmarklets and userscripts where bundle size matters.
|
|
12
12
|
|
|
13
|
-
- **Tiny**: **6,
|
|
13
|
+
- **Tiny**: **6,911 bytes** minified IIFE build
|
|
14
14
|
- **Read-only**: Extracts metadata and returns A1111-format text
|
|
15
15
|
- **Zero dependencies**: Works in Node.js and browsers
|
|
16
16
|
- **18+ tools**: Supports all major AI image generation tools
|
|
@@ -51,7 +51,7 @@ Load the IIFE build via `@require`:
|
|
|
51
51
|
// ==UserScript==
|
|
52
52
|
// @name My Script
|
|
53
53
|
// @namespace https://example.com
|
|
54
|
-
// @require https://cdn.jsdelivr.net/npm/@enslo/sd-metadata-lite@1.
|
|
54
|
+
// @require https://cdn.jsdelivr.net/npm/@enslo/sd-metadata-lite@1.3.0/dist/index.global.js
|
|
55
55
|
// ==/UserScript==
|
|
56
56
|
|
|
57
57
|
const response = await fetch(imageUrl);
|
|
@@ -70,7 +70,7 @@ if (text) {
|
|
|
70
70
|
|
|
71
71
|
Most sites block external script loading via CSP. Instead, paste the IIFE bundle inline:
|
|
72
72
|
|
|
73
|
-
1. Copy the contents of `dist/index.global.js` (or download from [npm](https://cdn.jsdelivr.net/npm/@enslo/sd-metadata-lite@1.
|
|
73
|
+
1. Copy the contents of `dist/index.global.js` (or download from [npm](https://cdn.jsdelivr.net/npm/@enslo/sd-metadata-lite@1.3.0/dist/index.global.js))
|
|
74
74
|
2. Build your bookmarklet with the code inlined:
|
|
75
75
|
|
|
76
76
|
```javascript
|
|
@@ -92,6 +92,7 @@ Parses metadata from an image and returns A1111-format text.
|
|
|
92
92
|
**Returns:**
|
|
93
93
|
|
|
94
94
|
- A1111-format metadata string if metadata is found
|
|
95
|
+
- For PNGs with no generation parameters, the C2PA Content Credentials generator name (e.g. `OpenAI Media Service API`, `Google C2PA Core Generator Library`) when present
|
|
95
96
|
- Empty string (`""`) if no metadata is found or the format is unrecognized
|
|
96
97
|
|
|
97
98
|
### Output Format
|
|
@@ -104,7 +105,7 @@ Negative prompt: lowres, bad quality
|
|
|
104
105
|
Steps: 20, Sampler: Euler a, Schedule type: Karras, CFG scale: 7, Seed: 12345, Size: 512x768, Model hash: a1b2c3d4, Model: model.safetensors
|
|
105
106
|
```
|
|
106
107
|
|
|
107
|
-
|
|
108
|
+
Prompt and parameter fields are included only when present in the source metadata.
|
|
108
109
|
|
|
109
110
|
## Supported Tools
|
|
110
111
|
|
|
@@ -129,6 +130,15 @@ Reads PNG, JPEG, and WebP metadata from:
|
|
|
129
130
|
> [!NOTE]
|
|
130
131
|
> \* Implemented based on reference code analysis, not verified with actual sample files.
|
|
131
132
|
|
|
133
|
+
### Content Credentials (C2PA)
|
|
134
|
+
|
|
135
|
+
PNGs from commercial tools that sign their output with [C2PA](https://c2pa.org/) Content Credentials are detected by their generator name instead of generation parameters:
|
|
136
|
+
|
|
137
|
+
- OpenAI ChatGPT
|
|
138
|
+
- Google Gemini
|
|
139
|
+
|
|
140
|
+
For these images `parse()` returns the generator name (e.g. `OpenAI Media Service API`). Detection is best-effort: the credentials are easily stripped by re-saving or re-uploading, and a present manifest is not cryptographically verified.
|
|
141
|
+
|
|
132
142
|
## Globals
|
|
133
143
|
|
|
134
144
|
When loaded via `<script>` tag or userscript `@require`, the IIFE build exposes:
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
//#region src/index.d.ts
|
|
1
2
|
/**
|
|
2
3
|
* @enslo/sd-metadata-lite
|
|
3
4
|
*
|
|
@@ -7,12 +8,15 @@
|
|
|
7
8
|
/**
|
|
8
9
|
* Parse AI-generated image metadata and return A1111-format text.
|
|
9
10
|
*
|
|
10
|
-
* Supports PNG, JPEG, and WebP formats across 18+ generation tools.
|
|
11
|
+
* Supports PNG, JPEG, and WebP formats across 18+ generation tools. For PNG
|
|
12
|
+
* images with no generation parameters, falls back to C2PA Content Credentials
|
|
13
|
+
* and returns the generator name (e.g. ChatGPT / Gemini exports).
|
|
11
14
|
* Returns empty string if no metadata is found.
|
|
12
15
|
*
|
|
13
16
|
* @param input - Image file data
|
|
14
|
-
* @returns A1111-format metadata text, or empty string
|
|
17
|
+
* @returns A1111-format metadata text, the C2PA generator name, or empty string
|
|
15
18
|
*/
|
|
16
19
|
declare function parse(input: Uint8Array | ArrayBuffer): string;
|
|
17
|
-
|
|
20
|
+
//#endregion
|
|
18
21
|
export { parse };
|
|
22
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/index.ts"],"mappings":";;AAqBA;;;;;;;;AAAqD;;;;;;;;iBAArC,KAAA,CAAM,KAAA,EAAO,UAAA,GAAa,WAAW"}
|
package/dist/index.global.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var sdml=(()=>{var e="class_type",t="parameters",n="use_stable_diffusion_model";function r(e,n){for(let r of["extraMetadata","invokeai_metadata","generation_data"])if(e[r]){let i={...n,[t]:n[t]??f(e[r]).replace(/\0+$/,"")};return e.prompt&&(i.prompt??=f(e.prompt)),i}return n}function i(i){let
|
|
1
|
+
var sdml=(()=>{var e="class_type",t="parameters",n="use_stable_diffusion_model";function r(e,n){for(let r of["extraMetadata","invokeai_metadata","generation_data"])if(e[r]){let i={...n,[t]:n[t]??f(e[r]).replace(/\0+$/,"")};return e.prompt&&(i.prompt??=f(e.prompt)),i}return n}function i(i){let c=function(e){if(e.Software?.startsWith("NovelAI"))return{...e,[t]:e[t]??e.Comment};let n=e.UserComment;if(!n)return r(e,e);if(!n.startsWith("{"))return n.includes("Steps:")?{...e,[t]:e[t]??n}:e;let i=o(n);if(!i)return e;let l=r(i,e);return l!==e?l:"prompt"in i&&"workflow"in i?{...e,prompt:e.prompt??f(i.prompt)}:t in i?{...e,[t]:e[t]??f(i[t])}:{...e,[t]:e[t]??n}}(i),m=c[t],h=c.prompt??c.Prompt;if(m?.includes("sui_image_params")){let e=o(m);return u(l(e.sui_image_params??e))}if(m&&!m.startsWith("{"))return m;if(m){let t=o(m),r="string"==typeof t?o(t):t;if(r){let t=function(e,t){if(a(e.software).includes("RuinedFooocus")||n in e)return u(l(e));if(t.includes('"Model"')&&t.includes('"resolution"')){let[t,n]=p(a(e.resolution),/(\d+)\s*x\s*(\d+)/);return u({...l(e),w:t,h:n})}if("base_model"in e){let[t,n]=p(a(e.resolution),/\(\s*(\d+)\s*,\s*(\d+)\s*\)/);return u({...l(e),w:t,h:n})}return"noise_schedule"in e?function(e){let t=e.v4_prompt?.caption,n=e.v4_negative_prompt?.caption;return u({...l(e),p:a(t?.base_caption)||a(e.prompt),n:a(n?.base_caption)||a(e.uc)})}(e):null}(r,m);if(t)return t;if(m.includes(e))return u(s(m));let i=l(r);return h?.includes(e)?u({...s(h),p:i.p,n:i.n,md:i.md,mh:i.mh}):u(i)}}return c[n]?u(l(c)):h?.includes(e)?u(s(h)):m??c.UserComment??c.Comment??c.ImageDescription??function(e){if(!e)return"";let t=e.indexOf("claim_generator_info");if(t<0)return"";let n=e.indexOf("dname",t);if(n<0||n>t+256)return"";let r=n+5,i=e.charCodeAt(r);if(!(i>=96&&i<=120))return"";let l=120===i,s=l?e.charCodeAt(r+1)||0:i-96,u=r+(l?2:1);return u+s>e.length?"":e.slice(u,u+s)}(c.cabx)}function l(e){let t=a(e.sampler??e.sampler_name),r=a(e.scheduler??e.noise_schedule),i=e.model,l=e.baseModel,s=e.use_upscaler;return{p:a(e.prompt??e.Prompt??e.positive_prompt),n:a(e.negative_prompt??e.Negative??e.negativeprompt??e.negativePrompt??e.uc),se:c(e.seed),st:c(e.steps??e.num_inference_steps),cf:c(e.cfg??e.cfg_scale??e.cfgScale??e.cfgscale??e.guidance_scale??e.scale),sa:t||r,sc:t?r:void 0,w:c(e.width),h:c(e.height),md:a(i)||a(e.Model)||a(e.base_model)||a(e.base_model_name)||a(l)||a(i?.name)||a(l?.modelFileName)||a(e[n]).split(/[\\/]/).pop(),mh:a(e.base_model_hash)||a(e["Model hash"])||a(i?.hash)||a(l?.hash),cs:c(e.clip_skip??e.clipSkip),hs:c(s?.upscale_by)??c(e.refinerupscale),hu:a(s?.upscale_method)||a(e.refinerupscalemethod),hd:c(s?.upscaler_strength)??c(e.refinercontrolpercentage),ht:c(s?.upscale_steps)}}function s(t){let n={},r=o(t.replace(/\0+$/,"").replace(/\bNaN\b/g,"null"));if(!r)return n;for(let t in r){let i=r[t];if(!i||"object"!=typeof i)continue;let l=a(i[e]),s=i.inputs;if(s){if(/Text(Encode|.?Box)|ShowText|PromptStash/.test(l)){let e=a(s.text)||a(s.prompt)||a(s.Text)||a(s.prompt_text)||a(s.text_0);e&&(/neg/i.test(l)?n.n??=e:n.p?n.n||(n.n=e):n.p=e)}l.includes("Sampler")&&(n.se??=c(s.seed)??c(s.noise_seed),n.st??=c(s.steps),n.cf??=c(s.cfg),n.sa||=a(s.sampler_name),n.sc||=a(s.scheduler)),n.md||=a(s.ckpt_name)||a(s.unet_name),n.w??=c(s.width),n.h??=c(s.height)}}return n}function u(e){let t=[];e.p&&t.push(e.p),e.n&&t.push("Negative prompt: "+e.n);let n=[],r=(e,t)=>{t&&n.push(`${e}: ${t}`)};return r("Steps",e.st),r("Sampler",e.sa),r("Schedule type",e.sc),r("CFG scale",e.cf),r("Seed",e.se),e.w&&e.h&&r("Size",`${e.w}x${e.h}`),r("Model hash",e.mh),r("Model",e.md),r("Clip skip",e.cs),r("Denoising strength",e.dn??e.hd),r("Hires upscale",e.hs),r("Hires steps",e.ht),r("Hires upscaler",e.hu),n.length&&t.push(n.join(", ")),t.join("\n")}function o(e){if(!e)return null;try{return JSON.parse(e)}catch{return null}}function a(e){return"string"==typeof e?e:""}function f(e){return"string"==typeof e?e:e&&"object"==typeof e?JSON.stringify(e):""}function c(e){if("number"==typeof e)return e==e?e:void 0;if("string"==typeof e){let t=+e;return t==t?t:void 0}}function p(e,t){if(!e)return[];let n=e.match(t);return n?[Number(n[1]),Number(n[2])]:[]}function m(e){if(e.length<8)return{};let t=e[0],n=73===t;if(!n&&77!==t)return{};let r=d(e);if(42!==r.getUint16(2,n))return{};let i={},l=r.getUint32(4,n),s=0,u=e=>{let t=function(e){if(e.length<8)return null;let t=b(e,0,8),n=e.subarray(8);return"UNICODE\0"===t?n.length<2?null:function(e,t){let n="";for(let r=0;r+1<e.length;r+=2){let i=t?e[r]|e[r+1]<<8:e[r]<<8|e[r+1];if(!i)break;n+=_(i)}return n}(n,0!==n[0]&&0===n[1]):"ASCII\0\0\0"===t?w(n):y(e)}(e);if(t){if(t.startsWith("{"))try{let e=JSON.parse(t),n=e.Software,r=e.Comment;if("string"==typeof n&&n.startsWith("NovelAI")&&"string"==typeof r)return i.Software=n,void(i.Comment=r)}catch{}i.UserComment=t}};return h(e,r,l,n,(t,l)=>{if(270===t||271===t){let e=w(l);if(e){let n=e.match(/^([A-Za-z]+):\s/);if(n){let t=n[1];t&&(i[t]=e.slice(n[0].length))}else i[270===t?"ImageDescription":"Make"]=e}}else 37510===t?u(l):34665===t&&(s=r.getUint32(l.byteOffset-e.byteOffset,n))}),s&&!i.UserComment&&!i.Software&&h(e,r,s,n,(e,t)=>{37510===e&&u(t)}),i}function h(e,t,n,r,i){let l=e=>t.getUint16(e,r),s=e=>t.getUint32(e,r);if(n+2>e.length)return;let u=l(n),o=n+2;for(let t=0;t<u;t++){if(o+12>e.length)return;let t=l(o),n=l(o+2),r=s(o+4)*([0,1,1,2,4,8,0,1][n]??1),u=r<=4?o+8:s(o+8);u+r<=e.length&&i(t,e.subarray(u,u+r)),o+=12}}function d(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}var g=new TextDecoder("utf-8",{fatal:!0}),_=String.fromCharCode;function b(e,t,n){let r="";for(let i=0;i<n;i++)r+=_(e[t+i]);return r}function y(e){try{return g.decode(e).replace(/\0$/,"")}catch{return null}}function w(e){let t=e.indexOf(0);return b(e,0,t<0?e.length:t).trim()||null}return{parse:function(e){let t=e instanceof ArrayBuffer?new Uint8Array(e):e;return 137===t[0]&&80===t[1]?i(function(e){let t={},n=d(e),r=8;for(;r+8<=e.length;){let i=n.getUint32(r),l=b(e,r+4,4);if(r+=8,r+i>e.length)break;if("caBX"===l&&(t.cabx=b(e,r,Math.min(i,8388608))),"tEXt"===l||"iTXt"===l){let n=e.indexOf(0,r);if(n>r&&n<r+i){let s=b(e,r,n-r);if("tEXt"===l){let l=e.subarray(n+1,r+i);t[s]=y(l)??b(e,n+1,r+i-n-1)}else{let l=n+3,u=e.indexOf(0,l),o=u<0?-1:e.indexOf(0,u+1);if(u<0||o<0){r+=i+4;continue}t[s]=y(e.subarray(o+1,r+i))??""}}}if("IEND"===l)break;r+=i+4}return t}(t)):255===t[0]&&216===t[1]?i(function(e){let t={},n=2;for(;n+4<=e.length;){let r=e[n+1];if(255!==e[n]||255===r){n++;continue}if(r>216&&r<219)break;let i=e[n+2]<<8|e[n+3];if(225===r&&n+10<=e.length&&"Exif\0\0"===b(e,n+4,6)&&Object.assign(t,m(e.subarray(n+10,n+2+i))),254===r){let r=y(e.subarray(n+4,n+2+i));r&&(t.Comment=r)}n+=2+i}return t}(t)):82===t[0]&&73===t[1]?i(function(e){let t=d(e),n=12;for(;n+8<=e.length;){let r=b(e,n,4),i=t.getUint32(n+4,!0);if(n+=8,"EXIF"===r&&n+i<=e.length)return m(e.subarray(n,n+i));n+=i+i%2}return{}}(t)):""}}})();
|