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.
@@ -8,7 +8,7 @@ export interface ParsedLine {
8
8
  */
9
9
  declare function escapeHtml(text: string): string;
10
10
  /**
11
- * Parse code into lines - Simple keyword + special char highlighting
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":"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;AA6BD;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,UAAU,EAAE,UAAU,GAAG,MAAM,CAEnE;AAED;;GAEG;AACH,wBAAgB,qBAAqB,IAAI,MAAM,CAwE9C;;;;;;;AAED,wBAKE"}
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"}
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Simple keyword lists for highlighting
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
- // JUX-specific
12
- 'jux', 'state', 'registry', 'render', 'bind', 'sync'
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, '&#39;');
27
25
  }
28
26
  /**
29
- * Parse code into lines - Simple keyword + special char highlighting
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
- * Ultra-simple highlighting - Keywords + operators + punctuation
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
- // Escape everything first
46
- let result = escapeHtml(line);
47
- // 1. Highlight single-line comments first (so keywords inside comments aren't highlighted)
48
- result = result.replace(/(\/\/.*$)/g, '<span class="token-comment">$1</span>');
49
- // 2. Highlight strings (simple pattern - just quotes, no nested logic)
50
- result = result.replace(/(&quot;[^&]*?&quot;|&#39;[^&#]*?&#39;)/g, '<span class="token-string">$1</span>');
51
- // 3. Highlight numbers
52
- result = result.replace(/\b(\d+)\b/g, '<span class="token-number">$1</span>');
53
- // 4. Highlight keywords (whole words only)
54
- KEYWORDS.forEach(keyword => {
55
- const regex = new RegExp(`\\b(${keyword})\\b`, 'g');
56
- result = result.replace(regex, '<span class="token-keyword">$1</span>');
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
  }
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Simple keyword lists for highlighting
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
- // JUX-specific
12
- 'jux', 'state', 'registry', 'render', 'bind', 'sync'
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 - Simple keyword + special char highlighting
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
- * Ultra-simple highlighting - Keywords + operators + punctuation
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
- // Escape everything first
57
- let result = escapeHtml(line);
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
- // 1. Highlight single-line comments first (so keywords inside comments aren't highlighted)
60
- result = result.replace(/(\/\/.*$)/g, '<span class="token-comment">$1</span>');
58
+ tokens.forEach(token => {
59
+ // Skip empty tokens
60
+ if (!token) return;
61
61
 
62
- // 2. Highlight strings (simple pattern - just quotes, no nested logic)
63
- result = result.replace(/(&quot;[^&]*?&quot;|&#39;[^&#]*?&#39;)/g, '<span class="token-string">$1</span>');
62
+ // Whitespace - preserve as-is
63
+ if (/^\s+$/.test(token)) {
64
+ result += token;
65
+ return;
66
+ }
64
67
 
65
- // 3. Highlight numbers
66
- result = result.replace(/\b(\d+)\b/g, '<span class="token-number">$1</span>');
68
+ // Escape the token
69
+ const escaped = escapeHtml(token);
67
70
 
68
- // 4. Highlight keywords (whole words only)
69
- KEYWORDS.forEach(keyword => {
70
- const regex = new RegExp(`\\b(${keyword})\\b`, 'g');
71
- result = result.replace(regex, '<span class="token-keyword">$1</span>');
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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "juxscript",
3
- "version": "1.1.54",
3
+ "version": "1.1.56",
4
4
  "type": "module",
5
5
  "description": "A JavaScript UX authorship platform",
6
6
  "main": "index.js",