@alexgyver/component 1.2.9 → 1.3.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.
Files changed (3) hide show
  1. package/Component.js +15 -1
  2. package/README.md +13 -1
  3. package/package.json +1 -1
package/Component.js CHANGED
@@ -89,8 +89,9 @@ export class Component {
89
89
  case 'parent': if (val) val.appendChild(el); break;
90
90
  case 'attrs': for (let attr in val) el.setAttribute(attr, val[attr]); break;
91
91
  case 'props': for (let prop in val) el[prop] = val[prop]; break;
92
- case 'child_r': case 'children_r': el.replaceChildren();
92
+ case 'child_r': el.replaceChildren(); // fall
93
93
  case 'child': addChild(val); break;
94
+ case 'children_r': el.replaceChildren(); // fall
94
95
  case 'children': for (const obj of val) addChild(obj); break;
95
96
  case 'style':
96
97
  if (typeof val === 'string') el.style.cssText += (val + ';');
@@ -222,6 +223,19 @@ export class StyledComponent extends Component {
222
223
  }
223
224
  }
224
225
 
226
+ export class SVG {
227
+ static svg = (attrs = {}, props = {}) => SVG._make('svg', attrs, props);
228
+ static rect = (x, y, w, h, rx, ry, attrs = {}, props = {}) => SVG._make('rect', { ...attrs, x: x, y: y, width: w, height: h, rx: rx, ry: ry }, props);
229
+ static circle = (x, y, r, attrs = {}, props = {}) => SVG._make('circle', { ...attrs, cx: x, cy: y, r: r }, props);
230
+ static line = (x1, y1, x2, y2, attrs = {}, props = {}) => SVG._make('line', { ...attrs, x1: x1, y1: y1, x2: x2, y2: y2 }, props);
231
+ static polyline = (points, attrs = {}, props = {}) => SVG._make('polyline', { ...attrs, points: points }, props);
232
+ static polygon = (points, attrs = {}, props = {}) => SVG._make('polygon', { ...attrs, points: points }, props);
233
+ static path = (d, attrs = {}, props = {}) => SVG._make('path', { ...attrs, d: d }, props);
234
+ static text = (text, x, y, attrs = {}, props = {}) => SVG._make('text', { ...attrs, x: x, y: y }, { ...props, text: text });
235
+
236
+ static _make = (tag, attrs = {}, props = {}) => Component.makeSVG(tag, { attrs: { ...attrs }, ...props });
237
+ }
238
+
225
239
  export async function waitRender(elm, cb = null, ctx = window) {
226
240
  return new Promise(res => {
227
241
  let e = elm;
package/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  # Component.js
2
- Библиотека для создания и настройки DOM элементов как JS объектов
2
+ Библиотека для создания и настройки DOM/SVG элементов как JS объектов
3
3
 
4
4
  > npm i @alexgyver/component
5
5
 
@@ -66,6 +66,18 @@ Component.makeArray(arr);
66
66
  Component.makeArraySVG(arr);
67
67
  ```
68
68
 
69
+ ### SVG
70
+ ```js
71
+ SVG.svg(attrs = {}, props = {});
72
+ SVG.rect(x, y, w, h, rx, ry, attrs = {}, props = {});
73
+ SVG.circle(x, y, r, attrs = {}, props = {});
74
+ SVG.line(x1, y1, x2, y2, attrs = {}, props = {});
75
+ SVG.polyline(points, attrs = {}, props = {});
76
+ SVG.polygon(points, attrs = {}, props = {});
77
+ SVG.path(d, attrs = {}, props = {});
78
+ SVG.text(text, x, y, attrs = {}, props = {});
79
+ ```
80
+
69
81
  ### Sheet
70
82
  ```js
71
83
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alexgyver/component",
3
- "version": "1.2.9",
3
+ "version": "1.3.0",
4
4
  "description": "Simple HTML element builder",
5
5
  "main": "./Component.js",
6
6
  "module": "./Component.js",