source: imaps-frontend/node_modules/stylis/src/Prefixer.js@ 0c6b92a

main
Last change on this file since 0c6b92a was 0c6b92a, checked in by stefan toskovski <stefantoska84@…>, 5 weeks ago

Pred finalna verzija

  • Property mode set to 100644
File size: 6.5 KB
Line 
1import {MS, MOZ, WEBKIT} from './Enum.js'
2import {hash, charat, strlen, indexof, replace, substr, match} from './Utility.js'
3
4/**
5 * @param {string} value
6 * @param {number} length
7 * @param {object[]} children
8 * @return {string}
9 */
10export function prefix (value, length, children) {
11 switch (hash(value, length)) {
12 // color-adjust
13 case 5103:
14 return WEBKIT + 'print-' + value + value
15 // animation, animation-(delay|direction|duration|fill-mode|iteration-count|name|play-state|timing-function)
16 case 5737: case 4201: case 3177: case 3433: case 1641: case 4457: case 2921:
17 // text-decoration, filter, clip-path, backface-visibility, column, box-decoration-break
18 case 5572: case 6356: case 5844: case 3191: case 6645: case 3005:
19 // background-clip, columns, column-(count|fill|gap|rule|rule-color|rule-style|rule-width|span|width)
20 case 4215: case 6389: case 5109: case 5365: case 5621: case 3829:
21 // mask, mask-image, mask-(mode|clip|size), mask-(repeat|origin), mask-position
22 case 6391: case 5879: case 5623: case 6135: case 4599:
23 return WEBKIT + value + value
24 // mask-composite
25 case 4855:
26 return WEBKIT + value.replace('add', 'source-over').replace('substract', 'source-out').replace('intersect', 'source-in').replace('exclude', 'xor') + value
27 // tab-size
28 case 4789:
29 return MOZ + value + value
30 // appearance, user-select, transform, hyphens, text-size-adjust
31 case 5349: case 4246: case 4810: case 6968: case 2756:
32 return WEBKIT + value + MOZ + value + MS + value + value
33 // writing-mode
34 case 5936:
35 switch (charat(value, length + 11)) {
36 // vertical-l(r)
37 case 114:
38 return WEBKIT + value + MS + replace(value, /[svh]\w+-[tblr]{2}/, 'tb') + value
39 // vertical-r(l)
40 case 108:
41 return WEBKIT + value + MS + replace(value, /[svh]\w+-[tblr]{2}/, 'tb-rl') + value
42 // horizontal(-)tb
43 case 45:
44 return WEBKIT + value + MS + replace(value, /[svh]\w+-[tblr]{2}/, 'lr') + value
45 // default: fallthrough to below
46 }
47 // flex, flex-direction, scroll-snap-type, writing-mode
48 case 6828: case 4268: case 2903:
49 return WEBKIT + value + MS + value + value
50 // order
51 case 6165:
52 return WEBKIT + value + MS + 'flex-' + value + value
53 // align-items
54 case 5187:
55 return WEBKIT + value + replace(value, /(\w+).+(:[^]+)/, WEBKIT + 'box-$1$2' + MS + 'flex-$1$2') + value
56 // align-self
57 case 5443:
58 return WEBKIT + value + MS + 'flex-item-' + replace(value, /flex-|-self/g, '') + (!match(value, /flex-|baseline/) ? MS + 'grid-row-' + replace(value, /flex-|-self/g, '') : '') + value
59 // align-content
60 case 4675:
61 return WEBKIT + value + MS + 'flex-line-pack' + replace(value, /align-content|flex-|-self/g, '') + value
62 // flex-shrink
63 case 5548:
64 return WEBKIT + value + MS + replace(value, 'shrink', 'negative') + value
65 // flex-basis
66 case 5292:
67 return WEBKIT + value + MS + replace(value, 'basis', 'preferred-size') + value
68 // flex-grow
69 case 6060:
70 return WEBKIT + 'box-' + replace(value, '-grow', '') + WEBKIT + value + MS + replace(value, 'grow', 'positive') + value
71 // transition
72 case 4554:
73 return WEBKIT + replace(value, /([^-])(transform)/g, '$1' + WEBKIT + '$2') + value
74 // cursor
75 case 6187:
76 return replace(replace(replace(value, /(zoom-|grab)/, WEBKIT + '$1'), /(image-set)/, WEBKIT + '$1'), value, '') + value
77 // background, background-image
78 case 5495: case 3959:
79 return replace(value, /(image-set\([^]*)/, WEBKIT + '$1' + '$`$1')
80 // justify-content
81 case 4968:
82 return replace(replace(value, /(.+:)(flex-)?(.*)/, WEBKIT + 'box-pack:$3' + MS + 'flex-pack:$3'), /space-between/, 'justify') + WEBKIT + value + value
83 // justify-self
84 case 4200:
85 if (!match(value, /flex-|baseline/)) return MS + 'grid-column-align' + substr(value, length) + value
86 break
87 // grid-template-(columns|rows)
88 case 2592: case 3360:
89 return MS + replace(value, 'template-', '') + value
90 // grid-(row|column)-start
91 case 4384: case 3616:
92 if (children && children.some(function (element, index) { return length = index, match(element.props, /grid-\w+-end/) })) {
93 return ~indexof(value + (children = children[length].value), 'span', 0) ? value : (MS + replace(value, '-start', '') + value + MS + 'grid-row-span:' + (~indexof(children, 'span', 0) ? match(children, /\d+/) : +match(children, /\d+/) - +match(value, /\d+/)) + ';')
94 }
95 return MS + replace(value, '-start', '') + value
96 // grid-(row|column)-end
97 case 4896: case 4128:
98 return (children && children.some(function (element) { return match(element.props, /grid-\w+-start/) })) ? value : MS + replace(replace(value, '-end', '-span'), 'span ', '') + value
99 // (margin|padding)-inline-(start|end)
100 case 4095: case 3583: case 4068: case 2532:
101 return replace(value, /(.+)-inline(.+)/, WEBKIT + '$1$2') + value
102 // (min|max)?(width|height|inline-size|block-size)
103 case 8116: case 7059: case 5753: case 5535:
104 case 5445: case 5701: case 4933: case 4677:
105 case 5533: case 5789: case 5021: case 4765:
106 // stretch, max-content, min-content, fill-available
107 if (strlen(value) - 1 - length > 6)
108 switch (charat(value, length + 1)) {
109 // (m)ax-content, (m)in-content
110 case 109:
111 // -
112 if (charat(value, length + 4) !== 45)
113 break
114 // (f)ill-available, (f)it-content
115 case 102:
116 return replace(value, /(.+:)(.+)-([^]+)/, '$1' + WEBKIT + '$2-$3' + '$1' + MOZ + (charat(value, length + 3) == 108 ? '$3' : '$2-$3')) + value
117 // (s)tretch
118 case 115:
119 return ~indexof(value, 'stretch', 0) ? prefix(replace(value, 'stretch', 'fill-available'), length, children) + value : value
120 }
121 break
122 // grid-(column|row)
123 case 5152: case 5920:
124 return replace(value, /(.+?):(\d+)(\s*\/\s*(span)?\s*(\d+))?(.*)/, function (_, a, b, c, d, e, f) { return (MS + a + ':' + b + f) + (c ? (MS + a + '-span:' + (d ? e : +e - +b)) + f : '') + value })
125 // position: sticky
126 case 4949:
127 // stick(y)?
128 if (charat(value, length + 6) === 121)
129 return replace(value, ':', ':' + WEBKIT) + value
130 break
131 // display: (flex|inline-flex|grid|inline-grid)
132 case 6444:
133 switch (charat(value, charat(value, 14) === 45 ? 18 : 11)) {
134 // (inline-)?fle(x)
135 case 120:
136 return replace(value, /(.+:)([^;\s!]+)(;|(\s+)?!.+)?/, '$1' + WEBKIT + (charat(value, 14) === 45 ? 'inline-' : '') + 'box$3' + '$1' + WEBKIT + '$2$3' + '$1' + MS + '$2box$3') + value
137 // (inline-)?gri(d)
138 case 100:
139 return replace(value, ':', ':' + MS) + value
140 }
141 break
142 // scroll-margin, scroll-margin-(top|right|bottom|left)
143 case 5719: case 2647: case 2135: case 3927: case 2391:
144 return replace(value, 'scroll-', 'scroll-snap-') + value
145 }
146
147 return value
148}
Note: See TracBrowser for help on using the repository browser.