minipug 1.0.1 → 1.1.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.
Files changed (3) hide show
  1. package/index.mjs +7 -2
  2. package/package.json +1 -1
  3. package/test.js +37 -5
package/index.mjs CHANGED
@@ -32,11 +32,11 @@ export default class MiniPug {
32
32
  'aria-describedby', 'aria-disabled', 'aria-haspopup', 'aria-invalid',
33
33
  'aria-labelledby', 'aria-live', 'aria-pressed', 'aria-required', 'aria-selected',
34
34
  'aria-checked', 'aria-valuenow', 'aria-valuemin', 'aria-valuemax', 'role', 'title', 'alt',
35
- 'disabled', 'readonly'
35
+ 'disabled', 'readonly', 'focused'
36
36
  ]);
37
37
 
38
38
  this.booleanAttributes = new Set([
39
- 'checked', 'selected', 'disabled', 'readonly', 'required'
39
+ 'checked', 'selected', 'disabled', 'readonly', 'required', 'focused'
40
40
  ]);
41
41
  }
42
42
 
@@ -226,6 +226,11 @@ export default class MiniPug {
226
226
  attributes['value'] = capturedValue;
227
227
  }
228
228
  }
229
+
230
+ // Check if element has focus
231
+ if (element === this.document.activeElement) {
232
+ attributes['focused'] = true;
233
+ }
229
234
 
230
235
  return attributes;
231
236
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "minipug",
3
- "version": "1.0.1",
3
+ "version": "1.1.0",
4
4
  "description": "Extract LLM-friendly representation of a webpage",
5
5
  "main": "index.mjs",
6
6
  "type": "module",
package/test.js CHANGED
@@ -26,6 +26,10 @@ const createTestHtml = async () => {
26
26
  <section class="example-section">
27
27
  <p>This is an example.</p>
28
28
  <button aria-label="Next page" class="z2iX5wAef9nHv">Next page</button>
29
+ <form>
30
+ <input type="text" id="searchInput" placeholder="Search...">
31
+ <input type="email" id="emailInput" placeholder="Email...">
32
+ </form>
29
33
  </section>
30
34
  </body>
31
35
  </html>
@@ -45,8 +49,11 @@ const runTest = async () => {
45
49
 
46
50
  try {
47
51
  await page.goto(testFileUrl);
52
+
53
+ // Test 1: Basic conversion without focus
54
+ console.log('\nTest 1: Basic conversion without focus');
48
55
  const miniPugCode = await fs.readFile('./index.mjs', 'utf8');
49
- const result = await page.evaluate(async (code) => {
56
+ let result = await page.evaluate(async (code) => {
50
57
  const blob = new Blob([code], { type: 'application/javascript' });
51
58
  const url = URL.createObjectURL(blob);
52
59
 
@@ -57,19 +64,44 @@ const runTest = async () => {
57
64
  return minipug.convert();
58
65
  }, miniPugCode);
59
66
 
60
- const expectedOutput = `h1 Hello World\nsection\n p This is an example.\n button(aria-label="Next page") Next page`;
67
+ const expectedOutput = `h1 Hello World\nsection\n p This is an example.\n button(aria-label="Next page") Next page\n form\n input(type="text" placeholder="Search...")\n input(type="email" placeholder="Email...")`;
61
68
 
62
- console.log('\nValidation:');
69
+ console.log('\nValidation for basic conversion:');
63
70
  if (result.trim() === expectedOutput.trim()) {
64
71
  console.log('✅ Test passed! Output matches expected result.');
65
72
  } else {
66
73
  console.log('❌ Test failed! Output does not match expected result.');
67
74
  console.log('\nExpected:');
68
75
  console.log(expectedOutput);
69
- console.log(expectedOutput.length);
70
76
  console.log('\nActual:');
71
77
  console.log(result);
72
- console.log(result.length);
78
+ process.exitCode = 1;
79
+ }
80
+
81
+ // Test 2: Conversion with focus
82
+ console.log('\nTest 2: Conversion with focus');
83
+ result = await page.evaluate(async (code) => {
84
+ const blob = new Blob([code], { type: 'application/javascript' });
85
+ const url = URL.createObjectURL(blob);
86
+
87
+ const MiniPugModule = await import(url);
88
+ const MiniPug = MiniPugModule.default;
89
+
90
+ // Focus the search input
91
+ document.getElementById('searchInput').focus();
92
+
93
+ const minipug = new MiniPug(document);
94
+ return minipug.convert();
95
+ }, miniPugCode);
96
+
97
+ // Check if the focused attribute is present in the output
98
+ console.log('\nValidation for focus detection:');
99
+ if (result.includes('input(type="text" placeholder="Search..." focused)')) {
100
+ console.log('✅ Focus detection test passed! The focused attribute is correctly applied.');
101
+ } else {
102
+ console.log('❌ Focus detection test failed! The focused attribute is missing.');
103
+ console.log('\nActual output:');
104
+ console.log(result);
73
105
  process.exitCode = 1;
74
106
  }
75
107
  } finally {