antigravity-rtl-patcher 2.3.0 → 2.3.2
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/bin/cli.js +2 -2
- package/package.json +1 -1
- package/payload/preload-inject.js +37 -11
- package/src/patcher.js +13 -0
package/bin/cli.js
CHANGED
|
@@ -5,13 +5,13 @@ const chalk = require('chalk');
|
|
|
5
5
|
const { patch, restore, status } = require('../src/patcher');
|
|
6
6
|
|
|
7
7
|
const BANNER = `
|
|
8
|
-
${chalk.cyan('Antigravity Smart RTL Patcher')} ${chalk.gray('v2.3.
|
|
8
|
+
${chalk.cyan('Antigravity Smart RTL Patcher')} ${chalk.gray('v2.3.2')}
|
|
9
9
|
`;
|
|
10
10
|
|
|
11
11
|
program
|
|
12
12
|
.name('agy-rtl')
|
|
13
13
|
.description('RTL patcher for Antigravity')
|
|
14
|
-
.version('2.3.
|
|
14
|
+
.version('2.3.2');
|
|
15
15
|
|
|
16
16
|
program
|
|
17
17
|
.command('patch')
|
package/package.json
CHANGED
|
@@ -223,8 +223,8 @@ function _agyRtlRendererMain() {
|
|
|
223
223
|
// ─── Helpers ─────────────────────────────────────────────
|
|
224
224
|
|
|
225
225
|
function getStoredState() {
|
|
226
|
-
try { var s = localStorage.getItem(STORAGE_KEY); return s === null ?
|
|
227
|
-
catch (e) { return
|
|
226
|
+
try { var s = localStorage.getItem(STORAGE_KEY); return s === null ? false : s === 'true'; }
|
|
227
|
+
catch (e) { return false; }
|
|
228
228
|
}
|
|
229
229
|
function setStoredState(v) {
|
|
230
230
|
try { localStorage.setItem(STORAGE_KEY, v ? 'true' : 'false'); } catch (e) {}
|
|
@@ -237,27 +237,53 @@ function _agyRtlRendererMain() {
|
|
|
237
237
|
var alpha = text.replace(/[\s\d\W]/g, '').length;
|
|
238
238
|
return alpha > 0 && (m.length / alpha) >= MIN_RTL_RATIO;
|
|
239
239
|
}
|
|
240
|
+
var INLINE_TAGS = ['SPAN', 'A', 'STRONG', 'B', 'EM', 'I', 'CODE', 'MARK', 'LABEL', 'BR', 'KBD', 'S', 'STRIKE', 'U', 'SUB', 'SUP'];
|
|
241
|
+
var TEXT_BLOCKS = ['P', 'H1', 'H2', 'H3', 'H4', 'H5', 'H6', 'BLOCKQUOTE', 'LI', 'TD', 'TH', 'BUTTON', 'TEXTAREA', 'INPUT'];
|
|
242
|
+
|
|
243
|
+
function isTextContainer(el) {
|
|
244
|
+
if (!el || el.nodeType !== 1) return false;
|
|
245
|
+
var tag = el.tagName.toUpperCase();
|
|
246
|
+
if (TEXT_BLOCKS.indexOf(tag) !== -1) return true;
|
|
247
|
+
|
|
248
|
+
// For DIVs and others, they are considered text containers ONLY if they
|
|
249
|
+
// don't contain any structural/block children (like SVG, IMG, DIV, P, UL).
|
|
250
|
+
// This prevents RTL-ing flex containers like sidebars.
|
|
251
|
+
var hasInlineOrText = false;
|
|
252
|
+
for (var i = 0; i < el.childNodes.length; i++) {
|
|
253
|
+
var child = el.childNodes[i];
|
|
254
|
+
if (child.nodeType === 3) {
|
|
255
|
+
if (child.nodeValue.trim().length > 0) hasInlineOrText = true;
|
|
256
|
+
} else if (child.nodeType === 1) {
|
|
257
|
+
if (INLINE_TAGS.indexOf(child.tagName.toUpperCase()) === -1) {
|
|
258
|
+
return false; // Found a block-level child, this is a structural container!
|
|
259
|
+
}
|
|
260
|
+
hasInlineOrText = true;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
return hasInlineOrText;
|
|
264
|
+
}
|
|
265
|
+
|
|
240
266
|
function applyRTL(el) {
|
|
241
267
|
if (el.getAttribute(PROCESSED_ATTR)) return;
|
|
242
268
|
// Skip the RTL panel/icon itself
|
|
243
269
|
if (el.closest && (el.closest('#' + PANEL_ID) || el.closest('#' + STATUS_ICON_ID))) return;
|
|
244
|
-
|
|
245
|
-
if (
|
|
246
|
-
el.
|
|
270
|
+
|
|
271
|
+
if (isTextContainer(el)) {
|
|
272
|
+
var text = el.textContent || '';
|
|
273
|
+
if (text.trim().length > 0 && isRTL(text)) {
|
|
274
|
+
el.setAttribute(PROCESSED_ATTR, 'true');
|
|
275
|
+
}
|
|
247
276
|
}
|
|
248
277
|
}
|
|
249
278
|
function removeRTL(el) {
|
|
250
279
|
if (el.getAttribute(PROCESSED_ATTR)) {
|
|
251
280
|
el.removeAttribute(PROCESSED_ATTR);
|
|
281
|
+
el.removeAttribute('dir'); // Ensure dir is cleaned up if it was left over from older versions
|
|
252
282
|
}
|
|
253
283
|
}
|
|
254
284
|
|
|
255
|
-
//
|
|
256
|
-
var SELECTORS =
|
|
257
|
-
'p', 'li', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6',
|
|
258
|
-
'blockquote', 'td', 'th', 'span', 'a', 'label',
|
|
259
|
-
'div', 'button',
|
|
260
|
-
].join(',');
|
|
285
|
+
// Broad selectors — we use isTextContainer to filter them safely
|
|
286
|
+
var SELECTORS = 'div, p, li, h1, h2, h3, h4, h5, h6, blockquote, td, th, span, a, label, button';
|
|
261
287
|
|
|
262
288
|
function scanElement(root) {
|
|
263
289
|
if (!root || root.nodeType !== 1) return;
|
package/src/patcher.js
CHANGED
|
@@ -75,6 +75,19 @@ async function patchAsar(installation, spinner) {
|
|
|
75
75
|
asar.extractAll(asarPath, tmpDir);
|
|
76
76
|
spinner.succeed('Extracted successfully.');
|
|
77
77
|
|
|
78
|
+
// 2.5 Check if it's the IDE
|
|
79
|
+
const pkgJsonPath = path.join(tmpDir, 'package.json');
|
|
80
|
+
if (fs.existsSync(pkgJsonPath)) {
|
|
81
|
+
try {
|
|
82
|
+
const pkg = JSON.parse(await fs.readFile(pkgJsonPath, 'utf-8'));
|
|
83
|
+
if (pkg.name && (pkg.name.toLowerCase().includes('ide') || pkg.name.toLowerCase().includes('antigravity-ide'))) {
|
|
84
|
+
spinner.warn('Antigravity IDE detected. Skipping (this patcher is only for the main app).');
|
|
85
|
+
await fs.remove(tmpDir);
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
} catch (e) {}
|
|
89
|
+
}
|
|
90
|
+
|
|
78
91
|
// 3. Find preload.js
|
|
79
92
|
spinner.start('Searching for preload.js...');
|
|
80
93
|
const preloadPath = findPreloadJs(tmpDir);
|