├── public ├── favicon.ico ├── vue-dat-gui.png └── index.html ├── src ├── utils │ └── Number.ts ├── env.d.ts ├── index.ts └── components │ ├── index.ts │ ├── DatString.vue │ ├── DatButton.vue │ ├── DatBoolean.vue │ ├── DatSelect.vue │ ├── DatFolder.vue │ ├── private │ └── NumberSlider.vue │ ├── DatColor.vue │ ├── DatNumber.vue │ └── DatGui.vue ├── .gitignore ├── deploy.sh ├── tsconfig.json ├── LICENSE.md ├── .github └── workflows │ ├── build-deploy-gh-pages.yml │ └── npm-publish.yml ├── vite.config.ts ├── package.json └── README.md /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyrilf/vue-dat-gui/HEAD/public/favicon.ico -------------------------------------------------------------------------------- /public/vue-dat-gui.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyrilf/vue-dat-gui/HEAD/public/vue-dat-gui.png -------------------------------------------------------------------------------- /src/utils/Number.ts: -------------------------------------------------------------------------------- 1 | const clamp = (value: number, min: number, max: number) => 2 | Math.min(Math.max(value, min), max); 3 | 4 | export { clamp }; 5 | -------------------------------------------------------------------------------- /src/env.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | declare module "*.vue" { 4 | import type { DefineComponent } from "vue"; 5 | const component: DefineComponent<{}, {}, any>; 6 | export default component; 7 | } 8 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | import { App } from "vue"; 2 | import * as components from "./components"; 3 | 4 | const install = (app: App) => { 5 | for (const key in components) { 6 | // @ts-expect-error 7 | app.component(key, components[key]); 8 | } 9 | }; 10 | 11 | export default { install }; 12 | 13 | export * from "./components"; 14 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .DS_Store 3 | dist 4 | dist-ssr 5 | *.local 6 | docs/.vuepress/.cache 7 | docs/.vuepress/.temp 8 | types 9 | 10 | # local env files 11 | .env.local 12 | .env.*.local 13 | 14 | # Log files 15 | npm-debug.log* 16 | yarn-debug.log* 17 | yarn-error.log* 18 | 19 | # Editor directories and files 20 | .idea 21 | .vscode 22 | *.suo 23 | *.ntvs* 24 | *.njsproj 25 | *.sln 26 | *.sw? 27 | -------------------------------------------------------------------------------- /src/components/index.ts: -------------------------------------------------------------------------------- 1 | import DatBoolean from "./DatBoolean.vue"; 2 | import DatButton from "./DatButton.vue"; 3 | import DatColor from "./DatColor.vue"; 4 | import DatFolder from "./DatFolder.vue"; 5 | import DatGui from "./DatGui.vue"; 6 | import DatNumber from "./DatNumber.vue"; 7 | import DatSelect from "./DatSelect.vue"; 8 | import DatString from "./DatString.vue"; 9 | 10 | export { 11 | DatBoolean, 12 | DatButton, 13 | DatColor, 14 | DatFolder, 15 | DatGui, 16 | DatNumber, 17 | DatSelect, 18 | DatString, 19 | }; 20 | -------------------------------------------------------------------------------- /deploy.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ### LEGACY DEPLOY SCRIPT 4 | # Now using a Github Action 5 | 6 | # abort on errors 7 | set -e 8 | 9 | # build 10 | npm run build 11 | 12 | # navigate into the build output directory 13 | cd dist 14 | 15 | # if you are deploying to a custom domain 16 | # echo 'www.example.com' > CNAME 17 | 18 | git init 19 | git add -A 20 | git commit -m 'deploy' 21 | 22 | # if you are deploying to https://.github.io 23 | # git push -f git@github.com:/.github.io.git main 24 | 25 | # if you are deploying to https://.github.io/ 26 | git push -f git@github.com:cyrilf/vue-dat-gui.git main:gh-pages 27 | 28 | cd - 29 | -------------------------------------------------------------------------------- /src/components/DatString.vue: -------------------------------------------------------------------------------- 1 | 16 | 17 | 27 | -------------------------------------------------------------------------------- /src/components/DatButton.vue: -------------------------------------------------------------------------------- 1 | 23 | 24 | 31 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "esnext", 4 | "useDefineForClassFields": true, 5 | "module": "esnext", 6 | "moduleResolution": "node", 7 | "strict": true, 8 | "jsx": "preserve", 9 | "sourceMap": true, 10 | "resolveJsonModule": true, 11 | "esModuleInterop": true, 12 | "lib": ["esnext", "dom"], 13 | "declaration": true, 14 | "emitDeclarationOnly": true, 15 | "outDir": "dist", 16 | "declarationDir": "./dist/types", 17 | "isolatedModules": true, 18 | "skipLibCheck": true, 19 | "types": [ 20 | "vite/client" 21 | ], 22 | "paths": { 23 | "@/*": ["./src/*"] 24 | } 25 | }, 26 | "include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.vue", "src/index.ts"], 27 | "exclude": ["node_modules"] 28 | } 29 | -------------------------------------------------------------------------------- /src/components/DatBoolean.vue: -------------------------------------------------------------------------------- 1 | 19 | 20 | 35 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 cyrilf 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 10 | -------------------------------------------------------------------------------- /.github/workflows/build-deploy-gh-pages.yml: -------------------------------------------------------------------------------- 1 | name: Build and Deploy to Github Pages 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | pull_request: 8 | 9 | jobs: 10 | build-and-deploy: 11 | runs-on: ubuntu-latest 12 | permissions: 13 | contents: write 14 | concurrency: 15 | group: ${{ github.workflow }}-${{ github.ref }} 16 | 17 | steps: 18 | - name: Checkout repository 19 | uses: actions/checkout@v4 20 | 21 | - name: Setup Node.js 22 | uses: actions/setup-node@v4 23 | with: 24 | node-version: 20 25 | cache: "npm" 26 | 27 | - name: Install dependencies 28 | run: npm ci 29 | 30 | - name: Build project 31 | run: npm run build 32 | 33 | - name: Deploy to GitHub Pages 34 | uses: peaceiris/actions-gh-pages@v3 35 | if: github.ref == 'refs/heads/main' 36 | with: 37 | github_token: ${{ secrets.GITHUB_TOKEN }} 38 | publish_dir: ./dist 39 | commit_message: ${{ github.event.head_commit.message }} 40 | exclude_assets: ".github,vue-dat-gui.png,types/**/*.d.ts" 41 | -------------------------------------------------------------------------------- /vite.config.ts: -------------------------------------------------------------------------------- 1 | import path from "path"; 2 | import { fileURLToPath, URL } from "node:url"; 3 | import { defineConfig } from "vite"; 4 | import vue from "@vitejs/plugin-vue"; 5 | 6 | export default defineConfig({ 7 | plugins: [ 8 | vue(), 9 | { 10 | name: "watch-public", 11 | buildStart() { 12 | this.addWatchFile(path.resolve(__dirname, "public/index.html")); 13 | }, 14 | }, 15 | ], 16 | resolve: { 17 | alias: { 18 | "@": fileURLToPath(new URL("./src", import.meta.url)), 19 | }, 20 | }, 21 | define: { "process.env.NODE_ENV": '"production"' }, 22 | build: { 23 | lib: { 24 | entry: path.resolve(__dirname, "src/index.ts"), 25 | name: "vue-dat-gui", 26 | formats: ["es"], 27 | fileName: "vue-dat-gui", 28 | }, 29 | rollupOptions: { 30 | // external modules won't be bundled into your library 31 | external: ["vue"], 32 | output: { 33 | // disable warning on src/index.ts using both default and named export 34 | exports: "named", 35 | globals: { 36 | vue: "Vue", 37 | }, 38 | }, 39 | }, 40 | }, 41 | }); 42 | -------------------------------------------------------------------------------- /.github/workflows/npm-publish.yml: -------------------------------------------------------------------------------- 1 | name: Publish to npm 2 | 3 | on: 4 | push: 5 | tags: 6 | - "*" 7 | 8 | permissions: 9 | id-token: write 10 | 11 | jobs: 12 | build: 13 | runs-on: ubuntu-latest 14 | permissions: 15 | contents: write 16 | concurrency: 17 | group: ${{ github.workflow }}-${{ github.ref }} 18 | 19 | steps: 20 | - name: Checkout repository 21 | uses: actions/checkout@v4 22 | 23 | - name: Setup Node.js 24 | uses: actions/setup-node@v4 25 | with: 26 | node-version: 20 27 | cache: "npm" 28 | 29 | - name: Install dependencies 30 | run: npm ci 31 | 32 | - name: Build project 33 | run: npm run build 34 | 35 | publish-npm: 36 | needs: build 37 | runs-on: ubuntu-latest 38 | steps: 39 | - name: Checkout repository 40 | uses: actions/checkout@v4 41 | 42 | - name: Setup Node.js 43 | uses: actions/setup-node@v4 44 | with: 45 | node-version: 20 46 | cache: "npm" 47 | registry-url: https://registry.npmjs.org/ 48 | scope: "@cyrilf" 49 | 50 | - name: Install dependencies 51 | run: npm ci 52 | 53 | - run: npm publish --provenance 54 | env: 55 | NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} 56 | -------------------------------------------------------------------------------- /src/components/DatSelect.vue: -------------------------------------------------------------------------------- 1 | 30 | 31 | 49 | -------------------------------------------------------------------------------- /src/components/DatFolder.vue: -------------------------------------------------------------------------------- 1 | 14 | 15 | 30 | 31 | 63 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@cyrilf/vue-dat-gui", 3 | "description": "A Vue3 port of the popular dat.GUI library", 4 | "version": "1.1.0", 5 | "scripts": { 6 | "build": "vite build && vue-tsc", 7 | "prepare": "npm run build", 8 | "postversion": "git push && git push --tags", 9 | "dev": "concurrently 'vite build --watch' 'npx live-server --cors dist'" 10 | }, 11 | "dependencies": { 12 | "vue3-colorpicker": "^2.2.3" 13 | }, 14 | "peerDependencies": { 15 | "vue": "^3.4.7" 16 | }, 17 | "devDependencies": { 18 | "@types/node": "^20.10.7", 19 | "@vitejs/plugin-vue": "^5.0.2", 20 | "concurrently": "^8.2.2", 21 | "typescript": "^5.3.3", 22 | "vite": "^7.0.0", 23 | "vue-tsc": "^1.8.27" 24 | }, 25 | "repository": { 26 | "type": "git", 27 | "url": "git+ssh://git@github.com/cyrilf/vue-dat-gui.git" 28 | }, 29 | "author": "cyrilf", 30 | "homepage": "https://github.com/cyrilf/vue-dat-gui#readme", 31 | "bugs": { 32 | "url": "https://github.com/cyrilf/vue-dat-gui/issues" 33 | }, 34 | "engines": { 35 | "node": ">=20.10", 36 | "npm": ">=10" 37 | }, 38 | "keywords": [ 39 | "vue dat gui", 40 | "vue", 41 | "dat.gui" 42 | ], 43 | "main": "./dist/vue-dat-gui.js", 44 | "type": "module", 45 | "files": [ 46 | "dist" 47 | ], 48 | "types": "./dist/types/index.d.ts", 49 | "exports": { 50 | ".": { 51 | "types": "./dist/types/index.d.ts", 52 | "default": "./dist/vue-dat-gui.js" 53 | }, 54 | "./dist/style.css": "./dist/style.css" 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/components/private/NumberSlider.vue: -------------------------------------------------------------------------------- 1 | 50 | 51 | 59 | 60 | 77 | -------------------------------------------------------------------------------- /src/components/DatColor.vue: -------------------------------------------------------------------------------- 1 | 45 | 46 | 75 | 76 | 94 | -------------------------------------------------------------------------------- /src/components/DatNumber.vue: -------------------------------------------------------------------------------- 1 | 57 | 58 | 86 | 87 | 110 | -------------------------------------------------------------------------------- /src/components/DatGui.vue: -------------------------------------------------------------------------------- 1 | 25 | 26 | 55 | 56 | 77 | 78 | 219 | -------------------------------------------------------------------------------- /public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | vue-dat-gui 9 | 12 | 18 | 19 | 65 | 66 | 67 | 68 | 74 |
75 | 109 | 117 | 197 | 198 | 199 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # vue-dat-gui 2 | 3 | ![vue-dat-gui](./public/vue-dat-gui.png) 4 | 5 | > A Vue3 port of the popular [dat.GUI](https://github.com/dataarts/dat.gui) library. 6 | 7 | This is a lightweight graphical user interface to change variables in Javascript (or Typescript). 8 | Useful for all your demos or experimental codes. 9 | 10 | ## DEMO ✨ 11 | 12 | Check out the [demo page](https://cyrilf.github.io/vue-dat-gui/). 13 | 14 | ### Used by: 15 | 16 | - [cyrilf/microbios](https://microbios.cyrilf.com/): Cellular automata simulation / [Github](https://github.com/cyrilf/microbios) 17 | - ... 18 | - _Feel free to submit a PR to add your website._ 19 | 20 | --- 21 | 22 | ## INSTALL 💻 23 | 24 | ### Option 1 - Install from NPM 25 | 26 | ``` 27 | npm install --save @cyrilf/vue-dat-gui 28 | ``` 29 | 30 | Then the usage is: 31 | 32 | ```js 33 | import { createApp } from "vue"; 34 | import VueDatGui from "@cyrilf/vue-dat-gui"; 35 | import "@cyrilf/vue-dat-gui/dist/style.css"; 36 | 37 | /* your code */ 38 | // ... 39 | 40 | const app = createApp(App); 41 | app.use(VueDatGui); 42 | 43 | app.mount("#app"); 44 | ``` 45 | 46 | ### Option 2 - Instal via CDN file 47 | 48 | In your head tag, include the following code: 49 | 50 | ```html 51 | 55 | 69 | ``` 70 | 71 | --- 72 | 73 | ## VERSIONS #️⃣ 74 | 75 | ### Vue3 76 | 77 | The [main branch](https://github.com/cyrilf/vue-dat-gui/tree/main) contains code for Vue3. It's refering to the tags `v1.x`. 78 | 79 | ### Vue2 80 | 81 | The **deprecated** branch [vue2](https://github.com/cyrilf/vue-dat-gui/tree/vue2) is for Vue2 support. It's refering to the tags `v0.x`. 82 | You can find the [README](https://github.com/cyrilf/vue-dat-gui/blob/4b7da19f9a6aef1e7c8b3fcfefabe9acb7b7f737/README.md) with all the required information for this version. 83 | 84 | --- 85 | 86 | ## USAGE 🖱️ 87 | 88 | You can always refer to the [public/index.html](https://github.com/cyrilf/vue-dat-gui/tree/main/public/index.html) file for the most up-to-date example of how to use it. _(keep in mind that this is a demo version using the CDN version of Vue and vue-dat-gui, so it's a bit different than the usage in your app)_. 89 | 90 | The [demo page](https://cyrilf.github.io/vue-dat-gui/) is also available. 91 | 92 | In your view: 93 | 94 | ```html 95 |
96 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 112 | 120 | 128 | 136 | 137 | 138 | 139 | 140 | 141 |
142 | ``` 143 | 144 | In your javascript: 145 | 146 | ```js 147 | // 200 | ``` 201 | 202 | --- 203 | 204 | ## Components 205 | 206 | ### DatGui 207 | 208 | The main menu that wraps all components. (required) 209 | 210 | ```html 211 | 217 | 218 | 219 | ``` 220 | 221 | | Name | Type | Default | Description | 222 | | ---------------- | --------------------- | ------------------ | ------------------------------------------ | 223 | | `v-model:open` | `Ref` | `true` | 2ways binding to the open state of the GUI | 224 | | `open` | `boolean` | `true` | 1way binding to the open state of the GUI | 225 | | `@update:open` | `Function` | `noop` | Listener for the open change | 226 | | `open-text` | `boolean` | `'Open controls'` | Text for the open button | 227 | | `close-text` | `boolean` | `'Close controls'` | Text for the close button | 228 | | `close-position` | `'bottom'` \| `'top'` | `'bottom'` | Position of the close button | 229 | 230 | ### DatBoolean 231 | 232 | A checkbox element 233 | 234 | ```html 235 | 236 | ``` 237 | 238 | | Name | Type | Default | Description | 239 | | ---------- | -------------- | ------- | ------------------ | 240 | | `v-model` | `Ref` | `false` | 2ways binding | 241 | | `label` | `string` | `""` | Text for the label | 242 | | `disabled` | `boolean` | `false` | disabled | 243 | 244 | ### DatButton 245 | 246 | A button element 247 | 248 | ```html 249 | 250 | ``` 251 | 252 | | Name | Type | Default | Description | 253 | | ---------- | ---------- | ------- | ------------- | 254 | | `@click` | `Function` | `noop` | Click handler | 255 | | `label` | `string` | `""` | Button text | 256 | | `disabled` | `boolean` | `false` | disabled | 257 | 258 | ### DatColor 259 | 260 | A color-picker element 261 | 262 | ```html 263 | 264 | ``` 265 | 266 | | Name | Type | Default | Description | 267 | | ---------- | ------------- | ------- | ------------------ | 268 | | `v-model` | `Ref` | `""` | 2ways binding | 269 | | `label` | `string` | `""` | Text for the label | 270 | | `disabled` | `boolean` | `false` | disabled | 271 | 272 | ### DatFolder 273 | 274 | A folder element 275 | 276 | ```html 277 | 278 | 279 | 280 | ``` 281 | 282 | | Name | Type | Default | Description | 283 | | -------------- | -------------- | ------- | ------------------------------------------ | 284 | | `v-model:open` | `Ref` | `true` | 2ways binding to the open state of the GUI | 285 | | `open` | `boolean` | `true` | 1way binding to the open state of the GUI | 286 | | `@update:open` | `Function` | `noop` | Listener for the open change | 287 | | `label` | `string` | `""` | Text for the folder | 288 | 289 | ### DatNumber 290 | 291 | A number input element. If `min` and `max` are specified, then a slider is added. 292 | 293 | ```html 294 | 302 | ``` 303 | 304 | | Name | Type | Default | Description | 305 | | ---------- | ------------- | -------------------------- | ------------------ | 306 | | `v-model` | `Ref` | `""` | 2ways binding | 307 | | `min` | `number` | `Number.NEGATIVE_INFINITY` | Minimum value | 308 | | `max` | `number` | `Number.POSITIVE_INFINITY` | Maximum value | 309 | | `step` | `number` | `Read note below*` | Incremental value | 310 | | `label` | `string` | `""` | Text for the label | 311 | | `disabled` | `boolean` | `false` | disabled | 312 | 313 | **`Note*`**: it's the "order of magnitude of the absolute difference between max and min and returns a power of 10 corresponding to that order of magnitude". 314 | 315 | ### DatSelect 316 | 317 | A select element 318 | 319 | ```html 320 | 321 | ``` 322 | 323 | ``` 324 | Type Item = { name: string; value: string; } | string | number 325 | ``` 326 | 327 | | Name | Type | Default | Description | 328 | | ---------- | ------------------------------ | ------- | -------------------------- | 329 | | `v-model` | `Ref` \| `Ref` | `""` | 2ways binding | 330 | | `items` | `Item[]` | `[]` | The options for the select | 331 | | `label` | `string` | `""` | Text for the label | 332 | | `disabled` | `boolean` | `false` | disabled | 333 | 334 | ### DatString 335 | 336 | A text input element 337 | 338 | ```html 339 | 340 | ``` 341 | 342 | | Name | Type | Default | Description | 343 | | ---------- | ------------- | ------- | ------------------ | 344 | | `v-model` | `Ref` | `""` | 2ways binding | 345 | | `label` | `string` | `""` | Text for the label | 346 | | `disabled` | `boolean` | `false` | disabled | 347 | 348 | ### Deploy 349 | 350 | ``` 351 | ./deploy 352 | ``` 353 | 354 | Feel free to open any Pull Request/Issues. 355 | 356 | --- 357 | 358 | ## THANKS 👌 359 | 360 | - [dat.GUI](https://github.com/dataarts/dat.gui) for the initial project 361 | --------------------------------------------------------------------------------