source: trip-planner-front/node_modules/@angular/material/__ivy_ngcc__/fesm2015/grid-list.js@ 59329aa

Last change on this file since 59329aa was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 37.5 KB
Line 
1import { InjectionToken, Component, ViewEncapsulation, ChangeDetectionStrategy, ElementRef, Optional, Inject, Input, ContentChildren, Directive, NgModule } from '@angular/core';
2import { setLines, MatLine, MatLineModule, MatCommonModule } from '@angular/material/core';
3import { coerceNumberProperty } from '@angular/cdk/coercion';
4import { Directionality } from '@angular/cdk/bidi';
5
6/**
7 * @license
8 * Copyright Google LLC All Rights Reserved.
9 *
10 * Use of this source code is governed by an MIT-style license that can be
11 * found in the LICENSE file at https://angular.io/license
12 */
13/**
14 * Class for determining, from a list of tiles, the (row, col) position of each of those tiles
15 * in the grid. This is necessary (rather than just rendering the tiles in normal document flow)
16 * because the tiles can have a rowspan.
17 *
18 * The positioning algorithm greedily places each tile as soon as it encounters a gap in the grid
19 * large enough to accommodate it so that the tiles still render in the same order in which they
20 * are given.
21 *
22 * The basis of the algorithm is the use of an array to track the already placed tiles. Each
23 * element of the array corresponds to a column, and the value indicates how many cells in that
24 * column are already occupied; zero indicates an empty cell. Moving "down" to the next row
25 * decrements each value in the tracking array (indicating that the column is one cell closer to
26 * being free).
27 *
28 * @docs-private
29 */
30import * as ɵngcc0 from '@angular/core';
31import * as ɵngcc1 from '@angular/cdk/bidi';
32
33const _c0 = ["*"];
34const _c1 = [[["", "mat-grid-avatar", ""], ["", "matGridAvatar", ""]], [["", "mat-line", ""], ["", "matLine", ""]], "*"];
35const _c2 = ["[mat-grid-avatar], [matGridAvatar]", "[mat-line], [matLine]", "*"];
36const _c3 = ".mat-grid-list{display:block;position:relative}.mat-grid-tile{display:block;position:absolute;overflow:hidden}.mat-grid-tile .mat-grid-tile-header,.mat-grid-tile .mat-grid-tile-footer{display:flex;align-items:center;height:48px;color:#fff;background:rgba(0,0,0,.38);overflow:hidden;padding:0 16px;position:absolute;left:0;right:0}.mat-grid-tile .mat-grid-tile-header>*,.mat-grid-tile .mat-grid-tile-footer>*{margin:0;padding:0;font-weight:normal;font-size:inherit}.mat-grid-tile .mat-grid-tile-header.mat-2-line,.mat-grid-tile .mat-grid-tile-footer.mat-2-line{height:68px}.mat-grid-tile .mat-grid-list-text{display:flex;flex-direction:column;flex:auto;box-sizing:border-box;overflow:hidden}.mat-grid-tile .mat-grid-list-text>*{margin:0;padding:0;font-weight:normal;font-size:inherit}.mat-grid-tile .mat-grid-list-text:empty{display:none}.mat-grid-tile .mat-grid-tile-header{top:0}.mat-grid-tile .mat-grid-tile-footer{bottom:0}.mat-grid-tile .mat-grid-avatar{padding-right:16px}[dir=rtl] .mat-grid-tile .mat-grid-avatar{padding-right:0;padding-left:16px}.mat-grid-tile .mat-grid-avatar:empty{display:none}.mat-grid-tile-content{top:0;left:0;right:0;bottom:0;position:absolute;display:flex;align-items:center;justify-content:center;height:100%;padding:0;margin:0}\n";
37class TileCoordinator {
38 constructor() {
39 /** Index at which the search for the next gap will start. */
40 this.columnIndex = 0;
41 /** The current row index. */
42 this.rowIndex = 0;
43 }
44 /** Gets the total number of rows occupied by tiles */
45 get rowCount() { return this.rowIndex + 1; }
46 /**
47 * Gets the total span of rows occupied by tiles.
48 * Ex: A list with 1 row that contains a tile with rowspan 2 will have a total rowspan of 2.
49 */
50 get rowspan() {
51 const lastRowMax = Math.max(...this.tracker);
52 // if any of the tiles has a rowspan that pushes it beyond the total row count,
53 // add the difference to the rowcount
54 return lastRowMax > 1 ? this.rowCount + lastRowMax - 1 : this.rowCount;
55 }
56 /**
57 * Updates the tile positions.
58 * @param numColumns Amount of columns in the grid.
59 * @param tiles Tiles to be positioned.
60 */
61 update(numColumns, tiles) {
62 this.columnIndex = 0;
63 this.rowIndex = 0;
64 this.tracker = new Array(numColumns);
65 this.tracker.fill(0, 0, this.tracker.length);
66 this.positions = tiles.map(tile => this._trackTile(tile));
67 }
68 /** Calculates the row and col position of a tile. */
69 _trackTile(tile) {
70 // Find a gap large enough for this tile.
71 const gapStartIndex = this._findMatchingGap(tile.colspan);
72 // Place tile in the resulting gap.
73 this._markTilePosition(gapStartIndex, tile);
74 // The next time we look for a gap, the search will start at columnIndex, which should be
75 // immediately after the tile that has just been placed.
76 this.columnIndex = gapStartIndex + tile.colspan;
77 return new TilePosition(this.rowIndex, gapStartIndex);
78 }
79 /** Finds the next available space large enough to fit the tile. */
80 _findMatchingGap(tileCols) {
81 if (tileCols > this.tracker.length && (typeof ngDevMode === 'undefined' || ngDevMode)) {
82 throw Error(`mat-grid-list: tile with colspan ${tileCols} is wider than ` +
83 `grid with cols="${this.tracker.length}".`);
84 }
85 // Start index is inclusive, end index is exclusive.
86 let gapStartIndex = -1;
87 let gapEndIndex = -1;
88 // Look for a gap large enough to fit the given tile. Empty spaces are marked with a zero.
89 do {
90 // If we've reached the end of the row, go to the next row.
91 if (this.columnIndex + tileCols > this.tracker.length) {
92 this._nextRow();
93 gapStartIndex = this.tracker.indexOf(0, this.columnIndex);
94 gapEndIndex = this._findGapEndIndex(gapStartIndex);
95 continue;
96 }
97 gapStartIndex = this.tracker.indexOf(0, this.columnIndex);
98 // If there are no more empty spaces in this row at all, move on to the next row.
99 if (gapStartIndex == -1) {
100 this._nextRow();
101 gapStartIndex = this.tracker.indexOf(0, this.columnIndex);
102 gapEndIndex = this._findGapEndIndex(gapStartIndex);
103 continue;
104 }
105 gapEndIndex = this._findGapEndIndex(gapStartIndex);
106 // If a gap large enough isn't found, we want to start looking immediately after the current
107 // gap on the next iteration.
108 this.columnIndex = gapStartIndex + 1;
109 // Continue iterating until we find a gap wide enough for this tile. Since gapEndIndex is
110 // exclusive, gapEndIndex is 0 means we didn't find a gap and should continue.
111 } while ((gapEndIndex - gapStartIndex < tileCols) || (gapEndIndex == 0));
112 // If we still didn't manage to find a gap, ensure that the index is
113 // at least zero so the tile doesn't get pulled out of the grid.
114 return Math.max(gapStartIndex, 0);
115 }
116 /** Move "down" to the next row. */
117 _nextRow() {
118 this.columnIndex = 0;
119 this.rowIndex++;
120 // Decrement all spaces by one to reflect moving down one row.
121 for (let i = 0; i < this.tracker.length; i++) {
122 this.tracker[i] = Math.max(0, this.tracker[i] - 1);
123 }
124 }
125 /**
126 * Finds the end index (exclusive) of a gap given the index from which to start looking.
127 * The gap ends when a non-zero value is found.
128 */
129 _findGapEndIndex(gapStartIndex) {
130 for (let i = gapStartIndex + 1; i < this.tracker.length; i++) {
131 if (this.tracker[i] != 0) {
132 return i;
133 }
134 }
135 // The gap ends with the end of the row.
136 return this.tracker.length;
137 }
138 /** Update the tile tracker to account for the given tile in the given space. */
139 _markTilePosition(start, tile) {
140 for (let i = 0; i < tile.colspan; i++) {
141 this.tracker[start + i] = tile.rowspan;
142 }
143 }
144}
145/**
146 * Simple data structure for tile position (row, col).
147 * @docs-private
148 */
149class TilePosition {
150 constructor(row, col) {
151 this.row = row;
152 this.col = col;
153 }
154}
155
156/**
157 * @license
158 * Copyright Google LLC All Rights Reserved.
159 *
160 * Use of this source code is governed by an MIT-style license that can be
161 * found in the LICENSE file at https://angular.io/license
162 */
163/**
164 * Injection token used to provide a grid list to a tile and to avoid circular imports.
165 * @docs-private
166 */
167const MAT_GRID_LIST = new InjectionToken('MAT_GRID_LIST');
168
169/**
170 * @license
171 * Copyright Google LLC All Rights Reserved.
172 *
173 * Use of this source code is governed by an MIT-style license that can be
174 * found in the LICENSE file at https://angular.io/license
175 */
176class MatGridTile {
177 constructor(_element, _gridList) {
178 this._element = _element;
179 this._gridList = _gridList;
180 this._rowspan = 1;
181 this._colspan = 1;
182 }
183 /** Amount of rows that the grid tile takes up. */
184 get rowspan() { return this._rowspan; }
185 set rowspan(value) { this._rowspan = Math.round(coerceNumberProperty(value)); }
186 /** Amount of columns that the grid tile takes up. */
187 get colspan() { return this._colspan; }
188 set colspan(value) { this._colspan = Math.round(coerceNumberProperty(value)); }
189 /**
190 * Sets the style of the grid-tile element. Needs to be set manually to avoid
191 * "Changed after checked" errors that would occur with HostBinding.
192 */
193 _setStyle(property, value) {
194 this._element.nativeElement.style[property] = value;
195 }
196}
197MatGridTile.ɵfac = function MatGridTile_Factory(t) { return new (t || MatGridTile)(ɵngcc0.ɵɵdirectiveInject(ɵngcc0.ElementRef), ɵngcc0.ɵɵdirectiveInject(MAT_GRID_LIST, 8)); };
198MatGridTile.ɵcmp = /*@__PURE__*/ ɵngcc0.ɵɵdefineComponent({ type: MatGridTile, selectors: [["mat-grid-tile"]], hostAttrs: [1, "mat-grid-tile"], hostVars: 2, hostBindings: function MatGridTile_HostBindings(rf, ctx) { if (rf & 2) {
199 ɵngcc0.ɵɵattribute("rowspan", ctx.rowspan)("colspan", ctx.colspan);
200 } }, inputs: { rowspan: "rowspan", colspan: "colspan" }, exportAs: ["matGridTile"], ngContentSelectors: _c0, decls: 2, vars: 0, consts: [[1, "mat-grid-tile-content"]], template: function MatGridTile_Template(rf, ctx) { if (rf & 1) {
201 ɵngcc0.ɵɵprojectionDef();
202 ɵngcc0.ɵɵelementStart(0, "div", 0);
203 ɵngcc0.ɵɵprojection(1);
204 ɵngcc0.ɵɵelementEnd();
205 } }, styles: [_c3], encapsulation: 2, changeDetection: 0 });
206MatGridTile.ctorParameters = () => [
207 { type: ElementRef },
208 { type: undefined, decorators: [{ type: Optional }, { type: Inject, args: [MAT_GRID_LIST,] }] }
209];
210MatGridTile.propDecorators = {
211 rowspan: [{ type: Input }],
212 colspan: [{ type: Input }]
213};
214(function () { (typeof ngDevMode === "undefined" || ngDevMode) && ɵngcc0.ɵsetClassMetadata(MatGridTile, [{
215 type: Component,
216 args: [{
217 selector: 'mat-grid-tile',
218 exportAs: 'matGridTile',
219 host: {
220 'class': 'mat-grid-tile',
221 // Ensures that the "rowspan" and "colspan" input value is reflected in
222 // the DOM. This is needed for the grid-tile harness.
223 '[attr.rowspan]': 'rowspan',
224 '[attr.colspan]': 'colspan'
225 },
226 template: "<div class=\"mat-grid-tile-content\">\n <ng-content></ng-content>\n</div>\n",
227 encapsulation: ViewEncapsulation.None,
228 changeDetection: ChangeDetectionStrategy.OnPush,
229 styles: [".mat-grid-list{display:block;position:relative}.mat-grid-tile{display:block;position:absolute;overflow:hidden}.mat-grid-tile .mat-grid-tile-header,.mat-grid-tile .mat-grid-tile-footer{display:flex;align-items:center;height:48px;color:#fff;background:rgba(0,0,0,.38);overflow:hidden;padding:0 16px;position:absolute;left:0;right:0}.mat-grid-tile .mat-grid-tile-header>*,.mat-grid-tile .mat-grid-tile-footer>*{margin:0;padding:0;font-weight:normal;font-size:inherit}.mat-grid-tile .mat-grid-tile-header.mat-2-line,.mat-grid-tile .mat-grid-tile-footer.mat-2-line{height:68px}.mat-grid-tile .mat-grid-list-text{display:flex;flex-direction:column;flex:auto;box-sizing:border-box;overflow:hidden}.mat-grid-tile .mat-grid-list-text>*{margin:0;padding:0;font-weight:normal;font-size:inherit}.mat-grid-tile .mat-grid-list-text:empty{display:none}.mat-grid-tile .mat-grid-tile-header{top:0}.mat-grid-tile .mat-grid-tile-footer{bottom:0}.mat-grid-tile .mat-grid-avatar{padding-right:16px}[dir=rtl] .mat-grid-tile .mat-grid-avatar{padding-right:0;padding-left:16px}.mat-grid-tile .mat-grid-avatar:empty{display:none}.mat-grid-tile-content{top:0;left:0;right:0;bottom:0;position:absolute;display:flex;align-items:center;justify-content:center;height:100%;padding:0;margin:0}\n"]
230 }]
231 }], function () { return [{ type: ɵngcc0.ElementRef }, { type: undefined, decorators: [{
232 type: Optional
233 }, {
234 type: Inject,
235 args: [MAT_GRID_LIST]
236 }] }]; }, { rowspan: [{
237 type: Input
238 }], colspan: [{
239 type: Input
240 }] }); })();
241class MatGridTileText {
242 constructor(_element) {
243 this._element = _element;
244 }
245 ngAfterContentInit() {
246 setLines(this._lines, this._element);
247 }
248}
249MatGridTileText.ɵfac = function MatGridTileText_Factory(t) { return new (t || MatGridTileText)(ɵngcc0.ɵɵdirectiveInject(ɵngcc0.ElementRef)); };
250MatGridTileText.ɵcmp = /*@__PURE__*/ ɵngcc0.ɵɵdefineComponent({ type: MatGridTileText, selectors: [["mat-grid-tile-header"], ["mat-grid-tile-footer"]], contentQueries: function MatGridTileText_ContentQueries(rf, ctx, dirIndex) { if (rf & 1) {
251 ɵngcc0.ɵɵcontentQuery(dirIndex, MatLine, 5);
252 } if (rf & 2) {
253 let _t;
254 ɵngcc0.ɵɵqueryRefresh(_t = ɵngcc0.ɵɵloadQuery()) && (ctx._lines = _t);
255 } }, ngContentSelectors: _c2, decls: 4, vars: 0, consts: [[1, "mat-grid-list-text"]], template: function MatGridTileText_Template(rf, ctx) { if (rf & 1) {
256 ɵngcc0.ɵɵprojectionDef(_c1);
257 ɵngcc0.ɵɵprojection(0);
258 ɵngcc0.ɵɵelementStart(1, "div", 0);
259 ɵngcc0.ɵɵprojection(2, 1);
260 ɵngcc0.ɵɵelementEnd();
261 ɵngcc0.ɵɵprojection(3, 2);
262 } }, encapsulation: 2, changeDetection: 0 });
263MatGridTileText.ctorParameters = () => [
264 { type: ElementRef }
265];
266MatGridTileText.propDecorators = {
267 _lines: [{ type: ContentChildren, args: [MatLine, { descendants: true },] }]
268};
269(function () { (typeof ngDevMode === "undefined" || ngDevMode) && ɵngcc0.ɵsetClassMetadata(MatGridTileText, [{
270 type: Component,
271 args: [{
272 selector: 'mat-grid-tile-header, mat-grid-tile-footer',
273 template: "<ng-content select=\"[mat-grid-avatar], [matGridAvatar]\"></ng-content>\n<div class=\"mat-grid-list-text\"><ng-content select=\"[mat-line], [matLine]\"></ng-content></div>\n<ng-content></ng-content>\n",
274 changeDetection: ChangeDetectionStrategy.OnPush,
275 encapsulation: ViewEncapsulation.None
276 }]
277 }], function () { return [{ type: ɵngcc0.ElementRef }]; }, { _lines: [{
278 type: ContentChildren,
279 args: [MatLine, { descendants: true }]
280 }] }); })();
281/**
282 * Directive whose purpose is to add the mat- CSS styling to this selector.
283 * @docs-private
284 */
285class MatGridAvatarCssMatStyler {
286}
287MatGridAvatarCssMatStyler.ɵfac = function MatGridAvatarCssMatStyler_Factory(t) { return new (t || MatGridAvatarCssMatStyler)(); };
288MatGridAvatarCssMatStyler.ɵdir = /*@__PURE__*/ ɵngcc0.ɵɵdefineDirective({ type: MatGridAvatarCssMatStyler, selectors: [["", "mat-grid-avatar", ""], ["", "matGridAvatar", ""]], hostAttrs: [1, "mat-grid-avatar"] });
289(function () { (typeof ngDevMode === "undefined" || ngDevMode) && ɵngcc0.ɵsetClassMetadata(MatGridAvatarCssMatStyler, [{
290 type: Directive,
291 args: [{
292 selector: '[mat-grid-avatar], [matGridAvatar]',
293 host: { 'class': 'mat-grid-avatar' }
294 }]
295 }], null, null); })();
296/**
297 * Directive whose purpose is to add the mat- CSS styling to this selector.
298 * @docs-private
299 */
300class MatGridTileHeaderCssMatStyler {
301}
302MatGridTileHeaderCssMatStyler.ɵfac = function MatGridTileHeaderCssMatStyler_Factory(t) { return new (t || MatGridTileHeaderCssMatStyler)(); };
303MatGridTileHeaderCssMatStyler.ɵdir = /*@__PURE__*/ ɵngcc0.ɵɵdefineDirective({ type: MatGridTileHeaderCssMatStyler, selectors: [["mat-grid-tile-header"]], hostAttrs: [1, "mat-grid-tile-header"] });
304(function () { (typeof ngDevMode === "undefined" || ngDevMode) && ɵngcc0.ɵsetClassMetadata(MatGridTileHeaderCssMatStyler, [{
305 type: Directive,
306 args: [{
307 selector: 'mat-grid-tile-header',
308 host: { 'class': 'mat-grid-tile-header' }
309 }]
310 }], null, null); })();
311/**
312 * Directive whose purpose is to add the mat- CSS styling to this selector.
313 * @docs-private
314 */
315class MatGridTileFooterCssMatStyler {
316}
317MatGridTileFooterCssMatStyler.ɵfac = function MatGridTileFooterCssMatStyler_Factory(t) { return new (t || MatGridTileFooterCssMatStyler)(); };
318MatGridTileFooterCssMatStyler.ɵdir = /*@__PURE__*/ ɵngcc0.ɵɵdefineDirective({ type: MatGridTileFooterCssMatStyler, selectors: [["mat-grid-tile-footer"]], hostAttrs: [1, "mat-grid-tile-footer"] });
319(function () { (typeof ngDevMode === "undefined" || ngDevMode) && ɵngcc0.ɵsetClassMetadata(MatGridTileFooterCssMatStyler, [{
320 type: Directive,
321 args: [{
322 selector: 'mat-grid-tile-footer',
323 host: { 'class': 'mat-grid-tile-footer' }
324 }]
325 }], null, null); })();
326
327/**
328 * @license
329 * Copyright Google LLC All Rights Reserved.
330 *
331 * Use of this source code is governed by an MIT-style license that can be
332 * found in the LICENSE file at https://angular.io/license
333 */
334/**
335 * RegExp that can be used to check whether a value will
336 * be allowed inside a CSS `calc()` expression.
337 */
338const cssCalcAllowedValue = /^-?\d+((\.\d+)?[A-Za-z%$]?)+$/;
339/**
340 * Sets the style properties for an individual tile, given the position calculated by the
341 * Tile Coordinator.
342 * @docs-private
343 */
344class TileStyler {
345 constructor() {
346 this._rows = 0;
347 this._rowspan = 0;
348 }
349 /**
350 * Adds grid-list layout info once it is available. Cannot be processed in the constructor
351 * because these properties haven't been calculated by that point.
352 *
353 * @param gutterSize Size of the grid's gutter.
354 * @param tracker Instance of the TileCoordinator.
355 * @param cols Amount of columns in the grid.
356 * @param direction Layout direction of the grid.
357 */
358 init(gutterSize, tracker, cols, direction) {
359 this._gutterSize = normalizeUnits(gutterSize);
360 this._rows = tracker.rowCount;
361 this._rowspan = tracker.rowspan;
362 this._cols = cols;
363 this._direction = direction;
364 }
365 /**
366 * Computes the amount of space a single 1x1 tile would take up (width or height).
367 * Used as a basis for other calculations.
368 * @param sizePercent Percent of the total grid-list space that one 1x1 tile would take up.
369 * @param gutterFraction Fraction of the gutter size taken up by one 1x1 tile.
370 * @return The size of a 1x1 tile as an expression that can be evaluated via CSS calc().
371 */
372 getBaseTileSize(sizePercent, gutterFraction) {
373 // Take the base size percent (as would be if evenly dividing the size between cells),
374 // and then subtracting the size of one gutter. However, since there are no gutters on the
375 // edges, each tile only uses a fraction (gutterShare = numGutters / numCells) of the gutter
376 // size. (Imagine having one gutter per tile, and then breaking up the extra gutter on the
377 // edge evenly among the cells).
378 return `(${sizePercent}% - (${this._gutterSize} * ${gutterFraction}))`;
379 }
380 /**
381 * Gets The horizontal or vertical position of a tile, e.g., the 'top' or 'left' property value.
382 * @param offset Number of tiles that have already been rendered in the row/column.
383 * @param baseSize Base size of a 1x1 tile (as computed in getBaseTileSize).
384 * @return Position of the tile as a CSS calc() expression.
385 */
386 getTilePosition(baseSize, offset) {
387 // The position comes the size of a 1x1 tile plus gutter for each previous tile in the
388 // row/column (offset).
389 return offset === 0 ? '0' : calc(`(${baseSize} + ${this._gutterSize}) * ${offset}`);
390 }
391 /**
392 * Gets the actual size of a tile, e.g., width or height, taking rowspan or colspan into account.
393 * @param baseSize Base size of a 1x1 tile (as computed in getBaseTileSize).
394 * @param span The tile's rowspan or colspan.
395 * @return Size of the tile as a CSS calc() expression.
396 */
397 getTileSize(baseSize, span) {
398 return `(${baseSize} * ${span}) + (${span - 1} * ${this._gutterSize})`;
399 }
400 /**
401 * Sets the style properties to be applied to a tile for the given row and column index.
402 * @param tile Tile to which to apply the styling.
403 * @param rowIndex Index of the tile's row.
404 * @param colIndex Index of the tile's column.
405 */
406 setStyle(tile, rowIndex, colIndex) {
407 // Percent of the available horizontal space that one column takes up.
408 let percentWidthPerTile = 100 / this._cols;
409 // Fraction of the vertical gutter size that each column takes up.
410 // For example, if there are 5 columns, each column uses 4/5 = 0.8 times the gutter width.
411 let gutterWidthFractionPerTile = (this._cols - 1) / this._cols;
412 this.setColStyles(tile, colIndex, percentWidthPerTile, gutterWidthFractionPerTile);
413 this.setRowStyles(tile, rowIndex, percentWidthPerTile, gutterWidthFractionPerTile);
414 }
415 /** Sets the horizontal placement of the tile in the list. */
416 setColStyles(tile, colIndex, percentWidth, gutterWidth) {
417 // Base horizontal size of a column.
418 let baseTileWidth = this.getBaseTileSize(percentWidth, gutterWidth);
419 // The width and horizontal position of each tile is always calculated the same way, but the
420 // height and vertical position depends on the rowMode.
421 let side = this._direction === 'rtl' ? 'right' : 'left';
422 tile._setStyle(side, this.getTilePosition(baseTileWidth, colIndex));
423 tile._setStyle('width', calc(this.getTileSize(baseTileWidth, tile.colspan)));
424 }
425 /**
426 * Calculates the total size taken up by gutters across one axis of a list.
427 */
428 getGutterSpan() {
429 return `${this._gutterSize} * (${this._rowspan} - 1)`;
430 }
431 /**
432 * Calculates the total size taken up by tiles across one axis of a list.
433 * @param tileHeight Height of the tile.
434 */
435 getTileSpan(tileHeight) {
436 return `${this._rowspan} * ${this.getTileSize(tileHeight, 1)}`;
437 }
438 /**
439 * Calculates the computed height and returns the correct style property to set.
440 * This method can be implemented by each type of TileStyler.
441 * @docs-private
442 */
443 getComputedHeight() { return null; }
444}
445/**
446 * This type of styler is instantiated when the user passes in a fixed row height.
447 * Example `<mat-grid-list cols="3" rowHeight="100px">`
448 * @docs-private
449 */
450class FixedTileStyler extends TileStyler {
451 constructor(fixedRowHeight) {
452 super();
453 this.fixedRowHeight = fixedRowHeight;
454 }
455 init(gutterSize, tracker, cols, direction) {
456 super.init(gutterSize, tracker, cols, direction);
457 this.fixedRowHeight = normalizeUnits(this.fixedRowHeight);
458 if (!cssCalcAllowedValue.test(this.fixedRowHeight) &&
459 (typeof ngDevMode === 'undefined' || ngDevMode)) {
460 throw Error(`Invalid value "${this.fixedRowHeight}" set as rowHeight.`);
461 }
462 }
463 setRowStyles(tile, rowIndex) {
464 tile._setStyle('top', this.getTilePosition(this.fixedRowHeight, rowIndex));
465 tile._setStyle('height', calc(this.getTileSize(this.fixedRowHeight, tile.rowspan)));
466 }
467 getComputedHeight() {
468 return [
469 'height', calc(`${this.getTileSpan(this.fixedRowHeight)} + ${this.getGutterSpan()}`)
470 ];
471 }
472 reset(list) {
473 list._setListStyle(['height', null]);
474 if (list._tiles) {
475 list._tiles.forEach(tile => {
476 tile._setStyle('top', null);
477 tile._setStyle('height', null);
478 });
479 }
480 }
481}
482/**
483 * This type of styler is instantiated when the user passes in a width:height ratio
484 * for the row height. Example `<mat-grid-list cols="3" rowHeight="3:1">`
485 * @docs-private
486 */
487class RatioTileStyler extends TileStyler {
488 constructor(value) {
489 super();
490 this._parseRatio(value);
491 }
492 setRowStyles(tile, rowIndex, percentWidth, gutterWidth) {
493 let percentHeightPerTile = percentWidth / this.rowHeightRatio;
494 this.baseTileHeight = this.getBaseTileSize(percentHeightPerTile, gutterWidth);
495 // Use padding-top and margin-top to maintain the given aspect ratio, as
496 // a percentage-based value for these properties is applied versus the *width* of the
497 // containing block. See http://www.w3.org/TR/CSS2/box.html#margin-properties
498 tile._setStyle('marginTop', this.getTilePosition(this.baseTileHeight, rowIndex));
499 tile._setStyle('paddingTop', calc(this.getTileSize(this.baseTileHeight, tile.rowspan)));
500 }
501 getComputedHeight() {
502 return [
503 'paddingBottom', calc(`${this.getTileSpan(this.baseTileHeight)} + ${this.getGutterSpan()}`)
504 ];
505 }
506 reset(list) {
507 list._setListStyle(['paddingBottom', null]);
508 list._tiles.forEach(tile => {
509 tile._setStyle('marginTop', null);
510 tile._setStyle('paddingTop', null);
511 });
512 }
513 _parseRatio(value) {
514 const ratioParts = value.split(':');
515 if (ratioParts.length !== 2 && (typeof ngDevMode === 'undefined' || ngDevMode)) {
516 throw Error(`mat-grid-list: invalid ratio given for row-height: "${value}"`);
517 }
518 this.rowHeightRatio = parseFloat(ratioParts[0]) / parseFloat(ratioParts[1]);
519 }
520}
521/**
522 * This type of styler is instantiated when the user selects a "fit" row height mode.
523 * In other words, the row height will reflect the total height of the container divided
524 * by the number of rows. Example `<mat-grid-list cols="3" rowHeight="fit">`
525 *
526 * @docs-private
527 */
528class FitTileStyler extends TileStyler {
529 setRowStyles(tile, rowIndex) {
530 // Percent of the available vertical space that one row takes up.
531 let percentHeightPerTile = 100 / this._rowspan;
532 // Fraction of the horizontal gutter size that each column takes up.
533 let gutterHeightPerTile = (this._rows - 1) / this._rows;
534 // Base vertical size of a column.
535 let baseTileHeight = this.getBaseTileSize(percentHeightPerTile, gutterHeightPerTile);
536 tile._setStyle('top', this.getTilePosition(baseTileHeight, rowIndex));
537 tile._setStyle('height', calc(this.getTileSize(baseTileHeight, tile.rowspan)));
538 }
539 reset(list) {
540 if (list._tiles) {
541 list._tiles.forEach(tile => {
542 tile._setStyle('top', null);
543 tile._setStyle('height', null);
544 });
545 }
546 }
547}
548/** Wraps a CSS string in a calc function */
549function calc(exp) {
550 return `calc(${exp})`;
551}
552/** Appends pixels to a CSS string if no units are given. */
553function normalizeUnits(value) {
554 return value.match(/([A-Za-z%]+)$/) ? value : `${value}px`;
555}
556
557/**
558 * @license
559 * Copyright Google LLC All Rights Reserved.
560 *
561 * Use of this source code is governed by an MIT-style license that can be
562 * found in the LICENSE file at https://angular.io/license
563 */
564// TODO(kara): Conditional (responsive) column count / row size.
565// TODO(kara): Re-layout on window resize / media change (debounced).
566// TODO(kara): gridTileHeader and gridTileFooter.
567const MAT_FIT_MODE = 'fit';
568class MatGridList {
569 constructor(_element, _dir) {
570 this._element = _element;
571 this._dir = _dir;
572 /** The amount of space between tiles. This will be something like '5px' or '2em'. */
573 this._gutter = '1px';
574 }
575 /** Amount of columns in the grid list. */
576 get cols() { return this._cols; }
577 set cols(value) {
578 this._cols = Math.max(1, Math.round(coerceNumberProperty(value)));
579 }
580 /** Size of the grid list's gutter in pixels. */
581 get gutterSize() { return this._gutter; }
582 set gutterSize(value) { this._gutter = `${value == null ? '' : value}`; }
583 /** Set internal representation of row height from the user-provided value. */
584 get rowHeight() { return this._rowHeight; }
585 set rowHeight(value) {
586 const newValue = `${value == null ? '' : value}`;
587 if (newValue !== this._rowHeight) {
588 this._rowHeight = newValue;
589 this._setTileStyler(this._rowHeight);
590 }
591 }
592 ngOnInit() {
593 this._checkCols();
594 this._checkRowHeight();
595 }
596 /**
597 * The layout calculation is fairly cheap if nothing changes, so there's little cost
598 * to run it frequently.
599 */
600 ngAfterContentChecked() {
601 this._layoutTiles();
602 }
603 /** Throw a friendly error if cols property is missing */
604 _checkCols() {
605 if (!this.cols && (typeof ngDevMode === 'undefined' || ngDevMode)) {
606 throw Error(`mat-grid-list: must pass in number of columns. ` +
607 `Example: <mat-grid-list cols="3">`);
608 }
609 }
610 /** Default to equal width:height if rowHeight property is missing */
611 _checkRowHeight() {
612 if (!this._rowHeight) {
613 this._setTileStyler('1:1');
614 }
615 }
616 /** Creates correct Tile Styler subtype based on rowHeight passed in by user */
617 _setTileStyler(rowHeight) {
618 if (this._tileStyler) {
619 this._tileStyler.reset(this);
620 }
621 if (rowHeight === MAT_FIT_MODE) {
622 this._tileStyler = new FitTileStyler();
623 }
624 else if (rowHeight && rowHeight.indexOf(':') > -1) {
625 this._tileStyler = new RatioTileStyler(rowHeight);
626 }
627 else {
628 this._tileStyler = new FixedTileStyler(rowHeight);
629 }
630 }
631 /** Computes and applies the size and position for all children grid tiles. */
632 _layoutTiles() {
633 if (!this._tileCoordinator) {
634 this._tileCoordinator = new TileCoordinator();
635 }
636 const tracker = this._tileCoordinator;
637 const tiles = this._tiles.filter(tile => !tile._gridList || tile._gridList === this);
638 const direction = this._dir ? this._dir.value : 'ltr';
639 this._tileCoordinator.update(this.cols, tiles);
640 this._tileStyler.init(this.gutterSize, tracker, this.cols, direction);
641 tiles.forEach((tile, index) => {
642 const pos = tracker.positions[index];
643 this._tileStyler.setStyle(tile, pos.row, pos.col);
644 });
645 this._setListStyle(this._tileStyler.getComputedHeight());
646 }
647 /** Sets style on the main grid-list element, given the style name and value. */
648 _setListStyle(style) {
649 if (style) {
650 this._element.nativeElement.style[style[0]] = style[1];
651 }
652 }
653}
654MatGridList.ɵfac = function MatGridList_Factory(t) { return new (t || MatGridList)(ɵngcc0.ɵɵdirectiveInject(ɵngcc0.ElementRef), ɵngcc0.ɵɵdirectiveInject(ɵngcc1.Directionality, 8)); };
655MatGridList.ɵcmp = /*@__PURE__*/ ɵngcc0.ɵɵdefineComponent({ type: MatGridList, selectors: [["mat-grid-list"]], contentQueries: function MatGridList_ContentQueries(rf, ctx, dirIndex) { if (rf & 1) {
656 ɵngcc0.ɵɵcontentQuery(dirIndex, MatGridTile, 5);
657 } if (rf & 2) {
658 let _t;
659 ɵngcc0.ɵɵqueryRefresh(_t = ɵngcc0.ɵɵloadQuery()) && (ctx._tiles = _t);
660 } }, hostAttrs: [1, "mat-grid-list"], hostVars: 1, hostBindings: function MatGridList_HostBindings(rf, ctx) { if (rf & 2) {
661 ɵngcc0.ɵɵattribute("cols", ctx.cols);
662 } }, inputs: { cols: "cols", gutterSize: "gutterSize", rowHeight: "rowHeight" }, exportAs: ["matGridList"], features: [ɵngcc0.ɵɵProvidersFeature([{
663 provide: MAT_GRID_LIST,
664 useExisting: MatGridList
665 }])], ngContentSelectors: _c0, decls: 2, vars: 0, template: function MatGridList_Template(rf, ctx) { if (rf & 1) {
666 ɵngcc0.ɵɵprojectionDef();
667 ɵngcc0.ɵɵelementStart(0, "div");
668 ɵngcc0.ɵɵprojection(1);
669 ɵngcc0.ɵɵelementEnd();
670 } }, styles: [_c3], encapsulation: 2, changeDetection: 0 });
671MatGridList.ctorParameters = () => [
672 { type: ElementRef },
673 { type: Directionality, decorators: [{ type: Optional }] }
674];
675MatGridList.propDecorators = {
676 _tiles: [{ type: ContentChildren, args: [MatGridTile, { descendants: true },] }],
677 cols: [{ type: Input }],
678 gutterSize: [{ type: Input }],
679 rowHeight: [{ type: Input }]
680};
681(function () { (typeof ngDevMode === "undefined" || ngDevMode) && ɵngcc0.ɵsetClassMetadata(MatGridList, [{
682 type: Component,
683 args: [{
684 selector: 'mat-grid-list',
685 exportAs: 'matGridList',
686 template: "<div>\n <ng-content></ng-content>\n</div>",
687 host: {
688 'class': 'mat-grid-list',
689 // Ensures that the "cols" input value is reflected in the DOM. This is
690 // needed for the grid-list harness.
691 '[attr.cols]': 'cols'
692 },
693 providers: [{
694 provide: MAT_GRID_LIST,
695 useExisting: MatGridList
696 }],
697 changeDetection: ChangeDetectionStrategy.OnPush,
698 encapsulation: ViewEncapsulation.None,
699 styles: [".mat-grid-list{display:block;position:relative}.mat-grid-tile{display:block;position:absolute;overflow:hidden}.mat-grid-tile .mat-grid-tile-header,.mat-grid-tile .mat-grid-tile-footer{display:flex;align-items:center;height:48px;color:#fff;background:rgba(0,0,0,.38);overflow:hidden;padding:0 16px;position:absolute;left:0;right:0}.mat-grid-tile .mat-grid-tile-header>*,.mat-grid-tile .mat-grid-tile-footer>*{margin:0;padding:0;font-weight:normal;font-size:inherit}.mat-grid-tile .mat-grid-tile-header.mat-2-line,.mat-grid-tile .mat-grid-tile-footer.mat-2-line{height:68px}.mat-grid-tile .mat-grid-list-text{display:flex;flex-direction:column;flex:auto;box-sizing:border-box;overflow:hidden}.mat-grid-tile .mat-grid-list-text>*{margin:0;padding:0;font-weight:normal;font-size:inherit}.mat-grid-tile .mat-grid-list-text:empty{display:none}.mat-grid-tile .mat-grid-tile-header{top:0}.mat-grid-tile .mat-grid-tile-footer{bottom:0}.mat-grid-tile .mat-grid-avatar{padding-right:16px}[dir=rtl] .mat-grid-tile .mat-grid-avatar{padding-right:0;padding-left:16px}.mat-grid-tile .mat-grid-avatar:empty{display:none}.mat-grid-tile-content{top:0;left:0;right:0;bottom:0;position:absolute;display:flex;align-items:center;justify-content:center;height:100%;padding:0;margin:0}\n"]
700 }]
701 }], function () { return [{ type: ɵngcc0.ElementRef }, { type: ɵngcc1.Directionality, decorators: [{
702 type: Optional
703 }] }]; }, { cols: [{
704 type: Input
705 }], gutterSize: [{
706 type: Input
707 }], rowHeight: [{
708 type: Input
709 }], _tiles: [{
710 type: ContentChildren,
711 args: [MatGridTile, { descendants: true }]
712 }] }); })();
713
714/**
715 * @license
716 * Copyright Google LLC All Rights Reserved.
717 *
718 * Use of this source code is governed by an MIT-style license that can be
719 * found in the LICENSE file at https://angular.io/license
720 */
721class MatGridListModule {
722}
723MatGridListModule.ɵfac = function MatGridListModule_Factory(t) { return new (t || MatGridListModule)(); };
724MatGridListModule.ɵmod = /*@__PURE__*/ ɵngcc0.ɵɵdefineNgModule({ type: MatGridListModule });
725MatGridListModule.ɵinj = /*@__PURE__*/ ɵngcc0.ɵɵdefineInjector({ imports: [[MatLineModule, MatCommonModule], MatLineModule,
726 MatCommonModule] });
727(function () { (typeof ngDevMode === "undefined" || ngDevMode) && ɵngcc0.ɵsetClassMetadata(MatGridListModule, [{
728 type: NgModule,
729 args: [{
730 imports: [MatLineModule, MatCommonModule],
731 exports: [
732 MatGridList,
733 MatGridTile,
734 MatGridTileText,
735 MatLineModule,
736 MatCommonModule,
737 MatGridTileHeaderCssMatStyler,
738 MatGridTileFooterCssMatStyler,
739 MatGridAvatarCssMatStyler
740 ],
741 declarations: [
742 MatGridList,
743 MatGridTile,
744 MatGridTileText,
745 MatGridTileHeaderCssMatStyler,
746 MatGridTileFooterCssMatStyler,
747 MatGridAvatarCssMatStyler
748 ]
749 }]
750 }], null, null); })();
751(function () { (typeof ngJitMode === "undefined" || ngJitMode) && ɵngcc0.ɵɵsetNgModuleScope(MatGridListModule, { declarations: function () { return [MatGridList, MatGridTile, MatGridTileText, MatGridTileHeaderCssMatStyler, MatGridTileFooterCssMatStyler, MatGridAvatarCssMatStyler]; }, imports: function () { return [MatLineModule, MatCommonModule]; }, exports: function () { return [MatGridList, MatGridTile, MatGridTileText, MatLineModule,
752 MatCommonModule, MatGridTileHeaderCssMatStyler, MatGridTileFooterCssMatStyler, MatGridAvatarCssMatStyler]; } }); })();
753
754/**
755 * @license
756 * Copyright Google LLC All Rights Reserved.
757 *
758 * Use of this source code is governed by an MIT-style license that can be
759 * found in the LICENSE file at https://angular.io/license
760 */
761// Privately exported for the grid-list harness.
762const ɵTileCoordinator = TileCoordinator;
763
764/**
765 * Generated bundle index. Do not edit.
766 */
767
768export { MatGridAvatarCssMatStyler, MatGridList, MatGridListModule, MatGridTile, MatGridTileFooterCssMatStyler, MatGridTileHeaderCssMatStyler, MatGridTileText, ɵTileCoordinator, MAT_GRID_LIST as ɵangular_material_src_material_grid_list_grid_list_a };
769
770//# sourceMappingURL=grid-list.js.map
Note: See TracBrowser for help on using the repository browser.