accessibility-plugin-react 2.2.0 → 2.2.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/dist/index.js +26 -7
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +26 -7
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -302,7 +302,8 @@ function validValue(key, value, fallback, validate) {
|
|
|
302
302
|
|
|
303
303
|
// src/core/effects.ts
|
|
304
304
|
import { useEffect } from "react";
|
|
305
|
-
var EXCLUDED = "[data-arap-ui], [data-arap-ui] *, script, style, link, meta";
|
|
305
|
+
var EXCLUDED = "[data-arap-ui], [data-arap-ui] *, script, style, link, meta, noscript, template";
|
|
306
|
+
var MAX_HOST_ELEMENTS = 4e3;
|
|
306
307
|
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`;
|
|
307
308
|
var palette = {
|
|
308
309
|
"yellow-on-black": ["#ffff00", "#000000"],
|
|
@@ -334,9 +335,10 @@ function applyPage(values) {
|
|
|
334
335
|
else element.style.removeProperty(property);
|
|
335
336
|
});
|
|
336
337
|
}
|
|
337
|
-
const
|
|
338
|
+
const allElements = Array.from(
|
|
338
339
|
document.body.querySelectorAll("*")
|
|
339
340
|
).filter((el) => el instanceof HTMLElement && !el.matches(EXCLUDED));
|
|
341
|
+
const elements = allElements.length > MAX_HOST_ELEMENTS ? allElements.slice(0, MAX_HOST_ELEMENTS) : allElements;
|
|
340
342
|
const font = Number(values.fontSize ?? 100) / 100;
|
|
341
343
|
const line = Number(values.lineHeight ?? 100) / 100;
|
|
342
344
|
const measurements = font !== 1 || line !== 1 ? elements.map((el) => {
|
|
@@ -402,6 +404,10 @@ function applyPage(values) {
|
|
|
402
404
|
};
|
|
403
405
|
}
|
|
404
406
|
function readingAid(mask) {
|
|
407
|
+
const existing = document.body.querySelectorAll(
|
|
408
|
+
mask ? ".arap-reading-mask" : ".arap-reading-guide"
|
|
409
|
+
);
|
|
410
|
+
existing.forEach((node) => node.remove());
|
|
405
411
|
const el = document.createElement("div");
|
|
406
412
|
el.dataset.arapUi = "";
|
|
407
413
|
el.className = mask ? "arap-reading-mask" : "arap-reading-guide";
|
|
@@ -433,6 +439,8 @@ function useBuiltinEffects(values) {
|
|
|
433
439
|
))
|
|
434
440
|
return;
|
|
435
441
|
let undo = applyPage(values);
|
|
442
|
+
let mutationTimer = null;
|
|
443
|
+
let resizeTimer = null;
|
|
436
444
|
const observer = new MutationObserver((records) => {
|
|
437
445
|
if (!records.some(
|
|
438
446
|
(record) => record.target instanceof Element && !record.target.closest("[data-arap-ui]") && [...record.addedNodes, ...record.removedNodes].some(
|
|
@@ -440,16 +448,24 @@ function useBuiltinEffects(values) {
|
|
|
440
448
|
)
|
|
441
449
|
))
|
|
442
450
|
return;
|
|
443
|
-
|
|
444
|
-
|
|
451
|
+
if (mutationTimer) clearTimeout(mutationTimer);
|
|
452
|
+
mutationTimer = setTimeout(() => {
|
|
453
|
+
undo();
|
|
454
|
+
undo = applyPage(values);
|
|
455
|
+
}, 16);
|
|
445
456
|
});
|
|
446
457
|
observer.observe(document.body, { childList: true, subtree: true });
|
|
447
458
|
const resize = () => {
|
|
448
|
-
|
|
449
|
-
|
|
459
|
+
if (resizeTimer) clearTimeout(resizeTimer);
|
|
460
|
+
resizeTimer = setTimeout(() => {
|
|
461
|
+
undo();
|
|
462
|
+
undo = applyPage(values);
|
|
463
|
+
}, 50);
|
|
450
464
|
};
|
|
451
465
|
window.addEventListener("resize", resize);
|
|
452
466
|
return () => {
|
|
467
|
+
if (mutationTimer) clearTimeout(mutationTimer);
|
|
468
|
+
if (resizeTimer) clearTimeout(resizeTimer);
|
|
453
469
|
observer.disconnect();
|
|
454
470
|
window.removeEventListener("resize", resize);
|
|
455
471
|
undo();
|
|
@@ -468,7 +484,10 @@ function CustomEffect({
|
|
|
468
484
|
definition,
|
|
469
485
|
value
|
|
470
486
|
}) {
|
|
471
|
-
useEffect(() =>
|
|
487
|
+
useEffect(() => {
|
|
488
|
+
const cleanup = definition.apply?.(value);
|
|
489
|
+
return typeof cleanup === "function" ? cleanup : void 0;
|
|
490
|
+
}, [definition, value]);
|
|
472
491
|
return null;
|
|
473
492
|
}
|
|
474
493
|
|