strokes-js 0.1.0 → 0.1.2

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/LICENSE ADDED
@@ -0,0 +1,15 @@
1
+ ISC License
2
+
3
+ Copyright (c) 2026, Anas
4
+
5
+ Permission to use, copy, modify, and/or distribute this software for any
6
+ purpose with or without fee is hereby granted, provided that the above
7
+ copyright notice and this permission notice appear in all copies.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12
+ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15
+ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
package/README.md CHANGED
@@ -197,6 +197,15 @@ export interface GlyphEntry {
197
197
 
198
198
  Adding or editing a glyph means editing its own file under `glyphs/letters`, `glyphs/digits`, or `glyphs/punctuation` — no other file needs to change except `glyphs.ts`'s import/lookup if you're adding a brand-new character.
199
199
 
200
+ ## Development
201
+
202
+ ```bash
203
+ npm run build # tsc — compiles src/ to dist/ (ESM + .d.ts)
204
+ npm run typecheck # tsc --noEmit
205
+ ```
206
+
207
+ There is no test suite or lint script yet.
208
+
200
209
  ## Demo
201
210
 
202
211
  `demo/index.html` is a static page (loads `../dist/index.js`, so run `npm run build` first) with:
package/dist/renderer.js CHANGED
@@ -16,9 +16,8 @@ function pickVariant(char, entry) {
16
16
  lastVariant.set(char, index);
17
17
  return index;
18
18
  }
19
- function splitWords(text) {
20
- // Attach trailing punctuation to the preceding word (e.g. "word," stays one unit).
21
- return text.split(/\s+/).filter((w) => w.length > 0);
19
+ function splitText(text) {
20
+ return text.split(/(\s+)/).filter((part) => part.length > 0);
22
21
  }
23
22
  const JITTER_ROTATE_DEG = 7;
24
23
  const JITTER_BASELINE = 1;
@@ -72,15 +71,20 @@ function renderWord(word, delayOffset, animate) {
72
71
  */
73
72
  export function renderText(text, options = {}) {
74
73
  const { animate = true } = options;
75
- const words = splitWords(text);
74
+ const parts = splitText(text);
76
75
  let delayOffset = 0;
77
- const wordSvgs = [];
78
- for (const word of words) {
76
+ const markup = [];
77
+ for (const part of parts) {
78
+ if (/^\s+$/.test(part)) {
79
+ markup.push(`<span class="hw-space" aria-hidden="true" style="white-space: pre-wrap">${escapeHtml(part)}</span>`);
80
+ continue;
81
+ }
82
+ const word = part;
79
83
  const { svg, letterCount } = renderWord(word, delayOffset, animate);
80
- wordSvgs.push(svg);
84
+ markup.push(svg);
81
85
  delayOffset += letterCount;
82
86
  }
83
- return `<span class="hw-sentence" aria-label="${escapeAttr(text)}">${wordSvgs.join(" ")}</span>`;
87
+ return `<span class="hw-sentence" aria-label="${escapeAttr(text)}">${markup.join("")}</span>`;
84
88
  }
85
89
  function escapeAttr(value) {
86
90
  return value
@@ -89,6 +93,12 @@ function escapeAttr(value) {
89
93
  .replace(/</g, "&lt;")
90
94
  .replace(/>/g, "&gt;");
91
95
  }
96
+ function escapeHtml(value) {
97
+ return value
98
+ .replace(/&/g, "&amp;")
99
+ .replace(/</g, "&lt;")
100
+ .replace(/>/g, "&gt;");
101
+ }
92
102
  /** Toggles the class that starts the draw-in transition for a rendered word's strokes. */
93
103
  export function animateWriting(el) {
94
104
  el.classList.add("hw-visible");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "strokes-js",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Renders text as animated hand-drawn SVG",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -33,7 +33,7 @@
33
33
  "text",
34
34
  "typography"
35
35
  ],
36
- "author": "",
36
+ "author": "Anas <anaselhaag@gmail.com>",
37
37
  "license": "ISC",
38
38
  "devDependencies": {
39
39
  "typescript": "^7.0.2"