@hortonstudio/main 1.9.10 → 1.9.20

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 (124) hide show
  1. package/.prettierrc +8 -0
  2. package/README.md +146 -0
  3. package/eslint.config.js +32 -0
  4. package/index.ts +275 -0
  5. package/package.json +19 -2
  6. package/public/bootstrap.js +16 -0
  7. package/src/animations/animations.ts +93 -0
  8. package/src/animations/functions/counter/counter.ts +137 -0
  9. package/src/config.json +570 -0
  10. package/src/config.ts +105 -0
  11. package/src/modules/default/README.md +167 -0
  12. package/src/modules/default/default.ts +71 -0
  13. package/{autoInit → src/modules/default/functions}/accessibility/README.md +44 -12
  14. package/src/modules/default/functions/accessibility/accessibility.ts +54 -0
  15. package/src/modules/default/functions/accordion/README.md +451 -0
  16. package/src/modules/default/functions/accordion/accordion.ts +189 -0
  17. package/src/modules/default/functions/comparison/comparison.ts +424 -0
  18. package/src/modules/default/functions/marquee/marquee.ts +206 -0
  19. package/src/modules/default/functions/navbar/README.md +393 -0
  20. package/src/modules/default/functions/navbar/functions/arrow-navigation/arrow-navigation.ts +183 -0
  21. package/src/modules/default/functions/navbar/functions/dropdown/dropdown.ts +313 -0
  22. package/src/modules/default/functions/navbar/functions/menu/menu.ts +315 -0
  23. package/src/modules/default/functions/navbar/navbar.ts +51 -0
  24. package/{autoInit → src/modules/default/functions}/smooth-scroll/README.md +45 -14
  25. package/{autoInit/smooth-scroll/smooth-scroll.js → src/modules/default/functions/smooth-scroll/smooth-scroll.ts} +33 -38
  26. package/{autoInit → src/modules/default/functions}/transition/README.md +59 -32
  27. package/src/modules/default/functions/transition/transition.ts +290 -0
  28. package/src/modules/normalize/README.md +172 -0
  29. package/src/modules/normalize/functions/clickable/README.md +84 -0
  30. package/src/modules/normalize/functions/clickable/clickable.ts +43 -0
  31. package/src/modules/normalize/functions/clickable/functions/normalize/README.md +213 -0
  32. package/src/modules/normalize/functions/clickable/functions/normalize/normalize.ts +68 -0
  33. package/src/modules/normalize/functions/dupe/README.md +405 -0
  34. package/src/modules/normalize/functions/dupe/dupe.ts +197 -0
  35. package/src/modules/normalize/functions/sync/sync.ts +378 -0
  36. package/src/modules/normalize/normalize.ts +58 -0
  37. package/src/modules/structure/README.md +190 -0
  38. package/src/modules/structure/functions/form/README.md +94 -0
  39. package/src/modules/structure/functions/form/form.ts +54 -0
  40. package/src/modules/structure/functions/form/functions/honeypot/README.md +77 -0
  41. package/src/modules/structure/functions/form/functions/honeypot/honeypot.ts +37 -0
  42. package/src/modules/structure/functions/form/functions/range/README.md +410 -0
  43. package/src/modules/structure/functions/form/functions/range/range.ts +92 -0
  44. package/src/modules/structure/functions/form/functions/select/README.md +393 -0
  45. package/src/modules/structure/functions/form/functions/select/functions/custom-select/custom-select.ts +637 -0
  46. package/src/modules/structure/functions/form/functions/select/functions/states/states.ts +118 -0
  47. package/src/modules/structure/functions/form/functions/select/select.ts +48 -0
  48. package/src/modules/structure/functions/form/functions/test/test.ts +132 -0
  49. package/src/modules/structure/functions/pagination/README.md +527 -0
  50. package/src/modules/structure/functions/pagination/pagination.ts +493 -0
  51. package/src/modules/structure/functions/site-settings/README.md +395 -0
  52. package/src/modules/structure/functions/site-settings/site-settings.ts +158 -0
  53. package/{autoInit/accessibility → src/modules/structure}/functions/toc/README.md +18 -15
  54. package/{autoInit/accessibility/functions/toc/toc.js → src/modules/structure/functions/toc/functions/heading-links/heading-links.ts} +43 -63
  55. package/src/modules/structure/functions/toc/functions/progress-bar/progress-bar.ts +101 -0
  56. package/src/modules/structure/functions/toc/toc.ts +35 -0
  57. package/{autoInit/accessibility → src/modules/structure}/functions/year-replacement/README.md +7 -6
  58. package/src/modules/structure/functions/year-replacement/year-replacement.ts +59 -0
  59. package/src/modules/structure/structure.ts +59 -0
  60. package/src/utils/attributeSelector.ts +78 -0
  61. package/src/utils/cssVariables.ts +24 -0
  62. package/src/utils/gsap.ts +198 -0
  63. package/src/utils/heightAnimator.ts +130 -0
  64. package/src/utils/modalManager.ts +150 -0
  65. package/src/utils.ts +54 -0
  66. package/tsconfig.json +24 -0
  67. package/vite.config.js +45 -0
  68. package/.claude/settings.local.json +0 -70
  69. package/archive/hero.js +0 -794
  70. package/archive/modal.js +0 -80
  71. package/archive/text.js +0 -628
  72. package/autoInit/accessibility/accessibility.js +0 -53
  73. package/autoInit/accessibility/functions/blog-remover/README.md +0 -61
  74. package/autoInit/accessibility/functions/blog-remover/blog-remover.js +0 -31
  75. package/autoInit/accessibility/functions/click-forwarding/README.md +0 -60
  76. package/autoInit/accessibility/functions/click-forwarding/click-forwarding.js +0 -82
  77. package/autoInit/accessibility/functions/dropdown/README.md +0 -212
  78. package/autoInit/accessibility/functions/dropdown/dropdown.js +0 -167
  79. package/autoInit/accessibility/functions/list-accessibility/README.md +0 -56
  80. package/autoInit/accessibility/functions/list-accessibility/list-accessibility.js +0 -23
  81. package/autoInit/accessibility/functions/pagination/README.md +0 -428
  82. package/autoInit/accessibility/functions/pagination/pagination.js +0 -359
  83. package/autoInit/accessibility/functions/text-synchronization/README.md +0 -62
  84. package/autoInit/accessibility/functions/text-synchronization/text-synchronization.js +0 -101
  85. package/autoInit/accessibility/functions/year-replacement/year-replacement.js +0 -43
  86. package/autoInit/button/README.md +0 -122
  87. package/autoInit/button/button.js +0 -51
  88. package/autoInit/counter/README.md +0 -274
  89. package/autoInit/counter/counter.js +0 -185
  90. package/autoInit/form/README.md +0 -338
  91. package/autoInit/form/form.js +0 -374
  92. package/autoInit/navbar/README.md +0 -366
  93. package/autoInit/navbar/navbar.js +0 -786
  94. package/autoInit/site-settings/README.md +0 -218
  95. package/autoInit/site-settings/site-settings.js +0 -134
  96. package/autoInit/transition/transition.js +0 -116
  97. package/index.js +0 -305
  98. package/utils/before-after/README.md +0 -520
  99. package/utils/before-after/before-after.js +0 -653
  100. package/utils/css-animations/buttons/main/bgbasic/btn-main-bgbasic.html +0 -10
  101. package/utils/css-animations/buttons/main/bgfill/btn-main-bgfill.html +0 -29
  102. package/utils/css-animations/buttons/navbar/bgbasic/navbar-main-bgbasic.html +0 -17
  103. package/utils/css-animations/buttons/navbar/bgbasic/navbar-menu-bgbasic.html +0 -16
  104. package/utils/css-animations/buttons/navbar/bgfill/navbar-main-bgfill.html +0 -46
  105. package/utils/css-animations/buttons/navbar/bgfill/navbar-menu-bgfill.html +0 -39
  106. package/utils/css-animations/buttons/navbar/color/navbar-announce-color.html +0 -5
  107. package/utils/css-animations/buttons/navbar/color/navbar-main-color.html +0 -7
  108. package/utils/css-animations/buttons/navbar/color/navbar-menu-color.html +0 -7
  109. package/utils/css-animations/buttons/navbar/double-slide/navbar-announce-double-slide.html +0 -40
  110. package/utils/css-animations/buttons/navbar/double-slide/navbar-main-double-slide.html +0 -77
  111. package/utils/css-animations/buttons/navbar/scale/navbar-announce-scale.html +0 -6
  112. package/utils/css-animations/buttons/navbar/scale/navbar-main-scale.html +0 -9
  113. package/utils/css-animations/buttons/navbar/scale/navbar-menu-scale.html +0 -8
  114. package/utils/css-animations/buttons/navbar/underline/navbar-announce-underline.html +0 -32
  115. package/utils/css-animations/buttons/navbar/underline/navbar-main-underline.html +0 -56
  116. package/utils/css-animations/buttons/text/color/text-footer-color.html +0 -5
  117. package/utils/css-animations/buttons/text/color/text-main-color.html +0 -5
  118. package/utils/css-animations/buttons/text/double-slide/text-main-double-slide.html +0 -56
  119. package/utils/css-animations/buttons/text/scale/text-footer-scale.html +0 -6
  120. package/utils/css-animations/buttons/text/scale/text-main-scale.html +0 -6
  121. package/utils/css-animations/buttons/text/underline/text-footer-underline.html +0 -45
  122. package/utils/css-animations/buttons/text/underline/text-main-underline.html +0 -58
  123. package/utils/css-animations/cards/card-clickable.html +0 -11
  124. package/utils/css-animations/defaults.html +0 -69
