@glassly/miniapp 0.4.3-beta.1240 → 0.4.3-beta.1278
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 +41 -3
- package/dist/display/profiles/types.d.ts.map +1 -1
- package/dist/display/scene/types.d.ts.map +1 -1
- package/dist/display/scene/types.js.map +1 -1
- package/dist/host/index.d.ts +1 -0
- package/dist/host/index.d.ts.map +1 -1
- package/dist/host/index.js +1 -0
- package/dist/host/index.js.map +1 -1
- package/dist/host/settingsBridge.d.ts +31 -8
- package/dist/host/settingsBridge.d.ts.map +1 -1
- package/dist/host/settingsBridge.js +63 -11
- package/dist/host/settingsBridge.js.map +1 -1
- package/dist/host/ttsSanitizer.d.ts +5 -0
- package/dist/host/ttsSanitizer.d.ts.map +1 -0
- package/dist/host/ttsSanitizer.js +61 -0
- package/dist/host/ttsSanitizer.js.map +1 -0
- package/dist/modules/cloud.d.ts +2 -0
- package/dist/modules/cloud.d.ts.map +1 -1
- package/dist/modules/cloud.js +17 -7
- package/dist/modules/cloud.js.map +1 -1
- package/dist/modules/settings.d.ts +4 -1
- package/dist/modules/settings.d.ts.map +1 -1
- package/dist/modules/settings.js +4 -1
- package/dist/modules/settings.js.map +1 -1
- package/dist/reader/Reader.d.ts +147 -0
- package/dist/reader/Reader.d.ts.map +1 -0
- package/dist/reader/Reader.js +525 -0
- package/dist/reader/Reader.js.map +1 -0
- package/dist/reader/document.d.ts +54 -0
- package/dist/reader/document.d.ts.map +1 -0
- package/dist/reader/document.js +114 -0
- package/dist/reader/document.js.map +1 -0
- package/dist/reader/index.d.ts +12 -0
- package/dist/reader/index.d.ts.map +1 -0
- package/dist/reader/index.js +9 -0
- package/dist/reader/index.js.map +1 -0
- package/dist/reader/lens.d.ts +55 -0
- package/dist/reader/lens.d.ts.map +1 -0
- package/dist/reader/lens.js +210 -0
- package/dist/reader/lens.js.map +1 -0
- package/dist/sub-path-types.test-d.d.ts +3 -1
- package/dist/sub-path-types.test-d.d.ts.map +1 -1
- package/dist/sub-path-types.test-d.js +1 -7
- package/dist/sub-path-types.test-d.js.map +1 -1
- package/dist/theme.css +856 -0
- package/dist/ui/index.d.ts +1 -0
- package/dist/ui/index.d.ts.map +1 -1
- package/dist/ui/index.js +1 -0
- package/dist/ui/index.js.map +1 -1
- package/dist/ui/kit/Badge.d.ts +8 -0
- package/dist/ui/kit/Badge.d.ts.map +1 -0
- package/dist/ui/kit/Badge.js +6 -0
- package/dist/ui/kit/Badge.js.map +1 -0
- package/dist/ui/kit/Button.d.ts +9 -0
- package/dist/ui/kit/Button.d.ts.map +1 -0
- package/dist/ui/kit/Button.js +7 -0
- package/dist/ui/kit/Button.js.map +1 -0
- package/dist/ui/kit/Card.d.ts +10 -0
- package/dist/ui/kit/Card.d.ts.map +1 -0
- package/dist/ui/kit/Card.js +21 -0
- package/dist/ui/kit/Card.js.map +1 -0
- package/dist/ui/kit/Dock.d.ts +29 -0
- package/dist/ui/kit/Dock.d.ts.map +1 -0
- package/dist/ui/kit/Dock.js +34 -0
- package/dist/ui/kit/Dock.js.map +1 -0
- package/dist/ui/kit/Feedback.d.ts +37 -0
- package/dist/ui/kit/Feedback.d.ts.map +1 -0
- package/dist/ui/kit/Feedback.js +21 -0
- package/dist/ui/kit/Feedback.js.map +1 -0
- package/dist/ui/kit/Field.d.ts +8 -0
- package/dist/ui/kit/Field.d.ts.map +1 -0
- package/dist/ui/kit/Field.js +16 -0
- package/dist/ui/kit/Field.js.map +1 -0
- package/dist/ui/kit/Page.d.ts +33 -0
- package/dist/ui/kit/Page.d.ts.map +1 -0
- package/dist/ui/kit/Page.js +77 -0
- package/dist/ui/kit/Page.js.map +1 -0
- package/dist/ui/kit/Section.d.ts +17 -0
- package/dist/ui/kit/Section.d.ts.map +1 -0
- package/dist/ui/kit/Section.js +22 -0
- package/dist/ui/kit/Section.js.map +1 -0
- package/dist/ui/kit/SetupGuide.d.ts +45 -0
- package/dist/ui/kit/SetupGuide.d.ts.map +1 -0
- package/dist/ui/kit/SetupGuide.js +40 -0
- package/dist/ui/kit/SetupGuide.js.map +1 -0
- package/dist/ui/kit/Switch.d.ts +7 -0
- package/dist/ui/kit/Switch.d.ts.map +1 -0
- package/dist/ui/kit/Switch.js +11 -0
- package/dist/ui/kit/Switch.js.map +1 -0
- package/dist/ui/kit/Tabs.d.ts +20 -0
- package/dist/ui/kit/Tabs.d.ts.map +1 -0
- package/dist/ui/kit/Tabs.js +53 -0
- package/dist/ui/kit/Tabs.js.map +1 -0
- package/dist/ui/kit/cx.d.ts +2 -0
- package/dist/ui/kit/cx.d.ts.map +1 -0
- package/dist/ui/kit/cx.js +4 -0
- package/dist/ui/kit/cx.js.map +1 -0
- package/dist/ui/kit/hooks.d.ts +17 -0
- package/dist/ui/kit/hooks.d.ts.map +1 -0
- package/dist/ui/kit/hooks.js +34 -0
- package/dist/ui/kit/hooks.js.map +1 -0
- package/dist/ui/kit/index.d.ts +14 -0
- package/dist/ui/kit/index.d.ts.map +1 -0
- package/dist/ui/kit/index.js +14 -0
- package/dist/ui/kit/index.js.map +1 -0
- package/dist/ui/kit/useWide.d.ts +4 -0
- package/dist/ui/kit/useWide.d.ts.map +1 -0
- package/dist/ui/kit/useWide.js +18 -0
- package/dist/ui/kit/useWide.js.map +1 -0
- package/package.json +16 -5
- package/src/display/profiles/types.ts +9 -1
- package/src/display/scene/types.ts +6 -1
- package/src/host/index.ts +1 -0
- package/src/host/settingsBridge.ts +72 -12
- package/src/host/ttsSanitizer.ts +66 -0
- package/src/modules/cloud.ts +21 -7
- package/src/modules/settings.ts +4 -1
- package/src/reader/Reader.ts +580 -0
- package/src/reader/document.ts +154 -0
- package/src/reader/index.ts +12 -0
- package/src/reader/lens.ts +250 -0
- package/src/sub-path-types.test-d.ts +5 -0
- package/src/ui/index.ts +2 -0
- package/src/ui/kit/Badge.tsx +19 -0
- package/src/ui/kit/Button.tsx +27 -0
- package/src/ui/kit/Card.tsx +29 -0
- package/src/ui/kit/Dock.tsx +77 -0
- package/src/ui/kit/Feedback.tsx +101 -0
- package/src/ui/kit/Field.tsx +38 -0
- package/src/ui/kit/Page.tsx +154 -0
- package/src/ui/kit/Section.tsx +80 -0
- package/src/ui/kit/SetupGuide.tsx +153 -0
- package/src/ui/kit/Switch.tsx +28 -0
- package/src/ui/kit/Tabs.tsx +108 -0
- package/src/ui/kit/cx.ts +3 -0
- package/src/ui/kit/hooks.ts +53 -0
- package/src/ui/kit/index.ts +51 -0
- package/src/ui/kit/useWide.ts +19 -0
- package/src/ui/theme.css +856 -0
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Reader: a miniapp hands it a title, sections of text and its end-screen
|
|
3
|
+
* actions, and the glasses read the text to the wearer line by line at their
|
|
4
|
+
* reading speed. Built only on session.display, session.input and
|
|
5
|
+
* session.settings, so it runs on any Glassly App; one that predates the
|
|
6
|
+
* reading settings reads at 220 wpm and keeps a glasses speed change for the
|
|
7
|
+
* rest of the session.
|
|
8
|
+
*
|
|
9
|
+
* Gestures (map A, as Teleprompter): tap pauses and resumes, and at an end
|
|
10
|
+
* screen runs its tap action; swipe down / up step a line while reading and
|
|
11
|
+
* change the speed by 20 wpm while paused (dial and scroll steps count as
|
|
12
|
+
* swipes); hold runs the app's hold action; double tap, or a Neural Band's
|
|
13
|
+
* swipe left, leaves the Reader.
|
|
14
|
+
*/
|
|
15
|
+
import type { RenderElement } from "../modules/display";
|
|
16
|
+
import { type ReaderSection } from "./document";
|
|
17
|
+
export interface ReaderOptions {
|
|
18
|
+
title: string;
|
|
19
|
+
details?: string;
|
|
20
|
+
sections: ReaderSection[];
|
|
21
|
+
hold?: {
|
|
22
|
+
action: string;
|
|
23
|
+
label: string;
|
|
24
|
+
};
|
|
25
|
+
leaveLabel?: string;
|
|
26
|
+
start?: {
|
|
27
|
+
part?: number;
|
|
28
|
+
percent?: number;
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
export type ReaderEvent = {
|
|
32
|
+
type: "action";
|
|
33
|
+
action: string;
|
|
34
|
+
} | {
|
|
35
|
+
type: "progress";
|
|
36
|
+
part: number;
|
|
37
|
+
section: number;
|
|
38
|
+
percent: number;
|
|
39
|
+
} | {
|
|
40
|
+
type: "closed";
|
|
41
|
+
reason: "double_tap" | "swipe_left" | "app";
|
|
42
|
+
};
|
|
43
|
+
export interface ReaderDeps {
|
|
44
|
+
later: (fn: () => void, ms: number) => () => void;
|
|
45
|
+
now: () => number;
|
|
46
|
+
}
|
|
47
|
+
export interface ReaderSession {
|
|
48
|
+
packageName: string;
|
|
49
|
+
capabilities: {
|
|
50
|
+
modelName?: unknown;
|
|
51
|
+
display?: object | null;
|
|
52
|
+
} | null;
|
|
53
|
+
display: {
|
|
54
|
+
render: (elements: RenderElement[]) => Promise<unknown>;
|
|
55
|
+
};
|
|
56
|
+
input: {
|
|
57
|
+
onTouch: (handler: (data: {
|
|
58
|
+
kind: string;
|
|
59
|
+
}) => void) => () => void;
|
|
60
|
+
setClaimedGestures: (gestures: string[], options?: {
|
|
61
|
+
scope?: string;
|
|
62
|
+
}) => Promise<void>;
|
|
63
|
+
};
|
|
64
|
+
settings: {
|
|
65
|
+
getAll: (keys?: string[]) => Promise<Record<string, unknown>>;
|
|
66
|
+
set: (key: string, value: unknown) => Promise<void>;
|
|
67
|
+
onChange: (handler: (change: {
|
|
68
|
+
key: string;
|
|
69
|
+
value: unknown;
|
|
70
|
+
}) => void) => () => void;
|
|
71
|
+
};
|
|
72
|
+
onCapabilitiesChange?: (handler: (capabilities: unknown) => void) => () => void;
|
|
73
|
+
onPause?: (handler: (reason: unknown) => void) => () => void;
|
|
74
|
+
paused?: boolean;
|
|
75
|
+
ready?: boolean;
|
|
76
|
+
on?: (event: "ready", handler: () => void) => () => void;
|
|
77
|
+
}
|
|
78
|
+
export declare const READER_WPM: {
|
|
79
|
+
readonly min: 100;
|
|
80
|
+
readonly max: 400;
|
|
81
|
+
readonly step: 20;
|
|
82
|
+
readonly default: 220;
|
|
83
|
+
};
|
|
84
|
+
export declare function openReader(session: ReaderSession, options: ReaderOptions, deps?: Partial<ReaderDeps>): Reader;
|
|
85
|
+
export declare class Reader {
|
|
86
|
+
private readonly session;
|
|
87
|
+
private readonly deps;
|
|
88
|
+
private options;
|
|
89
|
+
private prefs;
|
|
90
|
+
private bridged;
|
|
91
|
+
private readWpm;
|
|
92
|
+
private profile;
|
|
93
|
+
private measurer;
|
|
94
|
+
private wrapper;
|
|
95
|
+
private layout;
|
|
96
|
+
private doc;
|
|
97
|
+
private wrapWidth;
|
|
98
|
+
private docProfile;
|
|
99
|
+
private phase;
|
|
100
|
+
private line;
|
|
101
|
+
private part;
|
|
102
|
+
private toastText;
|
|
103
|
+
private readOnWhenReady;
|
|
104
|
+
private readMs;
|
|
105
|
+
private readingSince;
|
|
106
|
+
private lastFrame;
|
|
107
|
+
private isOpenNow;
|
|
108
|
+
private handlers;
|
|
109
|
+
private cancelClock;
|
|
110
|
+
private cancelToast;
|
|
111
|
+
private unsubs;
|
|
112
|
+
constructor(session: ReaderSession, options: ReaderOptions, deps: ReaderDeps);
|
|
113
|
+
get isOpen(): boolean;
|
|
114
|
+
get wpm(): number;
|
|
115
|
+
onEvent(handler: (event: ReaderEvent) => void): () => void;
|
|
116
|
+
open(): void;
|
|
117
|
+
close(): void;
|
|
118
|
+
/** Change the text or the hold action while open, keeping the place: e.g. comments arriving after the post. */
|
|
119
|
+
update(next: Partial<Omit<ReaderOptions, "start">>): void;
|
|
120
|
+
/** Show a brief message for 2 s, e.g. "★ Saved\nopens in Reddit on your phone". */
|
|
121
|
+
toast(text: string, ms?: number): void;
|
|
122
|
+
private emit;
|
|
123
|
+
private manual;
|
|
124
|
+
private speed;
|
|
125
|
+
private loadPreferences;
|
|
126
|
+
private apply;
|
|
127
|
+
private relayout;
|
|
128
|
+
private firstLine;
|
|
129
|
+
private autoStart;
|
|
130
|
+
private startReading;
|
|
131
|
+
private markReading;
|
|
132
|
+
private schedule;
|
|
133
|
+
private advance;
|
|
134
|
+
private step;
|
|
135
|
+
private enterStop;
|
|
136
|
+
/** Read on into the next part, from its first line. */
|
|
137
|
+
private continueReading;
|
|
138
|
+
private progress;
|
|
139
|
+
private pauseForAway;
|
|
140
|
+
private changeSpeed;
|
|
141
|
+
private gesture;
|
|
142
|
+
private finish;
|
|
143
|
+
private statusTitle;
|
|
144
|
+
private frame;
|
|
145
|
+
private render;
|
|
146
|
+
}
|
|
147
|
+
//# sourceMappingURL=Reader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Reader.d.ts","sourceRoot":"","sources":["../../src/reader/Reader.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAKH,OAAO,KAAK,EAAC,aAAa,EAAC,MAAM,oBAAoB,CAAA;AACrD,OAAO,EAAiB,KAAK,aAAa,EAAC,MAAM,YAAY,CAAA;AAG7D,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,MAAM,CAAA;IACb,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,QAAQ,EAAE,aAAa,EAAE,CAAA;IACzB,IAAI,CAAC,EAAE;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAC,CAAA;IACtC,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,KAAK,CAAC,EAAE;QAAC,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAC,CAAA;CAC1C;AAED,MAAM,MAAM,WAAW,GACnB;IAAC,IAAI,EAAE,QAAQ,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAC,GAChC;IAAC,IAAI,EAAE,UAAU,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAC,GAClE;IAAC,IAAI,EAAE,QAAQ,CAAC;IAAC,MAAM,EAAE,YAAY,GAAG,YAAY,GAAG,KAAK,CAAA;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@@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Reader: a miniapp hands it a title, sections of text and its end-screen
|
|
3
|
+
* actions, and the glasses read the text to the wearer line by line at their
|
|
4
|
+
* reading speed. Built only on session.display, session.input and
|
|
5
|
+
* session.settings, so it runs on any Glassly App; one that predates the
|
|
6
|
+
* reading settings reads at 220 wpm and keeps a glasses speed change for the
|
|
7
|
+
* rest of the session.
|
|
8
|
+
*
|
|
9
|
+
* Gestures (map A, as Teleprompter): tap pauses and resumes, and at an end
|
|
10
|
+
* screen runs its tap action; swipe down / up step a line while reading and
|
|
11
|
+
* change the speed by 20 wpm while paused (dial and scroll steps count as
|
|
12
|
+
* swipes); hold runs the app's hold action; double tap, or a Neural Band's
|
|
13
|
+
* swipe left, leaves the Reader.
|
|
14
|
+
*/
|
|
15
|
+
import { TextMeasurer } from "../display/measurer";
|
|
16
|
+
import { textProfileFor } from "../display/profiles";
|
|
17
|
+
import { TextWrapper } from "../display/wrapper";
|
|
18
|
+
import { ReaderDocument } from "./document";
|
|
19
|
+
import { lensElements, lensLayout, textWrapWidth } from "./lens";
|
|
20
|
+
export const READER_WPM = { min: 100, max: 400, step: 20, default: 220 };
|
|
21
|
+
const TITLE_CARD_MS = 2000;
|
|
22
|
+
const TOAST_MS = 2000;
|
|
23
|
+
const SCOPE = "reader";
|
|
24
|
+
const READING_KEYS = [
|
|
25
|
+
"reading_wpm",
|
|
26
|
+
"reading_auto_start",
|
|
27
|
+
"reading_pause_paragraphs",
|
|
28
|
+
"reading_glasses_speed",
|
|
29
|
+
"reading_highlight",
|
|
30
|
+
"reading_app_speed",
|
|
31
|
+
];
|
|
32
|
+
const DEFAULTS = {
|
|
33
|
+
wpm: READER_WPM.default,
|
|
34
|
+
autoStart: true,
|
|
35
|
+
beats: true,
|
|
36
|
+
keep: true,
|
|
37
|
+
highlight: "filled",
|
|
38
|
+
appSpeed: null,
|
|
39
|
+
};
|
|
40
|
+
const sessionWpm = new WeakMap();
|
|
41
|
+
const defaultDeps = () => ({
|
|
42
|
+
later: (fn, ms) => {
|
|
43
|
+
const timer = setTimeout(fn, ms);
|
|
44
|
+
return () => clearTimeout(timer);
|
|
45
|
+
},
|
|
46
|
+
now: Date.now,
|
|
47
|
+
});
|
|
48
|
+
const clampWpm = (wpm) => Math.max(READER_WPM.min, Math.min(READER_WPM.max, wpm));
|
|
49
|
+
const isWpm = (value) => typeof value === "number" && Number.isFinite(value) && value > 0;
|
|
50
|
+
function clock(ms) {
|
|
51
|
+
const seconds = Math.max(0, Math.round(ms / 1000));
|
|
52
|
+
return `${Math.floor(seconds / 60)}:${String(seconds % 60).padStart(2, "0")}`;
|
|
53
|
+
}
|
|
54
|
+
export function openReader(session, options, deps = {}) {
|
|
55
|
+
const reader = new Reader(session, options, { ...defaultDeps(), ...deps });
|
|
56
|
+
reader.open();
|
|
57
|
+
return reader;
|
|
58
|
+
}
|
|
59
|
+
export class Reader {
|
|
60
|
+
constructor(session, options, deps) {
|
|
61
|
+
this.session = session;
|
|
62
|
+
this.deps = deps;
|
|
63
|
+
this.prefs = { ...DEFAULTS };
|
|
64
|
+
this.bridged = false;
|
|
65
|
+
this.readWpm = null;
|
|
66
|
+
this.profile = textProfileFor(null);
|
|
67
|
+
this.measurer = new TextMeasurer(this.profile);
|
|
68
|
+
this.wrapper = new TextWrapper(this.measurer);
|
|
69
|
+
this.wrapWidth = 0;
|
|
70
|
+
this.docProfile = null;
|
|
71
|
+
this.phase = "title";
|
|
72
|
+
this.line = 0;
|
|
73
|
+
this.part = 0;
|
|
74
|
+
this.toastText = null;
|
|
75
|
+
this.readOnWhenReady = false;
|
|
76
|
+
this.readMs = 0;
|
|
77
|
+
this.readingSince = null;
|
|
78
|
+
this.lastFrame = "";
|
|
79
|
+
this.isOpenNow = false;
|
|
80
|
+
this.handlers = new Set();
|
|
81
|
+
this.cancelClock = null;
|
|
82
|
+
this.cancelToast = null;
|
|
83
|
+
this.unsubs = [];
|
|
84
|
+
this.options = options;
|
|
85
|
+
}
|
|
86
|
+
get isOpen() {
|
|
87
|
+
return this.isOpenNow;
|
|
88
|
+
}
|
|
89
|
+
get wpm() {
|
|
90
|
+
return this.speed();
|
|
91
|
+
}
|
|
92
|
+
onEvent(handler) {
|
|
93
|
+
this.handlers.add(handler);
|
|
94
|
+
return () => this.handlers.delete(handler);
|
|
95
|
+
}
|
|
96
|
+
open() {
|
|
97
|
+
if (this.isOpenNow)
|
|
98
|
+
return;
|
|
99
|
+
this.isOpenNow = true;
|
|
100
|
+
const legacy = sessionWpm.get(this.session);
|
|
101
|
+
if (legacy)
|
|
102
|
+
this.prefs.wpm = legacy;
|
|
103
|
+
this.relayout();
|
|
104
|
+
const start = this.options.start;
|
|
105
|
+
if (start) {
|
|
106
|
+
this.part = Math.max(0, Math.min(this.doc.parts.length - 1, start.part ?? 0));
|
|
107
|
+
this.line = this.doc.lineAt(this.part, start.percent ?? 0);
|
|
108
|
+
this.phase = "paused";
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
this.line = this.firstLine(0);
|
|
112
|
+
}
|
|
113
|
+
this.unsubs.push(this.session.input.onTouch((data) => this.gesture(data.kind)));
|
|
114
|
+
if (this.session.onPause) {
|
|
115
|
+
this.unsubs.push(this.session.onPause(() => this.pauseForAway()));
|
|
116
|
+
}
|
|
117
|
+
if (this.session.onCapabilitiesChange) {
|
|
118
|
+
this.unsubs.push(this.session.onCapabilitiesChange(() => this.relayout(true)));
|
|
119
|
+
}
|
|
120
|
+
if (this.session.ready === false && this.session.on) {
|
|
121
|
+
const off = this.session.on("ready", () => {
|
|
122
|
+
off();
|
|
123
|
+
this.relayout(true);
|
|
124
|
+
void this.loadPreferences();
|
|
125
|
+
if (this.session.paused)
|
|
126
|
+
this.pauseForAway();
|
|
127
|
+
});
|
|
128
|
+
this.unsubs.push(off);
|
|
129
|
+
}
|
|
130
|
+
void this.session.input.setClaimedGestures(["double_tap"], { scope: SCOPE }).catch(() => { });
|
|
131
|
+
this.render();
|
|
132
|
+
if (this.session.ready !== false || !this.session.on)
|
|
133
|
+
void this.loadPreferences();
|
|
134
|
+
if (this.phase === "title")
|
|
135
|
+
this.cancelClock = this.deps.later(() => this.autoStart(), TITLE_CARD_MS);
|
|
136
|
+
if (this.session.paused)
|
|
137
|
+
this.pauseForAway();
|
|
138
|
+
}
|
|
139
|
+
close() {
|
|
140
|
+
this.finish("app");
|
|
141
|
+
}
|
|
142
|
+
/** Change the text or the hold action while open, keeping the place: e.g. comments arriving after the post. */
|
|
143
|
+
update(next) {
|
|
144
|
+
this.options = { ...this.options, ...next };
|
|
145
|
+
if (!this.isOpenNow)
|
|
146
|
+
return;
|
|
147
|
+
this.relayout(true);
|
|
148
|
+
if (this.readOnWhenReady && this.phase === "stop" && this.continueReading())
|
|
149
|
+
this.readOnWhenReady = false;
|
|
150
|
+
}
|
|
151
|
+
/** Show a brief message for 2 s, e.g. "★ Saved\nopens in Reddit on your phone". */
|
|
152
|
+
toast(text, ms = TOAST_MS) {
|
|
153
|
+
if (!this.isOpenNow)
|
|
154
|
+
return;
|
|
155
|
+
this.cancelToast?.();
|
|
156
|
+
this.toastText = text;
|
|
157
|
+
this.render();
|
|
158
|
+
this.cancelToast = this.deps.later(() => {
|
|
159
|
+
this.cancelToast = null;
|
|
160
|
+
this.toastText = null;
|
|
161
|
+
this.render();
|
|
162
|
+
}, ms);
|
|
163
|
+
}
|
|
164
|
+
// ---------------------------------------------------------------------------
|
|
165
|
+
emit(event) {
|
|
166
|
+
for (const handler of [...this.handlers])
|
|
167
|
+
handler(event);
|
|
168
|
+
}
|
|
169
|
+
manual() {
|
|
170
|
+
return this.prefs.appSpeed === "off";
|
|
171
|
+
}
|
|
172
|
+
speed() {
|
|
173
|
+
if (this.readWpm)
|
|
174
|
+
return this.readWpm;
|
|
175
|
+
if (isWpm(this.prefs.appSpeed))
|
|
176
|
+
return clampWpm(this.prefs.appSpeed);
|
|
177
|
+
return clampWpm(this.prefs.wpm);
|
|
178
|
+
}
|
|
179
|
+
async loadPreferences() {
|
|
180
|
+
let values;
|
|
181
|
+
try {
|
|
182
|
+
values = await this.session.settings.getAll(READING_KEYS);
|
|
183
|
+
}
|
|
184
|
+
catch {
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
if (!this.isOpenNow)
|
|
188
|
+
return;
|
|
189
|
+
this.bridged = true;
|
|
190
|
+
this.apply(values);
|
|
191
|
+
this.unsubs.push(this.session.settings.onChange(({ key, value }) => this.apply({ [key]: value })));
|
|
192
|
+
}
|
|
193
|
+
apply(values) {
|
|
194
|
+
const prefs = { ...this.prefs };
|
|
195
|
+
if ("reading_wpm" in values && isWpm(values.reading_wpm))
|
|
196
|
+
prefs.wpm = values.reading_wpm;
|
|
197
|
+
if (typeof values.reading_auto_start === "boolean")
|
|
198
|
+
prefs.autoStart = values.reading_auto_start;
|
|
199
|
+
if (typeof values.reading_pause_paragraphs === "boolean")
|
|
200
|
+
prefs.beats = values.reading_pause_paragraphs;
|
|
201
|
+
if (values.reading_glasses_speed === "keep" || values.reading_glasses_speed === "this_read") {
|
|
202
|
+
prefs.keep = values.reading_glasses_speed === "keep";
|
|
203
|
+
}
|
|
204
|
+
const highlight = values.reading_highlight;
|
|
205
|
+
if (highlight === "filled" || highlight === "brackets" || highlight === "dim")
|
|
206
|
+
prefs.highlight = highlight;
|
|
207
|
+
if ("reading_app_speed" in values) {
|
|
208
|
+
const own = values.reading_app_speed;
|
|
209
|
+
prefs.appSpeed = own === "off" ? "off" : isWpm(own) ? own : null;
|
|
210
|
+
}
|
|
211
|
+
const rewrap = prefs.highlight !== this.prefs.highlight;
|
|
212
|
+
const wasManual = this.manual();
|
|
213
|
+
this.prefs = prefs;
|
|
214
|
+
if (rewrap)
|
|
215
|
+
this.relayout(true);
|
|
216
|
+
if (this.phase === "title" && !prefs.autoStart) {
|
|
217
|
+
this.cancelClock?.();
|
|
218
|
+
this.cancelClock = null;
|
|
219
|
+
}
|
|
220
|
+
if (wasManual !== this.manual() && this.phase === "reading")
|
|
221
|
+
this.schedule();
|
|
222
|
+
this.render();
|
|
223
|
+
}
|
|
224
|
+
relayout(keepPlace = false) {
|
|
225
|
+
const capabilities = this.session.capabilities;
|
|
226
|
+
const profile = textProfileFor(capabilities);
|
|
227
|
+
if (profile.id !== this.profile.id) {
|
|
228
|
+
this.profile = profile;
|
|
229
|
+
this.measurer = new TextMeasurer(profile);
|
|
230
|
+
this.wrapper = new TextWrapper(this.measurer);
|
|
231
|
+
}
|
|
232
|
+
this.layout = lensLayout(profile, (capabilities?.display ?? null));
|
|
233
|
+
const wrapWidth = textWrapWidth(this.layout, this.prefs.highlight, this.measurer);
|
|
234
|
+
const sameText = !!this.doc && this.doc.sections === this.options.sections;
|
|
235
|
+
if (keepPlace && sameText && wrapWidth === this.wrapWidth && profile === this.docProfile)
|
|
236
|
+
return this.render();
|
|
237
|
+
const before = keepPlace && this.doc ? { part: this.part, words: this.doc.wordsBefore(this.line), line: this.line } : null;
|
|
238
|
+
this.doc = new ReaderDocument(this.options.sections, this.wrapper, wrapWidth);
|
|
239
|
+
this.wrapWidth = wrapWidth;
|
|
240
|
+
this.docProfile = profile;
|
|
241
|
+
if (before) {
|
|
242
|
+
this.part = Math.min(before.part, this.doc.parts.length - 1);
|
|
243
|
+
this.line = sameText
|
|
244
|
+
? this.doc.lineAtWord(this.part, before.words)
|
|
245
|
+
: Math.min(before.line, this.doc.lines.length - 1);
|
|
246
|
+
this.render();
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
firstLine(part) {
|
|
250
|
+
const p = this.doc.parts[part];
|
|
251
|
+
return this.doc.nextReadable(p.first - 1, p.last) ?? p.first;
|
|
252
|
+
}
|
|
253
|
+
// ---------------------------------------------------------------------------
|
|
254
|
+
// Reading
|
|
255
|
+
autoStart() {
|
|
256
|
+
this.cancelClock = null;
|
|
257
|
+
if (this.phase === "title" && this.prefs.autoStart && !this.manual())
|
|
258
|
+
this.startReading();
|
|
259
|
+
}
|
|
260
|
+
startReading() {
|
|
261
|
+
this.phase = "reading";
|
|
262
|
+
this.markReading(true);
|
|
263
|
+
this.render();
|
|
264
|
+
this.progress();
|
|
265
|
+
this.schedule();
|
|
266
|
+
}
|
|
267
|
+
markReading(on) {
|
|
268
|
+
const now = this.deps.now();
|
|
269
|
+
if (this.readingSince !== null)
|
|
270
|
+
this.readMs += now - this.readingSince;
|
|
271
|
+
this.readingSince = on ? now : null;
|
|
272
|
+
}
|
|
273
|
+
schedule() {
|
|
274
|
+
this.cancelClock?.();
|
|
275
|
+
this.cancelClock = null;
|
|
276
|
+
if (this.phase !== "reading" || this.manual())
|
|
277
|
+
return;
|
|
278
|
+
this.cancelClock = this.deps.later(() => this.advance(), this.doc.lineMs(this.line, this.speed(), this.prefs.beats));
|
|
279
|
+
}
|
|
280
|
+
advance() {
|
|
281
|
+
this.cancelClock = null;
|
|
282
|
+
const last = this.doc.parts[this.part].last;
|
|
283
|
+
const next = this.doc.nextReadable(this.line, last);
|
|
284
|
+
if (next === null)
|
|
285
|
+
return this.enterStop();
|
|
286
|
+
this.line = next;
|
|
287
|
+
this.render();
|
|
288
|
+
this.progress();
|
|
289
|
+
this.schedule();
|
|
290
|
+
}
|
|
291
|
+
step(delta) {
|
|
292
|
+
const part = this.doc.parts[this.part];
|
|
293
|
+
const rows = this.manual() ? Math.max(1, this.layout.rows - 1) : 1;
|
|
294
|
+
let line = this.line;
|
|
295
|
+
for (let i = 0; i < rows; i++) {
|
|
296
|
+
const next = delta > 0 ? this.doc.nextReadable(line, part.last) : this.doc.previousReadable(line, part.first);
|
|
297
|
+
if (next === null) {
|
|
298
|
+
if (delta > 0 && i === 0)
|
|
299
|
+
return this.enterStop();
|
|
300
|
+
break;
|
|
301
|
+
}
|
|
302
|
+
line = next;
|
|
303
|
+
}
|
|
304
|
+
if (line === this.line)
|
|
305
|
+
return;
|
|
306
|
+
this.line = line;
|
|
307
|
+
this.render();
|
|
308
|
+
this.progress();
|
|
309
|
+
this.schedule();
|
|
310
|
+
}
|
|
311
|
+
enterStop() {
|
|
312
|
+
this.cancelClock?.();
|
|
313
|
+
this.cancelClock = null;
|
|
314
|
+
this.markReading(false);
|
|
315
|
+
this.phase = "stop";
|
|
316
|
+
this.render();
|
|
317
|
+
this.emit({
|
|
318
|
+
type: "progress",
|
|
319
|
+
part: this.part,
|
|
320
|
+
section: this.doc.parts[this.part].stopSection,
|
|
321
|
+
percent: 100,
|
|
322
|
+
});
|
|
323
|
+
}
|
|
324
|
+
/** Read on into the next part, from its first line. */
|
|
325
|
+
continueReading() {
|
|
326
|
+
if (this.part >= this.doc.parts.length - 1)
|
|
327
|
+
return false;
|
|
328
|
+
this.part += 1;
|
|
329
|
+
this.line = this.firstLine(this.part);
|
|
330
|
+
this.startReading();
|
|
331
|
+
return true;
|
|
332
|
+
}
|
|
333
|
+
progress() {
|
|
334
|
+
this.emit({
|
|
335
|
+
type: "progress",
|
|
336
|
+
part: this.part,
|
|
337
|
+
section: this.doc.lines[this.line]?.section ?? 0,
|
|
338
|
+
percent: this.doc.percent(this.line),
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
pauseForAway() {
|
|
342
|
+
if (this.phase === "title") {
|
|
343
|
+
this.cancelClock?.();
|
|
344
|
+
this.cancelClock = null;
|
|
345
|
+
}
|
|
346
|
+
if (this.phase !== "reading" || this.manual())
|
|
347
|
+
return;
|
|
348
|
+
this.phase = "paused";
|
|
349
|
+
this.markReading(false);
|
|
350
|
+
this.schedule();
|
|
351
|
+
this.render();
|
|
352
|
+
}
|
|
353
|
+
changeSpeed(delta) {
|
|
354
|
+
const next = clampWpm(this.speed() + delta * READER_WPM.step);
|
|
355
|
+
if (next === this.speed())
|
|
356
|
+
return;
|
|
357
|
+
const ownSpeed = isWpm(this.prefs.appSpeed);
|
|
358
|
+
if (ownSpeed || !this.prefs.keep) {
|
|
359
|
+
this.readWpm = next;
|
|
360
|
+
this.toast(`${next} wpm\nfor this read`);
|
|
361
|
+
return;
|
|
362
|
+
}
|
|
363
|
+
this.prefs.wpm = next;
|
|
364
|
+
if (!this.bridged) {
|
|
365
|
+
sessionWpm.set(this.session, next);
|
|
366
|
+
this.toast(`${next} wpm`);
|
|
367
|
+
return;
|
|
368
|
+
}
|
|
369
|
+
this.toast(`${next} wpm\nsaved for every app`);
|
|
370
|
+
void this.session.settings.set("reading_wpm", next).catch(() => sessionWpm.set(this.session, next));
|
|
371
|
+
}
|
|
372
|
+
// ---------------------------------------------------------------------------
|
|
373
|
+
// Gestures
|
|
374
|
+
gesture(kind) {
|
|
375
|
+
if (!this.isOpenNow)
|
|
376
|
+
return;
|
|
377
|
+
const down = kind === "swipe_down" || kind === "dial_down" || kind === "scroll_down";
|
|
378
|
+
const up = kind === "swipe_up" || kind === "dial_up" || kind === "scroll_up";
|
|
379
|
+
if (kind === "double_tap")
|
|
380
|
+
return this.finish("double_tap");
|
|
381
|
+
if (kind === "swipe_left")
|
|
382
|
+
return this.finish("swipe_left");
|
|
383
|
+
if (kind === "long_press" || kind === "tap_then_hold") {
|
|
384
|
+
if (this.options.hold)
|
|
385
|
+
this.emit({ type: "action", action: this.options.hold.action });
|
|
386
|
+
return;
|
|
387
|
+
}
|
|
388
|
+
if (kind !== "single_tap" && !down && !up)
|
|
389
|
+
return;
|
|
390
|
+
switch (this.phase) {
|
|
391
|
+
case "title":
|
|
392
|
+
this.cancelClock?.();
|
|
393
|
+
this.cancelClock = null;
|
|
394
|
+
this.startReading();
|
|
395
|
+
if (down)
|
|
396
|
+
this.step(1);
|
|
397
|
+
return;
|
|
398
|
+
case "reading":
|
|
399
|
+
if (kind === "single_tap") {
|
|
400
|
+
if (this.manual())
|
|
401
|
+
return;
|
|
402
|
+
this.phase = "paused";
|
|
403
|
+
this.markReading(false);
|
|
404
|
+
this.schedule();
|
|
405
|
+
this.render();
|
|
406
|
+
return;
|
|
407
|
+
}
|
|
408
|
+
this.step(down ? 1 : -1);
|
|
409
|
+
return;
|
|
410
|
+
case "paused":
|
|
411
|
+
if (kind === "single_tap")
|
|
412
|
+
return this.startReading();
|
|
413
|
+
this.changeSpeed(down ? 1 : -1);
|
|
414
|
+
return;
|
|
415
|
+
case "stop": {
|
|
416
|
+
if (up) {
|
|
417
|
+
this.readOnWhenReady = false;
|
|
418
|
+
this.phase = this.manual() ? "reading" : "paused";
|
|
419
|
+
this.render();
|
|
420
|
+
return;
|
|
421
|
+
}
|
|
422
|
+
const tap = this.options.sections[this.doc.parts[this.part].stopSection]?.stop?.tap;
|
|
423
|
+
if (kind === "single_tap" && tap?.action)
|
|
424
|
+
return this.emit({ type: "action", action: tap.action });
|
|
425
|
+
if (!this.continueReading() && kind === "single_tap")
|
|
426
|
+
this.readOnWhenReady = true;
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
finish(reason) {
|
|
431
|
+
if (!this.isOpenNow)
|
|
432
|
+
return;
|
|
433
|
+
this.isOpenNow = false;
|
|
434
|
+
this.cancelClock?.();
|
|
435
|
+
this.cancelToast?.();
|
|
436
|
+
this.cancelClock = this.cancelToast = null;
|
|
437
|
+
for (const unsub of this.unsubs)
|
|
438
|
+
unsub();
|
|
439
|
+
this.unsubs = [];
|
|
440
|
+
void this.session.input.setClaimedGestures([], { scope: SCOPE }).catch(() => { });
|
|
441
|
+
this.emit({ type: "closed", reason });
|
|
442
|
+
}
|
|
443
|
+
// ---------------------------------------------------------------------------
|
|
444
|
+
// Drawing
|
|
445
|
+
statusTitle() {
|
|
446
|
+
const section = this.options.sections[this.doc.lines[this.line]?.section ?? 0];
|
|
447
|
+
return section?.status ?? this.options.title;
|
|
448
|
+
}
|
|
449
|
+
frame() {
|
|
450
|
+
const { rows, marked } = this.layout;
|
|
451
|
+
const base = { highlight: this.prefs.highlight, toast: this.toastText };
|
|
452
|
+
const wpm = this.speed();
|
|
453
|
+
switch (this.phase) {
|
|
454
|
+
case "title": {
|
|
455
|
+
const wrap = (text, max) => this.wrapper.wrap(text, {
|
|
456
|
+
maxWidthPx: this.layout.wrapWidthPx,
|
|
457
|
+
maxLines: max,
|
|
458
|
+
maxBytes: Infinity,
|
|
459
|
+
breakMode: "word",
|
|
460
|
+
}).lines;
|
|
461
|
+
const head = [
|
|
462
|
+
...wrap(this.options.title, rows >= 7 ? 3 : 2),
|
|
463
|
+
...(this.options.details ? wrap(this.options.details, 2) : []),
|
|
464
|
+
];
|
|
465
|
+
const auto = this.prefs.autoStart && !this.manual();
|
|
466
|
+
const hint = [
|
|
467
|
+
auto ? "Reader starts in 2 s" : this.manual() ? "Swipe to read by hand" : "Tap to start reading",
|
|
468
|
+
auto ? "tap to start now · swipe to read by hand" : "",
|
|
469
|
+
].filter(Boolean);
|
|
470
|
+
const lines = [...head.slice(0, Math.max(1, rows - hint.length - 1)), "", ...hint].slice(0, rows);
|
|
471
|
+
const minutes = Math.max(1, Math.round(this.doc.wordsLeft(this.firstLine(this.part)) / wpm));
|
|
472
|
+
const detail = this.manual() ? "swipe to read" : `about ${minutes} min at ${wpm} wpm`;
|
|
473
|
+
return { ...base, rows: lines, marked: null, status: this.options.title, detail };
|
|
474
|
+
}
|
|
475
|
+
case "stop": {
|
|
476
|
+
const part = this.doc.parts[this.part];
|
|
477
|
+
const stop = this.options.sections[part.stopSection]?.stop;
|
|
478
|
+
const last = this.part === this.doc.parts.length - 1;
|
|
479
|
+
const actions = [
|
|
480
|
+
stop?.title ?? (last ? "End" : "Paused here"),
|
|
481
|
+
...(stop?.tap ? [`tap ${stop.tap.label}`] : !last ? ["tap read on"] : []),
|
|
482
|
+
...(this.options.hold ? [`hold ${this.options.hold.label}`] : []),
|
|
483
|
+
`double tap ${this.options.leaveLabel ?? "back"}`,
|
|
484
|
+
].slice(0, rows);
|
|
485
|
+
const room = Math.max(0, rows - actions.length - 1);
|
|
486
|
+
const tail = [];
|
|
487
|
+
for (let i = part.last; i >= part.first && tail.length < room; i--) {
|
|
488
|
+
if (this.doc.lines[i].kind !== "blank")
|
|
489
|
+
tail.unshift(this.doc.lines[i].text);
|
|
490
|
+
}
|
|
491
|
+
const lines = tail.length ? [...tail, "", ...actions] : actions;
|
|
492
|
+
const status = last ? `Done · ${clock(this.readMs)} read` : this.statusTitle();
|
|
493
|
+
return {
|
|
494
|
+
...base,
|
|
495
|
+
rows: lines,
|
|
496
|
+
marked: null,
|
|
497
|
+
dimBefore: tail.length + (tail.length ? 1 : 0),
|
|
498
|
+
status,
|
|
499
|
+
detail: "100%",
|
|
500
|
+
};
|
|
501
|
+
}
|
|
502
|
+
default: {
|
|
503
|
+
const percent = this.doc.percent(this.line);
|
|
504
|
+
const lines = this.doc.rowsAround(this.line, marked, rows);
|
|
505
|
+
if (this.phase === "paused") {
|
|
506
|
+
return { ...base, rows: lines, marked, status: "Paused · tap to resume", detail: `${wpm} wpm · ${percent}%` };
|
|
507
|
+
}
|
|
508
|
+
const left = clock((this.doc.wordsLeft(this.line) * 60000) / wpm);
|
|
509
|
+
const detail = this.manual() ? "swipe to scroll" : `${wpm} wpm · ${left} left`;
|
|
510
|
+
return { ...base, rows: lines, marked, status: `${this.statusTitle()} · ${percent}%`, detail };
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
render() {
|
|
515
|
+
if (!this.isOpenNow || !this.doc)
|
|
516
|
+
return;
|
|
517
|
+
const elements = lensElements(this.layout, this.frame(), this.measurer);
|
|
518
|
+
const encoded = JSON.stringify(elements);
|
|
519
|
+
if (encoded === this.lastFrame)
|
|
520
|
+
return;
|
|
521
|
+
this.lastFrame = encoded;
|
|
522
|
+
void this.session.display.render(elements).catch(() => { });
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
//# sourceMappingURL=Reader.js.map
|