tyrell-components 1.0.0-TC51 → 1.0.0-TC53

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 (108) hide show
  1. package/css/tyrell-theme.css +25 -2
  2. package/css/tyrell.css +4 -0
  3. package/dist/tyrell-colors-static.css +1 -316
  4. package/dist/tyrell-theme.css +1 -1443
  5. package/dist/tyrell.css +1 -1390
  6. package/dist/tyrell.js +1 -1
  7. package/lib/base/ty-component.js +196 -196
  8. package/lib/components/button.d.ts +1 -1
  9. package/lib/components/button.js +260 -259
  10. package/lib/components/calendar-month.d.ts +2 -2
  11. package/lib/components/calendar-month.js +426 -416
  12. package/lib/components/calendar-navigation.js +238 -238
  13. package/lib/components/calendar.js +605 -602
  14. package/lib/components/checkbox.d.ts +1 -1
  15. package/lib/components/checkbox.js +273 -272
  16. package/lib/components/copy.d.ts +1 -1
  17. package/lib/components/copy.js +279 -278
  18. package/lib/components/date-picker.d.ts +1 -1
  19. package/lib/components/date-picker.js +1103 -1108
  20. package/lib/components/file-upload.js +404 -404
  21. package/lib/components/icon.js +141 -141
  22. package/lib/components/input.d.ts +1 -1
  23. package/lib/components/input.js +593 -596
  24. package/lib/components/modal.js +319 -319
  25. package/lib/components/option.js +167 -167
  26. package/lib/components/popup.js +233 -233
  27. package/lib/components/radio.d.ts +2 -2
  28. package/lib/components/radio.js +407 -406
  29. package/lib/components/resize-observer.js +67 -67
  30. package/lib/components/scroll-container.js +294 -294
  31. package/lib/components/select.d.ts +1 -1
  32. package/lib/components/select.js +1524 -1532
  33. package/lib/components/selected-tags.js +184 -184
  34. package/lib/components/step.js +62 -62
  35. package/lib/components/switch.d.ts +1 -1
  36. package/lib/components/switch.js +214 -213
  37. package/lib/components/tab.js +62 -62
  38. package/lib/components/tabs.d.ts +1 -0
  39. package/lib/components/tabs.js +507 -479
  40. package/lib/components/tag.d.ts +1 -1
  41. package/lib/components/tag.js +236 -235
  42. package/lib/components/textarea.d.ts +1 -1
  43. package/lib/components/textarea.js +457 -456
  44. package/lib/components/tooltip.js +283 -283
  45. package/lib/components/wizard.js +384 -384
  46. package/lib/icons/heroicons/micro.js +392 -392
  47. package/lib/icons/heroicons/mini.js +382 -382
  48. package/lib/icons/heroicons/outline.js +337 -337
  49. package/lib/icons/heroicons/solid.js +407 -407
  50. package/lib/icons/lucide.js +22843 -22843
  51. package/lib/icons/material/filled.js +9653 -9653
  52. package/lib/icons/material/outlined.js +10271 -10271
  53. package/lib/icons/material/round.js +10495 -10495
  54. package/lib/icons/material/sharp.js +9905 -9905
  55. package/lib/icons/material/two-tone.js +12792 -12792
  56. package/lib/index.js +21 -21
  57. package/lib/styles/button.js +176 -288
  58. package/lib/styles/calendar-month.js +123 -183
  59. package/lib/styles/calendar-navigation.js +60 -79
  60. package/lib/styles/calendar.js +8 -9
  61. package/lib/styles/checkbox.js +45 -72
  62. package/lib/styles/copy.js +67 -91
  63. package/lib/styles/custom-scrollbar.js +80 -100
  64. package/lib/styles/date-picker.js +261 -331
  65. package/lib/styles/field-size.d.ts +6 -0
  66. package/lib/styles/field-size.js +91 -0
  67. package/lib/styles/file-upload.js +139 -169
  68. package/lib/styles/icon.js +92 -156
  69. package/lib/styles/input.js +125 -241
  70. package/lib/styles/modal.js +67 -102
  71. package/lib/styles/option.d.ts +1 -1
  72. package/lib/styles/option.js +47 -67
  73. package/lib/styles/popup.js +34 -65
  74. package/lib/styles/radio.js +69 -96
  75. package/lib/styles/resize-observer.js +2 -5
  76. package/lib/styles/scroll-container.js +100 -130
  77. package/lib/styles/select-base.js +525 -778
  78. package/lib/styles/select.js +140 -228
  79. package/lib/styles/step.js +22 -29
  80. package/lib/styles/switch.js +34 -55
  81. package/lib/styles/tab.d.ts +1 -1
  82. package/lib/styles/tab.js +22 -29
  83. package/lib/styles/tabs.d.ts +1 -1
  84. package/lib/styles/tabs.js +175 -237
  85. package/lib/styles/tag.js +135 -188
  86. package/lib/styles/textarea.d.ts +1 -1
  87. package/lib/styles/textarea.js +205 -271
  88. package/lib/styles/tooltip.js +3 -3
  89. package/lib/styles/wizard.js +170 -226
  90. package/lib/types/common.d.ts +2 -0
  91. package/lib/types/common.js +6 -5
  92. package/lib/utils/calendar-utils.js +100 -100
  93. package/lib/utils/custom-scrollbar.js +272 -272
  94. package/lib/utils/flavor-sheet.js +14 -14
  95. package/lib/utils/icon-registry.js +127 -127
  96. package/lib/utils/loader-registry.js +3 -3
  97. package/lib/utils/locale.js +34 -34
  98. package/lib/utils/mobile.js +1 -1
  99. package/lib/utils/number-format.js +54 -54
  100. package/lib/utils/positioning.js +212 -212
  101. package/lib/utils/property-capture.js +36 -36
  102. package/lib/utils/property-manager.js +125 -125
  103. package/lib/utils/resize-observer.js +23 -23
  104. package/lib/utils/scroll-lock.js +57 -57
  105. package/lib/utils/styles.js +17 -17
  106. package/lib/version.d.ts +1 -1
  107. package/lib/version.js +1 -1
  108. package/package.json +4 -4
@@ -3,551 +3,579 @@ import { tabsStyles } from '../styles/tabs.js';
3
3
  const eventHandlers = new WeakMap();
4
4
  const resizeObservers = new WeakMap();
