@seelen-ui/lib 2.4.6 → 2.4.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.
Files changed (120) hide show
  1. package/esm/deps/jsr.io/@std/encoding/1.0.10/_common16.d.ts +23 -0
  2. package/esm/deps/jsr.io/@std/encoding/1.0.10/_common16.d.ts.map +1 -0
  3. package/esm/deps/jsr.io/@std/encoding/1.0.10/_common16.js +51 -0
  4. package/esm/deps/jsr.io/@std/encoding/1.0.10/_common32.d.ts +35 -0
  5. package/esm/deps/jsr.io/@std/encoding/1.0.10/_common32.d.ts.map +1 -0
  6. package/esm/deps/jsr.io/@std/encoding/1.0.10/_common32.js +192 -0
  7. package/esm/deps/jsr.io/@std/encoding/1.0.10/_validate_binary_like.d.ts +2 -0
  8. package/esm/deps/jsr.io/@std/encoding/1.0.10/_validate_binary_like.d.ts.map +1 -0
  9. package/esm/deps/jsr.io/@std/encoding/1.0.10/_validate_binary_like.js +26 -0
  10. package/esm/deps/jsr.io/@std/encoding/1.0.10/ascii85.d.ts +61 -0
  11. package/esm/deps/jsr.io/@std/encoding/1.0.10/ascii85.d.ts.map +1 -0
  12. package/esm/deps/jsr.io/@std/encoding/1.0.10/ascii85.js +152 -0
  13. package/esm/deps/jsr.io/@std/encoding/1.0.10/base32.d.ts +40 -0
  14. package/esm/deps/jsr.io/@std/encoding/1.0.10/base32.d.ts.map +1 -0
  15. package/esm/deps/jsr.io/@std/encoding/1.0.10/base32.js +87 -0
  16. package/esm/deps/jsr.io/@std/encoding/1.0.10/base58.d.ts +40 -0
  17. package/esm/deps/jsr.io/@std/encoding/1.0.10/base58.d.ts.map +1 -0
  18. package/esm/deps/jsr.io/@std/encoding/1.0.10/base58.js +131 -0
  19. package/esm/deps/jsr.io/@std/encoding/1.0.10/base64.d.ts +40 -0
  20. package/esm/deps/jsr.io/@std/encoding/1.0.10/base64.d.ts.map +1 -0
  21. package/esm/deps/jsr.io/@std/encoding/1.0.10/base64.js +82 -0
  22. package/esm/deps/jsr.io/@std/encoding/1.0.10/hex.d.ts +39 -0
  23. package/esm/deps/jsr.io/@std/encoding/1.0.10/hex.d.ts.map +1 -0
  24. package/esm/deps/jsr.io/@std/encoding/1.0.10/hex.js +87 -0
  25. package/esm/deps/jsr.io/@std/encoding/1.0.10/mod.d.ts +98 -0
  26. package/esm/deps/jsr.io/@std/encoding/1.0.10/mod.d.ts.map +1 -0
  27. package/esm/deps/jsr.io/@std/encoding/1.0.10/mod.js +99 -0
  28. package/esm/deps/jsr.io/@std/encoding/1.0.10/varint.d.ts +120 -0
  29. package/esm/deps/jsr.io/@std/encoding/1.0.10/varint.d.ts.map +1 -0
  30. package/esm/deps/jsr.io/@std/encoding/1.0.10/varint.js +205 -0
  31. package/esm/gen/types/AppExtraFlag.d.ts +6 -5
  32. package/esm/gen/types/AppExtraFlag.d.ts.map +1 -1
  33. package/esm/gen/types/AppExtraFlag.js +6 -5
  34. package/esm/gen/types/FancyToolbarSettings.d.ts +0 -8
  35. package/esm/gen/types/FancyToolbarSettings.d.ts.map +1 -1
  36. package/esm/gen/types/FocusedApp.d.ts +6 -0
  37. package/esm/gen/types/FocusedApp.d.ts.map +1 -1
  38. package/esm/gen/types/SeelenCommandArgument.d.ts +4 -3
  39. package/esm/gen/types/SeelenCommandArgument.d.ts.map +1 -1
  40. package/esm/gen/types/SeelenCommandReturn.d.ts +4 -2
  41. package/esm/gen/types/SeelenCommandReturn.d.ts.map +1 -1
  42. package/esm/gen/types/SeelenEventPayload.d.ts +0 -4
  43. package/esm/gen/types/SeelenEventPayload.d.ts.map +1 -1
  44. package/esm/gen/types/mod.d.ts +0 -1
  45. package/esm/gen/types/mod.d.ts.map +1 -1
  46. package/esm/gen/types/mod.js +0 -1
  47. package/esm/src/constants/mod.d.ts +194 -196
  48. package/esm/src/constants/mod.d.ts.map +1 -1
  49. package/esm/src/constants/mod.js +52 -61
  50. package/esm/src/handlers/commands.d.ts +2 -1
  51. package/esm/src/handlers/commands.d.ts.map +1 -1
  52. package/esm/src/handlers/commands.js +2 -1
  53. package/esm/src/handlers/events.d.ts +0 -2
  54. package/esm/src/handlers/events.d.ts.map +1 -1
  55. package/esm/src/handlers/events.js +0 -2
  56. package/esm/src/state/widget/mod.js +1 -1
  57. package/package.json +7 -6
  58. package/script/deps/jsr.io/@std/encoding/1.0.10/_common16.d.ts +23 -0
  59. package/script/deps/jsr.io/@std/encoding/1.0.10/_common16.d.ts.map +1 -0
  60. package/script/deps/jsr.io/@std/encoding/1.0.10/_common16.js +57 -0
  61. package/script/deps/jsr.io/@std/encoding/1.0.10/_common32.d.ts +35 -0
  62. package/script/deps/jsr.io/@std/encoding/1.0.10/_common32.d.ts.map +1 -0
  63. package/script/deps/jsr.io/@std/encoding/1.0.10/_common32.js +198 -0
  64. package/script/deps/jsr.io/@std/encoding/1.0.10/_validate_binary_like.d.ts +2 -0
  65. package/script/deps/jsr.io/@std/encoding/1.0.10/_validate_binary_like.d.ts.map +1 -0
  66. package/script/deps/jsr.io/@std/encoding/1.0.10/_validate_binary_like.js +29 -0
  67. package/script/deps/jsr.io/@std/encoding/1.0.10/ascii85.d.ts +61 -0
  68. package/script/deps/jsr.io/@std/encoding/1.0.10/ascii85.d.ts.map +1 -0
  69. package/script/deps/jsr.io/@std/encoding/1.0.10/ascii85.js +156 -0
  70. package/script/deps/jsr.io/@std/encoding/1.0.10/base32.d.ts +40 -0
  71. package/script/deps/jsr.io/@std/encoding/1.0.10/base32.d.ts.map +1 -0
  72. package/script/deps/jsr.io/@std/encoding/1.0.10/base32.js +91 -0
  73. package/script/deps/jsr.io/@std/encoding/1.0.10/base58.d.ts +40 -0
  74. package/script/deps/jsr.io/@std/encoding/1.0.10/base58.d.ts.map +1 -0
  75. package/script/deps/jsr.io/@std/encoding/1.0.10/base58.js +135 -0
  76. package/script/deps/jsr.io/@std/encoding/1.0.10/base64.d.ts +40 -0
  77. package/script/deps/jsr.io/@std/encoding/1.0.10/base64.d.ts.map +1 -0
  78. package/script/deps/jsr.io/@std/encoding/1.0.10/base64.js +86 -0
  79. package/script/deps/jsr.io/@std/encoding/1.0.10/hex.d.ts +39 -0
  80. package/script/deps/jsr.io/@std/encoding/1.0.10/hex.d.ts.map +1 -0
  81. package/script/deps/jsr.io/@std/encoding/1.0.10/hex.js +91 -0
  82. package/script/deps/jsr.io/@std/encoding/1.0.10/mod.d.ts +98 -0
  83. package/script/deps/jsr.io/@std/encoding/1.0.10/mod.d.ts.map +1 -0
  84. package/script/deps/jsr.io/@std/encoding/1.0.10/mod.js +115 -0
  85. package/script/deps/jsr.io/@std/encoding/1.0.10/varint.d.ts +120 -0
  86. package/script/deps/jsr.io/@std/encoding/1.0.10/varint.d.ts.map +1 -0
  87. package/script/deps/jsr.io/@std/encoding/1.0.10/varint.js +211 -0
  88. package/script/gen/types/AppExtraFlag.d.ts +6 -5
  89. package/script/gen/types/AppExtraFlag.d.ts.map +1 -1
  90. package/script/gen/types/AppExtraFlag.js +6 -5
  91. package/script/gen/types/FancyToolbarSettings.d.ts +0 -8
  92. package/script/gen/types/FancyToolbarSettings.d.ts.map +1 -1
  93. package/script/gen/types/FocusedApp.d.ts +6 -0
  94. package/script/gen/types/FocusedApp.d.ts.map +1 -1
  95. package/script/gen/types/SeelenCommandArgument.d.ts +4 -3
  96. package/script/gen/types/SeelenCommandArgument.d.ts.map +1 -1
  97. package/script/gen/types/SeelenCommandReturn.d.ts +4 -2
  98. package/script/gen/types/SeelenCommandReturn.d.ts.map +1 -1
  99. package/script/gen/types/SeelenEventPayload.d.ts +0 -4
  100. package/script/gen/types/SeelenEventPayload.d.ts.map +1 -1
  101. package/script/gen/types/mod.d.ts +0 -1
  102. package/script/gen/types/mod.d.ts.map +1 -1
  103. package/script/gen/types/mod.js +0 -1
  104. package/script/src/constants/mod.d.ts +194 -196
  105. package/script/src/constants/mod.d.ts.map +1 -1
  106. package/script/src/constants/mod.js +52 -61
  107. package/script/src/handlers/commands.d.ts +2 -1
  108. package/script/src/handlers/commands.d.ts.map +1 -1
  109. package/script/src/handlers/commands.js +2 -1
  110. package/script/src/handlers/events.d.ts +0 -2
  111. package/script/src/handlers/events.d.ts.map +1 -1
  112. package/script/src/handlers/events.js +0 -2
  113. package/script/src/re-exports/tauri.js +17 -7
  114. package/script/src/state/widget/mod.js +19 -9
  115. package/esm/gen/types/SeelenCommandTranslateTextArgs.d.ts +0 -6
  116. package/esm/gen/types/SeelenCommandTranslateTextArgs.d.ts.map +0 -1
  117. package/esm/gen/types/SeelenCommandTranslateTextArgs.js +0 -2
  118. package/script/gen/types/SeelenCommandTranslateTextArgs.d.ts +0 -6
  119. package/script/gen/types/SeelenCommandTranslateTextArgs.d.ts.map +0 -1
  120. package/script/gen/types/SeelenCommandTranslateTextArgs.js +0 -3
