@gridui/text-morph 0.0.0-stage → 1.0.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/README.md +97 -2
- package/dist/index.d.ts +10 -0
- package/dist/index.js +668 -0
- package/dist/index.js.map +7 -0
- package/dist/styles.css +41 -0
- package/dist/text-morph/matching.d.ts +9 -0
- package/dist/text-morph/options.d.ts +28 -0
- package/dist/text-morph/segments.d.ts +14 -0
- package/dist/text-morph/text-morph.d.ts +13 -0
- package/dist/text-morph/timing.d.ts +13 -0
- package/dist/text-morph/transition.d.ts +12 -0
- package/dist/text-morph/use-text-morph.d.ts +23 -0
- package/package.json +48 -3
package/README.md
CHANGED
|
@@ -1,3 +1,98 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @gridui/text-morph
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Core family. Public API: `TextMorph`, `useTextMorph`, `TextMorphProps`,
|
|
4
|
+
`TextMorphOptions`, and `TextMorphSpring`.
|
|
5
|
+
|
|
6
|
+
Import `@gridui/theme/styles.css` before `@gridui/text-morph/styles.css`.
|
|
7
|
+
|
|
8
|
+
```tsx
|
|
9
|
+
import { TextMorph } from "@gridui/text-morph";
|
|
10
|
+
|
|
11
|
+
<button type="button">
|
|
12
|
+
<TextMorph>{copied ? "Copied" : "Copy"}</TextMorph>
|
|
13
|
+
</button>
|
|
14
|
+
<TextMorph as="h2" locale="en" formatOptions={{ style: "currency", currency: "USD" }}
|
|
15
|
+
ease={{ stiffness: 170, damping: 20, mass: 1 }}>
|
|
16
|
+
{total}
|
|
17
|
+
</TextMorph>
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
`children` accepts a string or number. Numbers use `Intl.NumberFormat`; strings
|
|
21
|
+
retain their formatting. The host owns `locale` and formatting policy. Supply
|
|
22
|
+
the same locale on the server and client when formatting numbers.
|
|
23
|
+
|
|
24
|
+
## Matching and rendering
|
|
25
|
+
|
|
26
|
+
Matching preserves complete Unicode graphemes, prioritizes identical whole words,
|
|
27
|
+
and then matches remaining characters. Reordered words retain their own nodes.
|
|
28
|
+
Numeric runs match by place value, including decimal and grouping symbols; currency
|
|
29
|
+
and sign characters remain ordinary text. Set `numbers={false}` for identifiers,
|
|
30
|
+
dates, versions, and other values that should not use numeric place matching.
|
|
31
|
+
|
|
32
|
+
`cursorIndex` is the UTF-16 caret offset after an edit. It disables numeric place
|
|
33
|
+
matching and anchors insertion/deletion identity around that caret, including
|
|
34
|
+
repeated digits. Complex replacements fall back to ordinary text matching. The
|
|
35
|
+
component displays text; it does not own an input, selection, or visible caret.
|
|
36
|
+
|
|
37
|
+
`as` defaults to `span` and accepts `div`, `p`, `h1`–`h6`, `strong`, and `em`.
|
|
38
|
+
Native attributes and the root ref are forwarded. Explicit `\n` breaks are
|
|
39
|
+
supported. Automatic wrapping, rich markup, and connected-script shaping across
|
|
40
|
+
segment boundaries are outside this component's contract; use ordinary text for
|
|
41
|
+
prose and typography that requires those behaviors.
|
|
42
|
+
|
|
43
|
+
## Motion
|
|
44
|
+
|
|
45
|
+
| Option | Behavior |
|
|
46
|
+
| --- | --- |
|
|
47
|
+
| `duration` | Finite nonnegative milliseconds; defaults to the theme duration, or the spring's settling duration |
|
|
48
|
+
| `ease` | CSS easing string or `{ stiffness, damping, mass, precision }` spring parameters |
|
|
49
|
+
| `scale` | Shrink removed characters while fading them out; defaults to false |
|
|
50
|
+
| `disabled` | Apply the new value immediately |
|
|
51
|
+
| `debug` | Outline visual segments without logging content |
|
|
52
|
+
| `onAnimationStart` | Once when an animated update starts |
|
|
53
|
+
| `onAnimationComplete` | Once when every animation in that update finishes |
|
|
54
|
+
| `onAnimationCancel` | Once when an active update is interrupted, disabled, unmounted, or reduced motion becomes active |
|
|
55
|
+
|
|
56
|
+
The default duration and easing use `--gridui-motion-duration-normal` and
|
|
57
|
+
`--gridui-motion-ease-out`. Springs accept positive finite parameters, with
|
|
58
|
+
precision between 0 and 1. Sampling and duration are bounded. CSS `linear()`
|
|
59
|
+
support is detected; unsupported easing falls back to the theme. Explicit zero
|
|
60
|
+
duration, reduced motion, first render, and unchanged text do not emit animation
|
|
61
|
+
start/complete callbacks. Live reduced-motion changes cancel active motion.
|
|
62
|
+
|
|
63
|
+
## Hook composition
|
|
64
|
+
|
|
65
|
+
The hook shares the component's lifecycle and semantic/visual separation. Bind
|
|
66
|
+
all three prop objects, render `text` in the semantic span, and leave the visual
|
|
67
|
+
span empty. Load the same stylesheet. Merge any custom root class with the
|
|
68
|
+
returned class rather than replacing it.
|
|
69
|
+
|
|
70
|
+
```tsx
|
|
71
|
+
const morph = useTextMorph(value, { duration: 250 });
|
|
72
|
+
return (
|
|
73
|
+
<strong {...morph.rootProps}>
|
|
74
|
+
<span {...morph.textProps}>{morph.text}</span>
|
|
75
|
+
<span {...morph.layerProps} />
|
|
76
|
+
</strong>
|
|
77
|
+
);
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Server rendering emits the complete escaped value as ordinary text. Enhancement
|
|
81
|
+
starts after hydration; an accessible copy carries the current value exactly
|
|
82
|
+
once while visual fragments are hidden from assistive technology. Live-region
|
|
83
|
+
announcements remain the caller's choice. Values beyond 256 graphemes render
|
|
84
|
+
without segmentation or animation to bound matching work and DOM size. Without
|
|
85
|
+
`Intl.Segmenter`, a whole value remains one segment; without Web Animations,
|
|
86
|
+
updates settle immediately. The component always respects reduced motion.
|
|
87
|
+
|
|
88
|
+
Segmentation, matching, timing, the imperative visual controller, and the React
|
|
89
|
+
hook live separately in `src/text-morph/`. React owns semantic content; the
|
|
90
|
+
controller owns only its empty visual layer. No animation dependency, global
|
|
91
|
+
configuration, application state, or framework adapter is introduced.
|
|
92
|
+
|
|
93
|
+
This implements the React-facing capabilities studied in
|
|
94
|
+
[Torph](https://github.com/lochie/torph). Vue/Svelte/vanilla wrappers and an override
|
|
95
|
+
that disables accessibility preferences are outside GridUI's React contract.
|
|
96
|
+
|
|
97
|
+
See [component ownership](https://github.com/sudo-ui/GridUI-React-Monorepo/blob/main/docs/component-ownership.md)
|
|
98
|
+
and [release history](https://github.com/sudo-ui/GridUI-React-Monorepo/tree/main/packages-core/text-morph/.changeset/history).
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @author WMXPY
|
|
3
|
+
* @package GridUI
|
|
4
|
+
* @namespace Root
|
|
5
|
+
* @description Index
|
|
6
|
+
*/
|
|
7
|
+
export type { TextMorphOptions, TextMorphSpring } from "./text-morph/options";
|
|
8
|
+
export type { TextMorphProps } from "./text-morph/text-morph";
|
|
9
|
+
export { TextMorph } from "./text-morph/text-morph";
|
|
10
|
+
export { useTextMorph } from "./text-morph/use-text-morph";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,668 @@
|
|
|
1
|
+
// src/text-morph/options.ts
|
|
2
|
+
var validateOptions = (options) => {
|
|
3
|
+
if (options.duration !== void 0 && (!Number.isFinite(options.duration) || options.duration < 0)) {
|
|
4
|
+
throw new RangeError("TextMorph duration must be a finite nonnegative number.");
|
|
5
|
+
}
|
|
6
|
+
if (options.cursorIndex !== void 0 && (!Number.isInteger(options.cursorIndex) || options.cursorIndex < 0)) {
|
|
7
|
+
throw new RangeError("TextMorph cursorIndex must be a nonnegative integer.");
|
|
8
|
+
}
|
|
9
|
+
if (typeof options.ease === "object") {
|
|
10
|
+
const { stiffness = 170, damping = 26, mass = 1, precision = 1e-3 } = options.ease;
|
|
11
|
+
if (![
|
|
12
|
+
stiffness,
|
|
13
|
+
damping,
|
|
14
|
+
mass,
|
|
15
|
+
precision
|
|
16
|
+
].every((value) => {
|
|
17
|
+
return Number.isFinite(value) && value > 0;
|
|
18
|
+
}) || precision >= 1) {
|
|
19
|
+
throw new RangeError("TextMorph spring values must be finite and positive; precision must be below 1.");
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
// src/text-morph/segments.ts
|
|
25
|
+
var MAX_SEGMENTS = 256;
|
|
26
|
+
var segmentText = (text, locale, numbers = true) => {
|
|
27
|
+
if (typeof Intl.Segmenter !== "function") {
|
|
28
|
+
return [{ text }];
|
|
29
|
+
}
|
|
30
|
+
const parts = [];
|
|
31
|
+
const segmenter = new Intl.Segmenter(locale, { granularity: "grapheme" });
|
|
32
|
+
for (const part of segmenter.segment(text)) {
|
|
33
|
+
parts.push({ text: part.segment });
|
|
34
|
+
if (parts.length > MAX_SEGMENTS) {
|
|
35
|
+
return parts;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
const wordSegments = new Intl.Segmenter(locale, { granularity: "word" });
|
|
39
|
+
let graphemeIndex = 0;
|
|
40
|
+
let offset = 0;
|
|
41
|
+
for (const word of wordSegments.segment(text)) {
|
|
42
|
+
const end = word.index + word.segment.length;
|
|
43
|
+
while (graphemeIndex < parts.length && offset < end) {
|
|
44
|
+
const part = parts[graphemeIndex];
|
|
45
|
+
if (word.isWordLike) {
|
|
46
|
+
parts[graphemeIndex] = {
|
|
47
|
+
...part,
|
|
48
|
+
word: word.index
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
offset += part.text.length;
|
|
52
|
+
graphemeIndex++;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
if (!numbers) {
|
|
56
|
+
return parts;
|
|
57
|
+
}
|
|
58
|
+
const format = new Intl.NumberFormat(locale).formatToParts(12345.6);
|
|
59
|
+
const decimal = format.find((part) => {
|
|
60
|
+
return part.type === "decimal";
|
|
61
|
+
})?.value ?? ".";
|
|
62
|
+
const group = format.find((part) => {
|
|
63
|
+
return part.type === "group";
|
|
64
|
+
})?.value ?? ",";
|
|
65
|
+
const digit = /^\p{Decimal_Number}$/u;
|
|
66
|
+
let run = 0;
|
|
67
|
+
for (let start = 0; start < parts.length; start++) {
|
|
68
|
+
if (!digit.test(parts[start].text)) {
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
let end = start + 1;
|
|
72
|
+
while (end < parts.length) {
|
|
73
|
+
const value = parts[end].text;
|
|
74
|
+
if (digit.test(value)) {
|
|
75
|
+
end++;
|
|
76
|
+
} else if ((value === decimal || value === group) && digit.test(parts[end + 1]?.text ?? "")) {
|
|
77
|
+
end++;
|
|
78
|
+
} else {
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
const positions = parts.slice(start, end);
|
|
83
|
+
const separators = positions.filter((part) => {
|
|
84
|
+
return part.text === decimal;
|
|
85
|
+
});
|
|
86
|
+
if (separators.length <= 1) {
|
|
87
|
+
const point = positions.findIndex((part) => {
|
|
88
|
+
return part.text === decimal;
|
|
89
|
+
});
|
|
90
|
+
const wholeEnd = point < 0 ? positions.length : point;
|
|
91
|
+
let place = 0;
|
|
92
|
+
for (let index = wholeEnd - 1; index >= 0; index--) {
|
|
93
|
+
if (digit.test(positions[index].text)) {
|
|
94
|
+
parts[start + index] = {
|
|
95
|
+
...parts[start + index],
|
|
96
|
+
kind: "digit",
|
|
97
|
+
place: `${run}:whole:${place++}`
|
|
98
|
+
};
|
|
99
|
+
} else {
|
|
100
|
+
parts[start + index] = {
|
|
101
|
+
...parts[start + index],
|
|
102
|
+
kind: "symbol",
|
|
103
|
+
place: `${run}:group:${place}`
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
if (point >= 0) {
|
|
108
|
+
parts[start + point] = {
|
|
109
|
+
...parts[start + point],
|
|
110
|
+
kind: "symbol",
|
|
111
|
+
place: `${run}:decimal`
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
for (let index = wholeEnd + 1; index < positions.length; index++) {
|
|
115
|
+
if (digit.test(positions[index].text)) {
|
|
116
|
+
parts[start + index] = {
|
|
117
|
+
...parts[start + index],
|
|
118
|
+
kind: "digit",
|
|
119
|
+
place: `${run}:fraction:${index - wholeEnd}`
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
run++;
|
|
125
|
+
start = end - 1;
|
|
126
|
+
}
|
|
127
|
+
return parts;
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
// src/text-morph/matching.ts
|
|
131
|
+
var words = (segments) => {
|
|
132
|
+
const result = [];
|
|
133
|
+
segments.forEach((segment, index) => {
|
|
134
|
+
if (segment.word === void 0) {
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
const previous = result.at(-1);
|
|
138
|
+
if (previous && index > 0 && segments[index - 1].word === segment.word) {
|
|
139
|
+
previous.text += segment.text;
|
|
140
|
+
previous.length++;
|
|
141
|
+
} else {
|
|
142
|
+
result.push({
|
|
143
|
+
text: segment.text,
|
|
144
|
+
start: index,
|
|
145
|
+
length: 1
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
return result;
|
|
150
|
+
};
|
|
151
|
+
var caretMatches = (previous, next, cursor) => {
|
|
152
|
+
const before = previous.map((part) => {
|
|
153
|
+
return part.text;
|
|
154
|
+
}).join("");
|
|
155
|
+
const after = next.map((part) => {
|
|
156
|
+
return part.text;
|
|
157
|
+
}).join("");
|
|
158
|
+
const delta = after.length - before.length;
|
|
159
|
+
const start = cursor - Math.max(0, delta);
|
|
160
|
+
const oldEnd = start + Math.max(0, -delta);
|
|
161
|
+
const newEnd = start + Math.max(0, delta);
|
|
162
|
+
if (!delta || start < 0 || cursor > after.length || before.slice(0, start) !== after.slice(0, start) || before.slice(oldEnd) !== after.slice(newEnd)) {
|
|
163
|
+
return null;
|
|
164
|
+
}
|
|
165
|
+
const byOffset = /* @__PURE__ */ new Map();
|
|
166
|
+
let offset = 0;
|
|
167
|
+
previous.forEach((segment, index) => {
|
|
168
|
+
byOffset.set(offset, index);
|
|
169
|
+
offset += segment.text.length;
|
|
170
|
+
});
|
|
171
|
+
offset = 0;
|
|
172
|
+
const matches = /* @__PURE__ */ new Map();
|
|
173
|
+
next.forEach((segment, index) => {
|
|
174
|
+
let oldOffset = -1;
|
|
175
|
+
if (offset + segment.text.length <= start) {
|
|
176
|
+
oldOffset = offset;
|
|
177
|
+
} else if (offset >= newEnd) {
|
|
178
|
+
oldOffset = offset - delta;
|
|
179
|
+
}
|
|
180
|
+
const old = byOffset.get(oldOffset);
|
|
181
|
+
if (old !== void 0 && previous[old].text === segment.text) {
|
|
182
|
+
matches.set(index, old);
|
|
183
|
+
}
|
|
184
|
+
offset += segment.text.length;
|
|
185
|
+
});
|
|
186
|
+
return matches;
|
|
187
|
+
};
|
|
188
|
+
var matchSegments = (previous, next, cursorIndex) => {
|
|
189
|
+
const matches = /* @__PURE__ */ new Map();
|
|
190
|
+
if (previous.length > MAX_SEGMENTS || next.length > MAX_SEGMENTS) {
|
|
191
|
+
return matches;
|
|
192
|
+
}
|
|
193
|
+
if (cursorIndex !== void 0) {
|
|
194
|
+
const caret = caretMatches(previous, next, cursorIndex);
|
|
195
|
+
if (caret) {
|
|
196
|
+
return caret;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
const used = /* @__PURE__ */ new Set();
|
|
200
|
+
const places = new Map(previous.map((segment, index) => {
|
|
201
|
+
return [
|
|
202
|
+
segment.place,
|
|
203
|
+
index
|
|
204
|
+
];
|
|
205
|
+
}));
|
|
206
|
+
next.forEach((segment, index) => {
|
|
207
|
+
const old2 = segment.place === void 0 ? void 0 : places.get(segment.place);
|
|
208
|
+
if (old2 !== void 0) {
|
|
209
|
+
matches.set(index, old2);
|
|
210
|
+
used.add(old2);
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
const oldWords = words(previous);
|
|
214
|
+
for (const word of words(next)) {
|
|
215
|
+
const candidate = oldWords.find((old2) => {
|
|
216
|
+
return old2.text === word.text && old2.length === word.length && Array.from({ length: old2.length }, (_, offset) => {
|
|
217
|
+
return !used.has(old2.start + offset) && !matches.has(word.start + offset);
|
|
218
|
+
}).every(Boolean);
|
|
219
|
+
});
|
|
220
|
+
if (candidate) {
|
|
221
|
+
for (let offset = 0; offset < word.length; offset++) {
|
|
222
|
+
matches.set(word.start + offset, candidate.start + offset);
|
|
223
|
+
used.add(candidate.start + offset);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
const equal = (old2, current2) => {
|
|
228
|
+
return !used.has(old2) && !matches.has(current2) && previous[old2].place === void 0 && next[current2].place === void 0 && previous[old2].text === next[current2].text;
|
|
229
|
+
};
|
|
230
|
+
const stride = next.length + 1;
|
|
231
|
+
const lengths = new Uint16Array((previous.length + 1) * stride);
|
|
232
|
+
for (let old2 = previous.length - 1; old2 >= 0; old2--) {
|
|
233
|
+
for (let current2 = next.length - 1; current2 >= 0; current2--) {
|
|
234
|
+
lengths[old2 * stride + current2] = equal(old2, current2) ? lengths[(old2 + 1) * stride + current2 + 1] + 1 : Math.max(lengths[(old2 + 1) * stride + current2], lengths[old2 * stride + current2 + 1]);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
let old = 0;
|
|
238
|
+
let current = 0;
|
|
239
|
+
while (old < previous.length && current < next.length) {
|
|
240
|
+
if (equal(old, current)) {
|
|
241
|
+
matches.set(current, old);
|
|
242
|
+
used.add(old);
|
|
243
|
+
old++;
|
|
244
|
+
current++;
|
|
245
|
+
} else if (lengths[(old + 1) * stride + current] >= lengths[old * stride + current + 1]) {
|
|
246
|
+
old++;
|
|
247
|
+
} else {
|
|
248
|
+
current++;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
next.forEach((_, index) => {
|
|
252
|
+
const candidate = previous.findIndex((__, candidateIndex) => {
|
|
253
|
+
return equal(candidateIndex, index);
|
|
254
|
+
});
|
|
255
|
+
if (candidate >= 0) {
|
|
256
|
+
matches.set(index, candidate);
|
|
257
|
+
used.add(candidate);
|
|
258
|
+
}
|
|
259
|
+
});
|
|
260
|
+
return matches;
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
// src/text-morph/timing.ts
|
|
264
|
+
var milliseconds = (value, fallback = 180) => {
|
|
265
|
+
const amount = Number.parseFloat(value);
|
|
266
|
+
return Number.isFinite(amount) ? Math.max(0, amount * (value.trim().endsWith("ms") ? 1 : 1e3)) : fallback;
|
|
267
|
+
};
|
|
268
|
+
var springTiming = (spring) => {
|
|
269
|
+
const { stiffness = 170, damping = 26, mass = 1, precision = 1e-3 } = spring;
|
|
270
|
+
const frequency = Math.sqrt(stiffness / mass);
|
|
271
|
+
const ratio = damping / (2 * Math.sqrt(stiffness * mass));
|
|
272
|
+
const position = (time) => {
|
|
273
|
+
if (ratio < 1) {
|
|
274
|
+
const damped = frequency * Math.sqrt(1 - ratio * ratio);
|
|
275
|
+
return 1 - Math.exp(-ratio * frequency * time) * (Math.cos(damped * time) + ratio * frequency / damped * Math.sin(damped * time));
|
|
276
|
+
}
|
|
277
|
+
if (Math.abs(ratio - 1) < 1e-4) {
|
|
278
|
+
return 1 - Math.exp(-frequency * time) * (1 + frequency * time);
|
|
279
|
+
}
|
|
280
|
+
const root = Math.sqrt(ratio * ratio - 1);
|
|
281
|
+
const slow = -frequency / (ratio + root);
|
|
282
|
+
const fast = -frequency * (ratio + root);
|
|
283
|
+
return 1 - (fast * Math.exp(slow * time) - slow * Math.exp(fast * time)) / (fast - slow);
|
|
284
|
+
};
|
|
285
|
+
let seconds = 5;
|
|
286
|
+
let settled = 0;
|
|
287
|
+
for (let tick = 1; tick <= 300; tick++) {
|
|
288
|
+
const time = tick / 60;
|
|
289
|
+
const value = position(time);
|
|
290
|
+
const velocity = (value - position(time - 1 / 60)) * 60;
|
|
291
|
+
settled = Math.abs(1 - value) < precision && Math.abs(velocity) < precision ? settled + 1 : 0;
|
|
292
|
+
if (settled >= 4) {
|
|
293
|
+
seconds = time;
|
|
294
|
+
break;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
const points = Array.from({ length: 121 }, (_, index) => {
|
|
298
|
+
return index === 120 ? "1" : String(Number(position(seconds * index / 120).toFixed(5)));
|
|
299
|
+
});
|
|
300
|
+
return {
|
|
301
|
+
duration: seconds * 1e3,
|
|
302
|
+
easing: `linear(${points.join(", ")})`
|
|
303
|
+
};
|
|
304
|
+
};
|
|
305
|
+
|
|
306
|
+
// src/text-morph/transition.ts
|
|
307
|
+
var createTextTransition = (layer) => {
|
|
308
|
+
let items = [];
|
|
309
|
+
let initialized = false;
|
|
310
|
+
let active = null;
|
|
311
|
+
let revision = 0;
|
|
312
|
+
let lastText;
|
|
313
|
+
const animations = /* @__PURE__ */ new Set();
|
|
314
|
+
const exits = /* @__PURE__ */ new Set();
|
|
315
|
+
const motion = layer.ownerDocument.defaultView?.matchMedia("(prefers-reduced-motion: reduce)");
|
|
316
|
+
const settle = () => {
|
|
317
|
+
revision++;
|
|
318
|
+
const previous = active;
|
|
319
|
+
active = null;
|
|
320
|
+
for (const animation of animations) {
|
|
321
|
+
animation.cancel();
|
|
322
|
+
}
|
|
323
|
+
animations.clear();
|
|
324
|
+
for (const element of exits) {
|
|
325
|
+
element.remove();
|
|
326
|
+
}
|
|
327
|
+
exits.clear();
|
|
328
|
+
previous?.cancel?.();
|
|
329
|
+
};
|
|
330
|
+
const onMotionChange = () => {
|
|
331
|
+
if (motion?.matches) {
|
|
332
|
+
settle();
|
|
333
|
+
}
|
|
334
|
+
};
|
|
335
|
+
motion?.addEventListener("change", onMotionChange);
|
|
336
|
+
const update = (text, options) => {
|
|
337
|
+
if (text === lastText) {
|
|
338
|
+
if (options.disabled || options.duration === 0) {
|
|
339
|
+
settle();
|
|
340
|
+
}
|
|
341
|
+
return;
|
|
342
|
+
}
|
|
343
|
+
lastText = text;
|
|
344
|
+
const segments = segmentText(text, options.locale, options.cursorIndex === void 0 && options.numbers !== false);
|
|
345
|
+
const style = getComputedStyle(layer);
|
|
346
|
+
const spring = typeof options.ease === "object" ? springTiming(options.ease) : void 0;
|
|
347
|
+
const duration = options.duration ?? spring?.duration ?? milliseconds(style.getPropertyValue("--gridui-motion-duration-normal"));
|
|
348
|
+
const animate = initialized && !options.disabled && !motion?.matches && duration > 0 && typeof layer.animate === "function" && segments.length <= MAX_SEGMENTS && items.length <= MAX_SEGMENTS;
|
|
349
|
+
const origin = layer.getBoundingClientRect();
|
|
350
|
+
const scaleX = layer.offsetWidth ? origin.width / layer.offsetWidth : 1;
|
|
351
|
+
const scaleY = layer.offsetHeight ? origin.height / layer.offsetHeight : 1;
|
|
352
|
+
const before = animate ? items.map(({ element }) => {
|
|
353
|
+
return {
|
|
354
|
+
rect: element.getBoundingClientRect(),
|
|
355
|
+
opacity: getComputedStyle(element).opacity
|
|
356
|
+
};
|
|
357
|
+
}) : [];
|
|
358
|
+
settle();
|
|
359
|
+
const requestedEase = typeof options.ease === "string" ? options.ease : spring?.easing;
|
|
360
|
+
const fallbackEase = style.getPropertyValue("--gridui-motion-ease-out").trim() || "ease-out";
|
|
361
|
+
const easing = requestedEase && CSS.supports("animation-timing-function", requestedEase) ? requestedEase : fallbackEase;
|
|
362
|
+
const timing = {
|
|
363
|
+
duration,
|
|
364
|
+
easing
|
|
365
|
+
};
|
|
366
|
+
const currentRevision = revision;
|
|
367
|
+
const pending = [];
|
|
368
|
+
const play = (element, frames, done) => {
|
|
369
|
+
const animation = element.animate(frames, timing);
|
|
370
|
+
animations.add(animation);
|
|
371
|
+
pending.push(animation.finished);
|
|
372
|
+
void animation.finished.then(() => {
|
|
373
|
+
animations.delete(animation);
|
|
374
|
+
done?.();
|
|
375
|
+
}, () => {
|
|
376
|
+
animations.delete(animation);
|
|
377
|
+
});
|
|
378
|
+
};
|
|
379
|
+
if (segments.length > MAX_SEGMENTS) {
|
|
380
|
+
layer.textContent = text;
|
|
381
|
+
items = [];
|
|
382
|
+
initialized = false;
|
|
383
|
+
return;
|
|
384
|
+
}
|
|
385
|
+
const matches = matchSegments(items.map((item) => {
|
|
386
|
+
return item.segment;
|
|
387
|
+
}), segments, options.cursorIndex);
|
|
388
|
+
const retained = new Set(matches.values());
|
|
389
|
+
items.forEach((item, index) => {
|
|
390
|
+
if (retained.has(index)) {
|
|
391
|
+
return;
|
|
392
|
+
}
|
|
393
|
+
const box = before[index];
|
|
394
|
+
if (!animate || !box || item.segment.text === "\n") {
|
|
395
|
+
item.element.remove();
|
|
396
|
+
return;
|
|
397
|
+
}
|
|
398
|
+
item.element.style.position = "absolute";
|
|
399
|
+
item.element.style.left = `${(box.rect.left - origin.left) / scaleX}px`;
|
|
400
|
+
item.element.style.top = `${(box.rect.top - origin.top) / scaleY}px`;
|
|
401
|
+
exits.add(item.element);
|
|
402
|
+
});
|
|
403
|
+
if (!items.length) {
|
|
404
|
+
layer.replaceChildren();
|
|
405
|
+
}
|
|
406
|
+
const next = segments.map((segment, index) => {
|
|
407
|
+
const oldIndex = matches.get(index);
|
|
408
|
+
const previous = oldIndex === void 0 ? void 0 : items[oldIndex];
|
|
409
|
+
const element = previous?.element ?? layer.ownerDocument.createElement(segment.text === "\n" ? "br" : "span");
|
|
410
|
+
element.className = "gridui-text-morph-segment";
|
|
411
|
+
if (!previous || previous.segment.text !== segment.text || previous.segment.kind !== segment.kind) {
|
|
412
|
+
if (segment.place !== void 0) {
|
|
413
|
+
const glyph = layer.ownerDocument.createElement("span");
|
|
414
|
+
glyph.className = "gridui-text-morph-glyph";
|
|
415
|
+
glyph.textContent = segment.text;
|
|
416
|
+
element.replaceChildren(glyph);
|
|
417
|
+
} else {
|
|
418
|
+
element.textContent = segment.text === "\n" ? "" : segment.text;
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
element.dataset.digit = String(segment.kind === "digit");
|
|
422
|
+
element.dataset.kind = segment.kind ?? "text";
|
|
423
|
+
return {
|
|
424
|
+
segment,
|
|
425
|
+
element
|
|
426
|
+
};
|
|
427
|
+
});
|
|
428
|
+
let cursor = layer.firstChild;
|
|
429
|
+
for (const { element } of next) {
|
|
430
|
+
if (element === cursor) {
|
|
431
|
+
cursor = cursor.nextSibling;
|
|
432
|
+
} else {
|
|
433
|
+
layer.insertBefore(element, cursor);
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
if (animate) {
|
|
437
|
+
const after = next.map(({ element }) => {
|
|
438
|
+
return element.getBoundingClientRect();
|
|
439
|
+
});
|
|
440
|
+
const destination = layer.getBoundingClientRect();
|
|
441
|
+
if (Math.abs(destination.width - origin.width) > 0.1 || Math.abs(destination.height - origin.height) > 0.1) {
|
|
442
|
+
play(layer, [
|
|
443
|
+
{
|
|
444
|
+
width: `${origin.width / scaleX}px`,
|
|
445
|
+
height: `${origin.height / scaleY}px`
|
|
446
|
+
},
|
|
447
|
+
{
|
|
448
|
+
width: `${destination.width / scaleX}px`,
|
|
449
|
+
height: `${destination.height / scaleY}px`
|
|
450
|
+
}
|
|
451
|
+
]);
|
|
452
|
+
}
|
|
453
|
+
next.forEach((item, index) => {
|
|
454
|
+
if (item.segment.text === "\n") {
|
|
455
|
+
return;
|
|
456
|
+
}
|
|
457
|
+
const oldIndex = matches.get(index);
|
|
458
|
+
const box = oldIndex === void 0 ? void 0 : before[oldIndex];
|
|
459
|
+
const previous = oldIndex === void 0 ? void 0 : items[oldIndex];
|
|
460
|
+
if (box && previous) {
|
|
461
|
+
const x = (box.rect.left - after[index].left) / scaleX;
|
|
462
|
+
const y = (box.rect.top - after[index].top) / scaleY;
|
|
463
|
+
if (previous.segment.text !== item.segment.text && item.segment.place !== void 0) {
|
|
464
|
+
const outgoing = layer.ownerDocument.createElement("span");
|
|
465
|
+
outgoing.className = "gridui-text-morph-glyph";
|
|
466
|
+
outgoing.textContent = previous.segment.text;
|
|
467
|
+
outgoing.style.position = "absolute";
|
|
468
|
+
outgoing.style.left = "0";
|
|
469
|
+
outgoing.style.top = "0";
|
|
470
|
+
const incoming = item.element.firstElementChild;
|
|
471
|
+
item.element.append(outgoing);
|
|
472
|
+
if (Math.abs(x) > 0.1 || Math.abs(y) > 0.1) {
|
|
473
|
+
play(item.element, [
|
|
474
|
+
{ transform: `translate(${x}px, ${y}px)` },
|
|
475
|
+
{ transform: "none" }
|
|
476
|
+
]);
|
|
477
|
+
}
|
|
478
|
+
exits.add(outgoing);
|
|
479
|
+
play(outgoing, [
|
|
480
|
+
{
|
|
481
|
+
opacity: box.opacity,
|
|
482
|
+
transform: "translateY(0)"
|
|
483
|
+
},
|
|
484
|
+
{
|
|
485
|
+
opacity: 0,
|
|
486
|
+
transform: "translateY(-0.6em)"
|
|
487
|
+
}
|
|
488
|
+
], () => {
|
|
489
|
+
outgoing.remove();
|
|
490
|
+
exits.delete(outgoing);
|
|
491
|
+
});
|
|
492
|
+
play(incoming, [
|
|
493
|
+
{
|
|
494
|
+
opacity: 0,
|
|
495
|
+
transform: "translateY(0.6em)"
|
|
496
|
+
},
|
|
497
|
+
{
|
|
498
|
+
opacity: 1,
|
|
499
|
+
transform: "none"
|
|
500
|
+
}
|
|
501
|
+
]);
|
|
502
|
+
} else if (Math.abs(x) > 0.1 || Math.abs(y) > 0.1 || Number(box.opacity) < 1) {
|
|
503
|
+
play(item.element, [
|
|
504
|
+
{
|
|
505
|
+
transform: `translate(${x}px, ${y}px)`,
|
|
506
|
+
opacity: box.opacity
|
|
507
|
+
},
|
|
508
|
+
{
|
|
509
|
+
transform: "none",
|
|
510
|
+
opacity: 1
|
|
511
|
+
}
|
|
512
|
+
]);
|
|
513
|
+
}
|
|
514
|
+
} else {
|
|
515
|
+
play(item.element, [
|
|
516
|
+
{
|
|
517
|
+
opacity: 0,
|
|
518
|
+
transform: "translateY(0.3em)"
|
|
519
|
+
},
|
|
520
|
+
{
|
|
521
|
+
opacity: 1,
|
|
522
|
+
transform: "none"
|
|
523
|
+
}
|
|
524
|
+
]);
|
|
525
|
+
}
|
|
526
|
+
});
|
|
527
|
+
items.forEach((item, index) => {
|
|
528
|
+
if (exits.has(item.element)) {
|
|
529
|
+
play(item.element, [
|
|
530
|
+
{ opacity: before[index].opacity },
|
|
531
|
+
{
|
|
532
|
+
opacity: 0,
|
|
533
|
+
transform: options.scale ? "scale(0.7)" : "none"
|
|
534
|
+
}
|
|
535
|
+
], () => {
|
|
536
|
+
item.element.remove();
|
|
537
|
+
exits.delete(item.element);
|
|
538
|
+
});
|
|
539
|
+
}
|
|
540
|
+
});
|
|
541
|
+
}
|
|
542
|
+
items = next;
|
|
543
|
+
initialized = true;
|
|
544
|
+
if (pending.length) {
|
|
545
|
+
active = { cancel: options.onAnimationCancel };
|
|
546
|
+
options.onAnimationStart?.();
|
|
547
|
+
void Promise.allSettled(pending).then(() => {
|
|
548
|
+
if (revision === currentRevision && active) {
|
|
549
|
+
active = null;
|
|
550
|
+
options.onAnimationComplete?.();
|
|
551
|
+
}
|
|
552
|
+
});
|
|
553
|
+
}
|
|
554
|
+
};
|
|
555
|
+
return {
|
|
556
|
+
update,
|
|
557
|
+
destroy: () => {
|
|
558
|
+
settle();
|
|
559
|
+
motion?.removeEventListener("change", onMotionChange);
|
|
560
|
+
layer.replaceChildren();
|
|
561
|
+
}
|
|
562
|
+
};
|
|
563
|
+
};
|
|
564
|
+
|
|
565
|
+
// src/text-morph/use-text-morph.ts
|
|
566
|
+
import { useCallback, useLayoutEffect, useRef } from "react";
|
|
567
|
+
var useTextMorph = (value, options = {}) => {
|
|
568
|
+
validateOptions(options);
|
|
569
|
+
const text = typeof value === "number" ? new Intl.NumberFormat(options.locale, options.formatOptions).format(value) : value;
|
|
570
|
+
const latest = useRef(options);
|
|
571
|
+
const transition = useRef(null);
|
|
572
|
+
const element = useRef(null);
|
|
573
|
+
const layerRef = useCallback((layer) => {
|
|
574
|
+
transition.current?.destroy();
|
|
575
|
+
element.current?.parentElement?.removeAttribute("data-enhanced");
|
|
576
|
+
element.current = layer;
|
|
577
|
+
transition.current = layer ? createTextTransition(layer) : null;
|
|
578
|
+
}, []);
|
|
579
|
+
useLayoutEffect(() => {
|
|
580
|
+
latest.current = options;
|
|
581
|
+
transition.current?.update(text, {
|
|
582
|
+
...options,
|
|
583
|
+
onAnimationStart: () => {
|
|
584
|
+
latest.current.onAnimationStart?.();
|
|
585
|
+
},
|
|
586
|
+
onAnimationComplete: () => {
|
|
587
|
+
latest.current.onAnimationComplete?.();
|
|
588
|
+
},
|
|
589
|
+
onAnimationCancel: () => {
|
|
590
|
+
latest.current.onAnimationCancel?.();
|
|
591
|
+
}
|
|
592
|
+
});
|
|
593
|
+
element.current?.parentElement?.setAttribute("data-enhanced", "true");
|
|
594
|
+
});
|
|
595
|
+
return {
|
|
596
|
+
text,
|
|
597
|
+
rootProps: {
|
|
598
|
+
className: "gridui-text-morph",
|
|
599
|
+
"data-debug": options.debug || void 0
|
|
600
|
+
},
|
|
601
|
+
textProps: { className: "gridui-text-morph-text" },
|
|
602
|
+
layerProps: {
|
|
603
|
+
ref: layerRef,
|
|
604
|
+
className: "gridui-text-morph-layer",
|
|
605
|
+
"aria-hidden": true
|
|
606
|
+
}
|
|
607
|
+
};
|
|
608
|
+
};
|
|
609
|
+
|
|
610
|
+
// src/text-morph/text-morph.tsx
|
|
611
|
+
import { cn } from "@gridui/style-utils";
|
|
612
|
+
import { createElement } from "react";
|
|
613
|
+
import { jsx } from "react/jsx-runtime";
|
|
614
|
+
var TextMorph = (props) => {
|
|
615
|
+
const {
|
|
616
|
+
children,
|
|
617
|
+
as = "span",
|
|
618
|
+
locale,
|
|
619
|
+
formatOptions,
|
|
620
|
+
numbers,
|
|
621
|
+
cursorIndex,
|
|
622
|
+
disabled,
|
|
623
|
+
duration,
|
|
624
|
+
ease,
|
|
625
|
+
scale,
|
|
626
|
+
debug,
|
|
627
|
+
onAnimationStart,
|
|
628
|
+
onAnimationComplete,
|
|
629
|
+
onAnimationCancel,
|
|
630
|
+
className,
|
|
631
|
+
...restProps
|
|
632
|
+
} = props;
|
|
633
|
+
const morph = useTextMorph(children, {
|
|
634
|
+
locale,
|
|
635
|
+
formatOptions,
|
|
636
|
+
numbers,
|
|
637
|
+
cursorIndex,
|
|
638
|
+
disabled,
|
|
639
|
+
duration,
|
|
640
|
+
ease,
|
|
641
|
+
scale,
|
|
642
|
+
debug,
|
|
643
|
+
onAnimationStart,
|
|
644
|
+
onAnimationComplete,
|
|
645
|
+
onAnimationCancel
|
|
646
|
+
});
|
|
647
|
+
return createElement(as, {
|
|
648
|
+
...restProps,
|
|
649
|
+
...morph.rootProps,
|
|
650
|
+
className: cn(morph.rootProps.className, className)
|
|
651
|
+
}, /* @__PURE__ */ jsx(
|
|
652
|
+
"span",
|
|
653
|
+
{
|
|
654
|
+
...morph.textProps,
|
|
655
|
+
children: morph.text
|
|
656
|
+
}
|
|
657
|
+
), /* @__PURE__ */ jsx(
|
|
658
|
+
"span",
|
|
659
|
+
{
|
|
660
|
+
...morph.layerProps
|
|
661
|
+
}
|
|
662
|
+
));
|
|
663
|
+
};
|
|
664
|
+
export {
|
|
665
|
+
TextMorph,
|
|
666
|
+
useTextMorph
|
|
667
|
+
};
|
|
668
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/text-morph/options.ts", "../src/text-morph/segments.ts", "../src/text-morph/matching.ts", "../src/text-morph/timing.ts", "../src/text-morph/transition.ts", "../src/text-morph/use-text-morph.ts", "../src/text-morph/text-morph.tsx"],
|
|
4
|
+
"sourcesContent": ["/**\n * @author WMXPY\n * @package GridUI\n * @namespace TextMorph\n * @description Options\n */\n\nexport type TextMorphSpring = {\n readonly stiffness?: number | undefined;\n readonly damping?: number | undefined;\n readonly mass?: number | undefined;\n readonly precision?: number | undefined;\n};\n\nexport type TextMorphOptions = {\n readonly locale?: string | undefined;\n readonly formatOptions?: Intl.NumberFormatOptions | undefined;\n readonly numbers?: boolean | undefined;\n /** UTF-16 caret position after an edit. Disables numeric place matching. */\n readonly cursorIndex?: number | undefined;\n readonly disabled?: boolean | undefined;\n readonly duration?: number | undefined;\n readonly ease?: string | TextMorphSpring | undefined;\n readonly scale?: boolean | undefined;\n readonly debug?: boolean | undefined;\n readonly onAnimationStart?: (() => void) | undefined;\n readonly onAnimationComplete?: (() => void) | undefined;\n readonly onAnimationCancel?: (() => void) | undefined;\n};\n\nexport const validateOptions = (options: TextMorphOptions): void => {\n if (options.duration !== undefined && (!Number.isFinite(options.duration) || options.duration < 0)) {\n throw new RangeError(\"TextMorph duration must be a finite nonnegative number.\");\n }\n if (options.cursorIndex !== undefined && (!Number.isInteger(options.cursorIndex) || options.cursorIndex < 0)) {\n throw new RangeError(\"TextMorph cursorIndex must be a nonnegative integer.\");\n }\n if (typeof options.ease === \"object\") {\n const { stiffness = 170, damping = 26, mass = 1, precision = 0.001 } = options.ease;\n if (![\n stiffness,\n damping,\n mass,\n precision,\n ].every((value) => {\n return Number.isFinite(value) && value > 0;\n }) || precision >= 1) {\n throw new RangeError(\"TextMorph spring values must be finite and positive; precision must be below 1.\");\n }\n }\n};\n", "/**\n * @author WMXPY\n * @package GridUI\n * @namespace TextMorph\n * @description Segments\n */\n\nexport type TextSegment = {\n readonly text: string;\n readonly place?: string;\n readonly kind?: \"digit\" | \"symbol\";\n readonly word?: number;\n};\n\n// Bound both DOM size and quadratic matching work; longer values remain plain text.\nexport const MAX_SEGMENTS = 256;\n\nexport const segmentText = (text: string, locale?: string, numbers = true): TextSegment[] => {\n if (typeof Intl.Segmenter !== \"function\") {\n return [{ text }];\n }\n const parts: TextSegment[] = [];\n const segmenter = new Intl.Segmenter(locale, { granularity: \"grapheme\" });\n for (const part of segmenter.segment(text)) {\n parts.push({ text: part.segment });\n if (parts.length > MAX_SEGMENTS) {\n return parts;\n }\n }\n const wordSegments = new Intl.Segmenter(locale, { granularity: \"word\" });\n let graphemeIndex = 0;\n let offset = 0;\n for (const word of wordSegments.segment(text)) {\n const end = word.index + word.segment.length;\n while (graphemeIndex < parts.length && offset < end) {\n const part = parts[graphemeIndex]!;\n if (word.isWordLike) {\n parts[graphemeIndex] = {\n ...part,\n word: word.index,\n };\n }\n offset += part.text.length;\n graphemeIndex++;\n }\n }\n if (!numbers) {\n return parts;\n }\n const format = new Intl.NumberFormat(locale).formatToParts(12345.6);\n const decimal = format.find((part) => {\n return part.type === \"decimal\";\n })?.value ?? \".\";\n const group = format.find((part) => {\n return part.type === \"group\";\n })?.value ?? \",\";\n const digit = /^\\p{Decimal_Number}$/u;\n let run = 0;\n for (let start = 0; start < parts.length; start++) {\n if (!digit.test(parts[start]!.text)) {\n continue;\n }\n let end = start + 1;\n while (end < parts.length) {\n const value = parts[end]!.text;\n if (digit.test(value)) {\n end++;\n } else if ((value === decimal || value === group) && digit.test(parts[end + 1]?.text ?? \"\")) {\n end++;\n } else {\n break;\n }\n }\n const positions = parts.slice(start, end);\n const separators = positions.filter((part) => {\n return part.text === decimal;\n });\n if (separators.length <= 1) {\n const point = positions.findIndex((part) => {\n return part.text === decimal;\n });\n const wholeEnd = point < 0 ? positions.length : point;\n let place = 0;\n for (let index = wholeEnd - 1; index >= 0; index--) {\n if (digit.test(positions[index]!.text)) {\n parts[start + index] = {\n ...parts[start + index]!,\n kind: \"digit\",\n place: `${run}:whole:${place++}`,\n };\n } else {\n parts[start + index] = {\n ...parts[start + index]!,\n kind: \"symbol\",\n place: `${run}:group:${place}`,\n };\n }\n }\n if (point >= 0) {\n parts[start + point] = {\n ...parts[start + point]!,\n kind: \"symbol\",\n place: `${run}:decimal`,\n };\n }\n for (let index = wholeEnd + 1; index < positions.length; index++) {\n if (digit.test(positions[index]!.text)) {\n parts[start + index] = {\n ...parts[start + index]!,\n kind: \"digit\",\n place: `${run}:fraction:${index - wholeEnd}`,\n };\n }\n }\n }\n run++;\n start = end - 1;\n }\n return parts;\n};\n", "/**\n * @author WMXPY\n * @package GridUI\n * @namespace TextMorph\n * @description Matching\n */\n\nimport type { TextSegment } from \"./segments\";\nimport { MAX_SEGMENTS } from \"./segments\";\n\ntype Word = {\n text: string;\n start: number;\n length: number;\n};\n\nconst words = (segments: readonly TextSegment[]): Word[] => {\n const result: Word[] = [];\n segments.forEach((segment, index) => {\n if (segment.word === undefined) {\n return;\n }\n const previous = result.at(-1);\n if (previous && index > 0 && segments[index - 1]!.word === segment.word) {\n previous.text += segment.text;\n previous.length++;\n } else {\n result.push({\n text: segment.text,\n start: index,\n length: 1,\n });\n }\n });\n return result;\n};\n\nconst caretMatches = (previous: readonly TextSegment[], next: readonly TextSegment[], cursor: number): Map<number, number> | null => {\n const before = previous.map((part) => {\n return part.text;\n }).join(\"\");\n const after = next.map((part) => {\n return part.text;\n }).join(\"\");\n const delta = after.length - before.length;\n const start = cursor - Math.max(0, delta);\n const oldEnd = start + Math.max(0, -delta);\n const newEnd = start + Math.max(0, delta);\n if (!delta || start < 0 || cursor > after.length || before.slice(0, start) !== after.slice(0, start)\n || before.slice(oldEnd) !== after.slice(newEnd)) {\n return null;\n }\n const byOffset = new Map<number, number>();\n let offset = 0;\n previous.forEach((segment, index) => {\n byOffset.set(offset, index);\n offset += segment.text.length;\n });\n offset = 0;\n const matches = new Map<number, number>();\n next.forEach((segment, index) => {\n let oldOffset = -1;\n if (offset + segment.text.length <= start) {\n oldOffset = offset;\n }\n else if (offset >= newEnd) {\n oldOffset = offset - delta;\n }\n const old = byOffset.get(oldOffset);\n if (old !== undefined && previous[old]!.text === segment.text) {\n matches.set(index, old);\n }\n offset += segment.text.length;\n });\n return matches;\n};\n\n/** Keep whole words together before matching remaining graphemes. Each node has one owner. */\nexport const matchSegments = (previous: readonly TextSegment[], next: readonly TextSegment[], cursorIndex?: number): Map<number, number> => {\n const matches = new Map<number, number>();\n if (previous.length > MAX_SEGMENTS || next.length > MAX_SEGMENTS) {\n return matches;\n }\n if (cursorIndex !== undefined) {\n const caret = caretMatches(previous, next, cursorIndex);\n if (caret) {\n return caret;\n }\n }\n const used = new Set<number>();\n const places = new Map(previous.map((segment, index) => {\n return [\n segment.place,\n index,\n ];\n }));\n next.forEach((segment, index) => {\n const old = segment.place === undefined ? undefined : places.get(segment.place);\n if (old !== undefined) {\n matches.set(index, old);\n used.add(old);\n }\n });\n const oldWords = words(previous);\n for (const word of words(next)) {\n const candidate = oldWords.find((old) => {\n return old.text === word.text && old.length === word.length\n && Array.from({ length: old.length }, (_, offset) => {\n return !used.has(old.start + offset) && !matches.has(word.start + offset);\n }).every(Boolean);\n });\n if (candidate) {\n for (let offset = 0; offset < word.length; offset++) {\n matches.set(word.start + offset, candidate.start + offset);\n used.add(candidate.start + offset);\n }\n }\n }\n const equal = (old: number, current: number) => {\n return !used.has(old) && !matches.has(current) && previous[old]!.place === undefined\n && next[current]!.place === undefined && previous[old]!.text === next[current]!.text;\n };\n const stride = next.length + 1;\n const lengths = new Uint16Array((previous.length + 1) * stride);\n for (let old = previous.length - 1; old >= 0; old--) {\n for (let current = next.length - 1; current >= 0; current--) {\n lengths[old * stride + current] = equal(old, current)\n ? lengths[(old + 1) * stride + current + 1]! + 1\n : Math.max(lengths[(old + 1) * stride + current]!, lengths[old * stride + current + 1]!);\n }\n }\n let old = 0;\n let current = 0;\n while (old < previous.length && current < next.length) {\n if (equal(old, current)) {\n matches.set(current, old);\n used.add(old);\n old++;\n current++;\n } else if (lengths[(old + 1) * stride + current]! >= lengths[old * stride + current + 1]!) {\n old++;\n } else {\n current++;\n }\n }\n next.forEach((_, index) => {\n const candidate = previous.findIndex((__, candidateIndex) => {\n return equal(candidateIndex, index);\n });\n if (candidate >= 0) {\n matches.set(index, candidate);\n used.add(candidate);\n }\n });\n return matches;\n};\n", "/**\n * @author WMXPY\n * @package GridUI\n * @namespace TextMorph\n * @description Timing\n */\n\nimport type { TextMorphSpring } from \"./options\";\n\nexport const milliseconds = (value: string, fallback = 180): number => {\n const amount = Number.parseFloat(value);\n return Number.isFinite(amount) ? Math.max(0, amount * (value.trim().endsWith(\"ms\") ? 1 : 1000)) : fallback;\n};\n\n/** Analytic damped oscillator; bounded samples avoid a per-character animation loop. */\nexport const springTiming = (spring: TextMorphSpring): {\n duration: number;\n easing: string;\n} => {\n const { stiffness = 170, damping = 26, mass = 1, precision = 0.001 } = spring;\n const frequency = Math.sqrt(stiffness / mass);\n const ratio = damping / (2 * Math.sqrt(stiffness * mass));\n const position = (time: number): number => {\n if (ratio < 1) {\n const damped = frequency * Math.sqrt(1 - ratio * ratio);\n return 1 - Math.exp(-ratio * frequency * time)\n * (Math.cos(damped * time) + ratio * frequency / damped * Math.sin(damped * time));\n }\n if (Math.abs(ratio - 1) < 0.0001) {\n return 1 - Math.exp(-frequency * time) * (1 + frequency * time);\n }\n const root = Math.sqrt(ratio * ratio - 1);\n const slow = -frequency / (ratio + root);\n const fast = -frequency * (ratio + root);\n return 1 - (fast * Math.exp(slow * time) - slow * Math.exp(fast * time)) / (fast - slow);\n };\n let seconds = 5;\n let settled = 0;\n for (let tick = 1; tick <= 300; tick++) {\n const time = tick / 60;\n const value = position(time);\n const velocity = (value - position(time - 1 / 60)) * 60;\n settled = Math.abs(1 - value) < precision && Math.abs(velocity) < precision ? settled + 1 : 0;\n if (settled >= 4) {\n seconds = time;\n break;\n }\n }\n const points = Array.from({ length: 121 }, (_, index) => {\n return index === 120 ? \"1\" : String(Number(position(seconds * index / 120).toFixed(5)));\n });\n return {\n duration: seconds * 1000,\n easing: `linear(${points.join(\", \")})`,\n };\n};\n", "/**\n * @author WMXPY\n * @package GridUI\n * @namespace TextMorph\n * @description Transition\n */\n\nimport { matchSegments } from \"./matching\";\nimport type { TextMorphOptions } from \"./options\";\nimport type { TextSegment } from \"./segments\";\nimport { MAX_SEGMENTS, segmentText } from \"./segments\";\nimport { milliseconds, springTiming } from \"./timing\";\n\ntype Item = {\n segment: TextSegment;\n element: HTMLSpanElement;\n};\nexport type TransitionOptions = Omit<TextMorphOptions, \"formatOptions\">;\n\nexport const createTextTransition = (layer: HTMLSpanElement) => {\n let items: Item[] = [];\n let initialized = false;\n let active: {\n cancel: (() => void) | undefined;\n } | null = null;\n let revision = 0;\n let lastText: string | undefined;\n const animations = new Set<Animation>();\n const exits = new Set<HTMLElement>();\n const motion = layer.ownerDocument.defaultView?.matchMedia(\"(prefers-reduced-motion: reduce)\");\n const settle = () => {\n revision++;\n const previous = active;\n active = null;\n for (const animation of animations) {\n animation.cancel();\n }\n animations.clear();\n for (const element of exits) {\n element.remove();\n }\n exits.clear();\n previous?.cancel?.();\n };\n const onMotionChange = () => {\n if (motion?.matches) {\n settle();\n }\n };\n motion?.addEventListener(\"change\", onMotionChange);\n\n const update = (text: string, options: TransitionOptions) => {\n if (text === lastText) {\n if (options.disabled || options.duration === 0) {\n settle();\n }\n return;\n }\n lastText = text;\n const segments = segmentText(text, options.locale, options.cursorIndex === undefined && options.numbers !== false);\n const style = getComputedStyle(layer);\n const spring = typeof options.ease === \"object\" ? springTiming(options.ease) : undefined;\n const duration = options.duration ?? spring?.duration ?? milliseconds(style.getPropertyValue(\"--gridui-motion-duration-normal\"));\n const animate = initialized && !options.disabled && !motion?.matches && duration > 0\n && typeof layer.animate === \"function\" && segments.length <= MAX_SEGMENTS && items.length <= MAX_SEGMENTS;\n const origin = layer.getBoundingClientRect();\n const scaleX = layer.offsetWidth ? origin.width / layer.offsetWidth : 1;\n const scaleY = layer.offsetHeight ? origin.height / layer.offsetHeight : 1;\n const before = animate ? items.map(({ element }) => {\n return {\n rect: element.getBoundingClientRect(),\n opacity: getComputedStyle(element).opacity,\n };\n }) : [];\n settle();\n const requestedEase = typeof options.ease === \"string\" ? options.ease : spring?.easing;\n const fallbackEase = style.getPropertyValue(\"--gridui-motion-ease-out\").trim() || \"ease-out\";\n const easing = requestedEase && CSS.supports(\"animation-timing-function\", requestedEase) ? requestedEase : fallbackEase;\n const timing: KeyframeAnimationOptions = {\n duration,\n easing,\n };\n const currentRevision = revision;\n const pending: Promise<Animation>[] = [];\n const play = (element: HTMLElement, frames: Keyframe[], done?: () => void) => {\n const animation = element.animate(frames, timing);\n animations.add(animation);\n pending.push(animation.finished);\n void animation.finished.then(() => {\n animations.delete(animation);\n done?.();\n }, () => {\n animations.delete(animation);\n });\n };\n if (segments.length > MAX_SEGMENTS) {\n layer.textContent = text;\n items = [];\n initialized = false;\n return;\n }\n const matches = matchSegments(items.map((item) => {\n return item.segment;\n }), segments, options.cursorIndex);\n const retained = new Set(matches.values());\n items.forEach((item, index) => {\n if (retained.has(index)) {\n return;\n }\n const box = before[index];\n if (!animate || !box || item.segment.text === \"\\n\") {\n item.element.remove();\n return;\n }\n item.element.style.position = \"absolute\";\n item.element.style.left = `${(box.rect.left - origin.left) / scaleX}px`;\n item.element.style.top = `${(box.rect.top - origin.top) / scaleY}px`;\n exits.add(item.element);\n });\n if (!items.length) {\n layer.replaceChildren();\n }\n const next = segments.map((segment, index): Item => {\n const oldIndex = matches.get(index);\n const previous = oldIndex === undefined ? undefined : items[oldIndex];\n const element = previous?.element ?? layer.ownerDocument.createElement(segment.text === \"\\n\" ? \"br\" : \"span\");\n element.className = \"gridui-text-morph-segment\";\n if (!previous || previous.segment.text !== segment.text || previous.segment.kind !== segment.kind) {\n if (segment.place !== undefined) {\n const glyph = layer.ownerDocument.createElement(\"span\");\n glyph.className = \"gridui-text-morph-glyph\";\n glyph.textContent = segment.text;\n element.replaceChildren(glyph);\n } else {\n element.textContent = segment.text === \"\\n\" ? \"\" : segment.text;\n }\n }\n element.dataset.digit = String(segment.kind === \"digit\");\n element.dataset.kind = segment.kind ?? \"text\";\n return {\n segment,\n element,\n };\n });\n let cursor: ChildNode | null = layer.firstChild;\n for (const { element } of next) {\n if (element === cursor) {\n cursor = cursor.nextSibling;\n } else {\n layer.insertBefore(element, cursor);\n }\n }\n if (animate) {\n // Read every destination before starting any animations.\n const after = next.map(({ element }) => {\n return element.getBoundingClientRect();\n });\n const destination = layer.getBoundingClientRect();\n if (Math.abs(destination.width - origin.width) > 0.1 || Math.abs(destination.height - origin.height) > 0.1) {\n play(layer, [\n {\n width: `${origin.width / scaleX}px`,\n height: `${origin.height / scaleY}px`,\n },\n {\n width: `${destination.width / scaleX}px`,\n height: `${destination.height / scaleY}px`,\n },\n ]);\n }\n next.forEach((item, index) => {\n if (item.segment.text === \"\\n\") {\n return;\n }\n const oldIndex = matches.get(index);\n const box = oldIndex === undefined ? undefined : before[oldIndex];\n const previous = oldIndex === undefined ? undefined : items[oldIndex];\n if (box && previous) {\n const x = (box.rect.left - after[index]!.left) / scaleX;\n const y = (box.rect.top - after[index]!.top) / scaleY;\n if (previous.segment.text !== item.segment.text && item.segment.place !== undefined) {\n const outgoing = layer.ownerDocument.createElement(\"span\");\n outgoing.className = \"gridui-text-morph-glyph\";\n outgoing.textContent = previous.segment.text;\n outgoing.style.position = \"absolute\";\n outgoing.style.left = \"0\";\n outgoing.style.top = \"0\";\n const incoming = item.element.firstElementChild as HTMLElement;\n item.element.append(outgoing);\n if (Math.abs(x) > 0.1 || Math.abs(y) > 0.1) {\n play(item.element, [\n { transform: `translate(${x}px, ${y}px)` },\n { transform: \"none\" },\n ]);\n }\n exits.add(outgoing);\n play(outgoing, [\n {\n opacity: box.opacity,\n transform: \"translateY(0)\",\n },\n {\n opacity: 0,\n transform: \"translateY(-0.6em)\",\n },\n ], () => {\n outgoing.remove();\n exits.delete(outgoing);\n });\n play(incoming, [\n {\n opacity: 0,\n transform: \"translateY(0.6em)\",\n },\n {\n opacity: 1,\n transform: \"none\",\n },\n ]);\n } else if (Math.abs(x) > 0.1 || Math.abs(y) > 0.1 || Number(box.opacity) < 1) {\n play(item.element, [\n {\n transform: `translate(${x}px, ${y}px)`,\n opacity: box.opacity,\n },\n {\n transform: \"none\",\n opacity: 1,\n },\n ]);\n }\n } else {\n play(item.element, [\n {\n opacity: 0,\n transform: \"translateY(0.3em)\",\n },\n {\n opacity: 1,\n transform: \"none\",\n },\n ]);\n }\n });\n items.forEach((item, index) => {\n if (exits.has(item.element)) {\n play(item.element, [\n { opacity: before[index]!.opacity },\n {\n opacity: 0,\n transform: options.scale ? \"scale(0.7)\" : \"none\",\n },\n ], () => {\n item.element.remove();\n exits.delete(item.element);\n });\n }\n });\n }\n items = next;\n initialized = true;\n if (pending.length) {\n active = { cancel: options.onAnimationCancel };\n options.onAnimationStart?.();\n void Promise.allSettled(pending).then(() => {\n if (revision === currentRevision && active) {\n active = null;\n options.onAnimationComplete?.();\n }\n });\n }\n };\n return {\n update,\n destroy: () => {\n settle();\n motion?.removeEventListener(\"change\", onMotionChange);\n layer.replaceChildren();\n },\n };\n};\n", "/**\n * @author WMXPY\n * @package GridUI\n * @namespace TextMorph\n * @description Use Text Morph\n */\n\nimport type { TextMorphOptions } from \"./options\";\nimport { validateOptions } from \"./options\";\nimport { createTextTransition } from \"./transition\";\nimport { useCallback, useLayoutEffect, useRef } from \"react\";\n\n/** Bind the returned props to a root, semantic text, and empty visual span. */\nexport const useTextMorph = (value: string | number, options: TextMorphOptions = {}) => {\n validateOptions(options);\n const text = typeof value === \"number\" ? new Intl.NumberFormat(options.locale, options.formatOptions).format(value) : value;\n const latest = useRef(options);\n const transition = useRef<ReturnType<typeof createTextTransition> | null>(null);\n const element = useRef<HTMLSpanElement | null>(null);\n const layerRef = useCallback((layer: HTMLSpanElement | null) => {\n transition.current?.destroy();\n element.current?.parentElement?.removeAttribute(\"data-enhanced\");\n element.current = layer;\n transition.current = layer ? createTextTransition(layer) : null;\n }, []);\n useLayoutEffect(() => {\n latest.current = options;\n transition.current?.update(text, {\n ...options,\n onAnimationStart: () => {\n latest.current.onAnimationStart?.();\n },\n onAnimationComplete: () => {\n latest.current.onAnimationComplete?.();\n },\n onAnimationCancel: () => {\n latest.current.onAnimationCancel?.();\n },\n });\n element.current?.parentElement?.setAttribute(\"data-enhanced\", \"true\");\n });\n return {\n text,\n rootProps: {\n className: \"gridui-text-morph\",\n \"data-debug\": options.debug || undefined,\n },\n textProps: { className: \"gridui-text-morph-text\" },\n layerProps: {\n ref: layerRef,\n className: \"gridui-text-morph-layer\",\n \"aria-hidden\": true as const,\n },\n };\n};\n", "/**\n * @author WMXPY\n * @package GridUI\n * @namespace TextMorph\n * @description Text Morph\n */\n\nimport type { TextMorphOptions } from \"./options\";\nimport { useTextMorph } from \"./use-text-morph\";\nimport { cn } from \"@gridui/style-utils\";\nimport type { ComponentPropsWithRef, FC } from \"react\";\nimport { createElement } from \"react\";\n\nexport type TextMorphProps = Omit<ComponentPropsWithRef<\"span\">, \"children\" | \"dangerouslySetInnerHTML\" | \"onAnimationStart\"> & TextMorphOptions & {\n readonly children: string | number;\n readonly as?: \"span\" | \"div\" | \"p\" | \"h1\" | \"h2\" | \"h3\" | \"h4\" | \"h5\" | \"h6\" | \"strong\" | \"em\";\n};\n\nexport const TextMorph: FC<TextMorphProps> = (props: TextMorphProps) => {\n const { children, as = \"span\", locale, formatOptions, numbers, cursorIndex, disabled, duration, ease, scale, debug,\n onAnimationStart, onAnimationComplete, onAnimationCancel, className, ...restProps } = props;\n const morph = useTextMorph(children, {\n locale,\n formatOptions,\n numbers,\n cursorIndex,\n disabled,\n duration,\n ease,\n scale,\n debug,\n onAnimationStart,\n onAnimationComplete,\n onAnimationCancel,\n });\n return createElement(as, {\n ...restProps,\n ...morph.rootProps,\n className: cn(morph.rootProps.className, className),\n }, (<span\n {...morph.textProps}\n >\n {morph.text}\n </span>), (<span\n {...morph.layerProps}\n />));\n};\n"],
|
|
5
|
+
"mappings": ";AA8BO,IAAM,kBAAkB,CAAC,YAAoC;AAChE,MAAI,QAAQ,aAAa,WAAc,CAAC,OAAO,SAAS,QAAQ,QAAQ,KAAK,QAAQ,WAAW,IAAI;AAChG,UAAM,IAAI,WAAW,yDAAyD;AAAA,EAClF;AACA,MAAI,QAAQ,gBAAgB,WAAc,CAAC,OAAO,UAAU,QAAQ,WAAW,KAAK,QAAQ,cAAc,IAAI;AAC1G,UAAM,IAAI,WAAW,sDAAsD;AAAA,EAC/E;AACA,MAAI,OAAO,QAAQ,SAAS,UAAU;AAClC,UAAM,EAAE,YAAY,KAAK,UAAU,IAAI,OAAO,GAAG,YAAY,KAAM,IAAI,QAAQ;AAC/E,QAAI,CAAC;AAAA,MACD;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACJ,EAAE,MAAM,CAAC,UAAU;AACf,aAAO,OAAO,SAAS,KAAK,KAAK,QAAQ;AAAA,IAC7C,CAAC,KAAK,aAAa,GAAG;AAClB,YAAM,IAAI,WAAW,iFAAiF;AAAA,IAC1G;AAAA,EACJ;AACJ;;;ACnCO,IAAM,eAAe;AAErB,IAAM,cAAc,CAAC,MAAc,QAAiB,UA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AAAA;AAAA,MACA,GAAG,MAAM;AAAA,MAET,gBAAM;AAAA;AAAA,EACX,GAAW;AAAA,IAAC;AAAA;AAAA,MACP,GAAG,MAAM;AAAA;AAAA,EACd,CAAG;AACP;",
|
|
6
|
+
"names": ["old", "current"]
|
|
7
|
+
}
|
package/dist/styles.css
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/*! tailwindcss v4.3.3 | MIT License | https://tailwindcss.com */
|
|
2
|
+
@layer theme, base, components, utilities;
|
|
3
|
+
@layer utilities;
|
|
4
|
+
@layer components {
|
|
5
|
+
.gridui-text-morph {
|
|
6
|
+
display: inline-block;
|
|
7
|
+
white-space: pre;
|
|
8
|
+
}
|
|
9
|
+
.gridui-text-morph-layer {
|
|
10
|
+
display: none;
|
|
11
|
+
position: relative;
|
|
12
|
+
white-space: pre;
|
|
13
|
+
min-height: 1em;
|
|
14
|
+
}
|
|
15
|
+
.gridui-text-morph[data-enhanced] > .gridui-text-morph-layer {
|
|
16
|
+
display: inline-block;
|
|
17
|
+
}
|
|
18
|
+
.gridui-text-morph[data-enhanced] > .gridui-text-morph-text {
|
|
19
|
+
position: absolute;
|
|
20
|
+
width: 1px;
|
|
21
|
+
height: 1px;
|
|
22
|
+
overflow: hidden;
|
|
23
|
+
clip-path: inset(50%);
|
|
24
|
+
user-select: none;
|
|
25
|
+
}
|
|
26
|
+
.gridui-text-morph-segment {
|
|
27
|
+
display: inline-block;
|
|
28
|
+
white-space: pre;
|
|
29
|
+
}
|
|
30
|
+
.gridui-text-morph-segment:is([data-kind="digit"], [data-kind="symbol"]) {
|
|
31
|
+
position: relative;
|
|
32
|
+
overflow: clip;
|
|
33
|
+
}
|
|
34
|
+
.gridui-text-morph-glyph {
|
|
35
|
+
display: inline-block;
|
|
36
|
+
}
|
|
37
|
+
.gridui-text-morph[data-debug] .gridui-text-morph-segment {
|
|
38
|
+
outline: 1px solid currentcolor;
|
|
39
|
+
outline-offset: -1px;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @author WMXPY
|
|
3
|
+
* @package GridUI
|
|
4
|
+
* @namespace TextMorph
|
|
5
|
+
* @description Matching
|
|
6
|
+
*/
|
|
7
|
+
import type { TextSegment } from "./segments";
|
|
8
|
+
/** Keep whole words together before matching remaining graphemes. Each node has one owner. */
|
|
9
|
+
export declare const matchSegments: (previous: readonly TextSegment[], next: readonly TextSegment[], cursorIndex?: number) => Map<number, number>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @author WMXPY
|
|
3
|
+
* @package GridUI
|
|
4
|
+
* @namespace TextMorph
|
|
5
|
+
* @description Options
|
|
6
|
+
*/
|
|
7
|
+
export type TextMorphSpring = {
|
|
8
|
+
readonly stiffness?: number | undefined;
|
|
9
|
+
readonly damping?: number | undefined;
|
|
10
|
+
readonly mass?: number | undefined;
|
|
11
|
+
readonly precision?: number | undefined;
|
|
12
|
+
};
|
|
13
|
+
export type TextMorphOptions = {
|
|
14
|
+
readonly locale?: string | undefined;
|
|
15
|
+
readonly formatOptions?: Intl.NumberFormatOptions | undefined;
|
|
16
|
+
readonly numbers?: boolean | undefined;
|
|
17
|
+
/** UTF-16 caret position after an edit. Disables numeric place matching. */
|
|
18
|
+
readonly cursorIndex?: number | undefined;
|
|
19
|
+
readonly disabled?: boolean | undefined;
|
|
20
|
+
readonly duration?: number | undefined;
|
|
21
|
+
readonly ease?: string | TextMorphSpring | undefined;
|
|
22
|
+
readonly scale?: boolean | undefined;
|
|
23
|
+
readonly debug?: boolean | undefined;
|
|
24
|
+
readonly onAnimationStart?: (() => void) | undefined;
|
|
25
|
+
readonly onAnimationComplete?: (() => void) | undefined;
|
|
26
|
+
readonly onAnimationCancel?: (() => void) | undefined;
|
|
27
|
+
};
|
|
28
|
+
export declare const validateOptions: (options: TextMorphOptions) => void;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @author WMXPY
|
|
3
|
+
* @package GridUI
|
|
4
|
+
* @namespace TextMorph
|
|
5
|
+
* @description Segments
|
|
6
|
+
*/
|
|
7
|
+
export type TextSegment = {
|
|
8
|
+
readonly text: string;
|
|
9
|
+
readonly place?: string;
|
|
10
|
+
readonly kind?: "digit" | "symbol";
|
|
11
|
+
readonly word?: number;
|
|
12
|
+
};
|
|
13
|
+
export declare const MAX_SEGMENTS = 256;
|
|
14
|
+
export declare const segmentText: (text: string, locale?: string, numbers?: boolean) => TextSegment[];
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @author WMXPY
|
|
3
|
+
* @package GridUI
|
|
4
|
+
* @namespace TextMorph
|
|
5
|
+
* @description Text Morph
|
|
6
|
+
*/
|
|
7
|
+
import type { TextMorphOptions } from "./options";
|
|
8
|
+
import type { ComponentPropsWithRef, FC } from "react";
|
|
9
|
+
export type TextMorphProps = Omit<ComponentPropsWithRef<"span">, "children" | "dangerouslySetInnerHTML" | "onAnimationStart"> & TextMorphOptions & {
|
|
10
|
+
readonly children: string | number;
|
|
11
|
+
readonly as?: "span" | "div" | "p" | "h1" | "h2" | "h3" | "h4" | "h5" | "h6" | "strong" | "em";
|
|
12
|
+
};
|
|
13
|
+
export declare const TextMorph: FC<TextMorphProps>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @author WMXPY
|
|
3
|
+
* @package GridUI
|
|
4
|
+
* @namespace TextMorph
|
|
5
|
+
* @description Timing
|
|
6
|
+
*/
|
|
7
|
+
import type { TextMorphSpring } from "./options";
|
|
8
|
+
export declare const milliseconds: (value: string, fallback?: number) => number;
|
|
9
|
+
/** Analytic damped oscillator; bounded samples avoid a per-character animation loop. */
|
|
10
|
+
export declare const springTiming: (spring: TextMorphSpring) => {
|
|
11
|
+
duration: number;
|
|
12
|
+
easing: string;
|
|
13
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @author WMXPY
|
|
3
|
+
* @package GridUI
|
|
4
|
+
* @namespace TextMorph
|
|
5
|
+
* @description Transition
|
|
6
|
+
*/
|
|
7
|
+
import type { TextMorphOptions } from "./options";
|
|
8
|
+
export type TransitionOptions = Omit<TextMorphOptions, "formatOptions">;
|
|
9
|
+
export declare const createTextTransition: (layer: HTMLSpanElement) => {
|
|
10
|
+
update: (text: string, options: TransitionOptions) => void;
|
|
11
|
+
destroy: () => void;
|
|
12
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @author WMXPY
|
|
3
|
+
* @package GridUI
|
|
4
|
+
* @namespace TextMorph
|
|
5
|
+
* @description Use Text Morph
|
|
6
|
+
*/
|
|
7
|
+
import type { TextMorphOptions } from "./options";
|
|
8
|
+
/** Bind the returned props to a root, semantic text, and empty visual span. */
|
|
9
|
+
export declare const useTextMorph: (value: string | number, options?: TextMorphOptions) => {
|
|
10
|
+
text: string;
|
|
11
|
+
rootProps: {
|
|
12
|
+
className: string;
|
|
13
|
+
"data-debug": true | undefined;
|
|
14
|
+
};
|
|
15
|
+
textProps: {
|
|
16
|
+
className: string;
|
|
17
|
+
};
|
|
18
|
+
layerProps: {
|
|
19
|
+
ref: (layer: HTMLSpanElement | null) => void;
|
|
20
|
+
className: string;
|
|
21
|
+
"aria-hidden": true;
|
|
22
|
+
};
|
|
23
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,51 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gridui/text-morph",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "GridUI React text and number transitions",
|
|
5
|
+
"license": "UNLICENSED",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist",
|
|
9
|
+
"README.md"
|
|
10
|
+
],
|
|
11
|
+
"sideEffects": [
|
|
12
|
+
"**/*.css"
|
|
13
|
+
],
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"import": "./dist/index.js"
|
|
18
|
+
},
|
|
19
|
+
"./styles.css": "./dist/styles.css"
|
|
20
|
+
},
|
|
21
|
+
"publishConfig": {
|
|
22
|
+
"access": "public"
|
|
23
|
+
},
|
|
24
|
+
"peerDependencies": {
|
|
25
|
+
"react": "^19.2.0",
|
|
26
|
+
"react-dom": "^19.2.0"
|
|
27
|
+
},
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@gridui/style-utils": "^2.2.0",
|
|
30
|
+
"@gridui/theme": "^2.5.0"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@gridui-internal/configuration": "0.0.0-internal",
|
|
34
|
+
"@jest/globals": "30.5.2",
|
|
35
|
+
"@storybook/react-vite": "10.6.5",
|
|
36
|
+
"@types/jest": "30.0.0",
|
|
37
|
+
"@types/node": "26.6.6",
|
|
38
|
+
"@types/react": "19.3.0",
|
|
39
|
+
"@types/react-dom": "19.3.0",
|
|
40
|
+
"jest": "30.5.2",
|
|
41
|
+
"react": "19.3.1",
|
|
42
|
+
"react-dom": "19.3.1",
|
|
43
|
+
"typescript": "6.0.3"
|
|
44
|
+
},
|
|
45
|
+
"scripts": {
|
|
46
|
+
"build": "node ../../scripts/compilation/package.ts",
|
|
47
|
+
"compile": "tsc --project tsconfig.json",
|
|
48
|
+
"test": "jest",
|
|
49
|
+
"coverage": "jest --coverage"
|
|
50
|
+
}
|
|
6
51
|
}
|