5
5
  function getTabsAttributes(el) {
6
- return {
7
- width: el.getAttribute('width') || '100%',
8
- height: el.getAttribute('height') || '400px',
9
- active: el.getAttribute('active'),
10
- placement: (el.getAttribute('placement') || 'top'),
11
- };
6
+ return {
7
+ width: el.getAttribute('width') || '100%',
8
+ height: el.getAttribute('height') || '400px',
9
+ active: el.getAttribute('active'),
10
+ placement: (el.getAttribute('placement') || 'top'),
11
+ fixed: el.hasAttribute('fixed'),
12
+ };
12
13
  }
13
14
  function getChildTabs(el) {
14
- return Array.from(el.querySelectorAll('ty-tab'));
15
+ return Array.from(el.querySelectorAll('ty-tab'));
15
16
  }
16
17
  function getTabId(tab) {
17
- return tab.getAttribute('id');
18
+ return tab.getAttribute('id');
18
19
  }
19
20
  function getSlotLabel(tabsEl, tabId) {
20
- return tabsEl.querySelector(`:scope > [slot='label-${tabId}']`);
21
+ return tabsEl.querySelector(`:scope > [slot='label-${tabId}']`);
21
22
  }
22
23
  function hasSlotLabel(tabsEl, tabId) {
23
- return getSlotLabel(tabsEl, tabId) !== null;
24
+ return getSlotLabel(tabsEl, tabId) !== null;
24
25
  }
25
26
  function getTabLabelType(tabsEl, tab) {
26
- const tabId = getTabId(tab);
27
- if (tabId && hasSlotLabel(tabsEl, tabId)) {
28
- return 'slot';
29
- }
30
- return 'text';
27
+ const tabId = getTabId(tab);
28
+ if (tabId && hasSlotLabel(tabsEl, tabId)) {
29
+ return 'slot';
30
+ }
31
+ return 'text';
31
32
  }
32
33
  function isTabDisabled(tab) {
33
- return tab.hasAttribute('disabled');
34
+ return tab.hasAttribute('disabled');
34
35
  }
35
36
  function hasCustomMarker(el) {
36
- return el.querySelector('[slot="marker"]') !== null;
37
+ return el.querySelector('[slot="marker"]') !== null;
37
38
  }
38
39
  function findTabIndex(tabs, tabId) {
39
- const index = tabs.findIndex(tab => getTabId(tab) === tabId);
40
- return index >= 0 ? index : undefined;
40
+ const index = tabs.findIndex(tab => getTabId(tab) === tabId);
41
+ return index >= 0 ? index : undefined;
41
42
  }
42
43
  function getActiveTabId(el, tabs) {
43
- const activeAttr = el.getAttribute('active');
44
- if (activeAttr && findTabIndex(tabs, activeAttr) !== undefined) {
45
- return activeAttr;
46
- }
47
- if (tabs.length > 0) {
48
- return getTabId(tabs[0]);
49
- }
50
- return null;
44
+ const activeAttr = el.getAttribute('active');
45
+ if (activeAttr && findTabIndex(tabs, activeAttr) !== undefined) {
46
+ return activeAttr;
47
+ }
48
+ if (tabs.length > 0) {
49
+ return getTabId(tabs[0]);
50
+ }
51
+ return null;
51
52
  }
52
53
  function setActiveTab(el, tabId) {
53
- el.setAttribute('active', tabId);
54
+ el.setAttribute('active', tabId);
54
55
  }
55
56
  function dispatchTabChangeEvent(el, activeId, activeIndex, previousId, previousIndex) {
56
- const event = new CustomEvent('ty-tab-change', {
57
- detail: {
58
- activeId,
59
- activeIndex,
60
- previousId,
61
- previousIndex,
62
- },
63
- bubbles: true,
64
- cancelable: false,
65
- });
66
- el.dispatchEvent(event);
57
+ const event = new CustomEvent('ty-tab-change', {
58
+ detail: {
59
+ activeId,
60
+ activeIndex,
61
+ previousId,
62
+ previousIndex,
63
+ },
64
+ bubbles: true,
65
+ cancelable: false,
66
+ });
67
+ el.dispatchEvent(event);
67
68
  }
68
69
  function handleTabClick(el, tabId, event) {
69
- event.preventDefault();
70
- event.stopPropagation();
71
- setActiveTab(el, tabId);
70
+ event.preventDefault();
71
+ event.stopPropagation();
72
+ setActiveTab(el, tabId);
72
73
  }
73
74
  function cleanupEventListeners(el) {
74
- const handlers = eventHandlers.get(el);
75
- if (!handlers)
76
- return;
77
- const shadowRoot = el.shadowRoot;
78
- if (!shadowRoot)
79
- return;
80
- handlers.tabClickHandlers.forEach((handler, tabId) => {
81
- const button = shadowRoot.querySelector(`[data-tab-id='${tabId}']`);
82
- if (button) {
83
- button.removeEventListener('pointerdown', handler);
84
- }
85
- });
86
- handlers.tabKeyClickHandlers.forEach((handler, tabId) => {
87
- const button = shadowRoot.querySelector(`[data-tab-id='${tabId}']`);
88
- if (button) {
89
- button.removeEventListener('click', handler);
90
- }
91
- });
92
- handlers.tabClickHandlers.clear();
93
- handlers.tabKeyClickHandlers.clear();
75
+ const handlers = eventHandlers.get(el);
76
+ if (!handlers)
77
+ return;
78
+ const shadowRoot = el.shadowRoot;
79
+ if (!shadowRoot)
80
+ return;
81
+ handlers.tabClickHandlers.forEach((handler, tabId) => {
82
+ const button = shadowRoot.querySelector(`[data-tab-id='${tabId}']`);
83
+ if (button) {
84
+ button.removeEventListener('pointerdown', handler);
85
+ }
86
+ });
87
+ handlers.tabKeyClickHandlers.forEach((handler, tabId) => {
88
+ const button = shadowRoot.querySelector(`[data-tab-id='${tabId}']`);
89
+ if (button) {
90
+ button.removeEventListener('click', handler);
91
+ }
92
+ });
93
+ handlers.tabClickHandlers.clear();
94
+ handlers.tabKeyClickHandlers.clear();
94
95
  }
