deictic 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.
- package/LICENSE +21 -0
- package/README.md +143 -2
- package/dist/annotations/client.d.ts +4 -0
- package/dist/annotations/client.d.ts.map +1 -0
- package/dist/annotations/client.js +497 -0
- package/dist/annotations/client.js.map +1 -0
- package/dist/annotations/index.d.ts +110 -0
- package/dist/annotations/index.d.ts.map +1 -0
- package/dist/annotations/index.js +22 -0
- package/dist/annotations/index.js.map +1 -0
- package/dist/astro.d.ts +29 -0
- package/dist/astro.d.ts.map +1 -0
- package/dist/astro.js +24 -0
- package/dist/astro.js.map +1 -0
- package/dist/bun.d.ts +12 -0
- package/dist/bun.d.ts.map +1 -0
- package/dist/bun.js +67 -0
- package/dist/bun.js.map +1 -0
- package/dist/client/index.d.ts +93 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +1329 -0
- package/dist/client/index.js.map +1 -0
- package/dist/endpoints.js +354 -0
- package/dist/endpoints.js.map +1 -0
- package/dist/index.d.ts +220 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -0
- package/dist/index2.d.ts +23 -0
- package/dist/index3.d.ts +98 -0
- package/dist/index3.d.ts.map +1 -0
- package/dist/index4.d.ts +74 -0
- package/dist/index4.d.ts.map +1 -0
- package/dist/index5.d.ts +70 -0
- package/dist/index5.d.ts.map +1 -0
- package/dist/integration.d.ts +19 -0
- package/dist/integration.d.ts.map +1 -0
- package/dist/integration.js +277 -0
- package/dist/integration.js.map +1 -0
- package/dist/kept.js +23 -0
- package/dist/kept.js.map +1 -0
- package/dist/loader.d.ts +15 -0
- package/dist/loader.d.ts.map +1 -0
- package/dist/loader.js +17 -0
- package/dist/loader.js.map +1 -0
- package/dist/marks.js +14 -0
- package/dist/marks.js.map +1 -0
- package/dist/next.d.ts +17 -0
- package/dist/next.d.ts.map +1 -0
- package/dist/next.js +150 -0
- package/dist/next.js.map +1 -0
- package/dist/playwright.js +105 -0
- package/dist/playwright.js.map +1 -0
- package/dist/recommended/index.d.ts +25 -0
- package/dist/recommended/index.d.ts.map +1 -0
- package/dist/recommended/index.js +19 -0
- package/dist/recommended/index.js.map +1 -0
- package/dist/recordings/client.d.ts +4 -0
- package/dist/recordings/client.d.ts.map +1 -0
- package/dist/recordings/client.js +376 -0
- package/dist/recordings/client.js.map +1 -0
- package/dist/recordings/index.d.ts +2 -0
- package/dist/recordings/index.js +3 -0
- package/dist/recordings.js +235 -0
- package/dist/recordings.js.map +1 -0
- package/dist/screenshots/client.d.ts +23 -0
- package/dist/screenshots/client.d.ts.map +1 -0
- package/dist/screenshots/client.js +76 -0
- package/dist/screenshots/client.js.map +1 -0
- package/dist/screenshots/dom.d.ts +4 -0
- package/dist/screenshots/dom.d.ts.map +1 -0
- package/dist/screenshots/dom.js +92 -0
- package/dist/screenshots/dom.js.map +1 -0
- package/dist/screenshots/index.d.ts +2 -0
- package/dist/screenshots/index.js +98 -0
- package/dist/screenshots/index.js.map +1 -0
- package/dist/screenshots/rrweb.d.ts +9 -0
- package/dist/screenshots/rrweb.d.ts.map +1 -0
- package/dist/screenshots/rrweb.js +60 -0
- package/dist/screenshots/rrweb.js.map +1 -0
- package/dist/shortcut.js +63 -0
- package/dist/shortcut.js.map +1 -0
- package/dist/tailwind/client.d.ts +4 -0
- package/dist/tailwind/client.d.ts.map +1 -0
- package/dist/tailwind/client.js +613 -0
- package/dist/tailwind/client.js.map +1 -0
- package/dist/tailwind/index.d.ts +2 -0
- package/dist/tailwind/index.js +557 -0
- package/dist/tailwind/index.js.map +1 -0
- package/dist/tasks/client.d.ts +6 -0
- package/dist/tasks/client.d.ts.map +1 -0
- package/dist/tasks/client.js +642 -0
- package/dist/tasks/client.js.map +1 -0
- package/dist/tasks/index.d.ts +159 -0
- package/dist/tasks/index.d.ts.map +1 -0
- package/dist/tasks/index.js +348 -0
- package/dist/tasks/index.js.map +1 -0
- package/dist/vite.d.ts +17 -0
- package/dist/vite.d.ts.map +1 -0
- package/dist/vite.js +44 -0
- package/dist/vite.js.map +1 -0
- package/dist/voice/client.d.ts +4 -0
- package/dist/voice/client.d.ts.map +1 -0
- package/dist/voice/client.js +66 -0
- package/dist/voice/client.js.map +1 -0
- package/dist/voice/index.d.ts +47 -0
- package/dist/voice/index.d.ts.map +1 -0
- package/dist/voice/index.js +74 -0
- package/dist/voice/index.js.map +1 -0
- package/dist/waveform.js +93 -0
- package/dist/waveform.js.map +1 -0
- package/dist/webpack.d.ts +50 -0
- package/dist/webpack.d.ts.map +1 -0
- package/dist/webpack.js +78 -0
- package/dist/webpack.js.map +1 -0
- package/package.json +313 -4
- package/skills/deictic/SKILL.md +47 -0
- package/skills/deictic/references/install.md +81 -0
- package/skills/deictic/references/recordings.md +83 -0
- package/skills/deictic/references/tasks.md +79 -0
- package/skills/deictic/references/watch.md +43 -0
- package/skills/deictic/scripts/frame.mjs +62 -0
- package/skills/deictic/scripts/lib.mjs +193 -0
- package/skills/deictic/scripts/recording.mjs +186 -0
- package/skills/deictic/scripts/task.mjs +84 -0
- package/skills/deictic/scripts/transcribe.mjs +93 -0
- package/skills/deictic/scripts/voice.mjs +50 -0
- package/skills/deictic/scripts/watch.mjs +51 -0
- package/src/astro.ts +34 -0
- package/src/bun.ts +79 -0
- package/src/client/index.ts +833 -0
- package/src/client/lightbox.ts +256 -0
- package/src/client/style.ts +243 -0
- package/src/client/tooltip.ts +78 -0
- package/src/client/waveform.ts +98 -0
- package/src/index.ts +240 -0
- package/src/loader.ts +28 -0
- package/src/next.ts +133 -0
- package/src/plugins/annotations/client.ts +301 -0
- package/src/plugins/annotations/draw.ts +169 -0
- package/src/plugins/annotations/index.ts +105 -0
- package/src/plugins/annotations/svg.ts +61 -0
- package/src/plugins/recommended/index.ts +35 -0
- package/src/plugins/recordings/client.ts +315 -0
- package/src/plugins/recordings/index.ts +174 -0
- package/src/plugins/recordings/marks.ts +11 -0
- package/src/plugins/recordings/ours.ts +70 -0
- package/src/plugins/recordings/replay.ts +139 -0
- package/src/plugins/screenshots/client.ts +63 -0
- package/src/plugins/screenshots/dom.ts +79 -0
- package/src/plugins/screenshots/index.ts +194 -0
- package/src/plugins/screenshots/playwright.ts +119 -0
- package/src/plugins/screenshots/rrweb.ts +45 -0
- package/src/plugins/tailwind/catalog.ts +396 -0
- package/src/plugins/tailwind/client.ts +669 -0
- package/src/plugins/tailwind/index.ts +267 -0
- package/src/plugins/tasks/client.ts +622 -0
- package/src/plugins/tasks/index.ts +513 -0
- package/src/plugins/voice/client.ts +57 -0
- package/src/plugins/voice/index.ts +114 -0
- package/src/shortcut.ts +83 -0
- package/src/tools/astro.ts +81 -0
- package/src/tools/editor.ts +22 -0
- package/src/tools/endpoints.ts +163 -0
- package/src/tools/history.ts +203 -0
- package/src/tools/integration.ts +106 -0
- package/src/tools/kept.ts +21 -0
- package/src/tools/locate.ts +94 -0
- package/src/tools/plugins.ts +41 -0
- package/src/tools/source.ts +72 -0
- package/src/vite.ts +62 -0
- package/src/webpack.ts +107 -0
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { dirname, isAbsolute, join, relative } from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
import { i as ownShortcut, n as checkShortcuts, t as OWN$1 } from "./shortcut.js";
|
|
5
|
+
import { createRequire } from "node:module";
|
|
6
|
+
import MagicString from "magic-string";
|
|
7
|
+
import { Visitor, parseSync } from "oxc-parser";
|
|
8
|
+
import { t as keptIn } from "./kept.js";
|
|
9
|
+
// src/tools/locate.ts
|
|
10
|
+
/**
|
|
11
|
+
* Marks each host element in a JSX module with where its opening tag starts:
|
|
12
|
+
* `<div data-deictic="src/App.tsx:12:5">`. The page reads it back to know what was clicked.
|
|
13
|
+
*
|
|
14
|
+
* At build time and not from React's fibers at runtime: it works for any framework that compiles JSX,
|
|
15
|
+
* for server components (which have no fiber in the browser), and it names the element's own tag
|
|
16
|
+
* rather than the component that rendered it. Only host elements (`div`, `button`) are marked, since a
|
|
17
|
+
* component may not pass the attribute on; a component's call site is reached from its elements.
|
|
18
|
+
*
|
|
19
|
+
* The transform must run on the source as written (`enforce: 'pre'` under Vite), so lines and columns
|
|
20
|
+
* are the file's. It runs alike on the server and in the browser, so a hydrated page matches its HTML.
|
|
21
|
+
*/
|
|
22
|
+
const ATTRIBUTE = "data-deictic";
|
|
23
|
+
/** Modules that may hold JSX: `.jsx` and `.tsx`, and plain `.js`, as many React projects write theirs. */
|
|
24
|
+
const JSX = /\.[cm]?(?:[jt]sx|js)$/;
|
|
25
|
+
/** A module parsed, with JSX read in a `.js` file too, which the parser reads there only when told. */
|
|
26
|
+
const parse = (file, code) => parseSync(file, code, /\.[cm]?js$/.test(file) ? { lang: "jsx" } : void 0);
|
|
27
|
+
/** Whether an opening tag is a host element's, `<div>` or `<svg>`, not a component's or a namespaced one. */
|
|
28
|
+
const isHost = (el) => el.name.type === "JSXIdentifier" && /^[a-z]/.test(el.name.name);
|
|
29
|
+
/**
|
|
30
|
+
* `code` with every host element marked, `file` being its path from the project's root, and `append`
|
|
31
|
+
* after it (the client's import, in the browser); nothing when there is nothing to mark, or the module
|
|
32
|
+
* doesn't parse, which the framework's own transform reports better.
|
|
33
|
+
*/
|
|
34
|
+
function locate(code, file, append = "") {
|
|
35
|
+
if (!/<[a-z]/.test(code)) return void 0;
|
|
36
|
+
const { program, errors } = parse(file, code);
|
|
37
|
+
if (errors.length > 0) return void 0;
|
|
38
|
+
return marked(code, file, openingsIn(program), append);
|
|
39
|
+
}
|
|
40
|
+
/** Every opening tag in a module, in its order. */
|
|
41
|
+
function openingsIn(program) {
|
|
42
|
+
const elements = [];
|
|
43
|
+
new Visitor({ JSXOpeningElement: (el) => void elements.push(el) }).visit(program);
|
|
44
|
+
return elements;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* `code` with a mark in each of `elements` that is a host element's and has none yet, and `append` after
|
|
48
|
+
* it; nothing with none to mark.
|
|
49
|
+
*/
|
|
50
|
+
function marked(code, file, elements, append = "") {
|
|
51
|
+
const lines = lineStarts(code);
|
|
52
|
+
const s = new MagicString(code);
|
|
53
|
+
for (const el of elements) {
|
|
54
|
+
if (!isHost(el) || el.attributes.some((a) => a.type === "JSXAttribute" && nameOf(a.name) === "data-deictic")) continue;
|
|
55
|
+
const { line, column } = position(lines, el.start);
|
|
56
|
+
s.appendLeft(el.name.end, ` ${ATTRIBUTE}="${file}:${line}:${column}"`);
|
|
57
|
+
}
|
|
58
|
+
if (!s.hasChanged()) return void 0;
|
|
59
|
+
if (append !== "") s.append(append);
|
|
60
|
+
return {
|
|
61
|
+
code: s.toString(),
|
|
62
|
+
map: s.generateMap({
|
|
63
|
+
source: file.slice(file.lastIndexOf("/") + 1),
|
|
64
|
+
hires: "boundary"
|
|
65
|
+
})
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
const nameOf = (name) => name.type === "JSXIdentifier" ? name.name : void 0;
|
|
69
|
+
/** Where each line starts, by offset. */
|
|
70
|
+
function lineStarts(code) {
|
|
71
|
+
const starts = [0];
|
|
72
|
+
for (let i = code.indexOf("\n"); i !== -1; i = code.indexOf("\n", i + 1)) starts.push(i + 1);
|
|
73
|
+
return starts;
|
|
74
|
+
}
|
|
75
|
+
/** An offset's line and column, from 1. */
|
|
76
|
+
function position(lines, offset) {
|
|
77
|
+
let lo = 0;
|
|
78
|
+
let hi = lines.length - 1;
|
|
79
|
+
while (lo < hi) {
|
|
80
|
+
const mid = lo + hi + 1 >> 1;
|
|
81
|
+
if (lines[mid] <= offset) lo = mid;
|
|
82
|
+
else hi = mid - 1;
|
|
83
|
+
}
|
|
84
|
+
return {
|
|
85
|
+
line: lo + 1,
|
|
86
|
+
column: offset - lines[lo] + 1
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
/** A line and column's offset, or nothing past the file's end. */
|
|
90
|
+
function offsetOf(lines, line, column) {
|
|
91
|
+
const start = lines[line - 1];
|
|
92
|
+
return start === void 0 ? void 0 : start + column - 1;
|
|
93
|
+
}
|
|
94
|
+
// src/tools/astro.ts
|
|
95
|
+
/**
|
|
96
|
+
* `.astro` components. They aren't JSX modules, but Astro 7's own parser reads a template as JSX, into the
|
|
97
|
+
* tree oxc makes (offsets in UTF-16, as ours are), so its host elements are marked as a JSX module's are,
|
|
98
|
+
* before Astro compiles the file. The parser is the project's own Astro's (`@astrojs/compiler-rs`, found
|
|
99
|
+
* through `astro`), so it reads a file exactly as the compiler will; an Astro before 7 has none like it,
|
|
100
|
+
* and its `.astro` files are left unmarked.
|
|
101
|
+
*/
|
|
102
|
+
const ASTRO = /\.astro$/;
|
|
103
|
+
const parsers = /* @__PURE__ */ new Map();
|
|
104
|
+
/** The parser of the Astro installed for the project at `root`, loaded once; nothing without Astro 7. */
|
|
105
|
+
function parserOf(root) {
|
|
106
|
+
if (!parsers.has(root)) parsers.set(root, load(root));
|
|
107
|
+
return parsers.get(root);
|
|
108
|
+
}
|
|
109
|
+
function load(root) {
|
|
110
|
+
try {
|
|
111
|
+
return createRequire(createRequire(join(root, "package.json")).resolve("astro/package.json"))("@astrojs/compiler-rs").parse;
|
|
112
|
+
} catch {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Astro gives a `<script>` or `<style>` with an attribute it doesn't know to the page as it is, unbundled and
|
|
118
|
+
* unscoped, and a `<slot>` isn't an element at all: none of them can be pointed at, so none is marked.
|
|
119
|
+
*/
|
|
120
|
+
const OWN = /* @__PURE__ */ new Set([
|
|
121
|
+
"script",
|
|
122
|
+
"style",
|
|
123
|
+
"slot"
|
|
124
|
+
]);
|
|
125
|
+
const isOpening = (node) => "type" in node && node.type === "JSXOpeningElement";
|
|
126
|
+
/** An `.astro` file's text parsed, or the `problem` with it: no parser (an older Astro), or text that doesn't parse. */
|
|
127
|
+
function parseAstro(root, code) {
|
|
128
|
+
const parse = parserOf(root);
|
|
129
|
+
if (parse === void 0) return { problem: "reading an .astro file takes Astro 7 or later, so update astro" };
|
|
130
|
+
const { ast, diagnostics } = parse(code);
|
|
131
|
+
const error = diagnostics.find((d) => d.severity === "error");
|
|
132
|
+
if (error !== void 0) return { problem: `fix it first (${error.text})` };
|
|
133
|
+
const elements = [];
|
|
134
|
+
const walk = (node) => {
|
|
135
|
+
if (Array.isArray(node)) return node.forEach(walk);
|
|
136
|
+
if (node === null || typeof node !== "object") return;
|
|
137
|
+
if (isOpening(node) && !(node.name.type === "JSXIdentifier" && OWN.has(node.name.name))) elements.push(node);
|
|
138
|
+
Object.values(node).forEach(walk);
|
|
139
|
+
};
|
|
140
|
+
walk(ast.body);
|
|
141
|
+
return {
|
|
142
|
+
program: ast.frontmatter.program,
|
|
143
|
+
elements
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
/** An `.astro` file's text with every host element marked, as `locate` marks a JSX module; nothing where it can't be read. */
|
|
147
|
+
function locateAstro(code, file, root) {
|
|
148
|
+
if (!/<[a-z]/.test(code)) return void 0;
|
|
149
|
+
const parsed = parseAstro(root, code);
|
|
150
|
+
return "problem" in parsed ? void 0 : marked(code, file, parsed.elements);
|
|
151
|
+
}
|
|
152
|
+
// src/tools/plugins.ts
|
|
153
|
+
const NAME = /^[a-z][a-z0-9-]*$/;
|
|
154
|
+
/** Throws what to fix in a set of plugins: names, what they need, and their shortcuts, beside deictic's own. */
|
|
155
|
+
function checkPlugins(plugins, own) {
|
|
156
|
+
const names = /* @__PURE__ */ new Set();
|
|
157
|
+
for (const { name, client, shortcut } of plugins) {
|
|
158
|
+
if (!NAME.test(name)) throw new Error(`deictic: a plugin is named "${name}": name it in lowercase letters, digits and -`);
|
|
159
|
+
if (names.has(name)) throw new Error(`deictic: two plugins are named ${name}: load each once`);
|
|
160
|
+
if (shortcut !== void 0 && client === void 0) throw new Error(`deictic: ${name} has a shortcut but no \`client\` to draw its panel: give it one, or leave out its shortcut`);
|
|
161
|
+
names.add(name);
|
|
162
|
+
}
|
|
163
|
+
for (const { name, needs = [] } of plugins) {
|
|
164
|
+
const missing = needs.find((other) => !names.has(other));
|
|
165
|
+
if (missing !== void 0) throw new Error(`deictic: ${name} needs the ${missing} plugin: add it to \`plugins\``);
|
|
166
|
+
}
|
|
167
|
+
checkShortcuts([{
|
|
168
|
+
name: OWN$1,
|
|
169
|
+
shortcut: ownShortcut(own)
|
|
170
|
+
}, ...plugins]);
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Runs every plugin's `setup`, all at once, and answers the context they share: `use` reads an API
|
|
174
|
+
* when it's asked for, so setups may `use` each other's only after they've all run, from a route or an
|
|
175
|
+
* op, never in `setup` itself.
|
|
176
|
+
*/
|
|
177
|
+
async function setUp(root, plugins) {
|
|
178
|
+
const apis = /* @__PURE__ */ new Map();
|
|
179
|
+
const context = {
|
|
180
|
+
root,
|
|
181
|
+
use: (name) => apis.get(name)
|
|
182
|
+
};
|
|
183
|
+
await Promise.all(plugins.map(async (p) => {
|
|
184
|
+
if (p.setup !== void 0) apis.set(p.name, await p.setup(context));
|
|
185
|
+
}));
|
|
186
|
+
return context;
|
|
187
|
+
}
|
|
188
|
+
// src/tools/integration.ts
|
|
189
|
+
/**
|
|
190
|
+
* What every bundler's integration shares: the options, the client module that starts the overlay, and
|
|
191
|
+
* the transform that marks a JSX module. Each integration adds what its bundler does its own way: how a
|
|
192
|
+
* module is transformed (a hook, a loader, `onLoad`), how the page loads the client (a virtual module
|
|
193
|
+
* under Vite, a file in `.deictic/` elsewhere, as webpack, Turbopack and Bun have none), where the
|
|
194
|
+
* endpoints are served, and what opens the editor.
|
|
195
|
+
*/
|
|
196
|
+
/** The options with their defaults, checked now, so a wrong set stops the dev server as it starts, not the page. */
|
|
197
|
+
function prepare(options) {
|
|
198
|
+
const plugins = options.plugins ?? [];
|
|
199
|
+
checkPlugins(plugins, options.shortcut);
|
|
200
|
+
return {
|
|
201
|
+
plugins,
|
|
202
|
+
shortcut: options.shortcut
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* The client module: the overlay, started with deictic's own shortcut and each plugin that has a half
|
|
207
|
+
* in the page, with its shortcut, checked.
|
|
208
|
+
*/
|
|
209
|
+
const clientModule = (plugins, base, own) => {
|
|
210
|
+
const [shortcut, ...shortcuts] = checkShortcuts([{
|
|
211
|
+
name: OWN$1,
|
|
212
|
+
shortcut: ownShortcut(own)
|
|
213
|
+
}, ...plugins]);
|
|
214
|
+
const paged = plugins.flatMap((p, i) => p.client === void 0 ? [] : [{
|
|
215
|
+
client: p.client,
|
|
216
|
+
rest: {
|
|
217
|
+
shortcut: shortcuts[i],
|
|
218
|
+
options: p.clientOptions
|
|
219
|
+
}
|
|
220
|
+
}]);
|
|
221
|
+
return [
|
|
222
|
+
`import { start } from 'deictic/client';`,
|
|
223
|
+
...paged.map((p, i) => `import p${i} from ${JSON.stringify(p.client)};`),
|
|
224
|
+
`start({ base: ${JSON.stringify(base)}, shortcut: ${JSON.stringify(shortcut) ?? "undefined"}, plugins: [${paged.map((p, i) => `{ plugin: p${i}, ...${JSON.stringify(p.rest)} }`).join(", ")}] });`
|
|
225
|
+
].join("\n");
|
|
226
|
+
};
|
|
227
|
+
/**
|
|
228
|
+
* Writes the client module to `.deictic/client.js` for a bundler without virtual modules, and answers
|
|
229
|
+
* its path. Its imports are bare (`deictic/client`, each plugin's), found from the project as its own
|
|
230
|
+
* are. Written only when it changed, so a watching bundler doesn't rebuild for nothing.
|
|
231
|
+
*/
|
|
232
|
+
function writeClient(root, plugins, base, own) {
|
|
233
|
+
const code = `// Written by deictic as the dev server starts: it starts the overlay in the page.\n${clientModule(plugins, base, own)}\n`;
|
|
234
|
+
const manifest = `${JSON.stringify({
|
|
235
|
+
private: true,
|
|
236
|
+
type: "module",
|
|
237
|
+
sideEffects: true
|
|
238
|
+
}, null, 2)}\n`;
|
|
239
|
+
writeIfChanged(keptIn(root, "package.json"), manifest);
|
|
240
|
+
return writeIfChanged(keptIn(root, "client.js"), code);
|
|
241
|
+
}
|
|
242
|
+
function writeIfChanged(path, text) {
|
|
243
|
+
if (!existsSync(path) || readFileSync(path, "utf8") !== text) writeFileSync(path, text);
|
|
244
|
+
return path;
|
|
245
|
+
}
|
|
246
|
+
/** A module beside `url`, by its name: `.ts` from the source, `.js` from `dist`, as `url` is. */
|
|
247
|
+
const beside = (url, name) => fileURLToPath(new URL(`./${name}${url.endsWith(".ts") ? ".ts" : ".js"}`, url)).replaceAll("\\", "/");
|
|
248
|
+
/**
|
|
249
|
+
* The import of the written client module in the module at `from`, by a relative path with forward
|
|
250
|
+
* slashes: Turbopack can't import a Windows path, and every bundler takes a relative one.
|
|
251
|
+
*/
|
|
252
|
+
function importOf(path, from) {
|
|
253
|
+
const to = relative(dirname(from), path).replaceAll("\\", "/");
|
|
254
|
+
return `\nimport ${JSON.stringify(to.startsWith(".") ? to : `./${to}`)};\n`;
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* A module marked, by its absolute path: its host elements, and `append` after it (the client's import,
|
|
258
|
+
* in the browser). Nothing for a file that isn't JSX, is a dependency's, or is outside the project.
|
|
259
|
+
*/
|
|
260
|
+
function mark(code, path, root, append = "") {
|
|
261
|
+
const file = JSX.test(path) ? fileIn(path, root) : void 0;
|
|
262
|
+
return file === void 0 ? void 0 : locate(code, file, append);
|
|
263
|
+
}
|
|
264
|
+
/** An `.astro` component marked, by its absolute path, as `mark` does a module. It's no module of the browser's, so nothing is appended. */
|
|
265
|
+
function markAstro(code, path, root) {
|
|
266
|
+
const file = ASTRO.test(path) ? fileIn(path, root) : void 0;
|
|
267
|
+
return file === void 0 ? void 0 : locateAstro(code, file, root);
|
|
268
|
+
}
|
|
269
|
+
/** A project file's path from the root, as a mark has it; nothing for a dependency's or one outside the project. */
|
|
270
|
+
function fileIn(path, root) {
|
|
271
|
+
if (/[\\/]node_modules[\\/]/.test(path) || !isAbsolute(path)) return void 0;
|
|
272
|
+
const file = relative(root, path).replaceAll("\\", "/");
|
|
273
|
+
return file.startsWith("..") || isAbsolute(file) ? void 0 : file;
|
|
274
|
+
}
|
|
275
|
+
export { markAstro as a, setUp as c, JSX as d, isHost as f, parse as g, openingsIn as h, mark as i, ASTRO as l, offsetOf as m, clientModule as n, prepare as o, lineStarts as p, importOf as r, writeClient as s, beside as t, parseAstro as u };
|
|
276
|
+
|
|
277
|
+
//# sourceMappingURL=integration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"integration.js","names":["OWN","OWN"],"sources":["../src/tools/locate.ts","../src/tools/astro.ts","../src/tools/plugins.ts","../src/tools/integration.ts"],"sourcesContent":["/**\n * Marks each host element in a JSX module with where its opening tag starts:\n * `<div data-deictic=\"src/App.tsx:12:5\">`. The page reads it back to know what was clicked.\n *\n * At build time and not from React's fibers at runtime: it works for any framework that compiles JSX,\n * for server components (which have no fiber in the browser), and it names the element's own tag\n * rather than the component that rendered it. Only host elements (`div`, `button`) are marked, since a\n * component may not pass the attribute on; a component's call site is reached from its elements.\n *\n * The transform must run on the source as written (`enforce: 'pre'` under Vite), so lines and columns\n * are the file's. It runs alike on the server and in the browser, so a hydrated page matches its HTML.\n */\nimport MagicString from 'magic-string';\nimport { type JSXOpeningElement, parseSync, type Program, Visitor } from 'oxc-parser';\n\nexport const ATTRIBUTE = 'data-deictic';\n/** Modules that may hold JSX: `.jsx` and `.tsx`, and plain `.js`, as many React projects write theirs. */\nexport const JSX = /\\.[cm]?(?:[jt]sx|js)$/;\n\n/** A module parsed, with JSX read in a `.js` file too, which the parser reads there only when told. */\nexport const parse = (file: string, code: string) => parseSync(file, code, /\\.[cm]?js$/.test(file) ? { lang: 'jsx' } : undefined);\n\nexport interface Located {\n code: string;\n map: ReturnType<MagicString['generateMap']>;\n}\n\n/** Whether an opening tag is a host element's, `<div>` or `<svg>`, not a component's or a namespaced one. */\nexport const isHost = (el: JSXOpeningElement) => el.name.type === 'JSXIdentifier' && /^[a-z]/.test(el.name.name);\n\n/**\n * `code` with every host element marked, `file` being its path from the project's root, and `append`\n * after it (the client's import, in the browser); nothing when there is nothing to mark, or the module\n * doesn't parse, which the framework's own transform reports better.\n */\nexport function locate(code: string, file: string, append = ''): Located | undefined {\n // No tag, no parse: most `.js` modules have none, and every one of the project's comes through here.\n if (!/<[a-z]/.test(code)) return undefined;\n const { program, errors } = parse(file, code);\n if (errors.length > 0) return undefined;\n return marked(code, file, openingsIn(program), append);\n}\n\n/** Every opening tag in a module, in its order. */\nexport function openingsIn(program: Program): JSXOpeningElement[] {\n const elements: JSXOpeningElement[] = [];\n new Visitor({ JSXOpeningElement: (el) => void elements.push(el) }).visit(program);\n return elements;\n}\n\n/**\n * `code` with a mark in each of `elements` that is a host element's and has none yet, and `append` after\n * it; nothing with none to mark.\n */\nexport function marked(code: string, file: string, elements: JSXOpeningElement[], append = ''): Located | undefined {\n const lines = lineStarts(code);\n const s = new MagicString(code);\n for (const el of elements) {\n if (!isHost(el) || el.attributes.some((a) => a.type === 'JSXAttribute' && nameOf(a.name) === ATTRIBUTE)) continue;\n const { line, column } = position(lines, el.start);\n s.appendLeft(el.name.end, ` ${ATTRIBUTE}=\"${file}:${line}:${column}\"`);\n }\n if (!s.hasChanged()) return undefined;\n if (append !== '') s.append(append);\n // A map's source is read from the module's own folder, so it's the file's name, not its path from the root.\n return { code: s.toString(), map: s.generateMap({ source: file.slice(file.lastIndexOf('/') + 1), hires: 'boundary' }) };\n}\n\nconst nameOf = (name: { type: string; name?: unknown }) => (name.type === 'JSXIdentifier' ? name.name : undefined);\n\n/** Where each line starts, by offset. */\nexport function lineStarts(code: string): number[] {\n const starts = [0];\n for (let i = code.indexOf('\\n'); i !== -1; i = code.indexOf('\\n', i + 1)) starts.push(i + 1);\n return starts;\n}\n\n/** An offset's line and column, from 1. */\nexport function position(lines: number[], offset: number): { line: number; column: number } {\n let lo = 0;\n let hi = lines.length - 1;\n while (lo < hi) {\n const mid = (lo + hi + 1) >> 1;\n if (lines[mid]! <= offset) lo = mid;\n else hi = mid - 1;\n }\n return { line: lo + 1, column: offset - lines[lo]! + 1 };\n}\n\n/** A line and column's offset, or nothing past the file's end. */\nexport function offsetOf(lines: number[], line: number, column: number): number | undefined {\n const start = lines[line - 1];\n return start === undefined ? undefined : start + column - 1;\n}\n","/**\n * `.astro` components. They aren't JSX modules, but Astro 7's own parser reads a template as JSX, into the\n * tree oxc makes (offsets in UTF-16, as ours are), so its host elements are marked as a JSX module's are,\n * before Astro compiles the file. The parser is the project's own Astro's (`@astrojs/compiler-rs`, found\n * through `astro`), so it reads a file exactly as the compiler will; an Astro before 7 has none like it,\n * and its `.astro` files are left unmarked.\n */\nimport { createRequire } from 'node:module';\nimport { join } from 'node:path';\n\nimport type { JSXOpeningElement, Program } from 'oxc-parser';\n\nimport { type Located, marked } from './locate.ts';\n\nexport const ASTRO = /\\.astro$/;\n\n/** A file parsed: its module (an `.astro` file's frontmatter), and each opening tag in it, in the file's order. */\nexport interface Parsed {\n program: Program;\n elements: JSXOpeningElement[];\n}\n\ninterface Tree {\n ast: { frontmatter: { program: Program }; body: unknown };\n diagnostics: { severity: string; text: string }[];\n}\ntype Parse = (code: string) => Tree;\n\nconst parsers = new Map<string, Parse | undefined>();\n\n/** The parser of the Astro installed for the project at `root`, loaded once; nothing without Astro 7. */\nfunction parserOf(root: string): Parse | undefined {\n if (!parsers.has(root)) parsers.set(root, load(root));\n return parsers.get(root);\n}\n\nfunction load(root: string): Parse | undefined {\n try {\n // Astro's own dependency, which a strict package manager doesn't put where the project could import it.\n const astro = createRequire(createRequire(join(root, 'package.json')).resolve('astro/package.json'));\n // An ES module, required: every Node that runs Astro 7 can, and reading a source stays synchronous.\n const compiler: { parse?: Parse } = astro('@astrojs/compiler-rs');\n return compiler.parse;\n } catch {\n return undefined;\n }\n}\n\n/**\n * Astro gives a `<script>` or `<style>` with an attribute it doesn't know to the page as it is, unbundled and\n * unscoped, and a `<slot>` isn't an element at all: none of them can be pointed at, so none is marked.\n */\nconst OWN = new Set(['script', 'style', 'slot']);\n\nconst isOpening = (node: object): node is JSXOpeningElement => 'type' in node && node.type === 'JSXOpeningElement';\n\n/** An `.astro` file's text parsed, or the `problem` with it: no parser (an older Astro), or text that doesn't parse. */\nexport function parseAstro(root: string, code: string): Parsed | { problem: string } {\n const parse = parserOf(root);\n if (parse === undefined) return { problem: 'reading an .astro file takes Astro 7 or later, so update astro' };\n const { ast, diagnostics } = parse(code);\n const error = diagnostics.find((d) => d.severity === 'error');\n if (error !== undefined) return { problem: `fix it first (${error.text})` };\n const elements: JSXOpeningElement[] = [];\n const walk = (node: unknown): void => {\n if (Array.isArray(node)) return node.forEach(walk);\n if (node === null || typeof node !== 'object') return;\n if (isOpening(node) && !(node.name.type === 'JSXIdentifier' && OWN.has(node.name.name))) elements.push(node);\n Object.values(node).forEach(walk);\n };\n walk(ast.body);\n return { program: ast.frontmatter.program, elements };\n}\n\n/** An `.astro` file's text with every host element marked, as `locate` marks a JSX module; nothing where it can't be read. */\nexport function locateAstro(code: string, file: string, root: string): Located | undefined {\n // No tag, no parse.\n if (!/<[a-z]/.test(code)) return undefined;\n const parsed = parseAstro(root, code);\n return 'problem' in parsed ? undefined : marked(code, file, parsed.elements);\n}\n","/**\n * The plugins an integration was given: checked as it starts, so a wrong set fails the dev server with\n * what to write instead, and set up once before the endpoints answer anything.\n */\nimport type { ServerContext, ServerPlugin } from '#src/index.ts';\nimport { checkShortcuts, OWN, ownShortcut, type Shortcut } from '#src/shortcut.ts';\n\nconst NAME = /^[a-z][a-z0-9-]*$/;\n\n/** Throws what to fix in a set of plugins: names, what they need, and their shortcuts, beside deictic's own. */\nexport function checkPlugins(plugins: readonly ServerPlugin[], own?: Shortcut | false): void {\n const names = new Set<string>();\n for (const { name, client, shortcut } of plugins) {\n if (!NAME.test(name)) throw new Error(`deictic: a plugin is named \"${name}\": name it in lowercase letters, digits and -`);\n if (names.has(name)) throw new Error(`deictic: two plugins are named ${name}: load each once`);\n if (shortcut !== undefined && client === undefined)\n throw new Error(`deictic: ${name} has a shortcut but no \\`client\\` to draw its panel: give it one, or leave out its shortcut`);\n names.add(name);\n }\n for (const { name, needs = [] } of plugins) {\n const missing = needs.find((other) => !names.has(other));\n if (missing !== undefined) throw new Error(`deictic: ${name} needs the ${missing} plugin: add it to \\`plugins\\``);\n }\n checkShortcuts([{ name: OWN, shortcut: ownShortcut(own) }, ...plugins]);\n}\n\n/**\n * Runs every plugin's `setup`, all at once, and answers the context they share: `use` reads an API\n * when it's asked for, so setups may `use` each other's only after they've all run, from a route or an\n * op, never in `setup` itself.\n */\nexport async function setUp(root: string, plugins: readonly ServerPlugin[]): Promise<ServerContext> {\n const apis = new Map<string, unknown>();\n const context: ServerContext = { root, use: (name) => apis.get(name) as never };\n await Promise.all(\n plugins.map(async (p) => {\n if (p.setup !== undefined) apis.set(p.name, await p.setup(context));\n }),\n );\n return context;\n}\n","/**\n * What every bundler's integration shares: the options, the client module that starts the overlay, and\n * the transform that marks a JSX module. Each integration adds what its bundler does its own way: how a\n * module is transformed (a hook, a loader, `onLoad`), how the page loads the client (a virtual module\n * under Vite, a file in `.deictic/` elsewhere, as webpack, Turbopack and Bun have none), where the\n * endpoints are served, and what opens the editor.\n */\nimport { existsSync, readFileSync, writeFileSync } from 'node:fs';\nimport { dirname, isAbsolute, relative } from 'node:path';\nimport { fileURLToPath } from 'node:url';\n\nimport type { ServerPlugin } from '#src/index.ts';\nimport { checkShortcuts, OWN, ownShortcut, type Shortcut } from '#src/shortcut.ts';\n\nimport { ASTRO, locateAstro } from './astro.ts';\nimport { keptIn } from './kept.ts';\nimport { JSX, locate, type Located } from './locate.ts';\nimport { checkPlugins } from './plugins.ts';\n\nexport interface DeicticOptions {\n /** The plugins to load, server halves: `tailwind()`, `tasks()`, your own. None by default. */\n plugins?: ServerPlugin[];\n /**\n * What opens the popup on any plugin, at the tab used last: Alt and the left button by default, or\n * `false` for none, leaving only plugins' own shortcuts.\n */\n shortcut?: Shortcut | false;\n}\n\n/** The options with their defaults, checked now, so a wrong set stops the dev server as it starts, not the page. */\nexport function prepare(options: DeicticOptions): { plugins: ServerPlugin[]; shortcut: Shortcut | false | undefined } {\n const plugins = options.plugins ?? [];\n checkPlugins(plugins, options.shortcut);\n return { plugins, shortcut: options.shortcut };\n}\n\n/**\n * The client module: the overlay, started with deictic's own shortcut and each plugin that has a half\n * in the page, with its shortcut, checked.\n */\nexport const clientModule = (plugins: ServerPlugin[], base: string, own?: Shortcut | false) => {\n const [shortcut, ...shortcuts] = checkShortcuts([{ name: OWN, shortcut: ownShortcut(own) }, ...plugins]);\n const paged = plugins.flatMap((p, i) =>\n p.client === undefined ? [] : [{ client: p.client, rest: { shortcut: shortcuts[i], options: p.clientOptions } }],\n );\n return [\n `import { start } from 'deictic/client';`,\n ...paged.map((p, i) => `import p${i} from ${JSON.stringify(p.client)};`),\n // Its shortcut and options as JSON, where it has them: `JSON.stringify` leaves out what's undefined.\n `start({ base: ${JSON.stringify(base)}, shortcut: ${JSON.stringify(shortcut) ?? 'undefined'}, plugins: [${paged.map((p, i) => `{ plugin: p${i}, ...${JSON.stringify(p.rest)} }`).join(', ')}] });`,\n ].join('\\n');\n};\n\n/**\n * Writes the client module to `.deictic/client.js` for a bundler without virtual modules, and answers\n * its path. Its imports are bare (`deictic/client`, each plugin's), found from the project as its own\n * are. Written only when it changed, so a watching bundler doesn't rebuild for nothing.\n */\nexport function writeClient(root: string, plugins: ServerPlugin[], base: string, own?: Shortcut | false): string {\n const code = `// Written by deictic as the dev server starts: it starts the overlay in the page.\\n${clientModule(plugins, base, own)}\\n`;\n // Its own package: an ES module that runs for its effect. An app whose package.json says\n // `\"sideEffects\": false` would otherwise have webpack drop the import, which is only for its effect.\n const manifest = `${JSON.stringify({ private: true, type: 'module', sideEffects: true }, null, 2)}\\n`;\n writeIfChanged(keptIn(root, 'package.json'), manifest);\n return writeIfChanged(keptIn(root, 'client.js'), code);\n}\n\nfunction writeIfChanged(path: string, text: string): string {\n if (!existsSync(path) || readFileSync(path, 'utf8') !== text) writeFileSync(path, text);\n return path;\n}\n\n/** A module beside `url`, by its name: `.ts` from the source, `.js` from `dist`, as `url` is. */\nexport const beside = (url: string, name: string) =>\n fileURLToPath(new URL(`./${name}${url.endsWith('.ts') ? '.ts' : '.js'}`, url)).replaceAll('\\\\', '/');\n\n/**\n * The import of the written client module in the module at `from`, by a relative path with forward\n * slashes: Turbopack can't import a Windows path, and every bundler takes a relative one.\n */\nexport function importOf(path: string, from: string): string {\n const to = relative(dirname(from), path).replaceAll('\\\\', '/');\n return `\\nimport ${JSON.stringify(to.startsWith('.') ? to : `./${to}`)};\\n`;\n}\n\n/**\n * A module marked, by its absolute path: its host elements, and `append` after it (the client's import,\n * in the browser). Nothing for a file that isn't JSX, is a dependency's, or is outside the project.\n */\nexport function mark(code: string, path: string, root: string, append = ''): Located | undefined {\n const file = JSX.test(path) ? fileIn(path, root) : undefined;\n return file === undefined ? undefined : locate(code, file, append);\n}\n\n/** An `.astro` component marked, by its absolute path, as `mark` does a module. It's no module of the browser's, so nothing is appended. */\nexport function markAstro(code: string, path: string, root: string): Located | undefined {\n const file = ASTRO.test(path) ? fileIn(path, root) : undefined;\n return file === undefined ? undefined : locateAstro(code, file, root);\n}\n\n/** A project file's path from the root, as a mark has it; nothing for a dependency's or one outside the project. */\nfunction fileIn(path: string, root: string): string | undefined {\n if (/[\\\\/]node_modules[\\\\/]/.test(path) || !isAbsolute(path)) return undefined;\n const file = relative(root, path).replaceAll('\\\\', '/');\n return file.startsWith('..') || isAbsolute(file) ? undefined : file;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAeA,MAAa,YAAY;;AAEzB,MAAa,MAAM;;AAGnB,MAAa,SAAS,MAAc,SAAiB,UAAU,MAAM,MAAM,aAAa,KAAK,IAAI,IAAI,EAAE,MAAM,MAAM,IAAI,KAAA,CAAS;;AAQhI,MAAa,UAAU,OAA0B,GAAG,KAAK,SAAS,mBAAmB,SAAS,KAAK,GAAG,KAAK,IAAI;;;;;;AAO/G,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rD,OAAO,SAAS,KAAA,IAAY,KAAA,IAAY,YAAY,MAAM,MAAM,IAAI;AACtE;;AAGA,SAAS,OAAO,MAAc,MAAkC;CAC9D,IAAI,yBAAyB,KAAK,IAAI,KAAK,CAAC,WAAW,IAAI,GAAG,OAAO,KAAA;CACrE,MAAM,OAAO,SAAS,MAAM,IAAI,CAAC,CAAC,WAAW,MAAM,GAAG;CACtD,OAAO,KAAK,WAAW,IAAI,KAAK,WAAW,IAAI,IAAI,KAAA,IAAY;AACjE"}
|
package/dist/kept.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
// src/tools/kept.ts
|
|
4
|
+
/**
|
|
5
|
+
* Where deictic keeps what it makes for a project: `.deictic/` at its root, beside `.board/` and the like,
|
|
6
|
+
* rather than in `node_modules`, which an install may clear. The history is there, and the shots,
|
|
7
|
+
* recordings and voice clips plugins keep. It ignores itself in git: the history holds whole files, and
|
|
8
|
+
* the rest is the page as it looked, neither of which belongs in a commit.
|
|
9
|
+
*/
|
|
10
|
+
const IGNORE = "# deictic's own: the history, and the shots, recordings and voice clips it keeps.\n*\n";
|
|
11
|
+
/** A path under the project's `.deictic/`, made with its `.gitignore` the first time. */
|
|
12
|
+
function keptIn(root, ...parts) {
|
|
13
|
+
const dir = join(root, ".deictic");
|
|
14
|
+
const ignore = join(dir, ".gitignore");
|
|
15
|
+
if (!existsSync(ignore)) {
|
|
16
|
+
mkdirSync(dir, { recursive: true });
|
|
17
|
+
writeFileSync(ignore, IGNORE);
|
|
18
|
+
}
|
|
19
|
+
return join(dir, ...parts);
|
|
20
|
+
}
|
|
21
|
+
export { keptIn as t };
|
|
22
|
+
|
|
23
|
+
//# sourceMappingURL=kept.js.map
|
package/dist/kept.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kept.js","names":[],"sources":["../src/tools/kept.ts"],"sourcesContent":["/**\n * Where deictic keeps what it makes for a project: `.deictic/` at its root, beside `.board/` and the like,\n * rather than in `node_modules`, which an install may clear. The history is there, and the shots,\n * recordings and voice clips plugins keep. It ignores itself in git: the history holds whole files, and\n * the rest is the page as it looked, neither of which belongs in a commit.\n */\nimport { existsSync, mkdirSync, writeFileSync } from 'node:fs';\nimport { join } from 'node:path';\n\nconst IGNORE = \"# deictic's own: the history, and the shots, recordings and voice clips it keeps.\\n*\\n\";\n\n/** A path under the project's `.deictic/`, made with its `.gitignore` the first time. */\nexport function keptIn(root: string, ...parts: string[]): string {\n const dir = join(root, '.deictic');\n const ignore = join(dir, '.gitignore');\n if (!existsSync(ignore)) {\n mkdirSync(dir, { recursive: true });\n writeFileSync(ignore, IGNORE);\n }\n return join(dir, ...parts);\n}\n"],"mappings":";;;;;;;;;AASA,MAAM,SAAS;;AAGf,SAAgB,OAAO,MAAc,GAAG,OAAyB;CAC/D,MAAM,MAAM,KAAK,MAAM,UAAU;CACjC,MAAM,SAAS,KAAK,KAAK,YAAY;CACrC,IAAI,CAAC,WAAW,MAAM,GAAG;EACvB,UAAU,KAAK,EAAE,WAAW,KAAK,CAAC;EAClC,cAAc,QAAQ,MAAM;CAC9B;CACA,OAAO,KAAK,KAAK,GAAG,KAAK;AAC3B"}
|
package/dist/loader.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export interface LoaderOptions {
|
|
2
|
+
/** The project's root, which a mark's path is from. */
|
|
3
|
+
root: string;
|
|
4
|
+
/** The written client module, to import in the browser; none on the server. */
|
|
5
|
+
client?: string;
|
|
6
|
+
}
|
|
7
|
+
interface Context {
|
|
8
|
+
getOptions(): LoaderOptions;
|
|
9
|
+
resourcePath: string;
|
|
10
|
+
sourceMap?: boolean;
|
|
11
|
+
callback(error: Error | null, code?: string, map?: object): void;
|
|
12
|
+
}
|
|
13
|
+
export default function loader(this: Context, source: string): void;
|
|
14
|
+
export {};
|
|
15
|
+
//# sourceMappingURL=loader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loader.d.ts","names":[],"sources":["../src/loader.ts"],"mappings":"A,iBAQiB;;EAEf;;EAEA;;UAGQ;EACR,cAAc;EACd;EACA;EACA,SAAS,OAAO,cAAc,eAAe;;wBAGvB,OAAO,MAAM,SAAS"}
|
package/dist/loader.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { i as mark, r as importOf } from "./integration.js";
|
|
2
|
+
// src/loader.ts
|
|
3
|
+
/**
|
|
4
|
+
* The loader `deictic/webpack` sets for webpack and Rspack, and `deictic/next` for Turbopack: it marks a
|
|
5
|
+
* JSX module's host elements (`tools/locate.ts`), and in the browser appends the import of the client
|
|
6
|
+
* module written to `.deictic/client.js`. It runs `pre`, before the app's own loaders, so lines and
|
|
7
|
+
* columns are the file's as written. Its options are JSON, as Turbopack's must be.
|
|
8
|
+
*/
|
|
9
|
+
function loader(source) {
|
|
10
|
+
const { root, client } = this.getOptions();
|
|
11
|
+
const marked = mark(source, this.resourcePath, root, client === void 0 ? "" : importOf(client, this.resourcePath));
|
|
12
|
+
if (marked === void 0) return this.callback(null, source);
|
|
13
|
+
this.callback(null, marked.code, this.sourceMap === false ? void 0 : marked.map);
|
|
14
|
+
}
|
|
15
|
+
export { loader as default };
|
|
16
|
+
|
|
17
|
+
//# sourceMappingURL=loader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loader.js","names":[],"sources":["../src/loader.ts"],"sourcesContent":["/**\n * The loader `deictic/webpack` sets for webpack and Rspack, and `deictic/next` for Turbopack: it marks a\n * JSX module's host elements (`tools/locate.ts`), and in the browser appends the import of the client\n * module written to `.deictic/client.js`. It runs `pre`, before the app's own loaders, so lines and\n * columns are the file's as written. Its options are JSON, as Turbopack's must be.\n */\nimport { importOf, mark } from './tools/integration.ts';\n\nexport interface LoaderOptions {\n /** The project's root, which a mark's path is from. */\n root: string;\n /** The written client module, to import in the browser; none on the server. */\n client?: string;\n}\n\ninterface Context {\n getOptions(): LoaderOptions;\n resourcePath: string;\n sourceMap?: boolean;\n callback(error: Error | null, code?: string, map?: object): void;\n}\n\nexport default function loader(this: Context, source: string): void {\n const { root, client } = this.getOptions();\n const marked = mark(source, this.resourcePath, root, client === undefined ? '' : importOf(client, this.resourcePath));\n if (marked === undefined) return this.callback(null, source);\n this.callback(null, marked.code, this.sourceMap === false ? undefined : marked.map);\n}\n"],"mappings":";;;;;;;;AAsBA,SAAwB,OAAsB,QAAsB;CAClE,MAAM,EAAE,MAAM,WAAW,KAAK,WAAW;CACzC,MAAM,SAAS,KAAK,QAAQ,KAAK,cAAc,MAAM,WAAW,KAAA,IAAY,KAAK,SAAS,QAAQ,KAAK,YAAY,CAAC;CACpH,IAAI,WAAW,KAAA,GAAW,OAAO,KAAK,SAAS,MAAM,MAAM;CAC3D,KAAK,SAAS,MAAM,OAAO,MAAM,KAAK,cAAc,QAAQ,KAAA,IAAY,OAAO,GAAG;AACpF"}
|
package/dist/marks.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// src/plugins/recordings/marks.ts
|
|
2
|
+
/**
|
|
3
|
+
* The custom event's tag the marks go in: the page's annotations, as an SVG in page coordinates (`svg`),
|
|
4
|
+
* and as the annotations themselves (`annotations`, absent from recordings made before it was added).
|
|
5
|
+
*/
|
|
6
|
+
const MARKS = "deictic.annotations";
|
|
7
|
+
/**
|
|
8
|
+
* The custom event a recording ends with: rrweb's timeline lasts as long as its events, so without it a
|
|
9
|
+
* recording of a still page (a voice-over, say) would replay as a moment, and its voice never play.
|
|
10
|
+
*/
|
|
11
|
+
const END = "deictic.end";
|
|
12
|
+
export { MARKS as n, END as t };
|
|
13
|
+
|
|
14
|
+
//# sourceMappingURL=marks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"marks.js","names":[],"sources":["../src/plugins/recordings/marks.ts"],"sourcesContent":["/**\n * The custom event's tag the marks go in: the page's annotations, as an SVG in page coordinates (`svg`),\n * and as the annotations themselves (`annotations`, absent from recordings made before it was added).\n */\nexport const MARKS = 'deictic.annotations';\n\n/**\n * The custom event a recording ends with: rrweb's timeline lasts as long as its events, so without it a\n * recording of a still page (a voice-over, say) would replay as a moment, and its voice never play.\n */\nexport const END = 'deictic.end';\n"],"mappings":";;;;;AAIA,MAAa,QAAQ;;;;;AAMrB,MAAa,MAAM"}
|
package/dist/next.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { t as DeicticOptions } from "./integration.js";
|
|
2
|
+
export interface DeicticNextOptions extends DeicticOptions {
|
|
3
|
+
/** The project's root, which marks and edits are from: the working directory `next dev` runs in by default. */
|
|
4
|
+
root?: string;
|
|
5
|
+
}
|
|
6
|
+
type ConfigFunction<C> = (phase: string, context: {
|
|
7
|
+
defaultConfig: C;
|
|
8
|
+
}) => C | Promise<C>;
|
|
9
|
+
/**
|
|
10
|
+
* Wraps the Next config: `export default withDeictic({ ... }, { plugins: [tailwind()] })`. Takes the
|
|
11
|
+
* config as an object or as the function Next calls with the phase, and returns the function.
|
|
12
|
+
*/
|
|
13
|
+
export declare function withDeictic<C extends object>(next?: C | ConfigFunction<C>, options?: DeicticNextOptions): (phase: string, context: {
|
|
14
|
+
defaultConfig: C;
|
|
15
|
+
}) => Promise<C>;
|
|
16
|
+
export { withDeictic as default };
|
|
17
|
+
//# sourceMappingURL=next.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"next.d.ts","names":[],"sources":["../src/next.ts"],"mappings":";iBA2BiB,2BAA2B;;EAE1C;;KAUG,eAAe,MAAM,eAAe;EAAW,eAAe;MAAQ,IAAI,QAAQ;;;;;wBAavE,YAAY,kBAC1B,OAAM,IAAI,eAAe,IACzB,UAAS,sBACP,eAAe;EAAW,eAAe;MAAQ,QAAQ"}
|
package/dist/next.js
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { createServer } from "node:http";
|
|
2
|
+
import { resolve } from "node:path";
|
|
3
|
+
import { n as nodeMiddleware, r as redirect, t as endpoints } from "./endpoints.js";
|
|
4
|
+
import { d as JSX, o as prepare, s as writeClient, t as beside } from "./integration.js";
|
|
5
|
+
// src/next.ts
|
|
6
|
+
/**
|
|
7
|
+
* `deictic/next`: deictic in `next dev`, on Turbopack or webpack (`--webpack`). Nothing runs in `next build`.
|
|
8
|
+
*
|
|
9
|
+
* Turbopack has no transform hook and no virtual modules, so a loader rule (`loader.ts`) marks each JSX
|
|
10
|
+
* module, on the server too, which marks server components' elements in the HTML they render; in the
|
|
11
|
+
* browser it also imports the client module, written to `.deictic/client.js`. Only code the browser
|
|
12
|
+
* loads can start the overlay, so a page with no client component at all has none. Under webpack the
|
|
13
|
+
* same loader is a `pre` rule, as in `webpack.ts`.
|
|
14
|
+
*
|
|
15
|
+
* The endpoints can't be a route of the app without a file in it, so a server of their own answers them
|
|
16
|
+
* on a local port, and a rewrite sends `/__deictic/*` there, before any of the app's own; Next's proxy
|
|
17
|
+
* forwards the page's host, so writes are still checked against its origin. A place opens through
|
|
18
|
+
* Next's own `/__nextjs_launch-editor`.
|
|
19
|
+
*
|
|
20
|
+
* Both bundlers' rules are always set, as the config can't tell which will run: Next refuses a Turbopack
|
|
21
|
+
* build whose config has a `webpack` key only where it has no `turbopack` one, and ours always does.
|
|
22
|
+
*/
|
|
23
|
+
const DEV = "phase-development-server";
|
|
24
|
+
const loaderPath = beside(import.meta.url, "loader");
|
|
25
|
+
const GLOBS = [
|
|
26
|
+
"*.tsx",
|
|
27
|
+
"*.jsx",
|
|
28
|
+
"*.js"
|
|
29
|
+
];
|
|
30
|
+
const serving = /* @__PURE__ */ new Map();
|
|
31
|
+
/**
|
|
32
|
+
* Wraps the Next config: `export default withDeictic({ ... }, { plugins: [tailwind()] })`. Takes the
|
|
33
|
+
* config as an object or as the function Next calls with the phase, and returns the function.
|
|
34
|
+
*/
|
|
35
|
+
function withDeictic(next = {}, options = {}) {
|
|
36
|
+
const { plugins, shortcut } = prepare(options);
|
|
37
|
+
return async (phase, context) => {
|
|
38
|
+
const resolved = typeof next === "function" ? await next(phase, context) : next;
|
|
39
|
+
if (phase !== DEV) return resolved;
|
|
40
|
+
const root = resolve(options.root ?? process.cwd());
|
|
41
|
+
const base = `${resolved.basePath ?? ""}/`;
|
|
42
|
+
const client = writeClient(root, plugins, base, shortcut);
|
|
43
|
+
return withRewrite(withWebpack(withRules(resolved, GLOBS.flatMap((glob) => [[glob, {
|
|
44
|
+
condition: { all: ["browser", { not: "foreign" }] },
|
|
45
|
+
loaders: [{
|
|
46
|
+
loader: loaderPath,
|
|
47
|
+
options: {
|
|
48
|
+
root,
|
|
49
|
+
client
|
|
50
|
+
}
|
|
51
|
+
}]
|
|
52
|
+
}], [glob, {
|
|
53
|
+
condition: { all: [{ not: "browser" }, { not: "foreign" }] },
|
|
54
|
+
loaders: [{
|
|
55
|
+
loader: loaderPath,
|
|
56
|
+
options: { root }
|
|
57
|
+
}]
|
|
58
|
+
}]])), root, client), await serve(root, plugins, base));
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
/** The app's rules and ours: where both have one for a glob, theirs first, then ours, in a list. */
|
|
62
|
+
function withRules(resolved, ours) {
|
|
63
|
+
const turbopack = resolved.turbopack;
|
|
64
|
+
const rules = { ...turbopack?.rules };
|
|
65
|
+
for (const [glob, rule] of ours) rules[glob] = glob in rules ? [rules[glob], rule].flat() : rule;
|
|
66
|
+
return {
|
|
67
|
+
...resolved,
|
|
68
|
+
turbopack: {
|
|
69
|
+
...turbopack,
|
|
70
|
+
rules
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
/** For `next dev --webpack`: the app's own `webpack`, then the loader, `pre`, with the client in the browser's build. */
|
|
75
|
+
function withWebpack(resolved, root, client) {
|
|
76
|
+
const theirs = resolved.webpack;
|
|
77
|
+
const webpack = (config, context) => {
|
|
78
|
+
const made = theirs?.(config, context) ?? config;
|
|
79
|
+
const options = context.isServer ? { root } : {
|
|
80
|
+
root,
|
|
81
|
+
client
|
|
82
|
+
};
|
|
83
|
+
made.module.rules.unshift({
|
|
84
|
+
test: JSX,
|
|
85
|
+
exclude: /[\\/]node_modules[\\/]/,
|
|
86
|
+
enforce: "pre",
|
|
87
|
+
use: [{
|
|
88
|
+
loader: loaderPath,
|
|
89
|
+
options
|
|
90
|
+
}]
|
|
91
|
+
});
|
|
92
|
+
return made;
|
|
93
|
+
};
|
|
94
|
+
return {
|
|
95
|
+
...resolved,
|
|
96
|
+
webpack
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
/** Sends `/__deictic/*` to the endpoints' server, before any of the app's own rewrites. */
|
|
100
|
+
function withRewrite(resolved, port) {
|
|
101
|
+
const theirs = resolved.rewrites;
|
|
102
|
+
const ours = [{
|
|
103
|
+
source: "/__deictic/:path*",
|
|
104
|
+
destination: `http://127.0.0.1:${port}/__deictic/:path*`
|
|
105
|
+
}];
|
|
106
|
+
const rewrites = async () => {
|
|
107
|
+
const r = await theirs?.() ?? [];
|
|
108
|
+
return Array.isArray(r) ? {
|
|
109
|
+
beforeFiles: ours,
|
|
110
|
+
afterFiles: r
|
|
111
|
+
} : {
|
|
112
|
+
...r,
|
|
113
|
+
beforeFiles: [...ours, ...r.beforeFiles ?? []]
|
|
114
|
+
};
|
|
115
|
+
};
|
|
116
|
+
return {
|
|
117
|
+
...resolved,
|
|
118
|
+
rewrites
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
/** Serves the endpoints on a free local port, for as long as the process lives. */
|
|
122
|
+
function serve(root, plugins, base) {
|
|
123
|
+
const running = serving.get(root);
|
|
124
|
+
if (running !== void 0) return running;
|
|
125
|
+
const handle = endpoints({
|
|
126
|
+
root,
|
|
127
|
+
plugins,
|
|
128
|
+
base: "/",
|
|
129
|
+
open: (path, { line, column }) => redirect(`${base}__nextjs_launch-editor?${new URLSearchParams({
|
|
130
|
+
file: path,
|
|
131
|
+
line1: String(line),
|
|
132
|
+
column1: String(column)
|
|
133
|
+
})}`)
|
|
134
|
+
});
|
|
135
|
+
const middleware = nodeMiddleware(handle);
|
|
136
|
+
const server = createServer((req, res) => middleware(req, res, () => {
|
|
137
|
+
res.statusCode = 404;
|
|
138
|
+
res.end();
|
|
139
|
+
}));
|
|
140
|
+
const port = new Promise((done, fail) => {
|
|
141
|
+
server.once("error", fail);
|
|
142
|
+
server.listen(0, "127.0.0.1", () => done(server.address().port));
|
|
143
|
+
});
|
|
144
|
+
server.unref();
|
|
145
|
+
serving.set(root, port);
|
|
146
|
+
return port;
|
|
147
|
+
}
|
|
148
|
+
export { withDeictic as default, withDeictic };
|
|
149
|
+
|
|
150
|
+
//# sourceMappingURL=next.js.map
|
package/dist/next.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"next.js","names":[],"sources":["../src/next.ts"],"sourcesContent":["/**\n * `deictic/next`: deictic in `next dev`, on Turbopack or webpack (`--webpack`). Nothing runs in `next build`.\n *\n * Turbopack has no transform hook and no virtual modules, so a loader rule (`loader.ts`) marks each JSX\n * module, on the server too, which marks server components' elements in the HTML they render; in the\n * browser it also imports the client module, written to `.deictic/client.js`. Only code the browser\n * loads can start the overlay, so a page with no client component at all has none. Under webpack the\n * same loader is a `pre` rule, as in `webpack.ts`.\n *\n * The endpoints can't be a route of the app without a file in it, so a server of their own answers them\n * on a local port, and a rewrite sends `/__deictic/*` there, before any of the app's own; Next's proxy\n * forwards the page's host, so writes are still checked against its origin. A place opens through\n * Next's own `/__nextjs_launch-editor`.\n *\n * Both bundlers' rules are always set, as the config can't tell which will run: Next refuses a Turbopack\n * build whose config has a `webpack` key only where it has no `turbopack` one, and ours always does.\n */\nimport { createServer } from 'node:http';\nimport type { AddressInfo } from 'node:net';\nimport { resolve } from 'node:path';\n\nimport type { ServerPlugin } from './index.ts';\nimport type { LoaderOptions } from './loader.ts';\nimport { endpoints, nodeMiddleware, redirect } from './tools/endpoints.ts';\nimport { beside, type DeicticOptions, prepare, writeClient } from './tools/integration.ts';\nimport { JSX } from './tools/locate.ts';\n\nexport interface DeicticNextOptions extends DeicticOptions {\n /** The project's root, which marks and edits are from: the working directory `next dev` runs in by default. */\n root?: string;\n}\n\n/** A Turbopack rule: ours, or whatever the app has. */\ntype Rule = { condition?: unknown; loaders: { loader: string; options: LoaderOptions }[] } | object;\ntype Rules = Record<string, Rule | Rule[]>;\ntype Rewrite = { source: string; destination: string };\ntype Rewrites = Rewrite[] | { beforeFiles?: Rewrite[]; afterFiles?: Rewrite[]; fallback?: Rewrite[] };\n/** What Next's `webpack` option reads and answers, as far as it's used here. Not async: Next doesn't wait for one. */\ntype Webpack = (config: { module: { rules: unknown[] } }, context: { isServer: boolean }) => { module: { rules: unknown[] } };\ntype ConfigFunction<C> = (phase: string, context: { defaultConfig: C }) => C | Promise<C>;\n\nconst DEV = 'phase-development-server';\nconst loaderPath = beside(import.meta.url, 'loader');\nconst GLOBS = ['*.tsx', '*.jsx', '*.js'];\n\n// Next loads its config more than once in a process: one endpoints server per project is enough.\nconst serving = new Map<string, Promise<number>>();\n\n/**\n * Wraps the Next config: `export default withDeictic({ ... }, { plugins: [tailwind()] })`. Takes the\n * config as an object or as the function Next calls with the phase, and returns the function.\n */\nexport function withDeictic<C extends object>(\n next: C | ConfigFunction<C> = {} as C,\n options: DeicticNextOptions = {},\n): (phase: string, context: { defaultConfig: C }) => Promise<C> {\n // Now, so a wrong set of plugins stops the dev server as it starts, rather than the page.\n const { plugins, shortcut } = prepare(options);\n return async (phase, context) => {\n const resolved = typeof next === 'function' ? await next(phase, context) : next;\n if (phase !== DEV) return resolved;\n const root = resolve(options.root ?? process.cwd());\n const base = `${(resolved as { basePath?: string }).basePath ?? ''}/`;\n const client = writeClient(root, plugins, base, shortcut);\n const rules: [string, Rule][] = GLOBS.flatMap((glob) => [\n [glob, { condition: { all: ['browser', { not: 'foreign' }] }, loaders: [{ loader: loaderPath, options: { root, client } }] }],\n [glob, { condition: { all: [{ not: 'browser' }, { not: 'foreign' }] }, loaders: [{ loader: loaderPath, options: { root } }] }],\n ]);\n return withRewrite(withWebpack(withRules(resolved, rules), root, client), await serve(root, plugins, base));\n };\n}\n\n/** The app's rules and ours: where both have one for a glob, theirs first, then ours, in a list. */\nfunction withRules<C extends object>(resolved: C, ours: [string, Rule][]): C {\n const turbopack = (resolved as { turbopack?: { rules?: Rules } }).turbopack;\n const rules: Rules = { ...turbopack?.rules };\n for (const [glob, rule] of ours) rules[glob] = glob in rules ? [rules[glob], rule].flat() : rule;\n return { ...resolved, turbopack: { ...turbopack, rules } };\n}\n\n/** For `next dev --webpack`: the app's own `webpack`, then the loader, `pre`, with the client in the browser's build. */\nfunction withWebpack<C extends object>(resolved: C, root: string, client: string): C {\n const theirs = (resolved as { webpack?: Webpack | null }).webpack;\n const webpack: Webpack = (config, context) => {\n const made = theirs?.(config, context) ?? config;\n const options: LoaderOptions = context.isServer ? { root } : { root, client };\n made.module.rules.unshift({ test: JSX, exclude: /[\\\\/]node_modules[\\\\/]/, enforce: 'pre', use: [{ loader: loaderPath, options }] });\n return made;\n };\n return { ...resolved, webpack };\n}\n\n/** Sends `/__deictic/*` to the endpoints' server, before any of the app's own rewrites. */\nfunction withRewrite<C extends object>(resolved: C, port: number): C {\n const theirs = (resolved as { rewrites?: () => Promise<Rewrites> }).rewrites;\n const ours = [{ source: '/__deictic/:path*', destination: `http://127.0.0.1:${port}/__deictic/:path*` }];\n const rewrites = async (): Promise<Rewrites> => {\n const r = (await theirs?.()) ?? [];\n return Array.isArray(r) ? { beforeFiles: ours, afterFiles: r } : { ...r, beforeFiles: [...ours, ...(r.beforeFiles ?? [])] };\n };\n return { ...resolved, rewrites };\n}\n\n/** Serves the endpoints on a free local port, for as long as the process lives. */\nfunction serve(root: string, plugins: ServerPlugin[], base: string): Promise<number> {\n const running = serving.get(root);\n if (running !== undefined) return running;\n const handle = endpoints({\n root,\n plugins,\n // Rewritten from under the base, but served at the root of their own server.\n base: '/',\n open: (path, { line, column }) =>\n redirect(`${base}__nextjs_launch-editor?${new URLSearchParams({ file: path, line1: String(line), column1: String(column) })}`),\n });\n const middleware = nodeMiddleware(handle);\n const server = createServer((req, res) =>\n middleware(req, res, () => {\n res.statusCode = 404;\n res.end();\n }),\n );\n const port = new Promise<number>((done, fail) => {\n server.once('error', fail);\n server.listen(0, '127.0.0.1', () => done((server.address() as AddressInfo).port));\n });\n // Not keeping the process alive past Next's own server.\n server.unref();\n serving.set(root, port);\n return port;\n}\n\nexport default withDeictic;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAyCA,MAAM,MAAM;AACZ,MAAM,aAAa,OAAO,YAAY,KAAK,QAAQ;AACnD,MAAM,QAAQ;CAAC;CAAS;CAAS;AAAM;AAGvC,MAAM,0BAAU,IAAI,IAA6B;;;;;AAMjD,SAAgB,YACd,OAA8B,CAAC,GAC/B,UAA8B,CAAC,GAC+B;CAE9D,MAAM,EAAE,SAAS,aAAa,QAAQ,OAAO;CAC7C,OAAO,OAAO,OAAO,YAAY;EAC/B,MAAM,WAAW,OAAO,SAAS,aAAa,MAAM,KAAK,OAAO,OAAO,IAAI;EAC3E,IAAI,UAAU,KAAK,OAAO;EAC1B,MAAM,OAAO,QAAQ,QAAQ,QAAQ,QAAQ,IAAI,CAAC;EAClD,MAAM,OAAO,GAAI,SAAmC,YAAY,GAAG;EACnE,MAAM,SAAS,YAAY,MAAM,SAAS,MAAM,QAAQ;EAKxD,OAAO,YAAY,YAAY,UAAU,UAJT,MAAM,SAAS,SAAS,CACtD,CAAC,MAAM;GAAE,WAAW,EAAE,KAAK,CAAC,WAAW,EAAE,KAAK,UAAU,CAAC,EAAE;GAAG,SAAS,CAAC;IAAE,QAAQ;IAAY,SAAS;KAAE;KAAM;IAAO;GAAE,CAAC;EAAE,CAAC,GAC5H,CAAC,MAAM;GAAE,WAAW,EAAE,KAAK,CAAC,EAAE,KAAK,UAAU,GAAG,EAAE,KAAK,UAAU,CAAC,EAAE;GAAG,SAAS,CAAC;IAAE,QAAQ;IA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