11/* -- React Preloader -- */
2-
3- const { useEffect, useRef } = React ;
2+ const { useEffect, useRef, useState } = React ;
43
54function Preloader ( ) {
65 const ref = useRef ( null ) ;
6+ const progressRef = useRef ( 0 ) ;
7+ const [ progress , setProgress ] = useState ( 0 ) ;
78
89 useEffect ( ( ) => {
9- function showPage ( ) {
10- ref . current . classList . add ( 'hidden' ) ;
10+ function advance ( value ) {
11+ if ( value > progressRef . current ) {
12+ progressRef . current = value ;
13+ setProgress ( value ) ;
14+ }
15+ }
1116
12- setTimeout ( ( ) => {
13- document . getElementById ( 'page' ) . classList . remove ( 'page-hidden' ) ;
14- startAnimations ( ) ;
15- } , 500 ) ;
17+ advance ( 5 ) ;
18+
19+ const resources = document . querySelectorAll (
20+ 'link[rel="stylesheet"], script[src], img[src]'
21+ ) ;
22+ const expectedCount = resources . length ;
23+ let loadedCount = 0 ;
24+
25+ let observer ;
26+ try {
27+ observer = new PerformanceObserver ( ( list ) => {
28+ loadedCount += list . getEntries ( ) . length ;
29+ if ( expectedCount > 0 ) {
30+ const pct = Math . min ( 85 , Math . round ( ( loadedCount / expectedCount ) * 85 ) ) ;
31+ advance ( pct ) ;
32+ }
33+ } ) ;
34+ observer . observe ( { type : 'resource' , buffered : true } ) ;
35+ } catch ( _ ) { }
36+
37+ if ( document . readyState === 'loading' ) {
38+ document . addEventListener ( 'DOMContentLoaded' , ( ) => advance ( 25 ) , { once : true } ) ;
39+ } else {
40+ advance ( 25 ) ;
1641 }
1742
18- function trigger ( ) {
19- setTimeout ( showPage , 1300 ) ;
43+ function finishLoading ( ) {
44+ if ( observer ) observer . disconnect ( ) ;
45+ advance ( 100 ) ;
46+ setTimeout ( ( ) => {
47+ if ( ref . current ) ref . current . classList . add ( 'hidden' ) ;
48+ setTimeout ( ( ) => {
49+ document . getElementById ( 'page' ) . classList . remove ( 'page-hidden' ) ;
50+ startAnimations ( ) ;
51+ } , 500 ) ;
52+ } , 450 ) ;
2053 }
2154
2255 if ( document . readyState === 'complete' ) {
23- trigger ( ) ;
56+ setTimeout ( finishLoading , 200 ) ;
2457 } else {
25- window . addEventListener ( 'load' , trigger , { once : true } ) ;
58+ window . addEventListener ( 'load' , ( ) => setTimeout ( finishLoading , 200 ) , { once : true } ) ;
2659 }
60+
61+ return ( ) => {
62+ if ( observer ) observer . disconnect ( ) ;
63+ } ;
2764 } , [ ] ) ;
2865
2966 return (
3067 < div id = "preloader" ref = { ref } >
31- < div className = "preloader-logo" > Nexory.Org </ div >
68+ < div className = "preloader-logo" > nexory.dev </ div >
3269 < div className = "preloader-bar" >
33- < div className = "preloader-bar-inner" > </ div >
70+ < div className = "preloader-bar-inner" style = { { width : progress + '%' } } > </ div >
3471 </ div >
3572 </ div >
3673 ) ;
@@ -42,7 +79,7 @@ ReactDOM.createRoot(document.getElementById('preloader-root')).render(<Preloader
4279function startAnimations ( ) {
4380 const canvas = document . getElementById ( 'code-canvas' ) ;
4481 const ctx = canvas . getContext ( '2d' ) ;
45- const PARTICLE_COUNT = 100 ;
82+ const PARTICLE_COUNT = 150 ;
4683 const CONNECTION_DIST = 200 ;
4784 const SPEED = 0.4 ;
4885 let particles = [ ] ;
@@ -108,7 +145,7 @@ function startAnimations() {
108145 draw ( ) ;
109146
110147 const CODE =
111- `class NexoryOrg :
148+ `class nexory :
112149 def __init__(self, org_name):
113150 self.org = org_name
114151 self.people = []
@@ -118,7 +155,7 @@ function startAnimations() {
118155 print(f"Welcome to {self.org}, {new_user}!")
119156
120157if __name__ == "__main__":
121- org = NexoryOrg("Nexory.Org ")
158+ org = NexoryOrg("nexory.dev ")
122159 org.join("Your Name")
123160 org.run()` ;
124161
0 commit comments