Skip to content

Commit

Permalink
Override editor style before creating canvas from HTML
Browse files Browse the repository at this point in the history
See: #2.
  • Loading branch information
Mamaduka committed Jan 27, 2020
1 parent 770f4b3 commit 5cc3496
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
2 changes: 1 addition & 1 deletion build/index.asset.php
@@ -1 +1 @@
<?php return array('dependencies' => array('lodash', 'wp-compose', 'wp-data', 'wp-edit-post', 'wp-element', 'wp-plugins', 'wp-polyfill'), 'version' => '148c2420ee5d0556bf0e3e0245ccf4b0');
<?php return array('dependencies' => array('lodash', 'wp-compose', 'wp-data', 'wp-edit-post', 'wp-element', 'wp-plugins', 'wp-polyfill'), 'version' => 'c5e62fb8b3d36ea793225edb445019a9');
2 changes: 1 addition & 1 deletion build/index.js

Large diffs are not rendered by default.

19 changes: 9 additions & 10 deletions src/util.js
Expand Up @@ -36,16 +36,15 @@ export function captureBlock( id, name ) {
const filename = kebabCase( name ) + '-screenshot';
const block = document.querySelector( `[data-block="${ id }"]` );

// Remove some styles before creating canvas.
const options = {
onclone: ( document ) => {
document.getElementById( `block-${ id }` )
.classList
.remove( 'has-child-selected' );
},
};

html2canvas( block, options ).then( ( canvas ) => {
// Hack: Temporarely override styles.
const style = document.createElement( 'style' );
document.head.appendChild( style );
style.sheet.insertRule( `#block-${ id } *::before { border: none; }`, 0 );

html2canvas( block ).then( ( canvas ) => {
download( canvas, filename );

// Remove custom style.
document.head.removeChild( style );
} );
}

0 comments on commit 5cc3496

Please sign in to comment.