@@ -1,520 +0,0 @@
1
- # **Before/After Image Comparison Documentation**
2
-
3
- ## **Overview**
4
-
5
- Interactive before/after image comparison utility with multiple viewing modes, slider controls, and carousel functionality. Features full keyboard navigation, touch gestures, ARIA live announcements, and Barba.js compatibility.
6
-
7
- **Note:** This utility is loaded via `data-hs-util-ba` attribute on the script tag in index.js.
8
-
9
- ---
10
-
11
- ## **Features**
12
-
13
- - **Three Viewing Modes**: Before, After, and Split (slider)
14
- - **Multiple Items**: Carousel navigation with arrows and pagination
15
- - **Slider Control**: Draggable slider with click-to-position
16
- - **Keyboard Support**: Full arrow key navigation and slider control
17
- - **Touch Gestures**: Complete mobile touch support
18
- - **Accessibility**: Live regions, proper ARIA attributes, semantic roles
19
- - **Memory Safe**: WeakMap-based references, proper cleanup for Barba.js
20
- - **Console Warnings**: Helpful warnings for missing required elements
21
-
22
- ---
23
-
24
- ## **Required Structure**
25
-
26
- ### **Wrapper** *(required)*
27
-
28
- **Attribute:** `data-hs-ba="wrapper"`
29
-
30
- **What it does:** Main container for entire before/after instance. Automatically receives:
31
- - `role="region"`
32
- - `aria-roledescription="image comparison carousel"`
33
- - `aria-label` with keyboard instructions
34
- - Live region for announcing state changes
35
-
36
- ---
37
-
38
- ### **Image Wrapper** *(required)*
39
-
40
- **Attribute:** `data-hs-ba="image-wrapper"`
41
-
42
- **What it does:** Container for before/after images. Made focusable for keyboard slider control.
43
- - `tabindex="0"` for keyboard focus
44
- - `role="img"` for semantics
45
- - Arrow keys adjust slider position when focused (in split mode)
46
-
47
- ---
48
-
49
- ### **Before Image** *(required)*
50
-
51
- **Attribute:** `data-hs-ba="image-before"`
52
-
53
- **What it does:** Background/base image layer. Always visible behind the after image.
54
-
55
- ---
56
-
57
- ### **After Image** *(required)*
58
-
59
- **Attribute:** `data-hs-ba="image-after"`
60
-
61
- **What it does:** Foreground image with clip-path animation. Reveals/hides based on mode and slider position.
62
-
63
- ---
64
-
65
- ### **Slider** *(optional)*
66
-
67
- **Attribute:** `data-hs-ba="slider"`
68
-
69
- **What it does:** Draggable handle for split view mode. Hidden in before/after modes.
70
- - Supports mouse and touch dragging
71
- - Click anywhere on image wrapper to reposition
72
-
73
- ---
74
-
75
- ### **Mode Buttons** *(optional)*
76
-
77
- **Attributes:**
78
- - `data-hs-ba="mode-before"`
79
- - `data-hs-ba="mode-split"`
80
- - `data-hs-ba="mode-after"`
81
-
82
- **What they do:** Switch between viewing modes. Must use Global/Button component pattern:
83
-
84
- **Typical element layout:**
85
-
86
- 1. Mode Wrapper (data-hs-ba="mode-before/split/after")
87
- 1. Style Element (has data-button-style attribute as descendant)
88
- 2. Clickable Wrapper (data-site-clickable="element")
89
- 1. Actual Button Element (first child)
90
-
91
- **What JavaScript does:**
92
- - Finds `[data-site-clickable="element"]` and gets `.children[0]` for actual button
93
- - Adds descriptive `aria-label` ("Switch to before view", etc.)
94
- - Manages `aria-pressed` state (true/false)
95
- - Finds descendant with `data-button-style` and updates between "primary"/"secondary"
96
- - Announces mode changes via live region
97
-
98
- ---
99
-
100
- ### **Navigation Arrows** *(optional, for multiple items)*
101
-
102
- **Attributes:**
103
- - `data-hs-ba="left-arrow"` - Previous item
104
- - `data-hs-ba="right-arrow"` - Next item
105
-
106
- **What they do:** Navigate between carousel items. Must use Global/Clickable component pattern:
107
-
108
- **Typical element layout:**
109
-
110
- 1. Arrow Wrapper (data-hs-ba="left-arrow" or "right-arrow")
111
- 1. Clickable Wrapper (data-site-clickable="element")
112
- 1. Link or Button Element (first child)
113
-
114
- **What JavaScript does:**
115
- - Finds `[data-site-clickable="element"]` and gets `.children[0]`
116
- - Adds `aria-label` ("Previous image" or "Next image")
117
- - Loops through items infinitely
118
- - Announces slide changes via live region
119
-
120
- ---
121
-
122
- ### **Pagination** *(optional)*
123
-
124
- **Attribute:** `data-hs-ba="pagination"`
125
-
126
- **What it does:** Displays dots for each item. Requires template dot as first child.
127
-
128
- **Typical element layout:**
129
-
130
- 1. Pagination Container (data-hs-ba="pagination")
131
- 1. Template Dot (first child, will be cloned)
132
-
133
- **What JavaScript does:**
134
- - Clones first child for each item
135
- - Adds `role="group"` and `aria-label="Image pagination"` to container
136
- - Adds `role="button"`, `tabindex="0"`, `aria-label` to each dot
137
- - Manages `is-active` class and `aria-current="true"` state
138
- - Keyboard accessible (Enter/Space to activate)
139
-
140
- ---
141
-
142
- ## **Usage Example**
143
-
144
- ### **Single Comparison**
145
-
146
- ```html
147
- <div data-hs-ba="wrapper">
148
- <div data-hs-ba="image-wrapper">
149
- <img data-hs-ba="image-before" src="before.jpg" alt="Before">
150
- <img data-hs-ba="image-after" src="after.jpg" alt="After">
151
- <div data-hs-ba="slider">
152
- <!-- Slider handle content -->
153
- </div>
154
- </div>
155
-
156
- <!-- Mode buttons (using Global/Button components) -->
157
- <div data-hs-ba="mode-before" data-site-button="wrapper">
158
- <div data-button-style="secondary">
159
- <div data-site-clickable="element">
160
- <button type="button">Before</button>
161
- </div>
162
- </div>
163
- </div>
164
-
165
- <div data-hs-ba="mode-split" data-site-button="wrapper">
166
- <div data-button-style="primary">
167
- <div data-site-clickable="element">
168
- <button type="button">Split</button>
169
- </div>
170
- </div>
171
- </div>
172
-
173
- <div data-hs-ba="mode-after" data-site-button="wrapper">
174
- <div data-button-style="secondary">
175
- <div data-site-clickable="element">
176
- <button type="button">After</button>
177
- </div>
178
- </div>
179
- </div>
180
- </div>
181
- ```
182
-
183
- ---
184
-
185
- ### **Multiple Items with Carousel**
186
-
187
- ```html
188
- <div data-hs-ba="wrapper">
189
- <!-- Item 1 -->
190
- <div>
191
- <div data-hs-ba="image-wrapper">
192
- <img data-hs-ba="image-before" src="before-1.jpg" alt="Before">
193
- <img data-hs-ba="image-after" src="after-1.jpg" alt="After">
194
- <div data-hs-ba="slider"></div>
195
- </div>
196
-
197
- <!-- Mode buttons for this item -->
198
- <div data-hs-ba="mode-before" data-site-button="wrapper">...</div>
199
- <div data-hs-ba="mode-split" data-site-button="wrapper">...</div>
200
- <div data-hs-ba="mode-after" data-site-button="wrapper">...</div>
201
- </div>
202
-
203
- <!-- Item 2 -->
204
- <div>
205
- <div data-hs-ba="image-wrapper">
206
- <img data-hs-ba="image-before" src="before-2.jpg" alt="Before">
207
- <img data-hs-ba="image-after" src="after-2.jpg" alt="After">
208
- <div data-hs-ba="slider"></div>
209
- </div>
210
-
211
- <!-- Mode buttons for this item -->
212
- <div data-hs-ba="mode-before" data-site-button="wrapper">...</div>
213
- <div data-hs-ba="mode-split" data-site-button="wrapper">...</div>
214
- <div data-hs-ba="mode-after" data-site-button="wrapper">...</div>
215
- </div>
216
-
217
- <!-- Navigation -->
218
- <div data-hs-ba="left-arrow">
219
- <div data-site-clickable="element">
220
- <a href="#">Previous</a>
221
- </div>
222
- </div>
223
-
224
- <div data-hs-ba="right-arrow">
225
- <div data-site-clickable="element">
226
- <a href="#">Next</a>
227
- </div>
228
- </div>
229
-
230
- <!-- Pagination -->
231
- <div data-hs-ba="pagination">
232
- <button class="dot"></button> <!-- Template -->
233
- </div>
234
- </div>
235
- ```
236
-
237
- ---
238
-
239
- ## **Viewing Modes**
240
-
241
- ### **Before Mode**
242
- - Shows only the before image
243
- - Hides slider
244
- - Clips after image to 100% (invisible)
245
- - Announces "Before view" to screen readers
246
-
247
- ### **After Mode**
248
- - Shows only the after image
249
- - Hides slider
250
- - Clips after image to 0% (fully visible)
251
- - Announces "After view" to screen readers
252
-
253
- ### **Split Mode** *(default)*
254
- - Shows both images side by side
255
- - Slider visible and draggable
256
- - Default split at 50%
257
- - Clicking split mode button when already in split mode resets to 50%
258
- - Announces "Split view" to screen readers
259
-
260
- ---
261
-
262
- ## **Keyboard Navigation**
263
-
264
- ### **Main Wrapper Focus:**
265
- - `Arrow Left/Right/Up/Down`: Navigate between carousel items
266
- - Focus returns to wrapper after slide change
267
-
268
- ### **Image Wrapper Focus:**
269
- - `Arrow Left`: Move slider left 5% (in split mode only)
270
- - `Arrow Right`: Move slider right 5% (in split mode only)
271
- - Step size configurable via `keyboardStep` config
272
-
273
- ### **Mode Buttons:**
274
- - `Enter` or `Space`: Activate button
275
- - `aria-pressed` state reflects active mode
276
-
277
- ### **Pagination Dots:**
278
- - `Tab`: Navigate between dots
279
- - `Enter` or `Space`: Jump to that slide
280
-
281
- ---
282
-
283
- ## **Configuration**
284
-
285
- Default configuration can be updated via `window.hsmain.utilBeforeAfter.updateConfig()`:
286
-
287
- ```javascript
288
- {
289
- defaultMode: "split", // Initial viewing mode
290
- sliderPosition: 50, // Default slider position (%)
291
- touchSensitivity: 1, // Touch drag sensitivity
292
- keyboardStep: 5, // Keyboard arrow step (%)
293
- autoPlay: false, // Auto-advance items
294
- autoPlayInterval: 5000 // Auto-play interval (ms)
295
- }
296
- ```
297
-
298
- ---
299
-
300
- ## **API Methods**
301
-
302
- Accessible via `window.hsmain.utilBeforeAfter`:
303
-
304
- ### **showSlide(instanceId, index)**
305
- Navigate to specific item in carousel
306
-
307
- ```javascript
308
- window.hsmain.utilBeforeAfter.showSlide(0, 2); // Go to third item
309
- ```
310
-
311
- ### **setMode(instanceId, mode)**
312
- Change viewing mode programmatically
313
-
314
- ```javascript
315
- window.hsmain.utilBeforeAfter.setMode(0, 'before');
316
- ```
317
-
318
- ### **updateConfig(newConfig)**
319
- Update global configuration
320
-
321
- ```javascript
322
- window.hsmain.utilBeforeAfter.updateConfig({
323
- sliderPosition: 60,
324
- keyboardStep: 10
325
- });
326
- ```
327
-
328
- ---
329
-
330
- ## **Key Attributes Summary**
331
-
332
- | Attribute | Purpose | Required | Element Type |
333
- | ----- | ----- | ----- | ----- |
334
- | `data-hs-ba="wrapper"` | Main container | **Required** | Wrapper div |
335
- | `data-hs-ba="image-wrapper"` | Images container | **Required** | Wrapper div |
336
- | `data-hs-ba="image-before"` | Before image | **Required** | `<img>` |
337
- | `data-hs-ba="image-after"` | After image | **Required** | `<img>` |
338
- | `data-hs-ba="slider"` | Slider handle | Optional | Wrapper div |
339
- | `data-hs-ba="mode-before"` | Before button wrapper | Optional | Wrapper div |
340
- | `data-hs-ba="mode-split"` | Split button wrapper | Optional | Wrapper div |
341
- | `data-hs-ba="mode-after"` | After button wrapper | Optional | Wrapper div |
342
- | `data-hs-ba="left-arrow"` | Previous button wrapper | Optional | Wrapper div |
343
- | `data-hs-ba="right-arrow"` | Next button wrapper | Optional | Wrapper div |
344
- | `data-hs-ba="pagination"` | Pagination container | Optional | Wrapper div |
345
- | `data-site-clickable="element"` | Interactive element wrapper | Required for buttons | Wrapper div |
346
-
347
- ---
348
-
349
- ## **Accessibility Features**
350
-
351
- ### **ARIA Live Regions**
352
- - Dynamically created live region for announcements
353
- - Announces mode changes: "Before view", "After view", "Split view"
354
- - Announces slide changes: "Image 2 of 3"
355
- - Uses `aria-live="polite"` and `aria-atomic="true"`
356
-
357
- ### **Semantic Roles**
358
- - Wrapper: `role="region"` with `aria-roledescription="image comparison carousel"`
359
- - Image wrapper: `role="img"` with descriptive `aria-label`
360
- - Pagination: `role="group"` with `aria-label="Image pagination"`
361
- - Dots: `role="button"` with `aria-current` state
362
-
363
- ### **Button States**
364
- - Mode buttons: `aria-pressed="true"` for active, `"false"` for inactive
365
- - Mode buttons: Descriptive `aria-label` for each mode
366
- - Arrow buttons: `aria-label="Previous image"` / `"Next image"`
367
- - Pagination dots: `aria-current="true"` for active page
368
-
369
- ### **Focus Management**
370
- - Wrapper and image wrapper are keyboard focusable
371
- - Tab key navigates through all interactive elements
372
- - Focus remains on controls during interaction
373
-
374
- ### **Memory Safety**
375
- - Uses WeakMap for storing DOM references (prevents memory leaks)
376
- - Proper cleanup on destroy for Barba.js page transitions
377
- - Global event handlers set up once at module level
378
-
379
- ---
380
-
381
- ## **Touch Support**
382
-
383
- - **Drag slider handle**: Touch and drag to adjust position
384
- - **Click/tap to position**: Click/tap anywhere on image wrapper to move slider
385
- - **Touch-friendly controls**: All buttons and dots are touch accessible
386
- - **Prevents scroll**: Prevents default scroll behavior during drag
387
-
388
- ---
389
-
390
- ## **Console Warnings**
391
-
392
- The utility provides helpful warnings for missing required elements:
393
-
394
- - `[hs-before-after] Wrapper element has no child items`
395
- - `[hs-before-after] Missing required element in item X: data-hs-ba="image-wrapper"`
396
- - `[hs-before-after] Missing required element in item X: data-hs-ba="image-before"`
397
- - `[hs-before-after] Missing required element in item X: data-hs-ba="image-after"`
398
-
399
- Optional elements (slider, mode buttons, navigation, pagination) do not trigger warnings.
400
-
401
- ---
402
-
403
- ## **Barba.js Compatibility**
404
-
405
- The utility is fully compatible with Barba.js page transitions:
406
-
407
- ### **On Destroy:**
408
- 1. Resets global drag state
409
- 2. Removes dynamically created live region elements
410
- 3. Clears cached elements (WeakMap and Map)
411
- 4. Removes all event listeners via clone-and-replace
412
- 5. Strips accessibility attributes from wrappers
413
- 6. Removes `data-initialized` markers
414
- 7. Cleans up window API
415
-
416
- ### **On Reinitialize:**
417
- 1. Finds fresh wrappers on new page
418
- 2. Creates new instances
419
- 3. Reuses existing global event handlers (no duplicates)
420
- 4. Applies all accessibility features to new elements
421
-
422
- ### **Global Event Handlers:**
423
- - Mouse/touch drag handlers attached once at module level
424
- - Shared across all page transitions
425
- - Only execute when `globalDragInstance` exists
426
- - No memory leaks or duplicate listeners
427
-
428
- ---
429
-
430
- ## **How It Works**
431
-
432
- 1. **Module Load**: Global event handlers attach to document (once)
433
- 2. **Initialization**: Finds all `[data-hs-ba="wrapper"]` elements not yet initialized
434
- 3. **Instance Creation**: Each wrapper becomes independent instance
435
- 4. **Live Region**: Creates hidden ARIA live region for announcements
436
- 5. **Accessibility Setup**: Adds all ARIA attributes and semantic roles
437
- 6. **Carousel Setup**: Multiple items get navigation and pagination
438
- 7. **Mode Management**: Buttons control image visibility via clip-path
439
- 8. **Slider Dragging**: Global handlers update clip-path via `globalDragInstance`
440
- 9. **Keyboard Control**: Arrow keys navigate items and adjust slider
441
- 10. **State Persistence**: Slider position maintained across item changes
442
- 11. **Cleanup**: Destroy removes all traces for clean Barba.js transitions
443
-
444
- ---
445
-
446
- ## **Clickable Element Pattern**
447
-
448
- **All interactive elements** (mode buttons, arrows) must follow this pattern:
449
-
450
- **For Buttons:**
451
- ```html
452
- <div data-hs-ba="mode-split">
453
- <div data-button-style="primary"> <!-- Found via querySelector -->
454
- <div data-site-clickable="element">
455
- <button type="button">Split</button> <!-- .children[0] -->
456
- </div>
457
- </div>
458
- </div>
459
- ```
460
-
461
- **For Links:**
462
- ```html
463
- <div data-hs-ba="left-arrow">
464
- <div data-site-clickable="element">
465
- <a href="#">Previous</a> <!-- .children[0] -->
466
- </div>
467
- </div>
468
- ```
469
-
470
- **Why:** JavaScript queries `[data-site-clickable="element"]` then gets `.children[0]` to find the actual interactive element. For mode buttons, it separately finds descendants with `[data-button-style]` for style updates. This allows wrapping for styling while maintaining consistent selection.
471
-
472
- ---
473
-
474
- ## **Common Issues**
475
-
476
- **Mode buttons not switching styles:**
477
- 1. Ensure `data-button-style` attribute exists on a descendant element
478
- 2. Verify button is first child of `[data-site-clickable="element"]`
479
- 3. Check console for warnings about missing elements
480
-
481
- **Arrow buttons not working:**
482
- 1. Ensure using `data-hs-ba="left-arrow"` and `data-hs-ba="right-arrow"` (not "left"/"right")
483
- 2. Verify `[data-site-clickable="element"]` wrapper exists
484
- 3. Check that first child is the actual link/button element
485
-
486
- **Slider not draggable:**
487
- 1. Verify `data-hs-ba="image-wrapper"` exists
488
- 2. Check that slider has `data-hs-ba="slider"` attribute
489
- 3. Ensure in split mode (slider hidden in before/after modes)
490
-
491
- **Pagination dots not generated:**
492
- 1. Ensure at least one template child exists in pagination container
493
- 2. Check that wrapper has multiple items (single item hides pagination)
494
- 3. Verify `data-hs-ba="pagination"` is on correct element
495
-
496
- **Console warnings appearing:**
497
- 1. Only required elements trigger warnings: wrapper, image-wrapper, image-before, image-after
498
- 2. Optional elements (slider, buttons, navigation) never trigger warnings
499
- 3. Fix missing elements or ignore if intentionally omitted
500
-
501
- **Barba.js transitions not working:**
502
- 1. Ensure `data-initialized` attribute is being removed on destroy
503
- 2. Check that destroy function is being called
504
- 3. Verify global event handlers not causing issues (they're safe to persist)
505
-
506
- ---
507
-
508
- ## **Notes**
509
-
510
- - Each wrapper is an independent instance
511
- - Slider position persists when navigating items across the carousel
512
- - Mode state persists when navigating items
513
- - Pagination automatically generated from items
514
- - First pagination child used as template (cloned for each item)
515
- - Supports any number of items (1+)
516
- - Single item hides navigation and pagination automatically
517
- - Using Global/Button and Global/Clickable components is recommended
518
- - Complete cleanup on destroy for Barba.js compatibility
519
- - WeakMap caching prevents memory leaks
520
- - Global drag handlers shared efficiently across instances and page transitions