wishthis/node_modules/autoprefixer/lib/hacks/grid-template.js

70 lines
1.4 KiB
JavaScript
Raw Normal View History

2023-08-17 09:47:40 +00:00
let Declaration = require('../declaration')
let {
getGridGap,
inheritGridGap,
parseTemplate,
warnGridGap,
warnMissedAreas
} = require('./grid-utils')
class GridTemplate extends Declaration {
2022-01-21 08:28:41 +00:00
/**
* Translate grid-template to separate -ms- prefixed properties
*/
2023-08-17 09:47:40 +00:00
insert(decl, prefix, prefixes, result) {
if (prefix !== '-ms-') return super.insert(decl, prefix, prefixes)
2022-01-21 08:28:41 +00:00
2023-08-17 09:47:40 +00:00
if (decl.parent.some(i => i.prop === '-ms-grid-rows')) {
return undefined
2022-01-21 08:28:41 +00:00
}
2023-08-17 09:47:40 +00:00
let gap = getGridGap(decl)
2022-01-21 08:28:41 +00:00
/**
* we must insert inherited gap values in some cases:
* if we are inside media query && if we have no grid-gap value
2023-08-17 09:47:40 +00:00
*/
let inheritedGap = inheritGridGap(decl, gap)
2022-01-21 08:28:41 +00:00
2023-08-17 09:47:40 +00:00
let { areas, columns, rows } = parseTemplate({
decl,
2022-01-21 08:28:41 +00:00
gap: inheritedGap || gap
2023-08-17 09:47:40 +00:00
})
let hasAreas = Object.keys(areas).length > 0
let hasRows = Boolean(rows)
let hasColumns = Boolean(columns)
2022-01-21 08:28:41 +00:00
warnGridGap({
2023-08-17 09:47:40 +00:00
decl,
gap,
hasColumns,
result
})
warnMissedAreas(areas, decl, result)
2022-01-21 08:28:41 +00:00
2023-08-17 09:47:40 +00:00
if ((hasRows && hasColumns) || hasAreas) {
2022-01-21 08:28:41 +00:00
decl.cloneBefore({
prop: '-ms-grid-rows',
2023-08-17 09:47:40 +00:00
raws: {},
value: rows
})
2022-01-21 08:28:41 +00:00
}
if (hasColumns) {
decl.cloneBefore({
prop: '-ms-grid-columns',
2023-08-17 09:47:40 +00:00
raws: {},
value: columns
})
2022-01-21 08:28:41 +00:00
}
2023-08-17 09:47:40 +00:00
return decl
}
}
2022-01-21 08:28:41 +00:00
2023-08-17 09:47:40 +00:00
GridTemplate.names = ['grid-template']
2022-01-21 08:28:41 +00:00
2023-08-17 09:47:40 +00:00
module.exports = GridTemplate