fetta 1.4.1 → 1.4.2
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.
|
@@ -19,6 +19,33 @@ var __spreadValues = (a, b) => {
|
|
|
19
19
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
20
|
|
|
21
21
|
// src/core/splitText.ts
|
|
22
|
+
var ARIA_LABEL_ALLOWED_TAGS = /* @__PURE__ */ new Set([
|
|
23
|
+
"h1",
|
|
24
|
+
"h2",
|
|
25
|
+
"h3",
|
|
26
|
+
"h4",
|
|
27
|
+
"h5",
|
|
28
|
+
"h6",
|
|
29
|
+
"a",
|
|
30
|
+
"button",
|
|
31
|
+
"img",
|
|
32
|
+
"input",
|
|
33
|
+
"select",
|
|
34
|
+
"textarea",
|
|
35
|
+
"table",
|
|
36
|
+
"figure",
|
|
37
|
+
"form",
|
|
38
|
+
"fieldset",
|
|
39
|
+
"dialog",
|
|
40
|
+
"details",
|
|
41
|
+
"section",
|
|
42
|
+
"article",
|
|
43
|
+
"nav",
|
|
44
|
+
"aside",
|
|
45
|
+
"header",
|
|
46
|
+
"footer",
|
|
47
|
+
"main"
|
|
48
|
+
]);
|
|
22
49
|
var BREAK_CHARS = /* @__PURE__ */ new Set([
|
|
23
50
|
"\u2014",
|
|
24
51
|
// em-dash
|
|
@@ -908,11 +935,13 @@ function splitText(element, {
|
|
|
908
935
|
let currentChars = [];
|
|
909
936
|
let currentWords = [];
|
|
910
937
|
let currentLines = [];
|
|
938
|
+
let originalAriaLabel = null;
|
|
911
939
|
if (splitChars) {
|
|
912
940
|
element.style.fontVariantLigatures = "none";
|
|
913
941
|
}
|
|
914
942
|
const trackAncestors = hasInlineDescendants(element);
|
|
915
943
|
const measuredWords = collectTextStructure(element, trackAncestors);
|
|
944
|
+
const useAriaLabel = !trackAncestors && ARIA_LABEL_ALLOWED_TAGS.has(element.tagName.toLowerCase());
|
|
916
945
|
const { chars, words, lines } = performSplit(
|
|
917
946
|
element,
|
|
918
947
|
measuredWords,
|
|
@@ -922,7 +951,7 @@ function splitText(element, {
|
|
|
922
951
|
splitChars,
|
|
923
952
|
splitWords,
|
|
924
953
|
splitLines,
|
|
925
|
-
{ propIndex, mask, ariaHidden:
|
|
954
|
+
{ propIndex, mask, ariaHidden: useAriaLabel, disableKerning, initialStyles, initialClasses }
|
|
926
955
|
);
|
|
927
956
|
currentChars = chars;
|
|
928
957
|
currentWords = words;
|
|
@@ -937,8 +966,21 @@ function splitText(element, {
|
|
|
937
966
|
}
|
|
938
967
|
element.appendChild(visualWrapper);
|
|
939
968
|
element.appendChild(createScreenReaderCopy(originalHTML));
|
|
969
|
+
} else if (useAriaLabel) {
|
|
970
|
+
originalAriaLabel = element.getAttribute("aria-label");
|
|
971
|
+
if (originalAriaLabel === null) {
|
|
972
|
+
element.setAttribute("aria-label", text);
|
|
973
|
+
}
|
|
940
974
|
} else {
|
|
941
|
-
|
|
975
|
+
injectSrOnlyStyles();
|
|
976
|
+
const visualWrapper = document.createElement("span");
|
|
977
|
+
visualWrapper.setAttribute("aria-hidden", "true");
|
|
978
|
+
visualWrapper.dataset.fettaVisual = "true";
|
|
979
|
+
while (element.firstChild) {
|
|
980
|
+
visualWrapper.appendChild(element.firstChild);
|
|
981
|
+
}
|
|
982
|
+
element.appendChild(visualWrapper);
|
|
983
|
+
element.appendChild(createScreenReaderCopy(originalHTML));
|
|
942
984
|
}
|
|
943
985
|
const dispose = () => {
|
|
944
986
|
if (!isActive) return;
|
|
@@ -955,8 +997,12 @@ function splitText(element, {
|
|
|
955
997
|
const revert = () => {
|
|
956
998
|
if (!isActive) return;
|
|
957
999
|
element.innerHTML = originalHTML;
|
|
958
|
-
if (
|
|
959
|
-
|
|
1000
|
+
if (useAriaLabel) {
|
|
1001
|
+
if (originalAriaLabel !== null) {
|
|
1002
|
+
element.setAttribute("aria-label", originalAriaLabel);
|
|
1003
|
+
} else {
|
|
1004
|
+
element.removeAttribute("aria-label");
|
|
1005
|
+
}
|
|
960
1006
|
}
|
|
961
1007
|
if (splitChars) {
|
|
962
1008
|
element.style.fontVariantLigatures = "none";
|
|
@@ -997,12 +1043,12 @@ function splitText(element, {
|
|
|
997
1043
|
splitChars,
|
|
998
1044
|
splitWords,
|
|
999
1045
|
splitLines,
|
|
1000
|
-
{ propIndex, mask, ariaHidden:
|
|
1046
|
+
{ propIndex, mask, ariaHidden: useAriaLabel, disableKerning, initialStyles, initialClasses }
|
|
1001
1047
|
);
|
|
1002
1048
|
currentChars = result.chars;
|
|
1003
1049
|
currentWords = result.words;
|
|
1004
1050
|
currentLines = result.lines;
|
|
1005
|
-
if (trackAncestors) {
|
|
1051
|
+
if (trackAncestors || !useAriaLabel) {
|
|
1006
1052
|
const visualWrapper = document.createElement("span");
|
|
1007
1053
|
visualWrapper.setAttribute("aria-hidden", "true");
|
|
1008
1054
|
visualWrapper.dataset.fettaVisual = "true";
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { splitText } from './chunk-
|
|
1
|
+
export { splitText } from './chunk-24TCJGUM.js';
|
package/dist/react.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { splitText, __spreadProps, __spreadValues, normalizeToPromise } from './chunk-
|
|
1
|
+
import { splitText, __spreadProps, __spreadValues, normalizeToPromise } from './chunk-24TCJGUM.js';
|
|
2
2
|
import { forwardRef, useRef, useCallback, useState, useLayoutEffect, useEffect, isValidElement, cloneElement } from 'react';
|
|
3
3
|
import { jsx } from 'react/jsx-runtime';
|
|
4
4
|
|