image.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. "use strict";
  2. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  3. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  4. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  5. var colCache = require('../utils/col-cache');
  6. var Anchor = require('./anchor');
  7. var Image = /*#__PURE__*/function () {
  8. function Image(worksheet, model) {
  9. _classCallCheck(this, Image);
  10. this.worksheet = worksheet;
  11. this.model = model;
  12. }
  13. _createClass(Image, [{
  14. key: "model",
  15. get: function get() {
  16. switch (this.type) {
  17. case 'background':
  18. return {
  19. type: this.type,
  20. imageId: this.imageId
  21. };
  22. case 'image':
  23. return {
  24. type: this.type,
  25. imageId: this.imageId,
  26. hyperlinks: this.range.hyperlinks,
  27. range: {
  28. tl: this.range.tl.model,
  29. br: this.range.br && this.range.br.model,
  30. ext: this.range.ext,
  31. editAs: this.range.editAs
  32. }
  33. };
  34. default:
  35. throw new Error('Invalid Image Type');
  36. }
  37. },
  38. set: function set(_ref) {
  39. var type = _ref.type,
  40. imageId = _ref.imageId,
  41. range = _ref.range,
  42. hyperlinks = _ref.hyperlinks;
  43. this.type = type;
  44. this.imageId = imageId;
  45. if (type === 'image') {
  46. if (typeof range === 'string') {
  47. var decoded = colCache.decode(range);
  48. this.range = {
  49. tl: new Anchor(this.worksheet, {
  50. col: decoded.left,
  51. row: decoded.top
  52. }, -1),
  53. br: new Anchor(this.worksheet, {
  54. col: decoded.right,
  55. row: decoded.bottom
  56. }, 0),
  57. editAs: 'oneCell'
  58. };
  59. } else {
  60. this.range = {
  61. tl: new Anchor(this.worksheet, range.tl, 0),
  62. br: range.br && new Anchor(this.worksheet, range.br, 0),
  63. ext: range.ext,
  64. editAs: range.editAs,
  65. hyperlinks: hyperlinks || range.hyperlinks
  66. };
  67. }
  68. }
  69. }
  70. }]);
  71. return Image;
  72. }();
  73. module.exports = Image;
  74. //# sourceMappingURL=image.js.map