qrdx 0.0.45 → 0.0.46

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.
Files changed (2) hide show
  1. package/dist/cli.js +113 -25
  2. package/package.json +9 -9
package/dist/cli.js CHANGED
@@ -1951,7 +1951,7 @@ var init_template = __esm({
1951
1951
  });
1952
1952
 
1953
1953
  // src/templates.tsx
1954
- var TEMPLATES, getTemplate;
1954
+ var TEMPLATES, getTemplate, getTemplateIds;
1955
1955
  var init_templates = __esm({
1956
1956
  "src/templates.tsx"() {
1957
1957
  init_template();
@@ -1965,6 +1965,7 @@ var init_templates = __esm({
1965
1965
  Halloween
1966
1966
  };
1967
1967
  getTemplate = (templateId) => TEMPLATES[templateId];
1968
+ getTemplateIds = () => Object.keys(TEMPLATES);
1968
1969
  }
1969
1970
  });
1970
1971
 
@@ -3712,6 +3713,16 @@ var RESET = "\x1B[0m";
3712
3713
  var TEXT = "\x1B[38;5;145m";
3713
3714
  var GREEN = "\x1B[38;5;114m";
3714
3715
  var DIM = "\x1B[38;5;102m";
3716
+ function parseColorFlag(value) {
3717
+ const trimmed = value.trim();
3718
+ if (trimmed.startsWith("{")) {
3719
+ try {
3720
+ return JSON.parse(trimmed);
3721
+ } catch {
3722
+ }
3723
+ }
3724
+ return trimmed;
3725
+ }
3715
3726
  var IS_TTY = Boolean(process.stdin.isTTY);
3716
3727
  function parseFlags(args) {
3717
3728
  const flags = {};
@@ -3750,19 +3761,19 @@ function parseFlags(args) {
3750
3761
  i += 2;
3751
3762
  break;
3752
3763
  case "--fg":
3753
- flags.fg = next;
3764
+ flags.fg = next ? parseColorFlag(next) : void 0;
3754
3765
  i += 2;
3755
3766
  break;
3756
3767
  case "--bg":
3757
- flags.bg = next;
3768
+ flags.bg = next ? parseColorFlag(next) : void 0;
3758
3769
  i += 2;
3759
3770
  break;
3760
3771
  case "--eye-color":
3761
- flags.eyeColor = next;
3772
+ flags.eyeColor = next ? parseColorFlag(next) : void 0;
3762
3773
  i += 2;
3763
3774
  break;
3764
3775
  case "--dot-color":
3765
- flags.dotColor = next;
3776
+ flags.dotColor = next ? parseColorFlag(next) : void 0;
3766
3777
  i += 2;
3767
3778
  break;
3768
3779
  case "--logo":
@@ -3781,6 +3792,10 @@ function parseFlags(args) {
3781
3792
  flags.noLogo = true;
3782
3793
  i++;
3783
3794
  break;
3795
+ case "--template":
3796
+ flags.template = next;
3797
+ i += 2;
3798
+ break;
3784
3799
  default:
3785
3800
  i++;
3786
3801
  }
@@ -3805,7 +3820,7 @@ async function runGenerate(args) {
3805
3820
  const flags = parseFlags(args);
3806
3821
  const nonInteractive = !IS_TTY;
3807
3822
  const hasAdvancedFlags = Boolean(
3808
- flags.body || flags.eye || flags.dot || flags.fg || flags.bg || flags.eyeColor || flags.dotColor || flags.logo || flags.level || flags.margin !== void 0
3823
+ flags.body || flags.eye || flags.dot || flags.fg || flags.bg || flags.eyeColor || flags.dotColor || flags.logo || flags.level || flags.margin !== void 0 || flags.template
3809
3824
  );
3810
3825
  Ie(`${TEXT}qrdx${RESET} ${DIM}\u2014 QR Code Generator${RESET}`);
3811
3826
  let value = flags.value;
@@ -3867,6 +3882,7 @@ async function runGenerate(args) {
3867
3882
  let dotColor = flags.dotColor;
3868
3883
  let logo = flags.logo;
3869
3884
  let margin = flags.margin ?? DEFAULT_MARGIN;
3885
+ let template = flags.template;
3870
3886
  if (wantAdvanced && !nonInteractive) {
3871
3887
  if (!flags.level) {
3872
3888
  const res = await ve({
@@ -3923,42 +3939,75 @@ async function runGenerate(args) {
3923
3939
  }
3924
3940
  if (!flags.fg) {
3925
3941
  const res = await he({
3926
- message: "Foreground color",
3942
+ message: `Foreground color ${DIM}(hex or JSON gradient)${RESET}`,
3927
3943
  placeholder: "#000000",
3928
3944
  defaultValue: "#000000",
3929
3945
  validate(v2) {
3930
- if (v2 && !/^#[0-9a-fA-F]{3,8}$/.test(v2)) {
3931
- return "Enter a valid hex color (e.g. #000000)";
3946
+ if (!v2) {
3947
+ return void 0;
3948
+ }
3949
+ if (v2.trim().startsWith("{")) {
3950
+ try {
3951
+ JSON.parse(v2.trim());
3952
+ } catch {
3953
+ return "Enter a valid hex color or JSON gradient object";
3954
+ }
3955
+ return void 0;
3956
+ }
3957
+ if (!/^#[0-9a-fA-F]{3,8}$/.test(v2)) {
3958
+ return "Enter a valid hex color (e.g. #000000) or JSON gradient";
3932
3959
  }
3933
3960
  }
3934
3961
  });
3935
3962
  if (isCancel(res)) {
3936
3963
  handleCancel();
3937
3964
  }
3938
- fg = res || "#000000";
3965
+ fg = parseColorFlag(res || "#000000");
3939
3966
  }
3940
3967
  if (!flags.bg) {
3941
3968
  const res = await he({
3942
- message: "Background color",
3969
+ message: `Background color ${DIM}(hex or JSON gradient)${RESET}`,
3943
3970
  placeholder: "#ffffff",
3944
3971
  defaultValue: "#ffffff",
3945
3972
  validate(v2) {
3946
- if (v2 && !/^#[0-9a-fA-F]{3,8}$/.test(v2)) {
3947
- return "Enter a valid hex color (e.g. #ffffff)";
3973
+ if (!v2) {
3974
+ return void 0;
3975
+ }
3976
+ if (v2.trim().startsWith("{")) {
3977
+ try {
3978
+ JSON.parse(v2.trim());
3979
+ } catch {
3980
+ return "Enter a valid hex color or JSON gradient object";
3981
+ }
3982
+ return void 0;
3983
+ }
3984
+ if (!/^#[0-9a-fA-F]{3,8}$/.test(v2)) {
3985
+ return "Enter a valid hex color (e.g. #ffffff) or JSON gradient";
3948
3986
  }
3949
3987
  }
3950
3988
  });
3951
3989
  if (isCancel(res)) {
3952
3990
  handleCancel();
3953
3991
  }
3954
- bg = res || "#ffffff";
3992
+ bg = parseColorFlag(res || "#ffffff");
3955
3993
  }
3956
3994
  if (eyeColor === void 0) {
3957
3995
  const res = await he({
3958
3996
  message: `Corner eye color ${DIM}(leave blank to match foreground)${RESET}`,
3959
- placeholder: fg,
3997
+ placeholder: "leave blank",
3960
3998
  validate(v2) {
3961
- if (v2 && !/^#[0-9a-fA-F]{3,8}$/.test(v2)) {
3999
+ if (!v2) {
4000
+ return void 0;
4001
+ }
4002
+ if (v2.trim().startsWith("{")) {
4003
+ try {
4004
+ JSON.parse(v2.trim());
4005
+ } catch {
4006
+ return "Enter a valid hex color or JSON gradient object";
4007
+ }
4008
+ return void 0;
4009
+ }
4010
+ if (!/^#[0-9a-fA-F]{3,8}$/.test(v2)) {
3962
4011
  return "Enter a valid hex color or leave blank";
3963
4012
  }
3964
4013
  }
@@ -3966,14 +4015,26 @@ async function runGenerate(args) {
3966
4015
  if (isCancel(res)) {
3967
4016
  handleCancel();
3968
4017
  }
3969
- eyeColor = res || void 0;
4018
+ const eyeVal = res;
4019
+ eyeColor = eyeVal ? parseColorFlag(eyeVal) : void 0;
3970
4020
  }
3971
4021
  if (dotColor === void 0) {
3972
4022
  const res = await he({
3973
4023
  message: `Corner dot color ${DIM}(leave blank to match foreground)${RESET}`,
3974
- placeholder: fg,
4024
+ placeholder: "leave blank",
3975
4025
  validate(v2) {
3976
- if (v2 && !/^#[0-9a-fA-F]{3,8}$/.test(v2)) {
4026
+ if (!v2) {
4027
+ return void 0;
4028
+ }
4029
+ if (v2.trim().startsWith("{")) {
4030
+ try {
4031
+ JSON.parse(v2.trim());
4032
+ } catch {
4033
+ return "Enter a valid hex color or JSON gradient object";
4034
+ }
4035
+ return void 0;
4036
+ }
4037
+ if (!/^#[0-9a-fA-F]{3,8}$/.test(v2)) {
3977
4038
  return "Enter a valid hex color or leave blank";
3978
4039
  }
3979
4040
  }
@@ -3981,7 +4042,23 @@ async function runGenerate(args) {
3981
4042
  if (isCancel(res)) {
3982
4043
  handleCancel();
3983
4044
  }
3984
- dotColor = res || void 0;
4045
+ const dotVal = res;
4046
+ dotColor = dotVal ? parseColorFlag(dotVal) : void 0;
4047
+ }
4048
+ if (!flags.template) {
4049
+ const templateIds = getTemplateIds();
4050
+ const res = await ve({
4051
+ message: `Template ${DIM}(decorative wrapper around the QR code)${RESET}`,
4052
+ options: [
4053
+ { value: "", label: "none" },
4054
+ ...templateIds.filter((id) => id !== "default").map((id) => ({ value: id, label: id }))
4055
+ ],
4056
+ initialValue: ""
4057
+ });
4058
+ if (isCancel(res)) {
4059
+ handleCancel();
4060
+ }
4061
+ template = res || void 0;
3985
4062
  }
3986
4063
  if (logo === void 0 && !flags.noLogo) {
3987
4064
  const addLogo = await ye({
@@ -4047,6 +4124,7 @@ async function runGenerate(args) {
4047
4124
  ...dotColor ? { dotColor } : {},
4048
4125
  margin,
4049
4126
  size,
4127
+ ...template ? { templateId: template } : {},
4050
4128
  ...logo ? {
4051
4129
  imageSettings: {
4052
4130
  src: logo,
@@ -4155,13 +4233,20 @@ ${BOLD}Generate Options:${RESET2}
4155
4233
  ${DIM2}square, rounded, circle, diamond, message,${RESET2}
4156
4234
  ${DIM2}message-reverse, diya, diya-reverse,${RESET2}
4157
4235
  ${DIM2}rounded-triangle, star, banner${RESET2}
4158
- --fg Foreground color ${DIM2}(default: #000000)${RESET2}
4159
- --bg Background color ${DIM2}(default: #ffffff)${RESET2}
4160
- --eye-color Corner eye color ${DIM2}(default: matches --fg)${RESET2}
4161
- --dot-color Corner dot color ${DIM2}(default: matches --fg)${RESET2}
4236
+ --fg Foreground color \u2014 hex or JSON gradient ${DIM2}(default: #000000)${RESET2}
4237
+ --bg Background color \u2014 hex or JSON gradient ${DIM2}(default: #ffffff)${RESET2}
4238
+ --eye-color Corner eye color \u2014 hex or JSON gradient ${DIM2}(default: matches --fg)${RESET2}
4239
+ --dot-color Corner dot color \u2014 hex or JSON gradient ${DIM2}(default: matches --fg)${RESET2}
4162
4240
  --logo Logo URL for center image
4163
4241
  --margin Quiet zone margin in modules ${DIM2}(default: 0)${RESET2}
4164
4242
  --size Output pixel size for SVG/PNG ${DIM2}(default: 512)${RESET2}
4243
+ --template Decorative template wrapper:
4244
+ ${DIM2}Arrow, StandardBox, SquareBorder, StrikedBox, Halloween${RESET2}
4245
+
4246
+ ${BOLD}Gradient Colors:${RESET2}
4247
+ Pass a JSON object to --fg / --bg / --eye-color / --dot-color for gradients:
4248
+ ${DIM2}Linear: '{"type":"linear","stops":[{"color":"#f00","offset":0},{"color":"#00f","offset":100}],"angle":45}'${RESET2}
4249
+ ${DIM2}Radial: '{"type":"radial","stops":[{"color":"#f00","offset":0},{"color":"#00f","offset":100}]}'${RESET2}
4165
4250
 
4166
4251
  ${BOLD}Global Options:${RESET2}
4167
4252
  --help, -h Show this help message
@@ -4173,7 +4258,10 @@ ${BOLD}Examples:${RESET2}
4173
4258
  ${DIM2}$${RESET2} qrdx generate "https://qrdx.dev" -o qr.svg
4174
4259
  ${DIM2}$${RESET2} qrdx generate "https://qrdx.dev" -o qr.png --body circle --eye gear --dot star
4175
4260
  ${DIM2}$${RESET2} qrdx generate "https://qrdx.dev" --fg "#ff0000" --bg "#ffffff" --size 1024
4176
- ${DIM2}$${RESET2} qrdx generate "https://qrdx.dev" --logo "https://qrdx.dev/logo.png" -o branded.svg
4261
+ ${DIM2}$${RESET2} qrdx generate "https://qrdx.dev" --logo "https://qrdx.dev/logo.png" --level H -o branded.svg
4262
+ ${DIM2}$${RESET2} qrdx generate "https://qrdx.dev" --template Arrow -o arrow.svg
4263
+ ${DIM2}$${RESET2} qrdx generate "https://qrdx.dev" --template Halloween --body circle --eye gear -o halloween.svg
4264
+ ${DIM2}$${RESET2} qrdx generate "https://qrdx.dev" --fg '{"type":"linear","stops":[{"color":"#6366f1","offset":0},{"color":"#ec4899","offset":100}],"angle":135}' -o gradient.svg
4177
4265
 
4178
4266
  Visit ${TEXT2}https://qrdx.dev${RESET2} for more.
4179
4267
  `);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "qrdx",
3
- "version": "0.0.45",
3
+ "version": "0.0.46",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.mjs",
6
6
  "types": "./dist/src/index.d.ts",
@@ -29,6 +29,11 @@
29
29
  "types",
30
30
  "src"
31
31
  ],
32
+ "scripts": {
33
+ "build": "tsup && tsc --project tsconfig.build.json --emitDeclarationOnly",
34
+ "clean": "git clean -xdf .cache .turbo dist node_modules",
35
+ "typecheck": "tsc --noEmit"
36
+ },
32
37
  "dependencies": {
33
38
  "jspdf": "^3.0.4",
34
39
  "jsqr": "^1.4.0",
@@ -37,20 +42,15 @@
37
42
  "zod": "^4.3.5"
38
43
  },
39
44
  "devDependencies": {
45
+ "@repo/typescript-config": "workspace:*",
40
46
  "@types/node": "25.1.0",
41
47
  "@types/react": "19.2.7",
42
48
  "@types/react-dom": "19.2.3",
43
49
  "next": "16.1.1",
44
50
  "tsup": "^8.5.1",
45
- "typescript": "5.9.3",
46
- "@repo/typescript-config": "0.0.0"
51
+ "typescript": "5.9.3"
47
52
  },
48
53
  "peerDependencies": {
49
54
  "react-dom": ">=18.0.0"
50
- },
51
- "scripts": {
52
- "build": "tsup && tsc --project tsconfig.build.json --emitDeclarationOnly",
53
- "clean": "git clean -xdf .cache .turbo dist node_modules",
54
- "typecheck": "tsc --noEmit"
55
55
  }
56
- }
56
+ }