@ssebastien/tcmd 0.1.3 → 0.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +256 -62
- package/bin/tcmd +10 -2
- package/bin/tcmd.js +13 -2
- package/desktop/dist/index.html +13 -0
- package/desktop/dist/main.js +20298 -0
- package/desktop/dist/style.css +1515 -0
- package/desktop/frontend/index.html +13 -0
- package/package.json +19 -6
- package/public/fonts/OFL.txt +93 -0
- package/public/index.html +14 -0
- package/public/licenses/LUCIDE.txt +43 -0
- package/public/main.js +20679 -0
- package/public/style.css +1515 -0
- package/scripts/build-desktop.js +31 -0
- package/scripts/serve-web.js +61 -0
- package/src/js/tcmd/components/App.html +80 -14
- package/src/js/tcmd/components/App.js +339 -114
- package/src/js/tcmd/components/App.xml +76 -22
- package/src/js/tcmd/components/BookmarkList.html +5 -5
- package/src/js/tcmd/components/BookmarkList.js +15 -41
- package/src/js/tcmd/components/BookmarkList.xml +1 -2
- package/src/js/tcmd/components/BookmarkRow.html +2 -1
- package/src/js/tcmd/components/BookmarkRow.js +14 -9
- package/src/js/tcmd/components/BookmarkRow.xml +1 -1
- package/src/js/tcmd/components/Breadcrumbs.js +1 -1
- package/src/js/tcmd/components/CommandArgRow.html +28 -0
- package/src/js/tcmd/components/CommandArgRow.js +146 -30
- package/src/js/tcmd/components/CommandArgRow.xml +55 -4
- package/src/js/tcmd/components/CommandBar.html +2 -2
- package/src/js/tcmd/components/CommandBar.js +33 -27
- package/src/js/tcmd/components/CommandBar.xml +2 -2
- package/src/js/tcmd/components/CommandItem.html +1 -1
- package/src/js/tcmd/components/CommandItem.js +25 -25
- package/src/js/tcmd/components/CommandItem.xml +2 -2
- package/src/js/tcmd/components/CommandPanel.html +29 -0
- package/src/js/tcmd/components/CommandPanel.js +78 -52
- package/src/js/tcmd/components/CommandPanel.xml +49 -25
- package/src/js/tcmd/components/Confirm.html +2 -2
- package/src/js/tcmd/components/EntryDetail.html +7 -7
- package/src/js/tcmd/components/EntryDetail.js +22 -8
- package/src/js/tcmd/components/FileList.html +5 -1
- package/src/js/tcmd/components/FileList.js +2 -1
- package/src/js/tcmd/components/FilePicker.html +10 -0
- package/src/js/tcmd/components/FilePicker.js +43 -0
- package/src/js/tcmd/components/FilePicker.xml +13 -0
- package/src/js/tcmd/components/FilePickerRow.html +6 -0
- package/src/js/tcmd/components/FilePickerRow.js +27 -0
- package/src/js/tcmd/components/FilePickerRow.xml +10 -0
- package/src/js/tcmd/components/FilePreview.html +14 -4
- package/src/js/tcmd/components/FilePreview.js +111 -12
- package/src/js/tcmd/components/FilePreview.xml +28 -8
- package/src/js/tcmd/components/FileRow.html +2 -1
- package/src/js/tcmd/components/FileRow.js +70 -12
- package/src/js/tcmd/components/FilterBar.html +1 -1
- package/src/js/tcmd/components/FilterBar.js +14 -4
- package/src/js/tcmd/components/FilterBar.xml +1 -1
- package/src/js/tcmd/components/Frame.js +324 -0
- package/src/js/tcmd/components/Help.html +15 -0
- package/src/js/tcmd/components/Help.js +260 -0
- package/src/js/tcmd/components/Help.xml +13 -4
- package/src/js/tcmd/components/HelpRow.html +8 -0
- package/src/js/tcmd/components/HelpRow.xml +7 -0
- package/src/js/tcmd/components/OverlayList.html +8 -0
- package/src/js/tcmd/components/OverlayList.js +69 -0
- package/src/js/tcmd/components/{CommandPalette.xml → OverlayList.xml} +2 -5
- package/src/js/tcmd/components/OverlayRow.html +5 -0
- package/src/js/tcmd/components/OverlayRow.js +47 -0
- package/src/js/tcmd/components/OverlayRow.xml +9 -0
- package/src/js/tcmd/components/Summary.html +1 -1
- package/src/js/tcmd/components/Summary.js +1 -6
- package/src/js/tcmd/components/format.js +4 -23
- package/src/js/tcmd/components/icons.js +176 -5
- package/src/js/tcmd/components/index.js +9 -5
- package/src/js/tcmd/components/rows.js +176 -48
- package/src/js/tcmd/core/base64.js +64 -0
- package/src/js/tcmd/core/bookmarks.js +45 -8
- package/src/js/tcmd/core/commands.js +978 -260
- package/src/js/tcmd/core/concurrency.js +59 -0
- package/src/js/tcmd/core/decompress.js +117 -0
- package/src/js/tcmd/core/directory.js +219 -93
- package/src/js/tcmd/core/format.js +36 -0
- package/src/js/tcmd/core/fs.js +438 -54
- package/src/js/tcmd/core/history.js +58 -0
- package/src/js/tcmd/core/index.js +3 -9
- package/src/js/tcmd/core/journal.js +93 -0
- package/src/js/tcmd/core/keymap.js +42 -6
- package/src/js/tcmd/core/operations.js +813 -48
- package/src/js/tcmd/core/os.js +29 -3
- package/src/js/tcmd/core/pane.js +33 -8
- package/src/js/tcmd/core/panel.js +280 -104
- package/src/js/tcmd/core/path.js +30 -3
- package/src/js/tcmd/core/permissions.js +107 -0
- package/src/js/tcmd/core/picker.js +156 -0
- package/src/js/tcmd/core/preview.js +102 -0
- package/src/js/tcmd/core/script.js +7 -95
- package/src/js/tcmd/core/selection.js +9 -1
- package/src/js/tcmd/core/session.js +498 -200
- package/src/js/tcmd/core/watch.js +153 -0
- package/src/js/tcmd/desktop/backend/api.js +165 -0
- package/src/js/tcmd/desktop/backend/fs.js +626 -0
- package/src/js/tcmd/desktop/backend/main.ts +9 -0
- package/src/js/tcmd/desktop/bookmarks.js +23 -0
- package/src/js/tcmd/desktop/fs.js +91 -0
- package/src/js/tcmd/desktop/main.js +194 -0
- package/src/js/tcmd/desktop/os.js +33 -0
- package/src/js/tcmd/index.js +0 -1
- package/src/js/tcmd/tui/app.js +118 -60
- package/src/js/tcmd/tui/catalogue.js +238 -42
- package/src/js/tcmd/tui/index.js +18 -19
- package/src/js/tcmd/tui/opentui.js +33 -0
- package/src/js/tcmd/tui/syntax.js +91 -0
- package/src/js/tcmd/tui/theme.js +32 -2
- package/src/js/tcmd/vendor/bzip2.js +276 -0
- package/src/js/tcmd/web/app.js +225 -41
- package/src/js/tcmd/web/bookmarks.js +36 -0
- package/src/js/tcmd/web/catalogue.js +81 -38
- package/src/js/tcmd/web/effects.js +223 -0
- package/src/js/tcmd/web/header.html +1 -1
- package/src/js/tcmd/web/header.js +15 -11
- package/src/js/tcmd/web/http.js +13 -0
- package/src/js/tcmd/web/index.js +2 -2
- package/src/js/tcmd/web/main.js +6 -66
- package/src/js/tcmd/web/opfs.js +297 -30
- package/src/js/tcmd/web/seed.js +4 -4
- package/src/js/tcmd/web/server.js +124 -21
- package/src/js/tcmd/web/theme.js +4 -0
- package/tinyjs.json +16 -0
- package/src/js/tcmd/components/CommandPalette.html +0 -7
- package/src/js/tcmd/components/CommandPalette.js +0 -58
- package/src/js/tcmd/components/PaletteRow.html +0 -3
- package/src/js/tcmd/components/PaletteRow.js +0 -43
- package/src/js/tcmd/components/PaletteRow.xml +0 -4
- package/src/js/tcmd/tui/frame.js +0 -269
- package/src/js/tcmd/tui/help.js +0 -32
package/src/js/tcmd/tui/theme.js
CHANGED
|
@@ -23,11 +23,16 @@
|
|
|
23
23
|
// from the cursor alone.
|
|
24
24
|
// - Text: primary, secondary (hints) and heading (titles/breadcrumbs).
|
|
25
25
|
// - Borders: secondary (pane box borders, header rules, active/inactive) and
|
|
26
|
-
// primary (the frame and the modal overlays).
|
|
26
|
+
// primary (the frame and the modal overlays). The active pane's
|
|
27
|
+
// border and head rule follow the view mode: the Tiny blue in
|
|
28
|
+
// explorer, the gold accent in commander.
|
|
27
29
|
// - Accent: primary (cursor, active pane label) and secondary (marks).
|
|
28
30
|
// - Semantic: error, warning and tip, each with a background + foreground
|
|
29
31
|
// for filled badges (the command bar status, the confirm dialog).
|
|
30
|
-
// - Content: the file-listing colors (file/link/device/directory
|
|
32
|
+
// - Content: the file-listing colors (file/link/device/directory plus the
|
|
33
|
+
// executable and read-only file states).
|
|
34
|
+
// - Scrollbar: the track and thumb of every scrollable surface (the TUI's
|
|
35
|
+
// slider, mirrored by the web's CSS variables).
|
|
31
36
|
// - Brand: the identity-bar gradient endpoints — "Tiny" stays blue, "Cmd"
|
|
32
37
|
// runs gold to saturated orange.
|
|
33
38
|
|
|
@@ -43,6 +48,8 @@ const DARK = {
|
|
|
43
48
|
cursorBg: "#274a9e",
|
|
44
49
|
cursorInactiveBg: "#1b2a51",
|
|
45
50
|
selectionBg: "#2b3f78",
|
|
51
|
+
// The value fields of the command panel's argument rows.
|
|
52
|
+
fieldBg: "#1b2a51",
|
|
46
53
|
// Text
|
|
47
54
|
textFg: "#e6ecff",
|
|
48
55
|
textSecondaryFg: "#8fa3d9",
|
|
@@ -50,6 +57,8 @@ const DARK = {
|
|
|
50
57
|
// Borders
|
|
51
58
|
borderSecondaryFg: "#33508f",
|
|
52
59
|
borderSecondaryActiveFg: "#f0b429",
|
|
60
|
+
// The active pane's border/head rule in explorer mode: the Tiny blue.
|
|
61
|
+
borderActiveExplorerFg: "#4088ff",
|
|
53
62
|
borderPrimaryFg: "#3d5590",
|
|
54
63
|
borderPrimaryActiveFg: "#ffc233",
|
|
55
64
|
// Accent
|
|
@@ -69,6 +78,13 @@ const DARK = {
|
|
|
69
78
|
linkFg: "#4fc3ff",
|
|
70
79
|
devFg: "#b48eff",
|
|
71
80
|
dirFg: "#5c8cff",
|
|
81
|
+
// Executable files go green, read-only files dimmer than a plain file
|
|
82
|
+
// (`ls --color` / Midnight Commander habits).
|
|
83
|
+
execFg: "#5fd67a",
|
|
84
|
+
readonlyFg: "#7d8ab8",
|
|
85
|
+
// Scrollbar
|
|
86
|
+
scrollbarTrackBg: "transparent",
|
|
87
|
+
scrollbarThumbBg: "#22345e",
|
|
72
88
|
// Brand
|
|
73
89
|
brandTinyFrom: "#4088ff",
|
|
74
90
|
brandTinyTo: "#7cd0ff",
|
|
@@ -88,6 +104,8 @@ const LIGHT = {
|
|
|
88
104
|
cursorBg: "#2f56b8",
|
|
89
105
|
cursorInactiveBg: "#c6d1ee",
|
|
90
106
|
selectionBg: "#c9d5f4",
|
|
107
|
+
// The value fields of the command panel's argument rows.
|
|
108
|
+
fieldBg: "#dbe4fb",
|
|
91
109
|
// Text
|
|
92
110
|
textFg: "#101a33",
|
|
93
111
|
textSecondaryFg: "#495785",
|
|
@@ -95,6 +113,7 @@ const LIGHT = {
|
|
|
95
113
|
// Borders
|
|
96
114
|
borderSecondaryFg: "#9aabd6",
|
|
97
115
|
borderSecondaryActiveFg: "#926000",
|
|
116
|
+
borderActiveExplorerFg: "#1d4ed8",
|
|
98
117
|
borderPrimaryFg: "#8c9cc9",
|
|
99
118
|
borderPrimaryActiveFg: "#a06a00",
|
|
100
119
|
// Accent
|
|
@@ -114,6 +133,11 @@ const LIGHT = {
|
|
|
114
133
|
linkFg: "#0369a1",
|
|
115
134
|
devFg: "#7c3aed",
|
|
116
135
|
dirFg: "#1d4ed8",
|
|
136
|
+
execFg: "#0f7a3d",
|
|
137
|
+
readonlyFg: "#6b7280",
|
|
138
|
+
// Scrollbar
|
|
139
|
+
scrollbarTrackBg: "transparent",
|
|
140
|
+
scrollbarThumbBg: "#34548f",
|
|
117
141
|
// Brand
|
|
118
142
|
brandTinyFrom: "#1d4ed8",
|
|
119
143
|
brandTinyTo: "#3b82f6",
|
|
@@ -131,11 +155,13 @@ const MONO = {
|
|
|
131
155
|
cursorBg: undefined,
|
|
132
156
|
cursorInactiveBg: undefined,
|
|
133
157
|
selectionBg: undefined,
|
|
158
|
+
fieldBg: undefined,
|
|
134
159
|
textFg: undefined,
|
|
135
160
|
textSecondaryFg: undefined,
|
|
136
161
|
textHeadingFg: undefined,
|
|
137
162
|
borderSecondaryFg: undefined,
|
|
138
163
|
borderSecondaryActiveFg: undefined,
|
|
164
|
+
borderActiveExplorerFg: undefined,
|
|
139
165
|
borderPrimaryFg: undefined,
|
|
140
166
|
borderPrimaryActiveFg: undefined,
|
|
141
167
|
accentFg: undefined,
|
|
@@ -152,6 +178,10 @@ const MONO = {
|
|
|
152
178
|
linkFg: undefined,
|
|
153
179
|
devFg: undefined,
|
|
154
180
|
dirFg: undefined,
|
|
181
|
+
execFg: undefined,
|
|
182
|
+
readonlyFg: undefined,
|
|
183
|
+
scrollbarTrackBg: undefined,
|
|
184
|
+
scrollbarThumbBg: undefined,
|
|
155
185
|
brandTinyFrom: undefined,
|
|
156
186
|
brandTinyTo: undefined,
|
|
157
187
|
brandCmdFrom: undefined,
|
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
// Project: TinyCommand
|
|
2
|
+
// Vendored dependency
|
|
3
|
+
//
|
|
4
|
+
// Module: tcmd/vendor/bzip2
|
|
5
|
+
// bzip2.js — a small bzip2 decompression implementation.
|
|
6
|
+
//
|
|
7
|
+
// Source: https://github.com/antimatter15/bzip2.js (bzip2.js)
|
|
8
|
+
// Author: antimatter15
|
|
9
|
+
// License: MIT
|
|
10
|
+
//
|
|
11
|
+
// Vendored verbatim (only this header and the trailing export were added) so
|
|
12
|
+
// TinyCommand can preview `.bz2` files without adding a runtime dependency.
|
|
13
|
+
// `array` wraps the bytes in a bit reader; `header` returns the block size and
|
|
14
|
+
// `decompress` decodes one block, returning `-1` on the stream terminator.
|
|
15
|
+
// Decoded output is a binary string (one char code per byte), so callers must
|
|
16
|
+
// decode it as UTF-8 themselves.
|
|
17
|
+
//
|
|
18
|
+
// MIT License
|
|
19
|
+
//
|
|
20
|
+
// Copyright (c) 2011 by antimatter15 (antimatter15@gmail.com).
|
|
21
|
+
//
|
|
22
|
+
// Permission is hereby granted, free of charge, to any person obtaining a
|
|
23
|
+
// copy of this software and associated documentation files (the "Software"),
|
|
24
|
+
// to deal in the Software without restriction, including without limitation
|
|
25
|
+
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
26
|
+
// and/or sell copies of the Software, and to permit persons to whom the
|
|
27
|
+
// Software is furnished to do so, subject to the following conditions:
|
|
28
|
+
//
|
|
29
|
+
// The above copyright notice and this permission notice shall be included in
|
|
30
|
+
// all copies or substantial portions of the Software.
|
|
31
|
+
//
|
|
32
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
33
|
+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
34
|
+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
35
|
+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
36
|
+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
37
|
+
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
38
|
+
// IN THE SOFTWARE.
|
|
39
|
+
|
|
40
|
+
var bzip2 = {};
|
|
41
|
+
|
|
42
|
+
bzip2.array = function(bytes){
|
|
43
|
+
var bit = 0, byte = 0;
|
|
44
|
+
var BITMASK = [0, 0x01, 0x03, 0x07, 0x0F, 0x1F, 0x3F, 0x7F, 0xFF ];
|
|
45
|
+
return function(n){
|
|
46
|
+
var result = 0;
|
|
47
|
+
while(n > 0){
|
|
48
|
+
var left = 8 - bit;
|
|
49
|
+
if(n >= left){
|
|
50
|
+
result <<= left;
|
|
51
|
+
result |= (BITMASK[left] & bytes[byte++]);
|
|
52
|
+
bit = 0;
|
|
53
|
+
n -= left;
|
|
54
|
+
}else{
|
|
55
|
+
result <<= n;
|
|
56
|
+
result |= ((bytes[byte] & (BITMASK[n] << (8 - n - bit))) >> (8 - n - bit));
|
|
57
|
+
bit += n;
|
|
58
|
+
n = 0;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return result
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
bzip2.simple = function(bits){
|
|
66
|
+
var size = bzip2.header(bits);
|
|
67
|
+
var all = '', chunk = '';
|
|
68
|
+
do{
|
|
69
|
+
all += chunk;
|
|
70
|
+
chunk = bzip2.decompress(bits, size);
|
|
71
|
+
}while(chunk != -1);
|
|
72
|
+
return all;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
bzip2.header = function(bits){
|
|
76
|
+
if(bits(8*3) != 4348520) throw "No magic number found";
|
|
77
|
+
var i = bits(8) - 48;
|
|
78
|
+
if(i < 1 || i > 9) throw "Not a BZIP archive";
|
|
79
|
+
return i;
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
//takes a function for reading the block data (starting with 0x314159265359)
|
|
84
|
+
//a block size (0-9) (optional, defaults to 9)
|
|
85
|
+
//a length at which to stop decompressing and return the output
|
|
86
|
+
bzip2.decompress = function(bits, size, len){
|
|
87
|
+
var MAX_HUFCODE_BITS = 20;
|
|
88
|
+
var MAX_SYMBOLS = 258;
|
|
89
|
+
var SYMBOL_RUNA = 0;
|
|
90
|
+
var SYMBOL_RUNB = 1;
|
|
91
|
+
var GROUP_SIZE = 50;
|
|
92
|
+
|
|
93
|
+
var bufsize = 100000 * size;
|
|
94
|
+
for(var h = '', i = 0; i < 6; i++) h += bits(8).toString(16);
|
|
95
|
+
if(h == "177245385090") return -1; //last block
|
|
96
|
+
if(h != "314159265359") throw "eek not valid bzip data";
|
|
97
|
+
bits(32); //ignore CRC codes
|
|
98
|
+
if(bits(1)) throw "unsupported obsolete version";
|
|
99
|
+
var origPtr = bits(24);
|
|
100
|
+
if(origPtr > bufsize) throw "Initial position larger than buffer size";
|
|
101
|
+
var t = bits(16);
|
|
102
|
+
var symToByte = new Uint8Array(256),
|
|
103
|
+
symTotal = 0;
|
|
104
|
+
for (i = 0; i < 16; i++) {
|
|
105
|
+
if(t & (1 << (15 - i))) {
|
|
106
|
+
var k = bits(16);
|
|
107
|
+
for(j = 0; j < 16; j++){
|
|
108
|
+
if(k & (1 << (15 - j))){
|
|
109
|
+
symToByte[symTotal++] = (16 * i) + j;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
var groupCount = bits(3);
|
|
116
|
+
if(groupCount < 2 || groupCount > 6) throw "another error";
|
|
117
|
+
var nSelectors = bits(15);
|
|
118
|
+
if(nSelectors == 0) throw "meh";
|
|
119
|
+
var mtfSymbol = []; //TODO: possibly replace JS array with typed arrays
|
|
120
|
+
for(var i = 0; i < groupCount; i++) mtfSymbol[i] = i;
|
|
121
|
+
var selectors = new Uint8Array(32768);
|
|
122
|
+
|
|
123
|
+
for(var i = 0; i < nSelectors; i++){
|
|
124
|
+
for(var j = 0; bits(1); j++) if(j >= groupCount) throw "whoops another error";
|
|
125
|
+
var uc = mtfSymbol[j];
|
|
126
|
+
mtfSymbol.splice(j, 1); //this is a probably inefficient MTF transform
|
|
127
|
+
mtfSymbol.splice(0, 0, uc);
|
|
128
|
+
selectors[i] = uc;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
var symCount = symTotal + 2;
|
|
132
|
+
var groups = [];
|
|
133
|
+
for(var j = 0; j < groupCount; j++){
|
|
134
|
+
var length = new Uint8Array(MAX_SYMBOLS),
|
|
135
|
+
temp = new Uint8Array(MAX_HUFCODE_BITS+1);
|
|
136
|
+
t = bits(5); //lengths
|
|
137
|
+
for(var i = 0; i < symCount; i++){
|
|
138
|
+
while(true){
|
|
139
|
+
if (t < 1 || t > MAX_HUFCODE_BITS) throw "I gave up a while ago on writing error messages";
|
|
140
|
+
if(!bits(1)) break;
|
|
141
|
+
if(!bits(1)) t++;
|
|
142
|
+
else t--;
|
|
143
|
+
}
|
|
144
|
+
length[i] = t;
|
|
145
|
+
}
|
|
146
|
+
var minLen, maxLen;
|
|
147
|
+
minLen = maxLen = length[0];
|
|
148
|
+
for(var i = 1; i < symCount; i++){
|
|
149
|
+
if(length[i] > maxLen) maxLen = length[i];
|
|
150
|
+
else if(length[i] < minLen) minLen = length[i];
|
|
151
|
+
}
|
|
152
|
+
var hufGroup;
|
|
153
|
+
hufGroup = groups[j] = {};
|
|
154
|
+
hufGroup.permute = new Uint32Array(MAX_SYMBOLS);
|
|
155
|
+
hufGroup.limit = new Uint32Array(MAX_HUFCODE_BITS + 1);
|
|
156
|
+
hufGroup.base = new Uint32Array(MAX_HUFCODE_BITS + 1);
|
|
157
|
+
hufGroup.minLen = minLen;
|
|
158
|
+
hufGroup.maxLen = maxLen;
|
|
159
|
+
var base = hufGroup.base.subarray(1);
|
|
160
|
+
var limit = hufGroup.limit.subarray(1);
|
|
161
|
+
var pp = 0;
|
|
162
|
+
for(var i = minLen; i <= maxLen; i++)
|
|
163
|
+
for(var t = 0; t < symCount; t++)
|
|
164
|
+
if(length[t] == i) hufGroup.permute[pp++] = t;
|
|
165
|
+
for(i = minLen; i <= maxLen; i++) temp[i] = limit[i] = 0;
|
|
166
|
+
for(i = 0; i < symCount; i++) temp[length[i]]++;
|
|
167
|
+
pp = t = 0;
|
|
168
|
+
for(i = minLen; i < maxLen; i++) {
|
|
169
|
+
pp += temp[i];
|
|
170
|
+
limit[i] = pp - 1;
|
|
171
|
+
pp <<= 1;
|
|
172
|
+
base[i+1] = pp - (t += temp[i]);
|
|
173
|
+
}
|
|
174
|
+
limit[maxLen]=pp+temp[maxLen]-1;
|
|
175
|
+
base[minLen]=0;
|
|
176
|
+
}
|
|
177
|
+
var byteCount = new Uint32Array(256);
|
|
178
|
+
for(var i = 0; i < 256; i++) mtfSymbol[i] = i;
|
|
179
|
+
var runPos, count, symCount, selector;
|
|
180
|
+
runPos = count = symCount = selector = 0;
|
|
181
|
+
var buf = new Uint32Array(bufsize);
|
|
182
|
+
while(true){
|
|
183
|
+
if(!(symCount--)){
|
|
184
|
+
symCount = GROUP_SIZE - 1;
|
|
185
|
+
if(selector >= nSelectors) throw "meow i'm a kitty, that's an error";
|
|
186
|
+
hufGroup = groups[selectors[selector++]];
|
|
187
|
+
base = hufGroup.base.subarray(1);
|
|
188
|
+
limit = hufGroup.limit.subarray(1);
|
|
189
|
+
}
|
|
190
|
+
i = hufGroup.minLen;
|
|
191
|
+
j = bits(i);
|
|
192
|
+
while(true){
|
|
193
|
+
if(i > hufGroup.maxLen) throw "rawr i'm a dinosaur";
|
|
194
|
+
if(j <= limit[i]) break;
|
|
195
|
+
i++;
|
|
196
|
+
j = (j << 1) | bits(1);
|
|
197
|
+
}
|
|
198
|
+
j -= base[i];
|
|
199
|
+
if(j < 0 || j >= MAX_SYMBOLS) throw "moo i'm a cow";
|
|
200
|
+
var nextSym = hufGroup.permute[j];
|
|
201
|
+
if (nextSym == SYMBOL_RUNA || nextSym == SYMBOL_RUNB) {
|
|
202
|
+
if(!runPos){
|
|
203
|
+
runPos = 1;
|
|
204
|
+
t = 0;
|
|
205
|
+
}
|
|
206
|
+
if(nextSym == SYMBOL_RUNA) t += runPos;
|
|
207
|
+
else t += 2 * runPos;
|
|
208
|
+
runPos <<= 1;
|
|
209
|
+
continue;
|
|
210
|
+
}
|
|
211
|
+
if(runPos){
|
|
212
|
+
runPos = 0;
|
|
213
|
+
if(count + t >= bufsize) throw "Boom.";
|
|
214
|
+
uc = symToByte[mtfSymbol[0]];
|
|
215
|
+
byteCount[uc] += t;
|
|
216
|
+
while(t--) buf[count++] = uc;
|
|
217
|
+
}
|
|
218
|
+
if(nextSym > symTotal) break;
|
|
219
|
+
if(count >= bufsize) throw "I can't think of anything. Error";
|
|
220
|
+
i = nextSym -1;
|
|
221
|
+
uc = mtfSymbol[i];
|
|
222
|
+
mtfSymbol.splice(i, 1);
|
|
223
|
+
mtfSymbol.splice(0, 0, uc);
|
|
224
|
+
uc = symToByte[uc];
|
|
225
|
+
byteCount[uc]++;
|
|
226
|
+
buf[count++] = uc;
|
|
227
|
+
}
|
|
228
|
+
if(origPtr < 0 || origPtr >= count) throw "I'm a monkey and I'm throwing something at someone, namely you";
|
|
229
|
+
var j = 0;
|
|
230
|
+
for(var i = 0; i < 256; i++){
|
|
231
|
+
k = j + byteCount[i];
|
|
232
|
+
byteCount[i] = j;
|
|
233
|
+
j = k;
|
|
234
|
+
}
|
|
235
|
+
for(var i = 0; i < count; i++){
|
|
236
|
+
uc = buf[i] & 0xff;
|
|
237
|
+
buf[byteCount[uc]] |= (i << 8);
|
|
238
|
+
byteCount[uc]++;
|
|
239
|
+
}
|
|
240
|
+
var pos = 0, current = 0, run = 0;
|
|
241
|
+
if(count) {
|
|
242
|
+
pos = buf[origPtr];
|
|
243
|
+
current = (pos & 0xff);
|
|
244
|
+
pos >>= 8;
|
|
245
|
+
run = -1;
|
|
246
|
+
}
|
|
247
|
+
count = count;
|
|
248
|
+
var output = '';
|
|
249
|
+
var copies, previous, outbyte;
|
|
250
|
+
if(!len) len = Infinity;
|
|
251
|
+
while(count){
|
|
252
|
+
count--;
|
|
253
|
+
previous = current;
|
|
254
|
+
pos = buf[pos];
|
|
255
|
+
current = pos & 0xff;
|
|
256
|
+
pos >>= 8;
|
|
257
|
+
if(run++ == 3){
|
|
258
|
+
copies = current;
|
|
259
|
+
outbyte = previous;
|
|
260
|
+
current = -1;
|
|
261
|
+
}else{
|
|
262
|
+
copies = 1;
|
|
263
|
+
outbyte = current;
|
|
264
|
+
}
|
|
265
|
+
while(copies--){
|
|
266
|
+
output += (String.fromCharCode(outbyte));
|
|
267
|
+
if(!--len) return output;
|
|
268
|
+
}
|
|
269
|
+
if(current != previous) run = 0;
|
|
270
|
+
}
|
|
271
|
+
return output;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
export { bzip2 }
|
|
275
|
+
|
|
276
|
+
// EOF
|