@pixerate/editor 0.254.1 → 0.255.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 (71) hide show
  1. package/dist/agent/index.cjs +2 -2
  2. package/dist/agent/index.js +1 -1
  3. package/dist/animation-editor/index.cjs +59 -59
  4. package/dist/animation-editor/index.js +3 -3
  5. package/dist/brushes/index.cjs +31 -29
  6. package/dist/brushes/index.d.cts +1 -1
  7. package/dist/brushes/index.d.ts +1 -1
  8. package/dist/brushes/index.js +27 -25
  9. package/dist/brushes/library.d.cts +17 -0
  10. package/dist/brushes/library.d.ts +17 -0
  11. package/dist/{brushstrokeRender-5PYSKZIJ.js → brushstrokeRender-HCOQUSWW.js} +53 -18
  12. package/dist/{brushstrokeRender-7FLLSQEC.cjs → brushstrokeRender-ZZOXI5O5.cjs} +55 -20
  13. package/dist/canvas/brushTypes.d.cts +22 -3
  14. package/dist/canvas/brushTypes.d.ts +22 -3
  15. package/dist/canvas/brushstroke.d.cts +34 -12
  16. package/dist/canvas/brushstroke.d.ts +34 -12
  17. package/dist/canvas/brushstrokeRender.d.cts +14 -8
  18. package/dist/canvas/brushstrokeRender.d.ts +14 -8
  19. package/dist/canvas/drawController.d.cts +11 -3
  20. package/dist/canvas/drawController.d.ts +11 -3
  21. package/dist/canvas/freehand.d.cts +6 -1
  22. package/dist/canvas/freehand.d.ts +6 -1
  23. package/dist/canvas/index.cjs +114 -102
  24. package/dist/canvas/index.js +16 -4
  25. package/dist/{chunk-XVIK73LS.js → chunk-5P4JEOIV.js} +4 -4
  26. package/dist/{chunk-JPEHXIB5.cjs → chunk-5YWWQ36H.cjs} +66 -21
  27. package/dist/{chunk-CHAWTXBE.cjs → chunk-6WCQ35GI.cjs} +4 -4
  28. package/dist/{chunk-GYMMNCFT.js → chunk-AF23QK5F.js} +56 -11
  29. package/dist/{chunk-JFHBXNR2.cjs → chunk-B7V34GIH.cjs} +86 -86
  30. package/dist/{chunk-QC3OXRE4.js → chunk-DMTEQ6SH.js} +1 -1
  31. package/dist/{chunk-TLOGFIIV.cjs → chunk-GCTUOTCW.cjs} +35 -35
  32. package/dist/{chunk-34KLWUH4.cjs → chunk-HIMGBZAM.cjs} +1133 -597
  33. package/dist/{chunk-7P6VF3FG.js → chunk-HYWRU5VX.js} +1 -1
  34. package/dist/{chunk-QPHNVZHO.js → chunk-JVRLGV3C.js} +1118 -582
  35. package/dist/{chunk-LFMKWGFL.cjs → chunk-LRNUZKWV.cjs} +22 -8
  36. package/dist/chunk-PGPFWC35.cjs +517 -0
  37. package/dist/{chunk-QLSGTCYT.cjs → chunk-TBAVCLEQ.cjs} +23 -23
  38. package/dist/{chunk-2ZJ4DT3M.js → chunk-VUKUTT2W.js} +1 -1
  39. package/dist/{chunk-5JNA6LLY.js → chunk-WYGSR3IJ.js} +22 -8
  40. package/dist/chunk-YHUMGBZD.js +517 -0
  41. package/dist/commands/builtins.d.cts +1 -1
  42. package/dist/commands/builtins.d.ts +1 -1
  43. package/dist/commands/index.cjs +2 -2
  44. package/dist/commands/index.js +1 -1
  45. package/dist/image-editor/brush-presets.d.cts +32 -0
  46. package/dist/image-editor/brush-presets.d.ts +32 -0
  47. package/dist/image-editor/controller.d.cts +15 -0
  48. package/dist/image-editor/controller.d.ts +15 -0
  49. package/dist/image-editor/index.cjs +848 -775
  50. package/dist/image-editor/index.d.cts +1 -0
  51. package/dist/image-editor/index.d.ts +1 -0
  52. package/dist/image-editor/index.js +81 -8
  53. package/dist/image-editor/types.d.cts +7 -0
  54. package/dist/image-editor/types.d.ts +7 -0
  55. package/dist/paint-editor/index.cjs +80 -80
  56. package/dist/paint-editor/index.js +13 -13
  57. package/dist/vector/brushstroke.d.cts +21 -5
  58. package/dist/vector/brushstroke.d.ts +21 -5
  59. package/dist/vector/controller.d.cts +14 -1
  60. package/dist/vector/controller.d.ts +14 -1
  61. package/dist/vector/index.cjs +1220 -1199
  62. package/dist/vector/index.js +34 -13
  63. package/dist/vector/types.d.cts +7 -0
  64. package/dist/vector/types.d.ts +7 -0
  65. package/package.json +1 -1
  66. package/skills/pixerate-brushes/SKILL.md +9 -3
  67. package/skills/pixerate-canvas/SKILL.md +10 -5
  68. package/skills/pixerate-image-editor/SKILL.md +2 -1
  69. package/skills/pixerate-vector/SKILL.md +1 -1
  70. package/dist/chunk-HS6QDWDF.cjs +0 -1029
  71. package/dist/chunk-MTKY6K3Q.js +0 -1029
