MCPcopy Create free account
hub / github.com/adobe/react-spectrum / getTextWidth

Function getTextWidth

packages/dev/s2-docs/src/textWidth.ts:87–104  ·  view source on GitHub ↗
(s: string)

Source from the content-addressed store, hash-verified

85
86// Gets the width of a string of text. Multiply by font size to get pixel width.
87export function getTextWidth(s: string) {
88 let longestWord = '';
89 for (let segment of s.split(/\s+/)) {
90 if (segment.length > longestWord.length) {
91 longestWord = segment;
92 }
93 }
94
95 let width = 0;
96 for (let c of longestWord) {
97 let w = letters[c];
98 if (w != null) {
99 width += w;
100 }
101 }
102
103 return width;
104}

Callers 1

H1Function · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected