ddb486c8cc8a04b038c4938993be1e6f0dfa00fec6a746c86a777d5eba7b9bea62fa81afef89c4e6d03f5f76840c86063fffee76810d7289eddb448f0197ea 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. "use strict";
  2. var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
  3. Object.defineProperty(exports, "__esModule", {
  4. value: true
  5. });
  6. exports.drawPolylinePath = drawPolylinePath;
  7. exports.drawBezierCurvePath = drawBezierCurvePath;
  8. exports["default"] = void 0;
  9. var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
  10. /**
  11. * @description Draw a polyline path
  12. * @param {Object} ctx Canvas 2d context
  13. * @param {Array} points The points that makes up a polyline
  14. * @param {Boolean} beginPath Whether to execute beginPath
  15. * @param {Boolean} closePath Whether to execute closePath
  16. * @return {Undefined} Void
  17. */
  18. function drawPolylinePath(ctx, points) {
  19. var beginPath = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  20. var closePath = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
  21. if (!ctx || points.length < 2) return false;
  22. if (beginPath) ctx.beginPath();
  23. points.forEach(function (point, i) {
  24. return point && (i === 0 ? ctx.moveTo.apply(ctx, (0, _toConsumableArray2["default"])(point)) : ctx.lineTo.apply(ctx, (0, _toConsumableArray2["default"])(point)));
  25. });
  26. if (closePath) ctx.closePath();
  27. }
  28. /**
  29. * @description Draw a bezier curve path
  30. * @param {Object} ctx Canvas 2d context
  31. * @param {Array} points The points that makes up a bezier curve
  32. * @param {Array} moveTo The point need to excute moveTo
  33. * @param {Boolean} beginPath Whether to execute beginPath
  34. * @param {Boolean} closePath Whether to execute closePath
  35. * @return {Undefined} Void
  36. */
  37. function drawBezierCurvePath(ctx, points) {
  38. var moveTo = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  39. var beginPath = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
  40. var closePath = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
  41. if (!ctx || !points) return false;
  42. if (beginPath) ctx.beginPath();
  43. if (moveTo) ctx.moveTo.apply(ctx, (0, _toConsumableArray2["default"])(moveTo));
  44. points.forEach(function (item) {
  45. return item && ctx.bezierCurveTo.apply(ctx, (0, _toConsumableArray2["default"])(item[0]).concat((0, _toConsumableArray2["default"])(item[1]), (0, _toConsumableArray2["default"])(item[2])));
  46. });
  47. if (closePath) ctx.closePath();
  48. }
  49. var _default = {
  50. drawPolylinePath: drawPolylinePath,
  51. drawBezierCurvePath: drawBezierCurvePath
  52. };
  53. exports["default"] = _default;