ng-fancy-gui
Version:
This package contains components, for creating userinterfaces in a Angular app.
958 lines (918 loc) • 118 kB
JavaScript
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/common'), require('@angular/forms'), require('@angular/platform-browser'), require('@angular/common/http')) :
typeof define === 'function' && define.amd ? define('ng-fancy-gui', ['exports', '@angular/core', '@angular/common', '@angular/forms', '@angular/platform-browser', '@angular/common/http'], factory) :
(global = global || self, factory(global['ng-fancy-gui'] = {}, global.ng.core, global.ng.common, global.ng.forms, global.ng.platformBrowser, global.ng.common.http));
}(this, (function (exports, core, common, forms, platformBrowser, http) { 'use strict';
/*! *****************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */
/* 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 __createBinding(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}
function __exportStar(m, exports) {
for (var p in m) if (p !== "default" && !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 ImageCropperConfig = /** @class */ (function () {
function ImageCropperConfig(width, height, rasterLevels) {
this.width = width;
this.height = height;
this.rasterLevels = rasterLevels;
}
return ImageCropperConfig;
}());
(function (AutCompleteSource) {
AutCompleteSource[AutCompleteSource["Input"] = 0] = "Input";
AutCompleteSource[AutCompleteSource["ApiEndpoint"] = 1] = "ApiEndpoint";
})(exports.AutCompleteSource || (exports.AutCompleteSource = {}));
(function (KeywordType) {
KeywordType[KeywordType["String"] = 0] = "String";
KeywordType[KeywordType["KeyValue"] = 1] = "KeyValue";
})(exports.KeywordType || (exports.KeywordType = {}));
var KeywordPickerConfig = /** @class */ (function () {
function KeywordPickerConfig(keywordType, autocompleteMode, autoCompleteSource, dataMapperFunction, autocompleteSourceUrl) {
if (keywordType === void 0) { keywordType = exports.KeywordType.String; }
if (autocompleteMode === void 0) { autocompleteMode = false; }
if (autoCompleteSource === void 0) { autoCompleteSource = exports.AutCompleteSource.Input; }
if (dataMapperFunction === void 0) { dataMapperFunction = null; }
if (autocompleteSourceUrl === void 0) { autocompleteSourceUrl = null; }
this.keywordType = keywordType;
this.autocompleteMode = autocompleteMode;
this.autoCompleteSource = autoCompleteSource;
this.dataMapperFunction = dataMapperFunction;
this.autocompleteSourceUrl = autocompleteSourceUrl;
}
return KeywordPickerConfig;
}());
(function (AutoCompleteSourceType) {
AutoCompleteSourceType[AutoCompleteSourceType["IdValueArray"] = 0] = "IdValueArray";
AutoCompleteSourceType[AutoCompleteSourceType["StringArray"] = 1] = "StringArray";
AutoCompleteSourceType[AutoCompleteSourceType["Object"] = 2] = "Object";
})(exports.AutoCompleteSourceType || (exports.AutoCompleteSourceType = {}));
var FileService = /** @class */ (function () {
function FileService() {
}
FileService.prototype.getBase64 = function (file) {
return new Promise(function (resolve) {
var reader = new FileReader();
reader.readAsDataURL(file);
reader.onload = function () {
resolve(reader.result);
};
reader.onerror = function (error) {
console.log('Error: ', error);
};
});
};
FileService.prototype.dataURLtoFile = function (dataurl, filename) {
var arr = dataurl.split(',');
var mime = arr[0].match(/:(.*?);/)[1];
var bstr = atob(arr[1]);
var n = bstr.length;
var u8arr = new Uint8Array(n);
while (n--) {
u8arr[n] = bstr.charCodeAt(n);
}
return new File([u8arr], filename, { type: mime });
};
FileService.prototype.getBinary = function (file) {
return new Promise(function (resolve) {
var reader = new FileReader();
reader.onloadend = function () {
var data = reader.result.split(',')[1];
var binaryBlob = atob(data);
resolve(binaryBlob);
};
reader.readAsDataURL(file);
});
};
FileService.ɵprov = core.ɵɵdefineInjectable({ factory: function FileService_Factory() { return new FileService(); }, token: FileService, providedIn: "root" });
FileService = __decorate([
core.Injectable({
providedIn: 'root'
})
], FileService);
return FileService;
}());
var InputBetweenComponent = /** @class */ (function () {
function InputBetweenComponent(elRef, sanitizer) {
this.elRef = elRef;
this.sanitizer = sanitizer;
this.placeholder = "";
this.max = 100;
this.min = 0;
this.lockScroll = true;
this.mouseDown = false;
this.minValue = 0;
this.maxValue = 0;
this.value = null;
this.maxTearMouseDown = false;
this.minTearMouseDown = false;
this.propagateChange = function (_) {
};
}
InputBetweenComponent_1 = InputBetweenComponent;
InputBetweenComponent.prototype.registerOnChange = function (fn) {
this.propagateChange = fn;
};
InputBetweenComponent.prototype.registerOnTouched = function (fn) {
};
InputBetweenComponent.prototype.setDisabledState = function (isDisabled) {
};
InputBetweenComponent.prototype.writeValue = function (value) {
if (value !== null) {
this.minValue = Math.round(value[0]);
this.maxValue = Math.round(value[1]);
this.tearMinStyle = this.calcStyle(this.minValue);
this.tearMaxStyle = this.calcStyle(this.maxValue);
this.calcSliderLineStyle();
}
};
InputBetweenComponent.prototype.ngOnInit = function () {
var _this = this;
if (this.value === null) {
this.minValue = Math.round(this.min + ((this.max - this.min) / 2));
this.maxValue = Math.round(this.min + ((this.max - this.min) / 2));
}
this.tearMinStyle = this.calcStyle(this.minValue);
this.tearMaxStyle = this.calcStyle(this.maxValue);
this.calcSliderLineStyle();
this.elRef.nativeElement.ontouchstart = function () {
_this.disableScroll();
};
this.elRef.nativeElement.ontouchend = function () {
_this.enableScroll();
};
};
InputBetweenComponent.prototype.resize = function () {
this.tearMinStyle = this.calcStyle(this.minValue);
this.tearMaxStyle = this.calcStyle(this.maxValue);
this.calcSliderLineStyle();
};
InputBetweenComponent.prototype.handleMouseLeave = function (event) {
var rect = this.elRef.nativeElement.getBoundingClientRect();
if (event.clientX >= rect.width + rect.x && this.maxTearMouseDown) {
this.maxValue = this.max;
}
if (event.clientX <= rect.x && this.minTearMouseDown) {
this.minValue = this.min;
}
this.maxTearMouseDown = false;
this.minTearMouseDown = false;
this.calcStyle(this.value);
this.tearMinStyle = this.calcStyle(this.minValue);
this.tearMaxStyle = this.calcStyle(this.maxValue);
this.calcSliderLineStyle();
};
InputBetweenComponent.prototype.handleTouchEnd = function (event) {
this.minTearMouseDown = false;
this.maxTearMouseDown = false;
this.calcStyle(this.value);
this.tearMinStyle = this.calcStyle(this.minValue);
this.tearMaxStyle = this.calcStyle(this.maxValue);
this.calcSliderLineStyle();
};
InputBetweenComponent.prototype.calcStyle = function (value) {
var unit = (this.elRef.nativeElement.clientWidth / (this.max - this.min));
return this.sanitizer.bypassSecurityTrustStyle('translate(' + ((Math.abs(this.min) * unit) + (unit * value)) + 'px, ' + -150 + '%) rotate(-135deg) translate(35%, -35%)');
};
InputBetweenComponent.prototype.calcSliderLineStyle = function () {
var unit = (this.elRef.nativeElement.clientWidth / (this.max - this.min));
this.sliderLineWidthStyle = this.sanitizer.bypassSecurityTrustStyle(unit * (this.maxValue - this.minValue) + 'px');
this.sliderLineLeftStyle = this.sanitizer.bypassSecurityTrustStyle((Math.abs(this.min) * unit) + (unit * this.minValue) + 'px');
};
InputBetweenComponent.prototype.disableScroll = function () {
document.body.style.overflowY = 'hidden';
};
InputBetweenComponent.prototype.enableScroll = function () {
document.body.style.overflowY = 'scroll';
};
InputBetweenComponent.prototype.tearMinDown = function () {
this.tearMin.nativeElement.classList.add('active');
this.minTearMouseDown = true;
};
InputBetweenComponent.prototype.tearMaxDown = function () {
this.tearMax.nativeElement.classList.add('active');
this.maxTearMouseDown = true;
};
InputBetweenComponent.prototype.processMouseEventTearMin = function (event) {
this.calcMinValue(event.clientX);
this.tearMinStyle = this.calcStyle(this.minValue);
this.calcSliderLineStyle();
};
InputBetweenComponent.prototype.processMouseEventTearMax = function (event) {
this.calcMaxValue(event.clientX);
this.tearMaxStyle = this.calcStyle(this.maxValue);
this.calcSliderLineStyle();
};
InputBetweenComponent.prototype.processMouseEvent = function (event) {
if (this.minTearMouseDown) {
this.processMouseEventTearMin(event);
}
if (this.maxTearMouseDown) {
this.processMouseEventTearMax(event);
}
};
InputBetweenComponent.prototype.processTouchEventTearMin = function (event) {
this.calcMinValue(event.touches[0].clientX);
this.tearMinStyle = this.calcStyle(this.minValue);
this.calcSliderLineStyle();
};
InputBetweenComponent.prototype.processTouchEventTearMax = function (event) {
this.calcMaxValue(event.touches[0].clientX);
this.tearMaxStyle = this.calcStyle(this.maxValue);
this.calcSliderLineStyle();
};
InputBetweenComponent.prototype.processTouchEvent = function (event) {
var rect = this.elRef.nativeElement.getBoundingClientRect();
if (this.minTearMouseDown) {
this.processTouchEventTearMin(event);
}
if (this.maxTearMouseDown) {
this.processTouchEventTearMax(event);
}
if (event.changedTouches[0].clientX >= rect.width + rect.x && this.maxTearMouseDown) {
this.maxValue = this.max;
// console.log("right leave");
this.tearMaxStyle = this.calcStyle(this.maxValue);
}
if (event.changedTouches[0].clientX <= rect.x && this.minTearMouseDown) {
//console.log("left leave");
this.minValue = this.min;
this.tearMinStyle = this.calcStyle(this.minValue);
}
};
InputBetweenComponent.prototype.calcMinValue = function (mouseX) {
var rect = this.elRef.nativeElement.getBoundingClientRect();
var x = mouseX - rect.left;
if (this.min + Math.round(((this.max - this.min) / (this.elRef.nativeElement.clientWidth)) * x) > this.min &&
this.min + Math.round(((this.max - this.min) / (this.elRef.nativeElement.clientWidth)) * x) < this.maxValue) {
this.minValue = this.min + Math.round(((this.max - this.min) / (this.elRef.nativeElement.clientWidth)) * x);
}
if (this.min + Math.round(((this.max - this.min) / (this.elRef.nativeElement.clientWidth)) * x) < this.min) {
this.minValue = this.min;
}
/*if (Math.round(((this.max - this.min) / (this.elRef.nativeElement.clientWidth)) * x) > this.maxValue) {
this.minValue = this.maxValue;
}*/
this.propagateChange([this.minValue, this.maxValue]);
};
InputBetweenComponent.prototype.calcMaxValue = function (mouseX) {
var rect = this.elRef.nativeElement.getBoundingClientRect();
var x = mouseX - rect.left;
if (this.min + Math.round(((this.max - this.min) / (this.elRef.nativeElement.clientWidth)) * x) > this.minValue &&
this.min + Math.round(((this.max - this.min) / (this.elRef.nativeElement.clientWidth)) * x) < this.max) {
this.maxValue = this.min + Math.round(((this.max - this.min) / (this.elRef.nativeElement.clientWidth)) * x);
}
/*if (Math.round(((this.max - this.min) / (this.elRef.nativeElement.clientWidth)) * x) < this.minValue) {
this.maxValue = this.minValue;
}*/
if (this.min + Math.round(((this.max - this.min) / (this.elRef.nativeElement.clientWidth)) * x) > this.max) {
this.maxValue = this.max;
}
this.propagateChange([this.minValue, this.maxValue]);
};
var InputBetweenComponent_1;
InputBetweenComponent.ctorParameters = function () { return [
{ type: core.ElementRef },
{ type: platformBrowser.DomSanitizer }
]; };
__decorate([
core.Input()
], InputBetweenComponent.prototype, "placeholder", void 0);
__decorate([
core.Input()
], InputBetweenComponent.prototype, "max", void 0);
__decorate([
core.Input()
], InputBetweenComponent.prototype, "min", void 0);
__decorate([
core.ViewChild('tearMax')
], InputBetweenComponent.prototype, "tearMax", void 0);
__decorate([
core.ViewChild('tearMin')
], InputBetweenComponent.prototype, "tearMin", void 0);
__decorate([
core.HostListener('window:resize')
], InputBetweenComponent.prototype, "resize", null);
InputBetweenComponent = InputBetweenComponent_1 = __decorate([
core.Component({
selector: 'fg-input-between',
template: "<div class=\"inputWrap noselect\"\n (touchmove)=\"processTouchEvent($event)\"\n (mousemove)=\"processMouseEvent($event)\"\n (mouseleave)=\"tearMin.classList.remove('active');tearMax.classList.remove('active');handleMouseLeave($event)\"\n (mouseup)=\"tearMax.classList.remove('active');maxTearMouseDown=false;tearMin.classList.remove('active');minTearMouseDown=false;\"\n (touchend)=\"tearMin.classList.remove('active');tearMax.classList.remove('active');handleTouchEnd($event)\"\n>\n <div class=\"fakeInputRange\">\n <div #tearMin class=\"tear\" [style.transform]=\"tearMinStyle\"\n [class.up]=\"minValue> 0 && maxValue===max\"\n (mousedown)=\"tearMinDown()\"\n (touchstart)=\"tearMinDown()\"\n >\n <span>{{minValue}}</span>\n </div>\n\n <div #tearMax class=\"tear\" [style.transform]=\"tearMaxStyle\"\n (mousedown)=\"tearMaxDown()\"\n (touchstart)=\"tearMaxDown()\"\n >\n <span>{{maxValue}}</span>\n </div>\n\n <div class=\"sliderLine\">\n <div class=\"sliderBackground\"></div>\n <div [style.width]=\"sliderLineWidthStyle\" [style.left]=\"sliderLineLeftStyle\" class=\"sliderActive\"></div>\n </div>\n </div>\n</div>\n\n\n\n",
providers: [
{
provide: forms.NG_VALUE_ACCESSOR,
useExisting: core.forwardRef(function () { return InputBetweenComponent_1; }),
multi: true
}
],
styles: [":host{display:block;position:relative}:host *{-webkit-touch-callout:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.up{z-index:10}span{display:block;font-size:22px}.inputWrap{padding-top:32px}.inputWrap .fakeInputRange{position:relative}.inputWrap .fakeInputRange .tear{position:absolute;transition:width .5s,height .5s;width:30px;height:30px;border-radius:0 50% 50%;border:3px solid;transform:rotate(-135deg)}.inputWrap .fakeInputRange .tear span{color:#fff;transition:left .5s,top .5s,font-size .5s;font-size:9px;position:absolute;left:11px;top:11px;transform:translate(-50%,-50%) rotate(-225deg)}.inputWrap .fakeInputRange .tear.active{z-index:7;width:50px;height:50px}.inputWrap .fakeInputRange .tear.active span{font-size:19px;left:20px;top:20px}.sliderLine{margin-top:20px;position:relative}.sliderLine .sliderBackground{width:100%;height:2px;background-color:gray}.sliderLine .sliderActive{position:absolute;height:2px;top:0;left:0}input{opacity:0;top:0;left:0;z-index:1;position:absolute;margin-top:7px;height:100%;font-size:21px;border:1px solid}input.invalid{border:1px solid}"]
})
], InputBetweenComponent);
return InputBetweenComponent;
}());
var CropImage = /** @class */ (function () {
function CropImage(imageCroper, x, y, src) {
var _this = this;
this.imageCroper = imageCroper;
this.x = x;
this.y = y;
this.src = src;
this.loaded = false;
this.rotation = 0;
this.userInputRotation = 0;
this.locked = false;
this.minWidth = 0;
this.minHeight = 0;
this.repositioningSpeed = 1;
this.moveing = false;
this.orignalImage = new Image();
this.orignalImage.src = src;
this.orignalImage.onload = function () {
var fc = document.createElement('canvas');
var fctx = fc.getContext("2d");
var oc = document.createElement('canvas');
var octx = oc.getContext('2d');
//document.body.append(oc);
//document.body.append(fc);
if (_this.orignalImage.width > _this.orignalImage.height) {
fc.width = (_this.orignalImage.width / _this.orignalImage.height) * _this.imageCroper.config.height;
fc.height = _this.imageCroper.config.height;
}
else {
fc.width = _this.imageCroper.config.width;
fc.height = (_this.orignalImage.height / _this.orignalImage.width) * _this.imageCroper.config.width;
}
var steps = Math.ceil(Math.log(_this.orignalImage.width / _this.imageCroper.config.width) / Math.log(2));
//console.log(fc);
// console.log(this.orignalImage.width, this.orignalImage.height);
oc.width = _this.orignalImage.width * 0.5;
oc.height = _this.orignalImage.height * 0.5;
octx.drawImage(_this.orignalImage, 0, 0, oc.width, oc.height);
var factor = 1;
for (var i = 0; i < steps - 3; i++) {
octx.drawImage(oc, 0, 0, oc.width * 0.5, oc.height * 0.5);
factor *= 0.5;
}
fctx.drawImage(oc, 0, 0, oc.width * factor, oc.height * factor, 0, 0, fctx.canvas.width, fctx.canvas.height);
_this.image = new Image();
_this.image.src = fc.toDataURL();
_this.image.onload = function () {
console.log(_this.image.width);
_this.originalWidth = _this.image.width;
_this.originalHeight = _this.image.height;
_this.width = _this.originalWidth;
_this.height = _this.originalHeight;
_this.coverCanvas();
_this.loaded = true;
};
};
}
CropImage.prototype.setMinSize = function () {
if (this.userInputRotation === 0) {
switch (this.rotation) {
case 0: {
if (this.originalWidth >= this.originalHeight) {
this.setMinSizeByWidth(this.imageCroper.canvas.width);
}
if (this.originalHeight >= this.originalWidth) {
this.setMinSizeByHeight(this.imageCroper.canvas.height);
}
break;
}
case -90: {
if (this.originalWidth >= this.originalHeight) {
this.setMinSizeByHeight(this.imageCroper.canvas.width);
}
if (this.originalHeight >= this.originalWidth) {
this.setMinSizeByWidth(this.imageCroper.canvas.height);
}
break;
}
case -180: {
if (this.originalWidth >= this.originalHeight) {
this.setMinSizeByWidth(this.imageCroper.canvas.width);
}
if (this.originalHeight >= this.originalWidth) {
this.setMinSizeByHeight(this.imageCroper.canvas.height);
}
break;
}
case -270: {
if (this.originalWidth >= this.originalHeight) {
this.setMinSizeByHeight(this.imageCroper.canvas.width);
}
if (this.originalHeight >= this.originalWidth) {
this.setMinSizeByWidth(this.imageCroper.canvas.height);
}
break;
}
}
if (this.minWidth < this.imageCroper.canvas.width || this.minHeight < this.imageCroper.canvas.height) {
if (this.rotation === 0 || this.rotation === -180) {
if (this.imageCroper.canvas.width > this.imageCroper.canvas.height) {
this.setMinSizeByWidth(this.imageCroper.canvas.width);
}
else {
this.setMinSizeByHeight(this.imageCroper.canvas.height);
}
}
else {
if (this.imageCroper.canvas.width > this.imageCroper.canvas.height) {
this.setMinSizeByHeight(this.imageCroper.canvas.width);
}
else {
this.setMinSizeByWidth(this.imageCroper.canvas.height);
}
}
}
}
};
CropImage.prototype.drawImageToCanvas = function (ctx) {
if (ctx === void 0) { ctx = this.imageCroper.ctx; }
var x = (this.x / this.imageCroper.canvas.width) * ctx.canvas.width;
var y = (this.y / this.imageCroper.canvas.height) * ctx.canvas.height;
var width = (this.width / this.imageCroper.canvas.width) * ctx.canvas.width;
var height = (this.height / this.imageCroper.canvas.height) * ctx.canvas.height;
ctx.beginPath();
ctx.translate(x, y);
ctx.rotate((Math.PI / 180) * (this.rotation + this.userInputRotation));
ctx.imageSmoothingEnabled = false;
ctx.drawImage(this.orignalImage, -width * 0.5, -height * 0.5, width, height);
ctx.setTransform(1, 0, 0, 1, 0, 0);
ctx.closePath();
};
CropImage.prototype.render = function () {
if (this.loaded) {
this.drawImageToCanvas();
}
};
CropImage.prototype.resize = function (factor) {
var verhaeltinis = this.originalHeight / this.originalWidth;
this.width = this.width * factor;
this.height = verhaeltinis * this.width;
this.coverCanvas();
};
CropImage.prototype.coverCanvas = function () {
var overLeftBorder = false;
var overRightBorder = false;
var overTopBorder = false;
var overBottomBorder = false;
this.setMinSize();
if (this.minHeight > this.height || this.minWidth > this.width) {
this.width = this.minWidth;
this.height = this.minHeight;
// console.log(`set min size ${this.width} ${this.height}`);
}
if (this.rotation === 0 || this.rotation === -180) {
if (this.x - (this.width / 2) > 0) { // over left border
this.x = (this.width / 2);
overLeftBorder = true;
}
if (this.x + (this.width / 2) < this.imageCroper.canvas.width) { // over right border
this.x = this.imageCroper.canvas.width - (this.width / 2);
overRightBorder = true;
}
if (this.y - (this.height / 2) > 0) { // over top
this.y = (this.height / 2);
overTopBorder = true;
}
if (this.y + (this.height / 2) < this.imageCroper.canvas.height) { // bottom border
this.y = this.imageCroper.canvas.height - (this.height / 2);
overBottomBorder = true;
}
if (this.originalWidth < this.originalHeight) {
if (overLeftBorder && overRightBorder) {
this.x = (this.imageCroper.canvas.width / 2);
this.resizeByWidth(this.imageCroper.canvas.width);
if (overTopBorder) {
this.y = (this.height / 2);
}
if (overBottomBorder) {
this.y = this.imageCroper.canvas.height - (this.height / 2);
}
}
}
else {
if (overTopBorder && overBottomBorder) {
this.y = (this.imageCroper.canvas.height / 2);
this.resizeByHeight(this.imageCroper.canvas.height);
if (overLeftBorder) {
this.x = (this.width / 2);
}
if (overRightBorder) {
this.x = this.imageCroper.canvas.width - (this.width / 2);
}
}
}
}
else if (this.rotation === -90 || this.rotation === -270) {
if (this.x - (this.height / 2) > 0) { // over left border
this.x = (this.height / 2);
overLeftBorder = true;
}
if (this.x + (this.height / 2) < this.imageCroper.canvas.width) { // over right border
this.x = this.imageCroper.canvas.width - (this.height / 2);
overRightBorder = true;
}
if (this.y - (this.width / 2) > 0) { // over top
this.y = (this.width / 2);
overTopBorder = true;
}
if (this.y + (this.width / 2) < this.imageCroper.canvas.height) { // bottom border
this.y = this.imageCroper.canvas.height - (this.width / 2);
overBottomBorder = true;
}
if (this.originalWidth > this.originalHeight) {
if (overTopBorder && overBottomBorder) {
this.y = (this.imageCroper.canvas.height / 2);
this.resizeByWidth(this.imageCroper.canvas.height);
if (overLeftBorder) {
this.x = (this.height / 2);
}
if (overRightBorder) {
this.x = this.imageCroper.canvas.width - (this.height / 2);
}
}
}
else {
if (overLeftBorder && overRightBorder) {
this.x = (this.imageCroper.canvas.width / 2);
this.resizeByHeight(this.imageCroper.canvas.width);
if (overTopBorder) {
this.y = (this.width / 2);
}
if (overBottomBorder) {
this.y = this.imageCroper.canvas.height - (this.width / 2);
}
}
}
}
// console.log("cover");
};
CropImage.prototype.resizeOriginalImage = function (factor) {
var verhaeltinis = this.originalHeight / this.originalWidth;
this.width = this.originalWidth * factor;
this.height = verhaeltinis * this.width;
};
CropImage.prototype.resetOriginalImage = function () {
this.originalWidth = this.width;
this.originalHeight = this.height;
};
CropImage.prototype.resizeByDeltaHeight = function (delataHeight) {
var verhaeltinis = this.originalWidth / this.originalHeight;
this.height += delataHeight;
this.width = this.height * verhaeltinis;
};
CropImage.prototype.resizeByDeltaWidth = function (delataWidth) {
var verhaeltinis = this.originalHeight / this.originalWidth;
this.width += delataWidth;
this.height = verhaeltinis * this.width;
};
CropImage.prototype.resizeByWidth = function (width) {
var verhaeltinis = this.originalHeight / this.originalWidth;
this.width = width;
this.height = verhaeltinis * width;
};
CropImage.prototype.resizeByHeight = function (height) {
var verhaeltinis = this.originalWidth / this.originalHeight;
this.height = height;
this.width = verhaeltinis * this.height;
};
CropImage.prototype.setUserInputRotation = function (deg) {
this.userInputRotation = deg;
this.setMinSize();
};
CropImage.prototype.setMinSizeByWidth = function (newWidth) {
//console.log("set new witdh: ", newWidth);
var heightWidthRatio = this.originalHeight / this.originalWidth;
this.minWidth = newWidth;
this.minHeight = heightWidthRatio * this.minWidth;
};
CropImage.prototype.setMinSizeByHeight = function (newHeight) {
//console.log("set new height : ", newHeight);
var widthHeightRatio = this.originalWidth / this.originalHeight;
this.minHeight = newHeight;
this.minWidth = widthHeightRatio * this.minHeight;
};
return CropImage;
}());
var GestureHandler = /** @class */ (function () {
function GestureHandler(imageCroper) {
var _this = this;
this.imageCroper = imageCroper;
this.imageCroper.canvas.onmousemove = function (evt) {
_this.handleMove(evt);
};
this.imageCroper.canvas.ontouchmove = function (evt) {
evt.preventDefault();
_this.handleTouch(evt);
};
this.imageCroper.canvas.onwheel = function (evt) {
event.preventDefault();
if (evt.deltaY < 0) {
_this.imageCroper.cropImage.resize(1.1);
}
else {
if (!_this.imageCroper.cropImage.locked) {
_this.imageCroper.cropImage.resize(0.9);
}
}
};
}
GestureHandler.prototype.handleMove = function (evt) {
//console.log("move");
var halfImageWidth = this.imageCroper.cropImage.width * 0.5;
var halfImageHeight = this.imageCroper.cropImage.height * 0.5;
var newImageX = this.imageCroper.cropImage.x + this.imageCroper.mouse.x - this.imageCroper.mouse.lastX;
var newImageY = this.imageCroper.cropImage.y + this.imageCroper.mouse.y - this.imageCroper.mouse.lastY;
var mouseXdiff = this.imageCroper.mouse.x - this.imageCroper.mouse.lastX;
var mouseYdiff = this.imageCroper.mouse.y - this.imageCroper.mouse.lastY;
if (this.imageCroper.mouse.isDown && !this.imageCroper.cropImage.locked) {
if ((this.imageCroper.cropImage.rotation === 0 || this.imageCroper.cropImage.rotation === -180) &&
this.imageCroper.cropImage.userInputRotation === 0) { // with, height is default
if ((newImageX - halfImageWidth <= 0 && newImageX + halfImageWidth >= this.imageCroper.canvas.width) ||
this.imageCroper.cropImage.userInputRotation !== 0) {
this.imageCroper.cropImage.x += mouseXdiff;
}
if ((newImageY + halfImageHeight >= this.imageCroper.canvas.height && newImageY - halfImageHeight <= 0) ||
this.imageCroper.cropImage.userInputRotation !== 0) {
this.imageCroper.cropImage.y += mouseYdiff;
}
}
else { // with, height is switched
if ((newImageX - halfImageHeight <= 0 && newImageX + halfImageHeight >= this.imageCroper.canvas.width) ||
this.imageCroper.cropImage.userInputRotation !== 0) {
this.imageCroper.cropImage.x += mouseXdiff;
}
if ((newImageY + halfImageWidth >= this.imageCroper.canvas.height && (newImageY - halfImageWidth) <= 0) ||
this.imageCroper.cropImage.userInputRotation !== 0) {
this.imageCroper.cropImage.y += mouseYdiff;
}
}
}
this.imageCroper.mouse.syncPosition(evt);
};
GestureHandler.prototype.handleTouch = function (evt) {
var halfImageWidth = this.imageCroper.cropImage.width * 0.5;
var halfImageHeight = this.imageCroper.cropImage.height * 0.5;
var newImageX = this.imageCroper.cropImage.x + this.imageCroper.mouse.x - this.imageCroper.mouse.lastX;
var newImageY = this.imageCroper.cropImage.y + this.imageCroper.mouse.y - this.imageCroper.mouse.lastY;
var mouseXdiff = this.imageCroper.mouse.x - this.imageCroper.mouse.lastX;
var mouseYdiff = this.imageCroper.mouse.y - this.imageCroper.mouse.lastY;
if (this.imageCroper.mouse.isDown && !this.imageCroper.cropImage.locked) {
if ((this.imageCroper.cropImage.rotation === 0 || this.imageCroper.cropImage.rotation === -180) &&
this.imageCroper.cropImage.userInputRotation === 0) { // with, height is default
if ((newImageX - halfImageWidth <= 0 && newImageX + halfImageWidth >= this.imageCroper.canvas.width) ||
this.imageCroper.cropImage.userInputRotation !== 0) {
this.imageCroper.cropImage.x += mouseXdiff;
}
if ((newImageY + halfImageHeight >= this.imageCroper.canvas.height && newImageY - halfImageHeight <= 0) ||
this.imageCroper.cropImage.userInputRotation !== 0) {
this.imageCroper.cropImage.y += mouseYdiff;
}
}
else { // with, height is switched
if ((newImageX - halfImageHeight <= 0 && newImageX + halfImageHeight >= this.imageCroper.canvas.width) ||
this.imageCroper.cropImage.userInputRotation !== 0) {
this.imageCroper.cropImage.x += mouseXdiff;
}
if ((newImageY + halfImageWidth >= this.imageCroper.canvas.height && (newImageY - halfImageWidth) <= 0) ||
this.imageCroper.cropImage.userInputRotation !== 0) {
this.imageCroper.cropImage.y += mouseYdiff;
}
}
}
this.imageCroper.mouse.syncTouchPosition(evt);
};
return GestureHandler;
}());
var Mouse = /** @class */ (function () {
function Mouse(imageCroper) {
var _this = this;
this.imageCroper = imageCroper;
this.pinching = false;
this.lastX = 0;
this.lastY = 0;
this.isDown = false;
this.imageCroper.canvas.style.cursor = 'grab';
this.imageCroper.canvas.onmousedown = function (evt) {
_this.imageCroper.canvas.style.cursor = 'grabbing';
_this.syncPosition(evt);
_this.lastY = _this.y;
_this.lastX = _this.x;
_this.isDown = true;
_this.imageCroper.cropImage.moveing = true;
};
this.imageCroper.canvas.onmouseup = function () {
_this.imageCroper.canvas.style.cursor = 'grab';
_this.isDown = false;
};
this.imageCroper.canvas.ontouchstart = function (evt) {
_this.imageCroper.canvas.style.cursor = 'grabbing';
_this.syncTouchPosition(evt);
_this.lastY = _this.y;
_this.lastX = _this.x;
_this.isDown = true;
_this.imageCroper.cropImage.moveing = true;
};
this.imageCroper.canvas.ontouchend = function () {
_this.imageCroper.canvas.style.cursor = 'grab';
_this.isDown = false;
};
}
Mouse.prototype.syncPosition = function (evt) {
var rect = this.imageCroper.canvas.getBoundingClientRect();
this.lastX = this.x;
this.lastY = this.y;
this.x = evt.clientX - rect.left;
this.y = ((evt.clientY - rect.top));
};
Mouse.prototype.syncTouchPosition = function (evt) {
var rect = this.imageCroper.canvas.getBoundingClientRect();
this.lastX = this.x;
this.lastY = this.y;
this.x = evt.touches[0].clientX - rect.left;
th