Skip to content

Commit 49108c8

Browse files
Andaristemmatown
andauthored
Removed auto-prefixing for widely available features (#3296)
* Drop prefixer * changeset * Revert "Drop prefixer" This reverts commit 3759507. * prefix what's not widely-avaialble * Remove moz and ms prefixes for user-select, hyphens, text-size-adjust * Remove zoom- and grab prefixing in cursor property * Remove unused moz and mz prefix imports * Remove image-set prefixing in cursor (image-set will be widely available so soon, just prefixing image-set for cursor is weird and cursor is such a small progressive enhancement thing anyway that if it doesn't work in older browsers, it's fine) * update snapshots * update changeset --------- Co-authored-by: Emma Hamilton <[email protected]>
1 parent 07353f9 commit 49108c8

20 files changed

+53
-971
lines changed

.changeset/late-horses-join.md

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
'@emotion/styled': major
3+
'@emotion/cache': major
4+
'@emotion/react': major
5+
'@emotion/css': major
6+
---
7+
8+
Removed auto-prefixing for widely available features.

packages/cache/__tests__/__snapshots__/index.js.snap

+2-5
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22

33
exports[`should accept container option 1`] = `
44
.emotion-0 {
5-
display: -webkit-box;
6-
display: -webkit-flex;
7-
display: -ms-flexbox;
85
display: flex;
96
color: blue;
107
}
@@ -22,7 +19,7 @@ exports[`should accept container option 1`] = `
2219
data-s=""
2320
>
2421
25-
.emotion-0{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;color:blue;}
22+
.emotion-0{display:flex;color:blue;}
2623
</style>
2724
</div>
2825
<div>
@@ -45,7 +42,7 @@ exports[`should accept insertionPoint option 1`] = `
4542
data-s=""
4643
>
4744
48-
.test-insertion-point-83n355{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;color:blue;}
45+
.test-insertion-point-83n355{display:flex;color:blue;}
4946
</style>
5047
5148

packages/cache/src/prefixer.ts

+10-321
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,16 @@
11
/* eslint-disable no-fallthrough */
22
/* eslint-disable eqeqeq */
3-
import {
4-
charat,
5-
combine,
6-
copy,
7-
DECLARATION,
8-
hash,
9-
indexof,
10-
KEYFRAMES,
11-
match,
12-
MOZ,
13-
MS,
14-
replace,
15-
RULESET,
16-
serialize,
17-
strlen,
18-
WEBKIT,
19-
Element,
20-
Middleware
21-
} from 'stylis'
3+
import { DECLARATION, Element, hash, WEBKIT } from 'stylis'
224

23-
// this is a copy of [email protected] prefixer, the latter version introduced grid prefixing which we don't want
5+
// this is a slice of [email protected] prefixer, the latter version introduced grid prefixing which we don't want
6+
// this version only includes css properties that are not widely available according to https://web-platform-dx.github.io/web-features/
247

258
function prefix(value: string, length: number): string {
269
switch (hash(value, length)) {
2710
// color-adjust
2811
case 5103:
2912
return WEBKIT + 'print-' + value + value
30-
// animation, animation-(delay|direction|duration|fill-mode|iteration-count|name|play-state|timing-function)
31-
case 5737:
32-
case 4201:
33-
case 3177:
34-
case 3433:
35-
case 1641:
36-
case 4457:
37-
case 2921:
38-
// text-decoration, filter, clip-path, backface-visibility, column, box-decoration-break
39-
case 5572:
40-
case 6356:
41-
case 5844:
42-
case 3191:
43-
case 6645:
13+
// box-decoration-break
4414
case 3005:
4515
// mask, mask-image, mask-(mode|clip|size), mask-(repeat|origin), mask-position, mask-composite,
4616
case 6391:
@@ -49,299 +19,18 @@ function prefix(value: string, length: number): string {
4919
case 6135:
5020
case 4599:
5121
case 4855:
52-
// background-clip, columns, column-(count|fill|gap|rule|rule-color|rule-style|rule-width|span|width)
53-
case 4215:
54-
case 6389:
55-
case 5109:
56-
case 5365:
57-
case 5621:
58-
case 3829:
59-
return WEBKIT + value + value
60-
// appearance, user-select, transform, hyphens, text-size-adjust
61-
case 5349:
22+
// user-select, hyphens, text-size-adjust
6223
case 4246:
63-
case 4810:
6424
case 6968:
6525
case 2756:
66-
return WEBKIT + value + MOZ + value + MS + value + value
67-
// flex, flex-direction
68-
case 6828:
69-
case 4268:
70-
return WEBKIT + value + MS + value + value
71-
// order
72-
case 6165:
73-
return WEBKIT + value + MS + 'flex-' + value + value
74-
// align-items
75-
case 5187:
76-
return (
77-
WEBKIT +
78-
value +
79-
replace(
80-
value,
81-
/(\w+).+(:[^]+)/,
82-
WEBKIT + 'box-$1$2' + MS + 'flex-$1$2'
83-
) +
84-
value
85-
)
86-
// align-self
87-
case 5443:
88-
return (
89-
WEBKIT +
90-
value +
91-
MS +
92-
'flex-item-' +
93-
replace(value, /flex-|-self/, '') +
94-
value
95-
)
96-
// align-content
97-
case 4675:
98-
return (
99-
WEBKIT +
100-
value +
101-
MS +
102-
'flex-line-pack' +
103-
replace(value, /align-content|flex-|-self/, '') +
104-
value
105-
)
106-
// flex-shrink
107-
case 5548:
108-
return WEBKIT + value + MS + replace(value, 'shrink', 'negative') + value
109-
// flex-basis
110-
case 5292:
111-
return (
112-
WEBKIT + value + MS + replace(value, 'basis', 'preferred-size') + value
113-
)
114-
// flex-grow
115-
case 6060:
116-
return (
117-
WEBKIT +
118-
'box-' +
119-
replace(value, '-grow', '') +
120-
WEBKIT +
121-
value +
122-
MS +
123-
replace(value, 'grow', 'positive') +
124-
value
125-
)
126-
// transition
127-
case 4554:
128-
return (
129-
WEBKIT +
130-
replace(value, /([^-])(transform)/g, '$1' + WEBKIT + '$2') +
131-
value
132-
)
133-
// cursor
134-
case 6187:
135-
return (
136-
replace(
137-
replace(
138-
replace(value, /(zoom-|grab)/, WEBKIT + '$1'),
139-
/(image-set)/,
140-
WEBKIT + '$1'
141-
),
142-
value,
143-
''
144-
) + value
145-
)
146-
// background, background-image
147-
case 5495:
148-
case 3959:
149-
return replace(value, /(image-set\([^]*)/, WEBKIT + '$1' + '$`$1')
150-
// justify-content
151-
case 4968:
152-
return (
153-
replace(
154-
replace(
155-
value,
156-
/(.+:)(flex-)?(.*)/,
157-
WEBKIT + 'box-pack:$3' + MS + 'flex-pack:$3'
158-
),
159-
/s.+-b[^;]+/,
160-
'justify'
161-
) +
162-
WEBKIT +
163-
value +
164-
value
165-
)
166-
// (margin|padding)-inline-(start|end)
167-
case 4095:
168-
case 3583:
169-
case 4068:
170-
case 2532:
171-
return replace(value, /(.+)-inline(.+)/, WEBKIT + '$1$2') + value
172-
// (min|max)?(width|height|inline-size|block-size)
173-
case 8116:
174-
case 7059:
175-
case 5753:
176-
case 5535:
177-
case 5445:
178-
case 5701:
179-
case 4933:
180-
case 4677:
181-
case 5533:
182-
case 5789:
183-
case 5021:
184-
case 4765:
185-
// stretch, max-content, min-content, fill-available
186-
if (strlen(value) - 1 - length > 6)
187-
switch (charat(value, length + 1)) {
188-
// (m)ax-content, (m)in-content
189-
case 109:
190-
// -
191-
if (charat(value, length + 4) !== 45) break
192-
// (f)ill-available, (f)it-content
193-
case 102:
194-
return (
195-
replace(
196-
value,
197-
/(.+:)(.+)-([^]+)/,
198-
'$1' +
199-
WEBKIT +
200-
'$2-$3' +
201-
'$1' +
202-
MOZ +
203-
(charat(value, length + 3) == 108 ? '$3' : '$2-$3')
204-
) + value
205-
)
206-
// (s)tretch
207-
case 115:
208-
return ~indexof(value, 'stretch')
209-
? prefix(replace(value, 'stretch', 'fill-available'), length) +
210-
value
211-
: value
212-
}
213-
break
214-
// position: sticky
215-
case 4949:
216-
// (s)ticky?
217-
if (charat(value, length + 1) !== 115) break
218-
// display: (flex|inline-flex)
219-
case 6444:
220-
switch (
221-
charat(value, strlen(value) - 3 - (~indexof(value, '!important') && 10))
222-
) {
223-
// stic(k)y
224-
case 107:
225-
return replace(value, ':', ':' + WEBKIT) + value
226-
// (inline-)?fl(e)x
227-
case 101:
228-
return (
229-
replace(
230-
value,
231-
/(.+:)([^;!]+)(;|!.+)?/,
232-
'$1' +
233-
WEBKIT +
234-
(charat(value, 14) === 45 ? 'inline-' : '') +
235-
'box$3' +
236-
'$1' +
237-
WEBKIT +
238-
'$2$3' +
239-
'$1' +
240-
MS +
241-
'$2box$3'
242-
) + value
243-
)
244-
}
245-
break
246-
// writing-mode
247-
case 5936:
248-
switch (charat(value, length + 11)) {
249-
// vertical-l(r)
250-
case 114:
251-
return (
252-
WEBKIT +
253-
value +
254-
MS +
255-
replace(value, /[svh]\w+-[tblr]{2}/, 'tb') +
256-
value
257-
)
258-
// vertical-r(l)
259-
case 108:
260-
return (
261-
WEBKIT +
262-
value +
263-
MS +
264-
replace(value, /[svh]\w+-[tblr]{2}/, 'tb-rl') +
265-
value
266-
)
267-
// horizontal(-)tb
268-
case 45:
269-
return (
270-
WEBKIT +
271-
value +
272-
MS +
273-
replace(value, /[svh]\w+-[tblr]{2}/, 'lr') +
274-
value
275-
)
276-
}
277-
278-
return WEBKIT + value + MS + value + value
26+
return WEBKIT + value + value
27927
}
28028

