File tree 8 files changed +48
-46
lines changed
themes/default/assets/typedoc
8 files changed +48
-46
lines changed Original file line number Diff line number Diff line change @@ -3,8 +3,6 @@ import { RendererComponent } from "../components.js";
3
3
import { RendererEvent } from "../events.js" ;
4
4
import { writeFile } from "../../utils/index.js" ;
5
5
import { DefaultTheme } from "../themes/default/DefaultTheme.js" ;
6
- import { gzip } from "zlib" ;
7
- import { promisify } from "util" ;
8
6
9
7
import type { Renderer } from "../index.js" ;
10
8
import {
@@ -13,8 +11,7 @@ import {
13
11
getUniquePath ,
14
12
} from "../themes/lib.js" ;
15
13
import type { DeclarationReflection } from "../../models/index.js" ;
16
-
17
- const gzipP = promisify ( gzip ) ;
14
+ import { compressJson } from "../../utils/compress.js" ;
18
15
19
16
interface JsonHierarchyElement {
20
17
name : string ;
@@ -102,13 +99,9 @@ export class HierarchyPlugin extends RendererComponent {
102
99
"hierarchy.js" ,
103
100
) ;
104
101
105
- const gz = await gzipP ( Buffer . from ( JSON . stringify ( hierarchy ) ) ) ;
106
-
107
102
await writeFile (
108
103
hierarchyJs ,
109
- `window.hierarchyData = "data:application/octet-stream;base64,${ gz . toString (
110
- "base64" ,
111
- ) } "`,
104
+ `window.hierarchyData = "${ await compressJson ( hierarchy ) } "` ,
112
105
) ;
113
106
}
114
107
}
Original file line number Diff line number Diff line change @@ -12,13 +12,10 @@ import { RendererComponent } from "../components.js";
12
12
import { IndexEvent , RendererEvent } from "../events.js" ;
13
13
import { Option , writeFile } from "../../utils/index.js" ;
14
14
import { DefaultTheme } from "../themes/default/DefaultTheme.js" ;
15
- import { gzip } from "zlib" ;
16
- import { promisify } from "util" ;
17
15
import type { Renderer } from "../index.js" ;
18
16
import { GroupPlugin } from "../../converter/plugins/GroupPlugin.js" ;
19
17
import { CategoryPlugin } from "../../converter/plugins/CategoryPlugin.js" ;
20
-
21
- const gzipP = promisify ( gzip ) ;
18
+ import { compressJson } from "../../utils/compress.js" ;
22
19
23
20
/**
24
21
* Keep this in sync with the interface in src/lib/output/themes/default/assets/typedoc/components/Search.ts
@@ -152,17 +149,13 @@ export class JavascriptIndexPlugin extends RendererComponent {
152
149
"search.js" ,
153
150
) ;
154
151
155
- const jsonData = JSON . stringify ( {
152
+ const data = {
156
153
rows,
157
154
index,
158
- } ) ;
159
- const data = await gzipP ( Buffer . from ( jsonData ) ) ;
160
-
155
+ } ;
161
156
await writeFile (
162
157
jsonFileName ,
163
- `window.searchData = "data:application/octet-stream;base64,${ data . toString (
164
- "base64" ,
165
- ) } ";`,
158
+ `window.searchData = "${ await compressJson ( data ) } ";` ,
166
159
) ;
167
160
168
161
if (
Original file line number Diff line number Diff line change @@ -3,11 +3,8 @@ import { RendererComponent } from "../components.js";
3
3
import { RendererEvent } from "../events.js" ;
4
4
import { writeFile } from "../../utils/index.js" ;
5
5
import { DefaultTheme } from "../themes/default/DefaultTheme.js" ;
6
- import { gzip } from "zlib" ;
7
- import { promisify } from "util" ;
8
6
import type { Renderer } from "../index.js" ;
9
-
10
- const gzipP = promisify ( gzip ) ;
7
+ import { compressJson } from "../../utils/compress.js" ;
11
8
12
9
export class NavigationPlugin extends RendererComponent {
13
10
constructor ( owner : Renderer ) {
@@ -34,13 +31,10 @@ export class NavigationPlugin extends RendererComponent {
34
31
const nav = ( this . owner . theme as DefaultTheme ) . getNavigation (
35
32
event . project ,
36
33
) ;
37
- const gz = await gzipP ( Buffer . from ( JSON . stringify ( nav ) ) ) ;
38
34
39
35
await writeFile (
40
36
navigationJs ,
41
- `window.navigationData = "data:application/octet-stream;base64,${ gz . toString (
42
- "base64" ,
43
- ) } "`,
37
+ `window.navigationData = "${ await compressJson ( nav ) } "` ,
44
38
) ;
45
39
}
46
40
}
Original file line number Diff line number Diff line change
1
+ import { decompressJson } from "./utils/decompress" ;
2
+
1
3
declare global {
2
4
interface Window {
3
5
// Base64 encoded data url, gzipped, JSON encoded JsonHierarchy
@@ -106,14 +108,8 @@ async function buildHierarchyToggle() {
106
108
) ;
107
109
if ( ! container || ! window . hierarchyData ) return ;
108
110
109
- const res = await fetch ( window . hierarchyData ) ;
110
- const data = await res . arrayBuffer ( ) ;
111
- const json = new Blob ( [ data ] )
112
- . stream ( )
113
- . pipeThrough ( new DecompressionStream ( "gzip" ) ) ;
114
-
115
111
const baseReflId = + container . dataset . refl ! ;
116
- const hierarchy : JsonHierarchy = await new Response ( json ) . json ( ) ;
112
+ const hierarchy : JsonHierarchy = await decompressJson ( window . hierarchyData ) ;
117
113
118
114
const collapsedHierarchy = container . querySelector ( "ul" ) ! ;
119
115
const expandedHierarchy = document . createElement ( "ul" ) ;
Original file line number Diff line number Diff line change
1
+ import { decompressJson } from "./utils/decompress" ;
2
+
1
3
export interface NavigationElement {
2
4
text : string ;
3
5
path ?: string ;
@@ -27,12 +29,9 @@ async function buildNav() {
27
29
const container = document . getElementById ( "tsd-nav-container" ) ;
28
30
if ( ! container || ! window . navigationData ) return ;
29
31
30
- const res = await fetch ( window . navigationData ) ;
31
- const data = await res . arrayBuffer ( ) ;
32
- const json = new Blob ( [ data ] )
33
- . stream ( )
34
- . pipeThrough ( new DecompressionStream ( "gzip" ) ) ;
35
- const nav : NavigationElement [ ] = await new Response ( json ) . json ( ) ;
32
+ const nav : NavigationElement [ ] = await decompressJson (
33
+ window . navigationData ,
34
+ ) ;
36
35
37
36
BASE_URL = document . documentElement . dataset . base ! ;
38
37
if ( ! BASE_URL . endsWith ( "/" ) ) BASE_URL += "/" ;
Original file line number Diff line number Diff line change 1
1
import { debounce } from "../utils/debounce.js" ;
2
2
import { Index } from "lunr" ;
3
+ import { decompressJson } from "../utils/decompress.js" ;
3
4
4
5
/**
5
6
* Keep this in sync with the interface in src/lib/output/plugins/JavascriptIndexPlugin.ts
@@ -35,11 +36,7 @@ interface SearchState {
35
36
async function updateIndex ( state : SearchState , searchEl : HTMLElement ) {
36
37
if ( ! window . searchData ) return ;
37
38
38
- const res = await fetch ( window . searchData ) ;
39
- const json = new Blob ( [ await res . arrayBuffer ( ) ] )
40
- . stream ( )
41
- . pipeThrough ( new DecompressionStream ( "gzip" ) ) ;
42
- const data : IData = await new Response ( json ) . json ( ) ;
39
+ const data : IData = await decompressJson ( window . searchData ) ;
43
40
44
41
state . data = data ;
45
42
state . index = Index . load ( data . index ) ;
Original file line number Diff line number Diff line change
1
+ /**
2
+ * Decompresses Base64-encoded Gzip data and parses it into a JSON object.
3
+ *
4
+ * @param base64 - The Base64-encoded string representing the Gzip-compressed JSON string.
5
+ * @returns A promise that resolves to the parsed JSON object.
6
+ */
7
+ export async function decompressJson ( base64 : string ) {
8
+ const binaryData = Uint8Array . from ( atob ( base64 ) , ( c ) => c . charCodeAt ( 0 ) ) ;
9
+ const blob = new Blob ( [ binaryData ] ) ;
10
+ const decompressedStream = blob
11
+ . stream ( )
12
+ . pipeThrough ( new DecompressionStream ( "gzip" ) ) ;
13
+ const decompressedText = await new Response ( decompressedStream ) . text ( ) ;
14
+ return JSON . parse ( decompressedText ) ;
15
+ }
Original file line number Diff line number Diff line change
1
+ import { gzip } from "zlib" ;
2
+ import { promisify } from "util" ;
3
+
4
+ const gzipP = promisify ( gzip ) ;
5
+
6
+ /**
7
+ * Compresses a JSON-serializable object into a Base64-encoded Gzip string.
8
+ *
9
+ * @param data - The JSON-serializable object to compress.
10
+ * @returns A promise that resolves to a Base64-encoded string of the Gzip-compressed data.
11
+ */
12
+ export async function compressJson ( data : any ) {
13
+ const gz = await gzipP ( Buffer . from ( JSON . stringify ( data ) ) ) ;
14
+ return gz . toString ( "base64" ) ;
15
+ }
You can’t perform that action at this time.
0 commit comments