2023-08-17 09:47:40 +00:00
|
|
|
let Declaration = require('../declaration')
|
|
|
|
let { isPureNumber } = require('../utils')
|
2022-01-21 08:28:41 +00:00
|
|
|
|
2023-08-17 09:47:40 +00:00
|
|
|
class GridEnd extends Declaration {
|
2022-01-21 08:28:41 +00:00
|
|
|
/**
|
|
|
|
* Change repeating syntax for IE
|
|
|
|
*/
|
2023-08-17 09:47:40 +00:00
|
|
|
insert(decl, prefix, prefixes, result) {
|
|
|
|
if (prefix !== '-ms-') return super.insert(decl, prefix, prefixes)
|
|
|
|
|
|
|
|
let clonedDecl = this.clone(decl)
|
|
|
|
|
|
|
|
let startProp = decl.prop.replace(/end$/, 'start')
|
|
|
|
let spanProp = prefix + decl.prop.replace(/end$/, 'span')
|
|
|
|
|
|
|
|
if (decl.parent.some(i => i.prop === spanProp)) {
|
|
|
|
return undefined
|
2022-01-21 08:28:41 +00:00
|
|
|
}
|
|
|
|
|
2023-08-17 09:47:40 +00:00
|
|
|
clonedDecl.prop = spanProp
|
2022-01-21 08:28:41 +00:00
|
|
|
|
|
|
|
if (decl.value.includes('span')) {
|
2023-08-17 09:47:40 +00:00
|
|
|
clonedDecl.value = decl.value.replace(/span\s/i, '')
|
2022-01-21 08:28:41 +00:00
|
|
|
} else {
|
2023-08-17 09:47:40 +00:00
|
|
|
let startDecl
|
|
|
|
decl.parent.walkDecls(startProp, d => {
|
|
|
|
startDecl = d
|
|
|
|
})
|
2022-01-21 08:28:41 +00:00
|
|
|
if (startDecl) {
|
2023-08-17 09:47:40 +00:00
|
|
|
if (isPureNumber(startDecl.value)) {
|
|
|
|
let value = Number(decl.value) - Number(startDecl.value) + ''
|
|
|
|
clonedDecl.value = value
|
|
|
|
} else {
|
|
|
|
return undefined
|
|
|
|
}
|
2022-01-21 08:28:41 +00:00
|
|
|
} else {
|
2023-08-17 09:47:40 +00:00
|
|
|
decl.warn(
|
|
|
|
result,
|
|
|
|
`Can not prefix ${decl.prop} (${startProp} is not found)`
|
|
|
|
)
|
2022-01-21 08:28:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-17 09:47:40 +00:00
|
|
|
decl.cloneBefore(clonedDecl)
|
2022-01-21 08:28:41 +00:00
|
|
|
|
2023-08-17 09:47:40 +00:00
|
|
|
return undefined
|
|
|
|
}
|
|
|
|
}
|
2022-01-21 08:28:41 +00:00
|
|
|
|
2023-08-17 09:47:40 +00:00
|
|
|
GridEnd.names = ['grid-row-end', 'grid-column-end']
|
2022-01-21 08:28:41 +00:00
|
|
|
|
2023-08-17 09:47:40 +00:00
|
|
|
module.exports = GridEnd
|