jizy-dom 2.1.7 → 2.1.8

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.
Files changed (2) hide show
  1. package/README.md +141 -18
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,18 +1,141 @@
1
- # jizy-dom
2
- DOM js implementation
3
-
4
- ## `lib/js` Directory
5
-
6
- This folder contains the core JavaScript modules for DOM manipulation:
7
-
8
- - **dom.js**: Utility functions, CSS property handling, and other DOM-related helpers.
9
- - **selector.js**: Lightweight selector engine and helper functions for working with DOM elements.
10
-
11
- ## Tests
12
-
13
- Vitest + happy-dom. Tests live under `tests/`.
14
-
15
- ```bash
16
- npm run test # watch mode
17
- npm run test:run # one-shot
18
- ```
1
+ # jizy-dom
2
+
3
+ A lightweight, chainable DOM manipulation library — a small jQuery-like wrapper over native DOM APIs, with no runtime dependencies.
4
+
5
+ ## Installation
6
+
7
+ ```sh
8
+ npm install jizy-dom
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ESM (Node / bundlers):
14
+
15
+ ```js
16
+ import DOM from 'jizy-dom';
17
+
18
+ const $items = new DOM('.item');
19
+ $items.addClass('active').on('click', (e) => console.log(e.target));
20
+ ```
21
+
22
+ Browser (UMD/IIFE bundle, exposes the `DOM` global):
23
+
24
+ ```html
25
+ <script src="node_modules/jizy-dom/dist/js/jizy-dom.min.js"></script>
26
+ <script>
27
+ new DOM('.item').show();
28
+ </script>
29
+ ```
30
+
31
+ ## Constructor
32
+
33
+ ```js
34
+ new DOM(selector, parent)
35
+ ```
36
+
37
+ `selector` may be a CSS string, a single `Element`, an array/NodeList of elements, or another `DOM` instance. `parent` is optional and may be a CSS string, an `Element`, or another `DOM` instance — when given, the lookup is scoped to it. Passing a `DOM` instance as `selector` returns it as-is.
38
+
39
+ ## `lib/js` directory
40
+
41
+ - **dom.js** — the `DOM` class (chainable API), CSS/data/class helpers, and a small `slide` animation primitive.
42
+ - **selector.js** — lightweight selector engine that normalizes the input (string, node, NodeList, window/document) and returns a flat array of elements.
43
+
44
+ ## API
45
+
46
+ All chainable methods return the `DOM` instance. Read methods return the requested value (or `null`/`false`/`undefined` when nothing matches).
47
+
48
+ ### Traversal & access
49
+
50
+ - `toArray()` — underlying elements as a plain array.
51
+ - `exists()` / `size()` — has matches / count.
52
+ - `each(cb)` — iterate `(el, i)`.
53
+ - `map(cb)` — collect callback return values; entries returning `false` are skipped.
54
+ - `filter(cbOrSelector)` — keep elements matching a selector or for which the callback returns truthy.
55
+ - `not(selector)` — inverse of `filter`.
56
+ - `get(index)` — single-element `DOM` at `index` (negative indexes count from the end).
57
+ - `getElement(tag)` — the first raw `Element`, or a freshly created `<tag>` (default `div`) when empty.
58
+ - `is(selector)` — match against a selector, an `Element`, a `DOM` instance, or the pseudo-selectors `:visible` / `:hidden`.
59
+ - `find(selector)` — descendants matching the selector; supports comma lists and a leading `>` for direct children.
60
+ - `parent(selector?)`, `children(selector?)`, `closest(selector)`, `prev(selector?)`, `next(selector?)`, `first(selector?)`, `last(selector?)`.
61
+
62
+ ### Mutation
63
+
64
+ - `insert(newEl, position)` — `position` accepts `before` / `after` / `prepend` / `append` (mapped to `insertAdjacent*`). `newEl` may be a `DOM`, an `Element`, or an HTML string.
65
+ - `before(newEl)`, `after(newEl)`, `append(newEl)`, `prepend(newEl)`.
66
+ - `replaceWith(newEl)`, `remove()`, `wrap(wrapper)`.
67
+
68
+ ### Content
69
+
70
+ - `text(value?)`, `html(value?)`, `content(value?)` — getter when called with no argument, setter otherwise.
71
+
72
+ ### Classes
73
+
74
+ - `addClass(name)`, `removeClass(name)`, `toggleClass(name)`, `replaceClass(oldClass, newClass)`.
75
+ - `hasClass(name)`, `hasClasses(names)` (any), `hasAllClasses(names)` (all), `containsClass(substring)`.
76
+
77
+ ### CSS / visibility
78
+
79
+ - `css(prop)` — read computed/inline value.
80
+ - `css(prop, value, important?)` — set; numeric values get `px` appended for size/spacing properties; pass `null` to remove.
81
+ - `css(['prop1','prop2'])` — read multiple values into an object.
82
+ - `show()`, `hide()`, `toggle()` — track the original `display` via `data-css-initial-display`.
83
+ - `offset()` — `{ top, left }` relative to the document.
84
+ - `outerHeight()`, `outerWidth()` — content + padding + margin.
85
+
86
+ ### Data & attributes
87
+
88
+ - `data()` / `data(key)` / `data(key, value)` — read all dataset values, read one, or write one. Values are deserialized: `"true"`/`"false"`/`"null"`, numbers, and JSON literals are parsed; everything else stays a string. Object values are written as `data-key-subkey`.
89
+ - `attr(name)` / `attr(name, value)` — `setAttribute` / `getAttribute`; passing `null` removes the attribute.
90
+ - `prop(name)` / `prop(name, value)` — DOM property access with HTML→DOM remapping (`class` → `className`, `for` → `htmlFor`, `tabindex` → `tabIndex`, etc.).
91
+ - `tagName(uppercase?)` — tag name of the first element.
92
+ - `val(value?)` — form-control value getter/setter.
93
+
94
+ ### Events
95
+
96
+ - `on(events, listener, options?)` — space-separated event list; `options` is forwarded to `addEventListener`.
97
+ - `off(events, listener)`.
98
+ - `delegate(events, selector, listener, options?)` — runs `listener` only when `event.target` matches `selector`.
99
+ - `trigger(eventName, eventData?, bubbles?, cancellable?)` — dispatches a `CustomEvent` when `eventData` is given, otherwise a plain `Event`.
100
+ - `submit()`, `focus()`.
101
+ - `swipe(swipeCb, ignoreCb?, params?)` — touch-swipe detector. `swipeCb(event, dir)` receives `'left' | 'right' | 'up' | 'down' | 'none'`. `params` overrides `{ scrolling: false, threshold: 10, restraint: 100, allowedTime: 300 }`. Uses passive listeners when supported.
102
+
103
+ ### Animation & scroll
104
+
105
+ - `slideDown(speed?, easing?, delay?, display?)`.
106
+ - `slideUp(speed?, easing?, delay?)`.
107
+ - `slideToggle(speed?, easing?, delay?, display?)` — falls back to `show`/`hide`/`toggle` when `Promise` is unavailable. Defaults: `speed=500`, `easing='cubic-bezier(0.25, 0.1, 0.44, 1.4)'`, `delay=200`. Hidden state is tracked via the `slider-hidden` class.
108
+ - `scrollTop(position?)` — read or smooth-scroll the first element.
109
+
110
+ ### Forms
111
+
112
+ - `serialize()` — first matched form serialized as a URL-encoded query string via `FormData` + `URLSearchParams`.
113
+
114
+ ## Per-element helpers
115
+
116
+ Inside `each`/`map` callbacks, the raw `Element` is decorated with shorthand methods bound to that element: `el.data`, `el.css`, `el.addClass`, `el.removeClass`, `el.hasClass`, `el.hasClasses`, `el.hasAllClasses`. They behave like their `DOM` counterparts but operate on the single element.
117
+
118
+ ## Build
119
+
120
+ This package follows the standard `jizy-*` packer layout. Build commands:
121
+
122
+ ```bash
123
+ npm run jpack:dist # build dist/ from lib/
124
+ npm run jpack:export # consumer-specific build (--name perso)
125
+ ```
126
+
127
+ The browser bundle exposes the global `DOM` (configured in `config/jpack.js`).
128
+
129
+ ## Tests
130
+
131
+ Vitest + happy-dom. Tests live under `tests/`.
132
+
133
+ ```bash
134
+ npm run test # watch mode
135
+ npm run test:run # one-shot
136
+ npm run test:coverage # with coverage
137
+ ```
138
+
139
+ ## License
140
+
141
+ MIT — see [LICENSE](LICENSE).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jizy-dom",
3
- "version": "2.1.7",
3
+ "version": "2.1.8",
4
4
  "browser": "dist/js/jizy-dom.min.js",
5
5
  "main": "lib/index.js",
6
6
  "type": "module",