@thinkpixellab-public/px-vue 4.1.21 → 4.1.23

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.
@@ -169,7 +169,7 @@ export default {
169
169
 
170
170
  methods: {
171
171
  transformSvgString(svg) {
172
- if (isServer() || typeof DOMParser === undefined) {
172
+ if (isServer() || DOMParser === undefined) {
173
173
  return svg;
174
174
  }
175
175
 
@@ -7,55 +7,99 @@
7
7
  -->
8
8
  <template>
9
9
  <div style="aspect-ratio: 1">
10
- <client-only>
11
- <qrcode-vue
12
- v-if="content"
13
- :value="content"
14
- role="img"
15
- :size="size"
16
- :margin="padding"
17
- :aria-label="label || content"
18
- :image-settings="imageSettingsLocal"
19
- level="M"
20
- ></qrcode-vue>
21
- </client-only>
10
+ <div
11
+ class="px-qr-code"
12
+ ref="qrCode"
13
+ :style="{ width: size + 'px', height: size + 'px' }"
14
+ role="img"
15
+ :aria-label="label || content"
16
+ ></div>
22
17
  </div>
23
18
  </template>
24
19
 
25
20
  <script>
26
- import QrcodeVue from 'qrcode.vue';
21
+ import QRCodeStyling from 'qr-code-styling';
22
+
27
23
  // test
28
24
 
29
25
  export default {
30
26
  name: 'px-qr-code',
31
- components: { QrcodeVue },
32
27
  props: {
33
28
  content: { type: String, default: 'Hello' },
34
29
  label: { type: String },
35
30
  padding: { type: Number, default: 0 },
36
31
  imageSettings: { type: Object, default: () => ({}) },
32
+ qrCodeConfig: { type: Object, default: null },
37
33
  },
38
34
  data() {
39
35
  return { size: 0 };
40
36
  },
41
- computed: {
42
- imageSettingsLocal() {
43
- // qrcode.vue crashes if imageSettings is not an object
44
- return this.imageSettings || {};
45
- },
46
- },
47
37
  mounted() {
48
38
  this.size = Math.min(this.$el.clientWidth, this.$el.clientHeight);
49
39
 
40
+ const options = {
41
+ width: this.size,
42
+ height: this.size,
43
+ image: this.imageSettings?.src || null,
44
+ imageOptions: {
45
+ hideBackgroundDots: false,
46
+ imageSize: this.imageSettings?.size || 0.1,
47
+ margin: 0,
48
+ crossOrigin: 'anonymous',
49
+ },
50
+ data: this.content,
51
+ ...this.qrCodeConfig,
52
+ type: 'svg',
53
+ };
54
+
55
+ this.qrCode = new QRCodeStyling(options);
56
+
50
57
  this.onSizeChange = () => {
51
- this.size = Math.min(this.$el.clientWidth, this.$el.clientHeight);
58
+ const containerSize = Math.min(this.$el.clientWidth, this.$el.clientHeight);
59
+ this.size = containerSize;
60
+
61
+ if (!this.qrCode._qr) {
62
+ return;
63
+ }
64
+
65
+ // 1. Get module count
66
+ const moduleCount = this.qrCode._qr.getModuleCount();
67
+
68
+ const naturalModSize = containerSize / moduleCount;
69
+
70
+ // 2. the qr code lib uses integer pixel sizes, so we need to round down
71
+ const moduleSize = Math.floor(naturalModSize);
72
+
73
+ // 3. recalculate actual size to position the qr code in the top left corner
74
+ const qrSize = moduleCount * moduleSize;
75
+
76
+ // 4. Update QR options
77
+ options.width = qrSize;
78
+ options.height = qrSize;
79
+
80
+ this.qrCode.update(options);
52
81
  };
53
82
 
54
83
  this.resizeObserver = new ResizeObserver(this.onSizeChange);
55
84
  this.resizeObserver.observe(this.$el);
85
+
86
+ this.$nextTick(() => {
87
+ this.qrCode.append(this.$refs.qrCode);
88
+
89
+ this.onSizeChange();
90
+ });
56
91
  },
57
92
  beforeUnmount() {
58
93
  this.resizeObserver?.disconnect();
59
94
  },
60
95
  };
61
96
  </script>
97
+
98
+ <style lang="scss">
99
+ .px-qr-code {
100
+ svg {
101
+ width: 100%;
102
+ height: 100%;
103
+ }
104
+ }
105
+ </style>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thinkpixellab-public/px-vue",
3
- "version": "4.1.21",
3
+ "version": "4.1.23",
4
4
  "description": "General purpose Vue components and helpers that can be used across projects.",
5
5
  "author": {
6
6
  "name": "Pixel Lab"
@@ -31,7 +31,7 @@
31
31
  "gsap": "^3.12.7",
32
32
  "highlight.js": "^11.11.1",
33
33
  "mitt": "^3.0.1",
34
- "qrcode.vue": "^3.6.0",
34
+ "qr-code-styling": "^1.9.2",
35
35
  "sortablejs": "^1.15.6",
36
36
  "throttle-debounce": "^5.0.2",
37
37
  "tiny-date-picker": "^3.2.8",