Skip to content

Commit 3c004f8

Browse files
authored
Merge pull request #202 from AegisJSProject/bug/css-media
FIx creating CSS output with media queries
2 parents 76a7535 + acf6491 commit 3c004f8

10 files changed

Lines changed: 1342 additions & 2084 deletions

File tree

.github/workflows/npm-publish.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,11 @@ jobs:
2525
cache: npm
2626
registry-url: https://registry.npmjs.org
2727
- name: Install dependencies
28-
run: npm ci --ignore-scripts --no-audit --fund-no
28+
run: npm ci --no-audit --no-fund
2929
- name: Run tests
3030
run: npm test
3131
- name: Build Package
3232
run: npm run build --if-present
3333
- name: Publish to npm
3434
run: npm publish --provenance --access public
35-
env:
36-
NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
3735

.nvmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20.9.0
1+
24.10.0

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## [v0.2.8] - 2026-03-14
11+
12+
### Changed
13+
- Separate `@property` from old `--prop`s
14+
15+
### Fixed
16+
- Fix outputing `.css` for sheets with media queries
17+
1018
## [v0.2.7] - 2025-04-21
1119

1220
### Fixed

createSheets.js

Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,78 @@ globalThis.reportError ??= console.error;
44

55
const scripts = [
66
'./animations.js', './button.js', './forms.js', './misc.js', './properties.js', './reset.js',
7-
'./scrollbar.js', './styles.js', './theme.js',
7+
'./scrollbar.js', './styles.js', './theme.js', './properties-legacy.js',
88
];
99

1010
class CSSStyleSheet {
1111
#text = '';
12+
#media = null;
13+
#disabled = false;
14+
15+
constructor({ media = null, disabled = false } = {}) {
16+
this.#media = media;
17+
this.#disabled = disabled;
18+
}
19+
20+
get media() {
21+
return this.#media;
22+
}
23+
24+
get disabled() {
25+
return this.#disabled;
26+
}
27+
28+
set disabled(val) {
29+
this,this.#disabled = val;
30+
}
1231

1332
toString() {
14-
return this.#text;
33+
if (this.disabled) {
34+
return '';
35+
} else if (typeof this.#media === 'string') {
36+
return `@media (${this.#media}) {${this.#text}}`;
37+
} else {
38+
return this.#text;
39+
}
1540
}
1641

1742
replaceSync(text) {
1843
this.#text = text;
1944
}
2045

2146
async replace(text) {
22-
return Promise.resolve().then(() => this.replaceSync(text)).then(() => this);
47+
return Promise.try(() => this.replaceSync(text)).then(() => this);
2348
}
2449
}
2550

2651
globalThis.CSS = { supports: () => true };
2752
globalThis.CSSStyleSheet = CSSStyleSheet;
2853
globalThis.document = {};
29-
globalThis.MediaQueryList = class MediaQueryList extends EventTarget {};
54+
globalThis.matchMedia = media => {
55+
const mql = new MediaQueryList();
56+
mql.media = media;
57+
return mql;
58+
};
59+
60+
globalThis.MediaQueryList = class MediaQueryList extends EventTarget {
61+
#media = null;
62+
63+
get matches() {
64+
return true;
65+
}
66+
67+
get media() {
68+
return this.#media;
69+
}
70+
71+
set media(val) {
72+
this.#media = val;
73+
}
74+
75+
toString() {
76+
return this.#media;
77+
}
78+
};
3079

3180
async function saveSheet(path) {
3281
const module = await import(path);

0 commit comments

Comments
 (0)