Skip to content

Commit 69ad743

Browse files
committed
add color picker
1 parent 34530a3 commit 69ad743

File tree

4 files changed

+123
-0
lines changed

4 files changed

+123
-0
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
"@fluent/bundle": "^0.17.0",
6767
"@mdi/svg": "^7.0.96",
6868
"@popperjs/core": "^2.9.2",
69+
"@simonwep/pickr": "^1.8.2",
6970
"@types/lodash-es": "^4.17.4",
7071
"@types/marked": "^4.0.1",
7172
"bootstrap": "=5.0.2",

ts/image-occlusion/color-picker.ts

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
// Copyright: Ankitects Pty Ltd and contributors
2+
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
3+
4+
import "@simonwep/pickr/dist/themes/nano.min.css"; // 'nano' theme
5+
6+
import Pickr from "@simonwep/pickr";
7+
import * as tr from "@tslib/ftl";
8+
import type fabric from "fabric";
9+
10+
import { getShapeColor } from "./tools/lib";
11+
12+
export const colorPicker = (canvas: fabric.Canvas, elem: string, isFillShape: boolean): Pickr => {
13+
const pickr = Pickr.create({
14+
el: elem,
15+
theme: "nano",
16+
useAsButton: true,
17+
autoReposition: true,
18+
comparison: false,
19+
default: getShapeColor(),
20+
swatches: [
21+
"rgba(244, 67, 54, 1)", // Red 500
22+
"rgba(233, 30, 99, 1)", // Pink 500
23+
"rgba(156, 39, 176, 1)", // Purple 500
24+
"rgba(103, 58, 183, 1)", // Deep Purple 500
25+
"rgba(63, 81, 181, 1)", // Indigo 500
26+
"rgba(33, 150, 243, 1)", // Blue 500
27+
"rgba(3, 169, 244, 1)", // Light Blue 500
28+
"rgba(0, 188, 212, 1)", // Cyan 500
29+
"rgba(0, 150, 136, 1)", // Teal 500
30+
"rgba(76, 175, 80, 1)", // Green 500
31+
"rgba(139, 195, 74, 1)", // Light Green 500
32+
"rgba(205, 220, 57, 1)", // Lime 500
33+
"rgba(255, 235, 59, 1)", // Yellow 500
34+
"rgba(255, 193, 7, 1)", // Amber 500
35+
],
36+
components: {
37+
preview: true,
38+
opacity: true,
39+
hue: true,
40+
interaction: {
41+
hex: true,
42+
rgba: true,
43+
input: true,
44+
},
45+
},
46+
});
47+
48+
pickr
49+
.on("init", () => {
50+
if (isFillShape) {
51+
setTiltle(pickr, tr.editingChangeShapeColor());
52+
} else {
53+
setTiltle(pickr, tr.editingQuestionMaskColor());
54+
}
55+
});
56+
pickr
57+
.on("change", (color) => {
58+
const clr = color.toHEXA().toString();
59+
if (isFillShape) {
60+
localStorage.setItem("shape-color", clr);
61+
} else {
62+
localStorage.setItem("ques-color", clr);
63+
}
64+
});
65+
66+
return pickr;
67+
};
68+
69+
const setTiltle = (pickr: Pickr, title: string): void => {
70+
const firstElem = pickr._root.app.firstChild;
71+
const titleElem = document.createElement("div");
72+
globalThis.pickr = pickr;
73+
titleElem.className = "pickr-title";
74+
titleElem.innerHTML = title;
75+
76+
if (firstElem) {
77+
pickr.getRoot().app.insertBefore(titleElem, firstElem);
78+
}
79+
};

