generated from shgysk8zer0/npm-template
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreateSheets.js
More file actions
92 lines (73 loc) · 1.74 KB
/
createSheets.js
File metadata and controls
92 lines (73 loc) · 1.74 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import { writeFile } from 'node:fs/promises';
globalThis.reportError ??= console.error;
const scripts = [
'./animations.js', './button.js', './forms.js', './misc.js', './properties.js', './reset.js',
'./scrollbar.js', './styles.js', './theme.js', './properties-legacy.js',
];
class CSSStyleSheet {
#text = '';
#media = null;
#disabled = false;
constructor({ media = null, disabled = false } = {}) {
this.#media = media;
this.#disabled = disabled;
}
get media() {
return this.#media;
}
get disabled() {
return this.#disabled;
}
set disabled(val) {
this,this.#disabled = val;
}
toString() {
if (this.disabled) {
return '';
} else if (typeof this.#media === 'string') {
return `@media (${this.#media}) {${this.#text}}`;
} else {
return this.#text;
}
}
replaceSync(text) {
this.#text = text;
}
async replace(text) {
return Promise.try(() => this.replaceSync(text)).then(() => this);
}
}
globalThis.CSS = { supports: () => true };
globalThis.CSSStyleSheet = CSSStyleSheet;
globalThis.document = {};
globalThis.matchMedia = media => {
const mql = new MediaQueryList();
mql.media = media;
return mql;
};
globalThis.MediaQueryList = class MediaQueryList extends EventTarget {
#media = null;
get matches() {
return true;
}
get media() {
return this.#media;
}
set media(val) {
this.#media = val;
}
toString() {
return this.#media;
}
};
async function saveSheet(path) {
const module = await import(path);
const sheets = Object.values(module).filter(exp => exp instanceof CSSStyleSheet);
if (sheets.length !== 0) {
await writeFile(path.replace('./', './css/').replace('.js', '.css'), sheets.join('\n\n'));
return true;
} else {
return false;
}
}
await Promise.all(scripts.map(saveSheet));