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
632 lines
17 KiB
React
632 lines
17 KiB
React
import PropTypes from "prop-types";
|
||
|
||
import classNames from "classnames";
|
||
|
||
import ImmutablePropTypes from "react-immutable-proptypes";
|
||
import ImmutablePureComponent from "react-immutable-pure-component";
|
||
import { connect } from "react-redux";
|
||
|
||
import Atrament from "atrament"; // the doodling library
|
||
import { debounce, mapValues } from "lodash";
|
||
|
||
import { doodleSet, uploadCompose } from "flavours/glitch/actions/compose";
|
||
import Button from "flavours/glitch/components/button";
|
||
import { IconButton } from "flavours/glitch/components/icon_button";
|
||
// palette nicked from MyPaint, CC0
|
||
const palette = [
|
||
["rgb( 0, 0, 0)", "Black"],
|
||
["rgb( 38, 38, 38)", "Gray 15"],
|
||
["rgb( 77, 77, 77)", "Grey 30"],
|
||
["rgb(128, 128, 128)", "Grey 50"],
|
||
["rgb(171, 171, 171)", "Grey 67"],
|
||
["rgb(217, 217, 217)", "Grey 85"],
|
||
["rgb(255, 255, 255)", "White"],
|
||
["rgb(128, 0, 0)", "Maroon"],
|
||
["rgb(209, 0, 0)", "English-red"],
|
||
["rgb(255, 54, 34)", "Tomato"],
|
||
["rgb(252, 60, 3)", "Orange-red"],
|
||
["rgb(255, 140, 105)", "Salmon"],
|
||
["rgb(252, 232, 32)", "Cadium-yellow"],
|
||
["rgb(243, 253, 37)", "Lemon yellow"],
|
||
["rgb(121, 5, 35)", "Dark crimson"],
|
||
["rgb(169, 32, 62)", "Deep carmine"],
|
||
["rgb(255, 140, 0)", "Orange"],
|
||
["rgb(255, 168, 18)", "Dark tangerine"],
|
||
["rgb(217, 144, 88)", "Persian orange"],
|
||
["rgb(194, 178, 128)", "Sand"],
|
||
["rgb(255, 229, 180)", "Peach"],
|
||
["rgb(100, 54, 46)", "Bole"],
|
||
["rgb(108, 41, 52)", "Dark cordovan"],
|
||
["rgb(163, 65, 44)", "Chestnut"],
|
||
["rgb(228, 136, 100)", "Dark salmon"],
|
||
["rgb(255, 195, 143)", "Apricot"],
|
||
["rgb(255, 219, 188)", "Unbleached silk"],
|
||
["rgb(242, 227, 198)", "Straw"],
|
||
["rgb( 53, 19, 13)", "Bistre"],
|
||
["rgb( 84, 42, 14)", "Dark chocolate"],
|
||
["rgb(102, 51, 43)", "Burnt sienna"],
|
||
["rgb(184, 66, 0)", "Sienna"],
|
||
["rgb(216, 153, 12)", "Yellow ochre"],
|
||
["rgb(210, 180, 140)", "Tan"],
|
||
["rgb(232, 204, 144)", "Dark wheat"],
|
||
["rgb( 0, 49, 83)", "Prussian blue"],
|
||
["rgb( 48, 69, 119)", "Dark grey blue"],
|
||
["rgb( 0, 71, 171)", "Cobalt blue"],
|
||
["rgb( 31, 117, 254)", "Blue"],
|
||
["rgb(120, 180, 255)", "Bright french blue"],
|
||
["rgb(171, 200, 255)", "Bright steel blue"],
|
||
["rgb(208, 231, 255)", "Ice blue"],
|
||
["rgb( 30, 51, 58)", "Medium jungle green"],
|
||
["rgb( 47, 79, 79)", "Dark slate grey"],
|
||
["rgb( 74, 104, 93)", "Dark grullo green"],
|
||
["rgb( 0, 128, 128)", "Teal"],
|
||
["rgb( 67, 170, 176)", "Turquoise"],
|
||
["rgb(109, 174, 199)", "Cerulean frost"],
|
||
["rgb(173, 217, 186)", "Tiffany green"],
|
||
["rgb( 22, 34, 29)", "Gray-asparagus"],
|
||
["rgb( 36, 48, 45)", "Medium dark teal"],
|
||
["rgb( 74, 104, 93)", "Xanadu"],
|
||
["rgb(119, 198, 121)", "Mint"],
|
||
["rgb(175, 205, 182)", "Timberwolf"],
|
||
["rgb(185, 245, 246)", "Celeste"],
|
||
["rgb(193, 255, 234)", "Aquamarine"],
|
||
["rgb( 29, 52, 35)", "Cal Poly Pomona"],
|
||
["rgb( 1, 68, 33)", "Forest green"],
|
||
["rgb( 42, 128, 0)", "Napier green"],
|
||
["rgb(128, 128, 0)", "Olive"],
|
||
["rgb( 65, 156, 105)", "Sea green"],
|
||
["rgb(189, 246, 29)", "Green-yellow"],
|
||
["rgb(231, 244, 134)", "Bright chartreuse"],
|
||
["rgb(138, 23, 137)", "Purple"],
|
||
["rgb( 78, 39, 138)", "Violet"],
|
||
["rgb(193, 75, 110)", "Dark thulian pink"],
|
||
["rgb(222, 49, 99)", "Cerise"],
|
||
["rgb(255, 20, 147)", "Deep pink"],
|
||
["rgb(255, 102, 204)", "Rose pink"],
|
||
["rgb(255, 203, 219)", "Pink"],
|
||
["rgb(255, 255, 255)", "White"],
|
||
["rgb(229, 17, 1)", "RGB Red"],
|
||
["rgb( 0, 255, 0)", "RGB Green"],
|
||
["rgb( 0, 0, 255)", "RGB Blue"],
|
||
["rgb( 0, 255, 255)", "CMYK Cyan"],
|
||
["rgb(255, 0, 255)", "CMYK Magenta"],
|
||
["rgb(255, 255, 0)", "CMYK Yellow"],
|
||
];
|
||
|
||
// re-arrange to the right order for display
|
||
let palReordered = [];
|
||
for (let row = 0; row < 7; row++) {
|
||
for (let col = 0; col < 11; col++) {
|
||
palReordered.push(palette[col * 7 + row]);
|
||
}
|
||
palReordered.push(null); // null indicates a <br />
|
||
}
|
||
|
||
// Utility for converting base64 image to binary for upload
|
||
// https://stackoverflow.com/questions/35940290/how-to-convert-base64-string-to-javascript-file-object-like-as-from-file-input-f
|
||
function dataURLtoFile(dataurl, filename) {
|
||
let arr = dataurl.split(","), mime = arr[0].match(/:(.*?);/)[1],
|
||
bstr = atob(arr[1]), n = bstr.length, u8arr = new Uint8Array(n);
|
||
while(n--){
|
||
u8arr[n] = bstr.charCodeAt(n);
|
||
}
|
||
return new File([u8arr], filename, { type: mime });
|
||
}
|
||
/** Doodle canvas size options */
|
||
const DOODLE_SIZES = {
|
||
normal: [500, 500, "Square 500"],
|
||
tootbanner: [702, 330, "Tootbanner"],
|
||
s640x480: [640, 480, "640×480 - 480p"],
|
||
s800x600: [800, 600, "800×600 - SVGA"],
|
||
s720x480: [720, 405, "720x405 - 16:9"],
|
||
};
|
||
|
||
|
||
const mapStateToProps = state => ({
|
||
options: state.getIn(["compose", "doodle"]),
|
||
});
|
||
|
||
const mapDispatchToProps = dispatch => ({
|
||
/**
|
||
* Set options in the redux store
|
||
* @param {Object} opts
|
||
*/
|
||
setOpt: (opts) => dispatch(doodleSet(opts)),
|
||
/**
|
||
* Submit doodle for upload
|
||
* @param {File} file
|
||
*/
|
||
submit: (file) => dispatch(uploadCompose([file])),
|
||
});
|
||
|
||
/**
|
||
* Doodling dialog with drawing canvas
|
||
*
|
||
* Keyboard shortcuts:
|
||
* - Delete: Clear screen, fill with background color
|
||
* - Backspace, Ctrl+Z: Undo one step
|
||
* - Ctrl held while drawing: Use background color
|
||
* - Shift held while clicking screen: Use fill tool
|
||
*
|
||
* Palette:
|
||
* - Left mouse button: pick foreground
|
||
* - Ctrl + left mouse button: pick background
|
||
* - Right mouse button: pick background
|
||
*/
|
||
class DoodleModal extends ImmutablePureComponent {
|
||
|
||
static propTypes = {
|
||
options: ImmutablePropTypes.map,
|
||
onClose: PropTypes.func.isRequired,
|
||
setOpt: PropTypes.func.isRequired,
|
||
submit: PropTypes.func.isRequired,
|
||
};
|
||
|
||
//region Option getters/setters
|
||
|
||
/** Foreground color */
|
||
get fg () {
|
||
return this.props.options.get("fg");
|
||
}
|
||
set fg (value) {
|
||
this.props.setOpt({ fg: value });
|
||
}
|
||
|
||
/** Background color */
|
||
get bg () {
|
||
return this.props.options.get("bg");
|
||
}
|
||
set bg (value) {
|
||
this.props.setOpt({ bg: value });
|
||
}
|
||
|
||
/** Swap Fg and Bg for drawing */
|
||
get swapped () {
|
||
return this.props.options.get("swapped");
|
||
}
|
||
set swapped (value) {
|
||
this.props.setOpt({ swapped: value });
|
||
}
|
||
|
||
/** Mode - 'draw' or 'fill' */
|
||
get mode () {
|
||
return this.props.options.get("mode");
|
||
}
|
||
set mode (value) {
|
||
this.props.setOpt({ mode: value });
|
||
}
|
||
|
||
/** Base line weight */
|
||
get weight () {
|
||
return this.props.options.get("weight");
|
||
}
|
||
set weight (value) {
|
||
this.props.setOpt({ weight: value });
|
||
}
|
||
|
||
/** Drawing opacity */
|
||
get opacity () {
|
||
return this.props.options.get("opacity");
|
||
}
|
||
set opacity (value) {
|
||
this.props.setOpt({ opacity: value });
|
||
}
|
||
|
||
/** Adaptive stroke - change width with speed */
|
||
get adaptiveStroke () {
|
||
return this.props.options.get("adaptiveStroke");
|
||
}
|
||
set adaptiveStroke (value) {
|
||
this.props.setOpt({ adaptiveStroke: value });
|
||
}
|
||
|
||
/** Smoothing (for mouse drawing) */
|
||
get smoothing () {
|
||
return this.props.options.get("smoothing");
|
||
}
|
||
set smoothing (value) {
|
||
this.props.setOpt({ smoothing: value });
|
||
}
|
||
|
||
/** Size preset */
|
||
get size () {
|
||
return this.props.options.get("size");
|
||
}
|
||
set size (value) {
|
||
this.props.setOpt({ size: value });
|
||
}
|
||
|
||
//endregion
|
||
|
||
/**
|
||
* Key up handler
|
||
* @param {KeyboardEvent} e
|
||
*/
|
||
handleKeyUp = (e) => {
|
||
if (e.target.nodeName === "INPUT") {
|
||
return;
|
||
}
|
||
|
||
if (e.key === "Delete") {
|
||
e.preventDefault();
|
||
this.handleClearBtn();
|
||
return;
|
||
}
|
||
|
||
if (e.key === "Backspace" || (e.key === "z" && (e.ctrlKey || e.metaKey))) {
|
||
e.preventDefault();
|
||
this.undo();
|
||
}
|
||
|
||
if (e.key === "Control" || e.key === "Meta") {
|
||
this.controlHeld = false;
|
||
this.swapped = false;
|
||
}
|
||
|
||
if (e.key === "Shift") {
|
||
this.shiftHeld = false;
|
||
this.mode = "draw";
|
||
}
|
||
};
|
||
|
||
/**
|
||
* Key down handler
|
||
* @param {KeyboardEvent} e
|
||
*/
|
||
handleKeyDown = (e) => {
|
||
if (e.key === "Control" || e.key === "Meta") {
|
||
this.controlHeld = true;
|
||
this.swapped = true;
|
||
}
|
||
|
||
if (e.key === "Shift") {
|
||
this.shiftHeld = true;
|
||
this.mode = "fill";
|
||
}
|
||
};
|
||
|
||
/**
|
||
* Component installed in the DOM, do some initial set-up
|
||
*/
|
||
componentDidMount () {
|
||
this.controlHeld = false;
|
||
this.shiftHeld = false;
|
||
this.swapped = false;
|
||
window.addEventListener("keyup", this.handleKeyUp, false);
|
||
window.addEventListener("keydown", this.handleKeyDown, false);
|
||
}
|
||
|
||
/**
|
||
* Tear component down
|
||
*/
|
||
componentWillUnmount () {
|
||
window.removeEventListener("keyup", this.handleKeyUp, false);
|
||
window.removeEventListener("keydown", this.handleKeyDown, false);
|
||
if (this.sketcher) {
|
||
this.sketcher.destroy();
|
||
}
|
||
}
|
||
|
||
/**
|
||
* Set reference to the canvas element.
|
||
* This is called during component init
|
||
* @param {HTMLCanvasElement} elem - canvas element
|
||
*/
|
||
setCanvasRef = (elem) => {
|
||
this.canvas = elem;
|
||
if (elem) {
|
||
elem.addEventListener("dirty", () => {
|
||
this.saveUndo();
|
||
this.sketcher._dirty = false;
|
||
});
|
||
|
||
elem.addEventListener("click", () => {
|
||
// sketcher bug - does not fire dirty on fill
|
||
if (this.mode === "fill") {
|
||
this.saveUndo();
|
||
}
|
||
});
|
||
|
||
// prevent context menu
|
||
elem.addEventListener("contextmenu", (e) => {
|
||
e.preventDefault();
|
||
});
|
||
|
||
elem.addEventListener("mousedown", (e) => {
|
||
if (e.button === 2) {
|
||
this.swapped = true;
|
||
}
|
||
});
|
||
|
||
elem.addEventListener("mouseup", (e) => {
|
||
if (e.button === 2) {
|
||
this.swapped = this.controlHeld;
|
||
}
|
||
});
|
||
|
||
this.initSketcher(elem);
|
||
this.mode = "draw"; // Reset mode - it's confusing if left at 'fill'
|
||
}
|
||
};
|
||
|
||
/**
|
||
* Set up the sketcher instance
|
||
* @param {HTMLCanvasElement | null} canvas - canvas element. Null if we're just resizing
|
||
*/
|
||
initSketcher (canvas = null) {
|
||
const sizepreset = DOODLE_SIZES[this.size];
|
||
|
||
if (this.sketcher) {
|
||
this.sketcher.destroy();
|
||
}
|
||
this.sketcher = new Atrament(canvas || this.canvas, sizepreset[0], sizepreset[1]);
|
||
|
||
if (canvas) {
|
||
this.ctx = this.sketcher.context;
|
||
this.updateSketcherSettings();
|
||
}
|
||
|
||
this.clearScreen();
|
||
}
|
||
|
||
/**
|
||
* Done button handler
|
||
*/
|
||
onDoneButton = () => {
|
||
const dataUrl = this.sketcher.toImage();
|
||
const file = dataURLtoFile(dataUrl, "doodle.png");
|
||
this.props.submit(file);
|
||
this.props.onClose(); // close dialog
|
||
};
|
||
|
||
/**
|
||
* Cancel button handler
|
||
*/
|
||
onCancelButton = () => {
|
||
if (this.undos.length > 1 && !confirm("Discard doodle? All changes will be lost!")) {
|
||
return;
|
||
}
|
||
|
||
this.props.onClose(); // close dialog
|
||
};
|
||
|
||
/**
|
||
* Update sketcher options based on state
|
||
*/
|
||
updateSketcherSettings () {
|
||
if (!this.sketcher) {
|
||
return;
|
||
}
|
||
|
||
if (this.oldSize !== this.size) {
|
||
this.initSketcher();
|
||
}
|
||
|
||
this.sketcher.color = (this.swapped ? this.bg : this.fg);
|
||
this.sketcher.opacity = this.opacity;
|
||
this.sketcher.weight = this.weight;
|
||
this.sketcher.mode = this.mode;
|
||
this.sketcher.smoothing = this.smoothing;
|
||
this.sketcher.adaptiveStroke = this.adaptiveStroke;
|
||
|
||
this.oldSize = this.size;
|
||
}
|
||
|
||
/**
|
||
* Fill screen with background color
|
||
*/
|
||
clearScreen = () => {
|
||
this.ctx.fillStyle = this.bg;
|
||
this.ctx.fillRect(-1, -1, this.canvas.width+2, this.canvas.height+2);
|
||
this.undos = [];
|
||
|
||
this.doSaveUndo();
|
||
};
|
||
|
||
/**
|
||
* Undo one step
|
||
*/
|
||
undo = () => {
|
||
if (this.undos.length > 1) {
|
||
this.undos.pop();
|
||
const buf = this.undos.pop();
|
||
|
||
this.sketcher.clear();
|
||
this.ctx.putImageData(buf, 0, 0);
|
||
this.doSaveUndo();
|
||
}
|
||
};
|
||
|
||
/**
|
||
* Save canvas content into the undo buffer immediately
|
||
*/
|
||
doSaveUndo = () => {
|
||
this.undos.push(this.ctx.getImageData(0, 0, this.canvas.width, this.canvas.height));
|
||
};
|
||
|
||
/**
|
||
* Called on each canvas change.
|
||
* Saves canvas content to the undo buffer after some period of inactivity.
|
||
*/
|
||
saveUndo = debounce(() => {
|
||
this.doSaveUndo();
|
||
}, 100);
|
||
|
||
/**
|
||
* Palette left click.
|
||
* Selects Fg color (or Bg, if Control/Meta is held)
|
||
* @param {MouseEvent<HTMLButtonElement>} e - event
|
||
*/
|
||
onPaletteClick = (e) => {
|
||
const c = e.target.dataset.color;
|
||
|
||
if (this.controlHeld) {
|
||
this.bg = c;
|
||
} else {
|
||
this.fg = c;
|
||
}
|
||
|
||
e.target.blur();
|
||
e.preventDefault();
|
||
};
|
||
|
||
/**
|
||
* Palette right click.
|
||
* Selects Bg color
|
||
* @param {MouseEvent<HTMLButtonElement>} e - event
|
||
*/
|
||
onPaletteRClick = (e) => {
|
||
this.bg = e.target.dataset.color;
|
||
e.target.blur();
|
||
e.preventDefault();
|
||
};
|
||
|
||
/**
|
||
* Handle click on the Draw mode button
|
||
* @param {MouseEvent<HTMLButtonElement>} e - event
|
||
*/
|
||
setModeDraw = (e) => {
|
||
this.mode = "draw";
|
||
e.target.blur();
|
||
};
|
||
|
||
/**
|
||
* Handle click on the Fill mode button
|
||
* @param {MouseEvent<HTMLButtonElement>} e - event
|
||
*/
|
||
setModeFill = (e) => {
|
||
this.mode = "fill";
|
||
e.target.blur();
|
||
};
|
||
|
||
/**
|
||
* Handle click on Smooth checkbox
|
||
* @param {ChangeEvent<HTMLInputElement>} e - event
|
||
*/
|
||
tglSmooth = (e) => {
|
||
this.smoothing = !this.smoothing;
|
||
e.target.blur();
|
||
};
|
||
|
||
/**
|
||
* Handle click on Adaptive checkbox
|
||
* @param {ChangeEvent<HTMLInputElement>} e - event
|
||
*/
|
||
tglAdaptive = (e) => {
|
||
this.adaptiveStroke = !this.adaptiveStroke;
|
||
e.target.blur();
|
||
};
|
||
|
||
/**
|
||
* Handle change of the Weight input field
|
||
* @param {ChangeEvent<HTMLInputElement>} e - event
|
||
*/
|
||
setWeight = (e) => {
|
||
this.weight = +e.target.value || 1;
|
||
};
|
||
|
||
/**
|
||
* Set size - clalback from the select box
|
||
* @param {ChangeEvent<HTMLSelectElement>} e - event
|
||
*/
|
||
changeSize = (e) => {
|
||
let newSize = e.target.value;
|
||
if (newSize === this.oldSize) {
|
||
return;
|
||
}
|
||
|
||
if (this.undos.length > 1 && !confirm("Change canvas size? This will erase your current drawing!")) {
|
||
return;
|
||
}
|
||
|
||
this.size = newSize;
|
||
};
|
||
|
||
handleClearBtn = () => {
|
||
if (this.undos.length > 1 && !confirm("Clear canvas? This will erase your current drawing!")) {
|
||
return;
|
||
}
|
||
|
||
this.clearScreen();
|
||
};
|
||
|
||
/**
|
||
* Render the component
|
||
*/
|
||
render () {
|
||
this.updateSketcherSettings();
|
||
|
||
return (
|
||
<div className='modal-root__modal doodle-modal'>
|
||
<div className='doodle-modal__container'>
|
||
<canvas ref={this.setCanvasRef} />
|
||
</div>
|
||
|
||
<div className='doodle-modal__action-bar'>
|
||
<div className='doodle-toolbar'>
|
||
<Button text='Done' onClick={this.onDoneButton} />
|
||
<Button text='Cancel' onClick={this.onCancelButton} />
|
||
</div>
|
||
<div className='filler' />
|
||
<div className='doodle-toolbar with-inputs'>
|
||
<div>
|
||
<label htmlFor='dd_smoothing'>Smoothing</label>
|
||
<span className='val'>
|
||
<input type='checkbox' id='dd_smoothing' onChange={this.tglSmooth} checked={this.smoothing} />
|
||
</span>
|
||
</div>
|
||
<div>
|
||
<label htmlFor='dd_adaptive'>Adaptive</label>
|
||
<span className='val'>
|
||
<input type='checkbox' id='dd_adaptive' onChange={this.tglAdaptive} checked={this.adaptiveStroke} />
|
||
</span>
|
||
</div>
|
||
<div>
|
||
<label htmlFor='dd_weight'>Weight</label>
|
||
<span className='val'>
|
||
<input type='number' min={1} id='dd_weight' value={this.weight} onChange={this.setWeight} />
|
||
</span>
|
||
</div>
|
||
<div>
|
||
<select aria-label='Canvas size' onInput={this.changeSize} defaultValue={this.size}>
|
||
{ Object.values(mapValues(DOODLE_SIZES, (val, k) =>
|
||
<option key={k} value={k}>{val[2]}</option>,
|
||
)) }
|
||
</select>
|
||
</div>
|
||
</div>
|
||
<div className='doodle-toolbar'>
|
||
<IconButton icon='pencil-simple-line' title='Draw' label='Draw' onClick={this.setModeDraw} size={18} active={this.mode === "draw"} inverted />
|
||
<IconButton icon='paint-bucket' title='Fill' label='Fill' onClick={this.setModeFill} size={18} active={this.mode === "fill"} inverted />
|
||
<IconButton icon='arrow-counter-clockwise' title='Undo' label='Undo' onClick={this.undo} size={18} inverted />
|
||
<IconButton icon='trash' title='Clear' label='Clear' onClick={this.handleClearBtn} size={18} inverted />
|
||
</div>
|
||
<div className='doodle-palette'>
|
||
{
|
||
palReordered.map((c, i) =>
|
||
c === null ?
|
||
<br key={i} /> :
|
||
<button
|
||
key={i}
|
||
style={{ backgroundColor: c[0] }}
|
||
onClick={this.onPaletteClick}
|
||
onContextMenu={this.onPaletteRClick}
|
||
data-color={c[0]}
|
||
title={c[1]}
|
||
className={classNames({
|
||
"foreground": this.fg === c[0],
|
||
"background": this.bg === c[0],
|
||
})}
|
||
/>,
|
||
)
|
||
}
|
||
</div>
|
||
</div>
|
||
</div>
|
||
);
|
||
}
|
||
|
||
}
|
||
|
||
export default connect(mapStateToProps, mapDispatchToProps)(DoodleModal);
|