chrome-devtools-frontend 1.0.956060 → 1.0.956401

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.
@@ -1553,7 +1553,6 @@ grd_files_debug_sources = [
1553
1553
  "front_end/ui/legacy/inspectorCommon.css.js",
1554
1554
  "front_end/ui/legacy/inspectorCommon.css.legacy.js",
1555
1555
  "front_end/ui/legacy/inspectorSyntaxHighlight.css.legacy.js",
1556
- "front_end/ui/legacy/inspectorSyntaxHighlightDark.css.legacy.js",
1557
1556
  "front_end/ui/legacy/inspectorViewTabbedPane.css.legacy.js",
1558
1557
  "front_end/ui/legacy/listWidget.css.legacy.js",
1559
1558
  "front_end/ui/legacy/popover.css.legacy.js",
@@ -1190,9 +1190,6 @@
1190
1190
  "entrypoints/main/MainImpl.ts | showConsoleDrawer": {
1191
1191
  "message": "Show console drawer"
1192
1192
  },
1193
- "entrypoints/main/MainImpl.ts | theSystempreferredColorSchemeHas": {
1194
- "message": "The system-preferred color scheme has changed. To apply this change to DevTools, reload."
1195
- },
1196
1193
  "entrypoints/main/MainImpl.ts | undockIntoSeparateWindow": {
1197
1194
  "message": "Undock into separate window"
1198
1195
  },
@@ -1190,9 +1190,6 @@
1190
1190
  "entrypoints/main/MainImpl.ts | showConsoleDrawer": {
1191
1191
  "message": "Ŝh́ôẃ ĉón̂śôĺê d́r̂áŵér̂"
1192
1192
  },
1193
- "entrypoints/main/MainImpl.ts | theSystempreferredColorSchemeHas": {
1194
- "message": "T̂h́ê śŷśt̂ém̂-ṕr̂éf̂ér̂ŕêd́ ĉól̂ór̂ śĉh́êḿê h́âś ĉh́âńĝéd̂. T́ô áp̂ṕl̂ý t̂h́îś ĉh́âńĝé t̂ó D̂év̂T́ôól̂ś, r̂él̂óâd́."
1195
- },
1196
1193
  "entrypoints/main/MainImpl.ts | undockIntoSeparateWindow": {
1197
1194
  "message": "Ûńd̂óĉḱ îńt̂ó ŝép̂ár̂át̂é ŵín̂d́ôẃ"
1198
1195
  },
@@ -11,3 +11,13 @@ export const enum FormatterActions {
11
11
  EVALUATE_JAVASCRIPT_SUBSTRING = 'evaluatableJavaScriptSubstring',
12
12
  ARGUMENTS_LIST = 'argumentsList',
13
13
  }
14
+
15
+ export interface FormatMapping {
16
+ original: number[];
17
+ formatted: number[];
18
+ }
19
+
20
+ export interface FormatResult {
21
+ content: string;
22
+ mapping: FormatMapping;
23
+ }
@@ -30,7 +30,6 @@
30
30
 
31
31
  import * as Platform from '../../core/platform/platform.js';
32
32
  import * as Root from '../../core/root/root.js';
33
- import type * as Formatter from '../../models/formatter/formatter.js';
34
33
  import * as Acorn from '../../third_party/acorn/acorn.js';
35
34
  import type * as CodeMirrorModule from '../../third_party/codemirror/codemirror-legacy.js'; // eslint-disable-line @typescript-eslint/no-unused-vars
36
35
 
@@ -38,6 +37,7 @@ import {AcornTokenizer, ECMA_VERSION} from './AcornTokenizer.js';
38
37
  import {CSSFormatter} from './CSSFormatter.js';
39
38
  import {ESTreeWalker} from './ESTreeWalker.js';
40
39
  import {FormattedContentBuilder} from './FormattedContentBuilder.js';
40
+ import type {FormatResult} from './FormatterActions.js';
41
41
  import {HTMLFormatter} from './HTMLFormatter.js';
42
42
  import {IdentityFormatter} from './IdentityFormatter.js';
43
43
  import {JavaScriptFormatter} from './JavaScriptFormatter.js';
@@ -179,12 +179,11 @@ export function javaScriptIdentifiers(content: string): {
179
179
  return identifiers.map(id => ({name: 'name' in id && id.name || undefined, offset: id.start}));
180
180
  }
181
181
 
182
- export function format(
183
- mimeType: string, text: string, indentString?: string): Formatter.FormatterWorkerPool.FormatResult {
182
+ export function format(mimeType: string, text: string, indentString?: string): FormatResult {
184
183
  // Default to a 4-space indent.
185
184
  indentString = indentString || ' ';
186
185
 
187
- let result: Formatter.FormatterWorkerPool.FormatResult;
186
+ let result: FormatResult;
188
187
  const builder = new FormattedContentBuilder(indentString);
189
188
  const lineEndings = Platform.StringUtilities.findLineEndingIndexes(text);
190
189
  try {
@@ -51,16 +51,12 @@ import * as IconButton from '../../ui/components/icon_button/icon_button.js';
51
51
  import * as PerfUI from '../../ui/legacy/components/perf_ui/perf_ui.js';
52
52
  import * as Components from '../../ui/legacy/components/utils/utils.js';
53
53
  import * as UI from '../../ui/legacy/legacy.js';
54
+ import * as ThemeSupport from '../../ui/legacy/theme_support/theme_support.js';
54
55
 
55
56
  import {ExecutionContextSelector} from './ExecutionContextSelector.js';
56
57
 
57
58
  const UIStrings = {
58
59
  /**
59
- *@description A message to display prompting the user to reload DevTools if the OS color scheme changes.
60
- */
61
- theSystempreferredColorSchemeHas:
62
- 'The system-preferred color scheme has changed. To apply this change to DevTools, reload.',
63
- /**
64
60
  *@description Title of item in main
65
61
  */
66
62
  customizeAndControlDevtools: 'Customize and control DevTools',
@@ -408,14 +404,26 @@ export class MainImpl {
408
404
 
409
405
  const defaultThemeSetting = 'systemPreferred';
410
406
  const themeSetting = Common.Settings.Settings.instance().createSetting('uiTheme', defaultThemeSetting);
411
- UI.UIUtils.initializeUIUtils(document, themeSetting);
412
- if (themeSetting.get() === defaultThemeSetting) {
413
- const darkThemeMediaQuery = window.matchMedia('(prefers-color-scheme: dark)');
414
- darkThemeMediaQuery.addEventListener('change', () => {
415
- UI.InspectorView.InspectorView.instance().displayReloadRequiredWarning(
416
- i18nString(UIStrings.theSystempreferredColorSchemeHas));
417
- });
407
+ UI.UIUtils.initializeUIUtils(document);
408
+
409
+ // Initialize theme support and apply it.
410
+ if (!ThemeSupport.ThemeSupport.hasInstance()) {
411
+ ThemeSupport.ThemeSupport.instance({forceNew: true, setting: themeSetting});
418
412
  }
413
+
414
+ ThemeSupport.ThemeSupport.instance().applyTheme(document);
415
+
416
+ const onThemeChange = (): void => {
417
+ ThemeSupport.ThemeSupport.instance().applyTheme(document);
418
+ };
419
+
420
+ // When the theme changes we instantiate a new theme support and reapply.
421
+ // Equally if the user has set to match the system and the OS preference changes
422
+ // we perform the same change.
423
+ const darkThemeMediaQuery = window.matchMedia('(prefers-color-scheme: dark)');
424
+ darkThemeMediaQuery.addEventListener('change', onThemeChange);
425
+ themeSetting.addChangeListener(onThemeChange);
426
+
419
427
  UI.UIUtils.installComponentRootStyles((document.body as Element));
420
428
 
421
429
  this.#addMainEventListeners(document);
@@ -588,7 +588,7 @@ Common.Settings.registerSettingExtension({
588
588
  settingName: 'uiTheme',
589
589
  settingType: Common.Settings.SettingType.ENUM,
590
590
  defaultValue: 'systemPreferred',
591
- reloadRequired: true,
591
+ reloadRequired: false,
592
592
  options: [
593
593
  {
594
594
  title: i18nLazyString(UIStrings.switchToSystemPreferredColor),
@@ -119,9 +119,9 @@ export class FormatterWorkerPool {
119
119
  });
120
120
  }
121
121
 
122
- format(mimeType: string, content: string, indentString: string): Promise<FormatResult> {
122
+ format(mimeType: string, content: string, indentString: string): Promise<FormatterActions.FormatResult> {
123
123
  const parameters = {mimeType: mimeType, content: content, indentString: indentString};
124
- return this.runTask(FormatterActions.FormatterActions.FORMAT, parameters) as Promise<FormatResult>;
124
+ return this.runTask(FormatterActions.FormatterActions.FORMAT, parameters) as Promise<FormatterActions.FormatResult>;
125
125
  }
126
126
 
127
127
  javaScriptIdentifiers(content: string): Promise<{
@@ -195,11 +195,6 @@ class Task {
195
195
  }
196
196
  }
197
197
 
198
- export interface FormatResult {
199
- content: string;
200
- mapping: FormatMapping;
201
- }
202
-
203
198
  interface CSSProperty {
204
199
  name: string;
205
200
  nameRange: TextRange;
@@ -220,11 +215,6 @@ export interface OutlineItem {
220
215
  subtitle?: string;
221
216
  }
222
217
 
223
- export interface FormatMapping {
224
- original: number[];
225
- formatted: number[];
226
- }
227
-
228
218
  export interface CSSStyleRule {
229
219
  selectorText: string;
230
220
  styleRange: TextRange;
@@ -30,8 +30,8 @@
30
30
 
31
31
  import * as Common from '../../core/common/common.js';
32
32
  import * as Platform from '../../core/platform/platform.js';
33
+ import type * as FormatterActions from '../../entrypoints/formatter_worker/FormatterActions.js'; // eslint-disable-line rulesdir/es_modules_import
33
34
 
34
- import type {FormatMapping} from './FormatterWorkerPool.js';
35
35
  import {formatterWorkerPool} from './FormatterWorkerPool.js';
36
36
 
37
37
  function locationToPosition(lineEndings: number[], lineNumber: number, columnNumber: number): number {
@@ -102,9 +102,9 @@ class IdentityFormatterSourceMapping implements FormatterSourceMapping {
102
102
  class FormatterSourceMappingImpl implements FormatterSourceMapping {
103
103
  private readonly originalLineEndings: number[];
104
104
  private readonly formattedLineEndings: number[];
105
- private readonly mapping: FormatMapping;
105
+ private readonly mapping: FormatterActions.FormatMapping;
106
106
 
107
- constructor(originalLineEndings: number[], formattedLineEndings: number[], mapping: FormatMapping) {
107
+ constructor(originalLineEndings: number[], formattedLineEndings: number[], mapping: FormatterActions.FormatMapping) {
108
108
  this.originalLineEndings = originalLineEndings;
109
109
  this.formattedLineEndings = formattedLineEndings;
110
110
  this.mapping = mapping;
@@ -77,8 +77,8 @@ export class AdvancedApp implements Common.App.App {
77
77
  }
78
78
 
79
79
  deviceModeEmulationFrameLoaded(toolboxDocument: Document): void {
80
- UI.UIUtils.initializeUIUtils(
81
- toolboxDocument, Common.Settings.Settings.instance().createSetting('uiTheme', 'default'));
80
+ Common.Settings.Settings.instance().createSetting('uiTheme', 'default');
81
+ UI.UIUtils.initializeUIUtils(toolboxDocument);
82
82
  UI.UIUtils.installComponentRootStyles((toolboxDocument.body as Element));
83
83
  UI.ContextMenu.ContextMenu.installHandler(toolboxDocument);
84
84
 
@@ -243,6 +243,25 @@ export class TimelineFlameChartDataProvider extends Common.ObjectWrapper.ObjectW
243
243
  this.interactionsHeaderLevel2 = this.buildGroupStyle({padding: 2, nestingLevel: 1});
244
244
  this.experienceHeader = this.buildGroupStyle({collapsible: false});
245
245
 
246
+ ThemeSupport.ThemeSupport.instance().addEventListener(ThemeSupport.ThemeChangeEvent.eventName, () => {
247
+ const headers = [
248
+ this.headerLevel1,
249
+ this.headerLevel2,
250
+ this.staticHeader,
251
+ this.framesHeader,
252
+ this.collapsibleTimingsHeader,
253
+ this.timingsHeader,
254
+ this.screenshotsHeader,
255
+ this.interactionsHeaderLevel1,
256
+ this.interactionsHeaderLevel2,
257
+ this.experienceHeader,
258
+ ];
259
+ for (const header of headers) {
260
+ header.color = ThemeSupport.ThemeSupport.instance().getComputedValue('--color-text-primary');
261
+ header.backgroundColor = ThemeSupport.ThemeSupport.instance().getComputedValue('--color-background');
262
+ }
263
+ });
264
+
246
265
  this.flowEventIndexById = new Map();
247
266
  }
248
267
 
@@ -79,6 +79,12 @@ export class TimelineFlameChartNetworkDataProvider implements PerfUI.FlameChart.
79
79
  this.timeSpan = 0;
80
80
  this.requests = [];
81
81
  this.maxLevel = 0;
82
+
83
+ // In the event of a theme change, these colors must be recalculated.
84
+ ThemeSupport.ThemeSupport.instance().addEventListener(ThemeSupport.ThemeChangeEvent.eventName, () => {
85
+ this.style.color = ThemeSupport.ThemeSupport.instance().getComputedValue('--color-text-primary');
86
+ this.style.backgroundColor = ThemeSupport.ThemeSupport.instance().getComputedValue('--color-background');
87
+ });
82
88
  }
83
89
 
84
90
  setModel(performanceModel: PerformanceModel|null): void {
@@ -194,7 +200,7 @@ export class TimelineFlameChartNetworkDataProvider implements PerfUI.FlameChart.
194
200
  const end = Math.max(timeToPixel(endTime), finish);
195
201
 
196
202
  // Draw waiting time.
197
- context.fillStyle = ThemeSupport.ThemeSupport.instance().getComputedValue('--color-background-opacity-80');
203
+ context.fillStyle = 'hsla(0, 100%, 100%, 0.8)';
198
204
  context.fillRect(sendStart + 0.5, barY + 0.5, headersEnd - sendStart - 0.5, barHeight - 2);
199
205
  // Clear portions of initial rect to prepare for the ticks.
200
206
  context.fillStyle = ThemeSupport.ThemeSupport.instance().getComputedValue('--color-background');
@@ -33,7 +33,6 @@
33
33
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
34
  */
35
35
 
36
- import type * as Common from '../../core/common/common.js';
37
36
  import * as DOMExtension from '../../core/dom_extension/dom_extension.js';
38
37
  import * as Host from '../../core/host/host.js';
39
38
  import * as i18n from '../../core/i18n/i18n.js';
@@ -46,7 +45,6 @@ import {Size} from './Geometry.js';
46
45
  import {GlassPane, PointerEventsBehavior, SizeBehavior} from './GlassPane.js';
47
46
  import {Icon} from './Icon.js';
48
47
  import {KeyboardShortcut} from './KeyboardShortcut.js';
49
- import * as ThemeSupport from './theme_support/theme_support.js';
50
48
  import * as Utils from './utils/utils.js';
51
49
 
52
50
  import type {ToolbarButton} from './Toolbar.js';
@@ -1043,7 +1041,7 @@ export class LongClickController {
1043
1041
  static readonly TIME_MS = 200;
1044
1042
  }
1045
1043
 
1046
- export function initializeUIUtils(document: Document, themeSetting: Common.Settings.Setting<string>): void {
1044
+ export function initializeUIUtils(document: Document): void {
1047
1045
  document.body.classList.toggle('inactive', !document.hasFocus());
1048
1046
  if (document.defaultView) {
1049
1047
  document.defaultView.addEventListener('focus', windowFocused.bind(undefined, document), false);
@@ -1051,11 +1049,6 @@ export function initializeUIUtils(document: Document, themeSetting: Common.Setti
1051
1049
  }
1052
1050
  document.addEventListener('focus', Utils.focusChanged.bind(undefined), true);
1053
1051
 
1054
- if (!ThemeSupport.ThemeSupport.hasInstance()) {
1055
- ThemeSupport.ThemeSupport.instance({forceNew: true, setting: themeSetting});
1056
- }
1057
- ThemeSupport.ThemeSupport.instance().applyTheme(document);
1058
-
1059
1052
  const body = (document.body as Element);
1060
1053
  GlassPane.setContainer(body);
1061
1054
  }
@@ -227,6 +227,10 @@ export class FlameChart extends Common.ObjectWrapper.eventMixin<EventTypes, type
227
227
 
228
228
  // Keyboard focused group is used to navigate groups irrespective of whether they are selectable or not
229
229
  this.keyboardFocusedGroup = -1;
230
+
231
+ ThemeSupport.ThemeSupport.instance().addEventListener(ThemeSupport.ThemeChangeEvent.eventName, () => {
232
+ this.scheduleUpdate();
233
+ });
230
234
  }
231
235
 
232
236
  willHide(): void {
@@ -1134,7 +1138,7 @@ export class FlameChart extends Common.ObjectWrapper.eventMixin<EventTypes, type
1134
1138
  this.forEachGroupInViewport((offset, index, group, isFirst, groupHeight) => {
1135
1139
  if (this.isGroupFocused(index)) {
1136
1140
  context.fillStyle =
1137
- ThemeSupport.ThemeSupport.instance().getComputedValue('--custom-val-test', this.contentElement);
1141
+ ThemeSupport.ThemeSupport.instance().getComputedValue('--selected-group-background', this.contentElement);
1138
1142
  context.fillRect(0, offset, width, groupHeight - group.style.padding);
1139
1143
  }
1140
1144
  });
@@ -27,18 +27,16 @@
27
27
  */
28
28
 
29
29
  .webkit-css-property {
30
- color: var(--webkit-css-property-color, rgb(200 0 0)); /* stylelint-disable-line plugin/use_theme_colors */ /* See: crbug.com/1152736 for color variable migration. */
30
+ color: var(--webkit-css-property-color, var(--color-syntax-1)); /* stylelint-disable-line plugin/use_theme_colors */ /* See: crbug.com/1152736 for color variable migration. */
31
31
  }
32
32
 
33
33
  .webkit-html-comment {
34
34
  /* Keep this in sync with view-source.css (.webkit-html-comment) */
35
- color: rgb(35 110 37); /* stylelint-disable-line plugin/use_theme_colors */
36
- /* See: crbug.com/1152736 for color variable migration. */
35
+ color: var(--color-token-comment);
37
36
  }
38
37
 
39
38
  .webkit-html-tag {
40
- color: rgb(168 148 166); /* stylelint-disable-line plugin/use_theme_colors */
41
- /* See: crbug.com/1152736 for color variable migration. */
39
+ color: var(--color-token-tag);
42
40
  }
43
41
 
44
42
  .webkit-html-tag-name,
@@ -49,16 +47,17 @@
49
47
 
50
48
  .webkit-html-pseudo-element {
51
49
  /* This one is non-standard. */
52
- color: rgb(17 85 204); /* stylelint-disable-line plugin/use_theme_colors */
53
- /* See: crbug.com/1152736 for color variable migration. */
50
+ color: var(--color-token-pseudo-element);
54
51
  }
55
52
 
56
53
  .webkit-html-js-node,
57
54
  .webkit-html-css-node {
55
+ color: var(--color-text-primary);
58
56
  white-space: pre-wrap;
59
57
  }
60
58
 
61
59
  .webkit-html-text-node {
60
+ color: var(--color-text-primary);
62
61
  unicode-bidi: -webkit-isolate;
63
62
  }
64
63
 
@@ -77,15 +76,13 @@
77
76
 
78
77
  .webkit-html-attribute-name {
79
78
  /* Keep this in sync with view-source.css (.webkit-html-attribute-name) */
80
- color: var(--color-token-attribute); /* stylelint-disable-line plugin/use_theme_colors */
81
- /* See: crbug.com/1152736 for color variable migration. */
79
+ color: var(--color-token-attribute);
82
80
  unicode-bidi: -webkit-isolate;
83
81
  }
84
82
 
85
83
  .webkit-html-attribute-value {
86
84
  /* Keep this in sync with view-source.css (.webkit-html-attribute-value) */
87
- color: rgb(26 26 166); /* stylelint-disable-line plugin/use_theme_colors */
88
- /* See: crbug.com/1152736 for color variable migration. */
85
+ color: var(--color-token-attribute-value);
89
86
  unicode-bidi: -webkit-isolate;
90
87
  word-break: break-all;
91
88
  }
@@ -155,6 +155,7 @@
155
155
  --color-token-meta: rgb(85 85 85);
156
156
  --color-token-deleted: rgb(221 68 68);
157
157
  --color-token-inserted: rgb(34 153 34);
158
+ --color-token-pseudo-element: rgb(17 85 204);
158
159
 
159
160
  /* Colors used by the code editor */
160
161
  --color-secondary-cursor: #c0c0c0;
@@ -295,8 +296,9 @@
295
296
  --color-token-comment: rgb(137 137 137);
296
297
  --color-token-tag: rgb(93 176 215);
297
298
  --color-token-attribute: rgb(155 187 220);
298
- --color-token-attribute-value: rgb(1 200 1);
299
+ --color-token-attribute-value: rgb(242 151 102);
299
300
  --color-token-meta: rgb(221 251 85);
301
+ --color-token-pseudo-element: rgb(237 119 229);
300
302
 
301
303
  /* Colors used by the code editor */
302
304
  --color-secondary-cursor: rgb(63 63 63);
@@ -36,23 +36,18 @@
36
36
  import * as Common from '../../../core/common/common.js';
37
37
 
38
38
  import inspectorSyntaxHighlightStyles from '../inspectorSyntaxHighlight.css.legacy.js';
39
- import inspectorSyntaxHighlightDarkStyles from '../inspectorSyntaxHighlightDark.css.legacy.js';
40
39
 
41
40
  let themeSupportInstance: ThemeSupport;
42
41
 
43
42
  const themeValuesCache = new Map<CSSStyleDeclaration, Map<string, string>>();
44
43
 
45
- export class ThemeSupport {
46
- private readonly themeNameInternal: string;
47
- private readonly customSheets: Set<string>;
48
- private readonly computedRoot: () => symbol | CSSStyleDeclaration;
44
+ export class ThemeSupport extends EventTarget {
45
+ private themeNameInternal = 'systemPreferred';
46
+ private customSheets: Set<string> = new Set();
47
+ private computedRoot = Common.Lazy.lazy(() => window.getComputedStyle(document.documentElement));
49
48
 
50
- private constructor(setting: Common.Settings.Setting<string>) {
51
- const systemPreferredTheme = window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'default';
52
- this.themeNameInternal = setting.get() === 'systemPreferred' ? systemPreferredTheme : setting.get();
53
-
54
- this.customSheets = new Set();
55
- this.computedRoot = Common.Lazy.lazy(() => window.getComputedStyle(document.documentElement));
49
+ private constructor(private setting: Common.Settings.Setting<string>) {
50
+ super();
56
51
  }
57
52
 
58
53
  static hasInstance(): boolean {
@@ -119,9 +114,6 @@ export class ThemeSupport {
119
114
 
120
115
  injectHighlightStyleSheets(element: Element|ShadowRoot): void {
121
116
  this.appendStyle(element, inspectorSyntaxHighlightStyles);
122
- if (this.themeNameInternal === 'dark') {
123
- this.appendStyle(element, inspectorSyntaxHighlightDarkStyles);
124
- }
125
117
  }
126
118
 
127
119
  /**
@@ -142,28 +134,37 @@ export class ThemeSupport {
142
134
  }
143
135
  }
144
136
 
145
- isForcedColorsMode(): boolean {
146
- return window.matchMedia('(forced-colors: active)').matches;
147
- }
148
-
149
137
  addCustomStylesheet(sheetText: string): void {
150
138
  this.customSheets.add(sheetText);
151
139
  }
152
140
 
153
141
  applyTheme(document: Document): void {
154
- if (!this.hasTheme() || this.isForcedColorsMode() || this.themeNameInternal !== 'dark') {
142
+ const isForcedColorsMode = window.matchMedia('(forced-colors: active)').matches;
143
+ if (isForcedColorsMode) {
155
144
  return;
156
145
  }
157
146
 
158
- document.documentElement.classList.add('-theme-with-dark-background');
147
+ const systemPreferredTheme = window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'default';
148
+ this.themeNameInternal = this.setting.get() === 'systemPreferred' ? systemPreferredTheme : this.setting.get();
149
+
150
+ const wasDarkThemed = document.documentElement.classList.contains('-theme-with-dark-background');
151
+ document.documentElement.classList.toggle('-theme-with-dark-background', this.themeNameInternal === 'dark');
152
+
153
+ const isDarkThemed = document.documentElement.classList.contains('-theme-with-dark-background');
154
+
155
+ // In the event the theme changes we need to clear caches and notify subscribers.
156
+ if (wasDarkThemed !== isDarkThemed) {
157
+ themeValuesCache.clear();
158
+ this.customSheets.clear();
159
+ this.dispatchEvent(new ThemeChangeEvent());
160
+ }
159
161
  }
160
162
  }
161
- export namespace ThemeSupport {
162
- // TODO(crbug.com/1167717): Make this a const enum again
163
- // eslint-disable-next-line rulesdir/const_enum
164
- export enum ColorUsage {
165
- Unknown = 0,
166
- Foreground = 1,
167
- Background = 2,
163
+
164
+ export class ThemeChangeEvent extends Event {
165
+ static readonly eventName = 'themechange';
166
+
167
+ constructor() {
168
+ super(ThemeChangeEvent.eventName, {bubbles: true, composed: true});
168
169
  }
169
170
  }
package/package.json CHANGED
@@ -53,5 +53,5 @@
53
53
  "unittest": "scripts/test/run_unittests.py --no-text-coverage",
54
54
  "watch": "third_party/node/node.py --output scripts/watch_build.js"
55
55
  },
56
- "version": "1.0.956060"
56
+ "version": "1.0.956401"
57
57
  }
@@ -0,0 +1,116 @@
1
+ // Copyright 2021 The Chromium Authors. All rights reserved.
2
+ // Use of this source code is governed by a BSD-style license that can be
3
+ // found in the LICENSE file.
4
+ 'use strict';
5
+
6
+ module.exports = {
7
+ meta: {
8
+ type: 'problem',
9
+ docs: {
10
+ description: 'Enforce that no methods that are used as LitHtml events are bound.',
11
+ category: 'Possible Errors',
12
+ },
13
+ fixable: 'code',
14
+ schema: [], // no options
15
+ messages: {
16
+ nonRenderBindFound:
17
+ 'Found bound method name {{ methodName }} on {{ componentName }} that was not `render`. Lit-Html binds all event handlers for you automatically so this is not required.',
18
+ },
19
+ },
20
+ create: function(context) {
21
+ function nodeIsHTMLElementClassDeclaration(node) {
22
+ return node.type === 'ClassDeclaration' && node.superClass && node.superClass.name === 'HTMLElement';
23
+ }
24
+
25
+ const classesToCheck = new Set();
26
+
27
+ // Store any method names that were passed to addEventListener.
28
+ // With the following code:
29
+ // window.addEventListener('click', this.boundOnClick)
30
+ // we would add `boundOnClick` to this set.
31
+ const addEventListenerCallPropertyNames = new Set();
32
+
33
+ function checkPropertyDeclarationForBinding(className, node) {
34
+ if (!node.value || node.value.type !== 'CallExpression') {
35
+ return;
36
+ }
37
+ if (node.value.callee.type !== 'MemberExpression') {
38
+ return;
39
+ }
40
+ if (node.value.callee.property.name !== 'bind') {
41
+ return;
42
+ }
43
+ // At this point we know it's a property of the form:
44
+ // someBoundThing = this.thing.bind(X)
45
+ // and now we want to check that the argument passed to bind is `this`.
46
+ // If the argument to bind is not `this`, we leave it be and move on.
47
+ if (node.value.arguments[0]?.type !== 'ThisExpression') {
48
+ return;
49
+ }
50
+
51
+ // At this point it's definitely of the form:
52
+ // someBoundThing = this.thing.bind(this)
53
+ // But we know that `render` may be bound for the scheduler, so if it's render we can move on
54
+ if (node.value.callee.object.property.name === 'render') {
55
+ return;
56
+ }
57
+
58
+ // Now it's an error UNLESS we found a call to
59
+ // addEventListener(x, this.#boundFoo),
60
+ // in which case it's allowed.
61
+
62
+ // Get the property name for the bound method
63
+ // #boundFoo = this.foo.bind(this);
64
+ // node.key.name === 'boundFoo';
65
+ const boundPropertyName = node.key.name;
66
+ if (addEventListenerCallPropertyNames.has(boundPropertyName)) {
67
+ return;
68
+ }
69
+
70
+ context.report({
71
+ node: node,
72
+ messageId: 'nonRenderBindFound',
73
+ data: {componentName: className, methodName: node.value.callee.object.property.name}
74
+ });
75
+ }
76
+
77
+ function checkClassForBoundMethods(classDeclarationNode) {
78
+ const classPropertyDeclarations = classDeclarationNode.body.body.filter(node => {
79
+ return node.type === 'PropertyDefinition';
80
+ });
81
+ for (const decl of classPropertyDeclarations) {
82
+ checkPropertyDeclarationForBinding(classDeclarationNode.id.name, decl);
83
+ }
84
+ }
85
+
86
+ return {
87
+ ClassDeclaration(classDeclarationNode) {
88
+ if (!nodeIsHTMLElementClassDeclaration(classDeclarationNode)) {
89
+ return;
90
+ }
91
+
92
+ classesToCheck.add(classDeclarationNode);
93
+ },
94
+ 'CallExpression[callee.type=\'MemberExpression\'][callee.property.name=\'addEventListener\']'(
95
+ callExpressionNode) {
96
+ const methodArg = callExpressionNode.arguments[1];
97
+ // Confirm that the argument is this.X, otherwise skip it
98
+ if (methodArg.type !== 'MemberExpression') {
99
+ return;
100
+ }
101
+
102
+ // Get the property from the addEventListener call
103
+ // window.addEventListener('click', this.#boundFoo)
104
+ // This will be the node representing `#boundFoo`
105
+ // and its `.name` property will be `boundFoo`
106
+ const propertyArg = methodArg.property;
107
+ addEventListenerCallPropertyNames.add(propertyArg.name);
108
+ },
109
+ 'Program:exit'() {
110
+ for (const classNode of classesToCheck) {
111
+ checkClassForBoundMethods(classNode);
112
+ }
113
+ }
114
+ };
115
+ }
116
+ };
@@ -0,0 +1,85 @@
1
+ // Copyright 2021 The Chromium Authors. All rights reserved.
2
+ // Use of this source code is governed by a BSD-style license that can be
3
+ // found in the LICENSE file.
4
+ 'use strict';
5
+
6
+ const rule = require('../lib/no_bound_component_methods.js');
7
+ const ruleTester = new (require('eslint').RuleTester)({
8
+ parserOptions: {ecmaVersion: 9, sourceType: 'module'},
9
+ parser: require.resolve('@typescript-eslint/parser'),
10
+ });
11
+
12
+ ruleTester.run('no_bound_component_methods', rule, {
13
+ valid: [
14
+ {
15
+ code: `export class FeedbackButton extends SomeOtherNonElementThing {
16
+ readonly #boundClick = this.onClick.bind(this);
17
+ }`,
18
+ filename: 'front_end/components/test.ts',
19
+ },
20
+ {
21
+ code: `export class FeedbackButton extends HTMLElement {
22
+ readonly #boundRender = this.render.bind(this);
23
+ private readonly shadow = this.attachShadow({mode: 'open'});
24
+ private frame?: SDK.ResourceTreeModel.ResourceTreeFrame;
25
+ }`,
26
+ filename: 'front_end/components/test.ts',
27
+ },
28
+ {
29
+ code: `export class FeedbackButton extends HTMLElement {
30
+ readonly #boundRender = this.render.bind(this);
31
+ #globalBoundThing = this.someEvent.bind(this);
32
+ private readonly shadow = this.attachShadow({mode: 'open'});
33
+
34
+ constructor() {
35
+ window.addEventListener('click', this.#globalBoundThing);
36
+ }
37
+ }`,
38
+ filename: 'front_end/components/test.ts',
39
+ },
40
+ {
41
+ code: `export class FeedbackButton extends HTMLElement {
42
+ readonly #boundRender = this.render.bind(this);
43
+ private globalBoundThing = this.someEvent.bind(this);
44
+ private readonly shadow = this.attachShadow({mode: 'open'});
45
+
46
+ constructor() {
47
+ window.addEventListener('click', this.globalBoundThing);
48
+ }
49
+ }`,
50
+ filename: 'front_end/components/test.ts',
51
+ },
52
+ ],
53
+ invalid: [
54
+ {
55
+ code: `export class FeedbackButton extends HTMLElement {
56
+ static readonly litTagName = LitHtml.literal\`devtools-feedback-button\`;
57
+ readonly #boundRender = this.render.bind(this);
58
+ readonly #boundClick = this.onClick.bind(this);
59
+ }`,
60
+ filename: 'front_end/components/test.ts',
61
+ errors: [{messageId: 'nonRenderBindFound', data: {componentName: 'FeedbackButton', methodName: 'onClick'}}]
62
+ },
63
+ {
64
+ code: `export class FeedbackButton extends HTMLElement {
65
+ static readonly litTagName = LitHtml.literal\`devtools-feedback-button\`;
66
+ private readonly boundClick = this.onClick.bind(this);
67
+ }`,
68
+ filename: 'front_end/components/test.ts',
69
+ errors: [{messageId: 'nonRenderBindFound', data: {componentName: 'FeedbackButton', methodName: 'onClick'}}]
70
+ },
71
+ {
72
+ code: `export class FeedbackButton extends HTMLElement {
73
+ static readonly litTagName = LitHtml.literal\`devtools-feedback-button\`;
74
+ private readonly boundClick = this.onClick.bind(this);
75
+ private readonly boundFocus = this.onFocus.bind(this);
76
+
77
+ constructor() {
78
+ this.addEventListener('click', this.boundClick);
79
+ }
80
+ }`,
81
+ filename: 'front_end/components/test.ts',
82
+ errors: [{messageId: 'nonRenderBindFound', data: {componentName: 'FeedbackButton', methodName: 'onFocus'}}]
83
+ },
84
+ ]
85
+ });
@@ -1,270 +0,0 @@
1
- /*
2
- * Copyright 2015 The Chromium Authors. All rights reserved.
3
- * Use of this source code is governed by a BSD-style license that can be
4
- * found in the LICENSE file.
5
- */
6
-
7
- .cm-js-atom {
8
- color: rgb(161 247 181); /* stylelint-disable-line plugin/use_theme_colors */ /* See: crbug.com/1152736 for color variable migration. */
9
- }
10
-
11
- .cm-js-attribute {
12
- color: rgb(97 148 198); /* stylelint-disable-line plugin/use_theme_colors */ /* See: crbug.com/1152736 for color variable migration. */
13
- }
14
-
15
- .cm-js-builtin {
16
- color: rgb(159 180 214); /* stylelint-disable-line plugin/use_theme_colors */ /* See: crbug.com/1152736 for color variable migration. */
17
- }
18
-
19
- .cm-js-comment {
20
- color: rgb(116 116 116); /* stylelint-disable-line plugin/use_theme_colors */ /* See: crbug.com/1152736 for color variable migration. */
21
- }
22
-
23
- .cm-js-def {
24
- color: var(--color-token-tag);
25
- }
26
-
27
- .cm-js-keyword {
28
- color: rgb(154 127 213); /* stylelint-disable-line plugin/use_theme_colors */ /* See: crbug.com/1152736 for color variable migration. */
29
- }
30
-
31
- .cm-js-link {
32
- color: rgb(159 180 214); /* stylelint-disable-line plugin/use_theme_colors */ /* See: crbug.com/1152736 for color variable migration. */
33
- }
34
-
35
- .cm-js-meta {
36
- color: rgb(221 251 85); /* stylelint-disable-line plugin/use_theme_colors */ /* See: crbug.com/1152736 for color variable migration. */
37
- }
38
-
39
- .cm-js-number {
40
- color: rgb(161 247 181); /* stylelint-disable-line plugin/use_theme_colors */ /* See: crbug.com/1152736 for color variable migration. */
41
- }
42
-
43
- .cm-js-operator {
44
- color: rgb(210 192 87); /* stylelint-disable-line plugin/use_theme_colors */ /* See: crbug.com/1152736 for color variable migration. */
45
- }
46
-
47
- .cm-js-property {
48
- color: rgb(210 192 87); /* stylelint-disable-line plugin/use_theme_colors */ /* See: crbug.com/1152736 for color variable migration. */
49
- }
50
-
51
- .cm-js-string {
52
- color: rgb(242 139 84); /* stylelint-disable-line plugin/use_theme_colors */ /* See: crbug.com/1152736 for color variable migration. */
53
- }
54
-
55
- .cm-js-string-2 {
56
- color: rgb(242 139 84); /* stylelint-disable-line plugin/use_theme_colors */ /* See: crbug.com/1152736 for color variable migration. */
57
- }
58
-
59
- .cm-js-tag {
60
- color: var(--color-token-tag);
61
- }
62
-
63
- .cm-js-variable {
64
- color: rgb(217 217 217); /* stylelint-disable-line plugin/use_theme_colors */ /* See: crbug.com/1152736 for color variable migration. */
65
- }
66
-
67
- .cm-js-variable-2 {
68
- color: rgb(217 217 217); /* stylelint-disable-line plugin/use_theme_colors */ /* See: crbug.com/1152736 for color variable migration. */
69
- }
70
-
71
- .cm-atom {
72
- color: rgb(161 247 181); /* stylelint-disable-line plugin/use_theme_colors */ /* See: crbug.com/1152736 for color variable migration. */
73
- }
74
-
75
- .cm-comment {
76
- color: rgb(116 116 116); /* stylelint-disable-line plugin/use_theme_colors */ /* See: crbug.com/1152736 for color variable migration. */
77
- }
78
-
79
- .cm-variable {
80
- color: rgb(217 217 217); /* stylelint-disable-line plugin/use_theme_colors */ /* See: crbug.com/1152736 for color variable migration. */
81
- }
82
-
83
- .cm-keyword {
84
- color: rgb(154 127 213); /* stylelint-disable-line plugin/use_theme_colors */ /* See: crbug.com/1152736 for color variable migration. */
85
- }
86
-
87
- .cm-number {
88
- color: rgb(161 247 181); /* stylelint-disable-line plugin/use_theme_colors */ /* See: crbug.com/1152736 for color variable migration. */
89
- }
90
-
91
- .cm-operator {
92
- color: rgb(210 192 87); /* stylelint-disable-line plugin/use_theme_colors */ /* See: crbug.com/1152736 for color variable migration. */
93
- }
94
-
95
- .cm-css-atom {
96
- color: rgb(217 217 217); /* stylelint-disable-line plugin/use_theme_colors */ /* See: crbug.com/1152736 for color variable migration. */
97
- }
98
-
99
- .cm-css-builtin {
100
- color: rgb(255 163 79); /* stylelint-disable-line plugin/use_theme_colors */ /* See: crbug.com/1152736 for color variable migration. */
101
- }
102
-
103
- .cm-css-def {
104
- color: rgb(255 163 79); /* stylelint-disable-line plugin/use_theme_colors */ /* See: crbug.com/1152736 for color variable migration. */
105
- }
106
-
107
- .cm-css-comment {
108
- color: rgb(116 116 116); /* stylelint-disable-line plugin/use_theme_colors */ /* See: crbug.com/1152736 for color variable migration. */
109
- }
110
-
111
- .cm-css-meta {
112
- color: rgb(132 240 255); /* stylelint-disable-line plugin/use_theme_colors */ /* See: crbug.com/1152736 for color variable migration. */
113
- }
114
-
115
- .cm-css-number {
116
- color: rgb(217 217 217); /* stylelint-disable-line plugin/use_theme_colors */ /* See: crbug.com/1152736 for color variable migration. */
117
- }
118
-
119
- .cm-css-operator {
120
- color: rgb(217 217 217); /* stylelint-disable-line plugin/use_theme_colors */ /* See: crbug.com/1152736 for color variable migration. */
121
- }
122
-
123
- .cm-css-property {
124
- color: rgb(132 240 255); /* stylelint-disable-line plugin/use_theme_colors */ /* See: crbug.com/1152736 for color variable migration. */
125
- }
126
-
127
- .cm-css-qualifier {
128
- color: rgb(255 163 79); /* stylelint-disable-line plugin/use_theme_colors */ /* See: crbug.com/1152736 for color variable migration. */
129
- }
130
-
131
- .cm-css-string {
132
- color: rgb(231 194 111); /* stylelint-disable-line plugin/use_theme_colors */ /* See: crbug.com/1152736 for color variable migration. */
133
- }
134
-
135
- .cm-css-string-2 {
136
- color: rgb(217 217 217); /* stylelint-disable-line plugin/use_theme_colors */ /* See: crbug.com/1152736 for color variable migration. */
137
- }
138
-
139
- .cm-css-tag {
140
- color: rgb(255 163 79); /* stylelint-disable-line plugin/use_theme_colors */ /* See: crbug.com/1152736 for color variable migration. */
141
- }
142
-
143
- .cm-css-variable {
144
- color: rgb(255 163 79); /* stylelint-disable-line plugin/use_theme_colors */ /* See: crbug.com/1152736 for color variable migration. */
145
- }
146
-
147
- .cm-css-variable-2 {
148
- color: rgb(255 163 79); /* stylelint-disable-line plugin/use_theme_colors */ /* See: crbug.com/1152736 for color variable migration. */
149
- }
150
-
151
- .cm-xml-comment {
152
- color: rgb(137 137 137); /* stylelint-disable-line plugin/use_theme_colors */ /* See: crbug.com/1152736 for color variable migration. */
153
- }
154
-
155
- .cm-xml-error {
156
- color: rgb(198 95 95); /* stylelint-disable-line plugin/use_theme_colors */ /* See: crbug.com/1152736 for color variable migration. */
157
- }
158
-
159
- .cm-xml-string {
160
- color: rgb(242 151 102); /* stylelint-disable-line plugin/use_theme_colors */ /* See: crbug.com/1152736 for color variable migration. */
161
- }
162
-
163
- .cm-xml-tag {
164
- color: var(--color-token-tag);
165
- }
166
-
167
- .cm-xml-attribute {
168
- color: var(--color-token-attribute);
169
- }
170
-
171
- .cm-xml-link {
172
- color: rgb(231 194 111); /* stylelint-disable-line plugin/use_theme_colors */ /* See: crbug.com/1152736 for color variable migration. */
173
- }
174
-
175
- .webkit-html-attribute-name {
176
- color: var(--color-token-attribute);
177
- }
178
-
179
- .webkit-html-attribute-value {
180
- color: rgb(242 151 102); /* stylelint-disable-line plugin/use_theme_colors */ /* See: crbug.com/1152736 for color variable migration. */
181
- }
182
-
183
- .webkit-html-comment {
184
- color: rgb(137 137 137); /* stylelint-disable-line plugin/use_theme_colors */ /* See: crbug.com/1152736 for color variable migration. */
185
- }
186
-
187
- .webkit-html-tag {
188
- color: var(--color-token-tag);
189
- }
190
-
191
- .webkit-html-tag-name {
192
- color: var(--color-token-tag);
193
- }
194
-
195
- .webkit-html-close-tag-name {
196
- color: var(--color-token-tag);
197
- }
198
-
199
- .webkit-html-text-node {
200
- color: rgb(207 208 208); /* stylelint-disable-line plugin/use_theme_colors */ /* See: crbug.com/1152736 for color variable migration. */
201
- }
202
-
203
- .webkit-html-css-node {
204
- color: rgb(207 208 208); /* stylelint-disable-line plugin/use_theme_colors */ /* See: crbug.com/1152736 for color variable migration. */
205
- }
206
-
207
- .webkit-html-js-node {
208
- color: rgb(207 208 208); /* stylelint-disable-line plugin/use_theme_colors */ /* See: crbug.com/1152736 for color variable migration. */
209
- }
210
-
211
- .webkit-html-pseudo-element {
212
- color: rgb(237 119 229); /* stylelint-disable-line plugin/use_theme_colors */ /* See: crbug.com/1152736 for color variable migration. */
213
- }
214
-
215
- .webkit-css-property {
216
- color: var(--webkit-css-property-color, rgb(53 212 199)); /* stylelint-disable-line plugin/use_theme_colors */ /* See: crbug.com/1152736 for color variable migration. */
217
- }
218
-
219
- .cm-def {
220
- color: var(--color-token-tag);
221
- }
222
-
223
- .cm-header {
224
- color: var(--color-token-tag);
225
- }
226
-
227
- .cm-variable-2 {
228
- color: #05a; /* stylelint-disable-line plugin/use_theme_colors */ /* See: crbug.com/1152736 for color variable migration. */
229
- }
230
-
231
- .cm-variable-3,
232
- .cm-type {
233
- color: rgb(93 176 215); /* stylelint-disable-line plugin/use_theme_colors */ /* See: crbug.com/1152736 for color variable migration. */
234
- }
235
-
236
- .cm-string {
237
- color: rgb(242 139 84); /* stylelint-disable-line plugin/use_theme_colors */ /* See: crbug.com/1152736 for color variable migration. */
238
- }
239
-
240
- .cm-meta {
241
- color: rgb(221 251 85); /* stylelint-disable-line plugin/use_theme_colors */ /* See: crbug.com/1152736 for color variable migration. */
242
- }
243
-
244
- .cm-qualifier {
245
- color: rgb(255 163 79); /* stylelint-disable-line plugin/use_theme_colors */ /* See: crbug.com/1152736 for color variable migration. */
246
- }
247
-
248
- .cm-builtin {
249
- color: rgb(159 180 214); /* stylelint-disable-line plugin/use_theme_colors */ /* See: crbug.com/1152736 for color variable migration. */
250
- }
251
-
252
- .cm-bracket {
253
- color: #997; /* stylelint-disable-line plugin/use_theme_colors */ /* See: crbug.com/1152736 for color variable migration. */
254
- }
255
-
256
- .cm-tag {
257
- color: var(--color-token-tag);
258
- }
259
-
260
- .cm-attribute {
261
- color: rgb(97 148 198); /* stylelint-disable-line plugin/use_theme_colors */ /* See: crbug.com/1152736 for color variable migration. */
262
- }
263
-
264
- .cm-hr {
265
- color: #999; /* stylelint-disable-line plugin/use_theme_colors */ /* See: crbug.com/1152736 for color variable migration. */
266
- }
267
-
268
- .cm-link {
269
- color: rgb(159 180 214); /* stylelint-disable-line plugin/use_theme_colors */ /* See: crbug.com/1152736 for color variable migration. */
270
- }