1. /**
    
  2.  * Copyright (c) Meta Platforms, Inc. and affiliates.
    
  3.  *
    
  4.  * This source code is licensed under the MIT license found in the
    
  5.  * LICENSE file in the root directory of this source tree.
    
  6.  *
    
  7.  * @flow
    
  8.  */
    
  9. 
    
  10. export const DPR: number = window.devicePixelRatio || 1;
    
  11. export const LABEL_SIZE = 80;
    
  12. export const MARKER_HEIGHT = 20;
    
  13. export const MARKER_TICK_HEIGHT = 8;
    
  14. export const FONT_SIZE = 10;
    
  15. export const MARKER_TEXT_PADDING = 8;
    
  16. export const COLOR_HOVER_DIM_DELTA = 5;
    
  17. export const TOP_ROW_PADDING = 4;
    
  18. export const NATIVE_EVENT_HEIGHT = 14;
    
  19. export const SUSPENSE_EVENT_HEIGHT = 14;
    
  20. export const PENDING_SUSPENSE_EVENT_SIZE = 8;
    
  21. export const REACT_EVENT_DIAMETER = 6;
    
  22. export const USER_TIMING_MARK_SIZE = 8;
    
  23. export const REACT_MEASURE_HEIGHT = 14;
    
  24. export const BORDER_SIZE = 1 / DPR;
    
  25. export const FLAMECHART_FRAME_HEIGHT = 14;
    
  26. export const TEXT_PADDING = 3;
    
  27. export const SNAPSHOT_SCRUBBER_SIZE = 3;
    
  28. 
    
  29. export const INTERVAL_TIMES = [
    
  30.   1, 2, 5, 10, 20, 50, 100, 200, 500, 1000, 2000, 5000,
    
  31. ];
    
  32. export const MIN_INTERVAL_SIZE_PX = 70;
    
  33. 
    
  34. // TODO Replace this with "export let" vars
    
  35. export let COLORS: {
    
  36.   BACKGROUND: string,
    
  37.   INTERNAL_MODULE_FRAME: string,
    
  38.   INTERNAL_MODULE_FRAME_HOVER: string,
    
  39.   INTERNAL_MODULE_FRAME_TEXT: string,
    
  40.   NATIVE_EVENT: string,
    
  41.   NATIVE_EVENT_HOVER: string,
    
  42.   NETWORK_PRIMARY: string,
    
  43.   NETWORK_PRIMARY_HOVER: string,
    
  44.   NETWORK_SECONDARY: string,
    
  45.   NETWORK_SECONDARY_HOVER: string,
    
  46.   PRIORITY_BACKGROUND: string,
    
  47.   PRIORITY_BORDER: string,
    
  48.   PRIORITY_LABEL: string,
    
  49.   REACT_COMMIT: string,
    
  50.   REACT_COMMIT_HOVER: string,
    
  51.   REACT_COMMIT_TEXT: string,
    
  52.   REACT_IDLE: string,
    
  53.   REACT_IDLE_HOVER: string,
    
  54.   REACT_LAYOUT_EFFECTS: string,
    
  55.   REACT_LAYOUT_EFFECTS_HOVER: string,
    
  56.   REACT_LAYOUT_EFFECTS_TEXT: string,
    
  57.   REACT_PASSIVE_EFFECTS: string,
    
  58.   REACT_PASSIVE_EFFECTS_HOVER: string,
    
  59.   REACT_PASSIVE_EFFECTS_TEXT: string,
    
  60.   REACT_RENDER: string,
    
  61.   REACT_RENDER_HOVER: string,
    
  62.   REACT_RENDER_TEXT: string,
    
  63.   REACT_RESIZE_BAR: string,
    
  64.   REACT_RESIZE_BAR_ACTIVE: string,
    
  65.   REACT_RESIZE_BAR_BORDER: string,
    
  66.   REACT_RESIZE_BAR_DOT: string,
    
  67.   REACT_SCHEDULE: string,
    
  68.   REACT_SCHEDULE_HOVER: string,
    
  69.   REACT_SUSPENSE_REJECTED_EVENT: string,
    
  70.   REACT_SUSPENSE_REJECTED_EVENT_HOVER: string,
    
  71.   REACT_SUSPENSE_RESOLVED_EVENT: string,
    
  72.   REACT_SUSPENSE_RESOLVED_EVENT_HOVER: string,
    
  73.   REACT_SUSPENSE_UNRESOLVED_EVENT: string,
    
  74.   REACT_SUSPENSE_UNRESOLVED_EVENT_HOVER: string,
    
  75.   REACT_THROWN_ERROR: string,
    
  76.   REACT_THROWN_ERROR_HOVER: string,
    
  77.   REACT_WORK_BORDER: string,
    
  78.   SCROLL_CARET: string,
    
  79.   SCRUBBER_BACKGROUND: string,
    
  80.   SCRUBBER_BORDER: string,
    
  81.   SEARCH_RESULT_FILL: string,
    
  82.   TEXT_COLOR: string,
    
  83.   TEXT_DIM_COLOR: string,
    
  84.   TIME_MARKER_LABEL: string,
    
  85.   USER_TIMING: string,
    
  86.   USER_TIMING_HOVER: string,
    
  87.   WARNING_BACKGROUND: string,
    
  88.   WARNING_BACKGROUND_HOVER: string,
    
  89.   WARNING_TEXT: string,
    
  90.   WARNING_TEXT_INVERED: string,
    
  91. } = {
    
  92.   BACKGROUND: '',
    
  93.   INTERNAL_MODULE_FRAME: '',
    
  94.   INTERNAL_MODULE_FRAME_HOVER: '',
    
  95.   INTERNAL_MODULE_FRAME_TEXT: '',
    
  96.   NATIVE_EVENT: '',
    
  97.   NATIVE_EVENT_HOVER: '',
    
  98.   NETWORK_PRIMARY: '',
    
  99.   NETWORK_PRIMARY_HOVER: '',
    
  100.   NETWORK_SECONDARY: '',
    
  101.   NETWORK_SECONDARY_HOVER: '',
    
  102.   PRIORITY_BACKGROUND: '',
    
  103.   PRIORITY_BORDER: '',
    
  104.   PRIORITY_LABEL: '',
    
  105.   USER_TIMING: '',
    
  106.   USER_TIMING_HOVER: '',
    
  107.   REACT_IDLE: '',
    
  108.   REACT_IDLE_HOVER: '',
    
  109.   REACT_RENDER: '',
    
  110.   REACT_RENDER_HOVER: '',
    
  111.   REACT_RENDER_TEXT: '',
    
  112.   REACT_COMMIT: '',
    
  113.   REACT_COMMIT_HOVER: '',
    
  114.   REACT_COMMIT_TEXT: '',
    
  115.   REACT_LAYOUT_EFFECTS: '',
    
  116.   REACT_LAYOUT_EFFECTS_HOVER: '',
    
  117.   REACT_LAYOUT_EFFECTS_TEXT: '',
    
  118.   REACT_PASSIVE_EFFECTS: '',
    
  119.   REACT_PASSIVE_EFFECTS_HOVER: '',
    
  120.   REACT_PASSIVE_EFFECTS_TEXT: '',
    
  121.   REACT_RESIZE_BAR: '',
    
  122.   REACT_RESIZE_BAR_ACTIVE: '',
    
  123.   REACT_RESIZE_BAR_BORDER: '',
    
  124.   REACT_RESIZE_BAR_DOT: '',
    
  125.   REACT_SCHEDULE: '',
    
  126.   REACT_SCHEDULE_HOVER: '',
    
  127.   REACT_SUSPENSE_REJECTED_EVENT: '',
    
  128.   REACT_SUSPENSE_REJECTED_EVENT_HOVER: '',
    
  129.   REACT_SUSPENSE_RESOLVED_EVENT: '',
    
  130.   REACT_SUSPENSE_RESOLVED_EVENT_HOVER: '',
    
  131.   REACT_SUSPENSE_UNRESOLVED_EVENT: '',
    
  132.   REACT_SUSPENSE_UNRESOLVED_EVENT_HOVER: '',
    
  133.   REACT_THROWN_ERROR: '',
    
  134.   REACT_THROWN_ERROR_HOVER: '',
    
  135.   REACT_WORK_BORDER: '',
    
  136.   SCROLL_CARET: '',
    
  137.   SCRUBBER_BACKGROUND: '',
    
  138.   SCRUBBER_BORDER: '',
    
  139.   SEARCH_RESULT_FILL: '',
    
  140.   TEXT_COLOR: '',
    
  141.   TEXT_DIM_COLOR: '',
    
  142.   TIME_MARKER_LABEL: '',
    
  143.   WARNING_BACKGROUND: '',
    
  144.   WARNING_BACKGROUND_HOVER: '',
    
  145.   WARNING_TEXT: '',
    
  146.   WARNING_TEXT_INVERED: '',
    
  147. };
    
  148. 
    
  149. export function updateColorsToMatchTheme(element: Element): boolean {
    
  150.   const computedStyle = getComputedStyle(element);
    
  151. 
    
  152.   // Check to see if styles have been initialized...
    
  153.   if (computedStyle.getPropertyValue('--color-background') == null) {
    
  154.     return false;
    
  155.   }
    
  156. 
    
  157.   COLORS = {
    
  158.     BACKGROUND: computedStyle.getPropertyValue('--color-background'),
    
  159.     INTERNAL_MODULE_FRAME: computedStyle.getPropertyValue(
    
  160.       '--color-timeline-internal-module',
    
  161.     ),
    
  162.     INTERNAL_MODULE_FRAME_HOVER: computedStyle.getPropertyValue(
    
  163.       '--color-timeline-internal-module-hover',
    
  164.     ),
    
  165.     INTERNAL_MODULE_FRAME_TEXT: computedStyle.getPropertyValue(
    
  166.       '--color-timeline-internal-module-text',
    
  167.     ),
    
  168.     NATIVE_EVENT: computedStyle.getPropertyValue(
    
  169.       '--color-timeline-native-event',
    
  170.     ),
    
  171.     NATIVE_EVENT_HOVER: computedStyle.getPropertyValue(
    
  172.       '--color-timeline-native-event-hover',
    
  173.     ),
    
  174.     NETWORK_PRIMARY: computedStyle.getPropertyValue(
    
  175.       '--color-timeline-network-primary',
    
  176.     ),
    
  177.     NETWORK_PRIMARY_HOVER: computedStyle.getPropertyValue(
    
  178.       '--color-timeline-network-primary-hover',
    
  179.     ),
    
  180.     NETWORK_SECONDARY: computedStyle.getPropertyValue(
    
  181.       '--color-timeline-network-secondary',
    
  182.     ),
    
  183.     NETWORK_SECONDARY_HOVER: computedStyle.getPropertyValue(
    
  184.       '--color-timeline-network-secondary-hover',
    
  185.     ),
    
  186.     PRIORITY_BACKGROUND: computedStyle.getPropertyValue(
    
  187.       '--color-timeline-priority-background',
    
  188.     ),
    
  189.     PRIORITY_BORDER: computedStyle.getPropertyValue(
    
  190.       '--color-timeline-priority-border',
    
  191.     ),
    
  192.     PRIORITY_LABEL: computedStyle.getPropertyValue('--color-text'),
    
  193.     USER_TIMING: computedStyle.getPropertyValue('--color-timeline-user-timing'),
    
  194.     USER_TIMING_HOVER: computedStyle.getPropertyValue(
    
  195.       '--color-timeline-user-timing-hover',
    
  196.     ),
    
  197.     REACT_IDLE: computedStyle.getPropertyValue('--color-timeline-react-idle'),
    
  198.     REACT_IDLE_HOVER: computedStyle.getPropertyValue(
    
  199.       '--color-timeline-react-idle-hover',
    
  200.     ),
    
  201.     REACT_RENDER: computedStyle.getPropertyValue(
    
  202.       '--color-timeline-react-render',
    
  203.     ),
    
  204.     REACT_RENDER_HOVER: computedStyle.getPropertyValue(
    
  205.       '--color-timeline-react-render-hover',
    
  206.     ),
    
  207.     REACT_RENDER_TEXT: computedStyle.getPropertyValue(
    
  208.       '--color-timeline-react-render-text',
    
  209.     ),
    
  210.     REACT_COMMIT: computedStyle.getPropertyValue(
    
  211.       '--color-timeline-react-commit',
    
  212.     ),
    
  213.     REACT_COMMIT_HOVER: computedStyle.getPropertyValue(
    
  214.       '--color-timeline-react-commit-hover',
    
  215.     ),
    
  216.     REACT_COMMIT_TEXT: computedStyle.getPropertyValue(
    
  217.       '--color-timeline-react-commit-text',
    
  218.     ),
    
  219.     REACT_LAYOUT_EFFECTS: computedStyle.getPropertyValue(
    
  220.       '--color-timeline-react-layout-effects',
    
  221.     ),
    
  222.     REACT_LAYOUT_EFFECTS_HOVER: computedStyle.getPropertyValue(
    
  223.       '--color-timeline-react-layout-effects-hover',
    
  224.     ),
    
  225.     REACT_LAYOUT_EFFECTS_TEXT: computedStyle.getPropertyValue(
    
  226.       '--color-timeline-react-layout-effects-text',
    
  227.     ),
    
  228.     REACT_PASSIVE_EFFECTS: computedStyle.getPropertyValue(
    
  229.       '--color-timeline-react-passive-effects',
    
  230.     ),
    
  231.     REACT_PASSIVE_EFFECTS_HOVER: computedStyle.getPropertyValue(
    
  232.       '--color-timeline-react-passive-effects-hover',
    
  233.     ),
    
  234.     REACT_PASSIVE_EFFECTS_TEXT: computedStyle.getPropertyValue(
    
  235.       '--color-timeline-react-passive-effects-text',
    
  236.     ),
    
  237.     REACT_RESIZE_BAR: computedStyle.getPropertyValue('--color-resize-bar'),
    
  238.     REACT_RESIZE_BAR_ACTIVE: computedStyle.getPropertyValue(
    
  239.       '--color-resize-bar-active',
    
  240.     ),
    
  241.     REACT_RESIZE_BAR_BORDER: computedStyle.getPropertyValue(
    
  242.       '--color-resize-bar-border',
    
  243.     ),
    
  244.     REACT_RESIZE_BAR_DOT: computedStyle.getPropertyValue(
    
  245.       '--color-resize-bar-dot',
    
  246.     ),
    
  247.     REACT_SCHEDULE: computedStyle.getPropertyValue(
    
  248.       '--color-timeline-react-schedule',
    
  249.     ),
    
  250.     REACT_SCHEDULE_HOVER: computedStyle.getPropertyValue(
    
  251.       '--color-timeline-react-schedule-hover',
    
  252.     ),
    
  253.     REACT_SUSPENSE_REJECTED_EVENT: computedStyle.getPropertyValue(
    
  254.       '--color-timeline-react-suspense-rejected',
    
  255.     ),
    
  256.     REACT_SUSPENSE_REJECTED_EVENT_HOVER: computedStyle.getPropertyValue(
    
  257.       '--color-timeline-react-suspense-rejected-hover',
    
  258.     ),
    
  259.     REACT_SUSPENSE_RESOLVED_EVENT: computedStyle.getPropertyValue(
    
  260.       '--color-timeline-react-suspense-resolved',
    
  261.     ),
    
  262.     REACT_SUSPENSE_RESOLVED_EVENT_HOVER: computedStyle.getPropertyValue(
    
  263.       '--color-timeline-react-suspense-resolved-hover',
    
  264.     ),
    
  265.     REACT_SUSPENSE_UNRESOLVED_EVENT: computedStyle.getPropertyValue(
    
  266.       '--color-timeline-react-suspense-unresolved',
    
  267.     ),
    
  268.     REACT_SUSPENSE_UNRESOLVED_EVENT_HOVER: computedStyle.getPropertyValue(
    
  269.       '--color-timeline-react-suspense-unresolved-hover',
    
  270.     ),
    
  271.     REACT_THROWN_ERROR: computedStyle.getPropertyValue(
    
  272.       '--color-timeline-thrown-error',
    
  273.     ),
    
  274.     REACT_THROWN_ERROR_HOVER: computedStyle.getPropertyValue(
    
  275.       '--color-timeline-thrown-error-hover',
    
  276.     ),
    
  277.     REACT_WORK_BORDER: computedStyle.getPropertyValue(
    
  278.       '--color-timeline-react-work-border',
    
  279.     ),
    
  280.     SCROLL_CARET: computedStyle.getPropertyValue('--color-scroll-caret'),
    
  281.     SCRUBBER_BACKGROUND: computedStyle.getPropertyValue(
    
  282.       '--color-timeline-react-suspense-rejected',
    
  283.     ),
    
  284.     SEARCH_RESULT_FILL: computedStyle.getPropertyValue(
    
  285.       '--color-timeline-react-suspense-rejected',
    
  286.     ),
    
  287.     SCRUBBER_BORDER: computedStyle.getPropertyValue(
    
  288.       '--color-timeline-text-color',
    
  289.     ),
    
  290.     TEXT_COLOR: computedStyle.getPropertyValue('--color-timeline-text-color'),
    
  291.     TEXT_DIM_COLOR: computedStyle.getPropertyValue(
    
  292.       '--color-timeline-text-dim-color',
    
  293.     ),
    
  294.     TIME_MARKER_LABEL: computedStyle.getPropertyValue('--color-text'),
    
  295.     WARNING_BACKGROUND: computedStyle.getPropertyValue(
    
  296.       '--color-warning-background',
    
  297.     ),
    
  298.     WARNING_BACKGROUND_HOVER: computedStyle.getPropertyValue(
    
  299.       '--color-warning-background-hover',
    
  300.     ),
    
  301.     WARNING_TEXT: computedStyle.getPropertyValue('--color-warning-text-color'),
    
  302.     WARNING_TEXT_INVERED: computedStyle.getPropertyValue(
    
  303.       '--color-warning-text-color-inverted',
    
  304.     ),
    
  305.   };
    
  306. 
    
  307.   return true;
    
  308. }