accessibility-plugin-react 2.28.1 → 2.29.1
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/README.md +12 -0
- package/dist/index.d.mts +36 -2
- package/dist/index.d.ts +36 -2
- package/dist/index.js +338 -128
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +334 -128
- package/dist/index.mjs.map +1 -1
- package/docs/API.md +16 -0
- package/docs/LARGE_DOCUMENT_PROFILING.md +120 -0
- package/docs/PROJECT_STATUS.md +17 -15
- package/docs/ROADMAP.md +31 -30
- package/docs/SCOPED_EFFECTS.md +129 -0
- package/docs/TROUBLESHOOTING.md +21 -21
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -836,7 +836,7 @@ function applySmartContrast(options = {}) {
|
|
|
836
836
|
|
|
837
837
|
// src/core/effects.ts
|
|
838
838
|
var EXCLUDED = "[data-arap-ui], [data-arap-ui] *, script, style, link, meta, noscript, template";
|
|
839
|
-
var MAX_HOST_ELEMENTS =
|
|
839
|
+
var MAX_HOST_ELEMENTS = 8e3;
|
|
840
840
|
var cursor = `url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='40'%3E%3Cpath d='M4 2v32l9-9 7 13 6-3-7-12h14z' fill='black' stroke='white' stroke-width='2'/%3E%3C/svg%3E") 4 2, auto`;
|
|
841
841
|
function isForcedColorsActive() {
|
|
842
842
|
if (typeof window === "undefined" || !window.matchMedia) return false;
|
|
@@ -1416,24 +1416,35 @@ function isEligibleDecorativeImage(el) {
|
|
|
1416
1416
|
}
|
|
1417
1417
|
return false;
|
|
1418
1418
|
}
|
|
1419
|
-
function
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
return;
|
|
1429
|
-
if (previous) element.style.setProperty(property, previous, priority);
|
|
1430
|
-
else element.style.removeProperty(property);
|
|
1431
|
-
});
|
|
1419
|
+
function resolveEffectScope(scope) {
|
|
1420
|
+
if (typeof document === "undefined") return null;
|
|
1421
|
+
if (!scope) return document.body ?? null;
|
|
1422
|
+
if (typeof scope === "string") {
|
|
1423
|
+
try {
|
|
1424
|
+
return document.querySelector(scope) ?? document.body ?? null;
|
|
1425
|
+
} catch {
|
|
1426
|
+
return document.body ?? null;
|
|
1427
|
+
}
|
|
1432
1428
|
}
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1429
|
+
if (typeof scope === "object") {
|
|
1430
|
+
if ("nodeType" in scope && scope.nodeType === 1) {
|
|
1431
|
+
return scope;
|
|
1432
|
+
}
|
|
1433
|
+
if ("current" in scope) {
|
|
1434
|
+
return scope.current ?? document.body ?? null;
|
|
1435
|
+
}
|
|
1436
|
+
}
|
|
1437
|
+
return document.body ?? null;
|
|
1438
|
+
}
|
|
1439
|
+
function applyToElements(elements, values, undo, styledElements, isFinePointer, set) {
|
|
1440
|
+
const targetElements = [];
|
|
1441
|
+
for (const el of elements) {
|
|
1442
|
+
if (!styledElements.has(el)) {
|
|
1443
|
+
styledElements.add(el);
|
|
1444
|
+
targetElements.push(el);
|
|
1445
|
+
}
|
|
1446
|
+
}
|
|
1447
|
+
if (targetElements.length === 0) return;
|
|
1437
1448
|
const fontScaleValue = typeof values.fontScale === "number" && values.fontScale !== 1 ? values.fontScale : typeof values.textScale === "number" && values.textScale !== 1 ? values.textScale : void 0;
|
|
1438
1449
|
const fontSizeScale = typeof values.fontSize === "number" && values.fontSize !== 100 ? values.fontSize / 100 : void 0;
|
|
1439
1450
|
const font = fontScaleValue ?? fontSizeScale ?? 1;
|
|
@@ -1442,7 +1453,7 @@ function applyPage(values) {
|
|
|
1442
1453
|
const fontActive = font !== 1;
|
|
1443
1454
|
const lineActive = lineRatio !== 1;
|
|
1444
1455
|
if (fontActive || lineActive) {
|
|
1445
|
-
const measurements =
|
|
1456
|
+
const measurements = targetElements.filter(
|
|
1446
1457
|
(el) => !isProtectedFromTextScale(el) || !isProtectedFromTextSpacing(el)
|
|
1447
1458
|
).map((el) => {
|
|
1448
1459
|
const computed = getComputedStyle(el);
|
|
@@ -1478,26 +1489,10 @@ function applyPage(values) {
|
|
|
1478
1489
|
}
|
|
1479
1490
|
}
|
|
1480
1491
|
}
|
|
1481
|
-
const filter = composeFilter(values);
|
|
1482
|
-
for (const el of Array.from(document.body.children)) {
|
|
1483
|
-
if (!(el instanceof HTMLElement) || el.matches(EXCLUDED) || !filter)
|
|
1484
|
-
continue;
|
|
1485
|
-
const computed = getComputedStyle(el);
|
|
1486
|
-
if (computed.backgroundColor === "rgba(0, 0, 0, 0)" || computed.backgroundColor === "transparent") {
|
|
1487
|
-
const bodyColor = getComputedStyle(document.body).backgroundColor;
|
|
1488
|
-
set(
|
|
1489
|
-
el,
|
|
1490
|
-
"background-color",
|
|
1491
|
-
bodyColor && bodyColor !== "rgba(0, 0, 0, 0)" && bodyColor !== "transparent" ? bodyColor : "#ffffff"
|
|
1492
|
-
);
|
|
1493
|
-
}
|
|
1494
|
-
const base = computed.filter;
|
|
1495
|
-
set(el, "filter", `${base && base !== "none" ? base + " " : ""}${filter}`);
|
|
1496
|
-
}
|
|
1497
1492
|
const letterSpacingVal = typeof values.letterSpacing === "number" && values.letterSpacing > 0 ? values.letterSpacing : 0;
|
|
1498
1493
|
const letterSpacingEmVal = typeof values.letterSpacingEm === "number" && values.letterSpacingEm > 0 ? values.letterSpacingEm : null;
|
|
1499
1494
|
if (letterSpacingVal > 0 || letterSpacingEmVal !== null) {
|
|
1500
|
-
for (const el of
|
|
1495
|
+
for (const el of targetElements) {
|
|
1501
1496
|
if (isProtectedFromTextSpacing(el)) {
|
|
1502
1497
|
if (el.matches(
|
|
1503
1498
|
"table, [role='table'], td, th, pre, code, kbd, samp, var, button, input, select, textarea, [data-arap-ui]"
|
|
@@ -1534,7 +1529,7 @@ function applyPage(values) {
|
|
|
1534
1529
|
const wordSpacingVal = typeof values.wordSpacing === "number" && values.wordSpacing > 0 ? values.wordSpacing : 0;
|
|
1535
1530
|
const wordSpacingEmVal = typeof values.wordSpacingEm === "number" && values.wordSpacingEm > 0 ? values.wordSpacingEm : null;
|
|
1536
1531
|
if (wordSpacingVal > 0 || wordSpacingEmVal !== null) {
|
|
1537
|
-
for (const el of
|
|
1532
|
+
for (const el of targetElements) {
|
|
1538
1533
|
if (isProtectedFromTextSpacing(el)) {
|
|
1539
1534
|
if (el.matches(
|
|
1540
1535
|
"table, [role='table'], td, th, pre, code, kbd, samp, var, button, input, select, textarea, [data-arap-ui]"
|
|
@@ -1553,7 +1548,7 @@ function applyPage(values) {
|
|
|
1553
1548
|
const paragraphSpacingVal = typeof values.paragraphSpacing === "number" && values.paragraphSpacing > 0 ? values.paragraphSpacing : 0;
|
|
1554
1549
|
const paragraphSpacingEmVal = typeof values.paragraphSpacingEm === "number" && values.paragraphSpacingEm > 0 ? values.paragraphSpacingEm : null;
|
|
1555
1550
|
if (paragraphSpacingVal > 0 || paragraphSpacingEmVal !== null) {
|
|
1556
|
-
for (const el of
|
|
1551
|
+
for (const el of targetElements) {
|
|
1557
1552
|
if (isProtectedFromTextSpacing(el)) continue;
|
|
1558
1553
|
if (el.matches("p, [role='paragraph']")) {
|
|
1559
1554
|
const computed = getComputedStyle(el);
|
|
@@ -1565,7 +1560,7 @@ function applyPage(values) {
|
|
|
1565
1560
|
}
|
|
1566
1561
|
const textAlignVal = values.textAlign ? String(values.textAlign) : "default";
|
|
1567
1562
|
if (textAlignVal !== "default" && textAlignVal !== "original") {
|
|
1568
|
-
for (const el of
|
|
1563
|
+
for (const el of targetElements) {
|
|
1569
1564
|
if (isProtectedFromTextAlign(el)) continue;
|
|
1570
1565
|
if (el.matches(TEXT_ALIGN_BLOCK_SELECTOR)) {
|
|
1571
1566
|
set(el, "text-align", textAlignVal);
|
|
@@ -1575,7 +1570,7 @@ function applyPage(values) {
|
|
|
1575
1570
|
const fontFamilyVal = values.fontFamily ? String(values.fontFamily) : "default";
|
|
1576
1571
|
if (fontFamilyVal !== "default" && fontFamilyVal !== "original") {
|
|
1577
1572
|
const targetStack = fontFamilyVal === "dyslexia-option" || fontFamilyVal === "dyslexia" ? DYSLEXIA_FONT_STACK : LEGIBLE_FONT_STACK;
|
|
1578
|
-
for (const el of
|
|
1573
|
+
for (const el of targetElements) {
|
|
1579
1574
|
if (isProtectedFromFontFamily(el)) {
|
|
1580
1575
|
if (el.matches("pre, code, kbd, samp, var")) {
|
|
1581
1576
|
const previous = el.style.getPropertyValue("font-family");
|
|
@@ -1594,19 +1589,16 @@ function applyPage(values) {
|
|
|
1594
1589
|
}
|
|
1595
1590
|
const isInvert = Boolean(values.invertColors) || values.contrast === "invert" || values.contrastMode === "invert";
|
|
1596
1591
|
if (isInvert && !isForcedColorsActive()) {
|
|
1597
|
-
const
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
).filter((el) => !el.closest("[data-arap-ui]"));
|
|
1602
|
-
for (const mediaEl of mediaElements) {
|
|
1603
|
-
set(mediaEl, "filter", "invert(1)");
|
|
1592
|
+
for (const el of targetElements) {
|
|
1593
|
+
if (el.matches("img, video, canvas, picture, [role='img']") && !el.closest("[data-arap-ui]")) {
|
|
1594
|
+
set(el, "filter", "invert(1)");
|
|
1595
|
+
}
|
|
1604
1596
|
}
|
|
1605
1597
|
}
|
|
1606
1598
|
const activeContrastKey = values.contrastMode && values.contrastMode !== "off" && values.contrastMode !== "original" ? String(values.contrastMode) : values.contrast !== void 0 && values.contrast !== 0 && values.contrast !== "0" && values.contrast !== "off" && values.contrast !== "original" ? String(values.contrast) : null;
|
|
1607
1599
|
const activePalette = activeContrastKey && !isForcedColorsActive() ? CONTRAST_PALETTES[activeContrastKey] : null;
|
|
1608
1600
|
if (activePalette) {
|
|
1609
|
-
for (const el of
|
|
1601
|
+
for (const el of targetElements) {
|
|
1610
1602
|
if (isProtectedFromContrast(el)) continue;
|
|
1611
1603
|
set(el, "color", activePalette.text);
|
|
1612
1604
|
if (el.matches("a[href]") && activePalette.link) {
|
|
@@ -1624,6 +1616,116 @@ function applyPage(values) {
|
|
|
1624
1616
|
}
|
|
1625
1617
|
}
|
|
1626
1618
|
}
|
|
1619
|
+
for (const el of targetElements) {
|
|
1620
|
+
if (values.bigCursor && isFinePointer) set(el, "cursor", cursor);
|
|
1621
|
+
if (values.hideImages) {
|
|
1622
|
+
if (isEligibleDecorativeImage(el)) {
|
|
1623
|
+
set(el, "visibility", "hidden");
|
|
1624
|
+
}
|
|
1625
|
+
if (!isFunctionalOrMeaningfulImage(el)) {
|
|
1626
|
+
const inlineBg = el.style.backgroundImage;
|
|
1627
|
+
if (inlineBg && inlineBg !== "none") {
|
|
1628
|
+
set(el, "background-image", "none");
|
|
1629
|
+
} else {
|
|
1630
|
+
try {
|
|
1631
|
+
const computedBg = getComputedStyle(el).backgroundImage;
|
|
1632
|
+
if (computedBg && computedBg !== "none") {
|
|
1633
|
+
set(el, "background-image", "none");
|
|
1634
|
+
}
|
|
1635
|
+
} catch {
|
|
1636
|
+
}
|
|
1637
|
+
}
|
|
1638
|
+
}
|
|
1639
|
+
}
|
|
1640
|
+
if (values.hideVideos && el.matches(
|
|
1641
|
+
'video, iframe[src*="youtube.com/embed/"], iframe[src*="youtube-nocookie.com/embed/"], iframe[src*="player.vimeo.com/video/"]'
|
|
1642
|
+
))
|
|
1643
|
+
set(el, "visibility", "hidden");
|
|
1644
|
+
const colors = palette[String(values.contrast)];
|
|
1645
|
+
if (colors && !activePalette && !isForcedColorsActive()) {
|
|
1646
|
+
set(el, "color", colors[0]);
|
|
1647
|
+
set(el, "background-color", colors[1]);
|
|
1648
|
+
}
|
|
1649
|
+
if (values.linkHighlight && el.matches("a[href]") && !el.closest("[data-arap-ui]")) {
|
|
1650
|
+
const isDisabled = el.getAttribute("aria-disabled") === "true" || el.hasAttribute("disabled") || el.classList.contains("disabled");
|
|
1651
|
+
if (!isDisabled) {
|
|
1652
|
+
if (isForcedColorsActive()) {
|
|
1653
|
+
set(el, "color", "LinkText");
|
|
1654
|
+
set(el, "text-decoration", "underline");
|
|
1655
|
+
set(el, "text-decoration-thickness", "2px");
|
|
1656
|
+
set(el, "text-underline-offset", "3px");
|
|
1657
|
+
} else {
|
|
1658
|
+
const colors2 = palette[String(values.linkHighlight)] ?? [
|
|
1659
|
+
"#111827",
|
|
1660
|
+
"#fef08a"
|
|
1661
|
+
];
|
|
1662
|
+
set(el, "color", colors2[0]);
|
|
1663
|
+
set(el, "background-color", colors2[1]);
|
|
1664
|
+
set(el, "text-decoration", "underline");
|
|
1665
|
+
set(el, "text-decoration-thickness", "2px");
|
|
1666
|
+
set(el, "text-underline-offset", "3px");
|
|
1667
|
+
}
|
|
1668
|
+
}
|
|
1669
|
+
}
|
|
1670
|
+
}
|
|
1671
|
+
}
|
|
1672
|
+
function applyPageSession(values, optionsOrScope) {
|
|
1673
|
+
let effectScope = void 0;
|
|
1674
|
+
let nonce = void 0;
|
|
1675
|
+
if (optionsOrScope && typeof optionsOrScope === "object") {
|
|
1676
|
+
if ("nodeType" in optionsOrScope) {
|
|
1677
|
+
effectScope = optionsOrScope;
|
|
1678
|
+
} else if ("current" in optionsOrScope && !("effectScope" in optionsOrScope)) {
|
|
1679
|
+
effectScope = optionsOrScope;
|
|
1680
|
+
} else {
|
|
1681
|
+
const opts = optionsOrScope;
|
|
1682
|
+
effectScope = opts.effectScope;
|
|
1683
|
+
nonce = opts.nonce;
|
|
1684
|
+
}
|
|
1685
|
+
} else if (typeof optionsOrScope === "string") {
|
|
1686
|
+
effectScope = optionsOrScope;
|
|
1687
|
+
}
|
|
1688
|
+
const targetRoot = resolveEffectScope(effectScope);
|
|
1689
|
+
const undo = [];
|
|
1690
|
+
const styledElements = /* @__PURE__ */ new WeakSet();
|
|
1691
|
+
let totalStyled = 0;
|
|
1692
|
+
const isFinePointer = hasFinePointer();
|
|
1693
|
+
function set(element, property, value) {
|
|
1694
|
+
const previous = element.style.getPropertyValue(property);
|
|
1695
|
+
const priority = element.style.getPropertyPriority(property);
|
|
1696
|
+
element.style.setProperty(property, value, "important");
|
|
1697
|
+
const applied = element.style.getPropertyValue(property);
|
|
1698
|
+
undo.push(() => {
|
|
1699
|
+
if (element.style.getPropertyValue(property) !== applied || element.style.getPropertyPriority(property) !== "important")
|
|
1700
|
+
return;
|
|
1701
|
+
if (previous) element.style.setProperty(property, previous, priority);
|
|
1702
|
+
else element.style.removeProperty(property);
|
|
1703
|
+
});
|
|
1704
|
+
}
|
|
1705
|
+
const filter = composeFilter(values);
|
|
1706
|
+
function applyContainerFilter(el) {
|
|
1707
|
+
if (el.matches(EXCLUDED) || !filter) return;
|
|
1708
|
+
const computed = getComputedStyle(el);
|
|
1709
|
+
if (computed.backgroundColor === "rgba(0, 0, 0, 0)" || computed.backgroundColor === "transparent") {
|
|
1710
|
+
const bodyColor = typeof document !== "undefined" && document.body ? getComputedStyle(document.body).backgroundColor : "#ffffff";
|
|
1711
|
+
set(
|
|
1712
|
+
el,
|
|
1713
|
+
"background-color",
|
|
1714
|
+
bodyColor && bodyColor !== "rgba(0, 0, 0, 0)" && bodyColor !== "transparent" ? bodyColor : "#ffffff"
|
|
1715
|
+
);
|
|
1716
|
+
}
|
|
1717
|
+
const base = computed.filter;
|
|
1718
|
+
set(el, "filter", `${base && base !== "none" ? base + " " : ""}${filter}`);
|
|
1719
|
+
}
|
|
1720
|
+
if (filter && targetRoot) {
|
|
1721
|
+
if (targetRoot === (typeof document !== "undefined" ? document.body : null)) {
|
|
1722
|
+
for (const el of Array.from(document.body.children)) {
|
|
1723
|
+
if (el instanceof HTMLElement) applyContainerFilter(el);
|
|
1724
|
+
}
|
|
1725
|
+
} else {
|
|
1726
|
+
applyContainerFilter(targetRoot);
|
|
1727
|
+
}
|
|
1728
|
+
}
|
|
1627
1729
|
const smartContrastVal = values.smartContrast;
|
|
1628
1730
|
if ((smartContrastVal === true || smartContrastVal === "aa" || smartContrastVal === "aaa") && !isForcedColorsActive()) {
|
|
1629
1731
|
const targetLevel = smartContrastVal === "aaa" ? "aaa" : "aa";
|
|
@@ -1639,6 +1741,10 @@ function applyPage(values) {
|
|
|
1639
1741
|
styleEl = document.createElement("style");
|
|
1640
1742
|
styleEl.id = FOCUS_STYLE_ID;
|
|
1641
1743
|
styleEl.dataset.arapUi = "";
|
|
1744
|
+
if (nonce) {
|
|
1745
|
+
styleEl.nonce = nonce;
|
|
1746
|
+
styleEl.setAttribute("nonce", nonce);
|
|
1747
|
+
}
|
|
1642
1748
|
styleEl.textContent = `
|
|
1643
1749
|
*:not([data-arap-ui]):not([data-arap-ui] *):focus-visible {
|
|
1644
1750
|
outline: 3px solid #2563eb !important;
|
|
@@ -1673,6 +1779,10 @@ function applyPage(values) {
|
|
|
1673
1779
|
styleEl = document.createElement("style");
|
|
1674
1780
|
styleEl.id = MOTION_STYLE_ID;
|
|
1675
1781
|
styleEl.dataset.arapUi = "";
|
|
1782
|
+
if (nonce) {
|
|
1783
|
+
styleEl.nonce = nonce;
|
|
1784
|
+
styleEl.setAttribute("nonce", nonce);
|
|
1785
|
+
}
|
|
1676
1786
|
styleEl.textContent = `
|
|
1677
1787
|
*:not([data-arap-ui]):not([data-arap-ui] *),
|
|
1678
1788
|
*:not([data-arap-ui]):not([data-arap-ui] *)::before,
|
|
@@ -1729,66 +1839,84 @@ function applyPage(values) {
|
|
|
1729
1839
|
}
|
|
1730
1840
|
});
|
|
1731
1841
|
}
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
if (
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1842
|
+
if (values.bigCursor && isFinePointer && typeof document !== "undefined" && targetRoot) {
|
|
1843
|
+
set(targetRoot, "cursor", cursor);
|
|
1844
|
+
}
|
|
1845
|
+
if (typeof document !== "undefined" && targetRoot) {
|
|
1846
|
+
const allElements = [];
|
|
1847
|
+
if (targetRoot !== document.body && !targetRoot.matches(EXCLUDED)) {
|
|
1848
|
+
allElements.push(targetRoot);
|
|
1849
|
+
}
|
|
1850
|
+
const descendants = Array.from(
|
|
1851
|
+
targetRoot.querySelectorAll("*")
|
|
1852
|
+
).filter((el) => el instanceof HTMLElement && !el.matches(EXCLUDED));
|
|
1853
|
+
allElements.push(...descendants);
|
|
1854
|
+
for (const el of descendants) {
|
|
1855
|
+
if (allElements.length >= MAX_HOST_ELEMENTS) break;
|
|
1856
|
+
if (el.shadowRoot && el.shadowRoot.mode === "open") {
|
|
1857
|
+
const shadowDescendants = Array.from(
|
|
1858
|
+
el.shadowRoot.querySelectorAll("*")
|
|
1859
|
+
).filter((s) => s instanceof HTMLElement && !s.matches(EXCLUDED));
|
|
1860
|
+
allElements.push(...shadowDescendants);
|
|
1861
|
+
}
|
|
1862
|
+
}
|
|
1863
|
+
const elements = allElements.length > MAX_HOST_ELEMENTS ? allElements.slice(0, MAX_HOST_ELEMENTS) : allElements;
|
|
1864
|
+
totalStyled = elements.length;
|
|
1865
|
+
applyToElements(elements, values, undo, styledElements, isFinePointer, set);
|
|
1866
|
+
}
|
|
1867
|
+
function applyIncremental(addedNodes) {
|
|
1868
|
+
if (typeof document === "undefined" || !targetRoot) return;
|
|
1869
|
+
const candidateElements = [];
|
|
1870
|
+
for (const root of addedNodes) {
|
|
1871
|
+
if (root.matches(EXCLUDED)) continue;
|
|
1872
|
+
if (targetRoot !== document.body && !targetRoot.contains(root) && root !== targetRoot) {
|
|
1873
|
+
continue;
|
|
1741
1874
|
}
|
|
1742
|
-
if (
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1875
|
+
if (filter && (targetRoot === document.body ? root.parentElement === document.body : root === targetRoot || root.parentElement === targetRoot)) {
|
|
1876
|
+
applyContainerFilter(root);
|
|
1877
|
+
}
|
|
1878
|
+
candidateElements.push(root);
|
|
1879
|
+
const descendants = Array.from(
|
|
1880
|
+
root.querySelectorAll("*")
|
|
1881
|
+
).filter((el) => el instanceof HTMLElement && !el.matches(EXCLUDED));
|
|
1882
|
+
candidateElements.push(...descendants);
|
|
1883
|
+
for (const el of descendants) {
|
|
1884
|
+
if (el.shadowRoot && el.shadowRoot.mode === "open") {
|
|
1885
|
+
const shadowDescendants = Array.from(
|
|
1886
|
+
el.shadowRoot.querySelectorAll("*")
|
|
1887
|
+
).filter((s) => s instanceof HTMLElement && !s.matches(EXCLUDED));
|
|
1888
|
+
candidateElements.push(...shadowDescendants);
|
|
1754
1889
|
}
|
|
1755
1890
|
}
|
|
1756
1891
|
}
|
|
1757
|
-
if (
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
set(el, "color", "LinkText");
|
|
1771
|
-
set(el, "text-decoration", "underline");
|
|
1772
|
-
set(el, "text-decoration-thickness", "2px");
|
|
1773
|
-
set(el, "text-underline-offset", "3px");
|
|
1774
|
-
} else {
|
|
1775
|
-
const colors2 = palette[String(values.linkHighlight)] ?? [
|
|
1776
|
-
"#111827",
|
|
1777
|
-
"#fef08a"
|
|
1778
|
-
];
|
|
1779
|
-
set(el, "color", colors2[0]);
|
|
1780
|
-
set(el, "background-color", colors2[1]);
|
|
1781
|
-
set(el, "text-decoration", "underline");
|
|
1782
|
-
set(el, "text-decoration-thickness", "2px");
|
|
1783
|
-
set(el, "text-underline-offset", "3px");
|
|
1784
|
-
}
|
|
1785
|
-
}
|
|
1892
|
+
if (candidateElements.length > 0) {
|
|
1893
|
+
const remainingQuota = MAX_HOST_ELEMENTS - totalStyled;
|
|
1894
|
+
if (remainingQuota <= 0) return;
|
|
1895
|
+
const elementsToStyle = candidateElements.length > remainingQuota ? candidateElements.slice(0, remainingQuota) : candidateElements;
|
|
1896
|
+
totalStyled += elementsToStyle.length;
|
|
1897
|
+
applyToElements(
|
|
1898
|
+
elementsToStyle,
|
|
1899
|
+
values,
|
|
1900
|
+
undo,
|
|
1901
|
+
styledElements,
|
|
1902
|
+
isFinePointer,
|
|
1903
|
+
set
|
|
1904
|
+
);
|
|
1786
1905
|
}
|
|
1787
1906
|
}
|
|
1788
|
-
return
|
|
1789
|
-
|
|
1907
|
+
return {
|
|
1908
|
+
undo: () => {
|
|
1909
|
+
for (const restore of undo.reverse()) restore();
|
|
1910
|
+
},
|
|
1911
|
+
applyIncremental,
|
|
1912
|
+
styledCount: () => totalStyled,
|
|
1913
|
+
targetRoot
|
|
1790
1914
|
};
|
|
1791
1915
|
}
|
|
1916
|
+
function applyPage(values, optionsOrScope) {
|
|
1917
|
+
const session = applyPageSession(values, optionsOrScope);
|
|
1918
|
+
return session.undo;
|
|
1919
|
+
}
|
|
1792
1920
|
function nudgeReadingAid(feature, delta) {
|
|
1793
1921
|
if (typeof document !== "undefined") {
|
|
1794
1922
|
try {
|
|
@@ -1918,45 +2046,113 @@ function readingAid(mask, height = 100, onDisable) {
|
|
|
1918
2046
|
el.remove();
|
|
1919
2047
|
};
|
|
1920
2048
|
}
|
|
1921
|
-
function useBuiltinEffects(values, onDisable) {
|
|
2049
|
+
function useBuiltinEffects(values, onDisable, optionsOrScope) {
|
|
1922
2050
|
useEffect(() => {
|
|
1923
2051
|
if (!Object.entries(values).some(
|
|
1924
2052
|
([key, value]) => key in builtins && value !== builtins[key].defaultValue
|
|
1925
2053
|
))
|
|
1926
2054
|
return;
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
2055
|
+
const targetRoot = resolveEffectScope(
|
|
2056
|
+
optionsOrScope && typeof optionsOrScope === "object" && "effectScope" in optionsOrScope ? optionsOrScope.effectScope : optionsOrScope
|
|
2057
|
+
);
|
|
2058
|
+
let activeSession = applyPageSession(values, optionsOrScope);
|
|
2059
|
+
let refreshTimer = null;
|
|
2060
|
+
let incrementalTimer = null;
|
|
2061
|
+
let pendingAddedNodes = [];
|
|
2062
|
+
const flushIncremental = () => {
|
|
2063
|
+
if (pendingAddedNodes.length === 0) return;
|
|
2064
|
+
const nodes = pendingAddedNodes;
|
|
2065
|
+
pendingAddedNodes = [];
|
|
2066
|
+
activeSession.applyIncremental(nodes);
|
|
2067
|
+
};
|
|
2068
|
+
const scheduleFullRefresh = (delay = 25) => {
|
|
2069
|
+
if (refreshTimer) clearTimeout(refreshTimer);
|
|
2070
|
+
refreshTimer = setTimeout(() => {
|
|
2071
|
+
activeSession.undo();
|
|
2072
|
+
activeSession = applyPageSession(values, optionsOrScope);
|
|
2073
|
+
}, delay);
|
|
2074
|
+
};
|
|
1930
2075
|
const observer = new MutationObserver((records) => {
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
)
|
|
1935
|
-
|
|
2076
|
+
let hasRootAttributeChange = false;
|
|
2077
|
+
const added = [];
|
|
2078
|
+
for (const record of records) {
|
|
2079
|
+
if (record.type === "attributes") {
|
|
2080
|
+
if (record.target === document.documentElement || record.target === document.body || record.target === targetRoot) {
|
|
2081
|
+
hasRootAttributeChange = true;
|
|
2082
|
+
}
|
|
2083
|
+
} else if (record.type === "childList") {
|
|
2084
|
+
if (record.target instanceof Element && record.target.closest("[data-arap-ui]")) {
|
|
2085
|
+
continue;
|
|
2086
|
+
}
|
|
2087
|
+
for (const node of record.addedNodes) {
|
|
2088
|
+
if (node instanceof HTMLElement && !node.matches("[data-arap-ui]")) {
|
|
2089
|
+
added.push(node);
|
|
2090
|
+
}
|
|
2091
|
+
}
|
|
2092
|
+
}
|
|
2093
|
+
}
|
|
2094
|
+
if (hasRootAttributeChange) {
|
|
2095
|
+
scheduleFullRefresh(25);
|
|
1936
2096
|
return;
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
2097
|
+
}
|
|
2098
|
+
if (added.length > 0) {
|
|
2099
|
+
pendingAddedNodes.push(...added);
|
|
2100
|
+
if (incrementalTimer) clearTimeout(incrementalTimer);
|
|
2101
|
+
incrementalTimer = setTimeout(flushIncremental, 16);
|
|
2102
|
+
}
|
|
1942
2103
|
});
|
|
1943
|
-
|
|
2104
|
+
const observerOptions = {
|
|
2105
|
+
childList: true,
|
|
2106
|
+
subtree: true,
|
|
2107
|
+
attributes: true,
|
|
2108
|
+
attributeFilter: ["class", "data-theme", "dir", "lang"]
|
|
2109
|
+
};
|
|
2110
|
+
if (targetRoot) {
|
|
2111
|
+
observer.observe(targetRoot, observerOptions);
|
|
2112
|
+
}
|
|
2113
|
+
if (typeof document !== "undefined" && document.body && targetRoot !== document.body) {
|
|
2114
|
+
observer.observe(document.body, {
|
|
2115
|
+
attributes: true,
|
|
2116
|
+
attributeFilter: ["class", "data-theme", "dir", "lang"]
|
|
2117
|
+
});
|
|
2118
|
+
}
|
|
2119
|
+
if (typeof document !== "undefined" && document.documentElement) {
|
|
2120
|
+
observer.observe(document.documentElement, {
|
|
2121
|
+
attributes: true,
|
|
2122
|
+
attributeFilter: ["class", "data-theme", "dir", "lang"]
|
|
2123
|
+
});
|
|
2124
|
+
}
|
|
2125
|
+
const fontCleanups = [];
|
|
2126
|
+
if (typeof document !== "undefined" && "fonts" in document && document.fonts) {
|
|
2127
|
+
const fonts = document.fonts;
|
|
2128
|
+
const handleFontLoad = () => {
|
|
2129
|
+
scheduleFullRefresh(50);
|
|
2130
|
+
};
|
|
2131
|
+
if (fonts.status === "loading") {
|
|
2132
|
+
fonts.ready.then(handleFontLoad).catch(() => {
|
|
2133
|
+
});
|
|
2134
|
+
}
|
|
2135
|
+
try {
|
|
2136
|
+
fonts.addEventListener("loadingdone", handleFontLoad);
|
|
2137
|
+
fontCleanups.push(() => {
|
|
2138
|
+
fonts.removeEventListener("loadingdone", handleFontLoad);
|
|
2139
|
+
});
|
|
2140
|
+
} catch {
|
|
2141
|
+
}
|
|
2142
|
+
}
|
|
1944
2143
|
const resize = () => {
|
|
1945
|
-
|
|
1946
|
-
resizeTimer = setTimeout(() => {
|
|
1947
|
-
undo();
|
|
1948
|
-
undo = applyPage(values);
|
|
1949
|
-
}, 50);
|
|
2144
|
+
scheduleFullRefresh(50);
|
|
1950
2145
|
};
|
|
1951
2146
|
window.addEventListener("resize", resize);
|
|
1952
2147
|
return () => {
|
|
1953
|
-
if (
|
|
1954
|
-
if (
|
|
2148
|
+
if (refreshTimer) clearTimeout(refreshTimer);
|
|
2149
|
+
if (incrementalTimer) clearTimeout(incrementalTimer);
|
|
1955
2150
|
observer.disconnect();
|
|
2151
|
+
for (const cleanup of fontCleanups) cleanup();
|
|
1956
2152
|
window.removeEventListener("resize", resize);
|
|
1957
|
-
undo();
|
|
2153
|
+
activeSession.undo();
|
|
1958
2154
|
};
|
|
1959
|
-
}, [values]);
|
|
2155
|
+
}, [values, optionsOrScope]);
|
|
1960
2156
|
useEffect(() => {
|
|
1961
2157
|
if (!values.readingMask) return;
|
|
1962
2158
|
const height = typeof values.readingMaskHeight === "number" ? values.readingMaskHeight : typeof values.readingMask === "number" ? values.readingMask : 100;
|
|
@@ -2809,7 +3005,9 @@ function AccessibilityPlugin({
|
|
|
2809
3005
|
statementUrl,
|
|
2810
3006
|
largeControls,
|
|
2811
3007
|
diagnostics,
|
|
2812
|
-
onFeatureEvent
|
|
3008
|
+
onFeatureEvent,
|
|
3009
|
+
effectScope,
|
|
3010
|
+
nonce
|
|
2813
3011
|
}) {
|
|
2814
3012
|
const [isOpen, setIsOpen] = useState(false);
|
|
2815
3013
|
const [store] = useState(
|
|
@@ -3023,7 +3221,7 @@ function AccessibilityPlugin({
|
|
|
3023
3221
|
return () => document.removeEventListener("arap:disable-feature", handler);
|
|
3024
3222
|
}, [handleDisable]);
|
|
3025
3223
|
const effectiveLocale = locale || (typeof document !== "undefined" ? document.documentElement.lang : void 0) || void 0;
|
|
3026
|
-
useBuiltinEffects(active, handleDisable);
|
|
3224
|
+
useBuiltinEffects(active, handleDisable, { effectScope, nonce });
|
|
3027
3225
|
const value = useMemo(
|
|
3028
3226
|
() => ({
|
|
3029
3227
|
state: { isOpen, features },
|
|
@@ -3042,7 +3240,9 @@ function AccessibilityPlugin({
|
|
|
3042
3240
|
unregisterReset,
|
|
3043
3241
|
locale: effectiveLocale,
|
|
3044
3242
|
statementUrl,
|
|
3045
|
-
largeControls
|
|
3243
|
+
largeControls,
|
|
3244
|
+
effectScope,
|
|
3245
|
+
nonce
|
|
3046
3246
|
}),
|
|
3047
3247
|
[
|
|
3048
3248
|
isOpen,
|
|
@@ -3061,7 +3261,9 @@ function AccessibilityPlugin({
|
|
|
3061
3261
|
unregisterReset,
|
|
3062
3262
|
effectiveLocale,
|
|
3063
3263
|
statementUrl,
|
|
3064
|
-
largeControls
|
|
3264
|
+
largeControls,
|
|
3265
|
+
effectScope,
|
|
3266
|
+
nonce
|
|
3065
3267
|
]
|
|
3066
3268
|
);
|
|
3067
3269
|
return /* @__PURE__ */ jsxs(AccessibilityContext.Provider, { value, children: [
|
|
@@ -13606,6 +13808,7 @@ export {
|
|
|
13606
13808
|
LetterSpacingController,
|
|
13607
13809
|
LineHeightController,
|
|
13608
13810
|
LinkHighlightController,
|
|
13811
|
+
MAX_HOST_ELEMENTS,
|
|
13609
13812
|
MAX_NODES_PER_TRANSLATION_BATCH,
|
|
13610
13813
|
MAX_READING_MASK_HEIGHT,
|
|
13611
13814
|
MAX_TEXT_LENGTH_PER_NODE,
|
|
@@ -13654,6 +13857,8 @@ export {
|
|
|
13654
13857
|
VoiceNavigationController,
|
|
13655
13858
|
WordSpacingController,
|
|
13656
13859
|
applyCustomPresetToStore,
|
|
13860
|
+
applyPage,
|
|
13861
|
+
applyPageSession,
|
|
13657
13862
|
applyProfileToStore,
|
|
13658
13863
|
applySmartContrast,
|
|
13659
13864
|
applyTranslations,
|
|
@@ -13726,6 +13931,7 @@ export {
|
|
|
13726
13931
|
recordProfileOverride,
|
|
13727
13932
|
registerLocale,
|
|
13728
13933
|
resolveActiveShortcut,
|
|
13934
|
+
resolveEffectScope,
|
|
13729
13935
|
resolveEffectiveBackdrop,
|
|
13730
13936
|
resolveEffectivePreferences,
|
|
13731
13937
|
resolveLocaleStrings,
|