occam-dom 3.1.129 → 4.0.2
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/README.md +1 -53
- package/package.json +9 -11
- package/bin/main.js +0 -15
- package/example.js +0 -35588
- package/index.html +0 -47
- package/lib/constants.js +0 -13
- package/lib/example/utilities/token.js +0 -28
- package/lib/example/view/div/sizeable.js +0 -39
- package/lib/example/view/input/expression.js +0 -156
- package/lib/example/view/input/maximumDepth.js +0 -156
- package/lib/example/view/input.js +0 -39
- package/lib/example/view/subHeading.js +0 -39
- package/lib/example/view/textarea/content.js +0 -155
- package/lib/example/view/textarea/nodes.js +0 -176
- package/lib/example/view/textarea/parseTree.js +0 -183
- package/lib/example/view/textarea.js +0 -39
- package/lib/example/view.js +0 -250
- package/lib/example.js +0 -19
- package/lib/index.js +0 -27
- package/lib/query.js +0 -168
- package/lib/spread.js +0 -86
- package/lib/utilities/array.js +0 -61
- package/lib/utilities/query.js +0 -79
- package/src/constants.js +0 -3
- package/src/example/utilities/token.js +0 -21
- package/src/example/view/div/sizeable.js +0 -12
- package/src/example/view/input/expression.js +0 -35
- package/src/example/view/input/maximumDepth.js +0 -35
- package/src/example/view/input.js +0 -14
- package/src/example/view/subHeading.js +0 -16
- package/src/example/view/textarea/content.js +0 -33
- package/src/example/view/textarea/nodes.js +0 -64
- package/src/example/view/textarea/parseTree.js +0 -50
- package/src/example/view/textarea.js +0 -18
- package/src/example/view.js +0 -120
- package/src/example.js +0 -21
- package/src/index.js +0 -4
- package/src/query.js +0 -170
- package/src/spread.js +0 -65
- package/src/utilities/array.js +0 -30
- package/src/utilities/query.js +0 -52
package/src/query.js
DELETED
|
@@ -1,170 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
import { characters } from "necessary";
|
|
4
|
-
|
|
5
|
-
import Spread from "./spread";
|
|
6
|
-
|
|
7
|
-
import { includes, push, clear, second, third, fourth, fifth } from "./utilities/array";
|
|
8
|
-
|
|
9
|
-
const { BAR_CHARACTER, WILDCARD_CHARACTER, FORWARD_SLASH_CHARACTER } = characters;
|
|
10
|
-
|
|
11
|
-
export default class Query {
|
|
12
|
-
constructor(types, spread, subQuery, ruleNames, maximumDepth, infiniteDescent, intermediateNodes) {
|
|
13
|
-
this.types = types;
|
|
14
|
-
this.spread = spread;
|
|
15
|
-
this.subQuery = subQuery;
|
|
16
|
-
this.ruleNames = ruleNames;
|
|
17
|
-
this.maximumDepth = maximumDepth;
|
|
18
|
-
this.infiniteDescent = infiniteDescent;
|
|
19
|
-
this.intermediateNodes = intermediateNodes;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
execute(node, depth = 0, maximumDepth = this.maximumDepth) {
|
|
23
|
-
const nodes = [];
|
|
24
|
-
|
|
25
|
-
this.clear();
|
|
26
|
-
|
|
27
|
-
this.find(node, depth, maximumDepth);
|
|
28
|
-
|
|
29
|
-
this.apply(nodes, depth, maximumDepth);
|
|
30
|
-
|
|
31
|
-
return nodes;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
clear() {
|
|
35
|
-
clear(this.intermediateNodes);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
find(node, depth, maximumDepth) {
|
|
39
|
-
if (depth > maximumDepth) {
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
const nodeTerminalNode = node.isTerminalNode(),
|
|
44
|
-
nodeNonTerminalNode = !nodeTerminalNode;
|
|
45
|
-
|
|
46
|
-
let found;
|
|
47
|
-
|
|
48
|
-
if (nodeTerminalNode) {
|
|
49
|
-
const terminalNode = node, ///
|
|
50
|
-
type = terminalNode.getType();
|
|
51
|
-
|
|
52
|
-
found = includes(this.types, type, WILDCARD_CHARACTER);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
if (nodeNonTerminalNode) {
|
|
56
|
-
const nonTerminalNode = node, ///
|
|
57
|
-
ruleName = nonTerminalNode.getRuleName();
|
|
58
|
-
|
|
59
|
-
found = includes(this.ruleNames, ruleName, WILDCARD_CHARACTER);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
if (found) {
|
|
63
|
-
const intermediateNode = node; ///
|
|
64
|
-
|
|
65
|
-
this.intermediateNodes.push(intermediateNode);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
if (this.infiniteDescent) {
|
|
69
|
-
if (nodeNonTerminalNode) {
|
|
70
|
-
depth++;
|
|
71
|
-
|
|
72
|
-
const nonTerminalNode = node, ///
|
|
73
|
-
childNodes = nonTerminalNode.getChildNodes();
|
|
74
|
-
|
|
75
|
-
childNodes.forEach((childNode) => {
|
|
76
|
-
this.find(childNode, depth, maximumDepth);
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
apply(nodes, depth, maximumDepth) {
|
|
83
|
-
this.spread.adjustNodes(this.intermediateNodes);
|
|
84
|
-
|
|
85
|
-
if (this.subQuery === null) {
|
|
86
|
-
push(nodes, this.intermediateNodes);
|
|
87
|
-
} else {
|
|
88
|
-
this.intermediateNodes.forEach((intermediateNode) => {
|
|
89
|
-
const intermediateNodeNonTerminalNode = intermediateNode.isNonTerminalNode();
|
|
90
|
-
|
|
91
|
-
if (intermediateNodeNonTerminalNode) {
|
|
92
|
-
depth++;
|
|
93
|
-
|
|
94
|
-
const nonTerminalNode = intermediateNode, ///
|
|
95
|
-
childNodes = nonTerminalNode.getChildNodes();
|
|
96
|
-
|
|
97
|
-
this.subQuery.clear();
|
|
98
|
-
|
|
99
|
-
childNodes.forEach((childNode) => {
|
|
100
|
-
this.subQuery.find(childNode, depth, maximumDepth);
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
this.subQuery.apply(nodes, depth, maximumDepth);
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
static fromExpression(expression, maximumDepth = Infinity) {
|
|
110
|
-
let query = null;
|
|
111
|
-
|
|
112
|
-
if (expression !== null) {
|
|
113
|
-
const regExp = /^\/(\/)?([^/\[!]+)(\[[^\]]+]|!)?(\/.*)?$/,
|
|
114
|
-
matches = expression.match(regExp),
|
|
115
|
-
secondMatch = second(matches),
|
|
116
|
-
thirdMatch = third(matches),
|
|
117
|
-
fourthMatch = fourth(matches),
|
|
118
|
-
fifthMatch = fifth(matches),
|
|
119
|
-
selectors = thirdMatch.split(BAR_CHARACTER),
|
|
120
|
-
subExpression = fifthMatch || null,
|
|
121
|
-
spreadExpression = fourthMatch || null,
|
|
122
|
-
types = typesFromSelectors(selectors),
|
|
123
|
-
spread = Spread.fromSpreadExpression(spreadExpression),
|
|
124
|
-
subQuery = Query.fromExpression(subExpression),
|
|
125
|
-
ruleNames = ruleNamesFromSelectors(selectors),
|
|
126
|
-
infiniteDescent = (secondMatch === FORWARD_SLASH_CHARACTER),
|
|
127
|
-
intermediateNodes = [];
|
|
128
|
-
|
|
129
|
-
query = new Query(types, spread, subQuery, ruleNames, maximumDepth, infiniteDescent, intermediateNodes);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
return query;
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
function typesFromSelectors(selectors) {
|
|
137
|
-
const types = [];
|
|
138
|
-
|
|
139
|
-
selectors.forEach((selector) => {
|
|
140
|
-
const selectorTypeSelector = isSelectorTypeSelector(selector);
|
|
141
|
-
|
|
142
|
-
if (selectorTypeSelector) {
|
|
143
|
-
const type = selector.substring(1);
|
|
144
|
-
|
|
145
|
-
types.push(type);
|
|
146
|
-
}
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
return types;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
function ruleNamesFromSelectors(selectors) {
|
|
153
|
-
const ruleNames = [];
|
|
154
|
-
|
|
155
|
-
selectors.forEach((selector) => {
|
|
156
|
-
const selectorRuleNameSelector = isSelectorRuleNameSelector(selector);
|
|
157
|
-
|
|
158
|
-
if (selectorRuleNameSelector) {
|
|
159
|
-
const ruleName = selector; ///
|
|
160
|
-
|
|
161
|
-
ruleNames.push(ruleName);
|
|
162
|
-
}
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
return ruleNames;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
function isSelectorTypeSelector(selector) { return /^@/.test(selector); }
|
|
169
|
-
|
|
170
|
-
function isSelectorRuleNameSelector(selector) { return /^[^@]/.test(selector); }
|
package/src/spread.js
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
import { characters } from "necessary";
|
|
4
|
-
|
|
5
|
-
import { clear, trim, second, third, fourth } from "./utilities/array";
|
|
6
|
-
|
|
7
|
-
const { EXCLAMATION_MARK_CHARACTER } = characters;
|
|
8
|
-
|
|
9
|
-
export default class Spread {
|
|
10
|
-
constructor(startIndex, endIndex, unique) {
|
|
11
|
-
this.startIndex = startIndex;
|
|
12
|
-
this.endIndex = endIndex;
|
|
13
|
-
this.unique = unique;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
adjustNodes(nodes) {
|
|
17
|
-
if (this.unique) {
|
|
18
|
-
const nodesLength = nodes.length;
|
|
19
|
-
|
|
20
|
-
if (nodesLength > 1) {
|
|
21
|
-
clear(nodes);
|
|
22
|
-
}
|
|
23
|
-
} else {
|
|
24
|
-
trim(nodes, this.startIndex, this.endIndex);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
static fromSpreadExpression(spreadExpression) {
|
|
29
|
-
let startIndex = 0,
|
|
30
|
-
endIndex = Infinity,
|
|
31
|
-
unique = false;
|
|
32
|
-
|
|
33
|
-
if (spreadExpression !== null) {
|
|
34
|
-
if (spreadExpression === EXCLAMATION_MARK_CHARACTER) {
|
|
35
|
-
unique = true;
|
|
36
|
-
} else {
|
|
37
|
-
const regExp = /\[(-?\d+)?(\.\.\.)?(-?\d+)?]/,
|
|
38
|
-
matches = spreadExpression.match(regExp),
|
|
39
|
-
secondMatch = second(matches) || null,
|
|
40
|
-
thirdMatch = third(matches) || null,
|
|
41
|
-
fourthMatch = fourth(matches) || null;
|
|
42
|
-
|
|
43
|
-
if (secondMatch !== null) {
|
|
44
|
-
startIndex = parseInt(secondMatch);
|
|
45
|
-
|
|
46
|
-
if (thirdMatch === null) {
|
|
47
|
-
endIndex = startIndex; ///
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
if (fourthMatch !== null) {
|
|
52
|
-
endIndex = parseInt(fourthMatch);
|
|
53
|
-
|
|
54
|
-
if (thirdMatch === null) {
|
|
55
|
-
startIndex = endIndex; ///
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
const spread = new Spread(startIndex, endIndex, unique);
|
|
62
|
-
|
|
63
|
-
return spread;
|
|
64
|
-
}
|
|
65
|
-
}
|
package/src/utilities/array.js
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
import { arrayUtilities } from "necessary";
|
|
4
|
-
|
|
5
|
-
export const { clear, push, second, third, fourth, fifth } = arrayUtilities;
|
|
6
|
-
|
|
7
|
-
export function trim(array, startIndex, endIndex) {
|
|
8
|
-
if (startIndex < 0) {
|
|
9
|
-
const length = array.length; ///
|
|
10
|
-
|
|
11
|
-
startIndex = length + startIndex; ///
|
|
12
|
-
|
|
13
|
-
endIndex = length + endIndex; ///
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
if (endIndex !== Infinity) {
|
|
17
|
-
const start = endIndex + 1;
|
|
18
|
-
|
|
19
|
-
array.splice(start);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const start = 0,
|
|
23
|
-
deleteCount = startIndex; ///
|
|
24
|
-
|
|
25
|
-
array.splice(start, deleteCount);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export function includes(array, ...elements) {
|
|
29
|
-
return elements.some((element) => array.includes(element));
|
|
30
|
-
}
|
package/src/utilities/query.js
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
import Query from "../query";
|
|
4
|
-
|
|
5
|
-
export function queryByClass(node, Class, nodes = []) {
|
|
6
|
-
if (node instanceof Class) {
|
|
7
|
-
nodes.push(node);
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
const nodeNonTerminalNode = node.isNonTerminalNode();
|
|
11
|
-
|
|
12
|
-
if (nodeNonTerminalNode) {
|
|
13
|
-
const childNodes = node.getChildNodes();
|
|
14
|
-
|
|
15
|
-
childNodes.forEach((childNode) => queryByClass(childNode, Class, nodes));
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
return nodes;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export function queryByClasses(node, Classes, nodes = []) {
|
|
22
|
-
Classes.some((Class) => {
|
|
23
|
-
if (node instanceof Class) {
|
|
24
|
-
nodes.push(node);
|
|
25
|
-
|
|
26
|
-
return true;
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
const nodeNonTerminalNode = node.isNonTerminalNode();
|
|
31
|
-
|
|
32
|
-
if (nodeNonTerminalNode) {
|
|
33
|
-
const childNodes = node.getChildNodes();
|
|
34
|
-
|
|
35
|
-
childNodes.forEach((childNode) => queryByClasses(childNode, Classes, nodes));
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
return nodes;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export function queryByExpression(node, expression, maximumDepth) {
|
|
42
|
-
const query = Query.fromExpression(expression, maximumDepth),
|
|
43
|
-
nodes = query.execute(node);
|
|
44
|
-
|
|
45
|
-
return nodes;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export default {
|
|
49
|
-
queryByClass,
|
|
50
|
-
queryByClasses,
|
|
51
|
-
queryByExpression
|
|
52
|
-
};
|