aboutsummaryrefslogtreecommitdiff
path: root/catapult/third_party/polymer/components/web-animations-js/src/shape-handler.js
blob: 6bbf79fe488377885cf9b88b16aa7a8a72b34afe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// Copyright 2014 Google Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
//   You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//   See the License for the specific language governing permissions and
// limitations under the License.

(function(scope) {

  var consumeLengthOrPercent = scope.consumeParenthesised.bind(null, scope.parseLengthOrPercent);
  var consumeLengthOrPercentPair = scope.consumeRepeated.bind(undefined, consumeLengthOrPercent, /^/);

  var mergeSizePair = scope.mergeNestedRepeated.bind(undefined, scope.mergeDimensions, ' ');
  var mergeSizePairList = scope.mergeNestedRepeated.bind(undefined, mergeSizePair, ',');

  function parseShape(input) {
    var circle = scope.consumeToken(/^circle/, input);
    if (circle && circle[0]) {
      return ['circle'].concat(scope.consumeList([
        scope.ignore(scope.consumeToken.bind(undefined, /^\(/)),
        consumeLengthOrPercent,
        scope.ignore(scope.consumeToken.bind(undefined, /^at/)),
        scope.consumePosition,
        scope.ignore(scope.consumeToken.bind(undefined, /^\)/))
      ], circle[1]));
    }
    var ellipse = scope.consumeToken(/^ellipse/, input);
    if (ellipse && ellipse[0]) {
      return ['ellipse'].concat(scope.consumeList([
        scope.ignore(scope.consumeToken.bind(undefined, /^\(/)),
        consumeLengthOrPercentPair,
        scope.ignore(scope.consumeToken.bind(undefined, /^at/)),
        scope.consumePosition,
        scope.ignore(scope.consumeToken.bind(undefined, /^\)/))
      ], ellipse[1]));
    }
    var polygon = scope.consumeToken(/^polygon/, input);
    if (polygon && polygon[0]) {
      return ['polygon'].concat(scope.consumeList([
        scope.ignore(scope.consumeToken.bind(undefined, /^\(/)),
        scope.optional(scope.consumeToken.bind(undefined, /^nonzero\s*,|^evenodd\s*,/), 'nonzero,'),
        scope.consumeSizePairList,
        scope.ignore(scope.consumeToken.bind(undefined, /^\)/))
      ], polygon[1]));
    }
  }

  function mergeShapes(left, right) {
    if (left[0] !== right[0])
      return;
    if (left[0] == 'circle') {
      return scope.mergeList(left.slice(1), right.slice(1), [
        'circle(',
        scope.mergeDimensions,
        ' at ',
        scope.mergeOffsetList,
        ')']);
    }
    if (left[0] == 'ellipse') {
      return scope.mergeList(left.slice(1), right.slice(1), [
        'ellipse(',
        scope.mergeNonNegativeSizePair,
        ' at ',
        scope.mergeOffsetList,
        ')']);
    }
    if (left[0] == 'polygon' && left[1] == right[1]) {
      return scope.mergeList(left.slice(2), right.slice(2), [
        'polygon(',
        left[1],
        mergeSizePairList,
        ')']);
    }
  }

  scope.addPropertiesHandler(parseShape, mergeShapes, ['shape-outside']);

})(webAnimations1);