[d565449] | 1 | "use strict";
|
---|
| 2 | Object.defineProperty(exports, "__esModule", { value: true });
|
---|
| 3 | exports.Shape = exports.shapes = void 0;
|
---|
| 4 | const Global_1 = require("./Global");
|
---|
| 5 | const Util_1 = require("./Util");
|
---|
| 6 | const Factory_1 = require("./Factory");
|
---|
| 7 | const Node_1 = require("./Node");
|
---|
| 8 | const Validators_1 = require("./Validators");
|
---|
| 9 | const Global_2 = require("./Global");
|
---|
| 10 | const PointerEvents = require("./PointerEvents");
|
---|
| 11 | var HAS_SHADOW = 'hasShadow';
|
---|
| 12 | var SHADOW_RGBA = 'shadowRGBA';
|
---|
| 13 | var patternImage = 'patternImage';
|
---|
| 14 | var linearGradient = 'linearGradient';
|
---|
| 15 | var radialGradient = 'radialGradient';
|
---|
| 16 | let dummyContext;
|
---|
| 17 | function getDummyContext() {
|
---|
| 18 | if (dummyContext) {
|
---|
| 19 | return dummyContext;
|
---|
| 20 | }
|
---|
| 21 | dummyContext = Util_1.Util.createCanvasElement().getContext('2d');
|
---|
| 22 | return dummyContext;
|
---|
| 23 | }
|
---|
| 24 | exports.shapes = {};
|
---|
| 25 | function _fillFunc(context) {
|
---|
| 26 | const fillRule = this.attrs.fillRule;
|
---|
| 27 | if (fillRule) {
|
---|
| 28 | context.fill(fillRule);
|
---|
| 29 | }
|
---|
| 30 | else {
|
---|
| 31 | context.fill();
|
---|
| 32 | }
|
---|
| 33 | }
|
---|
| 34 | function _strokeFunc(context) {
|
---|
| 35 | context.stroke();
|
---|
| 36 | }
|
---|
| 37 | function _fillFuncHit(context) {
|
---|
| 38 | const fillRule = this.attrs.fillRule;
|
---|
| 39 | if (fillRule) {
|
---|
| 40 | context.fill(fillRule);
|
---|
| 41 | }
|
---|
| 42 | else {
|
---|
| 43 | context.fill();
|
---|
| 44 | }
|
---|
| 45 | }
|
---|
| 46 | function _strokeFuncHit(context) {
|
---|
| 47 | context.stroke();
|
---|
| 48 | }
|
---|
| 49 | function _clearHasShadowCache() {
|
---|
| 50 | this._clearCache(HAS_SHADOW);
|
---|
| 51 | }
|
---|
| 52 | function _clearGetShadowRGBACache() {
|
---|
| 53 | this._clearCache(SHADOW_RGBA);
|
---|
| 54 | }
|
---|
| 55 | function _clearFillPatternCache() {
|
---|
| 56 | this._clearCache(patternImage);
|
---|
| 57 | }
|
---|
| 58 | function _clearLinearGradientCache() {
|
---|
| 59 | this._clearCache(linearGradient);
|
---|
| 60 | }
|
---|
| 61 | function _clearRadialGradientCache() {
|
---|
| 62 | this._clearCache(radialGradient);
|
---|
| 63 | }
|
---|
| 64 | class Shape extends Node_1.Node {
|
---|
| 65 | constructor(config) {
|
---|
| 66 | super(config);
|
---|
| 67 | let key;
|
---|
| 68 | while (true) {
|
---|
| 69 | key = Util_1.Util.getRandomColor();
|
---|
| 70 | if (key && !(key in exports.shapes)) {
|
---|
| 71 | break;
|
---|
| 72 | }
|
---|
| 73 | }
|
---|
| 74 | this.colorKey = key;
|
---|
| 75 | exports.shapes[key] = this;
|
---|
| 76 | }
|
---|
| 77 | getContext() {
|
---|
| 78 | Util_1.Util.warn('shape.getContext() method is deprecated. Please do not use it.');
|
---|
| 79 | return this.getLayer().getContext();
|
---|
| 80 | }
|
---|
| 81 | getCanvas() {
|
---|
| 82 | Util_1.Util.warn('shape.getCanvas() method is deprecated. Please do not use it.');
|
---|
| 83 | return this.getLayer().getCanvas();
|
---|
| 84 | }
|
---|
| 85 | getSceneFunc() {
|
---|
| 86 | return this.attrs.sceneFunc || this['_sceneFunc'];
|
---|
| 87 | }
|
---|
| 88 | getHitFunc() {
|
---|
| 89 | return this.attrs.hitFunc || this['_hitFunc'];
|
---|
| 90 | }
|
---|
| 91 | hasShadow() {
|
---|
| 92 | return this._getCache(HAS_SHADOW, this._hasShadow);
|
---|
| 93 | }
|
---|
| 94 | _hasShadow() {
|
---|
| 95 | return (this.shadowEnabled() &&
|
---|
| 96 | this.shadowOpacity() !== 0 &&
|
---|
| 97 | !!(this.shadowColor() ||
|
---|
| 98 | this.shadowBlur() ||
|
---|
| 99 | this.shadowOffsetX() ||
|
---|
| 100 | this.shadowOffsetY()));
|
---|
| 101 | }
|
---|
| 102 | _getFillPattern() {
|
---|
| 103 | return this._getCache(patternImage, this.__getFillPattern);
|
---|
| 104 | }
|
---|
| 105 | __getFillPattern() {
|
---|
| 106 | if (this.fillPatternImage()) {
|
---|
| 107 | var ctx = getDummyContext();
|
---|
| 108 | const pattern = ctx.createPattern(this.fillPatternImage(), this.fillPatternRepeat() || 'repeat');
|
---|
| 109 | if (pattern && pattern.setTransform) {
|
---|
| 110 | const tr = new Util_1.Transform();
|
---|
| 111 | tr.translate(this.fillPatternX(), this.fillPatternY());
|
---|
| 112 | tr.rotate(Global_1.Konva.getAngle(this.fillPatternRotation()));
|
---|
| 113 | tr.scale(this.fillPatternScaleX(), this.fillPatternScaleY());
|
---|
| 114 | tr.translate(-1 * this.fillPatternOffsetX(), -1 * this.fillPatternOffsetY());
|
---|
| 115 | const m = tr.getMatrix();
|
---|
| 116 | const matrix = typeof DOMMatrix === 'undefined'
|
---|
| 117 | ? {
|
---|
| 118 | a: m[0],
|
---|
| 119 | b: m[1],
|
---|
| 120 | c: m[2],
|
---|
| 121 | d: m[3],
|
---|
| 122 | e: m[4],
|
---|
| 123 | f: m[5],
|
---|
| 124 | }
|
---|
| 125 | : new DOMMatrix(m);
|
---|
| 126 | pattern.setTransform(matrix);
|
---|
| 127 | }
|
---|
| 128 | return pattern;
|
---|
| 129 | }
|
---|
| 130 | }
|
---|
| 131 | _getLinearGradient() {
|
---|
| 132 | return this._getCache(linearGradient, this.__getLinearGradient);
|
---|
| 133 | }
|
---|
| 134 | __getLinearGradient() {
|
---|
| 135 | var colorStops = this.fillLinearGradientColorStops();
|
---|
| 136 | if (colorStops) {
|
---|
| 137 | var ctx = getDummyContext();
|
---|
| 138 | var start = this.fillLinearGradientStartPoint();
|
---|
| 139 | var end = this.fillLinearGradientEndPoint();
|
---|
| 140 | var grd = ctx.createLinearGradient(start.x, start.y, end.x, end.y);
|
---|
| 141 | for (var n = 0; n < colorStops.length; n += 2) {
|
---|
| 142 | grd.addColorStop(colorStops[n], colorStops[n + 1]);
|
---|
| 143 | }
|
---|
| 144 | return grd;
|
---|
| 145 | }
|
---|
| 146 | }
|
---|
| 147 | _getRadialGradient() {
|
---|
| 148 | return this._getCache(radialGradient, this.__getRadialGradient);
|
---|
| 149 | }
|
---|
| 150 | __getRadialGradient() {
|
---|
| 151 | var colorStops = this.fillRadialGradientColorStops();
|
---|
| 152 | if (colorStops) {
|
---|
| 153 | var ctx = getDummyContext();
|
---|
| 154 | var start = this.fillRadialGradientStartPoint();
|
---|
| 155 | var end = this.fillRadialGradientEndPoint();
|
---|
| 156 | var grd = ctx.createRadialGradient(start.x, start.y, this.fillRadialGradientStartRadius(), end.x, end.y, this.fillRadialGradientEndRadius());
|
---|
| 157 | for (var n = 0; n < colorStops.length; n += 2) {
|
---|
| 158 | grd.addColorStop(colorStops[n], colorStops[n + 1]);
|
---|
| 159 | }
|
---|
| 160 | return grd;
|
---|
| 161 | }
|
---|
| 162 | }
|
---|
| 163 | getShadowRGBA() {
|
---|
| 164 | return this._getCache(SHADOW_RGBA, this._getShadowRGBA);
|
---|
| 165 | }
|
---|
| 166 | _getShadowRGBA() {
|
---|
| 167 | if (!this.hasShadow()) {
|
---|
| 168 | return;
|
---|
| 169 | }
|
---|
| 170 | var rgba = Util_1.Util.colorToRGBA(this.shadowColor());
|
---|
| 171 | if (rgba) {
|
---|
| 172 | return ('rgba(' +
|
---|
| 173 | rgba.r +
|
---|
| 174 | ',' +
|
---|
| 175 | rgba.g +
|
---|
| 176 | ',' +
|
---|
| 177 | rgba.b +
|
---|
| 178 | ',' +
|
---|
| 179 | rgba.a * (this.shadowOpacity() || 1) +
|
---|
| 180 | ')');
|
---|
| 181 | }
|
---|
| 182 | }
|
---|
| 183 | hasFill() {
|
---|
| 184 | return this._calculate('hasFill', [
|
---|
| 185 | 'fillEnabled',
|
---|
| 186 | 'fill',
|
---|
| 187 | 'fillPatternImage',
|
---|
| 188 | 'fillLinearGradientColorStops',
|
---|
| 189 | 'fillRadialGradientColorStops',
|
---|
| 190 | ], () => {
|
---|
| 191 | return (this.fillEnabled() &&
|
---|
| 192 | !!(this.fill() ||
|
---|
| 193 | this.fillPatternImage() ||
|
---|
| 194 | this.fillLinearGradientColorStops() ||
|
---|
| 195 | this.fillRadialGradientColorStops()));
|
---|
| 196 | });
|
---|
| 197 | }
|
---|
| 198 | hasStroke() {
|
---|
| 199 | return this._calculate('hasStroke', [
|
---|
| 200 | 'strokeEnabled',
|
---|
| 201 | 'strokeWidth',
|
---|
| 202 | 'stroke',
|
---|
| 203 | 'strokeLinearGradientColorStops',
|
---|
| 204 | ], () => {
|
---|
| 205 | return (this.strokeEnabled() &&
|
---|
| 206 | this.strokeWidth() &&
|
---|
| 207 | !!(this.stroke() || this.strokeLinearGradientColorStops()));
|
---|
| 208 | });
|
---|
| 209 | }
|
---|
| 210 | hasHitStroke() {
|
---|
| 211 | const width = this.hitStrokeWidth();
|
---|
| 212 | if (width === 'auto') {
|
---|
| 213 | return this.hasStroke();
|
---|
| 214 | }
|
---|
| 215 | return this.strokeEnabled() && !!width;
|
---|
| 216 | }
|
---|
| 217 | intersects(point) {
|
---|
| 218 | var stage = this.getStage();
|
---|
| 219 | if (!stage) {
|
---|
| 220 | return false;
|
---|
| 221 | }
|
---|
| 222 | const bufferHitCanvas = stage.bufferHitCanvas;
|
---|
| 223 | bufferHitCanvas.getContext().clear();
|
---|
| 224 | this.drawHit(bufferHitCanvas, undefined, true);
|
---|
| 225 | const p = bufferHitCanvas.context.getImageData(Math.round(point.x), Math.round(point.y), 1, 1).data;
|
---|
| 226 | return p[3] > 0;
|
---|
| 227 | }
|
---|
| 228 | destroy() {
|
---|
| 229 | Node_1.Node.prototype.destroy.call(this);
|
---|
| 230 | delete exports.shapes[this.colorKey];
|
---|
| 231 | delete this.colorKey;
|
---|
| 232 | return this;
|
---|
| 233 | }
|
---|
| 234 | _useBufferCanvas(forceFill) {
|
---|
| 235 | var _a;
|
---|
| 236 | const perfectDrawEnabled = (_a = this.attrs.perfectDrawEnabled) !== null && _a !== void 0 ? _a : true;
|
---|
| 237 | if (!perfectDrawEnabled) {
|
---|
| 238 | return false;
|
---|
| 239 | }
|
---|
| 240 | const hasFill = forceFill || this.hasFill();
|
---|
| 241 | const hasStroke = this.hasStroke();
|
---|
| 242 | const isTransparent = this.getAbsoluteOpacity() !== 1;
|
---|
| 243 | if (hasFill && hasStroke && isTransparent) {
|
---|
| 244 | return true;
|
---|
| 245 | }
|
---|
| 246 | const hasShadow = this.hasShadow();
|
---|
| 247 | const strokeForShadow = this.shadowForStrokeEnabled();
|
---|
| 248 | if (hasFill && hasStroke && hasShadow && strokeForShadow) {
|
---|
| 249 | return true;
|
---|
| 250 | }
|
---|
| 251 | return false;
|
---|
| 252 | }
|
---|
| 253 | setStrokeHitEnabled(val) {
|
---|
| 254 | Util_1.Util.warn('strokeHitEnabled property is deprecated. Please use hitStrokeWidth instead.');
|
---|
| 255 | if (val) {
|
---|
| 256 | this.hitStrokeWidth('auto');
|
---|
| 257 | }
|
---|
| 258 | else {
|
---|
| 259 | this.hitStrokeWidth(0);
|
---|
| 260 | }
|
---|
| 261 | }
|
---|
| 262 | getStrokeHitEnabled() {
|
---|
| 263 | if (this.hitStrokeWidth() === 0) {
|
---|
| 264 | return false;
|
---|
| 265 | }
|
---|
| 266 | else {
|
---|
| 267 | return true;
|
---|
| 268 | }
|
---|
| 269 | }
|
---|
| 270 | getSelfRect() {
|
---|
| 271 | var size = this.size();
|
---|
| 272 | return {
|
---|
| 273 | x: this._centroid ? -size.width / 2 : 0,
|
---|
| 274 | y: this._centroid ? -size.height / 2 : 0,
|
---|
| 275 | width: size.width,
|
---|
| 276 | height: size.height,
|
---|
| 277 | };
|
---|
| 278 | }
|
---|
| 279 | getClientRect(config = {}) {
|
---|
| 280 | let hasCachedParent = false;
|
---|
| 281 | let parent = this.getParent();
|
---|
| 282 | while (parent) {
|
---|
| 283 | if (parent.isCached()) {
|
---|
| 284 | hasCachedParent = true;
|
---|
| 285 | break;
|
---|
| 286 | }
|
---|
| 287 | parent = parent.getParent();
|
---|
| 288 | }
|
---|
| 289 | const skipTransform = config.skipTransform;
|
---|
| 290 | const relativeTo = config.relativeTo || (hasCachedParent && this.getStage()) || undefined;
|
---|
| 291 | const fillRect = this.getSelfRect();
|
---|
| 292 | const applyStroke = !config.skipStroke && this.hasStroke();
|
---|
| 293 | const strokeWidth = (applyStroke && this.strokeWidth()) || 0;
|
---|
| 294 | const fillAndStrokeWidth = fillRect.width + strokeWidth;
|
---|
| 295 | const fillAndStrokeHeight = fillRect.height + strokeWidth;
|
---|
| 296 | const applyShadow = !config.skipShadow && this.hasShadow();
|
---|
| 297 | const shadowOffsetX = applyShadow ? this.shadowOffsetX() : 0;
|
---|
| 298 | const shadowOffsetY = applyShadow ? this.shadowOffsetY() : 0;
|
---|
| 299 | const preWidth = fillAndStrokeWidth + Math.abs(shadowOffsetX);
|
---|
| 300 | const preHeight = fillAndStrokeHeight + Math.abs(shadowOffsetY);
|
---|
| 301 | const blurRadius = (applyShadow && this.shadowBlur()) || 0;
|
---|
| 302 | const width = preWidth + blurRadius * 2;
|
---|
| 303 | const height = preHeight + blurRadius * 2;
|
---|
| 304 | const rect = {
|
---|
| 305 | width: width,
|
---|
| 306 | height: height,
|
---|
| 307 | x: -(strokeWidth / 2 + blurRadius) +
|
---|
| 308 | Math.min(shadowOffsetX, 0) +
|
---|
| 309 | fillRect.x,
|
---|
| 310 | y: -(strokeWidth / 2 + blurRadius) +
|
---|
| 311 | Math.min(shadowOffsetY, 0) +
|
---|
| 312 | fillRect.y,
|
---|
| 313 | };
|
---|
| 314 | if (!skipTransform) {
|
---|
| 315 | return this._transformedRect(rect, relativeTo);
|
---|
| 316 | }
|
---|
| 317 | return rect;
|
---|
| 318 | }
|
---|
| 319 | drawScene(can, top, bufferCanvas) {
|
---|
| 320 | var layer = this.getLayer();
|
---|
| 321 | var canvas = can || layer.getCanvas(), context = canvas.getContext(), cachedCanvas = this._getCanvasCache(), drawFunc = this.getSceneFunc(), hasShadow = this.hasShadow(), stage, bufferContext;
|
---|
| 322 | var skipBuffer = canvas.isCache;
|
---|
| 323 | var cachingSelf = top === this;
|
---|
| 324 | if (!this.isVisible() && !cachingSelf) {
|
---|
| 325 | return this;
|
---|
| 326 | }
|
---|
| 327 | if (cachedCanvas) {
|
---|
| 328 | context.save();
|
---|
| 329 | var m = this.getAbsoluteTransform(top).getMatrix();
|
---|
| 330 | context.transform(m[0], m[1], m[2], m[3], m[4], m[5]);
|
---|
| 331 | this._drawCachedSceneCanvas(context);
|
---|
| 332 | context.restore();
|
---|
| 333 | return this;
|
---|
| 334 | }
|
---|
| 335 | if (!drawFunc) {
|
---|
| 336 | return this;
|
---|
| 337 | }
|
---|
| 338 | context.save();
|
---|
| 339 | if (this._useBufferCanvas() && !skipBuffer) {
|
---|
| 340 | stage = this.getStage();
|
---|
| 341 | const bc = bufferCanvas || stage.bufferCanvas;
|
---|
| 342 | bufferContext = bc.getContext();
|
---|
| 343 | bufferContext.clear();
|
---|
| 344 | bufferContext.save();
|
---|
| 345 | bufferContext._applyLineJoin(this);
|
---|
| 346 | var o = this.getAbsoluteTransform(top).getMatrix();
|
---|
| 347 | bufferContext.transform(o[0], o[1], o[2], o[3], o[4], o[5]);
|
---|
| 348 | drawFunc.call(this, bufferContext, this);
|
---|
| 349 | bufferContext.restore();
|
---|
| 350 | var ratio = bc.pixelRatio;
|
---|
| 351 | if (hasShadow) {
|
---|
| 352 | context._applyShadow(this);
|
---|
| 353 | }
|
---|
| 354 | context._applyOpacity(this);
|
---|
| 355 | context._applyGlobalCompositeOperation(this);
|
---|
| 356 | context.drawImage(bc._canvas, 0, 0, bc.width / ratio, bc.height / ratio);
|
---|
| 357 | }
|
---|
| 358 | else {
|
---|
| 359 | context._applyLineJoin(this);
|
---|
| 360 | if (!cachingSelf) {
|
---|
| 361 | var o = this.getAbsoluteTransform(top).getMatrix();
|
---|
| 362 | context.transform(o[0], o[1], o[2], o[3], o[4], o[5]);
|
---|
| 363 | context._applyOpacity(this);
|
---|
| 364 | context._applyGlobalCompositeOperation(this);
|
---|
| 365 | }
|
---|
| 366 | if (hasShadow) {
|
---|
| 367 | context._applyShadow(this);
|
---|
| 368 | }
|
---|
| 369 | drawFunc.call(this, context, this);
|
---|
| 370 | }
|
---|
| 371 | context.restore();
|
---|
| 372 | return this;
|
---|
| 373 | }
|
---|
| 374 | drawHit(can, top, skipDragCheck = false) {
|
---|
| 375 | if (!this.shouldDrawHit(top, skipDragCheck)) {
|
---|
| 376 | return this;
|
---|
| 377 | }
|
---|
| 378 | var layer = this.getLayer(), canvas = can || layer.hitCanvas, context = canvas && canvas.getContext(), drawFunc = this.hitFunc() || this.sceneFunc(), cachedCanvas = this._getCanvasCache(), cachedHitCanvas = cachedCanvas && cachedCanvas.hit;
|
---|
| 379 | if (!this.colorKey) {
|
---|
| 380 | Util_1.Util.warn('Looks like your canvas has a destroyed shape in it. Do not reuse shape after you destroyed it. If you want to reuse shape you should call remove() instead of destroy()');
|
---|
| 381 | }
|
---|
| 382 | if (cachedHitCanvas) {
|
---|
| 383 | context.save();
|
---|
| 384 | var m = this.getAbsoluteTransform(top).getMatrix();
|
---|
| 385 | context.transform(m[0], m[1], m[2], m[3], m[4], m[5]);
|
---|
| 386 | this._drawCachedHitCanvas(context);
|
---|
| 387 | context.restore();
|
---|
| 388 | return this;
|
---|
| 389 | }
|
---|
| 390 | if (!drawFunc) {
|
---|
| 391 | return this;
|
---|
| 392 | }
|
---|
| 393 | context.save();
|
---|
| 394 | context._applyLineJoin(this);
|
---|
| 395 | const selfCache = this === top;
|
---|
| 396 | if (!selfCache) {
|
---|
| 397 | var o = this.getAbsoluteTransform(top).getMatrix();
|
---|
| 398 | context.transform(o[0], o[1], o[2], o[3], o[4], o[5]);
|
---|
| 399 | }
|
---|
| 400 | drawFunc.call(this, context, this);
|
---|
| 401 | context.restore();
|
---|
| 402 | return this;
|
---|
| 403 | }
|
---|
| 404 | drawHitFromCache(alphaThreshold = 0) {
|
---|
| 405 | var cachedCanvas = this._getCanvasCache(), sceneCanvas = this._getCachedSceneCanvas(), hitCanvas = cachedCanvas.hit, hitContext = hitCanvas.getContext(), hitWidth = hitCanvas.getWidth(), hitHeight = hitCanvas.getHeight(), hitImageData, hitData, len, rgbColorKey, i, alpha;
|
---|
| 406 | hitContext.clear();
|
---|
| 407 | hitContext.drawImage(sceneCanvas._canvas, 0, 0, hitWidth, hitHeight);
|
---|
| 408 | try {
|
---|
| 409 | hitImageData = hitContext.getImageData(0, 0, hitWidth, hitHeight);
|
---|
| 410 | hitData = hitImageData.data;
|
---|
| 411 | len = hitData.length;
|
---|
| 412 | rgbColorKey = Util_1.Util._hexToRgb(this.colorKey);
|
---|
| 413 | for (i = 0; i < len; i += 4) {
|
---|
| 414 | alpha = hitData[i + 3];
|
---|
| 415 | if (alpha > alphaThreshold) {
|
---|
| 416 | hitData[i] = rgbColorKey.r;
|
---|
| 417 | hitData[i + 1] = rgbColorKey.g;
|
---|
| 418 | hitData[i + 2] = rgbColorKey.b;
|
---|
| 419 | hitData[i + 3] = 255;
|
---|
| 420 | }
|
---|
| 421 | else {
|
---|
| 422 | hitData[i + 3] = 0;
|
---|
| 423 | }
|
---|
| 424 | }
|
---|
| 425 | hitContext.putImageData(hitImageData, 0, 0);
|
---|
| 426 | }
|
---|
| 427 | catch (e) {
|
---|
| 428 | Util_1.Util.error('Unable to draw hit graph from cached scene canvas. ' + e.message);
|
---|
| 429 | }
|
---|
| 430 | return this;
|
---|
| 431 | }
|
---|
| 432 | hasPointerCapture(pointerId) {
|
---|
| 433 | return PointerEvents.hasPointerCapture(pointerId, this);
|
---|
| 434 | }
|
---|
| 435 | setPointerCapture(pointerId) {
|
---|
| 436 | PointerEvents.setPointerCapture(pointerId, this);
|
---|
| 437 | }
|
---|
| 438 | releaseCapture(pointerId) {
|
---|
| 439 | PointerEvents.releaseCapture(pointerId, this);
|
---|
| 440 | }
|
---|
| 441 | }
|
---|
| 442 | exports.Shape = Shape;
|
---|
| 443 | Shape.prototype._fillFunc = _fillFunc;
|
---|
| 444 | Shape.prototype._strokeFunc = _strokeFunc;
|
---|
| 445 | Shape.prototype._fillFuncHit = _fillFuncHit;
|
---|
| 446 | Shape.prototype._strokeFuncHit = _strokeFuncHit;
|
---|
| 447 | Shape.prototype._centroid = false;
|
---|
| 448 | Shape.prototype.nodeType = 'Shape';
|
---|
| 449 | (0, Global_2._registerNode)(Shape);
|
---|
| 450 | Shape.prototype.eventListeners = {};
|
---|
| 451 | Shape.prototype.on.call(Shape.prototype, 'shadowColorChange.konva shadowBlurChange.konva shadowOffsetChange.konva shadowOpacityChange.konva shadowEnabledChange.konva', _clearHasShadowCache);
|
---|
| 452 | Shape.prototype.on.call(Shape.prototype, 'shadowColorChange.konva shadowOpacityChange.konva shadowEnabledChange.konva', _clearGetShadowRGBACache);
|
---|
| 453 | Shape.prototype.on.call(Shape.prototype, 'fillPriorityChange.konva fillPatternImageChange.konva fillPatternRepeatChange.konva fillPatternScaleXChange.konva fillPatternScaleYChange.konva fillPatternOffsetXChange.konva fillPatternOffsetYChange.konva fillPatternXChange.konva fillPatternYChange.konva fillPatternRotationChange.konva', _clearFillPatternCache);
|
---|
| 454 | Shape.prototype.on.call(Shape.prototype, 'fillPriorityChange.konva fillLinearGradientColorStopsChange.konva fillLinearGradientStartPointXChange.konva fillLinearGradientStartPointYChange.konva fillLinearGradientEndPointXChange.konva fillLinearGradientEndPointYChange.konva', _clearLinearGradientCache);
|
---|
| 455 | Shape.prototype.on.call(Shape.prototype, 'fillPriorityChange.konva fillRadialGradientColorStopsChange.konva fillRadialGradientStartPointXChange.konva fillRadialGradientStartPointYChange.konva fillRadialGradientEndPointXChange.konva fillRadialGradientEndPointYChange.konva fillRadialGradientStartRadiusChange.konva fillRadialGradientEndRadiusChange.konva', _clearRadialGradientCache);
|
---|
| 456 | Factory_1.Factory.addGetterSetter(Shape, 'stroke', undefined, (0, Validators_1.getStringOrGradientValidator)());
|
---|
| 457 | Factory_1.Factory.addGetterSetter(Shape, 'strokeWidth', 2, (0, Validators_1.getNumberValidator)());
|
---|
| 458 | Factory_1.Factory.addGetterSetter(Shape, 'fillAfterStrokeEnabled', false);
|
---|
| 459 | Factory_1.Factory.addGetterSetter(Shape, 'hitStrokeWidth', 'auto', (0, Validators_1.getNumberOrAutoValidator)());
|
---|
| 460 | Factory_1.Factory.addGetterSetter(Shape, 'strokeHitEnabled', true, (0, Validators_1.getBooleanValidator)());
|
---|
| 461 | Factory_1.Factory.addGetterSetter(Shape, 'perfectDrawEnabled', true, (0, Validators_1.getBooleanValidator)());
|
---|
| 462 | Factory_1.Factory.addGetterSetter(Shape, 'shadowForStrokeEnabled', true, (0, Validators_1.getBooleanValidator)());
|
---|
| 463 | Factory_1.Factory.addGetterSetter(Shape, 'lineJoin');
|
---|
| 464 | Factory_1.Factory.addGetterSetter(Shape, 'lineCap');
|
---|
| 465 | Factory_1.Factory.addGetterSetter(Shape, 'sceneFunc');
|
---|
| 466 | Factory_1.Factory.addGetterSetter(Shape, 'hitFunc');
|
---|
| 467 | Factory_1.Factory.addGetterSetter(Shape, 'dash');
|
---|
| 468 | Factory_1.Factory.addGetterSetter(Shape, 'dashOffset', 0, (0, Validators_1.getNumberValidator)());
|
---|
| 469 | Factory_1.Factory.addGetterSetter(Shape, 'shadowColor', undefined, (0, Validators_1.getStringValidator)());
|
---|
| 470 | Factory_1.Factory.addGetterSetter(Shape, 'shadowBlur', 0, (0, Validators_1.getNumberValidator)());
|
---|
| 471 | Factory_1.Factory.addGetterSetter(Shape, 'shadowOpacity', 1, (0, Validators_1.getNumberValidator)());
|
---|
| 472 | Factory_1.Factory.addComponentsGetterSetter(Shape, 'shadowOffset', ['x', 'y']);
|
---|
| 473 | Factory_1.Factory.addGetterSetter(Shape, 'shadowOffsetX', 0, (0, Validators_1.getNumberValidator)());
|
---|
| 474 | Factory_1.Factory.addGetterSetter(Shape, 'shadowOffsetY', 0, (0, Validators_1.getNumberValidator)());
|
---|
| 475 | Factory_1.Factory.addGetterSetter(Shape, 'fillPatternImage');
|
---|
| 476 | Factory_1.Factory.addGetterSetter(Shape, 'fill', undefined, (0, Validators_1.getStringOrGradientValidator)());
|
---|
| 477 | Factory_1.Factory.addGetterSetter(Shape, 'fillPatternX', 0, (0, Validators_1.getNumberValidator)());
|
---|
| 478 | Factory_1.Factory.addGetterSetter(Shape, 'fillPatternY', 0, (0, Validators_1.getNumberValidator)());
|
---|
| 479 | Factory_1.Factory.addGetterSetter(Shape, 'fillLinearGradientColorStops');
|
---|
| 480 | Factory_1.Factory.addGetterSetter(Shape, 'strokeLinearGradientColorStops');
|
---|
| 481 | Factory_1.Factory.addGetterSetter(Shape, 'fillRadialGradientStartRadius', 0);
|
---|
| 482 | Factory_1.Factory.addGetterSetter(Shape, 'fillRadialGradientEndRadius', 0);
|
---|
| 483 | Factory_1.Factory.addGetterSetter(Shape, 'fillRadialGradientColorStops');
|
---|
| 484 | Factory_1.Factory.addGetterSetter(Shape, 'fillPatternRepeat', 'repeat');
|
---|
| 485 | Factory_1.Factory.addGetterSetter(Shape, 'fillEnabled', true);
|
---|
| 486 | Factory_1.Factory.addGetterSetter(Shape, 'strokeEnabled', true);
|
---|
| 487 | Factory_1.Factory.addGetterSetter(Shape, 'shadowEnabled', true);
|
---|
| 488 | Factory_1.Factory.addGetterSetter(Shape, 'dashEnabled', true);
|
---|
| 489 | Factory_1.Factory.addGetterSetter(Shape, 'strokeScaleEnabled', true);
|
---|
| 490 | Factory_1.Factory.addGetterSetter(Shape, 'fillPriority', 'color');
|
---|
| 491 | Factory_1.Factory.addComponentsGetterSetter(Shape, 'fillPatternOffset', ['x', 'y']);
|
---|
| 492 | Factory_1.Factory.addGetterSetter(Shape, 'fillPatternOffsetX', 0, (0, Validators_1.getNumberValidator)());
|
---|
| 493 | Factory_1.Factory.addGetterSetter(Shape, 'fillPatternOffsetY', 0, (0, Validators_1.getNumberValidator)());
|
---|
| 494 | Factory_1.Factory.addComponentsGetterSetter(Shape, 'fillPatternScale', ['x', 'y']);
|
---|
| 495 | Factory_1.Factory.addGetterSetter(Shape, 'fillPatternScaleX', 1, (0, Validators_1.getNumberValidator)());
|
---|
| 496 | Factory_1.Factory.addGetterSetter(Shape, 'fillPatternScaleY', 1, (0, Validators_1.getNumberValidator)());
|
---|
| 497 | Factory_1.Factory.addComponentsGetterSetter(Shape, 'fillLinearGradientStartPoint', [
|
---|
| 498 | 'x',
|
---|
| 499 | 'y',
|
---|
| 500 | ]);
|
---|
| 501 | Factory_1.Factory.addComponentsGetterSetter(Shape, 'strokeLinearGradientStartPoint', [
|
---|
| 502 | 'x',
|
---|
| 503 | 'y',
|
---|
| 504 | ]);
|
---|
| 505 | Factory_1.Factory.addGetterSetter(Shape, 'fillLinearGradientStartPointX', 0);
|
---|
| 506 | Factory_1.Factory.addGetterSetter(Shape, 'strokeLinearGradientStartPointX', 0);
|
---|
| 507 | Factory_1.Factory.addGetterSetter(Shape, 'fillLinearGradientStartPointY', 0);
|
---|
| 508 | Factory_1.Factory.addGetterSetter(Shape, 'strokeLinearGradientStartPointY', 0);
|
---|
| 509 | Factory_1.Factory.addComponentsGetterSetter(Shape, 'fillLinearGradientEndPoint', [
|
---|
| 510 | 'x',
|
---|
| 511 | 'y',
|
---|
| 512 | ]);
|
---|
| 513 | Factory_1.Factory.addComponentsGetterSetter(Shape, 'strokeLinearGradientEndPoint', [
|
---|
| 514 | 'x',
|
---|
| 515 | 'y',
|
---|
| 516 | ]);
|
---|
| 517 | Factory_1.Factory.addGetterSetter(Shape, 'fillLinearGradientEndPointX', 0);
|
---|
| 518 | Factory_1.Factory.addGetterSetter(Shape, 'strokeLinearGradientEndPointX', 0);
|
---|
| 519 | Factory_1.Factory.addGetterSetter(Shape, 'fillLinearGradientEndPointY', 0);
|
---|
| 520 | Factory_1.Factory.addGetterSetter(Shape, 'strokeLinearGradientEndPointY', 0);
|
---|
| 521 | Factory_1.Factory.addComponentsGetterSetter(Shape, 'fillRadialGradientStartPoint', [
|
---|
| 522 | 'x',
|
---|
| 523 | 'y',
|
---|
| 524 | ]);
|
---|
| 525 | Factory_1.Factory.addGetterSetter(Shape, 'fillRadialGradientStartPointX', 0);
|
---|
| 526 | Factory_1.Factory.addGetterSetter(Shape, 'fillRadialGradientStartPointY', 0);
|
---|
| 527 | Factory_1.Factory.addComponentsGetterSetter(Shape, 'fillRadialGradientEndPoint', [
|
---|
| 528 | 'x',
|
---|
| 529 | 'y',
|
---|
| 530 | ]);
|
---|
| 531 | Factory_1.Factory.addGetterSetter(Shape, 'fillRadialGradientEndPointX', 0);
|
---|
| 532 | Factory_1.Factory.addGetterSetter(Shape, 'fillRadialGradientEndPointY', 0);
|
---|
| 533 | Factory_1.Factory.addGetterSetter(Shape, 'fillPatternRotation', 0);
|
---|
| 534 | Factory_1.Factory.addGetterSetter(Shape, 'fillRule', undefined, (0, Validators_1.getStringValidator)());
|
---|
| 535 | Factory_1.Factory.backCompat(Shape, {
|
---|
| 536 | dashArray: 'dash',
|
---|
| 537 | getDashArray: 'getDash',
|
---|
| 538 | setDashArray: 'getDash',
|
---|
| 539 | drawFunc: 'sceneFunc',
|
---|
| 540 | getDrawFunc: 'getSceneFunc',
|
---|
| 541 | setDrawFunc: 'setSceneFunc',
|
---|
| 542 | drawHitFunc: 'hitFunc',
|
---|
| 543 | getDrawHitFunc: 'getHitFunc',
|
---|
| 544 | setDrawHitFunc: 'setHitFunc',
|
---|
| 545 | });
|
---|