juxscript 1.1.53 → 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;AAmCD;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,UAAU,EAAE,UAAU,GAAG,MAAM,CAEnE;AAED;;GAEG;AACH,wBAAgB,qBAAqB,IAAI,MAAM,CAqE9C;;;;;;;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,32 +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 keywords (whole words only)
48
- KEYWORDS.forEach(keyword => {
49
- const regex = new RegExp(`\\b(${keyword})\\b`, 'g');
50
- 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
+ }
51
63
  });
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
- });
65
- return result;
64
+ return result || ' ';
66
65
  }
67
66
  /**
68
67
  * Render a parsed line
@@ -129,17 +128,10 @@ export function getSyntaxHighlightCSS() {
129
128
  display: none;
130
129
  }
131
130
 
132
- /* Token colors */
131
+ /* Token colors - JUST KEYWORDS */
133
132
  .token-keyword {
134
133
  color: #c678dd;
135
134
  font-weight: 600;
136
- }
137
- .token-operator {
138
- color: #56b6c2;
139
- font-weight: 500;
140
- }
141
- .token-punctuation {
142
- color: #abb2bf;
143
135
  }
144
136
  `;
145
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,36 +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) || [];
58
53
 
59
- // 1. Highlight keywords (whole words only)
60
- KEYWORDS.forEach(keyword => {
61
- const regex = new RegExp(`\\b(${keyword})\\b`, 'g');
62
- result = result.replace(regex, '<span class="token-keyword">$1</span>');
63
- });
54
+ let result = '';
64
55
 
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
- });
56
+ tokens.forEach(token => {
57
+ // Skip empty tokens
58
+ if (!token) return;
59
+
60
+ // Whitespace - preserve as-is
61
+ if (/^\s+$/.test(token)) {
62
+ result += token;
63
+ return;
64
+ }
72
65
 
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>`);
66
+ // Escape the token
67
+ const escaped = escapeHtml(token);
68
+
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
+ }
78
77
  });
79
78
 
80
- return result;
79
+ return result || ' ';
81
80
  }
82
81
 
83
82
  /**
@@ -146,17 +145,10 @@ export function getSyntaxHighlightCSS(): string {
146
145
  display: none;
147
146
  }
148
147
 
149
- /* Token colors */
148
+ /* Token colors - JUST KEYWORDS */
150
149
  .token-keyword {
151
150
  color: #c678dd;
152
151
  font-weight: 600;
153
- }
154
- .token-operator {
155
- color: #56b6c2;
156
- font-weight: 500;
157
- }
158
- .token-punctuation {
159
- color: #abb2bf;
160
152
  }
161
153
  `;
162
154
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "juxscript",
3
- "version": "1.1.53",
3
+ "version": "1.1.55",
4
4
  "type": "module",
5
5
  "description": "A JavaScript UX authorship platform",
6
6
  "main": "index.js",