UNPKG

konva

Version:

<p align="center"> <img src="https://raw.githubusercontent.com/konvajs/konvajs.github.io/master/apple-touch-icon-180x180.png" alt="Konva logo" height="180" /> </p>

65 lines (64 loc) 2.81 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); var Util_1 = require("../Util"); var Factory_1 = require("../Factory"); var Shape_1 = require("../Shape"); var Global_1 = require("../Global"); var Rect = (function (_super) { __extends(Rect, _super); function Rect() { return _super !== null && _super.apply(this, arguments) || this; } Rect.prototype._sceneFunc = function (context) { var cornerRadius = this.cornerRadius(), width = this.width(), height = this.height(); context.beginPath(); if (!cornerRadius) { context.rect(0, 0, width, height); } else { var topLeft = 0; var topRight = 0; var bottomLeft = 0; var bottomRight = 0; if (typeof cornerRadius === 'number') { topLeft = topRight = bottomLeft = bottomRight = Math.min(cornerRadius, width / 2, height / 2); } else { topLeft = Math.min(cornerRadius[0], width / 2, height / 2); topRight = Math.min(cornerRadius[1], width / 2, height / 2); bottomRight = Math.min(cornerRadius[2], width / 2, height / 2); bottomLeft = Math.min(cornerRadius[3], width / 2, height / 2); } context.moveTo(topLeft, 0); context.lineTo(width - topRight, 0); context.arc(width - topRight, topRight, topRight, (Math.PI * 3) / 2, 0, false); context.lineTo(width, height - bottomRight); context.arc(width - bottomRight, height - bottomRight, bottomRight, 0, Math.PI / 2, false); context.lineTo(bottomLeft, height); context.arc(bottomLeft, height - bottomLeft, bottomLeft, Math.PI / 2, Math.PI, false); context.lineTo(0, topLeft); context.arc(topLeft, topLeft, topLeft, Math.PI, (Math.PI * 3) / 2, false); } context.closePath(); context.fillStrokeShape(this); }; return Rect; }(Shape_1.Shape)); exports.Rect = Rect; Rect.prototype.className = 'Rect'; Global_1._registerNode(Rect); Factory_1.Factory.addGetterSetter(Rect, 'cornerRadius', 0); Util_1.Collection.mapMethods(Rect);