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,184 @@
1
+ import { Board } from "@vercel/board";
2
+ import { w as Shortcut, y as Target } from "./index.js";
3
+ import { t as Box } from "./index2.js";
4
+ interface LocalOptions {
5
+ /**
6
+ * The port it listens on, on 127.0.0.1. By default 4100, or a free one where that's taken. One named here is
7
+ * the only one tried: taken, the board doesn't start.
8
+ */
9
+ port?: number;
10
+ /** Where its log is kept, from the project's root: `.deictic/board` by default. */
11
+ dir?: string;
12
+ /** `false` for no pages of the board's own (its inspector): the panel then links its tasks nowhere. */
13
+ inspect?: boolean;
14
+ /** More arguments for `vb serve`, as it takes them: `['--tailscale', 'box.tailnet.ts.net']`. */
15
+ args?: string[];
16
+ }
17
+ /** What `local()` answers, for the tasks plugin's `board` option. */
18
+ interface LocalBoard {
19
+ local: LocalOptions;
20
+ }
21
+ /**
22
+ * The project's own board on this machine, as the tasks plugin's `board`: what it uses anyway with no
23
+ * `BOARD_URL`, here whatever the environment says, and with options.
24
+ */
25
+ declare const local: (options?: LocalOptions) => LocalBoard;
26
+ /** What the plugin uses of a board: `board()` from `@vercel/board` is one. */
27
+ type TaskBoard = Pick<Board, 'tasks' | 'thread' | 'discovery' | 'upload' | 'edit'>;
28
+ interface TasksOptions {
29
+ /**
30
+ * The board, as `@vercel/board`'s `board()` answers it. By default the one `BOARD_URL` names, and with none,
31
+ * one of the project's own on this machine: `vb serve`, started with the dev server and stopped with it, at
32
+ * `http://127.0.0.1:4100/api/board` (or the port `.deictic/board.json` says, where that one's taken), its log
33
+ * in `.deictic/board`. For your team's board, through `vercel login`, pass `board()`. `local()`, from here, is
34
+ * that board of the project's own whatever `BOARD_URL` says, with its port, its folder and the rest as options.
35
+ */
36
+ board?: TaskBoard | LocalBoard;
37
+ /** The channel tasks go to: `deictic` by default. */
38
+ channel?: string;
39
+ /**
40
+ * The project the tasks are about, as the `deictic.project` label, to tell them apart on a board several
41
+ * projects share: by default the `name` in the root's `package.json`, and no label where it has none.
42
+ */
43
+ project?: string;
44
+ /** Labels every task gets besides deictic's own, for whoever works them to filter by (`vb tail --label`). None by default. */
45
+ labels?: Record<string, string>;
46
+ /**
47
+ * Where the panel links the channel to, for a person to see its tasks, and with `task`, where it links
48
+ * that task's ID to. By default the board's own pages when it's one `vb serve` runs on this machine
49
+ * (`http://127.0.0.1:4100/c/deictic`, and `?thread=<id>` on it), and none for another board, whose pages
50
+ * deictic can't know.
51
+ */
52
+ link?: (channel: string, task?: string) => string | undefined;
53
+ /** What opens its tab directly, beside deictic's own shortcut, which opens any: none by default. */
54
+ shortcut?: Shortcut;
55
+ }
56
+ interface Task {
57
+ id: string;
58
+ /** The first line of what was typed. */
59
+ title: string;
60
+ /** What was typed, whole: what an edit changes. */
61
+ text: string;
62
+ state: string;
63
+ /** Whether it can still be edited or deleted: no one has claimed it. */
64
+ open: boolean;
65
+ /** Its page on the board, when there's one to link to. */
66
+ link?: string;
67
+ }
68
+ interface Model {
69
+ channel: string;
70
+ /** The channel's page, when there's one to link to. */
71
+ link?: string;
72
+ /** Tasks about this element, oldest first, canceled ones left out. */
73
+ tasks: Task[];
74
+ }
75
+ /**
76
+ * What the Task tab asks for: a new task (an `Op`), other words for one it lists (`edit` is its ID), or
77
+ * that one deleted (`remove` is its ID), which cancels it on the board.
78
+ */
79
+ type Change = Op | {
80
+ edit: string;
81
+ text: string;
82
+ } | {
83
+ remove: string;
84
+ };
85
+ /** A new task: what the page knows and the source doesn't. */
86
+ interface Op {
87
+ text: string;
88
+ /** The page's URL. */
89
+ page: string;
90
+ viewport: {
91
+ width: number;
92
+ height: number;
93
+ };
94
+ /**
95
+ * What was under the pointer inside the element, where nothing marked it (a dependency's markup, or a
96
+ * shadow root's): its path from the element, and its HTML, cut short.
97
+ */
98
+ pointed?: {
99
+ path: string;
100
+ html: string;
101
+ };
102
+ /** How many elements on the page come from the same place in the source. */
103
+ count: number;
104
+ /**
105
+ * Shots the screenshots plugin took of it, to attach, where that plugin is loaded: each with where the
106
+ * element is in it, and the marks drawn on it in the panel, where there are any.
107
+ */
108
+ screenshots?: {
109
+ id: string;
110
+ box: Box;
111
+ marks?: Marks;
112
+ }[];
113
+ /**
114
+ * Recordings the recordings plugin made, to attach, where that plugin is loaded: how long each ran,
115
+ * where it plays back, and the voice plugin's clips of the mic in it, attached too.
116
+ */
117
+ recordings?: {
118
+ id: string;
119
+ duration: number;
120
+ replay: string;
121
+ voice?: string[];
122
+ }[];
123
+ /** Voice notes the voice plugin kept, to attach, where that plugin is loaded, and how long each runs. */
124
+ voice?: {
125
+ id: string;
126
+ duration: number;
127
+ }[];
128
+ /** The page's annotations, where that plugin is loaded and there are any: how many, and their notes' text. */
129
+ annotations?: Marks;
130
+ }
131
+ /**
132
+ * A task the Task tab just added, as the page hears of it: the `detail` of a `deictic:task` event on `window`, for a
133
+ * page that shows its own tasks (deictic's playground lists them as a board does).
134
+ */
135
+ interface TaskAdded {
136
+ id: string;
137
+ /** The first line of what was typed. */
138
+ title: string;
139
+ state: string;
140
+ channel: string;
141
+ /** The element: its file, line and column, and its tag. */
142
+ target: Target;
143
+ /** The page's URL. */
144
+ page: string;
145
+ /** How many of each were attached; `marks` counts those drawn on shots and on the page. */
146
+ attached: {
147
+ screenshots: number;
148
+ recordings: number;
149
+ voice: number;
150
+ marks: number;
151
+ };
152
+ }
153
+ /** Marks, as a task tells of them: how many, and what the notes among them say. */
154
+ interface Marks {
155
+ count: number;
156
+ notes: string[];
157
+ }
158
+ interface Added {
159
+ channel: string;
160
+ id: string;
161
+ text: string;
162
+ labels: Record<string, string>;
163
+ /** What's attached, by the board's IDs: kept, so a redo attaches the same without uploading it again. */
164
+ attachments?: string[];
165
+ }
166
+ /** A task's words changed: its message's whole text before and after. */
167
+ interface Edited {
168
+ kind: 'edited';
169
+ id: string;
170
+ before: string;
171
+ after: string;
172
+ }
173
+ /**
174
+ * A task deleted in the panel: canceled on the board, for good, as a board has it. So it's kept whole, and
175
+ * an undo adds it again, as a new task whose ID the record then has.
176
+ */
177
+ interface Removed extends Added {
178
+ kind: 'removed';
179
+ }
180
+ /** What the history keeps of a change: a task added has no `kind`, as it had none before there were others. */
181
+ type Kept = Added | Edited | Removed;
182
+ declare function tasks(options?: TasksOptions): import("deictic").ServerPlugin<Model, Change, Kept, unknown>;
183
+ export { Marks as a, Removed as c, TaskBoard as d, TasksOptions as f, local as g, LocalOptions as h, Kept as i, Task as l, LocalBoard as m, Change as n, Model as o, tasks as p, Edited as r, Op as s, Added as t, TaskAdded as u };
184
+ //# sourceMappingURL=index4.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index4.d.ts","names":[],"sources":["../../src/plugins/tasks/local.ts","../../src/plugins/tasks/index.ts"],"mappings":";;;UAkBiB;;;;;EAKf;;EAEA;;EAEA;;EAEA;;;UAIe;EACf,OAAO;;;;;;cAOI,QAAK,UAAa,iBAAoB;;KCdvC,YAAY,KAAK;UAEZ;;;;;;;;EAQf,QAAQ,YAAY;;EAEpB;;;;;EAKA;;EAEA,SAAS;;;;;;;EAOT,QAAQ,iBAAiB;;EAEzB,WAAW;;UAGI;EACf;;EAEA;;EAEA;EACA;;EAEA;;EAEA;;UAGe;EACf;;EAEA;;EAEA,OAAO;;;;;;KAOG,SAAS;EAAO;EAAc;;EAAmB;;;UAG5C;EACf;;EAEA;EACA;IAAY;IAAe;;;;;;EAK3B;IAAY;IAAc;;;EAE1B;;;;;EAKA;IAAgB;IAAY,KAAK;IAAK,QAAQ;;;;;;EAK9C;IAAe;IAAY;IAAkB;IAAgB;;;EAE7D;IAAU;IAAY;;;EAEtB,cAAc;;;;;;UAOC;EACf;;EAEA;EACA;EACA;;EAEA,QAAQ;;EAER;;EAEA;IAAY;IAAqB;IAAoB;IAAe;;;;UAIrD;EACf;EACA;;UAGe;EACf;EACA;EACA;EACA,QAAQ;;EAER;;;UAIe;EACf;EACA;EACA;EACA;;;;;;UAOe,gBAAgB;EAC/B;;;KAIU,OAAO,QAAQ,SAAS;iBAOpB,MAAM,UAAS,iCAAiB,aAAA,OAAA,QAAA"}
@@ -0,0 +1,70 @@
1
+ import { w as Shortcut } from "./index.js";
2
+ /** A class as the panel shows it. */
3
+ interface ClassInfo {
4
+ name: string;
5
+ /** Whether Tailwind makes anything of it: a class of the project's own isn't known. */
6
+ known: boolean;
7
+ /** The colour it sets, as CSS. */
8
+ color?: string;
9
+ /** What it sets its main property to, theme values resolved: `0.875rem`. */
10
+ value?: string;
11
+ /** A variant to go on typing after (`hover:`), not a class. */
12
+ variant?: true;
13
+ }
14
+ /** The classes of one kind, and how to write one with a value of the user's own. */
15
+ interface Alternatives {
16
+ /** The property the kind sets: `font-size`. */
17
+ label: string;
18
+ /** Whether the kind is a colour's, shown as swatches. */
19
+ colors: boolean;
20
+ items: ClassInfo[];
21
+ /** A custom value goes between these: `md:text-[` and `]`. None for a kind that takes no value (`flex`). */
22
+ custom?: {
23
+ before: string;
24
+ after: string;
25
+ value?: string;
26
+ };
27
+ }
28
+ interface TailwindOptions {
29
+ /** Calls whose first argument is a class list: `cn`, `clsx`, `cx`, `twMerge`, `classNames` by default. */
30
+ helpers?: string[];
31
+ /** The attribute an element without one gets: `className`, or `class` for Solid and Preact. */
32
+ attribute?: 'className' | 'class';
33
+ /**
34
+ * The stylesheet that imports Tailwind and holds the theme, from the project's root: `src/index.css`. What
35
+ * the panel completes and shows comes from it. Tailwind's default theme without one.
36
+ */
37
+ css?: string;
38
+ /** What opens its tab directly, beside deictic's own shortcut, which opens any: none by default. */
39
+ shortcut?: Shortcut;
40
+ }
41
+ type Model = {
42
+ editable: true;
43
+ classes: string;
44
+ /** The helper's other arguments, which add classes at runtime, each read as far as the source says. */
45
+ others?: Extra[];
46
+ } | {
47
+ editable: false;
48
+ source: string;
49
+ };
50
+ /** Classes a helper's argument adds: `active && 'ring'` is `ring` when `active`. */
51
+ interface Extra {
52
+ /** The argument, or the part of it these classes come from, as written. */
53
+ source: string;
54
+ /** The classes, where the source spells them out: there, or in a `const` of the file it names. */
55
+ classes?: string;
56
+ /** What must hold for them to be added, as written: `active === 'h3'`. None where they always are. */
57
+ when?: string;
58
+ /** Set where the classes are a string in this file, which an op with `at` can write. */
59
+ editable?: true;
60
+ /** The `const` the string is in, where it isn't the argument itself: other elements may use it too. */
61
+ shared?: string;
62
+ }
63
+ interface Op {
64
+ classes: string;
65
+ /** Which of the model's `others` the classes are for, by its place there. The element's own list without. */
66
+ at?: number;
67
+ }
68
+ declare function tailwind(options?: TailwindOptions): import("deictic").ServerPlugin<Model, Op, unknown, unknown>;
69
+ export { tailwind as a, TailwindOptions as i, Model as n, Alternatives as o, Op as r, ClassInfo as s, Extra as t };
70
+ //# sourceMappingURL=index5.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index5.d.ts","names":[],"sources":["../../src/plugins/tailwind/catalog.ts","../../src/plugins/tailwind/index.ts"],"mappings":";;UAeiB;EACf;;EAEA;;EAEA;;EAEA;;EAEA;;;UAIe;;EAEf;;EAEA;EACA,OAAO;;EAEP;IAAW;IAAgB;IAAe;;;UCf3B;;EAEf;;EAEA;;;;;EAKA;;EAEA,WAAW;;KAGD;EAEN;EACA;;EAEA,SAAS;;EAET;EAAiB;;;UAGN;;EAEf;;EAEA;;EAEA;;EAEA;;EAEA;;UAGe;EACf;;EAEA;;iBASc,SAAS,UAAS,oCAAoB,aAAA,OAAA"}
@@ -0,0 +1,20 @@
1
+ import { g as ServerPlugin, w as Shortcut } from "./index.js";
2
+ import "magic-string";
3
+ import "oxc-parser";
4
+ interface DeicticOptions {
5
+ /** The plugins to load, server halves: `tailwind()`, `tasks()`, your own. None by default. */
6
+ plugins?: ServerPlugin[];
7
+ /**
8
+ * What opens the popup on any plugin, at the tab used last: Alt and the left button by default, or
9
+ * `false` for none, leaving only plugins' own shortcuts.
10
+ */
11
+ shortcut?: Shortcut | false;
12
+ }
13
+ /**
14
+ * The client module: the overlay, started with deictic's own shortcut and each plugin that has a half
15
+ * in the page, with its shortcut, checked; and with `server`, a module of the page's that answers its requests
16
+ * where no dev server does.
17
+ */
18
+ declare const clientModule: (plugins: ServerPlugin[], base: string, own?: Shortcut | false, server?: string) => string;
19
+ export { clientModule as n, DeicticOptions as t };
20
+ //# sourceMappingURL=integration.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"integration.d.ts","names":[],"sources":["../../src/tools/integration.ts"],"mappings":";;;UAmBiB;;EAEf,UAAU;;;;;EAKV,WAAW;;;;;;;cAeA,eAAY,SAAa,gBAAc,cAAc,MAAQ,kBAAgB"}
@@ -0,0 +1,279 @@
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; and with `server`, a module of the page's that answers its requests
208
+ * where no dev server does.
209
+ */
210
+ const clientModule = (plugins, base, own, server) => {
211
+ const [shortcut, ...shortcuts] = checkShortcuts([{
212
+ name: OWN$1,
213
+ shortcut: ownShortcut(own)
214
+ }, ...plugins]);
215
+ const paged = plugins.flatMap((p, i) => p.client === void 0 ? [] : [{
216
+ client: p.client,
217
+ rest: {
218
+ shortcut: shortcuts[i],
219
+ options: p.clientOptions
220
+ }
221
+ }]);
222
+ return [
223
+ `import { start } from 'deictic/client';`,
224
+ ...paged.map((p, i) => `import p${i} from ${JSON.stringify(p.client)};`),
225
+ ...server === void 0 ? [] : [`import server from ${JSON.stringify(server)};`],
226
+ `start({ base: ${JSON.stringify(base)}, shortcut: ${JSON.stringify(shortcut) ?? "undefined"}, plugins: [${paged.map((p, i) => `{ plugin: p${i}, ...${JSON.stringify(p.rest)} }`).join(", ")}]${server === void 0 ? "" : ", server"} });`
227
+ ].join("\n");
228
+ };
229
+ /**
230
+ * Writes the client module to `.deictic/client.js` for a bundler without virtual modules, and answers
231
+ * its path. Its imports are bare (`deictic/client`, each plugin's), found from the project as its own
232
+ * are. Written only when it changed, so a watching bundler doesn't rebuild for nothing.
233
+ */
234
+ function writeClient(root, plugins, base, own) {
235
+ const code = `// Written by deictic as the dev server starts: it starts the overlay in the page.\n${clientModule(plugins, base, own)}\n`;
236
+ const manifest = `${JSON.stringify({
237
+ private: true,
238
+ type: "module",
239
+ sideEffects: true
240
+ }, null, 2)}\n`;
241
+ writeIfChanged(keptIn(root, "package.json"), manifest);
242
+ return writeIfChanged(keptIn(root, "client.js"), code);
243
+ }
244
+ function writeIfChanged(path, text) {
245
+ if (!existsSync(path) || readFileSync(path, "utf8") !== text) writeFileSync(path, text);
246
+ return path;
247
+ }
248
+ /** A module beside `url`, by its name: `.ts` from the source, `.js` from `dist`, as `url` is. */
249
+ const beside = (url, name) => fileURLToPath(new URL(`./${name}${url.endsWith(".ts") ? ".ts" : ".js"}`, url)).replaceAll("\\", "/");
250
+ /**
251
+ * The import of the written client module in the module at `from`, by a relative path with forward
252
+ * slashes: Turbopack can't import a Windows path, and every bundler takes a relative one.
253
+ */
254
+ function importOf(path, from) {
255
+ const to = relative(dirname(from), path).replaceAll("\\", "/");
256
+ return `\nimport ${JSON.stringify(to.startsWith(".") ? to : `./${to}`)};\n`;
257
+ }
258
+ /**
259
+ * A module marked, by its absolute path: its host elements, and `append` after it (the client's import,
260
+ * in the browser). Nothing for a file that isn't JSX, is a dependency's, or is outside the project.
261
+ */
262
+ function mark(code, path, root, append = "") {
263
+ const file = JSX.test(path) ? fileIn(path, root) : void 0;
264
+ return file === void 0 ? void 0 : locate(code, file, append);
265
+ }
266
+ /** 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. */
267
+ function markAstro(code, path, root) {
268
+ const file = ASTRO.test(path) ? fileIn(path, root) : void 0;
269
+ return file === void 0 ? void 0 : locateAstro(code, file, root);
270
+ }
271
+ /** A project file's path from the root, as a mark has it; nothing for a dependency's or one outside the project. */
272
+ function fileIn(path, root) {
273
+ if (/[\\/]node_modules[\\/]/.test(path) || !isAbsolute(path)) return void 0;
274
+ const file = relative(root, path).replaceAll("\\", "/");
275
+ return file.startsWith("..") || isAbsolute(file) ? void 0 : file;
276
+ }
277
+ 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 };
278
+
279
+ //# 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; and with `server`, a module of the page's that answers its requests\n * where no dev server does.\n */\nexport const clientModule = (plugins: ServerPlugin[], base: string, own?: Shortcut | false, server?: string) => {\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 ...(server === undefined ? [] : [`import server from ${JSON.stringify(server)};`]),\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(', ')}]${server === undefined ? '' : ', server'} });`,\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('..') || isAbsol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,CAAC,CAAC,WAAW,MAAM,GAAG;CAC7D,OAAO,YAAY,KAAK,UAAU,GAAG,WAAW,GAAG,IAAI,KAAK,KAAK,IAAI,EAAE;AACzE;;;;;AAMA,SAAgB,KAAK,MAAc,MAAc,MAAc,SAAS,IAAyB;CAC/F,MAAM,OAAO,IAAI,KAAK,IAAI,IAAI,OAAO,MAAM,IAAI,IAAI,KAAA;CACnD,OAAO,SAAS,KAAA,IAAY,KAAA,IAAY,OAAO,MAAM,MAAM,MAAM;AACnE;;AAGA,SAAgB,UAAU,MAAc,MAAc,MAAmC;CACvF,MAAM,OAAO,MAAM,KAAK,IAAI,IAAI,OAAO,MAAM,IAAI,IAAI,KAAA;CACrD,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"}
@@ -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, the shots,
7
+ * recordings and voice clips plugins keep, and the tasks plugin's own board. 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
@@ -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, the shots,\n * recordings and voice clips plugins keep, and the tasks plugin's own board. 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"}