deictic 0.0.1 → 0.2.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 (176) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +167 -0
  3. package/dist/annotations/client.d.ts +4 -0
  4. package/dist/annotations/client.d.ts.map +1 -0
  5. package/dist/annotations/client.js +497 -0
  6. package/dist/annotations/client.js.map +1 -0
  7. package/dist/annotations/index.d.ts +110 -0
  8. package/dist/annotations/index.d.ts.map +1 -0
  9. package/dist/annotations/index.js +22 -0
  10. package/dist/annotations/index.js.map +1 -0
  11. package/dist/astro.d.ts +29 -0
  12. package/dist/astro.d.ts.map +1 -0
  13. package/dist/astro.js +24 -0
  14. package/dist/astro.js.map +1 -0
  15. package/dist/bun.d.ts +12 -0
  16. package/dist/bun.d.ts.map +1 -0
  17. package/dist/bun.js +67 -0
  18. package/dist/bun.js.map +1 -0
  19. package/dist/client/index.d.ts +95 -0
  20. package/dist/client/index.d.ts.map +1 -0
  21. package/dist/client/index.js +1333 -0
  22. package/dist/client/index.js.map +1 -0
  23. package/dist/index.d.ts +23 -0
  24. package/dist/index.js +10 -0
  25. package/dist/index.js.map +1 -0
  26. package/dist/loader.d.ts +15 -0
  27. package/dist/loader.d.ts.map +1 -0
  28. package/dist/loader.js +17 -0
  29. package/dist/loader.js.map +1 -0
  30. package/dist/next.d.ts +17 -0
  31. package/dist/next.d.ts.map +1 -0
  32. package/dist/next.js +150 -0
  33. package/dist/next.js.map +1 -0
  34. package/dist/recommended/index.d.ts +25 -0
  35. package/dist/recommended/index.d.ts.map +1 -0
  36. package/dist/recommended/index.js +19 -0
  37. package/dist/recommended/index.js.map +1 -0
  38. package/dist/recordings/client.d.ts +4 -0
  39. package/dist/recordings/client.d.ts.map +1 -0
  40. package/dist/recordings/client.js +376 -0
  41. package/dist/recordings/client.js.map +1 -0
  42. package/dist/recordings/index.d.ts +2 -0
  43. package/dist/recordings/index.js +3 -0
  44. package/dist/screenshots/client.d.ts +23 -0
  45. package/dist/screenshots/client.d.ts.map +1 -0
  46. package/dist/screenshots/client.js +76 -0
  47. package/dist/screenshots/client.js.map +1 -0
  48. package/dist/screenshots/dom.d.ts +4 -0
  49. package/dist/screenshots/dom.d.ts.map +1 -0
  50. package/dist/screenshots/dom.js +92 -0
  51. package/dist/screenshots/dom.js.map +1 -0
  52. package/dist/screenshots/index.d.ts +2 -0
  53. package/dist/screenshots/index.js +98 -0
  54. package/dist/screenshots/index.js.map +1 -0
  55. package/dist/screenshots/rrweb.d.ts +9 -0
  56. package/dist/screenshots/rrweb.d.ts.map +1 -0
  57. package/dist/screenshots/rrweb.js +60 -0
  58. package/dist/screenshots/rrweb.js.map +1 -0
  59. package/dist/shared/endpoints.js +354 -0
  60. package/dist/shared/endpoints.js.map +1 -0
  61. package/dist/shared/index.d.ts +226 -0
  62. package/dist/shared/index.d.ts.map +1 -0
  63. package/dist/shared/index2.d.ts +98 -0
  64. package/dist/shared/index2.d.ts.map +1 -0
  65. package/dist/shared/index3.d.ts +86 -0
  66. package/dist/shared/index3.d.ts.map +1 -0
  67. package/dist/shared/index4.d.ts +184 -0
  68. package/dist/shared/index4.d.ts.map +1 -0
  69. package/dist/shared/index5.d.ts +70 -0
  70. package/dist/shared/index5.d.ts.map +1 -0
  71. package/dist/shared/integration.d.ts +20 -0
  72. package/dist/shared/integration.d.ts.map +1 -0
  73. package/dist/shared/integration.js +279 -0
  74. package/dist/shared/integration.js.map +1 -0
  75. package/dist/shared/kept.js +23 -0
  76. package/dist/shared/kept.js.map +1 -0
  77. package/dist/shared/marks.js +14 -0
  78. package/dist/shared/marks.js.map +1 -0
  79. package/dist/shared/playwright.js +105 -0
  80. package/dist/shared/playwright.js.map +1 -0
  81. package/dist/shared/recordings.js +246 -0
  82. package/dist/shared/recordings.js.map +1 -0
  83. package/dist/shared/shortcut.js +63 -0
  84. package/dist/shared/shortcut.js.map +1 -0
  85. package/dist/shared/tasks.js +521 -0
  86. package/dist/shared/tasks.js.map +1 -0
  87. package/dist/shared/waveform.js +93 -0
  88. package/dist/shared/waveform.js.map +1 -0
  89. package/dist/tailwind/client.d.ts +4 -0
  90. package/dist/tailwind/client.d.ts.map +1 -0
  91. package/dist/tailwind/client.js +613 -0
  92. package/dist/tailwind/client.js.map +1 -0
  93. package/dist/tailwind/index.d.ts +2 -0
  94. package/dist/tailwind/index.js +557 -0
  95. package/dist/tailwind/index.js.map +1 -0
  96. package/dist/tasks/client.d.ts +6 -0
  97. package/dist/tasks/client.d.ts.map +1 -0
  98. package/dist/tasks/client.js +642 -0
  99. package/dist/tasks/client.js.map +1 -0
  100. package/dist/tasks/index.d.ts +2 -0
  101. package/dist/tasks/index.js +1 -0
  102. package/dist/vite.d.ts +16 -0
  103. package/dist/vite.d.ts.map +1 -0
  104. package/dist/vite.js +61 -0
  105. package/dist/vite.js.map +1 -0
  106. package/dist/voice/client.d.ts +4 -0
  107. package/dist/voice/client.d.ts.map +1 -0
  108. package/dist/voice/client.js +66 -0
  109. package/dist/voice/client.js.map +1 -0
  110. package/dist/voice/index.d.ts +47 -0
  111. package/dist/voice/index.d.ts.map +1 -0
  112. package/dist/voice/index.js +74 -0
  113. package/dist/voice/index.js.map +1 -0
  114. package/dist/webpack.d.ts +50 -0
  115. package/dist/webpack.d.ts.map +1 -0
  116. package/dist/webpack.js +78 -0
  117. package/dist/webpack.js.map +1 -0
  118. package/package.json +307 -7
  119. package/skills/deictic/SKILL.md +47 -0
  120. package/skills/deictic/references/install.md +96 -0
  121. package/skills/deictic/references/recordings.md +83 -0
  122. package/skills/deictic/references/tasks.md +79 -0
  123. package/skills/deictic/references/watch.md +43 -0
  124. package/skills/deictic/scripts/frame.mjs +62 -0
  125. package/skills/deictic/scripts/lib.mjs +211 -0
  126. package/skills/deictic/scripts/recording.mjs +186 -0
  127. package/skills/deictic/scripts/task.mjs +84 -0
  128. package/skills/deictic/scripts/transcribe.mjs +93 -0
  129. package/skills/deictic/scripts/voice.mjs +50 -0
  130. package/skills/deictic/scripts/watch.mjs +51 -0
  131. package/src/astro.ts +34 -0
  132. package/src/bun.ts +79 -0
  133. package/src/client/index.ts +846 -0
  134. package/src/client/lightbox.ts +256 -0
  135. package/src/client/style.ts +243 -0
  136. package/src/client/tooltip.ts +78 -0
  137. package/src/client/waveform.ts +98 -0
  138. package/src/index.ts +247 -0
  139. package/src/loader.ts +28 -0
  140. package/src/next.ts +133 -0
  141. package/src/plugins/annotations/client.ts +301 -0
  142. package/src/plugins/annotations/draw.ts +169 -0
  143. package/src/plugins/annotations/index.ts +105 -0
  144. package/src/plugins/annotations/svg.ts +61 -0
  145. package/src/plugins/recommended/index.ts +35 -0
  146. package/src/plugins/recordings/client.ts +316 -0
  147. package/src/plugins/recordings/index.ts +175 -0
  148. package/src/plugins/recordings/marks.ts +11 -0
  149. package/src/plugins/recordings/ours.ts +70 -0
  150. package/src/plugins/recordings/replay.ts +165 -0
  151. package/src/plugins/screenshots/client.ts +64 -0
  152. package/src/plugins/screenshots/dom.ts +79 -0
  153. package/src/plugins/screenshots/index.ts +194 -0
  154. package/src/plugins/screenshots/playwright.ts +119 -0
  155. package/src/plugins/screenshots/rrweb.ts +45 -0
  156. package/src/plugins/tailwind/catalog.ts +396 -0
  157. package/src/plugins/tailwind/client.ts +669 -0
  158. package/src/plugins/tailwind/index.ts +267 -0
  159. package/src/plugins/tasks/client.ts +622 -0
  160. package/src/plugins/tasks/index.ts +557 -0
  161. package/src/plugins/tasks/local.ts +170 -0
  162. package/src/plugins/voice/client.ts +58 -0
  163. package/src/plugins/voice/index.ts +114 -0
  164. package/src/shortcut.ts +83 -0
  165. package/src/tools/astro.ts +81 -0
  166. package/src/tools/editor.ts +22 -0
  167. package/src/tools/endpoints.ts +163 -0
  168. package/src/tools/history.ts +203 -0
  169. package/src/tools/integration.ts +108 -0
  170. package/src/tools/kept.ts +21 -0
  171. package/src/tools/locate.ts +94 -0
  172. package/src/tools/plugins.ts +41 -0
  173. package/src/tools/source.ts +72 -0
  174. package/src/vite.ts +81 -0
  175. package/src/webpack.ts +107 -0
  176. package/index.js +0 -1
