{"id":27168044,"url":"https://github.com/alexayan/html-canvas","last_synced_at":"2025-06-11T05:33:10.529Z","repository":{"id":57267317,"uuid":"232038955","full_name":"alexayan/html-canvas","owner":"alexayan","description":"基于 HTML 和 CSS 实现 Canvas 绘图 (draw canvas with html \u0026 css)","archived":false,"fork":false,"pushed_at":"2020-01-09T01:38:27.000Z","size":346,"stargazers_count":17,"open_issues_count":0,"forks_count":6,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-11T01:22:01.214Z","etag":null,"topics":["canvas","html2canvas"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/alexayan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-01-06T06:31:36.000Z","updated_at":"2025-05-16T02:45:51.000Z","dependencies_parsed_at":"2022-09-02T05:40:51.491Z","dependency_job_id":null,"html_url":"https://github.com/alexayan/html-canvas","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/alexayan%2Fhtml-canvas","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexayan%2Fhtml-canvas/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexayan%2Fhtml-canvas/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexayan%2Fhtml-canvas/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alexayan","download_url":"https://codeload.github.com/alexayan/html-canvas/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexayan%2Fhtml-canvas/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259207768,"owners_count":22821759,"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":["canvas","html2canvas"],"created_at":"2025-04-09T05:20:17.362Z","updated_at":"2025-06-11T05:33:10.508Z","avatar_url":"https://github.com/alexayan.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"## 简介\n\n基于 HTML 和 CSS 实现 Canvas 绘图。\n\n## 原理\n\n构建虚拟DOM 树，依据 CSS 规范计算样式，使用 CSS 盒模型对 DOM 进行布局，计算出所有元素的位置。最后将 DOM 树通过 Canvas Api 进行绘制。\n\n## 小程序开发工具内运行 demo\n\n[小程序代码片段：https://developers.weixin.qq.com/s/9zFHKdmh7De2](https://developers.weixin.qq.com/s/9zFHKdmh7De2)\n\n``` bash\ngit clone https://github.com/alexayan/html-canvas.git\nnpm i\nnpm run watch\n```\n\n## 小程序内使用\n\n[example](./tools/demo/pages/index/index.js)\n\n## Node 环境中使用\n\n[example](./example/node/index.js)\n\n`html-canvas` 默认环境为小程序环境，其他环境中使用需要添加图片加载函数 `loadImage` 到 Node 类上, 返回的图片对象 `image` 会通过 `ctx.drawImage(image)` 画到 canvas 上\n\n```\nNode.prototype.loadImage = function (src) {\n  return new Promise((resolve, reject) =\u003e {\n    const img = new Image()\n    img.onload = () =\u003e {\n      resolve(img);\n    }\n    img.onerror = err =\u003e {\n      reject(err);\n    }\n    img.src = src;\n  })\n}\n```\n\n## 待支持的 CSS 属性\n\n- [ ] flex\n- [ ] flex-basis\n- [ ] flex-direction\n- [ ] flex-flow\n- [ ] flex-grow\n- [ ] flex-shrink\n- [ ] flex-wrap\n\n## 已支持的 CSS 属性\n\nmargin，margin-left，margin-top，margin-right，margin-bottom，padding，padding-left，padding-top，padding-right，padding-bottom，width，height，border，border-left，border-top，border-right，border-bottom，border-width，border-style，border-color，border-left-style，border-left-color，border-left-width，border-top-style，border-top-color，border-top-width，border-right-style，border-right-color，border-right-width，border-bottom-style，border-bottom-color，border-bottom-width，color，display，background-color，border-radius，border-top-left-radius，border-top-right-radius，border-bottom-left-radius，border-bottom-right-radius，box-sizing，font，font-style，font-variant，font-weight，font-stretch，font-size，line-height，font-family，text-align，position，overflow，overflow-x，overflow-y，top，left，right，bottom，z-index\n\n## style html\n\n一个工具库，将 style 样式文件应用到 html 行内样式。\n\n[html-style](https://github.com/alexayan/html-style)\n[example](./tools/demo/pages/index/index.js)\n\n## demo\n\n[canvas-draw.html](./canvas-draw.html)\n\n![canvas-draw](canvas-draw.png)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexayan%2Fhtml-canvas","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falexayan%2Fhtml-canvas","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexayan%2Fhtml-canvas/lists"}