@ansi-tools/parser 1.0.13 → 1.0.14

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.
Files changed (48) hide show
  1. package/dist/escaped.d.ts +10 -6
  2. package/dist/escaped.js +1 -4
  3. package/dist/index.d.ts +7 -5
  4. package/dist/index.js +1 -3
  5. package/dist/parse-BXzmEfiO.d.ts +85 -0
  6. package/dist/parse-DOrPQ1A8.js +1 -0
  7. package/package.json +6 -4
  8. package/dist/constants.d.ts +0 -56
  9. package/dist/constants.d.ts.map +0 -1
  10. package/dist/constants.js +0 -55
  11. package/dist/escaped.d.ts.map +0 -1
  12. package/dist/index.d.ts.map +0 -1
  13. package/dist/parse.d.ts +0 -4
  14. package/dist/parse.d.ts.map +0 -1
  15. package/dist/parse.escaped.d.ts +0 -3
  16. package/dist/parse.escaped.d.ts.map +0 -1
  17. package/dist/parse.escaped.js +0 -5
  18. package/dist/parse.js +0 -109
  19. package/dist/parsers/apc.d.ts +0 -3
  20. package/dist/parsers/apc.d.ts.map +0 -1
  21. package/dist/parsers/apc.js +0 -6
  22. package/dist/parsers/csi.d.ts +0 -3
  23. package/dist/parsers/csi.d.ts.map +0 -1
  24. package/dist/parsers/csi.js +0 -63
  25. package/dist/parsers/dcs.d.ts +0 -3
  26. package/dist/parsers/dcs.d.ts.map +0 -1
  27. package/dist/parsers/dcs.js +0 -26
  28. package/dist/parsers/esc.d.ts +0 -3
  29. package/dist/parsers/esc.d.ts.map +0 -1
  30. package/dist/parsers/esc.js +0 -8
  31. package/dist/parsers/osc.d.ts +0 -3
  32. package/dist/parsers/osc.d.ts.map +0 -1
  33. package/dist/parsers/osc.js +0 -28
  34. package/dist/parsers/pm.d.ts +0 -3
  35. package/dist/parsers/pm.d.ts.map +0 -1
  36. package/dist/parsers/pm.js +0 -6
  37. package/dist/parsers/sos.d.ts +0 -3
  38. package/dist/parsers/sos.d.ts.map +0 -1
  39. package/dist/parsers/sos.js +0 -6
  40. package/dist/tokenize.d.ts +0 -4
  41. package/dist/tokenize.d.ts.map +0 -1
  42. package/dist/tokenize.escaped.d.ts +0 -4
  43. package/dist/tokenize.escaped.d.ts.map +0 -1
  44. package/dist/tokenize.escaped.js +0 -295
  45. package/dist/tokenize.js +0 -314
  46. package/dist/types.d.ts +0 -23
  47. package/dist/types.d.ts.map +0 -1
  48. package/dist/types.js +0 -1
