juxscript 1.1.51 → 1.1.53

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,20 +8,17 @@ export interface ParsedLine {
8
8
  */
9
9
  declare function escapeHtml(text: string): string;
10
10
  /**
11
- * Parse code into lines with simple syntax highlighting
11
+ * Parse code into lines - Simple keyword + special char highlighting
12
12
  */
13
13
  export declare function parseCode(code: string, language?: string): ParsedLine[];
14
14
  /**
15
- * Render a parsed line (just returns the pre-generated HTML)
15
+ * Render a parsed line
16
16
  */
17
17
  export declare function renderLineWithTokens(parsedLine: ParsedLine): string;
18
18
  /**
19
19
  * Generate CSS for syntax highlighting
20
20
  */
21
21
  export declare function getSyntaxHighlightCSS(): string;
22
- /**
23
- * Main parser export
24
- */
25
22
  declare const _default: {
26
23
  parse: typeof parseCode;
27
24
  renderLine: typeof renderLineWithTokens;
@@ -1 +1 @@
1
- {"version":3,"file":"codeparser.d.ts","sourceRoot":"","sources":["codeparser.ts"],"names":[],"mappings":"AAYA,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;AAsCD;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,UAAU,EAAE,UAAU,GAAG,MAAM,CAEnE;AAED;;GAEG;AACH,wBAAgB,qBAAqB,IAAI,MAAM,CAiE9C;AAED;;GAEG;;;;;;;AACH,wBAKE"}
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"}
@@ -7,8 +7,13 @@ const KEYWORDS = new Set([
7
7
  'finally', 'for', 'function', 'if', 'import', 'in', 'instanceof',
8
8
  'let', 'new', 'return', 'super', 'switch', 'this', 'throw', 'try',
9
9
  'typeof', 'var', 'void', 'while', 'with', 'yield', 'from', 'of',
10
- 'static', 'get', 'set', 'as', 'interface', 'type', 'enum', 'namespace'
10
+ 'static', 'get', 'set', 'as', 'interface', 'type', 'enum', 'namespace',
11
+ // ✅ JUX-specific
12
+ 'jux', 'state', 'registry', 'render', 'bind', 'sync'
11
13
  ]);
14
+ // ✅ Reserved operators and punctuation
15
+ const OPERATORS = ['+', '-', '*', '/', '%', '=', '==', '===', '!=', '!==', '<', '>', '<=', '>=', '!', '&&', '||', '?', ':', '=>'];
16
+ const PUNCTUATION = ['{', '}', '(', ')', '[', ']', ';', ',', '.'];
12
17
  /**
13
18
  * Escape HTML entities
14
19
  */
@@ -21,7 +26,7 @@ function escapeHtml(text) {
21
26
  .replace(/'/g, '&#39;');
22
27
  }
23
28
  /**
24
- * Parse code into lines with simple syntax highlighting
29
+ * Parse code into lines - Simple keyword + special char highlighting
25
30
  */
26
31
  export function parseCode(code, language = 'javascript') {
27
32
  const lines = code.split('\n');
@@ -32,34 +37,35 @@ export function parseCode(code, language = 'javascript') {
32
37
  }));
33
38
  }
34
39
  /**
35
- * Highlight a single line of code
40
+ * Ultra-simple highlighting - Keywords + operators + punctuation
36
41
  */
37
42
  function highlightLine(line) {
38
43
  if (!line.trim())
39
44
  return ' ';
40
- // Escape the raw line first
41
- let escaped = escapeHtml(line);
42
- // Now add spans (on already-escaped text)
43
- // 1. Comments
44
- escaped = escaped.replace(/(\/\/.*$)/g, '<span class="token-comment">$1</span>');
45
- escaped = escaped.replace(/(\/\*[\s\S]*?\*\/)/g, '<span class="token-comment">$1</span>');
46
- // 2. Strings (already escaped, so look for &quot; etc)
47
- escaped = escaped.replace(/(&quot;[^&]*?&quot;|&#39;[^&]*?&#39;|`[^`]*?`)/g, '<span class="token-string">$1</span>');
48
- // 3. Numbers
49
- escaped = escaped.replace(/\b(\d+\.?\d*)\b/g, '<span class="token-number">$1</span>');
50
- // 4. Keywords (only whole words)
45
+ // Escape everything first
46
+ let result = escapeHtml(line);
47
+ // 1. Highlight keywords (whole words only)
51
48
  KEYWORDS.forEach(keyword => {
52
49
  const regex = new RegExp(`\\b(${keyword})\\b`, 'g');
53
- escaped = escaped.replace(regex, '<span class="token-keyword">$1</span>');
50
+ result = result.replace(regex, '<span class="token-keyword">$1</span>');
54
51
  });
55
- // 5. Braces, brackets, parentheses (these are plain text, not escaped)
56
- escaped = escaped.replace(/([{}[\]()])/g, '<span class="token-punctuation">$1</span>');
57
- // 6. Operators
58
- escaped = escaped.replace(/([+\-*/%=&lt;&gt;!&|^~?:])/g, '<span class="token-operator">$1</span>');
59
- return escaped || ' ';
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;
60
66
  }
61
67
  /**
62
- * Render a parsed line (just returns the pre-generated HTML)
68
+ * Render a parsed line
63
69
  */
64
70
  export function renderLineWithTokens(parsedLine) {
65
71
  return parsedLine.html;
@@ -90,11 +96,10 @@ export function getSyntaxHighlightCSS() {
90
96
  display: flex;
91
97
  align-items: flex-start;
92
98
  min-height: 1.6em;
93
- transition: background-color 0.2s;
94
99
  }
95
100
 
96
101
  .jux-code-line:hover {
97
- background-color: rgba(255, 255, 255, 0.05);
102
+ background-color: rgba(255, 255, 255, 0.03);
98
103
  }
99
104
 
100
105
  .jux-code-line-highlight {
@@ -125,17 +130,19 @@ export function getSyntaxHighlightCSS() {
125
130
  }
126
131
 
127
132
  /* Token colors */
128
- .token-keyword { color: #c678dd; font-weight: 600; }
129
- .token-string { color: #98c379; }
130
- .token-number { color: #d19a66; }
131
- .token-comment { color: #5c6370; font-style: italic; }
132
- .token-punctuation { color: #abb2bf; }
133
- .token-operator { color: #56b6c2; }
133
+ .token-keyword {
134
+ color: #c678dd;
135
+ font-weight: 600;
136
+ }
137
+ .token-operator {
138
+ color: #56b6c2;
139
+ font-weight: 500;
140
+ }
141
+ .token-punctuation {
142
+ color: #abb2bf;
143
+ }
134
144
  `;
135
145
  }
136
- /**
137
- * Main parser export
138
- */
139
146
  export default {
140
147
  parse: parseCode,
141
148
  renderLine: renderLineWithTokens,
@@ -7,9 +7,15 @@ const KEYWORDS = new Set([
7
7
  'finally', 'for', 'function', 'if', 'import', 'in', 'instanceof',
8
8
  'let', 'new', 'return', 'super', 'switch', 'this', 'throw', 'try',
9
9
  'typeof', 'var', 'void', 'while', 'with', 'yield', 'from', 'of',
10
- 'static', 'get', 'set', 'as', 'interface', 'type', 'enum', 'namespace'
10
+ 'static', 'get', 'set', 'as', 'interface', 'type', 'enum', 'namespace',
11
+ // ✅ JUX-specific
12
+ 'jux', 'state', 'registry', 'render', 'bind', 'sync'
11
13
  ]);
12
14
 
15
+ // ✅ Reserved operators and punctuation
16
+ const OPERATORS = ['+', '-', '*', '/', '%', '=', '==', '===', '!=', '!==', '<', '>', '<=', '>=', '!', '&&', '||', '?', ':', '=>'];
17
+ const PUNCTUATION = ['{', '}', '(', ')', '[', ']', ';', ',', '.'];
18
+
13
19
  export interface ParsedLine {
14
20
  lineNumber: number;
15
21
  html: string;
@@ -29,7 +35,7 @@ function escapeHtml(text: string): string {
29
35
  }
30
36
 
31
37
  /**
32
- * Parse code into lines with simple syntax highlighting
38
+ * Parse code into lines - Simple keyword + special char highlighting
33
39
  */
34
40
  export function parseCode(code: string, language: string = 'javascript'): ParsedLine[] {
35
41
  const lines = code.split('\n');
@@ -42,43 +48,40 @@ export function parseCode(code: string, language: string = 'javascript'): Parsed
42
48
  }
43
49
 
44
50
  /**
45
- * Highlight a single line of code
51
+ * Ultra-simple highlighting - Keywords + operators + punctuation
46
52
  */
47
53
  function highlightLine(line: string): string {
48
54
  if (!line.trim()) return ' ';
49
55
 
50
- // Escape the raw line first
51
- let escaped = escapeHtml(line);
52
-
53
- // Now add spans (on already-escaped text)
54
-
55
- // 1. Comments
56
- escaped = escaped.replace(/(\/\/.*$)/g, '<span class="token-comment">$1</span>');
57
- escaped = escaped.replace(/(\/\*[\s\S]*?\*\/)/g, '<span class="token-comment">$1</span>');
56
+ // Escape everything first
57
+ let result = escapeHtml(line);
58
58
 
59
- // 2. Strings (already escaped, so look for &quot; etc)
60
- escaped = escaped.replace(/(&quot;[^&]*?&quot;|&#39;[^&]*?&#39;|`[^`]*?`)/g, '<span class="token-string">$1</span>');
61
-
62
- // 3. Numbers
63
- escaped = escaped.replace(/\b(\d+\.?\d*)\b/g, '<span class="token-number">$1</span>');
64
-
65
- // 4. Keywords (only whole words)
59
+ // 1. Highlight keywords (whole words only)
66
60
  KEYWORDS.forEach(keyword => {
67
61
  const regex = new RegExp(`\\b(${keyword})\\b`, 'g');
68
- escaped = escaped.replace(regex, '<span class="token-keyword">$1</span>');
62
+ result = result.replace(regex, '<span class="token-keyword">$1</span>');
69
63
  });
70
64
 
71
- // 5. Braces, brackets, parentheses (these are plain text, not escaped)
72
- escaped = escaped.replace(/([{}[\]()])/g, '<span class="token-punctuation">$1</span>');
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
+ });
73
72
 
74
- // 6. Operators
75
- escaped = escaped.replace(/([+\-*/%=&lt;&gt;!&|^~?:])/g, '<span class="token-operator">$1</span>');
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>`);
78
+ });
76
79
 
77
- return escaped || ' ';
80
+ return result;
78
81
  }
79
82
 
80
83
  /**
81
- * Render a parsed line (just returns the pre-generated HTML)
84
+ * Render a parsed line
82
85
  */
83
86
  export function renderLineWithTokens(parsedLine: ParsedLine): string {
84
87
  return parsedLine.html;
@@ -110,11 +113,10 @@ export function getSyntaxHighlightCSS(): string {
110
113
  display: flex;
111
114
  align-items: flex-start;
112
115
  min-height: 1.6em;
113
- transition: background-color 0.2s;
114
116
  }
115
117
 
116
118
  .jux-code-line:hover {
117
- background-color: rgba(255, 255, 255, 0.05);
119
+ background-color: rgba(255, 255, 255, 0.03);
118
120
  }
119
121
 
120
122
  .jux-code-line-highlight {
@@ -145,18 +147,20 @@ export function getSyntaxHighlightCSS(): string {
145
147
  }
146
148
 
147
149
  /* Token colors */
148
- .token-keyword { color: #c678dd; font-weight: 600; }
149
- .token-string { color: #98c379; }
150
- .token-number { color: #d19a66; }
151
- .token-comment { color: #5c6370; font-style: italic; }
152
- .token-punctuation { color: #abb2bf; }
153
- .token-operator { color: #56b6c2; }
150
+ .token-keyword {
151
+ color: #c678dd;
152
+ font-weight: 600;
153
+ }
154
+ .token-operator {
155
+ color: #56b6c2;
156
+ font-weight: 500;
157
+ }
158
+ .token-punctuation {
159
+ color: #abb2bf;
160
+ }
154
161
  `;
155
162
  }
156
163
 
157
- /**
158
- * Main parser export
159
- */
160
164
  export default {
161
165
  parse: parseCode,
162
166
  renderLine: renderLineWithTokens,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "juxscript",
3
- "version": "1.1.51",
3
+ "version": "1.1.53",
4
4
  "type": "module",
5
5
  "description": "A JavaScript UX authorship platform",
6
6
  "main": "index.js",