@tailng-ui/primitives 0.51.0 → 0.52.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 (29) hide show
  1. package/package.json +2 -2
  2. package/src/lib/form/_shared/select/tng-select.overlay.shared.d.ts +6 -0
  3. package/src/lib/form/_shared/select/tng-select.overlay.shared.d.ts.map +1 -1
  4. package/src/lib/form/_shared/select/tng-select.overlay.shared.js +65 -11
  5. package/src/lib/form/_shared/select/tng-select.overlay.shared.js.map +1 -1
  6. package/src/lib/form/autocomplete/tng-autocomplete.overlay.d.ts +6 -1
  7. package/src/lib/form/autocomplete/tng-autocomplete.overlay.d.ts.map +1 -1
  8. package/src/lib/form/autocomplete/tng-autocomplete.overlay.js +59 -3
  9. package/src/lib/form/autocomplete/tng-autocomplete.overlay.js.map +1 -1
  10. package/src/lib/form/datepicker/tng-datepicker.overlay.d.ts +11 -0
  11. package/src/lib/form/datepicker/tng-datepicker.overlay.d.ts.map +1 -1
  12. package/src/lib/form/datepicker/tng-datepicker.overlay.js +73 -3
  13. package/src/lib/form/datepicker/tng-datepicker.overlay.js.map +1 -1
  14. package/src/lib/form/index.d.ts +1 -0
  15. package/src/lib/form/index.d.ts.map +1 -1
  16. package/src/lib/form/index.js +1 -0
  17. package/src/lib/form/index.js.map +1 -1
  18. package/src/lib/form/input/tng-adornment.d.ts +6 -6
  19. package/src/lib/form/input/tng-adornment.d.ts.map +1 -1
  20. package/src/lib/form/input/tng-adornment.js +12 -12
  21. package/src/lib/form/input/tng-adornment.js.map +1 -1
  22. package/src/lib/form/input/tng-input-group.d.ts +4 -4
  23. package/src/lib/form/input/tng-input-group.d.ts.map +1 -1
  24. package/src/lib/form/input/tng-input-group.js +8 -8
  25. package/src/lib/form/input/tng-input-group.js.map +1 -1
  26. package/src/lib/form/multi-autocomplete/tng-multi-autocomplete.overlay.d.ts +5 -0
  27. package/src/lib/form/multi-autocomplete/tng-multi-autocomplete.overlay.d.ts.map +1 -1
  28. package/src/lib/form/multi-autocomplete/tng-multi-autocomplete.overlay.js +51 -4
  29. package/src/lib/form/multi-autocomplete/tng-multi-autocomplete.overlay.js.map +1 -1
@@ -41,6 +41,48 @@ function viewportRect() {
41
41
  function isInside(target, container) {
42
42
  return !!target && target instanceof Node && container.contains(target);
43
43
  }
44
+ /**
45
+ * When the overlay's host element lives inside a `tng-form-field`, the form-field
46
+ * is the visible frame the consumer sees, so the overlay should align with it
47
+ * (width + left/right edges). For the `left` label layout the form-field's root
48
+ * spans the label column too, so anchor on the inner control-row instead.
49
+ */
50
+ function findFormFieldAnchor(host) {
51
+ const formField = host.closest('[data-slot="form-field"]');
52
+ if (!formField)
53
+ return null;
54
+ if (formField.getAttribute('data-label-position') === 'left') {
55
+ const row = formField.querySelector('.tng-form-field__control-row');
56
+ return row ?? formField;
57
+ }
58
+ return formField;
59
+ }
60
+ /**
61
+ * Rect to use for overlay positioning. When the anchor is a form-field root, the
62
+ * horizontal extent is taken from the form-field (so the overlay spans the field
63
+ * frame) but the vertical extent is taken from the inner fieldset (the input row)
64
+ * so the overlay opens directly under the input rather than below the messages
65
+ * region beneath the frame.
66
+ */
67
+ function anchorRectFor(anchorEl) {
68
+ const widthRect = anchorEl.getBoundingClientRect();
69
+ if (!anchorEl.matches('[data-slot="form-field"]')) {
70
+ return rectFromClientRect(widthRect);
71
+ }
72
+ const labelPosition = anchorEl.getAttribute('data-label-position');
73
+ const fieldset = anchorEl.querySelector('[data-slot="form-field-control-row"]');
74
+ const innerRow = anchorEl.querySelector('.tng-form-field__control-row');
75
+ const positionEl = labelPosition === 'outline' ? (fieldset ?? innerRow) : (innerRow ?? fieldset);
76
+ if (!positionEl)
77
+ return rectFromClientRect(widthRect);
78
+ const positionRect = positionEl.getBoundingClientRect();
79
+ return {
80
+ left: widthRect.left,
81
+ width: widthRect.width,
82
+ top: positionRect.top,
83
+ height: positionRect.height,
84
+ };
85
+ }
44
86
  export class TngMultiAutocompleteOverlay {
45
87
  multi = inject(TNG_MULTI_AUTOCOMPLETE);
46
88
  elRef = inject((ElementRef));
@@ -78,15 +120,20 @@ export class TngMultiAutocompleteOverlay {
78
120
  this.originalParent = null;
79
121
  });
80
122
  }
