@gregoriusrippenstein/node-red-contrib-introspection 0.0.6 → 0.0.7

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.
@@ -25,11 +25,12 @@
25
25
 
26
26
  // SVG has very specific requirements for colour specification, baseline
27
27
  // all colors to #rrggbb. This converts: 'rgb(rrr, ggg, bbb)' and '#rgb'.
28
+ // Although it could also just be Inkscape, SVG does have a broad range
29
+ // of color possibilities.
28
30
  var rgb2hex = (rgb) => {
29
- if ( !rgb ) { return "none" }
30
- if ( rgb === null ) { return "none" }
31
+ if ( !rgb || rgb === null || rgb == "none" ) { return "none" }
31
32
 
32
- rgb3 = rgb.match(/^#(.)(.)(.)$/);
33
+ var rgb3 = rgb.match(/^#(.)(.)(.)$/);
33
34
  if ( rgb3 ) {
34
35
  return ("#" +rgb3[1]+rgb3[1]+rgb3[2]+rgb3[2]+rgb3[3]+rgb3[3]);
35
36
  }
@@ -38,7 +39,21 @@
38
39
  if ( rgb3 ) { return rgb; }
39
40
 
40
41
  rgb3 = rgb.match(/^rgb\(([0-9]+),\s+([0-9]+),\s+([0-9]+)/);
41
- if ( rgb3 === null ) { return rgb; }
42
+ if ( rgb3 === null ) {
43
+ var rgb4 = rgb.match(/^rgba\(([0-9]+),\s+([0-9]+),\s+([0-9]+),\s+([0-9]+)/);
44
+ if ( rgb4 ) {
45
+ return {
46
+ clr: ("#" +
47
+ ("0" + parseInt(rgb4[1],10).toString(16)).slice(-2) +
48
+ ("0" + parseInt(rgb4[2],10).toString(16)).slice(-2) +
49
+ ("0" + parseInt(rgb4[3],10).toString(16)).slice(-2) ),
50
+ opa: rgb4[4]
51
+ }
52
+ } else {
53
+ console.log( "Screenshot node: returning unknown color: " + rgb );
54
+ return rgb;
55
+ }
56
+ }
42
57
 
43
58
  return "#" +
44
59
  ("0" + parseInt(rgb3[1],10).toString(16)).slice(-2) +
@@ -55,21 +70,30 @@
55
70
  var origElem = origElems[idx];
56
71
 
57
72
  [
58
- "fill", "stroke"
59
- ].forEach( function(attrname) {
60
- elem.setAttribute(attrname,
61
- rgb2hex($(origElem).attr(attrname) ||
62
- $(origElem).css(attrname) ));
63
- });
64
-
65
- [
66
- "stroke-width","fill-opacity","stroke-opacity","opacity"
73
+ "stroke-width","fill-opacity","stroke-opacity","opacity",
74
+ "stroke-dasharray"
67
75
  ].forEach(function(attrname) {
68
76
  elem.setAttribute(attrname,
69
77
  $(origElem).attr(attrname) ||
70
78
  $(origElem).css(attrname));
71
79
  });
72
80
 
81
+ [
82
+ "fill", "stroke"
83
+ ].forEach( function(attrname) {
84
+ var val = rgb2hex($(origElem).attr(attrname) ||
85
+ $(origElem).css(attrname) );
86
+
87
+ // Browsers/CSS has the color 'transparent', SVG is oblivious to
88
+ // such frills and whistles, instead opacity to the rescue.
89
+ if ( typeof val == "object" ) {
90
+ elem.setAttribute(attrname + "-opacity", val.opa);
91
+ elem.setAttribute(attrname, val.clr);
92
+ } else {
93
+ elem.setAttribute(attrname,val);
94
+ }
95
+ });
96
+
73
97
  if ( $(origElem).hasClass('hide') ) {
74
98
  if ( elem.tagName == "g" ) {
75
99
  // according to the SVG standard, visibility cannot be applied
@@ -91,7 +115,7 @@
91
115
  var origElem = origElems[idx];
92
116
 
93
117
  ["font-family", "font-size", "font-size-adjust", "font-stretch",
94
- "font-style", "font-variant", "font-weight"
118
+ "font-style", "font-variant", "font-weight", "text-anchor"
95
119
  ].forEach( function(attrname) {
96
120
  elem.setAttribute(attrname,
97
121
  $(origElem).attr(attrname) ||
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gregoriusrippenstein/node-red-contrib-introspection",
3
- "version": "0.0.6",
3
+ "version": "0.0.7",
4
4
  "keywords": [
5
5
  "node-red"
6
6
  ],