cb0ad15138
Replaces all icons with the [Phosphor icon set](https://phosphoricons.com/). To accomodate these icons this also touches general style of buttons, headings, and other containers of icons. I want to give a massive shout out to [Niléane](https://nileane.fr/@nileane) and her project [Tangerine UI](https://github.com/nileane/TangerineUI-for-Mastodon). Most of the icons/adjustments I’ve made are based on her choices and work. Reviewed-on: https://codeberg.org/superseriousbusiness/masto-fe-standalone/pulls/77 Contains: commit4cd78295ddAuthor: Zoë Bijl <code@moiety.me> Date: Tue Oct 14 13:57:50 2025 +0200 [bugfix] increase contrast for spoiler link commit4594e776e0Author: Zoë Bijl <code@moiety.me> Date: Tue Oct 14 13:48:05 2025 +0200 [bugfix] increase contrast for “secondary” in light mode Increase the contrast for icons, usernames, and some other places commit7db3518be7Author: Zoë Bijl <code@moiety.me> Date: Tue Oct 14 13:39:36 2025 +0200 [bugfix] increase size of overlayed buttons …such as the hide sensitive content button commit3fd37bbfa5Author: Zoë Bijl <code@moiety.me> Date: Tue Oct 14 13:29:22 2025 +0200 [bugfix] resize three dot menu next to user commit82a4b2b8d9Author: Zoë Bijl <code@moiety.me> Date: Tue Oct 14 13:23:29 2025 +0200 [bugfix] use correct icon name commit470cb995f9Author: Zoë Bijl <code@moiety.me> Date: Tue Oct 14 12:55:27 2025 +0200 [bugfix] add back translation for pin/unpin button https://codeberg.org/superseriousbusiness/masto-fe-standalone/pulls/77#issuecomment-7718876 commit255b64c8f7Author: Zoë Bijl <code@moiety.me> Date: Tue Oct 14 12:22:34 2025 +0200 [bugfix] restore title functionality for icons the `title`-attribute doesn’t work on `<SVG>`-elements. the way to do it is with a nested `<title>`-element. this adds this functionality commit9c25c362fbAuthor: Zoë Bijl <code@moiety.me> Date: Tue Oct 14 11:54:44 2025 +0200 [bugfix] remove import of Icon This gave me an error yesterday i think, but seems fine now, so 🤷🏻♀️. From review: https://codeberg.org/superseriousbusiness/masto-fe-standalone/pulls/77#issuecomment-7719077 commit36065d03fbAuthor: Zoë Bijl <code@moiety.me> Date: Tue Oct 14 10:43:02 2025 +0200 [docs] update changelog commit80cb9ef0c5Author: Zoë Bijl <code@moiety.me> Date: Tue Oct 14 10:09:10 2025 +0200 [bugfix] first pass at deduping and sorting commit59beb08921Author: Zoë Bijl <code@moiety.me> Date: Tue Oct 14 01:59:50 2025 +0200 fix lint issues commit3ffcdffdf1Author: Zoë Bijl <code@moiety.me> Date: Tue Oct 14 01:53:24 2025 +0200 liint commitcda2a62ee5Author: Zoë Bijl <code@moiety.me> Date: Tue Oct 14 01:46:50 2025 +0200 lint commit373b756e8aAuthor: Zoë Bijl <code@moiety.me> Date: Tue Oct 14 00:55:35 2025 +0200 rename calls commitd53ca0d990Author: Zoë Bijl <code@moiety.me> Date: Tue Oct 14 00:52:25 2025 +0200 rename icon components commit07a1e149e1Author: Zoë Bijl <code@moiety.me> Date: Tue Oct 14 00:45:21 2025 +0200 [feature] change _all_ remaining icons commit53fdc6b82fAuthor: Zoë Bijl <code@moiety.me> Date: Mon Oct 13 20:17:04 2025 +0200 [feature] change upload form icons commitd143b433b2Author: Zoë Bijl <code@moiety.me> Date: Mon Oct 13 13:56:27 2025 +0200 [bugfix] allow icon with badge to expand horizontally This allows it to contain more numbers / text. Getting double digit notifications for example. Or the follow request cap '40+' text. commitb737f07676Author: Zoë Bijl <code@moiety.me> Date: Mon Oct 13 13:46:13 2025 +0200 [bugfix] import correct component for “follow request” menu item commit03205b05a9Author: Zoë Bijl <code@moiety.me> Date: Mon Oct 13 13:07:40 2025 +0200 [feature] update follow request icons commit199db8b9afAuthor: Zoë Bijl <code@moiety.me> Date: Mon Oct 13 01:40:23 2025 +0200 [feature] change video player controls commit9fcbf23274Author: Zoë Bijl <code@moiety.me> Date: Sun Oct 12 14:07:37 2025 +0200 [feature] change unlisted status icon to an open padlock Custom made icon based on Phosphor. I flipped the “lock” bit so it’s easier to distinguish. commita359bf4ab1Author: Zoë Bijl <code@moiety.me> Date: Fri Oct 10 17:30:10 2025 +0200 [build] add regex for stylelint/custom-property-pattern Example: https://regex101.com/r/eITX54/1 commit972624b360Author: Zoë Bijl <code@moiety.me> Date: Fri Oct 10 15:52:28 2025 +0200 [build] edit custom-property-pattern commitcaf3c1e41aAuthor: Zoë Bijl <code@moiety.me> Date: Fri Oct 10 15:46:05 2025 +0200 [bugfix] fix media modal icons commit3d2df89ab5Author: Zoë Bijl <code@moiety.me> Date: Fri Oct 10 15:35:59 2025 +0200 [bugfix] correct notification filter bar colours commit36308a2234Author: Zoë Bijl <code@moiety.me> Date: Fri Oct 10 15:30:48 2025 +0200 [bugfix] fix account search result styling commiteea1c0315bAuthor: Zoë Bijl <code@moiety.me> Date: Fri Oct 10 15:30:17 2025 +0200 [bugfix] fix drawer colours commitc2140a4be1Author: Zoë Bijl <code@moiety.me> Date: Fri Oct 10 15:29:37 2025 +0200 [bugfix] fix search styling commit22c7fc2491Author: Zoë Bijl <code@moiety.me> Date: Fri Oct 10 15:28:48 2025 +0200 [feature] change icons to Phosphor commitf1eeb89908Author: Zoë Bijl <code@moiety.me> Date: Fri Oct 10 14:23:29 2025 +0200 [bugfix] properly set colors for lightmode commit7138e11984Author: Zoë Bijl <code@moiety.me> Date: Fri Oct 10 14:22:59 2025 +0200 [feature] use css variables for select component - Search field - Notifications filter bar/account post bar - Status prepend part ('x' boosted) - body background color commitb91f194012Author: Zoë Bijl <code@moiety.me> Date: Fri Oct 10 13:58:45 2025 +0200 [bugfix] set font-weight on account portion of the display name commit49ebf988a4Author: Zoë Bijl <code@moiety.me> Date: Fri Oct 10 12:16:41 2025 +0200 [chore] correct path to login.css commit6433626943Author: Zoë Bijl <code@moiety.me> Date: Fri Oct 10 12:10:54 2025 +0200 [chore] fix lint issues commit9034a3d103Author: Zoë Bijl <code@moiety.me> Date: Fri Oct 10 12:10:38 2025 +0200 [chore] update stylelint rules commit5d5325d067Author: Zoë Bijl <code@moiety.me> Date: Fri Oct 10 12:02:52 2025 +0200 [bugfix] style `.gts-icon-with-badge` Fixes styling for the notification badge commitfbd22639d9Author: Zoë Bijl <code@moiety.me> Date: Fri Oct 10 09:30:14 2025 +0200 icon badge style commit7f1c3fd388Author: Zoë Bijl <code@moiety.me> Date: Fri Oct 10 09:03:07 2025 +0200 [chore] fix lint issues commit5e063da784Author: Zoë Bijl <code@moiety.me> Date: Fri Oct 10 01:01:35 2025 +0200 [feature] change icon for “new list” button commitc22c8ea097Author: Zoë Bijl <code@moiety.me> Date: Thu Oct 9 23:50:28 2025 +0200 [chore] add debug style for `.fa` I want to remove all FontAwesome from the project. This will help find any that are left over. commitf236962403Author: Zoë Bijl <code@moiety.me> Date: Thu Oct 9 23:49:39 2025 +0200 [feature] change “local only” status icon commit94a1ec45c2Author: Zoë Bijl <code@moiety.me> Date: Thu Oct 9 23:31:42 2025 +0200 [bugfix] properly align account buttons commit7adcf93c80Author: Zoë Bijl <code@moiety.me> Date: Thu Oct 9 23:31:25 2025 +0200 [bugfix] set border radius on smaller screens commit8ad4c08069Author: Zoë Bijl <code@moiety.me> Date: Thu Oct 9 23:03:15 2025 +0200 [feature] remove icons from notification purge bar commit457c3c2910Author: Zoë Bijl <code@moiety.me> Date: Thu Oct 9 19:49:49 2025 +0200 [feature] change list edit buttons commit046be63ed6Author: Zoë Bijl <code@moiety.me> Date: Thu Oct 9 18:15:14 2025 +0200 [feature] update dismissible banner icon commit506e59034bAuthor: Zoë Bijl <code@moiety.me> Date: Thu Oct 9 15:08:15 2025 +0200 [feature] change header pin state/move icons commitd97df4b87fAuthor: Zoë Bijl <code@moiety.me> Date: Thu Oct 9 11:42:55 2025 +0200 [chore] fix lint:js errors commitb418204ae3Author: Zoë Bijl <code@moiety.me> Date: Thu Oct 9 09:50:37 2025 +0200 [chore] fix lint:js errors …related to the icons commit415b05d20aAuthor: Zoë Bijl <code@moiety.me> Date: Wed Oct 8 13:44:51 2025 +0200 [feature] replace column move icons commit14f119be65Author: Zoë Bijl <code@moiety.me> Date: Wed Oct 8 13:38:18 2025 +0200 [bugfix] hide overflow text commit6fb2dd73beAuthor: Zoë Bijl <code@moiety.me> Date: Wed Oct 8 12:05:25 2025 +0200 [feature] improve status-prepend display name hover state commitf8f0b403afAuthor: Zoë Bijl <code@moiety.me> Date: Wed Oct 8 11:55:57 2025 +0200 [bugfix] uncomment slim back button styles commit8b254ae288Author: Zoë Bijl <code@moiety.me> Date: Wed Oct 8 11:44:54 2025 +0200 [feature] refactor status styling This does a bunch of stuff: - split out status components into their own file - unify spacing within a status - outline all icons - neatly fade the overflow part of a username - add underlines to username links when appropriate - correctly size all icons in a status - restyle spoiler link (content warning button) commitebfbed0553Author: Zoë Bijl <code@moiety.me> Date: Wed Oct 8 11:40:18 2025 +0200 [feature] change content warning state icon commitf70946ef48Author: Zoë Bijl <code@moiety.me> Date: Wed Oct 8 11:26:22 2025 +0200 [bugfix] remove unnecessary `<span>` commit312b157581Author: Zoë Bijl <code@moiety.me> Date: Wed Oct 8 11:15:07 2025 +0200 [bugfix] correctly align status prepend commit2cd3a82fc7Author: Zoë Bijl <code@moiety.me> Date: Wed Oct 8 11:04:39 2025 +0200 [bugfix] set correct icon state in detailed status view This change was already made for the normal status view. It sets the icon to be filled when a status is boosted or favourited. Also forgoing the need for the Glitch checkmark. commite1c1325905Author: Zoë Bijl <code@moiety.me> Date: Wed Oct 8 11:02:58 2025 +0200 [feature] replace load-gap icon commitd483cab118Author: Zoë Bijl <code@moiety.me> Date: Wed Oct 8 11:00:05 2025 +0200 [feature] align `drawer` and `compose-panel` components - Neatly aligns both the `.drawer` and `.compose-panel` components - Fixes `.search__input` padding when inside the `.compose-panel` commit3c85b02b51Author: Zoë Bijl <code@moiety.me> Date: Wed Oct 8 10:52:37 2025 +0200 [feature] add “sizes” variables file commit7a4b9c6634Author: Zoë Bijl <code@moiety.me> Date: Tue Oct 7 17:26:30 2025 +0200 [feature] space out status action bar items commitebfd05be3dAuthor: Zoë Bijl <code@moiety.me> Date: Tue Oct 7 17:25:49 2025 +0200 [bugfix] remove “sticky” background on focus commita977011b34Author: Zoë Bijl <code@moiety.me> Date: Tue Oct 7 17:24:52 2025 +0200 [feature] refactor status prepend box commit52fbda27edAuthor: Zoë Bijl <code@moiety.me> Date: Tue Oct 7 17:20:44 2025 +0200 [feature] add GTS specific CSS provides a space to place rewritten CSS; should help keep track of what has been done. commit7209169ba9Author: Zoë Bijl <code@moiety.me> Date: Mon Oct 6 13:02:02 2025 +0200 [feature] add animations to status bar icons When activated the status bar (under a toot) icons now do a cute lil animation, courtesy of Tangerine UI. commitc0ea21299fAuthor: Zoë Bijl <code@moiety.me> Date: Sun Oct 5 01:36:12 2025 +0200 [feature] refactor search box / add drawer outlines - add outlines to some UI elements like the timeline and drawers - search “clear” button is now an actual `<button>` commit82cc610ab7Author: Zoë Bijl <code@moiety.me> Date: Sat Oct 4 20:34:17 2025 +0200 [feature] set icons for lists commit004404dc83Author: Zoë Bijl <code@moiety.me> Date: Sat Oct 4 20:33:39 2025 +0200 [feature] refactor local settings navigation item commit9dbc200fd6Author: Zoë Bijl <code@moiety.me> Date: Sat Oct 4 20:32:27 2025 +0200 [feature] refactor column/drawer header commitbeb7a68b5eAuthor: Zoë Bijl <code@moiety.me> Date: Sat Oct 4 20:30:29 2025 +0200 [fix] set correct icon size for action-bar commit6fb994abe6Author: Zoë Bijl <code@moiety.me> Date: Sat Oct 4 20:29:35 2025 +0200 [feature] refactor notifications filter bar commitefaeb5d969Author: Zoë Bijl <code@moiety.me> Date: Sat Oct 4 01:25:42 2025 +0200 [refactor] compose form button bar CSS Complete rewrite of the CSS for the compose form button bar. This makes the buttons and icons sit nicely in the available space. commit18fd2ef39aAuthor: Zoë Bijl <code@moiety.me> Date: Sat Oct 4 01:14:03 2025 +0200 [feat] change unlisted icon from lock to moon Makes easier to distinguish. commit5e16246d56Author: Zoë Bijl <code@moiety.me> Date: Sat Oct 4 01:00:54 2025 +0200 [fix] use `<button>` for emoji button No idea why this was a `<div>`; this works fine in my testing. commit250b415a9dAuthor: Zoë Bijl <code@moiety.me> Date: Sat Oct 4 00:58:16 2025 +0200 [fix] remove inline styling for icon button commitea3106c635Author: Zoë Bijl <code@moiety.me> Date: Fri Oct 3 23:11:38 2025 +0200 [feature] set toot footer icons based on state When you favourite, boost, or bookmark a toot the icons turns into a filled version. commit5a6fd18ec2Author: Zoë Bijl <code@moiety.me> Date: Wed Oct 1 23:48:22 2025 +0200 [feature] add SVG icons commitb62c1f4fc6Author: Zoë Bijl <code@moiety.me> Date: Wed Oct 1 00:56:51 2025 +0200 [feature] add SVG icons # Conflicts: # .editorconfig # Conflicts: # app/javascript/flavours/glitch/components/account.jsx # app/javascript/flavours/glitch/components/column_back_button.jsx # app/javascript/flavours/glitch/components/column_back_button_slim.jsx # app/javascript/flavours/glitch/components/column_header.jsx # app/javascript/flavours/glitch/components/dropdown_menu.jsx # app/javascript/flavours/glitch/components/media_gallery.jsx # app/javascript/flavours/glitch/components/status.jsx # app/javascript/flavours/glitch/components/status_action_bar.jsx # app/javascript/flavours/glitch/components/status_icons.jsx # app/javascript/flavours/glitch/components/status_prepend.jsx # app/javascript/flavours/glitch/components/status_visibility_icon.jsx # app/javascript/flavours/glitch/features/account/components/header.jsx # app/javascript/flavours/glitch/features/audio/index.jsx # app/javascript/flavours/glitch/features/compose/components/dropdown.jsx # app/javascript/flavours/glitch/features/compose/components/dropdown_menu.jsx # app/javascript/flavours/glitch/features/compose/components/emoji_picker_dropdown.jsx # app/javascript/flavours/glitch/features/compose/components/header.jsx # app/javascript/flavours/glitch/features/compose/components/options.jsx # app/javascript/flavours/glitch/features/compose/components/poll_form.jsx # app/javascript/flavours/glitch/features/compose/components/privacy_dropdown.jsx # app/javascript/flavours/glitch/features/compose/components/publisher.jsx # app/javascript/flavours/glitch/features/compose/components/reply_indicator.jsx # app/javascript/flavours/glitch/features/compose/components/search.jsx # app/javascript/flavours/glitch/features/compose/components/textarea_icons.jsx # app/javascript/flavours/glitch/features/favourites/index.jsx # app/javascript/flavours/glitch/features/getting_started/index.jsx # app/javascript/flavours/glitch/features/interaction_modal/index.jsx # app/javascript/flavours/glitch/features/local_settings/navigation/item/index.jsx # app/javascript/flavours/glitch/features/notifications/components/admin_report.jsx # app/javascript/flavours/glitch/features/notifications/components/admin_signup.jsx # app/javascript/flavours/glitch/features/notifications/components/clear_column_button.jsx # app/javascript/flavours/glitch/features/notifications/components/filter_bar.jsx # app/javascript/flavours/glitch/features/notifications/components/follow.jsx # app/javascript/flavours/glitch/features/notifications/components/follow_request.jsx # app/javascript/flavours/glitch/features/notifications/index.jsx # app/javascript/flavours/glitch/features/picture_in_picture/components/footer.jsx # app/javascript/flavours/glitch/features/reblogs/index.jsx # app/javascript/flavours/glitch/features/status/components/action_bar.jsx # app/javascript/flavours/glitch/features/status/components/detailed_status.jsx # app/javascript/flavours/glitch/features/status/index.jsx # app/javascript/flavours/glitch/features/ui/components/column_header.jsx # app/javascript/flavours/glitch/features/ui/components/column_link.jsx # app/javascript/flavours/glitch/features/ui/components/doodle_modal.jsx # app/javascript/flavours/glitch/features/ui/components/embed_modal.jsx # app/javascript/flavours/glitch/features/ui/components/filter_modal.jsx # app/javascript/flavours/glitch/features/ui/components/focal_point_modal.jsx # app/javascript/flavours/glitch/features/ui/components/image_modal.jsx # app/javascript/flavours/glitch/features/ui/components/media_modal.jsx # app/javascript/flavours/glitch/features/ui/components/notifications_counter_icon.js # app/javascript/flavours/glitch/features/ui/components/report_modal.jsx
684 lines
20 KiB
React
684 lines
20 KiB
React
import PropTypes from "prop-types";
|
|
import { PureComponent } from "react";
|
|
|
|
import { defineMessages, injectIntl, FormattedMessage } from "react-intl";
|
|
|
|
import classNames from "classnames";
|
|
|
|
import { is } from "immutable";
|
|
|
|
import { throttle } from "lodash";
|
|
|
|
import { Blurhash } from "flavours/glitch/components/blurhash";
|
|
import { Icon } from "flavours/glitch/components/icon";
|
|
import { displayMedia } from "flavours/glitch/initial_state";
|
|
|
|
import { isFullscreen, requestFullscreen, exitFullscreen } from "../ui/util/fullscreen";
|
|
|
|
const messages = defineMessages({
|
|
play: { id: "video.play", defaultMessage: "Play" },
|
|
pause: { id: "video.pause", defaultMessage: "Pause" },
|
|
mute: { id: "video.mute", defaultMessage: "Mute sound" },
|
|
unmute: { id: "video.unmute", defaultMessage: "Unmute sound" },
|
|
hide: { id: "video.hide", defaultMessage: "Hide video" },
|
|
expand: { id: "video.expand", defaultMessage: "Expand video" },
|
|
close: { id: "video.close", defaultMessage: "Close video" },
|
|
fullscreen: { id: "video.fullscreen", defaultMessage: "Full screen" },
|
|
exit_fullscreen: { id: "video.exit_fullscreen", defaultMessage: "Exit full screen" },
|
|
});
|
|
|
|
export const formatTime = secondsNum => {
|
|
let hours = Math.floor(secondsNum / 3600);
|
|
let minutes = Math.floor((secondsNum - (hours * 3600)) / 60);
|
|
let seconds = secondsNum - (hours * 3600) - (minutes * 60);
|
|
|
|
if (hours < 10) {
|
|
hours = "0" + hours;
|
|
}
|
|
if (minutes < 10) {
|
|
minutes = "0" + minutes;
|
|
}
|
|
if (seconds < 10) {
|
|
seconds = "0" + seconds;
|
|
}
|
|
|
|
return (hours === "00" ? "" : `${hours}:`) + `${minutes}:${seconds}`;
|
|
};
|
|
|
|
export const findElementPosition = el => {
|
|
let box;
|
|
|
|
if (el.getBoundingClientRect && el.parentNode) {
|
|
box = el.getBoundingClientRect();
|
|
}
|
|
|
|
if (!box) {
|
|
return {
|
|
left: 0,
|
|
top: 0,
|
|
};
|
|
}
|
|
|
|
const docEl = document.documentElement;
|
|
const body = document.body;
|
|
|
|
const clientLeft = docEl.clientLeft || body.clientLeft || 0;
|
|
const scrollLeft = window.pageXOffset || body.scrollLeft;
|
|
const left = (box.left + scrollLeft) - clientLeft;
|
|
|
|
const clientTop = docEl.clientTop || body.clientTop || 0;
|
|
const scrollTop = window.pageYOffset || body.scrollTop;
|
|
const top = (box.top + scrollTop) - clientTop;
|
|
|
|
return {
|
|
left: Math.round(left),
|
|
top: Math.round(top),
|
|
};
|
|
};
|
|
|
|
export const getPointerPosition = (el, event) => {
|
|
const position = {};
|
|
const box = findElementPosition(el);
|
|
const boxW = el.offsetWidth;
|
|
const boxH = el.offsetHeight;
|
|
const boxY = box.top;
|
|
const boxX = box.left;
|
|
|
|
let pageY = event.pageY;
|
|
let pageX = event.pageX;
|
|
|
|
if (event.changedTouches) {
|
|
pageX = event.changedTouches[0].pageX;
|
|
pageY = event.changedTouches[0].pageY;
|
|
}
|
|
|
|
position.y = Math.max(0, Math.min(1, (pageY - boxY) / boxH));
|
|
position.x = Math.max(0, Math.min(1, (pageX - boxX) / boxW));
|
|
|
|
return position;
|
|
};
|
|
|
|
export const fileNameFromURL = str => {
|
|
const url = new URL(str);
|
|
const pathname = url.pathname;
|
|
const index = pathname.lastIndexOf("/");
|
|
|
|
return pathname.slice(index + 1);
|
|
};
|
|
|
|
class Video extends PureComponent {
|
|
|
|
static propTypes = {
|
|
preview: PropTypes.string,
|
|
frameRate: PropTypes.string,
|
|
src: PropTypes.string.isRequired,
|
|
alt: PropTypes.string,
|
|
lang: PropTypes.string,
|
|
sensitive: PropTypes.bool,
|
|
currentTime: PropTypes.number,
|
|
onOpenVideo: PropTypes.func,
|
|
onCloseVideo: PropTypes.func,
|
|
detailed: PropTypes.bool,
|
|
inline: PropTypes.bool,
|
|
editable: PropTypes.bool,
|
|
alwaysVisible: PropTypes.bool,
|
|
visible: PropTypes.bool,
|
|
letterbox: PropTypes.bool,
|
|
fullwidth: PropTypes.bool,
|
|
preventPlayback: PropTypes.bool,
|
|
onToggleVisibility: PropTypes.func,
|
|
deployPictureInPicture: PropTypes.func,
|
|
intl: PropTypes.object.isRequired,
|
|
blurhash: PropTypes.string,
|
|
autoPlay: PropTypes.bool,
|
|
volume: PropTypes.number,
|
|
muted: PropTypes.bool,
|
|
componentIndex: PropTypes.number,
|
|
autoFocus: PropTypes.bool,
|
|
useBlurhash: PropTypes.bool,
|
|
};
|
|
|
|
static defaultProps = {
|
|
frameRate: "25",
|
|
};
|
|
|
|
state = {
|
|
currentTime: 0,
|
|
duration: 0,
|
|
volume: 0.5,
|
|
paused: true,
|
|
dragging: false,
|
|
fullscreen: false,
|
|
hovered: false,
|
|
muted: false,
|
|
revealed: this.props.visible !== undefined ? this.props.visible : (displayMedia !== "hide_all" && !this.props.sensitive || displayMedia === "show_all"),
|
|
};
|
|
|
|
setPlayerRef = c => {
|
|
this.player = c;
|
|
};
|
|
|
|
setVideoRef = c => {
|
|
this.video = c;
|
|
|
|
if (this.video) {
|
|
this.setState({ volume: this.video.volume, muted: this.video.muted });
|
|
}
|
|
};
|
|
|
|
setSeekRef = c => {
|
|
this.seek = c;
|
|
};
|
|
|
|
setVolumeRef = c => {
|
|
this.volume = c;
|
|
};
|
|
|
|
handleClickRoot = e => e.stopPropagation();
|
|
|
|
handlePlay = () => {
|
|
this.setState({ paused: false });
|
|
this._updateTime();
|
|
};
|
|
|
|
handlePause = () => {
|
|
this.setState({ paused: true });
|
|
};
|
|
|
|
_updateTime () {
|
|
requestAnimationFrame(() => {
|
|
if (!this.video) {
|
|
return;
|
|
}
|
|
|
|
this.handleTimeUpdate();
|
|
|
|
if (!this.state.paused) {
|
|
this._updateTime();
|
|
}
|
|
});
|
|
}
|
|
|
|
handleTimeUpdate = () => {
|
|
this.setState({
|
|
currentTime: this.video.currentTime,
|
|
duration:this.video.duration,
|
|
});
|
|
};
|
|
|
|
handleVolumeMouseDown = e => {
|
|
document.addEventListener("mousemove", this.handleMouseVolSlide, true);
|
|
document.addEventListener("mouseup", this.handleVolumeMouseUp, true);
|
|
document.addEventListener("touchmove", this.handleMouseVolSlide, true);
|
|
document.addEventListener("touchend", this.handleVolumeMouseUp, true);
|
|
|
|
this.handleMouseVolSlide(e);
|
|
|
|
e.preventDefault();
|
|
e.stopPropagation();
|
|
};
|
|
|
|
handleVolumeMouseUp = () => {
|
|
document.removeEventListener("mousemove", this.handleMouseVolSlide, true);
|
|
document.removeEventListener("mouseup", this.handleVolumeMouseUp, true);
|
|
document.removeEventListener("touchmove", this.handleMouseVolSlide, true);
|
|
document.removeEventListener("touchend", this.handleVolumeMouseUp, true);
|
|
};
|
|
|
|
handleMouseVolSlide = throttle(e => {
|
|
const { x } = getPointerPosition(this.volume, e);
|
|
|
|
if(!isNaN(x)) {
|
|
this.setState((state) => ({ volume: x, muted: state.muted && x === 0 }), () => {
|
|
this.video.volume = x;
|
|
this.video.muted = this.state.muted;
|
|
});
|
|
}
|
|
}, 15);
|
|
|
|
handleMouseDown = e => {
|
|
document.addEventListener("mousemove", this.handleMouseMove, true);
|
|
document.addEventListener("mouseup", this.handleMouseUp, true);
|
|
document.addEventListener("touchmove", this.handleMouseMove, true);
|
|
document.addEventListener("touchend", this.handleMouseUp, true);
|
|
|
|
this.setState({ dragging: true });
|
|
this.video.pause();
|
|
this.handleMouseMove(e);
|
|
|
|
e.preventDefault();
|
|
e.stopPropagation();
|
|
};
|
|
|
|
handleMouseUp = () => {
|
|
document.removeEventListener("mousemove", this.handleMouseMove, true);
|
|
document.removeEventListener("mouseup", this.handleMouseUp, true);
|
|
document.removeEventListener("touchmove", this.handleMouseMove, true);
|
|
document.removeEventListener("touchend", this.handleMouseUp, true);
|
|
|
|
this.setState({ dragging: false });
|
|
this.video.play();
|
|
};
|
|
|
|
handleMouseMove = throttle(e => {
|
|
const { x } = getPointerPosition(this.seek, e);
|
|
const currentTime = this.video.duration * x;
|
|
|
|
if (!isNaN(currentTime)) {
|
|
this.setState({ currentTime }, () => {
|
|
this.video.currentTime = currentTime;
|
|
});
|
|
}
|
|
}, 15);
|
|
|
|
seekBy (time) {
|
|
const currentTime = this.video.currentTime + time;
|
|
|
|
if (!isNaN(currentTime)) {
|
|
this.setState({ currentTime }, () => {
|
|
this.video.currentTime = currentTime;
|
|
});
|
|
}
|
|
}
|
|
|
|
handleVideoKeyDown = e => {
|
|
// On the video element or the seek bar, we can safely use the space bar
|
|
// for playback control because there are no buttons to press
|
|
|
|
if (e.key === " ") {
|
|
e.preventDefault();
|
|
e.stopPropagation();
|
|
this.togglePlay();
|
|
}
|
|
};
|
|
|
|
handleKeyDown = e => {
|
|
const frameTime = 1 / this.getFrameRate();
|
|
|
|
switch(e.key) {
|
|
case "k":
|
|
e.preventDefault();
|
|
e.stopPropagation();
|
|
this.togglePlay();
|
|
break;
|
|
case "m":
|
|
e.preventDefault();
|
|
e.stopPropagation();
|
|
this.toggleMute();
|
|
break;
|
|
case "f":
|
|
e.preventDefault();
|
|
e.stopPropagation();
|
|
this.toggleFullscreen();
|
|
break;
|
|
case "j":
|
|
e.preventDefault();
|
|
e.stopPropagation();
|
|
this.seekBy(-10);
|
|
break;
|
|
case "l":
|
|
e.preventDefault();
|
|
e.stopPropagation();
|
|
this.seekBy(10);
|
|
break;
|
|
case ",":
|
|
e.preventDefault();
|
|
e.stopPropagation();
|
|
this.seekBy(-frameTime);
|
|
break;
|
|
case ".":
|
|
e.preventDefault();
|
|
e.stopPropagation();
|
|
this.seekBy(frameTime);
|
|
break;
|
|
}
|
|
|
|
// If we are in fullscreen mode, we don't want any hotkeys
|
|
// interacting with the UI that's not visible
|
|
|
|
if (this.state.fullscreen) {
|
|
e.preventDefault();
|
|
e.stopPropagation();
|
|
|
|
if (e.key === "Escape") {
|
|
exitFullscreen();
|
|
}
|
|
}
|
|
};
|
|
|
|
togglePlay = () => {
|
|
if (this.state.paused) {
|
|
this.setState({ paused: false }, () => this.video.play());
|
|
} else {
|
|
this.setState({ paused: true }, () => this.video.pause());
|
|
}
|
|
};
|
|
|
|
toggleFullscreen = () => {
|
|
if (isFullscreen()) {
|
|
exitFullscreen();
|
|
} else {
|
|
requestFullscreen(this.player);
|
|
}
|
|
};
|
|
|
|
componentDidMount () {
|
|
document.addEventListener("fullscreenchange", this.handleFullscreenChange, true);
|
|
document.addEventListener("webkitfullscreenchange", this.handleFullscreenChange, true);
|
|
document.addEventListener("mozfullscreenchange", this.handleFullscreenChange, true);
|
|
document.addEventListener("MSFullscreenChange", this.handleFullscreenChange, true);
|
|
|
|
window.addEventListener("scroll", this.handleScroll);
|
|
}
|
|
|
|
componentWillUnmount () {
|
|
window.removeEventListener("scroll", this.handleScroll);
|
|
|
|
document.removeEventListener("fullscreenchange", this.handleFullscreenChange, true);
|
|
document.removeEventListener("webkitfullscreenchange", this.handleFullscreenChange, true);
|
|
document.removeEventListener("mozfullscreenchange", this.handleFullscreenChange, true);
|
|
document.removeEventListener("MSFullscreenChange", this.handleFullscreenChange, true);
|
|
|
|
if (!this.state.paused && this.video && this.props.deployPictureInPicture) {
|
|
this.props.deployPictureInPicture("video", {
|
|
src: this.props.src,
|
|
currentTime: this.video.currentTime,
|
|
muted: this.video.muted,
|
|
volume: this.video.volume,
|
|
});
|
|
}
|
|
}
|
|
|
|
UNSAFE_componentWillReceiveProps (nextProps) {
|
|
if (!is(nextProps.visible, this.props.visible) && nextProps.visible !== undefined) {
|
|
this.setState({ revealed: nextProps.visible });
|
|
}
|
|
}
|
|
|
|
componentDidUpdate (prevProps) {
|
|
if (this.video && this.state.revealed && this.props.preventPlayback && !prevProps.preventPlayback) {
|
|
this.video.pause();
|
|
}
|
|
}
|
|
|
|
handleScroll = throttle(() => {
|
|
if (!this.video) {
|
|
return;
|
|
}
|
|
|
|
const { top, height } = this.video.getBoundingClientRect();
|
|
const inView = (top <= (window.innerHeight || document.documentElement.clientHeight)) && (top + height >= 0);
|
|
|
|
if (!this.state.paused && !inView) {
|
|
this.video.pause();
|
|
|
|
if (this.props.deployPictureInPicture) {
|
|
this.props.deployPictureInPicture("video", {
|
|
src: this.props.src,
|
|
currentTime: this.video.currentTime,
|
|
muted: this.video.muted,
|
|
volume: this.video.volume,
|
|
});
|
|
}
|
|
|
|
this.setState({ paused: true });
|
|
}
|
|
}, 150, { trailing: true });
|
|
|
|
handleFullscreenChange = () => {
|
|
this.setState({ fullscreen: isFullscreen() });
|
|
};
|
|
|
|
handleMouseEnter = () => {
|
|
this.setState({ hovered: true });
|
|
};
|
|
|
|
handleMouseLeave = () => {
|
|
this.setState({ hovered: false });
|
|
};
|
|
|
|
toggleMute = () => {
|
|
const muted = !(this.video.muted || this.state.volume === 0);
|
|
|
|
this.setState((state) => ({ muted, volume: Math.max(state.volume || 0.5, 0.05) }), () => {
|
|
this.video.volume = this.state.volume;
|
|
this.video.muted = this.state.muted;
|
|
});
|
|
};
|
|
|
|
toggleReveal = () => {
|
|
if (this.state.revealed) {
|
|
this.setState({ paused: true });
|
|
}
|
|
|
|
if (this.props.onToggleVisibility) {
|
|
this.props.onToggleVisibility();
|
|
} else {
|
|
this.setState({ revealed: !this.state.revealed });
|
|
}
|
|
};
|
|
|
|
handleLoadedData = () => {
|
|
const { currentTime, volume, muted, autoPlay } = this.props;
|
|
|
|
if (currentTime) {
|
|
this.video.currentTime = currentTime;
|
|
}
|
|
|
|
if (volume !== undefined) {
|
|
this.video.volume = volume;
|
|
}
|
|
|
|
if (muted !== undefined) {
|
|
this.video.muted = muted;
|
|
}
|
|
|
|
if (autoPlay) {
|
|
this.video.play();
|
|
}
|
|
};
|
|
|
|
handleProgress = () => {
|
|
const lastTimeRange = this.video.buffered.length - 1;
|
|
|
|
if (lastTimeRange > -1) {
|
|
this.setState({ buffer: Math.ceil(this.video.buffered.end(lastTimeRange) / this.video.duration * 100) });
|
|
}
|
|
};
|
|
|
|
handleVolumeChange = () => {
|
|
this.setState({ volume: this.video.volume, muted: this.video.muted });
|
|
};
|
|
|
|
handleOpenVideo = () => {
|
|
this.video.pause();
|
|
|
|
this.props.onOpenVideo(this.props.lang, {
|
|
startTime: this.video.currentTime,
|
|
autoPlay: !this.state.paused,
|
|
defaultVolume: this.state.volume,
|
|
componentIndex: this.props.componentIndex,
|
|
});
|
|
};
|
|
|
|
handleCloseVideo = () => {
|
|
this.video.pause();
|
|
this.props.onCloseVideo();
|
|
};
|
|
|
|
getFrameRate () {
|
|
if (this.props.frameRate && isNaN(this.props.frameRate)) {
|
|
// The frame rate is returned as a fraction string so we
|
|
// need to convert it to a number
|
|
|
|
return this.props.frameRate.split("/").reduce((p, c) => p / c);
|
|
}
|
|
|
|
return this.props.frameRate;
|
|
}
|
|
|
|
render () {
|
|
const {
|
|
preview,
|
|
src,
|
|
inline,
|
|
onOpenVideo,
|
|
onCloseVideo,
|
|
intl,
|
|
alt,
|
|
lang,
|
|
letterbox,
|
|
fullwidth,
|
|
detailed,
|
|
sensitive,
|
|
editable,
|
|
blurhash,
|
|
autoFocus,
|
|
useBlurhash,
|
|
} = this.props;
|
|
const {
|
|
currentTime,
|
|
duration,
|
|
volume,
|
|
buffer,
|
|
dragging,
|
|
paused,
|
|
fullscreen,
|
|
hovered,
|
|
revealed,
|
|
} = this.state;
|
|
const progress = Math.min((currentTime / duration) * 100, 100);
|
|
const muted = this.state.muted || volume === 0;
|
|
|
|
const playerStyle = {};
|
|
|
|
if (inline) {
|
|
playerStyle.aspectRatio = "16 / 9";
|
|
}
|
|
|
|
let preload;
|
|
|
|
if (this.props.currentTime || fullscreen || dragging) {
|
|
preload = "auto";
|
|
} else if (detailed) {
|
|
preload = "metadata";
|
|
} else {
|
|
preload = "none";
|
|
}
|
|
|
|
let warning;
|
|
|
|
if (sensitive) {
|
|
warning = <FormattedMessage id='status.sensitive_warning' defaultMessage='Sensitive content' />;
|
|
} else {
|
|
warning = <FormattedMessage id='status.media_hidden' defaultMessage='Media hidden' />;
|
|
}
|
|
|
|
return (
|
|
<div
|
|
role='menuitem'
|
|
className={classNames("video-player", { inactive: !revealed, detailed, inline: inline && !fullscreen, fullscreen, editable, letterbox, "full-width": fullwidth })}
|
|
style={playerStyle}
|
|
ref={this.setPlayerRef}
|
|
onMouseEnter={this.handleMouseEnter}
|
|
onMouseLeave={this.handleMouseLeave}
|
|
onClick={this.handleClickRoot}
|
|
onKeyDown={this.handleKeyDown}
|
|
tabIndex={0}
|
|
>
|
|
<Blurhash
|
|
hash={blurhash}
|
|
className={classNames("media-gallery__preview", {
|
|
"media-gallery__preview--hidden": revealed,
|
|
})}
|
|
dummy={!useBlurhash}
|
|
/>
|
|
|
|
{(revealed || editable) && <video
|
|
ref={this.setVideoRef}
|
|
src={src}
|
|
poster={preview}
|
|
preload={preload}
|
|
role='button'
|
|
tabIndex={0}
|
|
aria-label={alt}
|
|
title={alt}
|
|
lang={lang}
|
|
volume={volume}
|
|
onClick={this.togglePlay}
|
|
onKeyDown={this.handleVideoKeyDown}
|
|
onPlay={this.handlePlay}
|
|
onPause={this.handlePause}
|
|
onLoadedData={this.handleLoadedData}
|
|
onProgress={this.handleProgress}
|
|
onVolumeChange={this.handleVolumeChange}
|
|
style={{ ...playerStyle, width: "100%" }}
|
|
/>}
|
|
|
|
<div className={classNames("spoiler-button", { "spoiler-button--hidden": revealed || editable })}>
|
|
<button type='button' className='spoiler-button__overlay' onClick={this.toggleReveal}>
|
|
<span className='spoiler-button__overlay__label'>
|
|
{warning}
|
|
<span className='spoiler-button__overlay__action'><FormattedMessage id='status.media.show' defaultMessage='Click to show' /></span>
|
|
</span>
|
|
</button>
|
|
</div>
|
|
|
|
<div className={classNames("video-player__controls", { active: paused || hovered })}>
|
|
<div className='video-player__seek' onMouseDown={this.handleMouseDown} ref={this.setSeekRef}>
|
|
<div className='video-player__seek__buffer' style={{ width: `${buffer}%` }} />
|
|
<div className='video-player__seek__progress' style={{ width: `${progress}%` }} />
|
|
|
|
<span
|
|
className={classNames("video-player__seek__handle", { active: dragging })}
|
|
tabIndex={0}
|
|
style={{ left: `${progress}%` }}
|
|
onKeyDown={this.handleVideoKeyDown}
|
|
/>
|
|
</div>
|
|
|
|
<div className='video-player__buttons-bar'>
|
|
<div className='video-player__buttons left'>
|
|
<button type='button' title={intl.formatMessage(paused ? messages.play : messages.pause)} aria-label={intl.formatMessage(paused ? messages.play : messages.pause)} className='player-button' onClick={this.togglePlay} autoFocus={autoFocus}>
|
|
<Icon id={paused ? "play" : "pause"} fixedWidth />
|
|
</button>
|
|
|
|
<button type='button' title={intl.formatMessage(muted ? messages.unmute : messages.mute)} aria-label={intl.formatMessage(muted ? messages.unmute : messages.mute)} className='player-button' onClick={this.toggleMute}>
|
|
<Icon id={muted ? "speaker-slash" : "speaker-high"} fixedWidth />
|
|
</button>
|
|
|
|
<div className={classNames("video-player__volume", { active: this.state.hovered })} onMouseDown={this.handleVolumeMouseDown} ref={this.setVolumeRef}>
|
|
<div className='video-player__volume__current' style={{ width: `${muted ? 0 : volume * 100}%` }} />
|
|
|
|
<span
|
|
className={classNames("video-player__volume__handle")}
|
|
tabIndex={0}
|
|
style={{ left: `${muted ? 0 : volume * 100}%` }}
|
|
/>
|
|
</div>
|
|
|
|
{(detailed || fullscreen) && (
|
|
<span className='video-player__time'>
|
|
<span className='video-player__time-current'>{formatTime(Math.floor(currentTime))}</span>
|
|
<span className='video-player__time-sep'>/</span>
|
|
<span className='video-player__time-total'>{formatTime(Math.floor(duration))}</span>
|
|
</span>
|
|
)}
|
|
</div>
|
|
|
|
<div className='video-player__buttons right'>
|
|
{(!onCloseVideo && !editable && !fullscreen && !this.props.alwaysVisible) && <button type='button' title={intl.formatMessage(messages.hide)} aria-label={intl.formatMessage(messages.hide)} className='player-button' onClick={this.toggleReveal}><Icon id='eye-slash-filled' fixedWidth /></button>}
|
|
{(!fullscreen && onOpenVideo) && <button type='button' title={intl.formatMessage(messages.expand)} aria-label={intl.formatMessage(messages.expand)} className='player-button' onClick={this.handleOpenVideo}><Icon id='arrows-out-simple' fixedWidth /></button>}
|
|
{onCloseVideo && <button type='button' title={intl.formatMessage(messages.close)} aria-label={intl.formatMessage(messages.close)} className='player-button' onClick={this.handleCloseVideo}><Icon id='arrows-in-simple' fixedWidth /></button>}
|
|
<button type='button' title={intl.formatMessage(fullscreen ? messages.exit_fullscreen : messages.fullscreen)} aria-label={intl.formatMessage(fullscreen ? messages.exit_fullscreen : messages.fullscreen)} className='player-button' onClick={this.toggleFullscreen}><Icon id={fullscreen ? "arrows-in-simple" : "frame-corners"} fixedWidth /></button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
}
|
|
|
|
export default injectIntl(Video);
|