-
Notifications
You must be signed in to change notification settings - Fork 59
/
__styles.ts
55 lines (45 loc) · 1.84 KB
/
__styles.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import { debugData, isDevToolsEnabled, getSourceURLfromError } from './devtools';
import { insertionFactory } from './insertionFactory';
import { reduceToClassNameForSlots } from './runtime/reduceToClassNameForSlots';
import type { CSSClassesMapBySlot, CSSRulesByBucket, GriffelInsertionFactory } from './types';
import type { MakeStylesOptions } from './makeStyles';
/**
* A version of makeStyles() that accepts build output as an input and skips all runtime transforms.
*
* @internal
*/
export function __styles<Slots extends string>(
classesMapBySlot: CSSClassesMapBySlot<Slots>,
cssRules: CSSRulesByBucket,
factory: GriffelInsertionFactory = insertionFactory,
) {
const insertStyles = factory();
let ltrClassNamesForSlots: Record<Slots, string> | null = null;
let rtlClassNamesForSlots: Record<Slots, string> | null = null;
let sourceURL: string | undefined;
if (process.env.NODE_ENV !== 'production' && isDevToolsEnabled) {
sourceURL = getSourceURLfromError();
}
function computeClasses(options: Pick<MakeStylesOptions, 'dir' | 'renderer'>): Record<Slots, string> {
const { dir, renderer } = options;
const isLTR = dir === 'ltr';
if (isLTR) {
if (ltrClassNamesForSlots === null) {
ltrClassNamesForSlots = reduceToClassNameForSlots(classesMapBySlot, dir);
}
} else {
if (rtlClassNamesForSlots === null) {
rtlClassNamesForSlots = reduceToClassNameForSlots(classesMapBySlot, dir);
}
}
insertStyles(renderer, dir, cssRules);
const classNamesForSlots = isLTR
? (ltrClassNamesForSlots as Record<Slots, string>)
: (rtlClassNamesForSlots as Record<Slots, string>);
if (process.env.NODE_ENV !== 'production' && isDevToolsEnabled) {
debugData.addSequenceDetails(classNamesForSlots!, sourceURL);
}
return classNamesForSlots;
}
return computeClasses;
}