@@ -13,7 +13,7 @@ import hljs from './highlight-config';
13
13
import daisyuiThemes from 'daisyui/src/theming/themes' ;
14
14
15
15
// ponyfill for missing ReadableStream asyncIterator on Safari
16
- import { asyncIterator } from " @sec-ant/readable-stream/ponyfill/asyncIterator" ;
16
+ import { asyncIterator } from ' @sec-ant/readable-stream/ponyfill/asyncIterator' ;
17
17
18
18
const isDev = import . meta. env . MODE === 'development' ;
19
19
@@ -22,7 +22,22 @@ const isString = (x) => !!x.toLowerCase;
22
22
const isBoolean = ( x ) => x === true || x === false ;
23
23
const isNumeric = ( n ) => ! isString ( n ) && ! isNaN ( n ) && ! isBoolean ( n ) ;
24
24
const escapeAttr = ( str ) => str . replace ( / > / g, '>' ) . replace ( / " / g, '"' ) ;
25
- const copyStr = ( str ) => navigator . clipboard . writeText ( str ) ;
25
+ const copyStr = ( textToCopy ) => {
26
+ // Navigator clipboard api needs a secure context (https)
27
+ if ( navigator . clipboard && window . isSecureContext ) {
28
+ navigator . clipboard . writeText ( textToCopy ) ;
29
+ } else {
30
+ // Use the 'out of viewport hidden text area' trick
31
+ const textArea = document . createElement ( 'textarea' ) ;
32
+ textArea . value = textToCopy ;
33
+ // Move textarea out of the viewport so it's not visible
34
+ textArea . style . position = 'absolute' ;
35
+ textArea . style . left = '-999999px' ;
36
+ document . body . prepend ( textArea ) ;
37
+ textArea . select ( ) ;
38
+ document . execCommand ( 'copy' ) ;
39
+ }
40
+ } ;
26
41
27
42
// constants
28
43
const BASE_URL = isDev
@@ -130,9 +145,9 @@ const VueMarkdown = defineComponent(
130
145
} ;
131
146
window . copyStr = copyStr ;
132
147
const content = computed ( ( ) => md . value . render ( props . source ) ) ;
133
- return ( ) => h ( " div" , { innerHTML : content . value } ) ;
148
+ return ( ) => h ( ' div' , { innerHTML : content . value } ) ;
134
149
} ,
135
- { props : [ " source" ] }
150
+ { props : [ ' source' ] }
136
151
) ;
137
152
138
153
// input field to be used by settings modal
0 commit comments