@qr-platform/qr-code.js 0.20.1 → 0.20.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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @qr-platform/qr-code-js
2
2
 
3
+ ## 0.20.2
4
+
5
+ ### Patch Changes
6
+
7
+ - 0e4b1dd: Added documentation about width and height options
8
+
3
9
  ## 0.20.1
4
10
 
5
11
  ### Patch Changes
package/README.md CHANGED
@@ -63,6 +63,8 @@ import { QRCodeJs, Options } from '@qr-platform/qr-code.js';
63
63
  // 1. Define options (only 'data' is required)
64
64
  const options: Options = {
65
65
  data: 'https://example.com',
66
+ width: 300, // Fixed 300px width
67
+ height: 300, // Fixed 300px height
66
68
  dotsOptions: {
67
69
  color: '#007bff', // Blue dots
68
70
  type: 'rounded' // Use rounded dots
@@ -98,7 +100,10 @@ qrCode.serialize().then(svgString => {
98
100
  | :--------------------- | :----------------------------------------------- | :------------------- |
99
101
  | `data` | **Required.** The content to encode. | `'Your URL here'` |
100
102
  | `shape` | Overall shape (`'square'` or `'circle'`). | `'circle'` |
103
+ | `width` | QR code width (pixels/CSS units). Ignored when `isResponsive: true`. | `300` or `'20rem'` |
104
+ | `height` | QR code height (pixels/CSS units). Ignored when `isResponsive: true`. | `300` or `'20rem'` |
101
105
  | `margin` | Quiet zone around the QR code (pixels). | `10` |
106
+ | `isResponsive` | Makes SVG responsive (100% width/height), ignoring `width`/`height`. | `true` |
102
107
  | `qrOptions.errorCorrectionLevel` | Error correction (`'L'`, `'M'`, `'Q'`, `'H'`). | `'H'` |
103
108
  | `dotsOptions.type` | Shape of the data dots (e.g., `rounded`, `dot`). | `'rounded'` |
104
109
  | `dotsOptions.color` | Color of the data dots. | `'#ff5733'` |
@@ -90,6 +90,45 @@ if (responsiveContainer) {
90
90
  }
91
91
  ```
92
92
 
93
+ **Example 3: Fixed Dimensions with CSS Units**
94
+
95
+ ```typescript
96
+ const qrLayoutCSSUnits = new QRCodeJs({
97
+ data: 'https://example.com/css-dimensions',
98
+ width: '25rem', // Fixed width using rem units
99
+ height: '25rem', // Fixed height using rem units
100
+ isResponsive: false, // Use specified dimensions (default)
101
+ dotsOptions: {
102
+ color: '#7B1FA2', // Purple dots
103
+ type: 'extraRounded'
104
+ },
105
+ backgroundOptions: {
106
+ color: '#F3E5F5', // Light purple background
107
+ round: 0.1
108
+ }
109
+ });
110
+ qrLayoutCSSUnits.append(document.getElementById('layout-css-units-container'));
111
+ ```
112
+
113
+ **Example 4: Mixed Pixel and Percentage Dimensions**
114
+
115
+ ```typescript
116
+ const qrLayoutMixed = new QRCodeJs({
117
+ data: 'https://example.com/mixed-dimensions',
118
+ width: 400, // Fixed pixel width
119
+ height: '50vh', // Height as 50% of viewport height
120
+ dotsOptions: {
121
+ color: '#E65100', // Deep orange dots
122
+ type: 'classy'
123
+ },
124
+ cornersSquareOptions: {
125
+ color: '#FF8F00', // Lighter orange corners
126
+ type: 'rounded'
127
+ }
128
+ });
129
+ qrLayoutMixed.append(document.getElementById('layout-mixed-container'));
130
+ ```
131
+
93
132
  ---
94
133
 
95
134
  ### Dot Styling
@@ -23,8 +23,10 @@ qrCode.append(document.getElementById('qr-container'));
23
23
  | :--------------------- | :------------------------------------- | :------------- | :-------------------------------------------------------------------------- |
24
24
  | `data` | `string` | - | Specifies the text, URL, or other data to encode into the QR code. **Required option** |
25
25
  | `shape` | `'square' \| 'circle'` | `'square'` | The overall shape of the QR code's boundary. See [ShapeType](#enums-shapetype) enum.
26
+ | `width` | `number \| string` | Auto-calculated| QR code width in pixels or CSS units. When `isResponsive` is false, overrides auto-calculated width. When `isResponsive` is true, this value is ignored. |
27
+ | `height` | `number \| string` | Auto-calculated| QR code height in pixels or CSS units. When `isResponsive` is false, overrides auto-calculated height. When `isResponsive` is true, this value is ignored. |
26
28
  | `margin` | `number` | `0` | The quiet zone (empty space) around the QR code in pixels. |
27
- | `isResponsive` | `boolean` | `false` | When `true`, the QR code SVG resizes dynamically to fill the width or height of the parent container, with no internal size dimensions applied. |
29
+ | `isResponsive` | `boolean` | `false` | Controls whether the QR code SVG should be responsive to its container. When true, SVG uses 100% width/height, ignoring any specified width/height values. When false, SVG uses specified width/height values or auto-calculated dimensions. |
28
30
  | `scale` | `number` (0 to 1.5) | `1` | Scales the QR code size relative to its container or border. |
29
31
  | `offset` | `number` | `0` | Applies a vertical offset (positive moves down, negative moves up) relative to the center. |
30
32
  | `verticalOffset` | `number` | `0` | Applies an absolute vertical offset in pixels. |
@@ -67,16 +67,79 @@ qrCode.append(document.getElementById('qr-container'));
67
67
  margin: 20
68
68
  ```
69
69
 
70
+ ### `width` and `height`
71
+
72
+ - **Purpose**: Allows you to specify custom dimensions for the QR code SVG. When `isResponsive` is `false`, these values override the auto-calculated dimensions. When `isResponsive` is `true`, these values are ignored in favor of responsive sizing.
73
+ - **Type**: `number | string` (optional)
74
+ - **Default**: Auto-calculated based on QR code content and options
75
+ - **Supported formats**:
76
+ - Numbers (pixels): `300`, `500`
77
+ - CSS units: `'300px'`, `'20rem'`, `'50vh'`, `'100%'`
78
+ - **Examples**:
79
+ ```typescript
80
+ // Fixed pixel dimensions
81
+ width: 300,
82
+ height: 300
83
+
84
+ // CSS units
85
+ width: '20rem',
86
+ height: '20rem'
87
+
88
+ // Mixed units
89
+ width: 400,
90
+ height: '30vh'
91
+ ```
92
+
70
93
  ### `isResponsive`
71
94
 
72
- - **Purpose**: Allows the QR code SVG to resize dynamically based on its container size. If `false`, fixed `width` and `height` attributes are set on the SVG.
95
+ - **Purpose**: Controls whether the QR code SVG should be responsive to its container. When `true`, the SVG uses 100% width/height and ignores any specified `width`/`height` values. When `false`, the SVG uses specified `width`/`height` values or auto-calculated dimensions.
73
96
  - **Type**: `boolean`
74
97
  - **Default**: `false`
75
- - **Example**:
98
+ - **Interaction with width/height**:
99
+ - When `true`: SVG becomes fluid (100% width/height), any `width`/`height` values are ignored
100
+ - When `false`: SVG uses `width`/`height` values if provided, otherwise uses auto-calculated dimensions
101
+ - **Examples**:
76
102
  ```typescript
77
- isResponsive: true
103
+ // Responsive QR code (ignores width/height)
104
+ isResponsive: true,
105
+ width: 500, // This will be ignored
106
+ height: 500 // This will be ignored
107
+
108
+ // Fixed size QR code (uses width/height)
109
+ isResponsive: false, // or omit (default)
110
+ width: 300,
111
+ height: 300
78
112
  ```
79
113
 
114
+ ### Dimension Control Use Cases
115
+
116
+ **1. Fixed-Size QR Codes (Print, Downloads):**
117
+ ```typescript
118
+ const qrCode = new QRCodeJs({
119
+ data: 'Fixed size for printing',
120
+ width: 300,
121
+ height: 300,
122
+ isResponsive: false // Default behavior
123
+ });
124
+ ```
125
+
126
+ **2. Responsive Web QR Codes:**
127
+ ```typescript
128
+ const qrCode = new QRCodeJs({
129
+ data: 'Responsive for web',
130
+ isResponsive: true // Ignores width/height, uses container size
131
+ });
132
+ ```
133
+
134
+ **3. CSS Unit Dimensions:**
135
+ ```typescript
136
+ const qrCode = new QRCodeJs({
137
+ data: 'Using CSS units',
138
+ width: '20rem',
139
+ height: '20rem'
140
+ });
141
+ ```
142
+
80
143
  ### `qrOptions`
81
144
 
82
145
  Options that affect the QR code generation algorithm.
package/docs/examples.md CHANGED
@@ -684,6 +684,82 @@ qrUseSettings1.append(document.getElementById('builder-usesettings-container-1')
684
684
 
685
685
  ---
686
686
 
687
+ ## Dimension Control
688
+
689
+ Control the size and responsiveness of your QR codes with `width`, `height`, and `isResponsive` options.
690
+
691
+ ### Fixed Size QR Codes
692
+
693
+ Perfect for downloads, print materials, or when you need exact pixel dimensions:
694
+
695
+ ```javascript
696
+ // Basic fixed size QR code
697
+ const fixedQR = new QRCodeJs({
698
+ data: 'Fixed size QR code - 300x300 pixels',
699
+ width: 300,
700
+ height: 300,
701
+ isResponsive: false // Default behavior
702
+ });
703
+ fixedQR.append(document.getElementById('fixed-size-container'));
704
+ ```
705
+
706
+ ### Using CSS Units
707
+
708
+ You can specify dimensions using any CSS units:
709
+
710
+ ```javascript
711
+ // QR code with CSS units
712
+ const cssUnitsQR = new QRCodeJs({
713
+ data: 'QR code with CSS units',
714
+ width: '20rem', // Using rem units
715
+ height: '20rem', // Using rem units
716
+ dotsOptions: {
717
+ color: '#007bff',
718
+ type: 'rounded'
719
+ }
720
+ });
721
+ cssUnitsQR.append(document.getElementById('css-units-container'));
722
+ ```
723
+
724
+ ### Responsive QR Codes
725
+
726
+ For web applications where the QR code should adapt to its container:
727
+
728
+ ```javascript
729
+ // Responsive QR code - scales with container
730
+ const responsiveQR = new QRCodeJs({
731
+ data: 'Responsive QR code - fills container',
732
+ width: 500, // This will be ignored
733
+ height: 500, // This will be ignored
734
+ isResponsive: true, // SVG becomes fluid (100% width/height)
735
+ dotsOptions: {
736
+ color: '#28a745',
737
+ type: 'extraRounded'
738
+ }
739
+ });
740
+ responsiveQR.append(document.getElementById('responsive-container'));
741
+ ```
742
+
743
+ ### Real-World Example: Your Provided Code
744
+
745
+ ```javascript
746
+ const qrCode = new QRCodeJs({
747
+ data: 'test/test/test22dasdasd',
748
+ scale: 1,
749
+ width: '100', // String width value
750
+ height: '100', // String height value
751
+ imageOptions: {
752
+ imageSize: 1,
753
+ backgroundColor: '#8e44ad',
754
+ margin: 0.2,
755
+ padding: 8,
756
+ radius: '5%'
757
+ }
758
+ });
759
+ ```
760
+
761
+ ---
762
+
687
763
  ### Border Options (Free Version)
688
764
 
689
765
  Adding a basic border (includes "QR-Platform" branding).
@@ -24,10 +24,30 @@ interface Options {
24
24
  /** The overall shape of the QR code's boundary. */
25
25
  shape: ShapeType;
26
26
 
27
+ /**
28
+ * QR code width in pixels or CSS units (e.g., '300px', '100%').
29
+ * When isResponsive is false: This value overrides the auto-calculated width and sets the SVG width attribute.
30
+ * When isResponsive is true: This value is ignored and the SVG uses 100% width.
31
+ * If not specified, the library calculates the optimal width based on QR code size and options.
32
+ */
33
+ width?: number | string;
34
+
35
+ /**
36
+ * QR code height in pixels or CSS units (e.g., '300px', '100%').
37
+ * When isResponsive is false: This value overrides the auto-calculated height and sets the SVG height attribute.
38
+ * When isResponsive is true: This value is ignored and the SVG uses 100% height.
39
+ * If not specified, the library calculates the optimal height based on QR code size and options.
40
+ */
41
+ height?: number | string;
42
+
27
43
  /** The quiet zone (empty space) around the QR code in pixels. */
28
44
  margin: number;
29
45
 
30
- /** When true, the QR code SVG resizes dynamically to fill the width or height of the parent container, with no internal size dimensions applied. */
46
+ /**
47
+ * Controls whether the QR code SVG should be responsive to its container.
48
+ * When true: SVG uses 100% width/height, ignoring any specified width/height values.
49
+ * When false (default): SVG uses specified width/height values or auto-calculated dimensions.
50
+ */
31
51
  isResponsive: boolean;
32
52
 
33
53
  /** Scales the QR code size relative to its container or border. */
@@ -70,14 +70,16 @@ const qrCode = new QRCodeJs({
70
70
 
71
71
  These options control the positioning, scaling, and responsiveness of the QR code within its container or border.
72
72
 
73
- | Option | Type | Default | Description |
74
- | :----------------- | :------- | :------ | :-------------------------------------------------------------------------- |
75
- | `margin` | `number` | `0` | The quiet zone (empty space) around the QR code in pixels. |
76
- | `isResponsive` | `boolean`| `false` | When `true`, the QR code SVG resizes dynamically to fill the width or height of the parent container, with no internal size dimensions applied. |
77
- | `scale` | `number` | `1` | Scales the QR code size relative to its container or border (0 to 1.5). |
78
- | `offset` | `number` | `0` | Applies a vertical offset (positive moves down, negative moves up) relative to the center. |
79
- | `verticalOffset` | `number` | `0` | Applies an absolute vertical offset in pixels. |
80
- | `horizontalOffset` | `number` | `0` | Applies an absolute horizontal offset in pixels. |
73
+ | Option | Type | Default | Description |
74
+ | :----------------- | :----------------- | :-------------- | :-------------------------------------------------------------------------- |
75
+ | `width` | `number \| string` | Auto-calculated | QR code width in pixels or CSS units. When `isResponsive` is false, overrides auto-calculated width. When `isResponsive` is true, this value is ignored. |
76
+ | `height` | `number \| string` | Auto-calculated | QR code height in pixels or CSS units. When `isResponsive` is false, overrides auto-calculated height. When `isResponsive` is true, this value is ignored. |
77
+ | `margin` | `number` | `0` | The quiet zone (empty space) around the QR code in pixels. |
78
+ | `isResponsive` | `boolean` | `false` | Controls whether the QR code SVG should be responsive to its container. When true, SVG uses 100% width/height, ignoring any specified width/height values. When false, SVG uses specified width/height values or auto-calculated dimensions. |
79
+ | `scale` | `number` | `1` | Scales the QR code size relative to its container or border (0 to 1.5). |
80
+ | `offset` | `number` | `0` | Applies a vertical offset (positive moves down, negative moves up) relative to the center. |
81
+ | `verticalOffset` | `number` | `0` | Applies an absolute vertical offset in pixels. |
82
+ | `horizontalOffset` | `number` | `0` | Applies an absolute horizontal offset in pixels. |
81
83
 
82
84
  ##### Example: Layout Options
83
85
 
@@ -90,6 +92,39 @@ const qrCode = new QRCodeJs({
90
92
  horizontalOffset: -5 // Absolute 5px left
91
93
  });
92
94
  ```
95
+
96
+ ##### Dimension Control Examples
97
+
98
+ **Fixed Size QR Code:**
99
+ ```javascript
100
+ const qrCode = new QRCodeJs({
101
+ data: 'Fixed size QR code',
102
+ width: 300, // Fixed 300px width
103
+ height: 300, // Fixed 300px height
104
+ isResponsive: false // Use fixed dimensions (default)
105
+ });
106
+ ```
107
+
108
+ **Responsive QR Code:**
109
+ ```javascript
110
+ const qrCode = new QRCodeJs({
111
+ data: 'Responsive QR code',
112
+ width: 500, // This will be ignored
113
+ height: 500, // This will be ignored
114
+ isResponsive: true // SVG will use 100% width/height
115
+ });
116
+ ```
117
+
118
+ **CSS Units:**
119
+ ```javascript
120
+ const qrCode = new QRCodeJs({
121
+ data: 'QR code with CSS units',
122
+ width: '20rem', // Using rem units
123
+ height: '20rem', // Using rem units
124
+ isResponsive: false
125
+ });
126
+ ```
127
+
93
128
  ---
94
129
 
95
130
  ### Styling Options