Repository navigation
Expand file tree
/
Copy pathui.html
More file actions
354 lines (300 loc) · 8.5 KB
/
Copy pathui.html
File metadata and controls
354 lines (300 loc) · 8.5 KB
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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Contrast Checker</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
font-size: 14px;
line-height: 1.5;
color: #181A1B;
background: #fff;
padding: 16px;
}
.header {
margin-bottom: 24px;
text-align: center;
}
.header h1 {
font-size: 18px;
font-weight: 600;
margin-bottom: 8px;
color: #181A1B;
}
.header p {
font-size: 12px;
color: #494D50;
}
.main-section {
margin-bottom: 20px;
}
.check-button {
width: 100%;
padding: 12px 16px;
background: #2B3BEE;
color: white;
border: none;
border-radius: 6px;
font-size: 14px;
font-weight: 500;
cursor: pointer;
transition: background-color 0.2s;
margin-bottom: 16px;
font-weight: bold;
}
.check-button:hover {
background: #0B1DDA;
}
.check-button:active {
background: #0413AE;
}
.check-button:disabled {
background: #E4E5E7;
cursor: not-allowed;
}
.results {
margin-top: 16px;
padding: 16px;
background: #f8f9fa;
border-radius: 6px;
display: none;
}
.results.show {
display: block;
}
.results-header {
font-weight: 600;
margin-bottom: 12px;
}
.result-item {
padding: 8px 0;
border-bottom: 1px solid #eee;
}
.result-item:last-child {
border-bottom: none;
}
.status-pass {
color: #049559;
font-weight: 500;
}
.status-fail {
color: #AE040A;
font-weight: 500;
}
.ratio {
font-family: 'Monaco', 'Menlo', monospace;
font-size: 12px;
background: #f1f3f4;
padding: 2px 6px;
border-radius: 3px;
margin-left: 8px;
}
.loading {
display: none;
text-align: center;
color: #666;
margin-top: 16px;
}
.error {
display: none;
padding: 12px;
background: #fff5f5;
border: 1px solid #feb2b2;
border-radius: 6px;
color: #c53030;
margin-top: 16px;
}
.info {
font-size: 12px;
color: #494D50;
margin-top: 16px;
padding: 12px;
background: #F5F9FF;
border-radius: 6px;
border-left: 3px solid #2B7FEE;
}
.highlight-controls {
margin-top: 16px;
}
.highlight-button {
width: 100%;
padding: 8px 12px;
background: transparent;
color: #2B3BEE;
border: 1px solid #2B3BEE;
border-radius: 4px;
font-size: 12px;
cursor: pointer;
margin-bottom: 8px;
font-weight: bold;
transition: background-color 0.2s;
}
.highlight-button:hover {
background: #F5F6FF;
}
.clear-button {
background: #E4E5E7;
border: none;
font-weight: bold;
color: #181A1B;
transition: background-color 0.2s;
}
.clear-button:hover {
background: #CACCCE;
}
</style>
</head>
<body>
<div class="header">
<h1>Contrast Checker</h1>
<p>テキストのコントラスト比をWCAG基準でチェック</p>
</div>
<div class="main-section">
<button id="checkButton" class="check-button">
コントラストをチェック
</button>
<div class="info">
<strong>使用方法:</strong><br>
1. Figmaでフレームまたは要素を選択<br>
2. 「コントラストをチェック」ボタンを押下<br>
3. 問題のあるテキストがFigma検索風に選択表示されます
</div>
</div>
<div id="loading" class="loading">
チェック中...
</div>
<div id="error" class="error"></div>
<div id="results" class="results">
<div class="results-header">チェック結果</div>
<div id="resultsList"></div>
</div>
<div class="highlight-controls">
<button id="highlightButton" class="highlight-button">
問題のあるテキストを選択
</button>
<button id="clearButton" class="highlight-button clear-button">
選択をクリア
</button>
</div>
<script>
let checkResults = [];
// ボタンイベントリスナー
document.getElementById('checkButton').addEventListener('click', function () {
checkContrast();
});
document.getElementById('highlightButton').addEventListener('click', function () {
highlightFailedTexts();
});
document.getElementById('clearButton').addEventListener('click', function () {
clearHighlights();
});
// コントラストチェック実行
function checkContrast() {
const button = document.getElementById('checkButton');
const loading = document.getElementById('loading');
const error = document.getElementById('error');
const results = document.getElementById('results');
// UI状態をリセット
button.disabled = true;
button.textContent = 'チェック中...';
loading.style.display = 'block';
error.style.display = 'none';
results.classList.remove('show');
// メインスレッドにメッセージを送信
parent.postMessage({
pluginMessage: {
type: 'check-contrast'
}
}, '*');
}
// ハイライト実行
function highlightFailedTexts() {
parent.postMessage({
pluginMessage: {
type: 'highlight-failed-texts',
results: checkResults
}
}, '*');
}
// ハイライトクリア
function clearHighlights() {
parent.postMessage({
pluginMessage: {
type: 'clear-highlights'
}
}, '*');
}
// メインスレッドからのメッセージを受信
window.onmessage = function (event) {
const message = event.data.pluginMessage;
if (message.type === 'check-complete') {
handleCheckComplete(message.data);
} else if (message.type === 'check-error') {
handleCheckError(message.error);
}
};
// チェック完了時の処理
function handleCheckComplete(data) {
const button = document.getElementById('checkButton');
const loading = document.getElementById('loading');
const results = document.getElementById('results');
const resultsList = document.getElementById('resultsList');
// UI状態を更新
button.disabled = false;
button.textContent = 'コントラストをチェック';
loading.style.display = 'none';
// 結果を保存
checkResults = data.results;
// 結果を表示
displayResults(data);
results.classList.add('show');
}
// エラー時の処理
function handleCheckError(errorMessage) {
const button = document.getElementById('checkButton');
const loading = document.getElementById('loading');
const error = document.getElementById('error');
button.disabled = false;
button.textContent = 'コントラストをチェック';
loading.style.display = 'none';
error.style.display = 'block';
error.textContent = errorMessage;
}
// 結果を表示
function displayResults(data) {
const resultsList = document.getElementById('resultsList');
const { results, totalTexts, passedCount, failedCount } = data;
let html = '';
// サマリー
html += `<div class="result-item">`;
html += `<strong>総テキスト数:</strong> ${totalTexts} `;
html += `<span class="status-pass">適合: ${passedCount}</span> `;
html += `<span class="status-fail">非適合: ${failedCount}</span>`;
html += `</div>`;
// 各テキストの詳細(非適合のもののみ表示)
if (failedCount > 0) {
const failedResults = results.filter(r => !r.aa);
html += `<div class="result-item"><strong>問題のあるテキスト:</strong></div>`;
failedResults.forEach((result, index) => {
const textPreview = result.text.length > 30
? result.text.substring(0, 30) + '...'
: result.text;
html += `<div class="result-item">`;
html += `${index + 1}. "${textPreview}"`;
html += `<span class="ratio">${result.ratio}:1</span>`;
html += ` <span class="status-fail">FAIL</span>`;
html += `<br><small>必要: ${result.isLargeText ? '3:1' : '4.5:1'} 以上</small>`;
html += `</div>`;
});
}
resultsList.innerHTML = html;
}
</script>
</body>
</html>