Skip to content

Commit 99bb67a

Browse files
committed
shadow dom for bar [WIP]
1 parent fd5b797 commit 99bb67a

File tree

3 files changed

+136
-322
lines changed

3 files changed

+136
-322
lines changed

src/Tracy/Bar/assets/bar.css

Lines changed: 41 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -12,63 +12,64 @@ body#tracy-debug { /* in popup window */
1212
display: block;
1313
}
1414

15-
#tracy-debug:not(body) {
15+
:host {
1616
position: absolute;
1717
left: 0;
1818
top: 0;
19+
margin: 0;
1920
}
2021

21-
#tracy-debug a {
22+
a {
2223
color: #125EAE;
2324
text-decoration: none;
2425
}
2526

26-
#tracy-debug a:hover,
27-
#tracy-debug a:focus {
27+
a:hover,
28+
a:focus {
2829
background-color: #125EAE;
2930
color: white;
3031
}
3132

32-
#tracy-debug h2,
33-
#tracy-debug h3,
34-
#tracy-debug p {
33+
h2,
34+
h3,
35+
p {
3536
margin: .4em 0;
3637
}
3738

38-
#tracy-debug table {
39+
table {
3940
background: #FDF5CE;
4041
width: 100%;
4142
}
4243

43-
#tracy-debug tr:nth-child(2n) td {
44+
tr:nth-child(2n) td {
4445
background: rgba(0, 0, 0, 0.02);
4546
}
4647

47-
#tracy-debug td,
48-
#tracy-debug th {
48+
td,
49+
th {
4950
border: 1px solid #E6DFBF;
5051
padding: 2px 5px;
5152
vertical-align: top;
5253
text-align: left;
5354
}
5455

55-
#tracy-debug th {
56+
th {
5657
background: #F4F3F1;
5758
color: #655E5E;
5859
font-size: 90%;
5960
font-weight: bold;
6061
}
6162

62-
#tracy-debug pre,
63-
#tracy-debug code {
63+
pre,
64+
code {
6465
font: 9pt/1.5 Consolas, monospace;
6566
}
6667

67-
#tracy-debug table .tracy-right {
68+
table .tracy-right {
6869
text-align: right;
6970
}
7071

71-
#tracy-debug svg {
72+
svg {
7273
display: inline;
7374
}
7475

@@ -168,49 +169,49 @@ body#tracy-debug { /* in popup window */
168169

169170

170171
/* panels */
171-
#tracy-debug .tracy-panel {
172+
.tracy-panel {
172173
display: none;
173174
font: normal normal 12px/1.5 sans-serif;
174175
background: white;
175176
color: #333;
176177
text-align: left;
177178
}
178179

179-
body#tracy-debug .tracy-panel { /* in popup window */
180+
body.tracy-panel { /* in popup window */
180181
display: block;
181182
}
182183

183-
#tracy-debug h1 {
184+
h1 {
184185
font: normal normal 23px/1.4 Tahoma, sans-serif;
185186
color: #575753;
186187
margin: -5px -5px 5px;
187188
padding: 0 5px 0 5px;
188189
word-wrap: break-word;
189190
}
190191

191-
#tracy-debug .tracy-inner {
192+
.tracy-inner {
192193
overflow: auto;
193194
flex: 1;
194195
}
195196

196-
#tracy-debug .tracy-panel .tracy-icons {
197+
.tracy-panel .tracy-icons {
197198
display: none;
198199
}
199200

200-
#tracy-debug .tracy-panel-ajax h1::after,
201-
#tracy-debug .tracy-panel-redirect h1::after {
201+
.tracy-panel-ajax h1::after,
202+
.tracy-panel-redirect h1::after {
202203
content: 'ajax';
203204
float: right;
204205
font-size: 65%;
205206
margin: 0 .3em;
206207
}
207208

208-
#tracy-debug .tracy-panel-redirect h1::after {
209+
.tracy-panel-redirect h1::after {
209210
content: 'redirect';
210211
}
211212

212-
#tracy-debug .tracy-mode-peek,
213-
#tracy-debug .tracy-mode-float {
213+
.tracy-mode-peek,
214+
.tracy-mode-float {
214215
position: fixed;
215216
flex-direction: column;
216217
padding: 10px;
@@ -221,24 +222,24 @@ body#tracy-debug .tracy-panel { /* in popup window */
221222
border: 1px solid rgba(0, 0, 0, 0.1);
222223
}
223224

224-
#tracy-debug .tracy-mode-peek,
225-
#tracy-debug .tracy-mode-float:not(.tracy-panel-resized) {
225+
.tracy-mode-peek,
226+
.tracy-mode-float:not(.tracy-panel-resized) {
226227
max-width: 700px;
227228
max-height: 500px;
228229
}
229230

230231
@media (max-height: 555px) {
231-
#tracy-debug .tracy-mode-peek,
232-
#tracy-debug .tracy-mode-float:not(.tracy-panel-resized) {
232+
.tracy-mode-peek,
233+
.tracy-mode-float:not(.tracy-panel-resized) {
233234
max-height: 100vh;
234235
}
235236
}
236237

237-
#tracy-debug .tracy-mode-peek h1 {
238+
.tracy-mode-peek h1 {
238239
cursor: move;
239240
}
240241

241-
#tracy-debug .tracy-mode-float {
242+
.tracy-mode-float {
242243
display: flex;
243244
opacity: .95;
244245
transition: opacity 0.2s;
@@ -247,45 +248,45 @@ body#tracy-debug .tracy-panel { /* in popup window */
247248
resize: both;
248249
}
249250

