mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 22:12:21 -04:00
Fix and refactor image size constraints (#2318)
* Remove 'ResizableImage.svelte' Rather than having a svelte file that just sets global styles, it's better to set those in a (s)css file. * Fix and refactor image size constraints - Fixes https://forums.ankiweb.net/t/2-1-56-image-size-problem-in-editor/26207 - Use :host-context() to switch image styles instead of toggling CSS variables. * Fix toolbar buttons for image overlay sometimes being cut off
This commit is contained in:
parent
8131ea1908
commit
604e0f46e1
4 changed files with 29 additions and 50 deletions
|
@ -1,19 +0,0 @@
|
||||||
<!--
|
|
||||||
Copyright: Ankitects Pty Ltd and contributors
|
|
||||||
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|
||||||
-->
|
|
||||||
<style lang="scss">
|
|
||||||
:global(img:not(.mathjax)) {
|
|
||||||
max-width: var(--editor-default-max-width, inherit);
|
|
||||||
max-height: var(--editor-default-max-height, inherit);
|
|
||||||
|
|
||||||
&:is([data-editor-shrink="true"]) {
|
|
||||||
max-width: var(--editor-shrink-max-width);
|
|
||||||
max-height: var(--editor-shrink-max-height);
|
|
||||||
}
|
|
||||||
&:is([data-editor-shrink="false"]) {
|
|
||||||
max-width: initial;
|
|
||||||
max-height: initial;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</style>
|
|
|
@ -26,3 +26,18 @@ p {
|
||||||
pre {
|
pre {
|
||||||
white-space: pre-wrap;
|
white-space: pre-wrap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// image size constraints
|
||||||
|
img:not(.mathjax) {
|
||||||
|
&:not([data-editor-shrink="false"]) {
|
||||||
|
:host-context(.shrink-image) & {
|
||||||
|
max-width: var(--editor-default-max-width);
|
||||||
|
max-height: var(--editor-default-max-height);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&[data-editor-shrink="true"] {
|
||||||
|
max-width: var(--editor-shrink-max-width);
|
||||||
|
max-height: var(--editor-shrink-max-height);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -5,4 +5,3 @@ import "./editable-base.scss";
|
||||||
/* only imported for the CSS */
|
/* only imported for the CSS */
|
||||||
import "./ContentEditable.svelte";
|
import "./ContentEditable.svelte";
|
||||||
import "./Mathjax.svelte";
|
import "./Mathjax.svelte";
|
||||||
import "./ResizableImage.svelte";
|
|
||||||
|
|
|
@ -24,25 +24,26 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
import HandleControl from "../HandleControl.svelte";
|
import HandleControl from "../HandleControl.svelte";
|
||||||
import HandleLabel from "../HandleLabel.svelte";
|
import HandleLabel from "../HandleLabel.svelte";
|
||||||
import { context } from "../NoteEditor.svelte";
|
import { context } from "../NoteEditor.svelte";
|
||||||
import type { RichTextInputAPI } from "../rich-text-input";
|
import { editingInputIsRichText } from "../rich-text-input";
|
||||||
import {
|
|
||||||
editingInputIsRichText,
|
|
||||||
lifecycle as richTextLifecycle,
|
|
||||||
} from "../rich-text-input";
|
|
||||||
import FloatButtons from "./FloatButtons.svelte";
|
import FloatButtons from "./FloatButtons.svelte";
|
||||||
import SizeSelect from "./SizeSelect.svelte";
|
import SizeSelect from "./SizeSelect.svelte";
|
||||||
|
|
||||||
export let maxWidth: number;
|
export let maxWidth: number;
|
||||||
export let maxHeight: number;
|
export let maxHeight: number;
|
||||||
|
|
||||||
richTextLifecycle.onMount(({ element }: RichTextInputAPI): void => {
|
(<[string, number][]>[
|
||||||
(async () => {
|
["--editor-shrink-max-width", maxWidth],
|
||||||
const container = await element;
|
["--editor-shrink-max-height", maxHeight],
|
||||||
|
["--editor-default-max-width", maxWidth],
|
||||||
|
["--editor-default-max-height", maxHeight],
|
||||||
|
]).forEach(([prop, value]) =>
|
||||||
|
document.documentElement.style.setProperty(prop, `${value}px`),
|
||||||
|
);
|
||||||
|
|
||||||
container.style.setProperty("--editor-shrink-max-width", `${maxWidth}px`);
|
$: document.documentElement.classList.toggle(
|
||||||
container.style.setProperty("--editor-shrink-max-height", `${maxHeight}px`);
|
"shrink-image",
|
||||||
})();
|
$shrinkImagesByDefault,
|
||||||
});
|
);
|
||||||
|
|
||||||
const { focusedInput } = context.get();
|
const { focusedInput } = context.get();
|
||||||
|
|
||||||
|
@ -83,24 +84,6 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$: {
|
|
||||||
if ($shrinkImagesByDefault) {
|
|
||||||
document.documentElement.style.setProperty(
|
|
||||||
"--editor-default-max-width",
|
|
||||||
`${maxWidth}px`,
|
|
||||||
);
|
|
||||||
document.documentElement.style.setProperty(
|
|
||||||
"--editor-default-max-height",
|
|
||||||
`${maxHeight}px`,
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
document.documentElement.style.removeProperty("--editor-default-max-width");
|
|
||||||
document.documentElement.style.removeProperty(
|
|
||||||
"--editor-default-max-height",
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function resetHandle(): Promise<void> {
|
async function resetHandle(): Promise<void> {
|
||||||
activeImage = null;
|
activeImage = null;
|
||||||
await tick();
|
await tick();
|
||||||
|
@ -265,6 +248,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
offset={20}
|
offset={20}
|
||||||
inline
|
inline
|
||||||
hideIfReferenceHidden
|
hideIfReferenceHidden
|
||||||
|
portalTarget={document.body}
|
||||||
let:position={positionFloating}
|
let:position={positionFloating}
|
||||||
on:close={async ({ detail }) => {
|
on:close={async ({ detail }) => {
|
||||||
const { reason, originalEvent } = detail;
|
const { reason, originalEvent } = detail;
|
||||||
|
|
Loading…
Reference in a new issue