28129
return value
28230
}
28331

284-
export let prefixer = (
285-
element: Element,
286-
index: number,
287-
children: Element[],
288-
callback: Middleware
289-
) => {
290-
if (element.length > -1)
291-
if (!element.return)
292-
switch (element.type) {
293-
case DECLARATION:
294-
element.return = prefix(element.value, element.length)
295-
break
296-
case KEYFRAMES:
297-
return serialize(
298-
[
299-
copy(element, {
300-
value: replace(element.value, '@', '@' + WEBKIT)
301-
})
302-
],
303-
callback
304-
)
305-
case RULESET:
306-
if (element.length)
307-
return combine(element.props as string[], function (value) {
308-
switch (match(value, /(::plac\w+|:read-\w+)/)) {
309-
// :read-(only|write)
310-
case ':read-only':
311-
case ':read-write':
312-
return serialize(
313-
[
314-
copy(element, {
315-
props: [replace(value, /:(read-\w+)/, ':' + MOZ + '$1')]
316-
})
317-
],
318-
callback
319-
)
320-
// :placeholder
321-
case '::placeholder':
322-
return serialize(
323-
[
324-
copy(element, {
325-
props: [
326-
replace(
327-
value,
328-
/:(plac\w+)/,
329-
':' + WEBKIT + 'input-$1'
330-
)
331-
]
332-
}),
333-
copy(element, {
334-
props: [replace(value, /:(plac\w+)/, ':' + MOZ + '$1')]
335-
}),
336-
copy(element, {
337-
props: [replace(value, /:(plac\w+)/, MS + 'input-$1')]
338-
})
339-
],
340-
callback
341-
)
342-
}
343-
344-
return ''
345-
})
346-
}
32+
export let prefixer = (element: Element) => {
33+
if (element.length > -1 && !element.return && element.type === DECLARATION) {
34+
element.return = prefix(element.value, element.length)
35+
}
34736
}

0 commit comments

Comments
 (0)