@pixerate/editor 0.267.0 → 0.268.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 (80) hide show
  1. package/dist/animation-editor/index.cjs +62 -62
  2. package/dist/animation-editor/index.js +6 -6
  3. package/dist/brushes/index.cjs +198 -72
  4. package/dist/brushes/index.d.cts +4 -3
  5. package/dist/brushes/index.d.ts +4 -3
  6. package/dist/brushes/index.js +136 -10
  7. package/dist/brushes/library.d.cts +27 -1
  8. package/dist/brushes/library.d.ts +27 -1
  9. package/dist/brushes/profiles.d.cts +4 -0
  10. package/dist/brushes/profiles.d.ts +4 -0
  11. package/dist/brushes/schema.d.cts +4 -0
  12. package/dist/brushes/schema.d.ts +4 -0
  13. package/dist/brushes/sources.d.cts +114 -0
  14. package/dist/brushes/sources.d.ts +114 -0
  15. package/dist/brushes/types.d.cts +37 -5
  16. package/dist/brushes/types.d.ts +37 -5
  17. package/dist/brushes/ui.d.cts +40 -4
  18. package/dist/brushes/ui.d.ts +40 -4
  19. package/dist/{brushstrokeRender-NLFPEBGI.js → brushstrokeRender-A727TTNQ.js} +6 -6
  20. package/dist/{brushstrokeRender-L7JYRR2R.cjs → brushstrokeRender-WR2N5HHY.cjs} +22 -22
  21. package/dist/canvas/index.cjs +13 -13
  22. package/dist/canvas/index.js +1 -1
  23. package/dist/{chunk-J2TNIZ55.cjs → chunk-2WOGXEDX.cjs} +1 -1
  24. package/dist/{chunk-JGWVZPT6.js → chunk-3XDSNIGF.js} +72 -5
  25. package/dist/{chunk-EXB2EGBE.cjs → chunk-62MFUHSI.cjs} +16 -16
  26. package/dist/{chunk-FGJHJIMN.js → chunk-74ODPZLX.js} +10 -10
  27. package/dist/{chunk-GCVFEPJG.js → chunk-ACTHSQOI.js} +182 -0
  28. package/dist/{chunk-LHPEG5AU.cjs → chunk-B3G7BKUV.cjs} +90 -90
  29. package/dist/{chunk-EF7LZAXQ.js → chunk-BAZMCFVL.js} +1 -1
  30. package/dist/{chunk-HIO6E7LC.cjs → chunk-BPJSI4NT.cjs} +2 -2
  31. package/dist/{chunk-XVOP3CGQ.cjs → chunk-EU2ZZA6L.cjs} +393 -62
  32. package/dist/{chunk-YIC6MAJ2.js → chunk-HFY5LG5J.js} +1 -1
  33. package/dist/{chunk-7UKFXXWL.js → chunk-HVO6XCI4.js} +1 -1
  34. package/dist/{chunk-OKHKA43L.cjs → chunk-JBB3GDBB.cjs} +330 -216
  35. package/dist/{chunk-AGNUD5BI.js → chunk-KZI3YWKW.js} +351 -20
  36. package/dist/{chunk-EYSHTYLG.js → chunk-LETF75CA.js} +1 -1
  37. package/dist/{chunk-FQPUF2W2.cjs → chunk-NIBFKXMD.cjs} +217 -35
  38. package/dist/{chunk-G7NHE2VD.cjs → chunk-NPWWSCWT.cjs} +35 -35
  39. package/dist/{chunk-OSEXT7JL.js → chunk-QNY7BDFP.js} +1 -1
  40. package/dist/{chunk-PXDIAYB6.cjs → chunk-STLTOISW.cjs} +34 -214
  41. package/dist/{chunk-4IDUYB45.js → chunk-UVTO3D4E.js} +130 -16
  42. package/dist/{chunk-TXFWZ5ZJ.js → chunk-W6JDUXP3.js} +4 -184
  43. package/dist/{chunk-LA5Y4ETA.cjs → chunk-YOVXQHA3.cjs} +23 -23
  44. package/dist/{chunk-DT4YQUGT.cjs → chunk-YXP6X3SY.cjs} +101 -34
  45. package/dist/image-editor/index.cjs +851 -851
  46. package/dist/image-editor/index.js +23 -23
  47. package/dist/paint/index.cjs +5 -5
  48. package/dist/paint/index.js +11 -11
  49. package/dist/paint-editor/brush-library-tools.d.cts +12 -2
  50. package/dist/paint-editor/brush-library-tools.d.ts +12 -2
  51. package/dist/paint-editor/brush-model.d.cts +29 -1
  52. package/dist/paint-editor/brush-model.d.ts +29 -1
  53. package/dist/paint-editor/brush-source-art.d.cts +32 -0
  54. package/dist/paint-editor/brush-source-art.d.ts +32 -0
  55. package/dist/paint-editor/controller.d.cts +6 -1
  56. package/dist/paint-editor/controller.d.ts +6 -1
  57. package/dist/paint-editor/dab-stroke.d.cts +2 -0
  58. package/dist/paint-editor/dab-stroke.d.ts +2 -0
  59. package/dist/paint-editor/engine.d.cts +11 -2
  60. package/dist/paint-editor/engine.d.ts +11 -2
  61. package/dist/paint-editor/index.cjs +576 -481
  62. package/dist/paint-editor/index.d.cts +3 -1
  63. package/dist/paint-editor/index.d.ts +3 -1
  64. package/dist/paint-editor/index.js +127 -32
  65. package/dist/paint-editor/stamp-tip.d.cts +8 -5
  66. package/dist/paint-editor/stamp-tip.d.ts +8 -5
  67. package/dist/paint-editor/thumbnails.d.cts +6 -0
  68. package/dist/paint-editor/thumbnails.d.ts +6 -0
  69. package/dist/paint-editor/tip-grain.d.cts +34 -0
  70. package/dist/paint-editor/tip-grain.d.ts +34 -0
  71. package/dist/raster/index.cjs +2 -2
  72. package/dist/raster/index.js +9 -9
  73. package/dist/vector/index.cjs +1002 -1002
  74. package/dist/vector/index.js +7 -7
  75. package/package.json +1 -1
  76. package/skills/pixerate-brushes/SKILL.md +35 -8
  77. package/skills/pixerate-brushes-design/SKILL.md +8 -1
  78. package/skills/pixerate-paint-editor/SKILL.md +6 -0
  79. package/skills/pixerate-paint-editor/references/brush-facets.md +3 -1
  80. package/skills/pixerate-paint-sketch-to-finish/SKILL.md +1 -0
