2021-04-28 02:27:38 +02:00
|
|
|
<!--
|
|
|
|
Copyright: Ankitects Pty Ltd and contributors
|
|
|
|
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|
|
|
-->
|
|
|
|
<script lang="typescript">
|
|
|
|
import * as tr from "lib/i18n";
|
|
|
|
|
2021-05-06 01:58:14 +02:00
|
|
|
import ButtonGroup from "components/ButtonGroup.svelte";
|
|
|
|
import ButtonGroupItem from "components/ButtonGroupItem.svelte";
|
2021-04-28 02:27:38 +02:00
|
|
|
import IconButton from "components/IconButton.svelte";
|
|
|
|
import WithShortcut from "components/WithShortcut.svelte";
|
2021-05-30 21:44:05 +02:00
|
|
|
import WithColorHelper from "./WithColorHelper.svelte";
|
2021-04-28 02:27:38 +02:00
|
|
|
|
2021-05-30 21:44:05 +02:00
|
|
|
import { textColorIcon, highlightColorIcon } from "./icons";
|
2021-05-06 02:49:59 +02:00
|
|
|
import { appendInParentheses } from "./helpers";
|
2021-04-28 02:27:38 +02:00
|
|
|
|
|
|
|
import "./color.css";
|
|
|
|
|
2021-05-06 16:10:26 +02:00
|
|
|
export let api = {};
|
|
|
|
|
2021-04-28 02:27:38 +02:00
|
|
|
const foregroundColorKeyword = "--foreground-color";
|
2021-04-28 22:32:12 +02:00
|
|
|
let color = "black";
|
2021-04-28 02:27:38 +02:00
|
|
|
|
2021-04-28 22:32:12 +02:00
|
|
|
$: {
|
2021-04-28 02:27:38 +02:00
|
|
|
document.documentElement.style.setProperty(foregroundColorKeyword, color);
|
|
|
|
}
|
|
|
|
|
2021-05-30 21:44:05 +02:00
|
|
|
const wrapWithForecolor = (color: string) => () => {
|
2021-04-28 02:27:38 +02:00
|
|
|
document.execCommand("forecolor", false, color);
|
|
|
|
}
|
|
|
|
|
2021-05-30 21:44:05 +02:00
|
|
|
const wrapWithBackcolor = (color: string) => () => {
|
|
|
|
document.execCommand("backcolor", false, color);
|
|
|
|
}
|
|
|
|
|
2021-04-28 02:27:38 +02:00
|
|
|
function setWithCurrentColor({ currentTarget }: Event): void {
|
2021-04-28 22:32:12 +02:00
|
|
|
color = (currentTarget as HTMLInputElement).value;
|
2021-04-28 02:27:38 +02:00
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
2021-05-06 19:26:50 +02:00
|
|
|
<ButtonGroup {api}>
|
2021-05-30 21:44:05 +02:00
|
|
|
<!--
|
2021-05-06 01:58:14 +02:00
|
|
|
<ButtonGroupItem>
|
2021-05-26 01:21:33 +02:00
|
|
|
<WithShortcut shortcut={"F7"} let:createShortcut let:shortcutLabel>
|
2021-05-06 01:58:14 +02:00
|
|
|
<IconButton
|
|
|
|
class="forecolor"
|
2021-05-26 01:21:33 +02:00
|
|
|
tooltip={appendInParentheses(
|
|
|
|
tr.editingSetForegroundColor(),
|
|
|
|
shortcutLabel
|
|
|
|
)}
|
2021-05-06 01:58:14 +02:00
|
|
|
on:click={wrapWithForecolor}
|
2021-05-26 01:21:33 +02:00
|
|
|
on:mount={createShortcut}
|
|
|
|
>
|
2021-05-06 01:58:14 +02:00
|
|
|
{@html squareFillIcon}
|
|
|
|
</IconButton>
|
|
|
|
</WithShortcut>
|
|
|
|
</ButtonGroupItem>
|
|
|
|
|
|
|
|
<ButtonGroupItem>
|
2021-05-26 01:21:33 +02:00
|
|
|
<WithShortcut shortcut={"F8"} let:createShortcut let:shortcutLabel>
|
2021-05-06 01:58:14 +02:00
|
|
|
<ColorPicker
|
2021-05-06 02:49:59 +02:00
|
|
|
tooltip={appendInParentheses(tr.editingChangeColor(), shortcutLabel)}
|
2021-05-06 01:58:14 +02:00
|
|
|
on:change={setWithCurrentColor}
|
2021-05-26 01:21:33 +02:00
|
|
|
on:mount={createShortcut}
|
|
|
|
/>
|
2021-05-06 01:58:14 +02:00
|
|
|
</WithShortcut>
|
|
|
|
</ButtonGroupItem>
|
2021-05-30 21:44:05 +02:00
|
|
|
-->
|
|
|
|
|
|
|
|
<WithColorHelper let:colorHelperIcon let:color>
|
|
|
|
<ButtonGroupItem>
|
|
|
|
<WithShortcut shortcut={"F7"} let:createShortcut let:shortcutLabel>
|
|
|
|
<IconButton
|
|
|
|
tooltip={appendInParentheses(
|
|
|
|
tr.editingSetForegroundColor(),
|
|
|
|
shortcutLabel
|
|
|
|
)}
|
|
|
|
on:click={wrapWithForecolor(color)}
|
|
|
|
on:mount={createShortcut}
|
|
|
|
>
|
|
|
|
{@html textColorIcon}
|
|
|
|
{@html colorHelperIcon}
|
|
|
|
</IconButton>
|
|
|
|
</WithShortcut>
|
|
|
|
</ButtonGroupItem>
|
|
|
|
</WithColorHelper>
|
|
|
|
|
|
|
|
<WithColorHelper let:colorHelperIcon let:color>
|
|
|
|
<ButtonGroupItem>
|
|
|
|
<WithShortcut shortcut={"F7"} let:createShortcut let:shortcutLabel>
|
|
|
|
<IconButton
|
|
|
|
tooltip={appendInParentheses(
|
|
|
|
tr.editingSetForegroundColor(),
|
|
|
|
shortcutLabel
|
|
|
|
)}
|
|
|
|
on:click={wrapWithBackcolor(color)}
|
|
|
|
on:mount={createShortcut}
|
|
|
|
>
|
|
|
|
{@html highlightColorIcon}
|
|
|
|
{@html colorHelperIcon}
|
|
|
|
</IconButton>
|
|
|
|
</WithShortcut>
|
|
|
|
</ButtonGroupItem>
|
|
|
|
</WithColorHelper>
|
2021-04-28 02:27:38 +02:00
|
|
|
</ButtonGroup>
|