@pixerate/editor 0.246.0 → 0.248.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.
Files changed (50) hide show
  1. package/dist/animation-editor/index.cjs +59 -59
  2. package/dist/animation-editor/index.js +3 -3
  3. package/dist/{brushstrokeRender-ZDHMXJAE.cjs → brushstrokeRender-DTDPFBLC.cjs} +5 -5
  4. package/dist/{brushstrokeRender-AKUI3SEJ.js → brushstrokeRender-QLCXROJK.js} +2 -2
  5. package/dist/canvas/index.cjs +8 -8
  6. package/dist/canvas/index.js +1 -1
  7. package/dist/{chunk-DQWPMGH2.js → chunk-5GLYUSNT.js} +1 -1
  8. package/dist/{chunk-Q2UYUWAZ.cjs → chunk-6G6ZDDDB.cjs} +390 -27
  9. package/dist/chunk-7T7JWTVE.cjs +192 -0
  10. package/dist/{chunk-UVPD55UZ.cjs → chunk-IBDU6EGZ.cjs} +35 -35
  11. package/dist/{chunk-FK5LTDOO.cjs → chunk-L6REDLNB.cjs} +2 -2
  12. package/dist/{chunk-LDPLEZ5T.js → chunk-NZ3O3A5C.js} +1 -1
  13. package/dist/{chunk-N6WUB3Y5.js → chunk-Q2HA52V4.js} +1 -1
  14. package/dist/chunk-SC2RZ5EF.js +192 -0
  15. package/dist/{chunk-5MFDD7SP.cjs → chunk-TPWB4Y6L.cjs} +1 -1
  16. package/dist/{chunk-VDAWA546.js → chunk-VNBUDVD4.js} +388 -25
  17. package/dist/{chunk-XTWXBQD4.cjs → chunk-WVS5KQDH.cjs} +442 -87
  18. package/dist/{chunk-A23PSOBB.js → chunk-XNRBMYNB.js} +1 -1
  19. package/dist/{chunk-CEPKXLBS.cjs → chunk-XWTRATIM.cjs} +23 -23
  20. package/dist/{chunk-4PMCMWQS.js → chunk-ZFSLEOSQ.js} +357 -2
  21. package/dist/image-editor/effect-tools.d.cts +37 -4
  22. package/dist/image-editor/effect-tools.d.ts +37 -4
  23. package/dist/image-editor/index.cjs +1059 -1552
  24. package/dist/image-editor/index.d.cts +1 -1
  25. package/dist/image-editor/index.d.ts +1 -1
  26. package/dist/image-editor/index.js +275 -768
  27. package/dist/paint-editor/controller.d.cts +34 -1
  28. package/dist/paint-editor/controller.d.ts +34 -1
  29. package/dist/paint-editor/index.cjs +426 -257
  30. package/dist/paint-editor/index.js +184 -15
  31. package/dist/paint-editor/procedural.d.cts +82 -5
  32. package/dist/paint-editor/procedural.d.ts +82 -5
  33. package/dist/paint-editor/tools.d.cts +1 -1
  34. package/dist/paint-editor/tools.d.ts +1 -1
  35. package/dist/paint-editor/ui.d.cts +15 -2
  36. package/dist/paint-editor/ui.d.ts +15 -2
  37. package/dist/{image-editor/layers/effects-ui.d.ts → raster/effects/ui.d.cts} +32 -5
  38. package/dist/{image-editor/layers/effects-ui.d.cts → raster/effects/ui.d.ts} +32 -5
  39. package/dist/raster/index.cjs +13 -1
  40. package/dist/raster/index.d.cts +1 -0
  41. package/dist/raster/index.d.ts +1 -0
  42. package/dist/raster/index.js +12 -0
  43. package/dist/vector/index.cjs +962 -962
  44. package/dist/vector/index.js +4 -4
  45. package/package.json +1 -1
  46. package/skills/pixerate-paint-editor/SKILL.md +18 -27
  47. package/skills/pixerate-paint-editor/references/gradient-paint.md +23 -0
  48. package/skills/pixerate-paint-editor/references/layer-effects.md +28 -0
  49. package/skills/pixerate-paint-editor/references/light-paint.md +10 -2
  50. package/skills/pixerate-paint-editor/references/particle-brushes.md +66 -0
