@a11y-hud/svelte 1.0.0-rc.0 → 1.0.0

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 CHANGED
@@ -21,7 +21,7 @@ Use `useA11yHud` inside any Svelte 5 component. Pass a getter function so that r
21
21
  let scopeSection = $state<HTMLDivElement | null>(null);
22
22
 
23
23
  useA11yHud(() => ({
24
- theme: "dark",
24
+ theme: "auto",
25
25
  scope: scopeSection,
26
26
  autoScan: true,
27
27
  debounce: 300,
@@ -46,7 +46,7 @@ Use the `<A11yHud>` component when you prefer a declarative approach:
46
46
  let scopeSection = $state<HTMLDivElement | null>(null);
47
47
  </script>
48
48
 
49
- <A11yHud scope={scopeSection} theme="dark" />
49
+ <A11yHud scope={scopeSection} theme="auto" />
50
50
 
51
51
  <div bind:this={scopeSection}>
52
52
  <!-- your app content -->
@@ -59,16 +59,21 @@ Use the `<A11yHud>` component when you prefer a declarative approach:
59
59
 
60
60
  | Option | Type | Description |
61
61
  |---|---|---|
62
- | `theme` | `Theme` | `"light"`, `"dark"`, or `"high-contrast"` |
62
+ | `theme` | `Theme` | `"auto"` (default), `"default"`, `"light"`, `"high-contrast"`, `"github-dark"`, `"github-light"`, `"tokyo-night"`, `"solarized-dark"` |
63
63
  | `scope` | `Element \| null` | Restrict scan to a subtree |
64
64
  | `autoScan` | `boolean` | Enable/disable automatic scanning (default: `true`) |
65
65
  | `debounce` | `number` | Debounce delay in milliseconds |
66
+ | `runOnly` | `string[]` | Restrict axe to specific rule-set tags |
66
67
 
67
- Returns `{ runScan(): Promise<AxeResults>, setTheme(theme: Theme): void }`.
68
+ Returns `{ runScan, setTheme, setRunOnly, exportResults, ignores }`. `runScan()` resolves `Promise<AxeResults | null>` — `null` if called before the HUD has mounted.
68
69
 
69
70
  ### `<A11yHud>` component
70
71
 
71
- Accepts the same options as `UseA11yHudOptions` as props. Renders nothing into the Svelte tree — the `<a11y-hud>` Custom Element is mounted directly on `document.body`.
72
+ Accepts the same options as `UseA11yHudOptions` as props (`theme`, `scope`, `autoScan`, `debounce`, `runOnly`). Renders nothing into the Svelte tree — the `<a11y-hud>` Custom Element is mounted directly on `document.body`.
73
+
74
+ ### Server-side rendering
75
+
76
+ Importing `@a11y-hud/svelte` is safe on the server (SvelteKit); the HUD mounts in `onMount`, so nothing renders server-side.
72
77
 
73
78
  ## License
74
79
 
@@ -0,0 +1,16 @@
1
+ <script lang="ts">
2
+ import { useA11yHud } from "./hook.svelte.js";
3
+ import type { A11yHudProps, UseA11yHudOptions } from "./types.js";
4
+
5
+ const { theme, scope, autoScan, debounce, runOnly }: A11yHudProps = $props();
6
+
7
+ useA11yHud(
8
+ (): UseA11yHudOptions => ({
9
+ ...(theme !== undefined && { theme }),
10
+ ...(scope !== undefined && { scope }),
11
+ ...(autoScan !== undefined && { autoScan }),
12
+ ...(debounce !== undefined && { debounce }),
13
+ ...(runOnly !== undefined && { runOnly }),
14
+ })
15
+ );
16
+ </script>
@@ -0,0 +1,5 @@
1
+ import type { UseA11yHudOptions } from "./types.js";
2
+ declare const A11yHud: import("svelte").Component<UseA11yHudOptions, {}, "">;
3
+ type A11yHud = ReturnType<typeof A11yHud>;
4
+ export default A11yHud;
5
+ //# sourceMappingURL=A11yHud.svelte.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"A11yHud.svelte.d.ts","sourceRoot":"","sources":["../src/A11yHud.svelte.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAgB,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAqBlE,QAAA,MAAM,OAAO,uDAAwC,CAAC;AACtD,KAAK,OAAO,GAAG,UAAU,CAAC,OAAO,OAAO,CAAC,CAAC;AAC1C,eAAe,OAAO,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { UseA11yHudOptions, UseA11yHudReturn } from "./types.js";
2
+ export declare function useA11yHud(getOptions?: () => UseA11yHudOptions): UseA11yHudReturn;
3
+ //# sourceMappingURL=hook.svelte.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hook.svelte.d.ts","sourceRoot":"","sources":["../src/hook.svelte.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAEtE,wBAAgB,UAAU,CAAC,UAAU,GAAE,MAAM,iBAA8B,GAAG,gBAAgB,CAkH7F"}
@@ -0,0 +1,110 @@
1
+ import { mount } from "a11y-hud";
2
+ import { onDestroy, onMount } from "svelte";
3
+ export function useA11yHud(getOptions = () => ({})) {
4
+ let mounted = $state(false);
5
+ let instanceRef = null;
6
+ let elementRef = null;
7
+ onMount(() => {
8
+ const opts = getOptions();
9
+ const { theme, autoScan, debounce, runOnly } = opts;
10
+ instanceRef = mount({
11
+ ...(theme !== undefined && { theme }),
12
+ ...(autoScan !== undefined && { autoScan }),
13
+ ...(debounce !== undefined && { debounce }),
14
+ ...(runOnly !== undefined && { runOnly }),
15
+ });
16
+ elementRef = document.querySelector("a11y-hud");
17
+ mounted = true;
18
+ });
19
+ onDestroy(() => {
20
+ instanceRef?.unmount();
21
+ instanceRef = null;
22
+ elementRef = null;
23
+ });
24
+ // Render-settled: scope sync + rescan
25
+ $effect(() => {
26
+ if (!mounted)
27
+ return;
28
+ const { scope } = getOptions();
29
+ const el = elementRef;
30
+ if (!el)
31
+ return;
32
+ el.scopeElement = scope ?? undefined;
33
+ void instanceRef?.runScan();
34
+ });
35
+ // Theme sync — runs when mounted becomes true or theme changes.
36
+ $effect(() => {
37
+ if (mounted) {
38
+ const { theme } = getOptions();
39
+ if (theme !== undefined)
40
+ instanceRef?.setTheme(theme);
41
+ }
42
+ });
43
+ // autoScan sync
44
+ $effect(() => {
45
+ if (mounted) {
46
+ const el = elementRef;
47
+ if (el) {
48
+ const { autoScan } = getOptions();
49
+ if (autoScan === false) {
50
+ el.removeAttribute("auto-scan");
51
+ }
52
+ else {
53
+ el.setAttribute("auto-scan", "");
54
+ }
55
+ }
56
+ }
57
+ });
58
+ // debounce sync
59
+ $effect(() => {
60
+ if (mounted) {
61
+ const el = elementRef;
62
+ if (el) {
63
+ const { debounce } = getOptions();
64
+ if (debounce !== undefined)
65
+ el.setAttribute("debounce", String(debounce));
66
+ }
67
+ }
68
+ });
69
+ // runOnly sync
70
+ $effect(() => {
71
+ if (mounted) {
72
+ const { runOnly } = getOptions();
73
+ if (runOnly !== undefined)
74
+ instanceRef?.setRunOnly(runOnly);
75
+ }
76
+ });
77
+ function runScan() {
78
+ return instanceRef?.runScan() ?? Promise.resolve(null);
79
+ }
80
+ function setTheme(t) {
81
+ instanceRef?.setTheme(t);
82
+ }
83
+ function setRunOnly(tags) {
84
+ instanceRef?.setRunOnly(tags);
85
+ }
86
+ function exportResults() {
87
+ return instanceRef?.exportResults() ?? null;
88
+ }
89
+ const ignores = {
90
+ add(ruleId, selector) {
91
+ instanceRef?.ignores.add(ruleId, selector);
92
+ },
93
+ remove(ruleId, selector) {
94
+ instanceRef?.ignores.remove(ruleId, selector);
95
+ },
96
+ clear() {
97
+ instanceRef?.ignores.clear();
98
+ },
99
+ list() {
100
+ return instanceRef?.ignores.list() ?? [];
101
+ },
102
+ exportJson() {
103
+ return instanceRef?.ignores.exportJson() ?? "[]";
104
+ },
105
+ importJson(json) {
106
+ instanceRef?.ignores.importJson(json);
107
+ },
108
+ };
109
+ return { runScan, setTheme, setRunOnly, exportResults, ignores };
110
+ }
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { default as A11yHud } from './A11yHud.svelte';
2
- export { useA11yHud } from './hook.svelte.js';
3
- export type { A11yHudProps, UseA11yHudOptions, UseA11yHudReturn } from './types.js';
1
+ export { default as A11yHud } from "./A11yHud.svelte";
2
+ export { useA11yHud } from "./hook.svelte.js";
3
+ export type { A11yHudProps, UseA11yHudOptions, UseA11yHudReturn } from "./types.js";
4
4
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1,99 +1,2 @@
1
- import "svelte/internal/disclose-version";
2
- import * as e from "svelte/internal/client";
3
- import { mount as t } from "a11y-hud";
4
- import { onDestroy as n, onMount as r } from "svelte";
5
- //#region src/hook.svelte.ts
6
- function i(i = () => ({})) {
7
- let a = e.state(!1), o = null, s = null;
8
- r(() => {
9
- let { theme: n, autoScan: r, debounce: c, runOnly: l } = i();
10
- o = t({
11
- ...n !== void 0 && { theme: n },
12
- ...r !== void 0 && { autoScan: r },
13
- ...c !== void 0 && { debounce: c },
14
- ...l !== void 0 && { runOnly: l }
15
- }), s = document.querySelector("a11y-hud"), e.set(a, !0);
16
- }), n(() => {
17
- o?.unmount(), o = null, s = null;
18
- }), e.user_effect(() => {
19
- if (!e.get(a)) return;
20
- let { scope: t } = i(), n = s;
21
- n && (n.scopeElement = t ?? void 0, o?.runScan());
22
- }), e.user_effect(() => {
23
- if (e.get(a)) {
24
- let { theme: e } = i();
25
- e !== void 0 && o?.setTheme(e);
26
- }
27
- }), e.user_effect(() => {
28
- if (e.get(a)) {
29
- let e = s;
30
- if (e) {
31
- let { autoScan: t } = i();
32
- t === !1 ? e.removeAttribute("auto-scan") : e.setAttribute("auto-scan", "");
33
- }
34
- }
35
- }), e.user_effect(() => {
36
- if (e.get(a)) {
37
- let e = s;
38
- if (e) {
39
- let { debounce: t } = i();
40
- t !== void 0 && e.setAttribute("debounce", String(t));
41
- }
42
- }
43
- }), e.user_effect(() => {
44
- if (e.get(a)) {
45
- let { runOnly: e } = i();
46
- e !== void 0 && o?.setRunOnly(e);
47
- }
48
- });
49
- function c() {
50
- return o?.runScan() ?? Promise.resolve(null);
51
- }
52
- function l(e) {
53
- o?.setTheme(e);
54
- }
55
- function u(e) {
56
- o?.setRunOnly(e);
57
- }
58
- function d() {
59
- return o?.exportResults() ?? null;
60
- }
61
- return {
62
- runScan: c,
63
- setTheme: l,
64
- setRunOnly: u,
65
- exportResults: d,
66
- ignores: {
67
- add(e, t) {
68
- o?.ignores.add(e, t);
69
- },
70
- remove(e, t) {
71
- o?.ignores.remove(e, t);
72
- },
73
- clear() {
74
- o?.ignores.clear();
75
- },
76
- list() {
77
- return o?.ignores.list() ?? [];
78
- },
79
- exportJson() {
80
- return o?.ignores.exportJson() ?? "[]";
81
- },
82
- importJson(e) {
83
- o?.ignores.importJson(e);
84
- }
85
- }
86
- };
87
- }
88
- //#endregion
89
- //#region src/A11yHud.svelte
90
- function a(t, n) {
91
- e.push(n, !0), i(() => ({
92
- ...n.theme !== void 0 && { theme: n.theme },
93
- ...n.scope !== void 0 && { scope: n.scope },
94
- ...n.autoScan !== void 0 && { autoScan: n.autoScan },
95
- ...n.debounce !== void 0 && { debounce: n.debounce }
96
- })), e.pop();
97
- }
98
- //#endregion
99
- export { a as A11yHud, i as useA11yHud };
1
+ export { default as A11yHud } from "./A11yHud.svelte";
2
+ export { useA11yHud } from "./hook.svelte.js";
package/dist/types.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { AxeResults, IgnoreEntry, Theme } from 'a11y-hud';
1
+ import type { AxeResults, IgnoreEntry, Theme } from "a11y-hud";
2
2
  export interface UseA11yHudOptions {
3
3
  theme?: Theme;
4
4
  scope?: Element | null;
@@ -8,7 +8,7 @@ export interface UseA11yHudOptions {
8
8
  }
9
9
  export type A11yHudProps = UseA11yHudOptions;
10
10
  export interface UseA11yHudReturn {
11
- runScan(): Promise<AxeResults>;
11
+ runScan(): Promise<AxeResults | null>;
12
12
  setTheme(theme: Theme): void;
13
13
  setRunOnly(tags: string[]): void;
14
14
  exportResults(): string | null;
@@ -21,5 +21,4 @@ export interface UseA11yHudReturn {
21
21
  importJson(json: string): void;
22
22
  };
23
23
  }
24
- export declare function useA11yHud(getOptions?: () => UseA11yHudOptions): UseA11yHudReturn;
25
24
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,UAAU,CAA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Q,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;CACpB;AAED,MAAM,MAAM,YAAY,GAAG,iBAAiB,CAAC;AAE7C,MAAM,WAAW,gBAAgB;IAC/B,OAAO,IAAI,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC,CAAC;IACtC,QAAQ,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IAC7B,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;IACjC,aAAa,IAAI,MAAM,GAAG,IAAI,CAAC;IAC/B,OAAO,EAAE;QACP,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;QAC7C,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;QAChD,KAAK,IAAI,IAAI,CAAC;QACd,IAAI,IAAI,WAAW,EAAE,CAAC;QACtB,UAAU,IAAI,MAAM,CAAC;QACrB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;KAChC,CAAC;CACH"}
package/dist/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,14 +1,15 @@
1
1
  {
2
2
  "name": "@a11y-hud/svelte",
3
- "version": "1.0.0-rc.0",
3
+ "version": "1.0.0",
4
4
  "description": "Svelte adapter for a11y-hud — run axe-core accessibility audits in your Svelte app with no DevTools required.",
5
5
  "type": "module",
6
6
  "exports": {
7
7
  ".": {
8
8
  "types": "./dist/index.d.ts",
9
9
  "svelte": "./dist/index.js",
10
- "import": "./dist/index.js"
11
- }
10
+ "default": "./dist/index.js"
11
+ },
12
+ "./package.json": "./package.json"
12
13
  },
13
14
  "module": "./dist/index.js",
14
15
  "types": "./dist/index.d.ts",
@@ -18,22 +19,22 @@
18
19
  "README.md"
19
20
  ],
20
21
  "dependencies": {
21
- "a11y-hud": "1.0.0-rc.0"
22
+ "a11y-hud": "1.0.0"
22
23
  },
23
24
  "peerDependencies": {
24
25
  "svelte": ">=5"
25
26
  },
26
27
  "devDependencies": {
27
- "@playwright/test": "^1.49.1",
28
- "@sveltejs/vite-plugin-svelte": "^7.0.0",
29
- "@testing-library/svelte": "^5.3.1",
30
- "@vitest/coverage-v8": "^4.1.5",
28
+ "@playwright/test": "^1.63.0",
29
+ "@sveltejs/package": "^2.5.7",
30
+ "@sveltejs/vite-plugin-svelte": "^7.3.1",
31
+ "@testing-library/svelte": "^5.4.2",
32
+ "@vitest/coverage-v8": "^4.1.11",
31
33
  "jsdom": "^29.1.1",
32
- "svelte": "^5.55.5",
33
- "svelte-check": "^4.4.7",
34
- "vite": "^8.0.10",
35
- "vite-plugin-dts": "^5.0.0",
36
- "vitest": "^4.1.5"
34
+ "svelte": "^5.57.1",
35
+ "svelte-check": "^4.7.6",
36
+ "vite": "^8.3.1",
37
+ "vitest": "^4.1.11"
37
38
  },
38
39
  "engines": {
39
40
  "node": ">=22"
@@ -61,8 +62,8 @@
61
62
  "hud"
62
63
  ],
63
64
  "scripts": {
64
- "build": "vite build",
65
- "dev": "vite build --watch",
65
+ "build": "svelte-package -i src -o dist",
66
+ "dev": "svelte-package -i src -o dist --watch",
66
67
  "test": "vitest run",
67
68
  "test:watch": "vitest",
68
69
  "test:coverage": "vitest run --coverage",