@degreesign/ui 1.0.2 → 1.0.4

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 +1,132 @@
1
- # DegreeSign UI functions
1
+ # DegreeSign UI functions
2
+
3
+ A lightweight TypeScript library for managing UI elements in web applications.
4
+
5
+ ## Installation
6
+
7
+ Install the package via npm:
8
+
9
+ ```bash
10
+ npm install @degreesign/ui
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ Import the functions from the `@degreesign/ui` package in your TypeScript or JavaScript project:
16
+
17
+ ```javascript
18
+ import { selectElement, selectAll, showElement, hideElement, repeatElements } from '@degreesign/ui';
19
+ ```
20
+
21
+ Below are the available functions and their usage examples.
22
+
23
+ ## Functions
24
+
25
+ ### `selectElement(id: string, parent?: Element) => HTMLElement`
26
+
27
+ Selects a single DOM element by its CSS selector, optionally within a parent element.
28
+
29
+ **Parameters:**
30
+ - `id`: The CSS selector (e.g., `#myId`, `.myClass`) of the element to select.
31
+ - `parent` (optional): The parent element to search within. Defaults to `document`.
32
+
33
+ **Returns:** An `HTMLElement`.
34
+
35
+ **Example:**
36
+ ```javascript
37
+ // Select an element by ID
38
+ const myDiv = selectElement('#myDiv');
39
+ myDiv.textContent = 'Hello, World!';
40
+
41
+ // Select an element within a specific parent
42
+ const parent = selectElement('.container');
43
+ const child = selectElement('.child', parent);
44
+ child.style.color = 'blue';
45
+ ```
46
+
47
+ ### `selectAll(id: string, parent?: Element) => NodeListOf<Element>`
48
+
49
+ Selects all DOM elements matching a CSS selector, optionally within a parent element.
50
+
51
+ **Parameters:**
52
+ - `id`: The CSS selector (e.g., `.myClass`, `div`) to select elements.
53
+ - `parent` (optional): The parent element to search within. Defaults to `document`.
54
+
55
+ **Returns:** A `NodeListOf<Element>`.
56
+
57
+ **Example:**
58
+ ```javascript
59
+ // Select all elements with a class
60
+ const items = selectAll('.item');
61
+ items.forEach(item => item.style.backgroundColor = 'lightgray');
62
+
63
+ // Select all divs within a parent
64
+ const parent = selectElement('#parent');
65
+ const divs = selectAll('div', parent);
66
+ divs.forEach(div => div.classList.add('highlight'));
67
+ ```
68
+
69
+ ### `showElement(element: HTMLElement) => void`
70
+
71
+ Sets an element's display style to `flex`, making it visible.
72
+
73
+ **Parameters:**
74
+ - `element`: The `HTMLElement` to show.
75
+
76
+ **Example:**
77
+ ```javascript
78
+ const myDiv = selectElement('#myDiv');
79
+ showElement(myDiv); // Displays the element with flex layout
80
+ ```
81
+
82
+ ### `hideElement(element: HTMLElement) => void`
83
+
84
+ Sets an element's display style to `none`, hiding it.
85
+
86
+ **Parameters:**
87
+ - `element`: The `HTMLElement` to hide.
88
+
89
+ **Example:**
90
+ ```javascript
91
+ const myDiv = selectElement('#myDiv');
92
+ hideElement(myDiv); // Hides the element
93
+ ```
94
+
95
+ ### `repeatElements({ children?: NodeListOf<Element>, parent: Element, targetCount: number }) => void`
96
+
97
+ Repeats or removes child elements within a parent to match a target count by cloning or removing the first child.
98
+
99
+ **Parameters:**
100
+ - `children` (optional): A `NodeListOf<Element>` containing the child elements to repeat or remove.
101
+ - `parent`: The parent `Element` where children will be added or removed.
102
+ - `targetCount`: The desired number of child elements.
103
+
104
+ **Example:**
105
+ ```javascript
106
+ // HTML structure:
107
+ // <div id="parent">
108
+ // <div class="child">Item</div>
109
+ // </div>
110
+
111
+ // Repeat child elements to a total of 5
112
+ const parent = selectElement('#parent');
113
+ const children = selectAll('.child', parent);
114
+ repeatElements({ parent, children, targetCount: 5 });
115
+ // Result: 5 child divs inside #parent
116
+
117
+ // Reduce to 2 child elements
118
+ repeatElements({ parent, children: selectAll('.child', parent), targetCount: 2 });
119
+ // Result: 2 child divs inside #parent
120
+ ```
121
+
122
+ ## Error Handling
123
+
124
+ The `repeatElements` function includes error handling to catch and log issues when manipulating elements. For example, if the `children` NodeList is invalid or cloning fails, an error will be logged to the console.
125
+
126
+ ## Contributing
127
+
128
+ Contributions are welcome! Please open an issue or submit a pull request at [https://github.com/DegreeSign/ds_ui](https://github.com/DegreeSign/ds_ui).
129
+
130
+ ## License
131
+
132
+ This project is licensed under the MIT License. See the [LICENSE](https://github.com/DegreeSign/ds_ui/blob/main/LICENSE) file for details.
@@ -1,2 +1,2 @@
1
1
  /*! For license information please see degreesign.min.js.LICENSE.txt */
2
- !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.degreesign=t():e.degreesign=t()}(this,(()=>(()=>{"use strict";var e={};return(()=>{var t=e;Object.defineProperty(t,"__esModule",{value:!0}),t.repeatElements=t.hideElement=t.showElement=t.selectAll=t.selectElement=void 0;t.selectElement=e=>document.querySelector(e),t.selectAll=e=>document.querySelectorAll(e),t.showElement=e=>e.style.display="flex",t.hideElement=e=>e.style.display="none",t.repeatElements=({children:e,parent:t,targetCount:l})=>{try{if(e?.length){const o=e?.length||0;if(l>o)for(let n=o;n<l;n++)t.appendChild(e[0]?.cloneNode(!0));else if(l<o&&0!=l)for(let t=o-1;t>=l;t--)e[t]?.remove()}}catch(e){console.log("Error repeating elements",l,e)}}})(),e})()));
2
+ !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.degreesign=t():e.degreesign=t()}(this,(()=>(()=>{"use strict";var e={};return(()=>{var t=e;Object.defineProperty(t,"__esModule",{value:!0}),t.repeatElements=t.hideElement=t.showElement=t.selectAll=t.selectElement=void 0;const l=e=>("string"==typeof e&&(e=document.querySelector(e)),e);t.selectElement=(e,t)=>(l(t)||document)?.querySelector(e),t.selectAll=(e,t)=>(l(t)||document)?.querySelectorAll(e),t.showElement=e=>e&&(e.style.display="flex"),t.hideElement=e=>e&&(e.style.display="none"),t.repeatElements=({children:e,parent:t,targetCount:o})=>{try{const n=l(t);if(e?.length){const t=e?.length||0;if(o>t)for(let l=t;l<o;l++)n?.appendChild(e?.[0]?.cloneNode(!0));else if(o<t&&0!=o)for(let l=t-1;l>=o;l--)e[l]?.remove()}}catch(e){console.log("Error repeating elements",o,e)}}})(),e})()));
package/dist/index.d.ts CHANGED
@@ -1,10 +1,10 @@
1
- declare const selectElement: (id: string) => HTMLElement, selectAll: (id: string) => NodeListOf<Element>, showElement: (element: HTMLElement) => string, hideElement: (element: HTMLElement) => string,
1
+ declare const selectElement: (id: string, parent?: Element | string) => HTMLElement, selectAll: (id: string, parent?: Element | string) => NodeListOf<Element>, showElement: (element: HTMLElement) => string, hideElement: (element: HTMLElement) => string,
2
2
  /** Repeat Elements */
