Moved colour picker into the built CSS and JS files.
This commit is contained in:
parent
25bc1bef60
commit
3d6e2a58db
8 changed files with 180 additions and 146 deletions
133
package-lock.json
generated
133
package-lock.json
generated
|
@ -5,7 +5,7 @@
|
|||
"packages": {
|
||||
"": {
|
||||
"dependencies": {
|
||||
"@swc/core": "^1.4.0",
|
||||
"@swc/core": "^1.4.2",
|
||||
"autoprefixer": "^10.4.17",
|
||||
"cssnano": "^6.0.3",
|
||||
"html-minifier-terser": "^7.2.0",
|
||||
|
@ -26,9 +26,9 @@
|
|||
}
|
||||
},
|
||||
"node_modules/@jridgewell/resolve-uri": {
|
||||
"version": "3.1.1",
|
||||
"resolved": "https://registry.npmjs.org/@jridgewell/resolve-uri/-/resolve-uri-3.1.1.tgz",
|
||||
"integrity": "sha512-dSYZh7HhCDtCKm4QakX0xFpsRDqjjtZf/kjI/v3T3Nwt5r8/qz/M19F9ySyOqU94SXBmeG9ttTul+YnR4LOxFA==",
|
||||
"version": "3.1.2",
|
||||
"resolved": "https://registry.npmjs.org/@jridgewell/resolve-uri/-/resolve-uri-3.1.2.tgz",
|
||||
"integrity": "sha512-bRISgCIjP20/tbWSPWMEi54QVPRZExkuD9lJL+UIxUKtwVJA8wW1Trb1jMs1RFXo1CBTNZ/5hpC9QvmKWdopKw==",
|
||||
"engines": {
|
||||
"node": ">=6.0.0"
|
||||
}
|
||||
|
@ -65,12 +65,12 @@
|
|||
}
|
||||
},
|
||||
"node_modules/@swc/core": {
|
||||
"version": "1.4.0",
|
||||
"resolved": "https://registry.npmjs.org/@swc/core/-/core-1.4.0.tgz",
|
||||
"integrity": "sha512-wc5DMI5BJftnK0Fyx9SNJKkA0+BZSJQx8430yutWmsILkHMBD3Yd9GhlMaxasab9RhgKqZp7Ht30hUYO5ZDvQg==",
|
||||
"version": "1.4.2",
|
||||
"resolved": "https://registry.npmjs.org/@swc/core/-/core-1.4.2.tgz",
|
||||
"integrity": "sha512-vWgY07R/eqj1/a0vsRKLI9o9klGZfpLNOVEnrv4nrccxBgYPjcf22IWwAoaBJ+wpA7Q4fVjCUM8lP0m01dpxcg==",
|
||||
"hasInstallScript": true,
|
||||
"dependencies": {
|
||||
"@swc/counter": "^0.1.1",
|
||||
"@swc/counter": "^0.1.2",
|
||||
"@swc/types": "^0.1.5"
|
||||
},
|
||||
"engines": {
|
||||
|
@ -81,16 +81,16 @@
|
|||
"url": "https://opencollective.com/swc"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"@swc/core-darwin-arm64": "1.4.0",
|
||||
"@swc/core-darwin-x64": "1.4.0",
|
||||
"@swc/core-linux-arm-gnueabihf": "1.4.0",
|
||||
"@swc/core-linux-arm64-gnu": "1.4.0",
|
||||
"@swc/core-linux-arm64-musl": "1.4.0",
|
||||
"@swc/core-linux-x64-gnu": "1.4.0",
|
||||
"@swc/core-linux-x64-musl": "1.4.0",
|
||||
"@swc/core-win32-arm64-msvc": "1.4.0",
|
||||
"@swc/core-win32-ia32-msvc": "1.4.0",
|
||||
"@swc/core-win32-x64-msvc": "1.4.0"
|
||||
"@swc/core-darwin-arm64": "1.4.2",
|
||||
"@swc/core-darwin-x64": "1.4.2",
|
||||
"@swc/core-linux-arm-gnueabihf": "1.4.2",
|
||||
"@swc/core-linux-arm64-gnu": "1.4.2",
|
||||
"@swc/core-linux-arm64-musl": "1.4.2",
|
||||
"@swc/core-linux-x64-gnu": "1.4.2",
|
||||
"@swc/core-linux-x64-musl": "1.4.2",
|
||||
"@swc/core-win32-arm64-msvc": "1.4.2",
|
||||
"@swc/core-win32-ia32-msvc": "1.4.2",
|
||||
"@swc/core-win32-x64-msvc": "1.4.2"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@swc/helpers": "^0.5.0"
|
||||
|
@ -102,9 +102,9 @@
|
|||
}
|
||||
},
|
||||
"node_modules/@swc/core-darwin-arm64": {
|
||||
"version": "1.4.0",
|
||||
"resolved": "https://registry.npmjs.org/@swc/core-darwin-arm64/-/core-darwin-arm64-1.4.0.tgz",
|
||||
"integrity": "sha512-UTJ/Vz+s7Pagef6HmufWt6Rs0aUu+EJF4Pzuwvr7JQQ5b1DZeAAUeUtkUTFx/PvCbM8Xfw4XdKBUZfrIKCfW8A==",
|
||||
"version": "1.4.2",
|
||||
"resolved": "https://registry.npmjs.org/@swc/core-darwin-arm64/-/core-darwin-arm64-1.4.2.tgz",
|
||||
"integrity": "sha512-1uSdAn1MRK5C1m/TvLZ2RDvr0zLvochgrZ2xL+lRzugLlCTlSA+Q4TWtrZaOz+vnnFVliCpw7c7qu0JouhgQIw==",
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
|
@ -117,9 +117,9 @@
|
|||
}
|
||||
},
|
||||
"node_modules/@swc/core-darwin-x64": {
|
||||
"version": "1.4.0",
|
||||
"resolved": "https://registry.npmjs.org/@swc/core-darwin-x64/-/core-darwin-x64-1.4.0.tgz",
|
||||
"integrity": "sha512-f8v58u2GsGak8EtZFN9guXqE0Ep10Suny6xriaW2d8FGqESPyNrnBzli3aqkSeQk5gGqu2zJ7WiiKp3XoUOidA==",
|
||||
"version": "1.4.2",
|
||||
"resolved": "https://registry.npmjs.org/@swc/core-darwin-x64/-/core-darwin-x64-1.4.2.tgz",
|
||||
"integrity": "sha512-TYD28+dCQKeuxxcy7gLJUCFLqrwDZnHtC2z7cdeGfZpbI2mbfppfTf2wUPzqZk3gEC96zHd4Yr37V3Tvzar+lQ==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
|
@ -132,9 +132,9 @@
|
|||
}
|
||||
},
|
||||
"node_modules/@swc/core-linux-arm-gnueabihf": {
|
||||
"version": "1.4.0",
|
||||
"resolved": "https://registry.npmjs.org/@swc/core-linux-arm-gnueabihf/-/core-linux-arm-gnueabihf-1.4.0.tgz",
|
||||
"integrity": "sha512-q2KAkBzmPcTnRij/Y1fgHCKAGevUX/H4uUESrw1J5gmUg9Qip6onKV80lTumA1/aooGJ18LOsB31qdbwmZk9OA==",
|
||||
"version": "1.4.2",
|
||||
"resolved": "https://registry.npmjs.org/@swc/core-linux-arm-gnueabihf/-/core-linux-arm-gnueabihf-1.4.2.tgz",
|
||||
"integrity": "sha512-Eyqipf7ZPGj0vplKHo8JUOoU1un2sg5PjJMpEesX0k+6HKE2T8pdyeyXODN0YTFqzndSa/J43EEPXm+rHAsLFQ==",
|
||||
"cpu": [
|
||||
"arm"
|
||||
],
|
||||
|
@ -147,9 +147,9 @@
|
|||
}
|
||||
},
|
||||
"node_modules/@swc/core-linux-arm64-gnu": {
|
||||
"version": "1.4.0",
|
||||
"resolved": "https://registry.npmjs.org/@swc/core-linux-arm64-gnu/-/core-linux-arm64-gnu-1.4.0.tgz",
|
||||
"integrity": "sha512-SknGu96W0mzHtLHWm+62fk5+Omp9fMPFO7AWyGFmz2tr8EgRRXtTSrBUnWhAbgcalnhen48GsvtMdxf1KNputg==",
|
||||
"version": "1.4.2",
|
||||
"resolved": "https://registry.npmjs.org/@swc/core-linux-arm64-gnu/-/core-linux-arm64-gnu-1.4.2.tgz",
|
||||
"integrity": "sha512-wZn02DH8VYPv3FC0ub4my52Rttsus/rFw+UUfzdb3tHMHXB66LqN+rR0ssIOZrH6K+VLN6qpTw9VizjyoH0BxA==",
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
|
@ -162,9 +162,9 @@
|
|||
}
|
||||
},
|
||||
"node_modules/@swc/core-linux-arm64-musl": {
|
||||
"version": "1.4.0",
|
||||
"resolved": "https://registry.npmjs.org/@swc/core-linux-arm64-musl/-/core-linux-arm64-musl-1.4.0.tgz",
|
||||
"integrity": "sha512-/k3TDvpBRMDNskHooNN1KqwUhcwkfBlIYxRTnJvsfT2C7My4pffR+4KXmt0IKynlTTbCdlU/4jgX4801FSuliw==",
|
||||
"version": "1.4.2",
|
||||
"resolved": "https://registry.npmjs.org/@swc/core-linux-arm64-musl/-/core-linux-arm64-musl-1.4.2.tgz",
|
||||
"integrity": "sha512-3G0D5z9hUj9bXNcwmA1eGiFTwe5rWkuL3DsoviTj73TKLpk7u64ND0XjEfO0huVv4vVu9H1jodrKb7nvln/dlw==",
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
|
@ -177,9 +177,9 @@
|
|||
}
|
||||
},
|
||||
"node_modules/@swc/core-linux-x64-gnu": {
|
||||
"version": "1.4.0",
|
||||
"resolved": "https://registry.npmjs.org/@swc/core-linux-x64-gnu/-/core-linux-x64-gnu-1.4.0.tgz",
|
||||
"integrity": "sha512-GYsTMvNt5+WTVlwwQzOOWsPMw6P/F41u5PGHWmfev8Nd4QJ1h3rWPySKk4mV42IJwH9MgQCVSl3ygwNqwl6kFg==",
|
||||
"version": "1.4.2",
|
||||
"resolved": "https://registry.npmjs.org/@swc/core-linux-x64-gnu/-/core-linux-x64-gnu-1.4.2.tgz",
|
||||
"integrity": "sha512-LFxn9U8cjmYHw3jrdPNqPAkBGglKE3tCZ8rA7hYyp0BFxuo7L2ZcEnPm4RFpmSCCsExFH+LEJWuMGgWERoktvg==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
|
@ -192,9 +192,9 @@
|
|||
}
|
||||
},
|
||||
"node_modules/@swc/core-linux-x64-musl": {
|
||||
"version": "1.4.0",
|
||||
"resolved": "https://registry.npmjs.org/@swc/core-linux-x64-musl/-/core-linux-x64-musl-1.4.0.tgz",
|
||||
"integrity": "sha512-jGVPdM/VwF7kK/uYRW5N6FwzKf/FnDjGIR3RPvQokjYJy7Auk+3Oj21C0Jev7sIT9RYnO/TrFEoEozKeD/z2Qw==",
|
||||
"version": "1.4.2",
|
||||
"resolved": "https://registry.npmjs.org/@swc/core-linux-x64-musl/-/core-linux-x64-musl-1.4.2.tgz",
|
||||
"integrity": "sha512-dp0fAmreeVVYTUcb4u9njTPrYzKnbIH0EhH2qvC9GOYNNREUu2GezSIDgonjOXkHiTCvopG4xU7y56XtXj4VrQ==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
|
@ -207,9 +207,9 @@
|
|||
}
|
||||
},
|
||||
"node_modules/@swc/core-win32-arm64-msvc": {
|
||||
"version": "1.4.0",
|
||||
"resolved": "https://registry.npmjs.org/@swc/core-win32-arm64-msvc/-/core-win32-arm64-msvc-1.4.0.tgz",
|
||||
"integrity": "sha512-biHYm1AronEKlt47O/H8sSOBM2BKXMmWT+ApvlxUw50m1RGNnVnE0bgY7tylFuuSiWyXsQPJbmUV708JqORXVg==",
|
||||
"version": "1.4.2",
|
||||
"resolved": "https://registry.npmjs.org/@swc/core-win32-arm64-msvc/-/core-win32-arm64-msvc-1.4.2.tgz",
|
||||
"integrity": "sha512-HlVIiLMQkzthAdqMslQhDkoXJ5+AOLUSTV6fm6shFKZKqc/9cJvr4S8UveNERL9zUficA36yM3bbfo36McwnvQ==",
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
|
@ -222,9 +222,9 @@
|
|||
}
|
||||
},
|
||||
"node_modules/@swc/core-win32-ia32-msvc": {
|
||||
"version": "1.4.0",
|
||||
"resolved": "https://registry.npmjs.org/@swc/core-win32-ia32-msvc/-/core-win32-ia32-msvc-1.4.0.tgz",
|
||||
"integrity": "sha512-TL5L2tFQb19kJwv6+elToGBj74QXCn9j+hZfwQatvZEJRA5rDK16eH6oAE751dGUArhnWlW3Vj65hViPvTuycw==",
|
||||
"version": "1.4.2",
|
||||
"resolved": "https://registry.npmjs.org/@swc/core-win32-ia32-msvc/-/core-win32-ia32-msvc-1.4.2.tgz",
|
||||
"integrity": "sha512-WCF8faPGjCl4oIgugkp+kL9nl3nUATlzKXCEGFowMEmVVCFM0GsqlmGdPp1pjZoWc9tpYanoXQDnp5IvlDSLhA==",
|
||||
"cpu": [
|
||||
"ia32"
|
||||
],
|
||||
|
@ -237,9 +237,9 @@
|
|||
}
|
||||
},
|
||||
"node_modules/@swc/core-win32-x64-msvc": {
|
||||
"version": "1.4.0",
|
||||
"resolved": "https://registry.npmjs.org/@swc/core-win32-x64-msvc/-/core-win32-x64-msvc-1.4.0.tgz",
|
||||
"integrity": "sha512-e2xVezU7XZ2Stzn4i7TOQe2Kn84oYdG0M3A7XI7oTdcpsKCcKwgiMoroiAhqCv+iN20KNqhnWwJiUiTj/qN5AA==",
|
||||
"version": "1.4.2",
|
||||
"resolved": "https://registry.npmjs.org/@swc/core-win32-x64-msvc/-/core-win32-x64-msvc-1.4.2.tgz",
|
||||
"integrity": "sha512-oV71rwiSpA5xre2C5570BhCsg1HF97SNLsZ/12xv7zayGzqr3yvFALFJN8tHKpqUdCB4FGPjoP3JFdV3i+1wUw==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
|
@ -322,9 +322,9 @@
|
|||
"integrity": "sha512-JZOSA7Mo9sNGB8+UjSgzdLtokWAky1zbztM3WRLCbZ70/3cTANmQmOdR7y2g+J0e2WXywy1yS468tY+IruqEww=="
|
||||
},
|
||||
"node_modules/browserslist": {
|
||||
"version": "4.22.3",
|
||||
"resolved": "https://registry.npmjs.org/browserslist/-/browserslist-4.22.3.tgz",
|
||||
"integrity": "sha512-UAp55yfwNv0klWNapjs/ktHoguxuQNGnOzxYmfnXIS+8AsRDZkSDxg7R1AX3GKzn078SBI5dzwzj/Yx0Or0e3A==",
|
||||
"version": "4.23.0",
|
||||
"resolved": "https://registry.npmjs.org/browserslist/-/browserslist-4.23.0.tgz",
|
||||
"integrity": "sha512-QW8HiM1shhT2GuzkvklfjcKDiWFXHOeFCIA/huJPwHsslwcydgk7X+z2zXpEijP98UCY7HbubZt5J2Zgvf0CaQ==",
|
||||
"funding": [
|
||||
{
|
||||
"type": "opencollective",
|
||||
|
@ -340,8 +340,8 @@
|
|||
}
|
||||
],
|
||||
"dependencies": {
|
||||
"caniuse-lite": "^1.0.30001580",
|
||||
"electron-to-chromium": "^1.4.648",
|
||||
"caniuse-lite": "^1.0.30001587",
|
||||
"electron-to-chromium": "^1.4.668",
|
||||
"node-releases": "^2.0.14",
|
||||
"update-browserslist-db": "^1.0.13"
|
||||
},
|
||||
|
@ -378,9 +378,9 @@
|
|||
}
|
||||
},
|
||||
"node_modules/caniuse-lite": {
|
||||
"version": "1.0.30001585",
|
||||
"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001585.tgz",
|
||||
"integrity": "sha512-yr2BWR1yLXQ8fMpdS/4ZZXpseBgE7o4g41x3a6AJOqZuOi+iE/WdJYAuZ6Y95i4Ohd2Y+9MzIWRR+uGABH4s3Q==",
|
||||
"version": "1.0.30001588",
|
||||
"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001588.tgz",
|
||||
"integrity": "sha512-+hVY9jE44uKLkH0SrUTqxjxqNTOWHsbnQDIKjwkZ3lNTzUUVdBLBGXtj/q5Mp5u98r3droaZAewQuEDzjQdZlQ==",
|
||||
"funding": [
|
||||
{
|
||||
"type": "opencollective",
|
||||
|
@ -643,9 +643,9 @@
|
|||
}
|
||||
},
|
||||
"node_modules/electron-to-chromium": {
|
||||
"version": "1.4.665",
|
||||
"resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.665.tgz",
|
||||
"integrity": "sha512-UpyCWObBoD+nSZgOC2ToaIdZB0r9GhqT2WahPKiSki6ckkSuKhQNso8V2PrFcHBMleI/eqbKgVQgVC4Wni4ilw=="
|
||||
"version": "1.4.677",
|
||||
"resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.677.tgz",
|
||||
"integrity": "sha512-erDa3CaDzwJOpyvfKhOiJjBVNnMM0qxHq47RheVVwsSQrgBA9ZSGV9kdaOfZDPXcHzhG7lBxhj6A7KvfLJBd6Q=="
|
||||
},
|
||||
"node_modules/entities": {
|
||||
"version": "4.5.0",
|
||||
|
@ -699,11 +699,14 @@
|
|||
}
|
||||
},
|
||||
"node_modules/lilconfig": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/lilconfig/-/lilconfig-3.0.0.tgz",
|
||||
"integrity": "sha512-K2U4W2Ff5ibV7j7ydLr+zLAkIg5JJ4lPn1Ltsdt+Tz/IjQ8buJ55pZAxoP34lqIiwtF9iAvtLv3JGv7CAyAg+g==",
|
||||
"version": "3.1.1",
|
||||
"resolved": "https://registry.npmjs.org/lilconfig/-/lilconfig-3.1.1.tgz",
|
||||
"integrity": "sha512-O18pf7nyvHTckunPWCV1XUNXU1piu01y2b7ATJ0ppkUkk8ocqVWBrYjJBCwHDjD/ZWcfyrA0P4gKhzWGi5EINQ==",
|
||||
"engines": {
|
||||
"node": ">=14"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/antonk52"
|
||||
}
|
||||
},
|
||||
"node_modules/lodash.memoize": {
|
||||
|
@ -1307,9 +1310,9 @@
|
|||
}
|
||||
},
|
||||
"node_modules/terser": {
|
||||
"version": "5.27.0",
|
||||
"resolved": "https://registry.npmjs.org/terser/-/terser-5.27.0.tgz",
|
||||
"integrity": "sha512-bi1HRwVRskAjheeYl291n3JC4GgO/Ty4z1nVs5AAsmonJulGxpSektecnNedrwK9C7vpvVtcX3cw00VSLt7U2A==",
|
||||
"version": "5.27.2",
|
||||
"resolved": "https://registry.npmjs.org/terser/-/terser-5.27.2.tgz",
|
||||
"integrity": "sha512-sHXmLSkImesJ4p5apTeT63DsV4Obe1s37qT8qvwHRmVxKTBH7Rv9Wr26VcAMmLbmk9UliiwK8z+657NyJHHy/w==",
|
||||
"dependencies": {
|
||||
"@jridgewell/source-map": "^0.3.3",
|
||||
"acorn": "^8.8.2",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"dependencies": {
|
||||
"@swc/core": "^1.4.0",
|
||||
"@swc/core": "^1.4.2",
|
||||
"autoprefixer": "^10.4.17",
|
||||
"cssnano": "^6.0.3",
|
||||
"html-minifier-terser": "^7.2.0",
|
||||
|
|
|
@ -516,6 +516,8 @@ body {
|
|||
@include sprite.css;
|
||||
@include noscript.css;
|
||||
|
||||
@include colpick.css;
|
||||
|
||||
@include domaintrans.css;
|
||||
|
||||
@include themes/beige.css;
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
|
||||
<meta name="format-detection" content="telephone=no">
|
||||
<link href="{ami.css}" rel="stylesheet" type="text/css">
|
||||
<link href="/picker.css" rel="stylesheet" type="text/css">
|
||||
</head>
|
||||
<body>
|
||||
<noscript>
|
||||
|
@ -24,7 +23,6 @@
|
|||
</div>
|
||||
</div>
|
||||
</noscript>
|
||||
<script src="/picker.js" type="text/javascript" charset="utf-8"></script>
|
||||
<script src="{ami.js}" type="text/javascript" charset="utf-8"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
85
src/ami.js/colour.js
Normal file
85
src/ami.js/colour.js
Normal file
|
@ -0,0 +1,85 @@
|
|||
const AmiColour = (() => {
|
||||
const readThres = 168;
|
||||
const lumiRed = .299;
|
||||
const lumiGreen = .587;
|
||||
const lumiBlue = .114;
|
||||
|
||||
const pub = {};
|
||||
|
||||
const extractRGB = raw => [
|
||||
(raw >> 16) & 0xFF,
|
||||
(raw >> 8) & 0xFF,
|
||||
raw & 0xFF,
|
||||
];
|
||||
|
||||
const luminance = raw => {
|
||||
const rgb = extractRGB(raw);
|
||||
return rgb[0] * lumiRed
|
||||
+ rgb[1] * lumiGreen
|
||||
+ rgb[2] * lumiBlue;
|
||||
};
|
||||
|
||||
const weightedNumber = (num1, num2, weight) => {
|
||||
weight = Math.min(1, Math.max(0, weight));
|
||||
return Math.round((num1 * weight) + (num2 * (1 - weight)));
|
||||
};
|
||||
|
||||
const weighted = (raw1, raw2, weight) => {
|
||||
const rgb1 = extractRGB(raw1),
|
||||
rgb2 = extractRGB(raw2);
|
||||
return (weightedNumber(rgb1[0], rgb2[0], weight) << 16)
|
||||
| (weightedNumber(rgb1[1], rgb2[1], weight) << 8)
|
||||
| weightedNumber(rgb1[2], rgb2[2], weight);
|
||||
};
|
||||
|
||||
pub.extractRGB = extractRGB;
|
||||
pub.weightedNumber = weightedNumber;
|
||||
pub.luminance = luminance;
|
||||
pub.weighted = weighted;
|
||||
|
||||
pub.text = raw => luminance(raw) > readThres ? 0 : 0xFFFFFF;
|
||||
|
||||
pub.shaded = (raw, offset) => {
|
||||
if(offset == 0)
|
||||
return raw;
|
||||
|
||||
let dir = 0xFFFFFF;
|
||||
if(offset < 0) {
|
||||
dir = 0;
|
||||
offset *= -1;
|
||||
}
|
||||
|
||||
return weighted(dir, raw, offset);
|
||||
};
|
||||
|
||||
pub.hexByte = raw => {
|
||||
let str = raw.toString(16).substring(0, 2);
|
||||
return str.length < 2
|
||||
? `0${str}` : str;
|
||||
};
|
||||
|
||||
pub.hex = raw => {
|
||||
let str = raw.toString(16).substring(0, 6);
|
||||
if(str.length < 6)
|
||||
str = '000000'.substring(str.length) + str;
|
||||
return `#${str}`;
|
||||
};
|
||||
|
||||
pub.fromHex = str => {
|
||||
while(str.substring(0, 1) === '#')
|
||||
str = str.substring(1);
|
||||
str = str.substring(0, 6);
|
||||
|
||||
if(str.length === 3)
|
||||
str = str.substring(0, 1) + str.substring(0, 1)
|
||||
+ str.substring(1, 2) + str.substring(1, 2)
|
||||
+ str.substring(2, 3) + str.substring(2, 3);
|
||||
|
||||
if(str.length !== 6)
|
||||
throw 'not a valid hex string';
|
||||
|
||||
return parseInt(str, 16);
|
||||
};
|
||||
|
||||
return pub;
|
||||
})();
|
|
@ -1,4 +1,6 @@
|
|||
#include colour.js
|
||||
#include utility.js
|
||||
#include colpick/picker.jsx
|
||||
|
||||
var AmiColourPicker = function(parent) {
|
||||
var container = $e({ attrs: { id: 'pickerNew', className: 'hidden' } }),
|
||||
|
@ -12,7 +14,7 @@ var AmiColourPicker = function(parent) {
|
|||
|
||||
callback.call(picker, {
|
||||
raw: result,
|
||||
hex: FwColourPicker.hexFormat(result),
|
||||
hex: AmiColour.hex(result),
|
||||
});
|
||||
callback = undefined;
|
||||
},
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
#include colour.js
|
||||
|
||||
var FwColourPicker = function(callback, options, colour, onClose) {
|
||||
if(typeof callback !== 'function')
|
||||
return;
|
||||
|
@ -6,58 +8,6 @@ var FwColourPicker = function(callback, options, colour, onClose) {
|
|||
if(typeof options !== 'object')
|
||||
options = {};
|
||||
|
||||
var readThres = 168,
|
||||
lumiRed = .299,
|
||||
lumiGreen = .587,
|
||||
lumiBlue = .114;
|
||||
|
||||
var extractRGB = function(raw) {
|
||||
return [
|
||||
(raw >> 16) & 0xFF,
|
||||
(raw >> 8) & 0xFF,
|
||||
raw & 0xFF,
|
||||
];
|
||||
};
|
||||
|
||||
var calcLumi = function(raw) {
|
||||
var rgb = extractRGB(raw);
|
||||
return rgb[0] * lumiRed
|
||||
+ rgb[1] * lumiGreen
|
||||
+ rgb[2] * lumiBlue;
|
||||
};
|
||||
|
||||
var textColour = function(raw) {
|
||||
return calcLumi(raw) > readThres ? 0 : 0xFFFFFF;
|
||||
};
|
||||
|
||||
var weightNum = function(n1, n2, w) {
|
||||
w = Math.min(1, Math.max(0, w));
|
||||
return Math.round((n1 * w) + (n2 * (1 - w)));
|
||||
};
|
||||
|
||||
var weightColour = function(c1, c2, w) {
|
||||
c1 = extractRGB(c1);
|
||||
c2 = extractRGB(c2);
|
||||
return (weightNum(c1[0], c2[0], w) << 16)
|
||||
| (weightNum(c1[1], c2[1], w) << 8)
|
||||
| weightNum(c1[2], c2[2], w);
|
||||
};
|
||||
|
||||
var shadeColour = function(raw, offset) {
|
||||
if(offset == 0)
|
||||
return raw;
|
||||
|
||||
var dir = 0xFFFFFF;
|
||||
if(offset < 0) {
|
||||
dir = 0;
|
||||
offset *= -1;
|
||||
}
|
||||
|
||||
return weightColour(dir, raw, offset);
|
||||
};
|
||||
|
||||
var hexFormat = FwColourPicker.hexFormat;
|
||||
|
||||
var verifyOption = function(name, type, def) {
|
||||
if(typeof options[name] !== type)
|
||||
options[name] = def;
|
||||
|
@ -75,7 +25,7 @@ var FwColourPicker = function(callback, options, colour, onClose) {
|
|||
|
||||
var onColourChange = [];
|
||||
var runOnColourChange = function() {
|
||||
var text = textColour(colour);
|
||||
var text = AmiColour.text(colour);
|
||||
for(var i = 0; i < onColourChange.length; ++i)
|
||||
onColourChange[i](colour, text);
|
||||
};
|
||||
|
@ -108,7 +58,7 @@ var FwColourPicker = function(callback, options, colour, onClose) {
|
|||
var container = document.createElement('div');
|
||||
container.className = 'fw-colour-picker';
|
||||
onColourChange.push(function(colour) {
|
||||
container.style.borderColor = hexFormat(colour);
|
||||
container.style.borderColor = AmiColour.hex(colour);
|
||||
});
|
||||
|
||||
var form = document.createElement('form');
|
||||
|
@ -125,9 +75,9 @@ var FwColourPicker = function(callback, options, colour, onClose) {
|
|||
var activeTab = undefined;
|
||||
onColourChange.push(function(colour, text) {
|
||||
if(activeTab) {
|
||||
activeTab.b.style.background = hexFormat(colour);
|
||||
activeTab.b.style.borderColor = hexFormat(colour);
|
||||
activeTab.b.style.color = hexFormat(text);
|
||||
activeTab.b.style.background = AmiColour.hex(colour);
|
||||
activeTab.b.style.borderColor = AmiColour.hex(colour);
|
||||
activeTab.b.style.color = AmiColour.hex(text);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -138,7 +88,7 @@ var FwColourPicker = function(callback, options, colour, onClose) {
|
|||
tabbedContainer.className = 'fw-colour-picker-tabbed-container';
|
||||
tabbed.appendChild(tabbedContainer);
|
||||
onColourChange.push(function(colour) {
|
||||
tabbedContainer.style.borderColor = hexFormat(colour);
|
||||
tabbedContainer.style.borderColor = AmiColour.hex(colour);
|
||||
});
|
||||
|
||||
var tabbedList = document.createElement('div');
|
||||
|
@ -162,9 +112,9 @@ var FwColourPicker = function(callback, options, colour, onClose) {
|
|||
if(activeTab) {
|
||||
activeTab.c.classList.add('fw-colour-picker-tab-container-active');
|
||||
activeTab.b.classList.add('fw-colour-picker-tab-button-active');
|
||||
activeTab.b.style.background = hexFormat(colour);
|
||||
activeTab.b.style.borderColor = hexFormat(colour);
|
||||
activeTab.b.style.color = hexFormat(textColour(colour));
|
||||
activeTab.b.style.background = AmiColour.hex(colour);
|
||||
activeTab.b.style.borderColor = AmiColour.hex(colour);
|
||||
activeTab.b.style.color = AmiColour.hex(AmiColour.text(colour));
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -199,7 +149,7 @@ var FwColourPicker = function(callback, options, colour, onClose) {
|
|||
var option = document.createElement('a');
|
||||
option.href = 'javascript:void(0);';
|
||||
option.className = 'fw-colour-picker-presets-option';
|
||||
option.style.background = hexFormat(preset.c);
|
||||
option.style.background = AmiColour.hex(preset.c);
|
||||
option.title = preset.n;
|
||||
option.onclick = function() {
|
||||
setColour(preset.c);
|
||||
|
@ -226,7 +176,7 @@ var FwColourPicker = function(callback, options, colour, onClose) {
|
|||
var option = document.createElement('a');
|
||||
option.href = 'javascript:void(0);';
|
||||
option.className = 'fw-colour-picker-grid-option';
|
||||
option.style.background = hexFormat(grey);
|
||||
option.style.background = AmiColour.hex(grey);
|
||||
option.onclick = function() {
|
||||
setColour(grey);
|
||||
};
|
||||
|
@ -242,7 +192,7 @@ var FwColourPicker = function(callback, options, colour, onClose) {
|
|||
var option = document.createElement('a');
|
||||
option.href = 'javascript:void(0);';
|
||||
option.className = 'fw-colour-picker-grid-option';
|
||||
option.style.background = hexFormat(colour);
|
||||
option.style.background = AmiColour.hex(colour);
|
||||
option.onclick = function() {
|
||||
setColour(colour);
|
||||
};
|
||||
|
@ -250,7 +200,7 @@ var FwColourPicker = function(callback, options, colour, onClose) {
|
|||
option.classList[(value === colour ? 'add' : 'remove')]('fw-colour-picker-grid-option-active');
|
||||
});
|
||||
cont.appendChild(option);
|
||||
})(shadeColour(colours[j], shades[i]));
|
||||
})(AmiColour.shaded(colours[j], shades[i]));
|
||||
|
||||
return cont;
|
||||
});
|
||||
|
@ -272,7 +222,7 @@ var FwColourPicker = function(callback, options, colour, onClose) {
|
|||
var sValue = document.createElement('div');
|
||||
sValue.className = 'fw-colour-picker-slider-value';
|
||||
sCont.appendChild(sValue);
|
||||
|
||||
|
||||
var sValueSliderCont = document.createElement('div');
|
||||
sValueSliderCont.className = 'fw-colour-picker-slider-value-slider-container';
|
||||
sValue.appendChild(sValueSliderCont);
|
||||
|
@ -318,7 +268,7 @@ var FwColourPicker = function(callback, options, colour, onClose) {
|
|||
sValueSlider.value = update(colour);
|
||||
sValueInput.value = update(colour);
|
||||
|
||||
var gradient = 'linear-gradient(to right, ' + hexFormat(apply(colour, 0)) + ', ' + hexFormat(apply(colour, 0xFF)) + ')';
|
||||
var gradient = 'linear-gradient(to right, ' + AmiColour.hex(apply(colour, 0)) + ', ' + AmiColour.hex(apply(colour, 0xFF)) + ')';
|
||||
sGradient.style.background = '';
|
||||
sGradient.style.background = gradient;
|
||||
if(!sGradient.style.background)
|
||||
|
@ -361,7 +311,7 @@ var FwColourPicker = function(callback, options, colour, onClose) {
|
|||
colourPreview.className = 'fw-colour-picker-colour-preview';
|
||||
colourPreviewContainer.appendChild(colourPreview);
|
||||
onColourChange.push(function(colour) {
|
||||
colourPreview.style.background = hexFormat(colour);
|
||||
colourPreview.style.background = AmiColour.hex(colour);
|
||||
});
|
||||
|
||||
var values = {};
|
||||
|
@ -397,7 +347,7 @@ var FwColourPicker = function(callback, options, colour, onClose) {
|
|||
|
||||
if(options.showHexValue)
|
||||
addValue('hex', 'Hex', 'text', function(value) {
|
||||
return hexFormat(value);
|
||||
return AmiColour.hex(value);
|
||||
}, function(value) {
|
||||
while(value.substring(0, 1) === '#')
|
||||
value = value.substring(1);
|
||||
|
@ -434,8 +384,8 @@ var FwColourPicker = function(callback, options, colour, onClose) {
|
|||
if(action === null) {
|
||||
button.className += ' fw-colour-picker-buttons-button-submit';
|
||||
onColourChange.push(function(colour, text) {
|
||||
button.style.background = hexFormat(colour);
|
||||
button.style.color = hexFormat(text);
|
||||
button.style.background = AmiColour.hex(colour);
|
||||
button.style.color = AmiColour.hex(text);
|
||||
});
|
||||
button.type = 'submit';
|
||||
} else {
|
||||
|
@ -497,9 +447,3 @@ var FwColourPicker = function(callback, options, colour, onClose) {
|
|||
|
||||
return pub;
|
||||
};
|
||||
FwColourPicker.hexFormat = function(raw) {
|
||||
var str = raw.toString(16).substring(0, 6);
|
||||
if(str.length < 6)
|
||||
str = '000000'.substring(str.length) + str;
|
||||
return '#' + str;
|
||||
};
|
Loading…
Reference in a new issue