@stocksharp/diagram 1.3.0 → 1.4.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.
@@ -1,5 +1,5 @@
1
1
  import { SvgSurface } from './svg-surface.js';
2
- import { readableOutlineOn, readableTextOn } from './color.js';
2
+ import { cappedLightness, legibleOn, readableOutlineOn, readableTextOn } from './color.js';
3
3
  // Internal dependency-free canvas renderer used by StockSharpDiagram.
4
4
  //
5
5
  // Dependency-free, pure 2D canvas. Demonstrates the hard parts: typed
@@ -202,10 +202,7 @@ function hashHue(s) {
202
202
  // wash out; a light theme passes a low ceiling to darken the links just enough to stay readable
203
203
  // while keeping each hue distinct. Non-hsl inputs are returned untouched.
204
204
  function clampLightness(color, maxL) {
205
- const m = color.match(/^hsl\(\s*([\d.]+)\s*,\s*([\d.]+)%\s*,\s*([\d.]+)%\s*\)$/i);
206
- if (m === null)
207
- return color;
208
- return `hsl(${m[1]}, ${m[2]}%, ${Math.min(+m[3], maxL * 100)}%)`;
205
+ return cappedLightness(color, maxL);
209
206
  }
210
207
  function colorLuminance(color) {
211
208
  if (color === undefined)
@@ -1691,6 +1688,15 @@ export class Diagram {
1691
1688
  return p.type;
1692
1689
  return this.portFeed.get(p) ?? p.type;
1693
1690
  }
1691
+ /// A type's colour as a wire.
1692
+ ///
1693
+ /// The same colour a socket of that type is filled with, moved into the band the canvas
1694
+ /// leaves room for. A socket can afford the host's exact colour because it is a filled
1695
+ /// square with an outline; a wire is a thin line with nothing behind it, and one drawn in
1696
+ /// #000000 on a dark canvas is not there at all.
1697
+ linkColor(type) {
1698
+ return legibleOn(this.portColor(type), this.opts.background ?? '#1b1b1f');
1699
+ }
1694
1700
  portColor(type) {
1695
1701
  const maxL = this.opts.linkMaxLightness;
1696
1702
  const light = maxL !== undefined && maxL < 0.5;
@@ -2710,7 +2716,7 @@ export class Diagram {
2710
2716
  continue;
2711
2717
  const fp = this.nodes.find((n) => n.id === l.from)?.outPorts.find((p) => p.id === l.fromPort);
2712
2718
  const baseColor = (this.opts.typedLinkColors ?? false) && fp !== undefined
2713
- ? this.portColor(fp.type)
2719
+ ? this.linkColor(fp.type)
2714
2720
  : this.portColor('');
2715
2721
  const state = options.selection && l === this.selectedLink
2716
2722
  ? 'sel'
@@ -3225,7 +3231,7 @@ export class Diagram {
3225
3231
  if (snapped !== null)
3226
3232
  excludedNodes.add(snapped.node.id);
3227
3233
  const points = this.routeLink(a, b, excludedNodes);
3228
- ctx.strokeStyle = this.portColor(colorType);
3234
+ ctx.strokeStyle = this.linkColor(colorType);
3229
3235
  if (snapped !== null) {
3230
3236
  ctx.setLineDash([]);
3231
3237
  ctx.lineWidth = 2.6;