@gtkx/css 0.1.22 → 0.1.24
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 +1 -1
- package/dist/gtk-style-sheet.d.ts +23 -0
- package/dist/gtk-style-sheet.js +70 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
type StyleSheetOptions = {
|
|
2
|
+
key: string;
|
|
3
|
+
container?: unknown;
|
|
4
|
+
nonce?: string;
|
|
5
|
+
speedy?: boolean;
|
|
6
|
+
prepend?: boolean;
|
|
7
|
+
};
|
|
8
|
+
export declare class GtkStyleSheet {
|
|
9
|
+
key: string;
|
|
10
|
+
private rules;
|
|
11
|
+
private provider;
|
|
12
|
+
private display;
|
|
13
|
+
private isRegistered;
|
|
14
|
+
private hasPendingRules;
|
|
15
|
+
constructor(options: StyleSheetOptions);
|
|
16
|
+
private ensureProvider;
|
|
17
|
+
private updateProvider;
|
|
18
|
+
insert(rule: string): void;
|
|
19
|
+
applyQueuedRules(): void;
|
|
20
|
+
flush(): void;
|
|
21
|
+
hydrate(_elements: unknown[]): void;
|
|
22
|
+
}
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { events } from "@gtkx/ffi";
|
|
2
|
+
import { DisplayManager } from "@gtkx/ffi/gdk";
|
|
3
|
+
import { CssProvider, StyleContext } from "@gtkx/ffi/gtk";
|
|
4
|
+
const STYLE_PROVIDER_PRIORITY_APPLICATION = 600;
|
|
5
|
+
let isGtkReady = false;
|
|
6
|
+
const pendingSheets = [];
|
|
7
|
+
const flushPendingStyles = () => {
|
|
8
|
+
isGtkReady = true;
|
|
9
|
+
for (const sheet of pendingSheets) {
|
|
10
|
+
sheet.applyQueuedRules();
|
|
11
|
+
}
|
|
12
|
+
pendingSheets.length = 0;
|
|
13
|
+
};
|
|
14
|
+
events.once("start", flushPendingStyles);
|
|
15
|
+
export class GtkStyleSheet {
|
|
16
|
+
key;
|
|
17
|
+
rules = [];
|
|
18
|
+
provider = null;
|
|
19
|
+
display = null;
|
|
20
|
+
isRegistered = false;
|
|
21
|
+
hasPendingRules = false;
|
|
22
|
+
constructor(options) {
|
|
23
|
+
this.key = options.key;
|
|
24
|
+
}
|
|
25
|
+
ensureProvider() {
|
|
26
|
+
if (!this.provider) {
|
|
27
|
+
this.provider = new CssProvider();
|
|
28
|
+
this.display = DisplayManager.get().getDefaultDisplay();
|
|
29
|
+
if (this.display) {
|
|
30
|
+
StyleContext.addProviderForDisplay(this.display, this.provider, STYLE_PROVIDER_PRIORITY_APPLICATION);
|
|
31
|
+
this.isRegistered = true;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
updateProvider() {
|
|
36
|
+
if (this.provider && this.rules.length > 0) {
|
|
37
|
+
const css = this.rules.join("\n");
|
|
38
|
+
this.provider.loadFromString(css);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
insert(rule) {
|
|
42
|
+
this.rules.push(rule);
|
|
43
|
+
if (isGtkReady) {
|
|
44
|
+
this.ensureProvider();
|
|
45
|
+
this.updateProvider();
|
|
46
|
+
}
|
|
47
|
+
else if (!this.hasPendingRules) {
|
|
48
|
+
this.hasPendingRules = true;
|
|
49
|
+
pendingSheets.push(this);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
applyQueuedRules() {
|
|
53
|
+
if (this.rules.length > 0) {
|
|
54
|
+
this.ensureProvider();
|
|
55
|
+
this.updateProvider();
|
|
56
|
+
}
|
|
57
|
+
this.hasPendingRules = false;
|
|
58
|
+
}
|
|
59
|
+
flush() {
|
|
60
|
+
if (this.provider && this.display && this.isRegistered) {
|
|
61
|
+
StyleContext.removeProviderForDisplay(this.display, this.provider);
|
|
62
|
+
this.isRegistered = false;
|
|
63
|
+
}
|
|
64
|
+
this.rules = [];
|
|
65
|
+
this.provider = null;
|
|
66
|
+
this.display = null;
|
|
67
|
+
this.hasPendingRules = false;
|
|
68
|
+
}
|
|
69
|
+
hydrate(_elements) { }
|
|
70
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gtkx/css",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.24",
|
|
4
4
|
"description": "Emotion-style CSS-in-JS for GTKX applications",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"gtk",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"@emotion/cache": "11.14.0",
|
|
38
38
|
"@emotion/serialize": "1.3.3",
|
|
39
|
-
"@gtkx/ffi": "0.1.
|
|
39
|
+
"@gtkx/ffi": "0.1.24"
|
|
40
40
|
},
|
|
41
41
|
"scripts": {
|
|
42
42
|
"build": "tsc -b && cp ../../README.md .",
|