@mkhuda/dom-screenshot 0.0.1 → 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 +542 -25
  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 -44
  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
package/.gitattributes ADDED
@@ -0,0 +1 @@
1
+ *.js linguist-detectable=false
@@ -0,0 +1,240 @@
1
+ # Examples - Quick Start Guide
2
+
3
+ ## React Example - Get It Running in 3 Steps
4
+
5
+ ### Step 1: Install Dependencies (from root)
6
+ ```bash
7
+ npm install
8
+ ```
9
+
10
+ This will automatically install dependencies for both the main library AND the React example (thanks to npm workspaces).
11
+
12
+ ### Step 2: Build the Library
13
+ ```bash
14
+ npm run build
15
+ ```
16
+
17
+ This creates the distributable files that the example app will use.
18
+
19
+ ### Step 3: Start the React Example
20
+ ```bash
21
+ npm run example:dev
22
+ ```
23
+
24
+ The app will automatically open in your browser at `http://localhost:5173`
25
+
26
+ ---
27
+
28
+ ## What You'll See
29
+
30
+ A beautiful React application with:
31
+
32
+ ### 🎨 **Left Side - Content Area**
33
+ - Three colorful cards
34
+ - Statistics section
35
+ - Three capture buttons (SVG, PNG, JPEG)
36
+
37
+ ### 📸 **Right Side - Preview Gallery**
38
+ - Shows all captured screenshots
39
+ - Download button for each capture
40
+ - Upload time displayed
41
+ - Clear All button
42
+
43
+ ### 🎯 **How to Use**
44
+
45
+ 1. Click **"📷 SVG"** to capture as vector format
46
+ 2. Click **"🖼️ PNG"** to capture as raster format
47
+ 3. Click **"📷 JPEG"** to capture as compressed format
48
+ 4. Watch the screenshot appear in the preview gallery
49
+ 5. Download any screenshot or clear them all
50
+
51
+ ---
52
+
53
+ ## Building for Production
54
+
55
+ ```bash
56
+ # From root directory
57
+ npm run example:build
58
+ ```
59
+
60
+ Creates optimized production build in `examples/react-app/dist/`
61
+
62
+ ---
63
+
64
+ ## Key Features Demonstrated
65
+
66
+ ✅ **SVG Capture** - Scalable vector format
67
+ ✅ **PNG Capture** - High-quality raster format
68
+ ✅ **JPEG Capture** - Compressed image format
69
+ ✅ **Error Handling** - Graceful error management
70
+ ✅ **UI Patterns** - Loading states, disabled buttons
71
+ ✅ **File Download** - Automatic download to user device
72
+ ✅ **Live Preview** - Real-time screenshot gallery
73
+ ✅ **Responsive Design** - Works on all screen sizes
74
+
75
+ ---
76
+
77
+ ## Project Structure
78
+
79
+ ```
80
+ dom-screenshot/
81
+ ├── dist/ # Built library output
82
+ ├── src/ # Library source
83
+ ├── tests/ # Library tests
84
+ ├── examples/
85
+ │ ├── README.md # Examples overview
86
+ │ └── react-app/ # React example app
87
+ │ ├── src/
88
+ │ ├── dist/ # Built React app
89
+ │ └── package.json
90
+ └── package.json # Root config with workspaces
91
+ ```
92
+
93
+ ---
94
+
95
+ ## Available Commands
96
+
97
+ From the **root directory**:
98
+
99
+ ```bash
100
+ # Library commands
101
+ npm run build # Build the library
102
+ npm run test:run # Run tests
103
+ npm run test:watch # Watch mode
104
+ npm run test:ui # Vitest UI
105
+
106
+ # Example app commands
107
+ npm run example:dev # Start example in dev mode
108
+ npm run example:build # Build example for production
109
+ ```
110
+
111
+ From the **react-app directory**:
112
+
113
+ ```bash
114
+ npm run dev # Development server
115
+ npm run build # Production build
116
+ npm run preview # Preview built app
117
+ ```
118
+
119
+ ---
120
+
121
+ ## Architecture
122
+
123
+ The React example uses:
124
+
125
+ - **Vite** for fast HMR (Hot Module Replacement) during development
126
+ - **React 18.3.1** with hooks for state management
127
+ - **TypeScript** for type safety
128
+ - **CSS** for styling (no frameworks needed)
129
+ - **@mkhuda/dom-screenshot** for DOM capture
130
+
131
+ ---
132
+
133
+ ## Real-World Use Cases
134
+
135
+ This example demonstrates patterns for:
136
+
137
+ 1. **Export Features** - Let users download UI as images
138
+ 2. **Report Generation** - Create visual reports from data
139
+ 3. **Screenshot Tools** - Build screenshot applications
140
+ 4. **Social Sharing** - Generate share-ready images
141
+ 5. **Documentation** - Auto-capture UI for docs
142
+
143
+ ---
144
+
145
+ ## Troubleshooting
146
+
147
+ ### Port Already in Use
148
+ If port 5173 is taken:
149
+ ```bash
150
+ # Vite will automatically use next available port
151
+ npm run example:dev
152
+ ```
153
+
154
+ ### Module Not Found
155
+ Make sure you've built the library:
156
+ ```bash
157
+ npm run build
158
+ ```
159
+
160
+ ### Styles Not Loading
161
+ Clear cache and reinstall:
162
+ ```bash
163
+ rm -rf node_modules examples/react-app/node_modules
164
+ npm install
165
+ ```
166
+
167
+ ### Canvas Issues
168
+ Some formats (PNG/JPEG) require browser environment. SVG should always work:
169
+ ```tsx
170
+ // Try SVG if other formats fail
171
+ const svg = await domtoimage.toSvg(element);
172
+ ```
173
+
174
+ ---
175
+
176
+ ## Next Steps
177
+
178
+ ### To Learn More
179
+ 1. Read `examples/react-app/README.md` for detailed documentation
180
+ 2. Explore the source code in `examples/react-app/src/`
181
+ 3. Check the main library docs in the root `README.md`
182
+
183
+ ### To Extend
184
+ 1. Add more capture options
185
+ 2. Implement filters/effects
186
+ 3. Add screenshot history
187
+ 4. Integrate with cloud storage
188
+ 5. Create batch processing
189
+
190
+ ### To Deploy
191
+ 1. Build with `npm run example:build`
192
+ 2. Upload `examples/react-app/dist/` to your server
193
+ 3. Or deploy to Vercel/Netlify with one click
194
+
195
+ ---
196
+
197
+ ## File Sizes
198
+
199
+ After building:
200
+
201
+ | File | Size | Purpose |
202
+ |------|------|---------|
203
+ | `dist/dom-screenshot.min.js` | ~9.6 KB | Minified IIFE |
204
+ | `dist/dom-screenshot.esm.js` | ~26 KB | ES Module |
205
+ | `dist/dom-screenshot.d.ts` | ~2 KB | TypeScript types |
206
+
207
+ ---
208
+
209
+ ## Browser Support
210
+
211
+ The library works in:
212
+ - ✅ Chrome/Chromium (latest)
213
+ - ✅ Firefox (latest)
214
+ - ✅ Safari (latest)
215
+ - ✅ Edge (latest)
216
+
217
+ For older browsers, ensure you have the required polyfills.
218
+
219
+ ---
220
+
221
+ ## Performance Tips
222
+
223
+ 1. **Use SVG** for simple UI elements (fastest)
224
+ 2. **Use PNG** for general screenshots
225
+ 3. **Use JPEG** for photo-like content (smallest)
226
+ 4. **Cache element references** with `useRef`
227
+ 5. **Provide loading feedback** during capture
228
+
229
+ ---
230
+
231
+ ## Getting Help
232
+
233
+ 1. Check the example's `README.md`
234
+ 2. Review component source code in `src/components/`
235
+ 3. Look at the main library documentation
236
+ 4. Check GitHub issues for common problems
237
+
238
+ ---
239
+
240
+ **You're all set! 🚀 Start capturing!** 📸