250-
#tracy-debug .tracy-focused {
251+
.tracy-focused {
251252
display: flex;
252253
opacity: 1;
253254
transition: opacity 0.1s;
254255
}
255256

256-
#tracy-debug .tracy-mode-float h1 {
257+
.tracy-mode-float h1 {
257258
cursor: move;
258259
padding-right: 25px;
259260
}
260261

261-
#tracy-debug .tracy-mode-float .tracy-icons {
262+
.tracy-mode-float .tracy-icons {
262263
display: block;
263264
position: absolute;
264265
top: 0;
265266
right: 5px;
266267
font-size: 18px;
267268
}
268269

269-
#tracy-debug .tracy-mode-window {
270+
.tracy-mode-window {
270271
padding: 10px;
271272
}
272273

273-
#tracy-debug .tracy-icons a {
274+
.tracy-icons a {
274275
color: #575753;
275276
}
276277

277-
#tracy-debug .tracy-icons a:hover {
278+
.tracy-icons a:hover {
278279
color: white;
279280
}
280281

281282

282-
#tracy-debug .tracy-inner-container {
283+
.tracy-inner-container {
283284
min-width: 100%;
284285
float: left;
285286
}
286287

287288
@media print {
288-
#tracy-debug * {
289+
* {
289290
display: none;
290291
}
291292
}

src/Tracy/Bar/assets/bar.js

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44

55
let requestId = document.currentScript.dataset.id,
66
ajaxCounter = 1,
7-
baseUrl = location.href.split('#')[0];
7+
baseUrl = location.href.split('#')[0],
8+
root;
89

910
baseUrl += (baseUrl.indexOf('?') < 0 ? '?' : '&');
1011

@@ -24,7 +25,7 @@ class Panel
2425
{
2526
constructor(id) {
2627
this.id = id;
27-
this.elem = document.getElementById(this.id);
28+
this.elem = root.getElementById(this.id);
2829
this.elem.Tracy = this.elem.Tracy || {};
2930
}
3031

@@ -34,7 +35,7 @@ class Panel
3435

3536
this.init = function() {};
3637
elem.innerHTML = elem.dataset.tracyContent;
37-
Tracy.Dumper.init(Debug.layer);
38+
Tracy.Dumper.init(root);
3839
evalScripts(elem);
3940

4041
draggable(elem, {
@@ -248,7 +249,7 @@ class Bar
248249
{
249250
init() {
250251
this.id = 'tracy-debug-bar';
251-
this.elem = document.getElementById(this.id);
252+
this.elem = root.getElementById(this.id);
252253

253254
draggable(this.elem, {
254255
handles: this.elem.querySelectorAll('li:first-child'),
@@ -352,7 +353,7 @@ class Bar
352353

353354

354355
close() {
355-
document.getElementById('tracy-debug').style.display = 'none';
356+
root.getElementById('tracy-debug').style.display = 'none';
356357
}
357358

358359

@@ -392,15 +393,16 @@ class Debug
392393
static init(content) {
393394
Debug.bar = new Bar;
394395
Debug.panels = {};
395-
Debug.layer = document.createElement('tracy-div');
396-
Debug.layer.setAttribute('id', 'tracy-debug');
397-
Debug.layer.innerHTML = content;
396+
Debug.layer = document.createElement('tracy-debug');
397+
root = Debug.layer.shadowRoot;
398+
root.innerHTML = content;
399+
root.appendChild(document.querySelector('style.tracy-debug'));
398400
(document.body || document.documentElement).appendChild(Debug.layer);
399-
evalScripts(Debug.layer);
401+
evalScripts(root);
400402
Debug.layer.style.display = 'block';
401403
Debug.bar.init();
402404

403-
Debug.layer.querySelectorAll('.tracy-panel').forEach((panel) => {
405+
root.querySelectorAll('.tracy-panel').forEach((panel) => {
404406
Debug.panels[panel.id] = new Panel(panel.id);
405407
Debug.panels[panel.id].restorePosition();
406408
});
@@ -437,12 +439,12 @@ class Debug
437439
});
438440
}
439441

440-
Debug.layer.insertAdjacentHTML('beforeend', content.panels);
441-
evalScripts(Debug.layer);
442+
root.insertAdjacentHTML('beforeend', content.panels);
443+
evalScripts(root);
442444
Debug.bar.elem.insertAdjacentHTML('beforeend', content.bar);
443445
let ajaxBar = Debug.bar.elem.querySelector('.tracy-row:last-child');
444446

445-
Debug.layer.querySelectorAll('.tracy-panel').forEach((panel) => {
447+
root.querySelectorAll('.tracy-panel').forEach((panel) => {
446448
if (!Debug.panels[panel.id]) {
447449
Debug.panels[panel.id] = new Panel(panel.id);
448450
Debug.panels[panel.id].restorePosition();
@@ -675,6 +677,16 @@ function getPosition(elem) {
675677
}
676678

677679

680+
class TracyDebugElement extends HTMLElement {
681+
constructor() {
682+
super();
683+
this.attachShadow({mode: 'open'});
684+
}
685+
}
686+
687+
window.customElements.define('tracy-debug', TracyDebugElement);
688+
689+
678690
let Tracy = window.Tracy = window.Tracy || {};
679691
Tracy.DebugPanel = Panel;
680692
Tracy.DebugBar = Bar;

0 commit comments

Comments
 (0)