image.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. "use strict";
  2. const colCache = require('../utils/col-cache');
  3. const Anchor = require('./anchor');
  4. class Image {
  5. constructor(worksheet, model) {
  6. this.worksheet = worksheet;
  7. this.model = model;
  8. }
  9. get model() {
  10. switch (this.type) {
  11. case 'background':
  12. return {
  13. type: this.type,
  14. imageId: this.imageId
  15. };
  16. case 'image':
  17. return {
  18. type: this.type,
  19. imageId: this.imageId,
  20. hyperlinks: this.range.hyperlinks,
  21. range: {
  22. tl: this.range.tl.model,
  23. br: this.range.br && this.range.br.model,
  24. ext: this.range.ext,
  25. editAs: this.range.editAs
  26. }
  27. };
  28. default:
  29. throw new Error('Invalid Image Type');
  30. }
  31. }
  32. set model(_ref) {
  33. let {
  34. type,
  35. imageId,
  36. range,
  37. hyperlinks
  38. } = _ref;
  39. this.type = type;
  40. this.imageId = imageId;
  41. if (type === 'image') {
  42. if (typeof range === 'string') {
  43. const decoded = colCache.decode(range);
  44. this.range = {
  45. tl: new Anchor(this.worksheet, {
  46. col: decoded.left,
  47. row: decoded.top
  48. }, -1),
  49. br: new Anchor(this.worksheet, {
  50. col: decoded.right,
  51. row: decoded.bottom
  52. }, 0),
  53. editAs: 'oneCell'
  54. };
  55. } else {
  56. this.range = {
  57. tl: new Anchor(this.worksheet, range.tl, 0),
  58. br: range.br && new Anchor(this.worksheet, range.br, 0),
  59. ext: range.ext,
  60. editAs: range.editAs,
  61. hyperlinks: hyperlinks || range.hyperlinks
  62. };
  63. }
  64. }
  65. }
  66. }
  67. module.exports = Image;
  68. //# sourceMappingURL=image.js.map