Skip to content

Commit

Permalink
chore: small changes
Browse files Browse the repository at this point in the history
  • Loading branch information
surunzi committed Sep 13, 2024
1 parent f730779 commit 2ba9cdb
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 8 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
"ts-loader": "^8.4.0",
"typedoc": "^0.26.3",
"typescript": "^4.8.3",
"vue": "^3.5.4",
"webpack": "^4.47.0",
"webpack-bundle-analyzer": "^4.4.2",
"webpack-cli": "^3.3.11"
Expand Down
15 changes: 13 additions & 2 deletions src/shader-toy-player/story.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ import 'luna-shader-toy-player.css'
import ShaderToyPlayer from 'luna-shader-toy-player.js'
import readme from './README.md'
import story from '../share/story'
import h from 'licia/h'
import $ from 'licia/$'
import shaders, { cube } from './shaders'
import LunaShaderToyPlayer from './vue'
import { defineComponent, h } from 'vue'
import { text, optionsKnob, button } from '@storybook/addon-knobs'

const def = story(
Expand Down Expand Up @@ -74,9 +75,19 @@ const def = story(
{
readme,
source: __STORY__,
VueComponent() {
return defineComponent({
components: {
LunaShaderToyPlayer,
},
render() {
return h('div', 'hello')
},
})
},
}
)

export default def

export const { shaderToyPlayer } = def
export const { shaderToyPlayer: html, vue } = def
9 changes: 9 additions & 0 deletions src/shader-toy-player/vue.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { defineComponent, h } from 'vue'

const LunaShaderToyPlayer = defineComponent({
render() {
return h('div', 'Hello world')
},
})

export default LunaShaderToyPlayer
36 changes: 30 additions & 6 deletions src/share/story.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import now from 'licia/now'
import ReactDOM from 'react-dom'
import * as registerKnobs from '@storybook/addon-knobs/dist/registerKnobs'
import { optionsKnob } from '@storybook/addon-knobs'
import { createApp } from 'vue'

export default function story(
name,
Expand All @@ -27,6 +28,7 @@ export default function story(
layout = 'padded',
themes = {},
ReactComponent = false,
VueComponent = false,
} = {}
) {
const container = h('div')
Expand Down Expand Up @@ -67,9 +69,8 @@ export default function story(
window.component = window.components[0]
window.componentName = upperFirst(camelCase(name))

document.documentElement.style.background = contain(theme, 'dark')
? '#000'
: '#fff'
updateBackground(theme)

each(window.components, (component) =>
component.setOption('theme', theme)
)
Expand All @@ -92,14 +93,31 @@ export default function story(

ReactDOM.render(<ReactComponent theme={theme} />, container)

document.documentElement.style.background = contain(theme, 'dark')
? '#000'
: '#fff'
updateBackground(theme)

return container
}
}

if (VueComponent) {
const container = h('div')

ret.vue = function () {
fixKnobs(`vue-${name}`)

const { theme } = createKnobs()
window.components = []
delete window.component
window.componentName = upperFirst(camelCase(`vue-${name}`))

createApp(VueComponent({ theme })).mount(container)

updateBackground(theme)

return container
}
}

function createKnobs() {
const theme = optionsKnob(
'Theme',
Expand Down Expand Up @@ -158,3 +176,9 @@ function fixKnobs(name) {
each(window.components, (component) => component.destroy())
}
}

function updateBackground(theme) {
document.documentElement.style.background = contain(theme, 'dark')
? '#000'
: '#fff'
}

0 comments on commit 2ba9cdb

Please sign in to comment.