@@ -39,25 +39,35 @@ export function getSnippetElement(event: Event) {
3939 throw new Error ( 'Could not find snippet element' ) ;
4040}
4141
42- export async function withExtraStyles ( target : HTMLElement , next : ( ) => Promise < void > ) {
43- let pre = target . querySelector ( 'pre' ) ;
44-
45- if ( ! pre ) {
46- return await next ( ) ;
47- }
48-
49- pre . classList . add ( 'drop-shadow-lg' ) ;
50- pre . style . margin = '0' ;
42+ /**
43+ * Cloning elements for screenshotting is hard.
44+ * Look at all this:
45+ * https://github.com/bubkoo/html-to-image/blob/128dc3edfde95d6ac636f2756630f5cbd6f7c8df/src/clone-node.ts#L231
46+ *
47+ * So instead, we jitter a bit
48+ */
49+ export async function copyToClipboard ( toCopy : HTMLElement ) {
50+ let pre = toCopy . querySelector ( 'pre' ) ;
5151
5252 try {
53- await next ( ) ;
53+ pre ?. classList . add ( 'drop-shadow-lg' ) ;
54+ Object . assign ( toCopy . style , {
55+ margin : 0 ,
56+ display : 'inline-block' ,
57+ width : 'fit-content' ,
58+ } ) ;
59+ await toClipboard ( toCopy ) ;
5460 } finally {
55- pre . classList . remove ( 'drop-shadow-lg' ) ;
56- pre . setAttribute ( 'style' , '' ) ;
61+ pre ?. classList . remove ( 'drop-shadow-lg' ) ;
62+ Object . assign ( toCopy . style , {
63+ margin : 'unset' ,
64+ display : 'unset' ,
65+ width : 'unset' ,
66+ } ) ;
5767 }
5868}
5969
60- export async function toClipboard ( target : HTMLElement ) {
70+ async function toClipboard ( target : HTMLElement ) {
6171 let backgroundColor = '#ffffff' ;
6272 let canCopyToImage = 'ClipboardItem' in window ;
6373 let filter = ( node : HTMLElement | Text ) => {
@@ -67,6 +77,10 @@ export async function toClipboard(target: HTMLElement) {
6777 return false ;
6878 }
6979
80+ if ( 'classList' in node && node . classList . contains ( 'limber__menu__content' ) ) {
81+ return false ;
82+ }
83+
7084 return true ;
7185 } ;
7286
@@ -79,10 +93,12 @@ export async function toClipboard(target: HTMLElement) {
7993 // html-to-image does not make adjustments if margins exist anyway
8094 width : box . width + 32 ,
8195 height : box . height + 32 ,
96+ cacheBust : true ,
97+ /**
98+ * Good for pasting on social medias
99+ */
82100 pixelRatio : 3 ,
83101 style : {
84- // m-0
85- // make margin uniform all the way around
86102 margin : '1rem' ,
87103 } ,
88104 } ;
0 commit comments