@@ -19,6 +19,8 @@ const immortals: { [globalKey: string]: any } = {};
19
19
20
20
const Z_INDEX = 1 ;
21
21
22
+ const SCROLL_COUNT = 10 ;
23
+
22
24
// make it really standout:
23
25
// const PADDING = 5;
24
26
// const STYLE = {
@@ -47,7 +49,8 @@ export default function ImmortalDomNode({
47
49
if ( divRef . current == null ) {
48
50
return ;
49
51
}
50
- const elt = getElt ( ) [ 0 ] ;
52
+ const jElt = getElt ( ) ;
53
+ const elt = jElt [ 0 ] ;
51
54
const eltRect = elt . getBoundingClientRect ( ) ;
52
55
const divRect = divRef . current . getBoundingClientRect ( ) ;
53
56
@@ -82,19 +85,39 @@ export default function ImmortalDomNode({
82
85
console . log ( { parentRect, eltRect } ) ;
83
86
// Calculate the overlap area
84
87
const top = Math . max ( 0 , parentRect . top - eltRect . top ) ;
85
- const right = Math . min ( eltRect . width , parentRect . right - eltRect . left ) ;
88
+ // leave 30px on right so to not block scrollbar
89
+ const right = Math . min (
90
+ eltRect . width ,
91
+ parentRect . right - 30 - eltRect . left ,
92
+ ) ;
86
93
const bottom = Math . min ( eltRect . height , parentRect . bottom - eltRect . top ) ;
87
94
const left = Math . max ( 0 , parentRect . left - eltRect . left ) ;
88
95
89
96
// Apply clip-path to elt to make it visible only inside of parentRect:
90
97
elt . style . clipPath = `polygon(${ left } px ${ top } px, ${ right } px ${ top } px, ${ right } px ${ bottom } px, ${ left } px ${ bottom } px)` ;
98
+
99
+ // if its an iframe resize it
100
+ if ( html . toLowerCase ( ) . startsWith ( "<iframe" ) ) {
101
+ const iframe = jElt . find ( "iframe" ) ;
102
+ if ( iframe . length > 0 ) {
103
+ var iframeBody = iframe . contents ( ) . find ( "body" ) ;
104
+ if ( iframeBody . length > 0 ) {
105
+ // Get dimensions of the iframe's body
106
+ //const width = iframeBody.outerWidth();
107
+ const height = iframeBody . outerHeight ( ) ;
108
+ //iframe[0].style.width = `${width}px`;
109
+ iframe [ 0 ] . style . height = `${ height } px` ;
110
+ iframeBody [ 0 ] . style [ "overflow-y" ] = "hidden" ;
111
+ }
112
+ }
113
+ }
91
114
}
92
115
} , [ ] ) ;
93
116
94
117
const getElt = ( ) => {
95
118
if ( immortals [ globalKey ] == null ) {
96
119
const elt = ( immortals [ globalKey ] = $ (
97
- `<div id="${ globalKey } " style="border:0;position:absolute;z-index:${ zIndex } "/>${ html } </div>` ,
120
+ `<div id="${ globalKey } " style="border:0;position:absolute;overflow-y:hidden; z-index:${ zIndex } "/>${ html } </div>` ,
98
121
) ) ;
99
122
$ ( "body" ) . append ( elt ) ;
100
123
return elt ;
@@ -135,7 +158,7 @@ export default function ImmortalDomNode({
135
158
// in order to make it so the iframe doesn't appear
136
159
// to just get "dragged along" nearly as much, as
137
160
// onScroll is throttled.
138
- count = Math . min ( 100 , count + 100 ) ;
161
+ count = Math . min ( SCROLL_COUNT , SCROLL_COUNT + 100 ) ;
139
162
while ( count > 0 ) {
140
163
position ( ) ;
141
164
await new Promise ( requestAnimationFrame ) ;
0 commit comments