@medyll/idae-dom-events 0.150.0 → 1.0.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 CHANGED
@@ -1,101 +1,159 @@
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
+
6
+ ## Features
7
+
8
+ - **CSS Change Tracking**: Use `cssDom` to monitor animations, style changes, and resize events on selected elements.
9
+ - **DOM Mutation Observation**: Use `htmlDom.track` to observe DOM mutations, such as attribute changes, child list modifications, and character data updates.
10
+ - **Event Management**: Efficiently manage DOM-related events with flexible callback options.
11
+
12
+ ## Installation
13
+
14
+ Install the library using npm:
15
+
16
+ ```bash
17
+ npm install @medyll/idae-dom-events
18
+ ```
19
+
20
+ ## Usage
21
+
22
+ ### CSS Change Tracking
23
+
24
+ ```typescript
25
+ import { cssDom } from '@medyll/idae-dom-events';
26
+
27
+ // Track CSS changes on elements with the attribute data-cssDom
28
+ cssDom('[data-cssDom]', {
29
+ trackChildList: true,
30
+ trackAttributes: true,
31
+ trackResize: true
32
+ }).each((element, changes) => {
33
+ console.log('Modified element:', element);
34
+
35
+ if (changes.attributes) {
36
+ console.log('Attribute changes:', changes.attributes);
37
+ }
38
+
39
+ if (changes.childList) {
40
+ console.log('Child list modifications:', changes.childList);
41
+ }
42
+
43
+ if (changes.characterData) {
44
+ console.log('Character data changes:', changes.characterData);
45
+ }
46
+
47
+ if (changes.resize) {
48
+ console.log('Resize detected:', changes.resize);
49
+ }
50
+ });
51
+ ```
52
+
53
+ ### DOM Mutation Observation
54
+
55
+ ```typescript
56
+ import { htmlDom } from '@medyll/idae-dom-events';
57
+
58
+ htmlDom.track('#widget', {
59
+ onAttributesChange: (element, mutation) => {
60
+ console.log('Modified attribute:', mutation);
61
+ },
62
+ onChildListChange: (mutation) => {
63
+ console.log('Child list modified:', mutation);
64
+ },
65
+ onCharacterDataChange: (mutation) => {
66
+ console.log('Character data modified:', mutation);
67
+ }
68
+ });
69
+ ```
70
+
71
+
72
+ ## TypeScript Types
73
+
74
+ ### Types pour `cssDom`
75
+
76
+ ```ts
77
+ export type CssObserverCommands = {
78
+ start: () => void;
79
+ pause: () => void;
80
+ destroy: () => void;
81
+ };
82
+
83
+ export type CssObserverCallBack = undefined | ((node: Node, mutation?: MutationRecord) => void);
84
+
85
+ export type CssObserverCallBackSummary = (nodes: Node[]) => void;
86
+
87
+ export type CssObserverOptions = {
88
+ strictlyNew: boolean;
89
+ eventDelay: number;
90
+ marquee: string;
91
+ legacyCssPrefix: 'Webkit' | 'Moz' | 'O' | 'ms' | '';
92
+ debounceDelay: number;
93
+ };
94
+ ```
95
+
96
+ ### Types pour `htmlDom.track`
97
+
98
+ ```ts
99
+ type OnMutationType = {
100
+ onResize?: (
101
+ element: Node,
102
+ mutation: MutationRecord,
103
+ observer: MutationObserver,
104
+ ) => void;
105
+ onChange?: (
106
+ element: Node,
107
+ mutation: MutationRecord,
108
+ observer: MutationObserver,
109
+ ) => void;
110
+ onAttributesChange?: (
111
+ element: Node,
112
+ mutation: MutationRecord,
113
+ observer: MutationObserver,
114
+ ) => void;
115
+ onChildListChange?: (
116
+ element: Node,
117
+ mutation: MutationRecord,
118
+ observer: MutationObserver,
119
+ ) => void;
120
+ onCharacterDataChange?: (
121
+ element: Node,
122
+ mutation: MutationRecord,
123
+ observer: MutationObserver,
124
+ ) => void;
125
+ };
126
+ ```
127
+
128
+ ## API
129
+
130
+ ### `cssDom(selector, options)`
131
+
132
+ - **`selector`**: CSS selector to target elements.
133
+ - **`options`**: Options to configure tracking, such as `trackChildList`, `trackAttributes`, or `trackResize`.
134
+
135
+ #### Methods
136
+
137
+ - **`each(callback)`**: Tracks changes for each matching element.
138
+ - **`summary(callback)`**: Provides a summary of affected elements.
139
+
140
+ ### `htmlDom.track(selector, options)`
141
+
142
+ - **`selector`**: Selector or DOM element to observe.
143
+ - **`options`**: Options to configure the types of mutations to track (`onAttributesChange`, `onChildListChange`, etc.).
144
+
145
+ ## Scripts
146
+
147
+ The following npm scripts are available for development and testing:
148
+
149
+ - `npm run dev`: Starts the development server.
150
+ - `npm run build`: Compiles the library for production.
151
+ - `npm run test`: Runs unit tests.
152
+
153
+ ## Contribution
154
+
155
+ Contributions are welcome! Feel free to submit a pull request or open an issue to report bugs or propose features.
156
+
157
+ ## License
158
+
159
+ This project is licensed under the MIT License. See the [LICENSE](../../LICENSE) file for more details.
package/cli.js ADDED
@@ -0,0 +1,46 @@
1
+ #!/usr/bin/env node
2
+
3
+ const fs = require('fs');
4
+ const path = require('path');
5
+
6
+
7
+ const pkgJson = require(path.join(__dirname, 'package.json'));
8
+ const packageName = pkgJson.name.replace(/^@[^/]+\//, '');
9
+ const cmd = process.argv[2];
10
+
11
+
12
+ if (cmd === 'get-readme') {
13
+ const readmePath = path.join(__dirname, 'README.md');
14
+ if (fs.existsSync(readmePath)) {
15
+ const content = fs.readFileSync(readmePath, 'utf8');
16
+ console.log(content);
17
+ } else {
18
+ console.error('README.md not found in this package.');
19
+ process.exit(1);
20
+ }
21
+ } else if (cmd === 'install-skill') {
22
+ const readline = require('readline');
23
+ const rl = readline.createInterface({
24
+ input: process.stdin,
25
+ output: process.stdout
26
+ });
27
+ const skillSrc = path.join(__dirname, 'SKILL.md');
28
+ const skillDest = path.resolve(__dirname, `../../../.github/skills/${packageName}/SKILL.md`);
29
+ if (!fs.existsSync(skillSrc)) {
30
+ console.error('SKILL.md not found in this package.');
31
+ process.exit(1);
32
+ }
33
+ rl.question(`This will copy SKILL.md to .github/skills/${packageName}/SKILL.md. Continue? (y/n): `, (answer) => {
34
+ if (answer.trim().toLowerCase() === 'y' || answer.trim().toLowerCase() === 'yes') {
35
+ fs.mkdirSync(path.dirname(skillDest), { recursive: true });
36
+ fs.copyFileSync(skillSrc, skillDest);
37
+ console.log(`SKILL.md installed to .github/skills/${packageName}/SKILL.md`);
38
+ } else {
39
+ console.log('Operation cancelled.');
40
+ }
41
+ rl.close();
42
+ });
43
+ } else {
44
+ console.log('Usage: <cli> get-readme | install-skill');
45
+ process.exit(1);
46
+ }
@@ -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,66 +1,76 @@
1
- {
2
- "name": "@medyll/idae-dom-events",
3
- "version": "0.150.0",
4
- "scope": "@medyll",
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
- "exports": {
7
- ".": {
8
- "types": "./dist/index.d.ts",
9
- "default": "./dist/index.js"
10
- }
11
- },
12
- "files": [
13
- "dist",
14
- "!dist/**/*.test.*",
15
- "!dist/**/*.spec.*"
16
- ],
17
- "publishConfig": {
18
- "access": "public"
19
- },
20
- "devDependencies": {
21
- "@playwright/test": "^1.51.1",
22
- "@sveltejs/adapter-auto": "^5.0.0",
23
- "@sveltejs/kit": "^2.20.2",
24
- "@sveltejs/package": "^2.3.10",
25
- "@sveltejs/vite-plugin-svelte": "^5.0.3",
26
- "@types/eslint": "9.6.1",
27
- "@typescript-eslint/eslint-plugin": "^8.28.0",
28
- "@typescript-eslint/parser": "^8.28.0",
29
- "@vitest/browser": "^3.0.9",
30
- "eslint": "^9.23.0",
31
- "eslint-config-prettier": "^10.1.1",
32
- "eslint-plugin-svelte": "^3.3.3",
33
- "happy-dom": "^17.4.4",
34
- "prettier": "^3.5.3",
35
- "prettier-plugin-svelte": "^3.3.3",
36
- "svelte": "^5.25.3",
37
- "svelte-check": "^4.1.5",
38
- "tslib": "^2.8.1",
39
- "typescript": "^5.8.2",
40
- "vite": "^6.2.3",
41
- "vitest": "^3.0.9",
42
- "@medyll/idae-prettier-config": "1.2.1"
43
- },
44
- "types": "./dist/index.d.ts",
45
- "type": "module",
46
- "dependencies": {
47
- "blob": "^0.1.0",
48
- "inquirer": "^12.5.0",
49
- "puppeteer": "^24.4.0"
50
- },
51
- "scripts": {
52
- "dev": "vite dev",
53
- "dev:test": "vite dev --port 3000",
54
- "build": "vite build && npm run package",
55
- "preview": "vite preview",
56
- "package": "svelte-kit sync && svelte-package && publint",
57
- "package:watch": "svelte-kit sync && svelte-package --watch",
58
- "check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
59
- "check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
60
- "test": "npm run test:unit",
61
- "test:unit": "vitest",
62
- "lint": "prettier --check . && eslint .",
63
- "format": "prettier --write .",
64
- "package:pre": "node scripts/package-pre.js"
65
- }
66
- }
1
+ {
2
+ "name": "@medyll/idae-dom-events",
3
+ "bin": {
4
+ "idae-dom-events": "./cli.js"
5
+ },
6
+ "version": "1.0.0",
7
+ "scope": "medyll",
8
+ "author": "Lebrun Meddy",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "https://github.com/medyll/idae.git"
12
+ },
13
+ "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.",
14
+ "scripts": {
15
+ "dev": "vite dev",
16
+ "dev:test": "vite dev --port 3000",
17
+ "build": "vite build && npm run package",
18
+ "preview": "vite preview",
19
+ "package": "svelte-kit sync && svelte-package && publint",
20
+ "package:watch": "svelte-kit sync && svelte-package --watch",
21
+ "prepublishOnly": "npm run package",
22
+ "check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
23
+ "check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
24
+ "test": "npm run test:unit",
25
+ "test:unit": "vitest",
26
+ "lint": "prettier --check . && eslint .",
27
+ "format": "prettier --write .",
28
+ "prepackage": "node scripts/package-pre.js"
29
+ },
30
+ "exports": {
31
+ ".": {
32
+ "types": "./dist/index.d.ts",
33
+ "default": "./dist/index.js"
34
+ }
35
+ },
36
+ "files": [
37
+ "dist",
38
+ "!dist/**/*.test.*",
39
+ "!dist/**/*.spec.*"
40
+ ],
41
+ "publishConfig": {
42
+ "access": "public"
43
+ },
44
+ "devDependencies": {
45
+ "@medyll/idae-eslint-config": "latest",
46
+ "@playwright/test": "^1.51.1",
47
+ "@semantic-release/github": "^10.3.5",
48
+ "@sveltejs/adapter-auto": "^5.0.0",
49
+ "@sveltejs/kit": "^2.20.2",
50
+ "@sveltejs/package": "^2.3.10",
51
+ "@sveltejs/vite-plugin-svelte": "^5.0.3",
52
+ "@types/eslint": "9.6.1",
53
+ "@typescript-eslint/eslint-plugin": "^8.28.0",
54
+ "@typescript-eslint/parser": "^8.28.0",
55
+ "@vitest/browser": "^3.0.9",
56
+ "eslint": "^9.23.0",
57
+ "eslint-config-prettier": "^10.1.1",
58
+ "eslint-plugin-svelte": "^3.3.3",
59
+ "happy-dom": "^17.4.4",
60
+ "prettier": "^3.5.3",
61
+ "prettier-plugin-svelte": "^3.3.3",
62
+ "svelte": "^5.25.3",
63
+ "svelte-check": "^4.1.5",
64
+ "tslib": "^2.8.1",
65
+ "typescript": "^5.8.2",
66
+ "vite": "^6.2.3",
67
+ "vitest": "^3.0.9"
68
+ },
69
+ "types": "./dist/index.d.ts",
70
+ "type": "module",
71
+ "dependencies": {
72
+ "blob": "^0.1.0",
73
+ "inquirer": "^12.5.0",
74
+ "puppeteer": "^24.4.0"
75
+ }
76
+ }
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2024 medyll
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.