From 790c52f01264fa31af5c88bb9340ee9da0dd903c Mon Sep 17 00:00:00 2001 From: RumovZ Date: Wed, 24 Apr 2024 03:37:31 +0200 Subject: [PATCH] Svg icon (#3135) * Add sveltekit-svg plugin to fix svg icon styling Closes #3127. * Unify svg icon usage Moves all icons into ts/lib/components/icons.ts and uses a single component to render them both with eslint and svelte-kit. * Fix spinning revert icon not being centered * Use svg earth icon for global label * Add tooltip to global label icon * Remove eslint-plugin-simple-import-sort Imports are already sorted by dprint with conflicting rules. --- .eslintrc.cjs | 3 - package.json | 7 +- ts/editable/icons.ts | 4 - ts/editable/mathjax.ts | 2 +- ts/editor/ClozeButtons.svelte | 7 +- ts/editor/CollapseBadge.svelte | 6 +- ts/editor/NoteEditor.svelte | 5 +- ts/editor/PlainTextBadge.svelte | 5 +- ts/editor/RichTextBadge.svelte | 5 +- ts/editor/StickyBadge.svelte | 5 +- ts/editor/editor-toolbar/BlockButtons.svelte | 35 +- ts/editor/editor-toolbar/BoldButton.svelte | 5 +- .../HighlightColorButton.svelte | 11 +- .../ImageOcclusionButton.svelte | 7 +- ts/editor/editor-toolbar/ItalicButton.svelte | 5 +- ts/editor/editor-toolbar/LatexButton.svelte | 5 +- ts/editor/editor-toolbar/OptionsButton.svelte | 5 +- .../editor-toolbar/RemoveFormatButton.svelte | 9 +- .../editor-toolbar/SubscriptButton.svelte | 5 +- .../editor-toolbar/SuperscriptButton.svelte | 5 +- .../editor-toolbar/TemplateButtons.svelte | 7 +- .../editor-toolbar/TextColorButton.svelte | 11 +- .../editor-toolbar/UnderlineButton.svelte | 5 +- .../editor-toolbar/WithColorHelper.svelte | 2 +- ts/editor/editor-toolbar/icons.ts | 28 -- ts/editor/icons.ts | 14 - ts/editor/image-overlay/FloatButtons.svelte | 14 +- ts/editor/image-overlay/SizeSelect.svelte | 8 +- ts/editor/image-overlay/icons.ts | 9 - .../mathjax-overlay/MathjaxButtons.svelte | 9 +- ts/editor/mathjax-overlay/icons.ts | 6 - ts/image-occlusion/icons.ts | 0 ts/lib/components/HelpModal.svelte | 5 +- ts/lib/components/Icon.svelte | 15 + ts/lib/components/RevertButton.svelte | 10 +- ts/lib/components/Select.svelte | 6 +- ts/lib/components/SpinBox.svelte | 8 +- ts/lib/components/icons.ts | 332 +++++++++++++++--- ts/lib/components/types.ts | 7 + ts/lib/tag-editor/TagDeleteBadge.svelte | 6 +- ts/lib/tag-editor/icons.ts | 4 - .../tag-options-button/TagAddButton.svelte | 5 +- .../TagsSelectedButton.svelte | 3 +- ts/routes/change-notetype/Alert.svelte | 3 +- .../change-notetype/NotetypeSelector.svelte | 5 +- ts/routes/change-notetype/StickyHeader.svelte | 3 +- ts/routes/deck-options/GlobalLabel.svelte | 18 +- ts/routes/deck-options/SaveButton.svelte | 3 +- ts/routes/image-occlusion/Toast.svelte | 6 +- ts/routes/image-occlusion/Toolbar.svelte | 26 +- ts/routes/image-occlusion/icons.ts | 74 ---- .../notes-toolbar/MoreTools.svelte | 5 +- .../notes-toolbar/TextFormatting.svelte | 10 +- ts/routes/image-occlusion/tools/more-tools.ts | 3 +- .../image-occlusion/tools/tool-buttons.ts | 3 +- .../image-occlusion/tools/tool-undo-redo.ts | 3 +- ts/routes/import-page/DetailsTable.svelte | 3 +- ts/routes/import-page/QueueSummary.svelte | 3 +- ts/routes/import-page/types.ts | 4 +- ts/src/app.d.ts | 2 + ts/vite.config.ts | 3 +- yarn.lock | 129 ++++++- 62 files changed, 627 insertions(+), 334 deletions(-) delete mode 100644 ts/editable/icons.ts delete mode 100644 ts/editor/editor-toolbar/icons.ts delete mode 100644 ts/editor/icons.ts delete mode 100644 ts/editor/image-overlay/icons.ts delete mode 100644 ts/editor/mathjax-overlay/icons.ts delete mode 100644 ts/image-occlusion/icons.ts create mode 100644 ts/lib/components/Icon.svelte delete mode 100644 ts/lib/tag-editor/icons.ts delete mode 100644 ts/routes/image-occlusion/icons.ts diff --git a/.eslintrc.cjs b/.eslintrc.cjs index e4044de30..3badc3ca3 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -7,7 +7,6 @@ module.exports = { }, plugins: [ "import", - "simple-import-sort", "@typescript-eslint", "@typescript-eslint/eslint-plugin", ], @@ -20,8 +19,6 @@ module.exports = { "no-unused-vars": ["warn", { argsIgnorePattern: "^_" }], "import/newline-after-import": "warn", "import/no-useless-path-segments": "warn", - "simple-import-sort/imports": "warn", - "simple-import-sort/exports": "warn", "prefer-const": "warn", "no-nested-ternary": "warn", "curly": "error", diff --git a/package.json b/package.json index a90d87e63..521f5bc54 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,7 @@ }, "devDependencies": { "@bufbuild/protoc-gen-es": "^1.8.0", + "@poppanator/sveltekit-svg": "^4.2.1", "@sqltools/formatter": "^1.2.2", "@sveltejs/adapter-static": "^3.0.0", "@sveltejs/kit": "^2.4.1", @@ -42,7 +43,6 @@ "eslint": "^8.44.0", "eslint-plugin-compat": "^4.1.4", "eslint-plugin-import": "^2.25.4", - "eslint-plugin-simple-import-sort": "^10.0.0", "eslint-plugin-svelte": "^2", "license-checker-rseidelsohn": "^4.2.6", "prettier": "^2.4.1", @@ -51,6 +51,7 @@ "svelte-check": "^3.4.4", "svelte-preprocess": "^5.0.4", "svelte-preprocess-esbuild": "^3.0.1", + "svgo": "^3.2.0", "tslib": "^2.0.3", "tsx": "^3.12.0", "typescript": "^5.0.4", @@ -69,13 +70,13 @@ "codemirror": "^5.63.1", "d3": "^7.0.0", "fabric": "^5.3.0", + "hammerjs": "^2.0.8", "intl-pluralrules": "^2.0.0", "jquery": "^3.5.1", "jquery-ui-dist": "^1.12.1", "lodash-es": "^4.17.21", "marked": "^5.1.0", - "mathjax": "^3.1.2", - "hammerjs": "^2.0.8" + "mathjax": "^3.1.2" }, "resolutions": { "canvas": "npm:empty-npm-package" diff --git a/ts/editable/icons.ts b/ts/editable/icons.ts deleted file mode 100644 index 034aee1bd..000000000 --- a/ts/editable/icons.ts +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright: Ankitects Pty Ltd and contributors -// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html - -export { default as mathIcon } from "@mdi/svg/svg/math-integral-box.svg"; diff --git a/ts/editable/mathjax.ts b/ts/editable/mathjax.ts index 55e23498d..94ea32118 100644 --- a/ts/editable/mathjax.ts +++ b/ts/editable/mathjax.ts @@ -7,7 +7,7 @@ import "mathjax/es5/tex-svg-full"; -import { mathIcon } from "./icons"; +import mathIcon from "@mdi/svg/svg/math-integral-box.svg?src"; const parser = new DOMParser(); diff --git a/ts/editor/ClozeButtons.svelte b/ts/editor/ClozeButtons.svelte index fdb29c320..11b8ca933 100644 --- a/ts/editor/ClozeButtons.svelte +++ b/ts/editor/ClozeButtons.svelte @@ -10,10 +10,11 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html import { get } from "svelte/store"; import ButtonGroup from "$lib/components/ButtonGroup.svelte"; + import Icon from "$lib/components/Icon.svelte"; import IconButton from "$lib/components/IconButton.svelte"; + import { clozeIcon, incrementClozeIcon } from "$lib/components/icons"; import Shortcut from "$lib/components/Shortcut.svelte"; - import { clozeIcon, incrementClozeIcon } from "./icons"; import { context as noteEditorContext } from "./NoteEditor.svelte"; import { editingInputIsRichText } from "./rich-text-input"; @@ -84,7 +85,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html on:click={onIncrementCloze} --border-left-radius="5px" > - {@html incrementClozeIcon} + - {@html clozeIcon} + diff --git a/ts/editor/CollapseBadge.svelte b/ts/editor/CollapseBadge.svelte index 8ea80eae2..f2b434afc 100644 --- a/ts/editor/CollapseBadge.svelte +++ b/ts/editor/CollapseBadge.svelte @@ -4,14 +4,14 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html -->
- {@html chevronDown} +
diff --git a/ts/routes/deck-options/SaveButton.svelte b/ts/routes/deck-options/SaveButton.svelte index dc5e4ab06..1c3c2bd63 100644 --- a/ts/routes/deck-options/SaveButton.svelte +++ b/ts/routes/deck-options/SaveButton.svelte @@ -12,6 +12,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html import DropdownDivider from "$lib/components/DropdownDivider.svelte"; import DropdownItem from "$lib/components/DropdownItem.svelte"; + import Icon from "$lib/components/Icon.svelte"; import IconButton from "$lib/components/IconButton.svelte"; import { chevronDown } from "$lib/components/icons"; import LabelButton from "$lib/components/LabelButton.svelte"; @@ -102,7 +103,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html --border-left-radius={rtl ? "var(--border-radius)" : "0"} iconSize={80} > - {@html chevronDown} + dispatch("add")}> diff --git a/ts/routes/image-occlusion/Toast.svelte b/ts/routes/image-occlusion/Toast.svelte index 37c50aa0a..17a26f558 100644 --- a/ts/routes/image-occlusion/Toast.svelte +++ b/ts/routes/image-occlusion/Toast.svelte @@ -3,9 +3,9 @@ Copyright: Ankitects Pty Ltd and contributors License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html -->