@@ -0,0 +1,39 @@
1
+ import type { Uint8Array_ } from "./_types.js";
2
+ export type { Uint8Array_ };
3
+ /**
4
+ * Converts data into a hex-encoded string.
5
+ *
6
+ * @param src The data to encode.
7
+ *
8
+ * @returns The hex-encoded string.
9
+ *
10
+ * @example Usage
11
+ * ```ts
12
+ * import { encodeHex } from "@std/encoding/hex";
13
+ * import { assertEquals } from "@std/assert";
14
+ *
15
+ * assertEquals(encodeHex("abc"), "616263");
16
+ * ```
17
+ */
18
+ export declare function encodeHex(src: string | Uint8Array | ArrayBuffer): string;
19
+ /**
20
+ * Decodes the given hex-encoded string. If the input is malformed, an error is
21
+ * thrown.
22
+ *
23
+ * @param src The hex-encoded string to decode.
24
+ *
25
+ * @returns The decoded data.
26
+ *
27
+ * @example Usage
28
+ * ```ts
29
+ * import { decodeHex } from "@std/encoding/hex";
30
+ * import { assertEquals } from "@std/assert";
31
+ *
32
+ * assertEquals(
33
+ * decodeHex("616263"),
34
+ * new TextEncoder().encode("abc"),
35
+ * );
36
+ * ```
37
+ */
38
+ export declare function decodeHex(src: string): Uint8Array_;
39
+ //# sourceMappingURL=hex.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hex.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/encoding/1.0.10/hex.ts"],"names":[],"mappings":"AA8BA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,YAAY,EAAE,WAAW,EAAE,CAAC;AAU5B;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,GAAG,WAAW,GAAG,MAAM,CAWxE;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,WAAW,CAKlD"}
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+ // Copyright 2009 The Go Authors. All rights reserved.
3
+ // https://github.com/golang/go/blob/master/LICENSE
4
+ // Copyright 2018-2025 the Deno authors. MIT license.
5
+ // This module is browser compatible.
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.encodeHex = encodeHex;
8
+ exports.decodeHex = decodeHex;
9
+ /**
10
+ * Port of the Go
11
+ * {@link https://github.com/golang/go/blob/go1.12.5/src/encoding/hex/hex.go | encoding/hex}
12
+ * library.
13
+ *
14
+ * ```ts
15
+ * import {
16
+ * decodeHex,
17
+ * encodeHex,
18
+ * } from "@std/encoding/hex";
19
+ * import { assertEquals } from "@std/assert";
20
+ *
21
+ * assertEquals(encodeHex("abc"), "616263");
22
+ *
23
+ * assertEquals(
24
+ * decodeHex("616263"),
25
+ * new TextEncoder().encode("abc"),
26
+ * );
27
+ * ```
28
+ *
29
+ * @module
30
+ */
31
+ const _common16_js_1 = require("./_common16.js");
32
+ const _common_detach_js_1 = require("./_common_detach.js");
33
+ const alphabet = new TextEncoder()
34
+ .encode("0123456789abcdef");
35
+ const rAlphabet = new Uint8Array(128).fill(16); // alphabet.length
36
+ alphabet.forEach((byte, i) => rAlphabet[byte] = i);
37
+ new TextEncoder()
38
+ .encode("ABCDEF")
39
+ .forEach((byte, i) => rAlphabet[byte] = i + 10);
40
+ /**
41
+ * Converts data into a hex-encoded string.
42
+ *
43
+ * @param src The data to encode.
44
+ *
45
+ * @returns The hex-encoded string.
46
+ *
47
+ * @example Usage
48
+ * ```ts
49
+ * import { encodeHex } from "@std/encoding/hex";
50
+ * import { assertEquals } from "@std/assert";
51
+ *
52
+ * assertEquals(encodeHex("abc"), "616263");
53
+ * ```
54
+ */
55
+ function encodeHex(src) {
56
+ if (typeof src === "string") {
57
+ src = new TextEncoder().encode(src);
58
+ }
59
+ else if (src instanceof ArrayBuffer)
60
+ src = new Uint8Array(src).slice();
61
+ else
62
+ src = src.slice();
63
+ const [output, i] = (0, _common_detach_js_1.detach)(src, (0, _common16_js_1.calcSizeHex)(src.length));
64
+ (0, _common16_js_1.encode)(output, i, 0, alphabet);
65
+ return new TextDecoder().decode(output);
66
+ }
67
+ /**
68
+ * Decodes the given hex-encoded string. If the input is malformed, an error is
69
+ * thrown.
70
+ *
71
+ * @param src The hex-encoded string to decode.
72
+ *
73
+ * @returns The decoded data.
74
+ *
75
+ * @example Usage
76
+ * ```ts
77
+ * import { decodeHex } from "@std/encoding/hex";
78
+ * import { assertEquals } from "@std/assert";
79
+ *
80
+ * assertEquals(
81
+ * decodeHex("616263"),
82
+ * new TextEncoder().encode("abc"),
83
+ * );
84
+ * ```
85
+ */
86
+ function decodeHex(src) {
87
+ const output = new TextEncoder().encode(src);
88
+ // deno-lint-ignore no-explicit-any
89
+ return new Uint8Array(output.buffer
90
+ .transfer((0, _common16_js_1.decode)(output, 0, 0, rAlphabet)));
91
+ }
@@ -0,0 +1,98 @@
1
+ /**
2
+ * Utilities for encoding and decoding common formats like hex, base64, and varint.
3
+ *
4
+ * ## Basic Usage
5
+ *
6
+ * ```ts
7
+ * import { encodeBase64, decodeBase64 } from "@std/encoding";
8
+ * import { assertEquals } from "@std/assert";
9
+ *
10
+ * const foobar = new TextEncoder().encode("foobar");
11
+ * assertEquals(encodeBase64(foobar), "Zm9vYmFy");
12
+ * assertEquals(decodeBase64("Zm9vYmFy"), foobar);
13
+ * ```
14
+ *
15
+ * ## Various Encoding Formats
16
+ *
17
+ * ```ts
18
+ * import {
19
+ * encodeHex,
20
+ * encodeBase32,
21
+ * encodeBase58,
22
+ * encodeBase64,
23
+ * encodeAscii85,
24
+ * decodeHex,
25
+ * decodeBase32,
26
+ * decodeBase58,
27
+ * decodeBase64,
28
+ * decodeAscii85,
29
+ * } from "@std/encoding";
30
+ * import { assertEquals } from "@std/assert";
31
+ *
32
+ * // Many different encodings for different character sets
33
+ * assertEquals(encodeHex("Hello world!"), "48656c6c6f20776f726c6421");
34
+ * assertEquals(encodeBase32("Hello world!"), "JBSWY3DPEB3W64TMMQQQ====");
35
+ * assertEquals(encodeBase58("Hello world!"), "2NEpo7TZRhna7vSvL");
36
+ * assertEquals(encodeBase64("Hello world!"), "SGVsbG8gd29ybGQh");
37
+ * assertEquals(encodeAscii85("Hello world!"), "87cURD]j7BEbo80");
38
+ *
39
+ * // Decoding
40
+ * assertEquals(new TextDecoder().decode(decodeHex("48656c6c6f20776f726c6421")), "Hello world!");
41
+ * assertEquals(new TextDecoder().decode(decodeBase32("JBSWY3DPEB3W64TMMQQQ====")), "Hello world!");
42
+ * assertEquals(new TextDecoder().decode(decodeBase58("2NEpo7TZRhna7vSvL")), "Hello world!");
43
+ * assertEquals(new TextDecoder().decode(decodeBase64("SGVsbG8gd29ybGQh")), "Hello world!");
44
+ * assertEquals(new TextDecoder().decode(decodeAscii85("87cURD]j7BEbo80")), "Hello world!");
45
+ * ```
46
+ *
47
+ * ## URL-Safe Base64
48
+ *
49
+ * ```ts
50
+ * import { encodeBase64, encodeBase64Url } from "@std/encoding";
51
+ * import { assertEquals } from "@std/assert";
52
+ *
53
+ * assertEquals(encodeBase64("ice creams"), "aWNlIGNyZWFtcw=="); // Not url-safe because of `=`
54
+ * assertEquals(encodeBase64Url("ice creams"), "aWNlIGNyZWFtcw"); // URL-safe!
55
+ *
56
+ * // Base64Url replaces + with - and / with _
57
+ * assertEquals(encodeBase64("subjects?"), "c3ViamVjdHM/"); // slash is not URL-safe
58
+ * assertEquals(encodeBase64Url("subjects?"), "c3ViamVjdHM_"); // _ is URL-safe
59
+ * ```
60
+ *
61
+ * ## Binary Data Encoding
62
+ *
63
+ * ```ts
64
+ * import { encodeHex, encodeBase64 } from "@std/encoding";
65
+ * import { assertEquals } from "@std/assert";
66
+ *
67
+ * // Working with binary data
68
+ * const binaryData = new Uint8Array([0xDE, 0xAD, 0xBE, 0xEF]);
69
+ * assertEquals(encodeHex(binaryData), "deadbeef");
70
+ * assertEquals(encodeBase64(binaryData), "3q2+7w==");
71
+ * ```
72
+ *
73
+ * ## Varint Encoding
74
+ *
75
+ * Learn more from the [protobuf Varint encoding docs](https://protobuf.dev/programming-guides/encoding/#varints).
76
+ *
77
+ * ```ts
78
+ * import { encodeVarint, decodeVarint } from "@std/encoding";
79
+ * import { assertEquals } from "@std/assert";
80
+ *
81
+ * // Varint encoding support
82
+ * assertEquals(encodeVarint(9601n), [new Uint8Array([129, 75]), 2]);
83
+ *
84
+ * // Decode a varint
85
+ * const bytes = new Uint8Array([129, 75]);
86
+ * assertEquals(decodeVarint(bytes), [9601n, 2]);
87
+ * ```
88
+ *
89
+ * @module
90
+ */
91
+ export * from "./ascii85.js";
92
+ export * from "./base32.js";
93
+ export * from "./base58.js";
94
+ export * from "./base64.js";
95
+ export * from "./base64url.js";
96
+ export * from "./hex.js";
97
+ export * from "./varint.js";
98
+ //# sourceMappingURL=mod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/encoding/1.0.10/mod.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyFG;AAEH,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC"}
@@ -0,0 +1,115 @@
1
+ "use strict";
2
+ // Copyright 2018-2025 the Deno authors. MIT license.
3
+ // This module is browser compatible.
4
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
5
+ if (k2 === undefined) k2 = k;
6
+ var desc = Object.getOwnPropertyDescriptor(m, k);
7
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
8
+ desc = { enumerable: true, get: function() { return m[k]; } };
9
+ }
10
+ Object.defineProperty(o, k2, desc);
11
+ }) : (function(o, m, k, k2) {
12
+ if (k2 === undefined) k2 = k;
13
+ o[k2] = m[k];
14
+ }));
15
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
17
+ };
18
+ Object.defineProperty(exports, "__esModule", { value: true });
19
+ /**
20
+ * Utilities for encoding and decoding common formats like hex, base64, and varint.
21
+ *
22
+ * ## Basic Usage
23
+ *
24
+ * ```ts
25
+ * import { encodeBase64, decodeBase64 } from "@std/encoding";
26
+ * import { assertEquals } from "@std/assert";
27
+ *
28
+ * const foobar = new TextEncoder().encode("foobar");
29
+ * assertEquals(encodeBase64(foobar), "Zm9vYmFy");
30
+ * assertEquals(decodeBase64("Zm9vYmFy"), foobar);
31
+ * ```
32
+ *
33
+ * ## Various Encoding Formats
34
+ *
35
+ * ```ts
36
+ * import {
37
+ * encodeHex,
38
+ * encodeBase32,
39
+ * encodeBase58,
40
+ * encodeBase64,
41
+ * encodeAscii85,
42
+ * decodeHex,
43
+ * decodeBase32,
44
+ * decodeBase58,
45
+ * decodeBase64,
46
+ * decodeAscii85,
47
+ * } from "@std/encoding";
48
+ * import { assertEquals } from "@std/assert";
49
+ *
50
+ * // Many different encodings for different character sets
51
+ * assertEquals(encodeHex("Hello world!"), "48656c6c6f20776f726c6421");
52
+ * assertEquals(encodeBase32("Hello world!"), "JBSWY3DPEB3W64TMMQQQ====");
53
+ * assertEquals(encodeBase58("Hello world!"), "2NEpo7TZRhna7vSvL");
54
+ * assertEquals(encodeBase64("Hello world!"), "SGVsbG8gd29ybGQh");
55
+ * assertEquals(encodeAscii85("Hello world!"), "87cURD]j7BEbo80");
56
+ *
57
+ * // Decoding
58
+ * assertEquals(new TextDecoder().decode(decodeHex("48656c6c6f20776f726c6421")), "Hello world!");
59
+ * assertEquals(new TextDecoder().decode(decodeBase32("JBSWY3DPEB3W64TMMQQQ====")), "Hello world!");
60
+ * assertEquals(new TextDecoder().decode(decodeBase58("2NEpo7TZRhna7vSvL")), "Hello world!");
61
+ * assertEquals(new TextDecoder().decode(decodeBase64("SGVsbG8gd29ybGQh")), "Hello world!");
62
+ * assertEquals(new TextDecoder().decode(decodeAscii85("87cURD]j7BEbo80")), "Hello world!");
63
+ * ```
64
+ *
65
+ * ## URL-Safe Base64
66
+ *
67
+ * ```ts
68
+ * import { encodeBase64, encodeBase64Url } from "@std/encoding";
69
+ * import { assertEquals } from "@std/assert";
70
+ *
71
+ * assertEquals(encodeBase64("ice creams"), "aWNlIGNyZWFtcw=="); // Not url-safe because of `=`
72
+ * assertEquals(encodeBase64Url("ice creams"), "aWNlIGNyZWFtcw"); // URL-safe!
73
+ *
74
+ * // Base64Url replaces + with - and / with _
75
+ * assertEquals(encodeBase64("subjects?"), "c3ViamVjdHM/"); // slash is not URL-safe
76
+ * assertEquals(encodeBase64Url("subjects?"), "c3ViamVjdHM_"); // _ is URL-safe
77
+ * ```
78
+ *
79
+ * ## Binary Data Encoding
80
+ *
81
+ * ```ts
82
+ * import { encodeHex, encodeBase64 } from "@std/encoding";
83
+ * import { assertEquals } from "@std/assert";
84
+ *
85
+ * // Working with binary data
86
+ * const binaryData = new Uint8Array([0xDE, 0xAD, 0xBE, 0xEF]);
87
+ * assertEquals(encodeHex(binaryData), "deadbeef");
88
+ * assertEquals(encodeBase64(binaryData), "3q2+7w==");
89
+ * ```
90
+ *
91
+ * ## Varint Encoding
92
+ *
93
+ * Learn more from the [protobuf Varint encoding docs](https://protobuf.dev/programming-guides/encoding/#varints).
94
+ *
95
+ * ```ts
96
+ * import { encodeVarint, decodeVarint } from "@std/encoding";
97
+ * import { assertEquals } from "@std/assert";
98
+ *
99
+ * // Varint encoding support
100
+ * assertEquals(encodeVarint(9601n), [new Uint8Array([129, 75]), 2]);
101
+ *
102
+ * // Decode a varint
103
+ * const bytes = new Uint8Array([129, 75]);
104
+ * assertEquals(decodeVarint(bytes), [9601n, 2]);
105
+ * ```
106
+ *
107
+ * @module
108
+ */
109
+ __exportStar(require("./ascii85.js"), exports);
110
+ __exportStar(require("./base32.js"), exports);
111
+ __exportStar(require("./base58.js"), exports);
112
+ __exportStar(require("./base64.js"), exports);
113
+ __exportStar(require("./base64url.js"), exports);
114
+ __exportStar(require("./hex.js"), exports);
115
+ __exportStar(require("./varint.js"), exports);
@@ -0,0 +1,120 @@
1
+ /**
2
+ * Utilities for {@link https://protobuf.dev/programming-guides/encoding/#varints Varint} encoding
3
+ * of typed integers. Varint encoding represents integers using a variable number of bytes, with
4
+ * smaller values requiring fewer bytes.
5
+ *
6
+ * ```ts
7
+ * import { encodeVarint, decodeVarint } from "@std/encoding/varint";
8
+ * import { assertEquals } from "@std/assert";
9
+ *
10
+ * const buf = new Uint8Array(10);
11
+ * assertEquals(
12
+ * encodeVarint(42n, buf),
13
+ * [new Uint8Array([42]), 1]
14
+ * );
15
+ *
16
+ * assertEquals(
17
+ * decodeVarint(new Uint8Array([42])),
18
+ * [ 42n, 1 ]
19
+ * );
20
+ * ```
21
+ *
22
+ * @module
23
+ */
24
+ import type { Uint8Array_ } from "./_types.js";
25
+ export type { Uint8Array_ };
26
+ /**
27
+ * The maximum value of an unsigned 64-bit integer.
28
+ * Equivalent to `2n**64n - 1n`
29
+ */
30
+ export declare const MaxUint64 = 18446744073709551615n;
31
+ /**
32
+ * The maximum length, in bytes, of a Varint encoded 64-bit integer.
33
+ */
34
+ export declare const MaxVarintLen64 = 10;
35
+ /**
36
+ * The maximum length, in bytes, of a Varint encoded 32-bit integer.
37
+ */
38
+ export declare const MaxVarintLen32 = 5;
39
+ /**
40
+ * Given a non empty `buf`, starting at `offset` (default: 0), begin decoding bytes as
41
+ * Varint encoded bytes, for a maximum of 10 bytes (offset + 10). The returned
42
+ * tuple is of the decoded varint 32-bit number, and the new offset with which
43
+ * to continue decoding other data.
44
+ *
45
+ * If a `bigint` in return is undesired, the `decode32` function will return a
46
+ * `number`, but this should only be used in cases where the varint is
47
+ * _assured_ to be 32-bits. If in doubt, use `decode()`.
48
+ *
49
+ * To know how many bytes the Varint took to encode, simply negate `offset`
50
+ * from the returned new `offset`.
51
+ *
52
+ * @param buf The buffer to decode from.
53
+ * @param offset The offset to start decoding from.
54
+ * @returns A tuple of the decoded varint 64-bit number, and the new offset.
55
+ *
56
+ * @example Usage
57
+ * ```ts
58
+ * import { decodeVarint } from "@std/encoding/varint";
59
+ * import { assertEquals } from "@std/assert";
60
+ *
61
+ * const buf = new Uint8Array([0x8E, 0x02]);
62
+ * assertEquals(decodeVarint(buf), [270n, 2]);
63
+ * ```
64
+ */
65
+ export declare function decodeVarint(buf: Uint8Array, offset?: number): [bigint, number];
66
+ /**
67
+ * Given a `buf`, starting at `offset` (default: 0), begin decoding bytes as
68
+ * Varint encoded bytes, for a maximum of 5 bytes (offset + 5). The returned
69
+ * tuple is of the decoded varint 32-bit number, and the new offset with which
70
+ * to continue decoding other data.
71
+ *
72
+ * Varints are _not 32-bit by default_ so this should only be used in cases
73
+ * where the varint is _assured_ to be 32-bits. If in doubt, use `decode()`.
74
+ *
75
+ * To know how many bytes the Varint took to encode, simply negate `offset`
76
+ * from the returned new `offset`.
77
+ *
78
+ * @param buf The buffer to decode from.
79
+ * @param offset The offset to start decoding from.
80
+ * @returns A tuple of the decoded varint 32-bit number, and the new offset.
81
+ *
82
+ * @example Usage
83
+ * ```ts
84
+ * import { decodeVarint32 } from "@std/encoding/varint";
85
+ * import { assertEquals } from "@std/assert";
86
+ *
87
+ * const buf = new Uint8Array([0x8E, 0x02]);
88
+ * assertEquals(decodeVarint32(buf), [270, 2]);
89
+ * ```
90
+ */
91
+ export declare function decodeVarint32(buf: Uint8Array, offset?: number): [number, number];
92
+ /**
93
+ * Takes unsigned number `num` and converts it into a Varint encoded
94
+ * `Uint8Array`, returning a tuple consisting of a `Uint8Array` slice of the
95
+ * encoded Varint, and an offset where the Varint encoded bytes end within the
96
+ * `Uint8Array`.
97
+ *
98
+ * If `buf` is not given then a Uint8Array will be created.
99
+ * `offset` defaults to `0`.
100
+ *
101
+ * If passed `buf` then that will be written into, starting at `offset`. The
102
+ * resulting returned `Uint8Array` will be a slice of `buf`. The resulting
103
+ * returned number is effectively `offset + bytesWritten`.
104
+ *
105
+ * @param num The number to encode.
106
+ * @param buf The buffer to write into.
107
+ * @param offset The offset to start writing at.
108
+ * @returns A tuple of the encoded Varint `Uint8Array` and the new offset.
109
+ *
110
+ * @example Usage
111
+ * ```ts
112
+ * import { encodeVarint } from "@std/encoding/varint";
113
+ * import { assertEquals } from "@std/assert";
114
+ *
115
+ * const buf = new Uint8Array(10);
116
+ * assertEquals(encodeVarint(42n, buf), [new Uint8Array([42]), 1]);
117
+ * ```
118
+ */
119
+ export declare function encodeVarint(num: bigint | number, buf?: Uint8Array, offset?: number): [Uint8Array_, number];
120
+ //# sourceMappingURL=varint.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"varint.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/encoding/1.0.10/varint.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAKH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,YAAY,EAAE,WAAW,EAAE,CAAC;AAE5B;;;GAGG;AACH,eAAO,MAAM,SAAS,wBAAwB,CAAC;AAE/C;;GAEG;AACH,eAAO,MAAM,cAAc,KAAK,CAAC;AACjC;;GAEG;AACH,eAAO,MAAM,cAAc,IAAI,CAAC;AAahC;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,UAAU,EAAE,MAAM,SAAI,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CA6D1E;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,UAAU,EAAE,MAAM,SAAI,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAe5E;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,YAAY,CAC1B,GAAG,EAAE,MAAM,GAAG,MAAM,EACpB,GAAG,GAAE,UAA2C,EAChD,MAAM,SAAI,GACT,CAAC,WAAW,EAAE,MAAM,CAAC,CAuBvB"}
@@ -0,0 +1,211 @@
1
+ "use strict";
2
+ // Copyright 2018-2025 the Deno authors. MIT license.
3
+ // Copyright 2020 Keith Cirkel. All rights reserved. MIT license.
4
+ // Copyright 2023 Skye "MierenManz". All rights reserved. MIT license.
5
+ /**
6
+ * Utilities for {@link https://protobuf.dev/programming-guides/encoding/#varints Varint} encoding
7
+ * of typed integers. Varint encoding represents integers using a variable number of bytes, with
8
+ * smaller values requiring fewer bytes.
9
+ *
10
+ * ```ts
11
+ * import { encodeVarint, decodeVarint } from "@std/encoding/varint";
12
+ * import { assertEquals } from "@std/assert";
13
+ *
14
+ * const buf = new Uint8Array(10);
15
+ * assertEquals(
16
+ * encodeVarint(42n, buf),
17
+ * [new Uint8Array([42]), 1]
18
+ * );
19
+ *
20
+ * assertEquals(
21
+ * decodeVarint(new Uint8Array([42])),
22
+ * [ 42n, 1 ]
23
+ * );
24
+ * ```
25
+ *
26
+ * @module
27
+ */
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.MaxVarintLen32 = exports.MaxVarintLen64 = exports.MaxUint64 = void 0;
30
+ exports.decodeVarint = decodeVarint;
31
+ exports.decodeVarint32 = decodeVarint32;
32
+ exports.encodeVarint = encodeVarint;
33
+ /**
34
+ * The maximum value of an unsigned 64-bit integer.
35
+ * Equivalent to `2n**64n - 1n`
36
+ */
37
+ exports.MaxUint64 = 18446744073709551615n;
38
+ /**
39
+ * The maximum length, in bytes, of a Varint encoded 64-bit integer.
40
+ */
41
+ exports.MaxVarintLen64 = 10;
42
+ /**
43
+ * The maximum length, in bytes, of a Varint encoded 32-bit integer.
44
+ */
45
+ exports.MaxVarintLen32 = 5;
46
+ const MSB = 0x80;
47
+ const REST = 0x7f;
48
+ const SHIFT = 7;
49
+ const MSBN = 0x80n;
50
+ const SHIFTN = 7n;
51
+ // ArrayBuffer and TypedArray's for "pointer casting"
52
+ const AB = new ArrayBuffer(8);
53
+ const U32_VIEW = new Uint32Array(AB);
54
+ const U64_VIEW = new BigUint64Array(AB);
55
+ /**
56
+ * Given a non empty `buf`, starting at `offset` (default: 0), begin decoding bytes as
57
+ * Varint encoded bytes, for a maximum of 10 bytes (offset + 10). The returned
58
+ * tuple is of the decoded varint 32-bit number, and the new offset with which
59
+ * to continue decoding other data.
60
+ *
61
+ * If a `bigint` in return is undesired, the `decode32` function will return a
62
+ * `number`, but this should only be used in cases where the varint is
63
+ * _assured_ to be 32-bits. If in doubt, use `decode()`.
64
+ *
65
+ * To know how many bytes the Varint took to encode, simply negate `offset`
66
+ * from the returned new `offset`.
67
+ *
68
+ * @param buf The buffer to decode from.
69
+ * @param offset The offset to start decoding from.
70
+ * @returns A tuple of the decoded varint 64-bit number, and the new offset.
71
+ *
72
+ * @example Usage
73
+ * ```ts
74
+ * import { decodeVarint } from "@std/encoding/varint";
75
+ * import { assertEquals } from "@std/assert";
76
+ *
77
+ * const buf = new Uint8Array([0x8E, 0x02]);
78
+ * assertEquals(decodeVarint(buf), [270n, 2]);
79
+ * ```
80
+ */
81
+ function decodeVarint(buf, offset = 0) {
82
+ // Clear the last result from the Two's complement view
83
+ U64_VIEW[0] = 0n;
84
+ // Setup the initiat state of the function
85
+ let intermediate = 0;
86
+ let position = 0;
87
+ let i = offset;
88
+ // If the buffer is empty Throw
89
+ if (buf.length === 0)
90
+ throw new RangeError("Cannot read empty buffer");
91
+ let byte;
92
+ do {
93
+ // Get a single byte from the buffer
94
+ byte = buf[i];
95
+ // 1. Take the lower 7 bits of the byte.
96
+ // 2. Shift the bits into the correct position.
97
+ // 3. Bitwise OR it with the intermediate value
98
+ // QUIRK: in the 5th (and 10th) iteration of this loop it will overflow on the shift.
99
+ // This causes only the lower 4 bits to be shifted into place and removing the upper 3 bits
100
+ intermediate |= (byte & 0b01111111) << position;
101
+ // If position is 28
102
+ // it means that this iteration needs to be written the the two's complement view
103
+ // This only happens once due to the `-4` in this branch
104
+ if (position === 28) {
105
+ // Write to the view
106
+ U32_VIEW[0] = intermediate;
107
+ // set `intermediate` to the remaining 3 bits
108
+ // We only want the remaining three bits because the other 4 have been "consumed" on line 21
109
+ intermediate = (byte & 0b01110000) >>> 4;
110
+ // set `position` to -4 because later 7 will be added, making it 3
111
+ position = -4;
112
+ }
113
+ // Increment the shift position by 7
114
+ position += 7;
115
+ // Increment the iterator by 1
116
+ i++;
117
+ // Keep going while there is a continuation bit
118
+ } while ((byte & 0b10000000) === 0b10000000);
119
+ // subtract the initial offset from `i` to get the bytes read
120
+ const nRead = i - offset;
121
+ // If 10 bytes have been read and intermediate has overflown
122
+ // it means that the varint is malformed
123
+ // If 11 bytes have been read it means that the varint is malformed
124
+ // If `i` is bigger than the buffer it means we overread the buffer and the varint is malformed
125
+ if ((nRead === 10 && intermediate > -1) || nRead === 11 || i > buf.length) {
126
+ throw new RangeError("Cannot decode the varint input: Malformed or overflow varint");
127
+ }
128
+ // Write the intermediate value to the "empty" slot
129
+ // if the first slot is taken. Take the second slot
130
+ U32_VIEW[Number(nRead > 4)] = intermediate;
131
+ return [U64_VIEW[0], i];
132
+ }
133
+ /**
134
+ * Given a `buf`, starting at `offset` (default: 0), begin decoding bytes as
135
+ * Varint encoded bytes, for a maximum of 5 bytes (offset + 5). The returned
136
+ * tuple is of the decoded varint 32-bit number, and the new offset with which
137
+ * to continue decoding other data.
138
+ *
139
+ * Varints are _not 32-bit by default_ so this should only be used in cases
140
+ * where the varint is _assured_ to be 32-bits. If in doubt, use `decode()`.
141
+ *
142
+ * To know how many bytes the Varint took to encode, simply negate `offset`
143
+ * from the returned new `offset`.
144
+ *
145
+ * @param buf The buffer to decode from.
146
+ * @param offset The offset to start decoding from.
147
+ * @returns A tuple of the decoded varint 32-bit number, and the new offset.
148
+ *
149
+ * @example Usage
150
+ * ```ts
151
+ * import { decodeVarint32 } from "@std/encoding/varint";
152
+ * import { assertEquals } from "@std/assert";
153
+ *
154
+ * const buf = new Uint8Array([0x8E, 0x02]);
155
+ * assertEquals(decodeVarint32(buf), [270, 2]);
156
+ * ```
157
+ */
158
+ function decodeVarint32(buf, offset = 0) {
159
+ let shift = 0;
160
+ let decoded = 0;
161
+ for (let i = offset; i <= Math.min(buf.length, offset + exports.MaxVarintLen32); i += 1, shift += SHIFT) {
162
+ const byte = buf[i];
163
+ decoded += (byte & REST) * Math.pow(2, shift);
164
+ if (!(byte & MSB))
165
+ return [decoded, i + 1];
166
+ }
167
+ throw new RangeError("Cannot decode the varint input: Malformed or overflow varint");
168
+ }
169
+ /**
170
+ * Takes unsigned number `num` and converts it into a Varint encoded
171
+ * `Uint8Array`, returning a tuple consisting of a `Uint8Array` slice of the
172
+ * encoded Varint, and an offset where the Varint encoded bytes end within the
173
+ * `Uint8Array`.
174
+ *
175
+ * If `buf` is not given then a Uint8Array will be created.
176
+ * `offset` defaults to `0`.
177
+ *
178
+ * If passed `buf` then that will be written into, starting at `offset`. The
179
+ * resulting returned `Uint8Array` will be a slice of `buf`. The resulting
180
+ * returned number is effectively `offset + bytesWritten`.
181
+ *
182
+ * @param num The number to encode.
183
+ * @param buf The buffer to write into.
184
+ * @param offset The offset to start writing at.
185
+ * @returns A tuple of the encoded Varint `Uint8Array` and the new offset.
186
+ *
187
+ * @example Usage
188
+ * ```ts
189
+ * import { encodeVarint } from "@std/encoding/varint";
190
+ * import { assertEquals } from "@std/assert";
191
+ *
192
+ * const buf = new Uint8Array(10);
193
+ * assertEquals(encodeVarint(42n, buf), [new Uint8Array([42]), 1]);
194
+ * ```
195
+ */
196
+ function encodeVarint(num, buf = new Uint8Array(exports.MaxVarintLen64), offset = 0) {
197
+ num = BigInt(num);
198
+ if (num < 0n) {
199
+ throw new RangeError(`Cannot encode the input into varint as it should be non-negative integer: received ${num}`);
200
+ }
201
+ for (let i = offset; i <= Math.min(buf.length, exports.MaxVarintLen64); i += 1) {
202
+ if (num < MSBN) {
203
+ buf[i] = Number(num);
204
+ i += 1;
205
+ return [buf.slice(offset, i), i];
206
+ }
207
+ buf[i] = Number((num & 0xffn) | MSBN);
208
+ num >>= SHIFTN;
209
+ }
210
+ throw new RangeError(`Cannot encode the input ${num} into varint as it overflows uint64`);
211
+ }