95
96
  function setupEventListeners(el, shadowRoot, tabs) {
96
- cleanupEventListeners(el);
97
- const handlers = {
98
- tabClickHandlers: new Map(),
99
- tabKeyClickHandlers: new Map(),
100
- };
101
- tabs.forEach((tab) => {
102
- const tabId = getTabId(tab);
103
- if (!tabId)
104
- return;
105
- const button = shadowRoot.querySelector(`[data-tab-id='${tabId}']`);
106
- if (button) {
107
- const handler = (e) => handleTabClick(el, tabId, e);
108
- const keyClickHandler = (e) => {
109
- if (e.detail === 0)
110
- handleTabClick(el, tabId, e);
111
- };
112
- button.addEventListener('pointerdown', handler);
113
- button.addEventListener('click', keyClickHandler);
114
- handlers.tabClickHandlers.set(tabId, handler);
115
- handlers.tabKeyClickHandlers.set(tabId, keyClickHandler);
116
- }
117
- });
118
- eventHandlers.set(el, handlers);
97
+ cleanupEventListeners(el);
98
+ const handlers = {
99
+ tabClickHandlers: new Map(),
100
+ tabKeyClickHandlers: new Map(),
101
+ };
102
+ tabs.forEach((tab) => {
103
+ const tabId = getTabId(tab);
104
+ if (!tabId)
105
+ return;
106
+ const button = shadowRoot.querySelector(`[data-tab-id='${tabId}']`);
107
+ if (button) {
108
+ const handler = (e) => handleTabClick(el, tabId, e);
109
+ const keyClickHandler = (e) => {
110
+ if (e.detail === 0)
111
+ handleTabClick(el, tabId, e);
112
+ };
113
+ button.addEventListener('pointerdown', handler);
114
+ button.addEventListener('click', keyClickHandler);
115
+ handlers.tabClickHandlers.set(tabId, handler);
116
+ handlers.tabKeyClickHandlers.set(tabId, keyClickHandler);
117
+ }
118
+ });
119
+ eventHandlers.set(el, handlers);
119
120
  }
120
121
  function updateTransform(el, activeIndex) {
121
- const shadowRoot = el.shadowRoot;
122
- if (!shadowRoot)
123
- return;
124
- const panelsWrapper = shadowRoot.querySelector('.panels-wrapper');
125
- if (!panelsWrapper)
126
- return;
127
- const containerWidth = el.offsetWidth;
128
- const offsetPx = activeIndex * containerWidth;
129
- panelsWrapper.style.transform = `translateX(-${offsetPx}px)`;
122
+ const shadowRoot = el.shadowRoot;
123
+ if (!shadowRoot)
124
+ return;
125
+ const panelsWrapper = shadowRoot.querySelector('.panels-wrapper');
126
+ if (!panelsWrapper)
127
+ return;
128
+ const containerWidth = el.offsetWidth;
129
+ const offsetPx = activeIndex * containerWidth;
130
+ panelsWrapper.style.transform = `translateX(-${offsetPx}px)`;
130
131
  }
131
132
  function updateAriaAttributes(el, shadowRoot, activeId) {
132
- const tabs = getChildTabs(el);
133
- tabs.forEach((tab, idx) => {
134
- const tabId = getTabId(tab);
135
- if (!tabId)
136
- return;
137
- const button = shadowRoot.querySelector(`[data-tab-id='${tabId}']`);
138
- const isActive = tabId === activeId;
139
- if (button) {
140
- button.setAttribute('aria-selected', String(isActive));
141
- button.setAttribute('tabindex', isActive ? '0' : '-1');
142
- button.setAttribute('data-active', String(isActive));
143
- const slottedLabel = getSlotLabel(el, tabId);
144
- if (slottedLabel) {
145
- slottedLabel.setAttribute('data-active', String(isActive));
146
- }
147
- }
148
- });
133
+ const tabs = getChildTabs(el);
134
+ tabs.forEach((tab, idx) => {
135
+ const tabId = getTabId(tab);
136
+ if (!tabId)
137
+ return;
138
+ const button = shadowRoot.querySelector(`[data-tab-id='${tabId}']`);
139
+ const isActive = tabId === activeId;
140
+ if (button) {
141
+ button.setAttribute('aria-selected', String(isActive));
142
+ button.setAttribute('tabindex', isActive ? '0' : '-1');
143
+ button.setAttribute('data-active', String(isActive));
144
+ const slottedLabel = getSlotLabel(el, tabId);
145
+ if (slottedLabel) {
146
+ slottedLabel.setAttribute('data-active', String(isActive));
147
+ }
148
+ }
149
+ });
149
150
  }
150
151
  function updatePanelInteraction(el, activeId) {
151
- const tabs = getChildTabs(el);
152
- tabs.forEach((tab) => {
153
- const tabId = getTabId(tab);
154
- if (!tabId)
155
- return;
156
- const isActive = tabId === activeId;
157
- tab.setAttribute('data-active', String(isActive));
158
- if (isActive) {
159
- tab.style.pointerEvents = 'auto';
160
- tab.style.opacity = '1';
161
- }
162
- else {
163
- tab.style.pointerEvents = 'none';
164
- tab.style.opacity = '0';
165
- }
166
- });
152
+ const tabs = getChildTabs(el);
153
+ tabs.forEach((tab) => {
154
+ const tabId = getTabId(tab);
155
+ if (!tabId)
156
+ return;
157
+ const isActive = tabId === activeId;
158
+ tab.setAttribute('data-active', String(isActive));
159
+ if (isActive) {
160
+ tab.style.pointerEvents = 'auto';
161
+ tab.style.opacity = '1';
162
+ }
163
+ else {
164
+ tab.style.pointerEvents = 'none';
165
+ tab.style.opacity = '0';
166
+ }
167
+ });
167
168
  }
168
169
  function calculateMarkerPosition(el, shadowRoot, activeId) {
169
- const button = shadowRoot.querySelector(`[data-tab-id='${activeId}']`);
170
- const buttonsContainer = shadowRoot.querySelector('.tab-buttons');
171
- if (!button || !buttonsContainer)
172
- return null;
173
- const buttonRect = button.getBoundingClientRect();
174
- const left = button.offsetLeft;
175
- const top = button.offsetTop;
176
- return {
177
- left,
178
- top,
179
- width: buttonRect.width,
180
- height: buttonRect.height,
181
- };
170
+ const button = shadowRoot.querySelector(`[data-tab-id='${activeId}']`);
171
+ const buttonsContainer = shadowRoot.querySelector('.tab-buttons');
172
+ if (!button || !buttonsContainer)
173
+ return null;
174
+ const buttonRect = button.getBoundingClientRect();
175
+ const left = button.offsetLeft;
176
+ const top = button.offsetTop;
177
+ return {
178
+ left,
179
+ top,
180
+ width: buttonRect.width,
181
+ height: buttonRect.height,
182
+ };
182
183
  }
