@mkhuda/dom-screenshot 0.0.2 → 1.0.1

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 (51) hide show
  1. package/.gitattributes +1 -0
  2. package/EXAMPLES_QUICKSTART.md +240 -0
  3. package/README.md +534 -33
  4. package/TESTING.md +269 -0
  5. package/TESTING_STATUS.md +215 -0
  6. package/TEST_SETUP_SUMMARY.md +335 -0
  7. package/dist/dom-screenshot.d.ts +44 -272
  8. package/dist/dom-screenshot.d.ts.map +1 -0
  9. package/dist/dom-screenshot.esm.js +753 -0
  10. package/dist/dom-screenshot.esm.js.map +1 -0
  11. package/dist/dom-screenshot.min.js +2 -1
  12. package/dist/dom-screenshot.min.js.map +1 -0
  13. package/examples/README.md +211 -0
  14. package/examples/react-app/README.md +161 -0
  15. package/examples/react-app/index.html +12 -0
  16. package/examples/react-app/node_modules/.vite/deps/_metadata.json +46 -0
  17. package/examples/react-app/node_modules/.vite/deps/chunk-FK77NBP6.js +1895 -0
  18. package/examples/react-app/node_modules/.vite/deps/chunk-FK77NBP6.js.map +7 -0
  19. package/examples/react-app/node_modules/.vite/deps/chunk-VSODSHUF.js +21647 -0
  20. package/examples/react-app/node_modules/.vite/deps/chunk-VSODSHUF.js.map +7 -0
  21. package/examples/react-app/node_modules/.vite/deps/package.json +3 -0
  22. package/examples/react-app/node_modules/.vite/deps/react-dom.js +5 -0
  23. package/examples/react-app/node_modules/.vite/deps/react-dom.js.map +7 -0
  24. package/examples/react-app/node_modules/.vite/deps/react-dom_client.js +38 -0
  25. package/examples/react-app/node_modules/.vite/deps/react-dom_client.js.map +7 -0
  26. package/examples/react-app/node_modules/.vite/deps/react.js +4 -0
  27. package/examples/react-app/node_modules/.vite/deps/react.js.map +7 -0
  28. package/examples/react-app/node_modules/.vite/deps/react_jsx-dev-runtime.js +898 -0
  29. package/examples/react-app/node_modules/.vite/deps/react_jsx-dev-runtime.js.map +7 -0
  30. package/examples/react-app/node_modules/.vite/deps/react_jsx-runtime.js +910 -0
  31. package/examples/react-app/node_modules/.vite/deps/react_jsx-runtime.js.map +7 -0
  32. package/examples/react-app/package.json +21 -0
  33. package/examples/react-app/tsconfig.json +25 -0
  34. package/examples/react-app/tsconfig.node.json +10 -0
  35. package/examples/react-app/vite.config.ts +10 -0
  36. package/package.json +75 -43
  37. package/rollup.config.mjs +35 -0
  38. package/tests/README.md +394 -0
  39. package/tests/fixtures/html.ts +192 -0
  40. package/tests/fixtures/images.ts +86 -0
  41. package/tests/fixtures/styles.ts +288 -0
  42. package/tests/helpers/dom-helpers.ts +242 -0
  43. package/tests/mocks/canvas-mock.ts +94 -0
  44. package/tests/mocks/image-mock.ts +147 -0
  45. package/tests/mocks/xhr-mock.ts +202 -0
  46. package/tests/setup.ts +103 -0
  47. package/tests/unit/basic.test.ts +263 -0
  48. package/tests/unit/simple.test.ts +172 -0
  49. package/tsconfig.json +44 -20
  50. package/vitest.config.mts +35 -0
  51. package/rollup.config.js +0 -20
