File tree Expand file tree Collapse file tree 2 files changed +28
-8
lines changed
docs/.vitepress/theme/components/state Expand file tree Collapse file tree 2 files changed +28
-8
lines changed Original file line number Diff line number Diff line change @@ -16,13 +16,32 @@ export function deserializeState(serializedString) {
16
16
}
17
17
18
18
try {
19
- // For backward compatibility, it can address non-compressed data.
20
- const compressed = ! serializedString . startsWith ( "eyJj" )
21
- const decodedText = window . atob ( serializedString )
22
- const jsonText = compressed
23
- ? pako . inflate ( decodedText , { to : "string" } )
24
- : decodedText
25
- const json = JSON . parse ( jsonText )
19
+ // For backward compatibility
20
+ const newCompressed = serializedString . startsWith ( "eJxd" )
21
+ const json = (
22
+ newCompressed
23
+ ? ( ) => {
24
+ const compressedString = window . atob ( serializedString )
25
+ const uint8Arr = pako . inflate (
26
+ Uint8Array . from ( compressedString , ( c ) =>
27
+ c . charCodeAt ( 0 ) ,
28
+ ) ,
29
+ )
30
+ const jsonText = new TextDecoder ( ) . decode ( uint8Arr )
31
+ return JSON . parse ( jsonText )
32
+ }
33
+ : ( ) => {
34
+ const decodedText = window . atob ( serializedString )
35
+ try {
36
+ const jsonText = pako . inflate ( decodedText , {
37
+ to : "string" ,
38
+ } )
39
+ return JSON . parse ( jsonText )
40
+ } catch {
41
+ return JSON . parse ( decodedText )
42
+ }
43
+ }
44
+ ) ( )
26
45
27
46
if ( typeof json === "object" && json != null ) {
28
47
if ( typeof json . code === "string" ) {
Original file line number Diff line number Diff line change @@ -25,7 +25,8 @@ export function serializeState(state) {
25
25
rules : state . rules ? getEnabledRules ( state . rules ) : undefined ,
26
26
}
27
27
const jsonString = JSON . stringify ( saveData )
28
- const compressedString = pako . deflate ( jsonString , { to : "string" } )
28
+ const uint8Arr = new TextEncoder ( ) . encode ( jsonString )
29
+ const compressedString = String . fromCharCode ( ...pako . deflate ( uint8Arr ) )
29
30
const base64 =
30
31
( typeof window !== "undefined" && window . btoa ( compressedString ) ) ||
31
32
compressedString
You can’t perform that action at this time.
0 commit comments