antigravity-rtl-patcher 3.0.3 → 3.0.6
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/package.json
CHANGED
|
Binary file
|
package/payload/utils-inject.js
CHANGED
|
@@ -38,32 +38,104 @@ win.webContents.on('dom-ready', () => {
|
|
|
38
38
|
let rtlEnabled = ${rtlConfig.enabled};
|
|
39
39
|
let panelVisible = false;
|
|
40
40
|
|
|
41
|
+
// RTL Detection Function
|
|
42
|
+
function isRTLText(text) {
|
|
43
|
+
if (!text || typeof text !== 'string') return false;
|
|
44
|
+
const rtlChars = /[\u0600-\u06FF\u0750-\u077F\u08A0-\u08FF\uFB50-\uFDFF\uFE70-\uFEFF]/;
|
|
45
|
+
const cleanText = text.trim();
|
|
46
|
+
if (cleanText.length === 0) return false;
|
|
47
|
+
|
|
48
|
+
// Check first non-whitespace character
|
|
49
|
+
for (let char of cleanText) {
|
|
50
|
+
if (char.trim()) {
|
|
51
|
+
return rtlChars.test(char);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Apply RTL to text elements dynamically
|
|
58
|
+
function applyRTLToContent() {
|
|
59
|
+
if (!rtlEnabled) return;
|
|
60
|
+
|
|
61
|
+
// Target message containers and paragraphs
|
|
62
|
+
const textElements = document.querySelectorAll('p, h1, h2, h3, h4, h5, h6, li, blockquote, td, th');
|
|
63
|
+
|
|
64
|
+
textElements.forEach(el => {
|
|
65
|
+
// Skip if already processed or is UI element
|
|
66
|
+
if (el.classList.contains('rtl-ui') || el.classList.contains('rtl-processed')) return;
|
|
67
|
+
|
|
68
|
+
// Skip code blocks
|
|
69
|
+
if (el.closest('pre, code')) return;
|
|
70
|
+
|
|
71
|
+
const text = el.textContent;
|
|
72
|
+
if (isRTLText(text)) {
|
|
73
|
+
el.setAttribute('dir', 'rtl');
|
|
74
|
+
el.classList.add('rtl-processed');
|
|
75
|
+
} else if (el.hasAttribute('dir') && el.getAttribute('dir') === 'rtl') {
|
|
76
|
+
el.removeAttribute('dir');
|
|
77
|
+
el.classList.remove('rtl-processed');
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// Observe DOM changes
|
|
83
|
+
const observer = new MutationObserver((mutations) => {
|
|
84
|
+
if (rtlEnabled) {
|
|
85
|
+
applyRTLToContent();
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
// Start observing after a short delay
|
|
90
|
+
setTimeout(() => {
|
|
91
|
+
observer.observe(document.body, {
|
|
92
|
+
childList: true,
|
|
93
|
+
subtree: true,
|
|
94
|
+
characterData: true
|
|
95
|
+
});
|
|
96
|
+
applyRTLToContent();
|
|
97
|
+
}, 500);
|
|
98
|
+
|
|
41
99
|
const CSS = \`
|
|
42
|
-
/*
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
body.rtl-active
|
|
47
|
-
|
|
48
|
-
|
|
100
|
+
/* Vazirmatn Font from CDN */
|
|
101
|
+
@import url('https://cdn.jsdelivr.net/gh/rastikerdar/vazirmatn@v33.003/Vazirmatn-font-face.css');
|
|
102
|
+
|
|
103
|
+
/* Apply Vazirmatn to all text when RTL is active */
|
|
104
|
+
body.rtl-active {
|
|
105
|
+
font-family: 'Vazirmatn', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif !important;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/* RTL Styles - Only for message content */
|
|
109
|
+
body.rtl-active [dir="rtl"] {
|
|
49
110
|
direction: rtl !important;
|
|
50
111
|
text-align: right !important;
|
|
112
|
+
unicode-bidi: isolate !important;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/* Keep paragraphs and headings with proper bidi */
|
|
116
|
+
body.rtl-active p,
|
|
117
|
+
body.rtl-active h1, body.rtl-active h2, body.rtl-active h3,
|
|
118
|
+
body.rtl-active h4, body.rtl-active h5, body.rtl-active h6 {
|
|
51
119
|
unicode-bidi: plaintext !important;
|
|
120
|
+
text-align: start !important;
|
|
52
121
|
}
|
|
53
122
|
|
|
54
|
-
|
|
123
|
+
/* Lists in RTL context */
|
|
124
|
+
body.rtl-active [dir="rtl"] ul,
|
|
55
125
|
body.rtl-active [dir="rtl"] ol {
|
|
56
126
|
padding-left: 0 !important;
|
|
57
|
-
padding-right:
|
|
127
|
+
padding-right: 2rem !important;
|
|
58
128
|
}
|
|
59
129
|
|
|
60
|
-
|
|
61
|
-
body.rtl-active
|
|
62
|
-
body.rtl-active
|
|
130
|
+
/* Code blocks always LTR */
|
|
131
|
+
body.rtl-active pre,
|
|
132
|
+
body.rtl-active code,
|
|
133
|
+
body.rtl-active pre *,
|
|
63
134
|
body.rtl-active code * {
|
|
64
135
|
direction: ltr !important;
|
|
65
136
|
text-align: left !important;
|
|
66
137
|
unicode-bidi: isolate !important;
|
|
138
|
+
font-family: 'Courier New', Consolas, Monaco, monospace !important;
|
|
67
139
|
}
|
|
68
140
|
|
|
69
141
|
/* Panel Container */
|
|
@@ -298,8 +370,14 @@ win.webContents.on('dom-ready', () => {
|
|
|
298
370
|
|
|
299
371
|
if (rtlEnabled) {
|
|
300
372
|
document.body.classList.add('rtl-active');
|
|
373
|
+
applyRTLToContent();
|
|
301
374
|
} else {
|
|
302
375
|
document.body.classList.remove('rtl-active');
|
|
376
|
+
// Remove all dir attributes when disabled
|
|
377
|
+
document.querySelectorAll('[dir="rtl"].rtl-processed').forEach(el => {
|
|
378
|
+
el.removeAttribute('dir');
|
|
379
|
+
el.classList.remove('rtl-processed');
|
|
380
|
+
});
|
|
303
381
|
}
|
|
304
382
|
|
|
305
383
|
console.log('RTL_CONFIG_SAVE:' + JSON.stringify({ enabled: rtlEnabled }));
|