tyrell-components 1.0.0-TC9 → 1.0.0-rc.22
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/AGENTS.md +122 -0
- package/CHANGELOG.md +1541 -0
- package/README.md +71 -53
- package/bin/tyrell.mjs +77 -0
- package/css/tyrell-colors-static.css +1 -0
- package/css/tyrell-theme.css +1 -0
- package/css/tyrell.css +1 -1783
- package/dist/tyrell-colors-static.css +1 -0
- package/dist/tyrell-theme.css +1 -0
- package/dist/tyrell.css +1 -1783
- package/dist/tyrell.js +1 -1
- package/guides/AGENT_INSTRUCTIONS.md +124 -0
- package/guides/AI_GUIDE.md +53 -0
- package/guides/CSS_GUIDE.md +1016 -0
- package/guides/DATASTAR_TY_GUIDE.md +657 -0
- package/guides/ICONS_GUIDE.md +212 -0
- package/guides/TY_GUIDE.md +937 -0
- package/guides/clj/CLOJURESCRIPT_GUIDE.md +300 -0
- package/guides/clj/CODE_SPLITTING.md +279 -0
- package/guides/clj/COMPONENT_GUIDE.md +391 -0
- package/guides/clj/HELIX_TY_GUIDE.md +428 -0
- package/guides/clj/I18N_GUIDE.md +478 -0
- package/guides/clj/LAYOUT_GUIDE.md +273 -0
- package/guides/clj/QUICKSTART.md +266 -0
- package/guides/clj/REAGENT_TY_GUIDE.md +408 -0
- package/guides/clj/REPLICANT_TY_GUIDE.md +623 -0
- package/guides/clj/ROUTING_GUIDE.md +346 -0
- package/guides/clj/UIX_TY_GUIDE.md +319 -0
- package/guides/js/HTMX_TY_GUIDE.md +252 -0
- package/guides/js/JAVASCRIPT_GUIDE.md +388 -0
- package/guides/js/REACT_TY_GUIDE.md +983 -0
- package/guides/js/SVELTE_TY_GUIDE.md +682 -0
- package/guides/js/TYCOMPONENT_GUIDE.md +962 -0
- package/guides/js/VUE_TY_GUIDE.md +738 -0
- package/lib/base/ty-component.d.ts +57 -13
- package/lib/base/ty-component.js +266 -292
- package/lib/components/button.d.ts +33 -18
- package/lib/components/button.js +317 -267
- package/lib/components/calendar-month.d.ts +30 -47
- package/lib/components/calendar-month.js +455 -429
- package/lib/components/calendar-navigation.d.ts +41 -49
- package/lib/components/calendar-navigation.js +287 -346
- package/lib/components/calendar.d.ts +73 -83
- package/lib/components/calendar.js +837 -762
- package/lib/components/checkbox.d.ts +26 -75
- package/lib/components/checkbox.js +298 -391
- package/lib/components/copy.d.ts +20 -60
- package/lib/components/copy.js +276 -380
- package/lib/components/date-picker.d.ts +100 -183
- package/lib/components/date-picker.js +1155 -1570
- package/lib/components/file-upload.d.ts +16 -15
- package/lib/components/file-upload.js +436 -426
- package/lib/components/icon.d.ts +3 -24
- package/lib/components/icon.js +141 -230
- package/lib/components/input.d.ts +93 -108
- package/lib/components/input.js +734 -710
- package/lib/components/modal.d.ts +39 -29
- package/lib/components/modal.js +419 -438
- package/lib/components/option.d.ts +20 -35
- package/lib/components/option.js +184 -309
- package/lib/components/popup.d.ts +2 -17
- package/lib/components/popup.js +353 -347
- package/lib/components/radio.d.ts +33 -25
- package/lib/components/radio.js +433 -422
- package/lib/components/resize-observer.d.ts +3 -30
- package/lib/components/resize-observer.js +71 -103
- package/lib/components/scroll-container.d.ts +21 -14
- package/lib/components/scroll-container.js +292 -234
- package/lib/components/select.d.ts +458 -0
- package/lib/components/select.js +1458 -0
- package/lib/components/selected-tags.d.ts +60 -0
- package/lib/components/selected-tags.js +225 -0
- package/lib/components/sortable.d.ts +175 -0
- package/lib/components/sortable.js +1844 -0
- package/lib/components/step.d.ts +1 -6
- package/lib/components/step.js +62 -68
- package/lib/components/switch.d.ts +15 -15
- package/lib/components/switch.js +237 -231
- package/lib/components/tab.d.ts +50 -7
- package/lib/components/tab.js +203 -69
- package/lib/components/tabs.d.ts +19 -64
- package/lib/components/tabs.js +600 -618
- package/lib/components/tag.d.ts +14 -52
- package/lib/components/tag.js +231 -306
- package/lib/components/textarea.d.ts +58 -89
- package/lib/components/textarea.js +523 -573
- package/lib/components/tooltip.d.ts +8 -13
- package/lib/components/tooltip.js +322 -409
- package/lib/components/wizard.d.ts +7 -54
- package/lib/components/wizard.js +376 -606
- package/lib/icons/fontawesome/brands.d.ts +0 -1
- package/lib/icons/fontawesome/brands.js +0 -8
- package/lib/icons/fontawesome/regular.d.ts +0 -1
- package/lib/icons/fontawesome/regular.js +0 -8
- package/lib/icons/fontawesome/solid.d.ts +0 -1
- package/lib/icons/fontawesome/solid.js +0 -8
- package/lib/icons/heroicons/micro.d.ts +0 -1
- package/lib/icons/heroicons/micro.js +392 -400
- package/lib/icons/heroicons/mini.d.ts +0 -1
- package/lib/icons/heroicons/mini.js +382 -390
- package/lib/icons/heroicons/outline.d.ts +0 -1
- package/lib/icons/heroicons/outline.js +337 -345
- package/lib/icons/heroicons/solid.d.ts +0 -1
- package/lib/icons/heroicons/solid.js +407 -415
- package/lib/icons/lucide.d.ts +0 -1
- package/lib/icons/lucide.js +24479 -26351
- package/lib/icons/material/filled.d.ts +0 -1
- package/lib/icons/material/filled.js +9653 -9663
- package/lib/icons/material/outlined.d.ts +0 -1
- package/lib/icons/material/outlined.js +10271 -10281
- package/lib/icons/material/round.d.ts +0 -1
- package/lib/icons/material/round.js +10495 -10505
- package/lib/icons/material/sharp.d.ts +0 -1
- package/lib/icons/material/sharp.js +9905 -9915
- package/lib/icons/material/two-tone.d.ts +0 -1
- package/lib/icons/material/two-tone.js +12792 -12802
- package/lib/index.d.ts +7 -4
- package/lib/index.js +26 -39
- package/lib/styles/button.d.ts +24 -7
- package/lib/styles/button.js +285 -445
- package/lib/styles/calendar-month.d.ts +7 -6
- package/lib/styles/calendar-month.js +158 -226
- package/lib/styles/calendar-navigation.d.ts +2 -6
- package/lib/styles/calendar-navigation.js +108 -127
- package/lib/styles/calendar.d.ts +3 -3
- package/lib/styles/calendar.js +87 -23
- package/lib/styles/checkbox.d.ts +7 -6
- package/lib/styles/checkbox.js +101 -15
- package/lib/styles/copy.d.ts +3 -2
- package/lib/styles/copy.js +91 -71
- package/lib/styles/custom-scrollbar.d.ts +1 -2
- package/lib/styles/custom-scrollbar.js +80 -115
- package/lib/styles/date-picker.d.ts +4 -6
- package/lib/styles/date-picker.js +321 -388
- package/lib/styles/field-size.d.ts +6 -0
- package/lib/styles/field-size.js +91 -0
- package/lib/styles/file-upload.d.ts +1 -2
- package/lib/styles/file-upload.js +143 -188
- package/lib/styles/icon.d.ts +2 -6
- package/lib/styles/icon.js +92 -170
- package/lib/styles/input.d.ts +4 -7
- package/lib/styles/input.js +148 -643
- package/lib/styles/modal.d.ts +1 -2
- package/lib/styles/modal.js +127 -108
- package/lib/styles/option.d.ts +2 -6
- package/lib/styles/option.js +53 -96
- package/lib/styles/popup.d.ts +1 -2
- package/lib/styles/popup.js +47 -77
- package/lib/styles/radio.d.ts +3 -2
- package/lib/styles/radio.js +90 -116
- package/lib/styles/resize-observer.d.ts +1 -2
- package/lib/styles/resize-observer.js +2 -12
- package/lib/styles/scroll-container.d.ts +1 -2
- package/lib/styles/scroll-container.js +103 -146
- package/lib/styles/select-base.d.ts +8 -0
- package/lib/styles/select-base.js +752 -0
- package/lib/styles/select.d.ts +11 -0
- package/lib/styles/select.js +229 -0
- package/lib/styles/sortable.d.ts +16 -0
- package/lib/styles/sortable.js +85 -0
- package/lib/styles/step.d.ts +1 -2
- package/lib/styles/step.js +15 -34
- package/lib/styles/switch.d.ts +3 -2
- package/lib/styles/switch.js +52 -68
- package/lib/styles/tab.d.ts +1 -2
- package/lib/styles/tab.js +86 -34
- package/lib/styles/tabs.d.ts +3 -11
- package/lib/styles/tabs.js +204 -162
- package/lib/styles/tag.d.ts +2 -6
- package/lib/styles/tag.js +168 -362
- package/lib/styles/textarea.d.ts +1 -2
- package/lib/styles/textarea.js +238 -306
- package/lib/styles/tooltip.d.ts +4 -3
- package/lib/styles/tooltip.js +3 -131
- package/lib/styles/wizard.d.ts +8 -20
- package/lib/styles/wizard.js +306 -295
- package/lib/types/common.d.ts +9 -8
- package/lib/types/common.js +8 -5
- package/lib/utils/calendar-utils.d.ts +49 -65
- package/lib/utils/calendar-utils.js +158 -343
- package/lib/utils/custom-scrollbar.d.ts +6 -20
- package/lib/utils/custom-scrollbar.js +273 -317
- package/lib/utils/flavor-sheet.d.ts +31 -0
- package/lib/utils/flavor-sheet.js +17 -0
- package/lib/utils/icon-registry.d.ts +0 -15
- package/lib/utils/icon-registry.js +138 -279
- package/lib/utils/icons.d.ts +9 -0
- package/lib/utils/icons.js +1 -0
- package/lib/utils/loader-registry.d.ts +2 -3
- package/lib/utils/loader-registry.js +3 -35
- package/lib/utils/locale.d.ts +2 -80
- package/lib/utils/locale.js +30 -205
- package/lib/utils/mobile.d.ts +0 -1
- package/lib/utils/mobile.js +1 -18
- package/lib/utils/number-format.d.ts +6 -24
- package/lib/utils/number-format.js +53 -136
- package/lib/utils/positioning.d.ts +72 -22
- package/lib/utils/positioning.js +224 -298
- package/lib/utils/property-capture.d.ts +5 -27
- package/lib/utils/property-capture.js +36 -144
- package/lib/utils/property-manager.d.ts +6 -6
- package/lib/utils/property-manager.js +127 -196
- package/lib/utils/resize-observer.d.ts +0 -1
- package/lib/utils/resize-observer.js +23 -59
- package/lib/utils/scroll-lock.d.ts +10 -11
- package/lib/utils/scroll-lock.js +165 -173
- package/lib/utils/styles.d.ts +0 -6
- package/lib/utils/styles.js +17 -48
- package/lib/utils/upgrade-properties.d.ts +21 -0
- package/lib/utils/upgrade-properties.js +47 -0
- package/lib/utils/validity.d.ts +122 -0
- package/lib/utils/validity.js +289 -0
- package/lib/version.d.ts +1 -2
- package/lib/version.js +1 -11
- package/package.json +66 -18
- package/lib/base/ty-component.d.ts.map +0 -1
- package/lib/base/ty-component.js.map +0 -1
- package/lib/components/button.d.ts.map +0 -1
- package/lib/components/button.js.map +0 -1
- package/lib/components/calendar-month.d.ts.map +0 -1
- package/lib/components/calendar-month.js.map +0 -1
- package/lib/components/calendar-navigation.d.ts.map +0 -1
- package/lib/components/calendar-navigation.js.map +0 -1
- package/lib/components/calendar.d.ts.map +0 -1
- package/lib/components/calendar.js.map +0 -1
- package/lib/components/checkbox.d.ts.map +0 -1
- package/lib/components/checkbox.js.map +0 -1
- package/lib/components/copy.d.ts.map +0 -1
- package/lib/components/copy.js.map +0 -1
- package/lib/components/date-picker.d.ts.map +0 -1
- package/lib/components/date-picker.js.map +0 -1
- package/lib/components/dropdown.d.ts +0 -404
- package/lib/components/dropdown.d.ts.map +0 -1
- package/lib/components/dropdown.js +0 -1563
- package/lib/components/dropdown.js.map +0 -1
- package/lib/components/file-upload.d.ts.map +0 -1
- package/lib/components/file-upload.js.map +0 -1
- package/lib/components/icon.d.ts.map +0 -1
- package/lib/components/icon.js.map +0 -1
- package/lib/components/input.d.ts.map +0 -1
- package/lib/components/input.js.map +0 -1
- package/lib/components/modal.d.ts.map +0 -1
- package/lib/components/modal.js.map +0 -1
- package/lib/components/multiselect.d.ts +0 -408
- package/lib/components/multiselect.d.ts.map +0 -1
- package/lib/components/multiselect.js +0 -1611
- package/lib/components/multiselect.js.map +0 -1
- package/lib/components/option.d.ts.map +0 -1
- package/lib/components/option.js.map +0 -1
- package/lib/components/popup.d.ts.map +0 -1
- package/lib/components/popup.js.map +0 -1
- package/lib/components/radio.d.ts.map +0 -1
- package/lib/components/radio.js.map +0 -1
- package/lib/components/resize-observer.d.ts.map +0 -1
- package/lib/components/resize-observer.js.map +0 -1
- package/lib/components/scroll-container.d.ts.map +0 -1
- package/lib/components/scroll-container.js.map +0 -1
- package/lib/components/step.d.ts.map +0 -1
- package/lib/components/step.js.map +0 -1
- package/lib/components/switch.d.ts.map +0 -1
- package/lib/components/switch.js.map +0 -1
- package/lib/components/tab.d.ts.map +0 -1
- package/lib/components/tab.js.map +0 -1
- package/lib/components/tabs.d.ts.map +0 -1
- package/lib/components/tabs.js.map +0 -1
- package/lib/components/tag.d.ts.map +0 -1
- package/lib/components/tag.js.map +0 -1
- package/lib/components/textarea.d.ts.map +0 -1
- package/lib/components/textarea.js.map +0 -1
- package/lib/components/tooltip.d.ts.map +0 -1
- package/lib/components/tooltip.js.map +0 -1
- package/lib/components/wizard.d.ts.map +0 -1
- package/lib/components/wizard.js.map +0 -1
- package/lib/icons/fontawesome/brands.d.ts.map +0 -1
- package/lib/icons/fontawesome/brands.js.map +0 -1
- package/lib/icons/fontawesome/regular.d.ts.map +0 -1
- package/lib/icons/fontawesome/regular.js.map +0 -1
- package/lib/icons/fontawesome/solid.d.ts.map +0 -1
- package/lib/icons/fontawesome/solid.js.map +0 -1
- package/lib/icons/heroicons/micro.d.ts.map +0 -1
- package/lib/icons/heroicons/micro.js.map +0 -1
- package/lib/icons/heroicons/mini.d.ts.map +0 -1
- package/lib/icons/heroicons/mini.js.map +0 -1
- package/lib/icons/heroicons/outline.d.ts.map +0 -1
- package/lib/icons/heroicons/outline.js.map +0 -1
- package/lib/icons/heroicons/solid.d.ts.map +0 -1
- package/lib/icons/heroicons/solid.js.map +0 -1
- package/lib/icons/lucide.d.ts.map +0 -1
- package/lib/icons/lucide.js.map +0 -1
- package/lib/icons/material/filled.d.ts.map +0 -1
- package/lib/icons/material/filled.js.map +0 -1
- package/lib/icons/material/outlined.d.ts.map +0 -1
- package/lib/icons/material/outlined.js.map +0 -1
- package/lib/icons/material/round.d.ts.map +0 -1
- package/lib/icons/material/round.js.map +0 -1
- package/lib/icons/material/sharp.d.ts.map +0 -1
- package/lib/icons/material/sharp.js.map +0 -1
- package/lib/icons/material/two-tone.d.ts.map +0 -1
- package/lib/icons/material/two-tone.js.map +0 -1
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/styles/button.d.ts.map +0 -1
- package/lib/styles/button.js.map +0 -1
- package/lib/styles/calendar-month.d.ts.map +0 -1
- package/lib/styles/calendar-month.js.map +0 -1
- package/lib/styles/calendar-navigation.d.ts.map +0 -1
- package/lib/styles/calendar-navigation.js.map +0 -1
- package/lib/styles/calendar.d.ts.map +0 -1
- package/lib/styles/calendar.js.map +0 -1
- package/lib/styles/checkbox.d.ts.map +0 -1
- package/lib/styles/checkbox.js.map +0 -1
- package/lib/styles/copy.d.ts.map +0 -1
- package/lib/styles/copy.js.map +0 -1
- package/lib/styles/custom-scrollbar.d.ts.map +0 -1
- package/lib/styles/custom-scrollbar.js.map +0 -1
- package/lib/styles/date-picker.d.ts.map +0 -1
- package/lib/styles/date-picker.js.map +0 -1
- package/lib/styles/dropdown.d.ts +0 -12
- package/lib/styles/dropdown.d.ts.map +0 -1
- package/lib/styles/dropdown.js +0 -1048
- package/lib/styles/dropdown.js.map +0 -1
- package/lib/styles/file-upload.d.ts.map +0 -1
- package/lib/styles/file-upload.js.map +0 -1
- package/lib/styles/icon.d.ts.map +0 -1
- package/lib/styles/icon.js.map +0 -1
- package/lib/styles/input.d.ts.map +0 -1
- package/lib/styles/input.js.map +0 -1
- package/lib/styles/modal.d.ts.map +0 -1
- package/lib/styles/modal.js.map +0 -1
- package/lib/styles/multiselect.d.ts +0 -6
- package/lib/styles/multiselect.d.ts.map +0 -1
- package/lib/styles/multiselect.js +0 -837
- package/lib/styles/multiselect.js.map +0 -1
- package/lib/styles/option.d.ts.map +0 -1
- package/lib/styles/option.js.map +0 -1
- package/lib/styles/popup.d.ts.map +0 -1
- package/lib/styles/popup.js.map +0 -1
- package/lib/styles/radio.d.ts.map +0 -1
- package/lib/styles/radio.js.map +0 -1
- package/lib/styles/resize-observer.d.ts.map +0 -1
- package/lib/styles/resize-observer.js.map +0 -1
- package/lib/styles/scroll-container.d.ts.map +0 -1
- package/lib/styles/scroll-container.js.map +0 -1
- package/lib/styles/step.d.ts.map +0 -1
- package/lib/styles/step.js.map +0 -1
- package/lib/styles/switch.d.ts.map +0 -1
- package/lib/styles/switch.js.map +0 -1
- package/lib/styles/tab.d.ts.map +0 -1
- package/lib/styles/tab.js.map +0 -1
- package/lib/styles/tabs.d.ts.map +0 -1
- package/lib/styles/tabs.js.map +0 -1
- package/lib/styles/tag.d.ts.map +0 -1
- package/lib/styles/tag.js.map +0 -1
- package/lib/styles/textarea.d.ts.map +0 -1
- package/lib/styles/textarea.js.map +0 -1
- package/lib/styles/tooltip.d.ts.map +0 -1
- package/lib/styles/tooltip.js.map +0 -1
- package/lib/styles/wizard.d.ts.map +0 -1
- package/lib/styles/wizard.js.map +0 -1
- package/lib/types/common.d.ts.map +0 -1
- package/lib/types/common.js.map +0 -1
- package/lib/utils/calendar-utils.d.ts.map +0 -1
- package/lib/utils/calendar-utils.js.map +0 -1
- package/lib/utils/custom-scrollbar.d.ts.map +0 -1
- package/lib/utils/custom-scrollbar.js.map +0 -1
- package/lib/utils/icon-registry.d.ts.map +0 -1
- package/lib/utils/icon-registry.js.map +0 -1
- package/lib/utils/loader-registry.d.ts.map +0 -1
- package/lib/utils/loader-registry.js.map +0 -1
- package/lib/utils/locale.d.ts.map +0 -1
- package/lib/utils/locale.js.map +0 -1
- package/lib/utils/mobile.d.ts.map +0 -1
- package/lib/utils/mobile.js.map +0 -1
- package/lib/utils/number-format.d.ts.map +0 -1
- package/lib/utils/number-format.js.map +0 -1
- package/lib/utils/parse-boolean.d.ts +0 -39
- package/lib/utils/parse-boolean.d.ts.map +0 -1
- package/lib/utils/parse-boolean.js +0 -58
- package/lib/utils/parse-boolean.js.map +0 -1
- package/lib/utils/positioning.d.ts.map +0 -1
- package/lib/utils/positioning.js.map +0 -1
- package/lib/utils/property-capture.d.ts.map +0 -1
- package/lib/utils/property-capture.js.map +0 -1
- package/lib/utils/property-manager.d.ts.map +0 -1
- package/lib/utils/property-manager.js.map +0 -1
- package/lib/utils/resize-observer.d.ts.map +0 -1
- package/lib/utils/resize-observer.js.map +0 -1
- package/lib/utils/scroll-lock.d.ts.map +0 -1
- package/lib/utils/scroll-lock.js.map +0 -1
- package/lib/utils/styles.d.ts.map +0 -1
- package/lib/utils/styles.js.map +0 -1
- package/lib/version.d.ts.map +0 -1
- package/lib/version.js.map +0 -1
package/lib/components/tabs.js
CHANGED
|
@@ -1,653 +1,635 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tabs Component
|
|
3
|
-
*
|
|
4
|
-
* A carousel-based tabs component with smooth animations and fixed container dimensions.
|
|
5
|
-
* Features horizontal sliding transitions, smart positioning marker, and independent panel scrolling.
|
|
6
|
-
*
|
|
7
|
-
* Features:
|
|
8
|
-
* - Carousel animation with smooth sliding transitions
|
|
9
|
-
* - Fixed dimensions prevent layout shift between tabs
|
|
10
|
-
* - Animated marker that follows active tab button
|
|
11
|
-
* - Rich label support via slots (icons, badges, custom content)
|
|
12
|
-
* - Custom marker slot for complete active tab styling control
|
|
13
|
-
* - Independent panel scrolling with scroll position reset
|
|
14
|
-
* - ResizeObserver for responsive percentage widths
|
|
15
|
-
* - Smart rendering - only updates DOM when necessary
|
|
16
|
-
* - Accessibility with ARIA roles and attributes
|
|
17
|
-
* - Top/bottom placement for tab buttons
|
|
18
|
-
*
|
|
19
|
-
* @example
|
|
20
|
-
* <!-- Basic tabs with text labels -->
|
|
21
|
-
* <ty-tabs width="800px" height="600px" active="general">
|
|
22
|
-
* <ty-tab id="general" label="General Settings">
|
|
23
|
-
* <div class="p-6">General content...</div>
|
|
24
|
-
* </ty-tab>
|
|
25
|
-
* <ty-tab id="advanced" label="Advanced Settings">
|
|
26
|
-
* <div class="p-6">Advanced content...</div>
|
|
27
|
-
* </ty-tab>
|
|
28
|
-
* </ty-tabs>
|
|
29
|
-
*
|
|
30
|
-
* @example
|
|
31
|
-
* <!-- Rich labels with icons and badges -->
|
|
32
|
-
* <ty-tabs width="800px" height="600px">
|
|
33
|
-
* <!-- Rich label as direct child -->
|
|
34
|
-
* <span slot="label-profile" class="flex items-center gap-2">
|
|
35
|
-
* <ty-icon name="user" size="sm"></ty-icon>
|
|
36
|
-
* Profile
|
|
37
|
-
* </span>
|
|
38
|
-
*
|
|
39
|
-
* <span slot="label-notifications" class="flex items-center gap-2">
|
|
40
|
-
* <ty-icon name="bell" size="sm"></ty-icon>
|
|
41
|
-
* Notifications
|
|
42
|
-
* <span class="ty-bg-danger ty-text-danger++ px-2 py-0.5 rounded-full text-xs">5</span>
|
|
43
|
-
* </span>
|
|
44
|
-
*
|
|
45
|
-
* <!-- Tab panels -->
|
|
46
|
-
* <ty-tab id="profile">...</ty-tab>
|
|
47
|
-
* <ty-tab id="notifications">...</ty-tab>
|
|
48
|
-
* </ty-tabs>
|
|
49
|
-
*
|
|
50
|
-
* @example
|
|
51
|
-
* <!-- Custom marker styling -->
|
|
52
|
-
* <ty-tabs width="100%" height="400px">
|
|
53
|
-
* <!-- Gradient marker slot -->
|
|
54
|
-
* <div slot="marker" style="
|
|
55
|
-
* background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
|
56
|
-
* border-radius: 0.5rem;
|
|
57
|
-
* box-shadow: 0 2px 8px rgba(0,0,0,0.15);
|
|
58
|
-
* "></div>
|
|
59
|
-
*
|
|
60
|
-
* <ty-tab id="tab1" label="Dashboard">...</ty-tab>
|
|
61
|
-
* <ty-tab id="tab2" label="Analytics">...</ty-tab>
|
|
62
|
-
* </ty-tabs>
|
|
63
|
-
*/
|
|
64
1
|
import { ensureStyles } from '../utils/styles.js';
|
|
65
2
|
import { tabsStyles } from '../styles/tabs.js';
|
|
66
|
-
// ============================================================================
|
|
67
|
-
// WeakMaps for State Management
|
|
68
|
-
// ============================================================================
|
|
69
3
|
const eventHandlers = new WeakMap();
|
|
70
4
|
const resizeObservers = new WeakMap();
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
5
|
+
const shownTabs = new WeakMap();
|
|
6
|
+
const instanceSheets = new WeakMap();
|
|
7
|
+
const pendingInitialSnap = new WeakMap();
|
|
8
|
+
let userInputs = 0;
|
|
9
|
+
const countInput = () => { userInputs++; };
|
|
10
|
+
addEventListener('pointerdown', countInput, { capture: true, passive: true });
|
|
11
|
+
addEventListener('keydown', countInput, { capture: true, passive: true });
|
|
12
|
+
const awaitedTabs = new WeakMap();
|
|
13
|
+
let snapCount = 0;
|
|
77
14
|
function getTabsAttributes(el) {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* Get all ty-tab child elements
|
|
87
|
-
*/
|
|
15
|
+
return {
|
|
16
|
+
placement: (el.getAttribute('placement') || 'top'),
|
|
17
|
+
fixed: el.hasAttribute('fixed'),
|
|
18
|
+
};
|
|
19
|
+
}
|
|
88
20
|
function getChildTabs(el) {
|
|
89
|
-
|
|
21
|
+
return Array.from(el.querySelectorAll(':scope > ty-tab'));
|
|
90
22
|
}
|
|
91
|
-
/**
|
|
92
|
-
* Get ID from a ty-tab element
|
|
93
|
-
*/
|
|
94
23
|
function getTabId(tab) {
|
|
95
|
-
|
|
24
|
+
return tab.getAttribute('id');
|
|
25
|
+
}
|
|
26
|
+
function getSlotLabel(tabsEl, tabId) {
|
|
27
|
+
return tabsEl.querySelector(`:scope > [slot='label-${tabId}']`);
|
|
96
28
|
}
|
|
97
|
-
/**
|
|
98
|
-
* Check if ty-tabs has a direct child label slot for this tab-id.
|
|
99
|
-
* Looks in ty-tabs' light DOM for slot='label-{tab-id}' elements.
|
|
100
|
-
*/
|
|
101
29
|
function hasSlotLabel(tabsEl, tabId) {
|
|
102
|
-
|
|
30
|
+
return getSlotLabel(tabsEl, tabId) !== null;
|
|
103
31
|
}
|
|
104
|
-
/**
|
|
105
|
-
* Determine label type: 'slot' (rich content) or 'text' (simple attribute).
|
|
106
|
-
* Checks ty-tabs element for slot='label-{tab-id}' direct children.
|
|
107
|
-
*/
|
|
108
32
|
function getTabLabelType(tabsEl, tab) {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
}
|
|
115
|
-
/**
|
|
116
|
-
* Check if tab is disabled
|
|
117
|
-
*/
|
|
33
|
+
const tabId = getTabId(tab);
|
|
34
|
+
if (tabId && hasSlotLabel(tabsEl, tabId)) {
|
|
35
|
+
return 'slot';
|
|
36
|
+
}
|
|
37
|
+
return 'text';
|
|
38
|
+
}
|
|
118
39
|
function isTabDisabled(tab) {
|
|
119
|
-
|
|
40
|
+
return tab.hasAttribute('disabled');
|
|
120
41
|
}
|
|
121
|
-
/**
|
|
122
|
-
* Check if user provided custom marker content via slot
|
|
123
|
-
*/
|
|
124
42
|
function hasCustomMarker(el) {
|
|
125
|
-
|
|
126
|
-
}
|
|
127
|
-
// ============================================================================
|
|
128
|
-
// Helper Functions - Active Tab Management
|
|
129
|
-
// ============================================================================
|
|
130
|
-
/**
|
|
131
|
-
* Find index of tab with given ID
|
|
132
|
-
*/
|
|
43
|
+
return el.querySelector(':scope > [slot="marker"]') !== null;
|
|
44
|
+
}
|
|
133
45
|
function findTabIndex(tabs, tabId) {
|
|
134
|
-
|
|
135
|
-
|
|
46
|
+
const index = tabs.findIndex(tab => getTabId(tab) === tabId);
|
|
47
|
+
return index >= 0 ? index : undefined;
|
|
48
|
+
}
|
|
49
|
+
function currentActive(el) {
|
|
50
|
+
return shownTabs.get(el) ?? null;
|
|
136
51
|
}
|
|
137
|
-
/**
|
|
138
|
-
* Get the active tab ID, defaulting to first tab if not specified
|
|
139
|
-
*/
|
|
140
52
|
function getActiveTabId(el, tabs) {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
function setActiveTab(el, tabId) {
|
|
155
|
-
el.setAttribute('active', tabId);
|
|
156
|
-
}
|
|
157
|
-
/**
|
|
158
|
-
* Dispatch ty-tab-change event
|
|
159
|
-
*/
|
|
53
|
+
const ids = tabs.map(getTabId).filter((id) => !!id);
|
|
54
|
+
const activeAttr = el.getAttribute('active');
|
|
55
|
+
if (activeAttr && ids.includes(activeAttr))
|
|
56
|
+
return activeAttr;
|
|
57
|
+
const shown = shownTabs.get(el);
|
|
58
|
+
if (shown && ids.includes(shown))
|
|
59
|
+
return shown;
|
|
60
|
+
return ids[0] ?? null;
|
|
61
|
+
}
|
|
62
|
+
function activateTab(el, tabId) {
|
|
63
|
+
el.setAttribute('active', tabId);
|
|
64
|
+
syncShownTab(el, true);
|
|
65
|
+
}
|
|
160
66
|
function dispatchTabChangeEvent(el, activeId, activeIndex, previousId, previousIndex) {
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
}
|
|
173
|
-
// ============================================================================
|
|
174
|
-
// Event Handlers - Tab Button Click
|
|
175
|
-
// ============================================================================
|
|
176
|
-
/**
|
|
177
|
-
* Handle tab button click
|
|
178
|
-
*/
|
|
67
|
+
const event = new CustomEvent('ty-tab-change', {
|
|
68
|
+
detail: {
|
|
69
|
+
activeId,
|
|
70
|
+
activeIndex,
|
|
71
|
+
previousId,
|
|
72
|
+
previousIndex,
|
|
73
|
+
},
|
|
74
|
+
bubbles: true,
|
|
75
|
+
cancelable: false,
|
|
76
|
+
});
|
|
77
|
+
el.dispatchEvent(event);
|
|
78
|
+
}
|
|
179
79
|
function handleTabClick(el, tabId, event) {
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
}
|
|
185
|
-
/**
|
|
186
|
-
* Cleanup existing event listeners
|
|
187
|
-
*/
|
|
80
|
+
event.preventDefault();
|
|
81
|
+
event.stopPropagation();
|
|
82
|
+
activateTab(el, tabId);
|
|
83
|
+
}
|
|
188
84
|
function cleanupEventListeners(el) {
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
85
|
+
const handlers = eventHandlers.get(el);
|
|
86
|
+
if (!handlers)
|
|
87
|
+
return;
|
|
88
|
+
const shadowRoot = el.shadowRoot;
|
|
89
|
+
if (!shadowRoot)
|
|
90
|
+
return;
|
|
91
|
+
handlers.tabClickHandlers.forEach((handler, tabId) => {
|
|
92
|
+
const button = shadowRoot.querySelector(`[data-tab-id='${tabId}']`);
|
|
93
|
+
if (button) {
|
|
94
|
+
button.removeEventListener('click', handler);
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
handlers.tabKeydownHandlers.forEach((handler, tabId) => {
|
|
98
|
+
const button = shadowRoot.querySelector(`[data-tab-id='${tabId}']`);
|
|
99
|
+
if (button) {
|
|
100
|
+
button.removeEventListener('keydown', handler);
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
handlers.tabClickHandlers.clear();
|
|
104
|
+
handlers.tabKeydownHandlers.clear();
|
|
105
|
+
}
|
|
106
|
+
function handleTabKeydown(el, shadowRoot, tabId, e) {
|
|
107
|
+
if (!['ArrowRight', 'ArrowLeft', 'Home', 'End'].includes(e.key))
|
|
108
|
+
return;
|
|
109
|
+
const ids = Array.from(shadowRoot.querySelectorAll('.tab-buttons [data-tab-id]:not([disabled])')).map((b) => b.getAttribute('data-tab-id'));
|
|
110
|
+
const i = ids.indexOf(tabId);
|
|
111
|
+
if (i < 0 || ids.length === 0)
|
|
112
|
+
return;
|
|
113
|
+
e.preventDefault();
|
|
114
|
+
const next = e.key === 'Home' ? ids[0]
|
|
115
|
+
: e.key === 'End' ? ids[ids.length - 1]
|
|
116
|
+
: e.key === 'ArrowRight' ? ids[(i + 1) % ids.length]
|
|
117
|
+
: ids[(i - 1 + ids.length) % ids.length];
|
|
118
|
+
if (next === tabId)
|
|
119
|
+
return;
|
|
120
|
+
handleTabClick(el, next, e);
|
|
121
|
+
requestAnimationFrame(() => {
|
|
122
|
+
shadowRoot.querySelector(`.tab-buttons [data-tab-id='${next}']`)?.focus();
|
|
123
|
+
});
|
|
124
|
+
}
|
|
207
125
|
function setupEventListeners(el, shadowRoot, tabs) {
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
126
|
+
cleanupEventListeners(el);
|
|
127
|
+
const handlers = {
|
|
128
|
+
tabClickHandlers: new Map(),
|
|
129
|
+
tabKeydownHandlers: new Map(),
|
|
130
|
+
};
|
|
131
|
+
tabs.forEach((tab) => {
|
|
132
|
+
const tabId = getTabId(tab);
|
|
133
|
+
if (!tabId)
|
|
134
|
+
return;
|
|
135
|
+
const button = shadowRoot.querySelector(`[data-tab-id='${tabId}']`);
|
|
136
|
+
if (button) {
|
|
137
|
+
const handler = (e) => handleTabClick(el, tabId, e);
|
|
138
|
+
const keydownHandler = (e) => handleTabKeydown(el, shadowRoot, tabId, e);
|
|
139
|
+
button.addEventListener('click', handler);
|
|
140
|
+
button.addEventListener('keydown', keydownHandler);
|
|
141
|
+
handlers.tabClickHandlers.set(tabId, handler);
|
|
142
|
+
handlers.tabKeydownHandlers.set(tabId, keydownHandler);
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
eventHandlers.set(el, handlers);
|
|
146
|
+
}
|
|
147
|
+
function carouselTransform(activeIndex) {
|
|
148
|
+
return `translateX(${activeIndex * -100}%)`;
|
|
149
|
+
}
|
|
150
|
+
function snapNextChange(container) {
|
|
151
|
+
if (!container)
|
|
152
|
+
return;
|
|
153
|
+
const token = String(++snapCount);
|
|
154
|
+
container.setAttribute('data-snap', token);
|
|
155
|
+
requestAnimationFrame(() => requestAnimationFrame(() => {
|
|
156
|
+
if (container.getAttribute('data-snap') === token)
|
|
157
|
+
container.removeAttribute('data-snap');
|
|
158
|
+
}));
|
|
159
|
+
}
|
|
235
160
|
function updateTransform(el, activeIndex) {
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
161
|
+
const panelsWrapper = el.shadowRoot?.querySelector('.panels-wrapper');
|
|
162
|
+
if (panelsWrapper)
|
|
163
|
+
panelsWrapper.style.transform = carouselTransform(activeIndex);
|
|
164
|
+
}
|
|
165
|
+
function setAttr(node, name, value) {
|
|
166
|
+
if (node.getAttribute(name) !== value)
|
|
167
|
+
node.setAttribute(name, value);
|
|
168
|
+
}
|
|
169
|
+
function syncInstanceSheet(el, shownId) {
|
|
170
|
+
const shadowRoot = el.shadowRoot;
|
|
171
|
+
if (!shadowRoot)
|
|
172
|
+
return;
|
|
173
|
+
let sheet = instanceSheets.get(el);
|
|
174
|
+
if (!sheet) {
|
|
175
|
+
sheet = new CSSStyleSheet();
|
|
176
|
+
sheet.replaceSync(':host {} ::slotted(ty-tab) {}');
|
|
177
|
+
const hide = sheet.cssRules[1].style;
|
|
178
|
+
hide.setProperty('opacity', '0', 'important');
|
|
179
|
+
hide.setProperty('visibility', 'hidden', 'important');
|
|
180
|
+
hide.setProperty('pointer-events', 'none', 'important');
|
|
181
|
+
shadowRoot.adoptedStyleSheets = [...shadowRoot.adoptedStyleSheets, sheet];
|
|
182
|
+
instanceSheets.set(el, sheet);
|
|
183
|
+
}
|
|
184
|
+
const host = sheet.cssRules[0].style;
|
|
185
|
+
for (const prop of ['width', 'height']) {
|
|
186
|
+
const value = el.getAttribute(prop);
|
|
187
|
+
if (value)
|
|
188
|
+
host.setProperty(prop, value, 'important');
|
|
189
|
+
else
|
|
190
|
+
host.removeProperty(prop);
|
|
191
|
+
}
|
|
192
|
+
sheet.cssRules[1].selectorText = shownId
|
|
193
|
+
? `::slotted(ty-tab:not(#${CSS.escape(shownId)}))`
|
|
194
|
+
: '::slotted(ty-tab)';
|
|
195
|
+
}
|
|
251
196
|
function updateAriaAttributes(el, shadowRoot, activeId) {
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
});
|
|
271
|
-
}
|
|
272
|
-
/**
|
|
273
|
-
* Update pointer-events, opacity, and data-active on tab panels without re-rendering
|
|
274
|
-
*/
|
|
197
|
+
const tabs = getChildTabs(el);
|
|
198
|
+
tabs.forEach((tab, idx) => {
|
|
199
|
+
const tabId = getTabId(tab);
|
|
200
|
+
if (!tabId)
|
|
201
|
+
return;
|
|
202
|
+
const button = shadowRoot.querySelector(`[data-tab-id='${tabId}']`);
|
|
203
|
+
const isActive = tabId === activeId;
|
|
204
|
+
if (button) {
|
|
205
|
+
button.setAttribute('aria-selected', String(isActive));
|
|
206
|
+
button.setAttribute('tabindex', isActive ? '0' : '-1');
|
|
207
|
+
button.setAttribute('data-active', String(isActive));
|
|
208
|
+
const slottedLabel = getSlotLabel(el, tabId);
|
|
209
|
+
if (slottedLabel) {
|
|
210
|
+
setAttr(slottedLabel, 'data-active', String(isActive));
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
});
|
|
214
|
+
}
|
|
275
215
|
function updatePanelInteraction(el, activeId) {
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
tab.style.pointerEvents = 'auto';
|
|
286
|
-
tab.style.opacity = '1';
|
|
287
|
-
}
|
|
288
|
-
else {
|
|
289
|
-
tab.style.pointerEvents = 'none';
|
|
290
|
-
tab.style.opacity = '0';
|
|
291
|
-
}
|
|
292
|
-
});
|
|
293
|
-
}
|
|
294
|
-
/**
|
|
295
|
-
* Calculate marker position and dimensions based on active tab button.
|
|
296
|
-
* Returns position object with left, top, width, height in pixels, or null if button not found.
|
|
297
|
-
*/
|
|
216
|
+
syncInstanceSheet(el, activeId);
|
|
217
|
+
getChildTabs(el).forEach((tab) => {
|
|
218
|
+
const tabId = getTabId(tab);
|
|
219
|
+
tab.setShown?.(!!tabId && tabId === activeId);
|
|
220
|
+
if (!tabId)
|
|
221
|
+
return;
|
|
222
|
+
setAttr(tab, 'data-active', String(tabId === activeId));
|
|
223
|
+
});
|
|
224
|
+
}
|
|
298
225
|
function calculateMarkerPosition(el, shadowRoot, activeId) {
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
226
|
+
const button = shadowRoot.querySelector(`[data-tab-id='${activeId}']`);
|
|
227
|
+
const buttonsContainer = shadowRoot.querySelector('.tab-buttons');
|
|
228
|
+
if (!button || !buttonsContainer)
|
|
229
|
+
return null;
|
|
230
|
+
const left = button.offsetLeft;
|
|
231
|
+
const top = button.offsetTop;
|
|
232
|
+
const width = button.offsetWidth;
|
|
233
|
+
const height = button.offsetHeight;
|
|
234
|
+
return { left, top, width, height };
|
|
235
|
+
}
|
|
236
|
+
function updateMarker(el, activeId, forceSnap = false) {
|
|
237
|
+
const shadowRoot = el.shadowRoot;
|
|
238
|
+
if (!shadowRoot)
|
|
239
|
+
return;
|
|
240
|
+
const marker = shadowRoot.querySelector('.marker-wrapper');
|
|
241
|
+
if (!marker)
|
|
242
|
+
return;
|
|
243
|
+
const position = calculateMarkerPosition(el, shadowRoot, activeId);
|
|
244
|
+
if (!position)
|
|
245
|
+
return;
|
|
246
|
+
const snap = forceSnap || !marker.style.left || marker.offsetWidth === 0;
|
|
247
|
+
if (snap)
|
|
248
|
+
marker.style.transition = 'none';
|
|
249
|
+
marker.style.left = `${position.left}px`;
|
|
250
|
+
marker.style.top = `${position.top}px`;
|
|
251
|
+
marker.style.width = `${position.width}px`;
|
|
252
|
+
marker.style.height = `${position.height}px`;
|
|
253
|
+
if (snap) {
|
|
254
|
+
marker.getBoundingClientRect();
|
|
255
|
+
marker.style.transition = '';
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
function syncShownTab(el, user = false) {
|
|
259
|
+
const shadowRoot = el.shadowRoot;
|
|
260
|
+
if (!shadowRoot)
|
|
261
|
+
return;
|
|
262
|
+
const tabs = getChildTabs(el);
|
|
263
|
+
const previousId = shownTabs.get(el) ?? null;
|
|
264
|
+
const tabId = getActiveTabId(el, tabs);
|
|
265
|
+
const newIndex = (tabId ? findTabIndex(tabs, tabId) : undefined) ?? 0;
|
|
266
|
+
const container = shadowRoot.querySelector('.tabs-container');
|
|
267
|
+
if (tabId === previousId) {
|
|
268
|
+
const wrapper = shadowRoot.querySelector('.panels-wrapper');
|
|
269
|
+
if (wrapper && wrapper.style.transform !== carouselTransform(newIndex)) {
|
|
270
|
+
snapNextChange(container);
|
|
271
|
+
wrapper.style.transform = carouselTransform(newIndex);
|
|
272
|
+
}
|
|
273
|
+
return;
|
|
274
|
+
}
|
|
275
|
+
shownTabs.set(el, tabId);
|
|
276
|
+
const initial = previousId === null;
|
|
277
|
+
const arrived = !user && tabId !== null && awaitedTabs.get(el) === tabId;
|
|
278
|
+
awaitedTabs.delete(el);
|
|
279
|
+
const requested = el.getAttribute('active');
|
|
280
|
+
if (initial && requested && requested !== tabId)
|
|
281
|
+
awaitedTabs.set(el, requested);
|
|
282
|
+
const snap = !user && (initial || arrived || pendingInitialSnap.get(el) === userInputs);
|
|
283
|
+
if (initial)
|
|
284
|
+
pendingInitialSnap.set(el, userInputs);
|
|
285
|
+
else if (!arrived)
|
|
286
|
+
pendingInitialSnap.delete(el);
|
|
287
|
+
if (snap)
|
|
288
|
+
snapNextChange(container);
|
|
289
|
+
updateTransform(el, newIndex);
|
|
290
|
+
updateAriaAttributes(el, shadowRoot, tabId || '');
|
|
291
|
+
updatePanelInteraction(el, tabId);
|
|
292
|
+
if (!tabId || initial)
|
|
293
|
+
return;
|
|
294
|
+
updateMarker(el, tabId, snap);
|
|
295
|
+
scrollActiveIntoView(el, tabId, !snap);
|
|
296
|
+
shadowRoot.querySelectorAll('.tab-overflow-item').forEach((item) => {
|
|
297
|
+
item.setAttribute('data-active', String(item.dataset.tabId === tabId));
|
|
298
|
+
});
|
|
299
|
+
tabs[newIndex]?.resetScroll?.();
|
|
300
|
+
if (arrived)
|
|
301
|
+
return;
|
|
302
|
+
const previousIndex = findTabIndex(tabs, previousId);
|
|
303
|
+
dispatchTabChangeEvent(el, tabId, newIndex, previousIndex === undefined ? null : previousId, previousIndex ?? null);
|
|
304
|
+
tabs[newIndex]?._requestLoad?.(newIndex);
|
|
305
|
+
}
|
|
376
306
|
function setupResizeObserver(el) {
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
el.style.setProperty('--tabs-width', `${measuredWidth}px`);
|
|
393
|
-
// Update transform with new width
|
|
394
|
-
if (activeIndex !== undefined) {
|
|
395
|
-
updateTransform(el, activeIndex);
|
|
396
|
-
}
|
|
397
|
-
// Update marker position (tab button positions may have changed)
|
|
398
|
-
if (activeId) {
|
|
399
|
-
updateMarker(el, activeId);
|
|
400
|
-
}
|
|
401
|
-
});
|
|
402
|
-
observer.observe(el);
|
|
403
|
-
resizeObservers.set(el, observer);
|
|
404
|
-
}
|
|
405
|
-
}
|
|
406
|
-
/**
|
|
407
|
-
* Cleanup ResizeObserver
|
|
408
|
-
*/
|
|
307
|
+
const oldObserver = resizeObservers.get(el);
|
|
308
|
+
if (oldObserver) {
|
|
309
|
+
oldObserver.disconnect();
|
|
310
|
+
}
|
|
311
|
+
const observer = new ResizeObserver(() => {
|
|
312
|
+
const activeId = currentActive(el);
|
|
313
|
+
updateOverflow(el);
|
|
314
|
+
if (activeId) {
|
|
315
|
+
updateMarker(el, activeId);
|
|
316
|
+
scrollActiveIntoView(el, activeId, false);
|
|
317
|
+
}
|
|
318
|
+
});
|
|
319
|
+
observer.observe(el);
|
|
320
|
+
resizeObservers.set(el, observer);
|
|
321
|
+
}
|
|
409
322
|
function cleanupResizeObserver(el) {
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
}
|
|
416
|
-
// ============================================================================
|
|
417
|
-
// Rendering Functions
|
|
418
|
-
// ============================================================================
|
|
419
|
-
/**
|
|
420
|
-
* Generate HTML for tab buttons using slots for rich labels.
|
|
421
|
-
* Slots are looked up as direct children of tabs-el with slot='label-{tab-id}'.
|
|
422
|
-
* Also renders marker wrapper with optional default underline (only if no custom marker).
|
|
423
|
-
*/
|
|
323
|
+
const observer = resizeObservers.get(el);
|
|
324
|
+
if (observer) {
|
|
325
|
+
observer.disconnect();
|
|
326
|
+
resizeObservers.delete(el);
|
|
327
|
+
}
|
|
328
|
+
}
|
|
424
329
|
function renderTabButtons(tabsEl, tabs, activeId) {
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
* Generate HTML for ONLY the button elements (no marker wrapper).
|
|
459
|
-
* Used during smart updates to preserve the marker wrapper.
|
|
460
|
-
*/
|
|
330
|
+
const buttons = tabs.map((tab) => {
|
|
331
|
+
const tabId = getTabId(tab);
|
|
332
|
+
if (!tabId)
|
|
333
|
+
return '';
|
|
334
|
+
const labelType = getTabLabelType(tabsEl, tab);
|
|
335
|
+
const textLabel = labelType === 'text' ? (tab.getAttribute('label') || 'Tab') : '';
|
|
336
|
+
const disabled = isTabDisabled(tab);
|
|
337
|
+
const active = tabId === activeId;
|
|
338
|
+
return `<button
|
|
339
|
+
class="tab-button"
|
|
340
|
+
role="tab"
|
|
341
|
+
data-tab-id="${tabId}"
|
|
342
|
+
id="tab-${tabId}"
|
|
343
|
+
aria-selected="${active}"
|
|
344
|
+
tabindex="${active ? '0' : '-1'}"
|
|
345
|
+
data-active="${active}"
|
|
346
|
+
${disabled ? 'disabled aria-disabled="true"' : ''}
|
|
347
|
+
>
|
|
348
|
+
${labelType === 'slot' ? `<slot name="label-${tabId}"></slot>` : `<span class="tab-label">${textLabel}</span>`}
|
|
349
|
+
</button>`;
|
|
350
|
+
}).join('');
|
|
351
|
+
return `
|
|
352
|
+
<div class="tab-buttons" part="buttons-container">
|
|
353
|
+
<div class="tab-strip" role="tablist" part="strip">
|
|
354
|
+
<div class="marker-wrapper" part="marker-wrapper">
|
|
355
|
+
${!hasCustomMarker(tabsEl) ? '<div class="default-marker"></div>' : ''}
|
|
356
|
+
<slot name="marker"></slot>
|
|
357
|
+
</div>
|
|
358
|
+
${buttons}
|
|
359
|
+
</div>
|
|
360
|
+
</div>
|
|
361
|
+
`;
|
|
362
|
+
}
|
|
461
363
|
function renderButtonsOnly(tabsEl, tabs, activeId) {
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
364
|
+
return tabs.map((tab) => {
|
|
365
|
+
const tabId = getTabId(tab);
|
|
366
|
+
if (!tabId)
|
|
367
|
+
return '';
|
|
368
|
+
const labelType = getTabLabelType(tabsEl, tab);
|
|
369
|
+
const textLabel = labelType === 'text' ? (tab.getAttribute('label') || 'Tab') : '';
|
|
370
|
+
const disabled = isTabDisabled(tab);
|
|
371
|
+
const active = tabId === activeId;
|
|
372
|
+
return `<button
|
|
373
|
+
class="tab-button"
|
|
374
|
+
role="tab"
|
|
375
|
+
data-tab-id="${tabId}"
|
|
376
|
+
id="tab-${tabId}"
|
|
377
|
+
aria-selected="${active}"
|
|
378
|
+
tabindex="${active ? '0' : '-1'}"
|
|
379
|
+
data-active="${active}"
|
|
380
|
+
${disabled ? 'disabled aria-disabled="true"' : ''}
|
|
381
|
+
>
|
|
382
|
+
${labelType === 'slot' ? `<slot name="label-${tabId}"></slot>` : `<span class="tab-label">${textLabel}</span>`}
|
|
383
|
+
</button>`;
|
|
384
|
+
}).join('');
|
|
385
|
+
}
|
|
386
|
+
function getTabMenuLabel(tabsEl, tab) {
|
|
387
|
+
const tabId = getTabId(tab);
|
|
388
|
+
if (tabId && getTabLabelType(tabsEl, tab) === 'slot') {
|
|
389
|
+
const slotted = getSlotLabel(tabsEl, tabId);
|
|
390
|
+
return slotted?.textContent?.trim() || tabId;
|
|
391
|
+
}
|
|
392
|
+
return tab.getAttribute('label') || 'Tab';
|
|
393
|
+
}
|
|
394
|
+
function removeOverflowMenu(shadowRoot) {
|
|
395
|
+
shadowRoot.querySelector('.tab-overflow-trigger')?.remove();
|
|
396
|
+
}
|
|
397
|
+
function renderOverflowMenu(el, container, allTabs) {
|
|
398
|
+
const activeId = getActiveTabId(el, allTabs);
|
|
399
|
+
const trigger = document.createElement('button');
|
|
400
|
+
trigger.className = 'tab-overflow-trigger';
|
|
401
|
+
trigger.type = 'button';
|
|
402
|
+
trigger.setAttribute('aria-label', `${allTabs.length} tabs`);
|
|
403
|
+
trigger.textContent = '⋯';
|
|
404
|
+
const popup = document.createElement('ty-popup');
|
|
405
|
+
popup.setAttribute('placement', 'bottom');
|
|
406
|
+
const menu = document.createElement('div');
|
|
407
|
+
menu.className = 'tab-overflow-menu';
|
|
408
|
+
menu.setAttribute('role', 'menu');
|
|
409
|
+
allTabs.forEach((tab) => {
|
|
410
|
+
const tabId = getTabId(tab);
|
|
411
|
+
if (!tabId)
|
|
412
|
+
return;
|
|
413
|
+
const item = document.createElement('button');
|
|
414
|
+
item.type = 'button';
|
|
415
|
+
item.className = 'tab-overflow-item';
|
|
416
|
+
item.setAttribute('role', 'menuitem');
|
|
417
|
+
item.setAttribute('data-tab-id', tabId);
|
|
418
|
+
item.setAttribute('data-active', String(tabId === activeId));
|
|
419
|
+
item.textContent = getTabMenuLabel(el, tab);
|
|
420
|
+
if (isTabDisabled(tab)) {
|
|
421
|
+
item.disabled = true;
|
|
422
|
+
}
|
|
423
|
+
else {
|
|
424
|
+
item.addEventListener('click', () => {
|
|
425
|
+
activateTab(el, tabId);
|
|
426
|
+
popup.closePopup?.();
|
|
427
|
+
});
|
|
428
|
+
}
|
|
429
|
+
menu.appendChild(item);
|
|
430
|
+
});
|
|
431
|
+
popup.appendChild(menu);
|
|
432
|
+
trigger.appendChild(popup);
|
|
433
|
+
container.appendChild(trigger);
|
|
434
|
+
}
|
|
435
|
+
function updateOverflow(el) {
|
|
436
|
+
const shadowRoot = el.shadowRoot;
|
|
437
|
+
if (!shadowRoot)
|
|
438
|
+
return;
|
|
439
|
+
const container = shadowRoot.querySelector('.tab-buttons');
|
|
440
|
+
const strip = shadowRoot.querySelector('.tab-strip');
|
|
441
|
+
if (!container || !strip)
|
|
442
|
+
return;
|
|
443
|
+
if (getTabsAttributes(el).fixed) {
|
|
444
|
+
removeOverflowMenu(shadowRoot);
|
|
445
|
+
strip.classList.add('unclipped');
|
|
446
|
+
strip.style.removeProperty('--fade-left');
|
|
447
|
+
strip.style.removeProperty('--fade-right');
|
|
448
|
+
return;
|
|
449
|
+
}
|
|
450
|
+
const savedScrollLeft = strip.scrollLeft;
|
|
451
|
+
removeOverflowMenu(shadowRoot);
|
|
452
|
+
if (strip.clientWidth <= 0)
|
|
453
|
+
return;
|
|
454
|
+
const buttons = strip.querySelectorAll('.tab-button');
|
|
455
|
+
const last = buttons[buttons.length - 1];
|
|
456
|
+
const contentWidth = last ? last.offsetLeft + last.offsetWidth : 0;
|
|
457
|
+
const stripWidth = strip.clientWidth;
|
|
458
|
+
const hidden = contentWidth - stripWidth;
|
|
459
|
+
strip.classList.toggle('unclipped', hidden <= 1);
|
|
460
|
+
if (hidden <= 1) {
|
|
461
|
+
strip.scrollLeft = savedScrollLeft;
|
|
462
|
+
updateEdgeFades(strip);
|
|
463
|
+
return;
|
|
464
|
+
}
|
|
465
|
+
renderOverflowMenu(el, container, getChildTabs(el));
|
|
466
|
+
const triggerCost = container.clientWidth - strip.clientWidth;
|
|
467
|
+
if (hidden <= triggerCost) {
|
|
468
|
+
removeOverflowMenu(shadowRoot);
|
|
469
|
+
}
|
|
470
|
+
strip.scrollLeft = savedScrollLeft;
|
|
471
|
+
updateEdgeFades(strip);
|
|
472
|
+
}
|
|
473
|
+
function updateEdgeFades(strip) {
|
|
474
|
+
const maxScroll = strip.scrollWidth - strip.clientWidth;
|
|
475
|
+
const fade = (distance) => `${distance > 1 ? Math.min(28, distance) : 0}px`;
|
|
476
|
+
strip.style.setProperty('--fade-left', fade(strip.scrollLeft));
|
|
477
|
+
strip.style.setProperty('--fade-right', fade(maxScroll - strip.scrollLeft));
|
|
478
|
+
}
|
|
479
|
+
function scrollActiveIntoView(el, activeId, smooth) {
|
|
480
|
+
const shadowRoot = el.shadowRoot;
|
|
481
|
+
if (!shadowRoot)
|
|
482
|
+
return;
|
|
483
|
+
const strip = shadowRoot.querySelector('.tab-strip');
|
|
484
|
+
const button = shadowRoot.querySelector(`[data-tab-id='${activeId}']`);
|
|
485
|
+
if (!strip || !button || strip.clientWidth <= 0)
|
|
486
|
+
return;
|
|
487
|
+
const centered = button.offsetLeft + button.offsetWidth / 2 - strip.clientWidth / 2;
|
|
488
|
+
const target = Math.max(0, Math.min(centered, strip.scrollWidth - strip.clientWidth));
|
|
489
|
+
if (Math.round(target) !== Math.round(strip.scrollLeft)) {
|
|
490
|
+
const reduce = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
|
|
491
|
+
strip.scrollTo({ left: target, behavior: smooth && !reduce ? 'smooth' : 'auto' });
|
|
492
|
+
}
|
|
493
|
+
}
|
|
489
494
|
function render(el) {
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
}
|
|
569
|
-
// Update transform with measured width
|
|
570
|
-
updateTransform(el, activeIndex);
|
|
571
|
-
// Update marker position to match active tab
|
|
572
|
-
if (activeId) {
|
|
573
|
-
updateMarker(el, activeId);
|
|
574
|
-
}
|
|
575
|
-
});
|
|
576
|
-
// Setup event listeners
|
|
577
|
-
setupEventListeners(el, shadowRoot, tabs);
|
|
578
|
-
// Update ARIA and data-active attributes on initial render
|
|
579
|
-
updateAriaAttributes(el, shadowRoot, activeId || '');
|
|
580
|
-
// Setup ResizeObserver for responsive width
|
|
581
|
-
setupResizeObserver(el);
|
|
582
|
-
// Update tab panel states
|
|
583
|
-
if (activeId) {
|
|
584
|
-
updatePanelInteraction(el, activeId);
|
|
585
|
-
}
|
|
586
|
-
// Listen for marker slot changes to hide default marker
|
|
587
|
-
const markerSlot = shadowRoot.querySelector('slot[name="marker"]');
|
|
588
|
-
if (markerSlot) {
|
|
589
|
-
const updateDefaultMarkerVisibility = () => {
|
|
590
|
-
const defaultMarker = shadowRoot.querySelector('.default-marker');
|
|
591
|
-
if (defaultMarker) {
|
|
592
|
-
const hasCustom = markerSlot.assignedElements().length > 0;
|
|
593
|
-
defaultMarker.style.display = hasCustom ? 'none' : '';
|
|
594
|
-
}
|
|
595
|
-
};
|
|
596
|
-
markerSlot.addEventListener('slotchange', updateDefaultMarkerVisibility);
|
|
597
|
-
// Check immediately in case content is already slotted
|
|
598
|
-
updateDefaultMarkerVisibility();
|
|
599
|
-
}
|
|
600
|
-
}
|
|
601
|
-
}
|
|
602
|
-
/**
|
|
603
|
-
* Cleanup when tabs component is disconnected
|
|
604
|
-
*/
|
|
495
|
+
const shadowRoot = el.shadowRoot;
|
|
496
|
+
if (!shadowRoot)
|
|
497
|
+
return;
|
|
498
|
+
const { placement, fixed } = getTabsAttributes(el);
|
|
499
|
+
const tabs = getChildTabs(el);
|
|
500
|
+
const activeId = getActiveTabId(el, tabs);
|
|
501
|
+
const activeIndex = activeId ? (findTabIndex(tabs, activeId) ?? 0) : 0;
|
|
502
|
+
tabs.forEach((tab) => tab.setPanelLabel?.(getTabMenuLabel(el, tab)));
|
|
503
|
+
const existingContainer = shadowRoot.querySelector('.tabs-container');
|
|
504
|
+
const existingButtons = shadowRoot.querySelector('.tab-buttons');
|
|
505
|
+
const existingStrip = shadowRoot.querySelector('.tab-strip');
|
|
506
|
+
const existingViewport = shadowRoot.querySelector('.panels-viewport');
|
|
507
|
+
ensureStyles(shadowRoot, { css: tabsStyles, id: 'ty-tabs' });
|
|
508
|
+
if (existingContainer && existingButtons && existingStrip && existingViewport) {
|
|
509
|
+
existingContainer.setAttribute('data-placement', placement);
|
|
510
|
+
existingContainer.toggleAttribute('data-fixed', fixed);
|
|
511
|
+
const savedScrollLeft = existingStrip.scrollLeft;
|
|
512
|
+
existingButtons.querySelector('.tab-overflow-trigger')?.remove();
|
|
513
|
+
const allButtons = existingStrip.querySelectorAll('.tab-button');
|
|
514
|
+
allButtons.forEach(button => button.remove());
|
|
515
|
+
const buttonsHtml = renderButtonsOnly(el, tabs, activeId);
|
|
516
|
+
const tempDiv = document.createElement('div');
|
|
517
|
+
tempDiv.innerHTML = buttonsHtml;
|
|
518
|
+
Array.from(tempDiv.children).forEach(button => {
|
|
519
|
+
existingStrip.appendChild(button);
|
|
520
|
+
});
|
|
521
|
+
existingStrip.scrollLeft = savedScrollLeft;
|
|
522
|
+
setupEventListeners(el, shadowRoot, tabs);
|
|
523
|
+
updateAriaAttributes(el, shadowRoot, activeId || '');
|
|
524
|
+
const firstShow = !shownTabs.get(el);
|
|
525
|
+
requestAnimationFrame(() => {
|
|
526
|
+
const currentId = currentActive(el);
|
|
527
|
+
updateOverflow(el);
|
|
528
|
+
if (currentId) {
|
|
529
|
+
updateMarker(el, currentId, firstShow);
|
|
530
|
+
scrollActiveIntoView(el, currentId, !firstShow);
|
|
531
|
+
}
|
|
532
|
+
});
|
|
533
|
+
updatePanelInteraction(el, activeId);
|
|
534
|
+
}
|
|
535
|
+
else {
|
|
536
|
+
shadowRoot.innerHTML = `
|
|
537
|
+
<div class="tabs-container" data-placement="${placement}"${fixed ? ' data-fixed' : ''}>
|
|
538
|
+
${renderTabButtons(el, tabs, activeId)}
|
|
539
|
+
<div class="panels-viewport" part="panels-container">
|
|
540
|
+
<div class="panels-wrapper" style="transform: ${carouselTransform(activeIndex)}">
|
|
541
|
+
<slot></slot>
|
|
542
|
+
</div>
|
|
543
|
+
</div>
|
|
544
|
+
</div>
|
|
545
|
+
`;
|
|
546
|
+
requestAnimationFrame(() => {
|
|
547
|
+
const currentId = currentActive(el);
|
|
548
|
+
updateOverflow(el);
|
|
549
|
+
if (currentId) {
|
|
550
|
+
updateMarker(el, currentId);
|
|
551
|
+
scrollActiveIntoView(el, currentId, false);
|
|
552
|
+
}
|
|
553
|
+
});
|
|
554
|
+
setupEventListeners(el, shadowRoot, tabs);
|
|
555
|
+
updateAriaAttributes(el, shadowRoot, activeId || '');
|
|
556
|
+
const strip = shadowRoot.querySelector('.tab-strip');
|
|
557
|
+
strip?.addEventListener('scroll', () => updateEdgeFades(strip), { passive: true });
|
|
558
|
+
updatePanelInteraction(el, activeId);
|
|
559
|
+
const markerSlot = shadowRoot.querySelector('slot[name="marker"]');
|
|
560
|
+
if (markerSlot) {
|
|
561
|
+
const updateDefaultMarkerVisibility = () => {
|
|
562
|
+
const defaultMarker = shadowRoot.querySelector('.default-marker');
|
|
563
|
+
if (defaultMarker) {
|
|
564
|
+
const hasCustom = markerSlot.assignedElements().length > 0;
|
|
565
|
+
defaultMarker.style.display = hasCustom ? 'none' : '';
|
|
566
|
+
}
|
|
567
|
+
};
|
|
568
|
+
markerSlot.addEventListener('slotchange', updateDefaultMarkerVisibility);
|
|
569
|
+
updateDefaultMarkerVisibility();
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
}
|
|
605
573
|
function cleanup(el) {
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
}
|
|
609
|
-
// ============================================================================
|
|
610
|
-
// Component Definition
|
|
611
|
-
// ============================================================================
|
|
612
|
-
/**
|
|
613
|
-
* TyTabs Web Component
|
|
614
|
-
*/
|
|
574
|
+
cleanupEventListeners(el);
|
|
575
|
+
cleanupResizeObserver(el);
|
|
576
|
+
}
|
|
615
577
|
export class TyTabs extends HTMLElement {
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
578
|
+
static get observedAttributes() {
|
|
579
|
+
return ['width', 'height', 'active', 'placement', 'fixed'];
|
|
580
|
+
}
|
|
581
|
+
constructor() {
|
|
582
|
+
super();
|
|
583
|
+
this._childObserver = null;
|
|
584
|
+
this._updateQueued = false;
|
|
585
|
+
this._structureDirty = false;
|
|
586
|
+
this.attachShadow({ mode: 'open' });
|
|
587
|
+
}
|
|
588
|
+
get activeTab() {
|
|
589
|
+
return shownTabs.get(this) ?? null;
|
|
590
|
+
}
|
|
591
|
+
connectedCallback() {
|
|
592
|
+
render(this);
|
|
593
|
+
syncShownTab(this);
|
|
594
|
+
setupResizeObserver(this);
|
|
595
|
+
this._childObserver = new MutationObserver(() => this._queueUpdate(true));
|
|
596
|
+
this._childObserver.observe(this, { childList: true });
|
|
597
|
+
}
|
|
598
|
+
disconnectedCallback() {
|
|
599
|
+
this._childObserver?.disconnect();
|
|
600
|
+
this._childObserver = null;
|
|
601
|
+
cleanup(this);
|
|
602
|
+
}
|
|
603
|
+
_queueUpdate(structure) {
|
|
604
|
+
this._structureDirty || (this._structureDirty = structure);
|
|
605
|
+
if (this._updateQueued)
|
|
606
|
+
return;
|
|
607
|
+
this._updateQueued = true;
|
|
608
|
+
queueMicrotask(() => {
|
|
609
|
+
this._updateQueued = false;
|
|
610
|
+
if (!this.isConnected)
|
|
611
|
+
return;
|
|
612
|
+
if (this._childObserver?.takeRecords().length)
|
|
613
|
+
this._structureDirty = true;
|
|
614
|
+
if (this._structureDirty) {
|
|
615
|
+
this._structureDirty = false;
|
|
616
|
+
render(this);
|
|
617
|
+
}
|
|
618
|
+
syncShownTab(this);
|
|
619
|
+
});
|
|
620
|
+
}
|
|
621
|
+
attributeChangedCallback(name, oldValue, newValue) {
|
|
622
|
+
if (!this.isConnected)
|
|
623
|
+
return;
|
|
624
|
+
if (name === 'active') {
|
|
625
|
+
if (oldValue !== newValue)
|
|
626
|
+
awaitedTabs.delete(this);
|
|
627
|
+
this._queueUpdate(false);
|
|
628
|
+
}
|
|
629
|
+
else
|
|
630
|
+
render(this);
|
|
631
|
+
}
|
|
632
|
+
}
|
|
650
633
|
if (!customElements.get('ty-tabs')) {
|
|
651
|
-
|
|
634
|
+
customElements.define('ty-tabs', TyTabs);
|
|
652
635
|
}
|
|
653
|
-
//# sourceMappingURL=tabs.js.map
|