deictic 0.0.1 → 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 (173) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +144 -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 +93 -0
  20. package/dist/client/index.d.ts.map +1 -0
  21. package/dist/client/index.js +1329 -0
  22. package/dist/client/index.js.map +1 -0
  23. package/dist/endpoints.js +354 -0
  24. package/dist/endpoints.js.map +1 -0
  25. package/dist/index.d.ts +220 -0
  26. package/dist/index.d.ts.map +1 -0
  27. package/dist/index.js +10 -0
  28. package/dist/index.js.map +1 -0
  29. package/dist/index2.d.ts +23 -0
  30. package/dist/index3.d.ts +98 -0
  31. package/dist/index3.d.ts.map +1 -0
  32. package/dist/index4.d.ts +74 -0
  33. package/dist/index4.d.ts.map +1 -0
  34. package/dist/index5.d.ts +70 -0
  35. package/dist/index5.d.ts.map +1 -0
  36. package/dist/integration.d.ts +19 -0
  37. package/dist/integration.d.ts.map +1 -0
  38. package/dist/integration.js +277 -0
  39. package/dist/integration.js.map +1 -0
  40. package/dist/kept.js +23 -0
  41. package/dist/kept.js.map +1 -0
  42. package/dist/loader.d.ts +15 -0
  43. package/dist/loader.d.ts.map +1 -0
  44. package/dist/loader.js +17 -0
  45. package/dist/loader.js.map +1 -0
  46. package/dist/marks.js +14 -0
  47. package/dist/marks.js.map +1 -0
  48. package/dist/next.d.ts +17 -0
  49. package/dist/next.d.ts.map +1 -0
  50. package/dist/next.js +150 -0
  51. package/dist/next.js.map +1 -0
  52. package/dist/playwright.js +105 -0
  53. package/dist/playwright.js.map +1 -0
  54. package/dist/recommended/index.d.ts +25 -0
  55. package/dist/recommended/index.d.ts.map +1 -0
  56. package/dist/recommended/index.js +19 -0
  57. package/dist/recommended/index.js.map +1 -0
  58. package/dist/recordings/client.d.ts +4 -0
  59. package/dist/recordings/client.d.ts.map +1 -0
  60. package/dist/recordings/client.js +376 -0
  61. package/dist/recordings/client.js.map +1 -0
  62. package/dist/recordings/index.d.ts +2 -0
  63. package/dist/recordings/index.js +3 -0
  64. package/dist/recordings.js +235 -0
  65. package/dist/recordings.js.map +1 -0
  66. package/dist/screenshots/client.d.ts +23 -0
  67. package/dist/screenshots/client.d.ts.map +1 -0
  68. package/dist/screenshots/client.js +76 -0
  69. package/dist/screenshots/client.js.map +1 -0
  70. package/dist/screenshots/dom.d.ts +4 -0
  71. package/dist/screenshots/dom.d.ts.map +1 -0
  72. package/dist/screenshots/dom.js +92 -0
  73. package/dist/screenshots/dom.js.map +1 -0
  74. package/dist/screenshots/index.d.ts +2 -0
  75. package/dist/screenshots/index.js +98 -0
  76. package/dist/screenshots/index.js.map +1 -0
  77. package/dist/screenshots/rrweb.d.ts +9 -0
  78. package/dist/screenshots/rrweb.d.ts.map +1 -0
  79. package/dist/screenshots/rrweb.js +60 -0
  80. package/dist/screenshots/rrweb.js.map +1 -0
  81. package/dist/shortcut.js +63 -0
  82. package/dist/shortcut.js.map +1 -0
  83. package/dist/tailwind/client.d.ts +4 -0
  84. package/dist/tailwind/client.d.ts.map +1 -0
  85. package/dist/tailwind/client.js +613 -0
  86. package/dist/tailwind/client.js.map +1 -0
  87. package/dist/tailwind/index.d.ts +2 -0
  88. package/dist/tailwind/index.js +557 -0
  89. package/dist/tailwind/index.js.map +1 -0
  90. package/dist/tasks/client.d.ts +6 -0
  91. package/dist/tasks/client.d.ts.map +1 -0
  92. package/dist/tasks/client.js +642 -0
  93. package/dist/tasks/client.js.map +1 -0
  94. package/dist/tasks/index.d.ts +159 -0
  95. package/dist/tasks/index.d.ts.map +1 -0
  96. package/dist/tasks/index.js +348 -0
  97. package/dist/tasks/index.js.map +1 -0
  98. package/dist/vite.d.ts +17 -0
  99. package/dist/vite.d.ts.map +1 -0
  100. package/dist/vite.js +44 -0
  101. package/dist/vite.js.map +1 -0
  102. package/dist/voice/client.d.ts +4 -0
  103. package/dist/voice/client.d.ts.map +1 -0
  104. package/dist/voice/client.js +66 -0
  105. package/dist/voice/client.js.map +1 -0
  106. package/dist/voice/index.d.ts +47 -0
  107. package/dist/voice/index.d.ts.map +1 -0
  108. package/dist/voice/index.js +74 -0
  109. package/dist/voice/index.js.map +1 -0
  110. package/dist/waveform.js +93 -0
  111. package/dist/waveform.js.map +1 -0
  112. package/dist/webpack.d.ts +50 -0
  113. package/dist/webpack.d.ts.map +1 -0
  114. package/dist/webpack.js +78 -0
  115. package/dist/webpack.js.map +1 -0
  116. package/package.json +307 -7
  117. package/skills/deictic/SKILL.md +47 -0
  118. package/skills/deictic/references/install.md +81 -0
  119. package/skills/deictic/references/recordings.md +83 -0
  120. package/skills/deictic/references/tasks.md +79 -0
  121. package/skills/deictic/references/watch.md +43 -0
  122. package/skills/deictic/scripts/frame.mjs +62 -0
  123. package/skills/deictic/scripts/lib.mjs +193 -0
  124. package/skills/deictic/scripts/recording.mjs +186 -0
  125. package/skills/deictic/scripts/task.mjs +84 -0
  126. package/skills/deictic/scripts/transcribe.mjs +93 -0
  127. package/skills/deictic/scripts/voice.mjs +50 -0
  128. package/skills/deictic/scripts/watch.mjs +51 -0
  129. package/src/astro.ts +34 -0
  130. package/src/bun.ts +79 -0
  131. package/src/client/index.ts +833 -0
  132. package/src/client/lightbox.ts +256 -0
  133. package/src/client/style.ts +243 -0
  134. package/src/client/tooltip.ts +78 -0
  135. package/src/client/waveform.ts +98 -0
  136. package/src/index.ts +240 -0
  137. package/src/loader.ts +28 -0
  138. package/src/next.ts +133 -0
  139. package/src/plugins/annotations/client.ts +301 -0
  140. package/src/plugins/annotations/draw.ts +169 -0
  141. package/src/plugins/annotations/index.ts +105 -0
  142. package/src/plugins/annotations/svg.ts +61 -0
  143. package/src/plugins/recommended/index.ts +35 -0
  144. package/src/plugins/recordings/client.ts +315 -0
  145. package/src/plugins/recordings/index.ts +174 -0
  146. package/src/plugins/recordings/marks.ts +11 -0
  147. package/src/plugins/recordings/ours.ts +70 -0
  148. package/src/plugins/recordings/replay.ts +139 -0
  149. package/src/plugins/screenshots/client.ts +63 -0
  150. package/src/plugins/screenshots/dom.ts +79 -0
  151. package/src/plugins/screenshots/index.ts +194 -0
  152. package/src/plugins/screenshots/playwright.ts +119 -0
  153. package/src/plugins/screenshots/rrweb.ts +45 -0
  154. package/src/plugins/tailwind/catalog.ts +396 -0
  155. package/src/plugins/tailwind/client.ts +669 -0
  156. package/src/plugins/tailwind/index.ts +267 -0
  157. package/src/plugins/tasks/client.ts +622 -0
  158. package/src/plugins/tasks/index.ts +513 -0
  159. package/src/plugins/voice/client.ts +57 -0
  160. package/src/plugins/voice/index.ts +114 -0
  161. package/src/shortcut.ts +83 -0
  162. package/src/tools/astro.ts +81 -0
  163. package/src/tools/editor.ts +22 -0
  164. package/src/tools/endpoints.ts +163 -0
  165. package/src/tools/history.ts +203 -0
  166. package/src/tools/integration.ts +106 -0
  167. package/src/tools/kept.ts +21 -0
  168. package/src/tools/locate.ts +94 -0
  169. package/src/tools/plugins.ts +41 -0
  170. package/src/tools/source.ts +72 -0
  171. package/src/vite.ts +62 -0
  172. package/src/webpack.ts +107 -0
  173. package/index.js +0 -1