183
184
  function updateMarker(el, activeId) {
184
- const shadowRoot = el.shadowRoot;
185
- if (!shadowRoot)
186
- return;
187
- const marker = shadowRoot.querySelector('.marker-wrapper');
188
- if (!marker)
189
- return;
190
- const position = calculateMarkerPosition(el, shadowRoot, activeId);
191
- if (!position)
192
- return;
193
- const snap = !marker.style.left || marker.offsetWidth === 0;
194
- if (snap)
195
- marker.style.transition = 'none';
196
- marker.style.left = `${position.left}px`;
197
- marker.style.top = `${position.top}px`;
198
- marker.style.width = `${position.width}px`;
199
- marker.style.height = `${position.height}px`;
200
- if (snap) {
201
- marker.offsetWidth;
202
- marker.style.transition = '';
203
- }
185
+ const shadowRoot = el.shadowRoot;
186
+ if (!shadowRoot)
187
+ return;
188
+ const marker = shadowRoot.querySelector('.marker-wrapper');
189
+ if (!marker)
190
+ return;
191
+ const position = calculateMarkerPosition(el, shadowRoot, activeId);
192
+ if (!position)
193
+ return;
194
+ const snap = !marker.style.left || marker.offsetWidth === 0;
195
+ if (snap)
196
+ marker.style.transition = 'none';
197
+ marker.style.left = `${position.left}px`;
198
+ marker.style.top = `${position.top}px`;
199
+ marker.style.width = `${position.width}px`;
200
+ marker.style.height = `${position.height}px`;
201
+ if (snap) {
202
+ marker.offsetWidth;
203
+ marker.style.transition = '';
204
+ }
204
205
  }
205
206
  function updateActiveTabState(el, tabId, previousId) {
206
- const tabs = getChildTabs(el);
207
- const shadowRoot = el.shadowRoot;
208
- if (!shadowRoot)
209
- return;
210
- const currentIndex = previousId ? findTabIndex(tabs, previousId) : undefined;
211
- const newIndex = findTabIndex(tabs, tabId);
212
- if (previousId === tabId || newIndex === undefined)
213
- return;
214
- el.style.setProperty('--active-index', String(newIndex));
215
- updateTransform(el, newIndex);
216
- updateAriaAttributes(el, shadowRoot, tabId);
217
- updatePanelInteraction(el, tabId);
218
- updateMarker(el, tabId);
219
- const newPanel = tabs[newIndex];
220
- if (newPanel?.resetScroll) {
221
- newPanel.resetScroll();
222
- }
223
- dispatchTabChangeEvent(el, tabId, newIndex, previousId, currentIndex ?? null);
207
+ const tabs = getChildTabs(el);
208
+ const shadowRoot = el.shadowRoot;
209
+ if (!shadowRoot)
210
+ return;
211
+ const currentIndex = previousId ? findTabIndex(tabs, previousId) : undefined;
212
+ const newIndex = findTabIndex(tabs, tabId);
213
+ if (previousId === tabId || newIndex === undefined)
214
+ return;
215
+ el.style.setProperty('--active-index', String(newIndex));
216
+ updateTransform(el, newIndex);
217
+ updateAriaAttributes(el, shadowRoot, tabId);
218
+ updatePanelInteraction(el, tabId);
219
+ updateMarker(el, tabId);
220
+ shadowRoot.querySelectorAll('.tab-overflow-item').forEach((item) => {
221
+ item.setAttribute('data-active', String(item.dataset.tabId === tabId));
222
+ });
223
+ const newPanel = tabs[newIndex];
224
+ if (newPanel?.resetScroll) {
225
+ newPanel.resetScroll();
226
+ }
227
+ dispatchTabChangeEvent(el, tabId, newIndex, previousId, currentIndex ?? null);
224
228
  }
225
229
  function setupResizeObserver(el) {
226
- const oldObserver = resizeObservers.get(el);
227
- if (oldObserver) {
228
- oldObserver.disconnect();
229
- }
230
- const observer = new ResizeObserver((entries) => {
231
- const entry = entries[0];
232
- const { width } = getTabsAttributes(el);
233
- const tabs = getChildTabs(el);
234
- const activeId = getActiveTabId(el, tabs);
235
- const activeIndex = activeId ? findTabIndex(tabs, activeId) : 0;
236
- if (width.includes('%')) {
237
- el.style.setProperty('--tabs-page-width', `${entry.contentRect.width}px`);
238
- }
239
- if (activeIndex !== undefined) {
240
- updateTransform(el, activeIndex);
241
- }
242
- updateOverflow(el);
243
- if (activeId) {
244
- updateMarker(el, activeId);
245
- scrollActiveIntoView(el, activeId, false);
246
- }
247
- });
248
- observer.observe(el);
249
- resizeObservers.set(el, observer);
230
+ const oldObserver = resizeObservers.get(el);
231
+ if (oldObserver) {
232
+ oldObserver.disconnect();
233
+ }
234
+ const observer = new ResizeObserver((entries) => {
235
+ const entry = entries[0];
236
+ const { width } = getTabsAttributes(el);
237
+ const tabs = getChildTabs(el);
238
+ const activeId = getActiveTabId(el, tabs);
239
+ const activeIndex = activeId ? findTabIndex(tabs, activeId) : 0;
240
+ if (width.includes('%')) {
241
+ el.style.setProperty('--tabs-page-width', `${entry.contentRect.width}px`);
242
+ }
243
+ if (activeIndex !== undefined) {
244
+ updateTransform(el, activeIndex);
245
+ }
246
+ updateOverflow(el);
247
+ if (activeId) {
248
+ updateMarker(el, activeId);
249
+ scrollActiveIntoView(el, activeId, false);
250
+ }
251
+ });
252
+ observer.observe(el);
253
+ resizeObservers.set(el, observer);
250
254
  }
251
255
  function cleanupResizeObserver(el) {
252
- const observer = resizeObservers.get(el);
253
- if (observer) {
254
- observer.disconnect();
255
- resizeObservers.delete(el);
256
- }
256
+ const observer = resizeObservers.get(el);
257
+ if (observer) {
258
+ observer.disconnect();
259
+ resizeObservers.delete(el);
260
+ }
257
261
  }
