juxscript 1.1.54 → 1.1.56
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 +30 -32
- package/lib/utils/codeparser.ts +30 -33
- 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 with simple syntax 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":"AAeA,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;AAuCD;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,UAAU,EAAE,UAAU,GAAG,MAAM,CAEnE;AAED;;GAEG;AACH,wBAAgB,qBAAqB,IAAI,MAAM,CA8D9C;;;;;;;AAED,wBAKE"}
|
package/lib/utils/codeparser.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Simple keyword
|
|
2
|
+
* Simple keyword list
|
|
3
3
|
*/
|
|
4
4
|
const KEYWORDS = new Set([
|
|
5
5
|
'async', 'await', 'break', 'case', 'catch', 'class', 'const', 'continue',
|
|
@@ -8,12 +8,10 @@ const KEYWORDS = new Set([
|
|
|
8
8
|
'let', 'new', 'return', 'super', 'switch', 'this', 'throw', 'try',
|
|
9
9
|
'typeof', 'var', 'void', 'while', 'with', 'yield', 'from', 'of',
|
|
10
10
|
'static', 'get', 'set', 'as', 'interface', 'type', 'enum', 'namespace',
|
|
11
|
-
|
|
12
|
-
'
|
|
11
|
+
'jux', 'state', 'registry', 'render', 'bind', 'sync', ';', '=', '==', '===',
|
|
12
|
+
'!=', '!==', '+', '-', '*', '/', '%', '++', '--', '&&', '||', '!', '<', '>',
|
|
13
|
+
'<=', '>=', '=>', '...', '.', ',', '(', ')', '{', '}', '[', ']', ':', '?'
|
|
13
14
|
]);
|
|
14
|
-
// ✅ Reserved operators and punctuation
|
|
15
|
-
const OPERATORS = ['+', '-', '*', '/', '%', '=', '==', '===', '!=', '!==', '<', '>', '<=', '>=', '!', '&&', '||', '?', ':', '=>'];
|
|
16
|
-
const PUNCTUATION = ['{', '}', '(', ')', '[', ']', ';', ',', '.'];
|
|
17
15
|
/**
|
|
18
16
|
* Escape HTML entities
|
|
19
17
|
*/
|
|
@@ -26,7 +24,7 @@ function escapeHtml(text) {
|
|
|
26
24
|
.replace(/'/g, ''');
|
|
27
25
|
}
|
|
28
26
|
/**
|
|
29
|
-
* Parse code into lines
|
|
27
|
+
* Parse code into lines with simple syntax highlighting
|
|
30
28
|
*/
|
|
31
29
|
export function parseCode(code, language = 'javascript') {
|
|
32
30
|
const lines = code.split('\n');
|
|
@@ -37,25 +35,35 @@ export function parseCode(code, language = 'javascript') {
|
|
|
37
35
|
}));
|
|
38
36
|
}
|
|
39
37
|
/**
|
|
40
|
-
*
|
|
38
|
+
* Highlight a single line - token-by-token approach to avoid nested spans
|
|
41
39
|
*/
|
|
42
40
|
function highlightLine(line) {
|
|
43
41
|
if (!line.trim())
|
|
44
42
|
return ' ';
|
|
45
|
-
//
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
43
|
+
// ✅ Split line into tokens (words, operators, whitespace)
|
|
44
|
+
const tokens = line.match(/\w+|[^\w\s]|\s+/g) || [];
|
|
45
|
+
let result = '';
|
|
46
|
+
tokens.forEach(token => {
|
|
47
|
+
// Skip empty tokens
|
|
48
|
+
if (!token)
|
|
49
|
+
return;
|
|
50
|
+
// Whitespace - preserve as-is
|
|
51
|
+
if (/^\s+$/.test(token)) {
|
|
52
|
+
result += token;
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
// Escape the token
|
|
56
|
+
const escaped = escapeHtml(token);
|
|
57
|
+
// Keywords
|
|
58
|
+
if (KEYWORDS.has(token)) {
|
|
59
|
+
result += `<span class="token-keyword">${escaped}</span>`;
|
|
60
|
+
}
|
|
61
|
+
// Everything else - plain text
|
|
62
|
+
else {
|
|
63
|
+
result += escaped;
|
|
64
|
+
}
|
|
57
65
|
});
|
|
58
|
-
return result;
|
|
66
|
+
return result || ' ';
|
|
59
67
|
}
|
|
60
68
|
/**
|
|
61
69
|
* Render a parsed line
|
|
@@ -122,20 +130,10 @@ export function getSyntaxHighlightCSS() {
|
|
|
122
130
|
display: none;
|
|
123
131
|
}
|
|
124
132
|
|
|
125
|
-
/* Token colors */
|
|
133
|
+
/* Token colors - JUST KEYWORDS */
|
|
126
134
|
.token-keyword {
|
|
127
135
|
color: #c678dd;
|
|
128
136
|
font-weight: 600;
|
|
129
|
-
}
|
|
130
|
-
.token-string {
|
|
131
|
-
color: #98c379;
|
|
132
|
-
}
|
|
133
|
-
.token-number {
|
|
134
|
-
color: #d19a66;
|
|
135
|
-
}
|
|
136
|
-
.token-comment {
|
|
137
|
-
color: #5c6370;
|
|
138
|
-
font-style: italic;
|
|
139
137
|
}
|
|
140
138
|
`;
|
|
141
139
|
}
|
package/lib/utils/codeparser.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Simple keyword
|
|
2
|
+
* Simple keyword list
|
|
3
3
|
*/
|
|
4
4
|
const KEYWORDS = new Set([
|
|
5
5
|
'async', 'await', 'break', 'case', 'catch', 'class', 'const', 'continue',
|
|
@@ -8,14 +8,11 @@ const KEYWORDS = new Set([
|
|
|
8
8
|
'let', 'new', 'return', 'super', 'switch', 'this', 'throw', 'try',
|
|
9
9
|
'typeof', 'var', 'void', 'while', 'with', 'yield', 'from', 'of',
|
|
10
10
|
'static', 'get', 'set', 'as', 'interface', 'type', 'enum', 'namespace',
|
|
11
|
-
|
|
12
|
-
'
|
|
11
|
+
'jux', 'state', 'registry', 'render', 'bind', 'sync', ';', '=', '==', '===',
|
|
12
|
+
'!=', '!==', '+', '-', '*', '/', '%', '++', '--', '&&', '||', '!', '<', '>',
|
|
13
|
+
'<=', '>=', '=>', '...', '.', ',', '(', ')', '{', '}', '[', ']', ':', '?'
|
|
13
14
|
]);
|
|
14
15
|
|
|
15
|
-
// ✅ Reserved operators and punctuation
|
|
16
|
-
const OPERATORS = ['+', '-', '*', '/', '%', '=', '==', '===', '!=', '!==', '<', '>', '<=', '>=', '!', '&&', '||', '?', ':', '=>'];
|
|
17
|
-
const PUNCTUATION = ['{', '}', '(', ')', '[', ']', ';', ',', '.'];
|
|
18
|
-
|
|
19
16
|
export interface ParsedLine {
|
|
20
17
|
lineNumber: number;
|
|
21
18
|
html: string;
|
|
@@ -35,7 +32,7 @@ function escapeHtml(text: string): string {
|
|
|
35
32
|
}
|
|
36
33
|
|
|
37
34
|
/**
|
|
38
|
-
* Parse code into lines
|
|
35
|
+
* Parse code into lines with simple syntax highlighting
|
|
39
36
|
*/
|
|
40
37
|
export function parseCode(code: string, language: string = 'javascript'): ParsedLine[] {
|
|
41
38
|
const lines = code.split('\n');
|
|
@@ -48,30 +45,40 @@ export function parseCode(code: string, language: string = 'javascript'): Parsed
|
|
|
48
45
|
}
|
|
49
46
|
|
|
50
47
|
/**
|
|
51
|
-
*
|
|
48
|
+
* Highlight a single line - token-by-token approach to avoid nested spans
|
|
52
49
|
*/
|
|
53
50
|
function highlightLine(line: string): string {
|
|
54
51
|
if (!line.trim()) return ' ';
|
|
55
52
|
|
|
56
|
-
//
|
|
57
|
-
|
|
53
|
+
// ✅ Split line into tokens (words, operators, whitespace)
|
|
54
|
+
const tokens = line.match(/\w+|[^\w\s]|\s+/g) || [];
|
|
55
|
+
|
|
56
|
+
let result = '';
|
|
58
57
|
|
|
59
|
-
|
|
60
|
-
|
|
58
|
+
tokens.forEach(token => {
|
|
59
|
+
// Skip empty tokens
|
|
60
|
+
if (!token) return;
|
|
61
61
|
|
|
62
|
-
|
|
63
|
-
|
|
62
|
+
// Whitespace - preserve as-is
|
|
63
|
+
if (/^\s+$/.test(token)) {
|
|
64
|
+
result += token;
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
64
67
|
|
|
65
|
-
|
|
66
|
-
|
|
68
|
+
// Escape the token
|
|
69
|
+
const escaped = escapeHtml(token);
|
|
67
70
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
71
|
+
// Keywords
|
|
72
|
+
if (KEYWORDS.has(token)) {
|
|
73
|
+
result += `<span class="token-keyword">${escaped}</span>`;
|
|
74
|
+
}
|
|
75
|
+
// Everything else - plain text
|
|
76
|
+
else {
|
|
77
|
+
result += escaped;
|
|
78
|
+
}
|
|
72
79
|
});
|
|
73
80
|
|
|
74
|
-
return result;
|
|
81
|
+
return result || ' ';
|
|
75
82
|
}
|
|
76
83
|
|
|
77
84
|
/**
|
|
@@ -140,20 +147,10 @@ export function getSyntaxHighlightCSS(): string {
|
|
|
140
147
|
display: none;
|
|
141
148
|
}
|
|
142
149
|
|
|
143
|
-
/* Token colors */
|
|
150
|
+
/* Token colors - JUST KEYWORDS */
|
|
144
151
|
.token-keyword {
|
|
145
152
|
color: #c678dd;
|
|
146
153
|
font-weight: 600;
|
|
147
|
-
}
|
|
148
|
-
.token-string {
|
|
149
|
-
color: #98c379;
|
|
150
|
-
}
|
|
151
|
-
.token-number {
|
|
152
|
-
color: #d19a66;
|
|
153
|
-
}
|
|
154
|
-
.token-comment {
|
|
155
|
-
color: #5c6370;
|
|
156
|
-
font-style: italic;
|
|
157
154
|
}
|
|
158
155
|
`;
|
|
159
156
|
}
|