excel.pattern_fill_helper.js 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /**
  2. * DevExtreme (exporter/excel/excel.pattern_fill_helper.js)
  3. * Version: 19.1.16
  4. * Build date: Tue Oct 18 2022
  5. *
  6. * Copyright (c) 2012 - 2022 Developer Express Inc. ALL RIGHTS RESERVED
  7. * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
  8. */
  9. "use strict";
  10. Object.defineProperty(exports, "__esModule", {
  11. value: true
  12. });
  13. var _type = require("../../core/utils/type");
  14. var _excel = require("./excel.tag_helper");
  15. var _excel2 = _interopRequireDefault(_excel);
  16. var _excel3 = require("./excel.color_helper");
  17. var _excel4 = _interopRequireDefault(_excel3);
  18. function _interopRequireDefault(obj) {
  19. return obj && obj.__esModule ? obj : {
  20. "default": obj
  21. }
  22. }
  23. var patternFillHelper = {
  24. tryCreateTag: function(sourceObj) {
  25. var result = null;
  26. if ((0, _type.isDefined)(sourceObj)) {
  27. result = {
  28. patternType: sourceObj.patternType,
  29. backgroundColor: _excel4.default.tryCreateTag(sourceObj.backgroundColor),
  30. foregroundColor: _excel4.default.tryCreateTag(sourceObj.foregroundColor)
  31. };
  32. if (patternFillHelper.isEmpty(result)) {
  33. result = null
  34. }
  35. }
  36. return result
  37. },
  38. copy: function(source) {
  39. var result = null;
  40. if ((0, _type.isDefined)(source)) {
  41. result = {};
  42. if (void 0 !== source.patternType) {
  43. result.patternType = source.patternType
  44. }
  45. if (void 0 !== source.backgroundColor) {
  46. result.backgroundColor = _excel4.default.copy(source.backgroundColor)
  47. }
  48. if (void 0 !== source.foregroundColor) {
  49. result.foregroundColor = _excel4.default.copy(source.foregroundColor)
  50. }
  51. }
  52. return result
  53. },
  54. areEqual: function(leftTag, rightTag) {
  55. return patternFillHelper.isEmpty(leftTag) && patternFillHelper.isEmpty(rightTag) || (0, _type.isDefined)(leftTag) && (0, _type.isDefined)(rightTag) && leftTag.patternType === rightTag.patternType && _excel4.default.areEqual(leftTag.backgroundColor, rightTag.backgroundColor) && _excel4.default.areEqual(leftTag.foregroundColor, rightTag.foregroundColor)
  56. },
  57. isEmpty: function(tag) {
  58. return !(0, _type.isDefined)(tag) || !(0, _type.isDefined)(tag.patternType)
  59. },
  60. toXml: function(tag) {
  61. var content = [(0, _type.isDefined)(tag.foregroundColor) ? _excel4.default.toXml("fgColor", tag.foregroundColor) : "", (0, _type.isDefined)(tag.backgroundColor) ? _excel4.default.toXml("bgColor", tag.backgroundColor) : ""].join("");
  62. return _excel2.default.toXml("patternFill", {
  63. patternType: tag.patternType
  64. }, content)
  65. }
  66. };
  67. exports.default = patternFillHelper;