MCPcopy
hub / github.com/microsoft/rushstack / registerStylesIE

Function registerStylesIE

src/index.ts:248–282  ·  view source on GitHub ↗

* Registers a set of style text, for IE 9 and below, which has a ~30 style element limit so we need * to register slightly differently. * @param {ThemableArray} styleArray Array of IThemingInstruction objects to register. * @param {IStyleRecord} styleRecord May specify a style Element to update.

(styleArray: ThemableArray, styleRecord?: IStyleRecord)

Source from the content-addressed store, hash-verified

246 * @param {IStyleRecord} styleRecord May specify a style Element to update.
247 */
248function registerStylesIE(styleArray: ThemableArray, styleRecord?: IStyleRecord): void {
249 const head: HTMLHeadElement = document.getElementsByTagName('head')[0];
250 let { lastStyleElement, registeredStyles }: IThemeState = _themeState;
251
252 const stylesheet: IStyleSheet = lastStyleElement ? lastStyleElement.styleSheet : undefined;
253 const lastStyleContent: string = stylesheet ? stylesheet.cssText : '';
254 let lastRegisteredStyle: IStyleRecord = registeredStyles[registeredStyles.length - 1];
255 const resolvedStyleText: string = resolveThemableArray(styleArray);
256
257 if (!lastStyleElement || (lastStyleContent.length + resolvedStyleText.length) > MAX_STYLE_CONTENT_SIZE) {
258 lastStyleElement = document.createElement('style') as IExtendedHtmlStyleElement;
259 lastStyleElement.type = 'text/css';
260
261 if (styleRecord) {
262 head.replaceChild(lastStyleElement, styleRecord.styleElement);
263 styleRecord.styleElement = lastStyleElement;
264 } else {
265 head.appendChild(lastStyleElement);
266 }
267
268 if (!styleRecord) {
269 lastRegisteredStyle = {
270 styleElement: lastStyleElement,
271 themableStyle: styleArray
272 };
273 registeredStyles.push(lastRegisteredStyle);
274 }
275 }
276
277 lastStyleElement.styleSheet.cssText += detokenize(resolvedStyleText);
278 Array.prototype.push.apply(lastRegisteredStyle.themableStyle, styleArray); // concat in-place
279
280 // Preserve the theme state.
281 _themeState.lastStyleElement = lastStyleElement;
282}
283
284/**
285 * Checks to see if styleSheet exists as a property off of a style element.

Callers 1

applyThemableStylesFunction · 0.85

Calls 2

resolveThemableArrayFunction · 0.85
detokenizeFunction · 0.85

Tested by

no test coverage detected