<canvas id="canvas" width="500" height="300"></canvas>
<div
id="textBox"
contenteditable="true"
style="
font-weight: bold;
font-size: 20px;
font-family: Helvetica;
color: rgb(153, 0, 56);
"
>
Este es un <em>texto</em> <span>de </span><span style="text-decoration-line: underline;background: rgb(255, 0, 0);">prueba
ajapagaqaya,a</span><span>, </span><span style="background: rgb(255, 243, 153);">con el cual la finalidad es llenar o recrear <em>texto</em> para ser probado o mostrado en <strong>sitios, paginas, documentos</strong> de muestra</span>, una vez explicado eso solo queda redactar sobre nada en absoluto manteniendo un <em>texto</em> enfocado en si mismo durante lo que se van recopilando las palabras u oraciones, siendo posible el incrementar la cantidad de <em>texto</em> disponible para ser mostrado.
</div>
TypeScript
console.clear();
// function fromEntries(xs: any[]) {
// return xs.reduce((acc, [key, value]) => ({ ...acc, [key]: value }), {});
// }
//
// function entries(xs: any) {
// let ownProps = Object.keys(xs);
// let i = ownProps.length;
// let resArray = new Array(i);
// while (i--) {
// resArray[i] = [ownProps[i], xs[ownProps[i]]];
// }
//
// return resArray;
// }
//
// function getStyle(attrs: any) {
// let obj = fromEntries(entries(attrs.style).filter(([k, v]) => v !== ""));
// return obj;
// }
interface Style {
fontSize?: number;
fontStyle?: string;
background?: string;
fontColor?: string;
fontWeight?: string;
fontFamily?: string;
textDecorationLine?: string;
}
function getStyle(attrs: any) {
let obj: Style = {};
if (attrs.style.fontSize !== "")
obj.fontSize = +attrs.style.fontSize.replace(/[px]/g, "");
if (attrs.style.fontStyle !== "") obj.fontStyle = attrs.style.fontStyle;
if (attrs.style.backgroundColor !== "")
obj.background = attrs.style.backgroundColor;
if (attrs.style.color !== "") obj.fontColor = attrs.style.color;
if (attrs.style.fontWeight !== "") obj.fontWeight = attrs.style.fontWeight;
if (attrs.style.fontFamily !== "") obj.fontFamily = attrs.style.fontFamily;
if (attrs.style.textDecorationLine !== "")
obj.textDecorationLine = attrs.style.textDecorationLine;
// fromEntries(entries(attrs.style).filter(([k, v]) => v !== ""));
return obj;
}
class Box {
x: number = 0;
y: number = 0;
width: number = 0;
height: number = 0;
}
class StyleGroup {
value: string = "";
box: Box = new Box();
measure?: TextMetrics;
fontSize = 12;
fontStyle = "";
background = "none";
fontColor = "#000000";
fontWeight = "normal";
fontFamily = "Verdana";
textDecorationLine = null;
}
function getAllChildStyle(
element: any,
styleGroups: StyleGroup[] = [],
style: any = []
): StyleGroup[] {
if (element.hasChildNodes()) {
let childLength = element.childNodes.length;
style =...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.