anchor.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 = /*#__PURE__*/function () {
  7. function Anchor(worksheet, address) {
  8. var offset = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
  9. _classCallCheck(this, Anchor);
  10. if (!address) {
  11. this.nativeCol = 0;
  12. this.nativeColOff = 0;
  13. this.nativeRow = 0;
  14. this.nativeRowOff = 0;
  15. } else if (typeof address === 'string') {
  16. var decoded = colCache.decodeAddress(address);
  17. this.nativeCol = decoded.col + offset;
  18. this.nativeColOff = 0;
  19. this.nativeRow = decoded.row + offset;
  20. this.nativeRowOff = 0;
  21. } else if (address.nativeCol !== undefined) {
  22. this.nativeCol = address.nativeCol || 0;
  23. this.nativeColOff = address.nativeColOff || 0;
  24. this.nativeRow = address.nativeRow || 0;
  25. this.nativeRowOff = address.nativeRowOff || 0;
  26. } else if (address.col !== undefined) {
  27. this.col = address.col + offset;
  28. this.row = address.row + offset;
  29. } else {
  30. this.nativeCol = 0;
  31. this.nativeColOff = 0;
  32. this.nativeRow = 0;
  33. this.nativeRowOff = 0;
  34. }
  35. this.worksheet = worksheet;
  36. }
  37. _createClass(Anchor, [{
  38. key: "col",
  39. get: function get() {
  40. return this.nativeCol + Math.min(this.colWidth - 1, this.nativeColOff) / this.colWidth;
  41. },
  42. set: function set(v) {
  43. this.nativeCol = Math.floor(v);
  44. this.nativeColOff = Math.floor((v - this.nativeCol) * this.colWidth);
  45. }
  46. }, {
  47. key: "row",
  48. get: function get() {
  49. return this.nativeRow + Math.min(this.rowHeight - 1, this.nativeRowOff) / this.rowHeight;
  50. },
  51. set: function set(v) {
  52. this.nativeRow = Math.floor(v);
  53. this.nativeRowOff = Math.floor((v - this.nativeRow) * this.rowHeight);
  54. }
  55. }, {
  56. key: "colWidth",
  57. get: function get() {
  58. return this.worksheet && this.worksheet.getColumn(this.nativeCol + 1) && this.worksheet.getColumn(this.nativeCol + 1).isCustomWidth ? Math.floor(this.worksheet.getColumn(this.nativeCol + 1).width * 10000) : 640000;
  59. }
  60. }, {
  61. key: "rowHeight",
  62. get: function get() {
  63. return this.worksheet && this.worksheet.getRow(this.nativeRow + 1) && this.worksheet.getRow(this.nativeRow + 1).height ? Math.floor(this.worksheet.getRow(this.nativeRow + 1).height * 10000) : 180000;
  64. }
  65. }, {
  66. key: "model",
  67. get: function get() {
  68. return {
  69. nativeCol: this.nativeCol,
  70. nativeColOff: this.nativeColOff,
  71. nativeRow: this.nativeRow,
  72. nativeRowOff: this.nativeRowOff
  73. };
  74. },
  75. set: function set(value) {
  76. this.nativeCol = value.nativeCol;
  77. this.nativeColOff = value.nativeColOff;
  78. this.nativeRow = value.nativeRow;
  79. this.nativeRowOff = value.nativeRowOff;
  80. }
  81. }], [{
  82. key: "asInstance",
  83. value: function asInstance(model) {
  84. return model instanceof Anchor || model == null ? model : new Anchor(model);
  85. }
  86. }]);
  87. return Anchor;
  88. }();
  89. module.exports = Anchor;
  90. //# sourceMappingURL=anchor.js.map