-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'chore/fela-enhancer' of https://github.com/microsoft/fl…
…uentui into chore/try-mix-cache-n-stylis � Conflicts: � packages/fluentui/react-northstar/src/utils/felaRenderer.tsx
- Loading branch information
Showing
15 changed files
with
152 additions
and
90 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
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
31 changes: 31 additions & 0 deletions
31
packages/fluentui/react-northstar/src/utils/felaStylisEnhancer.ts
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,31 @@ | ||
import { RULE_TYPE } from 'fela-utils'; | ||
// @ts-ignore | ||
import Stylis from 'stylis'; | ||
|
||
import { Renderer, RendererChange } from './types'; | ||
|
||
// We use Stylis only for vendor prefixing, all other capabilities are disabled | ||
const stylis = new Stylis({ | ||
cascade: false, | ||
compress: false, | ||
global: false, | ||
keyframe: false, | ||
preserve: false, | ||
semicolon: false, | ||
}); | ||
|
||
const felaStylisEnhancer = (renderer: Renderer) => ({ | ||
...renderer, | ||
_emitChange: (change: RendererChange) => { | ||
if (change.type === RULE_TYPE) { | ||
const prefixed: string = stylis('', change.declaration); | ||
|
||
// Fela uses objects by references, it's safe to override properties | ||
change.declaration = prefixed.slice(1, -1); | ||
} | ||
|
||
renderer._emitChange(change); | ||
}, | ||
}); | ||
|
||
export default felaStylisEnhancer; |
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,16 @@ | ||
import { IRenderer } from 'fela'; | ||
|
||
export type Renderer = IRenderer & { | ||
cache: Record<string, RendererChange>; | ||
_emitChange?: (change: RendererChange) => void; | ||
}; | ||
|
||
export type RendererChange = { | ||
type: 'RULE' | 'KEYFRAME' | 'FONT' | 'STATIC' | 'CLEAR'; | ||
className: string; | ||
selector: string; | ||
declaration: Object; | ||
pseudo: string; | ||
media: string; | ||
support: string; | ||
}; |
Oops, something went wrong.