Skip to content

Commit de73c29

Browse files
committed
Ensure the decoders object is utilised wherever code is being referenced.
Add some slightly improved UX hints for the `Image` renderer. Keep newlines when returning code as text. Disable Idbfs.
1 parent 9de4e5f commit de73c29

File tree

15 files changed

+145
-78
lines changed

15 files changed

+145
-78
lines changed

css/app.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,11 @@ span.actions {
165165
.tty {
166166
border: 1px solid rgba(248, 248, 242, .3);
167167
padding: 4px;
168+
resize: vertical;
169+
170+
.fullscreen & {
171+
height: calc(100vh - 16px);
172+
}
168173

169174
&:focus-within {
170175
border-color: #a6e22e;

dist/css/app.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/css/app.css.map

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/js/app.js

Lines changed: 44 additions & 43 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/js/app.js.map

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ <h1>
2626
<button name="copy" aria-label="Copy Link"></button>
2727
<button name="markdown" aria-label="Generate Markdown"></button>
2828
</span>
29+
30+
<button class="fullscreen-toggle" style="display: none;">
31+
Fullscreen
32+
</button>
2933
</h1>
3034

3135
<h3 class="code-header">

js/Decoders.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
export interface Decoder {
22
name(): string;
3-
matches(code: string): boolean;
4-
decode(code: string): number[];
3+
matches(code: number[]): boolean;
4+
matchesAsString(code: string): boolean;
5+
decode(code: number[]): number[];
6+
decodeAsString(code: string): number[];
57
}
68

79
export class Decoders {
@@ -11,17 +13,29 @@ export class Decoders {
1113
this.registered.push(...decoders);
1214
}
1315

14-
public decode(code: string): number[] {
16+
public decode(code: number[]): number[] {
1517
return this.decoder(code).decode(code);
1618
}
1719

18-
public decoder(code: string): Decoder {
20+
public decodeAsString(code: string): number[] {
21+
return this.decoderAsString(code).decodeAsString(code);
22+
}
23+
24+
public decoder(code: number[]): Decoder {
1925
const [decoder] = this.registered.filter((decoder): boolean =>
2026
decoder.matches(code)
2127
);
2228

2329
return decoder;
2430
}
31+
32+
public decoderAsString(code: string): Decoder {
33+
const [decoder] = this.registered.filter((decoder): boolean =>
34+
decoder.matchesAsString(code)
35+
);
36+
37+
return decoder;
38+
}
2539
}
2640

2741
export default Decoders;

js/Decoders/Base64.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import { Decoder } from '../Decoders';
2+
import Default from './Default';
23

3-
export class Base64 implements Decoder {
4+
export class Base64 extends Default implements Decoder {
45
public name(): string {
56
return 'base64';
67
}
78

8-
public matches(code: string): boolean {
9+
public matchesAsString(code: string): boolean {
910
// base64 input is at least 4 chars
1011
if (code.length < 4) {
1112
return false;
@@ -20,7 +21,7 @@ export class Base64 implements Decoder {
2021
}
2122
}
2223

23-
public decode(code: string): number[] {
24+
public decodeAsString(code: string): number[] {
2425
return Array.from(atob(code)).map((c: string): number => c.charCodeAt(0));
2526
}
2627
}

js/Decoders/Default.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,28 @@ export class Default implements Decoder {
55
return 'default';
66
}
77

8-
public matches(): boolean {
8+
protected codePointsToString(code: number[]): string {
9+
return code.reduce((code, ord) => code + String.fromCharCode(ord), '');
10+
}
11+
12+
protected stringToCodePoints(code: string): number[] {
13+
return code.split('').map((c: string): number => c.charCodeAt(0));
14+
}
15+
16+
public matches(code: number[]): boolean {
17+
return this.matchesAsString(this.codePointsToString(code));
18+
}
19+
20+
public matchesAsString(code: string): boolean {
921
return true;
1022
}
1123

12-
public decode(code: string): number[] {
13-
return Array.from(code).map((char: string): number => char.charCodeAt(0));
24+
public decode(code: number[]): number[] {
25+
return this.decodeAsString(this.codePointsToString(code));
26+
}
27+
28+
public decodeAsString(code: string): number[] {
29+
return this.stringToCodePoints(code);
1430
}
1531
}
1632

js/Decoders/Hexdump.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
import { Decoder } from '../Decoders';
2+
import Default from './Default';
23

3-
export class Hexdump implements Decoder {
4+
export class Hexdump extends Default implements Decoder {
45
public name(): string {
56
return 'hexdump';
67
}
78

8-
public matches(code: string): boolean {
9+
public matchesAsString(code: string): boolean {
910
return /^(\d{7} (((.{2}){1,2} ){1,8})(\n|$))+$/.test(code);
1011
}
1112

12-
public decode(code: string): number[] {
13+
public decodeAsString(code: string): number[] {
1314
return code
1415
.trim()
1516
.replace(/(?<=^|\n)\d{7} (((.{2}){1,2} ){1,8}).+/g, '$1')

0 commit comments

Comments
 (0)