@gregoriusrippenstein/node-red-contrib-introspection 0.0.2 → 0.0.4

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/README.md CHANGED
@@ -34,20 +34,20 @@ Double click on the top-level node and all nodes in the pathway are highlighted.
34
34
 
35
35
  Drag the node into a flow, double-click on the node and the tray opens -depending on the size of the flow, this might take a moment. Once the tray is opened, the SVG is shown in the editor window (I took the code from the template node hence the syntax dropdown). Below the editor window is the download button. Pressing that will download the SVG as it is in the editor window, so making changes in that window will be reflected in the downloaded content.
36
36
 
37
- The SVG code can also be copied and pasted into something like [drawsvg.org](https://drawsvg.org/drawsvg.html) hence select-all-copy-paste is provide by having the editor window.
37
+ The SVG code can also be copied and pasted into something like [drawsvg.org](https://drawsvg.org/drawsvg.html) hence select-all-copy-paste is provided by having the editor window.
38
38
 
39
39
  Improvements over [svgexport.io](https://svgexport.io) browser plugin:
40
40
 
41
- - Respects the 'hide' CSS class that is used to hide specific elements, this the svgexport plugin cannot know.
41
+ - Respects the 'hide' CSS class that is used to hide specific elements, this is something that the svgexport plugin cannot know.
42
42
  - Compliments the setting of visibility on the 'g' element with opacity=0. The SVG Standard ignores visibility on 'g' elements but browsers don't seem to care, Inkscape does care.
43
43
  - Image data (i.e. icons) is inlined using `data:image/XXXX;base64,` - this is good for things such as Inkscape that can't resolve relative urls. PNG, JPEG and SVG are supported.
44
44
  - It also retrieves font details and includes them in the SVG. This makes the font italic, even if it's not the correct font family (because font might not be installed on system).
45
45
 
46
46
  Disappointments:
47
47
 
48
- - Font-awesome icons, because they use the font-awesome font, aren't inlined and therefore aren't available in external tools (but are visible if SVG opened in browser). If the font-awesome fonts are installed on the system icons do work in Inkscape.
48
+ - Font-awesome icons, because they use the font-awesome font, aren't inlined and therefore aren't available in external tools. If the font-awesome fonts are installed on the system icons do work in Inkscape and browser.
49
49
  - Because a double click is required, any highlights in the workflow are lost (i.e. link-in/out highlights showing the other tab names disappears)
50
- - Limited testing: on Firefox (on mac), your mileage might vary
50
+ - Limited testing: Firefox & Opera (on mac), your mileage might vary
51
51
  - No error checking - network requests are assumed to work
52
52
 
53
53
  ## Examples
@@ -64,7 +64,7 @@ Example screenshot:
64
64
 
65
65
  ## License
66
66
 
67
- [Do whatever but don't do evil](/LICENSE)
67
+ [*Do whatever but don't do evil* license](/LICENSE)
68
68
 
69
69
  ## Contribution & Ideas
70
70
 
@@ -54,14 +54,16 @@
54
54
 
55
55
  this.editor.setValue( "Please wait, screenshot being prepared ..." );
56
56
 
57
- var hwAttrs = (
58
- 'width="' + $($('svg')[0]).attr('width') + '" height="' +
59
- $($('svg')[0]).attr('height') + '"'
60
- );
61
-
62
57
  //
63
58
  // begin the SVG conversion code.
64
59
  //
60
+ var origSvg = $($('svg')[0]);
61
+
62
+ var hwAttrs = (
63
+ 'width="' + origSvg.attr('width') + '" height="' +
64
+ origSvg.attr('height') + '"'
65
+ );
66
+
65
67
  var svgHeader = (
66
68
  '<?xml version="1.0" standalone="no"?>\r\n' +
67
69
  '<svg ' + hwAttrs + ' pointer-events="all" style="cursor: crosshair; '+
@@ -69,7 +71,7 @@
69
71
  'xmlns:xlink="http://www.w3.org/1999/xlink">\r\n'
70
72
  );
71
73
 
72
- var svgBody = $($('svg')[0]).html();
74
+ var svgBody = origSvg.html();
73
75
 
74
76
  var parser = new DOMParser();
75
77
  var doc = parser.parseFromString(svgHeader + svgBody + '\r\n</svg>',
@@ -101,23 +103,28 @@
101
103
  // Set everything that might have been set via CSS directly on the
102
104
  // element. All styling values must be defined as attributes on the
103
105
  // SVG element.
104
- var convertCssToAttr = function( collection ) {
106
+ var convertCssToAttr = function( collection, origElems ) {
105
107
  for ( var idx = 0; idx < collection.length; idx++ ) {
106
108
  var elem = collection.item(idx);
107
- ["fill", "stroke"].forEach( function(attrname) {
109
+ var origElem = origElems[idx];
110
+
111
+ [
112
+ "fill", "stroke"
113
+ ].forEach( function(attrname) {
108
114
  elem.setAttribute(attrname,
109
- rgb2hex($(elem).attr(attrname) ||
110
- $(elem).css(attrname) ));
115
+ rgb2hex($(origElem).attr(attrname) ||
116
+ $(origElem).css(attrname) ));
111
117
  });
112
118
 
113
119
  [
114
120
  "stroke-width","fill-opacity","stroke-opacity","opacity"
115
121
  ].forEach(function(attrname) {
116
122
  elem.setAttribute(attrname,
117
- $(elem).attr(attrname) || $(elem).css(attrname));
123
+ $(origElem).attr(attrname) ||
124
+ $(origElem).css(attrname));
118
125
  });
119
126
 
120
- if ( $(elem).hasClass('hide') ) {
127
+ if ( $(origElem).hasClass('hide') ) {
121
128
  if ( elem.tagName == "g" ) {
122
129
  // according to the SVG standard, visibility cannot be applied
123
130
  // (or better said: has no effect) on 'g' (group) elements.
@@ -132,28 +139,35 @@
132
139
  }
133
140
 
134
141
  // include font details on the text elements.
135
- var convertFontsToAttr = function( collection ) {
142
+ var convertFontsToAttr = function( collection, origElems ) {
136
143
  for ( var idx = 0; idx < collection.length; idx++ ) {
137
144
  var elem = collection.item(idx);
145
+ var origElem = origElems[idx];
146
+
138
147
  ["font-family", "font-size", "font-size-adjust", "font-stretch",
139
148
  "font-style", "font-variant", "font-weight"
140
149
  ].forEach( function(attrname) {
141
150
  elem.setAttribute(attrname,
142
- $(elem).attr(attrname) || $(elem).css(attrname) );
151
+ $(origElem).attr(attrname) ||
152
+ $(origElem).css(attrname) );
143
153
  })
144
154
  }
145
155
  }
146
156
 
147
157
  // probably missed some elements ...
148
- convertCssToAttr(doc.getElementsByTagName("g"));
149
- convertCssToAttr(doc.getElementsByTagName("rect"));
150
- convertCssToAttr(doc.getElementsByTagName("line"));
151
- convertCssToAttr(doc.getElementsByTagName("path"));
152
- convertCssToAttr(doc.getElementsByTagName("circle"));
153
- convertCssToAttr(doc.getElementsByTagName("image"));
158
+ var tagnames = [ "g", "rect", "line", "path", "circle", "image" ];
159
+ tagnames.forEach( function(tagname) {
160
+ convertCssToAttr(doc.getElementsByTagName(tagname),
161
+ origSvg.find(tagname));
162
+ });
163
+
164
+ [ "text" ].forEach( function(tagname) {
165
+ convertCssToAttr(doc.getElementsByTagName(tagname),
166
+ origSvg.find(tagname));
154
167
 
155
- convertCssToAttr(doc.getElementsByTagName("text"));
156
- convertFontsToAttr(doc.getElementsByTagName("text"));
168
+ convertFontsToAttr(doc.getElementsByTagName(tagname),
169
+ origSvg.find(tagname));
170
+ });
157
171
 
158
172
  // inline image data. Image types supported: Jpeg, Png and Svg.
159
173
  var imageColl = doc.getElementsByTagName("image");
@@ -225,6 +239,9 @@
225
239
  getDataAndCallbackWhenDone( imageColl.item(imageColl.length-1),
226
240
  imageColl.length-1,
227
241
  cb );
242
+ } else {
243
+ const serializer = new XMLSerializer();
244
+ that.editor.setValue( serializer.serializeToString(doc) );
228
245
  }
229
246
 
230
247
  // handle the download button under the editor window.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gregoriusrippenstein/node-red-contrib-introspection",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "keywords": [
5
5
  "node-red"
6
6
  ],