UNPKG

ri-flex-layout

Version:

An alternative library to Angular's deprecated [angular-flex-layout](https://github.com/angular/flex-layout) library. `ri-flex-layout` helps you achieve responsive layouts in Angular applications with minimal code changes.

157 lines (151 loc) 4.51 kB
/** * Method for apply css prefix css * @export * @param {({[key: string]: any | null})} target * @return */ function applyCssPrefixes(target) { for (let key in target) { let value = target[key] ?? ''; switch (key) { case 'display': if (value === 'flex') { target['display'] = [ '-webkit-flex', 'flex' ]; } else if (value === 'inline-flex') { target['display'] = [ '-webkit-inline-flex', 'inline-flex' ]; } else { target['display'] = value; } break; case 'align-items': case 'align-self': case 'align-content': case 'flex': case 'flex-basis': case 'flex-flow': case 'flex-grow': case 'flex-shrink': case 'flex-wrap': case 'justify-content': target['-webkit-' + key] = value; break; case 'flex-direction': target['-webkit-flex-direction'] = value; target['flex-direction'] = value; break; case 'order': target['order'] = target['-webkit-' + key] = isNaN(+value) ? '0' : value; break; } } return target; } const INLINE = 'inline'; const LAYOUT_VALUES = ['row', 'column', 'row-reverse', 'column-reverse']; /** * Method to validate the direction|'direction wrap' value and then update the host's inline flexbox styles */ function buildLayoutCSS(value) { let [direction, wrap, isInline] = validateValue(value); return buildCSS(direction, wrap, isInline); } /** * Method to validate the value to be one of the acceptable value options * Use default fallback of 'row' */ function validateValue(value) { value = value?.toLowerCase() ?? ''; let [direction, wrap, inline] = value.split(' '); // First value must be the `flex-direction` if (!LAYOUT_VALUES.find(x => x === direction)) { direction = LAYOUT_VALUES[0]; } if (wrap === INLINE) { wrap = (inline !== INLINE) ? inline : ''; inline = INLINE; } return [direction, validateWrapValue(wrap), !!inline]; } /** * Method for Determine if the validated, flex-direction value specifies * a horizontal/row flow. */ function isFlowHorizontal(value) { let [flow,] = validateValue(value); return flow.indexOf('row') > -1; } /** * Convert layout-wrap='<value>' to expected flex-wrap style */ function validateWrapValue(value) { if (!!value) { switch (value.toLowerCase()) { case 'reverse': case 'wrap-reverse': case 'reverse-wrap': value = 'wrap-reverse'; break; case 'no': case 'none': case 'nowrap': value = 'nowrap'; break; // All other values fallback to 'wrap' default: value = 'wrap'; break; } } return value; } /** * Method for build css based on params. * @param {string} direction * @param {(string | null)} [wrap=null] * @param {boolean} [inline=false] * @return */ function buildCSS(direction, wrap = null, inline = false) { return { display: inline ? 'inline-flex' : 'flex', 'box-sizing': 'border-box', 'flex-direction': direction, 'flex-wrap': wrap || null, }; } /** * Method for extend object with other objects. * @export * @param {*} dest * @param {...any[]} sources * @return * */ function extendObject(dest, ...sources) { if (dest == null) { throw TypeError('Cannot convert undefined or null to object'); } for (let source of sources) { if (source != null) { for (let key in source) { if (source.hasOwnProperty(key)) { dest[key] = source[key]; } } } } return dest; } // export * from './public-api.ts'; /** * Generated bundle index. Do not edit. */ export { INLINE, LAYOUT_VALUES, applyCssPrefixes, buildLayoutCSS, extendObject, isFlowHorizontal, validateValue, validateWrapValue }; //# sourceMappingURL=ri-flex-layout-src-lib-_private-utils.mjs.map