This repository has been archived by the owner on Feb 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add preliminary page inspector
- Loading branch information
Showing
13 changed files
with
1,624 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
partials: | ||
- partial: hero | ||
title: Hello World 1! | ||
image: | ||
url: 'data:image/gif;base64,R0lGODlhEAAOALMAAOazToeHh0tLS/7LZv/0jvb29t/f3//Ub//ge8WSLf/rhf/3kdbW1mxsbP//mf///yH5BAAAAAAALAAAAAAQAA4AAARe8L1Ekyky67QZ1hLnjM5UUde0ECwLJoExKcppV0aCcGCmTIHEIUEqjgaORCMxIC6e0CcguWw6aFjsVMkkIr7g77ZKPJjPZqIyd7sJAgVGoEGv2xsBxqNgYPj/gAwXEQA7' | ||
alt: 'Alt text' | ||
- partial: hero | ||
title: Hello World 2! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
<div class="hero"> | ||
<h1>{{partial.title}}</h1> | ||
{% if partial.image %} | ||
<img src="{{partial.image.url}}" alt="{{partial.image.alt}}"> | ||
{% endif %} | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import * as dom from '@blinkk/degu/lib/dom/dom'; | ||
import * as func from '@blinkk/degu/lib/func/func'; | ||
|
||
import {LitElement, css, html} from 'lit'; | ||
|
||
import {AttributeHighlighter as DeguAttributeHighlighter} from '@blinkk/degu/lib/ui/attribute-highlighter'; | ||
import {customElement} from 'lit/decorators.js'; | ||
|
||
// Adds required styles to page only ever once. | ||
const addStylesToPage = func.runOnlyOnce(() => { | ||
dom.addStylesToPage(` | ||
.attribute-highlighter { | ||
align-items: left; | ||
color: #FFF; | ||
background: #000; | ||
border-radius: 3px; | ||
box-shadow: none !important; | ||
display: flex; | ||
flex-direction: column; | ||
font-size: 11px; | ||
height: auto; | ||
justify-content: center; | ||
left: var(--left); | ||
margin: 0 !important; | ||
max-width: var(--max-width); | ||
padding: 0px 8px; | ||
position: fixed !important; | ||
// Slight off center. | ||
top: calc(var(--center) + 10px); | ||
transform: translateX(-50%) translateY(0%); | ||
transition: transform 0.3s ease; | ||
transform-origin: top center; | ||
z-index: 9999; | ||
cursor: pointer; | ||
} | ||
.attribute-highlighter span { | ||
display: block; | ||
} | ||
.attribute-highlighter.active, | ||
.attribute-highlighter:active, { | ||
z-index: 10000; | ||
transform: translateX(-50%) translateY(0%) scale(1.2); | ||
} | ||
.attribute-highlighter:hover { | ||
cursor: pointer; | ||
z-index: 10000; | ||
} | ||
.attribute-highlighter.up { | ||
top: calc(var(--center) - 10px + (var(--height) * -1)); | ||
} | ||
`); | ||
}); | ||
|
||
@customElement('attribute-highlighter') | ||
export class AttributeHighlighter extends LitElement { | ||
private attributeHighlighter?: DeguAttributeHighlighter; | ||
private show = false; | ||
connectedCallback() { | ||
super.connectedCallback(); | ||
|
||
// Add styles to page. | ||
addStylesToPage(); | ||
|
||
document.addEventListener('keydown', (e: KeyboardEvent) => { | ||
if (e.ctrlKey && e.key === 'a') { | ||
this.toggleA11yHighlight(); | ||
} | ||
}); | ||
} | ||
|
||
private toggleA11yHighlight() { | ||
this.show = !this.show; | ||
if (this.show) { | ||
this.attributeHighlighter = new DeguAttributeHighlighter({ | ||
cssClassName: 'attribute-highlighter', | ||
scopeQuerySelector: 'page-module', | ||
attributes: ['alt', 'aria-label'], | ||
warnMissingAttributes: [ | ||
{ | ||
attribute: 'alt', | ||
querySelector: 'img', | ||
}, | ||
], | ||
}); | ||
this.attributeHighlighter.refresh(); | ||
} else { | ||
this.attributeHighlighter?.dispose(); | ||
} | ||
} | ||
|
||
createRenderRoot() { | ||
return this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,182 @@ | ||
import {LitElement, css, html} from 'lit'; | ||
|
||
import {customElement} from 'lit/decorators.js'; | ||
|
||
@customElement('grid-inspector') | ||
export class GridInspector extends LitElement { | ||
connectedCallback() { | ||
super.connectedCallback(); | ||
// Enable toggling the grid overlay using `ctrl+g` (similar to Figma). | ||
document.addEventListener('keydown', (e: KeyboardEvent) => { | ||
if (e.ctrlKey && e.key === 'g') { | ||
this.toggleGridOverlay(); | ||
} | ||
}); | ||
} | ||
|
||
private toggleGridOverlay() { | ||
this.style.display = this.style.display === 'none' ? 'block' : 'none'; | ||
} | ||
|
||
static get styles() { | ||
return css` | ||
:host { | ||
display:none | ||
} | ||
.page-grid-overlay { | ||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji'; | ||
font-size: 12px; | ||
font-weight: 500; | ||
color:#000; | ||
font-optical-sizing:none; | ||
font-size:14px; | ||
font-weight:500; | ||
height:100vh; | ||
left:0; | ||
letter-spacing:.25px; | ||
line-height:20px; | ||
pointer-events:none; | ||
position:fixed; | ||
top:0; | ||
width:100%; | ||
z-index:2000; | ||
} | ||
.page-grid-overlay * { | ||
box-sizing:border-box | ||
} | ||
.page-grid-overlay .page-grid__label { | ||
display:none; | ||
margin-top:42px; | ||
margin-left:8px; | ||
padding:0 8px; | ||
background:#ebffff; | ||
position:absolute; | ||
text-align:left | ||
} | ||
.page-grid-overlay .opt--mobile::before { | ||
content:"Mobile (320 - 599px)" | ||
} | ||
@media(max-width: 599px) { | ||
.page-grid-overlay .opt--mobile { | ||
display:block | ||
} | ||
} | ||
.page-grid-overlay .opt--ds-tablet::before { | ||
content:"Tablet (600 - 1023px)" | ||
} | ||
@media(min-width: 600px)and (max-width: 1023px) { | ||
.page-grid-overlay .opt--ds-tablet { | ||
display:block | ||
} | ||
} | ||
.page-grid-overlay .opt--ds-laptop::before { | ||
content:"Laptop (1024 - 1439px)" | ||
} | ||
@media(min-width: 1024px)and (max-width: 1439px) { | ||
.page-grid-overlay .opt--ds-laptop { | ||
display:block | ||
} | ||
} | ||
.page-grid-overlay .opt--ds-desktop::before { | ||
content:"Desktop (1440px)" | ||
} | ||
@media(min-width: 1440px) { | ||
.page-grid-overlay .opt--ds-desktop { | ||
display:block | ||
} | ||
} | ||
.page-grid-overlay .page-grid { | ||
display:grid; | ||
-webkit-column-gap:24px; | ||
-moz-column-gap:24px; | ||
column-gap:24px; | ||
counter-reset:column; | ||
height:100% | ||
} | ||
@media(max-width: 599px) { | ||
.page-grid-overlay .page-grid { | ||
grid-template-columns:repeat(4, 1fr); | ||
padding:0 16px | ||
} | ||
} | ||
@media(min-width: 600px)and (max-width: 1023px) { | ||
.page-grid-overlay .page-grid { | ||
grid-template-columns:repeat(12, 1fr); | ||
margin-left:auto; | ||
margin-right:auto; | ||
max-width:600px; | ||
padding:0 24px | ||
} | ||
} | ||
@media(min-width: 1024px)and (max-width: 1439px) { | ||
.page-grid-overlay .page-grid { | ||
grid-template-columns:repeat(12, 1fr); | ||
padding:0 24px | ||
} | ||
} | ||
@media(min-width: 1440px) { | ||
.page-grid-overlay .page-grid { | ||
grid-template-columns:repeat(12, 1fr); | ||
margin-left:auto; | ||
margin-right:auto; | ||
max-width:1440px; | ||
padding:0 24px | ||
} | ||
} | ||
@media(max-width: 599px) { | ||
.page-grid-overlay .page-grid>* { | ||
grid-column-end:span 4 | ||
} | ||
} | ||
@media(min-width: 600px) { | ||
.page-grid-overlay .page-grid>* { | ||
grid-column-end:span 12 | ||
} | ||
} | ||
[page-grid-overlay=true] .page-grid-overlay .page-grid>* { | ||
box-shadow:inset 0 0 0 1px orchid | ||
} | ||
.page-grid-overlay .page-grid__col { | ||
grid-column-end:span 1; | ||
background-color:rgba(0,255,255,.08); | ||
height:100%; | ||
padding-top:12px; | ||
text-align:center | ||
} | ||
.page-grid-overlay .page-grid__col::before { | ||
counter-increment:column; | ||
content:counter(column) | ||
} | ||
@media(max-width: 599px) { | ||
.page-grid-overlay .page-grid__col:nth-child(5),.page-grid-overlay .page-grid__col:nth-child(6),.page-grid-overlay .page-grid__col:nth-child(7),.page-grid-overlay .page-grid__col:nth-child(8),.page-grid-overlay .page-grid__col:nth-child(9),.page-grid-overlay .page-grid__col:nth-child(10),.page-grid-overlay .page-grid__col:nth-child(11),.page-grid-overlay .page-grid__col:nth-child(12) { | ||
display:none | ||
} | ||
} | ||
`; | ||
} | ||
|
||
render() { | ||
return html` | ||
<div class="page-grid-overlay"> | ||
<div class="page-grid"> | ||
<div class="page-grid__label opt--mobile"></div> | ||
<div class="page-grid__label opt--ds-tablet"></div> | ||
<div class="page-grid__label opt--ds-laptop"></div> | ||
<div class="page-grid__label opt--ds-desktop"></div> | ||
<div class="page-grid__col"></div> | ||
<div class="page-grid__col"></div> | ||
<div class="page-grid__col"></div> | ||
<div class="page-grid__col"></div> | ||
<div class="page-grid__col"></div> | ||
<div class="page-grid__col"></div> | ||
<div class="page-grid__col"></div> | ||
<div class="page-grid__col"></div> | ||
<div class="page-grid__col"></div> | ||
<div class="page-grid__col"></div> | ||
<div class="page-grid__col"></div> | ||
<div class="page-grid__col"></div> | ||
</div> | ||
</div> | ||
`; | ||
} | ||
} |
Oops, something went wrong.