@banou/media-player 0.8.18 → 0.8.19
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/index.js +26 -6
- package/package.json +1 -1
- package/src/lib/react/components/chrome.tsx +46 -2
package/dist/index.js
CHANGED
|
@@ -2113,16 +2113,36 @@ ${X}
|
|
|
2113
2113
|
item: e
|
|
2114
2114
|
}];
|
|
2115
2115
|
}), ut = ({ ref: e, onVideoRef: t, onCanvasRef: n, overlay: r, controls: i, children: a }) => {
|
|
2116
|
-
let o = R(), s = R((e) => e.hideUI), c = R((e) => e.setHideUI), l = p(void 0), u = p("mouse")
|
|
2116
|
+
let o = R(), s = R((e) => e.hideUI), c = R((e) => e.setHideUI), l = p(void 0), u = p("mouse"), f = p({
|
|
2117
|
+
x: -1,
|
|
2118
|
+
y: -1
|
|
2119
|
+
}), m = p(null);
|
|
2117
2120
|
d(() => () => clearTimeout(l.current), []);
|
|
2118
|
-
let
|
|
2119
|
-
|
|
2121
|
+
let h = (t) => {
|
|
2122
|
+
m.current = t, typeof e == "function" ? e(t) : e && (e.current = t);
|
|
2123
|
+
}, g = () => {
|
|
2124
|
+
if (u.current !== "mouse") return !1;
|
|
2125
|
+
let { x: e, y: t } = f.current;
|
|
2126
|
+
if (!m.current || e < 0) return !1;
|
|
2127
|
+
let n = document.elementFromPoint(e, t);
|
|
2128
|
+
return !!n && m.current.contains(n) && !n.closest(".video");
|
|
2129
|
+
}, _ = () => {
|
|
2130
|
+
if (g()) {
|
|
2131
|
+
l.current = setTimeout(_, ot);
|
|
2132
|
+
return;
|
|
2133
|
+
}
|
|
2134
|
+
c(!0);
|
|
2135
|
+
}, v = () => {
|
|
2136
|
+
c(!1), clearTimeout(l.current), l.current = setTimeout(_, ot);
|
|
2120
2137
|
};
|
|
2121
2138
|
return /* @__PURE__ */ w("div", {
|
|
2122
2139
|
css: ct,
|
|
2123
|
-
ref:
|
|
2140
|
+
ref: h,
|
|
2124
2141
|
onPointerMove: (e) => {
|
|
2125
|
-
u.current = e.pointerType, e.pointerType === "mouse" && f
|
|
2142
|
+
u.current = e.pointerType, e.pointerType === "mouse" && (f.current = {
|
|
2143
|
+
x: e.clientX,
|
|
2144
|
+
y: e.clientY
|
|
2145
|
+
}, v());
|
|
2126
2146
|
},
|
|
2127
2147
|
onPointerDown: (e) => {
|
|
2128
2148
|
u.current = e.pointerType;
|
|
@@ -2154,7 +2174,7 @@ ${X}
|
|
|
2154
2174
|
o.togglePaused();
|
|
2155
2175
|
return;
|
|
2156
2176
|
}
|
|
2157
|
-
s ?
|
|
2177
|
+
s ? v() : (clearTimeout(l.current), c(!0));
|
|
2158
2178
|
},
|
|
2159
2179
|
children: [t ? /* @__PURE__ */ C("video", {
|
|
2160
2180
|
ref: t,
|
package/package.json
CHANGED
|
@@ -108,13 +108,56 @@ export const Chrome = ({ ref, onVideoRef, onCanvasRef, overlay, controls, childr
|
|
|
108
108
|
const autoHide = useRef<ReturnType<typeof setTimeout>>(undefined)
|
|
109
109
|
// a tap and a click mean different things, so the last pointer kind is remembered
|
|
110
110
|
const lastPointerType = useRef<string>('mouse')
|
|
111
|
+
// where the mouse last was, which is where it still is when nothing has moved
|
|
112
|
+
const pointer = useRef({ x: -1, y: -1 })
|
|
113
|
+
const root = useRef<HTMLDivElement | null>(null)
|
|
111
114
|
|
|
112
115
|
useEffect(() => () => clearTimeout(autoHide.current), [])
|
|
113
116
|
|
|
117
|
+
// The caller's ref still gets the element: video.js attaches the fullscreen container through it,
|
|
118
|
+
// and this needs the same node to hit test against.
|
|
119
|
+
const setRoot = (element: HTMLDivElement | null) => {
|
|
120
|
+
root.current = element
|
|
121
|
+
if (typeof ref === 'function') ref(element)
|
|
122
|
+
else if (ref) (ref as { current: HTMLDivElement | null }).current = element
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Is the mouse sitting on something it could press right now?
|
|
127
|
+
*
|
|
128
|
+
* The hide is a timeout on the last MOVEMENT, so a pointer parked on a control still runs it out
|
|
129
|
+
* and the control disappears from under the cursor. Everything then falls through to the video:
|
|
130
|
+
* `elementFromPoint` at the button's own centre returns the `video`, so a click pauses playback
|
|
131
|
+
* and a right click offers the browser's video menu rather than the control's. That is how a link
|
|
132
|
+
* drawn in an overlay stops behaving like a link, which is what this exists to stop.
|
|
133
|
+
*
|
|
134
|
+
* Only what actually takes pointer events can be hit, so this needs no list of selectors: the
|
|
135
|
+
* chrome's own layers opt out, an overlay item opts out until an app opts a child back in, and the
|
|
136
|
+
* picture is excluded here because resting on the picture is exactly when hiding is right.
|
|
137
|
+
*
|
|
138
|
+
* The mouse only. A finger has no resting position, and `elementFromPoint` on the last tap would
|
|
139
|
+
* keep the controls up forever after one press.
|
|
140
|
+
*/
|
|
141
|
+
const pointerRestsOnAControl = () => {
|
|
142
|
+
if (lastPointerType.current !== 'mouse') return false
|
|
143
|
+
const { x, y } = pointer.current
|
|
144
|
+
if (!root.current || x < 0) return false
|
|
145
|
+
const hit = document.elementFromPoint(x, y)
|
|
146
|
+
return !!hit && root.current.contains(hit) && !hit.closest('.video')
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
const hideUnlessTheMouseIsOnAControl = () => {
|
|
150
|
+
if (pointerRestsOnAControl()) {
|
|
151
|
+
autoHide.current = setTimeout(hideUnlessTheMouseIsOnAControl, AUTO_HIDE_DELAY)
|
|
152
|
+
return
|
|
153
|
+
}
|
|
154
|
+
setHideUI(true)
|
|
155
|
+
}
|
|
156
|
+
|
|
114
157
|
const reveal = () => {
|
|
115
158
|
setHideUI(false)
|
|
116
159
|
clearTimeout(autoHide.current)
|
|
117
|
-
autoHide.current = setTimeout(
|
|
160
|
+
autoHide.current = setTimeout(hideUnlessTheMouseIsOnAControl, AUTO_HIDE_DELAY)
|
|
118
161
|
}
|
|
119
162
|
|
|
120
163
|
// Hides after the delay whether or not playback is running. A finger produces no move, so this is
|
|
@@ -122,6 +165,7 @@ export const Chrome = ({ ref, onVideoRef, onCanvasRef, overlay, controls, childr
|
|
|
122
165
|
const onPointerMove = (event: React.PointerEvent<HTMLDivElement>) => {
|
|
123
166
|
lastPointerType.current = event.pointerType
|
|
124
167
|
if (event.pointerType !== 'mouse') return
|
|
168
|
+
pointer.current = { x: event.clientX, y: event.clientY }
|
|
125
169
|
reveal()
|
|
126
170
|
}
|
|
127
171
|
|
|
@@ -157,7 +201,7 @@ export const Chrome = ({ ref, onVideoRef, onCanvasRef, overlay, controls, childr
|
|
|
157
201
|
return (
|
|
158
202
|
<div
|
|
159
203
|
css={style}
|
|
160
|
-
ref={
|
|
204
|
+
ref={setRoot}
|
|
161
205
|
onPointerMove={onPointerMove}
|
|
162
206
|
onPointerDown={onPointerDown}
|
|
163
207
|
onMouseOut={onMouseOut}
|