UNPKG

grid-template-parser

Version:
44 lines (31 loc) 1.31 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var matchingArea = function matchingArea(areas, row, column) { return function (area) { return areas[area].row.start <= row + 1 && areas[area].row.end > row + 1 && areas[area].column.start <= column + 1 && areas[area].column.end > column + 1; }; }; var getColumns = function getColumns(areas, grid, row) { var current = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0; var cols = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : ''; var area = areas.find(matchingArea(grid.areas, row, current)); cols += typeof area === 'string' ? area : '.'; if (current < grid.width - 1) { return getColumns(areas, grid, row, current + 1, cols + ' '); } return cols; }; var getRows = function getRows(areas, grid) { var current = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0; var rows = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : ''; rows += '"' + getColumns(areas, grid, current) + '"'; if (current < grid.height - 1) { return getRows(areas, grid, current + 1, rows + '\n'); } return rows; }; var template = exports.template = function template(grid) { return getRows(Object.keys(grid.areas), grid); };