@pixerate/editor 0.137.0 → 0.139.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 (127) hide show
  1. package/dist/agent/index.cjs +2 -2
  2. package/dist/agent/index.d.cts +3 -3
  3. package/dist/agent/index.d.ts +3 -3
  4. package/dist/agent/index.js +1 -1
  5. package/dist/animation-editor/index.cjs +57 -57
  6. package/dist/animation-editor/index.d.cts +6 -5
  7. package/dist/animation-editor/index.d.ts +6 -5
  8. package/dist/animation-editor/index.js +4 -4
  9. package/dist/{arrange-CKXK_hf7.d.cts → arrange-j_mLiFMO.d.cts} +1 -1
  10. package/dist/{arrange-BUREmgD9.d.ts → arrange-q5HQvnnB.d.ts} +1 -1
  11. package/dist/{bezier-Dywv3Bw8.d.ts → bezier-B6cK8SR6.d.ts} +2 -2
  12. package/dist/{bezier-CZ2AhjID.d.cts → bezier-CEJ8Uw4O.d.cts} +2 -2
  13. package/dist/{brushTypes-C7N3EBK7.d.cts → brushTypes-MX5UVs_m.d.cts} +27 -2
  14. package/dist/{brushTypes-C7N3EBK7.d.ts → brushTypes-MX5UVs_m.d.ts} +27 -2
  15. package/dist/{brushes-DJmUbIgz.d.ts → brushes-CQpL7_Lc.d.ts} +2 -107
  16. package/dist/{brushes-CnvZSYYU.d.cts → brushes-aEnjqoji.d.cts} +2 -107
  17. package/dist/{brushstrokeRender-IMFY3FF6.cjs → brushstrokeRender-PP6NTF6M.cjs} +52 -24
  18. package/dist/brushstrokeRender-PP6NTF6M.cjs.map +1 -0
  19. package/dist/{brushstrokeRender-2FAXA3XC.js → brushstrokeRender-QGEYJ4OZ.js} +40 -12
  20. package/dist/brushstrokeRender-QGEYJ4OZ.js.map +1 -0
  21. package/dist/{builtins-Cc-bH-3U.d.cts → builtins-BakDiKWf.d.cts} +3 -2
  22. package/dist/{builtins-ZU1GJnUA.d.ts → builtins-CE33vyv2.d.ts} +3 -2
  23. package/dist/canvas/index.cjs +16 -9
  24. package/dist/canvas/index.cjs.map +1 -1
  25. package/dist/canvas/index.d.cts +60 -14
  26. package/dist/canvas/index.d.ts +60 -14
  27. package/dist/canvas/index.js +10 -3
  28. package/dist/canvas/index.js.map +1 -1
  29. package/dist/{chunk-PRSRYHQD.cjs → chunk-3QHPFSQM.cjs} +36 -36
  30. package/dist/{chunk-PRSRYHQD.cjs.map → chunk-3QHPFSQM.cjs.map} +1 -1
  31. package/dist/{chunk-QBWEH3IM.cjs → chunk-3T5O225T.cjs} +391 -76
  32. package/dist/chunk-3T5O225T.cjs.map +1 -0
  33. package/dist/{chunk-EQQMGO42.js → chunk-C2J7GOMJ.js} +18 -5
  34. package/dist/chunk-C2J7GOMJ.js.map +1 -0
  35. package/dist/{chunk-2XS6LTUP.cjs → chunk-C46AZEBE.cjs} +104 -339
  36. package/dist/chunk-C46AZEBE.cjs.map +1 -0
  37. package/dist/{chunk-HUO3TI4C.js → chunk-CPSMARTX.js} +6 -241
  38. package/dist/chunk-CPSMARTX.js.map +1 -0
  39. package/dist/{chunk-KEENUAFN.cjs → chunk-DLLUOVQX.cjs} +18 -5
  40. package/dist/chunk-DLLUOVQX.cjs.map +1 -0
  41. package/dist/{chunk-LSXXAJG3.js → chunk-J7DSKTKB.js} +5 -4
  42. package/dist/chunk-J7DSKTKB.js.map +1 -0
  43. package/dist/{chunk-6S6362D2.js → chunk-NI6RORDS.js} +2 -2
  44. package/dist/{chunk-XN2NBLV5.cjs → chunk-PMEHFHSP.cjs} +82 -82
  45. package/dist/{chunk-XN2NBLV5.cjs.map → chunk-PMEHFHSP.cjs.map} +1 -1
  46. package/dist/{chunk-5FSRTP6E.js → chunk-PQFVLOMR.js} +319 -4
  47. package/dist/chunk-PQFVLOMR.js.map +1 -0
  48. package/dist/{chunk-OIBIRXRG.js → chunk-PSPLRQL6.js} +2 -2
  49. package/dist/{chunk-SYT2TLQF.js → chunk-QEIN6JQO.js} +2 -2
  50. package/dist/{chunk-3D77LOBM.js → chunk-TJBYBSTN.js} +51 -6
  51. package/dist/chunk-TJBYBSTN.js.map +1 -0
  52. package/dist/{chunk-DFSZO2B5.cjs → chunk-UFL5N4DK.cjs} +5 -4
  53. package/dist/chunk-UFL5N4DK.cjs.map +1 -0
  54. package/dist/{chunk-TLCTTQFF.cjs → chunk-VEHVXRJU.cjs} +17 -17
  55. package/dist/{chunk-TLCTTQFF.cjs.map → chunk-VEHVXRJU.cjs.map} +1 -1
  56. package/dist/{chunk-5OOIUXNJ.cjs → chunk-XFXHA5MU.cjs} +55 -10
  57. package/dist/chunk-XFXHA5MU.cjs.map +1 -0
  58. package/dist/commands/index.cjs +2 -2
  59. package/dist/commands/index.d.cts +3 -3
  60. package/dist/commands/index.d.ts +3 -3
  61. package/dist/commands/index.js +1 -1
  62. package/dist/effects/index.d.cts +5 -4
  63. package/dist/effects/index.d.ts +5 -4
  64. package/dist/{export-DwnZ_hvQ.d.ts → export-0ZaTK__4.d.ts} +4 -4
  65. package/dist/{export-41rL6Cne.d.ts → export-C45v6MYq.d.ts} +1 -1
  66. package/dist/{export-CyJdfP_Z.d.cts → export-D-7WCDJ9.d.cts} +4 -4
  67. package/dist/{export-D9mXp05Q.d.cts → export-DSdCfd6O.d.cts} +1 -1
  68. package/dist/grain-BWmGZxP4.d.cts +58 -0
  69. package/dist/grain-BWmGZxP4.d.ts +58 -0
  70. package/dist/{helpers-v6GMazzg.d.cts → helpers-Cavy1TB7.d.cts} +21 -1
  71. package/dist/{helpers-C-RgeyvH.d.ts → helpers-LZQ4cpg4.d.ts} +21 -1
  72. package/dist/image-editor/index.cjs +695 -677
  73. package/dist/image-editor/index.cjs.map +1 -1
  74. package/dist/image-editor/index.d.cts +12 -11
  75. package/dist/image-editor/index.d.ts +12 -11
  76. package/dist/image-editor/index.js +23 -5
  77. package/dist/image-editor/index.js.map +1 -1
  78. package/dist/{opentype-KR_jj6b_.d.cts → opentype-BpIJhGpj.d.cts} +1 -1
  79. package/dist/{opentype-a1KAW-qs.d.ts → opentype-CyxDScVz.d.ts} +1 -1
  80. package/dist/paint/index.cjs +21 -3
  81. package/dist/paint/index.cjs.map +1 -1
  82. package/dist/paint/index.d.cts +72 -5
  83. package/dist/paint/index.d.ts +72 -5
  84. package/dist/paint/index.js +20 -2
  85. package/dist/paint-editor/index.cjs +171 -171
  86. package/dist/paint-editor/index.cjs.map +1 -1
  87. package/dist/paint-editor/index.d.cts +77 -29
  88. package/dist/paint-editor/index.d.ts +77 -29
  89. package/dist/paint-editor/index.js +12 -12
  90. package/dist/{pathfinder-BHS4vQNm.d.cts → pathfinder-BMQEcS0k.d.cts} +2 -2
  91. package/dist/{pathfinder-BVvTIBMo.d.ts → pathfinder-CQIxubuP.d.ts} +2 -2
  92. package/dist/{pool-CZQOrSXZ.d.ts → pool-Cynuj89K.d.ts} +1 -1
  93. package/dist/{pool-FjZZmZ80.d.cts → pool-DedjxDKo.d.cts} +1 -1
  94. package/dist/{rand-8xbUb6ur.d.ts → rand-COS4_E1g.d.ts} +17 -1
  95. package/dist/{rand-Cw9VLrVC.d.cts → rand-D1JqpR-p.d.cts} +17 -1
  96. package/dist/{svg-DTb40ICU.d.cts → svg-RcixtBFR.d.cts} +2 -2
  97. package/dist/{svg-CSz3mzkw.d.ts → svg-nWBJEpnk.d.ts} +2 -2
  98. package/dist/{tools-Ca0kI1qo.d.cts → tools-CL82d7nw.d.cts} +1 -1
  99. package/dist/{tools-B0wXP5cF.d.ts → tools-DrxgDnXY.d.ts} +1 -1
  100. package/dist/vector/index.cjs +995 -955
  101. package/dist/vector/index.cjs.map +1 -1
  102. package/dist/vector/index.d.cts +44 -18
  103. package/dist/vector/index.d.ts +44 -18
  104. package/dist/vector/index.js +55 -15
  105. package/dist/vector/index.js.map +1 -1
  106. package/dist/video-editor/index.d.cts +5 -4
  107. package/dist/video-editor/index.d.ts +5 -4
  108. package/dist/{warp-DTOp0lON.d.cts → warp-CHi_P_G6.d.cts} +1 -1
  109. package/dist/{warp-pd7hrH4T.d.ts → warp-CPaHULUL.d.ts} +1 -1
  110. package/package.json +1 -1
  111. package/skills/pixerate-canvas/SKILL.md +12 -5
  112. package/skills/pixerate-vector/SKILL.md +4 -2
  113. package/dist/brushstrokeRender-2FAXA3XC.js.map +0 -1
  114. package/dist/brushstrokeRender-IMFY3FF6.cjs.map +0 -1
  115. package/dist/chunk-2XS6LTUP.cjs.map +0 -1
  116. package/dist/chunk-3D77LOBM.js.map +0 -1
  117. package/dist/chunk-5FSRTP6E.js.map +0 -1
  118. package/dist/chunk-5OOIUXNJ.cjs.map +0 -1
  119. package/dist/chunk-DFSZO2B5.cjs.map +0 -1
  120. package/dist/chunk-EQQMGO42.js.map +0 -1
  121. package/dist/chunk-HUO3TI4C.js.map +0 -1
  122. package/dist/chunk-KEENUAFN.cjs.map +0 -1
  123. package/dist/chunk-LSXXAJG3.js.map +0 -1
  124. package/dist/chunk-QBWEH3IM.cjs.map +0 -1
  125. /package/dist/{chunk-6S6362D2.js.map → chunk-NI6RORDS.js.map} +0 -0
  126. /package/dist/{chunk-OIBIRXRG.js.map → chunk-PSPLRQL6.js.map} +0 -0
  127. /package/dist/{chunk-SYT2TLQF.js.map → chunk-QEIN6JQO.js.map} +0 -0
