@mirai/core 0.4.159 → 0.4.160
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/build/helpers/theme.js +0 -28
- package/build/helpers/theme.js.map +1 -1
- package/package.json +1 -1
package/build/helpers/theme.js
CHANGED
|
@@ -9,22 +9,12 @@ var _findDangerousCSSRules = require("./findDangerousCSSRules");
|
|
|
9
9
|
var _helpers = require("../components/helpers");
|
|
10
10
|
let cssTheme;
|
|
11
11
|
if (!_helpers.IS_JEST) cssTheme = require('bundle-text:../theme.css');
|
|
12
|
-
const BROWSER_FONTS = ['"system-ui"', 'serif', 'Times', '"Times New Roman"', '-webkit-standard'];
|
|
13
|
-
const FONT_FAMILY = 'font-family';
|
|
14
12
|
const LEGACY_ACCENT_VARIABLE = '--corporative-color';
|
|
15
|
-
const VARIABLES = {};
|
|
16
13
|
const theme = function () {
|
|
17
14
|
let {
|
|
18
15
|
accent = '',
|
|
19
16
|
findDangerousCSS = false
|
|
20
17
|
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
21
|
-
const processed = [];
|
|
22
|
-
const setVariable = (key, value) => {
|
|
23
|
-
if (!value || processed.includes(key)) return;
|
|
24
|
-
document.documentElement.style.setProperty(key, value.trim());
|
|
25
|
-
processed.push(key);
|
|
26
|
-
};
|
|
27
|
-
|
|
28
18
|
// Import css variables from theme.css
|
|
29
19
|
if (cssTheme) {
|
|
30
20
|
const style = document.createElement('style');
|
|
@@ -33,30 +23,12 @@ const theme = function () {
|
|
|
33
23
|
head.insertBefore(style, head.firstChild);
|
|
34
24
|
}
|
|
35
25
|
|
|
36
|
-
// CSS variables
|
|
37
|
-
Object.entries(VARIABLES).forEach(_ref => {
|
|
38
|
-
let [variable, legacy] = _ref;
|
|
39
|
-
if (getComputedStyle(document.documentElement).getPropertyValue(legacy)) setVariable(variable, "var(".concat(legacy, ")"));
|
|
40
|
-
});
|
|
41
|
-
|
|
42
26
|
// Generate accent palette using legacy
|
|
43
27
|
let legacyAccent = getComputedStyle(document.documentElement).getPropertyValue(LEGACY_ACCENT_VARIABLE);
|
|
44
28
|
if (legacyAccent) {
|
|
45
29
|
legacyAccent = legacyAccent.replace(/^"|"$/g, '').trim();
|
|
46
30
|
_ui.Theme.generatePalette('accent', legacyAccent);
|
|
47
31
|
}
|
|
48
|
-
|
|
49
|
-
// CSS Selectors
|
|
50
|
-
let font;
|
|
51
|
-
const bodyFont = window.getComputedStyle(document.body).getPropertyValue(FONT_FAMILY);
|
|
52
|
-
if (bodyFont && !BROWSER_FONTS.includes(bodyFont)) {
|
|
53
|
-
font = bodyFont;
|
|
54
|
-
} else {
|
|
55
|
-
const miBe = document.querySelector('.mi-be');
|
|
56
|
-
const miBeFont = miBe ? window.getComputedStyle(miBe).getPropertyValue(FONT_FAMILY) : undefined;
|
|
57
|
-
if (miBeFont && !BROWSER_FONTS.includes(miBeFont)) font = miBeFont;
|
|
58
|
-
}
|
|
59
|
-
if (font) setVariable('--mirai-ui-font', font);
|
|
60
32
|
if (accent.length === 6) _ui.Theme.generatePalette('accent', "#".concat(accent));
|
|
61
33
|
|
|
62
34
|
// Dangerous CSS rules
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"theme.js","names":["_ui","require","_findDangerousCSSRules","_helpers","cssTheme","IS_JEST","
|
|
1
|
+
{"version":3,"file":"theme.js","names":["_ui","require","_findDangerousCSSRules","_helpers","cssTheme","IS_JEST","LEGACY_ACCENT_VARIABLE","theme","accent","findDangerousCSS","arguments","length","undefined","style","document","createElement","head","textContent","insertBefore","firstChild","legacyAccent","getComputedStyle","documentElement","getPropertyValue","replace","trim","Theme","generatePalette","concat","cssRules","findDangerousCSSRules","console","warn","exports"],"sources":["../../src/helpers/theme.js"],"sourcesContent":["import { Theme } from '@mirai/ui';\n\nimport { findDangerousCSSRules } from './findDangerousCSSRules';\nimport { IS_JEST } from '../components/helpers';\n\nlet cssTheme;\nif (!IS_JEST) cssTheme = require('bundle-text:../theme.css');\n\nconst LEGACY_ACCENT_VARIABLE = '--corporative-color';\n\nexport const theme = ({ accent = '', findDangerousCSS = false } = {}) => {\n // Import css variables from theme.css\n if (cssTheme) {\n const style = document.createElement('style');\n const head = document.head;\n style.textContent = cssTheme;\n head.insertBefore(style, head.firstChild);\n }\n\n // Generate accent palette using legacy\n let legacyAccent = getComputedStyle(document.documentElement).getPropertyValue(LEGACY_ACCENT_VARIABLE);\n if (legacyAccent) {\n legacyAccent = legacyAccent.replace(/^\"|\"$/g, '').trim();\n Theme.generatePalette('accent', legacyAccent);\n }\n\n if (accent.length === 6) Theme.generatePalette('accent', `#${accent}`);\n\n // Dangerous CSS rules\n if (findDangerousCSS) {\n const cssRules = findDangerousCSSRules();\n // eslint-disable-next-line no-console\n if (cssRules.length) console.warn('WARNING: css rules ending with html tags', cssRules);\n }\n};\n"],"mappings":";;;;;;AAAA,IAAAA,GAAA,GAAAC,OAAA;AAEA,IAAAC,sBAAA,GAAAD,OAAA;AACA,IAAAE,QAAA,GAAAF,OAAA;AAEA,IAAIG,QAAQ;AACZ,IAAI,CAACC,gBAAO,EAAED,QAAQ,GAAGH,OAAO,CAAC,0BAA0B,CAAC;AAE5D,MAAMK,sBAAsB,GAAG,qBAAqB;AAE7C,MAAMC,KAAK,GAAG,SAAAA,CAAA,EAAoD;EAAA,IAAnD;IAAEC,MAAM,GAAG,EAAE;IAAEC,gBAAgB,GAAG;EAAM,CAAC,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,CAAC,CAAC;EAClE;EACA,IAAIN,QAAQ,EAAE;IACZ,MAAMS,KAAK,GAAGC,QAAQ,CAACC,aAAa,CAAC,OAAO,CAAC;IAC7C,MAAMC,IAAI,GAAGF,QAAQ,CAACE,IAAI;IAC1BH,KAAK,CAACI,WAAW,GAAGb,QAAQ;IAC5BY,IAAI,CAACE,YAAY,CAACL,KAAK,EAAEG,IAAI,CAACG,UAAU,CAAC;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