-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds
inlineStyle()
and inline style map.
Refs #41. The new `inlineStyle()` function looks equivalent to `inlineStyleLegacy()` from the user's perspective, however the key differences are: 1. `inlineStyle()` is synchronous and returns an annotation telling the build pipeline to inline the style here. `inlineStyleLegacy()` asynchronously read the CSS file and returned the actual `<style />` tag. This change makes the function easier to use (no viral `async`) and gives the build system an opportunity to bundle the inlined CSS file which wasn't available before. 2. `inlineStyle()` looks up the given import path in the "inline style map" and uses the result as the path in the output annotation. This map serves to correlate the import path users pass into `inlineStyle()` with the actual on disk location of the CSS file. These may not align as the latter could contain an artifact root, have a different file name, or even be in a different package altogether. The renderer receives this map in its arguments and `inlineStyle()` looks up this map so generated annotations use the real file path of inline styles, while users pass in the import path.
- Loading branch information
Showing
7 changed files
with
217 additions
and
6 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/** | ||
* @fileoverview A global map of inline style imports to their file locations. Inlined | ||
* styles may live at a different file location than is visible to the user, so import | ||
* paths may not align to the actual file location. This serves as a map of "user | ||
* import path" -> "actual file location the CSS file lives". | ||
*/ | ||
|
||
let map: ReadonlyMap<string, string> | undefined; | ||
|
||
/** Returns the inline style map. */ | ||
export function getMap(): ReadonlyMap<string, string> { | ||
if (!map) throw new Error('Inline style map not set.'); | ||
return map; | ||
} | ||
|
||
/** Sets the inline style map. */ | ||
export function setMap(newMap: ReadonlyMap<string, string>): void { | ||
if (map) throw new Error('Inline style map already set, cannot set it again.'); | ||
map = newMap; | ||
} |
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