@rcarls/rc-common 0.6.0 → 0.7.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.
Files changed (73) hide show
  1. package/CHANGELOG.md +295 -0
  2. package/README.md +148 -72
  3. package/dist/modules/ActiveDescendantController.js +89 -0
  4. package/dist/modules/AnchorController.js +317 -0
  5. package/dist/modules/ControllerEffects.js +60 -0
  6. package/dist/modules/DragController.js +128 -0
  7. package/dist/modules/DragGestureController.js +174 -0
  8. package/dist/modules/FlowController.js +35 -0
  9. package/dist/modules/ItemsCollectionController.js +233 -0
  10. package/dist/modules/KeyboardInteractionDirective.js +39 -0
  11. package/dist/modules/KeyboardNavigationDirective.js +88 -0
  12. package/dist/modules/LiveAnnouncer.js +36 -0
  13. package/dist/modules/MutationObserverController.js +30 -0
  14. package/dist/modules/NavigationIndicatorController.js +81 -0
  15. package/dist/modules/PopoverController.js +44 -0
  16. package/dist/modules/RafScheduler.js +83 -0
  17. package/dist/modules/ReorderController.js +361 -0
  18. package/dist/modules/ResizeController.js +425 -0
  19. package/dist/modules/RovingTabIndexMixin.js +87 -0
  20. package/dist/modules/ScrollObserverController.js +78 -0
  21. package/dist/modules/TypeaheadController.js +59 -0
  22. package/dist/modules/anchorPlacement.js +13 -0
  23. package/dist/modules/clickDelegate.js +31 -0
  24. package/dist/modules/cssText.js +6 -0
  25. package/dist/modules/cssTime.js +11 -0
  26. package/dist/modules/cssZoom.js +16 -0
  27. package/dist/modules/findNearestScrollAncestor.js +22 -0
  28. package/dist/modules/flow.js +94 -0
  29. package/dist/modules/isFocusable.js +6 -0
  30. package/dist/modules/localeFormat.js +38 -0
  31. package/dist/modules/messages.js +77 -0
  32. package/dist/modules/nativeChild.js +37 -0
  33. package/dist/modules/observeLocale.js +70 -0
  34. package/dist/modules/sliderUtils.js +14 -0
  35. package/dist/modules/snapUtils.js +25 -0
  36. package/dist/modules/softKeyboard.js +72 -0
  37. package/dist/modules/visualViewport.js +14 -0
  38. package/dist/rc-common.js +99 -1711
  39. package/dist/rc-common.umd.cjs +10 -26
  40. package/dist/types/AnchorController.d.ts +45 -22
  41. package/dist/types/ControllerEffects.d.ts +15 -0
  42. package/dist/types/DragController.d.ts +13 -0
  43. package/dist/types/DragGestureController.d.ts +31 -7
  44. package/dist/types/FlowController.d.ts +31 -0
  45. package/dist/types/ItemsCollectionController.d.ts +3 -2
  46. package/dist/types/KeyboardInteractionDirective.d.ts +1 -2
  47. package/dist/types/KeyboardNavigationDirective.d.ts +16 -7
  48. package/dist/types/LiveAnnouncer.d.ts +22 -0
  49. package/dist/types/MutationObserverController.d.ts +0 -1
  50. package/dist/types/NavigationIndicatorController.d.ts +1 -1
  51. package/dist/types/PopoverController.d.ts +21 -0
  52. package/dist/types/RafScheduler.d.ts +36 -1
  53. package/dist/types/ReorderController.d.ts +131 -0
  54. package/dist/types/ResizeController.d.ts +46 -0
  55. package/dist/types/ScrollObserverController.d.ts +13 -2
  56. package/dist/types/TypeaheadController.d.ts +8 -2
  57. package/dist/types/anchorPlacement.d.ts +24 -0
  58. package/dist/types/clickDelegate.d.ts +9 -56
  59. package/dist/types/cssText.d.ts +17 -0
  60. package/dist/types/cssTime.d.ts +14 -0
  61. package/dist/types/cssZoom.d.ts +12 -0
  62. package/dist/types/findNearestScrollAncestor.d.ts +3 -3
  63. package/dist/types/flow.d.ts +121 -0
  64. package/dist/types/index.d.ts +13 -1
  65. package/dist/types/localeFormat.d.ts +4 -0
  66. package/dist/types/messages.d.ts +105 -0
  67. package/dist/types/nativeChild.d.ts +0 -3
  68. package/dist/types/observeLocale.d.ts +23 -0
  69. package/dist/types/softKeyboard.d.ts +79 -0
  70. package/dist/types/visualViewport.d.ts +21 -0
  71. package/package.json +1 -4
  72. package/dist/css-anchor-positioning-fn-hFYJeBk4.js +0 -6371
  73. package/dist/types/MouseMoveDirective.d.ts +0 -42
