diff --git a/.eslintrc.cjs b/.eslintrc.cjs new file mode 100644 index 0000000..6f40582 --- /dev/null +++ b/.eslintrc.cjs @@ -0,0 +1,15 @@ +/* eslint-env node */ +require('@rushstack/eslint-patch/modern-module-resolution') + +module.exports = { + root: true, + 'extends': [ + 'plugin:vue/vue3-essential', + 'eslint:recommended', + '@vue/eslint-config-typescript', + '@vue/eslint-config-prettier/skip-formatting' + ], + parserOptions: { + ecmaVersion: 'latest' + } +} diff --git a/.gitignore b/.gitignore index 68bc17f..38adffa 100644 --- a/.gitignore +++ b/.gitignore @@ -1,160 +1,28 @@ -# Byte-compiled / optimized / DLL files -__pycache__/ -*.py[cod] -*$py.class - -# C extensions -*.so - -# Distribution / packaging -.Python -build/ -develop-eggs/ -dist/ -downloads/ -eggs/ -.eggs/ -lib/ -lib64/ -parts/ -sdist/ -var/ -wheels/ -share/python-wheels/ -*.egg-info/ -.installed.cfg -*.egg -MANIFEST - -# PyInstaller -# Usually these files are written by a python script from a template -# before PyInstaller builds the exe, so as to inject date/other infos into it. -*.manifest -*.spec - -# Installer logs -pip-log.txt -pip-delete-this-directory.txt - -# Unit test / coverage reports -htmlcov/ -.tox/ -.nox/ -.coverage -.coverage.* -.cache -nosetests.xml -coverage.xml -*.cover -*.py,cover -.hypothesis/ -.pytest_cache/ -cover/ - -# Translations -*.mo -*.pot - -# Django stuff: +# Logs +logs *.log -local_settings.py -db.sqlite3 -db.sqlite3-journal +npm-debug.log* +yarn-debug.log* +yarn-error.log* +pnpm-debug.log* +lerna-debug.log* -# Flask stuff: -instance/ -.webassets-cache +node_modules +.DS_Store +dist +dist-ssr +coverage +*.local -# Scrapy stuff: -.scrapy +/cypress/videos/ +/cypress/screenshots/ -# Sphinx documentation -docs/_build/ - -# PyBuilder -.pybuilder/ -target/ - -# Jupyter Notebook -.ipynb_checkpoints - -# IPython -profile_default/ -ipython_config.py - -# pyenv -# For a library or package, you might want to ignore these files since the code is -# intended to run in multiple environments; otherwise, check them in: -# .python-version - -# pipenv -# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. -# However, in case of collaboration, if having platform-specific dependencies or dependencies -# having no cross-platform support, pipenv may install dependencies that don't work, or not -# install all needed dependencies. -#Pipfile.lock - -# poetry -# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. -# This is especially recommended for binary packages to ensure reproducibility, and is more -# commonly ignored for libraries. -# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control -#poetry.lock - -# pdm -# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. -#pdm.lock -# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it -# in version control. -# https://pdm.fming.dev/#use-with-ide -.pdm.toml - -# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm -__pypackages__/ - -# Celery stuff -celerybeat-schedule -celerybeat.pid - -# SageMath parsed files -*.sage.py - -# Environments -.env -.venv -env/ -venv/ -ENV/ -env.bak/ -venv.bak/ - -# Spyder project settings -.spyderproject -.spyproject - -# Rope project settings -.ropeproject - -# mkdocs documentation -/site - -# mypy -.mypy_cache/ -.dmypy.json -dmypy.json - -# Pyre type checker -.pyre/ - -# pytype static type analyzer -.pytype/ - -# Cython debug symbols -cython_debug/ - -# PyCharm -# JetBrains specific template is maintained in a separate JetBrains.gitignore that can -# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore -# and can be added to the global gitignore or merged into this file. For a more nuclear -# option (not recommended) you can uncomment the following to ignore the entire idea folder. -#.idea/ +# Editor directories and files +.vscode/* +!.vscode/extensions.json +.idea +*.suo +*.ntvs* +*.njsproj +*.sln +*.sw? diff --git a/.prettierrc.json b/.prettierrc.json new file mode 100644 index 0000000..66e2335 --- /dev/null +++ b/.prettierrc.json @@ -0,0 +1,8 @@ +{ + "$schema": "https://json.schemastore.org/prettierrc", + "semi": false, + "tabWidth": 2, + "singleQuote": true, + "printWidth": 100, + "trailingComma": "none" +} \ No newline at end of file diff --git a/README.md b/README.md index 1777be3..b0a0b40 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,52 @@ # sd-webui-openpose-editor -Openpose editor within Stable Diffusion WebUI. + +This template should help get you started developing with Vue 3 in Vite. + +## Recommended IDE Setup + +[VSCode](https://code.visualstudio.com/) + [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar) (and disable Vetur) + [TypeScript Vue Plugin (Volar)](https://marketplace.visualstudio.com/items?itemName=Vue.vscode-typescript-vue-plugin). + +## Type Support for `.vue` Imports in TS + +TypeScript cannot handle type information for `.vue` imports by default, so we replace the `tsc` CLI with `vue-tsc` for type checking. In editors, we need [TypeScript Vue Plugin (Volar)](https://marketplace.visualstudio.com/items?itemName=Vue.vscode-typescript-vue-plugin) to make the TypeScript language service aware of `.vue` types. + +If the standalone TypeScript plugin doesn't feel fast enough to you, Volar has also implemented a [Take Over Mode](https://github.com/johnsoncodehk/volar/discussions/471#discussioncomment-1361669) that is more performant. You can enable it by the following steps: + +1. Disable the built-in TypeScript Extension + 1) Run `Extensions: Show Built-in Extensions` from VSCode's command palette + 2) Find `TypeScript and JavaScript Language Features`, right click and select `Disable (Workspace)` +2. Reload the VSCode window by running `Developer: Reload Window` from the command palette. + +## Customize configuration + +See [Vite Configuration Reference](https://vitejs.dev/config/). + +## Project Setup + +```sh +npm install +``` + +### Compile and Hot-Reload for Development + +```sh +npm run dev +``` + +### Type-Check, Compile and Minify for Production + +```sh +npm run build +``` + +### Run Unit Tests with [Vitest](https://vitest.dev/) + +```sh +npm run test:unit +``` + +### Lint with [ESLint](https://eslint.org/) + +```sh +npm run lint +``` diff --git a/env.d.ts b/env.d.ts new file mode 100644 index 0000000..11f02fe --- /dev/null +++ b/env.d.ts @@ -0,0 +1 @@ +/// diff --git a/index.html b/index.html new file mode 100644 index 0000000..a888544 --- /dev/null +++ b/index.html @@ -0,0 +1,13 @@ + + + + + + + Vite App + + +
+ + + diff --git a/javascript/openpose_editor.js b/javascript/openpose_editor.js new file mode 100644 index 0000000..f5b6c51 --- /dev/null +++ b/javascript/openpose_editor.js @@ -0,0 +1,283 @@ +/* See http://fabricjs.com/ for more information on fabric canvas API. */ +fabric.Object.prototype.transparentCorners = false; +fabric.Object.prototype.cornerColor = '#108ce6'; +fabric.Object.prototype.borderColor = '#108ce6'; +fabric.Object.prototype.cornerSize = 10; +fabric.Object.prototype.lockRotation = true; + +class OpenposeEditor { + /** + * @param {HTMLElement} canvasElem The HTML canvas element to be used as the OpenposeEditor. + */ + constructor(canvasElem) { + this.canvas = new fabric.Canvas(canvasElem, { + backgroundColor: '#000', + preserveObjectStacking: true + }); + this.people = []; + this.registerEventHandlers(); + } + + registerEventHandlers() { + this.canvas.on('object:moving', (event) => { + const keypoint = event.target; + + let selectedKeypoints = new Set(); + selectedKeypoints.add(keypoint); + if (selectedKeypoints.has(keypoint)) { + // Calculate the movement delta for the selected keypoint + const deltaX = keypoint.left - keypoint.aCoords.tl.x; + const deltaY = keypoint.top - keypoint.aCoords.tl.y; + + // Move all other selected vertices by the same delta + selectedKeypoints.forEach((selectedKeypoint) => { + if (selectedKeypoint !== keypoint) { + selectedKeypoint.set({ + left: selectedKeypoint.left + deltaX, + top: selectedKeypoint.top + deltaY, + }); + } + }); + + // Update all connections. + selectedKeypoints.forEach((selectedKeypoint) => { + selectedKeypoint.handle.connections.forEach((connection) => { + connection.pushUpdateToCanvas(); + }); + }); + } + }); + } + + addPerson(person) { + this.people.push(person); + person.addToCanvas(this.canvas); + this.canvas.requestRenderAll(); + } +}; + +class OpenposePerson { + /** + * @param {OpenposeBody} body + * @param {Array} hands + * @param {OpenposeFace} face + */ + constructor(body, hands, face) { + this.body = body; + this.hands = hands; + this.face = face; + } + + /** + * Add the person to the canvas. + * @param {fabric.Canvas} canvas + */ + addToCanvas(canvas) { + const selectionList = []; + this.body.addToCanvas(canvas, selectionList); + this.hands.forEach(hand => hand.addToCanvas(canvas, selectionList)); + this.face.addToCanvas(canvas, selectionList); + + const activeSelection = new fabric.ActiveSelection(selectionList, {canvas: canvas}); + canvas.discardActiveObject(); + canvas.setActiveObject(activeSelection); + canvas.selection = true; + } +}; + +class OpenposeKeypoint2D { + constructor(x, y, confidence, color, name) { + this.confidence = confidence; + this.name = name; + this.connections = []; + + const radius = 2; + this.circle = new fabric.Circle({ + handle: this, + radius: radius, + left: x - radius, + top: y - radius, + fill: color, + stroke: color, + strokeWidth: 1, + hasControls: false, // Disallow user to scale the keypoint circle. + hasBorders: false, + }); + } + + addConnection(connection) { + this.connections.push(connection); + } + + addToCanvas(canvas, selectionList) { + canvas.add(this.circle); + selectionList.push(this.circle); + } + + getX() { + return this.circle.left + this.circle.radius; + } + + getY() { + return this.circle.top + this.circle.radius; + } + + getColor() { + return this.circle.fill; + } + + setColor(color) { + this.circle.fill = color; + this.circle.stroke = color; + } +}; + +/** + * Connection between 2 keypoints. Direction matters. The color of connection will be applied to k2. + */ +class OpenposeConnection { + constructor(k1, k2, color) { + this.k1 = k1; + this.k2 = k2; + + this.k1.addConnection(this); + this.k2.addConnection(this); + this.line = new fabric.Line([this.k1.getX(), this.k1.getY(), this.k2.getX(), this.k2.getY()], { + handle: this, + fill: color, + stroke: color, + strokeWidth: 2, + // Connections(Edges) themselves are not selectable, they will adjust when relevant keypoints move. + selectable: false, + // Connections should not appear in events. + evented: false, + }); + } + + addToCanvas(canvas, selectionList) { + // We don't want lines to be selected so not adding line into selectionList. + canvas.add(this.line); + } + + pushUpdateToCanvas() { + this.line.set({ x1: this.k1.getX(), y1: this.k1.getY() }); + this.line.set({ x2: this.k2.getX(), y2: this.k2.getY() }); + } +} + +class OpenposeObject { + constructor(keypoints, connections) { + this.keypoints = keypoints; + this.connections = connections; + } + + addToCanvas(canvas, selectionList) { + this.keypoints.forEach(p => p.addToCanvas(canvas, selectionList)); + this.connections.forEach(c => c.addToCanvas(canvas, selectionList)); + } +}; + +class OpenposeBody extends OpenposeObject { + static keypoints_connections = [ + [0, 1], [1, 2], [2, 3], [3, 4], + [1, 5], [5, 6], [6, 7], [1, 8], + [8, 9], [9, 10], [1, 11], [11, 12], + [12, 13], [0, 14], [14, 16], [0, 15], + [15, 17], + ]; + static connection_colors = [ + [0, 0, 255], [255, 0, 0], [255, 170, 0], [255, 255, 0], + [255, 85, 0], [170, 255, 0], [85, 255, 0], [0, 255, 0], + [0, 255, 85], [0, 255, 170], [0, 255, 255], [0, 170, 255], + [0, 85, 255], [85, 0, 255], [170, 0, 255], [255, 0, 255], + [255, 0, 170], [255, 0, 85], + ]; + static keypoint_names = [ + "nose", + "neck", + "right_shoulder", + "right_elbow", + "right_wrist", + "left_shoulder", + "left_elbow", + "left_wrist", + "right_hip", + "right_knee", + "right_ankle", + "left_hip", + "left_knee", + "left_ankle", + "right_eye", + "left_eye", + "right_ear", + "left_ear", + ]; + + /** + * @param {Array>} rawKeypoints keypoints directly read from the openpose JSON format + * [ + * [x1, y1, c1], + * [x2, y2, c2], + * ... + * ] + */ + constructor(rawKeypoints) { + super(...OpenposeBody.createKeypointsAndConnections(rawKeypoints)); + } + + static createKeypointsAndConnections(rawKeypoints) { + /* Coco format has 18 keypoints. */ + if (rawKeypoints.length != 18) { + console.error(`Wrong number of keypoints for openpose body(Coco format). Expect 18 but got ${keypoints.length}.`); + return [[], []]; + } + + const keypoints = rawKeypoints.map((p, i) => new OpenposeKeypoint2D( + p[0], + p[1], + p.length >= 3 ? p[2] : 1.0, // confidence. + null, // color. + OpenposeBody.keypoint_names[i] + )); + + const connections = OpenposeBody.keypoints_connections.map((connection, i) => { + const k1 = keypoints[connection[0]]; + const k2 = keypoints[connection[1]]; + const color = `rgba(${OpenposeBody.connection_colors[i].join(", ")}, 0.7)`; + + if (k1.getColor == null) { + k1.setColor(color); + } + k2.setColor(color) + + return new OpenposeConnection(k1, k2, color); + }); + + return [keypoints, connections]; + } +}; + +class OpenposeHand extends OpenposeObject { + constructor() { + super([], []); + } +}; + +class OpenposeFace extends OpenposeObject { + constructor() { + super([], []); + } +}; + +window.addEventListener('DOMContentLoaded', () => { + const default_keypoints = [[241, 77], [241, 120], [191, 118], [177, 183], [163, 252], [298, 118], [317, 182], [332, 245], [225, 241], [213, 359], [215, 454], [270, 240], [282, 360], [286, 456], [232, 59], [253, 60], [225, 70], [260, 72]]; + const observer = new MutationObserver((m) => { + const canvasElem = gradioApp().querySelector('#cnet-openpose-editor'); + if (canvasElem) { + const editor = new OpenposeEditor(canvasElem); + editor.addPerson(new OpenposePerson(new OpenposeBody(default_keypoints), [], new OpenposeFace())); + observer.disconnect(); + } + }); + observer.observe(gradioApp(), { childList: true, subtree: true }); +}); diff --git a/package.json b/package.json new file mode 100644 index 0000000..af028ea --- /dev/null +++ b/package.json @@ -0,0 +1,39 @@ +{ + "name": "sd-webui-openpose-editor", + "version": "0.0.0", + "private": true, + "scripts": { + "dev": "vite", + "build": "run-p type-check build-only", + "preview": "vite preview", + "test:unit": "vitest", + "build-only": "vite build", + "type-check": "vue-tsc --noEmit -p tsconfig.vitest.json --composite false", + "lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .gitignore", + "format": "prettier --write src/" + }, + "dependencies": { + "pinia": "^2.0.32", + "vue": "^3.2.47" + }, + "devDependencies": { + "@rushstack/eslint-patch": "^1.2.0", + "@types/jsdom": "^21.1.0", + "@types/node": "^18.14.2", + "@vitejs/plugin-vue": "^4.0.0", + "@vitejs/plugin-vue-jsx": "^3.0.0", + "@vue/eslint-config-prettier": "^7.1.0", + "@vue/eslint-config-typescript": "^11.0.2", + "@vue/test-utils": "^2.3.0", + "@vue/tsconfig": "^0.1.3", + "eslint": "^8.34.0", + "eslint-plugin-vue": "^9.9.0", + "jsdom": "^21.1.0", + "npm-run-all": "^4.1.5", + "prettier": "^2.8.4", + "typescript": "~4.8.4", + "vite": "^4.1.4", + "vitest": "^0.29.1", + "vue-tsc": "^1.2.0" + } +} diff --git a/public/favicon.ico b/public/favicon.ico new file mode 100644 index 0000000..df36fcf Binary files /dev/null and b/public/favicon.ico differ diff --git a/scripts/__pycache__/openpose_editor.cpython-310.pyc b/scripts/__pycache__/openpose_editor.cpython-310.pyc new file mode 100644 index 0000000..7e14251 Binary files /dev/null and b/scripts/__pycache__/openpose_editor.cpython-310.pyc differ diff --git a/scripts/openpose_editor.py b/scripts/openpose_editor.py new file mode 100644 index 0000000..ef823a5 --- /dev/null +++ b/scripts/openpose_editor.py @@ -0,0 +1,34 @@ +import gradio as gr +from fastapi import FastAPI, Request +from fastapi.responses import HTMLResponse +from fastapi.staticfiles import StaticFiles +from fastapi.templating import Jinja2Templates + +from jinja2 import FileSystemLoader + +import modules.scripts as scripts +import modules.script_callbacks as script_callbacks + +VERSION = '0.0.1' +EXTENSION_DIR = 'extensions/sd-webui-openpose-editor' +TEMPLATES_DIR = f'{EXTENSION_DIR}/templates' +import os + +custom_templates_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', 'custom_templates') + +def mount_openpose_api(_: gr.Blocks, app: FastAPI): + templates = Jinja2Templates(directory=TEMPLATES_DIR) + # Configure the Jinja2 template loader to search for templates in both folders + app.jinja_loader = FileSystemLoader([custom_templates_path]) + + @app.get("/openpose_editor/greeting", response_class=HTMLResponse) + async def display_greeting(request: Request): + print('pose:', os.getcwd()) + return templates.TemplateResponse('greetings.html', {"request": request, 'name': "Charlie"}) + + @app.post('/openpose_editor') + async def index(): + pass + +script_callbacks.on_app_started(mount_openpose_api) + diff --git a/src/App.vue b/src/App.vue new file mode 100644 index 0000000..d05208d --- /dev/null +++ b/src/App.vue @@ -0,0 +1,47 @@ + + + + + diff --git a/src/assets/base.css b/src/assets/base.css new file mode 100644 index 0000000..71dc55a --- /dev/null +++ b/src/assets/base.css @@ -0,0 +1,74 @@ +/* color palette from */ +:root { + --vt-c-white: #ffffff; + --vt-c-white-soft: #f8f8f8; + --vt-c-white-mute: #f2f2f2; + + --vt-c-black: #181818; + --vt-c-black-soft: #222222; + --vt-c-black-mute: #282828; + + --vt-c-indigo: #2c3e50; + + --vt-c-divider-light-1: rgba(60, 60, 60, 0.29); + --vt-c-divider-light-2: rgba(60, 60, 60, 0.12); + --vt-c-divider-dark-1: rgba(84, 84, 84, 0.65); + --vt-c-divider-dark-2: rgba(84, 84, 84, 0.48); + + --vt-c-text-light-1: var(--vt-c-indigo); + --vt-c-text-light-2: rgba(60, 60, 60, 0.66); + --vt-c-text-dark-1: var(--vt-c-white); + --vt-c-text-dark-2: rgba(235, 235, 235, 0.64); +} + +/* semantic color variables for this project */ +:root { + --color-background: var(--vt-c-white); + --color-background-soft: var(--vt-c-white-soft); + --color-background-mute: var(--vt-c-white-mute); + + --color-border: var(--vt-c-divider-light-2); + --color-border-hover: var(--vt-c-divider-light-1); + + --color-heading: var(--vt-c-text-light-1); + --color-text: var(--vt-c-text-light-1); + + --section-gap: 160px; +} + +@media (prefers-color-scheme: dark) { + :root { + --color-background: var(--vt-c-black); + --color-background-soft: var(--vt-c-black-soft); + --color-background-mute: var(--vt-c-black-mute); + + --color-border: var(--vt-c-divider-dark-2); + --color-border-hover: var(--vt-c-divider-dark-1); + + --color-heading: var(--vt-c-text-dark-1); + --color-text: var(--vt-c-text-dark-2); + } +} + +*, +*::before, +*::after { + box-sizing: border-box; + margin: 0; + position: relative; + font-weight: normal; +} + +body { + min-height: 100vh; + color: var(--color-text); + background: var(--color-background); + transition: color 0.5s, background-color 0.5s; + line-height: 1.6; + font-family: Inter, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, + Cantarell, 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif; + font-size: 15px; + text-rendering: optimizeLegibility; + -webkit-font-smoothing: antialiased; + -moz-osx-font-smoothing: grayscale; +} diff --git a/src/assets/logo.svg b/src/assets/logo.svg new file mode 100644 index 0000000..7565660 --- /dev/null +++ b/src/assets/logo.svg @@ -0,0 +1 @@ + diff --git a/src/assets/main.css b/src/assets/main.css new file mode 100644 index 0000000..e8667cd --- /dev/null +++ b/src/assets/main.css @@ -0,0 +1,35 @@ +@import './base.css'; + +#app { + max-width: 1280px; + margin: 0 auto; + padding: 2rem; + + font-weight: normal; +} + +a, +.green { + text-decoration: none; + color: hsla(160, 100%, 37%, 1); + transition: 0.4s; +} + +@media (hover: hover) { + a:hover { + background-color: hsla(160, 100%, 37%, 0.2); + } +} + +@media (min-width: 1024px) { + body { + display: flex; + place-items: center; + } + + #app { + display: grid; + grid-template-columns: 1fr 1fr; + padding: 0 2rem; + } +} diff --git a/src/components/HelloWorld.vue b/src/components/HelloWorld.vue new file mode 100644 index 0000000..8901544 --- /dev/null +++ b/src/components/HelloWorld.vue @@ -0,0 +1,40 @@ + + + + + diff --git a/src/components/TheWelcome.vue b/src/components/TheWelcome.vue new file mode 100644 index 0000000..a70765c --- /dev/null +++ b/src/components/TheWelcome.vue @@ -0,0 +1,86 @@ + + + diff --git a/src/components/WelcomeItem.vue b/src/components/WelcomeItem.vue new file mode 100644 index 0000000..ba0def3 --- /dev/null +++ b/src/components/WelcomeItem.vue @@ -0,0 +1,86 @@ + + + diff --git a/src/components/__tests__/HelloWorld.spec.ts b/src/components/__tests__/HelloWorld.spec.ts new file mode 100644 index 0000000..2533202 --- /dev/null +++ b/src/components/__tests__/HelloWorld.spec.ts @@ -0,0 +1,11 @@ +import { describe, it, expect } from 'vitest' + +import { mount } from '@vue/test-utils' +import HelloWorld from '../HelloWorld.vue' + +describe('HelloWorld', () => { + it('renders properly', () => { + const wrapper = mount(HelloWorld, { props: { msg: 'Hello Vitest' } }) + expect(wrapper.text()).toContain('Hello Vitest') + }) +}) diff --git a/src/components/icons/IconCommunity.vue b/src/components/icons/IconCommunity.vue new file mode 100644 index 0000000..2dc8b05 --- /dev/null +++ b/src/components/icons/IconCommunity.vue @@ -0,0 +1,7 @@ + diff --git a/src/components/icons/IconDocumentation.vue b/src/components/icons/IconDocumentation.vue new file mode 100644 index 0000000..6d4791c --- /dev/null +++ b/src/components/icons/IconDocumentation.vue @@ -0,0 +1,7 @@ + diff --git a/src/components/icons/IconEcosystem.vue b/src/components/icons/IconEcosystem.vue new file mode 100644 index 0000000..c3a4f07 --- /dev/null +++ b/src/components/icons/IconEcosystem.vue @@ -0,0 +1,7 @@ + diff --git a/src/components/icons/IconSupport.vue b/src/components/icons/IconSupport.vue new file mode 100644 index 0000000..7452834 --- /dev/null +++ b/src/components/icons/IconSupport.vue @@ -0,0 +1,7 @@ + diff --git a/src/components/icons/IconTooling.vue b/src/components/icons/IconTooling.vue new file mode 100644 index 0000000..660598d --- /dev/null +++ b/src/components/icons/IconTooling.vue @@ -0,0 +1,19 @@ + + diff --git a/src/main.ts b/src/main.ts new file mode 100644 index 0000000..8b9d201 --- /dev/null +++ b/src/main.ts @@ -0,0 +1,11 @@ +import { createApp } from 'vue' +import { createPinia } from 'pinia' +import App from './App.vue' + +import './assets/main.css' + +const app = createApp(App) + +app.use(createPinia()) + +app.mount('#app') diff --git a/src/stores/counter.ts b/src/stores/counter.ts new file mode 100644 index 0000000..b6757ba --- /dev/null +++ b/src/stores/counter.ts @@ -0,0 +1,12 @@ +import { ref, computed } from 'vue' +import { defineStore } from 'pinia' + +export const useCounterStore = defineStore('counter', () => { + const count = ref(0) + const doubleCount = computed(() => count.value * 2) + function increment() { + count.value++ + } + + return { count, doubleCount, increment } +}) diff --git a/templates/greetings.html b/templates/greetings.html new file mode 100644 index 0000000..ddeb246 --- /dev/null +++ b/templates/greetings.html @@ -0,0 +1,15 @@ + + + + + + Greeting + + +

Welcome, {{ name }}!

+ + + + \ No newline at end of file diff --git a/templates/index.html b/templates/index.html new file mode 100644 index 0000000..c19342c --- /dev/null +++ b/templates/index.html @@ -0,0 +1,24 @@ + + + + + Gradio + Vue.js Example + + + +
+
+ +

{{ message }}

+
+ + + + \ No newline at end of file diff --git a/tsconfig.app.json b/tsconfig.app.json new file mode 100644 index 0000000..cdbea1d --- /dev/null +++ b/tsconfig.app.json @@ -0,0 +1,12 @@ +{ + "extends": "@vue/tsconfig/tsconfig.web.json", + "include": ["env.d.ts", "src/**/*", "src/**/*.vue"], + "exclude": ["src/**/__tests__/*"], + "compilerOptions": { + "composite": true, + "baseUrl": ".", + "paths": { + "@/*": ["./src/*"] + } + } +} diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..100cf6a --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,14 @@ +{ + "files": [], + "references": [ + { + "path": "./tsconfig.node.json" + }, + { + "path": "./tsconfig.app.json" + }, + { + "path": "./tsconfig.vitest.json" + } + ] +} diff --git a/tsconfig.node.json b/tsconfig.node.json new file mode 100644 index 0000000..424084a --- /dev/null +++ b/tsconfig.node.json @@ -0,0 +1,8 @@ +{ + "extends": "@vue/tsconfig/tsconfig.node.json", + "include": ["vite.config.*", "vitest.config.*", "cypress.config.*", "playwright.config.*"], + "compilerOptions": { + "composite": true, + "types": ["node"] + } +} diff --git a/tsconfig.vitest.json b/tsconfig.vitest.json new file mode 100644 index 0000000..d080d61 --- /dev/null +++ b/tsconfig.vitest.json @@ -0,0 +1,9 @@ +{ + "extends": "./tsconfig.app.json", + "exclude": [], + "compilerOptions": { + "composite": true, + "lib": [], + "types": ["node", "jsdom"] + } +} diff --git a/vite.config.ts b/vite.config.ts new file mode 100644 index 0000000..2fb21e9 --- /dev/null +++ b/vite.config.ts @@ -0,0 +1,15 @@ +import { fileURLToPath, URL } from 'node:url' + +import { defineConfig } from 'vite' +import vue from '@vitejs/plugin-vue' +import vueJsx from '@vitejs/plugin-vue-jsx' + +// https://vitejs.dev/config/ +export default defineConfig({ + plugins: [vue(), vueJsx()], + resolve: { + alias: { + '@': fileURLToPath(new URL('./src', import.meta.url)) + } + } +}) diff --git a/vitest.config.ts b/vitest.config.ts new file mode 100644 index 0000000..a2f57a5 --- /dev/null +++ b/vitest.config.ts @@ -0,0 +1,15 @@ +import { fileURLToPath } from 'node:url' +import { mergeConfig } from 'vite' +import { configDefaults, defineConfig } from 'vitest/config' +import viteConfig from './vite.config' + +export default mergeConfig( + viteConfig, + defineConfig({ + test: { + environment: 'jsdom', + exclude: [...configDefaults.exclude, 'e2e/*'], + root: fileURLToPath(new URL('./', import.meta.url)) + } + }) +)