@liquid-js/qr-code-styling 2.0.3 → 2.0.4

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
@@ -107,7 +107,6 @@ new QRCodeStyling(options) => QRCodeStyling
107
107
  | cornersSquareOptions | object | | Square in the corners styling options |
108
108
  | cornersDotOptions | object | | Dots in the corners styling options |
109
109
  | backgroundOptions | object \| boolean | `false` | QR background styling options, false to disable background |
110
- | margin | number | `0` | Margin (in blocks) to add to the code |
111
110
 
112
111
  `options.qrOptions` structure
113
112
 
@@ -153,11 +152,12 @@ new QRCodeStyling(options) => QRCodeStyling
153
152
 
154
153
  `options.backgroundOptions` structure
155
154
 
156
- | Property | Type | Default Value | Description |
157
- | -------- | ---------------- | ------------- | ------------------- |
158
- | round | number (`0 - 1`) | `0` | Background roundnes |
159
- | color | string | | |
160
- | gradient | object | | |
155
+ | Property | Type | Default Value | Description |
156
+ | -------- | ---------------- | ------------- | ----------------------------------------------------- |
157
+ | round | number (`0 - 1`) | `0` | Background roundnes |
158
+ | color | string | | |
159
+ | gradient | object | | |
160
+ | margin | number | `0` | Margin (in blocks) between background and the QR code |
161
161
 
162
162
  Gradient structure
163
163
 
@@ -228,16 +228,16 @@ const extension = (svg, options) => {
228
228
  const size = Math.min(width, height);
229
229
  const border = document.createElementNS("http://www.w3.org/2000/svg", "rect");
230
230
  const borderAttributes = {
231
- "fill": "none",
232
- "x": (width - size + 40) / 2,
233
- "y": (height - size + 40) / 2,
234
- "width": size - 40,
235
- "height": size - 40,
236
- "stroke": 'black',
231
+ fill: "none",
232
+ x: (width - size + 40) / 2,
233
+ y: (height - size + 40) / 2,
234
+ width: size - 40,
235
+ height: size - 40,
236
+ stroke: "black",
237
237
  "stroke-width": 40,
238
- "rx": 100,
238
+ rx: 100
239
239
  };
240
- Object.keys(borderAttributes).forEach(attribute => {
240
+ Object.keys(borderAttributes).forEach((attribute) => {
241
241
  border.setAttribute(attribute, borderAttributes[attribute]);
242
242
  });
243
243
  svg.appendChild(border);
@@ -4,7 +4,6 @@ export interface RequiredOptions extends Options {
4
4
  shape: ShapeType;
5
5
  width: number;
6
6
  height: number;
7
- margin: number;
8
7
  data: string;
9
8
  qrOptions: {
10
9
  typeNumber: TypeNumber;
@@ -165,7 +165,6 @@ const defaultOptions = {
165
165
  shape: ShapeType.square,
166
166
  width: undefined,
167
167
  height: undefined,
168
- margin: 0,
169
168
  data: "",
170
169
  qrOptions: {
171
170
  typeNumber: TypeNumber[0],
@@ -905,7 +904,8 @@ class QRSVG {
905
904
  }
906
905
  }
907
906
  if (options.shape === ShapeType.circle) {
908
- const additionalDots = Math.floor((minSize / dotSize - count - 2 * this._options.margin) / 2);
907
+ const margin = (this._options.backgroundOptions && this._options.backgroundOptions.margin) || 0;
908
+ const additionalDots = Math.floor((minSize / dotSize - count - 2 * margin) / 2);
909
909
  const fakeCount = count + additionalDots * 2;
910
910
  const xFakeBeginning = xBeginning - additionalDots * dotSize;
911
911
  const yFakeBeginning = yBeginning - additionalDots * dotSize;
@@ -1182,7 +1182,8 @@ let QRCodeStyling$1 = class QRCodeStyling {
1182
1182
  return;
1183
1183
  }
1184
1184
  const count = Math.ceil((this._options.shape == ShapeType.circle ? Math.sqrt(2) : 1) * this._qr.getModuleCount());
1185
- const size = this._options.dotsOptions.size * (count + 2 * this._options.margin);
1185
+ const margin = (this._options.backgroundOptions && this._options.backgroundOptions.margin) || 0;
1186
+ const size = this._options.dotsOptions.size * (count + 2 * margin);
1186
1187
  const qrSVG = new QRSVG({
1187
1188
  ...this._options,
1188
1189
  width: size,