{"id":19560003,"url":"https://github.com/plotdb/wrap-svg-text","last_synced_at":"2025-04-26T23:32:50.765Z","repository":{"id":57399709,"uuid":"311542189","full_name":"plotdb/wrap-svg-text","owner":"plotdb","description":"Generate multiline svg texts directly through a text string and a set of css style. Example:","archived":false,"fork":false,"pushed_at":"2022-01-21T15:00:12.000Z","size":2113,"stargazers_count":6,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-20T13:18:55.977Z","etag":null,"topics":["bounding-boxes","format","layout","svg","text"],"latest_commit_sha":null,"homepage":"http://plotdb.github.io/wrap-svg-text/","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/plotdb.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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-11-10T04:11:33.000Z","updated_at":"2023-03-21T19:00:52.000Z","dependencies_parsed_at":"2022-09-26T17:01:15.068Z","dependency_job_id":null,"html_url":"https://github.com/plotdb/wrap-svg-text","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/plotdb%2Fwrap-svg-text","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/plotdb%2Fwrap-svg-text/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/plotdb%2Fwrap-svg-text/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/plotdb%2Fwrap-svg-text/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/plotdb","download_url":"https://codeload.github.com/plotdb/wrap-svg-text/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251068040,"owners_count":21531475,"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":["bounding-boxes","format","layout","svg","text"],"created_at":"2024-11-11T05:05:30.676Z","updated_at":"2025-04-26T23:32:47.523Z","avatar_url":"https://github.com/plotdb.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# wrap-svg-text\n\nGenerate multiline svg texts directly through a text string and a set of css style. Example:\n\n    wrapSvgText({\n        text: \"Thank you, Chairman Rayon To Go(聽不懂他的發音人名), Chairman 還有我們President, 還有各位美僑商, 美國商會所有的好朋友, 還有各位新聞界的女士先生.\"\n        style: {\n            fontSize: \"32px\",\n            width: \"300px\",\n            whiteSpace: \"pre-line\"\n        }\n    });\n\n## Usage\n\ninstall:\n\n    npm install --save wrap-svg-text\n\ninclude:\n\n    \u003cscript src=\"path-to-wrap-svg-text.js\"\u003e\u003c/script\u003e\n\n\ncall:\n\n    ret = wrapSvgText({text: '...', style: { ... }});\n    myGroup.textContent = \"\"; /* clear myGroup content */\n    myGroup.appendChild(ret)\n\n\nwith prepared div `node` so we don't have to mimic its style ( content inside ):\n\n    ret = wrapSvgText({node: node});\n    myGroup.textContent = \"\"; /* clear myGroup content */\n    myGroup.appendChild(ret)\n\n\n## Options\n\n - `text`: string. text to render.\n - `style`: object containing styles for rendering above text. optional.\n - `node`: when provided, use this node to layout content.\n    - content may be altered due to algorithm in `wrap-svg-text`. check `useRange` for more detail.\n    - `node` should contain plain text only. \n    - `text` can be omitted if there are contents already in `node`\n    - `style` will be ignored when node is provided.\n - `useRange`: if true, use `document.range` for position calculation. default false. see below.\n\n\n### useRange\n\n`wrap-svg-text` by default get characters' position by wrapping them in span. however, this may touch node's content if user provide `node` as a paramter when calling `wrap-svg-text`. This may causing re-layout and change the position of elements, leading to incorrect result.\n\nIn this case, user can alternatively enable `useRange` and let `wrap-svg-text` calculate the position with `range.getBoundingClientRect`. However, this is 2 times slower so only suggested using for short text.\n\n\n\n## Mechanism\n\nwrap-svg-text simply calculates layouts of texts with the help of browser layout engine. Input texts with specified style are added directly in a hidden div, with every single glyph wrapped in span. Then, span are joined based on their y coordinate, and added back as a `\u003ctext\u003e` tag in a `\u003cg\u003e` tag, which is returned from `wrapSvgText` function call.\n\n\n## Note\n\nLayout is calculated directly based on CSS and DOM, thus it's important to make sure that when running wrap-svg-text, CSS and DOM are ready and correctly rendered, otherwise wrap-svg-text may give incorrect result due to style updating.\n\n\n## Credit\n\nSample text from '[HolyMosquito](https://www.facebook.com/HolyMosquito/posts/2428227354121577)'s transcription of [Han](https://zh.wikipedia.org/zh-tw/%E9%9F%93%E5%9C%8B%E7%91%9C)'s speech in AmCham Taipei, a good example of English / Chinese mixed context.\n\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fplotdb%2Fwrap-svg-text","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fplotdb%2Fwrap-svg-text","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fplotdb%2Fwrap-svg-text/lists"}