@@ -5,7 +5,7 @@
5
5
 
6
6
 
7
7
 
8
- var _chunkJPEHXIB5cjs = require('./chunk-JPEHXIB5.cjs');
8
+ var _chunk5YWWQ36Hcjs = require('./chunk-5YWWQ36H.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 = _chunkJPEHXIB5cjs.subpathSegment.call(void 0, sp, i);
1364
+ const s = _chunk5YWWQ36Hcjs.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) => _chunkJPEHXIB5cjs.subpathSegment.call(void 0, sp, i).length === 2;
1369
+ var isLine = (sp, i) => _chunk5YWWQ36Hcjs.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 = _chunkJPEHXIB5cjs.cloneAnchor.call(void 0, a);
1389
+ const next = _chunk5YWWQ36Hcjs.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 = _chunkJPEHXIB5cjs.inferAnchorType.call(void 0, next);
1392
+ const shown = _chunk5YWWQ36Hcjs.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(_chunkJPEHXIB5cjs.cloneAnchor);
1436
+ const anchors = sp.anchors.map(_chunk5YWWQ36Hcjs.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(_chunkJPEHXIB5cjs.cloneAnchor), closed: sp.closed });
1470
+ return order.reduce((acc, i) => removeAnchorKeepingShape(acc, i), { anchors: sp.anchors.map(_chunk5YWWQ36Hcjs.cloneAnchor), closed: sp.closed });
1471
1471
  }
