File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed
Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change 1+ // DOM utility functions
2+ export function isElementInViewport ( el : Element ) : boolean {
3+ const rect = el . getBoundingClientRect ( ) ;
4+ return rect . top >= 0 && rect . left >= 0 && rect . bottom <= window . innerHeight && rect . right <= window . innerWidth ;
5+ }
6+ export function copyToClipboard ( text : string ) : Promise < void > {
7+ if ( navigator . clipboard ) return navigator . clipboard . writeText ( text ) ;
8+ const textarea = document . createElement ( 'textarea' ) ;
9+ textarea . value = text ;
10+ textarea . style . position = 'fixed' ;
11+ textarea . style . opacity = '0' ;
12+ document . body . appendChild ( textarea ) ;
13+ textarea . select ( ) ;
14+ document . execCommand ( 'copy' ) ;
15+ document . body . removeChild ( textarea ) ;
16+ return Promise . resolve ( ) ;
17+ }
18+ export function getScrollPercentage ( ) : number {
19+ const h = document . documentElement ;
20+ const b = document . body ;
21+ const scrollTop = h . scrollTop || b . scrollTop ;
22+ const scrollHeight = ( h . scrollHeight || b . scrollHeight ) - h . clientHeight ;
23+ return scrollHeight > 0 ? Math . round ( ( scrollTop / scrollHeight ) * 100 ) : 0 ;
24+ }
You can’t perform that action at this time.
0 commit comments