xml-tokenizer 0.0.28 → 0.0.30

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.
@@ -0,0 +1 @@
1
+ "use strict";const t={strictDocument:!0,allowDtd:!0,rawTextElements:null,implicitSelfClosingElements:null,contextSliceSize:30},e={strictDocument:!1,allowDtd:!0,rawTextElements:["script","style","title","textarea"],implicitSelfClosingElements:["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"],contextSliceSize:30},l={strictDocument:!1,allowDtd:!0,rawTextElements:["style"],implicitSelfClosingElements:[],contextSliceSize:30};exports.htmlConfig=e,exports.svgConfig=l,exports.xmlConfig=t;
package/dist/cjs/index.js CHANGED
@@ -1 +1 @@
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
+ "use strict";var r=require("./config.js"),A=require("./get-q-name.js"),R=require("./selector/select.js"),T=require("./selector/TokenSelector.js"),S=require("./selector/TokenSelectState.js"),m=require("./selector/TokenSelectStateMachine.js"),a=require("./token-to-xml.js"),e=require("./tokenizer/ascii-constants.js"),t=require("./tokenizer/tokenize.js"),E=require("./tokenizer/utils.js"),l=require("./tokenizer/XmlError.js"),C=require("./tokenizer/XmlStream.js"),O=require("./tokens-to-xml.js"),i=require("./xml-to-object.js"),o=require("./xml-to-simplified-object.js");exports.htmlConfig=r.htmlConfig,exports.svgConfig=r.svgConfig,exports.xmlConfig=r.xmlConfig,exports.getQName=A.getQName,exports.select=R.select,exports.TokenSelector=T.TokenSelector,exports.EToCacheNodeProps=S.EToCacheNodeProps,exports.ETokenMatchCriteria=S.ETokenMatchCriteria,exports.TokenSelectState=S.TokenSelectState,exports.TokenSelectStateMachine=m.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=t.tokenize,exports.tokenizeXmlStream=t.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=l.XmlError,exports.XmlStream=C.XmlStream,exports.tokensToXml=O.tokensToXml,exports.processTokenForObject=i.processTokenForObject,exports.xmlToObject=i.xmlToObject,exports.processTokenForSimplifiedObject=o.processTokenForSimplifiedObject,exports.xmlToSimplifiedObject=o.xmlToSimplifiedObject;
@@ -1 +1 @@
1
- "use strict";var a=require("./TokenSelectState.js"),o=require("./TokenSelectStateMachine.js"),u=Object.defineProperty,f=(r,e,t)=>e in r?u(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,s=(r,e,t)=>f(r,typeof e!="symbol"?e+"":e,t);class S{constructor(e){s(this,"_currentDepth",0),s(this,"_tspStateMachines"),s(this,"_isRecording",!1),this._tspStateMachines=e.map(t=>new o.TokenSelectStateMachine(t))}pipeToken(e,t){let n=!1,i=!1;switch(e.type){case"ElementStart":n=this.handleElementStart(e);break;case"Attribute":n=this.handleAttribute(e);break;case"Text":n=this.handleText(e);break;case"ElementEnd":{i=this.handleElementEnd(e);break}}n&&!this._isRecording&&(this._isRecording=!0,t({type:"SelectionStart"}));for(const c of this._tspStateMachines){c.record(e);const l=c.takeRecordedTokens();l!=null&&l.forEach(h=>{t(h)})}this._isRecording&&t(e),i&&(t({type:"SelectionEnd"}),this._isRecording=!1)}handleElementStart(e){this._currentDepth+=1;let t=!1;for(const n of this._tspStateMachines){if(n.resetCurrentStateCache(),n.isFinalState())continue;const i=n.getNextState();i==null||!(i.matchCriteria&a.ETokenMatchCriteria.Name)||n.transitionIfNameMatch(e.local,e.prefix,this._currentDepth)&&n.isFinalState()&&(t=!0)}return t}handleAttribute(e){let t=!1;for(const n of this._tspStateMachines){if(n.isFinalState())continue;const i=n.getNextState();i==null||!(i.matchCriteria&a.ETokenMatchCriteria.Attributes)||n.transitionIfAttributesMatch(e.local,e.prefix,e.value,this._currentDepth)&&n.isFinalState()&&(t=!0)}return t}handleText(e){let t=!1;for(const n of this._tspStateMachines){if(n.isFinalState())continue;const i=n.getNextState();i==null||!(i.matchCriteria&a.ETokenMatchCriteria.Text)||n.transitionIfTextMatch(e.text,this._currentDepth)&&n.isFinalState()&&(t=!0)}return t}handleElementEnd(e){if(e.end.type==="Close"||e.end.type==="Empty"){this._currentDepth-=1;let t=!1;for(const n of this._tspStateMachines){const i=n.getCurrentState();i!=null&&(i.enteredDepth!=null&&this._currentDepth<i.enteredDepth&&n.transitionBack(this._currentDepth),t=t||n.isFinalState())}return!t}return!1}}exports.TokenSelector=S;
1
+ "use strict";var a=require("./TokenSelectState.js"),o=require("./TokenSelectStateMachine.js"),u=Object.defineProperty,f=(r,e,t)=>e in r?u(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,s=(r,e,t)=>f(r,typeof e!="symbol"?e+"":e,t);class S{constructor(e){s(this,"_currentDepth",0),s(this,"_tspStateMachines"),s(this,"_isRecording",!1),this._tspStateMachines=e.map(t=>new o.TokenSelectStateMachine(t))}pipeToken(e,t){let n=!1,i=!1;switch(e.type){case"ElementStart":n=this.handleElementStart(e);break;case"Attribute":n=this.handleAttribute(e);break;case"Text":n=this.handleText(e);break;case"ElementEnd":{i=this.handleElementEnd(e);break}}n&&!this._isRecording&&(this._isRecording=!0,t({type:"SelectionStart"}));for(const c of this._tspStateMachines){c.record(e);const l=c.takeRecordedTokens();l!=null&&l.forEach(h=>{t(h)})}this._isRecording&&t(e),i&&this._isRecording&&(t({type:"SelectionEnd"}),this._isRecording=!1)}handleElementStart(e){this._currentDepth+=1;let t=!1;for(const n of this._tspStateMachines){if(n.resetCurrentStateCache(),n.isFinalState())continue;const i=n.getNextState();i==null||!(i.matchCriteria&a.ETokenMatchCriteria.Name)||n.transitionIfNameMatch(e.local,e.prefix,this._currentDepth)&&n.isFinalState()&&(t=!0)}return t}handleAttribute(e){let t=!1;for(const n of this._tspStateMachines){if(n.isFinalState())continue;const i=n.getNextState();i==null||!(i.matchCriteria&a.ETokenMatchCriteria.Attributes)||n.transitionIfAttributesMatch(e.local,e.prefix,e.value,this._currentDepth)&&n.isFinalState()&&(t=!0)}return t}handleText(e){let t=!1;for(const n of this._tspStateMachines){if(n.isFinalState())continue;const i=n.getNextState();i==null||!(i.matchCriteria&a.ETokenMatchCriteria.Text)||n.transitionIfTextMatch(e.text,this._currentDepth)&&n.isFinalState()&&(t=!0)}return t}handleElementEnd(e){if(e.end.type==="Close"||e.end.type==="Empty"){this._currentDepth-=1;let t=!1;for(const n of this._tspStateMachines){const i=n.getCurrentState();i!=null&&(i.enteredDepth!=null&&this._currentDepth<i.enteredDepth&&n.transitionBack(this._currentDepth),t=t||n.isFinalState())}return!t}return!1}}exports.TokenSelector=S;
@@ -1 +1 @@
1
- "use strict";var o=require("./ascii-constants.js"),a=require("./utils.js"),n=require("./XmlError.js"),C=Object.defineProperty,d=Object.getOwnPropertySymbols,f=Object.prototype.hasOwnProperty,x=Object.prototype.propertyIsEnumerable,u=(h,t,e)=>t in h?C(h,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):h[t]=e,_=(h,t)=>{for(var e in t||(t={}))f.call(t,e)&&u(h,e,t[e]);if(d)for(var e of d(t))x.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:i=0,strictDocument:r=!0,allowDtd:s=!0,rawTextElements:c=null,contextSliceSize:l=30}=e;this._text=t,this._pos=i,this._end=this._text.length,this.config={strictDocument:r,allowDtd:s,rawTextElements:c,contextSliceSize:l}}clone(){return new m(this._text,_({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}goToEnd(){this._pos=this._end}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(),i=e.consumeReference();return i!=null?(this._pos+=e.getPos()-t,i):null}consumeReference(){if(!this.tryConsumeCodeUnit(o.AMPERSAND))return null;let t;if(this.tryConsumeCodeUnit(o.HASH)){let e,i;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),i=16):(e=this.consumeCodeUnitsWhile(s=>a.isAsciiDigit(s)),i=10);const r=parseInt(e,i);isNaN(r)||!a.isXmlChar(r)?t=null:t={type:"Char",value:String.fromCodePoint(r)}}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 i=this._pos;let r=null;for(;this._pos<this._end;){const l=this.currCodeUnitUnchecked();if(l===o.COLON)if(r==null)r=this._pos,this._pos+=1;else throw new n.XmlError({type:"InvalidName"},this.genTextPosFrom(i));else if(a.isXmlName(l))this._pos+=1;else break}let s,c;if(r!=null?(s=this._text.slice(i,r),c=this.sliceBack(r+1)):(s="",c=this.sliceBack(i)),s.length>0&&!a.isXmlNameStart((t=s[0])==null?void 0:t.codePointAt(0)))throw new n.XmlError({type:"InvalidName"},this.genTextPosFrom(i));if(c.length>0){if(!a.isXmlNameStart((e=c[0])==null?void 0:e.codePointAt(0)))throw new n.XmlError({type:"InvalidName"},this.genTextPosFrom(i))}else throw new n.XmlError({type:"InvalidName"},this.genTextPosFrom(i));return[s,c]}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())}getTextAround(t,e){const i=Math.floor(e/2),r=Math.max(0,t-i),s=Math.min(this._end,t+i+e%2);return this._text.slice(r,s)}genTextPos(){return this.genTextPosFrom(this._pos)}genTextPosFrom(t){const e=Math.min(t,this._end);let i=1,r=1;for(let s=0;s<e;s++)this._text.charCodeAt(s)===o.LINE_FEED?(i++,r=1):r++;return _({row:i,col:r},this.config.contextSliceSize?{contextSlice:this.getTextAround(t,this.config.contextSliceSize)}:{})}}exports.XmlStream=m;
1
+ "use strict";var n=require("./ascii-constants.js"),c=require("./utils.js"),o=require("./XmlError.js"),f=Object.defineProperty,d=Object.getOwnPropertySymbols,E=Object.prototype.hasOwnProperty,x=Object.prototype.propertyIsEnumerable,u=(h,t,e)=>t in h?f(h,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):h[t]=e,_=(h,t)=>{for(var e in t||(t={}))E.call(t,e)&&u(h,e,t[e]);if(d)for(var e of d(t))x.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:i=0,strictDocument:r=!0,allowDtd:s=!0,rawTextElements:a=null,implicitSelfClosingElements:l=null,contextSliceSize:C=30}=e;this._text=t,this._pos=i,this._end=this._text.length,this.config={strictDocument:r,allowDtd:s,rawTextElements:a,implicitSelfClosingElements:l,contextSliceSize:C}}clone(){return new m(this._text,_({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(!c.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}goToEnd(){this._pos=this._end}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&&c.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(),i=e.consumeReference();return i!=null?(this._pos+=e.getPos()-t,i):null}consumeReference(){if(!this.tryConsumeCodeUnit(n.AMPERSAND))return null;let t;if(this.tryConsumeCodeUnit(n.HASH)){let e,i;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),i=16):(e=this.consumeCodeUnitsWhile(s=>c.isAsciiDigit(s)),i=10);const r=parseInt(e,i);isNaN(r)||!c.isXmlChar(r)?t=null:t={type:"Char",value:String.fromCodePoint(r)}}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(!c.isXmlNameStart(e))throw new o.XmlError({type:"InvalidName"},this.genTextPosFrom(t))}else if(!c.isXmlName(e))break;this._pos+=1}}consumeQName(){var t,e;const i=this._pos;let r=null;for(;this._pos<this._end;){const l=this.currCodeUnitUnchecked();if(l===n.COLON)if(r==null)r=this._pos,this._pos+=1;else throw new o.XmlError({type:"InvalidName"},this.genTextPosFrom(i));else if(c.isXmlName(l))this._pos+=1;else break}let s,a;if(r!=null?(s=this._text.slice(i,r),a=this.sliceBack(r+1)):(s="",a=this.sliceBack(i)),s.length>0&&!c.isXmlNameStart((t=s[0])==null?void 0:t.codePointAt(0)))throw new o.XmlError({type:"InvalidName"},this.genTextPosFrom(i));if(a.length>0){if(!c.isXmlNameStart((e=a[0])==null?void 0:e.codePointAt(0)))throw new o.XmlError({type:"InvalidName"},this.genTextPosFrom(i))}else throw new o.XmlError({type:"InvalidName"},this.genTextPosFrom(i));return[s,a]}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())}getTextAround(t,e){const i=Math.floor(e/2),r=Math.max(0,t-i),s=Math.min(this._end,t+i+e%2);return this._text.slice(r,s)}genTextPos(){return this.genTextPosFrom(this._pos)}genTextPosFrom(t){const e=Math.min(t,this._end);let i=1,r=1;for(let s=0;s<e;s++)this._text.charCodeAt(s)===n.LINE_FEED?(i++,r=1):r++;return _({row:i,col:r},this.config.contextSliceSize?{contextSlice:this.getTextAround(t,this.config.contextSliceSize)}:{})}}exports.XmlStream=m;
@@ -1 +1 @@
1
- "use strict";var X=require("../get-q-name.js"),e=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,s={}){P(new L.XmlStream(t,s),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()===e.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()===e.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(s){if(s.startsWithSpace())s.skipSpaces();else if(!s.startsWith(C)&&!s.atEnd())throw new c.XmlError({type:"InvalidChar",expected:"a whitespace",actual:s.currCodeUnitUnchecked()},s.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 s=t.getPos();t.advance(4);const o=t.consumeCodeUnitsWhile((r,i)=>!(r===e.HYPHEN&&i.startsWith(w)));if(t.skipString(w),o.includes("--")||o.endsWith("-"))throw new c.XmlError({type:"InvalidComment"},t.genTextPosFrom(s));n({type:"Comment",text:o,range:t.rangeFrom(s)},t)}function h(t,n){if(t.startsWith(g))throw new c.XmlError({type:"UnexpectedDeclaration"},t.genTextPos());const s=t.getPos();t.advance(2);const o=t.consumeName();t.skipSpaces();const r=t.consumeCodeUnitsWhile((i,a)=>!(i===e.QUESTION_MARK&&a.startsWith(k)));t.skipString(k),n({type:"ProcessingInstruction",target:o,content:r.length===0?void 0:r,range:t.rangeFrom(s)},t)}function $(t,n){const s=t.getPos();if(j(t),t.skipSpaces(),t.currCodeUnit()===e.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()===e.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(s))}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!==e.OPEN_SQUARE_BRACKET&&n!==e.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 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 J(t,n){t.advance(8),t.consumeSpaces();const s=!t.tryConsumeCodeUnit(e.PERCENT);s||t.consumeSpaces();const o=t.consumeName();t.consumeSpaces();const r=V(t,s);r!==null&&n({type:"EntityDeclaration",name:o,definition:r},t),t.skipSpaces(),t.consumeCodeUnit(e.GREATER_THAN)}function V(t,n){const s=t.currCodeUnit();if(s===e.DOUBLE_QUOTE||s===e.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(s===e.UPPERCASE_S||s===e.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:s},t.genTextPos())}function Z(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},t);let i=!1;for(;!t.atEnd();){const a=t.startsWithSpace();t.skipSpaces();const l=t.getPos(),T=t.currCodeUnit();if(T===e.SLASH){t.advance(1),t.consumeCodeUnit(e.GREATER_THAN);const u=t.rangeFrom(l);n({type:"ElementEnd",end:{type:"Empty"},range:u},t);break}else if(T===e.GREATER_THAN){t.advance(1);const u=t.rangeFrom(l);n({type:"ElementEnd",end:{type:"Open"},range:u},t),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},t)}}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,s]=t.consumeQName();let o;const r=t.getPos();if(t.skipSpaces(),t.tryConsumeCodeUnit(e.EQUALS)){t.skipSpaces();const i=t.currCodeUnit();if(i===e.SINGLE_QUOTE||i===e.DOUBLE_QUOTE){const a=t.consumeQuote();o=t.consumeCodeUnitsWhile(l=>l!==a&&l!==e.LESS_THAN),t.consumeCodeUnit(a)}else if(!t.config.strictDocument)o=t.consumeCodeUnitsWhile(a=>!I.isXmlSpaceByte(a)&&a!==e.GREATER_THAN&&a!==e.SLASH&&a!==e.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:e.EQUALS,actual:t.currCodeUnit()},t.genTextPos());return[n,s,o]}function N(t,n,s=e.LESS_THAN){for(;!t.atEnd();)if(typeof s=="number"?t.currCodeUnit()===s:t.startsWith(s)){const o=t.nextCodeUnit();if(o===e.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===e.QUESTION_MARK)h(t,n);else if(o===e.SLASH){nt(t,n);break}else S(t,n)}else x(t,n,s)}function tt(t,n){const s=t.getPos();t.advance(9);const o=t.consumeCodeUnitsWhile((i,a)=>!(i===e.CLOSE_SQUARE_BRACKET&&a.startsWith(E)));t.skipString(E);const r=t.rangeFrom(s);n({type:"Cdata",text:o,range:r},t)}function nt(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},t)}function x(t,n,s=e.LESS_THAN){const o=t.getPos(),r=typeof s=="number"?t.consumeCodeUnitsWhile(i=>i!==s):t.consumeCodeUnitsWhile((i,a)=>!a.startsWith(s));if(r.includes(E))throw new c.XmlError({type:"InvalidCharacterData"},t.genTextPos());n({type:"Text",text:r,range:t.rangeFrom(o)},t)}exports.tokenize=K,exports.tokenizeXmlStream=P;
1
+ "use strict";var g=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",C="<?xml ",U="?>",Q="<!ENTITY",D="<!ELEMENT",O="<!ATTLIST",F="<!NOTATION",k="<!DOCTYPE",A="<?",w="?>",m="<!--",W="-->",G="<![CDATA[",E="]]>",b="NDATA",y="PUBLIC",B="SYSTEM",M="version",q="encoding",z="standalone";function K(t,n,e={}){N(new L.XmlStream(t,e),n)}function N(t,n){if(t.startsWith(H)&&t.advance(1),t.startsWith(C)&&Y(t),d(t,n),t.skipSpaces(),t.startsWith(k)||t.startsWith(k.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):v(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(U)&&!e.atEnd())throw new c.XmlError({type:"InvalidChar",expected:"a whitespace",actual:e.currCodeUnitUnchecked()},e.genTextPos())}if(t.advance(5),n(t),!t.startsWith(M))throw new c.XmlError({type:"InvalidString",expected:"version"},t.genTextPos());p(t),n(t),t.startsWith(q)&&(p(t),n(t)),t.startsWith(z)&&p(t),t.skipSpaces(),t.skipString(U)}function f(t,n){const e=t.getPos();t.advance(4);const o=t.consumeCodeUnitsWhile((i,r)=>!(i===s.HYPHEN&&r.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)},t)}function h(t,n){if(t.startsWith(C))throw new c.XmlError({type:"UnexpectedDeclaration"},t.genTextPos());const e=t.getPos();t.advance(2);const o=t.consumeName();t.skipSpaces();const i=t.consumeCodeUnitsWhile((r,a)=>!(r===s.QUESTION_MARK&&a.startsWith(w)));t.skipString(w),n({type:"ProcessingInstruction",target:o,content:i.length===0?void 0:i,range:t.rangeFrom(e)},t)}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(),P(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 P(t){if(t.startsWith(B)||t.startsWith(y)){const n=t.getPos();t.advance(6);const e=t.sliceBack(n);t.consumeSpaces();const o=t.consumeQuote();if(t.consumeCodeUnitsWhile(i=>i!==o),t.consumeCodeUnit(o),e===y){t.consumeSpaces();const i=t.consumeQuote();t.consumeCodeUnitsWhile(r=>r!==i),t.consumeCodeUnit(i)}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 i=V(t,e);i!==null&&n({type:"EntityDeclaration",name:o,definition:i},t),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(),i=t.getPos();t.skipCodeUnitsWhile(a=>a!==o);const r=t.sliceBack(i);return t.consumeCodeUnit(o),r}else if(e===s.UPPERCASE_S||e===s.UPPERCASE_P){if(P(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,i]=t.consumeQName();n({type:"ElementStart",prefix:o,local:i,start:e},t);let r=!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},t);break}else if(T===s.GREATER_THAN){t.advance(1);const u=t.rangeFrom(l);if(t.config.implicitSelfClosingElements!=null&&t.config.implicitSelfClosingElements.includes(g.getQName(i,o))){n({type:"ElementEnd",end:{type:"Empty"},range:u},t);break}else{n({type:"ElementEnd",end:{type:"Open"},range:u},t),r=!0;break}}else{if(!a)throw new c.XmlError({type:"InvalidChar",expected:"a whitespace",actual:t.currCodeUnitUnchecked()},t.genTextPos());const[u,R,_]=p(t),X=t.getPos();n({type:"Attribute",range:{start:l,end:X},prefix:u,local:R,value:_},t)}}if(r){if(t.config.rawTextElements!=null){const a=g.getQName(i,o);if(t.config.rawTextElements.includes(a)){x(t,n,`</${a}>`);return}}x(t,n)}}function p(t){const[n,e]=t.consumeQName();let o;const i=t.getPos();if(t.skipSpaces(),t.tryConsumeCodeUnit(s.EQUALS)){t.skipSpaces();const r=t.currCodeUnit();if(r===s.SINGLE_QUOTE||r===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:r},t.genTextPos())}else if(!t.config.strictDocument)t.goTo(i),o="true";else throw new c.XmlError({type:"InvalidChar",expected:s.EQUALS,actual:t.currCodeUnit()},t.genTextPos());return[n,e,o]}function x(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 v(t,n,e)}function tt(t,n){const e=t.getPos();t.advance(9);const o=t.consumeCodeUnitsWhile((r,a)=>!(r===s.CLOSE_SQUARE_BRACKET&&a.startsWith(E)));t.skipString(E);const i=t.rangeFrom(e);n({type:"Cdata",text:o,range:i},t)}function nt(t,n){const e=t.getPos();t.advance(2);const[o,i]=t.consumeQName();t.skipSpaces(),t.consumeCodeUnit(s.GREATER_THAN);const r=t.rangeFrom(e);n({type:"ElementEnd",end:{type:"Close",prefix:o,local:i},range:r},t)}function v(t,n,e=s.LESS_THAN){const o=t.getPos(),i=typeof e=="number"?t.consumeCodeUnitsWhile(r=>r!==e):t.consumeCodeUnitsWhile((r,a)=>!a.startsWith(e));if(i.includes(E))throw new c.XmlError({type:"InvalidCharacterData"},t.genTextPos());n({type:"Text",text:i,range:t.rangeFrom(o)},t)}exports.tokenize=K,exports.tokenizeXmlStream=N;
@@ -0,0 +1 @@
1
+ const e={strictDocument:!0,allowDtd:!0,rawTextElements:null,implicitSelfClosingElements:null,contextSliceSize:30},t={strictDocument:!1,allowDtd:!0,rawTextElements:["script","style","title","textarea"],implicitSelfClosingElements:["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"],contextSliceSize:30},l={strictDocument:!1,allowDtd:!0,rawTextElements:["style"],implicitSelfClosingElements:[],contextSliceSize:30};export{t as htmlConfig,l as svgConfig,e as xmlConfig};
package/dist/esm/index.js CHANGED
@@ -1 +1 @@
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
+ import{htmlConfig as E,svgConfig as r,xmlConfig as t}from"./config.js";import{getQName as S}from"./get-q-name.js";import{select as R}from"./selector/select.js";import{TokenSelector as i}from"./selector/TokenSelector.js";import{EToCacheNodeProps as T,ETokenMatchCriteria as N,TokenSelectState as _}from"./selector/TokenSelectState.js";import{TokenSelectStateMachine as f}from"./selector/TokenSelectStateMachine.js";import{tokenToXml as x}from"./token-to-xml.js";import{AMPERSAND as a,CARRIAGE_RETURN as c,CLOSE_SQUARE_BRACKET as s,COLON as L,DOUBLE_QUOTE as n,EQUALS as U,EXCLAMATION_MARK as X,GREATER_THAN as k,HASH as I,HORIZONTAL_TAB as H,HYPHEN as M,LESS_THAN as Q,LINE_FEED as g,LOWERCASE_A as B,LOWERCASE_F as D,LOWERCASE_X as h,LOWERCASE_Z as F,NINE as b,OPEN_SQUARE_BRACKET as j,PERCENT as K,PERIOD as W,QUESTION_MARK as Z,SEMICOLON as d,SINGLE_QUOTE as G,SLASH as y,SPACE as z,UNDERSCORE as v,UPPERCASE_A as Y,UPPERCASE_F as q,UPPERCASE_P as u,UPPERCASE_S as w,UPPERCASE_Z as J,ZERO as V}from"./tokenizer/ascii-constants.js";import{tokenize as ee,tokenizeXmlStream as oe}from"./tokenizer/tokenize.js";import{isAsciiDigit as re,isXmlChar as te,isXmlName as me,isXmlNameByte as Se,isXmlNameStart as Ae,isXmlSpaceByte as Re}from"./tokenizer/utils.js";import{XmlError as ie}from"./tokenizer/XmlError.js";import{XmlStream as Te}from"./tokenizer/XmlStream.js";import{tokensToXml as _e}from"./tokens-to-xml.js";import{processTokenForObject as fe,xmlToObject as le}from"./xml-to-object.js";import{processTokenForSimplifiedObject as Pe,xmlToSimplifiedObject as ae}from"./xml-to-simplified-object.js";export{a as AMPERSAND,c as CARRIAGE_RETURN,s as CLOSE_SQUARE_BRACKET,L as COLON,n as DOUBLE_QUOTE,U as EQUALS,T as EToCacheNodeProps,N as ETokenMatchCriteria,X as EXCLAMATION_MARK,k as GREATER_THAN,I as HASH,H as HORIZONTAL_TAB,M as HYPHEN,Q as LESS_THAN,g as LINE_FEED,B as LOWERCASE_A,D as LOWERCASE_F,h as LOWERCASE_X,F as LOWERCASE_Z,b as NINE,j as OPEN_SQUARE_BRACKET,K as PERCENT,W as PERIOD,Z as QUESTION_MARK,d as SEMICOLON,G as SINGLE_QUOTE,y as SLASH,z as SPACE,_ as TokenSelectState,f as TokenSelectStateMachine,i as TokenSelector,v as UNDERSCORE,Y as UPPERCASE_A,q as UPPERCASE_F,u as UPPERCASE_P,w as UPPERCASE_S,J as UPPERCASE_Z,ie as XmlError,Te as XmlStream,V as ZERO,S as getQName,E as htmlConfig,re as isAsciiDigit,te as isXmlChar,me as isXmlName,Se as isXmlNameByte,Ae as isXmlNameStart,Re as isXmlSpaceByte,fe as processTokenForObject,Pe as processTokenForSimplifiedObject,R as select,r as svgConfig,x as tokenToXml,ee as tokenize,oe as tokenizeXmlStream,_e as tokensToXml,t as xmlConfig,le as xmlToObject,ae as xmlToSimplifiedObject};
@@ -1 +1 @@
1
- import{ETokenMatchCriteria as a}from"./TokenSelectState.js";import{TokenSelectStateMachine as o}from"./TokenSelectStateMachine.js";var u=Object.defineProperty,f=(r,t,e)=>t in r?u(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,s=(r,t,e)=>f(r,typeof t!="symbol"?t+"":t,e);class p{constructor(t){s(this,"_currentDepth",0),s(this,"_tspStateMachines"),s(this,"_isRecording",!1),this._tspStateMachines=t.map(e=>new o(e))}pipeToken(t,e){let n=!1,i=!1;switch(t.type){case"ElementStart":n=this.handleElementStart(t);break;case"Attribute":n=this.handleAttribute(t);break;case"Text":n=this.handleText(t);break;case"ElementEnd":{i=this.handleElementEnd(t);break}}n&&!this._isRecording&&(this._isRecording=!0,e({type:"SelectionStart"}));for(const c of this._tspStateMachines){c.record(t);const l=c.takeRecordedTokens();l!=null&&l.forEach(h=>{e(h)})}this._isRecording&&e(t),i&&(e({type:"SelectionEnd"}),this._isRecording=!1)}handleElementStart(t){this._currentDepth+=1;let e=!1;for(const n of this._tspStateMachines){if(n.resetCurrentStateCache(),n.isFinalState())continue;const i=n.getNextState();i==null||!(i.matchCriteria&a.Name)||n.transitionIfNameMatch(t.local,t.prefix,this._currentDepth)&&n.isFinalState()&&(e=!0)}return e}handleAttribute(t){let e=!1;for(const n of this._tspStateMachines){if(n.isFinalState())continue;const i=n.getNextState();i==null||!(i.matchCriteria&a.Attributes)||n.transitionIfAttributesMatch(t.local,t.prefix,t.value,this._currentDepth)&&n.isFinalState()&&(e=!0)}return e}handleText(t){let e=!1;for(const n of this._tspStateMachines){if(n.isFinalState())continue;const i=n.getNextState();i==null||!(i.matchCriteria&a.Text)||n.transitionIfTextMatch(t.text,this._currentDepth)&&n.isFinalState()&&(e=!0)}return e}handleElementEnd(t){if(t.end.type==="Close"||t.end.type==="Empty"){this._currentDepth-=1;let e=!1;for(const n of this._tspStateMachines){const i=n.getCurrentState();i!=null&&(i.enteredDepth!=null&&this._currentDepth<i.enteredDepth&&n.transitionBack(this._currentDepth),e=e||n.isFinalState())}return!e}return!1}}export{p as TokenSelector};
1
+ import{ETokenMatchCriteria as a}from"./TokenSelectState.js";import{TokenSelectStateMachine as o}from"./TokenSelectStateMachine.js";var u=Object.defineProperty,f=(r,t,e)=>t in r?u(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,s=(r,t,e)=>f(r,typeof t!="symbol"?t+"":t,e);class p{constructor(t){s(this,"_currentDepth",0),s(this,"_tspStateMachines"),s(this,"_isRecording",!1),this._tspStateMachines=t.map(e=>new o(e))}pipeToken(t,e){let n=!1,i=!1;switch(t.type){case"ElementStart":n=this.handleElementStart(t);break;case"Attribute":n=this.handleAttribute(t);break;case"Text":n=this.handleText(t);break;case"ElementEnd":{i=this.handleElementEnd(t);break}}n&&!this._isRecording&&(this._isRecording=!0,e({type:"SelectionStart"}));for(const c of this._tspStateMachines){c.record(t);const l=c.takeRecordedTokens();l!=null&&l.forEach(h=>{e(h)})}this._isRecording&&e(t),i&&this._isRecording&&(e({type:"SelectionEnd"}),this._isRecording=!1)}handleElementStart(t){this._currentDepth+=1;let e=!1;for(const n of this._tspStateMachines){if(n.resetCurrentStateCache(),n.isFinalState())continue;const i=n.getNextState();i==null||!(i.matchCriteria&a.Name)||n.transitionIfNameMatch(t.local,t.prefix,this._currentDepth)&&n.isFinalState()&&(e=!0)}return e}handleAttribute(t){let e=!1;for(const n of this._tspStateMachines){if(n.isFinalState())continue;const i=n.getNextState();i==null||!(i.matchCriteria&a.Attributes)||n.transitionIfAttributesMatch(t.local,t.prefix,t.value,this._currentDepth)&&n.isFinalState()&&(e=!0)}return e}handleText(t){let e=!1;for(const n of this._tspStateMachines){if(n.isFinalState())continue;const i=n.getNextState();i==null||!(i.matchCriteria&a.Text)||n.transitionIfTextMatch(t.text,this._currentDepth)&&n.isFinalState()&&(e=!0)}return e}handleElementEnd(t){if(t.end.type==="Close"||t.end.type==="Empty"){this._currentDepth-=1;let e=!1;for(const n of this._tspStateMachines){const i=n.getCurrentState();i!=null&&(i.enteredDepth!=null&&this._currentDepth<i.enteredDepth&&n.transitionBack(this._currentDepth),e=e||n.isFinalState())}return!e}return!1}}export{p as TokenSelector};
@@ -1 +1 @@
1
- import{AMPERSAND as f,HASH as x,LOWERCASE_X as g,ZERO as U,NINE as w,UPPERCASE_A as y,UPPERCASE_F as S,LOWERCASE_A as E,LOWERCASE_F as v,SEMICOLON as P,COLON as k,SINGLE_QUOTE as N,DOUBLE_QUOTE as T,LINE_FEED as O}from"./ascii-constants.js";import{isXmlChar as d,isXmlSpaceByte as A,isAsciiDigit as b,isXmlNameStart as l,isXmlName as _}from"./utils.js";import{XmlError as o}from"./XmlError.js";var I=Object.defineProperty,m=Object.getOwnPropertySymbols,W=Object.prototype.hasOwnProperty,F=Object.prototype.propertyIsEnumerable,p=(r,t,e)=>t in r?I(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,C=(r,t)=>{for(var e in t||(t={}))W.call(t,e)&&p(r,e,t[e]);if(m)for(var e of m(t))F.call(t,e)&&p(r,e,t[e]);return r},a=(r,t,e)=>p(r,typeof t!="symbol"?t+"":t,e);class u{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,contextSliceSize:c=30}=e;this._text=t,this._pos=i,this._end=this._text.length,this.config={strictDocument:n,allowDtd:s,rawTextElements:h,contextSliceSize:c}}clone(){return new u(this._text,C({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}goToEnd(){this._pos=this._end}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&&A(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(f))return null;let t;if(this.tryConsumeCodeUnit(x)){let e,i;this.tryConsumeCodeUnit(g)?(e=this.consumeCodeUnitsWhile(s=>s>=U&&s<=w||s>=y&&s<=S||s>=E&&s<=v),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(P)?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 c=this.currCodeUnitUnchecked();if(c===k)if(n==null)n=this._pos,this._pos+=1;else throw new o({type:"InvalidName"},this.genTextPosFrom(i));else if(_(c))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===N||t===T)return this._pos+=1,t;throw new o({type:"InvalidChar",expected:"a quote",actual:t},this.genTextPos())}getTextAround(t,e){const i=Math.floor(e/2),n=Math.max(0,t-i),s=Math.min(this._end,t+i+e%2);return this._text.slice(n,s)}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 C({row:i,col:n},this.config.contextSliceSize?{contextSlice:this.getTextAround(t,this.config.contextSliceSize)}:{})}}export{u as XmlStream};
1
+ import{AMPERSAND as x,HASH as g,LOWERCASE_X as U,ZERO as w,NINE as y,UPPERCASE_A as S,UPPERCASE_F as E,LOWERCASE_A as v,LOWERCASE_F as P,SEMICOLON as k,COLON as N,SINGLE_QUOTE as T,DOUBLE_QUOTE as O,LINE_FEED as A}from"./ascii-constants.js";import{isXmlChar as d,isXmlSpaceByte as b,isAsciiDigit as I,isXmlNameStart as l,isXmlName as m}from"./utils.js";import{XmlError as o}from"./XmlError.js";var W=Object.defineProperty,_=Object.getOwnPropertySymbols,F=Object.prototype.hasOwnProperty,R=Object.prototype.propertyIsEnumerable,p=(r,t,e)=>t in r?W(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,C=(r,t)=>{for(var e in t||(t={}))F.call(t,e)&&p(r,e,t[e]);if(_)for(var e of _(t))R.call(t,e)&&p(r,e,t[e]);return r},a=(r,t,e)=>p(r,typeof t!="symbol"?t+"":t,e);class u{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,implicitSelfClosingElements:c=null,contextSliceSize:f=30}=e;this._text=t,this._pos=i,this._end=this._text.length,this.config={strictDocument:n,allowDtd:s,rawTextElements:h,implicitSelfClosingElements:c,contextSliceSize:f}}clone(){return new u(this._text,C({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}goToEnd(){this._pos=this._end}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(x))return null;let t;if(this.tryConsumeCodeUnit(g)){let e,i;this.tryConsumeCodeUnit(U)?(e=this.consumeCodeUnitsWhile(s=>s>=w&&s<=y||s>=S&&s<=E||s>=v&&s<=P),i=16):(e=this.consumeCodeUnitsWhile(s=>I(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(!m(e))break;this._pos+=1}}consumeQName(){var t,e;const i=this._pos;let n=null;for(;this._pos<this._end;){const c=this.currCodeUnitUnchecked();if(c===N)if(n==null)n=this._pos,this._pos+=1;else throw new o({type:"InvalidName"},this.genTextPosFrom(i));else if(m(c))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===T||t===O)return this._pos+=1,t;throw new o({type:"InvalidChar",expected:"a quote",actual:t},this.genTextPos())}getTextAround(t,e){const i=Math.floor(e/2),n=Math.max(0,t-i),s=Math.min(this._end,t+i+e%2);return this._text.slice(n,s)}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)===A?(i++,n=1):n++;return C({row:i,col:n},this.config.contextSliceSize?{contextSlice:this.getTextAround(t,this.config.contextSliceSize)}:{})}}export{u as XmlStream};
@@ -1 +1 @@
1
- import{getQName as b}from"../get-q-name.js";import{LESS_THAN as d,GREATER_THAN as r,SLASH as f,EQUALS as T,SINGLE_QUOTE as k,DOUBLE_QUOTE as w,HYPHEN as B,QUESTION_MARK as W,OPEN_SQUARE_BRACKET as M,PERCENT as X,EXCLAMATION_MARK as H,UPPERCASE_S as Y,UPPERCASE_P 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",ot="version",et="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(ot))throw new c({type:"InvalidString",expected:"version"},t.genTextPos());m(t),n(t),t.startsWith(et)&&(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 o=t.consumeCodeUnitsWhile((e,i)=>!(e===B&&i.startsWith(A)));if(t.skipString(A),o.includes("--")||o.endsWith("-"))throw new c({type:"InvalidComment"},t.genTextPosFrom(s));n({type:"Comment",text:o,range:t.rangeFrom(s)},t)}function S(t,n){if(t.startsWith(P))throw new c({type:"UnexpectedDeclaration"},t.genTextPos());const s=t.getPos();t.advance(2);const o=t.consumeName();t.skipSpaces();const e=t.consumeCodeUnitsWhile((i,a)=>!(i===W&&a.startsWith(N)));t.skipString(N),n({type:"ProcessingInstruction",target:o,content:e.length===0?void 0:e,range:t.rangeFrom(s)},t)}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(o){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 o=t.consumeQuote();if(t.consumeCodeUnitsWhile(e=>e!==o),t.consumeCodeUnit(o),s===I){t.consumeSpaces();const e=t.consumeQuote();t.consumeCodeUnitsWhile(i=>i!==e),t.consumeCodeUnit(e)}return!0}return!1}function dt(t,n){t.advance(8),t.consumeSpaces();const s=!t.tryConsumeCodeUnit(X);s||t.consumeSpaces();const o=t.consumeName();t.consumeSpaces();const e=ut(t,s);e!==null&&n({type:"EntityDeclaration",name:o,definition:e},t),t.skipSpaces(),t.consumeCodeUnit(r)}function ut(t,n){const s=t.currCodeUnit();if(s===w||s===k){const o=t.consumeQuote(),e=t.getPos();t.skipCodeUnitsWhile(a=>a!==o);const i=t.sliceBack(e);return t.consumeCodeUnit(o),i}else if(s===Y||s===K){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[o,e]=t.consumeQName();n({type:"ElementStart",prefix:o,local:e,start:s},t);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},t);break}else if(E===r){t.advance(1);const u=t.rangeFrom(p);n({type:"ElementEnd",end:{type:"Open"},range:u},t),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},t)}}if(i){if(t.config.rawTextElements!=null){const a=b(e,o);if(t.config.rawTextElements.includes(a)){Q(t,n,`</${a}>`);return}}Q(t,n)}}function m(t){const[n,s]=t.consumeQName();let o;const e=t.getPos();if(t.skipSpaces(),t.tryConsumeCodeUnit(T)){t.skipSpaces();const i=t.currCodeUnit();if(i===k||i===w){const a=t.consumeQuote();o=t.consumeCodeUnitsWhile(p=>p!==a&&p!==d),t.consumeCodeUnit(a)}else if(!t.config.strictDocument)o=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(e),o="true";else throw new c({type:"InvalidChar",expected:T,actual:t.currCodeUnit()},t.genTextPos());return[n,s,o]}function Q(t,n,s=d){for(;!t.atEnd();)if(typeof s=="number"?t.currCodeUnit()===s:t.startsWith(s)){const o=t.nextCodeUnit();if(o===H)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(o===W)S(t,n);else if(o===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 o=t.consumeCodeUnitsWhile((i,a)=>!(i===z&&a.startsWith(g)));t.skipString(g);const e=t.rangeFrom(s);n({type:"Cdata",text:o,range:e},t)}function ft(t,n){const s=t.getPos();t.advance(2);const[o,e]=t.consumeQName();t.skipSpaces(),t.consumeCodeUnit(r);const i=t.rangeFrom(s);n({type:"ElementEnd",end:{type:"Close",prefix:o,local:e},range:i},t)}function L(t,n,s=d){const o=t.getPos(),e=typeof s=="number"?t.consumeCodeUnitsWhile(i=>i!==s):t.consumeCodeUnitsWhile((i,a)=>!a.startsWith(s));if(e.includes(g))throw new c({type:"InvalidCharacterData"},t.genTextPos());n({type:"Text",text:e,range:t.rangeFrom(o)},t)}export{at as tokenize,D as tokenizeXmlStream};
1
+ import{getQName as k}from"../get-q-name.js";import{LESS_THAN as d,GREATER_THAN as r,SLASH as f,EQUALS as T,SINGLE_QUOTE as w,DOUBLE_QUOTE as W,HYPHEN as B,QUESTION_MARK as y,OPEN_SQUARE_BRACKET as M,PERCENT as X,EXCLAMATION_MARK as H,UPPERCASE_S as Y,UPPERCASE_P 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 ",x="?>",j="<!ENTITY",J="<!ELEMENT",V="<!ATTLIST",Z="<!NOTATION",v="<!DOCTYPE",N="<?",A="?>",h="<!--",I="-->",tt="<![CDATA[",g="]]>",nt="NDATA",D="PUBLIC",st="SYSTEM",et="version",ot="encoding",it="standalone";function at(t,n,s={}){F(new G(t,s),n)}function F(t,n){if(t.startsWith($)&&t.advance(1),t.startsWith(P)&&ct(t),u(t,n),t.skipSpaces(),t.startsWith(v)||t.startsWith(v.toLowerCase())){if(!t.config.allowDtd)throw new c({type:"DtdDetected"});rt(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 c({type:"UnknownToken",message:"Not at end"},t.genTextPos())}else for(;!t.atEnd();)t.currCodeUnit()===d?S(t,n):_(t,n),u(t,n)}function u(t,n){for(;!t.atEnd();)if(t.skipSpaces(),t.startsWith(h))C(t,n);else if(t.startsWith(N))E(t,n);else break}function ct(t){function n(s){if(s.startsWithSpace())s.skipSpaces();else if(!s.startsWith(x)&&!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(x)}function C(t,n){const s=t.getPos();t.advance(4);const e=t.consumeCodeUnitsWhile((o,i)=>!(o===B&&i.startsWith(I)));if(t.skipString(I),e.includes("--")||e.endsWith("-"))throw new c({type:"InvalidComment"},t.genTextPosFrom(s));n({type:"Comment",text:e,range:t.rangeFrom(s)},t)}function E(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===y&&a.startsWith(A)));t.skipString(A),n({type:"ProcessingInstruction",target:e,content:o.length===0?void 0:o,range:t.rangeFrom(s)},t)}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))lt(t,n);else if(t.startsWith(h))C(t,n);else if(t.startsWith(N))E(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{ut(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(),Q(t),t.skipSpaces();const n=t.currCodeUnit();if(n!==M&&n!==r)throw new c({type:"InvalidChar",expected:"'[' or '>'",actual:n},t.genTextPos())}function Q(t){if(t.startsWith(st)||t.startsWith(D)){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===D){t.consumeSpaces();const o=t.consumeQuote();t.consumeCodeUnitsWhile(i=>i!==o),t.consumeCodeUnit(o)}return!0}return!1}function lt(t,n){t.advance(8),t.consumeSpaces();const s=!t.tryConsumeCodeUnit(X);s||t.consumeSpaces();const e=t.consumeName();t.consumeSpaces();const o=dt(t,s);o!==null&&n({type:"EntityDeclaration",name:e,definition:o},t),t.skipSpaces(),t.consumeCodeUnit(r)}function dt(t,n){const s=t.currCodeUnit();if(s===W||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===Y||s===K){if(Q(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 ut(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},t);let i=!1;for(;!t.atEnd();){const a=t.startsWithSpace();t.skipSpaces();const p=t.getPos(),U=t.currCodeUnit();if(U===f){t.advance(1),t.consumeCodeUnit(r);const l=t.rangeFrom(p);n({type:"ElementEnd",end:{type:"Empty"},range:l},t);break}else if(U===r){t.advance(1);const l=t.rangeFrom(p);if(t.config.implicitSelfClosingElements!=null&&t.config.implicitSelfClosingElements.includes(k(o,e))){n({type:"ElementEnd",end:{type:"Empty"},range:l},t);break}else{n({type:"ElementEnd",end:{type:"Open"},range:l},t),i=!0;break}}else{if(!a)throw new c({type:"InvalidChar",expected:"a whitespace",actual:t.currCodeUnitUnchecked()},t.genTextPos());const[l,O,R]=m(t),b=t.getPos();n({type:"Attribute",range:{start:p,end:b},prefix:l,local:O,value:R},t)}}if(i){if(t.config.rawTextElements!=null){const a=k(o,e);if(t.config.rawTextElements.includes(a)){L(t,n,`</${a}>`);return}}L(t,n)}}function m(t){const[n,s]=t.consumeQName();let e;const o=t.getPos();if(t.skipSpaces(),t.tryConsumeCodeUnit(T)){t.skipSpaces();const i=t.currCodeUnit();if(i===w||i===W){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:T,actual:t.currCodeUnit()},t.genTextPos());return[n,s,e]}function L(t,n,s=d){for(;!t.atEnd();)if(typeof s=="number"?t.currCodeUnit()===s:t.startsWith(s)){const e=t.nextCodeUnit();if(e===H)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===y)E(t,n);else if(e===f){ft(t,n);break}else S(t,n)}else _(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},t)}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},t)}function _(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)},t)}export{at as tokenize,F as tokenizeXmlStream};
@@ -0,0 +1,16 @@
1
+ import { TXmlStreamOptions } from './tokenizer';
2
+ /**
3
+ * Default XML configuration with strict XML compliance.
4
+ */
5
+ export declare const xmlConfig: TXmlStreamOptions;
6
+ /**
7
+ * HTML configuration with HTML-specific settings.
8
+ * - Non-strict document structure
9
+ * - Raw text elements like script and style
10
+ * - Implicit self-closing elements (void elements in HTML)
11
+ */
12
+ export declare const htmlConfig: TXmlStreamOptions;
13
+ /**
14
+ * SVG configuration with SVG-specific settings.
15
+ */
16
+ export declare const svgConfig: TXmlStreamOptions;
@@ -1,3 +1,4 @@
1
+ export * from './config';
1
2
  export * from './get-q-name';
2
3
  export * from './selector';
3
4
  export * from './token-to-xml';
@@ -227,6 +227,12 @@ export interface TXmlStreamConfig {
227
227
  * @default null
228
228
  */
229
229
  rawTextElements: string[] | null;
230
+ /**
231
+ * List of element names that should be treated as self-closing without requiring '/>' syntax.
232
+ * Common examples are 'meta' and 'link' for HTML-like documents.
233
+ * @default null
234
+ */
235
+ implicitSelfClosingElements: string[] | null;
230
236
  /**
231
237
  * Whether to allow DOCTYPE declarations.
232
238
  * @default true
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xml-tokenizer",
3
- "version": "0.0.28",
3
+ "version": "0.0.30",
4
4
  "private": false,
5
5
  "description": "Straightforward and typesafe XML tokenizer that streams tokens through a callback mechanism",
6
6
  "keywords": [],