258
262
  function renderTabButtons(tabsEl, tabs, activeId) {
259
- const buttons = tabs.map((tab) => {
260
- const tabId = getTabId(tab);
261
- if (!tabId)
262
- return '';
263
- const labelType = getTabLabelType(tabsEl, tab);
264
- const textLabel = labelType === 'text' ? (tab.getAttribute('label') || 'Tab') : '';
265
- const disabled = isTabDisabled(tab);
266
- const active = tabId === activeId;
267
- return `<button
268
- class="tab-button"
269
- role="tab"
270
- data-tab-id="${tabId}"
271
- id="tab-${tabId}"
272
- aria-selected="${active}"
273
- tabindex="${active ? '0' : '-1'}"
274
- data-active="${active}"
275
- ${disabled ? 'disabled aria-disabled="true"' : ''}
276
- >
277
- ${labelType === 'slot' ? `<slot name="label-${tabId}"></slot>` : textLabel}
278
- </button>`;
279
- }).join('');
280
- return `
281
- <div class="tab-buttons" role="tablist" part="buttons-container">
282
- <div class="tab-strip" part="strip">
283
- <div class="marker-wrapper" part="marker-wrapper">
284
- ${!hasCustomMarker(tabsEl) ? '<div class="default-marker"></div>' : ''}
285
- <slot name="marker"></slot>
286
- </div>
287
- ${buttons}
288
- </div>
289
- </div>
290
- `;
263
+ const buttons = tabs.map((tab) => {
264
+ const tabId = getTabId(tab);
265
+ if (!tabId)
266
+ return '';
267
+ const labelType = getTabLabelType(tabsEl, tab);
268
+ const textLabel = labelType === 'text' ? (tab.getAttribute('label') || 'Tab') : '';
269
+ const disabled = isTabDisabled(tab);
270
+ const active = tabId === activeId;
271
+ return `<button
272
+ class="tab-button"
273
+ role="tab"
274
+ data-tab-id="${tabId}"
275
+ id="tab-${tabId}"
276
+ aria-selected="${active}"
277
+ tabindex="${active ? '0' : '-1'}"
278
+ data-active="${active}"
279
+ ${disabled ? 'disabled aria-disabled="true"' : ''}
280
+ >
281
+ ${labelType === 'slot' ? `<slot name="label-${tabId}"></slot>` : `<span class="tab-label">${textLabel}</span>`}
282
+ </button>`;
283
+ }).join('');
284
+ return `
285
+ <div class="tab-buttons" role="tablist" part="buttons-container">
286
+ <div class="tab-strip" part="strip">
287
+ <div class="marker-wrapper" part="marker-wrapper">
288
+ ${!hasCustomMarker(tabsEl) ? '<div class="default-marker"></div>' : ''}
289
+ <slot name="marker"></slot>
290
+ </div>
291
+ ${buttons}
292
+ </div>
293
+ </div>
294
+ `;
291
295
  }
292
296
  function renderButtonsOnly(tabsEl, tabs, activeId) {
293
- return tabs.map((tab) => {
294
- const tabId = getTabId(tab);
295
- if (!tabId)
296
- return '';
297
- const labelType = getTabLabelType(tabsEl, tab);
298
- const textLabel = labelType === 'text' ? (tab.getAttribute('label') || 'Tab') : '';
299
- const disabled = isTabDisabled(tab);
300
- const active = tabId === activeId;
301
- return `<button
302
- class="tab-button"
303
- role="tab"
304
- data-tab-id="${tabId}"
305
- id="tab-${tabId}"
306
- aria-selected="${active}"
307
- tabindex="${active ? '0' : '-1'}"
308
- data-active="${active}"
309
- ${disabled ? 'disabled aria-disabled="true"' : ''}
310
- >
311
- ${labelType === 'slot' ? `<slot name="label-${tabId}"></slot>` : textLabel}
312
- </button>`;
313
- }).join('');
297
+ return tabs.map((tab) => {
298
+ const tabId = getTabId(tab);
299
+ if (!tabId)
300
+ return '';
301
+ const labelType = getTabLabelType(tabsEl, tab);
302
+ const textLabel = labelType === 'text' ? (tab.getAttribute('label') || 'Tab') : '';
303
+ const disabled = isTabDisabled(tab);
304
+ const active = tabId === activeId;
305
+ return `<button
306
+ class="tab-button"
307
+ role="tab"
308
+ data-tab-id="${tabId}"
309
+ id="tab-${tabId}"
310
+ aria-selected="${active}"
311
+ tabindex="${active ? '0' : '-1'}"
312
+ data-active="${active}"
313
+ ${disabled ? 'disabled aria-disabled="true"' : ''}
314
+ >
315
+ ${labelType === 'slot' ? `<slot name="label-${tabId}"></slot>` : `<span class="tab-label">${textLabel}</span>`}
316
+ </button>`;
317
+ }).join('');
314
318
  }
315
319
  function getTabMenuLabel(tabsEl, tab) {
316
- const tabId = getTabId(tab);
317
- if (tabId && getTabLabelType(tabsEl, tab) === 'slot') {
318
- const slotted = getSlotLabel(tabsEl, tabId);
319
- return slotted?.textContent?.trim() || tabId;
320
- }
321
- return tab.getAttribute('label') || 'Tab';
320
+ const tabId = getTabId(tab);
321
+ if (tabId && getTabLabelType(tabsEl, tab) === 'slot') {
322
+ const slotted = getSlotLabel(tabsEl, tabId);
323
+ return slotted?.textContent?.trim() || tabId;
324
+ }
325
+ return tab.getAttribute('label') || 'Tab';
322
326
  }
323
327
  function removeOverflowMenu(shadowRoot) {
324
- shadowRoot.querySelector('.tab-overflow-trigger')?.remove();
328
+ shadowRoot.querySelector('.tab-overflow-trigger')?.remove();
325
329
  }
