strokes-js 0.1.2 → 0.1.3

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.
Files changed (2) hide show
  1. package/dist/renderer.js +10 -2
  2. package/package.json +1 -1
package/dist/renderer.js CHANGED
@@ -74,16 +74,24 @@ export function renderText(text, options = {}) {
74
74
  const parts = splitText(text);
75
75
  let delayOffset = 0;
76
76
  const markup = [];
77
+ let pendingWhitespace = "";
77
78
  for (const part of parts) {
78
79
  if (/^\s+$/.test(part)) {
79
- markup.push(`<span class="hw-space" aria-hidden="true" style="white-space: pre-wrap">${escapeHtml(part)}</span>`);
80
+ pendingWhitespace += part;
80
81
  continue;
81
82
  }
82
83
  const word = part;
83
84
  const { svg, letterCount } = renderWord(word, delayOffset, animate);
84
- markup.push(svg);
85
+ const space = pendingWhitespace
86
+ ? `<span class="hw-space" aria-hidden="true" style="white-space: pre-wrap">${escapeHtml(pendingWhitespace)}</span>`
87
+ : "";
88
+ markup.push(`<span class="hw-token">${space}${svg}</span>`);
89
+ pendingWhitespace = "";
85
90
  delayOffset += letterCount;
86
91
  }
92
+ if (pendingWhitespace) {
93
+ markup.push(`<span class="hw-token"><span class="hw-space" aria-hidden="true" style="white-space: pre-wrap">${escapeHtml(pendingWhitespace)}</span></span>`);
94
+ }
87
95
  return `<span class="hw-sentence" aria-label="${escapeAttr(text)}">${markup.join("")}</span>`;
88
96
  }
89
97
  function escapeAttr(value) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "strokes-js",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "Renders text as animated hand-drawn SVG",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",