import { Property } from '@nativescript/core';
import { Gradients } from './Gradients';
const startProperty = new Property({
    name: 'start',
    valueChanged(target, oldValue, newValue) {
        target.invalidate();
    },
});
const endProperty = new Property({
    name: 'end',
    valueChanged(target, oldValue, newValue) {
        target.invalidate();
    },
});
const colorsProperty = new Property({
    name: 'colors',
    valueChanged(target, oldValue, newValue) {
        target.invalidate();
    },
});
export class LinearGradient extends Gradients {
    _getColor() {
        const ctx = this._canvas.getContext('2d');
        const gradient = ctx.createLinearGradient(this.start.x, this.start.y, this.end.x, this.end.y);
        for (let i = 0; i < this.colors.length; i++) {
            gradient.addColorStop(i, this.colors[i]);
        }
        return gradient;
    }
    draw() {
        const ctx = this._canvas.getContext('2d');
        const gradient = this._getColor();
        if (this._getPaintStyle() === 'stroke') {
            ctx.strokeStyle = gradient;
        }
        else {
            ctx.fillStyle = gradient;
        }
    }
}
startProperty.register(LinearGradient);
endProperty.register(LinearGradient);
colorsProperty.register(LinearGradient);
//# sourceMappingURL=LinearGradient.js.map