@dimension-mismatch/htmltools 0.0.1

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/htmltools.js ADDED
@@ -0,0 +1,285 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
18
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
19
+ if (ar || !(i in from)) {
20
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
21
+ ar[i] = from[i];
22
+ }
23
+ }
24
+ return to.concat(ar || Array.prototype.slice.call(from));
25
+ };
26
+ Object.defineProperty(exports, "__esModule", { value: true });
27
+ exports.FORM = exports.A = exports.LI = exports.UL = exports.P = exports.INPUT = exports.BUTTON = exports.DIV = exports.FEform = exports.FEa = exports.FEli = exports.FEul = exports.FEp = exports.FEinput = exports.FEbutton = exports.FEdiv = exports.FElement = void 0;
28
+ exports.ElementByID = ElementByID;
29
+ exports.SetDocumentContent = SetDocumentContent;
30
+ var FElement = /** @class */ (function () {
31
+ function FElement(type) {
32
+ var children = [];
33
+ for (var _i = 1; _i < arguments.length; _i++) {
34
+ children[_i - 1] = arguments[_i];
35
+ }
36
+ if (typeof type === 'string' || type instanceof String) {
37
+ this.element = document.createElement(type);
38
+ }
39
+ else {
40
+ this.element = type;
41
+ }
42
+ for (var i in children) {
43
+ this.element.appendChild(children[i].element);
44
+ }
45
+ }
46
+ FElement.prototype.withAttributes = function (attributes) {
47
+ for (var attribute in attributes) {
48
+ this.element.setAttribute(attribute, attributes[attribute]);
49
+ }
50
+ return this;
51
+ };
52
+ FElement.prototype.id = function (id) {
53
+ this.element.id = id;
54
+ return this;
55
+ };
56
+ FElement.prototype.withClass = function (classname) {
57
+ this.element.classList.add(classname);
58
+ return this;
59
+ };
60
+ FElement.prototype.removeClass = function (classname) {
61
+ this.element.classList.remove(classname);
62
+ return this;
63
+ };
64
+ FElement.prototype.toggleClass = function (classname) {
65
+ this.element.classList.toggle(classname);
66
+ return this;
67
+ };
68
+ FElement.prototype.says = function (innerHTML) {
69
+ this.element.textContent = innerHTML;
70
+ return this;
71
+ };
72
+ FElement.prototype.replaceContent = function () {
73
+ var children = [];
74
+ for (var _i = 0; _i < arguments.length; _i++) {
75
+ children[_i] = arguments[_i];
76
+ }
77
+ this.element.replaceChildren();
78
+ for (var i in children) {
79
+ this.element.appendChild(children[i].element);
80
+ }
81
+ return this;
82
+ };
83
+ FElement.prototype.onEvent = function (eventName, callback) {
84
+ this.element.addEventListener(eventName, callback);
85
+ return this;
86
+ };
87
+ FElement.prototype.addChildren = function () {
88
+ var children = [];
89
+ for (var _i = 0; _i < arguments.length; _i++) {
90
+ children[_i] = arguments[_i];
91
+ }
92
+ for (var i in children) {
93
+ this.element.appendChild(children[i].element);
94
+ }
95
+ return this;
96
+ };
97
+ FElement.prototype.selfDestruct = function () {
98
+ this.element.remove();
99
+ };
100
+ return FElement;
101
+ }());
102
+ exports.FElement = FElement;
103
+ function ElementByID(id) {
104
+ var e = document.getElementById(id);
105
+ if (e) {
106
+ return new FElement(e);
107
+ }
108
+ else {
109
+ throw new Error("Could not find an element with id \"" + id + "\".");
110
+ }
111
+ }
112
+ function SetDocumentContent() {
113
+ var children = [];
114
+ for (var _i = 0; _i < arguments.length; _i++) {
115
+ children[_i] = arguments[_i];
116
+ }
117
+ document.body.replaceChildren();
118
+ for (var i in children) {
119
+ document.body.appendChild(children[i].element);
120
+ }
121
+ }
122
+ var FEdiv = /** @class */ (function (_super) {
123
+ __extends(FEdiv, _super);
124
+ function FEdiv() {
125
+ var children = [];
126
+ for (var _i = 0; _i < arguments.length; _i++) {
127
+ children[_i] = arguments[_i];
128
+ }
129
+ return _super.apply(this, __spreadArray(["div"], children, false)) || this;
130
+ }
131
+ return FEdiv;
132
+ }(FElement));
133
+ exports.FEdiv = FEdiv;
134
+ var DIV = function () {
135
+ var children = [];
136
+ for (var _i = 0; _i < arguments.length; _i++) {
137
+ children[_i] = arguments[_i];
138
+ }
139
+ return new (FEdiv.bind.apply(FEdiv, __spreadArray([void 0], children, false)))();
140
+ };
141
+ exports.DIV = DIV;
142
+ var FEbutton = /** @class */ (function (_super) {
143
+ __extends(FEbutton, _super);
144
+ function FEbutton() {
145
+ var children = [];
146
+ for (var _i = 0; _i < arguments.length; _i++) {
147
+ children[_i] = arguments[_i];
148
+ }
149
+ return _super.apply(this, __spreadArray(["button"], children, false)) || this;
150
+ }
151
+ FEbutton.prototype.does = function (action) {
152
+ this.onEvent("click", action);
153
+ return this;
154
+ };
155
+ return FEbutton;
156
+ }(FElement));
157
+ exports.FEbutton = FEbutton;
158
+ var BUTTON = function () {
159
+ var children = [];
160
+ for (var _i = 0; _i < arguments.length; _i++) {
161
+ children[_i] = arguments[_i];
162
+ }
163
+ return new (FEbutton.bind.apply(FEbutton, __spreadArray([void 0], children, false)))();
164
+ };
165
+ exports.BUTTON = BUTTON;
166
+ var FEinput = /** @class */ (function (_super) {
167
+ __extends(FEinput, _super);
168
+ function FEinput() {
169
+ var children = [];
170
+ for (var _i = 0; _i < arguments.length; _i++) {
171
+ children[_i] = arguments[_i];
172
+ }
173
+ return _super.apply(this, __spreadArray(["input"], children, false)) || this;
174
+ }
175
+ return FEinput;
176
+ }(FElement));
177
+ exports.FEinput = FEinput;
178
+ var INPUT = function () {
179
+ var children = [];
180
+ for (var _i = 0; _i < arguments.length; _i++) {
181
+ children[_i] = arguments[_i];
182
+ }
183
+ return new (FEinput.bind.apply(FEinput, __spreadArray([void 0], children, false)))();
184
+ };
185
+ exports.INPUT = INPUT;
186
+ var FEp = /** @class */ (function (_super) {
187
+ __extends(FEp, _super);
188
+ function FEp() {
189
+ var children = [];
190
+ for (var _i = 0; _i < arguments.length; _i++) {
191
+ children[_i] = arguments[_i];
192
+ }
193
+ return _super.apply(this, __spreadArray(["p"], children, false)) || this;
194
+ }
195
+ return FEp;
196
+ }(FElement));
197
+ exports.FEp = FEp;
198
+ var P = function () {
199
+ var children = [];
200
+ for (var _i = 0; _i < arguments.length; _i++) {
201
+ children[_i] = arguments[_i];
202
+ }
203
+ return new (FEp.bind.apply(FEp, __spreadArray([void 0], children, false)))();
204
+ };
205
+ exports.P = P;
206
+ var FEul = /** @class */ (function (_super) {
207
+ __extends(FEul, _super);
208
+ function FEul() {
209
+ var children = [];
210
+ for (var _i = 0; _i < arguments.length; _i++) {
211
+ children[_i] = arguments[_i];
212
+ }
213
+ return _super.apply(this, __spreadArray(["ul"], children, false)) || this;
214
+ }
215
+ return FEul;
216
+ }(FElement));
217
+ exports.FEul = FEul;
218
+ var UL = function () {
219
+ var children = [];
220
+ for (var _i = 0; _i < arguments.length; _i++) {
221
+ children[_i] = arguments[_i];
222
+ }
223
+ return new (FEul.bind.apply(FEul, __spreadArray([void 0], children, false)))();
224
+ };
225
+ exports.UL = UL;
226
+ var FEli = /** @class */ (function (_super) {
227
+ __extends(FEli, _super);
228
+ function FEli() {
229
+ var children = [];
230
+ for (var _i = 0; _i < arguments.length; _i++) {
231
+ children[_i] = arguments[_i];
232
+ }
233
+ return _super.apply(this, __spreadArray(["li"], children, false)) || this;
234
+ }
235
+ return FEli;
236
+ }(FElement));
237
+ exports.FEli = FEli;
238
+ var LI = function () {
239
+ var children = [];
240
+ for (var _i = 0; _i < arguments.length; _i++) {
241
+ children[_i] = arguments[_i];
242
+ }
243
+ return new (FEli.bind.apply(FEli, __spreadArray([void 0], children, false)))();
244
+ };
245
+ exports.LI = LI;
246
+ var FEa = /** @class */ (function (_super) {
247
+ __extends(FEa, _super);
248
+ function FEa() {
249
+ var children = [];
250
+ for (var _i = 0; _i < arguments.length; _i++) {
251
+ children[_i] = arguments[_i];
252
+ }
253
+ return _super.apply(this, __spreadArray(["a"], children, false)) || this;
254
+ }
255
+ return FEa;
256
+ }(FElement));
257
+ exports.FEa = FEa;
258
+ var A = function () {
259
+ var children = [];
260
+ for (var _i = 0; _i < arguments.length; _i++) {
261
+ children[_i] = arguments[_i];
262
+ }
263
+ return new (FEa.bind.apply(FEa, __spreadArray([void 0], children, false)))();
264
+ };
265
+ exports.A = A;
266
+ var FEform = /** @class */ (function (_super) {
267
+ __extends(FEform, _super);
268
+ function FEform() {
269
+ var children = [];
270
+ for (var _i = 0; _i < arguments.length; _i++) {
271
+ children[_i] = arguments[_i];
272
+ }
273
+ return _super.apply(this, __spreadArray(["form"], children, false)) || this;
274
+ }
275
+ return FEform;
276
+ }(FElement));
277
+ exports.FEform = FEform;
278
+ var FORM = function () {
279
+ var children = [];
280
+ for (var _i = 0; _i < arguments.length; _i++) {
281
+ children[_i] = arguments[_i];
282
+ }
283
+ return new (FEa.bind.apply(FEa, __spreadArray([void 0], children, false)))();
284
+ };
285
+ exports.FORM = FORM;
package/htmltools.ts ADDED
@@ -0,0 +1,114 @@
1
+
2
+ export class FElement{
3
+ element;
4
+ constructor(type: string | any, ...children: FElement[]){
5
+ if(typeof type === 'string' || type instanceof String){
6
+ this.element = document.createElement(type as string);
7
+ }
8
+ else{
9
+ this.element = type;
10
+ }
11
+ for(var i in children){
12
+ this.element.appendChild(children[i].element);
13
+ }
14
+ }
15
+ withAttributes(attributes: any){
16
+ for(var attribute in attributes){
17
+ this.element.setAttribute(attribute, attributes[attribute]);
18
+ }
19
+ return this;
20
+ }
21
+ id(id: string){
22
+ this.element.id = id;
23
+ return this;
24
+ }
25
+ withClass(classname: string){
26
+ this.element.classList.add(classname);
27
+ return this;
28
+ }
29
+ removeClass(classname: string){
30
+ this.element.classList.remove(classname);
31
+ return this;
32
+ }
33
+ toggleClass(classname: string){
34
+ this.element.classList.toggle(classname);
35
+ return this;
36
+ }
37
+ says(innerHTML: string){
38
+ this.element.textContent = innerHTML;
39
+ return this;
40
+ }
41
+ replaceContent(...children: FElement[]){
42
+ this.element.replaceChildren();
43
+ for(var i in children){
44
+ this.element.appendChild(children[i].element);
45
+ }
46
+ return this;
47
+ }
48
+ onEvent(eventName: string, callback: Function){
49
+ this.element.addEventListener(eventName, callback);
50
+ return this;
51
+ }
52
+ addChildren(...children: FElement[]){
53
+ for(var i in children){
54
+ this.element.appendChild(children[i].element);
55
+ }
56
+ return this;
57
+ }
58
+ selfDestruct(){
59
+ this.element.remove();
60
+ }
61
+ }
62
+
63
+ export function ElementByID(id: string){
64
+ let e = document.getElementById(id);
65
+ if(e){
66
+ return new FElement(e);
67
+ }
68
+ else{
69
+ throw new Error("Could not find an element with id \"" + id + "\".");
70
+ }
71
+ }
72
+
73
+ export function SetDocumentContent(...children: FElement[]){
74
+ document.body.replaceChildren();
75
+ for(var i in children){
76
+ document.body.appendChild(children[i].element);
77
+ }
78
+ }
79
+
80
+ class FEdiv extends FElement{constructor(...children: FElement[]){super("div", ...children);}}
81
+ const DIV = (...children: FElement[]) => new FEdiv(...children);
82
+
83
+ class FEbutton extends FElement{
84
+ constructor(...children: FElement[]){
85
+ super("button", ...children);
86
+ }
87
+ does(action: Function){
88
+ this.onEvent("click", action);
89
+ return this;
90
+ }
91
+ }
92
+ const BUTTON = (...children: FElement[]) => new FEbutton(...children);
93
+
94
+ class FEinput extends FElement{constructor(...children: FElement[]){super("input", ...children);}}
95
+ const INPUT = (...children: FElement[]) => new FEinput(...children);
96
+
97
+ class FEp extends FElement{constructor(...children: FElement[]){super("p", ...children);}}
98
+ const P = (...children: FElement[]) => new FEp(...children);
99
+
100
+ class FEul extends FElement{constructor(...children: FElement[]){super("ul", ...children);}}
101
+ const UL = (...children: FElement[]) => new FEul(...children);
102
+
103
+ class FEli extends FElement{constructor(...children: FElement[]){super("li", ...children);}}
104
+ const LI = (...children: FElement[]) => new FEli(...children);
105
+
106
+ class FEa extends FElement{constructor(...children: FElement[]){super("a", ...children);}}
107
+ const A = (...children: FElement[]) => new FEa(...children);
108
+
109
+ class FEform extends FElement{constructor(...children: FElement[]){super("form", ...children);}}
110
+ const FORM = (...children: FElement[]) => new FEa(...children);
111
+ export {FEdiv, FEbutton, FEinput, FEp, FEul, FEli, FEa, FEform}
112
+ export {DIV, BUTTON, INPUT, P, UL, LI, A, FORM}
113
+
114
+
package/package.json ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "name": "@dimension-mismatch/htmltools",
3
+ "version": "0.0.1",
4
+ "description": "Tools for working with html DOM (i hate js frameworks)",
5
+ "main": "htmltools.js",
6
+ "author": "dimension-mismatch"
7
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,2 @@
1
+ {
2
+ }