ts/licenses.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,14 @@
124124
"path": "node_modules/@protobufjs/utf8",
125125
"licenseFile": "node_modules/@protobufjs/utf8/LICENSE"
126126
},
127+
"@simonwep/pickr@1.8.2": {
128+
"licenses": "MIT",
129+
"repository": "https://github.com/Simonwep/pickr",
130+
"publisher": "Simon Reinisch",
131+
"email": "trash@reinisch.io",
132+
"path": "node_modules/@simonwep/pickr",
133+
"licenseFile": "node_modules/@simonwep/pickr/LICENSE"
134+
},
127135
"@tootallnate/once@2.0.0": {
128136
"licenses": "MIT",
129137
"repository": "https://github.com/TooTallNate/once",
@@ -373,6 +381,15 @@
373381
"path": "node_modules/console-control-strings",
374382
"licenseFile": "node_modules/console-control-strings/LICENSE"
375383
},
384+
"core-js@3.27.2": {
385+
"licenses": "MIT",
386+
"repository": "https://github.com/zloirock/core-js",
387+
"publisher": "Denis Pushkarev",
388+
"email": "zloirock@zloirock.ru",
389+
"url": "http://zloirock.ru",
390+
"path": "node_modules/core-js",
391+
"licenseFile": "node_modules/core-js/LICENSE"
392+
},
376393
"css-browser-selector@0.6.5": {
377394
"licenses": "CC-BY-SA-2.5",
378395
"repository": "https://github.com/verbatim/css_browser_selector",
@@ -1087,6 +1104,14 @@
10871104
"path": "node_modules/nan",
10881105
"licenseFile": "node_modules/nan/LICENSE.md"
10891106
},
1107+
"nanopop@2.2.0": {
1108+
"licenses": "MIT",
1109+
"repository": "https://github.com/Simonwep/nanopop",
1110+
"publisher": "Simon Reinisch",
1111+
"email": "trash@reinisch.io",
1112+
"path": "node_modules/nanopop",
1113+
"licenseFile": "node_modules/nanopop/LICENSE"
1114+
},
10901115
"ngraph.events@1.2.2": {
10911116
"licenses": "BSD-3-Clause",
10921117
"repository": "https://github.com/anvaka/ngraph.events",

yarn.lock

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -729,6 +729,14 @@
729729
resolved "https://registry.yarnpkg.com/@pyoner/svelte-types/-/svelte-types-3.4.4-2.tgz#0bc64255d56e82a5e7f3d0b31b324551a77da6b0"
730730
integrity sha512-5oQsFCU9pxu1mdA72e2XOqVmheSQfpaQnsmvO4FTEd6D3k3Wx3Nr4s2m0gfqjGLHoGGEo9FOK4xQXXX7D5Uz6A==
731731

732+
"@simonwep/pickr@^1.8.2":
733+
version "1.8.2"
734+
resolved "https://registry.yarnpkg.com/@simonwep/pickr/-/pickr-1.8.2.tgz#96dc86675940d7cad63d69c22083dd1cbb9797cb"
735+
integrity sha512-/l5w8BIkrpP6n1xsetx9MWPWlU6OblN5YgZZphxan0Tq4BByTCETL6lyIeY8lagalS2Nbt4F2W034KHLIiunKA==
736+
dependencies:
737+
core-js "^3.15.1"
738+
nanopop "^2.1.0"
739+
732740
"@sinclair/typebox@^0.23.3":
733741
version "0.23.4"
734742
resolved "https://registry.yarnpkg.com/@sinclair/typebox/-/typebox-0.23.4.tgz#6ff93fd2585ce44f7481c9ff6af610fbb5de98a4"
@@ -1810,6 +1818,11 @@ convert-source-map@^1.4.0, convert-source-map@^1.6.0, convert-source-map@^1.7.0:
18101818
dependencies:
18111819
safe-buffer "~5.1.1"
18121820

1821+
core-js@^3.15.1:
1822+
version "3.27.2"
1823+
resolved "https://registry.yarnpkg.com/core-js/-/core-js-3.27.2.tgz#85b35453a424abdcacb97474797815f4d62ebbf7"
1824+
integrity sha512-9ashVQskuh5AZEZ1JdQWp1GqSoC1e1G87MzRqg2gIfVAQ7Qn9K+uFj8EcniUFA4P2NLZfV+TOlX1SzoKfo+s7w==
1825+
18131826
core-js@^3.16.2:
18141827
version "3.21.1"
18151828
resolved "https://registry.yarnpkg.com/core-js/-/core-js-3.21.1.tgz#f2e0ddc1fc43da6f904706e8e955bc19d06a0d94"
@@ -4233,6 +4246,11 @@ nan@^2.17.0:
42334246
resolved "https://registry.yarnpkg.com/nan/-/nan-2.17.0.tgz#c0150a2368a182f033e9aa5195ec76ea41a199cb"
42344247
integrity sha512-2ZTgtl0nJsO0KQCjEpxcIr5D+Yv90plTitZt9JBfQvVJDS5seMl3FOvsh3+9CoYWXf/1l5OaZzzF6nDm4cagaQ==
42354248

4249+
nanopop@^2.1.0:
4250+
version "2.2.0"
4251+
resolved "https://registry.yarnpkg.com/nanopop/-/nanopop-2.2.0.tgz#bd1c25588a7beaf68865bc2df19db4c58c77dcc9"
4252+
integrity sha512-E9JaHcxh3ere8/BEZHAcnuD10RluTSPyTToBvoFWS9/7DcCx6gyKjbn7M7Bx7E1veCxCuY1iO6h4+gdAf1j73Q==
4253+
42364254
natural-compare@^1.4.0:
42374255
version "1.4.0"
42384256
resolved "https://registry.yarnpkg.com/natural-compare/-/natural-compare-1.4.0.tgz#4abebfeed7541f2c27acfb29bdbbd15c8d5ba4f7"

0 commit comments

Comments
 (0)