vde-open 0.1.16 → 0.1.18

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 (32) hide show
  1. package/README.md +20 -7
  2. package/THIRD_PARTY_NOTICES.md +159 -235
  3. package/dist/cli.js +929 -55
  4. package/dist/daemon.js +3 -4
  5. package/dist/{heap-C3qHm7SE.js → heap-wO8Issp7.js} +1 -2
  6. package/dist/{html-static-Ct_9qmNR.js → html-static-FxIbpM5b.js} +1630 -1216
  7. package/dist/{main-D-ZX3nEP.js → main-C6WuJzmz.js} +618 -320
  8. package/dist/{print-Bb6ArlQl.js → print-DNdOXOlQ.js} +281 -346
  9. package/dist/{render-CY_Mrhyl.js → render-CO37G_5o.js} +4 -7
  10. package/dist/rolldown-runtime-Bl4WtXjF.js +32 -0
  11. package/dist/{search-index-B0xpVDwG.js → search-index-CWn1X9n-.js} +160 -79
  12. package/dist/web/assets/apple-touch-icon-Be989aVe.png +0 -0
  13. package/dist/web/assets/favicon-Du9oTaDs.svg +1 -0
  14. package/dist/web/assets/main-cNlDXnWn.js +124 -0
  15. package/dist/web/assets/markdown.worker-iSTaa6gR.js +13 -0
  16. package/dist/web/assets/mobile-DlPHtOJc.js +1 -0
  17. package/dist/web/assets/rolldown-runtime-WkwZ5CU-.js +1 -0
  18. package/dist/web/assets/src-B8UfTgKw.js +40 -0
  19. package/dist/web/assets/src-DgGe2wbt.css +2 -0
  20. package/dist/web/index.html +6 -4
  21. package/dist/web/mobile.html +6 -4
  22. package/dist/workers/parse-worker.js +5 -6
  23. package/dist/workers/search-worker.js +3 -4
  24. package/docs/agent-usage.md +3 -0
  25. package/package.json +7 -6
  26. package/skills/vde-open/SKILL.md +9 -1
  27. package/dist/web/assets/main-DcvVu7FQ.js +0 -123
  28. package/dist/web/assets/markdown.worker-BhrAVXtB.js +0 -13
  29. package/dist/web/assets/mobile-HCpMXT2S.js +0 -1
  30. package/dist/web/assets/rolldown-runtime-CbXtAM7H.js +0 -1
  31. package/dist/web/assets/src--PpHwH7V.js +0 -41
  32. package/dist/web/assets/src-DinzSLDA.css +0 -2
package/dist/cli.js CHANGED
@@ -1,17 +1,17 @@
1
1
  #!/usr/bin/env node
2
- import { A as resolveRuntimeLocation, C as computeProof, D as renameWithRetry, E as removeWithRetry, M as daemonEntryPath, N as referencedBlobs, O as decodeStateFile, P as version, T as proofMatches, _ as readCurrentLock, a as DAEMON_LOCK_NAME, b as FrameDecoder, c as readIpcKey, d as LISTENER_CONFIG_FILE, f as readListenerConfig, g as inspectOwner, h as acquireLock, i as requirePrivateDirectoryIfExists, j as resolveStateRoot, k as currentPathEnvironment, l as readPointer, m as resolvePcPorts, n as ensurePrivateDirectory, o as POINTER_FILE, p as resolveMobileConfig, r as inspectPrivateDirectory, s as START_LOCK_NAME, t as startDaemon, u as DEFAULT_PORTS, v as releaseLock, w as createNonce, x as encodeFrame, y as systemProcessProbe } from "./main-D-ZX3nEP.js";
3
- import { A as isErrorCode, F as successEnvelope, M as ExitCode, N as envelopeSchema, O as VdeError, P as errorEnvelope, j as isVdeError, k as exitCodeForError, tt as LIMITS } from "./search-index-B0xpVDwG.js";
4
2
  import fs, { fstatSync } from "node:fs";
3
+ import { A as exitCodeForError, F as errorEnvelope, I as successEnvelope, M as isVdeError, N as ExitCode, P as envelopeSchema, j as isErrorCode, k as VdeError, nt as LIMITS } from "./search-index-CWn1X9n-.js";
5
4
  import { lstat, readFile, readdir, rename, rm, stat as stat$1, writeFile } from "node:fs/promises";
6
5
  import path, { dirname, isAbsolute, join, resolve } from "node:path";
7
6
  import { EventEmitter } from "node:events";
8
7
  import childProcess, { execFile, spawn } from "node:child_process";
9
8
  import process$1 from "node:process";
10
9
  import { stripVTControlCharacters } from "node:util";
10
+ import { A as resolveRuntimeLocation, C as computeProof, D as renameWithRetry, E as removeWithRetry, M as daemonEntryPath, N as referencedBlobs, O as decodeStateFile, P as version, T as proofMatches, _ as readCurrentLock, a as DAEMON_LOCK_NAME, b as FrameDecoder, c as readIpcKey, d as LISTENER_CONFIG_FILE, f as readListenerConfig, g as inspectOwner, h as acquireLock, i as requirePrivateDirectoryIfExists, j as resolveStateRoot, k as currentPathEnvironment, l as readPointer, m as resolvePcPorts, n as ensurePrivateDirectory, o as POINTER_FILE, p as resolveMobileConfig, r as inspectPrivateDirectory, s as START_LOCK_NAME, t as startDaemon, u as DEFAULT_PORTS, v as releaseLock, w as createNonce, x as encodeFrame, y as systemProcessProbe } from "./main-C6WuJzmz.js";
11
11
  import { randomBytes, randomUUID } from "node:crypto";
12
- import { connect } from "node:net";
13
12
  import { setTimeout as setTimeout$1 } from "node:timers/promises";
14
- //#region ../../node_modules/.pnpm/commander@15.0.0/node_modules/commander/lib/error.js
13
+ import { connect } from "node:net";
14
+ // ../../node_modules/.pnpm/commander@15.1.0/node_modules/commander/lib/error.js
15
15
  /**
16
16
  * CommanderError class
17
17
  */
@@ -45,8 +45,7 @@ var InvalidArgumentError = class extends CommanderError {
45
45
  this.name = this.constructor.name;
46
46
  }
47
47
  };
