MCPcopy
hub / github.com/typestyle/typestyle / TypeStyle

Class TypeStyle

src/internal/typestyle.ts:17–222  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

15 * Maintains a single stylesheet and keeps it in sync with requested styles
16 */
17export class TypeStyle {
18 private _autoGenerateTag: boolean;
19 private _freeStyle: FreeStyle.FreeStyle;
20 private _pending: number;
21 private _pendingRawChange: boolean;
22 private _raw: string;
23 private _tag?: StylesTarget;
24
25 /**
26 * We have a single stylesheet that we update as components register themselves
27 */
28 private _lastFreeStyleChangeId: number;
29
30 constructor({ autoGenerateTag }: { autoGenerateTag: boolean }) {
31 const freeStyle = createFreeStyle();
32
33 this._autoGenerateTag = autoGenerateTag;
34 this._freeStyle = freeStyle;
35 this._lastFreeStyleChangeId = freeStyle.changeId;
36 this._pending = 0;
37 this._pendingRawChange = false;
38 this._raw = '';
39 this._tag = undefined;
40
41 // rebind prototype to TypeStyle. It might be better to do a function() { return this.style.apply(this, arguments)}
42 this.style = this.style.bind(this);
43 }
44
45 /**
46 * Only calls cb all sync operations settle
47 */
48 private _afterAllSync(cb: () => void): void {
49 this._pending++;
50 const pending = this._pending;
51 raf(() => {
52 if (pending !== this._pending) {
53 return;
54 }
55 cb();
56 });
57 }
58
59 private _getTag(): StylesTarget | undefined {
60 if (this._tag) {
61 return this._tag;
62 }
63
64 if (this._autoGenerateTag) {
65 const tag = typeof window === 'undefined'
66 ? { textContent: '' }
67 : document.createElement('style');
68
69 if (typeof document !== 'undefined') {
70 document.head.appendChild(tag as any);
71 }
72 this._tag = tag;
73 return tag;
74 }

Callers

nothing calls this directly

Calls 7

_styleUpdatedMethod · 0.95
_getTagMethod · 0.95
styleMethod · 0.95
convertToStylesFunction · 0.90
extendFunction · 0.90
convertToKeyframesFunction · 0.90
createFreeStyleFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…