@il4mb/css-tokenizer 1.0.2 → 1.0.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/dist/index.js CHANGED
@@ -1 +1 @@
1
- var y=["aliceblue","antiquewhite","aqua","aquamarine","azure","beige","bisque","black","blanchedalmond","blue","blueviolet","brown","burlywood","cadetblue","chartreuse","chocolate","coral","cornflowerblue","cornsilk","crimson","cyan","darkblue","darkcyan","darkgoldenrod","darkgray","darkgrey","darkgreen","darkkhaki","darkmagenta","darkolivegreen","darkorange","darkorchid","darkred","darksalmon","darkseagreen","darkslateblue","darkslategray","darkslategrey","darkturquoise","darkviolet","deeppink","deepskyblue","dimgray","dimgrey","dodgerblue","firebrick","floralwhite","forestgreen","fuchsia","gainsboro","ghostwhite","gold","goldenrod","gray","grey","green","greenyellow","honeydew","hotpink","indianred","indigo","ivory","khaki","lavender","lavenderblush","lawngreen","lemonchiffon","lightblue","lightcoral","lightcyan","lightgoldenrodyellow","lightgray","lightgrey","lightgreen","lightpink","lightsalmon","lightseagreen","lightskyblue","lightslategray","lightslategrey","lightsteelblue","lightyellow","lime","limegreen","linen","magenta","maroon","mediumaquamarine","mediumblue","mediumorchid","mediumpurple","mediumseagreen","mediumslateblue","mediumspringgreen","mediumturquoise","mediumvioletred","midnightblue","mintcream","mistyrose","moccasin","navajowhite","navy","oldlace","olive","olivedrab","orange","orangered","orchid","palegoldenrod","palegreen","paleturquoise","palevioletred","papayawhip","peachpuff","peru","pink","plum","powderblue","purple","rebeccapurple","red","rosybrown","royalblue","saddlebrown","salmon","sandybrown","seagreen","seashell","sienna","silver","skyblue","slateblue","slategray","slategrey","snow","springgreen","steelblue","tan","teal","thistle","tomato","turquoise","violet","wheat","white","whitesmoke","yellow","yellowgreen","transparent","currentcolor"],f=[/^rgba?\(/i,/^hsla?\(/i,/^hwb\(/i,/^lab\(/i,/^lch\(/i,/^oklab\(/i,/^oklch\(/i,/^color\(/i,/^color-mix\(/i],k=/^#(?:[0-9a-f]{3}|[0-9a-f]{4}|[0-9a-f]{6}|[0-9a-f]{8})\b/i,b=["px","cm","mm","q","in","pt","pc","em","ex","ch","rem","lh","rlh","cap","ic","vw","vh","vi","vb","vmin","vmax","svw","svh","svi","svb","svmin","svmax","lvw","lvh","lvi","lvb","lvmin","lvmax","dvw","dvh","dvi","dvb","dvmin","dvmax","cqw","cqh","cqi","cqb","cqmin","cqmax","%","deg","grad","rad","turn","s","ms","hz","khz","dpi","dpcm","dppx","x","fr"],p=(e,i)=>{let r=0,t=i,s=!1,n="";while(t<e.length){let a=e[t];if(!s&&(a==='"'||a==="'"))s=!0,n=a;else if(s&&a===n)s=!1;if(!s){if(a==="(")r++;else if(a===")"){if(r--,r===0)return t+1}}t++}return e.length},g=(e,i,r)=>{let t=i;while(t<e.length&&r.test(e[t]))t++;return t};class c{items=[{type:"symbol",kind:"char",regex:/[\s\S]/,priority:0},{type:"escape",kind:"class",regex:/^\\[0-9a-f]{1,6}\s?/i,priority:110,reader({index:e,content:i}){let r=e+1,t=0;while(r<i.length&&/[0-9a-f]/i.test(i[r])&&t<6)r++,t++;if(r<i.length&&/\s/.test(i[r]))r++;return[e,r]}},{type:"unicode-range",kind:"keyword",exp:[/^u\+[0-9a-f?]{1,6}(-[0-9a-f]{1,6})?/i],priority:110,reader({index:e,content:i,matched:r}){let t=r instanceof RegExp?r.exec(i.slice(e)):null;if(!t)return[e,e+1];return[e,e+t[0].length]}},{type:"punctuation",kind:"class",regex:/^[{}()\[\],;:.]/,priority:80,reader({index:e,content:i}){return[e,e+1]}},{type:"operator",kind:"class",regex:/^[+\-*/=<>!~^|&]+/,priority:80,reader({index:e,content:i}){let r=e;while(r<i.length&&/[+\-*/=<>!~^|&]/.test(i[r]))r++;return[e,r]}},{type:"variable",kind:"keyword",exp:[/^--[a-zA-Z0-9-_]+/],priority:110,reader({index:e,content:i,matched:r}){let t=r instanceof RegExp?r.exec(i.slice(e)):null;if(!t)return[e,e+1];return[e,e+t[0].length]}},{type:"comment",kind:"class",regex:/^\/\*/,priority:90,reader({index:e,content:i}){let r=e+2;while(r<i.length&&!(i[r]==="*"&&i[r+1]==="/"))r++;if(r<i.length)r+=2;return[e,r]}},{type:"whitespace",kind:"class",regex:/^\s+/,priority:90,reader({index:e,content:i}){let r=e;while(r<i.length&&/\s/.test(i[r]))r++;return[e,r]}},{type:"url",kind:"class",regex:/^\"https?:\/\/[^\"]+/i,priority:50,reader({index:e,content:i}){let r=e+1;while(r<i.length&&i[r]!=='"')r++;if(r<i.length&&i[r]==='"')r++;return[e,r]}},{type:"string",kind:"class",regex:/^\"[^\"]*\"|^\'[^\']*\'/,priority:20,reader({index:e,content:i}){let r=i[e],t=e+1;while(t<i.length&&i[t]!==r)t++;if(t<i.length&&i[t]===r)t++;return[e,t]}},{type:"atrule",kind:"keyword",exp:[/^@[a-z]+/i],priority:100,reader({index:e,content:i,deepReader:r}){let t=/^@[\w-]+/.exec(i.slice(e));if(!t)return[e,e+1];let s=t[0],n=e+s.length;return r([e,n])}},{type:"function",kind:"keyword",exp:[/^[a-z][a-z0-9-]*\(/i],priority:150,reader({index:e,content:i,deepReader:r}){if(!/^[a-z][a-z0-9-]*\(/i.exec(i.slice(e)))return[e,e+1];let s=p(i,e);return r([e,s])}},{type:"dimension",kind:"keyword",exp:[/^[+-]?[0-9]+[a-z]+/],priority:110,reader({index:e,content:i,deepReader:r}){let t=e;if(i[t]==="-"||i[t]==="+")t++;while(t<i.length&&/[0-9]/.test(i[t]))t++;if(i[t]==="."&&/[0-9]/.test(i[t+1]??"")){t++;while(t<i.length&&/[0-9]/.test(i[t]))t++}while(t<i.length&&/[a-zA-Z%]/.test(i[t]))t++;return r([e,t])}},{type:"number",kind:"class",regex:/^[0-9]/,priority:5,reader({index:e,content:i}){let r=e;while(/^[0-9]$/.test(i[r]))r++;return[e,r]}},{type:"unit",kind:"keyword",exp:b.map((e)=>new RegExp(`^${e}\\b`,"i")),priority:10,reader({index:e,content:i,matched:r}){let t=r instanceof RegExp?r.exec(i.slice(e)):null;if(!t)return[e,e+1];return[e,e+t[0].length]}},{type:"word",kind:"class",regex:/^[a-z]/i,priority:5,reader({index:e,content:i}){let r=g(i,e,/[a-z0-9_-]+/);return[e,r]}},{type:"hash",kind:"class",regex:/^#[a-z0-9]+/i,priority:50,reader({index:e,content:i}){let r=e+1;while(r<i.length&&/^[a-z0-9]+/i.test(i[r]))r++;return[e,r]}},{type:"color",kind:"keyword",priority:120,exp:[...y,k,...f],reader({index:e,content:i,matched:r,deepReader:t}){if(r instanceof RegExp){let n=r.exec(i.slice(e));if(!n)return[e,e+1];let a=n[0];if(a.endsWith("(")){let l=p(i,e);return t([e,l],e+a.length-1)}}let s=g(i,e+1,/[a-zA-Z0-9_-]/);return[e,s]}}];constructor(e=[]){this.items.push(...e),this.sort()}all(){return[...this.items]}add(e){this.items.push({priority:0,...e}),this.sort()}get(e){return this.items[e]}get length(){return this.items.length}[Symbol.iterator](){return this.items[Symbol.iterator]()}indexOf(e){return this.items.indexOf(e)}sort(){this.items.sort((e,i)=>(i.priority??0)-(e.priority??0))}sortExps(e){return[...e].sort((i,r)=>{let t=i instanceof RegExp,s=r instanceof RegExp;if(t!==s)return t?-1:1;if(t&&s)return 0;return r.length-i.length})}}class m{registry;items=[];constructor(e){this.registry=e}push(...e){e.forEach((i)=>{this.items.push(i)})}toArray(){return[...this.items]}toTokenList(e){return this.items.map(([i,r,t])=>({type:this.registry.get(i)?.type??"unknown",start:r,end:t,value:e.slice(r,t)}))}toTokenTree(e){let i=this.toTokenList(e);i.sort((s,n)=>{if(s.start!==n.start)return s.start-n.start;return n.end-s.end});let r=[],t=[];for(let s of i){while(t.length>0&&t[t.length-1].end<=s.start)t.pop();let n=t[t.length-1];if(n){if(!n.children)n.children=[];n.children.push(s)}else r.push(s);t.push(s)}return r}}class d{registry;constructor(e){this.registry=e}getReader(e,i){let r=this.registry.indexOf(e);return(t,s)=>{if(e.kind==="char")return[[r,s,s+1]];let n=(l,u)=>{let o=[[r,l[0],l[1]]],h=t.slice(u??l[0],l[1]),w=this.tokenize(h,{ignoreTypes:[r]}).toArray().map(([x,v,T])=>[x,v+(u??l[0]),T+(u??l[0])]);return o.push(...w),o};if(e.kind==="class"){if("reader"in e&&e.reader){let o=e.reader({content:t,index:s,deepReader:n});if(o.length>0&&Array.isArray(o[0]))return o.map((h)=>h.length===2?[r,...h]:h);return[[r,...o]]}let l=s,u=l+1;while(u<t.length){let o=this.findMatch(t,u);if(o&&r===o[0])u++;else break}return[[r,l,u]]}if(!e.reader){let l=typeof i==="string"?i.length:1;return[[r,s,s+l]]}let a=e.reader({content:t,index:s,matched:i,deepReader:n});if(a.length>0&&Array.isArray(a[0]))return a.map((l)=>l.length===2?[r,...l]:l);return[[r,...a]]}}findMatch(e,i,r){for(let t=0;t<this.registry.length;t++){if(r&&r.includes(t))continue;let s=this.tryMatch(this.registry.get(t),e,i);if(s)return[t,s]}return}tryMatch(e,i,r){if(r>=i.length)return!1;if(e.kind==="keyword"){let t=i.slice(r),s=this.registry.sortExps(e.exp).find((n)=>n instanceof RegExp?n.test(t):t.startsWith(n));return s?this.getReader(e,s):!1}if(e.kind==="class"){if(!e.regex.test(i.slice(r)))return!1;return this.getReader(e)}if(e.kind==="char"){if("regex"in e){if(!e.regex.test(i.slice(r)))return!1;return this.getReader(e)}return e.char===i[r]?this.getReader(e):!1}return!1}tokenize(e,i){let r=new m(this.registry),t=0;while(t<e.length){let s=this.findMatch(e,t,i?.ignoreTypes);if(s){let n=s[1](e,t);if(n&&n.length>0){let a=Math.max(t,...n.map((l)=>l[2]));if(a<=t){r.push([-1,t,t+1]),t++;continue}r.push(...n),t=a;continue}}r.push([-1,t,t+1]),t++}return r}isRange(e){return Array.isArray(e)&&e.length===2&&e.every((i)=>typeof i==="number")}isTuple(e){return Array.isArray(e)&&e.length===3&&e.every((i)=>typeof i==="number")}}var R=new d(new c),A=(e)=>R.tokenize(e);export{f as COLOR_FUNCTIONS,y as CSS_NAMED_COLORS,b as CSS_UNITS,k as HEX_COLOR,c as Registry,d as Tokenizer,m as TupleList,p as findFunctionEnd,g as readWhile,A as tokenizeImpl};
1
+ var b=["aliceblue","antiquewhite","aqua","aquamarine","azure","beige","bisque","black","blanchedalmond","blue","blueviolet","brown","burlywood","cadetblue","chartreuse","chocolate","coral","cornflowerblue","cornsilk","crimson","cyan","darkblue","darkcyan","darkgoldenrod","darkgray","darkgrey","darkgreen","darkkhaki","darkmagenta","darkolivegreen","darkorange","darkorchid","darkred","darksalmon","darkseagreen","darkslateblue","darkslategray","darkslategrey","darkturquoise","darkviolet","deeppink","deepskyblue","dimgray","dimgrey","dodgerblue","firebrick","floralwhite","forestgreen","fuchsia","gainsboro","ghostwhite","gold","goldenrod","gray","grey","green","greenyellow","honeydew","hotpink","indianred","indigo","ivory","khaki","lavender","lavenderblush","lawngreen","lemonchiffon","lightblue","lightcoral","lightcyan","lightgoldenrodyellow","lightgray","lightgrey","lightgreen","lightpink","lightsalmon","lightseagreen","lightskyblue","lightslategray","lightslategrey","lightsteelblue","lightyellow","lime","limegreen","linen","magenta","maroon","mediumaquamarine","mediumblue","mediumorchid","mediumpurple","mediumseagreen","mediumslateblue","mediumspringgreen","mediumturquoise","mediumvioletred","midnightblue","mintcream","mistyrose","moccasin","navajowhite","navy","oldlace","olive","olivedrab","orange","orangered","orchid","palegoldenrod","palegreen","paleturquoise","palevioletred","papayawhip","peachpuff","peru","pink","plum","powderblue","purple","rebeccapurple","red","rosybrown","royalblue","saddlebrown","salmon","sandybrown","seagreen","seashell","sienna","silver","skyblue","slateblue","slategray","slategrey","snow","springgreen","steelblue","tan","teal","thistle","tomato","turquoise","violet","wheat","white","whitesmoke","yellow","yellowgreen","transparent","currentcolor"],w=[/^rgba?\(/i,/^hsla?\(/i,/^hwb\(/i,/^lab\(/i,/^lch\(/i,/^oklab\(/i,/^oklch\(/i,/^color\(/i,/^color-mix\(/i],x=/^#(?:[0-9a-f]{3}|[0-9a-f]{4}|[0-9a-f]{6}|[0-9a-f]{8})\b/i,I=["px","cm","mm","q","in","pt","pc","em","ex","ch","rem","lh","rlh","cap","ic","vw","vh","vi","vb","vmin","vmax","svw","svh","svi","svb","svmin","svmax","lvw","lvh","lvi","lvb","lvmin","lvmax","dvw","dvh","dvi","dvb","dvmin","dvmax","cqw","cqh","cqi","cqb","cqmin","cqmax","%","deg","grad","rad","turn","s","ms","hz","khz","dpi","dpcm","dppx","x","fr"],d=(e,t)=>{let r=0,i=t,s=!1,n="";while(i<e.length){let o=e[i];if(!s&&(o==='"'||o==="'"))s=!0,n=o;else if(s&&o===n)s=!1;if(!s){if(o==="(")r++;else if(o===")"){if(r--,r===0)return i+1}}i++}return e.length},y=(e,t,r)=>{let i=t;while(i<e.length&&r.test(e[i]))i++;return i},M=(e)=>e.sort((t,r)=>t[1]!==r[1]?t[1]-r[1]:r[2]-t[2]);class f{items=[{type:"symbol",kind:"char",regex:/[\s\S]/,priority:0},{type:"escape",kind:"class",regex:/^\\[0-9a-f]{1,6}\s?/i,priority:110,reader({index:e,content:t}){let r=e+1,i=0;while(r<t.length&&/[0-9a-f]/i.test(t[r])&&i<6)r++,i++;if(r<t.length&&/\s/.test(t[r]))r++;return[e,r]}},{type:"unicode-range",kind:"keyword",exp:[/^u\+[0-9a-f?]{1,6}(-[0-9a-f]{1,6})?/i],priority:110,reader({index:e,content:t,matched:r}){let i=r instanceof RegExp?r.exec(t.slice(e)):null;if(!i)return[e,e+1];return[e,e+i[0].length]}},{type:"punctuation",kind:"class",regex:/^[{}()\[\],;:.]/,priority:80,reader({index:e,content:t}){return[e,e+1]}},{type:"operator",kind:"class",regex:/^[+\-*/=<>!~^|&]+/,priority:80,reader({index:e,content:t}){let r=e;while(r<t.length&&/[+\-*/=<>!~^|&]/.test(t[r]))r++;return[e,r]}},{type:"variable",kind:"keyword",exp:[/^--[a-zA-Z0-9-_]+/],priority:110,reader({index:e,content:t,matched:r}){let i=r instanceof RegExp?r.exec(t.slice(e)):null;if(!i)return[e,e+1];return[e,e+i[0].length]}},{type:"comment",kind:"class",regex:/^\/\*/,priority:90,reader({index:e,content:t}){let r=e+2;while(r<t.length&&!(t[r]==="*"&&t[r+1]==="/"))r++;if(r<t.length)r+=2;return[e,r]}},{type:"whitespace",kind:"class",regex:/^\s+/,priority:90,reader({index:e,content:t}){let r=e;while(r<t.length&&/\s/.test(t[r]))r++;return[e,r]}},{type:"url",kind:"class",regex:/^\"https?:\/\/[^\"]+/i,priority:50,reader({index:e,content:t}){let r=e+1;while(r<t.length&&t[r]!=='"')r++;if(r<t.length&&t[r]==='"')r++;return[e,r]}},{type:"string",kind:"class",regex:/^\"[^\"]*\"|^\'[^\']*\'/,priority:20,reader({index:e,content:t}){let r=t[e],i=e+1;while(i<t.length&&t[i]!==r)i++;if(i<t.length&&t[i]===r)i++;return[e,i]}},{type:"atrule",kind:"keyword",exp:[/^@[a-z]+/i],priority:100,reader({index:e,content:t,deepReader:r}){let i=/^@[\w-]+/.exec(t.slice(e));if(!i)return[e,e+1];let s=i[0],n=e+s.length;return r([e,n])}},{type:"function",kind:"keyword",exp:[/^[a-z][a-z0-9-]*\(/i],priority:150,reader({index:e,content:t,deepReader:r}){if(!/^[a-z][a-z0-9-]*\(/i.exec(t.slice(e)))return[e,e+1];let s=d(t,e);return r([e,s])}},{type:"dimension",kind:"keyword",exp:[/^[+-]?[0-9]+[a-z]+/],priority:110,reader({index:e,content:t,deepReader:r}){let i=e;if(t[i]==="-"||t[i]==="+")i++;while(i<t.length&&/[0-9]/.test(t[i]))i++;if(t[i]==="."&&/[0-9]/.test(t[i+1]??"")){i++;while(i<t.length&&/[0-9]/.test(t[i]))i++}while(i<t.length&&/[a-zA-Z%]/.test(t[i]))i++;return r([e,i])}},{type:"number",kind:"class",regex:/^[0-9]/,priority:5,reader({index:e,content:t}){let r=e;while(/^[0-9]$/.test(t[r]))r++;return[e,r]}},{type:"unit",kind:"keyword",exp:I.map((e)=>new RegExp(`^${e}\\b`,"i")),priority:10,reader({index:e,content:t,matched:r}){let i=r instanceof RegExp?r.exec(t.slice(e)):null;if(!i)return[e,e+1];return[e,e+i[0].length]}},{type:"word",kind:"class",regex:/^[a-z]/i,priority:5,reader({index:e,content:t}){let r=y(t,e,/[a-z0-9_-]+/);return[e,r]}},{type:"hash",kind:"class",regex:/^#[a-z0-9]+/i,priority:50,reader({index:e,content:t}){let r=e+1;while(r<t.length&&/^[a-z0-9]+/i.test(t[r]))r++;return[e,r]}},{type:"color",kind:"keyword",priority:120,exp:[...b,x,...w],reader({index:e,content:t,matched:r,deepReader:i}){if(r instanceof RegExp){let n=r.exec(t.slice(e));if(!n)return[e,e+1];let o=n[0];if(o.endsWith("(")){let h=d(t,e);return i([[e,h],[e,e+o.length-1]],e+o.length-1)}}let s=y(t,e+1,/[a-zA-Z0-9_-]/);return[e,s]}}];constructor(e=[]){this.items.push(...e),this.sort()}all(){return[...this.items]}add(e){this.items.push({priority:0,...e}),this.sort()}get(e){return this.items[e]}get length(){return this.items.length}[Symbol.iterator](){return this.items[Symbol.iterator]()}indexOfType(e){let t=this.items.find((r)=>r.type===e);if(t)return this.indexOf(t);return-1}indexOf(e){return this.items.indexOf(e)}sort(){this.items.sort((e,t)=>(t.priority??0)-(e.priority??0))}sortExps(e){return[...e].sort((t,r)=>{let i=t instanceof RegExp,s=r instanceof RegExp;if(i!==s)return i?-1:1;if(i&&s)return 0;return r.length-t.length})}}class k{registry;constructor(e){this.registry=e}getReader(e,t){let r=e.type;return(i,s)=>{if(e.kind==="char")return[[r,s,s+1]];let n=(l,u)=>{let a=u??i.slice(l[0],l[1]);return[this.findMatch(a,l[0])?.[0]??"unknown",l[0],l[1]]},o=(l,u)=>{let a=this.isRange(l)?[[r,...l]]:l.map((p,m)=>m===0?[r,p[0],p[1]]:p.length==2?n(p):p),g=a[0],c=u??g[1],v=i.slice(c,g[2]),R=this.tokenize(v,{ignoreTypes:[r]}).map(([p,m,T])=>[p,m+c,T+c]);return a.push(...R),a};if(e.kind==="class"){if("reader"in e&&e.reader){let a=e.reader({content:i,index:s,deepReader:o,createTuple:n});if(this.isRange(a))return[[r,a[0],a[1]]];return a.map((g)=>g.length===2?[r,g[0],g[1]]:g)}let l=s,u=l+1;while(u<i.length){let a=this.findMatch(i,u);if(a&&r===a[0])u++;else break}return[[r,l,u]]}if(!e.reader){let l=typeof t==="string"?t.length:1;return[[r,s,s+l]]}let h=e.reader({content:i,index:s,matched:t,deepReader:o,createTuple:n});if(this.isRange(h))return[[r,h[0],h[1]]];return h.map((l)=>l.length===2?[r,l[0],l[1]]:l)}}findMatch(e,t,r){for(let i of this.registry){if(r&&r.includes(i.type))continue;let s=this.tryMatch(i,e,t);if(s)return[i.type,s]}return}tryMatch(e,t,r){if(r>=t.length)return!1;if(e.kind==="keyword"){let i=t.slice(r),s=this.registry.sortExps(e.exp).find((n)=>n instanceof RegExp?n.test(i):i.startsWith(n));return s?this.getReader(e,s):!1}if(e.kind==="class"){if(!e.regex.test(t.slice(r)))return!1;return this.getReader(e)}if(e.kind==="char"){if("regex"in e){if(!e.regex.test(t.slice(r)))return!1;return this.getReader(e)}return e.char===t[r]?this.getReader(e):!1}return!1}tokenize(e,t){let r=[],i=0;while(i<e.length){let s=this.findMatch(e,i,t?.ignoreTypes);if(s){let n=s[1](e,i);if(n&&n.length>0){let o=Math.max(i,...n.map((h)=>h[2]));if(o<=i){r.push([-1,i,i+1]),i++;continue}r.push(...n),i=o;continue}}r.push([-1,i,i+1]),i++}return r.sort(),r}isRange(e){return Array.isArray(e)&&e.length===2&&e.every((t)=>typeof t==="number")}isTuple(e){return Array.isArray(e)&&e.length===3&&e.every((t,r)=>typeof t===(r===0?"string":"number"))}}class z{registry;items;constructor(e,t=[]){this.registry=e;this.items=t}push(...e){e.forEach((t)=>{this.items.push(t)})}toArray(){return[...this.items]}sort(){this.items.sort((e,t)=>e[1]!==t[1]?e[1]-t[1]:t[2]-e[2])}toPlainList(e){return this.toArray().map(([t,r,i])=>({type:t,start:r,end:i,value:e.slice(r,i)}))}toJSON(){return[...this.items]}}var E=new k(new f),L=(e)=>E.tokenize(e);export{w as COLOR_FUNCTIONS,b as CSS_NAMED_COLORS,I as CSS_UNITS,x as HEX_COLOR,f as Registry,k as Tokenizer,z as TupleList,d as findFunctionEnd,y as readWhile,M as sortTuples,L as tokenizeImpl};
@@ -3,4 +3,4 @@ export * from "./registry";
3
3
  export * from "./tokenizer";
4
4
  export * from "./tools";
5
5
  export * from "./tupleList";
6
- export declare const tokenizeImpl: (content: string) => import("./tupleList").TupleList;
6
+ export declare const tokenizeImpl: (content: string) => [type: string, start: number, end: number][];
@@ -1,4 +1,4 @@
1
- import { Exp, ModelDefinition } from "./type";
1
+ import { IExp, ModelDefinition } from "./type";
2
2
  export declare class Registry implements Iterable<ModelDefinition> {
3
3
  private readonly items;
4
4
  constructor(models?: ModelDefinition[]);
@@ -7,7 +7,8 @@ export declare class Registry implements Iterable<ModelDefinition> {
7
7
  get(index: number): ModelDefinition;
8
8
  get length(): number;
9
9
  [Symbol.iterator](): ArrayIterator<ModelDefinition>;
10
+ indexOfType(type: string): number;
10
11
  indexOf(item: ModelDefinition): number;
11
12
  sort(): void;
12
- sortExps(exps: Exp[]): Exp[];
13
+ sortExps(exps: IExp[]): IExp[];
13
14
  }
@@ -1,15 +1,14 @@
1
1
  import { Registry } from "./registry";
2
- import { TupleList } from "./tupleList";
3
- import { Exp, ModelDefinition, TRange, Tuple } from "./type";
2
+ import { IExp, ModelDefinition, IRange, IToken } from "./type";
4
3
  export declare class Tokenizer {
5
4
  registry: Registry;
6
5
  constructor(registry: Registry);
7
- getReader(def: ModelDefinition, match?: Exp): (content: string, index: number) => Tuple[];
8
- findMatch(content: string, index: number, ignoreTypes?: number[]): [number, (c: string, i: number) => Tuple[]] | undefined;
9
- tryMatch(def: ModelDefinition, content: string, index: number): false | ((content: string, index: number) => Tuple[]);
6
+ getReader(def: ModelDefinition, match?: IExp): (content: string, index: number) => IToken[];
7
+ findMatch(content: string, index: number, ignoreTypes?: string[]): [string, (c: string, i: number) => IToken[]] | undefined;
8
+ tryMatch(def: ModelDefinition, content: string, index: number): false | ((content: string, index: number) => IToken[]);
10
9
  tokenize(content: string, options?: {
11
- ignoreTypes?: number[];
12
- }): TupleList;
13
- isRange(data: any): data is TRange;
14
- isTuple(data: any): data is Tuple;
10
+ ignoreTypes?: string[];
11
+ }): IToken[];
12
+ isRange(data: any): data is IRange;
13
+ isTuple(data: any): data is IToken;
15
14
  }
@@ -1,6 +1,8 @@
1
+ import { IToken } from "./type";
1
2
  export declare const CSS_NAMED_COLORS: string[];
2
3
  export declare const COLOR_FUNCTIONS: RegExp[];
3
4
  export declare const HEX_COLOR: RegExp;
4
5
  export declare const CSS_UNITS: string[];
5
6
  export declare const findFunctionEnd: (source: string, index: number) => number;
6
7
  export declare const readWhile: (content: string, index: number, test: RegExp) => number;
8
+ export declare const sortTuples: (tuples: IToken[]) => [type: string, start: number, end: number][];
@@ -1,11 +1,12 @@
1
1
  import { Registry } from "./registry";
2
- import { Token, TokenTree, Tuple } from "./type";
2
+ import { PlainToken, IToken } from "./type";
3
3
  export declare class TupleList {
4
4
  protected registry: Registry;
5
- protected items: Tuple[];
6
- constructor(registry: Registry);
7
- push(...items: Tuple[]): void;
8
- toArray(): Tuple[];
9
- toTokenList(content: string): Token[];
10
- toTokenTree(content: string): TokenTree[];
5
+ protected items: IToken[];
6
+ constructor(registry: Registry, items?: IToken[]);
7
+ push(...items: IToken[]): void;
8
+ toArray(): [type: string, start: number, end: number][];
9
+ sort(): void;
10
+ toPlainList(content: string): PlainToken[];
11
+ toJSON(): [type: string, start: number, end: number][];
11
12
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@il4mb/css-tokenizer",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "Modular, extensible CSS tokenizer for parsing CSS-like strings into tuple lists and token trees.",
5
5
  "keywords": [
6
6
  "css",
@@ -28,8 +28,8 @@
28
28
  "scripts": {
29
29
  "test": "vitest index.test.ts",
30
30
  "build:types": "npx tsc --build tsconfig.build.json",
31
- "build": "bun build ./src/index.ts --outdir ./dist --minify --format esm",
32
- "prepublishOnly": "npm run build"
31
+ "build:js": "bun build ./src/index.ts --outdir ./dist --minify --format esm",
32
+ "build": "bun run build:types && bun run build:js"
33
33
  },
34
34
  "devDependencies": {
35
35
  "@types/node": "^26.4.1",
@@ -0,0 +1 @@
1
+ {"version":"7.0.2","root":[[90,95]],"packageJsons":["./package.json"],"fileNames":["lib.es5.d.ts","lib.es2015.d.ts","lib.es2016.d.ts","lib.es2017.d.ts","lib.es2018.d.ts","lib.es2019.d.ts","lib.es2020.d.ts","lib.es2021.d.ts","lib.es2022.d.ts","lib.es2023.d.ts","lib.es2024.d.ts","lib.es2025.d.ts","lib.esnext.d.ts","lib.dom.d.ts","lib.dom.iterable.d.ts","lib.es2015.core.d.ts","lib.es2015.collection.d.ts","lib.es2015.generator.d.ts","lib.es2015.iterable.d.ts","lib.es2015.promise.d.ts","lib.es2015.proxy.d.ts","lib.es2015.reflect.d.ts","lib.es2015.symbol.d.ts","lib.es2015.symbol.wellknown.d.ts","lib.es2016.array.include.d.ts","lib.es2016.intl.d.ts","lib.es2017.arraybuffer.d.ts","lib.es2017.date.d.ts","lib.es2017.object.d.ts","lib.es2017.sharedmemory.d.ts","lib.es2017.string.d.ts","lib.es2017.intl.d.ts","lib.es2017.typedarrays.d.ts","lib.es2018.asyncgenerator.d.ts","lib.es2018.asynciterable.d.ts","lib.es2018.intl.d.ts","lib.es2018.promise.d.ts","lib.es2018.regexp.d.ts","lib.es2019.array.d.ts","lib.es2019.object.d.ts","lib.es2019.string.d.ts","lib.es2019.symbol.d.ts","lib.es2019.intl.d.ts","lib.es2020.bigint.d.ts","lib.es2020.date.d.ts","lib.es2020.promise.d.ts","lib.es2020.sharedmemory.d.ts","lib.es2020.string.d.ts","lib.es2020.symbol.wellknown.d.ts","lib.es2020.intl.d.ts","lib.es2020.number.d.ts","lib.es2021.promise.d.ts","lib.es2021.string.d.ts","lib.es2021.weakref.d.ts","lib.es2021.intl.d.ts","lib.es2022.array.d.ts","lib.es2022.error.d.ts","lib.es2022.intl.d.ts","lib.es2022.object.d.ts","lib.es2022.string.d.ts","lib.es2022.regexp.d.ts","lib.es2023.array.d.ts","lib.es2023.collection.d.ts","lib.es2023.intl.d.ts","lib.es2024.arraybuffer.d.ts","lib.es2024.collection.d.ts","lib.es2024.object.d.ts","lib.es2024.promise.d.ts","lib.es2024.regexp.d.ts","lib.es2024.sharedmemory.d.ts","lib.es2024.string.d.ts","lib.es2025.collection.d.ts","lib.es2025.float16.d.ts","lib.es2025.intl.d.ts","lib.es2025.iterator.d.ts","lib.es2025.promise.d.ts","lib.es2025.regexp.d.ts","lib.esnext.array.d.ts","lib.esnext.collection.d.ts","lib.esnext.date.d.ts","lib.esnext.decorators.d.ts","lib.esnext.disposable.d.ts","lib.esnext.error.d.ts","lib.esnext.intl.d.ts","lib.esnext.sharedmemory.d.ts","lib.esnext.temporal.d.ts","lib.esnext.typedarrays.d.ts","lib.decorators.d.ts","lib.decorators.legacy.d.ts","./src/type.d.ts","./src/tools.ts","./src/registry.ts","./src/tokenizer.ts","./src/tupleList.ts","./src/index.ts"],"fileInfos":[{"version":"16934abaab7026ac114da441aabea1a0","affectsGlobalScope":true,"impliedNodeFormat":1},"d4306fb2e47f74835e8674ffac07d76f","e437c5c1302869326c3bb93da85bbbcf","e4324975a566567b21d350615f1fc6ac","333b1b9a2a9ac3b8497dba5c63b5ba50","6cffacd662b6eb5fa7a36aa2ea366bfa","b4c34f9c23304dbef2d23698637ed638","e5cb86a5fc491796ecd1d2dd348d208f","feb6c6fb19cdb246a5d8acb36a6901c7","9443a7f109277ffaa79d893ed2549995","793cee405385076e27c24f409659dccd","09f69c6610266eaee1ac9e3e30df2c71","62bad718844246b8e17547f37bad6085",{"version":"aae8996e8b5684814785a42cbbefcd79","affectsGlobalScope":true,"impliedNodeFormat":1},"abad6dd56cc8caf095c165df8124d237",{"version":"926204c28cd3d073865348473ae28d2e","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"f25e42c801b2cb3cf2b39792006a9beb","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"6344b55f26a4e81d9608777dbfb877dd","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"3c0ed28e53d3695b363e256ec1c023fd","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"4c2761daba7f17141c25baa0821ac5da","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"b87656acabd63e69379ff6ffcfe52fc7","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"597469522da047a5af5222cc6989f405","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"1708ea4d34dc37fadadc63ca01127e80","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"55d97a8c6fbf34a30450a7b1e5f7a298","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"0ee05eb59426d33e374226d8dcfa708b","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"e347c14030993906efcfbb88915b6a05","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"b0231263857c9b6a03641acdc9280ceb","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"3b15c4a83b598cacb4067676e6f0abed","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"b417d97b7934cef63b1889abec0bbfbf","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"09a6cf4032ebba60ce22a501e663f881","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"2b056277dd138e8f5650fc04e20eaa8d","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"e22cc07e3f3cc242ba52fa3f8ea1fc58","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"2c45da767a1bfbb220848df1bc4029e4","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"b44c3e0fbaf2130cdcf6ac38b120ffa1","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"b612fb5cf8e5d964b92063a75207632a","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"02705151a5e1551b9162a9ed8ab763f7","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"41025e398be9215d32e4337335da8f0b","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"52684c2b1f353a5538e4f275182a54cd","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"6dedb6a4f90d1df3a6fbe5693e44886c","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"ca3f36fe3562c07e0f0d71c2bebd3f6d","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"409974d6129befbb8226ddd1c6558568","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"4d9cfde2a1ae1b4925f1f9bc10848e5d","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"7e1daecc66dd564144e3bb1a0266b5fd","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"a8e1d9bb35fd0637f2f9fd2b2a54f2ec","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"4f168501772a6543182765bfd5f2fbfe","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"a19c80aad1b2162103496f5ba293a732","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"b69afa63cd5d059851c78adb2856ee09","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"ae2fc5d954e9b0f5feee3d481b953c27","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"1cfd3091a071d8b6feec15277643bafe","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"1da2c1f258970fd3cc91184f69e91a9d","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"a0d87491913d843139e0c993650a3235","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"4ef72aa378127e7b7abba915b0110b1e","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"3ec74c6a7d4463f0254db3a74cf75646","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"84c2bdfa470d075526cce6322d81b0b6","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"0b3844c2b8c73e4e1ab91431411cad11","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"4fc71cf4a15b8d99675a31df77f26e07","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"d1b49564ddaeca3df5b6dbae925d2242","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"6a25be566d60ccfc2d6e8b7bfdeefa83","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"8a20e27646985dfd58c57ca6566553dd","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"9969f02ad3cdcbf4f709405cda44167f","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"9c9be4792a7a4f42c15ae7360bf28779","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"8cf777fe00349b71ee9c4b6f3fe7fd19","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"74f96bc192530c9723f572bfff3d3078","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"1df91c56b25955c56387426f378173c5","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"38856f70edcd2115c355d96ec77cc09e","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"de8700156c1275465bcd473c28b359aa","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"d47cfdb6ede40518357bb5a4cd7cd9fb","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"6e5773860cd9e5b15e683113f642ab47","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"30ff5fe1682f7fcd629880476ca3c2e0","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"bf23d7d1b40b9015b694ddc2f011752f","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"2cc585d42e2c548f9f24a30a1989fd33","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"713906ce9d332d2242b7f05ed9304be3","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"0219894bfe5042c7e1aa2d22e4a91ed0","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"6009ffff7e43c93318804d2d28e37fe3","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"03be89b227587594fbb50509fc1c2e45","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"b30df52dc24740c0bad7c55c3511df7d","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"ab8d3c9b5ed5c2ab8f383607eef439f0","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"d950ec671d0a8e07f3c1a31e94abed86","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"1abef2ace5eccb02d60dd73cd5a5ee4c","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"f5f0a3044029d1cc081b5887eb4deb07","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"d57c697f1446940ec4bfe669c962e2c4","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"be41035d7b941482a1e1ae6a5c5dcca5","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"10f7d9da7564f27f8ddf4a162b6da6d3","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"1d0520af549e0c3581f15173cc713ca1","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"d65083f97fd741cff028472563eddb79","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"da7f24f00653ebac660ac1c0821ed33d","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"7cb5ae9e65516ea2235f0721f6aac43c","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"f64453cbf9671f28158677fa5c43967a","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"33f317af5428801f944a478d2c1e38e5","affectsGlobalScope":true,"impliedNodeFormat":1},"7b19475502a08c2498516b8f7d0f018c",{"version":"0ae960452c8c903771118f9315d5d53b","signature":"156af4db9e6deb1ac75e84d2e99142e5","impliedNodeFormat":1},{"version":"f46ccef0b20a19f576d483e6fbdbdc3e","signature":"55e03d01362640a6ab1409c646da16b9","impliedNodeFormat":1},{"version":"f67b2e4b870ee0f8ac1b7dcfaec19260","signature":"8ce5829abeb35cee0da7fed9a0d4ab00","impliedNodeFormat":1},{"version":"81da8ee173f7400f0b46c91be1441c94","signature":"353cc1503c7d7a025a29c0f3bd9a53a6","impliedNodeFormat":1},{"version":"b28dd5335b4348ef855bddc51f02f519","signature":"9aa1636879734a3697a9a7a5c2b6237b","impliedNodeFormat":1}],"fileIdsList":[[90,91,92,93,94],[90,91],[90,92],[90]],"options":{"allowJs":true,"emitDeclarationOnly":true,"declaration":true,"declarationDir":"./dist/types","declarationMap":false,"jsx":4,"module":99,"outDir":"./dist","rootDir":"./src","skipLibCheck":true,"strict":false,"target":4,"esModuleInterop":true},"referencedMap":[[95,1],[92,2],[93,3],[91,4],[94,3]]}