Skip to content

Commit

Permalink
get theme styles
Browse files Browse the repository at this point in the history
  • Loading branch information
mxkae committed Oct 4, 2023
1 parent 7db1892 commit 88cf335
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/plugins/global-settings/typography/get-theme-styles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
export const getThemeStyles = () => {
const iframe = document.querySelector( 'iframe[name="editor-canvas"]' )
let themeStyles = ''

if ( iframe ) {
const doc = iframe.contentDocument || iframe.contentWindow.document

// theme styles are stored in <style> tags that are direct children of body
let styleList = doc.querySelectorAll( 'body style' )

// converts node list to array
styleList = Array.from( styleList )

styleList.forEach( style => {
// retrieves css rules with .editor-styles-wrapper only
if ( ! style.hasAttribute( 'id' ) && style.innerHTML.includes( '.editor-styles-wrapper' ) ) {
themeStyles += style.innerHTML
}
} )
}
return themeStyles
}
2 changes: 2 additions & 0 deletions src/plugins/global-settings/typography/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/
import { GlobalTypographyStyles } from './editor-loader'
import TypographyPicker from './typography-picker'
import { getThemeStyles } from './get-theme-styles'

/**
* External dependencies
Expand Down Expand Up @@ -163,6 +164,7 @@ addFilter( 'stackable.global-settings.inspector', 'stackable/global-typography',
default="blocks-stackable-native"
/>
<ControlSeparator />
<style> { getThemeStyles() } </style>
{ TYPOGRAPHY_TAGS.map( ( {
label, selector, help,
}, index ) => {
Expand Down

0 comments on commit 88cf335

Please sign in to comment.