ts-highlight 0.4.0 → 1.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
@@ -36,7 +36,6 @@ const cssClasses: HiglightCSSClasses = {
36
36
 
37
37
  whitespace: 'whitespace', // even whitespace has its own class
38
38
 
39
-
40
39
  ...
41
40
  };
42
41
 
package/dist/index.css ADDED
@@ -0,0 +1 @@
1
+ .pre__0GF8gk{font-family:monospace;font-size:1rem;margin:0}.line__TpOVfj{cursor:text;line-height:1.25rem}
package/dist/index.d.ts CHANGED
@@ -79,6 +79,7 @@ type HighlightCSSClasses = Partial<{
79
79
  * code: 'my-code-element-class',
80
80
  *
81
81
  * line: 'line-class my-line third-class',
82
+ *
82
83
  * token: 'token-class',
83
84
  *
84
85
  * operator: 'operator-class',
@@ -86,6 +87,7 @@ type HighlightCSSClasses = Partial<{
86
87
  * keyword: 'keyword-class',
87
88
  * stringLiteral: 'string-class',
88
89
  *
90
+ *
89
91
  * ...
90
92
  * }
91
93
  *
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]$/,a='<span class="',l="</span>",c=(c,u)=>{const y=(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})(c),d=((e,t)=>{const n=e.length;let o='<pre class="'+t.pre+'"><code class="'+t.code+'"><div class="'+t.line+'">',r=!0,i=0;for(;i<n;){const s=e[i];if("WhiteSpace"===s.type){o+=a+t.token+" "+t.whitespace+'">';let e=0;for(;e<s.value.length;)o+=" ",e++;o+=l,i++;continue}"LineDivision"!==s.type?"Operator"!==s.type?"Identifier"!==s.type?"Keyword"!==s.type?"Instruction"!==s.type?"StringLiteral"!==s.type?"NumberLiteral"!==s.type?"BooleanLiteral"!==s.type?"NaNLiteral"!==s.type?("Comment"!==s.type||(o+=a+t.token+" "+t.comment+'">'+s.value+l),i++):(o+=a+t.token+" "+t.NaNLiteral+'">'+s.value+l,i++):(o+=a+t.token+" "+t.booleanLiteral+'">'+s.value+l,i++):(o+=a+t.token+" "+t.numberLiteral+'">'+s.value+l,i++):(o+=a+t.token+" "+t.stringLiteral+'">'+s.value+l,i++):(o+=a+t.token+" "+t.instruction+">"+s.value+l,i++):(o+=a+t.token+" "+t.keyword+'">'+s.value+l,i++):(o+=a+t.token+" "+t.mutableIdentifier+'">'+s.value+l,i++):(o+=a+t.token+" "+t.operator+'">'+s.value+l,i++):(o+="</div>",i!==n-1&&(o+='<div class="'+t.line+'">',r=!1),i++)}return r&&(o+="</div>"),o+="</code></pre>",o})(y,u);return d};export{c as highlight};
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};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ts-highlight",
3
- "version": "0.4.0",
3
+ "version": "1.1.0",
4
4
  "module": "./dist/index.js",
5
5
  "type": "module",
6
6
  "private": false,
@@ -9,23 +9,31 @@
9
9
  "name": "marigold",
10
10
  "url": "https://github.com/a-marigold"
11
11
  },
12
- "repository": {
13
- "type": "github",
14
- "url": "https://github.com/a-marigold/ts-highlight"
15
- },
16
12
  "scripts": {
17
13
  "lint": "biome check",
18
14
  "build": "rollup -c",
19
15
  "prepublishOnly": "bun run build",
20
16
  "pshPub": "bun publish --access public"
21
17
  },
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "https://github.com/a-marigold/ts-highlight"
21
+ },
22
22
  "main": "./dist/index.js",
23
23
  "types": "./dist/index.d.ts",
24
24
  "readme": "./README.md",
25
+ "maintainers": [
26
+ {
27
+ "name": "marigold",
28
+ "url": "https://github.com/a-marigold"
29
+ }
30
+ ],
25
31
  "keywords": [
26
32
  "ts-higlight",
27
33
  "higlight",
28
- "syntax-higlight"
34
+ "syntax-higlight",
35
+ "highlighter",
36
+ "themes"
29
37
  ],
30
38
  "files": [
31
39
  "dist"
@@ -35,9 +43,13 @@
35
43
  "@rollup/plugin-terser": "^0.4.4",
36
44
  "@rollup/plugin-typescript": "^12.3.0",
37
45
  "@types/bun": "latest",
46
+ "postcss": "^8.5.6",
47
+ "postcss-modules": "^6.0.1",
38
48
  "rollup": "^4.54.0",
39
49
  "rollup-plugin-dts": "^6.3.0",
40
- "tslib": "^2.8.1"
50
+ "rollup-plugin-postcss": "^4.0.2",
51
+ "tslib": "^2.8.1",
52
+ "typescript-plugin-css-modules": "^5.2.0"
41
53
  },
42
54
  "peerDependencies": {
43
55
  "typescript": "^5"