chrome-devtools-frontend 1.0.1650677 → 1.0.1651641

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,106 @@
1
+ // Copyright 2026 The Chromium Authors
2
+ // Use of this source code is governed by a BSD-style license that can be
3
+ // found in the LICENSE file.
4
+
5
+ import * as i18n from '../../core/i18n/i18n.js';
6
+ import type * as Protocol from '../../generated/protocol.js';
7
+
8
+ const UIStrings = {
9
+ /**
10
+ * @description Summary line in a tooltip explaining a CSS selector specificity.
11
+ * @example {1} PH1
12
+ * @example {2} PH2
13
+ * @example {3} PH3
14
+ */
15
+ specificity: 'Specificity: ({PH1},{PH2},{PH3})',
16
+ /**
17
+ * @description Tooltip line listing the selector parts contributing to the ID-like specificity bucket.
18
+ * @example {#main} PH1
19
+ */
20
+ idLikeSpecificity: '(a) ID-like: {PH1}',
21
+ /**
22
+ * @description Tooltip line listing the selector parts contributing to the class-like specificity bucket.
23
+ * @example {.active, :hover} PH1
24
+ */
25
+ classLikeSpecificity: '(b) Class-like: {PH1}',
26
+ /**
27
+ * @description Tooltip line listing the selector parts contributing to the type-like specificity bucket.
28
+ * @example {div} PH1
29
+ */
30
+ typeLikeSpecificity: '(c) Type-like: {PH1}',
31
+ } as const;
32
+ const str_ = i18n.i18n.registerUIStrings('panels/elements/CSSSpecificityBreakdown.ts', UIStrings);
33
+ const i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_);
34
+
35
+ export interface SpecificityBreakdown {
36
+ ids: string[];
37
+ classes: string[];
38
+ types: string[];
39
+ }
40
+
41
+ function formatContribution(text: string, contribution: number): string {
42
+ return contribution > 1 ? `${text} x${contribution}` : text;
43
+ }
44
+
45
+ function formatComponentList(components: string[]): string {
46
+ const formatter = new Intl.ListFormat(i18n.DevToolsLocale.DevToolsLocale.instance().locale, {
47
+ style: 'long',
48
+ type: 'conjunction',
49
+ });
50
+ return formatter.format(components);
51
+ }
52
+
53
+ export function getSpecificityBreakdown(specificity: Protocol.CSS.Specificity): SpecificityBreakdown {
54
+ const ids: string[] = [];
55
+ const classes: string[] = [];
56
+ const types: string[] = [];
57
+
58
+ for (const component of specificity.components ?? []) {
59
+ if (component.a > 0) {
60
+ ids.push(formatContribution(component.text, component.a));
61
+ }
62
+ if (component.b > 0) {
63
+ classes.push(formatContribution(component.text, component.b));
64
+ }
65
+ if (component.c > 0) {
66
+ types.push(formatContribution(component.text, component.c));
67
+ }
68
+ }
69
+
70
+ return {ids, classes, types};
71
+ }
72
+
73
+ /**
74
+ * Formats the specificity breakdown into a human-readable multi-line string
75
+ * suitable for displaying in a tooltip.
76
+ *
77
+ * Example output for selector "div#main .active:hover":
78
+ * Specificity: (1,2,1)
79
+ * (a) ID-like: #main
80
+ * (b) Class-like: .active, :hover
81
+ * (c) Type-like: div
82
+ */
83
+ export function formatSpecificitySummary(specificity: Protocol.CSS.Specificity): string {
84
+ return i18nString(UIStrings.specificity, {PH1: specificity.a, PH2: specificity.b, PH3: specificity.c});
85
+ }
86
+
87
+ export function getSpecificityBreakdownLines(specificity: Protocol.CSS.Specificity): string[] {
88
+ const breakdown = getSpecificityBreakdown(specificity);
89
+ const lines: string[] = [];
90
+
91
+ if (breakdown.ids.length > 0) {
92
+ lines.push(i18nString(UIStrings.idLikeSpecificity, {PH1: formatComponentList(breakdown.ids)}));
93
+ }
94
+ if (breakdown.classes.length > 0) {
95
+ lines.push(i18nString(UIStrings.classLikeSpecificity, {PH1: formatComponentList(breakdown.classes)}));
96
+ }
97
+ if (breakdown.types.length > 0) {
98
+ lines.push(i18nString(UIStrings.typeLikeSpecificity, {PH1: formatComponentList(breakdown.types)}));
99
+ }
100
+
101
+ return lines;
102
+ }
103
+
104
+ export function formatSpecificityTooltip(specificity: Protocol.CSS.Specificity): string {
105
+ return [formatSpecificitySummary(specificity), ...getSpecificityBreakdownLines(specificity)].join('\n');
106
+ }
@@ -54,9 +54,15 @@ import * as VisualLogging from '../../ui/visual_logging/visual_logging.js';
54
54
  import * as PanelsCommon from '../common/common.js';