48
- //#endregion
49
- //#region ../../node_modules/.pnpm/commander@15.0.0/node_modules/commander/lib/argument.js
48
+ // ../../node_modules/.pnpm/commander@15.1.0/node_modules/commander/lib/argument.js
50
49
  var Argument = class {
51
50
  /**
52
51
  * Initialize a new command argument with the given name and description.
@@ -164,8 +163,7 @@ function humanReadableArgName(arg) {
164
163
  const nameOutput = arg.name() + (arg.variadic === true ? "..." : "");
165
164
  return arg.required ? "<" + nameOutput + ">" : "[" + nameOutput + "]";
166
165
  }
167
- //#endregion
168
- //#region ../../node_modules/.pnpm/commander@15.0.0/node_modules/commander/lib/help.js
166
+ // ../../node_modules/.pnpm/commander@15.1.0/node_modules/commander/lib/help.js
169
167
  /**
170
168
  * TypeScript import types for JSDoc, used by Visual Studio Code IntelliSense and `npm run typescript-checkJS`
171
169
  * https://www.typescriptlang.org/docs/handbook/jsdoc-supported-types.html#import-types
@@ -233,8 +231,8 @@ var Help = class {
233
231
  const removeShort = helpOption.short && cmd._findOption(helpOption.short);
234
232
  const removeLong = helpOption.long && cmd._findOption(helpOption.long);
235
233
  if (!removeShort && !removeLong) visibleOptions.push(helpOption);
236
- else if (helpOption.long && !removeLong) visibleOptions.push(cmd.createOption(helpOption.long, helpOption.description));
237
- else if (helpOption.short && !removeShort) visibleOptions.push(cmd.createOption(helpOption.short, helpOption.description));
234
+ else if (helpOption.long && !removeLong) visibleOptions.push(cmd.createOption(helpOption.long, helpOption.description).helpGroup(helpOption.helpGroupHeading));
235
+ else if (helpOption.short && !removeShort) visibleOptions.push(cmd.createOption(helpOption.short, helpOption.description).helpGroup(helpOption.helpGroupHeading));
238
236
  }
239
237
  if (this.sortOptions) visibleOptions.sort(this.compareOptions);
240
238
  return visibleOptions;
@@ -639,8 +637,7 @@ var Help = class {
639
637
  return wrappedLines.join("\n");
640
638
  }
641
639
  };
642
- //#endregion
643
- //#region ../../node_modules/.pnpm/commander@15.0.0/node_modules/commander/lib/option.js
640
+ // ../../node_modules/.pnpm/commander@15.1.0/node_modules/commander/lib/option.js
644
641
  var Option = class {
645
642
  /**
646
643
  * Initialize a new `Option` with the given `flags` and `description`.
@@ -653,7 +650,7 @@ var Option = class {
653
650
  this.description = description || "";
654
651
  this.required = flags.includes("<");
655
652
  this.optional = flags.includes("[");
656
- this.variadic = /\w\.\.\.[>\]]$/.test(flags);
653
+ this.variadic = /\p{ID_Continue}\.\.\.[>\]]$/u.test(flags);
657
654
  this.mandatory = false;
658
655
  const optionFlags = splitOptionFlags(flags);
659
656
  this.short = optionFlags.shortFlag;
@@ -937,8 +934,7 @@ function splitOptionFlags(flags) {
937
934
  longFlag
938
935
  };
939
936
  }
940
- //#endregion
941
- //#region ../../node_modules/.pnpm/commander@15.0.0/node_modules/commander/lib/suggestSimilar.js
937
+ // ../../node_modules/.pnpm/commander@15.1.0/node_modules/commander/lib/suggestSimilar.js
942
938
  const maxDistance = 3;
943
939
  function editDistance(a, b) {
944
940
  if (Math.abs(a.length - b.length) > maxDistance) return Math.max(a.length, b.length);
@@ -989,8 +985,7 @@ function suggestSimilar(word, candidates) {
989
985
  if (similar.length === 1) return `\n(Did you mean ${similar[0]}?)`;
990
986
  return "";
991
987
  }
992
- //#endregion
993
- //#region ../../node_modules/.pnpm/commander@15.0.0/node_modules/commander/lib/command.js
988
+ // ../../node_modules/.pnpm/commander@15.1.0/node_modules/commander/lib/command.js
994
989
  var Command = class Command extends EventEmitter {
995
990
  /**
996
991
  * Initialize a new `Command`.
@@ -1740,7 +1735,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
1740
1735
  getOptionValueSourceWithGlobals(key) {
1741
1736
  let source;
1742
1737
  this._getCommandAndAncestors().forEach((cmd) => {
1743
- if (cmd.getOptionValueSource(key) !== void 0) source = cmd.getOptionValueSource(key);
1738
+ if (Object.hasOwn(cmd._optionValueSources, key)) source = cmd.getOptionValueSource(key);
1744
1739
  });
1745
1740
  return source;
1746
1741
  }
@@ -2249,7 +2244,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
2249
2244
  return arg.length > 1 && arg[0] === "-";
2250
2245
  }
2251
2246
  const negativeNumberArg = (arg) => {
2252
- if (!/^-(\d+|\d*\.\d+)(e[+-]?\d+)?$/.test(arg)) return false;
2247
+ if (!/^-(\d+|\d*\.\d+)([eE][+-]?\d+)?$/.test(arg)) return false;
2253
2248
  return !this._getCommandAndAncestors().some((cmd) => cmd.options.map((opt) => opt.short).some((short) => /^-\d$/.test(short)));
2254
2249
  };
2255
2250
  let activeVariadicOption = null;
@@ -2649,7 +2644,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
2649
2644
  * (This does not override a group set directly on the subcommand using .helpGroup().)
2650
2645
  *
2651
2646
  * @example
2652
- * program.commandsGroup('Development Commands:);
2647
+ * program.commandsGroup('Development Commands:');
2653
2648
  * program.command('watch')...
2654
2649
  * program.command('lint')...
2655
2650
  * ...
@@ -2818,7 +2813,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
2818
2813
  * Pass in false to disable the built-in help option.
2819
2814
  *
2820
2815
  * @example
2821
- * program.helpOption('-?, --help' 'show help'); // customise
2816
+ * program.helpOption('-?, --help', 'show help'); // customise
2822
2817
  * program.helpOption(false); // disable
2823
2818
  *
2824
2819
  * @param {(string | boolean)} flags
@@ -2940,12 +2935,12 @@ function incrementNodeInspectorPort(args) {
2940
2935
  let debugHost = "127.0.0.1";
2941
2936
  let debugPort = "9229";
2942
2937
  let match;
2943
- if ((match = arg.match(/^(--inspect(-brk)?)$/)) !== null) debugOption = match[1];
2944
- else if ((match = arg.match(/^(--inspect(-brk|-port)?)=([^:]+)$/)) !== null) {
2938
+ if ((match = arg.match(/^(--inspect(-brk|-wait)?)$/)) !== null) debugOption = match[1];
2939
+ else if ((match = arg.match(/^(--inspect(-brk|-port|-wait)?)=(\[[^\]]+\]|[^:]+)$/)) !== null) {
2945
2940
  debugOption = match[1];
2946
2941
  if (/^\d+$/.test(match[3])) debugPort = match[3];
2947
2942
  else debugHost = match[3];
2948
- } else if ((match = arg.match(/^(--inspect(-brk|-port)?)=([^:]+):(\d+)$/)) !== null) {
2943
+ } else if ((match = arg.match(/^(--inspect(-brk|-port|-wait)?)=(\[[^\]]+\]|[^:]+):(\d+)$/)) !== null) {
2949
2944
  debugOption = match[1];
2950
2945
  debugHost = match[3];
2951
2946
  debugPort = match[4];
@@ -2965,8 +2960,890 @@ function useColor() {
2965
2960
  if (process$1.env.FORCE_COLOR || process$1.env.CLICOLOR_FORCE !== void 0) return true;
2966
2961
  }
2967
2962
  new Command();
2968
- //#endregion
2969
- //#region src/doctor/doctor.ts
2963
+ // ../../node_modules/.pnpm/uqr@0.1.3/node_modules/uqr/dist/index.mjs
2964
+ var QrCodeDataType = /* @__PURE__ */ ((QrCodeDataType2) => {
2965
+ QrCodeDataType2[QrCodeDataType2["Border"] = -1] = "Border";
2966
+ QrCodeDataType2[QrCodeDataType2["Data"] = 0] = "Data";
2967
+ QrCodeDataType2[QrCodeDataType2["Function"] = 1] = "Function";
2968
+ QrCodeDataType2[QrCodeDataType2["Position"] = 2] = "Position";
2969
+ QrCodeDataType2[QrCodeDataType2["Timing"] = 3] = "Timing";
2970
+ QrCodeDataType2[QrCodeDataType2["Alignment"] = 4] = "Alignment";
2971
+ return QrCodeDataType2;
2972
+ })(QrCodeDataType || {});
2973
+ const LOW = [0, 1];
2974
+ const MEDIUM = [1, 0];
2975
+ const QUARTILE = [2, 3];
2976
+ const HIGH = [3, 2];
2977
+ const EccMap = {
2978
+ L: LOW,
2979
+ M: MEDIUM,
2980
+ Q: QUARTILE,
2981
+ H: HIGH
2982
+ };
2983
+ const NUMERIC_REGEX = /^\d*$/;
2984
+ const ALPHANUMERIC_REGEX = /^[A-Z0-9 $%*+./:-]*$/;
2985
+ const ALPHANUMERIC_CHARSET = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:";
2986
+ const MIN_VERSION = 1;
2987
+ const MAX_VERSION = 40;
2988
+ const PENALTY_N1 = 3;
2989
+ const PENALTY_N2 = 3;
2990
+ const PENALTY_N3 = 40;
2991
+ const PENALTY_N4 = 10;
2992
+ const ECC_CODEWORDS_PER_BLOCK = [
2993
+ [
2994
+ -1,
2995
+ 7,
2996
+ 10,
2997
+ 15,
2998
+ 20,
2999
+ 26,
3000
+ 18,
3001
+ 20,
3002
+ 24,
3003
+ 30,
3004
+ 18,
3005
+ 20,
3006
+ 24,
3007
+ 26,
3008
+ 30,
3009
+ 22,
3010
+ 24,
3011
+ 28,
3012
+ 30,
3013
+ 28,
3014
+ 28,
3015
+ 28,
3016
+ 28,
3017
+ 30,
3018
+ 30,
3019
+ 26,
3020
+ 28,
3021
+ 30,
3022
+ 30,
3023
+ 30,
3024
+ 30,
3025
+ 30,
3026
+ 30,
3027
+ 30,
3028
+ 30,
3029
+ 30,
3030
+ 30,
3031
+ 30,
3032
+ 30,
3033
+ 30,
3034
+ 30
3035
+ ],
3036
+ [
3037
+ -1,
3038
+ 10,
3039
+ 16,
3040
+ 26,
3041
+ 18,
3042
+ 24,
3043
+ 16,
3044
+ 18,
3045
+ 22,
3046
+ 22,
3047
+ 26,
3048
+ 30,
3049
+ 22,
3050
+ 22,
3051
+ 24,
3052
+ 24,
3053
+ 28,
3054
+ 28,
3055
+ 26,
3056
+ 26,
3057
+ 26,
3058
+ 26,
3059
+ 28,
3060
+ 28,
3061
+ 28,
3062
+ 28,
3063
+ 28,
3064
+ 28,
3065
+ 28,
3066
+ 28,
3067
+ 28,
3068
+ 28,
3069
+ 28,
3070
+ 28,
3071
+ 28,
3072
+ 28,
3073
+ 28,
3074
+ 28,
3075
+ 28,
3076
+ 28,
3077
+ 28
3078
+ ],
3079
+ [
3080
+ -1,
3081
+ 13,
3082
+ 22,
3083
+ 18,
3084
+ 26,
3085
+ 18,
3086
+ 24,
3087
+ 18,
3088
+ 22,
3089
+ 20,
3090
+ 24,
3091
+ 28,
3092
+ 26,
3093
+ 24,
3094
+ 20,
3095
+ 30,
3096
+ 24,
3097
+ 28,
3098
+ 28,
3099
+ 26,
3100
+ 30,
3101
+ 28,
3102
+ 30,
3103
+ 30,
3104
+ 30,
3105
+ 30,
3106
+ 28,
3107
+ 30,
3108
+ 30,
3109
+ 30,
3110
+ 30,
3111
+ 30,
3112
+ 30,
3113
+ 30,
3114
+ 30,
3115
+ 30,
3116
+ 30,
3117
+ 30,
3118
+ 30,
3119
+ 30,
3120
+ 30
3121
+ ],
3122
+ [
3123
+ -1,
3124
+ 17,
3125
+ 28,
3126
+ 22,
3127
+ 16,
3128
+ 22,
3129
+ 28,
3130
+ 26,
3131
+ 26,
3132
+ 24,
3133
+ 28,
3134
+ 24,
3135
+ 28,
3136
+ 22,
3137
+ 24,
3138
+ 24,
3139
+ 30,
3140
+ 28,
3141
+ 28,
3142
+ 26,
3143
+ 28,
3144
+ 30,
3145
+ 24,
3146
+ 30,
3147
+ 30,
3148
+ 30,
3149
+ 30,
3150
+ 30,
3151
+ 30,
3152
+ 30,
3153
+ 30,
3154
+ 30,
3155
+ 30,
3156
+ 30,
3157
+ 30,
3158
+ 30,
3159
+ 30,
3160
+ 30,
3161
+ 30,
3162
+ 30,
3163
+ 30
3164
+ ]
3165
+ ];
3166
+ const NUM_ERROR_CORRECTION_BLOCKS = [
3167
+ [
3168
+ -1,
3169
+ 1,
3170
+ 1,
3171
+ 1,
3172
+ 1,
3173
+ 1,
3174
+ 2,
3175
+ 2,
3176
+ 2,
3177
+ 2,
3178
+ 4,
3179
+ 4,
3180
+ 4,
3181
+ 4,
3182
+ 4,
3183
+ 6,
3184
+ 6,
3185
+ 6,
3186
+ 6,
3187
+ 7,
3188
+ 8,
3189
+ 8,
3190
+ 9,
3191
+ 9,
3192
+ 10,
3193
+ 12,
3194
+ 12,
3195
+ 12,
3196
+ 13,
3197
+ 14,
3198
+ 15,
3199
+ 16,
3200
+ 17,
3201
+ 18,
3202
+ 19,
3203
+ 19,
3204
+ 20,
3205
+ 21,
3206
+ 22,
3207
+ 24,
3208
+ 25
3209
+ ],
3210
+ [
3211
+ -1,
3212
+ 1,
3213
+ 1,
3214
+ 1,
3215
+ 2,
3216
+ 2,
3217
+ 4,
3218
+ 4,
3219
+ 4,
3220
+ 5,
3221
+ 5,
3222
+ 5,
3223
+ 8,
3224
+ 9,
3225
+ 9,
3226
+ 10,
3227
+ 10,
3228
+ 11,
3229
+ 13,
3230
+ 14,
3231
+ 16,
3232
+ 17,
3233
+ 17,
3234
+ 18,
3235
+ 20,
3236
+ 21,
3237
+ 23,
3238
+ 25,
3239
+ 26,
3240
+ 28,
3241
+ 29,
3242
+ 31,
3243
+ 33,
3244
+ 35,
3245
+ 37,
3246
+ 38,
3247
+ 40,
3248
+ 43,
3249
+ 45,
3250
+ 47,
3251
+ 49
3252
+ ],
3253
+ [
3254
+ -1,
3255
+ 1,
3256
+ 1,
3257
+ 2,
3258
+ 2,
3259
+ 4,
3260
+ 4,
3261
+ 6,
3262
+ 6,
3263
+ 8,
3264
+ 8,
3265
+ 8,
3266
+ 10,
3267
+ 12,
3268
+ 16,
3269
+ 12,
3270
+ 17,
3271
+ 16,
3272
+ 18,
3273
+ 21,
3274
+ 20,
3275
+ 23,
3276
+ 23,
3277
+ 25,
3278
+ 27,
3279
+ 29,
3280
+ 34,
3281
+ 34,
3282
+ 35,
3283
+ 38,
3284
+ 40,
3285
+ 43,
3286
+ 45,
3287
+ 48,
3288
+ 51,
3289
+ 53,
3290
+ 56,
3291
+ 59,
3292
+ 62,
3293
+ 65,
3294
+ 68
3295
+ ],
3296
+ [
3297
+ -1,
3298
+ 1,
3299
+ 1,
3300
+ 2,
3301
+ 4,
3302
+ 4,
3303
+ 4,
3304
+ 5,
3305
+ 6,
3306
+ 8,
3307
+ 8,
3308
+ 11,
3309
+ 11,
3310
+ 16,
3311
+ 16,
3312
+ 18,
3313
+ 16,
3314
+ 19,
3315
+ 21,
3316
+ 25,
3317
+ 25,
3318
+ 25,
3319
+ 34,
3320
+ 30,
3321
+ 32,
3322
+ 35,
3323
+ 37,
3324
+ 40,
3325
+ 42,
3326
+ 45,
3327
+ 48,
3328
+ 51,
3329
+ 54,
3330
+ 57,
3331
+ 60,
3332
+ 63,
3333
+ 66,
3334
+ 70,
3335
+ 74,
3336
+ 77,
3337
+ 81
3338
+ ]
3339
+ ];
3340
+ var QrCode = class {
3341
+ constructor(version, ecc, dataCodewords, msk) {
3342
+ this.version = version;
3343
+ this.ecc = ecc;
3344
+ if (version < MIN_VERSION || version > MAX_VERSION) throw new RangeError("Version value out of range");
3345
+ if (msk < -1 || msk > 7) throw new RangeError("Mask value out of range");
3346
+ this.size = version * 4 + 17;
3347
+ const row = Array.from({ length: this.size }).fill(false);
3348
+ for (let i = 0; i < this.size; i++) {
3349
+ this.modules.push(row.slice());
3350
+ this.types.push(row.map(() => 0));
3351
+ }
3352
+ this.drawFunctionPatterns();
3353
+ const allCodewords = this.addEccAndInterleave(dataCodewords);
3354
+ this.drawCodewords(allCodewords);
3355
+ if (msk === -1) {
3356
+ let minPenalty = 1e9;
3357
+ for (let i = 0; i < 8; i++) {
3358
+ this.applyMask(i);
3359
+ this.drawFormatBits(i);
3360
+ const penalty = this.getPenaltyScore();
3361
+ if (penalty < minPenalty) {
3362
+ msk = i;
3363
+ minPenalty = penalty;
3364
+ }
3365
+ this.applyMask(i);
3366
+ }
3367
+ }
3368
+ this.mask = msk;
3369
+ this.applyMask(msk);
3370
+ this.drawFormatBits(msk);
3371
+ }
3372
+ size;
3373
+ mask;
3374
+ modules = [];
3375
+ types = [];
3376
+ getModule(x, y) {
3377
+ return x >= 0 && x < this.size && y >= 0 && y < this.size && this.modules[y][x];
3378
+ }
3379
+ drawFunctionPatterns() {
3380
+ for (let i = 0; i < this.size; i++) {
3381
+ this.setFunctionModule(6, i, i % 2 === 0, QrCodeDataType.Timing);
3382
+ this.setFunctionModule(i, 6, i % 2 === 0, QrCodeDataType.Timing);
3383
+ }
3384
+ this.drawFinderPattern(3, 3);
3385
+ this.drawFinderPattern(this.size - 4, 3);
3386
+ this.drawFinderPattern(3, this.size - 4);
3387
+ const alignPatPos = this.getAlignmentPatternPositions();
3388
+ const numAlign = alignPatPos.length;
3389
+ for (let i = 0; i < numAlign; i++) for (let j = 0; j < numAlign; j++) if (!(i === 0 && j === 0 || i === 0 && j === numAlign - 1 || i === numAlign - 1 && j === 0)) this.drawAlignmentPattern(alignPatPos[i], alignPatPos[j]);
3390
+ this.drawFormatBits(0);
3391
+ this.drawVersion();
3392
+ }
3393
+ drawFormatBits(mask) {
3394
+ const data = this.ecc[1] << 3 | mask;
3395
+ let rem = data;
3396
+ for (let i = 0; i < 10; i++) rem = rem << 1 ^ (rem >>> 9) * 1335;
3397
+ const bits = (data << 10 | rem) ^ 21522;
3398
+ for (let i = 0; i <= 5; i++) this.setFunctionModule(8, i, getBit(bits, i));
3399
+ this.setFunctionModule(8, 7, getBit(bits, 6));
3400
+ this.setFunctionModule(8, 8, getBit(bits, 7));
3401
+ this.setFunctionModule(7, 8, getBit(bits, 8));
3402
+ for (let i = 9; i < 15; i++) this.setFunctionModule(14 - i, 8, getBit(bits, i));
3403
+ for (let i = 0; i < 8; i++) this.setFunctionModule(this.size - 1 - i, 8, getBit(bits, i));
3404
+ for (let i = 8; i < 15; i++) this.setFunctionModule(8, this.size - 15 + i, getBit(bits, i));
3405
+ this.setFunctionModule(8, this.size - 8, true);
3406
+ }
3407
+ drawVersion() {
3408
+ if (this.version < 7) return;
3409
+ let rem = this.version;
3410
+ for (let i = 0; i < 12; i++) rem = rem << 1 ^ (rem >>> 11) * 7973;
3411
+ const bits = this.version << 12 | rem;
3412
+ for (let i = 0; i < 18; i++) {
3413
+ const color = getBit(bits, i);
3414
+ const a = this.size - 11 + i % 3;
3415
+ const b = Math.floor(i / 3);
3416
+ this.setFunctionModule(a, b, color);
3417
+ this.setFunctionModule(b, a, color);
3418
+ }
3419
+ }
3420
+ drawFinderPattern(x, y) {
3421
+ for (let dy = -4; dy <= 4; dy++) for (let dx = -4; dx <= 4; dx++) {
3422
+ const dist = Math.max(Math.abs(dx), Math.abs(dy));
3423
+ const xx = x + dx;
3424
+ const yy = y + dy;
3425
+ if (xx >= 0 && xx < this.size && yy >= 0 && yy < this.size) this.setFunctionModule(xx, yy, dist !== 2 && dist !== 4, QrCodeDataType.Position);
3426
+ }
3427
+ }
3428
+ drawAlignmentPattern(x, y) {
3429
+ for (let dy = -2; dy <= 2; dy++) for (let dx = -2; dx <= 2; dx++) this.setFunctionModule(x + dx, y + dy, Math.max(Math.abs(dx), Math.abs(dy)) !== 1, QrCodeDataType.Alignment);
3430
+ }
3431
+ setFunctionModule(x, y, isDark, type = QrCodeDataType.Function) {
3432
+ this.modules[y][x] = isDark;
3433
+ this.types[y][x] = type;
3434
+ }
3435
+ addEccAndInterleave(data) {
3436
+ const ver = this.version;
3437
+ const ecl = this.ecc;
3438
+ if (data.length !== getNumDataCodewords(ver, ecl)) throw new RangeError("Invalid argument");
3439
+ const numBlocks = NUM_ERROR_CORRECTION_BLOCKS[ecl[0]][ver];
3440
+ const blockEccLen = ECC_CODEWORDS_PER_BLOCK[ecl[0]][ver];
3441
+ const rawCodewords = Math.floor(getNumRawDataModules(ver) / 8);
3442
+ const numShortBlocks = numBlocks - rawCodewords % numBlocks;
3443
+ const shortBlockLen = Math.floor(rawCodewords / numBlocks);
3444
+ const blocks = [];
3445
+ const rsDiv = reedSolomonComputeDivisor(blockEccLen);
3446
+ for (let i = 0, k = 0; i < numBlocks; i++) {
3447
+ const dat = data.slice(k, k + shortBlockLen - blockEccLen + (i < numShortBlocks ? 0 : 1));
3448
+ k += dat.length;
3449
+ const ecc = reedSolomonComputeRemainder(dat, rsDiv);
3450
+ if (i < numShortBlocks) dat.push(0);
3451
+ blocks.push(dat.concat(ecc));
3452
+ }
3453
+ const result = [];
3454
+ for (let i = 0; i < blocks[0].length; i++) blocks.forEach((block, j) => {
3455
+ if (i !== shortBlockLen - blockEccLen || j >= numShortBlocks) result.push(block[i]);
3456
+ });
3457
+ return result;
3458
+ }
3459
+ drawCodewords(data) {
3460
+ if (data.length !== Math.floor(getNumRawDataModules(this.version) / 8)) throw new RangeError("Invalid argument");
3461
+ let i = 0;
3462
+ for (let right = this.size - 1; right >= 1; right -= 2) {
3463
+ if (right === 6) right = 5;
3464
+ for (let vert = 0; vert < this.size; vert++) for (let j = 0; j < 2; j++) {
3465
+ const x = right - j;
3466
+ const y = (right + 1 & 2) === 0 ? this.size - 1 - vert : vert;
3467
+ if (!this.types[y][x] && i < data.length * 8) {
3468
+ this.modules[y][x] = getBit(data[i >>> 3], 7 - (i & 7));
3469
+ i++;
3470
+ }
3471
+ }
3472
+ }
3473
+ }
3474
+ applyMask(mask) {
3475
+ if (mask < 0 || mask > 7) throw new RangeError("Mask value out of range");
3476
+ for (let y = 0; y < this.size; y++) for (let x = 0; x < this.size; x++) {
3477
+ let invert;
3478
+ switch (mask) {
3479
+ case 0:
3480
+ invert = (x + y) % 2 === 0;
3481
+ break;
3482
+ case 1:
3483
+ invert = y % 2 === 0;
3484
+ break;
3485
+ case 2:
3486
+ invert = x % 3 === 0;
3487
+ break;
3488
+ case 3:
3489
+ invert = (x + y) % 3 === 0;
3490
+ break;
3491
+ case 4:
3492
+ invert = (Math.floor(x / 3) + Math.floor(y / 2)) % 2 === 0;
3493
+ break;
3494
+ case 5:
3495
+ invert = x * y % 2 + x * y % 3 === 0;
3496
+ break;
3497
+ case 6:
3498
+ invert = (x * y % 2 + x * y % 3) % 2 === 0;
3499
+ break;
3500
+ case 7:
3501
+ invert = ((x + y) % 2 + x * y % 3) % 2 === 0;
3502
+ break;
3503
+ default: throw new Error("Unreachable");
3504
+ }
3505
+ if (!this.types[y][x] && invert) this.modules[y][x] = !this.modules[y][x];
3506
+ }
3507
+ }
3508
+ getPenaltyScore() {
3509
+ let result = 0;
3510
+ for (let y = 0; y < this.size; y++) {
3511
+ let runColor = false;
3512
+ let runX = 0;
3513
+ const runHistory = [
3514
+ 0,
3515
+ 0,
3516
+ 0,
3517
+ 0,
3518
+ 0,
3519
+ 0,
3520
+ 0
3521
+ ];
3522
+ for (let x = 0; x < this.size; x++) if (this.modules[y][x] === runColor) {
3523
+ runX++;
3524
+ if (runX === 5) result += PENALTY_N1;
3525
+ else if (runX > 5) result++;
3526
+ } else {
3527
+ this.finderPenaltyAddHistory(runX, runHistory);
3528
+ if (!runColor) result += this.finderPenaltyCountPatterns(runHistory) * PENALTY_N3;
3529
+ runColor = this.modules[y][x];
3530
+ runX = 1;
3531
+ }
3532
+ result += this.finderPenaltyTerminateAndCount(runColor, runX, runHistory) * PENALTY_N3;
3533
+ }
3534
+ for (let x = 0; x < this.size; x++) {
3535
+ let runColor = false;
3536
+ let runY = 0;
3537
+ const runHistory = [
3538
+ 0,
3539
+ 0,
3540
+ 0,
3541
+ 0,
3542
+ 0,
3543
+ 0,
3544
+ 0
3545
+ ];
3546
+ for (let y = 0; y < this.size; y++) if (this.modules[y][x] === runColor) {
3547
+ runY++;
3548
+ if (runY === 5) result += PENALTY_N1;
3549
+ else if (runY > 5) result++;
3550
+ } else {
3551
+ this.finderPenaltyAddHistory(runY, runHistory);
3552
+ if (!runColor) result += this.finderPenaltyCountPatterns(runHistory) * PENALTY_N3;
3553
+ runColor = this.modules[y][x];
3554
+ runY = 1;
3555
+ }
3556
+ result += this.finderPenaltyTerminateAndCount(runColor, runY, runHistory) * PENALTY_N3;
3557
+ }
3558
+ for (let y = 0; y < this.size - 1; y++) for (let x = 0; x < this.size - 1; x++) {
3559
+ const color = this.modules[y][x];
3560
+ if (color === this.modules[y][x + 1] && color === this.modules[y + 1][x] && color === this.modules[y + 1][x + 1]) result += PENALTY_N2;
3561
+ }
3562
+ let dark = 0;
3563
+ for (const row of this.modules) dark = row.reduce((sum, color) => sum + (color ? 1 : 0), dark);
3564
+ const total = this.size * this.size;
3565
+ const k = Math.ceil(Math.abs(dark * 20 - total * 10) / total) - 1;
3566
+ result += k * PENALTY_N4;
3567
+ return result;
3568
+ }
3569
+ getAlignmentPatternPositions() {
3570
+ if (this.version === 1) return [];
3571
+ else {
3572
+ const numAlign = Math.floor(this.version / 7) + 2;
3573
+ const step = this.version === 32 ? 26 : Math.ceil((this.version * 4 + 4) / (numAlign * 2 - 2)) * 2;
3574
+ const result = [6];
3575
+ for (let pos = this.size - 7; result.length < numAlign; pos -= step) result.splice(1, 0, pos);
3576
+ return result;
3577
+ }
3578
+ }
3579
+ finderPenaltyCountPatterns(runHistory) {
3580
+ const n = runHistory[1];
3581
+ const core = n > 0 && runHistory[2] === n && runHistory[3] === n * 3 && runHistory[4] === n && runHistory[5] === n;
3582
+ return (core && runHistory[0] >= n * 4 && runHistory[6] >= n ? 1 : 0) + (core && runHistory[6] >= n * 4 && runHistory[0] >= n ? 1 : 0);
3583
+ }
3584
+ finderPenaltyTerminateAndCount(currentRunColor, currentRunLength, runHistory) {
3585
+ if (currentRunColor) {
3586
+ this.finderPenaltyAddHistory(currentRunLength, runHistory);
3587
+ currentRunLength = 0;
3588
+ }
3589
+ currentRunLength += this.size;
3590
+ this.finderPenaltyAddHistory(currentRunLength, runHistory);
3591
+ return this.finderPenaltyCountPatterns(runHistory);
3592
+ }
3593
+ finderPenaltyAddHistory(currentRunLength, runHistory) {
3594
+ if (runHistory[0] === 0) currentRunLength += this.size;
3595
+ runHistory.pop();
3596
+ runHistory.unshift(currentRunLength);
3597
+ }
3598
+ };
3599
+ function appendBits(val, len, bb) {
3600
+ if (len < 0 || len > 31 || val >>> len !== 0) throw new RangeError("Value out of range");
3601
+ for (let i = len - 1; i >= 0; i--) bb.push(val >>> i & 1);
3602
+ }
3603
+ function getBit(x, i) {
3604
+ return (x >>> i & 1) !== 0;
3605
+ }
3606
+ var QrSegment = class {
3607
+ constructor(mode, numChars, bitData) {
3608
+ this.mode = mode;
3609
+ this.numChars = numChars;
3610
+ this.bitData = bitData;
3611
+ if (numChars < 0) throw new RangeError("Invalid argument");
3612
+ this.bitData = bitData.slice();
3613
+ }
3614
+ getData() {
3615
+ return this.bitData.slice();
3616
+ }
3617
+ };
3618
+ const MODE_NUMERIC = [
3619
+ 1,
3620
+ 10,
3621
+ 12,
3622
+ 14
3623
+ ];
3624
+ const MODE_ALPHANUMERIC = [
3625
+ 2,
3626
+ 9,
3627
+ 11,
3628
+ 13
3629
+ ];
3630
+ const MODE_BYTE = [
3631
+ 4,
3632
+ 8,
3633
+ 16,
3634
+ 16
3635
+ ];
3636
+ function numCharCountBits(mode, ver) {
3637
+ return mode[Math.floor((ver + 7) / 17) + 1];
3638
+ }
3639
+ function makeBytes(data) {
3640
+ const bb = [];
3641
+ for (const b of data) appendBits(b, 8, bb);
3642
+ return new QrSegment(MODE_BYTE, data.length, bb);
3643
+ }
3644
+ function makeNumeric(digits) {
3645
+ if (!isNumeric(digits)) throw new RangeError("String contains non-numeric characters");
3646
+ const bb = [];
3647
+ for (let i = 0; i < digits.length;) {
3648
+ const n = Math.min(digits.length - i, 3);
3649
+ appendBits(Number.parseInt(digits.substring(i, i + n), 10), n * 3 + 1, bb);
3650
+ i += n;
3651
+ }
3652
+ return new QrSegment(MODE_NUMERIC, digits.length, bb);
3653
+ }
3654
+ function makeAlphanumeric(text) {
3655
+ if (!isAlphanumeric(text)) throw new RangeError("String contains unencodable characters in alphanumeric mode");
3656
+ const bb = [];
3657
+ let i = 0;
3658
+ for (; i + 2 <= text.length; i += 2) {
3659
+ let temp = ALPHANUMERIC_CHARSET.indexOf(text.charAt(i)) * 45;
3660
+ temp += ALPHANUMERIC_CHARSET.indexOf(text.charAt(i + 1));
3661
+ appendBits(temp, 11, bb);
3662
+ }
3663
+ if (i < text.length) appendBits(ALPHANUMERIC_CHARSET.indexOf(text.charAt(i)), 6, bb);
3664
+ return new QrSegment(MODE_ALPHANUMERIC, text.length, bb);
3665
+ }
3666
+ function makeSegments(text) {
3667
+ if (text === "") return [];
3668
+ else if (isNumeric(text)) return [makeNumeric(text)];
3669
+ else if (isAlphanumeric(text)) return [makeAlphanumeric(text)];
3670
+ else return [makeBytes(toUtf8ByteArray(text))];
3671
+ }
3672
+ function isNumeric(text) {
3673
+ return NUMERIC_REGEX.test(text);
3674
+ }
3675
+ function isAlphanumeric(text) {
3676
+ return ALPHANUMERIC_REGEX.test(text);
3677
+ }
3678
+ function getTotalBits(segs, version) {
3679
+ let result = 0;
3680
+ for (const seg of segs) {
3681
+ const ccbits = numCharCountBits(seg.mode, version);
3682
+ if (seg.numChars >= 1 << ccbits) return Number.POSITIVE_INFINITY;
3683
+ result += 4 + ccbits + seg.bitData.length;
3684
+ }
3685
+ return result;
3686
+ }
3687
+ function toUtf8ByteArray(str) {
3688
+ str = encodeURI(str);
3689
+ const result = [];
3690
+ for (let i = 0; i < str.length; i++) if (str.charAt(i) !== "%") result.push(str.charCodeAt(i));
3691
+ else {
3692
+ result.push(Number.parseInt(str.substring(i + 1, i + 3), 16));
3693
+ i += 2;
3694
+ }
3695
+ return result;
3696
+ }
3697
+ function getNumRawDataModules(ver) {
3698
+ if (ver < MIN_VERSION || ver > MAX_VERSION) throw new RangeError("Version number out of range");
3699
+ let result = (16 * ver + 128) * ver + 64;
3700
+ if (ver >= 2) {
3701
+ const numAlign = Math.floor(ver / 7) + 2;
3702
+ result -= (25 * numAlign - 10) * numAlign - 55;
3703
+ if (ver >= 7) result -= 36;
3704
+ }
3705
+ return result;
3706
+ }
3707
+ function getNumDataCodewords(ver, ecl) {
3708
+ return Math.floor(getNumRawDataModules(ver) / 8) - ECC_CODEWORDS_PER_BLOCK[ecl[0]][ver] * NUM_ERROR_CORRECTION_BLOCKS[ecl[0]][ver];
3709
+ }
3710
+ function reedSolomonComputeDivisor(degree) {
3711
+ if (degree < 1 || degree > 255) throw new RangeError("Degree out of range");
3712
+ const result = [];
3713
+ for (let i = 0; i < degree - 1; i++) result.push(0);
3714
+ result.push(1);
3715
+ let root = 1;
3716
+ for (let i = 0; i < degree; i++) {
3717
+ for (let j = 0; j < result.length; j++) {
3718
+ result[j] = reedSolomonMultiply(result[j], root);
3719
+ if (j + 1 < result.length) result[j] ^= result[j + 1];
3720
+ }
3721
+ root = reedSolomonMultiply(root, 2);
3722
+ }
3723
+ return result;
3724
+ }
3725
+ function reedSolomonComputeRemainder(data, divisor) {
3726
+ const result = divisor.map((_) => 0);
3727
+ for (const b of data) {
3728
+ const factor = b ^ result.shift();
3729
+ result.push(0);
3730
+ divisor.forEach((coef, i) => result[i] ^= reedSolomonMultiply(coef, factor));
3731
+ }
3732
+ return result;
3733
+ }
3734
+ function reedSolomonMultiply(x, y) {
3735
+ if (x >>> 8 !== 0 || y >>> 8 !== 0) throw new RangeError("Byte out of range");
3736
+ let z = 0;
3737
+ for (let i = 7; i >= 0; i--) {
3738
+ z = z << 1 ^ (z >>> 7) * 285;
3739
+ z ^= (y >>> i & 1) * x;
3740
+ }
3741
+ return z;
3742
+ }
3743
+ function encodeSegments(segs, ecl, minVersion = 1, maxVersion = 40, mask = -1, boostEcl = true) {
3744
+ if (!(MIN_VERSION <= minVersion && minVersion <= maxVersion && maxVersion <= MAX_VERSION) || mask < -1 || mask > 7) throw new RangeError("Invalid value");
3745
+ let version;
3746
+ let dataUsedBits;
3747
+ for (version = minVersion;; version++) {
3748
+ const dataCapacityBits2 = getNumDataCodewords(version, ecl) * 8;
3749
+ const usedBits = getTotalBits(segs, version);
3750
+ if (usedBits <= dataCapacityBits2) {
3751
+ dataUsedBits = usedBits;
3752
+ break;
3753
+ }
3754
+ if (version >= maxVersion) throw new RangeError("Data too long");
3755
+ }
3756
+ for (const newEcl of [
3757
+ MEDIUM,
3758
+ QUARTILE,
3759
+ HIGH
3760
+ ]) if (boostEcl && dataUsedBits <= getNumDataCodewords(version, newEcl) * 8) ecl = newEcl;
3761
+ const bb = [];
3762
+ for (const seg of segs) {
3763
+ appendBits(seg.mode[0], 4, bb);
3764
+ appendBits(seg.numChars, numCharCountBits(seg.mode, version), bb);
3765
+ for (const b of seg.getData()) bb.push(b);
3766
+ }
3767
+ const dataCapacityBits = getNumDataCodewords(version, ecl) * 8;
3768
+ appendBits(0, Math.min(4, dataCapacityBits - bb.length), bb);
3769
+ appendBits(0, (8 - bb.length % 8) % 8, bb);
3770
+ for (let padByte = 236; bb.length < dataCapacityBits; padByte ^= 253) appendBits(padByte, 8, bb);
3771
+ const dataCodewords = Array.from({ length: Math.ceil(bb.length / 8) }, () => 0);
3772
+ bb.forEach((b, i) => dataCodewords[i >>> 3] |= b << 7 - (i & 7));
3773
+ return new QrCode(version, ecl, dataCodewords, mask);
3774
+ }
3775
+ function encode(data, options) {
3776
+ const { ecc = "L", boostEcc = false, minVersion = 1, maxVersion = 40, maskPattern = -1, border = 1 } = options || {};
3777
+ const segment = typeof data === "string" ? makeSegments(data) : Array.isArray(data) ? [makeBytes(data)] : void 0;
3778
+ if (!segment) throw new Error(`uqr only supports encoding string and binary data, but got: ${typeof data}`);
3779
+ const qr = encodeSegments(segment, EccMap[ecc], minVersion, maxVersion, maskPattern, boostEcc);
3780
+ const result = addBorder({
3781
+ version: qr.version,
3782
+ maskPattern: qr.mask,
3783
+ size: qr.size,
3784
+ data: qr.modules,
3785
+ types: qr.types
3786
+ }, border);
3787
+ if (options?.invert) result.data = result.data.map((row) => row.map((mod) => !mod));
3788
+ options?.onEncoded?.(result);
3789
+ return result;
3790
+ }
3791
+ function addBorder(input, border = 1) {
3792
+ if (!border) return input;
3793
+ const { size } = input;
3794
+ const newSize = size + border * 2;
3795
+ input.size = newSize;
3796
+ input.data.forEach((row) => {
3797
+ for (let i = 0; i < border; i++) {
3798
+ row.unshift(false);
3799
+ row.push(false);
3800
+ }
3801
+ });
3802
+ for (let i = 0; i < border; i++) {
3803
+ input.data.unshift(Array.from({ length: newSize }, (_) => false));
3804
+ input.data.push(Array.from({ length: newSize }, (_) => false));
3805
+ }
3806
+ const b = QrCodeDataType.Border;
3807
+ input.types.forEach((row) => {
3808
+ for (let i = 0; i < border; i++) {
3809
+ row.unshift(b);
3810
+ row.push(b);
3811
+ }
3812
+ });
3813
+ for (let i = 0; i < border; i++) {
3814
+ input.types.unshift(Array.from({ length: newSize }, (_) => b));
3815
+ input.types.push(Array.from({ length: newSize }, (_) => b));
3816
+ }
3817
+ return input;
3818
+ }
3819
+ function getDataAt(data, x, y, defaults = false) {
3820
+ if (x < 0 || y < 0 || x >= data.length || y >= data.length) return defaults;
3821
+ return data[y][x];
3822
+ }
3823
+ function renderUnicodeCompact(data, options = {}) {
3824
+ const palette = {
3825
+ WHITE_ALL: "█",
3826
+ WHITE_BLACK: "▀",
3827
+ BLACK_WHITE: "▄",
3828
+ BLACK_ALL: " "
3829
+ };
3830
+ const result = encode(data, options);
3831
+ const WHITE = false;
3832
+ const BLACK = true;
3833
+ const at = (x, y) => getDataAt(result.data, x, y, true);
3834
+ const lines = [];
3835
+ let line = "";
3836
+ for (let row = 0; row < result.size; row += 2) {
3837
+ for (let col = 0; col < result.size; col++) if (at(col, row) === WHITE && at(col, row + 1) === WHITE) line += palette.WHITE_ALL;
3838
+ else if (at(col, row) === WHITE && at(col, row + 1) === BLACK) line += palette.WHITE_BLACK;
3839
+ else if (at(col, row) === BLACK && at(col, row + 1) === WHITE) line += palette.BLACK_WHITE;
3840
+ else line += palette.BLACK_ALL;
3841
+ lines.push(line);
3842
+ line = "";
3843
+ }
3844
+ return lines.join("\n");
3845
+ }
3846
+ // src/doctor/doctor.ts
2970
3847
  async function inspectStateFile(stateRoot, name) {
2971
3848
  let bytes;
2972
3849
  try {
@@ -3172,8 +4049,7 @@ async function runDoctor(options) {
3172
4049
  warnings
3173
4050
  };
3174
4051
  }
3175
- //#endregion
3176
- //#region src/cli/argv.ts
4052
+ // src/cli/argv.ts
3177
4053
  function normalizeArgv(argv, stdinIsPiped, rules) {
3178
4054
  let firstPositional;
3179
4055
  for (let index = 0; index < argv.length; index += 1) {
@@ -3196,8 +4072,7 @@ function normalizeArgv(argv, stdinIsPiped, rules) {
3196
4072
  if (stdinIsPiped && !asksForInfo) return ["open", ...argv];
3197
4073
  return argv;
3198
4074
  }
3199
- //#endregion
3200
- //#region src/cli/browser.ts
4075
+ // src/cli/browser.ts
3201
4076
  const LAUNCH_WAIT_MS = 3e3;
3202
4077
  function launchCommand(env, platform, url) {
3203
4078
  const override = env["BROWSER"];
@@ -3386,8 +4261,7 @@ function connectIpc(options) {
3386
4261
  });
3387
4262
  });
3388
4263
  }
3389
- //#endregion
3390
- //#region src/cli/daemon-control.ts
4264
+ // src/cli/daemon-control.ts
3391
4265
  const START_TIMEOUT_MS = 1e4;
3392
4266
  const STOP_TIMEOUT_MS = 1e4;
3393
4267
  const POLL_INTERVAL_MS = 50;
@@ -3564,8 +4438,7 @@ function createDaemonControl(environment) {
3564
4438
  stoppedStatus
3565
4439
  };
3566
4440
  }
