@fleox/agentphoto 0.1.0 → 0.1.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.
Files changed (37) hide show
  1. package/README.md +177 -72
  2. package/changelog.json +18 -0
  3. package/dist/agent/agentphoto.mjs +64 -17
  4. package/dist/agent/chunks/{assets-CDQo3VqD.mjs → assets-BZVUUHjg.mjs} +3 -3
  5. package/dist/agent/chunks/{context-DoLoLF9f.mjs → context-CNpRboiC.mjs} +1 -1
  6. package/dist/agent/chunks/{doc-BjY_j4Su.mjs → doc-D_v_yE07.mjs} +25 -286
  7. package/dist/agent/chunks/{export-CLmpFART.mjs → export-aNJcPNbJ.mjs} +1 -1
  8. package/dist/agent/chunks/geometry-BKIhUO9x.mjs +315 -0
  9. package/dist/agent/chunks/{models-C4i_hicr.mjs → models-CxrjmA0W.mjs} +1 -1
  10. package/dist/agent/chunks/{package-DSmAxrla.mjs → package-Cu1GyvKL.mjs} +2 -2
  11. package/dist/agent/chunks/{project-CUykGysG.mjs → project-o1DH2nOw.mjs} +12 -10
  12. package/dist/agent/chunks/{templates--YGpGuHh.mjs → templates-BJ2me4XZ.mjs} +24 -3
  13. package/dist/agent/chunks/{tools-Dnh8g6F9.mjs → tools-DKaAPEV5.mjs} +92 -27
  14. package/dist/agent/chunks/{tree-DO7N0UDV.mjs → tree-D8qZKPAb.mjs} +2 -2
  15. package/dist/engine/agentphoto-engine.js +408 -352
  16. package/dist/studio/assets/index-CmOzzoXv.css +1 -0
  17. package/dist/studio/assets/index-D3Iw5q8v.js +28 -0
  18. package/dist/studio/assets/{transformers.web-DgnCIB_X.js → transformers.web-osEqoMhg.js} +1 -1
  19. package/dist/studio/index.html +2 -2
  20. package/dist/studio/templates/index.json +1 -1
  21. package/dist/studio/templates/product-white/photo.json +2 -2
  22. package/dist/studio/templates/product-white/preview.jpg +0 -0
  23. package/dist/studio/templates/product-white/template.json +1 -1
  24. package/package.json +2 -2
  25. package/plugin/.claude-plugin/plugin.json +1 -1
  26. package/plugin/skills/agentphoto-cutout/SKILL.md +30 -25
  27. package/plugin/skills/agentphoto-design/SKILL.md +24 -24
  28. package/plugin/skills/agentphoto-publish/SKILL.md +10 -10
  29. package/plugin/skills/agentphoto-retouch/SKILL.md +26 -26
  30. package/plugin/skills/agentphoto-retouch/references/filters.md +1 -1
  31. package/plugin/skills/agentphoto-retouch/references/patch-ops.md +14 -13
  32. package/plugin/skills/agentphoto-retouch/references/recipes.md +3 -3
  33. package/templates/product-white/photo.json +2 -2
  34. package/templates/product-white/preview.jpg +0 -0
  35. package/templates/product-white/template.json +1 -1
  36. package/dist/studio/assets/index-Be8JnaFy.js +0 -28
  37. package/dist/studio/assets/index-DwPms2S5.css +0 -1
