@lantun/core 0.0.0-stage → 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.
Files changed (129) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +14 -2
  3. package/dist/a11y/a11y.constants.d.ts +48 -0
  4. package/dist/a11y/a11y.constants.js +50 -0
  5. package/dist/a11y/a11y.d.ts +4 -0
  6. package/dist/a11y/a11y.js +133 -0
  7. package/dist/a11y/a11y.lib.d.ts +6 -0
  8. package/dist/a11y/a11y.lib.js +55 -0
  9. package/dist/a11y/a11y.styles.d.ts +1 -0
  10. package/dist/a11y/a11y.styles.js +63 -0
  11. package/dist/a11y/a11y.types.d.ts +27 -0
  12. package/dist/a11y/a11y.types.js +1 -0
  13. package/dist/autoscroll/autoscroll.constants.d.ts +7 -0
  14. package/dist/autoscroll/autoscroll.constants.js +10 -0
  15. package/dist/autoscroll/autoscroll.d.ts +2 -0
  16. package/dist/autoscroll/autoscroll.js +58 -0
  17. package/dist/autoscroll/autoscroll.types.d.ts +7 -0
  18. package/dist/autoscroll/autoscroll.types.js +1 -0
  19. package/dist/extract/extract.constants.d.ts +11 -0
  20. package/dist/extract/extract.constants.js +48 -0
  21. package/dist/extract/extract.d.ts +5 -0
  22. package/dist/extract/extract.js +68 -0
  23. package/dist/extract/extract.lib.d.ts +9 -0
  24. package/dist/extract/extract.lib.js +74 -0
  25. package/dist/highlight/highlight.constants.d.ts +7 -0
  26. package/dist/highlight/highlight.constants.js +9 -0
  27. package/dist/highlight/highlight.d.ts +3 -0
  28. package/dist/highlight/highlight.js +123 -0
  29. package/dist/highlight/highlight.lib.d.ts +5 -0
  30. package/dist/highlight/highlight.lib.js +35 -0
  31. package/dist/highlight/highlight.types.d.ts +34 -0
  32. package/dist/highlight/highlight.types.js +1 -0
  33. package/dist/index.d.ts +13 -0
  34. package/dist/index.js +76 -0
  35. package/dist/lib/color.d.ts +12 -0
  36. package/dist/lib/color.js +90 -0
  37. package/dist/lib/dom.d.ts +2 -0
  38. package/dist/lib/dom.js +19 -0
  39. package/dist/lib/emitter.d.ts +8 -0
  40. package/dist/lib/emitter.js +29 -0
  41. package/dist/lib/log.d.ts +4 -0
  42. package/dist/lib/log.js +28 -0
  43. package/dist/lib/storage.d.ts +3 -0
  44. package/dist/lib/storage.js +30 -0
  45. package/dist/lib/store.d.ts +7 -0
  46. package/dist/lib/store.js +28 -0
  47. package/dist/options/options.constants.d.ts +6 -0
  48. package/dist/options/options.constants.js +5 -0
  49. package/dist/options/options.d.ts +3 -0
  50. package/dist/options/options.js +45 -0
  51. package/dist/options/options.types.d.ts +29 -0
  52. package/dist/options/options.types.js +1 -0
  53. package/dist/player/player.constants.d.ts +9 -0
  54. package/dist/player/player.constants.js +14 -0
  55. package/dist/player/player.d.ts +2 -0
  56. package/dist/player/player.js +275 -0
  57. package/dist/player/player.lib.d.ts +3 -0
  58. package/dist/player/player.lib.js +11 -0
  59. package/dist/player/player.types.d.ts +51 -0
  60. package/dist/player/player.types.js +1 -0
  61. package/dist/reader/reader.constants.d.ts +7 -0
  62. package/dist/reader/reader.constants.js +10 -0
  63. package/dist/reader/reader.d.ts +3 -0
  64. package/dist/reader/reader.js +361 -0
  65. package/dist/reader/reader.lib.d.ts +10 -0
  66. package/dist/reader/reader.lib.js +36 -0
  67. package/dist/reader/reader.storage.d.ts +8 -0
  68. package/dist/reader/reader.storage.js +79 -0
  69. package/dist/reader/reader.types.d.ts +83 -0
  70. package/dist/reader/reader.types.js +1 -0
  71. package/dist/segment/segment.constants.d.ts +5 -0
  72. package/dist/segment/segment.constants.js +15 -0
  73. package/dist/segment/segment.d.ts +3 -0
  74. package/dist/segment/segment.js +106 -0
  75. package/dist/segment/segment.types.d.ts +14 -0
  76. package/dist/segment/segment.types.js +1 -0
  77. package/dist/speech/mixed-driver.d.ts +5 -0
  78. package/dist/speech/mixed-driver.js +65 -0
  79. package/dist/speech/speech.constants.d.ts +7 -0
  80. package/dist/speech/speech.constants.js +12 -0
  81. package/dist/speech/speech.types.d.ts +55 -0
  82. package/dist/speech/speech.types.js +2 -0
  83. package/dist/speech/web-speech.d.ts +4 -0
  84. package/dist/speech/web-speech.js +111 -0
  85. package/dist/speech/word-timing.d.ts +2 -0
  86. package/dist/speech/word-timing.js +125 -0
  87. package/dist/textmap/textmap.d.ts +10 -0
  88. package/dist/textmap/textmap.js +148 -0
  89. package/dist/ui/a11y-panel.d.ts +14 -0
  90. package/dist/ui/a11y-panel.js +60 -0
  91. package/dist/ui/app.d.ts +14 -0
  92. package/dist/ui/app.js +172 -0
  93. package/dist/ui/controls.d.ts +25 -0
  94. package/dist/ui/controls.js +21 -0
  95. package/dist/ui/dock.d.ts +22 -0
  96. package/dist/ui/dock.js +71 -0
  97. package/dist/ui/icons.d.ts +40 -0
  98. package/dist/ui/icons.js +101 -0
  99. package/dist/ui/mount.d.ts +7 -0
  100. package/dist/ui/mount.js +27 -0
  101. package/dist/ui/play-here.d.ts +9 -0
  102. package/dist/ui/play-here.js +112 -0
  103. package/dist/ui/reading-aids.d.ts +2 -0
  104. package/dist/ui/reading-aids.js +25 -0
  105. package/dist/ui/speed-popover.d.ts +12 -0
  106. package/dist/ui/speed-popover.js +17 -0
  107. package/dist/ui/ui.constants.d.ts +53 -0
  108. package/dist/ui/ui.constants.js +67 -0
  109. package/dist/ui/ui.hooks.d.ts +12 -0
  110. package/dist/ui/ui.hooks.js +224 -0
  111. package/dist/ui/ui.i18n.d.ts +105 -0
  112. package/dist/ui/ui.i18n.js +218 -0
  113. package/dist/ui/ui.lib.d.ts +27 -0
  114. package/dist/ui/ui.lib.js +117 -0
  115. package/dist/ui/ui.storage.d.ts +3 -0
  116. package/dist/ui/ui.storage.js +20 -0
  117. package/dist/ui/ui.styles.d.ts +1 -0
  118. package/dist/ui/ui.styles.js +278 -0
  119. package/dist/ui/ui.types.d.ts +39 -0
  120. package/dist/ui/ui.types.js +1 -0
  121. package/dist/ui/voice-popover.d.ts +13 -0
  122. package/dist/ui/voice-popover.js +44 -0
  123. package/dist/voices/voices.constants.d.ts +6 -0
  124. package/dist/voices/voices.constants.js +16 -0
  125. package/dist/voices/voices.lib.d.ts +9 -0
  126. package/dist/voices/voices.lib.js +112 -0
  127. package/dist/voices/voices.types.d.ts +6 -0
  128. package/dist/voices/voices.types.js +1 -0
  129. package/package.json +50 -3
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 rizkianakbar
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 CHANGED
@@ -1,3 +1,15 @@
1
- # Temporary Holding Version
1
+ # @lantun/core
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Read any article aloud, with each sentence and word highlighted, plus reading aids for low vision, dyslexia and ADHD.
4
+
5
+ ```sh
6
+ npm install @lantun/core
7
+ ```
8
+
9
+ ```ts
10
+ import { init } from "@lantun/core";
11
+
12
+ init({ contentSelector: "article", color: "#7c3aed" });
13
+ ```
14
+
15
+ Options, API and screenshots: [github.com/rizkianakbar/lantun](https://github.com/rizkianakbar/lantun#readme)
@@ -0,0 +1,48 @@
1
+ import type { AxSettings, ProfileId } from "./a11y.types";
2
+ export declare const AX_STYLE_ID = "lantun-ax";
3
+ export declare const AX_STORAGE_KEY = "ax";
4
+ export declare const MORPH_CLASS = "ax-morph";
5
+ export declare const AX_DEFAULTS: Readonly<AxSettings>;
6
+ export declare const TEXT_SIZES: readonly [100, 115, 130, 150];
7
+ export declare const STEPS: readonly unknown[];
8
+ export declare const FONTS: readonly unknown[];
9
+ export declare const CONTRASTS: readonly unknown[];
10
+ export declare const PROFILES: {
11
+ lowVision: {
12
+ text: 2;
13
+ contrast: "high";
14
+ cursor: true;
15
+ links: true;
16
+ };
17
+ dyslexia: {
18
+ font: "dyslexic";
19
+ line: 1;
20
+ spacing: 1;
21
+ guide: true;
22
+ };
23
+ adhd: {
24
+ mask: true;
25
+ still: true;
26
+ };
27
+ seizure: {
28
+ still: true;
29
+ desaturate: true;
30
+ };
31
+ elderly: {
32
+ text: 2;
33
+ font: "readable";
34
+ cursor: true;
35
+ };
36
+ };
37
+ export declare const PROFILE_IDS: ProfileId[];
38
+ export declare const SWITCHES: {
39
+ readonly desaturate: "ax-desaturate";
40
+ readonly links: "ax-links";
41
+ readonly cursor: "ax-cursor";
42
+ readonly guide: "ax-guide";
43
+ readonly mask: "ax-mask";
44
+ readonly still: "ax-still";
45
+ readonly noImages: "ax-no-images";
46
+ };
47
+ export declare const SWITCH_KEYS: (keyof typeof SWITCHES)[];
48
+ export declare const ALL_AX_CLASSES: readonly string[];
@@ -0,0 +1,50 @@
1
+ export const AX_STYLE_ID = "lantun-ax";
2
+ export const AX_STORAGE_KEY = "ax";
3
+ // Marks our own view transitions, which styles.ts times and makes click-through.
4
+ export const MORPH_CLASS = "ax-morph";
5
+ export const AX_DEFAULTS = {
6
+ text: 0,
7
+ line: 0,
8
+ spacing: 0,
9
+ font: "default",
10
+ contrast: "default",
11
+ desaturate: false,
12
+ links: false,
13
+ cursor: false,
14
+ guide: false,
15
+ mask: false,
16
+ still: false,
17
+ noImages: false,
18
+ };
19
+ export const TEXT_SIZES = [100, 115, 130, 150];
20
+ export const STEPS = [0, 1, 2, 3];
21
+ export const FONTS = ["default", "readable", "dyslexic"];
22
+ export const CONTRASTS = ["default", "dark", "light", "high", "invert"];
23
+ export const PROFILES = {
24
+ lowVision: { text: 2, contrast: "high", cursor: true, links: true },
25
+ dyslexia: { font: "dyslexic", line: 1, spacing: 1, guide: true },
26
+ adhd: { mask: true, still: true },
27
+ seizure: { still: true, desaturate: true },
28
+ elderly: { text: 2, font: "readable", cursor: true },
29
+ };
30
+ export const PROFILE_IDS = Object.keys(PROFILES);
31
+ // On/off settings and the class each one puts on <html>.
32
+ export const SWITCHES = {
33
+ desaturate: "ax-desaturate",
34
+ links: "ax-links",
35
+ cursor: "ax-cursor",
36
+ guide: "ax-guide",
37
+ mask: "ax-mask",
38
+ still: "ax-still",
39
+ noImages: "ax-no-images",
40
+ };
41
+ export const SWITCH_KEYS = Object.keys(SWITCHES);
42
+ export const ALL_AX_CLASSES = [
43
+ ...TEXT_SIZES.slice(1).map((size) => `ax-text-${size}`),
44
+ ...[1, 2, 3].map((n) => `ax-line-${n}`),
45
+ ...[1, 2, 3].map((n) => `ax-spacing-${n}`),
46
+ "ax-font-readable",
47
+ "ax-font-dyslexic",
48
+ ...CONTRASTS.slice(1).map((mode) => `ax-contrast-${mode}`),
49
+ ...Object.values(SWITCHES),
50
+ ];
@@ -0,0 +1,4 @@
1
+ import type { AxController, AxSettings } from "./a11y.types";
2
+ export declare function loadAx(): AxSettings;
3
+ export declare function applySavedAx(doc: Document, nonce?: string | null): void;
4
+ export declare function createAx(doc: Document, nonce?: string | null): AxController;
@@ -0,0 +1,133 @@
1
+ import { createStyle } from "../lib/dom";
2
+ import { readJson, writeJson } from "../lib/storage";
3
+ import { createStore } from "../lib/store";
4
+ import { ALL_AX_CLASSES, AX_DEFAULTS, AX_STORAGE_KEY, AX_STYLE_ID, MORPH_CLASS } from "./a11y.constants";
5
+ import { axClasses, profileSettings, sanitizeAx } from "./a11y.lib";
6
+ import { AX_CSS } from "./a11y.styles";
7
+ export function loadAx() {
8
+ return sanitizeAx(readJson(AX_STORAGE_KEY));
9
+ }
10
+ function ensureStyle(doc, nonce) {
11
+ const existing = doc.getElementById(AX_STYLE_ID);
12
+ if (existing instanceof HTMLStyleElement)
13
+ return existing;
14
+ const style = createStyle(doc, AX_CSS, nonce, AX_STYLE_ID);
15
+ (doc.head ?? doc.documentElement).append(style);
16
+ return style;
17
+ }
18
+ function applyClasses(doc, s) {
19
+ const wanted = new Set(axClasses(s));
20
+ const list = doc.documentElement.classList;
21
+ // Only our known classes: a host site's own "ax-*" classes are left alone.
22
+ for (const c of ALL_AX_CLASSES)
23
+ list.toggle(c, wanted.has(c));
24
+ }
25
+ function prefersReducedMotion() {
26
+ return typeof matchMedia === "function" && matchMedia("(prefers-reduced-motion: reduce)").matches;
27
+ }
28
+ // Synchronous, so returning readers get their settings before first paint when loaded in <head>.
29
+ export function applySavedAx(doc, nonce = null) {
30
+ const s = loadAx();
31
+ if (!axClasses(s).length)
32
+ return;
33
+ ensureStyle(doc, nonce);
34
+ applyClasses(doc, s);
35
+ }
36
+ export function createAx(doc, nonce = null) {
37
+ const store = createStore(loadAx());
38
+ const style = ensureStyle(doc, nonce);
39
+ const root = doc.documentElement;
40
+ // Videos we paused for "pause animations", resumed when it is turned off again.
41
+ const paused = new Set();
42
+ let morphing = 0;
43
+ let alive = true;
44
+ let last = store.get();
45
+ function pauseVideos() {
46
+ for (const v of Array.from(doc.querySelectorAll("video"))) {
47
+ if (!v.paused) {
48
+ v.pause();
49
+ paused.add(v);
50
+ }
51
+ }
52
+ }
53
+ function resumeVideos() {
54
+ for (const v of paused)
55
+ v.play().catch(() => { });
56
+ paused.clear();
57
+ }
58
+ // Catches autoplaying videos that start after the setting was turned on.
59
+ function onPlay(e) {
60
+ if (!store.get().still || !(e.target instanceof HTMLVideoElement))
61
+ return;
62
+ e.target.pause();
63
+ paused.add(e.target);
64
+ }
65
+ // Crossfades between looks with a View Transition instead of a hard cut, unless motion is unwanted.
66
+ function morph(s, calm) {
67
+ function change() {
68
+ if (alive)
69
+ applyClasses(doc, s);
70
+ }
71
+ if (calm ||
72
+ prefersReducedMotion() ||
73
+ doc.visibilityState !== "visible" ||
74
+ typeof doc.startViewTransition !== "function") {
75
+ change();
76
+ return;
77
+ }
78
+ function done() {
79
+ if (--morphing === 0)
80
+ root.classList.remove(MORPH_CLASS);
81
+ }
82
+ root.classList.add(MORPH_CLASS);
83
+ morphing++;
84
+ try {
85
+ doc.startViewTransition(change).finished.then(done, done);
86
+ }
87
+ catch {
88
+ done();
89
+ change();
90
+ }
91
+ }
92
+ doc.addEventListener("play", onPlay, true);
93
+ applyClasses(doc, last);
94
+ if (last.still)
95
+ pauseVideos();
96
+ const unsubscribe = store.subscribe((s) => {
97
+ morph(s, s.still || last.still);
98
+ if (s.still !== last.still) {
99
+ if (s.still)
100
+ pauseVideos();
101
+ else
102
+ resumeVideos();
103
+ }
104
+ last = s;
105
+ writeJson(AX_STORAGE_KEY, s);
106
+ });
107
+ return {
108
+ store,
109
+ update(patch) {
110
+ // Guide and mask are mutually exclusive: both at once leave nothing readable.
111
+ const next = { ...patch };
112
+ if (patch.guide)
113
+ next.mask = false;
114
+ if (patch.mask)
115
+ next.guide = false;
116
+ store.set(next);
117
+ },
118
+ toggleProfile(id, active) {
119
+ store.set(active ? { ...AX_DEFAULTS } : profileSettings(id));
120
+ },
121
+ reset() {
122
+ store.set({ ...AX_DEFAULTS });
123
+ },
124
+ destroy() {
125
+ alive = false;
126
+ unsubscribe();
127
+ doc.removeEventListener("play", onPlay, true);
128
+ resumeVideos();
129
+ root.classList.remove(...ALL_AX_CLASSES, MORPH_CLASS);
130
+ style.remove();
131
+ },
132
+ };
133
+ }
@@ -0,0 +1,6 @@
1
+ import type { AxSettings, ProfileId } from "./a11y.types";
2
+ export declare function profileSettings(id: ProfileId): AxSettings;
3
+ export declare function activeProfile(s: AxSettings): ProfileId | null;
4
+ export declare function isDefault(s: AxSettings): boolean;
5
+ export declare function sanitizeAx(raw: unknown): AxSettings;
6
+ export declare function axClasses(s: AxSettings): string[];
@@ -0,0 +1,55 @@
1
+ import { isRecord } from "../lib/storage";
2
+ import { AX_DEFAULTS, CONTRASTS, FONTS, PROFILE_IDS, PROFILES, STEPS, SWITCH_KEYS, SWITCHES, TEXT_SIZES, } from "./a11y.constants";
3
+ const KEYS = Object.keys(AX_DEFAULTS);
4
+ export function profileSettings(id) {
5
+ return { ...AX_DEFAULTS, ...PROFILES[id] };
6
+ }
7
+ function same(a, b) {
8
+ return KEYS.every((k) => a[k] === b[k]);
9
+ }
10
+ export function activeProfile(s) {
11
+ return PROFILE_IDS.find((id) => same(profileSettings(id), s)) ?? null;
12
+ }
13
+ export function isDefault(s) {
14
+ return same(s, AX_DEFAULTS);
15
+ }
16
+ // Stored settings are untrusted input: keep only well-formed values.
17
+ export function sanitizeAx(raw) {
18
+ const s = { ...AX_DEFAULTS };
19
+ if (!isRecord(raw))
20
+ return s;
21
+ if (STEPS.includes(raw.text))
22
+ s.text = raw.text;
23
+ if (STEPS.includes(raw.line))
24
+ s.line = raw.line;
25
+ if (STEPS.includes(raw.spacing))
26
+ s.spacing = raw.spacing;
27
+ if (FONTS.includes(raw.font))
28
+ s.font = raw.font;
29
+ if (CONTRASTS.includes(raw.contrast))
30
+ s.contrast = raw.contrast;
31
+ for (const k of SWITCH_KEYS) {
32
+ const value = raw[k];
33
+ if (typeof value === "boolean")
34
+ s[k] = value;
35
+ }
36
+ return s;
37
+ }
38
+ export function axClasses(s) {
39
+ const out = [];
40
+ if (s.text)
41
+ out.push(`ax-text-${TEXT_SIZES[s.text]}`);
42
+ if (s.line)
43
+ out.push(`ax-line-${s.line}`);
44
+ if (s.spacing)
45
+ out.push(`ax-spacing-${s.spacing}`);
46
+ if (s.font !== "default")
47
+ out.push(`ax-font-${s.font}`);
48
+ if (s.contrast !== "default")
49
+ out.push(`ax-contrast-${s.contrast}`);
50
+ for (const k of SWITCH_KEYS) {
51
+ if (s[k])
52
+ out.push(SWITCHES[k]);
53
+ }
54
+ return out;
55
+ }
@@ -0,0 +1 @@
1
+ export declare const AX_CSS: string;
@@ -0,0 +1,63 @@
1
+ // The one global stylesheet the widget adds. Every rule is scoped under an html.ax-* class, so it
2
+ // is inert until the reader turns a setting on.
3
+ const TEXT = "p,li,dt,dd,blockquote,figcaption,caption,td,th,label,legend,summary,pre,h1,h2,h3,h4,h5,h6";
4
+ // Icon fonts render glyphs from ligatures or private-use characters; changing their font or
5
+ // spacing turns icons into gibberish.
6
+ const ICONS = 'i,svg,svg *,[class*="icon"],[class*="fa-"],[class^="fa "],.material-icons,.material-symbols-outlined,.dashicons,[aria-hidden="true"]';
7
+ const MEDIA = "img,picture,video,canvas,iframe,svg,svg *,object,embed";
8
+ const OURS = "lantun-reader,lantun-overlay";
9
+ const SANS = 'ui-sans-serif,system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif';
10
+ const DYSLEXIC_SRC = "https://cdn.jsdelivr.net/npm/@fontsource/opendyslexic@5.3.0/files/opendyslexic-latin";
11
+ const CURSOR = "url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='48' height='48' viewBox='0 0 48 48'%3E%3Cpath d='M9 5v34l9-8 6 13 7-3-6-13h12z' fill='%23000' stroke='%23fff' stroke-width='2.5' stroke-linejoin='round'/%3E%3C/svg%3E\") 9 5,auto";
12
+ function scale(n, z) {
13
+ return `html.ax-text-${n} :is(${TEXT}):not(:is(${TEXT}) *){zoom:${z}}`;
14
+ }
15
+ function line(n, v) {
16
+ return `html.ax-line-${n} body :is(${TEXT}){line-height:${v}!important}`;
17
+ }
18
+ function spacing(n, l) {
19
+ return `html.ax-spacing-${n} body *:not(${ICONS}){letter-spacing:${l}em!important;word-spacing:${l * 2}em!important}`;
20
+ }
21
+ export const AX_CSS = [
22
+ // Our crossfade between looks (controller.ts): short, and never in the way of the next click.
23
+ "html.ax-morph::view-transition{pointer-events:none}",
24
+ "html.ax-morph::view-transition-old(root),html.ax-morph::view-transition-new(root){animation-duration:.22s;animation-timing-function:cubic-bezier(.2,.8,.2,1)}",
25
+ // The widget is its own layer (mount.tsx names it) and holds still: only the page changes.
26
+ "html.ax-morph::view-transition-old(lantun-ui){display:none}",
27
+ "html.ax-morph::view-transition-group(lantun-ui),html.ax-morph::view-transition-new(lantun-ui){animation:none}",
28
+ // Zoom on the outermost text blocks only: scales px-based themes (where font-size on <html>
29
+ // does nothing) without compounding on nested blocks like li > p.
30
+ scale(115, 1.15),
31
+ scale(130, 1.3),
32
+ scale(150, 1.5),
33
+ line(1, 1.75),
34
+ line(2, 2.05),
35
+ line(3, 2.4),
36
+ spacing(1, 0.05),
37
+ spacing(2, 0.1),
38
+ spacing(3, 0.16),
39
+ `html.ax-font-readable body *:not(${ICONS}){font-family:${SANS}!important}`,
40
+ // Declared always, downloaded only once a matching element exists: zero network until toggled.
41
+ `@font-face{font-family:"OpenDyslexic";src:url(${DYSLEXIC_SRC}-400-normal.woff2) format("woff2");font-weight:400;font-display:swap}`,
42
+ `@font-face{font-family:"OpenDyslexic";src:url(${DYSLEXIC_SRC}-700-normal.woff2) format("woff2");font-weight:700;font-display:swap}`,
43
+ `html.ax-font-dyslexic body *:not(${ICONS}){font-family:"OpenDyslexic",${SANS}!important}`,
44
+ // Filters compose through custom properties so dark/invert and desaturate can stack.
45
+ `html.ax-contrast-dark{--ax-invert:invert(1) hue-rotate(180deg);background-color:#fff!important}`,
46
+ `html.ax-contrast-invert{--ax-invert:invert(1);background-color:#fff!important}`,
47
+ `html.ax-desaturate{--ax-gray:grayscale(1)}`,
48
+ `html:is(.ax-contrast-dark,.ax-contrast-invert,.ax-desaturate){filter:var(--ax-invert,) var(--ax-gray,)!important}`,
49
+ // Dark mode is a "smart invert": photos and video are flipped back to their real colours.
50
+ `html.ax-contrast-dark :is(img,video,canvas,iframe,svg image,[style*="background-image"]):not(picture *){filter:invert(1) hue-rotate(180deg)!important}`,
51
+ `html.ax-contrast-dark :is(${OURS}){filter:invert(1) hue-rotate(180deg)!important}`,
52
+ `html.ax-contrast-invert :is(${OURS}){filter:invert(1)!important}`,
53
+ `html.ax-contrast-light body,html.ax-contrast-light body *:not(${MEDIA}){background-color:#fff!important;color:#141414!important;border-color:#c4c4c4!important;text-shadow:none!important}`,
54
+ `html.ax-contrast-light body a[href],html.ax-contrast-light body a[href] *{color:#0b57d0!important}`,
55
+ `html.ax-contrast-high body,html.ax-contrast-high body *:not(${MEDIA}){background-color:#000!important;background-image:none!important;color:#fff!important;border-color:#fff!important;text-shadow:none!important;box-shadow:none!important}`,
56
+ `html.ax-contrast-high body a[href],html.ax-contrast-high body a[href] *{color:#ffe14d!important;text-decoration:underline!important}`,
57
+ `html.ax-links body a[href]{text-decoration:underline!important;text-decoration-thickness:2px!important;text-underline-offset:3px!important;outline:2px solid #e8a200!important;outline-offset:2px!important;background-color:#fff4c2!important;color:#111!important}`,
58
+ `html.ax-links body a[href] *{color:#111!important}`,
59
+ `html.ax-cursor,html.ax-cursor *{cursor:${CURSOR}!important}`,
60
+ `html.ax-still *,html.ax-still *::before,html.ax-still *::after{animation-play-state:paused!important;transition:none!important;scroll-behavior:auto!important}`,
61
+ `html.ax-no-images :is(img,picture,video,canvas,[role="img"]){visibility:hidden!important}`,
62
+ `html.ax-no-images body *:not(${OURS}){background-image:none!important}`,
63
+ ].join("\n");
@@ -0,0 +1,27 @@
1
+ import type { Store } from "../lib/store";
2
+ import type { PROFILES } from "./a11y.constants";
3
+ export type Step = 0 | 1 | 2 | 3;
4
+ export type FontMode = "default" | "readable" | "dyslexic";
5
+ export type ContrastMode = "default" | "dark" | "light" | "high" | "invert";
6
+ export interface AxSettings {
7
+ text: Step;
8
+ line: Step;
9
+ spacing: Step;
10
+ font: FontMode;
11
+ contrast: ContrastMode;
12
+ desaturate: boolean;
13
+ links: boolean;
14
+ cursor: boolean;
15
+ guide: boolean;
16
+ mask: boolean;
17
+ still: boolean;
18
+ noImages: boolean;
19
+ }
20
+ export type ProfileId = keyof typeof PROFILES;
21
+ export interface AxController {
22
+ store: Store<AxSettings>;
23
+ update(patch: Partial<AxSettings>): void;
24
+ toggleProfile(id: ProfileId, active: boolean): void;
25
+ reset(): void;
26
+ destroy(): void;
27
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,7 @@
1
+ export declare const BAND_TOP = 0.15;
2
+ export declare const BAND_BOTTOM = 0.85;
3
+ export declare const TARGET = 0.3;
4
+ export declare const SCROLL_KEYS: Set<string>;
5
+ export declare const FIELDS: RegExp;
6
+ export declare const LISTENER: AddEventListenerOptions;
7
+ export declare const PAUSE_MS = 5000;
@@ -0,0 +1,10 @@
1
+ // The comfortable reading band, as fractions of viewport height. Targeting 30% from the top keeps
2
+ // text clear of the sticky headers most news portals use.
3
+ export const BAND_TOP = 0.15;
4
+ export const BAND_BOTTOM = 0.85;
5
+ export const TARGET = 0.3;
6
+ export const SCROLL_KEYS = new Set(["ArrowUp", "ArrowDown", "PageUp", "PageDown", "Home", "End", " "]);
7
+ export const FIELDS = /^(INPUT|TEXTAREA|SELECT)$/;
8
+ export const LISTENER = { passive: true, capture: true };
9
+ // How long auto-scroll stays off after the reader scrolls by hand .
10
+ export const PAUSE_MS = 5000;
@@ -0,0 +1,2 @@
1
+ import type { AutoScroll, AutoScrollOptions } from "./autoscroll.types";
2
+ export declare function createAutoScroll(win: Window, o?: AutoScrollOptions): AutoScroll;
@@ -0,0 +1,58 @@
1
+ import { BAND_BOTTOM, BAND_TOP, FIELDS, LISTENER, PAUSE_MS, SCROLL_KEYS, TARGET } from "./autoscroll.constants";
2
+ // Keys typed into a field, or pressed inside our own (shadow-hosted) UI, are not page scrolling.
3
+ function scrollsPage(e) {
4
+ const target = e.target;
5
+ return (SCROLL_KEYS.has(e.key) && !target?.isContentEditable && !FIELDS.test(target?.tagName ?? "") && !target?.shadowRoot);
6
+ }
7
+ export function createAutoScroll(win, o = {}) {
8
+ const pauseMs = o.pauseMs ?? PAUSE_MS;
9
+ const doc = win.document;
10
+ let suspendedUntil = 0;
11
+ // Only real user input counts: our own smooth scrolling fires `scroll` events too.
12
+ function suspend() {
13
+ suspendedUntil = Date.now() + pauseMs;
14
+ }
15
+ function onKey(e) {
16
+ if (scrollsPage(e))
17
+ suspend();
18
+ }
19
+ // A pointerdown on <html> itself is a click on the page scrollbar.
20
+ function onPointer(e) {
21
+ if (e.target === doc.documentElement)
22
+ suspend();
23
+ }
24
+ function reducedMotion() {
25
+ return win.matchMedia?.("(prefers-reduced-motion: reduce)").matches ?? false;
26
+ }
27
+ win.addEventListener("wheel", suspend, LISTENER);
28
+ win.addEventListener("touchmove", suspend, LISTENER);
29
+ win.addEventListener("keydown", onKey, LISTENER);
30
+ win.addEventListener("pointerdown", onPointer, LISTENER);
31
+ return {
32
+ follow(range) {
33
+ if (Date.now() < suspendedUntil || doc.hidden || typeof range.getBoundingClientRect !== "function") {
34
+ return;
35
+ }
36
+ const rect = range.getBoundingClientRect();
37
+ if (!rect.height)
38
+ return;
39
+ const vh = win.innerHeight;
40
+ const top = vh * BAND_TOP;
41
+ const bottom = vh * BAND_BOTTOM;
42
+ const tall = rect.height > bottom - top;
43
+ const outside = rect.top < top || rect.top > bottom || (!tall && rect.bottom > bottom);
44
+ if (!outside)
45
+ return;
46
+ win.scrollBy({
47
+ top: rect.top - vh * TARGET,
48
+ behavior: reducedMotion() ? "auto" : "smooth",
49
+ });
50
+ },
51
+ destroy() {
52
+ win.removeEventListener("wheel", suspend, LISTENER);
53
+ win.removeEventListener("touchmove", suspend, LISTENER);
54
+ win.removeEventListener("keydown", onKey, LISTENER);
55
+ win.removeEventListener("pointerdown", onPointer, LISTENER);
56
+ },
57
+ };
58
+ }
@@ -0,0 +1,7 @@
1
+ export interface AutoScrollOptions {
2
+ pauseMs?: number;
3
+ }
4
+ export interface AutoScroll {
5
+ follow(range: Range): void;
6
+ destroy(): void;
7
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,11 @@
1
+ export declare const POSITIVE_HINT: RegExp;
2
+ export declare const NEGATIVE_HINT: RegExp;
3
+ export declare const MIN_PARAGRAPH = 25;
4
+ export declare const MIN_HINTED_BODY = 200;
5
+ export declare const MIN_BARE_TEXT = 80;
6
+ export declare const ANCESTOR_DIVIDERS: readonly [1, 2, 6];
7
+ export declare const TAG_WEIGHTS: Readonly<Record<string, number>>;
8
+ export declare const BUILTIN_SKIP: string;
9
+ export declare const READ_ALSO: RegExp;
10
+ export declare const FOOTNOTES = "sup:has(> a[href^=\"#\"])";
11
+ export declare const FLOATS: Set<string>;
@@ -0,0 +1,48 @@
1
+ // Readability-style heuristics, trimmed to what matters for picking one root on article pages.
2
+ export const POSITIVE_HINT = /article|body|content|entry|main|post|story|text|detail|isi|berita|artikel/i;
3
+ export const NEGATIVE_HINT = /comment|sidebar|widget|footer|masthead|menu|nav|related|popular|share|social|sponsor|promo|banner|breadcrumb|cookie|subscribe|newsletter|tags?\b|meta|author|byline|caption|gpt-ad|(?:^|[\s_-])(?:ads?|advert\w*)(?:$|[\s_-])/i;
4
+ export const MIN_PARAGRAPH = 25;
5
+ export const MIN_HINTED_BODY = 200;
6
+ // Direct text a <div> needs to count as a paragraph of its own (<br><br>-separated bodies).
7
+ export const MIN_BARE_TEXT = 80;
8
+ // Share of a paragraph's score given to its parent, grandparent and great-grandparent.
9
+ export const ANCESTOR_DIVIDERS = [1, 2, 6];
10
+ export const TAG_WEIGHTS = {
11
+ div: 5,
12
+ article: 5,
13
+ pre: 3,
14
+ td: 3,
15
+ blockquote: 3,
16
+ ol: -3,
17
+ ul: -3,
18
+ dl: -3,
19
+ li: -3,
20
+ form: -3,
21
+ h1: -5,
22
+ h2: -5,
23
+ h3: -5,
24
+ h4: -5,
25
+ h5: -5,
26
+ h6: -5,
27
+ th: -5,
28
+ };
29
+ const ADS = '.ad,.ads,.advert,.advertisement,.ad-slot,.adsbygoogle,[id^="div-gpt-ad"],[data-ad-unit],[data-ad-slot]';
30
+ // Never read aloud, even inside the article root.
31
+ export const BUILTIN_SKIP = [
32
+ "[data-reader-skip]",
33
+ 'nav,aside,footer,[role="navigation"],[role="complementary"],[role="note"]',
34
+ // Many CMSes mark captions and photo credits with classes instead of <figcaption>.
35
+ 'figure,figcaption,[class*="caption"],[class*="credit"]',
36
+ ".sr-only,.screen-reader-text,.visually-hidden,.visuallyhidden",
37
+ "script,style,noscript,template,iframe,object,embed,svg,math,canvas,video,audio",
38
+ "button,select,textarea,input,form",
39
+ // Code reads terribly aloud; publishers can still opt in with contentSelector on a <pre>.
40
+ "pre",
41
+ '[hidden],[aria-hidden="true"]',
42
+ ADS,
43
+ ].join(",");
44
+ // Inline cross-links ("Baca juga: ...") are standard on Indonesian portals.
45
+ export const READ_ALSO = /^\s*(baca juga|lihat juga|simak juga|read more|read also|see also|related)\s*:/i;
46
+ // Footnote markers ("[1]"). Added only where :has() parses: one bad selector voids the whole list.
47
+ export const FOOTNOTES = 'sup:has(> a[href^="#"])';
48
+ export const FLOATS = new Set(["left", "right", "inline-start", "inline-end"]);
@@ -0,0 +1,5 @@
1
+ export type SkipMatcher = (el: Element) => boolean;
2
+ export declare function createSkipMatcher(exclude?: readonly string[], doc?: Document): SkipMatcher;
3
+ export declare function isInsideSkipped(el: Element, skip: SkipMatcher, stopAt: Element): boolean;
4
+ export declare function detectArticleRoot(doc: Document, skip: SkipMatcher): Element | null;
5
+ export declare function findArticleRoot(doc: Document, contentSelector: string | null, skip: SkipMatcher): Element | null;