326
330
  function renderOverflowMenu(el, container, allTabs) {
327
- const activeId = getActiveTabId(el, allTabs);
328
- const trigger = document.createElement('button');
329
- trigger.className = 'tab-overflow-trigger';
330
- trigger.type = 'button';
331
- trigger.setAttribute('aria-label', `${allTabs.length} tabs`);
332
- trigger.textContent = '⋯';
333
- const popup = document.createElement('ty-popup');
334
- popup.setAttribute('placement', 'bottom');
335
- const menu = document.createElement('div');
336
- menu.className = 'tab-overflow-menu';
337
- menu.setAttribute('role', 'menu');
338
- allTabs.forEach((tab) => {
339
- const tabId = getTabId(tab);
340
- if (!tabId)
341
- return;
342
- const item = document.createElement('button');
343
- item.type = 'button';
344
- item.className = 'tab-overflow-item';
345
- item.setAttribute('role', 'menuitem');
346
- item.setAttribute('data-active', String(tabId === activeId));
347
- item.textContent = getTabMenuLabel(el, tab);
348
- if (isTabDisabled(tab)) {
349
- item.disabled = true;
350
- }
351
- else {
352
- item.addEventListener('click', () => {
353
- setActiveTab(el, tabId);
354
- popup.closePopup?.();
355
- });
356
- }
357
- menu.appendChild(item);
358
- });
359
- popup.appendChild(menu);
360
- trigger.appendChild(popup);
361
- container.appendChild(trigger);
331
+ const activeId = getActiveTabId(el, allTabs);
332
+ const trigger = document.createElement('button');
333
+ trigger.className = 'tab-overflow-trigger';
334
+ trigger.type = 'button';
335
+ trigger.setAttribute('aria-label', `${allTabs.length} tabs`);
336
+ trigger.textContent = '⋯';
337
+ const popup = document.createElement('ty-popup');
338
+ popup.setAttribute('placement', 'bottom');
339
+ const menu = document.createElement('div');
340
+ menu.className = 'tab-overflow-menu';
341
+ menu.setAttribute('role', 'menu');
342
+ allTabs.forEach((tab) => {
343
+ const tabId = getTabId(tab);
344
+ if (!tabId)
345
+ return;
346
+ const item = document.createElement('button');
347
+ item.type = 'button';
348
+ item.className = 'tab-overflow-item';
349
+ item.setAttribute('role', 'menuitem');
350
+ item.setAttribute('data-tab-id', tabId);
351
+ item.setAttribute('data-active', String(tabId === activeId));
352
+ item.textContent = getTabMenuLabel(el, tab);
353
+ if (isTabDisabled(tab)) {
354
+ item.disabled = true;
355
+ }
356
+ else {
357
+ item.addEventListener('click', () => {
358
+ setActiveTab(el, tabId);
359
+ popup.closePopup?.();
360
+ });
361
+ }
362
+ menu.appendChild(item);
363
+ });
364
+ popup.appendChild(menu);
365
+ trigger.appendChild(popup);
366
+ container.appendChild(trigger);
362
367
  }
363
368
  function updateOverflow(el) {
364
- const shadowRoot = el.shadowRoot;
365
- if (!shadowRoot)
366
- return;
367
- const container = shadowRoot.querySelector('.tab-buttons');
368
- const strip = shadowRoot.querySelector('.tab-strip');
369
- if (!container || !strip)
370
- return;
371
- removeOverflowMenu(shadowRoot);
372
- if (strip.clientWidth <= 0)
373
- return;
374
- updateEdgeFades(strip);
375
- const buttons = strip.querySelectorAll('.tab-button');
376
- const last = buttons[buttons.length - 1];
377
- const contentWidth = last ? last.offsetLeft + last.offsetWidth : 0;
378
- const overflowing = contentWidth > strip.clientWidth + 1;
379
- strip.classList.toggle('unclipped', !overflowing);
380
- if (!overflowing)
381
- return;
382
- renderOverflowMenu(el, container, getChildTabs(el));
369
+ const shadowRoot = el.shadowRoot;
370
+ if (!shadowRoot)
371
+ return;
372
+ const container = shadowRoot.querySelector('.tab-buttons');
373
+ const strip = shadowRoot.querySelector('.tab-strip');
374
+ if (!container || !strip)
375
+ return;
376
+ if (getTabsAttributes(el).fixed) {
377
+ removeOverflowMenu(shadowRoot);
378
+ strip.classList.add('unclipped');
379
+ strip.style.removeProperty('--fade-left');
380
+ strip.style.removeProperty('--fade-right');
381
+ return;
382
+ }
383
+ const savedScrollLeft = strip.scrollLeft;
384
+ removeOverflowMenu(shadowRoot);
385
+ if (strip.clientWidth <= 0)
386
+ return;
387
+ const buttons = strip.querySelectorAll('.tab-button');
388
+ const last = buttons[buttons.length - 1];
389
+ const contentWidth = last ? last.offsetLeft + last.offsetWidth : 0;
390
+ const stripWidth = strip.clientWidth;
391
+ const hidden = contentWidth - stripWidth;
392
+ strip.classList.toggle('unclipped', hidden <= 1);
393
+ if (hidden <= 1) {
394
+ strip.scrollLeft = savedScrollLeft;
395
+ updateEdgeFades(strip);
396
+ return;
397
+ }
398
+ renderOverflowMenu(el, container, getChildTabs(el));
399
+ const triggerCost = container.clientWidth - strip.clientWidth;
400
+ if (hidden <= triggerCost) {
401
+ removeOverflowMenu(shadowRoot);
402
+ }
403
+ strip.scrollLeft = savedScrollLeft;
404
+ updateEdgeFades(strip);
383
405
  }
384
406
  function updateEdgeFades(strip) {
385
- const maxScroll = strip.scrollWidth - strip.clientWidth;
386
- strip.style.setProperty('--fade-left', strip.scrollLeft > 1 ? '28px' : '0px');
387
- strip.style.setProperty('--fade-right', strip.scrollLeft < maxScroll - 1 ? '28px' : '0px');
407
+ const maxScroll = strip.scrollWidth - strip.clientWidth;
408
+ const fade = (distance) => `${distance > 1 ? Math.min(28, distance) : 0}px`;
409
+ strip.style.setProperty('--fade-left', fade(strip.scrollLeft));
410
+ strip.style.setProperty('--fade-right', fade(maxScroll - strip.scrollLeft));
388
411
  }
389
412
  function scrollActiveIntoView(el, activeId, smooth) {
390
- const shadowRoot = el.shadowRoot;
391
- if (!shadowRoot)
392
- return;
393
- const strip = shadowRoot.querySelector('.tab-strip');
394
- const button = shadowRoot.querySelector(`[data-tab-id='${activeId}']`);
395
- if (!strip || !button || strip.clientWidth <= 0)
396
- return;
397
- const centered = button.offsetLeft + button.offsetWidth / 2 - strip.clientWidth / 2;
398
- const target = Math.max(0, Math.min(centered, strip.scrollWidth - strip.clientWidth));
399
- if (Math.round(target) !== Math.round(strip.scrollLeft)) {
400
- const reduce = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
401
- strip.scrollTo({ left: target, behavior: smooth && !reduce ? 'smooth' : 'auto' });
402
- }
413
+ const shadowRoot = el.shadowRoot;
414
+ if (!shadowRoot)
415
+ return;
416
+ const strip = shadowRoot.querySelector('.tab-strip');
417
+ const button = shadowRoot.querySelector(`[data-tab-id='${activeId}']`);
418
+ if (!strip || !button || strip.clientWidth <= 0)
419
+ return;
420
+ const centered = button.offsetLeft + button.offsetWidth / 2 - strip.clientWidth / 2;
421
+ const target = Math.max(0, Math.min(centered, strip.scrollWidth - strip.clientWidth));
422
+ if (Math.round(target) !== Math.round(strip.scrollLeft)) {
423
+ const reduce = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
424
+ strip.scrollTo({ left: target, behavior: smooth && !reduce ? 'smooth' : 'auto' });
425
+ }
403
426
  }