55
55
 
56
56
  import * as ElementsComponents from './components/components.js';
57
+ import {formatSpecificitySummary, getSpecificityBreakdownLines} from './CSSSpecificityBreakdown.js';
57
58
  import {ElementsPanel} from './ElementsPanel.js';
58
59
  import stylePropertiesTreeOutlineStyles from './stylePropertiesTreeOutline.css.js';
59
- import {type Context, GhostStylePropertyTreeElement, StylePropertyTreeElement} from './StylePropertyTreeElement.js';
60
+ import {
61
+ type Context,
62
+ GhostStylePropertyTreeElement,
63
+ handleVarDefinitionActivate,
64
+ StylePropertyTreeElement,
65
+ } from './StylePropertyTreeElement.js';
60
66
  import type {StylesContainer} from './StylesContainer.js';
61
67
 
62
68
  const UIStrings = {
@@ -110,11 +116,6 @@ const UIStrings = {
110
116
  * @description Text that is announced by the screen reader when the user focuses on an input field for editing the name of a CSS selector in the Styles panel
111
117
  */
112
118
  cssSelector: '`CSS` selector',
113
- /**
114
- * @description Text displayed in tooltip that shows specificity information.
115
- * @example {(0,0,1)} PH1
116
- */
117
- specificity: 'Specificity: {PH1}',
118
119
  /**
119
120
  * @description Accessibility label for the button that expands a collapsed CSS rule in the Styles pane.
120
121
  */
@@ -898,7 +899,7 @@ export class StylePropertiesSection {
898
899
  ancestorRuleElement = this.createMediaElement(rule.media[mediaIndex++]);
899
900
  break;
900
901
  case Protocol.CSS.CSSRuleType.ContainerRule:
901
- ancestorRuleElement = this.createContainerQueryElement(rule.containerQueries[containerIndex++]);
902
+ ancestorRuleElement = this.createContainerQueryElement(rule.containerQueries[containerIndex++], rule.style);
902
903
  break;
903
904
  case Protocol.CSS.CSSRuleType.ScopeRule:
904
905
  ancestorRuleElement = this.createScopeElement(rule.scopes[scopeIndex++]);
@@ -1019,7 +1020,8 @@ export class StylePropertiesSection {
1019
1020
  return mediaQueryElement;
1020
1021
  }
1021
1022
 
1022
- protected createContainerQueryElement(containerQuery: SDK.CSSContainerQuery.CSSContainerQuery):
1023
+ protected createContainerQueryElement(containerQuery: SDK.CSSContainerQuery.CSSContainerQuery,
1024
+ style?: SDK.CSSStyleDeclaration.CSSStyleDeclaration):
1023
1025
  ElementsComponents.CSSQuery.CSSQuery|undefined {
1024
1026
  let onQueryTextClick;
1025
1027
  if (containerQuery.styleSheetId) {
@@ -1032,10 +1034,22 @@ export class StylePropertiesSection {
1032
1034
  queryName: containerQuery.textIsConditionText ? undefined : containerQuery.name,
1033
1035
  queryText: containerQuery.text,
1034
1036
  onQueryTextClick,
1037
+ onLinkActivate: async(resolvedVariable: string|SDK.CSSMatchedStyles.CSSValueSource): Promise<void> => {
1038
+ handleVarDefinitionActivate(resolvedVariable, this.stylesContainer);
1039
+ },
1040
+ getPopoverContents: (variableName: string, variableValue: string|null):
1041
+ ElementsComponents.CSSVariableValueView.CSSVariableValueView => {
1042
+ return this.stylesContainer.getVariablePopoverContents(this.matchedStyles, variableName, variableValue);
1043
+ },
1035
1044
  jslogContext: 'container-query',
1036
1045
  };
1037
- if (!/^style\(.*\)/.test(containerQuery.text)) {
1038
- // We only add container element for non-style queries.
1046
+ if (style) {
1047
+ const tooltipPrefix = `container-${this.sectionTooltipIdPrefix}-${this.nestingLevel}`;
1048
+ void containerQuery.getContainerForNode(this.matchedStyles.node().id).then(container => {
1049
+ if (container) {
1050
+ containerQueryElement.parseStyleQueries(this.matchedStyles, style, container.containerNode, tooltipPrefix);
1051
+ }
1052
+ });
1039
1053
  void this.addContainerForContainerQuery(containerQuery);
1040
1054
  }
1041
1055
  return containerQueryElement;
@@ -1434,14 +1448,27 @@ export class StylePropertiesSection {
1434
1448
  elementToSelectorIndex.set(span, i);
1435
1449
  span.textContent = selectors[i].text;
1436
1450
  if (specificityTooltipId && selector.specificity) {
1437
- span.setAttribute('aria-describedby', specificityTooltipId);
1438
- const PH1 = `(${selector.specificity.a},${selector.specificity.b},${selector.specificity.c})`;
1451
+ span.setAttribute('aria-details', specificityTooltipId);
1439
1452
  const tooltip = this.#specificityTooltips.appendChild(new Tooltips.Tooltip.Tooltip({
1440
1453
  id: specificityTooltipId,
1441
1454
  anchor: span,
1455
+ variant: 'rich',
1442
1456
  jslogContext: 'elements.css-selector-specificity',
1443
1457
  }));
1444
- tooltip.textContent = i18nString(UIStrings.specificity, {PH1});
1458
+ tooltip.hoverDelay = 500;
1459
+
1460
+ const specificitySummary = formatSpecificitySummary(selector.specificity);
1461
+ const breakdownLines = getSpecificityBreakdownLines(selector.specificity);
1462
+ const tooltipContent = breakdownLines.length > 0 ? html`
1463
+ <details class="selector-specificity-tooltip-disclosure">
1464
+ <summary>${specificitySummary}</summary>
1465
+ <ul class="selector-specificity-tooltip-list">
1466
+ ${breakdownLines.map(line => html`<li>${line}</li>`)}
1467
+ </ul>
1468
+ </details>` :
1469
+ html`
1470
+ <div class="selector-specificity-tooltip-summary">${specificitySummary}</div>`;
1471
+ render(tooltipContent, tooltip, {host: this});
1445
1472
  }
1446
1473
  }
1447
1474
  }
@@ -316,8 +316,8 @@ export class CSSWideKeywordRenderer extends rendererBase(SDK.CSSPropertyParserMa
316
316
  }
317
317
  }
318
318
 
319
- function handleVarDefinitionActivate(variable: string|SDK.CSSMatchedStyles.CSSValueSource,
320
- stylesContainer: StylesContainer): void {
319
+ export function handleVarDefinitionActivate(variable: string|SDK.CSSMatchedStyles.CSSValueSource,
320
+ stylesContainer: StylesContainer): void {
321
321
  Host.userMetrics.actionTaken(Host.UserMetrics.Action.CustomPropertyLinkClicked);
322
322
  Host.userMetrics.swatchActivated(Host.UserMetrics.SwatchType.VAR_LINK);
323
323
 
@@ -448,16 +448,17 @@ export class VariableNameRenderer extends rendererBase(SDK.CSSPropertyParserMatc
448
448
  this.#matchedStyles = matchedStyles;
449
449
  }
450
450
 
451
- override render(match: SDK.CSSPropertyParserMatchers.VariableNameMatch, context: RenderingContext): Node[] {
451
+ override render(match: SDK.CSSPropertyParserMatchers.VariableNameMatch, _context: RenderingContext): Node[] {
452
+ const varSwatch = document.createElement('span');
452
453
  if (this.#treeElement?.property.ownerStyle.parentRule instanceof SDK.CSSRule.CSSFunctionRule) {
453
- return Renderer.render(ASTUtils.children(match.node), context).nodes;
454
+ render(html`${match.text}`, varSwatch);
455
+ return [varSwatch];
454
456
  }
455
457
 
456
458
  const {declaration, value: variableValue} = match.resolveVariable() ?? {};
457
459
  const isDefined = variableValue !== undefined;
458
460
  const onLinkActivate = (name: string): void =>
459
461
  handleVarDefinitionActivate(declaration ?? name, this.#stylesContainer);
460
- const varSwatch = document.createElement('span');
461
462
 
462
463
  const tooltipContents =
463
464
  this.#stylesContainer.getVariablePopoverContents(this.#matchedStyles, match.text, variableValue ?? null);
@@ -3,11 +3,17 @@
3
3
  // found in the LICENSE file.
4
4
  /* eslint-disable @devtools/no-lit-render-outside-of-view */
5
5
 
6
+ import '../../../ui/components/tooltips/tooltips.js';
7
+ import '../../../ui/legacy/components/inline_editor/inline_editor.js';
8
+
9
+ import * as SDK from '../../../core/sdk/sdk.js';
10
+ import type * as InlineEditor from '../../../ui/legacy/components/inline_editor/inline_editor.js';
6
11
  import * as UI from '../../../ui/legacy/legacy.js';
7
12
  import * as Lit from '../../../ui/lit/lit.js';
8
13
  import * as VisualLogging from '../../../ui/visual_logging/visual_logging.js';
9
14
 
10
15
  import cssQueryStyles from './cssQuery.css.js';
16
+ import type {CSSVariableValueView} from './CSSVariableValueView.js';
11
17
 
12
18
  const {render, html} = Lit;
13
19
 
@@ -16,36 +22,145 @@ export interface CSSQueryData {
16
22
  queryName?: string;
17
23
  queryText: string;
18
24
  onQueryTextClick?: (event: Event) => void;
25
+ onLinkActivate?: (resolvedVariable: string|SDK.CSSMatchedStyles.CSSValueSource) => void;
26
+ getPopoverContents?: (variableName: string, variableValue: string|null) => CSSVariableValueView;
19
27
  jslogContext: string;
20
28
  }
21
29
 
30
+ interface TextSection {
31
+ text: string;
32
+ isVariable: boolean;
33
+ }
34
+
22
35
  export class CSSQuery extends HTMLElement {
23
36
  readonly #shadow = this.attachShadow({mode: 'open'});
24
37
  #queryPrefix = '';
25
38
  #queryName?: string;
26
- #queryText = '';
39
+ #queryText: TextSection[] = [];
27
40
  #onQueryTextClick?: (event: Event) => void;
41
+ #onLinkActivate?: (resolvedVariable: string|SDK.CSSMatchedStyles.CSSValueSource) => void;
42
+ #getPopoverContents?: (variableName: string, variableValue: string|null) => CSSVariableValueView;
28
43
  #jslogContext?: string;
44
+ #matchedStyles?: SDK.CSSMatchedStyles.CSSMatchedStyles;
45
+ #style?: SDK.CSSStyleDeclaration.CSSStyleDeclaration;
46
+ #containerNode?: SDK.DOMModel.DOMNode;
47
+ #tooltipPrefix = '';
29
48
 
30
49
  set data(data: CSSQueryData) {
31
50
  this.#queryPrefix = data.queryPrefix;
32
51
  this.#queryName = data.queryName;
33
- this.#queryText = data.queryText;
52
+ this.#queryText = [{text: data.queryText, isVariable: false}];
34
53
  this.#onQueryTextClick = data.onQueryTextClick;
54
+ this.#onLinkActivate = data.onLinkActivate;
55
+ this.#getPopoverContents = data.getPopoverContents;
35
56
  this.#jslogContext = data.jslogContext;
36
57
  this.#render();
37
58
  }
38
59
 
60
+ parseStyleQueries(
61
+ matchedStyles: SDK.CSSMatchedStyles.CSSMatchedStyles,
62
+ style: SDK.CSSStyleDeclaration.CSSStyleDeclaration,
63
+ containerNode: SDK.DOMModel.DOMNode,
64
+ tooltipPrefix: string,
65
+ ): void {
66
+ this.#matchedStyles = matchedStyles;
67
+ this.#style = style;
68
+ this.#containerNode = containerNode;
69
+ this.#tooltipPrefix = tooltipPrefix;
70
+
71
+ const queryText = this.#queryText[0]?.text;
72
+ if (!queryText) {
73
+ return;
74
+ }
75
+
76
+ const prefix = 'if(';
77
+ const suffix = ': 1)';
78
+ const ast = SDK.CSSPropertyParser.tokenizeDeclaration('--query', prefix + queryText + suffix);
79
+ if (!ast) {
80
+ return;
81
+ }
82
+
83
+ const matcher = new SDK.CSSPropertyParserMatchers.VariableNameMatcher(matchedStyles, style);
84
+ const matchedResult = SDK.CSSPropertyParser.BottomUpTreeMatching.walk(ast, [matcher]);
85
+ const matchedNodes = SDK.CSSPropertyParser.TreeSearch.findAll(ast, node => {
86
+ return matchedResult.getMatch(node) instanceof SDK.CSSPropertyParserMatchers.VariableNameMatch;
87
+ });
88
+
89
+ matchedNodes.sort((a, b) => a.from - b.from);
90
+
91
+ const sections: TextSection[] = [];
92
+ const valueOffset = ast.rule.indexOf(ast.propertyValue) + prefix.length;
93
+ let lastOffset = 0;
94
+
95
+ for (const node of matchedNodes) {
96
+ const start = node.from - valueOffset;
97
+ const end = node.to - valueOffset;
98
+ if (start > lastOffset) {
99
+ sections.push({
100
+ text: queryText.substring(lastOffset, start),
101
+ isVariable: false,
102
+ });
103
+ }
104
+ sections.push({
105
+ text: queryText.substring(start, end),
106
+ isVariable: true,
107
+ });
108
+ lastOffset = end;
109
+ }
110
+
111
+ if (lastOffset < queryText.length) {
112
+ sections.push({
113
+ text: queryText.substring(lastOffset),
114
+ isVariable: false,
115
+ });
116
+ }
117
+
118
+ this.#queryText = sections;
119
+ this.#render();
120
+ }
121
+
39
122
  #render(): void {
40
123
  const queryClasses = Lit.Directives.classMap({
41
124
  query: true,
42
125
  editable: Boolean(this.#onQueryTextClick),
43
126
  });
44
127
 
45
- // Disabled until https://crbug.com/1079231 is fixed.
46
128
  // clang-format off
47
129
  const queryText = html`
48
- <span class="query-text" @click=${this.#onQueryTextClick}>${this.#queryText}</span>
130
+ <span class="query-text" @click=${this.#onQueryTextClick}>${
131
+ this.#queryText.map((section, index) => {
132
+ if (section.isVariable && this.#matchedStyles && this.#style && this.#onLinkActivate) {
133
+ const variableName = section.text;
134
+ const variable = this.#matchedStyles.computeCSSVariable(this.#style, variableName, this.#containerNode);
135
+ const isDefined = variable !== null && variable.value !== undefined;
136
+ const onLinkActivate = (): void => {
137
+ if (this.#onLinkActivate) {
138
+ this.#onLinkActivate(variable ? variable.declaration : variableName);
139
+ }
140
+ };
141
+ const tooltipContents = this.#getPopoverContents?.(variableName, variable?.value ?? null) ?? null;
142
+ const tooltipId = `${this.#tooltipPrefix}-${index}-${variableName}`;
143
+ const tooltip = {tooltipId};
144
+ return html`
145
+ <devtools-link-swatch class="css-var-link" .data=${{
146
+ tooltip,
147
+ text: variableName,
148
+ isDefined,
149
+ onLinkActivate,
150
+ } as InlineEditor.LinkSwatch.LinkSwatchRenderData}>
151
+ </devtools-link-swatch>
152
+ <devtools-tooltip
153
+ id=${tooltipId}
154
+ variant="rich"
155
+ jslogContext="elements.css-var"
156
+ >
157
+ ${tooltipContents}
158
+ </devtools-tooltip>
159
+ `;
160
+ }
161
+ return html`${section.text}`;
162
+ })
163
+ }</span>
49
164
  `;
50
165
 
51
166
  render(html`
@@ -23,6 +23,7 @@ import './StylesAiCodeCompletionProvider.js';
23
23
  import './StylePropertyTreeElement.js';
24
24
  import './ComputedStyleWidget.js';
25
25
  import './CSSRuleValidator.js';
26
+ import './CSSSpecificityBreakdown.js';
26
27
  import './ElementsPanel.js';
27
28
  import './ClassesPaneWidget.js';
28
29
  import './ElementStatePaneWidget.js';
@@ -36,6 +37,7 @@ import * as ClassesPaneWidget from './ClassesPaneWidget.js';
36
37
  import * as ColorSwatchPopoverIcon from './ColorSwatchPopoverIcon.js';
37
38
  import * as ComputedStyleWidget from './ComputedStyleWidget.js';
38
39
  import * as CSSRuleValidator from './CSSRuleValidator.js';
40
+ import * as CSSSpecificityBreakdown from './CSSSpecificityBreakdown.js';
39
41
  import * as CSSValueTraceView from './CSSValueTraceView.js';
40
42
  import * as DOMPath from './DOMPath.js';
41
43
  import * as ElementsPanel from './ElementsPanel.js';
@@ -73,6 +75,7 @@ export {
73
75
  ColorSwatchPopoverIcon,
74
76
  ComputedStyleWidget,
75
77
  CSSRuleValidator,
78
+ CSSSpecificityBreakdown,
76
79
  CSSValueTraceView,
77
80
  DOMPath,
78
81
  ElementsPanel,
@@ -326,3 +326,37 @@
326
326
  .section-block-expand-icon {
327
327
  margin-bottom: -4px;
328
328
  }
329
+
330
+ .selector-specificity-tooltip-summary {
331
+ white-space: nowrap;
332
+ }
333
+
334
+ .selector-specificity-tooltip-disclosure {
335
+ > summary {
336
+ cursor: pointer;
337
+ white-space: nowrap;
338
+ }
339
+ }
340
+
341
+ .selector-specificity-tooltip-list {
342
+ margin: var(--sys-size-3) 0 0;
343
+ padding: 0;
344
+ list-style: none;
345
+
346
+ > li {
347
+ display: flex;
348
+ align-items: center;
349
+ gap: var(--sys-size-3);
350
+
351
+ &::before {
352
+ content: "";
353
+ flex: none;
354
+ width: var(--sys-size-3);
355
+ height: var(--sys-size-3);
356
+ border-radius: 50%;
357
+ background-color: currentcolor;
358
+ /* Aligns the bullet's center with the disclosure triangle above. */
359
+ margin-left: var(--sys-size-2);
360
+ }
361
+ }
362
+ }
@@ -2,8 +2,6 @@
2
2
  // Use of this source code is governed by a BSD-style license that can be
3
3
  // found in the LICENSE file.
4
4
 
5
- /* eslint-disable @devtools/no-imperative-dom-api */
6
-
7
5
  import * as Common from '../../core/common/common.js';
8
6
  import * as i18n from '../../core/i18n/i18n.js';
9
7
  import * as Platform from '../../core/platform/platform.js';
@@ -266,7 +264,6 @@ export class PaintProfilerView extends Common.ObjectWrapper.eventMixin<EventType
266
264
 
267
265
  constructor(element?: HTMLElement, view: View = DEFAULT_VIEW) {
268
266
  super(element);
269
- this.contentElement.classList.add('paint-profiler-overview');
270
267
  this.#view = view;
271
268
 
272
269
  this.innerBarWidth = 4 * window.devicePixelRatio;
@@ -1,7 +1,7 @@
1
1
  Name: Dependencies sourced from the upstream `chromium` repository
2
2
  URL: Internal
3
3
  Version: N/A
4
- Revision: 2f1db9960be2f98ba060d8856277091dc61ee03d
4
+ Revision: f4d1d27cc2ccb4e6be93ee3be8a52050a6273550
5
5
  Update Mechanism: Manual (https://crbug.com/428069060)
6
6
  License: BSD-3-Clause
7
7
  License File: LICENSE
package/package.json CHANGED
@@ -91,5 +91,5 @@
91
91
  "webidl2": "24.5.0",
92
92
  "yargs": "17.7.2"
93
93
  },
94
- "version": "1.0.1650677"
94
+ "version": "1.0.1651641"
95
95
  }