@heypointerhq/sdk 0.0.0-stage → 0.2.1

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,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/NOTICE ADDED
@@ -0,0 +1,5 @@
1
+ HeyPointer
2
+ Copyright 2026 HeyPointer contributors
3
+
4
+ This product includes software developed by the HeyPointer contributors
5
+ (https://github.com/heypointer/heypointer).
package/README.md CHANGED
@@ -1,3 +1,132 @@
1
- # Temporary Holding Version
1
+ # @heypointerhq/sdk
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
+ The in-app guide. It turns a typed or spoken goal into a coachmark walkthrough of the host page: the page dims, a spotlight cuts out the real control, and a tooltip anchored to it shows `2 / 5`, a short instruction, **Skip** and **Next**. It only guides. It never clicks, types into or submits host elements.
4
+
5
+ One engine (this package) serves every web framework. The framework packages only manage lifecycle.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ npm install @heypointerhq/sdk
11
+ ```
12
+
13
+ ```ts
14
+ import { HeyPointer } from "@heypointerhq/sdk"; // ESM, types included, CSS compiled in: no Tailwind plugin needed
15
+ import { defineHeyPointerElement } from "@heypointerhq/sdk/element"; // registers <heypointer-assistant> when you call it
16
+ ```
17
+
18
+ For a plain `<script>` tag, copy `node_modules/@heypointerhq/sdk/dist/heypointer.global.js` (export `@heypointerhq/sdk/global`) to your static files. Version 0.2.1. Install it with `npm install @heypointerhq/sdk`. See [docs/PACKAGES.md](../../docs/PACKAGES.md).
19
+
20
+ ## Add it to an app
21
+
22
+ **Script tag** (any web app, no build step):
23
+
24
+ ```html
25
+ <script src="https://your-cdn/heypointer.global.js" data-base-url="https://your-heypointer-server" data-client-id="hpc_..." defer></script>
26
+ ```
27
+
28
+ **Global component** (any framework that can render a custom element):
29
+
30
+ ```html
31
+ <heypointer-assistant base-url="https://your-heypointer-server" client-id="hpc_..."></heypointer-assistant>
32
+ ```
33
+
34
+ Attributes: `base-url` (required), `client-id` (required in practice), `target-timeout-ms`, `assist`, and the customization attributes `labels`, `theme`, `color-scheme`, `dir`, `lang`, `launcher`, `launcher-side` (see [Customizing](#customizing)). Changing `base-url`, `client-id`, `assist` or `target-timeout-ms` remounts; the customization attributes update in place; removing the element destroys the guide. `element.open()`, `element.close()` and `element.ask(goal)` drive it; `element.player` is the live `HeyPointer`.
35
+
36
+ **From code:**
37
+
38
+ ```ts
39
+ import { HeyPointer } from "@heypointerhq/sdk";
40
+ const gf = new HeyPointer({ baseUrl: "http://localhost:8791", clientId: "hpc_..." });
41
+ ```
42
+
43
+ Options: `baseUrl`, `clientId`, `fetch`, `recorderFactory`, `speechSupported`, `targetTimeoutMs` (default 1500), `mountTo`, `assist`, `onAssist`, `labels`, `theme`, `colorScheme`, `dir`, `lang`, `launcher`, `launcherSide`. Methods: `open()`, `close()`, `ask(goal)`, `next()`, `prev()`, `setLabels()`, `setTheme()`, `setColorScheme()`, `setLayout()`, `destroy()`. Events (bubbling, composed, on the guide's root): `heypointer:open`, `heypointer:close`, `heypointer:assist`.
44
+
45
+ ### Client ID
46
+
47
+ The server only answers guide requests that carry a client id, sent as the `X-HeyPointer-Client` header on `POST /api/walkthrough`. You get one from `heypointer init`. It looks like `hpc_` plus 24 hex characters and is **public**, like a Stripe publishable key: it is fine in page source, and the server limits it with allowed origins and rate limits. Never put the server API key in an app.
48
+
49
+ An id that is clearly malformed is rejected in the browser without a request. A missing or unknown id, a page origin the client does not allow, and rate limiting each show a plain message in the guide (never the raw server response). Transcription requests do not carry the id.
50
+
51
+ Build the script-tag bundle with `npm run build -w packages/sdk`: `dist/heypointer.global.js`, about 57 kB (16.4 kB gzip) with the compiled CSS included. Without `data-base-url` it only registers the element and exposes the `HeyPointer` class as `window.HeyPointerGlobal.HeyPointer`.
52
+
53
+ ## Frameworks and platforms
54
+
55
+ | Platform | Package | Status |
56
+ |---|---|---|
57
+ | Plain HTML, any web app | `heypointer.global.js`, `<heypointer-assistant>` | Verified in a real browser: Chromium, Firefox, WebKit |
58
+ | React, Next.js | [`@heypointerhq/react`](../react/README.md) | Verified in jsdom with the real player, incl. server render. Not tested in a real Next.js app. |
59
+ | Vue, Nuxt | [`@heypointerhq/vue`](../vue/README.md) | Verified in jsdom with the real player, incl. server render. Not tested in a real Nuxt app. |
60
+ | Angular | none | Not built. The element should work with `CUSTOM_ELEMENTS_SCHEMA`; untested. |
61
+ | Svelte, SvelteKit | none | Not built. Untested. |
62
+ | Android (native views) | [`packages/android`](../android/README.md) | Prototype. Verified in one app on an Android 14 emulator, including rotation, Back and the accessibility tree. Not Jetpack Compose, tablets or TalkBack speech. |
63
+ | iOS, React Native, Flutter | none | Not built. Native apps have no DOM, so the CSS-selector targets cannot be reused: each platform needs its own renderer and a resolver over accessibility identifiers or semantics labels. Do not describe these as supported. |
64
+
65
+ Importing the SDK in Node (server rendering) is safe and tested: nothing touches the DOM at import time.
66
+
67
+ ## Behavior
68
+
69
+ - **Server calls:** `POST /api/walkthrough {goal, context:{url}}` and `POST /api/transcribe` (raw audio body).
70
+ - **Validation:** responses are checked client-side. A step with no evidence, an unknown action, or `insufficient_evidence` carrying steps is rejected and shown as an error.
71
+ - **Target resolution:** selectors, then role+text, then label, then text. Hidden elements are skipped. Several matches are reported as ambiguous ("I won't guess", no highlight, Try again / Skip). If a target appears late (route change, dialog), it waits up to `targetTimeoutMs`. A missing target shows an alert with "Try again"; the user can still go Back or Next.
72
+ - **Did you mean:** when the server answers `insufficient_evidence` with `suggestions` (up to 5 `{workflowId, title}`, contract 1.5.0), the message is followed by a "Did you mean:" group of buttons. Choosing one asks the server for that title as the goal. Titles are untrusted: rendered with `textContent`, trimmed, dropped if longer than 200 characters or duplicated, and the list is capped at 5; malformed entries are dropped without failing the reply, and suggestions on an `ok` walkthrough are ignored. The buttons are native buttons (Tab and Enter or Space work), grouped under the "Did you mean:" label, and the choices are announced in the live region. Unit-tested in jsdom against fake responses; the server does not produce suggestions yet.
73
+ - **Confirmation gate:** steps the server marks `requiresConfirmation`, and any click that looks like send, submit, delete, remove, pay, purchase, buy, transfer, publish, revoke or deploy, are not highlighted and cannot be advanced until the user ticks the confirmation box.
74
+ - **When the control goes away:** the guide watches the highlighted control. If it is removed, hidden (`display: none`, `hidden`, `visibility: hidden`, a closed `<dialog>`, `content-visibility`), made inert or collapsed to nothing, because the user acted, the highlight, the dimmer and the arrow are dropped and the card says "It looks like you did that. Press Next to continue." It then waits for Next; nothing advances on its own and assist mode clicks nothing. If the control comes back (the modal is reopened) the highlight returns. If the host app only swaps the node for an identical one in the same container, the guide follows it. It never moves onto a matching control elsewhere on the page. Cost: one `MutationObserver` on the document (visibility-related attributes and child lists), at most one check per frame after a relevant change, and a one-second follow-up only while a transition or animation that contains the control is running; it stops when the guide closes or is destroyed.
75
+ - **Coachmark:** the tooltip is placed below, above, right or left of the target, clamped to the viewport, and on narrow screens (600px or less) below or above full width. A `ResizeObserver` and scroll listeners keep the cutout and ring on the target after resize and scroll.
76
+ - **Audio:** the Speak button appears only when `getUserMedia` and `MediaRecorder` exist. Denied mic, or a server without transcription (501), shows a message and keeps the typed input.
77
+ - **Accessibility:** the UI is a Shadow DOM `role="dialog"`. Step changes go to an `aria-live` region and move focus to the step title. Escape closes. The highlight and dimmer are `aria-hidden` and ignore pointer events, so the user performs the action on the real control. Motion respects `prefers-reduced-motion`.
78
+ - **Host apps:** a modal dialog in the host makes the guide panel inert. Use non-modal dialogs for flows you want guided.
79
+
80
+ ## Assist mode
81
+
82
+ By default the guide never acts: it highlights and the user clicks. The goal card (and the goal tools inside the coachmark) has a checkbox, **Assist: do safe clicks for me when I press Next**, off by default. With it on, pressing Next performs the step's click for the user, and says so (`Clicked "Search" for you.`). It is opt-in per session (kept in memory only); host apps can start it on with `assist: true`, the `assist` attribute, `data-assist` on the script tag, or the React/Vue `assist` prop.
83
+
84
+ The guide clicks only when **all** of these hold, and otherwise Next just advances as before:
85
+
86
+ - the step is a `click` and is not gated (`requiresConfirmation` or a consequential label such as buy, delete, pay, send, place order);
87
+ - the target resolves to exactly one visible element, the one that is highlighted (never a guess);
88
+ - it is not disabled, `aria-disabled`, `inert`, a file input, or part of the guide itself;
89
+ - it is not a link that leaves the page (another origin, `target=_blank`, `download`, `mailto:`, `javascript:`);
90
+ - nobody has already clicked it since the step was shown (so a toggle such as "Add to favourites" is never undone), and the guide has not already clicked that step once.
91
+
92
+ It never types text, never chooses an option, and steps it will not do show "You need to do this one yourself." After a click the guide waits for the page to stop changing, then looks for the next control; if it does not appear the usual "I can't find it" recovery shows and the card still says what was clicked. If the click itself throws, the card says so and the step stays put; the guide never retries on its own.
93
+
94
+ Audit trail: the `onAssist({ stepIndex, action: 'click', label })` option and a `heypointer:assist` `CustomEvent` (bubbles, composed, same `detail`) fire once per assisted click, so a host app can log it.
95
+
96
+ ## Record steps (author mode)
97
+
98
+ Click through your app once and get a flow draft: `author: true` (or `data-author`, or `?heypointer-author=1` when the host sets `allowAuthorParam`) shows a small panel that records the controls you use, never what you type, and writes the Markdown `heypointer flows import` and `heypointer scan` read. It loads as its own file (`heypointer.author.js`, or `@heypointerhq/sdk/author`), so pages that do not ask for it never download it. See [docs/AUTHORING.md](../../docs/AUTHORING.md).
99
+
100
+ ## Customizing
101
+
102
+ Labels (every string, so translation is configuration), theme (colors, radius, font as `--hp-*` CSS variables or a validated `theme` option, with dark-scheme counterparts and a forced `colorScheme`), stable `::part()` names, right-to-left, and a hideable launcher with `open()`/`close()` for your own button. Full reference, with the rules for what a value may contain and the Android equivalents: [docs/CUSTOMIZING.md](../../docs/CUSTOMIZING.md).
103
+
104
+ ```html
105
+ <heypointer-assistant base-url="..." client-id="hpc_..."
106
+ labels='{"next":"Weiter","stepProgress":"Schritt {current} von {total}"}'
107
+ theme='{"accent":"#6d28d9","accentFg":"#ffffff","dark":{"accent":"#a78bfa","accentFg":"#1e1b4b"}}'></heypointer-assistant>
108
+ ```
109
+
110
+ ```css
111
+ [data-heypointer-root]::part(button-primary) { border-radius: 4px; }
112
+ ```
113
+
114
+ Label and theme values are validated: plain text only, CSS colors, lengths and font lists only, so neither can inject HTML or CSS. In development builds (tests, source imports) a rejected value logs one `console.warn`; the shipped bundles are silent.
115
+
116
+ ## Styling
117
+
118
+ `src/styles.css` is Tailwind CSS v4 (theme and utilities, no preflight) compiled into the shadow root, so nothing leaks into or out of the host page except the documented hooks: the `--hp-*` custom properties and the `::part()` names. The internal `--color-hp-*` tokens are private and read the public variables with a default. The build pins a modern CSS target (Chrome 100, Safari 15.4, Firefox 100) so logical properties stay as written; an older target rewrites them into `:lang()` fallbacks that follow the language instead of the text direction. Tailwind seeds some utility variables with `@property`, which browsers ignore inside a shadow root, so `:host` sets those defaults itself; an E2E test checks the highlight ring really computes to a solid border.
119
+
120
+ The built package (`dist/`, the script-tag bundle, and the React and Vue wrappers) has the CSS compiled in, so consuming apps need no Tailwind setup. Only building this repo's SDK from source needs `@tailwindcss/vite`, because the stylesheet is imported with `?inline`.
121
+
122
+ ## Test
123
+
124
+ `npm test -w packages/sdk` (vitest + jsdom, includes a Node-only import test). Browser behavior is covered by an end-to-end suite that is not part of this repository.
125
+
126
+ ## Limits
127
+
128
+ Only the web DOM is supported. Real microphone capture is untested. Targets inside iframes or other shadow roots are not resolved. Browser coverage is Chromium, Firefox and WebKit on the shop and global-bundle specs, Chromium elsewhere.
129
+
130
+ ---
131
+
132
+ [Website](https://heypointer.com/) · [Docs](https://heypointer.com/docs/) · [X](https://x.com/heypointer) · [Instagram](https://www.instagram.com/heypointer/) · Support: [Buy Me a Coffee](https://buymeacoffee.com/heypointer) · [Ko-fi](https://ko-fi.com/heypointer)
@@ -0,0 +1,53 @@
1
+ import type { StepKind } from './draft';
2
+ export interface Captured {
3
+ kind: StepKind;
4
+ label: string;
5
+ sensitive: boolean;
6
+ pageData: boolean;
7
+ context: string;
8
+ el: HTMLElement;
9
+ }
10
+ export interface CaptureOptions {
11
+ isRecording(): boolean;
12
+ /** True for events that came from the author panel itself. */
13
+ isOwn(path: EventTarget[]): boolean;
14
+ recordRows(): boolean;
15
+ /** Programmatic events (a script clicking for the user, the guide's own Assist) are not recordings. Tests may opt in. */
16
+ acceptUntrusted: boolean;
17
+ onStep(c: Captured): void;
18
+ onPage(path: string): void;
19
+ }
20
+ /**
21
+ * Watches the page the way a person uses it and reports controls, never values. It reads the accessible name of what was
22
+ * clicked, typed into or changed, and nothing else: no `value`, no field contents, no URL beyond the route.
23
+ */
24
+ export declare class Capture {
25
+ private readonly o;
26
+ private docs;
27
+ private lastKey;
28
+ private lastAt;
29
+ private lastTyped;
30
+ private lastPath;
31
+ private timer;
32
+ private observer;
33
+ private readonly frameLoads;
34
+ constructor(o: CaptureOptions);
35
+ start(): void;
36
+ stop(): void;
37
+ /** A full page load or a route change while recording becomes one informational note. */
38
+ checkRoute(): void;
39
+ /** Called when recording starts or resumes, so a route change while paused is not reported as a step's consequence. */
40
+ syncRoute(): void;
41
+ private scanFrames;
42
+ private attachFrame;
43
+ private attach;
44
+ private detach;
45
+ private accept;
46
+ private emit;
47
+ private control;
48
+ private onClick;
49
+ private onInput;
50
+ private onChange;
51
+ /** Enter in a field submits the form without a click on the button: record the button the person would have pressed. */
52
+ private onSubmit;
53
+ }
@@ -0,0 +1,81 @@
1
+ export type StepKind = 'click' | 'type' | 'select';
2
+ export type Status = {
3
+ kind: 'unique';
4
+ } | {
5
+ kind: 'ambiguous';
6
+ count: number;
7
+ } | {
8
+ kind: 'noname';
9
+ } | {
10
+ kind: 'notfound';
11
+ } | {
12
+ kind: 'unchecked';
13
+ };
14
+ export interface StepEntry {
15
+ t: 'step';
16
+ id: number;
17
+ kind: StepKind;
18
+ /** The sentence as it will be written, without the consequential suffix (that is added when rendering). */
19
+ text: string;
20
+ /** The author asked for a confirmation gate. A label such as "Buy now" gets one regardless. */
21
+ consequential: boolean;
22
+ status: Status;
23
+ pageData: boolean;
24
+ sensitive: boolean;
25
+ /** The nearest landmark's name at the time of recording, offered as "Add context". */
26
+ context: string;
27
+ }
28
+ export interface NoteEntry {
29
+ t: 'note';
30
+ id: number;
31
+ text: string;
32
+ }
33
+ export type Entry = StepEntry | NoteEntry;
34
+ export interface Draft {
35
+ title: string;
36
+ entries: Entry[];
37
+ }
38
+ /** The step sentence for a recorded control. The label never carries a double quote and never exceeds MAX_LABEL. */
39
+ export declare function sentenceFor(kind: StepKind, label: string): string;
40
+ export declare const stepsOf: (d: Draft) => StepEntry[];
41
+ export declare const hasGate: (s: StepEntry) => boolean;
42
+ /** The Markdown file, exactly as `heypointer generate flow` would write it. Notes become one plain paragraph. */
43
+ export declare function toMarkdown(d: Draft): string;
44
+ export declare const problems: (d: Draft, titleMessage: string) => string[];
45
+ export declare const fileName: (d: Draft) => string;
46
+ type Listener = () => void;
47
+ /** The draft plus the small operations the panel and the capture code need. Holds no DOM and no values. */
48
+ export declare class DraftStore {
49
+ draft: Draft;
50
+ private nextId;
51
+ private listeners;
52
+ constructor(initial?: Draft);
53
+ subscribe(fn: Listener): () => void;
54
+ private emit;
55
+ get stepCount(): number;
56
+ get full(): boolean;
57
+ setTitle(title: string): void;
58
+ addStep(s: Omit<StepEntry, 't' | 'id'>): StepEntry | null;
59
+ addNote(text: string): void;
60
+ find(id: number): Entry | undefined;
61
+ /** The author edited a step's sentence. The status goes stale and is set again by the caller. */
62
+ editText(id: number, text: string, quiet?: boolean): StepEntry | null;
63
+ setStatus(id: number, status: Status, pageData?: boolean): void;
64
+ toggleConsequential(id: number): void;
65
+ move(id: number, delta: -1 | 1): void;
66
+ remove(id: number): void;
67
+ /** Remove the newest step and any notes after it. */
68
+ undo(): boolean;
69
+ clear(): void;
70
+ }
71
+ export declare const ACTIVE_KEY = "heypointer:author:active:v1";
72
+ export interface Persisted {
73
+ draft: Draft;
74
+ recording: boolean;
75
+ }
76
+ /** A stored draft, or null. Anything that does not look exactly like a draft is dropped. */
77
+ export declare function loadPersisted(storage: Storage | null): Persisted | null;
78
+ export declare function savePersisted(storage: Storage | null, p: Persisted): void;
79
+ export declare function clearPersisted(storage: Storage | null): void;
80
+ export declare function sessionStore(): Storage | null;
81
+ export {};
@@ -0,0 +1,31 @@
1
+ /**
2
+ * The PRD-format Markdown `heypointer scan` reads. These helpers mirror the scanner's authoring rules
3
+ * (the scanner cannot ship in a browser bundle); an internal test renders the same drafts through
4
+ * the real scanner and fails if the two ever disagree.
5
+ */
6
+ export declare const MAX_STEPS = 100;
7
+ /** A whole step sentence. Longer text is cut when recording and refused when edited. */
8
+ export declare const MAX_STEP_TEXT = 120;
9
+ /** The longest control label a recorded step quotes. */
10
+ export declare const MAX_LABEL = 72;
11
+ export declare const isConsequentialLabel: (text: string | undefined) => boolean;
12
+ /** Control characters out, whitespace collapsed. */
13
+ export declare const clean: (s: string) => string;
14
+ /** A label goes between double quotes in a sentence, so it cannot contain them. */
15
+ export declare const forQuotes: (s: string) => string;
16
+ export declare const slug: (s: string) => string;
17
+ /** What the scanner treats as the step's target: the first quoted phrase. */
18
+ export declare const quotedLabel: (text: string) => string;
19
+ export declare function stepSentence(text: string, consequential?: boolean): string;
20
+ export interface FlowText {
21
+ title: string;
22
+ steps: string[];
23
+ }
24
+ export declare function renderFlow(flow: FlowText, opts?: {
25
+ consequential?: Set<number>;
26
+ note?: string;
27
+ }): string;
28
+ /** What the scanner would complain about, found without the scanner. Empty means usable. */
29
+ export declare function problemsOf(flow: FlowText, titleMessage: string): string[];
30
+ /** Route segments that look like record ids are not part of the page name. */
31
+ export declare function routeName(pathname: string): string;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,49 @@
1
+ import { type ColorScheme, type HeyPointerTheme } from '../theme';
2
+ import { type Draft, type Status } from './draft';
3
+ import { type AuthorLabels } from './labels';
4
+ import { type Mode } from './panel';
5
+ export { AUTHOR_LABELS, type AuthorLabels, type AuthorLabelKey } from './labels';
6
+ export { MAX_STEPS, MAX_STEP_TEXT, MAX_LABEL, renderFlow, stepSentence, slug } from './flow';
7
+ export type { Draft, Entry, StepEntry, NoteEntry, Status } from './draft';
8
+ export interface AuthorOptions {
9
+ /** The same `labels` object the guide takes; author mode reads the keys that start with `author`. */
10
+ labels?: AuthorLabels | Record<string, unknown>;
11
+ theme?: HeyPointerTheme;
12
+ colorScheme?: ColorScheme;
13
+ dir?: 'auto' | 'ltr' | 'rtl';
14
+ lang?: string;
15
+ mountTo?: HTMLElement;
16
+ /** Start with this flow title. */
17
+ title?: string;
18
+ /** Start recording at once instead of waiting for Record. */
19
+ autoRecord?: boolean;
20
+ /** Also record clicks on table rows and cells. They usually contain page data, so this is off. */
21
+ recordRows?: boolean;
22
+ /** Keep the draft in sessionStorage so a flow that spans page loads survives them. On by default. */
23
+ persist?: boolean;
24
+ /** Tests: where to keep the draft. */
25
+ storage?: Storage | null;
26
+ /** Tests and automation: also record events a script dispatched. Off, so the guide's own Assist clicks are never recorded. */
27
+ acceptUntrusted?: boolean;
28
+ /** Called after every change to the draft. */
29
+ onChange?: (draft: Draft) => void;
30
+ }
31
+ export interface AuthorSession {
32
+ /** End the session: stop recording, remove the panel and forget the stored draft. */
33
+ stop(): void;
34
+ getDraft(): Draft;
35
+ toMarkdown(): string;
36
+ pause(): void;
37
+ resume(): void;
38
+ readonly mode: Mode;
39
+ }
40
+ /** Classify a control name with the SAME resolver the guide uses at run time. */
41
+ export declare function classify(label: string, el?: Element): Status;
42
+ /**
43
+ * Turn on author mode: a panel records what a person does in the app (clicks, fields they fill, choices they make) and
44
+ * writes it as a flow draft in the PRD Markdown `heypointer scan` reads. It records control labels, never typed values.
45
+ * Calling this is the explicit opt-in; nothing here is sent over the network.
46
+ */
47
+ export declare function startAuthoring(opts?: AuthorOptions): AuthorSession;
48
+ /** Was author mode left running by an earlier page of this session? Used to resume it after a full page load. */
49
+ export declare function authorWasActive(storage?: Storage | null): boolean;
@@ -0,0 +1,73 @@
1
+ /**
2
+ * Everything author mode shows. Same rules as the guide's labels: plain text with `{placeholder}`
3
+ * substitution, applied with textContent only. Hosts pass them in the same `labels` object, with the
4
+ * `author` prefix (`labels: { authorRecord: 'Aufnehmen' }`). The commands in the follow-up are code and stay as they are.
5
+ */
6
+ export declare const AUTHOR_LABELS: {
7
+ readonly authorDialogName: "HeyPointer author mode";
8
+ readonly authorTitle: "Record steps";
9
+ readonly authorMinimize: "Minimize";
10
+ readonly authorClose: "Close author mode";
11
+ readonly authorMove: "Move the panel to the other side";
12
+ readonly authorSteps: "Steps ({count})";
13
+ readonly authorAbout: "Privacy and shortcuts";
14
+ readonly authorExpand: "Expand";
15
+ readonly authorFlowTitle: "Flow title";
16
+ readonly authorFlowTitlePlaceholder: "e.g. Add a product to the cart";
17
+ readonly authorRecord: "Record";
18
+ readonly authorPause: "Pause";
19
+ readonly authorResume: "Resume";
20
+ readonly authorStop: "Stop and review";
21
+ readonly authorUndo: "Undo last step";
22
+ readonly authorRows: "Record clicks on table rows and cells (they usually contain page data)";
23
+ readonly authorStatusIdle: "Not recording. Press Record, then use your app the way a person would.";
24
+ readonly authorStatusRecording: "Recording. {count} steps so far.";
25
+ readonly authorStatusPaused: "Paused. {count} steps so far.";
26
+ readonly authorStatusReview: "Review the draft. Nothing is sent anywhere.";
27
+ readonly authorEmpty: "No steps yet. Click, type or choose something in your app.";
28
+ readonly authorStepText: "Step {n} text";
29
+ readonly authorMoveUp: "Move step {n} up";
30
+ readonly authorMoveDown: "Move step {n} down";
31
+ readonly authorDelete: "Delete step {n}";
32
+ readonly authorDeleteNote: "Delete note";
33
+ readonly authorConsequential: "Needs confirmation";
34
+ readonly authorConsequentialAuto: "Needs confirmation (added automatically because of the label)";
35
+ readonly authorChipUnique: "Unique control";
36
+ readonly authorChipAmbiguous: "Ambiguous: {count} matches";
37
+ readonly authorChipNoName: "No accessible name";
38
+ readonly authorChipPageData: "Contains page data";
39
+ readonly authorChipNotFound: "Not found by the guide";
40
+ readonly authorChipUnchecked: "Not on this page";
41
+ readonly authorChipSensitive: "Sensitive field";
42
+ readonly authorHintAmbiguous: "The guide will not guess between {count} controls. Give this one an aria-label or visible text that is unique.";
43
+ readonly authorHintNoName: "Add an aria-label or visible text so the guide can find this control.";
44
+ readonly authorHintPageData: "This text looks like data from the page (a name, an email or a number). Change it so it names the control, not the data.";
45
+ readonly authorHintNotFound: "The guide would not find a control with this exact text. Check the text, or give the control a role and a label.";
46
+ readonly authorHintUnchecked: "This control is not on the current page, so it was not checked.";
47
+ readonly authorHintSensitive: "Only the field label is recorded. What is typed here is never captured.";
48
+ readonly authorAddContext: "Add context ({context})";
49
+ readonly authorRecheck: "Re-check all";
50
+ readonly authorNote: "Now on {path}";
51
+ readonly authorPreview: "Preview";
52
+ readonly authorProblems: "Fix these before copying:";
53
+ readonly authorTitleRequired: "Give the flow a title.";
54
+ readonly authorCopy: "Copy Markdown";
55
+ readonly authorCopied: "Copied to the clipboard.";
56
+ readonly authorCopyFailed: "Could not copy. Select the text and copy it yourself.";
57
+ readonly authorDownload: "Download {file}";
58
+ readonly authorKeepRecording: "Keep recording";
59
+ readonly authorDiscard: "Discard draft";
60
+ readonly authorDiscardConfirm: "Discard this draft? The recorded steps are lost.";
61
+ readonly authorNextHeading: "Then, from your project folder:";
62
+ readonly authorPrivacy: "Nothing leaves this page. Typed values are never recorded, but control labels can contain page data, so read every step before you share it.";
63
+ readonly authorLimit: "You reached {max} steps, the most one flow can have. Stop and review.";
64
+ readonly authorShortcut: "Alt+Shift+G moves focus to this panel.";
65
+ };
66
+ export type AuthorLabelKey = keyof typeof AUTHOR_LABELS;
67
+ export type AuthorLabels = {
68
+ [K in AuthorLabelKey]?: string;
69
+ };
70
+ export type ResolvedAuthorLabels = Record<AuthorLabelKey, string>;
71
+ /** Defaults with the host's `author*` overrides on top. Anything invalid is ignored (and reported in development builds). */
72
+ export declare function resolveAuthorLabels(input: unknown): ResolvedAuthorLabels;
73
+ export declare const authorText: (labels: ResolvedAuthorLabels, key: AuthorLabelKey, vars?: Record<string, string | number>) => string;