@peachy/plugin-css 0.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +31 -0
- package/dist/index.d.mts +11 -0
- package/dist/index.mjs +56 -0
- package/dist/modules.d.mts +5 -0
- package/package.json +37 -0
package/README.md
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# @peachy/plugin-css
|
|
2
|
+
|
|
3
|
+
A Rolldown plugin that allows you to import CSS modules.
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
First, create your CSS module:
|
|
8
|
+
|
|
9
|
+
```css
|
|
10
|
+
/* styles.css */
|
|
11
|
+
.heroImage {
|
|
12
|
+
border-radius: 12px;
|
|
13
|
+
border: 1px solid;
|
|
14
|
+
}
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Then you can import it in your code and use it:
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
/* app.ts */
|
|
21
|
+
|
|
22
|
+
import Gtk from "gi://Gtk?version=4.0";
|
|
23
|
+
|
|
24
|
+
import styles from "./styles.css";
|
|
25
|
+
|
|
26
|
+
const picture = new Gtk.Picture({
|
|
27
|
+
cssClasses: [styles.heroImage],
|
|
28
|
+
});
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Your image will now have a border and rounded corners.
|
package/dist/index.d.mts
ADDED
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { basename } from "node:path";
|
|
2
|
+
import { transform } from "lightningcss";
|
|
3
|
+
|
|
4
|
+
//#region src/index.ts
|
|
5
|
+
function cssPlugin({ prod }) {
|
|
6
|
+
return {
|
|
7
|
+
name: "@peachy/plugin-css#modules",
|
|
8
|
+
load: {
|
|
9
|
+
filter: { id: /\.module\.css$/ },
|
|
10
|
+
async handler(id) {
|
|
11
|
+
const { code, map, exports = {} } = transform({
|
|
12
|
+
code: await this.fs.readFile(id),
|
|
13
|
+
minify: prod,
|
|
14
|
+
cssModules: true,
|
|
15
|
+
filename: id,
|
|
16
|
+
sourceMap: true
|
|
17
|
+
});
|
|
18
|
+
const originalBasename = basename(id);
|
|
19
|
+
const sourceMapName = originalBasename.replace(/\.module\.css$/, ".css.map");
|
|
20
|
+
const cssId = this.emitFile({
|
|
21
|
+
type: "asset",
|
|
22
|
+
fileName: originalBasename.replace(/\.module\.css$/, ".css"),
|
|
23
|
+
source: code + `\n\n/*# sourceMappingURL=${sourceMapName} */`
|
|
24
|
+
});
|
|
25
|
+
if (map) this.emitFile({
|
|
26
|
+
type: "asset",
|
|
27
|
+
fileName: sourceMapName,
|
|
28
|
+
source: map
|
|
29
|
+
});
|
|
30
|
+
const classNameMappings = Object.fromEntries(Object.entries(exports).map(([key, value]) => [key, value.name]));
|
|
31
|
+
return {
|
|
32
|
+
code: [
|
|
33
|
+
`import GLib from "gi://GLib?version=2.0";`,
|
|
34
|
+
`import Gtk from "gi://Gtk?version=4.0";`,
|
|
35
|
+
`import Gdk from "gi://Gdk?version=4.0";`,
|
|
36
|
+
`Gtk.init();`,
|
|
37
|
+
`const provider = new Gtk.CssProvider();`,
|
|
38
|
+
`provider.load_from_path(import.meta.ROLLUP_FILE_URL_${cssId})`,
|
|
39
|
+
`Gtk.StyleContext.add_provider_for_display(Gdk.Display.get_default(), provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);`,
|
|
40
|
+
`export default ${JSON.stringify(classNameMappings)};`
|
|
41
|
+
].join("\n"),
|
|
42
|
+
moduleType: "js"
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
renderChunk(code) {
|
|
47
|
+
return {
|
|
48
|
+
code: code.replace(/new\s+URL\(\s*['"]([^'"]+)['"]\s*,\s*import\.meta\.url\s*\)\.href/g, (_, path) => `GLib.build_filenamev([GLib.path_get_dirname(import.meta.url.slice(7)), '${path}'])`),
|
|
49
|
+
map: null
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
//#endregion
|
|
56
|
+
export { cssPlugin };
|
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@peachy/plugin-css",
|
|
3
|
+
"version": "0.0.11",
|
|
4
|
+
"description": "Import CSS files into your GJS applications",
|
|
5
|
+
"keywords": [],
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"author": "Angelo Verlain <hey@vixalien.com>",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist"
|
|
10
|
+
],
|
|
11
|
+
"type": "module",
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"import": "./dist/index.mjs",
|
|
15
|
+
"types": "./dist/index.d.mts"
|
|
16
|
+
},
|
|
17
|
+
"./modules": {
|
|
18
|
+
"types": "./dist/modules.d.mts"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"lightningcss": "^1.31.1"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@types/node": "^25.2.2",
|
|
26
|
+
"rolldown": "1.0.0-rc.3",
|
|
27
|
+
"tsdown": "0.20.3",
|
|
28
|
+
"typescript": "^5.9.3",
|
|
29
|
+
"@peachy/internal-utilities": "0.0.0"
|
|
30
|
+
},
|
|
31
|
+
"peerDependencies": {
|
|
32
|
+
"rolldown": "1.0.0-beta.58"
|
|
33
|
+
},
|
|
34
|
+
"scripts": {
|
|
35
|
+
"build": "tsdown src/index.ts src/modules.d.ts --dts"
|
|
36
|
+
}
|
|
37
|
+
}
|