From fd358787538ad4753d72391a3fea0dfc38f2e97d Mon Sep 17 00:00:00 2001 From: Kevin Levron Date: Tue, 11 May 2021 17:55:33 +0200 Subject: [PATCH] canvas fallthrough attrs #59 --- src/core/Renderer.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/core/Renderer.ts b/src/core/Renderer.ts index a97fda5..d6fcf37 100644 --- a/src/core/Renderer.ts +++ b/src/core/Renderer.ts @@ -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,