3567
- //#endregion
3568
- //#region src/cli/mobile-setup.ts
4441
+ // src/cli/mobile-setup.ts
3569
4442
  const TAILSCALE_TIMEOUT_MS = 15e3;
3570
4443
  const MAC_APP_CLI = "/Applications/Tailscale.app/Contents/MacOS/Tailscale";
3571
4444
  function execute(command, args, env) {
@@ -3805,22 +4678,24 @@ async function mobileStatus(context) {
3805
4678
  uiPort: mobile.uiPort ?? DEFAULT_PORTS.mobileUi,
3806
4679
  previewPort: mobile.previewPort ?? DEFAULT_PORTS.mobilePreview
3807
4680
  } : null;
3808
- let serve = null;
3809
- if (configured) {
3810
- const status = await serveStatus(context.tailscale).catch(() => null);
3811
- if (status) serve = {
3812
- [String(configured.uiPort)]: forwardState(status, configured.host, configured.uiPort),
3813
- [String(configured.previewPort)]: forwardState(status, configured.host, configured.previewPort)
3814
- };
3815
- }
4681
+ const daemon = (await context.daemonStatus()).mobile;
4682
+ const status = configured || daemon?.state === "ready" ? await serveStatus(context.tailscale).catch(() => null) : null;
3816
4683
  return {
3817
4684
  configured,
3818
- daemon: (await context.daemonStatus()).mobile,
3819
- serve
4685
+ daemon,
4686
+ serve: configured && status ? {
4687
+ [String(configured.uiPort)]: forwardState(status, configured.host, configured.uiPort),
4688
+ [String(configured.previewPort)]: forwardState(status, configured.host, configured.previewPort)
4689
+ } : null,
4690
+ openableUrl: openableUrl(daemon, status)
3820
4691
  };
3821
4692
  }
