juxscript 1.1.52 → 1.1.53
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/lib/utils/codeparser.d.ts +1 -1
- package/lib/utils/codeparser.d.ts.map +1 -1
- package/lib/utils/codeparser.js +34 -10
- package/lib/utils/codeparser.ts +37 -10
- package/package.json +1 -1
|
@@ -8,7 +8,7 @@ export interface ParsedLine {
|
|
|
8
8
|
*/
|
|
9
9
|
declare function escapeHtml(text: string): string;
|
|
10
10
|
/**
|
|
11
|
-
* Parse code into lines -
|
|
11
|
+
* Parse code into lines - Simple keyword + special char highlighting
|
|
12
12
|
*/
|
|
13
13
|
export declare function parseCode(code: string, language?: string): ParsedLine[];
|
|
14
14
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"codeparser.d.ts","sourceRoot":"","sources":["codeparser.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"codeparser.d.ts","sourceRoot":"","sources":["codeparser.ts"],"names":[],"mappings":"AAkBA,MAAM,WAAW,UAAU;IACvB,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;CACf;AAED;;GAEG;AACH,iBAAS,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAOxC;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,GAAE,MAAqB,GAAG,UAAU,EAAE,CAQrF;AAmCD;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,UAAU,EAAE,UAAU,GAAG,MAAM,CAEnE;AAED;;GAEG;AACH,wBAAgB,qBAAqB,IAAI,MAAM,CAqE9C;;;;;;;AAED,wBAKE"}
|
package/lib/utils/codeparser.js
CHANGED
|
@@ -1,14 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Simple keyword
|
|
2
|
+
* Simple keyword lists for highlighting
|
|
3
3
|
*/
|
|
4
|
-
const KEYWORDS = [
|
|
4
|
+
const KEYWORDS = new Set([
|
|
5
5
|
'async', 'await', 'break', 'case', 'catch', 'class', 'const', 'continue',
|
|
6
6
|
'debugger', 'default', 'delete', 'do', 'else', 'export', 'extends',
|
|
7
7
|
'finally', 'for', 'function', 'if', 'import', 'in', 'instanceof',
|
|
8
8
|
'let', 'new', 'return', 'super', 'switch', 'this', 'throw', 'try',
|
|
9
9
|
'typeof', 'var', 'void', 'while', 'with', 'yield', 'from', 'of',
|
|
10
|
-
'static', 'get', 'set', 'as', 'interface', 'type', 'enum', 'namespace'
|
|
11
|
-
|
|
10
|
+
'static', 'get', 'set', 'as', 'interface', 'type', 'enum', 'namespace',
|
|
11
|
+
// ✅ JUX-specific
|
|
12
|
+
'jux', 'state', 'registry', 'render', 'bind', 'sync'
|
|
13
|
+
]);
|
|
14
|
+
// ✅ Reserved operators and punctuation
|
|
15
|
+
const OPERATORS = ['+', '-', '*', '/', '%', '=', '==', '===', '!=', '!==', '<', '>', '<=', '>=', '!', '&&', '||', '?', ':', '=>'];
|
|
16
|
+
const PUNCTUATION = ['{', '}', '(', ')', '[', ']', ';', ',', '.'];
|
|
12
17
|
/**
|
|
13
18
|
* Escape HTML entities
|
|
14
19
|
*/
|
|
@@ -21,7 +26,7 @@ function escapeHtml(text) {
|
|
|
21
26
|
.replace(/'/g, ''');
|
|
22
27
|
}
|
|
23
28
|
/**
|
|
24
|
-
* Parse code into lines -
|
|
29
|
+
* Parse code into lines - Simple keyword + special char highlighting
|
|
25
30
|
*/
|
|
26
31
|
export function parseCode(code, language = 'javascript') {
|
|
27
32
|
const lines = code.split('\n');
|
|
@@ -32,19 +37,31 @@ export function parseCode(code, language = 'javascript') {
|
|
|
32
37
|
}));
|
|
33
38
|
}
|
|
34
39
|
/**
|
|
35
|
-
* Ultra-simple highlighting -
|
|
40
|
+
* Ultra-simple highlighting - Keywords + operators + punctuation
|
|
36
41
|
*/
|
|
37
42
|
function highlightLine(line) {
|
|
38
43
|
if (!line.trim())
|
|
39
44
|
return ' ';
|
|
40
45
|
// Escape everything first
|
|
41
46
|
let result = escapeHtml(line);
|
|
42
|
-
//
|
|
47
|
+
// 1. Highlight keywords (whole words only)
|
|
43
48
|
KEYWORDS.forEach(keyword => {
|
|
44
|
-
// Match whole words only, case-sensitive
|
|
45
49
|
const regex = new RegExp(`\\b(${keyword})\\b`, 'g');
|
|
46
50
|
result = result.replace(regex, '<span class="token-keyword">$1</span>');
|
|
47
51
|
});
|
|
52
|
+
// 2. Highlight operators (multi-char first, then single-char)
|
|
53
|
+
const sortedOps = [...OPERATORS].sort((a, b) => b.length - a.length);
|
|
54
|
+
sortedOps.forEach(op => {
|
|
55
|
+
const escaped = op.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
56
|
+
const regex = new RegExp(escaped, 'g');
|
|
57
|
+
result = result.replace(regex, `<span class="token-operator">${escapeHtml(op)}</span>`);
|
|
58
|
+
});
|
|
59
|
+
// 3. Highlight punctuation
|
|
60
|
+
PUNCTUATION.forEach(punct => {
|
|
61
|
+
const escaped = punct.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
62
|
+
const regex = new RegExp(escaped, 'g');
|
|
63
|
+
result = result.replace(regex, `<span class="token-punctuation">${escapeHtml(punct)}</span>`);
|
|
64
|
+
});
|
|
48
65
|
return result;
|
|
49
66
|
}
|
|
50
67
|
/**
|
|
@@ -58,7 +75,7 @@ export function renderLineWithTokens(parsedLine) {
|
|
|
58
75
|
*/
|
|
59
76
|
export function getSyntaxHighlightCSS() {
|
|
60
77
|
return `
|
|
61
|
-
/* Simple
|
|
78
|
+
/* Simple Syntax Highlighting */
|
|
62
79
|
.jux-code {
|
|
63
80
|
font-family: 'Fira Code', 'Consolas', 'Monaco', monospace;
|
|
64
81
|
font-size: 14px;
|
|
@@ -112,10 +129,17 @@ export function getSyntaxHighlightCSS() {
|
|
|
112
129
|
display: none;
|
|
113
130
|
}
|
|
114
131
|
|
|
115
|
-
/* Token colors
|
|
132
|
+
/* Token colors */
|
|
116
133
|
.token-keyword {
|
|
117
134
|
color: #c678dd;
|
|
118
135
|
font-weight: 600;
|
|
136
|
+
}
|
|
137
|
+
.token-operator {
|
|
138
|
+
color: #56b6c2;
|
|
139
|
+
font-weight: 500;
|
|
140
|
+
}
|
|
141
|
+
.token-punctuation {
|
|
142
|
+
color: #abb2bf;
|
|
119
143
|
}
|
|
120
144
|
`;
|
|
121
145
|
}
|
package/lib/utils/codeparser.ts
CHANGED
|
@@ -1,14 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Simple keyword
|
|
2
|
+
* Simple keyword lists for highlighting
|
|
3
3
|
*/
|
|
4
|
-
const KEYWORDS = [
|
|
4
|
+
const KEYWORDS = new Set([
|
|
5
5
|
'async', 'await', 'break', 'case', 'catch', 'class', 'const', 'continue',
|
|
6
6
|
'debugger', 'default', 'delete', 'do', 'else', 'export', 'extends',
|
|
7
7
|
'finally', 'for', 'function', 'if', 'import', 'in', 'instanceof',
|
|
8
8
|
'let', 'new', 'return', 'super', 'switch', 'this', 'throw', 'try',
|
|
9
9
|
'typeof', 'var', 'void', 'while', 'with', 'yield', 'from', 'of',
|
|
10
|
-
'static', 'get', 'set', 'as', 'interface', 'type', 'enum', 'namespace'
|
|
11
|
-
|
|
10
|
+
'static', 'get', 'set', 'as', 'interface', 'type', 'enum', 'namespace',
|
|
11
|
+
// ✅ JUX-specific
|
|
12
|
+
'jux', 'state', 'registry', 'render', 'bind', 'sync'
|
|
13
|
+
]);
|
|
14
|
+
|
|
15
|
+
// ✅ Reserved operators and punctuation
|
|
16
|
+
const OPERATORS = ['+', '-', '*', '/', '%', '=', '==', '===', '!=', '!==', '<', '>', '<=', '>=', '!', '&&', '||', '?', ':', '=>'];
|
|
17
|
+
const PUNCTUATION = ['{', '}', '(', ')', '[', ']', ';', ',', '.'];
|
|
12
18
|
|
|
13
19
|
export interface ParsedLine {
|
|
14
20
|
lineNumber: number;
|
|
@@ -29,7 +35,7 @@ function escapeHtml(text: string): string {
|
|
|
29
35
|
}
|
|
30
36
|
|
|
31
37
|
/**
|
|
32
|
-
* Parse code into lines -
|
|
38
|
+
* Parse code into lines - Simple keyword + special char highlighting
|
|
33
39
|
*/
|
|
34
40
|
export function parseCode(code: string, language: string = 'javascript'): ParsedLine[] {
|
|
35
41
|
const lines = code.split('\n');
|
|
@@ -42,7 +48,7 @@ export function parseCode(code: string, language: string = 'javascript'): Parsed
|
|
|
42
48
|
}
|
|
43
49
|
|
|
44
50
|
/**
|
|
45
|
-
* Ultra-simple highlighting -
|
|
51
|
+
* Ultra-simple highlighting - Keywords + operators + punctuation
|
|
46
52
|
*/
|
|
47
53
|
function highlightLine(line: string): string {
|
|
48
54
|
if (!line.trim()) return ' ';
|
|
@@ -50,13 +56,27 @@ function highlightLine(line: string): string {
|
|
|
50
56
|
// Escape everything first
|
|
51
57
|
let result = escapeHtml(line);
|
|
52
58
|
|
|
53
|
-
//
|
|
59
|
+
// 1. Highlight keywords (whole words only)
|
|
54
60
|
KEYWORDS.forEach(keyword => {
|
|
55
|
-
// Match whole words only, case-sensitive
|
|
56
61
|
const regex = new RegExp(`\\b(${keyword})\\b`, 'g');
|
|
57
62
|
result = result.replace(regex, '<span class="token-keyword">$1</span>');
|
|
58
63
|
});
|
|
59
64
|
|
|
65
|
+
// 2. Highlight operators (multi-char first, then single-char)
|
|
66
|
+
const sortedOps = [...OPERATORS].sort((a, b) => b.length - a.length);
|
|
67
|
+
sortedOps.forEach(op => {
|
|
68
|
+
const escaped = op.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
69
|
+
const regex = new RegExp(escaped, 'g');
|
|
70
|
+
result = result.replace(regex, `<span class="token-operator">${escapeHtml(op)}</span>`);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
// 3. Highlight punctuation
|
|
74
|
+
PUNCTUATION.forEach(punct => {
|
|
75
|
+
const escaped = punct.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
76
|
+
const regex = new RegExp(escaped, 'g');
|
|
77
|
+
result = result.replace(regex, `<span class="token-punctuation">${escapeHtml(punct)}</span>`);
|
|
78
|
+
});
|
|
79
|
+
|
|
60
80
|
return result;
|
|
61
81
|
}
|
|
62
82
|
|
|
@@ -72,7 +92,7 @@ export function renderLineWithTokens(parsedLine: ParsedLine): string {
|
|
|
72
92
|
*/
|
|
73
93
|
export function getSyntaxHighlightCSS(): string {
|
|
74
94
|
return `
|
|
75
|
-
/* Simple
|
|
95
|
+
/* Simple Syntax Highlighting */
|
|
76
96
|
.jux-code {
|
|
77
97
|
font-family: 'Fira Code', 'Consolas', 'Monaco', monospace;
|
|
78
98
|
font-size: 14px;
|
|
@@ -126,10 +146,17 @@ export function getSyntaxHighlightCSS(): string {
|
|
|
126
146
|
display: none;
|
|
127
147
|
}
|
|
128
148
|
|
|
129
|
-
/* Token colors
|
|
149
|
+
/* Token colors */
|
|
130
150
|
.token-keyword {
|
|
131
151
|
color: #c678dd;
|
|
132
152
|
font-weight: 600;
|
|
153
|
+
}
|
|
154
|
+
.token-operator {
|
|
155
|
+
color: #56b6c2;
|
|
156
|
+
font-weight: 500;
|
|
157
|
+
}
|
|
158
|
+
.token-punctuation {
|
|
159
|
+
color: #abb2bf;
|
|
133
160
|
}
|
|
134
161
|
`;
|
|
135
162
|
}
|