404
427
  function render(el) {
405
- const shadowRoot = el.shadowRoot;
406
- if (!shadowRoot)
407
- return;
408
- const { width, height, placement } = getTabsAttributes(el);
409
- const tabs = getChildTabs(el);
410
- const activeId = getActiveTabId(el, tabs);
411
- const activeIndex = activeId ? (findTabIndex(tabs, activeId) ?? 0) : 0;
412
- tabs.forEach((tab) => {
413
- const tabId = getTabId(tab);
414
- if (!tabId)
415
- return;
416
- tab.setAttribute('role', 'tabpanel');
417
- tab.setAttribute('aria-labelledby', `tab-${tabId}`);
418
- tab.setAttribute('tabindex', '0');
419
- });
420
- const existingContainer = shadowRoot.querySelector('.tabs-container');
421
- const existingButtons = shadowRoot.querySelector('.tab-buttons');
422
- const existingStrip = shadowRoot.querySelector('.tab-strip');
423
- const existingViewport = shadowRoot.querySelector('.panels-viewport');
424
- ensureStyles(shadowRoot, { css: tabsStyles, id: 'ty-tabs' });
425
- el.style.setProperty('--tabs-width', width.includes('%') ? '100%' : width);
426
- el.style.setProperty('--tabs-height', height);
427
- el.style.setProperty('--active-index', String(activeIndex));
428
- if (existingContainer && existingButtons && existingStrip && existingViewport) {
429
- existingContainer.setAttribute('data-placement', placement);
430
- existingButtons.querySelector('.tab-overflow-trigger')?.remove();
431
- const savedScrollLeft = existingStrip.scrollLeft;
432
- const allButtons = existingStrip.querySelectorAll('.tab-button');
433
- allButtons.forEach(button => button.remove());
434
- const buttonsHtml = renderButtonsOnly(el, tabs, activeId);
435
- const tempDiv = document.createElement('div');
436
- tempDiv.innerHTML = buttonsHtml;
437
- Array.from(tempDiv.children).forEach(button => {
438
- existingStrip.appendChild(button);
439
- });
440
- existingStrip.scrollLeft = savedScrollLeft;
441
- setupEventListeners(el, shadowRoot, tabs);
442
- updateAriaAttributes(el, shadowRoot, activeId || '');
443
- requestAnimationFrame(() => {
444
- const buttons = shadowRoot.querySelector('.tab-buttons');
445
- if (buttons) {
446
- const buttonsHeight = buttons.offsetHeight;
447
- el.style.setProperty('--buttons-height', `${buttonsHeight}px`);
448
- }
449
- updateTransform(el, activeIndex);
450
- updateOverflow(el);
451
- if (activeId) {
452
- updateMarker(el, activeId);
453
- scrollActiveIntoView(el, activeId, true);
454
- }
455
- });
456
- if (activeId) {
457
- updatePanelInteraction(el, activeId);
458
- }
459
- }
460
- else {
461
- shadowRoot.innerHTML = `
462
- <div class="tabs-container" data-placement="${placement}">
463
- ${renderTabButtons(el, tabs, activeId)}
464
- <div class="panels-viewport" part="panels-container">
465
- <div class="panels-wrapper">
466
- <slot></slot>
467
- </div>
468
- </div>
469
- </div>
470
- `;
471
- requestAnimationFrame(() => {
472
- const buttons = shadowRoot.querySelector('.tab-buttons');
473
- if (buttons) {
474
- const buttonsHeight = buttons.offsetHeight;
475
- el.style.setProperty('--buttons-height', `${buttonsHeight}px`);
476
- }
477
- updateTransform(el, activeIndex);
478
- updateOverflow(el);
479
- if (activeId) {
480
- updateMarker(el, activeId);
481
- scrollActiveIntoView(el, activeId, false);
482
- }
483
- });
484
- setupEventListeners(el, shadowRoot, tabs);
485
- updateAriaAttributes(el, shadowRoot, activeId || '');
486
- setupResizeObserver(el);
487
- const strip = shadowRoot.querySelector('.tab-strip');
488
- strip?.addEventListener('scroll', () => updateEdgeFades(strip), { passive: true });
489
- if (activeId) {
490
- updatePanelInteraction(el, activeId);
491
- }
492
- const markerSlot = shadowRoot.querySelector('slot[name="marker"]');
493
- if (markerSlot) {
494
- const updateDefaultMarkerVisibility = () => {
495
- const defaultMarker = shadowRoot.querySelector('.default-marker');
496
- if (defaultMarker) {
497
- const hasCustom = markerSlot.assignedElements().length > 0;
498
- defaultMarker.style.display = hasCustom ? 'none' : '';
499
- }
500
- };
501
- markerSlot.addEventListener('slotchange', updateDefaultMarkerVisibility);
502
- updateDefaultMarkerVisibility();
503
- }
504
- }
428
+ const shadowRoot = el.shadowRoot;
429
+ if (!shadowRoot)
430
+ return;
431
+ const { width, height, placement, fixed } = getTabsAttributes(el);
432
+ const tabs = getChildTabs(el);
433
+ const activeId = getActiveTabId(el, tabs);
434
+ const activeIndex = activeId ? (findTabIndex(tabs, activeId) ?? 0) : 0;
435
+ tabs.forEach((tab) => {
436
+ const tabId = getTabId(tab);
437
+ if (!tabId)
438
+ return;
439
+ tab.setAttribute('role', 'tabpanel');
440
+ tab.setAttribute('aria-labelledby', `tab-${tabId}`);
441
+ tab.setAttribute('tabindex', '0');
442
+ });
443
+ const existingContainer = shadowRoot.querySelector('.tabs-container');
444
+ const existingButtons = shadowRoot.querySelector('.tab-buttons');
445
+ const existingStrip = shadowRoot.querySelector('.tab-strip');
446
+ const existingViewport = shadowRoot.querySelector('.panels-viewport');
447
+ ensureStyles(shadowRoot, { css: tabsStyles, id: 'ty-tabs' });
448
+ el.style.setProperty('--tabs-width', width.includes('%') ? '100%' : width);
449
+ el.style.setProperty('--tabs-height', height);
450
+ el.style.setProperty('--active-index', String(activeIndex));
451
+ if (existingContainer && existingButtons && existingStrip && existingViewport) {
452
+ existingContainer.setAttribute('data-placement', placement);
453
+ existingContainer.toggleAttribute('data-fixed', fixed);
454
+ const savedScrollLeft = existingStrip.scrollLeft;
455
+ existingButtons.querySelector('.tab-overflow-trigger')?.remove();
456
+ const allButtons = existingStrip.querySelectorAll('.tab-button');
457
+ allButtons.forEach(button => button.remove());
458
+ const buttonsHtml = renderButtonsOnly(el, tabs, activeId);
459
+ const tempDiv = document.createElement('div');
460
+ tempDiv.innerHTML = buttonsHtml;
461
+ Array.from(tempDiv.children).forEach(button => {
462
+ existingStrip.appendChild(button);
463
+ });
464
+ existingStrip.scrollLeft = savedScrollLeft;
465
+ setupEventListeners(el, shadowRoot, tabs);
466
+ updateAriaAttributes(el, shadowRoot, activeId || '');
467
+ requestAnimationFrame(() => {
468
+ const buttons = shadowRoot.querySelector('.tab-buttons');
469
+ if (buttons) {
470
+ const buttonsHeight = buttons.offsetHeight;
471
+ el.style.setProperty('--buttons-height', `${buttonsHeight}px`);
472
+ }
473
+ updateTransform(el, activeIndex);
474
+ updateOverflow(el);
475
+ if (activeId) {
476
+ updateMarker(el, activeId);
477
+ scrollActiveIntoView(el, activeId, true);
478
+ }
479
+ });
480
+ if (activeId) {
481
+ updatePanelInteraction(el, activeId);
482
+ }
483
+ }
484
+ else {
485
+ shadowRoot.innerHTML = `
486
+ <div class="tabs-container" data-placement="${placement}"${fixed ? ' data-fixed' : ''}>
487
+ ${renderTabButtons(el, tabs, activeId)}
488
+ <div class="panels-viewport" part="panels-container">
489
+ <div class="panels-wrapper">
490
+ <slot></slot>
491
+ </div>
492
+ </div>
493
+ </div>
494
+ `;
495
+ requestAnimationFrame(() => {
496
+ const buttons = shadowRoot.querySelector('.tab-buttons');
497
+ if (buttons) {
498
+ const buttonsHeight = buttons.offsetHeight;
499
+ el.style.setProperty('--buttons-height', `${buttonsHeight}px`);
500
+ }
501
+ updateTransform(el, activeIndex);
502
+ updateOverflow(el);
503
+ if (activeId) {
504
+ updateMarker(el, activeId);
505
+ scrollActiveIntoView(el, activeId, false);
506
+ }
507
+ });
508
+ setupEventListeners(el, shadowRoot, tabs);
509
+ updateAriaAttributes(el, shadowRoot, activeId || '');
510
+ setupResizeObserver(el);
511
+ const strip = shadowRoot.querySelector('.tab-strip');
512
+ strip?.addEventListener('scroll', () => updateEdgeFades(strip), { passive: true });
513
+ if (activeId) {
514
+ updatePanelInteraction(el, activeId);
515
+ }
516
+ const markerSlot = shadowRoot.querySelector('slot[name="marker"]');
517
+ if (markerSlot) {
518
+ const updateDefaultMarkerVisibility = () => {
519
+ const defaultMarker = shadowRoot.querySelector('.default-marker');
520
+ if (defaultMarker) {
521
+ const hasCustom = markerSlot.assignedElements().length > 0;
522
+ defaultMarker.style.display = hasCustom ? 'none' : '';
523
+ }
524
+ };
525
+ markerSlot.addEventListener('slotchange', updateDefaultMarkerVisibility);
526
+ updateDefaultMarkerVisibility();
527
+ }
528
+ }
505
529
  }
