@foblex/core
Version:
A core library providing a set of utilities and interfaces for various projects.
895 lines (862 loc) • 32.8 kB
JavaScript
import * as i0 from '@angular/core';
import { PLATFORM_ID, Injectable, Inject } from '@angular/core';
import { isPlatformBrowser } from '@angular/common';
/**
* @deprecated This class is deprecated and will be removed in future versions.
*/
class DomElementExtensions {
static setDataToAllChildren(element, attrName, value) {
for (let i = 0; i < element.children.length; i++) {
const childrenElement = element.children[i];
childrenElement.dataset[attrName] = value;
if (childrenElement.children.length) {
DomElementExtensions.setDataToAllChildren(childrenElement, attrName, value);
}
}
}
static removeDataFromAllChildren(element, attrName) {
for (let i = 0; i < element.children.length; i++) {
const childrenElement = element.children[i];
delete childrenElement.dataset[attrName];
if (childrenElement.children.length) {
DomElementExtensions.removeDataFromAllChildren(childrenElement, attrName);
}
}
}
/**
* @deprecated This method is deprecated and will be removed in future versions.
*/
static createSvgElement(tag) {
return document.createElementNS('http://www.w3.org/2000/svg', tag);
}
/**
* @deprecated This method is deprecated and will be removed in future versions.
*/
static createHtmlElement(tag) {
return document.createElement(tag);
}
//from angular material cdk drag-and-drop
static deepCloneNode(node) {
const clone = node.cloneNode(true);
const descendantsWithId = clone.querySelectorAll('[id]');
const nodeName = node.nodeName.toLowerCase();
clone.removeAttribute('id');
for (let i = 0; i < descendantsWithId.length; i++) {
descendantsWithId[i].removeAttribute('id');
}
if (nodeName === 'canvas') {
transferCanvasData(node, clone);
}
else if (nodeName === 'input' || nodeName === 'select' || nodeName === 'textarea') {
transferInputData(node, clone);
}
transferData('canvas', node, clone, transferCanvasData);
transferData('input, textarea, select', node, clone, transferInputData);
return clone;
}
}
function transferData(selector, node, clone, callback) {
const descendantElements = node.querySelectorAll(selector);
if (descendantElements.length) {
const cloneElements = clone.querySelectorAll(selector);
for (let i = 0; i < descendantElements.length; i++) {
callback(descendantElements[i], cloneElements[i]);
}
}
}
let cloneUniqueId = 0;
function transferInputData(source, clone) {
if (clone.type !== 'file') {
clone.value = source.value;
}
if (clone.type === 'radio' && clone.name) {
clone.name = `mat-clone-${clone.name}-${cloneUniqueId++}`;
}
}
function transferCanvasData(source, clone) {
const context = clone.getContext('2d');
if (context) {
try {
context.drawImage(source, 0, 0);
}
catch (_a) {
}
}
}
/**
* @deprecated This class is deprecated and will be removed in future versions.
*/
function sanitizeElementId(id) {
if (!id.match(/^[a-zA-Z_]/)) {
id = '_' + id;
}
return id.replace(/[^a-zA-Z0-9_\-:.]/g, '_');
}
class IPointerEvent {
constructor(event, target) {
this.event = event;
this.target = target;
this.event = event;
}
get originalEvent() {
return this.event;
}
get targetElement() {
return this.target || this.originalEvent.target;
}
setTarget(target) {
this.target = target;
}
preventDefault() {
this.originalEvent.preventDefault();
}
get isEventInLockedContext() {
return this.targetElement.closest('[fLockedContext]') !== null;
}
}
class IMouseEvent extends IPointerEvent {
constructor(event, target) {
super(event, target);
}
isMouseLeftButton() {
return this.originalEvent.button === 0;
}
isMouseRightButton() {
return this.originalEvent.buttons === 2;
}
getPosition() {
return { x: this.originalEvent.clientX, y: this.originalEvent.clientY };
}
}
class ITouchDownEvent extends IPointerEvent {
constructor(event) {
super(event);
}
isMouseLeftButton() {
return true;
}
isMouseRightButton() {
return false;
}
getPosition() {
return { x: this.originalEvent.touches[0].clientX, y: this.originalEvent.touches[0].clientY };
}
}
class ITouchMoveEvent extends IPointerEvent {
constructor(event, target) {
super(event, target);
}
isMouseLeftButton() {
return true;
}
isMouseRightButton() {
return false;
}
getPosition() {
return { x: this.originalEvent.targetTouches[0].clientX, y: this.originalEvent.targetTouches[0].clientY };
}
}
class ITouchUpEvent extends IPointerEvent {
constructor(event) {
super(event);
}
isMouseLeftButton() {
return true;
}
isMouseRightButton() {
return false;
}
getPosition() {
return { x: this.originalEvent.changedTouches[0].clientX, y: this.originalEvent.changedTouches[0].clientY };
}
}
class Arc {
constructor(center, radiusX, radiusY, startAngle, endAngle) {
this.center = center;
this.radiusX = radiusX;
this.radiusY = radiusY;
this.startAngle = startAngle;
this.endAngle = endAngle;
}
}
class BooleanExtensions {
static castToBoolean(value) {
return value != null && `${value}` !== 'false';
}
}
class EventExtensions {
static isPassiveEventListenerSupported() {
if (EventExtensions.isSupported == null && typeof window !== 'undefined') {
try {
window.addEventListener('test', EventExtensions.emptyListener, { passive: true });
EventExtensions.isSupported = true;
}
catch (e) {
EventExtensions.isSupported = false;
}
}
return EventExtensions.isSupported;
}
static passiveEventListener(options) {
return EventExtensions.isPassiveEventListenerSupported() ? options : !!options.capture;
}
static activeListener() {
return EventExtensions.passiveEventListener({ passive: false });
}
static passiveListener() {
return EventExtensions.passiveEventListener({ passive: true });
}
static emptyListener() {
return () => {
};
}
}
class GuidExtensions {
static generate() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
const r = Math.random() * 16 | 0;
const v = c === 'x' ? r : (r & 0x3 | 0x8);
return v.toString(16);
});
}
}
class PointExtensions {
static castToPoint(value) {
return value || PointExtensions.initialize();
}
static initialize(x = 0, y = 0) {
return { x: x, y: y };
}
static copy(point) {
return PointExtensions.initialize(point.x, point.y);
}
static isEqual(point1, point2) {
return point1.x === point2.x && point1.y === point2.y;
}
static sum(point1, point2) {
return { x: (point1.x + point2.x), y: (point1.y + point2.y) };
}
static sub(point1, point2) {
return { x: (point1.x - point2.x), y: (point1.y - point2.y) };
}
static div(point, value) {
return { x: (point.x / value), y: (point.y / value) };
}
static mult(point, value) {
return { x: (point.x * value), y: (point.y * value) };
}
static interpolatePoints(point1, point2, t) {
const oneMinusT = 1.0 - t;
return PointExtensions.initialize(point1.x * oneMinusT + point2.x * t, point1.y * oneMinusT + point2.y * t);
}
static roundTo(point, size) {
const xCount = Math.trunc(point.x / size);
const yCount = Math.trunc(point.y / size);
return { x: xCount * size, y: yCount * size };
}
static hypotenuse(point1, point2) {
const a = (point2.x - point1.x);
const b = (point2.y - point1.y);
return Math.abs(Math.sqrt(a * a + b * b));
}
static distance(point1, point2) {
const dx = point1.x - point2.x;
const dy = point1.y - point2.y;
return Math.sqrt(dx * dx + dy * dy);
}
static getMinimum(point1, point2) {
return PointExtensions.initialize(Math.min(point1.x, point2.x), Math.min(point1.y, point2.y));
}
static getMaximum(point1, point2) {
return PointExtensions.initialize(Math.max(point1.x, point2.x), Math.max(point1.y, point2.y));
}
static matrixTransform(point, element) {
let result = PointExtensions.initialize(point.x, point.y);
let matrix = element.getScreenCTM();
if (matrix) {
const svgPoint = element.createSVGPoint();
svgPoint.x = point.x;
svgPoint.y = point.y;
result = svgPoint.matrixTransform(matrix.inverse());
}
return result;
}
static elementTransform(point, element) {
let result = PointExtensions.initialize(point.x, point.y);
let matrix = element.getBoundingClientRect();
result = PointExtensions.sub(result, PointExtensions.initialize(matrix.left, matrix.top));
return result;
}
}
class Point {
constructor(x = 0, y = 0) {
this.x = x;
this.y = y;
}
static fromPoint(point) {
return new Point(point.x, point.y);
}
add(point) {
const result = PointExtensions.sum(this, point);
return Point.fromPoint(result);
}
sub(point) {
const result = PointExtensions.sub(this, point);
return Point.fromPoint(result);
}
subNumber(value) {
const result = PointExtensions.sub(this, new Point(value, value));
return Point.fromPoint(result);
}
div(value) {
const result = PointExtensions.div(this, value);
return Point.fromPoint(result);
}
mult(value) {
const result = PointExtensions.mult(this, value);
return Point.fromPoint(result);
}
matrixTransform(element) {
const result = PointExtensions.matrixTransform(this, element);
return Point.fromPoint(result);
}
elementTransform(element) {
const result = PointExtensions.elementTransform(this, element);
return Point.fromPoint(result);
}
}
class LineExtensions {
static initialize(point1 = PointExtensions.initialize(), point2 = PointExtensions.initialize()) {
return { point1, point2 };
}
static copy(line) {
return { point1: line.point1, point2: line.point2 };
}
static hypotenuse(line) {
return Math.sqrt(Math.pow((line.point1.x - line.point2.x), 2) +
Math.pow((line.point1.y - line.point2.y), 2));
}
}
class Line {
constructor(point1, point2) {
this.point1 = point1;
this.point2 = point2;
}
}
class NumberExtensions {
static castToNumber(value, fallbackValue = 0) {
return NumberExtensions.isNumberValue(value) ? Number(value) : fallbackValue;
}
static isNumberValue(value) {
return !isNaN(parseFloat(value)) && !isNaN(Number(value));
}
}
class RectExtensions {
static initialize(x = 0, y = 0, width = 0, height = 0) {
if (width < 0) {
x = x + width;
width = -width;
}
if (height < 0) {
y = y + height;
height = -height;
}
const gravityCenter = PointExtensions.initialize(x + (width / 2), y + (height / 2));
return { x: x, y: y, width: width, height: height, gravityCenter: gravityCenter };
}
static copy(rect) {
return RectExtensions.initialize(rect.x, rect.y, rect.width, rect.height);
}
static fromElement(element) {
const { x, y, width, height } = element.getBoundingClientRect();
return RectExtensions.initialize(x, y, width, height);
}
static isIncludePoint(rect, point) {
return point.x >= RectExtensions.left(rect) && point.x <= RectExtensions.right(rect) && point.y >= RectExtensions.top(rect) && point.y <= RectExtensions.bottom(rect);
}
static intersectionWithRect(rect1, rect2) {
return !(rect1.x + rect1.width < rect2.x ||
rect2.x + rect2.width < rect1.x ||
rect1.y + rect1.height < rect2.y ||
rect2.y + rect2.height < rect1.y);
}
static left(rect) {
return rect.x;
}
static top(rect) {
return rect.y;
}
static right(rect) {
return rect.x + rect.width;
}
static bottom(rect) {
return rect.y + rect.height;
}
static addPoint(rect, point) {
const rectCopy = RectExtensions.copy(rect);
rectCopy.x += point.x;
rectCopy.y += point.y;
return this.initialize(rectCopy.x, rectCopy.y, rectCopy.width, rectCopy.height);
}
static mult(rect, value) {
const rectCopy = RectExtensions.copy(rect);
rectCopy.x *= value;
rectCopy.y *= value;
rectCopy.width *= value;
rectCopy.height *= value;
return this.initialize(rectCopy.x, rectCopy.y, rectCopy.width, rectCopy.height);
}
static div(rect, value) {
const rectCopy = RectExtensions.copy(rect);
rectCopy.x /= value;
rectCopy.y /= value;
rectCopy.width /= value;
rectCopy.height /= value;
return this.initialize(rectCopy.x, rectCopy.y, rectCopy.width, rectCopy.height);
}
static addPointToSize(rect, point) {
const rectCopy = RectExtensions.copy(rect);
rectCopy.width += point.x;
rectCopy.height += point.y;
return this.initialize(rectCopy.x, rectCopy.y, rectCopy.width, rectCopy.height);
}
static union(rects) {
if (!rects || rects.length === 0) {
return null;
}
return rects.reduce((result, rect) => {
const minX = Math.min(result.x, rect.x);
const minY = Math.min(result.y, rect.y);
const maxX = Math.max(result.x + result.width, rect.x + rect.width);
const maxY = Math.max(result.y + result.height, rect.y + rect.height);
return RectExtensions.initialize(minX, minY, maxX - minX, maxY - minY);
}, rects[0]);
}
static elementTransform(rect, element) {
const matrix = element.getBoundingClientRect();
const position = PointExtensions.sub(rect, PointExtensions.initialize(matrix.left, matrix.top));
return RectExtensions.initialize(position.x, position.y, rect.width, rect.height);
}
}
class SizeExtensions {
static initialize(width = 0, height = 0) {
return { width, height };
}
}
function defaultTransformModel() {
return {
position: PointExtensions.initialize(),
scaledPosition: PointExtensions.initialize(),
scale: 1,
rotate: 0
};
}
function parseTransformModel(value) {
let result;
if (value) {
value = value.replace('matrix(', '');
value = value.replace(')', '');
const values = value.split(' ');
result = {
position: {
x: Number(values[4]),
y: Number(values[5])
},
scaledPosition: PointExtensions.initialize(),
scale: Number(values[0]),
rotate: 0
};
}
return result;
}
class TransformModelExtensions {
static toString(transform) {
const position = PointExtensions.sum(transform.position, transform.scaledPosition);
return `matrix(${transform.scale}, 0, 0, ${transform.scale}, ${position.x}, ${position.y})`;
}
static fromString(value) {
return parseTransformModel(value);
}
static default() {
return defaultTransformModel();
}
}
class VectorExtensions {
static initialize(x = 0, y = 0) {
return PointExtensions.initialize(x, y);
}
static fromPoints(p1, p2) {
return VectorExtensions.initialize(p2.x - p1.x, p2.y - p1.y);
}
static vectorLength(v) {
return Math.sqrt(VectorExtensions.magnitudeSquared(v));
}
static magnitudeSquared(v) {
return v.x * v.x + v.y * v.y;
}
static dotProduct(v1, v2) {
return v1.x * v2.x + v1.y * v2.y;
}
static crossProduct(v1, v2) {
return v1.x * v2.y - v1.y * v2.x;
}
static subtract(v1, v2) {
return VectorExtensions.initialize(v1.x - v2.x, v1.y - v2.y);
}
static add(v1, v2) {
return VectorExtensions.initialize(v1.x + v2.x, v1.y + v2.y);
}
static scale(v, value) {
return VectorExtensions.initialize(v.x * value, v.y * value);
}
static angle(v1, v2) {
const radians = Math.acos(Math.max(-1, Math.min(VectorExtensions.dotProduct(v1, v2) / (VectorExtensions.vectorLength(v1) * VectorExtensions.vectorLength(v2)), 1)));
return (VectorExtensions.crossProduct(v1, v2) < 0.0) ? -radians : radians;
}
}
const MOUSE_EVENT_IGNORE_TIME = 800;
class IDragAndDropBase {
constructor(ngZone) {
this.ngZone = ngZone;
this.mouseListeners = EventExtensions.emptyListener();
this.touchListeners = EventExtensions.emptyListener();
this.startListeners = EventExtensions.emptyListener();
this.lastTouchEventTime = 0;
this.isDragStarted = false;
this.dragStartThreshold = 5;
this.dragStartDelay = 0;
this.dragStartTime = 0;
this.dragStartPosition = PointExtensions.initialize();
this.moveHandler = this.checkDragSequenceToStart;
this.onMouseDown = (event) => {
const isSyntheticEvent = this.isSyntheticEvent(event);
const isFakeEvent = isFakeMousedownFromScreenReader(event);
const mouseEvent = new IMouseEvent(event);
if (isSyntheticEvent || isFakeEvent || this.disabled) {
return;
}
let result = this.onPointerDown(mouseEvent);
if (result) {
this.dragStartTime = Date.now();
this.dragStartPosition = mouseEvent.getPosition();
this.ngZone.runOutsideAngular(() => {
this.element.addEventListener('mousemove', this.onMouseMove);
this.element.addEventListener('mouseup', this.onMouseUp);
});
this.mouseListeners = () => {
this.element.removeEventListener('mousemove', this.onMouseMove);
this.element.removeEventListener('mouseup', this.onMouseUp);
};
}
};
this.onTouchDown = (event) => {
const isFakeEvent = isFakeTouchstartFromScreenReader(event);
const touchEvent = new ITouchDownEvent(event);
if (isFakeEvent || this.disabled) {
return;
}
let result = this.onPointerDown(new ITouchDownEvent(event));
if (result) {
this.dragStartTime = Date.now();
this.dragStartPosition = touchEvent.getPosition();
this.ngZone.runOutsideAngular(() => {
this.element.addEventListener('touchmove', this.onTouchMove);
this.element.addEventListener('touchend', this.onTouchUp);
});
this.touchListeners = () => {
this.element.removeEventListener('touchmove', this.onTouchMove);
this.element.removeEventListener('touchend', this.onTouchUp);
};
}
};
this.onMouseMove = (event) => {
this.moveHandler(new IMouseEvent(event));
};
this.onTouchMove = (event) => {
this.moveHandler(new ITouchMoveEvent(event));
};
this.onMouseUp = (event) => {
if (this.isDragStarted) {
this.onPointerUp(new IMouseEvent(event));
}
this.endDragSequence();
};
this.onTouchUp = (event) => {
if (this.isDragStarted) {
this.onPointerUp(new ITouchUpEvent(event));
}
this.endDragSequence();
};
}
isSyntheticEvent(event) {
return !!this.lastTouchEventTime &&
(this.lastTouchEventTime + MOUSE_EVENT_IGNORE_TIME > Date.now());
}
checkDragSequenceToStart(event) {
const pointerPosition = event.getPosition();
if (!this.isDragStarted) {
const distanceX = Math.abs(pointerPosition.x - this.dragStartPosition.x);
const distanceY = Math.abs(pointerPosition.y - this.dragStartPosition.y);
const isOverThreshold = distanceX + distanceY >= this.dragStartThreshold;
if (isOverThreshold) {
const isDelayElapsed = Date.now() >= this.dragStartTime + this.dragStartDelay;
if (!isDelayElapsed) {
this.endDragSequence();
return;
}
event.preventDefault();
this.prepareDragSequence(event);
this.isDragStarted = true;
this.moveHandler = this.onPointerMove;
if (isTouchEvent(event.originalEvent)) {
this.lastTouchEventTime = Date.now();
}
}
}
}
endDragSequence() {
this.isDragStarted = false;
this.moveHandler = this.checkDragSequenceToStart;
this.mouseListeners();
this.mouseListeners = EventExtensions.emptyListener();
this.touchListeners();
this.touchListeners = EventExtensions.emptyListener();
}
subscribe(elementToSubscribe) {
if (this.element) {
this.unsubscribe();
}
this.element = elementToSubscribe;
this.ngZone.runOutsideAngular(() => {
this.element.addEventListener('mousedown', this.onMouseDown, EventExtensions.activeListener());
this.element.addEventListener('touchstart', this.onTouchDown, EventExtensions.passiveListener());
});
this.startListeners = () => {
this.element.removeEventListener('mousedown', this.onMouseDown, EventExtensions.activeListener());
this.element.removeEventListener('touchstart', this.onTouchDown, EventExtensions.passiveListener());
};
}
unsubscribe() {
this.startListeners();
this.startListeners = EventExtensions.emptyListener();
this.touchListeners();
this.touchListeners = EventExtensions.emptyListener();
this.mouseListeners();
this.mouseListeners = EventExtensions.emptyListener();
}
}
function isTouchEvent(event) {
return event.type[0] === 't';
}
function isFakeMousedownFromScreenReader(event) {
return event.buttons === 0 || (event.offsetX === 0 && event.offsetY === 0);
}
function isFakeTouchstartFromScreenReader(event) {
const touch = (event.touches && event.touches[0]) || (event.changedTouches && event.changedTouches[0]);
return (!!touch &&
touch.identifier === -1 &&
(touch.radiusX == null || touch.radiusX === 1) &&
(touch.radiusY == null || touch.radiusY === 1));
}
/**
* @deprecated This class is deprecated and will be removed in future versions.
* Please use @foblex/platform instead.
*/
var EOperationSystem;
(function (EOperationSystem) {
EOperationSystem["MAC_OS"] = "macos";
EOperationSystem["IOS"] = "ios";
EOperationSystem["WINDOWS"] = "windows";
EOperationSystem["ANDROID"] = "android";
EOperationSystem["LINUX"] = "linux";
})(EOperationSystem || (EOperationSystem = {}));
/**
* @deprecated This class is deprecated and will be removed in future versions.
*/
class MouseEventExtensions {
static isContextMenuEvent(event) {
return event.type === 'contextmenu';
}
static isMouseMiddleButtonClickEvent(event) {
return event.type === 'auxclick' && event.button === 1;
}
static isClickEvent(event) {
return event.type === 'click';
}
static isCtrlPressed(event) {
return event.ctrlKey || event.metaKey;
}
static isShiftPressed(event) {
return event.shiftKey;
}
static fakeEvent() {
return {
shiftKey: false, ctrlKey: false, metaKey: false, altKey: false,
preventDefault: () => {
}
};
}
static fakeCommandEvent() {
return {
shiftKey: false, ctrlKey: false, metaKey: true, altKey: false,
type: 'click',
preventDefault: () => {
}
};
}
static isCommandButton(platform, event) {
return platform === EOperationSystem.MAC_OS ? event.metaKey : event.ctrlKey;
}
}
let hasV8BreakIterator;
try {
hasV8BreakIterator = typeof Intl !== 'undefined' && Intl.v8BreakIterator;
}
catch (_a) {
hasV8BreakIterator = false;
}
/**
* @deprecated This class is deprecated and will be removed in future versions.
* Please use @foblex/platform instead.
*/
class PlatformService {
constructor(_platformId) {
this._platformId = _platformId;
this.isBrowser = this._platformId
? isPlatformBrowser(this._platformId)
: typeof document === 'object' && !!document;
this.EDGE = this.isBrowser && /(edge)/i.test(navigator.userAgent);
this.TRIDENT = this.isBrowser && /(msie|trident)/i.test(navigator.userAgent);
this.BLINK = this.isBrowser &&
!!(window.chrome || hasV8BreakIterator) &&
typeof CSS !== 'undefined' &&
!this.EDGE &&
!this.TRIDENT;
this.WEBKIT = this.isBrowser &&
/AppleWebKit/i.test(navigator.userAgent) &&
!this.BLINK &&
!this.EDGE &&
!this.TRIDENT;
this.IOS = this.isBrowser && /iPad|iPhone|iPod/.test(navigator.userAgent) && !('MSStream' in window);
this.FIREFOX = this.isBrowser && /(firefox|minefield)/i.test(navigator.userAgent);
this.ANDROID = this.isBrowser && /android/i.test(navigator.userAgent) && !this.TRIDENT;
this.SAFARI = this.isBrowser && /safari/i.test(navigator.userAgent) && this.WEBKIT;
}
getOS() {
let userAgent = navigator.userAgent.toLowerCase(), macosPlatforms = /(macintosh|macintel|macppc|mac68k|macos)/i, windowsPlatforms = /(win32|win64|windows|wince)/i;
let result;
if (macosPlatforms.test(userAgent)) {
result = EOperationSystem.MAC_OS;
}
else if (this.IOS) {
result = EOperationSystem.IOS;
}
else if (windowsPlatforms.test(userAgent)) {
result = EOperationSystem.WINDOWS;
}
else if (this.ANDROID) {
result = EOperationSystem.ANDROID;
}
else if (!result && /linux/.test(userAgent)) {
result = EOperationSystem.LINUX;
}
return result;
}
}
PlatformService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: PlatformService, deps: [{ token: PLATFORM_ID }], target: i0.ɵɵFactoryTarget.Injectable });
PlatformService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: PlatformService, providedIn: 'root' });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: PlatformService, decorators: [{
type: Injectable,
args: [{ providedIn: 'root' }]
}], ctorParameters: function () { return [{ type: Object, decorators: [{
type: Inject,
args: [PLATFORM_ID]
}] }]; } });
function mixinChangeZoom(base) {
return class extends base {
setZoom(scaleValue, toPosition) {
if (scaleValue !== this.transform.scale) {
const summaryPosition = PointExtensions.sum(this.transform.scaledPosition, this.transform.position);
const newX = toPosition.x - (toPosition.x - summaryPosition.x) * scaleValue / this.transform.scale;
const newY = toPosition.y - (toPosition.y - summaryPosition.y) * scaleValue / this.transform.scale;
this.transform.scale = scaleValue;
this.transform.scaledPosition = PointExtensions.sub(PointExtensions.initialize(newX, newY), this.transform.position);
}
}
setScalePosition(value) {
this.transform.scaledPosition = value;
}
resetZoom() {
this.transform.scale = 1;
this.transform.scaledPosition = PointExtensions.initialize();
}
constructor(...args) {
super(...args);
}
};
}
function mixinFitToParent(base) {
return class extends base {
fitToParent(rect, parentRect, points, toCenter) {
this.transform.scaledPosition = PointExtensions.initialize();
this.transform.position = this.getZeroPositionWithoutScale(points);
const itemsContainerWidth = (rect.width / this.transform.scale) + toCenter.x;
const itemsContainerHeight = (rect.height / this.transform.scale) + toCenter.y;
if ((itemsContainerWidth > parentRect.width || itemsContainerHeight > parentRect.height) ||
itemsContainerWidth < parentRect.width && itemsContainerHeight < parentRect.height) {
this.transform.scale = Math.min(parentRect.width / itemsContainerWidth, parentRect.height / itemsContainerHeight);
}
const newX = (parentRect.width - itemsContainerWidth * this.transform.scale) / 2 - this.transform.position.x * this.transform.scale;
const newY = (parentRect.height - itemsContainerHeight * this.transform.scale) / 2 - this.transform.position.y * this.transform.scale;
this.transform.position = PointExtensions.initialize(newX + (toCenter.x / 2) * this.transform.scale, newY + (toCenter.y / 2) * this.transform.scale);
}
getZeroPositionWithoutScale(points) {
const xPoint = points.length ? Math.min(...points.map((point) => point.x)) : 0;
const yPoint = points.length ? Math.min(...points.map((point) => point.y)) : 0;
return PointExtensions.initialize(xPoint, yPoint);
}
constructor(...args) {
super(...args);
}
};
}
function mixinOneToOneCentering(base) {
return class extends base {
oneToOneCentering(rect, parentRect, points) {
this.transform.scaledPosition = PointExtensions.initialize();
this.transform.position = this.getZeroPositionWithoutScale(points);
const itemsContainerWidth = rect.width / this.transform.scale;
const itemsContainerHeight = rect.height / this.transform.scale;
this.transform.scale = 1;
const newX = (parentRect.width - itemsContainerWidth * this.transform.scale) / 2 - this.transform.position.x * this.transform.scale;
const newY = (parentRect.height - itemsContainerHeight * this.transform.scale) / 2 - this.transform.position.y * this.transform.scale;
this.transform.position = PointExtensions.initialize(newX, newY);
}
getZeroPositionWithoutScale(points) {
const xPoint = points.length ? Math.min(...points.map((point) => point.x)) : 0;
const yPoint = points.length ? Math.min(...points.map((point) => point.y)) : 0;
return PointExtensions.initialize(xPoint, yPoint);
}
constructor(...args) {
super(...args);
}
};
}
function mixinChangePosition(base) {
return class extends base {
getPosition() {
return this.transform.position;
}
setPosition(position) {
this.transform.position = PointExtensions.copy(position);
}
constructor(...args) {
super(...args);
}
};
}
/**
* Generated bundle index. Do not edit.
*/
export { Arc, BooleanExtensions, DomElementExtensions, EOperationSystem, EventExtensions, GuidExtensions, IDragAndDropBase, IMouseEvent, IPointerEvent, ITouchDownEvent, ITouchMoveEvent, ITouchUpEvent, Line, LineExtensions, MOUSE_EVENT_IGNORE_TIME, MouseEventExtensions, NumberExtensions, PlatformService, Point, PointExtensions, RectExtensions, SizeExtensions, TransformModelExtensions, VectorExtensions, defaultTransformModel, mixinChangePosition, mixinChangeZoom, mixinFitToParent, mixinOneToOneCentering, parseTransformModel, sanitizeElementId };
//# sourceMappingURL=foblex-core.js.map