@@ -4,10 +4,11 @@ import {
4
4
  VECTOR_PROFILE,
5
5
  checkBrush,
6
6
  closest,
7
+ isBrushSourceRef,
7
8
  listPresets,
8
9
  normalizeBrushSpec,
9
10
  resolveBrush
10
- } from "./chunk-AGNUD5BI.js";
11
+ } from "./chunk-KZI3YWKW.js";
11
12
  import {
12
13
  editorStampOf,
13
14
  stampCoverage
@@ -75,24 +76,24 @@ import {
75
76
  } from "./chunk-GSTSZPSR.js";
76
77
  import {
77
78
  BrushstrokeCache,
78
- GRAIN_PATTERNS,
79
- PaperGrain,
80
79
  brushstrokeDataUrl,
81
80
  brushstrokeSamples,
82
- grainCatch,
83
81
  isBrushstrokeBrush
84
- } from "./chunk-TXFWZ5ZJ.js";
82
+ } from "./chunk-W6JDUXP3.js";
85
83
  import {
86
84
  CoverageMap,
87
85
  EMPTY_MIXER_LOAD,
86
+ GRAIN_PATTERNS,
88
87
  PaintExchange,
89
88
  PaintGradientSampler,
89
+ PaperGrain,
90
90
  SmudgeTip,
91
91
  TileMedium,
92
92
  blenderDab,
93
93
  createBlenderScratch,
94
94
  dabRect,
95
95
  exchangeRates,
96
+ grainCatch,
96
97
  loadMixer,
97
98
  mixerRates,
98
99
  parsePaintSource,
@@ -100,7 +101,7 @@ import {
100
101
  readPaintSource,
101
102
  resolvePaintGradient,
102
103
  scalePaintGradient
103
- } from "./chunk-GCVFEPJG.js";
104
+ } from "./chunk-ACTHSQOI.js";
104
105
  import {
105
106
  rand01,
106
107
  randSigned
@@ -2726,7 +2727,18 @@ function effectDabField(img, rect, cov, centre, mixed, field, steps = 0, dab = n
2726
2727
 
2727
2728
  // src/paint-editor/stamp-tip.ts
2728
2729
  var samplers = /* @__PURE__ */ new WeakMap();
2729
- function stampSampler(ref, art) {
2730
+ function stampSampler(ref, art, hardness = 1) {
2731
+ const sampler = baseSampler(ref, art);
2732
+ if (!sampler || hardness >= 1 || !isBrushSourceRef(ref)) return sampler;
2733
+ const h = Math.max(0, hardness);
2734
+ return (u, v2, seed) => {
2735
+ const r = Math.hypot(u, v2) / Math.SQRT2;
2736
+ if (r <= h) return sampler(u, v2, seed);
2737
+ const t = Math.min(1, (r - h) / (1 - h));
2738
+ return sampler(u, v2, seed) * (1 - t * t * (3 - 2 * t));
2739
+ };
2740
+ }
2741
+ function baseSampler(ref, art) {
2730
2742
  let kind = null;
2731
2743
  try {
2732
2744
  kind = editorStampOf(ref.includes(":") ? ref : `editor:${ref}`);
@@ -2771,6 +2783,8 @@ function rasterizeStampDab(d, sample, seed, rect, out) {
2771
2783
  const sn = Math.sin(d.angle);
2772
2784
  const cs = Math.cos(d.angle);
2773
2785
  const ss = r < 6 ? 3 : 1;
2786
+ const fu = d.flip && d.flip & 1 ? -1 : 1;
2787
+ const fv = d.flip && d.flip & 2 ? -1 : 1;
2774
2788
  for (let yy = 0; yy < h; yy++) {
2775
2789
  for (let xx = 0; xx < w; xx++) {
2776
2790
  let sum = 0;
@@ -2778,8 +2792,8 @@ function rasterizeStampDab(d, sample, seed, rect, out) {
2778
2792
  for (let sx = 0; sx < ss; sx++) {
2779
2793
  const dx = rect.x + xx + (sx + 0.5) / ss - d.x;
2780
2794
  const dy = rect.y + yy + (sy + 0.5) / ss - d.y;
2781
- const u = (dx * cs - dy * sn) / r;
2782
- const v2 = (dx * sn + dy * cs) / (r * ro);
2795
+ const u = (dx * cs - dy * sn) / r * fu;
2796
+ const v2 = (dx * sn + dy * cs) / (r * ro) * fv;
2783
2797
  if (u > -1.05 && u < 1.05 && v2 > -1.05 && v2 < 1.05) sum += sample(u, v2, seed);
2784
2798
  }
2785
2799
  }
@@ -2790,7 +2804,7 @@ function rasterizeStampDab(d, sample, seed, rect, out) {
2790
2804
  }
2791
2805
  function brushStickerRefs(brush) {
2792
2806
  const refs = brush.engine === "sticker" ? [...brush.sticker.stamps] : brush.engine === "particle" ? [...brush.particle.dotTextures] : brush.engine === "dab" && brush.stamp ? [brush.stamp] : [];
2793
- return [...new Set(refs.filter((r) => r.includes(":") && !r.startsWith("editor:")))];
2807
+ return [...new Set(refs.filter((r) => r.includes(":") && !r.startsWith("editor:") && !isBrushSourceRef(r)))];
2794
2808
  }
2795
2809
  function sprayDroplets(d, spray, seed) {
2796
2810
  const count = 1 + Math.round(spray.density * 31);
@@ -2936,6 +2950,86 @@ function renderPaper(paper, rect, grain = new PaperGrain(paper), light) {
2936
2950
  return out;
2937
2951
  }
2938
2952
 
2953
+ // src/paint-editor/tip-grain.ts
2954
+ var ImageGrain = class {
2955
+ constructor(w, h, alpha, contrast, invert2, scale3) {
2956
+ this.w = w;
2957
+ this.h = h;
2958
+ this.scale = scale3;
2959
+ this.heights = new Float32Array(w * h);
2960
+ for (let i = 0; i < w * h; i++) {
2961
+ const v2 = Math.min(1, Math.max(0, (alpha[i * 4 + 3] / 255 - 0.5) * contrast + 0.5));
2962
+ this.heights[i] = invert2 ? 1 - v2 : v2;
2963
+ }
2964
+ }
2965
+ w;
2966
+ h;
2967
+ scale;
2968
+ heights;
2969
+ at(x, y) {
2970
+ const { w, h } = this;
2971
+ const u = x / this.scale - 0.5;
2972
+ const v2 = y / this.scale - 0.5;
2973
+ const x0 = Math.floor(u);
2974
+ const y0 = Math.floor(v2);
2975
+ const fx = u - x0;
2976
+ const fy = v2 - y0;
2977
+ const xa = (x0 % w + w) % w;
2978
+ const ya = (y0 % h + h) % h;
2979
+ const xb = (xa + 1) % w;
2980
+ const yb = (ya + 1) % h;
2981
+ const hs = this.heights;
2982
+ return (hs[ya * w + xa] * (1 - fx) + hs[ya * w + xb] * fx) * (1 - fy) + (hs[yb * w + xa] * (1 - fx) + hs[yb * w + xb] * fx) * fy;
2983
+ }
2984
+ };
2985
+ var TipGrain = class _TipGrain {
2986
+ constructor(field, settings) {
2987
+ this.field = field;
2988
+ this.settings = settings;
2989
+ }
2990
+ field;
2991
+ settings;
2992
+ /**
2993
+ * The grain for `settings`, or `null` when there is none to apply: no depth, or an image source
2994
+ * whose art is not loaded (the dabs then paint without it).
2995
+ */
2996
+ static create(settings, art) {
2997
+ if (!settings || settings.depth <= 0) return null;
2998
+ if (GRAIN_PATTERNS.includes(settings.source)) {
2999
+ if (settings.source === "smooth") return null;
3000
+ const tuning2 = { contrast: settings.contrast, invert: settings.invert };
3001
+ const paper = new PaperGrain({ pattern: settings.source, seed: 0, scale: settings.scale, tiling: "repeat", dry: tuning2, wet: tuning2 });
3002
+ return new _TipGrain(paper, settings);
3003
+ }
3004
+ const a = art?.(settings.source);
3005
+ if (!a || !(a.width > 0 && a.height > 0)) return null;
3006
+ return new _TipGrain(new ImageGrain(a.width, a.height, a.data, settings.contrast, settings.invert, settings.scale), settings);
3007
+ }
3008
+ /** Multiplies the dab's coverage `vals` (over `rect`) by the grain. */
3009
+ apply(vals, rect, d) {
3010
+ const depth = this.settings.depth;
3011
+ const moving = this.settings.mode === "moving";
3012
+ const cs = Math.cos(d.angle);
3013
+ const sn = Math.sin(d.angle);
3014
+ for (let yy = 0, k = 0; yy < rect.height; yy++) {
3015
+ const py = rect.y + yy + 0.5;
3016
+ for (let xx = 0; xx < rect.width; xx++, k++) {
3017
+ if (!(vals[k] > 0)) continue;
3018
+ const px = rect.x + xx + 0.5;
3019
+ let gx = px;
3020
+ let gy = py;
3021
+ if (moving) {
3022
+ const dx = px - d.x;
3023
+ const dy = py - d.y;
3024
+ gx = dx * cs - dy * sn + d.travel;
3025
+ gy = dx * sn + dy * cs;
3026
+ }
3027
+ vals[k] *= 1 - depth * (1 - this.field.at(gx, gy));
3028
+ }
3029
+ }
3030
+ }
3031
+ };
3032
+
2939
3033
  // src/paint-editor/engine.ts
2940
3034
  function penOrientation(p) {
2941
3035
  if (typeof p.altitude === "number" && Number.isFinite(p.altitude)) {
@@ -3075,7 +3169,13 @@ var PenDabWalker = class {
3075
3169
  x += Math.sin(this.dir) * off;
3076
3170
  y += Math.cos(this.dir) * off;
3077
3171
  }
3172
+ let flip = 0;
3173
+ if (dyn.flip && dyn.flip !== "none") {
3174
+ if (dyn.flip !== "y" && rand01(seed, i, 5 /* FlipX */) < 0.5) flip |= 1;
3175
+ if (dyn.flip !== "x" && rand01(seed, i, 6 /* FlipY */) < 0.5) flip |= 2;
3176
+ }
3078
3177
  return {
3178
+ ...flip ? { flip } : {},
3079
3179
  x,
3080
3180
  y,
3081
3181
  radius: Math.max(0.5, diameter / 2),
@@ -3106,7 +3206,7 @@ var PenDabWalker = class {
3106
3206
  const len2 = Math.hypot(dx, dy);
3107
3207
  if (len2 > 1e-9) this.dir = Math.atan2(-dy, dx);
3108
3208
  if (this.pendingFirst) {
3109
- out.push(this.dab(this.pendingFirst));
3209
+ this.lay(this.pendingFirst, out);
3110
3210
  this.pendingFirst = null;
3111
3211
  }
3112
3212
  if (len2 > 1e-9) {
@@ -3124,7 +3224,7 @@ var PenDabWalker = class {
3124
3224
  travel: a.travel + this.nextAt,
3125
3225
  time: a.time !== null && s.time !== null ? lerp4(a.time, s.time) : s.time
3126
3226
  };
3127
- out.push(this.dab(q));
3227
+ this.lay(q, out);
3128
3228
  this.nextAt += this.stepLen(q);
3129
3229
  }
3130
3230
  this.nextAt -= len2;
@@ -3133,10 +3233,15 @@ var PenDabWalker = class {
3133
3233
  }
3134
3234
  finish(out) {
3135
3235
  if (this.pendingFirst) {
3136
- out.push(this.dab(this.pendingFirst));
3236
+ this.lay(this.pendingFirst, out);
3137
3237
  this.pendingFirst = null;
3138
3238
  }
3139
3239
  }
3240
+ /** The dabs of one spacing step: `dynamics.count` of them, each with its own index and so its own jitter. */
3241
+ lay(s, out) {
3242
+ const n = this.brush.dynamics.count ?? 1;
3243
+ for (let k = 0; k < n; k++) out.push(this.dab(s));
3244
+ }
3140
3245
  };
3141
3246
  function lerpAngle(a, b, t) {
3142
3247
  let d = b - a;
@@ -3154,7 +3259,8 @@ var DryStroke = class {
3154
3259
  constructor(brush, options) {
3155
3260
  this.brush = brush;
3156
3261
  this.options = options;
3157
- this.stamp = brush.stamp ? stampSampler(brush.stamp, options.stampArt) : null;
3262
+ this.stamp = brush.stamp ? stampSampler(brush.stamp, options.stampArt, brush.tip.hardness) : null;
3263
+ this.tipGrain = TipGrain.create(brush.tipGrain, options.stampArt);
3158
3264
  this.smoother = new PenSmoother(brush.tip.smoothing, brush.pressureSmoothing);
3159
3265
  this.copies = options.copies?.length ? options.copies : [IDENTITY_COPY];
3160
3266
  this.walkers = this.copies.map((c, i) => new PenDabWalker(brush, (options.seed ?? 0) + i * 7919 | 0, c.linear));
@@ -3174,6 +3280,8 @@ var DryStroke = class {
3174
3280
  lastFed = null;
3175
3281
  /** The stamp tip's shape, or `null` for the round computed tip. */
3176
3282
  stamp;
3283
+ /** The tip's own grain, or `null`. */
3284
+ tipGrain;
3177
3285
  /** Feeds raw pen samples; returns the document rectangles the new dabs touched. */
3178
3286
  push(points) {
3179
3287
  const dabs = [];
@@ -3207,7 +3315,7 @@ var DryStroke = class {
3207
3315
  }
3208
3316
  return rects;
3209
3317
  }
3210
- /** Lays one mark (a dab, or a spray droplet of dab `d`): the round tip or the stamp, the paper grain, effect paint. */
3318
+ /** Lays one mark (a dab, or a spray droplet of dab `d`): the round tip or the stamp, the tip grain, the paper grain, effect paint. */
3211
3319
  mark(m, d, rects) {
3212
3320
  const hardness = this.brush.tip.hardness;
3213
3321
  const grain = this.options.grain;
@@ -3217,6 +3325,7 @@ var DryStroke = class {
3217
3325
  const vals = this.buf.subarray(0, n);
3218
3326
  if (this.stamp) rasterizeStampDab(m, this.stamp, d.index, rect, vals);
3219
3327
  else rasterizeDab(m, hardness, rect, vals);
3328
+ this.tipGrain?.apply(vals, rect, { x: m.x, y: m.y, angle: m.angle, travel: d.travel });
3220
3329
  if (this.depth > 0 && grain) {
3221
3330
  for (let yy = 0, k = 0; yy < rect.height; yy++) {
3222
3331
  const y = rect.y + yy + 0.5;
@@ -3294,7 +3403,8 @@ var PaintDabStroke = class {
3294
3403
  constructor(brush, options) {
3295
3404
  this.brush = brush;
3296
3405
  this.options = options;
3297
- this.stamp = brush.engine === "dab" && brush.stamp ? stampSampler(brush.stamp, options.stampArt) : null;
3406
+ this.stamp = brush.engine === "dab" && brush.stamp ? stampSampler(brush.stamp, options.stampArt, brush.tip.hardness) : null;
3407
+ this.tipGrain = TipGrain.create(brush.tipGrain, options.stampArt);
3298
3408
  this.smoother = new PenSmoother(brush.tip.smoothing, brush.pressureSmoothing);
3299
3409
  this.copies = options.copies?.length ? options.copies : [IDENTITY_COPY];
3300
3410
  const exchanging = brush.engine === "mixer" || brush.engine === "dab";
@@ -3340,6 +3450,8 @@ var PaintDabStroke = class {
3340
3450
  lastFed = null;
3341
3451
  /** The stamp tip's shape (dab brushes), or `null` for the round computed tip. */
3342
3452
  stamp;
3453
+ /** The tip's own grain, or `null`. */
3454
+ tipGrain;
3343
3455
  /** What copy 0's brush carries after the dabs so far (mixer and wet-capable dab brushes). */
3344
3456
  get load() {
3345
3457
  return this.states[0].exchange?.load ?? null;
@@ -3392,6 +3504,7 @@ var PaintDabStroke = class {
3392
3504
  tip.fill(0);
3393
3505
  if (this.stamp) rasterizeStampDab({ ...d, alpha: 1 }, this.stamp, d.index, rect, tip);
3394
3506
  else rasterizeDab({ ...d, alpha: 1 }, this.brush.tip.hardness, rect, tip);
3507
+ this.tipGrain?.apply(tip, rect, d);
3395
3508
  if (!(this.depth > 0 && this.options.grain)) return { tip, cov: tip };
3396
3509
  const cov = this.cov.subarray(0, n);
3397
3510
  const grain = this.options.grain;
@@ -12971,6 +13084,7 @@ export {
12971
13084
  normalizePaper,
12972
13085
  hexToRgb8,
12973
13086
  renderPaper,
13087
+ TipGrain,
12974
13088
  penOrientation,
12975
13089
  tiltToOrientation,
12976
13090
  PenSmoother,
@@ -1,6 +1,7 @@
1
1
  import {
2
2
  CoverageMap,
3
3
  PaintGradientSampler,
4
+ PaperGrain,
4
5
  TIP_GRADIENT_STEPS,
5
6
  applyStrokeToTile,
6
7
  dabRect,
@@ -9,11 +10,10 @@ import {
9
10
  normalizeBrush,
10
11
  rasterizeDab,
11
12
  resolvePaintGradient,
12
- scalePaintGradient
13
- } from "./chunk-GCVFEPJG.js";
13
+ scalePaintGradient,
14
+ strokeGrainCatch
15
+ } from "./chunk-ACTHSQOI.js";
14
16
  import {
15
- TileableNoise,
16
- hash2,
17
17
  randSigned
18
18
  } from "./chunk-4D6KP5BV.js";
19
19
  import {
@@ -34,180 +34,6 @@ import {
34
34
  tilesInRect
35
35
  } from "./chunk-HVVR5PZW.js";
36
36
 
37
- // src/paint/grain.ts
38
- var GRAIN_PATTERNS = ["smooth", "cold-pressed", "hot-pressed", "rough", "vellum", "laid", "ingres", "sanded", "canvas", "linen", "gesso"];
39
- var GRAIN_TILE = 256;
40
- var clamp01 = (v) => v < 0 ? 0 : v > 1 ? 1 : v;
41
- function patternHeights(pattern, n, seed) {
42
- const out = new Float32Array(n * n);
43
- const salt = Math.imul(seed | 0, 2654435761) + 17;
44
- if (pattern === "smooth") return out.fill(1);
45
- const noise = (cx, cy, oct, s = 0) => new TileableNoise(n, cx, cy, oct, salt + s);
46
- const k = n / GRAIN_TILE;
47
- switch (pattern) {
48
- case "cold-pressed": {
49
- const base = noise(20 * k, 20 * k, 4);
50
- const fine = noise(64 * k, 64 * k, 2, 3);
51
- for (let y = 0; y < n; y++)
52
- 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);
53
- break;
54
- }
55
- case "hot-pressed": {
56
- const base = noise(40 * k, 40 * k, 3);
57
- 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);
58
- break;
59
- }
60
- case "rough": {
61
- const base = noise(10 * k, 10 * k, 5);
62
- const blot = noise(28 * k, 28 * k, 2, 5);
63
- for (let y = 0; y < n; y++)
64
- 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);
65
- break;
66
- }
67
- case "vellum": {
68
- const base = noise(40 * k, 40 * k, 3);
69
- 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);
70
- break;
71
- }
72
- case "laid": {
73
- const pulp = noise(32 * k, 32 * k, 3);
74
- const chain = n / 8;
75
- for (let y = 0; y < n; y++) {
76
- const laid = 0.5 + 0.5 * Math.cos(2 * Math.PI * y / 4);
77
- for (let x = 0; x < n; x++) {
78
- const c = Math.abs((x + 0.5) % chain - chain / 2) / (chain / 2);
79
- const chainLine = c > 0.94 ? -0.35 : 0;
80
- out[y * n + x] = clamp01(0.3 + 0.5 * laid + chainLine + (pulp.at(x, y) - 0.5) * 0.6);
81
- }
82
- }
83
- break;
84
- }
85
- case "ingres": {
86
- const fibres = noise(64 * k, 12 * k, 3);
87
- const base = noise(16 * k, 16 * k, 3, 7);
88
- for (let y = 0; y < n; y++)
89
- for (let x = 0; x < n; x++) {
90
- const g = hash2(x, y, salt ^ 85);
91
- 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));
92
- }
93
- break;
94
- }
95
- case "sanded": {
96
- const grit = noise(96 * k, 96 * k, 2);
97
- for (let y = 0; y < n; y++)
98
- for (let x = 0; x < n; x++) {
99
- const h = hash2(x, y, salt);
100
- out[y * n + x] = clamp01((grit.at(x, y) - 0.5) * 2.4 + 0.5 + (h - 0.5) * 0.7);
101
- }
102
- break;
103
- }
104
- case "canvas":
105
- case "linen": {
106
- const period = (pattern === "canvas" ? 8 : 5) * k;
107
- const threads = Math.max(2, 2 * Math.round(n / period / 2));
108
- const p = n / threads;
109
- const slub = noise(threads, threads, 2, 11);
110
- for (let y = 0; y < n; y++)
111
- for (let x = 0; x < n; x++) {
112
- const fx = (x + 0.5) / p;
113
- const fy = (y + 0.5) / p;
114
- const cx = Math.floor(fx);
115
- const cy = Math.floor(fy);
116
- const warp = Math.sin(Math.PI * (fx - cx));
117
- const weft = Math.sin(Math.PI * (fy - cy));
118
- const top = (cx + cy) % 2 === 0 ? warp : weft;
119
- const irregular = pattern === "linen" ? (slub.at(x, y) - 0.5) * 0.5 : 0;
120
- out[y * n + x] = clamp01(0.2 + 0.7 * top + irregular + (hash2(x, y, salt) - 0.5) * 0.15);
121
- }
122
- break;
123
- }
124
- case "gesso": {
125
- const streaks = noise(2 * k, 28 * k, 3);
126
- const tooth = noise(64 * k, 64 * k, 2, 13);
127
- for (let y = 0; y < n; y++)
128
- 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);
129
- break;
130
- }
131
- }
132
- return out;
133
- }
134
- var rawCache = /* @__PURE__ */ new Map();
135
- function grainHeights(pattern, seed, size = GRAIN_TILE) {
136
- const key = `${pattern}:${seed}:${size}`;
137
- let h = rawCache.get(key);
138
- if (!h) {
139
- h = patternHeights(pattern, size, seed);
140
- if (rawCache.size > 32) rawCache.delete(rawCache.keys().next().value);
141
- rawCache.set(key, h);
142
- }
143
- return h;
144
- }
145
- var PaperGrain = class {
146
- size = GRAIN_TILE;
147
- heights;
148
- scale;
149
- mirror;
150
- ox;
151
- oy;
152
- flat;
153
- constructor(paper, media = "dry") {
154
- const raw = grainHeights(paper.pattern, paper.seed);
155
- const t = paper[media];
156
- this.flat = paper.pattern === "smooth";
157
- if (t.contrast === 1 && !t.invert) this.heights = raw;
158
- else {
159
- const out = new Float32Array(raw.length);
160
- for (let i = 0; i < raw.length; i++) {
161
- const v = clamp01((raw[i] - 0.5) * t.contrast + 0.5);
162
- out[i] = t.invert ? 1 - v : v;
163
- }
164
- this.heights = out;
165
- }
166
- this.scale = paper.scale;
167
- this.mirror = paper.tiling === "mirror";
168
- this.ox = paper.offset?.x ?? 0;
169
- this.oy = paper.offset?.y ?? 0;
170
- }
171
- /** Tile cell index for a coordinate in grain pixels (mirrored on odd tiles when mirroring). */
172
- wrap(v) {
173
- const n = this.size;
174
- if (!this.mirror) return (v % n + n) % n;
175
- const p = (v % (2 * n) + 2 * n) % (2 * n);
176
- return p < n ? p : 2 * n - 1 - p;
177
- }
178
- /** Height 0..1 at document position (x, y). */
179
- at(x, y) {
180
- const u = (x - this.ox) / this.scale - 0.5;
181
- const v = (y - this.oy) / this.scale - 0.5;
182
- const x0 = Math.floor(u);
183
- const y0 = Math.floor(v);
184
- const fx = u - x0;
185
- const fy = v - y0;
186
- const n = this.size;
187
- const h = this.heights;
188
- const a = this.wrap(x0);
189
- const b = this.wrap(x0 + 1);
190
- const c = this.wrap(y0) * n;
191
- const d = this.wrap(y0 + 1) * n;
192
- const top = h[c + a] + (h[c + b] - h[c + a]) * fx;
193
- const bot = h[d + a] + (h[d + b] - h[d + a]) * fx;
194
- return top + (bot - top) * fy;
195
- }
196
- };
197
- function grainCatch(h, depth, pressure) {
198
- if (depth <= 0) return 1;
199
- const t = depth * (0.75 - 0.65 * Math.min(1, Math.max(0, pressure)));
200
- const u = clamp01((h - t + 0.18) / 0.36);
201
- return 1 - depth + depth * u * u * (3 - 2 * u);
202
- }
203
- function strokeGrainCatch(h, depth, pressure) {
204
- if (depth <= 0) return 1;
205
- const p = Math.min(1, Math.max(0, pressure));
206
- const amount = Math.min(1, depth * (1.4 - 0.6 * p));
207
- const u = clamp01((h - 0.2 - 0.25 * (1 - p)) / 0.5);
208
- return 1 - amount + amount * u * u * (3 - 2 * u);
209
- }
210
-
211
37
  // src/paint/path-stroke.ts
212
38
  var JITTER_SIZE = 1;
213
39
  var JITTER_ANGLE = 2;
@@ -574,12 +400,6 @@ var BrushstrokeCache = class {
574
400
  };
575
401
 
576
402
  export {
577
- GRAIN_PATTERNS,
578
- GRAIN_TILE,
579
- grainHeights,
580
- PaperGrain,
581
- grainCatch,
582
- strokeGrainCatch,
583
403
  pathStrokeDabs,
584
404
  pathStrokeCoverage,
585
405
  paintPathStroke,
@@ -5,7 +5,7 @@
5
5
 
6
6
 
7
7
 
8
- var _chunkOKHKA43Lcjs = require('./chunk-OKHKA43L.cjs');
8
+ var _chunkJBB3GDBBcjs = require('./chunk-JBB3GDBB.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 = _chunkOKHKA43Lcjs.subpathSegment.call(void 0, sp, i);
1364
+ const s = _chunkJBB3GDBBcjs.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) => _chunkOKHKA43Lcjs.subpathSegment.call(void 0, sp, i).length === 2;
1369
+ var isLine = (sp, i) => _chunkJBB3GDBBcjs.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 = _chunkOKHKA43Lcjs.cloneAnchor.call(void 0, a);
1389
+ const next = _chunkJBB3GDBBcjs.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 = _chunkOKHKA43Lcjs.inferAnchorType.call(void 0, next);
1392
+ const shown = _chunkJBB3GDBBcjs.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(_chunkOKHKA43Lcjs.cloneAnchor);
1436
+ const anchors = sp.anchors.map(_chunkJBB3GDBBcjs.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(_chunkOKHKA43Lcjs.cloneAnchor), closed: sp.closed });
1470
+ return order.reduce((acc, i) => removeAnchorKeepingShape(acc, i), { anchors: sp.anchors.map(_chunkJBB3GDBBcjs.cloneAnchor), closed: sp.closed });
1471
1471
  }
1472
1472
  function bendSegment(sp, segment, t, p) {
1473
- const anchors = sp.anchors.map(_chunkOKHKA43Lcjs.cloneAnchor);
1473
+ const anchors = sp.anchors.map(_chunkJBB3GDBBcjs.cloneAnchor);
1474
1474
  const n = anchors.length;
1475
- if (segment < 0 || segment >= _chunkOKHKA43Lcjs.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 >= _chunkJBB3GDBBcjs.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] = _chunkOKHKA43Lcjs.moveAnchorHandle.call(void 0, a, "out", c1);
1487
- anchors[ib] = _chunkOKHKA43Lcjs.moveAnchorHandle.call(void 0, b, "in", c2);
1486
+ anchors[ia] = _chunkJBB3GDBBcjs.moveAnchorHandle.call(void 0, a, "out", c1);
1487
+ anchors[ib] = _chunkJBB3GDBBcjs.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, _chunkOKHKA43Lcjs.subpathSegment.call(void 0, sp, segment), t);
1491
+ const [x, y] = _chunkGF2RBSDMcjs.segmentPoint.call(void 0, _chunkJBB3GDBBcjs.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(_chunkOKHKA43Lcjs.cloneAnchor);
1495
+ const anchors = sp.anchors.map(_chunkJBB3GDBBcjs.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(_chunkOKHKA43Lcjs.cloneAnchor), closed: sp.closed }];
1541
+ if (!cuts.length || n < 2) return [{ anchors: sp.anchors.map(_chunkJBB3GDBBcjs.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(_chunkOKHKA43Lcjs.cloneAnchor.call(void 0, a));
1549
+ cur.push(_chunkJBB3GDBBcjs.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 >= _chunkOKHKA43Lcjs.subpathSegmentCount.call(void 0, sp)) return [{ anchors: sp.anchors.map(_chunkOKHKA43Lcjs.cloneAnchor), closed: sp.closed }];
1564
+ if (segment < 0 || segment >= _chunkJBB3GDBBcjs.subpathSegmentCount.call(void 0, sp)) return [{ anchors: sp.anchors.map(_chunkJBB3GDBBcjs.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 } = _chunkOKHKA43Lcjs.insertAnchor.call(void 0, sp, segment, t);
1567
+ const { subpath, index } = _chunkJBB3GDBBcjs.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(_chunkOKHKA43Lcjs.cloneAnchor), closed: sp.closed };
1590
+ const copy = { anchors: sp.anchors.map(_chunkJBB3GDBBcjs.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(_chunkOKHKA43Lcjs.cloneAnchor);
1645
+ const anchors = orig.map(_chunkJBB3GDBBcjs.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 < _chunkOKHKA43Lcjs.subpathSegmentCount.call(void 0, sp); i++) {
1675
- const s = _chunkOKHKA43Lcjs.subpathSegment.call(void 0, sp, i);
1674
+ for (let i = 0; i < _chunkJBB3GDBBcjs.subpathSegmentCount.call(void 0, sp); i++) {
1675
+ const s = _chunkJBB3GDBBcjs.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(_chunkOKHKA43Lcjs.cloneAnchor), closed: sp.closed };
1732
+ if (!segs.length) return { anchors: sp.anchors.map(_chunkJBB3GDBBcjs.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(_chunkOKHKA43Lcjs.cloneAnchor), closed: sp.closed }));
1750
+ return _nullishCoalesce(segsToSubpath(segs, sp.closed, types), () => ( { anchors: sp.anchors.map(_chunkJBB3GDBBcjs.cloneAnchor), closed: sp.closed }));
1751
1751
  }
1752
1752
 
1753
1753