@hortonstudio/main 1.1.14 → 1.1.16
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/animations/hero.js +59 -1
- package/package.json +1 -1
- package/styles.css +6 -1
package/animations/hero.js
CHANGED
@@ -244,14 +244,59 @@ export async function init() {
|
|
244
244
|
// Animation timeline
|
245
245
|
document.fonts.ready.then(() => {
|
246
246
|
|
247
|
+
// Helper function to flatten heading and extract span info
|
248
|
+
function flattenHeading(textElement) {
|
249
|
+
const spanMappings = new Map();
|
250
|
+
const spans = textElement.querySelectorAll('span');
|
251
|
+
|
252
|
+
// Extract span text and classes before flattening
|
253
|
+
spans.forEach(span => {
|
254
|
+
const text = span.textContent.trim();
|
255
|
+
const classes = Array.from(span.classList);
|
256
|
+
if (text && classes.length > 0) {
|
257
|
+
spanMappings.set(text, classes);
|
258
|
+
}
|
259
|
+
});
|
260
|
+
|
261
|
+
// Get the original tag name and attributes
|
262
|
+
const tagName = textElement.tagName;
|
263
|
+
const originalClasses = Array.from(textElement.classList);
|
264
|
+
const originalAttributes = {};
|
265
|
+
|
266
|
+
for (let attr of textElement.attributes) {
|
267
|
+
if (attr.name !== 'class') {
|
268
|
+
originalAttributes[attr.name] = attr.value;
|
269
|
+
}
|
270
|
+
}
|
271
|
+
|
272
|
+
// Create completely new element with just text content
|
273
|
+
const newElement = document.createElement(tagName);
|
274
|
+
newElement.textContent = textElement.textContent;
|
275
|
+
|
276
|
+
// Restore original attributes and classes
|
277
|
+
originalClasses.forEach(cls => newElement.classList.add(cls));
|
278
|
+
Object.entries(originalAttributes).forEach(([name, value]) => {
|
279
|
+
newElement.setAttribute(name, value);
|
280
|
+
});
|
281
|
+
|
282
|
+
// Replace the original element
|
283
|
+
textElement.parentNode.replaceChild(newElement, textElement);
|
284
|
+
|
285
|
+
return { newElement, spanMappings };
|
286
|
+
}
|
287
|
+
|
247
288
|
// Split text setup (after fonts are loaded)
|
248
289
|
headingSplits = [];
|
249
290
|
|
250
291
|
if (heading.length > 0) {
|
251
292
|
headingSplitElements.forEach((parent, index) => {
|
252
|
-
|
293
|
+
let textElement = heading[index];
|
253
294
|
const splitType = parent.getAttribute('data-hs-heroconfig') || 'word';
|
254
295
|
|
296
|
+
// Flatten the heading and get span mappings
|
297
|
+
const { newElement, spanMappings } = flattenHeading(textElement);
|
298
|
+
textElement = newElement; // Use the flattened element
|
299
|
+
|
255
300
|
let splitConfig = {};
|
256
301
|
let elementsClass = '';
|
257
302
|
|
@@ -282,6 +327,19 @@ export async function init() {
|
|
282
327
|
split.elementsClass = elementsClass;
|
283
328
|
headingSplits.push(split);
|
284
329
|
|
330
|
+
// Apply span classes to matching words if we have words available
|
331
|
+
if (split.words && spanMappings.size > 0) {
|
332
|
+
split.words.forEach(wordElement => {
|
333
|
+
const wordText = wordElement.textContent.trim();
|
334
|
+
if (spanMappings.has(wordText)) {
|
335
|
+
const classes = spanMappings.get(wordText);
|
336
|
+
classes.forEach(className => {
|
337
|
+
wordElement.classList.add(className);
|
338
|
+
});
|
339
|
+
}
|
340
|
+
});
|
341
|
+
}
|
342
|
+
|
285
343
|
gsap.set(split[elementsClass], { yPercent: config.headingSplit.yPercent });
|
286
344
|
gsap.set(textElement, { autoAlpha: 1 });
|
287
345
|
});
|
package/package.json
CHANGED
package/styles.css
CHANGED
@@ -13,7 +13,12 @@ body .transition {display: block}
|
|
13
13
|
|
14
14
|
/* safari line detection fix */
|
15
15
|
[data-hs-hero="heading"] {
|
16
|
-
|
16
|
+
text-rendering: optimizeSpeed;
|
17
|
+
font-variant-ligatures: none;
|
18
|
+
-webkit-font-feature-settings: "kern" 0;
|
19
|
+
font-feature-settings: "kern" 0;
|
20
|
+
-webkit-text-size-adjust: 100%;
|
21
|
+
text-size-adjust: 100%;
|
17
22
|
}
|
18
23
|
|
19
24
|
/* scroll cleanliness */
|