xml-tokenizer 0.0.21 → 0.0.22

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/cjs/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var i=require("./selector/select.js"),o=require("./selector/TokenSelector.js"),S=require("./selector/TokenSelectState.js"),R=require("./selector/TokenSelectStateMachine.js"),T=require("./token-to-xml.js"),e=require("./tokenizer/ascii-constants.js"),r=require("./tokenizer/tokenize.js"),E=require("./tokenizer/utils.js"),O=require("./tokenizer/XmlError.js"),l=require("./tokenizer/XmlStream.js"),a=require("./tokens-to-xml.js"),t=require("./xml-to-object.js"),A=require("./xml-to-simplified-object.js");exports.select=i.select,exports.TokenSelector=o.TokenSelector,exports.EToCacheNodeProps=S.EToCacheNodeProps,exports.ETokenMatchCriteria=S.ETokenMatchCriteria,exports.TokenSelectState=S.TokenSelectState,exports.TokenSelectStateMachine=R.TokenSelectStateMachine,exports.tokenToXml=T.tokenToXml,exports.AMPERSAND=e.AMPERSAND,exports.CARRIAGE_RETURN=e.CARRIAGE_RETURN,exports.CLOSE_SQUARE_BRACKET=e.CLOSE_SQUARE_BRACKET,exports.COLON=e.COLON,exports.DOUBLE_QUOTE=e.DOUBLE_QUOTE,exports.EQUALS=e.EQUALS,exports.EXCLAMATION_MARK=e.EXCLAMATION_MARK,exports.GREATER_THAN=e.GREATER_THAN,exports.HASH=e.HASH,exports.HORIZONTAL_TAB=e.HORIZONTAL_TAB,exports.HYPHEN=e.HYPHEN,exports.LESS_THAN=e.LESS_THAN,exports.LINE_FEED=e.LINE_FEED,exports.LOWERCASE_A=e.LOWERCASE_A,exports.LOWERCASE_F=e.LOWERCASE_F,exports.LOWERCASE_X=e.LOWERCASE_X,exports.LOWERCASE_Z=e.LOWERCASE_Z,exports.NINE=e.NINE,exports.OPEN_SQUARE_BRACKET=e.OPEN_SQUARE_BRACKET,exports.PERCENT=e.PERCENT,exports.PERIOD=e.PERIOD,exports.QUESTION_MARK=e.QUESTION_MARK,exports.SEMICOLON=e.SEMICOLON,exports.SINGLE_QUOTE=e.SINGLE_QUOTE,exports.SLASH=e.SLASH,exports.SPACE=e.SPACE,exports.UNDERSCORE=e.UNDERSCORE,exports.UPPERCASE_A=e.UPPERCASE_A,exports.UPPERCASE_F=e.UPPERCASE_F,exports.UPPERCASE_P=e.UPPERCASE_P,exports.UPPERCASE_S=e.UPPERCASE_S,exports.UPPERCASE_Z=e.UPPERCASE_Z,exports.ZERO=e.ZERO,exports.tokenize=r.tokenize,exports.tokenizeXmlStream=r.tokenizeXmlStream,exports.isAsciiDigit=E.isAsciiDigit,exports.isXmlChar=E.isXmlChar,exports.isXmlName=E.isXmlName,exports.isXmlNameByte=E.isXmlNameByte,exports.isXmlNameStart=E.isXmlNameStart,exports.isXmlSpaceByte=E.isXmlSpaceByte,exports.XmlError=O.XmlError,exports.XmlStream=l.XmlStream,exports.tokensToXml=a.tokensToXml,exports.processTokenForObject=t.processTokenForObject,exports.xmlToObject=t.xmlToObject,exports.processTokenForSimplifiedObject=A.processTokenForSimplifiedObject,exports.xmlToSimplifiedObject=A.xmlToSimplifiedObject;
1
+ "use strict";var i=require("./get-q-name.js"),o=require("./selector/select.js"),R=require("./selector/TokenSelector.js"),S=require("./selector/TokenSelectState.js"),T=require("./selector/TokenSelectStateMachine.js"),a=require("./token-to-xml.js"),e=require("./tokenizer/ascii-constants.js"),r=require("./tokenizer/tokenize.js"),E=require("./tokenizer/utils.js"),O=require("./tokenizer/XmlError.js"),m=require("./tokenizer/XmlStream.js"),l=require("./tokens-to-xml.js"),t=require("./xml-to-object.js"),A=require("./xml-to-simplified-object.js");exports.getQName=i.getQName,exports.select=o.select,exports.TokenSelector=R.TokenSelector,exports.EToCacheNodeProps=S.EToCacheNodeProps,exports.ETokenMatchCriteria=S.ETokenMatchCriteria,exports.TokenSelectState=S.TokenSelectState,exports.TokenSelectStateMachine=T.TokenSelectStateMachine,exports.tokenToXml=a.tokenToXml,exports.AMPERSAND=e.AMPERSAND,exports.CARRIAGE_RETURN=e.CARRIAGE_RETURN,exports.CLOSE_SQUARE_BRACKET=e.CLOSE_SQUARE_BRACKET,exports.COLON=e.COLON,exports.DOUBLE_QUOTE=e.DOUBLE_QUOTE,exports.EQUALS=e.EQUALS,exports.EXCLAMATION_MARK=e.EXCLAMATION_MARK,exports.GREATER_THAN=e.GREATER_THAN,exports.HASH=e.HASH,exports.HORIZONTAL_TAB=e.HORIZONTAL_TAB,exports.HYPHEN=e.HYPHEN,exports.LESS_THAN=e.LESS_THAN,exports.LINE_FEED=e.LINE_FEED,exports.LOWERCASE_A=e.LOWERCASE_A,exports.LOWERCASE_F=e.LOWERCASE_F,exports.LOWERCASE_X=e.LOWERCASE_X,exports.LOWERCASE_Z=e.LOWERCASE_Z,exports.NINE=e.NINE,exports.OPEN_SQUARE_BRACKET=e.OPEN_SQUARE_BRACKET,exports.PERCENT=e.PERCENT,exports.PERIOD=e.PERIOD,exports.QUESTION_MARK=e.QUESTION_MARK,exports.SEMICOLON=e.SEMICOLON,exports.SINGLE_QUOTE=e.SINGLE_QUOTE,exports.SLASH=e.SLASH,exports.SPACE=e.SPACE,exports.UNDERSCORE=e.UNDERSCORE,exports.UPPERCASE_A=e.UPPERCASE_A,exports.UPPERCASE_F=e.UPPERCASE_F,exports.UPPERCASE_P=e.UPPERCASE_P,exports.UPPERCASE_S=e.UPPERCASE_S,exports.UPPERCASE_Z=e.UPPERCASE_Z,exports.ZERO=e.ZERO,exports.tokenize=r.tokenize,exports.tokenizeXmlStream=r.tokenizeXmlStream,exports.isAsciiDigit=E.isAsciiDigit,exports.isXmlChar=E.isXmlChar,exports.isXmlName=E.isXmlName,exports.isXmlNameByte=E.isXmlNameByte,exports.isXmlNameStart=E.isXmlNameStart,exports.isXmlSpaceByte=E.isXmlSpaceByte,exports.XmlError=O.XmlError,exports.XmlStream=m.XmlStream,exports.tokensToXml=l.tokensToXml,exports.processTokenForObject=t.processTokenForObject,exports.xmlToObject=t.xmlToObject,exports.processTokenForSimplifiedObject=A.processTokenForSimplifiedObject,exports.xmlToSimplifiedObject=A.xmlToSimplifiedObject;
@@ -1 +1 @@
1
- "use strict";var o=require("./ascii-constants.js"),a=require("./utils.js"),n=require("./XmlError.js"),_=Object.defineProperty,m=Object.getOwnPropertySymbols,C=Object.prototype.hasOwnProperty,f=Object.prototype.propertyIsEnumerable,p=(h,t,e)=>t in h?_(h,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):h[t]=e,E=(h,t)=>{for(var e in t||(t={}))C.call(t,e)&&p(h,e,t[e]);if(m)for(var e of m(t))f.call(t,e)&&p(h,e,t[e]);return h},c=(h,t,e)=>p(h,typeof t!="symbol"?t+"":t,e);class u{constructor(t,e={}){c(this,"_text"),c(this,"_pos"),c(this,"_end"),c(this,"config");const{pos:r=0,strictDocument:i=!0,allowDtd:s=!0,allowBooleanAttributes:l=!1}=e;this._text=t,this._pos=r,this._end=this._text.length,this.config={strictDocument:i,allowDtd:s,allowBooleanAttributes:l}}clone(){return new u(this._text,E({pos:this._pos},this.config))}getPos(){return this._pos}atEnd(){return this._pos>=this._end}currCodeUnit(){if(this._pos>=this._end)throw new n.XmlError({type:"UnexpectedEndOfStream"});return this._text.charCodeAt(this._pos)}currCodeUnitUnchecked(){return this._text.charCodeAt(this._pos)}nextCodeUnit(){if(this._pos+1>=this._end)throw new n.XmlError({type:"UnexpectedEndOfStream"});return this._text.charCodeAt(this._pos+1)}consumeCodeUnit(t){const e=this.currCodeUnit();if(e!==t)throw new n.XmlError({type:"InvalidChar",expected:t,actual:e},this.genTextPos());this._pos+=1}tryConsumeCodeUnit(t){return this.currCodeUnit()===t?(this._pos+=1,!0):!1}consumeCodeUnitsWhile(t){const e=this._pos;return this.skipCodeUnitsWhile(t),this.sliceBack(e)}skipCodeUnitsWhile(t){for(;this._pos<this._end&&t(this.currCodeUnitUnchecked(),this);){if(!a.isXmlChar(this.currCodeUnitUnchecked()))throw new n.XmlError({type:"NonXmlChar",char:String.fromCodePoint(this.currCodeUnitUnchecked())},this.genTextPos());this._pos+=1}}advance(t){this._pos+=t}goTo(t){this._pos=t}startsWith(t){return this._text.startsWith(t,this._pos)}skipString(t){if(!this.startsWith(t))throw new n.XmlError({type:"InvalidString",expected:t},this.genTextPos());this._pos+=t.length}sliceBack(t){return this._text.slice(t,this._pos)}rangeFrom(t){return{start:t,end:this._pos}}skipSpaces(){for(;this.startsWithSpace();)this._pos+=1}startsWithSpace(){return this._pos<this._end&&a.isXmlSpaceByte(this.currCodeUnitUnchecked())}consumeSpaces(){if(this._pos>=this._end)throw new n.XmlError({type:"UnexpectedEndOfStream"},this.genTextPos());if(!this.startsWithSpace())throw new n.XmlError({type:"InvalidChar",expected:"a whitespace",actual:this.currCodeUnitUnchecked()},this.genTextPos());this.skipSpaces()}tryConsumeReference(){const t=this._pos,e=this.clone(),r=e.consumeReference();return r!=null?(this._pos+=e.getPos()-t,r):null}consumeReference(){if(!this.tryConsumeCodeUnit(o.AMPERSAND))return null;let t;if(this.tryConsumeCodeUnit(o.HASH)){let e,r;this.tryConsumeCodeUnit(o.LOWERCASE_X)?(e=this.consumeCodeUnitsWhile(s=>s>=o.ZERO&&s<=o.NINE||s>=o.UPPERCASE_A&&s<=o.UPPERCASE_F||s>=o.LOWERCASE_A&&s<=o.LOWERCASE_F),r=16):(e=this.consumeCodeUnitsWhile(s=>a.isAsciiDigit(s)),r=10);const i=parseInt(e,r);isNaN(i)||!a.isXmlChar(i)?t=null:t={type:"Char",value:String.fromCodePoint(i)}}else{const e=this.consumeName();switch(e){case"quot":t={type:"Char",value:'"'};break;case"amp":t={type:"Char",value:"&"};break;case"apos":t={type:"Char",value:"'"};break;case"lt":t={type:"Char",value:"<"};break;case"gt":t={type:"Char",value:">"};break;default:t={type:"Entity",value:e}}}return this.tryConsumeCodeUnit(o.SEMICOLON)?t:null}consumeName(){const t=this._pos;this.skipName();const e=this.sliceBack(t);if(e.length===0)throw new n.XmlError({type:"InvalidName"},this.genTextPosFrom(t));return e}skipName(){const t=this._pos;for(;this._pos<this._end;){const e=this.currCodeUnitUnchecked();if(this._pos===t){if(!a.isXmlNameStart(e))throw new n.XmlError({type:"InvalidName"},this.genTextPosFrom(t))}else if(!a.isXmlName(e))break;this._pos+=1}}consumeQName(){var t,e;const r=this._pos;let i=null;for(;this._pos<this._end;){const d=this.currCodeUnitUnchecked();if(d===o.COLON)if(i==null)i=this._pos,this._pos+=1;else throw new n.XmlError({type:"InvalidName"},this.genTextPosFrom(r));else if(a.isXmlName(d))this._pos+=1;else break}let s,l;if(i!=null?(s=this._text.slice(r,i),l=this.sliceBack(i+1)):(s="",l=this.sliceBack(r)),s.length>0&&!a.isXmlNameStart((t=s[0])==null?void 0:t.codePointAt(0)))throw new n.XmlError({type:"InvalidName"},this.genTextPosFrom(r));if(l.length>0){if(!a.isXmlNameStart((e=l[0])==null?void 0:e.codePointAt(0)))throw new n.XmlError({type:"InvalidName"},this.genTextPosFrom(r))}else throw new n.XmlError({type:"InvalidName"},this.genTextPosFrom(r));return[s,l]}consumeQuote(){const t=this.currCodeUnit();if(t===o.SINGLE_QUOTE||t===o.DOUBLE_QUOTE)return this._pos+=1,t;throw new n.XmlError({type:"InvalidChar",expected:"a quote",actual:t},this.genTextPos())}genTextPos(){return this.genTextPosFrom(this._pos)}genTextPosFrom(t){const e=Math.min(t,this._end);let r=1,i=1;for(let s=0;s<e;s++)this._text.charCodeAt(s)===o.LINE_FEED?(r++,i=1):i++;return{row:r,col:i}}}exports.XmlStream=u;
1
+ "use strict";var n=require("./ascii-constants.js"),a=require("./utils.js"),o=require("./XmlError.js"),_=Object.defineProperty,d=Object.getOwnPropertySymbols,C=Object.prototype.hasOwnProperty,f=Object.prototype.propertyIsEnumerable,u=(h,t,e)=>t in h?_(h,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):h[t]=e,E=(h,t)=>{for(var e in t||(t={}))C.call(t,e)&&u(h,e,t[e]);if(d)for(var e of d(t))f.call(t,e)&&u(h,e,t[e]);return h},p=(h,t,e)=>u(h,typeof t!="symbol"?t+"":t,e);class m{constructor(t,e={}){p(this,"_text"),p(this,"_pos"),p(this,"_end"),p(this,"config");const{pos:r=0,strictDocument:i=!0,allowDtd:s=!0,allowBooleanAttributes:l=!1,rawTextElements:c=null}=e;this._text=t,this._pos=r,this._end=this._text.length,this.config={strictDocument:i,allowDtd:s,allowBooleanAttributes:l,rawTextElements:c}}clone(){return new m(this._text,E({pos:this._pos},this.config))}getPos(){return this._pos}atEnd(){return this._pos>=this._end}currCodeUnit(){if(this._pos>=this._end)throw new o.XmlError({type:"UnexpectedEndOfStream"});return this._text.charCodeAt(this._pos)}currCodeUnitUnchecked(){return this._text.charCodeAt(this._pos)}nextCodeUnit(){if(this._pos+1>=this._end)throw new o.XmlError({type:"UnexpectedEndOfStream"});return this._text.charCodeAt(this._pos+1)}consumeCodeUnit(t){const e=this.currCodeUnit();if(e!==t)throw new o.XmlError({type:"InvalidChar",expected:t,actual:e},this.genTextPos());this._pos+=1}tryConsumeCodeUnit(t){return this.currCodeUnit()===t?(this._pos+=1,!0):!1}consumeCodeUnitsWhile(t){const e=this._pos;return this.skipCodeUnitsWhile(t),this.sliceBack(e)}skipCodeUnitsWhile(t){for(;this._pos<this._end&&t(this.currCodeUnitUnchecked(),this);){if(!a.isXmlChar(this.currCodeUnitUnchecked()))throw new o.XmlError({type:"NonXmlChar",char:String.fromCodePoint(this.currCodeUnitUnchecked())},this.genTextPos());this._pos+=1}}advance(t){this._pos+=t}goTo(t){this._pos=t}startsWith(t){return this._text.startsWith(t,this._pos)}skipString(t){if(!this.startsWith(t))throw new o.XmlError({type:"InvalidString",expected:t},this.genTextPos());this._pos+=t.length}sliceBack(t){return this._text.slice(t,this._pos)}rangeFrom(t){return{start:t,end:this._pos}}skipSpaces(){for(;this.startsWithSpace();)this._pos+=1}startsWithSpace(){return this._pos<this._end&&a.isXmlSpaceByte(this.currCodeUnitUnchecked())}consumeSpaces(){if(this._pos>=this._end)throw new o.XmlError({type:"UnexpectedEndOfStream"},this.genTextPos());if(!this.startsWithSpace())throw new o.XmlError({type:"InvalidChar",expected:"a whitespace",actual:this.currCodeUnitUnchecked()},this.genTextPos());this.skipSpaces()}tryConsumeReference(){const t=this._pos,e=this.clone(),r=e.consumeReference();return r!=null?(this._pos+=e.getPos()-t,r):null}consumeReference(){if(!this.tryConsumeCodeUnit(n.AMPERSAND))return null;let t;if(this.tryConsumeCodeUnit(n.HASH)){let e,r;this.tryConsumeCodeUnit(n.LOWERCASE_X)?(e=this.consumeCodeUnitsWhile(s=>s>=n.ZERO&&s<=n.NINE||s>=n.UPPERCASE_A&&s<=n.UPPERCASE_F||s>=n.LOWERCASE_A&&s<=n.LOWERCASE_F),r=16):(e=this.consumeCodeUnitsWhile(s=>a.isAsciiDigit(s)),r=10);const i=parseInt(e,r);isNaN(i)||!a.isXmlChar(i)?t=null:t={type:"Char",value:String.fromCodePoint(i)}}else{const e=this.consumeName();switch(e){case"quot":t={type:"Char",value:'"'};break;case"amp":t={type:"Char",value:"&"};break;case"apos":t={type:"Char",value:"'"};break;case"lt":t={type:"Char",value:"<"};break;case"gt":t={type:"Char",value:">"};break;default:t={type:"Entity",value:e}}}return this.tryConsumeCodeUnit(n.SEMICOLON)?t:null}consumeName(){const t=this._pos;this.skipName();const e=this.sliceBack(t);if(e.length===0)throw new o.XmlError({type:"InvalidName"},this.genTextPosFrom(t));return e}skipName(){const t=this._pos;for(;this._pos<this._end;){const e=this.currCodeUnitUnchecked();if(this._pos===t){if(!a.isXmlNameStart(e))throw new o.XmlError({type:"InvalidName"},this.genTextPosFrom(t))}else if(!a.isXmlName(e))break;this._pos+=1}}consumeQName(){var t,e;const r=this._pos;let i=null;for(;this._pos<this._end;){const c=this.currCodeUnitUnchecked();if(c===n.COLON)if(i==null)i=this._pos,this._pos+=1;else throw new o.XmlError({type:"InvalidName"},this.genTextPosFrom(r));else if(a.isXmlName(c))this._pos+=1;else break}let s,l;if(i!=null?(s=this._text.slice(r,i),l=this.sliceBack(i+1)):(s="",l=this.sliceBack(r)),s.length>0&&!a.isXmlNameStart((t=s[0])==null?void 0:t.codePointAt(0)))throw new o.XmlError({type:"InvalidName"},this.genTextPosFrom(r));if(l.length>0){if(!a.isXmlNameStart((e=l[0])==null?void 0:e.codePointAt(0)))throw new o.XmlError({type:"InvalidName"},this.genTextPosFrom(r))}else throw new o.XmlError({type:"InvalidName"},this.genTextPosFrom(r));return[s,l]}consumeQuote(){const t=this.currCodeUnit();if(t===n.SINGLE_QUOTE||t===n.DOUBLE_QUOTE)return this._pos+=1,t;throw new o.XmlError({type:"InvalidChar",expected:"a quote",actual:t},this.genTextPos())}genTextPos(){return this.genTextPosFrom(this._pos)}genTextPosFrom(t){const e=Math.min(t,this._end);let r=1,i=1;for(let s=0;s<e;s++)this._text.charCodeAt(s)===n.LINE_FEED?(r++,i=1):i++;return{row:r,col:i}}}exports.XmlStream=m;
@@ -1 +1 @@
1
- "use strict";var e=require("./ascii-constants.js"),a=require("./XmlError.js"),R=require("./XmlStream.js");const _="\uFEFF",g="<?xml ",C="?>",I="<!ENTITY",X="<!ELEMENT",H="<!ATTLIST",L="<!NOTATION",F="<!DOCTYPE",U="<?",k="?>",m="<!--",A="-->",Q="<![CDATA[",E="]]>",D="NDATA",w="PUBLIC",O="SYSTEM",G="version",b="encoding",B="standalone";function M(t,n,s={}){P(new R.XmlStream(t,s),n)}function P(t,n){if(t.startsWith(_)&&t.advance(1),t.startsWith(g)&&K(t),d(t,n),t.skipSpaces(),t.startsWith(F)){if(!t.config.allowDtd)throw new a.XmlError({type:"DtdDetected"});z(t,n),d(t,n)}if(t.skipSpaces(),t.config.strictDocument){if(!t.atEnd()&&t.currCodeUnit()===e.LESS_THAN&&S(t,n),d(t,n),!t.atEnd())throw new a.XmlError({type:"UnknownToken",message:"Not at end"},t.genTextPos())}else for(;!t.atEnd();)t.currCodeUnit()===e.LESS_THAN?S(t,n):y(t,n),d(t,n)}function d(t,n){for(;!t.atEnd();)if(t.skipSpaces(),t.startsWith(m))f(t,n);else if(t.startsWith(U))h(t,n);else break}function K(t){function n(s){if(s.startsWithSpace())s.skipSpaces();else if(!s.startsWith(C)&&!s.atEnd())throw new a.XmlError({type:"InvalidChar",expected:"a whitespace",actual:s.currCodeUnitUnchecked()},s.genTextPos())}if(t.advance(5),n(t),!t.startsWith(G))throw new a.XmlError({type:"InvalidString",expected:"version"},t.genTextPos());p(t),n(t),t.startsWith(b)&&(p(t),n(t)),t.startsWith(B)&&p(t),t.skipSpaces(),t.skipString(C)}function f(t,n){const s=t.getPos();t.advance(4);const o=t.consumeCodeUnitsWhile((r,i)=>!(r===e.HYPHEN&&i.startsWith(A)));if(t.skipString(A),o.includes("--")||o.endsWith("-"))throw new a.XmlError({type:"InvalidComment"},t.genTextPosFrom(s));n({type:"Comment",text:o,range:t.rangeFrom(s)})}function h(t,n){if(t.startsWith(g))throw new a.XmlError({type:"UnexpectedDeclaration"},t.genTextPos());const s=t.getPos();t.advance(2);const o=t.consumeName();t.skipSpaces();const r=t.consumeCodeUnitsWhile((i,c)=>!(i===e.QUESTION_MARK&&c.startsWith(k)));t.skipString(k),n({type:"ProcessingInstruction",target:o,content:r.length===0?void 0:r,range:t.rangeFrom(s)})}function z(t,n){const s=t.getPos();if(Y(t),t.skipSpaces(),t.currCodeUnit()===e.GREATER_THAN){t.advance(1);return}for(t.advance(1);!t.atEnd();)if(t.skipSpaces(),t.startsWith(I))q(t,n);else if(t.startsWith(m))f(t,n);else if(t.startsWith(U))h(t,n);else if(t.startsWith("]"))if(t.advance(1),t.skipSpaces(),t.currCodeUnit()===e.GREATER_THAN){t.advance(1);break}else throw new a.XmlError({type:"InvalidChar",expected:"'>'",actual:t.currCodeUnitUnchecked()},t.genTextPos());else if(t.startsWith(X)||t.startsWith(H)||t.startsWith(L))try{J(t)}catch(o){throw new a.XmlError({type:"UnknownToken",message:"Failed to consume declaration"},t.genTextPosFrom(s))}else throw new a.XmlError({type:"UnknownToken",message:"Failed to parse doctype"},t.genTextPos())}function Y(t){t.advance(9),t.consumeSpaces(),t.skipName(),t.skipSpaces(),W(t),t.skipSpaces();const n=t.currCodeUnit();if(n!==e.OPEN_SQUARE_BRACKET&&n!==e.GREATER_THAN)throw new a.XmlError({type:"InvalidChar",expected:"'[' or '>'",actual:n},t.genTextPos())}function W(t){if(t.startsWith(O)||t.startsWith(w)){const n=t.getPos();t.advance(6);const s=t.sliceBack(n);t.consumeSpaces();const o=t.consumeQuote();if(t.consumeCodeUnitsWhile(r=>r!==o),t.consumeCodeUnit(o),s===w){t.consumeSpaces();const r=t.consumeQuote();t.consumeCodeUnitsWhile(i=>i!==r),t.consumeCodeUnit(r)}return!0}return!1}function q(t,n){t.advance(8),t.consumeSpaces();const s=!t.tryConsumeCodeUnit(e.PERCENT);s||t.consumeSpaces();const o=t.consumeName();t.consumeSpaces();const r=j(t,s);r!==null&&n({type:"EntityDeclaration",name:o,definition:r}),t.skipSpaces(),t.consumeCodeUnit(e.GREATER_THAN)}function j(t,n){const s=t.currCodeUnit();if(s===e.DOUBLE_QUOTE||s===e.SINGLE_QUOTE){const o=t.consumeQuote(),r=t.getPos();t.skipCodeUnitsWhile(c=>c!==o);const i=t.sliceBack(r);return t.consumeCodeUnit(o),i}else if(s===e.UPPERCASE_S||s===e.UPPERCASE_P){if(W(t))return n&&(t.skipSpaces(),t.startsWith(D)&&(t.advance(5),t.consumeSpaces(),t.skipName())),null;throw new a.XmlError({type:"InvalidExternalID"},t.genTextPos())}else throw new a.XmlError({type:"InvalidChar",expected:"a quote, SYSTEM or PUBLIC",actual:s},t.genTextPos())}function J(t){t.skipCodeUnitsWhile(n=>n!==e.GREATER_THAN),t.consumeCodeUnit(e.GREATER_THAN)}function S(t,n){const s=t.getPos();t.advance(1);const[o,r]=t.consumeQName();n({type:"ElementStart",prefix:o,local:r,start:s});let i=!1;for(;!t.atEnd();){const c=t.startsWithSpace();t.skipSpaces();const u=t.getPos(),T=t.currCodeUnit();if(T===e.SLASH){t.advance(1),t.consumeCodeUnit(e.GREATER_THAN);const l=t.rangeFrom(u);n({type:"ElementEnd",end:{type:"Empty"},range:l});break}else if(T===e.GREATER_THAN){t.advance(1);const l=t.rangeFrom(u);n({type:"ElementEnd",end:{type:"Open"},range:l}),i=!0;break}else{if(!c)throw new a.XmlError({type:"InvalidChar",expected:"a whitespace",actual:t.currCodeUnitUnchecked()},t.genTextPos());const[l,N,v]=p(t),x=t.getPos();n({type:"Attribute",range:{start:u,end:x},prefix:l,local:N,value:v})}}i&&V(t,n)}function p(t){const[n,s]=t.consumeQName();let o;const r=t.getPos();if(t.skipSpaces(),t.tryConsumeCodeUnit(e.EQUALS)){t.skipSpaces();const i=t.consumeQuote();o=t.consumeCodeUnitsWhile(c=>c!==i&&c!==e.LESS_THAN),t.consumeCodeUnit(i)}else if(t.config.allowBooleanAttributes)t.goTo(r),o="true";else throw new a.XmlError({type:"InvalidChar",expected:e.EQUALS,actual:t.currCodeUnit()},t.genTextPos());return[n,s,o]}function V(t,n){for(;!t.atEnd();)if(t.currCodeUnit()===e.LESS_THAN){const s=t.nextCodeUnit();if(s===e.EXCLAMATION_MARK)if(t.startsWith(m))f(t,n);else if(t.startsWith(Q))Z(t,n);else throw new a.XmlError({type:"UnknownToken",message:"Failed to parse content"},t.genTextPos());else if(s===e.QUESTION_MARK)h(t,n);else if(s===e.SLASH){$(t,n);break}else S(t,n)}else y(t,n)}function Z(t,n){const s=t.getPos();t.advance(9);const o=t.consumeCodeUnitsWhile((i,c)=>!(i===e.CLOSE_SQUARE_BRACKET&&c.startsWith(E)));t.skipString(E);const r=t.rangeFrom(s);n({type:"Cdata",text:o,range:r})}function $(t,n){const s=t.getPos();t.advance(2);const[o,r]=t.consumeQName();t.skipSpaces(),t.consumeCodeUnit(e.GREATER_THAN);const i=t.rangeFrom(s);n({type:"ElementEnd",end:{type:"Close",prefix:o,local:r},range:i})}function y(t,n){const s=t.getPos(),o=t.consumeCodeUnitsWhile(r=>r!==e.LESS_THAN);if(o.includes(E))throw new a.XmlError({type:"InvalidCharacterData"},t.genTextPos());n({type:"Text",text:o,range:t.rangeFrom(s)})}exports.tokenize=M,exports.tokenizeXmlStream=P;
1
+ "use strict";var I=require("../get-q-name.js"),o=require("./ascii-constants.js"),a=require("./XmlError.js"),X=require("./XmlStream.js");const H="\uFEFF",g="<?xml ",C="?>",L="<!ENTITY",Q="<!ELEMENT",F="<!ATTLIST",D="<!NOTATION",U="<!DOCTYPE",k="<?",A="?>",p="<!--",w="-->",O="<![CDATA[",E="]]>",G="NDATA",W="PUBLIC",b="SYSTEM",B="version",M="encoding",K="standalone";function q(t,n,e={}){P(new X.XmlStream(t,e),n)}function P(t,n){if(t.startsWith(H)&&t.advance(1),t.startsWith(g)&&z(t),u(t,n),t.skipSpaces(),t.startsWith(U)||t.startsWith(U.toLowerCase())){if(!t.config.allowDtd)throw new a.XmlError({type:"DtdDetected"});Y(t,n),u(t,n)}if(t.skipSpaces(),t.config.strictDocument){if(!t.atEnd()&&t.currCodeUnit()===o.LESS_THAN&&T(t,n),u(t,n),!t.atEnd())throw new a.XmlError({type:"UnknownToken",message:"Not at end"},t.genTextPos())}else for(;!t.atEnd();)t.currCodeUnit()===o.LESS_THAN?T(t,n):x(t,n),u(t,n)}function u(t,n){for(;!t.atEnd();)if(t.skipSpaces(),t.startsWith(p))f(t,n);else if(t.startsWith(k))h(t,n);else break}function z(t){function n(e){if(e.startsWithSpace())e.skipSpaces();else if(!e.startsWith(C)&&!e.atEnd())throw new a.XmlError({type:"InvalidChar",expected:"a whitespace",actual:e.currCodeUnitUnchecked()},e.genTextPos())}if(t.advance(5),n(t),!t.startsWith(B))throw new a.XmlError({type:"InvalidString",expected:"version"},t.genTextPos());d(t),n(t),t.startsWith(M)&&(d(t),n(t)),t.startsWith(K)&&d(t),t.skipSpaces(),t.skipString(C)}function f(t,n){const e=t.getPos();t.advance(4);const s=t.consumeCodeUnitsWhile((r,i)=>!(r===o.HYPHEN&&i.startsWith(w)));if(t.skipString(w),s.includes("--")||s.endsWith("-"))throw new a.XmlError({type:"InvalidComment"},t.genTextPosFrom(e));n({type:"Comment",text:s,range:t.rangeFrom(e)})}function h(t,n){if(t.startsWith(g))throw new a.XmlError({type:"UnexpectedDeclaration"},t.genTextPos());const e=t.getPos();t.advance(2);const s=t.consumeName();t.skipSpaces();const r=t.consumeCodeUnitsWhile((i,c)=>!(i===o.QUESTION_MARK&&c.startsWith(A)));t.skipString(A),n({type:"ProcessingInstruction",target:s,content:r.length===0?void 0:r,range:t.rangeFrom(e)})}function Y(t,n){const e=t.getPos();if($(t),t.skipSpaces(),t.currCodeUnit()===o.GREATER_THAN){t.advance(1);return}for(t.advance(1);!t.atEnd();)if(t.skipSpaces(),t.startsWith(L))j(t,n);else if(t.startsWith(p))f(t,n);else if(t.startsWith(k))h(t,n);else if(t.startsWith("]"))if(t.advance(1),t.skipSpaces(),t.currCodeUnit()===o.GREATER_THAN){t.advance(1);break}else throw new a.XmlError({type:"InvalidChar",expected:"'>'",actual:t.currCodeUnitUnchecked()},t.genTextPos());else if(t.startsWith(Q)||t.startsWith(F)||t.startsWith(D))try{V(t)}catch(s){throw new a.XmlError({type:"UnknownToken",message:"Failed to consume declaration"},t.genTextPosFrom(e))}else throw new a.XmlError({type:"UnknownToken",message:"Failed to parse doctype"},t.genTextPos())}function $(t){t.advance(9),t.consumeSpaces(),t.skipName(),t.skipSpaces(),y(t),t.skipSpaces();const n=t.currCodeUnit();if(n!==o.OPEN_SQUARE_BRACKET&&n!==o.GREATER_THAN)throw new a.XmlError({type:"InvalidChar",expected:"'[' or '>'",actual:n},t.genTextPos())}function y(t){if(t.startsWith(b)||t.startsWith(W)){const n=t.getPos();t.advance(6);const e=t.sliceBack(n);t.consumeSpaces();const s=t.consumeQuote();if(t.consumeCodeUnitsWhile(r=>r!==s),t.consumeCodeUnit(s),e===W){t.consumeSpaces();const r=t.consumeQuote();t.consumeCodeUnitsWhile(i=>i!==r),t.consumeCodeUnit(r)}return!0}return!1}function j(t,n){t.advance(8),t.consumeSpaces();const e=!t.tryConsumeCodeUnit(o.PERCENT);e||t.consumeSpaces();const s=t.consumeName();t.consumeSpaces();const r=J(t,e);r!==null&&n({type:"EntityDeclaration",name:s,definition:r}),t.skipSpaces(),t.consumeCodeUnit(o.GREATER_THAN)}function J(t,n){const e=t.currCodeUnit();if(e===o.DOUBLE_QUOTE||e===o.SINGLE_QUOTE){const s=t.consumeQuote(),r=t.getPos();t.skipCodeUnitsWhile(c=>c!==s);const i=t.sliceBack(r);return t.consumeCodeUnit(s),i}else if(e===o.UPPERCASE_S||e===o.UPPERCASE_P){if(y(t))return n&&(t.skipSpaces(),t.startsWith(G)&&(t.advance(5),t.consumeSpaces(),t.skipName())),null;throw new a.XmlError({type:"InvalidExternalID"},t.genTextPos())}else throw new a.XmlError({type:"InvalidChar",expected:"a quote, SYSTEM or PUBLIC",actual:e},t.genTextPos())}function V(t){t.skipCodeUnitsWhile(n=>n!==o.GREATER_THAN),t.consumeCodeUnit(o.GREATER_THAN)}function T(t,n){const e=t.getPos();t.advance(1);const[s,r]=t.consumeQName();n({type:"ElementStart",prefix:s,local:r,start:e});let i=!1;for(;!t.atEnd();){const c=t.startsWithSpace();t.skipSpaces();const m=t.getPos(),S=t.currCodeUnit();if(S===o.SLASH){t.advance(1),t.consumeCodeUnit(o.GREATER_THAN);const l=t.rangeFrom(m);n({type:"ElementEnd",end:{type:"Empty"},range:l});break}else if(S===o.GREATER_THAN){t.advance(1);const l=t.rangeFrom(m);n({type:"ElementEnd",end:{type:"Open"},range:l}),i=!0;break}else{if(!c)throw new a.XmlError({type:"InvalidChar",expected:"a whitespace",actual:t.currCodeUnitUnchecked()},t.genTextPos());const[l,v,R]=d(t),_=t.getPos();n({type:"Attribute",range:{start:m,end:_},prefix:l,local:v,value:R})}}if(i){if(t.config.rawTextElements!=null){const c=I.getQName(r,s);if(t.config.rawTextElements.includes(c)){N(t,n,`</${c}>`);return}}N(t,n)}}function d(t){const[n,e]=t.consumeQName();let s;const r=t.getPos();if(t.skipSpaces(),t.tryConsumeCodeUnit(o.EQUALS)){t.skipSpaces();const i=t.consumeQuote();s=t.consumeCodeUnitsWhile(c=>c!==i&&c!==o.LESS_THAN),t.consumeCodeUnit(i)}else if(t.config.allowBooleanAttributes)t.goTo(r),s="true";else throw new a.XmlError({type:"InvalidChar",expected:o.EQUALS,actual:t.currCodeUnit()},t.genTextPos());return[n,e,s]}function N(t,n,e=o.LESS_THAN){for(;!t.atEnd();)if(typeof e=="number"?t.currCodeUnit()===e:t.startsWith(e)){const s=t.nextCodeUnit();if(s===o.EXCLAMATION_MARK)if(t.startsWith(p))f(t,n);else if(t.startsWith(O))Z(t,n);else throw new a.XmlError({type:"UnknownToken",message:"Failed to parse content"},t.genTextPos());else if(s===o.QUESTION_MARK)h(t,n);else if(s===o.SLASH){tt(t,n);break}else T(t,n)}else x(t,n,e)}function Z(t,n){const e=t.getPos();t.advance(9);const s=t.consumeCodeUnitsWhile((i,c)=>!(i===o.CLOSE_SQUARE_BRACKET&&c.startsWith(E)));t.skipString(E);const r=t.rangeFrom(e);n({type:"Cdata",text:s,range:r})}function tt(t,n){const e=t.getPos();t.advance(2);const[s,r]=t.consumeQName();t.skipSpaces(),t.consumeCodeUnit(o.GREATER_THAN);const i=t.rangeFrom(e);n({type:"ElementEnd",end:{type:"Close",prefix:s,local:r},range:i})}function x(t,n,e=o.LESS_THAN){const s=t.getPos(),r=typeof e=="number"?t.consumeCodeUnitsWhile(i=>i!==e):t.consumeCodeUnitsWhile((i,c)=>!c.startsWith(e));if(r.includes(E))throw new a.XmlError({type:"InvalidCharacterData"},t.genTextPos());n({type:"Text",text:r,range:t.rangeFrom(s)})}exports.tokenize=q,exports.tokenizeXmlStream=P;
package/dist/esm/index.js CHANGED
@@ -1 +1 @@
1
- import{select as o}from"./selector/select.js";import{TokenSelector as t}from"./selector/TokenSelector.js";import{EToCacheNodeProps as A,ETokenMatchCriteria as m,TokenSelectState as R}from"./selector/TokenSelectState.js";import{TokenSelectStateMachine as T}from"./selector/TokenSelectStateMachine.js";import{tokenToXml as _}from"./token-to-xml.js";import{AMPERSAND as N,CARRIAGE_RETURN as p,CLOSE_SQUARE_BRACKET as l,COLON as P,DOUBLE_QUOTE as c,EQUALS as f,EXCLAMATION_MARK as x,GREATER_THAN as L,HASH as a,HORIZONTAL_TAB as s,HYPHEN as U,LESS_THAN as X,LINE_FEED as n,LOWERCASE_A as k,LOWERCASE_F as I,LOWERCASE_X as H,LOWERCASE_Z as M,NINE as B,OPEN_SQUARE_BRACKET as D,PERCENT as Q,PERIOD as F,QUESTION_MARK as b,SEMICOLON as h,SINGLE_QUOTE as j,SLASH as K,SPACE as W,UNDERSCORE as Z,UPPERCASE_A as d,UPPERCASE_F as G,UPPERCASE_P as y,UPPERCASE_S as z,UPPERCASE_Z as g,ZERO as Y}from"./tokenizer/ascii-constants.js";import{tokenize as u,tokenizeXmlStream as v}from"./tokenizer/tokenize.js";import{isAsciiDigit as J,isXmlChar as V,isXmlName as $,isXmlNameByte as ee,isXmlNameStart as Ee,isXmlSpaceByte as oe}from"./tokenizer/utils.js";import{XmlError as te}from"./tokenizer/XmlError.js";import{XmlStream as Ae}from"./tokenizer/XmlStream.js";import{tokensToXml as Re}from"./tokens-to-xml.js";import{processTokenForObject as Te,xmlToObject as Ce}from"./xml-to-object.js";import{processTokenForSimplifiedObject as ie,xmlToSimplifiedObject as Ne}from"./xml-to-simplified-object.js";export{N as AMPERSAND,p as CARRIAGE_RETURN,l as CLOSE_SQUARE_BRACKET,P as COLON,c as DOUBLE_QUOTE,f as EQUALS,A as EToCacheNodeProps,m as ETokenMatchCriteria,x as EXCLAMATION_MARK,L as GREATER_THAN,a as HASH,s as HORIZONTAL_TAB,U as HYPHEN,X as LESS_THAN,n as LINE_FEED,k as LOWERCASE_A,I as LOWERCASE_F,H as LOWERCASE_X,M as LOWERCASE_Z,B as NINE,D as OPEN_SQUARE_BRACKET,Q as PERCENT,F as PERIOD,b as QUESTION_MARK,h as SEMICOLON,j as SINGLE_QUOTE,K as SLASH,W as SPACE,R as TokenSelectState,T as TokenSelectStateMachine,t as TokenSelector,Z as UNDERSCORE,d as UPPERCASE_A,G as UPPERCASE_F,y as UPPERCASE_P,z as UPPERCASE_S,g as UPPERCASE_Z,te as XmlError,Ae as XmlStream,Y as ZERO,J as isAsciiDigit,V as isXmlChar,$ as isXmlName,ee as isXmlNameByte,Ee as isXmlNameStart,oe as isXmlSpaceByte,Te as processTokenForObject,ie as processTokenForSimplifiedObject,o as select,_ as tokenToXml,u as tokenize,v as tokenizeXmlStream,Re as tokensToXml,Ce as xmlToObject,Ne as xmlToSimplifiedObject};
1
+ import{getQName as o}from"./get-q-name.js";import{select as t}from"./selector/select.js";import{TokenSelector as m}from"./selector/TokenSelector.js";import{EToCacheNodeProps as R,ETokenMatchCriteria as O,TokenSelectState as T}from"./selector/TokenSelectState.js";import{TokenSelectStateMachine as N}from"./selector/TokenSelectStateMachine.js";import{tokenToXml as i}from"./token-to-xml.js";import{AMPERSAND as l,CARRIAGE_RETURN as P,CLOSE_SQUARE_BRACKET as f,COLON as x,DOUBLE_QUOTE as a,EQUALS as c,EXCLAMATION_MARK as L,GREATER_THAN as s,HASH as U,HORIZONTAL_TAB as X,HYPHEN as n,LESS_THAN as k,LINE_FEED as I,LOWERCASE_A as H,LOWERCASE_F as M,LOWERCASE_X as Q,LOWERCASE_Z as B,NINE as D,OPEN_SQUARE_BRACKET as F,PERCENT as b,PERIOD as h,QUESTION_MARK as j,SEMICOLON as K,SINGLE_QUOTE as W,SLASH as Z,SPACE as d,UNDERSCORE as G,UPPERCASE_A as g,UPPERCASE_F as y,UPPERCASE_P as z,UPPERCASE_S as Y,UPPERCASE_Z as q,ZERO as u}from"./tokenizer/ascii-constants.js";import{tokenize as w,tokenizeXmlStream as J}from"./tokenizer/tokenize.js";import{isAsciiDigit as $,isXmlChar as ee,isXmlName as Ee,isXmlNameByte as oe,isXmlNameStart as re,isXmlSpaceByte as te}from"./tokenizer/utils.js";import{XmlError as me}from"./tokenizer/XmlError.js";import{XmlStream as Re}from"./tokenizer/XmlStream.js";import{tokensToXml as Te}from"./tokens-to-xml.js";import{processTokenForObject as Ne,xmlToObject as _e}from"./xml-to-object.js";import{processTokenForSimplifiedObject as pe,xmlToSimplifiedObject as le}from"./xml-to-simplified-object.js";export{l as AMPERSAND,P as CARRIAGE_RETURN,f as CLOSE_SQUARE_BRACKET,x as COLON,a as DOUBLE_QUOTE,c as EQUALS,R as EToCacheNodeProps,O as ETokenMatchCriteria,L as EXCLAMATION_MARK,s as GREATER_THAN,U as HASH,X as HORIZONTAL_TAB,n as HYPHEN,k as LESS_THAN,I as LINE_FEED,H as LOWERCASE_A,M as LOWERCASE_F,Q as LOWERCASE_X,B as LOWERCASE_Z,D as NINE,F as OPEN_SQUARE_BRACKET,b as PERCENT,h as PERIOD,j as QUESTION_MARK,K as SEMICOLON,W as SINGLE_QUOTE,Z as SLASH,d as SPACE,T as TokenSelectState,N as TokenSelectStateMachine,m as TokenSelector,G as UNDERSCORE,g as UPPERCASE_A,y as UPPERCASE_F,z as UPPERCASE_P,Y as UPPERCASE_S,q as UPPERCASE_Z,me as XmlError,Re as XmlStream,u as ZERO,o as getQName,$ as isAsciiDigit,ee as isXmlChar,Ee as isXmlName,oe as isXmlNameByte,re as isXmlNameStart,te as isXmlSpaceByte,Ne as processTokenForObject,pe as processTokenForSimplifiedObject,t as select,i as tokenToXml,w as tokenize,J as tokenizeXmlStream,Te as tokensToXml,_e as xmlToObject,le as xmlToSimplifiedObject};
@@ -1 +1 @@
1
- import{AMPERSAND as C,HASH as f,LOWERCASE_X as U,ZERO as w,NINE as y,UPPERCASE_A as g,UPPERCASE_F as x,LOWERCASE_A as P,LOWERCASE_F as E,SEMICOLON as k,COLON as v,SINGLE_QUOTE as S,DOUBLE_QUOTE as N,LINE_FEED as O}from"./ascii-constants.js";import{isXmlChar as d,isXmlSpaceByte as b,isAsciiDigit as A,isXmlNameStart as c,isXmlName as _}from"./utils.js";import{XmlError as o}from"./XmlError.js";var T=Object.defineProperty,m=Object.getOwnPropertySymbols,I=Object.prototype.hasOwnProperty,W=Object.prototype.propertyIsEnumerable,l=(r,t,e)=>t in r?T(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,F=(r,t)=>{for(var e in t||(t={}))I.call(t,e)&&l(r,e,t[e]);if(m)for(var e of m(t))W.call(t,e)&&l(r,e,t[e]);return r},a=(r,t,e)=>l(r,typeof t!="symbol"?t+"":t,e);class p{constructor(t,e={}){a(this,"_text"),a(this,"_pos"),a(this,"_end"),a(this,"config");const{pos:i=0,strictDocument:n=!0,allowDtd:s=!0,allowBooleanAttributes:h=!1}=e;this._text=t,this._pos=i,this._end=this._text.length,this.config={strictDocument:n,allowDtd:s,allowBooleanAttributes:h}}clone(){return new p(this._text,F({pos:this._pos},this.config))}getPos(){return this._pos}atEnd(){return this._pos>=this._end}currCodeUnit(){if(this._pos>=this._end)throw new o({type:"UnexpectedEndOfStream"});return this._text.charCodeAt(this._pos)}currCodeUnitUnchecked(){return this._text.charCodeAt(this._pos)}nextCodeUnit(){if(this._pos+1>=this._end)throw new o({type:"UnexpectedEndOfStream"});return this._text.charCodeAt(this._pos+1)}consumeCodeUnit(t){const e=this.currCodeUnit();if(e!==t)throw new o({type:"InvalidChar",expected:t,actual:e},this.genTextPos());this._pos+=1}tryConsumeCodeUnit(t){return this.currCodeUnit()===t?(this._pos+=1,!0):!1}consumeCodeUnitsWhile(t){const e=this._pos;return this.skipCodeUnitsWhile(t),this.sliceBack(e)}skipCodeUnitsWhile(t){for(;this._pos<this._end&&t(this.currCodeUnitUnchecked(),this);){if(!d(this.currCodeUnitUnchecked()))throw new o({type:"NonXmlChar",char:String.fromCodePoint(this.currCodeUnitUnchecked())},this.genTextPos());this._pos+=1}}advance(t){this._pos+=t}goTo(t){this._pos=t}startsWith(t){return this._text.startsWith(t,this._pos)}skipString(t){if(!this.startsWith(t))throw new o({type:"InvalidString",expected:t},this.genTextPos());this._pos+=t.length}sliceBack(t){return this._text.slice(t,this._pos)}rangeFrom(t){return{start:t,end:this._pos}}skipSpaces(){for(;this.startsWithSpace();)this._pos+=1}startsWithSpace(){return this._pos<this._end&&b(this.currCodeUnitUnchecked())}consumeSpaces(){if(this._pos>=this._end)throw new o({type:"UnexpectedEndOfStream"},this.genTextPos());if(!this.startsWithSpace())throw new o({type:"InvalidChar",expected:"a whitespace",actual:this.currCodeUnitUnchecked()},this.genTextPos());this.skipSpaces()}tryConsumeReference(){const t=this._pos,e=this.clone(),i=e.consumeReference();return i!=null?(this._pos+=e.getPos()-t,i):null}consumeReference(){if(!this.tryConsumeCodeUnit(C))return null;let t;if(this.tryConsumeCodeUnit(f)){let e,i;this.tryConsumeCodeUnit(U)?(e=this.consumeCodeUnitsWhile(s=>s>=w&&s<=y||s>=g&&s<=x||s>=P&&s<=E),i=16):(e=this.consumeCodeUnitsWhile(s=>A(s)),i=10);const n=parseInt(e,i);isNaN(n)||!d(n)?t=null:t={type:"Char",value:String.fromCodePoint(n)}}else{const e=this.consumeName();switch(e){case"quot":t={type:"Char",value:'"'};break;case"amp":t={type:"Char",value:"&"};break;case"apos":t={type:"Char",value:"'"};break;case"lt":t={type:"Char",value:"<"};break;case"gt":t={type:"Char",value:">"};break;default:t={type:"Entity",value:e}}}return this.tryConsumeCodeUnit(k)?t:null}consumeName(){const t=this._pos;this.skipName();const e=this.sliceBack(t);if(e.length===0)throw new o({type:"InvalidName"},this.genTextPosFrom(t));return e}skipName(){const t=this._pos;for(;this._pos<this._end;){const e=this.currCodeUnitUnchecked();if(this._pos===t){if(!c(e))throw new o({type:"InvalidName"},this.genTextPosFrom(t))}else if(!_(e))break;this._pos+=1}}consumeQName(){var t,e;const i=this._pos;let n=null;for(;this._pos<this._end;){const u=this.currCodeUnitUnchecked();if(u===v)if(n==null)n=this._pos,this._pos+=1;else throw new o({type:"InvalidName"},this.genTextPosFrom(i));else if(_(u))this._pos+=1;else break}let s,h;if(n!=null?(s=this._text.slice(i,n),h=this.sliceBack(n+1)):(s="",h=this.sliceBack(i)),s.length>0&&!c((t=s[0])==null?void 0:t.codePointAt(0)))throw new o({type:"InvalidName"},this.genTextPosFrom(i));if(h.length>0){if(!c((e=h[0])==null?void 0:e.codePointAt(0)))throw new o({type:"InvalidName"},this.genTextPosFrom(i))}else throw new o({type:"InvalidName"},this.genTextPosFrom(i));return[s,h]}consumeQuote(){const t=this.currCodeUnit();if(t===S||t===N)return this._pos+=1,t;throw new o({type:"InvalidChar",expected:"a quote",actual:t},this.genTextPos())}genTextPos(){return this.genTextPosFrom(this._pos)}genTextPosFrom(t){const e=Math.min(t,this._end);let i=1,n=1;for(let s=0;s<e;s++)this._text.charCodeAt(s)===O?(i++,n=1):n++;return{row:i,col:n}}}export{p as XmlStream};
1
+ import{AMPERSAND as C,HASH as f,LOWERCASE_X as w,ZERO as U,NINE as y,UPPERCASE_A as x,UPPERCASE_F as g,LOWERCASE_A as E,LOWERCASE_F as P,SEMICOLON as k,COLON as v,SINGLE_QUOTE as S,DOUBLE_QUOTE as N,LINE_FEED as O}from"./ascii-constants.js";import{isXmlChar as d,isXmlSpaceByte as T,isAsciiDigit as b,isXmlNameStart as l,isXmlName as _}from"./utils.js";import{XmlError as o}from"./XmlError.js";var A=Object.defineProperty,m=Object.getOwnPropertySymbols,I=Object.prototype.hasOwnProperty,W=Object.prototype.propertyIsEnumerable,p=(r,t,e)=>t in r?A(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,F=(r,t)=>{for(var e in t||(t={}))I.call(t,e)&&p(r,e,t[e]);if(m)for(var e of m(t))W.call(t,e)&&p(r,e,t[e]);return r},c=(r,t,e)=>p(r,typeof t!="symbol"?t+"":t,e);class u{constructor(t,e={}){c(this,"_text"),c(this,"_pos"),c(this,"_end"),c(this,"config");const{pos:i=0,strictDocument:n=!0,allowDtd:s=!0,allowBooleanAttributes:h=!1,rawTextElements:a=null}=e;this._text=t,this._pos=i,this._end=this._text.length,this.config={strictDocument:n,allowDtd:s,allowBooleanAttributes:h,rawTextElements:a}}clone(){return new u(this._text,F({pos:this._pos},this.config))}getPos(){return this._pos}atEnd(){return this._pos>=this._end}currCodeUnit(){if(this._pos>=this._end)throw new o({type:"UnexpectedEndOfStream"});return this._text.charCodeAt(this._pos)}currCodeUnitUnchecked(){return this._text.charCodeAt(this._pos)}nextCodeUnit(){if(this._pos+1>=this._end)throw new o({type:"UnexpectedEndOfStream"});return this._text.charCodeAt(this._pos+1)}consumeCodeUnit(t){const e=this.currCodeUnit();if(e!==t)throw new o({type:"InvalidChar",expected:t,actual:e},this.genTextPos());this._pos+=1}tryConsumeCodeUnit(t){return this.currCodeUnit()===t?(this._pos+=1,!0):!1}consumeCodeUnitsWhile(t){const e=this._pos;return this.skipCodeUnitsWhile(t),this.sliceBack(e)}skipCodeUnitsWhile(t){for(;this._pos<this._end&&t(this.currCodeUnitUnchecked(),this);){if(!d(this.currCodeUnitUnchecked()))throw new o({type:"NonXmlChar",char:String.fromCodePoint(this.currCodeUnitUnchecked())},this.genTextPos());this._pos+=1}}advance(t){this._pos+=t}goTo(t){this._pos=t}startsWith(t){return this._text.startsWith(t,this._pos)}skipString(t){if(!this.startsWith(t))throw new o({type:"InvalidString",expected:t},this.genTextPos());this._pos+=t.length}sliceBack(t){return this._text.slice(t,this._pos)}rangeFrom(t){return{start:t,end:this._pos}}skipSpaces(){for(;this.startsWithSpace();)this._pos+=1}startsWithSpace(){return this._pos<this._end&&T(this.currCodeUnitUnchecked())}consumeSpaces(){if(this._pos>=this._end)throw new o({type:"UnexpectedEndOfStream"},this.genTextPos());if(!this.startsWithSpace())throw new o({type:"InvalidChar",expected:"a whitespace",actual:this.currCodeUnitUnchecked()},this.genTextPos());this.skipSpaces()}tryConsumeReference(){const t=this._pos,e=this.clone(),i=e.consumeReference();return i!=null?(this._pos+=e.getPos()-t,i):null}consumeReference(){if(!this.tryConsumeCodeUnit(C))return null;let t;if(this.tryConsumeCodeUnit(f)){let e,i;this.tryConsumeCodeUnit(w)?(e=this.consumeCodeUnitsWhile(s=>s>=U&&s<=y||s>=x&&s<=g||s>=E&&s<=P),i=16):(e=this.consumeCodeUnitsWhile(s=>b(s)),i=10);const n=parseInt(e,i);isNaN(n)||!d(n)?t=null:t={type:"Char",value:String.fromCodePoint(n)}}else{const e=this.consumeName();switch(e){case"quot":t={type:"Char",value:'"'};break;case"amp":t={type:"Char",value:"&"};break;case"apos":t={type:"Char",value:"'"};break;case"lt":t={type:"Char",value:"<"};break;case"gt":t={type:"Char",value:">"};break;default:t={type:"Entity",value:e}}}return this.tryConsumeCodeUnit(k)?t:null}consumeName(){const t=this._pos;this.skipName();const e=this.sliceBack(t);if(e.length===0)throw new o({type:"InvalidName"},this.genTextPosFrom(t));return e}skipName(){const t=this._pos;for(;this._pos<this._end;){const e=this.currCodeUnitUnchecked();if(this._pos===t){if(!l(e))throw new o({type:"InvalidName"},this.genTextPosFrom(t))}else if(!_(e))break;this._pos+=1}}consumeQName(){var t,e;const i=this._pos;let n=null;for(;this._pos<this._end;){const a=this.currCodeUnitUnchecked();if(a===v)if(n==null)n=this._pos,this._pos+=1;else throw new o({type:"InvalidName"},this.genTextPosFrom(i));else if(_(a))this._pos+=1;else break}let s,h;if(n!=null?(s=this._text.slice(i,n),h=this.sliceBack(n+1)):(s="",h=this.sliceBack(i)),s.length>0&&!l((t=s[0])==null?void 0:t.codePointAt(0)))throw new o({type:"InvalidName"},this.genTextPosFrom(i));if(h.length>0){if(!l((e=h[0])==null?void 0:e.codePointAt(0)))throw new o({type:"InvalidName"},this.genTextPosFrom(i))}else throw new o({type:"InvalidName"},this.genTextPosFrom(i));return[s,h]}consumeQuote(){const t=this.currCodeUnit();if(t===S||t===N)return this._pos+=1,t;throw new o({type:"InvalidChar",expected:"a quote",actual:t},this.genTextPos())}genTextPos(){return this.genTextPosFrom(this._pos)}genTextPosFrom(t){const e=Math.min(t,this._end);let i=1,n=1;for(let s=0;s<e;s++)this._text.charCodeAt(s)===O?(i++,n=1):n++;return{row:i,col:n}}}export{u as XmlStream};
@@ -1 +1 @@
1
- import{LESS_THAN as d,HYPHEN as _,QUESTION_MARK as U,GREATER_THAN as r,OPEN_SQUARE_BRACKET as L,PERCENT as O,DOUBLE_QUOTE as R,SINGLE_QUOTE as b,UPPERCASE_S as B,UPPERCASE_P as H,SLASH as k,EQUALS as T,EXCLAMATION_MARK as M,CLOSE_SQUARE_BRACKET as K}from"./ascii-constants.js";import{XmlError as a}from"./XmlError.js";import{XmlStream as Y}from"./XmlStream.js";const X="\uFEFF",w="<?xml ",P="?>",z="<!ENTITY",G="<!ELEMENT",j="<!ATTLIST",q="<!NOTATION",J="<!DOCTYPE",W="<?",y="?>",f="<!--",x="-->",V="<![CDATA[",h="]]>",Z="NDATA",v="PUBLIC",$="SYSTEM",tt="version",nt="encoding",st="standalone";function et(t,n,s={}){A(new Y(t,s),n)}function A(t,n){if(t.startsWith(X)&&t.advance(1),t.startsWith(w)&&ot(t),u(t,n),t.skipSpaces(),t.startsWith(J)){if(!t.config.allowDtd)throw new a({type:"DtdDetected"});it(t,n),u(t,n)}if(t.skipSpaces(),t.config.strictDocument){if(!t.atEnd()&&t.currCodeUnit()===d&&S(t,n),u(t,n),!t.atEnd())throw new a({type:"UnknownToken",message:"Not at end"},t.genTextPos())}else for(;!t.atEnd();)t.currCodeUnit()===d?S(t,n):I(t,n),u(t,n)}function u(t,n){for(;!t.atEnd();)if(t.skipSpaces(),t.startsWith(f))g(t,n);else if(t.startsWith(W))C(t,n);else break}function ot(t){function n(s){if(s.startsWithSpace())s.skipSpaces();else if(!s.startsWith(P)&&!s.atEnd())throw new a({type:"InvalidChar",expected:"a whitespace",actual:s.currCodeUnitUnchecked()},s.genTextPos())}if(t.advance(5),n(t),!t.startsWith(tt))throw new a({type:"InvalidString",expected:"version"},t.genTextPos());l(t),n(t),t.startsWith(nt)&&(l(t),n(t)),t.startsWith(st)&&l(t),t.skipSpaces(),t.skipString(P)}function g(t,n){const s=t.getPos();t.advance(4);const e=t.consumeCodeUnitsWhile((o,i)=>!(o===_&&i.startsWith(x)));if(t.skipString(x),e.includes("--")||e.endsWith("-"))throw new a({type:"InvalidComment"},t.genTextPosFrom(s));n({type:"Comment",text:e,range:t.rangeFrom(s)})}function C(t,n){if(t.startsWith(w))throw new a({type:"UnexpectedDeclaration"},t.genTextPos());const s=t.getPos();t.advance(2);const e=t.consumeName();t.skipSpaces();const o=t.consumeCodeUnitsWhile((i,c)=>!(i===U&&c.startsWith(y)));t.skipString(y),n({type:"ProcessingInstruction",target:e,content:o.length===0?void 0:o,range:t.rangeFrom(s)})}function it(t,n){const s=t.getPos();if(at(t),t.skipSpaces(),t.currCodeUnit()===r){t.advance(1);return}for(t.advance(1);!t.atEnd();)if(t.skipSpaces(),t.startsWith(z))ct(t,n);else if(t.startsWith(f))g(t,n);else if(t.startsWith(W))C(t,n);else if(t.startsWith("]"))if(t.advance(1),t.skipSpaces(),t.currCodeUnit()===r){t.advance(1);break}else throw new a({type:"InvalidChar",expected:"'>'",actual:t.currCodeUnitUnchecked()},t.genTextPos());else if(t.startsWith(G)||t.startsWith(j)||t.startsWith(q))try{pt(t)}catch(e){throw new a({type:"UnknownToken",message:"Failed to consume declaration"},t.genTextPosFrom(s))}else throw new a({type:"UnknownToken",message:"Failed to parse doctype"},t.genTextPos())}function at(t){t.advance(9),t.consumeSpaces(),t.skipName(),t.skipSpaces(),N(t),t.skipSpaces();const n=t.currCodeUnit();if(n!==L&&n!==r)throw new a({type:"InvalidChar",expected:"'[' or '>'",actual:n},t.genTextPos())}function N(t){if(t.startsWith($)||t.startsWith(v)){const n=t.getPos();t.advance(6);const s=t.sliceBack(n);t.consumeSpaces();const e=t.consumeQuote();if(t.consumeCodeUnitsWhile(o=>o!==e),t.consumeCodeUnit(e),s===v){t.consumeSpaces();const o=t.consumeQuote();t.consumeCodeUnitsWhile(i=>i!==o),t.consumeCodeUnit(o)}return!0}return!1}function ct(t,n){t.advance(8),t.consumeSpaces();const s=!t.tryConsumeCodeUnit(O);s||t.consumeSpaces();const e=t.consumeName();t.consumeSpaces();const o=rt(t,s);o!==null&&n({type:"EntityDeclaration",name:e,definition:o}),t.skipSpaces(),t.consumeCodeUnit(r)}function rt(t,n){const s=t.currCodeUnit();if(s===R||s===b){const e=t.consumeQuote(),o=t.getPos();t.skipCodeUnitsWhile(c=>c!==e);const i=t.sliceBack(o);return t.consumeCodeUnit(e),i}else if(s===B||s===H){if(N(t))return n&&(t.skipSpaces(),t.startsWith(Z)&&(t.advance(5),t.consumeSpaces(),t.skipName())),null;throw new a({type:"InvalidExternalID"},t.genTextPos())}else throw new a({type:"InvalidChar",expected:"a quote, SYSTEM or PUBLIC",actual:s},t.genTextPos())}function pt(t){t.skipCodeUnitsWhile(n=>n!==r),t.consumeCodeUnit(r)}function S(t,n){const s=t.getPos();t.advance(1);const[e,o]=t.consumeQName();n({type:"ElementStart",prefix:e,local:o,start:s});let i=!1;for(;!t.atEnd();){const c=t.startsWithSpace();t.skipSpaces();const m=t.getPos(),E=t.currCodeUnit();if(E===k){t.advance(1),t.consumeCodeUnit(r);const p=t.rangeFrom(m);n({type:"ElementEnd",end:{type:"Empty"},range:p});break}else if(E===r){t.advance(1);const p=t.rangeFrom(m);n({type:"ElementEnd",end:{type:"Open"},range:p}),i=!0;break}else{if(!c)throw new a({type:"InvalidChar",expected:"a whitespace",actual:t.currCodeUnitUnchecked()},t.genTextPos());const[p,F,D]=l(t),Q=t.getPos();n({type:"Attribute",range:{start:m,end:Q},prefix:p,local:F,value:D})}}i&&dt(t,n)}function l(t){const[n,s]=t.consumeQName();let e;const o=t.getPos();if(t.skipSpaces(),t.tryConsumeCodeUnit(T)){t.skipSpaces();const i=t.consumeQuote();e=t.consumeCodeUnitsWhile(c=>c!==i&&c!==d),t.consumeCodeUnit(i)}else if(t.config.allowBooleanAttributes)t.goTo(o),e="true";else throw new a({type:"InvalidChar",expected:T,actual:t.currCodeUnit()},t.genTextPos());return[n,s,e]}function dt(t,n){for(;!t.atEnd();)if(t.currCodeUnit()===d){const s=t.nextCodeUnit();if(s===M)if(t.startsWith(f))g(t,n);else if(t.startsWith(V))ut(t,n);else throw new a({type:"UnknownToken",message:"Failed to parse content"},t.genTextPos());else if(s===U)C(t,n);else if(s===k){lt(t,n);break}else S(t,n)}else I(t,n)}function ut(t,n){const s=t.getPos();t.advance(9);const e=t.consumeCodeUnitsWhile((i,c)=>!(i===K&&c.startsWith(h)));t.skipString(h);const o=t.rangeFrom(s);n({type:"Cdata",text:e,range:o})}function lt(t,n){const s=t.getPos();t.advance(2);const[e,o]=t.consumeQName();t.skipSpaces(),t.consumeCodeUnit(r);const i=t.rangeFrom(s);n({type:"ElementEnd",end:{type:"Close",prefix:e,local:o},range:i})}function I(t,n){const s=t.getPos(),e=t.consumeCodeUnitsWhile(o=>o!==d);if(e.includes(h))throw new a({type:"InvalidCharacterData"},t.genTextPos());n({type:"Text",text:e,range:t.rangeFrom(s)})}export{et as tokenize,A as tokenizeXmlStream};
1
+ import{getQName as O}from"../get-q-name.js";import{LESS_THAN as d,HYPHEN as R,QUESTION_MARK as U,GREATER_THAN as r,OPEN_SQUARE_BRACKET as b,PERCENT as B,DOUBLE_QUOTE as M,SINGLE_QUOTE as H,UPPERCASE_S as K,UPPERCASE_P as Y,SLASH as T,EQUALS as k,EXCLAMATION_MARK as X,CLOSE_SQUARE_BRACKET as z}from"./ascii-constants.js";import{XmlError as a}from"./XmlError.js";import{XmlStream as G}from"./XmlStream.js";const $="\uFEFF",w="<?xml ",W="?>",j="<!ENTITY",q="<!ELEMENT",J="<!ATTLIST",V="<!NOTATION",P="<!DOCTYPE",y="<?",x="?>",f="<!--",v="-->",Z="<![CDATA[",h="]]>",tt="NDATA",A="PUBLIC",nt="SYSTEM",st="version",et="encoding",ot="standalone";function it(t,n,s={}){N(new G(t,s),n)}function N(t,n){if(t.startsWith($)&&t.advance(1),t.startsWith(w)&&at(t),u(t,n),t.skipSpaces(),t.startsWith(P)||t.startsWith(P.toLowerCase())){if(!t.config.allowDtd)throw new a({type:"DtdDetected"});ct(t,n),u(t,n)}if(t.skipSpaces(),t.config.strictDocument){if(!t.atEnd()&&t.currCodeUnit()===d&&E(t,n),u(t,n),!t.atEnd())throw new a({type:"UnknownToken",message:"Not at end"},t.genTextPos())}else for(;!t.atEnd();)t.currCodeUnit()===d?E(t,n):Q(t,n),u(t,n)}function u(t,n){for(;!t.atEnd();)if(t.skipSpaces(),t.startsWith(f))g(t,n);else if(t.startsWith(y))C(t,n);else break}function at(t){function n(s){if(s.startsWithSpace())s.skipSpaces();else if(!s.startsWith(W)&&!s.atEnd())throw new a({type:"InvalidChar",expected:"a whitespace",actual:s.currCodeUnitUnchecked()},s.genTextPos())}if(t.advance(5),n(t),!t.startsWith(st))throw new a({type:"InvalidString",expected:"version"},t.genTextPos());l(t),n(t),t.startsWith(et)&&(l(t),n(t)),t.startsWith(ot)&&l(t),t.skipSpaces(),t.skipString(W)}function g(t,n){const s=t.getPos();t.advance(4);const e=t.consumeCodeUnitsWhile((o,i)=>!(o===R&&i.startsWith(v)));if(t.skipString(v),e.includes("--")||e.endsWith("-"))throw new a({type:"InvalidComment"},t.genTextPosFrom(s));n({type:"Comment",text:e,range:t.rangeFrom(s)})}function C(t,n){if(t.startsWith(w))throw new a({type:"UnexpectedDeclaration"},t.genTextPos());const s=t.getPos();t.advance(2);const e=t.consumeName();t.skipSpaces();const o=t.consumeCodeUnitsWhile((i,c)=>!(i===U&&c.startsWith(x)));t.skipString(x),n({type:"ProcessingInstruction",target:e,content:o.length===0?void 0:o,range:t.rangeFrom(s)})}function ct(t,n){const s=t.getPos();if(rt(t),t.skipSpaces(),t.currCodeUnit()===r){t.advance(1);return}for(t.advance(1);!t.atEnd();)if(t.skipSpaces(),t.startsWith(j))pt(t,n);else if(t.startsWith(f))g(t,n);else if(t.startsWith(y))C(t,n);else if(t.startsWith("]"))if(t.advance(1),t.skipSpaces(),t.currCodeUnit()===r){t.advance(1);break}else throw new a({type:"InvalidChar",expected:"'>'",actual:t.currCodeUnitUnchecked()},t.genTextPos());else if(t.startsWith(q)||t.startsWith(J)||t.startsWith(V))try{ut(t)}catch(e){throw new a({type:"UnknownToken",message:"Failed to consume declaration"},t.genTextPosFrom(s))}else throw new a({type:"UnknownToken",message:"Failed to parse doctype"},t.genTextPos())}function rt(t){t.advance(9),t.consumeSpaces(),t.skipName(),t.skipSpaces(),I(t),t.skipSpaces();const n=t.currCodeUnit();if(n!==b&&n!==r)throw new a({type:"InvalidChar",expected:"'[' or '>'",actual:n},t.genTextPos())}function I(t){if(t.startsWith(nt)||t.startsWith(A)){const n=t.getPos();t.advance(6);const s=t.sliceBack(n);t.consumeSpaces();const e=t.consumeQuote();if(t.consumeCodeUnitsWhile(o=>o!==e),t.consumeCodeUnit(e),s===A){t.consumeSpaces();const o=t.consumeQuote();t.consumeCodeUnitsWhile(i=>i!==o),t.consumeCodeUnit(o)}return!0}return!1}function pt(t,n){t.advance(8),t.consumeSpaces();const s=!t.tryConsumeCodeUnit(B);s||t.consumeSpaces();const e=t.consumeName();t.consumeSpaces();const o=dt(t,s);o!==null&&n({type:"EntityDeclaration",name:e,definition:o}),t.skipSpaces(),t.consumeCodeUnit(r)}function dt(t,n){const s=t.currCodeUnit();if(s===M||s===H){const e=t.consumeQuote(),o=t.getPos();t.skipCodeUnitsWhile(c=>c!==e);const i=t.sliceBack(o);return t.consumeCodeUnit(e),i}else if(s===K||s===Y){if(I(t))return n&&(t.skipSpaces(),t.startsWith(tt)&&(t.advance(5),t.consumeSpaces(),t.skipName())),null;throw new a({type:"InvalidExternalID"},t.genTextPos())}else throw new a({type:"InvalidChar",expected:"a quote, SYSTEM or PUBLIC",actual:s},t.genTextPos())}function ut(t){t.skipCodeUnitsWhile(n=>n!==r),t.consumeCodeUnit(r)}function E(t,n){const s=t.getPos();t.advance(1);const[e,o]=t.consumeQName();n({type:"ElementStart",prefix:e,local:o,start:s});let i=!1;for(;!t.atEnd();){const c=t.startsWithSpace();t.skipSpaces();const m=t.getPos(),S=t.currCodeUnit();if(S===T){t.advance(1),t.consumeCodeUnit(r);const p=t.rangeFrom(m);n({type:"ElementEnd",end:{type:"Empty"},range:p});break}else if(S===r){t.advance(1);const p=t.rangeFrom(m);n({type:"ElementEnd",end:{type:"Open"},range:p}),i=!0;break}else{if(!c)throw new a({type:"InvalidChar",expected:"a whitespace",actual:t.currCodeUnitUnchecked()},t.genTextPos());const[p,D,_]=l(t),L=t.getPos();n({type:"Attribute",range:{start:m,end:L},prefix:p,local:D,value:_})}}if(i){if(t.config.rawTextElements!=null){const c=O(o,e);if(t.config.rawTextElements.includes(c)){F(t,n,`</${c}>`);return}}F(t,n)}}function l(t){const[n,s]=t.consumeQName();let e;const o=t.getPos();if(t.skipSpaces(),t.tryConsumeCodeUnit(k)){t.skipSpaces();const i=t.consumeQuote();e=t.consumeCodeUnitsWhile(c=>c!==i&&c!==d),t.consumeCodeUnit(i)}else if(t.config.allowBooleanAttributes)t.goTo(o),e="true";else throw new a({type:"InvalidChar",expected:k,actual:t.currCodeUnit()},t.genTextPos());return[n,s,e]}function F(t,n,s=d){for(;!t.atEnd();)if(typeof s=="number"?t.currCodeUnit()===s:t.startsWith(s)){const e=t.nextCodeUnit();if(e===X)if(t.startsWith(f))g(t,n);else if(t.startsWith(Z))lt(t,n);else throw new a({type:"UnknownToken",message:"Failed to parse content"},t.genTextPos());else if(e===U)C(t,n);else if(e===T){mt(t,n);break}else E(t,n)}else Q(t,n,s)}function lt(t,n){const s=t.getPos();t.advance(9);const e=t.consumeCodeUnitsWhile((i,c)=>!(i===z&&c.startsWith(h)));t.skipString(h);const o=t.rangeFrom(s);n({type:"Cdata",text:e,range:o})}function mt(t,n){const s=t.getPos();t.advance(2);const[e,o]=t.consumeQName();t.skipSpaces(),t.consumeCodeUnit(r);const i=t.rangeFrom(s);n({type:"ElementEnd",end:{type:"Close",prefix:e,local:o},range:i})}function Q(t,n,s=d){const e=t.getPos(),o=typeof s=="number"?t.consumeCodeUnitsWhile(i=>i!==s):t.consumeCodeUnitsWhile((i,c)=>!c.startsWith(s));if(o.includes(h))throw new a({type:"InvalidCharacterData"},t.genTextPos());n({type:"Text",text:o,range:t.rangeFrom(e)})}export{it as tokenize,N as tokenizeXmlStream};
@@ -1,3 +1,4 @@
1
+ export * from './get-q-name';
1
2
  export * from './selector';
2
3
  export * from './token-to-xml';
3
4
  export * from './tokenizer';
@@ -207,6 +207,13 @@ export interface TXmlStreamConfig {
207
207
  * @default true
208
208
  */
209
209
  strictDocument: boolean;
210
+ /**
211
+ * List of element names that should be treated as raw text elements.
212
+ * Their content will be parsed as text rather than XML.
213
+ * Common examples are 'script' and 'style' for HTML-like documents.
214
+ * @default null
215
+ */
216
+ rawTextElements: string[] | null;
210
217
  /**
211
218
  * Whether to allow HTML-style boolean attributes (e.g., <div hidden>).
212
219
  * When true, attributes without values are treated as having their name as the value.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xml-tokenizer",
3
- "version": "0.0.21",
3
+ "version": "0.0.22",
4
4
  "private": false,
5
5
  "description": "Straightforward and typesafe XML tokenizer that streams tokens through a callback mechanism",
6
6
  "keywords": [],