@mikuexe/annotator-effect 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 (83) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +263 -2
  3. package/dist/annotator.d.ts +5 -0
  4. package/dist/annotator.d.ts.map +1 -0
  5. package/dist/annotator.js +152 -0
  6. package/dist/annotator.js.map +1 -0
  7. package/dist/capture.d.ts +27 -0
  8. package/dist/capture.d.ts.map +1 -0
  9. package/dist/capture.js +186 -0
  10. package/dist/capture.js.map +1 -0
  11. package/dist/clipboard.d.ts +5 -0
  12. package/dist/clipboard.d.ts.map +1 -0
  13. package/dist/clipboard.js +35 -0
  14. package/dist/clipboard.js.map +1 -0
  15. package/dist/constants.d.ts +24 -0
  16. package/dist/constants.d.ts.map +1 -0
  17. package/dist/constants.js +24 -0
  18. package/dist/constants.js.map +1 -0
  19. package/dist/format.d.ts +9 -0
  20. package/dist/format.d.ts.map +1 -0
  21. package/dist/format.js +109 -0
  22. package/dist/format.js.map +1 -0
  23. package/dist/hotkey.d.ts +13 -0
  24. package/dist/hotkey.d.ts.map +1 -0
  25. package/dist/hotkey.js +54 -0
  26. package/dist/hotkey.js.map +1 -0
  27. package/dist/index.d.ts +8 -0
  28. package/dist/index.d.ts.map +1 -0
  29. package/dist/index.js +6 -0
  30. package/dist/index.js.map +1 -0
  31. package/dist/overlay/machine.d.ts +132 -0
  32. package/dist/overlay/machine.d.ts.map +1 -0
  33. package/dist/overlay/machine.js +236 -0
  34. package/dist/overlay/machine.js.map +1 -0
  35. package/dist/overlay/overlay.d.ts +26 -0
  36. package/dist/overlay/overlay.d.ts.map +1 -0
  37. package/dist/overlay/overlay.js +748 -0
  38. package/dist/overlay/overlay.js.map +1 -0
  39. package/dist/overlay/styles.d.ts +8 -0
  40. package/dist/overlay/styles.d.ts.map +1 -0
  41. package/dist/overlay/styles.js +386 -0
  42. package/dist/overlay/styles.js.map +1 -0
  43. package/dist/runtime/agent.d.ts +37 -0
  44. package/dist/runtime/agent.d.ts.map +1 -0
  45. package/dist/runtime/agent.js +142 -0
  46. package/dist/runtime/agent.js.map +1 -0
  47. package/dist/runtime/paths.d.ts +13 -0
  48. package/dist/runtime/paths.d.ts.map +1 -0
  49. package/dist/runtime/paths.js +64 -0
  50. package/dist/runtime/paths.js.map +1 -0
  51. package/dist/types.d.ts +106 -0
  52. package/dist/types.d.ts.map +1 -0
  53. package/dist/types.js +2 -0
  54. package/dist/types.js.map +1 -0
  55. package/dist/vite/analyze.d.ts +41 -0
  56. package/dist/vite/analyze.d.ts.map +1 -0
  57. package/dist/vite/analyze.js +324 -0
  58. package/dist/vite/analyze.js.map +1 -0
  59. package/dist/vite/ast.d.ts +38 -0
  60. package/dist/vite/ast.d.ts.map +1 -0
  61. package/dist/vite/ast.js +105 -0
  62. package/dist/vite/ast.js.map +1 -0
  63. package/dist/vite/index.d.ts +5 -0
  64. package/dist/vite/index.d.ts.map +1 -0
  65. package/dist/vite/index.js +3 -0
  66. package/dist/vite/index.js.map +1 -0
  67. package/dist/vite/plugin.d.ts +34 -0
  68. package/dist/vite/plugin.d.ts.map +1 -0
  69. package/dist/vite/plugin.js +181 -0
  70. package/dist/vite/plugin.js.map +1 -0
  71. package/dist/vite/scope.d.ts +39 -0
  72. package/dist/vite/scope.d.ts.map +1 -0
  73. package/dist/vite/scope.js +194 -0
  74. package/dist/vite/scope.js.map +1 -0
  75. package/dist/vite/tags.d.ts +5 -0
  76. package/dist/vite/tags.d.ts.map +1 -0
  77. package/dist/vite/tags.js +151 -0
  78. package/dist/vite/tags.js.map +1 -0
  79. package/dist/vite/transform.d.ts +39 -0
  80. package/dist/vite/transform.d.ts.map +1 -0
  81. package/dist/vite/transform.js +111 -0
  82. package/dist/vite/transform.js.map +1 -0
  83. package/package.json +107 -4
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 ExecMD
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,264 @@
1
- # Temporary Holding Version
1
+ # @mikuexe/annotator-effect
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
+ Effect UI devtool overlay for source-aware UI annotations. Pick live DOM elements, write notes, then copy an agent-ready Markdown or JSON prompt with the source location of each element.
4
+
5
+ This is the `effect/ui` counterpart of [@mikuexe/annotator-react](https://github.com/benjaminmodayil/annotator-react). The workflow, output and look are the same. Only source resolution differs: React fiber lookups find nothing in an Effect UI app, so this package reads Effect UI's own instance tree and adds source locations at dev time.
6
+
7
+ This package is personal tooling for a local-agent UI workflow. It is experimental and follows its maintainer's needs first. It credits [`@effect/ui-devtools`](https://effect.website), whose Pick tool showed how `BrowserHost.instanceAt` maps DOM nodes to component instances.
8
+
9
+ ## Install
10
+
11
+ Install it in the app as a dev dependency:
12
+
13
+ ```bash
14
+ pnpm add -D @mikuexe/annotator-effect
15
+ ```
16
+
17
+ To try unreleased changes, build a local checkout and link it instead:
18
+
19
+ ```bash
20
+ # in the annotator-effect checkout
21
+ pnpm install && pnpm build
22
+
23
+ # in the app
24
+ pnpm add -D link:../annotator-effect
25
+ ```
26
+
27
+ Peer dependencies:
28
+
29
+ - `effect` `~4.2.0`. The range stays on the 4.2 line on purpose: every `effect/ui` module is `@stability unstable`, the Vite plugin mirrors the 4.2 element vocabulary of `h` (`Html.containerTags`, `Html.voidTags`, the SVG tags), and the runtime uses 4.2 inspection APIs and the DevTools hook slot. A new minor version must be checked before the range moves.
30
+ - `vite` `^8.0.0`, for the Vite plugin. It parses TypeScript with Vite 8's `this.parse`.
31
+
32
+ Effect UI requires `strict` and `exactOptionalPropertyTypes` in `tsconfig.json`. Slots in effect/ui 4.2 fail to type-check under TypeScript 6.0.3 (TS2589) and pass under TypeScript 7.0.2.
33
+
34
+ ## Quick start
35
+
36
+ Add the Vite plugin. Nothing else is needed in `vite dev`:
37
+
38
+ ```ts
39
+ // vite.config.ts
40
+ import { annotatorEffect } from "@mikuexe/annotator-effect/vite";
41
+ import { defineConfig } from "vite";
42
+
43
+ export default defineConfig({
44
+ plugins: [annotatorEffect()],
45
+ });
46
+ ```
47
+
48
+ Run `vite dev`, press **Alt+A** (Option+A on macOS) or click **Annotate**, click an element, write a note, then click **Collect**. The prompt is on the clipboard.
49
+
50
+ Picking works like annotator-react:
51
+
52
+ - Hovering outlines the element and labels it with its component and call site.
53
+ - A click picks the element. The page does not receive the click or the press and release around it.
54
+ - Hold **Ctrl** (Windows and Linux) or **Cmd** (macOS) and click to add more elements to the same note.
55
+ - **Link element** on a saved annotation adds one more element to it.
56
+ - Pins mark saved annotations. Hover a pin to preview, edit or delete its note.
57
+ - **Escape** closes the open note, then the preview, then the session.
58
+ - Turning picking off with the hotkey or **Cancel** discards the session's annotations.
59
+
60
+ ### Plugin options
61
+
62
+ ```ts
63
+ type AnnotatorEffectPluginOptions = {
64
+ overlay?: boolean; // default true: inject the client that shows the overlay
65
+ hotkey?: string; // default "alt+a"
66
+ output?: "markdown" | "json" | "both"; // default "markdown"
67
+ position?: "bottom-right" | "bottom-left" | "top-right" | "top-left"; // default "bottom-right"
68
+ sourceRoot?: string; // reported paths are relative to this; default: Vite's root
69
+ };
70
+ ```
71
+
72
+ The plugin applies to `vite dev` only. `vite build`, `vite preview` and Vitest runs are untouched, so production output has no source attributes and no annotator code.
73
+
74
+ ### Runtime options and `onCollect`
75
+
76
+ The plugin's client calls `Annotator.start` before the app mounts. Call it again from the app to add options that are not serializable, such as `onCollect`. Load it behind `import.meta.env.DEV` so production builds drop it:
77
+
78
+ ```ts
79
+ // src/main.ts
80
+ if (import.meta.env.DEV) {
81
+ void import("@mikuexe/annotator-effect").then(({ Annotator }) => {
82
+ Annotator.start({
83
+ onCollect: (payload) => console.info("collected", payload),
84
+ });
85
+ });
86
+ }
87
+ ```
88
+
89
+ ```ts
90
+ type AnnotatorOptions = {
91
+ enabled?: boolean; // default: true when the plugin's dev client ran, false otherwise
92
+ hotkey?: string; // default "alt+a"
93
+ output?: "markdown" | "json" | "both"; // default "markdown"
94
+ position?: "bottom-right" | "bottom-left" | "top-right" | "top-left";
95
+ target?: Document | HTMLIFrameElement | null; // default: document
96
+ onCollect?: (payload: AnnotationCollection) => void; // after the clipboard write succeeds
97
+ };
98
+ ```
99
+
100
+ The runtime is a no-op outside dev: without the plugin's client, `Annotator.start` and `Annotator.layer` do nothing unless you pass `enabled: true`. That is the opt-in for a build that should keep the annotator.
101
+
102
+ ### Setting it up in code with `Annotator.layer`
103
+
104
+ Use the layer when the page does not come from Vite's `index.html` (for example, server-rendered HTML), or to keep the setup in the entry module. Pass `annotatorEffect({ overlay: false })` to keep source attributes and the registry without the injected client.
105
+
106
+ ```ts
107
+ import { Annotator } from "@mikuexe/annotator-effect";
108
+ import { Effect, Layer } from "effect";
109
+ import { BrowserHost } from "effect/ui/html";
110
+
111
+ BrowserHost.mount(App, {}, document.getElementById("app")!).pipe(
112
+ Layer.provide(Annotator.layer({ enabled: import.meta.env.DEV })),
113
+ Layer.launch,
114
+ Effect.runFork
115
+ );
116
+ ```
117
+
118
+ The layer provides a numbering `MessageLog` and `BrowserHost.Controllables` to the mount and keeps the overlay mounted while it is built. It reads what it receives: an enabled `MessageLog` passes through, and roots register with the incoming `Controllables` too. To use it with `DevTools.layer`, provide DevTools to the annotator layer, not beside it: `Annotator.layer().pipe(Layer.provide(DevTools.layer()))`. Two layers merged side by side both provide `MessageLog`, and only one wins.
119
+
120
+ ### Same-origin iframes
121
+
122
+ Pass a same-origin iframe as `target` when the annotator runs in a parent shell and the app runs in the frame. The framed page needs the plugin too: its client registers the frame's roots, and the parent asks it to hide its own overlay. Highlights, pins and popovers are offset into the parent viewport. See `examples/basic/shell.html`.
123
+
124
+ ## Output
125
+
126
+ Markdown by default. Fields with no data are left out. A real example from `examples/basic`:
127
+
128
+ ```text
129
+ Please update the UI based on these source-linked annotations.
130
+
131
+ Collected at: 2026-12-03T00:41:48.179Z
132
+ Domain: 127.0.0.1
133
+ Path: /
134
+
135
+ ## Annotation 1
136
+
137
+ ID: 8399ca58-1b7e-4d61-8da9-607c4a2270d9
138
+ Note: Rename this card heading to Inbox.
139
+ Source: src/components/Card.ts:6:37 (element call site)
140
+ Nearest Effect UI component: App
141
+ Effect UI instance path: /App
142
+ Component definitions:
143
+ - App: src/App.ts:14:20
144
+ Element tag: h2
145
+ Element HTML: <h2 class="card-title">Notes</h2>
146
+ Element text: Notes
147
+ Selector: #app main.shell section.card:nth-of-type(1) h2.card-title
148
+
149
+ ## Annotation 2
150
+
151
+ ID: f0ce5162-57e2-44c2-a334-30fd3a676759
152
+ Note: Add a placeholder to the draft input.
153
+ Source: src/App.ts:61:40 (element call site)
154
+ Nearest Effect UI component: Field
155
+ Effect UI owner path: Field › App
156
+ Effect UI instance path: /App/Field[draft]
157
+ Component definitions:
158
+ - Field (definition not recorded: library or untransformed module)
159
+ - App: src/App.ts:14:20
160
+ Element tag: input
161
+ Element HTML: <input class="field-input" data-valid="" id="_1b_App_1b_Field_2j_draft_2l_-control">
162
+ Selector: #_1b_App_1b_Field_2j_draft_2l_-control
163
+ ```
164
+
165
+ `output: "json"` copies the payload as JSON, and `"both"` appends it to the Markdown under `## JSON Payload`. The payload holds data only, never DOM references:
166
+
167
+ ```ts
168
+ type SourceLocation = {
169
+ filePath: string;
170
+ lineNumber: number | null; // 1-based
171
+ columnNumber: number | null; // 1-based
172
+ };
173
+
174
+ type AnnotationSource = SourceLocation & {
175
+ componentName: string | null;
176
+ kind: "element" | "ancestor-element" | "component-definition";
177
+ };
178
+
179
+ type ComponentFrame = {
180
+ componentName: string;
181
+ definitions: SourceLocation[]; // 0: not recorded, 1: exact, 2 or more: shared name
182
+ };
183
+
184
+ type AnnotationTarget = {
185
+ source: AnnotationSource | null;
186
+ componentPath: string[]; // owning component first, root last
187
+ instancePath: string | null; // such as "/App/NoteList[notes]"
188
+ componentStack: ComponentFrame[]; // one per componentPath entry
189
+ element: { tagName: string; text: string; html: string; selector: string };
190
+ };
191
+
192
+ type AnnotationCollection = {
193
+ createdAt: string;
194
+ page: { domain: string; path: string };
195
+ annotations: Array<{ id: string; note: string; targets: AnnotationTarget[] }>;
196
+ };
197
+ ```
198
+
199
+ ## How source resolution works
200
+
201
+ Effect UI records no source locations, so three layers each add part of the answer. Each one degrades on its own.
202
+
203
+ | Layer | Gives | How | Precision |
204
+ | ----------------------------- | -------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------- |
205
+ | A. Component lookup | The owning component, its owner path and the instance path | `BrowserHost.instanceAt` over every mounted root. The client takes effect/ui's DevTools hook slot before the app mounts, so each root registers itself and instances are numbered | Exact instance. Slot content belongs to the component that passed it; kit parts belong to the kit component (for example `/App/Field[draft]`) |
206
+ | B. Element call sites | `file:line:col` of the builder that made the element | The Vite plugin adds `data-effect-ui-source` to element builders in view code | Exact line and column of `h.<tag>`, `h.el(…)` or, for a kit component that draws its own element, of the kit call |
207
+ | C. Component definition sites | `file:line:col` of each owner's `Html.component(…)` / `Component.define(…)` call | The Vite plugin registers each definition by name in a virtual-module registry; the overlay looks names up | Exact for unique names. A name several components share is listed with every site and gives no single `Source` |
208
+
209
+ `Source` is the most precise answer available: the picked element's own call site, then the nearest ancestor's call site when the same instance rendered it, then the owning component's definition.
210
+
211
+ ### What the Vite plugin transforms
212
+
213
+ It parses each module that imports `effect/ui` with Vite's parser, finds the `h` helpers in scope and rewrites only their element builders:
214
+
215
+ - `view` in `X.make({ view })`, `Def.view(fn)` and `Def.fragment(fn)`, whatever the first parameter is called (`h`, `ui`, `html`).
216
+ - Parameters typed `Html.H<M>` or `View.Helper<…>` from `effect/ui`, so helpers in other modules are covered.
217
+ - Local functions called with `h` (followed to a fixed point) and `h.lazy(fn, …)`.
218
+ - Nested chains, list rows, slot content and builders handed to kit parts, such as `parts.root(h.button)` or `field.control(h.input)`.
219
+ - A call that receives `h` and that the plugin cannot see into, such as a kit component or an imported untyped helper, gets its call site on the builder it returns, unless that builder already has one.
220
+
221
+ `h.div.class(…)` becomes `h.div.attr("data-effect-ui-source", "src/App.ts:12:7").class(…)`. The call form `h.p("text")` becomes `h.p.attr(…).children("text")`, because `.attr` turns the callable shorthand into a plain builder. A bare `h.div` handed on keeps its callable shape through a runtime helper. Positions are taken from the original file; when an earlier plugin changed the code, they are traced back through its source map.
222
+
223
+ These forms are skipped and fall back to layers A and C: computed members (`h["div"]`), optional calls (`h.div?.(…)`), destructured helpers (`({ div }) => …`), aliases (`const x = h`), and helpers typed with an app-level alias of `Html.H`.
224
+
225
+ ## Coexisting with @effect/ui-devtools
226
+
227
+ Both tools can run at once. effect/ui's development build reads one window slot, `Symbol.for("effect/ui/devtools")`, when a root mounts, and `DevTools.attach` writes that slot. The annotator turns the slot into an accessor that keeps a DevTools hook written before or after it, registers every root with both, and forwards DevTools' `takeOver` to the DevTools hook. The DevTools launcher also starts at the bottom right, so give the annotator another corner:
228
+
229
+ ```ts
230
+ plugins: [annotatorEffect({ position: "bottom-left" }), DevToolsVite.plugin()];
231
+ ```
232
+
233
+ ## Why the overlay is plain DOM
234
+
235
+ The overlay renders plain DOM in an open shadow root, driven by an explicit state machine (`src/overlay/machine.ts`). An `effect/ui` overlay was the first choice, but every `effect/ui` mount in the page's window registers with the DevTools hook (`BrowserHost.mountRoot` reads it through `html/internal/hotOn.ts`). An `effect/ui` overlay would then show in the DevTools timeline, in its Pick tool and in this package's own root list. DevTools avoids that by mounting in an iframe, but an iframe cannot draw outlines and pins across the page while passing clicks through everywhere else. The shadow root keeps page styles out, and the overlay is never part of any root.
236
+
237
+ ## Limitations
238
+
239
+ - Development only by design; production builds carry nothing unless the app opts in.
240
+ - Layer A needs the plugin's client (or `Annotator.layer`) to run before the app mounts. Roots mounted earlier are not found.
241
+ - `BrowserHost.defineElement` roots do not register with `Controllables`, so custom elements get layers B and C only. Picking reaches inside open shadow roots; a closed shadow root picks its host.
242
+ - `effect` must resolve to one copy. Two copies keep two instance registries, and layer A finds nothing.
243
+ - Kit and library components are not in the registry, since `node_modules` is not transformed. Their frames say so.
244
+ - When another top-layer tool, such as an open DevTools panel, covers the overlay, the overlay raises itself again on each status change; a tool that raises itself later can still cover it.
245
+ - A modal dialog opened with `showModal()` makes the rest of the page inert, which can include the overlay's buttons.
246
+ - Collect needs clipboard permission; it falls back to a hidden textarea and `execCommand("copy")`, and shows a failure in the panel and a toast.
247
+
248
+ ## Local example
249
+
250
+ ```bash
251
+ pnpm install
252
+ pnpm build
253
+ pnpm example:dev
254
+ ```
255
+
256
+ `examples/basic` has components with a renamed `h`, a helper function that takes `h`, a slotted `Collapsible`, kit `Switch` and `Field` parts, and the DevTools overlay beside the annotator. `/shell.html` annotates the same app through an iframe.
257
+
258
+ ## Development
259
+
260
+ ```bash
261
+ pnpm run check:ci # tests, typecheck, lint, build, example build, production-build guard, publint
262
+ ```
263
+
264
+ TypeScript 7.0.2 (installed as `typescript-native`) typechecks and builds. TypeScript 6.0.3 stays installed as the engine of typescript-eslint, which does not support 7 yet. Use `pnpm changeset` for user-facing changes.
@@ -0,0 +1,5 @@
1
+ import type { AnnotatorApi } from "./types.js";
2
+ /** Whether the Vite plugin's development client ran in this window. */
3
+ export declare function isDevClientActive(): boolean;
4
+ export declare const Annotator: AnnotatorApi;
5
+ //# sourceMappingURL=annotator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"annotator.d.ts","sourceRoot":"","sources":["../src/annotator.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EACV,YAAY,EAGb,MAAM,YAAY,CAAC;AAsBpB,uEAAuE;AACvE,wBAAgB,iBAAiB,IAAI,OAAO,CAI3C;AA4KD,eAAO,MAAM,SAAS,EAAE,YAA+B,CAAC"}
@@ -0,0 +1,152 @@
1
+ import { Context, Effect, Layer } from "effect";
2
+ import * as BrowserHost from "effect/ui/html/BrowserHost";
3
+ import * as MessageLog from "effect/ui/MessageLog";
4
+ import { DEFAULT_HOTKEY, DEV_CLIENT_KEY, FRAME_TARGET_ATTRIBUTE, } from "./constants.js";
5
+ import { mountOverlay } from "./overlay/overlay.js";
6
+ import { getAgent, numberingLog, readAgent } from "./runtime/agent.js";
7
+ const RUNNING_KEY = Symbol.for("@mikuexe/annotator-effect/running");
8
+ const noopHandle = {
9
+ update: () => undefined,
10
+ stop: () => undefined,
11
+ };
12
+ /** Whether the Vite plugin's development client ran in this window. */
13
+ export function isDevClientActive() {
14
+ return (globalThis[DEV_CLIENT_KEY] === true);
15
+ }
16
+ function isEnabled(options) {
17
+ return options.enabled ?? isDevClientActive();
18
+ }
19
+ function runningSlot() {
20
+ const slots = globalThis;
21
+ slots[RUNNING_KEY] ??= {};
22
+ return slots[RUNNING_KEY];
23
+ }
24
+ function settingsOf(options) {
25
+ return {
26
+ hotkey: options.hotkey ?? DEFAULT_HOTKEY,
27
+ output: options.output ?? "markdown",
28
+ position: options.position ?? "bottom-right",
29
+ target: options.target ?? null,
30
+ onCollect: options.onCollect,
31
+ };
32
+ }
33
+ function mergeOptions(current, next) {
34
+ const merged = { ...current };
35
+ for (const [key, value] of Object.entries(next)) {
36
+ if (value !== undefined) {
37
+ merged[key] = value;
38
+ }
39
+ }
40
+ return merged;
41
+ }
42
+ // A page framed by an annotating parent leaves the overlay to the parent.
43
+ function isAnnotatedByParent() {
44
+ try {
45
+ return (window.frameElement?.hasAttribute(FRAME_TARGET_ATTRIBUTE) === true ||
46
+ getAgent().isOverlaySuppressed());
47
+ }
48
+ catch {
49
+ return false;
50
+ }
51
+ }
52
+ function createRunning(options) {
53
+ const record = {
54
+ options,
55
+ overlay: undefined,
56
+ claims: 0,
57
+ };
58
+ const mount = () => {
59
+ if (record.overlay || record.claims === 0 || isAnnotatedByParent()) {
60
+ return;
61
+ }
62
+ record.overlay = mountOverlay(document, settingsOf(record.options), (view) => (view === window ? getAgent() : (readAgent(view) ?? null)));
63
+ };
64
+ const unsubscribe = getAgent().onSuppressOverlay(() => {
65
+ record.overlay?.destroy();
66
+ record.overlay = undefined;
67
+ });
68
+ return Object.assign(record, { mount, unsubscribe });
69
+ }
70
+ function mountWhenReady(mount) {
71
+ if (document.body) {
72
+ mount();
73
+ }
74
+ else {
75
+ document.addEventListener("DOMContentLoaded", mount, { once: true });
76
+ }
77
+ }
78
+ /** Claims the overlay and returns the claim's handle. */
79
+ function claimOverlay(options) {
80
+ const slot = runningSlot();
81
+ const running = slot.running ?? createRunning(options);
82
+ slot.running = running;
83
+ if (running.claims > 0) {
84
+ running.options = mergeOptions(running.options, options);
85
+ running.overlay?.update(settingsOf(running.options));
86
+ }
87
+ running.claims += 1;
88
+ mountWhenReady(running.mount);
89
+ let released = false;
90
+ return {
91
+ update: (next) => {
92
+ running.options = mergeOptions(running.options, next);
93
+ running.overlay?.update(settingsOf(running.options));
94
+ },
95
+ stop: () => {
96
+ if (released) {
97
+ return;
98
+ }
99
+ released = true;
100
+ running.claims -= 1;
101
+ if (running.claims > 0) {
102
+ return;
103
+ }
104
+ running.overlay?.destroy();
105
+ running.overlay = undefined;
106
+ running.unsubscribe();
107
+ if (slot.running === running) {
108
+ delete slot.running;
109
+ }
110
+ },
111
+ };
112
+ }
113
+ function start(options = {}) {
114
+ if (!isEnabled(options) || typeof document === "undefined") {
115
+ return noopHandle;
116
+ }
117
+ getAgent().installHook();
118
+ return claimOverlay(options);
119
+ }
120
+ function combineControllables(first, second) {
121
+ if (first === second) {
122
+ return first;
123
+ }
124
+ return {
125
+ register: (root) => {
126
+ const unregisterFirst = first.register(root);
127
+ const unregisterSecond = second.register(root);
128
+ return () => {
129
+ unregisterSecond();
130
+ unregisterFirst();
131
+ };
132
+ },
133
+ };
134
+ }
135
+ function layer(options = {}) {
136
+ return Layer.effectContext(Effect.gen(function* () {
137
+ if (!isEnabled(options) || typeof document === "undefined") {
138
+ return Context.empty();
139
+ }
140
+ // What the layer receives, such as `DevTools.layer` provided below it,
141
+ // keeps working: an enabled log passes through, and roots register
142
+ // with both registries.
143
+ const incomingLog = yield* MessageLog.MessageLog;
144
+ const incomingControllables = yield* BrowserHost.Controllables;
145
+ const agent = getAgent();
146
+ const handle = claimOverlay(options);
147
+ yield* Effect.addFinalizer(() => Effect.sync(handle.stop));
148
+ return Context.make(MessageLog.MessageLog, incomingLog.enabled ? incomingLog : numberingLog).pipe(Context.add(BrowserHost.Controllables, combineControllables(incomingControllables, agent.controllables)));
149
+ }));
150
+ }
151
+ export const Annotator = { start, layer };
152
+ //# sourceMappingURL=annotator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"annotator.js","sourceRoot":"","sources":["../src/annotator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AAChD,OAAO,KAAK,WAAW,MAAM,4BAA4B,CAAC;AAC1D,OAAO,KAAK,UAAU,MAAM,sBAAsB,CAAC;AAEnD,OAAO,EACL,cAAc,EACd,cAAc,EACd,sBAAsB,GACvB,MAAM,gB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K,WAAW,EAAE,CAAC;YAC3D,OAAO,OAAO,CAAC,KAAK,EAAE,CAAC;QACzB,CAAC;QAED,uEAAuE;QACvE,mEAAmE;QACnE,wBAAwB;QACxB,MAAM,WAAW,GAAG,KAAK,CAAC,CAAC,UAAU,CAAC,UAAU,CAAC;QACjD,MAAM,qBAAqB,GAAG,KAAK,CAAC,CAAC,WAAW,CAAC,aAAa,CAAC;QAC/D,MAAM,KAAK,GAAG,QAAQ,EAAE,CAAC;QACzB,MAAM,MAAM,GAAG,YAAY,CAAC,OAAO,CAAC,CAAC;QACrC,KAAK,CAAC,CAAC,MAAM,CAAC,YAAY,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;QAE3D,OAAO,OAAO,CAAC,IAAI,CACjB,UAAU,CAAC,UAAU,EACrB,WAAW,CAAC,OAAO,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,YAAY,CACjD,CAAC,IAAI,CACJ,OAAO,CAAC,GAAG,CACT,WAAW,CAAC,aAAa,EACzB,oBAAoB,CAAC,qBAAqB,EAAE,KAAK,CAAC,aAAa,CAAC,CACjE,CACF,CAAC;IACJ,CAAC,CAAC,CACH,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,MAAM,SAAS,GAAiB,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC"}
@@ -0,0 +1,27 @@
1
+ import type { AnnotationTarget, SourceLocation } from "./types.js";
2
+ /** The effect/ui instance that owns a node (resolution layer A). */
3
+ export type ComponentOwner = {
4
+ /** The instance number its `MessageLog` entries carry. */
5
+ instance: number;
6
+ path: string;
7
+ component: string;
8
+ /** The path of the mounted root the instance belongs to. */
9
+ rootPath: string;
10
+ };
11
+ /**
12
+ * What capture asks of the runtime. Both lookups may be missing: capture
13
+ * then keeps what the DOM alone can tell.
14
+ */
15
+ export type SourceResolver = {
16
+ /** Layer A: the owning instance of a node, if a registered root owns it. */
17
+ ownerOf: (node: Node) => ComponentOwner | undefined;
18
+ /** Layer C: definition sites recorded for a component name. */
19
+ definitionsOf: (componentName: string) => SourceLocation[];
20
+ };
21
+ export declare function captureAnnotationTarget(element: Element, resolver?: SourceResolver | null): AnnotationTarget;
22
+ export declare function createAnnotationId(): string;
23
+ /** Parses `<file>:<line>:<column>`, reading the numbers from the right. */
24
+ export declare function parseSourceAttribute(value: string | null): SourceLocation | null;
25
+ export declare function getElementSelector(element: Element): string;
26
+ export declare function trimText(value: string, maxLength: number): string;
27
+ //# sourceMappingURL=capture.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"capture.d.ts","sourceRoot":"","sources":["../src/capture.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAEV,gBAAgB,EAEhB,cAAc,EACf,MAAM,YAAY,CAAC;AASpB,oEAAoE;AACpE,MAAM,MAAM,cAAc,GAAG;IAC3B,0DAA0D;IAC1D,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,4DAA4D;IAC5D,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,cAAc,GAAG;IAC3B,4EAA4E;IAC5E,OAAO,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,cAAc,GAAG,SAAS,CAAC;IACpD,+DAA+D;IAC/D,aAAa,EAAE,CAAC,aAAa,EAAE,MAAM,KAAK,cAAc,EAAE,CAAC;CAC5D,CAAC;AAEF,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,OAAO,EAChB,QAAQ,GAAE,cAAc,GAAG,IAAW,GACrC,gBAAgB,CAsBlB;AAED,wBAAgB,kBAAkB,IAAI,MAAM,CAM3C;AAED,2EAA2E;AAC3E,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,MAAM,GAAG,IAAI,GACnB,cAAc,GAAG,IAAI,CAevB;AAED,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,CAkB3D;AAED,wBAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CAQjE"}