@overpunch/threadtext 0.4.6 → 0.5.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/dist/core.d.ts ADDED
@@ -0,0 +1,142 @@
1
+ /**
2
+ * Mount a procedural satin-stitch embroidery renderer inside `target`.
3
+ *
4
+ * When `target` is a plain element, two stacked canvases (base + sheen overlay) are
5
+ * created inside it. When `target` is itself a `<canvas>`, it is used as the base and a
6
+ * sheen overlay is added as a sibling. Returns a {@link ThreadTextInstance} handle.
7
+ */
8
+ export declare function createThreadText(target: HTMLElement, opts: ThreadTextOptions): ThreadTextInstance;
9
+
10
+ /** CSS class names applied to the canvases threadText creates inside a container. */
11
+ export declare const THREAD_TEXT_CLASSES: {
12
+ /** Base canvas: the baked satin stitches (transparent ground). */
13
+ readonly bg: "tt-bg";
14
+ /** Overlay canvas: cursor sheen (`mix-blend-mode: screen`). */
15
+ readonly fx: "tt-fx";
16
+ /** The visually hidden real text (the element's own content, or a copy of `text`) for assistive tech. */
17
+ readonly text: "tt-text";
18
+ /** Blinking text caret shown in editable mode. */
19
+ readonly caret: "tt-caret";
20
+ };
21
+
22
+ /** Live handle to a mounted threadText renderer. */
23
+ export declare interface ThreadTextInstance {
24
+ /** Re-embroider with new text — re-fits to width and redraws instantly (no sew-in). */
25
+ setText(text: string): void;
26
+ /** Re-run the sew-in animation for the current word (when `animate` is on). */
27
+ replay(): void;
28
+ /** Re-fit the render surface to its container and redraw. */
29
+ resize(): void;
30
+ /**
31
+ * Apply option changes live and redraw instantly — never re-runs the sew-in. Use for
32
+ * colour, font, weight, size (`fill`), sew rate, sheen, and editability changes.
33
+ */
34
+ update(options: Partial<ThreadTextOptions>): void;
35
+ /** Focus the surface for typing (editable mode). */
36
+ focus(): void;
37
+ /** Cancel the animation loop, remove listeners, and free the created canvases. */
38
+ destroy(): void;
39
+ /** The current embroidered text. */
40
+ readonly text: string;
41
+ }
42
+
43
+ /**
44
+ * Options controlling the procedural satin-stitch embroidery renderer.
45
+ * Colours accept any CSS-ish hex (`#rgb` / `#rrggbb`) or `rgb()/rgba()` string.
46
+ */
47
+ export declare interface ThreadTextOptions {
48
+ /** The word (or short phrase) to embroider. */
49
+ text: string;
50
+ /**
51
+ * CSS `font-family` of an already-loaded font used to rasterise the glyphs.
52
+ * The renderer is font-agnostic — load the face however you like (`@font-face`,
53
+ * `next/font`, the CSS Font Loading API) before calling. (default: 'Georgia, serif')
54
+ */
55
+ font?: string;
56
+ /** Numeric font weight passed to the canvas `font` shorthand (100–900). (default: 680) */
57
+ weight?: number;
58
+ /**
59
+ * Variable-font axis values applied to the rasterised glyphs, e.g. `{ opsz: 40, SOFT: 60 }`.
60
+ * Uses the canvas `fontVariationSettings` API (Chrome/Edge/Safari) so the browser's own
61
+ * variable rendering drives the stitch shapes; silently ignored where unsupported (the font's
62
+ * default instance is used). Note: numeric `weight` already drives the `wght` axis via the
63
+ * standard font shorthand — reach for `axes` for `opsz` and custom axes (`SOFT`, `WONK`, …).
64
+ */
65
+ axes?: Record<string, number>;
66
+ /** Floss (thread) colour — the lit crest of each thread. (default: warm white '#fffbf3') */
67
+ threadColor?: string;
68
+ /**
69
+ * Second floss colour, used by `colorMode: 'twotone'` and `'gradient'`. Ignored when
70
+ * `colorMode` is `'solid'` (the default). (default: falls back to `threadColor`)
71
+ */
72
+ threadColor2?: string;
73
+ /**
74
+ * How the floss is coloured:
75
+ * - **'solid'** (default) — one colour (`threadColor`).
76
+ * - **'twotone'** — two colours (`threadColor` + `threadColor2`) laid as alternating threads
77
+ * packed side by side across each stroke.
78
+ * - **'gradient'** — a smooth colour transition from `threadColor` to `threadColor2` across the word.
79
+ */
80
+ colorMode?: 'solid' | 'twotone' | 'gradient';
81
+ /**
82
+ * Add a darker running-stitch **backstitch outline** traced around each glyph — the way a piece is
83
+ * often finished by hand. Sews in last. (default: false)
84
+ */
85
+ backstitch?: boolean;
86
+ /** Backstitch outline colour. (default: a darkened shade of `threadColor`) */
87
+ outlineColor?: string;
88
+ /**
89
+ * Thread spacing in internal pixels. Smaller = finer, denser stitching (and more work).
90
+ * (default: auto — derived from the fitted text height)
91
+ */
92
+ pitch?: number;
93
+ /**
94
+ * Fraction of the container width the word spans — the effective text size. The word is
95
+ * re-fitted to `fill × containerWidth` on load and resize, leaving the remainder as
96
+ * horizontal padding. Range ~0.3–1. (default: 0.9)
97
+ */
98
+ fill?: number;
99
+ /**
100
+ * Horizontal alignment of the word within the canvas when `fill` leaves spare width.
101
+ * `'center'` (default) · `'left'` · `'right'`.
102
+ */
103
+ align?: 'left' | 'center' | 'right';
104
+ /** Play the sew-in animation on mount and on `replay()`. (default: true) */
105
+ animate?: boolean;
106
+ /**
107
+ * How the word is sewn in:
108
+ * - **'machine'** (default) — satin cross-rows appear in parallel across each stroke, like
109
+ * machine embroidery (a BFS over the stitch graph).
110
+ * - **'hand'** — works one letter at a time (left to right). Within each letter it enters at
111
+ * the widest region near the top and works its way down the strokes, then cleans up the thin
112
+ * serifs and terminals last — the way a person embroiders a shape.
113
+ */
114
+ sewStyle?: 'machine' | 'hand';
115
+ /**
116
+ * The stitch texture filling each stroke:
117
+ * - **'satin'** (default) — smooth parallel threads across the stroke (raised satin floss).
118
+ * - **'cross'** — little X's, like cross-stitch.
119
+ * - **'chain'** — a field of looped links.
120
+ * - **'running'** — short dashes, a sparser hand-run look.
121
+ */
122
+ stitchMode?: 'satin' | 'cross' | 'chain' | 'running';
123
+ /** Satin cross-rows (machine) or stitches (hand) laid per second during the sew-in. (default: 110) */
124
+ sewRate?: number;
125
+ /** Enable the cursor-following radial sheen on the overlay canvas. (default: true) */
126
+ sheen?: boolean;
127
+ /**
128
+ * Make the surface focusable and typeable — click (or Tab) to focus, then type to edit
129
+ * the word, Backspace to delete, Enter to replay the sew-in. Shows a blinking caret.
130
+ * (default: false)
131
+ */
132
+ editable?: boolean;
133
+ /** Called with the new text whenever the user edits it directly (editable mode only). */
134
+ onTextChange?: (text: string) => void;
135
+ /**
136
+ * Force reduced-motion (skip the sew-in, draw instantly). If omitted, the value is
137
+ * auto-detected from `prefers-reduced-motion`.
138
+ */
139
+ reducedMotion?: boolean;
140
+ }
141
+
142
+ export { }