Skip to content

Commit

Permalink
fix: pack css in js
Browse files Browse the repository at this point in the history
  • Loading branch information
YunYouJun committed Dec 25, 2023
1 parent 22aec8a commit f2fdb77
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 9 deletions.
7 changes: 5 additions & 2 deletions packages/blender-ui/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ export * from './components'
export * from './styles'
export * from './utils'

export default {
createBUI,
if (typeof window !== 'undefined') {
// @ts-expect-error global
window.BUI = {
createBUI,
}
}

export { reactive, ref } from 'vue'
29 changes: 28 additions & 1 deletion packages/blender-ui/client/utils/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,36 @@ export interface PropertyOptions {
onChange?: (val: number) => void
}

export function createBUI(selector: string | Element = 'advjs-blender-ui-container', props: any = {}) {
export function createBUI({
selector = '#advjs-blender-ui-container',
props,
}: {
selector?: string
props: {
panels: {
properties: PropertyOptions[]
}[]
}
}) {
const app = createApp(App, props)

// 如果传入的是字符串,且没有找到对应的元素,则创建一个
if (typeof selector === 'string' && !document.querySelector(selector)) {
const targetEl = document.createElement('div')
targetEl.id = 'advjs-blender-ui-container'
targetEl.style.position = 'fixed'
targetEl.style.top = '0'
targetEl.style.right = '0'
targetEl.style.zIndex = '9999'
targetEl.style.width = '300px'

document.body.appendChild(targetEl)

selector = `#${targetEl.id}`
}

app.mount(selector)

return {
app,

Expand Down
3 changes: 2 additions & 1 deletion packages/blender-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"devDependencies": {
"@vitejs/plugin-vue": "^4.5.2",
"tsx": "^4.7.0",
"vite": "^5.0.10"
"vite": "^5.0.10",
"vite-plugin-css-injected-by-js": "^3.3.1"
}
}
4 changes: 4 additions & 0 deletions packages/blender-ui/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@ import { resolve } from 'node:path'
import { defineConfig } from 'vite'

import vue from '@vitejs/plugin-vue'
import cssInjectedByJsPlugin from 'vite-plugin-css-injected-by-js'

export default defineConfig({
plugins: [
vue(),

// css in js
cssInjectedByJsPlugin(),
],

build: {
Expand Down
21 changes: 16 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f2fdb77

Please sign in to comment.