File tree Expand file tree Collapse file tree 2 files changed +29
-12
lines changed
Expand file tree Collapse file tree 2 files changed +29
-12
lines changed Original file line number Diff line number Diff line change 11import type { Preflight , CSSRules , Context } from 'twind'
2- import svgToDataUri from 'mini-svg-data-uri'
32
43import { 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+ / % [ \d A - F ] { 2 } / g,
28+ specialHexEncode ,
29+ )
30+ )
31+ }
32+
633// Same as in preflight
734const 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
294318export const withForms = ( preflight ?: CSSRules | Preflight ) : Preflight => (
295319 defaultPreflight ,
Original file line number Diff line number Diff line change 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"
You can’t perform that action at this time.
0 commit comments