@alexgyver/component 1.3.8 → 1.3.10

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/Component.js CHANGED
@@ -1,6 +1,6 @@
1
1
  //#region EL
2
2
  export class EL {
3
- static ctx;
3
+ static context;
4
4
 
5
5
  /**
6
6
  * Создать компонент и поместить его в переменную $root
@@ -9,7 +9,7 @@ export class EL {
9
9
  * @param {Boolean} svg SVG
10
10
  */
11
11
  constructor(tag, data = {}, svg = false) {
12
- EL.ctx = this;
12
+ EL.context = this;
13
13
  this.$root = EL.make(tag, data, svg);
14
14
  }
15
15
 
@@ -28,7 +28,7 @@ export class EL {
28
28
  * class {string | Array} - добавить в className
29
29
  * style {string | object} - объект в виде { padding: '0px', ... } или строка css стилей
30
30
  * push {array} - добавить к указанному массиву
31
- * var {string} - создаёт переменную $имя в указанном контексте
31
+ * var | $ {string} - создаёт переменную $имя в указанном контексте
32
32
  * events {object} - добавляет addEventListener'ы {event: e => {}}
33
33
  * children/children_r - массив {DOM, EL, object, html string}. _r - заменить имеющиеся. Без тега tag будет div
34
34
  * child/child_r - {DOM, EL, object, html string}. _r - заменить имеющиеся. Без тега tag будет div
@@ -59,8 +59,8 @@ export class EL {
59
59
  if (!(el instanceof Node) || (typeof data !== 'object')) return el;
60
60
 
61
61
  let ctx = data.context;
62
- EL.ctx = (ctx === null) ? null : (ctx ? ctx : EL.ctx);
63
- ctx = EL.ctx;
62
+ EL.context = (ctx === null) ? null : (ctx ? ctx : EL.context);
63
+ ctx = EL.context;
64
64
 
65
65
  let addChild = (obj) => {
66
66
  if (!obj) return;
@@ -87,7 +87,7 @@ export class EL {
87
87
  switch (key) {
88
88
  case 'class': (Array.isArray(val) ? val : val.split(' ')).map(c => c && el.classList.add(c)); break;
89
89
  case 'push': val.push(el); break;
90
- case 'var': if (ctx) ctx['$' + val] = el; break;
90
+ case '$': case 'var': if (ctx) ctx['$' + val] = el; break;
91
91
  case 'events': for (let ev in val) el.addEventListener(ev, val[ev].bind(ctx)); break;
92
92
  case 'parent': val.appendChild(el); break;
93
93
  case 'attrs': for (let attr in val) el.setAttribute(attr, val[attr]); break;
package/Component.min.js CHANGED
@@ -1 +1 @@
1
- var e={d:(t,a)=>{for(var c in a)e.o(a,c)&&!e.o(t,c)&&Object.defineProperty(t,c,{enumerable:!0,get:a[c]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)},t={};e.d(t,{EL:()=>a,LV:()=>r,cj:()=>s,t4:()=>n,uA:()=>c});class a{static ctx;constructor(e,t={},c=!1){a.ctx=this,this.$root=a.make(e,t,c)}static make(e,t={},c=!1){return e&&"object"==typeof t?t instanceof Node?t:("svg"==e&&(c=!0),a.config(c?document.createElementNS("http://www.w3.org/2000/svg",e):document.createElement(e),t,c)):null}static config(e,t,c=!1){if(Array.isArray(e))return e.forEach((e=>a.config(e,t,c))),null;if(!(e instanceof Node)||"object"!=typeof t)return e;let n=t.context;a.ctx=null===n?null:n||a.ctx,n=a.ctx;let s=t=>{if(t)if(t instanceof Node)e.appendChild(t);else if(t instanceof a)e.appendChild(t.$root);else if("string"==typeof t)e.innerHTML+=t;else if("object"==typeof t){let n=a.make(t.tag??"div",t,c||"svg"==t.tag);n&&e.appendChild(n)}};for(const[c,r]of Object.entries(t)){switch(c){case"text":e.textContent=null==r?"":r+"";continue;case"html":e.innerHTML=null==r?"":r+"";continue;case"tag":case"context":case"get":case"also":continue}if(r)switch(c){case"class":(Array.isArray(r)?r:r.split(" ")).map((t=>t&&e.classList.add(t)));break;case"push":r.push(e);break;case"var":n&&(n["$"+r]=e);break;case"events":for(let t in r)e.addEventListener(t,r[t].bind(n));break;case"parent":r.appendChild(e);break;case"attrs":for(let t in r)e.setAttribute(t,r[t]);break;case"props":for(let t in r)e[t]=r[t];break;case"child_r":a.clear(e);case"child":s(r);break;case"children_r":a.clear(e);case"children":for(let e of r)s(e);break;case"style":if("string"==typeof r)e.style.cssText+=r+";";else for(let t in r)r[t]&&(e.style[t]=r[t]);break;default:e[c]=r}}return t.also&&n&&t.also.call(n,e),e}static clear(e){for(;e.firstChild;)e.removeChild(e.lastChild)}static makeArray(e,t=!1){return e&&Array.isArray(e)?e.map((e=>a.make(e.tag,e,t))):[]}static makeShadow(e,t={},c=null){if(!e||"object"!=typeof t)return null;let n=e instanceof Node?e:document.createElement(e);return n.attachShadow({mode:"open"}),a.config(n.shadowRoot,{context:t.context,children:[{tag:"style",textContent:c??""},t.child??{},...t.children??[]]}),delete t.children,delete t.child,a.config(n,t),n}}const c=a;class n{static make=(e,t)=>a.make(e,t,!0);static config=(e,t)=>a.config(e,t,!0);static makeArray=e=>a.makeArray(e,!0);static svg=(e={},t={})=>n._make("svg",e,t);static rect=(e,t,a,c,s,r,l={},o={})=>n._make("rect",{...l,x:e,y:t,width:a,height:c,rx:s,ry:r},o);static circle=(e,t,a,c={},s={})=>n._make("circle",{...c,cx:e,cy:t,r:a},s);static line=(e,t,a,c,s={},r={})=>n._make("line",{...s,x1:e,y1:t,x2:a,y2:c},r);static polyline=(e,t={},a={})=>n._make("polyline",{...t,points:e},a);static polygon=(e,t={},a={})=>n._make("polygon",{...t,points:e},a);static path=(e,t={},a={})=>n._make("path",{...t,d:e},a);static text=(e,t,a,c={},s={})=>n._make("text",{...c,x:t,y:a},{...s,text:e});static _make=(e,t={},a={})=>n.make(e,{attrs:{...t},...a})}class s{static addStyle(e,t,a=!1){if(e&&t&&("object"==typeof t&&(t=t.constructor.name),!s.#e.has(t)&&!s.#t.has(t)))if(a){let a=document.createElement("style");document.head.appendChild(a),a.textContent=e,s.#t.set(t,a)}else s.#a||(s.#a=document.head.appendChild(document.createElement("style"))),s.#a.textContent+=e+"\r\n",s.#e.add(t)}static removeStyle(e){"object"==typeof e&&(e=e.constructor.name),s.#t.has(e)&&(s.#t.get(e).remove(),s.#t.delete(e))}static#a=null;static#e=new Set;static#t=new Map}class r extends a{constructor(e,t={},a=null,c=null,n=!1){super(e,t),s.addStyle(a,c,n)}static make(e,t={},c=null,n=null,r=!1){return s.addStyle(c,n,r),a.make(e,t)}}const l=t.uA,o=t.EL,i=t.t4,d=t.cj,h=t.LV;export{l as Component,o as EL,i as SVG,d as Sheet,h as StyledComponent};
1
+ var e={d:(t,a)=>{for(var c in a)e.o(a,c)&&!e.o(t,c)&&Object.defineProperty(t,c,{enumerable:!0,get:a[c]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)},t={};e.d(t,{EL:()=>a,LV:()=>o,cj:()=>s,t4:()=>n,uA:()=>c});class a{static context;constructor(e,t={},c=!1){a.context=this,this.$root=a.make(e,t,c)}static make(e,t={},c=!1){return e&&"object"==typeof t?t instanceof Node?t:("svg"==e&&(c=!0),a.config(c?document.createElementNS("http://www.w3.org/2000/svg",e):document.createElement(e),t,c)):null}static config(e,t,c=!1){if(Array.isArray(e))return e.forEach(e=>a.config(e,t,c)),null;if(!(e instanceof Node)||"object"!=typeof t)return e;let n=t.context;a.context=null===n?null:n||a.context,n=a.context;let s=t=>{if(t)if(t instanceof Node)e.appendChild(t);else if(t instanceof a)e.appendChild(t.$root);else if("string"==typeof t)e.innerHTML+=t;else if("object"==typeof t){let n=a.make(t.tag??"div",t,c||"svg"==t.tag);n&&e.appendChild(n)}};for(const[c,o]of Object.entries(t)){switch(c){case"text":e.textContent=null==o?"":o+"";continue;case"html":e.innerHTML=null==o?"":o+"";continue;case"tag":case"context":case"get":case"also":continue}if(o)switch(c){case"class":(Array.isArray(o)?o:o.split(" ")).map(t=>t&&e.classList.add(t));break;case"push":o.push(e);break;case"$":case"var":n&&(n["$"+o]=e);break;case"events":for(let t in o)e.addEventListener(t,o[t].bind(n));break;case"parent":o.appendChild(e);break;case"attrs":for(let t in o)e.setAttribute(t,o[t]);break;case"props":for(let t in o)e[t]=o[t];break;case"child_r":a.clear(e);case"child":s(o);break;case"children_r":a.clear(e);case"children":for(let e of o)s(e);break;case"style":if("string"==typeof o)e.style.cssText+=o+";";else for(let t in o)o[t]&&(e.style[t]=o[t]);break;default:e[c]=o}}return t.also&&n&&t.also.call(n,e),e}static clear(e){for(;e.firstChild;)e.removeChild(e.lastChild)}static makeArray(e,t=!1){return e&&Array.isArray(e)?e.map(e=>a.make(e.tag,e,t)):[]}static makeShadow(e,t={},c=null){if(!e||"object"!=typeof t)return null;let n=e instanceof Node?e:document.createElement(e);return n.attachShadow({mode:"open"}),a.config(n.shadowRoot,{context:t.context,children:[{tag:"style",textContent:c??""},t.child??{},...t.children??[]]}),delete t.children,delete t.child,a.config(n,t),n}}const c=a;class n{static make=(e,t)=>a.make(e,t,!0);static config=(e,t)=>a.config(e,t,!0);static makeArray=e=>a.makeArray(e,!0);static svg=(e={},t={})=>n._make("svg",e,t);static rect=(e,t,a,c,s,o,r={},l={})=>n._make("rect",{...r,x:e,y:t,width:a,height:c,rx:s,ry:o},l);static circle=(e,t,a,c={},s={})=>n._make("circle",{...c,cx:e,cy:t,r:a},s);static line=(e,t,a,c,s={},o={})=>n._make("line",{...s,x1:e,y1:t,x2:a,y2:c},o);static polyline=(e,t={},a={})=>n._make("polyline",{...t,points:e},a);static polygon=(e,t={},a={})=>n._make("polygon",{...t,points:e},a);static path=(e,t={},a={})=>n._make("path",{...t,d:e},a);static text=(e,t,a,c={},s={})=>n._make("text",{...c,x:t,y:a},{...s,text:e});static _make=(e,t={},a={})=>n.make(e,{attrs:{...t},...a})}class s{static addStyle(e,t,a=!1){if(e&&t&&("object"==typeof t&&(t=t.constructor.name),!s.#e.has(t)&&!s.#t.has(t)))if(a){let a=document.createElement("style");document.head.appendChild(a),a.textContent=e,s.#t.set(t,a)}else s.#a||(s.#a=document.head.appendChild(document.createElement("style"))),s.#a.textContent+=e+"\r\n",s.#e.add(t)}static removeStyle(e){"object"==typeof e&&(e=e.constructor.name),s.#t.has(e)&&(s.#t.get(e).remove(),s.#t.delete(e))}static#a=null;static#e=new Set;static#t=new Map}class o extends a{constructor(e,t={},a=null,c=null,n=!1){super(e,t),s.addStyle(a,c,n)}static make(e,t={},c=null,n=null,o=!1){return s.addStyle(c,n,o),a.make(e,t)}}const r=t.uA,l=t.EL,i=t.t4,d=t.cj,h=t.LV;export{r as Component,l as EL,i as SVG,d as Sheet,h as StyledComponent};
package/README.md CHANGED
@@ -26,7 +26,7 @@ EL(tag, data = {}, svg = false);
26
26
  * class {string | Array} - добавить в className
27
27
  * style {string | object} - объект в виде { padding: '0px', ... } или строка css стилей
28
28
  * push {array} - добавить к указанному массиву
29
- * var {string} - создаёт переменную $имя в указанном контексте
29
+ * var | $ {string} - создаёт переменную $имя в указанном контексте
30
30
  * events {object} - добавляет addEventListener'ы {event: e => {}}
31
31
  * children/children_r - массив {DOM, EL, object, html string}. _r - заменить имеющиеся. Без тега tag будет div
32
32
  * child/child_r - {DOM, EL, object, html string}. _r - заменить имеющиеся. Без тега tag будет div
@@ -143,14 +143,14 @@ EL.make('div', {
143
143
  });
144
144
  ```
145
145
 
146
- Гораздо интереснее использовать в классе и передавать контекст. Параметр `var` создаст переменную с элементом с указанным именем + префикс `$`:
146
+ Гораздо интереснее использовать в классе и передавать контекст. Параметр `$` создаст переменную с элементом с указанным именем + префикс `$`:
147
147
 
148
148
  ```js
149
149
  class Button {
150
150
  constructor(text) {
151
151
  EL.make('button', {
152
152
  context: this,
153
- var: 'button',
153
+ $: 'button',
154
154
  text: text,
155
155
  class: 'btn',
156
156
  events: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alexgyver/component",
3
- "version": "1.3.8",
3
+ "version": "1.3.10",
4
4
  "description": "Simple HTML&SVG element builder",
5
5
  "main": "./Component.js",
6
6
  "module": "./Component.js",