qrcode.vue 3.9.1 → 3.11.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/CHANGELOG.md CHANGED
@@ -1,3 +1,25 @@
1
+ ## [3.11.0] - 2026-09-07
2
+
3
+ ### Feature
4
+
5
+ - Add AI assistant resources: Agent Skills-format skill (`skills/qrcode-vue/SKILL.md`) and `llms.txt` (llmstxt.org format), both shipped in the npm package.
6
+ - Serve `llms.txt` at the demo site root (`https://qr-vue.tie.pub/llms.txt`) via rsbuild `output.copy`.
7
+ - Document the AI / LLM resources in all four READMEs (en, zh_cn, zh-hant, ja).
8
+
9
+ ## [3.10.0] - 2026-06-13
10
+
11
+ ### Feature
12
+
13
+ - Add `crossOrigin` support to `imageSettings` for both Canvas and SVG logo images.
14
+ - Expose `toDataURL` and `download` methods via template ref on `QrcodeCanvas`.
15
+ - Expose `toDataURL` and `download` methods via template ref on `QrcodeSvg`.
16
+ - `QrcodeVue` now forwards the above template ref methods based on `render-as`.
17
+
18
+ ### Bugfix
19
+
20
+ - Remove `aria-label` from rendered output to avoid leaking encoded `value`.
21
+ - Fix declaration output path in Rollup build (`dist/src/index.d.ts` → `dist/index.d.ts`).
22
+
1
23
  ## [3.9.1]
2
24
 
3
25
  ### Bugfix
package/README.md CHANGED
@@ -6,7 +6,7 @@
6
6
 
7
7
  A Vue.js component to generate [QRCode](https://en.wikipedia.org/wiki/QR_code). Both support Vue 2 and Vue 3.
8
8
 
9
- [中文](./README-zh_cn.md) | [日本語](./README-ja.md)
9
+ [简体中文](./README-zh_cn.md) | [繁體中文](./README.zh-hant.md) | [日本語](./README-ja.md)
10
10
 
11
11
  ## install
12
12
 
@@ -107,6 +107,7 @@ When you use the component with Vue 3 with `TypeScript`:
107
107
  // x: 10,
108
108
  // y: 10,
109
109
  excavate: true,
110
+ // crossOrigin: 'anonymous', // Set this when you need to export the canvas to an image.
110
111
  })
111
112
 
112
113
  const gradient = ref(false)
@@ -182,6 +183,7 @@ The foreground color of qrcode.
182
183
  width: number, // The height of image
183
184
  excavate?: boolean, // Whether or not to "excavate" the modules around the image.
184
185
  borderRadius?: number, // The border radius of image.
186
+ crossOrigin?: 'anonymous' | 'use-credentials' | '', // The CORS attribute for the image. Useful when exporting canvas to an image.
185
187
  }
186
188
  ```
187
189
 
@@ -260,6 +262,54 @@ The end color of the gradient.
260
262
 
261
263
  The class name of qrcode element.
262
264
 
265
+ ## Template Ref Methods (`QrcodeCanvas` / `QrcodeSvg`)
266
+
267
+ Both `QrcodeCanvas` and `QrcodeSvg` expose the following methods via template ref. `QrcodeVue` forwards them based on the current `render-as`.
268
+
269
+ ### `QrcodeCanvas`
270
+
271
+ ```html
272
+ <script setup>
273
+ import { ref } from 'vue'
274
+ import { QrcodeCanvas } from 'qrcode.vue'
275
+
276
+ const qrRef = ref()
277
+ const handleDownload = () => {
278
+ qrRef.value?.download('my-qrcode.png')
279
+ }
280
+ </script>
281
+
282
+ <qrcode-canvas ref="qrRef" value="https://example.com" />
283
+ ```
284
+
285
+ | Method | Signature | Description |
286
+ |--------|-----------|-------------|
287
+ | `toDataURL` | `(type?: string, quality?: number) => string \| undefined` | Convert the canvas to a data URL. |
288
+ | `download` | `(filename?: string) => void` | Trigger a download of the QR code as a PNG image. |
289
+
290
+ > **CORS note:** When the QR code includes a cross-origin logo image, make sure to set `imageSettings.crossOrigin: 'anonymous'` and that the image server responds with the `Access-Control-Allow-Origin` header. Otherwise the canvas becomes "tainted" and `toDataURL` / `download` will throw a `SecurityError`.
291
+
292
+ ### `QrcodeSvg`
293
+
294
+ ```html
295
+ <script setup>
296
+ import { ref } from 'vue'
297
+ import { QrcodeSvg } from 'qrcode.vue'
298
+
299
+ const qrRef = ref()
300
+ const handleDownload = () => {
301
+ qrRef.value?.download('my-qrcode.svg')
302
+ }
303
+ </script>
304
+
305
+ <qrcode-svg ref="qrRef" value="https://example.com" />
306
+ ```
307
+
308
+ | Method | Signature | Description |
309
+ |--------|-----------|-------------|
310
+ | `toDataURL` | `() => string \| undefined` | Convert the SVG element to a data URL. |
311
+ | `download` | `(filename?: string) => void` | Trigger a download of the QR code as an SVG image. |
312
+
263
313
  ## `QrcodeVue` 3.5+
264
314
 
265
315
  `QrcodeVue` 3.5+ exports separate `QrcodeCanvas` and `QrcodeSvg` components, for which the rollup configuration has been modified:
@@ -303,6 +353,15 @@ Vue.createApp({
303
353
  </script>
304
354
  ```
