jsquery_node 1.0.14 → 1.0.15

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.
@@ -0,0 +1,78 @@
1
+ export declare class Extension {
2
+ constructor();
3
+ get(): {
4
+ $: {};
5
+ Element: {};
6
+ static_Element: {};
7
+ static_ElementArray: {};
8
+ ElementArray: {};
9
+ JSQuery: {};
10
+ };
11
+ $(): {};
12
+ Element(): {};
13
+ ElementArray(): {};
14
+ static_Element(): {};
15
+ static_ElementArray(): {};
16
+ JSQuery(): {};
17
+ }
18
+ export declare class Element {
19
+ #private;
20
+ elt: HTMLElement;
21
+ static from(elt: HTMLElement): Element | null;
22
+ static from(elt: NodeList | HTMLCollection): ElementArray;
23
+ new(): Element;
24
+ constructor(elt: HTMLElement);
25
+ on(e: any, func: (this: HTMLElement, ev: any) => any, s?: boolean | AddEventListenerOptions): this;
26
+ removeEvent(e: any, func: (this: HTMLElement, ev: any) => any, s?: boolean | AddEventListenerOptions): this;
27
+ trigger(e: any): this;
28
+ css(styles: Record<string, any>): this;
29
+ getCss(style: string): any;
30
+ props(props: Record<string, any>): this;
31
+ getProp(name: string): string;
32
+ id(): string;
33
+ id(val: string): this;
34
+ class(names: string | string[]): this;
35
+ removeClass(names: string | string[]): this;
36
+ toggleClass(names: string | string[]): this;
37
+ hasClass(name: string): boolean;
38
+ $(q: any): Element | null;
39
+ all(q: any): ElementArray;
40
+ is(q: string): boolean;
41
+ child(children: Element | Element[]): this;
42
+ remove(): this;
43
+ get children(): ElementArray;
44
+ html(): string;
45
+ html(val: string): this;
46
+ text(): string;
47
+ text(val: string): this;
48
+ rect(): any;
49
+ value(): string;
50
+ value(val: string): this;
51
+ checked(): boolean;
52
+ checked(val: boolean): this;
53
+ click(func?: (this: HTMLElement, ev: any) => any, s?: boolean | AddEventListenerOptions): this;
54
+ }
55
+ export declare class Caching extends Extension {
56
+ $(): {
57
+ cache<T extends (...args: any[]) => any>(func: T): T;
58
+ };
59
+ }
60
+ export declare class ElementArray extends Array<Element> {
61
+ on<K extends keyof DocumentEventMap>(e: K, func: (this: HTMLElement, ev: DocumentEventMap[K]) => any, s?: boolean | AddEventListenerOptions): this;
62
+ rect(): any[];
63
+ hasClass(c: string): boolean[];
64
+ is(q: string): boolean[];
65
+ checked(): boolean[];
66
+ checked(val: boolean): this;
67
+ trigger(e: any): this;
68
+ css(styles: Record<string, any>): this;
69
+ props(props: Record<string, any>): this;
70
+ class(names: string | string[]): this;
71
+ removeClass(names: string | string[]): this;
72
+ toggleClass(names: string | string[]): this;
73
+ remove(): this;
74
+ new(): ElementArray;
75
+ click(func: (this: HTMLElement, ev: any) => any, s?: boolean | AddEventListenerOptions): this;
76
+ }
77
+ export declare const Plugin: typeof Extension;
78
+ export type Plugin = Extension;
package/jsquerymod.js ADDED
@@ -0,0 +1,282 @@
1
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
2
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
3
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
4
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
5
+ };
6
+ var _Element_instances, _Element_TriggerEvent;
7
+ function toArray(elt) {
8
+ return elt instanceof NodeList || elt instanceof HTMLCollection;
9
+ }
10
+ function toElt(elt) {
11
+ if (elt instanceof Element)
12
+ return elt.elt;
13
+ return elt;
14
+ }
15
+ export class Extension {
16
+ constructor() {
17
+ if (this.constructor === Extension) {
18
+ throw new Error("you can't make an instance of class: JSQuery.Extension");
19
+ }
20
+ }
21
+ get() {
22
+ return {
23
+ $: this.$(),
24
+ Element: this.Element(),
25
+ static_Element: this.static_Element(),
26
+ static_ElementArray: this.static_ElementArray(),
27
+ ElementArray: this.ElementArray(),
28
+ JSQuery: this.JSQuery(),
29
+ };
30
+ }
31
+ $() {
32
+ return {};
33
+ }
34
+ Element() {
35
+ return {};
36
+ }
37
+ ElementArray() {
38
+ return {};
39
+ }
40
+ static_Element() {
41
+ return {};
42
+ }
43
+ static_ElementArray() {
44
+ return {};
45
+ }
46
+ JSQuery() {
47
+ return {};
48
+ }
49
+ }
50
+ export class Element {
51
+ static from(elt) {
52
+ if (elt == null) {
53
+ return null;
54
+ }
55
+ if (toArray(elt)) {
56
+ return ElementArray.from(elt).map((v) => new this(v));
57
+ }
58
+ return new this(elt);
59
+ }
60
+ new() {
61
+ return Element.from(this.elt);
62
+ }
63
+ constructor(elt) {
64
+ _Element_instances.add(this);
65
+ this.elt = elt;
66
+ }
67
+ on(e, func, s) {
68
+ this.elt.addEventListener(e, func, s);
69
+ return this;
70
+ }
71
+ removeEvent(e, func, s) {
72
+ this.elt.removeEventListener(e, func, s);
73
+ return this;
74
+ }
75
+ trigger(e) {
76
+ this.elt[e]();
77
+ return this;
78
+ }
79
+ css(styles) {
80
+ for (const [name, val] of Object.entries(styles)) {
81
+ this.elt.style[name] = val;
82
+ }
83
+ return this;
84
+ }
85
+ getCss(style) {
86
+ return this.elt.style[style];
87
+ }
88
+ props(props) {
89
+ for (const [name, val] of Object.entries(props)) {
90
+ if (val === null) {
91
+ this.elt.removeAttribute(name);
92
+ }
93
+ else {
94
+ this.elt.setAttribute(name, val);
95
+ }
96
+ }
97
+ return this;
98
+ }
99
+ getProp(name) {
100
+ return this.elt.getAttribute(name);
101
+ }
102
+ id(val) {
103
+ if (val == undefined)
104
+ return this.getProp("id");
105
+ this.props({ id: val });
106
+ return this;
107
+ }
108
+ class(names) {
109
+ if (Array.isArray(names)) {
110
+ names.forEach((name) => this.elt.classList.add(name));
111
+ }
112
+ else {
113
+ this.elt.classList.add(names);
114
+ }
115
+ return this;
116
+ }
117
+ removeClass(names) {
118
+ if (Array.isArray(names)) {
119
+ names.forEach((name) => this.elt.classList.remove(name));
120
+ }
121
+ else {
122
+ this.elt.classList.remove(names);
123
+ }
124
+ return this;
125
+ }
126
+ toggleClass(names) {
127
+ if (Array.isArray(names)) {
128
+ names.forEach((name) => this.elt.classList.toggle(name));
129
+ }
130
+ else {
131
+ this.elt.classList.toggle(names);
132
+ }
133
+ return this;
134
+ }
135
+ hasClass(name) {
136
+ return this.elt.classList.contains(name);
137
+ }
138
+ $(q) {
139
+ return Element.from(this.elt.querySelector(q));
140
+ }
141
+ all(q) {
142
+ return Element.from(this.elt.querySelectorAll(q));
143
+ }
144
+ is(q) {
145
+ return this.elt.matches(q);
146
+ }
147
+ child(children) {
148
+ if (Array.isArray(children)) {
149
+ children.forEach((child) => this.elt.appendChild(toElt(child)));
150
+ }
151
+ else {
152
+ this.elt.appendChild(toElt(children));
153
+ }
154
+ return this;
155
+ }
156
+ remove() {
157
+ this.elt.remove();
158
+ return this;
159
+ }
160
+ get children() {
161
+ return Element.from(this.elt.children);
162
+ }
163
+ html(val) {
164
+ if (val == undefined)
165
+ return this.elt.innerHTML;
166
+ this.elt.innerHTML = val;
167
+ return this;
168
+ }
169
+ text(val) {
170
+ if (val == undefined)
171
+ return this.elt.textContent;
172
+ this.elt.textContent = val;
173
+ return this;
174
+ }
175
+ rect() {
176
+ return this.elt.getBoundingClientRect().toJSON();
177
+ }
178
+ value(val) {
179
+ if (val == undefined)
180
+ return this.elt.value;
181
+ this.elt.value = val;
182
+ return this;
183
+ }
184
+ checked(val) {
185
+ if (val == undefined)
186
+ return this.elt.checked;
187
+ this.elt.checked = val;
188
+ return this;
189
+ }
190
+ //events
191
+ click(func, s) {
192
+ __classPrivateFieldGet(this, _Element_instances, "m", _Element_TriggerEvent).call(this, "click", func, s);
193
+ return this;
194
+ }
195
+ }
196
+ _Element_instances = new WeakSet(), _Element_TriggerEvent = function _Element_TriggerEvent(e, func, s) {
197
+ if (!func) {
198
+ this.trigger(e);
199
+ return;
200
+ }
201
+ this.on(e, func, s);
202
+ };
203
+ export class Caching extends Extension {
204
+ $() {
205
+ return {
206
+ cache(func) {
207
+ const f = (...args) => {
208
+ const val = JSON.stringify(args);
209
+ if (f.cache.hasOwnProperty(val)) {
210
+ return f.cache[val];
211
+ }
212
+ const temp = func(...args);
213
+ f.cache[val] = temp;
214
+ return temp;
215
+ };
216
+ f.cache = {};
217
+ return f;
218
+ },
219
+ };
220
+ }
221
+ }
222
+ export class ElementArray extends Array {
223
+ on(e, func, s) {
224
+ this.forEach((v) => v.on(e, func, s));
225
+ return this;
226
+ }
227
+ rect() {
228
+ return this.map((v) => v.rect());
229
+ }
230
+ hasClass(c) {
231
+ return this.map((v) => v.hasClass(c));
232
+ }
233
+ is(q) {
234
+ return this.map((v) => v.is(q));
235
+ }
236
+ checked(val) {
237
+ if (val !== undefined) {
238
+ this.forEach((v) => v.checked(val));
239
+ return this;
240
+ }
241
+ return this.map((v) => v.checked());
242
+ }
243
+ trigger(e) {
244
+ this.forEach((v) => v.trigger(e));
245
+ return this;
246
+ }
247
+ css(styles) {
248
+ this.forEach((v) => v.css(styles));
249
+ return this;
250
+ }
251
+ props(props) {
252
+ this.forEach((v) => v.props(props));
253
+ return this;
254
+ }
255
+ class(names) {
256
+ this.forEach((v) => v.class(names));
257
+ return this;
258
+ }
259
+ removeClass(names) {
260
+ this.forEach((v) => v.removeClass(names));
261
+ return this;
262
+ }
263
+ toggleClass(names) {
264
+ this.forEach((v) => v.toggleClass(names));
265
+ return this;
266
+ }
267
+ remove() {
268
+ this.forEach((v) => v.remove());
269
+ return this;
270
+ }
271
+ new() {
272
+ const temp = new ElementArray();
273
+ this.forEach((v) => temp.push(v.new()));
274
+ return temp;
275
+ }
276
+ //events
277
+ click(func, s) {
278
+ this.forEach((v) => v.click(func, s));
279
+ return this;
280
+ }
281
+ }
282
+ export const Plugin = Extension;
package/jsquerymod.ts ADDED
@@ -0,0 +1,284 @@
1
+ function toArray(elt: NodeList | HTMLCollection | HTMLElement) {
2
+ return elt instanceof NodeList || elt instanceof HTMLCollection;
3
+ }
4
+ function toElt(elt: Element): HTMLElement {
5
+ if (elt instanceof Element) return elt.elt;
6
+ return elt;
7
+ }
8
+ export class Extension {
9
+ constructor() {
10
+ if (this.constructor === Extension) {
11
+ throw new Error(
12
+ "you can't make an instance of class: JSQuery.Extension"
13
+ );
14
+ }
15
+ }
16
+ get() {
17
+ return {
18
+ $: this.$(),
19
+ Element: this.Element(),
20
+ static_Element: this.static_Element(),
21
+ static_ElementArray: this.static_ElementArray(),
22
+ ElementArray: this.ElementArray(),
23
+ JSQuery: this.JSQuery(),
24
+ };
25
+ }
26
+ $() {
27
+ return {};
28
+ }
29
+ Element() {
30
+ return {};
31
+ }
32
+ ElementArray() {
33
+ return {};
34
+ }
35
+
36
+ static_Element() {
37
+ return {};
38
+ }
39
+ static_ElementArray() {
40
+ return {};
41
+ }
42
+
43
+ JSQuery() {
44
+ return {};
45
+ }
46
+ }
47
+ export class Element {
48
+ elt: HTMLElement;
49
+ #TriggerEvent(e: any, func: (this:HTMLElement, ev: any) => any, s?: boolean | AddEventListenerOptions) {
50
+ if (!func) {
51
+ this.trigger(e);
52
+ return;
53
+ }
54
+ this.on(e, func, s);
55
+ }
56
+ static from(elt: HTMLElement): Element|null;
57
+ static from(elt: NodeList|HTMLCollection): ElementArray;
58
+ static from(elt: HTMLElement | NodeList | HTMLCollection): Element | ElementArray | null {
59
+ if (elt == null) {
60
+ return null;
61
+ }
62
+ if (toArray(elt)) {
63
+ return ElementArray.from(elt).map((v) => new this(v as HTMLElement)) as ElementArray;
64
+ }
65
+ return new this(elt);
66
+ }
67
+ new() {
68
+ return Element.from(this.elt);
69
+ }
70
+ constructor(elt:HTMLElement) {
71
+ this.elt = elt;
72
+ }
73
+ on(e: any, func: (this:HTMLElement, ev: any) => any, s?: boolean | AddEventListenerOptions) {
74
+ this.elt.addEventListener(e, func, s);
75
+ return this;
76
+ }
77
+ removeEvent(e: any, func: (this:HTMLElement, ev: any) => any, s?: boolean | AddEventListenerOptions) {
78
+ this.elt.removeEventListener(e, func, s);
79
+ return this;
80
+ }
81
+ trigger(e: any) {
82
+ this.elt[e]();
83
+ return this;
84
+ }
85
+ css(styles: Record<string, any>) {
86
+ for (const [name, val] of Object.entries(styles)) {
87
+ this.elt.style[name] = val;
88
+ }
89
+ return this;
90
+ }
91
+ getCss(style: string) {
92
+ return this.elt.style[style];
93
+ }
94
+ props(props: Record<string, any>) {
95
+ for (const [name, val] of Object.entries(props)) {
96
+ if(val === null) {
97
+ this.elt.removeAttribute(name);
98
+ } else {
99
+ this.elt.setAttribute(name, val);
100
+ }
101
+ }
102
+ return this;
103
+ }
104
+ getProp(name: string) {
105
+ return this.elt.getAttribute(name);
106
+ }
107
+ id(): string;
108
+ id(val: string): this;
109
+ id(val?: string): string | this {
110
+ if (val == undefined) return this.getProp("id");
111
+ this.props({ id: val });
112
+ return this;
113
+ }
114
+ class(names: string | string[]) {
115
+ if (Array.isArray(names)) {
116
+ names.forEach((name) => this.elt.classList.add(name));
117
+ } else {
118
+ this.elt.classList.add(names);
119
+ }
120
+ return this;
121
+ }
122
+ removeClass(names: string | string[]) {
123
+ if (Array.isArray(names)) {
124
+ names.forEach((name) => this.elt.classList.remove(name));
125
+ } else {
126
+ this.elt.classList.remove(names);
127
+ }
128
+ return this;
129
+ }
130
+ toggleClass(names: string | string[]) {
131
+ if (Array.isArray(names)) {
132
+ names.forEach((name) => this.elt.classList.toggle(name));
133
+ } else {
134
+ this.elt.classList.toggle(names);
135
+ }
136
+ return this;
137
+ }
138
+ hasClass(name: string) {
139
+ return this.elt.classList.contains(name);
140
+ }
141
+ $(q: any): Element|null {
142
+ return Element.from(this.elt.querySelector(q)) as any;
143
+ }
144
+ all(q: any): ElementArray {
145
+ return Element.from(this.elt.querySelectorAll(q)) as any;
146
+ }
147
+ is(q:string) {
148
+ return this.elt.matches(q);
149
+ }
150
+ child(children: Element|Element[]) {
151
+ if (Array.isArray(children)) {
152
+ children.forEach((child:Element) => this.elt.appendChild(toElt(child)));
153
+ } else {
154
+ this.elt.appendChild(toElt(children));
155
+ }
156
+ return this;
157
+ }
158
+ remove() {
159
+ this.elt.remove();
160
+ return this;
161
+ }
162
+ get children() {
163
+ return Element.from(this.elt.children);
164
+ }
165
+ html(): string;
166
+ html(val: string): this;
167
+ html(val?:string): string|this {
168
+ if (val == undefined) return this.elt.innerHTML;
169
+ this.elt.innerHTML = val;
170
+ return this;
171
+ }
172
+ text(): string;
173
+ text(val: string): this;
174
+ text(val?: string): string | this {
175
+ if (val == undefined) return this.elt.textContent;
176
+ this.elt.textContent = val;
177
+ return this;
178
+ }
179
+ rect() {
180
+ return this.elt.getBoundingClientRect().toJSON();
181
+ }
182
+ value(): string;
183
+ value(val: string): this;
184
+ value(val?: string): string | this {
185
+ if (val == undefined) return (this.elt as any).value;
186
+ (this.elt as any).value = val;
187
+ return this;
188
+ }
189
+ checked(): boolean;
190
+ checked(val: boolean): this;
191
+ checked(val?: boolean): boolean| this {
192
+ if (val == undefined) return (this.elt as any).checked;
193
+ (this.elt as any).checked = val;
194
+ return this;
195
+ }
196
+ //events
197
+ click(func?: (this:HTMLElement, ev: any) => any, s?: boolean | AddEventListenerOptions) {
198
+ this.#TriggerEvent("click", func, s);
199
+ return this;
200
+ }
201
+ }
202
+ export class Caching extends Extension {
203
+ $() {
204
+ return {
205
+ cache<T extends (...args:any[])=>any>(func: T): T {
206
+ const f = (...args: Parameters<T>): ReturnType<T> => {
207
+ const val = JSON.stringify(args);
208
+ if (f.cache.hasOwnProperty(val)) {
209
+ return f.cache[val];
210
+ }
211
+ const temp = func(...args);
212
+ f.cache[val] = temp;
213
+ return temp;
214
+ };
215
+ f.cache = {};
216
+ return f as any;
217
+ },
218
+ };
219
+ }
220
+ }
221
+ export class ElementArray extends Array<Element> {
222
+ on<K extends keyof DocumentEventMap>(e: K, func: (this: HTMLElement, ev: DocumentEventMap[K])=>any, s?: boolean | AddEventListenerOptions) {
223
+ this.forEach((v) => v.on(e, func, s));
224
+ return this;
225
+ }
226
+ rect() {
227
+ return this.map((v) => v.rect());
228
+ }
229
+ hasClass(c:string) {
230
+ return this.map((v) => v.hasClass(c));
231
+ }
232
+ is(q:string) {
233
+ return this.map((v) => v.is(q));
234
+ }
235
+ checked(): boolean[];
236
+ checked(val: boolean): this;
237
+ checked(val?: boolean): this | boolean[] {
238
+ if (val !== undefined) {
239
+ this.forEach((v) => v.checked(val));
240
+ return this;
241
+ }
242
+ return this.map((v) => v.checked()) as any;
243
+ }
244
+ trigger(e: any) {
245
+ this.forEach((v) => v.trigger(e));
246
+ return this;
247
+ }
248
+ css(styles: Record<string, any>) {
249
+ this.forEach((v) => v.css(styles));
250
+ return this;
251
+ }
252
+ props(props: Record<string, any>) {
253
+ this.forEach((v) => v.props(props));
254
+ return this;
255
+ }
256
+ class(names: string | string[]) {
257
+ this.forEach((v) => v.class(names));
258
+ return this;
259
+ }
260
+ removeClass(names: string | string[]) {
261
+ this.forEach((v) => v.removeClass(names));
262
+ return this;
263
+ }
264
+ toggleClass(names: string | string[]) {
265
+ this.forEach((v) => v.toggleClass(names));
266
+ return this;
267
+ }
268
+ remove() {
269
+ this.forEach((v) => v.remove());
270
+ return this;
271
+ }
272
+ new() {
273
+ const temp = new ElementArray();
274
+ this.forEach((v) => temp.push(v.new() as any));
275
+ return temp;
276
+ }
277
+ //events
278
+ click(func: (this:HTMLElement, ev: any) => any, s?: boolean | AddEventListenerOptions) {
279
+ this.forEach((v) => v.click(func, s));
280
+ return this;
281
+ }
282
+ }
283
+ export const Plugin = Extension;
284
+ export type Plugin = Extension;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jsquery_node",
3
- "version": "1.0.14",
3
+ "version": "1.0.15",
4
4
  "description": "jsquery",
5
5
  "homepage": "https://github.com/chickencuber/jsquery_node#readme",
6
6
  "bugs": {
package/tsconfig.json CHANGED
@@ -2,6 +2,7 @@
2
2
  "compilerOptions": {
3
3
  "declaration": true,
4
4
  "module": "esnext",
5
- "target": "es2020"
5
+ "target": "es2020",
6
+ "allowImportingTsExtensions": true
6
7
  }
7
8
  }