@medyll/idae-dom-events 0.90.0 → 0.91.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 +101 -101
- package/dist/components/content.html +44 -44
- package/dist/cssDom.js +14 -14
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,101 +1,101 @@
|
|
|
1
|
-
# @medyll/idae-dom-events
|
|
2
|
-
|
|
3
|
-
`@medyll/idae-dom-events` is a library for observing and reacting to changes in the DOM of web applications. It provides tools to track CSS changes, monitor DOM mutations, and manage various events efficiently, making it an ideal choice for dynamic web applications.
|
|
4
|
-
|
|
5
|
-
## Features
|
|
6
|
-
|
|
7
|
-
- **CSS Change Tracking**: Use `CssObserver` to monitor animations, style changes, and resize events.
|
|
8
|
-
- **DOM Mutation Observation**: Use `DomObserver` to track DOM mutations, such as attribute changes, child list modifications, and character data updates.
|
|
9
|
-
- **Event Management**: Efficiently manage DOM-related events.
|
|
10
|
-
|
|
11
|
-
## Installation
|
|
12
|
-
|
|
13
|
-
Install the library using npm:
|
|
14
|
-
|
|
15
|
-
```bash
|
|
16
|
-
npm install @medyll/idae-dom-events
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
## Usage
|
|
20
|
-
|
|
21
|
-
### CSS Change Tracking
|
|
22
|
-
|
|
23
|
-
```typescript
|
|
24
|
-
import { cssDom } from '@medyll/idae-dom-events';
|
|
25
|
-
|
|
26
|
-
// Track CSS changes on elements with the attribute data-cssDom
|
|
27
|
-
cssDom('[data-cssDom]', {
|
|
28
|
-
trackChildList: true,
|
|
29
|
-
trackAttributes: true,
|
|
30
|
-
trackResize: true
|
|
31
|
-
}).each((element, changes) => {
|
|
32
|
-
console.log('Modified element:', element);
|
|
33
|
-
|
|
34
|
-
if (changes.attributes) {
|
|
35
|
-
console.log('Attribute changes:', changes.attributes);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
if (changes.childList) {
|
|
39
|
-
console.log('Child list modifications:', changes.childList);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
if (changes.characterData) {
|
|
43
|
-
console.log('Character data changes:', changes.characterData);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
if (changes.resize) {
|
|
47
|
-
console.log('Resize detected:', changes.resize);
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
### DOM Mutation Observation
|
|
53
|
-
|
|
54
|
-
```typescript
|
|
55
|
-
import { htmlDom } from '@medyll/idae-dom-events';
|
|
56
|
-
|
|
57
|
-
htmlDom.track('#widget', {
|
|
58
|
-
onAttributesChange: (element, mutation) => {
|
|
59
|
-
console.log('Modified attribute:', mutation);
|
|
60
|
-
},
|
|
61
|
-
onChildListChange: (mutation) => {
|
|
62
|
-
console.log('Child list modified:', mutation);
|
|
63
|
-
},
|
|
64
|
-
onCharacterDataChange: (mutation) => {
|
|
65
|
-
console.log('Character data modified:', mutation);
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
|
-
```
|
|
69
|
-
|
|
70
|
-
## API
|
|
71
|
-
|
|
72
|
-
### `cssDom(selector, options)`
|
|
73
|
-
|
|
74
|
-
- **`selector`**: CSS selector to target elements.
|
|
75
|
-
- **`options`**: Options to configure tracking, such as `trackChildList`, `trackAttributes`, or `trackResize`.
|
|
76
|
-
|
|
77
|
-
#### Methods
|
|
78
|
-
|
|
79
|
-
- **`each(callback)`**: Tracks changes for each matching element.
|
|
80
|
-
- **`summary(callback)`**: Provides a summary of affected elements.
|
|
81
|
-
|
|
82
|
-
### `htmlDom.track(selector, options)`
|
|
83
|
-
|
|
84
|
-
- **`selector`**: Selector or DOM element to observe.
|
|
85
|
-
- **`options`**: Options to configure the types of mutations to track (`onAttributesChange`, `onChildListChange`, etc.).
|
|
86
|
-
|
|
87
|
-
## Scripts
|
|
88
|
-
|
|
89
|
-
The following npm scripts are available for development and testing:
|
|
90
|
-
|
|
91
|
-
- `npm run dev`: Starts the development server.
|
|
92
|
-
- `npm run build`: Compiles the library for production.
|
|
93
|
-
- `npm run test`: Runs unit tests.
|
|
94
|
-
|
|
95
|
-
## Contribution
|
|
96
|
-
|
|
97
|
-
Contributions are welcome! Feel free to submit a pull request or open an issue to report bugs or propose features.
|
|
98
|
-
|
|
99
|
-
## License
|
|
100
|
-
|
|
101
|
-
This project is licensed under the MIT License. See the [LICENSE](../../LICENSE) file for more details.
|
|
1
|
+
# @medyll/idae-dom-events
|
|
2
|
+
|
|
3
|
+
`@medyll/idae-dom-events` is a library for observing and reacting to changes in the DOM of web applications. It provides tools to track CSS changes, monitor DOM mutations, and manage various events efficiently, making it an ideal choice for dynamic web applications.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **CSS Change Tracking**: Use `CssObserver` to monitor animations, style changes, and resize events.
|
|
8
|
+
- **DOM Mutation Observation**: Use `DomObserver` to track DOM mutations, such as attribute changes, child list modifications, and character data updates.
|
|
9
|
+
- **Event Management**: Efficiently manage DOM-related events.
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
Install the library using npm:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install @medyll/idae-dom-events
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
### CSS Change Tracking
|
|
22
|
+
|
|
23
|
+
```typescript
|
|
24
|
+
import { cssDom } from '@medyll/idae-dom-events';
|
|
25
|
+
|
|
26
|
+
// Track CSS changes on elements with the attribute data-cssDom
|
|
27
|
+
cssDom('[data-cssDom]', {
|
|
28
|
+
trackChildList: true,
|
|
29
|
+
trackAttributes: true,
|
|
30
|
+
trackResize: true
|
|
31
|
+
}).each((element, changes) => {
|
|
32
|
+
console.log('Modified element:', element);
|
|
33
|
+
|
|
34
|
+
if (changes.attributes) {
|
|
35
|
+
console.log('Attribute changes:', changes.attributes);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (changes.childList) {
|
|
39
|
+
console.log('Child list modifications:', changes.childList);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (changes.characterData) {
|
|
43
|
+
console.log('Character data changes:', changes.characterData);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (changes.resize) {
|
|
47
|
+
console.log('Resize detected:', changes.resize);
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### DOM Mutation Observation
|
|
53
|
+
|
|
54
|
+
```typescript
|
|
55
|
+
import { htmlDom } from '@medyll/idae-dom-events';
|
|
56
|
+
|
|
57
|
+
htmlDom.track('#widget', {
|
|
58
|
+
onAttributesChange: (element, mutation) => {
|
|
59
|
+
console.log('Modified attribute:', mutation);
|
|
60
|
+
},
|
|
61
|
+
onChildListChange: (mutation) => {
|
|
62
|
+
console.log('Child list modified:', mutation);
|
|
63
|
+
},
|
|
64
|
+
onCharacterDataChange: (mutation) => {
|
|
65
|
+
console.log('Character data modified:', mutation);
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## API
|
|
71
|
+
|
|
72
|
+
### `cssDom(selector, options)`
|
|
73
|
+
|
|
74
|
+
- **`selector`**: CSS selector to target elements.
|
|
75
|
+
- **`options`**: Options to configure tracking, such as `trackChildList`, `trackAttributes`, or `trackResize`.
|
|
76
|
+
|
|
77
|
+
#### Methods
|
|
78
|
+
|
|
79
|
+
- **`each(callback)`**: Tracks changes for each matching element.
|
|
80
|
+
- **`summary(callback)`**: Provides a summary of affected elements.
|
|
81
|
+
|
|
82
|
+
### `htmlDom.track(selector, options)`
|
|
83
|
+
|
|
84
|
+
- **`selector`**: Selector or DOM element to observe.
|
|
85
|
+
- **`options`**: Options to configure the types of mutations to track (`onAttributesChange`, `onChildListChange`, etc.).
|
|
86
|
+
|
|
87
|
+
## Scripts
|
|
88
|
+
|
|
89
|
+
The following npm scripts are available for development and testing:
|
|
90
|
+
|
|
91
|
+
- `npm run dev`: Starts the development server.
|
|
92
|
+
- `npm run build`: Compiles the library for production.
|
|
93
|
+
- `npm run test`: Runs unit tests.
|
|
94
|
+
|
|
95
|
+
## Contribution
|
|
96
|
+
|
|
97
|
+
Contributions are welcome! Feel free to submit a pull request or open an issue to report bugs or propose features.
|
|
98
|
+
|
|
99
|
+
## License
|
|
100
|
+
|
|
101
|
+
This project is licensed under the MIT License. See the [LICENSE](../../LICENSE) file for more details.
|
|
@@ -1,44 +1,44 @@
|
|
|
1
|
-
<script lang="ts">
|
|
2
|
-
const id = 'aaa';
|
|
3
|
-
const red = new ResizeObserver((entries) => {
|
|
4
|
-
for (let entry of entries) {
|
|
5
|
-
console.log('Element:', entry.target);
|
|
6
|
-
console.log('Width:', entry.contentRect.width);
|
|
7
|
-
console.log('Height:', entry.contentRect.height);
|
|
8
|
-
console.log('Box:', entry.contentRect);
|
|
9
|
-
console.log('Padding:', entry.contentRect.padding);
|
|
10
|
-
}
|
|
11
|
-
});
|
|
12
|
-
red.observe(element);
|
|
13
|
-
|
|
14
|
-
let data;
|
|
15
|
-
data.onchange = () => console.log(element);
|
|
16
|
-
</script>
|
|
17
|
-
<content id="{id}">
|
|
18
|
-
<bind from="company.name"></bind>
|
|
19
|
-
<nav>
|
|
20
|
-
<loop
|
|
21
|
-
data-url="api/users"
|
|
22
|
-
collection="users"
|
|
23
|
-
filter="where:user.name=*jean*"
|
|
24
|
-
sort="name"
|
|
25
|
-
groupBy="field"
|
|
26
|
-
toggle=""
|
|
27
|
-
>
|
|
28
|
-
<h2 slot="title">title once</h2>
|
|
29
|
-
<div mdl="component/li-item" collection="users" data="" data-id="">inner content</div>
|
|
30
|
-
<be-item component>inner content</be-item>
|
|
31
|
-
</loop>
|
|
32
|
-
</nav>
|
|
33
|
-
<if>
|
|
34
|
-
<elseif>
|
|
35
|
-
<div>cond 1</div>
|
|
36
|
-
</elseif>
|
|
37
|
-
<else> cond 2 </else>
|
|
38
|
-
</if>
|
|
39
|
-
<slot> </slot>
|
|
40
|
-
</content>
|
|
41
|
-
<style>
|
|
42
|
-
#id {
|
|
43
|
-
}
|
|
44
|
-
</style>
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
const id = 'aaa';
|
|
3
|
+
const red = new ResizeObserver((entries) => {
|
|
4
|
+
for (let entry of entries) {
|
|
5
|
+
console.log('Element:', entry.target);
|
|
6
|
+
console.log('Width:', entry.contentRect.width);
|
|
7
|
+
console.log('Height:', entry.contentRect.height);
|
|
8
|
+
console.log('Box:', entry.contentRect);
|
|
9
|
+
console.log('Padding:', entry.contentRect.padding);
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
red.observe(element);
|
|
13
|
+
|
|
14
|
+
let data;
|
|
15
|
+
data.onchange = () => console.log(element);
|
|
16
|
+
</script>
|
|
17
|
+
<content id="{id}">
|
|
18
|
+
<bind from="company.name"></bind>
|
|
19
|
+
<nav>
|
|
20
|
+
<loop
|
|
21
|
+
data-url="api/users"
|
|
22
|
+
collection="users"
|
|
23
|
+
filter="where:user.name=*jean*"
|
|
24
|
+
sort="name"
|
|
25
|
+
groupBy="field"
|
|
26
|
+
toggle=""
|
|
27
|
+
>
|
|
28
|
+
<h2 slot="title">title once</h2>
|
|
29
|
+
<div mdl="component/li-item" collection="users" data="" data-id="">inner content</div>
|
|
30
|
+
<be-item component>inner content</be-item>
|
|
31
|
+
</loop>
|
|
32
|
+
</nav>
|
|
33
|
+
<if>
|
|
34
|
+
<elseif>
|
|
35
|
+
<div>cond 1</div>
|
|
36
|
+
</elseif>
|
|
37
|
+
<else> cond 2 </else>
|
|
38
|
+
</if>
|
|
39
|
+
<slot> </slot>
|
|
40
|
+
</content>
|
|
41
|
+
<style>
|
|
42
|
+
#id {
|
|
43
|
+
}
|
|
44
|
+
</style>
|
package/dist/cssDom.js
CHANGED
|
@@ -307,13 +307,13 @@ export class CssObserver {
|
|
|
307
307
|
createStyleFragment(selector, animationName) {
|
|
308
308
|
if ('adoptedStyleSheets' in Document.prototype && 'replace' in CSSStyleSheet.prototype) {
|
|
309
309
|
const sheet = new CSSStyleSheet();
|
|
310
|
-
const styleContent = `@${this.options.legacyCssPrefix}keyframes ${animationName} {
|
|
311
|
-
from { outline: 1px solid transparent; }
|
|
312
|
-
to { outline: 0px solid transparent; }
|
|
313
|
-
}
|
|
314
|
-
${selector} {
|
|
315
|
-
animation-duration: 0.0001s !important;
|
|
316
|
-
${this.options.legacyCssPrefix}animation-name: ${animationName} !important;
|
|
310
|
+
const styleContent = `@${this.options.legacyCssPrefix}keyframes ${animationName} {
|
|
311
|
+
from { outline: 1px solid transparent; }
|
|
312
|
+
to { outline: 0px solid transparent; }
|
|
313
|
+
}
|
|
314
|
+
${selector} {
|
|
315
|
+
animation-duration: 0.0001s !important;
|
|
316
|
+
${this.options.legacyCssPrefix}animation-name: ${animationName} !important;
|
|
317
317
|
}`;
|
|
318
318
|
sheet.replaceSync(styleContent);
|
|
319
319
|
document.adoptedStyleSheets.push(sheet);
|
|
@@ -321,13 +321,13 @@ export class CssObserver {
|
|
|
321
321
|
}
|
|
322
322
|
else {
|
|
323
323
|
const style = document.createElement('style');
|
|
324
|
-
style.textContent = `@${this.options.legacyCssPrefix}keyframes ${animationName} {
|
|
325
|
-
from { outline: 1px solid transparent; }
|
|
326
|
-
to { outline: 0px solid transparent; }
|
|
327
|
-
}
|
|
328
|
-
${selector} {
|
|
329
|
-
animation-duration: 0.0001s !important;
|
|
330
|
-
${this.options.legacyCssPrefix}animation-name: ${animationName} !important;
|
|
324
|
+
style.textContent = `@${this.options.legacyCssPrefix}keyframes ${animationName} {
|
|
325
|
+
from { outline: 1px solid transparent; }
|
|
326
|
+
to { outline: 0px solid transparent; }
|
|
327
|
+
}
|
|
328
|
+
${selector} {
|
|
329
|
+
animation-duration: 0.0001s !important;
|
|
330
|
+
${this.options.legacyCssPrefix}animation-name: ${animationName} !important;
|
|
331
331
|
}`;
|
|
332
332
|
document.head.appendChild(style);
|
|
333
333
|
return style;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@medyll/idae-dom-events",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.91.0",
|
|
4
4
|
"scope": "@medyll",
|
|
5
5
|
"description": "dom-events is a powerful library for observing and reacting to DOM changes in web applications. It provides tools to track CSS changes, monitor DOM mutations, and handle various events efficiently, making it ideal for dynamic web applications.",
|
|
6
6
|
"scripts": {
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"access": "public"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"@medyll/idae-prettier-config": "^1.2.
|
|
37
|
+
"@medyll/idae-prettier-config": "^1.2.1",
|
|
38
38
|
"@playwright/test": "^1.51.1",
|
|
39
39
|
"@sveltejs/adapter-auto": "^5.0.0",
|
|
40
40
|
"@sveltejs/kit": "^2.20.2",
|