graphein 0.16.0 → 0.16.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +8 -0
- package/dist/index.js +18 -12
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -354,6 +354,14 @@ declare class RoughPen {
|
|
|
354
354
|
private readonly rng;
|
|
355
355
|
constructor(ctx: RoughContext, style?: Partial<RoughStyle>);
|
|
356
356
|
private resolve;
|
|
357
|
+
/**
|
|
358
|
+
* Run `draw` with `factor` folded into the *ambient* `globalAlpha`, then restore
|
|
359
|
+
* it. Callers honoring a cross-highlight set `ctx.globalAlpha` below 1 to dim a
|
|
360
|
+
* non-selected mark; composing (rather than overwriting and resetting to 1) keeps
|
|
361
|
+
* that dim while still applying the pen's own fill/stroke translucency, so sketch
|
|
362
|
+
* marks dim during a highlight exactly like their solid-rendered counterparts.
|
|
363
|
+
*/
|
|
364
|
+
private withAlpha;
|
|
357
365
|
/** A symmetric random offset in [-x, x], scaled by a length-based gain. */
|
|
358
366
|
private off;
|
|
359
367
|
/**
|
package/dist/index.js
CHANGED
|
@@ -1291,6 +1291,20 @@ var RoughPen = class {
|
|
|
1291
1291
|
resolve(opts) {
|
|
1292
1292
|
return { ...this.base, ...opts };
|
|
1293
1293
|
}
|
|
1294
|
+
/**
|
|
1295
|
+
* Run `draw` with `factor` folded into the *ambient* `globalAlpha`, then restore
|
|
1296
|
+
* it. Callers honoring a cross-highlight set `ctx.globalAlpha` below 1 to dim a
|
|
1297
|
+
* non-selected mark; composing (rather than overwriting and resetting to 1) keeps
|
|
1298
|
+
* that dim while still applying the pen's own fill/stroke translucency, so sketch
|
|
1299
|
+
* marks dim during a highlight exactly like their solid-rendered counterparts.
|
|
1300
|
+
*/
|
|
1301
|
+
withAlpha(factor, draw) {
|
|
1302
|
+
const ctx = this.ctx;
|
|
1303
|
+
const prev = ctx.globalAlpha;
|
|
1304
|
+
ctx.globalAlpha = prev * factor;
|
|
1305
|
+
draw();
|
|
1306
|
+
ctx.globalAlpha = prev;
|
|
1307
|
+
}
|
|
1294
1308
|
/** A symmetric random offset in [-x, x], scaled by a length-based gain. */
|
|
1295
1309
|
off(x, gain) {
|
|
1296
1310
|
return gain * (this.rng() * 2 * x - x);
|
|
@@ -1375,9 +1389,7 @@ var RoughPen = class {
|
|
|
1375
1389
|
ctx.lineCap = "round";
|
|
1376
1390
|
ctx.lineJoin = "round";
|
|
1377
1391
|
ctx.strokeStyle = m.stroke ?? "#000";
|
|
1378
|
-
|
|
1379
|
-
ctx.stroke();
|
|
1380
|
-
ctx.globalAlpha = 1;
|
|
1392
|
+
this.withAlpha(m.strokeAlpha ?? 1, () => ctx.stroke());
|
|
1381
1393
|
}
|
|
1382
1394
|
/** Fill a closed polygon with hachure / cross-hatch / solid. */
|
|
1383
1395
|
fillPolygon(points, m) {
|
|
@@ -1388,9 +1400,7 @@ var RoughPen = class {
|
|
|
1388
1400
|
this.tracePolyline(points, { ...m, roughness: m.roughness * 0.6 }, true);
|
|
1389
1401
|
ctx.closePath();
|
|
1390
1402
|
ctx.fillStyle = m.fill;
|
|
1391
|
-
|
|
1392
|
-
ctx.fill();
|
|
1393
|
-
ctx.globalAlpha = 1;
|
|
1403
|
+
this.withAlpha(m.fillAlpha ?? 1, () => ctx.fill());
|
|
1394
1404
|
return;
|
|
1395
1405
|
}
|
|
1396
1406
|
const gap = m.hachureGap > 0 ? m.hachureGap : Math.max(3, m.strokeWidth * 3.2);
|
|
@@ -1406,9 +1416,7 @@ var RoughPen = class {
|
|
|
1406
1416
|
ctx.lineWidth = weight;
|
|
1407
1417
|
ctx.lineCap = "round";
|
|
1408
1418
|
ctx.strokeStyle = m.fill;
|
|
1409
|
-
|
|
1410
|
-
ctx.stroke();
|
|
1411
|
-
ctx.globalAlpha = 1;
|
|
1419
|
+
this.withAlpha(m.fillAlpha ?? 0.85, () => ctx.stroke());
|
|
1412
1420
|
}
|
|
1413
1421
|
/** Hand-drawn open polyline (axis rules, box-plot whiskers, short features). */
|
|
1414
1422
|
polyline(points, opts = {}) {
|
|
@@ -1482,9 +1490,7 @@ var RoughPen = class {
|
|
|
1482
1490
|
ctx.beginPath();
|
|
1483
1491
|
this.traceSmoothClosed(pts);
|
|
1484
1492
|
ctx.fillStyle = m.fill;
|
|
1485
|
-
|
|
1486
|
-
ctx.fill();
|
|
1487
|
-
ctx.globalAlpha = 1;
|
|
1493
|
+
this.withAlpha(m.fillAlpha ?? 1, () => ctx.fill());
|
|
1488
1494
|
}
|
|
1489
1495
|
if (m.stroke) {
|
|
1490
1496
|
ctx.beginPath();
|