@@ -40,6 +40,73 @@ function hash2(x, y, salt) {
40
40
  function rand01(seed, index, stream) {
41
41
  return hash2(index, stream, seed);
42
42
  }
43
+ function randSigned(seed, index, stream) {
44
+ return rand01(seed, index, stream) * 2 - 1;
45
+ }
46
+ function seedFromString(text) {
47
+ let h = 2166136261;
48
+ for (let i = 0; i < text.length; i++) {
49
+ h ^= text.charCodeAt(i);
50
+ h = Math.imul(h, 16777619);
51
+ }
52
+ return mix32(h >>> 0);
53
+ }
54
+ var smooth = (t) => t * t * (3 - 2 * t);
55
+ var Lattice = class {
56
+ constructor(px, py, salt) {
57
+ this.px = px;
58
+ this.py = py;
59
+ this.values = new Float32Array(px * py);
60
+ for (let j = 0; j < py; j++) for (let i = 0; i < px; i++) this.values[j * px + i] = hash2(i, j, salt);
61
+ }
62
+ px;
63
+ py;
64
+ values;
65
+ /** Value noise at (x, y) in lattice cells; wraps every `px` / `py` cells. */
66
+ at(x, y) {
67
+ const { px, py } = this;
68
+ const x0 = Math.floor(x);
69
+ const y0 = Math.floor(y);
70
+ const tx = smooth(x - x0);
71
+ const ty = smooth(y - y0);
72
+ const i0 = (x0 % px + px) % px;
73
+ const j0 = (y0 % py + py) % py;
74
+ const i1 = (i0 + 1) % px;
75
+ const j1 = (j0 + 1) % py;
76
+ const v = this.values;
77
+ const a = v[j0 * px + i0] + (v[j0 * px + i1] - v[j0 * px + i0]) * tx;
78
+ const b = v[j1 * px + i0] + (v[j1 * px + i1] - v[j1 * px + i0]) * tx;
79
+ return a + (b - a) * ty;
80
+ }
81
+ };
82
+ var TileableNoise = class {
83
+ constructor(size, cellsX, cellsY, octaves, salt) {
84
+ this.size = size;
85
+ let cx = Math.max(1, Math.round(cellsX));
86
+ let cy = Math.max(1, Math.round(cellsY));
87
+ for (let o = 0; o < octaves; o++) {
88
+ this.octaves.push(new Lattice(cx, cy, salt + o * 7919 | 0));
89
+ cx *= 2;
90
+ cy *= 2;
91
+ }
92
+ }
93
+ size;
94
+ octaves = [];
95
+ /** Fractal noise at pixel (x, y). */
96
+ at(x, y) {
97
+ let sum = 0;
98
+ let amp = 1;
99
+ let norm = 0;
100
+ const u = x / this.size;
101
+ const v = y / this.size;
102
+ for (const l of this.octaves) {
103
+ sum += l.at(u * l.px, v * l.py) * amp;
104
+ norm += amp;
105
+ amp *= 0.5;
106
+ }
107
+ return norm > 0 ? sum / norm : 0.5;
108
+ }
109
+ };
43
110
 
44
111
  // src/paint/gradient-paint.ts
45
112
  var PAINT_GRADIENT_SPACES = ["pigment", "oklab", "srgb"];
@@ -1100,7 +1167,181 @@ function coverageTileCoord(key) {
1100
1167
  return tileCoord(key);
1101
1168
  }
1102
1169
 
1170
+ // src/paint/grain.ts
1171
+ var GRAIN_PATTERNS = ["smooth", "cold-pressed", "hot-pressed", "rough", "vellum", "laid", "ingres", "sanded", "canvas", "linen", "gesso"];
1172
+ var GRAIN_TILE = 256;
1173
+ var clamp01 = (v) => v < 0 ? 0 : v > 1 ? 1 : v;
1174
+ function patternHeights(pattern, n, seed) {
1175
+ const out = new Float32Array(n * n);
1176
+ const salt = Math.imul(seed | 0, 2654435761) + 17;
1177
+ if (pattern === "smooth") return out.fill(1);
1178
+ const noise = (cx, cy, oct, s = 0) => new TileableNoise(n, cx, cy, oct, salt + s);
1179
+ const k = n / GRAIN_TILE;
1180
+ switch (pattern) {
1181
+ case "cold-pressed": {
1182
+ const base = noise(20 * k, 20 * k, 4);
1183
+ const fine = noise(64 * k, 64 * k, 2, 3);
1184
+ for (let y = 0; y < n; y++)
1185
+ for (let x = 0; x < n; x++) out[y * n + x] = clamp01((base.at(x, y) - 0.5) * 1.8 + 0.5 + (fine.at(x, y) - 0.5) * 0.5 + (hash2(x, y, salt) - 0.5) * 0.12);
1186
+ break;
1187
+ }
1188
+ case "hot-pressed": {
1189
+ const base = noise(40 * k, 40 * k, 3);
1190
+ for (let y = 0; y < n; y++) for (let x = 0; x < n; x++) out[y * n + x] = clamp01((base.at(x, y) - 0.5) * 1.1 + 0.6 + (hash2(x, y, salt) - 0.5) * 0.08);
1191
+ break;
1192
+ }
1193
+ case "rough": {
1194
+ const base = noise(10 * k, 10 * k, 5);
1195
+ const blot = noise(28 * k, 28 * k, 2, 5);
1196
+ for (let y = 0; y < n; y++)
1197
+ for (let x = 0; x < n; x++) out[y * n + x] = clamp01((base.at(x, y) - 0.5) * 2.4 + 0.5 + (blot.at(x, y) - 0.5) * 0.7 + (hash2(x, y, salt) - 0.5) * 0.15);
1198
+ break;
1199
+ }
1200
+ case "vellum": {
1201
+ const base = noise(40 * k, 40 * k, 3);
1202
+ for (let y = 0; y < n; y++) for (let x = 0; x < n; x++) out[y * n + x] = clamp01((base.at(x, y) - 0.5) * 1.6 + 0.55 + (hash2(x, y, salt) - 0.5) * 0.2);
1203
+ break;
1204
+ }
1205
+ case "laid": {
1206
+ const pulp = noise(32 * k, 32 * k, 3);
1207
+ const chain = n / 8;
1208
+ for (let y = 0; y < n; y++) {
1209
+ const laid = 0.5 + 0.5 * Math.cos(2 * Math.PI * y / 4);
1210
+ for (let x = 0; x < n; x++) {
1211
+ const c = Math.abs((x + 0.5) % chain - chain / 2) / (chain / 2);
1212
+ const chainLine = c > 0.94 ? -0.35 : 0;
1213
+ out[y * n + x] = clamp01(0.3 + 0.5 * laid + chainLine + (pulp.at(x, y) - 0.5) * 0.6);
1214
+ }
1215
+ }
1216
+ break;
1217
+ }
1218
+ case "ingres": {
1219
+ const fibres = noise(64 * k, 12 * k, 3);
1220
+ const base = noise(16 * k, 16 * k, 3, 7);
1221
+ for (let y = 0; y < n; y++)
1222
+ for (let x = 0; x < n; x++) {
1223
+ const g = hash2(x, y, salt ^ 85);
1224
+ out[y * n + x] = clamp01((fibres.at(x, y) - 0.5) * 1.5 + (base.at(x, y) - 0.5) * 0.7 + 0.55 + (g < 0.1 ? -0.3 : 0));
1225
+ }
1226
+ break;
1227
+ }
1228
+ case "sanded": {
1229
+ const grit = noise(96 * k, 96 * k, 2);
1230
+ for (let y = 0; y < n; y++)
1231
+ for (let x = 0; x < n; x++) {
1232
+ const h = hash2(x, y, salt);
1233
+ out[y * n + x] = clamp01((grit.at(x, y) - 0.5) * 2.4 + 0.5 + (h - 0.5) * 0.7);
1234
+ }
1235
+ break;
1236
+ }
1237
+ case "canvas":
1238
+ case "linen": {
1239
+ const period = (pattern === "canvas" ? 8 : 5) * k;
1240
+ const threads = Math.max(2, 2 * Math.round(n / period / 2));
1241
+ const p = n / threads;
1242
+ const slub = noise(threads, threads, 2, 11);
1243
+ for (let y = 0; y < n; y++)
1244
+ for (let x = 0; x < n; x++) {
1245
+ const fx = (x + 0.5) / p;
1246
+ const fy = (y + 0.5) / p;
1247
+ const cx = Math.floor(fx);
1248
+ const cy = Math.floor(fy);
1249
+ const warp = Math.sin(Math.PI * (fx - cx));
1250
+ const weft = Math.sin(Math.PI * (fy - cy));
1251
+ const top = (cx + cy) % 2 === 0 ? warp : weft;
1252
+ const irregular = pattern === "linen" ? (slub.at(x, y) - 0.5) * 0.5 : 0;
1253
+ out[y * n + x] = clamp01(0.2 + 0.7 * top + irregular + (hash2(x, y, salt) - 0.5) * 0.15);
1254
+ }
1255
+ break;
1256
+ }
1257
+ case "gesso": {
1258
+ const streaks = noise(2 * k, 28 * k, 3);
1259
+ const tooth = noise(64 * k, 64 * k, 2, 13);
1260
+ for (let y = 0; y < n; y++)
1261
+ for (let x = 0; x < n; x++) out[y * n + x] = clamp01((streaks.at(x, y) - 0.5) * 1.8 + (tooth.at(x, y) - 0.5) * 0.9 + 0.55);
1262
+ break;
1263
+ }
1264
+ }
1265
+ return out;
1266
+ }
1267
+ var rawCache = /* @__PURE__ */ new Map();
1268
+ function grainHeights(pattern, seed, size = GRAIN_TILE) {
1269
+ const key = `${pattern}:${seed}:${size}`;
1270
+ let h = rawCache.get(key);
1271
+ if (!h) {
1272
+ h = patternHeights(pattern, size, seed);
1273
+ if (rawCache.size > 32) rawCache.delete(rawCache.keys().next().value);
1274
+ rawCache.set(key, h);
1275
+ }
1276
+ return h;
1277
+ }
1278
+ var PaperGrain = class {
1279
+ size = GRAIN_TILE;
1280
+ heights;
1281
+ scale;
1282
+ mirror;
1283
+ flat;
1284
+ constructor(paper, media = "dry") {
1285
+ const raw = grainHeights(paper.pattern, paper.seed);
1286
+ const t = paper[media];
1287
+ this.flat = paper.pattern === "smooth";
1288
+ if (t.contrast === 1 && !t.invert) this.heights = raw;
1289
+ else {
1290
+ const out = new Float32Array(raw.length);
1291
+ for (let i = 0; i < raw.length; i++) {
1292
+ const v = clamp01((raw[i] - 0.5) * t.contrast + 0.5);
1293
+ out[i] = t.invert ? 1 - v : v;
1294
+ }
1295
+ this.heights = out;
1296
+ }
1297
+ this.scale = paper.scale;
1298
+ this.mirror = paper.tiling === "mirror";
1299
+ }
1300
+ /** Tile cell index for a coordinate in grain pixels (mirrored on odd tiles when mirroring). */
1301
+ wrap(v) {
1302
+ const n = this.size;
1303
+ if (!this.mirror) return (v % n + n) % n;
1304
+ const p = (v % (2 * n) + 2 * n) % (2 * n);
1305
+ return p < n ? p : 2 * n - 1 - p;
1306
+ }
1307
+ /** Height 0..1 at document position (x, y). */
1308
+ at(x, y) {
1309
+ const u = x / this.scale - 0.5;
1310
+ const v = y / this.scale - 0.5;
1311
+ const x0 = Math.floor(u);
1312
+ const y0 = Math.floor(v);
1313
+ const fx = u - x0;
1314
+ const fy = v - y0;
1315
+ const n = this.size;
1316
+ const h = this.heights;
1317
+ const a = this.wrap(x0);
1318
+ const b = this.wrap(x0 + 1);
1319
+ const c = this.wrap(y0) * n;
1320
+ const d = this.wrap(y0 + 1) * n;
1321
+ const top = h[c + a] + (h[c + b] - h[c + a]) * fx;
1322
+ const bot = h[d + a] + (h[d + b] - h[d + a]) * fx;
1323
+ return top + (bot - top) * fy;
1324
+ }
1325
+ };
1326
+ function grainCatch(h, depth, pressure) {
1327
+ if (depth <= 0) return 1;
1328
+ const t = depth * (0.75 - 0.65 * Math.min(1, Math.max(0, pressure)));
1329
+ const u = clamp01((h - t + 0.18) / 0.36);
1330
+ return 1 - depth + depth * u * u * (3 - 2 * u);
1331
+ }
1332
+ function strokeGrainCatch(h, depth, pressure) {
1333
+ if (depth <= 0) return 1;
1334
+ const p = Math.min(1, Math.max(0, pressure));
1335
+ const amount = Math.min(1, depth * (1.4 - 0.6 * p));
1336
+ const u = clamp01((h - 0.2 - 0.25 * (1 - p)) / 0.5);
1337
+ return 1 - amount + amount * u * u * (3 - 2 * u);
1338
+ }
1339
+
1103
1340
  // src/paint/path-stroke.ts
1341
+ var JITTER_SIZE = 1;
1342
+ var JITTER_ANGLE = 2;
1343
+ var JITTER_OPACITY = 3;
1344
+ var JITTER_SCATTER = 4;
1104
1345
  function lean(s) {
1105
1346
  if (typeof s.altitude === "number" && Number.isFinite(s.altitude)) {
1106
1347
  return { amount: 1 - Math.min(1, Math.max(0, s.altitude / (Math.PI / 2))), azimuth: s.azimuth ?? 0 };
@@ -1132,8 +1373,22 @@ function pathStrokeDabs(samples, options) {
1132
1373
  if (tilt.followAzimuth && l) angle = -l.azimuth;
1133
1374
  const roundness = Math.max(0.05, brush.roundness * (1 - 0.85 * (tilt.roundness ?? 0) * lean0));
1134
1375
  const op = brush.pressureOpacity ? pr : 1;
1135
- const params = { travel, index: index++, pressure: pr, lean: lean0, speed, direction: dir, time: time === null || t0 === null ? null : time - t0 };
1136
- return { x, y, radius: Math.max(0.5, size / 2), alpha: brush.flow, opacity: brush.opacity * op, angle, roundness, params };
1376
+ const i = index++;
1377
+ const params = { travel, index: i, pressure: pr, lean: lean0, speed, direction: dir, time: time === null || t0 === null ? null : time - t0 };
1378
+ let diameter = size;
1379
+ let opacity = brush.opacity * op;
1380
+ const j = options.jitter;
1381
+ if (j) {
1382
+ if (j.size) diameter *= Math.max(0.05, 1 + j.size * randSigned(j.seed, i, JITTER_SIZE));
1383
+ if (j.angle) angle += j.angle * Math.PI * randSigned(j.seed, i, JITTER_ANGLE);
1384
+ if (j.opacity) opacity *= 1 - j.opacity * (randSigned(j.seed, i, JITTER_OPACITY) * 0.5 + 0.5);
1385
+ if (j.scatter) {
1386
+ const off = j.scatter * diameter * randSigned(j.seed, i, JITTER_SCATTER);
1387
+ x += Math.sin(dir) * off;
1388
+ y += Math.cos(dir) * off;
1389
+ }
1390
+ }
1391
+ return { x, y, radius: Math.max(0.5, diameter / 2), alpha: brush.flow, opacity, angle, roundness, params };
1137
1392
  };
1138
1393
  const out = [];
1139
1394
  const pressure = (s) => typeof s.pressure === "number" && Number.isFinite(s.pressure) ? s.pressure : 1;
@@ -1202,6 +1457,17 @@ function pathStrokeCoverage(samples, options) {
1202
1457
  bounds = { x, y, width: Math.max(bounds.x + bounds.width, rect.x + rect.width) - x, height: Math.max(bounds.y + bounds.height, rect.y + rect.height) - y };
1203
1458
  }
1204
1459
  }
1460
+ const grain = options.grain;
1461
+ if (grain && grain.depth > 0 && dabs.length) {
1462
+ const pressure = dabs.reduce((sum, d) => sum + (d.params?.pressure ?? 1), 0) / dabs.length;
1463
+ for (const [key, t] of coverage.tiles) {
1464
+ const { tx, ty } = tileCoord(key);
1465
+ for (let y = 0, k = 0; y < TILE; y++) {
1466
+ const gy = ty * TILE + y + 0.5;
1467
+ for (let x = 0; x < TILE; x++, k++) if (t[k] > 0) t[k] *= strokeGrainCatch(grain.at(tx * TILE + x + 0.5, gy), grain.depth, pressure);
1468
+ }
1469
+ }
1470
+ }
1205
1471
  return { coverage, bounds, dabs: dabs.length };
1206
1472
  }
1207
1473
  function paintPathStroke(surface, samples, options) {
@@ -1296,6 +1562,26 @@ function isBrushstrokeBrush(brush) {
1296
1562
  return !("tip" in brush) || !brush.tip || (brush.engine ?? "dab") === "dab";
1297
1563
  }
1298
1564
  var finite2 = (v) => typeof v === "number" && Number.isFinite(v);
1565
+ function brushCharacterOf(brush) {
1566
+ if (!("tip" in brush) || !brush.tip) return { grain: 0, size: 0, angle: 0, opacity: 0, scatter: 0 };
1567
+ const d = brush.dynamics ?? {};
1568
+ const u = (v, hi = 1) => finite2(v) ? Math.min(hi, Math.max(0, v)) : 0;
1569
+ return { grain: u(brush.grain), size: u(d.sizeJitter), angle: u(d.angleJitter), opacity: u(d.opacityJitter), scatter: u(d.scatter, 4) };
1570
+ }
1571
+ var papers = /* @__PURE__ */ new Map();
1572
+ function paperGrain(paper) {
1573
+ const pattern = paper.pattern ?? "sanded";
1574
+ const seed = finite2(paper.seed) ? Math.round(Math.abs(paper.seed)) : 1;
1575
+ const scale = finite2(paper.scale) && paper.scale > 0 ? Math.min(8, Math.max(0.25, paper.scale)) : 1;
1576
+ const key = `${pattern}:${seed}:${scale}`;
1577
+ let g = papers.get(key);
1578
+ if (!g) {
1579
+ g = new PaperGrain({ pattern, seed, scale, tiling: "mirror", dry: { contrast: 1, invert: false }, wet: { contrast: 1, invert: false } });
1580
+ if (papers.size > 16) papers.delete(papers.keys().next().value);
1581
+ papers.set(key, g);
1582
+ }
1583
+ return g;
1584
+ }
1299
1585
  function renderBrushstroke(input, brush, options = {}) {
1300
1586
  const strokeOptions = brushstrokeStrokeOptions(brush);
1301
1587
  const samples = brushstrokeSamples(input);
@@ -1318,8 +1604,27 @@ function renderBrushstroke(input, brush, options = {}) {
1318
1604
  const area = (x1 - x0 + reach) * (y1 - y0 + reach);
1319
1605
  if (area * scale * scale > maxPixels) scale = Math.max(BRUSHSTROKE_MIN_SCALE, Math.sqrt(maxPixels / area));
1320
1606
  const scaled = samples.map((s) => ({ ...s, x: s.x * scale, y: s.y * scale }));
1607
+ let character = {};
1608
+ if (options.character) {
1609
+ const c = brushCharacterOf(brush);
1610
+ const ch = options.character;
1611
+ const seed = finite2(ch.seed) ? ch.seed | 0 : hashString(JSON.stringify(input));
1612
+ const jitter = c.size || c.angle || c.opacity || c.scatter ? { seed, size: c.size, angle: c.angle, opacity: c.opacity, scatter: c.scatter } : void 0;
1613
+ const paper = ch.paper === null ? null : ch.paper ?? {};
1614
+ const depth = paper ? Math.min(1, Math.max(0, (finite2(paper.depth) ? paper.depth : 0.5) * c.grain)) : 0;
1615
+ let grain;
1616
+ if (paper && depth > 0) {
1617
+ const g = paperGrain(paper);
1618
+ const ox = ch.origin?.x ?? 0;
1619
+ const oy = ch.origin?.y ?? 0;
1620
+ const k = (finite2(ch.unit) && ch.unit > 0 ? ch.unit : 1) / scale;
1621
+ grain = { depth, at: (x, y) => g.at(ox + x * k, oy + y * k) };
1622
+ }
1623
+ character = { ...jitter ? { jitter } : {}, ...grain ? { grain } : {} };
1624
+ }
1321
1625
  const { surface, bounds, dabs } = paintPathStroke(emptySurface(4), scaled, {
1322
1626
  ...strokeOptions,
1627
+ ...character,
1323
1628
  brush: { ...tip, size: tip.size * scale },
1324
1629
  closed: options.closed ?? strokeOptions.closed,
1325
1630
  color,
@@ -1361,7 +1666,8 @@ function hashString(s, h = 2166136261) {
1361
1666
  function brushstrokeKey(input, brush, options = {}) {
1362
1667
  const path = JSON.stringify(input);
1363
1668
  const { brush: tip, ...rest } = brushstrokeStrokeOptions(brush);
1364
- const rest2 = JSON.stringify([tip, rest, options.paint ?? options.color ?? null, options.seed ?? 0, options.closed ?? false, options.maxPixels ?? null]);
1669
+ const character = options.character ? [options.character, brushCharacterOf(brush)] : null;
1670
+ const rest2 = JSON.stringify([tip, rest, options.paint ?? options.color ?? null, options.seed ?? 0, options.closed ?? false, options.maxPixels ?? null, ...character ? [character] : []]);
1365
1671
  const scale = finite2(options.scale) ? options.scale : 1;
1366
1672
  return `${hashString(path).toString(16)}:${path.length}:${hashString(rest2).toString(16)}:${scale}`;
1367
1673
  }
@@ -2012,6 +2318,9 @@ export {
2012
2318
  mix32,
2013
2319
  hash2,
2014
2320
  rand01,
2321
+ randSigned,
2322
+ seedFromString,
2323
+ TileableNoise,
2015
2324
  PAINT_GRADIENT_SPACES,
2016
2325
  PAINT_GRADIENT_REPEATS,
2017
2326
  PAINT_GRADIENT_MAPPINGS,
@@ -2062,6 +2371,12 @@ export {
2062
2371
  applyStrokeToTile,
2063
2372
  applyStrokeToDeepTile,
2064
2373
  coverageTileCoord,
2374
+ GRAIN_PATTERNS,
2375
+ GRAIN_TILE,
2376
+ grainHeights,
2377
+ PaperGrain,
2378
+ grainCatch,
2379
+ strokeGrainCatch,
2065
2380
  pathStrokeDabs,
2066
2381
  pathStrokeCoverage,
2067
2382
  paintPathStroke,
@@ -2096,4 +2411,4 @@ export {
2096
2411
  cleanMixer,
2097
2412
  MixerStroke
2098
2413
  };
2099
- //# sourceMappingURL=chunk-5FSRTP6E.js.map
2414
+ //# sourceMappingURL=chunk-PQFVLOMR.js.map