@jsenv/plugin-toolbar 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/css/toolbar_main.css +784 -0
- package/dist/html/toolbar.html +305 -0
- package/dist/js/toolbar_injector.js +300 -0
- package/dist/js/toolbar_main.js +900 -0
- package/dist/jsenv_plugin_toolbar.js +51 -0
- package/dist/other/jsenv_logo.svg +140 -0
- package/package.json +30 -0
- package/scripts/build.mjs +20 -0
- package/src/client/animation/toolbar_animation_core.js +30 -0
- package/src/client/animation/toolbar_animation_ui.js +21 -0
- package/src/client/communication/parent_window_communication.js +33 -0
- package/src/client/eventsource/eventsource.css +83 -0
- package/src/client/eventsource/toolbar_eventsource.js +57 -0
- package/src/client/execution/execution.css +79 -0
- package/src/client/execution/toolbar_execution.js +88 -0
- package/src/client/focus/focus.css +61 -0
- package/src/client/focus/toolbar_focus.js +19 -0
- package/src/client/jsenv_logo.svg +140 -0
- package/src/client/notification/toolbar_notification.js +181 -0
- package/src/client/responsive/overflow_menu.css +61 -0
- package/src/client/responsive/toolbar_responsive.js +103 -0
- package/src/client/settings/settings.css +201 -0
- package/src/client/settings/toolbar_settings.js +47 -0
- package/src/client/theme/jsenv_theme.css +77 -0
- package/src/client/theme/light_theme.css +106 -0
- package/src/client/theme/toolbar_theme.js +34 -0
- package/src/client/toolbar.html +452 -0
- package/src/client/toolbar_injector.js +230 -0
- package/src/client/toolbar_main.css +173 -0
- package/src/client/toolbar_main.js +174 -0
- package/src/client/toolbar_state.js +16 -0
- package/src/client/tooltip/tooltip.css +61 -0
- package/src/client/tooltip/tooltip.js +39 -0
- package/src/client/util/animation.js +305 -0
- package/src/client/util/dom.js +108 -0
- package/src/client/util/fetch_using_xhr.js +400 -0
- package/src/client/util/fetching.js +14 -0
- package/src/client/util/iframe_to_parent_href.js +10 -0
- package/src/client/util/jsenv_logger.js +28 -0
- package/src/client/util/preferences.js +10 -0
- package/src/client/util/responsive.js +112 -0
- package/src/client/util/util.js +19 -0
- package/src/client/variant/variant.js +74 -0
- package/src/jsenv_plugin_toolbar.js +63 -0
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/packages/ast/src/html/html_src_set.js +18 -0
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/packages/jsenv-plugin-toolbar/src/client/animation/toolbar_animation.js +45 -0
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/packages/jsenv-plugin-toolbar/src/client/animation/toolbar_animation.js.map +12 -0
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/packages/jsenv-plugin-toolbar/src/client/animation/toolbar_animation_core.js +32 -0
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/packages/jsenv-plugin-toolbar/src/client/animation/toolbar_animation_core.js.map +12 -0
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/packages/jsenv-plugin-toolbar/src/client/animation/toolbar_animation_ui.js +23 -0
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/packages/jsenv-plugin-toolbar/src/client/animation/toolbar_animation_ui.js.map +12 -0
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/packages/jsenv-plugin-toolbar/src/client/communication/parent_window_communication.js +33 -0
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/packages/jsenv-plugin-toolbar/src/client/eventsource/eventsource.css +87 -0
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/packages/jsenv-plugin-toolbar/src/client/eventsource/toolbar_eventsource.js +59 -0
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/packages/jsenv-plugin-toolbar/src/client/eventsource/toolbar_eventsource.js.map +12 -0
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/packages/jsenv-plugin-toolbar/src/client/execution/execution.css +88 -0
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/packages/jsenv-plugin-toolbar/src/client/execution/toolbar_execution.js +90 -0
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/packages/jsenv-plugin-toolbar/src/client/execution/toolbar_execution.js.map +12 -0
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/packages/jsenv-plugin-toolbar/src/client/focus/focus.css +28 -0
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/packages/jsenv-plugin-toolbar/src/client/focus/toolbar_focus.js +19 -0
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/packages/jsenv-plugin-toolbar/src/client/jsenv_logo.svg +140 -0
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/packages/jsenv-plugin-toolbar/src/client/notification/toolbar_notification.js +183 -0
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/packages/jsenv-plugin-toolbar/src/client/notification/toolbar_notification.js.map +12 -0
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/packages/jsenv-plugin-toolbar/src/client/responsive/overflow_menu.css +60 -0
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/packages/jsenv-plugin-toolbar/src/client/responsive/toolbar_responsive.js +105 -0
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/packages/jsenv-plugin-toolbar/src/client/responsive/toolbar_responsive.js.map +12 -0
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/packages/jsenv-plugin-toolbar/src/client/settings/settings.css +200 -0
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/packages/jsenv-plugin-toolbar/src/client/settings/toolbar_settings.js +49 -0
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/packages/jsenv-plugin-toolbar/src/client/settings/toolbar_settings.js.map +12 -0
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/packages/jsenv-plugin-toolbar/src/client/theme/light_theme.css +110 -0
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/packages/jsenv-plugin-toolbar/src/client/theme/toolbar_theme.js +36 -0
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/packages/jsenv-plugin-toolbar/src/client/theme/toolbar_theme.js.map +12 -0
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/packages/jsenv-plugin-toolbar/src/client/toolbar.html +319 -0
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/packages/jsenv-plugin-toolbar/src/client/toolbar_injector.js +232 -0
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/packages/jsenv-plugin-toolbar/src/client/toolbar_injector.js.map +12 -0
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/packages/jsenv-plugin-toolbar/src/client/toolbar_main.css +161 -0
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/packages/jsenv-plugin-toolbar/src/client/toolbar_main.css.map +12 -0
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/packages/jsenv-plugin-toolbar/src/client/toolbar_main.js +176 -0
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/packages/jsenv-plugin-toolbar/src/client/toolbar_main.js.map +12 -0
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/packages/jsenv-plugin-toolbar/src/client/toolbar_state.js +18 -0
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/packages/jsenv-plugin-toolbar/src/client/toolbar_state.js.map +12 -0
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/packages/jsenv-plugin-toolbar/src/client/tooltip/tooltip.css +60 -0
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/packages/jsenv-plugin-toolbar/src/client/tooltip/tooltip.js +41 -0
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/packages/jsenv-plugin-toolbar/src/client/tooltip/tooltip.js.map +12 -0
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/packages/jsenv-plugin-toolbar/src/client/util/animation.js +307 -0
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/packages/jsenv-plugin-toolbar/src/client/util/animation.js.map +12 -0
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/packages/jsenv-plugin-toolbar/src/client/util/dom.js +108 -0
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/packages/jsenv-plugin-toolbar/src/client/util/iframe_to_parent_href.js +10 -0
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/packages/jsenv-plugin-toolbar/src/client/util/preferences.js +10 -0
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/packages/jsenv-plugin-toolbar/src/client/util/responsive.js +112 -0
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/packages/jsenv-plugin-toolbar/src/client/variant/variant.js +74 -0
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/src/plugins/autoreload/client/autoreload.js +201 -0
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/src/plugins/autoreload/client/autoreload.js.map +12 -0
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/src/plugins/autoreload/client/autoreload_preference.js +11 -0
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/src/plugins/autoreload/client/reload.js +138 -0
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/src/plugins/autoreload/client/reload.js.map +12 -0
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/src/plugins/autoreload/client/url_helpers.js +20 -0
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/src/plugins/explorer/client/explorer.html +590 -0
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/src/plugins/explorer/client/explorer.html@L15C5-L20C12.js +7 -0
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/src/plugins/explorer/client/explorer.html@L15C5-L20C12.js.map +12 -0
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/src/plugins/explorer/client/explorer.html@L368C5-L481C14.js +114 -0
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/src/plugins/explorer/client/explorer.html@L482C5-L605C14.js +124 -0
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/src/plugins/explorer/client/explorer.html@L69C5-L299C13.css +227 -0
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/src/plugins/explorer/client/explorer.html@L8C5-L68C13.css +28 -0
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/src/plugins/import_meta_hot/client/import_meta_hot.js +82 -0
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/src/plugins/ribbon/client/ribbon.js +51 -0
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/src/plugins/server_events/client/connection_manager.js +165 -0
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/src/plugins/server_events/client/events_manager.js +75 -0
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/src/plugins/server_events/client/server_events_client.js +20 -0
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/src/plugins/server_events/client/server_events_client.js.map +12 -0
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/src/plugins/server_events/client/web_socket_connection.js +83 -0
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/src/plugins/server_events/client/web_socket_connection.js.map +12 -0
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/src/plugins/supervisor/client/script_type_module_supervisor.js +98 -0
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/src/plugins/supervisor/client/supervisor.js +966 -0
- package/tests/toolbar_basic/main.html +18 -0
- package/tests/toolbar_basic/start_dev_server.mjs +7 -0
- package/todo.txt +0 -0
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
import { setStyles } from "./dom.js"
|
|
2
|
+
|
|
3
|
+
const animateFallback = () => {
|
|
4
|
+
return Promise.resolve()
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
const animateNative = (node, keyframes, { signal, ...options } = {}) => {
|
|
8
|
+
const animation = node.animate(keyframes, options)
|
|
9
|
+
if (signal) {
|
|
10
|
+
signal.addEventListener("abort", () => {
|
|
11
|
+
animation.cancel()
|
|
12
|
+
})
|
|
13
|
+
}
|
|
14
|
+
return new Promise((resolve) => {
|
|
15
|
+
animation.onfinish = resolve
|
|
16
|
+
})
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export const canUseAnimation = () =>
|
|
20
|
+
typeof HTMLElement.prototype.animate === "function"
|
|
21
|
+
|
|
22
|
+
export const animateElement = canUseAnimation()
|
|
23
|
+
? animateNative
|
|
24
|
+
: animateFallback
|
|
25
|
+
|
|
26
|
+
export const fadeIn = (node, options) =>
|
|
27
|
+
animateElement(
|
|
28
|
+
node,
|
|
29
|
+
[
|
|
30
|
+
{
|
|
31
|
+
opacity: 0,
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
opacity: 1,
|
|
35
|
+
},
|
|
36
|
+
],
|
|
37
|
+
options,
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
export const fadeOut = (node, options) =>
|
|
41
|
+
animateElement(
|
|
42
|
+
node,
|
|
43
|
+
[
|
|
44
|
+
{
|
|
45
|
+
opacity: 1,
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
opacity: 0,
|
|
49
|
+
},
|
|
50
|
+
],
|
|
51
|
+
options,
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
export const move = (fromNode, toNode, options) => {
|
|
55
|
+
const fromComputedStyle = window.getComputedStyle(fromNode)
|
|
56
|
+
const toComputedStyle = window.getComputedStyle(toNode)
|
|
57
|
+
// get positions of input in toolbar and aElement
|
|
58
|
+
const fromPosition = fromNode.getBoundingClientRect()
|
|
59
|
+
const toPosition = toNode.getBoundingClientRect()
|
|
60
|
+
|
|
61
|
+
// we'll do the animation in a div preventing overflow and pointer events
|
|
62
|
+
const div = document.createElement("div")
|
|
63
|
+
div.style.position = "absolute"
|
|
64
|
+
div.style.left = 0
|
|
65
|
+
div.style.top = 0
|
|
66
|
+
div.style.width = `${document.documentElement.scrollWidth}px`
|
|
67
|
+
div.style.height = `${document.documentElement.scrollHeight}px`
|
|
68
|
+
div.style.overflow = "hidden"
|
|
69
|
+
div.style.pointerEvents = "none"
|
|
70
|
+
|
|
71
|
+
const documentScroll = {
|
|
72
|
+
left: window.pageXOffset || document.documentElement.scrollLeft,
|
|
73
|
+
top: window.pageYOffset || document.documentElement.scrollTop,
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// clone node and style it
|
|
77
|
+
const copy = fromNode.cloneNode(true)
|
|
78
|
+
copy.style.position = "absolute"
|
|
79
|
+
copy.style.left = `${documentScroll.left + fromPosition.left}px`
|
|
80
|
+
copy.style.top = `${documentScroll.top + fromPosition.top}px`
|
|
81
|
+
copy.style.maxWidth = `${fromPosition.right - fromPosition.left}px`
|
|
82
|
+
copy.style.overflow = toComputedStyle.overflow
|
|
83
|
+
copy.style.textOverflow = toComputedStyle.textOverflow
|
|
84
|
+
div.appendChild(copy)
|
|
85
|
+
document.body.appendChild(div)
|
|
86
|
+
|
|
87
|
+
const left =
|
|
88
|
+
toPosition.left -
|
|
89
|
+
fromPosition.left -
|
|
90
|
+
(parseInt(fromComputedStyle.paddingLeft) || 0)
|
|
91
|
+
const top =
|
|
92
|
+
toPosition.top -
|
|
93
|
+
fromPosition.top -
|
|
94
|
+
(parseInt(fromComputedStyle.paddingTop) || 0)
|
|
95
|
+
// define final position of new element and the duration
|
|
96
|
+
const translate = `translate(${left}px, ${top}px)`
|
|
97
|
+
|
|
98
|
+
// animate new element
|
|
99
|
+
return animateElement(
|
|
100
|
+
copy,
|
|
101
|
+
[
|
|
102
|
+
{
|
|
103
|
+
transform: "translate(0px, 0px)",
|
|
104
|
+
backgroundColor: fromComputedStyle.backgroundColor,
|
|
105
|
+
color: fromComputedStyle.color,
|
|
106
|
+
fontSize: fromComputedStyle.fontSize,
|
|
107
|
+
height: `${fromPosition.bottom - fromPosition.top}px`,
|
|
108
|
+
width: "100%",
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
offset: 0.9,
|
|
112
|
+
backgroundColor: fromComputedStyle.backgroundColor,
|
|
113
|
+
color: fromComputedStyle.color,
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
transform: translate,
|
|
117
|
+
backgroundColor: toComputedStyle.backgroundColor,
|
|
118
|
+
color: toComputedStyle.color,
|
|
119
|
+
fontSize: toComputedStyle.fontSize,
|
|
120
|
+
height: `${toPosition.bottom - toPosition.top}px`,
|
|
121
|
+
width: toComputedStyle.width,
|
|
122
|
+
},
|
|
123
|
+
],
|
|
124
|
+
options,
|
|
125
|
+
).then(() => {
|
|
126
|
+
div.parentNode.removeChild(div)
|
|
127
|
+
})
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// the whole point of this toolbar animation wass to flight a visual imperfection when it's done by css transition.
|
|
131
|
+
// This imperfection is a white line sometimes flickering at the bottom of the page.
|
|
132
|
+
// It got fixed by removing the usage of calc(100vh - 40px)
|
|
133
|
+
// It was hapenning in chrome, safari but not inside Firefox
|
|
134
|
+
// I assume it's because Firefox does not read parent element min-height while
|
|
135
|
+
// chrome use it to compute min-height: 100%
|
|
136
|
+
export const createToolbarAnimation = () => {
|
|
137
|
+
const collapsedState = {
|
|
138
|
+
"#page": { paddingBottom: 0 },
|
|
139
|
+
"footer": { height: 0 },
|
|
140
|
+
"#toolbar": { visibility: "hidden" },
|
|
141
|
+
}
|
|
142
|
+
const expandedState = {
|
|
143
|
+
"#page": { paddingBottom: "40px" },
|
|
144
|
+
"footer": { height: "40px" },
|
|
145
|
+
"#toolbar": { visibility: "visible" },
|
|
146
|
+
}
|
|
147
|
+
const expandTransition = transit(collapsedState, expandedState, {
|
|
148
|
+
duration: 300,
|
|
149
|
+
})
|
|
150
|
+
|
|
151
|
+
const expand = () => {
|
|
152
|
+
expandTransition.play()
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
const collapse = () => {
|
|
156
|
+
expandTransition.reverse()
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
return { expand, collapse }
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
export const transit = (
|
|
163
|
+
fromState,
|
|
164
|
+
toState,
|
|
165
|
+
{ commitStyles = true, fill = "both", duration = 300 } = {},
|
|
166
|
+
) => {
|
|
167
|
+
const steps = []
|
|
168
|
+
Object.keys(fromState).forEach((selector) => {
|
|
169
|
+
const fromStyles = {}
|
|
170
|
+
const toStyles = {}
|
|
171
|
+
const element = document.querySelector(selector)
|
|
172
|
+
|
|
173
|
+
const keyframes = []
|
|
174
|
+
const fromProperties = fromState[selector]
|
|
175
|
+
const toProperties = toState[selector]
|
|
176
|
+
Object.keys(fromProperties).forEach((propertyName) => {
|
|
177
|
+
const from = fromProperties[propertyName]
|
|
178
|
+
const to = toProperties[propertyName]
|
|
179
|
+
fromStyles[propertyName] = from
|
|
180
|
+
toStyles[propertyName] = to
|
|
181
|
+
})
|
|
182
|
+
keyframes.push(fromStyles, toStyles)
|
|
183
|
+
|
|
184
|
+
let animation
|
|
185
|
+
if (canUseAnimation()) {
|
|
186
|
+
const effect = new KeyframeEffect(element, keyframes, { fill, duration })
|
|
187
|
+
animation = new Animation(effect)
|
|
188
|
+
} else {
|
|
189
|
+
animation = {
|
|
190
|
+
playbackRate: 1,
|
|
191
|
+
play: () => {
|
|
192
|
+
animation.onfinish()
|
|
193
|
+
},
|
|
194
|
+
reverse: () => {
|
|
195
|
+
animation.playbackRate = -1
|
|
196
|
+
animation.onfinish()
|
|
197
|
+
},
|
|
198
|
+
finish: () => {},
|
|
199
|
+
onfinish: () => {},
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
steps.push({
|
|
204
|
+
element,
|
|
205
|
+
animation,
|
|
206
|
+
fromStyles,
|
|
207
|
+
toStyles,
|
|
208
|
+
})
|
|
209
|
+
})
|
|
210
|
+
|
|
211
|
+
const play = async () => {
|
|
212
|
+
await Promise.all(
|
|
213
|
+
steps.map(({ animation, element, toStyles }) => {
|
|
214
|
+
return new Promise((resolve) => {
|
|
215
|
+
animation.onfinish = () => {
|
|
216
|
+
if (commitStyles) {
|
|
217
|
+
setStyles(element, toStyles)
|
|
218
|
+
}
|
|
219
|
+
resolve()
|
|
220
|
+
}
|
|
221
|
+
if (animation.playbackRate === -1) {
|
|
222
|
+
animation.reverse()
|
|
223
|
+
} else {
|
|
224
|
+
animation.play()
|
|
225
|
+
}
|
|
226
|
+
})
|
|
227
|
+
}),
|
|
228
|
+
)
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
const reverse = async () => {
|
|
232
|
+
await Promise.all(
|
|
233
|
+
steps.map(({ animation, element, fromStyles }) => {
|
|
234
|
+
return new Promise((resolve) => {
|
|
235
|
+
animation.onfinish = () => {
|
|
236
|
+
if (commitStyles) {
|
|
237
|
+
setStyles(element, fromStyles)
|
|
238
|
+
}
|
|
239
|
+
resolve()
|
|
240
|
+
}
|
|
241
|
+
animation.reverse()
|
|
242
|
+
})
|
|
243
|
+
}),
|
|
244
|
+
)
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
const finish = async () => {
|
|
248
|
+
steps.forEach(({ animation }) => {
|
|
249
|
+
animation.finish()
|
|
250
|
+
})
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
return { play, reverse, finish }
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
export const startJavaScriptAnimation = ({
|
|
257
|
+
duration = 300,
|
|
258
|
+
timingFunction = (t) => t,
|
|
259
|
+
onProgress = () => {},
|
|
260
|
+
onCancel = () => {},
|
|
261
|
+
onComplete = () => {},
|
|
262
|
+
}) => {
|
|
263
|
+
if (isNaN(duration)) {
|
|
264
|
+
// console.warn(`duration must be a number, received ${duration}`)
|
|
265
|
+
return () => {}
|
|
266
|
+
}
|
|
267
|
+
duration = parseInt(duration, 10)
|
|
268
|
+
const startMs = performance.now()
|
|
269
|
+
let currentRequestAnimationFrameId
|
|
270
|
+
let done = false
|
|
271
|
+
let rawProgress = 0
|
|
272
|
+
let progress = 0
|
|
273
|
+
const handler = () => {
|
|
274
|
+
currentRequestAnimationFrameId = null
|
|
275
|
+
const nowMs = performance.now()
|
|
276
|
+
rawProgress = Math.min((nowMs - startMs) / duration, 1)
|
|
277
|
+
progress = timingFunction(rawProgress)
|
|
278
|
+
done = rawProgress === 1
|
|
279
|
+
onProgress({
|
|
280
|
+
done,
|
|
281
|
+
rawProgress,
|
|
282
|
+
progress,
|
|
283
|
+
})
|
|
284
|
+
if (done) {
|
|
285
|
+
onComplete()
|
|
286
|
+
} else {
|
|
287
|
+
currentRequestAnimationFrameId = window.requestAnimationFrame(handler)
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
handler()
|
|
291
|
+
const stop = () => {
|
|
292
|
+
if (currentRequestAnimationFrameId) {
|
|
293
|
+
window.cancelAnimationFrame(currentRequestAnimationFrameId)
|
|
294
|
+
currentRequestAnimationFrameId = null
|
|
295
|
+
}
|
|
296
|
+
if (!done) {
|
|
297
|
+
done = true
|
|
298
|
+
onCancel({
|
|
299
|
+
rawProgress,
|
|
300
|
+
progress,
|
|
301
|
+
})
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
return stop
|
|
305
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
export const updateIframeOverflowOnParentWindow = () => {
|
|
2
|
+
if (!window.parent) {
|
|
3
|
+
// can happen while parent iframe reloads
|
|
4
|
+
return
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
const aTooltipIsOpened =
|
|
8
|
+
document.querySelector("[data-tooltip-visible]") ||
|
|
9
|
+
document.querySelector("[data-tooltip-auto-visible]")
|
|
10
|
+
const settingsAreOpened = document.querySelector("#settings[data-active]")
|
|
11
|
+
|
|
12
|
+
if (aTooltipIsOpened || settingsAreOpened) {
|
|
13
|
+
enableIframeOverflowOnParentWindow()
|
|
14
|
+
} else {
|
|
15
|
+
disableIframeOverflowOnParentWindow()
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
let iframeOverflowEnabled = false
|
|
20
|
+
const enableIframeOverflowOnParentWindow = () => {
|
|
21
|
+
if (iframeOverflowEnabled) return
|
|
22
|
+
iframeOverflowEnabled = true
|
|
23
|
+
|
|
24
|
+
const iframe = getToolbarIframe()
|
|
25
|
+
const transitionDuration = iframe.style.transitionDuration
|
|
26
|
+
setStyles(iframe, { "height": "100%", "transition-duration": "0ms" })
|
|
27
|
+
if (transitionDuration) {
|
|
28
|
+
setTimeout(() => {
|
|
29
|
+
setStyles(iframe, { "transition-duration": transitionDuration })
|
|
30
|
+
})
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const disableIframeOverflowOnParentWindow = () => {
|
|
35
|
+
if (!iframeOverflowEnabled) return
|
|
36
|
+
iframeOverflowEnabled = false
|
|
37
|
+
|
|
38
|
+
const iframe = getToolbarIframe()
|
|
39
|
+
const transitionDuration = iframe.style.transitionDuration
|
|
40
|
+
setStyles(iframe, { "height": "40px", "transition-duration": "0ms" })
|
|
41
|
+
if (transitionDuration) {
|
|
42
|
+
setTimeout(() => {
|
|
43
|
+
setStyles(iframe, { "transition-duration": transitionDuration })
|
|
44
|
+
})
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export const getToolbarIframe = () => {
|
|
49
|
+
const iframes = Array.from(window.parent.document.querySelectorAll("iframe"))
|
|
50
|
+
return iframes.find((iframe) => iframe.contentWindow === window)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export const forceHideElement = (element) => {
|
|
54
|
+
element.setAttribute("data-force-hide", "")
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export const removeForceHideElement = (element) => {
|
|
58
|
+
element.removeAttribute("data-force-hide")
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export const setStyles = (element, styles) => {
|
|
62
|
+
const elementStyle = element.style
|
|
63
|
+
const restoreStyles = Object.keys(styles).map((styleName) => {
|
|
64
|
+
let restore
|
|
65
|
+
if (styleName in elementStyle) {
|
|
66
|
+
const currentStyle = elementStyle[styleName]
|
|
67
|
+
restore = () => {
|
|
68
|
+
elementStyle[styleName] = currentStyle
|
|
69
|
+
}
|
|
70
|
+
} else {
|
|
71
|
+
restore = () => {
|
|
72
|
+
delete elementStyle[styleName]
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
elementStyle[styleName] = styles[styleName]
|
|
77
|
+
|
|
78
|
+
return restore
|
|
79
|
+
})
|
|
80
|
+
return () => {
|
|
81
|
+
restoreStyles.forEach((restore) => restore())
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export const setAttributes = (element, attributes) => {
|
|
86
|
+
Object.keys(attributes).forEach((name) => {
|
|
87
|
+
element.setAttribute(name, attributes[name])
|
|
88
|
+
})
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export const getDocumentScroll = () => {
|
|
92
|
+
return {
|
|
93
|
+
x: document.documentElement.scrollLeft,
|
|
94
|
+
y: document.documentElement.scrollTop,
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export const toolbarSectionIsActive = (element) => {
|
|
99
|
+
return element.hasAttribute("data-active")
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export const activateToolbarSection = (element) => {
|
|
103
|
+
element.setAttribute("data-active", "")
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export const deactivateToolbarSection = (element) => {
|
|
107
|
+
element.removeAttribute("data-active")
|
|
108
|
+
}
|