305
355
 
356
+ ## AI / LLM support
357
+
358
+ qrcode.vue ships resources that help AI coding assistants use this library correctly:
359
+
360
+ - [`llms.txt`](./llms.txt) — a compact, LLM-friendly summary of the library in [llmstxt.org](https://llmstxt.org) format.
361
+ - [`skills/qrcode-vue/SKILL.md`](./skills/qrcode-vue/SKILL.md) — an [Agent Skills](https://agentskills.io)–format skill with the props table, recipes, and pitfalls. Copy it into your assistant's skills directory (e.g. `~/.agents/skills/` or `.claude/skills/`) to give the agent expert knowledge of qrcode.vue.
362
+
363
+ Both files are also included in the npm package.
364
+
306
365
  ## License
307
366
 
308
367
  copyright &copy; 2021 @scopewu, license by [MIT](https://github.com/scopewu/qrcode.vue/blob/main/LICENSE)
@@ -0,0 +1,369 @@
1
+ # qrcode.vue
2
+
3
+ ⚠️ 如果你正在使用 Vue 3,請升級 `qrcode.vue` 到 `3.x`;
4
+
5
+ 🔒 如果你正在使用 Vue 2,請保持 `qrcode.vue` 的版本爲 `1.x`;
6
+
7
+ 一款 Vue.js 二維碼組件(QR Code),同時支援 Vue 2 和 Vue 3.
8
+
9
+ [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/scopewu/qrcode.vue/blob/main/LICENSE)
10
+
11
+ ## 快速開始
12
+
13
+ 快速添加 `qrcode.vue` 組件到項目中
14
+
15
+ ```bash
16
+ npm install --save qrcode.vue # yarn add qrcode.vue
17
+ ```
18
+
19
+ ```
20
+ dist/
21
+ |--- qrcode.vue.cjs.js // CommonJS
22
+ |--- qrcode.vue.esm.js // ES module
23
+ |--- qrcode.vue.browser.js // UMD for browser or require.js or CommonJS
24
+ |--- qrcode.vue.browser.min.js // UMD Minimum size
25
+ ```
26
+
27
+ ## 使用
28
+
29
+ e.g.
30
+
31
+ ```javascript
32
+ import { createApp } from 'vue'
33
+ import QrcodeVue from 'qrcode.vue'
34
+
35
+ createApp({
36
+ data: {
37
+ value: 'https://example.com',
38
+ },
39
+ template: '<qrcode-vue :value="value"></qrcode-vue>',
40
+ components: {
41
+ QrcodeVue,
42
+ },
43
+ }).mount('#root')
44
+ ```
45
+
46
+ 或者,在獨有單文件擴展 `*.vue` 中使用:
47
+
48
+ ```html
49
+ <template>
50
+ <qrcode-vue :value="value" :size="size" level="H" />
51
+ </template>
52
+ <script>
53
+ import QrcodeVue from 'qrcode.vue'
54
+
55
+ export default {
56
+ data() {
57
+ return {
58
+ value: 'https://example.com',
59
+ size: 300,
60
+ }
61
+ },
62
+ components: {
63
+ QrcodeVue,
64
+ },
65
+ }
66
+ </script>
67
+ ```
68
+
69
+ 在 Vue 3 中配合 `TypeScript` 使用:
70
+
71
+ ```html
72
+ <template>
73
+ <qrcode-vue
74
+ :value="value"
75
+ :level="level"
76
+ :render-as="renderAs"
77
+ :background="background"
78
+ :foreground='foreground'
79
+ :gradient="gradient"
80
+ :gradient-type="gradientType"
81
+ :gradient-start-color="gradientStartColor"
82
+ :gradient-end-color="gradientEndColor"
83
+ :image-settings='imageSettings'
84
+ :radius="radius"
85
+ />
86
+ </template>
87
+ <script setup lang="ts">
88
+ import { ref } from 'vue'
89
+ import QrcodeVue from 'qrcode.vue'
90
+ import type { Level, RenderAs, GradientType, ImageSettings } from 'qrcode.vue'
91
+
92
+ const value = ref('qrcode')
93
+ const level = ref<Level>('M')
94
+ const renderAs = ref<RenderAs>('svg')
95
+ const background = ref('#ffffff')
96
+ const foreground = ref('#000000')
97
+ const margin = ref(0)
98
+
99
+ // 可傳入二維碼圖片相關的屬性,支持二維碼 LOGO;
100
+ const imageSettings = ref<ImageSettings>({
101
+ src: 'https://github.com/scopewu.png',
102
+ width: 30,
103
+ height: 30,
104
+ // x: 10,
105
+ // y: 10,
106
+ excavate: true,
107
+ // crossOrigin: 'anonymous', // 如需把 canvas 導出為圖片,請設置此項。
108
+ })
109
+
110
+ // 可傳入漸變相關的屬性,支持漸變:
111
+ const gradient = ref(false)
112
+ const gradientType = ref<GradientType>('linear')
113
+ const gradientStartColor = ref('#000000')
114
+ const gradientEndColor = ref('#38bdf8')
115
+ // 可傳入圓角半徑:
116
+ const radius = ref(0)
117
+ </script>
118
+ ```
119
+
120
+ ## Component props
121
+
122
+ ### `value`
123
+
124
+ - 類型:`string`
125
+ - 默認值:`''`
126
+
127
+ 二維碼的內容值。
128
+
129
+ ### `size`
130
+
131
+ - 類型:`number`
132
+ - 默認值:`100`
133
+
134
+ 二維碼大小。
135
+
136
+ ### `render-as`
137
+
138
+ - 類型:`RenderAs('canvas' | 'svg')`
139
+ - 默認值:`canvas`
140
+
141
+ 生成二維碼的 HTML 標籤,可選 `canvas` 或 `svg`。其中 `svg` 可以用於 SSR。
142
+
143
+ ### `margin`
144
+
145
+ - 類型:`number`
146
+ - 默認值:`0`
147
+
148
+ 定義空白區的寬度應該是多少。
149
+
150
+ ### `level`
151
+
152
+ - 類型:`Level('L' | 'M' | 'Q' | 'H')`
153
+ - 默認值:`L`
154
+
155
+ 二維碼的容錯能力等級,取值爲 'L', 'M', 'Q', 'H' 之一。瞭解更多,[維基百科:QR_code](https://en.wikipedia.org/wiki/QR_code#Error_correction)。
156
+
157
+ ### `background`
158
+
159
+ - 類型:`string`
160
+ - 默認值:`#ffffff`
161
+
162
+ 二維碼背景顏色。
163
+
164
+ ### `foreground`
165
+
166
+ - 類型:`string`
167
+ - 默認值:`#000000`
168
+
169
+ 二維碼前景顏色。
170
+
171
+ ### `image-settings`
172
+
173
+ - 類型: `ImageSettings`
174
+ - 默認值: `{}`
175
+
176
+ ```ts
177
+ export type ImageSettings = {
178
+ src: string, // 圖片的地址。
179
+ x?: number, // 水平橫向偏移。沒有設定值時,圖片劇中
180
+ y?: number, // 垂直豎向偏移。沒有設定值時,圖片劇中
181
+ height: number, // 圖片的高度
182
+ width: number, // 圖片的寬度
183
+ // 是否“挖掘”圖像周圍的模塊。
184
+ // 這意味着嵌入圖像重疊的任何模塊都將使用背景顏色。
185
+ // 使用此選項可確保圖像周圍的邊緣清晰。嵌入透明圖像時也很有用。
186
+ excavate?: boolean,
187
+ borderRadius?: number, // 圖片的邊框圓角。
188
+ crossOrigin?: 'anonymous' | 'use-credentials' | '', // 圖片的 CORS 屬性。如需導出 canvas 為圖片,請設置此項。
189
+ }
190
+ ```
191
+
192
+ 二維碼圖片 logo 配置。
193
+
194
+ ### `radius`
195
+
196
+ - 類型:`number`
197
+ - 默認值:`0`
198
+
199
+ 每個二維碼模塊的圓角半徑,相對於模塊寬度的比例。接受 `0` 到 `0.5` 的值。
200
+
201
+ - `0`(默認)- 方形模塊,直角
202
+ - `0.5` - 最大圓角,模塊變爲圓形
203
+
204
+ 圓角是上下文感知的:相鄰深色模塊之間的內角保持直角,外角則圓角化。
205
+
206
+ ```html
207
+ <qrcode-vue value="test" :radius="0.35" />
208
+ ```
209
+
210
+ ### `id`
211
+
212
+ - 類型:`string`
213
+ - 默認值:`undefined`
214
+
215
+ 自定義 SVG 內部元素(漸變、裁剪路徑)的 ID。SSR 水合一致性需要此屬性 — 傳入 `useId()` 以確保服務端和客戶端生成匹配的 ID。
216
+
217
+ ```html
218
+ <script setup>
219
+ // 僅 vue 3.5+
220
+ import { useId } from 'vue'
221
+ const uid = useId()
222
+
223
+ // vue 3.4 及以下版本
224
+ // const uid = 'qrcode-1'
225
+ // const uid2 = 'qrcode-2'
226
+ </script>
227
+ <qrcode-svg value="test" :id="uid" render-as="svg" />
228
+ ```
229
+
230
+ 省略時使用模塊級計數器,該計數器在多請求的 SSR 環境中不安全。
231
+
232
+ ### `gradient`
233
+
234
+ - 類型: `boolean`
235
+ - 默認值: `false`
236
+
237
+ 啓用二維碼的漸變填充。
238
+
239
+ ### `gradient-type`
240
+
241
+ - 類型: `GradientType('linear' | 'radial')`
242
+ - 默認值: `linear`
243
+
244
+ 指定漸變類型。
245
+
246
+ ### `gradient-start-color`
247
+
248
+ - 類型: `string`
249
+ - 默認值: `#000000`
250
+
251
+ 漸變的起始顏色。
252
+
253
+ ### `gradient-end-color`
254
+
255
+ - 類型: `string`
256
+ - 默認值: `#ffffff`
257
+
258
+ 漸變的結束顏色。
259
+
260
+ ### `class`
261
+
262
+ - 類型:`string`
263
+ - 默認值:`''`
264
+
265
+ 傳遞給二維碼根元素的類名。
266
+
267
+ ## 模板 Ref 方法(`QrcodeCanvas` / `QrcodeSvg`)
268
+
269
+ `QrcodeCanvas` 與 `QrcodeSvg` 都透過模板 ref 暴露以下方法。`QrcodeVue` 會根據目前的 `render-as` 轉發這些方法。
270
+
271
+ ### `QrcodeCanvas`
272
+
273
+ ```html
274
+ <script setup>
275
+ import { ref } from 'vue'
276
+ import { QrcodeCanvas } from 'qrcode.vue'
277
+
278
+ const qrRef = ref()
279
+ const handleDownload = () => {
280
+ qrRef.value?.download('my-qrcode.png')
281
+ }
282
+ </script>
283
+
284
+ <qrcode-canvas ref="qrRef" value="https://example.com" />
285
+ ```
286
+
287
+ | 方法 | 簽名 | 說明 |
288
+ |------|------|------|
289
+ | `toDataURL` | `(type?: string, quality?: number) => string \| undefined` | 將 canvas 轉換為 Data URL。 |
290
+ | `download` | `(filename?: string) => void` | 觸發下載二維碼 PNG 圖片。 |
291
+
292
+ > **CORS 注意:** 當二維碼包含跨域 Logo 圖片時,請確保設置 `imageSettings.crossOrigin: 'anonymous'`,且圖片伺服器返回 `Access-Control-Allow-Origin` 響應頭。否則 canvas 會被「污染」,導致 `toDataURL` / `download` 拋出 `SecurityError`。
293
+
294
+ ### `QrcodeSvg`
295
+
296
+ ```html
297
+ <script setup>
298
+ import { ref } from 'vue'
299
+ import { QrcodeSvg } from 'qrcode.vue'
300
+
301
+ const qrRef = ref()
302
+ const handleDownload = () => {
303
+ qrRef.value?.download('my-qrcode.svg')
304
+ }
305
+ </script>
306
+
307
+ <qrcode-svg ref="qrRef" value="https://example.com" />
308
+ ```
309
+
310
+ | 方法 | 簽名 | 說明 |
311
+ |------|------|------|
312
+ | `toDataURL` | `() => string \| undefined` | 將 SVG 元素轉換為 Data URL。 |
313
+ | `download` | `(filename?: string) => void` | 觸發下載二維碼 SVG 圖片。 |
314
+
315
+ ## `QrcodeVue` 3.5+
316
+
317
+ `QrcodeVue` 3.5+ 後導出獨立的 `QrcodeCanvas` 和 `QrcodeSvg` 組件,爲此修改了 rollup 的配置:
318
+
319
+ ```
320
+ // rollup.config.js
321
+
322
+ - exports: 'default',
323
+ + exports: 'named',
324
+ ```
325
+
326
+ 現在在 common.js 和 cdn 直接引用 `QrcodeVue` 需要使用 `default` 字段:
327
+
328
+ ```js
329
+ const QrcodeVue = require('qrcode.vue').default
330
+ const { default: QrcodeVue, QrcodeCanvas, QrcodeSvg } = require('qrcode.vue')
331
+ ```
332
+
333
+ ```html
334
+ <!--With HTML-->
335
+ <div id="root">
336
+ <p class="flex space-x">
337
+ <qrcode-vue :value="test" render-as="svg"></qrcode-vue>
338
+ <qrcode-canvas :value="test"></qrcode-canvas>
339
+ </p>
340
+ <p><input v-model="test" /></p>
341
+ </div>
342
+ <script src="https://cdn.jsdelivr.net/npm/vue@3.5/dist/vue.global.prod.js"></script>
343
+ <script src="https://cdn.jsdelivr.net/npm/qrcode.vue@3.5/dist/qrcode.vue.browser.min.js"></script>
344
+
345
+ <script>
346
+ Vue.createApp({
347
+ data() { return {
348
+ test: 'Hello World',
349
+ }},
350
+ components: {
351
+ QrcodeVue: QrcodeVue.default,
352
+ QrcodeCanvas: QrcodeVue.QrcodeCanvas,
353
+ },
354
+ }).mount('#root')
355
+ </script>
356
+ ```
357
+
358
+ ## AI / 大模型支援
359
+
360
+ qrcode.vue 提供了幫助 AI 編程助手正確使用本組件庫的資源:
361
+
362
+ - [`llms.txt`](./llms.txt) — 遵循 [llmstxt.org](https://llmstxt.org) 格式的精簡版庫說明,適合大模型閱讀。
363
+ - [`skills/qrcode-vue/SKILL.md`](./skills/qrcode-vue/SKILL.md) — 符合 [Agent Skills](https://agentskills.io) 規範的技能文件,包含 props 速查表、常用範例和常見坑。將其複製到助手的技能目錄(如 `~/.agents/skills/` 或 `.claude/skills/`),即可讓 AI 助手掌握 qrcode.vue 的用法。
364
+
365
+ 這兩個文件也隨 npm 套件一起發佈。
366
+
367
+ ## 軟件許可
368
+
369
+ copyright &copy; 2021 scopewu, license by [MIT](https://github.com/scopewu/qrcode.vue/blob/main/LICENSE)