Skip to content

Commit f86c989

Browse files
committed
fix: inline mini-svg-data-uri as it does not export an es-module
1 parent 5cf588c commit f86c989

File tree

2 files changed

+29
-12
lines changed

2 files changed

+29
-12
lines changed

index.ts

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,35 @@
11
import type { Preflight, CSSRules, Context } from 'twind'
2-
import svgToDataUri from 'mini-svg-data-uri'
32

43
import { apply, directive } from 'twind'
54

5+
// Based on https://github.com/tigt/mini-svg-data-uri/blob/master/index.js (License MIT)
6+
const specialHexEncode = (match: string): string => {
7+
switch (
8+
match // Browsers tolerate these characters, and they're frequent
9+
) {
10+
case '%20':
11+
return ' '
12+
case '%3D':
13+
return '='
14+
case '%3A':
15+
return ':'
16+
case '%2F':
17+
return '/'
18+
default:
19+
return match.toLowerCase() // compresses better
20+
}
21+
}
22+
23+
const svgToDataUri = (svgString: string): string => {
24+
return (
25+
'data:image/svg+xml,' +
26+
encodeURIComponent(svgString.trim().replace(/\s+/g, ' ').replace(/"/g, "'")).replace(
27+
/%[\dA-F]{2}/g,
28+
specialHexEncode,
29+
)
30+
)
31+
}
32+
633
// Same as in preflight
734
const placeholder = ({ theme }: Context): CSSRules => ({
835
'&::placeholder': {
@@ -286,10 +313,7 @@ const styles = (selector: string): CSSRules => ({
286313
// },
287314
})
288315

289-
export const forms = directive(
290-
(): CSSRules => styles(''),
291-
undefined,
292-
)
316+
export const forms = directive((): CSSRules => styles(''), undefined)
293317

294318
export const withForms = (preflight?: CSSRules | Preflight): Preflight => (
295319
defaultPreflight,

package.json

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,6 @@
3131
".": "./index.ts",
3232
"./package.json": "./package.json"
3333
},
34-
"// These are ONLY bundled (eg included) in the umd builds": "",
35-
"bundledDependencies": [
36-
"mini-svg-data-uri"
37-
],
38-
"dependencies": {
39-
"mini-svg-data-uri": "^1.2.3"
40-
},
4134
"peerDependencies": {
4235
"twind": ">=0.14.4",
4336
"typescript": "^4.1.0"

0 commit comments

Comments
 (0)