@anime-studio/import-psd 0.0.0-stage → 0.5.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Dener Fernandes
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,71 @@
1
- # Temporary Holding Version
1
+ # @anime-studio/import-psd
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ [![npm](https://img.shields.io/npm/v/@anime-studio/import-psd)](https://www.npmjs.com/package/@anime-studio/import-psd)
4
+ [![CI](https://github.com/denerFernandes/animeStudio/actions/workflows/ci.yml/badge.svg)](https://github.com/denerFernandes/animeStudio/actions/workflows/ci.yml)
5
+ [![MIT](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/denerFernandes/animeStudio/blob/master/LICENSE)
6
+
7
+ Part of [animeStudio](https://github.com/denerFernandes/animeStudio), a deterministic 2D/2.5D cartoon animation engine: characters are
8
+ SVG art bound to skeletons, scenes are JSON documents, and every frame is a pure function of the
9
+ documents and the time.
10
+
11
+ Turns a layered raster drawing — a Photoshop `.psd` / `.psb` (Photoshop, Krita, GIMP, Photopea,
12
+ Affinity) or an OpenRaster `.ora` (Krita, GIMP, MyPaint) — into an animeStudio character: layers
13
+ named with the same convention as `@anime-studio/import-svg` become bones, parts, switch variants
14
+ and anchors, and each part embeds its layer's pixels as a `data:image/png` image.
15
+
16
+ ## Install
17
+
18
+ ```bash
19
+ npm install @anime-studio/core @anime-studio/import-psd
20
+ # or
21
+ pnpm add @anime-studio/core @anime-studio/import-psd
22
+ ```
23
+
24
+ Requires Node.js 22 or later (or a modern browser / bundler). Pure TypeScript with one dependency
25
+ (`fflate`, MIT) for zip and deflate.
26
+
27
+ ## Usage
28
+
29
+ ```ts
30
+ import { readFileSync, writeFileSync } from "node:fs";
31
+ import { importLayered } from "@anime-studio/import-psd";
32
+
33
+ const { doc, warnings } = importLayered(readFileSync("hero.psd"), { name: "hero" });
34
+ writeFileSync("hero.toon.json", JSON.stringify(doc, null, 2));
35
+ ```
36
+
37
+ Or from the command line: `toon import hero.psd -o hero.toon.json`.
38
+
39
+ ## Layer names
40
+
41
+ | Name | Meaning |
42
+ | --- | --- |
43
+ | `bone:<id>@<parent>` | a stroke painted from joint to tip (a dot for a zero-length bone) |
44
+ | `part:<id>@<bone>` | a pixel layer or group: rigid art on `<bone>` |
45
+ | `switch:<part>/<variant>@<bone>` | variants of a switch part (the topmost is the default) |
46
+ | `anchor:<name>@<bone>` | a dot marking a named point |
47
+ | `origin` | a dot marking the ground origin (default: the bottom centre) |
48
+
49
+ Marker layers (bones, anchors, origin) are usually hidden; they are read anyway. Other hidden
50
+ layers are skipped with a warning.
51
+
52
+ ## Limits
53
+
54
+ - RGB and greyscale documents, 8 or 16 bits per channel. CMYK, Lab, indexed and 32-bit documents
55
+ are rejected with a message (convert to RGB 8-bit first).
56
+ - Layer masks, adjustment layers, layer effects and non-normal blend modes are not applied (blend
57
+ modes are warned about); text and smart objects import as their rendered pixels.
58
+ - Raster art cannot be skinned: a `skin:` layer is imported as a rigid part on its first bone.
59
+ - Krita's own `.kra` is detected and rejected: save as `.ora` (File → Save As → OpenRaster) or `.psd`.
60
+
61
+ ## Documentation
62
+
63
+ - [Getting started and features](https://github.com/denerFernandes/animeStudio#readme)
64
+ - [Format specification](https://github.com/denerFernandes/animeStudio/blob/master/docs/FORMAT.md)
65
+ - [API reference](https://github.com/denerFernandes/animeStudio/blob/master/docs/API.md)
66
+ - [Authoring guide for AI agents](https://github.com/denerFernandes/animeStudio/blob/master/docs/AI_GUIDE.md)
67
+ - [Changelog](https://github.com/denerFernandes/animeStudio/blob/master/CHANGELOG.md)
68
+
69
+ ## License
70
+
71
+ MIT © Dener Fernandes
@@ -0,0 +1,32 @@
1
+ import type { ToonDoc } from "@anime-studio/core";
2
+ import { type LayeredImage } from "./layers.js";
3
+ export interface LayeredImportOptions {
4
+ /** The character's `name` (default `"imported"`). */
5
+ name?: string;
6
+ /** Alpha (0–255) above which a pixel of a marker layer (bone, anchor, origin) counts as painted. Default 8. */
7
+ threshold?: number;
8
+ }
9
+ export interface LayeredImportResult {
10
+ doc: ToonDoc;
11
+ warnings: string[];
12
+ }
13
+ /**
14
+ * Turns a layered drawing into a toon character with the naming convention of `import-svg`.
15
+ *
16
+ * Layer and group names:
17
+ * bone:<id>[@<parent>] a stroke painted from joint to tip (the end nearer the parent bone is the joint;
18
+ * the ends are taken half the stroke's width in from its tips, inside the round caps),
19
+ * or a dot (zero length); `bone:root` places the root bone itself
20
+ * part:<id>@<bone> a pixel layer or a group: rigid art attached to <bone>
21
+ * switch:<part>/<variant>@<bone> variants of a switch part (the topmost one is the default)
22
+ * skin:<id>@<bones> raster art cannot be skinned: imported as a rigid part on the first bone (warned)
23
+ * anchor:<name>@<bone> a dot marking a named point (its centre)
24
+ * origin a dot marking the character's ground origin (default: the bottom centre of the canvas)
25
+ * Unnamed visible pixel layers outside parts become rigid parts on the root bone; unnamed groups are walked.
26
+ * Raster art is embedded as `data:image/png` images cropped to what is painted, positioned where it
27
+ * was drawn (relative to the origin), with the layer's opacity. Hidden layers are skipped (warned),
28
+ * except switch variants and markers, which are usually hidden. Draw order follows the layers panel
29
+ * (top layer in front).
30
+ */
31
+ export declare function layersToToon(image: LayeredImage, opts?: LayeredImportOptions): LayeredImportResult;
32
+ //# sourceMappingURL=convert.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"convert.d.ts","sourceRoot":"","sources":["../src/convert.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAoB,OAAO,EAAQ,MAAM,oBAAoB,CAAC;AAC1E,OAAO,EAAc,KAAK,YAAY,EAAiB,MAAM,UAAU,CAAC;AAGxE,MAAM,WAAW,oBAAoB;IACnC,qDAAqD;IACrD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,+GAA+G;IAC/G,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,mBAAmB;IAClC,GAAG,EAAE,OAAO,CAAC;IACb,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB;AA8GD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,YAAY,EAAE,IAAI,GAAE,oBAAyB,GAAG,mBAAmB,CA6MtG"}
@@ -0,0 +1,334 @@
1
+ import { NORMAL_BLENDS } from "./layers.js";
2
+ import { base64, encodePng } from "./png.js";
3
+ /** Measures the painted pixels of a marker layer (bone, anchor, origin). */
4
+ function measure(img, threshold) {
5
+ const { width, height, data } = img;
6
+ let n = 0;
7
+ let sx = 0;
8
+ let sy = 0;
9
+ for (let y = 0; y < height; y++)
10
+ for (let x = 0; x < width; x++)
11
+ if (data[(y * width + x) * 4 + 3] > threshold) {
12
+ n++;
13
+ sx += x + 0.5;
14
+ sy += y + 0.5;
15
+ }
16
+ if (!n)
17
+ return undefined;
18
+ const cx = sx / n;
19
+ const cy = sy / n;
20
+ let xx = 0;
21
+ let yy = 0;
22
+ let xy = 0;
23
+ for (let y = 0; y < height; y++)
24
+ for (let x = 0; x < width; x++)
25
+ if (data[(y * width + x) * 4 + 3] > threshold) {
26
+ const dx = x + 0.5 - cx;
27
+ const dy = y + 0.5 - cy;
28
+ xx += dx * dx;
29
+ yy += dy * dy;
30
+ xy += dx * dy;
31
+ }
32
+ // Principal axis of the covariance matrix.
33
+ const angle = 0.5 * Math.atan2(2 * xy, xx - yy);
34
+ const ax = Math.cos(angle);
35
+ const ay = Math.sin(angle);
36
+ let lo = Infinity;
37
+ let hi = -Infinity;
38
+ let across = 0;
39
+ for (let y = 0; y < height; y++)
40
+ for (let x = 0; x < width; x++)
41
+ if (data[(y * width + x) * 4 + 3] > threshold) {
42
+ const dx = x + 0.5 - cx;
43
+ const dy = y + 0.5 - cy;
44
+ const t = dx * ax + dy * ay;
45
+ lo = Math.min(lo, t);
46
+ hi = Math.max(hi, t);
47
+ across = Math.max(across, Math.abs(-dx * ay + dy * ax));
48
+ }
49
+ const along = (hi - lo) / 2;
50
+ const at = (t) => [img.left + cx + ax * t, img.top + cy + ay * t];
51
+ // A brush stroke's round caps reach half its width past the points it was dragged between.
52
+ const cap = Math.min(across, along);
53
+ return { count: n, centroid: [img.left + cx, img.top + cy], ends: [at(lo + cap), at(hi - cap)], roundness: along > 0 ? Math.min(1, across / along) : 1 };
54
+ }
55
+ /** Crops a layer's pixels to what is painted (any alpha); undefined when nothing is. */
56
+ function crop(img) {
57
+ const { width, height, data } = img;
58
+ let x0 = width;
59
+ let y0 = height;
60
+ let x1 = -1;
61
+ let y1 = -1;
62
+ for (let y = 0; y < height; y++)
63
+ for (let x = 0; x < width; x++)
64
+ if (data[(y * width + x) * 4 + 3] > 0) {
65
+ if (x < x0)
66
+ x0 = x;
67
+ if (x > x1)
68
+ x1 = x;
69
+ if (y < y0)
70
+ y0 = y;
71
+ if (y > y1)
72
+ y1 = y;
73
+ }
74
+ if (x1 < 0)
75
+ return undefined;
76
+ if (x0 === 0 && y0 === 0 && x1 === width - 1 && y1 === height - 1)
77
+ return img;
78
+ const w = x1 - x0 + 1;
79
+ const h = y1 - y0 + 1;
80
+ const out = new Uint8Array(w * h * 4);
81
+ for (let y = 0; y < h; y++)
82
+ out.set(data.subarray(((y0 + y) * width + x0) * 4, ((y0 + y) * width + x1 + 1) * 4), y * w * 4);
83
+ return { left: img.left + x0, top: img.top + y0, width: w, height: h, data: out };
84
+ }
85
+ const round = (v) => Math.round(v * 100) / 100;
86
+ const fmt = (v) => String(round(v));
87
+ const distToSegment = (p, a, b) => {
88
+ const dx = b[0] - a[0];
89
+ const dy = b[1] - a[1];
90
+ const l2 = dx * dx + dy * dy;
91
+ const t = l2 > 0 ? Math.max(0, Math.min(1, ((p[0] - a[0]) * dx + (p[1] - a[1]) * dy) / l2)) : 0;
92
+ return Math.hypot(p[0] - a[0] - t * dx, p[1] - a[1] - t * dy);
93
+ };
94
+ /**
95
+ * Turns a layered drawing into a toon character with the naming convention of `import-svg`.
96
+ *
97
+ * Layer and group names:
98
+ * bone:<id>[@<parent>] a stroke painted from joint to tip (the end nearer the parent bone is the joint;
99
+ * the ends are taken half the stroke's width in from its tips, inside the round caps),
100
+ * or a dot (zero length); `bone:root` places the root bone itself
101
+ * part:<id>@<bone> a pixel layer or a group: rigid art attached to <bone>
102
+ * switch:<part>/<variant>@<bone> variants of a switch part (the topmost one is the default)
103
+ * skin:<id>@<bones> raster art cannot be skinned: imported as a rigid part on the first bone (warned)
104
+ * anchor:<name>@<bone> a dot marking a named point (its centre)
105
+ * origin a dot marking the character's ground origin (default: the bottom centre of the canvas)
106
+ * Unnamed visible pixel layers outside parts become rigid parts on the root bone; unnamed groups are walked.
107
+ * Raster art is embedded as `data:image/png` images cropped to what is painted, positioned where it
108
+ * was drawn (relative to the origin), with the layer's opacity. Hidden layers are skipped (warned),
109
+ * except switch variants and markers, which are usually hidden. Draw order follows the layers panel
110
+ * (top layer in front).
111
+ */
112
+ export function layersToToon(image, opts = {}) {
113
+ const warnings = [];
114
+ const warn = (m) => warnings.push(m);
115
+ const threshold = opts.threshold ?? 8;
116
+ let origin = [image.width / 2, image.height];
117
+ const bones = [];
118
+ const rigid = [];
119
+ const switches = new Map();
120
+ const anchors = {};
121
+ let order = 0;
122
+ let unnamed = 0;
123
+ const usedIds = new Set();
124
+ /** Every pixel layer of a subtree as an embedded image, bottom first. */
125
+ const images = (layer, inheritedOpacity, label, includeHidden) => {
126
+ const opacity = inheritedOpacity * layer.opacity;
127
+ if (!NORMAL_BLENDS.has(layer.blend))
128
+ warn(`${label}: blend mode "${layer.blend}" is drawn as normal`);
129
+ if (layer.children) {
130
+ const out = [];
131
+ for (const c of [...layer.children].reverse()) {
132
+ if (c.hidden && !includeHidden) {
133
+ warn(`${label}: hidden layer "${c.name}" skipped`);
134
+ continue;
135
+ }
136
+ out.push(...images(c, opacity, `${label}/${c.name}`, includeHidden));
137
+ }
138
+ return out;
139
+ }
140
+ if (!layer.image)
141
+ return [];
142
+ const c = crop(layer.image);
143
+ if (!c)
144
+ return [];
145
+ return [{ left: c.left, top: c.top, width: c.width, height: c.height, opacity, href: `data:image/png;base64,${base64(encodePng(c))}` }];
146
+ };
147
+ const uniquePartId = (id) => {
148
+ let out = id || "part";
149
+ let i = 2;
150
+ while (usedIds.has(out))
151
+ out = `${id}${i++}`;
152
+ usedIds.add(out);
153
+ if (out !== id)
154
+ warn(`part id "${id}" is taken; renamed "${out}"`);
155
+ return out;
156
+ };
157
+ const marker = (layer, label) => {
158
+ const px = layer.image;
159
+ const s = px ? measure(px, threshold) : undefined;
160
+ if (!s)
161
+ warn(`${label}: nothing painted on the marker layer`);
162
+ if (layer.children)
163
+ warn(`${label}: a marker must be a pixel layer, not a group`);
164
+ return s;
165
+ };
166
+ // Layers are top first; walking bottom first gives draw order.
167
+ const walk = (layers, opacity) => {
168
+ for (const layer of [...layers].reverse()) {
169
+ const name = layer.name.trim();
170
+ const colon = name.indexOf(":");
171
+ const kind = colon > 0 ? name.slice(0, colon) : name;
172
+ const rest = colon > 0 ? name.slice(colon + 1) : "";
173
+ const label = name || "(unnamed layer)";
174
+ if (kind === "origin") {
175
+ const s = marker(layer, label);
176
+ if (s)
177
+ origin = s.centroid;
178
+ continue;
179
+ }
180
+ if (kind === "bone") {
181
+ const [id, parent] = rest.split("@");
182
+ const s = marker(layer, `bone "${id}"`);
183
+ if (s)
184
+ bones.push({ id, parent, stroke: s, label });
185
+ continue;
186
+ }
187
+ if (kind === "anchor") {
188
+ const [id, bone] = rest.split("@");
189
+ const s = marker(layer, `anchor "${id}"`);
190
+ if (s && bone)
191
+ anchors[id] = { bone, at: s.centroid };
192
+ else if (s)
193
+ warn(`anchor "${id}" needs @bone`);
194
+ continue;
195
+ }
196
+ if (kind === "switch") {
197
+ const [path, bone] = rest.split("@");
198
+ const [part, variant] = path.split("/");
199
+ let sw = switches.get(part);
200
+ if (!sw) {
201
+ sw = { bone: bone ?? "root", variants: [], order: order++ };
202
+ switches.set(part, sw);
203
+ }
204
+ const art = images(layer, opacity, label, true);
205
+ if (!art.length)
206
+ warn(`${label}: nothing painted`);
207
+ sw.variants.push([variant ?? `v${sw.variants.length}`, art]);
208
+ continue;
209
+ }
210
+ if (layer.hidden) {
211
+ warn(`hidden layer "${label}" skipped`);
212
+ continue;
213
+ }
214
+ if (kind === "part" || kind === "skin") {
215
+ const [id, bones] = rest.split("@");
216
+ let bone = bones;
217
+ if (kind === "skin") {
218
+ bone = (bones ?? "root").split(",")[0];
219
+ warn(`skin "${id}": raster art cannot be skinned; imported as a rigid part on "${bone}"`);
220
+ }
221
+ else if (!bone)
222
+ warn(`part "${id}" has no @bone; attached to root`);
223
+ const art = images(layer, opacity, label, false);
224
+ if (!art.length)
225
+ warn(`${label}: nothing painted`);
226
+ else
227
+ rigid.push({ id: uniquePartId(id), bone: bone ?? "root", art, order: order++ });
228
+ continue;
229
+ }
230
+ if (layer.children) {
231
+ if (!NORMAL_BLENDS.has(layer.blend))
232
+ warn(`${label}: blend mode "${layer.blend}" is drawn as normal`);
233
+ walk(layer.children, opacity * layer.opacity);
234
+ continue;
235
+ }
236
+ const art = images(layer, opacity, label, false);
237
+ if (art.length)
238
+ rigid.push({ id: uniquePartId(`art${unnamed++}`), bone: "root", art, order: order++ });
239
+ }
240
+ };
241
+ walk(image.layers, 1);
242
+ // Switch variants: the topmost layer is the default; we collected bottom first.
243
+ for (const sw of switches.values())
244
+ sw.variants.reverse();
245
+ const toSetup = (p) => [round(p[0] - origin[0]), round(p[1] - origin[1])];
246
+ const imageMarkup = (p) => `<image x="${fmt(p.left - origin[0])}" y="${fmt(p.top - origin[1])}" width="${p.width}" height="${p.height}"${p.opacity < 1 ? ` opacity="${round(p.opacity)}"` : ""} href="${p.href}"/>`;
247
+ const art = (list) => list.map(imageMarkup).join("");
248
+ // Bones: parents first; the joint (`from`) is the end of the stroke nearer the parent bone.
249
+ const byId = new Map(bones.map((b) => [b.id, b]));
250
+ const resolved = new Map();
251
+ const ends = (id, seen = new Set()) => {
252
+ const known = resolved.get(id);
253
+ if (known)
254
+ return known;
255
+ if (id === "root" && !byId.has("root"))
256
+ return { from: origin };
257
+ const b = byId.get(id);
258
+ if (!b || seen.has(id))
259
+ return { from: origin };
260
+ seen.add(id);
261
+ const s = b.stroke;
262
+ let result;
263
+ if (s.roundness > 0.5 || Math.hypot(s.ends[1][0] - s.ends[0][0], s.ends[1][1] - s.ends[0][1]) < 3)
264
+ result = { from: s.centroid };
265
+ else {
266
+ const p = id === "root" ? { from: origin } : ends(b.parent ?? "root", seen);
267
+ const d = (q) => (p.to ? distToSegment(q, p.from, p.to) : Math.hypot(q[0] - p.from[0], q[1] - p.from[1]));
268
+ result = d(s.ends[0]) <= d(s.ends[1]) ? { from: s.ends[0], to: s.ends[1] } : { from: s.ends[1], to: s.ends[0] };
269
+ }
270
+ resolved.set(id, result);
271
+ return result;
272
+ };
273
+ const boneDef = (id, parent) => {
274
+ const e = ends(id);
275
+ const from = toSetup(e.from);
276
+ return { id, ...(id === "root" ? {} : { parent: parent ?? "root" }), from, ...(e.to ? { to: toSetup(e.to) } : {}) };
277
+ };
278
+ const drawnRoot = byId.get("root");
279
+ if (drawnRoot?.parent)
280
+ warn(`bone "root" cannot have a parent; "@${drawnRoot.parent}" ignored`);
281
+ const skeleton = [drawnRoot ? boneDef("root", undefined) : { id: "root" }];
282
+ const placed = new Set(["root"]);
283
+ const pending = bones.filter((b) => b.id !== "root");
284
+ while (pending.length) {
285
+ const idx = pending.findIndex((b) => placed.has(b.parent ?? "root"));
286
+ if (idx < 0) {
287
+ for (const b of pending)
288
+ warn(`bone "${b.id}" has unknown parent "${b.parent}"; attached to root`);
289
+ for (const b of pending)
290
+ b.parent = "root";
291
+ continue;
292
+ }
293
+ const [b] = pending.splice(idx, 1);
294
+ if (placed.has(b.id)) {
295
+ warn(`bone "${b.id}" is defined twice; the second one is ignored`);
296
+ continue;
297
+ }
298
+ skeleton.push(boneDef(b.id, b.parent));
299
+ placed.add(b.id);
300
+ }
301
+ const knownBone = (id) => {
302
+ if (!placed.has(id)) {
303
+ warn(`unknown bone "${id}"; attached to root`);
304
+ return "root";
305
+ }
306
+ return id;
307
+ };
308
+ const parts = [
309
+ ...rigid.map((r) => ({ id: r.id, type: "rigid", bone: knownBone(r.bone), art: art(r.art), order: r.order })),
310
+ ...[...switches.entries()].map(([id, sw]) => ({
311
+ id: uniquePartId(id),
312
+ type: "switch",
313
+ bone: knownBone(sw.bone),
314
+ variants: Object.fromEntries(sw.variants.map(([k, v]) => [k, art(v)])),
315
+ default: sw.variants[0][0],
316
+ order: sw.order,
317
+ })),
318
+ ];
319
+ parts.sort((a, b) => a.order - b.order);
320
+ if (!parts.length)
321
+ warn("no painted layers: the character has no parts");
322
+ const doc = {
323
+ format: "toon",
324
+ version: 1,
325
+ name: opts.name ?? "imported",
326
+ skeleton,
327
+ parts: parts.map(({ order: _o, ...p }) => p),
328
+ ...(Object.keys(anchors).length
329
+ ? { anchors: Object.fromEntries(Object.entries(anchors).map(([k, a]) => [k, { bone: knownBone(a.bone), at: toSetup(a.at) }])) }
330
+ : {}),
331
+ };
332
+ return { doc, warnings };
333
+ }
334
+ //# sourceMappingURL=convert.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"convert.js","sourceRoot":"","sources":["../src/convert.ts"],"names":[],"mappings":"AACA,OAAO,EAAiC,aAAa,EAAE,MAAM,UAAU,CAAC;AACxE,OAAO,EAAa,MAAM,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAmCrD,4EAA4E;AAC5E,SAAS,OAAO,CAAC,GAAW,EAAE,SAAiB;IAC7C,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,GAAG,CAAC;IACpC,IAAI,CAAC,GAAG,CAAC,CAAC;IACV,IAAI,EAAE,GAAG,CAAC,CAAC;IACX,IAAI,EAAE,GAAG,CAAC,CAAC;IACX,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,EAAE,CAAC,EAAE;QAC7B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,EAAE,CAAC,EAAE;YAC5B,IAAI,IAAI,CAAC,CAAC,CAAC,GAAG,KAAK,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,SAAS,EAAE,CAAC;gBAC9C,CAAC,EAAE,CAAC;gBACJ,EAAE,IAAI,CAAC,GAAG,GAAG,CAAC;gBACd,EAAE,IAAI,CAAC,GAAG,GAAG,CAAC;YAChB,CAAC;IACL,IAAI,CAAC,CAAC;QAAE,OAAO,SAAS,CAAC;IACzB,MAAM,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;IAClB,MAAM,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;IAClB,IAAI,EAAE,GAAG,CAAC,CAAC;IACX,IAAI,EAAE,GAAG,CAAC,CAAC;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Photoshop documents (`.psd` / `.psb`, as written by Photoshop, Krita, GIMP, Photopea,
5
+ * Affinity) and OpenRaster files (`.ora`, Krita / GIMP / MyPaint), and turns layers named with the
6
+ * `import-svg` naming convention into a character document whose parts embed the layers' pixels as
7
+ * `data:image/png` images. Pure TypeScript (one dependency, `fflate`, for zip and deflate): runs in
8
+ * Node and in browsers.
9
+ */
10
+ import { type LayeredImportOptions, type LayeredImportResult } from "./convert.js";
11
+ import type { LayeredImage } from "./layers.js";
12
+ export { type LayeredImportOptions, type LayeredImportResult, layersToToon } from "./convert.js";
13
+ export type { Layer, LayeredImage } from "./layers.js";
14
+ export { readOra } from "./ora.js";
15
+ export { type Rgba, decodePng, encodePng, pngSize } from "./png.js";
16
+ export { readPsd } from "./psd.js";
17
+ /** Imports a Photoshop document (`.psd` / `.psb`) as a character. */
18
+ export declare function importPsd(bytes: Uint8Array | ArrayBuffer, opts?: LayeredImportOptions): LayeredImportResult;
19
+ /** Imports an OpenRaster file (`.ora`) as a character. */
20
+ export declare function importOra(bytes: Uint8Array | ArrayBuffer, opts?: LayeredImportOptions): LayeredImportResult;
21
+ /** Which layered format some bytes are: `psd` (8BPS), `ora` (a zip), or undefined. */
22
+ export declare function layeredFormat(bytes: Uint8Array | ArrayBuffer): "psd" | "ora" | undefined;
23
+ /**
24
+ * Reads a layered drawing whatever its format (detected from the bytes: a PSD's signature, an
25
+ * OpenRaster zip). A Krita `.kra` is a zip too but stores its layers in Krita's own tiled format:
26
+ * it is rejected with an error saying to save the drawing as `.ora` (Krita: File → Save As →
27
+ * OpenRaster) or `.psd`.
28
+ */
29
+ export declare function readLayered(bytes: Uint8Array | ArrayBuffer): LayeredImage;
30
+ /** Imports a PSD, PSB or ORA file as a character, detecting the format from its bytes. */
31
+ export declare function importLayered(bytes: Uint8Array | ArrayBuffer, opts?: LayeredImportOptions): LayeredImportResult;
32
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,KAAK,oBAAoB,EAAE,KAAK,mBAAmB,EAAgB,MAAM,WAAW,CAAC;AAC9F,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAI7C,OAAO,EAAE,KAAK,oBAAoB,EAAE,KAAK,mBAAmB,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAC9F,YAAY,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAChC,OAAO,EAAE,KAAK,IAAI,EAAE,SAAS,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AACjE,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAEhC,qEAAqE;AACrE,wBAAgB,SAAS,CAAC,KAAK,EAAE,UAAU,GAAG,WAAW,EAAE,IAAI,GAAE,oBAAyB,GAAG,mBAAmB,CAE/G;AAED,0DAA0D;AAC1D,wBAAgB,SAAS,CAAC,KAAK,EAAE,UAAU,GAAG,WAAW,EAAE,IAAI,GAAE,oBAAyB,GAAG,mBAAmB,CAE/G;AAED,sFAAsF;AACtF,wBAAgB,aAAa,CAAC,KAAK,EAAE,UAAU,GAAG,WAAW,GAAG,KAAK,GAAG,KAAK,GAAG,SAAS,CAKxF;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,UAAU,GAAG,WAAW,GAAG,YAAY,CAYzE;AAED,0FAA0F;AAC1F,wBAAgB,aAAa,CAAC,KAAK,EAAE,UAAU,GAAG,WAAW,EAAE,IAAI,GAAE,oBAAyB,GAAG,mBAAmB,CAEnH"}
package/dist/index.js ADDED
@@ -0,0 +1,58 @@
1
+ /**
2
+ * `@anime-studio/import-psd`: layered raster drawings → animeStudio characters.
3
+ *
4
+ * Reads Photoshop documents (`.psd` / `.psb`, as written by Photoshop, Krita, GIMP, Photopea,
5
+ * Affinity) and OpenRaster files (`.ora`, Krita / GIMP / MyPaint), and turns layers named with the
6
+ * `import-svg` naming convention into a character document whose parts embed the layers' pixels as
7
+ * `data:image/png` images. Pure TypeScript (one dependency, `fflate`, for zip and deflate): runs in
8
+ * Node and in browsers.
9
+ */
10
+ import { layersToToon } from "./convert.js";
11
+ import { readOra } from "./ora.js";
12
+ import { readPsd } from "./psd.js";
13
+ export { layersToToon } from "./convert.js";
14
+ export { readOra } from "./ora.js";
15
+ export { decodePng, encodePng, pngSize } from "./png.js";
16
+ export { readPsd } from "./psd.js";
17
+ /** Imports a Photoshop document (`.psd` / `.psb`) as a character. */
18
+ export function importPsd(bytes, opts = {}) {
19
+ return layersToToon(readPsd(bytes), opts);
20
+ }
21
+ /** Imports an OpenRaster file (`.ora`) as a character. */
22
+ export function importOra(bytes, opts = {}) {
23
+ return layersToToon(readOra(bytes), opts);
24
+ }
25
+ /** Which layered format some bytes are: `psd` (8BPS), `ora` (a zip), or undefined. */
26
+ export function layeredFormat(bytes) {
27
+ const b = bytes instanceof Uint8Array ? bytes : new Uint8Array(bytes);
28
+ if (b[0] === 0x38 && b[1] === 0x42 && b[2] === 0x50 && b[3] === 0x53)
29
+ return "psd";
30
+ if (b[0] === 0x50 && b[1] === 0x4b && b[2] === 0x03 && b[3] === 0x04)
31
+ return "ora";
32
+ return undefined;
33
+ }
34
+ /**
35
+ * Reads a layered drawing whatever its format (detected from the bytes: a PSD's signature, an
36
+ * OpenRaster zip). A Krita `.kra` is a zip too but stores its layers in Krita's own tiled format:
37
+ * it is rejected with an error saying to save the drawing as `.ora` (Krita: File → Save As →
38
+ * OpenRaster) or `.psd`.
39
+ */
40
+ export function readLayered(bytes) {
41
+ const format = layeredFormat(bytes);
42
+ if (format === "psd")
43
+ return readPsd(bytes);
44
+ if (format === "ora") {
45
+ const b = bytes instanceof Uint8Array ? bytes : new Uint8Array(bytes);
46
+ const head = new TextDecoder("latin1").decode(b.subarray(0, Math.min(b.length, 200)));
47
+ if (head.includes("application/x-krita")) {
48
+ throw new Error("Krita .kra files store layers in Krita's own format: save the drawing as OpenRaster (.ora) or Photoshop (.psd) and import that");
49
+ }
50
+ return readOra(bytes);
51
+ }
52
+ throw new Error("not a layered drawing (expected a PSD/PSB or an OpenRaster .ora file)");
53
+ }
54
+ /** Imports a PSD, PSB or ORA file as a character, detecting the format from its bytes. */
55
+ export function importLayered(bytes, opts = {}) {
56
+ return layersToToon(readLayered(bytes), opts);
57
+ }
58
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAuD,YAAY,EAAE,MAAM,WAAW,CAAC;AAE9F,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAChC,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAEhC,OAAO,EAAuD,YAAY,EAAE,MAAM,WAAW,CAAC;AAE9F,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAChC,OAAO,EAAa,SAAS,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AACjE,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAEhC,qEAAqE;AACrE,MAAM,UAAU,SAAS,CAAC,KAA+B,EAAE,IAAI,GAAyB,EAAE;IACxF,OAAO,YAAY,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,IAAI,CAAC,CAAC;AAC5C,CAAC;AAED,0DAA0D;AAC1D,MAAM,UAAU,SAAS,CAAC,KAA+B,EAAE,IAAI,GAAyB,EAAE;IACxF,OAAO,YAAY,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,IAAI,CAAC,CAAC;AAC5C,CAAC;AAED,sFAAsF;AACtF,MAAM,UAAU,aAAa,CAAC,KAA+B;IAC3D,MAAM,CAAC,GAAG,KAAK,YAAY,UAAU,CAAC,CAAC,CA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AAC,uEAAuE,CAAC,CAAC;AAC3F,CAAC;AAED,0FAA0F;AAC1F,MAAM,UAAU,aAAa,CAAC,KAA+B,EAAE,IAAI,GAAyB,EAAE;IAC5F,OAAO,YAAY,CAAC,WAAW,CAAC,KAAK,CAAC,EAAE,IAAI,CAAC,CAAC;AAChD,CAAC"}
@@ -0,0 +1,29 @@
1
+ import type { Rgba } from "./png.js";
2
+ /**
3
+ * A layered drawing as the importers read it, independent of the file format.
4
+ * Layers are listed **top first** (the order a layers panel shows them).
5
+ */
6
+ export interface LayeredImage {
7
+ width: number;
8
+ height: number;
9
+ layers: Layer[];
10
+ }
11
+ export interface Layer {
12
+ name: string;
13
+ /** Hidden in the file (the eye switched off). */
14
+ hidden: boolean;
15
+ /** 0–1. */
16
+ opacity: number;
17
+ /** Blend mode as the file names it (`norm`, `svg:src-over`, `pass`, …). */
18
+ blend: string;
19
+ /** A group's children, top first; undefined for a pixel layer. */
20
+ children?: Layer[];
21
+ /** A pixel layer's pixels, placed at `left`, `top` in the canvas. Undefined for groups and empty layers. */
22
+ image?: {
23
+ left: number;
24
+ top: number;
25
+ } & Rgba;
26
+ }
27
+ /** Normal blending, as each format names it (anything else is warned about and drawn as normal). */
28
+ export declare const NORMAL_BLENDS: Set<string>;
29
+ //# sourceMappingURL=layers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"layers.d.ts","sourceRoot":"","sources":["../src/layers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC;AAElC;;;GAGG;AACH,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,KAAK,EAAE,CAAC;CACjB;AAED,MAAM,WAAW,KAAK;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,iDAAiD;IACjD,MAAM,EAAE,OAAO,CAAC;IAChB,WAAW;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,2EAA2E;IAC3E,KAAK,EAAE,MAAM,CAAC;IACd,kEAAkE;IAClE,QAAQ,CAAC,EAAE,KAAK,EAAE,CAAC;IACnB,4GAA4G;IAC5G,KAAK,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC;CAC9C;AAED,oGAAoG;AACpG,eAAO,MAAM,aAAa,aAAgD,CAAC"}
package/dist/layers.js ADDED
@@ -0,0 +1,3 @@
1
+ /** Normal blending, as each format names it (anything else is warned about and drawn as normal). */
2
+ export const NORMAL_BLENDS = new Set(["norm", "pass", "svg:src-over", ""]);
3
+ //# sourceMappingURL=layers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"layers.js","sourceRoot":"","sources":["../src/layers.ts"],"names":[],"mappings":"AA0BA,oGAAoG;AACpG,MAAM,CAAC,MAAM,aAAa,GAAG,IAAI,GAAG,CAAC,CAAC,MAAM,EAAE,MAAM,EAAE,cAAc,EAAE,EAAE,CAAC,CAAC,CAAC"}