-
Notifications
You must be signed in to change notification settings - Fork 272
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: remove placeholder span from shadow root (#503)
- Loading branch information
1 parent
5709e31
commit 4003029
Showing
71 changed files
with
353 additions
and
361 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,56 @@ | ||
import { getTheme } from "./Configuration.js"; | ||
import { getEffectiveStyle } from "./Theming.js"; | ||
import { injectWebComponentStyle } from "./theming/StyleInjection.js"; | ||
|
||
const styleMap = new Map(); | ||
|
||
const createStyleElement = css => { | ||
// Create a local <style> tag for the real shadow DOM | ||
const style = document.createElement("style"); | ||
style.innerHTML = css; | ||
return style; | ||
}; | ||
|
||
const createConstructableStyleSheet = css => { | ||
const elementStyleSheet = new CSSStyleSheet(); | ||
elementStyleSheet.replaceSync(css); | ||
return elementStyleSheet; | ||
/** | ||
* Creates the needed CSS for a web component class in the head tag | ||
* Note: IE11, Edge | ||
* @param ElementClass | ||
*/ | ||
const createHeadStyle = ElementClass => { | ||
const tag = ElementClass.getMetadata().getTag(); | ||
const cssContent = getEffectiveStyle(ElementClass); | ||
injectWebComponentStyle(tag, cssContent); | ||
}; | ||
|
||
const _createStyle = (tagName, styleContent) => { | ||
/** | ||
* Returns (and caches) a constructable style sheet for a web component class | ||
* Note: Chrome | ||
* @param ElementClass | ||
* @returns {*} | ||
*/ | ||
const getConstructableStyle = ElementClass => { | ||
const tagName = ElementClass.getMetadata().getTag(); | ||
const styleContent = getEffectiveStyle(ElementClass); | ||
const theme = getTheme(); | ||
const key = theme + tagName; | ||
if (styleMap.has(key)) { | ||
return styleMap.get(key); | ||
} | ||
|
||
let style; | ||
if (document.adoptedStyleSheets) { | ||
style = createConstructableStyleSheet(styleContent); | ||
} else { | ||
style = createStyleElement(styleContent); | ||
} | ||
const style = new CSSStyleSheet(); | ||
style.replaceSync(styleContent); | ||
|
||
styleMap.set(key, style); | ||
return style; | ||
}; | ||
|
||
const createStyle = ElementClass => { | ||
const tagName = ElementClass.getMetadata().getTag(); | ||
/** | ||
* Returns the CSS to be injected inside a web component shadow root, or undefined if not needed | ||
* Note: FF, Safari | ||
* @param ElementClass | ||
* @returns {string} | ||
*/ | ||
const getShadowRootStyle = ElementClass => { | ||
if (document.adoptedStyleSheets || window.ShadyDOM) { | ||
return; | ||
} | ||
|
||
const styleContent = getEffectiveStyle(ElementClass); | ||
return _createStyle(tagName, styleContent); | ||
return styleContent; | ||
}; | ||
|
||
// eslint-disable-next-line | ||
export { createStyle }; | ||
export { createHeadStyle, getConstructableStyle, getShadowRootStyle}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.