-
Notifications
You must be signed in to change notification settings - Fork 55
Expand file tree
/
Copy pathcss-fallback-debugger.html
More file actions
679 lines (633 loc) · 21.7 KB
/
Copy pathcss-fallback-debugger.html
File metadata and controls
679 lines (633 loc) · 21.7 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
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Diagnostic Engine | CSS Properties</title>
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link href="https://fonts.googleapis.com/css2?family=Cormorant+Garamond:wght@400;500;600&family=JetBrains+Mono:wght@300;400;500&family=Inter:wght@300;400;500;600&display=swap" rel="stylesheet" />
<style>
:root {
--bg-base: #050507;
--bg-surface: #0a0a0e;
--bg-elevated: #121218;
--border-subtle: #1e1e24;
--border-strong: #2a2a32;
--text-main: #f3f3f5;
--text-muted: #8b8b99;
--accent-gold: #c2a679;
--accent-blue: #3b82f6;
--status-success: #10b981;
--status-error: #ef4444;
--status-skip: #64748b;
}
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
background-color: var(--bg-base);
color: var(--text-main);
font-family: "Inter", sans-serif;
min-height: 100vh;
display: flex;
flex-direction: column;
overflow-x: hidden;
-webkit-font-smoothing: antialiased;
}
header {
padding: 2.5rem 4rem;
border-bottom: 1px solid var(--border-subtle);
background: var(--bg-surface);
display: flex;
justify-content: space-between;
align-items: flex-end;
}
h1 {
font-family: "Cormorant Garamond", serif;
font-size: 2.25rem;
font-weight: 500;
letter-spacing: 0.01em;
color: var(--text-main);
}
.subtitle {
font-family: "JetBrains Mono", monospace;
font-size: 0.75rem;
color: var(--accent-gold);
margin-top: 0.5rem;
letter-spacing: 0.1em;
text-transform: uppercase;
}
main {
flex: 1;
display: grid;
grid-template-columns: 45% 55%;
gap: 1px;
background: var(--border-subtle);
}
.panel {
background: var(--bg-base);
padding: 3rem 4rem;
display: flex;
flex-direction: column;
gap: 2.5rem;
height: calc(100vh - 110px);
overflow-y: auto;
}
.input-section {
display: flex;
flex-direction: column;
gap: 1rem;
}
.input-header {
display: flex;
justify-content: space-between;
align-items: center;
border-bottom: 1px solid var(--border-subtle);
padding-bottom: 0.75rem;
}
.input-header span {
font-family: "Inter", sans-serif;
font-size: 0.85rem;
font-weight: 500;
color: var(--text-muted);
text-transform: uppercase;
letter-spacing: 0.05em;
}
textarea {
width: 100%;
background: var(--bg-elevated);
border: 1px solid var(--border-strong);
border-radius: 4px;
color: var(--text-main);
font-family: "JetBrains Mono", monospace;
font-size: 0.85rem;
line-height: 1.6;
padding: 1.25rem;
resize: vertical;
outline: none;
transition: border-color 0.2s ease;
}
textarea:focus {
border-color: var(--accent-blue);
}
#context-vars {
height: 180px;
}
#target-css {
height: 120px;
}
.timeline-container {
position: relative;
display: flex;
flex-direction: column;
gap: 2rem;
padding-bottom: 2rem;
}
.timeline-track {
position: absolute;
top: 24px;
bottom: 24px;
left: 11px;
width: 2px;
background: var(--border-strong);
z-index: 0;
}
.step-wrapper {
display: flex;
gap: 1.5rem;
position: relative;
z-index: 1;
opacity: 0;
transform: translateY(10px);
animation: slideUp 0.4s ease forwards;
}
@keyframes slideUp {
to {
opacity: 1;
transform: translateY(0);
}
}
.step-indicator {
width: 24px;
height: 24px;
border-radius: 50%;
background: var(--bg-base);
border: 2px solid var(--border-strong);
flex-shrink: 0;
margin-top: 1.25rem;
display: flex;
align-items: center;
justify-content: center;
transition: all 0.3s ease;
}
.step-wrapper.is-success .step-indicator {
border-color: var(--status-success);
background: rgba(16, 185, 129, 0.1);
}
.step-wrapper.is-success .step-indicator::after {
content: "";
width: 8px;
height: 8px;
background: var(--status-success);
border-radius: 50%;
}
.step-wrapper.is-error .step-indicator {
border-color: var(--status-error);
background: rgba(239, 68, 68, 0.1);
}
.step-wrapper.is-error .step-indicator::after {
content: "";
width: 8px;
height: 8px;
background: var(--status-error);
border-radius: 50%;
}
.step-wrapper.is-skip .step-indicator {
border-color: var(--status-skip);
}
.step-content {
flex: 1;
background: var(--bg-surface);
border: 1px solid var(--border-strong);
border-radius: 6px;
padding: 1.5rem;
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
}
.step-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 1rem;
}
.var-name {
font-family: "JetBrains Mono", monospace;
font-size: 0.95rem;
color: var(--text-main);
background: var(--bg-elevated);
border: 1px solid var(--border-subtle);
padding: 0.35rem 0.75rem;
border-radius: 4px;
}
.badge {
font-size: 0.7rem;
font-weight: 600;
text-transform: uppercase;
letter-spacing: 0.05em;
padding: 0.35rem 0.6rem;
border-radius: 3px;
}
.badge-success {
background: rgba(16, 185, 129, 0.15);
color: var(--status-success);
}
.badge-error {
background: rgba(239, 68, 68, 0.15);
color: var(--status-error);
}
.badge-skip {
background: rgba(100, 116, 139, 0.15);
color: var(--status-skip);
}
.step-message {
font-size: 0.85rem;
color: var(--text-muted);
line-height: 1.5;
margin-bottom: 1.25rem;
}
.btn-details {
background: transparent;
border: 1px solid var(--border-strong);
color: var(--text-main);
padding: 0.5rem 1rem;
font-family: "Inter", sans-serif;
font-size: 0.75rem;
font-weight: 500;
border-radius: 4px;
cursor: pointer;
transition: all 0.2s ease;
}
.btn-details:hover {
background: var(--bg-elevated);
border-color: var(--accent-gold);
color: var(--accent-gold);
}
::-webkit-scrollbar {
width: 6px;
height: 6px;
}
::-webkit-scrollbar-track {
background: var(--bg-base);
}
::-webkit-scrollbar-thumb {
background: var(--border-strong);
border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
background: var(--border-subtle);
}
#empty-state {
height: 100%;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
text-align: center;
color: var(--text-muted);
}
#empty-state svg {
width: 48px;
height: 48px;
opacity: 0.5;
margin-bottom: 1rem;
}
#empty-state p {
font-family: "Cormorant Garamond", serif;
font-size: 1.5rem;
}
dialog {
margin: auto;
background: var(--bg-surface);
border: 1px solid var(--border-strong);
border-radius: 8px;
padding: 2.5rem;
color: var(--text-main);
width: 100%;
max-width: 600px;
box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
}
dialog::backdrop {
background: rgba(0, 0, 0, 0.7);
backdrop-filter: blur(4px);
}
.modal-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 1.5rem;
border-bottom: 1px solid var(--border-subtle);
padding-bottom: 1rem;
}
.modal-title {
font-family: "Cormorant Garamond", serif;
font-size: 1.5rem;
color: var(--accent-gold);
}
.btn-close {
background: transparent;
border: none;
color: var(--text-muted);
cursor: pointer;
font-size: 1.5rem;
}
.btn-close:hover {
color: var(--text-main);
}
.data-grid {
display: grid;
grid-template-columns: 140px 1fr;
gap: 1rem;
font-size: 0.85rem;
}
.data-label {
color: var(--text-muted);
font-weight: 500;
}
.data-value {
font-family: "JetBrains Mono", monospace;
color: var(--text-main);
word-break: break-all;
}
.data-value.highlight-red {
color: var(--status-error);
}
.modal-explanation {
margin-top: 1.5rem;
padding-top: 1.5rem;
border-top: 1px dashed var(--border-strong);
font-size: 0.9rem;
line-height: 1.6;
color: var(--text-muted);
}
.iacvt-warning {
margin-top: 1rem;
background: rgba(239, 68, 68, 0.1);
border-left: 3px solid var(--status-error);
padding: 1rem;
border-radius: 0 4px 4px 0;
color: #fca5a5;
font-size: 0.85rem;
}
</style>
</head>
<body>
<header>
<div>
<h1>Diagnostic Engine</h1>
<div class="subtitle">CSS Custom Property Fallback Resolution</div>
</div>
</header>
<main>
<div class="panel">
<div class="input-section">
<div class="input-header">
<span>Context Environment</span>
</div>
<textarea id="context-vars" spellcheck="false">
--theme-primary: 24px;
--theme-secondary: #000000;
--surface-bg: rgba(255, 255, 255, 0.8);
--invalid-color: 100vh;</textarea>
</div>
<div class="input-section">
<div class="input-header">
<span>Target CSS Rule</span>
</div>
<textarea id="target-css" spellcheck="false">background-color: var(--theme-brand, var(--invalid-color, var(--theme-secondary, red)));</textarea>
</div>
</div>
<div class="panel">
<div id="empty-state">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="1" d="M10 20l4-16m4 4l4 4-4 4M6 16l-4-4 4-4" />
</svg>
<p>Awaiting valid CSS execution</p>
</div>
<div class="timeline-container" id="timeline" style="display: none">
<div class="timeline-track"></div>
</div>
</div>
</main>
<dialog id="detail-modal">
<div class="modal-header">
<div class="modal-title" id="modal-title">Variable Diagnostics</div>
<button class="btn-close" id="modal-close">×</button>
</div>
<div class="data-grid" id="modal-data"></div>
<div class="modal-explanation" id="modal-explanation"></div>
</dialog>
<script>
function escHtml(s) {
return String(s).replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
}
const contextInput = document.getElementById("context-vars");
const targetInput = document.getElementById("target-css");
const timeline = document.getElementById("timeline");
const emptyState = document.getElementById("empty-state");
const modal = document.getElementById("detail-modal");
const modalClose = document.getElementById("modal-close");
let traceDataStore = [];
modalClose.addEventListener("click", () => modal.close());
modal.addEventListener("click", (e) => {
const rect = modal.getBoundingClientRect();
const isInDialog = rect.top <= e.clientY && e.clientY <= rect.top + rect.height && rect.left <= e.clientX && e.clientX <= rect.left + rect.width;
if (!isInDialog) modal.close();
});
function parseContext(text) {
const vars = {};
const lines = text.split("\n");
let currentRule = "";
for (const line of lines) {
currentRule += line.trim() + " ";
if (currentRule.includes(";")) {
const statements = currentRule.split(";");
for (let i = 0; i < statements.length - 1; i++) {
const stmt = statements[i];
const colonIdx = stmt.indexOf(":");
if (colonIdx > -1) {
const key = stmt.substring(0, colonIdx).trim();
const val = stmt.substring(colonIdx + 1).trim();
if (key.startsWith("--")) vars[key] = val;
}
}
currentRule = statements[statements.length - 1];
}
}
return vars;
}
function parseVarChain(valueStr) {
if (!valueStr.includes("var(")) {
return { type: "literal", value: valueStr.trim() };
}
let start = valueStr.indexOf("var(");
let parenCount = 0;
let end = -1;
for (let i = start + 3; i < valueStr.length; i++) {
if (valueStr[i] === "(") parenCount++;
if (valueStr[i] === ")") {
parenCount--;
if (parenCount === 0) {
end = i;
break;
}
}
}
if (end === -1) return { type: "literal", value: valueStr.trim() };
const inner = valueStr.substring(start + 4, end);
let commaIdx = -1;
let innerParenCount = 0;
for (let i = 0; i < inner.length; i++) {
if (inner[i] === "(") innerParenCount++;
if (inner[i] === ")") innerParenCount--;
if (inner[i] === "," && innerParenCount === 0) {
commaIdx = i;
break;
}
}
if (commaIdx !== -1) {
const customProp = inner.substring(0, commaIdx).trim();
const fallbackStr = inner.substring(commaIdx + 1).trim();
return { type: "var", name: customProp, fallback: parseVarChain(fallbackStr) };
}
return { type: "var", name: inner.trim(), fallback: null };
}
function evaluateLogic(tree, contextVars, cssPropName) {
let trace = [];
let currentNode = tree;
while (currentNode && currentNode.type === "var") {
let step = { prop: currentNode.name, cssPropName: cssPropName };
if (contextVars.hasOwnProperty(currentNode.name)) {
let val = contextVars[currentNode.name];
step.found = true;
step.value = val;
if (CSS.supports(cssPropName, val)) {
step.valid = true;
trace.push(step);
return trace;
} else {
step.valid = false;
trace.push(step);
return trace;
}
} else {
step.found = false;
trace.push(step);
currentNode = currentNode.fallback;
}
}
if (currentNode && currentNode.type === "literal") {
let step = { isLiteral: true, value: currentNode.value, cssPropName: cssPropName };
if (CSS.supports(cssPropName, currentNode.value)) {
step.valid = true;
} else {
step.valid = false;
}
trace.push(step);
}
return trace;
}
function showModal(index) {
const step = traceDataStore[index];
const titleEl = document.getElementById("modal-title");
const dataEl = document.getElementById("modal-data");
const expEl = document.getElementById("modal-explanation");
titleEl.textContent = step.isLiteral ? "Literal Fallback Analysis" : `Variable: ${step.prop}`;
dataEl.innerHTML = "";
expEl.innerHTML = "";
const addRow = (lbl, val, hl = false) => {
dataEl.innerHTML += `<div class="data-label">${escHtml(lbl)}</div><div class="data-value ${hl ? "highlight-red" : ""}">${escHtml(val)}</div>`;
};
addRow("Target Property", step.cssPropName);
if (step.isLiteral) {
addRow("Type", "Static Fallback");
addRow("Value", step.value);
addRow("CSS.supports()", step.valid ? "true" : "false", !step.valid);
expEl.innerHTML = step.valid ? `The parser reached the end of the chain. The literal value is valid for the target property and will be applied.` : `The parser exhausted all variables. The final fallback provided is syntactically invalid for the target property.`;
} else {
addRow("Context Search", step.found ? "Found" : "Undefined");
if (step.found) {
addRow("Assigned Value", step.value);
addRow("CSS.supports()", step.valid ? "true" : "false", !step.valid);
}
if (!step.found) {
expEl.innerHTML = `The variable was not declared in the provided context scope. The browser engine silently ignores this and proceeds to evaluate the next fallback argument in the comma-separated chain.`;
} else if (step.valid) {
expEl.innerHTML = `The variable was found in the execution context and its assigned value is structurally valid for the target property. Resolution stops here.`;
} else {
expEl.innerHTML = `The variable was defined, but its value is fundamentally incompatible with the target CSS property.`;
expEl.innerHTML += `<div class="iacvt-warning"><strong>IACVT Triggered:</strong> Invalid At Computed Value Time. Because the browser cannot guarantee validity during the parse phase for custom properties, it accepts it initially. When it computes the value and realizes it's invalid, it sets the property to <code>unset</code>. <strong>Crucially, it does NOT trigger the next fallback in the var() chain.</strong> The chain completely fails here.</div>`;
}
}
modal.showModal();
}
function renderTrace(trace) {
const track = `<div class="timeline-track"></div>`;
timeline.innerHTML = track;
traceDataStore = trace;
if (trace.length === 0) {
emptyState.style.display = "flex";
timeline.style.display = "none";
return;
}
emptyState.style.display = "none";
timeline.style.display = "flex";
trace.forEach((step, index) => {
const el = document.createElement("div");
let statusClass = "";
let badgeHTML = "";
let messageHTML = "";
if (step.isLiteral) {
statusClass = step.valid ? "is-success" : "is-error";
badgeHTML = step.valid ? `<span class="badge badge-success">APPLIED</span>` : `<span class="badge badge-error">INVALID</span>`;
messageHTML = `Final static fallback evaluated: <code>${escHtml(step.value)}</code>`;
} else {
if (!step.found) {
statusClass = "is-skip";
badgeHTML = `<span class="badge badge-skip">UNDEFINED</span>`;
messageHTML = `Variable missing from context scope. Proceeding to fallback.`;
} else if (step.valid) {
statusClass = "is-success";
badgeHTML = `<span class="badge badge-success">RESOLVED</span>`;
messageHTML = `Successfully computed value: <code>${escHtml(step.value)}</code>`;
} else {
statusClass = "is-error";
badgeHTML = `<span class="badge badge-error">IACVT FAILURE</span>`;
messageHTML = `Found value <code>${escHtml(step.value)}</code> is invalid for this property. Chain execution halted.`;
}
}
el.className = `step-wrapper ${statusClass}`;
el.style.animationDelay = `${index * 0.12}s`;
const title = step.isLiteral ? "Literal Fallback" : escHtml(step.prop);
el.innerHTML = `
<div class="step-indicator"></div>
<div class="step-content">
<div class="step-header">
<span class="var-name">${title}</span>
${badgeHTML}
</div>
<div class="step-message">${messageHTML}</div>
<button class="btn-details" onclick="showModal(${index})">View Diagnostics</button>
</div>
`;
timeline.appendChild(el);
});
}
function process() {
try {
const contextTxt = contextInput.value;
const targetTxt = targetInput.value;
const contextVars = parseContext(contextTxt);
const colonIdx = targetTxt.indexOf(":");
if (colonIdx === -1) throw new Error();
const propName = targetTxt.substring(0, colonIdx).trim();
const propVal = targetTxt
.substring(colonIdx + 1)
.replace(/;$/, "")
.trim();
const ast = parseVarChain(propVal);
const trace = evaluateLogic(ast, contextVars, propName);
renderTrace(trace);
} catch (e) {
timeline.innerHTML = "";
emptyState.style.display = "flex";
timeline.style.display = "none";
}
}
contextInput.addEventListener("input", process);
targetInput.addEventListener("input", process);
window.addEventListener("DOMContentLoaded", process);
</script>
</body>
</html>