@@ -0,0 +1,172 @@
1
+ /**
2
+ * Simple tests to verify testing infrastructure
3
+ */
4
+ import { describe, it, expect, beforeEach, afterEach } from 'vitest';
5
+ import { createSimpleDiv, createStyledDiv } from '../helpers/dom-helpers';
6
+ import { createValidPngDataUrl, createValidSvgDataUrl } from '../mocks/canvas-mock';
7
+ import { PNG_1X1_TRANSPARENT } from '../fixtures/images';
8
+ import { SIMPLE_HTML } from '../fixtures/html';
9
+
10
+ describe('Testing Infrastructure', () => {
11
+ let container: HTMLElement;
12
+
13
+ beforeEach(() => {
14
+ container = document.createElement('div');
15
+ document.body.appendChild(container);
16
+ });
17
+
18
+ afterEach(() => {
19
+ if (container && container.parentNode) {
20
+ container.parentNode.removeChild(container);
21
+ }
22
+ });
23
+
24
+ describe('Helper Functions', () => {
25
+ it('should create a simple div', () => {
26
+ const div = createSimpleDiv('Test');
27
+ expect(div).toBeInstanceOf(HTMLDivElement);
28
+ expect(div.textContent).toBe('Test');
29
+ });
30
+
31
+ it('should create a styled div', () => {
32
+ const div = createStyledDiv('Styled', { color: 'red', fontSize: '16px' });
33
+ expect(div).toBeInstanceOf(HTMLDivElement);
34
+ expect(div.textContent).toBe('Styled');
35
+ expect(div.style.color).toBe('red');
36
+ expect(div.style.fontSize).toBe('16px');
37
+ });
38
+
39
+ it('should create div with background color', () => {
40
+ const div = createSimpleDiv('Test');
41
+ div.style.backgroundColor = 'blue';
42
+ expect(div.style.backgroundColor).toBe('blue');
43
+ });
44
+ });
45
+
46
+ describe('DOM Operations', () => {
47
+ it('should add div to document', () => {
48
+ const div = createSimpleDiv('Test');
49
+ container.appendChild(div);
50
+ expect(container.contains(div)).toBe(true);
51
+ });
52
+
53
+ it('should find nested elements', () => {
54
+ container.innerHTML = '<div><p>Text</p></div>';
55
+ const p = container.querySelector('p');
56
+ expect(p).toBeDefined();
57
+ expect(p?.textContent).toBe('Text');
58
+ });
59
+
60
+ it('should manipulate styles', () => {
61
+ const div = document.createElement('div');
62
+ div.style.width = '100px';
63
+ div.style.height = '100px';
64
+ expect(div.style.width).toBe('100px');
65
+ expect(div.style.height).toBe('100px');
66
+ });
67
+ });
68
+
69
+ describe('Custom Matchers', () => {
70
+ it('should validate data URL', () => {
71
+ const dataUrl = 'data:text/plain;base64,SGVsbG8=';
72
+ expect(dataUrl).toBeValidDataUrl();
73
+ });
74
+
75
+ it('should validate SVG data URL', () => {
76
+ const svgUrl = createValidSvgDataUrl();
77
+ expect(svgUrl).toBeValidSvgDataUrl();
78
+ });
79
+
80
+ it('should validate PNG data URL', () => {
81
+ const pngUrl = createValidPngDataUrl();
82
+ expect(pngUrl).toBeValidPngDataUrl();
83
+ });
84
+ });
85
+
86
+ describe('Fixtures', () => {
87
+ it('should have HTML fixtures', () => {
88
+ expect(SIMPLE_HTML).toBeDefined();
89
+ expect(typeof SIMPLE_HTML).toBe('string');
90
+ expect(SIMPLE_HTML.length).toBeGreaterThan(0);
91
+ });
92
+
93
+ it('should have image data URLs', () => {
94
+ expect(PNG_1X1_TRANSPARENT).toMatch(/^data:image\/png/);
95
+ });
96
+
97
+ it('should render HTML fixtures', () => {
98
+ container.innerHTML = SIMPLE_HTML;
99
+ expect(container.innerHTML.length).toBeGreaterThan(0);
100
+ });
101
+ });
102
+
103
+ describe('Mocking', () => {
104
+ it('should create valid PNG data URL', () => {
105
+ const png = createValidPngDataUrl();
106
+ expect(png).toBeValidPngDataUrl();
107
+ });
108
+
109
+ it('should create valid SVG data URL', () => {
110
+ const svg = createValidSvgDataUrl();
111
+ expect(svg).toBeValidSvgDataUrl();
112
+ });
113
+
114
+ it('should create image data URL', () => {
115
+ const img = new Image();
116
+ img.src = PNG_1X1_TRANSPARENT;
117
+ expect(img.src).toMatch(/^data:image\/png/);
118
+ });
119
+ });
120
+
121
+ describe('DOM Parsing', () => {
122
+ it('should parse data URL', () => {
123
+ const dataUrl = 'data:text/plain;base64,SGVsbG8gV29ybGQ=';
124
+ expect(dataUrl.split(',')[0]).toContain('data:');
125
+ });
126
+
127
+ it('should handle complex HTML', () => {
128
+ const html = `
129
+ <div>
130
+ <h1>Title</h1>
131
+ <p>Paragraph</p>
132
+ <ul>
133
+ <li>Item 1</li>
134
+ <li>Item 2</li>
135
+ </ul>
136
+ </div>
137
+ `;
138
+ container.innerHTML = html;
139
+ expect(container.querySelector('h1')?.textContent).toBe('Title');
140
+ expect(container.querySelectorAll('li').length).toBe(2);
141
+ });
142
+ });
143
+
144
+ describe('Element Creation', () => {
145
+ it('should create various DOM elements', () => {
146
+ const div = document.createElement('div');
147
+ const span = document.createElement('span');
148
+ const p = document.createElement('p');
149
+
150
+ expect(div).toBeInstanceOf(HTMLDivElement);
151
+ expect(span).toBeInstanceOf(HTMLSpanElement);
152
+ expect(p).toBeInstanceOf(HTMLParagraphElement);
153
+ });
154
+
155
+ it('should set attributes', () => {
156
+ const img = document.createElement('img');
157
+ img.setAttribute('src', PNG_1X1_TRANSPARENT);
158
+ img.setAttribute('alt', 'test');
159
+
160
+ expect(img.getAttribute('src')).toBe(PNG_1X1_TRANSPARENT);
161
+ expect(img.getAttribute('alt')).toBe('test');
162
+ });
163
+
164
+ it('should set classes', () => {
165
+ const div = document.createElement('div');
166
+ div.className = 'test-class another-class';
167
+
168
+ expect(div.classList.contains('test-class')).toBe(true);
169
+ expect(div.classList.contains('another-class')).toBe(true);
170
+ });
171
+ });
172
+ });
package/tsconfig.json CHANGED
@@ -1,21 +1,45 @@
1
1
  {
2
- // Change this to match your project
3
- "include": ["src/**/*"],
4
- "compilerOptions": {
5
- // Tells TypeScript to read JS files, as
6
- // normally they are ignored as source files
7
- "allowJs": true,
8
- // Generate d.ts files
9
- "declaration": true,
10
- // This compiler run should
11
- // only output d.ts files
12
- "emitDeclarationOnly": true,
13
- // Types should go into this directory.
14
- // Removing this would place the .d.ts files
15
- // next to the .js files
16
- "outDir": "dist",
17
- // go to js file when using IDE functions like
18
- // "Go to Definition" in VSCode
19
- "declarationMap": true
20
- }
21
- }
2
+ "compilerOptions": {
3
+ // Target and module settings
4
+ "target": "ES2020",
5
+ "module": "ESNext",
6
+ "moduleResolution": "node",
7
+ "lib": ["ES2020", "DOM"],
8
+
9
+ // Output settings
10
+ "declaration": true,
11
+ "declarationMap": true,
12
+ "sourceMap": true,
13
+ "outDir": "./dist",
14
+
15
+ // Strict type checking
16
+ "strict": false,
17
+ "noImplicitAny": false,
18
+ "strictNullChecks": false,
19
+ "strictFunctionTypes": true,
20
+ "strictBindCallApply": true,
21
+ "strictPropertyInitialization": true,
22
+ "noImplicitThis": true,
23
+ "alwaysStrict": true,
24
+ "noUnusedLocals": false,
25
+ "noUnusedParameters": false,
26
+ "noImplicitReturns": false,
27
+ "noFallthroughCasesInSwitch": true,
28
+
29
+ // Emit settings
30
+ "removeComments": false,
31
+ "esModuleInterop": true,
32
+ "allowSyntheticDefaultImports": true,
33
+ "forceConsistentCasingInFileNames": true,
34
+ "resolveJsonModule": true,
35
+
36
+ // Allow JS compilation for gradual migration
37
+ "allowJs": true,
38
+ "checkJs": false,
39
+
40
+ // Skip lib check for faster compilation
41
+ "skipLibCheck": true
42
+ },
43
+ "include": ["src/**/*"],
44
+ "exclude": ["node_modules", "dist", "**/*.spec.ts", "**/*.test.ts"]
45
+ }
@@ -0,0 +1,35 @@
1
+ import { defineConfig } from 'vitest/config';
2
+ import path from 'path';
3
+
4
+ export default defineConfig({
5
+ test: {
6
+ globals: true,
7
+ environment: 'jsdom',
8
+ setupFiles: ['./tests/setup.ts'],
9
+ include: ['tests/**/*.{test,spec}.ts'],
10
+ exclude: ['node_modules', 'dist', 'types'],
11
+ reporters: ['verbose'],
12
+ coverage: {
13
+ provider: 'v8',
14
+ reporter: ['text', 'json', 'html', 'lcov'],
15
+ exclude: [
16
+ 'node_modules/',
17
+ 'tests/',
18
+ 'dist/',
19
+ '**/*.d.ts',
20
+ '**/*.config.*',
21
+ ],
22
+ },
23
+ pool: 'threads',
24
+ poolOptions: {
25
+ threads: {
26
+ singleThread: true, // Canvas operations should be single-threaded
27
+ },
28
+ },
29
+ },
30
+ resolve: {
31
+ alias: {
32
+ '@': path.resolve(__dirname, './src'),
33
+ },
34
+ },
35
+ });
package/rollup.config.js DELETED
@@ -1,20 +0,0 @@
1
- import { terser } from "rollup-plugin-terser";
2
- import copy from 'rollup-plugin-copy'
3
-
4
- export default {
5
- input: "src/dom-screenshot.js",
6
- output: [
7
- {
8
- file: "dist/dom-screenshot.min.js",
9
- format: "iife",
10
- name: "version",
11
- plugins: [
12
- terser(),
13
- copy({
14
- targets: [{ src: "types/dom-screenshot.d.ts", dest: "dist" }],
15
- hook: 'writeBundle'
16
- }),
17
- ],
18
- },
19
- ],
20
- };