File tree Expand file tree Collapse file tree 3 files changed +53
-1
lines changed
neos-ui-ckeditor5-bindings/src/EditorToolbar Expand file tree Collapse file tree 3 files changed +53
-1
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ import React, {PureComponent} from 'react';
3
3
import PropTypes from 'prop-types' ;
4
4
5
5
import { neos } from '@neos-project/neos-ui-decorators' ;
6
+ import { svgToDataUri } from '@neos-project/utils-helpers' ;
6
7
import ckeIcons from './icons' ;
7
8
8
9
import style from './TableDropDown.module.css' ;
@@ -39,12 +40,14 @@ export default class TableDropDownButton extends PureComponent {
39
40
}
40
41
41
42
render ( ) {
43
+ const iconDataUri = svgToDataUri ( ckeIcons [ this . props . icon ] ) ;
44
+ console . log ( { iconDataUri} ) ;
42
45
return (
43
46
< DropDown
44
47
padded = { false }
45
48
>
46
49
< DropDown . Header title = { this . props . i18nRegistry . translate ( this . props . tooltip ) } >
47
- < img style = { { verticalAlign : 'text-top' } } src = { ckeIcons [ this . props . icon ] } alt = { this . props . i18nRegistry . translate ( this . props . tooltip ) } />
50
+ < img style = { { verticalAlign : 'text-top' } } src = { iconDataUri } alt = { this . props . i18nRegistry . translate ( this . props . tooltip ) } />
48
51
</ DropDown . Header >
49
52
< DropDown . Contents className = { style . contents } scrollable = { false } >
50
53
{ this . props . options . map ( item => item . type === 'checkBox' ? (
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ import isEmail from './isEmail';
8
8
import { isUri } from './isUri' ;
9
9
import isEqualSet from './isEqualSet' ;
10
10
import isNil from './isNil' ;
11
+ import svgToDataUri from './svgToDataUri' ;
11
12
12
13
export {
13
14
decodeHtml ,
@@ -19,6 +20,7 @@ export {
19
20
isEqualSet ,
20
21
stripTags ,
21
22
stripTagsEncoded ,
23
+ svgToDataUri ,
22
24
cancelIdleCallback ,
23
25
requestIdleCallback
24
26
} ;
Original file line number Diff line number Diff line change
1
+ const REGEX = {
2
+ whitespace : / \s + / g,
3
+ urlHexPairs : / % [ \d A - F ] { 2 } / g,
4
+ quotes : / " / g
5
+ } ;
6
+
7
+ // Function to collapse whitespace in a string
8
+ const collapseWhitespace = ( str : string ) : string =>
9
+ str . trim ( ) . replace ( REGEX . whitespace , ' ' ) ;
10
+
11
+ // Function to encode data for a URI payload
12
+ const dataURIPayload = ( string : string ) : string =>
13
+ encodeURIComponent ( string ) . replace ( REGEX . urlHexPairs , specialHexEncode ) ;
14
+
15
+ // Function to handle special hex encoding
16
+ const specialHexEncode = ( match : string ) : string => {
17
+ switch ( match ) {
18
+ case '%20' :
19
+ return ' ' ;
20
+ case '%3D' :
21
+ return '=' ;
22
+ case '%3A' :
23
+ return ':' ;
24
+ case '%2F' :
25
+ return '/' ;
26
+ default :
27
+ return match . toLowerCase ( ) ; // Compresses better
28
+ }
29
+ } ;
30
+
31
+ // Function to convert an SVG string to a tiny data URI
32
+ const svgToDataUri = ( svgString : string ) : string => {
33
+ // Strip the Byte-Order Mark if the SVG has one
34
+ if ( svgString . charCodeAt ( 0 ) === 0xfeff ) {
35
+ svgString = svgString . slice ( 1 ) ;
36
+ }
37
+
38
+ const body = collapseWhitespace ( svgString ) ;
39
+ return `data:image/svg+xml,${ dataURIPayload ( body ) } ` ;
40
+ } ;
41
+
42
+ // Add a static method to handle srcset conversions
43
+ svgToDataUri . toSrcset = ( svgString : string ) : string =>
44
+ svgToDataUri ( svgString ) . replace ( / / g, '%20' ) ;
45
+
46
+ // Export the function as the default export
47
+ export default svgToDataUri ;
You can’t perform that action at this time.
0 commit comments