@juspay/svelte-ui-components 4.55.1 → 4.55.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.
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
import {
|
|
2
|
+
import { onDestroy, untrack } from 'svelte';
|
|
3
3
|
import { prefersReducedMotion } from '../utils';
|
|
4
4
|
import type { TypewriterTextProperties, TypewriterCharacterDelayRange } from './properties';
|
|
5
5
|
|
|
@@ -38,6 +38,7 @@
|
|
|
38
38
|
let displayedText = $state('');
|
|
39
39
|
let currentIndex = $state(0);
|
|
40
40
|
let timeoutId = $state<ReturnType<typeof setTimeout> | null>(null);
|
|
41
|
+
let destroyed = false;
|
|
41
42
|
|
|
42
43
|
// Where typing left off, so newly streamed-in text continues rather than restarts.
|
|
43
44
|
let previousTextLength = $state(0);
|
|
@@ -114,6 +115,10 @@
|
|
|
114
115
|
};
|
|
115
116
|
|
|
116
117
|
const typeNextCharacter = (): void => {
|
|
118
|
+
if (destroyed) {
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
timeoutId = null;
|
|
117
122
|
// Typing IS the animation here, so a reduced-motion request has to suppress the
|
|
118
123
|
// reveal itself rather than a transition around it: disclose the text instead.
|
|
119
124
|
// `ChatController` already bypasses its own drain loop on this setting, and the two
|
|
@@ -135,6 +140,10 @@
|
|
|
135
140
|
displayedText = text.substring(0, currentIndex + 1);
|
|
136
141
|
currentIndex++;
|
|
137
142
|
onprogress?.({ index: currentIndex, total: text.length, displayedText });
|
|
143
|
+
// A progress callback may synchronously remove its own component.
|
|
144
|
+
if (destroyed) {
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
138
147
|
timeoutId = setTimeout(
|
|
139
148
|
typeNextCharacter,
|
|
140
149
|
resolveTypingDelay(revealedCharacter, revealedCharacterIndex)
|
|
@@ -185,16 +194,11 @@
|
|
|
185
194
|
}
|
|
186
195
|
});
|
|
187
196
|
|
|
188
|
-
onMount(() => {
|
|
189
|
-
if (text.length > 0) {
|
|
190
|
-
previousTextLength = text.length;
|
|
191
|
-
typeNextCharacter();
|
|
192
|
-
}
|
|
193
|
-
});
|
|
194
|
-
|
|
195
197
|
onDestroy(() => {
|
|
198
|
+
destroyed = true;
|
|
196
199
|
if (timeoutId !== null) {
|
|
197
200
|
clearTimeout(timeoutId);
|
|
201
|
+
timeoutId = null;
|
|
198
202
|
}
|
|
199
203
|
});
|
|
200
204
|
</script>
|
package/dist-wc/index.js
CHANGED
|
@@ -53441,54 +53441,55 @@ function TypewriterText(e, t) {
|
|
|
53441
53441
|
function k() {
|
|
53442
53442
|
return C ??= Promise.resolve().then(() => (init_markdown(), markdown_exports)), C;
|
|
53443
53443
|
}
|
|
53444
|
-
let R = /* @__PURE__ */ user_derived(() => o() === !0 ? k() : null), te = /* @__PURE__ */ user_derived(() => typeof s() == "object" && s() !== null && !Array.isArray(s()) ? s() : {}), ne = /* @__PURE__ */ state(""), G = /* @__PURE__ */ state(0), re = /* @__PURE__ */ state(null), be = /* @__PURE__ */ state(0),
|
|
53444
|
+
let R = /* @__PURE__ */ user_derived(() => o() === !0 ? k() : null), te = /* @__PURE__ */ user_derived(() => typeof s() == "object" && s() !== null && !Array.isArray(s()) ? s() : {}), ne = /* @__PURE__ */ state(""), G = /* @__PURE__ */ state(0), re = /* @__PURE__ */ state(null), be = !1, Me = /* @__PURE__ */ state(0), Re = /* @__PURE__ */ state(0), Ue = new Set([" ", "\n"]), it = (e) => {
|
|
53445
53445
|
let t = 0;
|
|
53446
|
-
for (let n of e)
|
|
53446
|
+
for (let n of e) Ue.has(n) && (t += 1);
|
|
53447
53447
|
return t;
|
|
53448
|
-
},
|
|
53448
|
+
}, at = new Set([
|
|
53449
53449
|
",",
|
|
53450
53450
|
".",
|
|
53451
53451
|
"?",
|
|
53452
53452
|
"!"
|
|
53453
|
-
]),
|
|
53453
|
+
]), ot = /\d/, ct = (e) => e.min + Math.random() * (e.max - e.min), lt = (e, t) => typeof u() == "function" ? u()({
|
|
53454
53454
|
character: e,
|
|
53455
53455
|
index: t,
|
|
53456
|
-
wordCount: get(
|
|
53457
|
-
}) : l() ?
|
|
53456
|
+
wordCount: get(Re)
|
|
53457
|
+
}) : l() ? ot.test(e) && l().digit ? ct(l().digit) : Ue.has(e) && l().whitespace ? ct(l().whitespace) : at.has(e) && l().punctuation ? ct(l().punctuation) : l().default ? ct(l().default) : i() : i(), ut = () => {
|
|
53458
53458
|
get(re) !== null && (clearTimeout(get(re)), set(re, null));
|
|
53459
53459
|
let e = get(G) < n().length;
|
|
53460
|
-
set(ne, n(), !0), set(G, n().length, !0), set(
|
|
53460
|
+
set(ne, n(), !0), set(G, n().length, !0), set(Re, it(n()), !0), e && f()?.({
|
|
53461
53461
|
index: get(G),
|
|
53462
53462
|
total: n().length,
|
|
53463
53463
|
displayedText: get(ne)
|
|
53464
53464
|
});
|
|
53465
|
-
},
|
|
53466
|
-
if (
|
|
53467
|
-
|
|
53468
|
-
|
|
53469
|
-
|
|
53470
|
-
|
|
53471
|
-
|
|
53472
|
-
|
|
53473
|
-
|
|
53474
|
-
|
|
53475
|
-
|
|
53476
|
-
|
|
53465
|
+
}, dt = () => {
|
|
53466
|
+
if (!be) {
|
|
53467
|
+
if (set(re, null), prefersReducedMotion()) {
|
|
53468
|
+
ut();
|
|
53469
|
+
return;
|
|
53470
|
+
}
|
|
53471
|
+
if (get(G) < n().length) {
|
|
53472
|
+
let e = n()[get(G)], t = get(G);
|
|
53473
|
+
if (Ue.has(e) && update(Re), set(ne, n().substring(0, get(G) + 1), !0), update(G), f()?.({
|
|
53474
|
+
index: get(G),
|
|
53475
|
+
total: n().length,
|
|
53476
|
+
displayedText: get(ne)
|
|
53477
|
+
}), be) return;
|
|
53478
|
+
set(re, setTimeout(dt, lt(e, t)), !0);
|
|
53479
|
+
}
|
|
53477
53480
|
}
|
|
53478
53481
|
};
|
|
53479
53482
|
user_effect(() => {
|
|
53480
53483
|
let e = n();
|
|
53481
53484
|
untrack(() => {
|
|
53482
|
-
e.length >= get(
|
|
53485
|
+
e.length >= get(Me) && e.startsWith(get(ne)) || (get(re) !== null && (clearTimeout(get(re)), set(re, null)), set(ne, ""), set(G, 0), set(Me, 0), set(Re, 0)), e.length > 0 && e.length > get(Me) && (get(G) >= get(Me) && (get(re) !== null && (clearTimeout(get(re)), set(re, null)), dt()), set(Me, e.length, !0));
|
|
53483
53486
|
});
|
|
53484
53487
|
}), user_effect(() => {
|
|
53485
|
-
!a() && n().length > 0 &&
|
|
53486
|
-
}), onMount(() => {
|
|
53487
|
-
n().length > 0 && (set(be, n().length, !0), ut());
|
|
53488
|
+
!a() && n().length > 0 && ut();
|
|
53488
53489
|
}), onDestroy(() => {
|
|
53489
|
-
get(re) !== null && clearTimeout(get(re));
|
|
53490
|
+
be = !0, get(re) !== null && (clearTimeout(get(re)), set(re, null));
|
|
53490
53491
|
});
|
|
53491
|
-
var
|
|
53492
|
+
var ft = {
|
|
53492
53493
|
get text() {
|
|
53493
53494
|
return n();
|
|
53494
53495
|
},
|
|
@@ -53561,9 +53562,9 @@ function TypewriterText(e, t) {
|
|
|
53561
53562
|
set classes(e) {
|
|
53562
53563
|
S(e), flushSync();
|
|
53563
53564
|
}
|
|
53564
|
-
},
|
|
53565
|
-
let
|
|
53566
|
-
var
|
|
53565
|
+
}, pt = root$16();
|
|
53566
|
+
let mt;
|
|
53567
|
+
var ht = child(pt), gt = (e) => {
|
|
53567
53568
|
var t = comment();
|
|
53568
53569
|
await_block(first_child(t), () => get(R), (e) => {
|
|
53569
53570
|
var t = text();
|
|
@@ -53583,10 +53584,10 @@ function TypewriterText(e, t) {
|
|
|
53583
53584
|
var t = text();
|
|
53584
53585
|
template_effect(() => set_text(t, get(ne))), append(e, t);
|
|
53585
53586
|
}), append(e, t);
|
|
53586
|
-
},
|
|
53587
|
+
}, _t = (e) => {
|
|
53587
53588
|
var t = comment();
|
|
53588
53589
|
html(first_child(t), () => c()(get(ne))), append(e, t);
|
|
53589
|
-
},
|
|
53590
|
+
}, vt = (e) => {
|
|
53590
53591
|
var t = comment();
|
|
53591
53592
|
each(first_child(t), 17, () => get(ne).split(""), index, (e, t, n) => {
|
|
53592
53593
|
var i = comment();
|
|
@@ -53595,15 +53596,15 @@ function TypewriterText(e, t) {
|
|
|
53595
53596
|
index: n
|
|
53596
53597
|
})), append(e, i);
|
|
53597
53598
|
}), append(e, t);
|
|
53598
|
-
},
|
|
53599
|
+
}, yt = (e) => {
|
|
53599
53600
|
var t = text();
|
|
53600
53601
|
template_effect(() => set_text(t, get(ne))), append(e, t);
|
|
53601
53602
|
};
|
|
53602
|
-
return if_block(
|
|
53603
|
-
o() === !0 ? e(
|
|
53604
|
-
}), reset(
|
|
53605
|
-
|
|
53606
|
-
}), append(e,
|
|
53603
|
+
return if_block(ht, (e) => {
|
|
53604
|
+
o() === !0 ? e(gt) : typeof c() == "function" ? e(_t, 1) : p() ? e(vt, 2) : e(yt, -1);
|
|
53605
|
+
}), reset(pt), template_effect(() => {
|
|
53606
|
+
mt = set_class(pt, 1, `typewriter-text ${S() ?? "" ?? ""}`, "svelte-12jnsxo", mt, { plain: o() !== !0 && typeof c() != "function" }), set_attribute(pt, "data-pw", typeof h() == "string" ? h() : null), set_attribute(pt, "testid", typeof h() == "string" ? h() : null);
|
|
53607
|
+
}), append(e, pt), pop(ft);
|
|
53607
53608
|
}
|
|
53608
53609
|
create_custom_element(TypewriterText, {
|
|
53609
53610
|
text: {},
|