@geektech/tsone 0.2.1 → 0.3.0

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.
@@ -1,91 +0,0 @@
1
- // lib/style/StyleManager.ts
2
- class StyleManager {
3
- styleElement;
4
- styles = new Map;
5
- constructor() {
6
- this.styleElement = document.createElement("style");
7
- document.head.appendChild(this.styleElement);
8
- }
9
- addStyle(name, options) {
10
- this.styles.set(name, options);
11
- this.updateStyles();
12
- }
13
- removeStyle(name) {
14
- this.styles.delete(name);
15
- this.updateStyles();
16
- }
17
- clearStyles() {
18
- this.styles.clear();
19
- this.styleElement.textContent = "";
20
- }
21
- destroy() {
22
- this.clearStyles();
23
- this.styleElement.remove();
24
- }
25
- convertToCSS(properties) {
26
- return Object.entries(properties).map(([key, value]) => {
27
- const cssKey = key.replace(/([A-Z])/g, "-$1").toLowerCase();
28
- return `${cssKey}: ${value};`;
29
- }).join(`
30
- `);
31
- }
32
- updateStyles() {
33
- let cssText = "";
34
- this.styles.forEach((style) => {
35
- cssText += `${style.selector} {
36
- ${this.convertToCSS(style.properties)}
37
- }
38
- `;
39
- if (style.hover) {
40
- cssText += `${style.selector}:hover {
41
- ${this.convertToCSS(style.hover)}
42
- }
43
- `;
44
- }
45
- if (style.media) {
46
- Object.entries(style.media).forEach(([query, properties]) => {
47
- cssText += `@media ${query} {
48
- ${style.selector} {
49
- ${this.convertToCSS(properties)}
50
- }
51
- }
52
- `;
53
- });
54
- }
55
- });
56
- this.styleElement.textContent = cssText;
57
- }
58
- }
59
-
60
- // lib/style/sheet.ts
61
- function renderStyleSheet(styles) {
62
- return styles.map((entry) => renderStyleEntry(entry)).join(`
63
-
64
- `);
65
- }
66
- function renderStyleEntry(entry, indent = "") {
67
- if ("atRule" in entry) {
68
- const rules = entry.rules.map((rule) => renderStyleEntry(rule, `${indent} `)).join(`
69
-
70
- `);
71
- return `${indent}${entry.atRule} {
72
- ${rules}
73
- ${indent}}`;
74
- }
75
- const declarations = Object.entries(entry.properties).map(([property, value]) => `${indent} ${toCssProperty(property)}: ${String(value)};`).join(`
76
- `);
77
- return `${indent}${entry.selector} {
78
- ${declarations}
79
- ${indent}}`;
80
- }
81
- function toCssProperty(property) {
82
- if (property.startsWith("--") || property.includes("-")) {
83
- return property;
84
- }
85
- return property.replace(/[A-Z]/g, (match) => `-${match.toLowerCase()}`);
86
- }
87
-
88
- export { StyleManager, renderStyleSheet };
89
-
90
- //# debugId=4D9052062F0EFA4C64756E2164756E21
91
- //# sourceMappingURL=index-ffzday7h.js.map