@@ -0,0 +1,267 @@
1
+ /**
2
+ * `deictic/tailwind`: open its tab on an element to edit its classes, written to its `className`.
3
+ *
4
+ * Only a list the source spells out can be edited: `className="…"`, `className={'…'}`, a template
5
+ * with no `${}`, or the first argument of a class helper (`cn('…', active && '…')`), whose other
6
+ * arguments stay as they are. A list built any other way is shown, not edited, since there is no one
7
+ * place for a class to go. An element without the attribute gets one.
8
+ *
9
+ * Its routes answer the panel from the project's own Tailwind (`catalog.ts`): what completes a word typed
10
+ * (`complete`), what each class sets (`info`), the classes of a class's kind (`alternatives`) and the CSS of
11
+ * classes the page's build hasn't seen (`css`). Without Tailwind v4 they answer nothing, and the panel is plain.
12
+ */
13
+ import type { Argument, Expression, JSXAttribute, JSXOpeningElement, Program } from 'oxc-parser';
14
+
15
+ import { definePlugin, Refusal, type ServerContext, type Shortcut } from '#src/index.ts';
16
+
17
+ import { type Catalog, loadCatalog } from './catalog.ts';
18
+
19
+ export type { Alternatives, ClassInfo } from './catalog.ts';
20
+
21
+ export interface TailwindOptions {
22
+ /** Calls whose first argument is a class list: `cn`, `clsx`, `cx`, `twMerge`, `classNames` by default. */
23
+ helpers?: string[];
24
+ /** The attribute an element without one gets: `className`, or `class` for Solid and Preact. */
25
+ attribute?: 'className' | 'class';
26
+ /**
27
+ * The stylesheet that imports Tailwind and holds the theme, from the project's root: `src/index.css`. What
28
+ * the panel completes and shows comes from it. Tailwind's default theme without one.
29
+ */
30
+ css?: string;
31
+ /** What opens its tab directly, beside deictic's own shortcut, which opens any: none by default. */
32
+ shortcut?: Shortcut;
33
+ }
34
+
35
+ export type Model =
36
+ | {
37
+ editable: true;
38
+ classes: string;
39
+ /** The helper's other arguments, which add classes at runtime, each read as far as the source says. */
40
+ others?: Extra[];
41
+ }
42
+ | { editable: false; source: string };
43
+
44
+ /** Classes a helper's argument adds: `active && 'ring'` is `ring` when `active`. */
45
+ export interface Extra {
46
+ /** The argument, or the part of it these classes come from, as written. */
47
+ source: string;
48
+ /** The classes, where the source spells them out: there, or in a `const` of the file it names. */
49
+ classes?: string;
50
+ /** What must hold for them to be added, as written: `active === 'h3'`. None where they always are. */
51
+ when?: string;
52
+ /** Set where the classes are a string in this file, which an op with `at` can write. */
53
+ editable?: true;
54
+ /** The `const` the string is in, where it isn't the argument itself: other elements may use it too. */
55
+ shared?: string;
56
+ }
57
+
58
+ export interface Op {
59
+ classes: string;
60
+ /** Which of the model's `others` the classes are for, by its place there. The element's own list without. */
61
+ at?: number;
62
+ }
63
+
64
+ /** Where a class list sits in the source: the text between its quotes, or where a missing attribute goes. */
65
+ type List = { kind: 'list'; start: number; end: number; quote: string; others?: Argument[] };
66
+ type Spot = List | { kind: 'missing'; at: number } | { kind: 'fixed'; source: string };
67
+
68
+ const HELPERS = ['cn', 'clsx', 'cx', 'twMerge', 'classNames'];
69
+
70
+ export function tailwind(options: TailwindOptions = {}) {
71
+ const helpers = new Set(options.helpers ?? HELPERS);
72
+ const attribute = options.attribute ?? 'className';
73
+ // Loaded on the first ask, as it takes a moment, and once: a project without Tailwind v4 has none.
74
+ let loading: Promise<Catalog | undefined> | undefined;
75
+ const catalog = ({ root }: ServerContext) =>
76
+ (loading ??= loadCatalog(root, options.css).catch((problem: unknown) => {
77
+ console.warn(`deictic/tailwind: no completions or class details, as ${problem instanceof Error ? problem.message : String(problem)}`);
78
+ return undefined;
79
+ }));
80
+ const asked = async (request: Request): Promise<string[]> => {
81
+ const body = (await request.json().catch(() => undefined)) as { classes?: unknown } | undefined;
82
+ return Array.isArray(body?.classes) ? body.classes.filter((c): c is string => typeof c === 'string').slice(0, 500) : [];
83
+ };
84
+ return definePlugin<Model, Op>({
85
+ name: 'tailwind',
86
+ client: 'deictic/tailwind/client',
87
+ shortcut: options.shortcut,
88
+ routes: {
89
+ // `complete?q=fle`: the classes for a word being typed.
90
+ complete: async (request, context) => {
91
+ const query = new URL(request.url).searchParams.get('q') ?? '';
92
+ return Response.json({ items: (await catalog(context))?.complete(query) ?? [] });
93
+ },
94
+ // What each of `classes` sets. `available` is false where there's no catalog, so the panel stops asking.
95
+ info: async (request, context) => {
96
+ const known = await catalog(context);
97
+ return Response.json({ available: known !== undefined, items: known?.info(await asked(request)) ?? [] });
98
+ },
99
+ // `alternatives?class=text-sm`: the classes of its kind, or nothing for one Tailwind doesn't know.
100
+ alternatives: async (request, context) => {
101
+ const name = new URL(request.url).searchParams.get('class') ?? '';
102
+ return Response.json((await catalog(context))?.alternatives(name) ?? null);
103
+ },
104
+ css: async (request, context) => Response.json({ css: (await catalog(context))?.css(await asked(request)) ?? '' }),
105
+ },
106
+ read({ code, element, program }) {
107
+ const spot = spotOf(element, code, helpers);
108
+ if (spot.kind === 'fixed') return { editable: false, source: spot.source };
109
+ if (spot.kind === 'missing') return { editable: true, classes: '' };
110
+ const others = spot.others?.flatMap((argument) => extrasOf(argument, code, program)).map(({ spot: _, ...extra }) => extra);
111
+ return { editable: true, classes: code.slice(spot.start, spot.end), ...(others === undefined ? {} : { others }) };
112
+ },
113
+ apply({ file, code, element, program }, _target, { classes, at }) {
114
+ const list = classes.trim().split(/\s+/).filter(Boolean).join(' ');
115
+ const spot = spotOf(element, code, helpers);
116
+ if (spot.kind === 'fixed') throw new Refusal('this class list is built at runtime: edit it in the editor');
117
+ if (at !== undefined) {
118
+ const others = spot.kind === 'list' ? (spot.others ?? []).flatMap((argument) => extrasOf(argument, code, program)) : [];
119
+ const place = others[at]?.spot;
120
+ if (place === undefined)
121
+ throw new Refusal("these classes aren't a string in this file any more: reload, or edit them in the editor");
122
+ return [{ start: place.start, end: place.end, text: quoted(list, place.quote) }];
123
+ }
124
+ // An `.astro` component writes `class`, whatever the JSX beside it does.
125
+ const name = file.endsWith('.astro') ? 'class' : attribute;
126
+ if (spot.kind === 'missing') return list === '' ? [] : [{ start: spot.at, end: spot.at, text: ` ${name}="${quoted(list, '"')}"` }];
127
+ return [{ start: spot.start, end: spot.end, text: quoted(list, spot.quote) }];
128
+ },
129
+ describe({ classes, at }, before) {
130
+ if (!before.editable) return 'classes';
131
+ if (at === undefined) return diff(before.classes, classes);
132
+ const other = before.others?.[at];
133
+ return `${diff(other?.classes ?? '', classes)}${other?.when === undefined ? '' : ` when ${other.when}`}`;
134
+ },
135
+ });
136
+ }
137
+
138
+ function spotOf(element: JSXOpeningElement, code: string, helpers: Set<string>): Spot {
139
+ const attr = element.attributes.find(
140
+ (a): a is JSXAttribute =>
141
+ a.type === 'JSXAttribute' && a.name.type === 'JSXIdentifier' && (a.name.name === 'className' || a.name.name === 'class'),
142
+ );
143
+ if (attr === undefined) {
144
+ // Astro's `class:list` is the element's class list too: a `class` beside it would be a second one.
145
+ const listed = element.attributes.find(
146
+ (a) => a.type === 'JSXAttribute' && a.name.type === 'JSXIdentifier' && a.name.name === 'class:list',
147
+ );
148
+ return listed === undefined
149
+ ? { kind: 'missing', at: element.name.end }
150
+ : { kind: 'fixed', source: code.slice(listed.start, listed.end) };
151
+ }
152
+ const { value } = attr;
153
+ if (value?.type === 'Literal') return list(value, code);
154
+ if (value?.type !== 'JSXExpressionContainer' || value.expression.type === 'JSXEmptyExpression')
155
+ return { kind: 'fixed', source: code.slice(attr.start, attr.end) };
156
+ const e = value.expression;
157
+ const whole = listIn(e, code);
158
+ if (whole !== undefined) return whole;
159
+ if (e.type === 'CallExpression' && e.callee.type === 'Identifier' && helpers.has(e.callee.name)) {
160
+ const [first, ...others] = e.arguments;
161
+ const head = first === undefined || first.type === 'SpreadElement' ? undefined : listIn(first, code);
162
+ if (head !== undefined) return others.length === 0 ? head : { ...head, others };
163
+ }
164
+ return { kind: 'fixed', source: code.slice(attr.start, attr.end) };
165
+ }
166
+
167
+ /**
168
+ * What one of a helper's arguments adds, and when: `on && 'ring'`, `on ? 'a' : 'b'`, `{ ring: on }`, a string,
169
+ * or a name for one. Anything else is only its source, as nothing says what it adds.
170
+ */
171
+ function extrasOf(argument: Argument, code: string, program: Program): (Extra & { spot?: List })[] {
172
+ const source = (node: { start: number; end: number }) => code.slice(node.start, node.end);
173
+ const added = (e: { type: string; start: number; end: number }, when?: string, key = false): Extra & { spot?: List } => {
174
+ const found = stringOf(e, program, !key);
175
+ if (found === undefined) return { source: source(e), ...(when === undefined ? {} : { when }) };
176
+ return {
177
+ source: source(e),
178
+ classes: found.value,
179
+ ...(when === undefined ? {} : { when }),
180
+ editable: true,
181
+ ...(found.shared === undefined ? {} : { shared: found.shared }),
182
+ spot: list(found.node, code),
183
+ };
184
+ };
185
+ const e = argument;
186
+ if (e.type === 'SpreadElement') return [{ source: source(e) }];
187
+ if (e.type === 'LogicalExpression' && e.operator === '&&') return [added(e.right, source(e.left))];
188
+ if (e.type === 'ConditionalExpression') {
189
+ const test = source(e.test);
190
+ const not = e.test.type === 'Identifier' ? `!${test}` : `!(${test})`;
191
+ // A branch that adds nothing (`on ? 'ring' : undefined`) isn't one to show.
192
+ return [added(e.consequent, test), added(e.alternate, not)].filter(
193
+ (extra) => extra.classes !== '' && !/^(undefined|null|false)$/.test(extra.source),
194
+ );
195
+ }
196
+ if (e.type === 'ObjectExpression') {
197
+ return e.properties.map((property): Extra & { spot?: List } => {
198
+ if (property.type !== 'Property' || property.computed) return { source: source(property) };
199
+ const always = property.value.type === 'Literal' && property.value.value === true;
200
+ const when = always ? {} : { when: source(property.value) };
201
+ // A bare key (`ring`) is a class, but not a string to write a list into.
202
+ if (property.key.type === 'Identifier') return { source: source(property), classes: property.key.name, ...when };
203
+ const { source: _, ...key } = added(property.key, undefined, true);
204
+ return key.classes === undefined ? { source: source(property) } : { source: source(property), ...key, ...when };
205
+ });
206
+ }
207
+ return [added(e)];
208
+ }
209
+
210
+ /**
211
+ * A string the source spells out, and where: a literal, a template with nothing interpolated, or a top-level
212
+ * `const` of one (`shared`, its name).
213
+ */
214
+ function stringOf(
215
+ e: { type: string },
216
+ program: Program,
217
+ named = true,
218
+ ): { value: string; node: { start: number; end: number }; shared?: string } | undefined {
219
+ const node = e as Expression;
220
+ if (node.type === 'Literal') return typeof node.value === 'string' ? { value: node.value, node } : undefined;
221
+ if (node.type === 'TemplateLiteral') {
222
+ const value = node.expressions.length === 0 ? node.quasis[0]?.value.cooked : undefined;
223
+ return value === undefined || value === null ? undefined : { value, node };
224
+ }
225
+ if (node.type !== 'Identifier' || !named) return undefined;
226
+ for (const statement of program.body) {
227
+ const declared = statement.type === 'ExportNamedDeclaration' ? statement.declaration : statement;
228
+ if (declared?.type !== 'VariableDeclaration' || declared.kind !== 'const') continue;
229
+ for (const { id, init } of declared.declarations) {
230
+ if (id.type !== 'Identifier' || id.name !== node.name || !init) continue;
231
+ const found = stringOf(init, program, false);
232
+ return found === undefined ? undefined : { ...found, shared: node.name };
233
+ }
234
+ }
235
+ return undefined;
236
+ }
237
+
238
+ /** A string literal or a template with nothing interpolated, as the text between its quotes. */
239
+ function listIn(e: Expression, code: string): List | undefined {
240
+ if (e.type === 'Literal' && typeof e.value === 'string') return list(e, code);
241
+ if (e.type === 'TemplateLiteral' && e.expressions.length === 0) return list(e, code);
242
+ return undefined;
243
+ }
244
+
245
+ const list = (node: { start: number; end: number }, code: string): List => ({
246
+ kind: 'list',
247
+ start: node.start + 1,
248
+ end: node.end - 1,
249
+ quote: code[node.start]!,
250
+ });
251
+
252
+ /** The list as it may sit between `quote`s. A JSX attribute has no escapes, so a quote of its own kind can't. */
253
+ function quoted(list: string, quote: string): string {
254
+ if (quote === '`') return list.replaceAll('\\', '\\\\').replaceAll('`', '\\`').replaceAll('${', '\\${');
255
+ if (!list.includes(quote)) return list;
256
+ throw new Refusal(`a class can't hold ${quote} here: use the other quote inside arbitrary values, as in content-['…']`);
257
+ }
258
+
259
+ /** What changed between two lists: `+ring -px-2`. */
260
+ function diff(before: string, after: string): string {
261
+ const was = new Set(before.split(/\s+/).filter(Boolean));
262
+ const now = new Set(after.split(/\s+/).filter(Boolean));
263
+ const parts = [...[...now].filter((c) => !was.has(c)).map((c) => `+${c}`), ...[...was].filter((c) => !now.has(c)).map((c) => `-${c}`)];
264
+ return parts.length > 0 ? parts.join(' ') : 'reordered classes';
265
+ }
266
+
267
+ export default tailwind;