@loudy/lib 0.0.8 → 0.1.0

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 CHANGED
@@ -1,23 +1 @@
1
- # tsdown-starter
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,92 @@ 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 computed<T>(fn: () => T): Signal<T>;
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
+ * Allows for removing event listeners from elements
23
+ * @param event the event type
24
+ * @param fn this needs to be the exact same handler function as used in on()
25
+ */
26
+ off(event: EventHandlers, fn: (e: Event) => void): this;
27
+ /**
28
+ * Adds a class to an element
29
+ * @param className name of the class that should be added
30
+ */
17
31
  addClass(className: string): this;
32
+ /**
33
+ * removes a class from an element
34
+ * @param className name of the class you want to remove
35
+ */
36
+ removeClass(className: string): this;
37
+ /**
38
+ * toggles a class of an element
39
+ * @param className name of the class you want to toggle
40
+ */
41
+ toggleClass(className: string): this;
18
42
  hidden: boolean;
43
+ /**
44
+ * hides an element
45
+ */
19
46
  hide(): this;
47
+ /**
48
+ * shows an element
49
+ */
20
50
  show(): this;
51
+ /**
52
+ * toggles if an element is visible or not
53
+ */
21
54
  toggle(): this;
55
+ /**
56
+ * get/setter for the textContent of an element
57
+ * @example
58
+ * $(".text").text() // gets the textcontent
59
+ * @example
60
+ * $(".text").text("example") // sets the textcontent
61
+ */
22
62
  text(content?: string): string | this;
63
+ /**
64
+ * get/setter for the attributes of an element
65
+ * @example
66
+ * $(".img").attr("src") // gets the attribute
67
+ * @example
68
+ * $(".img").attr("src", "/image.png") // sets the attribute
69
+ */
70
+ attr(name: string, value?: string): string | this | null;
71
+ /**
72
+ * get/setter for the input of an input element
73
+ * @example
74
+ * $(".input").val() // gets the value
75
+ * @example
76
+ * $(".input").val("example") // sets the value
77
+ */
78
+ val(value?: string): string | this;
79
+ /**
80
+ * get/setter for the innerHtml of an element
81
+ * @example
82
+ * $(".img").html() // gets the innerHtml
83
+ * @example
84
+ * $(".img").html("<p>example</p>") // sets the innerHtml
85
+ */
86
+ html(content?: string): string | this;
87
+ /**
88
+ * removes the element
89
+ * @example
90
+ * $(".img").remove()
91
+ */
92
+ remove(): void;
23
93
  }
24
94
  type EventHandlers = { [K in Extract<keyof GlobalEventHandlers, `on${string}`>]: K extends `on${infer E}` ? E : never }[Extract<keyof GlobalEventHandlers, `on${string}`>];
25
95
  //#endregion
26
- export { $, LoudLibElement, Signal, computed, effect, signal };
96
+ 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}off(e,t){return this.element.removeEventListener(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())}function n(e){e()}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}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)}};export{r as $,i as LoudLibElement,t as computed,n as effect,e as signal};
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}off(e,t){return this.element.removeEventListener(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};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@loudy/lib",
3
3
  "type": "module",
4
- "version": "0.0.8",
4
+ "version": "0.1.0",
5
5
  "description": "library for various stuff.",
6
6
  "author": "loudsynth",
7
7
  "license": "MIT",