Huakun 234f245a9c
Improve: add global loading screen (#237)
* refactor(desktop): move ext loading code in store from +page.ts to +page.svelte

try to solve blank screen on slow network

* Revert "refactor(desktop): move ext loading code in store from +page.ts to +page.svelte"

This reverts commit 4a0a695ce615cee695849c64746ba569680ff8c4.

* feat(desktop): add full-screen loading state and border beam animation

- Implement full-screen loading component with BorderBeam animation
- Add fullScreenLoading flag to appState store
- Update extension store pages to use full-screen loading
- Add border beam animation to Tailwind config
- Enhance page loading experience with visual feedback

* feat(desktop): add dance animation to loading screen and update imports

- Add Dance component to FullScreenLoading with subtle background effect
- Remove unused fade transition import from layout
- Update lz-string import in utils to use default import
- Clean up compress test imports

* feat(desktop): add back button to full-screen loading component

- Import ArrowLeftIcon and Constants from @kksh/ui
- Add back button with absolute positioning
- Remove "Go Home" text button
- Enhance loading screen with improved navigation

* refactor(desktop): update BorderBeam component to use Svelte 5 runes
2025-03-07 13:00:15 -05:00

36 lines
1.1 KiB
TypeScript

import lzString from "lz-string"
const { compressToBase64, decompressFromBase64 } = lzString
/**
* This file contains the deserialization and compression functions I designed for the grid animation.
*/
export function deserializeFrame(frameStr: string): number[][] {
// Convert string to 2D array. "o" is 0, "l" is 255. Each line is separated by '\n'
return frameStr.split("\n").map((row) => Array.from(row).map((char) => (char === "o" ? 0 : 1)))
}
export function decompressFrame(compressedFrame: string): string {
// Each char can be "o" or "l". Compress consecutive same char to a number followed by the char.
let decompressed = []
let count = ""
for (let char of compressedFrame) {
if (!isNaN(parseInt(char))) {
count += char
} else {
if (count) {
decompressed.push(char.repeat(parseInt(count)))
count = ""
} else {
decompressed.push(char)
}
}
}
return decompressed.join("")
}
// this is simple re-export of lz-string, the purpose is to make it easy to swap to another compression algorithm later without changing other code
export const compressString = compressToBase64
export const decompressString = decompressFromBase64