Skip to content

Commit 9f55cde

Browse files
authored
Codec-Compare version 0.5.3 (#26)
Display the constants-table-ui component when selecting a match. Display a copy-to-clipboard button next to each command line constant.
1 parent 7163490 commit 9f55cde

7 files changed

Lines changed: 104 additions & 17 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## v0.5.3
4+
5+
- Display the constants-table-ui component when selecting a match.
6+
- Display a copy-to-clipboard button next to each command line constant.
7+
38
## v0.5.2
49

510
- Replace placeholder comparison presets by generic resource links.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "codec_compare",
3-
"version": "0.5.2",
3+
"version": "0.5.3",
44
"description": "Codec performance comparison tool",
55
"publisher": "Google LLC",
66
"author": "Yannis Guyon",
@@ -35,6 +35,7 @@
3535
"@material/mwc-linear-progress": "^0.27.0",
3636
"@material/mwc-menu": "^0.27.0",
3737
"@material/mwc-slider": "^0.27.0",
38+
"@material/mwc-snackbar": "^0.27.0",
3839
"@material/mwc-switch": "^0.27.0",
3940
"@material/mwc-tab": "^0.27.0",
4041
"@material/mwc-tab-bar": "^0.27.0",

src/batch_selection_actions_ui.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,6 @@ export class BatchSelectionActionsUi extends LitElement {
6666
}
6767

6868
static override styles = css`
69-
a {
70-
text-decoration: none;
71-
}
7269
mwc-icon-button {
7370
color: var(--mdc-theme-text);
7471
/* Make the background disk that appears when hovered slightly bigger

src/codec_compare.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ export class CodecCompare extends LitElement {
204204
</p>
205205
206206
<p id="credits">
207-
Codec Compare version 0.5.2<br>
207+
Codec Compare version 0.5.3<br>
208208
<a href="https://github.com/webmproject/codec-compare">
209209
Sources on GitHub
210210
</a>

src/constants_table_ui.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
// limitations under the License.
1414

1515
import './batch_name_ui';
16+
import './copy_button';
1617

1718
import {css, html, LitElement} from 'lit';
1819
import {customElement, property} from 'lit/decorators.js';
@@ -28,12 +29,12 @@ import {Batch, Constant, FieldId} from './entry';
2829
@customElement('constants-table-ui')
2930
export class ConstantsTableUi extends LitElement {
3031
@property({attribute: false}) batch?: Batch;
31-
@property({attribute: false}) rowIndex = -1;
32+
@property({attribute: false}) rowIndex: number|undefined = undefined;
3233

3334
private renderConstant(
3435
batch: Batch, constant: Constant, showDescriptionAsTitle: boolean,
3536
constantValue: string) {
36-
// Already displayed by parent component BatchUi.
37+
// Already displayed by a parent component.
3738
if (constant.id === FieldId.BATCH_NAME) return html``;
3839

3940
// Save screen space by hiding some fields that can be found elsewhere.
@@ -43,6 +44,12 @@ export class ConstantsTableUi extends LitElement {
4344
if (constant.id === FieldId.DECODED_IMAGE_PATH) return html``;
4445
if (constant.id === FieldId.PREVIEW_PATH) return html``;
4546

47+
const trailingElements =
48+
constant.displayName.toLowerCase().endsWith('command') ?
49+
html`<copy-button .textToCopyInClipboard=${
50+
constantValue}></copy-button>` :
51+
html``;
52+
4653
return html`
4754
<tr>
4855
${
@@ -52,8 +59,9 @@ export class ConstantsTableUi extends LitElement {
5259
<th>${constant.displayName}</th>
5360
<td class="description">${constant.description}</td>`}
5461
${
55-
constant.id === FieldId.DATE ? html`<td>${batch.timeStringLong}</td>` :
56-
html`<td>${constantValue}</td>`}
62+
constant.id === FieldId.DATE ?
63+
html`<td>${batch.timeStringLong}</td>` :
64+
html`<td>${constantValue}${trailingElements}</td>`}
5765
</tr>`;
5866
}
5967

@@ -62,7 +70,7 @@ export class ConstantsTableUi extends LitElement {
6270

6371
let constantValues: string[];
6472
let showDescriptionAsTitle: boolean;
65-
if (this.rowIndex === -1) {
73+
if (this.rowIndex === undefined) {
6674
constantValues = [];
6775
for (const constant of this.batch.constants) {
6876
constantValues.push(constant.value);

src/copy_button.ts

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// Copyright 2025 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
import '@material/mwc-icon-button';
16+
import '@material/mwc-snackbar';
17+
18+
import {Snackbar} from '@material/mwc-snackbar';
19+
import {css, html, LitElement} from 'lit';
20+
import {customElement, property, query} from 'lit/decorators.js';
21+
22+
/** Component that copies text to the clipboard when clicked. */
23+
@customElement('copy-button')
24+
export class CopyButton extends LitElement {
25+
@property() textToCopyInClipboard!: string;
26+
27+
// There should be only one snackbar per page but one snackbar per CopyButton
28+
// is easier to reference.
29+
@query('mwc-snackbar') private readonly snackbar!: Snackbar;
30+
31+
override render() {
32+
return html`
33+
<mwc-icon-button title="Copy to clipboard" icon="content_copy"
34+
@click=${() => {
35+
if (window.isSecureContext) {
36+
navigator.clipboard.writeText(this.textToCopyInClipboard);
37+
this.snackbar.labelText = 'Copied to clipboard';
38+
this.snackbar.show();
39+
} else {
40+
this.snackbar.labelText = 'Copy to clipboard failed';
41+
this.snackbar.show();
42+
}
43+
}}>
44+
</mwc-icon-button>
45+
<mwc-snackbar></mwc-snackbar>`;
46+
}
47+
48+
static override styles = css`
49+
:host {
50+
float: right;
51+
}
52+
mwc-icon-button {
53+
color: var(--mdc-theme-text);
54+
/* Make the background disk that appears when hovered slightly bigger
55+
* than the icon itself, which is 24px. */
56+
--mdc-icon-button-size: 28px;
57+
/* Tighten the buttons to save space. */
58+
margin: -2px;
59+
}
60+
`;
61+
}

src/matches_ui.ts

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,12 @@ export class MatchesUi extends LitElement {
3838
@property({attribute: false}) matchIndex!: number|undefined;
3939

4040
override render() {
41+
const rowIndex = this.matchIndex === undefined ?
42+
undefined :
43+
this.batchSelection.matchedDataPoints.rows[this.matchIndex].leftIndex;
44+
4145
return html`
42-
<div class="verticalFlex">
46+
<div class="leftVerticalFlex">
4347
<div id="batchesHeader">
4448
<div id="matchChip">
4549
<mwc-icon>${
@@ -66,11 +70,17 @@ export class MatchesUi extends LitElement {
6670
</matches-table-ui>
6771
</div>
6872
69-
<match-image-ui .state=${this.state}
70-
.batchSelection=${this.batchSelection}
71-
.matchIndex=${this.matchIndex === undefined ? 0 : this.matchIndex}
73+
<div class="rightVerticalFlex"
7274
style=${this.matchIndex !== undefined ? '' : 'display: none'}>
73-
</match-image-ui>`;
75+
<constants-table-ui
76+
.batch=${this.batchSelection.batch}
77+
.rowIndex=${rowIndex}>
78+
</constants-table-ui>
79+
<match-image-ui .state=${this.state}
80+
.batchSelection=${this.batchSelection}
81+
.matchIndex=${this.matchIndex === undefined ? 0 : this.matchIndex}>
82+
</match-image-ui>
83+
</div>`;
7484
}
7585

7686
static override styles = css`
@@ -81,16 +91,22 @@ export class MatchesUi extends LitElement {
8191
gap: 10px;
8292
overflow: hidden;
8393
}
84-
.verticalFlex {
94+
.leftVerticalFlex,
95+
.rightVerticalFlex {
8596
display: flex;
8697
flex-direction: column;
8798
justify-content: flex-start;
8899
gap: 10px;
89100
overflow: hidden;
101+
}
102+
.leftVerticalFlex {
90103
flex: 4;
91104
/* Prevents unnecessarily wide table but breaks scrollbars. */
92105
/* align-items: flex-start; */
93106
}
107+
.rightVerticalFlex {
108+
flex: 1;
109+
}
94110
95111
#batchesHeader {
96112
display: flex;
@@ -115,7 +131,6 @@ export class MatchesUi extends LitElement {
115131
}
116132
117133
match-image-ui {
118-
flex: 1;
119134
align-self: center;
120135
}
121136
`;

0 commit comments

Comments
 (0)