diff --git a/.gitignore b/.gitignore index c15ba82..a06872c 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,5 @@ /storage /tests/tested.json /tags/* +/styles/extensions/demo __pycache__ diff --git a/i18n.json.REMOVED.git-id b/i18n.json.REMOVED.git-id index ea8d11f..d3fb8bd 100644 --- a/i18n.json.REMOVED.git-id +++ b/i18n.json.REMOVED.git-id @@ -1 +1 @@ -8f0029951d020921489735c9e3a75e1def63be34 \ No newline at end of file +3ea76cc670268c82561eafa84165305517118d4e \ No newline at end of file diff --git a/javascript/main.entry.js.REMOVED.git-id b/javascript/main.entry.js.REMOVED.git-id index 10dfeb6..716d289 100644 --- a/javascript/main.entry.js.REMOVED.git-id +++ b/javascript/main.entry.js.REMOVED.git-id @@ -1 +1 @@ -93fdb60005d73f9a885338934a50c62505927e66 \ No newline at end of file +e3cfcaed2ef7497832d8b919833b8556ecac8c12 \ No newline at end of file diff --git a/javascript/main.entry.js.map.REMOVED.git-id b/javascript/main.entry.js.map.REMOVED.git-id index 43608a8..7126a90 100644 --- a/javascript/main.entry.js.map.REMOVED.git-id +++ b/javascript/main.entry.js.map.REMOVED.git-id @@ -1 +1 @@ -ea283d0443909de3d05c938167d0679b8a3ceba9 \ No newline at end of file +07a37828c4ae6ddbeb59198dd646dc3878eb62a2 \ No newline at end of file diff --git a/scripts/on_app_started.py b/scripts/on_app_started.py index 175a24c..6c162d2 100755 --- a/scripts/on_app_started.py +++ b/scripts/on_app_started.py @@ -12,6 +12,7 @@ from scripts.get_translate_apis import get_translate_apis from scripts.translate import translate from scripts.history import history from scripts.csv import get_csvs, get_csv +from scripts.styles import getStyleFullPath, getExtensionCssList VERSION = '0.0.1' @@ -197,15 +198,17 @@ def on_app_started(_: gr.Blocks, app: FastAPI): return Response(status_code=404) return FileResponse(file, media_type='text/csv', filename=os.path.basename(file)) - @app.get("/physton_prompt/theme") - async def _theme(file: str): - theme_path = os.path.dirname(os.path.abspath(__file__)) + '/../theme' - theme_path = os.path.normpath(theme_path) - file_path = os.path.join(theme_path, file) + @app.get("/physton_prompt/styles") + async def _styles(file: str): + file_path = getStyleFullPath(file) if not os.path.exists(file_path): return Response(status_code=404) return FileResponse(file_path, filename=os.path.basename(file_path)) + @app.get("/physton_prompt/get_extension_css_list") + async def _get_extension_css_list(): + return {"css_list": getExtensionCssList()} + try: script_callbacks.on_app_started(on_app_started) print('sd-webui-prompt-all-in-one background API service started successfully.') diff --git a/scripts/styles.py b/scripts/styles.py new file mode 100644 index 0000000..103c6df --- /dev/null +++ b/scripts/styles.py @@ -0,0 +1,50 @@ +import os +from scripts.storage import storage +storage = storage() + +styles_path = os.path.dirname(os.path.abspath(__file__)) + '/../styles' +styles_path = os.path.normpath(styles_path) + +def getStyleFullPath(file): + global styles_path + return os.path.join(styles_path, file) + +def getExtensionCssList(): + global styles_path + extension_path = os.path.join(styles_path, 'extensions') + if not os.path.exists(extension_path): + return [] + css_list = [] + # 扫描下面的每个文件夹 + for dir in os.listdir(extension_path): + dir_path = os.path.join(extension_path, dir) + if not os.path.isdir(dir_path): + continue + + # 是否有 manifest.json 文件 + manifest_path = os.path.join(dir_path, 'manifest.json') + if not os.path.exists(manifest_path): + continue + + # 是否有 style.min.css 文件 + style_path = os.path.join(dir_path, 'style.min.css') + if not os.path.exists(style_path): + continue + + manifest = None + with open(manifest_path, 'r') as f: + manifest = f.read() + if not manifest: + continue + + css_item = { + 'dir': dir, + 'dataName': 'extensionSelect.' + dir, + 'selected': False, + 'manifest': manifest, + 'style': f'extensions/{dir}/style.min.css', + } + css_item['selected'] = storage.get(css_item['dataName']) + css_list.append(css_item) + + return css_list diff --git a/src/src/App.vue b/src/src/App.vue index c83fb63..06db3c7 100755 --- a/src/src/App.vue +++ b/src/src/App.vue @@ -20,7 +20,8 @@ :translate-api-config="translateApiConfig" @click:translate-api="onTranslateApiClick" v-model:tag-complete-file="tagCompleteFile" - @click:select-language="onSelectLanguageClick"> + @click:select-language="onSelectLanguageClick" + @click:select-theme="onSelectThemeClick"> +
- +
{{ pasteTitle }}
Submit
- +
@@ -61,20 +64,20 @@ import PhystonPrompt from "./components/phystonPrompt.vue" import TranslateSetting from "@/components/translateSetting.vue"; import common from "@/utils/common"; -import IconClose from "@/components/icons/iconClose.vue"; -import IconLoading from "@/components/icons/iconLoading.vue"; import SelectLanguage from "@/components/selectLanguage.vue"; import Favorite from "@/components/favorite.vue"; import History from "@/components/history.vue"; +import IconSvg from "@/components/iconSvg.vue"; +import ExtensionCss from "@/components/extensionCss.vue"; export default { name: 'App', components: { + ExtensionCss, + IconSvg, History, Favorite, SelectLanguage, - IconLoading, - IconClose, TranslateSetting, PhystonPrompt, }, @@ -260,6 +263,7 @@ export default { }, }, mounted() { + common.loadCSS('main.min.css', 'physton-prompt-main', true) this.gradioAPI.getConfig().then(res => { console.log('config:', res) this.languageCode = res.i18n.default @@ -335,6 +339,7 @@ export default { } this.updateTranslateApiConfig() + this.$refs.extensionCss.init() this.prompts.forEach(item => { if (data[item.hideDefaultInputKey] !== null) { @@ -400,6 +405,9 @@ export default { onTranslateApiClick() { this.$refs.translateSetting.open(this.translateApi) }, + onSelectThemeClick() { + this.$refs.extensionCss.open() + }, handlePaste() { if (typeof gradioApp !== 'function') return const $pastes = gradioApp().querySelectorAll("#paste") @@ -526,5 +534,6 @@ export default { diff --git a/src/src/components/extensionCss.vue b/src/src/components/extensionCss.vue new file mode 100644 index 0000000..ebc92ea --- /dev/null +++ b/src/src/components/extensionCss.vue @@ -0,0 +1,92 @@ + + \ No newline at end of file diff --git a/src/src/components/favorite.vue b/src/src/components/favorite.vue index 35ca71d..ae09be8 100644 --- a/src/src/components/favorite.vue +++ b/src/src/components/favorite.vue @@ -37,19 +37,19 @@
- +
- +
- +
- +
@@ -57,23 +57,20 @@
- + {{ emptyMsg }}
\ No newline at end of file diff --git a/src/src/components/icons/iconClose.vue b/src/src/components/icons/iconClose.vue deleted file mode 100755 index f7755f0..0000000 --- a/src/src/components/icons/iconClose.vue +++ /dev/null @@ -1,26 +0,0 @@ - - \ No newline at end of file diff --git a/src/src/components/icons/iconCopy.vue b/src/src/components/icons/iconCopy.vue deleted file mode 100755 index e372391..0000000 --- a/src/src/components/icons/iconCopy.vue +++ /dev/null @@ -1,28 +0,0 @@ - - \ No newline at end of file diff --git a/src/src/components/icons/iconDisabled.vue b/src/src/components/icons/iconDisabled.vue deleted file mode 100755 index 2869ec4..0000000 --- a/src/src/components/icons/iconDisabled.vue +++ /dev/null @@ -1,26 +0,0 @@ - - \ No newline at end of file diff --git a/src/src/components/icons/iconEnable.vue b/src/src/components/icons/iconEnable.vue deleted file mode 100755 index 757752e..0000000 --- a/src/src/components/icons/iconEnable.vue +++ /dev/null @@ -1,27 +0,0 @@ - - \ No newline at end of file diff --git a/src/src/components/icons/iconEnglish.vue b/src/src/components/icons/iconEnglish.vue deleted file mode 100755 index ced7bcf..0000000 --- a/src/src/components/icons/iconEnglish.vue +++ /dev/null @@ -1,27 +0,0 @@ - - \ No newline at end of file diff --git a/src/src/components/icons/iconFavorite.vue b/src/src/components/icons/iconFavorite.vue deleted file mode 100755 index 7f49777..0000000 --- a/src/src/components/icons/iconFavorite.vue +++ /dev/null @@ -1,27 +0,0 @@ - - \ No newline at end of file diff --git a/src/src/components/icons/iconFavoriteState.vue b/src/src/components/icons/iconFavoriteState.vue deleted file mode 100755 index 69206c6..0000000 --- a/src/src/components/icons/iconFavoriteState.vue +++ /dev/null @@ -1,39 +0,0 @@ - - \ No newline at end of file diff --git a/src/src/components/icons/iconGithub.vue b/src/src/components/icons/iconGithub.vue deleted file mode 100644 index 2219e8d..0000000 --- a/src/src/components/icons/iconGithub.vue +++ /dev/null @@ -1,27 +0,0 @@ - - \ No newline at end of file diff --git a/src/src/components/icons/iconHistory.vue b/src/src/components/icons/iconHistory.vue deleted file mode 100755 index 21ea6ae..0000000 --- a/src/src/components/icons/iconHistory.vue +++ /dev/null @@ -1,28 +0,0 @@ - - \ No newline at end of file diff --git a/src/src/components/icons/iconI18n.vue b/src/src/components/icons/iconI18n.vue deleted file mode 100644 index 0ef9c91..0000000 --- a/src/src/components/icons/iconI18n.vue +++ /dev/null @@ -1,27 +0,0 @@ - - \ No newline at end of file diff --git a/src/src/components/icons/iconInput.vue b/src/src/components/icons/iconInput.vue deleted file mode 100644 index 0c117c7..0000000 --- a/src/src/components/icons/iconInput.vue +++ /dev/null @@ -1,28 +0,0 @@ - - \ No newline at end of file diff --git a/src/src/components/icons/iconLoading.vue b/src/src/components/icons/iconLoading.vue deleted file mode 100644 index 9ead85f..0000000 --- a/src/src/components/icons/iconLoading.vue +++ /dev/null @@ -1,91 +0,0 @@ - - - \ No newline at end of file diff --git a/src/src/components/icons/iconRefresh.vue b/src/src/components/icons/iconRefresh.vue deleted file mode 100644 index c96b9be..0000000 --- a/src/src/components/icons/iconRefresh.vue +++ /dev/null @@ -1,27 +0,0 @@ - - \ No newline at end of file diff --git a/src/src/components/icons/iconRemove.vue b/src/src/components/icons/iconRemove.vue deleted file mode 100644 index 0f3902f..0000000 --- a/src/src/components/icons/iconRemove.vue +++ /dev/null @@ -1,27 +0,0 @@ - - \ No newline at end of file diff --git a/src/src/components/icons/iconSetting.vue b/src/src/components/icons/iconSetting.vue deleted file mode 100755 index 31bc381..0000000 --- a/src/src/components/icons/iconSetting.vue +++ /dev/null @@ -1,28 +0,0 @@ - - \ No newline at end of file diff --git a/src/src/components/icons/iconTooltip.vue b/src/src/components/icons/iconTooltip.vue deleted file mode 100644 index 4226d76..0000000 --- a/src/src/components/icons/iconTooltip.vue +++ /dev/null @@ -1,28 +0,0 @@ - - \ No newline at end of file diff --git a/src/src/components/icons/iconTranslate.vue b/src/src/components/icons/iconTranslate.vue deleted file mode 100755 index 875dd19..0000000 --- a/src/src/components/icons/iconTranslate.vue +++ /dev/null @@ -1,27 +0,0 @@ - - \ No newline at end of file diff --git a/src/src/components/icons/iconUnflod.vue b/src/src/components/icons/iconUnflod.vue deleted file mode 100755 index 8fdd3cc..0000000 --- a/src/src/components/icons/iconUnflod.vue +++ /dev/null @@ -1,32 +0,0 @@ - - \ No newline at end of file diff --git a/src/src/components/icons/iconUse.vue b/src/src/components/icons/iconUse.vue deleted file mode 100644 index aeae619..0000000 --- a/src/src/components/icons/iconUse.vue +++ /dev/null @@ -1,28 +0,0 @@ - - \ No newline at end of file diff --git a/src/src/components/icons/iconWeight.vue b/src/src/components/icons/iconWeight.vue deleted file mode 100755 index b2477c8..0000000 --- a/src/src/components/icons/iconWeight.vue +++ /dev/null @@ -1,47 +0,0 @@ - - \ No newline at end of file diff --git a/src/src/components/icons/iconWrap.vue b/src/src/components/icons/iconWrap.vue deleted file mode 100755 index f406079..0000000 --- a/src/src/components/icons/iconWrap.vue +++ /dev/null @@ -1,28 +0,0 @@ - - \ No newline at end of file diff --git a/src/src/components/phystonPrompt.vue.REMOVED.git-id b/src/src/components/phystonPrompt.vue.REMOVED.git-id index 21ea8c8..f19f6be 100644 --- a/src/src/components/phystonPrompt.vue.REMOVED.git-id +++ b/src/src/components/phystonPrompt.vue.REMOVED.git-id @@ -1 +1 @@ -2236d48502f1d81fbbf431d022601cf6b808c5cc \ No newline at end of file +938ade8bd3d82b26cc75aa279a8dd4663e814073 \ No newline at end of file diff --git a/src/src/components/selectLanguage.vue b/src/src/components/selectLanguage.vue index b405a44..6244c47 100644 --- a/src/src/components/selectLanguage.vue +++ b/src/src/components/selectLanguage.vue @@ -2,7 +2,7 @@
- +