1 | /**
|
2 | * @license
|
3 | * Copyright Google LLC All Rights Reserved.
|
4 | *
|
5 | * Use of this source code is governed by an MIT-style license that can be
|
6 | * found in the LICENSE file at https://angular.io/license
|
7 | */
|
8 | /**
|
9 | * Applies CSS prefixes to appropriate style keys.
|
10 | *
|
11 | * Note: `-ms-`, `-moz` and `-webkit-box` are no longer supported. e.g.
|
12 | * {
|
13 | * display: -webkit-flex; NEW - Safari 6.1+. iOS 7.1+, BB10
|
14 | * display: flex; NEW, Spec - Firefox, Chrome, Opera
|
15 | * // display: -webkit-box; OLD - iOS 6-, Safari 3.1-6, BB7
|
16 | * // display: -ms-flexbox; TWEENER - IE 10
|
17 | * // display: -moz-flexbox; OLD - Firefox
|
18 | * }
|
19 | */
|
20 | function applyCssPrefixes(target) {
|
21 | for (let key in target) {
|
22 | let value = target[key] ?? '';
|
23 | switch (key) {
|
24 | case 'display':
|
25 | if (value === 'flex') {
|
26 | target['display'] = [
|
27 | '-webkit-flex',
|
28 | 'flex'
|
29 | ];
|
30 | }
|
31 | else if (value === 'inline-flex') {
|
32 | target['display'] = [
|
33 | '-webkit-inline-flex',
|
34 | 'inline-flex'
|
35 | ];
|
36 | }
|
37 | else {
|
38 | target['display'] = value;
|
39 | }
|
40 | break;
|
41 | case 'align-items':
|
42 | case 'align-self':
|
43 | case 'align-content':
|
44 | case 'flex':
|
45 | case 'flex-basis':
|
46 | case 'flex-flow':
|
47 | case 'flex-grow':
|
48 | case 'flex-shrink':
|
49 | case 'flex-wrap':
|
50 | case 'justify-content':
|
51 | target['-webkit-' + key] = value;
|
52 | break;
|
53 | case 'flex-direction':
|
54 | target['-webkit-flex-direction'] = value;
|
55 | target['flex-direction'] = value;
|
56 | break;
|
57 | case 'order':
|
58 | target['order'] = target['-webkit-' + key] = isNaN(+value) ? '0' : value;
|
59 | break;
|
60 | }
|
61 | }
|
62 | return target;
|
63 | }
|
64 |
|
65 | /**
|
66 | * @license
|
67 | * Copyright Google LLC All Rights Reserved.
|
68 | *
|
69 | * Use of this source code is governed by an MIT-style license that can be
|
70 | * found in the LICENSE file at https://angular.io/license
|
71 | */
|
72 | const INLINE = 'inline';
|
73 | const LAYOUT_VALUES = ['row', 'column', 'row-reverse', 'column-reverse'];
|
74 | /**
|
75 | * Validate the direction|'direction wrap' value and then update the host's inline flexbox styles
|
76 | */
|
77 | function buildLayoutCSS(value) {
|
78 | let [direction, wrap, isInline] = validateValue(value);
|
79 | return buildCSS(direction, wrap, isInline);
|
80 | }
|
81 | /**
|
82 | * Validate the value to be one of the acceptable value options
|
83 | * Use default fallback of 'row'
|
84 | */
|
85 | function validateValue(value) {
|
86 | value = value?.toLowerCase() ?? '';
|
87 | let [direction, wrap, inline] = value.split(' ');
|
88 | // First value must be the `flex-direction`
|
89 | if (!LAYOUT_VALUES.find(x => x === direction)) {
|
90 | direction = LAYOUT_VALUES[0];
|
91 | }
|
92 | if (wrap === INLINE) {
|
93 | wrap = (inline !== INLINE) ? inline : '';
|
94 | inline = INLINE;
|
95 | }
|
96 | return [direction, validateWrapValue(wrap), !!inline];
|
97 | }
|
98 | /**
|
99 | * Determine if the validated, flex-direction value specifies
|
100 | * a horizontal/row flow.
|
101 | */
|
102 | function isFlowHorizontal(value) {
|
103 | let [flow,] = validateValue(value);
|
104 | return flow.indexOf('row') > -1;
|
105 | }
|
106 | /**
|
107 | * Convert layout-wrap='<value>' to expected flex-wrap style
|
108 | */
|
109 | function validateWrapValue(value) {
|
110 | if (!!value) {
|
111 | switch (value.toLowerCase()) {
|
112 | case 'reverse':
|
113 | case 'wrap-reverse':
|
114 | case 'reverse-wrap':
|
115 | value = 'wrap-reverse';
|
116 | break;
|
117 | case 'no':
|
118 | case 'none':
|
119 | case 'nowrap':
|
120 | value = 'nowrap';
|
121 | break;
|
122 | // All other values fallback to 'wrap'
|
123 | default:
|
124 | value = 'wrap';
|
125 | break;
|
126 | }
|
127 | }
|
128 | return value;
|
129 | }
|
130 | /**
|
131 | * Build the CSS that should be assigned to the element instance
|
132 | * BUG:
|
133 | * 1) min-height on a column flex container won’t apply to its flex item children in IE 10-11.
|
134 | * Use height instead if possible; height : <xxx>vh;
|
135 | *
|
136 | * This way any padding or border specified on the child elements are
|
137 | * laid out and drawn inside that element's specified width and height.
|
138 | */
|
139 | function buildCSS(direction, wrap = null, inline = false) {
|
140 | return {
|
141 | display: inline ? 'inline-flex' : 'flex',
|
142 | 'box-sizing': 'border-box',
|
143 | 'flex-direction': direction,
|
144 | 'flex-wrap': wrap || null,
|
145 | };
|
146 | }
|
147 |
|
148 | /**
|
149 | * @license
|
150 | * Copyright Google LLC All Rights Reserved.
|
151 | *
|
152 | * Use of this source code is governed by an MIT-style license that can be
|
153 | * found in the LICENSE file at https://angular.io/license
|
154 | */
|
155 | /**
|
156 | * Extends an object with the *enumerable* and *own* properties of one or more source objects,
|
157 | * similar to Object.assign.
|
158 | *
|
159 | * @param dest The object which will have properties copied to it.
|
160 | * @param sources The source objects from which properties will be copied.
|
161 | */
|
162 | function extendObject(dest, ...sources) {
|
163 | if (dest == null) {
|
164 | throw TypeError('Cannot convert undefined or null to object');
|
165 | }
|
166 | for (let source of sources) {
|
167 | if (source != null) {
|
168 | for (let key in source) {
|
169 | if (source.hasOwnProperty(key)) {
|
170 | dest[key] = source[key];
|
171 | }
|
172 | }
|
173 | }
|
174 | }
|
175 | return dest;
|
176 | }
|
177 |
|
178 | /**
|
179 | * @license
|
180 | * Copyright Google LLC All Rights Reserved.
|
181 | *
|
182 | * Use of this source code is governed by an MIT-style license that can be
|
183 | * found in the LICENSE file at https://angular.io/license
|
184 | */
|
185 |
|
186 | /**
|
187 | * Generated bundle index. Do not edit.
|
188 | */
|
189 |
|
190 | export { INLINE, LAYOUT_VALUES, applyCssPrefixes, buildLayoutCSS, extendObject, isFlowHorizontal, validateValue, validateWrapValue };
|
191 | //# sourceMappingURL=angular-flex-layout-_private-utils.mjs.map
|