occam-dom 5.0.0 → 5.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.
Files changed (64) hide show
  1. package/example.js +1495 -1305
  2. package/lib/example/constants.js +22 -0
  3. package/lib/example/utilities/query.js +23 -0
  4. package/lib/example/view/div/sizeable.js +2 -2
  5. package/lib/example/view/textarea/expressions.js +143 -0
  6. package/lib/example/view/textarea/outerNodes.js +147 -0
  7. package/lib/example/view/{input/expressionString.js → textarea/parseTree/inner.js} +43 -28
  8. package/lib/{expression/parser.js → example/view/textarea/parseTree/outer.js} +20 -28
  9. package/lib/example/view/textarea/parseTree.js +1 -19
  10. package/lib/example/view.js +26 -20
  11. package/lib/index.js +7 -19
  12. package/lib/node.js +302 -0
  13. package/lib/parseTree/childNodes.js +164 -0
  14. package/lib/parseTree/horizontalBranch.js +120 -0
  15. package/lib/parseTree/node.js +145 -0
  16. package/lib/parseTree/string.js +109 -0
  17. package/lib/parseTree/verticalBranch.js +184 -0
  18. package/lib/parseTree.js +191 -0
  19. package/lib/utilities/node.js +56 -309
  20. package/package.json +3 -2
  21. package/src/example/constants.js +4 -0
  22. package/src/example/utilities/query.js +21 -0
  23. package/src/example/view/div/sizeable.js +1 -1
  24. package/src/example/view/textarea/expressions.js +39 -0
  25. package/src/example/view/textarea/outerNodes.js +48 -0
  26. package/src/example/view/textarea/parseTree/inner.js +24 -0
  27. package/src/example/view/textarea/parseTree/outer.js +17 -0
  28. package/src/example/view/textarea/parseTree.js +0 -18
  29. package/src/example/view.js +44 -32
  30. package/src/index.js +2 -5
  31. package/src/node.js +221 -0
  32. package/src/parseTree/childNodes.js +108 -0
  33. package/src/parseTree/horizontalBranch.js +32 -0
  34. package/src/parseTree/node.js +77 -0
  35. package/src/parseTree/string.js +18 -0
  36. package/src/parseTree/verticalBranch.js +77 -0
  37. package/src/parseTree.js +141 -0
  38. package/src/utilities/node.js +66 -416
  39. package/lib/example/view/textarea/nodes.js +0 -155
  40. package/lib/expression/bnf.js +0 -14
  41. package/lib/expression/entries.js +0 -27
  42. package/lib/expression/lexer.js +0 -145
  43. package/lib/expression.js +0 -113
  44. package/lib/path.js +0 -69
  45. package/lib/query.js +0 -216
  46. package/lib/ruleNames.js +0 -54
  47. package/lib/spread.js +0 -113
  48. package/lib/subExpression.js +0 -101
  49. package/lib/utilities/array.js +0 -67
  50. package/lib/utilities/query.js +0 -39
  51. package/src/example/view/input/expressionString.js +0 -33
  52. package/src/example/view/textarea/nodes.js +0 -55
  53. package/src/expression/bnf.js +0 -63
  54. package/src/expression/entries.js +0 -18
  55. package/src/expression/lexer.js +0 -35
  56. package/src/expression/parser.js +0 -15
  57. package/src/expression.js +0 -82
  58. package/src/path.js +0 -32
  59. package/src/query.js +0 -207
  60. package/src/ruleNames.js +0 -12
  61. package/src/spread.js +0 -104
  62. package/src/subExpression.js +0 -52
  63. package/src/utilities/array.js +0 -30
  64. package/src/utilities/query.js +0 -22
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+
3
+ import { characters } from "necessary";
4
+
5
+ import ParseTree from "../parseTree";
6
+
7
+ import { EMPTY_STRING } from "../constants";
8
+
9
+ const { BAR_CHARACTER } = characters;
10
+
11
+ export default class VerticalBranchParseTree extends ParseTree {
12
+ constructor(lines, verticalBranchPosition) {
13
+ super(lines);
14
+
15
+ this.verticalBranchPosition = verticalBranchPosition;
16
+ }
17
+
18
+ getVerticalBranchPosition() {
19
+ return this.verticalBranchPosition;
20
+ }
21
+
22
+ addLeftMargin(leftMarginWidth) {
23
+ super.addLeftMargin(leftMarginWidth);
24
+
25
+ this.verticalBranchPosition += leftMarginWidth; ///
26
+ }
27
+
28
+ static fromWidth(width) {
29
+ const string = BAR_CHARACTER,
30
+ verticalBranchPosition = 0,
31
+ verticalBranchParseTree = VerticalBranchParseTree.fromStringAndVerticalBranchPosition(VerticalBranchParseTree, string, verticalBranchPosition),
32
+ leftMarginWidth = Math.floor(width/2),
33
+ rightMarginWidth = width - leftMarginWidth - 1;
34
+
35
+ verticalBranchParseTree.addLeftMargin(leftMarginWidth);
36
+ verticalBranchParseTree.addRightMargin(rightMarginWidth);
37
+
38
+ return verticalBranchParseTree;
39
+ }
40
+
41
+ static fromDepthAndVerticalBranchPosition(Class, depth, verticalBranchPosition) {
42
+ const lines = linesFromDepth(depth),
43
+ verticalBranchParseTree = new Class(lines, verticalBranchPosition);
44
+
45
+ return verticalBranchParseTree;
46
+ }
47
+
48
+ static fromStringAndVerticalBranchPosition(Class, string, verticalBranchPosition) {
49
+ if (verticalBranchPosition === undefined) {
50
+ verticalBranchPosition = string; ///
51
+
52
+ string = Class; ///
53
+
54
+ Class = ParseTree; ///
55
+ }
56
+
57
+ const line = string, ///
58
+ lines = [
59
+ line
60
+ ],
61
+ verticalBranchParseTree = new Class(lines, verticalBranchPosition);
62
+
63
+ return verticalBranchParseTree;
64
+ }
65
+ }
66
+
67
+ function linesFromDepth(depth) {
68
+ const lines = [];
69
+
70
+ let index = 0;
71
+
72
+ while (index < depth) {
73
+ lines[index++] = EMPTY_STRING;
74
+ }
75
+
76
+ return lines;
77
+ }
@@ -0,0 +1,141 @@
1
+ "use strict";
2
+
3
+ import { characters, arrayUtilities } from "necessary";
4
+
5
+ import { EMPTY_STRING } from "./constants";
6
+
7
+ const { last } = arrayUtilities,
8
+ { NEW_LINE_CHARACTER, SPACE_CHARACTER } = characters;
9
+
10
+ export default class ParseTree {
11
+ constructor(lines) {
12
+ this.lines = lines;
13
+ }
14
+
15
+ clone() {
16
+ const lines = this.lines.slice(), ///
17
+ parseTree = new ParseTree(lines);
18
+
19
+ return parseTree;
20
+ }
21
+
22
+ getWidth() {
23
+ let width;
24
+
25
+ let linesLength = this.lines.length;
26
+
27
+ if (linesLength === 0) {
28
+ width = 0;
29
+ } else {
30
+ const lastLine = last(this.lines),
31
+ lastLineLength = lastLine.length;
32
+
33
+ width = lastLineLength; ///
34
+ }
35
+
36
+ return width;
37
+ }
38
+
39
+ getDepth() {
40
+ const linesLength = this.lines.length,
41
+ depth = linesLength; ///
42
+
43
+ return depth;
44
+ }
45
+
46
+ forEachLine(callback) {
47
+ this.lines.forEach(callback);
48
+ }
49
+
50
+ appendToTop(parseTree) {
51
+ parseTree.forEachLine((line) => {
52
+ this.lines.unshift(line);
53
+ });
54
+ }
55
+
56
+ appendToLeft(parseTree) {
57
+ parseTree.forEachLine((line, index) => {
58
+ this.lines[index] = line + this.lines[index];
59
+ });
60
+ }
61
+
62
+ appendToRight(parseTree) {
63
+ parseTree.forEachLine((line, index) => {
64
+ this.lines[index] = this.lines[index] + line;
65
+ });
66
+ }
67
+
68
+ appendToBottom(parseTree) {
69
+ parseTree.forEachLine((line) => {
70
+ this.lines.push(line);
71
+ });
72
+ }
73
+
74
+ addTopMargin(topMarginDepth) {
75
+ const width = this.getWidth(),
76
+ topMarginWidth = width, ///
77
+ topMarginString = marginStringFromMarginWidth(topMarginWidth);
78
+
79
+ for (let index = 0; index < topMarginDepth; index++) {
80
+ this.lines.unshift(topMarginString);
81
+ }
82
+ }
83
+
84
+ addLeftMargin(leftMarginWidth) {
85
+ const leftMarginString = marginStringFromMarginWidth(leftMarginWidth),
86
+ linesLength = this.lines.length;
87
+
88
+ for (let index = 0; index < linesLength; index++) {
89
+ this.lines[index] = leftMarginString + this.lines[index];
90
+ }
91
+ }
92
+
93
+ addRightMargin(rightMarginWidth) {
94
+ const rightMarginString = marginStringFromMarginWidth(rightMarginWidth),
95
+ linesLength = this.lines.length;
96
+
97
+ for (let index = 0; index < linesLength; index++) {
98
+ this.lines[index] = this.lines[index] + rightMarginString;
99
+ }
100
+ }
101
+
102
+ addBottomMargin(bottomMarginDepth) {
103
+ const width = this.getWidth(),
104
+ bottomMarginWidth = width, ///
105
+ bottomMarginString = marginStringFromMarginWidth(bottomMarginWidth);
106
+
107
+ for (let index = 0; index < bottomMarginDepth; index++) {
108
+ this.lines.push(bottomMarginString);
109
+ }
110
+ }
111
+
112
+ popLine() { return this.lines.pop(); }
113
+
114
+ shiftLine() { return this.lines.shift(); }
115
+
116
+ pushLine(line) { this.lines.push(line); }
117
+
118
+ unshiftLine(line) { this.lines.unshift(line); }
119
+
120
+ asString() {
121
+ const string = this.lines.reduce((string, line) => {
122
+ string += line + NEW_LINE_CHARACTER;
123
+
124
+ return string;
125
+ }, EMPTY_STRING);
126
+
127
+ return string;
128
+ }
129
+ }
130
+
131
+ function marginStringFromMarginWidth(marginWidth, spaceCharacter) {
132
+ spaceCharacter = spaceCharacter || SPACE_CHARACTER;
133
+
134
+ let marginString = EMPTY_STRING;
135
+
136
+ for (let index = 0; index < marginWidth; index++) {
137
+ marginString += spaceCharacter;
138
+ }
139
+
140
+ return marginString;
141
+ }