angular-fabric-js
Version:
This library was generated with [Angular CLI](https://github.com/angular/angular-cli) version 9.0.7.
809 lines (777 loc) • 36.9 kB
JavaScript
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('fabric'), require('@angular/platform-browser'), require('@angular/forms'), require('ngx-color-picker')) :
typeof define === 'function' && define.amd ? define('angular-fabric-js', ['exports', '@angular/core', 'fabric', '@angular/platform-browser', '@angular/forms', 'ngx-color-picker'], factory) :
(global = global || self, factory(global['angular-fabric-js'] = {}, global.ng.core, global.fabric, global.ng.platformBrowser, global.ng.forms, global.ngxColorPicker));
}(this, (function (exports, core, fabric, platformBrowser, forms, ngxColorPicker) { 'use strict';
/*! *****************************************************************************
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at http://www.apache.org/licenses/LICENSE-2.0
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
MERCHANTABLITY OR NON-INFRINGEMENT.
See the Apache Version 2.0 License for specific language governing permissions
and limitations under the License.
***************************************************************************** */
/* global Reflect, Promise */
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);
};
function __extends(d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
}
var __assign = function() {
__assign = Object.assign || function __assign(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
function __rest(s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
}
function __decorate(decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
}
function __param(paramIndex, decorator) {
return function (target, key) { decorator(target, key, paramIndex); }
}
function __metadata(metadataKey, metadataValue) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
}
function __awaiter(thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
}
function __generator(thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
}
function __exportStar(m, exports) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
function __values(o) {
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
if (m) return m.call(o);
if (o && typeof o.length === "number") return {
next: function () {
if (o && i >= o.length) o = void 0;
return { value: o && o[i++], done: !o };
}
};
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
}
function __read(o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
}
function __spread() {
for (var ar = [], i = 0; i < arguments.length; i++)
ar = ar.concat(__read(arguments[i]));
return ar;
}
function __spreadArrays() {
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
for (var r = Array(s), k = 0, i = 0; i < il; i++)
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
r[k] = a[j];
return r;
};
function __await(v) {
return this instanceof __await ? (this.v = v, this) : new __await(v);
}
function __asyncGenerator(thisArg, _arguments, generator) {
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
var g = generator.apply(thisArg, _arguments || []), i, q = [];
return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
function fulfill(value) { resume("next", value); }
function reject(value) { resume("throw", value); }
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
}
function __asyncDelegator(o) {
var i, p;
return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
}
function __asyncValues(o) {
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
var m = o[Symbol.asyncIterator], i;
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
}
function __makeTemplateObject(cooked, raw) {
if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
return cooked;
};
function __importStar(mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result.default = mod;
return result;
}
function __importDefault(mod) {
return (mod && mod.__esModule) ? mod : { default: mod };
}
function __classPrivateFieldGet(receiver, privateMap) {
if (!privateMap.has(receiver)) {
throw new TypeError("attempted to get private field on non-instance");
}
return privateMap.get(receiver);
}
function __classPrivateFieldSet(receiver, privateMap, value) {
if (!privateMap.has(receiver)) {
throw new TypeError("attempted to set private field on non-instance");
}
privateMap.set(receiver, value);
return value;
}
var FabricjsEditorComponent = /** @class */ (function () {
function FabricjsEditorComponent() {
this.props = {
canvasFill: '#ffffff',
canvasImage: '',
id: null,
opacity: null,
fill: null,
fontSize: null,
lineHeight: null,
charSpacing: null,
fontWeight: null,
fontStyle: null,
textAlign: null,
fontFamily: null,
TextDecoration: ''
};
this.url = '';
this.size = {
width: 500,
height: 300
};
this.globalEditor = false;
this.textEditor = false;
this.imageEditor = false;
this.figureEditor = false;
}
FabricjsEditorComponent.prototype.ngAfterViewInit = function () {
var _this = this;
// setup front side canvas
this.canvas = new fabric.fabric.Canvas(this.htmlCanvas.nativeElement, {
hoverCursor: 'pointer',
selection: true,
selectionBorderColor: 'blue',
isDrawingMode: true
});
this.canvas.on({
'object:moving': function (e) { },
'object:modified': function (e) { },
'object:selected': function (e) {
var selectedObject = e.target;
_this.selected = selectedObject;
selectedObject.hasRotatingPoint = true;
selectedObject.transparentCorners = false;
selectedObject.borderColor = 'blue';
selectedObject.cornerColor = 'green';
selectedObject.cornerSize = 6;
selectedObject.cornerStyle = 'circle';
selectedObject.padding = 10;
_this.resetPanels();
if (selectedObject.type !== 'group' && selectedObject) {
_this.getId();
_this.getOpacity();
switch (selectedObject.type) {
case 'rect':
case 'circle':
case 'triangle':
_this.figureEditor = true;
_this.getFill();
break;
case 'i-text':
_this.textEditor = true;
_this.getLineHeight();
_this.getCharSpacing();
_this.getBold();
_this.getFill();
_this.getTextDecoration();
_this.getTextAlign();
_this.getFontFamily();
break;
case 'image':
break;
}
}
},
'selection:cleared': function (e) {
_this.selected = null;
_this.resetPanels();
}
});
this.canvas.setWidth(this.size.width);
this.canvas.setHeight(this.size.height);
// get references to the html canvas element & its context
this.canvas.on('mouse:down', function (e) {
var canvasElement = document.getElementById('canvas');
});
};
/*------------------------Block elements------------------------*/
// Block "Size"
FabricjsEditorComponent.prototype.changeSize = function () {
this.canvas.setWidth(this.size.width);
this.canvas.setHeight(this.size.height);
};
// Block "Add text"
FabricjsEditorComponent.prototype.addText = function () {
if (this.textString) {
var text = new fabric.fabric.IText(this.textString, {
left: 10,
top: 10,
fontFamily: 'helvetica',
angle: 0,
fill: '#000000',
scaleX: 0.5,
scaleY: 0.5,
fontWeight: '',
hasRotatingPoint: true
});
this.extend(text, this.randomId());
this.canvas.add(text);
this.selectItemAfterAdded(text);
this.textString = '';
}
};
// Block "Add images"
FabricjsEditorComponent.prototype.getImgPolaroid = function (event) {
var _this = this;
var el = event.target;
fabric.fabric.loadSVGFromURL(el.src, function (objects, options) {
var image = fabric.fabric.util.groupSVGElements(objects, options);
image.set({
left: 10,
top: 10,
angle: 0,
padding: 10,
cornerSize: 10,
hasRotatingPoint: true,
});
_this.extend(image, _this.randomId());
_this.canvas.add(image);
_this.selectItemAfterAdded(image);
});
};
// Block "Upload Image"
FabricjsEditorComponent.prototype.addImageOnCanvas = function (url) {
var _this = this;
if (url) {
fabric.fabric.Image.fromURL(url, function (image) {
image.set({
left: 10,
top: 10,
angle: 0,
padding: 10,
cornerSize: 10,
hasRotatingPoint: true
});
image.scaleToWidth(200);
image.scaleToHeight(200);
_this.extend(image, _this.randomId());
_this.canvas.add(image);
_this.selectItemAfterAdded(image);
});
}
};
FabricjsEditorComponent.prototype.readUrl = function (event) {
var _this = this;
if (event.target.files && event.target.files[0]) {
var reader = new FileReader();
reader.onload = function (readerEvent) {
_this.url = readerEvent.target.result;
};
reader.readAsDataURL(event.target.files[0]);
}
};
FabricjsEditorComponent.prototype.removeWhite = function (url) {
this.url = '';
};
// Block "Add figure"
FabricjsEditorComponent.prototype.addFigure = function (figure) {
var add;
switch (figure) {
case 'rectangle':
add = new fabric.fabric.Rect({
width: 200, height: 100, left: 10, top: 10, angle: 0,
fill: '#3f51b5'
});
break;
case 'square':
add = new fabric.fabric.Rect({
width: 100, height: 100, left: 10, top: 10, angle: 0,
fill: '#4caf50'
});
break;
case 'triangle':
add = new fabric.fabric.Triangle({
width: 100, height: 100, left: 10, top: 10, fill: '#2196f3'
});
break;
case 'circle':
add = new fabric.fabric.Circle({
radius: 50, left: 10, top: 10, fill: '#ff5722'
});
break;
}
this.extend(add, this.randomId());
this.canvas.add(add);
this.selectItemAfterAdded(add);
};
/*Canvas*/
FabricjsEditorComponent.prototype.cleanSelect = function () {
this.canvas.discardActiveObject().renderAll();
};
FabricjsEditorComponent.prototype.selectItemAfterAdded = function (obj) {
this.canvas.discardActiveObject().renderAll();
this.canvas.setActiveObject(obj);
};
FabricjsEditorComponent.prototype.setCanvasFill = function () {
if (!this.props.canvasImage) {
this.canvas.backgroundColor = this.props.canvasFill;
this.canvas.renderAll();
}
};
FabricjsEditorComponent.prototype.extend = function (obj, id) {
obj.toObject = (function (toObject) {
return function () {
return fabric.fabric.util.object.extend(toObject.call(this), {
id: id
});
};
})(obj.toObject);
};
FabricjsEditorComponent.prototype.setCanvasImage = function () {
var self = this;
if (this.props.canvasImage) {
this.canvas.setBackgroundImage(this.props.canvasImage, this.canvas.renderAll.bind(this.canvas), {
// width: this.size.width,
// height: this.size.height,
originX: 'left',
originY: 'top',
crossOrigin: 'anonymous'
});
}
};
FabricjsEditorComponent.prototype.randomId = function () {
return Math.floor(Math.random() * 999999) + 1;
};
/*------------------------Global actions for element------------------------*/
FabricjsEditorComponent.prototype.getActiveStyle = function (styleName, object) {
object = object || this.canvas.getActiveObject();
if (!object) {
return '';
}
if (object.getSelectionStyles && object.isEditing) {
return (object.getSelectionStyles()[styleName] || '');
}
else {
return (object[styleName] || '');
}
};
FabricjsEditorComponent.prototype.setActiveStyle = function (styleName, value, object) {
object = object || this.canvas.getActiveObject();
if (!object) {
return;
}
if (object.setSelectionStyles && object.isEditing) {
var style = {};
style[styleName] = value;
if (typeof value === 'string') {
if (value.includes('underline')) {
object.setSelectionStyles({ underline: true });
}
else {
object.setSelectionStyles({ underline: false });
}
if (value.includes('overline')) {
object.setSelectionStyles({ overline: true });
}
else {
object.setSelectionStyles({ overline: false });
}
if (value.includes('line-through')) {
object.setSelectionStyles({ linethrough: true });
}
else {
object.setSelectionStyles({ linethrough: false });
}
}
object.setSelectionStyles(style);
object.setCoords();
}
else {
if (typeof value === 'string') {
if (value.includes('underline')) {
object.set('underline', true);
}
else {
object.set('underline', false);
}
if (value.includes('overline')) {
object.set('overline', true);
}
else {
object.set('overline', false);
}
if (value.includes('line-through')) {
object.set('linethrough', true);
}
else {
object.set('linethrough', false);
}
}
object.set(styleName, value);
}
object.setCoords();
this.canvas.renderAll();
};
FabricjsEditorComponent.prototype.getActiveProp = function (name) {
var object = this.canvas.getActiveObject();
if (!object) {
return '';
}
return object[name] || '';
};
FabricjsEditorComponent.prototype.setActiveProp = function (name, value) {
var object = this.canvas.getActiveObject();
if (!object) {
return;
}
object.set(name, value).setCoords();
this.canvas.renderAll();
};
FabricjsEditorComponent.prototype.clone = function () {
var activeObject = this.canvas.getActiveObject();
var activeGroup = this.canvas.getActiveObjects();
if (activeObject) {
var clone = void 0;
switch (activeObject.type) {
case 'rect':
clone = new fabric.fabric.Rect(activeObject.toObject());
break;
case 'circle':
clone = new fabric.fabric.Circle(activeObject.toObject());
break;
case 'triangle':
clone = new fabric.fabric.Triangle(activeObject.toObject());
break;
case 'i-text':
clone = new fabric.fabric.IText('', activeObject.toObject());
break;
case 'image':
clone = fabric.fabric.util.object.clone(activeObject);
break;
}
if (clone) {
clone.set({ left: 10, top: 10 });
this.canvas.add(clone);
this.selectItemAfterAdded(clone);
}
}
};
FabricjsEditorComponent.prototype.getId = function () {
this.props.id = this.canvas.getActiveObject().toObject().id;
};
FabricjsEditorComponent.prototype.setId = function () {
var val = this.props.id;
var complete = this.canvas.getActiveObject().toObject();
console.log(complete);
this.canvas.getActiveObject().toObject = function () {
complete.id = val;
return complete;
};
};
FabricjsEditorComponent.prototype.getOpacity = function () {
this.props.opacity = this.getActiveStyle('opacity', null) * 100;
};
FabricjsEditorComponent.prototype.setOpacity = function () {
this.setActiveStyle('opacity', parseInt(this.props.opacity, 10) / 100, null);
};
FabricjsEditorComponent.prototype.getFill = function () {
this.props.fill = this.getActiveStyle('fill', null);
};
FabricjsEditorComponent.prototype.setFill = function () {
this.setActiveStyle('fill', this.props.fill, null);
};
FabricjsEditorComponent.prototype.getLineHeight = function () {
this.props.lineHeight = this.getActiveStyle('lineHeight', null);
};
FabricjsEditorComponent.prototype.setLineHeight = function () {
this.setActiveStyle('lineHeight', parseFloat(this.props.lineHeight), null);
};
FabricjsEditorComponent.prototype.getCharSpacing = function () {
this.props.charSpacing = this.getActiveStyle('charSpacing', null);
};
FabricjsEditorComponent.prototype.setCharSpacing = function () {
this.setActiveStyle('charSpacing', this.props.charSpacing, null);
};
FabricjsEditorComponent.prototype.getFontSize = function () {
this.props.fontSize = this.getActiveStyle('fontSize', null);
};
FabricjsEditorComponent.prototype.setFontSize = function () {
this.setActiveStyle('fontSize', parseInt(this.props.fontSize, 10), null);
};
FabricjsEditorComponent.prototype.getBold = function () {
this.props.fontWeight = this.getActiveStyle('fontWeight', null);
};
FabricjsEditorComponent.prototype.setBold = function () {
this.props.fontWeight = !this.props.fontWeight;
this.setActiveStyle('fontWeight', this.props.fontWeight ? 'bold' : '', null);
};
FabricjsEditorComponent.prototype.setFontStyle = function () {
this.props.fontStyle = !this.props.fontStyle;
if (this.props.fontStyle) {
this.setActiveStyle('fontStyle', 'italic', null);
}
else {
this.setActiveStyle('fontStyle', 'normal', null);
}
};
FabricjsEditorComponent.prototype.getTextDecoration = function () {
this.props.TextDecoration = this.getActiveStyle('textDecoration', null);
};
FabricjsEditorComponent.prototype.setTextDecoration = function (value) {
var iclass = this.props.TextDecoration;
if (iclass.includes(value)) {
iclass = iclass.replace(RegExp(value, 'g'), '');
}
else {
iclass += " " + value;
}
this.props.TextDecoration = iclass;
this.setActiveStyle('textDecoration', this.props.TextDecoration, null);
};
FabricjsEditorComponent.prototype.hasTextDecoration = function (value) {
return this.props.TextDecoration.includes(value);
};
FabricjsEditorComponent.prototype.getTextAlign = function () {
this.props.textAlign = this.getActiveProp('textAlign');
};
FabricjsEditorComponent.prototype.setTextAlign = function (value) {
this.props.textAlign = value;
this.setActiveProp('textAlign', this.props.textAlign);
};
FabricjsEditorComponent.prototype.getFontFamily = function () {
this.props.fontFamily = this.getActiveProp('fontFamily');
};
FabricjsEditorComponent.prototype.setFontFamily = function () {
this.setActiveProp('fontFamily', this.props.fontFamily);
};
/*System*/
FabricjsEditorComponent.prototype.removeSelected = function () {
var activeObject = this.canvas.getActiveObject();
var activeGroup = this.canvas.getActiveObjects();
if (activeObject) {
this.canvas.remove(activeObject);
// this.textString = '';
}
else if (activeGroup) {
this.canvas.discardActiveObject();
var self_1 = this;
activeGroup.forEach(function (object) {
self_1.canvas.remove(object);
});
}
};
FabricjsEditorComponent.prototype.bringToFront = function () {
var activeObject = this.canvas.getActiveObject();
var activeGroup = this.canvas.getActiveObjects();
if (activeObject) {
activeObject.bringToFront();
activeObject.opacity = 1;
}
else if (activeGroup) {
this.canvas.discardActiveObject();
activeGroup.forEach(function (object) {
object.bringToFront();
});
}
};
FabricjsEditorComponent.prototype.sendToBack = function () {
var activeObject = this.canvas.getActiveObject();
var activeGroup = this.canvas.getActiveObjects();
if (activeObject) {
this.canvas.sendToBack(activeObject);
activeObject.sendToBack();
activeObject.opacity = 1;
}
else if (activeGroup) {
this.canvas.discardActiveObject();
activeGroup.forEach(function (object) {
object.sendToBack();
});
}
};
FabricjsEditorComponent.prototype.confirmClear = function () {
if (confirm('Are you sure?')) {
this.canvas.clear();
}
};
FabricjsEditorComponent.prototype.rasterize = function () {
var image = new Image();
image.src = this.canvas.toDataURL({ format: 'png' });
var w = window.open('');
w.document.write(image.outerHTML);
this.downLoadImage();
};
FabricjsEditorComponent.prototype.downLoadImage = function () {
var c = this.canvas.toDataURL({ format: 'png' });
var downloadLink = document.createElement('a');
document.body.appendChild(downloadLink);
downloadLink.href = c;
downloadLink.target = '_self';
downloadLink.download = Date.now() + '.png';
downloadLink.click();
};
FabricjsEditorComponent.prototype.rasterizeSVG = function () {
var w = window.open('');
w.document.write(this.canvas.toSVG());
this.downLoadSVG();
return 'data:image/svg+xml;utf8,' + encodeURIComponent(this.canvas.toSVG());
};
FabricjsEditorComponent.prototype.downLoadSVG = function () {
var c = 'data:image/svg+xml;utf8,' + encodeURIComponent(this.canvas.toSVG());
var downloadLink = document.createElement('a');
document.body.appendChild(downloadLink);
downloadLink.href = c;
downloadLink.target = '_self';
downloadLink.download = Date.now() + '.svg';
downloadLink.click();
};
FabricjsEditorComponent.prototype.saveCanvasToJSON = function () {
var json = JSON.stringify(this.canvas);
localStorage.setItem('Kanvas', json);
console.log('json');
console.log(json);
};
FabricjsEditorComponent.prototype.loadCanvasFromJSON = function () {
var _this = this;
var CANVAS = localStorage.getItem('Kanvas');
console.log('CANVAS');
console.log(CANVAS);
// and load everything from the same json
this.canvas.loadFromJSON(CANVAS, function () {
console.log('CANVAS untar');
console.log(CANVAS);
// making sure to render canvas at the end
_this.canvas.renderAll();
// and checking if object's "name" is preserved
console.log('this.canvas.item(0).name');
console.log(_this.canvas);
});
};
FabricjsEditorComponent.prototype.rasterizeJSON = function () {
this.json = JSON.stringify(this.canvas, null, 2);
};
FabricjsEditorComponent.prototype.resetPanels = function () {
this.textEditor = false;
this.imageEditor = false;
this.figureEditor = false;
};
FabricjsEditorComponent.prototype.drawingMode = function () {
this.canvas.isDrawingMode = !this.canvas.isDrawingMode;
};
__decorate([
core.ViewChild('htmlCanvas')
], FabricjsEditorComponent.prototype, "htmlCanvas", void 0);
FabricjsEditorComponent = __decorate([
core.Component({
selector: 'angular-editor-fabric-js',
template: "<canvas id=\"canvas\" #htmlCanvas></canvas>\r\n",
styles: ["#canvas{border:2px dashed #ccc}"]
})
], FabricjsEditorComponent);
return FabricjsEditorComponent;
}());
var FabricjsEditorModule = /** @class */ (function () {
function FabricjsEditorModule() {
}
FabricjsEditorModule = __decorate([
core.NgModule({
declarations: [FabricjsEditorComponent],
imports: [
platformBrowser.BrowserModule,
forms.FormsModule,
ngxColorPicker.ColorPickerModule
],
exports: [FabricjsEditorComponent]
})
], FabricjsEditorModule);
return FabricjsEditorModule;
}());
exports.FabricjsEditorComponent = FabricjsEditorComponent;
exports.FabricjsEditorModule = FabricjsEditorModule;
Object.defineProperty(exports, '__esModule', { value: true });
})));
//# sourceMappingURL=angular-fabric-js.umd.js.map