@@ -0,0 +1,315 @@
1
+ import { createRequire as __apRequire } from "node:module";
2
+ import { fileURLToPath as __apPath } from "node:url";
3
+ import { dirname as __apDirname } from "node:path";
4
+ __apRequire(import.meta.url);
5
+ const __filename = __apPath(import.meta.url);
6
+ __apDirname(__filename);
7
+ import { t as __exportAll } from "./rolldown-runtime-CMQPkI6i.mjs";
8
+ import { c as filterDef, i as EFFECTS } from "./catalog-DIZ5dnH5.mjs";
9
+ import { a as isShapeMask, n as hasBox, r as isGradientMask } from "./types-DOK7tAAu.mjs";
10
+ import { r as OpsError } from "./context-CNpRboiC.mjs";
11
+ // src/ops/geometry.ts
12
+ var geometry_exports = /* @__PURE__ */ __exportAll({ cropDoc: () => cropDoc });
13
+ var ANCHORS = [
14
+ "top-left",
15
+ "top",
16
+ "top-right",
17
+ "left",
18
+ "center",
19
+ "right",
20
+ "bottom-left",
21
+ "bottom",
22
+ "bottom-right"
23
+ ];
24
+ var clone = (v) => JSON.parse(JSON.stringify(v));
25
+ var r2 = (v) => Math.round(v * 100) / 100;
26
+ function estimateTextBox(l) {
27
+ const size = l.size ?? 64;
28
+ const lines = String(l.text ?? "").split("\n");
29
+ const longest = Math.max(1, ...lines.map((s) => s.length));
30
+ return {
31
+ width: l.width ?? longest * size * .55 + Math.max(0, longest - 1) * (l.letterSpacing ?? 0),
32
+ height: l.height ?? lines.length * size * (l.lineHeight ?? 1.2)
33
+ };
34
+ }
35
+ function layerBox(l, sizes = {}) {
36
+ if (!hasBox(l)) return null;
37
+ const x = l.x ?? 0;
38
+ const y = l.y ?? 0;
39
+ if (l.type === "text") return {
40
+ x,
41
+ y,
42
+ ...estimateTextBox(l)
43
+ };
44
+ let w = l.width;
45
+ let h = l.height;
46
+ if (l.type === "image" && (w === void 0 || h === void 0)) {
47
+ const nat = sizes[l.src];
48
+ const src = l.crop ? {
49
+ width: l.crop.width,
50
+ height: l.crop.height
51
+ } : nat;
52
+ if (src) {
53
+ if (w === void 0 && h === void 0) [w, h] = [src.width, src.height];
54
+ else if (w === void 0) w = h * src.width / src.height;
55
+ else h = w * src.height / src.width;
56
+ }
57
+ }
58
+ if (w === void 0 || h === void 0) return null;
59
+ return {
60
+ x,
61
+ y,
62
+ width: w,
63
+ height: h
64
+ };
65
+ }
66
+ function pinSize(l, sizes) {
67
+ if (l.type !== "image" || l.width !== void 0 && l.height !== void 0) return;
68
+ const b = layerBox(l, sizes);
69
+ if (!b) throw new OpsError("invalid", `The size of image layer "${l.id}" is unknown (its source ${l.src} could not be read).`, "Give the layer an explicit width and height, or fix its src (assets_list).");
70
+ l.width = r2(b.width);
71
+ l.height = r2(b.height);
72
+ }
73
+ function eachLayer(layers, fn) {
74
+ for (const l of layers) {
75
+ fn(l);
76
+ if (l.type === "group") eachLayer(l.children ?? [], fn);
77
+ }
78
+ }
79
+ function translateMask(m, dx, dy) {
80
+ if (m && isShapeMask(m)) {
81
+ m.x = r2(m.x + dx);
82
+ m.y = r2(m.y + dy);
83
+ }
84
+ }
85
+ function translateAll(layers, dx, dy) {
86
+ eachLayer(layers, (l) => {
87
+ if (hasBox(l)) {
88
+ l.x = r2((l.x ?? 0) + dx);
89
+ l.y = r2((l.y ?? 0) + dy);
90
+ } else translateMask(l.mask, dx, dy);
91
+ });
92
+ }
93
+ function cropDoc(doc, rect) {
94
+ const { x, y, width, height } = rect;
95
+ if (![
96
+ x,
97
+ y,
98
+ width,
99
+ height
100
+ ].every(Number.isFinite) || width < 1 || height < 1) throw new OpsError("invalid", "crop needs x, y, width ≥ 1, height ≥ 1 (canvas pixels).");
101
+ const out = clone(doc);
102
+ translateAll(out.layers, -x, -y);
103
+ out.canvas = {
104
+ ...out.canvas,
105
+ width: Math.round(width),
106
+ height: Math.round(height)
107
+ };
108
+ return out;
109
+ }
110
+ function anchorOffset(anchor, dw, dh) {
111
+ const ax = anchor.endsWith("left") ? 0 : anchor.endsWith("right") ? 1 : .5;
112
+ const ay = anchor.startsWith("top") ? 0 : anchor.startsWith("bottom") ? 1 : .5;
113
+ return [dw * ax, dh * ay];
114
+ }
115
+ function resizeCanvasDoc(doc, width, height, anchor = "center") {
116
+ if (!ANCHORS.includes(anchor)) throw new OpsError("invalid", `Unknown anchor "${anchor}".`, `Anchors: ${ANCHORS.join(", ")}.`);
117
+ const [ox, oy] = anchorOffset(anchor, width - doc.canvas.width, height - doc.canvas.height);
118
+ return cropDoc(doc, {
119
+ x: -ox,
120
+ y: -oy,
121
+ width,
122
+ height
123
+ });
124
+ }
125
+ function scalePx(obj, keys, k) {
126
+ if (!obj) return;
127
+ for (const key of keys) if (typeof obj[key] === "number") obj[key] = r2(obj[key] * k);
128
+ }
129
+ function scaleFilters(filters, k) {
130
+ for (const f of filters ?? []) scalePx(f, (filterDef(f.type)?.params ?? []).filter((p) => p.px).map((p) => p.name), k);
131
+ }
132
+ function scaleDoc(doc, sx, sy, sizes = {}) {
133
+ if (!(sx > 0) || !(sy > 0)) throw new OpsError("invalid", "The scale must be > 0.");
134
+ const out = clone(doc);
135
+ eachLayer(out.layers, (l) => scaleLayer(l, sx, sy, sizes));
136
+ out.canvas = {
137
+ ...out.canvas,
138
+ width: Math.max(1, Math.round(doc.canvas.width * sx)),
139
+ height: Math.max(1, Math.round(doc.canvas.height * sy))
140
+ };
141
+ return out;
142
+ }
143
+ function scaleLayer(l, sx, sy, sizes) {
144
+ const k = Math.sqrt(sx * sy);
145
+ pinSize(l, sizes);
146
+ if (hasBox(l)) {
147
+ l.x = r2((l.x ?? 0) * sx);
148
+ l.y = r2((l.y ?? 0) * sy);
149
+ if (l.width !== void 0) l.width = r2(l.width * sx);
150
+ if (l.height !== void 0) l.height = r2(l.height * sy);
151
+ } else if (l.mask && isShapeMask(l.mask)) {
152
+ const m = l.mask;
153
+ m.x = r2(m.x * sx);
154
+ m.y = r2(m.y * sy);
155
+ m.width = r2(m.width * sx);
156
+ m.height = r2(m.height * sy);
157
+ }
158
+ if (l.mask) {
159
+ if (hasBox(l) && isShapeMask(l.mask)) {
160
+ const m = l.mask;
161
+ m.x = r2(m.x * sx);
162
+ m.y = r2(m.y * sy);
163
+ m.width = r2(m.width * sx);
164
+ m.height = r2(m.height * sy);
165
+ }
166
+ scalePx(l.mask, ["feather", "radius"], k);
167
+ }
168
+ if (l.type === "text") {
169
+ scalePx(l, ["size", "letterSpacing"], k);
170
+ if (l.background) {
171
+ const p = l.background.padding;
172
+ l.background.padding = Array.isArray(p) ? [r2(p[0] * k), r2(p[1] * k)] : typeof p === "number" ? r2(p * k) : p;
173
+ scalePx(l.background, ["radius"], k);
174
+ }
175
+ }
176
+ if (l.type === "shape") {
177
+ scalePx(l, ["radius"], k);
178
+ if (l.stroke) scalePx(l.stroke, ["width"], k);
179
+ }
180
+ scaleFilters(l.filters, k);
181
+ if (l.effects) for (const def of EFFECTS) {
182
+ const fx = l.effects[def.id];
183
+ scalePx(fx, def.params.filter((p) => p.px).map((p) => p.name), k);
184
+ }
185
+ }
186
+ var isRect = (r) => !!r && typeof r === "object" && [
187
+ "x",
188
+ "y",
189
+ "width",
190
+ "height"
191
+ ].every((k) => Number.isFinite(r[k]));
192
+ function fitLayerDoc(doc, id, box, opts = {}) {
193
+ if (!isRect(box) || box.width < 1 || box.height < 1) throw new OpsError("invalid", "fitLayer needs box { x, y, width ≥ 1, height ≥ 1 } (canvas px).");
194
+ const anchor = opts.anchor ?? "center";
195
+ if (!ANCHORS.includes(anchor)) throw new OpsError("invalid", `Unknown anchor "${anchor}".`, `Anchors: ${ANCHORS.join(", ")}.`);
196
+ const out = clone(doc);
197
+ let layer = null;
198
+ eachLayer(out.layers, (l) => {
199
+ if (l.id === id && !layer) layer = l;
200
+ });
201
+ const l = layer;
202
+ if (!l) throw new OpsError("notFound", `No layer "${id}".`, "layer_list lists the layer ids.");
203
+ if (!hasBox(l)) throw new OpsError("invalid", `"${id}" is a ${l.type} layer: fitLayer moves image, text and shape layers.`);
204
+ pinSize(l, opts.sizes ?? {});
205
+ const b = layerBox(l, opts.sizes);
206
+ if (!b || !(b.width > 0) || !(b.height > 0)) throw new OpsError("invalid", `The box of layer "${id}" is unknown.`, "Give the layer an explicit width and height.");
207
+ const subj = opts.subject ?? b;
208
+ if (!isRect(subj) || !(subj.width > 0) || !(subj.height > 0)) throw new OpsError("invalid", "fitLayer subject must be { x, y, width > 0, height > 0 } (canvas px).", "Pass the subject returned by remove_background, or omit it to fit the whole layer.");
209
+ const k = Math.min(box.width / subj.width, box.height / subj.height);
210
+ const [ox, oy] = anchorOffset(anchor, box.width - subj.width * k, box.height - subj.height * k);
211
+ const relX = subj.x - b.x;
212
+ const relY = subj.y - b.y;
213
+ scaleLayer(l, k, k, opts.sizes ?? {});
214
+ l.x = r2(box.x + ox - relX * k);
215
+ l.y = r2(box.y + oy - relY * k);
216
+ return out;
217
+ }
218
+ var normAngle = (deg) => {
219
+ const a = ((deg + 180) % 360 + 360) % 360 - 180;
220
+ return a === -180 ? 180 : a;
221
+ };
222
+ function transformPaint(p, fn) {
223
+ if (!p || typeof p !== "object") return;
224
+ if (p.type === "linear") p.angle = r2(normAngle(fn.angle(p.angle ?? 90)));
225
+ else if (p.type === "radial") {
226
+ const [cx, cy] = fn.point(p.cx ?? .5, p.cy ?? .5);
227
+ p.cx = r2(cx);
228
+ p.cy = r2(cy);
229
+ }
230
+ }
231
+ function transformCanvasPaints(doc, fn) {
232
+ transformPaint(doc.canvas.background, fn);
233
+ eachLayer(doc.layers, (l) => {
234
+ if (hasBox(l)) return;
235
+ if (l.type === "fill") transformPaint(l.fill, fn);
236
+ if (l.mask && isGradientMask(l.mask)) transformPaint(l.mask.gradient, fn);
237
+ });
238
+ }
239
+ function rotateDoc(doc, angle, sizes = {}) {
240
+ const a = (Math.round(angle / 90) * 90 % 360 + 360) % 360;
241
+ if (angle % 90 !== 0) throw new OpsError("invalid", `Canvas rotation must be a multiple of 90°, got ${angle}.`, "To straighten a photo by a few degrees, set the image layer's rotation instead (and crop).");
242
+ if (a === 0) return clone(doc);
243
+ const out = clone(doc);
244
+ const W = doc.canvas.width;
245
+ const H = doc.canvas.height;
246
+ const map = (x, y) => a === 90 ? [H - y, x] : a === 180 ? [W - x, H - y] : [y, W - x];
247
+ eachLayer(out.layers, (l) => {
248
+ pinSize(l, sizes);
249
+ const box = layerBox(l, sizes);
250
+ if (box) {
251
+ const [cx, cy] = map(box.x + box.width / 2, box.y + box.height / 2);
252
+ const bl = l;
253
+ bl.x = r2(cx - box.width / 2);
254
+ bl.y = r2(cy - box.height / 2);
255
+ bl.rotation = normAngle((bl.rotation ?? 0) + a);
256
+ if (bl.rotation === 0) delete bl.rotation;
257
+ } else if (l.mask && isShapeMask(l.mask)) {
258
+ const m = l.mask;
259
+ const [cx, cy] = map(m.x + m.width / 2, m.y + m.height / 2);
260
+ const [w, h] = a === 180 ? [m.width, m.height] : [m.height, m.width];
261
+ Object.assign(m, {
262
+ x: r2(cx - w / 2),
263
+ y: r2(cy - h / 2),
264
+ width: w,
265
+ height: h
266
+ });
267
+ }
268
+ });
269
+ transformCanvasPaints(out, {
270
+ angle: (deg) => deg + a,
271
+ point: (fx, fy) => a === 90 ? [1 - fy, fx] : a === 180 ? [1 - fx, 1 - fy] : [fy, 1 - fx]
272
+ });
273
+ if (a !== 180) out.canvas = {
274
+ ...out.canvas,
275
+ width: H,
276
+ height: W
277
+ };
278
+ return out;
279
+ }
280
+ function flipDoc(doc, axis, sizes = {}) {
281
+ if (axis !== "horizontal" && axis !== "vertical") throw new OpsError("invalid", `axis must be "horizontal" or "vertical".`);
282
+ const out = clone(doc);
283
+ const W = doc.canvas.width;
284
+ const H = doc.canvas.height;
285
+ eachLayer(out.layers, (l) => {
286
+ pinSize(l, sizes);
287
+ const box = layerBox(l, sizes);
288
+ if (box) {
289
+ const bl = l;
290
+ if (axis === "horizontal") {
291
+ bl.x = r2(W - box.x - box.width);
292
+ if (l.type !== "text") bl.flipX = !bl.flipX || void 0;
293
+ } else {
294
+ bl.y = r2(H - box.y - box.height);
295
+ if (l.type !== "text") bl.flipY = !bl.flipY || void 0;
296
+ }
297
+ if (bl.rotation) bl.rotation = -bl.rotation;
298
+ if (!bl.flipX) delete bl.flipX;
299
+ if (!bl.flipY) delete bl.flipY;
300
+ } else if (l.mask && isShapeMask(l.mask)) {
301
+ const m = l.mask;
302
+ if (axis === "horizontal") m.x = r2(W - m.x - m.width);
303
+ else m.y = r2(H - m.y - m.height);
304
+ }
305
+ });
306
+ transformCanvasPaints(out, axis === "horizontal" ? {
307
+ angle: (deg) => 180 - deg,
308
+ point: (fx, fy) => [1 - fx, fy]
309
+ } : {
310
+ angle: (deg) => -deg,
311
+ point: (fx, fy) => [fx, 1 - fy]
312
+ });
313
+ return out;
314
+ }
315
+ export { geometry_exports as a, rotateDoc as c, flipDoc as i, scaleDoc as l, cropDoc as n, layerBox as o, fitLayerDoc as r, resizeCanvasDoc as s, ANCHORS as t };
@@ -6,7 +6,7 @@ const __filename = __apPath(import.meta.url);
6
6
  __apDirname(__filename);
