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.
@@ -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":"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"}
@@ -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,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, '&#39;');
27
23
  }
28
24
  /**
29
- * Parse code into lines - Simple keyword + special char highlighting
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
- * Ultra-simple highlighting - Keywords + operators + punctuation
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
- // 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>');
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
  }
@@ -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,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 - Simple keyword + special char highlighting
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
- * Ultra-simple highlighting - Keywords + operators + punctuation
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
- // Escape everything first
57
- let result = escapeHtml(line);
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
- // 1. Highlight single-line comments first (so keywords inside comments aren't highlighted)
60
- result = result.replace(/(\/\/.*$)/g, '<span class="token-comment">$1</span>');
56
+ tokens.forEach(token => {
57
+ // Skip empty tokens
58
+ if (!token) return;
61
59
 
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>');
60
+ // Whitespace - preserve as-is
61
+ if (/^\s+$/.test(token)) {
62
+ result += token;
63
+ return;
64
+ }
64
65
 
65
- // 3. Highlight numbers
66
- result = result.replace(/\b(\d+)\b/g, '<span class="token-number">$1</span>');
66
+ // Escape the token
67
+ const escaped = escapeHtml(token);
67
68
 
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>');
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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "juxscript",
3
- "version": "1.1.54",
3
+ "version": "1.1.55",
4
4
  "type": "module",
5
5
  "description": "A JavaScript UX authorship platform",
6
6
  "main": "index.js",