scan2form 1.2.1 → 1.2.2

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
@@ -19,14 +19,14 @@ import { Scan2Form } from 'scan2form';
19
19
 
20
20
  const scanner = new Scan2Form();
21
21
 
22
- // Triggers the scan and puts the file into <input type="file" id="my-input" />
22
+ // Triggers the scan.
23
+ // If your input has accept="image/*", it scans as JPEG. Default is PDF.
23
24
  await scanner.scanToInput('my-input');
24
25
 
25
- // OR use the new advanced options (Images & Preview)
26
+ // OR use advanced options (e.g. for preview)
26
27
  await scanner.scan({
27
- targetInputId: 'my-input',
28
- format: 'jpeg', // 'pdf' | 'jpeg' | 'png' | 'jpg'
29
- previewElementId: 'scan-preview' // ID of an <img>, <iframe>, <object>, or <embed> tag
28
+ targetInputId: 'my-input',
29
+ previewElementId: 'scan-preview'
30
30
  });
31
31
  ```
32
32
 
@@ -30,11 +30,27 @@ export class Scan2Form {
30
30
  // Backward compatibility: if string, treat as inputId
31
31
  let config = {};
32
32
  if (typeof options === 'string') {
33
- config = { targetInputId: options, format: 'pdf' };
33
+ config = { targetInputId: options };
34
34
  }
35
35
  else {
36
- config = { format: 'pdf', ...options };
36
+ config = { ...options };
37
37
  }
38
+ // Rule 5.6: Auto-detect format from Input "accept" attribute if not specified
39
+ if (!config.format && config.targetInputId) {
40
+ const input = document.getElementById(config.targetInputId);
41
+ if (input && input.accept) {
42
+ const accept = input.accept.toLowerCase();
43
+ if (accept.includes('image/png')) {
44
+ config.format = 'png';
45
+ }
46
+ else if (accept.includes('image/jpeg') || accept.includes('image/jpg') || accept.includes('image/*')) {
47
+ config.format = 'jpeg'; // Default image format
48
+ }
49
+ }
50
+ }
51
+ // Default to PDF
52
+ if (!config.format)
53
+ config.format = 'pdf';
38
54
  try {
39
55
  const response = await fetch(`${this.bridgeUrl}/scan`, {
40
56
  method: 'POST',
@@ -33,11 +33,27 @@ class Scan2Form {
33
33
  // Backward compatibility: if string, treat as inputId
34
34
  let config = {};
35
35
  if (typeof options === 'string') {
36
- config = { targetInputId: options, format: 'pdf' };
36
+ config = { targetInputId: options };
37
37
  }
38
38
  else {
39
- config = { format: 'pdf', ...options };
39
+ config = { ...options };
40
40
  }
41
+ // Rule 5.6: Auto-detect format from Input "accept" attribute if not specified
42
+ if (!config.format && config.targetInputId) {
43
+ const input = document.getElementById(config.targetInputId);
44
+ if (input && input.accept) {
45
+ const accept = input.accept.toLowerCase();
46
+ if (accept.includes('image/png')) {
47
+ config.format = 'png';
48
+ }
49
+ else if (accept.includes('image/jpeg') || accept.includes('image/jpg') || accept.includes('image/*')) {
50
+ config.format = 'jpeg'; // Default image format
51
+ }
52
+ }
53
+ }
54
+ // Default to PDF
55
+ if (!config.format)
56
+ config.format = 'pdf';
41
57
  try {
42
58
  const response = await fetch(`${this.bridgeUrl}/scan`, {
43
59
  method: 'POST',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "scan2form",
3
- "version": "1.2.1",
3
+ "version": "1.2.2",
4
4
  "description": "Local offline bridge allowing web browsers to access physical scanners (WIA, TWAIN, SANE).",
5
5
  "main": "dist/scanner-client.js",
6
6
  "scripts": {