@microsoft/load-themed-styles
Advanced tools
Comparing version 2.0.77 to 2.0.78
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. | ||
// See LICENSE in the project root for license information. | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
define(["require", "exports"], function (require, exports) { | ||
@@ -9,15 +20,17 @@ "use strict"; | ||
// load-themed-styles hosted on the page. | ||
const _root = typeof window === 'undefined' ? global : window; // eslint-disable-line @typescript-eslint/no-explicit-any | ||
var _root = typeof window === 'undefined' ? global : window; // eslint-disable-line @typescript-eslint/no-explicit-any | ||
// Nonce string to inject into script tag if one provided. This is used in CSP (Content Security Policy). | ||
const _styleNonce = _root && _root.CSPSettings && _root.CSPSettings.nonce; | ||
const _themeState = initializeThemeState(); | ||
var _styleNonce = _root && _root.CSPSettings && _root.CSPSettings.nonce; | ||
var _themeState = initializeThemeState(); | ||
/** | ||
* Matches theming tokens. For example, "[theme: themeSlotName, default: #FFF]" (including the quotes). | ||
*/ | ||
const _themeTokenRegex = /[\'\"]\[theme:\s*(\w+)\s*(?:\,\s*default:\s*([\\"\']?[\.\,\(\)\#\-\s\w]*[\.\,\(\)\#\-\w][\"\']?))?\s*\][\'\"]/g; | ||
const now = () => typeof performance !== 'undefined' && !!performance.now ? performance.now() : Date.now(); | ||
var _themeTokenRegex = /[\'\"]\[theme:\s*(\w+)\s*(?:\,\s*default:\s*([\\"\']?[\.\,\(\)\#\-\s\w]*[\.\,\(\)\#\-\w][\"\']?))?\s*\][\'\"]/g; | ||
var now = function () { | ||
return typeof performance !== 'undefined' && !!performance.now ? performance.now() : Date.now(); | ||
}; | ||
function measure(func) { | ||
const start = now(); | ||
var start = now(); | ||
func(); | ||
const end = now(); | ||
var end = now(); | ||
_themeState.perf.duration += end - start; | ||
@@ -29,3 +42,3 @@ } | ||
function initializeThemeState() { | ||
let state = _root.__themeState__ || { | ||
var state = _root.__themeState__ || { | ||
theme: undefined, | ||
@@ -36,3 +49,3 @@ lastStyleElement: undefined, | ||
if (!state.runState) { | ||
state = Object.assign(Object.assign({}, state), { perf: { | ||
state = __assign(__assign({}, state), { perf: { | ||
count: 0, | ||
@@ -47,3 +60,3 @@ duration: 0 | ||
if (!state.registeredThemableStyles) { | ||
state = Object.assign(Object.assign({}, state), { registeredThemableStyles: [] }); | ||
state = __assign(__assign({}, state), { registeredThemableStyles: [] }); | ||
} | ||
@@ -59,6 +72,7 @@ _root.__themeState__ = state; | ||
*/ | ||
function loadStyles(styles, loadAsync = false) { | ||
measure(() => { | ||
const styleParts = Array.isArray(styles) ? styles : splitStyles(styles); | ||
const { mode, buffer, flushTimer } = _themeState.runState; | ||
function loadStyles(styles, loadAsync) { | ||
if (loadAsync === void 0) { loadAsync = false; } | ||
measure(function () { | ||
var styleParts = Array.isArray(styles) ? styles : splitStyles(styles); | ||
var _a = _themeState.runState, mode = _a.mode, buffer = _a.buffer, flushTimer = _a.flushTimer; | ||
if (loadAsync || mode === 1 /* Mode.async */) { | ||
@@ -97,6 +111,6 @@ buffer.push(styleParts); | ||
function flush() { | ||
measure(() => { | ||
const styleArrays = _themeState.runState.buffer.slice(); | ||
measure(function () { | ||
var styleArrays = _themeState.runState.buffer.slice(); | ||
_themeState.runState.buffer = []; | ||
const mergedStyleArray = [].concat.apply([], styleArrays); | ||
var mergedStyleArray = [].concat.apply([], styleArrays); | ||
if (mergedStyleArray.length > 0) { | ||
@@ -114,3 +128,3 @@ applyThemableStyles(mergedStyleArray); | ||
// https://github.com/jestjs/jest/issues/14418 | ||
return self.setTimeout(() => { | ||
return self.setTimeout(function () { | ||
_themeState.runState.flushTimer = 0; | ||
@@ -150,3 +164,4 @@ flush(); | ||
*/ | ||
function clearStyles(option = 3 /* ClearStyleOptions.all */) { | ||
function clearStyles(option) { | ||
if (option === void 0) { option = 3 /* ClearStyleOptions.all */; } | ||
if (option === 3 /* ClearStyleOptions.all */ || option === 2 /* ClearStyleOptions.onlyNonThemable */) { | ||
@@ -163,4 +178,4 @@ clearStylesInternal(_themeState.registeredStyles); | ||
function clearStylesInternal(records) { | ||
records.forEach((styleRecord) => { | ||
const styleElement = styleRecord && styleRecord.styleElement; | ||
records.forEach(function (styleRecord) { | ||
var styleElement = styleRecord && styleRecord.styleElement; | ||
if (styleElement && styleElement.parentElement) { | ||
@@ -176,4 +191,5 @@ styleElement.parentElement.removeChild(styleElement); | ||
if (_themeState.theme) { | ||
const themableStyles = []; | ||
for (const styleRecord of _themeState.registeredThemableStyles) { | ||
var themableStyles = []; | ||
for (var _i = 0, _a = _themeState.registeredThemableStyles; _i < _a.length; _i++) { | ||
var styleRecord = _a[_i]; | ||
themableStyles.push(styleRecord.themableStyle); | ||
@@ -203,13 +219,13 @@ } | ||
function resolveThemableArray(splitStyleArray) { | ||
const { theme } = _themeState; | ||
let themable = false; | ||
var theme = _themeState.theme; | ||
var themable = false; | ||
// Resolve the array of theming instructions to an array of strings. | ||
// Then join the array to produce the final CSS string. | ||
const resolvedArray = (splitStyleArray || []).map((currentValue) => { | ||
const themeSlot = currentValue.theme; | ||
var resolvedArray = (splitStyleArray || []).map(function (currentValue) { | ||
var themeSlot = currentValue.theme; | ||
if (themeSlot) { | ||
themable = true; | ||
// A theming annotation. Resolve it. | ||
const themedValue = theme ? theme[themeSlot] : undefined; | ||
const defaultValue = currentValue.defaultValue || 'inherit'; | ||
var themedValue = theme ? theme[themeSlot] : undefined; | ||
var defaultValue = currentValue.defaultValue || 'inherit'; | ||
// Warn to console if we hit an unthemed value even when themes are provided, but only if "DEBUG" is true. | ||
@@ -223,3 +239,3 @@ // Allow the themedValue to be undefined to explicitly request the default value. | ||
DEBUG) { | ||
console.warn(`Theming value not provided for "${themeSlot}". Falling back to "${defaultValue}".`); | ||
console.warn("Theming value not provided for \"".concat(themeSlot, "\". Falling back to \"").concat(defaultValue, "\".")); | ||
} | ||
@@ -243,8 +259,8 @@ return themedValue || defaultValue; | ||
function splitStyles(styles) { | ||
const result = []; | ||
var result = []; | ||
if (styles) { | ||
let pos = 0; // Current position in styles. | ||
let tokenMatch; | ||
var pos = 0; // Current position in styles. | ||
var tokenMatch = void 0; | ||
while ((tokenMatch = _themeTokenRegex.exec(styles))) { | ||
const matchIndex = tokenMatch.index; | ||
var matchIndex = tokenMatch.index; | ||
if (matchIndex > pos) { | ||
@@ -280,5 +296,5 @@ result.push({ | ||
} | ||
const head = document.getElementsByTagName('head')[0]; | ||
const styleElement = document.createElement('style'); | ||
const { styleString, themable } = resolveThemableArray(styleArray); | ||
var head = document.getElementsByTagName('head')[0]; | ||
var styleElement = document.createElement('style'); | ||
var _a = resolveThemableArray(styleArray), styleString = _a.styleString, themable = _a.themable; | ||
styleElement.setAttribute('data-load-themed-styles', 'true'); | ||
@@ -291,3 +307,3 @@ if (_styleNonce) { | ||
head.appendChild(styleElement); | ||
const ev = document.createEvent('HTMLEvents'); | ||
var ev = document.createEvent('HTMLEvents'); | ||
ev.initEvent('styleinsert', true /* bubbleEvent */, false /* cancelable */); | ||
@@ -298,3 +314,3 @@ ev.args = { | ||
document.dispatchEvent(ev); | ||
const record = { | ||
var record = { | ||
styleElement: styleElement, | ||
@@ -301,0 +317,0 @@ themableStyle: styleArray |
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. | ||
// See LICENSE in the project root for license information. | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
// Store the theming state in __themeState__ global scope for reuse in the case of duplicate | ||
// load-themed-styles hosted on the page. | ||
const _root = typeof window === 'undefined' ? global : window; // eslint-disable-line @typescript-eslint/no-explicit-any | ||
var _root = typeof window === 'undefined' ? global : window; // eslint-disable-line @typescript-eslint/no-explicit-any | ||
// Nonce string to inject into script tag if one provided. This is used in CSP (Content Security Policy). | ||
const _styleNonce = _root && _root.CSPSettings && _root.CSPSettings.nonce; | ||
const _themeState = initializeThemeState(); | ||
var _styleNonce = _root && _root.CSPSettings && _root.CSPSettings.nonce; | ||
var _themeState = initializeThemeState(); | ||
/** | ||
* Matches theming tokens. For example, "[theme: themeSlotName, default: #FFF]" (including the quotes). | ||
*/ | ||
const _themeTokenRegex = /[\'\"]\[theme:\s*(\w+)\s*(?:\,\s*default:\s*([\\"\']?[\.\,\(\)\#\-\s\w]*[\.\,\(\)\#\-\w][\"\']?))?\s*\][\'\"]/g; | ||
const now = () => typeof performance !== 'undefined' && !!performance.now ? performance.now() : Date.now(); | ||
var _themeTokenRegex = /[\'\"]\[theme:\s*(\w+)\s*(?:\,\s*default:\s*([\\"\']?[\.\,\(\)\#\-\s\w]*[\.\,\(\)\#\-\w][\"\']?))?\s*\][\'\"]/g; | ||
var now = function () { | ||
return typeof performance !== 'undefined' && !!performance.now ? performance.now() : Date.now(); | ||
}; | ||
function measure(func) { | ||
const start = now(); | ||
var start = now(); | ||
func(); | ||
const end = now(); | ||
var end = now(); | ||
_themeState.perf.duration += end - start; | ||
@@ -24,3 +37,3 @@ } | ||
function initializeThemeState() { | ||
let state = _root.__themeState__ || { | ||
var state = _root.__themeState__ || { | ||
theme: undefined, | ||
@@ -31,3 +44,3 @@ lastStyleElement: undefined, | ||
if (!state.runState) { | ||
state = Object.assign(Object.assign({}, state), { perf: { | ||
state = __assign(__assign({}, state), { perf: { | ||
count: 0, | ||
@@ -42,3 +55,3 @@ duration: 0 | ||
if (!state.registeredThemableStyles) { | ||
state = Object.assign(Object.assign({}, state), { registeredThemableStyles: [] }); | ||
state = __assign(__assign({}, state), { registeredThemableStyles: [] }); | ||
} | ||
@@ -54,6 +67,7 @@ _root.__themeState__ = state; | ||
*/ | ||
export function loadStyles(styles, loadAsync = false) { | ||
measure(() => { | ||
const styleParts = Array.isArray(styles) ? styles : splitStyles(styles); | ||
const { mode, buffer, flushTimer } = _themeState.runState; | ||
export function loadStyles(styles, loadAsync) { | ||
if (loadAsync === void 0) { loadAsync = false; } | ||
measure(function () { | ||
var styleParts = Array.isArray(styles) ? styles : splitStyles(styles); | ||
var _a = _themeState.runState, mode = _a.mode, buffer = _a.buffer, flushTimer = _a.flushTimer; | ||
if (loadAsync || mode === 1 /* Mode.async */) { | ||
@@ -89,6 +103,6 @@ buffer.push(styleParts); | ||
export function flush() { | ||
measure(() => { | ||
const styleArrays = _themeState.runState.buffer.slice(); | ||
measure(function () { | ||
var styleArrays = _themeState.runState.buffer.slice(); | ||
_themeState.runState.buffer = []; | ||
const mergedStyleArray = [].concat.apply([], styleArrays); | ||
var mergedStyleArray = [].concat.apply([], styleArrays); | ||
if (mergedStyleArray.length > 0) { | ||
@@ -105,3 +119,3 @@ applyThemableStyles(mergedStyleArray); | ||
// https://github.com/jestjs/jest/issues/14418 | ||
return self.setTimeout(() => { | ||
return self.setTimeout(function () { | ||
_themeState.runState.flushTimer = 0; | ||
@@ -140,3 +154,4 @@ flush(); | ||
*/ | ||
export function clearStyles(option = 3 /* ClearStyleOptions.all */) { | ||
export function clearStyles(option) { | ||
if (option === void 0) { option = 3 /* ClearStyleOptions.all */; } | ||
if (option === 3 /* ClearStyleOptions.all */ || option === 2 /* ClearStyleOptions.onlyNonThemable */) { | ||
@@ -152,4 +167,4 @@ clearStylesInternal(_themeState.registeredStyles); | ||
function clearStylesInternal(records) { | ||
records.forEach((styleRecord) => { | ||
const styleElement = styleRecord && styleRecord.styleElement; | ||
records.forEach(function (styleRecord) { | ||
var styleElement = styleRecord && styleRecord.styleElement; | ||
if (styleElement && styleElement.parentElement) { | ||
@@ -165,4 +180,5 @@ styleElement.parentElement.removeChild(styleElement); | ||
if (_themeState.theme) { | ||
const themableStyles = []; | ||
for (const styleRecord of _themeState.registeredThemableStyles) { | ||
var themableStyles = []; | ||
for (var _i = 0, _a = _themeState.registeredThemableStyles; _i < _a.length; _i++) { | ||
var styleRecord = _a[_i]; | ||
themableStyles.push(styleRecord.themableStyle); | ||
@@ -191,13 +207,13 @@ } | ||
function resolveThemableArray(splitStyleArray) { | ||
const { theme } = _themeState; | ||
let themable = false; | ||
var theme = _themeState.theme; | ||
var themable = false; | ||
// Resolve the array of theming instructions to an array of strings. | ||
// Then join the array to produce the final CSS string. | ||
const resolvedArray = (splitStyleArray || []).map((currentValue) => { | ||
const themeSlot = currentValue.theme; | ||
var resolvedArray = (splitStyleArray || []).map(function (currentValue) { | ||
var themeSlot = currentValue.theme; | ||
if (themeSlot) { | ||
themable = true; | ||
// A theming annotation. Resolve it. | ||
const themedValue = theme ? theme[themeSlot] : undefined; | ||
const defaultValue = currentValue.defaultValue || 'inherit'; | ||
var themedValue = theme ? theme[themeSlot] : undefined; | ||
var defaultValue = currentValue.defaultValue || 'inherit'; | ||
// Warn to console if we hit an unthemed value even when themes are provided, but only if "DEBUG" is true. | ||
@@ -211,3 +227,3 @@ // Allow the themedValue to be undefined to explicitly request the default value. | ||
DEBUG) { | ||
console.warn(`Theming value not provided for "${themeSlot}". Falling back to "${defaultValue}".`); | ||
console.warn("Theming value not provided for \"".concat(themeSlot, "\". Falling back to \"").concat(defaultValue, "\".")); | ||
} | ||
@@ -231,8 +247,8 @@ return themedValue || defaultValue; | ||
export function splitStyles(styles) { | ||
const result = []; | ||
var result = []; | ||
if (styles) { | ||
let pos = 0; // Current position in styles. | ||
let tokenMatch; | ||
var pos = 0; // Current position in styles. | ||
var tokenMatch = void 0; | ||
while ((tokenMatch = _themeTokenRegex.exec(styles))) { | ||
const matchIndex = tokenMatch.index; | ||
var matchIndex = tokenMatch.index; | ||
if (matchIndex > pos) { | ||
@@ -267,5 +283,5 @@ result.push({ | ||
} | ||
const head = document.getElementsByTagName('head')[0]; | ||
const styleElement = document.createElement('style'); | ||
const { styleString, themable } = resolveThemableArray(styleArray); | ||
var head = document.getElementsByTagName('head')[0]; | ||
var styleElement = document.createElement('style'); | ||
var _a = resolveThemableArray(styleArray), styleString = _a.styleString, themable = _a.themable; | ||
styleElement.setAttribute('data-load-themed-styles', 'true'); | ||
@@ -278,3 +294,3 @@ if (_styleNonce) { | ||
head.appendChild(styleElement); | ||
const ev = document.createEvent('HTMLEvents'); | ||
var ev = document.createEvent('HTMLEvents'); | ||
ev.initEvent('styleinsert', true /* bubbleEvent */, false /* cancelable */); | ||
@@ -285,3 +301,3 @@ ev.args = { | ||
document.dispatchEvent(ev); | ||
const record = { | ||
var record = { | ||
styleElement: styleElement, | ||
@@ -288,0 +304,0 @@ themableStyle: styleArray |
"use strict"; | ||
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. | ||
// See LICENSE in the project root for license information. | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -8,15 +19,17 @@ exports.splitStyles = exports.detokenize = exports.clearStyles = exports.loadTheme = exports.flush = exports.configureRunMode = exports.configureLoadStyles = exports.loadStyles = void 0; | ||
// load-themed-styles hosted on the page. | ||
const _root = typeof window === 'undefined' ? global : window; // eslint-disable-line @typescript-eslint/no-explicit-any | ||
var _root = typeof window === 'undefined' ? global : window; // eslint-disable-line @typescript-eslint/no-explicit-any | ||
// Nonce string to inject into script tag if one provided. This is used in CSP (Content Security Policy). | ||
const _styleNonce = _root && _root.CSPSettings && _root.CSPSettings.nonce; | ||
const _themeState = initializeThemeState(); | ||
var _styleNonce = _root && _root.CSPSettings && _root.CSPSettings.nonce; | ||
var _themeState = initializeThemeState(); | ||
/** | ||
* Matches theming tokens. For example, "[theme: themeSlotName, default: #FFF]" (including the quotes). | ||
*/ | ||
const _themeTokenRegex = /[\'\"]\[theme:\s*(\w+)\s*(?:\,\s*default:\s*([\\"\']?[\.\,\(\)\#\-\s\w]*[\.\,\(\)\#\-\w][\"\']?))?\s*\][\'\"]/g; | ||
const now = () => typeof performance !== 'undefined' && !!performance.now ? performance.now() : Date.now(); | ||
var _themeTokenRegex = /[\'\"]\[theme:\s*(\w+)\s*(?:\,\s*default:\s*([\\"\']?[\.\,\(\)\#\-\s\w]*[\.\,\(\)\#\-\w][\"\']?))?\s*\][\'\"]/g; | ||
var now = function () { | ||
return typeof performance !== 'undefined' && !!performance.now ? performance.now() : Date.now(); | ||
}; | ||
function measure(func) { | ||
const start = now(); | ||
var start = now(); | ||
func(); | ||
const end = now(); | ||
var end = now(); | ||
_themeState.perf.duration += end - start; | ||
@@ -28,3 +41,3 @@ } | ||
function initializeThemeState() { | ||
let state = _root.__themeState__ || { | ||
var state = _root.__themeState__ || { | ||
theme: undefined, | ||
@@ -35,3 +48,3 @@ lastStyleElement: undefined, | ||
if (!state.runState) { | ||
state = Object.assign(Object.assign({}, state), { perf: { | ||
state = __assign(__assign({}, state), { perf: { | ||
count: 0, | ||
@@ -46,3 +59,3 @@ duration: 0 | ||
if (!state.registeredThemableStyles) { | ||
state = Object.assign(Object.assign({}, state), { registeredThemableStyles: [] }); | ||
state = __assign(__assign({}, state), { registeredThemableStyles: [] }); | ||
} | ||
@@ -58,6 +71,7 @@ _root.__themeState__ = state; | ||
*/ | ||
function loadStyles(styles, loadAsync = false) { | ||
measure(() => { | ||
const styleParts = Array.isArray(styles) ? styles : splitStyles(styles); | ||
const { mode, buffer, flushTimer } = _themeState.runState; | ||
function loadStyles(styles, loadAsync) { | ||
if (loadAsync === void 0) { loadAsync = false; } | ||
measure(function () { | ||
var styleParts = Array.isArray(styles) ? styles : splitStyles(styles); | ||
var _a = _themeState.runState, mode = _a.mode, buffer = _a.buffer, flushTimer = _a.flushTimer; | ||
if (loadAsync || mode === 1 /* Mode.async */) { | ||
@@ -96,6 +110,6 @@ buffer.push(styleParts); | ||
function flush() { | ||
measure(() => { | ||
const styleArrays = _themeState.runState.buffer.slice(); | ||
measure(function () { | ||
var styleArrays = _themeState.runState.buffer.slice(); | ||
_themeState.runState.buffer = []; | ||
const mergedStyleArray = [].concat.apply([], styleArrays); | ||
var mergedStyleArray = [].concat.apply([], styleArrays); | ||
if (mergedStyleArray.length > 0) { | ||
@@ -113,3 +127,3 @@ applyThemableStyles(mergedStyleArray); | ||
// https://github.com/jestjs/jest/issues/14418 | ||
return self.setTimeout(() => { | ||
return self.setTimeout(function () { | ||
_themeState.runState.flushTimer = 0; | ||
@@ -149,3 +163,4 @@ flush(); | ||
*/ | ||
function clearStyles(option = 3 /* ClearStyleOptions.all */) { | ||
function clearStyles(option) { | ||
if (option === void 0) { option = 3 /* ClearStyleOptions.all */; } | ||
if (option === 3 /* ClearStyleOptions.all */ || option === 2 /* ClearStyleOptions.onlyNonThemable */) { | ||
@@ -162,4 +177,4 @@ clearStylesInternal(_themeState.registeredStyles); | ||
function clearStylesInternal(records) { | ||
records.forEach((styleRecord) => { | ||
const styleElement = styleRecord && styleRecord.styleElement; | ||
records.forEach(function (styleRecord) { | ||
var styleElement = styleRecord && styleRecord.styleElement; | ||
if (styleElement && styleElement.parentElement) { | ||
@@ -175,4 +190,5 @@ styleElement.parentElement.removeChild(styleElement); | ||
if (_themeState.theme) { | ||
const themableStyles = []; | ||
for (const styleRecord of _themeState.registeredThemableStyles) { | ||
var themableStyles = []; | ||
for (var _i = 0, _a = _themeState.registeredThemableStyles; _i < _a.length; _i++) { | ||
var styleRecord = _a[_i]; | ||
themableStyles.push(styleRecord.themableStyle); | ||
@@ -202,13 +218,13 @@ } | ||
function resolveThemableArray(splitStyleArray) { | ||
const { theme } = _themeState; | ||
let themable = false; | ||
var theme = _themeState.theme; | ||
var themable = false; | ||
// Resolve the array of theming instructions to an array of strings. | ||
// Then join the array to produce the final CSS string. | ||
const resolvedArray = (splitStyleArray || []).map((currentValue) => { | ||
const themeSlot = currentValue.theme; | ||
var resolvedArray = (splitStyleArray || []).map(function (currentValue) { | ||
var themeSlot = currentValue.theme; | ||
if (themeSlot) { | ||
themable = true; | ||
// A theming annotation. Resolve it. | ||
const themedValue = theme ? theme[themeSlot] : undefined; | ||
const defaultValue = currentValue.defaultValue || 'inherit'; | ||
var themedValue = theme ? theme[themeSlot] : undefined; | ||
var defaultValue = currentValue.defaultValue || 'inherit'; | ||
// Warn to console if we hit an unthemed value even when themes are provided, but only if "DEBUG" is true. | ||
@@ -222,3 +238,3 @@ // Allow the themedValue to be undefined to explicitly request the default value. | ||
DEBUG) { | ||
console.warn(`Theming value not provided for "${themeSlot}". Falling back to "${defaultValue}".`); | ||
console.warn("Theming value not provided for \"".concat(themeSlot, "\". Falling back to \"").concat(defaultValue, "\".")); | ||
} | ||
@@ -242,8 +258,8 @@ return themedValue || defaultValue; | ||
function splitStyles(styles) { | ||
const result = []; | ||
var result = []; | ||
if (styles) { | ||
let pos = 0; // Current position in styles. | ||
let tokenMatch; | ||
var pos = 0; // Current position in styles. | ||
var tokenMatch = void 0; | ||
while ((tokenMatch = _themeTokenRegex.exec(styles))) { | ||
const matchIndex = tokenMatch.index; | ||
var matchIndex = tokenMatch.index; | ||
if (matchIndex > pos) { | ||
@@ -279,5 +295,5 @@ result.push({ | ||
} | ||
const head = document.getElementsByTagName('head')[0]; | ||
const styleElement = document.createElement('style'); | ||
const { styleString, themable } = resolveThemableArray(styleArray); | ||
var head = document.getElementsByTagName('head')[0]; | ||
var styleElement = document.createElement('style'); | ||
var _a = resolveThemableArray(styleArray), styleString = _a.styleString, themable = _a.themable; | ||
styleElement.setAttribute('data-load-themed-styles', 'true'); | ||
@@ -290,3 +306,3 @@ if (_styleNonce) { | ||
head.appendChild(styleElement); | ||
const ev = document.createEvent('HTMLEvents'); | ||
var ev = document.createEvent('HTMLEvents'); | ||
ev.initEvent('styleinsert', true /* bubbleEvent */, false /* cancelable */); | ||
@@ -297,3 +313,3 @@ ev.args = { | ||
document.dispatchEvent(ev); | ||
const record = { | ||
var record = { | ||
styleElement: styleElement, | ||
@@ -300,0 +316,0 @@ themableStyle: styleArray |
{ | ||
"name": "@microsoft/load-themed-styles", | ||
"version": "2.0.77", | ||
"version": "2.0.78", | ||
"description": "Loads themed styles.", | ||
@@ -16,7 +16,5 @@ "license": "MIT", | ||
"devDependencies": { | ||
"@types/heft-jest": "1.0.1", | ||
"@types/webpack-env": "1.18.0", | ||
"@rushstack/eslint-config": "3.3.4", | ||
"@rushstack/heft": "0.60.0", | ||
"@rushstack/heft-web-rig": "0.18.28" | ||
"local-web-rig": "1.0.0", | ||
"@rushstack/heft": "0.61.0" | ||
}, | ||
@@ -23,0 +21,0 @@ "scripts": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
106142
3
988