UNPKG

@circe/core

Version:

Circe Components for Angular :: Core Services and Tools

1,246 lines (1,218 loc) 45 kB
import { Injectable, Pipe, NgModule } from '@angular/core'; import { CommonModule } from '@angular/common'; import { startCase, kebabCase, camelCase } from 'lodash-es'; import { v4 } from 'uuid'; import dayjs from 'dayjs'; import { DomSanitizer } from '@angular/platform-browser'; import { OrderPipe, OrderModule } from 'ngx-order-pipe'; import { Subject } from 'rxjs'; // ############################################# // ###### OPTION CONSTANTS DEFINITION API ###### // ############################################# const npaStringTransform = { start: 'start', camel: 'camel', kebab: 'kebab' }; class ToolService { constructor() { this.months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']; this.yiqHumanThreshold = 128; } static getValueFromMultiLevelObject(object, key, separator) { const _separator = separator || '.'; if (object[key] !== undefined) { return object[key]; } try { return key.split(_separator).reduce((obj, index) => { return obj[index]; }, object); } catch (e) { if (e instanceof TypeError) { return undefined; } else { throw e; } } } static setValueInMultiLevelObject(object, key, value, separator) { const _separator = separator || '.'; return key.split(_separator).reduce((o, i) => { if (o && typeof o[i] === 'object') { return o[i]; } if (o && i in o) { o[i] = value; return o; } }, object); } static waitFor(milliseconds) { const _now = Date.now(); let _timeOut = false; do { _timeOut = (Date.now() - _now >= milliseconds); } while (!_timeOut); } /** * repeatedValuesInArray * @description * This method returns an array of uniques values if parameter "unique" is true; or returns * an array of ONLY repeated values (unique values are discarded) if unique is false. * Default value por parameter unique is true. */ static repeatedValuesInArray(values, unique) { const _unique = (unique === undefined) ? true : unique; return (_unique) ? Array.from(new Set(values)) : values.filter((e, i) => values.indexOf(e) !== i); } static checkLastChar(text, char) { if (text && text[text.length - 1] !== char) { return `${text}${char}`; } return text; } static hexToRgb(hex) { const _output = hex .replace(/^#?([a-f\d])([a-f\d])([a-f\d])$/i, (m, r, g, b) => '#' + r + r + g + g + b + b) .substring(1) .match(/.{2}/g); return _output.map((e) => parseInt(e, 16)); } static rgbToHex(r, g, b) { const _output = [r, g, b].map((e) => { const _hex = e.toString(16); return (_hex.length === 1) ? `0${_hex}` : _hex; }); return _output.join(''); } static rgbToCmyk(r, g, b) { let _output = [r, g, b].map((e) => 1 - (e / 255)); const k = Math.min(_output[0], Math.min(_output[1], _output[2])); _output = _output.map((e) => (e - k) / (1 - k)); _output.push(k); _output = _output.map((e) => Math.round(e * 100)).map((e) => e || 0); return _output; } /** * getColorYIQ * @description * This method returns de YIQ model (color space) from a given color. * Can receive single argument (hex color string) or three number arguments (rgb color). */ static getColorYIQ(...arg) { let _color = arg; if (arg.length === 1 && typeof arg[0] === 'string') { _color = this.hexToRgb(arg[0]); } if (_color.length === 3 && typeof _color[0] === 'number' && typeof _color[1] === 'number' && typeof _color[2] === 'number') { return ((_color[0] * 299) + (_color[1] * 587) + (_color[2] * 114)) / 1000; } return null; } /** * generateUuid * @description * Generates a new uuid using uuid dependency. */ static generateUuid() { return v4(); } /** * checkArray * @description * Returns true if parameter given "array" is an array, otherwise returns false; * If optional parameter "filled" is given, then this method checks the array is not empty. * Default value for "filled" is true. */ static checkArray(array, filled = true) { const _checkStructure = (!!array && Array.isArray(array)); if (filled) { return (_checkStructure && !!array.length); } return _checkStructure; } static isEmail(email) { const expr = /^([\w-.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(]?)$/; return expr.test(email); } /** * @deprecated */ static getValueFromDotedKey(object, dotedKey, separator) { const _separator = separator || '.'; if (object[dotedKey] !== undefined) { return object[dotedKey]; } try { return dotedKey.split(_separator).reduce((obj, index) => { return obj[index]; }, object); } catch (e) { if (e instanceof TypeError) { return undefined; } else { throw e; } } } /** * @deprecated */ static formatString(text) { if (isNaN(Number(text))) { return startCase(text); } else { return text; } } identifier(index, item) { let _output = (typeof item === 'string') ? item : index; ['code', 'id', 'param', 'key'].forEach((e) => { if (item.hasOwnProperty(e)) { _output = item[e]; return; } }); return _output; } stringTransform(text, transformType) { const _transformType = transformType || npaStringTransform.start; let _output = text; if (isNaN(Number(text))) { switch (_transformType) { case npaStringTransform.start: _output = startCase(text); break; case npaStringTransform.camel: _output = camelCase(text); break; case npaStringTransform.kebab: _output = kebabCase(text); break; } } return _output; } } ToolService.decorators = [ { type: Injectable } ]; ToolService.ctorParameters = () => []; // ############################################### // ###### POSITION CONSTANTS DEFINITION API ###### // ############################################### const npaHashTypes = { class: 'class', tag: 'tag', id: 'id' }; const npaElementFields = { name: 'name', type: 'type', query: 'query', shadowElement: 'shadowElement' }; const boxModelTypeConstants = { HORIZONTAL: 'horizontal', VERTICAL: 'vertical' }; class BoxModelService { constructor() { this._defaultBoxModelType = boxModelTypeConstants.VERTICAL; this._defaultElementHashType = npaHashTypes.class; this._defaultComputedStylePropertyProcessed = false; this._allowCssUnits = ['px', '%']; this._additionHorizontalInsideClasses = ['padding-left', 'padding-right', 'border-left-width', 'border-right-width']; this._additionHorizontalOutsideClasses = ['margin-left', 'margin-right']; this._additionVerticalInsideClasses = ['padding-top', 'padding-bottom', 'border-top-width', 'border-bottom-width']; this._additionVerticalOutsideClasses = ['margin-top', 'margin-bottom']; this._fontSizeRule = { applyOnElements: ['i'], boxModelType: boxModelTypeConstants.HORIZONTAL }; } /** * _isElementHash * * @description * Checks if element given param is ElementHash type. */ static _isElementHash(element) { return !!(typeof element === 'object' && npaElementFields.type in element && npaElementFields.name in element && (Object.keys(element).length === 2 || Object.keys(element).length === 3)); } /** * _isElementQuery * * @description * Checks if element given param is ElementQuery type. */ static _isElementQuery(element) { return !!(typeof element === 'object' && npaElementFields.query in element && (Object.keys(element).length === 1 || Object.keys(element).length === 2)); } /** * _isNativeDomElement * * @description * Checks if element given param is a native DOM element. */ static _isNativeDomElement(param) { const _paramsToCheck = [ 'getBoundingClientRect', 'getElementsByClassName', 'getElementsByTagName', 'querySelector' ]; return (!!param) ? (_paramsToCheck.map((e) => e in param)).every((el) => !!el) : false; } /** * getSizeValues * * @description * Get computed height and width from a SizeObject. */ static getSizeUnits(sizeObject) { return { height: sizeObject.height.value + sizeObject.height.unit, width: sizeObject.width.value + sizeObject.height.unit }; } /** * _convertToElementIdArray * * @description * Transform elementId type to array of Dom elements. */ _convertToElementIdArray(elementId) { const _auxArgument = []; const _elementId = (Array.isArray(elementId)) ? elementId : [elementId]; for (const element of _elementId) { _auxArgument.push(this.getElement(element)); } return _auxArgument; } _getElementAdditions(element, boxModelType) { const _type = boxModelType || this._defaultBoxModelType; const _elementStyle = window.getComputedStyle(element); const _output = { boxModelAdditionInside: 0, boxModelAdditionOutside: 0 }; const _auxOutputInside = []; const _auxOutputOutside = []; if (_type === boxModelTypeConstants.HORIZONTAL) { this._additionHorizontalInsideClasses.forEach((e) => { _auxOutputInside.push(_elementStyle.getPropertyValue(e)); }); this._additionHorizontalOutsideClasses.forEach((e) => { _auxOutputOutside.push(_elementStyle.getPropertyValue(e)); }); } else { this._additionVerticalInsideClasses.forEach((e) => { _auxOutputInside.push(_elementStyle.getPropertyValue(e)); }); this._additionVerticalOutsideClasses.forEach((e) => { _auxOutputOutside.push(_elementStyle.getPropertyValue(e)); }); } _auxOutputInside.forEach((el) => { if (el !== '0px') { _output.boxModelAdditionInside += this.readCssUnits(el).value; } }); _auxOutputOutside.forEach((el) => { if (el !== '0px') { _output.boxModelAdditionOutside += this.readCssUnits(el).value; } }); return _output; } getComputedStyleProperty(element, property, processed) { const _processed = processed || this._defaultComputedStylePropertyProcessed; const _elementComputedStyles = window.getComputedStyle(element); const _output = _elementComputedStyles.getPropertyValue(property); if (_output && _processed) { return this.readCssUnits(_output); } return _output; } processElementForSpecialRules(element) { if (this._fontSizeRule.applyOnElements.includes(element.tagName.toLowerCase())) { const _elementBoxModel = this.getBoxModel(element, boxModelTypeConstants.HORIZONTAL); const _elementFontSize = this.getComputedStyleProperty(element, 'font-size', true); if (_elementBoxModel.boxModelExtractedInside !== _elementFontSize.value) { element.style.width = `${_elementFontSize.value}px`; return element; } } return element; } readCssUnits(expression) { const _output = { value: 0, unit: '' }; this._allowCssUnits.forEach((e) => { if (expression.includes(e)) { _output.unit = e; const _aux = expression.split(e).filter((el) => !!el); if (_aux.length === 1) { _output.value = Number(_aux[0]); } return; } }); return (_output.value && _output.unit) ? _output : null; } processSizeString(sizeString) { const _output = { width: null, height: null }; if (sizeString) { const _auxSize = sizeString.split(' '); if (_auxSize.length === 1) { const _cssUnit = this.readCssUnits(_auxSize[0]); _output.width = _cssUnit; _output.height = _cssUnit; } else if (_auxSize.length === 2) { _output.height = this.readCssUnits(_auxSize[0]); _output.width = this.readCssUnits(_auxSize[1]); } } return (_output.width && _output.height) ? _output : null; } /** * getElement * * @description * Returns an element DOM native object from different types of given params. */ getElement(element) { let _output = element; let _element = element; let _shadowElement = document; if (typeof element === 'string') { _element = { type: this._defaultElementHashType, name: element }; } else { if (npaElementFields.shadowElement in _element) { _shadowElement = this.getElement(_element.shadowElement); } } if (!BoxModelService._isNativeDomElement(_element)) { if (BoxModelService._isElementHash(_element)) { switch (_element.type) { case npaHashTypes.class: _output = _shadowElement.getElementsByClassName(_element.name).item(0); break; case npaHashTypes.tag: _output = _shadowElement.getElementsByTagName(_element.name).item(0); break; case npaHashTypes.id: _output = document.getElementById(_element.name); break; } } else if (BoxModelService._isElementQuery(_element)) { _output = _shadowElement.querySelector(_element.query); } } if (!BoxModelService._isNativeDomElement(_output)) { throw new Error('BoxModel.getElement: Unrecognizable element.'); } return _output; } getDimensions(element) { let _output; const _element = this.getElement(element); if (!!_element) { const _elementRect = _element.getBoundingClientRect(); _output = { height: { value: _elementRect.height, unit: 'px' }, width: { value: _elementRect.width, unit: 'px' } }; } return _output; } getBoxModel(elementId, boxModelType) { const _output = { type: boxModelType || this._defaultBoxModelType, boxModel: 0, boxModelAdditions: 0, boxModelAggregated: 0, boxModelExtracted: 0, boxModelAdditionsInside: 0, boxModelAdditionsOutside: 0, boxModelAggregatedInside: 0, boxModelAggregatedOutside: 0, boxModelExtractedInside: 0, boxModelExtractedOutside: 0 }; const _elementId = this._convertToElementIdArray(elementId); _elementId.forEach((e) => { const _elementRect = e.getBoundingClientRect(); const _additions = this._getElementAdditions(e, _output.type); _output.boxModel += (_output.type === boxModelTypeConstants.HORIZONTAL) ? _elementRect.width : _elementRect.height; _output.boxModelAdditions += _additions.boxModelAdditionInside + _additions.boxModelAdditionOutside; _output.boxModelAdditionsInside += _additions.boxModelAdditionInside; _output.boxModelAdditionsOutside += _additions.boxModelAdditionOutside; }); _output.boxModelAggregated = _output.boxModel + _output.boxModelAdditions; _output.boxModelExtracted = _output.boxModel - _output.boxModelAdditions; _output.boxModelAggregatedInside = _output.boxModel + _output.boxModelAdditionsInside; _output.boxModelAggregatedOutside = _output.boxModel + _output.boxModelAdditionsOutside; _output.boxModelExtractedInside = _output.boxModel - _output.boxModelAdditionsInside; _output.boxModelExtractedOutside = _output.boxModel - _output.boxModelAdditionsOutside; return _output; } } BoxModelService.decorators = [ { type: Injectable } ]; BoxModelService.ctorParameters = () => []; class EventsService { constructor(_bm) { this._bm = _bm; this._defaultEventImmediatePropagation = true; this._defaultSelectDomElement = { type: npaHashTypes.tag, name: 'main' }; } preventNeededEvent(event, immediatePropagation) { const _immediate = immediatePropagation || this._defaultEventImmediatePropagation; if (_immediate) { event.stopImmediatePropagation(); } else { event.stopPropagation(); } } preventNoNeededEvent(event, immediatePropagation) { const _immediate = immediatePropagation || this._defaultEventImmediatePropagation; this.preventNeededEvent(event, _immediate); if (event.cancelable) { event.preventDefault(); } } scrollTop(element) { const _element = element || this._defaultSelectDomElement; const _target = this._bm.getElement(_element); if (_target) { _target.scroll(0, 0); } } /** * @deprecated */ preventMouseEvent(event, immediatePropagation) { const _immediate = immediatePropagation || this._defaultEventImmediatePropagation; if (_immediate) { event.stopImmediatePropagation(); } else { event.stopPropagation(); } event.preventDefault(); } /** * @deprecated */ preventKeyEvent(event, immediatePropagation) { const _immediate = immediatePropagation || this._defaultEventImmediatePropagation; if (_immediate) { event.stopImmediatePropagation(); } else { event.stopPropagation(); } } } EventsService.decorators = [ { type: Injectable } ]; EventsService.ctorParameters = () => [ { type: BoxModelService } ]; dayjs().format(); // @dynamic class CustomValidationService { constructor() { } static arrayRepeatedValues(control) { var _a; let _output = null; const previousLength = (_a = control.value) === null || _a === void 0 ? void 0 : _a.length; const _repeatedValues = ToolService.repeatedValuesInArray(control.value); if (_repeatedValues && Array.isArray(_repeatedValues) && _repeatedValues.length !== previousLength) { _output = { repeated: CustomValidationService.customMessages.repeated }; } return _output; } static arrayMinValues(minItems) { return (c) => { return c.value.length < minItems ? { arrayMinValues: `There must be at least ${minItems} items.` } : null; }; } static arrayMaxValues(maxItems) { return (c) => { return c.value.lenth > maxItems ? { arrayMaxValues: `There must be ${maxItems} items as maximum.` } : null; }; } static arrayOnlyNumberValues(control) { return control.value.every(v => /^[+-]?(\d+)?(\.\d+)?$/.test(v)) ? null : { arrayOnlyNumber: CustomValidationService.customMessages.arrayOnlyNumber }; } static arrayOnlyIntegerValues(control) { return control.value.every(v => /^[+-]?\d+$/.test(v)) ? null : { arrayOnlyInteger: CustomValidationService.customMessages.arrayOnlyInteger }; } static arrayRequired(control) { return control.dirty && !control.value.length ? { arrayRequired: CustomValidationService.customMessages.arrayRequired } : null; } static arrayPattern(pattern) { return (control) => { const regexp = new RegExp(pattern); return control.value.every(v => regexp.test(v)) ? null : { arrayPattern: CustomValidationService.customMessages.arrayPattern }; }; } static dateValidator(c) { if (c.value === 'MM/DD/YYYY') { return null; } return c.pristine || dayjs(c.value).isValid() ? null : { invalidDate: 'Invalid date.' }; } static dateRequiredValidator(c) { return c.touched && c.value === 'MM/DD/YYYY' ? { dateRequired: 'Required value.' } : null; } static dateDisableBeforeCurrentDayValidator(c) { if (!dayjs(c.value).isValid()) { return null; } return dayjs().isAfter(c.value, 'day') ? { disableBeforeCurrentDay: 'The date must be greater than current day.' } : null; } static dateDisableAfterCurrentDayValidator(c) { if (!dayjs(c.value).isValid()) { return null; } return dayjs().isBefore(c.value, 'day') ? { disableAfterCurrentDay: 'The date must be lower than current day.' } : null; } static dateMinDateValidator(minDate) { return (c) => { if (!dayjs(c.value).isValid()) { return null; } return dayjs(minDate).isAfter(c.value, 'day') ? { minDate: `The date must be greater than ${dayjs(minDate).format('L')}.` } : null; }; } static dateMaxDateValidator(maxDate) { return (c) => { if (!dayjs(c.value).isValid()) { return null; } return dayjs(maxDate).isBefore(c.value, 'day') ? { maxDate: `The date must be lower than ${dayjs(maxDate).format('L')}.` } : null; }; } } CustomValidationService.customMessages = { repeated: 'There can not be repeated values', arrayOnlyNumber: 'There can be only number values', arrayOnlyInteger: 'There can be only integer number values', arrayRequired: 'There must be at least 1 item', arrayPattern: 'All items must satisfied specified pattern' }; CustomValidationService.decorators = [ { type: Injectable } ]; CustomValidationService.ctorParameters = () => []; class SanitizeHtmlPipe { constructor(_sanitizer) { this._sanitizer = _sanitizer; } transform(value) { return this._sanitizer.bypassSecurityTrustHtml(value); } } SanitizeHtmlPipe.decorators = [ { type: Pipe, args: [{ name: 'sanitizeHtml' },] } ]; SanitizeHtmlPipe.ctorParameters = () => [ { type: DomSanitizer } ]; class SanitizeHtmlModule { } SanitizeHtmlModule.decorators = [ { type: NgModule, args: [{ exports: [SanitizeHtmlPipe], declarations: [SanitizeHtmlPipe], imports: [CommonModule] },] } ]; class OrderConditionPipe { constructor(_o) { this._o = _o; } transform(value, orderBy, condition, reverse, caseSensitive) { const _condition = (condition === undefined) ? true : !!condition; return (_condition) ? this._o.transform(value, orderBy, !!reverse, !!caseSensitive) : value; } } OrderConditionPipe.decorators = [ { type: Pipe, args: [{ name: 'orderCondition' },] } ]; OrderConditionPipe.ctorParameters = () => [ { type: OrderPipe } ]; class OrderConditionModule { } OrderConditionModule.decorators = [ { type: NgModule, args: [{ exports: [OrderConditionPipe], declarations: [OrderConditionPipe], imports: [ CommonModule, OrderModule ], providers: [OrderConditionPipe] },] } ]; // ############################################### // ###### POSITION CONSTANTS DEFINITION API ###### // ############################################### const npaPlacement = { topLeft: 'top left', topCenter: 'top center', topRight: 'top right', centerLeft: 'center left', centerCenter: 'center center', centerRight: 'center right', bottomLeft: 'bottom left', bottomCenter: 'bottom center', bottomRight: 'bottom right' }; const npaPlacementVertical = { top: 'top', center: 'center', bottom: 'bottom' }; const npaPlacementHorizontal = { left: 'left', center: 'center', right: 'right' }; const npaPlacementElementTypes = { RELATIVE: 'relative', HOST: 'host', CLIENT: 'client', SCROLL: 'scroll', BOUNDARY: 'boundary' }; const npaPlacementTypes = { POSITION: 'position', ORIENTATION: 'orientation' }; const npaPlacementInsideAutoOrientations = { [npaPlacement.topLeft]: npaPlacement.bottomRight, [npaPlacement.topCenter]: npaPlacement.bottomCenter, [npaPlacement.topRight]: npaPlacement.bottomLeft, [npaPlacement.centerLeft]: npaPlacement.centerRight, [npaPlacement.centerCenter]: npaPlacement.centerCenter, [npaPlacement.centerRight]: npaPlacement.centerLeft, [npaPlacement.bottomLeft]: npaPlacement.topRight, [npaPlacement.bottomCenter]: npaPlacement.topCenter, [npaPlacement.bottomRight]: npaPlacement.topLeft }; const npaPlacementInsideAutoMargins = { [npaPlacement.topLeft]: [1, 1], [npaPlacement.topCenter]: [1, 0], [npaPlacement.topRight]: [1, -1], [npaPlacement.centerLeft]: [0, 1], [npaPlacement.centerCenter]: [1, 1], [npaPlacement.centerRight]: [0, -1], [npaPlacement.bottomLeft]: [-1, 1], [npaPlacement.bottomCenter]: [-1, 0], [npaPlacement.bottomRight]: [-1, -1] }; class Placement { constructor(bm) { this._bm = bm; this._modV = 0; this._modH = 0; } _processPlacement(placement, type = npaPlacementTypes.POSITION) { const _placementArray = placement.split(' '); if ((_placementArray === null || _placementArray === void 0 ? void 0 : _placementArray.length) === 2) { if (type === npaPlacementTypes.POSITION) { this._positionV = _placementArray[0]; this._positionH = _placementArray[1]; } else if (type === npaPlacementTypes.ORIENTATION) { this._orientationV = _placementArray[0]; this._orientationH = _placementArray[1]; } } } _processModifiers(modifiers) { if (!!modifiers || modifiers === 0) { let _mods = modifiers; if (typeof modifiers === 'number') { _mods = [modifiers]; } if (Array.isArray(_mods) && !!_mods.length && _mods.length <= 2) { if (!!_mods[0] || _mods[0] === 0) { this._modV = _mods[0]; } if (!!_mods[1] || _mods[1] === 0) { this._modH = _mods[1]; } } } } _rightHorizontalSpaceNeeded(actual) { return actual.left + this._clientElementRect.width + this._modH > this._boundaryElementRect.right; } _leftHorizontalSpaceNeeded(actual) { return actual.left < this._boundaryElementRect.left; } _bottomVerticalSpaceNeeded(actual) { return actual.top + this._clientElementRect.height > this._boundaryElementRect.bottom; } _topVerticalSpaceNeeded(actual) { return actual.top < this._boundaryElementRect.top; } _verticalSpaceNeeded(actual) { return this._topVerticalSpaceNeeded(actual) || this._bottomVerticalSpaceNeeded(actual); } _horizontalSpaceNeeded(actual) { return this._leftHorizontalSpaceNeeded(actual) || this._rightHorizontalSpaceNeeded(actual); } setDomElement(element, type = npaPlacementElementTypes.HOST) { const _element = this._bm.getElement(element); if (!!_element) { if (type === npaPlacementElementTypes.HOST) { this._hostElement = _element; this._hostElementRect = this._hostElement.getBoundingClientRect(); this._hostPointsV = { top: this._hostElementRect.top, center: this._hostElementRect.top + (this._hostElementRect.height / 2), bottom: this._hostElementRect.bottom }; this._hostPointsH = { left: this._hostElementRect.left, center: this._hostElementRect.left + (this._hostElementRect.width / 2), right: this._hostElementRect.right }; } else if (type === npaPlacementElementTypes.CLIENT) { this._clientElement = _element; this._clientElementRect = this._clientElement.getBoundingClientRect(); this._clientMoveV = { top: this._clientElementRect.height, center: this._clientElementRect.height / 2, bottom: 0 }; this._clientMoveH = { left: this._clientElementRect.width, center: this._clientElementRect.width / 2, right: 0 }; } else if (type === npaPlacementElementTypes.RELATIVE) { this._relativeElement = _element; this._relativeElementRect = this._relativeElement.getBoundingClientRect(); this._relativeElementSet = true; } else if (type === npaPlacementElementTypes.SCROLL) { this._scrollElement = _element; this._scrollElementRect = this._scrollElement.getBoundingClientRect(); this._scrollElementSet = true; } else if (type === npaPlacementElementTypes.BOUNDARY) { this._boundaryElement = _element; this._boundaryElementRect = this._boundaryElement.getBoundingClientRect(); this._boundaryElementSet = true; } } } positioningElement(position, orientation, modifiers, checkAvailableSpace = false) { let _output; if (!!this._hostElement && !!this._clientElement) { let _correctionV = 0; let _correctionH = 0; if (this._relativeElementSet) { if (!this._scrollElementSet) { this._scrollElement = this._relativeElement; this._scrollElementRect = this._scrollElement.getBoundingClientRect(); } if (!this._boundaryElementSet) { this._boundaryElement = this._relativeElement; this._boundaryElementRect = this._boundaryElement.getBoundingClientRect(); } _correctionV = this._scrollElement.scrollTop - this._relativeElementRect.top; _correctionH = this._scrollElement.scrollLeft - this._relativeElementRect.left; } this._processModifiers(modifiers); this._processPlacement(position); this._processPlacement(orientation, npaPlacementTypes.ORIENTATION); _output = { top: this._hostPointsV[this._positionV] + _correctionV - this._clientMoveV[this._orientationV] + this._modV, left: this._hostPointsH[this._positionH] + _correctionH - this._clientMoveH[this._orientationH] + this._modH }; if (checkAvailableSpace) { const absoluteOutput = { top: this._hostPointsV[this._positionV] - this._clientMoveV[this._orientationV] + this._modV, left: this._hostPointsH[this._positionH] - this._clientMoveH[this._orientationH] + this._modH }; const _placementsMap = { [npaPlacementVertical.top]: npaPlacementVertical.bottom, [npaPlacementVertical.bottom]: npaPlacementVertical.top, [npaPlacementVertical.center]: npaPlacementVertical.center, [npaPlacementHorizontal.left]: npaPlacementHorizontal.right, [npaPlacementHorizontal.right]: npaPlacementHorizontal.left }; let _newPositionV = this._positionV; let _newOrientationV = this._orientationV; let _newPositionH = this._positionH; let _newOrientationH = this._orientationH; let _newModV = this._modV; let _newModH = this._modH; if (this._verticalSpaceNeeded(absoluteOutput)) { _newPositionV = _placementsMap[this._positionV]; _newOrientationV = _placementsMap[this._orientationV]; _newModV *= -1; } if (this._horizontalSpaceNeeded(absoluteOutput)) { _newPositionH = _placementsMap[this._positionH]; _newOrientationH = _placementsMap[this._orientationH]; _newModH *= -1; } const _position = `${_newPositionV} ${_newPositionH}`; const _orientation = `${_newOrientationV} ${_newOrientationH}`; const _modifiers = [_newModV, _newModH]; _output = this.positioningElement(_position, _orientation, _modifiers, false); } } return _output; } } class RenderService { constructor(_bm) { this._bm = _bm; } /** * intersectRect * @description * Detect when two dom elements intersect. */ static intersectRect(e1, e2) { return !(e2.left > e1.right || e2.right < e1.left || e2.top > e1.bottom || e2.bottom < e1.top); } positioningElementInside(element, host, position, margin) { const _element = this._bm.getElement(element); const _host = this._bm.getElement(host); const _positionPlacement = new Placement(this._bm); let _modifiers; if (!!_element && !!_host) { _modifiers = npaPlacementInsideAutoMargins[position].map((m) => m * margin); _positionPlacement.setDomElement(_element, npaPlacementElementTypes.CLIENT); _positionPlacement.setDomElement(_host, npaPlacementElementTypes.HOST); const _coordinates = _positionPlacement.positioningElement(position, npaPlacementInsideAutoOrientations[position], _modifiers); _element.style.left = `${_coordinates.left}px`; _element.style.top = `${_coordinates.top}px`; } } } RenderService.decorators = [ { type: Injectable } ]; RenderService.ctorParameters = () => [ { type: BoxModelService } ]; class CoreModule { static forChild() { return { ngModule: CoreModule, providers: [ BoxModelService, EventsService, CustomValidationService, ToolService, RenderService ] }; } } CoreModule.decorators = [ { type: NgModule, args: [{ exports: [ OrderConditionPipe, SanitizeHtmlPipe ], imports: [ CommonModule, OrderConditionModule, SanitizeHtmlModule ] },] } ]; class BoxModelModule { static forChild() { return { ngModule: BoxModelModule, providers: [BoxModelService] }; } } BoxModelModule.decorators = [ { type: NgModule, args: [{ imports: [CommonModule] },] } ]; class CustomValidationModule { static forChild() { return { ngModule: CustomValidationModule, providers: [CustomValidationService] }; } } CustomValidationModule.decorators = [ { type: NgModule, args: [{ imports: [CommonModule] },] } ]; class EventsModule { static forChild() { return { ngModule: EventsModule, providers: [EventsService] }; } } EventsModule.decorators = [ { type: NgModule, args: [{ imports: [ CommonModule, BoxModelModule.forChild() ] },] } ]; class RenderModule { static forChild() { return { ngModule: RenderModule, providers: [ RenderService, BoxModelService ] }; } } RenderModule.decorators = [ { type: NgModule, args: [{ imports: [ CommonModule ] },] } ]; class ToolModule { static forChild() { return { ngModule: ToolModule, providers: [ToolService] }; } } ToolModule.decorators = [ { type: NgModule, args: [{ imports: [CommonModule] },] } ]; // ##################################################### // ###### PRIVATE TYPES, INTERFACES AND CONSTANTS ###### // ##################################################### // ############################################# // ###### OPTION CONSTANTS DEFINITION API ###### // ############################################# const npaOptionFields = { value: 'value', label: 'label', color: 'color', separator: 'separator', icon: 'icon' }; // ##################################################### // ###### PRIVATE TYPES, INTERFACES AND CONSTANTS ###### // ##################################################### // ############################################### // ###### POSITION CONSTANTS DEFINITION API ###### // ############################################### const npaPositions = { left: 'left', right: 'right', top: 'top', bottom: 'bottom' }; // ##################################################### // ###### PRIVATE TYPES, INTERFACES AND CONSTANTS ###### // ##################################################### // ############################################# // ###### STATUS CONSTANTS DEFINITION API ###### // ############################################# const npaStatuses = { info: 'info', success: 'success', warning: 'warning', critical: 'critical' }; const ɵ0 = () => { }, ɵ1 = () => { }; const defaultConfig = { timeShowing: 400, timeToStop: 400, callbackShow: ɵ0, callbackStop: ɵ1 }; class AsynchronousPairVariables { constructor(config = defaultConfig) { var _a, _b; this.trigger$ = new Subject(); this.show$ = new Subject(); this._startArguments = []; this._stopArguments = []; this._config = {}; this._config.timeShowing = defaultConfig.timeShowing; if ((config === null || config === void 0 ? void 0 : config.timeShowing) || (!(config === null || config === void 0 ? void 0 : config.timeShowing) && (config === null || config === void 0 ? void 0 : config.timeShowing) === 0)) { this._config.timeShowing = config.timeShowing; } this._config.timeToStop = defaultConfig.timeToStop; if ((config === null || config === void 0 ? void 0 : config.timeToStop) || (!(config === null || config === void 0 ? void 0 : config.timeToStop) && (config === null || config === void 0 ? void 0 : config.timeToStop) === 0)) { this._config.timeToStop = config.timeToStop; } this._config.callbackShow = (_a = config === null || config === void 0 ? void 0 : config.callbackShow) !== null && _a !== void 0 ? _a : defaultConfig.callbackShow; this._config.callbackStop = config === null || config === void 0 ? void 0 : config.callbackStop; if (!this._config.callbackStop) { this._config.callbackStop = (_b = config === null || config === void 0 ? void 0 : config.callbackShow) !== null && _b !== void 0 ? _b : defaultConfig.callbackStop; } } set _trigger(state) { this.trigger$.next(state); if (state) { setTimeout(() => { this._config.callbackShow(...this._startArguments); this._show = true; if (!!this._config.timeShowing) { this._timeoutShow = setTimeout(() => { this._show = false; }, this._config.timeShowing); } }); } } set _show(state) { this.show$.next(state); if (!state) { setTimeout(() => { this._config.callbackStop(...this._stopArguments); this._trigger = false; }, this._config.timeToStop); } } _setStopArguments(...arg) { this._stopArguments = arg; } setConfig(config) { if (!!config.timeShowing) { this._config.timeShowing = config.timeShowing; } if (!!config.timeToStop) { this._config.timeToStop = config.timeToStop; } if (!!config.callbackShow) { this._config.callbackShow = config.callbackShow; } if (!!config.callbackStop) { this._config.callbackStop = config.callbackStop; } } start(...arg) { clearTimeout(this._timeoutShow); this._startArguments = arg; this._trigger = true; return this._setStopArguments.bind(this); } stop() { clearTimeout(this._timeoutShow); } remove() { this.stop(); this._show = false; } } const iconsClassBaseDefault = 'npa-icon'; class IconsOld { constructor(classBase = iconsClassBaseDefault) { this.classBase = classBase; this.defaultKeys = Object.assign(Object.assign({}, npaStatuses), { close: 'close' }); this._defaults = { info: 'icon-info', success: 'icon-circle-check', warning: 'icon-alert', critical: 'icon-shield', close: 'icon-cross' }; this.npaIconSetFields = { iconLeft: 'iconLeft', iconRight: 'iconRight' }; this.npaIconFields = { classes: 'classes', color: 'color' }; } _applyClassBase(icon) { return (!!this.classBase) ? `${this.classBase} ${icon}` : icon; } _getIconFromSet(iconSet, iconToExtract) { let _output = ''; if (!!iconSet && !!iconSet[iconToExtract]) { _output = this.getIcon(iconSet[iconToExtract]); } return _output; } get(defaultKey) { const _icon = this._defaults[defaultKey]; if (!!_icon) { return this._applyClassBase(_icon); } return ''; } getCustom(icon) { if (!!icon) { return this._applyClassBase(icon); } return ''; } getIcon(icon) { let _output = ''; if (!!(icon === null || icon === void 0 ? void 0 : icon.classes)) { _output = this._applyClassBase(icon.classes); if (!!icon.color) { _output = `${_output} ${icon.color}`; } } return _output; } getIconLeft(iconSet) { return this._getIconFromSet(iconSet, this.npaIconSetFields.iconLeft); } getIconRight(iconSet) { return this._getIconFromSet(iconSet, this.npaIconSetFields.iconRight); } } /* * Public API Surface of core */ /** * Generated bundle index. Do not edit. */ export { AsynchronousPairVariables, BoxModelModule, BoxModelService, CoreModule, CustomValidationModule, CustomValidationService, EventsModule, EventsService, IconsOld, OrderConditionModule, OrderConditionPipe, Placement, RenderModule, RenderService, SanitizeHtmlModule, SanitizeHtmlPipe, ToolModule, ToolService, boxModelTypeConstants, npaElementFields, npaHashTypes, npaOptionFields, npaPlacement, npaPlacementElementTypes, npaPlacementHorizontal, npaPlacementInsideAutoMargins, npaPlacementInsideAutoOrientations, npaPlacementTypes, npaPlacementVertical, npaPositions, npaStatuses, npaStringTransform, ɵ0, ɵ1 }; //# sourceMappingURL=circe-core.js.map