ts-highlight 1.1.2 → 2.1.0

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/README.md CHANGED
@@ -32,8 +32,8 @@ const cssClasses: HiglightCSSClasses = {
32
32
  keyword: 'keyword',
33
33
 
34
34
  bigintChar: 'bigint-class', // class of bigint character (`10n` - `n` is `bigintChar`)
35
- stringLiteral: 'string',
36
35
 
36
+ string: 'string',
37
37
  whitespace: 'whitespace', // even whitespace has its own class
38
38
 
39
39
  ...
package/dist/index.css CHANGED
@@ -1 +1 @@
1
- .pre__0GF8gk{font-family:monospace;font-size:1rem;margin:0}.line__TpOVfj{cursor:text;line-height:1.25rem}
1
+ .pre__0GF8gk{margin:0}.line__TpOVfj{cursor:text;line-height:1.25rem}
package/dist/index.d.ts CHANGED
@@ -54,11 +54,13 @@ type HighlightCSSClasses = Partial<{
54
54
  operator: string;
55
55
  constantIdentifier: string;
56
56
  mutableIdentifier: string;
57
- numberLiteral: string;
58
- stringLiteral: string;
59
- booleanLiteral: string;
60
- NaNLiteral: string;
57
+ number: string;
58
+ string: string;
59
+ boolean: string;
60
+ NaN: string;
61
61
  bigintChar: string;
62
+ null: string;
63
+ undefined: string;
62
64
  }>;
63
65
 
64
66
  /**
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- const e=new Set(["=","+","-","*","/","%","~","^",".",":","|","&","?","!","<",">","{","}","[","]","(",")",";",","]),t=new Set(["==","!=","<=",">=","++","--","**","*=","/=","%=","^=","&=","|=","&&","||","??"]),n=new Set(["===","!==","**=","<<=",">>=",">>>","&&=","||=","??="]),o={NaN:"NaNLiteral",abstract:"Keyword",as:"Instruction",assert:"Instruction",asserts:"Instruction",async:"Instruction",await:"Instruction",break:"Instruction",catch:"Instruction",class:"Keyword",const:"Keyword",continue:"Instruction",debugger:"Keyword",declare:"Keyword",default:"Instruction",delete:"Keyword",do:"Instruction",enum:"Keyword",export:"Instruction",false:"BooleanLiteral",finally:"Instruction",for:"Instruction",function:"Keyword",implements:"Keyword",import:"Instruction",in:"Keyword",instanceof:"Keyword",interface:"Keyword",is:"Instruction",keyof:"Keyword",let:"Keyword",new:"Keyword",package:"Instruction",this:"Keyword",throw:"Instruction",true:"BooleanLiteral",try:"Instruction",type:"Keyword",typeof:"Keyword",var:"Keyword",void:"Keyword",while:"Instruction",with:"Instruction",yield:"Instruction"},r=/^[a-zA-Zа-яА-Я_$]$/,i=/^[a-zA-Zа-яА-Я_$0-9]$/,s=/^[0-9]$/;const a='<span class="',l="</span>",c="pre__0GF8gk",u="line__TpOVfj",y=(y,d)=>((e,t)=>{const n=e.length;let o='<pre class="'+c+" "+t.pre+'"><code class="'+t.code+'"><div class="'+u+" "+t.line+'">',r=0;for(;r<n;){const i=e[r];"WhiteSpace"!==i.type?"LineDivision"!==i.type?"Operator"!==i.type?"Identifier"!==i.type?"Keyword"!==i.type?"Instruction"!==i.type?"StringLiteral"!==i.type?"NumberLiteral"!==i.type?"BooleanLiteral"!==i.type?"NaNLiteral"!==i.type?("Comment"!==i.type||(o+=a+t.token+" "+t.comment+'">'+i.value+l),r++):(o+=a+t.token+" "+t.NaNLiteral+'">'+i.value+l,r++):(o+=a+t.token+" "+t.booleanLiteral+'">'+i.value+l,r++):(o+=a+t.token+" "+t.numberLiteral+'">'+i.value+l,r++):(o+=a+t.token+" "+t.stringLiteral+'">'+i.value+l,r++):(o+=a+t.token+" "+t.instruction+">"+i.value+l,r++):(o+=a+t.token+" "+t.keyword+'">'+i.value+l,r++):(o+=a+t.token+" "+t.mutableIdentifier+'">'+i.value+l,r++):(o+=a+t.token+" "+t.operator+'">'+i.value+l,r++):(o+="</div>",r!==n-1&&(o+='<div class="'+u+" "+t.line+'">'),r++):(o+=a+t.token+" "+t.whitespace+'">'+i.value+l,r++)}return o+="</div>",o+="</code></pre>",o})((a=>{const l=[],c=a.length;let u=0;e:for(;u<c;){if(" "===a[u]||"\t"===a[u]){const e=u;for(u++;u<c&&(" "===a[u]||"\t"===a[u]);)u++;l[l.length]={type:"WhiteSpace",value:a.slice(e,u),start:e,end:u};continue e}if("\n"===a[u]||"\r"===a[u]){const e=u;"\r"===a[u]&&u++,u++,l[l.length]={type:"LineDivision",value:"\n",start:e,end:u};continue e}if(r.test(a[u])){const e=u;for(u++;u<c&&i.test(a[u]);)u++;const t=a.slice(e,u);l[l.length]={type:o[t]??"Identifier",value:t,start:e,end:u};continue e}if("'"===a[u]||'"'===a[u]||"`"===a[u]){const e=u,t=a[u];for(u++;u<c&&a[u]!==t;)u++;u++,l[l.length]={type:"StringLiteral",value:a.slice(e,u),start:e,end:u};continue e}if(s.test(a[u])){const e=u;for(;u<c&&s.test(a[u]);)u++;l[l.length]={type:"NumberLiteral",value:a.slice(e,u),start:e,end:u};continue e}if("/"===a[u]){const e=u;if(u++,"/"===a[u]){for(u++;u<c&&"\r"!==a[u]&&"\n"!==a[u];)u++;"\r"===a[u]&&(u+=2),l[l.length]={type:"Comment",value:a.slice(e,u),start:e,end:u},l[l.length]={type:"LineDivision",value:"\n",start:e,end:u};continue e}if("*"===a[u]){u++;let t=e;for(;u<c&&("*"!==a[u]||"/"!==a[u+1]);)"\n"!==a[u]&&"\r"!==a[u]||(l[l.length]={type:"Comment",value:a.slice(t,u),start:e,end:u},l[l.length]={type:"LineDivision",value:"\n",start:u,end:u+1},"\r"===a[u]&&u++,u++,t=u),u++;u+=2,l[l.length]={type:"Comment",value:a.slice(t,u),start:e,end:u};continue e}}if(a[u]+a[u+1]+a[u+2]+a[u+3]===">>>="){const e=u;u+=4,l[l.length]={type:"Operator",value:a.slice(e,u),start:e,end:u};continue e}if(n.has(a[u]+a[u+1]+a[u+2])){const e=u;u+=3,l[l.length]={type:"Operator",value:a.slice(e,u),start:e,end:u};continue e}if(t.has(a[u]+a[u+1])){const e=u;u+=2,l[l.length]={type:"Operator",value:a.slice(e,u),start:e,end:u};continue e}if(e.has(a[u])){const e=u;u++,l[l.length]={type:"Operator",value:a.slice(e,u),start:e,end:u};continue e}u++}return l})(y),d);export{y as highlight};
1
+ const e=new Set(["=","+","-","*","/","%","~","^",".",":","|","&","?","!","<",">","{","}","[","]","(",")",";",","]),t=new Set(["==","!=","<=",">=","++","--","**","*=","/=","%=","^=","&=","|=","&&","||","??"]),n=new Set(["===","!==","**=","<<=",">>=",">>>","&&=","||=","??="]),o={NaN:"NaNLiteral",false:"BooleanLiteral",true:"BooleanLiteral",null:"NullLiteral",undefined:"UndefinedLiteral",abstract:"Keyword",class:"Keyword",const:"Keyword",declare:"Keyword",enum:"Keyword",function:"Keyword",implements:"Keyword",in:"Keyword",instanceof:"Keyword",interface:"Keyword",keyof:"Keyword",let:"Keyword",new:"Keyword",this:"Keyword",type:"Keyword",typeof:"Keyword",var:"Keyword",void:"Keyword",debugger:"Keyword",as:"Instruction",assert:"Instruction",asserts:"Instruction",async:"Instruction",await:"Instruction",break:"Instruction",catch:"Instruction",continue:"Instruction",default:"Instruction",delete:"Instruction",do:"Instruction",export:"Instruction",finally:"Instruction",for:"Instruction",from:"Instruction",import:"Instruction",is:"Instruction",package:"Instruction",return:"Instruction",throw:"Instruction",try:"Instruction",while:"Instruction",with:"Instruction",yield:"Instruction"},r=/^[a-zA-Zа-яА-Я_$]$/,i=/^[a-zA-Zа-яА-Я_$0-9]$/,s=/^[0-9]$/;const a='<span class="',l="</span>",c="pre__0GF8gk",u="line__TpOVfj",d=(d,y)=>((e,t)=>{const n=e.length;let o='<pre class="'+c+" "+t.pre+'"><code class="'+t.code+'"><div class="'+u+" "+t.line+'">',r=0;for(;r<n;){const i=e[r];"WhiteSpace"!==i.type?"LineDivision"!==i.type?"Operator"!==i.type?"Identifier"!==i.type?"Keyword"!==i.type?"Instruction"!==i.type?"StringLiteral"!==i.type?"NumberLiteral"!==i.type?"BooleanLiteral"!==i.type?"NaNLiteral"!==i.type?"UndefinedLiteral"!==i.type?"NullLiteral"!==i.type?("Comment"!==i.type||(o+=a+t.token+" "+t.comment+'">'+i.value+l),r++):(o+=a+t.token+" "+t.null+'">'+i.value+l,r++):(o+=a+t.token+" "+t.undefined+'">'+i.value+l,r++):(o+=a+t.token+" "+t.NaN+'">'+i.value+l,r++):(o+=a+t.token+" "+t.boolean+'">'+i.value+l,r++):(o+=a+t.token+" "+t.number+'">'+i.value,r++,"n"===e[r].value&&(o+=l+a+t.token+" "+t.bigintChar+'">'+e[r].value),o+=l):(o+=a+t.token+" "+t.string+'">'+i.value+l,r++):(o+=a+t.token+" "+t.instruction+'">'+i.value+l,r++):(o+=a+t.token+" "+t.keyword+'">'+i.value+l,r++):(o+=a+t.token+" "+t.mutableIdentifier+'">'+i.value+l,r++):(o+=a+t.token+" "+t.operator+'">'+i.value+l,r++):(o+=" </div>",o+='<div class="'+u+" "+t.line+'">',r===n-1&&(o+=" </div>"),r++):(o+=a+t.token+" "+t.whitespace+'">'+i.value+l,r++)}return o+="</div></code></pre>",o})((a=>{const l=[],c=a.length;let u=0;e:for(;u<c;){if(" "===a[u]||"\t"===a[u]){const e=u;for(u++;u<c&&(" "===a[u]||"\t"===a[u]);)u++;l[l.length]={type:"WhiteSpace",value:a.slice(e,u),start:e,end:u};continue e}if("\n"===a[u]||"\r"===a[u]){const e=u;"\r"===a[u]&&u++,u++,l[l.length]={type:"LineDivision",value:"",start:e,end:u};continue e}if(r.test(a[u])){const e=u;for(u++;u<c&&i.test(a[u]);)u++;const t=a.slice(e,u);l[l.length]={type:o[t]??"Identifier",value:t,start:e,end:u};continue e}if("'"===a[u]||'"'===a[u]||"`"===a[u]){const e=u,t=a[u];for(u++;u<c&&a[u]!==t;)u++;u++,l[l.length]={type:"StringLiteral",value:a.slice(e,u),start:e,end:u};continue e}if(s.test(a[u])){const e=u;for(;u<c&&s.test(a[u]);)u++;l[l.length]={type:"NumberLiteral",value:a.slice(e,u),start:e,end:u};continue e}if("/"===a[u]){const e=u;if(u++,"/"===a[u]){for(u++;u<c&&"\r"!==a[u]&&"\n"!==a[u];)u++;"\r"===a[u]&&(u+=2),l[l.length]={type:"Comment",value:a.slice(e,u),start:e,end:u},l[l.length]={type:"LineDivision",value:"\n",start:e,end:u};continue e}if("*"===a[u]){u++;let t=e;for(;u<c&&("*"!==a[u]||"/"!==a[u+1]);)"\n"!==a[u]&&"\r"!==a[u]||(l[l.length]={type:"Comment",value:a.slice(t,u),start:e,end:u},l[l.length]={type:"LineDivision",value:"\n",start:u,end:u+1},"\r"===a[u]&&u++,u++,t=u),u++;u+=2,l[l.length]={type:"Comment",value:a.slice(t,u),start:e,end:u};continue e}}if(a[u]+a[u+1]+a[u+2]+a[u+3]===">>>="){const e=u;u+=4,l[l.length]={type:"Operator",value:a.slice(e,u),start:e,end:u};continue e}if(n.has(a[u]+a[u+1]+a[u+2])){const e=u;u+=3,l[l.length]={type:"Operator",value:a.slice(e,u),start:e,end:u};continue e}if(t.has(a[u]+a[u+1])){const e=u;u+=2,l[l.length]={type:"Operator",value:a.slice(e,u),start:e,end:u};continue e}if(e.has(a[u])){const e=u;u++,l[l.length]={type:"Operator",value:a.slice(e,u),start:e,end:u};continue e}u++}return l})(d),y);export{d as highlight};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ts-highlight",
3
- "version": "1.1.2",
3
+ "version": "2.1.0",
4
4
  "module": "./dist/index.js",
5
5
  "type": "module",
6
6
  "private": false,