3
3
  repeatElements: ({ children, parent, targetCount, }: {
4
4
  /** Child Element Nodes */
5
5
  children?: NodeListOf<Element>;
6
6
  /** Parent Element */
7
- parent: Element;
7
+ parent: Element | string;
8
8
  /** Target Count */
9
9
  targetCount: number;
10
10
  }) => void;
@@ -1,2 +1,2 @@
1
1
  /*! For license information please see degreesign.node.min.js.LICENSE.txt */
2
- (()=>{"use strict";var e={};(()=>{var l=e;Object.defineProperty(l,"__esModule",{value:!0}),l.repeatElements=l.hideElement=l.showElement=l.selectAll=l.selectElement=void 0;l.selectElement=e=>document.querySelector(e),l.selectAll=e=>document.querySelectorAll(e),l.showElement=e=>e.style.display="flex",l.hideElement=e=>e.style.display="none",l.repeatElements=({children:e,parent:l,targetCount:t})=>{try{if(e?.length){const r=e?.length||0;if(t>r)for(let n=r;n<t;n++)l.appendChild(e[0]?.cloneNode(!0));else if(t<r&&0!=t)for(let l=r-1;l>=t;l--)e[l]?.remove()}}catch(e){console.log("Error repeating elements",t,e)}}})();var l=exports;for(var t in e)l[t]=e[t];e.__esModule&&Object.defineProperty(l,"__esModule",{value:!0})})();
2
+ (()=>{"use strict";var e={};(()=>{var t=e;Object.defineProperty(t,"__esModule",{value:!0}),t.repeatElements=t.hideElement=t.showElement=t.selectAll=t.selectElement=void 0;const l=e=>("string"==typeof e&&(e=document.querySelector(e)),e);t.selectElement=(e,t)=>(l(t)||document)?.querySelector(e),t.selectAll=(e,t)=>(l(t)||document)?.querySelectorAll(e),t.showElement=e=>e&&(e.style.display="flex"),t.hideElement=e=>e&&(e.style.display="none"),t.repeatElements=({children:e,parent:t,targetCount:o})=>{try{const r=l(t);if(e?.length){const t=e?.length||0;if(o>t)for(let l=t;l<o;l++)r?.appendChild(e?.[0]?.cloneNode(!0));else if(o<t&&0!=o)for(let l=t-1;l>=o;l--)e[l]?.remove()}}catch(e){console.log("Error repeating elements",o,e)}}})();var t=exports;for(var l in e)t[l]=e[l];e.__esModule&&Object.defineProperty(t,"__esModule",{value:!0})})();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@degreesign/ui",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "DegreeSign UI Controls",
5
5
  "main": "dist/node/degreesign.node.min.js",
6
6
  "module": "dist/node/degreesign.node.min.js",