|
1 | 1 | import $ from 'blingblingjs' |
2 | 2 | import { Metatip } from './metatip.element.js' |
3 | | -import { TinyColor } from '@ctrl/tinycolor' |
| 3 | +import { preferredNotation } from '../../features/color.js' |
4 | 4 | import { draggable } from '../../features/' |
5 | 5 | import { getStyle, getComputedBackgroundColor } from '../../utilities' |
6 | | -import { getContrastingColor } from '../../utilities' |
7 | | -import { functionalNotate } from '../../features/color.js' |
8 | | - |
9 | | -const modemap = { |
10 | | - 'hex': 'toHexString', |
11 | | - 'hsl': 'toHslString', |
12 | | - 'rgb': 'toRgbString', |
13 | | -} |
| 6 | +import { contrast_color } from '../../utilities' |
14 | 7 |
|
15 | 8 | export class Ally extends Metatip { |
16 | 9 | constructor() { |
@@ -44,43 +37,45 @@ export class Ally extends Metatip { |
44 | 37 | } |
45 | 38 |
|
46 | 39 | render({el, ally_attributes, contrast_results}) { |
47 | | - const colormode = modemap[$('vis-bug').attr('color-mode')] |
| 40 | + const colormode = $('vis-bug').attr('color-mode') |
48 | 41 |
|
49 | 42 | const foreground = el instanceof SVGElement |
50 | 43 | ? (getStyle(el, 'fill') || getStyle(el, 'stroke')) |
51 | 44 | : getStyle(el, 'color') |
52 | 45 | const background = getComputedBackgroundColor(el) |
53 | 46 |
|
54 | | - const contrastingForegroundColor = getContrastingColor(foreground) |
55 | | - const contrastingBackgroundColor = getContrastingColor(background) |
| 47 | + const contrastingForegroundColor = contrast_color(foreground) |
| 48 | + const contrastingBackgroundColor = contrast_color(background) |
56 | 49 |
|
57 | 50 | this.style.setProperty('--copy-message-left-color', contrastingForegroundColor) |
58 | 51 | this.style.setProperty('--copy-message-right-color', contrastingBackgroundColor) |
59 | 52 |
|
60 | 53 | return ` |
61 | | - <figure> |
| 54 | + <figure visbug-ally> |
62 | 55 | <header> |
63 | 56 | <h5><${el.nodeName.toLowerCase()}>${el.id && '#' + el.id}</h5> |
64 | 57 | </header> |
65 | | - <div color-swatches> |
66 | | - <span color-swatch style="background-color:${foreground};" tabindex="0"> |
67 | | - <small style="color:${contrastingForegroundColor};"> |
68 | | - Foreground |
69 | | - </small> |
70 | | - <span style="color:${contrastingForegroundColor};"> |
71 | | - ${functionalNotate(new TinyColor(foreground)[colormode]())} |
| 58 | + <section> |
| 59 | + <div color-swatches> |
| 60 | + <span color-swatch style="background-color:${foreground};" tabindex="0"> |
| 61 | + <small style="color:${contrastingForegroundColor};"> |
| 62 | + Foreground |
| 63 | + </small> |
| 64 | + <span style="color:${contrastingForegroundColor};"> |
| 65 | + ${preferredNotation(foreground, colormode)} |
| 66 | + </span> |
72 | 67 | </span> |
73 | | - </span> |
74 | | - <span color-swatch style="background-color:${background};" tabindex="0"> |
75 | | - <small style="color:${contrastingBackgroundColor};"> |
76 | | - Background |
77 | | - </small> |
78 | | - <span style="color:${contrastingBackgroundColor};"> |
79 | | - ${functionalNotate(new TinyColor(background)[colormode]())} |
| 68 | + <span color-swatch style="background-color:${background};" tabindex="0"> |
| 69 | + <small style="color:${contrastingBackgroundColor};"> |
| 70 | + Background |
| 71 | + </small> |
| 72 | + <span style="color:${contrastingBackgroundColor};"> |
| 73 | + ${preferredNotation(background, colormode)} |
| 74 | + </span> |
80 | 75 | </span> |
81 | | - </span> |
82 | | - </div> |
83 | | - ${contrast_results} |
| 76 | + </div> |
| 77 | + ${contrast_results} |
| 78 | + </section> |
84 | 79 | ${ally_attributes.length > 0 |
85 | 80 | ? `<code accessibility> |
86 | 81 | <div> |
|
0 commit comments