123
+ /**
124
+ * Anchor for overlay positioning, width, and dismiss boundary.
125
+ * Prefer the enclosing form-field (so the overlay aligns with the visible
126
+ * field frame), else the multi-autocomplete host element itself.
127
+ */
81
128
  findAnchorEl() {
82
- return this.multi.hostElement;
129
+ return findFormFieldAnchor(this.multi.hostElement) ?? this.multi.hostElement;
83
130
  }
84
131
  reposition() {
85
132
  if (!this.multi.open())
86
133
  return;
87
134
  const panel = this.elRef.nativeElement;
88
135
  const anchorEl = this.findAnchorEl();
89
- const anchor = rectFromClientRect(anchorEl.getBoundingClientRect());
136
+ const anchor = anchorRectFor(anchorEl);
90
137
  const overlay = rectFromClientRect(panel.getBoundingClientRect());
91
138
  const viewport = viewportRect();
92
139
  const result = computeOverlayPosition({
@@ -136,7 +183,7 @@ export class TngMultiAutocompleteOverlay {
136
183
  const panel = this.elRef.nativeElement;
137
184
  if (isInside(event.target, panel))
138
185
  return;
139
- if (isInside(event.target, this.multi.hostElement))
186
+ if (isInside(event.target, this.findAnchorEl()))
140
187
  return;
141
188
  if (event.target && event.target.closest?.('[data-slot="multi-autocomplete-option"]')) {
142
189
  return;
@@ -195,7 +242,7 @@ export class TngMultiAutocompleteOverlay {
195
242
  queueMicrotask(() => {
196
243
  if (!this.multi.open())
197
244
  return;
198
- const anchor = rectFromClientRect(this.findAnchorEl().getBoundingClientRect());
245
+ const anchor = anchorRectFor(this.findAnchorEl());
199
246
  const viewportWidth = viewportRect().width;
200
247
  const inlineSize = Math.max(0, Math.min(anchor.width, viewportWidth - 16));
201
248
  panel.style.width = `${inlineSize}px`;
@@ -1 +1 @@
1
- {"version":3,"file":"tng-multi-autocomplete.overlay.js","sourceRoot":"","sources":["../../../../../../../../libs/tailng-ui/primitives/src/lib/form/multi-autocomplete/tng-multi-autocomplete.overlay.ts"],"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B,EAAE,CAAC;QACnC,KAAK,CAAC,KAAK,CAAC,QAAQ,GAAG,EAAE,CAAC;QAC1B,KAAK,CAAC,KAAK,CAAC,IAAI,GAAG,EAAE,CAAC;QACtB,KAAK,CAAC,KAAK,CAAC,GAAG,GAAG,EAAE,CAAC;QACrB,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,EAAE,CAAC;QACxB,KAAK,CAAC,KAAK,CAAC,KAAK,GAAG,EAAE,CAAC;QACvB,KAAK,CAAC,KAAK,CAAC,QAAQ,GAAG,EAAE,CAAC;QAC1B,IAAI,CAAC,uBAAuB,EAAE,CAAC;QAC/B,IAAI,CAAC,sBAAsB,EAAE,CAAC;IAChC,CAAC;uGAvNU,2BAA2B;2FAA3B,2BAA2B;;2FAA3B,2BAA2B;kBAJvC,SAAS;mBAAC;oBACT,QAAQ,EAAE,+BAA+B;oBACzC,QAAQ,EAAE,6BAA6B;iBACxC;;sBAaE,WAAW;uBAAC,gBAAgB;;sBAG5B,WAAW;uBAAC,aAAa","sourcesContent":["import {\n DestroyRef,\n Directive,\n ElementRef,\n HostBinding,\n effect,\n inject,\n} from '@angular/core';\nimport { computeOverlayPosition } from '@tailng-ui/cdk';\nimport { TNG_MULTI_AUTOCOMPLETE } from './tng-multi-autocomplete.tokens';\nimport type { TngMultiAutocomplete } from './tng-multi-autocomplete';\n\ntype MaybeRect = Readonly<{ left: number; top: number; width: number; height: number }>;\n\nconst PORTALLED_MULTI_AUTOCOMPLETE_THEME_VARS = [\n '--tng-multi-autocomplete-radius',\n '--tng-multi-autocomplete-padding',\n '--tng-multi-autocomplete-trigger-py',\n '--tng-multi-autocomplete-trigger-px',\n '--tng-multi-autocomplete-chip-py',\n '--tng-multi-autocomplete-chip-px',\n '--tng-multi-autocomplete-option-py',\n '--tng-multi-autocomplete-option-px',\n '--tng-multi-autocomplete-z-overlay',\n '--tng-multi-autocomplete-overlay-z-index',\n '--tng-z-overlay',\n '--tng-multi-autocomplete-border',\n '--tng-multi-autocomplete-border-strong',\n '--tng-multi-autocomplete-bg',\n '--tng-multi-autocomplete-surface',\n '--tng-multi-autocomplete-fg',\n '--tng-multi-autocomplete-muted',\n '--tng-multi-autocomplete-brand',\n '--tng-multi-autocomplete-danger',\n '--tng-multi-autocomplete-focus-ring',\n '--tng-multi-autocomplete-ease',\n '--tng-multi-autocomplete-shadow',\n '--tng-multi-autocomplete-shadow-focus',\n] as const;\n\nfunction rectFromClientRect(r: DOMRect | ClientRect): MaybeRect {\n return { left: r.left, top: r.top, width: r.width, height: r.height };\n}\n\nfunction viewportRect(): MaybeRect {\n return {\n left: 0,\n top: 0,\n width: window.innerWidth || 1024,\n height: window.innerHeight || 768,\n };\n}\n\nfunction isInside(target: EventTarget | null, container: HTMLElement): boolean {\n return !!target && target instanceof Node && container.contains(target);\n}\n\n@Directive({\n selector: '[tngMultiAutocompleteOverlay]',\n exportAs: 'tngMultiAutocompleteOverlay',\n})\nexport class TngMultiAutocompleteOverlay {\n private readonly multi = inject<TngMultiAutocomplete>(TNG_MULTI_AUTOCOMPLETE);\n private readonly elRef = inject(ElementRef<HTMLElement>);\n private readonly destroyRef = inject(DestroyRef);\n\n private removeResizeListener: (() => void) | null = null;\n private removeScrollListener: (() => void) | null = null;\n private resizeObserver: ResizeObserver | null = null;\n private removeDocPointerListener: (() => void) | null = null;\n private placeholder: Comment | null = null;\n private originalParent: Node | null = null;\n\n @HostBinding('attr.data-slot')\n protected readonly dataSlot = 'multi-autocomplete-overlay' as const;\n\n @HostBinding('attr.hidden')\n protected get hidden(): '' | null {\n return this.multi.open() ? null : '';\n }\n\n constructor() {\n const hostEl = this.elRef.nativeElement;\n this.placeholder = document.createComment('tng-multi-autocomplete-overlay-anchor');\n this.originalParent = hostEl.parentNode;\n this.originalParent?.insertBefore(this.placeholder, hostEl);\n this.multi.setOverlayElement(hostEl);\n\n effect(() => {\n const open = this.multi.open();\n if (open) {\n this.mountToBodyAndPosition();\n } else {\n this.restoreToPlaceholder();\n }\n });\n\n this.destroyRef.onDestroy(() => {\n this.teardownOutsidePointer();\n this.restoreToPlaceholder(true);\n this.multi.setOverlayElement(null);\n this.placeholder = null;\n this.originalParent = null;\n });\n }\n\n private findAnchorEl(): HTMLElement {\n return this.multi.hostElement;\n }\n\n private reposition(): void {\n if (!this.multi.open()) return;\n\n const panel = this.elRef.nativeElement;\n const anchorEl = this.findAnchorEl();\n const anchor = rectFromClientRect(anchorEl.getBoundingClientRect());\n const overlay = rectFromClientRect(panel.getBoundingClientRect());\n const viewport = viewportRect();\n const result = computeOverlayPosition({\n anchorRect: anchor,\n overlayRect: overlay,\n viewportRect: viewport,\n });\n\n panel.style.left = `${result.x}px`;\n panel.style.top = `${result.y}px`;\n }\n\n private setupRepositionListeners(): void {\n let rafId: number | null = null;\n\n const schedule = () => {\n if (rafId !== null) return;\n\n rafId = requestAnimationFrame(() => {\n rafId = null;\n this.reposition();\n });\n };\n\n const onResize = () => schedule();\n const onScroll = () => schedule();\n\n window.addEventListener('resize', onResize);\n window.addEventListener('scroll', onScroll, true);\n this.removeResizeListener = () => window.removeEventListener('resize', onResize);\n this.removeScrollListener = () => window.removeEventListener('scroll', onScroll, true);\n\n if ('ResizeObserver' in window) {\n this.resizeObserver = new ResizeObserver(() => schedule());\n this.resizeObserver.observe(this.findAnchorEl());\n this.resizeObserver.observe(this.elRef.nativeElement);\n }\n }\n\n private teardownRepositionListeners(): void {\n this.removeResizeListener?.();\n this.removeScrollListener?.();\n this.removeResizeListener = null;\n this.removeScrollListener = null;\n this.resizeObserver?.disconnect();\n this.resizeObserver = null;\n }\n\n private setupOutsidePointer(): void {\n if (this.removeDocPointerListener) return;\n\n const onPointerDown = (event: PointerEvent) => {\n if (!this.multi.open()) return;\n\n const panel = this.elRef.nativeElement;\n if (isInside(event.target, panel)) return;\n if (isInside(event.target, this.multi.hostElement)) return;\n if (event.target && (event.target as Element).closest?.('[data-slot=\"multi-autocomplete-option\"]')) {\n return;\n }\n\n this.multi.close();\n };\n\n document.addEventListener('pointerdown', onPointerDown, true);\n this.removeDocPointerListener = () =>\n document.removeEventListener('pointerdown', onPointerDown, true);\n }\n\n private teardownOutsidePointer(): void {\n this.removeDocPointerListener?.();\n this.removeDocPointerListener = null;\n }\n\n private syncPortalledThemeVars(): void {\n const panel = this.elRef.nativeElement;\n const hostStyles = getComputedStyle(this.multi.hostElement);\n\n for (const cssVar of PORTALLED_MULTI_AUTOCOMPLETE_THEME_VARS) {\n const value = hostStyles.getPropertyValue(cssVar).trim();\n if (value) {\n panel.style.setProperty(cssVar, value);\n } else {\n panel.style.removeProperty(cssVar);\n }\n }\n\n const colorScheme = hostStyles.colorScheme?.trim();\n if (colorScheme && colorScheme !== 'normal') {\n panel.style.colorScheme = colorScheme;\n } else {\n panel.style.removeProperty('color-scheme');\n }\n }\n\n private applyPortalledStacking(): void {\n this.elRef.nativeElement.style.zIndex =\n 'var(--tng-multi-autocomplete-z-overlay, var(--tng-multi-autocomplete-overlay-z-index, var(--tng-z-overlay, 2)))';\n }\n\n private clearPortalledThemeVars(): void {\n const panel = this.elRef.nativeElement;\n\n for (const cssVar of PORTALLED_MULTI_AUTOCOMPLETE_THEME_VARS) {\n panel.style.removeProperty(cssVar);\n }\n\n panel.style.removeProperty('color-scheme');\n }\n\n private mountToBodyAndPosition(): void {\n this.setupRepositionListeners();\n\n const panel = this.elRef.nativeElement;\n if (panel.parentNode !== document.body) {\n document.body.appendChild(panel);\n }\n\n panel.style.position = 'fixed';\n panel.style.left = '0px';\n panel.style.top = '0px';\n this.syncPortalledThemeVars();\n this.applyPortalledStacking();\n\n queueMicrotask(() => {\n if (!this.multi.open()) return;\n\n const anchor = rectFromClientRect(this.findAnchorEl().getBoundingClientRect());\n const viewportWidth = viewportRect().width;\n const inlineSize = Math.max(0, Math.min(anchor.width, viewportWidth - 16));\n panel.style.width = `${inlineSize}px`;\n panel.style.minWidth = `${inlineSize}px`;\n this.reposition();\n });\n\n this.setupOutsidePointer();\n }\n\n private restoreToPlaceholder(force = false): void {\n const panel = this.elRef.nativeElement;\n if (!force && panel.parentNode !== document.body) {\n this.teardownOutsidePointer();\n return;\n }\n\n if (this.placeholder?.parentNode) {\n this.placeholder.parentNode.insertBefore(panel, this.placeholder);\n } else if (this.originalParent) {\n this.originalParent.appendChild(panel);\n }\n\n this.teardownRepositionListeners();\n panel.style.position = '';\n panel.style.left = '';\n panel.style.top = '';\n panel.style.zIndex = '';\n panel.style.width = '';\n panel.style.minWidth = '';\n this.clearPortalledThemeVars();\n this.teardownOutsidePointer();\n }\n}\n"]}
1
+ {"version":3,"file":"tng-multi-autocomplete.overlay.js","sourceRoot":"","sources":["../../../../../../../../libs/tailng-ui/primitives/src/lib/form/multi-autocomplete/tng-multi-autocomplete.overlay.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,SAAS,EACT,UAAU,EACV,WAAW,EACX,MAAM,EACN,MAAM,GACP,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;;AAKzE,MAAM,uCAAuC,GAAG;IAC9C,iCAAiC;IACjC,kCAAkC;IAClC,qCAAqC;IACrC,qCAAqC;IACrC,kCAAkC;IAClC,kCAAkC;IAClC,oCAAoC;IACpC,oCAAoC;IACpC,oCAAoC;IACpC,0CAA0C;IAC1C,iBAAiB;IACjB,iCAAiC;IACjC,wCAAwC;IACxC,6BAA6B;IAC7B,kCAAkC;IAClC,6BAA6B;IAC7B,gCAAgC;IAChC,gCAAgC;IAChC,iCAAiC;IACjC,qCAAqC;IACrC,+BAA+B;IAC/B,iCAAiC;IACjC,uCAAuC;CAC/B,CAAC;AAEX,SAAS,kBAAkB,CAAC,CAAuB;IACjD,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,GAAG,EAAE,CAAC,CAAC,GAAG,EAAE,KAAK,EAAE,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC,MAA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ular/core';\nimport { computeOverlayPosition } from '@tailng-ui/cdk';\nimport { TNG_MULTI_AUTOCOMPLETE } from './tng-multi-autocomplete.tokens';\nimport type { TngMultiAutocomplete } from './tng-multi-autocomplete';\n\ntype MaybeRect = Readonly<{ left: number; top: number; width: number; height: number }>;\n\nconst PORTALLED_MULTI_AUTOCOMPLETE_THEME_VARS = [\n '--tng-multi-autocomplete-radius',\n '--tng-multi-autocomplete-padding',\n '--tng-multi-autocomplete-trigger-py',\n '--tng-multi-autocomplete-trigger-px',\n '--tng-multi-autocomplete-chip-py',\n '--tng-multi-autocomplete-chip-px',\n '--tng-multi-autocomplete-option-py',\n '--tng-multi-autocomplete-option-px',\n '--tng-multi-autocomplete-z-overlay',\n '--tng-multi-autocomplete-overlay-z-index',\n '--tng-z-overlay',\n '--tng-multi-autocomplete-border',\n '--tng-multi-autocomplete-border-strong',\n '--tng-multi-autocomplete-bg',\n '--tng-multi-autocomplete-surface',\n '--tng-multi-autocomplete-fg',\n '--tng-multi-autocomplete-muted',\n '--tng-multi-autocomplete-brand',\n '--tng-multi-autocomplete-danger',\n '--tng-multi-autocomplete-focus-ring',\n '--tng-multi-autocomplete-ease',\n '--tng-multi-autocomplete-shadow',\n '--tng-multi-autocomplete-shadow-focus',\n] as const;\n\nfunction rectFromClientRect(r: DOMRect | ClientRect): MaybeRect {\n return { left: r.left, top: r.top, width: r.width, height: r.height };\n}\n\nfunction viewportRect(): MaybeRect {\n return {\n left: 0,\n top: 0,\n width: window.innerWidth || 1024,\n height: window.innerHeight || 768,\n };\n}\n\nfunction isInside(target: EventTarget | null, container: HTMLElement): boolean {\n return !!target && target instanceof Node && container.contains(target);\n}\n\n/**\n * When the overlay's host element lives inside a `tng-form-field`, the form-field\n * is the visible frame the consumer sees, so the overlay should align with it\n * (width + left/right edges). For the `left` label layout the form-field's root\n * spans the label column too, so anchor on the inner control-row instead.\n */\nfunction findFormFieldAnchor(host: HTMLElement): HTMLElement | null {\n const formField = host.closest('[data-slot=\"form-field\"]') as HTMLElement | null;\n if (!formField) return null;\n if (formField.getAttribute('data-label-position') === 'left') {\n const row = formField.querySelector('.tng-form-field__control-row') as HTMLElement | null;\n return row ?? formField;\n }\n return formField;\n}\n\n/**\n * Rect to use for overlay positioning. When the anchor is a form-field root, the\n * horizontal extent is taken from the form-field (so the overlay spans the field\n * frame) but the vertical extent is taken from the inner fieldset (the input row)\n * so the overlay opens directly under the input rather than below the messages\n * region beneath the frame.\n */\nfunction anchorRectFor(anchorEl: HTMLElement): MaybeRect {\n const widthRect = anchorEl.getBoundingClientRect();\n if (!anchorEl.matches('[data-slot=\"form-field\"]')) {\n return rectFromClientRect(widthRect);\n }\n const labelPosition = anchorEl.getAttribute('data-label-position');\n const fieldset = anchorEl.querySelector('[data-slot=\"form-field-control-row\"]') as HTMLElement | null;\n const innerRow = anchorEl.querySelector('.tng-form-field__control-row') as HTMLElement | null;\n const positionEl = labelPosition === 'outline' ? (fieldset ?? innerRow) : (innerRow ?? fieldset);\n if (!positionEl) return rectFromClientRect(widthRect);\n const positionRect = positionEl.getBoundingClientRect();\n return {\n left: widthRect.left,\n width: widthRect.width,\n top: positionRect.top,\n height: positionRect.height,\n };\n}\n\n@Directive({\n selector: '[tngMultiAutocompleteOverlay]',\n exportAs: 'tngMultiAutocompleteOverlay',\n})\nexport class TngMultiAutocompleteOverlay {\n private readonly multi = inject<TngMultiAutocomplete>(TNG_MULTI_AUTOCOMPLETE);\n private readonly elRef = inject(ElementRef<HTMLElement>);\n private readonly destroyRef = inject(DestroyRef);\n\n private removeResizeListener: (() => void) | null = null;\n private removeScrollListener: (() => void) | null = null;\n private resizeObserver: ResizeObserver | null = null;\n private removeDocPointerListener: (() => void) | null = null;\n private placeholder: Comment | null = null;\n private originalParent: Node | null = null;\n\n @HostBinding('attr.data-slot')\n protected readonly dataSlot = 'multi-autocomplete-overlay' as const;\n\n @HostBinding('attr.hidden')\n protected get hidden(): '' | null {\n return this.multi.open() ? null : '';\n }\n\n constructor() {\n const hostEl = this.elRef.nativeElement;\n this.placeholder = document.createComment('tng-multi-autocomplete-overlay-anchor');\n this.originalParent = hostEl.parentNode;\n this.originalParent?.insertBefore(this.placeholder, hostEl);\n this.multi.setOverlayElement(hostEl);\n\n effect(() => {\n const open = this.multi.open();\n if (open) {\n this.mountToBodyAndPosition();\n } else {\n this.restoreToPlaceholder();\n }\n });\n\n this.destroyRef.onDestroy(() => {\n this.teardownOutsidePointer();\n this.restoreToPlaceholder(true);\n this.multi.setOverlayElement(null);\n this.placeholder = null;\n this.originalParent = null;\n });\n }\n\n /**\n * Anchor for overlay positioning, width, and dismiss boundary.\n * Prefer the enclosing form-field (so the overlay aligns with the visible\n * field frame), else the multi-autocomplete host element itself.\n */\n private findAnchorEl(): HTMLElement {\n return findFormFieldAnchor(this.multi.hostElement) ?? this.multi.hostElement;\n }\n\n private reposition(): void {\n if (!this.multi.open()) return;\n\n const panel = this.elRef.nativeElement;\n const anchorEl = this.findAnchorEl();\n const anchor = anchorRectFor(anchorEl);\n const overlay = rectFromClientRect(panel.getBoundingClientRect());\n const viewport = viewportRect();\n const result = computeOverlayPosition({\n anchorRect: anchor,\n overlayRect: overlay,\n viewportRect: viewport,\n });\n\n panel.style.left = `${result.x}px`;\n panel.style.top = `${result.y}px`;\n }\n\n private setupRepositionListeners(): void {\n let rafId: number | null = null;\n\n const schedule = () => {\n if (rafId !== null) return;\n\n rafId = requestAnimationFrame(() => {\n rafId = null;\n this.reposition();\n });\n };\n\n const onResize = () => schedule();\n const onScroll = () => schedule();\n\n window.addEventListener('resize', onResize);\n window.addEventListener('scroll', onScroll, true);\n this.removeResizeListener = () => window.removeEventListener('resize', onResize);\n this.removeScrollListener = () => window.removeEventListener('scroll', onScroll, true);\n\n if ('ResizeObserver' in window) {\n this.resizeObserver = new ResizeObserver(() => schedule());\n this.resizeObserver.observe(this.findAnchorEl());\n this.resizeObserver.observe(this.elRef.nativeElement);\n }\n }\n\n private teardownRepositionListeners(): void {\n this.removeResizeListener?.();\n this.removeScrollListener?.();\n this.removeResizeListener = null;\n this.removeScrollListener = null;\n this.resizeObserver?.disconnect();\n this.resizeObserver = null;\n }\n\n private setupOutsidePointer(): void {\n if (this.removeDocPointerListener) return;\n\n const onPointerDown = (event: PointerEvent) => {\n if (!this.multi.open()) return;\n\n const panel = this.elRef.nativeElement;\n if (isInside(event.target, panel)) return;\n if (isInside(event.target, this.findAnchorEl())) return;\n if (event.target && (event.target as Element).closest?.('[data-slot=\"multi-autocomplete-option\"]')) {\n return;\n }\n\n this.multi.close();\n };\n\n document.addEventListener('pointerdown', onPointerDown, true);\n this.removeDocPointerListener = () =>\n document.removeEventListener('pointerdown', onPointerDown, true);\n }\n\n private teardownOutsidePointer(): void {\n this.removeDocPointerListener?.();\n this.removeDocPointerListener = null;\n }\n\n private syncPortalledThemeVars(): void {\n const panel = this.elRef.nativeElement;\n const hostStyles = getComputedStyle(this.multi.hostElement);\n\n for (const cssVar of PORTALLED_MULTI_AUTOCOMPLETE_THEME_VARS) {\n const value = hostStyles.getPropertyValue(cssVar).trim();\n if (value) {\n panel.style.setProperty(cssVar, value);\n } else {\n panel.style.removeProperty(cssVar);\n }\n }\n\n const colorScheme = hostStyles.colorScheme?.trim();\n if (colorScheme && colorScheme !== 'normal') {\n panel.style.colorScheme = colorScheme;\n } else {\n panel.style.removeProperty('color-scheme');\n }\n }\n\n private applyPortalledStacking(): void {\n this.elRef.nativeElement.style.zIndex =\n 'var(--tng-multi-autocomplete-z-overlay, var(--tng-multi-autocomplete-overlay-z-index, var(--tng-z-overlay, 2)))';\n }\n\n private clearPortalledThemeVars(): void {\n const panel = this.elRef.nativeElement;\n\n for (const cssVar of PORTALLED_MULTI_AUTOCOMPLETE_THEME_VARS) {\n panel.style.removeProperty(cssVar);\n }\n\n panel.style.removeProperty('color-scheme');\n }\n\n private mountToBodyAndPosition(): void {\n this.setupRepositionListeners();\n\n const panel = this.elRef.nativeElement;\n if (panel.parentNode !== document.body) {\n document.body.appendChild(panel);\n }\n\n panel.style.position = 'fixed';\n panel.style.left = '0px';\n panel.style.top = '0px';\n this.syncPortalledThemeVars();\n this.applyPortalledStacking();\n\n queueMicrotask(() => {\n if (!this.multi.open()) return;\n\n const anchor = anchorRectFor(this.findAnchorEl());\n const viewportWidth = viewportRect().width;\n const inlineSize = Math.max(0, Math.min(anchor.width, viewportWidth - 16));\n panel.style.width = `${inlineSize}px`;\n panel.style.minWidth = `${inlineSize}px`;\n this.reposition();\n });\n\n this.setupOutsidePointer();\n }\n\n private restoreToPlaceholder(force = false): void {\n const panel = this.elRef.nativeElement;\n if (!force && panel.parentNode !== document.body) {\n this.teardownOutsidePointer();\n return;\n }\n\n if (this.placeholder?.parentNode) {\n this.placeholder.parentNode.insertBefore(panel, this.placeholder);\n } else if (this.originalParent) {\n this.originalParent.appendChild(panel);\n }\n\n this.teardownRepositionListeners();\n panel.style.position = '';\n panel.style.left = '';\n panel.style.top = '';\n panel.style.zIndex = '';\n panel.style.width = '';\n panel.style.minWidth = '';\n this.clearPortalledThemeVars();\n this.teardownOutsidePointer();\n }\n}\n"]}