transform.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. var IPropertyDescriptor_1 = require("../IPropertyDescriptor");
  4. var tokenizer_1 = require("../syntax/tokenizer");
  5. exports.transform = {
  6. name: 'transform',
  7. initialValue: 'none',
  8. prefix: true,
  9. type: IPropertyDescriptor_1.PropertyDescriptorParsingType.VALUE,
  10. parse: function (token) {
  11. if (token.type === tokenizer_1.TokenType.IDENT_TOKEN && token.value === 'none') {
  12. return null;
  13. }
  14. if (token.type === tokenizer_1.TokenType.FUNCTION) {
  15. var transformFunction = SUPPORTED_TRANSFORM_FUNCTIONS[token.name];
  16. if (typeof transformFunction === 'undefined') {
  17. throw new Error("Attempting to parse an unsupported transform function \"" + token.name + "\"");
  18. }
  19. return transformFunction(token.values);
  20. }
  21. return null;
  22. }
  23. };
  24. var matrix = function (args) {
  25. var values = args.filter(function (arg) { return arg.type === tokenizer_1.TokenType.NUMBER_TOKEN; }).map(function (arg) { return arg.number; });
  26. return values.length === 6 ? values : null;
  27. };
  28. // doesn't support 3D transforms at the moment
  29. var matrix3d = function (args) {
  30. var values = args.filter(function (arg) { return arg.type === tokenizer_1.TokenType.NUMBER_TOKEN; }).map(function (arg) { return arg.number; });
  31. var a1 = values[0], b1 = values[1], _a = values[2], _b = values[3], a2 = values[4], b2 = values[5], _c = values[6], _d = values[7], _e = values[8], _f = values[9], _g = values[10], _h = values[11], a4 = values[12], b4 = values[13], _j = values[14], _k = values[15];
  32. return values.length === 16 ? [a1, b1, a2, b2, a4, b4] : null;
  33. };
  34. var SUPPORTED_TRANSFORM_FUNCTIONS = {
  35. matrix: matrix,
  36. matrix3d: matrix3d
  37. };
  38. //# sourceMappingURL=transform.js.map