@nvidia-elements/forms 2.0.7 → 2.0.8

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/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ ## [2.0.8](https://github.com/NVIDIA/elements/compare/@nvidia-elements/forms-v2.0.7...@nvidia-elements/forms-v2.0.8) (2026-10-09)
2
+
3
+ ### Features
4
+
5
+ * **core:** add configurable viewport zoom stops ([ff741ea](https://github.com/NVIDIA/elements/commit/ff741eac903e2543c0fa3b9fefc8ef28a5e82d90))
6
+ * **core:** drag handle ([cc6d5b1](https://github.com/NVIDIA/elements/commit/cc6d5b17aac74e65163d581d8525897762d714c2))
7
+ * **core:** tree node prefix and suffix ([bc0f2f1](https://github.com/NVIDIA/elements/commit/bc0f2f13bbc4119b1941a8102d09e3eba41f278b))
8
+
9
+ ### Bug Fixes
10
+
11
+ * **cli:** update dependencies ([2a84274](https://github.com/NVIDIA/elements/commit/2a842746f3cd4055ab53414dd263511d74bad10f))
12
+ * **core:** nested background styles ([66d44e7](https://github.com/NVIDIA/elements/commit/66d44e7549f25f096d71c5fc662d805b4267bc72))
13
+ * **forms:** missing key event check ([3854d5f](https://github.com/NVIDIA/elements/commit/3854d5fb614912eb225612bcdf308badc832093d))
14
+
1
15
  ## [2.0.7](https://github.com/NVIDIA/elements/compare/@nvidia-elements/forms-v2.0.6...@nvidia-elements/forms-v2.0.7) (2026-10-07)
2
16
 
3
17
  ### Features
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  //#region src/index.ts
2
- var e = "2.0.7";
2
+ var e = "2.0.8";
3
3
  //#endregion
4
4
  export { e as VERSION };
5
5
 
@@ -1,6 +1,6 @@
1
- import { onKeys as e, stopEvent as t } from "../utils.js";
1
+ import { stopEvent as e } from "../utils.js";
2
2
  //#region src/internal/controllers/type-submit.controller.ts
3
- var n = class {
3
+ var t = class {
4
4
  #e;
5
5
  #t;
6
6
  #n;
@@ -22,12 +22,12 @@ var n = class {
22
22
  #i() {
23
23
  this.host.removeEventListener("click", this.#o), this.host.removeEventListener("keyup", this.#a);
24
24
  }
25
- #a = (t) => {
26
- e(["Enter", "Space"], t, () => this.host.click());
25
+ #a = (e) => {
26
+ (e.key === " " || e.key === "Enter" || e.code === "Space" || e.code === "Enter") && this.host.click();
27
27
  };
28
- #o = (e) => {
28
+ #o = (t) => {
29
29
  if (this.host.disabled) {
30
- t(e);
30
+ e(t);
31
31
  return;
32
32
  }
33
33
  this.host.type === "submit" && this.host.form instanceof HTMLFormElement ? this.#s(this.host.form) : this.host.type === "reset" && this.host.form instanceof HTMLFormElement && this.host.form.reset();
@@ -49,6 +49,6 @@ var n = class {
49
49
  }
50
50
  };
51
51
  //#endregion
52
- export { n as TypeSubmitController };
52
+ export { t as TypeSubmitController };
53
53
 
54
54
  //# sourceMappingURL=type-submit.controller.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"type-submit.controller.js","names":[],"sources":["../../../src/internal/controllers/type-submit.controller.ts"],"sourcesContent":["// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { onKeys, stopEvent } from '../utils.js';\nimport type { ButtonType } from '../types/button.js';\nimport type { ReactiveController, ReactiveElement } from './types.js';\n\ntype SubmitHost = ReactiveElement & {\n disabled: boolean;\n form: HTMLFormElement | null | string;\n name?: string;\n readOnly: boolean;\n type?: ButtonType;\n value?: string;\n};\n\nexport class TypeSubmitController<T extends SubmitHost> implements ReactiveController {\n #defaultType: ButtonType | undefined;\n #submitter: HTMLButtonElement | undefined;\n #submitterForm: HTMLFormElement | undefined;\n\n constructor(private host: T) {\n this.host.addController(this);\n }\n\n get defaultType() {\n return this.#defaultType;\n }\n\n hostUpdated() {\n this.#setButtonType();\n this.#removeSubmitBehavior();\n if (!this.host.readOnly && !this.host.disabled) {\n this.host.addEventListener('click', this.#onSubmitClick);\n this.host.addEventListener('keyup', this.#onSubmitKeyup);\n }\n }\n\n hostDisconnected() {\n this.#removeSubmitBehavior();\n this.#removeSubmitter();\n }\n\n #setButtonType() {\n if (!this.host.type && !this.host.hasAttribute('type') && this.host.form instanceof HTMLFormElement) {\n this.#defaultType = 'submit';\n }\n }\n\n #removeSubmitBehavior() {\n this.host.removeEventListener('click', this.#onSubmitClick);\n this.host.removeEventListener('keyup', this.#onSubmitKeyup);\n }\n\n #onSubmitKeyup = (event: KeyboardEvent) => {\n onKeys(['Enter', 'Space'], event, () => this.host.click());\n };\n\n #onSubmitClick = (event: Event) => {\n if (this.host.disabled) {\n stopEvent(event);\n return;\n }\n\n if (this.host.type === 'submit' && this.host.form instanceof HTMLFormElement) {\n this.#requestSubmit(this.host.form);\n } else if (this.host.type === 'reset' && this.host.form instanceof HTMLFormElement) {\n this.host.form.reset();\n }\n };\n\n #requestSubmit(form: HTMLFormElement) {\n this.#removeSubmitter();\n this.#createSubmitter();\n this.#submitterForm = form;\n form.addEventListener('submit', this.#onSubmit, { once: true });\n this.#submitter?.remove();\n form.appendChild(this.#submitter!);\n form.requestSubmit(this.#submitter);\n }\n\n #onSubmit = () => {\n const submitter = this.#submitter;\n this.#submitterForm = undefined;\n setTimeout(() => {\n submitter?.remove();\n if (this.#submitter === submitter) {\n this.#submitter = undefined;\n }\n }, 0);\n };\n\n #createSubmitter() {\n if (!this.#submitter) {\n this.#submitter = globalThis.document.createElement('button');\n this.#submitter.type = 'submit';\n this.#submitter.style.display = 'none';\n }\n\n this.#submitter.name = this.host.name ?? '';\n this.#submitter.value = this.host.value ?? '';\n }\n\n #removeSubmitter() {\n this.#submitterForm?.removeEventListener('submit', this.#onSubmit);\n this.#submitterForm = undefined;\n this.#submitter?.remove();\n this.#submitter = undefined;\n }\n}\n"],"mappings":";;AAgBA,IAAa,IAAb,MAAsF;CACpF;CACA;CACA;CAEA,YAAY,GAAiB;EAC3B,AADkB,KAAA,OAAA,GAClB,KAAK,KAAK,cAAc,IAAI;CAC9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B;GAEf,AADA,GAAW,OAAO,GACd,KAAK,OAAe,MACtB,KAAK,KAAa,KAAA;EAEtB,GAAG,CAAC;CACN;CAEA,KAAmB;EAQjB,AAPK,KAAK,OACR,KAAK,KAAa,WAAW,SAAS,cAAc,QAAQ,GAC5D,KAAK,GAAW,OAAO,UACvB,KAAK,GAAW,MAAM,UAAU,SAGlC,KAAK,GAAW,OAAO,KAAK,KAAK,QAAQ,IACzC,KAAK,GAAW,QAAQ,KAAK,KAAK,SAAS;CAC7C;CAEA,KAAmB;EAIjB,AAHA,KAAK,IAAgB,oBAAoB,UAAU,KAAK,EAAS,GACjE,KAAK,KAAiB,KAAA,GACtB,KAAK,IAAY,OAAO,GACxB,KAAK,KAAa,KAAA;CACpB;AACF"}
1
+ {"version":3,"file":"type-submit.controller.js","names":[],"sources":["../../../src/internal/controllers/type-submit.controller.ts"],"sourcesContent":["// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { stopEvent } from '../utils.js';\nimport type { ButtonType } from '../types/button.js';\nimport type { ReactiveController, ReactiveElement } from './types.js';\n\ntype SubmitHost = ReactiveElement & {\n disabled: boolean;\n form: HTMLFormElement | null | string;\n name?: string;\n readOnly: boolean;\n type?: ButtonType;\n value?: string;\n};\n\nexport class TypeSubmitController<T extends SubmitHost> implements ReactiveController {\n #defaultType: ButtonType | undefined;\n #submitter: HTMLButtonElement | undefined;\n #submitterForm: HTMLFormElement | undefined;\n\n constructor(private host: T) {\n this.host.addController(this);\n }\n\n get defaultType() {\n return this.#defaultType;\n }\n\n hostUpdated() {\n this.#setButtonType();\n this.#removeSubmitBehavior();\n if (!this.host.readOnly && !this.host.disabled) {\n this.host.addEventListener('click', this.#onSubmitClick);\n this.host.addEventListener('keyup', this.#onSubmitKeyup);\n }\n }\n\n hostDisconnected() {\n this.#removeSubmitBehavior();\n this.#removeSubmitter();\n }\n\n #setButtonType() {\n if (!this.host.type && !this.host.hasAttribute('type') && this.host.form instanceof HTMLFormElement) {\n this.#defaultType = 'submit';\n }\n }\n\n #removeSubmitBehavior() {\n this.host.removeEventListener('click', this.#onSubmitClick);\n this.host.removeEventListener('keyup', this.#onSubmitKeyup);\n }\n\n #onSubmitKeyup = (event: KeyboardEvent) => {\n if (event.key === ' ' || event.key === 'Enter' || event.code === 'Space' || event.code === 'Enter') {\n this.host.click();\n }\n };\n\n #onSubmitClick = (event: Event) => {\n if (this.host.disabled) {\n stopEvent(event);\n return;\n }\n\n if (this.host.type === 'submit' && this.host.form instanceof HTMLFormElement) {\n this.#requestSubmit(this.host.form);\n } else if (this.host.type === 'reset' && this.host.form instanceof HTMLFormElement) {\n this.host.form.reset();\n }\n };\n\n #requestSubmit(form: HTMLFormElement) {\n this.#removeSubmitter();\n this.#createSubmitter();\n this.#submitterForm = form;\n form.addEventListener('submit', this.#onSubmit, { once: true });\n this.#submitter?.remove();\n form.appendChild(this.#submitter!);\n form.requestSubmit(this.#submitter);\n }\n\n #onSubmit = () => {\n const submitter = this.#submitter;\n this.#submitterForm = undefined;\n setTimeout(() => {\n submitter?.remove();\n if (this.#submitter === submitter) {\n this.#submitter = undefined;\n }\n }, 0);\n };\n\n #createSubmitter() {\n if (!this.#submitter) {\n this.#submitter = globalThis.document.createElement('button');\n this.#submitter.type = 'submit';\n this.#submitter.style.display = 'none';\n }\n\n this.#submitter.name = this.host.name ?? '';\n this.#submitter.value = this.host.value ?? '';\n }\n\n #removeSubmitter() {\n this.#submitterForm?.removeEventListener('submit', this.#onSubmit);\n this.#submitterForm = undefined;\n this.#submitter?.remove();\n this.#submitter = undefined;\n }\n}\n"],"mappings":";;AAgBA,IAAa,IAAb,MAAsF;CACpF;CACA;CACA;CAEA,YAAY,GAAiB;EAC3B,AADkB,KAAA,OAAA,GAClB,KAAK,KAAK,cAAc,IAAI;CAC9B;CAEA,IAAI,cAAc;EAChB,OAAO,KAAK;CACd;CAEA,cAAc;EAGZ,AAFA,KAA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K,OAAe,MACtB,KAAK,KAAa,KAAA;EAEtB,GAAG,CAAC;CACN;CAEA,KAAmB;EAQjB,AAPK,KAAK,OACR,KAAK,KAAa,WAAW,SAAS,cAAc,QAAQ,GAC5D,KAAK,GAAW,OAAO,UACvB,KAAK,GAAW,MAAM,UAAU,SAGlC,KAAK,GAAW,OAAO,KAAK,KAAK,QAAQ,IACzC,KAAK,GAAW,QAAQ,KAAK,KAAK,SAAS;CAC7C;CAEA,KAAmB;EAIjB,AAHA,KAAK,IAAgB,oBAAoB,UAAU,KAAK,EAAS,GACjE,KAAK,KAAiB,KAAA,GACtB,KAAK,IAAY,OAAO,GACxB,KAAK,KAAa,KAAA;CACpB;AACF"}
@@ -11,7 +11,7 @@ function n(e, t, n) {
11
11
  n ? e.states.add(t) : e.states.delete(t);
12
12
  }
13
13
  function r(e, t = 10) {
14
- return Array.from(f(e)).reduce((e, n) => [...e, [n, [...Array.from(f(n)).map((e) => [e, r(e, t)])]]], []).flat(t);
14
+ return Array.from(d(e)).reduce((e, n) => [...e, [n, [...Array.from(d(n)).map((e) => [e, r(e, t)])]]], []).flat(t);
15
15
  }
16
16
  function i(e) {
17
17
  let t = e.anchor ?? e._activeTrigger;
@@ -26,37 +26,34 @@ function o(e, t, n) {
26
26
  function s(e) {
27
27
  return typeof HTMLFormElement < "u" && e instanceof HTMLFormElement;
28
28
  }
29
- function c(e, t, n) {
30
- e.includes(t.code) && n();
31
- }
32
- function l(e) {
29
+ function c(e) {
33
30
  e?.wholeText?.trim() === "" && e.parentNode?.removeChild(e);
34
31
  }
35
- function u(e, t, n) {
32
+ function l(e, t, n) {
36
33
  n === null ? e.removeAttribute(t) : e.setAttribute(t, n);
37
34
  }
38
- function d(e) {
35
+ function u(e) {
39
36
  e.preventDefault(), e.stopPropagation();
40
37
  }
41
- function f(e) {
42
- if (p(e)) return Array.from(e.documentElement.children);
43
- if (m(e)) return Array.from(e.shadowRoot.children);
44
- if (h(e)) {
38
+ function d(e) {
39
+ if (f(e)) return Array.from(e.documentElement.children);
40
+ if (p(e)) return Array.from(e.shadowRoot.children);
41
+ if (m(e)) {
45
42
  let t = e.assignedElements();
46
43
  return t.length ? t : Array.from(e.children);
47
44
  }
48
45
  return Array.from(e.children ?? []);
49
46
  }
50
- function p(e) {
47
+ function f(e) {
51
48
  return typeof Document < "u" && e instanceof Document && !!e.documentElement;
52
49
  }
53
- function m(e) {
50
+ function p(e) {
54
51
  return typeof HTMLElement < "u" && e instanceof HTMLElement && !!e.shadowRoot;
55
52
  }
56
- function h(e) {
53
+ function m(e) {
57
54
  return typeof HTMLSlotElement < "u" && e instanceof HTMLSlotElement && !!e.assignedElements;
58
55
  }
59
56
  //#endregion
60
- export { t as attachInternals, r as getFlattenedDOMTree, i as getHostAnchor, a as getStringValue, o as hasAttributeValue, s as isFormElement, e as isObjectLiteral, c as onKeys, l as removeEmptyTextNode, u as setAttributeValue, d as stopEvent, n as toggleState };
57
+ export { t as attachInternals, r as getFlattenedDOMTree, i as getHostAnchor, a as getStringValue, o as hasAttributeValue, s as isFormElement, e as isObjectLiteral, c as removeEmptyTextNode, l as setAttributeValue, u as stopEvent, n as toggleState };
61
58
 
62
59
  //# sourceMappingURL=utils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","names":[],"sources":["../../src/internal/utils.ts"],"sourcesContent":["// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nexport function isObjectLiteral(item: unknown) {\n if (!item || typeof item !== 'object' || Array.isArray(item)) {\n return false;\n }\n const proto = Object.getPrototypeOf(item);\n return proto === null || proto === Object.prototype;\n}\n\nexport function attachInternals(element: HTMLElement & { _internals?: ElementInternals }) {\n if (element._internals === undefined) {\n element._internals = element.attachInternals() as unknown as ElementInternals;\n }\n\n return element._internals;\n}\n\nexport function toggleState(internals: ElementInternals, state: string, force: boolean) {\n if (force) {\n internals.states.add(state);\n } else {\n internals.states.delete(state);\n }\n}\n\nexport type PopoverAnchorElement = HTMLElement & { anchor?: HTMLElement | string; _activeTrigger?: HTMLElement };\n\nexport function getFlattenedDOMTree(node: Node, depth = 10): HTMLElement[] {\n return (\n Array.from(getChildren(node)).reduce(\n (p: unknown[], n: Node) => [\n ...p,\n [n, [...Array.from(getChildren(n)).map(i => [i, getFlattenedDOMTree(i, depth)])]]\n ],\n []\n ) as unknown as HTMLElement[]\n ).flat(depth);\n}\n\nexport function getHostAnchor(host: PopoverAnchorElement) {\n const anchor = host.anchor ?? host._activeTrigger;\n\n if (typeof anchor === 'string' && anchor.length) {\n if (!host.parentNode) {\n return globalThis.document.body;\n }\n\n return (\n getFlattenedDOMTree(host.parentNode as Node).find(element => element.id === anchor) ?? globalThis.document.body\n );\n }\n\n if (anchor instanceof HTMLElement && anchor !== globalThis.document.body) {\n return anchor;\n }\n\n return globalThis.document.body;\n}\n\nexport function getStringValue(value: unknown) {\n if (typeof value === 'string' && value.length) {\n return value;\n }\n\n return value === '' ? '' : null;\n}\n\nexport function hasAttributeValue(element: HTMLElement, attribute: string, value: string | null) {\n return value === null ? !element.hasAttribute(attribute) : element.getAttribute(attribute) === value;\n}\n\nexport function isFormElement(value: unknown): value is HTMLFormElement {\n return typeof HTMLFormElement !== 'undefined' && value instanceof HTMLFormElement;\n}\n\nexport function onKeys(events: string[], event: KeyboardEvent, callback: () => void) {\n if (events.includes(event.code)) {\n callback();\n }\n}\n\nexport function removeEmptyTextNode(node: Node) {\n if ((node as Text)?.wholeText?.trim() === '') {\n node.parentNode?.removeChild(node);\n }\n}\n\nexport function setAttributeValue(element: HTMLElement, attribute: string, value: string | null) {\n if (value === null) {\n element.removeAttribute(attribute);\n } else {\n element.setAttribute(attribute, value);\n }\n}\n\nexport function stopEvent(event: Event) {\n event.preventDefault();\n event.stopPropagation();\n}\n\nfunction getChildren(node: Node): Element[] {\n if (isDocumentNode(node)) {\n return Array.from(node.documentElement.children);\n }\n\n if (isElementWithShadowRoot(node)) {\n return Array.from(node.shadowRoot.children);\n }\n\n if (isSlotElement(node)) {\n const slotted = node.assignedElements();\n return slotted.length ? slotted : Array.from(node.children);\n }\n\n return Array.from((node as HTMLElement).children ?? []);\n}\n\nfunction isDocumentNode(node: Node): node is Document {\n return typeof Document !== 'undefined' && node instanceof Document && Boolean(node.documentElement);\n}\n\nfunction isElementWithShadowRoot(node: Node): node is HTMLElement & { shadowRoot: ShadowRoot } {\n return typeof HTMLElement !== 'undefined' && node instanceof HTMLElement && Boolean(node.shadowRoot);\n}\n\nfunction isSlotElement(node: Node): node is HTMLSlotElement {\n return typeof HTMLSlotElement !== 'undefined' && node instanceof HTMLSlotElement && Boolean(node.assignedElements);\n}\n"],"mappings":";AAGA,SAAgB,EAAgB,GAAe;CAC7C,IAAI,CAAC,KAAQ,OAAO,KAAS,YAAY,MAAM,QAAQ,CAAI,GACzD,OAAO;CAET,IAAM,IAAQ,OAAO,eAAe,CAAI;CACxC,OAAO,MAAU,QAAQ,MAAU,OAAO;AAC5C;AAEA,SAAgB,EAAgB,GAA0D;CAKxF,OAJI,EAAQ,eAAe,KAAA,MACzB,EAAQ,aAAa,EAAQ,gBAAgB,IAGxC,EAAQ;AACjB;AAEA,SAAgB,EAAY,GAA6B,GAAe,GAAgB;CACtF,AAAI,IACF,EAAU,OAAO,IAAI,CAAK,IAE1B,EAAU,OAAO,OAAO,CAAK;AAEjC;AAIA,SAAgB,EAAoB,GAAY,IAAQ,IAAmB;CACzE,OACE,MAAM,KAAK,EAAY,CAAI,CAAC,CAAC,CAAC,QAC3B,GAAc,MAAY,CACzB,GAAG,GACH,CAAC,GAAG,CAAC,GAAG,MAAM,KAAK,EAAY,CAAC,CAAC,CAAC,CAAC,KAAI,MAAK,CAAC,GAAG,EAAoB,GAAG,CAAK,CAAC,CAAC,CAAC,CAAC,CAClF,GACA,CAAC,CACH,CAAC,CACD,KAAK,CAAK;AACd;AAEA,SAAgB,EAAc,GAA4B;CACxD,IAAM,IAAS,EAAK,UAAU,EAAK;CAgBn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AO,MAAM,KAAM,EAAqB,YAAY,CAAC,CAAC;AACxD;AAEA,SAAS,EAAe,GAA8B;CACpD,OAAO,OAAO,WAAa,OAAe,aAAgB,YAAY,EAAQ,EAAK;AACrF;AAEA,SAAS,EAAwB,GAA8D;CAC7F,OAAO,OAAO,cAAgB,OAAe,aAAgB,eAAe,EAAQ,EAAK;AAC3F;AAEA,SAAS,EAAc,GAAqC;CAC1D,OAAO,OAAO,kBAAoB,OAAe,aAAgB,mBAAmB,EAAQ,EAAK;AACnG"}
1
+ {"version":3,"file":"utils.js","names":[],"sources":["../../src/internal/utils.ts"],"sourcesContent":["// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nexport function isObjectLiteral(item: unknown) {\n if (!item || typeof item !== 'object' || Array.isArray(item)) {\n return false;\n }\n const proto = Object.getPrototypeOf(item);\n return proto === null || proto === Object.prototype;\n}\n\nexport function attachInternals(element: HTMLElement & { _internals?: ElementInternals }) {\n if (element._internals === undefined) {\n element._internals = element.attachInternals() as unknown as ElementInternals;\n }\n\n return element._internals;\n}\n\nexport function toggleState(internals: ElementInternals, state: string, force: boolean) {\n if (force) {\n internals.states.add(state);\n } else {\n internals.states.delete(state);\n }\n}\n\nexport type PopoverAnchorElement = HTMLElement & { anchor?: HTMLElement | string; _activeTrigger?: HTMLElement };\n\nexport function getFlattenedDOMTree(node: Node, depth = 10): HTMLElement[] {\n return (\n Array.from(getChildren(node)).reduce(\n (p: unknown[], n: Node) => [\n ...p,\n [n, [...Array.from(getChildren(n)).map(i => [i, getFlattenedDOMTree(i, depth)])]]\n ],\n []\n ) as unknown as HTMLElement[]\n ).flat(depth);\n}\n\nexport function getHostAnchor(host: PopoverAnchorElement) {\n const anchor = host.anchor ?? host._activeTrigger;\n\n if (typeof anchor === 'string' && anchor.length) {\n if (!host.parentNode) {\n return globalThis.document.body;\n }\n\n return (\n getFlattenedDOMTree(host.parentNode as Node).find(element => element.id === anchor) ?? globalThis.document.body\n );\n }\n\n if (anchor instanceof HTMLElement && anchor !== globalThis.document.body) {\n return anchor;\n }\n\n return globalThis.document.body;\n}\n\nexport function getStringValue(value: unknown) {\n if (typeof value === 'string' && value.length) {\n return value;\n }\n\n return value === '' ? '' : null;\n}\n\nexport function hasAttributeValue(element: HTMLElement, attribute: string, value: string | null) {\n return value === null ? !element.hasAttribute(attribute) : element.getAttribute(attribute) === value;\n}\n\nexport function isFormElement(value: unknown): value is HTMLFormElement {\n return typeof HTMLFormElement !== 'undefined' && value instanceof HTMLFormElement;\n}\n\nexport function onKeys(events: string[], event: KeyboardEvent, callback: () => void) {\n if (events.includes(event.code)) {\n callback();\n }\n}\n\nexport function removeEmptyTextNode(node: Node) {\n if ((node as Text)?.wholeText?.trim() === '') {\n node.parentNode?.removeChild(node);\n }\n}\n\nexport function setAttributeValue(element: HTMLElement, attribute: string, value: string | null) {\n if (value === null) {\n element.removeAttribute(attribute);\n } else {\n element.setAttribute(attribute, value);\n }\n}\n\nexport function stopEvent(event: Event) {\n event.preventDefault();\n event.stopPropagation();\n}\n\nfunction getChildren(node: Node): Element[] {\n if (isDocumentNode(node)) {\n return Array.from(node.documentElement.children);\n }\n\n if (isElementWithShadowRoot(node)) {\n return Array.from(node.shadowRoot.children);\n }\n\n if (isSlotElement(node)) {\n const slotted = node.assignedElements();\n return slotted.length ? slotted : Array.from(node.children);\n }\n\n return Array.from((node as HTMLElement).children ?? []);\n}\n\nfunction isDocumentNode(node: Node): node is Document {\n return typeof Document !== 'undefined' && node instanceof Document && Boolean(node.documentElement);\n}\n\nfunction isElementWithShadowRoot(node: Node): node is HTMLElement & { shadowRoot: ShadowRoot } {\n return typeof HTMLElement !== 'undefined' && node instanceof HTMLElement && Boolean(node.shadowRoot);\n}\n\nfunction isSlotElement(node: Node): node is HTMLSlotElement {\n return typeof HTMLSlotElement !== 'undefined' && node instanceof HTMLSlotElement && Boolean(node.assignedElements);\n}\n"],"mappings":";AA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