@seelen-ui/lib 2.4.7 → 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.
- package/esm/deps/jsr.io/@std/encoding/1.0.10/_common16.d.ts +23 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.10/_common16.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.10/_common16.js +51 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.10/_common32.d.ts +35 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.10/_common32.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.10/_common32.js +192 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.10/_validate_binary_like.d.ts +2 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.10/_validate_binary_like.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.10/_validate_binary_like.js +26 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.10/ascii85.d.ts +61 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.10/ascii85.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.10/ascii85.js +152 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.10/base32.d.ts +40 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.10/base32.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.10/base32.js +87 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.10/base58.d.ts +40 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.10/base58.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.10/base58.js +131 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.10/base64.d.ts +40 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.10/base64.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.10/base64.js +82 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.10/hex.d.ts +39 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.10/hex.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.10/hex.js +87 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.10/mod.d.ts +98 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.10/mod.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.10/mod.js +99 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.10/varint.d.ts +120 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.10/varint.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.10/varint.js +205 -0
- package/esm/gen/types/FancyToolbarSettings.d.ts +0 -8
- package/esm/gen/types/FancyToolbarSettings.d.ts.map +1 -1
- package/esm/gen/types/FocusedApp.d.ts +6 -0
- package/esm/gen/types/FocusedApp.d.ts.map +1 -1
- package/esm/gen/types/SeelenCommandArgument.d.ts +4 -0
- package/esm/gen/types/SeelenCommandArgument.d.ts.map +1 -1
- package/esm/gen/types/SeelenCommandReturn.d.ts +4 -0
- package/esm/gen/types/SeelenCommandReturn.d.ts.map +1 -1
- package/esm/gen/types/SeelenEventPayload.d.ts +0 -4
- package/esm/gen/types/SeelenEventPayload.d.ts.map +1 -1
- package/esm/src/handlers/commands.d.ts +2 -0
- package/esm/src/handlers/commands.d.ts.map +1 -1
- package/esm/src/handlers/commands.js +2 -0
- package/esm/src/handlers/events.d.ts +0 -2
- package/esm/src/handlers/events.d.ts.map +1 -1
- package/esm/src/handlers/events.js +0 -2
- package/esm/src/state/widget/mod.js +1 -1
- package/package.json +7 -6
- package/script/deps/jsr.io/@std/encoding/1.0.10/_common16.d.ts +23 -0
- package/script/deps/jsr.io/@std/encoding/1.0.10/_common16.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/encoding/1.0.10/_common16.js +57 -0
- package/script/deps/jsr.io/@std/encoding/1.0.10/_common32.d.ts +35 -0
- package/script/deps/jsr.io/@std/encoding/1.0.10/_common32.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/encoding/1.0.10/_common32.js +198 -0
- package/script/deps/jsr.io/@std/encoding/1.0.10/_validate_binary_like.d.ts +2 -0
- package/script/deps/jsr.io/@std/encoding/1.0.10/_validate_binary_like.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/encoding/1.0.10/_validate_binary_like.js +29 -0
- package/script/deps/jsr.io/@std/encoding/1.0.10/ascii85.d.ts +61 -0
- package/script/deps/jsr.io/@std/encoding/1.0.10/ascii85.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/encoding/1.0.10/ascii85.js +156 -0
- package/script/deps/jsr.io/@std/encoding/1.0.10/base32.d.ts +40 -0
- package/script/deps/jsr.io/@std/encoding/1.0.10/base32.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/encoding/1.0.10/base32.js +91 -0
- package/script/deps/jsr.io/@std/encoding/1.0.10/base58.d.ts +40 -0
- package/script/deps/jsr.io/@std/encoding/1.0.10/base58.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/encoding/1.0.10/base58.js +135 -0
- package/script/deps/jsr.io/@std/encoding/1.0.10/base64.d.ts +40 -0
- package/script/deps/jsr.io/@std/encoding/1.0.10/base64.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/encoding/1.0.10/base64.js +86 -0
- package/script/deps/jsr.io/@std/encoding/1.0.10/hex.d.ts +39 -0
- package/script/deps/jsr.io/@std/encoding/1.0.10/hex.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/encoding/1.0.10/hex.js +91 -0
- package/script/deps/jsr.io/@std/encoding/1.0.10/mod.d.ts +98 -0
- package/script/deps/jsr.io/@std/encoding/1.0.10/mod.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/encoding/1.0.10/mod.js +115 -0
- package/script/deps/jsr.io/@std/encoding/1.0.10/varint.d.ts +120 -0
- package/script/deps/jsr.io/@std/encoding/1.0.10/varint.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/encoding/1.0.10/varint.js +211 -0
- package/script/gen/types/FancyToolbarSettings.d.ts +0 -8
- package/script/gen/types/FancyToolbarSettings.d.ts.map +1 -1
- package/script/gen/types/FocusedApp.d.ts +6 -0
- package/script/gen/types/FocusedApp.d.ts.map +1 -1
- package/script/gen/types/SeelenCommandArgument.d.ts +4 -0
- package/script/gen/types/SeelenCommandArgument.d.ts.map +1 -1
- package/script/gen/types/SeelenCommandReturn.d.ts +4 -0
- package/script/gen/types/SeelenCommandReturn.d.ts.map +1 -1
- package/script/gen/types/SeelenEventPayload.d.ts +0 -4
- package/script/gen/types/SeelenEventPayload.d.ts.map +1 -1
- package/script/src/handlers/commands.d.ts +2 -0
- package/script/src/handlers/commands.d.ts.map +1 -1
- package/script/src/handlers/commands.js +2 -0
- package/script/src/handlers/events.d.ts +0 -2
- package/script/src/handlers/events.d.ts.map +1 -1
- package/script/src/handlers/events.js +0 -2
- package/script/src/re-exports/tauri.js +17 -7
- package/script/src/state/widget/mod.js +19 -9
|
@@ -25,8 +25,6 @@ export declare enum SeelenEvent {
|
|
|
25
25
|
PowerMode = "power-mode",
|
|
26
26
|
BatteriesStatus = "batteries-status",
|
|
27
27
|
ColorsChanged = "colors-changed",
|
|
28
|
-
ToolbarOverlaped = "set-auto-hide",
|
|
29
|
-
WegOverlaped = "set-auto-hide",
|
|
30
28
|
WMSetReservation = "set-reservation",
|
|
31
29
|
WMForceRetiling = "wm-force-retiling",
|
|
32
30
|
WMSetLayout = "wm-set-layout",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../../../src/src/handlers/events.ts"],"names":[],"mappings":"AACA,oBAAY,WAAW;IACrB,sBAAsB,8BAA8B;IACpD,kBAAkB,yBAAyB;IAC3C,eAAe,sBAAsB;IACrC,qBAAqB,mBAAmB;IACxC,qBAAqB,6BAA6B;IAClD,sBAAsB,8BAA8B;IACpD,WAAW,iBAAiB;IAC5B,iBAAiB,wBAAwB;IACzC,uBAAuB,+BAA+B;IACtD,qBAAqB,0BAA0B;IAC/C,uBAAuB,8BAA8B;IACrD,iCAAiC,yCAAyC;IAC1E,oBAAoB,4BAA4B;IAChD,uBAAuB,+BAA+B;IACtD,aAAa,mBAAmB;IAChC,WAAW,iBAAiB;IAC5B,YAAY,kBAAkB;IAC9B,qBAAqB,6BAA6B;IAClD,eAAe,qBAAqB;IACpC,yBAAyB,gCAAgC;IACzD,kBAAkB,iBAAiB;IACnC,aAAa,kBAAkB;IAC/B,WAAW,iBAAiB;IAC5B,SAAS,eAAe;IACxB,eAAe,qBAAqB;IACpC,aAAa,mBAAmB;IAChC,gBAAgB,
|
|
1
|
+
{"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../../../src/src/handlers/events.ts"],"names":[],"mappings":"AACA,oBAAY,WAAW;IACrB,sBAAsB,8BAA8B;IACpD,kBAAkB,yBAAyB;IAC3C,eAAe,sBAAsB;IACrC,qBAAqB,mBAAmB;IACxC,qBAAqB,6BAA6B;IAClD,sBAAsB,8BAA8B;IACpD,WAAW,iBAAiB;IAC5B,iBAAiB,wBAAwB;IACzC,uBAAuB,+BAA+B;IACtD,qBAAqB,0BAA0B;IAC/C,uBAAuB,8BAA8B;IACrD,iCAAiC,yCAAyC;IAC1E,oBAAoB,4BAA4B;IAChD,uBAAuB,+BAA+B;IACtD,aAAa,mBAAmB;IAChC,WAAW,iBAAiB;IAC5B,YAAY,kBAAkB;IAC9B,qBAAqB,6BAA6B;IAClD,eAAe,qBAAqB;IACpC,yBAAyB,gCAAgC;IACzD,kBAAkB,iBAAiB;IACnC,aAAa,kBAAkB;IAC/B,WAAW,iBAAiB;IAC5B,SAAS,eAAe;IACxB,eAAe,qBAAqB;IACpC,aAAa,mBAAmB;IAChC,gBAAgB,oBAAoB;IACpC,eAAe,sBAAsB;IACrC,WAAW,kBAAkB;IAC7B,mBAAmB,0BAA0B;IAC7C,oBAAoB,qBAAqB;IACzC,oBAAoB,cAAc;IAClC,wBAAwB,kBAAkB;IAC1C,kBAAkB,WAAW;IAC7B,yBAAyB,oBAAoB;IAC7C,mBAAmB,YAAY;IAC/B,qBAAqB,eAAe;IACpC,mBAAmB,oBAAoB;IACvC,mBAAmB,oBAAoB;IACvC,sBAAsB,sCAAsC;IAC5D,oBAAoB,qBAAqB;IACzC,iBAAiB,yBAAyB;IAC1C,2BAA2B,oCAAoC;IAC/D,eAAe,sBAAsB;CACtC"}
|
|
@@ -27,8 +27,6 @@ export var SeelenEvent;
|
|
|
27
27
|
SeelenEvent["PowerMode"] = "power-mode";
|
|
28
28
|
SeelenEvent["BatteriesStatus"] = "batteries-status";
|
|
29
29
|
SeelenEvent["ColorsChanged"] = "colors-changed";
|
|
30
|
-
SeelenEvent["ToolbarOverlaped"] = "set-auto-hide";
|
|
31
|
-
SeelenEvent["WegOverlaped"] = "set-auto-hide";
|
|
32
30
|
SeelenEvent["WMSetReservation"] = "set-reservation";
|
|
33
31
|
SeelenEvent["WMForceRetiling"] = "wm-force-retiling";
|
|
34
32
|
SeelenEvent["WMSetLayout"] = "wm-set-layout";
|
|
@@ -4,7 +4,7 @@ import { SeelenCommand, SeelenEvent, subscribe } from "../../handlers/mod.js";
|
|
|
4
4
|
import { List } from "../../utils/List.js";
|
|
5
5
|
import { newFromInvoke, newOnEvent } from "../../utils/State.js";
|
|
6
6
|
import { getCurrentWebviewWindow } from "@tauri-apps/api/webviewWindow";
|
|
7
|
-
import { decodeBase64Url } from "../../../deps/jsr.io/@std/encoding/1.0.10/
|
|
7
|
+
import { decodeBase64Url } from "../../../deps/jsr.io/@std/encoding/1.0.10/mod.js";
|
|
8
8
|
import { PhysicalPosition, PhysicalSize } from "@tauri-apps/api/dpi";
|
|
9
9
|
import { monitorFromPoint } from "@tauri-apps/api/window";
|
|
10
10
|
import { debounce } from "../../utils/async.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@seelen-ui/lib",
|
|
3
|
-
"version": "2.4.
|
|
3
|
+
"version": "2.4.8",
|
|
4
4
|
"description": "Seelen UI Library for Widgets",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -26,12 +26,13 @@
|
|
|
26
26
|
"require": "./script/src/re-exports/tauri.js"
|
|
27
27
|
}
|
|
28
28
|
},
|
|
29
|
+
"scripts": {},
|
|
29
30
|
"dependencies": {
|
|
30
|
-
"@tauri-apps/api": "^2.
|
|
31
|
-
"@tauri-apps/plugin-dialog": "^2.
|
|
32
|
-
"@tauri-apps/plugin-fs": "^2.4.
|
|
33
|
-
"@tauri-apps/plugin-log": "^2.
|
|
34
|
-
"@tauri-apps/plugin-process": "^2.3.
|
|
31
|
+
"@tauri-apps/api": "^2.9.0",
|
|
32
|
+
"@tauri-apps/plugin-dialog": "^2.4.2",
|
|
33
|
+
"@tauri-apps/plugin-fs": "^2.4.4",
|
|
34
|
+
"@tauri-apps/plugin-log": "^2.7.1",
|
|
35
|
+
"@tauri-apps/plugin-process": "^2.3.1"
|
|
35
36
|
},
|
|
36
37
|
"_generatedBy": "dnt@dev"
|
|
37
38
|
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Uint8Array_ } from "./_types.js";
|
|
2
|
+
export type { Uint8Array_ };
|
|
3
|
+
export declare const alphabet: Uint8Array<ArrayBufferLike>;
|
|
4
|
+
export declare const rAlphabet: Uint8Array<ArrayBuffer>;
|
|
5
|
+
/**
|
|
6
|
+
* Calculate the output size needed to encode a given input size for
|
|
7
|
+
* {@linkcode encodeIntoHex}.
|
|
8
|
+
*
|
|
9
|
+
* @param originalSize The size of the input buffer.
|
|
10
|
+
* @returns The size of the output buffer.
|
|
11
|
+
*
|
|
12
|
+
* @example Basic Usage
|
|
13
|
+
* ```ts
|
|
14
|
+
* import { assertEquals } from "@std/assert";
|
|
15
|
+
* import { calcSizeHex } from "@std/encoding/unstable-hex";
|
|
16
|
+
*
|
|
17
|
+
* assertEquals(calcSizeHex(1), 2);
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export declare function calcSizeHex(originalSize: number): number;
|
|
21
|
+
export declare function encode(buffer: Uint8Array_, i: number, o: number, alphabet: Uint8Array): number;
|
|
22
|
+
export declare function decode(buffer: Uint8Array_, i: number, o: number, alphabet: Uint8Array): number;
|
|
23
|
+
//# sourceMappingURL=_common16.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_common16.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/encoding/1.0.10/_common16.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,YAAY,EAAE,WAAW,EAAE,CAAC;AAE5B,eAAO,MAAM,QAAQ,6BAA+C,CAAC;AACrE,eAAO,MAAM,SAAS,yBAA+B,CAAC;AAMtD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,WAAW,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAExD;AAED,wBAAgB,MAAM,CACpB,MAAM,EAAE,WAAW,EACnB,CAAC,EAAE,MAAM,EACT,CAAC,EAAE,MAAM,EACT,QAAQ,EAAE,UAAU,GACnB,MAAM,CAOR;AAED,wBAAgB,MAAM,CACpB,MAAM,EAAE,WAAW,EACnB,CAAC,EAAE,MAAM,EACT,CAAC,EAAE,MAAM,EACT,QAAQ,EAAE,UAAU,GACnB,MAAM,CAeR"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright 2018-2025 the Deno authors. MIT license.
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.rAlphabet = exports.alphabet = void 0;
|
|
5
|
+
exports.calcSizeHex = calcSizeHex;
|
|
6
|
+
exports.encode = encode;
|
|
7
|
+
exports.decode = decode;
|
|
8
|
+
exports.alphabet = new TextEncoder().encode("0123456789abcdef");
|
|
9
|
+
exports.rAlphabet = new Uint8Array(128).fill(16); // alphabet.Hex.length
|
|
10
|
+
exports.alphabet.forEach((byte, i) => exports.rAlphabet[byte] = i);
|
|
11
|
+
new TextEncoder()
|
|
12
|
+
.encode("ABCDEF")
|
|
13
|
+
.forEach((byte, i) => exports.rAlphabet[byte] = i + 10);
|
|
14
|
+
/**
|
|
15
|
+
* Calculate the output size needed to encode a given input size for
|
|
16
|
+
* {@linkcode encodeIntoHex}.
|
|
17
|
+
*
|
|
18
|
+
* @param originalSize The size of the input buffer.
|
|
19
|
+
* @returns The size of the output buffer.
|
|
20
|
+
*
|
|
21
|
+
* @example Basic Usage
|
|
22
|
+
* ```ts
|
|
23
|
+
* import { assertEquals } from "@std/assert";
|
|
24
|
+
* import { calcSizeHex } from "@std/encoding/unstable-hex";
|
|
25
|
+
*
|
|
26
|
+
* assertEquals(calcSizeHex(1), 2);
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
function calcSizeHex(originalSize) {
|
|
30
|
+
return originalSize * 2;
|
|
31
|
+
}
|
|
32
|
+
function encode(buffer, i, o, alphabet) {
|
|
33
|
+
for (; i < buffer.length; ++i) {
|
|
34
|
+
const x = buffer[i];
|
|
35
|
+
buffer[o++] = alphabet[x >> 4];
|
|
36
|
+
buffer[o++] = alphabet[x & 0xF];
|
|
37
|
+
}
|
|
38
|
+
return o;
|
|
39
|
+
}
|
|
40
|
+
function decode(buffer, i, o, alphabet) {
|
|
41
|
+
if ((buffer.length - o) % 2 === 1) {
|
|
42
|
+
throw new RangeError(`Cannot decode input as hex: Length (${buffer.length - o}) must be divisible by 2`);
|
|
43
|
+
}
|
|
44
|
+
i += 1;
|
|
45
|
+
for (; i < buffer.length; i += 2) {
|
|
46
|
+
buffer[o++] = (getByte(buffer[i - 1], alphabet) << 4) |
|
|
47
|
+
getByte(buffer[i], alphabet);
|
|
48
|
+
}
|
|
49
|
+
return o;
|
|
50
|
+
}
|
|
51
|
+
function getByte(char, alphabet) {
|
|
52
|
+
const byte = alphabet[char] ?? 16;
|
|
53
|
+
if (byte === 16) { // alphabet.Hex.length
|
|
54
|
+
throw new TypeError(`Cannot decode input as hex: Invalid character (${String.fromCharCode(char)})`);
|
|
55
|
+
}
|
|
56
|
+
return byte;
|
|
57
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { Uint8Array_ } from "./_types.js";
|
|
2
|
+
export type { Uint8Array_ };
|
|
3
|
+
export declare const padding: number;
|
|
4
|
+
export declare const alphabet: Record<Base32Alphabet, Uint8Array>;
|
|
5
|
+
export declare const rAlphabet: Record<Base32Alphabet, Uint8Array>;
|
|
6
|
+
/**
|
|
7
|
+
* Options for encoding and decoding base32 strings.
|
|
8
|
+
*/
|
|
9
|
+
export interface Base32Options {
|
|
10
|
+
/** The base32 alphabet. Defaults to "base32" */
|
|
11
|
+
alphabet?: Base32Alphabet;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* The base32 alphabets.
|
|
15
|
+
*/
|
|
16
|
+
export type Base32Alphabet = "base32" | "base32hex" | "base32crockford";
|
|
17
|
+
/**
|
|
18
|
+
* Calculate the output size needed to encode a given input size for
|
|
19
|
+
* {@linkcode encodeIntoBase32}.
|
|
20
|
+
*
|
|
21
|
+
* @param rawSize The size of the input buffer.
|
|
22
|
+
* @returns The size of the output buffer.
|
|
23
|
+
*
|
|
24
|
+
* @example Basic Usage
|
|
25
|
+
* ```ts
|
|
26
|
+
* import { assertEquals } from "@std/assert";
|
|
27
|
+
* import { calcSizeBase32 } from "@std/encoding/unstable-base32";
|
|
28
|
+
*
|
|
29
|
+
* assertEquals(calcSizeBase32(1), 8);
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export declare function calcSizeBase32(rawSize: number): number;
|
|
33
|
+
export declare function encode(buffer: Uint8Array_, i: number, o: number, alphabet: Uint8Array, padding: number): number;
|
|
34
|
+
export declare function decode(buffer: Uint8Array_, i: number, o: number, alphabet: Uint8Array, padding: number): number;
|
|
35
|
+
//# sourceMappingURL=_common32.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_common32.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/encoding/1.0.10/_common32.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,YAAY,EAAE,WAAW,EAAE,CAAC;AAE5B,eAAO,MAAM,OAAO,QAAoB,CAAC;AACzC,eAAO,MAAM,QAAQ,EAAE,MAAM,CAAC,cAAc,EAAE,UAAU,CAIvD,CAAC;AACF,eAAO,MAAM,SAAS,EAAE,MAAM,CAAC,cAAc,EAAE,UAAU,CAIxD,CAAC;AAQF;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,gDAAgD;IAChD,QAAQ,CAAC,EAAE,cAAc,CAAC;CAC3B;AAED;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,QAAQ,GAAG,WAAW,GAAG,iBAAiB,CAAC;AAExE;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAEtD;AAED,wBAAgB,MAAM,CACpB,MAAM,EAAE,WAAW,EACnB,CAAC,EAAE,MAAM,EACT,CAAC,EAAE,MAAM,EACT,QAAQ,EAAE,UAAU,EACpB,OAAO,EAAE,MAAM,GACd,MAAM,CAmER;AAED,wBAAgB,MAAM,CACpB,MAAM,EAAE,WAAW,EACnB,CAAC,EAAE,MAAM,EACT,CAAC,EAAE,MAAM,EACT,QAAQ,EAAE,UAAU,EACpB,OAAO,EAAE,MAAM,GACd,MAAM,CAyFR"}
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright 2018-2025 the Deno authors. MIT license.
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.rAlphabet = exports.alphabet = exports.padding = void 0;
|
|
5
|
+
exports.calcSizeBase32 = calcSizeBase32;
|
|
6
|
+
exports.encode = encode;
|
|
7
|
+
exports.decode = decode;
|
|
8
|
+
exports.padding = "=".charCodeAt(0);
|
|
9
|
+
exports.alphabet = {
|
|
10
|
+
base32: new TextEncoder().encode("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"),
|
|
11
|
+
base32hex: new TextEncoder().encode("0123456789ABCDEFGHIJKLMNOPQRSTUV"),
|
|
12
|
+
base32crockford: new TextEncoder().encode("0123456789ABCDEFGHJKMNPQRSTVWXYZ"),
|
|
13
|
+
};
|
|
14
|
+
exports.rAlphabet = {
|
|
15
|
+
base32: new Uint8Array(128).fill(32), // alphabet.base32.length
|
|
16
|
+
base32hex: new Uint8Array(128).fill(32),
|
|
17
|
+
base32crockford: new Uint8Array(128).fill(32),
|
|
18
|
+
};
|
|
19
|
+
exports.alphabet.base32
|
|
20
|
+
.forEach((byte, i) => exports.rAlphabet.base32[byte] = i);
|
|
21
|
+
exports.alphabet.base32hex
|
|
22
|
+
.forEach((byte, i) => exports.rAlphabet.base32hex[byte] = i);
|
|
23
|
+
exports.alphabet.base32crockford
|
|
24
|
+
.forEach((byte, i) => exports.rAlphabet.base32crockford[byte] = i);
|
|
25
|
+
/**
|
|
26
|
+
* Calculate the output size needed to encode a given input size for
|
|
27
|
+
* {@linkcode encodeIntoBase32}.
|
|
28
|
+
*
|
|
29
|
+
* @param rawSize The size of the input buffer.
|
|
30
|
+
* @returns The size of the output buffer.
|
|
31
|
+
*
|
|
32
|
+
* @example Basic Usage
|
|
33
|
+
* ```ts
|
|
34
|
+
* import { assertEquals } from "@std/assert";
|
|
35
|
+
* import { calcSizeBase32 } from "@std/encoding/unstable-base32";
|
|
36
|
+
*
|
|
37
|
+
* assertEquals(calcSizeBase32(1), 8);
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
function calcSizeBase32(rawSize) {
|
|
41
|
+
return ((rawSize + 4) / 5 | 0) * 8;
|
|
42
|
+
}
|
|
43
|
+
function encode(buffer, i, o, alphabet, padding) {
|
|
44
|
+
i += 4;
|
|
45
|
+
for (; i < buffer.length; i += 5) {
|
|
46
|
+
let x = (buffer[i - 4] << 16) | (buffer[i - 3] << 8) | buffer[i - 2];
|
|
47
|
+
buffer[o++] = alphabet[x >> 19];
|
|
48
|
+
buffer[o++] = alphabet[x >> 14 & 0x1F];
|
|
49
|
+
buffer[o++] = alphabet[x >> 9 & 0x1F];
|
|
50
|
+
buffer[o++] = alphabet[x >> 4 & 0x1F];
|
|
51
|
+
x = (x << 16) | (buffer[i - 1] << 8) | buffer[i];
|
|
52
|
+
buffer[o++] = alphabet[x >> 15 & 0x1F];
|
|
53
|
+
buffer[o++] = alphabet[x >> 10 & 0x1F];
|
|
54
|
+
buffer[o++] = alphabet[x >> 5 & 0x1F];
|
|
55
|
+
buffer[o++] = alphabet[x & 0x1F];
|
|
56
|
+
}
|
|
57
|
+
switch (i) {
|
|
58
|
+
case buffer.length + 3: {
|
|
59
|
+
const x = buffer[i - 4] << 16;
|
|
60
|
+
buffer[o++] = alphabet[x >> 19];
|
|
61
|
+
buffer[o++] = alphabet[x >> 14 & 0x1F];
|
|
62
|
+
buffer[o++] = padding;
|
|
63
|
+
buffer[o++] = padding;
|
|
64
|
+
buffer[o++] = padding;
|
|
65
|
+
buffer[o++] = padding;
|
|
66
|
+
buffer[o++] = padding;
|
|
67
|
+
buffer[o++] = padding;
|
|
68
|
+
break;
|
|
69
|
+
}
|
|
70
|
+
case buffer.length + 2: {
|
|
71
|
+
const x = (buffer[i - 4] << 16) | (buffer[i - 3] << 8);
|
|
72
|
+
buffer[o++] = alphabet[x >> 19];
|
|
73
|
+
buffer[o++] = alphabet[x >> 14 & 0x1F];
|
|
74
|
+
buffer[o++] = alphabet[x >> 9 & 0x1F];
|
|
75
|
+
buffer[o++] = alphabet[x >> 4 & 0x1F];
|
|
76
|
+
buffer[o++] = padding;
|
|
77
|
+
buffer[o++] = padding;
|
|
78
|
+
buffer[o++] = padding;
|
|
79
|
+
buffer[o++] = padding;
|
|
80
|
+
break;
|
|
81
|
+
}
|
|
82
|
+
case buffer.length + 1: {
|
|
83
|
+
let x = (buffer[i - 4] << 16) | (buffer[i - 3] << 8) | buffer[i - 2];
|
|
84
|
+
buffer[o++] = alphabet[x >> 19];
|
|
85
|
+
buffer[o++] = alphabet[x >> 14 & 0x1F];
|
|
86
|
+
buffer[o++] = alphabet[x >> 9 & 0x1F];
|
|
87
|
+
buffer[o++] = alphabet[x >> 4 & 0x1F];
|
|
88
|
+
x <<= 16;
|
|
89
|
+
buffer[o++] = alphabet[x >> 15 & 0x1F];
|
|
90
|
+
buffer[o++] = padding;
|
|
91
|
+
buffer[o++] = padding;
|
|
92
|
+
buffer[o++] = padding;
|
|
93
|
+
break;
|
|
94
|
+
}
|
|
95
|
+
case buffer.length: {
|
|
96
|
+
let x = (buffer[i - 4] << 16) | (buffer[i - 3] << 8) | buffer[i - 2];
|
|
97
|
+
buffer[o++] = alphabet[x >> 19];
|
|
98
|
+
buffer[o++] = alphabet[x >> 14 & 0x1F];
|
|
99
|
+
buffer[o++] = alphabet[x >> 9 & 0x1F];
|
|
100
|
+
buffer[o++] = alphabet[x >> 4 & 0x1F];
|
|
101
|
+
x = (x << 16) | (buffer[i - 1] << 8);
|
|
102
|
+
buffer[o++] = alphabet[x >> 15 & 0x1F];
|
|
103
|
+
buffer[o++] = alphabet[x >> 10 & 0x1F];
|
|
104
|
+
buffer[o++] = alphabet[x >> 5 & 0x1F];
|
|
105
|
+
buffer[o++] = padding;
|
|
106
|
+
break;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return o;
|
|
110
|
+
}
|
|
111
|
+
function decode(buffer, i, o, alphabet, padding) {
|
|
112
|
+
for (let x = buffer.length - 6; x < buffer.length; ++x) {
|
|
113
|
+
if (buffer[x] === padding) {
|
|
114
|
+
for (let y = x + 1; y < buffer.length; ++y) {
|
|
115
|
+
if (buffer[y] !== padding) {
|
|
116
|
+
throw new TypeError(`Cannot decode input as base32: Invalid character (${String.fromCharCode(buffer[y])})`);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
buffer = buffer.subarray(0, x);
|
|
120
|
+
break;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
switch ((buffer.length - o) % 8) {
|
|
124
|
+
case 6:
|
|
125
|
+
case 3:
|
|
126
|
+
case 1:
|
|
127
|
+
throw new RangeError(`Cannot decode input as base32: Length (${buffer.length - o}), excluding padding, must not have a remainder of 1, 3, or 6 when divided by 8`);
|
|
128
|
+
}
|
|
129
|
+
i += 7;
|
|
130
|
+
for (; i < buffer.length; i += 8) {
|
|
131
|
+
let x = (getByte(buffer[i - 7], alphabet) << 19) |
|
|
132
|
+
(getByte(buffer[i - 6], alphabet) << 14) |
|
|
133
|
+
(getByte(buffer[i - 5], alphabet) << 9) |
|
|
134
|
+
(getByte(buffer[i - 4], alphabet) << 4);
|
|
135
|
+
buffer[o++] = x >> 16;
|
|
136
|
+
buffer[o++] = x >> 8 & 0xFF;
|
|
137
|
+
x = (x << 16) |
|
|
138
|
+
(getByte(buffer[i - 3], alphabet) << 15) |
|
|
139
|
+
(getByte(buffer[i - 2], alphabet) << 10) |
|
|
140
|
+
(getByte(buffer[i - 1], alphabet) << 5) |
|
|
141
|
+
getByte(buffer[i], alphabet);
|
|
142
|
+
buffer[o++] = x >> 16 & 0xFF;
|
|
143
|
+
buffer[o++] = x >> 8 & 0xFF;
|
|
144
|
+
buffer[o++] = x & 0xFF;
|
|
145
|
+
}
|
|
146
|
+
switch (i) {
|
|
147
|
+
case buffer.length + 5: {
|
|
148
|
+
const x = (getByte(buffer[i - 7], alphabet) << 19) |
|
|
149
|
+
(getByte(buffer[i - 6], alphabet) << 14);
|
|
150
|
+
buffer[o++] = x >> 16;
|
|
151
|
+
break;
|
|
152
|
+
}
|
|
153
|
+
case buffer.length + 3: {
|
|
154
|
+
const x = (getByte(buffer[i - 7], alphabet) << 19) |
|
|
155
|
+
(getByte(buffer[i - 6], alphabet) << 14) |
|
|
156
|
+
(getByte(buffer[i - 5], alphabet) << 9) |
|
|
157
|
+
(getByte(buffer[i - 4], alphabet) << 4);
|
|
158
|
+
buffer[o++] = x >> 16;
|
|
159
|
+
buffer[o++] = x >> 8 & 0xFF;
|
|
160
|
+
break;
|
|
161
|
+
}
|
|
162
|
+
case buffer.length + 2: {
|
|
163
|
+
let x = (getByte(buffer[i - 7], alphabet) << 19) |
|
|
164
|
+
(getByte(buffer[i - 6], alphabet) << 14) |
|
|
165
|
+
(getByte(buffer[i - 5], alphabet) << 9) |
|
|
166
|
+
(getByte(buffer[i - 4], alphabet) << 4);
|
|
167
|
+
buffer[o++] = x >> 16;
|
|
168
|
+
buffer[o++] = x >> 8 & 0xFF;
|
|
169
|
+
x = (x << 16) |
|
|
170
|
+
(getByte(buffer[i - 3], alphabet) << 15);
|
|
171
|
+
buffer[o++] = x >> 16 & 0xFF;
|
|
172
|
+
break;
|
|
173
|
+
}
|
|
174
|
+
case buffer.length: {
|
|
175
|
+
let x = (getByte(buffer[i - 7], alphabet) << 19) |
|
|
176
|
+
(getByte(buffer[i - 6], alphabet) << 14) |
|
|
177
|
+
(getByte(buffer[i - 5], alphabet) << 9) |
|
|
178
|
+
(getByte(buffer[i - 4], alphabet) << 4);
|
|
179
|
+
buffer[o++] = x >> 16;
|
|
180
|
+
buffer[o++] = x >> 8 & 0xFF;
|
|
181
|
+
x = (x << 16) |
|
|
182
|
+
(getByte(buffer[i - 3], alphabet) << 15) |
|
|
183
|
+
(getByte(buffer[i - 2], alphabet) << 10) |
|
|
184
|
+
(getByte(buffer[i - 1], alphabet) << 5);
|
|
185
|
+
buffer[o++] = x >> 16 & 0xFF;
|
|
186
|
+
buffer[o++] = x >> 8 & 0xFF;
|
|
187
|
+
break;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
return o;
|
|
191
|
+
}
|
|
192
|
+
function getByte(char, alphabet) {
|
|
193
|
+
const byte = alphabet[char] ?? 32;
|
|
194
|
+
if (byte === 32) { // alphabet.Base32.length
|
|
195
|
+
throw new TypeError(`Cannot decode input as base32: Invalid character (${String.fromCharCode(char)})`);
|
|
196
|
+
}
|
|
197
|
+
return byte;
|
|
198
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_validate_binary_like.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/encoding/1.0.10/_validate_binary_like.ts"],"names":[],"mappings":"AAeA,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,OAAO,GAAG,UAAU,CAa9D"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright 2018-2025 the Deno authors. MIT license.
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.validateBinaryLike = validateBinaryLike;
|
|
5
|
+
const encoder = new TextEncoder();
|
|
6
|
+
function getTypeName(value) {
|
|
7
|
+
const type = typeof value;
|
|
8
|
+
if (type !== "object") {
|
|
9
|
+
return type;
|
|
10
|
+
}
|
|
11
|
+
else if (value === null) {
|
|
12
|
+
return "null";
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
return value?.constructor?.name ?? "object";
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
function validateBinaryLike(source) {
|
|
19
|
+
if (typeof source === "string") {
|
|
20
|
+
return encoder.encode(source);
|
|
21
|
+
}
|
|
22
|
+
else if (source instanceof Uint8Array) {
|
|
23
|
+
return source;
|
|
24
|
+
}
|
|
25
|
+
else if (source instanceof ArrayBuffer) {
|
|
26
|
+
return new Uint8Array(source);
|
|
27
|
+
}
|
|
28
|
+
throw new TypeError(`Cannot validate the input as it must be a Uint8Array, a string, or an ArrayBuffer: received a value of the type ${getTypeName(source)}`);
|
|
29
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { Uint8Array_ } from "./_types.js";
|
|
2
|
+
export type { Uint8Array_ };
|
|
3
|
+
/**
|
|
4
|
+
* Supported ascii85 standards for {@linkcode EncodeAscii85Options} and
|
|
5
|
+
* {@linkcode DecodeAscii85Options}.
|
|
6
|
+
*/
|
|
7
|
+
export type Ascii85Standard = "Adobe" | "btoa" | "RFC 1924" | "Z85";
|
|
8
|
+
/** Options for {@linkcode encodeAscii85}. */
|
|
9
|
+
export interface EncodeAscii85Options {
|
|
10
|
+
/**
|
|
11
|
+
* Character set and delimiter (if supported and used).
|
|
12
|
+
*
|
|
13
|
+
* @default {"Adobe"}
|
|
14
|
+
*/
|
|
15
|
+
standard?: Ascii85Standard;
|
|
16
|
+
/**
|
|
17
|
+
* Whether to use a delimiter (if supported).
|
|
18
|
+
*
|
|
19
|
+
* @default {false}
|
|
20
|
+
*/
|
|
21
|
+
delimiter?: boolean;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Converts data into an ascii85-encoded string.
|
|
25
|
+
*
|
|
26
|
+
* @param data The data to encode.
|
|
27
|
+
* @param options Options for encoding.
|
|
28
|
+
*
|
|
29
|
+
* @returns The ascii85-encoded string.
|
|
30
|
+
*
|
|
31
|
+
* @example Usage
|
|
32
|
+
* ```ts
|
|
33
|
+
* import { encodeAscii85 } from "@std/encoding/ascii85";
|
|
34
|
+
* import { assertEquals } from "@std/assert";
|
|
35
|
+
*
|
|
36
|
+
* assertEquals(encodeAscii85("Hello world!"), "87cURD]j7BEbo80");
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export declare function encodeAscii85(data: ArrayBuffer | Uint8Array | string, options?: EncodeAscii85Options): string;
|
|
40
|
+
/** Options for {@linkcode decodeAscii85}. */
|
|
41
|
+
export type DecodeAscii85Options = Omit<EncodeAscii85Options, "delimiter">;
|
|
42
|
+
/**
|
|
43
|
+
* Decodes a ascii85-encoded string.
|
|
44
|
+
*
|
|
45
|
+
* @param ascii85 The ascii85-encoded string to decode.
|
|
46
|
+
* @param options Options for decoding.
|
|
47
|
+
* @returns The decoded data.
|
|
48
|
+
*
|
|
49
|
+
* @example Usage
|
|
50
|
+
* ```ts
|
|
51
|
+
* import { decodeAscii85 } from "@std/encoding/ascii85";
|
|
52
|
+
* import { assertEquals } from "@std/assert";
|
|
53
|
+
*
|
|
54
|
+
* assertEquals(
|
|
55
|
+
* decodeAscii85("87cURD]j7BEbo80"),
|
|
56
|
+
* new TextEncoder().encode("Hello world!"),
|
|
57
|
+
* );
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
export declare function decodeAscii85(ascii85: string, options?: DecodeAscii85Options): Uint8Array_;
|
|
61
|
+
//# sourceMappingURL=ascii85.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ascii85.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/encoding/1.0.10/ascii85.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,YAAY,EAAE,WAAW,EAAE,CAAC;AAwB5B;;;GAGG;AACH,MAAM,MAAM,eAAe,GAAG,OAAO,GAAG,MAAM,GAAG,UAAU,GAAG,KAAK,CAAC;AAEpE,6CAA6C;AAC7C,MAAM,WAAW,oBAAoB;IACnC;;;;OAIG;IACH,QAAQ,CAAC,EAAE,eAAe,CAAC;IAC3B;;;;OAIG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAOD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,aAAa,CAC3B,IAAI,EAAE,WAAW,GAAG,UAAU,GAAG,MAAM,EACvC,OAAO,GAAE,oBAAyB,GACjC,MAAM,CA6DR;AAED,6CAA6C;AAC7C,MAAM,MAAM,oBAAoB,GAAG,IAAI,CAAC,oBAAoB,EAAE,WAAW,CAAC,CAAC;AAE3E;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,aAAa,CAC3B,OAAO,EAAE,MAAM,EACf,OAAO,GAAE,oBAAyB,GACjC,WAAW,CA4Cb"}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright 2018-2025 the Deno authors. MIT license.
|
|
3
|
+
// This module is browser compatible.
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.encodeAscii85 = encodeAscii85;
|
|
6
|
+
exports.decodeAscii85 = decodeAscii85;
|
|
7
|
+
/**
|
|
8
|
+
* Utilities for working with {@link https://en.wikipedia.org/wiki/Ascii85 | ascii85} encoding.
|
|
9
|
+
*
|
|
10
|
+
* ## Specifying a standard and delimiter
|
|
11
|
+
*
|
|
12
|
+
* By default, all functions are using the most popular Adobe version of ascii85
|
|
13
|
+
* and not adding any delimiter. However, there are three more standards
|
|
14
|
+
* supported - btoa (different delimiter and additional compression of 4 bytes
|
|
15
|
+
* equal to 32), {@link https://rfc.zeromq.org/spec/32/ | Z85} and
|
|
16
|
+
* {@link https://www.rfc-editor.org/rfc/rfc1924.html | RFC 1924}. It's possible to use a
|
|
17
|
+
* different encoding by specifying it in `options` object as a second parameter.
|
|
18
|
+
*
|
|
19
|
+
* Similarly, it's possible to make `encode` add a delimiter (`<~` and `~>` for
|
|
20
|
+
* Adobe, `xbtoa Begin` and `xbtoa End` with newlines between the delimiters and
|
|
21
|
+
* encoded data for btoa. Checksums for btoa are not supported. Delimiters are not
|
|
22
|
+
* supported by other encodings.)
|
|
23
|
+
*
|
|
24
|
+
* @module
|
|
25
|
+
*/
|
|
26
|
+
const _validate_binary_like_js_1 = require("./_validate_binary_like.js");
|
|
27
|
+
const rfc1924 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!#$%&()*+-;<=>?@^_`{|}~";
|
|
28
|
+
const Z85 = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.-:+=^!/*?&<>()[]{}@%$#";
|
|
29
|
+
/**
|
|
30
|
+
* Converts data into an ascii85-encoded string.
|
|
31
|
+
*
|
|
32
|
+
* @param data The data to encode.
|
|
33
|
+
* @param options Options for encoding.
|
|
34
|
+
*
|
|
35
|
+
* @returns The ascii85-encoded string.
|
|
36
|
+
*
|
|
37
|
+
* @example Usage
|
|
38
|
+
* ```ts
|
|
39
|
+
* import { encodeAscii85 } from "@std/encoding/ascii85";
|
|
40
|
+
* import { assertEquals } from "@std/assert";
|
|
41
|
+
*
|
|
42
|
+
* assertEquals(encodeAscii85("Hello world!"), "87cURD]j7BEbo80");
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
function encodeAscii85(data, options = {}) {
|
|
46
|
+
let uint8 = (0, _validate_binary_like_js_1.validateBinaryLike)(data);
|
|
47
|
+
const { standard = "Adobe" } = options;
|
|
48
|
+
let output = [];
|
|
49
|
+
let v;
|
|
50
|
+
let n = 0;
|
|
51
|
+
let difference = 0;
|
|
52
|
+
if (uint8.length % 4 !== 0) {
|
|
53
|
+
const tmp = uint8;
|
|
54
|
+
difference = 4 - (tmp.length % 4);
|
|
55
|
+
uint8 = new Uint8Array(tmp.length + difference);
|
|
56
|
+
uint8.set(tmp);
|
|
57
|
+
}
|
|
58
|
+
const view = new DataView(uint8.buffer, uint8.byteOffset, uint8.byteLength);
|
|
59
|
+
for (let i = 0; i < uint8.length; i += 4) {
|
|
60
|
+
v = view.getUint32(i);
|
|
61
|
+
// Adobe and btoa standards compress 4 zeroes to single "z" character
|
|
62
|
+
if ((standard === "Adobe" || standard === "btoa") &&
|
|
63
|
+
v === 0 &&
|
|
64
|
+
i < uint8.length - difference - 3) {
|
|
65
|
+
output[n++] = "z";
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
// btoa compresses 4 spaces - that is, bytes equal to 32 - into single "y" character
|
|
69
|
+
if (standard === "btoa" && v === 538976288) {
|
|
70
|
+
output[n++] = "y";
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
for (let j = 4; j >= 0; j--) {
|
|
74
|
+
output[n + j] = String.fromCharCode((v % 85) + 33);
|
|
75
|
+
v = Math.trunc(v / 85);
|
|
76
|
+
}
|
|
77
|
+
n += 5;
|
|
78
|
+
}
|
|
79
|
+
switch (standard) {
|
|
80
|
+
case "Adobe":
|
|
81
|
+
if (options?.delimiter) {
|
|
82
|
+
return `<~${output.slice(0, output.length - difference).join("")}~>`;
|
|
83
|
+
}
|
|
84
|
+
break;
|
|
85
|
+
case "btoa":
|
|
86
|
+
if (options?.delimiter) {
|
|
87
|
+
return `xbtoa Begin\n${output
|
|
88
|
+
.slice(0, output.length - difference)
|
|
89
|
+
.join("")}\nxbtoa End`;
|
|
90
|
+
}
|
|
91
|
+
break;
|
|
92
|
+
case "RFC 1924":
|
|
93
|
+
output = output.map((val) => rfc1924[val.charCodeAt(0) - 33]);
|
|
94
|
+
break;
|
|
95
|
+
case "Z85":
|
|
96
|
+
output = output.map((val) => Z85[val.charCodeAt(0) - 33]);
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
return output.slice(0, output.length - difference).join("");
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Decodes a ascii85-encoded string.
|
|
103
|
+
*
|
|
104
|
+
* @param ascii85 The ascii85-encoded string to decode.
|
|
105
|
+
* @param options Options for decoding.
|
|
106
|
+
* @returns The decoded data.
|
|
107
|
+
*
|
|
108
|
+
* @example Usage
|
|
109
|
+
* ```ts
|
|
110
|
+
* import { decodeAscii85 } from "@std/encoding/ascii85";
|
|
111
|
+
* import { assertEquals } from "@std/assert";
|
|
112
|
+
*
|
|
113
|
+
* assertEquals(
|
|
114
|
+
* decodeAscii85("87cURD]j7BEbo80"),
|
|
115
|
+
* new TextEncoder().encode("Hello world!"),
|
|
116
|
+
* );
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
119
|
+
function decodeAscii85(ascii85, options = {}) {
|
|
120
|
+
const { standard = "Adobe" } = options;
|
|
121
|
+
// translate all encodings to most basic adobe/btoa one and decompress some special characters ("z" and "y")
|
|
122
|
+
switch (standard) {
|
|
123
|
+
case "Adobe":
|
|
124
|
+
ascii85 = ascii85.replaceAll(/(<~|~>)/g, "").replaceAll("z", "!!!!!");
|
|
125
|
+
break;
|
|
126
|
+
case "btoa":
|
|
127
|
+
ascii85 = ascii85
|
|
128
|
+
.replaceAll(/(xbtoa Begin|xbtoa End|\n)/g, "")
|
|
129
|
+
.replaceAll("z", "!!!!!")
|
|
130
|
+
.replaceAll("y", "+<VdL");
|
|
131
|
+
break;
|
|
132
|
+
case "RFC 1924":
|
|
133
|
+
ascii85 = ascii85.replaceAll(/./g, (match) => String.fromCharCode(rfc1924.indexOf(match) + 33));
|
|
134
|
+
break;
|
|
135
|
+
case "Z85":
|
|
136
|
+
ascii85 = ascii85.replaceAll(/./g, (match) => String.fromCharCode(Z85.indexOf(match) + 33));
|
|
137
|
+
break;
|
|
138
|
+
}
|
|
139
|
+
// remove all invalid characters
|
|
140
|
+
ascii85 = ascii85.replaceAll(/[^!-u]/g, "");
|
|
141
|
+
const len = ascii85.length;
|
|
142
|
+
const output = new Uint8Array(len + 4 - (len % 4));
|
|
143
|
+
const view = new DataView(output.buffer);
|
|
144
|
+
let v = 0;
|
|
145
|
+
let n = 0;
|
|
146
|
+
let max = 0;
|
|
147
|
+
for (let i = 0; i < len;) {
|
|
148
|
+
for (max += 5; i < max; i++) {
|
|
149
|
+
v = v * 85 + (i < len ? ascii85.charCodeAt(i) : 117) - 33;
|
|
150
|
+
}
|
|
151
|
+
view.setUint32(n, v);
|
|
152
|
+
v = 0;
|
|
153
|
+
n += 4;
|
|
154
|
+
}
|
|
155
|
+
return output.slice(0, Math.trunc(len * 0.8));
|
|
156
|
+
}
|