{"id":13672862,"url":"https://github.com/huruji/vuvas","last_synced_at":"2025-04-10T16:12:16.986Z","repository":{"id":57149248,"uuid":"288423206","full_name":"huruji/vuvas","owner":"huruji","description":"use vue.js + canvas build ui inspired by revas","archived":false,"fork":false,"pushed_at":"2020-09-29T16:24:20.000Z","size":2226,"stargazers_count":21,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-24T14:01:39.050Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/huruji.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-08-18T10:20:10.000Z","updated_at":"2024-06-19T06:11:27.000Z","dependencies_parsed_at":"2022-08-31T23:50:30.832Z","dependency_job_id":null,"html_url":"https://github.com/huruji/vuvas","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/huruji%2Fvuvas","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/huruji%2Fvuvas/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/huruji%2Fvuvas/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/huruji%2Fvuvas/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/huruji","download_url":"https://codeload.github.com/huruji/vuvas/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248231976,"owners_count":21069428,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-02T09:01:52.953Z","updated_at":"2025-04-10T16:12:16.966Z","avatar_url":"https://github.com/huruji.png","language":"TypeScript","readme":"[English](./README_EN.md) | 中文\n\n\u003ch2 align=\"center\"\u003e使用 vue 3.0 + css 在 canvas 上绘制高性能 UI\u003c/h2\u003e\n\n\n- [例子](#例子)\n- [原理](#原理)\n- [快速开始](#快速开始)\n- [组件](#组件)\n  - [View](#view)\n  - [Text](#text)\n  - [Image](#image)\n  - [Touchable](#touchable)\n  - [ScrollView](#scrollview)\n- [致谢](#致谢)\n\n## 例子\n\u003cp style=\"text-align:center\"\u003e\n  \u003cimg  width=\"100%\" src=\"./assets/example.png\" /\u003e\n\u003c/p\u003e\n\n运行例子:\n\n```bash\nnpm run dev:demo\n```\n\n更多例子：[https://codesandbox.io/u/huruji/sandboxes](https://codesandbox.io/u/huruji/sandboxes)\n\n\n## 原理\n\nVue 3.0 中 将 dom 的渲染器单独抽离为了 [@vue/runtime-dom](https://github.com/vuejs/vue-next/tree/master/packages/runtime-dom)，[@vue/runtime-dom](https://github.com/vuejs/vue-next/tree/master/packages/runtime-dom) 可以看作是基于 [@vue/runtime-core](https://github.com/vuejs/vue-next/tree/master/packages/runtime-core) 提供的 API 构建的 web DOM 渲染器，[@vue/runtime-core](https://github.com/vuejs/vue-next/tree/master/packages/runtime-core) 可以看作是与环境无关的 vue 核心实现，Vuvas 真是基于此来构建的 Canvas 环境下的渲染器。Vuvas 底层布局基于 [yoga-layout](https://github.com/facebook/yoga)，因此可以很方便的使用 css flexbox 来布局我们的页面。\n\n## 快速开始\n\n安装\n\n```bash\nnpm i vuvas -S\n```\n\n使用\n\n\u003e index.ts\n\n```js\nimport { createApp } from 'vuvas'\nimport App from './index.vue'\n\ncreateApp(App).mount(document.querySelector('#app'))\n```\n\n\u003e index.vue\n\n```html\n\u003ctemplate\u003e\n  \u003cView :style=\"styles.view\"\u003e\n      \u003cText :style=\"styles.text\"\u003e{{text}}\u003c/Text\u003e\n  \u003c/View\u003e\n\u003c/template\u003e\n\n\u003cscript\u003e\nimport { ref } from \"vue\";\n\nexport default {\n  data() {\n    return {\n      text: 'vuvas',\n      styles: {\n        view: {\n          height: 55,\n          backgroundColor: \"#D8D8D8\",\n        },\n        text: {\n          fontSize: 12,\n          color: \"#000\",\n        },\n      },\n    }\n  }\n};\n\u003c/script\u003e\n```\n\n## 组件\n\nVuvas 内置了帮助我们构建 UI 的基础组件，可以把这些组件视作 Vuvas 环境下的标准组件（类似于 web 环境下的 div、p等标签）。\n\n### View\n\n基础的布局组件，类似于 dom 中的 div、section 标签，例子：\n\n代码：\n\n\u003e 在 [code sandbox](https://codesandbox.io/s/view-component-qfo7j) 中打开\n\n```html\n\u003ctemplate\u003e\n  \u003cView :style=\"styles.container\"\u003e\n    \u003cView :style=\"styles.content\"\u003e\u003c/View\u003e\n  \u003c/View\u003e\n\u003c/template\u003e\n\u003cscript\u003e\nexport default {\n  setup() {\n    return {\n      styles: {\n        container: {\n          backgroundColor: '#fff',\n          justifyContent: 'center',\n          flex: 1,\n          alignItems: 'center'\n        },\n        content: {\n          height: 200,\n          width: 400,\n          backgroundColor: '#41b883',\n          borderWidth: 4,\n          borderColor: '#35495e'\n        }\n      },\n    };\n  },\n};\n\u003c/script\u003e\n```\n\n效果：\n\n![](./assets/View.png)\n\n### Text\n\n文本标签，可以在标签内部添加文字，类似 dom 中的 p 标签，例子：\n\n代码：\n\n\u003e 在 [code sandbox](https://codesandbox.io/s/text-component-wcs6d) 中打开\n\n```html\n\u003ctemplate\u003e\n  \u003cView :style=\"styles.container\"\u003e\n    \u003cText :style=\"styles.text\"\u003eVuvas\u003c/Text\u003e\n  \u003c/View\u003e\n\u003c/template\u003e\n\u003cscript\u003e\nexport default {\n  setup() {\n    return {\n      styles: {\n        container: {\n          justifyContent: 'center',\n          flex: 1,\n          backgroundColor: '#41b883',\n        },\n        text: {\n          fontSize: 100,\n          fontWeight: 800,\n          color: '#fff',\n          height: 100,\n          fontFamily: 'zapfino',\n          textAlign: 'center'\n        }\n      },\n    };\n  },\n};\n\u003c/script\u003e\n```\n\n效果：\n\n![](./assets/Text.png)\n\n### Image\n\n基本的图像标签，通过 src 属性链接图片地址，使用这个可以显示图片，类似 dom 的 img 标签，例子：\n\n代码：\n\n\u003e 在 [code sandbox](https://codesandbox.io/s/image-component-dl41z) 中打开\n\n```html\n\u003ctemplate\u003e\n  \u003cView :style=\"styles.container\"\u003e\n    \u003cImage src=\"./src/vue.png\" :style=\"styles.image\" /\u003e\n  \u003c/View\u003e\n\u003c/template\u003e\n\u003cscript\u003e\nexport default {\n  setup() {\n    return {\n      styles: {\n        container: {\n          justifyContent: 'center',\n          flex: 1,\n          backgroundColor: '#fff',\n          alignItems: 'center'\n        },\n        image: {\n          height: 200,\n          width: 200,\n        }\n      },\n    };\n  },\n};\n\u003c/script\u003e\n```\n\n效果：\n\n![](./assets/Image.png)\n\n### Touchable\n\n可触发 touch 事件的组件，使用这个组件可以添加 touchStart、touchMove、touchEnd、touchCancel 事件，例如实现一个 Button：\n\n代码：\n\n\u003e 在 [code sandbox](https://codesandbox.io/s/touchable-component-mz140) 中打开\n\n```html\n\u003ctemplate\u003e\n  \u003cView :style=\"styles.container\"\u003e\n    \u003cView\u003e\n      \u003cText :style=\"styles.text\"\u003e{{ count }}\u003c/Text\u003e\n      \u003cTouchable :onPress=\"inc\"\u003e\n        \u003cView :style=\"styles.content\"\u003e\n          \u003cText :style=\"styles.button\"\u003eAdd\u003c/Text\u003e\n        \u003c/View\u003e\n      \u003c/Touchable\u003e\n    \u003c/View\u003e\n  \u003c/View\u003e\n\u003c/template\u003e\n\u003cscript\u003e\nimport { ref } from \"vue\";\nexport default {\n  setup() {\n    const count = ref(0);\n    const inc = () =\u003e {\n      count.value++;\n    };\n    return {\n      count,\n      inc,\n      styles: {\n        container: {\n          justifyContent: \"center\",\n          flex: 1,\n          backgroundColor: \"#41b883\",\n          alignItems: \"center\",\n        },\n        text: {\n          fontSize: 100,\n          fontWeight: 800,\n          color: \"#fff\",\n          height: 100,\n          fontFamily: \"zapfino\",\n          textAlign: \"center\",\n        },\n        content: {\n          backgroundColor: \"#36495d\",\n          height: 80,\n          width: 160,\n          justifyContent: \"center\",\n          alignItems: \"center\",\n          borderRadius: 16\n        },\n        button: {\n          color: '#fff',\n          fontSize: 40,\n          height: 80,\n          width: 200,\n          textAlign: 'center',\n        },\n      },\n    };\n  },\n};\n\u003c/script\u003e\n```\n\n效果：\n\n![](./assets/Touchable.gif)\n\n### ScrollView\n\n可滚动的组件，通过这个组件可以包裹其他组件来实现滚动效果：\n\n代码：\n\n\u003e 在 [code sandbox](https://codesandbox.io/s/scrollview-component-do7kp) 中打开\n\n```html\n\u003ctemplate\u003e\n  \u003cView :style=\"styles.container\"\u003e\n    \u003cScrollView horizontal :style=\"styles.scroll\"\u003e\n      \u003cView\n        :style=\"styles.box\"\n        v-for=\"(num, index) in numbers\"\n        :key=\"index\"\n      \u003e\n        \u003cText :style=\"styles.text\"\u003e{{index + 1}}\u003c/Text\u003e\n      \u003c/View\u003e\n    \u003c/ScrollView\u003e\n  \u003c/View\u003e\n\u003c/template\u003e\n\u003cscript\u003e\nconst numbers = [];\nfor (let i = 0; i \u003c 20; i++) {\n  numbers.push(i);\n}\nexport default {\n  setup() {\n    return {\n      numbers,\n      styles: {\n        container: {\n          justifyContent: \"center\",\n          flex: 1,\n          backgroundColor: \"#41b883\",\n        },\n        scroll: {\n          height: 55,\n        },\n        box: {\n          width: 100,\n          height: 100,\n          justifyContent: \"center\",\n          backgroundColor: \"#333\",\n          marginRight: 10,\n        },\n        text: {\n          color: \"#fff\",\n          fontWeight: \"600\",\n          fontSize: 24,\n          textAlign: \"center\",\n        },\n      },\n    };\n  },\n};\n\u003c/script\u003e\n```\n\n效果：\n\n![](./assets/Scrollview.gif)\n\n## 致谢\n\nvuvas 是 [revas](https://github.com/pinqy520/revas) 的 vue 实现版本，感谢 [@pinqy520](https://github.com/pinqy520) 🙏🙏🙏","funding_links":[],"categories":["Web","TypeScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhuruji%2Fvuvas","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhuruji%2Fvuvas","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhuruji%2Fvuvas/lists"}