MCPcopy
hub / github.com/cssinjs/jss / SheetsRegistry

Class SheetsRegistry

packages/jss/src/SheetsRegistry.js:5–69  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3 * Sheets registry to access all instances in one place.
4 */
5export default class SheetsRegistry {
6 registry = []
7
8 /**
9 * Current highest index number.
10 */
11 get index() {
12 return this.registry.length === 0 ? 0 : this.registry[this.registry.length - 1].options.index
13 }
14
15 /**
16 * Register a Style Sheet.
17 */
18 add(sheet) {
19 const {registry} = this
20 const {index} = sheet.options
21
22 if (registry.indexOf(sheet) !== -1) return
23
24 if (registry.length === 0 || index >= this.index) {
25 registry.push(sheet)
26 return
27 }
28
29 // Find a position.
30 for (let i = 0; i < registry.length; i++) {
31 if (registry[i].options.index > index) {
32 registry.splice(i, 0, sheet)
33 return
34 }
35 }
36 }
37
38 /**
39 * Reset the registry.
40 */
41 reset() {
42 this.registry = []
43 }
44
45 /**
46 * Remove a Style Sheet.
47 */
48 remove(sheet) {
49 const index = this.registry.indexOf(sheet)
50 this.registry.splice(index, 1)
51 }
52
53 /**
54 * Convert all attached sheets to a CSS string.
55 */
56 toString({attached, ...options} = {}) {
57 const {linebreak} = getWhitespaceSymbols(options)
58 let css = ''
59 for (let i = 0; i < this.registry.length; i++) {
60 const sheet = this.registry[i]
61 if (attached != null && sheet.attached !== attached) {
62 continue

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…