excel.fill_helper.js 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /**
  2. * DevExtreme (exporter/excel/excel.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.pattern_fill_helper");
  17. var _excel4 = _interopRequireDefault(_excel3);
  18. function _interopRequireDefault(obj) {
  19. return obj && obj.__esModule ? obj : {
  20. "default": obj
  21. }
  22. }
  23. var fillHelper = {
  24. tryCreateTag: function(sourceObj) {
  25. var result = null;
  26. if ((0, _type.isDefined)(sourceObj)) {
  27. result = {
  28. patternFill: _excel4.default.tryCreateTag(sourceObj.patternFill)
  29. };
  30. if (fillHelper.isEmpty(result)) {
  31. result = null
  32. }
  33. }
  34. return result
  35. },
  36. tryCreateFillFromSimpleFormat: function() {
  37. var _ref = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {},
  38. backgroundColor = _ref.backgroundColor,
  39. fillPatternType = _ref.fillPatternType,
  40. fillPatternColor = _ref.fillPatternColor;
  41. if ((0, _type.isDefined)(backgroundColor) && !((0, _type.isDefined)(fillPatternType) && (0, _type.isDefined)(fillPatternColor))) {
  42. return {
  43. patternFill: {
  44. patternType: "solid",
  45. foregroundColor: {
  46. rgb: backgroundColor
  47. }
  48. }
  49. }
  50. } else {
  51. if ((0, _type.isDefined)(fillPatternType) && (0, _type.isDefined)(fillPatternColor)) {
  52. return {
  53. patternFill: {
  54. patternType: fillPatternType,
  55. foregroundColor: {
  56. rgb: fillPatternColor
  57. },
  58. backgroundColor: {
  59. rgb: backgroundColor
  60. }
  61. }
  62. }
  63. }
  64. }
  65. },
  66. copySimpleFormat: function(source, target) {
  67. if (void 0 !== source.backgroundColor) {
  68. target.backgroundColor = source.backgroundColor
  69. }
  70. if (void 0 !== source.fillPatternType) {
  71. target.fillPatternType = source.fillPatternType
  72. }
  73. if (void 0 !== source.fillPatternColor) {
  74. target.fillPatternColor = source.fillPatternColor
  75. }
  76. },
  77. copy: function(source) {
  78. var result = null;
  79. if ((0, _type.isDefined)(source)) {
  80. result = {};
  81. if (void 0 !== source.patternFill) {
  82. result.patternFill = _excel4.default.copy(source.patternFill)
  83. }
  84. }
  85. return result
  86. },
  87. areEqual: function(leftTag, rightTag) {
  88. return fillHelper.isEmpty(leftTag) && fillHelper.isEmpty(rightTag) || (0, _type.isDefined)(leftTag) && (0, _type.isDefined)(rightTag) && _excel4.default.areEqual(leftTag.patternFill, rightTag.patternFill)
  89. },
  90. isEmpty: function(tag) {
  91. return !(0, _type.isDefined)(tag) || _excel4.default.isEmpty(tag.patternFill)
  92. },
  93. toXml: function(tag) {
  94. return _excel2.default.toXml("fill", {}, _excel4.default.toXml(tag.patternFill))
  95. }
  96. };
  97. exports.default = fillHelper;