text-to-canvas 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
5
5
  The format is inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## v1.1.0
9
+
10
+ ### Added
11
+
12
+ - New `overflow?: boolean` config parameter for `drawText()` API: True (default) to allow overflow; false to clip text to box.
13
+
8
14
  ## v1.0.0
9
15
 
10
16
  - First official release 🎉
@@ -475,6 +475,12 @@ const drawText = (ctx, text, config) => {
475
475
  fontVariant: config.fontVariant,
476
476
  fontWeight: config.fontWeight
477
477
  });
478
+ const {
479
+ width: boxWidth,
480
+ height: boxHeight,
481
+ x: boxX = 0,
482
+ y: boxY = 0
483
+ } = config;
478
484
  const {
479
485
  lines: richLines,
480
486
  height: totalHeight,
@@ -485,8 +491,8 @@ const drawText = (ctx, text, config) => {
485
491
  words: Array.isArray(text) ? text : textToWords(text),
486
492
  inferWhitespace: Array.isArray(text) ? config.inferWhitespace === void 0 || config.inferWhitespace : void 0,
487
493
  // ignore since `text` is a string; we assume it already has all the whitespace it needs
488
- x: config.x || 0,
489
- y: config.y || 0,
494
+ x: boxX,
495
+ y: boxY,
490
496
  width: config.width,
491
497
  height: config.height,
492
498
  align: config.align,
@@ -499,6 +505,11 @@ const drawText = (ctx, text, config) => {
499
505
  ctx.textBaseline = textBaseline;
500
506
  ctx.font = getTextStyle(baseFormat);
501
507
  ctx.fillStyle = baseFormat.fontColor || DEFAULT_FONT_COLOR;
508
+ if (config.overflow === false) {
509
+ ctx.beginPath();
510
+ ctx.rect(boxX, boxY, boxWidth, boxHeight);
511
+ ctx.clip();
512
+ }
502
513
  richLines.forEach((line) => {
503
514
  line.forEach((pw) => {
504
515
  if (!pw.isWhitespace) {
@@ -517,39 +528,38 @@ const drawText = (ctx, text, config) => {
517
528
  });
518
529
  });
519
530
  if (config.debug) {
520
- const { width, height, x = 0, y = 0 } = config;
521
- const xEnd = x + width;
522
- const yEnd = y + height;
531
+ const xEnd = boxX + boxWidth;
532
+ const yEnd = boxY + boxHeight;
523
533
  let textAnchor;
524
534
  if (config.align === "right") {
525
535
  textAnchor = xEnd;
526
536
  } else if (config.align === "left") {
527
- textAnchor = x;
537
+ textAnchor = boxX;
528
538
  } else {
529
- textAnchor = x + width / 2;
539
+ textAnchor = boxX + boxWidth / 2;
530
540
  }
531
- let debugY = y;
541
+ let debugY = boxY;
532
542
  if (config.vAlign === "bottom") {
533
543
  debugY = yEnd;
534
544
  } else if (config.vAlign === "middle") {
535
- debugY = y + height / 2;
545
+ debugY = boxY + boxHeight / 2;
536
546
  }
537
547
  const debugColor = "#0C8CE9";
538
548
  ctx.lineWidth = 1;
539
549
  ctx.strokeStyle = debugColor;
540
- ctx.strokeRect(x, y, width, height);
550
+ ctx.strokeRect(boxX, boxY, boxWidth, boxHeight);
541
551
  ctx.lineWidth = 1;
542
552
  if (!config.align || config.align === "center") {
543
553
  ctx.strokeStyle = debugColor;
544
554
  ctx.beginPath();
545
- ctx.moveTo(textAnchor, y);
555
+ ctx.moveTo(textAnchor, boxY);
546
556
  ctx.lineTo(textAnchor, yEnd);
547
557
  ctx.stroke();
548
558
  }
549
559
  if (!config.vAlign || config.vAlign === "middle") {
550
560
  ctx.strokeStyle = debugColor;
551
561
  ctx.beginPath();
552
- ctx.moveTo(x, debugY);
562
+ ctx.moveTo(boxX, debugY);
553
563
  ctx.lineTo(xEnd, debugY);
554
564
  ctx.stroke();
555
565
  }
@@ -1,8 +1,8 @@
1
- const H = "Arial";
1
+ const D = "Arial";
2
2
  const $ = "black", _ = (t, n) => Object.assign(
3
3
  {},
4
4
  {
5
- fontFamily: H,
5
+ fontFamily: D,
6
6
  fontSize: 14,
7
7
  fontWeight: "400",
8
8
  fontStyle: "",
@@ -15,49 +15,49 @@ const $ = "black", _ = (t, n) => Object.assign(
15
15
  fontFamily: t,
16
16
  fontSize: n,
17
17
  fontStyle: e,
18
- fontVariant: i,
19
- fontWeight: s
20
- }) => `${e || ""} ${i || ""} ${s || ""} ${n ?? 14}px ${t || H}`.trim(), T = (t) => !!t.match(/^\s+$/), M = (t) => t.filter((n) => !T(n.text)), V = (t) => {
18
+ fontVariant: s,
19
+ fontWeight: i
20
+ }) => `${e || ""} ${s || ""} ${i || ""} ${n ?? 14}px ${t || D}`.trim(), T = (t) => !!t.match(/^\s+$/), M = (t) => t.filter((n) => !T(n.text)), V = (t) => {
21
21
  const n = { ...t };
22
22
  return t.format && (n.format = { ...t.format }), n;
23
- }, k = (t, n) => {
23
+ }, H = (t, n) => {
24
24
  if (t.length <= 1 || n.length < 1)
25
25
  return [...t];
26
26
  const e = [];
27
- return t.forEach((i, s) => {
28
- e.push(i), s < t.length - 1 && n.forEach((r) => e.push(V(r)));
27
+ return t.forEach((s, i) => {
28
+ e.push(s), i < t.length - 1 && n.forEach((r) => e.push(V(r)));
29
29
  }), e;
30
30
  }, Z = ({
31
31
  line: t,
32
32
  spaceWidth: n,
33
33
  spaceChar: e,
34
- boxWidth: i
34
+ boxWidth: s
35
35
  }) => {
36
- const s = M(t);
37
- if (s.length <= 1)
36
+ const i = M(t);
37
+ if (i.length <= 1)
38
38
  return t.concat();
39
- const r = s.reduce(
40
- (l, o) => {
41
- var m;
42
- return l + (((m = o.metrics) == null ? void 0 : m.width) ?? 0);
39
+ const r = i.reduce(
40
+ (a, u) => {
41
+ var d;
42
+ return a + (((d = u.metrics) == null ? void 0 : d.width) ?? 0);
43
43
  },
44
44
  0
45
- ), a = (i - r) / n;
46
- if (s.length > 2) {
47
- const l = Math.ceil(a / (s.length - 1)), o = Array.from({ length: l }, () => ({
45
+ ), l = (s - r) / n;
46
+ if (i.length > 2) {
47
+ const a = Math.ceil(l / (i.length - 1)), u = Array.from({ length: a }, () => ({
48
48
  text: e
49
- })), m = s.slice(0, s.length - 1), p = k(m, o), u = o.slice(
49
+ })), d = i.slice(0, i.length - 1), y = H(d, u), c = u.slice(
50
50
  0,
51
- Math.floor(a) - (m.length - 1) * o.length
52
- ), d = s[s.length - 1];
53
- return [...p, ...u, d];
51
+ Math.floor(l) - (d.length - 1) * u.length
52
+ ), h = i[i.length - 1];
53
+ return [...y, ...c, h];
54
54
  }
55
- const h = Array.from(
56
- { length: Math.floor(a) },
55
+ const o = Array.from(
56
+ { length: Math.floor(l) },
57
57
  () => ({ text: e })
58
58
  );
59
- return k(s, h);
60
- }, v = (t, n = "both") => {
59
+ return H(i, o);
60
+ }, x = (t, n = "both") => {
61
61
  let e = 0;
62
62
  if (n === "left" || n === "both") {
63
63
  for (; e < t.length && T(t[e].text); e++)
@@ -69,11 +69,11 @@ const $ = "black", _ = (t, n) => Object.assign(
69
69
  trimmedLine: []
70
70
  };
71
71
  }
72
- let i = t.length;
72
+ let s = t.length;
73
73
  if (n === "right" || n === "both") {
74
- for (i--; i >= 0 && T(t[i].text); i--)
74
+ for (s--; s >= 0 && T(t[s].text); s--)
75
75
  ;
76
- if (i++, i <= 0)
76
+ if (s++, s <= 0)
77
77
  return {
78
78
  trimmedLeft: [],
79
79
  trimmedRight: t.concat(),
@@ -82,61 +82,61 @@ const $ = "black", _ = (t, n) => Object.assign(
82
82
  }
83
83
  return {
84
84
  trimmedLeft: t.slice(0, e),
85
- trimmedRight: t.slice(i),
86
- trimmedLine: t.slice(e, i)
85
+ trimmedRight: t.slice(s),
86
+ trimmedLine: t.slice(e, s)
87
87
  };
88
- }, C = " ", Y = " ";
89
- let F;
90
- const I = (t) => `${t.text}${t.format ? JSON.stringify(t.format) : ""}`, q = (t, n = !0) => {
88
+ }, k = " ", Y = " ";
89
+ let v;
90
+ const I = (t) => `${t.text}${t.format ? JSON.stringify(t.format) : ""}`, X = (t, n = !0) => {
91
91
  const e = [[]];
92
- let i = !1;
93
- return t.forEach((s, r) => {
94
- var a, h, l;
95
- if (s.text.match(/^\n+$/)) {
96
- for (let o = 0; o < s.text.length; o++)
92
+ let s = !1;
93
+ return t.forEach((i, r) => {
94
+ var l, o, a;
95
+ if (i.text.match(/^\n+$/)) {
96
+ for (let u = 0; u < i.text.length; u++)
97
97
  e.push([]);
98
- i = !0;
98
+ s = !0;
99
99
  return;
100
100
  }
101
- if (T(s.text)) {
102
- (a = e.at(-1)) == null || a.push(s), i = !0;
101
+ if (T(i.text)) {
102
+ (l = e.at(-1)) == null || l.push(i), s = !0;
103
103
  return;
104
104
  }
105
- s.text !== "" && (n && !i && r > 0 && ((h = e.at(-1)) == null || h.push({ text: Y })), (l = e.at(-1)) == null || l.push(s), i = !1);
105
+ i.text !== "" && (n && !s && r > 0 && ((o = e.at(-1)) == null || o.push({ text: Y })), (a = e.at(-1)) == null || a.push(i), s = !1);
106
106
  }), e;
107
- }, G = ({
107
+ }, q = ({
108
108
  wrappedLines: t,
109
109
  wordMap: n,
110
110
  positioning: {
111
111
  width: e,
112
- height: i,
113
- x: s = 0,
112
+ height: s,
113
+ x: i = 0,
114
114
  y: r = 0,
115
- align: a,
116
- vAlign: h
115
+ align: l,
116
+ vAlign: o
117
117
  }
118
118
  }) => {
119
- const l = s + e, o = r + i, m = (f) => (
119
+ const a = i + e, u = r + s, d = (f) => (
120
120
  // NOTE: `metrics` must exist as every `word` MUST have been measured at this point
121
121
  f.metrics.fontBoundingBoxAscent + f.metrics.fontBoundingBoxDescent
122
- ), p = t.map(
123
- (f) => f.reduce((y, A) => Math.max(y, m(A)), 0)
124
- ), u = p.reduce((f, y) => f + y, 0);
125
- let d, c;
126
- return h === "top" ? (c = "top", d = r) : h === "bottom" ? (c = "bottom", d = o - u) : (c = "top", d = r + i / 2 - u / 2), {
127
- lines: t.map((f, y) => {
122
+ ), y = t.map(
123
+ (f) => f.reduce((p, A) => Math.max(p, d(A)), 0)
124
+ ), c = y.reduce((f, p) => f + p, 0);
125
+ let h, m;
126
+ return o === "top" ? (m = "top", h = r) : o === "bottom" ? (m = "bottom", h = u - c) : (m = "top", h = r + s / 2 - c / 2), {
127
+ lines: t.map((f, p) => {
128
128
  const A = f.reduce(
129
129
  // NOTE: `metrics` must exist as every `word` MUST have been measured at this point
130
- (W, x) => W + x.metrics.width,
130
+ (W, b) => W + b.metrics.width,
131
131
  0
132
- ), L = p[y];
132
+ ), L = y[p];
133
133
  let B;
134
- a === "right" ? B = l - A : a === "left" ? B = s : B = s + e / 2 - A / 2;
135
- let b = B;
134
+ l === "right" ? B = a - A : l === "left" ? B = i : B = i + e / 2 - A / 2;
135
+ let F = B;
136
136
  const z = f.map((W) => {
137
- const x = I(W), { format: J } = n.get(x), U = b, O = m(W);
137
+ const b = I(W), { format: J } = n.get(b), U = F, O = d(W);
138
138
  let E;
139
- return h === "top" ? E = d : h === "bottom" ? E = d + L : E = d + (L - O) / 2, b += W.metrics.width, {
139
+ return o === "top" ? E = h : o === "bottom" ? E = h + L : E = h + (L - O) / 2, F += W.metrics.width, {
140
140
  word: W,
141
141
  format: J,
142
142
  // undefined IF base formatting should be used when rendering (i.e. `word.format` is undefined)
@@ -147,13 +147,13 @@ const I = (t) => `${t.text}${t.format ? JSON.stringify(t.format) : ""}`, q = (t,
147
147
  isWhitespace: T(W.text)
148
148
  };
149
149
  });
150
- return d += L, z;
150
+ return h += L, z;
151
151
  }),
152
- textBaseline: c,
152
+ textBaseline: m,
153
153
  textAlign: "left",
154
154
  // always per current algorithm
155
155
  width: e,
156
- height: u
156
+ height: c
157
157
  };
158
158
  }, N = function(t, n) {
159
159
  if (t === "metrics" && n && typeof n == "object") {
@@ -165,50 +165,50 @@ const I = (t) => `${t.text}${t.format ? JSON.stringify(t.format) : ""}`, q = (t,
165
165
  };
166
166
  }
167
167
  return n;
168
- }, K = (t) => JSON.stringify(t, N), Q = (t) => JSON.stringify(t, N), D = ({
168
+ }, G = (t) => JSON.stringify(t, N), K = (t) => JSON.stringify(t, N), C = ({
169
169
  ctx: t,
170
170
  word: n,
171
171
  wordMap: e,
172
- baseTextFormat: i
172
+ baseTextFormat: s
173
173
  }) => {
174
- const s = I(n);
174
+ const i = I(n);
175
175
  if (n.metrics) {
176
- if (!e.has(s)) {
177
- let l;
178
- n.format && (l = _(n.format, i)), e.set(s, { metrics: n.metrics, format: l });
176
+ if (!e.has(i)) {
177
+ let a;
178
+ n.format && (a = _(n.format, s)), e.set(i, { metrics: n.metrics, format: a });
179
179
  }
180
180
  return n.metrics.width;
181
181
  }
182
- if (e.has(s)) {
183
- const { metrics: l } = e.get(s);
184
- return n.metrics = l, l.width;
182
+ if (e.has(i)) {
183
+ const { metrics: a } = e.get(i);
184
+ return n.metrics = a, a.width;
185
185
  }
186
- let r = !1, a;
187
- n.format && (t.save(), r = !0, a = _(n.format, i), t.font = S(a)), F || (r || (t.save(), r = !0), t.textBaseline = "bottom");
188
- const h = t.measureText(n.text);
189
- return typeof h.fontBoundingBoxAscent == "number" ? F = !0 : (F = !1, h.fontBoundingBoxAscent = h.actualBoundingBoxAscent, h.fontBoundingBoxDescent = 0), n.metrics = h, e.set(s, { metrics: h, format: a }), r && t.restore(), h.width;
190
- }, j = ({
186
+ let r = !1, l;
187
+ n.format && (t.save(), r = !0, l = _(n.format, s), t.font = S(l)), v || (r || (t.save(), r = !0), t.textBaseline = "bottom");
188
+ const o = t.measureText(n.text);
189
+ return typeof o.fontBoundingBoxAscent == "number" ? v = !0 : (v = !1, o.fontBoundingBoxAscent = o.actualBoundingBoxAscent, o.fontBoundingBoxDescent = 0), n.metrics = o, e.set(i, { metrics: o, format: l }), r && t.restore(), o.width;
190
+ }, P = ({
191
191
  ctx: t,
192
192
  words: n,
193
193
  justify: e,
194
- format: i,
195
- inferWhitespace: s = !0,
194
+ format: s,
195
+ inferWhitespace: i = !0,
196
196
  ...r
197
197
  // rest of params are related to positioning
198
198
  }) => {
199
- const a = /* @__PURE__ */ new Map(), h = _(i), { width: l } = r, o = (c, g = !1) => {
200
- let f = 0, y = 0;
201
- return c.every((A, L) => {
202
- const B = D({ ctx: t, word: A, wordMap: a, baseTextFormat: h });
203
- return !g && f + B > l ? (L === 0 && (y = 1, f = B), !1) : (y++, f += B, !0);
204
- }), { lineWidth: f, splitPoint: y };
199
+ const l = /* @__PURE__ */ new Map(), o = _(s), { width: a } = r, u = (m, g = !1) => {
200
+ let f = 0, p = 0;
201
+ return m.every((A, L) => {
202
+ const B = C({ ctx: t, word: A, wordMap: l, baseTextFormat: o });
203
+ return !g && f + B > a ? (L === 0 && (p = 1, f = B), !1) : (p++, f += B, !0);
204
+ }), { lineWidth: f, splitPoint: p };
205
205
  };
206
206
  t.save();
207
- const m = q(
208
- v(n).trimmedLine,
209
- s
207
+ const d = X(
208
+ x(n).trimmedLine,
209
+ i
210
210
  );
211
- if (m.length <= 0 || l <= 0 || r.height <= 0 || i && typeof i.fontSize == "number" && i.fontSize <= 0)
211
+ if (d.length <= 0 || a <= 0 || r.height <= 0 || s && typeof s.fontSize == "number" && s.fontSize <= 0)
212
212
  return {
213
213
  lines: [],
214
214
  textAlign: "center",
@@ -216,62 +216,62 @@ const I = (t) => `${t.text}${t.format ? JSON.stringify(t.format) : ""}`, q = (t,
216
216
  width: r.width,
217
217
  height: 0
218
218
  };
219
- t.font = S(h);
220
- const p = e ? D({ ctx: t, word: { text: C }, wordMap: a, baseTextFormat: h }) : 0, u = [];
221
- for (const c of m) {
222
- let { splitPoint: g } = o(c);
223
- if (g >= c.length)
224
- u.push(c);
219
+ t.font = S(o);
220
+ const y = e ? C({ ctx: t, word: { text: k }, wordMap: l, baseTextFormat: o }) : 0, c = [];
221
+ for (const m of d) {
222
+ let { splitPoint: g } = u(m);
223
+ if (g >= m.length)
224
+ c.push(m);
225
225
  else {
226
- let f = c.concat();
226
+ let f = m.concat();
227
227
  for (; g < f.length; ) {
228
- const y = v(
228
+ const p = x(
229
229
  f.slice(0, g),
230
230
  "right"
231
231
  ).trimmedLine;
232
- u.push(y), f = v(f.slice(g), "left").trimmedLine, { splitPoint: g } = o(f);
232
+ c.push(p), f = x(f.slice(g), "left").trimmedLine, { splitPoint: g } = u(f);
233
233
  }
234
- u.push(f);
234
+ c.push(f);
235
235
  }
236
236
  }
237
- e && u.length > 1 && u.forEach((c, g) => {
238
- if (g < u.length - 1) {
237
+ e && c.length > 1 && c.forEach((m, g) => {
238
+ if (g < c.length - 1) {
239
239
  const f = Z({
240
- line: c,
241
- spaceWidth: p,
242
- spaceChar: C,
243
- boxWidth: l
240
+ line: m,
241
+ spaceWidth: y,
242
+ spaceChar: k,
243
+ boxWidth: a
244
244
  });
245
- o(f, !0), u[g] = f;
245
+ u(f, !0), c[g] = f;
246
246
  }
247
247
  });
248
- const d = G({
249
- wrappedLines: u,
250
- wordMap: a,
248
+ const h = q({
249
+ wrappedLines: c,
250
+ wordMap: l,
251
251
  positioning: r
252
252
  });
253
- return t.restore(), d;
254
- }, P = (t) => {
253
+ return t.restore(), h;
254
+ }, j = (t) => {
255
255
  const n = [];
256
- let e, i = !1;
257
- return Array.from(t.trim()).forEach((s) => {
258
- const r = T(s);
259
- r && !i || !r && i ? (i = r, e && n.push(e), e = { text: s }) : (e || (e = { text: "" }), e.text += s);
256
+ let e, s = !1;
257
+ return Array.from(t.trim()).forEach((i) => {
258
+ const r = T(i);
259
+ r && !s || !r && s ? (s = r, e && n.push(e), e = { text: i }) : (e || (e = { text: "" }), e.text += i);
260
260
  }), e && n.push(e), n;
261
- }, X = ({ text: t, ...n }) => {
262
- const e = P(t);
263
- return j({
261
+ }, Q = ({ text: t, ...n }) => {
262
+ const e = j(t);
263
+ return P({
264
264
  ...n,
265
265
  words: e,
266
266
  inferWhitespace: !1
267
267
  }).lines.map(
268
- (s) => s.map(({ word: { text: r } }) => r).join("")
268
+ (i) => i.map(({ word: { text: r } }) => r).join("")
269
269
  );
270
270
  }, R = (t, n, e) => {
271
- const i = t.textBaseline, s = t.font;
271
+ const s = t.textBaseline, i = t.font;
272
272
  t.textBaseline = "bottom", e && (t.font = e);
273
273
  const { actualBoundingBoxAscent: r } = t.measureText(n);
274
- return t.textBaseline = i, e && (t.font = s), r;
274
+ return t.textBaseline = s, e && (t.font = i), r;
275
275
  }, w = ({
276
276
  ctx: t,
277
277
  word: n
@@ -280,45 +280,50 @@ const I = (t) => `${t.text}${t.format ? JSON.stringify(t.format) : ""}`, q = (t,
280
280
  text: n,
281
281
  style: e
282
282
  }) => R(t, n, e), et = (t, n, e) => {
283
- const i = _({
283
+ const s = _({
284
284
  fontFamily: e.fontFamily,
285
285
  fontSize: e.fontSize,
286
286
  fontStyle: e.fontStyle,
287
287
  fontVariant: e.fontVariant,
288
288
  fontWeight: e.fontWeight
289
289
  }), {
290
- lines: s,
290
+ width: i,
291
291
  height: r,
292
- textBaseline: a,
293
- textAlign: h
294
- } = j({
292
+ x: l = 0,
293
+ y: o = 0
294
+ } = e, {
295
+ lines: a,
296
+ height: u,
297
+ textBaseline: d,
298
+ textAlign: y
299
+ } = P({
295
300
  ctx: t,
296
- words: Array.isArray(n) ? n : P(n),
301
+ words: Array.isArray(n) ? n : j(n),
297
302
  inferWhitespace: Array.isArray(n) ? e.inferWhitespace === void 0 || e.inferWhitespace : void 0,
298
303
  // ignore since `text` is a string; we assume it already has all the whitespace it needs
299
- x: e.x || 0,
300
- y: e.y || 0,
304
+ x: l,
305
+ y: o,
301
306
  width: e.width,
302
307
  height: e.height,
303
308
  align: e.align,
304
309
  vAlign: e.vAlign,
305
310
  justify: e.justify,
306
- format: i
311
+ format: s
307
312
  });
308
- if (t.save(), t.textAlign = h, t.textBaseline = a, t.font = S(i), t.fillStyle = i.fontColor || $, s.forEach((l) => {
309
- l.forEach((o) => {
310
- o.isWhitespace || (o.format && (t.save(), t.font = S(o.format), o.format.fontColor && (t.fillStyle = o.format.fontColor)), t.fillText(o.word.text, o.x, o.y), o.format && t.restore());
313
+ if (t.save(), t.textAlign = y, t.textBaseline = d, t.font = S(s), t.fillStyle = s.fontColor || $, e.overflow === !1 && (t.beginPath(), t.rect(l, o, i, r), t.clip()), a.forEach((c) => {
314
+ c.forEach((h) => {
315
+ h.isWhitespace || (h.format && (t.save(), t.font = S(h.format), h.format.fontColor && (t.fillStyle = h.format.fontColor)), t.fillText(h.word.text, h.x, h.y), h.format && t.restore());
311
316
  });
312
317
  }), e.debug) {
313
- const { width: l, height: o, x: m = 0, y: p = 0 } = e, u = m + l, d = p + o;
314
- let c;
315
- e.align === "right" ? c = u : e.align === "left" ? c = m : c = m + l / 2;
316
- let g = p;
317
- e.vAlign === "bottom" ? g = d : e.vAlign === "middle" && (g = p + o / 2);
318
+ const c = l + i, h = o + r;
319
+ let m;
320
+ e.align === "right" ? m = c : e.align === "left" ? m = l : m = l + i / 2;
321
+ let g = o;
322
+ e.vAlign === "bottom" ? g = h : e.vAlign === "middle" && (g = o + r / 2);
318
323
  const f = "#0C8CE9";
319
- t.lineWidth = 1, t.strokeStyle = f, t.strokeRect(m, p, l, o), t.lineWidth = 1, (!e.align || e.align === "center") && (t.strokeStyle = f, t.beginPath(), t.moveTo(c, p), t.lineTo(c, d), t.stroke()), (!e.vAlign || e.vAlign === "middle") && (t.strokeStyle = f, t.beginPath(), t.moveTo(m, g), t.lineTo(u, g), t.stroke());
324
+ t.lineWidth = 1, t.strokeStyle = f, t.strokeRect(l, o, i, r), t.lineWidth = 1, (!e.align || e.align === "center") && (t.strokeStyle = f, t.beginPath(), t.moveTo(m, o), t.lineTo(m, h), t.stroke()), (!e.vAlign || e.vAlign === "middle") && (t.strokeStyle = f, t.beginPath(), t.moveTo(l, g), t.lineTo(c, g), t.stroke());
320
325
  }
321
- return t.restore(), { height: r };
326
+ return t.restore(), { height: u };
322
327
  };
323
328
  export {
324
329
  et as drawText,
@@ -326,10 +331,10 @@ export {
326
331
  tt as getTextHeight,
327
332
  S as getTextStyle,
328
333
  w as getWordHeight,
329
- K as specToJson,
330
- X as splitText,
331
- j as splitWords,
332
- P as textToWords,
333
- Q as wordsToJson
334
+ G as specToJson,
335
+ Q as splitText,
336
+ P as splitWords,
337
+ j as textToWords,
338
+ K as wordsToJson
334
339
  };
335
340
  //# sourceMappingURL=text-to-canvas.esm.min.js.map