@@ -0,0 +1,72 @@
1
+ /**
2
+ * The source a server half reads: a target's file, parsed, and the opening tag the page's attribute
3
+ * points at. Files are only ever read and written under the project's root, outside `node_modules`.
4
+ */
5
+ import { readFileSync } from 'node:fs';
6
+ import { isAbsolute, relative, resolve, sep } from 'node:path';
7
+
8
+ import { Refusal, type Source, type Target, type TextEdit } from '#src/index.ts';
9
+
10
+ import { ASTRO, parseAstro, type Parsed } from './astro.ts';
11
+ import { isHost, lineStarts, offsetOf, openingsIn, parse } from './locate.ts';
12
+
13
+ /** A file from the project's root, as an absolute path; refused anywhere the page has no business writing. */
14
+ export function resolveFile(root: string, file: string): string {
15
+ const path = resolve(root, file);
16
+ const from = relative(root, path);
17
+ // `relative` gives an absolute path for another drive.
18
+ if (from === '' || from.startsWith('..') || isAbsolute(from) || from.split(sep).includes('node_modules'))
19
+ throw new Refusal(`${file} is not a file of this project's own`);
20
+ return path;
21
+ }
22
+
23
+ export function readSource(root: string, file: string): string {
24
+ try {
25
+ return readFileSync(resolveFile(root, file), 'utf8');
26
+ } catch (e) {
27
+ if (e instanceof Refusal) throw e;
28
+ throw new Refusal(`can't read ${file}: has it moved since the page loaded?`, { cause: e });
29
+ }
30
+ }
31
+
32
+ /** The target's file and element, as they are on disk now. */
33
+ export function sourceAt(root: string, target: Target): Source {
34
+ const { file, line, column } = target.loc;
35
+ const code = readSource(root, file);
36
+ const offset = offsetOf(lineStarts(code), line, column);
37
+ const { program, elements } = ASTRO.test(file) ? astro(root, file, code) : jsx(file, code);
38
+ const element = elements.find((el) => el.start === offset && isHost(el));
39
+ if (element === undefined || (element.name.type === 'JSXIdentifier' && element.name.name !== target.tag))
40
+ throw new Refusal(`no <${target.tag}> at ${file}:${line}:${column} any more: the file changed since the page loaded, so reload it`);
41
+ return { file, code, program, element, read: (other) => readSource(root, other) };
42
+ }
43
+
44
+ function jsx(file: string, code: string): Parsed {
45
+ const { program, errors } = parse(file, code);
46
+ if (errors.length > 0) throw new Refusal(`${file} doesn't parse: fix it first (${errors[0]!.message})`);
47
+ return { program, elements: openingsIn(program) };
48
+ }
49
+
50
+ function astro(root: string, file: string, code: string): Parsed {
51
+ const parsed = parseAstro(root, code);
52
+ if ('problem' in parsed) throw new Refusal(`${file} can't be read: ${parsed.problem}`);
53
+ return parsed;
54
+ }
55
+
56
+ /** Each file's text after its edits, which must not overlap. */
57
+ export function applyEdits(source: Source, edits: TextEdit[]): Map<string, string> {
58
+ const byFile = Map.groupBy(edits, (e) => e.file ?? source.file);
59
+ const out = new Map<string, string>();
60
+ for (const [file, list] of byFile) {
61
+ const sorted = list.toSorted((a, b) => b.start - a.start);
62
+ let code = file === source.file ? source.code : source.read(file);
63
+ let floor = Infinity;
64
+ for (const edit of sorted) {
65
+ if (edit.end > floor) throw new Error(`deictic: edits to ${file} overlap at ${edit.end}`);
66
+ code = code.slice(0, edit.start) + edit.text + code.slice(edit.end);
67
+ floor = edit.start;
68
+ }
69
+ out.set(file, code);
70
+ }
71
+ return out;
72
+ }
package/src/vite.ts ADDED
@@ -0,0 +1,81 @@
1
+ /**
2
+ * `deictic/vite`: deictic in Vite's dev server. Nothing runs in a build, unless `standalone` asks for it.
3
+ *
4
+ * Its transform runs `pre`, so each JSX module's host elements are marked with their place in the
5
+ * source as written (`tools/locate.ts`). In the browser each marked module also imports the client
6
+ * module, which starts the overlay with every plugin's panel: imports run first and only once, so no
7
+ * line moves and frameworks that render their own HTML get it too. The endpoints are middleware on
8
+ * Vite's server, and a place opens through Vite's own `/__open-in-editor`, so the editor is whichever
9
+ * Vite already launches. A write reaches the page through Vite's usual update for the file.
10
+ */
11
+ import { resolve } from 'node:path';
12
+
13
+ import type { Plugin } from 'vite';
14
+
15
+ import { endpoints, nodeMiddleware, redirect } from './tools/endpoints.ts';
16
+ import { clientModule, type DeicticOptions, mark, markAstro, prepare } from './tools/integration.ts';
17
+
18
+ export { clientModule, type DeicticOptions };
19
+
20
+ export interface ViteOptions extends DeicticOptions {
21
+ /**
22
+ * deictic in a build too, for a page that shows it with no dev server behind it (a deployed demo): a module of
23
+ * the page's, from the root, whose default export answers the overlay's requests there (a `Standalone`, from
24
+ * `deictic`). The build's elements are marked and the overlay is in its bundle. The dev server answers as ever.
25
+ * Without it, the default, nothing of deictic is in a build.
26
+ */
27
+ standalone?: string;
28
+ }
29
+
30
+ /** The client module's ID, which a page can import itself where nothing it bundles is JSX (Astro's pages). */
31
+ export const CLIENT = 'virtual:deictic/client';
32
+ const CLIENT_ID = '\0deictic/client';
33
+
34
+ export function deictic(options: ViteOptions = {}): Plugin {
35
+ const { plugins, shortcut } = prepare(options);
36
+ let root = '';
37
+ let base = '/';
38
+ let building = false;
39
+ return {
40
+ name: 'deictic',
41
+ enforce: 'pre',
42
+ apply: (_, { command }) => command === 'serve' || options.standalone !== undefined,
43
+ // The client is the app's to bundle as it changes, not a dependency to prebundle once.
44
+ config: () => ({ optimizeDeps: { exclude: ['deictic'] } }),
45
+ configResolved(config) {
46
+ root = config.root;
47
+ base = config.base;
48
+ building = config.command === 'build';
49
+ },
50
+ configureServer(server) {
51
+ const handle = endpoints({
52
+ root,
53
+ plugins,
54
+ base,
55
+ open: (path, { line, column }) => redirect(`${base}__open-in-editor?${new URLSearchParams({ file: `${path}:${line}:${column}` })}`),
56
+ });
57
+ server.middlewares.use(nodeMiddleware(handle));
58
+ },
59
+ resolveId: (id) => (id === CLIENT ? CLIENT_ID : undefined),
60
+ load(id) {
61
+ if (id !== CLIENT_ID) return undefined;
62
+ // Only a build's page asks the module: the dev server is there to answer.
63
+ const server = building && options.standalone !== undefined ? resolve(root, options.standalone).replaceAll('\\', '/') : undefined;
64
+ return clientModule(plugins, base, shortcut, server);
65
+ },
66
+ transform: {
67
+ // First of all, not only first of the `pre` plugins: the React Compiler (`react({ compiler: true })`) is
68
+ // `pre` too and compiles the JSX away, so after it there'd be no element to mark, wherever deictic is listed.
69
+ order: 'pre',
70
+ handler(code, id) {
71
+ const [path = ''] = id.split('?');
72
+ // An `.astro` component itself, not the styles and scripts Astro loads from it by a query.
73
+ if (path.endsWith('.astro')) return id === path ? markAstro(code, path, root) : undefined;
74
+ const browser = this.environment.config.consumer === 'client';
75
+ return mark(code, path, root, browser ? `\nimport ${JSON.stringify(CLIENT)};\n` : '');
76
+ },
77
+ },
78
+ };
79
+ }
80
+
81
+ export default deictic;
package/src/webpack.ts ADDED
@@ -0,0 +1,107 @@
1
+ /**
2
+ * `deictic/webpack`: deictic in webpack's dev server, or Rspack's (`@rspack/core` takes the same
3
+ * plugin). Nothing runs out of development mode.
4
+ *
5
+ * A loader (`loader.ts`) runs `pre` on the project's JSX modules, marking each host element with its
6
+ * place in the source as written, and in a build for the browser appending the import of the client
7
+ * module, which webpack has no virtual module for, so it's written to `.deictic/client.js`. The
8
+ * endpoints go in front of the dev server's own middleware (`devServer.setupMiddlewares`, which
9
+ * webpack-dev-server and Rspack's both read), and a place opens with `launch-editor`, as webpack has no
10
+ * launcher of its own. Where the dev server is started by hand, or by Rsbuild, `middleware` is the
11
+ * endpoints to mount there.
12
+ */
13
+ import type { IncomingMessage, ServerResponse } from 'node:http';
14
+
15
+ import type { ServerPlugin } from './index.ts';
16
+ import type { LoaderOptions } from './loader.ts';
17
+ import type { Shortcut } from './shortcut.ts';
18
+ import { openInEditor } from './tools/editor.ts';
19
+ import { endpoints, nodeMiddleware } from './tools/endpoints.ts';
20
+ import { beside, type DeicticOptions, prepare, writeClient } from './tools/integration.ts';
21
+ import { JSX } from './tools/locate.ts';
22
+
23
+ export interface DeicticWebpackOptions extends DeicticOptions {
24
+ /** The project's root, which marks and edits are from: the compiler's `context` by default. */
25
+ root?: string;
26
+ /** The path the page is served under, ending in `/`: `/` by default. */
27
+ base?: string;
28
+ }
29
+
30
+ type Middleware = (req: IncomingMessage, res: ServerResponse, next: () => void) => void;
31
+ type Middlewares = ({ name: string; middleware: Middleware } | Middleware)[];
32
+
33
+ /** What the plugin reads and sets of a webpack or Rspack compiler. */
34
+ interface Compiler {
35
+ context: string;
36
+ options: {
37
+ mode?: string;
38
+ target?: string | string[] | false;
39
+ module: { rules: unknown[] };
40
+ devServer?: { setupMiddlewares?: (middlewares: Middlewares, server: unknown) => Middlewares } & Record<string, unknown>;
41
+ };
42
+ }
43
+
44
+ const loaderPath = beside(import.meta.url, 'loader');
45
+
46
+ /** Whether a target runs in a browser: webpack's default does, as do `web` and `browserslist`; Node's and Electron's main don't. */
47
+ const forBrowser = (target: Compiler['options']['target']) =>
48
+ target === undefined || [target].flat().some((t) => t !== false && !/^(async-)?node|^electron-main|^electron-preload/.test(t));
49
+
50
+ export class DeicticPlugin {
51
+ readonly #options: DeicticWebpackOptions;
52
+ readonly #plugins: ServerPlugin[];
53
+ readonly #shortcut: Shortcut | false | undefined;
54
+ #middleware: Middleware | undefined;
55
+ #root = '';
56
+
57
+ constructor(options: DeicticWebpackOptions = {}) {
58
+ this.#options = options;
59
+ // Now, so a wrong set of plugins stops the dev server as it starts, rather than the page.
60
+ ({ plugins: this.#plugins, shortcut: this.#shortcut } = prepare(options));
61
+ }
62
+
63
+ /** The endpoints as Node middleware, once the plugin is applied: for a dev server started by hand. */
64
+ get middleware(): Middleware {
65
+ if (this.#middleware !== undefined) return this.#middleware;
66
+ if (this.#root === '') throw new Error('deictic: give the plugin to the compiler before mounting its middleware');
67
+ const root = this.#root;
68
+ const handle = endpoints({
69
+ root,
70
+ plugins: this.#plugins,
71
+ base: this.#options.base ?? '/',
72
+ open: (path, loc) => openInEditor(path, loc),
73
+ });
74
+ return (this.#middleware = nodeMiddleware(handle));
75
+ }
76
+
77
+ apply(compiler: Compiler): void {
78
+ // Development only: a build without a mode is webpack's production one.
79
+ if (compiler.options.mode !== 'development') return;
80
+ this.#root = this.#options.root ?? compiler.context;
81
+ const browser = forBrowser(compiler.options.target);
82
+ const client = browser ? writeClient(this.#root, this.#plugins, this.#options.base ?? '/', this.#shortcut) : undefined;
83
+ const options: LoaderOptions = { root: this.#root, ...(client === undefined ? {} : { client }) };
84
+ // First, and `pre`, so it sees the source as written whatever the app's own rules do.
85
+ compiler.options.module.rules.unshift({
86
+ test: JSX,
87
+ exclude: /[\\/]node_modules[\\/]/,
88
+ enforce: 'pre',
89
+ use: [{ loader: loaderPath, options }],
90
+ });
91
+ if (!browser) return;
92
+
93
+ const devServer = (compiler.options.devServer ??= {});
94
+ const theirs = devServer.setupMiddlewares;
95
+ devServer.setupMiddlewares = (middlewares, server) => {
96
+ const all = theirs === undefined ? middlewares : theirs(middlewares, server);
97
+ // In front of the dev server's own, which would answer `/__deictic/` with the page or a 404.
98
+ all.unshift({ name: 'deictic', middleware: this.middleware });
99
+ return all;
100
+ };
101
+ }
102
+ }
103
+
104
+ /** The plugin, as a function: `plugins: [deictic({ plugins: [tailwind()] })]`. */
105
+ export const deictic = (options: DeicticWebpackOptions = {}) => new DeicticPlugin(options);
106
+
107
+ export default deictic;
package/index.js DELETED
@@ -1 +0,0 @@
1
- console.error("Package isn't ready yet. Please wait for the next release.");