MCPcopy Create free account
hub / github.com/bugy/script-server / getTextWidth

Function getTextWidth

web-src/src/common/utils/common.js:537–545  ·  view source on GitHub ↗
(text, element)

Source from the content-addressed store, hash-verified

535}
536
537export function getTextWidth(text, element) {
538 // re-use canvas object for better performance
539 const canvas = getTextWidth.canvas || (getTextWidth.canvas = document.createElement('canvas'));
540
541 const context = canvas.getContext('2d');
542 context.font = window.getComputedStyle(element, null).getPropertyValue('font');
543 const metrics = context.measureText(text);
544 return metrics.width;
545}
546
547export function toMap(elements, keyExtractor, valueExtractor) {
548 return elements.reduce(

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected