From cfb762c6cbfb30c454d677019e0f259f97943b6a Mon Sep 17 00:00:00 2001
From: FliPPeDround <734243792@qq.com>
Date: Fri, 10 Nov 2023 18:03:21 +0800
Subject: [PATCH] feat: use UI createElement
---
examples/vue3/src/App.vue | 39 +++++++++++--
packages/vue3/components/application/index.ts | 2 +-
packages/vue3/renderer/renderer.ts | 58 +++++++------------
3 files changed, 57 insertions(+), 42 deletions(-)
diff --git a/examples/vue3/src/App.vue b/examples/vue3/src/App.vue
index 9753074..9d4b326 100644
--- a/examples/vue3/src/App.vue
+++ b/examples/vue3/src/App.vue
@@ -1,18 +1,47 @@
-
-
+
+
+
+
+
+
+
+ aaaa
+
+
+
+
+
diff --git a/packages/vue3/components/application/index.ts b/packages/vue3/components/application/index.ts
index a142a22..74d1f6f 100644
--- a/packages/vue3/components/application/index.ts
+++ b/packages/vue3/components/application/index.ts
@@ -7,7 +7,7 @@ export default defineComponent({
const canvas = ref()
function mount() {
- const context = new Leafer({ view: window })
+ const context = new Leafer({ view: canvas.value })
const app = createApp({
render: () => renderSlot(slots, 'default'),
diff --git a/packages/vue3/renderer/renderer.ts b/packages/vue3/renderer/renderer.ts
index 9b7d1d6..3623771 100644
--- a/packages/vue3/renderer/renderer.ts
+++ b/packages/vue3/renderer/renderer.ts
@@ -1,45 +1,16 @@
-import { Rect, Text } from 'leafer-ui'
+import { UI } from 'leafer-ui'
import { createRenderer } from 'vue'
// export function createRenderer() {
// }
-export const renderer = createRenderer({
+export const renderer = createRenderer({
createElement(type) {
- let element
- switch (type) {
- case 'Rect':
- element = new Rect({
- width: 15,
- height: 15,
- fill: 'rgb(50,205,121)',
- })
- break
-
- default:
- throw new Error(`无${type}`)
- break
- }
- return element
+ return UI.one({ tag: type })
},
patchProp(el, key, prevValue, nextValue) {
- switch (key) {
- case 'fill' :
- el.fill = nextValue
- break
-
- case 'x':
- el.x = nextValue
- break
-
- case 'y':
- el.y = nextValue
- break
-
- default:
- break
- }
+ el[key] = nextValue
},
insert(el, parent, anchor) {
if (el && parent)
@@ -50,10 +21,10 @@ export const renderer = createRenderer({
el.parent.remove(el)
},
createText(text) {
- return new Text({ text })
+ return new Error('a') as unknown as UI
},
createComment(text) {
- return new Text({ text })
+ return new Error('a') as unknown as UI
},
setText(node, text) {
@@ -62,9 +33,24 @@ export const renderer = createRenderer({
},
parentNode(node) {
- return node.parent as unknown as Rect
+ return node.parent
},
nextSibling(node) {
return null
},
})
+
+// export function createRenderer(options: { prefix?: string } = {}) {
+// const { createElement, setText, ...nodeOps } = _nodeOps
+// const { prefix = 'pixi' } = options
+// const rendererOptions = rendererWithCapture({
+// createElement: (...args) => createElement(prefix, ...args),
+// setElementText: (...args) => setText(prefix, ...args),
+// setText: (...args) => setText(prefix, ...args),
+// patchProp,
+// ...nodeOps,
+// })
+// return _createRenderer(rendererOptions)
+// }
+
+// export const createApp = renderer.createApp