@juspay/svelte-ui-components 4.55.0 → 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 { onMount, onDestroy, untrack } from 'svelte';
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>
@@ -43,7 +43,8 @@ export declare function getFocusTrapBoundary(container: ParentNode | null): Focu
43
43
  * element focus should move to, or null when the default browser behavior
44
44
  * (move to the next/previous focusable element) should be left alone.
45
45
  *
46
- * Wrapping only happens exactly at an edge: focus sits on the last focusable
46
+ * An empty panel keeps focus on itself when it is already the active element.
47
+ * Otherwise wrapping only happens exactly at an edge: focus sits on the last focusable
47
48
  * element and Tab (not Shift+Tab) was pressed, or focus sits on the first and
48
49
  * Shift+Tab was pressed. Anywhere else in the middle of the tab order, the
49
50
  * browser's own handling is correct and this returns null.
@@ -95,7 +95,8 @@ export function getFocusTrapBoundary(container) {
95
95
  * element focus should move to, or null when the default browser behavior
96
96
  * (move to the next/previous focusable element) should be left alone.
97
97
  *
98
- * Wrapping only happens exactly at an edge: focus sits on the last focusable
98
+ * An empty panel keeps focus on itself when it is already the active element.
99
+ * Otherwise wrapping only happens exactly at an edge: focus sits on the last focusable
99
100
  * element and Tab (not Shift+Tab) was pressed, or focus sits on the first and
100
101
  * Shift+Tab was pressed. Anywhere else in the middle of the tab order, the
101
102
  * browser's own handling is correct and this returns null.
@@ -103,7 +104,14 @@ export function getFocusTrapBoundary(container) {
103
104
  export function focusTrapTabTarget(params) {
104
105
  const { first, last } = getFocusTrapBoundary(params.container);
105
106
  if (first === null || last === null) {
106
- return null;
107
+ // focusEntryPoint focuses the panel itself when it has no controls. Keep
108
+ // that panel, but never take focus from another (possibly nested) layer.
109
+ const active = params.activeElement;
110
+ return active === params.container &&
111
+ typeof HTMLElement === 'function' &&
112
+ active instanceof HTMLElement
113
+ ? active
114
+ : null;
107
115
  }
108
116
  const edge = params.shiftKey ? first : last;
109
117
  if (params.activeElement !== edge) {
package/dist-wc/index.js CHANGED
@@ -7158,7 +7158,10 @@ function getFocusTrapBoundary(e) {
7158
7158
  }
7159
7159
  function focusTrapTabTarget(e) {
7160
7160
  let { first: t, last: n } = getFocusTrapBoundary(e.container);
7161
- if (t === null || n === null) return null;
7161
+ if (t === null || n === null) {
7162
+ let t = e.activeElement;
7163
+ return t === e.container && typeof HTMLElement == "function" && t instanceof HTMLElement ? t : null;
7164
+ }
7162
7165
  let i = e.shiftKey ? t : n;
7163
7166
  return e.activeElement === i ? e.shiftKey ? n : t : null;
7164
7167
  }
@@ -53438,54 +53441,55 @@ function TypewriterText(e, t) {
53438
53441
  function k() {
53439
53442
  return C ??= Promise.resolve().then(() => (init_markdown(), markdown_exports)), C;
53440
53443
  }
53441
- 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), Me = /* @__PURE__ */ state(0), Re = new Set([" ", "\n"]), Ue = (e) => {
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) => {
53442
53445
  let t = 0;
53443
- for (let n of e) Re.has(n) && (t += 1);
53446
+ for (let n of e) Ue.has(n) && (t += 1);
53444
53447
  return t;
53445
- }, it = new Set([
53448
+ }, at = new Set([
53446
53449
  ",",
53447
53450
  ".",
53448
53451
  "?",
53449
53452
  "!"
53450
- ]), at = /\d/, ot = (e) => e.min + Math.random() * (e.max - e.min), ct = (e, t) => typeof u() == "function" ? u()({
53453
+ ]), ot = /\d/, ct = (e) => e.min + Math.random() * (e.max - e.min), lt = (e, t) => typeof u() == "function" ? u()({
53451
53454
  character: e,
53452
53455
  index: t,
53453
- wordCount: get(Me)
53454
- }) : l() ? at.test(e) && l().digit ? ot(l().digit) : Re.has(e) && l().whitespace ? ot(l().whitespace) : it.has(e) && l().punctuation ? ot(l().punctuation) : l().default ? ot(l().default) : i() : i(), lt = () => {
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 = () => {
53455
53458
  get(re) !== null && (clearTimeout(get(re)), set(re, null));
53456
53459
  let e = get(G) < n().length;
53457
- set(ne, n(), !0), set(G, n().length, !0), set(Me, Ue(n()), !0), e && f()?.({
53460
+ set(ne, n(), !0), set(G, n().length, !0), set(Re, it(n()), !0), e && f()?.({
53458
53461
  index: get(G),
53459
53462
  total: n().length,
53460
53463
  displayedText: get(ne)
53461
53464
  });
53462
- }, ut = () => {
53463
- if (prefersReducedMotion()) {
53464
- lt();
53465
- return;
53466
- }
53467
- if (get(G) < n().length) {
53468
- let e = n()[get(G)], t = get(G);
53469
- Re.has(e) && update(Me), set(ne, n().substring(0, get(G) + 1), !0), update(G), f()?.({
53470
- index: get(G),
53471
- total: n().length,
53472
- displayedText: get(ne)
53473
- }), set(re, setTimeout(ut, ct(e, t)), !0);
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
+ }
53474
53480
  }
53475
53481
  };
53476
53482
  user_effect(() => {
53477
53483
  let e = n();
53478
53484
  untrack(() => {
53479
- e.length >= get(be) && e.startsWith(get(ne)) || (get(re) !== null && (clearTimeout(get(re)), set(re, null)), set(ne, ""), set(G, 0), set(be, 0), set(Me, 0)), e.length > 0 && e.length > get(be) && (get(G) >= get(be) && (get(re) !== null && (clearTimeout(get(re)), set(re, null)), ut()), set(be, e.length, !0));
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));
53480
53486
  });
53481
53487
  }), user_effect(() => {
53482
- !a() && n().length > 0 && lt();
53483
- }), onMount(() => {
53484
- n().length > 0 && (set(be, n().length, !0), ut());
53488
+ !a() && n().length > 0 && ut();
53485
53489
  }), onDestroy(() => {
53486
- get(re) !== null && clearTimeout(get(re));
53490
+ be = !0, get(re) !== null && (clearTimeout(get(re)), set(re, null));
53487
53491
  });
53488
- var dt = {
53492
+ var ft = {
53489
53493
  get text() {
53490
53494
  return n();
53491
53495
  },
@@ -53558,9 +53562,9 @@ function TypewriterText(e, t) {
53558
53562
  set classes(e) {
53559
53563
  S(e), flushSync();
53560
53564
  }
53561
- }, ft = root$16();
53562
- let pt;
53563
- var mt = child(ft), ht = (e) => {
53565
+ }, pt = root$16();
53566
+ let mt;
53567
+ var ht = child(pt), gt = (e) => {
53564
53568
  var t = comment();
53565
53569
  await_block(first_child(t), () => get(R), (e) => {
53566
53570
  var t = text();
@@ -53580,10 +53584,10 @@ function TypewriterText(e, t) {
53580
53584
  var t = text();
53581
53585
  template_effect(() => set_text(t, get(ne))), append(e, t);
53582
53586
  }), append(e, t);
53583
- }, gt = (e) => {
53587
+ }, _t = (e) => {
53584
53588
  var t = comment();
53585
53589
  html(first_child(t), () => c()(get(ne))), append(e, t);
53586
- }, _t = (e) => {
53590
+ }, vt = (e) => {
53587
53591
  var t = comment();
53588
53592
  each(first_child(t), 17, () => get(ne).split(""), index, (e, t, n) => {
53589
53593
  var i = comment();
@@ -53592,15 +53596,15 @@ function TypewriterText(e, t) {
53592
53596
  index: n
53593
53597
  })), append(e, i);
53594
53598
  }), append(e, t);
53595
- }, vt = (e) => {
53599
+ }, yt = (e) => {
53596
53600
  var t = text();
53597
53601
  template_effect(() => set_text(t, get(ne))), append(e, t);
53598
53602
  };
53599
- return if_block(mt, (e) => {
53600
- o() === !0 ? e(ht) : typeof c() == "function" ? e(gt, 1) : p() ? e(_t, 2) : e(vt, -1);
53601
- }), reset(ft), template_effect(() => {
53602
- pt = set_class(ft, 1, `typewriter-text ${S() ?? "" ?? ""}`, "svelte-12jnsxo", pt, { plain: o() !== !0 && typeof c() != "function" }), set_attribute(ft, "data-pw", typeof h() == "string" ? h() : null), set_attribute(ft, "testid", typeof h() == "string" ? h() : null);
53603
- }), append(e, ft), pop(dt);
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);
53604
53608
  }
53605
53609
  create_custom_element(TypewriterText, {
53606
53610
  text: {},
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@juspay/svelte-ui-components",
3
- "version": "4.55.0",
3
+ "version": "4.55.2",
4
4
  "description": "A themeable Svelte 5 UI component library with CSS custom property driven styling",
5
5
  "keywords": [
6
6
  "svelte",