antigravity-rtl-patcher 2.3.1 → 2.3.3
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 -14
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.3')}
|
|
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.3');
|
|
15
15
|
|
|
16
16
|
program
|
|
17
17
|
.command('patch')
|
package/package.json
CHANGED
|
@@ -234,19 +234,46 @@ function _agyRtlRendererMain() {
|
|
|
234
234
|
if (!RTL_REGEX.test(text)) return false;
|
|
235
235
|
var m = text.match(RTL_CHAR_REGEX);
|
|
236
236
|
if (!m) return false;
|
|
237
|
-
|
|
238
|
-
|
|
237
|
+
// Calculate total word characters (removing spaces and punctuation)
|
|
238
|
+
var textLen = text.replace(/[\s\d\!\@\#\$\%\^\&\*\(\)\-\_\=\+\[\]\{\}\;\:\'\"\<\.\>\/\?\`\~\|\/\/،؛؟]/g, '').length;
|
|
239
|
+
return textLen > 0 && (m.length / textLen) >= MIN_RTL_RATIO;
|
|
239
240
|
}
|
|
241
|
+
var INLINE_TAGS = ['SPAN', 'A', 'STRONG', 'B', 'EM', 'I', 'CODE', 'MARK', 'LABEL', 'BR', 'KBD', 'S', 'STRIKE', 'U', 'SUB', 'SUP'];
|
|
242
|
+
var TEXT_BLOCKS = ['P', 'H1', 'H2', 'H3', 'H4', 'H5', 'H6', 'BLOCKQUOTE', 'LI', 'TD', 'TH', 'BUTTON', 'TEXTAREA', 'INPUT'];
|
|
243
|
+
|
|
244
|
+
function isTextContainer(el) {
|
|
245
|
+
if (!el || el.nodeType !== 1) return false;
|
|
246
|
+
var tag = el.tagName.toUpperCase();
|
|
247
|
+
if (TEXT_BLOCKS.indexOf(tag) !== -1) return true;
|
|
248
|
+
|
|
249
|
+
// For DIVs and others, they are considered text containers ONLY if they
|
|
250
|
+
// don't contain any structural/block children (like SVG, IMG, DIV, P, UL).
|
|
251
|
+
// This prevents RTL-ing flex containers like sidebars.
|
|
252
|
+
var hasInlineOrText = false;
|
|
253
|
+
for (var i = 0; i < el.childNodes.length; i++) {
|
|
254
|
+
var child = el.childNodes[i];
|
|
255
|
+
if (child.nodeType === 3) {
|
|
256
|
+
if (child.nodeValue.trim().length > 0) hasInlineOrText = true;
|
|
257
|
+
} else if (child.nodeType === 1) {
|
|
258
|
+
if (INLINE_TAGS.indexOf(child.tagName.toUpperCase()) === -1) {
|
|
259
|
+
return false; // Found a block-level child, this is a structural container!
|
|
260
|
+
}
|
|
261
|
+
hasInlineOrText = true;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
return hasInlineOrText;
|
|
265
|
+
}
|
|
266
|
+
|
|
240
267
|
function applyRTL(el) {
|
|
241
268
|
if (el.getAttribute(PROCESSED_ATTR)) return;
|
|
242
269
|
// Skip the RTL panel/icon itself
|
|
243
270
|
if (el.closest && (el.closest('#' + PANEL_ID) || el.closest('#' + STATUS_ICON_ID))) return;
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
271
|
+
|
|
272
|
+
if (isTextContainer(el)) {
|
|
273
|
+
var text = el.textContent || '';
|
|
274
|
+
if (text.trim().length > 0 && isRTL(text)) {
|
|
275
|
+
el.setAttribute(PROCESSED_ATTR, 'true');
|
|
276
|
+
}
|
|
250
277
|
}
|
|
251
278
|
}
|
|
252
279
|
function removeRTL(el) {
|
|
@@ -256,12 +283,8 @@ function _agyRtlRendererMain() {
|
|
|
256
283
|
}
|
|
257
284
|
}
|
|
258
285
|
|
|
259
|
-
//
|
|
260
|
-
var SELECTORS =
|
|
261
|
-
'p', 'li', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6',
|
|
262
|
-
'blockquote', 'td', 'th', 'span', 'a', 'label',
|
|
263
|
-
'button',
|
|
264
|
-
].join(',');
|
|
286
|
+
// Broad selectors — we use isTextContainer to filter them safely
|
|
287
|
+
var SELECTORS = 'div, p, li, h1, h2, h3, h4, h5, h6, blockquote, td, th, span, a, label, button';
|
|
265
288
|
|
|
266
289
|
function scanElement(root) {
|
|
267
290
|
if (!root || root.nodeType !== 1) return;
|