@deephaven/components 0.108.1-beta.8 → 0.108.1-input-filters.21
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.
- package/dist/theme/ThemeModel.d.ts +1 -12
- package/dist/theme/ThemeModel.d.ts.map +1 -1
- package/dist/theme/ThemeModel.js +0 -9
- package/dist/theme/ThemeModel.js.map +1 -1
- package/dist/theme/ThemeProvider.d.ts +1 -2
- package/dist/theme/ThemeProvider.d.ts.map +1 -1
- package/dist/theme/ThemeProvider.js +0 -4
- package/dist/theme/ThemeProvider.js.map +1 -1
- package/dist/theme/ThemeUtils.d.ts +7 -54
- package/dist/theme/ThemeUtils.d.ts.map +1 -1
- package/dist/theme/ThemeUtils.js +19 -130
- package/dist/theme/ThemeUtils.js.map +1 -1
- package/dist/theme/index.d.ts +0 -1
- package/dist/theme/index.d.ts.map +1 -1
- package/dist/theme/index.js +0 -1
- package/dist/theme/index.js.map +1 -1
- package/package.json +8 -8
- package/dist/theme/useExternalTheme.d.ts +0 -15
- package/dist/theme/useExternalTheme.d.ts.map +0 -1
- package/dist/theme/useExternalTheme.js +0 -68
- package/dist/theme/useExternalTheme.js.map +0 -1
|
@@ -2,16 +2,11 @@ export type BaseThemeType = 'dark' | 'light';
|
|
|
2
2
|
export type BaseThemeKey = `default-${BaseThemeType}`;
|
|
3
3
|
export type CssVariableStyleContent = `:root{${string}`;
|
|
4
4
|
export type ThemeCssVariableName = `--dh-${string}`;
|
|
5
|
-
export type ThemeCssColorVariableName = `--dh-color-${string}`;
|
|
6
5
|
export type ThemePreloadColorVariable = '--dh-color-accent-contrast' | '--dh-color-accent-bg' | '--dh-color-accent-hover-bg' | '--dh-color-accent-down-bg' | '--dh-color-accent-key-focus-bg' | '--dh-color-negative-bg' | '--dh-color-loading-spinner-primary' | '--dh-color-loading-spinner-secondary' | '--dh-color-bg' | '--dh-color-fg' | '--dh-color-input-bg' | '--dh-color-input-fg' | '--dh-color-input-disabled-bg' | '--dh-color-input-border' | '--dh-color-input-placeholder' | '--dh-color-input-focus-border' | '--dh-color-text-highlight' | '--dh-color-login-form-bg' | '--dh-color-login-status-message' | '--dh-color-login-logo-bg' | '--dh-color-login-footer-fg' | '--dh-color-random-area-plot-animation-fg-fill' | '--dh-color-random-area-plot-animation-fg-stroke' | '--dh-color-random-area-plot-animation-bg' | '--dh-color-random-area-plot-animation-grid';
|
|
7
6
|
export type ThemeIconsRequiringManualColorChanges = '--dh-svg-icon-select-indicator' | '--dh-svg-icon-select-indicator-hover' | '--dh-svg-icon-select-indicator-disabled' | '--dh-svg-icon-error';
|
|
8
7
|
export declare const DEFAULT_DARK_THEME_KEY = "default-dark";
|
|
9
8
|
export declare const DEFAULT_LIGHT_THEME_KEY = "default-light";
|
|
10
|
-
export declare const
|
|
11
|
-
export declare const MSG_REQUEST_GET_THEME = "io.deephaven.message.ThemeModel.requestExternalTheme";
|
|
12
|
-
export declare const MSG_REQUEST_SET_THEME = "io.deephaven.message.ThemeModel.requestSetTheme";
|
|
13
|
-
export declare const PRELOAD_TRANSPARENT_THEME_QUERY_PARAM: "preloadTransparentTheme";
|
|
14
|
-
export declare const THEME_KEY_OVERRIDE_QUERY_PARAM: "theme";
|
|
9
|
+
export declare const THEME_KEY_OVERRIDE_QUERY_PARAM = "theme";
|
|
15
10
|
export declare const DEFAULT_DARK_THEME_PALETTE: {
|
|
16
11
|
readonly blue: {
|
|
17
12
|
readonly 500: "#2f5bc0";
|
|
@@ -35,7 +30,6 @@ export declare const DEFAULT_DARK_THEME_PALETTE: {
|
|
|
35
30
|
};
|
|
36
31
|
};
|
|
37
32
|
export declare const DEFAULT_PRELOAD_DATA_VARIABLES: Record<ThemePreloadColorVariable, string>;
|
|
38
|
-
export declare const TRANSPARENT_PRELOAD_DATA_VARIABLES: Partial<Record<ThemePreloadColorVariable, string>>;
|
|
39
33
|
/**
|
|
40
34
|
* Some inline SVGs require manually updating their fill color via
|
|
41
35
|
* `updateSVGFillColors`. This object maps these variables to their respective
|
|
@@ -57,9 +51,4 @@ export interface ThemeRegistrationData {
|
|
|
57
51
|
base: ThemeData[];
|
|
58
52
|
custom: ThemeData[];
|
|
59
53
|
}
|
|
60
|
-
export interface ExternalThemeData {
|
|
61
|
-
baseThemeKey?: BaseThemeKey;
|
|
62
|
-
name: string;
|
|
63
|
-
cssVars: Record<ThemeCssColorVariableName, string>;
|
|
64
|
-
}
|
|
65
54
|
//# sourceMappingURL=ThemeModel.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ThemeModel.d.ts","sourceRoot":"","sources":["../../src/theme/ThemeModel.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,OAAO,CAAC;AAC7C,MAAM,MAAM,YAAY,GAAG,WAAW,aAAa,EAAE,CAAC;AACtD,MAAM,MAAM,uBAAuB,GAAG,SAAS,MAAM,EAAE,CAAC;AACxD,MAAM,MAAM,oBAAoB,GAAG,QAAQ,MAAM,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"ThemeModel.d.ts","sourceRoot":"","sources":["../../src/theme/ThemeModel.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,OAAO,CAAC;AAC7C,MAAM,MAAM,YAAY,GAAG,WAAW,aAAa,EAAE,CAAC;AACtD,MAAM,MAAM,uBAAuB,GAAG,SAAS,MAAM,EAAE,CAAC;AACxD,MAAM,MAAM,oBAAoB,GAAG,QAAQ,MAAM,EAAE,CAAC;AAOpD,MAAM,MAAM,yBAAyB,GACjC,4BAA4B,GAC5B,sBAAsB,GACtB,4BAA4B,GAC5B,2BAA2B,GAC3B,gCAAgC,GAChC,wBAAwB,GACxB,oCAAoC,GACpC,sCAAsC,GACtC,eAAe,GACf,eAAe,GACf,qBAAqB,GACrB,qBAAqB,GACrB,8BAA8B,GAC9B,yBAAyB,GACzB,8BAA8B,GAC9B,+BAA+B,GAC/B,2BAA2B,GAC3B,0BAA0B,GAC1B,iCAAiC,GACjC,0BAA0B,GAC1B,4BAA4B,GAC5B,+CAA+C,GAC/C,iDAAiD,GACjD,0CAA0C,GAC1C,4CAA4C,CAAC;AAEjD,MAAM,MAAM,qCAAqC,GAC7C,gCAAgC,GAChC,sCAAsC,GACtC,yCAAyC,GACzC,qBAAqB,CAAC;AAE1B,eAAO,MAAM,sBAAsB,iBAAwC,CAAC;AAC5E,eAAO,MAAM,uBAAuB,kBAAyC,CAAC;AAC9E,eAAO,MAAM,8BAA8B,UAAU,CAAC;AAItD,eAAO,MAAM,0BAA0B;;;;;;;;;;;;;;;;;;;;;CAqB7B,CAAC;AAQX,eAAO,MAAM,8BAA8B,EAAE,MAAM,CACjD,yBAAyB,EACzB,MAAM,CA6BP,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,yBAAyB,EAAE,MAAM,CAC5C,qCAAqC,EACrC,MAAM,CAMP,CAAC;AAEF,eAAO,MAAM,6BAA6B,yBAAyB,CAAC;AAEpE,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,MAAM,CAAC;IACjB,mBAAmB,CAAC,EAAE,uBAAuB,CAAC;CAC/C;AAED,MAAM,WAAW,SAAS;IACxB,YAAY,CAAC,EAAE,YAAY,CAAC;IAC5B,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,qBAAqB;IACpC,IAAI,EAAE,SAAS,EAAE,CAAC;IAClB,MAAM,EAAE,SAAS,EAAE,CAAC;CACrB"}
|
package/dist/theme/ThemeModel.js
CHANGED
|
@@ -5,10 +5,6 @@
|
|
|
5
5
|
// codebase. To be addressed by #1679
|
|
6
6
|
export var DEFAULT_DARK_THEME_KEY = 'default-dark';
|
|
7
7
|
export var DEFAULT_LIGHT_THEME_KEY = 'default-light';
|
|
8
|
-
export var EXTERNAL_THEME_KEY = 'external-theme';
|
|
9
|
-
export var MSG_REQUEST_GET_THEME = 'io.deephaven.message.ThemeModel.requestExternalTheme';
|
|
10
|
-
export var MSG_REQUEST_SET_THEME = 'io.deephaven.message.ThemeModel.requestSetTheme';
|
|
11
|
-
export var PRELOAD_TRANSPARENT_THEME_QUERY_PARAM = 'preloadTransparentTheme';
|
|
12
8
|
export var THEME_KEY_OVERRIDE_QUERY_PARAM = 'theme';
|
|
13
9
|
|
|
14
10
|
// Hex versions of some of the default dark theme color palette needed for
|
|
@@ -75,11 +71,6 @@ export var DEFAULT_PRELOAD_DATA_VARIABLES = {
|
|
|
75
71
|
'--dh-color-random-area-plot-animation-bg': DEFAULT_DARK_THEME_PALETTE.gray[75],
|
|
76
72
|
'--dh-color-random-area-plot-animation-grid': DEFAULT_DARK_THEME_PALETTE.gray[300]
|
|
77
73
|
};
|
|
78
|
-
export var TRANSPARENT_PRELOAD_DATA_VARIABLES = {
|
|
79
|
-
'--dh-color-bg': 'transparent',
|
|
80
|
-
'--dh-color-loading-spinner-primary': 'transparent',
|
|
81
|
-
'--dh-color-loading-spinner-secondary': 'transparent'
|
|
82
|
-
};
|
|
83
74
|
|
|
84
75
|
/**
|
|
85
76
|
* Some inline SVGs require manually updating their fill color via
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ThemeModel.js","names":["DEFAULT_DARK_THEME_KEY","DEFAULT_LIGHT_THEME_KEY","
|
|
1
|
+
{"version":3,"file":"ThemeModel.js","names":["DEFAULT_DARK_THEME_KEY","DEFAULT_LIGHT_THEME_KEY","THEME_KEY_OVERRIDE_QUERY_PARAM","DEFAULT_DARK_THEME_PALETTE","blue","red","gray","DEFAULT_PRELOAD_DATA_VARIABLES","concat","SVG_ICON_MANUAL_COLOR_MAP","THEME_CACHE_LOCAL_STORAGE_KEY"],"sources":["../../src/theme/ThemeModel.ts"],"sourcesContent":["export type BaseThemeType = 'dark' | 'light';\nexport type BaseThemeKey = `default-${BaseThemeType}`;\nexport type CssVariableStyleContent = `:root{${string}`;\nexport type ThemeCssVariableName = `--dh-${string}`;\n\n// DHC should only need to preload variables that are required by the empty page\n// with loading spinner that shows while plugins are loading. The rest of the\n// preload variables defined here are required by DHE due to theme plugins\n// loading after login. We should consider moving most of these to the DHE\n// codebase. To be addressed by #1679\nexport type ThemePreloadColorVariable =\n | '--dh-color-accent-contrast'\n | '--dh-color-accent-bg'\n | '--dh-color-accent-hover-bg'\n | '--dh-color-accent-down-bg'\n | '--dh-color-accent-key-focus-bg'\n | '--dh-color-negative-bg'\n | '--dh-color-loading-spinner-primary'\n | '--dh-color-loading-spinner-secondary'\n | '--dh-color-bg'\n | '--dh-color-fg'\n | '--dh-color-input-bg'\n | '--dh-color-input-fg'\n | '--dh-color-input-disabled-bg'\n | '--dh-color-input-border'\n | '--dh-color-input-placeholder'\n | '--dh-color-input-focus-border'\n | '--dh-color-text-highlight'\n | '--dh-color-login-form-bg'\n | '--dh-color-login-status-message'\n | '--dh-color-login-logo-bg'\n | '--dh-color-login-footer-fg'\n | '--dh-color-random-area-plot-animation-fg-fill'\n | '--dh-color-random-area-plot-animation-fg-stroke'\n | '--dh-color-random-area-plot-animation-bg'\n | '--dh-color-random-area-plot-animation-grid';\n\nexport type ThemeIconsRequiringManualColorChanges =\n | '--dh-svg-icon-select-indicator'\n | '--dh-svg-icon-select-indicator-hover'\n | '--dh-svg-icon-select-indicator-disabled'\n | '--dh-svg-icon-error';\n\nexport const DEFAULT_DARK_THEME_KEY = 'default-dark' satisfies BaseThemeKey;\nexport const DEFAULT_LIGHT_THEME_KEY = 'default-light' satisfies BaseThemeKey;\nexport const THEME_KEY_OVERRIDE_QUERY_PARAM = 'theme';\n\n// Hex versions of some of the default dark theme color palette needed for\n// preload defaults.\nexport const DEFAULT_DARK_THEME_PALETTE = {\n blue: {\n 500: '#2f5bc0',\n 400: '#254ba4',\n 600: '#3b6bda', // accent color\n 700: '#4c7dee',\n },\n red: {\n 600: '#c73f61',\n },\n gray: {\n 50: '#1a171a',\n 75: '#211f22',\n 300: '#373438',\n 400: '#403e41',\n 500: '#5b5a5c',\n 600: '#929192',\n 700: '#c0bfbf',\n 800: '#f0f0ee',\n 900: '#fcfcfa',\n },\n} as const;\n\n// Css properties that are used in preload data with default values.\n// DHC should only need to preload variables that are required by the empty page\n// with loading spinner that shows while plugins are loading. The rest of the\n// preload variables defined here are required by DHE due to theme plugins\n// loading after login. We should consider moving most of these to the DHE\n// codebase. To be addressed by #1679\nexport const DEFAULT_PRELOAD_DATA_VARIABLES: Record<\n ThemePreloadColorVariable,\n string\n> = {\n '--dh-color-accent-contrast': DEFAULT_DARK_THEME_PALETTE.gray[900],\n '--dh-color-accent-bg': DEFAULT_DARK_THEME_PALETTE.blue[600],\n '--dh-color-accent-hover-bg': DEFAULT_DARK_THEME_PALETTE.blue[500],\n '--dh-color-accent-down-bg': DEFAULT_DARK_THEME_PALETTE.blue[400],\n '--dh-color-accent-key-focus-bg': DEFAULT_DARK_THEME_PALETTE.blue[500],\n '--dh-color-negative-bg': DEFAULT_DARK_THEME_PALETTE.red[600],\n '--dh-color-loading-spinner-primary': DEFAULT_DARK_THEME_PALETTE.blue[600],\n '--dh-color-loading-spinner-secondary': `${DEFAULT_DARK_THEME_PALETTE.gray[800]}80`, // 50% opacity\n '--dh-color-bg': DEFAULT_DARK_THEME_PALETTE.gray[50],\n '--dh-color-fg': DEFAULT_DARK_THEME_PALETTE.gray[800],\n '--dh-color-input-bg': DEFAULT_DARK_THEME_PALETTE.gray[500],\n '--dh-color-input-fg': DEFAULT_DARK_THEME_PALETTE.gray[800],\n '--dh-color-input-disabled-bg': DEFAULT_DARK_THEME_PALETTE.gray[300],\n '--dh-color-input-border': DEFAULT_DARK_THEME_PALETTE.gray[600],\n '--dh-color-input-placeholder': DEFAULT_DARK_THEME_PALETTE.gray[600],\n '--dh-color-input-focus-border': `${DEFAULT_DARK_THEME_PALETTE.blue[600]}d9`, // 85% opacity\n '--dh-color-text-highlight': `${DEFAULT_DARK_THEME_PALETTE.blue[700]}4d`, // 30% opacity\n '--dh-color-login-form-bg': DEFAULT_DARK_THEME_PALETTE.gray[400],\n '--dh-color-login-status-message': DEFAULT_DARK_THEME_PALETTE.gray[600],\n '--dh-color-login-logo-bg': DEFAULT_DARK_THEME_PALETTE.gray[900],\n '--dh-color-login-footer-fg': DEFAULT_DARK_THEME_PALETTE.gray[700],\n '--dh-color-random-area-plot-animation-fg-fill': `${DEFAULT_DARK_THEME_PALETTE.blue[600]}14`, // .08 opacity\n '--dh-color-random-area-plot-animation-fg-stroke': `${DEFAULT_DARK_THEME_PALETTE.blue[600]}33`, // .2 opacity\n '--dh-color-random-area-plot-animation-bg':\n DEFAULT_DARK_THEME_PALETTE.gray[75],\n '--dh-color-random-area-plot-animation-grid':\n DEFAULT_DARK_THEME_PALETTE.gray[300],\n};\n\n/**\n * Some inline SVGs require manually updating their fill color via\n * `updateSVGFillColors`. This object maps these variables to their respective\n * fill color variables.\n */\nexport const SVG_ICON_MANUAL_COLOR_MAP: Record<\n ThemeIconsRequiringManualColorChanges,\n string\n> = {\n '--dh-svg-icon-select-indicator': '--dh-color-selector-fg',\n '--dh-svg-icon-select-indicator-hover': '--dh-color-selector-hover-fg',\n '--dh-svg-icon-select-indicator-disabled': '--dh-color-selector-disabled-fg',\n '--dh-svg-icon-error': '--dh-color-form-control-error',\n};\n\nexport const THEME_CACHE_LOCAL_STORAGE_KEY = 'deephaven.themeCache';\n\nexport interface ThemePreloadData {\n themeKey: string;\n preloadStyleContent?: CssVariableStyleContent;\n}\n\nexport interface ThemeData {\n baseThemeKey?: BaseThemeKey;\n themeKey: string;\n name: string;\n styleContent: string;\n}\n\nexport interface ThemeRegistrationData {\n base: ThemeData[];\n custom: ThemeData[];\n}\n"],"mappings":"AAKA;AACA;AACA;AACA;AACA;AAkCA,OAAO,IAAMA,sBAAsB,GAAG,cAAqC;AAC3E,OAAO,IAAMC,uBAAuB,GAAG,eAAsC;AAC7E,OAAO,IAAMC,8BAA8B,GAAG,OAAO;;AAErD;AACA;AACA,OAAO,IAAMC,0BAA0B,GAAG;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,0BAA0B,CAACG,IAAI,CAAC,GAAG,CAAC;EACpE,yBAAyB,EAAEH,0BAA0B,CAACG,IAAI,CAAC,GAAG,CAAC;EAC/D,8BAA8B,EAAEH,0BAA0B,CAACG,IAAI,CAAC,GAAG,CAAC;EACpE,+BAA+B,KAAAE,MAAA,CAAKL,0BAA0B,CAACC,IAAI,CAAC,GAAG,CAAC,OAAI;EAAE;EAC9E,2BAA2B,KAAAI,MAAA,CAAKL,0BAA0B,CAACC,IAAI,CAAC,GAAG,CAAC,OAAI;EAAE;EAC1E,0BAA0B,EAAED,0BAA0B,CAACG,IAAI,CAAC,GAAG,CAAC;EAChE,iCAAiC,EAAEH,0BAA0B,CAACG,IAAI,CAAC,GAAG,CAAC;EACvE,0BAA0B,EAAEH,0BAA0B,CAACG,IAAI,CAAC,GAAG,CAAC;EAChE,4BAA4B,EAAEH,0BAA0B,CAACG,IAAI,CAAC,GAAG,CAAC;EAClE,+CAA+C,KAAAE,MAAA,CAAKL,0BAA0B,CAACC,IAAI,CAAC,GAAG,CAAC,OAAI;EAAE;EAC9F,iDAAiD,KAAAI,MAAA,CAAKL,0BAA0B,CAACC,IAAI,CAAC,GAAG,CAAC,OAAI;EAAE;EAChG,0CAA0C,EACxCD,0BAA0B,CAACG,IAAI,CAAC,EAAE,CAAC;EACrC,4CAA4C,EAC1CH,0BAA0B,CAACG,IAAI,CAAC,GAAG;AACvC,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA,OAAO,IAAMG,yBAGZ,GAAG;EACF,gCAAgC,EAAE,wBAAwB;EAC1D,sCAAsC,EAAE,8BAA8B;EACtE,yCAAyC,EAAE,iCAAiC;EAC5E,qBAAqB,EAAE;AACzB,CAAC;AAED,OAAO,IAAMC,6BAA6B,GAAG,sBAAsB"}
|
|
@@ -10,10 +10,9 @@ export interface ThemeContextValue {
|
|
|
10
10
|
export declare const ThemeContext: import("react").Context<ThemeContextValue | null>;
|
|
11
11
|
export interface ThemeProviderProps {
|
|
12
12
|
themes: ThemeData[] | null;
|
|
13
|
-
waitForActivation?: boolean;
|
|
14
13
|
defaultPreloadValues?: Record<string, string>;
|
|
15
14
|
children: ReactNode;
|
|
16
15
|
}
|
|
17
|
-
export declare function ThemeProvider({ themes: customThemes,
|
|
16
|
+
export declare function ThemeProvider({ themes: customThemes, defaultPreloadValues, children, }: ThemeProviderProps): JSX.Element | null;
|
|
18
17
|
export default ThemeProvider;
|
|
19
18
|
//# sourceMappingURL=ThemeProvider.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ThemeProvider.d.ts","sourceRoot":"","sources":["../../src/theme/ThemeProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,SAAS,EAIf,MAAM,OAAO,CAAC;AAEf,OAAO,EAAkC,KAAK,SAAS,EAAE,MAAM,cAAc,CAAC;AAU9E,OAAO,kBAAkB,CAAC;AAE1B,MAAM,WAAW,iBAAiB;IAChC,YAAY,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC;IACjC,gBAAgB,EAAE,MAAM,CAAC;IACzB,MAAM,EAAE,SAAS,EAAE,CAAC;IACpB,mBAAmB,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAC;CACjD;AAID,eAAO,MAAM,YAAY,mDAAgD,CAAC;AAE1E,MAAM,WAAW,kBAAkB;IAMjC,MAAM,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"ThemeProvider.d.ts","sourceRoot":"","sources":["../../src/theme/ThemeProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,SAAS,EAIf,MAAM,OAAO,CAAC;AAEf,OAAO,EAAkC,KAAK,SAAS,EAAE,MAAM,cAAc,CAAC;AAU9E,OAAO,kBAAkB,CAAC;AAE1B,MAAM,WAAW,iBAAiB;IAChC,YAAY,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC;IACjC,gBAAgB,EAAE,MAAM,CAAC;IACzB,MAAM,EAAE,SAAS,EAAE,CAAC;IACpB,mBAAmB,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAC;CACjD;AAID,eAAO,MAAM,YAAY,mDAAgD,CAAC;AAE1E,MAAM,WAAW,kBAAkB;IAMjC,MAAM,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC;IAC3B,oBAAoB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC9C,QAAQ,EAAE,SAAS,CAAC;CACrB;AAED,wBAAgB,aAAa,CAAC,EAC5B,MAAM,EAAE,YAAY,EACpB,oBAAqD,EACrD,QAAQ,GACT,EAAE,kBAAkB,GAAG,GAAG,CAAC,OAAO,GAAG,IAAI,CAkFzC;AAED,eAAe,aAAa,CAAC"}
|
|
@@ -12,7 +12,6 @@ export var ThemeContext = /*#__PURE__*/createContext(null);
|
|
|
12
12
|
export function ThemeProvider(_ref) {
|
|
13
13
|
var {
|
|
14
14
|
themes: customThemes,
|
|
15
|
-
waitForActivation = false,
|
|
16
15
|
defaultPreloadValues = DEFAULT_PRELOAD_DATA_VARIABLES,
|
|
17
16
|
children
|
|
18
17
|
} = _ref;
|
|
@@ -55,9 +54,6 @@ export function ThemeProvider(_ref) {
|
|
|
55
54
|
setSelectedThemeKey
|
|
56
55
|
});
|
|
57
56
|
}, [activeThemes, selectedThemeKey, themes]);
|
|
58
|
-
if (waitForActivation && activeThemes == null) {
|
|
59
|
-
return null;
|
|
60
|
-
}
|
|
61
57
|
return /*#__PURE__*/_jsxs(_Fragment, {
|
|
62
58
|
children: [activeThemes == null ? null : /*#__PURE__*/_jsx(_Fragment, {
|
|
63
59
|
children: activeThemes.map(theme => /*#__PURE__*/_jsx("style", {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ThemeProvider.js","names":["createContext","useEffect","useMemo","useState","Log","DEFAULT_PRELOAD_DATA_VARIABLES","calculatePreloadStyleContent","getActiveThemes","getDefaultBaseThemes","setThemePreloadData","overrideSVGFillColors","getDefaultSelectedThemeKey","SpectrumThemeProvider","jsx","_jsx","Fragment","_Fragment","jsxs","_jsxs","log","module","ThemeContext","ThemeProvider","_ref","themes","customThemes","
|
|
1
|
+
{"version":3,"file":"ThemeProvider.js","names":["createContext","useEffect","useMemo","useState","Log","DEFAULT_PRELOAD_DATA_VARIABLES","calculatePreloadStyleContent","getActiveThemes","getDefaultBaseThemes","setThemePreloadData","overrideSVGFillColors","getDefaultSelectedThemeKey","SpectrumThemeProvider","jsx","_jsx","Fragment","_Fragment","jsxs","_jsxs","log","module","ThemeContext","ThemeProvider","_ref","themes","customThemes","defaultPreloadValues","children","baseThemes","value","setValue","selectedThemeKey","setSelectedThemeKey","activeThemes","base","custom","updateThemePreloadData","preloadStyleContent","debug2","active","map","theme","themeKey","styleContent","Provider"],"sources":["../../src/theme/ThemeProvider.tsx"],"sourcesContent":["import {\n createContext,\n type ReactNode,\n useEffect,\n useMemo,\n useState,\n} from 'react';\nimport Log from '@deephaven/log';\nimport { DEFAULT_PRELOAD_DATA_VARIABLES, type ThemeData } from './ThemeModel';\nimport {\n calculatePreloadStyleContent,\n getActiveThemes,\n getDefaultBaseThemes,\n setThemePreloadData,\n overrideSVGFillColors,\n getDefaultSelectedThemeKey,\n} from './ThemeUtils';\nimport { SpectrumThemeProvider } from './SpectrumThemeProvider';\nimport './theme-svg.scss';\n\nexport interface ThemeContextValue {\n activeThemes: ThemeData[] | null;\n selectedThemeKey: string;\n themes: ThemeData[];\n setSelectedThemeKey: (themeKey: string) => void;\n}\n\nconst log = Log.module('ThemeProvider');\n\nexport const ThemeContext = createContext<ThemeContextValue | null>(null);\n\nexport interface ThemeProviderProps {\n /*\n * Additional themes to load in addition to the base themes. If no additional\n * themes are to be loaded, this must be set to an empty array in order to\n * tell the provider to activate the base themes.\n */\n themes: ThemeData[] | null;\n defaultPreloadValues?: Record<string, string>;\n children: ReactNode;\n}\n\nexport function ThemeProvider({\n themes: customThemes,\n defaultPreloadValues = DEFAULT_PRELOAD_DATA_VARIABLES,\n children,\n}: ThemeProviderProps): JSX.Element | null {\n const baseThemes = useMemo(() => getDefaultBaseThemes(), []);\n\n const [value, setValue] = useState<ThemeContextValue | null>(null);\n\n const [selectedThemeKey, setSelectedThemeKey] = useState<string>(\n getDefaultSelectedThemeKey\n );\n\n // Calculate active themes once a non-null themes array is provided.\n const activeThemes = useMemo(\n () =>\n customThemes == null\n ? null\n : getActiveThemes(selectedThemeKey, {\n base: baseThemes,\n custom: customThemes ?? [],\n }),\n [baseThemes, selectedThemeKey, customThemes]\n );\n\n const themes = useMemo(\n () => [...baseThemes, ...(customThemes ?? [])],\n [baseThemes, customThemes]\n );\n\n useEffect(\n function updateThemePreloadData() {\n // Don't update preload data until themes have been loaded and activated\n if (activeThemes == null || customThemes == null) {\n return;\n }\n\n // Override fill color for certain inline SVGs (the originals are provided\n // by theme-svg.scss)\n overrideSVGFillColors(defaultPreloadValues);\n\n const preloadStyleContent =\n calculatePreloadStyleContent(defaultPreloadValues);\n\n log.debug2('updateThemePreloadData:', {\n active: activeThemes.map(theme => theme.themeKey),\n custom: customThemes.map(theme => theme.themeKey),\n preloadStyleContent,\n selectedThemeKey,\n });\n\n setThemePreloadData({\n themeKey: selectedThemeKey,\n preloadStyleContent,\n });\n },\n [activeThemes, selectedThemeKey, customThemes, defaultPreloadValues]\n );\n\n useEffect(() => {\n setValue({\n activeThemes,\n selectedThemeKey,\n themes,\n setSelectedThemeKey,\n });\n }, [activeThemes, selectedThemeKey, themes]);\n\n return (\n <>\n {activeThemes == null ? null : (\n <>\n {activeThemes.map(theme => (\n <style data-theme-key={theme.themeKey} key={theme.themeKey}>\n {theme.styleContent}\n </style>\n ))}\n </>\n )}\n {value == null ? null : (\n <ThemeContext.Provider value={value}>\n <SpectrumThemeProvider>{children}</SpectrumThemeProvider>\n </ThemeContext.Provider>\n )}\n </>\n );\n}\n\nexport default ThemeProvider;\n"],"mappings":"AAAA,SACEA,aAAa,EAEbC,SAAS,EACTC,OAAO,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IAAI,gBACnBf,IAAA,CAACO,YAAY,CAACuB,QAAQ;MAACf,KAAK,EAAEA,KAAM;MAAAF,QAAA,eAClCb,IAAA,CAACF,qBAAqB;QAAAe,QAAA,EAAEA;MAAQ,CAAwB;IAAC,CACpC,CACxB;EAAA,CACD,CAAC;AAEP;AAEA,eAAeL,aAAa"}
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type ThemeData, type ThemePreloadData, type CssVariableStyleContent, type ThemeRegistrationData, type ThemeCssVariableName } from './ThemeModel';
|
|
2
2
|
export declare const CSS_VAR_EXPRESSION_PREFIX = "var(--";
|
|
3
|
-
export declare const DH_VAR_PREFIX = "--dh-color-";
|
|
4
3
|
export declare const TMP_CSS_PROP_PREFIX = "dh-tmp";
|
|
5
4
|
export declare const NON_WHITESPACE_REGEX: RegExp;
|
|
6
5
|
export declare const WHITESPACE_REGEX: RegExp;
|
|
7
|
-
export declare const DH_CSS_VAR_NAME_REGEXP: RegExp;
|
|
8
6
|
export type VarExpressionResolver = (varExpression: string) => string;
|
|
9
7
|
/**
|
|
10
8
|
* Resolves the current values of CSS variables we want to preload. Preloading
|
|
@@ -52,12 +50,6 @@ export declare function getDefaultBaseThemes(): ThemeData[];
|
|
|
52
50
|
* @returns The default selected theme key
|
|
53
51
|
*/
|
|
54
52
|
export declare function getDefaultSelectedThemeKey(): string;
|
|
55
|
-
/**
|
|
56
|
-
* Derive unique theme key from plugin root path and theme name.
|
|
57
|
-
* @param pluginName The root path of the plugin
|
|
58
|
-
* @param themeName The name of the theme
|
|
59
|
-
*/
|
|
60
|
-
export declare function getThemeKey(pluginName: string, themeName: string): string;
|
|
61
53
|
/**
|
|
62
54
|
* A theme key override can be set via a query parameter to force a specific
|
|
63
55
|
* theme selection. Useful for embedded widget scenarios that don't expose the
|
|
@@ -96,45 +88,6 @@ export declare function getThemePreloadData(): ThemePreloadData | null;
|
|
|
96
88
|
* @returns An array of [start, end] index pairs for each expression
|
|
97
89
|
*/
|
|
98
90
|
export declare function getExpressionRanges(value: string): [number, number][];
|
|
99
|
-
/**
|
|
100
|
-
* Check if the given theme key is one of the base themes.
|
|
101
|
-
* @param themeKey The theme key to check
|
|
102
|
-
* @returns True if the theme key is a base theme key, false otherwise
|
|
103
|
-
*/
|
|
104
|
-
export declare function isBaseThemeKey(themeKey: string): themeKey is BaseThemeKey;
|
|
105
|
-
/**
|
|
106
|
-
* Determine if a given object is a `ExternalThemeData` object.
|
|
107
|
-
* @param maybeExternalThemeData An object that may or may not be a `ExternalThemeData`
|
|
108
|
-
* @returns True if the object is a `ExternalThemeData`, false otherwise
|
|
109
|
-
*/
|
|
110
|
-
export declare function isExternalThemeData(maybeExternalThemeData: unknown): maybeExternalThemeData is ExternalThemeData;
|
|
111
|
-
/**
|
|
112
|
-
* Check if the current URL specifies an external theme key override.
|
|
113
|
-
* @returns True if the external theme key override is set, false otherwise
|
|
114
|
-
*/
|
|
115
|
-
export declare function isExternalThemeEnabled(): boolean;
|
|
116
|
-
/**
|
|
117
|
-
* Check if PRELOAD_TRANSPARENT_THEME_QUERY_PARAM query parameter is set to true.
|
|
118
|
-
* @returns True if the preload transparent theme query parameter is set, false
|
|
119
|
-
* otherwise
|
|
120
|
-
*/
|
|
121
|
-
export declare function isPreloadTransparentTheme(): boolean;
|
|
122
|
-
/**
|
|
123
|
-
* Validate that a given CSS variable name / value pair is a valid Deephaven
|
|
124
|
-
* color variable.
|
|
125
|
-
* @param name The name of the CSS variable to validate, e.g. '--dh-color-primary'
|
|
126
|
-
* @param value The value of the CSS color to validate
|
|
127
|
-
* @returns True if the name is a valid Deephaven color variable and the value
|
|
128
|
-
* is a valid CSS color, false otherwise
|
|
129
|
-
*/
|
|
130
|
-
export declare function isValidColorVar(name: string, value: string): name is ThemeCssColorVariableName;
|
|
131
|
-
/**
|
|
132
|
-
* Parse external theme data into a `ThemeData` object. Invalid CSS color variable
|
|
133
|
-
* pairs are excluded from the resulting `ThemeData` object.
|
|
134
|
-
* @param externalThemeData The external theme data to parse
|
|
135
|
-
* @returns A `ThemeData` object representing the external theme
|
|
136
|
-
*/
|
|
137
|
-
export declare function parseExternalThemeData({ baseThemeKey, name, cssVars, }: ExternalThemeData): ThemeData;
|
|
138
91
|
/**
|
|
139
92
|
* Replace the `fill='...'` attribute in the given SVG content with the given
|
|
140
93
|
* color string.
|
|
@@ -142,12 +95,6 @@ export declare function parseExternalThemeData({ baseThemeKey, name, cssVars, }:
|
|
|
142
95
|
* @param fillColor The color to replace the fill color with
|
|
143
96
|
*/
|
|
144
97
|
export declare function replaceSVGFillColor(svgContent: string, fillColor: string): string;
|
|
145
|
-
/**
|
|
146
|
-
* Request theme data from the parent window.
|
|
147
|
-
* @returns A promise that resolves to the external theme data
|
|
148
|
-
* @throws Error if the response is not a valid `ExternalThemeData`
|
|
149
|
-
*/
|
|
150
|
-
export declare function requestExternalThemeData(): Promise<ExternalThemeData>;
|
|
151
98
|
/**
|
|
152
99
|
* Make a copy of the given object replacing any css variable expressions
|
|
153
100
|
* contained in its prop values with values resolved from the given HTML element.
|
|
@@ -182,6 +129,12 @@ export declare function resolveCssVariablesInString(resolver: VarExpressionResol
|
|
|
182
129
|
* @param preloadData The preload data to set
|
|
183
130
|
*/
|
|
184
131
|
export declare function setThemePreloadData(preloadData: ThemePreloadData): void;
|
|
132
|
+
/**
|
|
133
|
+
* Derive unique theme key from plugin root path and theme name.
|
|
134
|
+
* @param pluginName The root path of the plugin
|
|
135
|
+
* @param themeName The name of the theme
|
|
136
|
+
*/
|
|
137
|
+
export declare function getThemeKey(pluginName: string, themeName: string): string;
|
|
185
138
|
/**
|
|
186
139
|
* Preload minimal theme variables from the cache.
|
|
187
140
|
* @defaultPreloadValues Optional default values to use if a preload variable is not set.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ThemeUtils.d.ts","sourceRoot":"","sources":["../../src/theme/ThemeUtils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ThemeUtils.d.ts","s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n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
|
|
2
|
-
function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
|
|
3
1
|
import Log from '@deephaven/log';
|
|
4
|
-
import { assertNotNull, ColorUtils
|
|
2
|
+
import { assertNotNull, ColorUtils } from '@deephaven/utils';
|
|
5
3
|
import { themeDark } from "./theme-dark/index.js";
|
|
6
4
|
import { themeLight } from "./theme-light/index.js";
|
|
7
|
-
import { DEFAULT_DARK_THEME_KEY, DEFAULT_LIGHT_THEME_KEY, DEFAULT_PRELOAD_DATA_VARIABLES, THEME_CACHE_LOCAL_STORAGE_KEY, SVG_ICON_MANUAL_COLOR_MAP, THEME_KEY_OVERRIDE_QUERY_PARAM
|
|
5
|
+
import { DEFAULT_DARK_THEME_KEY, DEFAULT_LIGHT_THEME_KEY, DEFAULT_PRELOAD_DATA_VARIABLES, THEME_CACHE_LOCAL_STORAGE_KEY, SVG_ICON_MANUAL_COLOR_MAP, THEME_KEY_OVERRIDE_QUERY_PARAM } from "./ThemeModel.js";
|
|
8
6
|
var log = Log.module('ThemeUtils');
|
|
9
7
|
export var CSS_VAR_EXPRESSION_PREFIX = 'var(--';
|
|
10
|
-
export var DH_VAR_PREFIX = '--dh-color-';
|
|
11
8
|
export var TMP_CSS_PROP_PREFIX = 'dh-tmp';
|
|
12
9
|
export var NON_WHITESPACE_REGEX = /\S/;
|
|
13
10
|
export var WHITESPACE_REGEX = /\s/;
|
|
14
|
-
export var DH_CSS_VAR_NAME_REGEXP = /^--dh-color-[a-z0-9_-]+$/;
|
|
15
11
|
/**
|
|
16
12
|
* Resolves the current values of CSS variables we want to preload. Preloading
|
|
17
13
|
* happens before themes are fully loaded so that we can style things like the
|
|
@@ -133,15 +129,6 @@ export function getDefaultSelectedThemeKey() {
|
|
|
133
129
|
return (_ref2 = (_getThemeKeyOverride = getThemeKeyOverride()) !== null && _getThemeKeyOverride !== void 0 ? _getThemeKeyOverride : (_getThemePreloadData = getThemePreloadData()) === null || _getThemePreloadData === void 0 ? void 0 : _getThemePreloadData.themeKey) !== null && _ref2 !== void 0 ? _ref2 : DEFAULT_DARK_THEME_KEY;
|
|
134
130
|
}
|
|
135
131
|
|
|
136
|
-
/**
|
|
137
|
-
* Derive unique theme key from plugin root path and theme name.
|
|
138
|
-
* @param pluginName The root path of the plugin
|
|
139
|
-
* @param themeName The name of the theme
|
|
140
|
-
*/
|
|
141
|
-
export function getThemeKey(pluginName, themeName) {
|
|
142
|
-
return "".concat(pluginName, "_").concat(themeName);
|
|
143
|
-
}
|
|
144
|
-
|
|
145
132
|
/**
|
|
146
133
|
* A theme key override can be set via a query parameter to force a specific
|
|
147
134
|
* theme selection. Useful for embedded widget scenarios that don't expose the
|
|
@@ -218,84 +205,6 @@ export function getExpressionRanges(value) {
|
|
|
218
205
|
return ranges;
|
|
219
206
|
}
|
|
220
207
|
|
|
221
|
-
/**
|
|
222
|
-
* Check if the given theme key is one of the base themes.
|
|
223
|
-
* @param themeKey The theme key to check
|
|
224
|
-
* @returns True if the theme key is a base theme key, false otherwise
|
|
225
|
-
*/
|
|
226
|
-
export function isBaseThemeKey(themeKey) {
|
|
227
|
-
return [DEFAULT_DARK_THEME_KEY, DEFAULT_LIGHT_THEME_KEY].includes(themeKey);
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
/**
|
|
231
|
-
* Determine if a given object is a `ExternalThemeData` object.
|
|
232
|
-
* @param maybeExternalThemeData An object that may or may not be a `ExternalThemeData`
|
|
233
|
-
* @returns True if the object is a `ExternalThemeData`, false otherwise
|
|
234
|
-
*/
|
|
235
|
-
export function isExternalThemeData(maybeExternalThemeData) {
|
|
236
|
-
if (typeof maybeExternalThemeData !== 'object' || maybeExternalThemeData == null) {
|
|
237
|
-
return false;
|
|
238
|
-
}
|
|
239
|
-
return 'name' in maybeExternalThemeData && typeof maybeExternalThemeData.name === 'string' && 'cssVars' in maybeExternalThemeData && typeof maybeExternalThemeData.cssVars === 'object' && maybeExternalThemeData.cssVars != null;
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
/**
|
|
243
|
-
* Check if the current URL specifies an external theme key override.
|
|
244
|
-
* @returns True if the external theme key override is set, false otherwise
|
|
245
|
-
*/
|
|
246
|
-
export function isExternalThemeEnabled() {
|
|
247
|
-
var searchParams = new URLSearchParams(window.location.search);
|
|
248
|
-
return searchParams.get(THEME_KEY_OVERRIDE_QUERY_PARAM) === EXTERNAL_THEME_KEY;
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
/**
|
|
252
|
-
* Check if PRELOAD_TRANSPARENT_THEME_QUERY_PARAM query parameter is set to true.
|
|
253
|
-
* @returns True if the preload transparent theme query parameter is set, false
|
|
254
|
-
* otherwise
|
|
255
|
-
*/
|
|
256
|
-
export function isPreloadTransparentTheme() {
|
|
257
|
-
var searchParams = new URLSearchParams(window.location.search);
|
|
258
|
-
return searchParams.get(PRELOAD_TRANSPARENT_THEME_QUERY_PARAM) === 'true';
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
/**
|
|
262
|
-
* Validate that a given CSS variable name / value pair is a valid Deephaven
|
|
263
|
-
* color variable.
|
|
264
|
-
* @param name The name of the CSS variable to validate, e.g. '--dh-color-primary'
|
|
265
|
-
* @param value The value of the CSS color to validate
|
|
266
|
-
* @returns True if the name is a valid Deephaven color variable and the value
|
|
267
|
-
* is a valid CSS color, false otherwise
|
|
268
|
-
*/
|
|
269
|
-
export function isValidColorVar(name, value) {
|
|
270
|
-
return DH_CSS_VAR_NAME_REGEXP.test(name) && CSS.supports('color', value);
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
/**
|
|
274
|
-
* Parse external theme data into a `ThemeData` object. Invalid CSS color variable
|
|
275
|
-
* pairs are excluded from the resulting `ThemeData` object.
|
|
276
|
-
* @param externalThemeData The external theme data to parse
|
|
277
|
-
* @returns A `ThemeData` object representing the external theme
|
|
278
|
-
*/
|
|
279
|
-
export function parseExternalThemeData(_ref3) {
|
|
280
|
-
var {
|
|
281
|
-
baseThemeKey = DEFAULT_DARK_THEME_KEY,
|
|
282
|
-
name,
|
|
283
|
-
cssVars
|
|
284
|
-
} = _ref3;
|
|
285
|
-
var toExpression = _ref4 => {
|
|
286
|
-
var [varName, varValue] = _ref4;
|
|
287
|
-
return isValidColorVar(varName, varValue) ? "".concat(varName, ":").concat(varValue, ";") : null;
|
|
288
|
-
};
|
|
289
|
-
var sanitized = Object.entries(cssVars).map(toExpression).filter(str => str != null);
|
|
290
|
-
var styleContent = sanitized.length === 0 ? '' : ":root{".concat(sanitized.join(''), "}");
|
|
291
|
-
return {
|
|
292
|
-
baseThemeKey,
|
|
293
|
-
themeKey: EXTERNAL_THEME_KEY,
|
|
294
|
-
name,
|
|
295
|
-
styleContent
|
|
296
|
-
};
|
|
297
|
-
}
|
|
298
|
-
|
|
299
208
|
/**
|
|
300
209
|
* Replace the `fill='...'` attribute in the given SVG content with the given
|
|
301
210
|
* color string.
|
|
@@ -306,15 +215,6 @@ export function replaceSVGFillColor(svgContent, fillColor) {
|
|
|
306
215
|
return svgContent.replace(/fill='.*?'/, "fill='".concat(encodeURIComponent(fillColor), "'"));
|
|
307
216
|
}
|
|
308
217
|
|
|
309
|
-
/**
|
|
310
|
-
* Request theme data from the parent window.
|
|
311
|
-
* @returns A promise that resolves to the external theme data
|
|
312
|
-
* @throws Error if the response is not a valid `ExternalThemeData`
|
|
313
|
-
*/
|
|
314
|
-
export function requestExternalThemeData() {
|
|
315
|
-
return _requestExternalThemeData.apply(this, arguments);
|
|
316
|
-
}
|
|
317
|
-
|
|
318
218
|
/**
|
|
319
219
|
* Make a copy of the given object replacing any css variable expressions
|
|
320
220
|
* contained in its prop values with values resolved from the given HTML element.
|
|
@@ -335,16 +235,6 @@ export function requestExternalThemeData() {
|
|
|
335
235
|
* @param isAlphaOptional If true, the alpha value will be dropped from resolved
|
|
336
236
|
* 8 character hex colors if it is 'ff'. Defaults to false.
|
|
337
237
|
*/
|
|
338
|
-
function _requestExternalThemeData() {
|
|
339
|
-
_requestExternalThemeData = _asyncToGenerator(function* () {
|
|
340
|
-
var result = yield requestParentResponse(MSG_REQUEST_GET_THEME);
|
|
341
|
-
if (!isExternalThemeData(result)) {
|
|
342
|
-
throw new Error("Unexpected external theme data response: ".concat(JSON.stringify(result)));
|
|
343
|
-
}
|
|
344
|
-
return result;
|
|
345
|
-
});
|
|
346
|
-
return _requestExternalThemeData.apply(this, arguments);
|
|
347
|
-
}
|
|
348
238
|
export function resolveCssVariablesInRecord(record) {
|
|
349
239
|
var targetElement = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : document.body;
|
|
350
240
|
var isAlphaOptional = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
@@ -354,8 +244,8 @@ export function resolveCssVariablesInRecord(record) {
|
|
|
354
244
|
var tmpPropEl = document.createElement('div');
|
|
355
245
|
tmpPropEl.style.display = 'none';
|
|
356
246
|
var recordArray = Object.entries(record);
|
|
357
|
-
recordArray.forEach((
|
|
358
|
-
var [, value] =
|
|
247
|
+
recordArray.forEach((_ref3, i) => {
|
|
248
|
+
var [, value] = _ref3;
|
|
359
249
|
tmpPropEl.style.setProperty("--".concat(TMP_CSS_PROP_PREFIX, "-").concat(i), value);
|
|
360
250
|
// faster to create these now all at once, even if we don't use them all
|
|
361
251
|
// since the parent isn't added yet to the DOM
|
|
@@ -370,8 +260,8 @@ export function resolveCssVariablesInRecord(record) {
|
|
|
370
260
|
targetElement.appendChild(tmpPropEl);
|
|
371
261
|
var tempPropElComputedStyle = window.getComputedStyle(tmpPropEl);
|
|
372
262
|
var result = {};
|
|
373
|
-
recordArray.forEach((
|
|
374
|
-
var [key, value] =
|
|
263
|
+
recordArray.forEach((_ref4, i) => {
|
|
264
|
+
var [key, value] = _ref4;
|
|
375
265
|
// resolves any variables in the expression
|
|
376
266
|
var resolved = tempPropElComputedStyle.getPropertyValue("--".concat(TMP_CSS_PROP_PREFIX, "-").concat(i));
|
|
377
267
|
var containsCssVar = value.includes(CSS_VAR_EXPRESSION_PREFIX);
|
|
@@ -407,8 +297,8 @@ export function resolveCssVariablesInRecord(record) {
|
|
|
407
297
|
export function resolveCssVariablesInString(resolver, value) {
|
|
408
298
|
var result = [];
|
|
409
299
|
var i = 0;
|
|
410
|
-
getExpressionRanges(value).forEach(
|
|
411
|
-
var [start, end] =
|
|
300
|
+
getExpressionRanges(value).forEach(_ref5 => {
|
|
301
|
+
var [start, end] = _ref5;
|
|
412
302
|
if (i < start) {
|
|
413
303
|
result.push(value.substring(i, start));
|
|
414
304
|
i += start - i;
|
|
@@ -431,6 +321,15 @@ export function setThemePreloadData(preloadData) {
|
|
|
431
321
|
localStorage.setItem(THEME_CACHE_LOCAL_STORAGE_KEY, JSON.stringify(preloadData));
|
|
432
322
|
}
|
|
433
323
|
|
|
324
|
+
/**
|
|
325
|
+
* Derive unique theme key from plugin root path and theme name.
|
|
326
|
+
* @param pluginName The root path of the plugin
|
|
327
|
+
* @param themeName The name of the theme
|
|
328
|
+
*/
|
|
329
|
+
export function getThemeKey(pluginName, themeName) {
|
|
330
|
+
return "".concat(pluginName, "_").concat(themeName);
|
|
331
|
+
}
|
|
332
|
+
|
|
434
333
|
/**
|
|
435
334
|
* Preload minimal theme variables from the cache.
|
|
436
335
|
* @defaultPreloadValues Optional default values to use if a preload variable is not set.
|
|
@@ -438,16 +337,6 @@ export function setThemePreloadData(preloadData) {
|
|
|
438
337
|
export function preloadTheme() {
|
|
439
338
|
var _getThemePreloadData2;
|
|
440
339
|
var defaultPreloadValues = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : DEFAULT_PRELOAD_DATA_VARIABLES;
|
|
441
|
-
// In certain cases we may want to preload a transparent theme to allow the
|
|
442
|
-
// parent container to show through. For example, when a parent Window is
|
|
443
|
-
// providing a theme via `postMessage` apis, we may not have enough information
|
|
444
|
-
// to properly preload the theme, so we can just preload a transparent
|
|
445
|
-
// theme and let the parent container show through until `postMessage`
|
|
446
|
-
// communication is complete.
|
|
447
|
-
if (isPreloadTransparentTheme()) {
|
|
448
|
-
createPreloadStyleElement('theme-preload-transparent', calculatePreloadStyleContent(TRANSPARENT_PRELOAD_DATA_VARIABLES));
|
|
449
|
-
return;
|
|
450
|
-
}
|
|
451
340
|
var previousPreloadStyleContent = (_getThemePreloadData2 = getThemePreloadData()) === null || _getThemePreloadData2 === void 0 ? void 0 : _getThemePreloadData2.preloadStyleContent;
|
|
452
341
|
var defaultPreloadStyleContent = calculatePreloadStyleContent(defaultPreloadValues);
|
|
453
342
|
log.debug('Preloading theme content:', {
|
|
@@ -481,8 +370,8 @@ export function preloadTheme() {
|
|
|
481
370
|
*/
|
|
482
371
|
export function overrideSVGFillColors(defaultValues) {
|
|
483
372
|
var resolveVar = createCssVariableResolver(document.body, defaultValues);
|
|
484
|
-
Object.entries(SVG_ICON_MANUAL_COLOR_MAP).forEach(
|
|
485
|
-
var [key, value] =
|
|
373
|
+
Object.entries(SVG_ICON_MANUAL_COLOR_MAP).forEach(_ref6 => {
|
|
374
|
+
var [key, value] = _ref6;
|
|
486
375
|
// Clear any previous override so that our variables get resolved against the
|
|
487
376
|
// actual svg content provided by the active themes and not from a previous
|
|
488
377
|
// override
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ThemeUtils.js","names":["Log","assertNotNull","ColorUtils","requestParentResponse","themeDark","themeLight","DEFAULT_DARK_THEME_KEY","DEFAULT_LIGHT_THEME_KEY","DEFAULT_PRELOAD_DATA_VARIABLES","THEME_CACHE_LOCAL_STORAGE_KEY","SVG_ICON_MANUAL_COLOR_MAP","THEME_KEY_OVERRIDE_QUERY_PARAM","EXTERNAL_THEME_KEY","MSG_REQUEST_GET_THEME","TRANSPARENT_PRELOAD_DATA_VARIABLES","PRELOAD_TRANSPARENT_THEME_QUERY_PARAM","log","module","CSS_VAR_EXPRESSION_PREFIX","DH_VAR_PREFIX","TMP_CSS_PROP_PREFIX","NON_WHITESPACE_REGEX","WHITESPACE_REGEX","DH_CSS_VAR_NAME_REGEXP","calculatePreloadStyleContent","defaultPreloadValues","resolveVar","createCssVariableResolver","document","body","pairs","Object","keys","map","key","concat","join","el","defaultValues","computedStyle","getComputedStyle","cssVariableResolver","varName","_defaultValues","value","getPropertyValue","createPreloadStyleElement","id","preloadStyleContent","style","createElement","innerHTML","head","appendChild","extractDistinctCssVariableExpressions","record","set","Set","values","forEach","getExpressionRanges","_ref","start","end","expression","substring","includes","add","getActiveThemes","themeKey","themeRegistration","_custom$baseThemeKey","custom","find","theme","baseThemeKey","base","error","debug","getDefaultBaseThemes","name","styleContent","getDefaultSelectedThemeKey","_ref2","_getThemeKeyOverride","_getThemePreloadData","getThemeKeyOverride","getThemePreloadData","getThemeKey","pluginName","themeName","searchParams","URLSearchParams","window","location","search","get","data","localStorage","getItem","JSON","parse","_unused","_NON_WHITESPACE_REGEX","_NON_WHITESPACE_REGEX2","ranges","exec","index","parenLevel","i","length","test","push","isBaseThemeKey","isExternalThemeData","maybeExternalThemeData","cssVars","isExternalThemeEnabled","isPreloadTransparentTheme","isValidColorVar","CSS","supports","parseExternalThemeData","_ref3","toExpression","_ref4","varValue","sanitized","entries","filter","str","replaceSVGFillColor","svgContent","fillColor","replace","encodeURIComponent","requestExternalThemeData","_requestExternalThemeData","apply","arguments","_asyncToGenerator","result","Error","stringify","resolveCssVariablesInRecord","targetElement","undefined","isAlphaOptional","perfStart","performance","now","tmpPropEl","display","recordArray","_ref5","setProperty","backgroundColor","tempPropElComputedStyle","_ref6","resolved","containsCssVar","isColor","children","color","normalizeCssColor","remove","resolveCssVariablesInString","resolver","_ref7","setThemePreloadData","preloadData","setItem","preloadTheme","_getThemePreloadData2","previousPreloadStyleContent","defaultPreloadStyleContent","overrideSVGFillColors","_ref8","removeProperty","newSVGContent"],"sources":["../../src/theme/ThemeUtils.ts"],"sourcesContent":["import Log from '@deephaven/log';\nimport {\n assertNotNull,\n ColorUtils,\n requestParentResponse,\n} from '@deephaven/utils';\nimport { themeDark } from './theme-dark';\nimport { themeLight } from './theme-light';\nimport {\n DEFAULT_DARK_THEME_KEY,\n DEFAULT_LIGHT_THEME_KEY,\n DEFAULT_PRELOAD_DATA_VARIABLES,\n type BaseThemeKey,\n type ThemeData,\n type ThemePreloadData,\n type CssVariableStyleContent,\n type ThemePreloadColorVariable,\n type ThemeRegistrationData,\n THEME_CACHE_LOCAL_STORAGE_KEY,\n SVG_ICON_MANUAL_COLOR_MAP,\n type ThemeCssVariableName,\n type ThemeIconsRequiringManualColorChanges,\n THEME_KEY_OVERRIDE_QUERY_PARAM,\n EXTERNAL_THEME_KEY,\n type ExternalThemeData,\n MSG_REQUEST_GET_THEME,\n type ThemeCssColorVariableName,\n TRANSPARENT_PRELOAD_DATA_VARIABLES,\n PRELOAD_TRANSPARENT_THEME_QUERY_PARAM,\n} from './ThemeModel';\n\nconst log = Log.module('ThemeUtils');\n\nexport const CSS_VAR_EXPRESSION_PREFIX = 'var(--';\nexport const DH_VAR_PREFIX = '--dh-color-';\nexport const TMP_CSS_PROP_PREFIX = 'dh-tmp';\nexport const NON_WHITESPACE_REGEX = /\\S/;\nexport const WHITESPACE_REGEX = /\\s/;\n\nexport const DH_CSS_VAR_NAME_REGEXP = /^--dh-color-[a-z0-9_-]+$/;\n\nexport type VarExpressionResolver = (varExpression: string) => string;\n\n/**\n * Resolves the current values of CSS variables we want to preload. Preloading\n * happens before themes are fully loaded so that we can style things like the\n * loading spinner and background color which are shown to the user early on in\n * the app lifecycle.\n * @defaultPreloadValues Default values to use if a preload variable is not set.\n */\nexport function calculatePreloadStyleContent(\n defaultPreloadValues: Record<string, string>\n): CssVariableStyleContent {\n const resolveVar = createCssVariableResolver(\n document.body,\n defaultPreloadValues\n );\n\n // Calculate the current preload variables. If the variable is not set, use\n // the default value.\n const pairs = Object.keys(defaultPreloadValues).map(\n key => `${key}:${resolveVar(key as ThemePreloadColorVariable)}`\n );\n\n return `:root{${pairs.join(';')}}`;\n}\n\n/**\n * Create a resolver function for calculating the value of a css variable based\n * on a given element's computed style. If the variable resolves to '', we check\n * `defaultValues` for a default value, and if one does not exist,\n * return ''.\n * @param el Element to resolve css variables against\n * @param defaultValues Default values to use if a variable is not set.\n */\nexport function createCssVariableResolver(\n el: Element,\n defaultValues: Record<string, string>\n): (varName: ThemeCssVariableName) => string {\n const computedStyle = getComputedStyle(el);\n\n /**\n * Resolve the given css variable name to a value. If the variable is not set,\n * return the default preload value or '' if one does not exist.\n */\n return function cssVariableResolver(varName: ThemeCssVariableName): string {\n const value = computedStyle.getPropertyValue(varName);\n\n if (value !== '') {\n return value;\n }\n\n return defaultValues[varName as ThemePreloadColorVariable] ?? '';\n };\n}\n\n/**\n * Create a style tag containing preload css variables and add to the head.\n * @param id The id of the style tag\n * @param preloadStyleContent The css variable content to add to the style tag\n */\nexport function createPreloadStyleElement(\n id: `theme-preload-${string}`,\n preloadStyleContent: CssVariableStyleContent\n): void {\n const style = document.createElement('style');\n style.id = id;\n style.innerHTML = preloadStyleContent;\n document.head.appendChild(style);\n}\n\n/**\n * Extracts all css variable expressions from the given record and returns\n * a set of unique expressions.\n * @param record The record to extract css variable expressions from\n */\nexport function extractDistinctCssVariableExpressions(\n record: Record<string, string>\n): Set<string> {\n const set = new Set<string>();\n\n Object.values(record).forEach(value => {\n getExpressionRanges(value).forEach(([start, end]) => {\n const expression = value.substring(start, end + 1);\n\n if (expression.includes(CSS_VAR_EXPRESSION_PREFIX)) {\n set.add(expression);\n }\n });\n });\n\n return set;\n}\n\n/**\n * Returns an array of the active themes. The first item will always be one\n * of the base themes. Optionally, the second item will be a custom theme.\n */\nexport function getActiveThemes(\n themeKey: string,\n themeRegistration: ThemeRegistrationData\n): [ThemeData] | [ThemeData, ThemeData] {\n const custom = themeRegistration.custom.find(\n theme => theme.themeKey === themeKey\n );\n\n const baseThemeKey = custom?.baseThemeKey ?? themeKey;\n\n let base = themeRegistration.base.find(\n theme => theme.themeKey === baseThemeKey\n );\n\n if (base == null) {\n log.error(\n `No registered base theme found for theme key: '${baseThemeKey}'`,\n 'Registered:',\n themeRegistration.base.map(theme => theme.themeKey),\n themeRegistration.custom.map(theme => theme.themeKey)\n );\n base = themeRegistration.base.find(\n theme => theme.themeKey === DEFAULT_DARK_THEME_KEY\n );\n\n assertNotNull(\n base,\n `Default base theme '${DEFAULT_DARK_THEME_KEY}' is not registered`\n );\n }\n\n log.debug('Applied themes:', base.themeKey, custom?.themeKey);\n\n return custom == null ? [base] : [base, custom];\n}\n\n/**\n * Get default base theme data.\n */\nexport function getDefaultBaseThemes(): ThemeData[] {\n return [\n {\n name: 'Default Dark',\n themeKey: DEFAULT_DARK_THEME_KEY,\n styleContent: themeDark,\n },\n // The ThemePicker shows whenever more than 1 theme is available. Disable\n // light theme for now to keep the picker hidden until it is fully\n // implemented by #1539.\n {\n name: 'Default Light',\n themeKey: DEFAULT_LIGHT_THEME_KEY,\n styleContent: themeLight,\n },\n ];\n}\n\n/**\n * Get the default selected theme key. Precedence is:\n * 1. Theme key override query parameter\n * 2. Theme key from preload data\n * 3. Default dark theme key\n * @returns The default selected theme key\n */\nexport function getDefaultSelectedThemeKey(): string {\n return (\n getThemeKeyOverride() ??\n getThemePreloadData()?.themeKey ??\n DEFAULT_DARK_THEME_KEY\n );\n}\n\n/**\n * Derive unique theme key from plugin root path and theme name.\n * @param pluginName The root path of the plugin\n * @param themeName The name of the theme\n */\nexport function getThemeKey(pluginName: string, themeName: string): string {\n return `${pluginName}_${themeName}`;\n}\n\n/**\n * A theme key override can be set via a query parameter to force a specific\n * theme selection. Useful for embedded widget scenarios that don't expose the\n * theme selector.\n */\nexport function getThemeKeyOverride(): string | null {\n const searchParams = new URLSearchParams(window.location.search);\n return searchParams.get(THEME_KEY_OVERRIDE_QUERY_PARAM);\n}\n\n/**\n * Get the preload data from local storage or null if it does not exist or is\n * invalid\n */\nexport function getThemePreloadData(): ThemePreloadData | null {\n const data = localStorage.getItem(THEME_CACHE_LOCAL_STORAGE_KEY);\n\n try {\n return data == null ? null : JSON.parse(data);\n } catch {\n // ignore\n }\n\n return null;\n}\n\n/**\n * Identifies start and end indices of any top-level expressions in the given\n * string.\n *\n * e.g.\n * getExpressionRanges('var(--aaa-aa) #fff var(--bbb-bb)')\n * yields:\n * [\n * [0, 12], // 'var(--aaa-aa)'\n * [14, 17] // '#fff'\n * [19, 31], // 'var(--bbb-bb)'\n * ]\n *\n * In cases where there are nested expressions, only the indices of the outermost\n * expression will be included.\n *\n * e.g.\n * getExpressionRanges('var(--ccc-cc, var(--aaa-aa, green)) var(--bbb-bb)')\n * yields:\n * [\n * [0, 34], // 'var(--ccc-cc, var(--aaa-aa, green))'\n * [36, 48], // 'var(--bbb-bb)'\n * ]\n * @param value The string to search for expressions\n * @returns An array of [start, end] index pairs for each expression\n */\nexport function getExpressionRanges(value: string): [number, number][] {\n const ranges: [number, number][] = [];\n\n let start = NON_WHITESPACE_REGEX.exec(value)?.index ?? 0;\n let parenLevel = 0;\n\n for (let i = 0; i < value.length; i += 1) {\n if (value[i] === '(') {\n parenLevel += 1;\n } else if (value[i] === ')') {\n parenLevel -= 1;\n }\n\n if (\n i === value.length - 1 ||\n (WHITESPACE_REGEX.test(value[i + 1]) && parenLevel === 0)\n ) {\n ranges.push([start, i]);\n\n while (i < value.length - 1 && WHITESPACE_REGEX.test(value[i + 1])) {\n i += 1;\n }\n\n start = i + 1;\n }\n }\n\n if (parenLevel !== 0) {\n log.error('Unbalanced parentheses in css var expression', value);\n return [];\n }\n\n return ranges;\n}\n\n/**\n * Check if the given theme key is one of the base themes.\n * @param themeKey The theme key to check\n * @returns True if the theme key is a base theme key, false otherwise\n */\nexport function isBaseThemeKey(themeKey: string): themeKey is BaseThemeKey {\n return [DEFAULT_DARK_THEME_KEY, DEFAULT_LIGHT_THEME_KEY].includes(themeKey);\n}\n\n/**\n * Determine if a given object is a `ExternalThemeData` object.\n * @param maybeExternalThemeData An object that may or may not be a `ExternalThemeData`\n * @returns True if the object is a `ExternalThemeData`, false otherwise\n */\nexport function isExternalThemeData(\n maybeExternalThemeData: unknown\n): maybeExternalThemeData is ExternalThemeData {\n if (\n typeof maybeExternalThemeData !== 'object' ||\n maybeExternalThemeData == null\n ) {\n return false;\n }\n\n return (\n 'name' in maybeExternalThemeData &&\n typeof maybeExternalThemeData.name === 'string' &&\n 'cssVars' in maybeExternalThemeData &&\n typeof maybeExternalThemeData.cssVars === 'object' &&\n maybeExternalThemeData.cssVars != null\n );\n}\n\n/**\n * Check if the current URL specifies an external theme key override.\n * @returns True if the external theme key override is set, false otherwise\n */\nexport function isExternalThemeEnabled(): boolean {\n const searchParams = new URLSearchParams(window.location.search);\n return (\n searchParams.get(THEME_KEY_OVERRIDE_QUERY_PARAM) === EXTERNAL_THEME_KEY\n );\n}\n\n/**\n * Check if PRELOAD_TRANSPARENT_THEME_QUERY_PARAM query parameter is set to true.\n * @returns True if the preload transparent theme query parameter is set, false\n * otherwise\n */\nexport function isPreloadTransparentTheme(): boolean {\n const searchParams = new URLSearchParams(window.location.search);\n return searchParams.get(PRELOAD_TRANSPARENT_THEME_QUERY_PARAM) === 'true';\n}\n\n/**\n * Validate that a given CSS variable name / value pair is a valid Deephaven\n * color variable.\n * @param name The name of the CSS variable to validate, e.g. '--dh-color-primary'\n * @param value The value of the CSS color to validate\n * @returns True if the name is a valid Deephaven color variable and the value\n * is a valid CSS color, false otherwise\n */\nexport function isValidColorVar(\n name: string,\n value: string\n): name is ThemeCssColorVariableName {\n return DH_CSS_VAR_NAME_REGEXP.test(name) && CSS.supports('color', value);\n}\n\n/**\n * Parse external theme data into a `ThemeData` object. Invalid CSS color variable\n * pairs are excluded from the resulting `ThemeData` object.\n * @param externalThemeData The external theme data to parse\n * @returns A `ThemeData` object representing the external theme\n */\nexport function parseExternalThemeData({\n baseThemeKey = DEFAULT_DARK_THEME_KEY,\n name,\n cssVars,\n}: ExternalThemeData): ThemeData {\n const toExpression = ([varName, varValue]: [string, string]) =>\n isValidColorVar(varName, varValue) ? `${varName}:${varValue};` : null;\n\n const sanitized = Object.entries(cssVars)\n .map(toExpression)\n .filter((str): str is string => str != null);\n\n const styleContent =\n sanitized.length === 0 ? '' : `:root{${sanitized.join('')}}`;\n\n return {\n baseThemeKey,\n themeKey: EXTERNAL_THEME_KEY,\n name,\n styleContent,\n };\n}\n\n/**\n * Replace the `fill='...'` attribute in the given SVG content with the given\n * color string.\n * @param svgContent Inline SVG content to replace the fill color in\n * @param fillColor The color to replace the fill color with\n */\nexport function replaceSVGFillColor(\n svgContent: string,\n fillColor: string\n): string {\n return svgContent.replace(\n /fill='.*?'/,\n `fill='${encodeURIComponent(fillColor)}'`\n );\n}\n\n/**\n * Request theme data from the parent window.\n * @returns A promise that resolves to the external theme data\n * @throws Error if the response is not a valid `ExternalThemeData`\n */\nexport async function requestExternalThemeData(): Promise<ExternalThemeData> {\n const result = await requestParentResponse(MSG_REQUEST_GET_THEME);\n\n if (!isExternalThemeData(result)) {\n throw new Error(\n `Unexpected external theme data response: ${JSON.stringify(result)}`\n );\n }\n\n return result;\n}\n\n/**\n * Make a copy of the given object replacing any css variable expressions\n * contained in its prop values with values resolved from the given HTML element.\n * Variables that resolve to color strings will also be normalized to 8 digit\n * hex values (or optionally 6 digit hex if `isAlphaOptional` is true).\n *\n * Note that the browser will force a reflow when calling `getComputedStyle` if\n * css properties have changed. In order to avoid a reflow for every property\n * check we use distinct setup, resolve / normalize, and cleanup passes:\n * 1. Setup - Create a tmp element and set all css props we want to evaluate\n * 2. Resolve / Normalize - Evaluate all css props via `getPropertyValue` calls\n * and replace the original expressions with resolved values. Also normalize\n * css colors to rgb/a.\n * 3. Cleanup - Remove the tmp element\n * @param record An object whose values may contain css var expressions\n * @param targetElement The element to resolve css variables against. Defaults\n * to document.body\n * @param isAlphaOptional If true, the alpha value will be dropped from resolved\n * 8 character hex colors if it is 'ff'. Defaults to false.\n */\nexport function resolveCssVariablesInRecord<T extends Record<string, string>>(\n record: T,\n targetElement: HTMLElement = document.body,\n isAlphaOptional = false\n): T {\n const perfStart = performance.now();\n\n // Add a temporary div to attach temp css variables to\n const tmpPropEl = document.createElement('div');\n tmpPropEl.style.display = 'none';\n\n const recordArray = Object.entries(record);\n recordArray.forEach(([, value], i) => {\n tmpPropEl.style.setProperty(`--${TMP_CSS_PROP_PREFIX}-${i}`, value);\n // faster to create these now all at once, even if we don't use them all\n // since the parent isn't added yet to the DOM\n const el = document.createElement('div');\n // use background color instead of color to avoid inherited values\n el.style.backgroundColor = value;\n tmpPropEl.appendChild(el);\n });\n\n // append only once to avoid multiple re-layouts\n // must be part of DOM to get computed color\n targetElement.appendChild(tmpPropEl);\n const tempPropElComputedStyle = window.getComputedStyle(tmpPropEl);\n\n const result = {} as T;\n recordArray.forEach(([key, value], i) => {\n // resolves any variables in the expression\n let resolved = tempPropElComputedStyle.getPropertyValue(\n `--${TMP_CSS_PROP_PREFIX}-${i}`\n );\n\n const containsCssVar = value.includes(CSS_VAR_EXPRESSION_PREFIX);\n const isColor = CSS.supports('color', resolved);\n\n if (\n // only try to normalize non-hex strings that are valid colors\n // otherwise non-colors will be made #00000000\n isColor &&\n !/^#[0-9A-F]{6}[0-9a-f]{0,2}$/i.test(resolved)\n ) {\n // getting the computed background color is necessary\n // because resolved can still contain a color-mix() function\n const el = tmpPropEl.children[i] as HTMLDivElement;\n const computedStyle = window.getComputedStyle(el);\n const color = computedStyle.getPropertyValue('background-color');\n // convert color to hex, which is what monaco and plotly require\n resolved = ColorUtils.normalizeCssColor(color, isAlphaOptional);\n }\n (result as Record<string, string>)[key] =\n containsCssVar || isColor ? resolved : value;\n });\n\n // Remove the temporary div\n tmpPropEl.remove();\n\n log.debug('Resolved css variables', performance.now() - perfStart, 'ms');\n\n return result;\n}\n\n/**\n * Resolve css variable expressions in the given string using the\n * given resolver and replace the original expressions with the resolved values.\n *\n * @param resolver Function that can resolve a css variable expression\n * @param value Value that may contain css variable expressions\n */\nexport function resolveCssVariablesInString(\n resolver: VarExpressionResolver,\n value: string\n): string {\n const result: string[] = [];\n let i = 0;\n getExpressionRanges(value).forEach(([start, end]) => {\n if (i < start) {\n result.push(value.substring(i, start));\n i += start - i;\n }\n\n const expression = value.substring(start, end + 1);\n\n result.push(\n expression.includes(CSS_VAR_EXPRESSION_PREFIX)\n ? resolver(expression)\n : expression\n );\n\n i += end - start + 1;\n });\n\n if (result.length === 0) {\n return value;\n }\n\n return result.join('');\n}\n\n/**\n * Store theme preload data in local storage.\n * @param preloadData The preload data to set\n */\nexport function setThemePreloadData(preloadData: ThemePreloadData): void {\n localStorage.setItem(\n THEME_CACHE_LOCAL_STORAGE_KEY,\n JSON.stringify(preloadData)\n );\n}\n\n/**\n * Preload minimal theme variables from the cache.\n * @defaultPreloadValues Optional default values to use if a preload variable is not set.\n */\nexport function preloadTheme(\n defaultPreloadValues: Record<string, string> = DEFAULT_PRELOAD_DATA_VARIABLES\n): void {\n // In certain cases we may want to preload a transparent theme to allow the\n // parent container to show through. For example, when a parent Window is\n // providing a theme via `postMessage` apis, we may not have enough information\n // to properly preload the theme, so we can just preload a transparent\n // theme and let the parent container show through until `postMessage`\n // communication is complete.\n if (isPreloadTransparentTheme()) {\n createPreloadStyleElement(\n 'theme-preload-transparent',\n calculatePreloadStyleContent(TRANSPARENT_PRELOAD_DATA_VARIABLES)\n );\n return;\n }\n\n const previousPreloadStyleContent =\n getThemePreloadData()?.preloadStyleContent;\n\n const defaultPreloadStyleContent =\n calculatePreloadStyleContent(defaultPreloadValues);\n\n log.debug('Preloading theme content:', {\n defaultPreloadStyleContent,\n previousPreloadStyleContent,\n });\n\n createPreloadStyleElement(\n 'theme-preload-defaults',\n defaultPreloadStyleContent\n );\n\n // Any preload variables that were saved by last theme load should override\n // the defaults\n if (previousPreloadStyleContent != null) {\n createPreloadStyleElement(\n 'theme-preload-previous',\n previousPreloadStyleContent\n );\n }\n}\n\n/**\n * Inline SVGs cannot depend on dynamic CSS variables, so we have to statically\n * update them if we want to change their color.\n *\n * This function:\n * 1. Clears any previous overrides\n * 2. Resolves CSS variables containing inline SVG urls\n * 3. Resolves mapped color variables and replaces the `fill='...'` attribute with the result\n * 4. Sets the original CSS variable to the new replaced value\n *\n * Note that it is preferable to use inline SVGs as background-mask values and\n * just change the background color instead of relying on this util, but this\n * is not always possible. e.g. <select> elements don't support pseudo elements,\n * so there's not a good way to set icons via masks.\n * @param defaultValues Default values to use if a variable is not set.\n */\nexport function overrideSVGFillColors(\n defaultValues: Record<string, string>\n): void {\n const resolveVar = createCssVariableResolver(document.body, defaultValues);\n\n Object.entries(SVG_ICON_MANUAL_COLOR_MAP).forEach(([key, value]) => {\n // Clear any previous override so that our variables get resolved against the\n // actual svg content provided by the active themes and not from a previous\n // override\n document.body.style.removeProperty(key);\n\n const svgContent = resolveVar(key as ThemeIconsRequiringManualColorChanges);\n const fillColor = resolveVar(value as ThemePreloadColorVariable);\n\n const newSVGContent = replaceSVGFillColor(svgContent, fillColor);\n\n // This will take precedence over any values for the variable provided by\n // the active themes\n document.body.style.setProperty(key, newSVGContent);\n });\n}\n"],"mappings":";;AAAA,OAAOA,GAAG,MAAM,gBAAgB;AAChC,SACEC,aAAa,EACbC,UAAU,EACVC,qBAAqB,QAChB,kBAAkB;AAAC,SACjBC,SAAS;AAAA,SACTC,UAAU;AAAA,SAEjBC,sBAAsB,EACtBC,uBAAuB,EACvBC,8BAA8B,EAO9BC,6BAA6B,EAC7BC,yBAAyB,EAGzBC,8BAA8B,EAC9BC,kBAAkB,EAElBC,qBAAqB,EAErBC,kCAAkC,EAClCC,qCAAqC;AAGvC,IAAMC,GAAG,GAAGhB,GAAG,CAACiB,MAAM,CAAC,YAAY,CAAC;AAEpC,OAAO,IAAMC,yBAAyB,GAAG,QAAQ;AACjD,OAAO,IAAMC,aAAa,GAAG,aAAa;AAC1C,OAAO,IAAMC,mBAAmB,GAAG,QAAQ;AAC3C,OAAO,IAAMC,oBAAoB,GAAG,IAAI;AACxC,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CAACC,oBAAoB,CAAC;EAEpDT,GAAG,CAAC8D,KAAK,CAAC,2BAA2B,EAAE;IACrCiG,0BAA0B;IAC1BD;EACF,CAAC,CAAC;EAEFhI,yBAAyB,CACvB,wBAAwB,EACxBiI,0BACF,CAAC;;EAED;EACA;EACA,IAAID,2BAA2B,IAAI,IAAI,EAAE;IACvChI,yBAAyB,CACvB,wBAAwB,EACxBgI,2BACF,CAAC;EACH;AACF;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASE,qBAAqBA,CACnC1I,aAAqC,EAC/B;EACN,IAAMZ,UAAU,GAAGC,yBAAyB,CAACC,QAAQ,CAACC,IAAI,EAAES,aAAa,CAAC;EAE1EP,MAAM,CAACiG,OAAO,CAACtH,yBAAyB,CAAC,CAACiD,OAAO,CAACsH,KAAA,IAAkB;IAAA,IAAjB,CAAC/I,GAAG,EAAEU,KAAK,CAAC,GAAAqI,KAAA;IAC7D;IACA;IACA;IACArJ,QAAQ,CAACC,IAAI,CAACoB,KAAK,CAACiI,cAAc,CAAChJ,GAAG,CAAC;IAEvC,IAAMkG,UAAU,GAAG1G,UAAU,CAACQ,GAA4C,CAAC;IAC3E,IAAMmG,SAAS,GAAG3G,UAAU,CAACkB,KAAkC,CAAC;IAEhE,IAAMuI,aAAa,GAAGhD,mBAAmB,CAACC,UAAU,EAAEC,SAAS,CAAC;;IAEhE;IACA;IACAzG,QAAQ,CAACC,IAAI,CAACoB,KAAK,CAAC0G,WAAW,CAACzH,GAAG,EAAEiJ,aAAa,CAAC;EACrD,CAAC,CAAC;AACJ"}
|
|
1
|
+
{"version":3,"file":"ThemeUtils.js","names":["Log","assertNotNull","ColorUtils","themeDark","themeLight","DEFAULT_DARK_THEME_KEY","DEFAULT_LIGHT_THEME_KEY","DEFAULT_PRELOAD_DATA_VARIABLES","THEME_CACHE_LOCAL_STORAGE_KEY","SVG_ICON_MANUAL_COLOR_MAP","THEME_KEY_OVERRIDE_QUERY_PARAM","log","module","CSS_VAR_EXPRESSION_PREFIX","TMP_CSS_PROP_PREFIX","NON_WHITESPACE_REGEX","WHITESPACE_REGEX","calculatePreloadStyleContent","defaultPreloadValues","resolveVar","createCssVariableResolver","document","body","pairs","Object","keys","map","key","concat","join","el","defaultValues","computedStyle","getComputedStyle","cssVariableResolver","varName","_defaultValues","value","getPropertyValue","createPreloadStyleElement","id","preloadStyleContent","style","createElement","innerHTML","head","appendChild","extractDistinctCssVariableExpressions","record","set","Set","values","forEach","getExpressionRanges","_ref","start","end","expression","substring","includes","add","getActiveThemes","themeKey","themeRegistration","_custom$baseThemeKey","custom","find","theme","baseThemeKey","base","error","debug","getDefaultBaseThemes","name","styleContent","getDefaultSelectedThemeKey","_ref2","_getThemeKeyOverride","_getThemePreloadData","getThemeKeyOverride","getThemePreloadData","searchParams","URLSearchParams","window","location","search","get","data","localStorage","getItem","JSON","parse","_unused","_NON_WHITESPACE_REGEX","_NON_WHITESPACE_REGEX2","ranges","exec","index","parenLevel","i","length","test","push","replaceSVGFillColor","svgContent","fillColor","replace","encodeURIComponent","resolveCssVariablesInRecord","targetElement","arguments","undefined","isAlphaOptional","perfStart","performance","now","tmpPropEl","display","recordArray","entries","_ref3","setProperty","backgroundColor","tempPropElComputedStyle","result","_ref4","resolved","containsCssVar","isColor","CSS","supports","children","color","normalizeCssColor","remove","resolveCssVariablesInString","resolver","_ref5","setThemePreloadData","preloadData","setItem","stringify","getThemeKey","pluginName","themeName","preloadTheme","_getThemePreloadData2","previousPreloadStyleContent","defaultPreloadStyleContent","overrideSVGFillColors","_ref6","removeProperty","newSVGContent"],"sources":["../../src/theme/ThemeUtils.ts"],"sourcesContent":["import Log from '@deephaven/log';\nimport { assertNotNull, ColorUtils } from '@deephaven/utils';\nimport { themeDark } from './theme-dark';\nimport { themeLight } from './theme-light';\nimport {\n DEFAULT_DARK_THEME_KEY,\n DEFAULT_LIGHT_THEME_KEY,\n DEFAULT_PRELOAD_DATA_VARIABLES,\n type ThemeData,\n type ThemePreloadData,\n type CssVariableStyleContent,\n type ThemePreloadColorVariable,\n type ThemeRegistrationData,\n THEME_CACHE_LOCAL_STORAGE_KEY,\n SVG_ICON_MANUAL_COLOR_MAP,\n type ThemeCssVariableName,\n type ThemeIconsRequiringManualColorChanges,\n THEME_KEY_OVERRIDE_QUERY_PARAM,\n} from './ThemeModel';\n\nconst log = Log.module('ThemeUtils');\n\nexport const CSS_VAR_EXPRESSION_PREFIX = 'var(--';\nexport const TMP_CSS_PROP_PREFIX = 'dh-tmp';\nexport const NON_WHITESPACE_REGEX = /\\S/;\nexport const WHITESPACE_REGEX = /\\s/;\n\nexport type VarExpressionResolver = (varExpression: string) => string;\n\n/**\n * Resolves the current values of CSS variables we want to preload. Preloading\n * happens before themes are fully loaded so that we can style things like the\n * loading spinner and background color which are shown to the user early on in\n * the app lifecycle.\n * @defaultPreloadValues Default values to use if a preload variable is not set.\n */\nexport function calculatePreloadStyleContent(\n defaultPreloadValues: Record<string, string>\n): CssVariableStyleContent {\n const resolveVar = createCssVariableResolver(\n document.body,\n defaultPreloadValues\n );\n\n // Calculate the current preload variables. If the variable is not set, use\n // the default value.\n const pairs = Object.keys(defaultPreloadValues).map(\n key => `${key}:${resolveVar(key as ThemePreloadColorVariable)}`\n );\n\n return `:root{${pairs.join(';')}}`;\n}\n\n/**\n * Create a resolver function for calculating the value of a css variable based\n * on a given element's computed style. If the variable resolves to '', we check\n * `defaultValues` for a default value, and if one does not exist,\n * return ''.\n * @param el Element to resolve css variables against\n * @param defaultValues Default values to use if a variable is not set.\n */\nexport function createCssVariableResolver(\n el: Element,\n defaultValues: Record<string, string>\n): (varName: ThemeCssVariableName) => string {\n const computedStyle = getComputedStyle(el);\n\n /**\n * Resolve the given css variable name to a value. If the variable is not set,\n * return the default preload value or '' if one does not exist.\n */\n return function cssVariableResolver(varName: ThemeCssVariableName): string {\n const value = computedStyle.getPropertyValue(varName);\n\n if (value !== '') {\n return value;\n }\n\n return defaultValues[varName as ThemePreloadColorVariable] ?? '';\n };\n}\n\n/**\n * Create a style tag containing preload css variables and add to the head.\n * @param id The id of the style tag\n * @param preloadStyleContent The css variable content to add to the style tag\n */\nexport function createPreloadStyleElement(\n id: `theme-preload-${string}`,\n preloadStyleContent: CssVariableStyleContent\n): void {\n const style = document.createElement('style');\n style.id = id;\n style.innerHTML = preloadStyleContent;\n document.head.appendChild(style);\n}\n\n/**\n * Extracts all css variable expressions from the given record and returns\n * a set of unique expressions.\n * @param record The record to extract css variable expressions from\n */\nexport function extractDistinctCssVariableExpressions(\n record: Record<string, string>\n): Set<string> {\n const set = new Set<string>();\n\n Object.values(record).forEach(value => {\n getExpressionRanges(value).forEach(([start, end]) => {\n const expression = value.substring(start, end + 1);\n\n if (expression.includes(CSS_VAR_EXPRESSION_PREFIX)) {\n set.add(expression);\n }\n });\n });\n\n return set;\n}\n\n/**\n * Returns an array of the active themes. The first item will always be one\n * of the base themes. Optionally, the second item will be a custom theme.\n */\nexport function getActiveThemes(\n themeKey: string,\n themeRegistration: ThemeRegistrationData\n): [ThemeData] | [ThemeData, ThemeData] {\n const custom = themeRegistration.custom.find(\n theme => theme.themeKey === themeKey\n );\n\n const baseThemeKey = custom?.baseThemeKey ?? themeKey;\n\n let base = themeRegistration.base.find(\n theme => theme.themeKey === baseThemeKey\n );\n\n if (base == null) {\n log.error(\n `No registered base theme found for theme key: '${baseThemeKey}'`,\n 'Registered:',\n themeRegistration.base.map(theme => theme.themeKey),\n themeRegistration.custom.map(theme => theme.themeKey)\n );\n base = themeRegistration.base.find(\n theme => theme.themeKey === DEFAULT_DARK_THEME_KEY\n );\n\n assertNotNull(\n base,\n `Default base theme '${DEFAULT_DARK_THEME_KEY}' is not registered`\n );\n }\n\n log.debug('Applied themes:', base.themeKey, custom?.themeKey);\n\n return custom == null ? [base] : [base, custom];\n}\n\n/**\n * Get default base theme data.\n */\nexport function getDefaultBaseThemes(): ThemeData[] {\n return [\n {\n name: 'Default Dark',\n themeKey: DEFAULT_DARK_THEME_KEY,\n styleContent: themeDark,\n },\n // The ThemePicker shows whenever more than 1 theme is available. Disable\n // light theme for now to keep the picker hidden until it is fully\n // implemented by #1539.\n {\n name: 'Default Light',\n themeKey: DEFAULT_LIGHT_THEME_KEY,\n styleContent: themeLight,\n },\n ];\n}\n\n/**\n * Get the default selected theme key. Precedence is:\n * 1. Theme key override query parameter\n * 2. Theme key from preload data\n * 3. Default dark theme key\n * @returns The default selected theme key\n */\nexport function getDefaultSelectedThemeKey(): string {\n return (\n getThemeKeyOverride() ??\n getThemePreloadData()?.themeKey ??\n DEFAULT_DARK_THEME_KEY\n );\n}\n\n/**\n * A theme key override can be set via a query parameter to force a specific\n * theme selection. Useful for embedded widget scenarios that don't expose the\n * theme selector.\n */\nexport function getThemeKeyOverride(): string | null {\n const searchParams = new URLSearchParams(window.location.search);\n return searchParams.get(THEME_KEY_OVERRIDE_QUERY_PARAM);\n}\n\n/**\n * Get the preload data from local storage or null if it does not exist or is\n * invalid\n */\nexport function getThemePreloadData(): ThemePreloadData | null {\n const data = localStorage.getItem(THEME_CACHE_LOCAL_STORAGE_KEY);\n\n try {\n return data == null ? null : JSON.parse(data);\n } catch {\n // ignore\n }\n\n return null;\n}\n\n/**\n * Identifies start and end indices of any top-level expressions in the given\n * string.\n *\n * e.g.\n * getExpressionRanges('var(--aaa-aa) #fff var(--bbb-bb)')\n * yields:\n * [\n * [0, 12], // 'var(--aaa-aa)'\n * [14, 17] // '#fff'\n * [19, 31], // 'var(--bbb-bb)'\n * ]\n *\n * In cases where there are nested expressions, only the indices of the outermost\n * expression will be included.\n *\n * e.g.\n * getExpressionRanges('var(--ccc-cc, var(--aaa-aa, green)) var(--bbb-bb)')\n * yields:\n * [\n * [0, 34], // 'var(--ccc-cc, var(--aaa-aa, green))'\n * [36, 48], // 'var(--bbb-bb)'\n * ]\n * @param value The string to search for expressions\n * @returns An array of [start, end] index pairs for each expression\n */\nexport function getExpressionRanges(value: string): [number, number][] {\n const ranges: [number, number][] = [];\n\n let start = NON_WHITESPACE_REGEX.exec(value)?.index ?? 0;\n let parenLevel = 0;\n\n for (let i = 0; i < value.length; i += 1) {\n if (value[i] === '(') {\n parenLevel += 1;\n } else if (value[i] === ')') {\n parenLevel -= 1;\n }\n\n if (\n i === value.length - 1 ||\n (WHITESPACE_REGEX.test(value[i + 1]) && parenLevel === 0)\n ) {\n ranges.push([start, i]);\n\n while (i < value.length - 1 && WHITESPACE_REGEX.test(value[i + 1])) {\n i += 1;\n }\n\n start = i + 1;\n }\n }\n\n if (parenLevel !== 0) {\n log.error('Unbalanced parentheses in css var expression', value);\n return [];\n }\n\n return ranges;\n}\n\n/**\n * Replace the `fill='...'` attribute in the given SVG content with the given\n * color string.\n * @param svgContent Inline SVG content to replace the fill color in\n * @param fillColor The color to replace the fill color with\n */\nexport function replaceSVGFillColor(\n svgContent: string,\n fillColor: string\n): string {\n return svgContent.replace(\n /fill='.*?'/,\n `fill='${encodeURIComponent(fillColor)}'`\n );\n}\n\n/**\n * Make a copy of the given object replacing any css variable expressions\n * contained in its prop values with values resolved from the given HTML element.\n * Variables that resolve to color strings will also be normalized to 8 digit\n * hex values (or optionally 6 digit hex if `isAlphaOptional` is true).\n *\n * Note that the browser will force a reflow when calling `getComputedStyle` if\n * css properties have changed. In order to avoid a reflow for every property\n * check we use distinct setup, resolve / normalize, and cleanup passes:\n * 1. Setup - Create a tmp element and set all css props we want to evaluate\n * 2. Resolve / Normalize - Evaluate all css props via `getPropertyValue` calls\n * and replace the original expressions with resolved values. Also normalize\n * css colors to rgb/a.\n * 3. Cleanup - Remove the tmp element\n * @param record An object whose values may contain css var expressions\n * @param targetElement The element to resolve css variables against. Defaults\n * to document.body\n * @param isAlphaOptional If true, the alpha value will be dropped from resolved\n * 8 character hex colors if it is 'ff'. Defaults to false.\n */\nexport function resolveCssVariablesInRecord<T extends Record<string, string>>(\n record: T,\n targetElement: HTMLElement = document.body,\n isAlphaOptional = false\n): T {\n const perfStart = performance.now();\n\n // Add a temporary div to attach temp css variables to\n const tmpPropEl = document.createElement('div');\n tmpPropEl.style.display = 'none';\n\n const recordArray = Object.entries(record);\n recordArray.forEach(([, value], i) => {\n tmpPropEl.style.setProperty(`--${TMP_CSS_PROP_PREFIX}-${i}`, value);\n // faster to create these now all at once, even if we don't use them all\n // since the parent isn't added yet to the DOM\n const el = document.createElement('div');\n // use background color instead of color to avoid inherited values\n el.style.backgroundColor = value;\n tmpPropEl.appendChild(el);\n });\n\n // append only once to avoid multiple re-layouts\n // must be part of DOM to get computed color\n targetElement.appendChild(tmpPropEl);\n const tempPropElComputedStyle = window.getComputedStyle(tmpPropEl);\n\n const result = {} as T;\n recordArray.forEach(([key, value], i) => {\n // resolves any variables in the expression\n let resolved = tempPropElComputedStyle.getPropertyValue(\n `--${TMP_CSS_PROP_PREFIX}-${i}`\n );\n\n const containsCssVar = value.includes(CSS_VAR_EXPRESSION_PREFIX);\n const isColor = CSS.supports('color', resolved);\n\n if (\n // only try to normalize non-hex strings that are valid colors\n // otherwise non-colors will be made #00000000\n isColor &&\n !/^#[0-9A-F]{6}[0-9a-f]{0,2}$/i.test(resolved)\n ) {\n // getting the computed background color is necessary\n // because resolved can still contain a color-mix() function\n const el = tmpPropEl.children[i] as HTMLDivElement;\n const computedStyle = window.getComputedStyle(el);\n const color = computedStyle.getPropertyValue('background-color');\n // convert color to hex, which is what monaco and plotly require\n resolved = ColorUtils.normalizeCssColor(color, isAlphaOptional);\n }\n (result as Record<string, string>)[key] =\n containsCssVar || isColor ? resolved : value;\n });\n\n // Remove the temporary div\n tmpPropEl.remove();\n\n log.debug('Resolved css variables', performance.now() - perfStart, 'ms');\n\n return result;\n}\n\n/**\n * Resolve css variable expressions in the given string using the\n * given resolver and replace the original expressions with the resolved values.\n *\n * @param resolver Function that can resolve a css variable expression\n * @param value Value that may contain css variable expressions\n */\nexport function resolveCssVariablesInString(\n resolver: VarExpressionResolver,\n value: string\n): string {\n const result: string[] = [];\n let i = 0;\n getExpressionRanges(value).forEach(([start, end]) => {\n if (i < start) {\n result.push(value.substring(i, start));\n i += start - i;\n }\n\n const expression = value.substring(start, end + 1);\n\n result.push(\n expression.includes(CSS_VAR_EXPRESSION_PREFIX)\n ? resolver(expression)\n : expression\n );\n\n i += end - start + 1;\n });\n\n if (result.length === 0) {\n return value;\n }\n\n return result.join('');\n}\n\n/**\n * Store theme preload data in local storage.\n * @param preloadData The preload data to set\n */\nexport function setThemePreloadData(preloadData: ThemePreloadData): void {\n localStorage.setItem(\n THEME_CACHE_LOCAL_STORAGE_KEY,\n JSON.stringify(preloadData)\n );\n}\n\n/**\n * Derive unique theme key from plugin root path and theme name.\n * @param pluginName The root path of the plugin\n * @param themeName The name of the theme\n */\nexport function getThemeKey(pluginName: string, themeName: string): string {\n return `${pluginName}_${themeName}`;\n}\n\n/**\n * Preload minimal theme variables from the cache.\n * @defaultPreloadValues Optional default values to use if a preload variable is not set.\n */\nexport function preloadTheme(\n defaultPreloadValues: Record<string, string> = DEFAULT_PRELOAD_DATA_VARIABLES\n): void {\n const previousPreloadStyleContent =\n getThemePreloadData()?.preloadStyleContent;\n\n const defaultPreloadStyleContent =\n calculatePreloadStyleContent(defaultPreloadValues);\n\n log.debug('Preloading theme content:', {\n defaultPreloadStyleContent,\n previousPreloadStyleContent,\n });\n\n createPreloadStyleElement(\n 'theme-preload-defaults',\n defaultPreloadStyleContent\n );\n\n // Any preload variables that were saved by last theme load should override\n // the defaults\n if (previousPreloadStyleContent != null) {\n createPreloadStyleElement(\n 'theme-preload-previous',\n previousPreloadStyleContent\n );\n }\n}\n\n/**\n * Inline SVGs cannot depend on dynamic CSS variables, so we have to statically\n * update them if we want to change their color.\n *\n * This function:\n * 1. Clears any previous overrides\n * 2. Resolves CSS variables containing inline SVG urls\n * 3. Resolves mapped color variables and replaces the `fill='...'` attribute with the result\n * 4. Sets the original CSS variable to the new replaced value\n *\n * Note that it is preferable to use inline SVGs as background-mask values and\n * just change the background color instead of relying on this util, but this\n * is not always possible. e.g. <select> elements don't support pseudo elements,\n * so there's not a good way to set icons via masks.\n * @param defaultValues Default values to use if a variable is not set.\n */\nexport function overrideSVGFillColors(\n defaultValues: Record<string, string>\n): void {\n const resolveVar = createCssVariableResolver(document.body, defaultValues);\n\n Object.entries(SVG_ICON_MANUAL_COLOR_MAP).forEach(([key, value]) => {\n // Clear any previous override so that our variables get resolved against the\n // actual svg content provided by the active themes and not from a previous\n // override\n document.body.style.removeProperty(key);\n\n const svgContent = resolveVar(key as ThemeIconsRequiringManualColorChanges);\n const fillColor = resolveVar(value as ThemePreloadColorVariable);\n\n const newSVGContent = replaceSVGFillColor(svgContent, fillColor);\n\n // This will take precedence over any values for the variable provided by\n // the active themes\n document.body.style.setProperty(key, newSVGContent);\n });\n}\n"],"mappings":"AAAA,OAAOA,GAAG,MAAM,gBAAgB;AAChC,SAASC,aAAa,EAAEC,UAAU,QAAQ,kBAAkB;AAAC,SACpDC,SAAS;AAAA,SACTC,UAAU;AAAA,SAEjBC,sBAAsB,EACtBC,uBAAuB,EACvBC,8BAA8B,EAM9BC,6BAA6B,EAC7BC,yBAAyB,EAGzBC,8BAA8B;AAGhC,IAAMC,GAAG,GAAGX,GAAG,CAACY,MAAM,CAAC,YAAY,CAAC;AAEpC,OAAO,IAAMC,yBAAyB,GAAG,QAAQ;AACjD,OAAO,IAAMC,mBAAmB,GAAG,QAAQ;AAC3C,OAAO,IAAMC,oBAAoB,GAAG,IAAI;AACxC,OAAO,IAAMC,gBAAgB,GAAG,IAAI;AAIpC;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,4BAA4BA,CAC1CC,oBAA4C,EACnB;EACzB,IAAMC,UAAU,GAAGC,yBAAyB,CAC1CC,QAAQ,CAACC,IAAI,EACbJ,oBACF,CAAC;;EAED;EACA;EACA,IAAMK,KAAK,GAAGC,MAAM,CAACC,IAAI,CAACP,oBAAoB,CAAC,CAACQ,GAAG,CACjDC,GAAG,OAAAC,MAAA,CAAOD,GAAG,OAAAC,M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AkB;IAAA,IAAjB,CAAC3H,GAAG,EAAEU,KAAK,CAAC,GAAAiH,KAAA;IAC7D;IACA;IACA;IACAjI,QAAQ,CAACC,IAAI,CAACoB,KAAK,CAAC6G,cAAc,CAAC5H,GAAG,CAAC;IAEvC,IAAM6E,UAAU,GAAGrF,UAAU,CAACQ,GAA4C,CAAC;IAC3E,IAAM8E,SAAS,GAAGtF,UAAU,CAACkB,KAAkC,CAAC;IAEhE,IAAMmH,aAAa,GAAGjD,mBAAmB,CAACC,UAAU,EAAEC,SAAS,CAAC;;IAEhE;IACA;IACApF,QAAQ,CAACC,IAAI,CAACoB,KAAK,CAAC+E,WAAW,CAAC9F,GAAG,EAAE6H,aAAa,CAAC;EACrD,CAAC,CAAC;AACJ"}
|
package/dist/theme/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/theme/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,QAAQ,CAAC;AACvB,cAAc,cAAc,CAAC;AAC7B,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/theme/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,QAAQ,CAAC;AACvB,cAAc,cAAc,CAAC;AAC7B,cAAc,4BAA4B,CAAC"}
|
package/dist/theme/index.js
CHANGED
package/dist/theme/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../src/theme/index.ts"],"sourcesContent":["export * from './theme-dark';\nexport * from './theme-light';\nexport * from './ThemeModel';\nexport * from './ThemePicker';\nexport * from './ThemeProvider';\nexport * from './ThemeUtils';\nexport * from './useTheme';\nexport * from './Logo';\nexport * from './colorUtils';\nexport * from './
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/theme/index.ts"],"sourcesContent":["export * from './theme-dark';\nexport * from './theme-light';\nexport * from './ThemeModel';\nexport * from './ThemePicker';\nexport * from './ThemeProvider';\nexport * from './ThemeUtils';\nexport * from './useTheme';\nexport * from './Logo';\nexport * from './colorUtils';\nexport * from './useSpectrumThemeProvider';\n"],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@deephaven/components",
|
|
3
|
-
"version": "0.108.1-
|
|
3
|
+
"version": "0.108.1-input-filters.21+e9ba02e0",
|
|
4
4
|
"description": "Deephaven React component library",
|
|
5
5
|
"author": "Deephaven Data Labs LLC",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -25,10 +25,10 @@
|
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"@adobe/react-spectrum": "3.38.0",
|
|
28
|
-
"@deephaven/icons": "^0.108.1-
|
|
29
|
-
"@deephaven/log": "^0.108.1-
|
|
30
|
-
"@deephaven/react-hooks": "^0.108.1-
|
|
31
|
-
"@deephaven/utils": "^0.108.1-
|
|
28
|
+
"@deephaven/icons": "^0.108.1-input-filters.21+e9ba02e0",
|
|
29
|
+
"@deephaven/log": "^0.108.1-input-filters.21+e9ba02e0",
|
|
30
|
+
"@deephaven/react-hooks": "^0.108.1-input-filters.21+e9ba02e0",
|
|
31
|
+
"@deephaven/utils": "^0.108.1-input-filters.21+e9ba02e0",
|
|
32
32
|
"@fortawesome/fontawesome-svg-core": "^6.2.1",
|
|
33
33
|
"@fortawesome/react-fontawesome": "^0.2.0",
|
|
34
34
|
"@internationalized/date": "^3.5.5",
|
|
@@ -61,8 +61,8 @@
|
|
|
61
61
|
"react-is": ">=16.8.0"
|
|
62
62
|
},
|
|
63
63
|
"devDependencies": {
|
|
64
|
-
"@deephaven/mocks": "^0.108.1-
|
|
65
|
-
"@deephaven/test-utils": "^0.108.1-
|
|
64
|
+
"@deephaven/mocks": "^0.108.1-input-filters.21+e9ba02e0",
|
|
65
|
+
"@deephaven/test-utils": "^0.108.1-input-filters.21+e9ba02e0",
|
|
66
66
|
"react-redux": "^7.2.4"
|
|
67
67
|
},
|
|
68
68
|
"files": [
|
|
@@ -77,5 +77,5 @@
|
|
|
77
77
|
"publishConfig": {
|
|
78
78
|
"access": "public"
|
|
79
79
|
},
|
|
80
|
-
"gitHead": "
|
|
80
|
+
"gitHead": "e9ba02e045afe589e4700d15ba0908779155efd5"
|
|
81
81
|
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { type ThemeData } from './ThemeModel';
|
|
2
|
-
export interface UseExternalThemeResult {
|
|
3
|
-
isEnabled: boolean;
|
|
4
|
-
isPending: boolean;
|
|
5
|
-
themeData?: ThemeData;
|
|
6
|
-
}
|
|
7
|
-
/**
|
|
8
|
-
* If external theme is configured via `theme=EXTERNAL_THEME_KEY` query param,
|
|
9
|
-
* handle `postMessage` communication to retrieve the theme data from the parent
|
|
10
|
-
* Window. The hook will also listen for `MSG_REQUEST_SET_THEME` messages from
|
|
11
|
-
* the parent and current Window to allow explicitly setting the theme.
|
|
12
|
-
*/
|
|
13
|
-
export declare function useExternalTheme(): UseExternalThemeResult;
|
|
14
|
-
export default useExternalTheme;
|
|
15
|
-
//# sourceMappingURL=useExternalTheme.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useExternalTheme.d.ts","sourceRoot":"","sources":["../../src/theme/useExternalTheme.ts"],"names":[],"mappings":"AAGA,OAAO,EAGL,KAAK,SAAS,EACf,MAAM,cAAc,CAAC;AAStB,MAAM,WAAW,sBAAsB;IACrC,SAAS,EAAE,OAAO,CAAC;IACnB,SAAS,EAAE,OAAO,CAAC;IACnB,SAAS,CAAC,EAAE,SAAS,CAAC;CACvB;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,IAAI,sBAAsB,CA8DzD;AAED,eAAe,gBAAgB,CAAC"}
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { useCallback, useEffect, useState } from 'react';
|
|
2
|
-
import Log from '@deephaven/log';
|
|
3
|
-
import { getWindowParent } from '@deephaven/utils';
|
|
4
|
-
import { MSG_REQUEST_SET_THEME } from "./ThemeModel.js";
|
|
5
|
-
import { isExternalThemeData, isExternalThemeEnabled, parseExternalThemeData, requestExternalThemeData } from "./ThemeUtils.js";
|
|
6
|
-
var logger = Log.module('useExternalTheme');
|
|
7
|
-
/**
|
|
8
|
-
* If external theme is configured via `theme=EXTERNAL_THEME_KEY` query param,
|
|
9
|
-
* handle `postMessage` communication to retrieve the theme data from the parent
|
|
10
|
-
* Window. The hook will also listen for `MSG_REQUEST_SET_THEME` messages from
|
|
11
|
-
* the parent and current Window to allow explicitly setting the theme.
|
|
12
|
-
*/
|
|
13
|
-
export function useExternalTheme() {
|
|
14
|
-
var [result, setResult] = useState(() => {
|
|
15
|
-
var isEnabled = isExternalThemeEnabled();
|
|
16
|
-
return {
|
|
17
|
-
isEnabled,
|
|
18
|
-
isPending: isEnabled
|
|
19
|
-
};
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
/** Parse external theme data and update the result */
|
|
23
|
-
var handleExternalThemeData = useCallback(externalThemeData => {
|
|
24
|
-
var themeData = parseExternalThemeData(externalThemeData);
|
|
25
|
-
setResult({
|
|
26
|
-
isEnabled: true,
|
|
27
|
-
isPending: false,
|
|
28
|
-
themeData
|
|
29
|
-
});
|
|
30
|
-
}, []);
|
|
31
|
-
useEffect(() => {
|
|
32
|
-
if (!result.isEnabled) {
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
logger.debug('Requesting external theme data');
|
|
36
|
-
|
|
37
|
-
/** Parent or current Window can explicitly set the theme */
|
|
38
|
-
function onMessage(event) {
|
|
39
|
-
var parent = getWindowParent();
|
|
40
|
-
|
|
41
|
-
// Allow messages from parent or current window
|
|
42
|
-
if (event.source !== window && event.source !== parent) {
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
if (event.data.message === MSG_REQUEST_SET_THEME) {
|
|
46
|
-
if (isExternalThemeData(event.data.payload)) {
|
|
47
|
-
handleExternalThemeData(event.data.payload);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
window.addEventListener('message', onMessage);
|
|
52
|
-
|
|
53
|
-
/** Request initial theme data from parent window */
|
|
54
|
-
requestExternalThemeData().then(handleExternalThemeData).catch(err => {
|
|
55
|
-
logger.error(err);
|
|
56
|
-
setResult({
|
|
57
|
-
isEnabled: true,
|
|
58
|
-
isPending: false
|
|
59
|
-
});
|
|
60
|
-
});
|
|
61
|
-
return () => {
|
|
62
|
-
window.removeEventListener('message', onMessage);
|
|
63
|
-
};
|
|
64
|
-
}, [handleExternalThemeData, result.isEnabled]);
|
|
65
|
-
return result;
|
|
66
|
-
}
|
|
67
|
-
export default useExternalTheme;
|
|
68
|
-
//# sourceMappingURL=useExternalTheme.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useExternalTheme.js","names":["useCallback","useEffect","useState","Log","getWindowParent","MSG_REQUEST_SET_THEME","isExternalThemeData","isExternalThemeEnabled","parseExternalThemeData","requestExternalThemeData","logger","module","useExternalTheme","result","setResult","isEnabled","isPending","handleExternalThemeData","externalThemeData","themeData","debug","onMessage","event","parent","source","window","data","message","payload","addEventListener","then","catch","err","error","removeEventListener"],"sources":["../../src/theme/useExternalTheme.ts"],"sourcesContent":["import { useCallback, useEffect, useState } from 'react';\nimport Log from '@deephaven/log';\nimport { getWindowParent, type PostMessage } from '@deephaven/utils';\nimport {\n MSG_REQUEST_SET_THEME,\n type ExternalThemeData,\n type ThemeData,\n} from './ThemeModel';\nimport {\n isExternalThemeData,\n isExternalThemeEnabled,\n parseExternalThemeData,\n requestExternalThemeData,\n} from './ThemeUtils';\n\nconst logger = Log.module('useExternalTheme');\nexport interface UseExternalThemeResult {\n isEnabled: boolean;\n isPending: boolean;\n themeData?: ThemeData;\n}\n\n/**\n * If external theme is configured via `theme=EXTERNAL_THEME_KEY` query param,\n * handle `postMessage` communication to retrieve the theme data from the parent\n * Window. The hook will also listen for `MSG_REQUEST_SET_THEME` messages from\n * the parent and current Window to allow explicitly setting the theme.\n */\nexport function useExternalTheme(): UseExternalThemeResult {\n const [result, setResult] = useState<UseExternalThemeResult>(() => {\n const isEnabled = isExternalThemeEnabled();\n return {\n isEnabled,\n isPending: isEnabled,\n };\n });\n\n /** Parse external theme data and update the result */\n const handleExternalThemeData = useCallback(\n (externalThemeData: ExternalThemeData) => {\n const themeData = parseExternalThemeData(externalThemeData);\n\n setResult({\n isEnabled: true,\n isPending: false,\n themeData,\n });\n },\n []\n );\n\n useEffect(() => {\n if (!result.isEnabled) {\n return;\n }\n\n logger.debug('Requesting external theme data');\n\n /** Parent or current Window can explicitly set the theme */\n function onMessage(event: MessageEvent<PostMessage<unknown>>): void {\n const parent = getWindowParent();\n\n // Allow messages from parent or current window\n if (event.source !== window && event.source !== parent) {\n return;\n }\n\n if (event.data.message === MSG_REQUEST_SET_THEME) {\n if (isExternalThemeData(event.data.payload)) {\n handleExternalThemeData(event.data.payload);\n }\n }\n }\n\n window.addEventListener('message', onMessage);\n\n /** Request initial theme data from parent window */\n requestExternalThemeData()\n .then(handleExternalThemeData)\n .catch(err => {\n logger.error(err);\n setResult({ isEnabled: true, isPending: false });\n });\n\n return () => {\n window.removeEventListener('message', onMessage);\n };\n }, [handleExternalThemeData, result.isEnabled]);\n\n return result;\n}\n\nexport default useExternalTheme;\n"],"mappings":"AAAA,SAASA,WAAW,EAAEC,SAAS,EAAEC,QAAQ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