package/dist/escaped.d.ts CHANGED
@@ -1,6 +1,10 @@
1
- export * from "./constants.ts";
2
- export { parse } from "./parse.escaped.ts";
3
- export { parser } from "./parse.ts";
4
- export { tokenize, tokenizer } from "./tokenize.escaped.ts";
5
- export type { CODE, CONTROL_CODE, TEXT, TOKEN } from "./types.ts";
6
- //# sourceMappingURL=escaped.d.ts.map
1
+ import { A as OSC_CODE, B as SOS_OPEN, C as DCS_CODE, D as ESC_CODE, E as ESC, F as PM_CODE, G as SUB_CODE, H as STRING_OPENERS, I as PM_OPEN, K as TOKEN_TYPES, L as PRIVATE_OPENERS, M as OSC_OPEN_CODE, N as PARAM_SEPARATOR, O as INTERRUPTERS, P as PM, R as SOS, S as DCS, T as DEC_OPEN, U as ST_CODE, V as ST, W as SUB, _ as CODE_TYPES, a as TEXT, b as CSI_OPEN, c as APC_CODE, d as BACKSLASH_CODE, f as BELL, g as CAN_CODE, h as CAN, i as CONTROL_CODE, j as OSC_OPEN, k as OSC, l as APC_OPEN, m as C0_INTERRUPTERS, n as parser, o as TOKEN, p as BELL_CODE, r as CODE, s as APC, u as BACKSLASH, v as CSI, w as DCS_OPEN, x as CSI_OPEN_CODE, y as CSI_CODE, z as SOS_CODE } from "./parse-BXzmEfiO.js";
2
+
3
+ //#region src/parse.escaped.d.ts
4
+ declare function parse(input: string): CODE[];
5
+ //#endregion
6
+ //#region src/tokenize.escaped.d.ts
7
+ declare function tokenizer(input: string): IterableIterator<TOKEN>;
8
+ declare function tokenize(input: string): TOKEN[];
9
+ //#endregion
10
+ export { APC, APC_CODE, APC_OPEN, BACKSLASH, BACKSLASH_CODE, BELL, BELL_CODE, C0_INTERRUPTERS, CAN, CAN_CODE, type CODE, CODE_TYPES, type CONTROL_CODE, CSI, CSI_CODE, CSI_OPEN, CSI_OPEN_CODE, DCS, DCS_CODE, DCS_OPEN, DEC_OPEN, ESC, ESC_CODE, INTERRUPTERS, OSC, OSC_CODE, OSC_OPEN, OSC_OPEN_CODE, PARAM_SEPARATOR, PM, PM_CODE, PM_OPEN, PRIVATE_OPENERS, SOS, SOS_CODE, SOS_OPEN, ST, STRING_OPENERS, ST_CODE, SUB, SUB_CODE, type TEXT, type TOKEN, TOKEN_TYPES, parse, parser, tokenize, tokenizer };
package/dist/escaped.js CHANGED
@@ -1,4 +1 @@
1
- export * from "./constants.js";
2
- export { parse } from "./parse.escaped.js";
3
- export { parser } from "./parse.js";
4
- export { tokenize, tokenizer } from "./tokenize.escaped.js";
1
+ import{A as e,B as t,C as n,D as r,E as i,F as a,H as o,I as s,L as c,M as l,N as u,O as d,P as f,R as p,S as m,T as h,U as g,V as _,W as v,_ as y,a as b,b as x,c as S,d as C,f as w,g as T,h as E,j as D,k as O,l as k,m as A,n as j,o as M,p as N,s as P,u as F,v as I,w as L,x as R,y as z,z as B}from"./parse-DOrPQ1A8.js";const V=`\\u009b`,H=`\\x9b`,U=`ABANDONED`,W=[[`\\u001b`,6],[V,6],[H,4],[`\\x1b`,4],[`\\033`,4],[`\\e`,2]],G=[[`\\x18`,4],[`\\x1a`,4],[`\\u0018`,6],[`\\u001a`,6]],K=new Map;for(let[e,t]of G){let n=e[1];K.has(n)||K.set(n,[]),K.get(n)?.push([e,t])}const q=new Map,J=new Map;for(let[e,t]of W){let n=e[1];q.has(n)||q.set(n,[]),q.get(n)?.push([e,t]),J.set(e,!0)}function Y(e){return e}function*X(n){let i=n.length,a=0,o=`GROUND`,s,c=n.indexOf(k);function l(e,t){o=e,s=t}for(;a<i;)if(o===`GROUND`){let o=a;for(;a<i;){if(c===-1){a=i;break}if(c<a&&(c=n.indexOf(k,a)),c===-1){a=i;break}let e=!1,t=q.get(n[c+1]);if(t){for(let[r,a]of t)if(!(c+a>i)&&n.startsWith(r,c)){e=!0;break}}if(e){a=c;break}else a=c+1}if(a>o&&(yield Y({type:v.TEXT,pos:o,raw:n.substring(o,a)})),a<i){let o=q.get(n[a+1]);if(o){let s=!1;for(let[c,u]of o)if(!(a+u>i)&&n.startsWith(c,a)){if(s=!0,c===V||c===H)yield Y({type:v.INTRODUCER,pos:a,raw:c,code:y}),a+=u,l(`SEQUENCE`,T);else{let o=n[a+u];if(o===z)yield Y({type:v.INTRODUCER,pos:a,raw:c+o,code:y}),a+=u+1,l(`SEQUENCE`,T);else if(o===e)yield Y({type:v.INTRODUCER,pos:a,raw:c+o,code:d}),a+=u+1,l(`SEQUENCE`,r);else if(t.has(o))yield Y({type:v.INTRODUCER,pos:a,raw:c+o,code:o}),a+=u+1,l(`SEQUENCE`,o.charCodeAt(0));else if(o){let e=a+u;for(;e<i&&n.charCodeAt(e)>=32&&n.charCodeAt(e)<=47;)e++;if(e<i){let t=n.slice(a+u,e);t?yield Y({type:v.INTRODUCER,pos:a,raw:c+t,code:h,intermediate:t}):yield Y({type:v.INTRODUCER,pos:a,raw:c,code:h}),a=e,l(`SEQUENCE`,L)}else a=e}else a+=u}break}s||a++}else a++}}else if(o===`SEQUENCE`){let e=``,t=-1,o=a;for(;!e&&a<i;){if(n.charCodeAt(a)===S){let o=n[a+1];if(o){let r=K.get(o);if(r){for(let[o,s]of r)if(a+s<=i){let r=!0;for(let e=0;e<s;e++)if(n[a+e]!==o[e]){r=!1;break}if(r){e=U,t=a,a+=s;break}}}}if(e)break;if(s!==T&&s!==L)if(o===`a`&&a+2<=i)s===r&&n[a+1]===`a`&&(e=`\\a`,t=a,a+=2);else if(o===`x`){if(a+4<=i){let o=n[a+2],c=n[a+3];o===`0`&&c===`7`&&s===r?(e=`\\x07`,t=a,a+=4):o===`9`&&c===`c`?(e=`\\x9c`,t=a,a+=4):o===`1`&&c===`b`&&a+6<=i&&n.charCodeAt(a+4)===S&&n.charCodeAt(a+5)===S&&(e=`\\x1b\\\\`,t=a,a+=6)}}else o===`u`&&s===r&&a+6<=i?n[a+2]===`0`&&n[a+3]===`0`&&n[a+4]===`0`&&n[a+5]===`7`&&(e=`\\u0007`,t=a,a+=6):o===`e`&&a+4<=i&&n.charCodeAt(a+2)===S&&n.charCodeAt(a+3)===S&&(e=`\\e\\\\`,t=a,a+=4);if(!e&&o){let r=q.get(o);if(r)for(let[o,s]of r){if(a+s>i)continue;let r=!0;for(let e=0;e<s&&r;e+=2)r=n[a+e]===o[e],r&&e+1<s&&(r=n[a+e+1]===o[e+1]);if(r){e=U,t=a;break}}}}else if(s===T){let r=n.charCodeAt(a);r>=64&&r<=126&&(e=n[a],t=a,a++)}else s===L&&(e=n[a],t=a,a++);e||a++}t>o&&(yield Y({type:v.DATA,pos:o,raw:n.substring(o,t)})),e&&e!==U&&(yield Y({type:v.FINAL,pos:t,raw:e})),l(`GROUND`)}}function Z(e){return Array.from(X(e))}function Q(e){return Array.from(j(X(e)))}export{b as APC,M as APC_CODE,P as APC_OPEN,S as BACKSLASH,k as BACKSLASH_CODE,F as BELL,C as BELL_CODE,w as C0_INTERRUPTERS,N as CAN,A as CAN_CODE,E as CODE_TYPES,T as CSI,y as CSI_CODE,I as CSI_OPEN,z as CSI_OPEN_CODE,x as DCS,R as DCS_CODE,m as DCS_OPEN,n as DEC_OPEN,L as ESC,h as ESC_CODE,i as INTERRUPTERS,r as OSC,d as OSC_CODE,O as OSC_OPEN,e as OSC_OPEN_CODE,D as PARAM_SEPARATOR,l as PM,u as PM_CODE,f as PM_OPEN,a as PRIVATE_OPENERS,s as SOS,c as SOS_CODE,p as SOS_OPEN,B as ST,t as STRING_OPENERS,_ as ST_CODE,o as SUB,g as SUB_CODE,v as TOKEN_TYPES,Q as parse,j as parser,Z as tokenize,X as tokenizer};
package/dist/index.d.ts CHANGED
@@ -1,5 +1,7 @@
1
- export * from "./constants.ts";
2
- export { parse, parser } from "./parse.ts";
3
- export { tokenize, tokenizer } from "./tokenize.ts";
4
- export type { CODE, CONTROL_CODE, TEXT, TOKEN } from "./types.ts";
5
- //# sourceMappingURL=index.d.ts.map
1
+ import { A as OSC_CODE, B as SOS_OPEN, C as DCS_CODE, D as ESC_CODE, E as ESC, F as PM_CODE, G as SUB_CODE, H as STRING_OPENERS, I as PM_OPEN, K as TOKEN_TYPES, L as PRIVATE_OPENERS, M as OSC_OPEN_CODE, N as PARAM_SEPARATOR, O as INTERRUPTERS, P as PM, R as SOS, S as DCS, T as DEC_OPEN, U as ST_CODE, V as ST, W as SUB, _ as CODE_TYPES, a as TEXT, b as CSI_OPEN, c as APC_CODE, d as BACKSLASH_CODE, f as BELL, g as CAN_CODE, h as CAN, i as CONTROL_CODE, j as OSC_OPEN, k as OSC, l as APC_OPEN, m as C0_INTERRUPTERS, n as parser, o as TOKEN, p as BELL_CODE, r as CODE, s as APC, t as parse, u as BACKSLASH, v as CSI, w as DCS_OPEN, x as CSI_OPEN_CODE, y as CSI_CODE, z as SOS_CODE } from "./parse-BXzmEfiO.js";
2
+
3
+ //#region src/tokenize.d.ts
4
+ declare function tokenizer(input: string): IterableIterator<TOKEN>;
5
+ declare function tokenize(input: string): TOKEN[];
6
+ //#endregion
7
+ export { APC, APC_CODE, APC_OPEN, BACKSLASH, BACKSLASH_CODE, BELL, BELL_CODE, C0_INTERRUPTERS, CAN, CAN_CODE, type CODE, CODE_TYPES, type CONTROL_CODE, CSI, CSI_CODE, CSI_OPEN, CSI_OPEN_CODE, DCS, DCS_CODE, DCS_OPEN, DEC_OPEN, ESC, ESC_CODE, INTERRUPTERS, OSC, OSC_CODE, OSC_OPEN, OSC_OPEN_CODE, PARAM_SEPARATOR, PM, PM_CODE, PM_OPEN, PRIVATE_OPENERS, SOS, SOS_CODE, SOS_OPEN, ST, STRING_OPENERS, ST_CODE, SUB, SUB_CODE, type TEXT, type TOKEN, TOKEN_TYPES, parse, parser, tokenize, tokenizer };
package/dist/index.js CHANGED
@@ -1,3 +1 @@
1
- export * from "./constants.js";
2
- export { parse, parser } from "./parse.js";
3
- export { tokenize, tokenizer } from "./tokenize.js";
1
+ import{A as e,B as t,C as n,D as r,E as i,F as a,H as o,I as s,L as c,M as l,N as u,O as d,P as f,R as p,S as m,T as h,U as g,V as _,W as v,_ as y,a as b,b as x,c as S,d as C,f as w,g as T,h as E,i as D,j as O,k,l as A,m as j,n as M,o as N,p as P,r as F,s as I,t as L,u as R,v as z,w as B,x as V,y as H,z as U}from"./parse-DOrPQ1A8.js";export{b as APC,N as APC_CODE,I as APC_OPEN,S as BACKSLASH,A as BACKSLASH_CODE,R as BELL,C as BELL_CODE,w as C0_INTERRUPTERS,P as CAN,j as CAN_CODE,E as CODE_TYPES,T as CSI,y as CSI_CODE,z as CSI_OPEN,H as CSI_OPEN_CODE,x as DCS,V as DCS_CODE,m as DCS_OPEN,n as DEC_OPEN,B as ESC,h as ESC_CODE,i as INTERRUPTERS,r as OSC,d as OSC_CODE,k as OSC_OPEN,e as OSC_OPEN_CODE,O as PARAM_SEPARATOR,l as PM,u as PM_CODE,f as PM_OPEN,a as PRIVATE_OPENERS,s as SOS,c as SOS_CODE,p as SOS_OPEN,U as ST,t as STRING_OPENERS,_ as ST_CODE,o as SUB,g as SUB_CODE,v as TOKEN_TYPES,L as parse,M as parser,F as tokenize,D as tokenizer};
@@ -0,0 +1,85 @@
1
+ //#region src/constants.d.ts
2
+ declare const BELL = 7;
3
+ declare const BELL_CODE: string;
4
+ declare const CAN = 24;
5
+ declare const CAN_CODE: string;
6
+ declare const SUB = 26;
7
+ declare const SUB_CODE: string;
8
+ declare const ESC = 27;
9
+ declare const ESC_CODE: string;
10
+ declare const BACKSLASH = 92;
11
+ declare const BACKSLASH_CODE: string;
12
+ declare const DCS = 144;
13
+ declare const DCS_CODE: string;
14
+ declare const SOS = 152;
15
+ declare const SOS_CODE: string;
16
+ declare const CSI = 155;
17
+ declare const CSI_CODE: string;
18
+ declare const ST = 156;
19
+ declare const ST_CODE: string;
20
+ declare const OSC = 157;
21
+ declare const OSC_CODE: string;
22
+ declare const PM = 158;
23
+ declare const PM_CODE: string;
24
+ declare const APC = 159;
25
+ declare const APC_CODE: string;
26
+ declare const CSI_OPEN: number;
27
+ declare const CSI_OPEN_CODE: string;
28
+ declare const OSC_OPEN: number;
29
+ declare const OSC_OPEN_CODE: string;
30
+ declare const DEC_OPEN: number;
31
+ declare const PRIVATE_OPENERS: Set<string>;
32
+ declare const DCS_OPEN = "P";
33
+ declare const APC_OPEN = "_";
34
+ declare const SOS_OPEN = "^";
35
+ declare const PM_OPEN = "X";
36
+ declare const STRING_OPENERS: Set<string>;
37
+ declare const INTERRUPTERS: Set<number>;
38
+ declare const C0_INTERRUPTERS: Set<number>;
39
+ declare const PARAM_SEPARATOR: RegExp;
40
+ declare const TOKEN_TYPES: {
41
+ readonly TEXT: "TEXT";
42
+ readonly INTRODUCER: "INTRODUCER";
43
+ readonly DATA: "DATA";
44
+ readonly FINAL: "FINAL";
45
+ };
46
+ declare const CODE_TYPES: {
47
+ readonly CSI: "CSI";
48
+ readonly DCS: "DCS";
49
+ readonly DEC: "DEC";
50
+ readonly ESC: "ESC";
51
+ readonly OSC: "OSC";
52
+ readonly PRIVATE: "PRIVATE";
53
+ readonly SGR: "SGR";
54
+ readonly STRING: "STRING";
55
+ readonly TEXT: "TEXT";
56
+ };
57
+ //#endregion
58
+ //#region src/types.d.ts
59
+ type TOKEN = {
60
+ type: keyof typeof TOKEN_TYPES;
61
+ pos: number;
62
+ raw: string;
63
+ code?: string;
64
+ intermediate?: string;
65
+ };
66
+ type CONTROL_CODE_TYPE = Exclude<keyof typeof CODE_TYPES, TEXT["type"]>;
67
+ type CONTROL_CODE = {
68
+ type: CONTROL_CODE_TYPE;
69
+ command: string;
70
+ raw: string;
71
+ params: string[];
72
+ pos: number;
73
+ };
74
+ type TEXT = {
75
+ type: "TEXT";
76
+ raw: string;
77
+ pos: number;
78
+ };
79
+ type CODE = CONTROL_CODE | TEXT;
80
+ //#endregion
81
+ //#region src/parse.d.ts
82
+ declare function parser(tokens: IterableIterator<TOKEN>): IterableIterator<CODE>;
83
+ declare function parse(input: string): CODE[];
84
+ //#endregion
85
+ export { OSC_CODE as A, SOS_OPEN as B, DCS_CODE as C, ESC_CODE as D, ESC as E, PM_CODE as F, SUB_CODE as G, STRING_OPENERS as H, PM_OPEN as I, TOKEN_TYPES as K, PRIVATE_OPENERS as L, OSC_OPEN_CODE as M, PARAM_SEPARATOR as N, INTERRUPTERS as O, PM as P, SOS as R, DCS as S, DEC_OPEN as T, ST_CODE as U, ST as V, SUB as W, CODE_TYPES as _, TEXT as a, CSI_OPEN as b, APC_CODE as c, BACKSLASH_CODE as d, BELL as f, CAN_CODE as g, CAN as h, CONTROL_CODE as i, OSC_OPEN as j, OSC as k, APC_OPEN as l, C0_INTERRUPTERS as m, parser as n, TOKEN as o, BELL_CODE as p, CODE as r, APC as s, parse as t, BACKSLASH as u, CSI as v, DCS_OPEN as w, CSI_OPEN_CODE as x, CSI_CODE as y, SOS_CODE as z };
@@ -0,0 +1 @@
1
+ const e=7,t=`\x07`,n=24,r=``,i=26,a=``,o=27,s=`\x1B`,c=92,l=`\\`,u=144,d=``,f=152,ee=`˜`,p=155,m=`›`,h=156,g=`œ`,_=157,v=``,y=158,b=`ž`,x=159,S=`Ÿ`,C=91,w=`[`,T=93,E=`]`,D=63,O=new Set([`<`,`=`,`>`]),k=`P`,A=`_`,j=`^`,M=`X`,N=new Set([`P`,`_`,`^`,`X`]),P=new Set([24,26,27,155,157,144,159,158,152]),F=new Set([24,26]),I=/[;:]/,L={TEXT:`TEXT`,INTRODUCER:`INTRODUCER`,DATA:`DATA`,FINAL:`FINAL`},R={CSI:`CSI`,DCS:`DCS`,DEC:`DEC`,ESC:`ESC`,OSC:`OSC`,PRIVATE:`PRIVATE`,SGR:`SGR`,STRING:`STRING`,TEXT:`TEXT`};function z(e,t,n){let r=t.map(e=>e.raw).join(``),i=e.raw+r+(n?.raw||``);return{type:R.STRING,pos:e.pos,raw:i,command:`APC`,params:r?[r]:[]}}function B(e,t,n){let r=t.length===1?t[0].raw:t.length===0?``:t.map(e=>e.raw).join(``),i=n?.raw??``,a=e.raw+r+i,o=[],s=R.CSI,c=0;if(r)for(;c<r.length;){let e=r.charCodeAt(c);if(e<48||e>63)break;c++}let l=c>0?r.substring(0,c):``,u=c<r.length?r.substring(c):``;if(l){let e=0;for(let t=0;t<=l.length;t++)(t===l.length||l.charCodeAt(t)===59||l.charCodeAt(t)===58)&&(o.push(t>e?l.substring(e,t):`0`),e=t+1)}let d=u+i,f=o[0];if(f!==void 0&&f.charCodeAt(0)===63)return s=R.DEC,f.length>1?o[0]=f.substring(1):o.shift(),{type:s,pos:e.pos,raw:a,command:d,params:o};for(let t of o)if(t.length>0&&O.has(t[0])){s=R.PRIVATE;let n=t[0]+d;for(let e=0;e<o.length;e++)if(o[e].length>0&&O.has(o[e][0])){o[e].length>1?o[e]=o[e].substring(1):o.splice(e,1);break}return{type:s,pos:e.pos,raw:a,command:n,params:o}}return d===`m`&&o.length===5&&o[1]===`2`&&(f===`38`||f===`48`)&&o.splice(2,0,`0`),d===`r`&&o.length===2&&o[1]===`0`&&(o[1]=`-1`),{type:s,pos:e.pos,raw:a,command:d,params:o}}const V=new Map([[`$q`,2],[`+q`,2],[`+p`,2],[`|`,1],[`{`,1]]);function H(e,t,n){let r=t.map(e=>e.raw).join(``),i=e.raw+r+(n?.raw??``);if(!r)return{type:R.DCS,pos:e.pos,raw:i,command:``,params:[]};for(let[t,n]of V)if(r.startsWith(t)){let a=r.slice(n),o=[];if(a)for(let e of a.split(I))o.push(e||`-1`);return{type:R.DCS,pos:e.pos,raw:i,command:t,params:o}}return{type:R.DCS,pos:e.pos,raw:i,command:``,params:[r]}}function U(e,t,n){let r=t.map(e=>e.raw).join(``),i=e.intermediate||(t[0]?.raw??n?.raw??``),a=e.intermediate&&n?.raw?[n.raw]:[],o=e.raw+r+(n?.raw??``);return{type:R.ESC,pos:e.pos,raw:o,command:i,params:a}}function W(e,t,n){let r=t.map(e=>e.raw).join(``),i=e.raw+r+(n?.raw||``),a=r.indexOf(`;`);if(a===-1)return{type:R.OSC,pos:e.pos,raw:i,command:r,params:[]};let o=r.slice(0,a),s=r.slice(a+1);if(o===`1337`)return{type:R.OSC,pos:e.pos,raw:i,command:o,params:[s]};let c=[];if(s){let e=``;for(let t=0;t<s.length;t++)s[t]===`;`?(c.push(e),e=``):e+=s[t];c.push(e)}return{type:R.OSC,pos:e.pos,raw:i,command:o,params:c}}function G(e,t,n){let r=t.map(e=>e.raw).join(``),i=e.raw+r+(n?.raw||``);return{type:R.STRING,pos:e.pos,raw:i,command:`PM`,params:r?[r]:[]}}function K(e,t,n){let r=t.map(e=>e.raw).join(``),i=e.raw+r+(n?.raw||``);return{type:R.STRING,pos:e.pos,raw:i,command:`SOS`,params:r?[r]:[]}}function q(e){return e===24||e===26||e===27||e===155||e===157||e===144||e===159||e===158||e===152}function J(e){return e===24||e===26}function Y(e){return e===27||e===155||e===157||e===144||e===159||e===158||e===152}function X(e){return e===155||e===157||e===144||e===159||e===158||e===152}function*Z(e){let t=0,n=0,r=0,i=e.length;for(;t<i;)if(n===0){let a=t,o=e.charCodeAt(t);for(;t<i&&!Y(o);)o=e.charCodeAt(++t);if(t>a&&(yield{type:L.TEXT,pos:a,raw:e.substring(a,t)}),t>=i)break;if(X(o))yield{type:L.INTRODUCER,pos:t,raw:e[t],code:e[t]},t++,n=1,r=o;else{let a=e.charCodeAt(t+1);if(a===91)yield{type:L.INTRODUCER,pos:t,raw:e.substring(t,t+2),code:`›`},t+=2,n=1,r=155;else if(a===93)yield{type:L.INTRODUCER,pos:t,raw:e.substring(t,t+2),code:``},t+=2,n=1,r=157;else if(t+1<i&&N.has(e[t+1]))yield{type:L.INTRODUCER,pos:t,raw:e.substring(t,t+2),code:e[t+1]},t+=2,n=1,r=a;else if(t+1<i){let a=t+1;for(;a<i&&e.charCodeAt(a)>=32&&e.charCodeAt(a)<=47;)a++;if(a<i){if(a>t+1){let n=e.substring(t+1,a);yield{type:L.INTRODUCER,pos:t,raw:e.substring(t,a),code:`\x1B`,intermediate:n}}else yield{type:L.INTRODUCER,pos:t,raw:e[t],code:`\x1B`};t=a,n=1,r=27}else t=a}else t++}}else{let a=t;if(r===155){let r=t;for(;t<i;){let i=e.charCodeAt(t);if(q(i)){t>r&&(yield{type:L.DATA,pos:a,raw:e.substring(r,t)}),n=0,J(i)&&t++;break}if(i>=64&&i<=126){t>r&&(yield{type:L.DATA,pos:a,raw:e.substring(r,t)}),yield{type:L.FINAL,pos:t,raw:e[t]},t++,n=0;break}t++}}else if(r===27){if(t<i){let r=e.charCodeAt(t);q(r)?(n=0,J(r)&&t++):(yield{type:L.FINAL,pos:t,raw:e[t]},t++,n=0)}}else{let o=t;for(;t<i;){let i=e.charCodeAt(t),s;if(i===27&&e.charCodeAt(t+1)===92?s=`\x1B\\`:i===156?s=`œ`:i===7&&r===157&&(s=`\x07`),s){t>o&&(yield{type:L.DATA,pos:a,raw:e.substring(o,t)}),yield{type:L.FINAL,pos:t,raw:s},t+=s.length,n=0;break}if(q(i)){t>o&&(yield{type:L.DATA,pos:a,raw:e.substring(o,t)}),n=0,J(i)&&t++;break}t++}}n===1&&(n=0)}}function Q(e){return Array.from(Z(e))}function*$(e){let t=e.next();for(;!t.done;){let n=t.value;if(n.type===L.TEXT){yield{type:R.TEXT,pos:n.pos,raw:n.raw},t=e.next();continue}if(n.type===L.INTRODUCER){let r=n,i=[],a;for(t=e.next();!t.done;){let n=t.value;if(n.type===L.DATA)i.push(n);else if(n.type===L.FINAL){a=n,t=e.next();break}else break;t=e.next()}yield te(r,i,a)}else t=e.next()}}function te(e,t,n){switch(e.code){case`›`:return B(e,t,n);case``:return W(e,t,n);case``:case`P`:return H(e,t,n);case`Ÿ`:case`_`:return z(e,t,n);case`ž`:case`X`:return G(e,t,n);case`˜`:case`^`:return K(e,t,n);case`\x1B`:return U(e,t,n);default:return{type:R.TEXT,pos:e.pos,raw:e.raw}}}function ne(e){return Array.from($(Z(e)))}export{E as A,N as B,D as C,_ as D,P as E,O as F,i as H,f as I,ee as L,y as M,b as N,v as O,M as P,j as R,k as S,s as T,a as U,g as V,L as W,m as _,x as a,u as b,c,t as d,F as f,p as g,R as h,Z as i,I as j,T as k,l,r as m,$ as n,S as o,n as p,Q as r,A as s,ne as t,e as u,C as v,o as w,d as x,w as y,h as z};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ansi-tools/parser",
3
- "version": "1.0.13",
3
+ "version": "1.0.14",
4
4
  "description": "Tokenize and parse strings containing ANSI escape sequences and control codes",
