Skip to content
Snippets Groups Projects
fabric.min.js 361 KiB
Newer Older
Carsten  Rose's avatar
Carsten Rose committed
var fabric = fabric || {version: "1.7.17"};
"undefined" != typeof exports && (exports.fabric = fabric), "undefined" != typeof document && "undefined" != typeof window ? (fabric.document = document, fabric.window = window, window.fabric = fabric) : (fabric.document = require("jsdom").jsdom(decodeURIComponent("%3C!DOCTYPE%20html%3E%3Chtml%3E%3Chead%3E%3C%2Fhead%3E%3Cbody%3E%3C%2Fbody%3E%3C%2Fhtml%3E")), fabric.document.createWindow ? fabric.window = fabric.document.createWindow() : fabric.window = fabric.document.parentWindow), fabric.isTouchSupported = "ontouchstart"in fabric.document.documentElement, fabric.isLikelyNode = "undefined" != typeof Buffer && "undefined" == typeof window, fabric.SHARED_ATTRIBUTES = ["display", "transform", "fill", "fill-opacity", "fill-rule", "opacity", "stroke", "stroke-dasharray", "stroke-linecap", "stroke-linejoin", "stroke-miterlimit", "stroke-opacity", "stroke-width", "id"], fabric.DPI = 96, fabric.reNum = "(?:[-+]?(?:\\d+|\\d*\\.\\d+)(?:e[-+]?\\d+)?)", fabric.fontPaths = {}, fabric.iMatrix = [1, 0, 0, 1, 0, 0], fabric.canvasModule = "canvas", fabric.perfLimitSizeTotal = 2097152, fabric.maxCacheSideLimit = 4096, fabric.minCacheSideLimit = 256, fabric.charWidthsCache = {}, fabric.devicePixelRatio = fabric.window.devicePixelRatio || fabric.window.webkitDevicePixelRatio || fabric.window.mozDevicePixelRatio || 1, function () {
    function t(t, e) {
        if (this.__eventListeners[t]) {
            var i = this.__eventListeners[t];
            e ? i[i.indexOf(e)] = !1 : fabric.util.array.fill(i, !1)
        }
    }

    function e(t, e) {
        if (this.__eventListeners || (this.__eventListeners = {}), 1 === arguments.length)for (var i in t)this.on(i, t[i]); else this.__eventListeners[t] || (this.__eventListeners[t] = []), this.__eventListeners[t].push(e);
        return this
    }

    function i(e, i) {
        if (this.__eventListeners) {
            if (0 === arguments.length)for (e in this.__eventListeners)t.call(this, e); else if (1 === arguments.length && "object" == typeof arguments[0])for (var r in e)t.call(this, r, e[r]); else t.call(this, e, i);
            return this
        }
    }

    function r(t, e) {
        if (this.__eventListeners) {
            var i = this.__eventListeners[t];
            if (i) {
                for (var r = 0, n = i.length; r < n; r++)i[r] && i[r].call(this, e || {});
                return this.__eventListeners[t] = i.filter(function (t) {
                    return t !== !1
                }), this
            }
        }
    }

    fabric.Observable = {observe: e, stopObserving: i, fire: r, on: e, off: i, trigger: r}
}(), fabric.Collection = {
    _objects: [], add: function () {
        if (this._objects.push.apply(this._objects, arguments), this._onObjectAdded)for (var t = 0, e = arguments.length; t < e; t++)this._onObjectAdded(arguments[t]);
        return this.renderOnAddRemove && this.renderAll(), this
    }, insertAt: function (t, e, i) {
        var r = this.getObjects();
        return i ? r[e] = t : r.splice(e, 0, t), this._onObjectAdded && this._onObjectAdded(t), this.renderOnAddRemove && this.renderAll(), this
    }, remove: function () {
        for (var t, e = this.getObjects(), i = !1, r = 0, n = arguments.length; r < n; r++)t = e.indexOf(arguments[r]), t !== -1 && (i = !0, e.splice(t, 1), this._onObjectRemoved && this._onObjectRemoved(arguments[r]));
        return this.renderOnAddRemove && i && this.renderAll(), this
    }, forEachObject: function (t, e) {
        for (var i = this.getObjects(), r = 0, n = i.length; r < n; r++)t.call(e, i[r], r, i);
        return this
    }, getObjects: function (t) {
        return "undefined" == typeof t ? this._objects : this._objects.filter(function (e) {
            return e.type === t
        })
    }, item: function (t) {
        return this.getObjects()[t]
    }, isEmpty: function () {
        return 0 === this.getObjects().length
    }, size: function () {
        return this.getObjects().length
    }, contains: function (t) {
        return this.getObjects().indexOf(t) > -1
    }, complexity: function () {
        return this.getObjects().reduce(function (t, e) {
            return t += e.complexity ? e.complexity() : 0
        }, 0)
    }
}, fabric.CommonMethods = {
    _setOptions: function (t) {
        for (var e in t)this.set(e, t[e])
    }, _initGradient: function (t, e) {
        !t || !t.colorStops || t instanceof fabric.Gradient || this.set(e, new fabric.Gradient(t))
    }, _initPattern: function (t, e, i) {
        !t || !t.source || t instanceof fabric.Pattern ? i && i() : this.set(e, new fabric.Pattern(t, i))
    }, _initClipping: function (t) {
        if (t.clipTo && "string" == typeof t.clipTo) {
            var e = fabric.util.getFunctionBody(t.clipTo);
            "undefined" != typeof e && (this.clipTo = new Function("ctx", e))
        }
    }, _setObject: function (t) {
        for (var e in t)this._set(e, t[e])
    }, set: function (t, e) {
        return "object" == typeof t ? this._setObject(t) : "function" == typeof e && "clipTo" !== t ? this._set(t, e(this.get(t))) : this._set(t, e), this
    }, _set: function (t, e) {
        this[t] = e
    }, toggle: function (t) {
        var e = this.get(t);
        return "boolean" == typeof e && this.set(t, !e), this
    }, get: function (t) {
        return this[t]
    }
}, function (t) {
    var e = Math.sqrt, i = Math.atan2, r = Math.pow, n = Math.abs, s = Math.PI / 180;
    fabric.util = {
        removeFromArray: function (t, e) {
            var i = t.indexOf(e);
            return i !== -1 && t.splice(i, 1), t
        }, getRandomInt: function (t, e) {
            return Math.floor(Math.random() * (e - t + 1)) + t
        }, degreesToRadians: function (t) {
            return t * s
        }, radiansToDegrees: function (t) {
            return t / s
        }, rotatePoint: function (t, e, i) {
            t.subtractEquals(e);
            var r = fabric.util.rotateVector(t, i);
            return new fabric.Point(r.x, r.y).addEquals(e)
        }, rotateVector: function (t, e) {
            var i = Math.sin(e), r = Math.cos(e), n = t.x * r - t.y * i, s = t.x * i + t.y * r;
            return {x: n, y: s}
        }, transformPoint: function (t, e, i) {
            return i ? new fabric.Point(e[0] * t.x + e[2] * t.y, e[1] * t.x + e[3] * t.y) : new fabric.Point(e[0] * t.x + e[2] * t.y + e[4], e[1] * t.x + e[3] * t.y + e[5])
        }, makeBoundingBoxFromPoints: function (t) {
            var e = [t[0].x, t[1].x, t[2].x, t[3].x], i = fabric.util.array.min(e), r = fabric.util.array.max(e), n = Math.abs(i - r), s = [t[0].y, t[1].y, t[2].y, t[3].y], o = fabric.util.array.min(s), a = fabric.util.array.max(s), h = Math.abs(o - a);
            return {left: i, top: o, width: n, height: h}
        }, invertTransform: function (t) {
            var e = 1 / (t[0] * t[3] - t[1] * t[2]), i = [e * t[3], -e * t[1], -e * t[2], e * t[0]], r = fabric.util.transformPoint({
                x: t[4],
                y: t[5]
            }, i, !0);
            return i[4] = -r.x, i[5] = -r.y, i
        }, toFixed: function (t, e) {
            return parseFloat(Number(t).toFixed(e))
        }, parseUnit: function (t, e) {
            var i = /\D{0,2}$/.exec(t), r = parseFloat(t);
            switch (e || (e = fabric.Text.DEFAULT_SVG_FONT_SIZE), i[0]) {
                case"mm":
                    return r * fabric.DPI / 25.4;
                case"cm":
                    return r * fabric.DPI / 2.54;
                case"in":
                    return r * fabric.DPI;
                case"pt":
                    return r * fabric.DPI / 72;
                case"pc":
                    return r * fabric.DPI / 72 * 12;
                case"em":
                    return r * e;
                default:
                    return r
            }
        }, falseFunction: function () {
            return !1
        }, getKlass: function (t, e) {
            return t = fabric.util.string.camelize(t.charAt(0).toUpperCase() + t.slice(1)), fabric.util.resolveNamespace(e)[t]
        }, resolveNamespace: function (e) {
            if (!e)return fabric;
            var i, r = e.split("."), n = r.length, s = t || fabric.window;
            for (i = 0; i < n; ++i)s = s[r[i]];
            return s
        }, loadImage: function (t, e, i, r) {
            if (!t)return void(e && e.call(i, t));
            var n = fabric.util.createImage();
            n.onload = function () {
                e && e.call(i, n), n = n.onload = n.onerror = null
            }, n.onerror = function () {
                fabric.log("Error loading " + n.src), e && e.call(i, null, !0), n = n.onload = n.onerror = null
            }, 0 !== t.indexOf("data") && r && (n.crossOrigin = r), n.src = t
        }, enlivenObjects: function (t, e, i, r) {
            function n() {
                ++o === a && e && e(s)
            }

            t = t || [];
            var s = [], o = 0, a = t.length, h = !0;
            return a ? void t.forEach(function (t, e) {
                if (!t || !t.type)return void n();
                var o = fabric.util.getKlass(t.type, i);
                o.fromObject(t, function (i, o) {
                    o || (s[e] = i), r && r(t, i, o), n()
                }, h)
            }) : void(e && e(s))
        }, enlivenPatterns: function (t, e) {
            function i() {
                ++n === s && e && e(r)
            }

            t = t || [];
            var r = [], n = 0, s = t.length;
            return s ? void t.forEach(function (t, e) {
                t && t.source ? new fabric.Pattern(t, function (t) {
                    r[e] = t, i()
                }) : (r[e] = t, i())
            }) : void(e && e(r))
        }, groupSVGElements: function (t, e, i) {
            var r;
            return r = new fabric.PathGroup(t, e), "undefined" != typeof i && (r.sourcePath = i), r
        }, populateWithProperties: function (t, e, i) {
            if (i && "[object Array]" === Object.prototype.toString.call(i))for (var r = 0, n = i.length; r < n; r++)i[r]in t && (e[i[r]] = t[i[r]])
        }, drawDashedLine: function (t, r, n, s, o, a) {
            var h = s - r, c = o - n, l = e(h * h + c * c), u = i(c, h), f = a.length, d = 0, g = !0;
            for (t.save(), t.translate(r, n), t.moveTo(0, 0), t.rotate(u), r = 0; l > r;)r += a[d++ % f], r > l && (r = l), t[g ? "lineTo" : "moveTo"](r, 0), g = !g;
            t.restore()
        }, createCanvasElement: function (t) {
            return t || (t = fabric.document.createElement("canvas")), t.getContext || "undefined" == typeof G_vmlCanvasManager || G_vmlCanvasManager.initElement(t), t
        }, createImage: function () {
            return fabric.isLikelyNode ? new (require("canvas").Image) : fabric.document.createElement("img")
        }, createAccessors: function (t) {
            var e, i, r, n, s, o = t.prototype;
            for (e = o.stateProperties.length; e--;)i = o.stateProperties[e], r = i.charAt(0).toUpperCase() + i.slice(1), n = "set" + r, s = "get" + r, o[s] || (o[s] = function (t) {
                return new Function('return this.get("' + t + '")')
            }(i)), o[n] || (o[n] = function (t) {
                return new Function("value", 'return this.set("' + t + '", value)')
Loading
Loading full blame...