jj 2.3.0 → 2.5.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 +18 -57
- package/lib/JJD.d.ts +36 -25
- package/lib/JJD.js +56 -28
- package/lib/JJD.js.map +1 -1
- package/lib/JJDF.d.ts +19 -5
- package/lib/JJDF.js +32 -2
- package/lib/JJDF.js.map +1 -1
- package/lib/JJE.d.ts +96 -110
- package/lib/JJE.js +143 -154
- package/lib/JJE.js.map +1 -1
- package/lib/JJET.d.ts +79 -0
- package/lib/JJET.js +114 -0
- package/lib/JJET.js.map +1 -0
- package/lib/JJEx.d.ts +63 -0
- package/lib/JJEx.js +83 -0
- package/lib/JJEx.js.map +1 -0
- package/lib/JJHE.d.ts +26 -37
- package/lib/JJHE.js +34 -62
- package/lib/JJHE.js.map +1 -1
- package/lib/JJN-wrap.js +46 -0
- package/lib/JJN-wrap.js.map +1 -0
- package/lib/JJN.d.ts +21 -106
- package/lib/JJN.js +44 -164
- package/lib/JJN.js.map +1 -1
- package/lib/JJNx.d.ts +126 -0
- package/lib/JJNx.js +157 -0
- package/lib/JJNx.js.map +1 -0
- package/lib/JJSE.d.ts +32 -10
- package/lib/JJSE.js +36 -9
- package/lib/JJSE.js.map +1 -1
- package/lib/JJSR.d.ts +8 -4
- package/lib/JJSR.js +10 -5
- package/lib/JJSR.js.map +1 -1
- package/lib/JJT.d.ts +26 -13
- package/lib/JJT.js +38 -30
- package/lib/JJT.js.map +1 -1
- package/lib/bundle.js +779 -734
- package/lib/bundle.js.map +3 -3
- package/lib/bundle.min.js +1 -2
- package/lib/components.js +5 -4
- package/lib/components.js.map +1 -1
- package/lib/helpers.d.ts +3 -2
- package/lib/helpers.js +11 -9
- package/lib/helpers.js.map +1 -1
- package/lib/index.d.ts +20 -2
- package/lib/index.js +21 -2
- package/lib/index.js.map +1 -1
- package/lib/internal.d.ts +30 -0
- package/lib/internal.js +35 -0
- package/lib/internal.js.map +1 -0
- package/lib/types.d.ts +18 -30
- package/lib/util.d.ts +0 -28
- package/lib/util.js +0 -32
- package/lib/util.js.map +1 -1
- package/llms.txt +214 -0
- package/package.json +11 -3
- package/lib/case.test.js +0 -79
- package/lib/case.test.js.map +0 -1
- package/lib/mixin-types.d.ts +0 -143
- package/lib/mixin-types.js +0 -2
- package/lib/mixin-types.js.map +0 -1
- package/lib/mixins.d.ts +0 -94
- package/lib/mixins.js +0 -359
- package/lib/mixins.js.map +0 -1
- package/lib/util.test.d.ts +0 -1
- package/lib/util.test.js +0 -46
- package/lib/util.test.js.map +0 -1
- /package/lib/{case.test.d.ts → JJN-wrap.d.ts} +0 -0
package/README.md
CHANGED
|
@@ -1,77 +1,38 @@
|
|
|
1
1
|
# Just JavaScript!
|
|
2
2
|
|
|
3
|
-
**
|
|
4
|
-
**Do you know what's faster than transpilation? No transpilation!**
|
|
3
|
+
**Faster than VDOM. No Build Step. Use the Platform!**
|
|
5
4
|
|
|
6
|
-
**JJ**
|
|
5
|
+
**JJ** is a lightweight, no-transpilation library for modern web development. What You Write Is What Is Run (WYWIWIR).
|
|
7
6
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
## Install
|
|
7
|
+
## ⚡ Quick Start
|
|
11
8
|
|
|
12
9
|
```bash
|
|
13
10
|
npm i jj
|
|
14
11
|
```
|
|
15
12
|
|
|
16
|
-
# Usage
|
|
17
|
-
|
|
18
|
-
CDN:
|
|
19
|
-
|
|
20
13
|
```js
|
|
21
|
-
import {
|
|
22
|
-
```
|
|
23
|
-
|
|
24
|
-
From NPM:
|
|
14
|
+
import { JJHE } from 'jj'
|
|
25
15
|
|
|
26
|
-
|
|
27
|
-
|
|
16
|
+
JJHE.fromTag('div')
|
|
17
|
+
.addClass('card')
|
|
18
|
+
.setText('Hello World!')
|
|
19
|
+
.on('click', () => console.log('Hi'))
|
|
20
|
+
.appendToBody()
|
|
28
21
|
```
|
|
29
22
|
|
|
30
|
-
##
|
|
31
|
-
|
|
32
|
-
- Modern: take full advantage of ever-green browser features. No support for legacy browsers
|
|
33
|
-
- Sugar but not magic: it'll let you write shorter code but it won't do much logic behind the scene
|
|
34
|
-
- Excplicit: make the code more readable and easier to follow
|
|
35
|
-
- Basic: use plain old javascript objects (POJOs) for describing HTML and CSS
|
|
36
|
-
|
|
37
|
-
# Install
|
|
38
|
-
|
|
39
|
-
One of the main points of using this library is to avoid compiling your code.
|
|
40
|
-
You can directly import it from UNPKG at https://unpkg.com/browse/jj/dist/jj.js
|
|
41
|
-
|
|
42
|
-
But if you prefer to install it via NPM:
|
|
23
|
+
## 🚀 Why JJ?
|
|
43
24
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
# Use
|
|
49
|
-
|
|
50
|
-
```html
|
|
51
|
-
<html>
|
|
52
|
-
<body>
|
|
53
|
-
<script type="module" src="index.js" defer async></script>
|
|
54
|
-
</body>
|
|
55
|
-
</html>
|
|
56
|
-
```
|
|
57
|
-
|
|
58
|
-
```javascript
|
|
59
|
-
// If you installed via NPM
|
|
60
|
-
import { ready, html } from '/node_modules/jj/dist/jj.js'
|
|
61
|
-
// Is you want to directly use it via UNPKG
|
|
62
|
-
import { ready, html } from 'https://unpkg.com/browse/jj/dist/jj.js'
|
|
63
|
-
|
|
64
|
-
ready(() => {
|
|
65
|
-
html.div('Hello world!').appendToBody()
|
|
66
|
-
})
|
|
67
|
-
```
|
|
25
|
+
- **Zero Build** – Runs directly in modern browsers
|
|
26
|
+
- **Native Speed** – Direct DOM manipulation, no VDOM overhead
|
|
27
|
+
- **Web Standards** – First-class Web Components support
|
|
28
|
+
- **Fluent API** – Chainable methods for cleaner code
|
|
68
29
|
|
|
69
|
-
|
|
30
|
+
## 📚 Learn More
|
|
70
31
|
|
|
71
|
-
|
|
32
|
+
**👉 [Visit the full site with tutorials, examples, and API docs](https://alexewerlof.github.io/jj)**
|
|
72
33
|
|
|
73
|
-
|
|
34
|
+
## License
|
|
74
35
|
|
|
75
36
|
MIT
|
|
76
37
|
|
|
77
|
-
_Made in Sweden 🇸🇪 by [
|
|
38
|
+
_Made in Sweden 🇸🇪 by [Alex Ewerlöf](https://alexewerlof.com/)_
|
package/lib/JJD.d.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
export interface JJD<T extends Document> extends IById, IQuery, IAppendPrepend {
|
|
4
|
-
}
|
|
1
|
+
import { Wrapped } from './types.js';
|
|
2
|
+
import { JJNx } from './JJNx.js';
|
|
5
3
|
/**
|
|
6
4
|
* Wraps a Document (which is a descendant of Node).
|
|
7
5
|
*
|
|
@@ -10,15 +8,18 @@ export interface JJD<T extends Document> extends IById, IQuery, IAppendPrepend {
|
|
|
10
8
|
* the fluent API capabilities of `JJN`.
|
|
11
9
|
* It also supports querying (`byId`, `query`) and manipulation (`append`, `prepend`) methods.
|
|
12
10
|
*
|
|
11
|
+
* To set the document title, use: `doc.ref.title = 'New Title'`
|
|
12
|
+
*
|
|
13
13
|
* @example
|
|
14
14
|
* ```ts
|
|
15
15
|
* const doc = JJD.from(document)
|
|
16
16
|
* doc.on('DOMContentLoaded', () => console.log('Ready'))
|
|
17
|
+
* doc.ref.title = 'My Page Title' // Set document title
|
|
17
18
|
* ```
|
|
18
19
|
*
|
|
19
20
|
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Document | Document}
|
|
20
21
|
*/
|
|
21
|
-
export declare class JJD<T extends Document = Document> extends
|
|
22
|
+
export declare class JJD<T extends Document = Document> extends JJNx<T> {
|
|
22
23
|
/**
|
|
23
24
|
* Creates a JJD instance from a Document reference.
|
|
24
25
|
*
|
|
@@ -40,37 +41,47 @@ export declare class JJD<T extends Document = Document> extends JJN<T> {
|
|
|
40
41
|
*/
|
|
41
42
|
constructor(ref: T);
|
|
42
43
|
/**
|
|
43
|
-
*
|
|
44
|
+
* Finds an element by ID within this Document.
|
|
44
45
|
*
|
|
45
|
-
* @
|
|
46
|
-
*
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
* Gets the `<body>` element of the document wrapped in a `JJHE` instance.
|
|
46
|
+
* @example
|
|
47
|
+
* ```ts
|
|
48
|
+
* const el = doc.byId('my-id') // Returns null if not found
|
|
49
|
+
* const el = doc.byId('my-id', true) // Throws if not found
|
|
50
|
+
* ```
|
|
51
51
|
*
|
|
52
|
-
* @
|
|
53
|
-
* @
|
|
52
|
+
* @param id - The ID to search for.
|
|
53
|
+
* @param required - Whether to throw an error if not found. Defaults to false.
|
|
54
|
+
* @returns The wrapped element, or null if not found and required is false.
|
|
55
|
+
* @throws {TypeError} If id is not a string or element not found and required is true.
|
|
56
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Document/getElementById | Document.getElementById}
|
|
54
57
|
*/
|
|
55
|
-
|
|
58
|
+
byId(id: string, required?: boolean): Wrapped | null;
|
|
56
59
|
/**
|
|
57
|
-
*
|
|
60
|
+
* Finds elements by class name in the Document.
|
|
58
61
|
*
|
|
59
62
|
* @example
|
|
60
63
|
* ```ts
|
|
61
|
-
*
|
|
64
|
+
* const items = byClass('list-item')
|
|
62
65
|
* ```
|
|
63
66
|
*
|
|
64
|
-
* @param
|
|
65
|
-
* @returns
|
|
66
|
-
* @
|
|
67
|
+
* @param className - The class name to search for.
|
|
68
|
+
* @returns An array of wrapped elements.
|
|
69
|
+
* @throws {TypeError} If className is not a string.
|
|
70
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Document/getElementsByClassName | Document.getElementsByClassName}
|
|
67
71
|
*/
|
|
68
|
-
|
|
72
|
+
byClass(className: string): Wrapped[];
|
|
69
73
|
/**
|
|
70
|
-
* Gets the document
|
|
74
|
+
* Gets the `<head>` element of the document wrapped in a `JJHE` instance.
|
|
71
75
|
*
|
|
72
|
-
* @returns The
|
|
73
|
-
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Document/
|
|
76
|
+
* @returns The wrapped head element.
|
|
77
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Document/head | Document.head}
|
|
78
|
+
*/
|
|
79
|
+
get head(): Wrapped;
|
|
80
|
+
/**
|
|
81
|
+
* Gets the `<body>` element of the document wrapped in a `JJHE` instance.
|
|
82
|
+
*
|
|
83
|
+
* @returns The wrapped body element.
|
|
84
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Document/body | Document.body}
|
|
74
85
|
*/
|
|
75
|
-
|
|
86
|
+
get body(): Wrapped;
|
|
76
87
|
}
|
package/lib/JJD.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import { isA } from 'jty';
|
|
1
|
+
import { isA, isStr } from 'jty';
|
|
2
2
|
import { JJN } from './JJN.js';
|
|
3
|
+
import { JJNx } from './JJNx.js';
|
|
4
|
+
import { typeErr } from './internal.js';
|
|
3
5
|
/**
|
|
4
6
|
* Wraps a Document (which is a descendant of Node).
|
|
5
7
|
*
|
|
@@ -8,15 +10,18 @@ import { JJN } from './JJN.js';
|
|
|
8
10
|
* the fluent API capabilities of `JJN`.
|
|
9
11
|
* It also supports querying (`byId`, `query`) and manipulation (`append`, `prepend`) methods.
|
|
10
12
|
*
|
|
13
|
+
* To set the document title, use: `doc.ref.title = 'New Title'`
|
|
14
|
+
*
|
|
11
15
|
* @example
|
|
12
16
|
* ```ts
|
|
13
17
|
* const doc = JJD.from(document)
|
|
14
18
|
* doc.on('DOMContentLoaded', () => console.log('Ready'))
|
|
19
|
+
* doc.ref.title = 'My Page Title' // Set document title
|
|
15
20
|
* ```
|
|
16
21
|
*
|
|
17
22
|
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Document | Document}
|
|
18
23
|
*/
|
|
19
|
-
export class JJD extends
|
|
24
|
+
export class JJD extends JJNx {
|
|
20
25
|
/**
|
|
21
26
|
* Creates a JJD instance from a Document reference.
|
|
22
27
|
*
|
|
@@ -40,10 +45,58 @@ export class JJD extends JJN {
|
|
|
40
45
|
*/
|
|
41
46
|
constructor(ref) {
|
|
42
47
|
if (!isA(ref, Document)) {
|
|
43
|
-
throw new TypeError(`
|
|
48
|
+
throw new TypeError(`JJD expects a Document instance. Got ${ref} (${typeof ref}). `);
|
|
44
49
|
}
|
|
45
50
|
super(ref);
|
|
46
51
|
}
|
|
52
|
+
/**
|
|
53
|
+
* Finds an element by ID within this Document.
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```ts
|
|
57
|
+
* const el = doc.byId('my-id') // Returns null if not found
|
|
58
|
+
* const el = doc.byId('my-id', true) // Throws if not found
|
|
59
|
+
* ```
|
|
60
|
+
*
|
|
61
|
+
* @param id - The ID to search for.
|
|
62
|
+
* @param required - Whether to throw an error if not found. Defaults to false.
|
|
63
|
+
* @returns The wrapped element, or null if not found and required is false.
|
|
64
|
+
* @throws {TypeError} If id is not a string or element not found and required is true.
|
|
65
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Document/getElementById | Document.getElementById}
|
|
66
|
+
*/
|
|
67
|
+
byId(id, required = false) {
|
|
68
|
+
if (!isStr(id)) {
|
|
69
|
+
throw typeErr('id', 'a string', id);
|
|
70
|
+
}
|
|
71
|
+
const el = this.ref.getElementById(id);
|
|
72
|
+
if (el) {
|
|
73
|
+
return JJN.wrap(el);
|
|
74
|
+
}
|
|
75
|
+
if (required) {
|
|
76
|
+
throw new TypeError(`Element with id "${id}" not found in the document. ` +
|
|
77
|
+
`Did you mean to call .byId("${id}", false) to return null instead? `);
|
|
78
|
+
}
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Finds elements by class name in the Document.
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* ```ts
|
|
86
|
+
* const items = byClass('list-item')
|
|
87
|
+
* ```
|
|
88
|
+
*
|
|
89
|
+
* @param className - The class name to search for.
|
|
90
|
+
* @returns An array of wrapped elements.
|
|
91
|
+
* @throws {TypeError} If className is not a string.
|
|
92
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Document/getElementsByClassName | Document.getElementsByClassName}
|
|
93
|
+
*/
|
|
94
|
+
byClass(className) {
|
|
95
|
+
if (!isStr(className)) {
|
|
96
|
+
throw typeErr('className', 'a string', className);
|
|
97
|
+
}
|
|
98
|
+
return JJN.wrapAll(this.ref.getElementsByClassName(className));
|
|
99
|
+
}
|
|
47
100
|
/**
|
|
48
101
|
* Gets the `<head>` element of the document wrapped in a `JJHE` instance.
|
|
49
102
|
*
|
|
@@ -62,30 +115,5 @@ export class JJD extends JJN {
|
|
|
62
115
|
get body() {
|
|
63
116
|
return JJN.wrap(this.ref.body);
|
|
64
117
|
}
|
|
65
|
-
/**
|
|
66
|
-
* Sets the document title.
|
|
67
|
-
*
|
|
68
|
-
* @example
|
|
69
|
-
* ```ts
|
|
70
|
-
* JJD.from(document).setTitle('New Page Title')
|
|
71
|
-
* ```
|
|
72
|
-
*
|
|
73
|
-
* @param title - The new title string.
|
|
74
|
-
* @returns This instance for chaining.
|
|
75
|
-
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Document/title | Document.title}
|
|
76
|
-
*/
|
|
77
|
-
setTitle(title) {
|
|
78
|
-
this.ref.title = title;
|
|
79
|
-
return this;
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* Gets the document title.
|
|
83
|
-
*
|
|
84
|
-
* @returns The current title of the document.
|
|
85
|
-
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Document/title | Document.title}
|
|
86
|
-
*/
|
|
87
|
-
getTitle() {
|
|
88
|
-
return this.ref.title;
|
|
89
|
-
}
|
|
90
118
|
}
|
|
91
119
|
//# sourceMappingURL=JJD.js.map
|
package/lib/JJD.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"JJD.js","sourceRoot":"","sources":["../src/JJD.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAA;
|
|
1
|
+
{"version":3,"file":"JJD.js","sourceRoot":"","sources":["../src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ACH,OAAO,CAAC,SAAiB;QACrB,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,EAAE,CAAC;YACpB,MAAM,OAAO,CAAC,WAAW,EAAE,UAAU,EAAE,SAAS,CAAC,CAAA;QACrD,CAAC;QACD,OAAO,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,sBAAsB,CAAC,SAAS,CAAC,CAAC,CAAA;IAClE,CAAC;IAED;;;;;OAKG;IACH,IAAI,IAAI;QACJ,OAAO,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;IAClC,CAAC;IAED;;;;;OAKG;IACH,IAAI,IAAI;QACJ,OAAO,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;IAClC,CAAC;CACJ"}
|
package/lib/JJDF.d.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
export interface JJDF<T extends DocumentFragment> extends IById, IQuery, IAppendPrepend {
|
|
4
|
-
}
|
|
1
|
+
import { Wrapped } from './types.js';
|
|
2
|
+
import { JJNx } from './JJNx.js';
|
|
5
3
|
/**
|
|
6
4
|
* Wraps a DocumentFragment (which is a descendant of Node).
|
|
7
5
|
*
|
|
@@ -23,7 +21,7 @@ export interface JJDF<T extends DocumentFragment> extends IById, IQuery, IAppend
|
|
|
23
21
|
*
|
|
24
22
|
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/DocumentFragment | DocumentFragment}
|
|
25
23
|
*/
|
|
26
|
-
export declare class JJDF<T extends DocumentFragment = DocumentFragment> extends
|
|
24
|
+
export declare class JJDF<T extends DocumentFragment = DocumentFragment> extends JJNx<T> {
|
|
27
25
|
/**
|
|
28
26
|
* Creates a JJDF instance from a DocumentFragment reference.
|
|
29
27
|
*
|
|
@@ -57,4 +55,20 @@ export declare class JJDF<T extends DocumentFragment = DocumentFragment> extends
|
|
|
57
55
|
* @throws {TypeError} If `ref` is not a DocumentFragment.
|
|
58
56
|
*/
|
|
59
57
|
constructor(ref: T);
|
|
58
|
+
/**
|
|
59
|
+
* Finds an element by ID within this DocumentFragment.
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```ts
|
|
63
|
+
* const el = frag.byId('header') // Returns null if not found
|
|
64
|
+
* const el = frag.byId('header', true) // Throws if not found
|
|
65
|
+
* ```
|
|
66
|
+
*
|
|
67
|
+
* @param id - The ID to search for.
|
|
68
|
+
* @param required - Whether to throw an error if not found. Defaults to false.
|
|
69
|
+
* @returns The wrapped element, or null if not found and required is false.
|
|
70
|
+
* @throws {TypeError} If id is not a string or element not found and required is true.
|
|
71
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/DocumentFragment/getElementById | DocumentFragment.getElementById}
|
|
72
|
+
*/
|
|
73
|
+
byId(id: string, required?: boolean): Wrapped | null;
|
|
60
74
|
}
|
package/lib/JJDF.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import { isA } from 'jty';
|
|
1
|
+
import { isA, isStr } from 'jty';
|
|
2
2
|
import { JJN } from './JJN.js';
|
|
3
|
+
import { JJNx } from './JJNx.js';
|
|
4
|
+
import { typeErr } from './internal.js';
|
|
3
5
|
/**
|
|
4
6
|
* Wraps a DocumentFragment (which is a descendant of Node).
|
|
5
7
|
*
|
|
@@ -21,7 +23,7 @@ import { JJN } from './JJN.js';
|
|
|
21
23
|
*
|
|
22
24
|
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/DocumentFragment | DocumentFragment}
|
|
23
25
|
*/
|
|
24
|
-
export class JJDF extends
|
|
26
|
+
export class JJDF extends JJNx {
|
|
25
27
|
/**
|
|
26
28
|
* Creates a JJDF instance from a DocumentFragment reference.
|
|
27
29
|
*
|
|
@@ -64,5 +66,33 @@ export class JJDF extends JJN {
|
|
|
64
66
|
}
|
|
65
67
|
super(ref);
|
|
66
68
|
}
|
|
69
|
+
/**
|
|
70
|
+
* Finds an element by ID within this DocumentFragment.
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```ts
|
|
74
|
+
* const el = frag.byId('header') // Returns null if not found
|
|
75
|
+
* const el = frag.byId('header', true) // Throws if not found
|
|
76
|
+
* ```
|
|
77
|
+
*
|
|
78
|
+
* @param id - The ID to search for.
|
|
79
|
+
* @param required - Whether to throw an error if not found. Defaults to false.
|
|
80
|
+
* @returns The wrapped element, or null if not found and required is false.
|
|
81
|
+
* @throws {TypeError} If id is not a string or element not found and required is true.
|
|
82
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/DocumentFragment/getElementById | DocumentFragment.getElementById}
|
|
83
|
+
*/
|
|
84
|
+
byId(id, required = false) {
|
|
85
|
+
if (!isStr(id)) {
|
|
86
|
+
throw typeErr('id', 'a string', id);
|
|
87
|
+
}
|
|
88
|
+
const el = this.ref.getElementById(id);
|
|
89
|
+
if (el) {
|
|
90
|
+
return JJN.wrap(el);
|
|
91
|
+
}
|
|
92
|
+
if (required) {
|
|
93
|
+
throw new TypeError(`Element with id ${id} not found`);
|
|
94
|
+
}
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
67
97
|
}
|
|
68
98
|
//# sourceMappingURL=JJDF.js.map
|
package/lib/JJDF.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"JJDF.js","sourceRoot":"","sources":["../src/JJDF.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAA;
|
|
1
|
+
{"version":3,"file":"JJDF.js","sourceRoot":"","sources":["../src/JJDF.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,KAAK,CAAA;AAChC,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;AAE9B,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;A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