juxscript 1.1.54 → 1.1.55
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 +27 -31
- package/lib/utils/codeparser.ts +27 -32
- 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":"AAaA,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,8 @@ 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
|
-
// ✅ JUX-specific
|
|
12
11
|
'jux', 'state', 'registry', 'render', 'bind', 'sync'
|
|
13
12
|
]);
|
|
14
|
-
// ✅ Reserved operators and punctuation
|
|
15
|
-
const OPERATORS = ['+', '-', '*', '/', '%', '=', '==', '===', '!=', '!==', '<', '>', '<=', '>=', '!', '&&', '||', '?', ':', '=>'];
|
|
16
|
-
const PUNCTUATION = ['{', '}', '(', ')', '[', ']', ';', ',', '.'];
|
|
17
13
|
/**
|
|
18
14
|
* Escape HTML entities
|
|
19
15
|
*/
|
|
@@ -26,7 +22,7 @@ function escapeHtml(text) {
|
|
|
26
22
|
.replace(/'/g, ''');
|
|
27
23
|
}
|
|
28
24
|
/**
|
|
29
|
-
* Parse code into lines
|
|
25
|
+
* Parse code into lines with simple syntax highlighting
|
|
30
26
|
*/
|
|
31
27
|
export function parseCode(code, language = 'javascript') {
|
|
32
28
|
const lines = code.split('\n');
|
|
@@ -37,25 +33,35 @@ export function parseCode(code, language = 'javascript') {
|
|
|
37
33
|
}));
|
|
38
34
|
}
|
|
39
35
|
/**
|
|
40
|
-
*
|
|
36
|
+
* Highlight a single line - token-by-token approach to avoid nested spans
|
|
41
37
|
*/
|
|
42
38
|
function highlightLine(line) {
|
|
43
39
|
if (!line.trim())
|
|
44
40
|
return ' ';
|
|
45
|
-
//
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
41
|
+
// ✅ Split line into tokens (words, operators, whitespace)
|
|
42
|
+
const tokens = line.match(/\w+|[^\w\s]|\s+/g) || [];
|
|
43
|
+
let result = '';
|
|
44
|
+
tokens.forEach(token => {
|
|
45
|
+
// Skip empty tokens
|
|
46
|
+
if (!token)
|
|
47
|
+
return;
|
|
48
|
+
// Whitespace - preserve as-is
|
|
49
|
+
if (/^\s+$/.test(token)) {
|
|
50
|
+
result += token;
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
// Escape the token
|
|
54
|
+
const escaped = escapeHtml(token);
|
|
55
|
+
// Keywords
|
|
56
|
+
if (KEYWORDS.has(token)) {
|
|
57
|
+
result += `<span class="token-keyword">${escaped}</span>`;
|
|
58
|
+
}
|
|
59
|
+
// Everything else - plain text
|
|
60
|
+
else {
|
|
61
|
+
result += escaped;
|
|
62
|
+
}
|
|
57
63
|
});
|
|
58
|
-
return result;
|
|
64
|
+
return result || ' ';
|
|
59
65
|
}
|
|
60
66
|
/**
|
|
61
67
|
* Render a parsed line
|
|
@@ -122,20 +128,10 @@ export function getSyntaxHighlightCSS() {
|
|
|
122
128
|
display: none;
|
|
123
129
|
}
|
|
124
130
|
|
|
125
|
-
/* Token colors */
|
|
131
|
+
/* Token colors - JUST KEYWORDS */
|
|
126
132
|
.token-keyword {
|
|
127
133
|
color: #c678dd;
|
|
128
134
|
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
135
|
}
|
|
140
136
|
`;
|
|
141
137
|
}
|
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,9 @@ 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
|
-
// ✅ JUX-specific
|
|
12
11
|
'jux', 'state', 'registry', 'render', 'bind', 'sync'
|
|
13
12
|
]);
|
|
14
13
|
|
|
15
|
-
// ✅ Reserved operators and punctuation
|
|
16
|
-
const OPERATORS = ['+', '-', '*', '/', '%', '=', '==', '===', '!=', '!==', '<', '>', '<=', '>=', '!', '&&', '||', '?', ':', '=>'];
|
|
17
|
-
const PUNCTUATION = ['{', '}', '(', ')', '[', ']', ';', ',', '.'];
|
|
18
|
-
|
|
19
14
|
export interface ParsedLine {
|
|
20
15
|
lineNumber: number;
|
|
21
16
|
html: string;
|
|
@@ -35,7 +30,7 @@ function escapeHtml(text: string): string {
|
|
|
35
30
|
}
|
|
36
31
|
|
|
37
32
|
/**
|
|
38
|
-
* Parse code into lines
|
|
33
|
+
* Parse code into lines with simple syntax highlighting
|
|
39
34
|
*/
|
|
40
35
|
export function parseCode(code: string, language: string = 'javascript'): ParsedLine[] {
|
|
41
36
|
const lines = code.split('\n');
|
|
@@ -48,30 +43,40 @@ export function parseCode(code: string, language: string = 'javascript'): Parsed
|
|
|
48
43
|
}
|
|
49
44
|
|
|
50
45
|
/**
|
|
51
|
-
*
|
|
46
|
+
* Highlight a single line - token-by-token approach to avoid nested spans
|
|
52
47
|
*/
|
|
53
48
|
function highlightLine(line: string): string {
|
|
54
49
|
if (!line.trim()) return ' ';
|
|
55
50
|
|
|
56
|
-
//
|
|
57
|
-
|
|
51
|
+
// ✅ Split line into tokens (words, operators, whitespace)
|
|
52
|
+
const tokens = line.match(/\w+|[^\w\s]|\s+/g) || [];
|
|
53
|
+
|
|
54
|
+
let result = '';
|
|
58
55
|
|
|
59
|
-
|
|
60
|
-
|
|
56
|
+
tokens.forEach(token => {
|
|
57
|
+
// Skip empty tokens
|
|
58
|
+
if (!token) return;
|
|
61
59
|
|
|
62
|
-
|
|
63
|
-
|
|
60
|
+
// Whitespace - preserve as-is
|
|
61
|
+
if (/^\s+$/.test(token)) {
|
|
62
|
+
result += token;
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
64
65
|
|
|
65
|
-
|
|
66
|
-
|
|
66
|
+
// Escape the token
|
|
67
|
+
const escaped = escapeHtml(token);
|
|
67
68
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
69
|
+
// Keywords
|
|
70
|
+
if (KEYWORDS.has(token)) {
|
|
71
|
+
result += `<span class="token-keyword">${escaped}</span>`;
|
|
72
|
+
}
|
|
73
|
+
// Everything else - plain text
|
|
74
|
+
else {
|
|
75
|
+
result += escaped;
|
|
76
|
+
}
|
|
72
77
|
});
|
|
73
78
|
|
|
74
|
-
return result;
|
|
79
|
+
return result || ' ';
|
|
75
80
|
}
|
|
76
81
|
|
|
77
82
|
/**
|
|
@@ -140,20 +145,10 @@ export function getSyntaxHighlightCSS(): string {
|
|
|
140
145
|
display: none;
|
|
141
146
|
}
|
|
142
147
|
|
|
143
|
-
/* Token colors */
|
|
148
|
+
/* Token colors - JUST KEYWORDS */
|
|
144
149
|
.token-keyword {
|
|
145
150
|
color: #c678dd;
|
|
146
151
|
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
152
|
}
|
|
158
153
|
`;
|
|
159
154
|
}
|