@zumer/snapdom 1.7.1 → 1.8.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
@@ -7,7 +7,21 @@
7
7
  </p>
8
8
 
9
9
  <p align="center">
10
- <a href="https://www.npmjs.com/package/@zumer/snapdom"><img src="https://img.shields.io/github/package-json/v/zumerlab/snapdom"></a>
10
+ <a href="https://www.npmjs.com/package/@zumer/snapdom">
11
+ <img alt="NPM version" src="https://img.shields.io/npm/v/@zumer/snapdom?style=flat-square&label=Version">
12
+ </a>
13
+ <a href="https://github.com/zumerlab/snapdom/graphs/contributors">
14
+ <img alt="GitHub contributors" src="https://img.shields.io/github/contributors/zumerlab/snapdom?style=flat-square&label=Contributors">
15
+ </a>
16
+ <a href="https://github.com/zumerlab/snapdom/stargazers">
17
+ <img alt="GitHub stars" src="https://img.shields.io/github/stars/zumerlab/snapdom?style=flat-square&label=Stars">
18
+ </a>
19
+ <a href="https://github.com/zumerlab/snapdom/network/members">
20
+ <img alt="GitHub forks" src="https://img.shields.io/github/forks/zumerlab/snapdom?style=flat-square&label=Forks">
21
+ </a>
22
+ <a href="https://github.com/zumerlab/snapdom/blob/main/LICENSE">
23
+ <img alt="License" src="https://img.shields.io/github/license/zumerlab/snapdom?style=flat-square">
24
+ </a>
11
25
  </p>
12
26
 
13
27
  **snapDOM** is a fast and accurate DOM-to-image capture tool built for **Zumly**, a zoom-based view transition framework.
@@ -128,10 +142,50 @@ All capture methods accept an `options` object:
128
142
  | `fast` | boolean | `true` | Skips idle delay for faster results |
129
143
  | `embedFonts` | boolean | `false` | Inlines fonts (icon fonts always embedded) |
130
144
  | `scale` | number | `1` | Output scale multiplier |
145
+ | `width` | number | - | Output specific width size |
146
+ | `height` | number | - | Output specific height size |
131
147
  | `backgroundColor` | string | `"#fff"` | Fallback color for JPG/WebP |
132
148
  | `quality` | number | `1` | Quality for JPG/WebP (0 to 1) |
133
149
  | `crossOrigin` | function | - | Function to determine CORS mode per image URL |
134
150
 
151
+ ### Setting custom dimensions with width and height options
152
+
153
+ Use the `width` and `height` options to generate an image with specific dimensions.
154
+
155
+ **Examples:**
156
+
157
+ **1. Fixed width (proportional Hhight)**
158
+ Sets a specific width while maintaining the aspect ratio. Height adjusts proportionally.
159
+
160
+ ```js
161
+ const result = await snapdom(element, {
162
+ width: 400 // Outputs a 400px-wide image with auto-scaled height
163
+ });
164
+ ```
165
+
166
+ **2. Fixed height (proportional width)**
167
+ Sets a specific height while maintaining the aspect ratio. Width adjusts proportionally.
168
+
169
+ ```js
170
+ const result = await snapdom(element, {
171
+ height: 200 // Outputs a 200px-tall image with auto-scaled width
172
+ });
173
+ ```
174
+
175
+ **3. Fixed width and height (may distort image)**
176
+ Forces exact dimensions, potentially distorting the image if the aspect ratio differs.
177
+
178
+ ```js
179
+ const result = await snapdom(element, {
180
+ width: 800, // Outputs an 800px × 200px image (may stretch/squish content)
181
+ height: 200
182
+ });
183
+ ```
184
+
185
+ **Note:** If `scale` is different from 1, it takes priority over width and height.
186
+ Example: `{ scale: 3, width: 500 }` ignores width and scales the image 3x instead.
187
+
188
+
135
189
  ### Cross-Origin Images
136
190
 
137
191
  By default, snapDOM loads images with `crossOrigin="anonymous"`. You can customize this behavior using the `crossOrigin` option:
@@ -207,7 +261,6 @@ import { snapdom, preCache } from './snapdom.mjs';
207
261
 
208
262
  `snapDOM` is not only highly accurate — it’s **extremely fast**.
209
263
 
210
-
211
264
  Latest benchmarks show significant performance improvements against other libraries:
212
265
 
213
266
  | Scenario | vs. `modern-screenshot` | vs. `html2canvas` |
@@ -237,11 +290,45 @@ npm run test:benchmark
237
290
 
238
291
  They execute in **headless Chromium** using real DOM nodes.
239
292
 
293
+ ## Development
294
+
295
+ To contribute or build snapDOM locally:
296
+
297
+ ```sh
298
+ # Clone the repository
299
+ git clone https://github.com/zumerlab/snapdom.git
300
+ cd snapdom
301
+
302
+ # Install dependencies
303
+ npm install
304
+
305
+ # Compile the library (ESM, CJS, and minified versions)
306
+ npm run compile
307
+
308
+ # Run tests
309
+ npm test
310
+
311
+ # Run Benchmarks
312
+ npm run test:benchmark
313
+ ```
314
+
315
+ The main entry point is in `src/`, and output bundles are generated in the `dist/` folder.
316
+
317
+ For detailed contribution guidelines, please see [CONTRIBUTING](https://github.com/zumerlab/snapdom/blob/main/CONTRIBUTING.md).
318
+
319
+
240
320
  ## Contributors 🙌
241
321
 
242
- <a href="https://github.com/zumerlab/snapdom/graphs/contributors">
243
- <img src="https://contrib.rocks/image?repo=zumerlab/snapdom" />
244
- </a>
322
+ <!-- CONTRIBUTORS:START -->
323
+ <p>
324
+ <a href="https://github.com/tinchox5" title="tinchox5"><img src="https://avatars.githubusercontent.com/u/11557901?v=4&s=100" style="border-radius:10px; width:60px; height:60px; object-fit:cover; margin:5px;" alt="tinchox5"/></a>
325
+ <a href="https://github.com/pedrocateexte" title="pedrocateexte"><img src="https://avatars.githubusercontent.com/u/207524750?v=4&s=100" style="border-radius:10px; width:60px; height:60px; object-fit:cover; margin:5px;" alt="pedrocateexte"/></a>
326
+ <a href="https://github.com/domialex" title="domialex"><img src="https://avatars.githubusercontent.com/u/4694217?v=4&s=100" style="border-radius:10px; width:60px; height:60px; object-fit:cover; margin:5px;" alt="domialex"/></a>
327
+ <a href="https://github.com/elliots" title="elliots"><img src="https://avatars.githubusercontent.com/u/622455?v=4&s=100" style="border-radius:10px; width:60px; height:60px; object-fit:cover; margin:5px;" alt="elliots"/></a>
328
+ <a href="https://github.com/jswhisperer" title="jswhisperer"><img src="https://avatars.githubusercontent.com/u/1177690?v=4&s=100" style="border-radius:10px; width:60px; height:60px; object-fit:cover; margin:5px;" alt="jswhisperer"/></a>
329
+ <a href="https://github.com/jhbae200" title="jhbae200"><img src="https://avatars.githubusercontent.com/u/20170610?v=4&s=100" style="border-radius:10px; width:60px; height:60px; object-fit:cover; margin:5px;" alt="jhbae200"/></a>
330
+ </p>
331
+ <!-- CONTRIBUTORS:END -->
245
332
 
246
333
  ## License
247
334