App.tsx 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import React, { FC, useEffect, useRef, useState } from 'react';
  2. import FilePicker from './components/file-picker';
  3. import CodeBox from './components/code-box';
  4. const App: FC = () => {
  5. const [files, setFiles] = useState<File[] | null>([]);
  6. const cbRef = useRef<HTMLDivElement>(null);
  7. useEffect(() => {
  8. if (files && files.length) {
  9. cbRef.current!.scrollIntoView({
  10. behavior: 'smooth' // Hopefully IE just ignores this value
  11. });
  12. }
  13. }, [files]);
  14. return (
  15. <>
  16. <div style={{
  17. display: 'flex',
  18. fontSize: '70px',
  19. justifyContent: 'space-between',
  20. flexDirection: 'row',
  21. overflow: 'hidden',
  22. width: '100%',
  23. fontWeight: 'bold'
  24. }}>
  25. <div style={{ paddingLeft: '0.25em' }}>
  26. fflate
  27. <div style={{
  28. color: 'gray',
  29. fontSize: '0.25em',
  30. fontWeight: 'lighter'
  31. }}>a fast compression library by <a href="//github.com/101arrowz" style={{ color: 'gray' }}>101arrowz</a></div>
  32. </div>
  33. <a href="//github.com/101arrowz/fflate">
  34. <svg xmlns="http://www.w3.org/2000/svg" width="80" height="80" viewBox="0 0 250 250" fill="white">
  35. <path d="M0 0l115 115h15l12 27 108 108V0z" fill="black"/>
  36. <path d="M128 109c-15-9-9-19-9-19 3-7 2-11 2-11-1-7 3-2 3-2 4 5 2 11 2 11-3 10 5 15 9 16" style={{ transformOrigin: '130px 106px' }} />
  37. <path d="M115 115s4 2 5 0l14-14c3-2 6-3 8-3-8-11-15-24 2-41 5-5 10-7 16-7 1-2 3-7 12-11 0 0 5 3 7 16 4 2 8 5 12 9s7 8 9 12c14 3 17 7 17 7-4 8-9 11-11 11 0 6-2 11-7 16-16 16-30 10-41 2 0 3-1 7-5 11l-12 11c-1 1 1 5 1 5z"/>
  38. </svg>
  39. </a>
  40. </div>
  41. <div style={{
  42. display: 'flex',
  43. justifyContent: 'center',
  44. alignItems: 'center',
  45. flexDirection: 'column',
  46. textAlign: 'center',
  47. width: '100%',
  48. flex: 1
  49. }}>
  50. <div style={{ maxWidth: '80%', fontSize: 'calc(15px + 0.6vw)', paddingTop: '4vh', paddingBottom: '2vh' }}>
  51. You've found <a href="//npmjs.com/package/fflate">fflate</a>, the fastest pure JavaScript compression library in existence.
  52. <br /><br />
  53. You can both pack and expand Zlib, GZIP, DEFLATE, or ZIP files very quickly with just a few lines of code.
  54. <br /><br />
  55. Weighing in at a measly 8kB for basic compression and decompression, you don't need to worry about your bundle size ballooning.
  56. <br /><br />
  57. Despite utilizing multiple cores, supporting data streams, and being very memory efficient, fflate is compatible with both Node.js and browsers as old as IE11.
  58. <br /><br />
  59. You can read more about fflate on <a href="//github.com/package/fflate">GitHub</a>. Try the demo below to see its performance for yourself. The code boxes are editable; try changing parameters or using a different compression format.
  60. <br /><br />
  61. <span style={{ fontSize: '0.75em' }}>Disclaimer: I added a <span style={{ fontStyle: 'italic' }}>lot</span> of sugar (around 4 hundred lines) to the UZIP and Pako APIs to make the demo clean and asynchronous, but the fflate API is unmodified.</span>
  62. <br /><br />
  63. </div>
  64. <div style={{
  65. width: '100%',
  66. display: 'flex',
  67. alignItems: 'center',
  68. flexDirection: 'column',
  69. marginBottom: '2vh'
  70. }}>
  71. <FilePicker allowDirs onFiles={setFiles} onError={console.log} onDrag={() => {}}>
  72. <div>{files ? ((files.length || 'No') + ' file' + (files.length == 1 ? '' : 's') + ' selected') : 'Loading...'}</div>
  73. <br />
  74. </FilePicker>
  75. {((!files || files.length) && <CodeBox files={files!} forwardRef={cbRef} />) || null}
  76. </div>
  77. </div>
  78. </>
  79. );
  80. }
  81. export default App;