@@ -18,7 +18,7 @@ import {
18
18
  unionBounds,
19
19
  vectorGradientPoints,
20
20
  widthProfileAt
21
- } from "./chunk-N6WUB3Y5.js";
21
+ } from "./chunk-Q2HA52V4.js";
22
22
  import {
23
23
  segmentLength,
24
24
  segmentParamAtLength,
@@ -5,7 +5,7 @@
5
5
 
6
6
 
7
7
 
8
- var _chunkFK5LTDOOcjs = require('./chunk-FK5LTDOO.cjs');
8
+ var _chunkL6REDLNBcjs = require('./chunk-L6REDLNB.cjs');
9
9
 
10
10
 
11
11
  var _chunkGF2RBSDMcjs = require('./chunk-GF2RBSDM.cjs');
@@ -1361,12 +1361,12 @@ var unit = (x, y) => {
1361
1361
  return l > 1e-12 && Number.isFinite(l) ? [x / l, y / l] : null;
1362
1362
  };
1363
1363
  function cubicOf(sp, i) {
1364
- const s = _chunkFK5LTDOOcjs.subpathSegment.call(void 0, sp, i);
1364
+ const s = _chunkL6REDLNBcjs.subpathSegment.call(void 0, sp, i);
1365
1365
  if (s.length === 4) return s;
1366
1366
  const [a, b] = s;
1367
1367
  return [a, [a[0] + (b[0] - a[0]) / 3, a[1] + (b[1] - a[1]) / 3], [a[0] + 2 * (b[0] - a[0]) / 3, a[1] + 2 * (b[1] - a[1]) / 3], b];
1368
1368
  }
1369
- var isLine = (sp, i) => _chunkFK5LTDOOcjs.subpathSegment.call(void 0, sp, i).length === 2;
1369
+ var isLine = (sp, i) => _chunkL6REDLNBcjs.subpathSegment.call(void 0, sp, i).length === 2;
1370
1370
  function startTangent(c) {
1371
1371
  for (let k = 1; k < 4; k++) {
1372
1372
  const u = unit(c[k][0] - c[0][0], c[k][1] - c[0][1]);
@@ -1386,10 +1386,10 @@ function sample(c, n, out, withStart) {
1386
1386
  }
1387
1387
  var onAnchor = (a, h) => !h || Math.abs(h.x - a.x) < EPS && Math.abs(h.y - a.y) < EPS;
1388
1388
  function tidy(a, keepType = true) {
1389
- const next = _chunkFK5LTDOOcjs.cloneAnchor.call(void 0, a);
1389
+ const next = _chunkL6REDLNBcjs.cloneAnchor.call(void 0, a);
1390
1390
  if (onAnchor(next, next.in)) delete next.in;
1391
1391
  if (onAnchor(next, next.out)) delete next.out;
1392
- const shown = _chunkFK5LTDOOcjs.inferAnchorType.call(void 0, next);
1392
+ const shown = _chunkL6REDLNBcjs.inferAnchorType.call(void 0, next);
1393
1393
  const type = keepType && a.type ? a.type === "symmetric" && shown !== "symmetric" ? shown === "corner" ? "corner" : "smooth" : a.type === "smooth" && shown === "corner" ? "corner" : a.type : shown;
1394
1394
  if (type === "corner") delete next.type;
1395
1395
  else next.type = type;
@@ -1433,7 +1433,7 @@ function fitAcross(pts, N, t0, t1) {
1433
1433
  return goldenMin(fit, 0, 1);
1434
1434
  }
1435
1435
  function removeAnchorKeepingShape(sp, index) {
1436
- const anchors = sp.anchors.map(_chunkFK5LTDOOcjs.cloneAnchor);
1436
+ const anchors = sp.anchors.map(_chunkL6REDLNBcjs.cloneAnchor);
1437
1437
  const n = anchors.length;
1438
1438
  if (index < 0 || index >= n) return { anchors, closed: sp.closed };
1439
1439
  if ((sp.closed || index > 0 && index < n - 1) && n >= 3) {
@@ -1467,12 +1467,12 @@ function removeAnchorKeepingShape(sp, index) {
1467
1467
  }
1468
1468
  function removeAnchorsKeepingShape(sp, indices) {
1469
1469
  const order = [...new Set(indices)].filter((i) => i >= 0 && i < sp.anchors.length).sort((a, b) => b - a);
1470
- return order.reduce((acc, i) => removeAnchorKeepingShape(acc, i), { anchors: sp.anchors.map(_chunkFK5LTDOOcjs.cloneAnchor), closed: sp.closed });
1470
+ return order.reduce((acc, i) => removeAnchorKeepingShape(acc, i), { anchors: sp.anchors.map(_chunkL6REDLNBcjs.cloneAnchor), closed: sp.closed });
1471
1471
  }
1472
1472
  function bendSegment(sp, segment, t, p) {
1473
- const anchors = sp.anchors.map(_chunkFK5LTDOOcjs.cloneAnchor);
1473
+ const anchors = sp.anchors.map(_chunkL6REDLNBcjs.cloneAnchor);
1474
1474
  const n = anchors.length;
1475
- if (segment < 0 || segment >= _chunkFK5LTDOOcjs.subpathSegmentCount.call(void 0, sp) || !Number.isFinite(t) || !Number.isFinite(p.x) || !Number.isFinite(p.y)) return { anchors, closed: sp.closed };
1475
+ if (segment < 0 || segment >= _chunkL6REDLNBcjs.subpathSegmentCount.call(void 0, sp) || !Number.isFinite(t) || !Number.isFinite(p.x) || !Number.isFinite(p.y)) return { anchors, closed: sp.closed };
1476
1476
  const tc = Math.min(0.95, Math.max(0.05, t));
1477
1477
  const ia = segment;
1478
1478
  const ib = (segment + 1) % n;
@@ -1483,16 +1483,16 @@ function bendSegment(sp, segment, t, p) {
1483
1483
  const oy = (p.y - (a.y + (b.y - a.y) * tc)) / k;
1484
1484
  const c1 = { x: a.x + (b.x - a.x) / 3 + ox, y: a.y + (b.y - a.y) / 3 + oy };
1485
1485
  const c2 = { x: b.x + (a.x - b.x) / 3 + ox, y: b.y + (a.y - b.y) / 3 + oy };
1486
- anchors[ia] = _chunkFK5LTDOOcjs.moveAnchorHandle.call(void 0, a, "out", c1);
1487
- anchors[ib] = _chunkFK5LTDOOcjs.moveAnchorHandle.call(void 0, b, "in", c2);
1486
+ anchors[ia] = _chunkL6REDLNBcjs.moveAnchorHandle.call(void 0, a, "out", c1);
1487
+ anchors[ib] = _chunkL6REDLNBcjs.moveAnchorHandle.call(void 0, b, "in", c2);
1488
1488
  return { anchors, closed: sp.closed };
1489
1489
  }
1490
1490
  function subpathPointAt(sp, segment, t) {
1491
- const [x, y] = _chunkGF2RBSDMcjs.segmentPoint.call(void 0, _chunkFK5LTDOOcjs.subpathSegment.call(void 0, sp, segment), t);
1491
+ const [x, y] = _chunkGF2RBSDMcjs.segmentPoint.call(void 0, _chunkL6REDLNBcjs.subpathSegment.call(void 0, sp, segment), t);
1492
1492
  return { x, y };
1493
1493
  }
1494
1494
  function curvatureMoveAnchor(sp, index, q) {
1495
- const anchors = sp.anchors.map(_chunkFK5LTDOOcjs.cloneAnchor);
1495
+ const anchors = sp.anchors.map(_chunkL6REDLNBcjs.cloneAnchor);
1496
1496
  const a = sp.anchors[index];
1497
1497
  if (!a) return { anchors, closed: sp.closed };
1498
1498
  const own = [
@@ -1538,7 +1538,7 @@ function curvatureMoveAnchor(sp, index, q) {
1538
1538
  function cutSubpathAt(sp, at) {
1539
1539
  const n = sp.anchors.length;
1540
1540
  const cuts = [...new Set(at)].filter((i) => Number.isInteger(i) && i >= 0 && i < n && (sp.closed || i > 0 && i < n - 1)).sort((a, b) => a - b);
1541
- if (!cuts.length || n < 2) return [{ anchors: sp.anchors.map(_chunkFK5LTDOOcjs.cloneAnchor), closed: sp.closed }];
1541
+ if (!cuts.length || n < 2) return [{ anchors: sp.anchors.map(_chunkL6REDLNBcjs.cloneAnchor), closed: sp.closed }];
1542
1542
  const first = cuts[0];
1543
1543
  const run = sp.closed ? Array.from({ length: n + 1 }, (_, i) => sp.anchors[(first + i) % n]) : sp.anchors;
1544
1544
  const cutSet = new Set(sp.closed ? [...cuts.map((c) => (c - first + n) % n), n] : cuts);
@@ -1546,7 +1546,7 @@ function cutSubpathAt(sp, at) {
1546
1546
  let cur = [];
1547
1547
  run.forEach((a, i) => {
1548
1548
  if (!cutSet.has(i)) {
1549
- cur.push(_chunkFK5LTDOOcjs.cloneAnchor.call(void 0, a));
1549
+ cur.push(_chunkL6REDLNBcjs.cloneAnchor.call(void 0, a));
1550
1550
  return;
1551
1551
  }
1552
1552
  if (cur.length) {
@@ -1561,10 +1561,10 @@ function cutSubpathAt(sp, at) {
1561
1561
  }
1562
1562
  function splitSubpathAt(sp, segment, t, endTolerance = 1e-6) {
1563
1563
  const n = sp.anchors.length;
1564
- if (segment < 0 || segment >= _chunkFK5LTDOOcjs.subpathSegmentCount.call(void 0, sp)) return [{ anchors: sp.anchors.map(_chunkFK5LTDOOcjs.cloneAnchor), closed: sp.closed }];
1564
+ if (segment < 0 || segment >= _chunkL6REDLNBcjs.subpathSegmentCount.call(void 0, sp)) return [{ anchors: sp.anchors.map(_chunkL6REDLNBcjs.cloneAnchor), closed: sp.closed }];
1565
1565
  if (t <= endTolerance) return cutSubpathAt(sp, [segment]);
1566
1566
  if (t >= 1 - endTolerance) return cutSubpathAt(sp, [(segment + 1) % n]);
1567
- const { subpath, index } = _chunkFK5LTDOOcjs.insertAnchor.call(void 0, sp, segment, t);
1567
+ const { subpath, index } = _chunkL6REDLNBcjs.insertAnchor.call(void 0, sp, segment, t);
1568
1568
  return cutSubpathAt(subpath, [index]);
1569
1569
  }
1570
1570
  var endOf = (sp, last) => sp.anchors[last ? sp.anchors.length - 1 : 0];
@@ -1587,7 +1587,7 @@ function joinSubpaths(subpaths, tolerance) {
1587
1587
  const closed = [];
1588
1588
  let open = [];
1589
1589
  for (const sp of subpaths) {
1590
- const copy = { anchors: sp.anchors.map(_chunkFK5LTDOOcjs.cloneAnchor), closed: sp.closed };
1590
+ const copy = { anchors: sp.anchors.map(_chunkL6REDLNBcjs.cloneAnchor), closed: sp.closed };
1591
1591
  if (sp.closed || sp.anchors.length < 2) {
1592
1592
  if (sp.anchors.length) closed.push(copy);
1593
1593
  } else open.push(copy);
@@ -1642,7 +1642,7 @@ function smoothSubpath(sp, amount = 1, only) {
1642
1642
  const t = Math.min(1, Math.max(0, amount));
1643
1643
  const orig = sp.anchors;
1644
1644
  const n = orig.length;
1645
- const anchors = orig.map(_chunkFK5LTDOOcjs.cloneAnchor);
1645
+ const anchors = orig.map(_chunkL6REDLNBcjs.cloneAnchor);
1646
1646
  if (n < 3 || t === 0) return { anchors, closed: sp.closed };
1647
1647
  for (let i = 0; i < n; i++) {
1648
1648
  if (!sp.closed && (i === 0 || i === n - 1)) continue;
@@ -1671,8 +1671,8 @@ function smoothSubpath(sp, amount = 1, only) {
1671
1671
  }
1672
1672
  function segsOf(sp) {
1673
1673
  const out = [];
1674
- for (let i = 0; i < _chunkFK5LTDOOcjs.subpathSegmentCount.call(void 0, sp); i++) {
1675
- const s = _chunkFK5LTDOOcjs.subpathSegment.call(void 0, sp, i);
1674
+ for (let i = 0; i < _chunkL6REDLNBcjs.subpathSegmentCount.call(void 0, sp); i++) {
1675
+ const s = _chunkL6REDLNBcjs.subpathSegment.call(void 0, sp, i);
1676
1676
  out.push(s.length === 2 ? { c: s, line: true } : { c: s, line: false });
1677
1677
  }
1678
1678
  return out;
@@ -1729,7 +1729,7 @@ function removeRedundantPoints(sp, tolerance) {
1729
1729
  const tol = Math.max(tolerance, 1e-9);
1730
1730
  const types = new Map(sp.anchors.filter((a) => a.type).map((a) => [`${a.x},${a.y}`, a.type]));
1731
1731
  const segs = segsOf(sp).filter((s) => !isZeroSeg(s));
1732
- if (!segs.length) return { anchors: sp.anchors.map(_chunkFK5LTDOOcjs.cloneAnchor), closed: sp.closed };
1732
+ if (!segs.length) return { anchors: sp.anchors.map(_chunkL6REDLNBcjs.cloneAnchor), closed: sp.closed };
1733
1733
  const minSegs = sp.closed ? 2 : 1;
1734
1734
  let changed = true;
1735
1735
  while (changed && segs.length > minSegs) {
@@ -1747,7 +1747,7 @@ function removeRedundantPoints(sp, tolerance) {
1747
1747
  break;
1748
1748
  }
1749
1749
  }
1750
- return _nullishCoalesce(segsToSubpath(segs, sp.closed, types), () => ( { anchors: sp.anchors.map(_chunkFK5LTDOOcjs.cloneAnchor), closed: sp.closed }));
1750
+ return _nullishCoalesce(segsToSubpath(segs, sp.closed, types), () => ( { anchors: sp.anchors.map(_chunkL6REDLNBcjs.cloneAnchor), closed: sp.closed }));
1751
1751
  }
1752
1752
 
1753
1753
 
@@ -22,6 +22,7 @@ import {
22
22
  TransformTooLargeError,
23
23
  blendTile,
24
24
  builtinPattern,
25
+ builtinPatternIds,
25
26
  curveLut,
26
27
  defaultLayerEffect,
27
28
  effectColorHex,
@@ -35,6 +36,7 @@ import {
35
36
  isInterpolation,
36
37
  isLayerEffectKind,
37
38
  isLayerLocked,
39
+ layerEffectLabel,
38
40
  mapLayer,
39
41
  mergeLayerEffect,
40
42
  newEffectId,
@@ -104,7 +106,7 @@ import {
104
106
  transformTextRect,
105
107
  translateMatrix,
106
108
  warpPresetMesh
107
- } from "./chunk-N6WUB3Y5.js";
109
+ } from "./chunk-Q2HA52V4.js";
108
110
  import {
109
111
  bezierPathBounds,
110
112
  outlineStroke,
@@ -114,6 +116,7 @@ import {
114
116
  transformBezierPath
115
117
  } from "./chunk-WEIK3UYB.js";
116
118
  import {
119
+ BLEND_MODES,
117
120
  base64ToBytes,
118
121
  blendRgb,
119
122
  bytesToBase64,
@@ -11723,6 +11726,355 @@ function exportPsd(input) {
11723
11726
  return { bytes, psb, records: records.length, warnings };
11724
11727
  }
11725
11728
 
11729
+ // src/image-editor/effect-tools.ts
11730
+ var READ = { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false };
11731
+ var WRITE = { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: false };
11732
+ var WRITE_IDEMPOTENT = { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: false };
11733
+ var DESTRUCTIVE = { readOnlyHint: false, destructiveHint: true, idempotentHint: false, openWorldHint: false };
11734
+ var EFFECT_ID = { type: "string", description: "Effect id from list_layer_effects or add_layer_effect." };
11735
+ var BLEND_IDS = BLEND_MODES.map((m) => m.id).filter((id) => id !== "pigment");
11736
+ var DEFS = {
11737
+ color: { type: "string", pattern: "^#?([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$", description: "Colour as #rrggbb." },
11738
+ contour: {
11739
+ type: "object",
11740
+ description: "A transfer curve over the effect coverage: points { input, output } from 0 to 1 (at least 2), sorted by input. Linear is [{0,0},{1,1}].",
11741
+ properties: {
11742
+ name: { type: "string", description: 'Display name (e.g. "Cone", "Gaussian").' },
11743
+ points: {
11744
+ type: "array",
11745
+ minItems: 2,
11746
+ description: "Curve points.",
11747
+ items: {
11748
+ type: "object",
11749
+ properties: {
11750
+ input: { type: "number", minimum: 0, maximum: 1, description: "Coverage in (0..1)." },
11751
+ output: { type: "number", minimum: 0, maximum: 1, description: "Coverage out (0..1)." },
11752
+ corner: { type: "boolean", description: "Sharp corner instead of a smooth point (default false)." }
11753
+ },
11754
+ required: ["input", "output"],
11755
+ additionalProperties: false
11756
+ }
11757
+ }
11758
+ },
11759
+ required: ["name", "points"],
11760
+ additionalProperties: false
11761
+ },
11762
+ gradient: {
11763
+ type: "object",
11764
+ description: "A gradient: colour stops, optional opacity stops and its layout.",
11765
+ properties: {
11766
+ stops: {
11767
+ type: "array",
11768
+ minItems: 1,
11769
+ description: "Colour stops { position 0..1, color #rrggbb }.",
11770
+ items: {
11771
+ type: "object",
11772
+ properties: { position: { type: "number", minimum: 0, maximum: 1, description: "0..1 along the gradient." }, color: { $ref: "#/$defs/color" } },
11773
+ required: ["position", "color"],
11774
+ additionalProperties: false
11775
+ }
11776
+ },
11777
+ opacityStops: {
11778
+ type: "array",
11779
+ description: "Opacity stops { position 0..1, opacity 0..1 } (default opaque).",
11780
+ items: {
11781
+ type: "object",
11782
+ properties: {
11783
+ position: { type: "number", minimum: 0, maximum: 1, description: "0..1 along the gradient." },
11784
+ opacity: { type: "number", minimum: 0, maximum: 1, description: "0..1." }
11785
+ },
11786
+ required: ["position", "opacity"],
11787
+ additionalProperties: false
11788
+ }
11789
+ },
11790
+ style: { type: "string", enum: ["linear", "radial", "angle", "reflected", "diamond"], description: "Geometry." },
11791
+ angle: { type: "number", minimum: -360, maximum: 360, description: "Degrees, 90 = bottom to top." },
11792
+ scale: { type: "number", minimum: 0.1, maximum: 1.5, description: "1 = 100 %." },
11793
+ reverse: { type: "boolean", description: "Swap the ends." },
11794
+ align: { type: "boolean", description: "Lay out over the layer bounds (true) or the canvas." },
11795
+ offset: {
11796
+ type: "object",
11797
+ description: "Centre offset as fractions of the bounds.",
11798
+ properties: { x: { type: "number", minimum: -1, maximum: 1, description: "Fraction of the width." }, y: { type: "number", minimum: -1, maximum: 1, description: "Fraction of the height." } },
11799
+ required: ["x", "y"],
11800
+ additionalProperties: false
11801
+ }
11802
+ },
11803
+ required: ["stops", "style", "angle", "scale", "reverse", "align", "offset"],
11804
+ additionalProperties: false
11805
+ },
11806
+ phase: {
11807
+ type: "object",
11808
+ description: "Pattern origin offset in px.",
11809
+ properties: { x: { type: "number", description: "px." }, y: { type: "number", description: "px." } },
11810
+ required: ["x", "y"],
11811
+ additionalProperties: false
11812
+ },
11813
+ fill: {
11814
+ description: "What a stroke or glow paints with. Glows take color or gradient only.",
11815
+ anyOf: [
11816
+ {
11817
+ type: "object",
11818
+ properties: { type: { const: "color", description: "Solid colour." }, color: { $ref: "#/$defs/color" } },
11819
+ required: ["type", "color"],
11820
+ additionalProperties: false
11821
+ },
11822
+ {
11823
+ type: "object",
11824
+ properties: { type: { const: "gradient", description: "Gradient." }, gradient: { $ref: "#/$defs/gradient" } },
11825
+ required: ["type", "gradient"],
11826
+ additionalProperties: false
11827
+ },
11828
+ {
11829
+ type: "object",
11830
+ properties: {
11831
+ type: { const: "pattern", description: "Pattern (strokes only)." },
11832
+ patternId: { type: "string", description: "Pattern id from list_layer_effects.patterns." },
11833
+ name: { type: "string", description: "Display name." },
11834
+ scale: { type: "number", minimum: 0.01, maximum: 10, description: "1 = 100 %." },
11835
+ angle: { type: "number", minimum: -360, maximum: 360, description: "Rotation in degrees (default 0)." },
11836
+ link: { type: "boolean", description: "Tile from the layer (default true) or the canvas origin." },
11837
+ phase: { $ref: "#/$defs/phase" }
11838
+ },
11839
+ required: ["type", "patternId", "scale"],
11840
+ additionalProperties: false
11841
+ }
11842
+ ]
11843
+ }
11844
+ };
11845
+ var nullable = (schema, description) => ({ anyOf: [schema, { type: "null" }], description });
11846
+ function settingsSchema(forUpdate) {
11847
+ const opt = (schema, description) => forUpdate ? nullable(schema, `${description} null removes it.`) : { ...schema, description };
11848
+ return {
11849
+ type: "object",
11850
+ description: forUpdate ? "Settings to change (only these; nested objects are replaced whole). Which settings a kind takes: see add_layer_effect." : "Settings to change from Photoshop's defaults (all optional). Unknown settings for the kind are refused with the list of its settings.",
11851
+ properties: {
11852
+ enabled: { type: "boolean", description: "All kinds: false keeps the effect but hides it (default true)." },
11853
+ blend: { type: "string", enum: BLEND_IDS, description: "All but bevel-emboss: blend mode (shadows multiply, glows screen, others normal)." },
11854
+ opacity: { type: "number", minimum: 0, maximum: 1, description: "All but bevel-emboss: 0..1 (shadows / glows 0.75, satin 0.5, others 1)." },
11855
+ color: { $ref: "#/$defs/color", description: "drop-shadow, inner-shadow, satin, color-overlay: #rrggbb." },
11856
+ angle: { type: "number", minimum: -360, maximum: 360, description: "Shadows, satin, bevel-emboss: light direction in degrees, counter-clockwise from 3 o'clock (default 120; satin 19)." },
11857
+ useGlobalLight: { type: "boolean", description: "Shadows, bevel-emboss: follow the document global light instead of angle (default true)." },
11858
+ distance: { type: "number", minimum: 0, maximum: 3e4, description: "Shadows, satin: offset in px (default 5; satin 11)." },
11859
+ spread: { type: "number", minimum: 0, maximum: 1, description: "drop-shadow, outer-glow: 0..1 of the size made solid (default 0)." },
11860
+ choke: { type: "number", minimum: 0, maximum: 1, description: "inner-shadow, inner-glow: 0..1 of the size made solid (default 0)." },
11861
+ size: { type: "number", minimum: 0, maximum: 250, description: "Shadows, glows, satin, bevel-emboss: blur / size in px (default 5; satin 14); stroke: width in px (default 3)." },
11862
+ contour: opt({ $ref: "#/$defs/contour" }, "Shadows, glows, satin: coverage contour (default linear)."),
11863
+ antiAlias: { type: "boolean", description: "Shadows, glows, satin: smooth the contour (default false; satin true)." },
11864
+ noise: { type: "number", minimum: 0, maximum: 1, description: "Shadows, glows: speckle 0..1 (default 0)." },
11865
+ knocksOut: { type: "boolean", description: "drop-shadow: the layer hides the shadow beneath its see-through fill (default true)." },
11866
+ fill: { $ref: "#/$defs/fill", description: "outer-glow, inner-glow (color or gradient), stroke (color, gradient or pattern)." },
11867
+ technique: { type: "string", enum: ["softer", "precise", "smooth", "chisel-hard", "chisel-soft"], description: "Glows: softer | precise (default softer); bevel-emboss: smooth | chisel-hard | chisel-soft (default smooth)." },
11868
+ range: { type: "number", minimum: 0.01, maximum: 1, description: "Glows: the part of the glow the contour spans (default 0.5)." },
11869
+ jitter: { type: "number", minimum: 0, maximum: 1, description: "Glows: gradient jitter 0..1 (stored, not rendered; default 0)." },
11870
+ source: { type: "string", enum: ["edge", "center"], description: "inner-glow: glow from the edge (default) or the centre." },
11871
+ style: { type: "string", enum: ["inner-bevel", "outer-bevel", "emboss", "pillow-emboss", "stroke-emboss"], description: "bevel-emboss: style (default inner-bevel)." },
11872
+ depth: { type: "number", minimum: 0, maximum: 10, description: "bevel-emboss: depth, 1 = 100 % (default 1)." },
11873
+ direction: { type: "string", enum: ["up", "down"], description: "bevel-emboss: raised (up, default) or sunk (down)." },
11874
+ soften: { type: "number", minimum: 0, maximum: 16, description: "bevel-emboss: blur of the height in px (default 0)." },
11875
+ altitude: { type: "number", minimum: 0, maximum: 90, description: "bevel-emboss: light altitude in degrees (default 30)." },
11876
+ glossContour: opt({ $ref: "#/$defs/contour" }, "bevel-emboss: gloss contour over the shading (default linear)."),
11877
+ highlightColor: { $ref: "#/$defs/color", description: "bevel-emboss: highlight colour (default #ffffff)." },
11878
+ highlightBlend: { type: "string", enum: BLEND_IDS, description: "bevel-emboss: highlight mode (default screen)." },
11879
+ highlightOpacity: { type: "number", minimum: 0, maximum: 1, description: "bevel-emboss: highlight opacity (default 0.75)." },
11880
+ shadowColor: { $ref: "#/$defs/color", description: "bevel-emboss: shadow colour (default #000000)." },
11881
+ shadowBlend: { type: "string", enum: BLEND_IDS, description: "bevel-emboss: shadow mode (default multiply)." },
11882
+ shadowOpacity: { type: "number", minimum: 0, maximum: 1, description: "bevel-emboss: shadow opacity (default 0.75)." },
11883
+ contourElement: opt(
11884
+ {
11885
+ type: "object",
11886
+ properties: {
11887
+ contour: { $ref: "#/$defs/contour" },
11888
+ range: { type: "number", minimum: 0, maximum: 1, description: "Stored range (default 0.5)." },
11889
+ antiAlias: { type: "boolean", description: "Smooth the contour." }
11890
+ },
11891
+ required: ["contour", "range", "antiAlias"],
11892
+ additionalProperties: false
11893
+ },
11894
+ "bevel-emboss: the Contour element, shaping the bevel's height profile (default off)."
11895
+ ),
11896
+ texture: opt(
11897
+ {
11898
+ type: "object",
11899
+ properties: {
11900
+ patternId: { type: "string", description: "Pattern id from list_layer_effects.patterns." },
11901
+ name: { type: "string", description: "Display name." },
11902
+ scale: { type: "number", minimum: 0.01, maximum: 10, description: "1 = 100 %." },
11903
+ depth: { type: "number", minimum: -10, maximum: 10, description: "1 = +100 %; negative carves the pattern in." },
11904
+ invert: { type: "boolean", description: "Invert the pattern." },
11905
+ link: { type: "boolean", description: "Tile from the layer (default true)." },
11906
+ phase: { $ref: "#/$defs/phase" }
11907
+ },
11908
+ required: ["patternId", "scale", "depth", "invert"],
11909
+ additionalProperties: false
11910
+ },
11911
+ "bevel-emboss: the Texture element, a pattern's luminance as extra height (default off)."
11912
+ ),
11913
+ invert: { type: "boolean", description: "satin: invert (default true)." },
11914
+ gradient: { $ref: "#/$defs/gradient", description: "gradient-overlay: the gradient (default black to white, 90\xB0)." },
11915
+ dither: { type: "boolean", description: "gradient-overlay: dither (stored; default false)." },
11916
+ patternId: { type: "string", description: "pattern-overlay: pattern id from list_layer_effects.patterns (default checker)." },
11917
+ name: { type: "string", description: "pattern-overlay: pattern display name." },
11918
+ scale: { type: "number", minimum: 0.01, maximum: 10, description: "pattern-overlay: 1 = 100 % (default 1)." },
11919
+ link: { type: "boolean", description: "pattern-overlay: tile from the layer (default true) or the canvas origin." },
11920
+ phase: { $ref: "#/$defs/phase", description: "pattern-overlay: origin offset in px (default 0, 0)." },
11921
+ position: { type: "string", enum: ["outside", "inside", "center"], description: "stroke: where the stroke sits on the edge (default outside)." }
11922
+ },
11923
+ additionalProperties: false
11924
+ };
11925
+ }
11926
+ function patternList(documentPatterns) {
11927
+ const doc = documentPatterns.map((p) => ({ id: p.id, name: p.name, width: p.width, height: p.height, builtin: false }));
11928
+ const builtins = builtinPatternIds().map((id) => {
11929
+ const p = builtinPattern(id);
11930
+ return { id, name: p.name, width: p.width, height: p.height, builtin: true };
11931
+ });
11932
+ return [...doc, ...builtins];
11933
+ }
11934
+ function describeLayerEffects(effects) {
11935
+ return {
11936
+ enabled: effects.enabled,
11937
+ scale: effects.scale ?? 1,
11938
+ margin: effectsMargin(effects),
11939
+ fromPsd: Boolean(effects.psd),
11940
+ effects: effects.items.map((e) => ({ ...JSON.parse(JSON.stringify(e)), label: layerEffectLabel(e.kind) }))
11941
+ };
11942
+ }
11943
+ function createImageEffectTools(controller) {
11944
+ return createLayerEffectTools(
11945
+ {
11946
+ requireLayer: (id) => void requireLayer(controller.getLayers(), id),
11947
+ getLayerEffects: (id) => controller.getLayerEffects(id),
11948
+ addLayerEffect: (id, kind, settings, index) => controller.addLayerEffect(id, kind, settings, index),
11949
+ updateLayerEffect: (id, effectId, changes) => controller.updateLayerEffect(id, effectId, changes),
11950
+ removeLayerEffect: (id, effectId) => controller.removeLayerEffect(id, effectId),
11951
+ setLayerEffectsEnabled: (id, enabled, scale) => controller.setLayerEffectsEnabled(id, enabled, scale),
11952
+ getGlobalLight: () => controller.getGlobalLight(),
11953
+ setGlobalLight: (light) => controller.setGlobalLight(light),
11954
+ getDocumentPatterns: () => controller.getDocumentPatterns()
11955
+ },
11956
+ { layers: "a pixel, shape, type, smart object, annotation or group layer" }
11957
+ );
11958
+ }
11959
+ function createLayerEffectTools(host, options) {
11960
+ const error = options.error ?? ((m) => new LayerOperationError(m));
11961
+ const LAYER_ID = { type: "string", description: `Layer id from list_layers (${options.layers}).` };
11962
+ const layerArg = (id) => {
11963
+ if (typeof id !== "string" || !id) throw error("layerId is required (a layer id from list_layers).");
11964
+ host.requireLayer(id);
11965
+ return id;
11966
+ };
11967
+ const result = (layerId, extra = {}) => ({ layerId, ...extra, ...describeLayerEffects(host.getLayerEffects(layerId)) });
11968
+ const globalLight = () => host.getGlobalLight?.() ?? { ...DEFAULT_GLOBAL_LIGHT };
11969
+ const list2 = {
11970
+ name: "list_layer_effects",
11971
+ title: "List layer effects",
11972
+ description: "Returns a layer's effects: the master switch (enabled), Scale Effects (scale, 1 = 100 %), margin (px the effects reach beyond the shape), whether they came from a PSD, and every effect with its id, kind, label and all settings. Also returns the document global light and the pattern ids pattern effects can use.",
11973
+ inputSchema: { type: "object", properties: { layerId: LAYER_ID }, required: ["layerId"], additionalProperties: false },
11974
+ annotations: { title: "List layer effects", ...READ },
11975
+ handler: ({ layerId }) => result(layerArg(layerId), { globalLight: globalLight(), patterns: patternList(host.getDocumentPatterns?.() ?? []), kinds: [...LAYER_EFFECT_KINDS] })
11976
+ };
11977
+ const add = {
11978
+ name: "add_layer_effect",
11979
+ title: "Add a layer effect",
11980
+ description: `Adds a live effect to ${options.layers} with Photoshop's defaults, changed by settings: drop-shadow, inner-shadow, outer-glow, inner-glow, bevel-emboss, satin, color-overlay, gradient-overlay, pattern-overlay or stroke. Several of one kind are allowed (the first listed is on top). The effect is drawn from the layer's pixels, so it follows later changes. One undo step. Returns the new effect's id and the layer's effects.`,
11981
+ inputSchema: {
11982
+ type: "object",
11983
+ $defs: DEFS,
11984
+ properties: {
11985
+ layerId: LAYER_ID,
11986
+ kind: { type: "string", enum: [...LAYER_EFFECT_KINDS], description: "Effect kind." },
11987
+ settings: settingsSchema(false),
11988
+ index: { type: "integer", minimum: 0, description: "Position in the layer's effect list (default the end)." }
11989
+ },
11990
+ required: ["layerId", "kind"],
11991
+ additionalProperties: false
11992
+ },
11993
+ annotations: { title: "Add a layer effect", ...WRITE },
11994
+ handler: ({ layerId, kind, settings, index }) => {
11995
+ const id = layerArg(layerId);
11996
+ if (!isLayerEffectKind(kind)) throw error(`kind must be one of ${LAYER_EFFECT_KINDS.join(", ")}.`);
11997
+ const { effect } = host.addLayerEffect(id, kind, settings ?? {}, index);
11998
+ return result(id, { effectId: effect.id });
11999
+ }
12000
+ };
12001
+ const update = {
12002
+ name: "update_layer_effect",
12003
+ title: "Change a layer effect",
12004
+ description: "Changes settings of one effect (only the given ones; fill, gradient, contour and texture objects are replaced whole, null removes an optional contour or texture). The kind cannot change. Validates everything before changing anything. One undo step. Returns the layer's effects.",
12005
+ inputSchema: {
12006
+ type: "object",
12007
+ $defs: DEFS,
12008
+ properties: { layerId: LAYER_ID, effectId: EFFECT_ID, settings: settingsSchema(true) },
12009
+ required: ["layerId", "effectId", "settings"],
12010
+ additionalProperties: false
12011
+ },
12012
+ annotations: { title: "Change a layer effect", ...WRITE_IDEMPOTENT },
12013
+ handler: ({ layerId, effectId, settings }) => {
12014
+ const id = layerArg(layerId);
12015
+ const changes = settings ?? {};
12016
+ if (!Object.keys(changes).length) throw error("Give at least one setting to change.");
12017
+ host.updateLayerEffect(id, effectId, changes);
12018
+ return result(id);
12019
+ }
12020
+ };
12021
+ const remove = {
12022
+ name: "remove_layer_effect",
12023
+ title: "Remove a layer effect",
12024
+ description: "Removes one effect from a layer (to hide it but keep its settings, set enabled false with update_layer_effect instead). One undo step. Returns the layer's remaining effects.",
12025
+ inputSchema: { type: "object", properties: { layerId: LAYER_ID, effectId: EFFECT_ID }, required: ["layerId", "effectId"], additionalProperties: false },
12026
+ annotations: { title: "Remove a layer effect", ...DESTRUCTIVE },
12027
+ handler: ({ layerId, effectId }) => {
12028
+ const id = layerArg(layerId);
12029
+ host.removeLayerEffect(id, effectId);
12030
+ return result(id);
12031
+ }
12032
+ };
12033
+ const setEnabled = {
12034
+ name: "set_layer_effects_enabled",
12035
+ title: "Switch layer effects on or off",
12036
+ description: "Turns all of a layer's effects on or off at once (the master switch; each effect keeps its own enabled flag) and optionally sets Scale Effects, which multiplies every size, distance and pattern scale. One undo step. Returns the layer's effects.",
12037
+ inputSchema: {
12038
+ type: "object",
12039
+ properties: {
12040
+ layerId: LAYER_ID,
12041
+ enabled: { type: "boolean", description: "true renders the enabled effects; false hides them all." },
12042
+ scale: { type: "number", minimum: 0.01, maximum: 10, description: "Scale Effects, 1 = 100 % (unchanged when left out)." }
12043
+ },
12044
+ required: ["layerId", "enabled"],
12045
+ additionalProperties: false
12046
+ },
12047
+ annotations: { title: "Switch layer effects on or off", ...WRITE_IDEMPOTENT },
12048
+ handler: ({ layerId, enabled, scale }) => {
12049
+ const id = layerArg(layerId);
12050
+ host.setLayerEffectsEnabled(id, enabled, scale);
12051
+ return result(id);
12052
+ }
12053
+ };
12054
+ const light = {
12055
+ name: "set_global_light",
12056
+ title: "Set the global light",
12057
+ description: "Sets the document global light that shadows and bevels with useGlobalLight follow (Photoshop default: angle 120\xB0, altitude 30\xB0). One undo step. Returns the light.",
12058
+ inputSchema: {
12059
+ type: "object",
12060
+ properties: {
12061
+ angle: { type: "number", minimum: -360, maximum: 360, description: "Degrees, counter-clockwise from 3 o'clock: where the light comes from (unchanged when left out)." },
12062
+ altitude: { type: "number", minimum: 0, maximum: 90, description: "Degrees above the canvas, for bevels (unchanged when left out)." }
12063
+ },
12064
+ additionalProperties: false
12065
+ },
12066
+ annotations: { title: "Set the global light", ...WRITE_IDEMPOTENT },
12067
+ handler: ({ angle, altitude }) => {
12068
+ if (angle === void 0 && altitude === void 0) throw error("Give angle, altitude or both.");
12069
+ const next = {};
12070
+ if (angle !== void 0) next.angle = angle;
12071
+ if (altitude !== void 0) next.altitude = altitude;
12072
+ return { globalLight: host.setGlobalLight(next) };
12073
+ }
12074
+ };
12075
+ return host.setGlobalLight ? [list2, add, update, remove, setEnabled, light] : [list2, add, update, remove, setEnabled];
12076
+ }
12077
+
11726
12078
  export {
11727
12079
  LEGACY_PROCESS_VERSION,
11728
12080
  LATEST_PROCESS_VERSION,
@@ -12084,5 +12436,8 @@ export {
12084
12436
  psdToLayers,
12085
12437
  importPsd,
12086
12438
  smartContentsFile,
12087
- exportPsd
12439
+ exportPsd,
12440
+ describeLayerEffects,
12441
+ createImageEffectTools,
12442
+ createLayerEffectTools
12088
12443
  };
@@ -1,11 +1,44 @@
1
1
  import type { AgentTool } from '../tools/registry.cjs';
2
2
  import type { ImageEditorController } from './controller.cjs';
3
- import { type LayerEffects } from '../raster/effects/model.cjs';
3
+ import { type LayerEffectKind, type GlobalLight, type LayerEffects } from '../raster/effects/model.cjs';
4
+ import { type EffectPattern } from '../raster/effects/patterns.cjs';
4
5
  /** A layer's effects for agents: the master switch, scale, reach and every effect with its settings. */
5
6
  export declare function describeLayerEffects(effects: LayerEffects): Record<string, unknown>;
6
7
  /**
7
- * Agent tools for layer effects: `list_layer_effects`, `add_layer_effect`, `update_layer_effect`,
8
- * `remove_layer_effect`, `set_layer_effects_enabled` and `set_global_light`. Each write validates
9
- * every setting first, is one undo step and returns the layer's effects after the change.
8
+ * What the layer effect tools need of an editor. The image and paint editors both provide it, so
9
+ * both get the same tools, schemas and defaults (`../raster/effects/model`).
10
10
  */
11
+ export interface LayerEffectsHost {
12
+ /** Throws a helpful error when `id` is not a layer that can take effects. */
13
+ requireLayer(id: string): void;
14
+ getLayerEffects(id: string): LayerEffects;
15
+ addLayerEffect(id: string, kind: LayerEffectKind, settings: Record<string, unknown>, index?: number): {
16
+ effect: {
17
+ id: string;
18
+ };
19
+ };
20
+ updateLayerEffect(id: string, effectId: string, changes: Record<string, unknown>): unknown;
21
+ removeLayerEffect(id: string, effectId: string): unknown;
22
+ setLayerEffectsEnabled(id: string, enabled: boolean, scale?: number): unknown;
23
+ /** The light shadows and bevels with useGlobalLight follow; without it, the default 120° / 30°. */
24
+ getGlobalLight?(): GlobalLight;
25
+ /** With it, the `set_global_light` tool is offered. */
26
+ setGlobalLight?(light: Partial<GlobalLight>): GlobalLight;
27
+ /** Document patterns beside the built-in ones (from a PSD). */
28
+ getDocumentPatterns?(): readonly EffectPattern[];
29
+ }
30
+ export interface LayerEffectToolsOptions {
31
+ /** What a layerId may name, for its description (e.g. "a pixel, shape, smart object, annotation or group layer"). */
32
+ layers: string;
33
+ /** Turns a refusal into the host's error type (default LayerOperationError). */
34
+ error?: (message: string) => Error;
35
+ }
36
+ /** The image editor's layer effect tools (see `createLayerEffectTools`). */
11
37
  export declare function createImageEffectTools(controller: ImageEditorController): AgentTool[];
38
+ /**
39
+ * Agent tools for layer effects: `list_layer_effects`, `add_layer_effect`, `update_layer_effect`,
40
+ * `remove_layer_effect`, `set_layer_effects_enabled` and, when the host has a global light to set,
41
+ * `set_global_light`. Each write validates every setting first, is one undo step and returns the
42
+ * layer's effects after the change.
43
+ */
44
+ export declare function createLayerEffectTools(host: LayerEffectsHost, options: LayerEffectToolsOptions): AgentTool[];