-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcolor-picker.php
277 lines (250 loc) · 8.52 KB
/
color-picker.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
<!doctype html>
<html lang="en" data-bs-theme="dark">
<head>
<title>Color Picker | browse.wf</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
<link rel="icon" href="https://browse.wf/Lotus/Interface/Icons/Categories/GrimoireModIcon.png">
<style>
#picker-cards .card {
cursor: pointer;
}
.colour-block {
height: 44px;
width: 44px;
}
.colour-overlay {
color: #fff;
/*text-shadow: #fff 0 0 10px;
mix-blend-mode: difference;*/
text-shadow: #000 0 0 5px, #000 0 0 10px;
}
#picker-table tr:first-child td:first-child > div {
border-top-left-radius: 0.375rem;
}
#picker-table tr:first-child td:last-child > div {
border-top-right-radius: 0.375rem;
}
#picker-table tr:last-child td:first-child > div {
border-bottom-left-radius: 0.375rem;
}
#picker-table tr:last-child td:last-child > div {
border-bottom-right-radius: 0.375rem;
}
</style>
</head>
<body data-bs-theme="dark">
<?php require "components/navbar.php"; ?>
<div class="container pt-3">
<div class="input-group mb-3">
<input class="form-control form-control-color" type="color" style="flex:0 0 auto;width:50px" value="#ff0000" />
<input class="form-control" type="text" value="#ff0000" maxlength="7" />
</div>
<div class="row" style="overflow:hidden">
<div class="col-5 col-lg-4" id="picker-cards" style="height:calc(100vh - 126px);overflow: auto;">
Loading...
</div>
<div class="col-7 col-lg-8" style="height:calc(100vh - 126px);overflow:auto">
<table id="picker-table"></table>
</div>
</div>
</div>
<?php require "components/commonjs.html"; ?>
<script>
let active_picker = "/Lotus/Types/StoreItems/SuitCustomizations/ColourPickerPrimeWarframesItemA";
const params = new URLSearchParams(location.hash.replace("#", ""));
if (params.has("i"))
{
document.querySelector("input[type=color]").value = "#" + params.get("i");
document.querySelector("input[type=text]").value = "#" + params.get("i");
}
if (params.has("p"))
{
active_picker = params.get("p");
}
Promise.all([
fetch("https://browse.wf/warframe-public-export-plus/ExportFlavour.json").then(res => res.json()),
getDictPromise()
]).then(([ExportFlavour, dict]) =>
{
window.ExportFlavour = ExportFlavour;
window.dict = dict;
updatePickerCards();
onLanguageUpdate = function()
{
updatePickerCards();
};
});
function updatePickerCards()
{
const colour_pickers = [];
Object.entries(ExportFlavour).forEach(([uniqueName, flavourItem]) =>
{
if (flavourItem.hexColours)
{
colour_pickers.push({
uniqueName: uniqueName,
icon: flavourItem.icon,
name: dict[flavourItem.name],
colours: flavourItem.hexColours,
});
if (flavourItem.legacyColours)
{
colour_pickers.push({
uniqueName: uniqueName + ":legacy",
icon: flavourItem.icon,
name: dict[flavourItem.name] + " (Legacy)",
colours: flavourItem.legacyColours,
});
}
}
});
const targetRgb = document.querySelector("input[type=text]").value.length == 7 ? hexToRgb(document.querySelector("input[type=text]").value) : undefined;
if (targetRgb)
{
colour_pickers.forEach(picker =>
{
picker.peakSimilarity = 0;
for (colour of picker.colours)
{
const similiary = rgbSimilarity(hexToRgb(peColourToHex(colour)), targetRgb);
if (similiary > picker.peakSimilarity)
{
picker.peakSimilarity = similiary;
}
}
});
colour_pickers.sort((a, b) => b.peakSimilarity - a.peakSimilarity);
}
document.getElementById("picker-cards").innerHTML = "";
colour_pickers.forEach(picker =>
{
const card = document.createElement("div");
card.setAttribute("data-uniqueName", picker.uniqueName);
card.onclick = () => { setActivePicker(picker.uniqueName); };
card.className = "card mb-2";
{
const row = document.createElement("div");
row.className = "row g-0";
{
const col = document.createElement("div");
col.className = "col-3 col-xl-2 d-none d-md-block";
{
const img = document.createElement("img");
img.className = "img-fluid rounded-start";
img.src = "https://browse.wf" + picker.icon;
col.appendChild(img);
}
row.appendChild(col);
}
{
const col = document.createElement("div");
col.className = "col-md-9 col-xl-10";
{
const body = document.createElement("div");
body.className = "card-body";
{
const h5 = document.createElement("h5");
h5.className = "card-title";
h5.textContent = picker.name;
body.appendChild(h5);
}
{
const h6 = document.createElement("h6");
h6.className = "card-subtitle text-body-secondary";
h6.textContent = (picker.peakSimilarity * 100).toFixed(0) + "% Peak Similarity";
body.appendChild(h6);
}
col.appendChild(body);
}
row.appendChild(col);
}
card.appendChild(row);
}
document.getElementById("picker-cards").appendChild(card);
});
setActivePicker(active_picker);
}
function peColourToHex(colour)
{
return "#" + colour.value.substr(4);
}
function hexToRgb(hex)
{
return [
parseInt(hex.substr(1, 2), 16),
parseInt(hex.substr(3, 2), 16),
parseInt(hex.substr(5, 2), 16)
];
}
function rgbDistance(e1, e2)
{
const rmean = (e1[0] + e2[0]) / 2;
const r = e1[0] - e2[0];
const g = e1[1] - e2[1];
const b = e1[2] - e2[2];
return Math.sqrt((((512 + rmean) * r * r) >> 8) + 4 * g * g + (((767 - rmean) * b * b) >> 8));
}
function rgbSimilarity(e1, e2)
{
return 1.0 - (rgbDistance(e1, e2) / 765.0);
}
function updatePickerTable(hexColours)
{
const targetRgb = document.querySelector("input[type=text]").value.length == 7 ? hexToRgb(document.querySelector("input[type=text]").value) : undefined;
document.getElementById("picker-table").innerHTML = "";
let tr = document.createElement("tr");
for (let i = 0; i != hexColours.length; )
{
const hex = peColourToHex(hexColours[i])
const td = document.createElement("td");
{
const block = document.createElement("div");
block.className = "colour-block";
block.style.backgroundColor = hex;
if (targetRgb)
{
const similarity = rgbSimilarity(hexToRgb(hex), targetRgb);
const overlay = document.createElement("div");
overlay.className = "colour-overlay text-center pt-2";
overlay.style.opacity = Math.max(0.5, similarity);
overlay.textContent = (similarity * 100).toFixed(0) + "%";
block.appendChild(overlay);
}
td.appendChild(block);
}
tr.appendChild(td);
if ((++i % 5) == 0)
{
document.getElementById("picker-table").appendChild(tr);
tr = document.createElement("tr");
}
}
}
function setActivePicker(uniqueName)
{
active_picker = uniqueName;
document.querySelectorAll("#picker-cards [data-uniqueName].border-primary").forEach(elm => elm.classList.remove("border-primary"));
document.querySelector("#picker-cards [data-uniqueName='" + uniqueName + "']").classList.add("border-primary");
const picker = ExportFlavour[uniqueName.split(":legacy").join("")];
const legacy = (uniqueName.indexOf(":legacy") != -1);
updatePickerTable(legacy ? picker.legacyColours : picker.hexColours);
history.replaceState({}, undefined, location.pathname + "#i=" + document.querySelector("input[type=color]").value.substr(1) + "&p=" + active_picker);
}
document.querySelector("input[type=color]").onchange = function()
{
document.querySelector("input[type=text]").value = this.value;
updatePickerCards();
};
document.querySelector("input[type=text]").oninput = function()
{
if (this.value.length == 7)
{
document.querySelector("input[type=color]").value = this.value;
updatePickerCards();
}
};
</script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz" crossorigin="anonymous"></script>
</body>
</html>