source: node_modules/autoprefixer/lib/hacks/intrinsic.js@ e4c61dd

Last change on this file since e4c61dd was 2058e5c, checked in by istevanoska <ilinastevanoska@…>, 6 months ago

Working / before login

  • Property mode set to 100644
File size: 1.4 KB
Line 
1let OldValue = require('../old-value')
2let Value = require('../value')
3
4function regexp(name) {
5 return new RegExp(`(^|[\\s,(])(${name}($|[\\s),]))`, 'gi')
6}
7
8class Intrinsic extends Value {
9 add(decl, prefix) {
10 if (decl.prop.includes('grid') && prefix !== '-webkit-') {
11 return undefined
12 }
13 return super.add(decl, prefix)
14 }
15
16 isStretch() {
17 return (
18 this.name === 'stretch' ||
19 this.name === 'fill' ||
20 this.name === 'fill-available'
21 )
22 }
23
24 old(prefix) {
25 let prefixed = prefix + this.name
26 if (this.isStretch()) {
27 if (prefix === '-moz-') {
28 prefixed = '-moz-available'
29 } else if (prefix === '-webkit-') {
30 prefixed = '-webkit-fill-available'
31 }
32 }
33 return new OldValue(this.name, prefixed, prefixed, regexp(prefixed))
34 }
35
36 regexp() {
37 if (!this.regexpCache) this.regexpCache = regexp(this.name)
38 return this.regexpCache
39 }
40
41 replace(string, prefix) {
42 if (prefix === '-moz-' && this.isStretch()) {
43 return string.replace(this.regexp(), '$1-moz-available$3')
44 }
45 if (prefix === '-webkit-' && this.isStretch()) {
46 return string.replace(this.regexp(), '$1-webkit-fill-available$3')
47 }
48 return super.replace(string, prefix)
49 }
50}
51
52Intrinsic.names = [
53 'max-content',
54 'min-content',
55 'fit-content',
56 'fill',
57 'fill-available',
58 'stretch'
59]
60
61module.exports = Intrinsic
Note: See TracBrowser for help on using the repository browser.