5
5
  "keywords": [
6
6
  "ansi",
@@ -37,15 +37,17 @@
37
37
  "access": "public"
38
38
  },
39
39
  "scripts": {
40
- "prebuild": "pnpm test",
41
- "build": "tsc",
42
- "dev": "tsc --watch",
40
+ "prebuild": "pnpm type-check && pnpm test",
41
+ "build": "tsdown --dts --minify src/index.ts src/escaped.ts",
42
+ "dev": "tsdown --dts src/index.ts src/escaped.ts --watch",
43
43
  "test": "node --import ./test/assertions.ts --test",
44
+ "type-check": "tsc --noEmit",
44
45
  "prepack": "pnpm build"
45
46
  },
46
47
  "devDependencies": {
47
48
  "@types/node": "^24.12.0",
48
49
  "mitata": "^1.0.34",
50
+ "tsdown": "^0.15.7",
49
51
  "typescript": "^5.9.3"
50
52
  }
51
53
  }
@@ -1,56 +0,0 @@
1
- export declare const BELL = 7;
2
- export declare const BELL_CODE: string;
3
- export declare const CAN = 24;
4
- export declare const CAN_CODE: string;
5
- export declare const SUB = 26;
6
- export declare const SUB_CODE: string;
7
- export declare const ESC = 27;
8
- export declare const ESC_CODE: string;
9
- export declare const BACKSLASH = 92;
10
- export declare const BACKSLASH_CODE: string;
11
- export declare const DCS = 144;
12
- export declare const DCS_CODE: string;
13
- export declare const SOS = 152;
14
- export declare const SOS_CODE: string;
15
- export declare const CSI = 155;
16
- export declare const CSI_CODE: string;
17
- export declare const ST = 156;
18
- export declare const ST_CODE: string;
19
- export declare const OSC = 157;
20
- export declare const OSC_CODE: string;
21
- export declare const PM = 158;
22
- export declare const PM_CODE: string;
23
- export declare const APC = 159;
24
- export declare const APC_CODE: string;
25
- export declare const CSI_OPEN: number;
26
- export declare const CSI_OPEN_CODE: string;
27
- export declare const OSC_OPEN: number;
28
- export declare const OSC_OPEN_CODE: string;
29
- export declare const DEC_OPEN: number;
30
- export declare const PRIVATE_OPENERS: Set<string>;
31
- export declare const DCS_OPEN = "P";
32
- export declare const APC_OPEN = "_";
33
- export declare const SOS_OPEN = "^";
34
- export declare const PM_OPEN = "X";
35
- export declare const STRING_OPENERS: Set<string>;
36
- export declare const INTERRUPTERS: Set<number>;
37
- export declare const C0_INTERRUPTERS: Set<number>;
38
- export declare const PARAM_SEPARATOR: RegExp;
39
- export declare const TOKEN_TYPES: {
40
- readonly TEXT: "TEXT";
41
- readonly INTRODUCER: "INTRODUCER";
42
- readonly DATA: "DATA";
43
- readonly FINAL: "FINAL";
44
- };
45
- export declare const CODE_TYPES: {
46
- readonly CSI: "CSI";
47
- readonly DCS: "DCS";
48
- readonly DEC: "DEC";
49
- readonly ESC: "ESC";
50
- readonly OSC: "OSC";
51
- readonly PRIVATE: "PRIVATE";
52
- readonly SGR: "SGR";
53
- readonly STRING: "STRING";
54
- readonly TEXT: "TEXT";
55
- };
56
- //# sourceMappingURL=constants.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,IAAI,IAAI,CAAC;AACtB,eAAO,MAAM,SAAS,QAA4B,CAAC;AACnD,eAAO,MAAM,GAAG,KAAK,CAAC;AACtB,eAAO,MAAM,QAAQ,QAA2B,CAAC;AACjD,eAAO,MAAM,GAAG,KAAK,CAAC;AACtB,eAAO,MAAM,QAAQ,QAA2B,CAAC;AACjD,eAAO,MAAM,GAAG,KAAK,CAAC;AACtB,eAAO,MAAM,QAAQ,QAA2B,CAAC;AACjD,eAAO,MAAM,SAAS,KAAK,CAAC;AAC5B,eAAO,MAAM,cAAc,QAAiC,CAAC;AAC7D,eAAO,MAAM,GAAG,MAAM,CAAC;AACvB,eAAO,MAAM,QAAQ,QAA2B,CAAC;AACjD,eAAO,MAAM,GAAG,MAAM,CAAC;AACvB,eAAO,MAAM,QAAQ,QAA2B,CAAC;AACjD,eAAO,MAAM,GAAG,MAAM,CAAC;AACvB,eAAO,MAAM,QAAQ,QAA2B,CAAC;AACjD,eAAO,MAAM,EAAE,MAAM,CAAC;AACtB,eAAO,MAAM,OAAO,QAA0B,CAAC;AAC/C,eAAO,MAAM,GAAG,MAAM,CAAC;AACvB,eAAO,MAAM,QAAQ,QAA2B,CAAC;AACjD,eAAO,MAAM,EAAE,MAAM,CAAC;AACtB,eAAO,MAAM,OAAO,QAA0B,CAAC;AAC/C,eAAO,MAAM,GAAG,MAAM,CAAC;AACvB,eAAO,MAAM,QAAQ,QAA2B,CAAC;AAEjD,eAAO,MAAM,QAAQ,QAAoB,CAAC;AAC1C,eAAO,MAAM,aAAa,QAAgC,CAAC;AAC3D,eAAO,MAAM,QAAQ,QAAoB,CAAC;AAC1C,eAAO,MAAM,aAAa,QAAgC,CAAC;AAC3D,eAAO,MAAM,QAAQ,QAAoB,CAAC;AAC1C,eAAO,MAAM,eAAe,aAA2B,CAAC;AAExD,eAAO,MAAM,QAAQ,MAAM,CAAC;AAC5B,eAAO,MAAM,QAAQ,MAAM,CAAC;AAC5B,eAAO,MAAM,QAAQ,MAAM,CAAC;AAC5B,eAAO,MAAM,OAAO,MAAM,CAAC;AAC3B,eAAO,MAAM,cAAc,aAAmD,CAAC;AAE/E,eAAO,MAAM,YAAY,aAAwD,CAAC;AAClF,eAAO,MAAM,eAAe,aAAsB,CAAC;AAEnD,eAAO,MAAM,eAAe,QAAS,CAAC;AAEtC,eAAO,MAAM,WAAW;;;;;CAKd,CAAC;AAEX,eAAO,MAAM,UAAU;;;;;;;;;;CAUb,CAAC"}
package/dist/constants.js DELETED
@@ -1,55 +0,0 @@
1
- export const BELL = 7;
2
- export const BELL_CODE = String.fromCharCode(BELL);
3
- export const CAN = 24;
4
- export const CAN_CODE = String.fromCharCode(CAN);
5
- export const SUB = 26;
6
- export const SUB_CODE = String.fromCharCode(SUB);
7
- export const ESC = 27;
8
- export const ESC_CODE = String.fromCharCode(ESC);
9
- export const BACKSLASH = 92;
10
- export const BACKSLASH_CODE = String.fromCharCode(BACKSLASH);
11
- export const DCS = 144;
12
- export const DCS_CODE = String.fromCharCode(DCS);
13
- export const SOS = 152;
14
- export const SOS_CODE = String.fromCharCode(SOS);
15
- export const CSI = 155;
16
- export const CSI_CODE = String.fromCharCode(CSI);
17
- export const ST = 156;
18
- export const ST_CODE = String.fromCharCode(ST);
19
- export const OSC = 157;
20
- export const OSC_CODE = String.fromCharCode(OSC);
21
- export const PM = 158;
22
- export const PM_CODE = String.fromCharCode(PM);
23
- export const APC = 159;
24
- export const APC_CODE = String.fromCharCode(APC);
25
- export const CSI_OPEN = "[".charCodeAt(0);
26
- export const CSI_OPEN_CODE = String.fromCharCode(CSI_OPEN);
27
- export const OSC_OPEN = "]".charCodeAt(0);
28
- export const OSC_OPEN_CODE = String.fromCharCode(OSC_OPEN);
29
- export const DEC_OPEN = "?".charCodeAt(0);
30
- export const PRIVATE_OPENERS = new Set(["<", "=", ">"]);
31
- export const DCS_OPEN = "P";
32
- export const APC_OPEN = "_";
33
- export const SOS_OPEN = "^";
34
- export const PM_OPEN = "X";
35
- export const STRING_OPENERS = new Set([DCS_OPEN, APC_OPEN, SOS_OPEN, PM_OPEN]);
36
- export const INTERRUPTERS = new Set([CAN, SUB, ESC, CSI, OSC, DCS, APC, PM, SOS]);
37
- export const C0_INTERRUPTERS = new Set([CAN, SUB]);
38
- export const PARAM_SEPARATOR = /[;:]/;
39
- export const TOKEN_TYPES = {
40
- TEXT: "TEXT",
41
- INTRODUCER: "INTRODUCER",
42
- DATA: "DATA",
43
- FINAL: "FINAL",
44
- };
45
- export const CODE_TYPES = {
46
- CSI: "CSI",
47
- DCS: "DCS",
48
- DEC: "DEC",
49
- ESC: "ESC",
50
- OSC: "OSC",
51
- PRIVATE: "PRIVATE",
52
- SGR: "SGR",
53
- STRING: "STRING",
54
- TEXT: "TEXT",
55
- };
@@ -1 +0,0 @@
1
- {"version":3,"file":"escaped.d.ts","sourceRoot":"","sources":["../src/escaped.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AACpC,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAC5D,YAAY,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AACpD,YAAY,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC"}
package/dist/parse.d.ts DELETED
@@ -1,4 +0,0 @@
1
- import type { CODE, TOKEN } from "./types.ts";
2
- export declare function parser(tokens: IterableIterator<TOKEN>): IterableIterator<CODE>;
3
- export declare function parse(input: string): CODE[];
4
- //# sourceMappingURL=parse.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"parse.d.ts","sourceRoot":"","sources":["../src/parse.ts"],"names":[],"mappings":"AAuBA,OAAO,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAE9C,wBAAiB,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,KAAK,CAAC,GAAG,gBAAgB,CAAC,IAAI,CAAC,CAsC/E;AA2BD,wBAAgB,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,EAAE,CA2C3C"}
@@ -1,3 +0,0 @@
1
- import type { CODE } from "./types.ts";
2
- export declare function parse(input: string): CODE[];
3
- //# sourceMappingURL=parse.escaped.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"parse.escaped.d.ts","sourceRoot":"","sources":["../src/parse.escaped.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAEvC,wBAAgB,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,EAAE,CAE3C"}
@@ -1,5 +0,0 @@
1
- import { parser } from "./parse.js";
2
- import { tokenizer } from "./tokenize.escaped.js";
3
- export function parse(input) {
4
- return Array.from(parser(tokenizer(input)));
5
- }
package/dist/parse.js DELETED
@@ -1,109 +0,0 @@
1
- import { APC_CODE, APC_OPEN, CODE_TYPES, CSI_CODE, DCS_CODE, DCS_OPEN, ESC_CODE, OSC_CODE, PM_CODE, PM_OPEN, SOS_CODE, SOS_OPEN, TOKEN_TYPES, } from "./constants.js";
2
- import { parseAPC } from "./parsers/apc.js";
3
- import { parseCSI } from "./parsers/csi.js";
4
- import { parseDCS } from "./parsers/dcs.js";
5
- import { parseESC } from "./parsers/esc.js";
6
- import { parseOSC } from "./parsers/osc.js";
7
- import { parsePM } from "./parsers/pm.js";
8
- import { parseSOS } from "./parsers/sos.js";
9
- import { tokenize } from "./tokenize.js";
10
- export function* parser(tokens) {
11
- let current = tokens.next();
12
- while (!current.done) {
13
- const token = current.value;
14
- if (token.type === TOKEN_TYPES.TEXT) {
15
- yield { type: CODE_TYPES.TEXT, pos: token.pos, raw: token.raw };
16
- current = tokens.next();
17
- continue;
18
- }
19
- if (token.type === TOKEN_TYPES.INTRODUCER) {
20
- const introducer = token;
21
- const data = [];
22
- let final;
23
- current = tokens.next();
24
- while (!current.done) {
25
- const nextToken = current.value;
26
- if (nextToken.type === TOKEN_TYPES.DATA) {
27
- data.push(nextToken);
28
- }
29
- else if (nextToken.type === TOKEN_TYPES.FINAL) {
30
- final = nextToken;
31
- current = tokens.next();
32
- break;
33
- }
34
- else {
35
- break;
36
- }
37
- current = tokens.next();
38
- }
39
- yield emitCode(introducer, data, final);
40
- }
41
- else {
42
- current = tokens.next();
43
- }
44
- }
45
- }
46
- function emitCode(introducer, data, final) {
47
- switch (introducer.code) {
48
- case CSI_CODE:
49
- return parseCSI(introducer, data, final);
50
- case OSC_CODE:
51
- return parseOSC(introducer, data, final);
52
- case DCS_CODE:
53
- case DCS_OPEN:
54
- return parseDCS(introducer, data, final);
55
- case APC_CODE:
56
- case APC_OPEN:
57
- return parseAPC(introducer, data, final);
58
- case PM_CODE:
59
- case PM_OPEN:
60
- return parsePM(introducer, data, final);
61
- case SOS_CODE:
62
- case SOS_OPEN:
63
- return parseSOS(introducer, data, final);
64
- case ESC_CODE:
65
- return parseESC(introducer, data, final);
66
- default:
67
- return { type: CODE_TYPES.TEXT, pos: introducer.pos, raw: introducer.raw };
68
- }
69
- }
70
- export function parse(input) {
71
- const tokens = tokenize(input);
72
- const result = [];
73
- let ti = 0;
74
- const tlen = tokens.length;
75
- while (ti < tlen) {
76
- const token = tokens[ti];
77
- if (token.type === TOKEN_TYPES.TEXT) {
78
- result.push({ type: CODE_TYPES.TEXT, pos: token.pos, raw: token.raw });
79
- ti++;
80
- continue;
81
- }
82
- if (token.type === TOKEN_TYPES.INTRODUCER) {
83
- const introducer = token;
84
- const data = [];
85
- let final;
86
- ti++;
87
- while (ti < tlen) {
88
- const nextToken = tokens[ti];
89
- if (nextToken.type === TOKEN_TYPES.DATA) {
90
- data.push(nextToken);
91
- }
92
- else if (nextToken.type === TOKEN_TYPES.FINAL) {
93
- final = nextToken;
94
- ti++;
95
- break;
96
- }
97
- else {
98
- break;
99
- }
100
- ti++;
101
- }
102
- result.push(emitCode(introducer, data, final));
103
- }
104
- else {
105
- ti++;
106
- }
107
- }
108
- return result;
109
- }
@@ -1,3 +0,0 @@
1
- import type { CODE, TOKEN } from "../types.ts";
2
- export declare function parseAPC(introducer: TOKEN, dataTokens: TOKEN[], final: TOKEN | undefined): CODE;
3
- //# sourceMappingURL=apc.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"apc.d.ts","sourceRoot":"","sources":["../../src/parsers/apc.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAE/C,wBAAgB,QAAQ,CAAC,UAAU,EAAE,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,EAAE,KAAK,EAAE,KAAK,GAAG,SAAS,GAAG,IAAI,CAI/F"}
@@ -1,6 +0,0 @@
1
- import { CODE_TYPES } from "../constants.js";
2
- export function parseAPC(introducer, dataTokens, final) {
3
- const data = dataTokens.map((t) => t.raw).join("");
4
- const raw = introducer.raw + data + (final?.raw || "");
5
- return { type: CODE_TYPES.STRING, pos: introducer.pos, raw, command: "APC", params: data ? [data] : [] };
6
- }
@@ -1,3 +0,0 @@
1
- import type { CODE, TOKEN } from "../types.ts";
2
- export declare function parseCSI(introducer: TOKEN, dataTokens: TOKEN[], final: TOKEN | undefined): CODE;
3
- //# sourceMappingURL=csi.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"csi.d.ts","sourceRoot":"","sources":["../../src/parsers/csi.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAqB,KAAK,EAAE,MAAM,aAAa,CAAC;AAElE,wBAAgB,QAAQ,CAAC,UAAU,EAAE,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,EAAE,KAAK,EAAE,KAAK,GAAG,SAAS,GAAG,IAAI,CAsE/F"}
@@ -1,63 +0,0 @@
1
- import { CODE_TYPES, PRIVATE_OPENERS } from "../constants.js";
2
- export function parseCSI(introducer, dataTokens, final) {
3
- const data = dataTokens.length === 1 ? dataTokens[0].raw : dataTokens.length === 0 ? "" : dataTokens.map(t => t.raw).join("");
4
- const finalRaw = final?.raw ?? "";
5
- const raw = introducer.raw + data + finalRaw;
6
- const params = [];
7
- let type = CODE_TYPES.CSI;
8
- let paramEnd = 0;
9
- if (data) {
10
- while (paramEnd < data.length) {
11
- const charCode = data.charCodeAt(paramEnd);
12
- if (charCode < 0x30 || charCode > 0x3f)
13
- break;
14
- paramEnd++;
15
- }
16
- }
17
- const paramSection = paramEnd > 0 ? data.substring(0, paramEnd) : "";
18
- const intermediates = paramEnd < data.length ? data.substring(paramEnd) : "";
19
- if (paramSection) {
20
- let start = 0;
21
- for (let i = 0; i <= paramSection.length; i++) {
22
- if (i === paramSection.length || paramSection.charCodeAt(i) === 0x3b || paramSection.charCodeAt(i) === 0x3a) {
23
- params.push(i > start ? paramSection.substring(start, i) : "0");
24
- start = i + 1;
25
- }
26
- }
27
- }
28
- const command = intermediates + finalRaw;
29
- const first = params[0];
30
- if (first !== undefined && first.charCodeAt(0) === 0x3f) {
31
- type = CODE_TYPES.DEC;
32
- if (first.length > 1)
33
- params[0] = first.substring(1);
34
- else
35
- params.shift();
36
- return { type, pos: introducer.pos, raw, command, params };
37
- }
38
- for (const param of params) {
39
- if (param.length > 0 && PRIVATE_OPENERS.has(param[0])) {
40
- type = CODE_TYPES.PRIVATE;
41
- const privateCommand = param[0] + command;
42
- for (let i = 0; i < params.length; i++) {
43
- if (params[i].length > 0 && PRIVATE_OPENERS.has(params[i][0])) {
44
- if (params[i].length > 1) {
45
- params[i] = params[i].substring(1);
46
- }
47
- else {
48
- params.splice(i, 1);
49
- }
50
- break;
51
- }
52
- }
53
- return { type, pos: introducer.pos, raw, command: privateCommand, params };
54
- }
55
- }
56
- if (command === "m" && params.length === 5 && params[1] === "2" && (first === "38" || first === "48")) {
57
- params.splice(2, 0, "0");
58
- }
59
- if (command === "r" && params.length === 2 && params[1] === "0") {
60
- params[1] = "-1";
61
- }
62
- return { type, pos: introducer.pos, raw, command, params };
63
- }
@@ -1,3 +0,0 @@
1
- import type { CODE, TOKEN } from "../types.ts";
2
- export declare function parseDCS(introducer: TOKEN, dataTokens: TOKEN[], final: TOKEN | undefined): CODE;
3
- //# sourceMappingURL=dcs.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"dcs.d.ts","sourceRoot":"","sources":["../../src/parsers/dcs.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAU/C,wBAAgB,QAAQ,CAAC,UAAU,EAAE,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,EAAE,KAAK,EAAE,KAAK,GAAG,SAAS,GAAG,IAAI,CAiB/F"}
@@ -1,26 +0,0 @@
1
- import { CODE_TYPES, PARAM_SEPARATOR } from "../constants.js";
2
- const DCS_PATTERNS = new Map([
3
- ["$q", 2],
4
- ["+q", 2],
5
- ["+p", 2],
6
- ["|", 1],
7
- ["{", 1],
8
- ]);
9
- export function parseDCS(introducer, dataTokens, final) {
10
- const data = dataTokens.map(t => t.raw).join("");
11
- const raw = introducer.raw + data + (final?.raw ?? "");
12
- if (!data)
13
- return { type: CODE_TYPES.DCS, pos: introducer.pos, raw, command: "", params: [] };
14
- for (const [pattern, length] of DCS_PATTERNS) {
15
- if (data.startsWith(pattern)) {
16
- const remainder = data.slice(length);
17
- const params = [];
18
- if (remainder) {
19
- for (const part of remainder.split(PARAM_SEPARATOR))
20
- params.push(part || "-1");
21
- }
22
- return { type: CODE_TYPES.DCS, pos: introducer.pos, raw, command: pattern, params };
23
- }
24
- }
25
- return { type: CODE_TYPES.DCS, pos: introducer.pos, raw, command: "", params: [data] };
26
- }
@@ -1,3 +0,0 @@
1
- import type { CODE, TOKEN } from "../types.ts";
2
- export declare function parseESC(introducer: TOKEN, dataTokens: TOKEN[], final?: TOKEN): CODE;
3
- //# sourceMappingURL=esc.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"esc.d.ts","sourceRoot":"","sources":["../../src/parsers/esc.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAE/C,wBAAgB,QAAQ,CAAC,UAAU,EAAE,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,EAAE,KAAK,CAAC,EAAE,KAAK,GAAG,IAAI,CAMpF"}
@@ -1,8 +0,0 @@
1
- import { CODE_TYPES } from "../constants.js";
2
- export function parseESC(introducer, dataTokens, final) {
3
- const data = dataTokens.map(t => t.raw).join("");
4
- const command = introducer.intermediate || (dataTokens[0]?.raw ?? final?.raw ?? "");
5
- const params = introducer.intermediate ? (final?.raw ? [final.raw] : []) : [];
6
- const raw = introducer.raw + data + (final?.raw ?? "");
7
- return { type: CODE_TYPES.ESC, pos: introducer.pos, raw, command, params };
8
- }
@@ -1,3 +0,0 @@
1
- import type { CODE, TOKEN } from "../types.ts";
2
- export declare function parseOSC(introducer: TOKEN, dataTokens: TOKEN[], final: TOKEN | undefined): CODE;
3
- //# sourceMappingURL=osc.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"osc.d.ts","sourceRoot":"","sources":["../../src/parsers/osc.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAE/C,wBAAgB,QAAQ,CAAC,UAAU,EAAE,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,EAAE,KAAK,EAAE,KAAK,GAAG,SAAS,GAAG,IAAI,CA2B/F"}
@@ -1,28 +0,0 @@
1
- import { CODE_TYPES } from "../constants.js";
2
- export function parseOSC(introducer, dataTokens, final) {
3
- const data = dataTokens.map(t => t.raw).join("");
4
- const raw = introducer.raw + data + (final?.raw || "");
5
- const semicolonIndex = data.indexOf(";");
6
- if (semicolonIndex === -1) {
7
- return { type: CODE_TYPES.OSC, pos: introducer.pos, raw, command: data, params: [] };
8
- }
9
- const command = data.slice(0, semicolonIndex);
10
- const remainder = data.slice(semicolonIndex + 1);
11
- if (command === "1337")
12
- return { type: CODE_TYPES.OSC, pos: introducer.pos, raw, command, params: [remainder] };
13
- const params = [];
14
- if (remainder) {
15
- let current = "";
16
- for (let i = 0; i < remainder.length; i++) {
17
- if (remainder[i] === ";") {
18
- params.push(current);
19
- current = "";
20
- }
21
- else {
22
- current += remainder[i];
23
- }
24
- }
25
- params.push(current);
26
- }
27
- return { type: CODE_TYPES.OSC, pos: introducer.pos, raw, command, params };
28
- }
@@ -1,3 +0,0 @@
1
- import type { CODE, TOKEN } from "../types.ts";
2
- export declare function parsePM(introducer: TOKEN, dataTokens: TOKEN[], final: TOKEN | undefined): CODE;
3
- //# sourceMappingURL=pm.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"pm.d.ts","sourceRoot":"","sources":["../../src/parsers/pm.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAE/C,wBAAgB,OAAO,CAAC,UAAU,EAAE,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,EAAE,KAAK,EAAE,KAAK,GAAG,SAAS,GAAG,IAAI,CAI9F"}