|
34 | 34 | return {type: 'path', path: path}; |
35 | 35 | } |
36 | 36 |
|
37 | | - function offsetPathParse (input) { |
38 | | - var parseAngleAsDegrees = internalScope.parseAngleAsDegrees; |
39 | | - var isInArray = internalScope.isInArray; |
40 | | - // https://drafts.fxtf.org/motion-1/#offset-path-property |
| 37 | + function basicShapeCircleParse (input) { |
| 38 | + // TODO: Need element as an argument to this function |
| 39 | + var radius; |
| 40 | + var position = /at (.*?)$/.exec(input); |
41 | 41 |
|
| 42 | + // TODO: Need to support other positions as currently this only supports positions in which both x and y are specified and are in px |
| 43 | + if (position === null) { |
| 44 | + // TODO: Set default position to the center of the reference box |
| 45 | + position = '0px 0px'; |
| 46 | + if (input !== '') { |
| 47 | + radius = input; |
| 48 | + } |
| 49 | + } else { |
| 50 | + position = position[1].split(/\s+/); |
| 51 | + radius = (/^(.*?) at/.exec(input)); |
| 52 | + if (radius === null) { |
| 53 | + radius = 'closest-side'; |
| 54 | + } else { |
| 55 | + radius = radius[1]; |
| 56 | + } |
| 57 | + } |
| 58 | + |
| 59 | + radius = Number(radius.substring(0, radius.length - 2)); |
| 60 | + |
| 61 | + var positionX = Number(position[0].substring(0, position[0].length - 2)); |
| 62 | + var positionY = Number(position[1].substring(0, position[1].length - 2)); |
| 63 | + |
| 64 | + var pathString = 'M ' + positionX + ' ' + positionY + |
| 65 | + ' m 0,' + (-radius) + |
| 66 | + ' a ' + radius + ',' + radius + ' 0 0,1 ' + radius + ',' + radius + |
| 67 | + ' a ' + radius + ',' + radius + ' 0 1,1 ' + (-radius) + ',' + (-radius) + ' z'; |
| 68 | + |
| 69 | + return {type: 'path', path: pathString}; |
| 70 | + } |
| 71 | + |
| 72 | + function basicShapeInsetParse (input) { |
| 73 | + // WIP |
| 74 | + return null; |
| 75 | + } |
| 76 | + |
| 77 | + function basicShapeEllipseParse (input) { |
| 78 | + // WIP |
| 79 | + return null; |
| 80 | + } |
| 81 | + |
| 82 | + function parseNone (input) { |
42 | 83 | if (input === 'none') { |
43 | 84 | return {type: null, angle: null, path: null}; |
44 | 85 | } |
| 86 | + } |
45 | 87 |
|
| 88 | + function parseRay (input) { |
| 89 | + var isInArray = internalScope.isInArray; |
| 90 | + var parseAngleAsDegrees = internalScope.parseAngleAsDegrees; |
46 | 91 | var ray = /^ray\((.*)\)$/.exec(input); |
47 | | - var path = /^path\(['"](.*)['"]\)$/.exec(input); |
48 | | - // TODO: For basic shape check for closing brackets |
49 | | - var shapeType = /^[^\(]*/.exec(input); |
50 | 92 |
|
51 | | - if (ray !== null) { |
52 | | - var rayInput = ray[1].split(/\s+/); |
53 | | - if (rayInput.length > 3) { |
54 | | - return undefined; |
55 | | - } |
56 | | - var result = {type: 'ray', angle: null, path: null, contain: false, size: null}; |
57 | | - var validSizes = ['closest-side', 'farthest-side', 'closest-corner', 'farthest-corner']; |
58 | | - |
59 | | - for (var i = 0; i < rayInput.length; i++) { |
60 | | - if (rayInput[i] === 'contain') { |
61 | | - if (result.contain) { |
62 | | - return undefined; |
63 | | - } |
64 | | - result.contain = true; |
65 | | - } else if (isInArray(validSizes, rayInput[i])) { |
66 | | - if (result.size) { |
67 | | - return undefined; |
68 | | - } |
69 | | - result.size = rayInput[i]; |
70 | | - } else { |
71 | | - if (result.angle) { |
72 | | - return undefined; |
73 | | - } |
74 | | - var rayInputDegrees = parseAngleAsDegrees(rayInput[i]); |
75 | | - if (rayInputDegrees === null) { |
76 | | - return undefined; |
77 | | - } |
78 | | - result.angle = rayInputDegrees; |
| 93 | + if (ray === null) { |
| 94 | + return undefined; |
| 95 | + } |
| 96 | + var rayInput = ray[1].split(/\s+/); |
| 97 | + if (rayInput.length > 3) { |
| 98 | + return undefined; |
| 99 | + } |
| 100 | + var result = {type: 'ray', angle: null, path: null, contain: false, size: null}; |
| 101 | + var validSizes = ['closest-side', 'farthest-side', 'closest-corner', 'farthest-corner']; |
| 102 | + |
| 103 | + for (var i = 0; i < rayInput.length; i++) { |
| 104 | + if (rayInput[i] === 'contain') { |
| 105 | + if (result.contain) { |
| 106 | + return undefined; |
79 | 107 | } |
| 108 | + result.contain = true; |
| 109 | + } else if (isInArray(validSizes, rayInput[i])) { |
| 110 | + if (result.size) { |
| 111 | + return undefined; |
| 112 | + } |
| 113 | + result.size = rayInput[i]; |
| 114 | + } else { |
| 115 | + if (result.angle) { |
| 116 | + return undefined; |
| 117 | + } |
| 118 | + var rayInputDegrees = parseAngleAsDegrees(rayInput[i]); |
| 119 | + if (rayInputDegrees === null) { |
| 120 | + return undefined; |
| 121 | + } |
| 122 | + result.angle = rayInputDegrees; |
80 | 123 | } |
81 | | - return result; |
82 | | - } else if (path !== null) { |
83 | | - var pathInput = path[1]; |
84 | | - return {type: 'path', path: pathInput}; |
85 | | - } else if (shapeType !== null) { |
86 | | - var basicShapes = ['inset', 'circle', 'ellipse', 'polygon']; |
87 | | - if (!isInArray(basicShapes, shapeType[0])) { |
88 | | - return undefined; |
89 | | - } |
90 | | - var shapeArguments = /\(([^)]+)\)/.exec(input); |
91 | | - if (shapeArguments === null) { |
92 | | - return undefined; |
| 124 | + } |
| 125 | + return result; |
| 126 | + } |
| 127 | + |
| 128 | + function parsePath (input) { |
| 129 | + var path = /^path\(['"](.*)['"]\)$/.exec(input); |
| 130 | + if (path === null) { |
| 131 | + return undefined; |
| 132 | + } |
| 133 | + var pathInput = path[1]; |
| 134 | + return {type: 'path', path: pathInput}; |
| 135 | + } |
| 136 | + |
| 137 | + function parseShape (input) { |
| 138 | + var isInArray = internalScope.isInArray; |
| 139 | + var shapeType = /^[^\(]*/.exec(input); |
| 140 | + if (shapeType == null) { |
| 141 | + return undefined; |
| 142 | + } |
| 143 | + var basicShapes = ['inset', 'circle', 'ellipse', 'polygon']; |
| 144 | + if (!isInArray(basicShapes, shapeType[0])) { |
| 145 | + return undefined; |
| 146 | + } |
| 147 | + // TODO: For basic shape check for closing brackets |
| 148 | + var shapeArguments = /\(([^)]+)\)/.exec(input); |
| 149 | + if (shapeArguments === null) { |
| 150 | + return undefined; |
| 151 | + } |
| 152 | + var toParse = [basicShapePolygonParse, basicShapeCircleParse, basicShapeInsetParse, basicShapeEllipseParse]; |
| 153 | + for (var i = 0; i < toParse.length; i++) { |
| 154 | + var result = toParse[i](shapeArguments[1]); |
| 155 | + if (result) { |
| 156 | + return result; |
93 | 157 | } |
94 | | - if (shapeType[0] === 'polygon') { |
95 | | - return basicShapePolygonParse(shapeArguments[1]); |
| 158 | + } |
| 159 | + return undefined; |
| 160 | + } |
| 161 | + |
| 162 | + function offsetPathParse (input) { |
| 163 | + // https://drafts.fxtf.org/motion-1/#offset-path-property |
| 164 | + var toParse = [parseNone, parseRay, parsePath, parseShape]; |
| 165 | + for (var i = 0; i < toParse.length; i++) { |
| 166 | + var result = toParse[i](input); |
| 167 | + if (result) { |
| 168 | + return result; |
96 | 169 | } |
97 | 170 | } |
98 | 171 | return undefined; |
|
114 | 187 | if (input.type === 'path') { |
115 | 188 | return "path('" + input.path + "')"; |
116 | 189 | } |
| 190 | + |
117 | 191 | if (input.type === null) { |
118 | 192 | return 'none'; |
119 | 193 | } |
|
0 commit comments