@zhin.js/plugin-qrcode 1.1.6 → 1.1.8
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 +14 -9
- package/commands/gen/index.js +10 -0
- package/commands/gen/index.ts +10 -0
- package/lib/qrcode-lib.js +4 -2
- package/lib/qrcode-lib.js.map +1 -1
- package/package.json +7 -7
- package/src/qrcode-lib.ts +3 -2
- package/commands/gen/[text]/index.js +0 -16
- package/commands/gen/[text]/index.ts +0 -16
package/README.md
CHANGED
|
@@ -5,24 +5,29 @@ Zhin.js plugin for qrcode functionality.
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
|
-
pnpm
|
|
8
|
+
pnpm exec zhin install @zhin.js/plugin-qrcode
|
|
9
9
|
```
|
|
10
10
|
|
|
11
11
|
## Usage
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
Run the installation command from your application directory. It installs the package and mounts the `qrcode` instance in `package.json#zhin.plugins`. The corresponding `zhin.config.yml` node is:
|
|
14
14
|
|
|
15
15
|
```yaml
|
|
16
16
|
plugins:
|
|
17
|
-
|
|
17
|
+
qrcode: {}
|
|
18
18
|
```
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
## Configuration
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
zhin install @zhin.js/plugin-qrcode
|
|
24
|
-
```
|
|
22
|
+
This plugin currently has no configuration fields. Its [`schema.json`](./schema.json) accepts an empty object; do not place package names in a `plugins` array.
|
|
25
23
|
|
|
26
|
-
##
|
|
24
|
+
## Commands
|
|
25
|
+
|
|
26
|
+
- `gen hello beautiful world`: generate a 300 × 300 QR image.
|
|
27
|
+
- `gen hello --size 512` / `gen hello -s 512`: choose 64–1024 pixels.
|
|
28
|
+
- `scan https://example.com/qr.png`: decode an existing QR image.
|
|
29
|
+
- `gen --help`: show parameters, constraints and defaults.
|
|
27
30
|
|
|
28
|
-
|
|
31
|
+
The Endpoint determines any command prefix. An explicit `commandNamespace` adds a plugin
|
|
32
|
+
namespace; neither is hardcoded in the command. Generation declares text length (1–2048)
|
|
33
|
+
and image size in `defineCommand`; invalid values are rejected before creating the image.
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// Generated by build-plugin-runtime-entries.mjs. Do not edit.
|
|
2
|
+
import { defineCommand } from 'zhin.js/command';
|
|
3
|
+
import { raw } from '@zhin.js/core/runtime';
|
|
4
|
+
import { buildQrImageUrl } from "../../lib/qrcode-lib.js";
|
|
5
|
+
export default defineCommand({
|
|
6
|
+
description: '根据文本或链接生成二维码图片',
|
|
7
|
+
params: { text: { type: 'text', min: 1, max: 2048, description: '二维码内容(可含空格)' } },
|
|
8
|
+
options: { size: { type: 'integer', alias: 's', default: 300, min: 64, max: 1024, description: '图片宽高(像素)' } },
|
|
9
|
+
execute: ({ params, options }) => raw({ type: 'image', data: { url: buildQrImageUrl(params.text, options.size) } }),
|
|
10
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { defineCommand } from 'zhin.js/command';
|
|
2
|
+
import { raw } from '@zhin.js/core/runtime';
|
|
3
|
+
import { buildQrImageUrl } from '../../src/qrcode-lib.js';
|
|
4
|
+
|
|
5
|
+
export default defineCommand({
|
|
6
|
+
description: '根据文本或链接生成二维码图片',
|
|
7
|
+
params: { text: { type: 'text', min: 1, max: 2048, description: '二维码内容(可含空格)' } },
|
|
8
|
+
options: { size: { type: 'integer', alias: 's', default: 300, min: 64, max: 1024, description: '图片宽高(像素)' } },
|
|
9
|
+
execute: ({ params, options }) => raw({ type: 'image', data: { url: buildQrImageUrl(params.text, options.size) } }),
|
|
10
|
+
});
|
package/lib/qrcode-lib.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
const QR_API_BASE = 'https://api.qrserver.com/v1';
|
|
2
|
-
export function buildQrImageUrl(text) {
|
|
3
|
-
|
|
2
|
+
export function buildQrImageUrl(text, size = 300) {
|
|
3
|
+
if (!Number.isInteger(size) || size < 64 || size > 1024)
|
|
4
|
+
throw new TypeError('QR size must be an integer between 64 and 1024');
|
|
5
|
+
return `${QR_API_BASE}/create-qr-code/?size=${size}x${size}&data=${encodeURIComponent(text)}`;
|
|
4
6
|
}
|
|
5
7
|
export function qrImageSegment(text) {
|
|
6
8
|
const qrUrl = buildQrImageUrl(text);
|
package/lib/qrcode-lib.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"qrcode-lib.js","sourceRoot":"","sources":["../src/qrcode-lib.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,GAAG,6BAA6B,CAAC;AAElD,MAAM,UAAU,eAAe,CAAC,IAAY;
|
|
1
|
+
{"version":3,"file":"qrcode-lib.js","sourceRoot":"","sources":["../src/qrcode-lib.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,GAAG,6BAA6B,CAAC;AAElD,MAAM,UAAU,eAAe,CAAC,IAAY,EAAE,IAAI,GAAG,GAAG;IACtD,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,IAAI,GAAG,EAAE,IAAI,IAAI,GAAG,IAAI;QAAE,MAAM,IAAI,SAAS,CAAC,gDAAgD,CAAC,CAAC;IAC/H,OAAO,GAAG,WAAW,yBAAyB,IAAI,IAAI,IAAI,SAAS,kBAAkB,CAAC,IAAI,CAAC,EAAE,CAAC;AAChG,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,IAAY;IACzC,MAAM,KAAK,GAAG,eAAe,CAAC,IAAI,CAAC,CAAC;IACpC,OAAO,CAAC,EAAE,IAAI,EAAE,OAAgB,EAAE,IAAI,EAAE,EAAE,GAAG,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC;AAC5D,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zhin.js/plugin-qrcode",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.8",
|
|
4
4
|
"description": "QR code generator & reader plugin for Zhin.js (Plugin Runtime)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./lib/index.js",
|
|
@@ -38,20 +38,20 @@
|
|
|
38
38
|
},
|
|
39
39
|
"license": "MIT",
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@zhin.js/core": "1.1.
|
|
42
|
-
"@zhin.js/tool": "1.1.
|
|
43
|
-
"@zhin.js/skill": "1.1.
|
|
41
|
+
"@zhin.js/core": "1.1.43",
|
|
42
|
+
"@zhin.js/tool": "1.1.5",
|
|
43
|
+
"@zhin.js/skill": "1.1.5"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"typescript": "^6.0.3",
|
|
47
47
|
"vitest": "^4.1.10",
|
|
48
48
|
"zod": "^4.4.3",
|
|
49
|
-
"zhin.js": "1.1.
|
|
49
|
+
"zhin.js": "1.1.8"
|
|
50
50
|
},
|
|
51
51
|
"peerDependencies": {
|
|
52
52
|
"zod": "^4.0.0",
|
|
53
|
-
"@zhin.js/command": "^1.1.
|
|
54
|
-
"zhin.js": "^1.1.
|
|
53
|
+
"@zhin.js/command": "^1.1.6",
|
|
54
|
+
"zhin.js": "^1.1.8"
|
|
55
55
|
},
|
|
56
56
|
"peerDependenciesMeta": {
|
|
57
57
|
"@zhin.js/command": {
|
package/src/qrcode-lib.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
const QR_API_BASE = 'https://api.qrserver.com/v1';
|
|
2
2
|
|
|
3
|
-
export function buildQrImageUrl(text: string): string {
|
|
4
|
-
|
|
3
|
+
export function buildQrImageUrl(text: string, size = 300): string {
|
|
4
|
+
if (!Number.isInteger(size) || size < 64 || size > 1024) throw new TypeError('QR size must be an integer between 64 and 1024');
|
|
5
|
+
return `${QR_API_BASE}/create-qr-code/?size=${size}x${size}&data=${encodeURIComponent(text)}`;
|
|
5
6
|
}
|
|
6
7
|
|
|
7
8
|
export function qrImageSegment(text: string) {
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
// Generated by build-plugin-runtime-entries.mjs. Do not edit.
|
|
2
|
-
import { defineCommand } from 'zhin.js/command';
|
|
3
|
-
import { raw } from '@zhin.js/core/runtime';
|
|
4
|
-
import { buildQrImageUrl } from "../../../lib/qrcode-lib.js";
|
|
5
|
-
export default defineCommand({
|
|
6
|
-
description: '根据文本或链接生成二维码图片',
|
|
7
|
-
params: { text: { type: 'string' } },
|
|
8
|
-
execute: ({ params, args }) => {
|
|
9
|
-
// [text] 单动态段只消费一个词;含空格的文本需拼上剩余 args
|
|
10
|
-
const text = [String(params.text ?? ''), ...args].join(' ').trim();
|
|
11
|
-
return raw({
|
|
12
|
-
type: 'image',
|
|
13
|
-
data: { url: buildQrImageUrl(text) },
|
|
14
|
-
});
|
|
15
|
-
},
|
|
16
|
-
});
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { defineCommand } from 'zhin.js/command';
|
|
2
|
-
import { raw } from '@zhin.js/core/runtime';
|
|
3
|
-
import { buildQrImageUrl } from '../../../src/qrcode-lib.js';
|
|
4
|
-
|
|
5
|
-
export default defineCommand({
|
|
6
|
-
description: '根据文本或链接生成二维码图片',
|
|
7
|
-
params: { text: { type: 'string' } },
|
|
8
|
-
execute: ({ params, args }) => {
|
|
9
|
-
// [text] 单动态段只消费一个词;含空格的文本需拼上剩余 args
|
|
10
|
-
const text = [String(params.text ?? ''), ...args].join(' ').trim();
|
|
11
|
-
return raw({
|
|
12
|
-
type: 'image',
|
|
13
|
-
data: { url: buildQrImageUrl(text) },
|
|
14
|
-
});
|
|
15
|
-
},
|
|
16
|
-
});
|