@rslsp1/fa-app-tools 6.1.0 → 7.0.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.
@@ -1,218 +0,0 @@
1
- // src/lib/project.ts
2
- import JSZip from "jszip";
3
-
4
- // src/lib/metadata.ts
5
- var crcTable = (() => {
6
- let c;
7
- const table = new Uint32Array(256);
8
- for (let n = 0; n < 256; n++) {
9
- c = n;
10
- for (let k = 0; k < 8; k++) {
11
- c = c & 1 ? 3988292384 ^ c >>> 1 : c >>> 1;
12
- }
13
- table[n] = c;
14
- }
15
- return table;
16
- })();
17
- function calculateCRC(bytes) {
18
- let crc = 4294967295;
19
- for (let i = 0; i < bytes.length; i++) {
20
- crc = crcTable[(crc ^ bytes[i]) & 255] ^ crc >>> 8;
21
- }
22
- return (crc ^ 4294967295) >>> 0;
23
- }
24
- function indexOfBytes(buffer, search, start = 0) {
25
- for (let i = start; i <= buffer.length - search.length; i++) {
26
- let found = true;
27
- for (let j = 0; j < search.length; j++) {
28
- if (buffer[i + j] !== search[j]) {
29
- found = false;
30
- break;
31
- }
32
- }
33
- if (found) return i;
34
- }
35
- return -1;
36
- }
37
- function createXMPPacket(prompt, seed, model, id, tags = [], hierarchy) {
38
- const sanitize = (str) => (str || "").replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
39
- const escPrompt = sanitize(prompt);
40
- const escModel = sanitize(model || "AI Model");
41
- const escHierarchy = sanitize(hierarchy || "");
42
- const timestamp = (/* @__PURE__ */ new Date()).toISOString();
43
- const allTags = [.../* @__PURE__ */ new Set([...tags, "Avatar Architect", escModel])];
44
- const rdfTags = allTags.map((t) => `<rdf:li>${sanitize(t)}</rdf:li>`).join("");
45
- const BOM = "\uFEFF";
46
- return `<?xpacket begin="${BOM}" id="W5M0MpCehiHzreSzNTczkc9d"?>
47
- <x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Adobe XMP Core 5.6-c140">
48
- <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
49
- <rdf:Description rdf:about=""
50
- xmlns:xmp="http://ns.adobe.com/xap/1.0/"
51
- xmlns:dc="http://purl.org/dc/elements/1.1/"
52
- xmlns:photoshop="http://ns.adobe.com/photoshop/1.0/"
53
- xmlns:ai="http://ns.flow.creative/ai/1.0/">
54
- <dc:format>image/png</dc:format>
55
- <dc:description><rdf:Alt><rdf:li xml:lang="x-default">${escPrompt}</rdf:li></rdf:Alt></dc:description>
56
- <dc:subject><rdf:Bag>${rdfTags}</rdf:Bag></dc:subject>
57
- <photoshop:Instructions>Seed: ${seed} | Model: ${escModel}</photoshop:Instructions>
58
- <xmp:CreateDate>${timestamp}</xmp:CreateDate>
59
- <ai:prompt>${escPrompt}</ai:prompt>
60
- <ai:seed>${seed ?? "0"}</ai:seed>
61
- <ai:model>${escModel}</ai:model>
62
- <ai:hierarchy>${escHierarchy}</ai:hierarchy>
63
- </rdf:Description>
64
- </rdf:RDF>
65
- </x:xmpmeta>${" ".repeat(1024)}<?xpacket end="w"?>`;
66
- }
67
- function bytesToBase64(bytes) {
68
- let binary = "";
69
- const len = bytes.byteLength;
70
- for (let i = 0; i < len; i++) binary += String.fromCharCode(bytes[i]);
71
- return btoa(binary);
72
- }
73
- function base64ToBytes(base64) {
74
- const clean = base64.includes(",") ? base64.split(",")[1] : base64.trim();
75
- try {
76
- const binary = atob(clean);
77
- const bytes = new Uint8Array(binary.length);
78
- for (let i = 0; i < binary.length; i++) bytes[i] = binary.charCodeAt(i);
79
- return bytes;
80
- } catch (e) {
81
- return new Uint8Array(0);
82
- }
83
- }
84
- function injectXMPMetadata(base64, prompt, seed, model, id, tags = [], hierarchy) {
85
- try {
86
- const bytes = base64ToBytes(base64);
87
- if (bytes.length < 8 || bytes[0] !== 137 || bytes[1] !== 80) {
88
- console.warn("Metadaten-Injektion \xFCbersprungen: Datei ist kein PNG.");
89
- return base64;
90
- }
91
- const xmpData = createXMPPacket(prompt, seed, model, id, tags, hierarchy);
92
- const encoder = new TextEncoder();
93
- const keyword = encoder.encode("XML:com.adobe.xmp");
94
- const textBytes = encoder.encode(xmpData);
95
- const chunkData = new Uint8Array(keyword.length + 5 + textBytes.length);
96
- chunkData.set(keyword, 0);
97
- chunkData.set(textBytes, keyword.length + 5);
98
- const type = encoder.encode("iTXt");
99
- const crcInput = new Uint8Array(type.length + chunkData.length);
100
- crcInput.set(type, 0);
101
- crcInput.set(chunkData, type.length);
102
- const crc = calculateCRC(crcInput);
103
- const fullChunk = new Uint8Array(4 + 4 + chunkData.length + 4);
104
- const view = new DataView(fullChunk.buffer);
105
- view.setUint32(0, chunkData.length);
106
- fullChunk.set(type, 4);
107
- fullChunk.set(chunkData, 8);
108
- view.setUint32(8 + chunkData.length, crc);
109
- const IDAT = encoder.encode("IDAT");
110
- const idatPos = indexOfBytes(bytes, IDAT);
111
- const insertPos = idatPos !== -1 ? idatPos - 4 : 8;
112
- const result = new Uint8Array(bytes.length + fullChunk.length);
113
- result.set(bytes.slice(0, insertPos), 0);
114
- result.set(fullChunk, insertPos);
115
- result.set(bytes.slice(insertPos), insertPos + fullChunk.length);
116
- return bytesToBase64(result);
117
- } catch (e) {
118
- console.error("Fehler beim Einbetten der Metadaten:", e);
119
- return base64;
120
- }
121
- }
122
-
123
- // src/lib/project.ts
124
- function generateMarkdownReport(nodes, history) {
125
- let md = "# Avatar Architect - Projekt Report\n\n";
126
- md += `Exportiert: ${(/* @__PURE__ */ new Date()).toLocaleString()}
127
-
128
- `;
129
- md += "## Hierarchie\n";
130
- nodes.forEach((n) => {
131
- md += `- **${n.data?.label || "Unbenannt"}**
132
- `;
133
- });
134
- md += "\n## Historie der Generationen\n";
135
- history.forEach((h, i) => {
136
- md += `### ${i + 1}. Generation (${h.model || "AI"})
137
- `;
138
- md += `- **Zeitstempel**: ${new Date(h.timestamp).toLocaleString()}
139
- `;
140
- md += `- **Seed**: ${h.seed}
141
- `;
142
- md += `- **Prompt**:
143
- > ${h.prompt}
144
-
145
- `;
146
- });
147
- return md;
148
- }
149
- async function exportProjectToZip(nodes, edges, history, galleryItems, settings, workspaceTags, recentLabItemIds) {
150
- const zip = new JSZip();
151
- const projectData = {
152
- nodes,
153
- edges,
154
- history: history.map((h) => ({ ...h, base64: void 0 })),
155
- galleryItems: galleryItems.map((g) => ({ ...g, base64: void 0 })),
156
- settings,
157
- workspaceTags: workspaceTags || null,
158
- recentLabItemIds: recentLabItemIds || [],
159
- version: "1.3.0"
160
- };
161
- zip.file("project.json", JSON.stringify(projectData, null, 2));
162
- zip.file("projekt_bericht.md", generateMarkdownReport(nodes, history));
163
- const imgFolder = zip.folder("images");
164
- if (imgFolder) {
165
- const allItems = [...history, ...galleryItems];
166
- for (const item of allItems) {
167
- if (item.base64) {
168
- try {
169
- const cleanB64 = item.base64.includes(",") ? item.base64.split(",")[1] : item.base64;
170
- const withMeta = injectXMPMetadata(cleanB64, item.prompt || "", item.seed, item.model, item.id, item.tags || []);
171
- imgFolder.file(`${item.id}.png`, withMeta, { base64: true });
172
- } catch (e) {
173
- console.error("Fehler beim Packen eines Bildes:", e);
174
- }
175
- }
176
- }
177
- }
178
- const blob = await zip.generateAsync({ type: "blob", compression: "STORE" });
179
- return blobToBase64(blob);
180
- }
181
- async function blobToBase64(blob) {
182
- return new Promise((resolve, reject) => {
183
- const reader = new FileReader();
184
- reader.onloadend = () => {
185
- const result = reader.result;
186
- resolve({ base64: result.split(",")[1] });
187
- };
188
- reader.onerror = reject;
189
- reader.readAsDataURL(blob);
190
- });
191
- }
192
- async function importProjectFromZip(file) {
193
- const zip = await JSZip.loadAsync(file);
194
- const jsonStr = await zip.file("project.json")?.async("string");
195
- if (!jsonStr) throw new Error("Keine project.json gefunden.");
196
- const data = JSON.parse(jsonStr);
197
- const imgFolder = zip.folder("images");
198
- if (imgFolder) {
199
- const loadImgs = async (items) => {
200
- if (!items) return [];
201
- return Promise.all(items.map(async (h) => {
202
- const imgFile = zip.file(`images/${h.id}.png`);
203
- if (!imgFile) return h;
204
- const b64 = await imgFile.async("base64");
205
- return { ...h, base64: `data:image/png;base64,${b64}` };
206
- }));
207
- };
208
- data.history = await loadImgs(data.history || []);
209
- data.galleryItems = await loadImgs(data.galleryItems || []);
210
- }
211
- return data;
212
- }
213
-
214
- export {
215
- injectXMPMetadata,
216
- exportProjectToZip,
217
- importProjectFromZip
218
- };
@@ -1,56 +0,0 @@
1
- import {
2
- HF_TOKEN_KEY,
3
- getHFToken,
4
- getSessionClientId,
5
- hfBatchArchive,
6
- hfBootstrapFromLegacy,
7
- hfDeleteProject,
8
- hfDownloadBinaryByPath,
9
- hfDownloadJsonByPath,
10
- hfDownloadProject,
11
- hfListDir,
12
- hfListProjects,
13
- hfLoadImageAsBase64,
14
- hfLoadMetadata,
15
- hfLoadTags,
16
- hfSaveMetadata,
17
- hfSaveTags,
18
- hfUploadImage,
19
- hfUploadProject,
20
- hfUploadProjectForm,
21
- hfUploadSmallFile,
22
- listEventPaths,
23
- loadHFState,
24
- loadPendingEvents,
25
- setHFToken,
26
- tsFromEventPath,
27
- writeHFEvent
28
- } from "./chunk-NBUS7AWR.mjs";
29
- export {
30
- HF_TOKEN_KEY,
31
- getHFToken,
32
- getSessionClientId,
33
- hfBatchArchive,
34
- hfBootstrapFromLegacy,
35
- hfDeleteProject,
36
- hfDownloadBinaryByPath,
37
- hfDownloadJsonByPath,
38
- hfDownloadProject,
39
- hfListDir,
40
- hfListProjects,
41
- hfLoadImageAsBase64,
42
- hfLoadMetadata,
43
- hfLoadTags,
44
- hfSaveMetadata,
45
- hfSaveTags,
46
- hfUploadImage,
47
- hfUploadProject,
48
- hfUploadProjectForm,
49
- hfUploadSmallFile,
50
- listEventPaths,
51
- loadHFState,
52
- loadPendingEvents,
53
- setHFToken,
54
- tsFromEventPath,
55
- writeHFEvent
56
- };
@@ -1,8 +0,0 @@
1
- import {
2
- exportProjectToZip,
3
- importProjectFromZip
4
- } from "./chunk-UFXDXENC.mjs";
5
- export {
6
- exportProjectToZip,
7
- importProjectFromZip
8
- };