3822
- //#endregion
3823
- //#region src/cli/output.ts
4693
+ function openableUrl(daemon, serve) {
4694
+ if (daemon?.state !== "ready" || serve === null) return null;
4695
+ const { hostname, port } = new URL(daemon.uiUrl);
4696
+ return [Number(port), daemon.previewPort].every((each) => forwardState(serve, hostname, each) === "ours") ? daemon.uiUrl : null;
4697
+ }
4698
+ // src/cli/output.ts
3824
4699
  function codeUnitEscape(character) {
3825
4700
  return `\\u${character.charCodeAt(0).toString(16).padStart(4, "0")}`;
3826
4701
  }
@@ -3833,8 +4708,7 @@ function escapeForTerminal(text) {
3833
4708
  function escapeContentForTerminal(text) {
3834
4709
  return text.replace(/[\u0000-\u0008\u000b-\u001f\u007f-\u009f]/g, codeUnitEscape);
3835
4710
  }
3836
- //#endregion
3837
- //#region src/cli/wait-for-answer.ts
4711
+ // src/cli/wait-for-answer.ts
3838
4712
  const RECONNECTABLE = /* @__PURE__ */ new Set([
3839
4713
  "E_DAEMON_STOPPING",
3840
4714
  "E_DAEMON_UNAVAILABLE",
@@ -3903,8 +4777,7 @@ async function waitForAnswer(options) {
3903
4777
  abandon.abort(new VdeError("E_INTERRUPTED", "The wait has ended."));
3904
4778
  }
3905
4779
  }
3906
- //#endregion
3907
- //#region src/cli/run.ts
4780
+ // src/cli/run.ts
3908
4781
  const CLI_VERSION = version;
3909
4782
  const PROGRAM_NAME = "vde-open";
3910
4783
  function toErrorBody(error) {
@@ -4348,6 +5221,7 @@ async function runCli(rawArgv, context) {
4348
5221
  await control.stop();
4349
5222
  return (await viaDaemon("daemon.status", {})).data;
4350
5223
  };
5224
+ const phoneQrOf = (url) => url !== null && context.stdoutIsTty ? renderUnicodeCompact(url, { border: 2 }).split("\n").map((line) => `\u001b[97;40m${line}\u001b[0m`) : [];
4351
5225
  const renderServe = (serve) => Object.entries(serve).map(([port, state]) => `${port} ${state}`).join(", ");
4352
5226
  mobile.command("enable").description("Read this machine's Tailscale name and your login into listeners.json, restart the daemon, and add the two Tailscale Serve forwards").option("--no-serve", "Do not change Tailscale Serve (add the forwards yourself)").option("--json", "Output the result as JSON", false).action(async (options) => {
4353
5227
  await execute("mobile.enable", options.json, async () => ({ data: await enableMobile({
@@ -4358,7 +5232,8 @@ async function runCli(rawArgv, context) {
4358
5232
  `phone reader: ${data.uiUrl}`,
4359
5233
  `login: ${escapeForTerminal(data.login)}`,
4360
5234
  `serve: ${renderServe(data.serve)}`,
4361
- options.serve ? "Open the URL on your phone (signed in to the same tailnet) and bookmark it." : `Add the forwards: tailscale serve --bg --https=<port> http://127.0.0.1:<port> (for ${Object.keys(data.serve).join(" and ")})`
5235
+ options.serve ? "Open the URL on your phone (signed in to the same tailnet) and bookmark it." : `Add the forwards: tailscale serve --bg --https=<port> http://127.0.0.1:<port> (for ${Object.keys(data.serve).join(" and ")})`,
5236
+ ...phoneQrOf(options.serve ? data.uiUrl : null)
4362
5237
  ].join("\n"));
4363
5238
  });
4364
5239
  mobile.command("disable").description("Remove the phone reader settings and only its own Tailscale Serve forwards, then restart the daemon").option("--no-serve", "Do not change Tailscale Serve").option("--json", "Output the result as JSON", false).action(async (options) => {
@@ -4389,7 +5264,8 @@ async function runCli(rawArgv, context) {
4389
5264
  }) }), (data) => [
4390
5265
  data.configured === null ? "settings: none (vo mobile enable)" : `settings: https://${data.configured.host}:${String(data.configured.uiPort)}/ login: ${escapeForTerminal(data.configured.login)}`,
4391
5266
  `daemon: ${data.daemon === null ? "stopped" : data.daemon.state === "error" ? `error (${escapeForTerminal(data.daemon.reason)})` : data.daemon.state === "ready" ? `ready ${data.daemon.uiUrl}` : data.daemon.state}`,
4392
- ...data.configured === null ? [] : [`serve: ${data.serve === null ? "unknown (tailscale not available)" : renderServe(data.serve)}`]
5267
+ ...data.configured === null ? [] : [`serve: ${data.serve === null ? "unknown (tailscale not available)" : renderServe(data.serve)}`],
5268
+ ...phoneQrOf(data.openableUrl)
4393
5269
  ].join("\n"));
4394
5270
  });
4395
5271
  program.command("serve").description("Run the daemon in the foreground. Press Ctrl+C to stop").option("--port <n>", "Port for the management UI for this run only. Defaults to listeners.json, then 43180", parseInteger("--port", 1, 65535)).option("--preview-port <n>", "Port for the listener that shows documents for this run only. Defaults to listeners.json, then 43181", parseInteger("--preview-port", 1, 65535)).action(async (options) => {
@@ -4461,8 +5337,7 @@ async function runCli(rawArgv, context) {
4461
5337
  }
4462
5338
  return exitCode;
4463
5339
  }
4464
- //#endregion
4465
- //#region src/cli.ts
5340
+ // src/cli.ts
4466
5341
  function stdinIsPiped() {
4467
5342
  try {
4468
5343
  const stats = fstatSync(0);
@@ -4496,5 +5371,4 @@ process.exitCode = await runCli(process.argv.slice(2), {
4496
5371
  read: readStdin
4497
5372
  }
4498
5373
  });
4499
- //#endregion
4500
5374
  export {};