506
530
  function cleanup(el) {
507
- cleanupEventListeners(el);
508
- cleanupResizeObserver(el);
531
+ cleanupEventListeners(el);
532
+ cleanupResizeObserver(el);
509
533
  }
510
534
  export class TyTabs extends HTMLElement {
511
- static get observedAttributes() {
512
- return ['width', 'height', 'active', 'placement'];
513
- }
514
- constructor() {
515
- super();
516
- this._childObserver = null;
517
- this._childRenderQueued = false;
518
- this.attachShadow({ mode: 'open' });
519
- }
520
- connectedCallback() {
521
- render(this);
522
- this._childObserver = new MutationObserver(() => {
523
- if (this._childRenderQueued)
524
- return;
525
- this._childRenderQueued = true;
526
- queueMicrotask(() => {
527
- this._childRenderQueued = false;
528
- if (this.isConnected)
529
- render(this);
530
- });
531
- });
532
- this._childObserver.observe(this, { childList: true });
533
- }
534
- disconnectedCallback() {
535
- this._childObserver?.disconnect();
536
- this._childObserver = null;
537
- cleanup(this);
538
- }
539
- attributeChangedCallback(name, oldValue, newValue) {
540
- if (name === 'active') {
541
- if (newValue) {
542
- updateActiveTabState(this, newValue, oldValue);
543
- }
544
- render(this);
545
- }
546
- else {
547
- render(this);
548
- }
549
- }
535
+ static get observedAttributes() {
536
+ return ['width', 'height', 'active', 'placement', 'fixed'];
537
+ }
538
+ constructor() {
539
+ super();
540
+ this._childObserver = null;
541
+ this._childRenderQueued = false;
542
+ this.attachShadow({ mode: 'open' });
543
+ }
544
+ connectedCallback() {
545
+ render(this);
546
+ this._childObserver = new MutationObserver(() => {
547
+ if (this._childRenderQueued)
548
+ return;
549
+ this._childRenderQueued = true;
550
+ queueMicrotask(() => {
551
+ this._childRenderQueued = false;
552
+ if (this.isConnected)
553
+ render(this);
554
+ });
555
+ });
556
+ this._childObserver.observe(this, { childList: true });
557
+ }
558
+ disconnectedCallback() {
559
+ this._childObserver?.disconnect();
560
+ this._childObserver = null;
561
+ cleanup(this);
562
+ }
563
+ attributeChangedCallback(name, oldValue, newValue) {
564
+ if (name === 'active') {
565
+ if (!newValue)
566
+ return;
567
+ if (!this.shadowRoot?.querySelector(`[data-tab-id='${newValue}']`)) {
568
+ render(this);
569
+ return;
570
+ }
571
+ updateActiveTabState(this, newValue, oldValue);
572
+ scrollActiveIntoView(this, newValue, true);
573
+ }
574
+ else {
575
+ render(this);
576
+ }
577
+ }
550
578
  }
551
579
  if (!customElements.get('ty-tabs')) {
552
- customElements.define('ty-tabs', TyTabs);
580
+ customElements.define('ty-tabs', TyTabs);
553
581
  }