xml-tokenizer 0.0.21 → 0.0.23

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,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(d)for(var e of d(t))f.call(t,e)&&p(h,e,t[e]);return h},l=(h,t,e)=>p(h,typeof t!="symbol"?t+"":t,e);class u{constructor(t,e={}){l(this,"_text"),l(this,"_pos"),l(this,"_end"),l(this,"config");const{pos:r=0,strictDocument:i=!0,allowDtd:s=!0,rawTextElements:c=null}=e;this._text=t,this._pos=r,this._end=this._text.length,this.config={strictDocument:i,allowDtd:s,rawTextElements:c}}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 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 m=this.currCodeUnitUnchecked();if(m===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(m))this._pos+=1;else break}let s,c;if(i!=null?(s=this._text.slice(r,i),c=this.sliceBack(i+1)):(s="",c=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(c.length>0){if(!a.isXmlNameStart((e=c[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,c]}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=u;
@@ -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 X=require("../get-q-name.js"),s=require("./ascii-constants.js"),I=require("./utils.js"),c=require("./XmlError.js"),L=require("./XmlStream.js");const H="\uFEFF",g="<?xml ",C="?>",Q="<!ENTITY",D="<!ELEMENT",O="<!ATTLIST",F="<!NOTATION",U="<!DOCTYPE",A="<?",k="?>",m="<!--",w="-->",G="<![CDATA[",E="]]>",B="NDATA",W="PUBLIC",b="SYSTEM",q="version",M="encoding",z="standalone";function K(t,n,e={}){P(new L.XmlStream(t,e),n)}function P(t,n){if(t.startsWith(H)&&t.advance(1),t.startsWith(g)&&Y(t),d(t,n),t.skipSpaces(),t.startsWith(U)||t.startsWith(U.toLowerCase())){if(!t.config.allowDtd)throw new c.XmlError({type:"DtdDetected"});$(t,n),d(t,n)}if(t.skipSpaces(),t.config.strictDocument){if(!t.atEnd()&&t.currCodeUnit()===s.LESS_THAN&&S(t,n),d(t,n),!t.atEnd())throw new c.XmlError({type:"UnknownToken",message:"Not at end"},t.genTextPos())}else for(;!t.atEnd();)t.currCodeUnit()===s.LESS_THAN?S(t,n):x(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(A))h(t,n);else break}function Y(t){function n(e){if(e.startsWithSpace())e.skipSpaces();else if(!e.startsWith(C)&&!e.atEnd())throw new c.XmlError({type:"InvalidChar",expected:"a whitespace",actual:e.currCodeUnitUnchecked()},e.genTextPos())}if(t.advance(5),n(t),!t.startsWith(q))throw new c.XmlError({type:"InvalidString",expected:"version"},t.genTextPos());p(t),n(t),t.startsWith(M)&&(p(t),n(t)),t.startsWith(z)&&p(t),t.skipSpaces(),t.skipString(C)}function f(t,n){const e=t.getPos();t.advance(4);const o=t.consumeCodeUnitsWhile((r,i)=>!(r===s.HYPHEN&&i.startsWith(w)));if(t.skipString(w),o.includes("--")||o.endsWith("-"))throw new c.XmlError({type:"InvalidComment"},t.genTextPosFrom(e));n({type:"Comment",text:o,range:t.rangeFrom(e)})}function h(t,n){if(t.startsWith(g))throw new c.XmlError({type:"UnexpectedDeclaration"},t.genTextPos());const e=t.getPos();t.advance(2);const o=t.consumeName();t.skipSpaces();const r=t.consumeCodeUnitsWhile((i,a)=>!(i===s.QUESTION_MARK&&a.startsWith(k)));t.skipString(k),n({type:"ProcessingInstruction",target:o,content:r.length===0?void 0:r,range:t.rangeFrom(e)})}function $(t,n){const e=t.getPos();if(j(t),t.skipSpaces(),t.currCodeUnit()===s.GREATER_THAN){t.advance(1);return}for(t.advance(1);!t.atEnd();)if(t.skipSpaces(),t.startsWith(Q))J(t,n);else if(t.startsWith(m))f(t,n);else if(t.startsWith(A))h(t,n);else if(t.startsWith("]"))if(t.advance(1),t.skipSpaces(),t.currCodeUnit()===s.GREATER_THAN){t.advance(1);break}else throw new c.XmlError({type:"InvalidChar",expected:"'>'",actual:t.currCodeUnitUnchecked()},t.genTextPos());else if(t.startsWith(D)||t.startsWith(O)||t.startsWith(F))try{Z(t)}catch(o){throw new c.XmlError({type:"UnknownToken",message:"Failed to consume declaration"},t.genTextPosFrom(e))}else throw new c.XmlError({type:"UnknownToken",message:"Failed to parse doctype"},t.genTextPos())}function j(t){t.advance(9),t.consumeSpaces(),t.skipName(),t.skipSpaces(),y(t),t.skipSpaces();const n=t.currCodeUnit();if(n!==s.OPEN_SQUARE_BRACKET&&n!==s.GREATER_THAN)throw new c.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 o=t.consumeQuote();if(t.consumeCodeUnitsWhile(r=>r!==o),t.consumeCodeUnit(o),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(s.PERCENT);e||t.consumeSpaces();const o=t.consumeName();t.consumeSpaces();const r=V(t,e);r!==null&&n({type:"EntityDeclaration",name:o,definition:r}),t.skipSpaces(),t.consumeCodeUnit(s.GREATER_THAN)}function V(t,n){const e=t.currCodeUnit();if(e===s.DOUBLE_QUOTE||e===s.SINGLE_QUOTE){const o=t.consumeQuote(),r=t.getPos();t.skipCodeUnitsWhile(a=>a!==o);const i=t.sliceBack(r);return t.consumeCodeUnit(o),i}else if(e===s.UPPERCASE_S||e===s.UPPERCASE_P){if(y(t))return n&&(t.skipSpaces(),t.startsWith(B)&&(t.advance(5),t.consumeSpaces(),t.skipName())),null;throw new c.XmlError({type:"InvalidExternalID"},t.genTextPos())}else throw new c.XmlError({type:"InvalidChar",expected:"a quote, SYSTEM or PUBLIC",actual:e},t.genTextPos())}function Z(t){t.skipCodeUnitsWhile(n=>n!==s.GREATER_THAN),t.consumeCodeUnit(s.GREATER_THAN)}function S(t,n){const e=t.getPos();t.advance(1);const[o,r]=t.consumeQName();n({type:"ElementStart",prefix:o,local:r,start:e});let i=!1;for(;!t.atEnd();){const a=t.startsWithSpace();t.skipSpaces();const l=t.getPos(),T=t.currCodeUnit();if(T===s.SLASH){t.advance(1),t.consumeCodeUnit(s.GREATER_THAN);const u=t.rangeFrom(l);n({type:"ElementEnd",end:{type:"Empty"},range:u});break}else if(T===s.GREATER_THAN){t.advance(1);const u=t.rangeFrom(l);n({type:"ElementEnd",end:{type:"Open"},range:u}),i=!0;break}else{if(!a)throw new c.XmlError({type:"InvalidChar",expected:"a whitespace",actual:t.currCodeUnitUnchecked()},t.genTextPos());const[u,v,R]=p(t),_=t.getPos();n({type:"Attribute",range:{start:l,end:_},prefix:u,local:v,value:R})}}if(i){if(t.config.rawTextElements!=null){const a=X.getQName(r,o);if(t.config.rawTextElements.includes(a)){N(t,n,`</${a}>`);return}}N(t,n)}}function p(t){const[n,e]=t.consumeQName();let o;const r=t.getPos();if(t.skipSpaces(),t.tryConsumeCodeUnit(s.EQUALS)){t.skipSpaces();const i=t.currCodeUnit();if(i===s.SINGLE_QUOTE||i===s.DOUBLE_QUOTE){const a=t.consumeQuote();o=t.consumeCodeUnitsWhile(l=>l!==a&&l!==s.LESS_THAN),t.consumeCodeUnit(a)}else if(!t.config.strictDocument)o=t.consumeCodeUnitsWhile(a=>!I.isXmlSpaceByte(a)&&a!==s.GREATER_THAN&&a!==s.SLASH&&a!==s.LESS_THAN);else throw new c.XmlError({type:"InvalidChar",expected:"a quote",actual:i},t.genTextPos())}else if(!t.config.strictDocument)t.goTo(r),o="true";else throw new c.XmlError({type:"InvalidChar",expected:s.EQUALS,actual:t.currCodeUnit()},t.genTextPos());return[n,e,o]}function N(t,n,e=s.LESS_THAN){for(;!t.atEnd();)if(typeof e=="number"?t.currCodeUnit()===e:t.startsWith(e)){const o=t.nextCodeUnit();if(o===s.EXCLAMATION_MARK)if(t.startsWith(m))f(t,n);else if(t.startsWith(G))tt(t,n);else throw new c.XmlError({type:"UnknownToken",message:"Failed to parse content"},t.genTextPos());else if(o===s.QUESTION_MARK)h(t,n);else if(o===s.SLASH){nt(t,n);break}else S(t,n)}else x(t,n,e)}function tt(t,n){const e=t.getPos();t.advance(9);const o=t.consumeCodeUnitsWhile((i,a)=>!(i===s.CLOSE_SQUARE_BRACKET&&a.startsWith(E)));t.skipString(E);const r=t.rangeFrom(e);n({type:"Cdata",text:o,range:r})}function nt(t,n){const e=t.getPos();t.advance(2);const[o,r]=t.consumeQName();t.skipSpaces(),t.consumeCodeUnit(s.GREATER_THAN);const i=t.rangeFrom(e);n({type:"ElementEnd",end:{type:"Close",prefix:o,local:r},range:i})}function x(t,n,e=s.LESS_THAN){const o=t.getPos(),r=typeof e=="number"?t.consumeCodeUnitsWhile(i=>i!==e):t.consumeCodeUnitsWhile((i,a)=>!a.startsWith(e));if(r.includes(E))throw new c.XmlError({type:"InvalidCharacterData"},t.genTextPos());n({type:"Text",text:r,range:t.rangeFrom(o)})}exports.tokenize=K,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 U,ZERO as w,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 c,isXmlName as m}from"./utils.js";import{XmlError as o}from"./XmlError.js";var A=Object.defineProperty,_=Object.getOwnPropertySymbols,I=Object.prototype.hasOwnProperty,W=Object.prototype.propertyIsEnumerable,l=(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)&&l(r,e,t[e]);if(_)for(var e of _(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,rawTextElements:h=null}=e;this._text=t,this._pos=i,this._end=this._text.length,this.config={strictDocument:n,allowDtd:s,rawTextElements: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&&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(U)?(e=this.consumeCodeUnitsWhile(s=>s>=w&&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(!c(e))throw new o({type:"InvalidName"},this.genTextPosFrom(t))}else if(!m(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(m(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 +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 b}from"../get-q-name.js";import{LESS_THAN as d,HYPHEN as B,QUESTION_MARK as T,GREATER_THAN as r,OPEN_SQUARE_BRACKET as M,PERCENT as X,DOUBLE_QUOTE as k,SINGLE_QUOTE as w,UPPERCASE_S as H,UPPERCASE_P as Y,SLASH as f,EQUALS as W,EXCLAMATION_MARK as K,CLOSE_SQUARE_BRACKET as z}from"./ascii-constants.js";import{isXmlSpaceByte as q}from"./utils.js";import{XmlError as c}from"./XmlError.js";import{XmlStream as G}from"./XmlStream.js";const $="\uFEFF",P="<?xml ",y="?>",j="<!ENTITY",J="<!ELEMENT",V="<!ATTLIST",Z="<!NOTATION",x="<!DOCTYPE",v="<?",N="?>",h="<!--",A="-->",tt="<![CDATA[",g="]]>",nt="NDATA",I="PUBLIC",st="SYSTEM",et="version",ot="encoding",it="standalone";function at(t,n,s={}){D(new G(t,s),n)}function D(t,n){if(t.startsWith($)&&t.advance(1),t.startsWith(P)&&ct(t),l(t,n),t.skipSpaces(),t.startsWith(x)||t.startsWith(x.toLowerCase())){if(!t.config.allowDtd)throw new c({type:"DtdDetected"});rt(t,n),l(t,n)}if(t.skipSpaces(),t.config.strictDocument){if(!t.atEnd()&&t.currCodeUnit()===d&&U(t,n),l(t,n),!t.atEnd())throw new c({type:"UnknownToken",message:"Not at end"},t.genTextPos())}else for(;!t.atEnd();)t.currCodeUnit()===d?U(t,n):L(t,n),l(t,n)}function l(t,n){for(;!t.atEnd();)if(t.skipSpaces(),t.startsWith(h))C(t,n);else if(t.startsWith(v))S(t,n);else break}function ct(t){function n(s){if(s.startsWithSpace())s.skipSpaces();else if(!s.startsWith(y)&&!s.atEnd())throw new c({type:"InvalidChar",expected:"a whitespace",actual:s.currCodeUnitUnchecked()},s.genTextPos())}if(t.advance(5),n(t),!t.startsWith(et))throw new c({type:"InvalidString",expected:"version"},t.genTextPos());m(t),n(t),t.startsWith(ot)&&(m(t),n(t)),t.startsWith(it)&&m(t),t.skipSpaces(),t.skipString(y)}function C(t,n){const s=t.getPos();t.advance(4);const e=t.consumeCodeUnitsWhile((o,i)=>!(o===B&&i.startsWith(A)));if(t.skipString(A),e.includes("--")||e.endsWith("-"))throw new c({type:"InvalidComment"},t.genTextPosFrom(s));n({type:"Comment",text:e,range:t.rangeFrom(s)})}function S(t,n){if(t.startsWith(P))throw new c({type:"UnexpectedDeclaration"},t.genTextPos());const s=t.getPos();t.advance(2);const e=t.consumeName();t.skipSpaces();const o=t.consumeCodeUnitsWhile((i,a)=>!(i===T&&a.startsWith(N)));t.skipString(N),n({type:"ProcessingInstruction",target:e,content:o.length===0?void 0:o,range:t.rangeFrom(s)})}function rt(t,n){const s=t.getPos();if(pt(t),t.skipSpaces(),t.currCodeUnit()===r){t.advance(1);return}for(t.advance(1);!t.atEnd();)if(t.skipSpaces(),t.startsWith(j))dt(t,n);else if(t.startsWith(h))C(t,n);else if(t.startsWith(v))S(t,n);else if(t.startsWith("]"))if(t.advance(1),t.skipSpaces(),t.currCodeUnit()===r){t.advance(1);break}else throw new c({type:"InvalidChar",expected:"'>'",actual:t.currCodeUnitUnchecked()},t.genTextPos());else if(t.startsWith(J)||t.startsWith(V)||t.startsWith(Z))try{lt(t)}catch(e){throw new c({type:"UnknownToken",message:"Failed to consume declaration"},t.genTextPosFrom(s))}else throw new c({type:"UnknownToken",message:"Failed to parse doctype"},t.genTextPos())}function pt(t){t.advance(9),t.consumeSpaces(),t.skipName(),t.skipSpaces(),F(t),t.skipSpaces();const n=t.currCodeUnit();if(n!==M&&n!==r)throw new c({type:"InvalidChar",expected:"'[' or '>'",actual:n},t.genTextPos())}function F(t){if(t.startsWith(st)||t.startsWith(I)){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===I){t.consumeSpaces();const o=t.consumeQuote();t.consumeCodeUnitsWhile(i=>i!==o),t.consumeCodeUnit(o)}return!0}return!1}function dt(t,n){t.advance(8),t.consumeSpaces();const s=!t.tryConsumeCodeUnit(X);s||t.consumeSpaces();const e=t.consumeName();t.consumeSpaces();const o=ut(t,s);o!==null&&n({type:"EntityDeclaration",name:e,definition:o}),t.skipSpaces(),t.consumeCodeUnit(r)}function ut(t,n){const s=t.currCodeUnit();if(s===k||s===w){const e=t.consumeQuote(),o=t.getPos();t.skipCodeUnitsWhile(a=>a!==e);const i=t.sliceBack(o);return t.consumeCodeUnit(e),i}else if(s===H||s===Y){if(F(t))return n&&(t.skipSpaces(),t.startsWith(nt)&&(t.advance(5),t.consumeSpaces(),t.skipName())),null;throw new c({type:"InvalidExternalID"},t.genTextPos())}else throw new c({type:"InvalidChar",expected:"a quote, SYSTEM or PUBLIC",actual:s},t.genTextPos())}function lt(t){t.skipCodeUnitsWhile(n=>n!==r),t.consumeCodeUnit(r)}function U(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 a=t.startsWithSpace();t.skipSpaces();const p=t.getPos(),E=t.currCodeUnit();if(E===f){t.advance(1),t.consumeCodeUnit(r);const u=t.rangeFrom(p);n({type:"ElementEnd",end:{type:"Empty"},range:u});break}else if(E===r){t.advance(1);const u=t.rangeFrom(p);n({type:"ElementEnd",end:{type:"Open"},range:u}),i=!0;break}else{if(!a)throw new c({type:"InvalidChar",expected:"a whitespace",actual:t.currCodeUnitUnchecked()},t.genTextPos());const[u,_,O]=m(t),R=t.getPos();n({type:"Attribute",range:{start:p,end:R},prefix:u,local:_,value:O})}}if(i){if(t.config.rawTextElements!=null){const a=b(o,e);if(t.config.rawTextElements.includes(a)){Q(t,n,`</${a}>`);return}}Q(t,n)}}function m(t){const[n,s]=t.consumeQName();let e;const o=t.getPos();if(t.skipSpaces(),t.tryConsumeCodeUnit(W)){t.skipSpaces();const i=t.currCodeUnit();if(i===w||i===k){const a=t.consumeQuote();e=t.consumeCodeUnitsWhile(p=>p!==a&&p!==d),t.consumeCodeUnit(a)}else if(!t.config.strictDocument)e=t.consumeCodeUnitsWhile(a=>!q(a)&&a!==r&&a!==f&&a!==d);else throw new c({type:"InvalidChar",expected:"a quote",actual:i},t.genTextPos())}else if(!t.config.strictDocument)t.goTo(o),e="true";else throw new c({type:"InvalidChar",expected:W,actual:t.currCodeUnit()},t.genTextPos());return[n,s,e]}function Q(t,n,s=d){for(;!t.atEnd();)if(typeof s=="number"?t.currCodeUnit()===s:t.startsWith(s)){const e=t.nextCodeUnit();if(e===K)if(t.startsWith(h))C(t,n);else if(t.startsWith(tt))mt(t,n);else throw new c({type:"UnknownToken",message:"Failed to parse content"},t.genTextPos());else if(e===T)S(t,n);else if(e===f){ft(t,n);break}else U(t,n)}else L(t,n,s)}function mt(t,n){const s=t.getPos();t.advance(9);const e=t.consumeCodeUnitsWhile((i,a)=>!(i===z&&a.startsWith(g)));t.skipString(g);const o=t.rangeFrom(s);n({type:"Cdata",text:e,range:o})}function ft(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 L(t,n,s=d){const e=t.getPos(),o=typeof s=="number"?t.consumeCodeUnitsWhile(i=>i!==s):t.consumeCodeUnitsWhile((i,a)=>!a.startsWith(s));if(o.includes(g))throw new c({type:"InvalidCharacterData"},t.genTextPos());n({type:"Text",text:o,range:t.rangeFrom(e)})}export{at as tokenize,D 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';
@@ -200,19 +200,21 @@ export interface TXmlStreamConfig {
200
200
  * - Document must have exactly one root element
201
201
  * - No text nodes at document level (outside root element)
202
202
  * - Only comments and processing instructions allowed outside root element
203
+ * - Attribute requires an explicit value and the value must be quoted
203
204
  * When false:
204
205
  * - Multiple root elements allowed
205
206
  * - Text nodes allowed at document level
206
- * - More HTML-like permissive parsing
207
+ * - More HTML-like permissive parsing (unquoted attributes, boolean attributes)
207
208
  * @default true
208
209
  */
209
210
  strictDocument: boolean;
210
211
  /**
211
- * Whether to allow HTML-style boolean attributes (e.g., <div hidden>).
212
- * When true, attributes without values are treated as having their name as the value.
213
- * @default false
212
+ * List of element names that should be treated as raw text elements.
213
+ * Their content will be parsed as text rather than XML.
214
+ * Common examples are 'script' and 'style' for HTML-like documents.
215
+ * @default null
214
216
  */
215
- allowBooleanAttributes: boolean;
217
+ rawTextElements: string[] | null;
216
218
  /**
217
219
  * Whether to allow DOCTYPE declarations.
218
220
  * @default true
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xml-tokenizer",
3
- "version": "0.0.21",
3
+ "version": "0.0.23",
4
4
  "private": false,
5
5
  "description": "Straightforward and typesafe XML tokenizer that streams tokens through a callback mechanism",
6
6
  "keywords": [],