|
2 | 2 | 'use strict'; |
3 | 3 |
|
4 | 4 | (function () { |
5 | | - function basicShapePolygon (input) { |
| 5 | + function basicShapePolygonParse (input) { |
6 | 6 | // TODO: Support the fill-rule option and % |
7 | 7 | var argumentList = input.split(','); |
8 | 8 | var coordinate = null; |
|
34 | 34 | return {type: 'path', path: path}; |
35 | 35 | } |
36 | 36 |
|
37 | | - function basicShapeInset (input) { |
38 | | - // WIP |
39 | | - return null; |
40 | | - } |
41 | | - |
42 | | - function basicShapeCircle (input) { |
| 37 | + function basicShapeCircleParse (input) { |
43 | 38 | // TODO: Need element as an argument to this function |
44 | 39 | var radius; |
45 | 40 | var position = /at (.*?)$/.exec(input); |
|
74 | 69 | return {type: 'path', path: pathString}; |
75 | 70 | } |
76 | 71 |
|
77 | | - function basicShapeEllipse (input) { |
| 72 | + function basicShapeInsetParse (input) { |
78 | 73 | // WIP |
79 | 74 | return null; |
80 | 75 | } |
81 | 76 |
|
82 | | - function offsetPathParse (input) { |
83 | | - var parseAngleAsDegrees = internalScope.parseAngleAsDegrees; |
84 | | - var isInArray = internalScope.isInArray; |
85 | | - // https://drafts.fxtf.org/motion-1/#offset-path-property |
| 77 | + function basicShapeEllipseParse (input) { |
| 78 | + // WIP |
| 79 | + return null; |
| 80 | + } |
86 | 81 |
|
| 82 | + function parseNone (input) { |
87 | 83 | if (input === 'none') { |
88 | 84 | return {type: null, angle: null, path: null}; |
89 | 85 | } |
| 86 | + } |
90 | 87 |
|
| 88 | + function parseRay (input) { |
| 89 | + var isInArray = internalScope.isInArray; |
| 90 | + var parseAngleAsDegrees = internalScope.parseAngleAsDegrees; |
91 | 91 | var ray = /^ray\((.*)\)$/.exec(input); |
92 | | - var path = /^path\(['"](.*)['"]\)$/.exec(input); |
93 | | - // TODO: For basic shape check for closing brackets |
94 | | - var shapeType = /^[^\(]*/.exec(input); |
95 | | - |
96 | | - if (ray !== null) { |
97 | | - var rayInput = ray[1].split(/\s+/); |
98 | | - if (rayInput.length > 3) { |
99 | | - return undefined; |
100 | | - } |
| 92 | + if (ray === null) { |
| 93 | + return undefined; |
| 94 | + } |
| 95 | + var rayInput = ray[1].split(/\s+/); |
| 96 | + if (rayInput.length > 3) { |
| 97 | + return undefined; |
| 98 | + } |
| 99 | + var result = {type: 'ray', angle: null, path: null, contain: false, size: null}; |
| 100 | + var validSizes = ['closest-side', 'farthest-side', 'closest-corner', 'farthest-corner']; |
101 | 101 |
|
102 | | - var result = {type: 'ray', angle: null, path: null, contain: false, size: null}; |
103 | | - var validSizes = ['closest-side', 'farthest-side', 'closest-corner', 'farthest-corner']; |
104 | | - |
105 | | - for (var i = 0; i < rayInput.length; i++) { |
106 | | - if (rayInput[i] === 'contain') { |
107 | | - if (result.contain) { |
108 | | - return undefined; |
109 | | - } |
110 | | - result.contain = true; |
111 | | - } else if (isInArray(validSizes, rayInput[i])) { |
112 | | - if (result.size) { |
113 | | - return undefined; |
114 | | - } |
115 | | - result.size = rayInput[i]; |
116 | | - } else { |
117 | | - if (result.angle) { |
118 | | - return undefined; |
119 | | - } |
120 | | - var rayInputDegrees = parseAngleAsDegrees(rayInput[i]); |
121 | | - if (rayInputDegrees === null) { |
122 | | - return undefined; |
123 | | - } |
124 | | - result.angle = rayInputDegrees; |
| 102 | + for (var i = 0; i < rayInput.length; i++) { |
| 103 | + if (rayInput[i] === 'contain') { |
| 104 | + if (result.contain) { |
| 105 | + return undefined; |
125 | 106 | } |
| 107 | + result.contain = true; |
| 108 | + } else if (isInArray(validSizes, rayInput[i])) { |
| 109 | + if (result.size) { |
| 110 | + return undefined; |
| 111 | + } |
| 112 | + result.size = rayInput[i]; |
| 113 | + } else { |
| 114 | + if (result.angle) { |
| 115 | + return undefined; |
| 116 | + } |
| 117 | + var rayInputDegrees = parseAngleAsDegrees(rayInput[i]); |
| 118 | + if (rayInputDegrees === null) { |
| 119 | + return undefined; |
| 120 | + } |
| 121 | + result.angle = rayInputDegrees; |
126 | 122 | } |
127 | | - return result; |
128 | | - } else if (path !== null) { |
129 | | - var pathInput = path[1]; |
130 | | - return {type: 'path', path: pathInput}; |
131 | | - } else { |
132 | | - var basicShapes = ['inset', 'circle', 'ellipse', 'polygon']; |
133 | | - if (!isInArray(basicShapes, shapeType[0])) { |
134 | | - return undefined; |
135 | | - } |
136 | | - |
137 | | - var shapeArguments = /\(([^)]+)\)/.exec(input); |
138 | | - |
139 | | - if (shapeType[0] === 'inset') { |
140 | | - return basicShapeInset(shapeArguments[1]); |
141 | | - } |
| 123 | + } |
| 124 | + return result; |
| 125 | + } |
142 | 126 |
|
143 | | - if (shapeType[0] === 'circle') { |
144 | | - return basicShapeCircle(shapeArguments[1]); |
145 | | - } |
| 127 | + function parsePath (input) { |
| 128 | + var path = /^path\(['"](.*)['"]\)$/.exec(input); |
| 129 | + if (path === null) { |
| 130 | + return undefined; |
| 131 | + } |
| 132 | + var pathInput = path[1]; |
| 133 | + return {type: 'path', path: pathInput}; |
| 134 | + } |
146 | 135 |
|
147 | | - if (shapeType[0] === 'ellipse') { |
148 | | - return basicShapeEllipse(shapeArguments[1]); |
| 136 | + function parseShape (input) { |
| 137 | + var isInArray = internalScope.isInArray; |
| 138 | + var shapeType = /^[^\(]*/.exec(input); |
| 139 | + if (shapeType == null) { |
| 140 | + return undefined; |
| 141 | + } |
| 142 | + var basicShapes = ['inset', 'circle', 'ellipse', 'polygon']; |
| 143 | + if (!isInArray(basicShapes, shapeType[0])) { |
| 144 | + return undefined; |
| 145 | + } |
| 146 | + // TODO: For basic shape check for closing brackets |
| 147 | + var shapeArguments = /\(([^)]+)\)/.exec(input); |
| 148 | + if (shapeArguments === null) { |
| 149 | + return undefined; |
| 150 | + } |
| 151 | + var toParse = [basicShapePolygonParse, basicShapeCircleParse, basicShapeInsetParse, basicShapeEllipseParse]; |
| 152 | + for (var i = 0; i < toParse.length; i++) { |
| 153 | + var result = toParse[i](shapeArguments[1]); |
| 154 | + if (result) { |
| 155 | + return result; |
149 | 156 | } |
| 157 | + } |
| 158 | + return undefined; |
| 159 | + } |
150 | 160 |
|
151 | | - if (shapeType[0] === 'polygon') { |
152 | | - return basicShapePolygon(shapeArguments[1]); |
| 161 | + function offsetPathParse (input) { |
| 162 | + // https://drafts.fxtf.org/motion-1/#offset-path-property |
| 163 | + var toParse = [parseNone, parseRay, parsePath, parseShape]; |
| 164 | + for (var i = 0; i < toParse.length; i++) { |
| 165 | + var result = toParse[i](input); |
| 166 | + if (result) { |
| 167 | + return result; |
153 | 168 | } |
154 | 169 | } |
| 170 | + return undefined; |
155 | 171 | } |
156 | 172 |
|
157 | 173 | function offsetPathMerge (start, end) { |
|
0 commit comments