@enslo/sd-metadata-lite 1.6.0 → 1.7.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 +41 -0
- package/README.ja.md +8 -6
- package/README.md +8 -6
- package/dist/index.d.ts +5 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.global.js +1 -1
- package/dist/index.js +333 -385
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,47 @@ 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.7.0] - 2026-11-28
|
|
9
|
+
|
|
10
|
+
A Kilobyte Lighter
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- **Tool names for C2PA images** (#354): the name comes from the tool an
|
|
15
|
+
image declares, so Kling AI and Dreamina images are named, and ChatGPT
|
|
16
|
+
images return `ChatGPT` in place of `OpenAI Media Service API`.
|
|
17
|
+
- **Size from any `resolution` text** (#356): `1024x1024` and `(1024, 1024)`
|
|
18
|
+
are read in every JSON format, not only Fooocus and HF Space.
|
|
19
|
+
|
|
20
|
+
### Fixed
|
|
21
|
+
|
|
22
|
+
- **NovelAI JPEG with a comment segment** (#357): the comment no longer
|
|
23
|
+
replaces the NovelAI metadata.
|
|
24
|
+
|
|
25
|
+
### Maintenance
|
|
26
|
+
|
|
27
|
+
- IIFE bundle size: 7,257 → 6,177 bytes (#354, #355, #356, #357, #358)
|
|
28
|
+
|
|
29
|
+
## [1.6.1] - 2026-11-09
|
|
30
|
+
|
|
31
|
+
Steady on Unexpected Text
|
|
32
|
+
|
|
33
|
+
### Fixed
|
|
34
|
+
|
|
35
|
+
- **No throw or stall on odd text** (#326): non-JSON `parameters`, long NUL
|
|
36
|
+
runs and unusual Fooocus size strings are handled.
|
|
37
|
+
- **Seed note** (#337): 1.6.0 overstated it. String seeds keep every digit;
|
|
38
|
+
JSON-number seeds are rounded past 2^53 by `JSON.parse`. No behaviour change.
|
|
39
|
+
|
|
40
|
+
### Demo Site
|
|
41
|
+
|
|
42
|
+
- Security headers (#331); read errors shown (#336).
|
|
43
|
+
|
|
44
|
+
### Maintenance
|
|
45
|
+
|
|
46
|
+
- IIFE bundle size: 7,259 → 7,257 bytes (#326)
|
|
47
|
+
- Update development dependencies (#320)
|
|
48
|
+
|
|
8
49
|
## [1.6.0] - 2026-11-04
|
|
9
50
|
|
|
10
51
|
### Added
|
package/README.ja.md
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
AI生成画像のメタデータを読み取る軽量パーサーです。
|
|
11
11
|
バンドルサイズが重要なブックマークレットやユーザースクリプト向けに設計されています。
|
|
12
12
|
|
|
13
|
-
- **超軽量**: **
|
|
13
|
+
- **超軽量**: **6,177 bytes** のminified IIFEビルド
|
|
14
14
|
- **読み取り専用**: メタデータを抽出し、A1111形式のテキストで返却
|
|
15
15
|
- **ゼロ依存**: Node.jsとブラウザの両方で動作
|
|
16
16
|
- **18以上のツール対応**: 主要なAI画像生成ツールをサポート
|
|
@@ -66,7 +66,7 @@ if (text) {
|
|
|
66
66
|
// ==UserScript==
|
|
67
67
|
// @name My Script
|
|
68
68
|
// @namespace https://example.com
|
|
69
|
-
// @require https://cdn.jsdelivr.net/npm/@enslo/sd-metadata-lite@1.
|
|
69
|
+
// @require https://cdn.jsdelivr.net/npm/@enslo/sd-metadata-lite@1.7.0/dist/index.global.js
|
|
70
70
|
// ==/UserScript==
|
|
71
71
|
|
|
72
72
|
const response = await fetch(imageUrl);
|
|
@@ -85,7 +85,7 @@ if (text) {
|
|
|
85
85
|
|
|
86
86
|
多くのサイトではCSPにより外部スクリプトの読み込みがブロックされます。代わりに、IIFEバンドルをインラインで貼り付けてください:
|
|
87
87
|
|
|
88
|
-
1. `dist/index.global.js` の内容をコピー(または[npm](https://cdn.jsdelivr.net/npm/@enslo/sd-metadata-lite@1.
|
|
88
|
+
1. `dist/index.global.js` の内容をコピー(または[npm](https://cdn.jsdelivr.net/npm/@enslo/sd-metadata-lite@1.7.0/dist/index.global.js)からダウンロード)
|
|
89
89
|
2. コードをインラインでブックマークレットに組み込みます:
|
|
90
90
|
|
|
91
91
|
```javascript
|
|
@@ -107,7 +107,7 @@ IIFEは `var sdml` に代入するため、インラインコードの直後か
|
|
|
107
107
|
**戻り値:**
|
|
108
108
|
|
|
109
109
|
- メタデータが見つかった場合はA1111形式のテキスト
|
|
110
|
-
- 生成パラメータを持たないPNG・JPEGでは、C2PA Content Credentials
|
|
110
|
+
- 生成パラメータを持たないPNG・JPEGでは、C2PA Content Credentialsに記された生成ツール名(例: `ChatGPT`、`Kling AI`、`Grok Imagine`)があればそれを返却
|
|
111
111
|
- メタデータが見つからない、またはフォーマットが認識できない場合は空文字列(`""`)
|
|
112
112
|
|
|
113
113
|
### 出力フォーマット
|
|
@@ -147,13 +147,15 @@ PNG、JPEG、WebPのメタデータを読み取り可能:
|
|
|
147
147
|
|
|
148
148
|
### Content Credentials (C2PA)
|
|
149
149
|
|
|
150
|
-
[C2PA](https://c2pa.org/) Content Credentialsで署名された商用ツールのPNGとJPEG
|
|
150
|
+
[C2PA](https://c2pa.org/) Content Credentialsで署名された商用ツールのPNGとJPEGは、生成パラメータの代わりに、マニフェストに記されたツール名で判別します:
|
|
151
151
|
|
|
152
152
|
- OpenAI ChatGPT
|
|
153
153
|
- Google Gemini
|
|
154
154
|
- xAI Grok Imagine
|
|
155
|
+
- Kuaishou Kling AI
|
|
156
|
+
- ByteDance Dreamina
|
|
155
157
|
|
|
156
|
-
これらの画像では `parse()`
|
|
158
|
+
これらの画像では `parse()` が画像に記されたツール名(例: `ChatGPT`、`Kling AI`、`Dreamina/7.5.0`)を返します。ツール名が記されていない場合は署名したプログラムの名前(Gemini: `Google C2PA Core Generator Library`)を返します。判別はベストエフォートです。Content Credentialsは再保存や再アップロードで簡単に失われ、また存在する場合も署名検証は行いません。
|
|
157
159
|
|
|
158
160
|
## グローバル変数
|
|
159
161
|
|
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**: **
|
|
13
|
+
- **Tiny**: **6,177 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
|
|
@@ -66,7 +66,7 @@ Load the IIFE build via `@require`:
|
|
|
66
66
|
// ==UserScript==
|
|
67
67
|
// @name My Script
|
|
68
68
|
// @namespace https://example.com
|
|
69
|
-
// @require https://cdn.jsdelivr.net/npm/@enslo/sd-metadata-lite@1.
|
|
69
|
+
// @require https://cdn.jsdelivr.net/npm/@enslo/sd-metadata-lite@1.7.0/dist/index.global.js
|
|
70
70
|
// ==/UserScript==
|
|
71
71
|
|
|
72
72
|
const response = await fetch(imageUrl);
|
|
@@ -85,7 +85,7 @@ if (text) {
|
|
|
85
85
|
|
|
86
86
|
Most sites block external script loading via CSP. Instead, paste the IIFE bundle inline:
|
|
87
87
|
|
|
88
|
-
1. Copy the contents of `dist/index.global.js` (or download from [npm](https://cdn.jsdelivr.net/npm/@enslo/sd-metadata-lite@1.
|
|
88
|
+
1. Copy the contents of `dist/index.global.js` (or download from [npm](https://cdn.jsdelivr.net/npm/@enslo/sd-metadata-lite@1.7.0/dist/index.global.js))
|
|
89
89
|
2. Build your bookmarklet with the code inlined:
|
|
90
90
|
|
|
91
91
|
```javascript
|
|
@@ -107,7 +107,7 @@ Parses metadata from an image and returns A1111-format text.
|
|
|
107
107
|
**Returns:**
|
|
108
108
|
|
|
109
109
|
- A1111-format metadata string if metadata is found
|
|
110
|
-
- For PNG and JPEG files with no generation parameters, the C2PA Content Credentials
|
|
110
|
+
- For PNG and JPEG files with no generation parameters, the name of the tool that made the image, from its C2PA Content Credentials (e.g. `ChatGPT`, `Kling AI`, `Grok Imagine`) when present
|
|
111
111
|
- Empty string (`""`) if no metadata is found or the format is unrecognized
|
|
112
112
|
|
|
113
113
|
### Output Format
|
|
@@ -147,13 +147,15 @@ Reads PNG, JPEG, and WebP metadata from:
|
|
|
147
147
|
|
|
148
148
|
### Content Credentials (C2PA)
|
|
149
149
|
|
|
150
|
-
PNG and JPEG files from commercial tools that sign their output with [C2PA](https://c2pa.org/) Content Credentials are detected by their
|
|
150
|
+
PNG and JPEG files from commercial tools that sign their output with [C2PA](https://c2pa.org/) Content Credentials are detected by the tool their manifest names instead of generation parameters:
|
|
151
151
|
|
|
152
152
|
- OpenAI ChatGPT
|
|
153
153
|
- Google Gemini
|
|
154
154
|
- xAI Grok Imagine
|
|
155
|
+
- Kuaishou Kling AI
|
|
156
|
+
- ByteDance Dreamina
|
|
155
157
|
|
|
156
|
-
For these images `parse()` returns the
|
|
158
|
+
For these images `parse()` returns the tool name as the image declares it (e.g. `ChatGPT`, `Kling AI`, `Dreamina/7.5.0`), or the name of the program that signed it when it declares none (Gemini: `Google C2PA Core Generator Library`). Detection is best-effort: the credentials are easily stripped by re-saving or re-uploading, and a present manifest is not cryptographically verified.
|
|
157
159
|
|
|
158
160
|
## Globals
|
|
159
161
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
//#region src/index.d.ts
|
|
2
1
|
/**
|
|
3
2
|
* @enslo/sd-metadata-lite
|
|
4
3
|
*
|
|
@@ -9,13 +8,14 @@
|
|
|
9
8
|
* Parse AI-generated image metadata and return A1111-format text.
|
|
10
9
|
*
|
|
11
10
|
* Supports PNG, JPEG, and WebP formats across 18+ generation tools. For PNG
|
|
12
|
-
* images with no generation parameters, falls back to C2PA Content
|
|
13
|
-
* and returns the
|
|
11
|
+
* and JPEG images with no generation parameters, falls back to C2PA Content
|
|
12
|
+
* Credentials and returns the name of the tool that made the image
|
|
13
|
+
* (`ChatGPT`, `Kling AI`, `Grok Imagine`), or of the program that signed it
|
|
14
|
+
* when the manifest names no tool (Gemini exports).
|
|
14
15
|
* Returns empty string if no metadata is found.
|
|
15
16
|
*
|
|
16
17
|
* @param input - Image file data
|
|
17
|
-
* @returns A1111-format metadata text,
|
|
18
|
+
* @returns A1111-format metadata text, a C2PA tool name, or empty string
|
|
18
19
|
*/
|
|
19
20
|
export declare function parse(input: Uint8Array | ArrayBuffer): string;
|
|
20
|
-
//#endregion
|
|
21
21
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/index.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/index.ts"],"mappings":";;;;;;;;;;;;;;;;;;;wBAuBgB,MAAM,OAAO,aAAa"}
|
package/dist/index.global.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var sdml=(()=>{
|
|
1
|
+
var sdml=(()=>{function e(e){let r={},i=e[0],c=73===i,f=t(e),p=e=>f.getUint16(e,c),h=e=>f.getUint32(e,c);if(e.length<8||!c&&77!==i||42!==p(2))return r;let d=(t,r)=>{for(let n=t+2,l=n>e.length?0:p(t);l--&&n+12<=e.length;n+=12){let t=[0,1,1,2,4,8,0,1][p(n+2)]??1,l=h(n+4)*t,i=l<=4?n+8:h(n+8);i+l<=e.length&&r(p(n),e.subarray(i,i+l),i)}},m=0,g=e=>{let t=(e=>{if(e.length<8)return null;let t=s(e,0,8),r=e.subarray(8);return"UNICODE\0"===t?((e,t)=>{let r="";for(let l=0;l+1<e.length;l+=2){let i=t?e[l]|e[l+1]<<8:e[l]<<8|e[l+1];if(!i)break;r+=n(i)}return r})(r,0===r[1]):"ASCII\0\0\0"===t?o(r):u(e)})(e);t&&(r[l]=t)};return d(h(4),(e,t,n)=>{if(e>269&&e<273){let n=o(t);if(n){let t=n.match(/^([A-Za-z]+):(?:\s|(?=\{))/);t?r[t[1]]=n.slice(t[0].length):r[[a,"Make","Model"][e-270]]=n}}else 37510===e?g(t):34665===e&&(m=h(n))}),m&&!r[l]&&d(m,(e,t)=>{37510===e&&g(t)}),r}function t(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}var r=new TextDecoder("utf-8",{fatal:!0}),n=String.fromCharCode,l="UserComment",i="Comment",a="ImageDescription";function s(e,t,r){let l="";for(let i=0;i<r;i++)l+=n(e[t+i]);return l}function u(e){try{return r.decode(e).replace(/\0$/,"")}catch{return null}}function o(e){let t=e.indexOf(0);return s(e,0,t<0?e.length:t).trim()||null}var c="class_type",f="parameters",p="use_stable_diffusion_model",h="prompt",d="Source",m="sui_image_params",g="noise_schedule",_="sampler_name",b="base_caption";function x(e,t){let r=["extraMetadata","invokeai_metadata","generation_data"].find(t=>e[t]);return r&&(t[f]??=N(e[r]).replace(/(?<!\0)\0+$/,""),e[h]&&(t[h]??=N(e[h]))),!!r}function y(e,t){let r=e.charCodeAt(t);if(!(r>=96&&r<=120))return"";let n=120===r,l=n?e.charCodeAt(t+1)||0:r-96,i=t+(n?2:1);return i+l>e.length?"":e.slice(i,i+l)}function S(e){let t=k(e.sampler??e[_]),r=k(e.scheduler??e[g]),n=e.model,l=e.baseModel,i=e.use_upscaler,a=k(e.resolution).match(/(?<!\d)(\d+)\s*[x,]\s*(\d+)/);return{p:e.full_prompt?.join?.(", ")||k(e[h]??e.Prompt??e.positive_prompt),n:e.full_negative_prompt?.join?.(", ")||k(e.negative_prompt??e.Negative??e.negativeprompt??e.negativePrompt??e.uc),se:k(e.seed),st:k(e.steps??e.num_inference_steps),cf:k(e.cfg??e.cfg_scale??e.cfgScale??e.cfgscale??e.guidance_scale??e.scale),sa:t||r,sc:t&&r,w:a?.[1]??k(e.width),h:a?.[2]??k(e.height),md:k(n,e.Model,e.base_model,e.base_model_name,l,n?.name,l?.modelFileName)||k(e[p]).split(/[\\/]/).pop(),mh:k(e.base_model_hash,e["Model hash"],n?.hash,l?.hash),cs:k(e.clip_skip??e.clipSkip),hs:k(i?.upscale_by,e.refinerupscale),hu:k(i?.upscale_method,e.refinerupscalemethod),hd:k(i?.upscaler_strength,e.refinercontrolpercentage),ht:k(i?.upscale_steps)}}function v(e){let t={},r="",n=O(e.replace(/(?<!\0)\0+$/,"").replace(/\bNaN\b/g,"null"));if(!n)return t;for(let e in n){let l=n[e],i=l?.inputs;if(!i)continue;let a=k(l[c]);if(/User Prompt/.test(k(l._meta?.title))&&(r||=k(i.value)),/Text(Encode|.?Box)|ShowText|PromptStash/.test(a)){let e=k(i.text,i[h],i.Text,i.prompt_text,i.text_0);e&&(/neg/i.test(a)?t.n??=e:t.p?t.n||(t.n=e):t.p=e)}a.includes("Sampler")&&(t.se||=k(i.seed,i.noise_seed),t.st||=k(i.steps),t.cf||=k(i.cfg),t.sa||=k(i[_]),t.sc||=k(i.scheduler)),t.md||=k(i.ckpt_name,i.unet_name),t.w||=k(i.width),t.h||=k(i.height)}return t.p||=r,t}function w(e){let t=(e,t)=>t?`${e}: ${t}`:"";return[e.p,t("Negative prompt",e.n),[t("Steps",e.st),t("Sampler",e.sa),t("Schedule type",e.sc),t("CFG scale",e.cf),t("Seed",e.se),t("Size",e.w&&e.h&&`${e.w}x${e.h}`),t("Model hash",e.mh),t("Model",e.md),t("Clip skip",e.cs),t("Denoising strength",e.dn??e.hd),t("Hires upscale",e.hs),t("Hires steps",e.ht),t("Hires upscaler",e.hu)].filter(Boolean).join(", ")].filter(Boolean).join("\n")}function O(e){if(!e)return null;try{return JSON.parse(e)}catch{return null}}function k(...e){return""+(e.find(e=>"string"==typeof e&&e||"number"==typeof e)??"")}function N(e){return"string"==typeof e?e:e&&"object"==typeof e?JSON.stringify(e):""}return{parse:r=>{let n=r instanceof ArrayBuffer?new Uint8Array(r):r,o=n[0]<<8|n[1];return(e=>{let t=(e=>{let t={...e},r=t[l];if(t.Software?.startsWith("NovelAI"))t[f]??=t[i];else if(r)if(r.startsWith("{")){let e=O(r),n=e?.[i];k(e?.Software).startsWith("NovelAI")&&"string"==typeof n?(t[f]??=n,t[d]=e[d]):e&&!x(e,t)&&(h in e&&"workflow"in e?t[h]??=N(e[h]):t[f]??=f in e?N(e[f]):r)}else r.includes("Steps:")&&(t[f]??=r);else x(t,t);return t})(e),r=t[f],n=t[h]??t.Prompt,s=O(r);if(s&&r.includes(m))return w(S(s[m]??s));if(r&&!r.startsWith("{"))return r;if(s){if(t[d]&&(s[d]=t[d]),g in s)return(e=>{let t=e.v4_prompt?.caption,r=e.v4_negative_prompt?.caption,n=/^(.+) ([0-9A-F]{8})$/.exec(k(e[d]));return w({...S(e),p:k(t?.[b],e[h]).replace(/(^|, )teXt:(?!:).*/s,""),n:k(r?.[b],e.uc),dn:k(e.strength),md:n?.[1]??k(e[d]),mh:n?.[2]})})(s);if(r.includes(c))return w(v(r));let e=S(s);return n?.includes(c)?w({...v(n),p:e.p,n:e.n,md:e.md,mh:e.mh}):w(e)}return t[p]?w({...S(t),cs:""}):n?.includes(c)?w(v(n)):r??((e=>{if(!e)return"";let t=(t,r)=>{let n=e.indexOf("dname",t);return t<0||n<0||n>t+r?"":y(e,n+5)},r=e.indexOf("softwareAgent");return(r<0?"":y(e,r+13))||t(r,14)||t(e.indexOf("claim_generator_info"),256)})(t.cabx)||(t[l]??t[i]??t[a]??""))})(35152===o?(r=>{let n={},l=t(r),i=8;for(;i+8<=r.length;){let t=l.getUint32(i),a=s(r,i+4,4);if(i+=8,i+t>r.length)break;if("caBX"===a&&(n.cabx=s(r,i,Math.min(t,8388608))),"eXIf"===a&&Object.assign(n,e(r.subarray(i,i+t))),"tEXt"===a||"iTXt"===a){let e=r.indexOf(0,i);if(e>i&&e<i+t){let l=s(r,i,e-i);if("tEXt"===a){let a=r.subarray(e+1,i+t);n[l]=u(a)??s(r,e+1,i+t-e-1)}else{let a=r.indexOf(0,e+3),s=r.indexOf(0,a+1);a>=0&&s>=0&&(n[l]=u(r.subarray(s+1,i+t))??"")}}}if("IEND"===a)break;i+=t+4}return n})(n):65496===o?(t=>{let r={},n=2;for(;n+4<=t.length;){let l=t[n+1];if(255!==t[n]||255===l){n++;continue}if(l>216&&l<219)break;let a=t[n+2]<<8|t[n+3];if(225===l&&"Exif\0\0"===s(t,n+4,6)&&Object.assign(r,e(t.subarray(n+10,n+2+a))),235===l&&(r.cabx=(r.cabx??"")+s(t,n+12,a-10)),254===l){let e=u(t.subarray(n+4,n+2+a));e&&(r[i]=e)}n+=2+a}return r})(n):21065===o?(r=>{let n=t(r),l=12;for(;l+8<=r.length;){let t=s(r,l,4),i=n.getUint32(l+4,!0);if(l+=8,"EXIF"===t&&l+i<=r.length)return e(r.subarray(l,l+i));l+=i+i%2}return{}})(n):{})}}})();
|