1472
1472
  function bendSegment(sp, segment, t, p) {
1473
- const anchors = sp.anchors.map(_chunkJPEHXIB5cjs.cloneAnchor);
1473
+ const anchors = sp.anchors.map(_chunk5YWWQ36Hcjs.cloneAnchor);
1474
1474
  const n = anchors.length;
1475
- if (segment < 0 || segment >= _chunkJPEHXIB5cjs.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 >= _chunk5YWWQ36Hcjs.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] = _chunkJPEHXIB5cjs.moveAnchorHandle.call(void 0, a, "out", c1);
1487
- anchors[ib] = _chunkJPEHXIB5cjs.moveAnchorHandle.call(void 0, b, "in", c2);
1486
+ anchors[ia] = _chunk5YWWQ36Hcjs.moveAnchorHandle.call(void 0, a, "out", c1);
1487
+ anchors[ib] = _chunk5YWWQ36Hcjs.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, _chunkJPEHXIB5cjs.subpathSegment.call(void 0, sp, segment), t);
1491
+ const [x, y] = _chunkGF2RBSDMcjs.segmentPoint.call(void 0, _chunk5YWWQ36Hcjs.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(_chunkJPEHXIB5cjs.cloneAnchor);
1495
+ const anchors = sp.anchors.map(_chunk5YWWQ36Hcjs.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(_chunkJPEHXIB5cjs.cloneAnchor), closed: sp.closed }];
1541
+ if (!cuts.length || n < 2) return [{ anchors: sp.anchors.map(_chunk5YWWQ36Hcjs.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(_chunkJPEHXIB5cjs.cloneAnchor.call(void 0, a));
1549
+ cur.push(_chunk5YWWQ36Hcjs.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 >= _chunkJPEHXIB5cjs.subpathSegmentCount.call(void 0, sp)) return [{ anchors: sp.anchors.map(_chunkJPEHXIB5cjs.cloneAnchor), closed: sp.closed }];
1564
+ if (segment < 0 || segment >= _chunk5YWWQ36Hcjs.subpathSegmentCount.call(void 0, sp)) return [{ anchors: sp.anchors.map(_chunk5YWWQ36Hcjs.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 } = _chunkJPEHXIB5cjs.insertAnchor.call(void 0, sp, segment, t);
1567
+ const { subpath, index } = _chunk5YWWQ36Hcjs.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(_chunkJPEHXIB5cjs.cloneAnchor), closed: sp.closed };
1590
+ const copy = { anchors: sp.anchors.map(_chunk5YWWQ36Hcjs.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(_chunkJPEHXIB5cjs.cloneAnchor);
1645
+ const anchors = orig.map(_chunk5YWWQ36Hcjs.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 < _chunkJPEHXIB5cjs.subpathSegmentCount.call(void 0, sp); i++) {
1675
- const s = _chunkJPEHXIB5cjs.subpathSegment.call(void 0, sp, i);
1674
+ for (let i = 0; i < _chunk5YWWQ36Hcjs.subpathSegmentCount.call(void 0, sp); i++) {
1675
+ const s = _chunk5YWWQ36Hcjs.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(_chunkJPEHXIB5cjs.cloneAnchor), closed: sp.closed };
1732
+ if (!segs.length) return { anchors: sp.anchors.map(_chunk5YWWQ36Hcjs.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(_chunkJPEHXIB5cjs.cloneAnchor), closed: sp.closed }));
1750
+ return _nullishCoalesce(segsToSubpath(segs, sp.closed, types), () => ( { anchors: sp.anchors.map(_chunk5YWWQ36Hcjs.cloneAnchor), closed: sp.closed }));
1751
1751
  }
1752
1752
 
1753
1753
 
@@ -5,7 +5,7 @@ import {
5
5
  moveAnchorHandle,
6
6
  subpathSegment,
7
7
  subpathSegmentCount
8
- } from "./chunk-GYMMNCFT.js";
8
+ } from "./chunk-AF23QK5F.js";
9
9
  import {
10
10
  segmentPoint
11
11
  } from "./chunk-WEIK3UYB.js";
@@ -74,17 +74,25 @@ function profileAlongPolyline(points, values, count = 32) {
74
74
  var round3 = (v) => Math.round(v * 1e3) / 1e3;
75
75
  var loading = null;
76
76
  function loadCanvasBrushstrokeRenderer() {
77
- loading ??= import("./brushstrokeRender-5PYSKZIJ.js").catch((error) => {
77
+ loading ??= import("./brushstrokeRender-HCOQUSWW.js").catch((error) => {
78
78
  loading = null;
79
79
  throw error;
80
80
  });
81
81
  return loading;
82
82
  }
83
- async function listCanvasBrushes() {
84
- return (await loadCanvasBrushstrokeRenderer()).listCanvasBrushes();
83
+ async function listCanvasBrushes(library) {
84
+ const user = library ? (await library.list({ source: "user" })).map((e) => e.brush) : [];
85
+ return (await loadCanvasBrushstrokeRenderer()).listCanvasBrushes(user);
85
86
  }
86
- async function validateCanvasBrush(brush) {
87
- (await loadCanvasBrushstrokeRenderer()).resolveCanvasBrush(brush, 1);
87
+ async function resolveCanvasBrushSpec(brush, library) {
88
+ if (typeof brush !== "string" || !library || library.isBuiltin(brush)) return void 0;
89
+ const entry = await library.get(brush);
90
+ if (!entry) return void 0;
91
+ (await loadCanvasBrushstrokeRenderer()).readCanvasBrushSpec(entry.brush);
92
+ return entry.brush;
93
+ }
94
+ async function validateCanvasBrush(brush, spec) {
95
+ (await loadCanvasBrushstrokeRenderer()).resolveCanvasBrush(brush, 1, spec);
88
96
  }
89
97
  async function validateCanvasBrushPaint(paint) {
90
98
  (await loadCanvasBrushstrokeRenderer()).resolveCanvasPaint(paint);
@@ -105,9 +113,13 @@ async function getBrushedShapeSvg(shape, size, options = {}) {
105
113
  if (!isBrushedShape(shape)) return null;
106
114
  return (await loadCanvasBrushstrokeRenderer()).brushedShapeSvgNow(shape, size, options.scale ?? 2, options);
107
115
  }
108
- async function renderCanvasBrushSwatch(brush, options = {}) {
109
- return (await loadCanvasBrushstrokeRenderer()).brushSwatchNow(brush, options);
116
+ async function renderCanvasBrushSwatch(brush, options = {}, spec) {
117
+ return (await loadCanvasBrushstrokeRenderer()).brushSwatchNow(brush, options, spec);
110
118
  }
119
+ var renderCanvasBrushPreview = async (brush, { width, height, color }) => {
120
+ const url = await renderCanvasBrushSwatch(brush.id, { width, height, color, scale: 1 }, brush);
121
+ return { data: url.replace(/^data:image\/png;base64,/, ""), mimeType: "image/png" };
122
+ };
111
123
 
112
124
  export {
113
125
  isBrushedShape,
@@ -115,10 +127,12 @@ export {
115
127
  profileAlongPolyline,
116
128
  loadCanvasBrushstrokeRenderer,
117
129
  listCanvasBrushes,
130
+ resolveCanvasBrushSpec,
118
131
  validateCanvasBrush,
119
132
  validateCanvasBrushPaint,
120
133
  brushstrokeSeed,
121
134
  renderShapeBrushstroke,
122
135
  getBrushedShapeSvg,
123
- renderCanvasBrushSwatch
136
+ renderCanvasBrushSwatch,
137
+ renderCanvasBrushPreview
124
138
  };