{"id":20542196,"url":"https://github.com/weivea/qr-code-wasm","last_synced_at":"2025-09-13T01:13:50.635Z","repository":{"id":83302635,"uuid":"341769427","full_name":"weivea/qr-code-wasm","owner":"weivea","description":"基于wasm 的二维码数据生成生成","archived":false,"fork":false,"pushed_at":"2021-02-24T03:42:21.000Z","size":105,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-16T15:22:09.444Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/weivea.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE_APACHE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-02-24T03:39:06.000Z","updated_at":"2021-02-24T03:42:24.000Z","dependencies_parsed_at":null,"dependency_job_id":"810b653c-173f-4b0d-9d26-8aca7d5ead68","html_url":"https://github.com/weivea/qr-code-wasm","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/weivea%2Fqr-code-wasm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/weivea%2Fqr-code-wasm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/weivea%2Fqr-code-wasm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/weivea%2Fqr-code-wasm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/weivea","download_url":"https://codeload.github.com/weivea/qr-code-wasm/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242147059,"owners_count":20079484,"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-11-16T01:29:45.556Z","updated_at":"2025-03-06T04:26:30.175Z","avatar_url":"https://github.com/weivea.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# qr-code-wasm\n\n基于wasm 的二维码数据生成生成\n\n![pic](./pic.png)\n\n## install\n```\nnpm i @weivea/qr-code-wasm\n```\n\n## usage\n\nqr-code-wasm 以esm 的方式提供，       \n\n下边代码需要webpack打包，webpack目前已经支持 import wasm\n\n可参考： [example](./www)\n\n```javascript\nimport { QR, Cell } from \"qr-code-wasm\";\nimport { memory } from \"qr-code-wasm/qr_code_wasm_bg.wasm\";\n\nlet qr = QR.new(\"Hello\");\nlet width = qr.width();\nconst cellsPtr = qr.cells(); // \u003c universe's cells\nconst cells = new Uint8Array(memory.buffer, cellsPtr, width * width);\n\nlet outStr = \"\";\nfor (let row = 0; row \u003c width; row++) {\n  for (let col = 0; col \u003c width; col++) {\n    let index = row * width + col;\n    let cell = cells[index] == Cell.Alive ? \"◼\" : \" \";\n    outStr += cell;\n  }\n  outStr += \"\\n\";\n}\n\nconsole.log(outStr);\ndocument.querySelector(\"#qr\").innerText = outStr;\n\n// canvas\nconst CELL_SIZE = 5; // px\nconst DEAD_COLOR = \"#FFFFFF\";\nconst ALIVE_COLOR = \"#000000\";\nconst canvas = document.getElementById(\"qr-canvas\");\ncanvas.height = CELL_SIZE * width;\ncanvas.width = CELL_SIZE * width;\n\nconst ctx = canvas.getContext(\"2d\");\n\nctx.beginPath();\n\nfor (let row = 0; row \u003c width; row++) {\n  for (let col = 0; col \u003c width; col++) {\n    let idx = row * width + col;\n    ctx.fillStyle = cells[idx] === Cell.Dead ? DEAD_COLOR : ALIVE_COLOR;\n\n    ctx.fillRect(col * CELL_SIZE, row * CELL_SIZE, CELL_SIZE, CELL_SIZE);\n  }\n}\n\nctx.stroke();\n\n\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fweivea%2Fqr-code-wasm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fweivea%2Fqr-code-wasm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fweivea%2Fqr-code-wasm/lists"}