{"id":21368192,"url":"https://github.com/chrisvilches/portraycanvas","last_synced_at":"2025-12-12T03:38:40.057Z","repository":{"id":57327600,"uuid":"103356882","full_name":"ChrisVilches/PortrayCanvas","owner":"ChrisVilches","description":"Parameterizable canvas library that allows you to draw on it, and get the drawn points.","archived":false,"fork":false,"pushed_at":"2021-09-18T17:08:30.000Z","size":131,"stargazers_count":11,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-11-10T20:46:11.539Z","etag":null,"topics":["bower","bower-components","canvas","drawing","front-end","frontend","handwriting","handwriting-recognition","html5","javascript","user-interface"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/portraycanvas","language":"JavaScript","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/ChrisVilches.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":"2017-09-13T05:24:39.000Z","updated_at":"2024-11-09T04:15:11.000Z","dependencies_parsed_at":"2022-08-31T00:20:52.228Z","dependency_job_id":null,"html_url":"https://github.com/ChrisVilches/PortrayCanvas","commit_stats":null,"previous_names":["felovilches/drawcanvas"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ChrisVilches%2FPortrayCanvas","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ChrisVilches%2FPortrayCanvas/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ChrisVilches%2FPortrayCanvas/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ChrisVilches%2FPortrayCanvas/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ChrisVilches","download_url":"https://codeload.github.com/ChrisVilches/PortrayCanvas/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225858249,"owners_count":17535369,"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":["bower","bower-components","canvas","drawing","front-end","frontend","handwriting","handwriting-recognition","html5","javascript","user-interface"],"created_at":"2024-11-22T07:23:11.881Z","updated_at":"2025-12-12T03:38:39.849Z","avatar_url":"https://github.com/ChrisVilches.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PortrayCanvas\n\nA library that allows the user to draw on a canvas, and extract the drawn points. Useful for getting handwritten user input.\n\n[Live demo](http://cloud.chrisvilches.com/live_demos/PortrayCanvas/)\n\n## Download\n\n```bash\nnpm install portraycanvas --save\n```\n\nor\n\n```bash\nyarn add portraycanvas\n```\n\n## Usage\n\nYour html:\n\n```html\n\u003ccanvas id=\"canvas-main\" style=\"width: 100%; border: 1px solid black;\" height=\"200\"\u003e\u003c/canvas\u003e\n```\n\nYour Javascript:\n\n```js\n\nimport PortrayCanvas from 'portraycanvas';\n\nvar canvas = new PortrayCanvas(document.getElementById(\"canvas-main\"), {\n\n  // All these attributes are optional.\n\n  // Stroke size\n  lineWidth: 2,\n\n  // Set the color\n  color: '#00ff00',\n\n  // Period in which it collects points. The lower, the more points it collects.\n  // If it's too high, you might not get curved lines accurately.\n  period: 5,\n\n  // Some events...\n\n  onLineFinish: function(c){\n    console.log(\"A line was finished, here are all the lines:\");\n    console.log(c.getLines());\n  },\n\n  onClear: function(){\n    console.log(\"The canvas was cleared\");\n  },\n\n  onUndo: function(line){\n    console.log(\"This line was deleted:\");\n    console.log(line);\n  }\n});\n```\n\nYou can programmatically call these methods:\n\n```js\n\ncanvas.getLines(); // Get all lines\n\ncanvas.clear(); // Clear the canvas\n\ncanvas.undo(); // Remove last line you drew\n\ncanvas.setColor('#ff0000'); // Change the stroke color\n\ncanvas.revertDefaultColor(); // If you had changed the color, go back to the default one.\n```\n\n## Issues\n\nIt seems it's necessary that the canvas element defines `width` and `height`.\n\n```html\n\u003ccanvas id=\"main-canvas\" width=\"500\" height=\"700\"\u003e\n```\n\nThis issue is being investigated. It might still work without them in some situations, but make sure the canvas works correctly even after resizing the window.\n\n## Styling\n\nYou can initialize the canvas using the `color` option (as explained above), but you can use a `css` class in order to keep it consistent with the rest of your application:\n\n```css\n.green-canvas {\n  /* If you include the 'color' property, it'll be\n  used as the stroke color */\n  color: #006600;\n  background-color: #fafafa;\n  border: 3px solid black;\n  cursor: crosshair;\n}\n```\n\nAnd then in your HTML:\n\n```html\n\u003ccanvas id=\"canvas-main\" class=\"green-canvas\" width=\"800\" height=\"500\"\u003e\u003c/canvas\u003e\n```\n\n## Recommended CSS\n\nYou can make the canvas unselectable by applying the following CSS:\n\n```css\n.my-canvas{\n  -webkit-user-select: none;  /* Chrome all / Safari all */\n  -moz-user-select: none;     /* Firefox all */\n  -ms-user-select: none;      /* IE 10+ */\n  user-select: none;          /* Likely future */      \n}\n```\n\nYou can make the canvas unscrollable, which is useful for mobile pages, so that it doesn't unintentionally scroll while touching it, by applying the following CSS to your canvas.\n\n```css\n.my-canvas{\n  touch-action: none;\n}\n```\n\nIn future versions, these CSS rules will be applied automatically by the library.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchrisvilches%2Fportraycanvas","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchrisvilches%2Fportraycanvas","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchrisvilches%2Fportraycanvas/lists"}