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
|
<style>
:host {
height: 100%;
width: 100%;
}
:host([is-selecting-text]) {
cursor: text;
}
#textRenderCanvas {
visibility: hidden;
}
.background-image {
position: absolute;
pointer-events: none;
user-select: none;
z-index: 0;
}
.translated-line,
.word {
cursor: text;
opacity: 0;
pointer-events: all;
position: absolute;
user-select: none;
}
.translated-line {
align-items: center;
display: flex;
flex-wrap: nowrap;
opacity: 100%;
pointer-events: none;
white-space: pre;
z-index: 1;
}
.translated-word {
cursor: text;
pointer-events: all;
user-select: none;
}
:host([debug-mode]) .translated-line {
border: 1px solid orange;
}
:host([debug-mode]) .translated-word {
border: 1px solid teal;
}
:host([debug-mode]) .word {
border: 1px solid blue;
opacity: 50%;
}
:host(:not([should-render-translate-words])) .translated-line,
:host(:not([should-render-translate-words])) .background-image {
display: none;
}
.highlighted-line {
position: absolute;
background-color: var(--color-shader-layer-3);
opacity: 60%;
z-index: 1;
}
/* Set styles for high contrast mode in Windows. */
@media (forced-colors: active) {
.highlighted-line {
/* Set the icon color to hcm (high contrast mode) value. */
background-color: Highlight;
}
}
</style>
<template id="wordsContainer" is="dom-repeat" items="[[renderedWords]]"
index-as="wordIndex">
<div
style$="[[getWordStyle(item, wordIndex, shouldRenderTranslateWords, selectionOverlayRect)]]"
class="word"
on-pointerenter="handlePointerEnter" on-pointerleave="handlePointerLeave">
</div>
</template>
<template id="translateContainer" is="dom-repeat"
items="[[renderedTranslateLines]]" as="translatedLineData"
index-as="lineIndex">
<template is="dom-if" if="[[translatedLineData.line.backgroundImageData]]">
<img class="background-image"
style$="[[getBackgroundImageDataStyle(translatedLineData,selectionOverlayRect)]]"
src="[[getBlobUrlFromImageData(translatedLineData.line.backgroundImageData)]]">
</template>
<div
style$="[[getTranslatedLineStyle(translatedLineData,selectionOverlayRect)]]"
class="translated-line">
<template is="dom-repeat" items="[[translatedLineData.words]]"
as="translatedWordData" index-as="wordIndex">
<span class="translated-word"
data-line-index$="[[lineIndex]]"
data-word-index$="[[translatedWordData.index]]"
lang$="[[currentTranslateLanguage]]">[[translatedWordData.word.plainText]][[translatedWordData.word.textSeparator]]</span>
</template>
</div>
</template>
<template is="dom-repeat" items="[[highlightedLines]]">
<div style$="[[getHighlightedLineStyle(item)]]" class="highlighted-line">
</div>
</template>
<canvas id="textRenderCanvas"></canvas>
|