Repository: ckpack/vue-color Branch: main Commit: 053f05f462d1 Files: 59 Total size: 84.3 KB Directory structure: gitextract_w8xtql1h/ ├── .eslintignore ├── .eslintrc.cjs ├── .gitattributes ├── .github/ │ └── workflows/ │ └── npm-publish.yml ├── .gitignore ├── .husky/ │ ├── .gitignore │ ├── commit-msg │ └── pre-commit ├── CHANGELOG.md ├── LICENSE ├── README.md ├── build/ │ ├── build.config.js │ ├── build.dist.js │ └── build.libs.js ├── commitlint.config.cjs ├── dev/ │ ├── serve.js │ └── serve.vue ├── example/ │ └── index.html ├── jsconfig.json ├── package.json ├── scripts/ │ ├── gen-compoents.js │ └── gen.js ├── src/ │ ├── components/ │ │ ├── alpha/ │ │ │ ├── alpha.vue │ │ │ └── index.js │ │ ├── checkboard/ │ │ │ ├── checkboard.vue │ │ │ └── index.js │ │ ├── chrome/ │ │ │ ├── chrome.vue │ │ │ └── index.js │ │ ├── compact/ │ │ │ ├── compact.vue │ │ │ └── index.js │ │ ├── editable-input/ │ │ │ ├── editable-input.vue │ │ │ └── index.js │ │ ├── grayscale/ │ │ │ ├── grayscale.vue │ │ │ └── index.js │ │ ├── hue/ │ │ │ ├── hue.vue │ │ │ └── index.js │ │ ├── material/ │ │ │ ├── index.js │ │ │ └── material.vue │ │ ├── photoshop/ │ │ │ ├── index.js │ │ │ └── photoshop.vue │ │ ├── saturation/ │ │ │ ├── index.js │ │ │ └── saturation.vue │ │ ├── sketch/ │ │ │ ├── index.js │ │ │ └── sketch.vue │ │ ├── slider/ │ │ │ ├── index.js │ │ │ └── slider.vue │ │ ├── swatches/ │ │ │ ├── index.js │ │ │ └── swatches.vue │ │ └── twitter/ │ │ ├── index.js │ │ └── twitter.vue │ ├── components.js │ ├── create.js │ ├── defaultConfig.js │ ├── index.js │ ├── mixin/ │ │ └── color.js │ ├── preset.js │ └── utils/ │ ├── compoent.js │ └── utils.js └── types.d.ts ================================================ FILE CONTENTS ================================================ ================================================ FILE: .eslintignore ================================================ dist/ libs/ website/ node_modules/ ================================================ FILE: .eslintrc.cjs ================================================ module.exports = { extends: [ '@antfu', ], rules: { 'semi': 'off', '@typescript-eslint/semi': ['error', 'always'], 'no-console': 'off', 'vue/require-explicit-emits': 'off', 'unused-imports/no-unused-vars': 'off', }, }; ================================================ FILE: .gitattributes ================================================ # Auto detect text files and perform LF normalization * text=auto ================================================ FILE: .github/workflows/npm-publish.yml ================================================ # This workflow will run tests using node and then publish a package to GitHub Packages when a release is created # For more information see: https://help.github.com/actions/language-and-framework-guides/publishing-nodejs-packages name: Node.js Package on: push: tags: - '*' jobs: publish-npm: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - uses: actions/setup-node@v1 with: node-version: 18 registry-url: https://registry.npmjs.org/ - run: npm install --force - run: npm run build - run: npm publish --access=public env: NODE_AUTH_TOKEN: ${{secrets.npm_token}} - name: deploy uses: peaceiris/actions-gh-pages@v3 with: github_token: ${{ secrets.GITHUB_TOKEN }} publish_dir: ./example ================================================ FILE: .gitignore ================================================ node_modules/ dist/ libs/ website/ ================================================ FILE: .husky/.gitignore ================================================ _ ================================================ FILE: .husky/commit-msg ================================================ #!/bin/sh . "$(dirname "$0")/_/husky.sh" npx --no-install commitlint --edit "$1" ================================================ FILE: .husky/pre-commit ================================================ #!/bin/sh . "$(dirname "$0")/_/husky.sh" npx lint-staged ================================================ FILE: CHANGELOG.md ================================================ # Changelog All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. ## [1.6.0](https://github.com/ckpack/vue-color/compare/v1.5.2...v1.6.0) (2024-07-19) ### Features * exported ColorMixin ([dbbe373](https://github.com/ckpack/vue-color/commit/dbbe373cfcc901f5e9a72cae2f6758bcc16dad53)) ### [1.5.2](https://github.com/ckpack/vue-color/compare/v1.5.0...v1.5.2) (2024-07-18) ### [1.5.1](https://github.com/ckpack/vue-color/compare/v1.5.0...v1.5.1) (2024-07-18) ### Features Added `MIT` license to the `package.json` ## [1.5.0](https://github.com/ckpack/vue-color/compare/v1.4.1...v1.5.0) (2023-06-15) ### Features * chrome compoent add a props named format (hex, rgb, etc) and an event update:format; fix [#28](https://github.com/ckpack/vue-color/issues/28) ([c9f3a5c](https://github.com/ckpack/vue-color/commit/c9f3a5cb1df733246f9b99c06088417c363a7d22)) ### [1.4.1](https://github.com/ckpack/vue-color/compare/v1.4.0...v1.4.1) (2023-02-16) ### Bug Fixes * update package.json ([aec3072](https://github.com/ckpack/vue-color/commit/aec30723de33d9366f3c1d1cd6cc18a18eb44b0b)) ## [1.4.0](https://github.com/ckpack/vue-color/compare/v1.3.0...v1.4.0) (2023-02-16) ### Features * add Type declarations ([213b3e2](https://github.com/ckpack/vue-color/commit/213b3e20451f4f177ec16ab3c7d0356a46cbcd61)) ## [1.3.0](https://github.com/ckpack/vue-color/compare/v1.2.4...v1.3.0) (2022-11-30) ### Features * add keyboard navigation support for swatches and twitter ([a0ff7aa](https://github.com/ckpack/vue-color/commit/a0ff7aa7cc0afe450e01416250cd61d512093dd2)) ### [1.2.4](https://github.com/ckpack/vue-color/compare/v1.2.3...v1.2.4) (2022-10-17) ### Bug Fixes * update github_token ([2c78f05](https://github.com/ckpack/vue-color/commit/2c78f055498aba5815625bf677f3b76a9fc37299)) ### [1.2.3](https://github.com/ckpack/vue-color/compare/v1.2.2...v1.2.3) (2022-10-17) ### Bug Fixes * change yarn to npm ([2ef2928](https://github.com/ckpack/vue-color/commit/2ef292831439c407de8d2218a0df0c6f3c74dd23)) ### [1.2.2](https://github.com/ckpack/vue-color/compare/v1.2.1...v1.2.2) (2022-10-17) ### Bug Fixes * upgrade node version ([2ecf716](https://github.com/ckpack/vue-color/commit/2ecf716ea1995c4af524bb7df7149464dfb20875)) ### [1.2.1](https://github.com/ckpack/vue-color/compare/v1.2.0...v1.2.1) (2022-10-17) ## [1.2.0](https://github.com/ckpack/vue-color/compare/v1.1.9...v1.2.0) (2022-07-11) ### Features * explicitly export the type as module ([5fbf273](https://github.com/ckpack/vue-color/commit/5fbf27390cb3cf7be5fedc6e8dcda3c9e9317636)) ### [1.1.9](https://github.com/ckpack/vue-color/compare/v1.1.8...v1.1.9) (2022-04-12) ### Bug Fixes * sketch presetColors alpha not work ([93ec741](https://github.com/ckpack/vue-color/commit/93ec7413e6785e19b31e5c3760001cbd3e5be91c)) ### [1.1.8](https://github.com/ckpack/vue-color/compare/v1.1.7...v1.1.8) (2022-02-22) ### Bug Fixes * tinycolor(...).isValid is not a function ([7831c54](https://github.com/ckpack/vue-color/commit/7831c54654a702b587f03007a6d4539287cdb91d)) ### [1.1.7](https://github.com/ckpack/vue-color/compare/v1.1.6...v1.1.7) (2022-02-16) ### Bug Fixes * replace CommonJS package ([6f1292f](https://github.com/ckpack/vue-color/commit/6f1292f3fe95fee68aff30e3ea45e5799247b2a1)) ### [1.1.6](https://github.com/ckpack/vue-color/compare/v1.1.5...v1.1.6) (2022-02-14) ### Bug Fixes * use replace tinycolor2 with @ctrl/tinycolor ([09bb612](https://github.com/ckpack/vue-color/commit/09bb612c50467fda655e8b6b36c16d7b120263d6)) ### [1.1.5](https://github.com/ckpack/vue-color/compare/v1.1.4...v1.1.5) (2021-12-08) ### Bug Fixes * esm result exclude vue module ([d61b120](https://github.com/ckpack/vue-color/commit/d61b120542fbf531b22a73dbfe814b99bc4ad828)) * **hue:** emit color on mouseup just like saturation does ([9d8c798](https://github.com/ckpack/vue-color/commit/9d8c798728dfd985dac3f5ef8331adadf5de929c)) ### [1.1.4](https://github.com/ckpack/vue-color/compare/v1.1.3...v1.1.4) (2021-10-21) ### Bug Fixes * repair production mode component import error ([c6aa16f](https://github.com/ckpack/vue-color/commit/c6aa16f638a72beffdf493f531cd85da85ecdfa5)) ### [1.1.3](https://github.com/ckpack/vue-color/compare/v1.1.2...v1.1.3) (2021-10-15) ### [1.1.2](https://github.com/ckpack/vue-color/compare/v1.1.1...v1.1.2) (2021-10-15) ### Bug Fixes * update peerDependencies vue version ([22d57bf](https://github.com/ckpack/vue-color/commit/22d57bf7a5fc789a357dd7f2c43870a15db48d38)) ### [1.1.1](https://github.com/ckpack/vue-color/compare/v1.1.0...v1.1.1) (2021-10-14) ### Bug Fixes * excluded dependencies module when build libs ([6b0d860](https://github.com/ckpack/vue-color/commit/6b0d860c2b2f6d07f31c195b4a93c1e7a58fc941)) * update dev serve.js ([915233d](https://github.com/ckpack/vue-color/commit/915233dc2c6602aac00d7acbf4142dfb2b2f9112)) ## [1.1.0](https://github.com/ckpack/vue-color/compare/v1.0.1...v1.1.0) (2021-09-09) ### Features * add standard-version gen changelog ([43cb18b](https://github.com/ckpack/vue-color/commit/43cb18b00b5a9f3d4a2921db6b5dcb98b47e81a8)) * pre-commit add lint-staged ([d0e7ddb](https://github.com/ckpack/vue-color/commit/d0e7ddbe7dd0ed29ce13ba23af8c766df33798cb)) * pre-commit add lint-staged ([2c63fff](https://github.com/ckpack/vue-color/commit/2c63fffcb15eefc278e3c6b2ab54622238664730)) * pre-commit add lint-staged ([31602b5](https://github.com/ckpack/vue-color/commit/31602b5d06c561392115b3d6b43f91aca9449b34)) # [1.0.0] - 2021-08-26 ## Feature Now we can import on Demand (Tree Shaking) ================================================ FILE: LICENSE ================================================ MIT License Copyright (c) 2021 chenkai0520 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: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 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. ================================================ FILE: README.md ================================================ # vue-color > Modified based on [https://github.com/xiaokaike/vue-color](https://github.com/xiaokaike/vue-color) to support vue3.0 🎨 Vue Color Pickers for Sketch, Photoshop, Chrome & more ![image](https://user-images.githubusercontent.com/30174970/114983369-1e5aa380-9ec3-11eb-9e77-b122d19f1ebd.png) ## [Demo](https://ckpack.github.io/vue-color) ## Use case #### On demand We can import components we actually need, making the project smaller than otherwise. ##### Import Directly ```html ``` ##### Install on Demand Globally ```js import { createApp } from 'vue'; import App from '@/App.vue'; import { Sketch, create } from '@ckpack/vue-color'; const app = createApp(App); app.use(create({ components: [Sketch], })); app.mount('#app'); ``` #### Fully import ```js import { createApp } from 'vue'; import App from '@/App.vue'; import VueColor from '@ckpack/vue-color'; const app = createApp(App); app.use(VueColor); app.mount('#app'); ``` ## [CHANGELOG](/CHANGELOG.md) ## License vue-color is licensed under [The MIT License](LICENSE). ================================================ FILE: build/build.config.js ================================================ import path from 'path'; import resolve from '@rollup/plugin-node-resolve'; import alias from '@rollup/plugin-alias'; import vue from 'rollup-plugin-vue'; import terser from '@rollup/plugin-terser'; import postcss from 'rollup-plugin-postcss'; import commonjs from '@rollup/plugin-commonjs'; import prefixer from 'postcss-prefixer'; import { cssPrefix, name } from '../src/defaultConfig.js'; import packageJson from '../package.json' assert { type: 'json' }; const { dependencies } = packageJson; const projectRoot = path.resolve(__dirname, '../src'); const globals = { // Provide global variable names to replace your external imports, eg. jquery: '$' vue: 'Vue', }; const postcssPlugin = (options = {}) => { const minimize = options.minimize !== false; const exclude = options.exclude || /node_modules/; const include = options.include || /(? facadeModuleId.replace(`${projectRoot}/`, ''), globals: output.globals, }, plugins: [ ...basePlugins, plugins.postcss(), ], external: [...external.vue, ...external.dependencies], }, ]; ================================================ FILE: commitlint.config.cjs ================================================ module.exports = { extends: ['@commitlint/config-conventional'], }; ================================================ FILE: dev/serve.js ================================================ import { createApp } from 'vue'; import Dev from './serve.vue'; const app = createApp(Dev); app.mount('#app'); ================================================ FILE: dev/serve.vue ================================================ ================================================ FILE: example/index.html ================================================ vue-color
================================================ FILE: jsconfig.json ================================================ { "compilerOptions": { "baseUrl": ".", "checkJs": false, "paths": { "@/*": ["src/*"] } }, "include": ["src/**/*"], "exclude": ["node_modules", "dist", "libs", "website"] } ================================================ FILE: package.json ================================================ { "name": "@ckpack/vue-color", "version": "1.6.0", "description": "(vue3.0) 🎨 Vue Color Pickers for Sketch, Photoshop, Chrome & more", "repository": "https://github.com/ckpack/vue-color", "sideEffects": false, "type": "module", "types": "./types.d.ts", "main": "dist/index.js", "module": "libs/index.js", "unpkg": "dist/index.min.js", "author": "chenkai", "license": "MIT", "keywords": [ "vue-color", "color", "vuejs" ], "files": [ "dist/*", "src/*", "libs/*", "types.d.ts" ], "scripts": { "dev": "vue-cli-service serve dev/serve.js", "build": "npm run build:libs && npm run build:dist", "build:libs": "rm -rf ./libs && rollup --bundleConfigAsCjs --config ./build/build.libs.js", "build:dist": "rm -rf ./dist && rollup --bundleConfigAsCjs --config ./build/build.dist.js", "build:style": "", "build:website": "vue-cli-service build --dest website dev/serve.js", "lint": "eslint --fix --ext .js,.vue ./", "gen": "node ./scripts/gen.js", "gen:compoents": "node ./scripts/gen-compoents.js", "prepare": "husky install", "release": "standard-version" }, "devDependencies": { "@commitlint/cli": "^17.4.3", "@commitlint/config-conventional": "^17.4.3", "@rollup/plugin-alias": "^4.0.3", "@rollup/plugin-commonjs": "^24.0.1", "@rollup/plugin-node-resolve": "^15.0.1", "@vue/cli-service": "^5.0.8", "@vue/compiler-sfc": "^3.2.47", "eslint": "^8.34.0", "@antfu/eslint-config": "0.35.2", "glob": "^8.1.0", "husky": "^8.0.3", "lint-staged": "^13.1.2", "postcss": "^8.4.21", "postcss-prefixer": "^2.1.3", "rollup": "^3.15.0", "rollup-plugin-postcss": "^4.0.2", "@rollup/plugin-terser": "^0.4.0", "rollup-plugin-vue": "^6.0.0", "standard-version": "^9.5.0", "vue": "3.2.41" }, "peerDependencies": { "vue": "^3.2.0" }, "dependencies": { "material-colors": "^1.2.6", "@ctrl/tinycolor": "^3.6.0" }, "engines": { "node": ">=12" }, "lint-staged": { "*.{js,jsx,vue}": [ "eslint --fix" ] } } ================================================ FILE: scripts/gen-compoents.js ================================================ import fs from 'fs'; const basePath = process.cwd(); function formatComponent(component) { return component.split('-').map(name => name.slice(0, 1).toUpperCase() + name.slice(1)).join(''); } function getCompoentsJS() { const components = fs.readdirSync(`${basePath}/src/components`); let componentsJS = '/* Do not modify the automatically generated code */\n'; componentsJS += components.map(name => `import ${formatComponent(name)} from '@/components/${name}';\n`).join(''); componentsJS += `\nconst components = [\n${components.map(name => ` ${formatComponent(name)},\n`).join('')}];\n`; componentsJS += `\nexport {\n components,\n${components.map(name => ` ${formatComponent(name)},\n`).join('')}};\n`; return componentsJS; } fs.writeFileSync(`${basePath}/src/components.js`, getCompoentsJS()); ================================================ FILE: scripts/gen.js ================================================ import fs from 'fs'; function formatComponent(component) { return component.split('-').map(name => name.slice(0, 1).toUpperCase() + name.slice(1)).join(''); } const basePath = process.cwd(); const componentName = process.argv.slice(2).join(' '); const formatComponentName = formatComponent(componentName); if (!/^[a-z]+(-[a-z]+){0,}$/.test(componentName)) { console.error(`component name is incorrect: ${componentName}\netc:\nbutton\nsome-button\nsome-button-group`); process.exit(1); } if (fs.existsSync(`${basePath}/src/components/${componentName}`)) { console.error(`component name is already exist: ${componentName}`); process.exit(1); } fs.mkdirSync(`${basePath}/src/components/${componentName}`); fs.writeFileSync(`${basePath}/src/components/${componentName}/${componentName}.vue`, ` `); fs.writeFileSync(`${basePath}/src/components/${componentName}/${componentName}.scss`, `@import '../../styles/var.scss'; .${componentName} {}`); fs.writeFileSync(`${basePath}/src/components/${componentName}/index.js`, `import ${formatComponentName} from './${componentName}.vue'; export default ${formatComponentName}; `); // require('./gen-compoents'); ================================================ FILE: src/components/alpha/alpha.vue ================================================ ================================================ FILE: src/components/alpha/index.js ================================================ import Alpha from './alpha.vue'; import { install } from '@/utils/compoent'; Alpha.install = install; export default Alpha; ================================================ FILE: src/components/checkboard/checkboard.vue ================================================ ================================================ FILE: src/components/checkboard/index.js ================================================ import Checkboard from './checkboard.vue'; import { install } from '@/utils/compoent'; Checkboard.install = install; export default Checkboard; ================================================ FILE: src/components/chrome/chrome.vue ================================================ ================================================ FILE: src/components/chrome/index.js ================================================ import Chrome from './chrome.vue'; import { install } from '@/utils/compoent'; Chrome.install = install; export default Chrome; ================================================ FILE: src/components/compact/compact.vue ================================================ ================================================ FILE: src/components/compact/index.js ================================================ import Compact from './compact.vue'; import { install } from '@/utils/compoent'; Compact.install = install; export default Compact; ================================================ FILE: src/components/editable-input/editable-input.vue ================================================ ================================================ FILE: src/components/editable-input/index.js ================================================ import EditableInput from './editable-input.vue'; import { install } from '@/utils/compoent'; EditableInput.install = install; export default EditableInput; ================================================ FILE: src/components/grayscale/grayscale.vue ================================================ ================================================ FILE: src/components/grayscale/index.js ================================================ import Grayscale from './grayscale.vue'; import { install } from '@/utils/compoent'; Grayscale.install = install; export default Grayscale; ================================================ FILE: src/components/hue/hue.vue ================================================ ================================================ FILE: src/components/hue/index.js ================================================ import Hue from './hue.vue'; import { install } from '@/utils/compoent'; Hue.install = install; export default Hue; ================================================ FILE: src/components/material/index.js ================================================ import Material from './material.vue'; import { install } from '@/utils/compoent'; Material.install = install; export default Material; ================================================ FILE: src/components/material/material.vue ================================================ ================================================ FILE: src/components/photoshop/index.js ================================================ import Photoshop from './photoshop.vue'; import { install } from '@/utils/compoent'; Photoshop.install = install; export default Photoshop; ================================================ FILE: src/components/photoshop/photoshop.vue ================================================ ================================================ FILE: src/components/saturation/index.js ================================================ import Saturation from './saturation.vue'; import { install } from '@/utils/compoent'; Saturation.install = install; export default Saturation; ================================================ FILE: src/components/saturation/saturation.vue ================================================ ================================================ FILE: src/components/sketch/index.js ================================================ import Sketch from './sketch.vue'; import { install } from '@/utils/compoent'; Sketch.install = install; export default Sketch; ================================================ FILE: src/components/sketch/sketch.vue ================================================ ================================================ FILE: src/components/slider/index.js ================================================ import Slider from './slider.vue'; import { install } from '@/utils/compoent'; Slider.install = install; export default Slider; ================================================ FILE: src/components/slider/slider.vue ================================================ ================================================ FILE: src/components/swatches/index.js ================================================ import Swatches from './swatches.vue'; import { install } from '@/utils/compoent'; Swatches.install = install; export default Swatches; ================================================ FILE: src/components/swatches/swatches.vue ================================================ ================================================ FILE: src/components/twitter/index.js ================================================ import Twitter from './twitter.vue'; import { install } from '@/utils/compoent'; Twitter.install = install; export default Twitter; ================================================ FILE: src/components/twitter/twitter.vue ================================================ ================================================ FILE: src/components.js ================================================ /* Do not modify the automatically generated code */ import Alpha from '@/components/alpha'; import Checkboard from '@/components/checkboard'; import Chrome from '@/components/chrome'; import Compact from '@/components/compact'; import EditableInput from '@/components/editable-input'; import Grayscale from '@/components/grayscale'; import Hue from '@/components/hue'; import Material from '@/components/material'; import Photoshop from '@/components/photoshop'; import Saturation from '@/components/saturation'; import Sketch from '@/components/sketch'; import Slider from '@/components/slider'; import Swatches from '@/components/swatches'; import Twitter from '@/components/twitter'; const components = [ Alpha, Checkboard, Chrome, Compact, EditableInput, Grayscale, Hue, Material, Photoshop, Saturation, Sketch, Slider, Swatches, Twitter, ]; export { components, Alpha, Checkboard, Chrome, Compact, EditableInput, Grayscale, Hue, Material, Photoshop, Saturation, Sketch, Slider, Swatches, Twitter, }; ================================================ FILE: src/create.js ================================================ import { prefix, size } from '@/defaultConfig'; function create(params = {}) { return (app) => { const { components, componentPrefix = prefix, componentSize = size } = params; app.config.globalProperties.$VUI = { size: componentSize, prefix: componentPrefix, }; (Array.isArray(components) ? components : Object.values(components)).forEach((component) => { app.component(`${componentPrefix}${component.name}`, component); }); }; } export default create; ================================================ FILE: src/defaultConfig.js ================================================ const name = 'VueColor'; // 自定义组件前缀 const prefix = ''; const cssPrefix = ''; const size = 'medium'; export { name, prefix, size, cssPrefix, }; ================================================ FILE: src/index.js ================================================ import preset from '@/preset'; import create from '@/create'; import ColorMixin from '@/mixin/color'; export * from '@/components'; export { preset as default, preset as install, create, ColorMixin, }; ================================================ FILE: src/mixin/color.js ================================================ import { TinyColor } from '@ctrl/tinycolor'; function tinycolor(...args) { return new TinyColor(...args); } function _colorChange(data, oldHue) { const alpha = data && data.a; let color; // hsl is better than hex between conversions if (data && data.hsl) color = tinycolor(data.hsl); else if (data && data.hex && data.hex.length > 0) color = tinycolor(data.hex); else if (data && data.hsv) color = tinycolor(data.hsv); else if (data && data.rgba) color = tinycolor(data.rgba); else if (data && data.rgb) color = tinycolor(data.rgb); else color = tinycolor(data); if (color && (color._a === undefined || color._a === null)) color.setAlpha(alpha || color.getAlpha()); const hsl = color.toHsl(); const hsv = color.toHsv(); if (hsl.s === 0) hsv.h = hsl.h = data.h || (data.hsl && data.hsl.h) || oldHue || 0; /* --- comment this block to fix #109, may cause #25 again --- */ // when the hsv.v is less than 0.0164 (base on test) // because of possible loss of precision // the result of hue and saturation would be miscalculated if (hsv.v < 0.0164) { hsv.h = data.h || (data.hsv && data.hsv.h) || 0; hsv.s = data.s || (data.hsv && data.hsv.s) || 0; } if (hsl.l < 0.01) { hsl.h = data.h || (data.hsl && data.hsl.h) || 0; hsl.s = data.s || (data.hsl && data.hsl.s) || 0; } /* ------ */ return { hsl, hex: color.toHexString().toUpperCase(), hex8: color.toHex8String().toUpperCase(), rgba: color.toRgb(), hsv, oldHue: data.h || oldHue || hsl.h, source: data.source, a: color.getAlpha(), }; } export default { model: { prop: 'modelValue', event: 'update:modelValue', }, props: ['modelValue'], data() { return { val: _colorChange(this.modelValue), }; }, computed: { colors: { get() { return this.val; }, set(newVal) { this.val = newVal; this.$emit('update:modelValue', newVal); }, }, }, watch: { modelValue(newVal) { this.val = _colorChange(newVal); }, }, methods: { colorChange(data, oldHue) { this.oldHue = this.colors.hsl.h; this.colors = _colorChange(data, oldHue || this.oldHue); }, isValidHex(hex) { return tinycolor(hex).isValid; }, simpleCheckForValidColor(data) { const keysToCheck = ['r', 'g', 'b', 'a', 'h', 's', 'l', 'v']; let checked = 0; let passed = 0; for (let i = 0; i < keysToCheck.length; i++) { const letter = keysToCheck[i]; if (data[letter]) { checked++; if (!isNaN(data[letter])) passed++; } } if (checked === passed) return data; }, paletteUpperCase(palette) { return palette.map(c => c.toUpperCase()); }, isTransparent(color) { return tinycolor(color).getAlpha() === 0; }, }, }; ================================================ FILE: src/preset.js ================================================ import create from '@/create'; import { components } from '@/components'; const preset = create({ components, }); export default preset; ================================================ FILE: src/utils/compoent.js ================================================ import { prefix } from '@/defaultConfig'; export const install = function (app, options) { const { componentPrefix = prefix } = options || {}; app.component(`${componentPrefix}${this.name}`, this); }; ================================================ FILE: src/utils/utils.js ================================================ export function clamp(value, min, max) { return min < max ? (value < min ? min : value > max ? max : value) : (value < max ? max : value > min ? min : value); } ================================================ FILE: types.d.ts ================================================ declare module '@ckpack/vue-color' { import type { DefineComponent } from 'vue'; import type { ColorInput, HSV, HSL, RGBA } from '@ctrl/tinycolor'; interface Payload { a: number hex: string hex8: string hsl: HSL hsv: HSV oldHue: number rgba: RGBA source: 'rgba' | 'hsl' | 'hex' | 'hsv' | 'hsva' } interface Props { modelValue?: ColorInput 'onUpdate:modelValue'?: (data: Payload) => void } interface Context { colorChange: Function; isValidHex: Function simpleCheckForValidColor: Function paletteUpperCase: Function isTransparent: Function } const Chrome: DefineComponent; const Compact: DefineComponent; const Grayscale: DefineComponent; const Material: DefineComponent; const Photoshop: DefineComponent; const Sketch: DefineComponent; const Slider: DefineComponent; const Swatches: DefineComponent; const Twitter: DefineComponent; }