xml-tokenizer 0.0.32 → 0.0.34
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/config.js +1 -43
- package/dist/cjs/get-q-name.js +1 -8
- package/dist/cjs/index.js +1 -80
- package/dist/cjs/processor/process.js +1 -0
- package/dist/cjs/processor/processors/path-tracker.js +1 -0
- package/dist/cjs/processor/validate-processor-order.js +5 -0
- package/dist/cjs/selector/TokenSelectState.js +1 -107
- package/dist/cjs/selector/TokenSelectStateMachine.js +1 -151
- package/dist/cjs/selector/TokenSelector.js +1 -140
- package/dist/cjs/selector/match-string.js +1 -22
- package/dist/cjs/selector/select.js +1 -20
- package/dist/cjs/token-to-xml.js +1 -45
- package/dist/cjs/tokenizer/XmlError.js +1 -97
- package/dist/cjs/tokenizer/XmlStream.js +1 -479
- package/dist/cjs/tokenizer/ascii-constants.js +1 -70
- package/dist/cjs/tokenizer/tokenize.js +2 -420
- package/dist/cjs/tokenizer/utils.js +1 -48
- package/dist/cjs/tokens-to-xml.js +1 -14
- package/dist/cjs/xml-to-object.js +1 -70
- package/dist/cjs/xml-to-simplified-object.js +1 -87
- package/dist/esm/config.js +1 -39
- package/dist/esm/get-q-name.js +1 -6
- package/dist/esm/index.js +1 -16
- package/dist/esm/processor/process.js +1 -0
- package/dist/esm/processor/processors/path-tracker.js +1 -0
- package/dist/esm/processor/validate-processor-order.js +5 -0
- package/dist/esm/selector/TokenSelectState.js +1 -103
- package/dist/esm/selector/TokenSelectStateMachine.js +1 -149
- package/dist/esm/selector/TokenSelector.js +1 -138
- package/dist/esm/selector/match-string.js +1 -20
- package/dist/esm/selector/select.js +1 -18
- package/dist/esm/token-to-xml.js +1 -43
- package/dist/esm/tokenizer/XmlError.js +1 -95
- package/dist/esm/tokenizer/XmlStream.js +1 -477
- package/dist/esm/tokenizer/ascii-constants.js +1 -36
- package/dist/esm/tokenizer/tokenize.js +2 -417
- package/dist/esm/tokenizer/utils.js +1 -41
- package/dist/esm/tokens-to-xml.js +1 -12
- package/dist/esm/xml-to-object.js +1 -67
- package/dist/esm/xml-to-simplified-object.js +1 -84
- package/dist/types/config.d.ts +0 -1
- package/dist/types/get-q-name.d.ts +0 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/processor/index.d.ts +4 -0
- package/dist/types/processor/process.d.ts +3 -0
- package/dist/types/processor/processors/index.d.ts +1 -0
- package/dist/types/processor/processors/path-tracker.d.ts +5 -0
- package/dist/types/processor/types.d.ts +10 -0
- package/dist/types/processor/validate-processor-order.d.ts +2 -0
- package/dist/types/selector/TokenSelectState.d.ts +0 -1
- package/dist/types/selector/TokenSelectStateMachine.d.ts +0 -1
- package/dist/types/selector/TokenSelector.d.ts +0 -1
- package/dist/types/selector/index.d.ts +0 -1
- package/dist/types/selector/match-string.d.ts +0 -1
- package/dist/types/selector/select.d.ts +0 -1
- package/dist/types/selector/types.d.ts +0 -1
- package/dist/types/token-to-xml.d.ts +0 -1
- package/dist/types/tokenizer/XmlError.d.ts +0 -1
- package/dist/types/tokenizer/XmlStream.d.ts +20 -1
- package/dist/types/tokenizer/ascii-constants.d.ts +0 -1
- package/dist/types/tokenizer/index.d.ts +0 -1
- package/dist/types/tokenizer/tokenize.d.ts +0 -1
- package/dist/types/tokenizer/types.d.ts +0 -1
- package/dist/types/tokenizer/utils.d.ts +0 -1
- package/dist/types/tokens-to-xml.d.ts +0 -1
- package/dist/types/xml-to-object.d.ts +0 -1
- package/dist/types/xml-to-simplified-object.d.ts +0 -1
- package/package.json +6 -6
- package/dist/cjs/config.js.map +0 -1
- package/dist/cjs/get-q-name.js.map +0 -1
- package/dist/cjs/index.js.map +0 -1
- package/dist/cjs/selector/TokenSelectState.js.map +0 -1
- package/dist/cjs/selector/TokenSelectStateMachine.js.map +0 -1
- package/dist/cjs/selector/TokenSelector.js.map +0 -1
- package/dist/cjs/selector/match-string.js.map +0 -1
- package/dist/cjs/selector/select.js.map +0 -1
- package/dist/cjs/token-to-xml.js.map +0 -1
- package/dist/cjs/tokenizer/XmlError.js.map +0 -1
- package/dist/cjs/tokenizer/XmlStream.js.map +0 -1
- package/dist/cjs/tokenizer/ascii-constants.js.map +0 -1
- package/dist/cjs/tokenizer/tokenize.js.map +0 -1
- package/dist/cjs/tokenizer/utils.js.map +0 -1
- package/dist/cjs/tokens-to-xml.js.map +0 -1
- package/dist/cjs/xml-to-object.js.map +0 -1
- package/dist/cjs/xml-to-simplified-object.js.map +0 -1
- package/dist/esm/config.js.map +0 -1
- package/dist/esm/get-q-name.js.map +0 -1
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/selector/TokenSelectState.js.map +0 -1
- package/dist/esm/selector/TokenSelectStateMachine.js.map +0 -1
- package/dist/esm/selector/TokenSelector.js.map +0 -1
- package/dist/esm/selector/match-string.js.map +0 -1
- package/dist/esm/selector/select.js.map +0 -1
- package/dist/esm/token-to-xml.js.map +0 -1
- package/dist/esm/tokenizer/XmlError.js.map +0 -1
- package/dist/esm/tokenizer/XmlStream.js.map +0 -1
- package/dist/esm/tokenizer/ascii-constants.js.map +0 -1
- package/dist/esm/tokenizer/tokenize.js.map +0 -1
- package/dist/esm/tokenizer/utils.js.map +0 -1
- package/dist/esm/tokens-to-xml.js.map +0 -1
- package/dist/esm/xml-to-object.js.map +0 -1
- package/dist/esm/xml-to-simplified-object.js.map +0 -1
- package/dist/types/config.d.ts.map +0 -1
- package/dist/types/get-q-name.d.ts.map +0 -1
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/selector/TokenSelectState.d.ts.map +0 -1
- package/dist/types/selector/TokenSelectStateMachine.d.ts.map +0 -1
- package/dist/types/selector/TokenSelector.d.ts.map +0 -1
- package/dist/types/selector/index.d.ts.map +0 -1
- package/dist/types/selector/match-string.d.ts.map +0 -1
- package/dist/types/selector/select.d.ts.map +0 -1
- package/dist/types/selector/types.d.ts.map +0 -1
- package/dist/types/token-to-xml.d.ts.map +0 -1
- package/dist/types/tokenizer/XmlError.d.ts.map +0 -1
- package/dist/types/tokenizer/XmlStream.d.ts.map +0 -1
- package/dist/types/tokenizer/ascii-constants.d.ts.map +0 -1
- package/dist/types/tokenizer/index.d.ts.map +0 -1
- package/dist/types/tokenizer/tokenize.d.ts.map +0 -1
- package/dist/types/tokenizer/types.d.ts.map +0 -1
- package/dist/types/tokenizer/utils.d.ts.map +0 -1
- package/dist/types/tokens-to-xml.d.ts.map +0 -1
- package/dist/types/xml-to-object.d.ts.map +0 -1
- package/dist/types/xml-to-simplified-object.d.ts.map +0 -1
package/dist/cjs/config.js
CHANGED
|
@@ -1,43 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const xmlConfig = {
|
|
4
|
-
strictDocument: true,
|
|
5
|
-
allowDtd: true,
|
|
6
|
-
rawTextElements: null,
|
|
7
|
-
implicitSelfClosingElements: null,
|
|
8
|
-
contextSliceSize: 30
|
|
9
|
-
};
|
|
10
|
-
const htmlConfig = {
|
|
11
|
-
strictDocument: false,
|
|
12
|
-
allowDtd: true,
|
|
13
|
-
rawTextElements: ["script", "style", "title", "textarea"],
|
|
14
|
-
implicitSelfClosingElements: [
|
|
15
|
-
"area",
|
|
16
|
-
"base",
|
|
17
|
-
"br",
|
|
18
|
-
"col",
|
|
19
|
-
"embed",
|
|
20
|
-
"hr",
|
|
21
|
-
"img",
|
|
22
|
-
"input",
|
|
23
|
-
"link",
|
|
24
|
-
"meta",
|
|
25
|
-
"param",
|
|
26
|
-
"source",
|
|
27
|
-
"track",
|
|
28
|
-
"wbr"
|
|
29
|
-
],
|
|
30
|
-
contextSliceSize: 30
|
|
31
|
-
};
|
|
32
|
-
const svgConfig = {
|
|
33
|
-
strictDocument: false,
|
|
34
|
-
allowDtd: true,
|
|
35
|
-
rawTextElements: ["style"],
|
|
36
|
-
implicitSelfClosingElements: [],
|
|
37
|
-
contextSliceSize: 30
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
exports.htmlConfig = htmlConfig;
|
|
41
|
-
exports.svgConfig = svgConfig;
|
|
42
|
-
exports.xmlConfig = xmlConfig;
|
|
43
|
-
//# sourceMappingURL=config.js.map
|
|
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/get-q-name.js
CHANGED
|
@@ -1,8 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
function getQName(local, prefix = null) {
|
|
4
|
-
return prefix != null && prefix.length > 0 ? `${prefix}:${local}` : local;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
exports.getQName = getQName;
|
|
8
|
-
//# sourceMappingURL=get-q-name.js.map
|
|
1
|
+
"use strict";function l(t,e=null){return e!=null&&e.length>0?`${e}:${t}`:t}exports.getQName=l;
|
package/dist/cjs/index.js
CHANGED
|
@@ -1,80 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var config = require('./config.js');
|
|
4
|
-
var getQName = require('./get-q-name.js');
|
|
5
|
-
var select = require('./selector/select.js');
|
|
6
|
-
var TokenSelector = require('./selector/TokenSelector.js');
|
|
7
|
-
var TokenSelectState = require('./selector/TokenSelectState.js');
|
|
8
|
-
var TokenSelectStateMachine = require('./selector/TokenSelectStateMachine.js');
|
|
9
|
-
var tokenToXml = require('./token-to-xml.js');
|
|
10
|
-
var asciiConstants = require('./tokenizer/ascii-constants.js');
|
|
11
|
-
var tokenize = require('./tokenizer/tokenize.js');
|
|
12
|
-
var utils = require('./tokenizer/utils.js');
|
|
13
|
-
var XmlError = require('./tokenizer/XmlError.js');
|
|
14
|
-
var XmlStream = require('./tokenizer/XmlStream.js');
|
|
15
|
-
var tokensToXml = require('./tokens-to-xml.js');
|
|
16
|
-
var xmlToObject = require('./xml-to-object.js');
|
|
17
|
-
var xmlToSimplifiedObject = require('./xml-to-simplified-object.js');
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
exports.htmlConfig = config.htmlConfig;
|
|
22
|
-
exports.svgConfig = config.svgConfig;
|
|
23
|
-
exports.xmlConfig = config.xmlConfig;
|
|
24
|
-
exports.getQName = getQName.getQName;
|
|
25
|
-
exports.select = select.select;
|
|
26
|
-
exports.TokenSelector = TokenSelector.TokenSelector;
|
|
27
|
-
exports.EToCacheNodeProps = TokenSelectState.EToCacheNodeProps;
|
|
28
|
-
exports.ETokenMatchCriteria = TokenSelectState.ETokenMatchCriteria;
|
|
29
|
-
exports.TokenSelectState = TokenSelectState.TokenSelectState;
|
|
30
|
-
exports.TokenSelectStateMachine = TokenSelectStateMachine.TokenSelectStateMachine;
|
|
31
|
-
exports.tokenToXml = tokenToXml.tokenToXml;
|
|
32
|
-
exports.AMPERSAND = asciiConstants.AMPERSAND;
|
|
33
|
-
exports.CARRIAGE_RETURN = asciiConstants.CARRIAGE_RETURN;
|
|
34
|
-
exports.CLOSE_SQUARE_BRACKET = asciiConstants.CLOSE_SQUARE_BRACKET;
|
|
35
|
-
exports.COLON = asciiConstants.COLON;
|
|
36
|
-
exports.DOUBLE_QUOTE = asciiConstants.DOUBLE_QUOTE;
|
|
37
|
-
exports.EQUALS = asciiConstants.EQUALS;
|
|
38
|
-
exports.EXCLAMATION_MARK = asciiConstants.EXCLAMATION_MARK;
|
|
39
|
-
exports.GREATER_THAN = asciiConstants.GREATER_THAN;
|
|
40
|
-
exports.HASH = asciiConstants.HASH;
|
|
41
|
-
exports.HORIZONTAL_TAB = asciiConstants.HORIZONTAL_TAB;
|
|
42
|
-
exports.HYPHEN = asciiConstants.HYPHEN;
|
|
43
|
-
exports.LESS_THAN = asciiConstants.LESS_THAN;
|
|
44
|
-
exports.LINE_FEED = asciiConstants.LINE_FEED;
|
|
45
|
-
exports.LOWERCASE_A = asciiConstants.LOWERCASE_A;
|
|
46
|
-
exports.LOWERCASE_F = asciiConstants.LOWERCASE_F;
|
|
47
|
-
exports.LOWERCASE_X = asciiConstants.LOWERCASE_X;
|
|
48
|
-
exports.LOWERCASE_Z = asciiConstants.LOWERCASE_Z;
|
|
49
|
-
exports.NINE = asciiConstants.NINE;
|
|
50
|
-
exports.OPEN_SQUARE_BRACKET = asciiConstants.OPEN_SQUARE_BRACKET;
|
|
51
|
-
exports.PERCENT = asciiConstants.PERCENT;
|
|
52
|
-
exports.PERIOD = asciiConstants.PERIOD;
|
|
53
|
-
exports.QUESTION_MARK = asciiConstants.QUESTION_MARK;
|
|
54
|
-
exports.SEMICOLON = asciiConstants.SEMICOLON;
|
|
55
|
-
exports.SINGLE_QUOTE = asciiConstants.SINGLE_QUOTE;
|
|
56
|
-
exports.SLASH = asciiConstants.SLASH;
|
|
57
|
-
exports.SPACE = asciiConstants.SPACE;
|
|
58
|
-
exports.UNDERSCORE = asciiConstants.UNDERSCORE;
|
|
59
|
-
exports.UPPERCASE_A = asciiConstants.UPPERCASE_A;
|
|
60
|
-
exports.UPPERCASE_F = asciiConstants.UPPERCASE_F;
|
|
61
|
-
exports.UPPERCASE_P = asciiConstants.UPPERCASE_P;
|
|
62
|
-
exports.UPPERCASE_S = asciiConstants.UPPERCASE_S;
|
|
63
|
-
exports.UPPERCASE_Z = asciiConstants.UPPERCASE_Z;
|
|
64
|
-
exports.ZERO = asciiConstants.ZERO;
|
|
65
|
-
exports.tokenize = tokenize.tokenize;
|
|
66
|
-
exports.tokenizeXmlStream = tokenize.tokenizeXmlStream;
|
|
67
|
-
exports.isAsciiDigit = utils.isAsciiDigit;
|
|
68
|
-
exports.isXmlChar = utils.isXmlChar;
|
|
69
|
-
exports.isXmlName = utils.isXmlName;
|
|
70
|
-
exports.isXmlNameByte = utils.isXmlNameByte;
|
|
71
|
-
exports.isXmlNameStart = utils.isXmlNameStart;
|
|
72
|
-
exports.isXmlSpaceByte = utils.isXmlSpaceByte;
|
|
73
|
-
exports.XmlError = XmlError.XmlError;
|
|
74
|
-
exports.XmlStream = XmlStream.XmlStream;
|
|
75
|
-
exports.tokensToXml = tokensToXml.tokensToXml;
|
|
76
|
-
exports.processTokenForObject = xmlToObject.processTokenForObject;
|
|
77
|
-
exports.xmlToObject = xmlToObject.xmlToObject;
|
|
78
|
-
exports.processTokenForSimplifiedObject = xmlToSimplifiedObject.processTokenForSimplifiedObject;
|
|
79
|
-
exports.xmlToSimplifiedObject = xmlToSimplifiedObject.xmlToSimplifiedObject;
|
|
80
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
"use strict";var E=require("./config.js"),a=require("./get-q-name.js"),A=require("./processor/process.js"),T=require("./processor/processors/path-tracker.js"),R=require("./processor/validate-processor-order.js"),l=require("./selector/select.js"),m=require("./selector/TokenSelector.js"),t=require("./selector/TokenSelectState.js"),O=require("./selector/TokenSelectStateMachine.js"),C=require("./token-to-xml.js"),e=require("./tokenizer/ascii-constants.js"),i=require("./tokenizer/tokenize.js"),r=require("./tokenizer/utils.js"),s=require("./tokenizer/XmlError.js"),c=require("./tokenizer/XmlStream.js"),N=require("./tokens-to-xml.js"),S=require("./xml-to-object.js"),o=require("./xml-to-simplified-object.js");exports.htmlConfig=E.htmlConfig,exports.svgConfig=E.svgConfig,exports.xmlConfig=E.xmlConfig,exports.getQName=a.getQName,exports.process=A.process,exports.pathTracker=T.pathTracker,exports.validateProcessorOrder=R.validateProcessorOrder,exports.select=l.select,exports.TokenSelector=m.TokenSelector,exports.EToCacheNodeProps=t.EToCacheNodeProps,exports.ETokenMatchCriteria=t.ETokenMatchCriteria,exports.TokenSelectState=t.TokenSelectState,exports.TokenSelectStateMachine=O.TokenSelectStateMachine,exports.tokenToXml=C.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=i.tokenize,exports.tokenizeXmlStream=i.tokenizeXmlStream,exports.isAsciiDigit=r.isAsciiDigit,exports.isXmlChar=r.isXmlChar,exports.isXmlName=r.isXmlName,exports.isXmlNameByte=r.isXmlNameByte,exports.isXmlNameStart=r.isXmlNameStart,exports.isXmlSpaceByte=r.isXmlSpaceByte,exports.XmlError=s.XmlError,exports.XmlStream=c.XmlStream,exports.tokensToXml=N.tokensToXml,exports.processTokenForObject=S.processTokenForObject,exports.xmlToObject=S.xmlToObject,exports.processTokenForSimplifiedObject=o.processTokenForSimplifiedObject,exports.xmlToSimplifiedObject=o.xmlToSimplifiedObject;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var a=require("../tokenizer/tokenize.js"),i=require("./validate-processor-order.js");function l(c,r,n){i.validateProcessorOrder(r);const e={};for(const s of r)Object.assign(e,s.context);return a.tokenize(c,s=>{var o;for(const t of r)(o=t.process)==null||o.call(t,s,e)},n),e}exports.process=l;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const a={name:"PathTracker",context:{currentPath:[]},process:(t,e)=>{if(t.type==="ElementStart"){const r=t.prefix?`${t.prefix}:${t.local}`:t.local;e.currentPath.push(r)}else t.type==="ElementEnd"&&t.end.type==="Close"&&e.currentPath.pop()}};exports.pathTracker=a;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";function p(r){const t=new Set;for(let s=0;s<r.length;s++){const o=r[s];if(o.deps==null){t.add(o);continue}const d=[];for(const n of o.deps)t.has(n)||d.push(n);if(d.length>0){const n=o.name||`Processor[${s}]`,a=d.map((e,c)=>{const i=r.indexOf(e);return e.name||`Processor[${i>=0?i:c}]`}).join(", "),l=r.filter(e=>e!=null).map((e,c)=>e.name||`Processor[${c}]`).join(" \u2192 ");throw new Error(`Processor dependency order invalid:
|
|
2
|
+
${n} depends on: ${a}
|
|
3
|
+
But those dependencies haven't been processed yet.
|
|
4
|
+
Current order: ${l}
|
|
5
|
+
Solution: Move dependencies before ${n} in the processors array.`)}t.add(o)}}exports.validateProcessorOrder=p;
|
|
@@ -1,107 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var matchString = require('./match-string.js');
|
|
4
|
-
|
|
5
|
-
var __defProp = Object.defineProperty;
|
|
6
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
7
|
-
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
8
|
-
class TokenSelectState {
|
|
9
|
-
constructor(segment) {
|
|
10
|
-
__publicField(this, "_segment");
|
|
11
|
-
__publicField(this, "_matchCriteria", 0 /* None */);
|
|
12
|
-
__publicField(this, "_toCacheNodeProps", 0 /* None */);
|
|
13
|
-
__publicField(this, "_enteredDepth", null);
|
|
14
|
-
this._segment = segment;
|
|
15
|
-
this.applyLevels();
|
|
16
|
-
}
|
|
17
|
-
get matchCriteria() {
|
|
18
|
-
return this._matchCriteria;
|
|
19
|
-
}
|
|
20
|
-
get toCacheNodeProps() {
|
|
21
|
-
return this._toCacheNodeProps;
|
|
22
|
-
}
|
|
23
|
-
get enteredDepth() {
|
|
24
|
-
return this._enteredDepth;
|
|
25
|
-
}
|
|
26
|
-
applyLevels() {
|
|
27
|
-
let matchCriteria = 0 /* None */;
|
|
28
|
-
let cacheProps = 0 /* None */;
|
|
29
|
-
if (this._segment.local != null || this._segment.prefix != null) {
|
|
30
|
-
matchCriteria |= 1 /* Name */;
|
|
31
|
-
}
|
|
32
|
-
if (this._segment.attributes != null) {
|
|
33
|
-
matchCriteria |= 2 /* Attributes */;
|
|
34
|
-
cacheProps |= 2 /* Attributes */;
|
|
35
|
-
}
|
|
36
|
-
if (this._segment.text != null) {
|
|
37
|
-
matchCriteria |= 4 /* Text */;
|
|
38
|
-
}
|
|
39
|
-
this._matchCriteria = matchCriteria;
|
|
40
|
-
this._toCacheNodeProps = cacheProps;
|
|
41
|
-
}
|
|
42
|
-
matchesName(local, prefix) {
|
|
43
|
-
return (
|
|
44
|
-
// Match local
|
|
45
|
-
(this._segment.local == null || matchString.matchString(local, this._segment.local)) && // Match prefix
|
|
46
|
-
(this._segment.prefix == null || matchString.matchString(prefix, this._segment.prefix))
|
|
47
|
-
);
|
|
48
|
-
}
|
|
49
|
-
matchesAttributes(attributes) {
|
|
50
|
-
if (this._segment.attributes == null) {
|
|
51
|
-
return true;
|
|
52
|
-
}
|
|
53
|
-
for (const attributeConfig of this._segment.attributes) {
|
|
54
|
-
let matchFound = false;
|
|
55
|
-
for (const attribute of attributes) {
|
|
56
|
-
const localMatch = attributeConfig.local == null || matchString.matchString(attribute.local, attributeConfig.local);
|
|
57
|
-
const valueMatch = attributeConfig.value == null || attribute.value != null && matchString.matchString(attribute.value, attributeConfig.value);
|
|
58
|
-
const prefixMatch = attributeConfig.prefix == null || attribute.prefix != null && matchString.matchString(attribute.prefix, attributeConfig.prefix);
|
|
59
|
-
if (localMatch && valueMatch && prefixMatch) {
|
|
60
|
-
matchFound = true;
|
|
61
|
-
break;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
if (!matchFound) {
|
|
65
|
-
return false;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
return true;
|
|
69
|
-
}
|
|
70
|
-
matchesText(text) {
|
|
71
|
-
return this._segment.text == null || matchString.matchString(text, this._segment.text);
|
|
72
|
-
}
|
|
73
|
-
matchesDepth(depth, parentDepth) {
|
|
74
|
-
switch (this._segment.axis) {
|
|
75
|
-
case "child":
|
|
76
|
-
return depth === parentDepth + 1;
|
|
77
|
-
case "self-or-descendant":
|
|
78
|
-
return depth >= parentDepth;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
match(depth) {
|
|
82
|
-
this._enteredDepth = depth;
|
|
83
|
-
}
|
|
84
|
-
unmatch() {
|
|
85
|
-
this._enteredDepth = null;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
var EToCacheNodeProps = /* @__PURE__ */ ((EToCacheNodeProps2) => {
|
|
89
|
-
EToCacheNodeProps2[EToCacheNodeProps2["None"] = 0] = "None";
|
|
90
|
-
EToCacheNodeProps2[EToCacheNodeProps2["Name"] = 1] = "Name";
|
|
91
|
-
EToCacheNodeProps2[EToCacheNodeProps2["Attributes"] = 2] = "Attributes";
|
|
92
|
-
EToCacheNodeProps2[EToCacheNodeProps2["Text"] = 4] = "Text";
|
|
93
|
-
return EToCacheNodeProps2;
|
|
94
|
-
})(EToCacheNodeProps || {});
|
|
95
|
-
var ETokenMatchCriteria = /* @__PURE__ */ ((ETokenMatchCriteria2) => {
|
|
96
|
-
ETokenMatchCriteria2[ETokenMatchCriteria2["None"] = 0] = "None";
|
|
97
|
-
ETokenMatchCriteria2[ETokenMatchCriteria2["Name"] = 1] = "Name";
|
|
98
|
-
ETokenMatchCriteria2[ETokenMatchCriteria2["Attributes"] = 2] = "Attributes";
|
|
99
|
-
ETokenMatchCriteria2[ETokenMatchCriteria2["Text"] = 4] = "Text";
|
|
100
|
-
ETokenMatchCriteria2[ETokenMatchCriteria2["Node"] = 8] = "Node";
|
|
101
|
-
return ETokenMatchCriteria2;
|
|
102
|
-
})(ETokenMatchCriteria || {});
|
|
103
|
-
|
|
104
|
-
exports.EToCacheNodeProps = EToCacheNodeProps;
|
|
105
|
-
exports.ETokenMatchCriteria = ETokenMatchCriteria;
|
|
106
|
-
exports.TokenSelectState = TokenSelectState;
|
|
107
|
-
//# sourceMappingURL=TokenSelectState.js.map
|
|
1
|
+
"use strict";var s=require("./match-string.js"),m=Object.defineProperty,g=(e,t,r)=>t in e?m(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,a=(e,t,r)=>g(e,typeof t!="symbol"?t+"":t,r);class p{constructor(t){a(this,"_segment"),a(this,"_matchCriteria",0),a(this,"_toCacheNodeProps",0),a(this,"_enteredDepth",null),this._segment=t,this.applyLevels()}get matchCriteria(){return this._matchCriteria}get toCacheNodeProps(){return this._toCacheNodeProps}get enteredDepth(){return this._enteredDepth}applyLevels(){let t=0,r=0;(this._segment.local!=null||this._segment.prefix!=null)&&(t|=1),this._segment.attributes!=null&&(t|=2,r|=2),this._segment.text!=null&&(t|=4),this._matchCriteria=t,this._toCacheNodeProps=r}matchesName(t,r){return(this._segment.local==null||s.matchString(t,this._segment.local))&&(this._segment.prefix==null||s.matchString(r,this._segment.prefix))}matchesAttributes(t){if(this._segment.attributes==null)return!0;for(const r of this._segment.attributes){let n=!1;for(const i of t){const u=r.local==null||s.matchString(i.local,r.local),o=r.value==null||i.value!=null&&s.matchString(i.value,r.value),c=r.prefix==null||i.prefix!=null&&s.matchString(i.prefix,r.prefix);if(u&&o&&c){n=!0;break}}if(!n)return!1}return!0}matchesText(t){return this._segment.text==null||s.matchString(t,this._segment.text)}matchesDepth(t,r){switch(this._segment.axis){case"child":return t===r+1;case"self-or-descendant":return t>=r}}match(t){this._enteredDepth=t}unmatch(){this._enteredDepth=null}}var h=(e=>(e[e.None=0]="None",e[e.Name=1]="Name",e[e.Attributes=2]="Attributes",e[e.Text=4]="Text",e))(h||{}),l=(e=>(e[e.None=0]="None",e[e.Name=1]="Name",e[e.Attributes=2]="Attributes",e[e.Text=4]="Text",e[e.Node=8]="Node",e))(l||{});exports.EToCacheNodeProps=h,exports.ETokenMatchCriteria=l,exports.TokenSelectState=p;
|
|
@@ -1,151 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var TokenSelectState = require('./TokenSelectState.js');
|
|
4
|
-
|
|
5
|
-
var __defProp = Object.defineProperty;
|
|
6
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
7
|
-
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
8
|
-
class TokenSelectStateMachine {
|
|
9
|
-
constructor(tokenSelectPath) {
|
|
10
|
-
__publicField(this, "_states");
|
|
11
|
-
// null (start state) -> index (x state)
|
|
12
|
-
__publicField(this, "_currentState", null);
|
|
13
|
-
// Current state cache
|
|
14
|
-
__publicField(this, "_cachedNodeProps", {
|
|
15
|
-
prefix: null,
|
|
16
|
-
local: null,
|
|
17
|
-
attributes: null,
|
|
18
|
-
text: null
|
|
19
|
-
});
|
|
20
|
-
__publicField(this, "_cachedTokens", []);
|
|
21
|
-
__publicField(this, "_toRecordTokens", []);
|
|
22
|
-
this._states = tokenSelectPath.map((part) => new TokenSelectState.TokenSelectState(part));
|
|
23
|
-
}
|
|
24
|
-
getNextState() {
|
|
25
|
-
var _a;
|
|
26
|
-
const nextIndex = this._currentState != null ? this._currentState + 1 : 0;
|
|
27
|
-
if (nextIndex < this._states.length) {
|
|
28
|
-
return (_a = this._states[nextIndex]) != null ? _a : null;
|
|
29
|
-
}
|
|
30
|
-
return null;
|
|
31
|
-
}
|
|
32
|
-
getCurrentState() {
|
|
33
|
-
var _a;
|
|
34
|
-
if (this._currentState != null && this._currentState < this._states.length) {
|
|
35
|
-
return (_a = this._states[this._currentState]) != null ? _a : null;
|
|
36
|
-
}
|
|
37
|
-
return null;
|
|
38
|
-
}
|
|
39
|
-
record(token) {
|
|
40
|
-
if (this.getOffsetToFinal() <= 1) {
|
|
41
|
-
this._cachedTokens.push(token);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
takeRecordedTokens() {
|
|
45
|
-
if (this._toRecordTokens.length > 0) {
|
|
46
|
-
const recordedTokens = this._toRecordTokens;
|
|
47
|
-
this._toRecordTokens = [];
|
|
48
|
-
return recordedTokens;
|
|
49
|
-
}
|
|
50
|
-
return null;
|
|
51
|
-
}
|
|
52
|
-
transitionIfNameMatch(local, prefix, depth) {
|
|
53
|
-
var _a;
|
|
54
|
-
const nextState = this.getNextState();
|
|
55
|
-
const currentState = this.getCurrentState();
|
|
56
|
-
if (nextState == null) {
|
|
57
|
-
return false;
|
|
58
|
-
}
|
|
59
|
-
if (nextState.toCacheNodeProps & TokenSelectState.EToCacheNodeProps.Name) {
|
|
60
|
-
this._cachedNodeProps.local = local;
|
|
61
|
-
this._cachedNodeProps.prefix = prefix;
|
|
62
|
-
}
|
|
63
|
-
if (nextState.matchesName(local, prefix) && nextState.matchesDepth(depth, (_a = currentState == null ? void 0 : currentState.enteredDepth) != null ? _a : 0) && !(nextState.matchCriteria & (TokenSelectState.ETokenMatchCriteria.Attributes | TokenSelectState.ETokenMatchCriteria.Text | TokenSelectState.ETokenMatchCriteria.Node))) {
|
|
64
|
-
this.transitionForward(depth);
|
|
65
|
-
return true;
|
|
66
|
-
}
|
|
67
|
-
return false;
|
|
68
|
-
}
|
|
69
|
-
// Transition forward if attributes and depth match, and no additional criteria are required
|
|
70
|
-
transitionIfAttributesMatch(local, prefix, value, depth) {
|
|
71
|
-
var _a, _b;
|
|
72
|
-
const nextState = this.getNextState();
|
|
73
|
-
const currentState = this.getCurrentState();
|
|
74
|
-
if (nextState == null) {
|
|
75
|
-
return false;
|
|
76
|
-
}
|
|
77
|
-
const attributes = (_a = this._cachedNodeProps.attributes) != null ? _a : [];
|
|
78
|
-
attributes.push({ local, prefix, value });
|
|
79
|
-
if (nextState.toCacheNodeProps & TokenSelectState.EToCacheNodeProps.Attributes) {
|
|
80
|
-
this._cachedNodeProps.attributes = attributes;
|
|
81
|
-
}
|
|
82
|
-
if (nextState.matchesAttributes(attributes) && nextState.matchesDepth(depth, (_b = currentState == null ? void 0 : currentState.enteredDepth) != null ? _b : 0) && !(nextState.matchCriteria & (TokenSelectState.ETokenMatchCriteria.Text | TokenSelectState.ETokenMatchCriteria.Node))) {
|
|
83
|
-
this.transitionForward(depth);
|
|
84
|
-
return true;
|
|
85
|
-
}
|
|
86
|
-
return false;
|
|
87
|
-
}
|
|
88
|
-
// Transition forward if text content and depth match, and no additional criteria are required
|
|
89
|
-
transitionIfTextMatch(text, depth) {
|
|
90
|
-
var _a;
|
|
91
|
-
const nextState = this.getNextState();
|
|
92
|
-
const currentState = this.getCurrentState();
|
|
93
|
-
if (nextState == null) {
|
|
94
|
-
return false;
|
|
95
|
-
}
|
|
96
|
-
if (nextState.toCacheNodeProps & TokenSelectState.EToCacheNodeProps.Text) {
|
|
97
|
-
this._cachedNodeProps.text = text;
|
|
98
|
-
}
|
|
99
|
-
if (nextState.matchesText(text) && nextState.matchesDepth(depth, (_a = currentState == null ? void 0 : currentState.enteredDepth) != null ? _a : 0) && !(nextState.matchCriteria & TokenSelectState.ETokenMatchCriteria.Node)) {
|
|
100
|
-
this.transitionForward(depth);
|
|
101
|
-
return true;
|
|
102
|
-
}
|
|
103
|
-
return false;
|
|
104
|
-
}
|
|
105
|
-
transitionForward(depth) {
|
|
106
|
-
const previousState = this.getCurrentState();
|
|
107
|
-
if (previousState != null) {
|
|
108
|
-
previousState.unmatch();
|
|
109
|
-
}
|
|
110
|
-
this._currentState = this._currentState != null ? this._currentState + 1 : 0;
|
|
111
|
-
const currentState = this.getCurrentState();
|
|
112
|
-
if (currentState != null) {
|
|
113
|
-
currentState.match(depth);
|
|
114
|
-
}
|
|
115
|
-
if (this.isFinalState()) {
|
|
116
|
-
this._toRecordTokens = this._cachedTokens;
|
|
117
|
-
}
|
|
118
|
-
this.resetCurrentStateCache();
|
|
119
|
-
}
|
|
120
|
-
transitionBack(depth) {
|
|
121
|
-
const previousState = this.getCurrentState();
|
|
122
|
-
if (previousState != null) {
|
|
123
|
-
previousState.unmatch();
|
|
124
|
-
}
|
|
125
|
-
this._currentState = this._currentState != null ? this._currentState - 1 : 0;
|
|
126
|
-
const currentState = this.getCurrentState();
|
|
127
|
-
if (currentState != null) {
|
|
128
|
-
currentState.match(depth);
|
|
129
|
-
}
|
|
130
|
-
this.resetCurrentStateCache();
|
|
131
|
-
}
|
|
132
|
-
isFinalState() {
|
|
133
|
-
return this._currentState != null && this._currentState >= this._states.length - 1;
|
|
134
|
-
}
|
|
135
|
-
getOffsetToFinal() {
|
|
136
|
-
if (this._currentState == null) {
|
|
137
|
-
return this._states.length;
|
|
138
|
-
}
|
|
139
|
-
return this._states.length - 1 - this._currentState;
|
|
140
|
-
}
|
|
141
|
-
resetCurrentStateCache() {
|
|
142
|
-
this._cachedNodeProps.prefix = null;
|
|
143
|
-
this._cachedNodeProps.local = null;
|
|
144
|
-
this._cachedNodeProps.attributes = null;
|
|
145
|
-
this._cachedNodeProps.text = null;
|
|
146
|
-
this._cachedTokens = [];
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
exports.TokenSelectStateMachine = TokenSelectStateMachine;
|
|
151
|
-
//# sourceMappingURL=TokenSelectStateMachine.js.map
|
|
1
|
+
"use strict";var n=require("./TokenSelectState.js"),d=Object.defineProperty,_=(i,t,e)=>t in i?d(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e,c=(i,t,e)=>_(i,typeof t!="symbol"?t+"":t,e);class S{constructor(t){c(this,"_states"),c(this,"_currentState",null),c(this,"_cachedNodeProps",{prefix:null,local:null,attributes:null,text:null}),c(this,"_cachedTokens",[]),c(this,"_toRecordTokens",[]),this._states=t.map(e=>new n.TokenSelectState(e))}getNextState(){var t;const e=this._currentState!=null?this._currentState+1:0;return e<this._states.length&&(t=this._states[e])!=null?t:null}getCurrentState(){var t;return this._currentState!=null&&this._currentState<this._states.length&&(t=this._states[this._currentState])!=null?t:null}record(t){this.getOffsetToFinal()<=1&&this._cachedTokens.push(t)}takeRecordedTokens(){if(this._toRecordTokens.length>0){const t=this._toRecordTokens;return this._toRecordTokens=[],t}return null}transitionIfNameMatch(t,e,r){var s;const a=this.getNextState(),h=this.getCurrentState();return a==null?!1:(a.toCacheNodeProps&n.EToCacheNodeProps.Name&&(this._cachedNodeProps.local=t,this._cachedNodeProps.prefix=e),a.matchesName(t,e)&&a.matchesDepth(r,(s=h==null?void 0:h.enteredDepth)!=null?s:0)&&!(a.matchCriteria&(n.ETokenMatchCriteria.Attributes|n.ETokenMatchCriteria.Text|n.ETokenMatchCriteria.Node))?(this.transitionForward(r),!0):!1)}transitionIfAttributesMatch(t,e,r,s){var a,h;const o=this.getNextState(),u=this.getCurrentState();if(o==null)return!1;const l=(a=this._cachedNodeProps.attributes)!=null?a:[];return l.push({local:t,prefix:e,value:r}),o.toCacheNodeProps&n.EToCacheNodeProps.Attributes&&(this._cachedNodeProps.attributes=l),o.matchesAttributes(l)&&o.matchesDepth(s,(h=u==null?void 0:u.enteredDepth)!=null?h:0)&&!(o.matchCriteria&(n.ETokenMatchCriteria.Text|n.ETokenMatchCriteria.Node))?(this.transitionForward(s),!0):!1}transitionIfTextMatch(t,e){var r;const s=this.getNextState(),a=this.getCurrentState();return s==null?!1:(s.toCacheNodeProps&n.EToCacheNodeProps.Text&&(this._cachedNodeProps.text=t),s.matchesText(t)&&s.matchesDepth(e,(r=a==null?void 0:a.enteredDepth)!=null?r:0)&&!(s.matchCriteria&n.ETokenMatchCriteria.Node)?(this.transitionForward(e),!0):!1)}transitionForward(t){const e=this.getCurrentState();e!=null&&e.unmatch(),this._currentState=this._currentState!=null?this._currentState+1:0;const r=this.getCurrentState();r!=null&&r.match(t),this.isFinalState()&&(this._toRecordTokens=this._cachedTokens),this.resetCurrentStateCache()}transitionBack(t){const e=this.getCurrentState();e!=null&&e.unmatch(),this._currentState=this._currentState!=null?this._currentState-1:0;const r=this.getCurrentState();r!=null&&r.match(t),this.resetCurrentStateCache()}isFinalState(){return this._currentState!=null&&this._currentState>=this._states.length-1}getOffsetToFinal(){return this._currentState==null?this._states.length:this._states.length-1-this._currentState}resetCurrentStateCache(){this._cachedNodeProps.prefix=null,this._cachedNodeProps.local=null,this._cachedNodeProps.attributes=null,this._cachedNodeProps.text=null,this._cachedTokens=[]}}exports.TokenSelectStateMachine=S;
|
|
@@ -1,140 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var TokenSelectState = require('./TokenSelectState.js');
|
|
4
|
-
var TokenSelectStateMachine = require('./TokenSelectStateMachine.js');
|
|
5
|
-
|
|
6
|
-
var __defProp = Object.defineProperty;
|
|
7
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
-
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
9
|
-
class TokenSelector {
|
|
10
|
-
constructor(tokenSelectPaths) {
|
|
11
|
-
__publicField(this, "_currentDepth", 0);
|
|
12
|
-
__publicField(this, "_tspStateMachines");
|
|
13
|
-
__publicField(this, "_isRecording", false);
|
|
14
|
-
this._tspStateMachines = tokenSelectPaths.map(
|
|
15
|
-
(tokenSelectPath) => new TokenSelectStateMachine.TokenSelectStateMachine(tokenSelectPath)
|
|
16
|
-
);
|
|
17
|
-
}
|
|
18
|
-
pipeToken(token, recorder) {
|
|
19
|
-
let startRecording = false;
|
|
20
|
-
let stopRecording = false;
|
|
21
|
-
switch (token.type) {
|
|
22
|
-
case "ElementStart":
|
|
23
|
-
startRecording = this.handleElementStart(token);
|
|
24
|
-
break;
|
|
25
|
-
case "Attribute":
|
|
26
|
-
startRecording = this.handleAttribute(token);
|
|
27
|
-
break;
|
|
28
|
-
case "Text":
|
|
29
|
-
startRecording = this.handleText(token);
|
|
30
|
-
break;
|
|
31
|
-
case "ElementEnd": {
|
|
32
|
-
stopRecording = this.handleElementEnd(token);
|
|
33
|
-
break;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
if (startRecording && !this._isRecording) {
|
|
37
|
-
this._isRecording = true;
|
|
38
|
-
recorder({ type: "SelectionStart" });
|
|
39
|
-
}
|
|
40
|
-
for (const stateMachine of this._tspStateMachines) {
|
|
41
|
-
stateMachine.record(token);
|
|
42
|
-
const recordedTokens = stateMachine.takeRecordedTokens();
|
|
43
|
-
if (recordedTokens != null) {
|
|
44
|
-
recordedTokens.forEach((t) => {
|
|
45
|
-
recorder(t);
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
if (this._isRecording) {
|
|
50
|
-
recorder(token);
|
|
51
|
-
}
|
|
52
|
-
if (stopRecording && this._isRecording) {
|
|
53
|
-
recorder({ type: "SelectionEnd" });
|
|
54
|
-
this._isRecording = false;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
handleElementStart(token) {
|
|
58
|
-
this._currentDepth += 1;
|
|
59
|
-
let startRecording = false;
|
|
60
|
-
for (const stateMachine of this._tspStateMachines) {
|
|
61
|
-
stateMachine.resetCurrentStateCache();
|
|
62
|
-
if (stateMachine.isFinalState()) {
|
|
63
|
-
continue;
|
|
64
|
-
}
|
|
65
|
-
const nextState = stateMachine.getNextState();
|
|
66
|
-
if (nextState == null || !(nextState.matchCriteria & TokenSelectState.ETokenMatchCriteria.Name)) {
|
|
67
|
-
continue;
|
|
68
|
-
}
|
|
69
|
-
const transitioned = stateMachine.transitionIfNameMatch(
|
|
70
|
-
token.local,
|
|
71
|
-
token.prefix,
|
|
72
|
-
this._currentDepth
|
|
73
|
-
);
|
|
74
|
-
if (transitioned && stateMachine.isFinalState()) {
|
|
75
|
-
startRecording = true;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
return startRecording;
|
|
79
|
-
}
|
|
80
|
-
handleAttribute(token) {
|
|
81
|
-
let startRecording = false;
|
|
82
|
-
for (const stateMachine of this._tspStateMachines) {
|
|
83
|
-
if (stateMachine.isFinalState()) {
|
|
84
|
-
continue;
|
|
85
|
-
}
|
|
86
|
-
const nextState = stateMachine.getNextState();
|
|
87
|
-
if (nextState == null || !(nextState.matchCriteria & TokenSelectState.ETokenMatchCriteria.Attributes)) {
|
|
88
|
-
continue;
|
|
89
|
-
}
|
|
90
|
-
const transitioned = stateMachine.transitionIfAttributesMatch(
|
|
91
|
-
token.local,
|
|
92
|
-
token.prefix,
|
|
93
|
-
token.value,
|
|
94
|
-
this._currentDepth
|
|
95
|
-
);
|
|
96
|
-
if (transitioned && stateMachine.isFinalState()) {
|
|
97
|
-
startRecording = true;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
return startRecording;
|
|
101
|
-
}
|
|
102
|
-
handleText(token) {
|
|
103
|
-
let startRecording = false;
|
|
104
|
-
for (const stateMachine of this._tspStateMachines) {
|
|
105
|
-
if (stateMachine.isFinalState()) {
|
|
106
|
-
continue;
|
|
107
|
-
}
|
|
108
|
-
const nextState = stateMachine.getNextState();
|
|
109
|
-
if (nextState == null || !(nextState.matchCriteria & TokenSelectState.ETokenMatchCriteria.Text)) {
|
|
110
|
-
continue;
|
|
111
|
-
}
|
|
112
|
-
const transitioned = stateMachine.transitionIfTextMatch(token.text, this._currentDepth);
|
|
113
|
-
if (transitioned && stateMachine.isFinalState()) {
|
|
114
|
-
startRecording = true;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
return startRecording;
|
|
118
|
-
}
|
|
119
|
-
handleElementEnd(token) {
|
|
120
|
-
if (token.end.type === "Close" || token.end.type === "Empty") {
|
|
121
|
-
this._currentDepth -= 1;
|
|
122
|
-
let isFinalState = false;
|
|
123
|
-
for (const stateMachine of this._tspStateMachines) {
|
|
124
|
-
const currentState = stateMachine.getCurrentState();
|
|
125
|
-
if (currentState == null) {
|
|
126
|
-
continue;
|
|
127
|
-
}
|
|
128
|
-
if (currentState.enteredDepth != null && this._currentDepth < currentState.enteredDepth) {
|
|
129
|
-
stateMachine.transitionBack(this._currentDepth);
|
|
130
|
-
}
|
|
131
|
-
isFinalState = isFinalState || stateMachine.isFinalState();
|
|
132
|
-
}
|
|
133
|
-
return !isFinalState;
|
|
134
|
-
}
|
|
135
|
-
return false;
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
exports.TokenSelector = TokenSelector;
|
|
140
|
-
//# sourceMappingURL=TokenSelector.js.map
|
|
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,22 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
function matchString(value, config) {
|
|
4
|
-
if (typeof config === "string") {
|
|
5
|
-
return value === config;
|
|
6
|
-
}
|
|
7
|
-
switch (config.matchStrategy) {
|
|
8
|
-
case "ANY":
|
|
9
|
-
return true;
|
|
10
|
-
case "EXACT":
|
|
11
|
-
return value === config.value;
|
|
12
|
-
case "CONTAINS":
|
|
13
|
-
return value.includes(config.value);
|
|
14
|
-
case "STARTS_WITH":
|
|
15
|
-
return value.startsWith(config.value);
|
|
16
|
-
case "ENDS_WITH":
|
|
17
|
-
return value.endsWith(config.value);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
exports.matchString = matchString;
|
|
22
|
-
//# sourceMappingURL=match-string.js.map
|
|
1
|
+
"use strict";function r(t,e){if(typeof e=="string")return t===e;switch(e.matchStrategy){case"ANY":return!0;case"EXACT":return t===e.value;case"CONTAINS":return t.includes(e.value);case"STARTS_WITH":return t.startsWith(e.value);case"ENDS_WITH":return t.endsWith(e.value)}}exports.matchString=r;
|
|
@@ -1,20 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var tokenize = require('../tokenizer/tokenize.js');
|
|
4
|
-
var TokenSelector = require('./TokenSelector.js');
|
|
5
|
-
|
|
6
|
-
function select(xml, tokenSelectPaths, callback, options) {
|
|
7
|
-
const selector = new TokenSelector.TokenSelector(tokenSelectPaths);
|
|
8
|
-
tokenize.tokenize(
|
|
9
|
-
xml,
|
|
10
|
-
(token, stream) => {
|
|
11
|
-
selector.pipeToken(token, (recordedToken) => {
|
|
12
|
-
callback(recordedToken, stream);
|
|
13
|
-
});
|
|
14
|
-
},
|
|
15
|
-
options
|
|
16
|
-
);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
exports.select = select;
|
|
20
|
-
//# sourceMappingURL=select.js.map
|
|
1
|
+
"use strict";var l=require("../tokenizer/tokenize.js"),s=require("./TokenSelector.js");function u(e,t,n,o){const r=new s.TokenSelector(t);l.tokenize(e,(c,i)=>{r.pipeToken(c,k=>{n(k,i)})},o)}exports.select=u;
|
package/dist/cjs/token-to-xml.js
CHANGED
|
@@ -1,45 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
function tokenToXml(token) {
|
|
4
|
-
let xmlString = "";
|
|
5
|
-
switch (token.type) {
|
|
6
|
-
case "ProcessingInstruction":
|
|
7
|
-
xmlString += `<?${token.target}`;
|
|
8
|
-
if (token.content) {
|
|
9
|
-
xmlString += ` ${token.content}`;
|
|
10
|
-
}
|
|
11
|
-
xmlString += "?>";
|
|
12
|
-
break;
|
|
13
|
-
case "Comment":
|
|
14
|
-
xmlString += `<!--${token.text}-->`;
|
|
15
|
-
break;
|
|
16
|
-
case "EntityDeclaration":
|
|
17
|
-
xmlString += `<!ENTITY ${token.name} "${token.definition}">`;
|
|
18
|
-
break;
|
|
19
|
-
case "ElementStart":
|
|
20
|
-
xmlString += `<${token.prefix.length > 0 ? `${token.prefix}:` : ""}${token.local}`;
|
|
21
|
-
break;
|
|
22
|
-
case "Attribute":
|
|
23
|
-
xmlString += ` ${token.prefix.length > 0 ? `${token.prefix}:` : ""}${token.local}="${token.value}"`;
|
|
24
|
-
break;
|
|
25
|
-
case "ElementEnd":
|
|
26
|
-
if (token.end.type === "Open") {
|
|
27
|
-
xmlString += ">";
|
|
28
|
-
} else if (token.end.type === "Close") {
|
|
29
|
-
xmlString += `</${token.end.prefix.length > 0 ? `${token.end.prefix}:` : ""}${token.end.local}>`;
|
|
30
|
-
} else {
|
|
31
|
-
xmlString += "/>";
|
|
32
|
-
}
|
|
33
|
-
break;
|
|
34
|
-
case "Text":
|
|
35
|
-
xmlString += token.text;
|
|
36
|
-
break;
|
|
37
|
-
case "Cdata":
|
|
38
|
-
xmlString += `<![CDATA[${token.text}]]>`;
|
|
39
|
-
break;
|
|
40
|
-
}
|
|
41
|
-
return xmlString;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
exports.tokenToXml = tokenToXml;
|
|
45
|
-
//# sourceMappingURL=token-to-xml.js.map
|
|
1
|
+
"use strict";function n(t){let e="";switch(t.type){case"ProcessingInstruction":e+=`<?${t.target}`,t.content&&(e+=` ${t.content}`),e+="?>";break;case"Comment":e+=`<!--${t.text}-->`;break;case"EntityDeclaration":e+=`<!ENTITY ${t.name} "${t.definition}">`;break;case"ElementStart":e+=`<${t.prefix.length>0?`${t.prefix}:`:""}${t.local}`;break;case"Attribute":e+=` ${t.prefix.length>0?`${t.prefix}:`:""}${t.local}="${t.value}"`;break;case"ElementEnd":t.end.type==="Open"?e+=">":t.end.type==="Close"?e+=`</${t.end.prefix.length>0?`${t.end.prefix}:`:""}${t.end.local}>`:e+="/>";break;case"Text":e+=t.text;break;case"Cdata":e+=`<![CDATA[${t.text}]]>`;break}return e}exports.tokenToXml=n;
|