Comparing version 0.0.1-dev.2 to 0.0.1-dev.3
type AccentedProps = { | ||
outputToConsole?: boolean; | ||
outputToConsole: boolean; | ||
initialDelay: number; | ||
throttleDelay: number; | ||
}; | ||
export default function accented(props?: AccentedProps): void; | ||
export default function accented(props?: Partial<AccentedProps>): void; | ||
export {}; | ||
//# sourceMappingURL=accented.d.ts.map |
@@ -6,6 +6,13 @@ import axe from 'axe-core'; | ||
const defaultProps = { | ||
outputToConsole: true | ||
outputToConsole: true, | ||
initialDelay: 0, | ||
throttleDelay: 1000 | ||
}; | ||
export default function accented(props = {}) { | ||
const { outputToConsole } = { ...defaultProps, ...props }; | ||
const { outputToConsole, initialDelay, throttleDelay } = { ...defaultProps, ...props }; | ||
if (typeof window === 'undefined' || typeof document === 'undefined') { | ||
console.warn('Accented: this script can only run in the browser, and it’s likely running on the server now. Exiting.'); | ||
console.trace(); | ||
return; | ||
} | ||
const domUpdater = new DomUpdater(); | ||
@@ -22,3 +29,3 @@ const taskQueue = new TaskQueue(async () => { | ||
console.log('Axe run duration:', Math.round(axeMeasure.duration), 'ms'); | ||
}); | ||
}, { initialDelay, throttleDelay }); | ||
taskQueue.add(document); | ||
@@ -25,0 +32,0 @@ const mutationObserver = new MutationObserver(mutationList => { |
@@ -19,2 +19,3 @@ const attrName = 'data-accented'; | ||
const styleElement = document.createElement('style'); | ||
// FIX: looks like a bad idea, the stylesheet gets multiple <br> tags | ||
styleElement.innerText = ` | ||
@@ -21,0 +22,0 @@ [${attrName}]:not(:focus-visible) { |
type TaskCallback = () => void; | ||
export default class TaskQueue<T> { | ||
#private; | ||
items: Set<T>; | ||
idleCallbackId: number | null; | ||
asyncCallback: TaskCallback | null; | ||
constructor(asyncCallback: TaskCallback); | ||
constructor(asyncCallback: TaskCallback, { initialDelay, throttleDelay }?: { | ||
initialDelay?: number; | ||
throttleDelay?: number; | ||
}); | ||
add(item: T): void; | ||
@@ -9,0 +9,0 @@ } |
@@ -1,26 +0,37 @@ | ||
// TODO: add generic typing | ||
export default class TaskQueue { | ||
items = new Set(); | ||
idleCallbackId = null; | ||
asyncCallback = null; | ||
constructor(asyncCallback) { | ||
this.asyncCallback = asyncCallback; | ||
#items = new Set(); | ||
#runningOrScheduled = false; | ||
#initialDelay; | ||
#throttleDelay; | ||
// I'm not sure why the editor needs NodeJS.Timeout here. | ||
// tsconfig.json doesn't mention that the code needs to run in Node. | ||
// Maybe it's somehow related to the fact that we're using the Node test runner. | ||
#timeoutId = null; | ||
#asyncCallback = null; | ||
constructor(asyncCallback, { initialDelay, throttleDelay } = {}) { | ||
this.#asyncCallback = asyncCallback; | ||
this.#initialDelay = initialDelay ?? 0; | ||
this.#throttleDelay = throttleDelay ?? 1000; | ||
} | ||
// TODO: test all the asynchronicity | ||
#scheduleRun() { | ||
if (this.idleCallbackId !== null || this.items.size === 0) { | ||
if (this.#items.size === 0) { | ||
this.#runningOrScheduled = false; | ||
} | ||
if (this.#timeoutId !== null || this.#items.size === 0) { | ||
return; | ||
} | ||
this.idleCallbackId = requestIdleCallback(() => this.#run()); | ||
const delay = this.#runningOrScheduled ? this.#throttleDelay : this.#initialDelay; | ||
this.#runningOrScheduled = true; | ||
this.#timeoutId = setTimeout(() => this.#run(), delay); | ||
} | ||
async #run() { | ||
this.items.clear(); | ||
if (this.asyncCallback) { | ||
await this.asyncCallback(); | ||
this.#items.clear(); | ||
if (this.#asyncCallback) { | ||
await this.#asyncCallback(); | ||
} | ||
this.idleCallbackId = null; | ||
this.#timeoutId = null; | ||
this.#scheduleRun(); | ||
} | ||
add(item) { | ||
this.items.add(item); | ||
this.#items.add(item); | ||
this.#scheduleRun(); | ||
@@ -27,0 +38,0 @@ } |
@@ -1,3 +0,3 @@ | ||
import { AxeResults } from 'axe-core'; | ||
import type { AxeResults } from 'axe-core'; | ||
export default function issuesToElements(issues: typeof AxeResults.violations): Element[]; | ||
//# sourceMappingURL=issuesToElements.d.ts.map |
@@ -1,2 +0,1 @@ | ||
import { AxeResults } from 'axe-core'; | ||
export default function issuesToElements(issues) { | ||
@@ -3,0 +2,0 @@ const elements = new Set(); |
{ | ||
"name": "accented", | ||
"version": "0.0.1-dev.2", | ||
"version": "0.0.1-dev.3", | ||
"description": "Continuous accessibility testing and issue highlighting for web development", | ||
"type": "module", | ||
"main": "dist/accented.js", | ||
@@ -31,4 +32,4 @@ "files": [ | ||
"watch": "tsc --watch", | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"test": "node --test --import tsx ./**/*.test.ts" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
13372
22
154
2
Yes