@loudy/lib 0.0.8 → 0.0.9
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/README.md +1 -23
- package/dist/index.d.mts +67 -3
- package/dist/index.iife.js +1 -0
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,23 +1 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
A starter for creating a TypeScript package.
|
|
4
|
-
|
|
5
|
-
## Development
|
|
6
|
-
|
|
7
|
-
- Install dependencies:
|
|
8
|
-
|
|
9
|
-
```bash
|
|
10
|
-
npm install
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
- Run the unit tests:
|
|
14
|
-
|
|
15
|
-
```bash
|
|
16
|
-
npm run test
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
- Build the library:
|
|
20
|
-
|
|
21
|
-
```bash
|
|
22
|
-
npm run build
|
|
23
|
-
```
|
|
1
|
+
# a javascript library to do the boring part of webdev
|
package/dist/index.d.mts
CHANGED
|
@@ -5,22 +5,86 @@ type Signal<T> = {
|
|
|
5
5
|
subscribe(fn: (value: T) => void): () => void;
|
|
6
6
|
};
|
|
7
7
|
declare function signal<T>(initialValue: T): Signal<T>;
|
|
8
|
-
declare function
|
|
9
|
-
declare function effect(fn: () => void): void;
|
|
8
|
+
declare function effect<T>(signal: Signal<T>, fn: (value: T) => void): () => void;
|
|
10
9
|
//#endregion
|
|
11
10
|
//#region src/index.d.ts
|
|
12
11
|
declare function $(elementOrFn: string | (() => void)): LoudLibElement | void | null;
|
|
13
12
|
declare class LoudLibElement {
|
|
14
13
|
constructor(element: Element);
|
|
15
14
|
element: Element;
|
|
15
|
+
/**
|
|
16
|
+
* Allows for adding event listeners to elements
|
|
17
|
+
* @param event the event you want to listen to
|
|
18
|
+
* @param fn the handler for the event
|
|
19
|
+
*/
|
|
16
20
|
on(event: EventHandlers, fn: (e: Event) => void): this;
|
|
21
|
+
/**
|
|
22
|
+
* Adds a class to an element
|
|
23
|
+
* @param className name of the class that should be added
|
|
24
|
+
*/
|
|
17
25
|
addClass(className: string): this;
|
|
26
|
+
/**
|
|
27
|
+
* removes a class from an element
|
|
28
|
+
* @param className name of the class you want to remove
|
|
29
|
+
*/
|
|
30
|
+
removeClass(className: string): this;
|
|
31
|
+
/**
|
|
32
|
+
* toggles a class of an element
|
|
33
|
+
* @param className name of the class you want to toggle
|
|
34
|
+
*/
|
|
35
|
+
toggleClass(className: string): this;
|
|
18
36
|
hidden: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* hides an element
|
|
39
|
+
*/
|
|
19
40
|
hide(): this;
|
|
41
|
+
/**
|
|
42
|
+
* shows an element
|
|
43
|
+
*/
|
|
20
44
|
show(): this;
|
|
45
|
+
/**
|
|
46
|
+
* toggles if an element is visible or not
|
|
47
|
+
*/
|
|
21
48
|
toggle(): this;
|
|
49
|
+
/**
|
|
50
|
+
* get/setter for the textContent of an element
|
|
51
|
+
* @example
|
|
52
|
+
* $(".text").text() // gets the textcontent
|
|
53
|
+
* @example
|
|
54
|
+
* $(".text").text("example") // sets the textcontent
|
|
55
|
+
*/
|
|
22
56
|
text(content?: string): string | this;
|
|
57
|
+
/**
|
|
58
|
+
* get/setter for the attributes of an element
|
|
59
|
+
* @example
|
|
60
|
+
* $(".img").attr("src") // gets the attribute
|
|
61
|
+
* @example
|
|
62
|
+
* $(".img").attr("src", "/image.png") // sets the attribute
|
|
63
|
+
*/
|
|
64
|
+
attr(name: string, value?: string): string | this | null;
|
|
65
|
+
/**
|
|
66
|
+
* get/setter for the input of an input element
|
|
67
|
+
* @example
|
|
68
|
+
* $(".input").val() // gets the value
|
|
69
|
+
* @example
|
|
70
|
+
* $(".input").val("example") // sets the value
|
|
71
|
+
*/
|
|
72
|
+
val(value?: string): string | this;
|
|
73
|
+
/**
|
|
74
|
+
* get/setter for the innerHtml of an element
|
|
75
|
+
* @example
|
|
76
|
+
* $(".img").html() // gets the innerHtml
|
|
77
|
+
* @example
|
|
78
|
+
* $(".img").html("<p>example</p>") // sets the innerHtml
|
|
79
|
+
*/
|
|
80
|
+
html(content?: string): string | this;
|
|
81
|
+
/**
|
|
82
|
+
* removes the element
|
|
83
|
+
* @example
|
|
84
|
+
* $(".img").remove()
|
|
85
|
+
*/
|
|
86
|
+
remove(): void;
|
|
23
87
|
}
|
|
24
88
|
type EventHandlers = { [K in Extract<keyof GlobalEventHandlers, `on${string}`>]: K extends `on${infer E}` ? E : never }[Extract<keyof GlobalEventHandlers, `on${string}`>];
|
|
25
89
|
//#endregion
|
|
26
|
-
export { $, LoudLibElement, Signal,
|
|
90
|
+
export { $, LoudLibElement, Signal, effect, signal };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var loudlib=(function(e){function t(e){let t=e,n=new Set;return{get(){return t},set(e){t=e,n.forEach(e=>e(t))},subscribe(e){return n.add(e),e(t),()=>n.delete(e)}}}function n(e,t){return e.subscribe(t)}function r(e){if(typeof e==`function`){document.readyState===`loading`?document.addEventListener(`DOMContentLoaded`,e):e();return}let t=document.querySelector(e);return t?new i(t):null}var i=class{constructor(e){this.element=e}element;on(e,t){return this.element.addEventListener(e,t),this}addClass(e){return this.element.classList.add(e),this}removeClass(e){return this.element.classList.remove(e),this}toggleClass(e){return this.element.classList.toggle(e),this}hidden=!1;hide(){return this.element.style.display=`none`,this.hidden=!0,this}show(){return this.element.style.display=``,this.hidden=!1,this}toggle(){return this.hidden?this.show():this.hide(),this}text(e){return e===void 0?this.element.textContent:(this.element.textContent=e,this)}attr(e,t){return t===void 0?this.element.getAttribute(e):(this.element.setAttribute(e,t),this)}val(e){return e===void 0?this.element.value:(this.element.value=e,this)}html(e){return e===void 0?this.element.innerHTML:(this.element.innerHTML=e,this)}remove(){this.element.remove()}};return e.$=r,e.LoudLibElement=i,e.effect=n,e.signal=t,e})({});
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function e(e){let t=e,n=new Set;return{get(){return t},set(e){t=e,n.forEach(e=>e(t))},subscribe(e){return n.add(e),e(t),()=>n.delete(e)}}}function t(t){return e(t
|
|
1
|
+
function e(e){let t=e,n=new Set;return{get(){return t},set(e){t=e,n.forEach(e=>e(t))},subscribe(e){return n.add(e),e(t),()=>n.delete(e)}}}function t(e,t){return e.subscribe(t)}function n(e){if(typeof e==`function`){document.readyState===`loading`?document.addEventListener(`DOMContentLoaded`,e):e();return}let t=document.querySelector(e);return t?new r(t):null}var r=class{constructor(e){this.element=e}element;on(e,t){return this.element.addEventListener(e,t),this}addClass(e){return this.element.classList.add(e),this}removeClass(e){return this.element.classList.remove(e),this}toggleClass(e){return this.element.classList.toggle(e),this}hidden=!1;hide(){return this.element.style.display=`none`,this.hidden=!0,this}show(){return this.element.style.display=``,this.hidden=!1,this}toggle(){return this.hidden?this.show():this.hide(),this}text(e){return e===void 0?this.element.textContent:(this.element.textContent=e,this)}attr(e,t){return t===void 0?this.element.getAttribute(e):(this.element.setAttribute(e,t),this)}val(e){return e===void 0?this.element.value:(this.element.value=e,this)}html(e){return e===void 0?this.element.innerHTML:(this.element.innerHTML=e,this)}remove(){this.element.remove()}};export{n as $,r as LoudLibElement,t as effect,e as signal};
|