@taybart/corvid 0.0.5 → 0.0.6

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/dist/dom.d.ts CHANGED
@@ -16,6 +16,7 @@ type elOpts = {
16
16
  };
17
17
  export declare class el {
18
18
  el: HTMLElement | null;
19
+ name: string;
19
20
  constructor(opts: string | elOpts);
20
21
  /*** get ***/
21
22
  value(): string;
@@ -28,6 +29,8 @@ export declare class el {
28
29
  }): this;
29
30
  src(url: string): this;
30
31
  style(style: Object | string): this;
32
+ addClass(className: string): this;
33
+ removeClass(className: string): this;
31
34
  listen(event: string, cb: (ev: Event) => void): this;
32
35
  onClick(cb: (ev: Event) => void): this;
33
36
  }
package/dist/index.js CHANGED
@@ -67,18 +67,18 @@ class el {
67
67
  return '';
68
68
  }
69
69
  parent(parent) {
70
- if (!this.el) throw new Error('no element');
70
+ if (!this.el) throw new Error(`no element from input: ${this.name}`);
71
71
  parent.appendChild(this.el);
72
72
  return this;
73
73
  }
74
74
  child(ch) {
75
75
  var _this_el;
76
- if (!this.el) throw new Error('no element');
76
+ if (!this.el) throw new Error(`no element from input: ${this.name}`);
77
77
  null == (_this_el = this.el) || _this_el.appendChild(ch);
78
78
  return this;
79
79
  }
80
80
  inner(content, { force = false, text = false } = {}) {
81
- if (!this.el) throw new Error('no element');
81
+ if (!this.el) throw new Error(`no element from input: ${this.name}`);
82
82
  if (this.el instanceof HTMLIFrameElement && !force) this.el.src = content;
83
83
  else if (this.el instanceof HTMLInputElement && !force) this.el.value = content;
84
84
  else if (text) this.el.textContent = content;
@@ -100,8 +100,18 @@ class el {
100
100
  }
101
101
  return this;
102
102
  }
103
+ addClass(className) {
104
+ if (!this.el) throw new Error(`no element from input: ${this.name}`);
105
+ this.el.classList.add(className);
106
+ return this;
107
+ }
108
+ removeClass(className) {
109
+ if (!this.el) throw new Error(`no element from input: ${this.name}`);
110
+ this.el.classList.remove(className);
111
+ return this;
112
+ }
103
113
  listen(event, cb) {
104
- if (!this.el) throw new Error('no element');
114
+ if (!this.el) throw new Error(`no element from input: ${this.name}`);
105
115
  this.el.addEventListener(event, cb);
106
116
  return this;
107
117
  }
@@ -110,16 +120,21 @@ class el {
110
120
  }
111
121
  constructor(opts){
112
122
  _define_property(this, "el", void 0);
123
+ _define_property(this, "name", void 0);
113
124
  if ('string' == typeof opts) {
125
+ this.name = opts;
114
126
  this.el = document.querySelector(opts);
115
127
  return;
116
128
  }
117
129
  const { query, type, content, parent, create } = opts;
118
130
  if (query) {
131
+ this.name = query;
119
132
  this.el = document.querySelector(query);
120
133
  if (!this.el && type && create) this.el = document.createElement(type);
121
- } else if (type) this.el = document.createElement(type);
122
- else throw new Error('no query or type provided');
134
+ } else if (type) {
135
+ this.name = type;
136
+ this.el = document.createElement(type);
137
+ } else throw new Error('no query or type provided');
123
138
  if (this.el && content) this.el.innerHTML = content;
124
139
  if (this.el && parent) parent.appendChild(this.el);
125
140
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@taybart/corvid",
3
- "version": "0.0.5",
3
+ "version": "0.0.6",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "exports": {