Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use Shadow DOM to avoid CSS conflicts #13

Merged
merged 1 commit into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions playground/vite/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
style="text-decoration: none; margin-top: 10px; display: block"
>You can use right panel to control your layout image.</a
>
<button>style test</button>
<script type="module" src="./main.ts"></script>
</body>
</html>
1 change: 0 additions & 1 deletion popup/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,3 @@ const handleClickOperation = (offset: number) => {
}
}
</script>
./utils
17 changes: 15 additions & 2 deletions popup/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,34 @@ import type { Component } from 'vue'

import App from './App.vue'

import './index.css'
import styles from './index.css?inline'

function createDevToolsContainer(App: Component) {
// Plugin root div
const CONTAINER_ID = '__vue-overlay-layout__'
const el = document.createElement('div')
el.setAttribute('id', CONTAINER_ID)
el.setAttribute('data-v-inspector-ignore', 'true')

// Use Shadow DOM to avoid CSS conflicts
const shadowRoot = el.attachShadow({ mode: 'open' })
const styleEl = document.createElement('style')
styleEl.textContent = styles
shadowRoot.appendChild(styleEl)

const contentEl = document.createElement('div')
contentEl.setAttribute('id', 'shadow-root-content')
shadowRoot.appendChild(contentEl)

document.getElementsByTagName('body')[0].appendChild(el)

const app = createApp({
render: () => h(App),
devtools: {
hide: true
}
})
app.mount(el)
app.mount(contentEl)
}

createDevToolsContainer(App)
8 changes: 0 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,6 @@ export const unpluginFactory: UnpluginFactory<Options | undefined> = (
type: 'module',
src: '/__OVERLAY_LAYOUT__/overlay-layout.js'
}
},
{
tag: 'link',
injectTo: 'head',
attrs: {
rel: 'stylesheet',
href: '/__OVERLAY_LAYOUT__/overlay-layout.css'
}
}
]
}
Expand Down
4 changes: 0 additions & 4 deletions src/nuxt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,5 @@ export default defineNuxtModule<ModuleOptions>({
}
]
)

nuxt.options.app.head.link.push(
...[{ rel: 'stylesheet', href: '/__OVERLAY_LAYOUT__/overlay-layout.css' }]
)
}
})
Loading