1
0
mirror of https://github.com/troisjs/trois.git synced 2024-11-23 20:02:32 +08:00

canvas fallthrough attrs #59

This commit is contained in:
Kevin Levron 2021-05-11 17:55:33 +02:00
parent 8c1c81bc94
commit fd35878753

View File

@ -114,7 +114,8 @@ export default defineComponent({
onReady: Function as PropType<(r: RendererInterface) => void>,
onClick: Function as PropType<(this: HTMLCanvasElement, ev: MouseEvent) => any>,
},
setup(props): RendererSetupInterface {
inheritAttrs: false,
setup(props, { attrs }): RendererSetupInterface {
const initCallbacks: InitCallbackType[] = []
const mountedCallbacks: MountedCallbackType[] = []
const beforeRenderCallbacks: RenderCallbackType[] = []
@ -122,6 +123,15 @@ export default defineComponent({
const resizeCallbacks: ResizeCallbackType[] = []
const canvas = document.createElement('canvas')
Object.entries(attrs).forEach(([key, value]) => {
const matches = key.match(/^on([A-Z][a-zA-Z]*)$/)
if (matches) {
canvas.addEventListener(matches[1].toLowerCase(), value as {(): void })
} else {
canvas.setAttribute(key, value as string)
}
})
const config: ThreeConfigInterface = {
canvas,
antialias: props.antialias,