Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make wavy underline markings smaller #4989

Merged
merged 6 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { customElement, property } from "lit/decorators.js";
import { html, LitElement, TemplateResult } from "lit";
import { css, html, LitElement, TemplateResult, CSSResultGroup } from "lit";
import {
Annotation,
compareAnnotationOrders,
Expand All @@ -19,37 +19,46 @@ import { StateController } from "state/state_system/StateController";
export class AnnotationMarker extends LitElement {
@property({ type: Array })
annotations: Annotation[];
@property({ type: Boolean, attribute: "full-width" })
fullWidth = false;

state = new StateController(this);

static get styles(): CSSResultGroup {
// order matters here, the last defined class determines the color if multiple apply
return css`
.info, .warning, .error,
.info-intense, .warning-intense, .error-intense {
background-position: left bottom;
background-repeat: repeat-x;
}
.info { background-image: var(--d-annotation-info-background) }
.warning { background-image: var(--d-annotation-warning-background) }
.error { background-image: var(--d-annotation-error-background) }
.info-intense { background-image: var(--d-annotation-info-background-intense) }
.warning-intense { background-image: var(--d-annotation-warning-background-intense) }
.error-intense { background-image: var(--d-annotation-error-background-intense) }
.annotation { background-color: var(--annotation-color) }
.question { background-color: var(--question-color) }
.annotation-intense { background-color: var(--annotation-intense-color) }
.question-intense { background-color: var(--question-intense-color) }
`;
}

static getClass(annotation: Annotation): string {
return annotation.isHovered ? `${annotation.type}-intense` : annotation.type;
}

static colors = {
"error": "var(--error-color, red)",
"warning": "var(--warning-color, yellow)",
"info": "var(--info-color, blue)",
"error": "var(--d-annotation-error, red)",
"warning": "var(--d-annotation-warning, yellow)",
"info": "var(--d-annotation-info, blue)",
"annotation": "var(--annotation-color, green)",
"question": "var(--question-color, orange)",
"annotation-intense": "var(--annotation-intense-color, green)",
"question-intense": "var(--question-intense-color, orange)",
};

static getStyle(annotation: Annotation): string {
if (["error", "warning", "info"].includes(annotation.type)) {
// shorthand notation does not work in safari
return `
text-decoration-line: underline;
text-decoration-color: ${AnnotationMarker.colors[annotation.type]};
text-decoration-thickness: ${annotation.isHovered ? 2 : 1}px;
text-decoration-style: wavy;
text-decoration-skip-ink: none;
`;
} else {
const key = annotation.isHovered ? `${annotation.type}-intense` : annotation.type;
return `
background: ${AnnotationMarker.colors[key]};
`;
}
}

/**
* Returns the annotations sorted in order of importance.
* Hovered annotations are prioritized over non-hovered annotations.
Expand Down Expand Up @@ -79,16 +88,11 @@ export class AnnotationMarker extends LitElement {
</svg>`;
}

get annotationStyles(): string {
return this.sortedAnnotations.reverse().map(a => AnnotationMarker.getStyle(a)).join(" ");
get annotationClasses(): string {
return this.annotations.map(a => AnnotationMarker.getClass(a)).join(" ");
}

render(): TemplateResult {
return html`<style>
:host {
position: relative;
${this.annotationStyles}
}
</style><slot>${this.machineAnnotationMarkerSVG}</slot>`;
return html`<span class="${this.annotationClasses} ${this.fullWidth ? "full-width" : ""}"><slot>${this.machineAnnotationMarkerSVG}</slot></span>`;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ export class LineOfCode extends ShadowlessLitElement {
return html`
<div class="code-layers">
${ this.fullLineAnnotations.length > 0 ? html`
<d-annotation-marker style="width: 100%; display: block" .annotations=${this.fullLineAnnotations}>
<d-annotation-marker full-width="true" .annotations=${this.fullLineAnnotations}>
<pre class="code-line background-layer"><span></span>${backgroundLayer}</pre>
</d-annotation-marker>` : html`
<pre class="code-line background-layer">${backgroundLayer}</pre>
Expand Down
2 changes: 1 addition & 1 deletion app/assets/stylesheets/base.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
@import "../../../node_modules/bootstrap/scss/functions";

// 2. Include any default variable overrides here
@import "mixins.css.scss";
@import "theme/m3-theme-light.css.scss";
@import "theme/m3-theme-dark.css.scss";
@import "bootstrap_variable_overrides.css.scss";
@import "mixins.css.scss";
@import "theme/rouge.css.scss";
@import "theme/ace.css.scss";

Expand Down
3 changes: 0 additions & 3 deletions app/assets/stylesheets/components/code_listing.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -527,9 +527,6 @@

d-annotation-marker,
d-selection-marker {
--info-color: var(--d-annotation-info);
--warning-color: var(--d-annotation-warning);
--error-color: var(--d-annotation-error);
--question-color: var(--d-annotation-question-background);
--annotation-color: var(--d-annotation-user-background);
--question-intense-color: var(--d-annotation-question-background-intense);
Expand Down
10 changes: 10 additions & 0 deletions app/assets/stylesheets/mixins.css.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
@use "sass:string";
@use "sass:color";

@mixin shadow-z0 {
box-shadow: none;
}
Expand Down Expand Up @@ -27,3 +30,10 @@
0 16px 24px 2px rgba(0, 0, 0, 0.098),
0 6px 30px 5px rgba(0, 0, 0, 0.084);
}

// sets the variable equal to the url of a wavy svg with the specified color and stroke-width
@mixin wavy-underline($variable, $color, $stroke-width) {
// this is a custom wavy svg that can be used as a background image
// the color is slightly hacked to get a proper url encode version of the color
#{$variable}: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="6" height="3">%3Cpath%20d%3D%22m0%202.5%20l2%20-1.5%20l1%200%20l2%201.5%20l1%200%22%20stroke%3D%22%23#{string.slice(color.ie-hex-str($color), 4)}%22%20fill%3D%22none%22%20stroke-width%3D%22#{$stroke-width}%22%2F%3E</svg>');
}
7 changes: 7 additions & 0 deletions app/assets/stylesheets/theme/m3-theme-dark.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,13 @@
--d-annotation-question-background-intense: #{color.mix($purple-80, $neutral-25, 20%)};
--d-annotation-user-background-intense: #{color.mix($success-70, $neutral-25, 20%)};

@include wavy-underline(--d-annotation-warning-background, $warning-80, 0.7);
@include wavy-underline(--d-annotation-warning-background-intense, $warning-80, 1.7);
@include wavy-underline(--d-annotation-error-background, $danger-70, 0.7);
@include wavy-underline(--d-annotation-error-background-intense, $danger-70, 1.7);
@include wavy-underline(--d-annotation-info-background, $info-80, 0.7);
@include wavy-underline(--d-annotation-info-background-intense, $info-80, 1.7);

.image-bright {
// $gray-90 converted to filter using https://codepen.io/sosuke/pen/Pjoqqp
filter: invert(86%) sepia(3%) saturate(218%) hue-rotate(242deg) brightness(107%) contrast(90%);
Expand Down
8 changes: 8 additions & 0 deletions app/assets/stylesheets/theme/m3-theme-light.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

@use "sass:color";
@import "theme/m3-theme.css.scss";
@import "mixins.css.scss";

:root,
[data-bs-theme="light"] {
Expand Down Expand Up @@ -217,6 +218,13 @@
--d-annotation-question-background-intense: #{color.mix($purple-40, $neutral-98, 20%)};
--d-annotation-user-background-intense: #{color.mix($success-60, $neutral-98, 20%)};

@include wavy-underline(--d-annotation-warning-background, $warning-70, 0.7);
@include wavy-underline(--d-annotation-warning-background-intense, $warning-70, 1.7);
@include wavy-underline(--d-annotation-error-background, $danger-60, 0.7);
@include wavy-underline(--d-annotation-error-background-intense, $danger-60, 1.7);
@include wavy-underline(--d-annotation-info-background, $info-40, 0.7);
@include wavy-underline(--d-annotation-info-background-intense, $info-40, 1.7);

.image-bright {
// $gray-10 converted to filter using https://codepen.io/sosuke/pen/Pjoqqp
filter: invert(8%) sepia(10%) saturate(679%) hue-rotate(201deg) brightness(93%) contrast(92%);
Expand Down
Loading