@@ -0,0 +1,31 @@
1
+ const r = 'a[href], button, input, select, textarea, summary, [role="button"], [role="link"], [contenteditable]:not([contenteditable="false"]), [tabindex]:not([tabindex="-1"])';
2
+ function c(o, n, i) {
3
+ for (const e of o.composedPath()) {
4
+ if (e === n)
5
+ return !1;
6
+ if (e instanceof Element && e.matches(i))
7
+ return !0;
8
+ }
9
+ return !1;
10
+ }
11
+ class l {
12
+ constructor(n, i) {
13
+ this._handleClick = (e) => {
14
+ const s = this._options.target(), t = e;
15
+ !s || this._options.disabled?.() || t.defaultPrevented || t.button !== 0 || t.altKey || t.ctrlKey || t.metaKey || t.shiftKey || c(
16
+ t,
17
+ this._host,
18
+ this._options.interactiveSelector ?? r
19
+ ) || (t.preventDefault(), s.click());
20
+ }, this._host = n, this._options = i, n.addController(this);
21
+ }
22
+ hostConnected() {
23
+ this._host.addEventListener("click", this._handleClick);
24
+ }
25
+ hostDisconnected() {
26
+ this._host.removeEventListener("click", this._handleClick);
27
+ }
28
+ }
29
+ export {
30
+ l as ClickDelegateController
31
+ };
@@ -0,0 +1,6 @@
1
+ function u(e, ...r) {
2
+ return e.reduce((t, n, c) => t + String(r[c - 1]) + n);
3
+ }
4
+ export {
5
+ u as cssText
6
+ };
@@ -0,0 +1,11 @@
1
+ const o = /^([+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?)(ms|s)?$/i;
2
+ function r(t) {
3
+ const s = o.exec(t.trim());
4
+ if (!s)
5
+ return;
6
+ const [, i, n] = s, e = Number(i) * (n?.toLowerCase() === "s" ? 1e3 : 1);
7
+ return Number.isFinite(e) && e >= 0 ? e : void 0;
8
+ }
9
+ export {
10
+ r as parseCssTime
11
+ };
@@ -0,0 +1,16 @@
1
+ function i(r) {
2
+ const t = r.currentCSSZoom;
3
+ if (t && Number.isFinite(t))
4
+ return t;
5
+ let n = 1, o = r;
6
+ for (; o; ) {
7
+ const e = Number.parseFloat(getComputedStyle(o).zoom);
8
+ Number.isFinite(e) && e > 0 && (n *= e);
9
+ const u = o.getRootNode();
10
+ o = o.parentElement ?? (u instanceof ShadowRoot ? u.host : null);
11
+ }
12
+ return n;
13
+ }
14
+ export {
15
+ i as cssZoom
16
+ };
@@ -0,0 +1,22 @@
1
+ function l(t) {
2
+ const o = t.ownerDocument;
3
+ let e = n(t);
4
+ for (; e && e !== o.documentElement; ) {
5
+ const { overflow: r, overflowY: c } = getComputedStyle(e);
6
+ if (/auto|scroll/.test(c) || /auto|scroll/.test(r))
7
+ return e;
8
+ e = n(e);
9
+ }
10
+ return o.scrollingElement ?? o.documentElement;
11
+ }
12
+ function n(t) {
13
+ if (t.assignedSlot)
14
+ return t.assignedSlot;
15
+ if (t.parentElement)
16
+ return t.parentElement;
17
+ const o = t.getRootNode();
18
+ return o instanceof ShadowRoot ? o.host : null;
19
+ }
20
+ export {
21
+ l as findNearestScrollAncestor
22
+ };
@@ -0,0 +1,94 @@
1
+ const x = Object.freeze({
2
+ inline: "x",
3
+ block: "y",
4
+ inlineReversed: !1,
5
+ blockReversed: !1,
6
+ rtl: !1
7
+ });
8
+ function R(e) {
9
+ const n = getComputedStyle(e), i = n.direction === "rtl";
10
+ switch (n.writingMode) {
11
+ case "vertical-rl":
12
+ case "sideways-rl":
13
+ return { inline: "y", block: "x", inlineReversed: i, blockReversed: !0, rtl: i };
14
+ case "vertical-lr":
15
+ return { inline: "y", block: "x", inlineReversed: i, blockReversed: !1, rtl: i };
16
+ case "sideways-lr":
17
+ return { inline: "y", block: "x", inlineReversed: !i, blockReversed: !1, rtl: i };
18
+ default:
19
+ return { inline: "x", block: "y", inlineReversed: i, blockReversed: !1, rtl: i };
20
+ }
21
+ }
22
+ function t(e, n) {
23
+ return e === "inline" ? n.inline : n.block;
24
+ }
25
+ function s(e, n) {
26
+ return e === "inline" ? n.inlineReversed : n.blockReversed;
27
+ }
28
+ function u(e, n) {
29
+ return n.inline === e ? n.inlineReversed : n.blockReversed;
30
+ }
31
+ function b(e, n, i) {
32
+ const r = t(n, i) === "x" ? e.scrollLeft : e.scrollTop;
33
+ return s(n, i) ? Math.abs(r) : r;
34
+ }
35
+ function k(e, n, i, r, l = "auto") {
36
+ const o = s(n, r) ? -i : i;
37
+ t(n, r) === "x" ? e.scrollTo({ left: o, behavior: l }) : e.scrollTo({ top: o, behavior: l });
38
+ }
39
+ function h(e, n, i) {
40
+ return t(n, i) === "x" ? e.clientWidth : e.clientHeight;
41
+ }
42
+ function y(e, n, i) {
43
+ return t(n, i) === "x" ? e.scrollWidth : e.scrollHeight;
44
+ }
45
+ function d(e, n, i, r) {
46
+ return i === "x" ? r ? n.right - e.right : e.left - n.left : r ? n.bottom - e.bottom : e.top - n.top;
47
+ }
48
+ function f(e, n, i) {
49
+ return {
50
+ inlineStart: d(e, n, i.inline, i.inlineReversed),
51
+ blockStart: d(e, n, i.block, i.blockReversed),
52
+ inlineSize: i.inline === "x" ? e.width : e.height,
53
+ blockSize: i.block === "x" ? e.width : e.height
54
+ };
55
+ }
56
+ function p(e, n) {
57
+ const i = n.inlineReversed ? -e.inline : e.inline, r = n.blockReversed ? -e.block : e.block;
58
+ return n.inline === "x" ? { x: i, y: r } : { x: r, y: i };
59
+ }
60
+ function g(e, n, i) {
61
+ const r = t(n, i) === "x" ? e.dx : e.dy;
62
+ return s(n, i) ? -r : r;
63
+ }
64
+ function v(e, n) {
65
+ const i = u("x", n), r = u("y", n), l = i ? "ArrowLeft" : "ArrowRight", o = i ? "ArrowRight" : "ArrowLeft", c = r ? "ArrowUp" : "ArrowDown", a = r ? "ArrowDown" : "ArrowUp";
66
+ return e === "horizontal" ? { next: l, prev: o, openFirst: c, openLast: a } : { next: c, prev: a, openFirst: l, openLast: o };
67
+ }
68
+ function z(e) {
69
+ return v(e.inline === "x" ? "horizontal" : "vertical", e);
70
+ }
71
+ function A(e, n) {
72
+ return t(e === "horizontal" ? "inline" : "block", n) === "x" ? "horizontal" : "vertical";
73
+ }
74
+ function O(e, n) {
75
+ return e === "horizontal" == (n.inline === "x") ? "horizontal" : "vertical";
76
+ }
77
+ export {
78
+ x as HORIZONTAL_LTR_FLOW,
79
+ v as arrowKeys,
80
+ h as clientSize,
81
+ b as getScrollOffset,
82
+ z as inlineArrowKeys,
83
+ u as isPhysicalReversed,
84
+ s as isReversed,
85
+ O as layoutOrientation,
86
+ g as logicalDelta,
87
+ f as logicalRect,
88
+ t as physicalAxis,
89
+ p as physicalOffset,
90
+ A as renderedOrientation,
91
+ R as resolveFlow,
92
+ y as scrollSize,
93
+ k as setScrollOffset
94
+ };
@@ -0,0 +1,6 @@
1
+ function e(t) {
2
+ return t == null || t.hasAttribute("disabled") ? !1 : !!((t instanceof HTMLAnchorElement || t instanceof HTMLAreaElement) && t.hasAttribute("href") || t instanceof HTMLButtonElement || t instanceof HTMLInputElement || t instanceof HTMLTextAreaElement || t instanceof HTMLSelectElement || t.hasAttribute("tabindex") || t.shadowRoot?.delegatesFocus === !0);
3
+ }
4
+ export {
5
+ e as isFocusable
6
+ };
@@ -0,0 +1,38 @@
1
+ const l = /* @__PURE__ */ new Map(), c = /* @__PURE__ */ new Map();
2
+ function a(r, e, n, t) {
3
+ const u = `${n ?? ""}|${JSON.stringify(t)}`;
4
+ let o = r.get(u);
5
+ return o || (o = e(n, t), r.set(u, o)), o;
6
+ }
7
+ function m(r, e = {}) {
8
+ return a(
9
+ l,
10
+ (n, t) => {
11
+ try {
12
+ return new Intl.NumberFormat(n, t);
13
+ } catch {
14
+ return new Intl.NumberFormat(void 0, t);
15
+ }
16
+ },
17
+ r,
18
+ e
19
+ );
20
+ }
21
+ function i(r, e = {}) {
22
+ return a(
23
+ c,
24
+ (n, t) => {
25
+ try {
26
+ return new Intl.Collator(n, t);
27
+ } catch {
28
+ return new Intl.Collator(void 0, t);
29
+ }
30
+ },
31
+ r,
32
+ e
33
+ );
34
+ }
35
+ export {
36
+ i as collator,
37
+ m as numberFormat
38
+ };
@@ -0,0 +1,77 @@
1
+ import { observeLocale as f, notifyLocaleChange as g } from "./observeLocale.js";
2
+ const c = /* @__PURE__ */ new Map();
3
+ let u = 0;
4
+ function C(t, e) {
5
+ const s = t.toLowerCase(), r = { ...c.get(s) };
6
+ for (const [n, o] of Object.entries(e))
7
+ r[n] = { ...r[n], ...o };
8
+ c.set(s, r), u += 1, g();
9
+ }
10
+ function h(t) {
11
+ return t.getAttribute("lang") ?? t.ownerDocument.documentElement.lang ?? "";
12
+ }
13
+ function L(t) {
14
+ return `⁨${t}⁩`;
15
+ }
16
+ function d(t) {
17
+ const e = t.toLowerCase().split("-").filter(Boolean);
18
+ return e.map((s, r) => e.slice(0, r + 1).join("-"));
19
+ }
20
+ function y(t, e, s, r, n = {}) {
21
+ const o = { ...s }, a = new Set(Object.keys(s));
22
+ for (const _ of d(h(t))) {
23
+ const l = c.get(_);
24
+ n.inherit && i(o, l?.[n.inherit], a), i(o, l?.[e]);
25
+ }
26
+ return i(o, r), o;
27
+ }
28
+ function i(t, e, s) {
29
+ if (e)
30
+ for (const [r, n] of Object.entries(e))
31
+ n !== void 0 && (!s || s.has(r)) && (t[r] = n);
32
+ }
33
+ class b {
34
+ constructor(e, s = {}) {
35
+ this._unobserveLocale = null, this._key = "", this._host = e, this._onChange = s.onChange, e.addController(this);
36
+ }
37
+ /** The host's UI locale, or `undefined` for the runtime default. Read it while rendering. */
38
+ get locale() {
39
+ return this._key = this._currentKey(), h(this._host) || void 0;
40
+ }
41
+ hostConnected() {
42
+ this._unobserveLocale ??= f(() => {
43
+ const e = this._currentKey();
44
+ this._key !== e && (this._key = e, this._onChange ? this._onChange() : this._host.requestUpdate());
45
+ }, this._host);
46
+ }
47
+ hostDisconnected() {
48
+ this._unobserveLocale?.(), this._unobserveLocale = null;
49
+ }
50
+ _currentKey() {
51
+ return `${h(this._host)}|${u}`;
52
+ }
53
+ }
54
+ class k extends b {
55
+ constructor(e, s, r, n = {}) {
56
+ super(e, n), this._scope = s, this._defaults = r, this._overrides = n.overrides, this._inherit = n.inherit;
57
+ }
58
+ /** The resolved text. Read it while rendering. */
59
+ get value() {
60
+ return this.locale, y(this._host, this._scope, this._defaults, this._overrides?.(), {
61
+ inherit: this._inherit
62
+ });
63
+ }
64
+ }
65
+ function p(t, e, s, r) {
66
+ const n = t.getAttribute(e);
67
+ return n !== null && n !== r ? null : (n !== s && t.setAttribute(e, s), s);
68
+ }
69
+ export {
70
+ b as LocaleController,
71
+ k as MessagesController,
72
+ L as bidiIsolate,
73
+ h as messagesLocale,
74
+ C as registerMessages,
75
+ y as resolveMessages,
76
+ p as syncDefaultAttribute
77
+ };
@@ -0,0 +1,37 @@
1
+ function o(t, e) {
2
+ return Array.from(t.querySelectorAll(e));
3
+ }
4
+ function n(t, e) {
5
+ if (o(t, e.selector).length >= (e.minimum ?? 1))
6
+ return !1;
7
+ const s = e.hostName ?? t.localName, i = e.childDescription ?? e.selector.replace(":scope > ", ""), r = e.message ?? `[${s}] No direct child ${i} found. Place ${i} inside <${s}>.`;
8
+ return console.warn(r, t), !0;
9
+ }
10
+ class c {
11
+ constructor(e, s) {
12
+ this._observer = null, this._child = null, this._host = e, this._options = s, e.addController(this);
13
+ }
14
+ get child() {
15
+ return this._child;
16
+ }
17
+ hostConnected() {
18
+ if (this.sync(), !this._options.observe)
19
+ return;
20
+ this._observer ??= new MutationObserver(() => this.sync());
21
+ const e = this._options.observe === !0 ? { childList: !0 } : this._options.observe;
22
+ this._observer.observe(this._host, e);
23
+ }
24
+ hostDisconnected() {
25
+ this._observer?.disconnect(), this._child = null;
26
+ }
27
+ /** Re-read the child from the host and invoke `onChange` when it changes. */
28
+ sync() {
29
+ const e = this._child, s = this._host.querySelector(this._options.selector);
30
+ return this._child = s, s || this._options.onMissing?.(this._host), s !== e && this._options.onChange?.(s, e), s;
31
+ }
32
+ }
33
+ export {
34
+ c as NativeChildController,
35
+ o as getDirectChildren,
36
+ n as warnMissingDirectChild
37
+ };
@@ -0,0 +1,70 @@
1
+ const d = /* @__PURE__ */ new Set(), u = /* @__PURE__ */ new Map();
2
+ function l(o, t) {
3
+ let n = t;
4
+ for (; ; ) {
5
+ if (o.contains(n))
6
+ return !0;
7
+ const e = n.getRootNode();
8
+ if (e.nodeType !== 11)
9
+ return !1;
10
+ n = e.host;
11
+ }
12
+ }
13
+ function b(o, t) {
14
+ return l(t, o) || l(o, t);
15
+ }
16
+ function w(o, t) {
17
+ if (!t)
18
+ return !0;
19
+ const n = t().filter((e) => !!e);
20
+ return o.some(({ target: e }) => n.some((i) => b(e, i)));
21
+ }
22
+ function m(o, t, n) {
23
+ let e = u.get(o);
24
+ if (!e) {
25
+ const i = /* @__PURE__ */ new Map(), s = new MutationObserver((c) => {
26
+ for (const [r, f] of Array.from(i))
27
+ w(c, f) && r();
28
+ });
29
+ s.observe(o.nodeType === 9 ? o.documentElement : o, {
30
+ attributes: !0,
31
+ attributeFilter: ["dir", "lang"],
32
+ subtree: !0
33
+ }), e = { observer: s, listeners: i }, u.set(o, e);
34
+ }
35
+ return e.listeners.set(t, n), () => {
36
+ e.listeners.delete(t), e.listeners.size === 0 && (e.observer.disconnect(), u.delete(o));
37
+ };
38
+ }
39
+ function h(o, t, n = t ? () => [t] : void 0) {
40
+ const e = () => o(), i = [], s = /* @__PURE__ */ new Set();
41
+ if (d.add(e), typeof MutationObserver == "function") {
42
+ const c = t?.ownerDocument ?? (typeof document > "u" ? null : document);
43
+ if (c) {
44
+ s.add(c);
45
+ for (const r of [t, ...n?.() ?? []]) {
46
+ if (!r)
47
+ continue;
48
+ s.add(r.ownerDocument), r.shadowRoot && s.add(r.shadowRoot);
49
+ let f = r.getRootNode();
50
+ for (; f.nodeType === 11 && "host" in f; ) {
51
+ const a = f;
52
+ s.add(a), f = a.host.getRootNode();
53
+ }
54
+ }
55
+ for (const r of s)
56
+ i.push(m(r, e, n));
57
+ }
58
+ }
59
+ return () => {
60
+ d.delete(e), i.forEach((c) => c());
61
+ };
62
+ }
63
+ function p() {
64
+ for (const o of Array.from(d))
65
+ o();
66
+ }
67
+ export {
68
+ p as notifyLocaleChange,
69
+ h as observeLocale
70
+ };
@@ -0,0 +1,14 @@
1
+ function u(n, t, a, r) {
2
+ const e = Math.min(Math.max(n, t), a);
3
+ if (r <= 0)
4
+ return e;
5
+ const o = Math.round((e - t) / r) * r + t;
6
+ return Math.min(Math.max(o, t), a);
7
+ }
8
+ function h(n, t, a) {
9
+ return a === t ? 0 : Math.min(Math.max((n - t) / (a - t), 0), 1);
10
+ }
11
+ export {
12
+ u as snapToStep,
13
+ h as valueToPercent
14
+ };
@@ -0,0 +1,25 @@
1
+ function a(e, t) {
2
+ let i = -1, n = 1 / 0;
3
+ return e.forEach((r, d) => {
4
+ const f = Math.abs(r - t);
5
+ Number.isFinite(r) && f < n && (i = d, n = f);
6
+ }), i;
7
+ }
8
+ function u(e, t, i) {
9
+ if (i > 0) {
10
+ const n = e.findIndex((r) => Number.isFinite(r) && r > t);
11
+ return n >= 0 ? n : e.length - 1;
12
+ }
13
+ for (let n = e.length - 1; n >= 0; n -= 1)
14
+ if (Number.isFinite(e[n]) && e[n] < t)
15
+ return n;
16
+ return e.length > 0 ? 0 : -1;
17
+ }
18
+ function x(e, t) {
19
+ return e.length === 0 ? -1 : t > 0 ? e.length - 1 : 0;
20
+ }
21
+ export {
22
+ x as findExtremeSnapIndex,
23
+ a as findNearestSnapIndex,
24
+ u as findNextSnapIndex
25
+ };
@@ -0,0 +1,72 @@
1
+ const s = [
2
+ "",
3
+ "date",
4
+ "datetime-local",
5
+ "email",
6
+ "month",
7
+ "number",
8
+ "password",
9
+ "search",
10
+ "tel",
11
+ "text",
12
+ "time",
13
+ "url",
14
+ "week"
15
+ ];
16
+ function h(e) {
17
+ let t = e.activeElement;
18
+ for (; t?.shadowRoot?.activeElement; )
19
+ t = t.shadowRoot.activeElement;
20
+ return t;
21
+ }
22
+ function r(e) {
23
+ return e instanceof HTMLTextAreaElement ? !e.readOnly && !e.disabled : e instanceof HTMLInputElement ? !e.readOnly && !e.disabled && s.includes(e.type) : e instanceof HTMLElement && e.isContentEditable;
24
+ }
25
+ function n(e) {
26
+ return r(h(e));
27
+ }
28
+ class o {
29
+ constructor(t = {}) {
30
+ this._full = null, this._applied = null, this._keyboardOpen = !1, this._closeTimer = null, this._heightWhileOpen = t.heightWhileOpen ?? "keyboard", this._closeTimeout = t.closeTimeout ?? 1e3, this._onCloseTimeout = t.onCloseTimeout;
31
+ }
32
+ /** Whether the keyboard is up or still closing, as far as the measurements show. */
33
+ get keyboardOpen() {
34
+ return this._keyboardOpen;
35
+ }
36
+ /**
37
+ * Returns the size to apply for a fresh measurement.
38
+ *
39
+ * @param measured - the viewport as measured now
40
+ * @param textEntryFocused - whether a field that raises the keyboard has focus
41
+ */
42
+ next(t, l) {
43
+ const i = this._full;
44
+ return !i || !this._applied || t.width !== this._applied.width ? this._settle(t) : t.height >= i.height ? this._settle(t) : l ? (this._clearCloseTimer(), this._keyboardOpen = !0, this._apply(
45
+ this._heightWhileOpen === "full" ? { ...t, height: i.height } : t
46
+ )) : this._keyboardOpen ? (this._startCloseTimer(), this._heightWhileOpen === "full" || t.height < this._applied.height ? this._apply({ ...t, height: this._applied.height }) : this._apply(t)) : this._settle(t);
47
+ }
48
+ /** Forgets the measurements so far and cancels a pending close timeout. */
49
+ reset() {
50
+ this._clearCloseTimer(), this._full = null, this._applied = null, this._keyboardOpen = !1;
51
+ }
52
+ // Takes the measurement as the keyboard-free size.
53
+ _settle(t) {
54
+ return this._clearCloseTimer(), this._keyboardOpen = !1, this._full = t, this._apply(t);
55
+ }
56
+ _apply(t) {
57
+ return this._applied = t, t;
58
+ }
59
+ _startCloseTimer() {
60
+ this._closeTimer === null && (this._closeTimer = setTimeout(() => {
61
+ this._closeTimer = null, this._keyboardOpen = !1, this._full = null, this._onCloseTimeout?.();
62
+ }, this._closeTimeout));
63
+ }
64
+ _clearCloseTimer() {
65
+ this._closeTimer !== null && (clearTimeout(this._closeTimer), this._closeTimer = null);
66
+ }
67
+ }
68
+ export {
69
+ o as SoftKeyboardViewport,
70
+ h as deepActiveElement,
71
+ n as isTextEntryFocused
72
+ };
@@ -0,0 +1,14 @@
1
+ function h(e) {
2
+ const t = e.visualViewport, o = t?.offsetLeft ?? 0, i = t?.offsetTop ?? 0, n = t?.width ?? e.innerWidth, s = t?.height ?? e.innerHeight;
3
+ return {
4
+ left: o,
5
+ top: i,
6
+ width: n,
7
+ height: s,
8
+ right: o + n,
9
+ bottom: i + s
10
+ };
11
+ }
12
+ export {
13
+ h as getVisualViewportBounds
14
+ };