7
7
  import { t as __exportAll } from "./rolldown-runtime-CMQPkI6i.mjs";
8
8
  import { o as MODELS } from "./catalog-DIZ5dnH5.mjs";
9
- import { t as package_default } from "./package-DSmAxrla.mjs";
9
+ import { t as package_default } from "./package-Cu1GyvKL.mjs";
10
10
  import { createReadStream, createWriteStream, existsSync, mkdirSync, readFileSync, readdirSync, realpathSync, renameSync, rmSync, statSync } from "node:fs";
11
11
  import { homedir } from "node:os";
12
12
  import { createServer } from "node:http";
@@ -6,7 +6,7 @@ const __filename = __apPath(import.meta.url);
6
6
  __apDirname(__filename);
7
7
  // package.json
8
8
  var name = "@fleox/agentphoto";
9
- var version = "0.1.0";
9
+ var version = "0.1.1";
10
10
  var package_default = {
11
11
  name,
12
12
  version,
@@ -41,7 +41,7 @@ var package_default = {
41
41
  "check:docs": "node scripts/build-cli-docs.mjs --check",
42
42
  "hermes:build": "node scripts/build-hermes.mjs",
43
43
  "check:hermes": "node scripts/build-hermes.mjs --check && python3 -m unittest discover -s hermes/tests",
44
- "version": "node scripts/sync-version.mjs && npm run build && node scripts/build-hermes.mjs && node scripts/build-cli-docs.mjs && git add -A plugin hermes .claude-plugin README.md docs",
44
+ "version": "node scripts/sync-version.mjs && npm run build && node scripts/build-hermes.mjs && node scripts/build-cli-docs.mjs && git add -A plugin hermes .claude-plugin README.md AGENTS.md docs",
45
45
  "prepublishOnly": "npm run typecheck && npm test && npm run build && npm run check:skills"
46
46
  },
47
47
  devDependencies: {
@@ -9,8 +9,8 @@ import { r as slugify } from "./ids-DAmiNwd9.mjs";
9
9
  import { n as imageInfo } from "./imageInfo-QxAfu8R6.mjs";
10
10
  import { i as validateDoc, l as didYouMean, n as defaultDoc, r as normalizeDoc, t as MAX_CANVAS } from "./validate-CXPFB-i6.mjs";
11
11
  import { i as isImageMask } from "./types-DOK7tAAu.mjs";
12
- import { a as nowIso, c as validationError, i as hasErrors, l as writeJson, o as readJson, r as OpsError, s as readJsonOr, t as AGENTPHOTO_VERSION } from "./context-DoLoLF9f.mjs";
13
- import { n as findLayer } from "./tree-DO7N0UDV.mjs";
12
+ import { a as nowIso, c as validationError, i as hasErrors, l as writeJson, o as readJson, r as OpsError, s as readJsonOr, t as AGENTPHOTO_VERSION } from "./context-CNpRboiC.mjs";
13
+ import { n as findLayer, s as referencedFiles } from "./tree-D8qZKPAb.mjs";
14
14
  // src/ops/project.ts
15
15
  var MANIFEST_FILE = "agentphoto.json";
16
16
  var DOC_FILE = "photo.json";
@@ -64,7 +64,7 @@ async function createProject(fs, opts) {
64
64
  if (opts.image) {
65
65
  const info = imageInfo(opts.image.bytes);
66
66
  if (!info) throw new OpsError("invalid", `${opts.image.name} is not a supported image (PNG, JPEG, WebP, GIF, BMP, AVIF, SVG).`);
67
- const { addAsset } = await import("./assets-CDQo3VqD.mjs").then((n) => n.n);
67
+ const { addAsset } = await import("./assets-BZVUUHjg.mjs").then((n) => n.n);
68
68
  const entry = await addAsset(fs, {
69
69
  name: opts.image.name,
70
70
  bytes: opts.image.bytes,
@@ -83,12 +83,6 @@ async function createProject(fs, opts) {
83
83
  }
84
84
  if (opts.templateFiles) {
85
85
  const tf = opts.templateFiles;
86
- for (const [path, content] of Object.entries(tf)) {
87
- if (path === "photo.json" || path === "agentphoto.json" || path === "template.json" || path === "preview.png" || path === "preview.jpg") continue;
88
- if (typeof content === "string") await fs.writeText(path, content);
89
- else await fs.writeBytes(path, content);
90
- files.push(path);
91
- }
92
86
  doc = templateDoc;
93
87
  try {
94
88
  templateSlot = tf["template.json"] ? JSON.parse(asText(tf["template.json"])).slot : void 0;
@@ -110,6 +104,14 @@ async function createProject(fs, opts) {
110
104
  delete slot.layer.crop;
111
105
  } else doc.layers.unshift(photoLayer(photo, doc.canvas));
112
106
  }
107
+ const used = new Set(referencedFiles(doc).map((f) => f.path));
108
+ for (const [path, content] of Object.entries(tf)) {
109
+ if (path === "photo.json" || path === "agentphoto.json" || path === "template.json" || path === "preview.png" || path === "preview.jpg") continue;
110
+ if (path.startsWith("assets/") && path !== "assets/manifest.json" && !used.has(path)) continue;
111
+ if (typeof content === "string") await fs.writeText(path, content);
112
+ else await fs.writeBytes(path, content);
113
+ files.push(path);
114
+ }
113
115
  } else {
114
116
  const canvas = size ?? (photo ? {
115
117
  width: photo.width,
@@ -195,4 +197,4 @@ async function touchManifest(fs) {
195
197
  agentphoto: AGENTPHOTO_VERSION
196
198
  });
197
199
  }
198
- export { saveDoc as a, loadProject as i, DOC_FILE as n, createProject as r, ASSET_MANIFEST_FILE as t };
200
+ export { loadProject as a, loadManifest as i, DOC_FILE as n, saveDoc as o, createProject as r, ASSET_MANIFEST_FILE as t };
@@ -5,8 +5,9 @@ __apRequire(import.meta.url);
5
5
  const __filename = __apPath(import.meta.url);
6
6
  __apDirname(__filename);
7
7
  import { c as closest } from "./validate-CXPFB-i6.mjs";
8
- import { r as OpsError } from "./context-DoLoLF9f.mjs";
9
- import "./project-CUykGysG.mjs";
8
+ import { r as OpsError } from "./context-CNpRboiC.mjs";
9
+ import { t as ANCHORS } from "./geometry-BKIhUO9x.mjs";
10
+ import "./project-o1DH2nOw.mjs";
10
11
  // src/ops/templates.ts
11
12
  function listTemplates(index, filter = {}) {
12
13
  const words = (filter.query ?? "").toLowerCase().split(/\s+/).filter(Boolean);
@@ -34,7 +35,27 @@ function parseTemplateInfo(json, fallbackId) {
34
35
  tags: Array.isArray(t.tags) ? t.tags.map(String) : [],
35
36
  width: typeof t.width === "number" ? t.width : 1200,
36
37
  height: typeof t.height === "number" ? t.height : 630,
37
- ...typeof t.slot === "string" ? { slot: t.slot } : {}
38
+ ...typeof t.slot === "string" ? { slot: t.slot } : {},
39
+ ...subjectArea(t.subjectArea) ? { subjectArea: subjectArea(t.subjectArea) } : {}
40
+ };
41
+ }
42
+ function subjectArea(v) {
43
+ if (!v || typeof v !== "object") return null;
44
+ const a = v;
45
+ if (![
46
+ "x",
47
+ "y",
48
+ "width",
49
+ "height"
50
+ ].every((k) => typeof a[k] === "number" && Number.isFinite(a[k]))) return null;
51
+ if (!(a.width >= 1 && a.height >= 1)) return null;
52
+ const anchor = ANCHORS.includes(a.anchor) ? a.anchor : void 0;
53
+ return {
54
+ x: a.x,
55
+ y: a.y,
56
+ width: a.width,
57
+ height: a.height,
58
+ ...anchor ? { anchor } : {}
38
59
  };
39
60
  }
40
61
  export { listTemplates as n, parseTemplateInfo as r, findTemplate as t };