MCPcopy
hub / github.com/styletron/styletron / StyletronServer

Class StyletronServer

packages/styletron-engine-atomic/src/server/server.ts:39–138  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

37};
38
39class StyletronServer implements StandardEngine {
40 styleCache: MultiCache<{
41 pseudo: string;
42 block: string;
43 }>;
44 keyframesCache: Cache<KeyframesObject>;
45 fontFaceCache: Cache<FontFaceObject>;
46 styleRules: {
47 [x: string]: string;
48 };
49 keyframesRules: string;
50 fontFaceRules: string;
51
52 constructor(opts: optionsT = {}) {
53 this.styleRules = {"": ""};
54 this.styleCache = new MultiCache(
55 new SequentialIDGenerator(opts.prefix),
56 media => {
57 this.styleRules[media] = "";
58 },
59 (cache, id, value) => {
60 const {pseudo, block} = value;
61 this.styleRules[cache.key] += styleBlockToRule(
62 atomicSelector(id, pseudo),
63 block,
64 );
65 },
66 );
67
68 this.fontFaceRules = "";
69 this.fontFaceCache = new Cache(
70 new SequentialIDGenerator(opts.prefix),
71 (cache, id, value) => {
72 this.fontFaceRules += fontFaceBlockToRule(
73 id,
74 declarationsToBlock(value),
75 );
76 },
77 );
78
79 this.keyframesRules = "";
80 this.keyframesCache = new Cache(
81 new SequentialIDGenerator(opts.prefix),
82 (cache, id, value) => {
83 this.keyframesRules += keyframesBlockToRule(
84 id,
85 keyframesToBlock(value),
86 );
87 },
88 );
89 }
90
91 renderStyle(style: StyleObject): string {
92 return injectStylePrefixed(this.styleCache, style, "", "");
93 }
94
95 renderFontFace(fontFace: FontFaceObject): string {
96 const key = JSON.stringify(fontFace);

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected