ntk 8.24.0 → 8.25.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.
- package/lib/widgets/svgview.js +56 -0
- package/package.json +2 -2
package/lib/widgets/svgview.js
CHANGED
|
@@ -33,6 +33,8 @@ const INHERITED = {
|
|
|
33
33
|
lineCap: 'butt',
|
|
34
34
|
lineJoin: 'miter',
|
|
35
35
|
miterLimit: 4,
|
|
36
|
+
dashArray: 'none',
|
|
37
|
+
dashOffset: 0,
|
|
36
38
|
fillRule: 'nonzero',
|
|
37
39
|
clipRule: 'nonzero',
|
|
38
40
|
fillOpacity: 1,
|
|
@@ -61,6 +63,8 @@ const STYLE_ATTRS = {
|
|
|
61
63
|
'stroke-linecap': 'lineCap',
|
|
62
64
|
'stroke-linejoin': 'lineJoin',
|
|
63
65
|
'stroke-miterlimit': 'miterLimit',
|
|
66
|
+
'stroke-dasharray': 'dashArray',
|
|
67
|
+
'stroke-dashoffset': 'dashOffset',
|
|
64
68
|
'fill-rule': 'fillRule',
|
|
65
69
|
'clip-rule': 'clipRule',
|
|
66
70
|
'fill-opacity': 'fillOpacity',
|
|
@@ -578,6 +582,12 @@ function resolveStyle(node, parent) {
|
|
|
578
582
|
case 'textAnchor':
|
|
579
583
|
value = v.toLowerCase();
|
|
580
584
|
break;
|
|
585
|
+
case 'dashArray':
|
|
586
|
+
value = dashArrayValue(v);
|
|
587
|
+
break;
|
|
588
|
+
case 'dashOffset':
|
|
589
|
+
value = dashLength(v, true) ?? undefined;
|
|
590
|
+
break;
|
|
581
591
|
case 'markerStart':
|
|
582
592
|
case 'markerMid':
|
|
583
593
|
case 'markerEnd':
|
|
@@ -596,6 +606,42 @@ function resolveStyle(node, parent) {
|
|
|
596
606
|
return style;
|
|
597
607
|
}
|
|
598
608
|
|
|
609
|
+
/**
|
|
610
|
+
* A length in a dash pattern or its offset, in user units: a number, or one
|
|
611
|
+
* in `px` (SVG 2, 13.5.6). A percentage of the viewport's diagonal, or a
|
|
612
|
+
* length in another unit, is none this reads. A negative one is an error in
|
|
613
|
+
* a pattern, and fine in an offset (`signed`).
|
|
614
|
+
*/
|
|
615
|
+
function dashLength(value, signed = false) {
|
|
616
|
+
const m = /^([-+]?(?:\d+\.?\d*|\.\d+)(?:e[-+]?\d+)?)(px)?$/i.exec(value.trim());
|
|
617
|
+
if (!m) return null;
|
|
618
|
+
const n = Number(m[1]);
|
|
619
|
+
if (!Number.isFinite(n) || (!signed && n < 0)) return null;
|
|
620
|
+
return n;
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
/**
|
|
624
|
+
* `stroke-dasharray` as `setLineDash` takes it (SVG 2, 13.5.5): `none`, or
|
|
625
|
+
* its lengths, split on commas and white space. One that is not a length,
|
|
626
|
+
* or is negative, makes the value an error, which leaves the property as it
|
|
627
|
+
* was (undefined); lengths that come to nothing draw the stroke solid, as
|
|
628
|
+
* `none` does. An odd count is repeated by `setLineDash`, as the property
|
|
629
|
+
* has it.
|
|
630
|
+
*/
|
|
631
|
+
function dashArrayValue(value) {
|
|
632
|
+
const v = value.trim();
|
|
633
|
+
if (v.toLowerCase() === 'none') return 'none';
|
|
634
|
+
const parts = v.split(/[\s,]+/).filter(Boolean);
|
|
635
|
+
if (!parts.length) return undefined;
|
|
636
|
+
const out = [];
|
|
637
|
+
for (const part of parts) {
|
|
638
|
+
const n = dashLength(part);
|
|
639
|
+
if (n === null) return undefined;
|
|
640
|
+
out.push(n);
|
|
641
|
+
}
|
|
642
|
+
return out.some((n) => n > 0) ? out : 'none';
|
|
643
|
+
}
|
|
644
|
+
|
|
599
645
|
/**
|
|
600
646
|
* How many distinct colours a document actually commits to, decided once at
|
|
601
647
|
* parse time.
|
|
@@ -1179,7 +1225,17 @@ export default class SvgView {
|
|
|
1179
1225
|
ctx.lineCap = style.lineCap;
|
|
1180
1226
|
ctx.lineJoin = style.lineJoin;
|
|
1181
1227
|
ctx.miterLimit = style.miterLimit;
|
|
1228
|
+
// dashed where it says so, and nothing after it is
|
|
1229
|
+
const dashed = style.dashArray !== 'none' && typeof ctx.setLineDash === 'function';
|
|
1230
|
+
if (dashed) {
|
|
1231
|
+
ctx.setLineDash(style.dashArray);
|
|
1232
|
+
ctx.lineDashOffset = style.dashOffset;
|
|
1233
|
+
}
|
|
1182
1234
|
this._ink(ctx, 'stroke', style.stroke, style, path, nodeAlpha * style.strokeOpacity, () => ctx.stroke(path));
|
|
1235
|
+
if (dashed) {
|
|
1236
|
+
ctx.setLineDash([]);
|
|
1237
|
+
ctx.lineDashOffset = 0;
|
|
1238
|
+
}
|
|
1183
1239
|
}
|
|
1184
1240
|
ctx.globalAlpha = 1;
|
|
1185
1241
|
// over its fill and its stroke, which is the default paint order
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ntk",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.25.0",
|
|
4
4
|
"description": "Desktop UI toolkit for X11 with canvas-like 2d and OpenGL rendering",
|
|
5
5
|
"author": "Andrey Sidorov <sidorares@yandex.ru>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -68,7 +68,7 @@
|
|
|
68
68
|
"x11-dri": ">=0.5.0 <1"
|
|
69
69
|
},
|
|
70
70
|
"scripts": {
|
|
71
|
-
"test": "NTK_STRICT_COLORS=1 node --test",
|
|
71
|
+
"test": "NTK_STRICT_COLORS=1 node --import ./test/helpers/exit-watchdog.js --test",
|
|
72
72
|
"check-release-message": "node scripts/check-release-message.mjs"
|
|
73
73
|
},
|
|
74
74
|
"devDependencies": {
|