@ape-egg/codie 0.1.2 → 0.1.3

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/codie.js CHANGED
@@ -61,7 +61,7 @@ const highlight = (code, modes, options = {}) => {
61
61
  if (!modes.html) {
62
62
  if (modes.json) return highlightJSON(escaped);
63
63
  if (modes.css) return highlightCSS(escaped);
64
- if (modes.js) return highlightJS(escaped);
64
+ if (modes.js) return highlightJSRaw(code);
65
65
  return escaped;
66
66
  }
67
67
 
package/constants.js CHANGED
@@ -53,6 +53,7 @@ export const CLASS = {
53
53
  CSS_VALUE: 'codie-css-value',
54
54
 
55
55
  // Syntax tokens - JS
56
+ COMMAND: 'codie-command',
56
57
  JS_KEYWORD: 'codie-js-keyword',
57
58
  JS_IMPORT: 'codie-js-import',
58
59
  JS_STRING: 'codie-js-string',
package/format.js CHANGED
@@ -12,12 +12,13 @@ export const dedent = str => {
12
12
 
13
13
  // Clean up boolean attributes for non-value attributes:
14
14
  // attr="" → attr, attr="true" → attr, attr="false" → (removed)
15
+ // Vibe name bindings (@[expr]) count as attribute names too.
15
16
  export const cleanupBooleanAttrs = html =>
16
17
  html
17
- .replace(/ ([\w-]+)="(?:true|)"/g, (match, attr) =>
18
+ .replace(/ ([\w-]+|@\[[^\]]+\])="(?:true|)"/g, (match, attr) =>
18
19
  VALUE_ATTRS.has(attr) ? match : ` ${attr}`
19
20
  )
20
- .replace(/ ([\w-]+)="false"/g, (match, attr) =>
21
+ .replace(/ ([\w-]+|@\[[^\]]+\])="false"/g, (match, attr) =>
21
22
  VALUE_ATTRS.has(attr) ? match : ''
22
23
  )
23
24
 
package/highlight-js.css CHANGED
@@ -1,5 +1,9 @@
1
1
  /* Codie JavaScript syntax highlighting */
2
2
 
3
+ [codie] .codie-command {
4
+ color: var(--codie-js-ident);
5
+ }
6
+
3
7
  [codie] .codie-js-keyword {
4
8
  color: var(--codie-js-keyword);
5
9
  }
package/highlight.js CHANGED
@@ -44,7 +44,7 @@ const highlightCommentVariables = (content) => {
44
44
  export const highlightJS = (code, options = {}) => {
45
45
  const tokens = [];
46
46
  const tokenRegex =
47
- /(@\[([^\]]+)\])|("(?:[^&]|&(?!quot;))*?")|('(?:[^'\\]|\\.)*')|(`(?:[^`\\]|\\.)*`)|(\/\/[^\n]*)|(\/\*[\s\S]*?\*\/)|(\$\.([a-zA-Z_][a-zA-Z0-9_]*))|(\b\d+\.?\d*\b)|(\b[a-zA-Z_][a-zA-Z0-9_]*\b)|([^\s])/g;
47
+ /(@\[([^\]]+)\])|(&quot;(?:[^&]|&(?!quot;))*?&quot;)|('(?:[^'\\]|\\.)*')|(`(?:[^`\\]|\\.)*`)|((?<=^|\s)(?:\/\/|#)[^\n]*)|(\/\*[\s\S]*?\*\/)|(\$\.([a-zA-Z_][a-zA-Z0-9_]*))|(\b\d[\d_]*(?:\.[\d_]+)?\b)|(\b[a-zA-Z_][a-zA-Z0-9_]*\b)|([^\s])/g;
48
48
  let match,
49
49
  lastIndex = 0;
50
50
 
@@ -112,8 +112,10 @@ export const highlightJS = (code, options = {}) => {
112
112
  // JavaScript highlighter for raw (unescaped) content
113
113
  export const highlightJSRaw = (code) => {
114
114
  const tokens = [];
115
+ // A command line: a bare lowercase word then arguments, on one full row — no JS
116
+ // keyword lead, no assignment/call/statement characters, no trailing continuation \
115
117
  const tokenRegex =
116
- /(<\/?[a-zA-Z][a-zA-Z0-9-]*(?:\s+[^>]*)?>)|("(?:[^"\\]|\\.)*")|('(?:[^'\\]|\\.)*')|(`(?:[^`\\]|\\.)*`)|(\/\/[^\n]*)|(\/\*[\s\S]*?\*\/)|(\$\.([a-zA-Z_][a-zA-Z0-9_]*))|(\b\d+\.?\d*\b)|(\b[a-zA-Z_][a-zA-Z0-9_]*\b)|([^\s])/g;
118
+ /(^[ \t]*(?!(?:import|export|const|let|var|return|await|async|function|if|else|for|while|new|typeof|throw)\b)[a-z][\w.-]*[ \t]+[^\n=(){};]*[^\n\\=(){};])$|(<\/?[a-zA-Z][a-zA-Z0-9-]*(?:\s+[^>]*)?>)|("(?:[^"\\]|\\.)*")|('(?:[^'\\]|\\.)*')|(`(?:[^`\\]|\\.)*`)|((?<=^|\s)(?:\/\/|#)[^\n]*)|(\/\*[\s\S]*?\*\/)|(\$\.([a-zA-Z_][a-zA-Z0-9_]*))|(\b\d[\d_]*(?:\.[\d_]+)?\b)|(\b[a-zA-Z_][a-zA-Z0-9_]*\b)|([^\s])/gm;
117
119
  let match,
118
120
  lastIndex = 0;
119
121
 
@@ -122,6 +124,7 @@ export const highlightJSRaw = (code) => {
122
124
 
123
125
  const [
124
126
  full,
127
+ commandLine,
125
128
  htmlTag,
126
129
  dblStr,
127
130
  sglStr,
@@ -136,7 +139,9 @@ export const highlightJSRaw = (code) => {
136
139
  ] = match;
137
140
  const escaped = escapeHTML(full);
138
141
 
139
- if (htmlTag) {
142
+ if (commandLine) {
143
+ tokens.push(span(CLASS.COMMAND, escaped));
144
+ } else if (htmlTag) {
140
145
  const tagMatch = full.match(/^(<\/?)([a-zA-Z][a-zA-Z0-9-]*)([\s\S]*?)(>)$/);
141
146
  if (tagMatch) {
142
147
  const [, open, tagName, attrs, close] = tagMatch;
@@ -324,21 +329,25 @@ export const highlightHTML = (
324
329
  span(CLASS.COMMENT, `&lt;!--${highlightCommentVariables(content)}--&gt;`),
325
330
  );
326
331
 
327
- // HTML tags with attributes
332
+ // HTML tags with attributes (attribute names can be @[...] name bindings)
328
333
  highlighted = highlighted.replace(
329
- /(&lt;\/?)([a-zA-Z0-9\-]+)((?:\s+[a-zA-Z0-9\-:]+(?:=(?:&quot;(?:(?!&quot;).)*?&quot;|'[^']*'|[^\s&gt;]+))?)*\s*)(\/?\s*&gt;)/gs,
334
+ /(&lt;\/?)([a-zA-Z0-9\-]+)((?:\s+(?:[a-zA-Z0-9\-:]+|@\[[^\]]+\])(?:=(?:&quot;(?:(?!&quot;).)*?&quot;|'[^']*'|[^\s&gt;]+))?)*\s*)(\/?\s*&gt;)/gs,
330
335
  (fullMatch, open, tag, attrs, close) => {
331
336
  let result = span(CLASS.PUNCTUATION, open) + span(CLASS.TAG, tag);
332
337
 
333
338
  if (attrs) {
334
339
  if (attrs.trim()) {
335
340
  const attrRegex =
336
- /([a-zA-Z0-9\-:]+)(=(?:&quot;((?:(?!&quot;).)*?)&quot;|'([^']*)'|([^\s&gt;]+)))?/gs;
341
+ /([a-zA-Z0-9\-:]+|@\[[^\]]+\])(=(?:&quot;((?:(?!&quot;).)*?)&quot;|'([^']*)'|([^\s&gt;]+)))?/gs;
337
342
  let attrMatch,
338
343
  last = 0;
339
344
 
340
345
  while ((attrMatch = attrRegex.exec(attrs)) !== null) {
341
- result += attrs.substring(last, attrMatch.index) + span(CLASS.ATTR_NAME, attrMatch[1]);
346
+ result +=
347
+ attrs.substring(last, attrMatch.index) +
348
+ (attrMatch[1].startsWith('@[')
349
+ ? highlightBindings(attrMatch[1])
350
+ : span(CLASS.ATTR_NAME, attrMatch[1]));
342
351
 
343
352
  if (attrMatch[2]) {
344
353
  result += span(CLASS.PUNCTUATION, '=');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ape-egg/codie",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "Modular code display and editing package",
5
5
  "type": "module",
6
6
  "main": "codie.js",
@@ -21,6 +21,9 @@
21
21
  "syntax-highlighting",
22
22
  "code-display"
23
23
  ],
24
- "author": "kortes",
25
- "license": "MIT"
24
+ "author": "kkortes",
25
+ "license": "ISC",
26
+ "publishConfig": {
27
+ "access": "public"
28
+ }
26
29
  }
package/structure.css CHANGED
@@ -50,6 +50,9 @@
50
50
  min-height: 100%;
51
51
  border: none;
52
52
  outline: none;
53
+ box-shadow: none;
54
+ border-radius: 0;
55
+ background: none;
53
56
  resize: none;
54
57
  overflow: hidden;
55
58
  color: transparent;