@medyll/idae-be 0.1.0 → 0.2.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/README.md CHANGED
@@ -1,58 +1,154 @@
1
- # create-svelte
2
-
3
- Everything you need to build a Svelte library, powered by [`create-svelte`](https://github.com/sveltejs/kit/tree/main/packages/create-svelte).
4
-
5
- Read more about creating a library [in the docs](https://kit.svelte.dev/docs/packaging).
6
-
7
- ## Creating a project
8
-
9
- If you're seeing this, you've probably already done this step. Congrats!
10
-
11
- ```bash
12
- # create a new project in the current directory
13
- npm create svelte@latest
14
-
15
- # create a new project in my-app
16
- npm create svelte@latest my-app
17
- ```
18
-
19
- ## Developing
20
-
21
- Once you've created a project and installed dependencies with `npm install` (or `pnpm install` or `yarn`), start a development server:
22
-
23
- ```bash
24
- npm run dev
25
-
26
- # or start the server and open the app in a new browser tab
27
- npm run dev -- --open
28
- ```
29
-
30
- Everything inside `src/lib` is part of your library, everything inside `src/routes` can be used as a showcase or preview app.
31
-
32
- ## Building
33
-
34
- To build your library:
35
-
36
- ```bash
37
- npm run package
38
- ```
39
-
40
- To create a production version of your showcase app:
41
-
42
- ```bash
43
- npm run build
44
- ```
45
-
46
- You can preview the production build with `npm run preview`.
47
-
48
- > To deploy your app, you may need to install an [adapter](https://kit.svelte.dev/docs/adapters) for your target environment.
49
-
50
- ## Publishing
51
-
52
- Go into the `package.json` and give your package the desired name through the `"name"` option. Also consider adding a `"license"` field and point it to a `LICENSE` file which you can create from a template (one popular option is the [MIT license](https://opensource.org/license/mit/)).
53
-
54
- To publish your library to [npm](https://www.npmjs.com):
55
-
56
- ```bash
57
- npm publish
58
- ```
1
+
2
+ # @medyll/idae-be
3
+
4
+ A powerful DOM manipulation library with a callback-based approach for precise element targeting.
5
+
6
+ ## Installation
7
+
8
+ ```bash
9
+ npm install @medyll/idae-be
10
+ ```
11
+
12
+ ## Key Features
13
+
14
+ - Root object persistence for consistent chaining
15
+ - Callback-based element manipulation for precise targeting
16
+ - Comprehensive DOM traversal and manipulation
17
+ - Event handling, style management, and attribute control
18
+ - Timer integration for dynamic operations
19
+
20
+ ## Unique Approach
21
+
22
+ Unlike jQuery and other chained libraries, `@medyll/idae-be` always returns the root object. This approach allows for consistent chaining while using callbacks to manipulate targeted elements. This design provides more control and clarity in complex DOM operations.
23
+
24
+ ## Basic Usage
25
+
26
+ ```javascript
27
+ import { be, toBe } from '@medyll/idae-be';
28
+
29
+ be('#container')
30
+ .append(toBe('<div>New content</div>'), ({ be }) => {
31
+ be
32
+ .addClass('highlight')
33
+ .on('click', () => console.log('Clicked!'));
34
+ })
35
+ .prepend(toBe('<h1>Title</h1>'))
36
+ .children(undefined, ({ be }) => {
37
+ be.setStyle({ color: 'blue' });
38
+ });
39
+ ```
40
+
41
+ ## API Reference
42
+
43
+ ### Core Methods
44
+
45
+ - `be(selector: string | HTMLElement | HTMLElement[]): Be` - Create a new Be instance
46
+ - `toBe(str: string | HTMLElement, options?: { tag?: string }): Be` - Convert string or HTMLElement to Be instance
47
+ - `createBe(tagOrHtml: string, options?: Object): Be` - Create a new Be element
48
+
49
+ ### DOM Manipulation
50
+
51
+ - `update(content: string): Be`
52
+ - `append(content: string | HTMLElement): Be`
53
+ - `prepend(content: string | HTMLElement): Be`
54
+ - `insert(mode: 'afterbegin' | 'afterend' | 'beforebegin' | 'beforeend', element: HTMLElement | Be): Be`
55
+ - `remove(): Be`
56
+ - `replace(content: string | HTMLElement): Be`
57
+ - `clear(): Be`
58
+ - `normalize(): Be`
59
+ - `wrap(tag?: string): Be`
60
+
61
+ ### Traversal
62
+
63
+ - `up(selector?: string, callback?: HandlerCallBackFn): Be`
64
+ - `next(selector?: string, callback?: HandlerCallBackFn): Be`
65
+ - `previous(selector?: string, callback?: HandlerCallBackFn): Be`
66
+ - `siblings(selector?: string, callback?: HandlerCallBackFn): Be`
67
+ - `children(selector?: string, callback?: HandlerCallBackFn): Be`
68
+ - `closest(selector: string, callback?: HandlerCallBackFn): Be`
69
+ - `firstChild(selector?: string, callback?: HandlerCallBackFn): Be`
70
+ - `lastChild(selector?: string, callback?: HandlerCallBackFn): Be`
71
+ - `find(selector: string, callback?: HandlerCallBackFn): Be`
72
+ - `findAll(selector: string, callback?: HandlerCallBackFn): Be`
73
+ - `without(selector: string, callback?: HandlerCallBackFn): Be`
74
+
75
+ ### Styling
76
+
77
+ - `setStyle(styles: Record<string, string>): Be`
78
+ - `getStyle(property: string): string | null`
79
+ - `unsetStyle(properties: string[]): Be`
80
+ - `addClass(className: string): Be`
81
+ - `removeClass(className: string): Be`
82
+ - `toggleClass(className: string): Be`
83
+ - `replaceClass(oldClass: string, newClass: string): Be`
84
+
85
+ ### Events
86
+
87
+ - `on(eventName: string, handler: EventListener): Be`
88
+ - `off(eventName: string, handler: EventListener): Be`
89
+ - `fire(eventName: string, detail?: any): Be`
90
+
91
+ ### Attributes and Properties
92
+
93
+ - `setAttr(name: string, value: string): Be`
94
+ - `getAttr(name: string): string | null`
95
+ - `deleteAttr(name: string): Be`
96
+ - `setData(key: string, value: string): Be`
97
+ - `getData(key: string): string | null`
98
+ - `deleteData(key: string): Be`
99
+
100
+ ### Timers
101
+
102
+ - `timeout(delay: number, callback: HandlerCallBackFn): Be`
103
+ - `interval(delay: number, callback: HandlerCallBackFn): Be`
104
+ - `clearTimeout(): Be`
105
+ - `clearInterval(): Be`
106
+
107
+ ## Advanced Example
108
+
109
+ ```javascript
110
+ be('#app')
111
+ .append(toBe('<div id="content"></div>'), ({ be }) => {
112
+ be
113
+ .append(toBe('<button>Add Item</button>'), ({ be }) => {
114
+ be.on('click', () => {
115
+ content.append(toBe('<p>New item</p>'), ({ be }) => {
116
+ be
117
+ .addClass('item')
118
+ .setStyle({ color: 'blue' })
119
+ .on('click', ({ target }) => {
120
+ be(target).toggleClass('selected');
121
+ });
122
+ });
123
+ });
124
+ })
125
+ .children('.item', ({ be }) => {
126
+ be.setStyle({ padding: '5px', margin: '2px' });
127
+ });
128
+ })
129
+ .up(({ be }) => {
130
+ be.setStyle({ backgroundColor: '#f0f0f0' });
131
+ });
132
+ ```
133
+
134
+ This example demonstrates:
135
+ 1. Nested element creation and manipulation
136
+ 2. Event handling with dynamic content addition
137
+ 3. Traversal and bulk operations on children
138
+ 4. Accessing and styling parent elements
139
+
140
+ ## TypeScript Support
141
+
142
+ This library is written in TypeScript and includes type definitions for a great developer experience.
143
+
144
+ ## Browser Support
145
+
146
+ Designed for modern browsers. May require polyfills for older browser support.
147
+
148
+ ## Contributing
149
+
150
+ Contributions are welcome! Please submit pull requests or open issues on our GitHub repository.
151
+
152
+ ## License
153
+
154
+ This project is licensed under the MIT License.
package/dist/be.d.ts CHANGED
@@ -1,68 +1,138 @@
1
- type IsWhat = 'element' | 'array' | 'qy';
2
- declare class DataHandler {
3
- private element;
4
- constructor(element: Be);
5
- get(key: string): string | null;
6
- set(keyOrObject: string | Record<string, string>, value?: string): Be;
7
- get beElem(): Be;
8
- valueOf(): DOMStringMap | null;
9
- }
10
- declare class PropHandler {
11
- private element;
12
- constructor(element: Be);
13
- get(name: string): any;
14
- set(nameOrObject: string | Record<string, any>, value?: any): Be;
15
- valueOf(): Record<string, any> | null;
16
- }
17
- declare class DomHandler {
18
- private element;
19
- constructor(element: Be);
20
- update(content: string): Be;
21
- get text(): string | null;
22
- textUpdate(content: string): Be;
23
- valueOf(): string | null;
24
- }
25
- declare class AttrHandler {
26
- private element;
27
- constructor(element: Be);
28
- get(name?: string): string | null;
29
- set(nameOrObject: string | Record<string, string>, value?: string): Be;
30
- valueOf(): Record<string, string> | null;
31
- }
1
+ import { type AttrHandlerHandle, AttrHandler } from './modules/attrs.js';
2
+ import { StylesHandler, type BeStylesHandler } from './modules/styles.js';
3
+ import type { IsWhat } from './types.js';
4
+ import { type DataHandlerHandle, DataHandler } from './modules/data.js';
5
+ import { EventsHandler, type EventHandlerHandle } from './modules/events.js';
6
+ import { type ClassHandlerHandler, ClassesHandler } from './modules/classes.js';
7
+ import { type PropsHandlerHandle } from './modules/props.js';
8
+ import { DomHandler, type DomHandlerHandle } from './modules/dom.js';
9
+ import { PositionHandler, type PositionHandlerHandle } from './modules/position.js';
10
+ import { WalkHandler } from './modules/walk.js';
11
+ import { TextHandler, type TextHandlerHandle } from './modules/text.js';
12
+ import { TimersHandler } from './modules/timers.js';
32
13
  export declare class Be {
33
14
  node: HTMLElement | HTMLElement[] | string;
34
15
  isWhat: IsWhat;
35
- attr: AttrHandler;
36
- dom: DomHandler;
37
- prop: PropHandler;
38
- data: DataHandler;
16
+ BeTimer: NodeJS.Timeout | null;
17
+ BeInterval: NodeJS.Timeout | null;
18
+ styles: (actions: BeStylesHandler) => Be;
19
+ private styleHandler;
20
+ setStyle: StylesHandler['set'];
21
+ getStyle: StylesHandler['get'];
22
+ unsetStyle: StylesHandler['unset'];
23
+ props: (actions: PropsHandlerHandle) => Be;
24
+ private propHandler;
25
+ data: (actions: DataHandlerHandle) => Be;
26
+ private dataHandler;
27
+ setData: DataHandler['set'];
28
+ getData: DataHandler['get'];
29
+ deleteData: DataHandler['delete'];
30
+ getKey: DataHandler['getKey'];
31
+ attrs: (actions: Partial<AttrHandlerHandle>) => Be;
32
+ private attrHandler;
33
+ setAttr: AttrHandler['set'];
34
+ getAttr: AttrHandler['get'];
35
+ deleteAttr: AttrHandler['delete'];
36
+ position: (actions: PositionHandlerHandle) => Be;
37
+ private positionHandler;
38
+ clonePosition: PositionHandler['clonePosition'];
39
+ overlapPosition: PositionHandler['overlapPosition'];
40
+ snapTo: PositionHandler['snapTo'];
41
+ dom: (actions: DomHandlerHandle) => Be;
42
+ private domHandler;
43
+ update: DomHandler['update'];
44
+ append: DomHandler['append'];
45
+ prepend: DomHandler['prepend'];
46
+ insert: DomHandler['insert'];
47
+ afterBegin: DomHandler['afterBegin'];
48
+ afterEnd: DomHandler['afterEnd'];
49
+ beforeBegin: DomHandler['beforeBegin'];
50
+ beforeEnd: DomHandler['beforeEnd'];
51
+ remove: DomHandler['remove'];
52
+ replace: DomHandler['replace'];
53
+ clear: DomHandler['clear'];
54
+ normalize: DomHandler['normalize'];
55
+ wrap: DomHandler['wrap'];
56
+ text: (actions: TextHandlerHandle) => Be;
57
+ private textHandler;
58
+ appendText: TextHandler['append'];
59
+ prependText: TextHandler['prepend'];
60
+ events: (actions: EventHandlerHandle) => Be;
61
+ private eventHandler;
62
+ on: EventsHandler['on'];
63
+ off: EventsHandler['off'];
64
+ fire: EventsHandler['fire'];
65
+ classes: (actions: ClassHandlerHandler) => Be;
66
+ private classesHandler;
67
+ addClass: ClassesHandler['add'];
68
+ removeClass: ClassesHandler['remove'];
69
+ toggleClass: ClassesHandler['toggle'];
70
+ replaceClass: ClassesHandler['replace'];
71
+ walk: (actions: DataHandlerHandle) => Be;
72
+ private walkHandler;
73
+ up: WalkHandler['up'];
74
+ next: WalkHandler['next'];
75
+ without: WalkHandler['without'];
76
+ previous: WalkHandler['previous'];
77
+ siblings: WalkHandler['siblings'];
78
+ children: WalkHandler['children'];
79
+ closest: WalkHandler['closest'];
80
+ lastChild: WalkHandler['lastChild'];
81
+ firstChild: WalkHandler['firstChild'];
82
+ find: WalkHandler['find'];
83
+ findAll: WalkHandler['findAll'];
84
+ timers: (actions: TextHandlerHandle) => Be;
85
+ private timerHandler;
86
+ timeout: TimersHandler['timeout'];
87
+ interval: TimersHandler['interval'];
88
+ clearTimeout: TimersHandler['clearTimeout'];
89
+ clearInterval: TimersHandler['clearInterval'];
39
90
  private constructor();
40
91
  static elem(node: HTMLElement | HTMLElement[] | string): Be;
41
- classAdd(className: string): this;
42
- classRemove(className: string): this;
43
- classToggle(className: string): this;
44
- find(qy: string): Element | (Element | null)[] | null;
45
- findAll(qy: string): Element[];
46
- get html(): string | null;
47
- htmlSet(content: string): this;
48
- get text(): string | null;
49
- textSet(content: string): this;
50
- up(qy?: string): Element | (Element | null)[] | null;
51
- next(qy?: string): Element | (Element | null)[] | null;
52
- previous(qy?: string): Element | (Element | null)[] | null;
53
- styleSet(styles: Record<string, any>): this;
54
- on(eventName: string, handler: EventListener): this;
55
- off(eventName: string, handler: EventListener): this;
56
- append(content: string | HTMLElement): this;
57
- remove(): this;
92
+ static createBe(tagOrHtml: CreateFragment, options?: {
93
+ is?: string;
94
+ style?: Record<string, string> | string;
95
+ attributes?: Record<string, string>;
96
+ className?: string;
97
+ }): Be;
98
+ /**
99
+ * Creates a new `Be` element based on the provided string or HTMLElement.
100
+ * If the input is an HTMLElement, it creates a new `Be` element and sets it as the child of the provided element.
101
+ * If the input is a string, it checks if it is a valid HTML string and creates a new `Be` element based on it.
102
+ * If the input is neither a string nor an HTMLElement, it creates a new `Be` element with the default tag.
103
+ *
104
+ * @param str - The string or HTMLElement to create the `Be` element from.
105
+ * @param options - Additional options for creating the `Be` element.
106
+ * @returns The created `Be` element.
107
+ */
108
+ static toBe(str: string | HTMLElement, options?: {
109
+ tag?: string;
110
+ }): Be;
111
+ /**
112
+ * setStyle Sets one or more CSS styles for the selected element(s), including CSS custom properties.
113
+ * @param styles An object of CSS properties and values, or a string of CSS properties and values.
114
+ * @param value The value for a single CSS property when styles is a property name string.
115
+ * @returns The Be instance for method chaining.
116
+ */
58
117
  fetch<T extends object>(options: {
59
118
  url: string;
60
119
  method?: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'OPTIONS' | 'HEAD' | 'CONNECT' | 'TRACE';
61
120
  data?: T;
62
121
  headers?: Record<string, string>;
63
122
  }): Promise<any>;
64
- each(callback: (el: HTMLElement) => void): void;
65
- private findWhile;
123
+ eachNode(callback: (el: HTMLElement) => void): void;
124
+ /** DOM
125
+ * Handles various DOM operations on the element(s).
126
+ * @param actions An object specifying the DOM actions to perform.
127
+ * @returns The Be instance for method chaining.
128
+ */
129
+ get html(): string | null;
130
+ private attach;
131
+ private handle;
66
132
  }
67
- export declare function be(selector: string | HTMLElement | HTMLElement[]): Be;
133
+ type CreateFragment = `<${string}>${string}</${string}>` | string;
134
+ export declare const be: typeof Be.elem;
135
+ export declare const toBe: typeof Be.toBe;
136
+ export declare const beId: (id: string) => Be;
137
+ export declare const createBe: typeof Be.createBe;
68
138
  export {};