@lukso/web-components 1.6.3 → 1.7.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/color-palette.cjs +1363 -0
- package/dist/{shared/utils/color-palette.d.ts → color-palette.d.ts} +1 -2
- package/dist/color-palette.d.ts.map +1 -0
- package/dist/color-palette.js +1356 -0
- package/dist/components/index.cjs +74 -0
- package/dist/components/index.d.ts +2 -1
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/index.js +17 -7354
- package/dist/components/lukso-button/index.cjs +144 -0
- package/dist/components/lukso-button/index.js +95 -1190
- package/dist/components/lukso-card/index.cjs +143 -0
- package/dist/components/lukso-card/index.js +61 -1487
- package/dist/components/lukso-icon/index.cjs +4366 -0
- package/dist/components/lukso-icon/index.js +1713 -2410
- package/dist/components/lukso-input/index.cjs +219 -0
- package/dist/components/lukso-input/index.d.ts +1 -2
- package/dist/components/lukso-input/index.d.ts.map +1 -1
- package/dist/components/lukso-input/index.js +128 -1229
- package/dist/components/lukso-modal/index.cjs +70 -0
- package/dist/components/lukso-modal/index.d.ts +18 -0
- package/dist/components/lukso-modal/index.d.ts.map +1 -0
- package/dist/components/lukso-modal/index.js +68 -0
- package/dist/components/lukso-navbar/index.cjs +75 -0
- package/dist/components/lukso-navbar/index.d.ts.map +1 -1
- package/dist/components/lukso-navbar/index.js +45 -1155
- package/dist/components/lukso-profile/index.cjs +547 -0
- package/dist/components/lukso-profile/index.js +483 -1370
- package/dist/components/lukso-sanitize/index.cjs +1730 -0
- package/dist/components/lukso-sanitize/index.js +1643 -1544
- package/dist/components/lukso-tag/index.cjs +78 -0
- package/dist/components/lukso-tag/index.js +52 -1189
- package/dist/components/lukso-test/index.cjs +120 -0
- package/dist/components/lukso-test/index.js +65 -1767
- package/dist/components/lukso-username/index.cjs +126 -0
- package/dist/components/lukso-username/index.js +75 -1206
- package/dist/components/lukso-wizard/index.cjs +93 -0
- package/dist/components/lukso-wizard/index.js +47 -1253
- package/dist/directive-9ec64c08.js +28 -0
- package/dist/directive-db00f5fb.cjs +34 -0
- package/dist/index-3a24432e.js +59 -0
- package/dist/index-4a1ee696.cjs +67 -0
- package/dist/index-714323c9.js +18 -0
- package/dist/index-7dc05ee5.cjs +20 -0
- package/dist/index.cjs +74 -0
- package/dist/index.js +17 -7354
- package/dist/shared/tailwind-element/index.cjs +10 -0
- package/dist/shared/tailwind-element/index.js +1 -1064
- package/dist/state-7fde94d1.js +9 -0
- package/dist/state-a62a7d5d.cjs +11 -0
- package/dist/style-map-17d4829d.cjs +12 -0
- package/dist/style-map-52bada0b.js +10 -0
- package/dist/styles/main.css.map +1 -1
- package/package.json +85 -147
- package/tools/assets/fonts/index.cjs +10 -0
- package/tools/assets/fonts/index.d.ts +2 -0
- package/tools/assets/fonts/index.d.ts.map +1 -0
- package/tools/assets/fonts/index.js +6 -0
- package/tools/assets/images/index.cjs +10 -0
- package/tools/assets/images/index.d.ts +2 -0
- package/tools/assets/images/index.d.ts.map +1 -0
- package/tools/assets/images/index.js +6 -0
- package/tools/assets/index.cjs +15 -0
- package/tools/assets/index.d.ts +4 -0
- package/tools/assets/index.d.ts.map +1 -0
- package/tools/assets/index.js +9 -0
- package/tools/color-palette-a34f5d09.js +1356 -0
- package/tools/color-palette-bf5780ed.cjs +1362 -0
- package/tools/color-palette.cjs +11 -146
- package/tools/color-palette.d.ts +39 -52
- package/tools/color-palette.d.ts.map +1 -1
- package/tools/color-palette.js +1 -0
- package/tools/copy-assets.cjs +50 -136
- package/tools/copy-assets.d.ts +7 -9
- package/tools/copy-assets.d.ts.map +1 -1
- package/tools/copy-assets.js +49 -0
- package/tools/index.cjs +35 -0
- package/tools/index.d.ts +6 -0
- package/tools/index.d.ts.map +1 -0
- package/tools/index.js +22 -0
- package/tools/sass/index.cjs +7 -0
- package/tools/sass/index.js +1 -0
- package/tools/styles/index.cjs +5 -0
- package/tools/styles/index.js +3 -0
- package/tools/styles/main.css +287 -0
- package/CHANGELOG.md +0 -287
- package/dist/assets/fonts/index.js +0 -4
- package/dist/assets/fonts/index.ts +0 -1
- package/dist/assets/fonts/index.umd.cjs +0 -1
- package/dist/assets/images/index.js +0 -4
- package/dist/assets/images/index.ts +0 -1
- package/dist/assets/images/index.umd.cjs +0 -1
- package/dist/assets/index.js +0 -4
- package/dist/assets/index.ts +0 -1
- package/dist/assets/index.umd.cjs +0 -1
- package/dist/color-palette/index.js +0 -705
- package/dist/color-palette/index.umd.cjs +0 -1
- package/dist/components/index.umd.cjs +0 -3756
- package/dist/components/lukso-button/index.umd.cjs +0 -88
- package/dist/components/lukso-card/index.umd.cjs +0 -145
- package/dist/components/lukso-icon/index.umd.cjs +0 -3465
- package/dist/components/lukso-input/index.umd.cjs +0 -109
- package/dist/components/lukso-navbar/index.umd.cjs +0 -73
- package/dist/components/lukso-profile/index.umd.cjs +0 -90
- package/dist/components/lukso-sanitize/index.umd.cjs +0 -61
- package/dist/components/lukso-tag/index.umd.cjs +0 -67
- package/dist/components/lukso-test/index.umd.cjs +0 -95
- package/dist/components/lukso-username/index.umd.cjs +0 -75
- package/dist/components/lukso-wizard/index.umd.cjs +0 -89
- package/dist/index.umd.cjs +0 -3756
- package/dist/sass/index.js +0 -4
- package/dist/sass/index.ts +0 -1
- package/dist/sass/index.umd.cjs +0 -1
- package/dist/shared/assets/index.d.ts +0 -3
- package/dist/shared/assets/index.d.ts.map +0 -1
- package/dist/shared/directives/custom-class-map/index.d.ts +0 -26
- package/dist/shared/directives/custom-class-map/index.d.ts.map +0 -1
- package/dist/shared/directives/index.d.ts +0 -2
- package/dist/shared/directives/index.d.ts.map +0 -1
- package/dist/shared/styles/index.d.ts +0 -3
- package/dist/shared/styles/index.d.ts.map +0 -1
- package/dist/shared/tailwind-element/index.umd.cjs +0 -39
- package/dist/shared/tailwind-element.js +0 -1064
- package/dist/shared/tailwind-element.umd.cjs +0 -39
- package/dist/shared/utils/color-palette.d.ts.map +0 -1
- package/dist/styles/index.js +0 -4
- package/dist/styles/index.umd.cjs +0 -1
- package/src/components/index.ts +0 -13
- package/src/components/lukso-button/index.ts +0 -145
- package/src/components/lukso-button/lukso-button.stories.ts +0 -216
- package/src/components/lukso-card/index.ts +0 -131
- package/src/components/lukso-card/lukso-card.stories.ts +0 -191
- package/src/components/lukso-card/style.scss +0 -7
- package/src/components/lukso-icon/icons/add-photo.ts +0 -46
- package/src/components/lukso-icon/icons/arrow-down-lg.ts +0 -26
- package/src/components/lukso-icon/icons/arrow-down-sm.ts +0 -26
- package/src/components/lukso-icon/icons/arrow-left-lg.ts +0 -26
- package/src/components/lukso-icon/icons/arrow-left-sm.ts +0 -26
- package/src/components/lukso-icon/icons/arrow-right-lg.ts +0 -26
- package/src/components/lukso-icon/icons/arrow-right-sm.ts +0 -26
- package/src/components/lukso-icon/icons/arrow-up-lg.ts +0 -26
- package/src/components/lukso-icon/icons/arrow-up-sm.ts +0 -26
- package/src/components/lukso-icon/icons/barbell-outline.ts +0 -54
- package/src/components/lukso-icon/icons/bulb-outline.ts +0 -54
- package/src/components/lukso-icon/icons/camera.ts +0 -40
- package/src/components/lukso-icon/icons/clipboard.ts +0 -59
- package/src/components/lukso-icon/icons/clock.ts +0 -31
- package/src/components/lukso-icon/icons/close-lg.ts +0 -33
- package/src/components/lukso-icon/icons/close-sm.ts +0 -33
- package/src/components/lukso-icon/icons/cloud.ts +0 -25
- package/src/components/lukso-icon/icons/compass-outline.ts +0 -29
- package/src/components/lukso-icon/icons/complete-filled-fade-in.ts +0 -34
- package/src/components/lukso-icon/icons/complete-filled.ts +0 -32
- package/src/components/lukso-icon/icons/complete-outline.ts +0 -31
- package/src/components/lukso-icon/icons/connect.ts +0 -33
- package/src/components/lukso-icon/icons/connections.ts +0 -34
- package/src/components/lukso-icon/icons/contract-lock.ts +0 -43
- package/src/components/lukso-icon/icons/controller.ts +0 -55
- package/src/components/lukso-icon/icons/copy.ts +0 -31
- package/src/components/lukso-icon/icons/cross-outline.ts +0 -38
- package/src/components/lukso-icon/icons/dots.ts +0 -22
- package/src/components/lukso-icon/icons/edit.ts +0 -30
- package/src/components/lukso-icon/icons/error.ts +0 -31
- package/src/components/lukso-icon/icons/eth-logo.ts +0 -50
- package/src/components/lukso-icon/icons/expand.ts +0 -31
- package/src/components/lukso-icon/icons/extension.ts +0 -31
- package/src/components/lukso-icon/icons/eye-hide.ts +0 -47
- package/src/components/lukso-icon/icons/eye-show.ts +0 -37
- package/src/components/lukso-icon/icons/filter.ts +0 -43
- package/src/components/lukso-icon/icons/fish-outline.ts +0 -36
- package/src/components/lukso-icon/icons/flip.ts +0 -45
- package/src/components/lukso-icon/icons/globe.ts +0 -61
- package/src/components/lukso-icon/icons/google-color.ts +0 -35
- package/src/components/lukso-icon/icons/hamburger.ts +0 -40
- package/src/components/lukso-icon/icons/infinite.ts +0 -33
- package/src/components/lukso-icon/icons/information.ts +0 -38
- package/src/components/lukso-icon/icons/key-outline.ts +0 -25
- package/src/components/lukso-icon/icons/link.ts +0 -33
- package/src/components/lukso-icon/icons/link1.ts +0 -39
- package/src/components/lukso-icon/icons/link2.ts +0 -46
- package/src/components/lukso-icon/icons/link3.ts +0 -32
- package/src/components/lukso-icon/icons/link4.ts +0 -52
- package/src/components/lukso-icon/icons/loading.ts +0 -50
- package/src/components/lukso-icon/icons/location.ts +0 -33
- package/src/components/lukso-icon/icons/locked.ts +0 -44
- package/src/components/lukso-icon/icons/login-2.ts +0 -55
- package/src/components/lukso-icon/icons/login-3.ts +0 -53
- package/src/components/lukso-icon/icons/login.ts +0 -39
- package/src/components/lukso-icon/icons/logo-chrome.ts +0 -35
- package/src/components/lukso-icon/icons/lyx-logo.ts +0 -41
- package/src/components/lukso-icon/icons/mail.ts +0 -33
- package/src/components/lukso-icon/icons/menu-1.ts +0 -71
- package/src/components/lukso-icon/icons/menu-2.ts +0 -61
- package/src/components/lukso-icon/icons/migrate.ts +0 -47
- package/src/components/lukso-icon/icons/minimize.ts +0 -53
- package/src/components/lukso-icon/icons/network.ts +0 -49
- package/src/components/lukso-icon/icons/notifications.ts +0 -33
- package/src/components/lukso-icon/icons/phone-portrait-outline.ts +0 -33
- package/src/components/lukso-icon/icons/pin.ts +0 -25
- package/src/components/lukso-icon/icons/play-filled.ts +0 -23
- package/src/components/lukso-icon/icons/play-outline.ts +0 -24
- package/src/components/lukso-icon/icons/plus.ts +0 -33
- package/src/components/lukso-icon/icons/profile-add.ts +0 -43
- package/src/components/lukso-icon/icons/profile-export.ts +0 -42
- package/src/components/lukso-icon/icons/profile-import.ts +0 -42
- package/src/components/lukso-icon/icons/profile-recovery-2.ts +0 -62
- package/src/components/lukso-icon/icons/profile-recovery.ts +0 -55
- package/src/components/lukso-icon/icons/profile-restore.ts +0 -50
- package/src/components/lukso-icon/icons/profile.ts +0 -29
- package/src/components/lukso-icon/icons/progress-complete.ts +0 -289
- package/src/components/lukso-icon/icons/progress-indicator.ts +0 -236
- package/src/components/lukso-icon/icons/pulse-dot.ts +0 -22
- package/src/components/lukso-icon/icons/qr-code.ts +0 -122
- package/src/components/lukso-icon/icons/relayer.ts +0 -40
- package/src/components/lukso-icon/icons/reload.ts +0 -32
- package/src/components/lukso-icon/icons/return-down.ts +0 -33
- package/src/components/lukso-icon/icons/return-left.ts +0 -33
- package/src/components/lukso-icon/icons/return-right.ts +0 -33
- package/src/components/lukso-icon/icons/return-up.ts +0 -33
- package/src/components/lukso-icon/icons/search.ts +0 -28
- package/src/components/lukso-icon/icons/settings.ts +0 -33
- package/src/components/lukso-icon/icons/smart-contract-doc.ts +0 -40
- package/src/components/lukso-icon/icons/smart-contract.ts +0 -31
- package/src/components/lukso-icon/icons/star-filled.ts +0 -23
- package/src/components/lukso-icon/icons/star-outline.ts +0 -24
- package/src/components/lukso-icon/icons/step-dot.ts +0 -34
- package/src/components/lukso-icon/icons/step-progress.ts +0 -31
- package/src/components/lukso-icon/icons/steps.ts +0 -40
- package/src/components/lukso-icon/icons/tick.ts +0 -26
- package/src/components/lukso-icon/icons/timer-outline.ts +0 -47
- package/src/components/lukso-icon/icons/transaction-receive.ts +0 -39
- package/src/components/lukso-icon/icons/transaction-send.ts +0 -39
- package/src/components/lukso-icon/icons/transfer.ts +0 -47
- package/src/components/lukso-icon/icons/trash.ts +0 -40
- package/src/components/lukso-icon/icons/turn-down.ts +0 -33
- package/src/components/lukso-icon/icons/turn-left.ts +0 -33
- package/src/components/lukso-icon/icons/turn-right.ts +0 -33
- package/src/components/lukso-icon/icons/turn-up.ts +0 -33
- package/src/components/lukso-icon/icons/unlocked.ts +0 -41
- package/src/components/lukso-icon/icons/wallet-outline.ts +0 -35
- package/src/components/lukso-icon/icons/warning-round.ts +0 -32
- package/src/components/lukso-icon/icons/warning-triangle.ts +0 -32
- package/src/components/lukso-icon/index.ts +0 -310
- package/src/components/lukso-icon/lukso-icon.stories.ts +0 -116
- package/src/components/lukso-icon/style.scss +0 -3
- package/src/components/lukso-input/index.ts +0 -211
- package/src/components/lukso-input/lukso-input.stories.ts +0 -184
- package/src/components/lukso-navbar/index.ts +0 -63
- package/src/components/lukso-navbar/lukso-navbar.stories.ts +0 -70
- package/src/components/lukso-profile/index.ts +0 -106
- package/src/components/lukso-profile/lukso-profile.stories.ts +0 -104
- package/src/components/lukso-sanitize/index.ts +0 -28
- package/src/components/lukso-sanitize/lukso-sanitize.stories.ts +0 -30
- package/src/components/lukso-tag/index.ts +0 -68
- package/src/components/lukso-tag/lukso-tag.stories.ts +0 -129
- package/src/components/lukso-test/index.ts +0 -72
- package/src/components/lukso-test/test.component.scss +0 -7
- package/src/components/lukso-test/test.stories.ts +0 -31
- package/src/components/lukso-username/index.ts +0 -105
- package/src/components/lukso-username/lukso-username.stories.ts +0 -98
- package/src/components/lukso-wizard/index.ts +0 -74
- package/src/components/lukso-wizard/lukso-wizard.stories.ts +0 -52
- package/src/docs/animations.stories.mdx +0 -83
- package/src/docs/colors.stories.mdx +0 -77
- package/src/docs/drop-shadows.stories.mdx +0 -108
- package/src/docs/icons.stories.mdx +0 -1590
- package/src/docs/typography.stories.mdx +0 -253
- package/src/index.ts +0 -1
- package/src/postcss.config.ts +0 -8
- package/src/shared/assets/fonts/Apax-Bold.woff2 +0 -0
- package/src/shared/assets/fonts/Apax-Light.woff2 +0 -0
- package/src/shared/assets/fonts/Apax-Medium.woff2 +0 -0
- package/src/shared/assets/fonts/Apax-Regular.woff2 +0 -0
- package/src/shared/assets/fonts/Inter-Bold.woff2 +0 -0
- package/src/shared/assets/fonts/Inter-ExtraBold.woff2 +0 -0
- package/src/shared/assets/fonts/Inter-Medium.woff2 +0 -0
- package/src/shared/assets/fonts/Inter-Regular.woff2 +0 -0
- package/src/shared/assets/fonts/Inter-SemiBold.woff2 +0 -0
- package/src/shared/assets/fonts/Inter-Thin.woff2 +0 -0
- package/src/shared/assets/fonts/PT-Mono-Bold.woff2 +0 -0
- package/src/shared/assets/fonts/PT-Mono-Regular.woff2 +0 -0
- package/src/shared/assets/fonts/index.ts +0 -1
- package/src/shared/assets/images/index.ts +0 -1
- package/src/shared/assets/images/lukso-logo.svg +0 -3
- package/src/shared/assets/images/profile-default.png +0 -0
- package/src/shared/assets/index.ts +0 -1
- package/src/shared/directives/custom-class-map/index.ts +0 -49
- package/src/shared/directives/index.ts +0 -1
- package/src/shared/globals.d.ts +0 -5
- package/src/shared/styles/colors.scss +0 -91
- package/src/shared/styles/component.scss +0 -13
- package/src/shared/styles/fonts.scss +0 -97
- package/src/shared/styles/index.ts +0 -1
- package/src/shared/styles/main.scss +0 -13
- package/src/shared/styles/typography.scss +0 -142
- package/src/shared/styles/variables.scss +0 -5
- package/src/shared/tailwind-element/index.ts +0 -16
- package/src/shared/utils/__tests__/slice-address.spec.ts +0 -15
- package/src/shared/utils/color-palette.ts +0 -76
- package/src/shared/utils/copy-assets.ts +0 -80
- package/src/shared/utils/hsl-color-map.ts +0 -20
- package/src/shared/utils/slice-address.ts +0 -30
- /package/{dist → tools}/assets/fonts/Apax-Bold.woff2 +0 -0
- /package/{dist → tools}/assets/fonts/Apax-Light.woff2 +0 -0
- /package/{dist → tools}/assets/fonts/Apax-Medium.woff2 +0 -0
- /package/{dist → tools}/assets/fonts/Apax-Regular.woff2 +0 -0
- /package/{dist → tools}/assets/fonts/Inter-Bold.woff2 +0 -0
- /package/{dist → tools}/assets/fonts/Inter-ExtraBold.woff2 +0 -0
- /package/{dist → tools}/assets/fonts/Inter-Medium.woff2 +0 -0
- /package/{dist → tools}/assets/fonts/Inter-Regular.woff2 +0 -0
- /package/{dist → tools}/assets/fonts/Inter-SemiBold.woff2 +0 -0
- /package/{dist → tools}/assets/fonts/Inter-Thin.woff2 +0 -0
- /package/{dist → tools}/assets/fonts/PT-Mono-Bold.woff2 +0 -0
- /package/{dist → tools}/assets/fonts/PT-Mono-Regular.woff2 +0 -0
- /package/{dist → tools}/assets/images/lukso-logo.svg +0 -0
- /package/{dist → tools}/assets/images/profile-default.png +0 -0
- /package/{dist/shared/utils → tools}/hsl-color-map.d.ts +0 -0
- /package/{dist/shared/utils → tools}/hsl-color-map.d.ts.map +0 -0
- /package/{dist → tools}/sass/colors.scss +0 -0
- /package/{dist → tools}/sass/component.scss +0 -0
- /package/{dist → tools}/sass/fonts.scss +0 -0
- /package/{dist/shared/assets/fonts → tools/sass}/index.d.ts +0 -0
- /package/{dist/shared/assets/fonts → tools/sass}/index.d.ts.map +0 -0
- /package/{dist → tools}/sass/main.scss +0 -0
- /package/{dist → tools}/sass/typography.scss +0 -0
- /package/{dist → tools}/sass/variables.scss +0 -0
- /package/{dist/shared/utils → tools}/slice-address.d.ts +0 -0
- /package/{dist/shared/utils → tools}/slice-address.d.ts.map +0 -0
- /package/{dist/shared/assets/images → tools/styles}/index.d.ts +0 -0
- /package/{dist/shared/assets/images → tools/styles}/index.d.ts.map +0 -0
|
@@ -0,0 +1,1363 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
+
|
|
5
|
+
// This file is autogenerated. It's used to publish ESM to npm.
|
|
6
|
+
// https://github.com/bgrins/TinyColor
|
|
7
|
+
// Brian Grinstead, MIT License
|
|
8
|
+
|
|
9
|
+
const trimLeft = /^\s+/;
|
|
10
|
+
const trimRight = /\s+$/;
|
|
11
|
+
|
|
12
|
+
function tinycolor(color, opts) {
|
|
13
|
+
color = color ? color : "";
|
|
14
|
+
opts = opts || {};
|
|
15
|
+
|
|
16
|
+
// If input is already a tinycolor, return itself
|
|
17
|
+
if (color instanceof tinycolor) {
|
|
18
|
+
return color;
|
|
19
|
+
}
|
|
20
|
+
// If we are called as a function, call using new instead
|
|
21
|
+
if (!(this instanceof tinycolor)) {
|
|
22
|
+
return new tinycolor(color, opts);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
var rgb = inputToRGB(color);
|
|
26
|
+
(this._originalInput = color),
|
|
27
|
+
(this._r = rgb.r),
|
|
28
|
+
(this._g = rgb.g),
|
|
29
|
+
(this._b = rgb.b),
|
|
30
|
+
(this._a = rgb.a),
|
|
31
|
+
(this._roundA = Math.round(100 * this._a) / 100),
|
|
32
|
+
(this._format = opts.format || rgb.format);
|
|
33
|
+
this._gradientType = opts.gradientType;
|
|
34
|
+
|
|
35
|
+
// Don't let the range of [0,255] come back in [0,1].
|
|
36
|
+
// Potentially lose a little bit of precision here, but will fix issues where
|
|
37
|
+
// .5 gets interpreted as half of the total, instead of half of 1
|
|
38
|
+
// If it was supposed to be 128, this was already taken care of by `inputToRgb`
|
|
39
|
+
if (this._r < 1) this._r = Math.round(this._r);
|
|
40
|
+
if (this._g < 1) this._g = Math.round(this._g);
|
|
41
|
+
if (this._b < 1) this._b = Math.round(this._b);
|
|
42
|
+
|
|
43
|
+
this._ok = rgb.ok;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
tinycolor.prototype = {
|
|
47
|
+
isDark: function () {
|
|
48
|
+
return this.getBrightness() < 128;
|
|
49
|
+
},
|
|
50
|
+
isLight: function () {
|
|
51
|
+
return !this.isDark();
|
|
52
|
+
},
|
|
53
|
+
isValid: function () {
|
|
54
|
+
return this._ok;
|
|
55
|
+
},
|
|
56
|
+
getOriginalInput: function () {
|
|
57
|
+
return this._originalInput;
|
|
58
|
+
},
|
|
59
|
+
getFormat: function () {
|
|
60
|
+
return this._format;
|
|
61
|
+
},
|
|
62
|
+
getAlpha: function () {
|
|
63
|
+
return this._a;
|
|
64
|
+
},
|
|
65
|
+
getBrightness: function () {
|
|
66
|
+
//http://www.w3.org/TR/AERT#color-contrast
|
|
67
|
+
var rgb = this.toRgb();
|
|
68
|
+
return (rgb.r * 299 + rgb.g * 587 + rgb.b * 114) / 1000;
|
|
69
|
+
},
|
|
70
|
+
getLuminance: function () {
|
|
71
|
+
//http://www.w3.org/TR/2008/REC-WCAG20-20081211/#relativeluminancedef
|
|
72
|
+
var rgb = this.toRgb();
|
|
73
|
+
var RsRGB, GsRGB, BsRGB, R, G, B;
|
|
74
|
+
RsRGB = rgb.r / 255;
|
|
75
|
+
GsRGB = rgb.g / 255;
|
|
76
|
+
BsRGB = rgb.b / 255;
|
|
77
|
+
|
|
78
|
+
if (RsRGB <= 0.03928) R = RsRGB / 12.92;
|
|
79
|
+
else R = Math.pow((RsRGB + 0.055) / 1.055, 2.4);
|
|
80
|
+
if (GsRGB <= 0.03928) G = GsRGB / 12.92;
|
|
81
|
+
else G = Math.pow((GsRGB + 0.055) / 1.055, 2.4);
|
|
82
|
+
if (BsRGB <= 0.03928) B = BsRGB / 12.92;
|
|
83
|
+
else B = Math.pow((BsRGB + 0.055) / 1.055, 2.4);
|
|
84
|
+
return 0.2126 * R + 0.7152 * G + 0.0722 * B;
|
|
85
|
+
},
|
|
86
|
+
setAlpha: function (value) {
|
|
87
|
+
this._a = boundAlpha(value);
|
|
88
|
+
this._roundA = Math.round(100 * this._a) / 100;
|
|
89
|
+
return this;
|
|
90
|
+
},
|
|
91
|
+
toHsv: function () {
|
|
92
|
+
var hsv = rgbToHsv(this._r, this._g, this._b);
|
|
93
|
+
return { h: hsv.h * 360, s: hsv.s, v: hsv.v, a: this._a };
|
|
94
|
+
},
|
|
95
|
+
toHsvString: function () {
|
|
96
|
+
var hsv = rgbToHsv(this._r, this._g, this._b);
|
|
97
|
+
var h = Math.round(hsv.h * 360),
|
|
98
|
+
s = Math.round(hsv.s * 100),
|
|
99
|
+
v = Math.round(hsv.v * 100);
|
|
100
|
+
return this._a == 1
|
|
101
|
+
? "hsv(" + h + ", " + s + "%, " + v + "%)"
|
|
102
|
+
: "hsva(" + h + ", " + s + "%, " + v + "%, " + this._roundA + ")";
|
|
103
|
+
},
|
|
104
|
+
toHsl: function () {
|
|
105
|
+
var hsl = rgbToHsl(this._r, this._g, this._b);
|
|
106
|
+
return { h: hsl.h * 360, s: hsl.s, l: hsl.l, a: this._a };
|
|
107
|
+
},
|
|
108
|
+
toHslString: function () {
|
|
109
|
+
var hsl = rgbToHsl(this._r, this._g, this._b);
|
|
110
|
+
var h = Math.round(hsl.h * 360),
|
|
111
|
+
s = Math.round(hsl.s * 100),
|
|
112
|
+
l = Math.round(hsl.l * 100);
|
|
113
|
+
return this._a == 1
|
|
114
|
+
? "hsl(" + h + ", " + s + "%, " + l + "%)"
|
|
115
|
+
: "hsla(" + h + ", " + s + "%, " + l + "%, " + this._roundA + ")";
|
|
116
|
+
},
|
|
117
|
+
toHex: function (allow3Char) {
|
|
118
|
+
return rgbToHex(this._r, this._g, this._b, allow3Char);
|
|
119
|
+
},
|
|
120
|
+
toHexString: function (allow3Char) {
|
|
121
|
+
return "#" + this.toHex(allow3Char);
|
|
122
|
+
},
|
|
123
|
+
toHex8: function (allow4Char) {
|
|
124
|
+
return rgbaToHex(this._r, this._g, this._b, this._a, allow4Char);
|
|
125
|
+
},
|
|
126
|
+
toHex8String: function (allow4Char) {
|
|
127
|
+
return "#" + this.toHex8(allow4Char);
|
|
128
|
+
},
|
|
129
|
+
toRgb: function () {
|
|
130
|
+
return {
|
|
131
|
+
r: Math.round(this._r),
|
|
132
|
+
g: Math.round(this._g),
|
|
133
|
+
b: Math.round(this._b),
|
|
134
|
+
a: this._a,
|
|
135
|
+
};
|
|
136
|
+
},
|
|
137
|
+
toRgbString: function () {
|
|
138
|
+
return this._a == 1
|
|
139
|
+
? "rgb(" +
|
|
140
|
+
Math.round(this._r) +
|
|
141
|
+
", " +
|
|
142
|
+
Math.round(this._g) +
|
|
143
|
+
", " +
|
|
144
|
+
Math.round(this._b) +
|
|
145
|
+
")"
|
|
146
|
+
: "rgba(" +
|
|
147
|
+
Math.round(this._r) +
|
|
148
|
+
", " +
|
|
149
|
+
Math.round(this._g) +
|
|
150
|
+
", " +
|
|
151
|
+
Math.round(this._b) +
|
|
152
|
+
", " +
|
|
153
|
+
this._roundA +
|
|
154
|
+
")";
|
|
155
|
+
},
|
|
156
|
+
toPercentageRgb: function () {
|
|
157
|
+
return {
|
|
158
|
+
r: Math.round(bound01(this._r, 255) * 100) + "%",
|
|
159
|
+
g: Math.round(bound01(this._g, 255) * 100) + "%",
|
|
160
|
+
b: Math.round(bound01(this._b, 255) * 100) + "%",
|
|
161
|
+
a: this._a,
|
|
162
|
+
};
|
|
163
|
+
},
|
|
164
|
+
toPercentageRgbString: function () {
|
|
165
|
+
return this._a == 1
|
|
166
|
+
? "rgb(" +
|
|
167
|
+
Math.round(bound01(this._r, 255) * 100) +
|
|
168
|
+
"%, " +
|
|
169
|
+
Math.round(bound01(this._g, 255) * 100) +
|
|
170
|
+
"%, " +
|
|
171
|
+
Math.round(bound01(this._b, 255) * 100) +
|
|
172
|
+
"%)"
|
|
173
|
+
: "rgba(" +
|
|
174
|
+
Math.round(bound01(this._r, 255) * 100) +
|
|
175
|
+
"%, " +
|
|
176
|
+
Math.round(bound01(this._g, 255) * 100) +
|
|
177
|
+
"%, " +
|
|
178
|
+
Math.round(bound01(this._b, 255) * 100) +
|
|
179
|
+
"%, " +
|
|
180
|
+
this._roundA +
|
|
181
|
+
")";
|
|
182
|
+
},
|
|
183
|
+
toName: function () {
|
|
184
|
+
if (this._a === 0) {
|
|
185
|
+
return "transparent";
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
if (this._a < 1) {
|
|
189
|
+
return false;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
return hexNames[rgbToHex(this._r, this._g, this._b, true)] || false;
|
|
193
|
+
},
|
|
194
|
+
toFilter: function (secondColor) {
|
|
195
|
+
var hex8String = "#" + rgbaToArgbHex(this._r, this._g, this._b, this._a);
|
|
196
|
+
var secondHex8String = hex8String;
|
|
197
|
+
var gradientType = this._gradientType ? "GradientType = 1, " : "";
|
|
198
|
+
|
|
199
|
+
if (secondColor) {
|
|
200
|
+
var s = tinycolor(secondColor);
|
|
201
|
+
secondHex8String = "#" + rgbaToArgbHex(s._r, s._g, s._b, s._a);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
return (
|
|
205
|
+
"progid:DXImageTransform.Microsoft.gradient(" +
|
|
206
|
+
gradientType +
|
|
207
|
+
"startColorstr=" +
|
|
208
|
+
hex8String +
|
|
209
|
+
",endColorstr=" +
|
|
210
|
+
secondHex8String +
|
|
211
|
+
")"
|
|
212
|
+
);
|
|
213
|
+
},
|
|
214
|
+
toString: function (format) {
|
|
215
|
+
var formatSet = !!format;
|
|
216
|
+
format = format || this._format;
|
|
217
|
+
|
|
218
|
+
var formattedString = false;
|
|
219
|
+
var hasAlpha = this._a < 1 && this._a >= 0;
|
|
220
|
+
var needsAlphaFormat =
|
|
221
|
+
!formatSet &&
|
|
222
|
+
hasAlpha &&
|
|
223
|
+
(format === "hex" ||
|
|
224
|
+
format === "hex6" ||
|
|
225
|
+
format === "hex3" ||
|
|
226
|
+
format === "hex4" ||
|
|
227
|
+
format === "hex8" ||
|
|
228
|
+
format === "name");
|
|
229
|
+
|
|
230
|
+
if (needsAlphaFormat) {
|
|
231
|
+
// Special case for "transparent", all other non-alpha formats
|
|
232
|
+
// will return rgba when there is transparency.
|
|
233
|
+
if (format === "name" && this._a === 0) {
|
|
234
|
+
return this.toName();
|
|
235
|
+
}
|
|
236
|
+
return this.toRgbString();
|
|
237
|
+
}
|
|
238
|
+
if (format === "rgb") {
|
|
239
|
+
formattedString = this.toRgbString();
|
|
240
|
+
}
|
|
241
|
+
if (format === "prgb") {
|
|
242
|
+
formattedString = this.toPercentageRgbString();
|
|
243
|
+
}
|
|
244
|
+
if (format === "hex" || format === "hex6") {
|
|
245
|
+
formattedString = this.toHexString();
|
|
246
|
+
}
|
|
247
|
+
if (format === "hex3") {
|
|
248
|
+
formattedString = this.toHexString(true);
|
|
249
|
+
}
|
|
250
|
+
if (format === "hex4") {
|
|
251
|
+
formattedString = this.toHex8String(true);
|
|
252
|
+
}
|
|
253
|
+
if (format === "hex8") {
|
|
254
|
+
formattedString = this.toHex8String();
|
|
255
|
+
}
|
|
256
|
+
if (format === "name") {
|
|
257
|
+
formattedString = this.toName();
|
|
258
|
+
}
|
|
259
|
+
if (format === "hsl") {
|
|
260
|
+
formattedString = this.toHslString();
|
|
261
|
+
}
|
|
262
|
+
if (format === "hsv") {
|
|
263
|
+
formattedString = this.toHsvString();
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
return formattedString || this.toHexString();
|
|
267
|
+
},
|
|
268
|
+
clone: function () {
|
|
269
|
+
return tinycolor(this.toString());
|
|
270
|
+
},
|
|
271
|
+
|
|
272
|
+
_applyModification: function (fn, args) {
|
|
273
|
+
var color = fn.apply(null, [this].concat([].slice.call(args)));
|
|
274
|
+
this._r = color._r;
|
|
275
|
+
this._g = color._g;
|
|
276
|
+
this._b = color._b;
|
|
277
|
+
this.setAlpha(color._a);
|
|
278
|
+
return this;
|
|
279
|
+
},
|
|
280
|
+
lighten: function () {
|
|
281
|
+
return this._applyModification(lighten, arguments);
|
|
282
|
+
},
|
|
283
|
+
brighten: function () {
|
|
284
|
+
return this._applyModification(brighten, arguments);
|
|
285
|
+
},
|
|
286
|
+
darken: function () {
|
|
287
|
+
return this._applyModification(darken, arguments);
|
|
288
|
+
},
|
|
289
|
+
desaturate: function () {
|
|
290
|
+
return this._applyModification(desaturate, arguments);
|
|
291
|
+
},
|
|
292
|
+
saturate: function () {
|
|
293
|
+
return this._applyModification(saturate, arguments);
|
|
294
|
+
},
|
|
295
|
+
greyscale: function () {
|
|
296
|
+
return this._applyModification(greyscale, arguments);
|
|
297
|
+
},
|
|
298
|
+
spin: function () {
|
|
299
|
+
return this._applyModification(spin, arguments);
|
|
300
|
+
},
|
|
301
|
+
|
|
302
|
+
_applyCombination: function (fn, args) {
|
|
303
|
+
return fn.apply(null, [this].concat([].slice.call(args)));
|
|
304
|
+
},
|
|
305
|
+
analogous: function () {
|
|
306
|
+
return this._applyCombination(analogous, arguments);
|
|
307
|
+
},
|
|
308
|
+
complement: function () {
|
|
309
|
+
return this._applyCombination(complement, arguments);
|
|
310
|
+
},
|
|
311
|
+
monochromatic: function () {
|
|
312
|
+
return this._applyCombination(monochromatic, arguments);
|
|
313
|
+
},
|
|
314
|
+
splitcomplement: function () {
|
|
315
|
+
return this._applyCombination(splitcomplement, arguments);
|
|
316
|
+
},
|
|
317
|
+
// Disabled until https://github.com/bgrins/TinyColor/issues/254
|
|
318
|
+
// polyad: function (number) {
|
|
319
|
+
// return this._applyCombination(polyad, [number]);
|
|
320
|
+
// },
|
|
321
|
+
triad: function () {
|
|
322
|
+
return this._applyCombination(polyad, [3]);
|
|
323
|
+
},
|
|
324
|
+
tetrad: function () {
|
|
325
|
+
return this._applyCombination(polyad, [4]);
|
|
326
|
+
},
|
|
327
|
+
};
|
|
328
|
+
|
|
329
|
+
// If input is an object, force 1 into "1.0" to handle ratios properly
|
|
330
|
+
// String input requires "1.0" as input, so 1 will be treated as 1
|
|
331
|
+
tinycolor.fromRatio = function (color, opts) {
|
|
332
|
+
if (typeof color == "object") {
|
|
333
|
+
var newColor = {};
|
|
334
|
+
for (var i in color) {
|
|
335
|
+
if (color.hasOwnProperty(i)) {
|
|
336
|
+
if (i === "a") {
|
|
337
|
+
newColor[i] = color[i];
|
|
338
|
+
} else {
|
|
339
|
+
newColor[i] = convertToPercentage(color[i]);
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
color = newColor;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
return tinycolor(color, opts);
|
|
347
|
+
};
|
|
348
|
+
|
|
349
|
+
// Given a string or object, convert that input to RGB
|
|
350
|
+
// Possible string inputs:
|
|
351
|
+
//
|
|
352
|
+
// "red"
|
|
353
|
+
// "#f00" or "f00"
|
|
354
|
+
// "#ff0000" or "ff0000"
|
|
355
|
+
// "#ff000000" or "ff000000"
|
|
356
|
+
// "rgb 255 0 0" or "rgb (255, 0, 0)"
|
|
357
|
+
// "rgb 1.0 0 0" or "rgb (1, 0, 0)"
|
|
358
|
+
// "rgba (255, 0, 0, 1)" or "rgba 255, 0, 0, 1"
|
|
359
|
+
// "rgba (1.0, 0, 0, 1)" or "rgba 1.0, 0, 0, 1"
|
|
360
|
+
// "hsl(0, 100%, 50%)" or "hsl 0 100% 50%"
|
|
361
|
+
// "hsla(0, 100%, 50%, 1)" or "hsla 0 100% 50%, 1"
|
|
362
|
+
// "hsv(0, 100%, 100%)" or "hsv 0 100% 100%"
|
|
363
|
+
//
|
|
364
|
+
function inputToRGB(color) {
|
|
365
|
+
var rgb = { r: 0, g: 0, b: 0 };
|
|
366
|
+
var a = 1;
|
|
367
|
+
var s = null;
|
|
368
|
+
var v = null;
|
|
369
|
+
var l = null;
|
|
370
|
+
var ok = false;
|
|
371
|
+
var format = false;
|
|
372
|
+
|
|
373
|
+
if (typeof color == "string") {
|
|
374
|
+
color = stringInputToObject(color);
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
if (typeof color == "object") {
|
|
378
|
+
if (
|
|
379
|
+
isValidCSSUnit(color.r) &&
|
|
380
|
+
isValidCSSUnit(color.g) &&
|
|
381
|
+
isValidCSSUnit(color.b)
|
|
382
|
+
) {
|
|
383
|
+
rgb = rgbToRgb(color.r, color.g, color.b);
|
|
384
|
+
ok = true;
|
|
385
|
+
format = String(color.r).substr(-1) === "%" ? "prgb" : "rgb";
|
|
386
|
+
} else if (
|
|
387
|
+
isValidCSSUnit(color.h) &&
|
|
388
|
+
isValidCSSUnit(color.s) &&
|
|
389
|
+
isValidCSSUnit(color.v)
|
|
390
|
+
) {
|
|
391
|
+
s = convertToPercentage(color.s);
|
|
392
|
+
v = convertToPercentage(color.v);
|
|
393
|
+
rgb = hsvToRgb(color.h, s, v);
|
|
394
|
+
ok = true;
|
|
395
|
+
format = "hsv";
|
|
396
|
+
} else if (
|
|
397
|
+
isValidCSSUnit(color.h) &&
|
|
398
|
+
isValidCSSUnit(color.s) &&
|
|
399
|
+
isValidCSSUnit(color.l)
|
|
400
|
+
) {
|
|
401
|
+
s = convertToPercentage(color.s);
|
|
402
|
+
l = convertToPercentage(color.l);
|
|
403
|
+
rgb = hslToRgb(color.h, s, l);
|
|
404
|
+
ok = true;
|
|
405
|
+
format = "hsl";
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
if (color.hasOwnProperty("a")) {
|
|
409
|
+
a = color.a;
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
a = boundAlpha(a);
|
|
414
|
+
|
|
415
|
+
return {
|
|
416
|
+
ok: ok,
|
|
417
|
+
format: color.format || format,
|
|
418
|
+
r: Math.min(255, Math.max(rgb.r, 0)),
|
|
419
|
+
g: Math.min(255, Math.max(rgb.g, 0)),
|
|
420
|
+
b: Math.min(255, Math.max(rgb.b, 0)),
|
|
421
|
+
a: a,
|
|
422
|
+
};
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
// Conversion Functions
|
|
426
|
+
// --------------------
|
|
427
|
+
|
|
428
|
+
// `rgbToHsl`, `rgbToHsv`, `hslToRgb`, `hsvToRgb` modified from:
|
|
429
|
+
// <http://mjijackson.com/2008/02/rgb-to-hsl-and-rgb-to-hsv-color-model-conversion-algorithms-in-javascript>
|
|
430
|
+
|
|
431
|
+
// `rgbToRgb`
|
|
432
|
+
// Handle bounds / percentage checking to conform to CSS color spec
|
|
433
|
+
// <http://www.w3.org/TR/css3-color/>
|
|
434
|
+
// *Assumes:* r, g, b in [0, 255] or [0, 1]
|
|
435
|
+
// *Returns:* { r, g, b } in [0, 255]
|
|
436
|
+
function rgbToRgb(r, g, b) {
|
|
437
|
+
return {
|
|
438
|
+
r: bound01(r, 255) * 255,
|
|
439
|
+
g: bound01(g, 255) * 255,
|
|
440
|
+
b: bound01(b, 255) * 255,
|
|
441
|
+
};
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
// `rgbToHsl`
|
|
445
|
+
// Converts an RGB color value to HSL.
|
|
446
|
+
// *Assumes:* r, g, and b are contained in [0, 255] or [0, 1]
|
|
447
|
+
// *Returns:* { h, s, l } in [0,1]
|
|
448
|
+
function rgbToHsl(r, g, b) {
|
|
449
|
+
r = bound01(r, 255);
|
|
450
|
+
g = bound01(g, 255);
|
|
451
|
+
b = bound01(b, 255);
|
|
452
|
+
|
|
453
|
+
var max = Math.max(r, g, b),
|
|
454
|
+
min = Math.min(r, g, b);
|
|
455
|
+
var h,
|
|
456
|
+
s,
|
|
457
|
+
l = (max + min) / 2;
|
|
458
|
+
|
|
459
|
+
if (max == min) {
|
|
460
|
+
h = s = 0; // achromatic
|
|
461
|
+
} else {
|
|
462
|
+
var d = max - min;
|
|
463
|
+
s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
|
|
464
|
+
switch (max) {
|
|
465
|
+
case r:
|
|
466
|
+
h = (g - b) / d + (g < b ? 6 : 0);
|
|
467
|
+
break;
|
|
468
|
+
case g:
|
|
469
|
+
h = (b - r) / d + 2;
|
|
470
|
+
break;
|
|
471
|
+
case b:
|
|
472
|
+
h = (r - g) / d + 4;
|
|
473
|
+
break;
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
h /= 6;
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
return { h: h, s: s, l: l };
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
// `hslToRgb`
|
|
483
|
+
// Converts an HSL color value to RGB.
|
|
484
|
+
// *Assumes:* h is contained in [0, 1] or [0, 360] and s and l are contained [0, 1] or [0, 100]
|
|
485
|
+
// *Returns:* { r, g, b } in the set [0, 255]
|
|
486
|
+
function hslToRgb(h, s, l) {
|
|
487
|
+
var r, g, b;
|
|
488
|
+
|
|
489
|
+
h = bound01(h, 360);
|
|
490
|
+
s = bound01(s, 100);
|
|
491
|
+
l = bound01(l, 100);
|
|
492
|
+
|
|
493
|
+
function hue2rgb(p, q, t) {
|
|
494
|
+
if (t < 0) t += 1;
|
|
495
|
+
if (t > 1) t -= 1;
|
|
496
|
+
if (t < 1 / 6) return p + (q - p) * 6 * t;
|
|
497
|
+
if (t < 1 / 2) return q;
|
|
498
|
+
if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6;
|
|
499
|
+
return p;
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
if (s === 0) {
|
|
503
|
+
r = g = b = l; // achromatic
|
|
504
|
+
} else {
|
|
505
|
+
var q = l < 0.5 ? l * (1 + s) : l + s - l * s;
|
|
506
|
+
var p = 2 * l - q;
|
|
507
|
+
r = hue2rgb(p, q, h + 1 / 3);
|
|
508
|
+
g = hue2rgb(p, q, h);
|
|
509
|
+
b = hue2rgb(p, q, h - 1 / 3);
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
return { r: r * 255, g: g * 255, b: b * 255 };
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
// `rgbToHsv`
|
|
516
|
+
// Converts an RGB color value to HSV
|
|
517
|
+
// *Assumes:* r, g, and b are contained in the set [0, 255] or [0, 1]
|
|
518
|
+
// *Returns:* { h, s, v } in [0,1]
|
|
519
|
+
function rgbToHsv(r, g, b) {
|
|
520
|
+
r = bound01(r, 255);
|
|
521
|
+
g = bound01(g, 255);
|
|
522
|
+
b = bound01(b, 255);
|
|
523
|
+
|
|
524
|
+
var max = Math.max(r, g, b),
|
|
525
|
+
min = Math.min(r, g, b);
|
|
526
|
+
var h,
|
|
527
|
+
s,
|
|
528
|
+
v = max;
|
|
529
|
+
|
|
530
|
+
var d = max - min;
|
|
531
|
+
s = max === 0 ? 0 : d / max;
|
|
532
|
+
|
|
533
|
+
if (max == min) {
|
|
534
|
+
h = 0; // achromatic
|
|
535
|
+
} else {
|
|
536
|
+
switch (max) {
|
|
537
|
+
case r:
|
|
538
|
+
h = (g - b) / d + (g < b ? 6 : 0);
|
|
539
|
+
break;
|
|
540
|
+
case g:
|
|
541
|
+
h = (b - r) / d + 2;
|
|
542
|
+
break;
|
|
543
|
+
case b:
|
|
544
|
+
h = (r - g) / d + 4;
|
|
545
|
+
break;
|
|
546
|
+
}
|
|
547
|
+
h /= 6;
|
|
548
|
+
}
|
|
549
|
+
return { h: h, s: s, v: v };
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
// `hsvToRgb`
|
|
553
|
+
// Converts an HSV color value to RGB.
|
|
554
|
+
// *Assumes:* h is contained in [0, 1] or [0, 360] and s and v are contained in [0, 1] or [0, 100]
|
|
555
|
+
// *Returns:* { r, g, b } in the set [0, 255]
|
|
556
|
+
function hsvToRgb(h, s, v) {
|
|
557
|
+
h = bound01(h, 360) * 6;
|
|
558
|
+
s = bound01(s, 100);
|
|
559
|
+
v = bound01(v, 100);
|
|
560
|
+
|
|
561
|
+
var i = Math.floor(h),
|
|
562
|
+
f = h - i,
|
|
563
|
+
p = v * (1 - s),
|
|
564
|
+
q = v * (1 - f * s),
|
|
565
|
+
t = v * (1 - (1 - f) * s),
|
|
566
|
+
mod = i % 6,
|
|
567
|
+
r = [v, q, p, p, t, v][mod],
|
|
568
|
+
g = [t, v, v, q, p, p][mod],
|
|
569
|
+
b = [p, p, t, v, v, q][mod];
|
|
570
|
+
|
|
571
|
+
return { r: r * 255, g: g * 255, b: b * 255 };
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
// `rgbToHex`
|
|
575
|
+
// Converts an RGB color to hex
|
|
576
|
+
// Assumes r, g, and b are contained in the set [0, 255]
|
|
577
|
+
// Returns a 3 or 6 character hex
|
|
578
|
+
function rgbToHex(r, g, b, allow3Char) {
|
|
579
|
+
var hex = [
|
|
580
|
+
pad2(Math.round(r).toString(16)),
|
|
581
|
+
pad2(Math.round(g).toString(16)),
|
|
582
|
+
pad2(Math.round(b).toString(16)),
|
|
583
|
+
];
|
|
584
|
+
|
|
585
|
+
// Return a 3 character hex if possible
|
|
586
|
+
if (
|
|
587
|
+
allow3Char &&
|
|
588
|
+
hex[0].charAt(0) == hex[0].charAt(1) &&
|
|
589
|
+
hex[1].charAt(0) == hex[1].charAt(1) &&
|
|
590
|
+
hex[2].charAt(0) == hex[2].charAt(1)
|
|
591
|
+
) {
|
|
592
|
+
return hex[0].charAt(0) + hex[1].charAt(0) + hex[2].charAt(0);
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
return hex.join("");
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
// `rgbaToHex`
|
|
599
|
+
// Converts an RGBA color plus alpha transparency to hex
|
|
600
|
+
// Assumes r, g, b are contained in the set [0, 255] and
|
|
601
|
+
// a in [0, 1]. Returns a 4 or 8 character rgba hex
|
|
602
|
+
function rgbaToHex(r, g, b, a, allow4Char) {
|
|
603
|
+
var hex = [
|
|
604
|
+
pad2(Math.round(r).toString(16)),
|
|
605
|
+
pad2(Math.round(g).toString(16)),
|
|
606
|
+
pad2(Math.round(b).toString(16)),
|
|
607
|
+
pad2(convertDecimalToHex(a)),
|
|
608
|
+
];
|
|
609
|
+
|
|
610
|
+
// Return a 4 character hex if possible
|
|
611
|
+
if (
|
|
612
|
+
allow4Char &&
|
|
613
|
+
hex[0].charAt(0) == hex[0].charAt(1) &&
|
|
614
|
+
hex[1].charAt(0) == hex[1].charAt(1) &&
|
|
615
|
+
hex[2].charAt(0) == hex[2].charAt(1) &&
|
|
616
|
+
hex[3].charAt(0) == hex[3].charAt(1)
|
|
617
|
+
) {
|
|
618
|
+
return (
|
|
619
|
+
hex[0].charAt(0) + hex[1].charAt(0) + hex[2].charAt(0) + hex[3].charAt(0)
|
|
620
|
+
);
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
return hex.join("");
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
// `rgbaToArgbHex`
|
|
627
|
+
// Converts an RGBA color to an ARGB Hex8 string
|
|
628
|
+
// Rarely used, but required for "toFilter()"
|
|
629
|
+
function rgbaToArgbHex(r, g, b, a) {
|
|
630
|
+
var hex = [
|
|
631
|
+
pad2(convertDecimalToHex(a)),
|
|
632
|
+
pad2(Math.round(r).toString(16)),
|
|
633
|
+
pad2(Math.round(g).toString(16)),
|
|
634
|
+
pad2(Math.round(b).toString(16)),
|
|
635
|
+
];
|
|
636
|
+
|
|
637
|
+
return hex.join("");
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
// `equals`
|
|
641
|
+
// Can be called with any tinycolor input
|
|
642
|
+
tinycolor.equals = function (color1, color2) {
|
|
643
|
+
if (!color1 || !color2) return false;
|
|
644
|
+
return tinycolor(color1).toRgbString() == tinycolor(color2).toRgbString();
|
|
645
|
+
};
|
|
646
|
+
|
|
647
|
+
tinycolor.random = function () {
|
|
648
|
+
return tinycolor.fromRatio({
|
|
649
|
+
r: Math.random(),
|
|
650
|
+
g: Math.random(),
|
|
651
|
+
b: Math.random(),
|
|
652
|
+
});
|
|
653
|
+
};
|
|
654
|
+
|
|
655
|
+
// Modification Functions
|
|
656
|
+
// ----------------------
|
|
657
|
+
// Thanks to less.js for some of the basics here
|
|
658
|
+
// <https://github.com/cloudhead/less.js/blob/master/lib/less/functions.js>
|
|
659
|
+
|
|
660
|
+
function desaturate(color, amount) {
|
|
661
|
+
amount = amount === 0 ? 0 : amount || 10;
|
|
662
|
+
var hsl = tinycolor(color).toHsl();
|
|
663
|
+
hsl.s -= amount / 100;
|
|
664
|
+
hsl.s = clamp01(hsl.s);
|
|
665
|
+
return tinycolor(hsl);
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
function saturate(color, amount) {
|
|
669
|
+
amount = amount === 0 ? 0 : amount || 10;
|
|
670
|
+
var hsl = tinycolor(color).toHsl();
|
|
671
|
+
hsl.s += amount / 100;
|
|
672
|
+
hsl.s = clamp01(hsl.s);
|
|
673
|
+
return tinycolor(hsl);
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
function greyscale(color) {
|
|
677
|
+
return tinycolor(color).desaturate(100);
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
function lighten(color, amount) {
|
|
681
|
+
amount = amount === 0 ? 0 : amount || 10;
|
|
682
|
+
var hsl = tinycolor(color).toHsl();
|
|
683
|
+
hsl.l += amount / 100;
|
|
684
|
+
hsl.l = clamp01(hsl.l);
|
|
685
|
+
return tinycolor(hsl);
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
function brighten(color, amount) {
|
|
689
|
+
amount = amount === 0 ? 0 : amount || 10;
|
|
690
|
+
var rgb = tinycolor(color).toRgb();
|
|
691
|
+
rgb.r = Math.max(0, Math.min(255, rgb.r - Math.round(255 * -(amount / 100))));
|
|
692
|
+
rgb.g = Math.max(0, Math.min(255, rgb.g - Math.round(255 * -(amount / 100))));
|
|
693
|
+
rgb.b = Math.max(0, Math.min(255, rgb.b - Math.round(255 * -(amount / 100))));
|
|
694
|
+
return tinycolor(rgb);
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
function darken(color, amount) {
|
|
698
|
+
amount = amount === 0 ? 0 : amount || 10;
|
|
699
|
+
var hsl = tinycolor(color).toHsl();
|
|
700
|
+
hsl.l -= amount / 100;
|
|
701
|
+
hsl.l = clamp01(hsl.l);
|
|
702
|
+
return tinycolor(hsl);
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
// Spin takes a positive or negative amount within [-360, 360] indicating the change of hue.
|
|
706
|
+
// Values outside of this range will be wrapped into this range.
|
|
707
|
+
function spin(color, amount) {
|
|
708
|
+
var hsl = tinycolor(color).toHsl();
|
|
709
|
+
var hue = (hsl.h + amount) % 360;
|
|
710
|
+
hsl.h = hue < 0 ? 360 + hue : hue;
|
|
711
|
+
return tinycolor(hsl);
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
// Combination Functions
|
|
715
|
+
// ---------------------
|
|
716
|
+
// Thanks to jQuery xColor for some of the ideas behind these
|
|
717
|
+
// <https://github.com/infusion/jQuery-xcolor/blob/master/jquery.xcolor.js>
|
|
718
|
+
|
|
719
|
+
function complement(color) {
|
|
720
|
+
var hsl = tinycolor(color).toHsl();
|
|
721
|
+
hsl.h = (hsl.h + 180) % 360;
|
|
722
|
+
return tinycolor(hsl);
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
function polyad(color, number) {
|
|
726
|
+
if (isNaN(number) || number <= 0) {
|
|
727
|
+
throw new Error("Argument to polyad must be a positive number");
|
|
728
|
+
}
|
|
729
|
+
var hsl = tinycolor(color).toHsl();
|
|
730
|
+
var result = [tinycolor(color)];
|
|
731
|
+
var step = 360 / number;
|
|
732
|
+
for (var i = 1; i < number; i++) {
|
|
733
|
+
result.push(tinycolor({ h: (hsl.h + i * step) % 360, s: hsl.s, l: hsl.l }));
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
return result;
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
function splitcomplement(color) {
|
|
740
|
+
var hsl = tinycolor(color).toHsl();
|
|
741
|
+
var h = hsl.h;
|
|
742
|
+
return [
|
|
743
|
+
tinycolor(color),
|
|
744
|
+
tinycolor({ h: (h + 72) % 360, s: hsl.s, l: hsl.l }),
|
|
745
|
+
tinycolor({ h: (h + 216) % 360, s: hsl.s, l: hsl.l }),
|
|
746
|
+
];
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
function analogous(color, results, slices) {
|
|
750
|
+
results = results || 6;
|
|
751
|
+
slices = slices || 30;
|
|
752
|
+
|
|
753
|
+
var hsl = tinycolor(color).toHsl();
|
|
754
|
+
var part = 360 / slices;
|
|
755
|
+
var ret = [tinycolor(color)];
|
|
756
|
+
|
|
757
|
+
for (hsl.h = (hsl.h - ((part * results) >> 1) + 720) % 360; --results; ) {
|
|
758
|
+
hsl.h = (hsl.h + part) % 360;
|
|
759
|
+
ret.push(tinycolor(hsl));
|
|
760
|
+
}
|
|
761
|
+
return ret;
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
function monochromatic(color, results) {
|
|
765
|
+
results = results || 6;
|
|
766
|
+
var hsv = tinycolor(color).toHsv();
|
|
767
|
+
var h = hsv.h,
|
|
768
|
+
s = hsv.s,
|
|
769
|
+
v = hsv.v;
|
|
770
|
+
var ret = [];
|
|
771
|
+
var modification = 1 / results;
|
|
772
|
+
|
|
773
|
+
while (results--) {
|
|
774
|
+
ret.push(tinycolor({ h: h, s: s, v: v }));
|
|
775
|
+
v = (v + modification) % 1;
|
|
776
|
+
}
|
|
777
|
+
|
|
778
|
+
return ret;
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
// Utility Functions
|
|
782
|
+
// ---------------------
|
|
783
|
+
|
|
784
|
+
tinycolor.mix = function (color1, color2, amount) {
|
|
785
|
+
amount = amount === 0 ? 0 : amount || 50;
|
|
786
|
+
|
|
787
|
+
var rgb1 = tinycolor(color1).toRgb();
|
|
788
|
+
var rgb2 = tinycolor(color2).toRgb();
|
|
789
|
+
|
|
790
|
+
var p = amount / 100;
|
|
791
|
+
|
|
792
|
+
var rgba = {
|
|
793
|
+
r: (rgb2.r - rgb1.r) * p + rgb1.r,
|
|
794
|
+
g: (rgb2.g - rgb1.g) * p + rgb1.g,
|
|
795
|
+
b: (rgb2.b - rgb1.b) * p + rgb1.b,
|
|
796
|
+
a: (rgb2.a - rgb1.a) * p + rgb1.a,
|
|
797
|
+
};
|
|
798
|
+
|
|
799
|
+
return tinycolor(rgba);
|
|
800
|
+
};
|
|
801
|
+
|
|
802
|
+
// Readability Functions
|
|
803
|
+
// ---------------------
|
|
804
|
+
// <http://www.w3.org/TR/2008/REC-WCAG20-20081211/#contrast-ratiodef (WCAG Version 2)
|
|
805
|
+
|
|
806
|
+
// `contrast`
|
|
807
|
+
// Analyze the 2 colors and returns the color contrast defined by (WCAG Version 2)
|
|
808
|
+
tinycolor.readability = function (color1, color2) {
|
|
809
|
+
var c1 = tinycolor(color1);
|
|
810
|
+
var c2 = tinycolor(color2);
|
|
811
|
+
return (
|
|
812
|
+
(Math.max(c1.getLuminance(), c2.getLuminance()) + 0.05) /
|
|
813
|
+
(Math.min(c1.getLuminance(), c2.getLuminance()) + 0.05)
|
|
814
|
+
);
|
|
815
|
+
};
|
|
816
|
+
|
|
817
|
+
// `isReadable`
|
|
818
|
+
// Ensure that foreground and background color combinations meet WCAG2 guidelines.
|
|
819
|
+
// The third argument is an optional Object.
|
|
820
|
+
// the 'level' property states 'AA' or 'AAA' - if missing or invalid, it defaults to 'AA';
|
|
821
|
+
// the 'size' property states 'large' or 'small' - if missing or invalid, it defaults to 'small'.
|
|
822
|
+
// If the entire object is absent, isReadable defaults to {level:"AA",size:"small"}.
|
|
823
|
+
|
|
824
|
+
// *Example*
|
|
825
|
+
// tinycolor.isReadable("#000", "#111") => false
|
|
826
|
+
// tinycolor.isReadable("#000", "#111",{level:"AA",size:"large"}) => false
|
|
827
|
+
tinycolor.isReadable = function (color1, color2, wcag2) {
|
|
828
|
+
var readability = tinycolor.readability(color1, color2);
|
|
829
|
+
var wcag2Parms, out;
|
|
830
|
+
|
|
831
|
+
out = false;
|
|
832
|
+
|
|
833
|
+
wcag2Parms = validateWCAG2Parms(wcag2);
|
|
834
|
+
switch (wcag2Parms.level + wcag2Parms.size) {
|
|
835
|
+
case "AAsmall":
|
|
836
|
+
case "AAAlarge":
|
|
837
|
+
out = readability >= 4.5;
|
|
838
|
+
break;
|
|
839
|
+
case "AAlarge":
|
|
840
|
+
out = readability >= 3;
|
|
841
|
+
break;
|
|
842
|
+
case "AAAsmall":
|
|
843
|
+
out = readability >= 7;
|
|
844
|
+
break;
|
|
845
|
+
}
|
|
846
|
+
return out;
|
|
847
|
+
};
|
|
848
|
+
|
|
849
|
+
// `mostReadable`
|
|
850
|
+
// Given a base color and a list of possible foreground or background
|
|
851
|
+
// colors for that base, returns the most readable color.
|
|
852
|
+
// Optionally returns Black or White if the most readable color is unreadable.
|
|
853
|
+
// *Example*
|
|
854
|
+
// tinycolor.mostReadable(tinycolor.mostReadable("#123", ["#124", "#125"],{includeFallbackColors:false}).toHexString(); // "#112255"
|
|
855
|
+
// tinycolor.mostReadable(tinycolor.mostReadable("#123", ["#124", "#125"],{includeFallbackColors:true}).toHexString(); // "#ffffff"
|
|
856
|
+
// tinycolor.mostReadable("#a8015a", ["#faf3f3"],{includeFallbackColors:true,level:"AAA",size:"large"}).toHexString(); // "#faf3f3"
|
|
857
|
+
// tinycolor.mostReadable("#a8015a", ["#faf3f3"],{includeFallbackColors:true,level:"AAA",size:"small"}).toHexString(); // "#ffffff"
|
|
858
|
+
tinycolor.mostReadable = function (baseColor, colorList, args) {
|
|
859
|
+
var bestColor = null;
|
|
860
|
+
var bestScore = 0;
|
|
861
|
+
var readability;
|
|
862
|
+
var includeFallbackColors, level, size;
|
|
863
|
+
args = args || {};
|
|
864
|
+
includeFallbackColors = args.includeFallbackColors;
|
|
865
|
+
level = args.level;
|
|
866
|
+
size = args.size;
|
|
867
|
+
|
|
868
|
+
for (var i = 0; i < colorList.length; i++) {
|
|
869
|
+
readability = tinycolor.readability(baseColor, colorList[i]);
|
|
870
|
+
if (readability > bestScore) {
|
|
871
|
+
bestScore = readability;
|
|
872
|
+
bestColor = tinycolor(colorList[i]);
|
|
873
|
+
}
|
|
874
|
+
}
|
|
875
|
+
|
|
876
|
+
if (
|
|
877
|
+
tinycolor.isReadable(baseColor, bestColor, {
|
|
878
|
+
level: level,
|
|
879
|
+
size: size,
|
|
880
|
+
}) ||
|
|
881
|
+
!includeFallbackColors
|
|
882
|
+
) {
|
|
883
|
+
return bestColor;
|
|
884
|
+
} else {
|
|
885
|
+
args.includeFallbackColors = false;
|
|
886
|
+
return tinycolor.mostReadable(baseColor, ["#fff", "#000"], args);
|
|
887
|
+
}
|
|
888
|
+
};
|
|
889
|
+
|
|
890
|
+
// Big List of Colors
|
|
891
|
+
// ------------------
|
|
892
|
+
// <https://www.w3.org/TR/css-color-4/#named-colors>
|
|
893
|
+
var names = (tinycolor.names = {
|
|
894
|
+
aliceblue: "f0f8ff",
|
|
895
|
+
antiquewhite: "faebd7",
|
|
896
|
+
aqua: "0ff",
|
|
897
|
+
aquamarine: "7fffd4",
|
|
898
|
+
azure: "f0ffff",
|
|
899
|
+
beige: "f5f5dc",
|
|
900
|
+
bisque: "ffe4c4",
|
|
901
|
+
black: "000",
|
|
902
|
+
blanchedalmond: "ffebcd",
|
|
903
|
+
blue: "00f",
|
|
904
|
+
blueviolet: "8a2be2",
|
|
905
|
+
brown: "a52a2a",
|
|
906
|
+
burlywood: "deb887",
|
|
907
|
+
burntsienna: "ea7e5d",
|
|
908
|
+
cadetblue: "5f9ea0",
|
|
909
|
+
chartreuse: "7fff00",
|
|
910
|
+
chocolate: "d2691e",
|
|
911
|
+
coral: "ff7f50",
|
|
912
|
+
cornflowerblue: "6495ed",
|
|
913
|
+
cornsilk: "fff8dc",
|
|
914
|
+
crimson: "dc143c",
|
|
915
|
+
cyan: "0ff",
|
|
916
|
+
darkblue: "00008b",
|
|
917
|
+
darkcyan: "008b8b",
|
|
918
|
+
darkgoldenrod: "b8860b",
|
|
919
|
+
darkgray: "a9a9a9",
|
|
920
|
+
darkgreen: "006400",
|
|
921
|
+
darkgrey: "a9a9a9",
|
|
922
|
+
darkkhaki: "bdb76b",
|
|
923
|
+
darkmagenta: "8b008b",
|
|
924
|
+
darkolivegreen: "556b2f",
|
|
925
|
+
darkorange: "ff8c00",
|
|
926
|
+
darkorchid: "9932cc",
|
|
927
|
+
darkred: "8b0000",
|
|
928
|
+
darksalmon: "e9967a",
|
|
929
|
+
darkseagreen: "8fbc8f",
|
|
930
|
+
darkslateblue: "483d8b",
|
|
931
|
+
darkslategray: "2f4f4f",
|
|
932
|
+
darkslategrey: "2f4f4f",
|
|
933
|
+
darkturquoise: "00ced1",
|
|
934
|
+
darkviolet: "9400d3",
|
|
935
|
+
deeppink: "ff1493",
|
|
936
|
+
deepskyblue: "00bfff",
|
|
937
|
+
dimgray: "696969",
|
|
938
|
+
dimgrey: "696969",
|
|
939
|
+
dodgerblue: "1e90ff",
|
|
940
|
+
firebrick: "b22222",
|
|
941
|
+
floralwhite: "fffaf0",
|
|
942
|
+
forestgreen: "228b22",
|
|
943
|
+
fuchsia: "f0f",
|
|
944
|
+
gainsboro: "dcdcdc",
|
|
945
|
+
ghostwhite: "f8f8ff",
|
|
946
|
+
gold: "ffd700",
|
|
947
|
+
goldenrod: "daa520",
|
|
948
|
+
gray: "808080",
|
|
949
|
+
green: "008000",
|
|
950
|
+
greenyellow: "adff2f",
|
|
951
|
+
grey: "808080",
|
|
952
|
+
honeydew: "f0fff0",
|
|
953
|
+
hotpink: "ff69b4",
|
|
954
|
+
indianred: "cd5c5c",
|
|
955
|
+
indigo: "4b0082",
|
|
956
|
+
ivory: "fffff0",
|
|
957
|
+
khaki: "f0e68c",
|
|
958
|
+
lavender: "e6e6fa",
|
|
959
|
+
lavenderblush: "fff0f5",
|
|
960
|
+
lawngreen: "7cfc00",
|
|
961
|
+
lemonchiffon: "fffacd",
|
|
962
|
+
lightblue: "add8e6",
|
|
963
|
+
lightcoral: "f08080",
|
|
964
|
+
lightcyan: "e0ffff",
|
|
965
|
+
lightgoldenrodyellow: "fafad2",
|
|
966
|
+
lightgray: "d3d3d3",
|
|
967
|
+
lightgreen: "90ee90",
|
|
968
|
+
lightgrey: "d3d3d3",
|
|
969
|
+
lightpink: "ffb6c1",
|
|
970
|
+
lightsalmon: "ffa07a",
|
|
971
|
+
lightseagreen: "20b2aa",
|
|
972
|
+
lightskyblue: "87cefa",
|
|
973
|
+
lightslategray: "789",
|
|
974
|
+
lightslategrey: "789",
|
|
975
|
+
lightsteelblue: "b0c4de",
|
|
976
|
+
lightyellow: "ffffe0",
|
|
977
|
+
lime: "0f0",
|
|
978
|
+
limegreen: "32cd32",
|
|
979
|
+
linen: "faf0e6",
|
|
980
|
+
magenta: "f0f",
|
|
981
|
+
maroon: "800000",
|
|
982
|
+
mediumaquamarine: "66cdaa",
|
|
983
|
+
mediumblue: "0000cd",
|
|
984
|
+
mediumorchid: "ba55d3",
|
|
985
|
+
mediumpurple: "9370db",
|
|
986
|
+
mediumseagreen: "3cb371",
|
|
987
|
+
mediumslateblue: "7b68ee",
|
|
988
|
+
mediumspringgreen: "00fa9a",
|
|
989
|
+
mediumturquoise: "48d1cc",
|
|
990
|
+
mediumvioletred: "c71585",
|
|
991
|
+
midnightblue: "191970",
|
|
992
|
+
mintcream: "f5fffa",
|
|
993
|
+
mistyrose: "ffe4e1",
|
|
994
|
+
moccasin: "ffe4b5",
|
|
995
|
+
navajowhite: "ffdead",
|
|
996
|
+
navy: "000080",
|
|
997
|
+
oldlace: "fdf5e6",
|
|
998
|
+
olive: "808000",
|
|
999
|
+
olivedrab: "6b8e23",
|
|
1000
|
+
orange: "ffa500",
|
|
1001
|
+
orangered: "ff4500",
|
|
1002
|
+
orchid: "da70d6",
|
|
1003
|
+
palegoldenrod: "eee8aa",
|
|
1004
|
+
palegreen: "98fb98",
|
|
1005
|
+
paleturquoise: "afeeee",
|
|
1006
|
+
palevioletred: "db7093",
|
|
1007
|
+
papayawhip: "ffefd5",
|
|
1008
|
+
peachpuff: "ffdab9",
|
|
1009
|
+
peru: "cd853f",
|
|
1010
|
+
pink: "ffc0cb",
|
|
1011
|
+
plum: "dda0dd",
|
|
1012
|
+
powderblue: "b0e0e6",
|
|
1013
|
+
purple: "800080",
|
|
1014
|
+
rebeccapurple: "663399",
|
|
1015
|
+
red: "f00",
|
|
1016
|
+
rosybrown: "bc8f8f",
|
|
1017
|
+
royalblue: "4169e1",
|
|
1018
|
+
saddlebrown: "8b4513",
|
|
1019
|
+
salmon: "fa8072",
|
|
1020
|
+
sandybrown: "f4a460",
|
|
1021
|
+
seagreen: "2e8b57",
|
|
1022
|
+
seashell: "fff5ee",
|
|
1023
|
+
sienna: "a0522d",
|
|
1024
|
+
silver: "c0c0c0",
|
|
1025
|
+
skyblue: "87ceeb",
|
|
1026
|
+
slateblue: "6a5acd",
|
|
1027
|
+
slategray: "708090",
|
|
1028
|
+
slategrey: "708090",
|
|
1029
|
+
snow: "fffafa",
|
|
1030
|
+
springgreen: "00ff7f",
|
|
1031
|
+
steelblue: "4682b4",
|
|
1032
|
+
tan: "d2b48c",
|
|
1033
|
+
teal: "008080",
|
|
1034
|
+
thistle: "d8bfd8",
|
|
1035
|
+
tomato: "ff6347",
|
|
1036
|
+
turquoise: "40e0d0",
|
|
1037
|
+
violet: "ee82ee",
|
|
1038
|
+
wheat: "f5deb3",
|
|
1039
|
+
white: "fff",
|
|
1040
|
+
whitesmoke: "f5f5f5",
|
|
1041
|
+
yellow: "ff0",
|
|
1042
|
+
yellowgreen: "9acd32",
|
|
1043
|
+
});
|
|
1044
|
+
|
|
1045
|
+
// Make it easy to access colors via `hexNames[hex]`
|
|
1046
|
+
var hexNames = (tinycolor.hexNames = flip(names));
|
|
1047
|
+
|
|
1048
|
+
// Utilities
|
|
1049
|
+
// ---------
|
|
1050
|
+
|
|
1051
|
+
// `{ 'name1': 'val1' }` becomes `{ 'val1': 'name1' }`
|
|
1052
|
+
function flip(o) {
|
|
1053
|
+
var flipped = {};
|
|
1054
|
+
for (var i in o) {
|
|
1055
|
+
if (o.hasOwnProperty(i)) {
|
|
1056
|
+
flipped[o[i]] = i;
|
|
1057
|
+
}
|
|
1058
|
+
}
|
|
1059
|
+
return flipped;
|
|
1060
|
+
}
|
|
1061
|
+
|
|
1062
|
+
// Return a valid alpha value [0,1] with all invalid values being set to 1
|
|
1063
|
+
function boundAlpha(a) {
|
|
1064
|
+
a = parseFloat(a);
|
|
1065
|
+
|
|
1066
|
+
if (isNaN(a) || a < 0 || a > 1) {
|
|
1067
|
+
a = 1;
|
|
1068
|
+
}
|
|
1069
|
+
|
|
1070
|
+
return a;
|
|
1071
|
+
}
|
|
1072
|
+
|
|
1073
|
+
// Take input from [0, n] and return it as [0, 1]
|
|
1074
|
+
function bound01(n, max) {
|
|
1075
|
+
if (isOnePointZero(n)) n = "100%";
|
|
1076
|
+
|
|
1077
|
+
var processPercent = isPercentage(n);
|
|
1078
|
+
n = Math.min(max, Math.max(0, parseFloat(n)));
|
|
1079
|
+
|
|
1080
|
+
// Automatically convert percentage into number
|
|
1081
|
+
if (processPercent) {
|
|
1082
|
+
n = parseInt(n * max, 10) / 100;
|
|
1083
|
+
}
|
|
1084
|
+
|
|
1085
|
+
// Handle floating point rounding errors
|
|
1086
|
+
if (Math.abs(n - max) < 0.000001) {
|
|
1087
|
+
return 1;
|
|
1088
|
+
}
|
|
1089
|
+
|
|
1090
|
+
// Convert into [0, 1] range if it isn't already
|
|
1091
|
+
return (n % max) / parseFloat(max);
|
|
1092
|
+
}
|
|
1093
|
+
|
|
1094
|
+
// Force a number between 0 and 1
|
|
1095
|
+
function clamp01(val) {
|
|
1096
|
+
return Math.min(1, Math.max(0, val));
|
|
1097
|
+
}
|
|
1098
|
+
|
|
1099
|
+
// Parse a base-16 hex value into a base-10 integer
|
|
1100
|
+
function parseIntFromHex(val) {
|
|
1101
|
+
return parseInt(val, 16);
|
|
1102
|
+
}
|
|
1103
|
+
|
|
1104
|
+
// Need to handle 1.0 as 100%, since once it is a number, there is no difference between it and 1
|
|
1105
|
+
// <http://stackoverflow.com/questions/7422072/javascript-how-to-detect-number-as-a-decimal-including-1-0>
|
|
1106
|
+
function isOnePointZero(n) {
|
|
1107
|
+
return typeof n == "string" && n.indexOf(".") != -1 && parseFloat(n) === 1;
|
|
1108
|
+
}
|
|
1109
|
+
|
|
1110
|
+
// Check to see if string passed in is a percentage
|
|
1111
|
+
function isPercentage(n) {
|
|
1112
|
+
return typeof n === "string" && n.indexOf("%") != -1;
|
|
1113
|
+
}
|
|
1114
|
+
|
|
1115
|
+
// Force a hex value to have 2 characters
|
|
1116
|
+
function pad2(c) {
|
|
1117
|
+
return c.length == 1 ? "0" + c : "" + c;
|
|
1118
|
+
}
|
|
1119
|
+
|
|
1120
|
+
// Replace a decimal with it's percentage value
|
|
1121
|
+
function convertToPercentage(n) {
|
|
1122
|
+
if (n <= 1) {
|
|
1123
|
+
n = n * 100 + "%";
|
|
1124
|
+
}
|
|
1125
|
+
|
|
1126
|
+
return n;
|
|
1127
|
+
}
|
|
1128
|
+
|
|
1129
|
+
// Converts a decimal to a hex value
|
|
1130
|
+
function convertDecimalToHex(d) {
|
|
1131
|
+
return Math.round(parseFloat(d) * 255).toString(16);
|
|
1132
|
+
}
|
|
1133
|
+
// Converts a hex value to a decimal
|
|
1134
|
+
function convertHexToDecimal(h) {
|
|
1135
|
+
return parseIntFromHex(h) / 255;
|
|
1136
|
+
}
|
|
1137
|
+
|
|
1138
|
+
var matchers = (function () {
|
|
1139
|
+
// <http://www.w3.org/TR/css3-values/#integers>
|
|
1140
|
+
var CSS_INTEGER = "[-\\+]?\\d+%?";
|
|
1141
|
+
|
|
1142
|
+
// <http://www.w3.org/TR/css3-values/#number-value>
|
|
1143
|
+
var CSS_NUMBER = "[-\\+]?\\d*\\.\\d+%?";
|
|
1144
|
+
|
|
1145
|
+
// Allow positive/negative integer/number. Don't capture the either/or, just the entire outcome.
|
|
1146
|
+
var CSS_UNIT = "(?:" + CSS_NUMBER + ")|(?:" + CSS_INTEGER + ")";
|
|
1147
|
+
|
|
1148
|
+
// Actual matching.
|
|
1149
|
+
// Parentheses and commas are optional, but not required.
|
|
1150
|
+
// Whitespace can take the place of commas or opening paren
|
|
1151
|
+
var PERMISSIVE_MATCH3 =
|
|
1152
|
+
"[\\s|\\(]+(" +
|
|
1153
|
+
CSS_UNIT +
|
|
1154
|
+
")[,|\\s]+(" +
|
|
1155
|
+
CSS_UNIT +
|
|
1156
|
+
")[,|\\s]+(" +
|
|
1157
|
+
CSS_UNIT +
|
|
1158
|
+
")\\s*\\)?";
|
|
1159
|
+
var PERMISSIVE_MATCH4 =
|
|
1160
|
+
"[\\s|\\(]+(" +
|
|
1161
|
+
CSS_UNIT +
|
|
1162
|
+
")[,|\\s]+(" +
|
|
1163
|
+
CSS_UNIT +
|
|
1164
|
+
")[,|\\s]+(" +
|
|
1165
|
+
CSS_UNIT +
|
|
1166
|
+
")[,|\\s]+(" +
|
|
1167
|
+
CSS_UNIT +
|
|
1168
|
+
")\\s*\\)?";
|
|
1169
|
+
|
|
1170
|
+
return {
|
|
1171
|
+
CSS_UNIT: new RegExp(CSS_UNIT),
|
|
1172
|
+
rgb: new RegExp("rgb" + PERMISSIVE_MATCH3),
|
|
1173
|
+
rgba: new RegExp("rgba" + PERMISSIVE_MATCH4),
|
|
1174
|
+
hsl: new RegExp("hsl" + PERMISSIVE_MATCH3),
|
|
1175
|
+
hsla: new RegExp("hsla" + PERMISSIVE_MATCH4),
|
|
1176
|
+
hsv: new RegExp("hsv" + PERMISSIVE_MATCH3),
|
|
1177
|
+
hsva: new RegExp("hsva" + PERMISSIVE_MATCH4),
|
|
1178
|
+
hex3: /^#?([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,
|
|
1179
|
+
hex6: /^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/,
|
|
1180
|
+
hex4: /^#?([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,
|
|
1181
|
+
hex8: /^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/,
|
|
1182
|
+
};
|
|
1183
|
+
})();
|
|
1184
|
+
|
|
1185
|
+
// `isValidCSSUnit`
|
|
1186
|
+
// Take in a single string / number and check to see if it looks like a CSS unit
|
|
1187
|
+
// (see `matchers` above for definition).
|
|
1188
|
+
function isValidCSSUnit(color) {
|
|
1189
|
+
return !!matchers.CSS_UNIT.exec(color);
|
|
1190
|
+
}
|
|
1191
|
+
|
|
1192
|
+
// `stringInputToObject`
|
|
1193
|
+
// Permissive string parsing. Take in a number of formats, and output an object
|
|
1194
|
+
// based on detected format. Returns `{ r, g, b }` or `{ h, s, l }` or `{ h, s, v}`
|
|
1195
|
+
function stringInputToObject(color) {
|
|
1196
|
+
color = color.replace(trimLeft, "").replace(trimRight, "").toLowerCase();
|
|
1197
|
+
var named = false;
|
|
1198
|
+
if (names[color]) {
|
|
1199
|
+
color = names[color];
|
|
1200
|
+
named = true;
|
|
1201
|
+
} else if (color == "transparent") {
|
|
1202
|
+
return { r: 0, g: 0, b: 0, a: 0, format: "name" };
|
|
1203
|
+
}
|
|
1204
|
+
|
|
1205
|
+
// Try to match string input using regular expressions.
|
|
1206
|
+
// Keep most of the number bounding out of this function - don't worry about [0,1] or [0,100] or [0,360]
|
|
1207
|
+
// Just return an object and let the conversion functions handle that.
|
|
1208
|
+
// This way the result will be the same whether the tinycolor is initialized with string or object.
|
|
1209
|
+
var match;
|
|
1210
|
+
if ((match = matchers.rgb.exec(color))) {
|
|
1211
|
+
return { r: match[1], g: match[2], b: match[3] };
|
|
1212
|
+
}
|
|
1213
|
+
if ((match = matchers.rgba.exec(color))) {
|
|
1214
|
+
return { r: match[1], g: match[2], b: match[3], a: match[4] };
|
|
1215
|
+
}
|
|
1216
|
+
if ((match = matchers.hsl.exec(color))) {
|
|
1217
|
+
return { h: match[1], s: match[2], l: match[3] };
|
|
1218
|
+
}
|
|
1219
|
+
if ((match = matchers.hsla.exec(color))) {
|
|
1220
|
+
return { h: match[1], s: match[2], l: match[3], a: match[4] };
|
|
1221
|
+
}
|
|
1222
|
+
if ((match = matchers.hsv.exec(color))) {
|
|
1223
|
+
return { h: match[1], s: match[2], v: match[3] };
|
|
1224
|
+
}
|
|
1225
|
+
if ((match = matchers.hsva.exec(color))) {
|
|
1226
|
+
return { h: match[1], s: match[2], v: match[3], a: match[4] };
|
|
1227
|
+
}
|
|
1228
|
+
if ((match = matchers.hex8.exec(color))) {
|
|
1229
|
+
return {
|
|
1230
|
+
r: parseIntFromHex(match[1]),
|
|
1231
|
+
g: parseIntFromHex(match[2]),
|
|
1232
|
+
b: parseIntFromHex(match[3]),
|
|
1233
|
+
a: convertHexToDecimal(match[4]),
|
|
1234
|
+
format: named ? "name" : "hex8",
|
|
1235
|
+
};
|
|
1236
|
+
}
|
|
1237
|
+
if ((match = matchers.hex6.exec(color))) {
|
|
1238
|
+
return {
|
|
1239
|
+
r: parseIntFromHex(match[1]),
|
|
1240
|
+
g: parseIntFromHex(match[2]),
|
|
1241
|
+
b: parseIntFromHex(match[3]),
|
|
1242
|
+
format: named ? "name" : "hex",
|
|
1243
|
+
};
|
|
1244
|
+
}
|
|
1245
|
+
if ((match = matchers.hex4.exec(color))) {
|
|
1246
|
+
return {
|
|
1247
|
+
r: parseIntFromHex(match[1] + "" + match[1]),
|
|
1248
|
+
g: parseIntFromHex(match[2] + "" + match[2]),
|
|
1249
|
+
b: parseIntFromHex(match[3] + "" + match[3]),
|
|
1250
|
+
a: convertHexToDecimal(match[4] + "" + match[4]),
|
|
1251
|
+
format: named ? "name" : "hex8",
|
|
1252
|
+
};
|
|
1253
|
+
}
|
|
1254
|
+
if ((match = matchers.hex3.exec(color))) {
|
|
1255
|
+
return {
|
|
1256
|
+
r: parseIntFromHex(match[1] + "" + match[1]),
|
|
1257
|
+
g: parseIntFromHex(match[2] + "" + match[2]),
|
|
1258
|
+
b: parseIntFromHex(match[3] + "" + match[3]),
|
|
1259
|
+
format: named ? "name" : "hex",
|
|
1260
|
+
};
|
|
1261
|
+
}
|
|
1262
|
+
|
|
1263
|
+
return false;
|
|
1264
|
+
}
|
|
1265
|
+
|
|
1266
|
+
function validateWCAG2Parms(parms) {
|
|
1267
|
+
// return valid WCAG2 parms for isReadable.
|
|
1268
|
+
// If input parms are invalid, return {"level":"AA", "size":"small"}
|
|
1269
|
+
var level, size;
|
|
1270
|
+
parms = parms || { level: "AA", size: "small" };
|
|
1271
|
+
level = (parms.level || "AA").toUpperCase();
|
|
1272
|
+
size = (parms.size || "small").toLowerCase();
|
|
1273
|
+
if (level !== "AA" && level !== "AAA") {
|
|
1274
|
+
level = "AA";
|
|
1275
|
+
}
|
|
1276
|
+
if (size !== "small" && size !== "large") {
|
|
1277
|
+
size = "small";
|
|
1278
|
+
}
|
|
1279
|
+
return { level: level, size: size };
|
|
1280
|
+
}
|
|
1281
|
+
|
|
1282
|
+
const hslColorMap = (h, s, l) => {
|
|
1283
|
+
const colors = {};
|
|
1284
|
+
for (let i = 0; i < l.length; i++) {
|
|
1285
|
+
const lightness = l[i];
|
|
1286
|
+
colors[lightness] = tinycolor({ h, s, l: lightness }).toHexString();
|
|
1287
|
+
}
|
|
1288
|
+
return colors;
|
|
1289
|
+
};
|
|
1290
|
+
|
|
1291
|
+
const colorPalette = {
|
|
1292
|
+
neutral: hslColorMap(
|
|
1293
|
+
206,
|
|
1294
|
+
30,
|
|
1295
|
+
[
|
|
1296
|
+
10,
|
|
1297
|
+
15,
|
|
1298
|
+
20,
|
|
1299
|
+
25,
|
|
1300
|
+
30,
|
|
1301
|
+
35,
|
|
1302
|
+
40,
|
|
1303
|
+
45,
|
|
1304
|
+
50,
|
|
1305
|
+
55,
|
|
1306
|
+
60,
|
|
1307
|
+
65,
|
|
1308
|
+
70,
|
|
1309
|
+
75,
|
|
1310
|
+
80,
|
|
1311
|
+
85,
|
|
1312
|
+
90,
|
|
1313
|
+
95,
|
|
1314
|
+
97,
|
|
1315
|
+
98,
|
|
1316
|
+
100
|
|
1317
|
+
]
|
|
1318
|
+
),
|
|
1319
|
+
honey: hslColorMap(42, 93, [72, 75, 82, 85, 92]),
|
|
1320
|
+
coral: hslColorMap(14, 87, [65, 74, 75, 84, 85, 94]),
|
|
1321
|
+
warm: hslColorMap(25, 100, [77, 87, 97]),
|
|
1322
|
+
"sea-salt": hslColorMap(180, 17, [57, 67, 88]),
|
|
1323
|
+
cloud: hslColorMap(200, 38, [43, 75, 88]),
|
|
1324
|
+
ocean: hslColorMap(209, 38, [38, 75, 88]),
|
|
1325
|
+
sky: hslColorMap(209, 64, [64, 75, 85]),
|
|
1326
|
+
lukso: hslColorMap(335, 33, [70, 80, 90]),
|
|
1327
|
+
yellow: hslColorMap(36, 100, [55, 65, 75, 85]),
|
|
1328
|
+
green: hslColorMap(135, 57, [45, 54, 75, 85]),
|
|
1329
|
+
blue: hslColorMap(216, 96, [50, 60, 75, 85]),
|
|
1330
|
+
red: hslColorMap(0, 75, [55, 65, 75, 85]),
|
|
1331
|
+
purple: hslColorMap(230, 24, [94, 82, 63, 58, 51, 41, 31, 15]),
|
|
1332
|
+
pink: hslColorMap(11, 73, [97, 96, 95, 94, 93, 92, 91, 90]),
|
|
1333
|
+
"gradient-1": {
|
|
1334
|
+
start: "#D39B9D",
|
|
1335
|
+
end: "#9071D1"
|
|
1336
|
+
},
|
|
1337
|
+
"gradient-2": {
|
|
1338
|
+
start: "#F8DAD3",
|
|
1339
|
+
end: "#CC99AE"
|
|
1340
|
+
},
|
|
1341
|
+
"gradient-3": {
|
|
1342
|
+
start: tinycolor({ h: 230, s: 20, l: 28 }).toHexString(),
|
|
1343
|
+
end: tinycolor({ h: 230, s: 24, l: 51 }).toHexString()
|
|
1344
|
+
}
|
|
1345
|
+
};
|
|
1346
|
+
const splitColor = (colors, from, to) => {
|
|
1347
|
+
return Object.keys(colors).slice(from, to).reduce((result, key) => {
|
|
1348
|
+
result[key] = colors[key];
|
|
1349
|
+
return result;
|
|
1350
|
+
}, {});
|
|
1351
|
+
};
|
|
1352
|
+
const neutral1 = splitColor(colorPalette.neutral, 0, 8);
|
|
1353
|
+
const neutral2 = splitColor(colorPalette.neutral, 8, 16);
|
|
1354
|
+
const neutral3 = splitColor(
|
|
1355
|
+
colorPalette.neutral,
|
|
1356
|
+
16,
|
|
1357
|
+
Object.keys(colorPalette.neutral).length
|
|
1358
|
+
);
|
|
1359
|
+
|
|
1360
|
+
exports.colorPalette = colorPalette;
|
|
1361
|
+
exports.neutral1 = neutral1;
|
|
1362
|
+
exports.neutral2 = neutral2;
|
|
1363
|
+
exports.neutral3 = neutral3;
|