-
Notifications
You must be signed in to change notification settings - Fork 3.9k
/
Copy pathfull-overlay-frame-helper.js
100 lines (94 loc) · 2.79 KB
/
full-overlay-frame-helper.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/**
* Copyright 2017 The AMP HTML Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS-IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {px, resetStyles, setStyles, translate} from './style';
/**
* Centers a frame with a translate transition.
* This function does direct DOM manipulation, so it needs to run under vsync
* mutate context.
* @param {!HTMLIFrameElement} iframe
* @param {!ClientRect} iframeRect
* @param {{width: number, height: number}} viewportSize
* @param {number} transitionTimeMs
*/
export function centerFrameUnderVsyncMutate(
iframe,
iframeRect,
viewportSize,
transitionTimeMs
) {
// TODO(alanorozco): Place a sentinel sibling on inabox to account for
// gap necessary for position: fixed.
const translateX = px(
viewportSize.width / 2 - iframeRect.width / 2 - iframeRect.left
);
const translateY = px(
viewportSize.height / 2 - iframeRect.height / 2 - iframeRect.top
);
setStyles(iframe, {
'position': 'fixed',
'top': px(iframeRect.top),
'right': px(viewportSize.width - (iframeRect.left + iframeRect.width)),
'left': px(iframeRect.left),
'bottom': px(viewportSize.height - (iframeRect.top + iframeRect.height)),
'height': px(iframeRect.height),
'width': px(iframeRect.width),
'transition': `transform ${transitionTimeMs}ms ease`,
'transform': translate(translateX, translateY),
'margin': 0,
});
}
/**
* Expands frame to fill the entire viewport.
* This function does direct DOM manipulation, so it needs to run under vsync
* mutate context.
* @param {!HTMLIFrameElement} iframe
*/
export function expandFrameUnderVsyncMutate(iframe) {
setStyles(iframe, {
'position': 'fixed',
'z-index': 1000,
'left': 0,
'right': 0,
'top': 0,
'bottom': 0,
'width': '100vw',
'height': '100vh',
'transition': null,
'transform': null,
'margin': 0,
'border': 0,
});
}
/**
* Resets frame that was previously expanded to fill the entire viewport.
* This function does direct DOM manipulation, so it needs to run under vsync
* mutate context.
* @param {!HTMLIFrameElement} iframe
*/
export function collapseFrameUnderVsyncMutate(iframe) {
resetStyles(iframe, [
'position',
'z-index',
'left',
'right',
'top',
'bottom',
'width',
'height',
'margin',
'border',
]);
}