| 37 | }; |
| 38 | |
| 39 | class 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); |
nothing calls this directly
no outgoing calls
no test coverage detected