@shadow-garden/bapbong-a11y 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Le Phuoc Minh
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,33 @@
1
+ # @shadow-garden/bapbong-a11y
2
+
3
+ Accessibility for the canvas-rendered editor. A `<canvas>` is **opaque to screen
4
+ readers** — there is no text in the accessibility tree. `A11yMirror` keeps a
5
+ parallel, visually-hidden DOM subtree that mirrors the document so assistive
6
+ tech can read and navigate it.
7
+
8
+ The mirror is built from the document's **own schema `toDOM`** (via
9
+ ProseMirror's `DOMSerializer`), so it is faithfully semantic: paragraphs,
10
+ lists, tables, and real `<a href>` links — the same structure the model would
11
+ export.
12
+
13
+ ```ts
14
+ import { A11yMirror } from '@shadow-garden/bapbong-a11y';
15
+
16
+ const mirror = new A11yMirror(hostEl, { label: 'My document' });
17
+ mirror.update(doc); // call on each document change — debounced internally
18
+ // …
19
+ mirror.destroy();
20
+ ```
21
+
22
+ Wired automatically by `RenderCore` (so both `@shadow-garden/bapbong-editor` and
23
+ `@shadow-garden/bapbong-view` are accessible out of the box); you rarely
24
+ construct it by hand.
25
+
26
+ ## Notes
27
+
28
+ - **Visually hidden, AT-visible.** Uses the standard `sr-only` clip recipe — the
29
+ mirror never shows on screen but stays in the accessibility tree.
30
+ - **Debounced.** `update()` coalesces rapid edits (200 ms by default) so typing
31
+ stays snappy; the mirror is for reading/navigation, not live keystroke echo.
32
+ - **Light.** Inline-image `src` (base64 data-URLs) is stripped — assistive tech
33
+ reads the `alt`, and duplicating data-URLs would bloat the DOM.
package/dist/index.cjs ADDED
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // packages/a11y/src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ A11yMirror: () => A11yMirror
24
+ });
25
+ module.exports = __toCommonJS(index_exports);
26
+
27
+ // packages/a11y/src/lib/a11y-mirror.ts
28
+ var import_prosemirror_model = require("prosemirror-model");
29
+ var SR_ONLY = "position:absolute;width:1px;height:1px;margin:-1px;padding:0;border:0;overflow:hidden;clip:rect(0 0 0 0);clip-path:inset(50%);white-space:normal;";
30
+ var A11yMirror = class {
31
+ el;
32
+ debounceMs;
33
+ pending = null;
34
+ timer = null;
35
+ constructor(host, opts = {}) {
36
+ this.debounceMs = opts.debounceMs ?? 200;
37
+ const el = host.ownerDocument.createElement("div");
38
+ el.setAttribute("role", "document");
39
+ el.setAttribute("aria-label", opts.label ?? "Document content");
40
+ el.style.cssText = SR_ONLY;
41
+ host.appendChild(el);
42
+ this.el = el;
43
+ }
44
+ /** Re-render the mirror from `doc` (debounced). Safe to call on every change. */
45
+ update(doc) {
46
+ this.pending = doc;
47
+ if (this.debounceMs <= 0) {
48
+ this.flush();
49
+ return;
50
+ }
51
+ if (this.timer != null) return;
52
+ this.timer = setTimeout(() => {
53
+ this.timer = null;
54
+ this.flush();
55
+ }, this.debounceMs);
56
+ }
57
+ /** Render any pending document immediately (cancelling a scheduled flush). */
58
+ flush() {
59
+ if (this.timer != null) {
60
+ clearTimeout(this.timer);
61
+ this.timer = null;
62
+ }
63
+ const doc = this.pending;
64
+ if (!doc) return;
65
+ this.pending = null;
66
+ const serializer = import_prosemirror_model.DOMSerializer.fromSchema(doc.type.schema);
67
+ const fragment = serializer.serializeFragment(doc.content, {
68
+ document: this.el.ownerDocument
69
+ });
70
+ this.el.replaceChildren(fragment);
71
+ for (const img of Array.from(this.el.querySelectorAll("img"))) {
72
+ img.removeAttribute("src");
73
+ if (!img.getAttribute("alt")) img.setAttribute("alt", "image");
74
+ }
75
+ }
76
+ /** The mirror container (e.g. to wire `aria-describedby`). */
77
+ get element() {
78
+ return this.el;
79
+ }
80
+ destroy() {
81
+ if (this.timer != null) clearTimeout(this.timer);
82
+ this.timer = null;
83
+ this.pending = null;
84
+ this.el.remove();
85
+ }
86
+ };
87
+ // Annotate the CommonJS export names for ESM import in node:
88
+ 0 && (module.exports = {
89
+ A11yMirror
90
+ });
@@ -0,0 +1,2 @@
1
+ export * from './lib/a11y-mirror.js';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,63 @@
1
+ // packages/a11y/src/lib/a11y-mirror.ts
2
+ import { DOMSerializer } from "prosemirror-model";
3
+ var SR_ONLY = "position:absolute;width:1px;height:1px;margin:-1px;padding:0;border:0;overflow:hidden;clip:rect(0 0 0 0);clip-path:inset(50%);white-space:normal;";
4
+ var A11yMirror = class {
5
+ el;
6
+ debounceMs;
7
+ pending = null;
8
+ timer = null;
9
+ constructor(host, opts = {}) {
10
+ this.debounceMs = opts.debounceMs ?? 200;
11
+ const el = host.ownerDocument.createElement("div");
12
+ el.setAttribute("role", "document");
13
+ el.setAttribute("aria-label", opts.label ?? "Document content");
14
+ el.style.cssText = SR_ONLY;
15
+ host.appendChild(el);
16
+ this.el = el;
17
+ }
18
+ /** Re-render the mirror from `doc` (debounced). Safe to call on every change. */
19
+ update(doc) {
20
+ this.pending = doc;
21
+ if (this.debounceMs <= 0) {
22
+ this.flush();
23
+ return;
24
+ }
25
+ if (this.timer != null) return;
26
+ this.timer = setTimeout(() => {
27
+ this.timer = null;
28
+ this.flush();
29
+ }, this.debounceMs);
30
+ }
31
+ /** Render any pending document immediately (cancelling a scheduled flush). */
32
+ flush() {
33
+ if (this.timer != null) {
34
+ clearTimeout(this.timer);
35
+ this.timer = null;
36
+ }
37
+ const doc = this.pending;
38
+ if (!doc) return;
39
+ this.pending = null;
40
+ const serializer = DOMSerializer.fromSchema(doc.type.schema);
41
+ const fragment = serializer.serializeFragment(doc.content, {
42
+ document: this.el.ownerDocument
43
+ });
44
+ this.el.replaceChildren(fragment);
45
+ for (const img of Array.from(this.el.querySelectorAll("img"))) {
46
+ img.removeAttribute("src");
47
+ if (!img.getAttribute("alt")) img.setAttribute("alt", "image");
48
+ }
49
+ }
50
+ /** The mirror container (e.g. to wire `aria-describedby`). */
51
+ get element() {
52
+ return this.el;
53
+ }
54
+ destroy() {
55
+ if (this.timer != null) clearTimeout(this.timer);
56
+ this.timer = null;
57
+ this.pending = null;
58
+ this.el.remove();
59
+ }
60
+ };
61
+ export {
62
+ A11yMirror
63
+ };
@@ -0,0 +1,38 @@
1
+ import { type Node as ProseMirrorNode } from 'prosemirror-model';
2
+ export interface A11yMirrorOptions {
3
+ /** `aria-label` for the mirrored document region. */
4
+ label?: string;
5
+ /** Debounce (ms) before re-serializing after `update()` — coalesces rapid
6
+ * edits so typing stays snappy (the mirror is for reading/navigation, not
7
+ * live keystroke echo). Default 200. Set 0 to update synchronously. */
8
+ debounceMs?: number;
9
+ }
10
+ /**
11
+ * An **ARIA shadow-DOM mirror** of a bapbong document. The canvas the editor /
12
+ * viewer paints into is opaque to screen readers; this keeps a parallel,
13
+ * visually-hidden DOM subtree — built from the schema's own `toDOM` via
14
+ * {@link DOMSerializer} — so assistive tech can read and navigate the content
15
+ * (headings/paragraphs/lists/tables and real `<a href>` links).
16
+ *
17
+ * const mirror = new A11yMirror(hostEl);
18
+ * mirror.update(doc); // re-serialise on each doc change (debounced)
19
+ * mirror.destroy();
20
+ *
21
+ * It only needs the document `Node` (the schema rides on `doc.type.schema`), so
22
+ * it works for both the editable and read-only tiers.
23
+ */
24
+ export declare class A11yMirror {
25
+ private readonly el;
26
+ private readonly debounceMs;
27
+ private pending;
28
+ private timer;
29
+ constructor(host: HTMLElement, opts?: A11yMirrorOptions);
30
+ /** Re-render the mirror from `doc` (debounced). Safe to call on every change. */
31
+ update(doc: ProseMirrorNode): void;
32
+ /** Render any pending document immediately (cancelling a scheduled flush). */
33
+ flush(): void;
34
+ /** The mirror container (e.g. to wire `aria-describedby`). */
35
+ get element(): HTMLElement;
36
+ destroy(): void;
37
+ }
38
+ //# sourceMappingURL=a11y-mirror.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"a11y-mirror.d.ts","sourceRoot":"","sources":["../../src/lib/a11y-mirror.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,KAAK,IAAI,IAAI,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEhF,MAAM,WAAW,iBAAiB;IAChC,qDAAqD;IACrD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;4EAEwE;IACxE,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAOD;;;;;;;;;;;;;GAaG;AACH,qBAAa,UAAU;IACrB,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAc;IACjC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;IACpC,OAAO,CAAC,OAAO,CAAgC;IAC/C,OAAO,CAAC,KAAK,CAA8C;gBAE/C,IAAI,EAAE,WAAW,EAAE,IAAI,GAAE,iBAAsB;IAU3D,iFAAiF;IACjF,MAAM,CAAC,GAAG,EAAE,eAAe,GAAG,IAAI;IAalC,8EAA8E;IAC9E,KAAK,IAAI,IAAI;IAqBb,8DAA8D;IAC9D,IAAI,OAAO,IAAI,WAAW,CAEzB;IAED,OAAO,IAAI,IAAI;CAMhB"}
package/package.json ADDED
@@ -0,0 +1,59 @@
1
+ {
2
+ "name": "@shadow-garden/bapbong-a11y",
3
+ "version": "0.1.0",
4
+ "description": "bapbong — accessibility: a visually-hidden ARIA DOM mirror of the canvas document so screen readers can read it (the canvas itself is opaque to assistive tech).",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/shadowgarden-app/bapbong.git",
9
+ "directory": "packages/a11y"
10
+ },
11
+ "type": "module",
12
+ "main": "./dist/index.cjs",
13
+ "module": "./dist/index.js",
14
+ "types": "./dist/index.d.ts",
15
+ "exports": {
16
+ "./package.json": "./package.json",
17
+ ".": {
18
+ "@shadow-garden/source": "./src/index.ts",
19
+ "types": "./dist/index.d.ts",
20
+ "import": "./dist/index.js",
21
+ "require": "./dist/index.cjs",
22
+ "default": "./dist/index.js"
23
+ }
24
+ },
25
+ "files": [
26
+ "dist",
27
+ "!**/*.tsbuildinfo"
28
+ ],
29
+ "publishConfig": {
30
+ "access": "public"
31
+ },
32
+ "nx": {
33
+ "tags": [
34
+ "scope:a11y"
35
+ ],
36
+ "targets": {
37
+ "build": {
38
+ "executor": "@nx/esbuild:esbuild",
39
+ "outputs": [
40
+ "{options.outputPath}"
41
+ ],
42
+ "options": {
43
+ "outputPath": "packages/a11y/dist",
44
+ "main": "packages/a11y/src/index.ts",
45
+ "tsConfig": "packages/a11y/tsconfig.lib.json",
46
+ "format": [
47
+ "esm",
48
+ "cjs"
49
+ ],
50
+ "declarationRootDir": "packages/a11y/src",
51
+ "external": []
52
+ }
53
+ }
54
+ }
55
+ },
56
+ "dependencies": {
57
+ "prosemirror-model": "^1.25.7"
58
+ }
59
+ }